am 40bc7cd4: (-s ours) DO NOT MERGE  Re-add .save directive for arm assembler code.

* commit '40bc7cd4ed9fb848a7b3d934f69669f64ceed707':
  DO NOT MERGE  Re-add .save directive for arm assembler code.
diff --git a/CleanSpec.mk b/CleanSpec.mk
index b84e1b6..841ad16 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -44,6 +44,10 @@
 #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
 #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
 
+# Switching to jemalloc requires deleting these files.
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libc_*)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libc_*)
+
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
 # ************************************************
diff --git a/HACKING.txt b/HACKING.txt
new file mode 100644
index 0000000..27e1368
--- /dev/null
+++ b/HACKING.txt
@@ -0,0 +1,162 @@
+Working on bionic
+=================
+
+What are the big pieces of bionic?
+----------------------------------
+
+libc/ --- libc.so, libc.a
+  The C library. Stuff like fopen(3) and kill(2).
+libm/ --- libm.so, libm.a
+  The math library. Traditionally Unix systems kept stuff like sin(3) and
+  cos(3) in a separate library to save space in the days before shared
+  libraries.
+libdl/ --- libdl.so
+  The dynamic linker interface library. This is actually just a bunch of
+  stubs that the dynamic linker replaces with pointers to its own
+  implementation at runtime. This is where stuff like dlopen(3) lives.
+libstdc++/ --- libstdc++.so
+  The C++ ABI support functions. The C++ compiler doesn't know how to
+  implement thread-safe static initialization and the like, so it just calls
+  functions that are supplied by the system. Stuff like __cxa_guard_acquire
+  and __cxa_pure_virtual live here.
+
+linker/ --- /system/bin/linker and /system/bin/linker64
+  The dynamic linker. When you run a dynamically-linked executable, its ELF
+  file has a DT_INTERP entry that says "use the following program to start me".
+  On Android, that's either linker or linker64 (depending on whether it's a
+  32-bit or 64-bit executable). It's responsible for loading the ELF executable
+  into memory and resolving references to symbols (so that when your code tries
+  to jump to fopen(3), say, it lands in the right place).
+
+tests/ --- unit tests
+  The tests/ directory contains unit tests. Roughly arranged as one file per
+  publicly-exported header file.
+benchmarks/ --- benchmarks
+  The benchmarks/ directory contains benchmarks.
+
+
+What's in libc/?
+----------------
+
+libc/
+  arch-arm/
+  arch-arm64/
+  arch-common/
+  arch-mips/
+  arch-mips64/
+  arch-x86/
+  arch-x86_64/
+    # Each architecture has its own subdirectory for stuff that isn't shared
+    # because it's architecture-specific. There will be a .mk file in here that
+    # drags in all the architecture-specific files.
+    bionic/
+      # Every architecture needs a handful of machine-specific assembler files.
+      # They live here.
+    include/
+      machine/
+        # The majority of header files are actually in libc/include/, but many
+        # of them pull in a <machine/something.h> for things like limits,
+        # endianness, and how floating point numbers are represented. Those
+        # headers live here.
+    string/
+      # Most architectures have a handful of optional assembler files
+      # implementing optimized versions of various routines. The <string.h>
+      # functions are particular favorites.
+    syscalls/
+      # The syscalls directories contain script-generated assembler files.
+      # See 'Adding system calls' later.
+
+  include/
+    # The public header files on everyone's include path. These are a mixture of
+    # files written by us and files taken from BSD.
+
+  kernel/
+    # The kernel uapi header files. These are scrubbed copies of the originals
+    # in external/kernel-headers/. These files must not be edited directly. The
+    # generate_uapi_headers.sh script should be used to go from a kernel tree to
+    # external/kernel-headers/ --- this takes care of the architecture-specific
+    # details. The update_all.py script should be used to regenerate bionic's
+    # scrubbed headers from external/kernel-headers/.
+
+  private/
+    # These are private header files meant for use within bionic itself.
+
+  dns/
+    # Contains the DNS resolver (originates from NetBSD code).
+
+  upstream-dlmalloc/
+  upstream-freebsd/
+  upstream-netbsd/
+  upstream-openbsd/
+    # These directories contain unmolested upstream source. Any time we can
+    # just use a BSD implementation of something unmodified, we should.
+    # The structure under these directories mimics the upstream tree,
+    # but there's also...
+    android/
+      include/
+        # This is where we keep the hacks necessary to build BSD source
+        # in our world. The *-compat.h files are automatically included
+        # using -include, but we also provide equivalents for missing
+        # header/source files needed by the BSD implementation.
+
+  bionic/
+    # This is the biggest mess. The C++ files are files we own, typically
+    # because the Linux kernel interface is sufficiently different that we
+    # can't use any of the BSD implementations. The C files are usually
+    # legacy mess that needs to be sorted out, either by replacing it with
+    # current upstream source in one of the upstream directories or by
+    # switching the file to C++ and cleaning it up.
+
+  stdio/
+    # These are legacy files of dubious provenance. We're working to clean
+    # this mess up, and this directory should disappear.
+
+  tools/
+    # Various tools used to maintain bionic.
+
+  tzcode/
+    # A modified superset of the IANA tzcode. Most of the modifications relate
+    # to Android's use of a single file (with corresponding index) to contain
+    # time zone data.
+  zoneinfo/
+    # Android-format time zone data.
+    # See 'Updating tzdata' later.
+
+
+Adding system calls
+-------------------
+
+Adding a system call usually involves:
+
+  1. Add entries to SYSCALLS.TXT.
+     See SYSCALLS.TXT itself for documentation on the format.
+  2. Run the gensyscalls.py script.
+  3. Add constants (and perhaps types) to the appropriate header file.
+     Note that you should check to see whether the constants are already in
+     kernel uapi header files, in which case you just need to make sure that
+     the appropriate POSIX header file in libc/include/ includes the
+     relevant file or files.
+  4. Add function declarations to the appropriate header file.
+  5. Add at least basic tests. Even a test that deliberately supplies
+     an invalid argument helps check that we're generating the right symbol
+     and have the right declaration in the header file. (And strace(1) can
+     confirm that the correct system call is being made.)
+
+
+Updating kernel header files
+----------------------------
+
+As mentioned above, this is currently a two-step process:
+
+  1. Use generate_uapi_headers.sh to go from a Linux source tree to appropriate
+     contents for external/kernel-headers/.
+  2. Run update_all.py to scrub those headers and import them into bionic.
+
+
+Updating tzdata
+---------------
+
+This is fully automated:
+
+  1. Run update-tzdata.py.
+
diff --git a/benchmarks/Android.mk b/benchmarks/Android.mk
index f64c108..4d7ad96 100644
--- a/benchmarks/Android.mk
+++ b/benchmarks/Android.mk
@@ -24,7 +24,7 @@
 
 benchmark_c_flags = \
     -O2 \
-    -Wall -Wextra \
+    -Wall -Wextra -Wunused \
     -Werror \
     -fno-builtin \
     -std=gnu++11 \
@@ -33,13 +33,20 @@
     benchmark_main.cpp \
     math_benchmark.cpp \
     property_benchmark.cpp \
+    pthread_benchmark.cpp \
+    semaphore_benchmark.cpp \
+    stdio_benchmark.cpp \
     string_benchmark.cpp \
     time_benchmark.cpp \
+    unistd_benchmark.cpp \
 
 # Build benchmarks for the device (with bionic's .so). Run with:
 #   adb shell bionic-benchmarks
 include $(CLEAR_VARS)
 LOCAL_MODULE := bionic-benchmarks
+LOCAL_MODULE_STEM_32 := bionic-benchmarks32
+LOCAL_MODULE_STEM_64 := bionic-benchmarks64
+LOCAL_MULTILIB := both
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_CFLAGS += $(benchmark_c_flags)
 LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
@@ -47,4 +54,27 @@
 LOCAL_SRC_FILES := $(benchmark_src_files)
 include $(BUILD_EXECUTABLE)
 
+ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
+ifeq ($(TARGET_ARCH),x86)
+LINKER = linker
+NATIVE_SUFFIX=32
+else
+LINKER = linker64
+NATIVE_SUFFIX=64
+endif
+
+bionic-benchmarks-run-on-host: bionic-benchmarks $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
+	if [ ! -d /system -o ! -d /system/bin ]; then \
+	  echo "Attempting to create /system/bin"; \
+	  sudo mkdir -p -m 0777 /system/bin; \
+	fi
+	mkdir -p $(TARGET_OUT_DATA)/local/tmp
+	cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
+	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
+	ANDROID_DATA=$(TARGET_OUT_DATA) \
+	ANDROID_ROOT=$(TARGET_OUT) \
+	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
+		$(TARGET_OUT_EXECUTABLES)/bionic-benchmarks$(NATIVE_SUFFIX) $(BIONIC_BENCHMARKS_FLAGS)
+endif # linux-x86
+
 endif # !BUILD_TINY_ANDROID
diff --git a/benchmarks/benchmark_main.cpp b/benchmarks/benchmark_main.cpp
index d8b8e58..d60670b 100644
--- a/benchmarks/benchmark_main.cpp
+++ b/benchmarks/benchmark_main.cpp
@@ -25,13 +25,14 @@
 
 #include <inttypes.h>
 
-static int64_t gBytesProcessed;
-static int64_t gBenchmarkTotalTimeNs;
-static int64_t gBenchmarkStartTimeNs;
+static int64_t g_bytes_processed;
+static int64_t g_benchmark_total_time_ns;
+static int64_t g_benchmark_start_time_ns;
 
 typedef std::map<std::string, ::testing::Benchmark*> BenchmarkMap;
 typedef BenchmarkMap::iterator BenchmarkMapIt;
-static BenchmarkMap gBenchmarks;
+static BenchmarkMap g_benchmarks;
+static int g_name_column_width = 20;
 
 static int Round(int n) {
   int base = 1;
@@ -96,7 +97,7 @@
     exit(EXIT_FAILURE);
   }
 
-  gBenchmarks.insert(std::make_pair(name, this));
+  g_benchmarks.insert(std::make_pair(name, this));
 }
 
 void Benchmark::Run() {
@@ -114,16 +115,16 @@
 }
 
 void Benchmark::RunRepeatedlyWithArg(int iterations, int arg) {
-  gBytesProcessed = 0;
-  gBenchmarkTotalTimeNs = 0;
-  gBenchmarkStartTimeNs = NanoTime();
+  g_bytes_processed = 0;
+  g_benchmark_total_time_ns = 0;
+  g_benchmark_start_time_ns = NanoTime();
   if (fn_ != NULL) {
     fn_(iterations);
   } else {
     fn_range_(iterations, arg);
   }
-  if (gBenchmarkStartTimeNs != 0) {
-    gBenchmarkTotalTimeNs += NanoTime() - gBenchmarkStartTimeNs;
+  if (g_benchmark_start_time_ns != 0) {
+    g_benchmark_total_time_ns += NanoTime() - g_benchmark_start_time_ns;
   }
 }
 
@@ -131,12 +132,12 @@
   // run once in case it's expensive
   int iterations = 1;
   RunRepeatedlyWithArg(iterations, arg);
-  while (gBenchmarkTotalTimeNs < 1e9 && iterations < 1e9) {
+  while (g_benchmark_total_time_ns < 1e9 && iterations < 1e9) {
     int last = iterations;
-    if (gBenchmarkTotalTimeNs/iterations == 0) {
+    if (g_benchmark_total_time_ns/iterations == 0) {
       iterations = 1e9;
     } else {
-      iterations = 1e9 / (gBenchmarkTotalTimeNs/iterations);
+      iterations = 1e9 / (g_benchmark_total_time_ns/iterations);
     }
     iterations = std::max(last + 1, std::min(iterations + iterations/2, 100*last));
     iterations = Round(iterations);
@@ -145,9 +146,9 @@
 
   char throughput[100];
   throughput[0] = '\0';
-  if (gBenchmarkTotalTimeNs > 0 && gBytesProcessed > 0) {
-    double mib_processed = static_cast<double>(gBytesProcessed)/1e6;
-    double seconds = static_cast<double>(gBenchmarkTotalTimeNs)/1e9;
+  if (g_benchmark_total_time_ns > 0 && g_bytes_processed > 0) {
+    double mib_processed = static_cast<double>(g_bytes_processed)/1e6;
+    double seconds = static_cast<double>(g_benchmark_total_time_ns)/1e9;
     snprintf(throughput, sizeof(throughput), " %8.2f MiB/s", mib_processed/seconds);
   }
 
@@ -164,42 +165,47 @@
     snprintf(full_name, sizeof(full_name), "%s", name_);
   }
 
-  printf("%-20s %10d %10" PRId64 "%s\n", full_name,
-         iterations, gBenchmarkTotalTimeNs/iterations, throughput);
+  printf("%-*s %10d %10" PRId64 "%s\n", g_name_column_width, full_name,
+         iterations, g_benchmark_total_time_ns/iterations, throughput);
   fflush(stdout);
 }
 
 }  // namespace testing
 
 void SetBenchmarkBytesProcessed(int64_t x) {
-  gBytesProcessed = x;
+  g_bytes_processed = x;
 }
 
 void StopBenchmarkTiming() {
-  if (gBenchmarkStartTimeNs != 0) {
-    gBenchmarkTotalTimeNs += NanoTime() - gBenchmarkStartTimeNs;
+  if (g_benchmark_start_time_ns != 0) {
+    g_benchmark_total_time_ns += NanoTime() - g_benchmark_start_time_ns;
   }
-  gBenchmarkStartTimeNs = 0;
+  g_benchmark_start_time_ns = 0;
 }
 
 void StartBenchmarkTiming() {
-  if (gBenchmarkStartTimeNs == 0) {
-    gBenchmarkStartTimeNs = NanoTime();
+  if (g_benchmark_start_time_ns == 0) {
+    g_benchmark_start_time_ns = NanoTime();
   }
 }
 
 int main(int argc, char* argv[]) {
-  if (gBenchmarks.empty()) {
+  if (g_benchmarks.empty()) {
     fprintf(stderr, "No benchmarks registered!\n");
     exit(EXIT_FAILURE);
   }
 
+  for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) {
+    int name_width = static_cast<int>(strlen(it->second->Name()));
+    g_name_column_width = std::max(g_name_column_width, name_width);
+  }
+
   bool need_header = true;
-  for (BenchmarkMapIt it = gBenchmarks.begin(); it != gBenchmarks.end(); ++it) {
+  for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) {
     ::testing::Benchmark* b = it->second;
     if (b->ShouldRun(argc, argv)) {
       if (need_header) {
-        printf("%-20s %10s %10s\n", "", "iterations", "ns/op");
+        printf("%-*s %10s %10s\n", g_name_column_width, "", "iterations", "ns/op");
         fflush(stdout);
         need_header = false;
       }
@@ -210,7 +216,7 @@
   if (need_header) {
     fprintf(stderr, "No matching benchmarks!\n");
     fprintf(stderr, "Available benchmarks:\n");
-    for (BenchmarkMapIt it = gBenchmarks.begin(); it != gBenchmarks.end(); ++it) {
+    for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) {
       fprintf(stderr, "  %s\n", it->second->Name());
     }
     exit(EXIT_FAILURE);
diff --git a/benchmarks/math_benchmark.cpp b/benchmarks/math_benchmark.cpp
index a8c1cfa..a9748cd 100644
--- a/benchmarks/math_benchmark.cpp
+++ b/benchmarks/math_benchmark.cpp
@@ -16,6 +16,7 @@
 
 #include "benchmark.h"
 
+#include <fenv.h>
 #include <math.h>
 
 // Avoid optimization.
@@ -60,3 +61,151 @@
   StopBenchmarkTiming();
 }
 BENCHMARK(BM_math_logb);
+
+static void BM_math_isinf_NORMAL(int iters) {
+  StartBenchmarkTiming();
+
+  d = 0.0;
+  v = 1234.0; // FP_NORMAL
+  for (int i = 0; i < iters; ++i) {
+    d += (isinf)(v);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_isinf_NORMAL);
+
+static void BM_math_isinf_NAN(int iters) {
+  StartBenchmarkTiming();
+
+  d = 0.0;
+  v = nan(""); // FP_NAN
+  for (int i = 0; i < iters; ++i) {
+    d += (isinf)(v);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_isinf_NAN);
+
+static void BM_math_isinf_INFINITE(int iters) {
+  StartBenchmarkTiming();
+
+  d = 0.0;
+  v = HUGE_VAL; // FP_INFINITE
+  for (int i = 0; i < iters; ++i) {
+    d += (isinf)(v);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_isinf_INFINITE);
+
+static void BM_math_isinf_ZERO(int iters) {
+  StartBenchmarkTiming();
+
+  d = 0.0;
+  v = 0.0; // FP_ZERO
+  for (int i = 0; i < iters; ++i) {
+    d += (isinf)(v);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_isinf_ZERO);
+
+static void BM_math_sin_fast(int iters) {
+  StartBenchmarkTiming();
+
+  d = 1.0;
+  for (int i = 0; i < iters; ++i) {
+    d += sin(d);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_sin_fast);
+
+static void BM_math_sin_feupdateenv(int iters) {
+  StartBenchmarkTiming();
+
+  d = 1.0;
+  for (int i = 0; i < iters; ++i) {
+    fenv_t __libc_save_rm;
+    feholdexcept(&__libc_save_rm);
+    fesetround(FE_TONEAREST);
+    d += sin(d);
+    feupdateenv(&__libc_save_rm);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_sin_feupdateenv);
+
+static void BM_math_sin_fesetenv(int iters) {
+  StartBenchmarkTiming();
+
+  d = 1.0;
+  for (int i = 0; i < iters; ++i) {
+    fenv_t __libc_save_rm;
+    feholdexcept(&__libc_save_rm);
+    fesetround(FE_TONEAREST);
+    d += sin(d);
+    fesetenv(&__libc_save_rm);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_sin_fesetenv);
+
+static void BM_math_fpclassify_NORMAL(int iters) {
+  StartBenchmarkTiming();
+
+  d = 0.0;
+  v = 1234.0; // FP_NORMAL
+  for (int i = 0; i < iters; ++i) {
+    d += fpclassify(v);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_fpclassify_NORMAL);
+
+static void BM_math_fpclassify_NAN(int iters) {
+  StartBenchmarkTiming();
+
+  d = 0.0;
+  v = nan(""); // FP_NAN
+  for (int i = 0; i < iters; ++i) {
+    d += fpclassify(v);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_fpclassify_NAN);
+
+static void BM_math_fpclassify_INFINITE(int iters) {
+  StartBenchmarkTiming();
+
+  d = 0.0;
+  v = HUGE_VAL; // FP_INFINITE
+  for (int i = 0; i < iters; ++i) {
+    d += fpclassify(v);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_fpclassify_INFINITE);
+
+static void BM_math_fpclassify_ZERO(int iters) {
+  StartBenchmarkTiming();
+
+  d = 0.0;
+  v = 0.0; // FP_ZERO
+  for (int i = 0; i < iters; ++i) {
+    d += fpclassify(v);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_math_fpclassify_ZERO);
diff --git a/benchmarks/property_benchmark.cpp b/benchmarks/property_benchmark.cpp
index 4311a1d..0802b4c 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -15,6 +15,9 @@
  */
 
 #include "benchmark.h"
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
@@ -25,17 +28,26 @@
 
 extern void *__system_property_area__;
 
+// Do not exceed 512, that is about the largest number of properties
+// that can be created with the current property area size.
 #define TEST_NUM_PROPS \
-    Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)->Arg(1024)
+    Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)
 
 struct LocalPropertyTestState {
     LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
-        static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_";
+        static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
 
-        char dir_template[] = "/data/local/tmp/prop-XXXXXX";
+        const char* android_data = getenv("ANDROID_DATA");
+        if (android_data == NULL) {
+          printf("ANDROID_DATA environment variable not set\n");
+          return;
+        }
+        char dir_template[PATH_MAX];
+        snprintf(dir_template, sizeof(dir_template), "%s/local/tmp/prop-XXXXXX", android_data);
         char *dirname = mkdtemp(dir_template);
         if (!dirname) {
-            perror("making temp file for test state failed (is /data/local/tmp writable?)");
+            printf("making temp file for test state failed (is %s/local/tmp writable?): %s\n",
+                   android_data, strerror(errno));
             return;
         }
 
@@ -56,18 +68,38 @@
         srandom(nprops);
 
         for (int i = 0; i < nprops; i++) {
-            name_lens[i] = random() % PROP_NAME_MAX;
+            // Make sure the name has at least 10 characters to make
+            // it very unlikely to generate the same random name.
+            name_lens[i] = (random() % (PROP_NAME_MAX - 10)) + 10;
             names[i] = new char[PROP_NAME_MAX + 1];
+            size_t prop_name_len = sizeof(prop_name_chars) - 1;
             for (int j = 0; j < name_lens[i]; j++) {
-                names[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)];
+                if (j == 0 || names[i][j-1] == '.' || j == name_lens[i] - 1) {
+                    // Certain values are not allowed:
+                    // - Don't start name with '.'
+                    // - Don't allow '.' to appear twice in a row
+                    // - Don't allow the name to end with '.'
+                    // This assumes that '.' is the last character in the
+                    // array so that decrementing the length by one removes
+                    // the value from the possible values.
+                    prop_name_len--;
+                }
+                names[i][j] = prop_name_chars[random() % prop_name_len];
             }
             names[i][name_lens[i]] = 0;
-            value_lens[i] = random() % PROP_VALUE_MAX;
+
+            // Make sure the value contains at least 1 character.
+            value_lens[i] = (random() % (PROP_VALUE_MAX - 1)) + 1;
             values[i] = new char[PROP_VALUE_MAX];
             for (int j = 0; j < value_lens[i]; j++) {
                 values[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)];
             }
-            __system_property_add(names[i], name_lens[i], values[i], value_lens[i]);
+
+            if (__system_property_add(names[i], name_lens[i], values[i], value_lens[i]) < 0) {
+                printf("Failed to add a property, terminating...\n");
+                printf("%s = %.*s\n", names[i], value_lens[i], values[i]);
+                exit(1);
+            }
         }
 
         valid = true;
@@ -146,3 +178,56 @@
     StopBenchmarkTiming();
 }
 BENCHMARK(BM_property_find)->TEST_NUM_PROPS;
+
+static void BM_property_read(int iters, int nprops)
+{
+    StopBenchmarkTiming();
+
+    LocalPropertyTestState pa(nprops);
+
+    if (!pa.valid)
+        return;
+
+    srandom(iters * nprops);
+    const prop_info** pinfo = new const prop_info*[iters];
+    char propvalue[PROP_VALUE_MAX];
+
+    for (int i = 0; i < iters; i++) {
+        pinfo[i] = __system_property_find(pa.names[random() % nprops]);
+    }
+
+    StartBenchmarkTiming();
+    for (int i = 0; i < iters; i++) {
+        __system_property_read(pinfo[i], 0, propvalue);
+    }
+    StopBenchmarkTiming();
+
+    delete[] pinfo;
+}
+BENCHMARK(BM_property_read)->TEST_NUM_PROPS;
+
+static void BM_property_serial(int iters, int nprops)
+{
+    StopBenchmarkTiming();
+
+    LocalPropertyTestState pa(nprops);
+
+    if (!pa.valid)
+        return;
+
+    srandom(iters * nprops);
+    const prop_info** pinfo = new const prop_info*[iters];
+
+    for (int i = 0; i < iters; i++) {
+        pinfo[i] = __system_property_find(pa.names[random() % nprops]);
+    }
+
+    StartBenchmarkTiming();
+    for (int i = 0; i < iters; i++) {
+        __system_property_serial(pinfo[i]);
+    }
+    StopBenchmarkTiming();
+
+    delete[] pinfo;
+}
+BENCHMARK(BM_property_serial)->TEST_NUM_PROPS;
diff --git a/benchmarks/pthread_benchmark.cpp b/benchmarks/pthread_benchmark.cpp
new file mode 100644
index 0000000..c010dd2
--- /dev/null
+++ b/benchmarks/pthread_benchmark.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "benchmark.h"
+
+#include <pthread.h>
+
+// Stop GCC optimizing out our pure function.
+/* Must not be static! */ pthread_t (*pthread_self_fp)() = pthread_self;
+
+static void BM_pthread_self(int iters) {
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    pthread_self_fp();
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_pthread_self);
+
+static void BM_pthread_getspecific(int iters) {
+  StopBenchmarkTiming();
+  pthread_key_t key;
+  pthread_key_create(&key, NULL);
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    pthread_getspecific(key);
+  }
+
+  StopBenchmarkTiming();
+  pthread_key_delete(key);
+}
+BENCHMARK(BM_pthread_getspecific);
+
+static void DummyPthreadOnceInitFunction() {
+}
+
+static void BM_pthread_once(int iters) {
+  StopBenchmarkTiming();
+  pthread_once_t once = PTHREAD_ONCE_INIT;
+  pthread_once(&once, DummyPthreadOnceInitFunction);
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    pthread_once(&once, DummyPthreadOnceInitFunction);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_pthread_once);
+
+static void BM_pthread_mutex_lock(int iters) {
+  StopBenchmarkTiming();
+  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    pthread_mutex_lock(&mutex);
+    pthread_mutex_unlock(&mutex);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_pthread_mutex_lock);
+
+static void BM_pthread_mutex_lock_ERRORCHECK(int iters) {
+  StopBenchmarkTiming();
+  pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    pthread_mutex_lock(&mutex);
+    pthread_mutex_unlock(&mutex);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_pthread_mutex_lock_ERRORCHECK);
+
+static void BM_pthread_mutex_lock_RECURSIVE(int iters) {
+  StopBenchmarkTiming();
+  pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    pthread_mutex_lock(&mutex);
+    pthread_mutex_unlock(&mutex);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_pthread_mutex_lock_RECURSIVE);
diff --git a/benchmarks/semaphore_benchmark.cpp b/benchmarks/semaphore_benchmark.cpp
new file mode 100644
index 0000000..a11fcc1
--- /dev/null
+++ b/benchmarks/semaphore_benchmark.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "benchmark.h"
+
+#include <semaphore.h>
+
+static void BM_semaphore_sem_getvalue(int iters) {
+  StopBenchmarkTiming();
+  sem_t semaphore;
+  sem_init(&semaphore, 1, 1);
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    int dummy;
+    sem_getvalue(&semaphore, &dummy);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_semaphore_sem_getvalue);
+
+static void BM_semaphore_sem_wait_sem_post(int iters) {
+  StopBenchmarkTiming();
+  sem_t semaphore;
+  sem_init(&semaphore, 1, 1);
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    sem_wait(&semaphore);
+    sem_post(&semaphore);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_semaphore_sem_wait_sem_post);
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp
new file mode 100644
index 0000000..e899df7
--- /dev/null
+++ b/benchmarks/stdio_benchmark.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "benchmark.h"
+
+#include <stdio.h>
+
+#define KB 1024
+#define MB 1024*KB
+
+#define AT_COMMON_SIZES \
+    Arg(1)->Arg(2)->Arg(3)->Arg(4)->Arg(8)->Arg(16)->Arg(32)->Arg(64)->Arg(512)-> \
+    Arg(1*KB)->Arg(4*KB)->Arg(8*KB)->Arg(16*KB)->Arg(64*KB)
+
+static void BM_stdio_fread(int iters, int chunk_size) {
+  StopBenchmarkTiming();
+  FILE* fp = fopen("/dev/zero", "rw");
+  char* buf = new char[chunk_size];
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    fread(buf, chunk_size, 1, fp);
+  }
+
+  StopBenchmarkTiming();
+  SetBenchmarkBytesProcessed(int64_t(iters) * int64_t(chunk_size));
+  delete[] buf;
+  fclose(fp);
+}
+BENCHMARK(BM_stdio_fread)->AT_COMMON_SIZES;
+
+
+static void BM_stdio_fwrite(int iters, int chunk_size) {
+  StopBenchmarkTiming();
+  FILE* fp = fopen("/dev/zero", "rw");
+  char* buf = new char[chunk_size];
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+      fwrite(buf, chunk_size, 1, fp);
+  }
+
+  StopBenchmarkTiming();
+  SetBenchmarkBytesProcessed(int64_t(iters) * int64_t(chunk_size));
+  delete[] buf;
+  fclose(fp);
+}
+BENCHMARK(BM_stdio_fwrite)->AT_COMMON_SIZES;
diff --git a/benchmarks/time_benchmark.cpp b/benchmarks/time_benchmark.cpp
index 75132e5..22f6e8e 100644
--- a/benchmarks/time_benchmark.cpp
+++ b/benchmarks/time_benchmark.cpp
@@ -16,23 +16,64 @@
 
 #include "benchmark.h"
 
+#include <sys/syscall.h>
 #include <time.h>
 
-#if defined(__BIONIC__)
-
-// Used by the horrible android.text.format.Time class, which is used by Calendar. http://b/8270865.
-extern "C" void localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz);
-
-static void BM_time_localtime_tz(int iters) {
+static void BM_time_clock_gettime(int iters) {
   StartBenchmarkTiming();
 
-  time_t now(time(NULL));
-  tm broken_down_time;
+  timespec t;
   for (int i = 0; i < iters; ++i) {
-    localtime_tz(&now, &broken_down_time, "Europe/Berlin");
+    clock_gettime(CLOCK_MONOTONIC, &t);
   }
 
   StopBenchmarkTiming();
 }
-BENCHMARK(BM_time_localtime_tz);
-#endif
+BENCHMARK(BM_time_clock_gettime);
+
+static void BM_time_clock_gettime_syscall(int iters) {
+  StartBenchmarkTiming();
+
+  timespec t;
+  for (int i = 0; i < iters; ++i) {
+    syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &t);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_time_clock_gettime_syscall);
+
+static void BM_time_gettimeofday(int iters) {
+  StartBenchmarkTiming();
+
+  timeval tv;
+  for (int i = 0; i < iters; ++i) {
+    gettimeofday(&tv, NULL);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_time_gettimeofday);
+
+static void BM_time_gettimeofday_syscall(int iters) {
+  StartBenchmarkTiming();
+
+  timeval tv;
+  for (int i = 0; i < iters; ++i) {
+    syscall(__NR_gettimeofday, &tv, NULL);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_time_gettimeofday_syscall);
+
+static void BM_time_time(int iters) {
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    time(NULL);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_time_time);
diff --git a/benchmarks/unistd_benchmark.cpp b/benchmarks/unistd_benchmark.cpp
new file mode 100644
index 0000000..7e2ac30
--- /dev/null
+++ b/benchmarks/unistd_benchmark.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "benchmark.h"
+
+#include <sys/syscall.h>
+#include <unistd.h>
+
+static void BM_unistd_getpid(int iters) {
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    getpid();
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_unistd_getpid);
+
+static void BM_unistd_getpid_syscall(int iters) {
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    syscall(__NR_getpid);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_unistd_getpid_syscall);
+
+// Stop GCC optimizing out our pure function.
+/* Must not be static! */ pid_t (*gettid_fp)() = gettid;
+
+static void BM_unistd_gettid(int iters) {
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    gettid_fp();
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_unistd_gettid);
+
+static void BM_unistd_gettid_syscall(int iters) {
+  StartBenchmarkTiming();
+
+  for (int i = 0; i < iters; ++i) {
+    syscall(__NR_gettid);
+  }
+
+  StopBenchmarkTiming();
+}
+BENCHMARK(BM_unistd_gettid_syscall);
diff --git a/libc/Android.mk b/libc/Android.mk
index ea46bf9..9c5e785 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -1,191 +1,78 @@
 LOCAL_PATH := $(call my-dir)
 
-include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/syscalls.mk
-
 # Make everything depend on any changes to included makefiles.
-libc_common_additional_dependencies := \
-    $(LOCAL_PATH)/arch-$(TARGET_ARCH)/syscalls.mk \
-    $(LOCAL_PATH)/Android.mk \
+libc_common_additional_dependencies := $(LOCAL_PATH)/Android.mk
+
+# Load config for TARGET_ARCH
+my_2nd_arch_prefix :=
+include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
+libc_common_additional_dependencies += \
+    $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
+
+
+ifdef TARGET_2ND_ARCH
+# Load config for TARGET_2ND_ARCH
+my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
+include $(LOCAL_PATH)/arch-$(TARGET_2ND_ARCH)/$(TARGET_2ND_ARCH).mk
+my_2nd_arch_prefix :=
+libc_common_additional_dependencies += \
+    $(LOCAL_PATH)/arch-$(TARGET_2ND_ARCH)/$(TARGET_2ND_ARCH).mk
+endif
+
+# crt obj files
+# ========================================================
+# crtbrand.c needs <stdint.h> and a #define for the platform SDK version.
+libc_crt_target_cflags := \
+    -I$(LOCAL_PATH)/include \
+    -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) \
+
+my_2nd_arch_prefix :=
+include $(LOCAL_PATH)/crt.mk
+ifdef TARGET_2ND_ARCH
+my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
+include $(LOCAL_PATH)/crt.mk
+my_2nd_arch_prefix :=
+endif
 
 # Define the common source files for all the libc instances
 # =========================================================
 libc_common_src_files := \
-	$(syscall_src) \
-	unistd/alarm.c \
-	unistd/exec.c \
-	unistd/fnmatch.c \
-	unistd/syslog.c \
-	unistd/system.c \
-	unistd/time.c \
-	stdio/asprintf.c \
-	stdio/fflush.c \
-	stdio/fgetc.c \
-	stdio/findfp.c \
-	stdio/fprintf.c \
-	stdio/fputc.c \
-	stdio/fread.c \
-	stdio/freopen.c \
-	stdio/fscanf.c \
-	stdio/fseek.c \
-	stdio/ftell.c \
-	stdio/fvwrite.c \
-	stdio/gets.c \
-	stdio/printf.c \
-	stdio/refill.c \
-	stdio/rewind.c \
-	stdio/scanf.c \
-	stdio/snprintf.c\
-	stdio/sprintf.c \
-	stdio/sscanf.c \
-	stdio/stdio.c \
-	stdio/ungetc.c \
-	stdio/vasprintf.c \
-	stdio/vfprintf.c \
-	stdio/vfscanf.c \
-	stdio/vprintf.c \
-	stdio/vsnprintf.c \
-	stdio/vsprintf.c \
-	stdio/vscanf.c \
-	stdio/vsscanf.c \
-	stdio/wbuf.c \
-	stdlib/atexit.c \
-	stdlib/ctype_.c \
-	stdlib/getenv.c \
-	stdlib/putenv.c \
-	stdlib/setenv.c \
-	stdlib/strtod.c \
-	stdlib/strtoimax.c \
-	stdlib/strtol.c \
-	stdlib/strtoll.c \
-	stdlib/strtoul.c \
-	stdlib/strtoull.c \
-	stdlib/strtoumax.c \
-	stdlib/tolower_.c \
-	stdlib/toupper_.c \
-	string/strcasecmp.c \
-	string/strcspn.c \
-	string/strdup.c \
-	string/strpbrk.c \
-	string/strsep.c \
-	string/strspn.c \
-	string/strstr.c \
-	string/strtok.c \
-	wchar/wcswidth.c \
-	wchar/wcsxfrm.c \
-	bionic/arc4random.c \
-	bionic/atoi.c \
-	bionic/atol.c \
-	bionic/atoll.c \
-	bionic/bindresvport.c \
-	bionic/clearenv.c \
-	bionic/daemon.c \
-	bionic/err.c \
-	bionic/ether_aton.c \
-	bionic/ether_ntoa.c \
-	bionic/fdprintf.c \
-	bionic/flockfile.c \
-	bionic/ftime.c \
-	bionic/ftok.c \
-	bionic/fts.c \
-	bionic/getdtablesize.c \
-	bionic/gethostname.c \
-	bionic/getpgrp.c \
-	bionic/getpriority.c \
-	bionic/getpt.c \
-	bionic/if_indextoname.c \
-	bionic/if_nametoindex.c \
-	bionic/initgroups.c \
-	bionic/ioctl.c \
-	bionic/isatty.c \
-	bionic/issetugid.c \
-	bionic/ldexp.c \
-	bionic/md5.c \
-	bionic/memmem.c \
-	bionic/memswap.c \
-	bionic/name_mem.c \
-	bionic/pathconf.c \
-	bionic/perror.c \
-	bionic/ptsname.c \
-	bionic/ptsname_r.c \
-	bionic/pututline.c \
-	bionic/reboot.c \
-	bionic/recv.c \
-	bionic/sched_cpualloc.c \
-	bionic/sched_cpucount.c \
-	bionic/semaphore.c \
-	bionic/send.c \
-	bionic/setpgrp.c \
-	bionic/sigblock.c \
-	bionic/siginterrupt.c \
-	bionic/siglist.c \
-	bionic/signame.c \
-	bionic/sigsetmask.c \
-	bionic/strndup.c \
-	bionic/strntoimax.c \
-	bionic/strntoumax.c \
-	bionic/strtotimeval.c \
-	bionic/system_properties.c \
-	bionic/system_properties_compat.c \
-	bionic/tcgetpgrp.c \
-	bionic/tcsetpgrp.c \
-	bionic/time64.c \
-	bionic/umount.c \
-	bionic/unlockpt.c \
-	bionic/utmp.c \
-	bionic/wcscoll.c \
-
-
-libc_dns_src_files += \
-    netbsd/gethnamaddr.c \
-    netbsd/inet/nsap_addr.c \
-    netbsd/nameser/ns_name.c \
-    netbsd/nameser/ns_netint.c \
-    netbsd/nameser/ns_parse.c \
-    netbsd/nameser/ns_print.c \
-    netbsd/nameser/ns_samedomain.c \
-    netbsd/nameser/ns_ttl.c \
-    netbsd/net/base64.c \
-    netbsd/net/getaddrinfo.c \
-    netbsd/net/getnameinfo.c \
-    netbsd/net/getservbyname.c \
-    netbsd/net/getservbyport.c \
-    netbsd/net/getservent.c \
-    netbsd/net/nsdispatch.c \
-    netbsd/resolv/__dn_comp.c \
-    netbsd/resolv/herror.c \
-    netbsd/resolv/res_cache.c \
-    netbsd/resolv/__res_close.c \
-    netbsd/resolv/res_comp.c \
-    netbsd/resolv/res_data.c \
-    netbsd/resolv/res_debug.c \
-    netbsd/resolv/res_init.c \
-    netbsd/resolv/res_mkquery.c \
-    netbsd/resolv/res_query.c \
-    netbsd/resolv/__res_send.c \
-    netbsd/resolv/res_send.c \
-    netbsd/resolv/res_state.c \
-
-
-# These are used by the 32-bit targets, but not the 64-bit ones.
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
-libc_common_src_files += \
-    bionic/legacy_32_bit_support.cpp \
-    bionic/ndk_cruft.cpp \
-
-endif
+    bionic/bindresvport.c \
+    bionic/daemon.c \
+    bionic/err.c \
+    bionic/ether_aton.c \
+    bionic/ether_ntoa.c \
+    bionic/fts.c \
+    bionic/gethostname.c \
+    bionic/getpriority.c \
+    bionic/if_indextoname.c \
+    bionic/if_nametoindex.c \
+    bionic/initgroups.c \
+    bionic/ioctl.c \
+    bionic/isatty.c \
+    bionic/memmem.c \
+    bionic/pathconf.c \
+    bionic/pututline.c \
+    bionic/sched_cpualloc.c \
+    bionic/sched_cpucount.c \
+    bionic/semaphore.c \
+    bionic/sigblock.c \
+    bionic/siginterrupt.c \
+    bionic/sigsetmask.c \
+    bionic/system_properties_compat.c \
+    stdio/snprintf.c\
+    stdio/sprintf.c \
 
 # Fortify implementations of libc functions.
 libc_common_src_files += \
     bionic/__FD_chk.cpp \
     bionic/__fgets_chk.cpp \
-    bionic/__memcpy_chk.cpp \
     bionic/__memmove_chk.cpp \
-    bionic/__memset_chk.cpp \
     bionic/__read_chk.cpp \
     bionic/__recvfrom_chk.cpp \
-    bionic/__strcat_chk.cpp \
+    bionic/__stpcpy_chk.cpp \
+    bionic/__stpncpy_chk.cpp \
     bionic/__strchr_chk.cpp \
-    bionic/__strcpy_chk.cpp \
     bionic/__strlcat_chk.cpp \
     bionic/__strlcpy_chk.cpp \
     bionic/__strlen_chk.cpp \
@@ -198,40 +85,68 @@
 
 libc_bionic_src_files := \
     bionic/abort.cpp \
+    bionic/accept.cpp \
+    bionic/accept4.cpp \
     bionic/access.cpp \
     bionic/assert.cpp \
+    bionic/atof.cpp \
     bionic/bionic_time_conversions.cpp \
     bionic/brk.cpp \
+    bionic/c16rtomb.cpp \
+    bionic/c32rtomb.cpp \
     bionic/chmod.cpp \
     bionic/chown.cpp \
+    bionic/clearenv.cpp \
+    bionic/clock.cpp \
     bionic/clone.cpp \
+    bionic/__cmsg_nxthdr.cpp \
+    bionic/connect.cpp \
+    bionic/ctype.cpp \
     bionic/dirent.cpp \
     bionic/dup2.cpp \
     bionic/epoll_create.cpp \
-    bionic/epoll_wait.cpp \
     bionic/epoll_pwait.cpp \
+    bionic/epoll_wait.cpp \
     bionic/__errno.cpp \
     bionic/eventfd_read.cpp \
     bionic/eventfd_write.cpp \
     bionic/ffs.cpp \
+    bionic/flockfile.cpp \
     bionic/fork.cpp \
+    bionic/fpclassify.cpp \
     bionic/futimens.cpp \
     bionic/getauxval.cpp \
     bionic/getcwd.cpp \
+    bionic/getentropy_linux.c \
+    bionic/getpgrp.cpp \
+    bionic/getpid.cpp \
+    bionic/gettid.cpp \
     bionic/inotify_init.cpp \
     bionic/lchown.cpp \
+    bionic/lfs64_support.cpp \
+    bionic/__libc_current_sigrtmax.cpp \
+    bionic/__libc_current_sigrtmin.cpp \
     bionic/libc_init_common.cpp \
     bionic/libc_logging.cpp \
     bionic/libgen.cpp \
     bionic/link.cpp \
+    bionic/locale.cpp \
     bionic/lstat.cpp \
+    bionic/mbrtoc16.cpp \
+    bionic/mbrtoc32.cpp \
+    bionic/mbstate.cpp \
     bionic/mkdir.cpp \
     bionic/mkfifo.cpp \
     bionic/mknod.cpp \
+    bionic/mntent.cpp \
+    bionic/NetdClientDispatch.cpp \
     bionic/open.cpp \
     bionic/pause.cpp \
     bionic/pipe.cpp \
     bionic/poll.cpp \
+    bionic/posix_fadvise.cpp \
+    bionic/posix_fallocate.cpp \
+    bionic/posix_timers.cpp \
     bionic/pthread_atfork.cpp \
     bionic/pthread_attr.cpp \
     bionic/pthread_cond.cpp \
@@ -241,6 +156,7 @@
     bionic/pthread_exit.cpp \
     bionic/pthread_getcpuclockid.cpp \
     bionic/pthread_getschedparam.cpp \
+    bionic/pthread_gettid_np.cpp \
     bionic/pthread_internals.cpp \
     bionic/pthread_join.cpp \
     bionic/pthread_key.cpp \
@@ -253,19 +169,22 @@
     bionic/pthread_setschedparam.cpp \
     bionic/pthread_sigmask.cpp \
     bionic/ptrace.cpp \
+    bionic/pty.cpp \
     bionic/raise.cpp \
+    bionic/rand.cpp \
     bionic/readlink.cpp \
+    bionic/reboot.cpp \
+    bionic/recv.cpp \
     bionic/rename.cpp \
     bionic/rmdir.cpp \
-    bionic/sbrk.cpp \
     bionic/scandir.cpp \
     bionic/sched_getaffinity.cpp \
     bionic/sched_getcpu.cpp \
+    bionic/send.cpp \
     bionic/setegid.cpp \
     bionic/__set_errno.cpp \
     bionic/seteuid.cpp \
-    bionic/setlocale.cpp \
-    bionic/signalfd.cpp \
+    bionic/setpgrp.cpp \
     bionic/sigaction.cpp \
     bionic/sigaddset.cpp \
     bionic/sigdelset.cpp \
@@ -273,77 +192,55 @@
     bionic/sigfillset.cpp \
     bionic/sigismember.cpp \
     bionic/signal.cpp \
+    bionic/signalfd.cpp \
     bionic/sigpending.cpp \
     bionic/sigprocmask.cpp \
     bionic/sigsuspend.cpp \
     bionic/sigwait.cpp \
+    bionic/socket.cpp \
     bionic/stat.cpp \
     bionic/statvfs.cpp \
+    bionic/strcoll_l.cpp \
     bionic/strerror.cpp \
     bionic/strerror_r.cpp \
+    bionic/strftime_l.cpp \
     bionic/strsignal.cpp \
+    bionic/strtold.cpp \
+    bionic/strtold_l.cpp \
+    bionic/strtoll_l.cpp \
+    bionic/strtoull_l.cpp \
+    bionic/strxfrm_l.cpp \
     bionic/stubs.cpp \
     bionic/symlink.cpp \
     bionic/sysconf.cpp \
-    bionic/thread_atexit.cpp \
+    bionic/syslog.cpp \
+    bionic/sys_siglist.c \
+    bionic/sys_signame.c \
+    bionic/system_properties.cpp \
     bionic/tdestroy.cpp \
-    bionic/timer.cpp \
+    bionic/termios.cpp \
+    bionic/thread_private.cpp \
     bionic/tmpfile.cpp \
+    bionic/umount.cpp \
     bionic/unlink.cpp \
     bionic/utimes.cpp \
+    bionic/vdso.cpp \
     bionic/wait.cpp \
     bionic/wchar.cpp \
+    bionic/wctype.cpp \
 
-# These are shared by all the 32-bit targets, but not the 64-bit ones.
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
-libc_bionic_src_files += \
-    bionic/mmap.cpp \
-
-endif
-
-libc_tzcode_src_files := \
-    tzcode/asctime.c \
-    tzcode/difftime.c \
-    tzcode/localtime.c \
-    tzcode/strftime.c \
-    tzcode/strptime.c \
+libc_cxa_src_files := \
+    bionic/__cxa_guard.cpp \
+    bionic/__cxa_pure_virtual.cpp \
+    bionic/new.cpp \
 
 libc_upstream_freebsd_src_files := \
+    upstream-freebsd/lib/libc/gen/ldexp.c \
     upstream-freebsd/lib/libc/gen/sleep.c \
     upstream-freebsd/lib/libc/gen/usleep.c \
-    upstream-freebsd/lib/libc/stdio/clrerr.c \
     upstream-freebsd/lib/libc/stdio/fclose.c \
-    upstream-freebsd/lib/libc/stdio/fdopen.c \
-    upstream-freebsd/lib/libc/stdio/feof.c \
-    upstream-freebsd/lib/libc/stdio/ferror.c \
-    upstream-freebsd/lib/libc/stdio/fgetln.c \
-    upstream-freebsd/lib/libc/stdio/fgetpos.c \
-    upstream-freebsd/lib/libc/stdio/fgets.c \
-    upstream-freebsd/lib/libc/stdio/fileno.c \
     upstream-freebsd/lib/libc/stdio/flags.c \
     upstream-freebsd/lib/libc/stdio/fopen.c \
-    upstream-freebsd/lib/libc/stdio/fpurge.c \
-    upstream-freebsd/lib/libc/stdio/fputs.c \
-    upstream-freebsd/lib/libc/stdio/fsetpos.c \
-    upstream-freebsd/lib/libc/stdio/funopen.c \
-    upstream-freebsd/lib/libc/stdio/fwalk.c \
-    upstream-freebsd/lib/libc/stdio/fwrite.c \
-    upstream-freebsd/lib/libc/stdio/getc.c \
-    upstream-freebsd/lib/libc/stdio/getchar.c \
-    upstream-freebsd/lib/libc/stdio/makebuf.c \
-    upstream-freebsd/lib/libc/stdio/mktemp.c \
-    upstream-freebsd/lib/libc/stdio/putc.c \
-    upstream-freebsd/lib/libc/stdio/putchar.c \
-    upstream-freebsd/lib/libc/stdio/puts.c \
-    upstream-freebsd/lib/libc/stdio/putw.c \
-    upstream-freebsd/lib/libc/stdio/remove.c \
-    upstream-freebsd/lib/libc/stdio/rget.c \
-    upstream-freebsd/lib/libc/stdio/setbuf.c \
-    upstream-freebsd/lib/libc/stdio/setbuffer.c \
-    upstream-freebsd/lib/libc/stdio/setvbuf.c \
-    upstream-freebsd/lib/libc/stdio/tempnam.c \
-    upstream-freebsd/lib/libc/stdio/tmpnam.c \
-    upstream-freebsd/lib/libc/stdio/wsetup.c \
     upstream-freebsd/lib/libc/stdlib/abs.c \
     upstream-freebsd/lib/libc/stdlib/getopt_long.c \
     upstream-freebsd/lib/libc/stdlib/imaxabs.c \
@@ -351,6 +248,7 @@
     upstream-freebsd/lib/libc/stdlib/labs.c \
     upstream-freebsd/lib/libc/stdlib/llabs.c \
     upstream-freebsd/lib/libc/stdlib/qsort.c \
+    upstream-freebsd/lib/libc/stdlib/quick_exit.c \
     upstream-freebsd/lib/libc/stdlib/realpath.c \
     upstream-freebsd/lib/libc/string/wcpcpy.c \
     upstream-freebsd/lib/libc/string/wcpncpy.c \
@@ -358,7 +256,6 @@
     upstream-freebsd/lib/libc/string/wcscspn.c \
     upstream-freebsd/lib/libc/string/wcsdup.c \
     upstream-freebsd/lib/libc/string/wcslcat.c \
-    upstream-freebsd/lib/libc/string/wcslcpy.c \
     upstream-freebsd/lib/libc/string/wcsncasecmp.c \
     upstream-freebsd/lib/libc/string/wcsncat.c \
     upstream-freebsd/lib/libc/string/wcsncmp.c \
@@ -366,238 +263,268 @@
     upstream-freebsd/lib/libc/string/wcsnlen.c \
     upstream-freebsd/lib/libc/string/wcspbrk.c \
     upstream-freebsd/lib/libc/string/wcsspn.c \
-    upstream-freebsd/lib/libc/string/wcsstr.c \
     upstream-freebsd/lib/libc/string/wcstok.c \
     upstream-freebsd/lib/libc/string/wmemchr.c \
     upstream-freebsd/lib/libc/string/wmemcpy.c \
-    upstream-freebsd/lib/libc/string/wmemmove.c \
     upstream-freebsd/lib/libc/string/wmemset.c \
 
 libc_upstream_netbsd_src_files := \
-    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
-    upstream-netbsd/common/lib/libc/inet/inet_addr.c \
-    upstream-netbsd/libc/compat-43/creat.c \
-    upstream-netbsd/libc/gen/ftw.c \
-    upstream-netbsd/libc/gen/nftw.c \
-    upstream-netbsd/libc/gen/nice.c \
-    upstream-netbsd/libc/gen/popen.c \
-    upstream-netbsd/libc/gen/psignal.c \
-    upstream-netbsd/libc/gen/setjmperr.c \
-    upstream-netbsd/libc/gen/utime.c \
-    upstream-netbsd/libc/inet/inet_ntoa.c \
-    upstream-netbsd/libc/inet/inet_ntop.c \
-    upstream-netbsd/libc/inet/inet_pton.c \
-    upstream-netbsd/libc/isc/ev_streams.c \
-    upstream-netbsd/libc/isc/ev_timers.c \
-    upstream-netbsd/libc/regex/regcomp.c \
-    upstream-netbsd/libc/regex/regerror.c \
-    upstream-netbsd/libc/regex/regexec.c \
-    upstream-netbsd/libc/regex/regfree.c \
-    upstream-netbsd/libc/stdio/getdelim.c \
-    upstream-netbsd/libc/stdio/getline.c \
-    upstream-netbsd/libc/stdlib/bsearch.c \
-    upstream-netbsd/libc/stdlib/div.c \
-    upstream-netbsd/libc/stdlib/drand48.c \
-    upstream-netbsd/libc/stdlib/erand48.c \
-    upstream-netbsd/libc/stdlib/exit.c \
-    upstream-netbsd/libc/stdlib/jrand48.c \
-    upstream-netbsd/libc/stdlib/ldiv.c \
-    upstream-netbsd/libc/stdlib/lldiv.c \
-    upstream-netbsd/libc/stdlib/lrand48.c \
-    upstream-netbsd/libc/stdlib/mrand48.c \
-    upstream-netbsd/libc/stdlib/nrand48.c \
-    upstream-netbsd/libc/stdlib/_rand48.c \
-    upstream-netbsd/libc/stdlib/seed48.c \
-    upstream-netbsd/libc/stdlib/srand48.c \
-    upstream-netbsd/libc/stdlib/tdelete.c \
-    upstream-netbsd/libc/stdlib/tfind.c \
-    upstream-netbsd/libc/stdlib/tsearch.c \
-    upstream-netbsd/libc/string/memccpy.c \
-    upstream-netbsd/libc/string/strcasestr.c \
-    upstream-netbsd/libc/string/strcoll.c \
-    upstream-netbsd/libc/string/strxfrm.c \
-    upstream-netbsd/libc/thread-stub/__isthreaded.c \
-    upstream-netbsd/libc/unistd/killpg.c \
+    upstream-netbsd/common/lib/libc/stdlib/random.c \
+    upstream-netbsd/lib/libc/gen/ftw.c \
+    upstream-netbsd/lib/libc/gen/nftw.c \
+    upstream-netbsd/lib/libc/gen/nice.c \
+    upstream-netbsd/lib/libc/gen/popen.c \
+    upstream-netbsd/lib/libc/gen/psignal.c \
+    upstream-netbsd/lib/libc/gen/utime.c \
+    upstream-netbsd/lib/libc/gen/utmp.c \
+    upstream-netbsd/lib/libc/inet/nsap_addr.c \
+    upstream-netbsd/lib/libc/regex/regcomp.c \
+    upstream-netbsd/lib/libc/regex/regerror.c \
+    upstream-netbsd/lib/libc/regex/regexec.c \
+    upstream-netbsd/lib/libc/regex/regfree.c \
+    upstream-netbsd/lib/libc/stdlib/bsearch.c \
+    upstream-netbsd/lib/libc/stdlib/div.c \
+    upstream-netbsd/lib/libc/stdlib/drand48.c \
+    upstream-netbsd/lib/libc/stdlib/erand48.c \
+    upstream-netbsd/lib/libc/stdlib/insque.c \
+    upstream-netbsd/lib/libc/stdlib/jrand48.c \
+    upstream-netbsd/lib/libc/stdlib/ldiv.c \
+    upstream-netbsd/lib/libc/stdlib/lldiv.c \
+    upstream-netbsd/lib/libc/stdlib/lrand48.c \
+    upstream-netbsd/lib/libc/stdlib/mrand48.c \
+    upstream-netbsd/lib/libc/stdlib/nrand48.c \
+    upstream-netbsd/lib/libc/stdlib/_rand48.c \
+    upstream-netbsd/lib/libc/stdlib/rand_r.c \
+    upstream-netbsd/lib/libc/stdlib/remque.c \
+    upstream-netbsd/lib/libc/stdlib/seed48.c \
+    upstream-netbsd/lib/libc/stdlib/srand48.c \
+    upstream-netbsd/lib/libc/string/memccpy.c \
+    upstream-netbsd/lib/libc/string/strcasestr.c \
+    upstream-netbsd/lib/libc/string/strcoll.c \
+    upstream-netbsd/lib/libc/string/strxfrm.c \
+    upstream-netbsd/lib/libc/unistd/killpg.c \
 
-# Architecture specific source files go here
-# =========================================================
-ifeq ($(TARGET_ARCH),arm)
-libc_common_src_files += \
-    bionic/memchr.c \
-    bionic/memmove.c.arm \
-    bionic/memrchr.c \
-    bionic/strchr.cpp \
-    bionic/strnlen.c \
-    string/bcopy.c \
-    string/index.c \
-    string/strlcat.c \
-    string/strlcpy.c \
-    string/strncat.c \
-    string/strncmp.c \
-    string/strncpy.c \
-    string/strrchr.c \
-    upstream-freebsd/lib/libc/string/wcscat.c \
-    upstream-freebsd/lib/libc/string/wcschr.c \
-    upstream-freebsd/lib/libc/string/wcscmp.c \
-    upstream-freebsd/lib/libc/string/wcscpy.c \
-    upstream-freebsd/lib/libc/string/wcslen.c \
-    upstream-freebsd/lib/libc/string/wcsrchr.c \
-    upstream-freebsd/lib/libc/string/wmemcmp.c \
+libc_upstream_openbsd_gdtoa_src_files := \
+    upstream-openbsd/android/gdtoa_support.cpp \
+    upstream-openbsd/lib/libc/gdtoa/dmisc.c \
+    upstream-openbsd/lib/libc/gdtoa/dtoa.c \
+    upstream-openbsd/lib/libc/gdtoa/gdtoa.c \
+    upstream-openbsd/lib/libc/gdtoa/gethex.c \
+    upstream-openbsd/lib/libc/gdtoa/gmisc.c \
+    upstream-openbsd/lib/libc/gdtoa/hd_init.c \
+    upstream-openbsd/lib/libc/gdtoa/hdtoa.c \
+    upstream-openbsd/lib/libc/gdtoa/hexnan.c \
+    upstream-openbsd/lib/libc/gdtoa/ldtoa.c \
+    upstream-openbsd/lib/libc/gdtoa/misc.c \
+    upstream-openbsd/lib/libc/gdtoa/smisc.c \
+    upstream-openbsd/lib/libc/gdtoa/strtod.c \
+    upstream-openbsd/lib/libc/gdtoa/strtodg.c \
+    upstream-openbsd/lib/libc/gdtoa/strtof.c \
+    upstream-openbsd/lib/libc/gdtoa/strtord.c \
+    upstream-openbsd/lib/libc/gdtoa/sum.c \
+    upstream-openbsd/lib/libc/gdtoa/ulp.c \
 
-endif # arm
+libc_upstream_openbsd_gdtoa_src_files_32 := \
+    $(libc_upstream_openbsd_gdtoa_src_files) \
 
-ifeq ($(TARGET_ARCH), arm64)
-#TODO: Replace C stubs with optimised assembly
-libc_common_src_files += \
-    bionic/memchr.c   \
-    bionic/memcmp.c   \
-    bionic/memcpy.c   \
-    bionic/memmove.c  \
-    bionic/memrchr.c  \
-    bionic/memset.c   \
-    bionic/strchr.cpp \
-    bionic/strnlen.c  \
-    string/bcopy.c    \
-    string/index.c    \
-    string/memcmp16.c \
-    string/strcat.c   \
-    string/strcmp.c   \
-    string/strcpy.c   \
-    string/strlcat.c  \
-    string/strlcpy.c  \
-    string/strlen.c   \
-    string/strncat.c  \
-    string/strncmp.c  \
-    string/strncpy.c  \
-    string/strrchr.c  \
-    upstream-freebsd/lib/libc/string/wcscat.c \
-    upstream-freebsd/lib/libc/string/wcschr.c \
-    upstream-freebsd/lib/libc/string/wcscmp.c \
-    upstream-freebsd/lib/libc/string/wcscpy.c \
-    upstream-freebsd/lib/libc/string/wcslen.c \
-    upstream-freebsd/lib/libc/string/wcsrchr.c \
-    upstream-freebsd/lib/libc/string/wmemcmp.c \
+libc_upstream_openbsd_gdtoa_src_files_64 := \
+    $(libc_upstream_openbsd_gdtoa_src_files) \
+    upstream-openbsd/lib/libc/gdtoa/strtorQ.c \
 
-endif # arm64
+libc_upstream_openbsd_src_files := \
+    upstream-openbsd/lib/libc/crypt/arc4random.c \
+    upstream-openbsd/lib/libc/crypt/arc4random_uniform.c \
+    upstream-openbsd/lib/libc/gen/alarm.c \
+    upstream-openbsd/lib/libc/gen/ctype_.c \
+    upstream-openbsd/lib/libc/gen/exec.c \
+    upstream-openbsd/lib/libc/gen/fnmatch.c \
+    upstream-openbsd/lib/libc/gen/ftok.c \
+    upstream-openbsd/lib/libc/gen/getprogname.c \
+    upstream-openbsd/lib/libc/gen/isctype.c \
+    upstream-openbsd/lib/libc/gen/setprogname.c \
+    upstream-openbsd/lib/libc/gen/time.c \
+    upstream-openbsd/lib/libc/gen/tolower_.c \
+    upstream-openbsd/lib/libc/gen/toupper_.c \
+    upstream-openbsd/lib/libc/locale/btowc.c \
+    upstream-openbsd/lib/libc/locale/mbrlen.c \
+    upstream-openbsd/lib/libc/locale/mbstowcs.c \
+    upstream-openbsd/lib/libc/locale/mbtowc.c \
+    upstream-openbsd/lib/libc/locale/wcscoll.c \
+    upstream-openbsd/lib/libc/locale/wcstod.c \
+    upstream-openbsd/lib/libc/locale/wcstof.c \
+    upstream-openbsd/lib/libc/locale/wcstoimax.c \
+    upstream-openbsd/lib/libc/locale/wcstol.c \
+    upstream-openbsd/lib/libc/locale/wcstold.c \
+    upstream-openbsd/lib/libc/locale/wcstoll.c \
+    upstream-openbsd/lib/libc/locale/wcstombs.c \
+    upstream-openbsd/lib/libc/locale/wcstoul.c \
+    upstream-openbsd/lib/libc/locale/wcstoull.c \
+    upstream-openbsd/lib/libc/locale/wcstoumax.c \
+    upstream-openbsd/lib/libc/locale/wcsxfrm.c \
+    upstream-openbsd/lib/libc/locale/wctob.c \
+    upstream-openbsd/lib/libc/locale/wctomb.c \
+    upstream-openbsd/lib/libc/net/htonl.c \
+    upstream-openbsd/lib/libc/net/htons.c \
+    upstream-openbsd/lib/libc/net/inet_addr.c \
+    upstream-openbsd/lib/libc/net/inet_lnaof.c \
+    upstream-openbsd/lib/libc/net/inet_makeaddr.c \
+    upstream-openbsd/lib/libc/net/inet_netof.c \
+    upstream-openbsd/lib/libc/net/inet_network.c \
+    upstream-openbsd/lib/libc/net/inet_ntoa.c \
+    upstream-openbsd/lib/libc/net/inet_ntop.c \
+    upstream-openbsd/lib/libc/net/inet_pton.c \
+    upstream-openbsd/lib/libc/net/ntohl.c \
+    upstream-openbsd/lib/libc/net/ntohs.c \
+    upstream-openbsd/lib/libc/stdio/asprintf.c \
+    upstream-openbsd/lib/libc/stdio/clrerr.c \
+    upstream-openbsd/lib/libc/stdio/dprintf.c \
+    upstream-openbsd/lib/libc/stdio/fdopen.c \
+    upstream-openbsd/lib/libc/stdio/feof.c \
+    upstream-openbsd/lib/libc/stdio/ferror.c \
+    upstream-openbsd/lib/libc/stdio/fflush.c \
+    upstream-openbsd/lib/libc/stdio/fgetc.c \
+    upstream-openbsd/lib/libc/stdio/fgetln.c \
+    upstream-openbsd/lib/libc/stdio/fgetpos.c \
+    upstream-openbsd/lib/libc/stdio/fgets.c \
+    upstream-openbsd/lib/libc/stdio/fgetwc.c \
+    upstream-openbsd/lib/libc/stdio/fgetws.c \
+    upstream-openbsd/lib/libc/stdio/fileno.c \
+    upstream-openbsd/lib/libc/stdio/findfp.c \
+    upstream-openbsd/lib/libc/stdio/fprintf.c \
+    upstream-openbsd/lib/libc/stdio/fpurge.c \
+    upstream-openbsd/lib/libc/stdio/fputc.c \
+    upstream-openbsd/lib/libc/stdio/fputs.c \
+    upstream-openbsd/lib/libc/stdio/fputwc.c \
+    upstream-openbsd/lib/libc/stdio/fputws.c \
+    upstream-openbsd/lib/libc/stdio/fread.c \
+    upstream-openbsd/lib/libc/stdio/freopen.c \
+    upstream-openbsd/lib/libc/stdio/fscanf.c \
+    upstream-openbsd/lib/libc/stdio/fseek.c \
+    upstream-openbsd/lib/libc/stdio/fsetpos.c \
+    upstream-openbsd/lib/libc/stdio/ftell.c \
+    upstream-openbsd/lib/libc/stdio/funopen.c \
+    upstream-openbsd/lib/libc/stdio/fvwrite.c \
+    upstream-openbsd/lib/libc/stdio/fwalk.c \
+    upstream-openbsd/lib/libc/stdio/fwide.c \
+    upstream-openbsd/lib/libc/stdio/fwprintf.c \
+    upstream-openbsd/lib/libc/stdio/fwrite.c \
+    upstream-openbsd/lib/libc/stdio/fwscanf.c \
+    upstream-openbsd/lib/libc/stdio/getc.c \
+    upstream-openbsd/lib/libc/stdio/getchar.c \
+    upstream-openbsd/lib/libc/stdio/getdelim.c \
+    upstream-openbsd/lib/libc/stdio/getline.c \
+    upstream-openbsd/lib/libc/stdio/gets.c \
+    upstream-openbsd/lib/libc/stdio/getwc.c \
+    upstream-openbsd/lib/libc/stdio/getwchar.c \
+    upstream-openbsd/lib/libc/stdio/makebuf.c \
+    upstream-openbsd/lib/libc/stdio/mktemp.c \
+    upstream-openbsd/lib/libc/stdio/perror.c \
+    upstream-openbsd/lib/libc/stdio/printf.c \
+    upstream-openbsd/lib/libc/stdio/putc.c \
+    upstream-openbsd/lib/libc/stdio/putchar.c \
+    upstream-openbsd/lib/libc/stdio/puts.c \
+    upstream-openbsd/lib/libc/stdio/putwc.c \
+    upstream-openbsd/lib/libc/stdio/putwchar.c \
+    upstream-openbsd/lib/libc/stdio/refill.c \
+    upstream-openbsd/lib/libc/stdio/remove.c \
+    upstream-openbsd/lib/libc/stdio/rewind.c \
+    upstream-openbsd/lib/libc/stdio/rget.c \
+    upstream-openbsd/lib/libc/stdio/scanf.c \
+    upstream-openbsd/lib/libc/stdio/setbuf.c \
+    upstream-openbsd/lib/libc/stdio/setbuffer.c \
+    upstream-openbsd/lib/libc/stdio/setvbuf.c \
+    upstream-openbsd/lib/libc/stdio/sscanf.c \
+    upstream-openbsd/lib/libc/stdio/stdio.c \
+    upstream-openbsd/lib/libc/stdio/swprintf.c \
+    upstream-openbsd/lib/libc/stdio/swscanf.c \
+    upstream-openbsd/lib/libc/stdio/tempnam.c \
+    upstream-openbsd/lib/libc/stdio/tmpnam.c \
+    upstream-openbsd/lib/libc/stdio/ungetc.c \
+    upstream-openbsd/lib/libc/stdio/ungetwc.c \
+    upstream-openbsd/lib/libc/stdio/vasprintf.c \
+    upstream-openbsd/lib/libc/stdio/vdprintf.c \
+    upstream-openbsd/lib/libc/stdio/vfprintf.c \
+    upstream-openbsd/lib/libc/stdio/vfscanf.c \
+    upstream-openbsd/lib/libc/stdio/vfwprintf.c \
+    upstream-openbsd/lib/libc/stdio/vfwscanf.c \
+    upstream-openbsd/lib/libc/stdio/vprintf.c \
+    upstream-openbsd/lib/libc/stdio/vscanf.c \
+    upstream-openbsd/lib/libc/stdio/vsnprintf.c \
+    upstream-openbsd/lib/libc/stdio/vsprintf.c \
+    upstream-openbsd/lib/libc/stdio/vsscanf.c \
+    upstream-openbsd/lib/libc/stdio/vswprintf.c \
+    upstream-openbsd/lib/libc/stdio/vswscanf.c \
+    upstream-openbsd/lib/libc/stdio/vwprintf.c \
+    upstream-openbsd/lib/libc/stdio/vwscanf.c \
+    upstream-openbsd/lib/libc/stdio/wbuf.c \
+    upstream-openbsd/lib/libc/stdio/wprintf.c \
+    upstream-openbsd/lib/libc/stdio/wscanf.c \
+    upstream-openbsd/lib/libc/stdio/wsetup.c \
+    upstream-openbsd/lib/libc/stdlib/atexit.c \
+    upstream-openbsd/lib/libc/stdlib/atoi.c \
+    upstream-openbsd/lib/libc/stdlib/atol.c \
+    upstream-openbsd/lib/libc/stdlib/atoll.c \
+    upstream-openbsd/lib/libc/stdlib/exit.c \
+    upstream-openbsd/lib/libc/stdlib/getenv.c \
+    upstream-openbsd/lib/libc/stdlib/lsearch.c \
+    upstream-openbsd/lib/libc/stdlib/setenv.c \
+    upstream-openbsd/lib/libc/stdlib/strtoimax.c \
+    upstream-openbsd/lib/libc/stdlib/strtol.c \
+    upstream-openbsd/lib/libc/stdlib/strtoll.c \
+    upstream-openbsd/lib/libc/stdlib/strtoul.c \
+    upstream-openbsd/lib/libc/stdlib/strtoull.c \
+    upstream-openbsd/lib/libc/stdlib/strtoumax.c \
+    upstream-openbsd/lib/libc/stdlib/system.c \
+    upstream-openbsd/lib/libc/stdlib/tfind.c \
+    upstream-openbsd/lib/libc/stdlib/tsearch.c \
+    upstream-openbsd/lib/libc/string/strcasecmp.c \
+    upstream-openbsd/lib/libc/string/strcspn.c \
+    upstream-openbsd/lib/libc/string/strdup.c \
+    upstream-openbsd/lib/libc/string/strndup.c \
+    upstream-openbsd/lib/libc/string/strpbrk.c \
+    upstream-openbsd/lib/libc/string/strsep.c \
+    upstream-openbsd/lib/libc/string/strspn.c \
+    upstream-openbsd/lib/libc/string/strstr.c \
+    upstream-openbsd/lib/libc/string/strtok.c \
+    upstream-openbsd/lib/libc/string/wcslcpy.c \
+    upstream-openbsd/lib/libc/string/wcsstr.c \
+    upstream-openbsd/lib/libc/string/wcswidth.c \
 
-ifeq ($(TARGET_ARCH),mips)
-libc_common_src_files += \
-    bionic/memchr.c \
-    bionic/memcmp.c \
-    bionic/memrchr.c \
-    bionic/strchr.cpp \
-    bionic/strnlen.c \
-    string/bcopy.c \
-    string/index.c \
-    string/strcat.c \
-    string/strcmp.c \
-    string/strcpy.c \
-    string/strlcat.c \
-    string/strlcpy.c \
-    string/strncat.c \
-    string/strncmp.c \
-    string/strncpy.c \
-    string/strrchr.c \
-    upstream-freebsd/lib/libc/string/wcscat.c \
-    upstream-freebsd/lib/libc/string/wcschr.c \
-    upstream-freebsd/lib/libc/string/wcscmp.c \
-    upstream-freebsd/lib/libc/string/wcscpy.c \
-    upstream-freebsd/lib/libc/string/wcslen.c \
-    upstream-freebsd/lib/libc/string/wcsrchr.c \
-    upstream-freebsd/lib/libc/string/wmemcmp.c \
-
-endif # mips
-
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
-libc_common_src_files += \
-    bionic/memchr.c \
-    bionic/memcmp.c \
-    bionic/memcpy.c \
-    bionic/memmove.c \
-    bionic/memrchr.c \
-    bionic/memset.c \
-    bionic/strchr.cpp \
-    bionic/strnlen.c \
-    string/bcopy.c \
-    string/index.c \
-    string/strcat.c \
-    string/strcmp.c \
-    string/strcpy.c \
-    string/strlcat.c \
-    string/strlcpy.c \
-    string/strlen.c \
-    string/strncat.c \
-    string/strncmp.c \
-    string/strncpy.c \
-    string/strrchr.c \
-    upstream-freebsd/lib/libc/string/wcscat.c \
-    upstream-freebsd/lib/libc/string/wcschr.c \
-    upstream-freebsd/lib/libc/string/wcscmp.c \
-    upstream-freebsd/lib/libc/string/wcscpy.c \
-    upstream-freebsd/lib/libc/string/wcslen.c \
-    upstream-freebsd/lib/libc/string/wcsrchr.c \
-    upstream-freebsd/lib/libc/string/wmemcmp.c \
-
-endif # x86_64
-
-ifeq ($(TARGET_ARCH),arm)
-  ifeq ($(strip $(TARGET_CPU_VARIANT)),)
-    $(warning TARGET_ARCH is arm, but TARGET_CPU_VARIANT is not defined)
-  endif
-endif
-
-###########################################################
-## Add cpu specific source files.
-##
-## This can be called multiple times, but it will only add
-## the first source file for each unique $(1).
-## $(1): Unique identifier to identify the cpu variant
-##       implementation.
-## $(2): Cpu specific source file.
-###########################################################
-
-define libc-add-cpu-variant-src
-$(if $(filter true,$(_LIBC_ARCH_CPU_VARIANT_HAS_$(1))), \
-	, \
-     $(eval _LIBC_ARCH_CPU_VARIANT_HAS_$(1) := true) \
-     $(eval _LIBC_ARCH_CPU_VARIANT_SRC_FILE.$(1) := $(2)) \
-     $(eval _LIBC_ARCH_CPU_VARIANT_SRC_FILES += $(2)) \
-)
-endef
-
-_LIBC_ARCH_COMMON_SRC_FILES :=
-_LIBC_ARCH_CPU_VARIANT_SRC_FILES :=
-_LIBC_ARCH_STATIC_SRC_FILES :=
-_LIBC_ARCH_DYNAMIC_SRC_FILES :=
-_LIBC_ARCH_ADDITIONAL_DEPENDENCIES :=
-
-libc_common_additional_dependencies += \
-    $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
-include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
-
-libc_bionic_src_files += $(_LIBC_ARCH_COMMON_SRC_FILES)
-libc_bionic_src_files += $(_LIBC_ARCH_CPU_VARIANT_SRC_FILES)
-libc_arch_static_src_files := $(_LIBC_ARCH_STATIC_SRC_FILES)
-libc_arch_dynamic_src_files := $(_LIBC_ARCH_DYNAMIC_SRC_FILES)
-libc_common_additional_dependencies += $(_LIBC_ARCH_ADDITIONAL_DEPENDENCIES)
+libc_arch_static_src_files := \
+    bionic/dl_iterate_phdr_static.cpp \
 
 # Define some common cflags
 # ========================================================
 libc_common_cflags := \
-    -DANDROID_CHANGES \
     -D_LIBC=1 \
-    -Wall -Wextra \
+    -Wall -Wextra -Wunused \
+
+ifneq ($(TARGET_USES_LOGD),false)
+libc_common_cflags += -DTARGET_USES_LOGD
+endif
+
+use_clang := false
 
 # Try to catch typical 32-bit assumptions that break with 64-bit pointers.
 libc_common_cflags += \
     -Werror=pointer-to-int-cast \
     -Werror=int-to-pointer-cast \
     -Werror=type-limits \
+    -Werror \
 
 ifeq ($(strip $(DEBUG_BIONIC_LIBC)),true)
   libc_common_cflags += -DDEBUG
 endif
 
+ifeq ($(MALLOC_IMPL),dlmalloc)
+  libc_common_cflags += -DUSE_DLMALLOC
+  libc_malloc_src := bionic/dlmalloc.c
+else
+  libc_common_cflags += -DUSE_JEMALLOC
+  libc_malloc_src := bionic/jemalloc_wrapper.cpp
+  libc_common_c_includes += external/jemalloc/include
+endif
+
 # To customize dlmalloc's alignment, set BOARD_MALLOC_ALIGNMENT in
 # the appropriate BoardConfig.mk file.
 #
@@ -605,36 +532,6 @@
   libc_common_cflags += -DMALLOC_ALIGNMENT=$(BOARD_MALLOC_ALIGNMENT)
 endif
 
-# crtbrand.c needs <stdint.h> and a #define for the platform SDK version.
-libc_crt_target_cflags := \
-    -I$(LOCAL_PATH)/include \
-    -I$(LOCAL_PATH)/arch-$(TARGET_ARCH)/include \
-    -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) \
-
-ifeq ($(TARGET_ARCH),arm)
-  libc_common_cflags += -DSOFTFLOAT
-  libc_common_cflags += -fstrict-aliasing
-  libc_crt_target_cflags += -mthumb-interwork
-endif # arm
-
-ifeq ($(TARGET_ARCH),mips)
-  ifneq ($(ARCH_MIPS_HAS_FPU),true)
-    libc_common_cflags += -DSOFTFLOAT
-  endif
-  libc_common_cflags += -fstrict-aliasing
-  libc_crt_target_cflags += $(TARGET_GLOBAL_CFLAGS)
-endif # mips
-
-ifeq ($(TARGET_ARCH),x86)
-  libc_crt_target_cflags += -m32
-  libc_crt_target_ldflags := -melf_i386
-endif # x86
-
-ifeq ($(TARGET_ARCH),x86_64)
-  libc_crt_target_cflags += -m64
-  libc_crt_target_ldflags := -melf_x86_64
-endif # x86_64
-
 # Define ANDROID_SMP appropriately.
 ifeq ($(TARGET_CPU_SMP),true)
     libc_common_cflags += -DANDROID_SMP=1
@@ -652,141 +549,24 @@
 
 # Define some common includes
 # ========================================================
-libc_common_c_includes := \
-		$(LOCAL_PATH)/stdlib  \
-		$(LOCAL_PATH)/string  \
-		$(LOCAL_PATH)/stdio   \
-		external/safe-iop/include
-
-# Define the libc run-time (crt) support object files that must be built,
-# which are needed to build all other objects (shared/static libs and
-# executables)
-# ==========================================================================
-# ARM, Arm64, MIPS, and x86 all need crtbegin_so/crtend_so.
-#
-# For x86, the .init section must point to a function that calls all
-# entries in the .ctors section. (on ARM this is done through the
-# .init_array section instead).
-#
-# For all the platforms, the .fini_array section must point to a function
-# that will call __cxa_finalize(&__dso_handle) in order to ensure that
-# static C++ destructors are properly called on dlclose().
-#
-libc_crt_target_crtbegin_file := $(LOCAL_PATH)/arch-common/bionic/crtbegin.c
-libc_crt_target_crtbegin_so_file := $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
-
-ifeq ($(TARGET_ARCH),arm)
-    libc_crt_target_so_cflags :=
-endif
-ifeq ($(TARGET_ARCH),arm64)
-    libc_crt_target_so_cflags :=
-    libc_crt_target_crtbegin_file := $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin.c
-endif
-ifeq ($(TARGET_ARCH),mips)
-    libc_crt_target_so_cflags := -fPIC
-    libc_crt_target_crtbegin_file := $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin.c
-endif
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
-    libc_crt_target_so_cflags := -fPIC
-endif
-libc_crt_target_so_cflags += $(libc_crt_target_cflags)
-
-# See the comment in crtbrand.c for the reason why we need to generate
-# crtbrand.s before generating crtbrand.o.
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.s
-$(GEN): $(LOCAL_PATH)/bionic/crtbrand.c
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_CC) $(libc_crt_target_so_cflags) -S \
-		-MD -MF $(@:%.s=%.d) -o $@ $<
-	$(hide) sed -i -e '/\.note\.ABI-tag/s/progbits/note/' $@
-	$(call transform-d-to-p-args,$(@:%.s=%.d),$(@:%.s=%.P))
--include $(GEN:%.s=%.P)
-ALL_GENERATED_SOURCES += $(GEN)
-
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
-$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.s
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_CC) $(libc_crt_target_so_cflags) -o $@ -c $<
-ALL_GENERATED_SOURCES += $(GEN)
-
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
-$(GEN): $(libc_crt_target_crtbegin_so_file)
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_CC) $(libc_crt_target_so_cflags) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
--include $(GEN:%.o=%.P)
-ALL_GENERATED_SOURCES += $(GEN)
-
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
-$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend_so.S
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_CC) $(libc_crt_target_so_cflags) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
--include $(GEN:%.o=%.P)
-ALL_GENERATED_SOURCES += $(GEN)
-
-# The following two are installed to device
-GEN := $(TARGET_OUT_SHARED_LIBRARIES)/crtbegin_so.o
-$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
-	$(hide) mkdir -p $(dir $@) && cp -f $< $@
-ALL_GENERATED_SOURCES += $(GEN)
-
-GEN := $(TARGET_OUT_SHARED_LIBRARIES)/crtend_so.o
-$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
-	$(hide) mkdir -p $(dir $@) && cp -f $< $@
-ALL_GENERATED_SOURCES += $(GEN)
-
-
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o
-$(GEN): $(libc_crt_target_crtbegin_file)
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_CC) $(libc_crt_target_cflags) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
--include $(GEN:%.o=%.P)
-ALL_GENERATED_SOURCES += $(GEN)
-
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
-$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_LD) $(libc_crt_target_ldflags) -r -o $@ $^
-ALL_GENERATED_SOURCES += $(GEN)
-
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o
-$(GEN): $(libc_crt_target_crtbegin_file)
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_CC) $(libc_crt_target_cflags) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
--include $(GEN:%.o=%.P)
-ALL_GENERATED_SOURCES += $(GEN)
-
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
-$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_LD) $(libc_crt_target_ldflags) -r -o $@ $^
-ALL_GENERATED_SOURCES += $(GEN)
-
-# We rename crtend.o to crtend_android.o to avoid a
-# name clash between gcc and bionic.
-GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
-$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend.S
-	@mkdir -p $(dir $@)
-	$(hide) $(TARGET_CC) $(libc_crt_target_cflags) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
--include $(GEN:%.o=%.P)
-ALL_GENERATED_SOURCES += $(GEN)
-
-
-# To enable malloc leak check for statically linked programs, add
-# "WITH_MALLOC_CHECK_LIBC_A := true" to buildspec.mk
-WITH_MALLOC_CHECK_LIBC_A := $(strip $(WITH_MALLOC_CHECK_LIBC_A))
+libc_common_c_includes += \
+    $(LOCAL_PATH)/stdio   \
 
 # ========================================================
-# libbionic_ssp.a - stack protector code
+# Add in the arch-specific flags.
+# Must be called with $(eval).
+# $(1): the LOCAL_ variable name
+# $(2): the bionic variable name to pull in
+define patch-up-arch-specific-flags
+$(1)_$(TARGET_ARCH) += $($(2)_$(TARGET_ARCH))
+ifdef TARGET_2ND_ARCH
+$(1)_$(TARGET_2ND_ARCH) += $($(2)_$(TARGET_2ND_ARCH))
+endif
+endef
+
+
+# ========================================================
+# libc_stack_protector.a - stack protector code
 # ========================================================
 #
 # The stack protector code needs to be compiled
@@ -796,14 +576,16 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := bionic/__stack_chk_fail.cpp
-LOCAL_CFLAGS := $(libc_common_cflags) -fno-stack-protector -Werror
+LOCAL_CFLAGS := $(libc_common_cflags) -fno-stack-protector
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_MODULE := libbionic_ssp
+LOCAL_MODULE := libc_stack_protector
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -813,20 +595,35 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES := $(libc_tzcode_src_files)
-LOCAL_CFLAGS := \
-    $(libc_common_cflags) \
-    -DSTD_INSPIRED=1 \
-    -DTZDIR=\"/system/usr/share/zoneinfo\" \
-    -DTM_GMTOFF=tm_gmtoff \
-    -DUSG_COMPAT=1
+LOCAL_SRC_FILES := $(call all-c-files-under,tzcode)
+# tzcode doesn't include wcsftime, so we use the OpenBSD one.
+LOCAL_SRC_FILES += upstream-openbsd/lib/libc/time/wcsftime.c
+
+LOCAL_CFLAGS := $(libc_common_cflags) \
+    -fvisibility=hidden \
+
+# Don't use ridiculous amounts of stack.
+LOCAL_CFLAGS += -DALL_STATE
+# Include tzsetwall, timelocal, timegm, time2posix, and posix2time.
+LOCAL_CFLAGS += -DSTD_INSPIRED
+# The name of the tm_gmtoff field in our struct tm.
+LOCAL_CFLAGS += -DTM_GMTOFF=tm_gmtoff
+# Where we store our tzdata.
+LOCAL_CFLAGS += -DTZDIR=\"/system/usr/share/zoneinfo\"
+# Include timezone and daylight globals.
+LOCAL_CFLAGS += -DUSG_COMPAT=1
+LOCAL_CFLAGS += -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
+LOCAL_CFLAGS += -Dlint
+
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_C_INCLUDES := $(libc_common_c_includes) $(LOCAL_PATH)/tzcode/
 LOCAL_MODULE := libc_tzcode
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -836,20 +633,33 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES := $(libc_dns_src_files)
+LOCAL_SRC_FILES := \
+    $(call all-c-files-under,dns) \
+    upstream-netbsd/lib/libc/isc/ev_streams.c \
+    upstream-netbsd/lib/libc/isc/ev_timers.c \
+    upstream-netbsd/lib/libc/resolv/mtctxres.c \
+
 LOCAL_CFLAGS := \
     $(libc_common_cflags) \
+    -DANDROID_CHANGES \
     -DINET6 \
+    -fvisibility=hidden \
+    -Wno-unused-parameter \
+    -I$(LOCAL_PATH)/dns/include \
     -I$(LOCAL_PATH)/private \
-    -I$(LOCAL_PATH)/upstream-netbsd/libc/include # for NetBSD private headers
+    -I$(LOCAL_PATH)/upstream-netbsd/lib/libc/include \
+    -I$(LOCAL_PATH)/upstream-netbsd/android/include \
+    -include netbsd-compat.h \
 
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_MODULE := libc_dns
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -865,16 +675,20 @@
 LOCAL_SRC_FILES := $(libc_upstream_freebsd_src_files)
 LOCAL_CFLAGS := \
     $(libc_common_cflags) \
-    -I$(LOCAL_PATH)/upstream-freebsd \
-    -I$(LOCAL_PATH)/upstream-freebsd/libc/include \
-    -include upstream-freebsd/freebsd-compat.h
+    -Wno-sign-compare -Wno-uninitialized \
+    -I$(LOCAL_PATH)/upstream-freebsd/android/include \
+    -I$(LOCAL_PATH)/upstream-freebsd/lib/libc/include \
+    -include freebsd-compat.h \
+
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_MODULE := libc_freebsd
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -890,17 +704,85 @@
 LOCAL_SRC_FILES := $(libc_upstream_netbsd_src_files)
 LOCAL_CFLAGS := \
     $(libc_common_cflags) \
+    -Wno-sign-compare -Wno-uninitialized \
     -DPOSIX_MISTAKE \
-    -I$(LOCAL_PATH)/upstream-netbsd \
-    -I$(LOCAL_PATH)/upstream-netbsd/libc/include \
-    -include upstream-netbsd/netbsd-compat.h
+    -I$(LOCAL_PATH)/upstream-netbsd/android/include \
+    -I$(LOCAL_PATH)/upstream-netbsd/lib/libc/include \
+    -include netbsd-compat.h \
+
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_MODULE := libc_netbsd
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_netbsd_src_files))
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
+# libc_openbsd.a - upstream OpenBSD C library code
+# ========================================================
+#
+# These files are built with the openbsd-compat.h header file
+# automatically included.
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(libc_upstream_openbsd_src_files)
+LOCAL_CFLAGS := \
+    $(libc_common_cflags) \
+    -Wno-sign-compare -Wno-uninitialized -Wno-unused-parameter \
+    -I$(LOCAL_PATH)/private \
+    -I$(LOCAL_PATH)/upstream-openbsd/android/include \
+    -I$(LOCAL_PATH)/upstream-openbsd/lib/libc/include \
+    -I$(LOCAL_PATH)/upstream-openbsd/lib/libc/gdtoa/ \
+    -include openbsd-compat.h \
+
+LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
+LOCAL_CPPFLAGS := $(libc_common_cppflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_MODULE := libc_openbsd
+LOCAL_CLANG := $(use_clang)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
+LOCAL_SYSTEM_SHARED_LIBRARIES :=
+
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
+# libc_gdtoa.a - upstream OpenBSD C library gdtoa code
+# ========================================================
+#
+# These files are built with the openbsd-compat.h header file
+# automatically included.
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES_32 := $(libc_upstream_openbsd_gdtoa_src_files_32)
+LOCAL_SRC_FILES_64 := $(libc_upstream_openbsd_gdtoa_src_files_64)
+LOCAL_CFLAGS := \
+    $(libc_common_cflags) \
+    -Wno-sign-compare -Wno-uninitialized \
+    -fvisibility=hidden \
+    -I$(LOCAL_PATH)/private \
+    -I$(LOCAL_PATH)/upstream-openbsd/android/include \
+    -I$(LOCAL_PATH)/upstream-openbsd/lib/libc/include \
+    -include openbsd-compat.h \
+
+LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
+LOCAL_CPPFLAGS := $(libc_common_cppflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_MODULE := libc_gdtoa
+LOCAL_CLANG := $(use_clang)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
+LOCAL_SYSTEM_SHARED_LIBRARIES :=
+
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -911,22 +793,81 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := $(libc_bionic_src_files)
-LOCAL_CFLAGS := $(libc_common_cflags) -Werror
+LOCAL_CFLAGS := $(libc_common_cflags) \
+    -Wframe-larger-than=2048 \
+
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_MODULE := libc_bionic
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
-# Set -DPTHREAD_DEBUG_ENABLED=true to enable support for pthread deadlock prediction.
-# Since this code is experimental it is disabled by default.
-LOCAL_CFLAGS += $(libc_common_cflags) -DPTHREAD_DEBUG_ENABLED=false
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_bionic_src_files))
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
+# libc_cxa.a - Things traditionally in libstdc++
+# ========================================================
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(libc_cxa_src_files)
+LOCAL_CFLAGS := $(libc_common_cflags) \
+    -fvisibility=hidden \
+
+LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
+LOCAL_CPPFLAGS := $(libc_common_cppflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_MODULE := libc_cxa
+# GCC refuses to hide new/delete
+LOCAL_CLANG := true
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
+LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
 include $(BUILD_STATIC_LIBRARY)
 
 
 # ========================================================
+# libc_syscalls.a
+# ========================================================
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES_$(TARGET_ARCH) := $(call all-S-files-under,arch-$(TARGET_ARCH)/syscalls)
+ifdef TARGET_2ND_ARCH
+LOCAL_SRC_FILES_$(TARGET_2ND_ARCH) := $(call all-S-files-under,arch-$(TARGET_2ND_ARCH)/syscalls)
+endif
+LOCAL_MODULE := libc_syscalls
+LOCAL_CLANG := $(use_clang)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
+LOCAL_SYSTEM_SHARED_LIBRARIES :=
+
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
+# libc_aeabi.a
+# This is an LP32 ARM-only library that needs to be built with -fno-builtin
+# to avoid infinite recursion. For the other architectures we just build an
+# empty library to keep this makefile simple.
+# ========================================================
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES_arm := arch-arm/bionic/__aeabi.c
+LOCAL_MODULE := libc_aeabi
+LOCAL_CLANG := $(use_clang)
+LOCAL_CFLAGS := $(libc_common_cflags) -fno-builtin
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
+LOCAL_SYSTEM_SHARED_LIBRARIES :=
+
+include $(BUILD_STATIC_LIBRARY)
+
+# ========================================================
 # libc_common.a
 # ========================================================
 
@@ -938,20 +879,35 @@
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_MODULE := libc_common
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_WHOLE_STATIC_LIBRARIES := \
-    libbionic_ssp \
     libc_bionic \
+    libc_cxa \
     libc_dns \
     libc_freebsd \
+    libc_gdtoa \
+    libc_malloc \
     libc_netbsd \
+    libc_openbsd \
+    libc_stack_protector \
+    libc_syscalls \
     libc_tzcode \
 
+LOCAL_WHOLE_STATIC_LIBRARIES_arm := libc_aeabi
+
+ifneq ($(MALLOC_IMPL),dlmalloc)
+LOCAL_WHOLE_STATIC_LIBRARIES += libjemalloc
+endif
+
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
 # TODO: split out the asflags.
 LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_common_src_files))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_ASFLAGS,LOCAL_CFLAGS))
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -962,27 +918,49 @@
 # This is a version of the static C library that does not
 # include malloc. It's useful in situations when the user wants
 # to provide their own malloc implementation, or wants to
-# explicitly disallow the use of the use of malloc,
-# such as in the dynamic loader.
+# explicitly disallow the use of malloc, such as in the
+# dynamic linker.
 
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
-	$(libc_arch_static_src_files) \
-	$(libc_static_common_src_files) \
-	bionic/libc_init_static.cpp
+    $(libc_arch_static_src_files) \
+    $(libc_static_common_src_files) \
+    bionic/libc_init_static.cpp
 
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_CFLAGS := $(libc_common_cflags) \
-                -DLIBC_STATIC
+    -DLIBC_STATIC \
+
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 
 LOCAL_MODULE := libc_nomalloc
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_arch_static_src_files))
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
+# libc_malloc.a: the _prefixed_ malloc functions (like dlcalloc).
+# ========================================================
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(libc_malloc_src)
+LOCAL_CFLAGS := $(libc_common_cflags) \
+    -fvisibility=hidden \
+
+LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
+LOCAL_CPPFLAGS := $(libc_common_cppflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_MODULE := libc_malloc
+LOCAL_CLANG := $(use_clang)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -992,22 +970,25 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
-	$(libc_arch_static_src_files) \
-	$(libc_static_common_src_files) \
-	bionic/dlmalloc.c \
-	bionic/malloc_debug_common.cpp \
-	bionic/libc_init_static.cpp
+    $(libc_arch_static_src_files) \
+    $(libc_static_common_src_files) \
+    bionic/malloc_debug_common.cpp \
+    bionic/libc_init_static.cpp \
 
 LOCAL_CFLAGS := $(libc_common_cflags) \
-                -DLIBC_STATIC
+    -DLIBC_STATIC \
+
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_MODULE := libc
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_arch_static_src_files))
 include $(BUILD_STATIC_LIBRARY)
 
 
@@ -1020,44 +1001,52 @@
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
-
 LOCAL_SRC_FILES := \
     $(libc_arch_dynamic_src_files) \
     $(libc_static_common_src_files) \
-    bionic/dlmalloc.c \
     bionic/malloc_debug_common.cpp \
-    bionic/debug_mapinfo.cpp \
-    bionic/debug_stacktrace.cpp \
-    bionic/pthread_debug.cpp \
     bionic/libc_init_dynamic.cpp \
+    bionic/NetdClient.cpp \
 
-ifeq ($(TARGET_ARCH),arm)
-	LOCAL_NO_CRT := true
-	LOCAL_CFLAGS += -DCRT_LEGACY_WORKAROUND
-
-	LOCAL_SRC_FILES := \
-		arch-common/bionic/crtbegin_so.c \
-		arch-arm/bionic/atexit_legacy.c \
-		$(LOCAL_SRC_FILES) \
-		arch-common/bionic/crtend_so.S
-endif
-
-LOCAL_MODULE:= libc
+LOCAL_MODULE := libc
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 LOCAL_REQUIRED_MODULES := tzdata
 
+# Leave the symbols in the shared library so that stack unwinders can produce
+# meaningful name resolution.
+LOCAL_STRIP_MODULE := keep_symbols
+
 # WARNING: The only library libc.so should depend on is libdl.so!  If you add other libraries,
 # make sure to add -Wl,--exclude-libs=libgcc.a to the LOCAL_LDFLAGS for those libraries.  This
 # ensures that symbols that are pulled into those new libraries from libgcc.a are not declared
 # external; if that were the case, then libc would not pull those symbols from libgcc.a as it
 # should, instead relying on the external symbols from the dependent libraries.  That would
-# create an "cloaked" dependency on libgcc.a in libc though the libraries, which is not what
+# create a "cloaked" dependency on libgcc.a in libc though the libraries, which is not what
 # you wanted!
 
 LOCAL_SHARED_LIBRARIES := libdl
 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
+# We'd really like to do this for all architectures, but since this wasn't done
+# before, these symbols must continue to be exported on LP32 for binary
+# compatibility.
+LOCAL_LDFLAGS_arm64 := -Wl,--exclude-libs,libgcc.a
+LOCAL_LDFLAGS_mips64 := -Wl,--exclude-libs,libgcc.a
+LOCAL_LDFLAGS_x86_64 := -Wl,--exclude-libs,libgcc.a
+
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_arch_dynamic_src_files))
+$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_static_common_src_files))
+# special for arm
+LOCAL_NO_CRT_arm := true
+LOCAL_CFLAGS_arm += -DCRT_LEGACY_WORKAROUND
+LOCAL_SRC_FILES_arm += \
+    arch-common/bionic/crtbegin_so.c \
+    arch-arm/bionic/atexit_legacy.c \
+    arch-common/bionic/crtend_so.S
+
 include $(BUILD_SHARED_LIBRARY)
 
 
@@ -1075,30 +1064,38 @@
 include $(CLEAR_VARS)
 
 LOCAL_CFLAGS := \
-	$(libc_common_cflags) \
-	-DMALLOC_LEAK_CHECK
+    $(libc_common_cflags) \
+    -DMALLOC_LEAK_CHECK \
+
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
+# Make sure that unwind.h comes from libunwind.
+LOCAL_C_INCLUDES := \
+    $(libc_common_c_includes) \
 
 LOCAL_SRC_FILES := \
-	bionic/debug_mapinfo.cpp \
-	bionic/debug_stacktrace.cpp \
-	bionic/malloc_debug_leak.cpp \
-	bionic/malloc_debug_check.cpp \
+    bionic/debug_mapinfo.cpp \
+    bionic/debug_stacktrace.cpp \
+    bionic/libc_logging.cpp \
+    bionic/malloc_debug_leak.cpp \
+    bionic/malloc_debug_check.cpp \
 
-LOCAL_MODULE:= libc_malloc_debug_leak
+LOCAL_MODULE := libc_malloc_debug_leak
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 
 LOCAL_SHARED_LIBRARIES := libc libdl
-LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
+# Only need this for arm since libc++ uses its own unwind code that
+# doesn't mix with the other default unwind code.
+LOCAL_STATIC_LIBRARIES_arm := libc++
 LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
 
 # Don't install on release build
 LOCAL_MODULE_TAGS := eng debug
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
 include $(BUILD_SHARED_LIBRARY)
 
 
@@ -1108,29 +1105,62 @@
 include $(CLEAR_VARS)
 
 LOCAL_CFLAGS := \
-	$(libc_common_cflags) \
-	-DMALLOC_QEMU_INSTRUMENT
+    $(libc_common_cflags) \
+    -DMALLOC_QEMU_INSTRUMENT \
+
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 
 LOCAL_SRC_FILES := \
-	bionic/malloc_debug_qemu.cpp
+    bionic/libc_logging.cpp \
+    bionic/malloc_debug_qemu.cpp \
 
-LOCAL_MODULE:= libc_malloc_debug_qemu
+LOCAL_MODULE := libc_malloc_debug_qemu
+LOCAL_CLANG := $(use_clang)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
 
 LOCAL_SHARED_LIBRARIES := libc libdl
-LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
 # Don't install on release build
 LOCAL_MODULE_TAGS := eng debug
 
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
 include $(BUILD_SHARED_LIBRARY)
 
-endif	#!user
+endif  #!user
+
+# ========================================================
+# libstdc++.so
+# ========================================================
+libstdcxx_common_src_files := \
+    bionic/__cxa_guard.cpp \
+    bionic/__cxa_pure_virtual.cpp \
+    bionic/new.cpp \
+    bionic/libc_logging.cpp \
+
+include $(CLEAR_VARS)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_CFLAGS := $(libc_common_cflags)
+LOCAL_SRC_FILES := $(libstdcxx_common_src_files)
+LOCAL_MODULE:= libstdc++
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc
+include $(BUILD_SHARED_LIBRARY)
+
+# ========================================================
+# libstdc++.a
+# ========================================================
+include $(CLEAR_VARS)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_CFLAGS := $(libc_common_cflags)
+LOCAL_SRC_FILES := $(libstdcxx_common_src_files)
+LOCAL_MODULE:= libstdc++
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc
+include $(BUILD_STATIC_LIBRARY)
 
 
 # ========================================================
diff --git a/libc/NOTICE b/libc/NOTICE
index a737001..80d9a27 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -1,3 +1,90 @@
+   Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+   strchr - find a character in a string
+
+   Copyright (c) 2014, ARM Limited
+   All rights Reserved.
+   Copyright (c) 2014, Linaro Ltd.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the company nor the names of its contributors
+         may be used to endorse or promote products derived from this
+         software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+ Copyright (c) 1993 John Brezak
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ 3. The name of the author may be used to endorse or promote products
+    derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 ====================================================
 Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 
@@ -8,6 +95,38 @@
 
 -------------------------------------------------------------------
 
+Based on the UCB version with the ID appearing below.
+This is ANSIish only when "multibyte character == plain character".
+
+Copyright (c) 1989, 1993
+   The Regents of the University of California.  All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. Neither the name of the University nor the names of its contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
 All rights reserved.
 
@@ -72,14 +191,74 @@
 -------------------------------------------------------------------
 
 Copyright (C) 2006 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2006 The Android Open Source Project
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in
+   the documentation and/or other materials provided with the
+   distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2008 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2008 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -101,13 +280,14 @@
 
 Copyright (C) 2008 The Android Open Source Project
 All rights reserved.
+Copyright (c) 2013-2014, NVIDIA Corporation.  All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -133,9 +313,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -156,14 +336,30 @@
 -------------------------------------------------------------------
 
 Copyright (C) 2009 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2009 The Android Open Source Project
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -205,9 +401,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -280,9 +476,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -324,9 +520,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -368,9 +564,111 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in
+   the documentation and/or other materials provided with the
+   distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2013 The Android Open Source Project
+All rights reserved.
+Copyright (c) 2013-2014 NVIDIA Corporation.  All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in
+   the documentation and/or other materials provided with the
+   distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2013 The Android Open Source Project
+Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in
+   the documentation and/or other materials provided with the
+   distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2014 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2014 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -442,35 +740,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1980, 1993
-   The Regents of the University of California.  All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 1982, 1986, 1993
    The Regents of the University of California.  All rights reserved.
 
@@ -563,35 +832,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1983, 1988, 1993
-   The Regents of the University of California.  All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 1983, 1989
    The Regents of the University of California.  All rights reserved.
 
@@ -665,11 +905,7 @@
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-3. All advertising materials mentioning features or use of this software
-   must display the following acknowledgement:
-    This product includes software developed by the University of
-    California, Berkeley and its contributors.
-4. Neither the name of the University nor the names of its contributors
+3. Neither the name of the University nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.
 
@@ -685,6 +921,24 @@
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.
 
+Portions Copyright (c) 1993 by Digital Equipment Corporation.
+
+Permission to use, copy, modify, and 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, and that
+the name of Digital Equipment Corporation not be used in advertising or
+publicity pertaining to distribution of the document or software without
+specific, written prior permission.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+CORPORATION 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.
+
 -------------------------------------------------------------------
 
 Copyright (c) 1983, 1993
@@ -1099,35 +1353,6 @@
 -------------------------------------------------------------------
 
 Copyright (c) 1988, 1993
-    The Regents of the University of California.  All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-Copyright (c) 1988, 1993
    The Regents of the University of California.  All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -1232,7 +1457,7 @@
 by the University of California, Berkeley. The name of the
 University may not be used to endorse or promote products derived
 from this software without specific prior written permission.
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
@@ -1361,11 +1586,9 @@
 
 Copyright (c) 1989, 1993
    The Regents of the University of California.  All rights reserved.
-(c) UNIX System Laboratories, Inc.
-All or some portions of this file are derived from material licensed
-to the University of California by American Telephone and Telegraph
-Co. or Unix System Laboratories, Inc. and are reproduced herein with
-the permission of UNIX System Laboratories, Inc.
+
+This code is derived from software contributed to Berkeley by
+Roger L. Snyder.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
@@ -1401,9 +1624,6 @@
 Co. or Unix System Laboratories, Inc. and are reproduced herein with
 the permission of UNIX System Laboratories, Inc.
 
-This code is derived from software contributed to Berkeley by
-Paul Borman at Krystal Technologies.
-
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
@@ -1412,7 +1632,7 @@
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-4. Neither the name of the University nor the names of its contributors
+3. Neither the name of the University nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.
 
@@ -1707,6 +1927,38 @@
 
 Copyright (c) 1990, 1993
    The Regents of the University of California.  All rights reserved.
+
+This code is derived from software contributed to Berkeley by
+Donn Seeley at UUNET Technologies, Inc.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+4. Neither the name of the University nor the names of its contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 1990, 1993
+   The Regents of the University of California.  All rights reserved.
 (c) UNIX System Laboratories, Inc.
 All or some portions of this file are derived from material licensed
 to the University of California by American Telephone and Telegraph
@@ -1800,6 +2052,35 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 1991 The Regents of the University of California.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. Neither the name of the University nor the names of its contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 1991, 1993
    The Regents of the University of California.  All rights reserved.
 
@@ -2130,44 +2411,6 @@
 
 Copyright (c) 1992, 1993
    The Regents of the University of California.  All rights reserved.
-
-This software was developed by the Computer Systems Engineering group
-at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
-contributed to Berkeley.
-
-All advertising materials mentioning features or use of this software
-must display the following acknowledgement:
-   This product includes software developed by the University of
-   California, Lawrence Berkeley Laboratory.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-Copyright (c) 1992, 1993
-   The Regents of the University of California.  All rights reserved.
 (c) UNIX System Laboratories, Inc.
 All or some portions of this file are derived from material licensed
 to the University of California by American Telephone and Telegraph
@@ -2365,92 +2608,30 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1994 The NetBSD Foundation, Inc.
-All rights reserved.
-
-This code is derived from software contributed to The NetBSD Foundation
-by Christos Zoulas.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
-(Royal Institute of Technology, Stockholm, Sweden).
+Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-3. Neither the name of the Institute nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
-       at Electronni Visti IA, Kiev, Ukraine.
-           All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
 
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 -------------------------------------------------------------------
 
@@ -2500,6 +2681,24 @@
 
 Copyright (c) 1996, David Mazieres <dm@uun.org>
 Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
+
+Permission to use, copy, modify, and 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.
+
+-------------------------------------------------------------------
+
+Copyright (c) 1996-1998, 2008 Theo de Raadt
+Copyright (c) 1997, 2008-2009 Todd C. Miller
 
 Permission to use, copy, modify, and distribute this software for any
 purpose with or without fee is hereby granted, provided that the above
@@ -2645,6 +2844,33 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
 All rights reserved.
 
@@ -2694,13 +2920,6 @@
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-3. All advertising materials mentioning features or use of this software
-   must display the following acknowledgement:
-       This product includes software developed by the NetBSD
-       Foundation, Inc. and its contributors.
-4. Neither the name of The NetBSD Foundation nor the names of its
-   contributors may be used to endorse or promote products derived
-   from this software without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -2752,42 +2971,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1997, 1998, 2003 The NetBSD Foundation, Inc.
-All rights reserved.
-
-This code is derived from software contributed to The NetBSD Foundation
-by J.T. Conklin, by Nathan J. Williams, and by Jason R. Thorpe.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. All advertising materials mentioning features or use of this software
-   must display the following acknowledgement:
-       This product includes software developed by the NetBSD
-       Foundation, Inc. and its contributors.
-4. Neither the name of The NetBSD Foundation nor the names of its
-   contributors may be used to endorse or promote products derived
-   from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 1997, 2005 Todd C. Miller <Todd.Miller@courtesan.com>
 
 Permission to use, copy, modify, and distribute this software for any
@@ -2980,35 +3163,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1999 The NetBSD Foundation, Inc.
-All rights reserved.
-
-This code is derived from software contributed to The NetBSD Foundation
-by Michael Graff.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 2000 Ben Harris.
 Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
 All rights reserved.
@@ -3314,13 +3468,6 @@
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-3. All advertising materials mentioning features or use of this software
-   must display the following acknowledgement:
-       This product includes software developed by the NetBSD
-       Foundation, Inc. and its contributors.
-4. Neither the name of The NetBSD Foundation nor the names of its
-   contributors may be used to endorse or promote products derived
-   from this software without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -3362,6 +3509,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2002 Tim J. Robbins.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
 
 Permission to use, copy, modify, and distribute this software for any
@@ -3382,6 +3555,84 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2002, 2003 Tim J. Robbins.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2002-2004 Tim J. Robbins
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2002-2004 Tim J. Robbins.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru>
 
 Redistribution and use in source and binary forms, with or without
@@ -3410,6 +3661,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2003 David Schultz <das@FreeBSD.ORG>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2003 Networks Associates Technology, Inc.
 All rights reserved.
 
@@ -3651,6 +3928,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2004, 2005 David Schultz <das@FreeBSD.ORG>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2005 Tim J. Robbins.
 All rights reserved.
 
@@ -3799,6 +4102,22 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+
+Permission to use, copy, modify, and 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.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2009
      MIPS Technologies, Inc., California.
 
@@ -3831,6 +4150,37 @@
 Copyright (c) 2009 David Schultz <das@FreeBSD.org>
 All rights reserved.
 
+Copyright (c) 2011 The FreeBSD Foundation
+All rights reserved.
+Portions of this software were developed by David Chisnall
+under sponsorship from the FreeBSD Foundation.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2009 David Schultz <das@FreeBSD.org>
+All rights reserved.
+
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
@@ -3889,13 +4239,13 @@
 modification, are permitted provided that the following conditions
 are met:
 
-    Redistributions of source code must retain the above copyright
+     * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
-    Redistributions in binary form must reproduce the above copyright
+     * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer
        in the documentation and/or other materials provided with
        the distribution.
-    Neither the name of MIPS Technologies Inc. nor the names of its
+     * Neither the name of MIPS Technologies Inc. nor the names of its
        contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.
 
@@ -3913,22 +4263,38 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
+
+Permission to use, copy, modify, and 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.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2010, 2011, 2012, 2013 Intel Corporation
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
-   Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
 
-   Redistributions in binary form must reproduce the above copyright notice,
-   this list of conditions and the following disclaimer in the documentation
-   and/or other materials provided with the distribution.
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
 
-   Neither the name of Intel Corporation nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -3949,16 +4315,16 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
-   Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
 
-   Redistributions in binary form must reproduce the above copyright notice,
-   this list of conditions and the following disclaimer in the documentation
-   and/or other materials provided with the distribution.
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
 
-   Neither the name of Intel Corporation nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -3973,22 +4339,75 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2011 David Chisnall
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
+                   David Chisnall <theraven@FreeBSD.org>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2011 Intel Corporation
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
-   Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
 
-   Redistributions in binary form must reproduce the above copyright notice,
-   this list of conditions and the following disclaimer in the documentation
-   and/or other materials provided with the distribution.
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
 
-   Neither the name of Intel Corporation nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -4038,16 +4457,16 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
-   Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
 
-   Redistributions in binary form must reproduce the above copyright notice,
-   this list of conditions and the following disclaimer in the documentation
-   and/or other materials provided with the distribution.
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
 
-   Neither the name of Intel Corporation nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -4068,16 +4487,16 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
-   Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
 
-   Redistributions in binary form must reproduce the above copyright notice,
-   this list of conditions and the following disclaimer in the documentation
-   and/or other materials provided with the distribution.
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
 
-   Neither the name of Intel Corporation nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -4097,12 +4516,12 @@
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
-   Redistributions of source code must retain the above copyright
+    * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
-   Redistributions in binary form must reproduce the above copyright
+    * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
-   Neither the name of the VMware, Inc. nor the names of its contributors
+    * Neither the name of the VMware, Inc. nor the names of its contributors
       may be used to endorse or promote products derived from this software
       without specific prior written permission.
 
@@ -4119,6 +4538,63 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+   Copyright (c) 2014, NVIDIA Corporation.  All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2013 ARM Ltd
 All rights reserved.
 
@@ -4147,63 +4623,19 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 2013 Intel Corporation
-All rights reserved.
+Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
 
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
+Permission to use, copy, modify, and 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.
 
-   Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
-
-   Redistributions in binary form must reproduce the above copyright notice,
-   this list of conditions and the following disclaimer in the documentation
-   and/or other materials provided with the distribution.
-
-   Neither the name of Intel Corporation nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
--------------------------------------------------------------------
-
-Copyright (c) 2013, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-   Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
-
-   Redistributions in binary form must reproduce the above copyright notice,
-   this list of conditions and the following disclaimer in the documentation
-   and/or other materials provided with the distribution.
-
-   Neither the name of Intel Corporation nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+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.
 
 -------------------------------------------------------------------
 
@@ -4214,14 +4646,14 @@
    modification, are permitted provided that the following conditions
    are met:
 
-     Redistributions of source code must retain the above copyright
+      * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
 
-     Redistributions in binary form must reproduce the above copyright
+      * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
 
-     Neither the name of Linaro Limited nor the names of its
+      * Neither the name of Linaro Limited nor the names of its
       contributors may be used to endorse or promote products derived
       from this software without specific prior written permission.
 
@@ -4239,6 +4671,84 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
+Copyright (c) 2014 Bob Beck <beck@obtuse.com>
+
+Permission to use, copy, modify, and 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.
+
+Emulation of getentropy(2) as documented at:
+http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2
+
+-------------------------------------------------------------------
+
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c)1999 Citrus Project,
 All rights reserved.
 
@@ -4265,6 +4775,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c)1999, 2000, 2001 Citrus Project,
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c)2001 Citrus Project,
 All rights reserved.
 
@@ -4291,21 +4827,9 @@
 
 -------------------------------------------------------------------
 
-Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
-Copyright 2008 Damien Miller <djm@openbsd.org>
-Copyright 2008 Android Open Source Project (thread-safety)
+Copyright (c)2003 Citrus Project,
 All rights reserved.
 
-Theo de Raadt <deraadt@openbsd.org> came up with the idea of using
-such a mathematical system to generate more random (yet non-repeating)
-ids to solve the resolver/named problem.  But Niels designed the
-actual system based on the constraints.
-
-Later modified by Damien Miller to wrap the LCG output in a 15-bit
-permutation generator based on a Luby-Rackoff block cipher. This
-ensures the output is non-repeating and preserves the MSB twiddle
-trick, but makes it more resistant to LCG prediction.
-
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
@@ -4315,16 +4839,17 @@
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
 
 -------------------------------------------------------------------
 
@@ -4353,32 +4878,6 @@
 
 -------------------------------------------------------------------
 
-Copyright 2006, The Android Open Source Project
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-   Redistributions of source code must retain the above copyright
-      notice, this list of conditions and the following disclaimer.
-   Redistributions in binary form must reproduce the above copyright
-      notice, this list of conditions and the following disclaimer in the
-      documentation and/or other materials provided with the distribution.
-   Neither the name of Google Inc. nor the names of its contributors may
-      be used to endorse or promote products derived from this software
-      without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright 2008  Android Open Source Project (source port randomization)
 Copyright (c) 1985, 1989, 1993
    The Regents of the University of California.  All rights reserved.
@@ -4413,6 +4912,23 @@
 
 -------------------------------------------------------------------
 
+Portions Copyright (C) 2004, 2005, 2008, 2009  Internet Systems Consortium, Inc. ("ISC")
+Portions Copyright (C) 1996-2003  Internet Software Consortium.
+
+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 ISC DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS.  IN NO EVENT SHALL ISC 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.
+
+-------------------------------------------------------------------
+
 Portions Copyright (c) 1993 by Digital Equipment Corporation.
 
 Permission to use, copy, modify, and distribute this software for any
@@ -4485,18 +5001,188 @@
 
 The author of this software is David M. Gay.
 
-Copyright (c) 1991 by AT&T.
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
 
-Permission to use, copy, modify, and distribute this software for any
-purpose without fee is hereby granted, provided that this entire notice
-is included in all copies of any software which is or includes a copy
-or modification of this software and in all copies of the supporting
-documentation for such software.
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
 
-THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
-WARRANTY.  IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
-REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
-OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+-------------------------------------------------------------------
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+-------------------------------------------------------------------
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+-------------------------------------------------------------------
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998-2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+-------------------------------------------------------------------
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998-2001 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+-------------------------------------------------------------------
+
+The author of this software is David M. Gay.
+
+Copyright (C) 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+-------------------------------------------------------------------
+
+memchr - find a character in a memory zone
+
+Copyright (c) 2014, ARM Limited
+All rights Reserved.
+Copyright (c) 2014, Linaro Ltd.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of the company nor the names of its contributors
+      may be used to endorse or promote products derived from this
+      software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 -------------------------------------------------------------------
 
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 0951648..c3b7bab 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -6,7 +6,7 @@
 #
 # where:
 #       arch_list ::= "all" | arch+
-#       arch      ::= "arm" | "arm64" | "mips" | "x86" | "x86_64"
+#       arch      ::= "arm" | "arm64" | "mips" | "mips64" | "x86" | "x86_64"
 #
 # Note:
 #      - syscall_name corresponds to the name of the syscall, which may differ from
@@ -27,41 +27,38 @@
 int     execve(const char*, char* const*, char* const*)  all
 
 uid_t   getuid:getuid32()         arm,x86
-uid_t   getuid:getuid()           arm64,mips,x86_64
+uid_t   getuid:getuid()           arm64,mips,mips64,x86_64
 gid_t   getgid:getgid32()         arm,x86
-gid_t   getgid:getgid()           arm64,mips,x86_64
+gid_t   getgid:getgid()           arm64,mips,mips64,x86_64
 uid_t   geteuid:geteuid32()       arm,x86
-uid_t   geteuid:geteuid()         arm64,mips,x86_64
+uid_t   geteuid:geteuid()         arm64,mips,mips64,x86_64
 gid_t   getegid:getegid32()       arm,x86
-gid_t   getegid:getegid()         arm64,mips,x86_64
+gid_t   getegid:getegid()         arm64,mips,mips64,x86_64
 uid_t   getresuid:getresuid32(uid_t* ruid, uid_t* euid, uid_t* suid)   arm,x86
-uid_t   getresuid:getresuid(uid_t* ruid, uid_t* euid, uid_t* suid)     arm64,mips,x86_64
+uid_t   getresuid:getresuid(uid_t* ruid, uid_t* euid, uid_t* suid)     arm64,mips,mips64,x86_64
 gid_t   getresgid:getresgid32(gid_t* rgid, gid_t* egid, gid_t* sgid)   arm,x86
-gid_t   getresgid:getresgid(gid_t* rgid, gid_t* egid, gid_t* sgid)     arm64,mips,x86_64
-pid_t   gettid()                   all
+gid_t   getresgid:getresgid(gid_t* rgid, gid_t* egid, gid_t* sgid)     arm64,mips,mips64,x86_64
 ssize_t readahead(int, off64_t, size_t)     all
 int     getgroups:getgroups32(int, gid_t*)    arm,x86
-int     getgroups:getgroups(int, gid_t*)      arm64,mips,x86_64
+int     getgroups:getgroups(int, gid_t*)      arm64,mips,mips64,x86_64
 pid_t   getpgid(pid_t)             all
 pid_t   getppid()                  all
 pid_t   getsid(pid_t)              all
 pid_t   setsid()                   all
 int     setgid:setgid32(gid_t)     arm,x86
-int     setgid:setgid(gid_t)       arm64,mips,x86_64
+int     setgid:setgid(gid_t)       arm64,mips,mips64,x86_64
 int     setuid:setuid32(uid_t)    arm,x86
-int     setuid:setuid(uid_t)      arm64,mips,x86_64
+int     setuid:setuid(uid_t)      arm64,mips,mips64,x86_64
 int     setreuid:setreuid32(uid_t, uid_t)   arm,x86
-int     setreuid:setreuid(uid_t, uid_t)     arm64,mips,x86_64
+int     setreuid:setreuid(uid_t, uid_t)     arm64,mips,mips64,x86_64
 int     setresuid:setresuid32(uid_t, uid_t, uid_t)   arm,x86
-int     setresuid:setresuid(uid_t, uid_t, uid_t)     arm64,mips,x86_64
+int     setresuid:setresuid(uid_t, uid_t, uid_t)     arm64,mips,mips64,x86_64
 int     setresgid:setresgid32(gid_t, gid_t, gid_t)   arm,x86
-int     setresgid:setresgid(gid_t, gid_t, gid_t)     arm64,mips,x86_64
+int     setresgid:setresgid(gid_t, gid_t, gid_t)     arm64,mips,mips64,x86_64
 void*   __brk:brk(void*)           all
 int     kill(pid_t, int)           all
-int     tkill(pid_t tid, int sig)  all
 int     tgkill(pid_t tgid, pid_t tid, int sig)  all
 int     __ptrace:ptrace(int request, int pid, void* addr, void* data)  all
-int     __set_thread_area:set_thread_area(void*  user_desc)  mips,x86
 
 # <sys/resource.h>
 int getrusage(int, struct rusage*)  all
@@ -71,22 +68,20 @@
 # On 32-bit systems we use prlimit64 to implement the rlimit64 functions.
 int getrlimit:ugetrlimit(int, struct rlimit*)  arm,x86
 int getrlimit(int, struct rlimit*)  mips
-int getrlimit|getrlimit64(int, struct rlimit*)  arm64,x86_64
+int getrlimit|getrlimit64(int, struct rlimit*)  arm64,mips64,x86_64
 int setrlimit(int, const struct rlimit*)  arm,mips,x86
-int setrlimit|setrlimit64(int, const struct rlimit*)  arm64,x86_64
-int prlimit64|prlimit(pid_t, int, struct rlimit64*, const struct rlimit64*)  arm64,x86_64
+int setrlimit|setrlimit64(int, const struct rlimit*)  arm64,mips64,x86_64
+int prlimit64|prlimit(pid_t, int, struct rlimit64*, const struct rlimit64*)  arm64,mips64,x86_64
 int prlimit64(pid_t, int, struct rlimit64*, const struct rlimit64*)  arm,mips,x86
 
 int     setgroups:setgroups32(int, const gid_t*)   arm,x86
-int     setgroups:setgroups(int, const gid_t*)     arm64,mips,x86_64
+int     setgroups:setgroups(int, const gid_t*)     arm64,mips,mips64,x86_64
 int     setpgid(pid_t, pid_t)  all
 pid_t   vfork(void)  arm
 int     setregid:setregid32(gid_t, gid_t)  arm,x86
-int     setregid:setregid(gid_t, gid_t)    arm64,mips,x86_64
+int     setregid:setregid(gid_t, gid_t)    arm64,mips,mips64,x86_64
 int     chroot(const char*)  all
-# IMPORTANT: Even though <sys/prctl.h> declares prctl(int, ...), the syscall stub must take 6 arguments
-#            to match the kernel implementation.
-int     prctl(int option, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5) all
+int     prctl(int, unsigned long, unsigned long, unsigned long, unsigned long) all
 long    __arch_prctl:arch_prctl(int, unsigned long) x86_64
 int     capget(cap_user_header_t header, cap_user_data_t data) all
 int     capset(cap_user_header_t header, const cap_user_data_t data) all
@@ -97,11 +92,11 @@
 ssize_t     read(int, void*, size_t)        all
 ssize_t     write(int, const void*, size_t)       all
 ssize_t     pread64(int, void*, size_t, off64_t) arm,mips,x86
-ssize_t     pread64|pread(int, void*, size_t, off_t) arm64,x86_64
+ssize_t     pread64|pread(int, void*, size_t, off_t) arm64,mips64,x86_64
 ssize_t     pwrite64(int, void*, size_t, off64_t) arm,mips,x86
-ssize_t     pwrite64|pwrite(int, void*, size_t, off_t) arm64,x86_64
+ssize_t     pwrite64|pwrite(int, void*, size_t, off_t) arm64,mips64,x86_64
 int         close(int)                      all
-pid_t       getpid()    all
+pid_t       __getpid:getpid()  all
 int         munmap(void*, size_t)  all
 void*       mremap(void*, size_t, size_t, unsigned long)  all
 int         msync(const void*, size_t, int)    all
@@ -116,31 +111,30 @@
 int         readv(int, const struct iovec*, int)   all
 int         writev(int, const struct iovec*, int)  all
 int         __fcntl64:fcntl64(int, int, void*)  arm,mips,x86
-int         fcntl(int, int, void*)  arm64,x86_64
+int         fcntl(int, int, void*)  arm64,mips64,x86_64
 int         flock(int, int)   all
 int         fchmod(int, mode_t)  all
 int         dup(int)  all
 int         pipe2(int*, int) all
 int         dup3(int, int, int)   all
-int         getdents:getdents64(unsigned int, struct dirent*, unsigned int)   all
 int         fsync(int)  all
 int         fdatasync(int) all
 int         fchown:fchown32(int, uid_t, gid_t)  arm,x86
-int         fchown:fchown(int, uid_t, gid_t)    arm64,mips,x86_64
+int         fchown:fchown(int, uid_t, gid_t)    arm64,mips,mips64,x86_64
 void        sync(void)  all
-int         __fstatfs64:fstatfs64(int, size_t, struct statfs*)  arm,mips,x86
-int         fstatfs(int, struct statfs*)  arm64,x86_64
 int         fsetxattr(int, const char*, const void*, size_t, int) all
 ssize_t     fgetxattr(int, const char*, void*, size_t) all
 ssize_t     flistxattr(int, char*, size_t) all
 int         fremovexattr(int, const char*) all
 
+int __getdents64:getdents64(unsigned int, struct dirent*, unsigned int)   arm,arm64,mips,mips64,x86,x86_64
+
 int __openat:openat(int, const char*, int, mode_t) all
 int faccessat(int, const char*, int, int)  all
 int fchmodat(int, const char*, mode_t, int)  all
 int fchownat(int, const char*, uid_t, gid_t, int)  all
-int fstatat:fstatat64(int, const char*, struct stat*, int)   arm,mips,x86
-int fstatat:newfstatat(int, const char*, struct stat*, int)  arm64,x86_64
+int fstatat64|fstatat:fstatat64(int, const char*, struct stat*, int)   arm,mips,x86
+int fstatat64|fstatat:newfstatat(int, const char*, struct stat*, int)  arm64,mips64,x86_64
 int linkat(int, const char*, int, const char*, int)  all
 int mkdirat(int, const char*, mode_t)  all
 int mknodat(int, const char*, mode_t, dev_t)  all
@@ -156,26 +150,41 @@
 # That means that every system call in this section should take three lines.
 off_t lseek(int, off_t, int) arm,mips,x86
 int __llseek:_llseek(int, unsigned long, unsigned long, off64_t*, int) arm,mips,x86
-off_t lseek|lseek64(int, off_t, int) arm64,x86_64
+off_t lseek|lseek64(int, off_t, int) arm64,mips64,x86_64
 int ftruncate(int, off_t) arm,mips,x86
 int ftruncate64(int, off64_t) arm,mips,x86
-int ftruncate|ftruncate64(int, off_t) arm64,x86_64
+int ftruncate|ftruncate64(int, off_t) arm64,mips64,x86_64
 ssize_t sendfile(int out_fd, int in_fd, off_t* offset, size_t count) arm,mips,x86
 ssize_t sendfile64(int out_fd, int in_fd, off64_t* offset, size_t count) arm,mips,x86
-ssize_t sendfile|sendfile64(int out_fd, int in_fd, off_t* offset, size_t count) arm64,x86_64
+ssize_t sendfile|sendfile64(int out_fd, int in_fd, off_t* offset, size_t count) arm64,mips64,x86_64
 int truncate(const char*, off_t) arm,mips,x86
 int truncate64(const char*, off64_t) arm,mips,x86
-int truncate|truncate64(const char*, off_t) arm64,x86_64
+int truncate|truncate64(const char*, off_t) arm64,mips64,x86_64
 # (mmap only gets two lines because we only used the 64-bit variant on 32-bit systems.)
 void* __mmap2:mmap2(void*, size_t, int, int, int, long)   arm,mips,x86
-void* mmap|mmap64(void*, size_t, int, int, int, off_t)  arm64,x86_64
+void* mmap|mmap64(void*, size_t, int, int, int, off_t)  arm64,mips64,x86_64
+# (fallocate only gets two lines because there is no 32-bit variant.)
+int fallocate64:fallocate(int, int, off64_t, off64_t) arm,mips,x86
+int fallocate|fallocate64(int, int, off_t, off_t) arm64,mips64,x86_64
+
+# posix_fadvise64 is awkward: arm has shuffled arguments,
+# the POSIX functions don't set errno, and no architecture has posix_fadvise.
+int __arm_fadvise64_64:arm_fadvise64_64(int, int, off64_t, off64_t) arm
+int __fadvise64:fadvise64_64(int, off64_t, off64_t, int) x86
+int __fadvise64:fadvise64(int, off64_t, off64_t, int) arm64,mips,mips64,x86_64
+
+int __fstatfs64:fstatfs64(int, size_t, struct statfs*)  arm,mips,x86
+int fstatfs64|fstatfs:fstatfs(int, struct statfs*)  arm64,mips64,x86_64
+int __statfs64:statfs64(const char*, size_t, struct statfs*)  arm,mips,x86
+int statfs64|statfs:statfs(const char*, struct statfs*)  arm64,mips64,x86_64
+
+int     fstat64|fstat:fstat64(int, struct stat*)    arm,mips,x86
+int     fstat64|fstat:fstat(int, struct stat*)    arm64,mips64,x86_64
 
 # file system
 int     chdir(const char*)              all
 int     mount(const char*, const char*, const char*, unsigned long, const void*)  all
 int     umount2(const char*, int)  all
-int     fstat:fstat64(int, struct stat*)    arm,mips,x86
-int     fstat(int, struct stat*)    arm64,x86_64
 int     __getcwd:getcwd(char* buf, size_t size)  all
 int     fchdir(int)    all
 int     setxattr(const char*, const char*, const void*, size_t, int) all
@@ -186,27 +195,23 @@
 ssize_t llistxattr(const char*, char*, size_t) all
 int     removexattr(const char*, const char*) all
 int     lremovexattr(const char*, const char*) all
-int     __statfs64:statfs64(const char*, size_t, struct statfs*)  arm,mips,x86
-int     statfs(const char*, struct statfs*)  arm64,x86_64
 int     swapon(const char*, int) all
 int     swapoff(const char*) all
 
 # time
-int           gettimeofday(struct timeval*, struct timezone*)       all
 int           settimeofday(const struct timeval*, const struct timezone*)   all
 clock_t       times(struct tms*)       all
 int           nanosleep(const struct timespec*, struct timespec*)   all
-int           clock_gettime(clockid_t clk_id, struct timespec* tp)    all
 int           clock_settime(clockid_t clk_id, const struct timespec* tp)  all
 int           clock_getres(clockid_t clk_id, struct timespec* res)   all
 int           clock_nanosleep(clockid_t clock_id, int flags, const struct timespec* req, struct timespec* rem)  all
 int           getitimer(int, const struct itimerval*)   all
 int           setitimer(int, const struct itimerval*, struct itimerval*)  all
-int           __timer_create:timer_create(clockid_t clockid, struct sigevent* evp, timer_t* timerid)    all
-int           __timer_settime:timer_settime(timer_t, int, const struct itimerspec*, struct itimerspec*) all
-int           __timer_gettime:timer_gettime(timer_t, struct itimerspec*)                                all
-int           __timer_getoverrun:timer_getoverrun(timer_t)                                              all
-int           __timer_delete:timer_delete(timer_t)                                                      all
+int           __timer_create:timer_create(clockid_t clockid, struct sigevent* evp, __kernel_timer_t* timerid)    all
+int           __timer_settime:timer_settime(__kernel_timer_t, int, const struct itimerspec*, struct itimerspec*) all
+int           __timer_gettime:timer_gettime(__kernel_timer_t, struct itimerspec*)                                all
+int           __timer_getoverrun:timer_getoverrun(__kernel_timer_t)                                              all
+int           __timer_delete:timer_delete(__kernel_timer_t)                                                      all
 int           timerfd_create(clockid_t, int)   all
 int           timerfd_settime(int, int, const struct itimerspec*, struct itimerspec*)   all
 int           timerfd_gettime(int, struct itimerspec*)   all
@@ -218,31 +223,32 @@
 int     __rt_sigprocmask:rt_sigprocmask(int, const sigset_t*, sigset_t*, size_t)  all
 int     __rt_sigsuspend:rt_sigsuspend(const sigset_t*, size_t)  all
 int     __rt_sigtimedwait:rt_sigtimedwait(const sigset_t*, struct siginfo_t*, struct timespec_t*, size_t)  all
-int     signalfd4(int, const sigset_t*, size_t, int)  all
+int     __signalfd4:signalfd4(int, const sigset_t*, size_t, int)  all
 
 # sockets
-int           socket(int, int, int)              arm,arm64,mips,x86_64
-int           socketpair(int, int, int, int*)    arm,arm64,mips,x86_64
-int           bind(int, struct sockaddr*, int)  arm,arm64,mips,x86_64
-int           connect(int, struct sockaddr*, socklen_t)   arm,arm64,mips,x86_64
-int           listen(int, int)                   arm,arm64,mips,x86_64
-int           accept(int, struct sockaddr*, socklen_t*)  arm,arm64,mips,x86_64
-int           getsockname(int, struct sockaddr*, socklen_t*)  arm,arm64,mips,x86_64
-int           getpeername(int, struct sockaddr*, socklen_t*)  arm,arm64,mips,x86_64
-int           sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t)  arm,arm64,mips,x86_64
-int           recvfrom(int, void*, size_t, unsigned int, struct sockaddr*, socklen_t*)  arm,arm64,mips,x86_64
-int           shutdown(int, int)  arm,arm64,mips,x86_64
-int           setsockopt(int, int, int, const void*, socklen_t)  arm,arm64,mips,x86_64
-int           getsockopt(int, int, int, void*, socklen_t*)    arm,arm64,mips,x86_64
-int           sendmsg(int, const struct msghdr*, unsigned int)  arm,arm64,mips,x86_64
-int           recvmsg(int, struct msghdr*, unsigned int)   arm,arm64,mips,x86_64
+int           __socket:socket(int, int, int)              arm,arm64,mips,mips64,x86_64
+int           socketpair(int, int, int, int*)    arm,arm64,mips,mips64,x86_64
+int           bind(int, struct sockaddr*, int)  arm,arm64,mips,mips64,x86_64
+int           __connect:connect(int, struct sockaddr*, socklen_t)   arm,arm64,mips,mips64,x86_64
+int           listen(int, int)                   arm,arm64,mips,mips64,x86_64
+int           __accept4:accept4(int, struct sockaddr*, socklen_t*, int)  arm,arm64,mips,mips64,x86_64
+int           getsockname(int, struct sockaddr*, socklen_t*)  arm,arm64,mips,mips64,x86_64
+int           getpeername(int, struct sockaddr*, socklen_t*)  arm,arm64,mips,mips64,x86_64
+int           sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t)  arm,arm64,mips,mips64,x86_64
+int           recvfrom(int, void*, size_t, unsigned int, struct sockaddr*, socklen_t*)  arm,arm64,mips,mips64,x86_64
+int           shutdown(int, int)  arm,arm64,mips,mips64,x86_64
+int           setsockopt(int, int, int, const void*, socklen_t)  arm,arm64,mips,mips64,x86_64
+int           getsockopt(int, int, int, void*, socklen_t*)    arm,arm64,mips,mips64,x86_64
+int           sendmsg(int, const struct msghdr*, unsigned int)  arm,arm64,mips,mips64,x86_64
+int           recvmsg(int, struct msghdr*, unsigned int)   arm,arm64,mips,mips64,x86_64
+int           recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*)   arm,arm64,mips,mips64,x86_64
+int           sendmmsg(int, struct mmsghdr*, unsigned int, int)   arm,arm64,mips,mips64,x86_64
 
 # sockets for x86. These are done as an "indexed" call to socketcall syscall.
-int           socket:socketcall:1(int, int, int) x86
+int           __socket:socketcall:1(int, int, int) x86
 int           bind:socketcall:2(int, struct sockaddr*, int)  x86
-int           connect:socketcall:3(int, struct sockaddr*, socklen_t)   x86
+int           __connect:socketcall:3(int, struct sockaddr*, socklen_t)   x86
 int           listen:socketcall:4(int, int)                   x86
-int           accept:socketcall:5(int, struct sockaddr*, socklen_t*)  x86
 int           getsockname:socketcall:6(int, struct sockaddr*, socklen_t*)  x86
 int           getpeername:socketcall:7(int, struct sockaddr*, socklen_t*)  x86
 int           socketpair:socketcall:8(int, int, int, int*)    x86
@@ -253,6 +259,9 @@
 int           getsockopt:socketcall:15(int, int, int, void*, socklen_t*)    x86
 int           sendmsg:socketcall:16(int, const struct msghdr*, unsigned int)  x86
 int           recvmsg:socketcall:17(int, struct msghdr*, unsigned int)   x86
+int           __accept4:socketcall:18(int, struct sockaddr*, socklen_t*, int)  x86
+int           recvmmsg:socketcall:19(int, struct mmsghdr*, unsigned int, int, const struct timespec*)   x86
+int           sendmmsg:socketcall:20(int, struct mmsghdr*, unsigned int, int)   x86
 
 # scheduler & real-time
 int sched_setscheduler(pid_t pid, int policy, const struct sched_param* param)  all
@@ -269,21 +278,19 @@
 int __sched_getaffinity:sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set)  all
 int __getcpu:getcpu(unsigned*, unsigned*, void*) all
 
-# io priorities
-int ioprio_set(int which, int who, int ioprio) all
-int ioprio_get(int which, int who) all
-
 # other
 int     uname(struct utsname*)  all
 mode_t  umask(mode_t)  all
 int     __reboot:reboot(int, int, int, void*)  all
-int     __syslog:syslog(int, char*, int)  all
 int     init_module(void*, unsigned long, const char*)  all
 int     delete_module(const char*, unsigned int)   all
 int     klogctl:syslog(int, char*, int)   all
 int     sysinfo(struct sysinfo*)  all
 int     personality(unsigned long)  all
-long    perf_event_open(struct perf_event_attr* attr_uptr, pid_t pid, int cpu, int group_fd, unsigned long flags) all
+
+ssize_t tee(int, int, size_t, unsigned int)  all
+ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int)  all
+ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int)  all
 
 int epoll_create1(int)  all
 int epoll_ctl(int, int op, int, struct epoll_event*)  all
@@ -291,11 +298,9 @@
 
 int eventfd:eventfd2(unsigned int, int)  all
 
-void _exit:exit_group(int)  all
+void _exit|_Exit:exit_group(int)  all
 void __exit:exit(int)  all
 
-int futex(void*, int, int, void*, void*, int)  all
-
 int inotify_init1(int)  all
 int inotify_add_watch(int, const char*, unsigned int)  all
 int inotify_rm_watch(int, unsigned int)  all
@@ -305,6 +310,9 @@
 
 int __set_tid_address:set_tid_address(int*)  all
 
+int setfsgid(gid_t)  all
+int setfsuid(uid_t)  all
+
 pid_t wait4(pid_t, int*, int, struct rusage*)  all
 int __waitid:waitid(int, pid_t, struct siginfo_t*, int, void*)  all
 
@@ -313,4 +321,14 @@
 int     cacheflush:__ARM_NR_cacheflush(long start, long end, long flags)  arm
 
 # MIPS-specific
-int     _flush_cache:cacheflush(char* addr, const int nbytes, const int op) mips
+int     _flush_cache:cacheflush(char* addr, const int nbytes, const int op) mips,mips64
+int     __set_tls:set_thread_area(void*) mips,mips64
+
+# x86-specific
+int     __set_thread_area:set_thread_area(void*) x86
+
+# vdso stuff.
+int clock_gettime(clockid_t, timespec*)                 arm,mips,mips64,x86
+int __clock_gettime:clock_gettime(clockid_t, timespec*) arm64,x86_64
+int gettimeofday(timeval*, timezone*)                   arm,mips,mips64,x86
+int __gettimeofday:gettimeofday(timeval*, timezone*)    arm64,x86_64
diff --git a/libc/arch-arm/arm.mk b/libc/arch-arm/arm.mk
index 95c3b61..70cc8eb 100644
--- a/libc/arch-arm/arm.mk
+++ b/libc/arch-arm/arm.mk
@@ -1,43 +1,93 @@
-_LIBC_ARCH_COMMON_SRC_FILES := \
+# arm specific configs
+
+# These are used by the 32-bit targets, but not the 64-bit ones.
+libc_common_src_files_arm := \
+    bionic/legacy_32_bit_support.cpp \
+    bionic/ndk_cruft.cpp \
+    bionic/time64.c \
+    upstream-openbsd/lib/libc/stdio/putw.c \
+
+# These are shared by all the 32-bit targets, but not the 64-bit ones.
+libc_bionic_src_files_arm := \
+    bionic/mmap.cpp
+
+libc_common_src_files_arm += \
+    bionic/memchr.c \
+    bionic/memrchr.c \
+    bionic/strchr.cpp \
+    bionic/strnlen.c \
+    bionic/strrchr.cpp \
+    upstream-freebsd/lib/libc/string/wcscat.c \
+    upstream-freebsd/lib/libc/string/wcschr.c \
+    upstream-freebsd/lib/libc/string/wcscmp.c \
+    upstream-freebsd/lib/libc/string/wcscpy.c \
+    upstream-freebsd/lib/libc/string/wcslen.c \
+    upstream-freebsd/lib/libc/string/wcsrchr.c \
+    upstream-freebsd/lib/libc/string/wmemcmp.c \
+    upstream-freebsd/lib/libc/string/wmemmove.c \
+    upstream-openbsd/lib/libc/string/bcopy.c \
+    upstream-openbsd/lib/libc/string/stpcpy.c \
+    upstream-openbsd/lib/libc/string/stpncpy.c \
+    upstream-openbsd/lib/libc/string/strlcat.c \
+    upstream-openbsd/lib/libc/string/strlcpy.c \
+    upstream-openbsd/lib/libc/string/strncat.c \
+    upstream-openbsd/lib/libc/string/strncmp.c \
+    upstream-openbsd/lib/libc/string/strncpy.c \
+
+# The C++ fortify function implementations for which there is an
+# arm assembler version.
+#
+# Fortify implementations of libc functions.
+# libc_common_src_files_arm +=
+#    bionic/__memcpy_chk.cpp \
+#    bionic/__memset_chk.cpp \
+#    bionic/__strcpy_chk.cpp \
+#    bionic/__strcat_chk.cpp \
+
+libc_common_cflags_arm := -DSOFTFLOAT
+
+##########################################
+### CPU specific source files
+libc_bionic_src_files_arm += \
     arch-arm/bionic/abort_arm.S \
     arch-arm/bionic/atomics_arm.c \
     arch-arm/bionic/__bionic_clone.S \
-    arch-arm/bionic/eabi.c \
     arch-arm/bionic/_exit_with_stack_teardown.S \
-    arch-arm/bionic/futex_arm.S \
-    arch-arm/bionic/__get_sp.S \
     arch-arm/bionic/libgcc_compat.c \
-    arch-arm/bionic/memcmp16.S \
     arch-arm/bionic/memcmp.S \
     arch-arm/bionic/_setjmp.S \
     arch-arm/bionic/setjmp.S \
     arch-arm/bionic/sigsetjmp.S \
     arch-arm/bionic/syscall.S \
 
-# These are used by the static and dynamic versions of the libc
-# respectively.
-_LIBC_ARCH_STATIC_SRC_FILES := \
-    arch-arm/bionic/exidx_static.c \
-    bionic/dl_iterate_phdr_static.c \
+libc_arch_static_src_files_arm := arch-arm/bionic/exidx_static.c
+libc_arch_dynamic_src_files_arm := arch-arm/bionic/exidx_dynamic.c
 
-_LIBC_ARCH_DYNAMIC_SRC_FILES := \
-    arch-arm/bionic/exidx_dynamic.c \
+libc_netbsd_src_files_arm := \
+    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
 
-# Remove the C++ fortify function implementations for which there is an
-# arm assembler version.
-_LIBC_FORTIFY_FILES_TO_REMOVE := \
-    bionic/__memcpy_chk.cpp \
-    bionic/__memset_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-    bionic/__strcat_chk.cpp \
-
-libc_common_src_files := \
-    $(filter-out $(_LIBC_FORTIFY_FILES_TO_REMOVE),$(libc_common_src_files))
-
-ifeq ($(strip $(wildcard bionic/libc/arch-arm/$(TARGET_CPU_VARIANT)/$(TARGET_CPU_VARIANT).mk)),)
-$(error "TARGET_CPU_VARIANT not set or set to an unknown value. Possible values are cortex-a7, cortex-a8, cortex-a9, cortex-a15, krait. Use generic for devices that do not have a CPU similar to any of the supported cpu variants.")
+## CPU variant specific source files
+ifeq ($(strip $(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT)),)
+  $(warning TARGET_$(my_2nd_arch_prefix)ARCH is arm, but TARGET_$(my_2nd_arch_prefix)CPU_VARIANT is not defined)
 endif
+cpu_variant_mk := $(LOCAL_PATH)/arch-arm/$(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT)/$(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT).mk
+ifeq ($(wildcard $(cpu_variant_mk)),)
+$(error "TARGET_$(my_2nd_arch_prefix)CPU_VARIANT not set or set to an unknown value. Possible values are cortex-a7, cortex-a8, cortex-a9, cortex-a15, krait, denver. Use generic for devices that do not have a CPU similar to any of the supported cpu variants.")
+endif
+include $(cpu_variant_mk)
+libc_common_additional_dependencies += $(cpu_variant_mk)
 
-_LIBC_ARCH_ADDITIONAL_DEPENDENCIES := \
-    $(LOCAL_PATH)/arch-arm/$(TARGET_CPU_VARIANT)/$(TARGET_CPU_VARIANT).mk
-include $(LOCAL_PATH)/arch-arm/$(TARGET_CPU_VARIANT)/$(TARGET_CPU_VARIANT).mk
+cpu_variant_mk :=
+
+
+libc_crt_target_cflags_arm := \
+    -I$(LOCAL_PATH)/arch-arm/include \
+    -mthumb-interwork
+
+libc_crt_target_so_cflags_arm :=
+
+libc_crt_target_crtbegin_file_arm := \
+    $(LOCAL_PATH)/arch-common/bionic/crtbegin.c
+
+libc_crt_target_crtbegin_so_file_arm := \
+    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
diff --git a/libc/arch-arm/bionic/__aeabi.c b/libc/arch-arm/bionic/__aeabi.c
new file mode 100644
index 0000000..3254f64
--- /dev/null
+++ b/libc/arch-arm/bionic/__aeabi.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(__clang__)
+// clang interprets -fno-builtin more loosely than you might expect,
+// and thinks it's okay to still substitute builtins as long as they're
+// named __aeabi_* rather than __builtin_*, which causes infinite
+// recursion if we have the fortified memcpy visible in this file.
+#undef _FORTIFY_SOURCE
+#endif
+
+#include <stddef.h>
+#include <string.h>
+
+extern int __cxa_atexit(void (*)(void*), void*, void*);
+
+/* The "C++ ABI for ARM" document states that static C++ constructors,
+ * which are called from the .init_array, should manually call
+ * __aeabi_atexit() to register static destructors explicitly.
+ *
+ * Note that 'dso_handle' is the address of a magic linker-generate
+ * variable from the shared object that contains the constructor/destructor
+ */
+
+// Make this a weak symbol to avoid a multiple definition error when linking with libstdc++-v3.
+int __attribute__((weak))
+__aeabi_atexit(void *object, void (*destructor) (void *), void *dso_handle) {
+    return __cxa_atexit(destructor, object, dso_handle);
+}
+
+
+void __aeabi_memcpy8(void *dest, const void *src, size_t n) {
+    memcpy(dest, src, n);
+}
+
+void __aeabi_memcpy4(void *dest, const void *src, size_t n) {
+    memcpy(dest, src, n);
+}
+
+void __aeabi_memcpy(void *dest, const void *src, size_t n) {
+    memcpy(dest, src, n);
+}
+
+
+void __aeabi_memmove8(void *dest, const void *src, size_t n) {
+    memmove(dest, src, n);
+}
+
+void __aeabi_memmove4(void *dest, const void *src, size_t n) {
+    memmove(dest, src, n);
+}
+
+void __aeabi_memmove(void *dest, const void *src, size_t n) {
+    memmove(dest, src, n);
+}
+
+/*
+ * __aeabi_memset has the order of its second and third arguments reversed.
+ *  This allows __aeabi_memclr to tail-call __aeabi_memset
+ */
+
+void __aeabi_memset8(void *dest, size_t n, int c) {
+    memset(dest, c, n);
+}
+
+void __aeabi_memset4(void *dest, size_t n, int c) {
+    memset(dest, c, n);
+}
+
+void __aeabi_memset(void *dest, size_t n, int c) {
+    memset(dest, c, n);
+}
+
+
+void __aeabi_memclr8(void *dest, size_t n) {
+    __aeabi_memset8(dest, n, 0);
+}
+
+void __aeabi_memclr4(void *dest, size_t n) {
+    __aeabi_memset4(dest, n, 0);
+}
+
+void __aeabi_memclr(void *dest, size_t n) {
+    __aeabi_memset(dest, n, 0);
+}
diff --git a/libc/arch-arm/bionic/__bionic_clone.S b/libc/arch-arm/bionic/__bionic_clone.S
index 72f4892..f5cf9e0 100644
--- a/libc/arch-arm/bionic/__bionic_clone.S
+++ b/libc/arch-arm/bionic/__bionic_clone.S
@@ -31,7 +31,6 @@
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
 ENTRY(__bionic_clone)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     # save registers to parent stack
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
@@ -55,20 +54,16 @@
 
     # In the parent, reload saved registers then either return or set errno.
     ldmfd   sp!, {r4, r5, r6, r7}
-    .cfi_def_cfa_offset 0
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 
 1:  # The child.
-    # Re-add the unwind directives that were reset from above.
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset r4, 0
-    .cfi_rel_offset r5, 4
-    .cfi_rel_offset r6, 8
-    .cfi_rel_offset r7, 12
+    # Setting lr to 0 will make the unwinder stop at __start_thread
+    mov    lr, #0
     ldr    r0, [sp, #-4]
     ldr    r1, [sp, #-8]
-    b      __bionic_clone_entry
+    b      __start_thread
 END(__bionic_clone)
+.hidden __bionic_clone
diff --git a/libc/arch-arm/bionic/__get_sp.S b/libc/arch-arm/bionic/__get_sp.S
deleted file mode 100644
index 2a7e7b7..0000000
--- a/libc/arch-arm/bionic/__get_sp.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-
-ENTRY(__get_sp)
-  mov r0, sp
-  bx lr
-END(__get_sp)
diff --git a/libc/arch-arm/bionic/_exit_with_stack_teardown.S b/libc/arch-arm/bionic/_exit_with_stack_teardown.S
index 6fa950e..1a67fed 100644
--- a/libc/arch-arm/bionic/_exit_with_stack_teardown.S
+++ b/libc/arch-arm/bionic/_exit_with_stack_teardown.S
@@ -29,7 +29,7 @@
 #include <private/bionic_asm.h>
 
 // void _exit_with_stack_teardown(void* stackBase, size_t stackSize)
-ENTRY(_exit_with_stack_teardown)
+ENTRY_PRIVATE(_exit_with_stack_teardown)
   ldr r7, =__NR_munmap
   swi #0
   // If munmap failed, we ignore the failure and exit anyway.
diff --git a/libc/arch-arm/bionic/_setjmp.S b/libc/arch-arm/bionic/_setjmp.S
index 6b8aa50..64a0a31 100644
--- a/libc/arch-arm/bionic/_setjmp.S
+++ b/libc/arch-arm/bionic/_setjmp.S
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 #include <machine/cpu-features.h>
 
@@ -107,7 +107,7 @@
 
 	/* validation failed, die die die. */
 botch:
-	bl	PIC_SYM(_C_LABEL(longjmperror), PLT)
-	bl	PIC_SYM(_C_LABEL(abort), PLT)
+	bl	PIC_SYM(longjmperror, PLT)
+	bl	PIC_SYM(abort, PLT)
 	b	. - 8		/* Cannot get here */
 END(_longjmp)
diff --git a/libc/arch-arm/bionic/abort_arm.S b/libc/arch-arm/bionic/abort_arm.S
index 2fc2913..6b181ef 100644
--- a/libc/arch-arm/bionic/abort_arm.S
+++ b/libc/arch-arm/bionic/abort_arm.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * Coding the abort function in assembly so that registers are guaranteed to
@@ -36,10 +36,9 @@
  * sequence when the crash happens.
  */
 ENTRY(abort)
-    .save   {r3, r14}
     stmfd   sp!, {r3, r14}
     .cfi_def_cfa_offset 8
     .cfi_rel_offset r3, 0
     .cfi_rel_offset r14, 4
-    bl      PIC_SYM(_C_LABEL(__libc_android_abort), PLT)
+    bl      PIC_SYM(__libc_android_abort, PLT)
 END(abort)
diff --git a/libc/arch-arm/bionic/eabi.c b/libc/arch-arm/bionic/eabi.c
deleted file mode 100644
index 5511ddd..0000000
--- a/libc/arch-arm/bionic/eabi.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stddef.h>
-#include <string.h>
-
-extern int  __cxa_atexit(void (*)(void*), void*, void* );
-
-/* The "C++ ABI for ARM" document states that static C++ constructors,
- * which are called from the .init_array, should manually call
- * __aeabi_atexit() to register static destructors explicitly.
- *
- * Note that 'dso_handle' is the address of a magic linker-generate
- * variable from the shared object that contains the constructor/destructor
- */
-
-/* Make this a weak symbol to avoid a multiple definition error when linking
- * with libstdc++-v3.  */
-int __attribute__((weak))
-__aeabi_atexit (void *object, void (*destructor) (void *), void *dso_handle)
-{
-    return __cxa_atexit(destructor, object, dso_handle);
-}
-
-
-void __aeabi_memcpy8(void *dest, const void *src, size_t n) {
-    memcpy(dest, src, n);
-}
-
-void __aeabi_memcpy4(void *dest, const void *src, size_t n) {
-    memcpy(dest, src, n);
-}
-
-void __aeabi_memcpy(void *dest, const void *src, size_t n) {
-    memcpy(dest, src, n);
-}
-
-
-void __aeabi_memmove8(void *dest, const void *src, size_t n) {
-    memmove(dest, src, n);
-}
-
-void __aeabi_memmove4(void *dest, const void *src, size_t n) {
-    memmove(dest, src, n);
-}
-
-void __aeabi_memmove(void *dest, const void *src, size_t n) {
-    memmove(dest, src, n);
-}
-
-/*
- * __aeabi_memset has the order of its second and third arguments reversed. 
- *  This allows __aeabi_memclr to tail-call __aeabi_memset
- */
- 
-void __aeabi_memset8(void *dest, size_t n, int c) {
-    memset(dest, c, n);
-}
-
-void __aeabi_memset4(void *dest, size_t n, int c) {
-    memset(dest, c, n);
-}
-
-void __aeabi_memset(void *dest, size_t n, int c) {
-    memset(dest, c, n);
-}
-
-
-void __aeabi_memclr8(void *dest, size_t n) {
-    __aeabi_memset8(dest, n, 0);
-}
-
-void __aeabi_memclr4(void *dest, size_t n) {
-    __aeabi_memset4(dest, n, 0);
-}
-
-void __aeabi_memclr(void *dest, size_t n) {
-    __aeabi_memset(dest, n, 0);
-}
diff --git a/libc/arch-arm/bionic/futex_arm.S b/libc/arch-arm/bionic/futex_arm.S
deleted file mode 100644
index 0aba278..0000000
--- a/libc/arch-arm/bionic/futex_arm.S
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <private/bionic_asm.h>
-
-#define FUTEX_WAIT 0
-#define FUTEX_WAKE 1
-
-// int __futex_syscall3(volatile void* ftx, int op, int count)
-ENTRY(__futex_syscall3)
-    mov     ip, r7
-    ldr     r7, =__NR_futex
-    swi     #0
-    mov     r7, ip
-    bx      lr
-END(__futex_syscall3)
-
-// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout)
-ENTRY(__futex_syscall4)
-    b __futex_syscall3
-END(__futex_syscall4)
-
-// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout)
-ENTRY(__futex_wait)
-    mov     ip, r7
-    mov     r3, r2
-    mov     r2, r1
-    mov     r1, #FUTEX_WAIT
-    ldr     r7, =__NR_futex
-    swi     #0
-    mov     r7, ip
-    bx      lr
-END(__futex_wait)
-
-// int __futex_wake(volatile void* ftx, int count)
-ENTRY(__futex_wake)
-    mov     ip, r7
-    mov     r2, r1
-    mov     r1, #FUTEX_WAKE
-    ldr     r7, =__NR_futex
-    swi     #0
-    mov     r7, ip
-    bx      lr
-END(__futex_wake)
diff --git a/libc/arch-arm/bionic/libgcc_compat.c b/libc/arch-arm/bionic/libgcc_compat.c
index f694060..10faf2d 100644
--- a/libc/arch-arm/bionic/libgcc_compat.c
+++ b/libc/arch-arm/bionic/libgcc_compat.c
@@ -1,177 +1,159 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+/* Generated by genlibgcc_compat.py */
 
-/* This file contains dummy references to libgcc.a functions to force the
- * dynamic linker to copy their definition into the final libc.so binary.
- *
- * They are required to ensure backwards binary compatibility with
- * libc.so provided by the platform and binaries built with the NDK or
- * different versions/configurations of toolchains.
- *
- * Now, for a more elaborate description of the issue:
- *
- * libgcc.a is a compiler-specific library containing various helper
- * functions used to implement certain operations that are not necessarily
- * supported by the target CPU. For example, integer division doesn't have a
- * corresponding CPU instruction on ARMv5, and is instead implemented in the
- * compiler-generated machine code as a call to an __idiv helper function.
- *
- * Normally, one has to place libgcc.a in the link command used to generate
- * target binaries (shared libraries and executables) after all objects and
- * static libraries, but before dependent shared libraries, i.e. something
- * like:
- *         gcc <options> -o libfoo.so  foo.a libgcc.a -lc -lm
- *
- * This ensures that any helper function needed by the code in foo.a is copied
- * into the final libfoo.so. However, doing so will link a bunch of other __cxa
- * functions from libgcc.a into each .so and executable, causing 4k+ increase
- * in every binary. Therefore the Android platform build system has been
- * using this instead:
- *
- *         gcc <options> -o libfoo.so foo.a -lc -lm libgcc.a
- *
- * The problem with this is that if one helper function needed by foo.a has
- * already been copied into libc.so or libm.so, then nothing will be copied
- * into libfoo.so. Instead, a symbol import definition will be added to it
- * so libfoo.so can directly call the one in libc.so at runtime.
- *
- * When refreshing toolchains for new versions or using different architecture
- * flags, the set of helper functions copied to libc.so may change, which
- * resulted in some native shared libraries generated with the NDK or prebuilts
- * from vendors to fail to load properly.
- *
- * The NDK has been fixed after 1.6_r1 to use the correct link command, so
- * any native shared library generated with it should now be safe from that
- * problem. On the other hand, existing shared libraries distributed with
- * applications that were generated with a previous version of the NDK
- * still need all 1.5/1.6 helper functions in libc.so and libm.so
- *
- * After 3.2, the toolchain was updated again, adding __aeabi_f2uiz to the
- * list of requirements. Technically, this is due to mis-linked NDK libraries
- * but it is easier to add a single function here than asking several app
- * developers to fix their build.
- *
- * The __aeabi_idiv function is added to the list since cortex-a15 supports
- * HW idiv instructions so the system libc.so doesn't pull in the reference to
- * __aeabi_idiv but legacy libraries built against cortex-a9 targets still need
- * it.
- *
- * Final note: some of the functions below should really be in libm.so to
- *             completely reflect the state of 1.5/1.6 system images. However,
- *             since libm.so depends on libc.so, it's easier to put all of
- *             these in libc.so instead, since the dynamic linker will always
- *             search in libc.so before libm.so for dependencies.
- */
+extern char __adddf3;
+extern char __addsf3;
+extern char __aeabi_cdcmpeq;
+extern char __aeabi_cdcmple;
+extern char __aeabi_cdrcmple;
+extern char __aeabi_d2f;
+extern char __aeabi_d2iz;
+extern char __aeabi_dadd;
+extern char __aeabi_dcmpeq;
+extern char __aeabi_dcmpge;
+extern char __aeabi_dcmpgt;
+extern char __aeabi_dcmple;
+extern char __aeabi_dcmplt;
+extern char __aeabi_dcmpun;
+extern char __aeabi_ddiv;
+extern char __aeabi_dmul;
+extern char __aeabi_drsub;
+extern char __aeabi_dsub;
+extern char __aeabi_f2d;
+extern char __aeabi_f2iz;
+extern char __aeabi_f2uiz;
+extern char __aeabi_fadd;
+extern char __aeabi_fcmpun;
+extern char __aeabi_fdiv;
+extern char __aeabi_fmul;
+extern char __aeabi_frsub;
+extern char __aeabi_fsub;
+extern char __aeabi_i2d;
+extern char __aeabi_i2f;
+extern char __aeabi_idiv;
+extern char __aeabi_idivmod;
+extern char __aeabi_l2d;
+extern char __aeabi_l2f;
+extern char __aeabi_lasr;
+extern char __aeabi_ldivmod;
+extern char __aeabi_llsl;
+extern char __aeabi_llsr;
+extern char __aeabi_lmul;
+extern char __aeabi_ui2d;
+extern char __aeabi_ui2f;
+extern char __aeabi_uidiv;
+extern char __aeabi_uidivmod;
+extern char __aeabi_ul2d;
+extern char __aeabi_ul2f;
+extern char __aeabi_uldivmod;
+extern char __aeabi_unwind_cpp_pr0;
+extern char __aeabi_unwind_cpp_pr1;
+extern char __cmpdf2;
+extern char __divdf3;
+extern char __divsf3;
+extern char __eqdf2;
+extern char __extendsfdf2;
+extern char __fixdfsi;
+extern char __fixsfsi;
+extern char __floatdidf;
+extern char __floatdisf;
+extern char __floatsidf;
+extern char __floatsisf;
+extern char __floatundidf;
+extern char __floatundisf;
+extern char __floatunsidf;
+extern char __floatunsisf;
+extern char __gedf2;
+extern char __gtdf2;
+extern char __ledf2;
+extern char __ltdf2;
+extern char __muldf3;
+extern char __muldi3;
+extern char __mulsf3;
+extern char __nedf2;
+extern char __popcount_tab;
+extern char __popcountsi2;
+extern char __subdf3;
+extern char __subsf3;
+extern char __truncdfsf2;
+extern char __unorddf2;
+extern char __unordsf2;
 
-#define   COMPAT_FUNCTIONS_LIST \
-    XX(__adddf3)             \
-    XX(__addsf3)             \
-    XX(__aeabi_cdcmpeq)      \
-    XX(__aeabi_cdcmple)      \
-    XX(__aeabi_cdrcmple)     \
-    XX(__aeabi_d2f)          \
-    XX(__aeabi_d2iz)         \
-    XX(__aeabi_dadd)         \
-    XX(__aeabi_dcmpeq)       \
-    XX(__aeabi_dcmpge)       \
-    XX(__aeabi_dcmpgt)       \
-    XX(__aeabi_dcmple)       \
-    XX(__aeabi_dcmplt)       \
-    XX(__aeabi_dcmpun)       \
-    XX(__aeabi_ddiv)         \
-    XX(__aeabi_dmul)         \
-    XX(__aeabi_drsub)        \
-    XX(__aeabi_dsub)         \
-    XX(__aeabi_f2d)          \
-    XX(__aeabi_f2iz)         \
-    XX(__aeabi_f2uiz)        \
-    XX(__aeabi_fadd)         \
-    XX(__aeabi_fcmpun)       \
-    XX(__aeabi_fdiv)         \
-    XX(__aeabi_fmul)         \
-    XX(__aeabi_frsub)        \
-    XX(__aeabi_fsub)         \
-    XX(__aeabi_i2d)          \
-    XX(__aeabi_i2f)          \
-    XX(__aeabi_idiv)         \
-    XX(__aeabi_idivmod)      \
-    XX(__aeabi_l2d)          \
-    XX(__aeabi_l2f)          \
-    XX(__aeabi_lasr)         \
-    XX(__aeabi_ldivmod)      \
-    XX(__aeabi_llsl)         \
-    XX(__aeabi_llsr)         \
-    XX(__aeabi_lmul)         \
-    XX(__aeabi_ui2d)         \
-    XX(__aeabi_ui2f)         \
-    XX(__aeabi_uidiv)        \
-    XX(__aeabi_uidivmod)     \
-    XX(__aeabi_ul2d)         \
-    XX(__aeabi_ul2f)         \
-    XX(__aeabi_uldivmod)     \
-    XX(__cmpdf2)             \
-    XX(__divdf3)             \
-    XX(__divsf3)             \
-    XX(__eqdf2)              \
-    XX(__extendsfdf2)        \
-    XX(__fixdfsi)            \
-    XX(__fixsfsi)            \
-    XX(__floatdidf)          \
-    XX(__floatdisf)          \
-    XX(__floatsidf)          \
-    XX(__floatsisf)          \
-    XX(__floatundidf)        \
-    XX(__floatundisf)        \
-    XX(__floatunsidf)        \
-    XX(__floatunsisf)        \
-    XX(__gedf2)              \
-    XX(__gtdf2)              \
-    XX(__ledf2)              \
-    XX(__ltdf2)              \
-    XX(__muldf3)             \
-    XX(__muldi3)             \
-    XX(__mulsf3)             \
-    XX(__nedf2)              \
-    XX(__popcountsi2)        \
-    XX(__popcount_tab)       \
-    XX(__subdf3)             \
-    XX(__subsf3)             \
-    XX(__truncdfsf2)         \
-    XX(__unorddf2)           \
-    XX(__unordsf2)           \
-
-#define  XX(f)    extern void f(void);
-COMPAT_FUNCTIONS_LIST
-#undef XX
-
-void  __bionic_libgcc_compat_hooks(void)
-{
-#define XX(f)    f();
-COMPAT_FUNCTIONS_LIST
-#undef XX
-}
+void* __bionic_libgcc_compat_symbols[] = {
+    &__adddf3,
+    &__addsf3,
+    &__aeabi_cdcmpeq,
+    &__aeabi_cdcmple,
+    &__aeabi_cdrcmple,
+    &__aeabi_d2f,
+    &__aeabi_d2iz,
+    &__aeabi_dadd,
+    &__aeabi_dcmpeq,
+    &__aeabi_dcmpge,
+    &__aeabi_dcmpgt,
+    &__aeabi_dcmple,
+    &__aeabi_dcmplt,
+    &__aeabi_dcmpun,
+    &__aeabi_ddiv,
+    &__aeabi_dmul,
+    &__aeabi_drsub,
+    &__aeabi_dsub,
+    &__aeabi_f2d,
+    &__aeabi_f2iz,
+    &__aeabi_f2uiz,
+    &__aeabi_fadd,
+    &__aeabi_fcmpun,
+    &__aeabi_fdiv,
+    &__aeabi_fmul,
+    &__aeabi_frsub,
+    &__aeabi_fsub,
+    &__aeabi_i2d,
+    &__aeabi_i2f,
+    &__aeabi_idiv,
+    &__aeabi_idivmod,
+    &__aeabi_l2d,
+    &__aeabi_l2f,
+    &__aeabi_lasr,
+    &__aeabi_ldivmod,
+    &__aeabi_llsl,
+    &__aeabi_llsr,
+    &__aeabi_lmul,
+    &__aeabi_ui2d,
+    &__aeabi_ui2f,
+    &__aeabi_uidiv,
+    &__aeabi_uidivmod,
+    &__aeabi_ul2d,
+    &__aeabi_ul2f,
+    &__aeabi_uldivmod,
+    &__aeabi_unwind_cpp_pr0,
+    &__aeabi_unwind_cpp_pr1,
+    &__cmpdf2,
+    &__divdf3,
+    &__divsf3,
+    &__eqdf2,
+    &__extendsfdf2,
+    &__fixdfsi,
+    &__fixsfsi,
+    &__floatdidf,
+    &__floatdisf,
+    &__floatsidf,
+    &__floatsisf,
+    &__floatundidf,
+    &__floatundisf,
+    &__floatunsidf,
+    &__floatunsisf,
+    &__gedf2,
+    &__gtdf2,
+    &__ledf2,
+    &__ltdf2,
+    &__muldf3,
+    &__muldi3,
+    &__mulsf3,
+    &__nedf2,
+    &__popcount_tab,
+    &__popcountsi2,
+    &__subdf3,
+    &__subsf3,
+    &__truncdfsf2,
+    &__unorddf2,
+    &__unordsf2,
+};
diff --git a/libc/arch-arm/bionic/memcmp.S b/libc/arch-arm/bionic/memcmp.S
index 921f8ef..70a2a58 100644
--- a/libc/arch-arm/bionic/memcmp.S
+++ b/libc/arch-arm/bionic/memcmp.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 
 #ifdef HAVE_32_BYTE_CACHE_LINE
@@ -108,7 +108,6 @@
 #endif
 
         /* save registers */
-        .save       {r4, lr}
         stmfd       sp!, {r4, lr}
         .cfi_def_cfa_offset 8
         .cfi_rel_offset r4, 0
diff --git a/libc/arch-arm/bionic/memcmp16.S b/libc/arch-arm/bionic/memcmp16.S
deleted file mode 100644
index 26a1bf3..0000000
--- a/libc/arch-arm/bionic/memcmp16.S
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/cpu-features.h>
-#include <machine/asm.h>
-
-/*
- * Optimized memcmp16() for ARM9.
- * This would not be optimal on XScale or ARM11, where more prefetching
- * and use of pld will be needed.
- * The 2 major optimzations here are
- * (1) The main loop compares 16 bytes at a time
- * (2) The loads are scheduled in a way they won't stall
- */
-
-ENTRY(__memcmp16)
-        pld         [r0, #0]
-        pld         [r1, #0]
-
-        /* take of the case where length is nul or the buffers are the same */
-        cmp         r0, r1
-        cmpne       r2, #0
-        moveq       r0, #0
-        bxeq        lr
-
-        /* since r0 hold the result, move the first source
-         * pointer somewhere else
-         */
-
-        mov         r3, r0
-
-         /* make sure we have at least 12 words, this simplify things below
-          * and avoid some overhead for small blocks
-          */
-
-        cmp         r2, #12
-        bpl         0f
-
-        /* small blocks (less then 12 words) */
-        pld         [r0, #32]
-        pld         [r1, #32]
-
-1:      ldrh        r0, [r3], #2
-        ldrh        ip, [r1], #2
-        subs        r0, r0, ip
-        bxne        lr
-        subs        r2, r2, #1
-        bne         1b
-        bx          lr
-
-
-        /* save registers */
-        .save       {r4, lr}
-0:      stmfd       sp!, {r4, lr}
-        .cfi_def_cfa_offset 8
-        .cfi_rel_offset r4, 0
-        .cfi_rel_offset lr, 4
-
-        /* align first pointer to word boundary */
-        tst         r3, #2
-        beq         0f
-
-        ldrh        r0, [r3], #2
-        ldrh        ip, [r1], #2
-        sub         r2, r2, #1
-        subs        r0, r0, ip
-        /* restore registers and return */
-        ldmnefd     sp!, {r4, lr}
-        bxne        lr
-
-
-0:      /* here the first pointer is aligned, and we have at least 3 words
-         * to process.
-         */
-
-        /* see if the pointers are congruent */
-        eor         r0, r3, r1
-        ands        r0, r0, #2
-        bne         5f
-
-        /* congruent case, 16 half-words per iteration
-         * We need to make sure there are at least 16+2 words left
-         * because we effectively read ahead one long word, and we could
-         * read past the buffer (and segfault) if we're not careful.
-         */
-
-        ldr         ip, [r1]
-        subs        r2, r2, #(16 + 2)
-        bmi         1f
-
-0:
-        pld         [r3, #64]
-        pld         [r1, #64]
-        ldr         r0, [r3], #4
-        ldr         lr, [r1, #4]!
-        eors        r0, r0, ip
-        ldreq       r0, [r3], #4
-        ldreq       ip, [r1, #4]!
-        eoreqs      r0, r0, lr
-        ldreq       r0, [r3], #4
-        ldreq       lr, [r1, #4]!
-        eoreqs      r0, r0, ip
-        ldreq       r0, [r3], #4
-        ldreq       ip, [r1, #4]!
-        eoreqs      r0, r0, lr
-        ldreq       r0, [r3], #4
-        ldreq       lr, [r1, #4]!
-        eoreqs      r0, r0, ip
-        ldreq       r0, [r3], #4
-        ldreq       ip, [r1, #4]!
-        eoreqs      r0, r0, lr
-        ldreq       r0, [r3], #4
-        ldreq       lr, [r1, #4]!
-        eoreqs      r0, r0, ip
-        ldreq       r0, [r3], #4
-        ldreq       ip, [r1, #4]!
-        eoreqs      r0, r0, lr
-        bne         2f
-        subs        r2, r2, #16
-        bhs         0b
-
-        /* do we have at least 2 words left? */
-1:      adds        r2, r2, #(16 - 2 + 2)
-        bmi         4f
-
-        /* finish off 2 words at a time */
-3:      ldr         r0, [r3], #4
-        ldr         ip, [r1], #4
-        eors        r0, r0, ip
-        bne         2f
-        subs        r2, r2, #2
-        bhs         3b
-
-        /* are we done? */
-4:      adds        r2, r2, #2
-        bne         8f
-        /* restore registers and return */
-        mov         r0, #0
-        ldmfd       sp!, {r4, lr}
-        bx          lr
-
-2:      /* the last 2 words are different, restart them */
-        ldrh        r0, [r3, #-4]
-        ldrh        ip, [r1, #-4]
-        subs        r0, r0, ip
-        ldreqh      r0, [r3, #-2]
-        ldreqh      ip, [r1, #-2]
-        subeqs      r0, r0, ip
-        /* restore registers and return */
-        ldmfd       sp!, {r4, lr}
-        bx          lr
-
-        /* process the last few words */
-8:      ldrh        r0, [r3], #2
-        ldrh        ip, [r1], #2
-        subs        r0, r0, ip
-        bne         9f
-        subs        r2, r2, #1
-        bne         8b
-
-9:      /* restore registers and return */
-        ldmfd       sp!, {r4, lr}
-        bx          lr
-
-
-5:      /*************** non-congruent case ***************/
-
-        /* align the unaligned pointer */
-        bic         r1, r1, #3
-        ldr         lr, [r1], #4
-        sub         r2, r2, #8
-
-6:
-        pld         [r3, #64]
-        pld         [r1, #64]
-        mov         ip, lr, lsr #16
-        ldr         lr, [r1], #4
-        ldr         r0, [r3], #4
-        orr         ip, ip, lr, lsl #16
-        eors        r0, r0, ip
-        moveq       ip, lr, lsr #16
-        ldreq       lr, [r1], #4
-        ldreq       r0, [r3], #4
-        orreq       ip, ip, lr, lsl #16
-        eoreqs      r0, r0, ip
-        moveq       ip, lr, lsr #16
-        ldreq       lr, [r1], #4
-        ldreq       r0, [r3], #4
-        orreq       ip, ip, lr, lsl #16
-        eoreqs      r0, r0, ip
-        moveq       ip, lr, lsr #16
-        ldreq       lr, [r1], #4
-        ldreq       r0, [r3], #4
-        orreq       ip, ip, lr, lsl #16
-        eoreqs      r0, r0, ip
-        bne         7f
-        subs        r2, r2, #8
-        bhs         6b
-        sub         r1, r1, #2
-        /* are we done? */
-        adds        r2, r2, #8
-        moveq       r0, #0
-        beq         9b
-        /* finish off the remaining bytes */
-        b           8b
-
-7:      /* fix up the 2 pointers and fallthrough... */
-        sub         r1, r1, #2
-        b           2b
-END(__memcmp16)
diff --git a/libc/arch-arm/bionic/memcpy.S b/libc/arch-arm/bionic/memcpy.S
index f25b3e3..2c9b10c 100644
--- a/libc/arch-arm/bionic/memcpy.S
+++ b/libc/arch-arm/bionic/memcpy.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #if defined(__ARM_NEON__) && !defined(ARCH_ARM_USE_NON_NEON_MEMCPY)
 
diff --git a/libc/arch-arm/bionic/memcpy.a9.S b/libc/arch-arm/bionic/memcpy.a9.S
index 2ba1ff5..259701d 100644
--- a/libc/arch-arm/bionic/memcpy.a9.S
+++ b/libc/arch-arm/bionic/memcpy.a9.S
@@ -44,7 +44,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 	.syntax unified
 	/* This implementation requires ARM state.  */
diff --git a/libc/arch-arm/bionic/setjmp.S b/libc/arch-arm/bionic/setjmp.S
index 65b93fd..ed59d07 100644
--- a/libc/arch-arm/bionic/setjmp.S
+++ b/libc/arch-arm/bionic/setjmp.S
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 #include <machine/cpu-features.h>
 
@@ -56,7 +56,7 @@
 	.cfi_rel_offset r14, 4
 	mov	r0, #0x00000000
 
-	bl	PIC_SYM(_C_LABEL(sigblock), PLT)
+	bl	PIC_SYM(sigblock, PLT)
 	mov	r1, r0
 
 	ldmfd	sp!, {r0, r14}
@@ -108,11 +108,11 @@
 	.cfi_adjust_cfa_offset 4
 
 	mov	r0, r2
-	bl	PIC_SYM(_C_LABEL(sigsetmask), PLT)
+	bl	PIC_SYM(sigsetmask, PLT)
 
 	add	sp, sp, #4	/* unalign the stack */
 	.cfi_adjust_cfa_offset -4
-	ldmfd	sp!, {r0, r1, r14} 
+	ldmfd	sp!, {r0, r1, r14}
 	.cfi_def_cfa_offset 0
 
 #ifdef __ARM_HAVE_VFP
@@ -147,7 +147,7 @@
 
 	/* validation failed, die die die. */
 botch:
-	bl	PIC_SYM(_C_LABEL(longjmperror), PLT)
-	bl	PIC_SYM(_C_LABEL(abort), PLT)
+	bl	PIC_SYM(longjmperror, PLT)
+	bl	PIC_SYM(abort, PLT)
 	b	. - 8		/* Cannot get here */
 END(longjmp)
diff --git a/libc/arch-arm/bionic/sigsetjmp.S b/libc/arch-arm/bionic/sigsetjmp.S
index 12311e5..7016f50 100644
--- a/libc/arch-arm/bionic/sigsetjmp.S
+++ b/libc/arch-arm/bionic/sigsetjmp.S
@@ -35,7 +35,7 @@
 
 #define _ALIGN_TEXT .align 0
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -50,8 +50,8 @@
 
 ENTRY(sigsetjmp)
 	teq	r1, #0
-	beq	PIC_SYM(_C_LABEL(_setjmp), PLT)
-	b	PIC_SYM(_C_LABEL(setjmp), PLT)
+	beq	PIC_SYM(_setjmp, PLT)
+	b	PIC_SYM(setjmp, PLT)
 END(sigsetjmp)
 
 .L_setjmp_magic:
@@ -61,6 +61,6 @@
 	ldr	r2, .L_setjmp_magic
 	ldr	r3, [r0]
 	teq	r2, r3
-	beq	PIC_SYM(_C_LABEL(_longjmp), PLT)
-	b	PIC_SYM(_C_LABEL(longjmp), PLT)
+	beq	PIC_SYM(_longjmp, PLT)
+	b	PIC_SYM(longjmp, PLT)
 END(siglongjmp)
diff --git a/libc/arch-arm/bionic/strcmp.S b/libc/arch-arm/bionic/strcmp.S
index 42d41d1..6dba942 100644
--- a/libc/arch-arm/bionic/strcmp.S
+++ b/libc/arch-arm/bionic/strcmp.S
@@ -28,7 +28,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 	.text
 
diff --git a/libc/arch-arm/bionic/syscall.S b/libc/arch-arm/bionic/syscall.S
index 5a6627b..d0df379 100644
--- a/libc/arch-arm/bionic/syscall.S
+++ b/libc/arch-arm/bionic/syscall.S
@@ -30,7 +30,6 @@
 
 ENTRY(syscall)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -48,5 +47,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(syscall)
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
index dc86150..36da2d9 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
index 95aaf4f..c3e3e14 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/bionic/memcpy.S b/libc/arch-arm/cortex-a15/bionic/memcpy.S
index badc93b..da4f3dd 100644
--- a/libc/arch-arm/cortex-a15/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a15/bionic/memcpy.S
@@ -55,8 +55,8 @@
 
 // Prototype: void *memcpy (void *dst, const void *src, size_t count).
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
         .text
         .syntax unified
diff --git a/libc/arch-arm/cortex-a15/bionic/memset.S b/libc/arch-arm/cortex-a15/bionic/memset.S
index 4e6d322..12c68d6 100644
--- a/libc/arch-arm/cortex-a15/bionic/memset.S
+++ b/libc/arch-arm/cortex-a15/bionic/memset.S
@@ -27,8 +27,8 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
         /*
          * Optimized memset() for ARM.
diff --git a/libc/arch-arm/cortex-a15/bionic/strcat.S b/libc/arch-arm/cortex-a15/bionic/strcat.S
index 72d4e9e..b95be94 100644
--- a/libc/arch-arm/cortex-a15/bionic/strcat.S
+++ b/libc/arch-arm/cortex-a15/bionic/strcat.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/bionic/strcmp.S b/libc/arch-arm/cortex-a15/bionic/strcmp.S
index 0cccf06..12da115 100644
--- a/libc/arch-arm/cortex-a15/bionic/strcmp.S
+++ b/libc/arch-arm/cortex-a15/bionic/strcmp.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
 #define S2LOMEM lsl
diff --git a/libc/arch-arm/cortex-a15/bionic/strcpy.S b/libc/arch-arm/cortex-a15/bionic/strcpy.S
index 5773540..cb878c4 100644
--- a/libc/arch-arm/cortex-a15/bionic/strcpy.S
+++ b/libc/arch-arm/cortex-a15/bionic/strcpy.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/bionic/strlen.S b/libc/arch-arm/cortex-a15/bionic/strlen.S
index 08f6d19..9a0ce62 100644
--- a/libc/arch-arm/cortex-a15/bionic/strlen.S
+++ b/libc/arch-arm/cortex-a15/bionic/strlen.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/cortex-a15.mk b/libc/arch-arm/cortex-a15/cortex-a15.mk
index c62e7e7..552811e 100644
--- a/libc/arch-arm/cortex-a15/cortex-a15.mk
+++ b/libc/arch-arm/cortex-a15/cortex-a15.mk
@@ -1,10 +1,10 @@
-$(call libc-add-cpu-variant-src,MEMCPY,arch-arm/cortex-a15/bionic/memcpy.S)
-$(call libc-add-cpu-variant-src,MEMSET,arch-arm/cortex-a15/bionic/memset.S)
-$(call libc-add-cpu-variant-src,STRCAT,arch-arm/cortex-a15/bionic/strcat.S)
-$(call libc-add-cpu-variant-src,STRCMP,arch-arm/cortex-a15/bionic/strcmp.S)
-$(call libc-add-cpu-variant-src,STRCPY,arch-arm/cortex-a15/bionic/strcpy.S)
-$(call libc-add-cpu-variant-src,STRLEN,arch-arm/cortex-a15/bionic/strlen.S)
-$(call libc-add-cpu-variant-src,__STRCAT_CHK,arch-arm/cortex-a15/bionic/__strcat_chk.S)
-$(call libc-add-cpu-variant-src,__STRCPY_CHK,arch-arm/cortex-a15/bionic/__strcpy_chk.S)
-
-include bionic/libc/arch-arm/generic/generic.mk
+libc_bionic_src_files_arm += \
+    arch-arm/cortex-a15/bionic/memcpy.S \
+    arch-arm/cortex-a15/bionic/memset.S \
+    arch-arm/cortex-a15/bionic/strcat.S \
+    arch-arm/cortex-a15/bionic/strcmp.S \
+    arch-arm/cortex-a15/bionic/strcpy.S \
+    arch-arm/cortex-a15/bionic/strlen.S \
+    arch-arm/cortex-a15/bionic/__strcat_chk.S \
+    arch-arm/cortex-a15/bionic/__strcpy_chk.S \
+    bionic/memmove.c \
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
index 7009168..651aefc 100644
--- a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
     .fpu    neon
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
index 908eec4..2447780 100644
--- a/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
     .fpu    neon
diff --git a/libc/arch-arm/cortex-a9/bionic/memcpy.S b/libc/arch-arm/cortex-a9/bionic/memcpy.S
index 72c1a66..8dcd937 100644
--- a/libc/arch-arm/cortex-a9/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a9/bionic/memcpy.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
diff --git a/libc/arch-arm/cortex-a9/bionic/memset.S b/libc/arch-arm/cortex-a9/bionic/memset.S
index 7f77dad..a5057eb 100644
--- a/libc/arch-arm/cortex-a9/bionic/memset.S
+++ b/libc/arch-arm/cortex-a9/bionic/memset.S
@@ -26,9 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
diff --git a/libc/arch-arm/cortex-a9/bionic/strcat.S b/libc/arch-arm/cortex-a9/bionic/strcat.S
index 0f5baef..f5a855e 100644
--- a/libc/arch-arm/cortex-a9/bionic/strcat.S
+++ b/libc/arch-arm/cortex-a9/bionic/strcat.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a9/bionic/strcmp.S b/libc/arch-arm/cortex-a9/bionic/strcmp.S
index eacdb89..2411c65 100644
--- a/libc/arch-arm/cortex-a9/bionic/strcmp.S
+++ b/libc/arch-arm/cortex-a9/bionic/strcmp.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
 #define S2LOMEM lsl
diff --git a/libc/arch-arm/cortex-a9/bionic/strcpy.S b/libc/arch-arm/cortex-a9/bionic/strcpy.S
index 9aa4f88..9e9610b 100644
--- a/libc/arch-arm/cortex-a9/bionic/strcpy.S
+++ b/libc/arch-arm/cortex-a9/bionic/strcpy.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a9/bionic/strlen.S b/libc/arch-arm/cortex-a9/bionic/strlen.S
index 259eda0..b92b043 100644
--- a/libc/arch-arm/cortex-a9/bionic/strlen.S
+++ b/libc/arch-arm/cortex-a9/bionic/strlen.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a9/cortex-a9.mk b/libc/arch-arm/cortex-a9/cortex-a9.mk
index eee1b36..9b99387 100644
--- a/libc/arch-arm/cortex-a9/cortex-a9.mk
+++ b/libc/arch-arm/cortex-a9/cortex-a9.mk
@@ -1,10 +1,10 @@
-$(call libc-add-cpu-variant-src,MEMCPY,arch-arm/cortex-a9/bionic/memcpy.S)
-$(call libc-add-cpu-variant-src,MEMSET,arch-arm/cortex-a9/bionic/memset.S)
-$(call libc-add-cpu-variant-src,STRCAT,arch-arm/cortex-a9/bionic/strcat.S)
-$(call libc-add-cpu-variant-src,STRCMP,arch-arm/cortex-a9/bionic/strcmp.S)
-$(call libc-add-cpu-variant-src,STRCPY,arch-arm/cortex-a9/bionic/strcpy.S)
-$(call libc-add-cpu-variant-src,STRLEN,arch-arm/cortex-a9/bionic/strlen.S)
-$(call libc-add-cpu-variant-src,__STRCAT_CHK,arch-arm/cortex-a9/bionic/__strcat_chk.S)
-$(call libc-add-cpu-variant-src,__STRCPY_CHK,arch-arm/cortex-a9/bionic/__strcpy_chk.S)
-
-include bionic/libc/arch-arm/generic/generic.mk
+libc_bionic_src_files_arm += \
+    arch-arm/cortex-a9/bionic/memcpy.S \
+    arch-arm/cortex-a9/bionic/memset.S \
+    arch-arm/cortex-a9/bionic/strcat.S \
+    arch-arm/cortex-a9/bionic/strcmp.S \
+    arch-arm/cortex-a9/bionic/strcpy.S \
+    arch-arm/cortex-a9/bionic/strlen.S \
+    arch-arm/cortex-a9/bionic/__strcat_chk.S \
+    arch-arm/cortex-a9/bionic/__strcpy_chk.S \
+    bionic/memmove.c \
diff --git a/libc/arch-arm/denver/bionic/__strcat_chk.S b/libc/arch-arm/denver/bionic/__strcat_chk.S
new file mode 100644
index 0000000..36da2d9
--- /dev/null
+++ b/libc/arch-arm/denver/bionic/__strcat_chk.S
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
+
+    .syntax unified
+
+    .thumb
+    .thumb_func
+
+// Get the length of src string, then get the source of the dst string.
+// Check that the two lengths together don't exceed the threshold, then
+// do a memcpy of the data.
+ENTRY(__strcat_chk)
+    pld     [r0, #0]
+    push    {r0, lr}
+    .save   {r0, lr}
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset r0, 0
+    .cfi_rel_offset lr, 4
+    push    {r4, r5}
+    .save   {r4, r5}
+    .cfi_adjust_cfa_offset 8
+    .cfi_rel_offset r4, 0
+    .cfi_rel_offset r5, 4
+
+    mov     lr, r2
+
+    // Save the dst register to r5
+    mov     r5, r0
+
+    // Zero out r4
+    eor     r4, r4, r4
+
+    // r1 contains the address of the string to count.
+.L_strlen_start:
+    mov     r0, r1
+    ands    r3, r1, #7
+    beq     .L_mainloop
+
+    // Align to a double word (64 bits).
+    rsb     r3, r3, #8
+    lsls    ip, r3, #31
+    beq     .L_align_to_32
+
+    ldrb    r2, [r1], #1
+    cbz     r2, .L_update_count_and_finish
+
+.L_align_to_32:
+    bcc     .L_align_to_64
+    ands    ip, r3, #2
+    beq     .L_align_to_64
+
+    ldrb    r2, [r1], #1
+    cbz     r2, .L_update_count_and_finish
+    ldrb    r2, [r1], #1
+    cbz     r2, .L_update_count_and_finish
+
+.L_align_to_64:
+    tst     r3, #4
+    beq     .L_mainloop
+    ldr     r3, [r1], #4
+
+    sub     ip, r3, #0x01010101
+    bic     ip, ip, r3
+    ands    ip, ip, #0x80808080
+    bne     .L_zero_in_second_register
+
+    .p2align 2
+.L_mainloop:
+    ldrd    r2, r3, [r1], #8
+
+    pld     [r1, #64]
+
+    sub     ip, r2, #0x01010101
+    bic     ip, ip, r2
+    ands    ip, ip, #0x80808080
+    bne     .L_zero_in_first_register
+
+    sub     ip, r3, #0x01010101
+    bic     ip, ip, r3
+    ands    ip, ip, #0x80808080
+    bne     .L_zero_in_second_register
+    b       .L_mainloop
+
+.L_update_count_and_finish:
+    sub     r3, r1, r0
+    sub     r3, r3, #1
+    b       .L_finish
+
+.L_zero_in_first_register:
+    sub     r3, r1, r0
+    lsls    r2, ip, #17
+    bne     .L_sub8_and_finish
+    bcs     .L_sub7_and_finish
+    lsls    ip, ip, #1
+    bne     .L_sub6_and_finish
+
+    sub     r3, r3, #5
+    b       .L_finish
+
+.L_sub8_and_finish:
+    sub     r3, r3, #8
+    b       .L_finish
+
+.L_sub7_and_finish:
+    sub     r3, r3, #7
+    b       .L_finish
+
+.L_sub6_and_finish:
+    sub     r3, r3, #6
+    b       .L_finish
+
+.L_zero_in_second_register:
+    sub     r3, r1, r0
+    lsls    r2, ip, #17
+    bne     .L_sub4_and_finish
+    bcs     .L_sub3_and_finish
+    lsls    ip, ip, #1
+    bne     .L_sub2_and_finish
+
+    sub     r3, r3, #1
+    b       .L_finish
+
+.L_sub4_and_finish:
+    sub     r3, r3, #4
+    b       .L_finish
+
+.L_sub3_and_finish:
+    sub     r3, r3, #3
+    b       .L_finish
+
+.L_sub2_and_finish:
+    sub     r3, r3, #2
+
+.L_finish:
+    cmp     r4, #0
+    bne     .L_strlen_done
+
+    // Time to get the dst string length.
+    mov     r1, r5
+
+    // Save the original source address to r5.
+    mov     r5, r0
+
+    // Save the current length (adding 1 for the terminator).
+    add     r4, r3, #1
+    b       .L_strlen_start
+
+    // r0 holds the pointer to the dst string.
+    // r3 holds the dst string length.
+    // r4 holds the src string length + 1.
+.L_strlen_done:
+    add     r2, r3, r4
+    cmp     r2, lr
+    bhi     __strcat_chk_failed
+
+    // Set up the registers for the memcpy code.
+    mov     r1, r5
+    pld     [r1, #64]
+    mov     r2, r4
+    add     r0, r0, r3
+    pop     {r4, r5}
+END(__strcat_chk)
+
+#define MEMCPY_BASE         __strcat_chk_memcpy_base
+#define MEMCPY_BASE_ALIGNED __strcat_chk_memcpy_base_aligned
+
+#include "memcpy_base.S"
+
+ENTRY_PRIVATE(__strcat_chk_failed)
+    .save   {r0, lr}
+    .save   {r4, r5}
+
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset r0, 0
+    .cfi_rel_offset lr, 4
+    .cfi_adjust_cfa_offset 8
+    .cfi_rel_offset r4, 0
+    .cfi_rel_offset r5, 4
+
+    ldr     r0, error_message
+    ldr     r1, error_code
+1:
+    add     r0, pc
+    bl      __fortify_chk_fail
+error_code:
+    .word   BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW
+error_message:
+    .word   error_string-(1b+4)
+END(__strcat_chk_failed)
+
+    .data
+error_string:
+    .string "strcat: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/bionic/__strcpy_chk.S b/libc/arch-arm/denver/bionic/__strcpy_chk.S
new file mode 100644
index 0000000..c3e3e14
--- /dev/null
+++ b/libc/arch-arm/denver/bionic/__strcpy_chk.S
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
+
+    .syntax unified
+
+    .thumb
+    .thumb_func
+
+// Get the length of the source string first, then do a memcpy of the data
+// instead of a strcpy.
+ENTRY(__strcpy_chk)
+    pld     [r0, #0]
+    push    {r0, lr}
+    .save   {r0, lr}
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset r0, 0
+    .cfi_rel_offset lr, 4
+
+    mov     lr, r2
+    mov     r0, r1
+
+    ands    r3, r1, #7
+    beq     .L_mainloop
+
+    // Align to a double word (64 bits).
+    rsb     r3, r3, #8
+    lsls    ip, r3, #31
+    beq     .L_align_to_32
+
+    ldrb    r2, [r0], #1
+    cbz     r2, .L_update_count_and_finish
+
+.L_align_to_32:
+    bcc     .L_align_to_64
+    ands    ip, r3, #2
+    beq     .L_align_to_64
+
+    ldrb    r2, [r0], #1
+    cbz     r2, .L_update_count_and_finish
+    ldrb    r2, [r0], #1
+    cbz     r2, .L_update_count_and_finish
+
+.L_align_to_64:
+    tst     r3, #4
+    beq     .L_mainloop
+    ldr     r3, [r0], #4
+
+    sub     ip, r3, #0x01010101
+    bic     ip, ip, r3
+    ands    ip, ip, #0x80808080
+    bne     .L_zero_in_second_register
+
+    .p2align 2
+.L_mainloop:
+    ldrd    r2, r3, [r0], #8
+
+    pld     [r0, #64]
+
+    sub     ip, r2, #0x01010101
+    bic     ip, ip, r2
+    ands    ip, ip, #0x80808080
+    bne     .L_zero_in_first_register
+
+    sub     ip, r3, #0x01010101
+    bic     ip, ip, r3
+    ands    ip, ip, #0x80808080
+    bne     .L_zero_in_second_register
+    b       .L_mainloop
+
+.L_update_count_and_finish:
+    sub     r3, r0, r1
+    sub     r3, r3, #1
+    b       .L_check_size
+
+.L_zero_in_first_register:
+    sub     r3, r0, r1
+    lsls    r2, ip, #17
+    bne     .L_sub8_and_finish
+    bcs     .L_sub7_and_finish
+    lsls    ip, ip, #1
+    bne     .L_sub6_and_finish
+
+    sub     r3, r3, #5
+    b       .L_check_size
+
+.L_sub8_and_finish:
+    sub     r3, r3, #8
+    b       .L_check_size
+
+.L_sub7_and_finish:
+    sub     r3, r3, #7
+    b       .L_check_size
+
+.L_sub6_and_finish:
+    sub     r3, r3, #6
+    b       .L_check_size
+
+.L_zero_in_second_register:
+    sub     r3, r0, r1
+    lsls    r2, ip, #17
+    bne     .L_sub4_and_finish
+    bcs     .L_sub3_and_finish
+    lsls    ip, ip, #1
+    bne     .L_sub2_and_finish
+
+    sub     r3, r3, #1
+    b       .L_check_size
+
+.L_sub4_and_finish:
+    sub     r3, r3, #4
+    b       .L_check_size
+
+.L_sub3_and_finish:
+    sub     r3, r3, #3
+    b       .L_check_size
+
+.L_sub2_and_finish:
+    sub     r3, r3, #2
+
+.L_check_size:
+    pld     [r1, #0]
+    pld     [r1, #64]
+    ldr     r0, [sp]
+    cmp     r3, lr
+    bhs     __strcpy_chk_failed
+
+    // Add 1 for copy length to get the string terminator.
+    add     r2, r3, #1
+END(__strcpy_chk)
+
+#define MEMCPY_BASE         __strcpy_chk_memcpy_base
+#define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
+#include "memcpy_base.S"
+
+ENTRY_PRIVATE(__strcpy_chk_failed)
+    .save   {r0, lr}
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset r0, 0
+    .cfi_rel_offset lr, 4
+
+    ldr     r0, error_message
+    ldr     r1, error_code
+1:
+    add     r0, pc
+    bl      __fortify_chk_fail
+error_code:
+    .word   BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW
+error_message:
+    .word   error_string-(1b+4)
+END(__strcpy_chk_failed)
+
+    .data
+error_string:
+    .string "strcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/bionic/memcpy.S b/libc/arch-arm/denver/bionic/memcpy.S
new file mode 100644
index 0000000..da4f3dd
--- /dev/null
+++ b/libc/arch-arm/denver/bionic/memcpy.S
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * Copyright (c) 2013 ARM Ltd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the company may not be used to endorse or promote
+ *    products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// Prototype: void *memcpy (void *dst, const void *src, size_t count).
+
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
+
+        .text
+        .syntax unified
+        .fpu    neon
+
+ENTRY(__memcpy_chk)
+        cmp     r2, r3
+        bhi     __memcpy_chk_fail
+
+        // Fall through to memcpy...
+END(__memcpy_chk)
+
+ENTRY(memcpy)
+        pld     [r1, #64]
+        push    {r0, lr}
+        .save   {r0, lr}
+        .cfi_def_cfa_offset 8
+        .cfi_rel_offset r0, 0
+        .cfi_rel_offset lr, 4
+END(memcpy)
+
+#define MEMCPY_BASE         __memcpy_base
+#define MEMCPY_BASE_ALIGNED __memcpy_base_aligned
+#include "memcpy_base.S"
+
+ENTRY_PRIVATE(__memcpy_chk_fail)
+        // Preserve lr for backtrace.
+        push    {lr}
+        .save   {lr}
+        .cfi_def_cfa_offset 4
+        .cfi_rel_offset lr, 0
+
+        ldr     r0, error_message
+        ldr     r1, error_code
+1:
+        add     r0, pc
+        bl      __fortify_chk_fail
+error_code:
+        .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
+error_message:
+        .word   error_string-(1b+8)
+END(__memcpy_chk_fail)
+
+        .data
+error_string:
+        .string "memcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/bionic/memcpy_base.S b/libc/arch-arm/denver/bionic/memcpy_base.S
new file mode 100644
index 0000000..2abb486
--- /dev/null
+++ b/libc/arch-arm/denver/bionic/memcpy_base.S
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ * Copyright (c) 2013-2014, NVIDIA Corporation.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#define CACHE_LINE_SIZE         (64)
+#define PREFETCH_DISTANCE       (CACHE_LINE_SIZE*6)
+
+ENTRY_PRIVATE(MEMCPY_BASE)
+        .cfi_def_cfa_offset 8
+        .cfi_rel_offset r0, 0
+        .cfi_rel_offset lr, 4
+
+        cmp         r2, #0
+        beq         .L_memcpy_done
+        cmp         r0, r1
+        beq         .L_memcpy_done
+
+        /* preload next cache line */
+        pld         [r1, #CACHE_LINE_SIZE*1]
+
+        /* Deal with very small blocks (< 32bytes) asap */
+        cmp         r2, #32
+        blo         .L_memcpy_lt_32bytes
+        /* no need to align if len < 128 bytes */
+        cmp         r2, #128
+        blo         .L_memcpy_lt_128bytes
+
+        /* large copy, align dest to 64 byte boundry */
+        pld         [r1, #CACHE_LINE_SIZE*2]
+        rsb         r3, r0, #0
+        ands        r3, r3, #0x3F
+        pld         [r1, #CACHE_LINE_SIZE*3]
+        beq         .L_memcpy_dispatch
+        sub         r2, r2, r3
+        /* copy 1 byte */
+        movs        ip, r3, lsl #31
+        itt         mi
+        ldrbmi      ip, [r1], #1
+        strbmi      ip, [r0], #1
+        /* copy 2 bytes */
+        itt         cs
+        ldrhcs      ip, [r1], #2
+        strhcs      ip, [r0], #2
+        /* copy 4 bytes */
+        movs        ip, r3, lsl #29
+        itt         mi
+        ldrmi       ip, [r1], #4
+        strmi       ip, [r0], #4
+        /* copy 8 bytes */
+        bcc         1f
+        vld1.8      {d0}, [r1]!
+        vst1.8      {d0}, [r0, :64]!
+1:      /* copy 16 bytes */
+        movs        ip, r3, lsl #27
+        bpl         1f
+        vld1.8      {q0}, [r1]!
+        vst1.8      {q0}, [r0, :128]!
+1:      /* copy 32 bytes */
+        bcc         .L_memcpy_dispatch
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0, :256]!
+
+.L_memcpy_dispatch:
+        // pre-decrement by 128 to detect nearly-done condition easily, but
+        // also need to check if we have less than 128 bytes left at this
+        // point due to alignment code above
+        subs        r2, r2, #128
+        blo         .L_memcpy_lt_128presub
+
+        // Denver does better if both source and dest are aligned so
+        // we'll special-case that even though the code is virually identical
+        tst         r1, #0xF
+        bne         .L_memcpy_neon_unalign_src_pld
+
+        // DRAM memcpy should be throttled slightly to get full bandwidth
+        //
+        cmp         r2, #32768
+        bhi         .L_memcpy_neon_unalign_src_pld
+        .align      4
+1:
+        /* copy 128 bytes in each loop */
+        subs        r2, r2, #128
+
+        /* preload a cache line */
+        pld         [r1, #PREFETCH_DISTANCE]
+        /* copy a cache line */
+        vld1.8      {q0, q1}, [r1, :128]!
+        vst1.8      {q0, q1}, [r0, :256]!
+        vld1.8      {q0, q1}, [r1, :128]!
+        vst1.8      {q0, q1}, [r0, :256]!
+        /* preload a cache line */
+        pld         [r1, #PREFETCH_DISTANCE]
+        /* copy a cache line */
+        vld1.8      {q0, q1}, [r1, :128]!
+        vst1.8      {q0, q1}, [r0, :256]!
+        vld1.8      {q0, q1}, [r1, :128]!
+        vst1.8      {q0, q1}, [r0, :256]!
+
+        bhs         1b
+        adds        r2, r2, #128
+        bne         .L_memcpy_lt_128bytes_align
+        pop         {r0, pc}
+
+        .align      4
+.L_memcpy_neon_unalign_src_pld:
+1:
+        /* copy 128 bytes in each loop */
+        subs        r2, r2, #128
+
+        /* preload a cache line */
+        pld         [r1, #PREFETCH_DISTANCE]
+        /* copy a cache line */
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0, :256]!
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0, :256]!
+        /* preload a cache line */
+        pld         [r1, #PREFETCH_DISTANCE]
+        /* copy a cache line */
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0, :256]!
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0, :256]!
+
+        bhs         1b
+        adds        r2, r2, #128
+        bne         .L_memcpy_lt_128bytes_align
+        pop         {r0, pc}
+
+.L_memcpy_lt_128presub:
+        add         r2, r2, #128
+.L_memcpy_lt_128bytes_align:
+        /* copy 64 bytes */
+        movs        ip, r2, lsl #26
+        bcc         1f
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0, :256]!
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0, :256]!
+1:      /* copy 32 bytes */
+        bpl         1f
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0, :256]!
+1:      /* copy 16 bytes */
+        movs        ip, r2, lsl #28
+        bcc         1f
+        vld1.8      {q0}, [r1]!
+        vst1.8      {q0}, [r0, :128]!
+1:      /* copy 8 bytes */
+        bpl         1f
+        vld1.8      {d0}, [r1]!
+        vst1.8      {d0}, [r0, :64]!
+1:      /* copy 4 bytes */
+        tst         r2, #4
+        itt         ne
+        ldrne       ip, [r1], #4
+        strne       ip, [r0], #4
+        /* copy 2 bytes */
+        movs        ip, r2, lsl #31
+        itt         cs
+        ldrhcs      ip, [r1], #2
+        strhcs      ip, [r0], #2
+        /* copy 1 byte */
+        itt         mi
+        ldrbmi      ip, [r1]
+        strbmi      ip, [r0]
+
+        pop         {r0, pc}
+
+.L_memcpy_lt_128bytes:
+        /* copy 64 bytes */
+        movs        ip, r2, lsl #26
+        bcc         1f
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0]!
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0]!
+1:      /* copy 32 bytes */
+        bpl	    .L_memcpy_lt_32bytes
+        vld1.8      {q0, q1}, [r1]!
+        vst1.8      {q0, q1}, [r0]!
+.L_memcpy_lt_32bytes:
+        /* copy 16 bytes */
+        movs        ip, r2, lsl #28
+        bcc         1f
+        vld1.8      {q0}, [r1]!
+        vst1.8      {q0}, [r0]!
+1:      /* copy 8 bytes */
+        bpl         1f
+        vld1.8      {d0}, [r1]!
+        vst1.8      {d0}, [r0]!
+1:      /* copy 4 bytes */
+        tst         r2, #4
+        itt         ne
+        ldrne       ip, [r1], #4
+        strne       ip, [r0], #4
+        /* copy 2 bytes */
+        movs        ip, r2, lsl #31
+        itt         cs
+        ldrhcs      ip, [r1], #2
+        strhcs      ip, [r0], #2
+        /* copy 1 byte */
+        itt         mi
+        ldrbmi      ip, [r1]
+        strbmi      ip, [r0]
+
+.L_memcpy_done:
+        pop         {r0, pc}
+END(MEMCPY_BASE)
diff --git a/libc/arch-arm/denver/bionic/memmove.S b/libc/arch-arm/denver/bionic/memmove.S
new file mode 100644
index 0000000..132190b
--- /dev/null
+++ b/libc/arch-arm/denver/bionic/memmove.S
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ * Copyright (c) 2013-2014 NVIDIA Corporation.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
+
+        .text
+        .syntax unified
+        .fpu    neon
+
+#define CACHE_LINE_SIZE         (64)
+#define MEMCPY_BLOCK_SIZE_SMALL (32768)
+#define MEMCPY_BLOCK_SIZE_MID   (1048576)
+#define PREFETCH_DISTANCE_NEAR  (CACHE_LINE_SIZE*4)
+#define PREFETCH_DISTANCE_MID   (CACHE_LINE_SIZE*4)
+#define PREFETCH_DISTANCE_FAR   (CACHE_LINE_SIZE*16)
+
+ENTRY(memmove)
+        cmp         r2, #0
+        cmpne       r0, r1
+        bxeq        lr
+        subs        r3, r0, r1
+        bls         .L_jump_to_memcpy
+        cmp         r2, r3
+        bhi         .L_reversed_memcpy
+
+.L_jump_to_memcpy:
+        b           memcpy
+
+.L_reversed_memcpy:
+        push        {r0, lr}
+        .cfi_def_cfa_offset 8
+        .cfi_rel_offset r0, 0
+        .cfi_rel_offset lr, 4
+
+        add         r0, r0, r2
+        add         r1, r1, r2
+
+        /* preload next cache line */
+        pld         [r1, #-CACHE_LINE_SIZE]
+        pld         [r1, #-CACHE_LINE_SIZE*2]
+
+.L_reversed_memcpy_align_dest:
+        /* Deal with very small blocks (< 32bytes) asap */
+        cmp         r2, #32
+        blo         .L_reversed_memcpy_lt_32bytes
+        /* no need to align if len < 128 bytes */
+        cmp         r2, #128
+        blo         .L_reversed_memcpy_lt_128bytes
+        /* align destination to 64 bytes (1 cache line) */
+        ands        r3, r0, #0x3f
+        beq         .L_reversed_memcpy_dispatch
+        sub         r2, r2, r3
+0:      /* copy 1 byte */
+        movs        ip, r3, lsl #31
+        ldrbmi      ip, [r1, #-1]!
+        strbmi      ip, [r0, #-1]!
+1:      /* copy 2 bytes */
+        ldrbcs      ip, [r1, #-1]!
+        strbcs      ip, [r0, #-1]!
+        ldrbcs      ip, [r1, #-1]!
+        strbcs      ip, [r0, #-1]!
+2:      /* copy 4 bytes */
+        movs        ip, r3, lsl #29
+        bpl         3f
+        sub         r1, r1, #4
+        sub         r0, r0, #4
+        vld4.8      {d0[0], d1[0], d2[0], d3[0]}, [r1]
+        vst4.8      {d0[0], d1[0], d2[0], d3[0]}, [r0, :32]
+3:      /* copy 8 bytes */
+        bcc         4f
+        sub         r1, r1, #8
+        sub         r0, r0, #8
+        vld1.8      {d0}, [r1]
+        vst1.8      {d0}, [r0, :64]
+4:      /* copy 16 bytes */
+        movs        ip, r3, lsl #27
+        bpl         5f
+        sub         r1, r1, #16
+        sub         r0, r0, #16
+        vld1.8      {q0}, [r1]
+        vst1.8      {q0}, [r0, :128]
+5:      /* copy 32 bytes */
+        bcc         .L_reversed_memcpy_dispatch
+        sub         r1, r1, #32
+        sub         r0, r0, #32
+        vld1.8      {q0, q1}, [r1]
+        vst1.8      {q0, q1}, [r0, :256]
+
+.L_reversed_memcpy_dispatch:
+        /* preload more cache lines */
+        pld         [r1, #-CACHE_LINE_SIZE*3]
+        pld         [r1, #-CACHE_LINE_SIZE*4]
+
+        cmp         r2, #MEMCPY_BLOCK_SIZE_SMALL
+        blo         .L_reversed_memcpy_neon_pld_near
+        cmp         r2, #MEMCPY_BLOCK_SIZE_MID
+        blo         .L_reversed_memcpy_neon_pld_mid
+        b           .L_reversed_memcpy_neon_pld_far
+
+.L_reversed_memcpy_neon_pld_near:
+        /* less than 128 bytes? */
+        subs        r2, r2, #128
+        blo         1f
+        sub         r1, r1, #32
+        sub         r0, r0, #32
+        mov         r3, #-32
+        .align      4
+0:
+        /* copy 128 bytes in each loop */
+        subs        r2, r2, #128
+
+        /* preload to cache */
+        pld         [r1, #-(PREFETCH_DISTANCE_NEAR+CACHE_LINE_SIZE*2)+32]
+        /* copy a cache line */
+        vld1.8      {q0, q1}, [r1], r3
+        vst1.8      {q0, q1}, [r0, :256], r3
+        vld1.8      {q0, q1}, [r1], r3
+        vst1.8      {q0, q1}, [r0, :256], r3
+
+        /* preload to cache */
+        pld         [r1, #-(PREFETCH_DISTANCE_NEAR+CACHE_LINE_SIZE*2)+32]
+        /* copy a cache line */
+        vld1.8      {q0, q1}, [r1], r3
+        vst1.8      {q0, q1}, [r0, :256], r3
+        vld1.8      {q0, q1}, [r1], r3
+        vst1.8      {q0, q1}, [r0, :256], r3
+
+        bhs         0b
+        add         r1, r1, #32
+        add         r0, r0, #32
+1:
+        adds        r2, r2, #128
+        bne         .L_reversed_memcpy_lt_128bytes
+        pop         {r0, pc}
+
+.L_reversed_memcpy_neon_pld_mid:
+        subs        r2, r2, #128
+        sub         r1, r1, #32
+        sub         r0, r0, #32
+        mov         r3, #-32
+        .align      4
+0:
+        /* copy 128 bytes in each loop */
+        subs        r2, r2, #128
+
+        /* preload to cache */
+        pld         [r1, #-(PREFETCH_DISTANCE_MID+CACHE_LINE_SIZE)+32]
+        /* copy a cache line */
+        vld1.8      {q0, q1}, [r1], r3
+        vst1.8      {q0, q1}, [r0, :256], r3
+        vld1.8      {q0, q1}, [r1], r3
+        vst1.8      {q0, q1}, [r0, :256], r3
+
+        /* preload to cache */
+        pld         [r1, #-(PREFETCH_DISTANCE_MID+CACHE_LINE_SIZE)+32]
+        /* copy a cache line */
+        vld1.8      {q0, q1}, [r1], r3
+        vst1.8      {q0, q1}, [r0, :256], r3
+        vld1.8      {q0, q1}, [r1], r3
+        vst1.8      {q0, q1}, [r0, :256], r3
+
+        bhs         0b
+        add         r1, r1, #32
+        add         r0, r0, #32
+1:
+        adds        r2, r2, #128
+        bne         .L_reversed_memcpy_lt_128bytes
+        pop         {r0, pc}
+
+.L_reversed_memcpy_neon_pld_far:
+        sub         r2, r2, #128
+        sub         r0, r0, #128
+        sub         r1, r1, #128
+        .align      4
+0:
+        /* copy 128 bytes in each loop */
+        subs        r2, r2, #128
+
+        /* preload to cache */
+        pld         [r1, #-(PREFETCH_DISTANCE_FAR+CACHE_LINE_SIZE*2)+128]
+        pld         [r1, #-(PREFETCH_DISTANCE_FAR+CACHE_LINE_SIZE)+128]
+        /* read */
+        vld1.8      {q0, q1}, [r1]!
+        vld1.8      {q2, q3}, [r1]!
+        vld1.8      {q8, q9}, [r1]!
+        vld1.8      {q10, q11}, [r1]!
+        /* write */
+        vst1.8      {q0, q1}, [r0, :256]!
+        vst1.8      {q2, q3}, [r0, :256]!
+        vst1.8      {q8, q9}, [r0, :256]!
+        vst1.8      {q10, q11}, [r0, :256]!
+
+        sub         r0, r0, #256
+        sub         r1, r1, #256
+        bhs         0b
+        add         r0, r0, #128
+        add         r1, r1, #128
+1:
+        adds        r2, r2, #128
+        bne         .L_reversed_memcpy_lt_128bytes
+        pop         {r0, pc}
+
+.L_reversed_memcpy_lt_128bytes:
+6:      /* copy 64 bytes */
+        movs        ip, r2, lsl #26
+        bcc         5f
+        sub         r1, r1, #32
+        sub         r0, r0, #32
+        vld1.8      {q0, q1}, [r1]
+        vst1.8      {q0, q1}, [r0]
+        sub         r1, r1, #32
+        sub         r0, r0, #32
+        vld1.8      {q0, q1}, [r1]
+        vst1.8      {q0, q1}, [r0]
+5:      /* copy 32 bytes */
+        bpl         4f
+        sub         r1, r1, #32
+        sub         r0, r0, #32
+        vld1.8      {q0, q1}, [r1]
+        vst1.8      {q0, q1}, [r0]
+.L_reversed_memcpy_lt_32bytes:
+4:      /* copy 16 bytes */
+        movs        ip, r2, lsl #28
+        bcc         3f
+        sub         r1, r1, #16
+        sub         r0, r0, #16
+        vld1.8      {q0}, [r1]
+        vst1.8      {q0}, [r0]
+3:      /* copy 8 bytes */
+        bpl         2f
+        sub         r1, r1, #8
+        sub         r0, r0, #8
+        vld1.8      {d0}, [r1]
+        vst1.8      {d0}, [r0]
+2:      /* copy 4 bytes */
+        ands        ip, r2, #0x4
+        beq         1f
+        sub         r1, r1, #4
+        sub         r0, r0, #4
+        vld4.8      {d0[0], d1[0], d2[0], d3[0]}, [r1]
+        vst4.8      {d0[0], d1[0], d2[0], d3[0]}, [r0]
+1:      /* copy 2 bytes */
+        movs        ip, r2, lsl #31
+        ldrbcs      ip, [r1, #-1]!
+        strbcs      ip, [r0, #-1]!
+        ldrbcs      ip, [r1, #-1]!
+        strbcs      ip, [r0, #-1]!
+0:      /* copy 1 byte */
+        ldrbmi      ip, [r1, #-1]!
+        strbmi      ip, [r0, #-1]!
+
+        pop         {r0, pc}
+
+END(memmove)
diff --git a/libc/arch-arm/denver/bionic/memset.S b/libc/arch-arm/denver/bionic/memset.S
new file mode 100644
index 0000000..bf3d9ad
--- /dev/null
+++ b/libc/arch-arm/denver/bionic/memset.S
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/cpu-features.h>
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
+
+        /*
+         * Optimized memset() for ARM.
+         *
+         * memset() returns its first argument.
+         */
+
+        .fpu        neon
+        .syntax     unified
+
+ENTRY(__memset_chk)
+        cmp         r2, r3
+        bls         .L_done
+
+        // Preserve lr for backtrace.
+        push        {lr}
+        .cfi_def_cfa_offset 4
+        .cfi_rel_offset lr, 0
+
+
+        ldr         r0, error_message
+        ldr         r1, error_code
+1:
+        add         r0, pc
+        bl          __fortify_chk_fail
+error_code:
+        .word       BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
+error_message:
+        .word       error_string-(1b+8)
+END(__memset_chk)
+
+ENTRY(bzero)
+        mov         r2, r1
+        mov         r1, #0
+.L_done:
+        // Fall through to memset...
+END(bzero)
+
+ENTRY(memset)
+        pldw        [r0]
+        mov         r3, r0
+
+        // Duplicate the low byte of r1
+        mov         r1, r1, lsl #24
+        orr         r1, r1, r1, lsr #8
+        orr         r1, r1, r1, lsr #16
+
+        cmp         r2, #16
+        blo         .L_less_than_16
+
+        // This section handles regions 16 bytes or larger
+        //
+        // Use aligned vst1.8 and vstm when possible.  Register values will be:
+        //   ip is scratch
+        //   q0, q1, and r1 contain the memset value
+        //   r2 is the number of bytes to set
+        //   r3 is the advancing destination pointer
+        vdup.32     q0, r1
+
+        ands        ip, r3, 0xF
+        beq         .L_memset_aligned
+
+        // Align dest pointer to 16-byte boundary.
+        pldw        [r0, #64]
+        rsb         ip, ip, #16
+
+        // Pre-adjust the byte count to reflect post-aligment value.  Expecting
+        // 8-byte alignment to be rather common so we special case that one.
+        sub         r2, r2, ip
+
+        /* set 1 byte */
+        tst         ip, #1
+        it          ne
+        strbne      r1, [r3], #1
+        /* set 2 bytes */
+        tst         ip, #2
+        it          ne
+        strhne      r1, [r3], #2
+        /* set 4 bytes */
+        movs        ip, ip, lsl #29
+        it          mi
+        strmi       r1, [r3], #4
+        /* set 8 bytes */
+        itt         cs
+        strcs       r1, [r3], #4
+        strcs       r1, [r3], #4
+
+.L_memset_aligned:
+        // Destination is now 16-byte aligned.  Determine how to handle
+        // remaining bytes.
+        vmov        q1, q0
+        cmp         r2, #128
+        blo         .L_less_than_128
+
+        // We need to set a larger block of memory.  Use four Q regs to
+        // set a full cache line in one instruction.  Pre-decrement
+        // r2 to simplify end-of-loop detection
+        vmov        q2, q0
+        vmov        q3, q0
+        pldw        [r0, #128]
+        sub         r2, r2, #128
+        .align 4
+.L_memset_loop_128:
+        pldw        [r3, #192]
+        vstm        r3!, {q0, q1, q2, q3}
+        vstm        r3!, {q0, q1, q2, q3}
+        subs        r2, r2, #128
+        bhs         .L_memset_loop_128
+
+        // Un-bias r2 so it contains the number of bytes left.  Early
+        // exit if we are done.
+        adds        r2, r2, #128
+        beq         2f
+
+        .align 4
+.L_less_than_128:
+        // set 64 bytes
+        movs        ip, r2, lsl #26
+        bcc         1f
+        vst1.8      {q0, q1}, [r3, :128]!
+        vst1.8      {q0, q1}, [r3, :128]!
+        beq         2f
+1:
+        // set 32 bytes
+        bpl         1f
+        vst1.8      {q0, q1}, [r3, :128]!
+1:
+        // set 16 bytes
+        movs        ip, r2, lsl #28
+        bcc         1f
+        vst1.8      {q0}, [r3, :128]!
+        beq         2f
+1:
+        // set 8 bytes
+        bpl         1f
+        vst1.8      {d0}, [r3, :64]!
+1:
+        // set 4 bytes
+        tst         r2, #4
+        it          ne
+        strne       r1, [r3], #4
+1:
+        // set 2 bytes
+        movs        ip, r2, lsl #31
+        it          cs
+        strhcs      r1, [r3], #2
+        // set 1 byte
+        it          mi
+        strbmi      r1, [r3]
+2:
+        bx          lr
+
+.L_less_than_16:
+        // Store up to 15 bytes without worrying about byte alignment
+        movs        ip, r2, lsl #29
+        bcc         1f
+        str         r1, [r3], #4
+        str         r1, [r3], #4
+        beq         2f
+1:
+        it          mi
+        strmi       r1, [r3], #4
+        movs        ip, r2, lsl #31
+        it          mi
+        strbmi      r1, [r3], #1
+        itt         cs
+        strbcs      r1, [r3], #1
+        strbcs      r1, [r3]
+2:
+        bx          lr
+END(memset)
+
+        .data
+error_string:
+        .string     "memset: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/denver.mk b/libc/arch-arm/denver/denver.mk
new file mode 100644
index 0000000..6989187
--- /dev/null
+++ b/libc/arch-arm/denver/denver.mk
@@ -0,0 +1,13 @@
+libc_bionic_src_files_arm += \
+    arch-arm/denver/bionic/memcpy.S \
+    arch-arm/denver/bionic/memmove.S \
+    arch-arm/denver/bionic/memset.S \
+    arch-arm/denver/bionic/__strcat_chk.S \
+    arch-arm/denver/bionic/__strcpy_chk.S \
+
+# Use cortex-a15 versions of strcat/strcpy/strlen.
+libc_bionic_src_files_arm += \
+    arch-arm/cortex-a15/bionic/strcat.S \
+    arch-arm/cortex-a15/bionic/strcpy.S \
+    arch-arm/cortex-a15/bionic/strlen.S \
+    arch-arm/cortex-a15/bionic/strcmp.S \
diff --git a/libc/arch-arm/generic/bionic/memcpy.S b/libc/arch-arm/generic/bionic/memcpy.S
index 699b88d..cd4a13d 100644
--- a/libc/arch-arm/generic/bionic/memcpy.S
+++ b/libc/arch-arm/generic/bionic/memcpy.S
@@ -27,8 +27,8 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
         /*
          * Optimized memcpy() for ARM.
diff --git a/libc/arch-arm/generic/bionic/memset.S b/libc/arch-arm/generic/bionic/memset.S
index baeb519..be35de9 100644
--- a/libc/arch-arm/generic/bionic/memset.S
+++ b/libc/arch-arm/generic/bionic/memset.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
         /*
          * Optimized memset() for ARM.
diff --git a/libc/arch-arm/generic/bionic/strcmp.S b/libc/arch-arm/generic/bionic/strcmp.S
index 42d41d1..6dba942 100644
--- a/libc/arch-arm/generic/bionic/strcmp.S
+++ b/libc/arch-arm/generic/bionic/strcmp.S
@@ -28,7 +28,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 	.text
 
diff --git a/libc/arch-arm/generic/bionic/strcpy.S b/libc/arch-arm/generic/bionic/strcpy.S
index cc997f4..802a62d 100644
--- a/libc/arch-arm/generic/bionic/strcpy.S
+++ b/libc/arch-arm/generic/bionic/strcpy.S
@@ -30,7 +30,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(strcpy)
 	pld	[r1, #0]
diff --git a/libc/arch-arm/generic/generic.mk b/libc/arch-arm/generic/generic.mk
index e230003..2456e6e 100644
--- a/libc/arch-arm/generic/generic.mk
+++ b/libc/arch-arm/generic/generic.mk
@@ -1,8 +1,10 @@
-$(call libc-add-cpu-variant-src,MEMCPY,arch-arm/generic/bionic/memcpy.S)
-$(call libc-add-cpu-variant-src,MEMSET,arch-arm/generic/bionic/memset.S)
-$(call libc-add-cpu-variant-src,STRCAT,string/strcat.c)
-$(call libc-add-cpu-variant-src,STRCMP,arch-arm/generic/bionic/strcmp.S)
-$(call libc-add-cpu-variant-src,STRCPY,arch-arm/generic/bionic/strcpy.S)
-$(call libc-add-cpu-variant-src,STRLEN,arch-arm/generic/bionic/strlen.c)
-$(call libc-add-cpu-variant-src,__STRCAT_CHK,bionic/__strcat_chk.cpp)
-$(call libc-add-cpu-variant-src,__STRCPY_CHK,bionic/__strcpy_chk.cpp)
+libc_bionic_src_files_arm += \
+    arch-arm/generic/bionic/memcpy.S \
+    arch-arm/generic/bionic/memset.S \
+    arch-arm/generic/bionic/strcmp.S \
+    arch-arm/generic/bionic/strcpy.S \
+    arch-arm/generic/bionic/strlen.c \
+    bionic/memmove.c \
+    bionic/__strcat_chk.cpp \
+    bionic/__strcpy_chk.cpp \
+    upstream-openbsd/lib/libc/string/strcat.c \
diff --git a/libc/arch-arm/include/machine/_types.h b/libc/arch-arm/include/machine/_types.h
deleted file mode 100644
index 0a8b610..0000000
--- a/libc/arch-arm/include/machine/_types.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*	$OpenBSD: _types.h,v 1.3 2006/02/14 18:12:58 miod Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)types.h	8.3 (Berkeley) 1/5/94
- *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
- */
-
-#ifndef _ARM__TYPES_H_
-#define _ARM__TYPES_H_
-
-/* 7.18.1.1 Exact-width integer types */
-typedef	__signed char		__int8_t;
-typedef	unsigned char		__uint8_t;
-typedef	short			__int16_t;
-typedef	unsigned short		__uint16_t;
-typedef	int			__int32_t;
-typedef	unsigned int		__uint32_t;
-/* LONGLONG */
-typedef	long long		__int64_t;
-/* LONGLONG */
-typedef	unsigned long long	__uint64_t;
-
-/* 7.18.1.2 Minimum-width integer types */
-typedef	__int8_t		__int_least8_t;
-typedef	__uint8_t		__uint_least8_t;
-typedef	__int16_t		__int_least16_t;
-typedef	__uint16_t		__uint_least16_t;
-typedef	__int32_t		__int_least32_t;
-typedef	__uint32_t		__uint_least32_t;
-typedef	__int64_t		__int_least64_t;
-typedef	__uint64_t		__uint_least64_t;
-
-/* 7.18.1.3 Fastest minimum-width integer types */
-typedef	__int32_t		__int_fast8_t;
-typedef	__uint32_t		__uint_fast8_t;
-typedef	__int32_t		__int_fast16_t;
-typedef	__uint32_t		__uint_fast16_t;
-typedef	__int32_t		__int_fast32_t;
-typedef	__uint32_t		__uint_fast32_t;
-typedef	__int64_t		__int_fast64_t;
-typedef	__uint64_t		__uint_fast64_t;
-
-/* 7.18.1.4 Integer types capable of holding object pointers */
-typedef	int 			__intptr_t;
-typedef	unsigned int 		__uintptr_t;
-
-/* 7.18.1.5 Greatest-width integer types */
-typedef	__int64_t		__intmax_t;
-typedef	__uint64_t		__uintmax_t;
-
-/* Register size */
-typedef __int32_t		__register_t;
-
-/* VM system types */
-typedef unsigned long		__vaddr_t;
-typedef unsigned long		__paddr_t;
-typedef unsigned long		__vsize_t;
-typedef unsigned long		__psize_t;
-
-/* Standard system types */
-typedef int			__clock_t;
-typedef int			__clockid_t;
-typedef double			__double_t;
-typedef float			__float_t;
-typedef long			__ptrdiff_t;
-typedef	int			__time_t;
-typedef int			__timer_t;
-#if defined(__GNUC__) && __GNUC__ >= 3
-typedef	__builtin_va_list	__va_list;
-#else
-typedef	char *			__va_list;
-#endif
-
-/* Wide character support types */
-#ifndef __cplusplus
-typedef	int			__wchar_t;
-#endif
-typedef int			__wint_t;
-typedef	int			__rune_t;
-typedef	void *			__wctrans_t;
-typedef	void *			__wctype_t;
-
-#endif	/* _ARM__TYPES_H_ */
diff --git a/libc/arch-arm/include/machine/asm.h b/libc/arch-arm/include/machine/asm.h
index f16baf8..7954f05 100644
--- a/libc/arch-arm/include/machine/asm.h
+++ b/libc/arch-arm/include/machine/asm.h
@@ -38,107 +38,22 @@
 #ifndef _ARM32_ASM_H_
 #define _ARM32_ASM_H_
 
-#ifdef __ELF__
-# define _C_LABEL(x)	x
-#else
-# ifdef __STDC__
-#  define _C_LABEL(x)	_ ## x
-# else
-#  define _C_LABEL(x)	_/**/x
-# endif
-#endif
-#define	_ASM_LABEL(x)	x
-
-#ifdef __STDC__
-# define __CONCAT(x,y)	x ## y
-# define __STRING(x)	#x
-#else
-# define __CONCAT(x,y)	x/**/y
-# define __STRING(x)	"x"
-#endif
-
 #ifndef _ALIGN_TEXT
 # define _ALIGN_TEXT .align 0
 #endif
 
-/*
- * gas/arm uses @ as a single comment character and thus cannot be used here
- * Instead it recognised the # instead of an @ symbols in .type directives
- * We define a couple of macros so that assembly code will not be dependant
- * on one or the other.
- */
-#define _ASM_TYPE_FUNCTION	#function
-#define _ASM_TYPE_OBJECT	#object
-#define _ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x: .fnstart; .cfi_startproc;
+#undef __bionic_asm_custom_entry
+#undef __bionic_asm_custom_end
+#define __bionic_asm_custom_entry(f) .fnstart
+#define __bionic_asm_custom_end(f) .fnend
 
-#define _ASM_SIZE(x)	.size x, .-x;
-
-#define _END(x) \
-	.fnend; .cfi_endproc; \
-	_ASM_SIZE(x)
-
-#ifdef GPROF
-# ifdef __ELF__
-#  define _PROF_PROLOGUE	\
-	mov ip, lr; bl __mcount
-# else
-#  define _PROF_PROLOGUE	\
-	mov ip,lr; bl mcount
-# endif
-#else
-# define _PROF_PROLOGUE
-#endif
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
-#define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
-#define	END(y)		_END(_C_LABEL(y))
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
-#define	ASEND(y)	_END(_ASM_LABEL(y))
-
-#ifdef __ELF__
-#define ENTRY_PRIVATE(y)  ENTRY(y); .hidden _C_LABEL(y)
-#else
-#define ENTRY_PRIVATE(y)  ENTRY(y)
-#endif
-
-#define	ASMSTR		.asciz
+#undef __bionic_asm_function_type
+#define __bionic_asm_function_type #function
 
 #if defined(__ELF__) && defined(PIC)
-#ifdef __STDC__
-#define	PIC_SYM(x,y)	x ## ( ## y ## )
+#define PIC_SYM(x,y) x ## ( ## y ## )
 #else
-#define	PIC_SYM(x,y)	x/**/(/**/y/**/)
+#define PIC_SYM(x,y) x
 #endif
-#else
-#define	PIC_SYM(x,y)	x
-#endif
-
-#ifdef __ELF__
-#define RCSID(x)	.section ".ident"; .asciz x
-#else
-#define RCSID(x)	.text; .asciz x
-#endif
-
-#ifdef __ELF__
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-#endif
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg ## ,30,0,0,0 ;					\
-	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
-#elif defined(__ELF__)
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(sym),1,0,0,0
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(_/**/sym),1,0,0,0
-#endif /* __STDC__ */
 
 #endif /* !_ARM_ASM_H_ */
diff --git a/libc/arch-arm/include/machine/ieee.h b/libc/arch-arm/include/machine/ieee.h
deleted file mode 100644
index 5f9b89e..0000000
--- a/libc/arch-arm/include/machine/ieee.h
+++ /dev/null
@@ -1,191 +0,0 @@
-/*	$OpenBSD: ieee.h,v 1.1 2004/02/01 05:09:49 drahn Exp $	*/
-/*	$NetBSD: ieee.h,v 1.2 2001/02/21 17:43:50 bjh21 Exp $	*/
-
-/*
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Lawrence Berkeley Laboratory.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
- */
-
-/*
- * ieee.h defines the machine-dependent layout of the machine's IEEE
- * floating point.
- */
-
-/*
- * Define the number of bits in each fraction and exponent.
- *
- *		     k	         k+1
- * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
- *
- *					  (-exp_bias+1)
- * as fractions that look like 0.fffff x 2             .  This means that
- *
- *			 -126
- * the number 0.10000 x 2    , for instance, is the same as the normalized
- *
- *		-127			   -128
- * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
- *
- *				  -129
- * in the fraction; to represent 2    , we need two, and so on.  This
- *
- *						     (-exp_bias-fracbits+1)
- * implies that the smallest denormalized number is 2
- *
- * for whichever format we are talking about: for single precision, for
- *
- *						-126		-149
- * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
- *
- * -149 == -127 - 23 + 1.
- */
-
-/*
- * The ARM has two sets of FP data formats.  The FPA supports 32-bit, 64-bit
- * and 96-bit IEEE formats, with the words in big-endian order.  VFP supports
- * 32-bin and 64-bit IEEE formats with the words in the CPU's native byte
- * order.
- *
- * The FPA also has two packed decimal formats, but we ignore them here.
- */
-
-#define	SNG_EXPBITS	8
-#define	SNG_FRACBITS	23
-
-#define	DBL_EXPBITS	11
-#define	DBL_FRACBITS	52
-
-#ifndef __VFP_FP__
-#define	E80_EXPBITS	15
-#define	E80_FRACBITS	64
-
-#define	EXT_EXPBITS	15
-#define	EXT_FRACBITS	112
-#endif
-
-struct ieee_single {
-	u_int	sng_frac:23;
-	u_int	sng_exponent:8;
-	u_int	sng_sign:1;
-};
-
-#ifdef __VFP_FP__
-struct ieee_double {
-#ifdef __ARMEB__
-	u_int	dbl_sign:1;
-	u_int	dbl_exp:11;
-	u_int	dbl_frach:20;
-	u_int	dbl_fracl;
-#else /* !__ARMEB__ */
-	u_int	dbl_fracl;
-	u_int	dbl_frach:20;
-	u_int	dbl_exp:11;
-	u_int	dbl_sign:1;
-#endif /* !__ARMEB__ */
-};
-#else /* !__VFP_FP__ */
-struct ieee_double {
-	u_int	dbl_frach:20;
-	u_int	dbl_exp:11;
-	u_int	dbl_sign:1;
-	u_int	dbl_fracl;
-};
-
-union ieee_double_u {
-	double                  dblu_d;
-	struct ieee_double      dblu_dbl;
-};
-
-
-struct ieee_e80 {
-	u_int	e80_exp:15;
-	u_int	e80_zero:16;
-	u_int	e80_sign:1;
-	u_int	e80_frach:31;
-	u_int	e80_j:1;
-	u_int	e80_fracl;
-};
-
-struct ieee_ext {
-	u_int	ext_frach:16;
-	u_int	ext_exp:15;
-	u_int	ext_sign:1;
-	u_int	ext_frachm;
-	u_int	ext_fraclm;
-	u_int	ext_fracl;
-};
-#endif /* !__VFP_FP__ */
-
-/*
- * Floats whose exponent is in [1..INFNAN) (of whatever type) are
- * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
- * Floats whose exponent is zero are either zero (iff all fraction
- * bits are zero) or subnormal values.
- *
- * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
- * high fraction; if the bit is set, it is a `quiet NaN'.
- */
-#define	SNG_EXP_INFNAN	255
-#define	DBL_EXP_INFNAN	2047
-#ifndef __VFP_FP__
-#define	E80_EXP_INFNAN	32767
-#define	EXT_EXP_INFNAN	32767
-#endif /* !__VFP_FP__ */
-
-#if 0
-#define	SNG_QUIETNAN	(1 << 22)
-#define	DBL_QUIETNAN	(1 << 19)
-#ifndef __VFP_FP__
-#define	E80_QUIETNAN	(1 << 15)
-#define	EXT_QUIETNAN	(1 << 15)
-#endif /* !__VFP_FP__ */
-#endif
-
-/*
- * Exponent biases.
- */
-#define	SNG_EXP_BIAS	127
-#define	DBL_EXP_BIAS	1023
-#ifndef __VFP_FP__
-#define	E80_EXP_BIAS	16383
-#define	EXT_EXP_BIAS	16383
-#endif /* !__VFP_FP__ */
diff --git a/libc/arch-arm/include/machine/limits.h b/libc/arch-arm/include/machine/limits.h
deleted file mode 100644
index f9c04fa..0000000
--- a/libc/arch-arm/include/machine/limits.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.3 2006/01/06 22:48:46 millert Exp $	*/
-/*	$NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 Exp $	*/
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)limits.h	7.2 (Berkeley) 6/28/90
- */
-
-#ifndef	_ARM32_LIMITS_H_
-#define	_ARM32_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	1		/* no multibyte characters */
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	UINT_MAX	/* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define	SSIZE_MAX	INT_MAX		/* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	UINT_MAX	/* max value for a size_t (historic) */
-
-#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
-#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
-#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#define LONGLONG_BIT    64
-#define LONGLONG_MIN    (-9223372036854775807LL-1)
-#define LONGLONG_MAX    9223372036854775807LL
-#define ULONGLONG_MAX   18446744073709551615ULL
-
-#endif	/* _ARM32_LIMITS_H_ */
diff --git a/libc/arch-arm/krait/bionic/__strcat_chk.S b/libc/arch-arm/krait/bionic/__strcat_chk.S
index a5d06f3..34becdb 100644
--- a/libc/arch-arm/krait/bionic/__strcat_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcat_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/krait/bionic/__strcpy_chk.S b/libc/arch-arm/krait/bionic/__strcpy_chk.S
index 95aaf4f..c3e3e14 100644
--- a/libc/arch-arm/krait/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcpy_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/krait/bionic/memcpy.S b/libc/arch-arm/krait/bionic/memcpy.S
index 54405fa..0b7b276 100644
--- a/libc/arch-arm/krait/bionic/memcpy.S
+++ b/libc/arch-arm/krait/bionic/memcpy.S
@@ -28,8 +28,8 @@
 
 /* Assumes neon instructions and a cache line size of 32 bytes. */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
diff --git a/libc/arch-arm/krait/bionic/memset.S b/libc/arch-arm/krait/bionic/memset.S
index 1563327..5d1943b 100644
--- a/libc/arch-arm/krait/bionic/memset.S
+++ b/libc/arch-arm/krait/bionic/memset.S
@@ -27,8 +27,8 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
diff --git a/libc/arch-arm/krait/bionic/strcmp.S b/libc/arch-arm/krait/bionic/strcmp.S
index f735fb5..eacb82a 100644
--- a/libc/arch-arm/krait/bionic/strcmp.S
+++ b/libc/arch-arm/krait/bionic/strcmp.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
 #define S2LOMEM lsl
diff --git a/libc/arch-arm/krait/krait.mk b/libc/arch-arm/krait/krait.mk
index 29ab743..631ab68 100644
--- a/libc/arch-arm/krait/krait.mk
+++ b/libc/arch-arm/krait/krait.mk
@@ -1,11 +1,13 @@
-$(call libc-add-cpu-variant-src,MEMCPY,arch-arm/krait/bionic/memcpy.S)
-$(call libc-add-cpu-variant-src,MEMSET,arch-arm/krait/bionic/memset.S)
-$(call libc-add-cpu-variant-src,STRCMP,arch-arm/krait/bionic/strcmp.S)
-$(call libc-add-cpu-variant-src,__STRCAT_CHK,arch-arm/krait/bionic/__strcat_chk.S)
-$(call libc-add-cpu-variant-src,__STRCPY_CHK,arch-arm/krait/bionic/__strcpy_chk.S)
-# Use cortex-a15 versions of strcat/strcpy/strlen.
-$(call libc-add-cpu-variant-src,STRCAT,arch-arm/cortex-a15/bionic/strcat.S)
-$(call libc-add-cpu-variant-src,STRCPY,arch-arm/cortex-a15/bionic/strcpy.S)
-$(call libc-add-cpu-variant-src,STRLEN,arch-arm/cortex-a15/bionic/strlen.S)
+libc_bionic_src_files_arm += \
+    arch-arm/krait/bionic/memcpy.S \
+    arch-arm/krait/bionic/memset.S \
+    arch-arm/krait/bionic/strcmp.S \
+    arch-arm/krait/bionic/__strcat_chk.S \
+    arch-arm/krait/bionic/__strcpy_chk.S \
 
-include bionic/libc/arch-arm/generic/generic.mk
+# Use cortex-a15 versions of strcat/strcpy/strlen and standard memmove
+libc_bionic_src_files_arm += \
+    arch-arm/cortex-a15/bionic/strcat.S \
+    arch-arm/cortex-a15/bionic/strcpy.S \
+    arch-arm/cortex-a15/bionic/strlen.S \
+    bionic/memmove.c \
diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk
deleted file mode 100644
index 83e6a97..0000000
--- a/libc/arch-arm/syscalls.mk
+++ /dev/null
@@ -1,198 +0,0 @@
-# Generated by gensyscalls.py. Do not edit.
-syscall_src :=
-syscall_src += arch-arm/syscalls/__brk.S
-syscall_src += arch-arm/syscalls/__epoll_pwait.S
-syscall_src += arch-arm/syscalls/__exit.S
-syscall_src += arch-arm/syscalls/__fcntl64.S
-syscall_src += arch-arm/syscalls/__fstatfs64.S
-syscall_src += arch-arm/syscalls/__getcpu.S
-syscall_src += arch-arm/syscalls/__getcwd.S
-syscall_src += arch-arm/syscalls/__getpriority.S
-syscall_src += arch-arm/syscalls/__ioctl.S
-syscall_src += arch-arm/syscalls/__llseek.S
-syscall_src += arch-arm/syscalls/__mmap2.S
-syscall_src += arch-arm/syscalls/__openat.S
-syscall_src += arch-arm/syscalls/__ppoll.S
-syscall_src += arch-arm/syscalls/__pselect6.S
-syscall_src += arch-arm/syscalls/__ptrace.S
-syscall_src += arch-arm/syscalls/__reboot.S
-syscall_src += arch-arm/syscalls/__rt_sigaction.S
-syscall_src += arch-arm/syscalls/__rt_sigpending.S
-syscall_src += arch-arm/syscalls/__rt_sigprocmask.S
-syscall_src += arch-arm/syscalls/__rt_sigsuspend.S
-syscall_src += arch-arm/syscalls/__rt_sigtimedwait.S
-syscall_src += arch-arm/syscalls/__sched_getaffinity.S
-syscall_src += arch-arm/syscalls/__set_tid_address.S
-syscall_src += arch-arm/syscalls/__set_tls.S
-syscall_src += arch-arm/syscalls/__sigaction.S
-syscall_src += arch-arm/syscalls/__statfs64.S
-syscall_src += arch-arm/syscalls/__syslog.S
-syscall_src += arch-arm/syscalls/__timer_create.S
-syscall_src += arch-arm/syscalls/__timer_delete.S
-syscall_src += arch-arm/syscalls/__timer_getoverrun.S
-syscall_src += arch-arm/syscalls/__timer_gettime.S
-syscall_src += arch-arm/syscalls/__timer_settime.S
-syscall_src += arch-arm/syscalls/__waitid.S
-syscall_src += arch-arm/syscalls/_exit.S
-syscall_src += arch-arm/syscalls/accept.S
-syscall_src += arch-arm/syscalls/acct.S
-syscall_src += arch-arm/syscalls/bind.S
-syscall_src += arch-arm/syscalls/cacheflush.S
-syscall_src += arch-arm/syscalls/capget.S
-syscall_src += arch-arm/syscalls/capset.S
-syscall_src += arch-arm/syscalls/chdir.S
-syscall_src += arch-arm/syscalls/chroot.S
-syscall_src += arch-arm/syscalls/clock_getres.S
-syscall_src += arch-arm/syscalls/clock_gettime.S
-syscall_src += arch-arm/syscalls/clock_nanosleep.S
-syscall_src += arch-arm/syscalls/clock_settime.S
-syscall_src += arch-arm/syscalls/close.S
-syscall_src += arch-arm/syscalls/connect.S
-syscall_src += arch-arm/syscalls/delete_module.S
-syscall_src += arch-arm/syscalls/dup.S
-syscall_src += arch-arm/syscalls/dup3.S
-syscall_src += arch-arm/syscalls/epoll_create1.S
-syscall_src += arch-arm/syscalls/epoll_ctl.S
-syscall_src += arch-arm/syscalls/eventfd.S
-syscall_src += arch-arm/syscalls/execve.S
-syscall_src += arch-arm/syscalls/faccessat.S
-syscall_src += arch-arm/syscalls/fchdir.S
-syscall_src += arch-arm/syscalls/fchmod.S
-syscall_src += arch-arm/syscalls/fchmodat.S
-syscall_src += arch-arm/syscalls/fchown.S
-syscall_src += arch-arm/syscalls/fchownat.S
-syscall_src += arch-arm/syscalls/fdatasync.S
-syscall_src += arch-arm/syscalls/fgetxattr.S
-syscall_src += arch-arm/syscalls/flistxattr.S
-syscall_src += arch-arm/syscalls/flock.S
-syscall_src += arch-arm/syscalls/fremovexattr.S
-syscall_src += arch-arm/syscalls/fsetxattr.S
-syscall_src += arch-arm/syscalls/fstat.S
-syscall_src += arch-arm/syscalls/fstatat.S
-syscall_src += arch-arm/syscalls/fsync.S
-syscall_src += arch-arm/syscalls/ftruncate.S
-syscall_src += arch-arm/syscalls/ftruncate64.S
-syscall_src += arch-arm/syscalls/futex.S
-syscall_src += arch-arm/syscalls/getdents.S
-syscall_src += arch-arm/syscalls/getegid.S
-syscall_src += arch-arm/syscalls/geteuid.S
-syscall_src += arch-arm/syscalls/getgid.S
-syscall_src += arch-arm/syscalls/getgroups.S
-syscall_src += arch-arm/syscalls/getitimer.S
-syscall_src += arch-arm/syscalls/getpeername.S
-syscall_src += arch-arm/syscalls/getpgid.S
-syscall_src += arch-arm/syscalls/getpid.S
-syscall_src += arch-arm/syscalls/getppid.S
-syscall_src += arch-arm/syscalls/getresgid.S
-syscall_src += arch-arm/syscalls/getresuid.S
-syscall_src += arch-arm/syscalls/getrlimit.S
-syscall_src += arch-arm/syscalls/getrusage.S
-syscall_src += arch-arm/syscalls/getsid.S
-syscall_src += arch-arm/syscalls/getsockname.S
-syscall_src += arch-arm/syscalls/getsockopt.S
-syscall_src += arch-arm/syscalls/gettid.S
-syscall_src += arch-arm/syscalls/gettimeofday.S
-syscall_src += arch-arm/syscalls/getuid.S
-syscall_src += arch-arm/syscalls/getxattr.S
-syscall_src += arch-arm/syscalls/init_module.S
-syscall_src += arch-arm/syscalls/inotify_add_watch.S
-syscall_src += arch-arm/syscalls/inotify_init1.S
-syscall_src += arch-arm/syscalls/inotify_rm_watch.S
-syscall_src += arch-arm/syscalls/ioprio_get.S
-syscall_src += arch-arm/syscalls/ioprio_set.S
-syscall_src += arch-arm/syscalls/kill.S
-syscall_src += arch-arm/syscalls/klogctl.S
-syscall_src += arch-arm/syscalls/lgetxattr.S
-syscall_src += arch-arm/syscalls/linkat.S
-syscall_src += arch-arm/syscalls/listen.S
-syscall_src += arch-arm/syscalls/listxattr.S
-syscall_src += arch-arm/syscalls/llistxattr.S
-syscall_src += arch-arm/syscalls/lremovexattr.S
-syscall_src += arch-arm/syscalls/lseek.S
-syscall_src += arch-arm/syscalls/lsetxattr.S
-syscall_src += arch-arm/syscalls/madvise.S
-syscall_src += arch-arm/syscalls/mincore.S
-syscall_src += arch-arm/syscalls/mkdirat.S
-syscall_src += arch-arm/syscalls/mknodat.S
-syscall_src += arch-arm/syscalls/mlock.S
-syscall_src += arch-arm/syscalls/mlockall.S
-syscall_src += arch-arm/syscalls/mount.S
-syscall_src += arch-arm/syscalls/mprotect.S
-syscall_src += arch-arm/syscalls/mremap.S
-syscall_src += arch-arm/syscalls/msync.S
-syscall_src += arch-arm/syscalls/munlock.S
-syscall_src += arch-arm/syscalls/munlockall.S
-syscall_src += arch-arm/syscalls/munmap.S
-syscall_src += arch-arm/syscalls/nanosleep.S
-syscall_src += arch-arm/syscalls/perf_event_open.S
-syscall_src += arch-arm/syscalls/personality.S
-syscall_src += arch-arm/syscalls/pipe2.S
-syscall_src += arch-arm/syscalls/prctl.S
-syscall_src += arch-arm/syscalls/pread64.S
-syscall_src += arch-arm/syscalls/prlimit64.S
-syscall_src += arch-arm/syscalls/pwrite64.S
-syscall_src += arch-arm/syscalls/read.S
-syscall_src += arch-arm/syscalls/readahead.S
-syscall_src += arch-arm/syscalls/readlinkat.S
-syscall_src += arch-arm/syscalls/readv.S
-syscall_src += arch-arm/syscalls/recvfrom.S
-syscall_src += arch-arm/syscalls/recvmsg.S
-syscall_src += arch-arm/syscalls/removexattr.S
-syscall_src += arch-arm/syscalls/renameat.S
-syscall_src += arch-arm/syscalls/sched_get_priority_max.S
-syscall_src += arch-arm/syscalls/sched_get_priority_min.S
-syscall_src += arch-arm/syscalls/sched_getparam.S
-syscall_src += arch-arm/syscalls/sched_getscheduler.S
-syscall_src += arch-arm/syscalls/sched_rr_get_interval.S
-syscall_src += arch-arm/syscalls/sched_setaffinity.S
-syscall_src += arch-arm/syscalls/sched_setparam.S
-syscall_src += arch-arm/syscalls/sched_setscheduler.S
-syscall_src += arch-arm/syscalls/sched_yield.S
-syscall_src += arch-arm/syscalls/sendfile.S
-syscall_src += arch-arm/syscalls/sendfile64.S
-syscall_src += arch-arm/syscalls/sendmsg.S
-syscall_src += arch-arm/syscalls/sendto.S
-syscall_src += arch-arm/syscalls/setgid.S
-syscall_src += arch-arm/syscalls/setgroups.S
-syscall_src += arch-arm/syscalls/setitimer.S
-syscall_src += arch-arm/syscalls/setns.S
-syscall_src += arch-arm/syscalls/setpgid.S
-syscall_src += arch-arm/syscalls/setpriority.S
-syscall_src += arch-arm/syscalls/setregid.S
-syscall_src += arch-arm/syscalls/setresgid.S
-syscall_src += arch-arm/syscalls/setresuid.S
-syscall_src += arch-arm/syscalls/setreuid.S
-syscall_src += arch-arm/syscalls/setrlimit.S
-syscall_src += arch-arm/syscalls/setsid.S
-syscall_src += arch-arm/syscalls/setsockopt.S
-syscall_src += arch-arm/syscalls/settimeofday.S
-syscall_src += arch-arm/syscalls/setuid.S
-syscall_src += arch-arm/syscalls/setxattr.S
-syscall_src += arch-arm/syscalls/shutdown.S
-syscall_src += arch-arm/syscalls/sigaltstack.S
-syscall_src += arch-arm/syscalls/signalfd4.S
-syscall_src += arch-arm/syscalls/socket.S
-syscall_src += arch-arm/syscalls/socketpair.S
-syscall_src += arch-arm/syscalls/swapoff.S
-syscall_src += arch-arm/syscalls/swapon.S
-syscall_src += arch-arm/syscalls/symlinkat.S
-syscall_src += arch-arm/syscalls/sync.S
-syscall_src += arch-arm/syscalls/sysinfo.S
-syscall_src += arch-arm/syscalls/tgkill.S
-syscall_src += arch-arm/syscalls/timerfd_create.S
-syscall_src += arch-arm/syscalls/timerfd_gettime.S
-syscall_src += arch-arm/syscalls/timerfd_settime.S
-syscall_src += arch-arm/syscalls/times.S
-syscall_src += arch-arm/syscalls/tkill.S
-syscall_src += arch-arm/syscalls/truncate.S
-syscall_src += arch-arm/syscalls/truncate64.S
-syscall_src += arch-arm/syscalls/umask.S
-syscall_src += arch-arm/syscalls/umount2.S
-syscall_src += arch-arm/syscalls/uname.S
-syscall_src += arch-arm/syscalls/unlinkat.S
-syscall_src += arch-arm/syscalls/unshare.S
-syscall_src += arch-arm/syscalls/utimensat.S
-syscall_src += arch-arm/syscalls/vfork.S
-syscall_src += arch-arm/syscalls/wait4.S
-syscall_src += arch-arm/syscalls/write.S
-syscall_src += arch-arm/syscalls/writev.S
diff --git a/libc/arch-arm/syscalls/__accept4.S b/libc/arch-arm/syscalls/__accept4.S
new file mode 100644
index 0000000..dca5699
--- /dev/null
+++ b/libc/arch-arm/syscalls/__accept4.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__accept4)
+    mov     ip, r7
+    ldr     r7, =__NR_accept4
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(__accept4)
diff --git a/libc/arch-arm/syscalls/__arm_fadvise64_64.S b/libc/arch-arm/syscalls/__arm_fadvise64_64.S
new file mode 100644
index 0000000..761c4d6
--- /dev/null
+++ b/libc/arch-arm/syscalls/__arm_fadvise64_64.S
@@ -0,0 +1,22 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__arm_fadvise64_64)
+    mov     ip, sp
+    stmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 16
+    .cfi_rel_offset r4, 0
+    .cfi_rel_offset r5, 4
+    .cfi_rel_offset r6, 8
+    .cfi_rel_offset r7, 12
+    ldmfd   ip, {r4, r5, r6}
+    ldr     r7, =__NR_arm_fadvise64_64
+    swi     #0
+    ldmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 0
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(__arm_fadvise64_64)
diff --git a/libc/arch-arm/syscalls/__brk.S b/libc/arch-arm/syscalls/__brk.S
index 31de0d2..be304da 100644
--- a/libc/arch-arm/syscalls/__brk.S
+++ b/libc/arch-arm/syscalls/__brk.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__brk)
diff --git a/libc/arch-arm/syscalls/__connect.S b/libc/arch-arm/syscalls/__connect.S
new file mode 100644
index 0000000..a2a997e
--- /dev/null
+++ b/libc/arch-arm/syscalls/__connect.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__connect)
+    mov     ip, r7
+    ldr     r7, =__NR_connect
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(__connect)
diff --git a/libc/arch-arm/syscalls/__epoll_pwait.S b/libc/arch-arm/syscalls/__epoll_pwait.S
index a90254a..3642ee3 100644
--- a/libc/arch-arm/syscalls/__epoll_pwait.S
+++ b/libc/arch-arm/syscalls/__epoll_pwait.S
@@ -4,7 +4,6 @@
 
 ENTRY(__epoll_pwait)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__epoll_pwait)
diff --git a/libc/arch-arm/syscalls/__exit.S b/libc/arch-arm/syscalls/__exit.S
index c534bb0..6ebd5b3 100644
--- a/libc/arch-arm/syscalls/__exit.S
+++ b/libc/arch-arm/syscalls/__exit.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__exit)
diff --git a/libc/arch-arm/syscalls/__fcntl64.S b/libc/arch-arm/syscalls/__fcntl64.S
index 2132cb7..229c5c6 100644
--- a/libc/arch-arm/syscalls/__fcntl64.S
+++ b/libc/arch-arm/syscalls/__fcntl64.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__fcntl64)
diff --git a/libc/arch-arm/syscalls/__fstatfs64.S b/libc/arch-arm/syscalls/__fstatfs64.S
index 18942bc..9c0c439 100644
--- a/libc/arch-arm/syscalls/__fstatfs64.S
+++ b/libc/arch-arm/syscalls/__fstatfs64.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__fstatfs64)
diff --git a/libc/arch-arm/syscalls/__getcpu.S b/libc/arch-arm/syscalls/__getcpu.S
index 1aea50a..d523d8e 100644
--- a/libc/arch-arm/syscalls/__getcpu.S
+++ b/libc/arch-arm/syscalls/__getcpu.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__getcpu)
diff --git a/libc/arch-arm/syscalls/__getcwd.S b/libc/arch-arm/syscalls/__getcwd.S
index 1c2ac6c..4ff6667 100644
--- a/libc/arch-arm/syscalls/__getcwd.S
+++ b/libc/arch-arm/syscalls/__getcwd.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__getcwd)
diff --git a/libc/arch-arm/syscalls/__getdents64.S b/libc/arch-arm/syscalls/__getdents64.S
new file mode 100644
index 0000000..dac3bfc
--- /dev/null
+++ b/libc/arch-arm/syscalls/__getdents64.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getdents64)
+    mov     ip, r7
+    ldr     r7, =__NR_getdents64
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(__getdents64)
diff --git a/libc/arch-arm/syscalls/__getpid.S b/libc/arch-arm/syscalls/__getpid.S
new file mode 100644
index 0000000..dbb192e
--- /dev/null
+++ b/libc/arch-arm/syscalls/__getpid.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getpid)
+    mov     ip, r7
+    ldr     r7, =__NR_getpid
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(__getpid)
diff --git a/libc/arch-arm/syscalls/__getpriority.S b/libc/arch-arm/syscalls/__getpriority.S
index 90ccaea..e637d6f 100644
--- a/libc/arch-arm/syscalls/__getpriority.S
+++ b/libc/arch-arm/syscalls/__getpriority.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__getpriority)
diff --git a/libc/arch-arm/syscalls/__ioctl.S b/libc/arch-arm/syscalls/__ioctl.S
index 3f816db..fcd1157 100644
--- a/libc/arch-arm/syscalls/__ioctl.S
+++ b/libc/arch-arm/syscalls/__ioctl.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__ioctl)
diff --git a/libc/arch-arm/syscalls/__llseek.S b/libc/arch-arm/syscalls/__llseek.S
index 1a3e4c7..3cff318 100644
--- a/libc/arch-arm/syscalls/__llseek.S
+++ b/libc/arch-arm/syscalls/__llseek.S
@@ -4,7 +4,6 @@
 
 ENTRY(__llseek)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__llseek)
diff --git a/libc/arch-arm/syscalls/__mmap2.S b/libc/arch-arm/syscalls/__mmap2.S
index 7d989e9..f11e467 100644
--- a/libc/arch-arm/syscalls/__mmap2.S
+++ b/libc/arch-arm/syscalls/__mmap2.S
@@ -4,7 +4,6 @@
 
 ENTRY(__mmap2)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__mmap2)
diff --git a/libc/arch-arm/syscalls/__openat.S b/libc/arch-arm/syscalls/__openat.S
index 7a38dc3..9b774db 100644
--- a/libc/arch-arm/syscalls/__openat.S
+++ b/libc/arch-arm/syscalls/__openat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__openat)
diff --git a/libc/arch-arm/syscalls/__ppoll.S b/libc/arch-arm/syscalls/__ppoll.S
index 7cdbe51..02de8a8 100644
--- a/libc/arch-arm/syscalls/__ppoll.S
+++ b/libc/arch-arm/syscalls/__ppoll.S
@@ -4,7 +4,6 @@
 
 ENTRY(__ppoll)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__ppoll)
diff --git a/libc/arch-arm/syscalls/__pselect6.S b/libc/arch-arm/syscalls/__pselect6.S
index 4c5b513..8f31e1b 100644
--- a/libc/arch-arm/syscalls/__pselect6.S
+++ b/libc/arch-arm/syscalls/__pselect6.S
@@ -4,7 +4,6 @@
 
 ENTRY(__pselect6)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__pselect6)
diff --git a/libc/arch-arm/syscalls/__ptrace.S b/libc/arch-arm/syscalls/__ptrace.S
index 4e41d9d..975ab0f 100644
--- a/libc/arch-arm/syscalls/__ptrace.S
+++ b/libc/arch-arm/syscalls/__ptrace.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__ptrace)
diff --git a/libc/arch-arm/syscalls/__reboot.S b/libc/arch-arm/syscalls/__reboot.S
index 18e29a7..03f8c89 100644
--- a/libc/arch-arm/syscalls/__reboot.S
+++ b/libc/arch-arm/syscalls/__reboot.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__reboot)
diff --git a/libc/arch-arm/syscalls/__rt_sigaction.S b/libc/arch-arm/syscalls/__rt_sigaction.S
index 974c0e2..2c21012 100644
--- a/libc/arch-arm/syscalls/__rt_sigaction.S
+++ b/libc/arch-arm/syscalls/__rt_sigaction.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__rt_sigaction)
diff --git a/libc/arch-arm/syscalls/__rt_sigpending.S b/libc/arch-arm/syscalls/__rt_sigpending.S
index 4a0f5d7..6a32e50 100644
--- a/libc/arch-arm/syscalls/__rt_sigpending.S
+++ b/libc/arch-arm/syscalls/__rt_sigpending.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__rt_sigpending)
diff --git a/libc/arch-arm/syscalls/__rt_sigprocmask.S b/libc/arch-arm/syscalls/__rt_sigprocmask.S
index 19abdc1..136dc79 100644
--- a/libc/arch-arm/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-arm/syscalls/__rt_sigprocmask.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__rt_sigprocmask)
diff --git a/libc/arch-arm/syscalls/__rt_sigsuspend.S b/libc/arch-arm/syscalls/__rt_sigsuspend.S
index a0af905..2cef4a4 100644
--- a/libc/arch-arm/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-arm/syscalls/__rt_sigsuspend.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__rt_sigsuspend)
diff --git a/libc/arch-arm/syscalls/__rt_sigtimedwait.S b/libc/arch-arm/syscalls/__rt_sigtimedwait.S
index 0ba7ce2..cb43ad1 100644
--- a/libc/arch-arm/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-arm/syscalls/__rt_sigtimedwait.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__rt_sigtimedwait)
diff --git a/libc/arch-arm/syscalls/__sched_getaffinity.S b/libc/arch-arm/syscalls/__sched_getaffinity.S
index e977cfb..6613ea5 100644
--- a/libc/arch-arm/syscalls/__sched_getaffinity.S
+++ b/libc/arch-arm/syscalls/__sched_getaffinity.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__sched_getaffinity)
diff --git a/libc/arch-arm/syscalls/__set_tid_address.S b/libc/arch-arm/syscalls/__set_tid_address.S
index b4b42e7..d3558f5 100644
--- a/libc/arch-arm/syscalls/__set_tid_address.S
+++ b/libc/arch-arm/syscalls/__set_tid_address.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__set_tid_address)
diff --git a/libc/arch-arm/syscalls/__set_tls.S b/libc/arch-arm/syscalls/__set_tls.S
index 94c7cf4..4d5d963 100644
--- a/libc/arch-arm/syscalls/__set_tls.S
+++ b/libc/arch-arm/syscalls/__set_tls.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__set_tls)
diff --git a/libc/arch-arm/syscalls/__sigaction.S b/libc/arch-arm/syscalls/__sigaction.S
index 7e2e07e..600593d 100644
--- a/libc/arch-arm/syscalls/__sigaction.S
+++ b/libc/arch-arm/syscalls/__sigaction.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__sigaction)
diff --git a/libc/arch-arm/syscalls/__signalfd4.S b/libc/arch-arm/syscalls/__signalfd4.S
new file mode 100644
index 0000000..630a71f
--- /dev/null
+++ b/libc/arch-arm/syscalls/__signalfd4.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__signalfd4)
+    mov     ip, r7
+    ldr     r7, =__NR_signalfd4
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(__signalfd4)
diff --git a/libc/arch-arm/syscalls/__socket.S b/libc/arch-arm/syscalls/__socket.S
new file mode 100644
index 0000000..fffe0cc
--- /dev/null
+++ b/libc/arch-arm/syscalls/__socket.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__socket)
+    mov     ip, r7
+    ldr     r7, =__NR_socket
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(__socket)
diff --git a/libc/arch-arm/syscalls/__statfs64.S b/libc/arch-arm/syscalls/__statfs64.S
index 2563562..ec43218 100644
--- a/libc/arch-arm/syscalls/__statfs64.S
+++ b/libc/arch-arm/syscalls/__statfs64.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__statfs64)
diff --git a/libc/arch-arm/syscalls/__syslog.S b/libc/arch-arm/syscalls/__syslog.S
deleted file mode 100644
index 66e761a..0000000
--- a/libc/arch-arm/syscalls/__syslog.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(__syslog)
-    mov     ip, r7
-    ldr     r7, =__NR_syslog
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(__syslog)
diff --git a/libc/arch-arm/syscalls/__timer_create.S b/libc/arch-arm/syscalls/__timer_create.S
index 9b75749..2e4c634 100644
--- a/libc/arch-arm/syscalls/__timer_create.S
+++ b/libc/arch-arm/syscalls/__timer_create.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__timer_create)
diff --git a/libc/arch-arm/syscalls/__timer_delete.S b/libc/arch-arm/syscalls/__timer_delete.S
index db32b3b..237024c 100644
--- a/libc/arch-arm/syscalls/__timer_delete.S
+++ b/libc/arch-arm/syscalls/__timer_delete.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__timer_delete)
diff --git a/libc/arch-arm/syscalls/__timer_getoverrun.S b/libc/arch-arm/syscalls/__timer_getoverrun.S
index 5701b12..f29d5b3 100644
--- a/libc/arch-arm/syscalls/__timer_getoverrun.S
+++ b/libc/arch-arm/syscalls/__timer_getoverrun.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__timer_getoverrun)
diff --git a/libc/arch-arm/syscalls/__timer_gettime.S b/libc/arch-arm/syscalls/__timer_gettime.S
index e9a4ff9..e6dc2ed 100644
--- a/libc/arch-arm/syscalls/__timer_gettime.S
+++ b/libc/arch-arm/syscalls/__timer_gettime.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__timer_gettime)
diff --git a/libc/arch-arm/syscalls/__timer_settime.S b/libc/arch-arm/syscalls/__timer_settime.S
index 2f1ab19..4aea279 100644
--- a/libc/arch-arm/syscalls/__timer_settime.S
+++ b/libc/arch-arm/syscalls/__timer_settime.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__timer_settime)
diff --git a/libc/arch-arm/syscalls/__waitid.S b/libc/arch-arm/syscalls/__waitid.S
index ad9ad16..f4dfa59 100644
--- a/libc/arch-arm/syscalls/__waitid.S
+++ b/libc/arch-arm/syscalls/__waitid.S
@@ -4,7 +4,6 @@
 
 ENTRY(__waitid)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(__waitid)
diff --git a/libc/arch-arm/syscalls/_exit.S b/libc/arch-arm/syscalls/_exit.S
index 1a6b35d..328a5ce 100644
--- a/libc/arch-arm/syscalls/_exit.S
+++ b/libc/arch-arm/syscalls/_exit.S
@@ -10,5 +10,8 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(_exit)
+
+    .globl _Exit
+    .equ _Exit, _exit
diff --git a/libc/arch-arm/syscalls/accept.S b/libc/arch-arm/syscalls/accept.S
deleted file mode 100644
index e2a51f5..0000000
--- a/libc/arch-arm/syscalls/accept.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(accept)
-    mov     ip, r7
-    ldr     r7, =__NR_accept
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(accept)
diff --git a/libc/arch-arm/syscalls/acct.S b/libc/arch-arm/syscalls/acct.S
index e360c5a..dbc5d58 100644
--- a/libc/arch-arm/syscalls/acct.S
+++ b/libc/arch-arm/syscalls/acct.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(acct)
diff --git a/libc/arch-arm/syscalls/bind.S b/libc/arch-arm/syscalls/bind.S
index e07dd77..c901417 100644
--- a/libc/arch-arm/syscalls/bind.S
+++ b/libc/arch-arm/syscalls/bind.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(bind)
diff --git a/libc/arch-arm/syscalls/cacheflush.S b/libc/arch-arm/syscalls/cacheflush.S
index ac2a218..76f4623 100644
--- a/libc/arch-arm/syscalls/cacheflush.S
+++ b/libc/arch-arm/syscalls/cacheflush.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(cacheflush)
diff --git a/libc/arch-arm/syscalls/capget.S b/libc/arch-arm/syscalls/capget.S
index b912830..59a5a3c 100644
--- a/libc/arch-arm/syscalls/capget.S
+++ b/libc/arch-arm/syscalls/capget.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(capget)
diff --git a/libc/arch-arm/syscalls/capset.S b/libc/arch-arm/syscalls/capset.S
index cef68c5..af284ab 100644
--- a/libc/arch-arm/syscalls/capset.S
+++ b/libc/arch-arm/syscalls/capset.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(capset)
diff --git a/libc/arch-arm/syscalls/chdir.S b/libc/arch-arm/syscalls/chdir.S
index ea93fd6..25f27ba 100644
--- a/libc/arch-arm/syscalls/chdir.S
+++ b/libc/arch-arm/syscalls/chdir.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(chdir)
diff --git a/libc/arch-arm/syscalls/chroot.S b/libc/arch-arm/syscalls/chroot.S
index b1199e6..6f829a6 100644
--- a/libc/arch-arm/syscalls/chroot.S
+++ b/libc/arch-arm/syscalls/chroot.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(chroot)
diff --git a/libc/arch-arm/syscalls/clock_getres.S b/libc/arch-arm/syscalls/clock_getres.S
index f1e7fa2..48fa07c 100644
--- a/libc/arch-arm/syscalls/clock_getres.S
+++ b/libc/arch-arm/syscalls/clock_getres.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(clock_getres)
diff --git a/libc/arch-arm/syscalls/clock_gettime.S b/libc/arch-arm/syscalls/clock_gettime.S
index 9b3e132..317481d 100644
--- a/libc/arch-arm/syscalls/clock_gettime.S
+++ b/libc/arch-arm/syscalls/clock_gettime.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(clock_gettime)
diff --git a/libc/arch-arm/syscalls/clock_nanosleep.S b/libc/arch-arm/syscalls/clock_nanosleep.S
index fda7394..80295bb 100644
--- a/libc/arch-arm/syscalls/clock_nanosleep.S
+++ b/libc/arch-arm/syscalls/clock_nanosleep.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(clock_nanosleep)
diff --git a/libc/arch-arm/syscalls/clock_settime.S b/libc/arch-arm/syscalls/clock_settime.S
index 5a0059e..bf54702 100644
--- a/libc/arch-arm/syscalls/clock_settime.S
+++ b/libc/arch-arm/syscalls/clock_settime.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(clock_settime)
diff --git a/libc/arch-arm/syscalls/close.S b/libc/arch-arm/syscalls/close.S
index 00c8f85..ec05445 100644
--- a/libc/arch-arm/syscalls/close.S
+++ b/libc/arch-arm/syscalls/close.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(close)
diff --git a/libc/arch-arm/syscalls/connect.S b/libc/arch-arm/syscalls/connect.S
deleted file mode 100644
index f7a5188..0000000
--- a/libc/arch-arm/syscalls/connect.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(connect)
-    mov     ip, r7
-    ldr     r7, =__NR_connect
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(connect)
diff --git a/libc/arch-arm/syscalls/delete_module.S b/libc/arch-arm/syscalls/delete_module.S
index a26b478..57580c9 100644
--- a/libc/arch-arm/syscalls/delete_module.S
+++ b/libc/arch-arm/syscalls/delete_module.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(delete_module)
diff --git a/libc/arch-arm/syscalls/dup.S b/libc/arch-arm/syscalls/dup.S
index b1859d9..2cd69d7 100644
--- a/libc/arch-arm/syscalls/dup.S
+++ b/libc/arch-arm/syscalls/dup.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(dup)
diff --git a/libc/arch-arm/syscalls/dup3.S b/libc/arch-arm/syscalls/dup3.S
index 3e47c10..4613d63 100644
--- a/libc/arch-arm/syscalls/dup3.S
+++ b/libc/arch-arm/syscalls/dup3.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(dup3)
diff --git a/libc/arch-arm/syscalls/epoll_create1.S b/libc/arch-arm/syscalls/epoll_create1.S
index 2eebc0c..108c24f 100644
--- a/libc/arch-arm/syscalls/epoll_create1.S
+++ b/libc/arch-arm/syscalls/epoll_create1.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(epoll_create1)
diff --git a/libc/arch-arm/syscalls/epoll_ctl.S b/libc/arch-arm/syscalls/epoll_ctl.S
index 7a1cc41..473af6a 100644
--- a/libc/arch-arm/syscalls/epoll_ctl.S
+++ b/libc/arch-arm/syscalls/epoll_ctl.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(epoll_ctl)
diff --git a/libc/arch-arm/syscalls/eventfd.S b/libc/arch-arm/syscalls/eventfd.S
index 08272d3..ca6bcee 100644
--- a/libc/arch-arm/syscalls/eventfd.S
+++ b/libc/arch-arm/syscalls/eventfd.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(eventfd)
diff --git a/libc/arch-arm/syscalls/execve.S b/libc/arch-arm/syscalls/execve.S
index 361ec63..3eca810 100644
--- a/libc/arch-arm/syscalls/execve.S
+++ b/libc/arch-arm/syscalls/execve.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(execve)
diff --git a/libc/arch-arm/syscalls/faccessat.S b/libc/arch-arm/syscalls/faccessat.S
index c82b2ce..a1df5c0 100644
--- a/libc/arch-arm/syscalls/faccessat.S
+++ b/libc/arch-arm/syscalls/faccessat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(faccessat)
diff --git a/libc/arch-arm/syscalls/fallocate64.S b/libc/arch-arm/syscalls/fallocate64.S
new file mode 100644
index 0000000..4bfd5e3
--- /dev/null
+++ b/libc/arch-arm/syscalls/fallocate64.S
@@ -0,0 +1,22 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fallocate64)
+    mov     ip, sp
+    stmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 16
+    .cfi_rel_offset r4, 0
+    .cfi_rel_offset r5, 4
+    .cfi_rel_offset r6, 8
+    .cfi_rel_offset r7, 12
+    ldmfd   ip, {r4, r5, r6}
+    ldr     r7, =__NR_fallocate
+    swi     #0
+    ldmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 0
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(fallocate64)
diff --git a/libc/arch-arm/syscalls/fchdir.S b/libc/arch-arm/syscalls/fchdir.S
index 1a7eb51..705ad32 100644
--- a/libc/arch-arm/syscalls/fchdir.S
+++ b/libc/arch-arm/syscalls/fchdir.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fchdir)
diff --git a/libc/arch-arm/syscalls/fchmod.S b/libc/arch-arm/syscalls/fchmod.S
index 42dc5b8..5675f0a 100644
--- a/libc/arch-arm/syscalls/fchmod.S
+++ b/libc/arch-arm/syscalls/fchmod.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fchmod)
diff --git a/libc/arch-arm/syscalls/fchmodat.S b/libc/arch-arm/syscalls/fchmodat.S
index e03da8c..3f7e0ee 100644
--- a/libc/arch-arm/syscalls/fchmodat.S
+++ b/libc/arch-arm/syscalls/fchmodat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fchmodat)
diff --git a/libc/arch-arm/syscalls/fchown.S b/libc/arch-arm/syscalls/fchown.S
index c2c3982..45ad9bf 100644
--- a/libc/arch-arm/syscalls/fchown.S
+++ b/libc/arch-arm/syscalls/fchown.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fchown)
diff --git a/libc/arch-arm/syscalls/fchownat.S b/libc/arch-arm/syscalls/fchownat.S
index 4397a22..2aac0fe 100644
--- a/libc/arch-arm/syscalls/fchownat.S
+++ b/libc/arch-arm/syscalls/fchownat.S
@@ -4,7 +4,6 @@
 
 ENTRY(fchownat)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fchownat)
diff --git a/libc/arch-arm/syscalls/fdatasync.S b/libc/arch-arm/syscalls/fdatasync.S
index 9c8317d..7fefd22 100644
--- a/libc/arch-arm/syscalls/fdatasync.S
+++ b/libc/arch-arm/syscalls/fdatasync.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fdatasync)
diff --git a/libc/arch-arm/syscalls/fgetxattr.S b/libc/arch-arm/syscalls/fgetxattr.S
index bef536b..3f1e5fc 100644
--- a/libc/arch-arm/syscalls/fgetxattr.S
+++ b/libc/arch-arm/syscalls/fgetxattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fgetxattr)
diff --git a/libc/arch-arm/syscalls/flistxattr.S b/libc/arch-arm/syscalls/flistxattr.S
index d9a30bb..ee09295 100644
--- a/libc/arch-arm/syscalls/flistxattr.S
+++ b/libc/arch-arm/syscalls/flistxattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(flistxattr)
diff --git a/libc/arch-arm/syscalls/flock.S b/libc/arch-arm/syscalls/flock.S
index 016e824..c946fe9 100644
--- a/libc/arch-arm/syscalls/flock.S
+++ b/libc/arch-arm/syscalls/flock.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(flock)
diff --git a/libc/arch-arm/syscalls/fremovexattr.S b/libc/arch-arm/syscalls/fremovexattr.S
index c7ff034..f4e950b 100644
--- a/libc/arch-arm/syscalls/fremovexattr.S
+++ b/libc/arch-arm/syscalls/fremovexattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fremovexattr)
diff --git a/libc/arch-arm/syscalls/fsetxattr.S b/libc/arch-arm/syscalls/fsetxattr.S
index 39b97f9..0e33ad2 100644
--- a/libc/arch-arm/syscalls/fsetxattr.S
+++ b/libc/arch-arm/syscalls/fsetxattr.S
@@ -4,7 +4,6 @@
 
 ENTRY(fsetxattr)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fsetxattr)
diff --git a/libc/arch-arm/syscalls/fstat.S b/libc/arch-arm/syscalls/fstat.S
deleted file mode 100644
index cf08d08..0000000
--- a/libc/arch-arm/syscalls/fstat.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstat)
-    mov     ip, r7
-    ldr     r7, =__NR_fstat64
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(fstat)
diff --git a/libc/arch-arm/syscalls/fstat64.S b/libc/arch-arm/syscalls/fstat64.S
new file mode 100644
index 0000000..c60e7ee
--- /dev/null
+++ b/libc/arch-arm/syscalls/fstat64.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstat64)
+    mov     ip, r7
+    ldr     r7, =__NR_fstat64
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(fstat64)
+
+    .globl fstat
+    .equ fstat, fstat64
diff --git a/libc/arch-arm/syscalls/fstatat.S b/libc/arch-arm/syscalls/fstatat.S
deleted file mode 100644
index 7cc9bb0..0000000
--- a/libc/arch-arm/syscalls/fstatat.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstatat)
-    mov     ip, r7
-    ldr     r7, =__NR_fstatat64
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(fstatat)
diff --git a/libc/arch-arm/syscalls/fstatat64.S b/libc/arch-arm/syscalls/fstatat64.S
new file mode 100644
index 0000000..ce56c36
--- /dev/null
+++ b/libc/arch-arm/syscalls/fstatat64.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatat64)
+    mov     ip, r7
+    ldr     r7, =__NR_fstatat64
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(fstatat64)
+
+    .globl fstatat
+    .equ fstatat, fstatat64
diff --git a/libc/arch-arm/syscalls/fsync.S b/libc/arch-arm/syscalls/fsync.S
index 6b7c4a8..1dfff05 100644
--- a/libc/arch-arm/syscalls/fsync.S
+++ b/libc/arch-arm/syscalls/fsync.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(fsync)
diff --git a/libc/arch-arm/syscalls/ftruncate.S b/libc/arch-arm/syscalls/ftruncate.S
index 4a3d56c..1bfe2f3 100644
--- a/libc/arch-arm/syscalls/ftruncate.S
+++ b/libc/arch-arm/syscalls/ftruncate.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(ftruncate)
diff --git a/libc/arch-arm/syscalls/ftruncate64.S b/libc/arch-arm/syscalls/ftruncate64.S
index 910ca68..ac0caa8 100644
--- a/libc/arch-arm/syscalls/ftruncate64.S
+++ b/libc/arch-arm/syscalls/ftruncate64.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(ftruncate64)
diff --git a/libc/arch-arm/syscalls/futex.S b/libc/arch-arm/syscalls/futex.S
deleted file mode 100644
index 45e6fa6..0000000
--- a/libc/arch-arm/syscalls/futex.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(futex)
-    mov     ip, sp
-    .save   {r4, r5, r6, r7}
-    stmfd   sp!, {r4, r5, r6, r7}
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset r4, 0
-    .cfi_rel_offset r5, 4
-    .cfi_rel_offset r6, 8
-    .cfi_rel_offset r7, 12
-    ldmfd   ip, {r4, r5, r6}
-    ldr     r7, =__NR_futex
-    swi     #0
-    ldmfd   sp!, {r4, r5, r6, r7}
-    .cfi_def_cfa_offset 0
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(futex)
diff --git a/libc/arch-arm/syscalls/getdents.S b/libc/arch-arm/syscalls/getdents.S
deleted file mode 100644
index 8f0e81a..0000000
--- a/libc/arch-arm/syscalls/getdents.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getdents)
-    mov     ip, r7
-    ldr     r7, =__NR_getdents64
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(getdents)
diff --git a/libc/arch-arm/syscalls/getegid.S b/libc/arch-arm/syscalls/getegid.S
index 6afca90..afa9cc8 100644
--- a/libc/arch-arm/syscalls/getegid.S
+++ b/libc/arch-arm/syscalls/getegid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getegid)
diff --git a/libc/arch-arm/syscalls/geteuid.S b/libc/arch-arm/syscalls/geteuid.S
index 78e5cf4..10c8a25 100644
--- a/libc/arch-arm/syscalls/geteuid.S
+++ b/libc/arch-arm/syscalls/geteuid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(geteuid)
diff --git a/libc/arch-arm/syscalls/getgid.S b/libc/arch-arm/syscalls/getgid.S
index c2d3538..8772762 100644
--- a/libc/arch-arm/syscalls/getgid.S
+++ b/libc/arch-arm/syscalls/getgid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getgid)
diff --git a/libc/arch-arm/syscalls/getgroups.S b/libc/arch-arm/syscalls/getgroups.S
index e6b8e10..366299b 100644
--- a/libc/arch-arm/syscalls/getgroups.S
+++ b/libc/arch-arm/syscalls/getgroups.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getgroups)
diff --git a/libc/arch-arm/syscalls/getitimer.S b/libc/arch-arm/syscalls/getitimer.S
index 3dce707..80fb0f2 100644
--- a/libc/arch-arm/syscalls/getitimer.S
+++ b/libc/arch-arm/syscalls/getitimer.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getitimer)
diff --git a/libc/arch-arm/syscalls/getpeername.S b/libc/arch-arm/syscalls/getpeername.S
index 0613231..25f0026 100644
--- a/libc/arch-arm/syscalls/getpeername.S
+++ b/libc/arch-arm/syscalls/getpeername.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getpeername)
diff --git a/libc/arch-arm/syscalls/getpgid.S b/libc/arch-arm/syscalls/getpgid.S
index 1992afc..36c4c19 100644
--- a/libc/arch-arm/syscalls/getpgid.S
+++ b/libc/arch-arm/syscalls/getpgid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getpgid)
diff --git a/libc/arch-arm/syscalls/getpid.S b/libc/arch-arm/syscalls/getpid.S
deleted file mode 100644
index 10bcb8e..0000000
--- a/libc/arch-arm/syscalls/getpid.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getpid)
-    mov     ip, r7
-    ldr     r7, =__NR_getpid
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(getpid)
diff --git a/libc/arch-arm/syscalls/getppid.S b/libc/arch-arm/syscalls/getppid.S
index 594fca5..606b2e0 100644
--- a/libc/arch-arm/syscalls/getppid.S
+++ b/libc/arch-arm/syscalls/getppid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getppid)
diff --git a/libc/arch-arm/syscalls/getresgid.S b/libc/arch-arm/syscalls/getresgid.S
index 9dcdb33..a5e4689 100644
--- a/libc/arch-arm/syscalls/getresgid.S
+++ b/libc/arch-arm/syscalls/getresgid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getresgid)
diff --git a/libc/arch-arm/syscalls/getresuid.S b/libc/arch-arm/syscalls/getresuid.S
index 387bd7c..74c26a7 100644
--- a/libc/arch-arm/syscalls/getresuid.S
+++ b/libc/arch-arm/syscalls/getresuid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getresuid)
diff --git a/libc/arch-arm/syscalls/getrlimit.S b/libc/arch-arm/syscalls/getrlimit.S
index 879b666..166da63 100644
--- a/libc/arch-arm/syscalls/getrlimit.S
+++ b/libc/arch-arm/syscalls/getrlimit.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getrlimit)
diff --git a/libc/arch-arm/syscalls/getrusage.S b/libc/arch-arm/syscalls/getrusage.S
index ee84f49..93979c6 100644
--- a/libc/arch-arm/syscalls/getrusage.S
+++ b/libc/arch-arm/syscalls/getrusage.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getrusage)
diff --git a/libc/arch-arm/syscalls/getsid.S b/libc/arch-arm/syscalls/getsid.S
index 715f217..87d38fb 100644
--- a/libc/arch-arm/syscalls/getsid.S
+++ b/libc/arch-arm/syscalls/getsid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getsid)
diff --git a/libc/arch-arm/syscalls/getsockname.S b/libc/arch-arm/syscalls/getsockname.S
index 2ee68f3..5dc4eab 100644
--- a/libc/arch-arm/syscalls/getsockname.S
+++ b/libc/arch-arm/syscalls/getsockname.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getsockname)
diff --git a/libc/arch-arm/syscalls/getsockopt.S b/libc/arch-arm/syscalls/getsockopt.S
index 735efbb..4143bbd 100644
--- a/libc/arch-arm/syscalls/getsockopt.S
+++ b/libc/arch-arm/syscalls/getsockopt.S
@@ -4,7 +4,6 @@
 
 ENTRY(getsockopt)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getsockopt)
diff --git a/libc/arch-arm/syscalls/gettid.S b/libc/arch-arm/syscalls/gettid.S
deleted file mode 100644
index 3928be1..0000000
--- a/libc/arch-arm/syscalls/gettid.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(gettid)
-    mov     ip, r7
-    ldr     r7, =__NR_gettid
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(gettid)
diff --git a/libc/arch-arm/syscalls/gettimeofday.S b/libc/arch-arm/syscalls/gettimeofday.S
index 4d33b5d..174f94b 100644
--- a/libc/arch-arm/syscalls/gettimeofday.S
+++ b/libc/arch-arm/syscalls/gettimeofday.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(gettimeofday)
diff --git a/libc/arch-arm/syscalls/getuid.S b/libc/arch-arm/syscalls/getuid.S
index 66f570f..3d07d3c 100644
--- a/libc/arch-arm/syscalls/getuid.S
+++ b/libc/arch-arm/syscalls/getuid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getuid)
diff --git a/libc/arch-arm/syscalls/getxattr.S b/libc/arch-arm/syscalls/getxattr.S
index 71d0035..6661aaf 100644
--- a/libc/arch-arm/syscalls/getxattr.S
+++ b/libc/arch-arm/syscalls/getxattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(getxattr)
diff --git a/libc/arch-arm/syscalls/init_module.S b/libc/arch-arm/syscalls/init_module.S
index 6850ddf..8251533 100644
--- a/libc/arch-arm/syscalls/init_module.S
+++ b/libc/arch-arm/syscalls/init_module.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(init_module)
diff --git a/libc/arch-arm/syscalls/inotify_add_watch.S b/libc/arch-arm/syscalls/inotify_add_watch.S
index 367a49f..b945bd1 100644
--- a/libc/arch-arm/syscalls/inotify_add_watch.S
+++ b/libc/arch-arm/syscalls/inotify_add_watch.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(inotify_add_watch)
diff --git a/libc/arch-arm/syscalls/inotify_init1.S b/libc/arch-arm/syscalls/inotify_init1.S
index 13e175f..32090de 100644
--- a/libc/arch-arm/syscalls/inotify_init1.S
+++ b/libc/arch-arm/syscalls/inotify_init1.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(inotify_init1)
diff --git a/libc/arch-arm/syscalls/inotify_rm_watch.S b/libc/arch-arm/syscalls/inotify_rm_watch.S
index b80e0f8..e8230e2 100644
--- a/libc/arch-arm/syscalls/inotify_rm_watch.S
+++ b/libc/arch-arm/syscalls/inotify_rm_watch.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(inotify_rm_watch)
diff --git a/libc/arch-arm/syscalls/ioprio_get.S b/libc/arch-arm/syscalls/ioprio_get.S
deleted file mode 100644
index 19e04ed..0000000
--- a/libc/arch-arm/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    mov     ip, r7
-    ldr     r7, =__NR_ioprio_get
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(ioprio_get)
diff --git a/libc/arch-arm/syscalls/ioprio_set.S b/libc/arch-arm/syscalls/ioprio_set.S
deleted file mode 100644
index 9b94efb..0000000
--- a/libc/arch-arm/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    mov     ip, r7
-    ldr     r7, =__NR_ioprio_set
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(ioprio_set)
diff --git a/libc/arch-arm/syscalls/kill.S b/libc/arch-arm/syscalls/kill.S
index 9a44208..0b5f4a4 100644
--- a/libc/arch-arm/syscalls/kill.S
+++ b/libc/arch-arm/syscalls/kill.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(kill)
diff --git a/libc/arch-arm/syscalls/klogctl.S b/libc/arch-arm/syscalls/klogctl.S
index 84ce7f6..b76b2b5 100644
--- a/libc/arch-arm/syscalls/klogctl.S
+++ b/libc/arch-arm/syscalls/klogctl.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(klogctl)
diff --git a/libc/arch-arm/syscalls/lgetxattr.S b/libc/arch-arm/syscalls/lgetxattr.S
index 9eed67f..b033a9a 100644
--- a/libc/arch-arm/syscalls/lgetxattr.S
+++ b/libc/arch-arm/syscalls/lgetxattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(lgetxattr)
diff --git a/libc/arch-arm/syscalls/linkat.S b/libc/arch-arm/syscalls/linkat.S
index c612d02..6e74d06 100644
--- a/libc/arch-arm/syscalls/linkat.S
+++ b/libc/arch-arm/syscalls/linkat.S
@@ -4,7 +4,6 @@
 
 ENTRY(linkat)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(linkat)
diff --git a/libc/arch-arm/syscalls/listen.S b/libc/arch-arm/syscalls/listen.S
index 330ea56..3aaa801 100644
--- a/libc/arch-arm/syscalls/listen.S
+++ b/libc/arch-arm/syscalls/listen.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(listen)
diff --git a/libc/arch-arm/syscalls/listxattr.S b/libc/arch-arm/syscalls/listxattr.S
index c64e484..51ff267 100644
--- a/libc/arch-arm/syscalls/listxattr.S
+++ b/libc/arch-arm/syscalls/listxattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(listxattr)
diff --git a/libc/arch-arm/syscalls/llistxattr.S b/libc/arch-arm/syscalls/llistxattr.S
index cea926b..46e8116 100644
--- a/libc/arch-arm/syscalls/llistxattr.S
+++ b/libc/arch-arm/syscalls/llistxattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(llistxattr)
diff --git a/libc/arch-arm/syscalls/lremovexattr.S b/libc/arch-arm/syscalls/lremovexattr.S
index c7a6458..a945062 100644
--- a/libc/arch-arm/syscalls/lremovexattr.S
+++ b/libc/arch-arm/syscalls/lremovexattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(lremovexattr)
diff --git a/libc/arch-arm/syscalls/lseek.S b/libc/arch-arm/syscalls/lseek.S
index 9edae37..00aeab3 100644
--- a/libc/arch-arm/syscalls/lseek.S
+++ b/libc/arch-arm/syscalls/lseek.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(lseek)
diff --git a/libc/arch-arm/syscalls/lsetxattr.S b/libc/arch-arm/syscalls/lsetxattr.S
index 67639f6..c41fb88 100644
--- a/libc/arch-arm/syscalls/lsetxattr.S
+++ b/libc/arch-arm/syscalls/lsetxattr.S
@@ -4,7 +4,6 @@
 
 ENTRY(lsetxattr)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(lsetxattr)
diff --git a/libc/arch-arm/syscalls/madvise.S b/libc/arch-arm/syscalls/madvise.S
index ee2c2a5..4d3cdcd 100644
--- a/libc/arch-arm/syscalls/madvise.S
+++ b/libc/arch-arm/syscalls/madvise.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(madvise)
diff --git a/libc/arch-arm/syscalls/mincore.S b/libc/arch-arm/syscalls/mincore.S
index 9ef9237..f1154d0 100644
--- a/libc/arch-arm/syscalls/mincore.S
+++ b/libc/arch-arm/syscalls/mincore.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(mincore)
diff --git a/libc/arch-arm/syscalls/mkdirat.S b/libc/arch-arm/syscalls/mkdirat.S
index 9e77ef0..1f8957b 100644
--- a/libc/arch-arm/syscalls/mkdirat.S
+++ b/libc/arch-arm/syscalls/mkdirat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(mkdirat)
diff --git a/libc/arch-arm/syscalls/mknodat.S b/libc/arch-arm/syscalls/mknodat.S
index de492da..1a2bf6f 100644
--- a/libc/arch-arm/syscalls/mknodat.S
+++ b/libc/arch-arm/syscalls/mknodat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(mknodat)
diff --git a/libc/arch-arm/syscalls/mlock.S b/libc/arch-arm/syscalls/mlock.S
index 043b21b..8a4fc7a 100644
--- a/libc/arch-arm/syscalls/mlock.S
+++ b/libc/arch-arm/syscalls/mlock.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(mlock)
diff --git a/libc/arch-arm/syscalls/mlockall.S b/libc/arch-arm/syscalls/mlockall.S
index 9c6c4e4..b49ca05 100644
--- a/libc/arch-arm/syscalls/mlockall.S
+++ b/libc/arch-arm/syscalls/mlockall.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(mlockall)
diff --git a/libc/arch-arm/syscalls/mount.S b/libc/arch-arm/syscalls/mount.S
index b184114..ed28ab2 100644
--- a/libc/arch-arm/syscalls/mount.S
+++ b/libc/arch-arm/syscalls/mount.S
@@ -4,7 +4,6 @@
 
 ENTRY(mount)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(mount)
diff --git a/libc/arch-arm/syscalls/mprotect.S b/libc/arch-arm/syscalls/mprotect.S
index 9461d9b..cb51306 100644
--- a/libc/arch-arm/syscalls/mprotect.S
+++ b/libc/arch-arm/syscalls/mprotect.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(mprotect)
diff --git a/libc/arch-arm/syscalls/mremap.S b/libc/arch-arm/syscalls/mremap.S
index 2486fc9..505ea3c 100644
--- a/libc/arch-arm/syscalls/mremap.S
+++ b/libc/arch-arm/syscalls/mremap.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(mremap)
diff --git a/libc/arch-arm/syscalls/msync.S b/libc/arch-arm/syscalls/msync.S
index 3fc4118..220fb4d 100644
--- a/libc/arch-arm/syscalls/msync.S
+++ b/libc/arch-arm/syscalls/msync.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(msync)
diff --git a/libc/arch-arm/syscalls/munlock.S b/libc/arch-arm/syscalls/munlock.S
index c89fd3c..05bf941 100644
--- a/libc/arch-arm/syscalls/munlock.S
+++ b/libc/arch-arm/syscalls/munlock.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(munlock)
diff --git a/libc/arch-arm/syscalls/munlockall.S b/libc/arch-arm/syscalls/munlockall.S
index 3ac9f32..e2c5dd5 100644
--- a/libc/arch-arm/syscalls/munlockall.S
+++ b/libc/arch-arm/syscalls/munlockall.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(munlockall)
diff --git a/libc/arch-arm/syscalls/munmap.S b/libc/arch-arm/syscalls/munmap.S
index ed3bb1e..740c360 100644
--- a/libc/arch-arm/syscalls/munmap.S
+++ b/libc/arch-arm/syscalls/munmap.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(munmap)
diff --git a/libc/arch-arm/syscalls/nanosleep.S b/libc/arch-arm/syscalls/nanosleep.S
index 695c126..fcd6e90 100644
--- a/libc/arch-arm/syscalls/nanosleep.S
+++ b/libc/arch-arm/syscalls/nanosleep.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(nanosleep)
diff --git a/libc/arch-arm/syscalls/perf_event_open.S b/libc/arch-arm/syscalls/perf_event_open.S
deleted file mode 100644
index e0cf91e..0000000
--- a/libc/arch-arm/syscalls/perf_event_open.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(perf_event_open)
-    mov     ip, sp
-    .save   {r4, r5, r6, r7}
-    stmfd   sp!, {r4, r5, r6, r7}
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset r4, 0
-    .cfi_rel_offset r5, 4
-    .cfi_rel_offset r6, 8
-    .cfi_rel_offset r7, 12
-    ldmfd   ip, {r4, r5, r6}
-    ldr     r7, =__NR_perf_event_open
-    swi     #0
-    ldmfd   sp!, {r4, r5, r6, r7}
-    .cfi_def_cfa_offset 0
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(perf_event_open)
diff --git a/libc/arch-arm/syscalls/personality.S b/libc/arch-arm/syscalls/personality.S
index e3f7371..d43d763 100644
--- a/libc/arch-arm/syscalls/personality.S
+++ b/libc/arch-arm/syscalls/personality.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(personality)
diff --git a/libc/arch-arm/syscalls/pipe2.S b/libc/arch-arm/syscalls/pipe2.S
index 420dee9..1cbdfb2 100644
--- a/libc/arch-arm/syscalls/pipe2.S
+++ b/libc/arch-arm/syscalls/pipe2.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(pipe2)
diff --git a/libc/arch-arm/syscalls/prctl.S b/libc/arch-arm/syscalls/prctl.S
index 40acb61..a2d869c 100644
--- a/libc/arch-arm/syscalls/prctl.S
+++ b/libc/arch-arm/syscalls/prctl.S
@@ -4,7 +4,6 @@
 
 ENTRY(prctl)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(prctl)
diff --git a/libc/arch-arm/syscalls/pread64.S b/libc/arch-arm/syscalls/pread64.S
index a33018c..dc07bb3 100644
--- a/libc/arch-arm/syscalls/pread64.S
+++ b/libc/arch-arm/syscalls/pread64.S
@@ -4,7 +4,6 @@
 
 ENTRY(pread64)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(pread64)
diff --git a/libc/arch-arm/syscalls/prlimit64.S b/libc/arch-arm/syscalls/prlimit64.S
index 8d9c4ff..3ae9e1b 100644
--- a/libc/arch-arm/syscalls/prlimit64.S
+++ b/libc/arch-arm/syscalls/prlimit64.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(prlimit64)
diff --git a/libc/arch-arm/syscalls/pwrite64.S b/libc/arch-arm/syscalls/pwrite64.S
index 5ae9921..5749f6b 100644
--- a/libc/arch-arm/syscalls/pwrite64.S
+++ b/libc/arch-arm/syscalls/pwrite64.S
@@ -4,7 +4,6 @@
 
 ENTRY(pwrite64)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(pwrite64)
diff --git a/libc/arch-arm/syscalls/read.S b/libc/arch-arm/syscalls/read.S
index b01daf5..1c3b395 100644
--- a/libc/arch-arm/syscalls/read.S
+++ b/libc/arch-arm/syscalls/read.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(read)
diff --git a/libc/arch-arm/syscalls/readahead.S b/libc/arch-arm/syscalls/readahead.S
index 326ed6f..6952b4e 100644
--- a/libc/arch-arm/syscalls/readahead.S
+++ b/libc/arch-arm/syscalls/readahead.S
@@ -4,7 +4,6 @@
 
 ENTRY(readahead)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(readahead)
diff --git a/libc/arch-arm/syscalls/readlinkat.S b/libc/arch-arm/syscalls/readlinkat.S
index 28926ab..e7cc8ff 100644
--- a/libc/arch-arm/syscalls/readlinkat.S
+++ b/libc/arch-arm/syscalls/readlinkat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(readlinkat)
diff --git a/libc/arch-arm/syscalls/readv.S b/libc/arch-arm/syscalls/readv.S
index 433d33d..c7807bd 100644
--- a/libc/arch-arm/syscalls/readv.S
+++ b/libc/arch-arm/syscalls/readv.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(readv)
diff --git a/libc/arch-arm/syscalls/recvfrom.S b/libc/arch-arm/syscalls/recvfrom.S
index 367790b..115a09c 100644
--- a/libc/arch-arm/syscalls/recvfrom.S
+++ b/libc/arch-arm/syscalls/recvfrom.S
@@ -4,7 +4,6 @@
 
 ENTRY(recvfrom)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(recvfrom)
diff --git a/libc/arch-arm/syscalls/recvmmsg.S b/libc/arch-arm/syscalls/recvmmsg.S
new file mode 100644
index 0000000..6cf2b92
--- /dev/null
+++ b/libc/arch-arm/syscalls/recvmmsg.S
@@ -0,0 +1,22 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(recvmmsg)
+    mov     ip, sp
+    stmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 16
+    .cfi_rel_offset r4, 0
+    .cfi_rel_offset r5, 4
+    .cfi_rel_offset r6, 8
+    .cfi_rel_offset r7, 12
+    ldmfd   ip, {r4, r5, r6}
+    ldr     r7, =__NR_recvmmsg
+    swi     #0
+    ldmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 0
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(recvmmsg)
diff --git a/libc/arch-arm/syscalls/recvmsg.S b/libc/arch-arm/syscalls/recvmsg.S
index 47e82a7..995a9e3 100644
--- a/libc/arch-arm/syscalls/recvmsg.S
+++ b/libc/arch-arm/syscalls/recvmsg.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(recvmsg)
diff --git a/libc/arch-arm/syscalls/removexattr.S b/libc/arch-arm/syscalls/removexattr.S
index a3fcdfa..3a32e5c 100644
--- a/libc/arch-arm/syscalls/removexattr.S
+++ b/libc/arch-arm/syscalls/removexattr.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(removexattr)
diff --git a/libc/arch-arm/syscalls/renameat.S b/libc/arch-arm/syscalls/renameat.S
index cea6286..98e86dc 100644
--- a/libc/arch-arm/syscalls/renameat.S
+++ b/libc/arch-arm/syscalls/renameat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(renameat)
diff --git a/libc/arch-arm/syscalls/sched_get_priority_max.S b/libc/arch-arm/syscalls/sched_get_priority_max.S
index c940adc..187e680 100644
--- a/libc/arch-arm/syscalls/sched_get_priority_max.S
+++ b/libc/arch-arm/syscalls/sched_get_priority_max.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_get_priority_max)
diff --git a/libc/arch-arm/syscalls/sched_get_priority_min.S b/libc/arch-arm/syscalls/sched_get_priority_min.S
index 39faede..68bf7df 100644
--- a/libc/arch-arm/syscalls/sched_get_priority_min.S
+++ b/libc/arch-arm/syscalls/sched_get_priority_min.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_get_priority_min)
diff --git a/libc/arch-arm/syscalls/sched_getparam.S b/libc/arch-arm/syscalls/sched_getparam.S
index 59df104..32b97b8 100644
--- a/libc/arch-arm/syscalls/sched_getparam.S
+++ b/libc/arch-arm/syscalls/sched_getparam.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_getparam)
diff --git a/libc/arch-arm/syscalls/sched_getscheduler.S b/libc/arch-arm/syscalls/sched_getscheduler.S
index 953368d..330c208 100644
--- a/libc/arch-arm/syscalls/sched_getscheduler.S
+++ b/libc/arch-arm/syscalls/sched_getscheduler.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_getscheduler)
diff --git a/libc/arch-arm/syscalls/sched_rr_get_interval.S b/libc/arch-arm/syscalls/sched_rr_get_interval.S
index 1fa7d15..5d176ac 100644
--- a/libc/arch-arm/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-arm/syscalls/sched_rr_get_interval.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_rr_get_interval)
diff --git a/libc/arch-arm/syscalls/sched_setaffinity.S b/libc/arch-arm/syscalls/sched_setaffinity.S
index 63bfe4d..6653471 100644
--- a/libc/arch-arm/syscalls/sched_setaffinity.S
+++ b/libc/arch-arm/syscalls/sched_setaffinity.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_setaffinity)
diff --git a/libc/arch-arm/syscalls/sched_setparam.S b/libc/arch-arm/syscalls/sched_setparam.S
index 324f0bb..16e1997 100644
--- a/libc/arch-arm/syscalls/sched_setparam.S
+++ b/libc/arch-arm/syscalls/sched_setparam.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_setparam)
diff --git a/libc/arch-arm/syscalls/sched_setscheduler.S b/libc/arch-arm/syscalls/sched_setscheduler.S
index 0ce6b15..2ec9fec 100644
--- a/libc/arch-arm/syscalls/sched_setscheduler.S
+++ b/libc/arch-arm/syscalls/sched_setscheduler.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_setscheduler)
diff --git a/libc/arch-arm/syscalls/sched_yield.S b/libc/arch-arm/syscalls/sched_yield.S
index 8e6d65a..1ec328f 100644
--- a/libc/arch-arm/syscalls/sched_yield.S
+++ b/libc/arch-arm/syscalls/sched_yield.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sched_yield)
diff --git a/libc/arch-arm/syscalls/sendfile.S b/libc/arch-arm/syscalls/sendfile.S
index 28b25a3..afae021 100644
--- a/libc/arch-arm/syscalls/sendfile.S
+++ b/libc/arch-arm/syscalls/sendfile.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sendfile)
diff --git a/libc/arch-arm/syscalls/sendfile64.S b/libc/arch-arm/syscalls/sendfile64.S
index 4a9f245..d0ad0b8 100644
--- a/libc/arch-arm/syscalls/sendfile64.S
+++ b/libc/arch-arm/syscalls/sendfile64.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sendfile64)
diff --git a/libc/arch-arm/syscalls/sendmmsg.S b/libc/arch-arm/syscalls/sendmmsg.S
new file mode 100644
index 0000000..8bb5f80
--- /dev/null
+++ b/libc/arch-arm/syscalls/sendmmsg.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendmmsg)
+    mov     ip, r7
+    ldr     r7, =__NR_sendmmsg
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(sendmmsg)
diff --git a/libc/arch-arm/syscalls/sendmsg.S b/libc/arch-arm/syscalls/sendmsg.S
index 554f307..fd38140 100644
--- a/libc/arch-arm/syscalls/sendmsg.S
+++ b/libc/arch-arm/syscalls/sendmsg.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sendmsg)
diff --git a/libc/arch-arm/syscalls/sendto.S b/libc/arch-arm/syscalls/sendto.S
index 533d95e..29b7b0b 100644
--- a/libc/arch-arm/syscalls/sendto.S
+++ b/libc/arch-arm/syscalls/sendto.S
@@ -4,7 +4,6 @@
 
 ENTRY(sendto)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sendto)
diff --git a/libc/arch-arm/syscalls/setfsgid.S b/libc/arch-arm/syscalls/setfsgid.S
new file mode 100644
index 0000000..f677a94
--- /dev/null
+++ b/libc/arch-arm/syscalls/setfsgid.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsgid)
+    mov     ip, r7
+    ldr     r7, =__NR_setfsgid
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(setfsgid)
diff --git a/libc/arch-arm/syscalls/setfsuid.S b/libc/arch-arm/syscalls/setfsuid.S
new file mode 100644
index 0000000..5d27a4d
--- /dev/null
+++ b/libc/arch-arm/syscalls/setfsuid.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsuid)
+    mov     ip, r7
+    ldr     r7, =__NR_setfsuid
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(setfsuid)
diff --git a/libc/arch-arm/syscalls/setgid.S b/libc/arch-arm/syscalls/setgid.S
index fb38148..d9b2b88 100644
--- a/libc/arch-arm/syscalls/setgid.S
+++ b/libc/arch-arm/syscalls/setgid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setgid)
diff --git a/libc/arch-arm/syscalls/setgroups.S b/libc/arch-arm/syscalls/setgroups.S
index 5420a53..169de73 100644
--- a/libc/arch-arm/syscalls/setgroups.S
+++ b/libc/arch-arm/syscalls/setgroups.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setgroups)
diff --git a/libc/arch-arm/syscalls/setitimer.S b/libc/arch-arm/syscalls/setitimer.S
index 2345e5b..31b277b 100644
--- a/libc/arch-arm/syscalls/setitimer.S
+++ b/libc/arch-arm/syscalls/setitimer.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setitimer)
diff --git a/libc/arch-arm/syscalls/setns.S b/libc/arch-arm/syscalls/setns.S
index 7afbff0..59203ef 100644
--- a/libc/arch-arm/syscalls/setns.S
+++ b/libc/arch-arm/syscalls/setns.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setns)
diff --git a/libc/arch-arm/syscalls/setpgid.S b/libc/arch-arm/syscalls/setpgid.S
index 1470a9d..4a91520 100644
--- a/libc/arch-arm/syscalls/setpgid.S
+++ b/libc/arch-arm/syscalls/setpgid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setpgid)
diff --git a/libc/arch-arm/syscalls/setpriority.S b/libc/arch-arm/syscalls/setpriority.S
index b7f47be..2053ce1 100644
--- a/libc/arch-arm/syscalls/setpriority.S
+++ b/libc/arch-arm/syscalls/setpriority.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setpriority)
diff --git a/libc/arch-arm/syscalls/setregid.S b/libc/arch-arm/syscalls/setregid.S
index a4323d4..f1bdc60 100644
--- a/libc/arch-arm/syscalls/setregid.S
+++ b/libc/arch-arm/syscalls/setregid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setregid)
diff --git a/libc/arch-arm/syscalls/setresgid.S b/libc/arch-arm/syscalls/setresgid.S
index a578440..9b8968a 100644
--- a/libc/arch-arm/syscalls/setresgid.S
+++ b/libc/arch-arm/syscalls/setresgid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setresgid)
diff --git a/libc/arch-arm/syscalls/setresuid.S b/libc/arch-arm/syscalls/setresuid.S
index 9798bc5..c26a955 100644
--- a/libc/arch-arm/syscalls/setresuid.S
+++ b/libc/arch-arm/syscalls/setresuid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setresuid)
diff --git a/libc/arch-arm/syscalls/setreuid.S b/libc/arch-arm/syscalls/setreuid.S
index fa83dc6..796191a 100644
--- a/libc/arch-arm/syscalls/setreuid.S
+++ b/libc/arch-arm/syscalls/setreuid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setreuid)
diff --git a/libc/arch-arm/syscalls/setrlimit.S b/libc/arch-arm/syscalls/setrlimit.S
index 0711aca..c87b21b 100644
--- a/libc/arch-arm/syscalls/setrlimit.S
+++ b/libc/arch-arm/syscalls/setrlimit.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setrlimit)
diff --git a/libc/arch-arm/syscalls/setsid.S b/libc/arch-arm/syscalls/setsid.S
index df6196b..83bda1b 100644
--- a/libc/arch-arm/syscalls/setsid.S
+++ b/libc/arch-arm/syscalls/setsid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setsid)
diff --git a/libc/arch-arm/syscalls/setsockopt.S b/libc/arch-arm/syscalls/setsockopt.S
index c4f7a01..8ea3893 100644
--- a/libc/arch-arm/syscalls/setsockopt.S
+++ b/libc/arch-arm/syscalls/setsockopt.S
@@ -4,7 +4,6 @@
 
 ENTRY(setsockopt)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setsockopt)
diff --git a/libc/arch-arm/syscalls/settimeofday.S b/libc/arch-arm/syscalls/settimeofday.S
index af39761..5763f40 100644
--- a/libc/arch-arm/syscalls/settimeofday.S
+++ b/libc/arch-arm/syscalls/settimeofday.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(settimeofday)
diff --git a/libc/arch-arm/syscalls/setuid.S b/libc/arch-arm/syscalls/setuid.S
index 1999c2b..55b349c 100644
--- a/libc/arch-arm/syscalls/setuid.S
+++ b/libc/arch-arm/syscalls/setuid.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setuid)
diff --git a/libc/arch-arm/syscalls/setxattr.S b/libc/arch-arm/syscalls/setxattr.S
index 6987215..8ba4b77 100644
--- a/libc/arch-arm/syscalls/setxattr.S
+++ b/libc/arch-arm/syscalls/setxattr.S
@@ -4,7 +4,6 @@
 
 ENTRY(setxattr)
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -19,5 +18,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(setxattr)
diff --git a/libc/arch-arm/syscalls/shutdown.S b/libc/arch-arm/syscalls/shutdown.S
index 744f384..889934a 100644
--- a/libc/arch-arm/syscalls/shutdown.S
+++ b/libc/arch-arm/syscalls/shutdown.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(shutdown)
diff --git a/libc/arch-arm/syscalls/sigaltstack.S b/libc/arch-arm/syscalls/sigaltstack.S
index d8777b4..b61b25d 100644
--- a/libc/arch-arm/syscalls/sigaltstack.S
+++ b/libc/arch-arm/syscalls/sigaltstack.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sigaltstack)
diff --git a/libc/arch-arm/syscalls/signalfd4.S b/libc/arch-arm/syscalls/signalfd4.S
deleted file mode 100644
index f8d8a28..0000000
--- a/libc/arch-arm/syscalls/signalfd4.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(signalfd4)
-    mov     ip, r7
-    ldr     r7, =__NR_signalfd4
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(signalfd4)
diff --git a/libc/arch-arm/syscalls/socket.S b/libc/arch-arm/syscalls/socket.S
deleted file mode 100644
index 05fa529..0000000
--- a/libc/arch-arm/syscalls/socket.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(socket)
-    mov     ip, r7
-    ldr     r7, =__NR_socket
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(socket)
diff --git a/libc/arch-arm/syscalls/socketpair.S b/libc/arch-arm/syscalls/socketpair.S
index f896313..f3c8a4b 100644
--- a/libc/arch-arm/syscalls/socketpair.S
+++ b/libc/arch-arm/syscalls/socketpair.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(socketpair)
diff --git a/libc/arch-arm/syscalls/splice.S b/libc/arch-arm/syscalls/splice.S
new file mode 100644
index 0000000..6bc3f0d
--- /dev/null
+++ b/libc/arch-arm/syscalls/splice.S
@@ -0,0 +1,22 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    mov     ip, sp
+    stmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 16
+    .cfi_rel_offset r4, 0
+    .cfi_rel_offset r5, 4
+    .cfi_rel_offset r6, 8
+    .cfi_rel_offset r7, 12
+    ldmfd   ip, {r4, r5, r6}
+    ldr     r7, =__NR_splice
+    swi     #0
+    ldmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 0
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(splice)
diff --git a/libc/arch-arm/syscalls/swapoff.S b/libc/arch-arm/syscalls/swapoff.S
index f78bc7f..a7aaa82 100644
--- a/libc/arch-arm/syscalls/swapoff.S
+++ b/libc/arch-arm/syscalls/swapoff.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(swapoff)
diff --git a/libc/arch-arm/syscalls/swapon.S b/libc/arch-arm/syscalls/swapon.S
index d28216a..6ea93c3 100644
--- a/libc/arch-arm/syscalls/swapon.S
+++ b/libc/arch-arm/syscalls/swapon.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(swapon)
diff --git a/libc/arch-arm/syscalls/symlinkat.S b/libc/arch-arm/syscalls/symlinkat.S
index d81e43b..d330a54 100644
--- a/libc/arch-arm/syscalls/symlinkat.S
+++ b/libc/arch-arm/syscalls/symlinkat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(symlinkat)
diff --git a/libc/arch-arm/syscalls/sync.S b/libc/arch-arm/syscalls/sync.S
index 279a192..48ecfc0 100644
--- a/libc/arch-arm/syscalls/sync.S
+++ b/libc/arch-arm/syscalls/sync.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sync)
diff --git a/libc/arch-arm/syscalls/sysinfo.S b/libc/arch-arm/syscalls/sysinfo.S
index 6bee583..709478e 100644
--- a/libc/arch-arm/syscalls/sysinfo.S
+++ b/libc/arch-arm/syscalls/sysinfo.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(sysinfo)
diff --git a/libc/arch-arm/syscalls/tee.S b/libc/arch-arm/syscalls/tee.S
new file mode 100644
index 0000000..a019c00
--- /dev/null
+++ b/libc/arch-arm/syscalls/tee.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(tee)
+    mov     ip, r7
+    ldr     r7, =__NR_tee
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(tee)
diff --git a/libc/arch-arm/syscalls/tgkill.S b/libc/arch-arm/syscalls/tgkill.S
index 4ea04f5..2068465 100644
--- a/libc/arch-arm/syscalls/tgkill.S
+++ b/libc/arch-arm/syscalls/tgkill.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(tgkill)
diff --git a/libc/arch-arm/syscalls/timerfd_create.S b/libc/arch-arm/syscalls/timerfd_create.S
index f5842e9..89a80cd 100644
--- a/libc/arch-arm/syscalls/timerfd_create.S
+++ b/libc/arch-arm/syscalls/timerfd_create.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(timerfd_create)
diff --git a/libc/arch-arm/syscalls/timerfd_gettime.S b/libc/arch-arm/syscalls/timerfd_gettime.S
index 6f254e5..4a7df76 100644
--- a/libc/arch-arm/syscalls/timerfd_gettime.S
+++ b/libc/arch-arm/syscalls/timerfd_gettime.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(timerfd_gettime)
diff --git a/libc/arch-arm/syscalls/timerfd_settime.S b/libc/arch-arm/syscalls/timerfd_settime.S
index 75d175c..2e0fe93 100644
--- a/libc/arch-arm/syscalls/timerfd_settime.S
+++ b/libc/arch-arm/syscalls/timerfd_settime.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(timerfd_settime)
diff --git a/libc/arch-arm/syscalls/times.S b/libc/arch-arm/syscalls/times.S
index 4792ad1..289c185 100644
--- a/libc/arch-arm/syscalls/times.S
+++ b/libc/arch-arm/syscalls/times.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(times)
diff --git a/libc/arch-arm/syscalls/tkill.S b/libc/arch-arm/syscalls/tkill.S
deleted file mode 100644
index 2626ae7..0000000
--- a/libc/arch-arm/syscalls/tkill.S
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(tkill)
-    mov     ip, r7
-    ldr     r7, =__NR_tkill
-    swi     #0
-    mov     r7, ip
-    cmn     r0, #(MAX_ERRNO + 1)
-    bxls    lr
-    neg     r0, r0
-    b       __set_errno
-END(tkill)
diff --git a/libc/arch-arm/syscalls/truncate.S b/libc/arch-arm/syscalls/truncate.S
index ff8fd19..bb33beb 100644
--- a/libc/arch-arm/syscalls/truncate.S
+++ b/libc/arch-arm/syscalls/truncate.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(truncate)
diff --git a/libc/arch-arm/syscalls/truncate64.S b/libc/arch-arm/syscalls/truncate64.S
index 8fd0855..9cafbb5 100644
--- a/libc/arch-arm/syscalls/truncate64.S
+++ b/libc/arch-arm/syscalls/truncate64.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(truncate64)
diff --git a/libc/arch-arm/syscalls/umask.S b/libc/arch-arm/syscalls/umask.S
index 830af21..5dc4461 100644
--- a/libc/arch-arm/syscalls/umask.S
+++ b/libc/arch-arm/syscalls/umask.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(umask)
diff --git a/libc/arch-arm/syscalls/umount2.S b/libc/arch-arm/syscalls/umount2.S
index 4c0ce4d..435eda4 100644
--- a/libc/arch-arm/syscalls/umount2.S
+++ b/libc/arch-arm/syscalls/umount2.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(umount2)
diff --git a/libc/arch-arm/syscalls/uname.S b/libc/arch-arm/syscalls/uname.S
index 20a6d7d..8af6123 100644
--- a/libc/arch-arm/syscalls/uname.S
+++ b/libc/arch-arm/syscalls/uname.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(uname)
diff --git a/libc/arch-arm/syscalls/unlinkat.S b/libc/arch-arm/syscalls/unlinkat.S
index 1c27416..96257e6 100644
--- a/libc/arch-arm/syscalls/unlinkat.S
+++ b/libc/arch-arm/syscalls/unlinkat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(unlinkat)
diff --git a/libc/arch-arm/syscalls/unshare.S b/libc/arch-arm/syscalls/unshare.S
index 5ec1049..8054171 100644
--- a/libc/arch-arm/syscalls/unshare.S
+++ b/libc/arch-arm/syscalls/unshare.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(unshare)
diff --git a/libc/arch-arm/syscalls/utimensat.S b/libc/arch-arm/syscalls/utimensat.S
index f0f834f..f3c2fa2 100644
--- a/libc/arch-arm/syscalls/utimensat.S
+++ b/libc/arch-arm/syscalls/utimensat.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(utimensat)
diff --git a/libc/arch-arm/syscalls/vfork.S b/libc/arch-arm/syscalls/vfork.S
index e12fba5..5f4cb3d 100644
--- a/libc/arch-arm/syscalls/vfork.S
+++ b/libc/arch-arm/syscalls/vfork.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(vfork)
diff --git a/libc/arch-arm/syscalls/vmsplice.S b/libc/arch-arm/syscalls/vmsplice.S
new file mode 100644
index 0000000..cc12ca5
--- /dev/null
+++ b/libc/arch-arm/syscalls/vmsplice.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(vmsplice)
+    mov     ip, r7
+    ldr     r7, =__NR_vmsplice
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(vmsplice)
diff --git a/libc/arch-arm/syscalls/wait4.S b/libc/arch-arm/syscalls/wait4.S
index a197c2e..26a4929 100644
--- a/libc/arch-arm/syscalls/wait4.S
+++ b/libc/arch-arm/syscalls/wait4.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(wait4)
diff --git a/libc/arch-arm/syscalls/write.S b/libc/arch-arm/syscalls/write.S
index ed7cfa2..bf89d7f 100644
--- a/libc/arch-arm/syscalls/write.S
+++ b/libc/arch-arm/syscalls/write.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(write)
diff --git a/libc/arch-arm/syscalls/writev.S b/libc/arch-arm/syscalls/writev.S
index 8cc506f..15b5275 100644
--- a/libc/arch-arm/syscalls/writev.S
+++ b/libc/arch-arm/syscalls/writev.S
@@ -10,5 +10,5 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(writev)
diff --git a/libc/arch-arm64/arm64.mk b/libc/arch-arm64/arm64.mk
index 86bf91a..6c4f6a6 100644
--- a/libc/arch-arm64/arm64.mk
+++ b/libc/arch-arm64/arm64.mk
@@ -1,10 +1,34 @@
-_LIBC_ARCH_COMMON_SRC_FILES := \
+# arm64 specific configs
+
+libc_common_src_files_arm64 := \
+    bionic/memrchr.c \
+    bionic/strrchr.cpp \
+    upstream-freebsd/lib/libc/string/wcscat.c \
+    upstream-freebsd/lib/libc/string/wcschr.c \
+    upstream-freebsd/lib/libc/string/wcscmp.c \
+    upstream-freebsd/lib/libc/string/wcscpy.c \
+    upstream-freebsd/lib/libc/string/wcslen.c \
+    upstream-freebsd/lib/libc/string/wcsrchr.c \
+    upstream-freebsd/lib/libc/string/wmemcmp.c \
+    upstream-openbsd/lib/libc/string/stpncpy.c \
+    upstream-openbsd/lib/libc/string/strcat.c \
+    upstream-openbsd/lib/libc/string/strlcat.c \
+    upstream-openbsd/lib/libc/string/strlcpy.c \
+    upstream-openbsd/lib/libc/string/strncat.c \
+    upstream-openbsd/lib/libc/string/strncpy.c \
+
+# Fortify implementations of libc functions.
+libc_common_src_files_arm64 += \
+    bionic/__memcpy_chk.cpp \
+    bionic/__memset_chk.cpp \
+    bionic/__strcpy_chk.cpp \
+    bionic/__strcat_chk.cpp \
+
+##########################################
+### CPU specific source files
+libc_bionic_src_files_arm64 := \
     arch-arm64/bionic/__bionic_clone.S \
-    arch-arm64/bionic/bzero_arm64.c \
-    arch-arm64/bionic/cacheflush_arm64.c \
     arch-arm64/bionic/_exit_with_stack_teardown.S \
-    arch-arm64/bionic/futex_arm64.S \
-    arch-arm64/bionic/__get_sp.S \
     arch-arm64/bionic/__rt_sigreturn.S \
     arch-arm64/bionic/_setjmp.S \
     arch-arm64/bionic/setjmp.S \
@@ -13,7 +37,25 @@
     arch-arm64/bionic/syscall.S \
     arch-arm64/bionic/vfork.S \
 
-_LIBC_ARCH_STATIC_SRC_FILES := \
-    bionic/dl_iterate_phdr_static.c \
 
-_LIBC_ARCH_DYNAMIC_SRC_FILES :=
+libc_crt_target_cflags_arm64 := \
+    -I$(LOCAL_PATH)/arch-arm64/include
+
+libc_crt_target_crtbegin_file_arm64 := \
+    $(LOCAL_PATH)/arch-arm64/bionic/crtbegin.c
+
+libc_crt_target_crtbegin_so_file_arm64 := \
+    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
+
+## CPU variant specific source files
+ifeq ($(strip $(TARGET_CPU_VARIANT)),)
+  $(warning TARGET_ARCH is arm64, but TARGET_CPU_VARIANT is not defined)
+endif
+cpu_variant_mk := $(LOCAL_PATH)/arch-arm64/$(TARGET_CPU_VARIANT)/$(TARGET_CPU_VARIANT).mk
+ifeq ($(wildcard $(cpu_variant_mk)),)
+$(error "TARGET_CPU_VARIANT not set or set to an unknown value. Possible values are generic, generic-neon, denver64. Use generic for devices that do not have a CPU similar to any of the supported cpu variants.")
+endif
+include $(cpu_variant_mk)
+libc_common_additional_dependencies += $(cpu_variank_mk)
+
+cpu_variant_mk :=
diff --git a/libc/arch-arm64/bionic/__bionic_clone.S b/libc/arch-arm64/bionic/__bionic_clone.S
index 9790291..56ac0f6 100644
--- a/libc/arch-arm64/bionic/__bionic_clone.S
+++ b/libc/arch-arm64/bionic/__bionic_clone.S
@@ -31,33 +31,30 @@
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
 
 ENTRY(__bionic_clone)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    /* store thread pointer & args in child stack */
+    # Copy 'fn' and 'arg' onto the child stack.
     stp     x5, x6, [x1, #-16]
 
-    /* sys_clone */
-    uxtw    x0, w0
+    # Make the system call.
     mov     x8, __NR_clone
     svc     #0
 
-    /* check for child/parent */
-    cbz     x0,1f
+    # Are we the child?
+    cbz     x0, .L_bc_child
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
+    # Set errno if something went wrong.
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 
-    /* thread initialization - set the end of the frame record chain */
-1:
+.L_bc_child:
+    # We're in the child now. Set the end of the frame record chain...
     mov     x29, xzr
+    # Setting x30 to 0 will make the unwinder stop at __start_thread
+    mov     x30, xzr
+    # ...and call __start_thread with the 'fn' and 'arg' we stored on the child stack.
     ldp     x0, x1, [sp, #-16]
-    b       __bionic_clone_entry
+    b       __start_thread
 END(__bionic_clone)
+.hidden __bionic_clone
diff --git a/libc/arch-arm64/bionic/__get_sp.S b/libc/arch-arm64/bionic/__get_sp.S
deleted file mode 100644
index 3cd4ceb..0000000
--- a/libc/arch-arm64/bionic/__get_sp.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-
-ENTRY(__get_sp)
-    mov x0, sp
-    ret
-END(__get_sp)
diff --git a/libc/arch-arm64/bionic/__rt_sigreturn.S b/libc/arch-arm64/bionic/__rt_sigreturn.S
index d176ea3..8fb6f0c 100644
--- a/libc/arch-arm64/bionic/__rt_sigreturn.S
+++ b/libc/arch-arm64/bionic/__rt_sigreturn.S
@@ -26,8 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY_PRIVATE(__rt_sigreturn)
   mov     x8, __NR_rt_sigreturn
diff --git a/libc/arch-arm64/bionic/__set_tls.c b/libc/arch-arm64/bionic/__set_tls.c
index 4eb3ade..0d88d11 100644
--- a/libc/arch-arm64/bionic/__set_tls.c
+++ b/libc/arch-arm64/bionic/__set_tls.c
@@ -26,6 +26,8 @@
  * SUCH DAMAGE.
  */
 
-void __set_tls(void* tls) {
+#include <sys/cdefs.h>
+
+__LIBC_HIDDEN__ void __set_tls(void* tls) {
   asm("msr tpidr_el0, %0" : : "r" (tls));
 }
diff --git a/libc/arch-arm64/bionic/_exit_with_stack_teardown.S b/libc/arch-arm64/bionic/_exit_with_stack_teardown.S
index 075e388..6a7b1e5 100644
--- a/libc/arch-arm64/bionic/_exit_with_stack_teardown.S
+++ b/libc/arch-arm64/bionic/_exit_with_stack_teardown.S
@@ -29,7 +29,7 @@
 #include <private/bionic_asm.h>
 
 // void _exit_with_stack_teardown(void* stackBase, size_t stackSize)
-ENTRY(_exit_with_stack_teardown)
+ENTRY_PRIVATE(_exit_with_stack_teardown)
   mov w8, __NR_munmap
   svc #0
   // If munmap failed, we ignore the failure and exit anyway.
diff --git a/libc/arch-arm64/bionic/_setjmp.S b/libc/arch-arm64/bionic/_setjmp.S
index ea70a52..3836899 100644
--- a/libc/arch-arm64/bionic/_setjmp.S
+++ b/libc/arch-arm64/bionic/_setjmp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -73,7 +73,7 @@
     ldr     w9, .L_setjmp_magic
     ldr     w10, [x0, #(_JB_MAGIC * 4)]
     cmp     w9, w10
-    b.ne    botch
+    b.ne    .L_fail
 
     /* restore core registers */
     ldp     x30, x10, [x0, #(_JB_CORE_BASE * 4 + 16 * 0)]
@@ -93,10 +93,10 @@
 
     /* validate sp (sp mod 16 = 0) and lr (lr mod 4 = 0) */
     tst     x30, #3
-    b.ne    botch
+    b.ne    .L_fail
     mov     x10, sp
     tst     x10, #15
-    b.ne    botch
+    b.ne    .L_fail
 
     /* set return value */
     cmp     w1, wzr
@@ -104,8 +104,8 @@
     ret
 
     /* validation failed, die die die */
-botch:
-    bl      PIC_SYM(_C_LABEL(longjmperror), PLT)
-    bl      PIC_SYM(_C_LABEL(abort), PLT)
+.L_fail:
+    bl      PIC_SYM(longjmperror, PLT)
+    bl      PIC_SYM(abort, PLT)
     b        . - 8       /* Cannot get here */
 END(_longjmp)
diff --git a/libc/arch-arm64/bionic/bzero_arm64.c b/libc/arch-arm64/bionic/bzero_arm64.c
deleted file mode 100644
index 1ef920c..0000000
--- a/libc/arch-arm64/bionic/bzero_arm64.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-void bzero(void* s, size_t n) {
-  memset(s, '\0', n);
-}
diff --git a/libc/arch-arm64/bionic/cacheflush_arm64.c b/libc/arch-arm64/bionic/cacheflush_arm64.c
deleted file mode 100644
index 1354fee..0000000
--- a/libc/arch-arm64/bionic/cacheflush_arm64.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* TODO: We can implement a specialised cacheflush() */
-int cacheflush (long start, long end, long flags __attribute__((unused))) {
-  __builtin___clear_cache((char*) start, (char*) end);
-  return 0;
-}
diff --git a/libc/arch-arm64/bionic/futex_arm64.S b/libc/arch-arm64/bionic/futex_arm64.S
deleted file mode 100644
index d452771..0000000
--- a/libc/arch-arm64/bionic/futex_arm64.S
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <private/bionic_asm.h>
-
-#define FUTEX_WAIT 0
-#define FUTEX_WAKE 1
-
-// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout)
-ENTRY(__futex_syscall4)
-  stp x29, x30, [sp, #-16]!
-  mov x29, sp
-
-  str x8, [sp, #-16]!
-  mov x8, __NR_futex
-  svc #0
-  ldr x8, [sp], #16
-
-  ldp x29, x30, [sp], #16
-  ret
-END(__futex_syscall4)
-
-// int __futex_syscall3(volatile void* ftx, int op, int count)
-ENTRY(__futex_syscall3)
-  b __futex_syscall4
-END(__futex_syscall3)
-
-// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout)
-ENTRY(__futex_wait)
-  stp x29, x30, [sp, #-16]!
-  mov x29, sp
-
-  mov x3, x2
-  mov x2, x1
-  mov x1, #FUTEX_WAIT
-
-  str x8, [sp, #-16]!
-  mov x8, __NR_futex
-  svc #0
-  ldr x8, [sp], #16
-
-  ldp x29, x30, [sp], #16
-  ret
-END(__futex_wait)
-
-// int __futex_wake(volatile void* ftx, int count)
-ENTRY(__futex_wake)
-  stp x29, x30, [sp, #-16]!
-  mov x29, sp
-
-  mov x2, x1
-  mov x1, #FUTEX_WAKE
-
-  str x8, [sp, #-16]!
-  mov x8, __NR_futex
-  svc #0
-  ldr x8, [sp], #16
-
-  ldp x29, x30, [sp], #16
-  ret
-END(__futex_wake)
diff --git a/libc/arch-arm64/bionic/setjmp.S b/libc/arch-arm64/bionic/setjmp.S
index b1ec0a8..f9d2266 100644
--- a/libc/arch-arm64/bionic/setjmp.S
+++ b/libc/arch-arm64/bionic/setjmp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -45,7 +45,7 @@
     stp     x0, x30, [sp, #-16]!
 
     mov     x0, xzr
-    bl      PIC_SYM(_C_LABEL(sigblock), PLT)
+    bl      PIC_SYM(sigblock, PLT)
     mov     w1, w0
 
     ldp     x0, x30, [sp], #16
@@ -85,7 +85,7 @@
     ldr     w9, .L_setjmp_magic
     ldr     w10, [x0, #(_JB_MAGIC * 4)]
     cmp     w9, w10
-    b.ne    botch
+    b.ne    .L_fail
 
     /* restore core registers */
     ldp     x30, x10, [x0, #(_JB_CORE_BASE * 4 + 16 * 0)]
@@ -105,10 +105,10 @@
 
     /* validate sp (sp mod 16 = 0) and lr (lr mod 4 = 0) */
     tst     x30, #3
-    b.ne    botch
+    b.ne    .L_fail
     mov     x10, sp
     tst     x10, #15
-    b.ne    botch
+    b.ne    .L_fail
 
     /* set return value */
     cmp     w1, wzr
@@ -116,8 +116,8 @@
     ret
 
     /* validation failed, die die die */
-botch:
-    bl      PIC_SYM(_C_LABEL(longjmperror), PLT)
-    bl      PIC_SYM(_C_LABEL(abort), PLT)
+.L_fail:
+    bl      PIC_SYM(longjmperror, PLT)
+    bl      PIC_SYM(abort, PLT)
     b       . - 8       /* Cannot get here */
 END(longjmp)
diff --git a/libc/arch-arm64/bionic/sigsetjmp.S b/libc/arch-arm64/bionic/sigsetjmp.S
index 3afceab..4fdb367 100644
--- a/libc/arch-arm64/bionic/sigsetjmp.S
+++ b/libc/arch-arm64/bionic/sigsetjmp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -35,8 +35,8 @@
  */
 
 ENTRY(sigsetjmp)
-    cbz     w1, PIC_SYM(_C_LABEL(_setjmp), PLT)
-    b       PIC_SYM(_C_LABEL(setjmp), PLT)
+    cbz     w1, PIC_SYM(_setjmp, PLT)
+    b       PIC_SYM(setjmp, PLT)
 END(sigsetjmp)
 
 .L_setjmp_magic:
@@ -46,6 +46,6 @@
     ldr     w2, .L_setjmp_magic
     ldr     w3, [x0]
     cmp     w2, w3
-    b.eq    PIC_SYM(_C_LABEL(_longjmp), PLT)
-    b       PIC_SYM(_C_LABEL(longjmp), PLT)
+    b.eq    PIC_SYM(_longjmp, PLT)
+    b       PIC_SYM(longjmp, PLT)
 END(siglongjmp)
diff --git a/libc/arch-arm64/bionic/syscall.S b/libc/arch-arm64/bionic/syscall.S
index e5be1d5..8389f98 100644
--- a/libc/arch-arm64/bionic/syscall.S
+++ b/libc/arch-arm64/bionic/syscall.S
@@ -29,13 +29,6 @@
 #include <private/bionic_asm.h>
 
 ENTRY(syscall)
-    /* create AAPCS frame pointer */
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-
-    /* store x8 */
-    str     x8,       [sp, #-16]!
-
     /* Move syscall No. from x0 to x8 */
     mov     x8, x0
     /* Move syscall parameters from x1 thru x6 to x0 thru x5 */
@@ -47,14 +40,10 @@
     mov     x5, x6
     svc     #0
 
-    /* restore x8 */
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     /* check if syscall returned successfully */
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(syscall)
diff --git a/libc/arch-arm64/bionic/vfork.S b/libc/arch-arm64/bionic/vfork.S
index 52009e2..b6a672d 100644
--- a/libc/arch-arm64/bionic/vfork.S
+++ b/libc/arch-arm64/bionic/vfork.S
@@ -37,14 +37,12 @@
     mov     x3, xzr
     mov     x4, xzr
 
-    str     x8, [sp, #-16]!
     mov     x8, __NR_clone
     svc     #0
-    ldr     x8, [sp], #16
 
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(vfork)
diff --git a/libc/arch-arm64/denver64/bionic/memcpy.S b/libc/arch-arm64/denver64/bionic/memcpy.S
new file mode 100644
index 0000000..700f0d0
--- /dev/null
+++ b/libc/arch-arm64/denver64/bionic/memcpy.S
@@ -0,0 +1,205 @@
+/* Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+   Copyright (c) 2014, NVIDIA Corporation.  All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * denver, ARMv8-a, AArch64
+ * Unaligned accesses
+ *
+ */
+
+#include <private/bionic_asm.h>
+
+#define dstin	x0
+#define src	x1
+#define count	x2
+#define tmp1	x3
+#define tmp1w	w3
+#define tmp2	x4
+#define tmp2w	w4
+#define tmp3	x5
+#define tmp3w	w5
+#define dst	x6
+
+#define A_l	x7
+#define A_h	x8
+#define B_l	x9
+#define B_h	x10
+#define C_l	x11
+#define C_h	x12
+#define D_l	x13
+#define D_h	x14
+
+#define QA_l	q0
+#define QA_h	q1
+#define QB_l	q2
+#define QB_h	q3
+
+ENTRY(memcpy)
+
+	mov	dst, dstin
+	cmp	count, #64
+	b.ge	.Lcpy_not_short
+	cmp	count, #15
+	b.le	.Ltail15tiny
+
+	/* Deal with small copies quickly by dropping straight into the
+	 * exit block.  */
+.Ltail63:
+	/* Copy up to 48 bytes of data.  At this point we only need the
+	 * bottom 6 bits of count to be accurate.  */
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15
+	add	dst, dst, tmp1
+	add	src, src, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	ldp	A_l, A_h, [src, #-48]
+	stp	A_l, A_h, [dst, #-48]
+1:
+	ldp	A_l, A_h, [src, #-32]
+	stp	A_l, A_h, [dst, #-32]
+2:
+	ldp	A_l, A_h, [src, #-16]
+	stp	A_l, A_h, [dst, #-16]
+
+.Ltail15:
+	ands	count, count, #15
+	beq	1f
+	add	src, src, count
+	ldp	A_l, A_h, [src, #-16]
+	add	dst, dst, count
+	stp	A_l, A_h, [dst, #-16]
+1:
+	ret
+
+.Ltail15tiny:
+	/* Copy up to 15 bytes of data.  Does not assume additional data
+	   being copied.  */
+	tbz	count, #3, 1f
+	ldr	tmp1, [src], #8
+	str	tmp1, [dst], #8
+1:
+	tbz	count, #2, 1f
+	ldr	tmp1w, [src], #4
+	str	tmp1w, [dst], #4
+1:
+	tbz	count, #1, 1f
+	ldrh	tmp1w, [src], #2
+	strh	tmp1w, [dst], #2
+1:
+	tbz	count, #0, 1f
+	ldrb	tmp1w, [src]
+	strb	tmp1w, [dst]
+1:
+	ret
+
+.Lcpy_not_short:
+	/* We don't much care about the alignment of DST, but we want SRC
+	 * to be 128-bit (16 byte) aligned so that we don't cross cache line
+	 * boundaries on both loads and stores.  */
+	neg	tmp2, src
+	ands	tmp2, tmp2, #15		/* Bytes to reach alignment.  */
+	b.eq	2f
+	sub	count, count, tmp2
+	/* Copy more data than needed; it's faster than jumping
+	 * around copying sub-Quadword quantities.  We know that
+	 * it can't overrun.  */
+	ldp	A_l, A_h, [src]
+	add	src, src, tmp2
+	stp	A_l, A_h, [dst]
+	add	dst, dst, tmp2
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #63
+	b.le	.Ltail63
+2:
+	subs	count, count, #128
+	b.ge	.Lcpy_body_large
+	/* Less than 128 bytes to copy, so handle 64 here and then jump
+	 * to the tail.  */
+	ldp	QA_l, QA_h, [src]
+	ldp	QB_l, QB_h, [src, #32]
+	stp	QA_l, QA_h, [dst]
+	stp	QB_l, QB_h, [dst, #32]
+	tst	count, #0x3f
+	add	src, src, #64
+	add	dst, dst, #64
+	b.ne	.Ltail63
+	ret
+
+	/* Critical loop.  Start at a new cache line boundary.  Assuming
+	 * 64 bytes per line this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lcpy_body_large:
+	cmp	count, 65536
+	bhi	.Lcpy_body_huge
+	/* There are at least 128 bytes to copy.  */
+	ldp	QA_l, QA_h, [src, #0]
+	sub	dst, dst, #32		/* Pre-bias.  */
+	ldp	QB_l, QB_h, [src, #32]!	/* src += 64 - Pre-bias.  */
+1:
+	stp	QA_l, QA_h, [dst, #32]
+	ldp	QA_l, QA_h, [src, #32]
+	stp	QB_l, QB_h, [dst, #64]!
+	ldp	QB_l, QB_h, [src, #64]!
+
+	subs	count, count, #64
+	b.ge	1b
+
+	stp	QA_l, QA_h, [dst, #32]
+	stp	QB_l, QB_h, [dst, #64]
+	add	src, src, #32
+	add	dst, dst, #64 + 32
+	tst	count, #0x3f
+	b.ne	.Ltail63
+	ret
+.Lcpy_body_huge:
+	/* There are at least 128 bytes to copy.  */
+	ldp	QA_l, QA_h, [src, #0]
+	sub	dst, dst, #32		/* Pre-bias.  */
+	ldp	QB_l, QB_h, [src, #32]!
+1:
+	stnp	QA_l, QA_h, [dst, #32]
+	stnp	QB_l, QB_h, [dst, #64]
+	ldp	QA_l, QA_h, [src, #32]
+	ldp	QB_l, QB_h, [src, #64]!
+	add	dst, dst, #64
+
+	subs	count, count, #64
+	b.ge	1b
+
+	stnp	QA_l, QA_h, [dst, #32]
+	stnp	QB_l, QB_h, [dst, #64]
+	add	src, src, #32
+	add	dst, dst, #64 + 32
+	tst	count, #0x3f
+	b.ne	.Ltail63
+	ret
+
+END(memcpy)
diff --git a/libc/arch-arm64/denver64/bionic/memset.S b/libc/arch-arm64/denver64/bionic/memset.S
new file mode 100644
index 0000000..9127d89
--- /dev/null
+++ b/libc/arch-arm64/denver64/bionic/memset.S
@@ -0,0 +1,271 @@
+/* Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+   Copyright (c) 2014, NVIDIA Corporation.  All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * denver, ARMv8-a, AArch64
+ * Unaligned accesses
+ *
+ */
+
+#include <private/bionic_asm.h>
+
+/* By default we assume that the DC instruction can be used to zero
+   data blocks more efficiently.  In some circumstances this might be
+   unsafe, for example in an asymmetric multiprocessor environment with
+   different DC clear lengths (neither the upper nor lower lengths are
+   safe to use).  The feature can be disabled by defining DONT_USE_DC.
+
+   If code may be run in a virtualized environment, then define
+   MAYBE_VIRT.  This will cause the code to cache the system register
+   values rather than re-reading them each call.  */
+
+#define dstin		x0
+#define val		w1
+#define count		x2
+#define tmp1		x3
+#define tmp1w		w3
+#define tmp2		x4
+#define tmp2w		w4
+#define zva_len_x	x5
+#define zva_len		w5
+#define zva_bits_x	x6
+
+#define A_l		x7
+#define A_lw		w7
+#define dst		x8
+#define tmp3w		w9
+
+#define QA_l		q0
+
+ENTRY(memset)
+
+	mov	dst, dstin		/* Preserve return value.  */
+	ands	A_lw, val, #255
+#ifndef DONT_USE_DC
+#	b.eq	.Lzero_mem
+#endif
+	orr	A_lw, A_lw, A_lw, lsl #8
+	orr	A_lw, A_lw, A_lw, lsl #16
+	orr	A_l, A_l, A_l, lsl #32
+.Ltail_maybe_long:
+	cmp	count, #256
+	b.ge	.Lnot_short
+.Ltail_maybe_tiny:
+	cmp	count, #15
+	b.le	.Ltail15tiny
+.Ltail255:
+	ands	tmp1, count, #0xC0
+	b.eq	.Ltail63
+	dup	v0.4s, A_lw
+	cmp	tmp1w, #0x80
+	b.eq	1f
+	b.lt	2f
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+1:
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+2:
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+.Ltail63:
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15
+	add	dst, dst, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	stp	A_l, A_l, [dst, #-48]
+1:
+	stp	A_l, A_l, [dst, #-32]
+2:
+	stp	A_l, A_l, [dst, #-16]
+
+.Ltail15:
+	and	count, count, #15
+	add	dst, dst, count
+	stp	A_l, A_l, [dst, #-16]	/* Repeat some/all of last store. */
+	ret
+
+.Ltail15tiny:
+	/* Set up to 15 bytes.  Does not assume earlier memory
+	   being set.  */
+	tbz	count, #3, 1f
+	str	A_l, [dst], #8
+1:
+	tbz	count, #2, 1f
+	str	A_lw, [dst], #4
+1:
+	tbz	count, #1, 1f
+	strh	A_lw, [dst], #2
+1:
+	tbz	count, #0, 1f
+	strb	A_lw, [dst]
+1:
+	ret
+
+	/* Critical loop.  Start at a new cache line boundary.  Assuming
+	 * 64 bytes per line, this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lnot_short:
+	dup	v0.4s, A_lw
+	neg	tmp2, dst
+	ands	tmp2, tmp2, #15
+	b.eq	2f
+	/* Bring DST to 128-bit (16-byte) alignment.  We know that there's
+	 * more than that to set, so we simply store 16 bytes and advance by
+	 * the amount required to reach alignment.  */
+	sub	count, count, tmp2
+	stp	A_l, A_l, [dst]
+	add	dst, dst, tmp2
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #255
+	b.le	.Ltail255
+2:
+	cmp	count, #2097152
+	b.gt	3f
+1:
+	sub	count, count, #256
+2:
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	stp	QA_l, QA_l, [dst], #32
+	subs	count, count, #256
+	b.ge	2b
+	tst	count, #0xff
+	b.ne	.Ltail255
+	ret
+3:
+	sub	count, count, #64
+4:
+	subs	count, count, #64
+	stnp	QA_l, QA_l, [dst]
+	stnp	QA_l, QA_l, [dst, #32]
+	add	dst, dst, #64
+	b.ge	4b
+	tst	count, #0x3f
+	b.ne	.Ltail63
+	ret
+
+#ifndef DONT_USE_DC
+	/* For zeroing memory, check to see if we can use the ZVA feature to
+	 * zero entire 'cache' lines.  */
+.Lzero_mem:
+	mov	A_l, #0
+	cmp	count, #63
+	b.le	.Ltail_maybe_tiny
+	neg	tmp2, dst
+	ands	tmp2, tmp2, #15
+	b.eq	1f
+	sub	count, count, tmp2
+	stp	A_l, A_l, [dst]
+	add	dst, dst, tmp2
+	cmp	count, #63
+	b.le	.Ltail63
+1:
+	/* For zeroing small amounts of memory, it's not worth setting up
+	 * the line-clear code.  */
+	cmp	count, #128
+	b.lt	.Lnot_short
+#ifdef MAYBE_VIRT
+	/* For efficiency when virtualized, we cache the ZVA capability.  */
+	adrp	tmp2, .Lcache_clear
+	ldr	zva_len, [tmp2, #:lo12:.Lcache_clear]
+	tbnz	zva_len, #31, .Lnot_short
+	cbnz	zva_len, .Lzero_by_line
+	mrs	tmp1, dczid_el0
+	tbz	tmp1, #4, 1f
+	/* ZVA not available.  Remember this for next time.  */
+	mov	zva_len, #~0
+	str	zva_len, [tmp2, #:lo12:.Lcache_clear]
+	b	.Lnot_short
+1:
+	mov	tmp3w, #4
+	and	zva_len, tmp1w, #15	/* Safety: other bits reserved.  */
+	lsl	zva_len, tmp3w, zva_len
+	str	zva_len, [tmp2, #:lo12:.Lcache_clear]
+#else
+	mrs	tmp1, dczid_el0
+	tbnz	tmp1, #4, .Lnot_short
+	mov	tmp3w, #4
+	and	zva_len, tmp1w, #15	/* Safety: other bits reserved.  */
+	lsl	zva_len, tmp3w, zva_len
+#endif
+
+.Lzero_by_line:
+	/* Compute how far we need to go to become suitably aligned.  We're
+	 * already at quad-word alignment.  */
+	cmp	count, zva_len_x
+	b.lt	.Lnot_short		/* Not enough to reach alignment.  */
+	sub	zva_bits_x, zva_len_x, #1
+	neg	tmp2, dst
+	ands	tmp2, tmp2, zva_bits_x
+	b.eq	1f			/* Already aligned.  */
+	/* Not aligned, check that there's enough to copy after alignment.  */
+	sub	tmp1, count, tmp2
+	cmp	tmp1, #64
+	ccmp	tmp1, zva_len_x, #8, ge	/* NZCV=0b1000 */
+	b.lt	.Lnot_short
+	/* We know that there's at least 64 bytes to zero and that it's safe
+	 * to overrun by 64 bytes.  */
+	mov	count, tmp1
+2:
+	stp	A_l, A_l, [dst]
+	stp	A_l, A_l, [dst, #16]
+	stp	A_l, A_l, [dst, #32]
+	subs	tmp2, tmp2, #64
+	stp	A_l, A_l, [dst, #48]
+	add	dst, dst, #64
+	b.ge	2b
+	/* We've overrun a bit, so adjust dst downwards.  */
+	add	dst, dst, tmp2
+1:
+	sub	count, count, zva_len_x
+3:
+	dc	zva, dst
+	add	dst, dst, zva_len_x
+	subs	count, count, zva_len_x
+	b.ge	3b
+	ands	count, count, zva_bits_x
+	b.ne	.Ltail_maybe_long
+	ret
+END(memset)
+
+#ifdef MAYBE_VIRT
+	.bss
+	.p2align 2
+.Lcache_clear:
+	.space 4
+#endif
+#endif /* DONT_USE_DC */
diff --git a/libc/arch-arm64/denver64/denver64.mk b/libc/arch-arm64/denver64/denver64.mk
new file mode 100644
index 0000000..d619c11
--- /dev/null
+++ b/libc/arch-arm64/denver64/denver64.mk
@@ -0,0 +1,14 @@
+libc_bionic_src_files_arm64 += \
+    arch-arm64/generic/bionic/memchr.S \
+    arch-arm64/generic/bionic/memcmp.S \
+    arch-arm64/denver64/bionic/memcpy.S \
+    arch-arm64/generic/bionic/memmove.S \
+    arch-arm64/denver64/bionic/memset.S \
+    arch-arm64/generic/bionic/stpcpy.S \
+    arch-arm64/generic/bionic/strchr.S \
+    arch-arm64/generic/bionic/strcmp.S \
+    arch-arm64/generic/bionic/strcpy.S \
+    arch-arm64/generic/bionic/strlen.S \
+    arch-arm64/generic/bionic/strncmp.S \
+    arch-arm64/generic/bionic/strnlen.S \
+    arch-arm64/generic/bionic/wmemmove.S
diff --git a/libc/arch-arm64/generic-neon/bionic/memcpy.S b/libc/arch-arm64/generic-neon/bionic/memcpy.S
new file mode 100644
index 0000000..320f748
--- /dev/null
+++ b/libc/arch-arm64/generic-neon/bionic/memcpy.S
@@ -0,0 +1,179 @@
+/* Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ * Unaligned accesses
+ *
+ */
+
+#include <private/bionic_asm.h>
+
+#define dstin	x0
+#define src	x1
+#define count	x2
+#define tmp1	x3
+#define tmp1w	w3
+#define tmp2	x4
+#define tmp2w	w4
+#define tmp3	x5
+#define tmp3w	w5
+#define dst	x6
+
+#define A_l	x7
+#define A_h	x8
+#define B_l	x9
+#define B_h	x10
+#define C_l	x11
+#define C_h	x12
+#define D_l	x13
+#define D_h	x14
+
+#define QA_l q0
+#define QA_h q1
+#define QB_l q2
+#define QB_h q3
+
+ENTRY(memcpy)
+
+	mov	dst, dstin
+	cmp	count, #64
+	b.ge	.Lcpy_not_short
+	cmp	count, #15
+	b.le	.Ltail15tiny
+
+	/* Deal with small copies quickly by dropping straight into the
+	 * exit block.  */
+.Ltail63:
+	/* Copy up to 48 bytes of data.  At this point we only need the
+	 * bottom 6 bits of count to be accurate.  */
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15
+	add	dst, dst, tmp1
+	add	src, src, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	ldp	A_l, A_h, [src, #-48]
+	stp	A_l, A_h, [dst, #-48]
+1:
+	ldp	A_l, A_h, [src, #-32]
+	stp	A_l, A_h, [dst, #-32]
+2:
+	ldp	A_l, A_h, [src, #-16]
+	stp	A_l, A_h, [dst, #-16]
+
+.Ltail15:
+	ands	count, count, #15
+	beq	1f
+	add	src, src, count
+	ldp	A_l, A_h, [src, #-16]
+	add	dst, dst, count
+	stp	A_l, A_h, [dst, #-16]
+1:
+	ret
+
+.Ltail15tiny:
+	/* Copy up to 15 bytes of data.  Does not assume additional data
+	   being copied.  */
+	tbz	count, #3, 1f
+	ldr	tmp1, [src], #8
+	str	tmp1, [dst], #8
+1:
+	tbz	count, #2, 1f
+	ldr	tmp1w, [src], #4
+	str	tmp1w, [dst], #4
+1:
+	tbz	count, #1, 1f
+	ldrh	tmp1w, [src], #2
+	strh	tmp1w, [dst], #2
+1:
+	tbz	count, #0, 1f
+	ldrb	tmp1w, [src]
+	strb	tmp1w, [dst]
+1:
+	ret
+
+.Lcpy_not_short:
+	/* We don't much care about the alignment of DST, but we want SRC
+	 * to be 128-bit (16 byte) aligned so that we don't cross cache line
+	 * boundaries on both loads and stores.  */
+	neg	tmp2, src
+	ands	tmp2, tmp2, #15		/* Bytes to reach alignment.  */
+	b.eq	2f
+	sub	count, count, tmp2
+	/* Copy more data than needed; it's faster than jumping
+	 * around copying sub-Quadword quantities.  We know that
+	 * it can't overrun.  */
+	ldp	A_l, A_h, [src]
+	add	src, src, tmp2
+	stp	A_l, A_h, [dst]
+	add	dst, dst, tmp2
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #63
+	b.le	.Ltail63
+2:
+	subs	count, count, #128
+	b.ge	.Lcpy_body_large
+	/* Less than 128 bytes to copy, so handle 64 here and then jump
+	 * to the tail.  */
+	ldp QA_l, QA_h, [src]
+	ldp QB_l, QB_h, [src, #32]
+	stp QA_l, QA_h, [dst]
+	stp QB_l, QB_h, [dst, #32]
+	tst	count, #0x3f
+	add	src, src, #64
+	add	dst, dst, #64
+	b.ne	.Ltail63
+	ret
+
+	/* Critical loop.  Start at a new cache line boundary.  Assuming
+	 * 64 bytes per line this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lcpy_body_large:
+	/* There are at least 128 bytes to copy.  */
+	ldp QA_l, QA_h, [src, #0]
+	sub	dst, dst, #32		/* Pre-bias.  */
+	ldp QB_l, QB_h, [src, #32]!	/* src += 64 - Pre-bias.  */
+1:
+	stp QA_l, QA_h, [dst, #32]
+	ldp QA_l, QA_h, [src, #32]
+	stp QB_l, QB_h, [dst, #64]!
+	ldp QB_l, QB_h, [src, #64]!
+
+	subs	count, count, #64
+	b.ge	1b
+
+	stp QA_l, QA_h, [dst, #32]
+	stp QB_l, QB_h, [dst, #64]
+	add	src, src, #32
+	add	dst, dst, #64 + 32
+	tst	count, #0x3f
+	b.ne	.Ltail63
+	ret
+END(memcpy)
diff --git a/libc/arch-arm64/generic-neon/generic-neon.mk b/libc/arch-arm64/generic-neon/generic-neon.mk
new file mode 100644
index 0000000..77e3861
--- /dev/null
+++ b/libc/arch-arm64/generic-neon/generic-neon.mk
@@ -0,0 +1,13 @@
+libc_bionic_src_files_arm64 += \
+    arch-arm64/generic/bionic/memchr.S \
+    arch-arm64/generic/bionic/memcmp.S \
+    arch-arm64/generic/bionic/memmove.S \
+    arch-arm64/generic/bionic/memset.S \
+    arch-arm64/generic/bionic/stpcpy.S \
+    arch-arm64/generic/bionic/strchr.S \
+    arch-arm64/generic/bionic/strcmp.S \
+    arch-arm64/generic/bionic/strcpy.S \
+    arch-arm64/generic/bionic/strlen.S \
+    arch-arm64/generic/bionic/strncmp.S \
+    arch-arm64/generic/bionic/strnlen.S \
+    arch-arm64/generic-neon/bionic/memcpy.S \
diff --git a/libc/arch-arm64/generic/bionic/memchr.S b/libc/arch-arm64/generic/bionic/memchr.S
new file mode 100644
index 0000000..e5ea57d
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/memchr.S
@@ -0,0 +1,165 @@
+/*
+ * memchr - find a character in a memory zone
+ *
+ * Copyright (c) 2014, ARM Limited
+ * All rights Reserved.
+ * Copyright (c) 2014, Linaro Ltd.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the company nor the names of its contributors
+ *       may be used to endorse or promote products derived from this
+ *       software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ * Neon Available.
+ */
+
+#include <private/bionic_asm.h>
+
+/* Arguments and results.  */
+#define srcin		x0
+#define chrin		w1
+#define cntin		x2
+
+#define result		x0
+
+#define src		x3
+#define	tmp		x4
+#define wtmp2		w5
+#define synd		x6
+#define soff		x9
+#define cntrem		x10
+
+#define vrepchr		v0
+#define vdata1		v1
+#define vdata2		v2
+#define vhas_chr1	v3
+#define vhas_chr2	v4
+#define vrepmask	v5
+#define vend		v6
+
+/*
+ * Core algorithm:
+ *
+ * For each 32-byte chunk we calculate a 64-bit syndrome value, with two bits
+ * per byte. For each tuple, bit 0 is set if the relevant byte matched the
+ * requested character and bit 1 is not used (faster than using a 32bit
+ * syndrome). Since the bits in the syndrome reflect exactly the order in which
+ * things occur in the original string, counting trailing zeros allows to
+ * identify exactly which byte has matched.
+ */
+
+ENTRY(memchr)
+	/*
+	 * Magic constant 0x40100401 allows us to identify which lane matches
+	 * the requested byte.
+	 */
+	cbz	cntin, .Lzero_length
+	mov	wtmp2, #0x0401
+	movk	wtmp2, #0x4010, lsl #16
+	dup	vrepchr.16b, chrin
+	/* Work with aligned 32-byte chunks */
+	bic	src, srcin, #31
+	dup	vrepmask.4s, wtmp2
+	ands	soff, srcin, #31
+	and	cntrem, cntin, #31
+	b.eq	.Lloop
+
+	/*
+	 * Input string is not 32-byte aligned. We calculate the syndrome
+	 * value for the aligned 32 bytes block containing the first bytes
+	 * and mask the irrelevant part.
+	 */
+
+	ld1	{vdata1.16b, vdata2.16b}, [src], #32
+	sub	tmp, soff, #32
+	adds	cntin, cntin, tmp
+	cmeq	vhas_chr1.16b, vdata1.16b, vrepchr.16b
+	cmeq	vhas_chr2.16b, vdata2.16b, vrepchr.16b
+	and	vhas_chr1.16b, vhas_chr1.16b, vrepmask.16b
+	and	vhas_chr2.16b, vhas_chr2.16b, vrepmask.16b
+	addp	vend.16b, vhas_chr1.16b, vhas_chr2.16b		/* 256->128 */
+	addp	vend.16b, vend.16b, vend.16b			/* 128->64 */
+	mov	synd, vend.2d[0]
+	/* Clear the soff*2 lower bits */
+	lsl	tmp, soff, #1
+	lsr	synd, synd, tmp
+	lsl	synd, synd, tmp
+	/* The first block can also be the last */
+	b.ls	.Lmasklast
+	/* Have we found something already? */
+	cbnz	synd, .Ltail
+
+.Lloop:
+	ld1	{vdata1.16b, vdata2.16b}, [src], #32
+	subs	cntin, cntin, #32
+	cmeq	vhas_chr1.16b, vdata1.16b, vrepchr.16b
+	cmeq	vhas_chr2.16b, vdata2.16b, vrepchr.16b
+	/* If we're out of data we finish regardless of the result */
+	b.ls	.Lend
+	/* Use a fast check for the termination condition */
+	orr	vend.16b, vhas_chr1.16b, vhas_chr2.16b
+	addp	vend.2d, vend.2d, vend.2d
+	mov	synd, vend.2d[0]
+	/* We're not out of data, loop if we haven't found the character */
+	cbz	synd, .Lloop
+
+.Lend:
+	/* Termination condition found, let's calculate the syndrome value */
+	and	vhas_chr1.16b, vhas_chr1.16b, vrepmask.16b
+	and	vhas_chr2.16b, vhas_chr2.16b, vrepmask.16b
+	addp	vend.16b, vhas_chr1.16b, vhas_chr2.16b		/* 256->128 */
+	addp	vend.16b, vend.16b, vend.16b			/* 128->64 */
+	mov	synd, vend.2d[0]
+	/* Only do the clear for the last possible block */
+	b.hi	.Ltail
+
+.Lmasklast:
+	/* Clear the (32 - ((cntrem + soff) % 32)) * 2 upper bits */
+	add	tmp, cntrem, soff
+	and	tmp, tmp, #31
+	sub	tmp, tmp, #32
+	neg	tmp, tmp, lsl #1
+	lsl	synd, synd, tmp
+	lsr	synd, synd, tmp
+
+.Ltail:
+	/* Count the trailing zeros using bit reversing */
+	rbit	synd, synd
+	/* Compensate the last post-increment */
+	sub	src, src, #32
+	/* Check that we have found a character */
+	cmp	synd, #0
+	/* And count the leading zeros */
+	clz	synd, synd
+	/* Compute the potential result */
+	add	result, src, synd, lsr #1
+	/* Select result or NULL */
+	csel	result, xzr, result, eq
+	ret
+
+.Lzero_length:
+	mov	result, xzr
+	ret
+END(memchr)
diff --git a/libc/arch-arm64/generic/bionic/memcmp.S b/libc/arch-arm64/generic/bionic/memcmp.S
new file mode 100644
index 0000000..3d08ecd
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/memcmp.S
@@ -0,0 +1,155 @@
+/* Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ */
+
+#include <private/bionic_asm.h>
+
+/* Parameters and result.  */
+#define src1		x0
+#define src2		x1
+#define limit		x2
+#define result		x0
+
+/* Internal variables.  */
+#define data1		x3
+#define data1w		w3
+#define data2		x4
+#define data2w		w4
+#define has_nul		x5
+#define diff		x6
+#define endloop		x7
+#define tmp1		x8
+#define tmp2		x9
+#define tmp3		x10
+#define pos		x11
+#define limit_wd	x12
+#define mask		x13
+
+ENTRY(memcmp)
+	cbz	limit, .Lret0
+	eor	tmp1, src1, src2
+	tst	tmp1, #7
+	b.ne	.Lmisaligned8
+	ands	tmp1, src1, #7
+	b.ne	.Lmutual_align
+	add	limit_wd, limit, #7
+	lsr	limit_wd, limit_wd, #3
+	/* Start of performance-critical section  -- one 64B cache line.  */
+.Lloop_aligned:
+	ldr	data1, [src1], #8
+	ldr	data2, [src2], #8
+.Lstart_realigned:
+	subs	limit_wd, limit_wd, #1
+	eor	diff, data1, data2	/* Non-zero if differences found.  */
+	csinv	endloop, diff, xzr, ne	/* Last Dword or differences.  */
+	cbz	endloop, .Lloop_aligned
+	/* End of performance-critical section  -- one 64B cache line.  */
+
+	/* Not reached the limit, must have found a diff.  */
+	cbnz	limit_wd, .Lnot_limit
+
+	/* Limit % 8 == 0 => all bytes significant.  */
+	ands	limit, limit, #7
+	b.eq	.Lnot_limit
+
+	lsl	limit, limit, #3	/* Bits -> bytes.  */
+	mov	mask, #~0
+#ifdef __AARCH64EB__
+	lsr	mask, mask, limit
+#else
+	lsl	mask, mask, limit
+#endif
+	bic	data1, data1, mask
+	bic	data2, data2, mask
+
+	orr	diff, diff, mask
+.Lnot_limit:
+
+#ifndef	__AARCH64EB__
+	rev	diff, diff
+	rev	data1, data1
+	rev	data2, data2
+#endif
+	/* The MS-non-zero bit of DIFF marks either the first bit
+	   that is different, or the end of the significant data.
+	   Shifting left now will bring the critical information into the
+	   top bits.  */
+	clz	pos, diff
+	lsl	data1, data1, pos
+	lsl	data2, data2, pos
+	/* But we need to zero-extend (char is unsigned) the value and then
+	   perform a signed 32-bit subtraction.  */
+	lsr	data1, data1, #56
+	sub	result, data1, data2, lsr #56
+	ret
+
+.Lmutual_align:
+	/* Sources are mutually aligned, but are not currently at an
+	   alignment boundary.  Round down the addresses and then mask off
+	   the bytes that precede the start point.  */
+	bic	src1, src1, #7
+	bic	src2, src2, #7
+	add	limit, limit, tmp1	/* Adjust the limit for the extra.  */
+	lsl	tmp1, tmp1, #3		/* Bytes beyond alignment -> bits.  */
+	ldr	data1, [src1], #8
+	neg	tmp1, tmp1		/* Bits to alignment -64.  */
+	ldr	data2, [src2], #8
+	mov	tmp2, #~0
+#ifdef __AARCH64EB__
+	/* Big-endian.  Early bytes are at MSB.  */
+	lsl	tmp2, tmp2, tmp1	/* Shift (tmp1 & 63).  */
+#else
+	/* Little-endian.  Early bytes are at LSB.  */
+	lsr	tmp2, tmp2, tmp1	/* Shift (tmp1 & 63).  */
+#endif
+	add	limit_wd, limit, #7
+	orr	data1, data1, tmp2
+	orr	data2, data2, tmp2
+	lsr	limit_wd, limit_wd, #3
+	b	.Lstart_realigned
+
+.Lret0:
+	mov	result, #0
+	ret
+
+	.p2align 6
+.Lmisaligned8:
+	sub	limit, limit, #1
+1:
+	/* Perhaps we can do better than this.  */
+	ldrb	data1w, [src1], #1
+	ldrb	data2w, [src2], #1
+	subs	limit, limit, #1
+	ccmp	data1w, data2w, #0, cs	/* NZCV = 0b0000.  */
+	b.eq	1b
+	sub	result, data1, data2
+	ret
+END(memcmp)
diff --git a/libc/arch-arm64/generic/bionic/memcpy.S b/libc/arch-arm64/generic/bionic/memcpy.S
new file mode 100644
index 0000000..e1b1a72
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/memcpy.S
@@ -0,0 +1,184 @@
+/* Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ * Unaligned accesses
+ *
+ */
+
+#include <private/bionic_asm.h>
+
+#define dstin	x0
+#define src	x1
+#define count	x2
+#define tmp1	x3
+#define tmp1w	w3
+#define tmp2	x4
+#define tmp2w	w4
+#define tmp3	x5
+#define tmp3w	w5
+#define dst	x6
+
+#define A_l	x7
+#define A_h	x8
+#define B_l	x9
+#define B_h	x10
+#define C_l	x11
+#define C_h	x12
+#define D_l	x13
+#define D_h	x14
+
+ENTRY(memcpy)
+
+	mov	dst, dstin
+	cmp	count, #64
+	b.ge	.Lcpy_not_short
+	cmp	count, #15
+	b.le	.Ltail15tiny
+
+	/* Deal with small copies quickly by dropping straight into the
+	 * exit block.  */
+.Ltail63:
+	/* Copy up to 48 bytes of data.  At this point we only need the
+	 * bottom 6 bits of count to be accurate.  */
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15
+	add	dst, dst, tmp1
+	add	src, src, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	ldp	A_l, A_h, [src, #-48]
+	stp	A_l, A_h, [dst, #-48]
+1:
+	ldp	A_l, A_h, [src, #-32]
+	stp	A_l, A_h, [dst, #-32]
+2:
+	ldp	A_l, A_h, [src, #-16]
+	stp	A_l, A_h, [dst, #-16]
+
+.Ltail15:
+	ands	count, count, #15
+	beq	1f
+	add	src, src, count
+	ldp	A_l, A_h, [src, #-16]
+	add	dst, dst, count
+	stp	A_l, A_h, [dst, #-16]
+1:
+	ret
+
+.Ltail15tiny:
+	/* Copy up to 15 bytes of data.  Does not assume additional data
+	   being copied.  */
+	tbz	count, #3, 1f
+	ldr	tmp1, [src], #8
+	str	tmp1, [dst], #8
+1:
+	tbz	count, #2, 1f
+	ldr	tmp1w, [src], #4
+	str	tmp1w, [dst], #4
+1:
+	tbz	count, #1, 1f
+	ldrh	tmp1w, [src], #2
+	strh	tmp1w, [dst], #2
+1:
+	tbz	count, #0, 1f
+	ldrb	tmp1w, [src]
+	strb	tmp1w, [dst]
+1:
+	ret
+
+.Lcpy_not_short:
+	/* We don't much care about the alignment of DST, but we want SRC
+	 * to be 128-bit (16 byte) aligned so that we don't cross cache line
+	 * boundaries on both loads and stores.  */
+	neg	tmp2, src
+	ands	tmp2, tmp2, #15		/* Bytes to reach alignment.  */
+	b.eq	2f
+	sub	count, count, tmp2
+	/* Copy more data than needed; it's faster than jumping
+	 * around copying sub-Quadword quantities.  We know that
+	 * it can't overrun.  */
+	ldp	A_l, A_h, [src]
+	add	src, src, tmp2
+	stp	A_l, A_h, [dst]
+	add	dst, dst, tmp2
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #63
+	b.le	.Ltail63
+2:
+	subs	count, count, #128
+	b.ge	.Lcpy_body_large
+	/* Less than 128 bytes to copy, so handle 64 here and then jump
+	 * to the tail.  */
+	ldp	A_l, A_h, [src]
+	ldp	B_l, B_h, [src, #16]
+	ldp	C_l, C_h, [src, #32]
+	ldp	D_l, D_h, [src, #48]
+	stp	A_l, A_h, [dst]
+	stp	B_l, B_h, [dst, #16]
+	stp	C_l, C_h, [dst, #32]
+	stp	D_l, D_h, [dst, #48]
+	tst	count, #0x3f
+	add	src, src, #64
+	add	dst, dst, #64
+	b.ne	.Ltail63
+	ret
+
+	/* Critical loop.  Start at a new cache line boundary.  Assuming
+	 * 64 bytes per line this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lcpy_body_large:
+	/* There are at least 128 bytes to copy.  */
+	ldp	A_l, A_h, [src, #0]
+	sub	dst, dst, #16		/* Pre-bias.  */
+	ldp	B_l, B_h, [src, #16]
+	ldp	C_l, C_h, [src, #32]
+	ldp	D_l, D_h, [src, #48]!	/* src += 64 - Pre-bias.  */
+1:
+	stp	A_l, A_h, [dst, #16]
+	ldp	A_l, A_h, [src, #16]
+	stp	B_l, B_h, [dst, #32]
+	ldp	B_l, B_h, [src, #32]
+	stp	C_l, C_h, [dst, #48]
+	ldp	C_l, C_h, [src, #48]
+	stp	D_l, D_h, [dst, #64]!
+	ldp	D_l, D_h, [src, #64]!
+	subs	count, count, #64
+	b.ge	1b
+	stp	A_l, A_h, [dst, #16]
+	stp	B_l, B_h, [dst, #32]
+	stp	C_l, C_h, [dst, #48]
+	stp	D_l, D_h, [dst, #64]
+	add	src, src, #16
+	add	dst, dst, #64 + 16
+	tst	count, #0x3f
+	b.ne	.Ltail63
+	ret
+END(memcpy)
diff --git a/libc/arch-arm64/generic/bionic/memmove.S b/libc/arch-arm64/generic/bionic/memmove.S
new file mode 100644
index 0000000..8b366a3
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/memmove.S
@@ -0,0 +1,341 @@
+/* Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ * Unaligned accesses
+ * wchar_t is 4 bytes
+ */
+
+#include <private/bionic_asm.h>
+
+/* Parameters and result.  */
+#ifdef BCOPY
+#define origdstin	x1
+#define origsrc	x0
+#endif
+#define dstin	x0
+#define src	x1
+#define count	x2
+#define tmp1	x3
+#define tmp1w	w3
+#define tmp2	x4
+#define tmp2w	w4
+#define tmp3	x5
+#define tmp3w	w5
+#define dst	x6
+
+#define A_l	x7
+#define A_h	x8
+#define B_l	x9
+#define B_h	x10
+#define C_l	x11
+#define C_h	x12
+#define D_l	x13
+#define D_h	x14
+
+#ifdef BCOPY
+ENTRY(bcopy)
+	/* Swap src and dst so that a branch to memcpy doesn't cause issues. */
+	mov	tmp1, origsrc
+	mov	origsrc, origdstin
+	mov	origdstin, tmp1
+#elif defined(WMEMMOVE)
+ENTRY(wmemmove)
+	lsl	count, count, #2
+#else
+ENTRY(memmove)
+#endif
+	cmp	dstin, src
+	b.lo	.Ldownwards
+	add	tmp1, src, count
+	cmp	dstin, tmp1
+	b.hs	memcpy		/* No overlap.  */
+
+	/* Upwards move with potential overlap.
+	 * Need to move from the tail backwards.  SRC and DST point one
+	 * byte beyond the remaining data to move.  */
+	add	dst, dstin, count
+	add	src, src, count
+	cmp	count, #64
+	b.ge	.Lmov_not_short_up
+
+	/* Deal with small moves quickly by dropping straight into the
+	 * exit block.  */
+.Ltail63up:
+	/* Move up to 48 bytes of data.  At this point we only need the
+	 * bottom 6 bits of count to be accurate.  */
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15up
+	sub	dst, dst, tmp1
+	sub	src, src, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	ldp	A_l, A_h, [src, #32]
+	stp	A_l, A_h, [dst, #32]
+1:
+	ldp	A_l, A_h, [src, #16]
+	stp	A_l, A_h, [dst, #16]
+2:
+	ldp	A_l, A_h, [src]
+	stp	A_l, A_h, [dst]
+.Ltail15up:
+	/* Move up to 15 bytes of data.  Does not assume additional data
+	 * being moved.  */
+	tbz	count, #3, 1f
+	ldr	tmp1, [src, #-8]!
+	str	tmp1, [dst, #-8]!
+1:
+	tbz	count, #2, 1f
+	ldr	tmp1w, [src, #-4]!
+	str	tmp1w, [dst, #-4]!
+1:
+	tbz	count, #1, 1f
+	ldrh	tmp1w, [src, #-2]!
+	strh	tmp1w, [dst, #-2]!
+1:
+	tbz	count, #0, 1f
+	ldrb	tmp1w, [src, #-1]
+	strb	tmp1w, [dst, #-1]
+1:
+	ret
+
+.Lmov_not_short_up:
+	/* We don't much care about the alignment of DST, but we want SRC
+	 * to be 128-bit (16 byte) aligned so that we don't cross cache line
+	 * boundaries on both loads and stores.  */
+	ands	tmp2, src, #15		/* Bytes to reach alignment.  */
+	b.eq	2f
+	sub	count, count, tmp2
+	/* Move enough data to reach alignment; unlike memcpy, we have to
+	 * be aware of the overlap, which means we can't move data twice.  */
+	tbz	tmp2, #3, 1f
+	ldr	tmp1, [src, #-8]!
+	str	tmp1, [dst, #-8]!
+1:
+	tbz	tmp2, #2, 1f
+	ldr	tmp1w, [src, #-4]!
+	str	tmp1w, [dst, #-4]!
+1:
+	tbz	tmp2, #1, 1f
+	ldrh	tmp1w, [src, #-2]!
+	strh	tmp1w, [dst, #-2]!
+1:
+	tbz	tmp2, #0, 1f
+	ldrb	tmp1w, [src, #-1]!
+	strb	tmp1w, [dst, #-1]!
+1:
+
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #63
+	b.le	.Ltail63up
+2:
+	subs	count, count, #128
+	b.ge	.Lmov_body_large_up
+	/* Less than 128 bytes to move, so handle 64 here and then jump
+	 * to the tail.  */
+	ldp	A_l, A_h, [src, #-64]!
+	ldp	B_l, B_h, [src, #16]
+	ldp	C_l, C_h, [src, #32]
+	ldp	D_l, D_h, [src, #48]
+	stp	A_l, A_h, [dst, #-64]!
+	stp	B_l, B_h, [dst, #16]
+	stp	C_l, C_h, [dst, #32]
+	stp	D_l, D_h, [dst, #48]
+	tst	count, #0x3f
+	b.ne	.Ltail63up
+	ret
+
+	/* Critical loop.  Start at a new Icache line boundary.  Assuming
+	 * 64 bytes per line this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lmov_body_large_up:
+	/* There are at least 128 bytes to move.  */
+	ldp	A_l, A_h, [src, #-16]
+	ldp	B_l, B_h, [src, #-32]
+	ldp	C_l, C_h, [src, #-48]
+	ldp	D_l, D_h, [src, #-64]!
+1:
+	stp	A_l, A_h, [dst, #-16]
+	ldp	A_l, A_h, [src, #-16]
+	stp	B_l, B_h, [dst, #-32]
+	ldp	B_l, B_h, [src, #-32]
+	stp	C_l, C_h, [dst, #-48]
+	ldp	C_l, C_h, [src, #-48]
+	stp	D_l, D_h, [dst, #-64]!
+	ldp	D_l, D_h, [src, #-64]!
+	subs	count, count, #64
+	b.ge	1b
+	stp	A_l, A_h, [dst, #-16]
+	stp	B_l, B_h, [dst, #-32]
+	stp	C_l, C_h, [dst, #-48]
+	stp	D_l, D_h, [dst, #-64]!
+	tst	count, #0x3f
+	b.ne	.Ltail63up
+	ret
+
+
+.Ldownwards:
+	/* For a downwards move we can safely use memcpy provided that
+	 * DST is more than 16 bytes away from SRC.  */
+	sub	tmp1, src, #16
+	cmp	dstin, tmp1
+	b.ls	memcpy		/* May overlap, but not critically.  */
+
+	mov	dst, dstin	/* Preserve DSTIN for return value.  */
+	cmp	count, #64
+	b.ge	.Lmov_not_short_down
+
+	/* Deal with small moves quickly by dropping straight into the
+	 * exit block.  */
+.Ltail63down:
+	/* Move up to 48 bytes of data.  At this point we only need the
+	 * bottom 6 bits of count to be accurate.  */
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15down
+	add	dst, dst, tmp1
+	add	src, src, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	ldp	A_l, A_h, [src, #-48]
+	stp	A_l, A_h, [dst, #-48]
+1:
+	ldp	A_l, A_h, [src, #-32]
+	stp	A_l, A_h, [dst, #-32]
+2:
+	ldp	A_l, A_h, [src, #-16]
+	stp	A_l, A_h, [dst, #-16]
+.Ltail15down:
+	/* Move up to 15 bytes of data.  Does not assume additional data
+	   being moved.  */
+	tbz	count, #3, 1f
+	ldr	tmp1, [src], #8
+	str	tmp1, [dst], #8
+1:
+	tbz	count, #2, 1f
+	ldr	tmp1w, [src], #4
+	str	tmp1w, [dst], #4
+1:
+	tbz	count, #1, 1f
+	ldrh	tmp1w, [src], #2
+	strh	tmp1w, [dst], #2
+1:
+	tbz	count, #0, 1f
+	ldrb	tmp1w, [src]
+	strb	tmp1w, [dst]
+1:
+	ret
+
+.Lmov_not_short_down:
+	/* We don't much care about the alignment of DST, but we want SRC
+	 * to be 128-bit (16 byte) aligned so that we don't cross cache line
+	 * boundaries on both loads and stores.  */
+	neg	tmp2, src
+	ands	tmp2, tmp2, #15		/* Bytes to reach alignment.  */
+	b.eq	2f
+	sub	count, count, tmp2
+	/* Move enough data to reach alignment; unlike memcpy, we have to
+	 * be aware of the overlap, which means we can't move data twice.  */
+	tbz	tmp2, #3, 1f
+	ldr	tmp1, [src], #8
+	str	tmp1, [dst], #8
+1:
+	tbz	tmp2, #2, 1f
+	ldr	tmp1w, [src], #4
+	str	tmp1w, [dst], #4
+1:
+	tbz	tmp2, #1, 1f
+	ldrh	tmp1w, [src], #2
+	strh	tmp1w, [dst], #2
+1:
+	tbz	tmp2, #0, 1f
+	ldrb	tmp1w, [src], #1
+	strb	tmp1w, [dst], #1
+1:
+
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #63
+	b.le	.Ltail63down
+2:
+	subs	count, count, #128
+	b.ge	.Lmov_body_large_down
+	/* Less than 128 bytes to move, so handle 64 here and then jump
+	 * to the tail.  */
+	ldp	A_l, A_h, [src]
+	ldp	B_l, B_h, [src, #16]
+	ldp	C_l, C_h, [src, #32]
+	ldp	D_l, D_h, [src, #48]
+	stp	A_l, A_h, [dst]
+	stp	B_l, B_h, [dst, #16]
+	stp	C_l, C_h, [dst, #32]
+	stp	D_l, D_h, [dst, #48]
+	tst	count, #0x3f
+	add	src, src, #64
+	add	dst, dst, #64
+	b.ne	.Ltail63down
+	ret
+
+	/* Critical loop.  Start at a new cache line boundary.  Assuming
+	 * 64 bytes per line this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lmov_body_large_down:
+	/* There are at least 128 bytes to move.  */
+	ldp	A_l, A_h, [src, #0]
+	sub	dst, dst, #16		/* Pre-bias.  */
+	ldp	B_l, B_h, [src, #16]
+	ldp	C_l, C_h, [src, #32]
+	ldp	D_l, D_h, [src, #48]!	/* src += 64 - Pre-bias.  */
+1:
+	stp	A_l, A_h, [dst, #16]
+	ldp	A_l, A_h, [src, #16]
+	stp	B_l, B_h, [dst, #32]
+	ldp	B_l, B_h, [src, #32]
+	stp	C_l, C_h, [dst, #48]
+	ldp	C_l, C_h, [src, #48]
+	stp	D_l, D_h, [dst, #64]!
+	ldp	D_l, D_h, [src, #64]!
+	subs	count, count, #64
+	b.ge	1b
+	stp	A_l, A_h, [dst, #16]
+	stp	B_l, B_h, [dst, #32]
+	stp	C_l, C_h, [dst, #48]
+	stp	D_l, D_h, [dst, #64]
+	add	src, src, #16
+	add	dst, dst, #64 + 16
+	tst	count, #0x3f
+	b.ne	.Ltail63down
+	ret
+#ifdef BCOPY
+END(bcopy)
+#elif defined(WMEMMOVE)
+END(wmemmove)
+#else
+END(memmove)
+#endif
diff --git a/libc/arch-arm64/generic/bionic/memset.S b/libc/arch-arm64/generic/bionic/memset.S
new file mode 100644
index 0000000..7c204b4
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/memset.S
@@ -0,0 +1,247 @@
+/* Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ * Unaligned accesses
+ *
+ */
+
+#include <private/bionic_asm.h>
+
+/* By default we assume that the DC instruction can be used to zero
+   data blocks more efficiently.  In some circumstances this might be
+   unsafe, for example in an asymmetric multiprocessor environment with
+   different DC clear lengths (neither the upper nor lower lengths are
+   safe to use).
+
+   If code may be run in a virtualized environment, then define
+   MAYBE_VIRT.  This will cause the code to cache the system register
+   values rather than re-reading them each call.  */
+
+#define dstin		x0
+#ifdef BZERO
+#define count		x1
+#else
+#define count		x2
+#endif
+#define val		w1
+#define tmp1		x3
+#define tmp1w		w3
+#define tmp2		x4
+#define tmp2w		w4
+#define zva_len_x	x5
+#define zva_len		w5
+#define zva_bits_x	x6
+
+#define A_l		x7
+#define A_lw		w7
+#define dst		x8
+#define tmp3w		w9
+
+#ifdef BZERO
+ENTRY(bzero)
+#else
+ENTRY(memset)
+#endif
+
+	mov	dst, dstin		/* Preserve return value.  */
+#ifdef BZERO
+	b	.Lzero_mem
+#endif
+	ands	A_lw, val, #255
+	b.eq	.Lzero_mem
+	orr	A_lw, A_lw, A_lw, lsl #8
+	orr	A_lw, A_lw, A_lw, lsl #16
+	orr	A_l, A_l, A_l, lsl #32
+.Ltail_maybe_long:
+	cmp	count, #64
+	b.ge	.Lnot_short
+.Ltail_maybe_tiny:
+	cmp	count, #15
+	b.le	.Ltail15tiny
+.Ltail63:
+	ands	tmp1, count, #0x30
+	b.eq	.Ltail15
+	add	dst, dst, tmp1
+	cmp	tmp1w, #0x20
+	b.eq	1f
+	b.lt	2f
+	stp	A_l, A_l, [dst, #-48]
+1:
+	stp	A_l, A_l, [dst, #-32]
+2:
+	stp	A_l, A_l, [dst, #-16]
+
+.Ltail15:
+	and	count, count, #15
+	add	dst, dst, count
+	stp	A_l, A_l, [dst, #-16]	/* Repeat some/all of last store. */
+	ret
+
+.Ltail15tiny:
+	/* Set up to 15 bytes.  Does not assume earlier memory
+	   being set.  */
+	tbz	count, #3, 1f
+	str	A_l, [dst], #8
+1:
+	tbz	count, #2, 1f
+	str	A_lw, [dst], #4
+1:
+	tbz	count, #1, 1f
+	strh	A_lw, [dst], #2
+1:
+	tbz	count, #0, 1f
+	strb	A_lw, [dst]
+1:
+	ret
+
+	/* Critical loop.  Start at a new cache line boundary.  Assuming
+	 * 64 bytes per line, this ensures the entire loop is in one line.  */
+	.p2align 6
+.Lnot_short:
+	neg	tmp2, dst
+	ands	tmp2, tmp2, #15
+	b.eq	2f
+	/* Bring DST to 128-bit (16-byte) alignment.  We know that there's
+	 * more than that to set, so we simply store 16 bytes and advance by
+	 * the amount required to reach alignment.  */
+	sub	count, count, tmp2
+	stp	A_l, A_l, [dst]
+	add	dst, dst, tmp2
+	/* There may be less than 63 bytes to go now.  */
+	cmp	count, #63
+	b.le	.Ltail63
+2:
+	sub	dst, dst, #16		/* Pre-bias.  */
+	sub	count, count, #64
+1:
+	stp	A_l, A_l, [dst, #16]
+	stp	A_l, A_l, [dst, #32]
+	stp	A_l, A_l, [dst, #48]
+	stp	A_l, A_l, [dst, #64]!
+	subs	count, count, #64
+	b.ge	1b
+	tst	count, #0x3f
+	add	dst, dst, #16
+	b.ne	.Ltail63
+	ret
+
+	/* For zeroing memory, check to see if we can use the ZVA feature to
+	 * zero entire 'cache' lines.  */
+.Lzero_mem:
+	mov	A_l, #0
+	cmp	count, #63
+	b.le	.Ltail_maybe_tiny
+	neg	tmp2, dst
+	ands	tmp2, tmp2, #15
+	b.eq	1f
+	sub	count, count, tmp2
+	stp	A_l, A_l, [dst]
+	add	dst, dst, tmp2
+	cmp	count, #63
+	b.le	.Ltail63
+1:
+	/* For zeroing small amounts of memory, it's not worth setting up
+	 * the line-clear code.  */
+	cmp	count, #128
+	b.lt	.Lnot_short
+#ifdef MAYBE_VIRT
+	/* For efficiency when virtualized, we cache the ZVA capability.  */
+	adrp	tmp2, .Lcache_clear
+	ldr	zva_len, [tmp2, #:lo12:.Lcache_clear]
+	tbnz	zva_len, #31, .Lnot_short
+	cbnz	zva_len, .Lzero_by_line
+	mrs	tmp1, dczid_el0
+	tbz	tmp1, #4, 1f
+	/* ZVA not available.  Remember this for next time.  */
+	mov	zva_len, #~0
+	str	zva_len, [tmp2, #:lo12:.Lcache_clear]
+	b	.Lnot_short
+1:
+	mov	tmp3w, #4
+	and	zva_len, tmp1w, #15	/* Safety: other bits reserved.  */
+	lsl	zva_len, tmp3w, zva_len
+	str	zva_len, [tmp2, #:lo12:.Lcache_clear]
+#else
+	mrs	tmp1, dczid_el0
+	tbnz	tmp1, #4, .Lnot_short
+	mov	tmp3w, #4
+	and	zva_len, tmp1w, #15	/* Safety: other bits reserved.  */
+	lsl	zva_len, tmp3w, zva_len
+#endif
+
+.Lzero_by_line:
+	/* Compute how far we need to go to become suitably aligned.  We're
+	 * already at quad-word alignment.  */
+	cmp	count, zva_len_x
+	b.lt	.Lnot_short		/* Not enough to reach alignment.  */
+	sub	zva_bits_x, zva_len_x, #1
+	neg	tmp2, dst
+	ands	tmp2, tmp2, zva_bits_x
+	b.eq	1f			/* Already aligned.  */
+	/* Not aligned, check that there's enough to copy after alignment.  */
+	sub	tmp1, count, tmp2
+	cmp	tmp1, #64
+	ccmp	tmp1, zva_len_x, #8, ge	/* NZCV=0b1000 */
+	b.lt	.Lnot_short
+	/* We know that there's at least 64 bytes to zero and that it's safe
+	 * to overrun by 64 bytes.  */
+	mov	count, tmp1
+2:
+	stp	A_l, A_l, [dst]
+	stp	A_l, A_l, [dst, #16]
+	stp	A_l, A_l, [dst, #32]
+	subs	tmp2, tmp2, #64
+	stp	A_l, A_l, [dst, #48]
+	add	dst, dst, #64
+	b.ge	2b
+	/* We've overrun a bit, so adjust dst downwards.  */
+	add	dst, dst, tmp2
+1:
+	sub	count, count, zva_len_x
+3:
+	dc	zva, dst
+	add	dst, dst, zva_len_x
+	subs	count, count, zva_len_x
+	b.ge	3b
+	ands	count, count, zva_bits_x
+	b.ne	.Ltail_maybe_long
+	ret
+#ifdef BZERO
+END(bzero)
+#else
+END(memset)
+#endif
+
+#ifdef MAYBE_VIRT
+	.bss
+	.p2align 2
+.Lcache_clear:
+	.space 4
+#endif
diff --git a/libc/arch-arm64/generic/bionic/stpcpy.S b/libc/arch-arm64/generic/bionic/stpcpy.S
new file mode 100644
index 0000000..e4a7993
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/stpcpy.S
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#define STPCPY
+#include "string_copy.S"
diff --git a/libc/arch-arm64/generic/bionic/strchr.S b/libc/arch-arm64/generic/bionic/strchr.S
new file mode 100644
index 0000000..469b83c
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/strchr.S
@@ -0,0 +1,154 @@
+/*
+   strchr - find a character in a string
+
+   Copyright (c) 2014, ARM Limited
+   All rights Reserved.
+   Copyright (c) 2014, Linaro Ltd.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the company nor the names of its contributors
+         may be used to endorse or promote products derived from this
+         software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ * Neon Available.
+ */
+
+#include <private/bionic_asm.h>
+
+/* Arguments and results.  */
+#define srcin		x0
+#define chrin		w1
+
+#define result		x0
+
+#define src		x2
+#define	tmp1		x3
+#define wtmp2		w4
+#define tmp3		x5
+
+#define vrepchr		v0
+#define vdata1		v1
+#define vdata2		v2
+#define vhas_nul1	v3
+#define vhas_nul2	v4
+#define vhas_chr1	v5
+#define vhas_chr2	v6
+#define vrepmask_0	v7
+#define vrepmask_c	v16
+#define vend1		v17
+#define vend2		v18
+
+/* Core algorithm.
+
+   For each 32-byte hunk we calculate a 64-bit syndrome value, with
+   two bits per byte (LSB is always in bits 0 and 1, for both big
+   and little-endian systems).  For each tuple, bit 0 is set iff
+   the relevant byte matched the requested character; bit 1 is set
+   iff the relevant byte matched the NUL end of string (we trigger
+   off bit0 for the special case of looking for NUL).  Since the bits
+   in the syndrome reflect exactly the order in which things occur
+   in the original string a count_trailing_zeros() operation will
+   identify exactly which byte is causing the termination, and why.  */
+
+/* Locals and temporaries.  */
+
+ENTRY(strchr)
+	/* Magic constant 0x40100401 to allow us to identify which lane
+	   matches the requested byte.  Magic constant 0x80200802 used
+	   similarly for NUL termination.  */
+	mov	wtmp2, #0x0401
+	movk	wtmp2, #0x4010, lsl #16
+	dup	vrepchr.16b, chrin
+	bic	src, srcin, #31		/* Work with aligned 32-byte hunks.  */
+	dup	vrepmask_c.4s, wtmp2
+	ands	tmp1, srcin, #31
+	add	vrepmask_0.4s, vrepmask_c.4s, vrepmask_c.4s /* equiv: lsl #1 */
+	b.eq	.Lloop
+
+	/* Input string is not 32-byte aligned.  Rather than forcing
+	   the padding bytes to a safe value, we calculate the syndrome
+	   for all the bytes, but then mask off those bits of the
+	   syndrome that are related to the padding.  */
+	ld1	{vdata1.16b, vdata2.16b}, [src], #32
+	neg	tmp1, tmp1
+	cmeq	vhas_nul1.16b, vdata1.16b, #0
+	cmeq	vhas_chr1.16b, vdata1.16b, vrepchr.16b
+	cmeq	vhas_nul2.16b, vdata2.16b, #0
+	cmeq	vhas_chr2.16b, vdata2.16b, vrepchr.16b
+	and	vhas_nul1.16b, vhas_nul1.16b, vrepmask_0.16b
+	and	vhas_nul2.16b, vhas_nul2.16b, vrepmask_0.16b
+	and	vhas_chr1.16b, vhas_chr1.16b, vrepmask_c.16b
+	and	vhas_chr2.16b, vhas_chr2.16b, vrepmask_c.16b
+	orr	vend1.16b, vhas_nul1.16b, vhas_chr1.16b
+	orr	vend2.16b, vhas_nul2.16b, vhas_chr2.16b
+	lsl	tmp1, tmp1, #1
+	addp	vend1.16b, vend1.16b, vend2.16b		// 256->128
+	mov	tmp3, #~0
+	addp	vend1.16b, vend1.16b, vend2.16b		// 128->64
+	lsr	tmp1, tmp3, tmp1
+
+	mov	tmp3, vend1.2d[0]
+	bic	tmp1, tmp3, tmp1	// Mask padding bits.
+	cbnz	tmp1, .Ltail
+
+.Lloop:
+	ld1	{vdata1.16b, vdata2.16b}, [src], #32
+	cmeq	vhas_nul1.16b, vdata1.16b, #0
+	cmeq	vhas_chr1.16b, vdata1.16b, vrepchr.16b
+	cmeq	vhas_nul2.16b, vdata2.16b, #0
+	cmeq	vhas_chr2.16b, vdata2.16b, vrepchr.16b
+	/* Use a fast check for the termination condition.  */
+	orr	vend1.16b, vhas_nul1.16b, vhas_chr1.16b
+	orr	vend2.16b, vhas_nul2.16b, vhas_chr2.16b
+	orr	vend1.16b, vend1.16b, vend2.16b
+	addp	vend1.2d, vend1.2d, vend1.2d
+	mov	tmp1, vend1.2d[0]
+	cbz	tmp1, .Lloop
+
+	/* Termination condition found.  Now need to establish exactly why
+	   we terminated.  */
+	and	vhas_nul1.16b, vhas_nul1.16b, vrepmask_0.16b
+	and	vhas_nul2.16b, vhas_nul2.16b, vrepmask_0.16b
+	and	vhas_chr1.16b, vhas_chr1.16b, vrepmask_c.16b
+	and	vhas_chr2.16b, vhas_chr2.16b, vrepmask_c.16b
+	orr	vend1.16b, vhas_nul1.16b, vhas_chr1.16b
+	orr	vend2.16b, vhas_nul2.16b, vhas_chr2.16b
+	addp	vend1.16b, vend1.16b, vend2.16b		// 256->128
+	addp	vend1.16b, vend1.16b, vend2.16b		// 128->64
+
+	mov	tmp1, vend1.2d[0]
+.Ltail:
+	/* Count the trailing zeros, by bit reversing...  */
+	rbit	tmp1, tmp1
+	/* Re-bias source.  */
+	sub	src, src, #32
+	clz	tmp1, tmp1	/* And counting the leading zeros.  */
+	/* Tmp1 is even if the target charager was found first.  Otherwise
+	   we've found the end of string and we weren't looking for NUL.  */
+	tst	tmp1, #1
+	add	result, src, tmp1, lsr #1
+	csel	result, result, xzr, eq
+	ret
+END(strchr)
diff --git a/libc/arch-arm64/generic/bionic/strcmp.S b/libc/arch-arm64/generic/bionic/strcmp.S
new file mode 100644
index 0000000..3cce478
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/strcmp.S
@@ -0,0 +1,162 @@
+/* Copyright (c) 2012, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ */
+
+#include <private/bionic_asm.h>
+
+#define REP8_01 0x0101010101010101
+#define REP8_7f 0x7f7f7f7f7f7f7f7f
+#define REP8_80 0x8080808080808080
+
+/* Parameters and result.  */
+#define src1		x0
+#define src2		x1
+#define result		x0
+
+/* Internal variables.  */
+#define data1		x2
+#define data1w		w2
+#define data2		x3
+#define data2w		w3
+#define has_nul		x4
+#define diff		x5
+#define syndrome	x6
+#define tmp1		x7
+#define tmp2		x8
+#define tmp3		x9
+#define zeroones	x10
+#define pos		x11
+
+	/* Start of performance-critical section  -- one 64B cache line.  */
+ENTRY(strcmp)
+	eor	tmp1, src1, src2
+	mov	zeroones, #REP8_01
+	tst	tmp1, #7
+	b.ne	.Lmisaligned8
+	ands	tmp1, src1, #7
+	b.ne	.Lmutual_align
+	/* NUL detection works on the principle that (X - 1) & (~X) & 0x80
+	   (=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and
+	   can be done in parallel across the entire word.  */
+.Lloop_aligned:
+	ldr	data1, [src1], #8
+	ldr	data2, [src2], #8
+.Lstart_realigned:
+	sub	tmp1, data1, zeroones
+	orr	tmp2, data1, #REP8_7f
+	eor	diff, data1, data2	/* Non-zero if differences found.  */
+	bic	has_nul, tmp1, tmp2	/* Non-zero if NUL terminator.  */
+	orr	syndrome, diff, has_nul
+	cbz	syndrome, .Lloop_aligned
+	/* End of performance-critical section  -- one 64B cache line.  */
+
+#ifndef	__AARCH64EB__
+	rev	syndrome, syndrome
+	rev	data1, data1
+	/* The MS-non-zero bit of the syndrome marks either the first bit
+	   that is different, or the top bit of the first zero byte.
+	   Shifting left now will bring the critical information into the
+	   top bits.  */
+	clz	pos, syndrome
+	rev	data2, data2
+	lsl	data1, data1, pos
+	lsl	data2, data2, pos
+	/* But we need to zero-extend (char is unsigned) the value and then
+	   perform a signed 32-bit subtraction.  */
+	lsr	data1, data1, #56
+	sub	result, data1, data2, lsr #56
+	ret
+#else
+	/* For big-endian we cannot use the trick with the syndrome value
+	   as carry-propagation can corrupt the upper bits if the trailing
+	   bytes in the string contain 0x01.  */
+	/* However, if there is no NUL byte in the dword, we can generate
+	   the result directly.  We can't just subtract the bytes as the
+	   MSB might be significant.  */
+	cbnz	has_nul, 1f
+	cmp	data1, data2
+	cset	result, ne
+	cneg	result, result, lo
+	ret
+1:
+	/* Re-compute the NUL-byte detection, using a byte-reversed value.  */
+	rev	tmp3, data1
+	sub	tmp1, tmp3, zeroones
+	orr	tmp2, tmp3, #REP8_7f
+	bic	has_nul, tmp1, tmp2
+	rev	has_nul, has_nul
+	orr	syndrome, diff, has_nul
+	clz	pos, syndrome
+	/* The MS-non-zero bit of the syndrome marks either the first bit
+	   that is different, or the top bit of the first zero byte.
+	   Shifting left now will bring the critical information into the
+	   top bits.  */
+	lsl	data1, data1, pos
+	lsl	data2, data2, pos
+	/* But we need to zero-extend (char is unsigned) the value and then
+	   perform a signed 32-bit subtraction.  */
+	lsr	data1, data1, #56
+	sub	result, data1, data2, lsr #56
+	ret
+#endif
+
+.Lmutual_align:
+	/* Sources are mutually aligned, but are not currently at an
+	   alignment boundary.  Round down the addresses and then mask off
+	   the bytes that preceed the start point.  */
+	bic	src1, src1, #7
+	bic	src2, src2, #7
+	lsl	tmp1, tmp1, #3		/* Bytes beyond alignment -> bits.  */
+	ldr	data1, [src1], #8
+	neg	tmp1, tmp1		/* Bits to alignment -64.  */
+	ldr	data2, [src2], #8
+	mov	tmp2, #~0
+#ifdef __AARCH64EB__
+	/* Big-endian.  Early bytes are at MSB.  */
+	lsl	tmp2, tmp2, tmp1	/* Shift (tmp1 & 63).  */
+#else
+	/* Little-endian.  Early bytes are at LSB.  */
+	lsr	tmp2, tmp2, tmp1	/* Shift (tmp1 & 63).  */
+#endif
+	orr	data1, data1, tmp2
+	orr	data2, data2, tmp2
+	b	.Lstart_realigned
+
+.Lmisaligned8:
+	/* We can do better than this.  */
+	ldrb	data1w, [src1], #1
+	ldrb	data2w, [src2], #1
+	cmp	data1w, #1
+	ccmp	data1w, data2w, #0, cs	/* NZCV = 0b0000.  */
+	b.eq	.Lmisaligned8
+	sub	result, data1, data2
+	ret
+END(strcmp)
diff --git a/libc/arch-arm64/generic/bionic/strcpy.S b/libc/arch-arm64/generic/bionic/strcpy.S
new file mode 100644
index 0000000..260c321
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/strcpy.S
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#define STRCPY
+#include "string_copy.S"
diff --git a/libc/arch-arm64/generic/bionic/string_copy.S b/libc/arch-arm64/generic/bionic/string_copy.S
new file mode 100644
index 0000000..2bf969d
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/string_copy.S
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+   Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ */
+
+#if !defined(STPCPY) && !defined(STRCPY)
+#error "Either STPCPY or STRCPY must be defined."
+#endif
+
+#include <private/bionic_asm.h>
+
+/* Arguments and results.  */
+#if defined(STPCPY)
+#define dst         x0
+#elif defined(STRCPY)
+#define dstin       x0
+#endif
+#define src         x1
+
+/* Locals and temporaries.  */
+#if defined(STRCPY)
+#define dst         x2
+#endif
+#define data1       x3
+#define data1_w     w3
+#define data2       x4
+#define data2_w     w4
+#define has_nul1    x5
+#define has_nul1_w  w5
+#define has_nul2    x6
+#define tmp1        x7
+#define tmp2        x8
+#define tmp3        x9
+#define tmp4        x10
+#define zeroones    x11
+#define zeroones_w  w11
+#define pos         x12
+
+#define REP8_01 0x0101010101010101
+#define REP8_7f 0x7f7f7f7f7f7f7f7f
+#define REP8_80 0x8080808080808080
+
+#if defined(STPCPY)
+ENTRY(stpcpy)
+#elif defined(STRCPY)
+ENTRY(strcpy)
+#endif
+    mov     zeroones, #REP8_01
+#if defined(STRCPY)
+    mov     dst, dstin
+#endif
+    ands    tmp1, src, #15
+    b.ne    .Lmisaligned
+    // NUL detection works on the principle that (X - 1) & (~X) & 0x80
+    // (=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and
+    // can be done in parallel across the entire word.
+    // The inner loop deals with two Dwords at a time.  This has a
+    // slightly higher start-up cost, but we should win quite quickly,
+    // especially on cores with a high number of issue slots per
+    // cycle, as we get much better parallelism out of the operations.
+.Lloop:
+    ldp     data1, data2, [src], #16
+    sub     tmp1, data1, zeroones
+    orr     tmp2, data1, #REP8_7f
+    bic     has_nul1, tmp1, tmp2
+    cbnz    has_nul1, .Lnul_in_data1
+    sub     tmp3, data2, zeroones
+    orr     tmp4, data2, #REP8_7f
+    bic     has_nul2, tmp3, tmp4
+    cbnz    has_nul2, .Lnul_in_data2
+    // No NUL in either register, copy it in a single instruction.
+    stp     data1, data2, [dst], #16
+    b       .Lloop
+
+.Lnul_in_data1:
+    rev     has_nul1, has_nul1
+    clz     pos, has_nul1
+    add     tmp1, pos, #0x8
+
+    tbz     tmp1, #6, 1f
+#if defined(STPCPY)
+    str     data1, [dst], #7
+#elif defined(STRCPY)
+    str     data1, [dst]
+#endif
+    ret
+1:
+    tbz     tmp1, #5, 1f
+    str     data1_w, [dst], #4
+    lsr     data1, data1, #32
+1:
+    tbz     tmp1, #4, 1f
+    strh    data1_w, [dst], #2
+    lsr     data1, data1, #16
+1:
+    tbz     tmp1, #3, 1f
+    strb    data1_w, [dst]
+#if defined(STPCPY)
+    ret
+#endif
+1:
+#if defined(STPCPY)
+    // Back up one so that dst points to the '\0' string terminator.
+    sub     dst, dst, #1
+#endif
+    ret
+
+.Lnul_in_data2:
+    str     data1, [dst], #8
+    rev     has_nul2, has_nul2
+    clz     pos, has_nul2
+    add     tmp1, pos, #0x8
+
+    tbz     tmp1, #6, 1f
+#if defined(STPCPY)
+    str     data2, [dst], #7
+#elif defined(STRCPY)
+    str     data2, [dst]
+#endif
+    ret
+1:
+    tbz     tmp1, #5, 1f
+    str     data2_w, [dst], #4
+    lsr     data2, data2, #32
+1:
+    tbz     tmp1, #4, 1f
+    strh    data2_w, [dst], #2
+    lsr     data2, data2, #16
+1:
+    tbz     tmp1, #3, 1f
+    strb    data2_w, [dst]
+#if defined(STPCPY)
+    ret
+#endif
+1:
+#if defined(STPCPY)
+    // Back up one so that dst points to the '\0' string terminator.
+    sub     dst, dst, #1
+#endif
+    ret
+
+.Lmisaligned:
+    tbz     src, #0, 1f
+    ldrb    data1_w, [src], #1
+    strb    data1_w, [dst], #1
+    cbnz    data1_w, 1f
+#if defined(STPCPY)
+    // Back up one so that dst points to the '\0' string terminator.
+    sub     dst, dst, #1
+#endif
+    ret
+1:
+    tbz     src, #1, 1f
+    ldrb    data1_w, [src], #1
+    strb    data1_w, [dst], #1
+    cbz     data1_w, .Ldone
+    ldrb    data2_w, [src], #1
+    strb    data2_w, [dst], #1
+    cbnz    data2_w, 1f
+.Ldone:
+#if defined(STPCPY)
+    // Back up one so that dst points to the '\0' string terminator.
+    sub     dst, dst, #1
+#endif
+    ret
+1:
+    tbz     src, #2, 1f
+    ldr     data1_w, [src], #4
+    // Check for a zero.
+    sub     has_nul1_w, data1_w, zeroones_w
+    bic     has_nul1_w, has_nul1_w, data1_w
+    ands    has_nul1_w, has_nul1_w, #0x80808080
+    b.ne    .Lnul_in_data1
+    str     data1_w, [dst], #4
+1:
+    tbz     src, #3, .Lloop
+    ldr     data1, [src], #8
+    // Check for a zero.
+    sub     tmp1, data1, zeroones
+    orr     tmp2, data1, #REP8_7f
+    bics    has_nul1, tmp1, tmp2
+    b.ne    .Lnul_in_data1
+    str     data1, [dst], #8
+    b       .Lloop
+#if defined(STPCPY)
+END(stpcpy)
+#elif defined(STRCPY)
+END(strcpy)
+#endif
diff --git a/libc/arch-arm64/generic/bionic/strlen.S b/libc/arch-arm64/generic/bionic/strlen.S
new file mode 100644
index 0000000..3bd9809
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/strlen.S
@@ -0,0 +1,126 @@
+/* Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ */
+
+#include <private/bionic_asm.h>
+
+/* Arguments and results.  */
+#define srcin		x0
+#define len		x0
+
+/* Locals and temporaries.  */
+#define src		x1
+#define data1		x2
+#define data2		x3
+#define data2a		x4
+#define has_nul1	x5
+#define has_nul2	x6
+#define tmp1		x7
+#define tmp2		x8
+#define tmp3		x9
+#define tmp4		x10
+#define zeroones	x11
+#define pos		x12
+
+#define REP8_01 0x0101010101010101
+#define REP8_7f 0x7f7f7f7f7f7f7f7f
+#define REP8_80 0x8080808080808080
+
+	/* Start of critial section -- keep to one 64Byte cache line.  */
+ENTRY(strlen)
+	mov	zeroones, #REP8_01
+	bic	src, srcin, #15
+	ands	tmp1, srcin, #15
+	b.ne	.Lmisaligned
+	/* NUL detection works on the principle that (X - 1) & (~X) & 0x80
+	   (=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and
+	   can be done in parallel across the entire word.  */
+	/* The inner loop deals with two Dwords at a time.  This has a
+	   slightly higher start-up cost, but we should win quite quickly,
+	   especially on cores with a high number of issue slots per
+	   cycle, as we get much better parallelism out of the operations.  */
+.Lloop:
+	ldp	data1, data2, [src], #16
+.Lrealigned:
+	sub	tmp1, data1, zeroones
+	orr	tmp2, data1, #REP8_7f
+	sub	tmp3, data2, zeroones
+	orr	tmp4, data2, #REP8_7f
+	bic	has_nul1, tmp1, tmp2
+	bics	has_nul2, tmp3, tmp4
+	ccmp	has_nul1, #0, #0, eq	/* NZCV = 0000  */
+	b.eq	.Lloop
+	/* End of critical section -- keep to one 64Byte cache line.  */
+
+	sub	len, src, srcin
+	cbz	has_nul1, .Lnul_in_data2
+#ifdef __AARCH64EB__
+	mov	data2, data1
+#endif
+	sub	len, len, #8
+	mov	has_nul2, has_nul1
+.Lnul_in_data2:
+#ifdef __AARCH64EB__
+	/* For big-endian, carry propagation (if the final byte in the
+	   string is 0x01) means we cannot use has_nul directly.  The
+	   easiest way to get the correct byte is to byte-swap the data
+	   and calculate the syndrome a second time.  */
+	rev	data2, data2
+	sub	tmp1, data2, zeroones
+	orr	tmp2, data2, #REP8_7f
+	bic	has_nul2, tmp1, tmp2
+#endif
+	sub	len, len, #8
+	rev	has_nul2, has_nul2
+	clz	pos, has_nul2
+	add	len, len, pos, lsr #3		/* Bits to bytes.  */
+	ret
+
+.Lmisaligned:
+	cmp	tmp1, #8
+	neg	tmp1, tmp1
+	ldp	data1, data2, [src], #16
+	lsl	tmp1, tmp1, #3		/* Bytes beyond alignment -> bits.  */
+	mov	tmp2, #~0
+#ifdef __AARCH64EB__
+	/* Big-endian.  Early bytes are at MSB.  */
+	lsl	tmp2, tmp2, tmp1	/* Shift (tmp1 & 63).  */
+#else
+	/* Little-endian.  Early bytes are at LSB.  */
+	lsr	tmp2, tmp2, tmp1	/* Shift (tmp1 & 63).  */
+#endif
+	orr	data1, data1, tmp2
+	orr	data2a, data2, tmp2
+	csinv	data1, data1, xzr, le
+	csel	data2, data2, data2a, le
+	b	.Lrealigned
+
+END(strlen)
diff --git a/libc/arch-arm64/generic/bionic/strncmp.S b/libc/arch-arm64/generic/bionic/strncmp.S
new file mode 100644
index 0000000..267f663
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/strncmp.S
@@ -0,0 +1,217 @@
+/* Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ */
+
+#include <private/bionic_asm.h>
+
+#define REP8_01 0x0101010101010101
+#define REP8_7f 0x7f7f7f7f7f7f7f7f
+#define REP8_80 0x8080808080808080
+
+/* Parameters and result.  */
+#define src1		x0
+#define src2		x1
+#define limit		x2
+#define result		x0
+
+/* Internal variables.  */
+#define data1		x3
+#define data1w		w3
+#define data2		x4
+#define data2w		w4
+#define has_nul		x5
+#define diff		x6
+#define syndrome	x7
+#define tmp1		x8
+#define tmp2		x9
+#define tmp3		x10
+#define zeroones	x11
+#define pos		x12
+#define limit_wd	x13
+#define mask		x14
+#define endloop		x15
+
+	.text
+	.p2align 6
+	.rep 7
+	nop	/* Pad so that the loop below fits a cache line.  */
+	.endr
+ENTRY(strncmp)
+	cbz	limit, .Lret0
+	eor	tmp1, src1, src2
+	mov	zeroones, #REP8_01
+	tst	tmp1, #7
+	b.ne	.Lmisaligned8
+	ands	tmp1, src1, #7
+	b.ne	.Lmutual_align
+	/* Calculate the number of full and partial words -1.  */
+	sub	limit_wd, limit, #1	/* limit != 0, so no underflow.  */
+	lsr	limit_wd, limit_wd, #3	/* Convert to Dwords.  */
+
+	/* NUL detection works on the principle that (X - 1) & (~X) & 0x80
+	   (=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and
+	   can be done in parallel across the entire word.  */
+	/* Start of performance-critical section  -- one 64B cache line.  */
+.Lloop_aligned:
+	ldr	data1, [src1], #8
+	ldr	data2, [src2], #8
+.Lstart_realigned:
+	subs	limit_wd, limit_wd, #1
+	sub	tmp1, data1, zeroones
+	orr	tmp2, data1, #REP8_7f
+	eor	diff, data1, data2	/* Non-zero if differences found.  */
+	csinv	endloop, diff, xzr, pl	/* Last Dword or differences.  */
+	bics	has_nul, tmp1, tmp2	/* Non-zero if NUL terminator.  */
+	ccmp	endloop, #0, #0, eq
+	b.eq	.Lloop_aligned
+	/* End of performance-critical section  -- one 64B cache line.  */
+
+	/* Not reached the limit, must have found the end or a diff.  */
+	tbz	limit_wd, #63, .Lnot_limit
+
+	/* Limit % 8 == 0 => all bytes significant.  */
+	ands	limit, limit, #7
+	b.eq	.Lnot_limit
+
+	lsl	limit, limit, #3	/* Bits -> bytes.  */
+	mov	mask, #~0
+#ifdef __AARCH64EB__
+	lsr	mask, mask, limit
+#else
+	lsl	mask, mask, limit
+#endif
+	bic	data1, data1, mask
+	bic	data2, data2, mask
+
+	/* Make sure that the NUL byte is marked in the syndrome.  */
+	orr	has_nul, has_nul, mask
+
+.Lnot_limit:
+	orr	syndrome, diff, has_nul
+
+#ifndef	__AARCH64EB__
+	rev	syndrome, syndrome
+	rev	data1, data1
+	/* The MS-non-zero bit of the syndrome marks either the first bit
+	   that is different, or the top bit of the first zero byte.
+	   Shifting left now will bring the critical information into the
+	   top bits.  */
+	clz	pos, syndrome
+	rev	data2, data2
+	lsl	data1, data1, pos
+	lsl	data2, data2, pos
+	/* But we need to zero-extend (char is unsigned) the value and then
+	   perform a signed 32-bit subtraction.  */
+	lsr	data1, data1, #56
+	sub	result, data1, data2, lsr #56
+	ret
+#else
+	/* For big-endian we cannot use the trick with the syndrome value
+	   as carry-propagation can corrupt the upper bits if the trailing
+	   bytes in the string contain 0x01.  */
+	/* However, if there is no NUL byte in the dword, we can generate
+	   the result directly.  We can't just subtract the bytes as the
+	   MSB might be significant.  */
+	cbnz	has_nul, 1f
+	cmp	data1, data2
+	cset	result, ne
+	cneg	result, result, lo
+	ret
+1:
+	/* Re-compute the NUL-byte detection, using a byte-reversed value.  */
+	rev	tmp3, data1
+	sub	tmp1, tmp3, zeroones
+	orr	tmp2, tmp3, #REP8_7f
+	bic	has_nul, tmp1, tmp2
+	rev	has_nul, has_nul
+	orr	syndrome, diff, has_nul
+	clz	pos, syndrome
+	/* The MS-non-zero bit of the syndrome marks either the first bit
+	   that is different, or the top bit of the first zero byte.
+	   Shifting left now will bring the critical information into the
+	   top bits.  */
+	lsl	data1, data1, pos
+	lsl	data2, data2, pos
+	/* But we need to zero-extend (char is unsigned) the value and then
+	   perform a signed 32-bit subtraction.  */
+	lsr	data1, data1, #56
+	sub	result, data1, data2, lsr #56
+	ret
+#endif
+
+.Lmutual_align:
+	/* Sources are mutually aligned, but are not currently at an
+	   alignment boundary.  Round down the addresses and then mask off
+	   the bytes that precede the start point.
+	   We also need to adjust the limit calculations, but without
+	   overflowing if the limit is near ULONG_MAX.  */
+	bic	src1, src1, #7
+	bic	src2, src2, #7
+	ldr	data1, [src1], #8
+	neg	tmp3, tmp1, lsl #3	/* 64 - bits(bytes beyond align). */
+	ldr	data2, [src2], #8
+	mov	tmp2, #~0
+	sub	limit_wd, limit, #1	/* limit != 0, so no underflow.  */
+#ifdef __AARCH64EB__
+	/* Big-endian.  Early bytes are at MSB.  */
+	lsl	tmp2, tmp2, tmp3	/* Shift (tmp1 & 63).  */
+#else
+	/* Little-endian.  Early bytes are at LSB.  */
+	lsr	tmp2, tmp2, tmp3	/* Shift (tmp1 & 63).  */
+#endif
+	and	tmp3, limit_wd, #7
+	lsr	limit_wd, limit_wd, #3
+	/* Adjust the limit. Only low 3 bits used, so overflow irrelevant.  */
+	add	limit, limit, tmp1
+	add	tmp3, tmp3, tmp1
+	orr	data1, data1, tmp2
+	orr	data2, data2, tmp2
+	add	limit_wd, limit_wd, tmp3, lsr #3
+	b	.Lstart_realigned
+
+.Lret0:
+	mov	result, #0
+	ret
+
+	.p2align 6
+.Lmisaligned8:
+	sub	limit, limit, #1
+1:
+	/* Perhaps we can do better than this.  */
+	ldrb	data1w, [src1], #1
+	ldrb	data2w, [src2], #1
+	subs	limit, limit, #1
+	ccmp	data1w, #1, #0, cs	/* NZCV = 0b0000.  */
+	ccmp	data1w, data2w, #0, cs	/* NZCV = 0b0000.  */
+	b.eq	1b
+	sub	result, data1, data2
+	ret
+END(strncmp)
diff --git a/libc/arch-arm64/generic/bionic/strnlen.S b/libc/arch-arm64/generic/bionic/strnlen.S
new file mode 100644
index 0000000..0ad446e
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/strnlen.S
@@ -0,0 +1,174 @@
+/* Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64
+ */
+
+#include <private/bionic_asm.h>
+
+/* Arguments and results.  */
+#define srcin		x0
+#define len		x0
+#define limit		x1
+
+/* Locals and temporaries.  */
+#define src		x2
+#define data1		x3
+#define data2		x4
+#define data2a		x5
+#define has_nul1	x6
+#define has_nul2	x7
+#define tmp1		x8
+#define tmp2		x9
+#define tmp3		x10
+#define tmp4		x11
+#define zeroones	x12
+#define pos		x13
+#define limit_wd	x14
+
+#define REP8_01 0x0101010101010101
+#define REP8_7f 0x7f7f7f7f7f7f7f7f
+#define REP8_80 0x8080808080808080
+
+	.text
+	.p2align	6
+.Lstart:
+	/* Pre-pad to ensure critical loop begins an icache line.  */
+	.rep 7
+	nop
+	.endr
+	/* Put this code here to avoid wasting more space with pre-padding.  */
+.Lhit_limit:
+	mov	len, limit
+	ret
+
+ENTRY(strnlen)
+	cbz	limit, .Lhit_limit
+	mov	zeroones, #REP8_01
+	bic	src, srcin, #15
+	ands	tmp1, srcin, #15
+	b.ne	.Lmisaligned
+	/* Calculate the number of full and partial words -1.  */
+	sub	limit_wd, limit, #1	/* Limit != 0, so no underflow.  */
+	lsr	limit_wd, limit_wd, #4	/* Convert to Qwords.  */
+
+	/* NUL detection works on the principle that (X - 1) & (~X) & 0x80
+	   (=> (X - 1) & ~(X | 0x7f)) is non-zero iff a byte is zero, and
+	   can be done in parallel across the entire word.  */
+	/* The inner loop deals with two Dwords at a time.  This has a
+	   slightly higher start-up cost, but we should win quite quickly,
+	   especially on cores with a high number of issue slots per
+	   cycle, as we get much better parallelism out of the operations.  */
+
+	/* Start of critial section -- keep to one 64Byte cache line.  */
+.Lloop:
+	ldp	data1, data2, [src], #16
+.Lrealigned:
+	sub	tmp1, data1, zeroones
+	orr	tmp2, data1, #REP8_7f
+	sub	tmp3, data2, zeroones
+	orr	tmp4, data2, #REP8_7f
+	bic	has_nul1, tmp1, tmp2
+	bic	has_nul2, tmp3, tmp4
+	subs	limit_wd, limit_wd, #1
+	orr	tmp1, has_nul1, has_nul2
+	ccmp	tmp1, #0, #0, pl	/* NZCV = 0000  */
+	b.eq	.Lloop
+	/* End of critical section -- keep to one 64Byte cache line.  */
+
+	orr	tmp1, has_nul1, has_nul2
+	cbz	tmp1, .Lhit_limit	/* No null in final Qword.  */
+
+	/* We know there's a null in the final Qword.  The easiest thing
+	   to do now is work out the length of the string and return
+	   MIN (len, limit).  */
+
+	sub	len, src, srcin
+	cbz	has_nul1, .Lnul_in_data2
+#ifdef __AARCH64EB__
+	mov	data2, data1
+#endif
+	sub	len, len, #8
+	mov	has_nul2, has_nul1
+.Lnul_in_data2:
+#ifdef __AARCH64EB__
+	/* For big-endian, carry propagation (if the final byte in the
+	   string is 0x01) means we cannot use has_nul directly.  The
+	   easiest way to get the correct byte is to byte-swap the data
+	   and calculate the syndrome a second time.  */
+	rev	data2, data2
+	sub	tmp1, data2, zeroones
+	orr	tmp2, data2, #REP8_7f
+	bic	has_nul2, tmp1, tmp2
+#endif
+	sub	len, len, #8
+	rev	has_nul2, has_nul2
+	clz	pos, has_nul2
+	add	len, len, pos, lsr #3		/* Bits to bytes.  */
+	cmp	len, limit
+	csel	len, len, limit, ls		/* Return the lower value.  */
+	ret
+
+.Lmisaligned:
+	/* Deal with a partial first word.
+	   We're doing two things in parallel here;
+	   1) Calculate the number of words (but avoiding overflow if
+	      limit is near ULONG_MAX) - to do this we need to work out
+	      limit + tmp1 - 1 as a 65-bit value before shifting it;
+	   2) Load and mask the initial data words - we force the bytes
+	      before the ones we are interested in to 0xff - this ensures
+	      early bytes will not hit any zero detection.  */
+	sub	limit_wd, limit, #1
+	neg	tmp4, tmp1
+	cmp	tmp1, #8
+
+	and	tmp3, limit_wd, #15
+	lsr	limit_wd, limit_wd, #4
+	mov	tmp2, #~0
+
+	ldp	data1, data2, [src], #16
+	lsl	tmp4, tmp4, #3		/* Bytes beyond alignment -> bits.  */
+	add	tmp3, tmp3, tmp1
+
+#ifdef __AARCH64EB__
+	/* Big-endian.  Early bytes are at MSB.  */
+	lsl	tmp2, tmp2, tmp4	/* Shift (tmp1 & 63).  */
+#else
+	/* Little-endian.  Early bytes are at LSB.  */
+	lsr	tmp2, tmp2, tmp4	/* Shift (tmp1 & 63).  */
+#endif
+	add	limit_wd, limit_wd, tmp3, lsr #4
+
+	orr	data1, data1, tmp2
+	orr	data2a, data2, tmp2
+
+	csinv	data1, data1, xzr, le
+	csel	data2, data2, data2a, le
+	b	.Lrealigned
+END(strnlen)
diff --git a/libc/arch-arm64/generic/bionic/wmemmove.S b/libc/arch-arm64/generic/bionic/wmemmove.S
new file mode 100644
index 0000000..e4f67f7
--- /dev/null
+++ b/libc/arch-arm64/generic/bionic/wmemmove.S
@@ -0,0 +1,30 @@
+/* Copyright (c) 2014, Linaro Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the name of the Linaro nor the
+         names of its contributors may be used to endorse or promote products
+         derived from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define WMEMMOVE
+#include "memmove.S"
+#undef WMEMMOVE
diff --git a/libc/arch-arm64/generic/generic.mk b/libc/arch-arm64/generic/generic.mk
new file mode 100644
index 0000000..1b595aa
--- /dev/null
+++ b/libc/arch-arm64/generic/generic.mk
@@ -0,0 +1,14 @@
+libc_bionic_src_files_arm64 += \
+    arch-arm64/generic/bionic/memchr.S \
+    arch-arm64/generic/bionic/memcmp.S \
+    arch-arm64/generic/bionic/memcpy.S \
+    arch-arm64/generic/bionic/memmove.S \
+    arch-arm64/generic/bionic/memset.S \
+    arch-arm64/generic/bionic/stpcpy.S \
+    arch-arm64/generic/bionic/strchr.S \
+    arch-arm64/generic/bionic/strcmp.S \
+    arch-arm64/generic/bionic/strcpy.S \
+    arch-arm64/generic/bionic/strlen.S \
+    arch-arm64/generic/bionic/strncmp.S \
+    arch-arm64/generic/bionic/strnlen.S \
+    arch-arm64/generic/bionic/wmemmove.S
diff --git a/libc/arch-arm64/include/machine/_types.h b/libc/arch-arm64/include/machine/_types.h
deleted file mode 100644
index 0a462ab..0000000
--- a/libc/arch-arm64/include/machine/_types.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*	$OpenBSD: _types.h,v 1.3 2006/02/14 18:12:58 miod Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)types.h	8.3 (Berkeley) 1/5/94
- *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
- */
-
-#ifndef _AARCH64__TYPES_H_
-#define _AARCH64__TYPES_H_
-
-/* 7.18.1.1 Exact-width integer types */
-typedef	__signed char		__int8_t;
-typedef	unsigned char		__uint8_t;
-typedef	short			__int16_t;
-typedef	unsigned short		__uint16_t;
-typedef	int			__int32_t;
-typedef	unsigned int		__uint32_t;
-typedef	long 		__int64_t;
-typedef	unsigned long  __uint64_t;
-
-/* 7.18.1.2 Minimum-width integer types */
-typedef	__int8_t		__int_least8_t;
-typedef	__uint8_t		__uint_least8_t;
-typedef	__int16_t		__int_least16_t;
-typedef	__uint16_t		__uint_least16_t;
-typedef	__int32_t		__int_least32_t;
-typedef	__uint32_t		__uint_least32_t;
-typedef	__int64_t		__int_least64_t;
-typedef	__uint64_t		__uint_least64_t;
-
-/* 7.18.1.3 Fastest minimum-width integer types */
-typedef	__int32_t		__int_fast8_t;
-typedef	__uint32_t		__uint_fast8_t;
-typedef	__int32_t		__int_fast16_t;
-typedef	__uint32_t		__uint_fast16_t;
-typedef	__int32_t		__int_fast32_t;
-typedef	__uint32_t		__uint_fast32_t;
-typedef	__int64_t		__int_fast64_t;
-typedef	__uint64_t		__uint_fast64_t;
-
-/* 7.18.1.4 Integer types capable of holding object pointers */
-typedef	int 			__intptr_t;
-typedef	unsigned int 		__uintptr_t;
-
-/* 7.18.1.5 Greatest-width integer types */
-typedef	__int64_t		__intmax_t;
-typedef	__uint64_t		__uintmax_t;
-
-/* Register size */
-typedef	__int64_t		__register_t;
-
-/* VM system types */
-typedef	unsigned long		__vaddr_t;
-typedef	unsigned long		__paddr_t;
-typedef	unsigned long		__vsize_t;
-typedef	unsigned long		__psize_t;
-
-/* Standard system types */
-typedef	long			__clock_t;
-typedef	int	    		__clockid_t;
-typedef	double			__double_t;
-typedef	float			__float_t;
-typedef	long			__ptrdiff_t;
-typedef	long			__time_t;
-typedef	int	    		__timer_t;
-#if defined(__GNUC__) && __GNUC__ >= 3
-typedef	__builtin_va_list	__va_list;
-#else
-typedef	char *			__va_list;
-#endif
-
-/* Wide character support types */
-#ifndef __cplusplus
-typedef	int			__wchar_t;
-#endif
-typedef	int			__wint_t;
-typedef	int			__rune_t;
-typedef	void *			__wctrans_t;
-typedef	void *			__wctype_t;
-
-#define _BYTE_ORDER _LITTLE_ENDIAN
-
-#endif  /* _AARCH64__TYPES_H_ */
-
diff --git a/libc/arch-arm64/include/machine/asm.h b/libc/arch-arm64/include/machine/asm.h
index 3f8b908..4bfabaf 100644
--- a/libc/arch-arm64/include/machine/asm.h
+++ b/libc/arch-arm64/include/machine/asm.h
@@ -38,91 +38,17 @@
 #ifndef _AARCH64_ASM_H_
 #define _AARCH64_ASM_H_
 
-/* TODO: Add cfi directives for creating/restoring FP */
-#ifdef __ELF__
-# define	_C_LABEL(x)	x
-#else
-# ifdef __STDC__
-#  define	_C_LABEL(x)	_ ## x
-# else
-#  define	_C_LABEL(x)	_/**/x
-# endif
-#endif
-#define	_ASM_LABEL(x)	x
-
-#ifdef __STDC__
-# define	__CONCAT(x,y)	x ## y
-# define	__STRING(x)	#x
-#else
-# define	__CONCAT(x,y)	x/**/y
-# define	__STRING(x)	"x"
-#endif
-
 #ifndef _ALIGN_TEXT
-# define	_ALIGN_TEXT	.align 0
+# define _ALIGN_TEXT .align 0
 #endif
 
-#define	_ASM_TYPE_FUNCTION	%function
-#define	_ASM_TYPE_OBJECT	%object
-#define	_ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x: .cfi_startproc
-
-#define	_ASM_SIZE(x)	.size x, .-x;
-
-#define _END(x) \
-	.cfi_endproc; \
-	_ASM_SIZE(x)
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y));
-#define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
-#define	END(y)		_END(_C_LABEL(y))
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
-#define	ASEND(y)	_END(_ASM_LABEL(y))
-
-#ifdef __ELF__
-#define	ENTRY_PRIVATE(y)  ENTRY(y); .hidden _C_LABEL(y)
-#else
-#define	ENTRY_PRIVATE(y)  ENTRY(y)
-#endif
-
-#define	ASMSTR		.asciz
+#undef __bionic_asm_function_type
+#define __bionic_asm_function_type %function
 
 #if defined(__ELF__) && defined(PIC)
-#ifdef __STDC__
-#define	PIC_SYM(x,y)	x ## ( ## y ## )
+#define PIC_SYM(x,y) x ## ( ## y ## )
 #else
-#define	PIC_SYM(x,y)	x/**/(/**/y/**/)
+#define PIC_SYM(x,y) x
 #endif
-#else
-#define	PIC_SYM(x,y)	x
-#endif
-
-#ifdef __ELF__
-#define	RCSID(x)	.section ".ident"; .asciz x
-#else
-#define	RCSID(x)	.text; .asciz x
-#endif
-
-#ifdef __ELF__
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-#endif
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg ## ,30,0,0,0 ;					\
-	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
-#elif defined(__ELF__)
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(sym),1,0,0,0
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(_/**/sym),1,0,0,0
-#endif /* __STDC__ */
 
 #endif /* _AARCH64_ASM_H_ */
-
diff --git a/libc/arch-arm64/include/machine/ieee.h b/libc/arch-arm64/include/machine/ieee.h
deleted file mode 100644
index cf2c1fc..0000000
--- a/libc/arch-arm64/include/machine/ieee.h
+++ /dev/null
@@ -1,191 +0,0 @@
-/*	$OpenBSD: ieee.h,v 1.1 2004/02/01 05:09:49 drahn Exp $	*/
-/*	$NetBSD: ieee.h,v 1.2 2001/02/21 17:43:50 bjh21 Exp $	*/
-
-/*
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Lawrence Berkeley Laboratory.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
- */
-
-/*
- * ieee.h defines the machine-dependent layout of the machine's IEEE
- * floating point.
- */
-
-/*
- * Define the number of bits in each fraction and exponent.
- *
- *		     k	         k+1
- * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
- *
- *					  (-exp_bias+1)
- * as fractions that look like 0.fffff x 2             .  This means that
- *
- *			 -126
- * the number 0.10000 x 2    , for instance, is the same as the normalized
- *
- *		-127			   -128
- * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
- *
- *				  -129
- * in the fraction; to represent 2    , we need two, and so on.  This
- *
- *						     (-exp_bias-fracbits+1)
- * implies that the smallest denormalized number is 2
- *
- * for whichever format we are talking about: for single precision, for
- *
- *						-126		-149
- * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
- *
- * -149 == -127 - 23 + 1.
- */
-
-/*
- * The ARM has two sets of FP data formats.  The FPA supports 32-bit, 64-bit
- * and 96-bit IEEE formats, with the words in big-endian order.  VFP supports
- * 32-bin and 64-bit IEEE formats with the words in the CPU's native byte
- * order.
- *
- * The FPA also has two packed decimal formats, but we ignore them here.
- */
-
-#define	SNG_EXPBITS	8
-#define	SNG_FRACBITS	23
-
-#define	DBL_EXPBITS	11
-#define	DBL_FRACBITS	52
-
-#ifndef __VFP_FP__
-#define	E80_EXPBITS	15
-#define	E80_FRACBITS	64
-
-#define	EXT_EXPBITS	15
-#define	EXT_FRACBITS	112
-#endif
-
-struct ieee_single {
-	u_int	sng_frac:23;
-	u_int	sng_exponent:8;
-	u_int	sng_sign:1;
-};
-
-#ifdef __VFP_FP__
-struct ieee_double {
-#ifdef __AARCH64EB__
-	u_int	dbl_sign:1;
-	u_int	dbl_exp:11;
-	u_int	dbl_frach:20;
-	u_int	dbl_fracl;
-#else /* !__AARCH64EB__ */
-	u_int	dbl_fracl;
-	u_int	dbl_frach:20;
-	u_int	dbl_exp:11;
-	u_int	dbl_sign:1;
-#endif /* !__AARCH64EB__ */
-};
-#else /* !__VFP_FP__ */
-struct ieee_double {
-	u_int	dbl_frach:20;
-	u_int	dbl_exp:11;
-	u_int	dbl_sign:1;
-	u_int	dbl_fracl;
-};
-
-union ieee_double_u {
-	double                  dblu_d;
-	struct ieee_double      dblu_dbl;
-};
-
-
-struct ieee_e80 {
-	u_int	e80_exp:15;
-	u_int	e80_zero:16;
-	u_int	e80_sign:1;
-	u_int	e80_frach:31;
-	u_int	e80_j:1;
-	u_int	e80_fracl;
-};
-
-struct ieee_ext {
-	u_int	ext_frach:16;
-	u_int	ext_exp:15;
-	u_int	ext_sign:1;
-	u_int	ext_frachm;
-	u_int	ext_fraclm;
-	u_int	ext_fracl;
-};
-#endif /* !__VFP_FP__ */
-
-/*
- * Floats whose exponent is in [1..INFNAN) (of whatever type) are
- * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
- * Floats whose exponent is zero are either zero (iff all fraction
- * bits are zero) or subnormal values.
- *
- * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
- * high fraction; if the bit is set, it is a `quiet NaN'.
- */
-#define	SNG_EXP_INFNAN	255
-#define	DBL_EXP_INFNAN	2047
-#ifndef __VFP_FP__
-#define	E80_EXP_INFNAN	32767
-#define	EXT_EXP_INFNAN	32767
-#endif /* !__VFP_FP__ */
-
-#if 0
-#define	SNG_QUIETNAN	(1 << 22)
-#define	DBL_QUIETNAN	(1 << 19)
-#ifndef __VFP_FP__
-#define	E80_QUIETNAN	(1 << 15)
-#define	EXT_QUIETNAN	(1 << 15)
-#endif /* !__VFP_FP__ */
-#endif
-
-/*
- * Exponent biases.
- */
-#define	SNG_EXP_BIAS	127
-#define	DBL_EXP_BIAS	1023
-#ifndef __VFP_FP__
-#define	E80_EXP_BIAS	16383
-#define	EXT_EXP_BIAS	16383
-#endif /* !__VFP_FP__ */
diff --git a/libc/arch-arm64/include/machine/limits.h b/libc/arch-arm64/include/machine/limits.h
deleted file mode 100644
index ecddb01..0000000
--- a/libc/arch-arm64/include/machine/limits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.3 2006/01/06 22:48:46 millert Exp $	*/
-/*	$NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 Exp $	*/
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)limits.h	7.2 (Berkeley) 6/28/90
- */
-
-#ifndef _AARCH64_LIMITS_H_
-#define _AARCH64_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	1		/* no multibyte characters */
-
-#define	LONGLONG_BIT	64
-#define	LONGLONG_MIN	(-9223372036854775807LL-1)
-#define	LONGLONG_MAX	9223372036854775807LL
-#define	ULONGLONG_MAX	18446744073709551615ULL
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	ULONGLONG_MAX	/* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define	SSIZE_MAX	LONGLONG_MAX		/* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t (historic) */
-
-#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
-#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
-#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-#endif /* _AARCH64_LIMITS_H_ */
diff --git a/libc/arch-arm64/syscalls.mk b/libc/arch-arm64/syscalls.mk
deleted file mode 100644
index f1de5a5..0000000
--- a/libc/arch-arm64/syscalls.mk
+++ /dev/null
@@ -1,190 +0,0 @@
-# Generated by gensyscalls.py. Do not edit.
-syscall_src :=
-syscall_src += arch-arm64/syscalls/__brk.S
-syscall_src += arch-arm64/syscalls/__epoll_pwait.S
-syscall_src += arch-arm64/syscalls/__exit.S
-syscall_src += arch-arm64/syscalls/__getcpu.S
-syscall_src += arch-arm64/syscalls/__getcwd.S
-syscall_src += arch-arm64/syscalls/__getpriority.S
-syscall_src += arch-arm64/syscalls/__ioctl.S
-syscall_src += arch-arm64/syscalls/__openat.S
-syscall_src += arch-arm64/syscalls/__ppoll.S
-syscall_src += arch-arm64/syscalls/__pselect6.S
-syscall_src += arch-arm64/syscalls/__ptrace.S
-syscall_src += arch-arm64/syscalls/__reboot.S
-syscall_src += arch-arm64/syscalls/__rt_sigaction.S
-syscall_src += arch-arm64/syscalls/__rt_sigpending.S
-syscall_src += arch-arm64/syscalls/__rt_sigprocmask.S
-syscall_src += arch-arm64/syscalls/__rt_sigsuspend.S
-syscall_src += arch-arm64/syscalls/__rt_sigtimedwait.S
-syscall_src += arch-arm64/syscalls/__sched_getaffinity.S
-syscall_src += arch-arm64/syscalls/__set_tid_address.S
-syscall_src += arch-arm64/syscalls/__syslog.S
-syscall_src += arch-arm64/syscalls/__timer_create.S
-syscall_src += arch-arm64/syscalls/__timer_delete.S
-syscall_src += arch-arm64/syscalls/__timer_getoverrun.S
-syscall_src += arch-arm64/syscalls/__timer_gettime.S
-syscall_src += arch-arm64/syscalls/__timer_settime.S
-syscall_src += arch-arm64/syscalls/__waitid.S
-syscall_src += arch-arm64/syscalls/_exit.S
-syscall_src += arch-arm64/syscalls/accept.S
-syscall_src += arch-arm64/syscalls/acct.S
-syscall_src += arch-arm64/syscalls/bind.S
-syscall_src += arch-arm64/syscalls/capget.S
-syscall_src += arch-arm64/syscalls/capset.S
-syscall_src += arch-arm64/syscalls/chdir.S
-syscall_src += arch-arm64/syscalls/chroot.S
-syscall_src += arch-arm64/syscalls/clock_getres.S
-syscall_src += arch-arm64/syscalls/clock_gettime.S
-syscall_src += arch-arm64/syscalls/clock_nanosleep.S
-syscall_src += arch-arm64/syscalls/clock_settime.S
-syscall_src += arch-arm64/syscalls/close.S
-syscall_src += arch-arm64/syscalls/connect.S
-syscall_src += arch-arm64/syscalls/delete_module.S
-syscall_src += arch-arm64/syscalls/dup.S
-syscall_src += arch-arm64/syscalls/dup3.S
-syscall_src += arch-arm64/syscalls/epoll_create1.S
-syscall_src += arch-arm64/syscalls/epoll_ctl.S
-syscall_src += arch-arm64/syscalls/eventfd.S
-syscall_src += arch-arm64/syscalls/execve.S
-syscall_src += arch-arm64/syscalls/faccessat.S
-syscall_src += arch-arm64/syscalls/fchdir.S
-syscall_src += arch-arm64/syscalls/fchmod.S
-syscall_src += arch-arm64/syscalls/fchmodat.S
-syscall_src += arch-arm64/syscalls/fchown.S
-syscall_src += arch-arm64/syscalls/fchownat.S
-syscall_src += arch-arm64/syscalls/fcntl.S
-syscall_src += arch-arm64/syscalls/fdatasync.S
-syscall_src += arch-arm64/syscalls/fgetxattr.S
-syscall_src += arch-arm64/syscalls/flistxattr.S
-syscall_src += arch-arm64/syscalls/flock.S
-syscall_src += arch-arm64/syscalls/fremovexattr.S
-syscall_src += arch-arm64/syscalls/fsetxattr.S
-syscall_src += arch-arm64/syscalls/fstat.S
-syscall_src += arch-arm64/syscalls/fstatat.S
-syscall_src += arch-arm64/syscalls/fstatfs.S
-syscall_src += arch-arm64/syscalls/fsync.S
-syscall_src += arch-arm64/syscalls/ftruncate.S
-syscall_src += arch-arm64/syscalls/futex.S
-syscall_src += arch-arm64/syscalls/getdents.S
-syscall_src += arch-arm64/syscalls/getegid.S
-syscall_src += arch-arm64/syscalls/geteuid.S
-syscall_src += arch-arm64/syscalls/getgid.S
-syscall_src += arch-arm64/syscalls/getgroups.S
-syscall_src += arch-arm64/syscalls/getitimer.S
-syscall_src += arch-arm64/syscalls/getpeername.S
-syscall_src += arch-arm64/syscalls/getpgid.S
-syscall_src += arch-arm64/syscalls/getpid.S
-syscall_src += arch-arm64/syscalls/getppid.S
-syscall_src += arch-arm64/syscalls/getresgid.S
-syscall_src += arch-arm64/syscalls/getresuid.S
-syscall_src += arch-arm64/syscalls/getrlimit.S
-syscall_src += arch-arm64/syscalls/getrusage.S
-syscall_src += arch-arm64/syscalls/getsid.S
-syscall_src += arch-arm64/syscalls/getsockname.S
-syscall_src += arch-arm64/syscalls/getsockopt.S
-syscall_src += arch-arm64/syscalls/gettid.S
-syscall_src += arch-arm64/syscalls/gettimeofday.S
-syscall_src += arch-arm64/syscalls/getuid.S
-syscall_src += arch-arm64/syscalls/getxattr.S
-syscall_src += arch-arm64/syscalls/init_module.S
-syscall_src += arch-arm64/syscalls/inotify_add_watch.S
-syscall_src += arch-arm64/syscalls/inotify_init1.S
-syscall_src += arch-arm64/syscalls/inotify_rm_watch.S
-syscall_src += arch-arm64/syscalls/ioprio_get.S
-syscall_src += arch-arm64/syscalls/ioprio_set.S
-syscall_src += arch-arm64/syscalls/kill.S
-syscall_src += arch-arm64/syscalls/klogctl.S
-syscall_src += arch-arm64/syscalls/lgetxattr.S
-syscall_src += arch-arm64/syscalls/linkat.S
-syscall_src += arch-arm64/syscalls/listen.S
-syscall_src += arch-arm64/syscalls/listxattr.S
-syscall_src += arch-arm64/syscalls/llistxattr.S
-syscall_src += arch-arm64/syscalls/lremovexattr.S
-syscall_src += arch-arm64/syscalls/lseek.S
-syscall_src += arch-arm64/syscalls/lsetxattr.S
-syscall_src += arch-arm64/syscalls/madvise.S
-syscall_src += arch-arm64/syscalls/mincore.S
-syscall_src += arch-arm64/syscalls/mkdirat.S
-syscall_src += arch-arm64/syscalls/mknodat.S
-syscall_src += arch-arm64/syscalls/mlock.S
-syscall_src += arch-arm64/syscalls/mlockall.S
-syscall_src += arch-arm64/syscalls/mmap.S
-syscall_src += arch-arm64/syscalls/mount.S
-syscall_src += arch-arm64/syscalls/mprotect.S
-syscall_src += arch-arm64/syscalls/mremap.S
-syscall_src += arch-arm64/syscalls/msync.S
-syscall_src += arch-arm64/syscalls/munlock.S
-syscall_src += arch-arm64/syscalls/munlockall.S
-syscall_src += arch-arm64/syscalls/munmap.S
-syscall_src += arch-arm64/syscalls/nanosleep.S
-syscall_src += arch-arm64/syscalls/perf_event_open.S
-syscall_src += arch-arm64/syscalls/personality.S
-syscall_src += arch-arm64/syscalls/pipe2.S
-syscall_src += arch-arm64/syscalls/prctl.S
-syscall_src += arch-arm64/syscalls/pread64.S
-syscall_src += arch-arm64/syscalls/prlimit64.S
-syscall_src += arch-arm64/syscalls/pwrite64.S
-syscall_src += arch-arm64/syscalls/read.S
-syscall_src += arch-arm64/syscalls/readahead.S
-syscall_src += arch-arm64/syscalls/readlinkat.S
-syscall_src += arch-arm64/syscalls/readv.S
-syscall_src += arch-arm64/syscalls/recvfrom.S
-syscall_src += arch-arm64/syscalls/recvmsg.S
-syscall_src += arch-arm64/syscalls/removexattr.S
-syscall_src += arch-arm64/syscalls/renameat.S
-syscall_src += arch-arm64/syscalls/sched_get_priority_max.S
-syscall_src += arch-arm64/syscalls/sched_get_priority_min.S
-syscall_src += arch-arm64/syscalls/sched_getparam.S
-syscall_src += arch-arm64/syscalls/sched_getscheduler.S
-syscall_src += arch-arm64/syscalls/sched_rr_get_interval.S
-syscall_src += arch-arm64/syscalls/sched_setaffinity.S
-syscall_src += arch-arm64/syscalls/sched_setparam.S
-syscall_src += arch-arm64/syscalls/sched_setscheduler.S
-syscall_src += arch-arm64/syscalls/sched_yield.S
-syscall_src += arch-arm64/syscalls/sendfile.S
-syscall_src += arch-arm64/syscalls/sendmsg.S
-syscall_src += arch-arm64/syscalls/sendto.S
-syscall_src += arch-arm64/syscalls/setgid.S
-syscall_src += arch-arm64/syscalls/setgroups.S
-syscall_src += arch-arm64/syscalls/setitimer.S
-syscall_src += arch-arm64/syscalls/setns.S
-syscall_src += arch-arm64/syscalls/setpgid.S
-syscall_src += arch-arm64/syscalls/setpriority.S
-syscall_src += arch-arm64/syscalls/setregid.S
-syscall_src += arch-arm64/syscalls/setresgid.S
-syscall_src += arch-arm64/syscalls/setresuid.S
-syscall_src += arch-arm64/syscalls/setreuid.S
-syscall_src += arch-arm64/syscalls/setrlimit.S
-syscall_src += arch-arm64/syscalls/setsid.S
-syscall_src += arch-arm64/syscalls/setsockopt.S
-syscall_src += arch-arm64/syscalls/settimeofday.S
-syscall_src += arch-arm64/syscalls/setuid.S
-syscall_src += arch-arm64/syscalls/setxattr.S
-syscall_src += arch-arm64/syscalls/shutdown.S
-syscall_src += arch-arm64/syscalls/sigaltstack.S
-syscall_src += arch-arm64/syscalls/signalfd4.S
-syscall_src += arch-arm64/syscalls/socket.S
-syscall_src += arch-arm64/syscalls/socketpair.S
-syscall_src += arch-arm64/syscalls/statfs.S
-syscall_src += arch-arm64/syscalls/swapoff.S
-syscall_src += arch-arm64/syscalls/swapon.S
-syscall_src += arch-arm64/syscalls/symlinkat.S
-syscall_src += arch-arm64/syscalls/sync.S
-syscall_src += arch-arm64/syscalls/sysinfo.S
-syscall_src += arch-arm64/syscalls/tgkill.S
-syscall_src += arch-arm64/syscalls/timerfd_create.S
-syscall_src += arch-arm64/syscalls/timerfd_gettime.S
-syscall_src += arch-arm64/syscalls/timerfd_settime.S
-syscall_src += arch-arm64/syscalls/times.S
-syscall_src += arch-arm64/syscalls/tkill.S
-syscall_src += arch-arm64/syscalls/truncate.S
-syscall_src += arch-arm64/syscalls/umask.S
-syscall_src += arch-arm64/syscalls/umount2.S
-syscall_src += arch-arm64/syscalls/uname.S
-syscall_src += arch-arm64/syscalls/unlinkat.S
-syscall_src += arch-arm64/syscalls/unshare.S
-syscall_src += arch-arm64/syscalls/utimensat.S
-syscall_src += arch-arm64/syscalls/wait4.S
-syscall_src += arch-arm64/syscalls/write.S
-syscall_src += arch-arm64/syscalls/writev.S
diff --git a/libc/arch-arm64/syscalls/__accept4.S b/libc/arch-arm64/syscalls/__accept4.S
new file mode 100644
index 0000000..559e6a7
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__accept4.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__accept4)
+    mov     x8, __NR_accept4
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__accept4)
+.hidden __accept4
diff --git a/libc/arch-arm64/syscalls/__brk.S b/libc/arch-arm64/syscalls/__brk.S
index 98055cc..fb794bf 100644
--- a/libc/arch-arm64/syscalls/__brk.S
+++ b/libc/arch-arm64/syscalls/__brk.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__brk)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_brk
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__brk)
-.hidden _C_LABEL(__brk)
+.hidden __brk
diff --git a/libc/arch-arm64/syscalls/__clock_gettime.S b/libc/arch-arm64/syscalls/__clock_gettime.S
new file mode 100644
index 0000000..658ab29
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__clock_gettime.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__clock_gettime)
+    mov     x8, __NR_clock_gettime
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__clock_gettime)
+.hidden __clock_gettime
diff --git a/libc/arch-arm64/syscalls/__connect.S b/libc/arch-arm64/syscalls/__connect.S
new file mode 100644
index 0000000..c18e6eb
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__connect.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__connect)
+    mov     x8, __NR_connect
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__connect)
+.hidden __connect
diff --git a/libc/arch-arm64/syscalls/__epoll_pwait.S b/libc/arch-arm64/syscalls/__epoll_pwait.S
index d512c7c..acf2bbf 100644
--- a/libc/arch-arm64/syscalls/__epoll_pwait.S
+++ b/libc/arch-arm64/syscalls/__epoll_pwait.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__epoll_pwait)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_epoll_pwait
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__epoll_pwait)
-.hidden _C_LABEL(__epoll_pwait)
+.hidden __epoll_pwait
diff --git a/libc/arch-arm64/syscalls/__exit.S b/libc/arch-arm64/syscalls/__exit.S
index 50cd45a..b6b1866 100644
--- a/libc/arch-arm64/syscalls/__exit.S
+++ b/libc/arch-arm64/syscalls/__exit.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__exit)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_exit
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__exit)
-.hidden _C_LABEL(__exit)
+.hidden __exit
diff --git a/libc/arch-arm64/syscalls/__fadvise64.S b/libc/arch-arm64/syscalls/__fadvise64.S
new file mode 100644
index 0000000..695d094
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__fadvise64.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__fadvise64)
+    mov     x8, __NR_fadvise64
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__fadvise64)
+.hidden __fadvise64
diff --git a/libc/arch-arm64/syscalls/__getcpu.S b/libc/arch-arm64/syscalls/__getcpu.S
index 698e8ff..11ed68e 100644
--- a/libc/arch-arm64/syscalls/__getcpu.S
+++ b/libc/arch-arm64/syscalls/__getcpu.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__getcpu)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getcpu
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__getcpu)
-.hidden _C_LABEL(__getcpu)
+.hidden __getcpu
diff --git a/libc/arch-arm64/syscalls/__getcwd.S b/libc/arch-arm64/syscalls/__getcwd.S
index f0543f0..c64f4d2 100644
--- a/libc/arch-arm64/syscalls/__getcwd.S
+++ b/libc/arch-arm64/syscalls/__getcwd.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__getcwd)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getcwd
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__getcwd)
-.hidden _C_LABEL(__getcwd)
+.hidden __getcwd
diff --git a/libc/arch-arm64/syscalls/__getdents64.S b/libc/arch-arm64/syscalls/__getdents64.S
new file mode 100644
index 0000000..9943390
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__getdents64.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getdents64)
+    mov     x8, __NR_getdents64
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__getdents64)
+.hidden __getdents64
diff --git a/libc/arch-arm64/syscalls/__getpid.S b/libc/arch-arm64/syscalls/__getpid.S
new file mode 100644
index 0000000..fbc96df
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__getpid.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getpid)
+    mov     x8, __NR_getpid
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__getpid)
+.hidden __getpid
diff --git a/libc/arch-arm64/syscalls/__getpriority.S b/libc/arch-arm64/syscalls/__getpriority.S
index f7fd1b8..9d98e22 100644
--- a/libc/arch-arm64/syscalls/__getpriority.S
+++ b/libc/arch-arm64/syscalls/__getpriority.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__getpriority)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getpriority
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__getpriority)
-.hidden _C_LABEL(__getpriority)
+.hidden __getpriority
diff --git a/libc/arch-arm64/syscalls/__gettimeofday.S b/libc/arch-arm64/syscalls/__gettimeofday.S
new file mode 100644
index 0000000..0c8206a
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__gettimeofday.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__gettimeofday)
+    mov     x8, __NR_gettimeofday
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__gettimeofday)
+.hidden __gettimeofday
diff --git a/libc/arch-arm64/syscalls/__ioctl.S b/libc/arch-arm64/syscalls/__ioctl.S
index 2569fdf..62bc28c 100644
--- a/libc/arch-arm64/syscalls/__ioctl.S
+++ b/libc/arch-arm64/syscalls/__ioctl.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__ioctl)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_ioctl
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__ioctl)
-.hidden _C_LABEL(__ioctl)
+.hidden __ioctl
diff --git a/libc/arch-arm64/syscalls/__openat.S b/libc/arch-arm64/syscalls/__openat.S
index cca66ce..8b6853f 100644
--- a/libc/arch-arm64/syscalls/__openat.S
+++ b/libc/arch-arm64/syscalls/__openat.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__openat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_openat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__openat)
-.hidden _C_LABEL(__openat)
+.hidden __openat
diff --git a/libc/arch-arm64/syscalls/__ppoll.S b/libc/arch-arm64/syscalls/__ppoll.S
index 68efc09..1f54d67 100644
--- a/libc/arch-arm64/syscalls/__ppoll.S
+++ b/libc/arch-arm64/syscalls/__ppoll.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__ppoll)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_ppoll
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__ppoll)
-.hidden _C_LABEL(__ppoll)
+.hidden __ppoll
diff --git a/libc/arch-arm64/syscalls/__pselect6.S b/libc/arch-arm64/syscalls/__pselect6.S
index 295b71a..388d84e 100644
--- a/libc/arch-arm64/syscalls/__pselect6.S
+++ b/libc/arch-arm64/syscalls/__pselect6.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__pselect6)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_pselect6
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__pselect6)
-.hidden _C_LABEL(__pselect6)
+.hidden __pselect6
diff --git a/libc/arch-arm64/syscalls/__ptrace.S b/libc/arch-arm64/syscalls/__ptrace.S
index aa41071..d68b674 100644
--- a/libc/arch-arm64/syscalls/__ptrace.S
+++ b/libc/arch-arm64/syscalls/__ptrace.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__ptrace)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_ptrace
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__ptrace)
-.hidden _C_LABEL(__ptrace)
+.hidden __ptrace
diff --git a/libc/arch-arm64/syscalls/__reboot.S b/libc/arch-arm64/syscalls/__reboot.S
index 9680bdc..79cd5be 100644
--- a/libc/arch-arm64/syscalls/__reboot.S
+++ b/libc/arch-arm64/syscalls/__reboot.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__reboot)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_reboot
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__reboot)
-.hidden _C_LABEL(__reboot)
+.hidden __reboot
diff --git a/libc/arch-arm64/syscalls/__rt_sigaction.S b/libc/arch-arm64/syscalls/__rt_sigaction.S
index 77f83ea..65fea2e 100644
--- a/libc/arch-arm64/syscalls/__rt_sigaction.S
+++ b/libc/arch-arm64/syscalls/__rt_sigaction.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigaction)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_rt_sigaction
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__rt_sigaction)
-.hidden _C_LABEL(__rt_sigaction)
+.hidden __rt_sigaction
diff --git a/libc/arch-arm64/syscalls/__rt_sigpending.S b/libc/arch-arm64/syscalls/__rt_sigpending.S
index 59a2e1e..6553781 100644
--- a/libc/arch-arm64/syscalls/__rt_sigpending.S
+++ b/libc/arch-arm64/syscalls/__rt_sigpending.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigpending)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_rt_sigpending
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__rt_sigpending)
-.hidden _C_LABEL(__rt_sigpending)
+.hidden __rt_sigpending
diff --git a/libc/arch-arm64/syscalls/__rt_sigprocmask.S b/libc/arch-arm64/syscalls/__rt_sigprocmask.S
index c5a51ed..95127d6 100644
--- a/libc/arch-arm64/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-arm64/syscalls/__rt_sigprocmask.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigprocmask)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_rt_sigprocmask
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__rt_sigprocmask)
-.hidden _C_LABEL(__rt_sigprocmask)
+.hidden __rt_sigprocmask
diff --git a/libc/arch-arm64/syscalls/__rt_sigsuspend.S b/libc/arch-arm64/syscalls/__rt_sigsuspend.S
index 7a1c22e..7cbd8d6 100644
--- a/libc/arch-arm64/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-arm64/syscalls/__rt_sigsuspend.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigsuspend)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_rt_sigsuspend
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__rt_sigsuspend)
-.hidden _C_LABEL(__rt_sigsuspend)
+.hidden __rt_sigsuspend
diff --git a/libc/arch-arm64/syscalls/__rt_sigtimedwait.S b/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
index b3d950c..8001635 100644
--- a/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__rt_sigtimedwait)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_rt_sigtimedwait
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__rt_sigtimedwait)
-.hidden _C_LABEL(__rt_sigtimedwait)
+.hidden __rt_sigtimedwait
diff --git a/libc/arch-arm64/syscalls/__sched_getaffinity.S b/libc/arch-arm64/syscalls/__sched_getaffinity.S
index 9b785ad..7dad15e 100644
--- a/libc/arch-arm64/syscalls/__sched_getaffinity.S
+++ b/libc/arch-arm64/syscalls/__sched_getaffinity.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__sched_getaffinity)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_getaffinity
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__sched_getaffinity)
-.hidden _C_LABEL(__sched_getaffinity)
+.hidden __sched_getaffinity
diff --git a/libc/arch-arm64/syscalls/__set_tid_address.S b/libc/arch-arm64/syscalls/__set_tid_address.S
index b7541fc..f7ae16d 100644
--- a/libc/arch-arm64/syscalls/__set_tid_address.S
+++ b/libc/arch-arm64/syscalls/__set_tid_address.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__set_tid_address)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_set_tid_address
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__set_tid_address)
-.hidden _C_LABEL(__set_tid_address)
+.hidden __set_tid_address
diff --git a/libc/arch-arm64/syscalls/__signalfd4.S b/libc/arch-arm64/syscalls/__signalfd4.S
new file mode 100644
index 0000000..f6e3497
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__signalfd4.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__signalfd4)
+    mov     x8, __NR_signalfd4
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__signalfd4)
+.hidden __signalfd4
diff --git a/libc/arch-arm64/syscalls/__socket.S b/libc/arch-arm64/syscalls/__socket.S
new file mode 100644
index 0000000..344bb2d
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__socket.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__socket)
+    mov     x8, __NR_socket
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__socket)
+.hidden __socket
diff --git a/libc/arch-arm64/syscalls/__syslog.S b/libc/arch-arm64/syscalls/__syslog.S
deleted file mode 100644
index 625a7eb..0000000
--- a/libc/arch-arm64/syscalls/__syslog.S
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(__syslog)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_syslog
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(__syslog)
-.hidden _C_LABEL(__syslog)
diff --git a/libc/arch-arm64/syscalls/__timer_create.S b/libc/arch-arm64/syscalls/__timer_create.S
index bfce448..4790845 100644
--- a/libc/arch-arm64/syscalls/__timer_create.S
+++ b/libc/arch-arm64/syscalls/__timer_create.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_create)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_timer_create
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__timer_create)
-.hidden _C_LABEL(__timer_create)
+.hidden __timer_create
diff --git a/libc/arch-arm64/syscalls/__timer_delete.S b/libc/arch-arm64/syscalls/__timer_delete.S
index 03ed44e..ce12613 100644
--- a/libc/arch-arm64/syscalls/__timer_delete.S
+++ b/libc/arch-arm64/syscalls/__timer_delete.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_delete)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_timer_delete
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__timer_delete)
-.hidden _C_LABEL(__timer_delete)
+.hidden __timer_delete
diff --git a/libc/arch-arm64/syscalls/__timer_getoverrun.S b/libc/arch-arm64/syscalls/__timer_getoverrun.S
index a458941..2cfdf6a 100644
--- a/libc/arch-arm64/syscalls/__timer_getoverrun.S
+++ b/libc/arch-arm64/syscalls/__timer_getoverrun.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_getoverrun)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_timer_getoverrun
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__timer_getoverrun)
-.hidden _C_LABEL(__timer_getoverrun)
+.hidden __timer_getoverrun
diff --git a/libc/arch-arm64/syscalls/__timer_gettime.S b/libc/arch-arm64/syscalls/__timer_gettime.S
index b6ae29e..a1ea323 100644
--- a/libc/arch-arm64/syscalls/__timer_gettime.S
+++ b/libc/arch-arm64/syscalls/__timer_gettime.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_gettime)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_timer_gettime
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__timer_gettime)
-.hidden _C_LABEL(__timer_gettime)
+.hidden __timer_gettime
diff --git a/libc/arch-arm64/syscalls/__timer_settime.S b/libc/arch-arm64/syscalls/__timer_settime.S
index 3c44b53..059d705 100644
--- a/libc/arch-arm64/syscalls/__timer_settime.S
+++ b/libc/arch-arm64/syscalls/__timer_settime.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__timer_settime)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_timer_settime
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__timer_settime)
-.hidden _C_LABEL(__timer_settime)
+.hidden __timer_settime
diff --git a/libc/arch-arm64/syscalls/__waitid.S b/libc/arch-arm64/syscalls/__waitid.S
index 4244018..8bd649d 100644
--- a/libc/arch-arm64/syscalls/__waitid.S
+++ b/libc/arch-arm64/syscalls/__waitid.S
@@ -3,20 +3,13 @@
 #include <private/bionic_asm.h>
 
 ENTRY(__waitid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_waitid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(__waitid)
-.hidden _C_LABEL(__waitid)
+.hidden __waitid
diff --git a/libc/arch-arm64/syscalls/_exit.S b/libc/arch-arm64/syscalls/_exit.S
index 24b7b17..edf6744 100644
--- a/libc/arch-arm64/syscalls/_exit.S
+++ b/libc/arch-arm64/syscalls/_exit.S
@@ -3,19 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(_exit)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_exit_group
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(_exit)
+
+    .globl _Exit
+    .equ _Exit, _exit
diff --git a/libc/arch-arm64/syscalls/accept.S b/libc/arch-arm64/syscalls/accept.S
deleted file mode 100644
index dae6121..0000000
--- a/libc/arch-arm64/syscalls/accept.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(accept)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_accept
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(accept)
diff --git a/libc/arch-arm64/syscalls/acct.S b/libc/arch-arm64/syscalls/acct.S
index 901e420..48cb4e9 100644
--- a/libc/arch-arm64/syscalls/acct.S
+++ b/libc/arch-arm64/syscalls/acct.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(acct)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_acct
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(acct)
diff --git a/libc/arch-arm64/syscalls/bind.S b/libc/arch-arm64/syscalls/bind.S
index 471d783..47170ff 100644
--- a/libc/arch-arm64/syscalls/bind.S
+++ b/libc/arch-arm64/syscalls/bind.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(bind)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_bind
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(bind)
diff --git a/libc/arch-arm64/syscalls/capget.S b/libc/arch-arm64/syscalls/capget.S
index 33fe11c..7e0dfe9 100644
--- a/libc/arch-arm64/syscalls/capget.S
+++ b/libc/arch-arm64/syscalls/capget.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(capget)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_capget
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(capget)
diff --git a/libc/arch-arm64/syscalls/capset.S b/libc/arch-arm64/syscalls/capset.S
index 75f03a9..e7b7a8d 100644
--- a/libc/arch-arm64/syscalls/capset.S
+++ b/libc/arch-arm64/syscalls/capset.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(capset)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_capset
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(capset)
diff --git a/libc/arch-arm64/syscalls/chdir.S b/libc/arch-arm64/syscalls/chdir.S
index 051f823..723cd08 100644
--- a/libc/arch-arm64/syscalls/chdir.S
+++ b/libc/arch-arm64/syscalls/chdir.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(chdir)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_chdir
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(chdir)
diff --git a/libc/arch-arm64/syscalls/chroot.S b/libc/arch-arm64/syscalls/chroot.S
index c06399f..e4f6bd9 100644
--- a/libc/arch-arm64/syscalls/chroot.S
+++ b/libc/arch-arm64/syscalls/chroot.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(chroot)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_chroot
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(chroot)
diff --git a/libc/arch-arm64/syscalls/clock_getres.S b/libc/arch-arm64/syscalls/clock_getres.S
index bffc7cb..33fda8f 100644
--- a/libc/arch-arm64/syscalls/clock_getres.S
+++ b/libc/arch-arm64/syscalls/clock_getres.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(clock_getres)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_clock_getres
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(clock_getres)
diff --git a/libc/arch-arm64/syscalls/clock_gettime.S b/libc/arch-arm64/syscalls/clock_gettime.S
deleted file mode 100644
index 3c58236..0000000
--- a/libc/arch-arm64/syscalls/clock_gettime.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(clock_gettime)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_clock_gettime
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(clock_gettime)
diff --git a/libc/arch-arm64/syscalls/clock_nanosleep.S b/libc/arch-arm64/syscalls/clock_nanosleep.S
index 357bda6..349c5cc 100644
--- a/libc/arch-arm64/syscalls/clock_nanosleep.S
+++ b/libc/arch-arm64/syscalls/clock_nanosleep.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(clock_nanosleep)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_clock_nanosleep
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(clock_nanosleep)
diff --git a/libc/arch-arm64/syscalls/clock_settime.S b/libc/arch-arm64/syscalls/clock_settime.S
index 06e9393..62354d1 100644
--- a/libc/arch-arm64/syscalls/clock_settime.S
+++ b/libc/arch-arm64/syscalls/clock_settime.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(clock_settime)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_clock_settime
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(clock_settime)
diff --git a/libc/arch-arm64/syscalls/close.S b/libc/arch-arm64/syscalls/close.S
index fefe147..3624581 100644
--- a/libc/arch-arm64/syscalls/close.S
+++ b/libc/arch-arm64/syscalls/close.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(close)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_close
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(close)
diff --git a/libc/arch-arm64/syscalls/connect.S b/libc/arch-arm64/syscalls/connect.S
deleted file mode 100644
index d3cd43d..0000000
--- a/libc/arch-arm64/syscalls/connect.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(connect)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_connect
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(connect)
diff --git a/libc/arch-arm64/syscalls/delete_module.S b/libc/arch-arm64/syscalls/delete_module.S
index 4e8b09d..db8d947 100644
--- a/libc/arch-arm64/syscalls/delete_module.S
+++ b/libc/arch-arm64/syscalls/delete_module.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(delete_module)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_delete_module
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(delete_module)
diff --git a/libc/arch-arm64/syscalls/dup.S b/libc/arch-arm64/syscalls/dup.S
index 9dbe562..4e95045 100644
--- a/libc/arch-arm64/syscalls/dup.S
+++ b/libc/arch-arm64/syscalls/dup.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(dup)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_dup
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(dup)
diff --git a/libc/arch-arm64/syscalls/dup3.S b/libc/arch-arm64/syscalls/dup3.S
index ee04440..2e6be32 100644
--- a/libc/arch-arm64/syscalls/dup3.S
+++ b/libc/arch-arm64/syscalls/dup3.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(dup3)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_dup3
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(dup3)
diff --git a/libc/arch-arm64/syscalls/epoll_create1.S b/libc/arch-arm64/syscalls/epoll_create1.S
index 0ed34b5..6ef518e 100644
--- a/libc/arch-arm64/syscalls/epoll_create1.S
+++ b/libc/arch-arm64/syscalls/epoll_create1.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(epoll_create1)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_epoll_create1
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(epoll_create1)
diff --git a/libc/arch-arm64/syscalls/epoll_ctl.S b/libc/arch-arm64/syscalls/epoll_ctl.S
index a09ba29..1188f38 100644
--- a/libc/arch-arm64/syscalls/epoll_ctl.S
+++ b/libc/arch-arm64/syscalls/epoll_ctl.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(epoll_ctl)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_epoll_ctl
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(epoll_ctl)
diff --git a/libc/arch-arm64/syscalls/eventfd.S b/libc/arch-arm64/syscalls/eventfd.S
index e6b592b..ca5df12 100644
--- a/libc/arch-arm64/syscalls/eventfd.S
+++ b/libc/arch-arm64/syscalls/eventfd.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(eventfd)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_eventfd2
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(eventfd)
diff --git a/libc/arch-arm64/syscalls/execve.S b/libc/arch-arm64/syscalls/execve.S
index 4f3cdb8..fc8fb68 100644
--- a/libc/arch-arm64/syscalls/execve.S
+++ b/libc/arch-arm64/syscalls/execve.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(execve)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_execve
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(execve)
diff --git a/libc/arch-arm64/syscalls/faccessat.S b/libc/arch-arm64/syscalls/faccessat.S
index c6b6557..4c96cfa 100644
--- a/libc/arch-arm64/syscalls/faccessat.S
+++ b/libc/arch-arm64/syscalls/faccessat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(faccessat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_faccessat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(faccessat)
diff --git a/libc/arch-arm64/syscalls/fallocate.S b/libc/arch-arm64/syscalls/fallocate.S
new file mode 100644
index 0000000..ef3d4a4
--- /dev/null
+++ b/libc/arch-arm64/syscalls/fallocate.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fallocate)
+    mov     x8, __NR_fallocate
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(fallocate)
+
+    .globl fallocate64
+    .equ fallocate64, fallocate
diff --git a/libc/arch-arm64/syscalls/fchdir.S b/libc/arch-arm64/syscalls/fchdir.S
index c608231..2e164cb 100644
--- a/libc/arch-arm64/syscalls/fchdir.S
+++ b/libc/arch-arm64/syscalls/fchdir.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchdir)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fchdir
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fchdir)
diff --git a/libc/arch-arm64/syscalls/fchmod.S b/libc/arch-arm64/syscalls/fchmod.S
index a777cdc..83a8060 100644
--- a/libc/arch-arm64/syscalls/fchmod.S
+++ b/libc/arch-arm64/syscalls/fchmod.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchmod)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fchmod
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fchmod)
diff --git a/libc/arch-arm64/syscalls/fchmodat.S b/libc/arch-arm64/syscalls/fchmodat.S
index 1a52c9f..8c5bb0e 100644
--- a/libc/arch-arm64/syscalls/fchmodat.S
+++ b/libc/arch-arm64/syscalls/fchmodat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchmodat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fchmodat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fchmodat)
diff --git a/libc/arch-arm64/syscalls/fchown.S b/libc/arch-arm64/syscalls/fchown.S
index 073e36f..4456f1b 100644
--- a/libc/arch-arm64/syscalls/fchown.S
+++ b/libc/arch-arm64/syscalls/fchown.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchown)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fchown
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fchown)
diff --git a/libc/arch-arm64/syscalls/fchownat.S b/libc/arch-arm64/syscalls/fchownat.S
index db80ab1..7ba6611 100644
--- a/libc/arch-arm64/syscalls/fchownat.S
+++ b/libc/arch-arm64/syscalls/fchownat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fchownat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fchownat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fchownat)
diff --git a/libc/arch-arm64/syscalls/fcntl.S b/libc/arch-arm64/syscalls/fcntl.S
index 23ce155..e2787ae 100644
--- a/libc/arch-arm64/syscalls/fcntl.S
+++ b/libc/arch-arm64/syscalls/fcntl.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fcntl)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fcntl
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fcntl)
diff --git a/libc/arch-arm64/syscalls/fdatasync.S b/libc/arch-arm64/syscalls/fdatasync.S
index b4e9aa9..225ab29 100644
--- a/libc/arch-arm64/syscalls/fdatasync.S
+++ b/libc/arch-arm64/syscalls/fdatasync.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fdatasync)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fdatasync
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fdatasync)
diff --git a/libc/arch-arm64/syscalls/fgetxattr.S b/libc/arch-arm64/syscalls/fgetxattr.S
index 3278a12..0d6ada7 100644
--- a/libc/arch-arm64/syscalls/fgetxattr.S
+++ b/libc/arch-arm64/syscalls/fgetxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fgetxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fgetxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fgetxattr)
diff --git a/libc/arch-arm64/syscalls/flistxattr.S b/libc/arch-arm64/syscalls/flistxattr.S
index 40b2a30..8921bb4 100644
--- a/libc/arch-arm64/syscalls/flistxattr.S
+++ b/libc/arch-arm64/syscalls/flistxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(flistxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_flistxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(flistxattr)
diff --git a/libc/arch-arm64/syscalls/flock.S b/libc/arch-arm64/syscalls/flock.S
index 7e28789..0c036c8 100644
--- a/libc/arch-arm64/syscalls/flock.S
+++ b/libc/arch-arm64/syscalls/flock.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(flock)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_flock
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(flock)
diff --git a/libc/arch-arm64/syscalls/fremovexattr.S b/libc/arch-arm64/syscalls/fremovexattr.S
index be86dd0..cf3a371 100644
--- a/libc/arch-arm64/syscalls/fremovexattr.S
+++ b/libc/arch-arm64/syscalls/fremovexattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fremovexattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fremovexattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fremovexattr)
diff --git a/libc/arch-arm64/syscalls/fsetxattr.S b/libc/arch-arm64/syscalls/fsetxattr.S
index 2cb72c9..e69e718 100644
--- a/libc/arch-arm64/syscalls/fsetxattr.S
+++ b/libc/arch-arm64/syscalls/fsetxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fsetxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fsetxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fsetxattr)
diff --git a/libc/arch-arm64/syscalls/fstat.S b/libc/arch-arm64/syscalls/fstat.S
deleted file mode 100644
index f8aaa40..0000000
--- a/libc/arch-arm64/syscalls/fstat.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_fstat
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(fstat)
diff --git a/libc/arch-arm64/syscalls/fstat64.S b/libc/arch-arm64/syscalls/fstat64.S
new file mode 100644
index 0000000..85a07f5
--- /dev/null
+++ b/libc/arch-arm64/syscalls/fstat64.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstat64)
+    mov     x8, __NR_fstat
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(fstat64)
+
+    .globl fstat
+    .equ fstat, fstat64
diff --git a/libc/arch-arm64/syscalls/fstatat.S b/libc/arch-arm64/syscalls/fstatat.S
deleted file mode 100644
index 5de0fa0..0000000
--- a/libc/arch-arm64/syscalls/fstatat.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstatat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_newfstatat
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(fstatat)
diff --git a/libc/arch-arm64/syscalls/fstatat64.S b/libc/arch-arm64/syscalls/fstatat64.S
new file mode 100644
index 0000000..dafd982
--- /dev/null
+++ b/libc/arch-arm64/syscalls/fstatat64.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatat64)
+    mov     x8, __NR_newfstatat
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(fstatat64)
+
+    .globl fstatat
+    .equ fstatat, fstatat64
diff --git a/libc/arch-arm64/syscalls/fstatfs.S b/libc/arch-arm64/syscalls/fstatfs.S
deleted file mode 100644
index afd8875..0000000
--- a/libc/arch-arm64/syscalls/fstatfs.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstatfs)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_fstatfs
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(fstatfs)
diff --git a/libc/arch-arm64/syscalls/fstatfs64.S b/libc/arch-arm64/syscalls/fstatfs64.S
new file mode 100644
index 0000000..2ca2dcd
--- /dev/null
+++ b/libc/arch-arm64/syscalls/fstatfs64.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatfs64)
+    mov     x8, __NR_fstatfs
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(fstatfs64)
+
+    .globl fstatfs
+    .equ fstatfs, fstatfs64
diff --git a/libc/arch-arm64/syscalls/fsync.S b/libc/arch-arm64/syscalls/fsync.S
index e1076f2..2bc0d0b 100644
--- a/libc/arch-arm64/syscalls/fsync.S
+++ b/libc/arch-arm64/syscalls/fsync.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(fsync)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_fsync
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(fsync)
diff --git a/libc/arch-arm64/syscalls/ftruncate.S b/libc/arch-arm64/syscalls/ftruncate.S
index 7ed80b9..c6e99f5 100644
--- a/libc/arch-arm64/syscalls/ftruncate.S
+++ b/libc/arch-arm64/syscalls/ftruncate.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(ftruncate)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_ftruncate
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(ftruncate)
 
-    .globl _C_LABEL(ftruncate64)
-    .equ _C_LABEL(ftruncate64), _C_LABEL(ftruncate)
+    .globl ftruncate64
+    .equ ftruncate64, ftruncate
diff --git a/libc/arch-arm64/syscalls/futex.S b/libc/arch-arm64/syscalls/futex.S
deleted file mode 100644
index 5149d6b..0000000
--- a/libc/arch-arm64/syscalls/futex.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(futex)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_futex
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(futex)
diff --git a/libc/arch-arm64/syscalls/getdents.S b/libc/arch-arm64/syscalls/getdents.S
deleted file mode 100644
index 56496c2..0000000
--- a/libc/arch-arm64/syscalls/getdents.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getdents)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_getdents64
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(getdents)
diff --git a/libc/arch-arm64/syscalls/getegid.S b/libc/arch-arm64/syscalls/getegid.S
index 144fe88..f7d60d9 100644
--- a/libc/arch-arm64/syscalls/getegid.S
+++ b/libc/arch-arm64/syscalls/getegid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getegid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getegid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getegid)
diff --git a/libc/arch-arm64/syscalls/geteuid.S b/libc/arch-arm64/syscalls/geteuid.S
index fcec977..3096a92 100644
--- a/libc/arch-arm64/syscalls/geteuid.S
+++ b/libc/arch-arm64/syscalls/geteuid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(geteuid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_geteuid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(geteuid)
diff --git a/libc/arch-arm64/syscalls/getgid.S b/libc/arch-arm64/syscalls/getgid.S
index 0fd172e..2f921ff 100644
--- a/libc/arch-arm64/syscalls/getgid.S
+++ b/libc/arch-arm64/syscalls/getgid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getgid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getgid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getgid)
diff --git a/libc/arch-arm64/syscalls/getgroups.S b/libc/arch-arm64/syscalls/getgroups.S
index 3c12ef4..a9a897e 100644
--- a/libc/arch-arm64/syscalls/getgroups.S
+++ b/libc/arch-arm64/syscalls/getgroups.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getgroups)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getgroups
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getgroups)
diff --git a/libc/arch-arm64/syscalls/getitimer.S b/libc/arch-arm64/syscalls/getitimer.S
index d795cd7..f37063c 100644
--- a/libc/arch-arm64/syscalls/getitimer.S
+++ b/libc/arch-arm64/syscalls/getitimer.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getitimer)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getitimer
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getitimer)
diff --git a/libc/arch-arm64/syscalls/getpeername.S b/libc/arch-arm64/syscalls/getpeername.S
index aea3122..8374d60 100644
--- a/libc/arch-arm64/syscalls/getpeername.S
+++ b/libc/arch-arm64/syscalls/getpeername.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getpeername)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getpeername
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getpeername)
diff --git a/libc/arch-arm64/syscalls/getpgid.S b/libc/arch-arm64/syscalls/getpgid.S
index 1bda83f..ffc0d91 100644
--- a/libc/arch-arm64/syscalls/getpgid.S
+++ b/libc/arch-arm64/syscalls/getpgid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getpgid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getpgid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getpgid)
diff --git a/libc/arch-arm64/syscalls/getpid.S b/libc/arch-arm64/syscalls/getpid.S
deleted file mode 100644
index 3a408c8..0000000
--- a/libc/arch-arm64/syscalls/getpid.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getpid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_getpid
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(getpid)
diff --git a/libc/arch-arm64/syscalls/getppid.S b/libc/arch-arm64/syscalls/getppid.S
index 1b85cef..1e21bdf 100644
--- a/libc/arch-arm64/syscalls/getppid.S
+++ b/libc/arch-arm64/syscalls/getppid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getppid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getppid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getppid)
diff --git a/libc/arch-arm64/syscalls/getresgid.S b/libc/arch-arm64/syscalls/getresgid.S
index ab00b06..b15357a 100644
--- a/libc/arch-arm64/syscalls/getresgid.S
+++ b/libc/arch-arm64/syscalls/getresgid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getresgid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getresgid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getresgid)
diff --git a/libc/arch-arm64/syscalls/getresuid.S b/libc/arch-arm64/syscalls/getresuid.S
index 0ff218a..53de6b7 100644
--- a/libc/arch-arm64/syscalls/getresuid.S
+++ b/libc/arch-arm64/syscalls/getresuid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getresuid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getresuid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getresuid)
diff --git a/libc/arch-arm64/syscalls/getrlimit.S b/libc/arch-arm64/syscalls/getrlimit.S
index 21b471e..518ab73 100644
--- a/libc/arch-arm64/syscalls/getrlimit.S
+++ b/libc/arch-arm64/syscalls/getrlimit.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getrlimit)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getrlimit
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getrlimit)
 
-    .globl _C_LABEL(getrlimit64)
-    .equ _C_LABEL(getrlimit64), _C_LABEL(getrlimit)
+    .globl getrlimit64
+    .equ getrlimit64, getrlimit
diff --git a/libc/arch-arm64/syscalls/getrusage.S b/libc/arch-arm64/syscalls/getrusage.S
index 5e2bace..676221a 100644
--- a/libc/arch-arm64/syscalls/getrusage.S
+++ b/libc/arch-arm64/syscalls/getrusage.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getrusage)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getrusage
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getrusage)
diff --git a/libc/arch-arm64/syscalls/getsid.S b/libc/arch-arm64/syscalls/getsid.S
index c85ca60..cfbdfdb 100644
--- a/libc/arch-arm64/syscalls/getsid.S
+++ b/libc/arch-arm64/syscalls/getsid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getsid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getsid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getsid)
diff --git a/libc/arch-arm64/syscalls/getsockname.S b/libc/arch-arm64/syscalls/getsockname.S
index 1d0279a..4cca55d 100644
--- a/libc/arch-arm64/syscalls/getsockname.S
+++ b/libc/arch-arm64/syscalls/getsockname.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getsockname)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getsockname
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getsockname)
diff --git a/libc/arch-arm64/syscalls/getsockopt.S b/libc/arch-arm64/syscalls/getsockopt.S
index 3bfd5b8..96b8c0f 100644
--- a/libc/arch-arm64/syscalls/getsockopt.S
+++ b/libc/arch-arm64/syscalls/getsockopt.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getsockopt)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getsockopt
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getsockopt)
diff --git a/libc/arch-arm64/syscalls/gettid.S b/libc/arch-arm64/syscalls/gettid.S
deleted file mode 100644
index d8c128e..0000000
--- a/libc/arch-arm64/syscalls/gettid.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(gettid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_gettid
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(gettid)
diff --git a/libc/arch-arm64/syscalls/gettimeofday.S b/libc/arch-arm64/syscalls/gettimeofday.S
deleted file mode 100644
index 4f9ac28..0000000
--- a/libc/arch-arm64/syscalls/gettimeofday.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(gettimeofday)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_gettimeofday
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(gettimeofday)
diff --git a/libc/arch-arm64/syscalls/getuid.S b/libc/arch-arm64/syscalls/getuid.S
index 96198b7..ef95ba7 100644
--- a/libc/arch-arm64/syscalls/getuid.S
+++ b/libc/arch-arm64/syscalls/getuid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getuid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getuid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getuid)
diff --git a/libc/arch-arm64/syscalls/getxattr.S b/libc/arch-arm64/syscalls/getxattr.S
index 11b90aa..2b38f3d 100644
--- a/libc/arch-arm64/syscalls/getxattr.S
+++ b/libc/arch-arm64/syscalls/getxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(getxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_getxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(getxattr)
diff --git a/libc/arch-arm64/syscalls/init_module.S b/libc/arch-arm64/syscalls/init_module.S
index 8648b04..913c7cc 100644
--- a/libc/arch-arm64/syscalls/init_module.S
+++ b/libc/arch-arm64/syscalls/init_module.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(init_module)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_init_module
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(init_module)
diff --git a/libc/arch-arm64/syscalls/inotify_add_watch.S b/libc/arch-arm64/syscalls/inotify_add_watch.S
index 583ab72..83a5b57 100644
--- a/libc/arch-arm64/syscalls/inotify_add_watch.S
+++ b/libc/arch-arm64/syscalls/inotify_add_watch.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(inotify_add_watch)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_inotify_add_watch
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(inotify_add_watch)
diff --git a/libc/arch-arm64/syscalls/inotify_init1.S b/libc/arch-arm64/syscalls/inotify_init1.S
index 3ee946e..d3bc81b 100644
--- a/libc/arch-arm64/syscalls/inotify_init1.S
+++ b/libc/arch-arm64/syscalls/inotify_init1.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(inotify_init1)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_inotify_init1
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(inotify_init1)
diff --git a/libc/arch-arm64/syscalls/inotify_rm_watch.S b/libc/arch-arm64/syscalls/inotify_rm_watch.S
index 3121b51..c44445f 100644
--- a/libc/arch-arm64/syscalls/inotify_rm_watch.S
+++ b/libc/arch-arm64/syscalls/inotify_rm_watch.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(inotify_rm_watch)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_inotify_rm_watch
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(inotify_rm_watch)
diff --git a/libc/arch-arm64/syscalls/ioprio_get.S b/libc/arch-arm64/syscalls/ioprio_get.S
deleted file mode 100644
index 207a4e7..0000000
--- a/libc/arch-arm64/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_ioprio_get
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(ioprio_get)
diff --git a/libc/arch-arm64/syscalls/ioprio_set.S b/libc/arch-arm64/syscalls/ioprio_set.S
deleted file mode 100644
index eb7b026..0000000
--- a/libc/arch-arm64/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_ioprio_set
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(ioprio_set)
diff --git a/libc/arch-arm64/syscalls/kill.S b/libc/arch-arm64/syscalls/kill.S
index 3788df7..0334ff0 100644
--- a/libc/arch-arm64/syscalls/kill.S
+++ b/libc/arch-arm64/syscalls/kill.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(kill)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_kill
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(kill)
diff --git a/libc/arch-arm64/syscalls/klogctl.S b/libc/arch-arm64/syscalls/klogctl.S
index efa8b4a..625f359 100644
--- a/libc/arch-arm64/syscalls/klogctl.S
+++ b/libc/arch-arm64/syscalls/klogctl.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(klogctl)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_syslog
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(klogctl)
diff --git a/libc/arch-arm64/syscalls/lgetxattr.S b/libc/arch-arm64/syscalls/lgetxattr.S
index 1fda092..89db206 100644
--- a/libc/arch-arm64/syscalls/lgetxattr.S
+++ b/libc/arch-arm64/syscalls/lgetxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(lgetxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_lgetxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(lgetxattr)
diff --git a/libc/arch-arm64/syscalls/linkat.S b/libc/arch-arm64/syscalls/linkat.S
index 999c007..62aea3a 100644
--- a/libc/arch-arm64/syscalls/linkat.S
+++ b/libc/arch-arm64/syscalls/linkat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(linkat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_linkat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(linkat)
diff --git a/libc/arch-arm64/syscalls/listen.S b/libc/arch-arm64/syscalls/listen.S
index 8b7fa0f..ba97be9 100644
--- a/libc/arch-arm64/syscalls/listen.S
+++ b/libc/arch-arm64/syscalls/listen.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(listen)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_listen
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(listen)
diff --git a/libc/arch-arm64/syscalls/listxattr.S b/libc/arch-arm64/syscalls/listxattr.S
index cc399a9..48208e6 100644
--- a/libc/arch-arm64/syscalls/listxattr.S
+++ b/libc/arch-arm64/syscalls/listxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(listxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_listxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(listxattr)
diff --git a/libc/arch-arm64/syscalls/llistxattr.S b/libc/arch-arm64/syscalls/llistxattr.S
index 87bfe10..ed66005 100644
--- a/libc/arch-arm64/syscalls/llistxattr.S
+++ b/libc/arch-arm64/syscalls/llistxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(llistxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_llistxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(llistxattr)
diff --git a/libc/arch-arm64/syscalls/lremovexattr.S b/libc/arch-arm64/syscalls/lremovexattr.S
index ad823e4..b5e51c7 100644
--- a/libc/arch-arm64/syscalls/lremovexattr.S
+++ b/libc/arch-arm64/syscalls/lremovexattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(lremovexattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_lremovexattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(lremovexattr)
diff --git a/libc/arch-arm64/syscalls/lseek.S b/libc/arch-arm64/syscalls/lseek.S
index 867bb71..de96df0 100644
--- a/libc/arch-arm64/syscalls/lseek.S
+++ b/libc/arch-arm64/syscalls/lseek.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(lseek)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_lseek
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(lseek)
 
-    .globl _C_LABEL(lseek64)
-    .equ _C_LABEL(lseek64), _C_LABEL(lseek)
+    .globl lseek64
+    .equ lseek64, lseek
diff --git a/libc/arch-arm64/syscalls/lsetxattr.S b/libc/arch-arm64/syscalls/lsetxattr.S
index 683fc2b..b873513 100644
--- a/libc/arch-arm64/syscalls/lsetxattr.S
+++ b/libc/arch-arm64/syscalls/lsetxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(lsetxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_lsetxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(lsetxattr)
diff --git a/libc/arch-arm64/syscalls/madvise.S b/libc/arch-arm64/syscalls/madvise.S
index 8136ec9..6fced41 100644
--- a/libc/arch-arm64/syscalls/madvise.S
+++ b/libc/arch-arm64/syscalls/madvise.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(madvise)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_madvise
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(madvise)
diff --git a/libc/arch-arm64/syscalls/mincore.S b/libc/arch-arm64/syscalls/mincore.S
index 8a8e5a5..5781b4c 100644
--- a/libc/arch-arm64/syscalls/mincore.S
+++ b/libc/arch-arm64/syscalls/mincore.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mincore)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mincore
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mincore)
diff --git a/libc/arch-arm64/syscalls/mkdirat.S b/libc/arch-arm64/syscalls/mkdirat.S
index b3dd838..fa868a2 100644
--- a/libc/arch-arm64/syscalls/mkdirat.S
+++ b/libc/arch-arm64/syscalls/mkdirat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mkdirat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mkdirat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mkdirat)
diff --git a/libc/arch-arm64/syscalls/mknodat.S b/libc/arch-arm64/syscalls/mknodat.S
index aca6786..13632ec 100644
--- a/libc/arch-arm64/syscalls/mknodat.S
+++ b/libc/arch-arm64/syscalls/mknodat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mknodat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mknodat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mknodat)
diff --git a/libc/arch-arm64/syscalls/mlock.S b/libc/arch-arm64/syscalls/mlock.S
index bb01435..1eee85c 100644
--- a/libc/arch-arm64/syscalls/mlock.S
+++ b/libc/arch-arm64/syscalls/mlock.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mlock)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mlock
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mlock)
diff --git a/libc/arch-arm64/syscalls/mlockall.S b/libc/arch-arm64/syscalls/mlockall.S
index 278e6d3..d4ca185 100644
--- a/libc/arch-arm64/syscalls/mlockall.S
+++ b/libc/arch-arm64/syscalls/mlockall.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mlockall)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mlockall
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mlockall)
diff --git a/libc/arch-arm64/syscalls/mmap.S b/libc/arch-arm64/syscalls/mmap.S
index a2d181a..64b955e 100644
--- a/libc/arch-arm64/syscalls/mmap.S
+++ b/libc/arch-arm64/syscalls/mmap.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mmap)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mmap
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mmap)
 
-    .globl _C_LABEL(mmap64)
-    .equ _C_LABEL(mmap64), _C_LABEL(mmap)
+    .globl mmap64
+    .equ mmap64, mmap
diff --git a/libc/arch-arm64/syscalls/mount.S b/libc/arch-arm64/syscalls/mount.S
index d88a54b..cd35017 100644
--- a/libc/arch-arm64/syscalls/mount.S
+++ b/libc/arch-arm64/syscalls/mount.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mount)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mount
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mount)
diff --git a/libc/arch-arm64/syscalls/mprotect.S b/libc/arch-arm64/syscalls/mprotect.S
index c8a2efe..9dd8812 100644
--- a/libc/arch-arm64/syscalls/mprotect.S
+++ b/libc/arch-arm64/syscalls/mprotect.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mprotect)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mprotect
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mprotect)
diff --git a/libc/arch-arm64/syscalls/mremap.S b/libc/arch-arm64/syscalls/mremap.S
index 7c7fe5b..69b91d6 100644
--- a/libc/arch-arm64/syscalls/mremap.S
+++ b/libc/arch-arm64/syscalls/mremap.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(mremap)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_mremap
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(mremap)
diff --git a/libc/arch-arm64/syscalls/msync.S b/libc/arch-arm64/syscalls/msync.S
index b45c99d..72387ea 100644
--- a/libc/arch-arm64/syscalls/msync.S
+++ b/libc/arch-arm64/syscalls/msync.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(msync)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_msync
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(msync)
diff --git a/libc/arch-arm64/syscalls/munlock.S b/libc/arch-arm64/syscalls/munlock.S
index d84b850..d2a248c 100644
--- a/libc/arch-arm64/syscalls/munlock.S
+++ b/libc/arch-arm64/syscalls/munlock.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(munlock)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_munlock
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(munlock)
diff --git a/libc/arch-arm64/syscalls/munlockall.S b/libc/arch-arm64/syscalls/munlockall.S
index e043f71..ac42cb4 100644
--- a/libc/arch-arm64/syscalls/munlockall.S
+++ b/libc/arch-arm64/syscalls/munlockall.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(munlockall)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_munlockall
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(munlockall)
diff --git a/libc/arch-arm64/syscalls/munmap.S b/libc/arch-arm64/syscalls/munmap.S
index 02afbe8..9d3f6a6 100644
--- a/libc/arch-arm64/syscalls/munmap.S
+++ b/libc/arch-arm64/syscalls/munmap.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(munmap)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_munmap
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(munmap)
diff --git a/libc/arch-arm64/syscalls/nanosleep.S b/libc/arch-arm64/syscalls/nanosleep.S
index 8cd9a95..d3e6fae 100644
--- a/libc/arch-arm64/syscalls/nanosleep.S
+++ b/libc/arch-arm64/syscalls/nanosleep.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(nanosleep)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_nanosleep
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(nanosleep)
diff --git a/libc/arch-arm64/syscalls/perf_event_open.S b/libc/arch-arm64/syscalls/perf_event_open.S
deleted file mode 100644
index 3960264..0000000
--- a/libc/arch-arm64/syscalls/perf_event_open.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(perf_event_open)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_perf_event_open
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(perf_event_open)
diff --git a/libc/arch-arm64/syscalls/personality.S b/libc/arch-arm64/syscalls/personality.S
index 2535467..f9f3bf6 100644
--- a/libc/arch-arm64/syscalls/personality.S
+++ b/libc/arch-arm64/syscalls/personality.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(personality)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_personality
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(personality)
diff --git a/libc/arch-arm64/syscalls/pipe2.S b/libc/arch-arm64/syscalls/pipe2.S
index f72e707..89181cd 100644
--- a/libc/arch-arm64/syscalls/pipe2.S
+++ b/libc/arch-arm64/syscalls/pipe2.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(pipe2)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_pipe2
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(pipe2)
diff --git a/libc/arch-arm64/syscalls/prctl.S b/libc/arch-arm64/syscalls/prctl.S
index 79b3e92..86f4df5 100644
--- a/libc/arch-arm64/syscalls/prctl.S
+++ b/libc/arch-arm64/syscalls/prctl.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(prctl)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_prctl
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(prctl)
diff --git a/libc/arch-arm64/syscalls/pread64.S b/libc/arch-arm64/syscalls/pread64.S
index 0d098f1..eafc044 100644
--- a/libc/arch-arm64/syscalls/pread64.S
+++ b/libc/arch-arm64/syscalls/pread64.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(pread64)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_pread64
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(pread64)
 
-    .globl _C_LABEL(pread)
-    .equ _C_LABEL(pread), _C_LABEL(pread64)
+    .globl pread
+    .equ pread, pread64
diff --git a/libc/arch-arm64/syscalls/prlimit64.S b/libc/arch-arm64/syscalls/prlimit64.S
index 439e355..2bece99 100644
--- a/libc/arch-arm64/syscalls/prlimit64.S
+++ b/libc/arch-arm64/syscalls/prlimit64.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(prlimit64)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_prlimit64
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(prlimit64)
 
-    .globl _C_LABEL(prlimit)
-    .equ _C_LABEL(prlimit), _C_LABEL(prlimit64)
+    .globl prlimit
+    .equ prlimit, prlimit64
diff --git a/libc/arch-arm64/syscalls/pwrite64.S b/libc/arch-arm64/syscalls/pwrite64.S
index a10f76f..6970954 100644
--- a/libc/arch-arm64/syscalls/pwrite64.S
+++ b/libc/arch-arm64/syscalls/pwrite64.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(pwrite64)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_pwrite64
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(pwrite64)
 
-    .globl _C_LABEL(pwrite)
-    .equ _C_LABEL(pwrite), _C_LABEL(pwrite64)
+    .globl pwrite
+    .equ pwrite, pwrite64
diff --git a/libc/arch-arm64/syscalls/read.S b/libc/arch-arm64/syscalls/read.S
index cf7ca04..ddb88c8 100644
--- a/libc/arch-arm64/syscalls/read.S
+++ b/libc/arch-arm64/syscalls/read.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(read)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_read
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(read)
diff --git a/libc/arch-arm64/syscalls/readahead.S b/libc/arch-arm64/syscalls/readahead.S
index fe45cf9..445abd4 100644
--- a/libc/arch-arm64/syscalls/readahead.S
+++ b/libc/arch-arm64/syscalls/readahead.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(readahead)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_readahead
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(readahead)
diff --git a/libc/arch-arm64/syscalls/readlinkat.S b/libc/arch-arm64/syscalls/readlinkat.S
index eb8221c..62cc9e2 100644
--- a/libc/arch-arm64/syscalls/readlinkat.S
+++ b/libc/arch-arm64/syscalls/readlinkat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(readlinkat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_readlinkat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(readlinkat)
diff --git a/libc/arch-arm64/syscalls/readv.S b/libc/arch-arm64/syscalls/readv.S
index f4fa612..6e7f151 100644
--- a/libc/arch-arm64/syscalls/readv.S
+++ b/libc/arch-arm64/syscalls/readv.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(readv)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_readv
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(readv)
diff --git a/libc/arch-arm64/syscalls/recvfrom.S b/libc/arch-arm64/syscalls/recvfrom.S
index 51ac25f..aecf165 100644
--- a/libc/arch-arm64/syscalls/recvfrom.S
+++ b/libc/arch-arm64/syscalls/recvfrom.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(recvfrom)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_recvfrom
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(recvfrom)
diff --git a/libc/arch-arm64/syscalls/recvmmsg.S b/libc/arch-arm64/syscalls/recvmmsg.S
new file mode 100644
index 0000000..b9cae69
--- /dev/null
+++ b/libc/arch-arm64/syscalls/recvmmsg.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(recvmmsg)
+    mov     x8, __NR_recvmmsg
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(recvmmsg)
diff --git a/libc/arch-arm64/syscalls/recvmsg.S b/libc/arch-arm64/syscalls/recvmsg.S
index 4ca40ea..2dafdc9 100644
--- a/libc/arch-arm64/syscalls/recvmsg.S
+++ b/libc/arch-arm64/syscalls/recvmsg.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(recvmsg)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_recvmsg
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(recvmsg)
diff --git a/libc/arch-arm64/syscalls/removexattr.S b/libc/arch-arm64/syscalls/removexattr.S
index ae53307..ede36a6 100644
--- a/libc/arch-arm64/syscalls/removexattr.S
+++ b/libc/arch-arm64/syscalls/removexattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(removexattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_removexattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(removexattr)
diff --git a/libc/arch-arm64/syscalls/renameat.S b/libc/arch-arm64/syscalls/renameat.S
index 3f6e4d4..96025df 100644
--- a/libc/arch-arm64/syscalls/renameat.S
+++ b/libc/arch-arm64/syscalls/renameat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(renameat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_renameat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(renameat)
diff --git a/libc/arch-arm64/syscalls/sched_get_priority_max.S b/libc/arch-arm64/syscalls/sched_get_priority_max.S
index 735ca93..c848889 100644
--- a/libc/arch-arm64/syscalls/sched_get_priority_max.S
+++ b/libc/arch-arm64/syscalls/sched_get_priority_max.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_get_priority_max)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_get_priority_max
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_get_priority_max)
diff --git a/libc/arch-arm64/syscalls/sched_get_priority_min.S b/libc/arch-arm64/syscalls/sched_get_priority_min.S
index a453b0b..74b72a2 100644
--- a/libc/arch-arm64/syscalls/sched_get_priority_min.S
+++ b/libc/arch-arm64/syscalls/sched_get_priority_min.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_get_priority_min)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_get_priority_min
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_get_priority_min)
diff --git a/libc/arch-arm64/syscalls/sched_getparam.S b/libc/arch-arm64/syscalls/sched_getparam.S
index f3492b9..75a32d4 100644
--- a/libc/arch-arm64/syscalls/sched_getparam.S
+++ b/libc/arch-arm64/syscalls/sched_getparam.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_getparam)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_getparam
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_getparam)
diff --git a/libc/arch-arm64/syscalls/sched_getscheduler.S b/libc/arch-arm64/syscalls/sched_getscheduler.S
index db944f1..e24baf2 100644
--- a/libc/arch-arm64/syscalls/sched_getscheduler.S
+++ b/libc/arch-arm64/syscalls/sched_getscheduler.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_getscheduler)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_getscheduler
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_getscheduler)
diff --git a/libc/arch-arm64/syscalls/sched_rr_get_interval.S b/libc/arch-arm64/syscalls/sched_rr_get_interval.S
index b91f646..2a6936b 100644
--- a/libc/arch-arm64/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-arm64/syscalls/sched_rr_get_interval.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_rr_get_interval)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_rr_get_interval
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_rr_get_interval)
diff --git a/libc/arch-arm64/syscalls/sched_setaffinity.S b/libc/arch-arm64/syscalls/sched_setaffinity.S
index e8e1aec..30b58f6 100644
--- a/libc/arch-arm64/syscalls/sched_setaffinity.S
+++ b/libc/arch-arm64/syscalls/sched_setaffinity.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_setaffinity)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_setaffinity
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_setaffinity)
diff --git a/libc/arch-arm64/syscalls/sched_setparam.S b/libc/arch-arm64/syscalls/sched_setparam.S
index 5df84f0..eaf25ba 100644
--- a/libc/arch-arm64/syscalls/sched_setparam.S
+++ b/libc/arch-arm64/syscalls/sched_setparam.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_setparam)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_setparam
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_setparam)
diff --git a/libc/arch-arm64/syscalls/sched_setscheduler.S b/libc/arch-arm64/syscalls/sched_setscheduler.S
index 83c31e4..31d53c4 100644
--- a/libc/arch-arm64/syscalls/sched_setscheduler.S
+++ b/libc/arch-arm64/syscalls/sched_setscheduler.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_setscheduler)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_setscheduler
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_setscheduler)
diff --git a/libc/arch-arm64/syscalls/sched_yield.S b/libc/arch-arm64/syscalls/sched_yield.S
index 7d5f88b..4cfeeda 100644
--- a/libc/arch-arm64/syscalls/sched_yield.S
+++ b/libc/arch-arm64/syscalls/sched_yield.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sched_yield)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sched_yield
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sched_yield)
diff --git a/libc/arch-arm64/syscalls/sendfile.S b/libc/arch-arm64/syscalls/sendfile.S
index e540296..17a0d46 100644
--- a/libc/arch-arm64/syscalls/sendfile.S
+++ b/libc/arch-arm64/syscalls/sendfile.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sendfile)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sendfile
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sendfile)
 
-    .globl _C_LABEL(sendfile64)
-    .equ _C_LABEL(sendfile64), _C_LABEL(sendfile)
+    .globl sendfile64
+    .equ sendfile64, sendfile
diff --git a/libc/arch-arm64/syscalls/sendmmsg.S b/libc/arch-arm64/syscalls/sendmmsg.S
new file mode 100644
index 0000000..e91c246
--- /dev/null
+++ b/libc/arch-arm64/syscalls/sendmmsg.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendmmsg)
+    mov     x8, __NR_sendmmsg
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(sendmmsg)
diff --git a/libc/arch-arm64/syscalls/sendmsg.S b/libc/arch-arm64/syscalls/sendmsg.S
index 2f0cdc8..a343543 100644
--- a/libc/arch-arm64/syscalls/sendmsg.S
+++ b/libc/arch-arm64/syscalls/sendmsg.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sendmsg)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sendmsg
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sendmsg)
diff --git a/libc/arch-arm64/syscalls/sendto.S b/libc/arch-arm64/syscalls/sendto.S
index 3fd54d1..6a6813e 100644
--- a/libc/arch-arm64/syscalls/sendto.S
+++ b/libc/arch-arm64/syscalls/sendto.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sendto)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sendto
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sendto)
diff --git a/libc/arch-arm64/syscalls/setfsgid.S b/libc/arch-arm64/syscalls/setfsgid.S
new file mode 100644
index 0000000..1a45df3
--- /dev/null
+++ b/libc/arch-arm64/syscalls/setfsgid.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsgid)
+    mov     x8, __NR_setfsgid
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(setfsgid)
diff --git a/libc/arch-arm64/syscalls/setfsuid.S b/libc/arch-arm64/syscalls/setfsuid.S
new file mode 100644
index 0000000..cd4efd7
--- /dev/null
+++ b/libc/arch-arm64/syscalls/setfsuid.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsuid)
+    mov     x8, __NR_setfsuid
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(setfsuid)
diff --git a/libc/arch-arm64/syscalls/setgid.S b/libc/arch-arm64/syscalls/setgid.S
index 0a811b0..c128fb9 100644
--- a/libc/arch-arm64/syscalls/setgid.S
+++ b/libc/arch-arm64/syscalls/setgid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setgid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setgid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setgid)
diff --git a/libc/arch-arm64/syscalls/setgroups.S b/libc/arch-arm64/syscalls/setgroups.S
index d316e5e..aedabd6 100644
--- a/libc/arch-arm64/syscalls/setgroups.S
+++ b/libc/arch-arm64/syscalls/setgroups.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setgroups)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setgroups
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setgroups)
diff --git a/libc/arch-arm64/syscalls/setitimer.S b/libc/arch-arm64/syscalls/setitimer.S
index 7c2b718..7ce8617 100644
--- a/libc/arch-arm64/syscalls/setitimer.S
+++ b/libc/arch-arm64/syscalls/setitimer.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setitimer)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setitimer
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setitimer)
diff --git a/libc/arch-arm64/syscalls/setns.S b/libc/arch-arm64/syscalls/setns.S
index 2ce2a75..386e8f4 100644
--- a/libc/arch-arm64/syscalls/setns.S
+++ b/libc/arch-arm64/syscalls/setns.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setns)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setns
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setns)
diff --git a/libc/arch-arm64/syscalls/setpgid.S b/libc/arch-arm64/syscalls/setpgid.S
index bd12e70..458c88b 100644
--- a/libc/arch-arm64/syscalls/setpgid.S
+++ b/libc/arch-arm64/syscalls/setpgid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setpgid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setpgid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setpgid)
diff --git a/libc/arch-arm64/syscalls/setpriority.S b/libc/arch-arm64/syscalls/setpriority.S
index d9a4857..ed58f26 100644
--- a/libc/arch-arm64/syscalls/setpriority.S
+++ b/libc/arch-arm64/syscalls/setpriority.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setpriority)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setpriority
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setpriority)
diff --git a/libc/arch-arm64/syscalls/setregid.S b/libc/arch-arm64/syscalls/setregid.S
index 702ae8b..30d902d 100644
--- a/libc/arch-arm64/syscalls/setregid.S
+++ b/libc/arch-arm64/syscalls/setregid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setregid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setregid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setregid)
diff --git a/libc/arch-arm64/syscalls/setresgid.S b/libc/arch-arm64/syscalls/setresgid.S
index c9501ac..f56e6ce 100644
--- a/libc/arch-arm64/syscalls/setresgid.S
+++ b/libc/arch-arm64/syscalls/setresgid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setresgid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setresgid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setresgid)
diff --git a/libc/arch-arm64/syscalls/setresuid.S b/libc/arch-arm64/syscalls/setresuid.S
index 6f680c3..d5c5cc6 100644
--- a/libc/arch-arm64/syscalls/setresuid.S
+++ b/libc/arch-arm64/syscalls/setresuid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setresuid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setresuid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setresuid)
diff --git a/libc/arch-arm64/syscalls/setreuid.S b/libc/arch-arm64/syscalls/setreuid.S
index ef870fa..e76c72e 100644
--- a/libc/arch-arm64/syscalls/setreuid.S
+++ b/libc/arch-arm64/syscalls/setreuid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setreuid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setreuid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setreuid)
diff --git a/libc/arch-arm64/syscalls/setrlimit.S b/libc/arch-arm64/syscalls/setrlimit.S
index e723806..6cb6b98 100644
--- a/libc/arch-arm64/syscalls/setrlimit.S
+++ b/libc/arch-arm64/syscalls/setrlimit.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setrlimit)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setrlimit
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setrlimit)
 
-    .globl _C_LABEL(setrlimit64)
-    .equ _C_LABEL(setrlimit64), _C_LABEL(setrlimit)
+    .globl setrlimit64
+    .equ setrlimit64, setrlimit
diff --git a/libc/arch-arm64/syscalls/setsid.S b/libc/arch-arm64/syscalls/setsid.S
index c9ba594..1bb4cc7 100644
--- a/libc/arch-arm64/syscalls/setsid.S
+++ b/libc/arch-arm64/syscalls/setsid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setsid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setsid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setsid)
diff --git a/libc/arch-arm64/syscalls/setsockopt.S b/libc/arch-arm64/syscalls/setsockopt.S
index 7c9d584..14b0136 100644
--- a/libc/arch-arm64/syscalls/setsockopt.S
+++ b/libc/arch-arm64/syscalls/setsockopt.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setsockopt)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setsockopt
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setsockopt)
diff --git a/libc/arch-arm64/syscalls/settimeofday.S b/libc/arch-arm64/syscalls/settimeofday.S
index 4cf6ff2..4f0a078 100644
--- a/libc/arch-arm64/syscalls/settimeofday.S
+++ b/libc/arch-arm64/syscalls/settimeofday.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(settimeofday)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_settimeofday
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(settimeofday)
diff --git a/libc/arch-arm64/syscalls/setuid.S b/libc/arch-arm64/syscalls/setuid.S
index a886c15..5500dd6 100644
--- a/libc/arch-arm64/syscalls/setuid.S
+++ b/libc/arch-arm64/syscalls/setuid.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setuid)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setuid
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setuid)
diff --git a/libc/arch-arm64/syscalls/setxattr.S b/libc/arch-arm64/syscalls/setxattr.S
index 1d25f3a..5ba9e3c 100644
--- a/libc/arch-arm64/syscalls/setxattr.S
+++ b/libc/arch-arm64/syscalls/setxattr.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(setxattr)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_setxattr
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(setxattr)
diff --git a/libc/arch-arm64/syscalls/shutdown.S b/libc/arch-arm64/syscalls/shutdown.S
index b9fc3c3..ab067fa 100644
--- a/libc/arch-arm64/syscalls/shutdown.S
+++ b/libc/arch-arm64/syscalls/shutdown.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(shutdown)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_shutdown
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(shutdown)
diff --git a/libc/arch-arm64/syscalls/sigaltstack.S b/libc/arch-arm64/syscalls/sigaltstack.S
index 6052caa..a9cbcaf 100644
--- a/libc/arch-arm64/syscalls/sigaltstack.S
+++ b/libc/arch-arm64/syscalls/sigaltstack.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sigaltstack)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sigaltstack
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sigaltstack)
diff --git a/libc/arch-arm64/syscalls/signalfd4.S b/libc/arch-arm64/syscalls/signalfd4.S
deleted file mode 100644
index 7a8f7f7..0000000
--- a/libc/arch-arm64/syscalls/signalfd4.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(signalfd4)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_signalfd4
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(signalfd4)
diff --git a/libc/arch-arm64/syscalls/socket.S b/libc/arch-arm64/syscalls/socket.S
deleted file mode 100644
index 37a3851..0000000
--- a/libc/arch-arm64/syscalls/socket.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(socket)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_socket
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(socket)
diff --git a/libc/arch-arm64/syscalls/socketpair.S b/libc/arch-arm64/syscalls/socketpair.S
index 05e617b..bd70dac 100644
--- a/libc/arch-arm64/syscalls/socketpair.S
+++ b/libc/arch-arm64/syscalls/socketpair.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(socketpair)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_socketpair
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(socketpair)
diff --git a/libc/arch-arm64/syscalls/splice.S b/libc/arch-arm64/syscalls/splice.S
new file mode 100644
index 0000000..a5450d9
--- /dev/null
+++ b/libc/arch-arm64/syscalls/splice.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    mov     x8, __NR_splice
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(splice)
diff --git a/libc/arch-arm64/syscalls/statfs.S b/libc/arch-arm64/syscalls/statfs.S
deleted file mode 100644
index 9bfae63..0000000
--- a/libc/arch-arm64/syscalls/statfs.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(statfs)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_statfs
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(statfs)
diff --git a/libc/arch-arm64/syscalls/statfs64.S b/libc/arch-arm64/syscalls/statfs64.S
new file mode 100644
index 0000000..ec8c588
--- /dev/null
+++ b/libc/arch-arm64/syscalls/statfs64.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(statfs64)
+    mov     x8, __NR_statfs
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(statfs64)
+
+    .globl statfs
+    .equ statfs, statfs64
diff --git a/libc/arch-arm64/syscalls/swapoff.S b/libc/arch-arm64/syscalls/swapoff.S
index 742b460..0103bd7 100644
--- a/libc/arch-arm64/syscalls/swapoff.S
+++ b/libc/arch-arm64/syscalls/swapoff.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(swapoff)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_swapoff
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(swapoff)
diff --git a/libc/arch-arm64/syscalls/swapon.S b/libc/arch-arm64/syscalls/swapon.S
index b82d7de..560c960 100644
--- a/libc/arch-arm64/syscalls/swapon.S
+++ b/libc/arch-arm64/syscalls/swapon.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(swapon)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_swapon
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(swapon)
diff --git a/libc/arch-arm64/syscalls/symlinkat.S b/libc/arch-arm64/syscalls/symlinkat.S
index c6a8313..4a4ea27 100644
--- a/libc/arch-arm64/syscalls/symlinkat.S
+++ b/libc/arch-arm64/syscalls/symlinkat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(symlinkat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_symlinkat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(symlinkat)
diff --git a/libc/arch-arm64/syscalls/sync.S b/libc/arch-arm64/syscalls/sync.S
index 1954fe8..d285d43 100644
--- a/libc/arch-arm64/syscalls/sync.S
+++ b/libc/arch-arm64/syscalls/sync.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sync)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sync
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sync)
diff --git a/libc/arch-arm64/syscalls/sysinfo.S b/libc/arch-arm64/syscalls/sysinfo.S
index cb91550..80a8641 100644
--- a/libc/arch-arm64/syscalls/sysinfo.S
+++ b/libc/arch-arm64/syscalls/sysinfo.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(sysinfo)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_sysinfo
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(sysinfo)
diff --git a/libc/arch-arm64/syscalls/tee.S b/libc/arch-arm64/syscalls/tee.S
new file mode 100644
index 0000000..d7baa26
--- /dev/null
+++ b/libc/arch-arm64/syscalls/tee.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(tee)
+    mov     x8, __NR_tee
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(tee)
diff --git a/libc/arch-arm64/syscalls/tgkill.S b/libc/arch-arm64/syscalls/tgkill.S
index a401819..fd9ec3b 100644
--- a/libc/arch-arm64/syscalls/tgkill.S
+++ b/libc/arch-arm64/syscalls/tgkill.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(tgkill)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_tgkill
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(tgkill)
diff --git a/libc/arch-arm64/syscalls/timerfd_create.S b/libc/arch-arm64/syscalls/timerfd_create.S
index e0558be..ee805fd 100644
--- a/libc/arch-arm64/syscalls/timerfd_create.S
+++ b/libc/arch-arm64/syscalls/timerfd_create.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(timerfd_create)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_timerfd_create
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(timerfd_create)
diff --git a/libc/arch-arm64/syscalls/timerfd_gettime.S b/libc/arch-arm64/syscalls/timerfd_gettime.S
index 09234cd..4d5e2f9 100644
--- a/libc/arch-arm64/syscalls/timerfd_gettime.S
+++ b/libc/arch-arm64/syscalls/timerfd_gettime.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(timerfd_gettime)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_timerfd_gettime
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(timerfd_gettime)
diff --git a/libc/arch-arm64/syscalls/timerfd_settime.S b/libc/arch-arm64/syscalls/timerfd_settime.S
index cc205ad..e925a0c 100644
--- a/libc/arch-arm64/syscalls/timerfd_settime.S
+++ b/libc/arch-arm64/syscalls/timerfd_settime.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(timerfd_settime)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_timerfd_settime
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(timerfd_settime)
diff --git a/libc/arch-arm64/syscalls/times.S b/libc/arch-arm64/syscalls/times.S
index c5fe38b..d7b9c74 100644
--- a/libc/arch-arm64/syscalls/times.S
+++ b/libc/arch-arm64/syscalls/times.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(times)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_times
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(times)
diff --git a/libc/arch-arm64/syscalls/tkill.S b/libc/arch-arm64/syscalls/tkill.S
deleted file mode 100644
index 0b910fc..0000000
--- a/libc/arch-arm64/syscalls/tkill.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(tkill)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
-    mov     x8, __NR_tkill
-    svc     #0
-
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
-    cmn     x0, #(MAX_ERRNO + 1)
-    cneg    x0, x0, hi
-    b.hi    __set_errno
-
-    ret
-END(tkill)
diff --git a/libc/arch-arm64/syscalls/truncate.S b/libc/arch-arm64/syscalls/truncate.S
index f254c34..0e5a33e 100644
--- a/libc/arch-arm64/syscalls/truncate.S
+++ b/libc/arch-arm64/syscalls/truncate.S
@@ -3,22 +3,15 @@
 #include <private/bionic_asm.h>
 
 ENTRY(truncate)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_truncate
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(truncate)
 
-    .globl _C_LABEL(truncate64)
-    .equ _C_LABEL(truncate64), _C_LABEL(truncate)
+    .globl truncate64
+    .equ truncate64, truncate
diff --git a/libc/arch-arm64/syscalls/umask.S b/libc/arch-arm64/syscalls/umask.S
index 70a3e01..0d71fa6 100644
--- a/libc/arch-arm64/syscalls/umask.S
+++ b/libc/arch-arm64/syscalls/umask.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(umask)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_umask
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(umask)
diff --git a/libc/arch-arm64/syscalls/umount2.S b/libc/arch-arm64/syscalls/umount2.S
index cdd0362..c25344e 100644
--- a/libc/arch-arm64/syscalls/umount2.S
+++ b/libc/arch-arm64/syscalls/umount2.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(umount2)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_umount2
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(umount2)
diff --git a/libc/arch-arm64/syscalls/uname.S b/libc/arch-arm64/syscalls/uname.S
index c242786..dfdcc03 100644
--- a/libc/arch-arm64/syscalls/uname.S
+++ b/libc/arch-arm64/syscalls/uname.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(uname)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_uname
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(uname)
diff --git a/libc/arch-arm64/syscalls/unlinkat.S b/libc/arch-arm64/syscalls/unlinkat.S
index f7bb2c5..b1eba63 100644
--- a/libc/arch-arm64/syscalls/unlinkat.S
+++ b/libc/arch-arm64/syscalls/unlinkat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(unlinkat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_unlinkat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(unlinkat)
diff --git a/libc/arch-arm64/syscalls/unshare.S b/libc/arch-arm64/syscalls/unshare.S
index c9bd497..74f5663 100644
--- a/libc/arch-arm64/syscalls/unshare.S
+++ b/libc/arch-arm64/syscalls/unshare.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(unshare)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_unshare
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(unshare)
diff --git a/libc/arch-arm64/syscalls/utimensat.S b/libc/arch-arm64/syscalls/utimensat.S
index 62c98a6..b8c6b04 100644
--- a/libc/arch-arm64/syscalls/utimensat.S
+++ b/libc/arch-arm64/syscalls/utimensat.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(utimensat)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_utimensat
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(utimensat)
diff --git a/libc/arch-arm64/syscalls/vmsplice.S b/libc/arch-arm64/syscalls/vmsplice.S
new file mode 100644
index 0000000..9490efb
--- /dev/null
+++ b/libc/arch-arm64/syscalls/vmsplice.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(vmsplice)
+    mov     x8, __NR_vmsplice
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(vmsplice)
diff --git a/libc/arch-arm64/syscalls/wait4.S b/libc/arch-arm64/syscalls/wait4.S
index 7431535..12973b8 100644
--- a/libc/arch-arm64/syscalls/wait4.S
+++ b/libc/arch-arm64/syscalls/wait4.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(wait4)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_wait4
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(wait4)
diff --git a/libc/arch-arm64/syscalls/write.S b/libc/arch-arm64/syscalls/write.S
index 2f95f5d..e8c3270 100644
--- a/libc/arch-arm64/syscalls/write.S
+++ b/libc/arch-arm64/syscalls/write.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(write)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_write
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(write)
diff --git a/libc/arch-arm64/syscalls/writev.S b/libc/arch-arm64/syscalls/writev.S
index 015c1d3..baaffda 100644
--- a/libc/arch-arm64/syscalls/writev.S
+++ b/libc/arch-arm64/syscalls/writev.S
@@ -3,19 +3,12 @@
 #include <private/bionic_asm.h>
 
 ENTRY(writev)
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, __NR_writev
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(writev)
diff --git a/libc/arch-common/bionic/atexit.h b/libc/arch-common/bionic/atexit.h
index 16ae7aa..90aa030 100644
--- a/libc/arch-common/bionic/atexit.h
+++ b/libc/arch-common/bionic/atexit.h
@@ -26,11 +26,20 @@
  * SUCH DAMAGE.
  */
 
+#include <stddef.h>
+
 extern void* __dso_handle;
 
 extern int __cxa_atexit(void (*)(void*), void*, void*);
 
 __attribute__ ((visibility ("hidden")))
+void __atexit_handler_wrapper(void* func) {
+  if (func != NULL) {
+    (*(void (*)(void))func)();
+  }
+}
+
+__attribute__ ((visibility ("hidden")))
 int atexit(void (*func)(void)) {
-  return (__cxa_atexit((void (*)(void*)) func, (void*) 0, &__dso_handle));
+  return (__cxa_atexit(&__atexit_handler_wrapper, func, &__dso_handle));
 }
diff --git a/libc/arch-mips/bionic/__bionic_clone.S b/libc/arch-mips/bionic/__bionic_clone.S
index 8970b6e..b216efe 100644
--- a/libc/arch-mips/bionic/__bionic_clone.S
+++ b/libc/arch-mips/bionic/__bionic_clone.S
@@ -26,49 +26,47 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
+#include <private/bionic_asm.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
-	.text
-	.type __bionic_clone, @function
-	.global __bionic_clone
-	.align 4
-        .ent __bionic_clone
-__bionic_clone:
+ENTRY(__bionic_clone)
         .set	noreorder
-        .cpload $t9
+        .cpload t9
         .set	reorder
 
 	# set up child stack
-	subu	$a1,16
-	lw	$t0,20($sp)     # fn
-	lw	$t1,24($sp)     # arg
-	sw	$t0,0($a1)	# fn
-	sw	$t1,4($a1)	# arg
+	subu	a1,16
+	lw	t0,20(sp)     # fn
+	lw	t1,24(sp)     # arg
+	sw	t0,0(a1)	# fn
+	sw	t1,4(a1)	# arg
 
 	# remainder of arguments are correct for clone system call
-        li	$v0,__NR_clone
+        li	v0,__NR_clone
         syscall
 
-        bnez	$a3,.L__error_bc
+        bnez	a3,.L__error_bc
 
-        beqz	$v0,.L__thread_start_bc
+        beqz	v0,.L__thread_start_bc
 
-        j $ra
+        j ra
 
 .L__thread_start_bc:
-        lw	$a0,0($sp)	#  fn
-        lw	$a1,4($sp)	#  arg
+        # Clear return address in child so we don't unwind further.
+        li      ra,0
 
-	# void __bionic_clone_entry(int (*func)(void*), void *arg)
-        la	$t9,__bionic_clone_entry
-        j	$t9
+        lw	a0,0(sp)	#  fn
+        lw	a1,4(sp)	#  arg
+
+	# void __start_thread(int (*func)(void*), void *arg)
+        la	t9,__start_thread
+        j	t9
 
 .L__error_bc:
-	move	$a0,$v0
-	la	$t9,__set_errno
-	j	$t9
-
-        .end __bionic_clone
+	move	a0,v0
+	la	t9,__set_errno_internal
+	j	t9
+END(__bionic_clone)
+.hidden __bionic_clone
diff --git a/libc/arch-mips/bionic/__get_sp.S b/libc/arch-mips/bionic/__get_sp.S
deleted file mode 100644
index 834c89d..0000000
--- a/libc/arch-mips/bionic/__get_sp.S
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-	.text
-
-/* void *__get_sp(void) */
-
-	.type	__get_sp, @function
-	.global	__get_sp
-	.align	4
-	.ent	__get_sp
-__get_sp:
-	move	$v0, $sp
-	j	$ra
-	.end	__get_sp
diff --git a/libc/arch-mips/bionic/__set_tls.c b/libc/arch-mips/bionic/__set_tls.c
deleted file mode 100644
index 38e3a50..0000000
--- a/libc/arch-mips/bionic/__set_tls.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <pthread.h>
-
-extern int __set_thread_area(void *u_info);
-
-int __set_tls(void *ptr)
-{
-    return __set_thread_area(ptr);
-}
diff --git a/libc/arch-mips/bionic/_exit_with_stack_teardown.S b/libc/arch-mips/bionic/_exit_with_stack_teardown.S
index 8f624c3..7d47160 100644
--- a/libc/arch-mips/bionic/_exit_with_stack_teardown.S
+++ b/libc/arch-mips/bionic/_exit_with_stack_teardown.S
@@ -26,23 +26,16 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-
-	.text
+#include <private/bionic_asm.h>
 
 // void _exit_with_stack_teardown(void* stackBase, size_t stackSize)
-
-	.type	_exit_with_stack_teardown, @function
-	.global	_exit_with_stack_teardown
-	.align	4
-	.ent	_exit_with_stack_teardown
-_exit_with_stack_teardown:
-	li	$v0, __NR_munmap
+ENTRY_PRIVATE(_exit_with_stack_teardown)
+	li	v0, __NR_munmap
 	syscall
 	// If munmap failed, we ignore the failure and exit anyway.
 
-	li	$a0, 0
-	li	$v0, __NR_exit
+	li	a0, 0
+	li	v0, __NR_exit
 	syscall
         // The exit syscall does not return.
-	.end	_exit_with_stack_teardown
+END(_exit_with_stack_teardown)
diff --git a/libc/arch-mips/bionic/_setjmp.S b/libc/arch-mips/bionic/_setjmp.S
index e7083ae..d237e6d 100644
--- a/libc/arch-mips/bionic/_setjmp.S
+++ b/libc/arch-mips/bionic/_setjmp.S
@@ -2,7 +2,7 @@
 
 /*
  * Copyright (c) 2002 Opsycon AB  (www.opsycon.se / www.opsycon.com)
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -29,7 +29,7 @@
  *
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/signal.h>
 
@@ -44,17 +44,6 @@
 FRAMESZ= MKFSIZ(0,4)
 GPOFF= FRAMESZ-2*REGSZ
 
-#define FPREG64_S(FPR, OFF, BASE)       \
-        swc1    FPR, OFF(BASE)  ;       \
-        mfhc1   t0, FPR         ;       \
-        sw      t0, OFF+4(BASE) ;
-        
-#define FPREG64_L(FPR, OFF, BASE)       \
-        lw      t0, OFF+4(BASE) ;       \
-        lw      t1, OFF(BASE)   ;       \
-        mtc1    t1, FPR         ;       \
-        mthc1   t0, FPR         ;       \
-        
 LEAF(_setjmp, FRAMESZ)
 	PTR_SUBU sp, FRAMESZ
 	SETUP_GP64(GPOFF, _setjmp)
@@ -85,32 +74,19 @@
 	li	v0, 1				# be nice if we could tell
 	REG_S	v0, SC_FPUSED(a0)		# sc_fpused = 1
 	cfc1	v0, $31
+	s.d	$f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
+	s.d	$f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
+	s.d	$f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
+	s.d	$f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
+	s.d	$f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
+	s.d	$f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
 #if _MIPS_FPSET == 32
-        FPREG64_S($f20, SC_FPREGS+((F20-F0)*REGSZ_FP), a0)
-        FPREG64_S($f21, SC_FPREGS+((F21-F0)*REGSZ_FP), a0)
-        FPREG64_S($f22, SC_FPREGS+((F22-F0)*REGSZ_FP), a0)
-        FPREG64_S($f23, SC_FPREGS+((F23-F0)*REGSZ_FP), a0)
-        FPREG64_S($f24, SC_FPREGS+((F24-F0)*REGSZ_FP), a0)
-        FPREG64_S($f25, SC_FPREGS+((F25-F0)*REGSZ_FP), a0)
-        FPREG64_S($f26, SC_FPREGS+((F26-F0)*REGSZ_FP), a0)
-        FPREG64_S($f27, SC_FPREGS+((F27-F0)*REGSZ_FP), a0)
-        FPREG64_S($f28, SC_FPREGS+((F28-F0)*REGSZ_FP), a0)
-        FPREG64_S($f29, SC_FPREGS+((F29-F0)*REGSZ_FP), a0)
-        FPREG64_S($f30, SC_FPREGS+((F30-F0)*REGSZ_FP), a0)
-        FPREG64_S($f31, SC_FPREGS+((F31-F0)*REGSZ_FP), a0)
-#else
-        swc1    $f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
-        swc1    $f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
-        swc1    $f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
-        swc1    $f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
-        swc1    $f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
-        swc1    $f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
-        swc1    $f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
-        swc1    $f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
-        swc1    $f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
-        swc1    $f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
-        swc1    $f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
-        swc1    $f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
+	s.d	$f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
+	s.d	$f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
+	s.d	$f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
+	s.d	$f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
+	s.d	$f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
+	s.d	$f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
 #endif
 	REG_S	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
 #endif /* !SOFTFLOAT */
@@ -142,32 +118,19 @@
 	REG_L	sp, SC_REGS+SP*REGSZ(a0)
 #if !defined(SOFTFLOAT)
 	ctc1	v0, $31
+	l.d	$f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
+	l.d	$f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
+	l.d	$f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
+	l.d	$f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
+	l.d	$f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
+	l.d	$f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
 #if _MIPS_FPSET == 32
-        FPREG64_L($f20, SC_FPREGS+((F20-F0)*REGSZ_FP), a0)
-        FPREG64_L($f21, SC_FPREGS+((F21-F0)*REGSZ_FP), a0)
-        FPREG64_L($f22, SC_FPREGS+((F22-F0)*REGSZ_FP), a0)
-        FPREG64_L($f23, SC_FPREGS+((F23-F0)*REGSZ_FP), a0)
-        FPREG64_L($f24, SC_FPREGS+((F24-F0)*REGSZ_FP), a0)
-        FPREG64_L($f25, SC_FPREGS+((F25-F0)*REGSZ_FP), a0)
-        FPREG64_L($f26, SC_FPREGS+((F26-F0)*REGSZ_FP), a0)
-        FPREG64_L($f27, SC_FPREGS+((F27-F0)*REGSZ_FP), a0)
-        FPREG64_L($f28, SC_FPREGS+((F28-F0)*REGSZ_FP), a0)
-        FPREG64_L($f29, SC_FPREGS+((F29-F0)*REGSZ_FP), a0)
-        FPREG64_L($f30, SC_FPREGS+((F30-F0)*REGSZ_FP), a0)
-        FPREG64_L($f31, SC_FPREGS+((F31-F0)*REGSZ_FP), a0)
-#else
-        lwc1    $f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
-        lwc1    $f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
-        lwc1    $f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
-        lwc1    $f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
-        lwc1    $f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
-        lwc1    $f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
-        lwc1    $f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
-        lwc1    $f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
-        lwc1    $f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
-        lwc1    $f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
-        lwc1    $f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
-        lwc1    $f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
+	l.d	$f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
+	l.d	$f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
+	l.d	$f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
+	l.d	$f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
+	l.d	$f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
+	l.d	$f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
 #endif
 #endif /* !SOFTFLOAT */
 	bne	a1, zero, 1f
@@ -185,4 +148,3 @@
 	RESTORE_GP64
 	PTR_ADDU sp, FRAMESZ
 END(_longjmp)
-
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/arch-mips/bionic/bzero.S
index 6739345..6e5d294 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/arch-mips/bionic/bzero.S
@@ -25,21 +25,15 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-	.text
 
-/*
- * void bzero(void *s, size_t n);
- */
-	.type	bzero, @function
-	.global	bzero
-	.align	4
-	.ent	bzero
+#include <private/bionic_asm.h>
+
+// void bzero(void*, size_t);
+ENTRY(bzero)
 	.set	noreorder
-bzero:
-	.cpload	$t9
-	move	$a2,$a1
-	la	$t9,memset
-	j	$t9
-	 move	$a1,$zero
-	.end	bzero
-
+	.cpload	t9
+	move	a2,a1
+	la	t9,memset
+	j	t9
+	 move	a1,zero
+END(bzero)
diff --git a/libc/arch-mips/bionic/cacheflush.cpp b/libc/arch-mips/bionic/cacheflush.cpp
index 7955dd6..98c0bd4 100644
--- a/libc/arch-mips/bionic/cacheflush.cpp
+++ b/libc/arch-mips/bionic/cacheflush.cpp
@@ -25,75 +25,39 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #include <unistd.h>
 #include <sys/cachectl.h>
 
-#ifdef DEBUG
 #include "private/libc_logging.h"
-#define  XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc-cacheflush",__VA_ARGS__)
-#endif
 
-/*
- * Linux historically defines a cacheflush(3) routine for MIPS
- * with this signature:
- * int cacheflush(char *addr, int nbytes, int cache);
- *
- * Android defines an alternate cacheflush routine which exposes the
- * ARM system call interface:
- * int cacheflush (long start, long end, long flags)
- *
- * This is an attempt to maintain compatibility between the historical MIPS
- * usage for software previously ported to MIPS and Android specific
- * uses of cacheflush()
- *
- * Use the gcc __clear_cache builtin if possible. This will generate inline synci
- * instructions if available or call _flush_cache(start, len, BCACHE) directly
- */
+// Linux historically defines a cacheflush(3) routine for MIPS
+// with this signature:
 
-#if defined (__GNUC__)
-#define GCC_VERSION ((__GNUC__*10000) + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
-#endif
+//   int cacheflush(char *addr, int nbytes, int cache);
 
-/* This is the Android signature */
-int cacheflush (long start, long end, long /*flags*/) {
-	if (end < start) {
-		/*
-		 * It looks like this is really MIPS style cacheflush call
-		 * start => addr
-		 * end => nbytes
-		 */
-#ifdef DEBUG
-		static int warned = 0;
-		if (!warned) {
-			XLOG("called with (start,len) instead of (start,end)");
-			warned = 1;
-		}
-#endif
-		end += start;
-	}
+// Android defines an alternate cacheflush routine which exposes the
+// ARM system call interface:
 
-#if !defined(ARCH_MIPS_USE_FLUSHCACHE_SYSCALL) && \
-	defined(GCC_VERSION) && (GCC_VERSION >= 40300)
+//   int cacheflush (long start, long end, long flags)
 
-#if (__mips_isa_rev >= 2) && (GCC_VERSION < 40403)
-	/*
-	 * Modify "start" and "end" to avoid GCC 4.3.0-4.4.2 bug in
-	 * mips_expand_synci_loop that may execute synci one more time.
-	 * "start" points to the first byte of the cache line.
-	 * "end" points to the last byte of the line before the last cache line.
-	 * Because size is always a multiple of 4, this is safe to set
-	 * "end" to the last byte.
-	 */
-	{
-		int lineSize;
-		asm("rdhwr %0, $1" : "=r" (lineSize));
-		start = start & (-lineSize);
-		end = (end & (-lineSize)) - 1;
-	}
-#endif
-	__builtin___clear_cache((char *)start, (char *)end);
-#else
-	_flush_cache((char *)start, end-start, BCACHE);
-#endif
-	return 0;
+// This is an attempt to maintain compatibility between the historical MIPS
+// usage for software previously ported to MIPS and Android specific
+// uses of cacheflush().
+
+int cacheflush(long start, long end, long /*flags*/) {
+  if (end < start) {
+    // It looks like this is really a MIPS-style cacheflush call.
+    static bool warned = false;
+    if (!warned) {
+      __libc_format_log(ANDROID_LOG_WARN, "libc", "cacheflush called with (start,len) instead of (start,end)");
+      warned = true;
+    }
+    end += start;
+  }
+
+  // Use the GCC builtin. This will generate inline synci instructions if available,
+  // or call _flush_cache(start, len, BCACHE) directly.
+  __builtin___clear_cache(reinterpret_cast<char*>(start), reinterpret_cast<char*>(end));
+  return 0;
 }
diff --git a/libc/arch-mips/bionic/futex_mips.S b/libc/arch-mips/bionic/futex_mips.S
deleted file mode 100644
index 5247b79..0000000
--- a/libc/arch-mips/bionic/futex_mips.S
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <private/bionic_asm.h>
-
-#define FUTEX_WAIT 0
-#define FUTEX_WAKE 1
-
-// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout)
-	.type	__futex_wait, @function
-	.global	__futex_wait
-	.align	4
-	.ent	__futex_wait
-__futex_wait:
-	subu	$sp,4*6
-	sw	$0,20($sp)	/* val3 */
-	sw	$0,16($sp)	/* addr2 */
-	move	$a3,$a2		/* timespec */
-	move	$a2,$a1		/* val */
-	li	$a1,FUTEX_WAIT	/* op */
-#	move	$a0,$a0		/* ftx */
-	li	$v0,__NR_futex
-	syscall
-	.set noreorder
-	bnez	$a3, 1f		/* Check for error */
-         neg	$v0		/* Negate error number if it's valid */
-	move	$v0,$0		/* Otherwise return 0 */
-1:
-	.set reorder
-	addu	$sp,4*6
-	j	$ra
-	.end	__futex_wait
-
-// int __futex_wake(volatile void* ftx, int count)
-	.type	__futex_wake, @function
-	.globl	__futex_wake
-	.align	4
-	.ent	__futex_wake
-__futex_wake:
-	subu	$sp,4*6
-	sw	$0,20($sp)	/* val3 */
-	sw	$0,16($sp)	/* addr2 */
-	move	$a3,$0		/* timespec */
-	move	$a2,$a1		/* val */
-	li	$a1,FUTEX_WAKE	/* op */
-#	move	$a0,$a0		/* ftx */
-	li	$v0,__NR_futex
-	syscall
-	.set noreorder
-	bnez	$a3, 1f		/* Check for error */
-         neg	$v0		/* Negate error number if it's valid */
-	move	$v0,$0		/* Otherwise return 0 */
-1:
-	.set reorder
-	addu	$sp,4*6
-	j	$ra
-	.end	__futex_wake
-
-// int __futex_syscall3(volatile void* ftx, int op, int count)
-	.type	__futex_syscall3, @function
-	.global	__futex_syscall3
-	.align	4
-	.ent	__futex_syscall3
-__futex_syscall3:
-	subu	$sp,4*6
-	sw	$0,20($sp)	/* val3 */
-	sw	$0,16($sp)	/* addr2 */
-	move	$a3,$0		/* timespec */
-#	move	$a2,$a2		/* val */
-#	li	$a1,$a1		/* op */
-#	move	$a0,$a0		/* ftx */
-	li	$v0,__NR_futex
-	syscall
-	.set noreorder
-	bnez	$a3, 1f		/* Check for error */
-         neg	$v0		/* Negate error number if it's valid */
-	move	$v0,$0		/* Otherwise return 0 */
-1:
-	.set reorder
-	addu	$sp,4*6
-	j	$ra
-	.end	__futex_syscall3
-
-// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout)
-	.type	__futex_syscall4, @function
-	.global	__futex_syscall4
-	.align	4
-	.ent	__futex_syscall4
-__futex_syscall4:
-	subu	$sp,4*6
-	sw	$0,20($sp)	/* val3 */
-	sw	$0,16($sp)	/* addr2 */
-#	move	$a3,$a3		/* timespec */
-#	move	$a2,$a2		/* val */
-#	li	$a1,$a1		/* op */
-#	move	$a0,$a0		/* ftx */
-	li	$v0,__NR_futex
-	syscall
-	.set noreorder
-	bnez	$a3, 1f		/* Check for error */
-         neg	$v0		/* Negate error number if it's valid */
-	move	$v0,$0		/* Otherwise return 0 */
-1:
-	.set reorder
-	addu	$sp,4*6
-	j	$ra
-	.end	__futex_syscall4
diff --git a/libc/arch-mips/bionic/memcmp16.S b/libc/arch-mips/bionic/memcmp16.S
deleted file mode 100644
index a2b2544..0000000
--- a/libc/arch-mips/bionic/memcmp16.S
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-	.text
-
-/*
- * u4 __memcmp16(const u2* s0, const u2* s1, size_t count);
- */
-	.type	__memcmp16, @function
-	.global	__memcmp16
-	.align	4
-	.ent __memcmp16
-__memcmp16:
-	li	$t0,0
-	li	$t1,0
-	beqz	$a2,done		/* 0 length string */ 
-	beq	$a0,$a1,done		/* strings are identical */
-
-	/* Unoptimised... */
-1:	lhu	$t0,0($a0)
-	lhu	$t1,0($a1)
-	addu	$a1,2
-	bne	$t0,$t1,done
-	addu	$a0,2
-	subu	$a2,1
-	bnez	$a2,1b
-
-done:
-	subu	$v0,$t0,$t1
-	j	$ra
-        .end __memcmp16
diff --git a/libc/arch-mips/bionic/memmove.c b/libc/arch-mips/bionic/memmove.c
deleted file mode 100644
index 1f4522b..0000000
--- a/libc/arch-mips/bionic/memmove.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <string.h>
-#include <strings.h>
-
-void *memmove(void *dst, const void *src, size_t n)
-{
-  const char *p = src;
-  char *q = dst;
-  /* We can use the optimized memcpy if the destination is completely below the
-   * source (i.e. q + n <= p), or if it is completely over it (i.e. q >= p+n).
-   */
-  if (__builtin_expect((q + n < p) || (q >= p + n), 1)) {
-    return memcpy(dst, src, n);
-  } else {
-    bcopy(src, dst, n);
-    return dst;
-  }
-}
diff --git a/libc/arch-mips/bionic/setjmp.S b/libc/arch-mips/bionic/setjmp.S
index 7c21195..31786be 100644
--- a/libc/arch-mips/bionic/setjmp.S
+++ b/libc/arch-mips/bionic/setjmp.S
@@ -29,7 +29,7 @@
  *
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/signal.h>
 
@@ -45,17 +45,6 @@
 GPOFF= FRAMESZ-2*REGSZ
 RAOFF= FRAMESZ-1*REGSZ
 
-#define FPREG64_S(FPR, OFF, BASE)       \
-        swc1    FPR, OFF(BASE)  ;       \
-        mfhc1   t0, FPR         ;       \
-        sw      t0, OFF+4(BASE) ;
-        
-#define FPREG64_L(FPR, OFF, BASE)       \
-        lw      t0, OFF+4(BASE) ;       \
-        lw      t1, OFF(BASE)   ;       \
-        mtc1    t1, FPR         ;       \
-        mthc1   t0, FPR         ;       \
-        
 NON_LEAF(setjmp, FRAMESZ, ra)
 	.mask	0x80000000, RAOFF
 	PTR_SUBU sp, FRAMESZ			# allocate stack frame
@@ -98,32 +87,19 @@
 	li	v0, 1				# be nice if we could tell
 	REG_S	v0, SC_FPUSED(a0)		# sc_fpused = 1
 	cfc1	v0, $31
+	s.d	$f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
+	s.d	$f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
+	s.d	$f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
+	s.d	$f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
+	s.d	$f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
+	s.d	$f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
 #if _MIPS_FPSET == 32
-        FPREG64_S($f20, SC_FPREGS+((F20-F0)*REGSZ_FP), a0)
-        FPREG64_S($f21, SC_FPREGS+((F21-F0)*REGSZ_FP), a0)
-        FPREG64_S($f22, SC_FPREGS+((F22-F0)*REGSZ_FP), a0)
-        FPREG64_S($f23, SC_FPREGS+((F23-F0)*REGSZ_FP), a0)
-        FPREG64_S($f24, SC_FPREGS+((F24-F0)*REGSZ_FP), a0)
-        FPREG64_S($f25, SC_FPREGS+((F25-F0)*REGSZ_FP), a0)
-        FPREG64_S($f26, SC_FPREGS+((F26-F0)*REGSZ_FP), a0)
-        FPREG64_S($f27, SC_FPREGS+((F27-F0)*REGSZ_FP), a0)
-        FPREG64_S($f28, SC_FPREGS+((F28-F0)*REGSZ_FP), a0)
-        FPREG64_S($f29, SC_FPREGS+((F29-F0)*REGSZ_FP), a0)
-        FPREG64_S($f30, SC_FPREGS+((F30-F0)*REGSZ_FP), a0)
-        FPREG64_S($f31, SC_FPREGS+((F31-F0)*REGSZ_FP), a0)
-#else
-        swc1    $f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
-        swc1    $f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
-        swc1    $f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
-        swc1    $f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
-        swc1    $f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
-        swc1    $f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
-        swc1    $f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
-        swc1    $f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
-        swc1    $f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
-        swc1    $f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
-        swc1    $f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
-        swc1    $f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
+	s.d	$f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
+	s.d	$f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
+	s.d	$f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
+	s.d	$f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
+	s.d	$f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
+	s.d	$f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
 #endif
 	REG_S	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
 #endif /* !SOFTFLOAT */
@@ -154,7 +130,7 @@
 	lw	a0, A0OFF(sp)
 	lw	a1, A1OFF(sp)
 
-	.set	noreorder	
+	.set	noreorder
 	REG_L	v0, SC_REGS+ZERO*REGSZ(a0)
 	bne	v0, 0xACEDBADE, botch		# jump if error
 	REG_L	ra, SC_PC(a0)
@@ -169,36 +145,23 @@
 	REG_L	s8, SC_REGS+S8*REGSZ(a0)
 	REG_L	gp, SC_REGS+GP*REGSZ(a0)
 	REG_L	sp, SC_REGS+SP*REGSZ(a0)
-	
+
 #if !defined(SOFTFLOAT)
-	REG_L	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)	
+	REG_L	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
 	ctc1	v0, $31
+	l.d	$f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
+	l.d	$f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
+	l.d	$f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
+	l.d	$f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
+	l.d	$f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
+	l.d	$f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
 #if _MIPS_FPSET == 32
-        FPREG64_L($f20, SC_FPREGS+((F20-F0)*REGSZ_FP), a0)
-        FPREG64_L($f21, SC_FPREGS+((F21-F0)*REGSZ_FP), a0)
-        FPREG64_L($f22, SC_FPREGS+((F22-F0)*REGSZ_FP), a0)
-        FPREG64_L($f23, SC_FPREGS+((F23-F0)*REGSZ_FP), a0)
-        FPREG64_L($f24, SC_FPREGS+((F24-F0)*REGSZ_FP), a0)
-        FPREG64_L($f25, SC_FPREGS+((F25-F0)*REGSZ_FP), a0)
-        FPREG64_L($f26, SC_FPREGS+((F26-F0)*REGSZ_FP), a0)
-        FPREG64_L($f27, SC_FPREGS+((F27-F0)*REGSZ_FP), a0)
-        FPREG64_L($f28, SC_FPREGS+((F28-F0)*REGSZ_FP), a0)
-        FPREG64_L($f29, SC_FPREGS+((F29-F0)*REGSZ_FP), a0)
-        FPREG64_L($f30, SC_FPREGS+((F30-F0)*REGSZ_FP), a0)
-        FPREG64_L($f31, SC_FPREGS+((F31-F0)*REGSZ_FP), a0)
-#else
-        lwc1    $f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
-        lwc1    $f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
-        lwc1    $f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
-        lwc1    $f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
-        lwc1    $f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
-        lwc1    $f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
-        lwc1    $f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
-        lwc1    $f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
-        lwc1    $f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
-        lwc1    $f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
-        lwc1    $f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
-        lwc1    $f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
+	l.d	$f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
+	l.d	$f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
+	l.d	$f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
+	l.d	$f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
+	l.d	$f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
+	l.d	$f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
 #endif
 #endif /* !SOFTFLOAT */
 	bne	a1, zero, 1f
diff --git a/libc/arch-mips/bionic/sigsetjmp.S b/libc/arch-mips/bionic/sigsetjmp.S
index b05454c..9d2e5ea 100644
--- a/libc/arch-mips/bionic/sigsetjmp.S
+++ b/libc/arch-mips/bionic/sigsetjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/setjmp.h>
 
diff --git a/libc/arch-mips/bionic/syscall.S b/libc/arch-mips/bionic/syscall.S
index af5bcc9..5fed0ac 100644
--- a/libc/arch-mips/bionic/syscall.S
+++ b/libc/arch-mips/bionic/syscall.S
@@ -26,11 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-    .text
-    .globl syscall
-    .align 4
-    .ent syscall
+#include <private/bionic_asm.h>
 
 /*
  * The caller is only required to allocate 16 bytes of stack for a0-a3.
@@ -38,28 +34,28 @@
  */
 #define STACKSIZE 2*4
 
-syscall:
+ENTRY(syscall)
     .set noreorder
-    .cpload $t9
-    move    $v0, $a0
-    move    $a0, $a1
-    move    $a1, $a2
-    move    $a2, $a3
-    lw      $a3, 16($sp)
-    lw      $t0, 20($sp)
-    lw      $t1, 24($sp)
-    subu    $sp, STACKSIZE
-    sw      $t0, 16($sp)
-    sw      $t1, 20($sp)
+    .cpload t9
+    move    v0, a0
+    move    a0, a1
+    move    a1, a2
+    move    a2, a3
+    lw      a3, 16(sp)
+    lw      t0, 20(sp)
+    lw      t1, 24(sp)
+    subu    sp, STACKSIZE
+    sw      t0, 16(sp)
+    sw      t1, 20(sp)
     syscall
-    addu    $sp, STACKSIZE
-    bnez    $a3, 1f
-    move    $a0, $v0
-    j       $ra
+    addu    sp, STACKSIZE
+    bnez    a3, 1f
+    move    a0, v0
+    j       ra
     nop
 1:
-    la      $t9,__set_errno
-    j       $t9
+    la      t9,__set_errno_internal
+    j       t9
     nop
     .set reorder
-    .end syscall
+END(syscall)
diff --git a/libc/arch-mips/bionic/vfork.S b/libc/arch-mips/bionic/vfork.S
index 414caaf..1849624 100644
--- a/libc/arch-mips/bionic/vfork.S
+++ b/libc/arch-mips/bionic/vfork.S
@@ -26,39 +26,33 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
+#include <private/bionic_asm.h>
 #include <linux/sched.h>
 
 // TODO: mips' uapi signal.h is missing #ifndef __ASSEMBLY__.
 // #include <asm/signal.h>
 #define SIGCHLD 18
 
-	.text
-
-	.type	vfork, @function
-	.global	vfork
-	.align	4
-	.ent	vfork
-vfork:
+ENTRY(vfork)
 	.set	noreorder
-	.cpload	$t9
+	.cpload	t9
 
-	li	$a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
-	li	$a1, 0
-	li	$a2, 0
-	li	$a3, 0
-	subu	$sp, 8
-	sw	$0, 16($sp)
-	li	$v0, __NR_clone
+	li	a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
+	li	a1, 0
+	li	a2, 0
+	li	a3, 0
+	subu	sp, 8
+	sw	$0, 16(sp)
+	li	v0, __NR_clone
 	syscall
-	addu	$sp, 8
-	bnez	$a3, 1f
-	 move	$a0, $v0
+	addu	sp, 8
+	bnez	a3, 1f
+	 move	a0, v0
 
-	j	$ra
+	j	ra
 	 nop
 1:
-	la	$t9, __set_errno
-	j	$t9
+	la	t9, __set_errno_internal
+	j	t9
 	 nop
-	.end	vfork
+END(vfork)
diff --git a/libc/arch-mips/include/machine/_types.h b/libc/arch-mips/include/machine/_types.h
deleted file mode 100644
index 05f79ef..0000000
--- a/libc/arch-mips/include/machine/_types.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*	$OpenBSD: _types.h,v 1.5 2008/07/21 20:50:54 martynas Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)types.h	8.3 (Berkeley) 1/5/94
- *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
- */
-
-#ifndef _MIPS64__TYPES_H_
-#define _MIPS64__TYPES_H_
-
-/*
- *  We need to handle the various ISA levels for sizes.
- */
-#define	_MIPS_ISA_MIPS1	1	/* R2000/R3000 */
-#define	_MIPS_ISA_MIPS2	2	/* R4000/R6000 */
-#define	_MIPS_ISA_MIPS3	3	/* R4000 */
-#define	_MIPS_ISA_MIPS4	4	/* TFP (R1x000) */
-
-/* 7.18.1.1 Exact-width integer types */
-typedef	__signed char		__int8_t;
-typedef	unsigned char		__uint8_t;
-typedef	short			__int16_t;
-typedef	unsigned short		__uint16_t;
-typedef	int			__int32_t;
-typedef	unsigned int		__uint32_t;
-/* LONGLONG */
-typedef	long long		__int64_t;
-/* LONGLONG */
-typedef	unsigned long long	__uint64_t;
-
-/* 7.18.1.2 Minimum-width integer types */
-typedef	__int8_t		__int_least8_t;
-typedef	__uint8_t		__uint_least8_t;
-typedef	__int16_t		__int_least16_t;
-typedef	__uint16_t		__uint_least16_t;
-typedef	__int32_t		__int_least32_t;
-typedef	__uint32_t		__uint_least32_t;
-typedef	__int64_t		__int_least64_t;
-typedef	__uint64_t		__uint_least64_t;
-
-/* 7.18.1.3 Fastest minimum-width integer types */
-typedef	__int32_t		__int_fast8_t;
-typedef	__uint32_t		__uint_fast8_t;
-typedef	__int32_t		__int_fast16_t;
-typedef	__uint32_t		__uint_fast16_t;
-typedef	__int32_t		__int_fast32_t;
-typedef	__uint32_t		__uint_fast32_t;
-typedef	__int64_t		__int_fast64_t;
-typedef	__uint64_t		__uint_fast64_t;
-
-/* 7.18.1.4 Integer types capable of holding object pointers */
-typedef	long			__intptr_t;
-typedef	unsigned long		__uintptr_t;
-
-/* 7.18.1.5 Greatest-width integer types */
-typedef	__int64_t		__intmax_t;
-typedef	__uint64_t		__uintmax_t;
-
-/* Register size */
-#if (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4)
-typedef __int64_t		__register_t;
-typedef __int64_t		f_register_t;	/* XXX */
-#else
-typedef __int32_t		__register_t;
-typedef __int32_t		f_register_t;	/* XXX */
-#endif
-
-/* VM system types */
-typedef unsigned long		__vaddr_t;
-typedef unsigned long		__paddr_t;
-typedef unsigned long		__vsize_t;
-typedef unsigned long		__psize_t;
-
-/* Standard system types */
-typedef int			__clock_t;
-typedef int			__clockid_t;
-typedef double			__double_t;
-typedef float			__float_t;
-typedef long long		__off_t;
-typedef long			__ptrdiff_t;
-typedef	int			__time_t;
-typedef int			__timer_t;
-#if defined(__GNUC__) && __GNUC__ >= 3
-typedef	__builtin_va_list	__va_list;
-#else
-typedef	char *			__va_list;
-#endif
-
-/* Wide character support types */
-#ifndef __cplusplus
-typedef	int			__wchar_t;
-#endif
-typedef int			__wint_t;
-typedef	int			__rune_t;
-typedef	void *			__wctrans_t;
-typedef	void *			__wctype_t;
-
-#if defined(_KERNEL)
-typedef struct label_t {
-	__register_t val[14];
-} label_t;
-#endif
-
-/* XXX check why this still has to be defined. pmap.c issue? */
-#define __SWAP_BROKEN
-
-/* Feature test macros */
-#define __HAVE_TIMECOUNTER
-
-#endif	/* _MIPS64__TYPES_H_ */
diff --git a/libc/arch-mips/include/machine/asm.h b/libc/arch-mips/include/machine/asm.h
index 43dbc09..5eacde3 100644
--- a/libc/arch-mips/include/machine/asm.h
+++ b/libc/arch-mips/include/machine/asm.h
@@ -28,25 +28,24 @@
 #ifndef _MIPS64_ASM_H
 #define _MIPS64_ASM_H
 
-#include <machine/regdef.h>
-
-#ifdef NEED_OLD_RM7KFIX
-#define ITLBNOPFIX      nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
-#else
-#define ITLBNOPFIX      nop;nop;nop;nop
+#ifndef _ALIGN_TEXT
+# define _ALIGN_TEXT .align 4
 #endif
 
+#undef __bionic_asm_custom_entry
+#undef __bionic_asm_custom_end
+#define __bionic_asm_custom_entry(f) .ent f
+#define __bionic_asm_custom_end(f) .end f
+
+#include <machine/regdef.h>
+
 #define	_MIPS_ISA_MIPS1	1	/* R2000/R3000 */
 #define	_MIPS_ISA_MIPS2	2	/* R4000/R6000 */
 #define	_MIPS_ISA_MIPS3	3	/* R4000 */
 #define	_MIPS_ISA_MIPS4	4	/* TFP (R1x000) */
-#ifdef __linux__
 #define	_MIPS_ISA_MIPS5 5
 #define	_MIPS_ISA_MIPS32 6
 #define	_MIPS_ISA_MIPS64 7
-#else
-#define	_MIPS_ISA_MIPS32 32	/* MIPS32 */
-#endif
 
 #if !defined(ABICALLS) && !defined(_NO_ABICALLS)
 #define	ABICALLS	.abicalls
@@ -56,8 +55,6 @@
 	ABICALLS
 #endif
 
-#define _C_LABEL(x) x		/* XXX Obsolete but keep for a while */
-
 #if !defined(__MIPSEL__) && !defined(__MIPSEB__)
 #error "__MIPSEL__ or __MIPSEB__ must be defined"
 #endif
@@ -90,15 +87,6 @@
  */
 #if defined(ABICALLS) && !defined(_KERNEL) && !defined(_STANDALONE)
 
-#ifndef _MIPS_SIM
-#define _MIPS_SIM 1
-#define _ABIO32	1
-#endif
-#ifndef _MIPS_ISA
-#define _MIPS_ISA 2
-#define _MIPS_ISA_MIPS2 2
-#endif
-
 #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
 #define NARGSAVE	4
 
@@ -151,7 +139,7 @@
 #define	CF_RA_OFFS	20	/* Call ra save offset */
 #endif
 
-#if (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4)
+#if (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4 || _MIPS_ISA == _MIPS_ISA_MIPS64)
 #define REGSZ		8	/* 64 bit mode register size */
 #define LOGREGSZ	3	/* log rsize */
 #define	REG_S	sd
@@ -190,28 +178,6 @@
 #endif
 
 /*
- * Define -pg profile entry code.
- */
-#if defined(XGPROF) || defined(XPROF)
-#define	MCOUNT			\
-	PTR_SUBU sp, sp, 32;	\
-	SAVE_GP(16);		\
-	sw	ra, 28(sp);	\
-	sw	gp, 24(sp);	\
-	.set	noat;		\
-	.set	noreorder;	\
-	move	AT, ra;		\
-	jal	_mcount;	\
-	PTR_SUBU sp, sp, 8;	\
-	lw	ra, 28(sp);	\
-	PTR_ADDU sp, sp, 32;	\
-	.set reorder;		\
-	.set	at;
-#else
-#define	MCOUNT
-#endif
-
-/*
  * LEAF(x, fsize)
  *
  *	Declare a leaf routine.
@@ -221,26 +187,9 @@
 	.globl x;		\
 	.ent x, 0;		\
 x: ;				\
+	.cfi_startproc; \
 	.frame sp, fsize, ra;	\
 	SETUP_GP		\
-	MCOUNT
-
-#define	ALEAF(x)		\
-	.globl	x;		\
-x:
-
-/*
- * NLEAF(x)
- *
- *	Declare a non-profiled leaf routine.
- */
-#define NLEAF(x, fsize)		\
-	.align	3;		\
-	.globl x;		\
-	.ent x, 0;		\
-x: ;				\
-	.frame sp, fsize, ra;	\
-	SETUP_GP
 
 /*
  * NON_LEAF(x)
@@ -252,54 +201,8 @@
 	.globl x;		\
 	.ent x, 0;		\
 x: ;				\
+	.cfi_startproc; \
 	.frame sp, fsize, retpc; \
 	SETUP_GP		\
-	MCOUNT
-
-/*
- * NNON_LEAF(x)
- *
- *	Declare a non-profiled non-leaf routine
- *	(a routine that makes other C calls).
- */
-#define NNON_LEAF(x, fsize, retpc) \
-	.align	3;		\
-	.globl x;		\
-	.ent x, 0;		\
-x: ;				\
-	.frame sp, fsize, retpc	\
-	SETUP_GP
-
-/*
- * END(x)
- *
- *	Mark end of a procedure.
- */
-#define END(x) \
-	.end x
-
-/*
- * Macros to panic and printf from assembly language.
- */
-#define PANIC(msg) \
-	LA	a0, 9f; \
-	jal	panic;	\
-	nop	;	\
-	MSG(msg)
-
-#define	PRINTF(msg) \
-	la	a0, 9f; \
-	jal	printf; \
-	nop	;	\
-	MSG(msg)
-
-#define	MSG(msg) \
-	.rdata; \
-9:	.asciiz	msg; \
-	.text
-
-#define ASMSTR(str) \
-	.asciiz str; \
-	.align	3
 
 #endif /* !_MIPS_ASM_H */
diff --git a/libc/arch-mips/include/machine/ieee.h b/libc/arch-mips/include/machine/ieee.h
deleted file mode 100644
index 520a77b..0000000
--- a/libc/arch-mips/include/machine/ieee.h
+++ /dev/null
@@ -1,169 +0,0 @@
-/*	$OpenBSD: ieee.h,v 1.4 2010/01/23 19:11:21 miod Exp $	*/
-
-/*
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Lawrence Berkeley Laboratory.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
- */
-
-/*
- * ieee.h defines the machine-dependent layout of the machine's IEEE
- * floating point.  It does *not* define (yet?) any of the rounding
- * mode bits, exceptions, and so forth.
- */
-
-/*
- * Define the number of bits in each fraction and exponent.
- *
- *		     k	         k+1
- * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
- *
- *					  (-exp_bias+1)
- * as fractions that look like 0.fffff x 2             .  This means that
- *
- *			 -126
- * the number 0.10000 x 2    , for instance, is the same as the normalized
- *
- *		-127			   -128
- * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
- *
- *				  -129
- * in the fraction; to represent 2    , we need two, and so on.  This
- *
- *						     (-exp_bias-fracbits+1)
- * implies that the smallest denormalized number is 2
- *
- * for whichever format we are talking about: for single precision, for
- *
- *						-126		-149
- * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
- *
- * -149 == -127 - 23 + 1.
- */
-#define	SNG_EXPBITS	8
-#define	SNG_FRACBITS	23
-
-#define	DBL_EXPBITS	11
-#define	DBL_FRACHBITS	20
-#define	DBL_FRACLBITS	32
-#define	DBL_FRACBITS	52
-
-#define	EXT_EXPBITS	15
-#define	EXT_FRACHBITS	16
-#define	EXT_FRACHMBITS	32
-#define	EXT_FRACLMBITS	32
-#define	EXT_FRACLBITS	32
-#define	EXT_FRACBITS	112
-
-#define	EXT_IMPLICIT_NBIT
-
-#define	EXT_TO_ARRAY32(p, a) do {		\
-	(a)[0] = (uint32_t)(p)->ext_fracl;	\
-	(a)[1] = (uint32_t)(p)->ext_fraclm;	\
-	(a)[2] = (uint32_t)(p)->ext_frachm;	\
-	(a)[3] = (uint32_t)(p)->ext_frach;	\
-} while(0)
-
-struct ieee_single {
-#ifdef __MIPSEB__
-	u_int	sng_sign:1;
-	u_int	sng_exp:8;
-	u_int	sng_frac:23;
-#else
-	u_int	sng_frac:23;
-	u_int	sng_exp:8;
-	u_int	sng_sign:1;
-#endif
-};
-
-struct ieee_double {
-#ifdef __MIPSEB__
-	u_int	dbl_sign:1;
-	u_int	dbl_exp:11;
-	u_int	dbl_frach:20;
-	u_int	dbl_fracl;
-#else
-	u_int	dbl_fracl;
-	u_int	dbl_frach:20;
-	u_int	dbl_exp:11;
-	u_int	dbl_sign:1;
-#endif
-};
-
-struct ieee_ext {
-#ifdef __MIPSEB__
-	u_int	ext_sign:1;
-	u_int	ext_exp:15;
-	u_int	ext_frach:16;
-	u_int	ext_frachm;
-	u_int	ext_fraclm;
-	u_int	ext_fracl;
-#else
-	u_int	ext_fracl;
-	u_int	ext_fraclm;
-	u_int	ext_frachm;
-	u_int	ext_frach:16;
-	u_int	ext_exp:15;
-	u_int	ext_sign:1;
-#endif
-};
-
-/*
- * Floats whose exponent is in [1..INFNAN) (of whatever type) are
- * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
- * Floats whose exponent is zero are either zero (iff all fraction
- * bits are zero) or subnormal values.
- *
- * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
- * high fraction; if the bit is set, it is a `quiet NaN'.
- */
-#define	SNG_EXP_INFNAN	255
-#define	DBL_EXP_INFNAN	2047
-#define	EXT_EXP_INFNAN	32767
-
-#if 0
-#define	SNG_QUIETNAN	(1 << 22)
-#define	DBL_QUIETNAN	(1 << 19)
-#define	EXT_QUIETNAN	(1 << 15)
-#endif
-
-/*
- * Exponent biases.
- */
-#define	SNG_EXP_BIAS	127
-#define	DBL_EXP_BIAS	1023
-#define	EXT_EXP_BIAS	16383
diff --git a/libc/arch-mips/include/machine/limits.h b/libc/arch-mips/include/machine/limits.h
deleted file mode 100644
index 339444d..0000000
--- a/libc/arch-mips/include/machine/limits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.5 2007/05/07 20:51:07 kettenis Exp $	*/
-
-/*
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)limits.h	8.3 (Berkeley) 1/4/94
- */
-
-#ifndef _MIPS_LIMITS_H_
-#define _MIPS_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	6		/* Allow 31 bit UTF2 */
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	ULONG_MAX	/* max value for a size_t */
-#endif
-#define	SSIZE_MAX	LONG_MAX	/* max value for a ssize_t */
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t (historic) */
-
-/* Quads and longs are the same on mips64 */
-#define	UQUAD_MAX	(ULONG_MAX)	/* max value for a uquad_t */
-#define	QUAD_MAX	(LONG_MAX)	/* max value for a quad_t */
-#define	QUAD_MIN	(LONG_MIN)	/* min value for a quad_t */
-
-#endif /* __BSD_VISIBLE */
-
-
-#define LONGLONG_BIT    64
-#define LONGLONG_MIN    (-9223372036854775807LL-1)
-#define LONGLONG_MAX    9223372036854775807LL
-#define ULONGLONG_MAX   18446744073709551615ULL
-
-#endif /* !_MIPS_LIMITS_H_ */
diff --git a/libc/arch-mips/include/machine/signal.h b/libc/arch-mips/include/machine/signal.h
index 4efb856..b31715c 100644
--- a/libc/arch-mips/include/machine/signal.h
+++ b/libc/arch-mips/include/machine/signal.h
@@ -37,111 +37,15 @@
 #ifndef _MIPS_SIGNAL_H_
 #define _MIPS_SIGNAL_H_
 
-#include <sys/cdefs.h>
-
-#if !defined(__LANGUAGE_ASSEMBLY)
-#include <sys/types.h>
-
-/*
- * Machine-dependent signal definitions
- */
-typedef int sig_atomic_t;
-
-#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
-
-/*
- * Information pushed on stack when a signal is delivered.
- * This is used by the kernel to restore state following
- * execution of the signal handler.  It is also made available
- * to the handler to allow it to restore state properly if
- * a non-standard exit is performed.
- */
-
-#if defined(__ANDROID__)
-
-/*
- * The Linux and OpenBSD sigcontext structures are slightly different
- * This is the Linux O32 ABI compatible sigcontext
- */
-
-struct sigcontext {
-	unsigned int sc_regmask;
-	unsigned int sc_status;
-	unsigned long long sc_pc;
-	unsigned long long sc_regs[32];
-	unsigned long long sc_fpregs[32];
-	unsigned int sc_acx;
-	unsigned int sc_fpc_csr;
-	unsigned int sc_fpc_eir;
-	unsigned int sc_used_math;
-	unsigned int sc_dsp;
-	unsigned long long sc_mdhi;
-	unsigned long long sc_mdlo;
-	unsigned long sc_hi1;
-	unsigned long sc_lo1;
-	unsigned long sc_hi2;
-	unsigned long sc_lo2;
-	unsigned long sc_hi3;
-	unsigned long sc_lo3;
-};
-
-#else
-
-struct	sigcontext {
-	long	sc_onstack;	/* sigstack state to restore */
-	long	 sc_mask;	/* signal mask to restore */
-	__register_t sc_pc;	/* pc at time of signal */
-	__register_t sc_regs[32]; /* processor regs 0 to 31 */
-	__register_t mullo;	/* mullo and mulhi registers... */
-	__register_t mulhi;	/* mullo and mulhi registers... */
-	f_register_t sc_fpregs[33]; /* fp regs 0 to 31 and csr */
-	long	sc_fpused;	/* fp has been used */
-	long	sc_fpc_eir;	/* floating point exception instruction reg */
-	long	xxx[8];		/* XXX reserved */
-};
-#endif
-#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
-
-#else /* __LANGUAGE_ASSEMBLY */
-
-#ifdef __ANDROID__
-
 #define	SC_REGMASK	(0*REGSZ)
 #define	SC_STATUS	(1*REGSZ)
 #define	SC_PC		(2*REGSZ)
 #define	SC_REGS		(SC_PC+8)
 #define	SC_FPREGS	(SC_REGS+32*8)
 #define	SC_ACX		(SC_FPREGS+32*REGSZ_FP)
-#define	SC_FPC_CSR	(SC_ACX+1*REGSZ)
-#define	SC_FPC_EIR	(SC_ACX+2*REGSZ)
 #define	SC_USED_MATH	(SC_ACX+3*REGSZ)
-#define	SC_DSP		(SC_ACX+4*REGSZ)
-#define	SC_MDHI		(SC_ACX+5*REGSZ)
-#define	SC_MDLO		(SC_MDHI+8)
-#define	SC_HI1		(SC_MDLO+8)
-#define	SC_LO1		(SC_HI1+1*REGSZ)
-#define	SC_HI2		(SC_HI1+2*REGSZ)
-#define	SC_LO2		(SC_HI1+3*REGSZ)
-#define	SC_HI3		(SC_HI1+4*REGSZ)
-#define	SC_LO3		(SC_HI1+5*REGSZ)
 /* OpenBSD compatibility */
 #define	SC_MASK		SC_REGMASK
 #define	SC_FPUSED	SC_USED_MATH
 
-#else
-
-#define SC_ONSTACK	(0 * REGSZ)
-#define	SC_MASK		(1 * REGSZ)
-#define	SC_PC		(2 * REGSZ)
-#define	SC_REGS		(3 * REGSZ)
-#define	SC_MULLO	(35 * REGSZ)
-#define	SC_MULHI	(36 * REGSZ)
-#define	SC_FPREGS	(37 * REGSZ)
-#define	SC_FPUSED	(70 * REGSZ)
-#define	SC_FPC_EIR	(71 * REGSZ)
-
-#endif /* __ANDROID__ */
-
-#endif /* __LANGUAGE_ASSEMBLY */
-
 #endif	/* !_MIPS_SIGNAL_H_ */
diff --git a/libc/arch-mips/mips.mk b/libc/arch-mips/mips.mk
index 1119a66..31a1f32 100644
--- a/libc/arch-mips/mips.mk
+++ b/libc/arch-mips/mips.mk
@@ -1,23 +1,94 @@
-_LIBC_ARCH_COMMON_SRC_FILES := \
+# mips specific configs
+
+# These are shared by all the 32-bit targets, but not the 64-bit ones.
+libc_common_src_files_mips := \
+    bionic/legacy_32_bit_support.cpp \
+    bionic/ndk_cruft.cpp \
+    bionic/time64.c \
+    upstream-openbsd/lib/libc/stdio/putw.c \
+
+# These are shared by all the 32-bit targets, but not the 64-bit ones.
+libc_bionic_src_files_mips += \
+     bionic/mmap.cpp
+
+libc_common_src_files_mips += \
+    bionic/memchr.c \
+    bionic/memcmp.c \
+    bionic/memmove.c \
+    bionic/memrchr.c \
+    bionic/strchr.cpp \
+    bionic/strnlen.c \
+    bionic/strrchr.cpp \
+    upstream-freebsd/lib/libc/string/wcscat.c \
+    upstream-freebsd/lib/libc/string/wcschr.c \
+    upstream-freebsd/lib/libc/string/wcscmp.c \
+    upstream-freebsd/lib/libc/string/wcscpy.c \
+    upstream-freebsd/lib/libc/string/wcslen.c \
+    upstream-freebsd/lib/libc/string/wcsrchr.c \
+    upstream-freebsd/lib/libc/string/wmemcmp.c \
+    upstream-freebsd/lib/libc/string/wmemmove.c \
+    upstream-openbsd/lib/libc/string/bcopy.c \
+    upstream-openbsd/lib/libc/string/stpcpy.c \
+    upstream-openbsd/lib/libc/string/stpncpy.c \
+    upstream-openbsd/lib/libc/string/strcat.c \
+    upstream-openbsd/lib/libc/string/strcmp.c \
+    upstream-openbsd/lib/libc/string/strcpy.c \
+    upstream-openbsd/lib/libc/string/strlcat.c \
+    upstream-openbsd/lib/libc/string/strlcpy.c \
+    upstream-openbsd/lib/libc/string/strncat.c \
+    upstream-openbsd/lib/libc/string/strncmp.c \
+    upstream-openbsd/lib/libc/string/strncpy.c \
+
+# Fortify implementations of libc functions.
+libc_common_src_files_mips += \
+    bionic/__memcpy_chk.cpp \
+    bionic/__memset_chk.cpp \
+    bionic/__strcpy_chk.cpp \
+    bionic/__strcat_chk.cpp \
+
+
+##########################################
+### CPU specific source files
+libc_bionic_src_files_mips += \
     arch-mips/bionic/__bionic_clone.S \
     arch-mips/bionic/bzero.S \
     arch-mips/bionic/cacheflush.cpp \
     arch-mips/bionic/_exit_with_stack_teardown.S \
-    arch-mips/bionic/futex_mips.S \
-    arch-mips/bionic/__get_sp.S \
-    arch-mips/bionic/memcmp16.S \
-    arch-mips/bionic/memmove.c \
     arch-mips/bionic/_setjmp.S \
     arch-mips/bionic/setjmp.S \
-    arch-mips/bionic/__set_tls.c \
     arch-mips/bionic/sigsetjmp.S \
     arch-mips/bionic/syscall.S \
     arch-mips/bionic/vfork.S \
+
+ifndef ARCH_MIPS_REV6
+libc_bionic_src_files_mips += \
     arch-mips/string/memcpy.S \
     arch-mips/string/memset.S \
     arch-mips/string/mips_strlen.c \
 
-_LIBC_ARCH_STATIC_SRC_FILES := \
-    bionic/dl_iterate_phdr_static.c \
+else
+libc_bionic_src_files_mips += \
+    bionic/memcpy.cpp \
+    bionic/memset.c
+libc_common_src_files_mips += \
+    upstream-openbsd/lib/libc/string/strlen.c
+endif
 
-_LIBC_ARCH_DYNAMIC_SRC_FILES :=
+libc_netbsd_src_files_mips := \
+    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
+
+libc_crt_target_cflags_mips := \
+    $($(my_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \
+    -I$(LOCAL_PATH)/arch-mips/include
+
+libc_crt_target_crtbegin_file_mips := \
+    $(LOCAL_PATH)/arch-mips/bionic/crtbegin.c
+
+libc_crt_target_crtbegin_so_file_mips := \
+    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
+
+libc_crt_target_so_cflags_mips := \
+    -fPIC
+
+libc_crt_target_ldflags_mips := \
+    -melf32ltsmip
diff --git a/libc/arch-mips/string/memcpy.S b/libc/arch-mips/string/memcpy.S
index aabdfcf..dc91096 100644
--- a/libc/arch-mips/string/memcpy.S
+++ b/libc/arch-mips/string/memcpy.S
@@ -39,13 +39,13 @@
  *  Include files
  ************************************************************************/
 
-#include "machine/asm.h"
+#include <private/bionic_asm.h>
 
 
-/* 
+/*
  * This routine could be optimized for MIPS64. The current code only
  * uses MIPS32 instructions.
- */	
+ */
 #if defined(__MIPSEB__)
 #  define LWHI	lwl		/* high part is left in big-endian	*/
 #  define SWHI	swl		/* high part is left in big-endian	*/
diff --git a/libc/arch-mips/string/memset.S b/libc/arch-mips/string/memset.S
index a1c5055..3e630ca 100644
--- a/libc/arch-mips/string/memset.S
+++ b/libc/arch-mips/string/memset.S
@@ -39,12 +39,12 @@
  *  Include files
  ************************************************************************/
 
-#include "machine/asm.h"
+#include <private/bionic_asm.h>
 
-/* 
+/*
  * This routine could be optimized for MIPS64. The current code only
  * uses MIPS32 instructions.
- */	
+ */
 
 #if defined(__MIPSEB__)
 #  define SWHI	swl		/* high part is left in big-endian	*/
@@ -220,7 +220,7 @@
 	sw	a1,-36(a0)
 	nop
 	nop			# the extra nop instructions help to balance
-	nop			# cycles needed for "store" + "fill" + "evict" 
+	nop			# cycles needed for "store" + "fill" + "evict"
 	nop			# For 64byte store there are needed 8 fill
 	nop			# and 8 evict cycles, i.e. at least 32 instr.
 	nop
@@ -320,4 +320,3 @@
 /************************************************************************
  *  Implementation : Static functions
  ************************************************************************/
-
diff --git a/libc/arch-mips/syscalls.mk b/libc/arch-mips/syscalls.mk
deleted file mode 100644
index 8d87b29..0000000
--- a/libc/arch-mips/syscalls.mk
+++ /dev/null
@@ -1,197 +0,0 @@
-# Generated by gensyscalls.py. Do not edit.
-syscall_src :=
-syscall_src += arch-mips/syscalls/__brk.S
-syscall_src += arch-mips/syscalls/__epoll_pwait.S
-syscall_src += arch-mips/syscalls/__exit.S
-syscall_src += arch-mips/syscalls/__fcntl64.S
-syscall_src += arch-mips/syscalls/__fstatfs64.S
-syscall_src += arch-mips/syscalls/__getcpu.S
-syscall_src += arch-mips/syscalls/__getcwd.S
-syscall_src += arch-mips/syscalls/__getpriority.S
-syscall_src += arch-mips/syscalls/__ioctl.S
-syscall_src += arch-mips/syscalls/__llseek.S
-syscall_src += arch-mips/syscalls/__mmap2.S
-syscall_src += arch-mips/syscalls/__openat.S
-syscall_src += arch-mips/syscalls/__ppoll.S
-syscall_src += arch-mips/syscalls/__pselect6.S
-syscall_src += arch-mips/syscalls/__ptrace.S
-syscall_src += arch-mips/syscalls/__reboot.S
-syscall_src += arch-mips/syscalls/__rt_sigaction.S
-syscall_src += arch-mips/syscalls/__rt_sigpending.S
-syscall_src += arch-mips/syscalls/__rt_sigprocmask.S
-syscall_src += arch-mips/syscalls/__rt_sigsuspend.S
-syscall_src += arch-mips/syscalls/__rt_sigtimedwait.S
-syscall_src += arch-mips/syscalls/__sched_getaffinity.S
-syscall_src += arch-mips/syscalls/__set_thread_area.S
-syscall_src += arch-mips/syscalls/__set_tid_address.S
-syscall_src += arch-mips/syscalls/__sigaction.S
-syscall_src += arch-mips/syscalls/__statfs64.S
-syscall_src += arch-mips/syscalls/__syslog.S
-syscall_src += arch-mips/syscalls/__timer_create.S
-syscall_src += arch-mips/syscalls/__timer_delete.S
-syscall_src += arch-mips/syscalls/__timer_getoverrun.S
-syscall_src += arch-mips/syscalls/__timer_gettime.S
-syscall_src += arch-mips/syscalls/__timer_settime.S
-syscall_src += arch-mips/syscalls/__waitid.S
-syscall_src += arch-mips/syscalls/_exit.S
-syscall_src += arch-mips/syscalls/_flush_cache.S
-syscall_src += arch-mips/syscalls/accept.S
-syscall_src += arch-mips/syscalls/acct.S
-syscall_src += arch-mips/syscalls/bind.S
-syscall_src += arch-mips/syscalls/capget.S
-syscall_src += arch-mips/syscalls/capset.S
-syscall_src += arch-mips/syscalls/chdir.S
-syscall_src += arch-mips/syscalls/chroot.S
-syscall_src += arch-mips/syscalls/clock_getres.S
-syscall_src += arch-mips/syscalls/clock_gettime.S
-syscall_src += arch-mips/syscalls/clock_nanosleep.S
-syscall_src += arch-mips/syscalls/clock_settime.S
-syscall_src += arch-mips/syscalls/close.S
-syscall_src += arch-mips/syscalls/connect.S
-syscall_src += arch-mips/syscalls/delete_module.S
-syscall_src += arch-mips/syscalls/dup.S
-syscall_src += arch-mips/syscalls/dup3.S
-syscall_src += arch-mips/syscalls/epoll_create1.S
-syscall_src += arch-mips/syscalls/epoll_ctl.S
-syscall_src += arch-mips/syscalls/eventfd.S
-syscall_src += arch-mips/syscalls/execve.S
-syscall_src += arch-mips/syscalls/faccessat.S
-syscall_src += arch-mips/syscalls/fchdir.S
-syscall_src += arch-mips/syscalls/fchmod.S
-syscall_src += arch-mips/syscalls/fchmodat.S
-syscall_src += arch-mips/syscalls/fchown.S
-syscall_src += arch-mips/syscalls/fchownat.S
-syscall_src += arch-mips/syscalls/fdatasync.S
-syscall_src += arch-mips/syscalls/fgetxattr.S
-syscall_src += arch-mips/syscalls/flistxattr.S
-syscall_src += arch-mips/syscalls/flock.S
-syscall_src += arch-mips/syscalls/fremovexattr.S
-syscall_src += arch-mips/syscalls/fsetxattr.S
-syscall_src += arch-mips/syscalls/fstat.S
-syscall_src += arch-mips/syscalls/fstatat.S
-syscall_src += arch-mips/syscalls/fsync.S
-syscall_src += arch-mips/syscalls/ftruncate.S
-syscall_src += arch-mips/syscalls/ftruncate64.S
-syscall_src += arch-mips/syscalls/futex.S
-syscall_src += arch-mips/syscalls/getdents.S
-syscall_src += arch-mips/syscalls/getegid.S
-syscall_src += arch-mips/syscalls/geteuid.S
-syscall_src += arch-mips/syscalls/getgid.S
-syscall_src += arch-mips/syscalls/getgroups.S
-syscall_src += arch-mips/syscalls/getitimer.S
-syscall_src += arch-mips/syscalls/getpeername.S
-syscall_src += arch-mips/syscalls/getpgid.S
-syscall_src += arch-mips/syscalls/getpid.S
-syscall_src += arch-mips/syscalls/getppid.S
-syscall_src += arch-mips/syscalls/getresgid.S
-syscall_src += arch-mips/syscalls/getresuid.S
-syscall_src += arch-mips/syscalls/getrlimit.S
-syscall_src += arch-mips/syscalls/getrusage.S
-syscall_src += arch-mips/syscalls/getsid.S
-syscall_src += arch-mips/syscalls/getsockname.S
-syscall_src += arch-mips/syscalls/getsockopt.S
-syscall_src += arch-mips/syscalls/gettid.S
-syscall_src += arch-mips/syscalls/gettimeofday.S
-syscall_src += arch-mips/syscalls/getuid.S
-syscall_src += arch-mips/syscalls/getxattr.S
-syscall_src += arch-mips/syscalls/init_module.S
-syscall_src += arch-mips/syscalls/inotify_add_watch.S
-syscall_src += arch-mips/syscalls/inotify_init1.S
-syscall_src += arch-mips/syscalls/inotify_rm_watch.S
-syscall_src += arch-mips/syscalls/ioprio_get.S
-syscall_src += arch-mips/syscalls/ioprio_set.S
-syscall_src += arch-mips/syscalls/kill.S
-syscall_src += arch-mips/syscalls/klogctl.S
-syscall_src += arch-mips/syscalls/lgetxattr.S
-syscall_src += arch-mips/syscalls/linkat.S
-syscall_src += arch-mips/syscalls/listen.S
-syscall_src += arch-mips/syscalls/listxattr.S
-syscall_src += arch-mips/syscalls/llistxattr.S
-syscall_src += arch-mips/syscalls/lremovexattr.S
-syscall_src += arch-mips/syscalls/lseek.S
-syscall_src += arch-mips/syscalls/lsetxattr.S
-syscall_src += arch-mips/syscalls/madvise.S
-syscall_src += arch-mips/syscalls/mincore.S
-syscall_src += arch-mips/syscalls/mkdirat.S
-syscall_src += arch-mips/syscalls/mknodat.S
-syscall_src += arch-mips/syscalls/mlock.S
-syscall_src += arch-mips/syscalls/mlockall.S
-syscall_src += arch-mips/syscalls/mount.S
-syscall_src += arch-mips/syscalls/mprotect.S
-syscall_src += arch-mips/syscalls/mremap.S
-syscall_src += arch-mips/syscalls/msync.S
-syscall_src += arch-mips/syscalls/munlock.S
-syscall_src += arch-mips/syscalls/munlockall.S
-syscall_src += arch-mips/syscalls/munmap.S
-syscall_src += arch-mips/syscalls/nanosleep.S
-syscall_src += arch-mips/syscalls/perf_event_open.S
-syscall_src += arch-mips/syscalls/personality.S
-syscall_src += arch-mips/syscalls/pipe2.S
-syscall_src += arch-mips/syscalls/prctl.S
-syscall_src += arch-mips/syscalls/pread64.S
-syscall_src += arch-mips/syscalls/prlimit64.S
-syscall_src += arch-mips/syscalls/pwrite64.S
-syscall_src += arch-mips/syscalls/read.S
-syscall_src += arch-mips/syscalls/readahead.S
-syscall_src += arch-mips/syscalls/readlinkat.S
-syscall_src += arch-mips/syscalls/readv.S
-syscall_src += arch-mips/syscalls/recvfrom.S
-syscall_src += arch-mips/syscalls/recvmsg.S
-syscall_src += arch-mips/syscalls/removexattr.S
-syscall_src += arch-mips/syscalls/renameat.S
-syscall_src += arch-mips/syscalls/sched_get_priority_max.S
-syscall_src += arch-mips/syscalls/sched_get_priority_min.S
-syscall_src += arch-mips/syscalls/sched_getparam.S
-syscall_src += arch-mips/syscalls/sched_getscheduler.S
-syscall_src += arch-mips/syscalls/sched_rr_get_interval.S
-syscall_src += arch-mips/syscalls/sched_setaffinity.S
-syscall_src += arch-mips/syscalls/sched_setparam.S
-syscall_src += arch-mips/syscalls/sched_setscheduler.S
-syscall_src += arch-mips/syscalls/sched_yield.S
-syscall_src += arch-mips/syscalls/sendfile.S
-syscall_src += arch-mips/syscalls/sendfile64.S
-syscall_src += arch-mips/syscalls/sendmsg.S
-syscall_src += arch-mips/syscalls/sendto.S
-syscall_src += arch-mips/syscalls/setgid.S
-syscall_src += arch-mips/syscalls/setgroups.S
-syscall_src += arch-mips/syscalls/setitimer.S
-syscall_src += arch-mips/syscalls/setns.S
-syscall_src += arch-mips/syscalls/setpgid.S
-syscall_src += arch-mips/syscalls/setpriority.S
-syscall_src += arch-mips/syscalls/setregid.S
-syscall_src += arch-mips/syscalls/setresgid.S
-syscall_src += arch-mips/syscalls/setresuid.S
-syscall_src += arch-mips/syscalls/setreuid.S
-syscall_src += arch-mips/syscalls/setrlimit.S
-syscall_src += arch-mips/syscalls/setsid.S
-syscall_src += arch-mips/syscalls/setsockopt.S
-syscall_src += arch-mips/syscalls/settimeofday.S
-syscall_src += arch-mips/syscalls/setuid.S
-syscall_src += arch-mips/syscalls/setxattr.S
-syscall_src += arch-mips/syscalls/shutdown.S
-syscall_src += arch-mips/syscalls/sigaltstack.S
-syscall_src += arch-mips/syscalls/signalfd4.S
-syscall_src += arch-mips/syscalls/socket.S
-syscall_src += arch-mips/syscalls/socketpair.S
-syscall_src += arch-mips/syscalls/swapoff.S
-syscall_src += arch-mips/syscalls/swapon.S
-syscall_src += arch-mips/syscalls/symlinkat.S
-syscall_src += arch-mips/syscalls/sync.S
-syscall_src += arch-mips/syscalls/sysinfo.S
-syscall_src += arch-mips/syscalls/tgkill.S
-syscall_src += arch-mips/syscalls/timerfd_create.S
-syscall_src += arch-mips/syscalls/timerfd_gettime.S
-syscall_src += arch-mips/syscalls/timerfd_settime.S
-syscall_src += arch-mips/syscalls/times.S
-syscall_src += arch-mips/syscalls/tkill.S
-syscall_src += arch-mips/syscalls/truncate.S
-syscall_src += arch-mips/syscalls/truncate64.S
-syscall_src += arch-mips/syscalls/umask.S
-syscall_src += arch-mips/syscalls/umount2.S
-syscall_src += arch-mips/syscalls/uname.S
-syscall_src += arch-mips/syscalls/unlinkat.S
-syscall_src += arch-mips/syscalls/unshare.S
-syscall_src += arch-mips/syscalls/utimensat.S
-syscall_src += arch-mips/syscalls/wait4.S
-syscall_src += arch-mips/syscalls/write.S
-syscall_src += arch-mips/syscalls/writev.S
diff --git a/libc/arch-mips/syscalls/__accept4.S b/libc/arch-mips/syscalls/__accept4.S
new file mode 100644
index 0000000..72df04f
--- /dev/null
+++ b/libc/arch-mips/syscalls/__accept4.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__accept4)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_accept4
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__accept4)
diff --git a/libc/arch-mips/syscalls/__brk.S b/libc/arch-mips/syscalls/__brk.S
index 87e13bd..8472663 100644
--- a/libc/arch-mips/syscalls/__brk.S
+++ b/libc/arch-mips/syscalls/__brk.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __brk
-    .align 4
-    .ent __brk
+#include <private/bionic_asm.h>
 
-__brk:
+ENTRY(__brk)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_brk
+    .cpload t9
+    li v0, __NR_brk
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __brk
+END(__brk)
diff --git a/libc/arch-mips/syscalls/__connect.S b/libc/arch-mips/syscalls/__connect.S
new file mode 100644
index 0000000..38c1b9b
--- /dev/null
+++ b/libc/arch-mips/syscalls/__connect.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__connect)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_connect
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__connect)
diff --git a/libc/arch-mips/syscalls/__epoll_pwait.S b/libc/arch-mips/syscalls/__epoll_pwait.S
index 0a5fdae..3aed9bc 100644
--- a/libc/arch-mips/syscalls/__epoll_pwait.S
+++ b/libc/arch-mips/syscalls/__epoll_pwait.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __epoll_pwait
-    .align 4
-    .ent __epoll_pwait
+#include <private/bionic_asm.h>
 
-__epoll_pwait:
+ENTRY(__epoll_pwait)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_epoll_pwait
+    .cpload t9
+    li v0, __NR_epoll_pwait
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __epoll_pwait
+END(__epoll_pwait)
diff --git a/libc/arch-mips/syscalls/__exit.S b/libc/arch-mips/syscalls/__exit.S
index 529e49c..7349804 100644
--- a/libc/arch-mips/syscalls/__exit.S
+++ b/libc/arch-mips/syscalls/__exit.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __exit
-    .align 4
-    .ent __exit
+#include <private/bionic_asm.h>
 
-__exit:
+ENTRY(__exit)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_exit
+    .cpload t9
+    li v0, __NR_exit
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __exit
+END(__exit)
diff --git a/libc/arch-mips/syscalls/__fadvise64.S b/libc/arch-mips/syscalls/__fadvise64.S
new file mode 100644
index 0000000..abacbb2
--- /dev/null
+++ b/libc/arch-mips/syscalls/__fadvise64.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__fadvise64)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_fadvise64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__fadvise64)
diff --git a/libc/arch-mips/syscalls/__fcntl64.S b/libc/arch-mips/syscalls/__fcntl64.S
index 39ed4cf..2734be2 100644
--- a/libc/arch-mips/syscalls/__fcntl64.S
+++ b/libc/arch-mips/syscalls/__fcntl64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __fcntl64
-    .align 4
-    .ent __fcntl64
+#include <private/bionic_asm.h>
 
-__fcntl64:
+ENTRY(__fcntl64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fcntl64
+    .cpload t9
+    li v0, __NR_fcntl64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __fcntl64
+END(__fcntl64)
diff --git a/libc/arch-mips/syscalls/__fstatfs64.S b/libc/arch-mips/syscalls/__fstatfs64.S
index 3389a8d..e08cf7e 100644
--- a/libc/arch-mips/syscalls/__fstatfs64.S
+++ b/libc/arch-mips/syscalls/__fstatfs64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __fstatfs64
-    .align 4
-    .ent __fstatfs64
+#include <private/bionic_asm.h>
 
-__fstatfs64:
+ENTRY(__fstatfs64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fstatfs64
+    .cpload t9
+    li v0, __NR_fstatfs64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __fstatfs64
+END(__fstatfs64)
diff --git a/libc/arch-mips/syscalls/__getcpu.S b/libc/arch-mips/syscalls/__getcpu.S
index d29bd62..262f440 100644
--- a/libc/arch-mips/syscalls/__getcpu.S
+++ b/libc/arch-mips/syscalls/__getcpu.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __getcpu
-    .align 4
-    .ent __getcpu
+#include <private/bionic_asm.h>
 
-__getcpu:
+ENTRY(__getcpu)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getcpu
+    .cpload t9
+    li v0, __NR_getcpu
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __getcpu
+END(__getcpu)
diff --git a/libc/arch-mips/syscalls/__getcwd.S b/libc/arch-mips/syscalls/__getcwd.S
index ce05d92..ca6ec7c 100644
--- a/libc/arch-mips/syscalls/__getcwd.S
+++ b/libc/arch-mips/syscalls/__getcwd.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __getcwd
-    .align 4
-    .ent __getcwd
+#include <private/bionic_asm.h>
 
-__getcwd:
+ENTRY(__getcwd)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getcwd
+    .cpload t9
+    li v0, __NR_getcwd
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __getcwd
+END(__getcwd)
diff --git a/libc/arch-mips/syscalls/__getdents64.S b/libc/arch-mips/syscalls/__getdents64.S
new file mode 100644
index 0000000..fe7ef86
--- /dev/null
+++ b/libc/arch-mips/syscalls/__getdents64.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getdents64)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_getdents64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__getdents64)
diff --git a/libc/arch-mips/syscalls/__getpid.S b/libc/arch-mips/syscalls/__getpid.S
new file mode 100644
index 0000000..f5ab049
--- /dev/null
+++ b/libc/arch-mips/syscalls/__getpid.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getpid)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_getpid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__getpid)
diff --git a/libc/arch-mips/syscalls/__getpriority.S b/libc/arch-mips/syscalls/__getpriority.S
index 767b6d0..ef6235d 100644
--- a/libc/arch-mips/syscalls/__getpriority.S
+++ b/libc/arch-mips/syscalls/__getpriority.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __getpriority
-    .align 4
-    .ent __getpriority
+#include <private/bionic_asm.h>
 
-__getpriority:
+ENTRY(__getpriority)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getpriority
+    .cpload t9
+    li v0, __NR_getpriority
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __getpriority
+END(__getpriority)
diff --git a/libc/arch-mips/syscalls/__ioctl.S b/libc/arch-mips/syscalls/__ioctl.S
index 3d83c60..27716e8 100644
--- a/libc/arch-mips/syscalls/__ioctl.S
+++ b/libc/arch-mips/syscalls/__ioctl.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __ioctl
-    .align 4
-    .ent __ioctl
+#include <private/bionic_asm.h>
 
-__ioctl:
+ENTRY(__ioctl)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ioctl
+    .cpload t9
+    li v0, __NR_ioctl
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __ioctl
+END(__ioctl)
diff --git a/libc/arch-mips/syscalls/__llseek.S b/libc/arch-mips/syscalls/__llseek.S
index 9a3753b..e0cb321 100644
--- a/libc/arch-mips/syscalls/__llseek.S
+++ b/libc/arch-mips/syscalls/__llseek.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __llseek
-    .align 4
-    .ent __llseek
+#include <private/bionic_asm.h>
 
-__llseek:
+ENTRY(__llseek)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR__llseek
+    .cpload t9
+    li v0, __NR__llseek
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __llseek
+END(__llseek)
diff --git a/libc/arch-mips/syscalls/__mmap2.S b/libc/arch-mips/syscalls/__mmap2.S
index 723e80e..8175b31 100644
--- a/libc/arch-mips/syscalls/__mmap2.S
+++ b/libc/arch-mips/syscalls/__mmap2.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __mmap2
-    .align 4
-    .ent __mmap2
+#include <private/bionic_asm.h>
 
-__mmap2:
+ENTRY(__mmap2)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mmap2
+    .cpload t9
+    li v0, __NR_mmap2
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __mmap2
+END(__mmap2)
diff --git a/libc/arch-mips/syscalls/__openat.S b/libc/arch-mips/syscalls/__openat.S
index e55e71d..c0c3cdf 100644
--- a/libc/arch-mips/syscalls/__openat.S
+++ b/libc/arch-mips/syscalls/__openat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __openat
-    .align 4
-    .ent __openat
+#include <private/bionic_asm.h>
 
-__openat:
+ENTRY(__openat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_openat
+    .cpload t9
+    li v0, __NR_openat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __openat
+END(__openat)
diff --git a/libc/arch-mips/syscalls/__ppoll.S b/libc/arch-mips/syscalls/__ppoll.S
index ef6d343..75dbbc8 100644
--- a/libc/arch-mips/syscalls/__ppoll.S
+++ b/libc/arch-mips/syscalls/__ppoll.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __ppoll
-    .align 4
-    .ent __ppoll
+#include <private/bionic_asm.h>
 
-__ppoll:
+ENTRY(__ppoll)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ppoll
+    .cpload t9
+    li v0, __NR_ppoll
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __ppoll
+END(__ppoll)
diff --git a/libc/arch-mips/syscalls/__pselect6.S b/libc/arch-mips/syscalls/__pselect6.S
index 26af92a..d028156 100644
--- a/libc/arch-mips/syscalls/__pselect6.S
+++ b/libc/arch-mips/syscalls/__pselect6.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __pselect6
-    .align 4
-    .ent __pselect6
+#include <private/bionic_asm.h>
 
-__pselect6:
+ENTRY(__pselect6)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_pselect6
+    .cpload t9
+    li v0, __NR_pselect6
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __pselect6
+END(__pselect6)
diff --git a/libc/arch-mips/syscalls/__ptrace.S b/libc/arch-mips/syscalls/__ptrace.S
index f2ea8c7..c5d91fb 100644
--- a/libc/arch-mips/syscalls/__ptrace.S
+++ b/libc/arch-mips/syscalls/__ptrace.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __ptrace
-    .align 4
-    .ent __ptrace
+#include <private/bionic_asm.h>
 
-__ptrace:
+ENTRY(__ptrace)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ptrace
+    .cpload t9
+    li v0, __NR_ptrace
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __ptrace
+END(__ptrace)
diff --git a/libc/arch-mips/syscalls/__reboot.S b/libc/arch-mips/syscalls/__reboot.S
index 95ba5d8..c01f7fb 100644
--- a/libc/arch-mips/syscalls/__reboot.S
+++ b/libc/arch-mips/syscalls/__reboot.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __reboot
-    .align 4
-    .ent __reboot
+#include <private/bionic_asm.h>
 
-__reboot:
+ENTRY(__reboot)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_reboot
+    .cpload t9
+    li v0, __NR_reboot
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __reboot
+END(__reboot)
diff --git a/libc/arch-mips/syscalls/__rt_sigaction.S b/libc/arch-mips/syscalls/__rt_sigaction.S
index 73253d6..7fa37fd 100644
--- a/libc/arch-mips/syscalls/__rt_sigaction.S
+++ b/libc/arch-mips/syscalls/__rt_sigaction.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigaction
-    .align 4
-    .ent __rt_sigaction
+#include <private/bionic_asm.h>
 
-__rt_sigaction:
+ENTRY(__rt_sigaction)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigaction
+    .cpload t9
+    li v0, __NR_rt_sigaction
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __rt_sigaction
+END(__rt_sigaction)
diff --git a/libc/arch-mips/syscalls/__rt_sigpending.S b/libc/arch-mips/syscalls/__rt_sigpending.S
index 90357b3..b80b311 100644
--- a/libc/arch-mips/syscalls/__rt_sigpending.S
+++ b/libc/arch-mips/syscalls/__rt_sigpending.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigpending
-    .align 4
-    .ent __rt_sigpending
+#include <private/bionic_asm.h>
 
-__rt_sigpending:
+ENTRY(__rt_sigpending)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigpending
+    .cpload t9
+    li v0, __NR_rt_sigpending
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __rt_sigpending
+END(__rt_sigpending)
diff --git a/libc/arch-mips/syscalls/__rt_sigprocmask.S b/libc/arch-mips/syscalls/__rt_sigprocmask.S
index 0d34e37..e2a39eb 100644
--- a/libc/arch-mips/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-mips/syscalls/__rt_sigprocmask.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigprocmask
-    .align 4
-    .ent __rt_sigprocmask
+#include <private/bionic_asm.h>
 
-__rt_sigprocmask:
+ENTRY(__rt_sigprocmask)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigprocmask
+    .cpload t9
+    li v0, __NR_rt_sigprocmask
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __rt_sigprocmask
+END(__rt_sigprocmask)
diff --git a/libc/arch-mips/syscalls/__rt_sigsuspend.S b/libc/arch-mips/syscalls/__rt_sigsuspend.S
index 3ff4723..e91c53f 100644
--- a/libc/arch-mips/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-mips/syscalls/__rt_sigsuspend.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigsuspend
-    .align 4
-    .ent __rt_sigsuspend
+#include <private/bionic_asm.h>
 
-__rt_sigsuspend:
+ENTRY(__rt_sigsuspend)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigsuspend
+    .cpload t9
+    li v0, __NR_rt_sigsuspend
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __rt_sigsuspend
+END(__rt_sigsuspend)
diff --git a/libc/arch-mips/syscalls/__rt_sigtimedwait.S b/libc/arch-mips/syscalls/__rt_sigtimedwait.S
index 19a5ce9..0b4195f 100644
--- a/libc/arch-mips/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-mips/syscalls/__rt_sigtimedwait.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigtimedwait
-    .align 4
-    .ent __rt_sigtimedwait
+#include <private/bionic_asm.h>
 
-__rt_sigtimedwait:
+ENTRY(__rt_sigtimedwait)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigtimedwait
+    .cpload t9
+    li v0, __NR_rt_sigtimedwait
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __rt_sigtimedwait
+END(__rt_sigtimedwait)
diff --git a/libc/arch-mips/syscalls/__sched_getaffinity.S b/libc/arch-mips/syscalls/__sched_getaffinity.S
index 0038ff9..b09f404 100644
--- a/libc/arch-mips/syscalls/__sched_getaffinity.S
+++ b/libc/arch-mips/syscalls/__sched_getaffinity.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __sched_getaffinity
-    .align 4
-    .ent __sched_getaffinity
+#include <private/bionic_asm.h>
 
-__sched_getaffinity:
+ENTRY(__sched_getaffinity)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_getaffinity
+    .cpload t9
+    li v0, __NR_sched_getaffinity
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __sched_getaffinity
+END(__sched_getaffinity)
diff --git a/libc/arch-mips/syscalls/__set_thread_area.S b/libc/arch-mips/syscalls/__set_thread_area.S
deleted file mode 100644
index 69383e9..0000000
--- a/libc/arch-mips/syscalls/__set_thread_area.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl __set_thread_area
-    .align 4
-    .ent __set_thread_area
-
-__set_thread_area:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_set_thread_area
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end __set_thread_area
diff --git a/libc/arch-mips/syscalls/__set_tid_address.S b/libc/arch-mips/syscalls/__set_tid_address.S
index 4fcc82a..8ca0716 100644
--- a/libc/arch-mips/syscalls/__set_tid_address.S
+++ b/libc/arch-mips/syscalls/__set_tid_address.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __set_tid_address
-    .align 4
-    .ent __set_tid_address
+#include <private/bionic_asm.h>
 
-__set_tid_address:
+ENTRY(__set_tid_address)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_set_tid_address
+    .cpload t9
+    li v0, __NR_set_tid_address
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __set_tid_address
+END(__set_tid_address)
diff --git a/libc/arch-mips/syscalls/__set_tls.S b/libc/arch-mips/syscalls/__set_tls.S
new file mode 100644
index 0000000..1f9eba5
--- /dev/null
+++ b/libc/arch-mips/syscalls/__set_tls.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__set_tls)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_set_thread_area
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__set_tls)
diff --git a/libc/arch-mips/syscalls/__sigaction.S b/libc/arch-mips/syscalls/__sigaction.S
index cc53ab4..0886e95 100644
--- a/libc/arch-mips/syscalls/__sigaction.S
+++ b/libc/arch-mips/syscalls/__sigaction.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __sigaction
-    .align 4
-    .ent __sigaction
+#include <private/bionic_asm.h>
 
-__sigaction:
+ENTRY(__sigaction)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sigaction
+    .cpload t9
+    li v0, __NR_sigaction
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __sigaction
+END(__sigaction)
diff --git a/libc/arch-mips/syscalls/__signalfd4.S b/libc/arch-mips/syscalls/__signalfd4.S
new file mode 100644
index 0000000..8e5717e
--- /dev/null
+++ b/libc/arch-mips/syscalls/__signalfd4.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__signalfd4)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_signalfd4
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__signalfd4)
diff --git a/libc/arch-mips/syscalls/__socket.S b/libc/arch-mips/syscalls/__socket.S
new file mode 100644
index 0000000..c933355
--- /dev/null
+++ b/libc/arch-mips/syscalls/__socket.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__socket)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_socket
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__socket)
diff --git a/libc/arch-mips/syscalls/__statfs64.S b/libc/arch-mips/syscalls/__statfs64.S
index 4b3351c..ed4dcdb 100644
--- a/libc/arch-mips/syscalls/__statfs64.S
+++ b/libc/arch-mips/syscalls/__statfs64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __statfs64
-    .align 4
-    .ent __statfs64
+#include <private/bionic_asm.h>
 
-__statfs64:
+ENTRY(__statfs64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_statfs64
+    .cpload t9
+    li v0, __NR_statfs64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __statfs64
+END(__statfs64)
diff --git a/libc/arch-mips/syscalls/__syslog.S b/libc/arch-mips/syscalls/__syslog.S
deleted file mode 100644
index 61a3242..0000000
--- a/libc/arch-mips/syscalls/__syslog.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl __syslog
-    .align 4
-    .ent __syslog
-
-__syslog:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_syslog
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end __syslog
diff --git a/libc/arch-mips/syscalls/__timer_create.S b/libc/arch-mips/syscalls/__timer_create.S
index 054c1b9..ef50749 100644
--- a/libc/arch-mips/syscalls/__timer_create.S
+++ b/libc/arch-mips/syscalls/__timer_create.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_create
-    .align 4
-    .ent __timer_create
+#include <private/bionic_asm.h>
 
-__timer_create:
+ENTRY(__timer_create)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_create
+    .cpload t9
+    li v0, __NR_timer_create
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __timer_create
+END(__timer_create)
diff --git a/libc/arch-mips/syscalls/__timer_delete.S b/libc/arch-mips/syscalls/__timer_delete.S
index 2fa6e50..5993ace 100644
--- a/libc/arch-mips/syscalls/__timer_delete.S
+++ b/libc/arch-mips/syscalls/__timer_delete.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_delete
-    .align 4
-    .ent __timer_delete
+#include <private/bionic_asm.h>
 
-__timer_delete:
+ENTRY(__timer_delete)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_delete
+    .cpload t9
+    li v0, __NR_timer_delete
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __timer_delete
+END(__timer_delete)
diff --git a/libc/arch-mips/syscalls/__timer_getoverrun.S b/libc/arch-mips/syscalls/__timer_getoverrun.S
index 269ac4d..31234e5 100644
--- a/libc/arch-mips/syscalls/__timer_getoverrun.S
+++ b/libc/arch-mips/syscalls/__timer_getoverrun.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_getoverrun
-    .align 4
-    .ent __timer_getoverrun
+#include <private/bionic_asm.h>
 
-__timer_getoverrun:
+ENTRY(__timer_getoverrun)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_getoverrun
+    .cpload t9
+    li v0, __NR_timer_getoverrun
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __timer_getoverrun
+END(__timer_getoverrun)
diff --git a/libc/arch-mips/syscalls/__timer_gettime.S b/libc/arch-mips/syscalls/__timer_gettime.S
index 3a18e3d..38800d3 100644
--- a/libc/arch-mips/syscalls/__timer_gettime.S
+++ b/libc/arch-mips/syscalls/__timer_gettime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_gettime
-    .align 4
-    .ent __timer_gettime
+#include <private/bionic_asm.h>
 
-__timer_gettime:
+ENTRY(__timer_gettime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_gettime
+    .cpload t9
+    li v0, __NR_timer_gettime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __timer_gettime
+END(__timer_gettime)
diff --git a/libc/arch-mips/syscalls/__timer_settime.S b/libc/arch-mips/syscalls/__timer_settime.S
index daf671f..73cea73 100644
--- a/libc/arch-mips/syscalls/__timer_settime.S
+++ b/libc/arch-mips/syscalls/__timer_settime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_settime
-    .align 4
-    .ent __timer_settime
+#include <private/bionic_asm.h>
 
-__timer_settime:
+ENTRY(__timer_settime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_settime
+    .cpload t9
+    li v0, __NR_timer_settime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __timer_settime
+END(__timer_settime)
diff --git a/libc/arch-mips/syscalls/__waitid.S b/libc/arch-mips/syscalls/__waitid.S
index 9442ca6..9d17f8f 100644
--- a/libc/arch-mips/syscalls/__waitid.S
+++ b/libc/arch-mips/syscalls/__waitid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __waitid
-    .align 4
-    .ent __waitid
+#include <private/bionic_asm.h>
 
-__waitid:
+ENTRY(__waitid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_waitid
+    .cpload t9
+    li v0, __NR_waitid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end __waitid
+END(__waitid)
diff --git a/libc/arch-mips/syscalls/_exit.S b/libc/arch-mips/syscalls/_exit.S
index 220876a..5ac1324 100644
--- a/libc/arch-mips/syscalls/_exit.S
+++ b/libc/arch-mips/syscalls/_exit.S
@@ -1,23 +1,22 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl _exit
-    .align 4
-    .ent _exit
+#include <private/bionic_asm.h>
 
-_exit:
+ENTRY(_exit)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_exit_group
+    .cpload t9
+    li v0, __NR_exit_group
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end _exit
+END(_exit)
+
+    .globl _Exit
+    .equ _Exit, _exit
diff --git a/libc/arch-mips/syscalls/_flush_cache.S b/libc/arch-mips/syscalls/_flush_cache.S
index 0ac2576..a4030e9 100644
--- a/libc/arch-mips/syscalls/_flush_cache.S
+++ b/libc/arch-mips/syscalls/_flush_cache.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl _flush_cache
-    .align 4
-    .ent _flush_cache
+#include <private/bionic_asm.h>
 
-_flush_cache:
+ENTRY(_flush_cache)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_cacheflush
+    .cpload t9
+    li v0, __NR_cacheflush
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end _flush_cache
+END(_flush_cache)
diff --git a/libc/arch-mips/syscalls/accept.S b/libc/arch-mips/syscalls/accept.S
deleted file mode 100644
index f4da4d8..0000000
--- a/libc/arch-mips/syscalls/accept.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl accept
-    .align 4
-    .ent accept
-
-accept:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_accept
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end accept
diff --git a/libc/arch-mips/syscalls/acct.S b/libc/arch-mips/syscalls/acct.S
index c641b9c..e3a5ccd 100644
--- a/libc/arch-mips/syscalls/acct.S
+++ b/libc/arch-mips/syscalls/acct.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl acct
-    .align 4
-    .ent acct
+#include <private/bionic_asm.h>
 
-acct:
+ENTRY(acct)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_acct
+    .cpload t9
+    li v0, __NR_acct
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end acct
+END(acct)
diff --git a/libc/arch-mips/syscalls/bind.S b/libc/arch-mips/syscalls/bind.S
index 912b161..78fe2bb 100644
--- a/libc/arch-mips/syscalls/bind.S
+++ b/libc/arch-mips/syscalls/bind.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl bind
-    .align 4
-    .ent bind
+#include <private/bionic_asm.h>
 
-bind:
+ENTRY(bind)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_bind
+    .cpload t9
+    li v0, __NR_bind
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end bind
+END(bind)
diff --git a/libc/arch-mips/syscalls/capget.S b/libc/arch-mips/syscalls/capget.S
index 48f7be3..0cbb626 100644
--- a/libc/arch-mips/syscalls/capget.S
+++ b/libc/arch-mips/syscalls/capget.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl capget
-    .align 4
-    .ent capget
+#include <private/bionic_asm.h>
 
-capget:
+ENTRY(capget)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_capget
+    .cpload t9
+    li v0, __NR_capget
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end capget
+END(capget)
diff --git a/libc/arch-mips/syscalls/capset.S b/libc/arch-mips/syscalls/capset.S
index 40223c2..e811080 100644
--- a/libc/arch-mips/syscalls/capset.S
+++ b/libc/arch-mips/syscalls/capset.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl capset
-    .align 4
-    .ent capset
+#include <private/bionic_asm.h>
 
-capset:
+ENTRY(capset)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_capset
+    .cpload t9
+    li v0, __NR_capset
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end capset
+END(capset)
diff --git a/libc/arch-mips/syscalls/chdir.S b/libc/arch-mips/syscalls/chdir.S
index 4f427a1..82b7a2b 100644
--- a/libc/arch-mips/syscalls/chdir.S
+++ b/libc/arch-mips/syscalls/chdir.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl chdir
-    .align 4
-    .ent chdir
+#include <private/bionic_asm.h>
 
-chdir:
+ENTRY(chdir)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_chdir
+    .cpload t9
+    li v0, __NR_chdir
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end chdir
+END(chdir)
diff --git a/libc/arch-mips/syscalls/chroot.S b/libc/arch-mips/syscalls/chroot.S
index a501459..e6a29fc 100644
--- a/libc/arch-mips/syscalls/chroot.S
+++ b/libc/arch-mips/syscalls/chroot.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl chroot
-    .align 4
-    .ent chroot
+#include <private/bionic_asm.h>
 
-chroot:
+ENTRY(chroot)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_chroot
+    .cpload t9
+    li v0, __NR_chroot
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end chroot
+END(chroot)
diff --git a/libc/arch-mips/syscalls/clock_getres.S b/libc/arch-mips/syscalls/clock_getres.S
index d3986fc..ac7c5c6 100644
--- a/libc/arch-mips/syscalls/clock_getres.S
+++ b/libc/arch-mips/syscalls/clock_getres.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl clock_getres
-    .align 4
-    .ent clock_getres
+#include <private/bionic_asm.h>
 
-clock_getres:
+ENTRY(clock_getres)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_clock_getres
+    .cpload t9
+    li v0, __NR_clock_getres
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end clock_getres
+END(clock_getres)
diff --git a/libc/arch-mips/syscalls/clock_gettime.S b/libc/arch-mips/syscalls/clock_gettime.S
index fa02309..d227a06 100644
--- a/libc/arch-mips/syscalls/clock_gettime.S
+++ b/libc/arch-mips/syscalls/clock_gettime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl clock_gettime
-    .align 4
-    .ent clock_gettime
+#include <private/bionic_asm.h>
 
-clock_gettime:
+ENTRY(clock_gettime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_clock_gettime
+    .cpload t9
+    li v0, __NR_clock_gettime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end clock_gettime
+END(clock_gettime)
diff --git a/libc/arch-mips/syscalls/clock_nanosleep.S b/libc/arch-mips/syscalls/clock_nanosleep.S
index 91a1418..6002ab4 100644
--- a/libc/arch-mips/syscalls/clock_nanosleep.S
+++ b/libc/arch-mips/syscalls/clock_nanosleep.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl clock_nanosleep
-    .align 4
-    .ent clock_nanosleep
+#include <private/bionic_asm.h>
 
-clock_nanosleep:
+ENTRY(clock_nanosleep)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_clock_nanosleep
+    .cpload t9
+    li v0, __NR_clock_nanosleep
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end clock_nanosleep
+END(clock_nanosleep)
diff --git a/libc/arch-mips/syscalls/clock_settime.S b/libc/arch-mips/syscalls/clock_settime.S
index d8eb8f1..193bdc2 100644
--- a/libc/arch-mips/syscalls/clock_settime.S
+++ b/libc/arch-mips/syscalls/clock_settime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl clock_settime
-    .align 4
-    .ent clock_settime
+#include <private/bionic_asm.h>
 
-clock_settime:
+ENTRY(clock_settime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_clock_settime
+    .cpload t9
+    li v0, __NR_clock_settime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end clock_settime
+END(clock_settime)
diff --git a/libc/arch-mips/syscalls/close.S b/libc/arch-mips/syscalls/close.S
index 098fdd2..231f497 100644
--- a/libc/arch-mips/syscalls/close.S
+++ b/libc/arch-mips/syscalls/close.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl close
-    .align 4
-    .ent close
+#include <private/bionic_asm.h>
 
-close:
+ENTRY(close)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_close
+    .cpload t9
+    li v0, __NR_close
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end close
+END(close)
diff --git a/libc/arch-mips/syscalls/connect.S b/libc/arch-mips/syscalls/connect.S
deleted file mode 100644
index d3b0cea..0000000
--- a/libc/arch-mips/syscalls/connect.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl connect
-    .align 4
-    .ent connect
-
-connect:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_connect
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end connect
diff --git a/libc/arch-mips/syscalls/delete_module.S b/libc/arch-mips/syscalls/delete_module.S
index ae47697..8c01c06 100644
--- a/libc/arch-mips/syscalls/delete_module.S
+++ b/libc/arch-mips/syscalls/delete_module.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl delete_module
-    .align 4
-    .ent delete_module
+#include <private/bionic_asm.h>
 
-delete_module:
+ENTRY(delete_module)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_delete_module
+    .cpload t9
+    li v0, __NR_delete_module
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end delete_module
+END(delete_module)
diff --git a/libc/arch-mips/syscalls/dup.S b/libc/arch-mips/syscalls/dup.S
index 6cb924f..b4dcd70 100644
--- a/libc/arch-mips/syscalls/dup.S
+++ b/libc/arch-mips/syscalls/dup.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl dup
-    .align 4
-    .ent dup
+#include <private/bionic_asm.h>
 
-dup:
+ENTRY(dup)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_dup
+    .cpload t9
+    li v0, __NR_dup
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end dup
+END(dup)
diff --git a/libc/arch-mips/syscalls/dup3.S b/libc/arch-mips/syscalls/dup3.S
index 6a3752c..1d9c236 100644
--- a/libc/arch-mips/syscalls/dup3.S
+++ b/libc/arch-mips/syscalls/dup3.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl dup3
-    .align 4
-    .ent dup3
+#include <private/bionic_asm.h>
 
-dup3:
+ENTRY(dup3)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_dup3
+    .cpload t9
+    li v0, __NR_dup3
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end dup3
+END(dup3)
diff --git a/libc/arch-mips/syscalls/epoll_create1.S b/libc/arch-mips/syscalls/epoll_create1.S
index 0abaeda..8754879 100644
--- a/libc/arch-mips/syscalls/epoll_create1.S
+++ b/libc/arch-mips/syscalls/epoll_create1.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl epoll_create1
-    .align 4
-    .ent epoll_create1
+#include <private/bionic_asm.h>
 
-epoll_create1:
+ENTRY(epoll_create1)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_epoll_create1
+    .cpload t9
+    li v0, __NR_epoll_create1
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end epoll_create1
+END(epoll_create1)
diff --git a/libc/arch-mips/syscalls/epoll_ctl.S b/libc/arch-mips/syscalls/epoll_ctl.S
index 20d4367..14c9202 100644
--- a/libc/arch-mips/syscalls/epoll_ctl.S
+++ b/libc/arch-mips/syscalls/epoll_ctl.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl epoll_ctl
-    .align 4
-    .ent epoll_ctl
+#include <private/bionic_asm.h>
 
-epoll_ctl:
+ENTRY(epoll_ctl)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_epoll_ctl
+    .cpload t9
+    li v0, __NR_epoll_ctl
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end epoll_ctl
+END(epoll_ctl)
diff --git a/libc/arch-mips/syscalls/eventfd.S b/libc/arch-mips/syscalls/eventfd.S
index f12bc7d..6494dbc 100644
--- a/libc/arch-mips/syscalls/eventfd.S
+++ b/libc/arch-mips/syscalls/eventfd.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl eventfd
-    .align 4
-    .ent eventfd
+#include <private/bionic_asm.h>
 
-eventfd:
+ENTRY(eventfd)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_eventfd2
+    .cpload t9
+    li v0, __NR_eventfd2
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end eventfd
+END(eventfd)
diff --git a/libc/arch-mips/syscalls/execve.S b/libc/arch-mips/syscalls/execve.S
index 750b402..2d20b51 100644
--- a/libc/arch-mips/syscalls/execve.S
+++ b/libc/arch-mips/syscalls/execve.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl execve
-    .align 4
-    .ent execve
+#include <private/bionic_asm.h>
 
-execve:
+ENTRY(execve)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_execve
+    .cpload t9
+    li v0, __NR_execve
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end execve
+END(execve)
diff --git a/libc/arch-mips/syscalls/faccessat.S b/libc/arch-mips/syscalls/faccessat.S
index ffa4f42..e616106 100644
--- a/libc/arch-mips/syscalls/faccessat.S
+++ b/libc/arch-mips/syscalls/faccessat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl faccessat
-    .align 4
-    .ent faccessat
+#include <private/bionic_asm.h>
 
-faccessat:
+ENTRY(faccessat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_faccessat
+    .cpload t9
+    li v0, __NR_faccessat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end faccessat
+END(faccessat)
diff --git a/libc/arch-mips/syscalls/fallocate64.S b/libc/arch-mips/syscalls/fallocate64.S
new file mode 100644
index 0000000..5f05513
--- /dev/null
+++ b/libc/arch-mips/syscalls/fallocate64.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fallocate64)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_fallocate
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(fallocate64)
diff --git a/libc/arch-mips/syscalls/fchdir.S b/libc/arch-mips/syscalls/fchdir.S
index ae0b883..d683baa 100644
--- a/libc/arch-mips/syscalls/fchdir.S
+++ b/libc/arch-mips/syscalls/fchdir.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchdir
-    .align 4
-    .ent fchdir
+#include <private/bionic_asm.h>
 
-fchdir:
+ENTRY(fchdir)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchdir
+    .cpload t9
+    li v0, __NR_fchdir
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fchdir
+END(fchdir)
diff --git a/libc/arch-mips/syscalls/fchmod.S b/libc/arch-mips/syscalls/fchmod.S
index 272964e..2a95cc3 100644
--- a/libc/arch-mips/syscalls/fchmod.S
+++ b/libc/arch-mips/syscalls/fchmod.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchmod
-    .align 4
-    .ent fchmod
+#include <private/bionic_asm.h>
 
-fchmod:
+ENTRY(fchmod)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchmod
+    .cpload t9
+    li v0, __NR_fchmod
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fchmod
+END(fchmod)
diff --git a/libc/arch-mips/syscalls/fchmodat.S b/libc/arch-mips/syscalls/fchmodat.S
index 388d221..d9de036 100644
--- a/libc/arch-mips/syscalls/fchmodat.S
+++ b/libc/arch-mips/syscalls/fchmodat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchmodat
-    .align 4
-    .ent fchmodat
+#include <private/bionic_asm.h>
 
-fchmodat:
+ENTRY(fchmodat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchmodat
+    .cpload t9
+    li v0, __NR_fchmodat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fchmodat
+END(fchmodat)
diff --git a/libc/arch-mips/syscalls/fchown.S b/libc/arch-mips/syscalls/fchown.S
index 52d6e59..1ac9451 100644
--- a/libc/arch-mips/syscalls/fchown.S
+++ b/libc/arch-mips/syscalls/fchown.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchown
-    .align 4
-    .ent fchown
+#include <private/bionic_asm.h>
 
-fchown:
+ENTRY(fchown)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchown
+    .cpload t9
+    li v0, __NR_fchown
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fchown
+END(fchown)
diff --git a/libc/arch-mips/syscalls/fchownat.S b/libc/arch-mips/syscalls/fchownat.S
index 6913d6c..be1a021 100644
--- a/libc/arch-mips/syscalls/fchownat.S
+++ b/libc/arch-mips/syscalls/fchownat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchownat
-    .align 4
-    .ent fchownat
+#include <private/bionic_asm.h>
 
-fchownat:
+ENTRY(fchownat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchownat
+    .cpload t9
+    li v0, __NR_fchownat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fchownat
+END(fchownat)
diff --git a/libc/arch-mips/syscalls/fdatasync.S b/libc/arch-mips/syscalls/fdatasync.S
index a1d4056..24d6541 100644
--- a/libc/arch-mips/syscalls/fdatasync.S
+++ b/libc/arch-mips/syscalls/fdatasync.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fdatasync
-    .align 4
-    .ent fdatasync
+#include <private/bionic_asm.h>
 
-fdatasync:
+ENTRY(fdatasync)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fdatasync
+    .cpload t9
+    li v0, __NR_fdatasync
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fdatasync
+END(fdatasync)
diff --git a/libc/arch-mips/syscalls/fgetxattr.S b/libc/arch-mips/syscalls/fgetxattr.S
index 1d645a5..6516feb 100644
--- a/libc/arch-mips/syscalls/fgetxattr.S
+++ b/libc/arch-mips/syscalls/fgetxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fgetxattr
-    .align 4
-    .ent fgetxattr
+#include <private/bionic_asm.h>
 
-fgetxattr:
+ENTRY(fgetxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fgetxattr
+    .cpload t9
+    li v0, __NR_fgetxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fgetxattr
+END(fgetxattr)
diff --git a/libc/arch-mips/syscalls/flistxattr.S b/libc/arch-mips/syscalls/flistxattr.S
index 2cb53c5..0b71532 100644
--- a/libc/arch-mips/syscalls/flistxattr.S
+++ b/libc/arch-mips/syscalls/flistxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl flistxattr
-    .align 4
-    .ent flistxattr
+#include <private/bionic_asm.h>
 
-flistxattr:
+ENTRY(flistxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_flistxattr
+    .cpload t9
+    li v0, __NR_flistxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end flistxattr
+END(flistxattr)
diff --git a/libc/arch-mips/syscalls/flock.S b/libc/arch-mips/syscalls/flock.S
index c1723a1..8d70c9e 100644
--- a/libc/arch-mips/syscalls/flock.S
+++ b/libc/arch-mips/syscalls/flock.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl flock
-    .align 4
-    .ent flock
+#include <private/bionic_asm.h>
 
-flock:
+ENTRY(flock)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_flock
+    .cpload t9
+    li v0, __NR_flock
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end flock
+END(flock)
diff --git a/libc/arch-mips/syscalls/fremovexattr.S b/libc/arch-mips/syscalls/fremovexattr.S
index 2526ae0..fba2d6d 100644
--- a/libc/arch-mips/syscalls/fremovexattr.S
+++ b/libc/arch-mips/syscalls/fremovexattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fremovexattr
-    .align 4
-    .ent fremovexattr
+#include <private/bionic_asm.h>
 
-fremovexattr:
+ENTRY(fremovexattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fremovexattr
+    .cpload t9
+    li v0, __NR_fremovexattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fremovexattr
+END(fremovexattr)
diff --git a/libc/arch-mips/syscalls/fsetxattr.S b/libc/arch-mips/syscalls/fsetxattr.S
index 4552b07..663c0df 100644
--- a/libc/arch-mips/syscalls/fsetxattr.S
+++ b/libc/arch-mips/syscalls/fsetxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fsetxattr
-    .align 4
-    .ent fsetxattr
+#include <private/bionic_asm.h>
 
-fsetxattr:
+ENTRY(fsetxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fsetxattr
+    .cpload t9
+    li v0, __NR_fsetxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fsetxattr
+END(fsetxattr)
diff --git a/libc/arch-mips/syscalls/fstat.S b/libc/arch-mips/syscalls/fstat.S
deleted file mode 100644
index 77eabf8..0000000
--- a/libc/arch-mips/syscalls/fstat.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl fstat
-    .align 4
-    .ent fstat
-
-fstat:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_fstat64
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end fstat
diff --git a/libc/arch-mips/syscalls/fstat64.S b/libc/arch-mips/syscalls/fstat64.S
new file mode 100644
index 0000000..525c23c
--- /dev/null
+++ b/libc/arch-mips/syscalls/fstat64.S
@@ -0,0 +1,22 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstat64)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_fstat64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(fstat64)
+
+    .globl fstat
+    .equ fstat, fstat64
diff --git a/libc/arch-mips/syscalls/fstatat.S b/libc/arch-mips/syscalls/fstatat.S
deleted file mode 100644
index 478f099..0000000
--- a/libc/arch-mips/syscalls/fstatat.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl fstatat
-    .align 4
-    .ent fstatat
-
-fstatat:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_fstatat64
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end fstatat
diff --git a/libc/arch-mips/syscalls/fstatat64.S b/libc/arch-mips/syscalls/fstatat64.S
new file mode 100644
index 0000000..f7b8e1d
--- /dev/null
+++ b/libc/arch-mips/syscalls/fstatat64.S
@@ -0,0 +1,22 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatat64)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_fstatat64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(fstatat64)
+
+    .globl fstatat
+    .equ fstatat, fstatat64
diff --git a/libc/arch-mips/syscalls/fsync.S b/libc/arch-mips/syscalls/fsync.S
index 383bd0c..819f0f2 100644
--- a/libc/arch-mips/syscalls/fsync.S
+++ b/libc/arch-mips/syscalls/fsync.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fsync
-    .align 4
-    .ent fsync
+#include <private/bionic_asm.h>
 
-fsync:
+ENTRY(fsync)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fsync
+    .cpload t9
+    li v0, __NR_fsync
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end fsync
+END(fsync)
diff --git a/libc/arch-mips/syscalls/ftruncate.S b/libc/arch-mips/syscalls/ftruncate.S
index 797d239..0589c81 100644
--- a/libc/arch-mips/syscalls/ftruncate.S
+++ b/libc/arch-mips/syscalls/ftruncate.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl ftruncate
-    .align 4
-    .ent ftruncate
+#include <private/bionic_asm.h>
 
-ftruncate:
+ENTRY(ftruncate)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ftruncate
+    .cpload t9
+    li v0, __NR_ftruncate
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end ftruncate
+END(ftruncate)
diff --git a/libc/arch-mips/syscalls/ftruncate64.S b/libc/arch-mips/syscalls/ftruncate64.S
index e7f7f81..059ff77 100644
--- a/libc/arch-mips/syscalls/ftruncate64.S
+++ b/libc/arch-mips/syscalls/ftruncate64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl ftruncate64
-    .align 4
-    .ent ftruncate64
+#include <private/bionic_asm.h>
 
-ftruncate64:
+ENTRY(ftruncate64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ftruncate64
+    .cpload t9
+    li v0, __NR_ftruncate64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end ftruncate64
+END(ftruncate64)
diff --git a/libc/arch-mips/syscalls/futex.S b/libc/arch-mips/syscalls/futex.S
deleted file mode 100644
index 25c88c8..0000000
--- a/libc/arch-mips/syscalls/futex.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl futex
-    .align 4
-    .ent futex
-
-futex:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_futex
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end futex
diff --git a/libc/arch-mips/syscalls/getdents.S b/libc/arch-mips/syscalls/getdents.S
deleted file mode 100644
index 7b8006a..0000000
--- a/libc/arch-mips/syscalls/getdents.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl getdents
-    .align 4
-    .ent getdents
-
-getdents:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_getdents64
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end getdents
diff --git a/libc/arch-mips/syscalls/getegid.S b/libc/arch-mips/syscalls/getegid.S
index 5d75420..8ae2d1e 100644
--- a/libc/arch-mips/syscalls/getegid.S
+++ b/libc/arch-mips/syscalls/getegid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getegid
-    .align 4
-    .ent getegid
+#include <private/bionic_asm.h>
 
-getegid:
+ENTRY(getegid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getegid
+    .cpload t9
+    li v0, __NR_getegid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getegid
+END(getegid)
diff --git a/libc/arch-mips/syscalls/geteuid.S b/libc/arch-mips/syscalls/geteuid.S
index f878ea7..cf5cf6c 100644
--- a/libc/arch-mips/syscalls/geteuid.S
+++ b/libc/arch-mips/syscalls/geteuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl geteuid
-    .align 4
-    .ent geteuid
+#include <private/bionic_asm.h>
 
-geteuid:
+ENTRY(geteuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_geteuid
+    .cpload t9
+    li v0, __NR_geteuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end geteuid
+END(geteuid)
diff --git a/libc/arch-mips/syscalls/getgid.S b/libc/arch-mips/syscalls/getgid.S
index 207d1a1..9bd1fc3 100644
--- a/libc/arch-mips/syscalls/getgid.S
+++ b/libc/arch-mips/syscalls/getgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getgid
-    .align 4
-    .ent getgid
+#include <private/bionic_asm.h>
 
-getgid:
+ENTRY(getgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getgid
+    .cpload t9
+    li v0, __NR_getgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getgid
+END(getgid)
diff --git a/libc/arch-mips/syscalls/getgroups.S b/libc/arch-mips/syscalls/getgroups.S
index d0a10a3..2eda185 100644
--- a/libc/arch-mips/syscalls/getgroups.S
+++ b/libc/arch-mips/syscalls/getgroups.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getgroups
-    .align 4
-    .ent getgroups
+#include <private/bionic_asm.h>
 
-getgroups:
+ENTRY(getgroups)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getgroups
+    .cpload t9
+    li v0, __NR_getgroups
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getgroups
+END(getgroups)
diff --git a/libc/arch-mips/syscalls/getitimer.S b/libc/arch-mips/syscalls/getitimer.S
index 40f90f2..2e382c7 100644
--- a/libc/arch-mips/syscalls/getitimer.S
+++ b/libc/arch-mips/syscalls/getitimer.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getitimer
-    .align 4
-    .ent getitimer
+#include <private/bionic_asm.h>
 
-getitimer:
+ENTRY(getitimer)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getitimer
+    .cpload t9
+    li v0, __NR_getitimer
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getitimer
+END(getitimer)
diff --git a/libc/arch-mips/syscalls/getpeername.S b/libc/arch-mips/syscalls/getpeername.S
index 6d491de..8642798 100644
--- a/libc/arch-mips/syscalls/getpeername.S
+++ b/libc/arch-mips/syscalls/getpeername.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getpeername
-    .align 4
-    .ent getpeername
+#include <private/bionic_asm.h>
 
-getpeername:
+ENTRY(getpeername)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getpeername
+    .cpload t9
+    li v0, __NR_getpeername
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getpeername
+END(getpeername)
diff --git a/libc/arch-mips/syscalls/getpgid.S b/libc/arch-mips/syscalls/getpgid.S
index dc6ec96..562b9ce 100644
--- a/libc/arch-mips/syscalls/getpgid.S
+++ b/libc/arch-mips/syscalls/getpgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getpgid
-    .align 4
-    .ent getpgid
+#include <private/bionic_asm.h>
 
-getpgid:
+ENTRY(getpgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getpgid
+    .cpload t9
+    li v0, __NR_getpgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getpgid
+END(getpgid)
diff --git a/libc/arch-mips/syscalls/getpid.S b/libc/arch-mips/syscalls/getpid.S
deleted file mode 100644
index 244d256..0000000
--- a/libc/arch-mips/syscalls/getpid.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl getpid
-    .align 4
-    .ent getpid
-
-getpid:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_getpid
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end getpid
diff --git a/libc/arch-mips/syscalls/getppid.S b/libc/arch-mips/syscalls/getppid.S
index 1973424..afff0b9 100644
--- a/libc/arch-mips/syscalls/getppid.S
+++ b/libc/arch-mips/syscalls/getppid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getppid
-    .align 4
-    .ent getppid
+#include <private/bionic_asm.h>
 
-getppid:
+ENTRY(getppid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getppid
+    .cpload t9
+    li v0, __NR_getppid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getppid
+END(getppid)
diff --git a/libc/arch-mips/syscalls/getresgid.S b/libc/arch-mips/syscalls/getresgid.S
index b78e90c..248d3f9 100644
--- a/libc/arch-mips/syscalls/getresgid.S
+++ b/libc/arch-mips/syscalls/getresgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getresgid
-    .align 4
-    .ent getresgid
+#include <private/bionic_asm.h>
 
-getresgid:
+ENTRY(getresgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getresgid
+    .cpload t9
+    li v0, __NR_getresgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getresgid
+END(getresgid)
diff --git a/libc/arch-mips/syscalls/getresuid.S b/libc/arch-mips/syscalls/getresuid.S
index 336c049..924b6cd 100644
--- a/libc/arch-mips/syscalls/getresuid.S
+++ b/libc/arch-mips/syscalls/getresuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getresuid
-    .align 4
-    .ent getresuid
+#include <private/bionic_asm.h>
 
-getresuid:
+ENTRY(getresuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getresuid
+    .cpload t9
+    li v0, __NR_getresuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getresuid
+END(getresuid)
diff --git a/libc/arch-mips/syscalls/getrlimit.S b/libc/arch-mips/syscalls/getrlimit.S
index 557c2c1..19570d6 100644
--- a/libc/arch-mips/syscalls/getrlimit.S
+++ b/libc/arch-mips/syscalls/getrlimit.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getrlimit
-    .align 4
-    .ent getrlimit
+#include <private/bionic_asm.h>
 
-getrlimit:
+ENTRY(getrlimit)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getrlimit
+    .cpload t9
+    li v0, __NR_getrlimit
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getrlimit
+END(getrlimit)
diff --git a/libc/arch-mips/syscalls/getrusage.S b/libc/arch-mips/syscalls/getrusage.S
index c2750f9..75bc8bc 100644
--- a/libc/arch-mips/syscalls/getrusage.S
+++ b/libc/arch-mips/syscalls/getrusage.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getrusage
-    .align 4
-    .ent getrusage
+#include <private/bionic_asm.h>
 
-getrusage:
+ENTRY(getrusage)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getrusage
+    .cpload t9
+    li v0, __NR_getrusage
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getrusage
+END(getrusage)
diff --git a/libc/arch-mips/syscalls/getsid.S b/libc/arch-mips/syscalls/getsid.S
index 9ceb65d..6436ecd 100644
--- a/libc/arch-mips/syscalls/getsid.S
+++ b/libc/arch-mips/syscalls/getsid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getsid
-    .align 4
-    .ent getsid
+#include <private/bionic_asm.h>
 
-getsid:
+ENTRY(getsid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getsid
+    .cpload t9
+    li v0, __NR_getsid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getsid
+END(getsid)
diff --git a/libc/arch-mips/syscalls/getsockname.S b/libc/arch-mips/syscalls/getsockname.S
index 43b28c2..ffadd92 100644
--- a/libc/arch-mips/syscalls/getsockname.S
+++ b/libc/arch-mips/syscalls/getsockname.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getsockname
-    .align 4
-    .ent getsockname
+#include <private/bionic_asm.h>
 
-getsockname:
+ENTRY(getsockname)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getsockname
+    .cpload t9
+    li v0, __NR_getsockname
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getsockname
+END(getsockname)
diff --git a/libc/arch-mips/syscalls/getsockopt.S b/libc/arch-mips/syscalls/getsockopt.S
index affe539..6ebe15e 100644
--- a/libc/arch-mips/syscalls/getsockopt.S
+++ b/libc/arch-mips/syscalls/getsockopt.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getsockopt
-    .align 4
-    .ent getsockopt
+#include <private/bionic_asm.h>
 
-getsockopt:
+ENTRY(getsockopt)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getsockopt
+    .cpload t9
+    li v0, __NR_getsockopt
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getsockopt
+END(getsockopt)
diff --git a/libc/arch-mips/syscalls/gettid.S b/libc/arch-mips/syscalls/gettid.S
deleted file mode 100644
index d258ef2..0000000
--- a/libc/arch-mips/syscalls/gettid.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl gettid
-    .align 4
-    .ent gettid
-
-gettid:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_gettid
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end gettid
diff --git a/libc/arch-mips/syscalls/gettimeofday.S b/libc/arch-mips/syscalls/gettimeofday.S
index 006752e..672faa3 100644
--- a/libc/arch-mips/syscalls/gettimeofday.S
+++ b/libc/arch-mips/syscalls/gettimeofday.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl gettimeofday
-    .align 4
-    .ent gettimeofday
+#include <private/bionic_asm.h>
 
-gettimeofday:
+ENTRY(gettimeofday)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_gettimeofday
+    .cpload t9
+    li v0, __NR_gettimeofday
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end gettimeofday
+END(gettimeofday)
diff --git a/libc/arch-mips/syscalls/getuid.S b/libc/arch-mips/syscalls/getuid.S
index 747318a..5858632 100644
--- a/libc/arch-mips/syscalls/getuid.S
+++ b/libc/arch-mips/syscalls/getuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getuid
-    .align 4
-    .ent getuid
+#include <private/bionic_asm.h>
 
-getuid:
+ENTRY(getuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getuid
+    .cpload t9
+    li v0, __NR_getuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getuid
+END(getuid)
diff --git a/libc/arch-mips/syscalls/getxattr.S b/libc/arch-mips/syscalls/getxattr.S
index 2f82c4c..28c7fe6 100644
--- a/libc/arch-mips/syscalls/getxattr.S
+++ b/libc/arch-mips/syscalls/getxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getxattr
-    .align 4
-    .ent getxattr
+#include <private/bionic_asm.h>
 
-getxattr:
+ENTRY(getxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getxattr
+    .cpload t9
+    li v0, __NR_getxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end getxattr
+END(getxattr)
diff --git a/libc/arch-mips/syscalls/init_module.S b/libc/arch-mips/syscalls/init_module.S
index ee644b3..989614a 100644
--- a/libc/arch-mips/syscalls/init_module.S
+++ b/libc/arch-mips/syscalls/init_module.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl init_module
-    .align 4
-    .ent init_module
+#include <private/bionic_asm.h>
 
-init_module:
+ENTRY(init_module)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_init_module
+    .cpload t9
+    li v0, __NR_init_module
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end init_module
+END(init_module)
diff --git a/libc/arch-mips/syscalls/inotify_add_watch.S b/libc/arch-mips/syscalls/inotify_add_watch.S
index f1c4d92..7d3315f 100644
--- a/libc/arch-mips/syscalls/inotify_add_watch.S
+++ b/libc/arch-mips/syscalls/inotify_add_watch.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl inotify_add_watch
-    .align 4
-    .ent inotify_add_watch
+#include <private/bionic_asm.h>
 
-inotify_add_watch:
+ENTRY(inotify_add_watch)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_inotify_add_watch
+    .cpload t9
+    li v0, __NR_inotify_add_watch
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end inotify_add_watch
+END(inotify_add_watch)
diff --git a/libc/arch-mips/syscalls/inotify_init1.S b/libc/arch-mips/syscalls/inotify_init1.S
index c3fcf48..e4ec266 100644
--- a/libc/arch-mips/syscalls/inotify_init1.S
+++ b/libc/arch-mips/syscalls/inotify_init1.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl inotify_init1
-    .align 4
-    .ent inotify_init1
+#include <private/bionic_asm.h>
 
-inotify_init1:
+ENTRY(inotify_init1)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_inotify_init1
+    .cpload t9
+    li v0, __NR_inotify_init1
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end inotify_init1
+END(inotify_init1)
diff --git a/libc/arch-mips/syscalls/inotify_rm_watch.S b/libc/arch-mips/syscalls/inotify_rm_watch.S
index 13191af..eec9856 100644
--- a/libc/arch-mips/syscalls/inotify_rm_watch.S
+++ b/libc/arch-mips/syscalls/inotify_rm_watch.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl inotify_rm_watch
-    .align 4
-    .ent inotify_rm_watch
+#include <private/bionic_asm.h>
 
-inotify_rm_watch:
+ENTRY(inotify_rm_watch)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_inotify_rm_watch
+    .cpload t9
+    li v0, __NR_inotify_rm_watch
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end inotify_rm_watch
+END(inotify_rm_watch)
diff --git a/libc/arch-mips/syscalls/ioprio_get.S b/libc/arch-mips/syscalls/ioprio_get.S
deleted file mode 100644
index b8bd1d3..0000000
--- a/libc/arch-mips/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl ioprio_get
-    .align 4
-    .ent ioprio_get
-
-ioprio_get:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_ioprio_get
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end ioprio_get
diff --git a/libc/arch-mips/syscalls/ioprio_set.S b/libc/arch-mips/syscalls/ioprio_set.S
deleted file mode 100644
index c5b3bdc..0000000
--- a/libc/arch-mips/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl ioprio_set
-    .align 4
-    .ent ioprio_set
-
-ioprio_set:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_ioprio_set
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end ioprio_set
diff --git a/libc/arch-mips/syscalls/kill.S b/libc/arch-mips/syscalls/kill.S
index 20a484e..415da73 100644
--- a/libc/arch-mips/syscalls/kill.S
+++ b/libc/arch-mips/syscalls/kill.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl kill
-    .align 4
-    .ent kill
+#include <private/bionic_asm.h>
 
-kill:
+ENTRY(kill)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_kill
+    .cpload t9
+    li v0, __NR_kill
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end kill
+END(kill)
diff --git a/libc/arch-mips/syscalls/klogctl.S b/libc/arch-mips/syscalls/klogctl.S
index 5d30db2..123d8a0 100644
--- a/libc/arch-mips/syscalls/klogctl.S
+++ b/libc/arch-mips/syscalls/klogctl.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl klogctl
-    .align 4
-    .ent klogctl
+#include <private/bionic_asm.h>
 
-klogctl:
+ENTRY(klogctl)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_syslog
+    .cpload t9
+    li v0, __NR_syslog
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end klogctl
+END(klogctl)
diff --git a/libc/arch-mips/syscalls/lgetxattr.S b/libc/arch-mips/syscalls/lgetxattr.S
index 6266aaf..a9916d9 100644
--- a/libc/arch-mips/syscalls/lgetxattr.S
+++ b/libc/arch-mips/syscalls/lgetxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl lgetxattr
-    .align 4
-    .ent lgetxattr
+#include <private/bionic_asm.h>
 
-lgetxattr:
+ENTRY(lgetxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_lgetxattr
+    .cpload t9
+    li v0, __NR_lgetxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end lgetxattr
+END(lgetxattr)
diff --git a/libc/arch-mips/syscalls/linkat.S b/libc/arch-mips/syscalls/linkat.S
index dae07dd..a05a995 100644
--- a/libc/arch-mips/syscalls/linkat.S
+++ b/libc/arch-mips/syscalls/linkat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl linkat
-    .align 4
-    .ent linkat
+#include <private/bionic_asm.h>
 
-linkat:
+ENTRY(linkat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_linkat
+    .cpload t9
+    li v0, __NR_linkat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end linkat
+END(linkat)
diff --git a/libc/arch-mips/syscalls/listen.S b/libc/arch-mips/syscalls/listen.S
index f2e6083..7bb2ec8 100644
--- a/libc/arch-mips/syscalls/listen.S
+++ b/libc/arch-mips/syscalls/listen.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl listen
-    .align 4
-    .ent listen
+#include <private/bionic_asm.h>
 
-listen:
+ENTRY(listen)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_listen
+    .cpload t9
+    li v0, __NR_listen
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end listen
+END(listen)
diff --git a/libc/arch-mips/syscalls/listxattr.S b/libc/arch-mips/syscalls/listxattr.S
index e752340..c160178 100644
--- a/libc/arch-mips/syscalls/listxattr.S
+++ b/libc/arch-mips/syscalls/listxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl listxattr
-    .align 4
-    .ent listxattr
+#include <private/bionic_asm.h>
 
-listxattr:
+ENTRY(listxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_listxattr
+    .cpload t9
+    li v0, __NR_listxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end listxattr
+END(listxattr)
diff --git a/libc/arch-mips/syscalls/llistxattr.S b/libc/arch-mips/syscalls/llistxattr.S
index 9dc868e..9bf05b0 100644
--- a/libc/arch-mips/syscalls/llistxattr.S
+++ b/libc/arch-mips/syscalls/llistxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl llistxattr
-    .align 4
-    .ent llistxattr
+#include <private/bionic_asm.h>
 
-llistxattr:
+ENTRY(llistxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_llistxattr
+    .cpload t9
+    li v0, __NR_llistxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end llistxattr
+END(llistxattr)
diff --git a/libc/arch-mips/syscalls/lremovexattr.S b/libc/arch-mips/syscalls/lremovexattr.S
index d7e6609..fe73ddb 100644
--- a/libc/arch-mips/syscalls/lremovexattr.S
+++ b/libc/arch-mips/syscalls/lremovexattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl lremovexattr
-    .align 4
-    .ent lremovexattr
+#include <private/bionic_asm.h>
 
-lremovexattr:
+ENTRY(lremovexattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_lremovexattr
+    .cpload t9
+    li v0, __NR_lremovexattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end lremovexattr
+END(lremovexattr)
diff --git a/libc/arch-mips/syscalls/lseek.S b/libc/arch-mips/syscalls/lseek.S
index 269cc95..6d6b4e5 100644
--- a/libc/arch-mips/syscalls/lseek.S
+++ b/libc/arch-mips/syscalls/lseek.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl lseek
-    .align 4
-    .ent lseek
+#include <private/bionic_asm.h>
 
-lseek:
+ENTRY(lseek)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_lseek
+    .cpload t9
+    li v0, __NR_lseek
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end lseek
+END(lseek)
diff --git a/libc/arch-mips/syscalls/lsetxattr.S b/libc/arch-mips/syscalls/lsetxattr.S
index 2dfd24a..69ea0a2 100644
--- a/libc/arch-mips/syscalls/lsetxattr.S
+++ b/libc/arch-mips/syscalls/lsetxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl lsetxattr
-    .align 4
-    .ent lsetxattr
+#include <private/bionic_asm.h>
 
-lsetxattr:
+ENTRY(lsetxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_lsetxattr
+    .cpload t9
+    li v0, __NR_lsetxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end lsetxattr
+END(lsetxattr)
diff --git a/libc/arch-mips/syscalls/madvise.S b/libc/arch-mips/syscalls/madvise.S
index 8318272..7d67b80 100644
--- a/libc/arch-mips/syscalls/madvise.S
+++ b/libc/arch-mips/syscalls/madvise.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl madvise
-    .align 4
-    .ent madvise
+#include <private/bionic_asm.h>
 
-madvise:
+ENTRY(madvise)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_madvise
+    .cpload t9
+    li v0, __NR_madvise
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end madvise
+END(madvise)
diff --git a/libc/arch-mips/syscalls/mincore.S b/libc/arch-mips/syscalls/mincore.S
index 629a468..96f5e29 100644
--- a/libc/arch-mips/syscalls/mincore.S
+++ b/libc/arch-mips/syscalls/mincore.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mincore
-    .align 4
-    .ent mincore
+#include <private/bionic_asm.h>
 
-mincore:
+ENTRY(mincore)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mincore
+    .cpload t9
+    li v0, __NR_mincore
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end mincore
+END(mincore)
diff --git a/libc/arch-mips/syscalls/mkdirat.S b/libc/arch-mips/syscalls/mkdirat.S
index 3f8bc19..55dd976 100644
--- a/libc/arch-mips/syscalls/mkdirat.S
+++ b/libc/arch-mips/syscalls/mkdirat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mkdirat
-    .align 4
-    .ent mkdirat
+#include <private/bionic_asm.h>
 
-mkdirat:
+ENTRY(mkdirat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mkdirat
+    .cpload t9
+    li v0, __NR_mkdirat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end mkdirat
+END(mkdirat)
diff --git a/libc/arch-mips/syscalls/mknodat.S b/libc/arch-mips/syscalls/mknodat.S
index fc05bb3..1a03a8e 100644
--- a/libc/arch-mips/syscalls/mknodat.S
+++ b/libc/arch-mips/syscalls/mknodat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mknodat
-    .align 4
-    .ent mknodat
+#include <private/bionic_asm.h>
 
-mknodat:
+ENTRY(mknodat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mknodat
+    .cpload t9
+    li v0, __NR_mknodat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end mknodat
+END(mknodat)
diff --git a/libc/arch-mips/syscalls/mlock.S b/libc/arch-mips/syscalls/mlock.S
index 20cacda..3cf7c1b 100644
--- a/libc/arch-mips/syscalls/mlock.S
+++ b/libc/arch-mips/syscalls/mlock.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mlock
-    .align 4
-    .ent mlock
+#include <private/bionic_asm.h>
 
-mlock:
+ENTRY(mlock)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mlock
+    .cpload t9
+    li v0, __NR_mlock
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end mlock
+END(mlock)
diff --git a/libc/arch-mips/syscalls/mlockall.S b/libc/arch-mips/syscalls/mlockall.S
index 0aac087..3b90f41 100644
--- a/libc/arch-mips/syscalls/mlockall.S
+++ b/libc/arch-mips/syscalls/mlockall.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mlockall
-    .align 4
-    .ent mlockall
+#include <private/bionic_asm.h>
 
-mlockall:
+ENTRY(mlockall)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mlockall
+    .cpload t9
+    li v0, __NR_mlockall
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end mlockall
+END(mlockall)
diff --git a/libc/arch-mips/syscalls/mount.S b/libc/arch-mips/syscalls/mount.S
index 1f951ce..fdf299f 100644
--- a/libc/arch-mips/syscalls/mount.S
+++ b/libc/arch-mips/syscalls/mount.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mount
-    .align 4
-    .ent mount
+#include <private/bionic_asm.h>
 
-mount:
+ENTRY(mount)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mount
+    .cpload t9
+    li v0, __NR_mount
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end mount
+END(mount)
diff --git a/libc/arch-mips/syscalls/mprotect.S b/libc/arch-mips/syscalls/mprotect.S
index 7d9e784..5618310 100644
--- a/libc/arch-mips/syscalls/mprotect.S
+++ b/libc/arch-mips/syscalls/mprotect.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mprotect
-    .align 4
-    .ent mprotect
+#include <private/bionic_asm.h>
 
-mprotect:
+ENTRY(mprotect)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mprotect
+    .cpload t9
+    li v0, __NR_mprotect
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end mprotect
+END(mprotect)
diff --git a/libc/arch-mips/syscalls/mremap.S b/libc/arch-mips/syscalls/mremap.S
index 22ddda9..7cbb94e 100644
--- a/libc/arch-mips/syscalls/mremap.S
+++ b/libc/arch-mips/syscalls/mremap.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mremap
-    .align 4
-    .ent mremap
+#include <private/bionic_asm.h>
 
-mremap:
+ENTRY(mremap)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mremap
+    .cpload t9
+    li v0, __NR_mremap
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end mremap
+END(mremap)
diff --git a/libc/arch-mips/syscalls/msync.S b/libc/arch-mips/syscalls/msync.S
index 4969433..fb7462d 100644
--- a/libc/arch-mips/syscalls/msync.S
+++ b/libc/arch-mips/syscalls/msync.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl msync
-    .align 4
-    .ent msync
+#include <private/bionic_asm.h>
 
-msync:
+ENTRY(msync)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_msync
+    .cpload t9
+    li v0, __NR_msync
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end msync
+END(msync)
diff --git a/libc/arch-mips/syscalls/munlock.S b/libc/arch-mips/syscalls/munlock.S
index 59f1d44..6c65c02 100644
--- a/libc/arch-mips/syscalls/munlock.S
+++ b/libc/arch-mips/syscalls/munlock.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl munlock
-    .align 4
-    .ent munlock
+#include <private/bionic_asm.h>
 
-munlock:
+ENTRY(munlock)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_munlock
+    .cpload t9
+    li v0, __NR_munlock
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end munlock
+END(munlock)
diff --git a/libc/arch-mips/syscalls/munlockall.S b/libc/arch-mips/syscalls/munlockall.S
index d0a8e9f..e30dddc 100644
--- a/libc/arch-mips/syscalls/munlockall.S
+++ b/libc/arch-mips/syscalls/munlockall.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl munlockall
-    .align 4
-    .ent munlockall
+#include <private/bionic_asm.h>
 
-munlockall:
+ENTRY(munlockall)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_munlockall
+    .cpload t9
+    li v0, __NR_munlockall
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end munlockall
+END(munlockall)
diff --git a/libc/arch-mips/syscalls/munmap.S b/libc/arch-mips/syscalls/munmap.S
index d4c1057..903edde 100644
--- a/libc/arch-mips/syscalls/munmap.S
+++ b/libc/arch-mips/syscalls/munmap.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl munmap
-    .align 4
-    .ent munmap
+#include <private/bionic_asm.h>
 
-munmap:
+ENTRY(munmap)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_munmap
+    .cpload t9
+    li v0, __NR_munmap
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end munmap
+END(munmap)
diff --git a/libc/arch-mips/syscalls/nanosleep.S b/libc/arch-mips/syscalls/nanosleep.S
index ad3b0f9..8dae88b 100644
--- a/libc/arch-mips/syscalls/nanosleep.S
+++ b/libc/arch-mips/syscalls/nanosleep.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl nanosleep
-    .align 4
-    .ent nanosleep
+#include <private/bionic_asm.h>
 
-nanosleep:
+ENTRY(nanosleep)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_nanosleep
+    .cpload t9
+    li v0, __NR_nanosleep
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end nanosleep
+END(nanosleep)
diff --git a/libc/arch-mips/syscalls/perf_event_open.S b/libc/arch-mips/syscalls/perf_event_open.S
deleted file mode 100644
index edd8b85..0000000
--- a/libc/arch-mips/syscalls/perf_event_open.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl perf_event_open
-    .align 4
-    .ent perf_event_open
-
-perf_event_open:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_perf_event_open
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end perf_event_open
diff --git a/libc/arch-mips/syscalls/personality.S b/libc/arch-mips/syscalls/personality.S
index 59aaeac..2f51d39 100644
--- a/libc/arch-mips/syscalls/personality.S
+++ b/libc/arch-mips/syscalls/personality.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl personality
-    .align 4
-    .ent personality
+#include <private/bionic_asm.h>
 
-personality:
+ENTRY(personality)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_personality
+    .cpload t9
+    li v0, __NR_personality
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end personality
+END(personality)
diff --git a/libc/arch-mips/syscalls/pipe2.S b/libc/arch-mips/syscalls/pipe2.S
index 798bd7b..b06309c 100644
--- a/libc/arch-mips/syscalls/pipe2.S
+++ b/libc/arch-mips/syscalls/pipe2.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl pipe2
-    .align 4
-    .ent pipe2
+#include <private/bionic_asm.h>
 
-pipe2:
+ENTRY(pipe2)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_pipe2
+    .cpload t9
+    li v0, __NR_pipe2
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end pipe2
+END(pipe2)
diff --git a/libc/arch-mips/syscalls/prctl.S b/libc/arch-mips/syscalls/prctl.S
index 5e9a28d..71544ee 100644
--- a/libc/arch-mips/syscalls/prctl.S
+++ b/libc/arch-mips/syscalls/prctl.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl prctl
-    .align 4
-    .ent prctl
+#include <private/bionic_asm.h>
 
-prctl:
+ENTRY(prctl)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_prctl
+    .cpload t9
+    li v0, __NR_prctl
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end prctl
+END(prctl)
diff --git a/libc/arch-mips/syscalls/pread64.S b/libc/arch-mips/syscalls/pread64.S
index 870b138..9e7248b 100644
--- a/libc/arch-mips/syscalls/pread64.S
+++ b/libc/arch-mips/syscalls/pread64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl pread64
-    .align 4
-    .ent pread64
+#include <private/bionic_asm.h>
 
-pread64:
+ENTRY(pread64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_pread64
+    .cpload t9
+    li v0, __NR_pread64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end pread64
+END(pread64)
diff --git a/libc/arch-mips/syscalls/prlimit64.S b/libc/arch-mips/syscalls/prlimit64.S
index 17e9157..ca913df 100644
--- a/libc/arch-mips/syscalls/prlimit64.S
+++ b/libc/arch-mips/syscalls/prlimit64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl prlimit64
-    .align 4
-    .ent prlimit64
+#include <private/bionic_asm.h>
 
-prlimit64:
+ENTRY(prlimit64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_prlimit64
+    .cpload t9
+    li v0, __NR_prlimit64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end prlimit64
+END(prlimit64)
diff --git a/libc/arch-mips/syscalls/pwrite64.S b/libc/arch-mips/syscalls/pwrite64.S
index 1e808ff..ac206aa 100644
--- a/libc/arch-mips/syscalls/pwrite64.S
+++ b/libc/arch-mips/syscalls/pwrite64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl pwrite64
-    .align 4
-    .ent pwrite64
+#include <private/bionic_asm.h>
 
-pwrite64:
+ENTRY(pwrite64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_pwrite64
+    .cpload t9
+    li v0, __NR_pwrite64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end pwrite64
+END(pwrite64)
diff --git a/libc/arch-mips/syscalls/read.S b/libc/arch-mips/syscalls/read.S
index c649837..1355b66 100644
--- a/libc/arch-mips/syscalls/read.S
+++ b/libc/arch-mips/syscalls/read.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl read
-    .align 4
-    .ent read
+#include <private/bionic_asm.h>
 
-read:
+ENTRY(read)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_read
+    .cpload t9
+    li v0, __NR_read
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end read
+END(read)
diff --git a/libc/arch-mips/syscalls/readahead.S b/libc/arch-mips/syscalls/readahead.S
index 09eab9e..b28df08 100644
--- a/libc/arch-mips/syscalls/readahead.S
+++ b/libc/arch-mips/syscalls/readahead.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl readahead
-    .align 4
-    .ent readahead
+#include <private/bionic_asm.h>
 
-readahead:
+ENTRY(readahead)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_readahead
+    .cpload t9
+    li v0, __NR_readahead
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end readahead
+END(readahead)
diff --git a/libc/arch-mips/syscalls/readlinkat.S b/libc/arch-mips/syscalls/readlinkat.S
index 3e5d72f..5cf84a2 100644
--- a/libc/arch-mips/syscalls/readlinkat.S
+++ b/libc/arch-mips/syscalls/readlinkat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl readlinkat
-    .align 4
-    .ent readlinkat
+#include <private/bionic_asm.h>
 
-readlinkat:
+ENTRY(readlinkat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_readlinkat
+    .cpload t9
+    li v0, __NR_readlinkat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end readlinkat
+END(readlinkat)
diff --git a/libc/arch-mips/syscalls/readv.S b/libc/arch-mips/syscalls/readv.S
index 1f367be..57952a0 100644
--- a/libc/arch-mips/syscalls/readv.S
+++ b/libc/arch-mips/syscalls/readv.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl readv
-    .align 4
-    .ent readv
+#include <private/bionic_asm.h>
 
-readv:
+ENTRY(readv)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_readv
+    .cpload t9
+    li v0, __NR_readv
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end readv
+END(readv)
diff --git a/libc/arch-mips/syscalls/recvfrom.S b/libc/arch-mips/syscalls/recvfrom.S
index 3c2303c..707ba4b 100644
--- a/libc/arch-mips/syscalls/recvfrom.S
+++ b/libc/arch-mips/syscalls/recvfrom.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl recvfrom
-    .align 4
-    .ent recvfrom
+#include <private/bionic_asm.h>
 
-recvfrom:
+ENTRY(recvfrom)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_recvfrom
+    .cpload t9
+    li v0, __NR_recvfrom
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end recvfrom
+END(recvfrom)
diff --git a/libc/arch-mips/syscalls/recvmmsg.S b/libc/arch-mips/syscalls/recvmmsg.S
new file mode 100644
index 0000000..796d0d8
--- /dev/null
+++ b/libc/arch-mips/syscalls/recvmmsg.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(recvmmsg)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_recvmmsg
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(recvmmsg)
diff --git a/libc/arch-mips/syscalls/recvmsg.S b/libc/arch-mips/syscalls/recvmsg.S
index aaf022f..fdcac32 100644
--- a/libc/arch-mips/syscalls/recvmsg.S
+++ b/libc/arch-mips/syscalls/recvmsg.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl recvmsg
-    .align 4
-    .ent recvmsg
+#include <private/bionic_asm.h>
 
-recvmsg:
+ENTRY(recvmsg)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_recvmsg
+    .cpload t9
+    li v0, __NR_recvmsg
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end recvmsg
+END(recvmsg)
diff --git a/libc/arch-mips/syscalls/removexattr.S b/libc/arch-mips/syscalls/removexattr.S
index 29df5d2..d99e1ae 100644
--- a/libc/arch-mips/syscalls/removexattr.S
+++ b/libc/arch-mips/syscalls/removexattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl removexattr
-    .align 4
-    .ent removexattr
+#include <private/bionic_asm.h>
 
-removexattr:
+ENTRY(removexattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_removexattr
+    .cpload t9
+    li v0, __NR_removexattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end removexattr
+END(removexattr)
diff --git a/libc/arch-mips/syscalls/renameat.S b/libc/arch-mips/syscalls/renameat.S
index b7c210e..c865d74 100644
--- a/libc/arch-mips/syscalls/renameat.S
+++ b/libc/arch-mips/syscalls/renameat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl renameat
-    .align 4
-    .ent renameat
+#include <private/bionic_asm.h>
 
-renameat:
+ENTRY(renameat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_renameat
+    .cpload t9
+    li v0, __NR_renameat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end renameat
+END(renameat)
diff --git a/libc/arch-mips/syscalls/sched_get_priority_max.S b/libc/arch-mips/syscalls/sched_get_priority_max.S
index 6d63fec..1c73af6 100644
--- a/libc/arch-mips/syscalls/sched_get_priority_max.S
+++ b/libc/arch-mips/syscalls/sched_get_priority_max.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_get_priority_max
-    .align 4
-    .ent sched_get_priority_max
+#include <private/bionic_asm.h>
 
-sched_get_priority_max:
+ENTRY(sched_get_priority_max)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_get_priority_max
+    .cpload t9
+    li v0, __NR_sched_get_priority_max
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_get_priority_max
+END(sched_get_priority_max)
diff --git a/libc/arch-mips/syscalls/sched_get_priority_min.S b/libc/arch-mips/syscalls/sched_get_priority_min.S
index de88b3e..b69b72b 100644
--- a/libc/arch-mips/syscalls/sched_get_priority_min.S
+++ b/libc/arch-mips/syscalls/sched_get_priority_min.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_get_priority_min
-    .align 4
-    .ent sched_get_priority_min
+#include <private/bionic_asm.h>
 
-sched_get_priority_min:
+ENTRY(sched_get_priority_min)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_get_priority_min
+    .cpload t9
+    li v0, __NR_sched_get_priority_min
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_get_priority_min
+END(sched_get_priority_min)
diff --git a/libc/arch-mips/syscalls/sched_getparam.S b/libc/arch-mips/syscalls/sched_getparam.S
index ae261db..387257a 100644
--- a/libc/arch-mips/syscalls/sched_getparam.S
+++ b/libc/arch-mips/syscalls/sched_getparam.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_getparam
-    .align 4
-    .ent sched_getparam
+#include <private/bionic_asm.h>
 
-sched_getparam:
+ENTRY(sched_getparam)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_getparam
+    .cpload t9
+    li v0, __NR_sched_getparam
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_getparam
+END(sched_getparam)
diff --git a/libc/arch-mips/syscalls/sched_getscheduler.S b/libc/arch-mips/syscalls/sched_getscheduler.S
index 6a4e6f6..9b293db 100644
--- a/libc/arch-mips/syscalls/sched_getscheduler.S
+++ b/libc/arch-mips/syscalls/sched_getscheduler.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_getscheduler
-    .align 4
-    .ent sched_getscheduler
+#include <private/bionic_asm.h>
 
-sched_getscheduler:
+ENTRY(sched_getscheduler)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_getscheduler
+    .cpload t9
+    li v0, __NR_sched_getscheduler
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_getscheduler
+END(sched_getscheduler)
diff --git a/libc/arch-mips/syscalls/sched_rr_get_interval.S b/libc/arch-mips/syscalls/sched_rr_get_interval.S
index 436f8b3..3d7b8a8 100644
--- a/libc/arch-mips/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-mips/syscalls/sched_rr_get_interval.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_rr_get_interval
-    .align 4
-    .ent sched_rr_get_interval
+#include <private/bionic_asm.h>
 
-sched_rr_get_interval:
+ENTRY(sched_rr_get_interval)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_rr_get_interval
+    .cpload t9
+    li v0, __NR_sched_rr_get_interval
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_rr_get_interval
+END(sched_rr_get_interval)
diff --git a/libc/arch-mips/syscalls/sched_setaffinity.S b/libc/arch-mips/syscalls/sched_setaffinity.S
index 98bf458..a0e9f6c 100644
--- a/libc/arch-mips/syscalls/sched_setaffinity.S
+++ b/libc/arch-mips/syscalls/sched_setaffinity.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_setaffinity
-    .align 4
-    .ent sched_setaffinity
+#include <private/bionic_asm.h>
 
-sched_setaffinity:
+ENTRY(sched_setaffinity)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_setaffinity
+    .cpload t9
+    li v0, __NR_sched_setaffinity
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_setaffinity
+END(sched_setaffinity)
diff --git a/libc/arch-mips/syscalls/sched_setparam.S b/libc/arch-mips/syscalls/sched_setparam.S
index 2c03e93..a8a8982 100644
--- a/libc/arch-mips/syscalls/sched_setparam.S
+++ b/libc/arch-mips/syscalls/sched_setparam.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_setparam
-    .align 4
-    .ent sched_setparam
+#include <private/bionic_asm.h>
 
-sched_setparam:
+ENTRY(sched_setparam)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_setparam
+    .cpload t9
+    li v0, __NR_sched_setparam
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_setparam
+END(sched_setparam)
diff --git a/libc/arch-mips/syscalls/sched_setscheduler.S b/libc/arch-mips/syscalls/sched_setscheduler.S
index adb1f14..a2cd7fa 100644
--- a/libc/arch-mips/syscalls/sched_setscheduler.S
+++ b/libc/arch-mips/syscalls/sched_setscheduler.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_setscheduler
-    .align 4
-    .ent sched_setscheduler
+#include <private/bionic_asm.h>
 
-sched_setscheduler:
+ENTRY(sched_setscheduler)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_setscheduler
+    .cpload t9
+    li v0, __NR_sched_setscheduler
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_setscheduler
+END(sched_setscheduler)
diff --git a/libc/arch-mips/syscalls/sched_yield.S b/libc/arch-mips/syscalls/sched_yield.S
index cbe799c..295266f 100644
--- a/libc/arch-mips/syscalls/sched_yield.S
+++ b/libc/arch-mips/syscalls/sched_yield.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_yield
-    .align 4
-    .ent sched_yield
+#include <private/bionic_asm.h>
 
-sched_yield:
+ENTRY(sched_yield)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_yield
+    .cpload t9
+    li v0, __NR_sched_yield
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sched_yield
+END(sched_yield)
diff --git a/libc/arch-mips/syscalls/sendfile.S b/libc/arch-mips/syscalls/sendfile.S
index 219a311..5e5e887 100644
--- a/libc/arch-mips/syscalls/sendfile.S
+++ b/libc/arch-mips/syscalls/sendfile.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sendfile
-    .align 4
-    .ent sendfile
+#include <private/bionic_asm.h>
 
-sendfile:
+ENTRY(sendfile)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sendfile
+    .cpload t9
+    li v0, __NR_sendfile
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sendfile
+END(sendfile)
diff --git a/libc/arch-mips/syscalls/sendfile64.S b/libc/arch-mips/syscalls/sendfile64.S
index 7669973..78f1908 100644
--- a/libc/arch-mips/syscalls/sendfile64.S
+++ b/libc/arch-mips/syscalls/sendfile64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sendfile64
-    .align 4
-    .ent sendfile64
+#include <private/bionic_asm.h>
 
-sendfile64:
+ENTRY(sendfile64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sendfile64
+    .cpload t9
+    li v0, __NR_sendfile64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sendfile64
+END(sendfile64)
diff --git a/libc/arch-mips/syscalls/sendmmsg.S b/libc/arch-mips/syscalls/sendmmsg.S
new file mode 100644
index 0000000..1dc7576
--- /dev/null
+++ b/libc/arch-mips/syscalls/sendmmsg.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendmmsg)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_sendmmsg
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(sendmmsg)
diff --git a/libc/arch-mips/syscalls/sendmsg.S b/libc/arch-mips/syscalls/sendmsg.S
index faa4cf3..88c653e 100644
--- a/libc/arch-mips/syscalls/sendmsg.S
+++ b/libc/arch-mips/syscalls/sendmsg.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sendmsg
-    .align 4
-    .ent sendmsg
+#include <private/bionic_asm.h>
 
-sendmsg:
+ENTRY(sendmsg)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sendmsg
+    .cpload t9
+    li v0, __NR_sendmsg
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sendmsg
+END(sendmsg)
diff --git a/libc/arch-mips/syscalls/sendto.S b/libc/arch-mips/syscalls/sendto.S
index 80a6110..ef3fa9f 100644
--- a/libc/arch-mips/syscalls/sendto.S
+++ b/libc/arch-mips/syscalls/sendto.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sendto
-    .align 4
-    .ent sendto
+#include <private/bionic_asm.h>
 
-sendto:
+ENTRY(sendto)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sendto
+    .cpload t9
+    li v0, __NR_sendto
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sendto
+END(sendto)
diff --git a/libc/arch-mips/syscalls/setfsgid.S b/libc/arch-mips/syscalls/setfsgid.S
new file mode 100644
index 0000000..158d2c0
--- /dev/null
+++ b/libc/arch-mips/syscalls/setfsgid.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsgid)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_setfsgid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(setfsgid)
diff --git a/libc/arch-mips/syscalls/setfsuid.S b/libc/arch-mips/syscalls/setfsuid.S
new file mode 100644
index 0000000..f76fd17
--- /dev/null
+++ b/libc/arch-mips/syscalls/setfsuid.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsuid)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_setfsuid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(setfsuid)
diff --git a/libc/arch-mips/syscalls/setgid.S b/libc/arch-mips/syscalls/setgid.S
index 7e460b8..44127cd 100644
--- a/libc/arch-mips/syscalls/setgid.S
+++ b/libc/arch-mips/syscalls/setgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setgid
-    .align 4
-    .ent setgid
+#include <private/bionic_asm.h>
 
-setgid:
+ENTRY(setgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setgid
+    .cpload t9
+    li v0, __NR_setgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setgid
+END(setgid)
diff --git a/libc/arch-mips/syscalls/setgroups.S b/libc/arch-mips/syscalls/setgroups.S
index f89a4a4..be4dc13 100644
--- a/libc/arch-mips/syscalls/setgroups.S
+++ b/libc/arch-mips/syscalls/setgroups.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setgroups
-    .align 4
-    .ent setgroups
+#include <private/bionic_asm.h>
 
-setgroups:
+ENTRY(setgroups)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setgroups
+    .cpload t9
+    li v0, __NR_setgroups
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setgroups
+END(setgroups)
diff --git a/libc/arch-mips/syscalls/setitimer.S b/libc/arch-mips/syscalls/setitimer.S
index 5a1850a..968b453 100644
--- a/libc/arch-mips/syscalls/setitimer.S
+++ b/libc/arch-mips/syscalls/setitimer.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setitimer
-    .align 4
-    .ent setitimer
+#include <private/bionic_asm.h>
 
-setitimer:
+ENTRY(setitimer)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setitimer
+    .cpload t9
+    li v0, __NR_setitimer
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setitimer
+END(setitimer)
diff --git a/libc/arch-mips/syscalls/setns.S b/libc/arch-mips/syscalls/setns.S
index fd4529e..a9270ec 100644
--- a/libc/arch-mips/syscalls/setns.S
+++ b/libc/arch-mips/syscalls/setns.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setns
-    .align 4
-    .ent setns
+#include <private/bionic_asm.h>
 
-setns:
+ENTRY(setns)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setns
+    .cpload t9
+    li v0, __NR_setns
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setns
+END(setns)
diff --git a/libc/arch-mips/syscalls/setpgid.S b/libc/arch-mips/syscalls/setpgid.S
index d41e01c..d2db62f 100644
--- a/libc/arch-mips/syscalls/setpgid.S
+++ b/libc/arch-mips/syscalls/setpgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setpgid
-    .align 4
-    .ent setpgid
+#include <private/bionic_asm.h>
 
-setpgid:
+ENTRY(setpgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setpgid
+    .cpload t9
+    li v0, __NR_setpgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setpgid
+END(setpgid)
diff --git a/libc/arch-mips/syscalls/setpriority.S b/libc/arch-mips/syscalls/setpriority.S
index 443d017..9b68335 100644
--- a/libc/arch-mips/syscalls/setpriority.S
+++ b/libc/arch-mips/syscalls/setpriority.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setpriority
-    .align 4
-    .ent setpriority
+#include <private/bionic_asm.h>
 
-setpriority:
+ENTRY(setpriority)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setpriority
+    .cpload t9
+    li v0, __NR_setpriority
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setpriority
+END(setpriority)
diff --git a/libc/arch-mips/syscalls/setregid.S b/libc/arch-mips/syscalls/setregid.S
index a91e21b..6b7474c 100644
--- a/libc/arch-mips/syscalls/setregid.S
+++ b/libc/arch-mips/syscalls/setregid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setregid
-    .align 4
-    .ent setregid
+#include <private/bionic_asm.h>
 
-setregid:
+ENTRY(setregid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setregid
+    .cpload t9
+    li v0, __NR_setregid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setregid
+END(setregid)
diff --git a/libc/arch-mips/syscalls/setresgid.S b/libc/arch-mips/syscalls/setresgid.S
index dd8a330..223a0d0 100644
--- a/libc/arch-mips/syscalls/setresgid.S
+++ b/libc/arch-mips/syscalls/setresgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setresgid
-    .align 4
-    .ent setresgid
+#include <private/bionic_asm.h>
 
-setresgid:
+ENTRY(setresgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setresgid
+    .cpload t9
+    li v0, __NR_setresgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setresgid
+END(setresgid)
diff --git a/libc/arch-mips/syscalls/setresuid.S b/libc/arch-mips/syscalls/setresuid.S
index 1319e2c..1f99682 100644
--- a/libc/arch-mips/syscalls/setresuid.S
+++ b/libc/arch-mips/syscalls/setresuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setresuid
-    .align 4
-    .ent setresuid
+#include <private/bionic_asm.h>
 
-setresuid:
+ENTRY(setresuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setresuid
+    .cpload t9
+    li v0, __NR_setresuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setresuid
+END(setresuid)
diff --git a/libc/arch-mips/syscalls/setreuid.S b/libc/arch-mips/syscalls/setreuid.S
index e25f2d9..fa9c3d2 100644
--- a/libc/arch-mips/syscalls/setreuid.S
+++ b/libc/arch-mips/syscalls/setreuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setreuid
-    .align 4
-    .ent setreuid
+#include <private/bionic_asm.h>
 
-setreuid:
+ENTRY(setreuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setreuid
+    .cpload t9
+    li v0, __NR_setreuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setreuid
+END(setreuid)
diff --git a/libc/arch-mips/syscalls/setrlimit.S b/libc/arch-mips/syscalls/setrlimit.S
index 65b1cd8..016e24c 100644
--- a/libc/arch-mips/syscalls/setrlimit.S
+++ b/libc/arch-mips/syscalls/setrlimit.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setrlimit
-    .align 4
-    .ent setrlimit
+#include <private/bionic_asm.h>
 
-setrlimit:
+ENTRY(setrlimit)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setrlimit
+    .cpload t9
+    li v0, __NR_setrlimit
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setrlimit
+END(setrlimit)
diff --git a/libc/arch-mips/syscalls/setsid.S b/libc/arch-mips/syscalls/setsid.S
index a0bad2b..9f3cb48 100644
--- a/libc/arch-mips/syscalls/setsid.S
+++ b/libc/arch-mips/syscalls/setsid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setsid
-    .align 4
-    .ent setsid
+#include <private/bionic_asm.h>
 
-setsid:
+ENTRY(setsid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setsid
+    .cpload t9
+    li v0, __NR_setsid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setsid
+END(setsid)
diff --git a/libc/arch-mips/syscalls/setsockopt.S b/libc/arch-mips/syscalls/setsockopt.S
index 3192d93..b2368a1 100644
--- a/libc/arch-mips/syscalls/setsockopt.S
+++ b/libc/arch-mips/syscalls/setsockopt.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setsockopt
-    .align 4
-    .ent setsockopt
+#include <private/bionic_asm.h>
 
-setsockopt:
+ENTRY(setsockopt)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setsockopt
+    .cpload t9
+    li v0, __NR_setsockopt
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setsockopt
+END(setsockopt)
diff --git a/libc/arch-mips/syscalls/settimeofday.S b/libc/arch-mips/syscalls/settimeofday.S
index 673b7fd..e3a5a06 100644
--- a/libc/arch-mips/syscalls/settimeofday.S
+++ b/libc/arch-mips/syscalls/settimeofday.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl settimeofday
-    .align 4
-    .ent settimeofday
+#include <private/bionic_asm.h>
 
-settimeofday:
+ENTRY(settimeofday)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_settimeofday
+    .cpload t9
+    li v0, __NR_settimeofday
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end settimeofday
+END(settimeofday)
diff --git a/libc/arch-mips/syscalls/setuid.S b/libc/arch-mips/syscalls/setuid.S
index abfdafb..ff3da0a 100644
--- a/libc/arch-mips/syscalls/setuid.S
+++ b/libc/arch-mips/syscalls/setuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setuid
-    .align 4
-    .ent setuid
+#include <private/bionic_asm.h>
 
-setuid:
+ENTRY(setuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setuid
+    .cpload t9
+    li v0, __NR_setuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setuid
+END(setuid)
diff --git a/libc/arch-mips/syscalls/setxattr.S b/libc/arch-mips/syscalls/setxattr.S
index b9c1aaa..5b3a241 100644
--- a/libc/arch-mips/syscalls/setxattr.S
+++ b/libc/arch-mips/syscalls/setxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setxattr
-    .align 4
-    .ent setxattr
+#include <private/bionic_asm.h>
 
-setxattr:
+ENTRY(setxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setxattr
+    .cpload t9
+    li v0, __NR_setxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end setxattr
+END(setxattr)
diff --git a/libc/arch-mips/syscalls/shutdown.S b/libc/arch-mips/syscalls/shutdown.S
index 0f2208f..5db046f 100644
--- a/libc/arch-mips/syscalls/shutdown.S
+++ b/libc/arch-mips/syscalls/shutdown.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl shutdown
-    .align 4
-    .ent shutdown
+#include <private/bionic_asm.h>
 
-shutdown:
+ENTRY(shutdown)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_shutdown
+    .cpload t9
+    li v0, __NR_shutdown
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end shutdown
+END(shutdown)
diff --git a/libc/arch-mips/syscalls/sigaltstack.S b/libc/arch-mips/syscalls/sigaltstack.S
index ec1d8a1..f543759 100644
--- a/libc/arch-mips/syscalls/sigaltstack.S
+++ b/libc/arch-mips/syscalls/sigaltstack.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sigaltstack
-    .align 4
-    .ent sigaltstack
+#include <private/bionic_asm.h>
 
-sigaltstack:
+ENTRY(sigaltstack)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sigaltstack
+    .cpload t9
+    li v0, __NR_sigaltstack
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sigaltstack
+END(sigaltstack)
diff --git a/libc/arch-mips/syscalls/signalfd4.S b/libc/arch-mips/syscalls/signalfd4.S
deleted file mode 100644
index 74e6168..0000000
--- a/libc/arch-mips/syscalls/signalfd4.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl signalfd4
-    .align 4
-    .ent signalfd4
-
-signalfd4:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_signalfd4
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end signalfd4
diff --git a/libc/arch-mips/syscalls/socket.S b/libc/arch-mips/syscalls/socket.S
deleted file mode 100644
index c67404e..0000000
--- a/libc/arch-mips/syscalls/socket.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl socket
-    .align 4
-    .ent socket
-
-socket:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_socket
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end socket
diff --git a/libc/arch-mips/syscalls/socketpair.S b/libc/arch-mips/syscalls/socketpair.S
index c0f41e2..7f85da3 100644
--- a/libc/arch-mips/syscalls/socketpair.S
+++ b/libc/arch-mips/syscalls/socketpair.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl socketpair
-    .align 4
-    .ent socketpair
+#include <private/bionic_asm.h>
 
-socketpair:
+ENTRY(socketpair)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_socketpair
+    .cpload t9
+    li v0, __NR_socketpair
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end socketpair
+END(socketpair)
diff --git a/libc/arch-mips/syscalls/splice.S b/libc/arch-mips/syscalls/splice.S
new file mode 100644
index 0000000..a55b7e8
--- /dev/null
+++ b/libc/arch-mips/syscalls/splice.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_splice
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(splice)
diff --git a/libc/arch-mips/syscalls/swapoff.S b/libc/arch-mips/syscalls/swapoff.S
index 1ed5083..ce782d0 100644
--- a/libc/arch-mips/syscalls/swapoff.S
+++ b/libc/arch-mips/syscalls/swapoff.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl swapoff
-    .align 4
-    .ent swapoff
+#include <private/bionic_asm.h>
 
-swapoff:
+ENTRY(swapoff)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_swapoff
+    .cpload t9
+    li v0, __NR_swapoff
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end swapoff
+END(swapoff)
diff --git a/libc/arch-mips/syscalls/swapon.S b/libc/arch-mips/syscalls/swapon.S
index 08a85b0..127c3a8 100644
--- a/libc/arch-mips/syscalls/swapon.S
+++ b/libc/arch-mips/syscalls/swapon.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl swapon
-    .align 4
-    .ent swapon
+#include <private/bionic_asm.h>
 
-swapon:
+ENTRY(swapon)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_swapon
+    .cpload t9
+    li v0, __NR_swapon
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end swapon
+END(swapon)
diff --git a/libc/arch-mips/syscalls/symlinkat.S b/libc/arch-mips/syscalls/symlinkat.S
index 9c43241..b0690a4 100644
--- a/libc/arch-mips/syscalls/symlinkat.S
+++ b/libc/arch-mips/syscalls/symlinkat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl symlinkat
-    .align 4
-    .ent symlinkat
+#include <private/bionic_asm.h>
 
-symlinkat:
+ENTRY(symlinkat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_symlinkat
+    .cpload t9
+    li v0, __NR_symlinkat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end symlinkat
+END(symlinkat)
diff --git a/libc/arch-mips/syscalls/sync.S b/libc/arch-mips/syscalls/sync.S
index 0e0ee1f..8858e74 100644
--- a/libc/arch-mips/syscalls/sync.S
+++ b/libc/arch-mips/syscalls/sync.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sync
-    .align 4
-    .ent sync
+#include <private/bionic_asm.h>
 
-sync:
+ENTRY(sync)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sync
+    .cpload t9
+    li v0, __NR_sync
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sync
+END(sync)
diff --git a/libc/arch-mips/syscalls/sysinfo.S b/libc/arch-mips/syscalls/sysinfo.S
index 3acfbf7..beefc0e 100644
--- a/libc/arch-mips/syscalls/sysinfo.S
+++ b/libc/arch-mips/syscalls/sysinfo.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sysinfo
-    .align 4
-    .ent sysinfo
+#include <private/bionic_asm.h>
 
-sysinfo:
+ENTRY(sysinfo)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sysinfo
+    .cpload t9
+    li v0, __NR_sysinfo
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end sysinfo
+END(sysinfo)
diff --git a/libc/arch-mips/syscalls/tee.S b/libc/arch-mips/syscalls/tee.S
new file mode 100644
index 0000000..1115907
--- /dev/null
+++ b/libc/arch-mips/syscalls/tee.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(tee)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_tee
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(tee)
diff --git a/libc/arch-mips/syscalls/tgkill.S b/libc/arch-mips/syscalls/tgkill.S
index 5de33d0..bea211d 100644
--- a/libc/arch-mips/syscalls/tgkill.S
+++ b/libc/arch-mips/syscalls/tgkill.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl tgkill
-    .align 4
-    .ent tgkill
+#include <private/bionic_asm.h>
 
-tgkill:
+ENTRY(tgkill)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_tgkill
+    .cpload t9
+    li v0, __NR_tgkill
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end tgkill
+END(tgkill)
diff --git a/libc/arch-mips/syscalls/timerfd_create.S b/libc/arch-mips/syscalls/timerfd_create.S
index 2528355..116c628 100644
--- a/libc/arch-mips/syscalls/timerfd_create.S
+++ b/libc/arch-mips/syscalls/timerfd_create.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl timerfd_create
-    .align 4
-    .ent timerfd_create
+#include <private/bionic_asm.h>
 
-timerfd_create:
+ENTRY(timerfd_create)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timerfd_create
+    .cpload t9
+    li v0, __NR_timerfd_create
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end timerfd_create
+END(timerfd_create)
diff --git a/libc/arch-mips/syscalls/timerfd_gettime.S b/libc/arch-mips/syscalls/timerfd_gettime.S
index b38c2d4..df7138c 100644
--- a/libc/arch-mips/syscalls/timerfd_gettime.S
+++ b/libc/arch-mips/syscalls/timerfd_gettime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl timerfd_gettime
-    .align 4
-    .ent timerfd_gettime
+#include <private/bionic_asm.h>
 
-timerfd_gettime:
+ENTRY(timerfd_gettime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timerfd_gettime
+    .cpload t9
+    li v0, __NR_timerfd_gettime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end timerfd_gettime
+END(timerfd_gettime)
diff --git a/libc/arch-mips/syscalls/timerfd_settime.S b/libc/arch-mips/syscalls/timerfd_settime.S
index 11dc61b..2bfadb9 100644
--- a/libc/arch-mips/syscalls/timerfd_settime.S
+++ b/libc/arch-mips/syscalls/timerfd_settime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl timerfd_settime
-    .align 4
-    .ent timerfd_settime
+#include <private/bionic_asm.h>
 
-timerfd_settime:
+ENTRY(timerfd_settime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timerfd_settime
+    .cpload t9
+    li v0, __NR_timerfd_settime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end timerfd_settime
+END(timerfd_settime)
diff --git a/libc/arch-mips/syscalls/times.S b/libc/arch-mips/syscalls/times.S
index 248a23f..90ce97f 100644
--- a/libc/arch-mips/syscalls/times.S
+++ b/libc/arch-mips/syscalls/times.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl times
-    .align 4
-    .ent times
+#include <private/bionic_asm.h>
 
-times:
+ENTRY(times)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_times
+    .cpload t9
+    li v0, __NR_times
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end times
+END(times)
diff --git a/libc/arch-mips/syscalls/tkill.S b/libc/arch-mips/syscalls/tkill.S
deleted file mode 100644
index a80b506..0000000
--- a/libc/arch-mips/syscalls/tkill.S
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <asm/unistd.h>
-    .text
-    .globl tkill
-    .align 4
-    .ent tkill
-
-tkill:
-    .set noreorder
-    .cpload $t9
-    li $v0, __NR_tkill
-    syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
-    nop
-1:
-    la $t9,__set_errno
-    j $t9
-    nop
-    .set reorder
-    .end tkill
diff --git a/libc/arch-mips/syscalls/truncate.S b/libc/arch-mips/syscalls/truncate.S
index a4256dc..6800705 100644
--- a/libc/arch-mips/syscalls/truncate.S
+++ b/libc/arch-mips/syscalls/truncate.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl truncate
-    .align 4
-    .ent truncate
+#include <private/bionic_asm.h>
 
-truncate:
+ENTRY(truncate)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_truncate
+    .cpload t9
+    li v0, __NR_truncate
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end truncate
+END(truncate)
diff --git a/libc/arch-mips/syscalls/truncate64.S b/libc/arch-mips/syscalls/truncate64.S
index 9f48da0..870e735 100644
--- a/libc/arch-mips/syscalls/truncate64.S
+++ b/libc/arch-mips/syscalls/truncate64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl truncate64
-    .align 4
-    .ent truncate64
+#include <private/bionic_asm.h>
 
-truncate64:
+ENTRY(truncate64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_truncate64
+    .cpload t9
+    li v0, __NR_truncate64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end truncate64
+END(truncate64)
diff --git a/libc/arch-mips/syscalls/umask.S b/libc/arch-mips/syscalls/umask.S
index d74cf90..ccf4292 100644
--- a/libc/arch-mips/syscalls/umask.S
+++ b/libc/arch-mips/syscalls/umask.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl umask
-    .align 4
-    .ent umask
+#include <private/bionic_asm.h>
 
-umask:
+ENTRY(umask)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_umask
+    .cpload t9
+    li v0, __NR_umask
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end umask
+END(umask)
diff --git a/libc/arch-mips/syscalls/umount2.S b/libc/arch-mips/syscalls/umount2.S
index 6164f76..65a7129 100644
--- a/libc/arch-mips/syscalls/umount2.S
+++ b/libc/arch-mips/syscalls/umount2.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl umount2
-    .align 4
-    .ent umount2
+#include <private/bionic_asm.h>
 
-umount2:
+ENTRY(umount2)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_umount2
+    .cpload t9
+    li v0, __NR_umount2
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end umount2
+END(umount2)
diff --git a/libc/arch-mips/syscalls/uname.S b/libc/arch-mips/syscalls/uname.S
index a1051a2..f540b3a 100644
--- a/libc/arch-mips/syscalls/uname.S
+++ b/libc/arch-mips/syscalls/uname.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl uname
-    .align 4
-    .ent uname
+#include <private/bionic_asm.h>
 
-uname:
+ENTRY(uname)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_uname
+    .cpload t9
+    li v0, __NR_uname
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end uname
+END(uname)
diff --git a/libc/arch-mips/syscalls/unlinkat.S b/libc/arch-mips/syscalls/unlinkat.S
index 0ca77fe..001f9cf 100644
--- a/libc/arch-mips/syscalls/unlinkat.S
+++ b/libc/arch-mips/syscalls/unlinkat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl unlinkat
-    .align 4
-    .ent unlinkat
+#include <private/bionic_asm.h>
 
-unlinkat:
+ENTRY(unlinkat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_unlinkat
+    .cpload t9
+    li v0, __NR_unlinkat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end unlinkat
+END(unlinkat)
diff --git a/libc/arch-mips/syscalls/unshare.S b/libc/arch-mips/syscalls/unshare.S
index 592cc61..13ca452 100644
--- a/libc/arch-mips/syscalls/unshare.S
+++ b/libc/arch-mips/syscalls/unshare.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl unshare
-    .align 4
-    .ent unshare
+#include <private/bionic_asm.h>
 
-unshare:
+ENTRY(unshare)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_unshare
+    .cpload t9
+    li v0, __NR_unshare
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end unshare
+END(unshare)
diff --git a/libc/arch-mips/syscalls/utimensat.S b/libc/arch-mips/syscalls/utimensat.S
index 42fe4f9..14e5a10 100644
--- a/libc/arch-mips/syscalls/utimensat.S
+++ b/libc/arch-mips/syscalls/utimensat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl utimensat
-    .align 4
-    .ent utimensat
+#include <private/bionic_asm.h>
 
-utimensat:
+ENTRY(utimensat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_utimensat
+    .cpload t9
+    li v0, __NR_utimensat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end utimensat
+END(utimensat)
diff --git a/libc/arch-mips/syscalls/vmsplice.S b/libc/arch-mips/syscalls/vmsplice.S
new file mode 100644
index 0000000..0191f53
--- /dev/null
+++ b/libc/arch-mips/syscalls/vmsplice.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(vmsplice)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_vmsplice
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(vmsplice)
diff --git a/libc/arch-mips/syscalls/wait4.S b/libc/arch-mips/syscalls/wait4.S
index 8c53eca..8a12533 100644
--- a/libc/arch-mips/syscalls/wait4.S
+++ b/libc/arch-mips/syscalls/wait4.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl wait4
-    .align 4
-    .ent wait4
+#include <private/bionic_asm.h>
 
-wait4:
+ENTRY(wait4)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_wait4
+    .cpload t9
+    li v0, __NR_wait4
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end wait4
+END(wait4)
diff --git a/libc/arch-mips/syscalls/write.S b/libc/arch-mips/syscalls/write.S
index 85fe4d0..62dc36f 100644
--- a/libc/arch-mips/syscalls/write.S
+++ b/libc/arch-mips/syscalls/write.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl write
-    .align 4
-    .ent write
+#include <private/bionic_asm.h>
 
-write:
+ENTRY(write)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_write
+    .cpload t9
+    li v0, __NR_write
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end write
+END(write)
diff --git a/libc/arch-mips/syscalls/writev.S b/libc/arch-mips/syscalls/writev.S
index 4e23049..d8d6616 100644
--- a/libc/arch-mips/syscalls/writev.S
+++ b/libc/arch-mips/syscalls/writev.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl writev
-    .align 4
-    .ent writev
+#include <private/bionic_asm.h>
 
-writev:
+ENTRY(writev)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_writev
+    .cpload t9
+    li v0, __NR_writev
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end writev
+END(writev)
diff --git a/libc/arch-mips64/bionic/__bionic_clone.S b/libc/arch-mips64/bionic/__bionic_clone.S
new file mode 100644
index 0000000..0d266ee
--- /dev/null
+++ b/libc/arch-mips64/bionic/__bionic_clone.S
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+FRAMESZ		=	MKFSIZ(NARGSAVE,0)
+FRAME_ARG	=	0*REGSZ
+FRAME_FN	=	1*REGSZ
+#else
+FRAMESZ		=	MKFSIZ(0,3)
+FRAME_GP	=	FRAMESZ-1*REGSZ
+FRAME_ARG	=	FRAMESZ-2*REGSZ
+FRAME_FN	=	FRAMESZ-3*REGSZ
+#endif
+
+// pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
+LEAF(__bionic_clone, FRAMESZ)
+	PTR_SUBU sp, FRAMESZ			# allocate stack frame
+	SETUP_GP64(FRAME_GP,__bionic_clone)
+	SAVE_GP(FRAME_GP)
+
+	# set up child stack
+	PTR_SUBU a1,FRAMESZ
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+	PTR_L	t0,FRAMESZ+5*REGSZ(sp)	# fn
+	PRL_L	t1,FRAMESZ+6*REGSZ(sp)	# arg
+	PTR_S	t0,FRAME_FN(a1)		# fn
+	PTR_S	t1,FRAME_ARG(a1)	# arg
+#else
+	PTR_L	t0,FRAME_GP(sp)		# copy gp to child stack
+	PTR_S	t0,FRAME_GP(a1)
+	PTR_S	a5,FRAME_FN(a1)		# fn
+	PTR_S	a6,FRAME_ARG(a1)	# arg
+# endif
+
+	# remainder of arguments are correct for clone system call
+	LI	v0,__NR_clone
+	syscall
+
+	move    a0,v0
+	bnez	a3,.L__error_bc
+
+	beqz	v0,.L__thread_start_bc
+
+	RESTORE_GP64
+	PTR_ADDU sp,FRAMESZ
+	j	ra
+
+.L__thread_start_bc:
+	# Clear return address in child so we don't unwind further.
+	li	ra,0
+
+	# void __start_thread(int (*func)(void*), void *arg)
+	PTR_L	a0,FRAME_FN(sp)		#  fn
+	PTR_L	a1,FRAME_ARG(sp)	#  arg
+	LA	t9,__start_thread
+	RESTORE_GP64
+	/*
+	 * For O32 etc the child stack must have space for a0..a3 to be stored
+	 * For N64 etc, the child stack can be restored to the original value
+	 */
+#if !((_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32))
+	PTR_ADDU sp,FRAMESZ
+#endif
+	j	t9
+
+.L__error_bc:
+	LA	t9,__set_errno_internal
+	RESTORE_GP64
+	PTR_ADDU sp,FRAMESZ
+	j	t9
+	END(__bionic_clone)
+.hidden __bionic_clone
diff --git a/libc/arch-mips64/bionic/_exit_with_stack_teardown.S b/libc/arch-mips64/bionic/_exit_with_stack_teardown.S
new file mode 100644
index 0000000..fcf8cc1
--- /dev/null
+++ b/libc/arch-mips64/bionic/_exit_with_stack_teardown.S
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+// void _exit_with_stack_teardown(void* stackBase, size_t stackSize)
+ENTRY_PRIVATE(_exit_with_stack_teardown)
+  li	v0, __NR_munmap
+  syscall
+  // If munmap failed, we ignore the failure and exit anyway.
+
+  li	a0, 0
+  li	v0, __NR_exit
+  syscall
+  // The exit syscall does not return.
+END(_exit_with_stack_teardown)
diff --git a/libc/arch-mips64/bionic/_setjmp.S b/libc/arch-mips64/bionic/_setjmp.S
new file mode 100644
index 0000000..d237e6d
--- /dev/null
+++ b/libc/arch-mips64/bionic/_setjmp.S
@@ -0,0 +1,150 @@
+/*	$OpenBSD: _setjmp.S,v 1.4 2005/08/07 16:40:15 espie Exp $ */
+
+/*
+ * Copyright (c) 2002 Opsycon AB  (www.opsycon.se / www.opsycon.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Opsycon AB nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <private/bionic_asm.h>
+#include <machine/regnum.h>
+#include <machine/signal.h>
+
+/*
+ * _setjmp, _longjmp (not restoring signal state)
+ *
+ * XXX FPSET should probably be taken from SR setting. hmmm...
+ *  GPOFF and FRAMESIZE must be the same for both _setjmp and _longjmp!
+ *
+ */
+
+FRAMESZ= MKFSIZ(0,4)
+GPOFF= FRAMESZ-2*REGSZ
+
+LEAF(_setjmp, FRAMESZ)
+	PTR_SUBU sp, FRAMESZ
+	SETUP_GP64(GPOFF, _setjmp)
+	SAVE_GP(GPOFF)
+	.set	noreorder
+#if defined(__mips64)
+	dli	v0, 0xACEDBADE			# sigcontext magic number
+#else
+	li	v0, 0xACEDBADE			# sigcontext magic number
+#endif
+	REG_S	v0, SC_REGS+ZERO*REGSZ(a0)
+	REG_S	s0, SC_REGS+S0*REGSZ(a0)
+	REG_S	s1, SC_REGS+S1*REGSZ(a0)
+	REG_S	s2, SC_REGS+S2*REGSZ(a0)
+	REG_S	s3, SC_REGS+S3*REGSZ(a0)
+	REG_S	s4, SC_REGS+S4*REGSZ(a0)
+	REG_S	s5, SC_REGS+S5*REGSZ(a0)
+	REG_S	s6, SC_REGS+S6*REGSZ(a0)
+	REG_S	s7, SC_REGS+S7*REGSZ(a0)
+	REG_S	s8, SC_REGS+S8*REGSZ(a0)
+	REG_L	v0, GPOFF(sp)
+	REG_S	v0, SC_REGS+GP*REGSZ(a0)
+	PTR_ADDU v0, sp, FRAMESZ
+	REG_S	v0, SC_REGS+SP*REGSZ(a0)
+	REG_S	ra, SC_PC(a0)
+
+#if !defined(SOFTFLOAT)
+	li	v0, 1				# be nice if we could tell
+	REG_S	v0, SC_FPUSED(a0)		# sc_fpused = 1
+	cfc1	v0, $31
+	s.d	$f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
+	s.d	$f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
+	s.d	$f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
+	s.d	$f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
+	s.d	$f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
+	s.d	$f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
+#if _MIPS_FPSET == 32
+	s.d	$f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
+	s.d	$f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
+	s.d	$f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
+	s.d	$f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
+	s.d	$f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
+	s.d	$f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
+#endif
+	REG_S	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
+#endif /* !SOFTFLOAT */
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	j	ra
+	 move	v0, zero
+END(_setjmp)
+
+LEAF(_longjmp, FRAMESZ)
+	PTR_SUBU sp, FRAMESZ
+	SETUP_GP64(GPOFF, _longjmp)
+	SAVE_GP(GPOFF)
+	.set    noreorder
+	REG_L	v0, SC_REGS+ZERO*REGSZ(a0)
+	bne	v0, 0xACEDBADE, botch		# jump if error
+	REG_L	ra, SC_PC(a0)
+	REG_L	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
+	REG_L	s0, SC_REGS+S0*REGSZ(a0)
+	REG_L	s1, SC_REGS+S1*REGSZ(a0)
+	REG_L	s2, SC_REGS+S2*REGSZ(a0)
+	REG_L	s3, SC_REGS+S3*REGSZ(a0)
+	REG_L	s4, SC_REGS+S4*REGSZ(a0)
+	REG_L	s5, SC_REGS+S5*REGSZ(a0)
+	REG_L	s6, SC_REGS+S6*REGSZ(a0)
+	REG_L	s7, SC_REGS+S7*REGSZ(a0)
+	REG_L	s8, SC_REGS+S8*REGSZ(a0)
+	REG_L	gp, SC_REGS+GP*REGSZ(a0)
+	REG_L	sp, SC_REGS+SP*REGSZ(a0)
+#if !defined(SOFTFLOAT)
+	ctc1	v0, $31
+	l.d	$f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
+	l.d	$f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
+	l.d	$f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
+	l.d	$f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
+	l.d	$f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
+	l.d	$f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
+#if _MIPS_FPSET == 32
+	l.d	$f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
+	l.d	$f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
+	l.d	$f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
+	l.d	$f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
+	l.d	$f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
+	l.d	$f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
+#endif
+#endif /* !SOFTFLOAT */
+	bne	a1, zero, 1f
+	 nop
+	li	a1, 1			# never return 0!
+1:
+	j	ra
+	 move	v0, a1
+
+botch:
+	jal	longjmperror
+	nop
+	jal	abort
+	nop
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+END(_longjmp)
diff --git a/libc/arch-mips64/bionic/atexit.h b/libc/arch-mips64/bionic/atexit.h
new file mode 100644
index 0000000..759008c
--- /dev/null
+++ b/libc/arch-mips64/bionic/atexit.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+extern void *__dso_handle;
+extern int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
+
+__attribute__ ((visibility ("hidden")))
+int atexit(void (*func)(void))
+{
+  return (__cxa_atexit((void (*)(void *))func, (void *)0, &__dso_handle));
+}
diff --git a/libc/arch-mips64/bionic/crtbegin.c b/libc/arch-mips64/bionic/crtbegin.c
new file mode 100644
index 0000000..2ea31ad
--- /dev/null
+++ b/libc/arch-mips64/bionic/crtbegin.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "../../bionic/libc_init_common.h"
+#include <stddef.h>
+#include <stdint.h>
+
+__attribute__ ((section (".preinit_array")))
+void (*__PREINIT_ARRAY__)(void) = (void (*)(void)) -1;
+
+__attribute__ ((section (".init_array")))
+void (*__INIT_ARRAY__)(void) = (void (*)(void)) -1;
+
+__attribute__ ((section (".fini_array")))
+void (*__FINI_ARRAY__)(void) = (void (*)(void)) -1;
+
+
+__LIBC_HIDDEN__  void do_mips_start(void *raw_args) {
+  structors_array_t array;
+  array.preinit_array = &__PREINIT_ARRAY__;
+  array.init_array = &__INIT_ARRAY__;
+  array.fini_array = &__FINI_ARRAY__;
+
+  __libc_init(raw_args, NULL, &main, &array);
+}
+
+/*
+ * This function prepares the return address with a branch-and-link
+ * instruction (bal) and then uses a .cpsetup to compute the Global
+ * Offset Table (GOT) pointer ($gp). The $gp is then used to load
+ * the address of _do_mips_start() into $t9 just before calling it.
+ * Terminating the stack with a NULL return address.
+ */
+__asm__ (
+"       .set push                   \n"
+"                                   \n"
+"       .text                       \n"
+"       .align  4                   \n"
+"       .type __start,@function     \n"
+"       .globl __start              \n"
+"       .globl  _start              \n"
+"                                   \n"
+"       .ent    __start             \n"
+"__start:                           \n"
+" _start:                           \n"
+"       .frame   $sp,32,$0          \n"
+"       .mask   0x80000000,-8       \n"
+"                                   \n"
+"       move    $a0, $sp            \n"
+"       daddiu  $sp, $sp, -32       \n"
+"                                   \n"
+"       .set noreorder              \n"
+"       bal     1f                  \n"
+"       nop                         \n"
+"1:                                 \n"
+"       .cpsetup $ra,16,1b          \n"
+"       .set reorder                \n"
+"                                   \n"
+"       sd      $0, 24($sp)         \n"
+"       jal     do_mips_start       \n"
+"                                   \n"
+"2:     b       2b                  \n"
+"       .end    __start             \n"
+"                                   \n"
+"       .set pop                    \n"
+);
+
+#include "../../arch-common/bionic/__dso_handle.h"
+#include "atexit.h"
diff --git a/libc/arch-mips64/bionic/crtbegin_so.c b/libc/arch-mips64/bionic/crtbegin_so.c
new file mode 100644
index 0000000..d664ce6
--- /dev/null
+++ b/libc/arch-mips64/bionic/crtbegin_so.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+extern void __cxa_finalize(void *);
+extern void *__dso_handle;
+
+__attribute__((visibility("hidden"),destructor))
+void __on_dlclose() {
+  __cxa_finalize(&__dso_handle);
+}
+
+#include "../../arch-common/bionic/__dso_handle_so.h"
+#include "atexit.h"
diff --git a/libc/arch-mips64/bionic/setjmp.S b/libc/arch-mips64/bionic/setjmp.S
new file mode 100644
index 0000000..31786be
--- /dev/null
+++ b/libc/arch-mips64/bionic/setjmp.S
@@ -0,0 +1,174 @@
+/*      $OpenBSD: setjmp.S,v 1.5 2005/08/07 16:40:15 espie Exp $ */
+
+/*
+ * Copyright (c) 2001-2002 Opsycon AB  (www.opsycon.se / www.opsycon.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Opsycon AB nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <private/bionic_asm.h>
+#include <machine/regnum.h>
+#include <machine/signal.h>
+
+/*
+ * setjmp, longjmp implementation for libc. this code depends
+ * on the layout of the struct sigcontext in machine/signal.h.
+ *
+ */
+
+FRAMESZ= MKFSIZ(2,6)
+A1OFF= FRAMESZ-4*REGSZ
+A0OFF= FRAMESZ-3*REGSZ
+GPOFF= FRAMESZ-2*REGSZ
+RAOFF= FRAMESZ-1*REGSZ
+
+NON_LEAF(setjmp, FRAMESZ, ra)
+	.mask	0x80000000, RAOFF
+	PTR_SUBU sp, FRAMESZ			# allocate stack frame
+	SETUP_GP64(GPOFF, setjmp)
+	SAVE_GP(GPOFF)
+	.set	reorder
+	REG_S	ra, RAOFF(sp)			# save state
+	REG_S	a0, A0OFF(sp)
+
+	move	a0, zero			# get current signal mask
+	jal	sigblock
+
+	REG_L	v1, A0OFF(sp)			# v1 = jmpbuf
+	REG_S	v0, SC_MASK(v1)			# save sc_mask = sigblock(0)
+
+	REG_L	a0, A0OFF(sp)			# restore jmpbuf
+	REG_L	ra, RAOFF(sp)
+	REG_S	ra, SC_PC(a0)			# sc_pc = return address
+#if defined(__mips64)
+	dli	v0, 0xACEDBADE			# sigcontext magic number
+#else
+	li	v0, 0xACEDBADE			# sigcontext magic number
+#endif
+	REG_S	v0, SC_REGS+ZERO*REGSZ(a0)
+	REG_S	s0, SC_REGS+S0*REGSZ(a0)
+	REG_S	s1, SC_REGS+S1*REGSZ(a0)
+	REG_S	s2, SC_REGS+S2*REGSZ(a0)
+	REG_S	s3, SC_REGS+S3*REGSZ(a0)
+	REG_S	s4, SC_REGS+S4*REGSZ(a0)
+	REG_S	s5, SC_REGS+S5*REGSZ(a0)
+	REG_S	s6, SC_REGS+S6*REGSZ(a0)
+	REG_S	s7, SC_REGS+S7*REGSZ(a0)
+	REG_S	s8, SC_REGS+S8*REGSZ(a0)
+	REG_L	v0, GPOFF(sp)
+	REG_S	v0, SC_REGS+GP*REGSZ(a0)
+	PTR_ADDU v0, sp, FRAMESZ
+	REG_S	v0, SC_REGS+SP*REGSZ(a0)
+
+#if !defined(SOFTFLOAT)
+	li	v0, 1				# be nice if we could tell
+	REG_S	v0, SC_FPUSED(a0)		# sc_fpused = 1
+	cfc1	v0, $31
+	s.d	$f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
+	s.d	$f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
+	s.d	$f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
+	s.d	$f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
+	s.d	$f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
+	s.d	$f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
+#if _MIPS_FPSET == 32
+	s.d	$f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
+	s.d	$f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
+	s.d	$f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
+	s.d	$f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
+	s.d	$f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
+	s.d	$f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
+#endif
+	REG_S	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
+#endif /* !SOFTFLOAT */
+	move	v0, zero
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	j	ra
+
+botch:
+	jal	longjmperror
+	jal	abort
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+END(setjmp)
+
+
+LEAF(longjmp, FRAMESZ)
+	PTR_SUBU sp, FRAMESZ
+	SETUP_GP64(GPOFF, longjmp)
+	SAVE_GP(GPOFF)
+	.set	reorder
+	sw	a1, A1OFF(sp)
+	sw	a0, A0OFF(sp)
+
+	lw	a0, SC_MASK(a0)
+	jal	sigsetmask
+
+	lw	a0, A0OFF(sp)
+	lw	a1, A1OFF(sp)
+
+	.set	noreorder
+	REG_L	v0, SC_REGS+ZERO*REGSZ(a0)
+	bne	v0, 0xACEDBADE, botch		# jump if error
+	REG_L	ra, SC_PC(a0)
+	REG_L	s0, SC_REGS+S0*REGSZ(a0)
+	REG_L	s1, SC_REGS+S1*REGSZ(a0)
+	REG_L	s2, SC_REGS+S2*REGSZ(a0)
+	REG_L	s3, SC_REGS+S3*REGSZ(a0)
+	REG_L	s4, SC_REGS+S4*REGSZ(a0)
+	REG_L	s5, SC_REGS+S5*REGSZ(a0)
+	REG_L	s6, SC_REGS+S6*REGSZ(a0)
+	REG_L	s7, SC_REGS+S7*REGSZ(a0)
+	REG_L	s8, SC_REGS+S8*REGSZ(a0)
+	REG_L	gp, SC_REGS+GP*REGSZ(a0)
+	REG_L	sp, SC_REGS+SP*REGSZ(a0)
+
+#if !defined(SOFTFLOAT)
+	REG_L	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
+	ctc1	v0, $31
+	l.d	$f20, SC_FPREGS+((F20-F0)*REGSZ_FP)(a0)
+	l.d	$f22, SC_FPREGS+((F22-F0)*REGSZ_FP)(a0)
+	l.d	$f24, SC_FPREGS+((F24-F0)*REGSZ_FP)(a0)
+	l.d	$f26, SC_FPREGS+((F26-F0)*REGSZ_FP)(a0)
+	l.d	$f28, SC_FPREGS+((F28-F0)*REGSZ_FP)(a0)
+	l.d	$f30, SC_FPREGS+((F30-F0)*REGSZ_FP)(a0)
+#if _MIPS_FPSET == 32
+	l.d	$f21, SC_FPREGS+((F21-F0)*REGSZ_FP)(a0)
+	l.d	$f23, SC_FPREGS+((F23-F0)*REGSZ_FP)(a0)
+	l.d	$f25, SC_FPREGS+((F25-F0)*REGSZ_FP)(a0)
+	l.d	$f27, SC_FPREGS+((F27-F0)*REGSZ_FP)(a0)
+	l.d	$f29, SC_FPREGS+((F29-F0)*REGSZ_FP)(a0)
+	l.d	$f31, SC_FPREGS+((F31-F0)*REGSZ_FP)(a0)
+#endif
+#endif /* !SOFTFLOAT */
+	bne	a1, zero, 1f
+	 nop
+	li	a1, 1			# never return 0!
+1:
+	j	ra
+	 move	v0, a1
+
+END(longjmp)
diff --git a/libc/arch-mips64/bionic/sigsetjmp.S b/libc/arch-mips64/bionic/sigsetjmp.S
new file mode 100644
index 0000000..9d2e5ea
--- /dev/null
+++ b/libc/arch-mips64/bionic/sigsetjmp.S
@@ -0,0 +1,77 @@
+/* $OpenBSD: sigsetjmp.S,v 1.5 2005/08/07 16:40:15 espie Exp $ */
+/*-
+ * Copyright (c) 1991, 1993, 1995,
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Havard Eidnes.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+#include <machine/regnum.h>
+#include <machine/setjmp.h>
+
+/*
+ * trampolines for sigsetjmp and  siglongjmp save and restore mask.
+ *
+ */
+FRAMESZ= MKFSIZ(1,1)
+GPOFF= FRAMESZ-2*REGSZ
+
+LEAF(sigsetjmp, FRAMESZ)
+	PTR_SUBU sp, FRAMESZ
+	SETUP_GP64(GPOFF, sigsetjmp)
+	.set	reorder
+	REG_S	a1, (_JBLEN*REGSZ)(a0)		# save "savemask"
+	bne	a1, 0x0, 1f			# do saving of signal mask?
+	LA	t9, _setjmp
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	jr t9
+
+1:	LA	t9, setjmp
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	jr t9
+END(sigsetjmp)
+
+LEAF(siglongjmp, FRAMESZ)
+	PTR_SUBU sp, FRAMESZ
+	SETUP_GP64(GPOFF, siglongjmp)
+	.set	reorder
+	REG_L	t0, (_JBLEN*REGSZ)(a0)		# get "savemask"
+	bne	t0, 0x0, 1f			# restore signal mask?
+	LA	t9, _longjmp
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	jr	t9
+1:
+	LA	t9, longjmp
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	jr	t9
+END(siglongjmp)
diff --git a/libc/arch-mips64/bionic/syscall.S b/libc/arch-mips64/bionic/syscall.S
new file mode 100644
index 0000000..924741d
--- /dev/null
+++ b/libc/arch-mips64/bionic/syscall.S
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+FRAMESZ		=	MKFSIZ(6,0)
+#else
+FRAMESZ		=	MKFSIZ(0,1)
+FRAME_GP	=	FRAMESZ-1*REGSZ
+#endif
+
+LEAF(syscall,FRAMESZ)
+	PTR_SUBU sp, FRAMESZ	# allocate stack frame
+	SETUP_GP64(FRAME_GP,syscall)
+	SAVE_GP(FRAME_GP)
+	move	v0, a0		# syscall number to v0
+	move	a0, a1		# shift args down
+	move	a1, a2
+	move	a2, a3
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+	REG_L	a3, FRAMESZ+4*REGSZ(sp)
+	REG_L	t0, FRAMESZ+5*REGSZ(sp)
+	REG_L	t1, FRAMESZ+6*REGSZ(sp)
+	REG_S	t0, 4*REGSZ(sp)
+	REG_S	t1, 5*REGSZ(sp)
+#else
+	move	a3, a4
+	move	a4, a5
+	REG_L	a5, FRAMESZ(sp)
+#endif
+	syscall
+	move	a0, v0
+	bnez	a3, 1f
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	j	ra
+1:
+	LA	t9,__set_errno_internal
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	j	t9
+	END(syscall)
diff --git a/libc/arch-mips64/bionic/vfork.S b/libc/arch-mips64/bionic/vfork.S
new file mode 100644
index 0000000..d180a8c
--- /dev/null
+++ b/libc/arch-mips64/bionic/vfork.S
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+#include <linux/sched.h>
+
+// TODO: mips' uapi signal.h is missing #ifndef __ASSEMBLY__.
+// #include <asm/signal.h>
+#define SIGCHLD 18
+
+	.text
+
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+FRAMESZ		=	MKFSIZ(5,0)
+#else
+FRAMESZ		=	MKFSIZ(0,0)
+#endif
+
+LEAF(vfork,FRAMESZ)
+#if FRAMESZ!=0
+	PTR_SUBU sp, FRAMESZ
+#endif
+	SETUP_GP64(a5, vfork)
+	LI	a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
+	move	a1, $0
+	move	a2, $0
+	move	a3, $0
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+	REG_S	$0, 4*REGSZ(sp)
+#else
+	move	a4, $0
+#endif
+	LI	v0, __NR_clone
+	syscall
+#if FRAMESZ!=0
+	PTR_ADDU sp,FRAMESZ
+#endif
+	move	a0, v0
+	bnez	a3, 1f
+	RESTORE_GP64
+	j	ra
+1:
+	LA	t9,__set_errno_internal
+	RESTORE_GP64
+	j	t9
+	END(vfork)
diff --git a/libc/arch-mips64/include/machine/asm.h b/libc/arch-mips64/include/machine/asm.h
new file mode 100644
index 0000000..5eacde3
--- /dev/null
+++ b/libc/arch-mips64/include/machine/asm.h
@@ -0,0 +1,208 @@
+/*	$OpenBSD: asm.h,v 1.7 2004/10/20 12:49:15 pefo Exp $ */
+
+/*
+ * Copyright (c) 2001-2002 Opsycon AB  (www.opsycon.se / www.opsycon.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#ifndef _MIPS64_ASM_H
+#define _MIPS64_ASM_H
+
+#ifndef _ALIGN_TEXT
+# define _ALIGN_TEXT .align 4
+#endif
+
+#undef __bionic_asm_custom_entry
+#undef __bionic_asm_custom_end
+#define __bionic_asm_custom_entry(f) .ent f
+#define __bionic_asm_custom_end(f) .end f
+
+#include <machine/regdef.h>
+
+#define	_MIPS_ISA_MIPS1	1	/* R2000/R3000 */
+#define	_MIPS_ISA_MIPS2	2	/* R4000/R6000 */
+#define	_MIPS_ISA_MIPS3	3	/* R4000 */
+#define	_MIPS_ISA_MIPS4	4	/* TFP (R1x000) */
+#define	_MIPS_ISA_MIPS5 5
+#define	_MIPS_ISA_MIPS32 6
+#define	_MIPS_ISA_MIPS64 7
+
+#if !defined(ABICALLS) && !defined(_NO_ABICALLS)
+#define	ABICALLS	.abicalls
+#endif
+
+#if defined(ABICALLS) && !defined(_KERNEL)
+	ABICALLS
+#endif
+
+#if !defined(__MIPSEL__) && !defined(__MIPSEB__)
+#error "__MIPSEL__ or __MIPSEB__ must be defined"
+#endif
+/*
+ * Define how to access unaligned data word
+ */
+#if defined(__MIPSEL__)
+#define LWLO    lwl
+#define LWHI    lwr
+#define	SWLO	swl
+#define	SWHI	swr
+#define LDLO    ldl
+#define LDHI    ldr
+#define	SDLO	sdl
+#define	SDHI	sdr
+#endif
+#if defined(__MIPSEB__)
+#define LWLO    lwr
+#define LWHI    lwl
+#define	SWLO	swr
+#define	SWHI	swl
+#define LDLO    ldr
+#define LDHI    ldl
+#define	SDLO	sdr
+#define	SDHI	sdl
+#endif
+
+/*
+ *  Define programming environment for ABI.
+ */
+#if defined(ABICALLS) && !defined(_KERNEL) && !defined(_STANDALONE)
+
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+#define NARGSAVE	4
+
+#define	SETUP_GP		\
+	.set	noreorder;	\
+	.cpload	t9;		\
+	.set	reorder;
+
+#define	SAVE_GP(x)		\
+	.cprestore x
+
+#define	SETUP_GP64(gpoff, name)
+#define	RESTORE_GP64
+#endif
+
+#if (_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIN32)
+#define NARGSAVE	0
+
+#define	SETUP_GP
+#define	SAVE_GP(x)
+#define	SETUP_GP64(gpoff, name)	\
+	.cpsetup t9, gpoff, name
+#define	RESTORE_GP64		\
+	.cpreturn
+#endif
+
+#define	MKFSIZ(narg,locals) (((narg+locals)*REGSZ+31)&(~31))
+
+#else /* defined(ABICALLS) && !defined(_KERNEL) */
+
+#define	NARGSAVE	4
+#define	SETUP_GP
+#define	SAVE_GP(x)
+
+#define	ALIGNSZ		16	/* Stack layout alignment */
+#define	FRAMESZ(sz)	(((sz) + (ALIGNSZ-1)) & ~(ALIGNSZ-1))
+
+#endif
+
+/*
+ *  Basic register operations based on selected ISA
+ */
+#if (_MIPS_ISA == _MIPS_ISA_MIPS1 || _MIPS_ISA == _MIPS_ISA_MIPS2 || _MIPS_ISA == _MIPS_ISA_MIPS32)
+#define REGSZ		4	/* 32 bit mode register size */
+#define LOGREGSZ	2	/* log rsize */
+#define	REG_S	sw
+#define	REG_L	lw
+#define	CF_SZ		24	/* Call frame size */
+#define	CF_ARGSZ	16	/* Call frame arg size */
+#define	CF_RA_OFFS	20	/* Call ra save offset */
+#endif
+
+#if (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4 || _MIPS_ISA == _MIPS_ISA_MIPS64)
+#define REGSZ		8	/* 64 bit mode register size */
+#define LOGREGSZ	3	/* log rsize */
+#define	REG_S	sd
+#define	REG_L	ld
+#define	CF_SZ		48	/* Call frame size (multiple of ALIGNSZ) */
+#define	CF_ARGSZ	32	/* Call frame arg size */
+#define	CF_RA_OFFS	40	/* Call ra save offset */
+#endif
+
+#define REGSZ_FP	 8	/* 64 bit FP register size */
+
+#ifndef __LP64__
+#define	PTR_L		lw
+#define	PTR_S		sw
+#define	PTR_SUB		sub
+#define	PTR_ADD		add
+#define	PTR_SUBU	subu
+#define	PTR_ADDU	addu
+#define LI		li
+#define	LA		la
+#define	PTR_SLL		sll
+#define	PTR_SRL		srl
+#define	PTR_VAL		.word
+#else
+#define	PTR_L		ld
+#define	PTR_S		sd
+#define	PTR_ADD		dadd
+#define	PTR_SUB		dsub
+#define	PTR_SUBU	dsubu
+#define	PTR_ADDU	daddu
+#define LI		dli
+#define LA		dla
+#define	PTR_SLL		dsll
+#define	PTR_SRL		dsrl
+#define	PTR_VAL		.dword
+#endif
+
+/*
+ * LEAF(x, fsize)
+ *
+ *	Declare a leaf routine.
+ */
+#define LEAF(x, fsize)		\
+	.align	3;		\
+	.globl x;		\
+	.ent x, 0;		\
+x: ;				\
+	.cfi_startproc; \
+	.frame sp, fsize, ra;	\
+	SETUP_GP		\
+
+/*
+ * NON_LEAF(x)
+ *
+ *	Declare a non-leaf routine (a routine that makes other C calls).
+ */
+#define NON_LEAF(x, fsize, retpc) \
+	.align	3;		\
+	.globl x;		\
+	.ent x, 0;		\
+x: ;				\
+	.cfi_startproc; \
+	.frame sp, fsize, retpc; \
+	SETUP_GP		\
+
+#endif /* !_MIPS_ASM_H */
diff --git a/libc/arch-mips64/include/machine/elf_machdep.h b/libc/arch-mips64/include/machine/elf_machdep.h
new file mode 100644
index 0000000..d27d431
--- /dev/null
+++ b/libc/arch-mips64/include/machine/elf_machdep.h
@@ -0,0 +1,196 @@
+/*	$NetBSD: elf_machdep.h,v 1.15 2011/03/15 07:39:22 matt Exp $	*/
+
+#ifndef _MIPS_ELF_MACHDEP_H_
+#define  _MIPS_ELF_MACHDEP_H_
+
+#ifdef _LP64
+#define ARCH_ELFSIZE		64	/* MD native binary size */
+#else
+#define ARCH_ELFSIZE		32	/* MD native binary size */
+#endif
+
+#if ELFSIZE == 32
+#define	ELF32_MACHDEP_ID_CASES						\
+		case EM_MIPS:						\
+			break;
+
+#define	ELF32_MACHDEP_ID	EM_MIPS
+#elif ELFSIZE == 64
+#define	ELF64_MACHDEP_ID_CASES						\
+		case EM_MIPS:						\
+			break;
+
+#define	ELF64_MACHDEP_ID	EM_MIPS
+#endif
+
+/* mips relocs.  */
+
+#define R_MIPS_NONE		0
+#define R_MIPS_16		1
+#define R_MIPS_32		2
+#define R_MIPS_REL32		3
+#define R_MIPS_REL		R_MIPS_REL32
+#define R_MIPS_26		4
+#define R_MIPS_HI16		5	/* high 16 bits of symbol value */
+#define R_MIPS_LO16		6	/* low 16 bits of symbol value */
+#define R_MIPS_GPREL16		7  	/* GP-relative reference  */
+#define R_MIPS_LITERAL		8 	/* Reference to literal section  */
+#define R_MIPS_GOT16		9	/* Reference to global offset table */
+#define R_MIPS_GOT		R_MIPS_GOT16
+#define R_MIPS_PC16		10  	/* 16 bit PC relative reference */
+#define R_MIPS_CALL16 		11  	/* 16 bit call thru glbl offset tbl */
+#define R_MIPS_CALL		R_MIPS_CALL16
+#define R_MIPS_GPREL32		12
+
+/* 13, 14, 15 are not defined at this point. */
+#define R_MIPS_UNUSED1		13
+#define R_MIPS_UNUSED2		14
+#define R_MIPS_UNUSED3		15
+
+/*
+ * The remaining relocs are apparently part of the 64-bit Irix ELF ABI.
+ */
+#define R_MIPS_SHIFT5		16
+#define R_MIPS_SHIFT6		17
+
+#define R_MIPS_64		18
+#define R_MIPS_GOT_DISP		19
+#define R_MIPS_GOT_PAGE		20
+#define R_MIPS_GOT_OFST		21
+#define R_MIPS_GOT_HI16		22
+#define R_MIPS_GOT_LO16		23
+#define R_MIPS_SUB 		24
+#define R_MIPS_INSERT_A		25
+#define R_MIPS_INSERT_B		26
+#define R_MIPS_DELETE		27
+#define R_MIPS_HIGHER		28
+#define R_MIPS_HIGHEST		29
+#define R_MIPS_CALL_HI16	30
+#define R_MIPS_CALL_LO16	31
+#define R_MIPS_SCN_DISP		32
+#define R_MIPS_REL16		33
+#define R_MIPS_ADD_IMMEDIATE	34
+#define R_MIPS_PJUMP		35
+#define R_MIPS_RELGOT		36
+#define	R_MIPS_JALR		37
+/* TLS relocations */
+
+#define R_MIPS_TLS_DTPMOD32	38	/* Module number 32 bit */
+#define R_MIPS_TLS_DTPREL32	39	/* Module-relative offset 32 bit */
+#define R_MIPS_TLS_DTPMOD64	40	/* Module number 64 bit */
+#define R_MIPS_TLS_DTPREL64	41	/* Module-relative offset 64 bit */
+#define R_MIPS_TLS_GD		42	/* 16 bit GOT offset for GD */
+#define R_MIPS_TLS_LDM		43	/* 16 bit GOT offset for LDM */
+#define R_MIPS_TLS_DTPREL_HI16	44	/* Module-relative offset, high 16 bits */
+#define R_MIPS_TLS_DTPREL_LO16	45	/* Module-relative offset, low 16 bits */
+#define R_MIPS_TLS_GOTTPREL	46	/* 16 bit GOT offset for IE */
+#define R_MIPS_TLS_TPREL32	47	/* TP-relative offset, 32 bit */
+#define R_MIPS_TLS_TPREL64	48	/* TP-relative offset, 64 bit */
+#define R_MIPS_TLS_TPREL_HI16	49	/* TP-relative offset, high 16 bits */
+#define R_MIPS_TLS_TPREL_LO16	50	/* TP-relative offset, low 16 bits */
+
+#define R_MIPS_max		51
+
+#define R_TYPE(name)		__CONCAT(R_MIPS_,name)
+
+#define	R_MIPS16_min		100
+#define	R_MIPS16_26		100
+#define	R_MIPS16_GPREL		101
+#define	R_MIPS16_GOT16		102
+#define	R_MIPS16_CALL16		103
+#define	R_MIPS16_HI16		104
+#define	R_MIPS16_LO16		105
+#define	R_MIPS16_max		106
+
+
+/* mips dynamic tags */
+
+#define DT_MIPS_RLD_VERSION	0x70000001
+#define DT_MIPS_TIME_STAMP	0x70000002
+#define DT_MIPS_ICHECKSUM	0x70000003
+#define DT_MIPS_IVERSION	0x70000004
+#define DT_MIPS_FLAGS		0x70000005
+#define DT_MIPS_BASE_ADDRESS	0x70000006
+#define DT_MIPS_CONFLICT	0x70000008
+#define DT_MIPS_LIBLIST		0x70000009
+#define DT_MIPS_CONFLICTNO	0x7000000b
+#define	DT_MIPS_LOCAL_GOTNO	0x7000000a	/* number of local got ents */
+#define DT_MIPS_LIBLISTNO	0x70000010
+#define	DT_MIPS_SYMTABNO	0x70000011	/* number of .dynsym entries */
+#define DT_MIPS_UNREFEXTNO	0x70000012
+#define	DT_MIPS_GOTSYM		0x70000013	/* first dynamic sym in got */
+#define DT_MIPS_HIPAGENO	0x70000014
+#define	DT_MIPS_RLD_MAP		0x70000016	/* address of loader map */
+
+/*
+ * ELF Flags
+ */
+#define	EF_MIPS_PIC		0x00000002	/* Contains PIC code */
+#define	EF_MIPS_CPIC		0x00000004	/* STD PIC calling sequence */
+#define	EF_MIPS_ABI2		0x00000020	/* N32 */
+
+#define	EF_MIPS_ARCH_ASE	0x0f000000	/* Architectural extensions */
+#define	EF_MIPS_ARCH_MDMX	0x08000000	/* MDMX multimedia extension */
+#define	EF_MIPS_ARCH_M16	0x04000000	/* MIPS-16 ISA extensions */
+
+#define	EF_MIPS_ARCH		0xf0000000	/* Architecture field */
+#define	EF_MIPS_ARCH_1		0x00000000	/* -mips1 code */
+#define	EF_MIPS_ARCH_2		0x10000000	/* -mips2 code */
+#define	EF_MIPS_ARCH_3		0x20000000	/* -mips3 code */
+#define	EF_MIPS_ARCH_4		0x30000000	/* -mips4 code */
+#define	EF_MIPS_ARCH_5		0x40000000	/* -mips5 code */
+#define	EF_MIPS_ARCH_32		0x50000000	/* -mips32 code */
+#define	EF_MIPS_ARCH_64		0x60000000	/* -mips64 code */
+#define	EF_MIPS_ARCH_32R2	0x70000000	/* -mips32r2 code */
+#define	EF_MIPS_ARCH_64R2	0x80000000	/* -mips64r2 code */
+
+#define	EF_MIPS_ABI		0x0000f000
+#define	EF_MIPS_ABI_O32		0x00001000
+#define	EF_MIPS_ABI_O64		0x00002000
+#define	EF_MIPS_ABI_EABI32	0x00003000
+#define	EF_MIPS_ABI_EABI64	0x00004000
+
+#if defined(__MIPSEB__)
+#define	ELF32_MACHDEP_ENDIANNESS	ELFDATA2MSB
+#define	ELF64_MACHDEP_ENDIANNESS	ELFDATA2MSB
+#elif defined(__MIPSEL__)
+#define	ELF32_MACHDEP_ENDIANNESS	ELFDATA2LSB
+#define	ELF64_MACHDEP_ENDIANNESS	ELFDATA2LSB
+#elif !defined(HAVE_NBTOOL_CONFIG_H)
+#error neither __MIPSEL__ nor __MIPSEB__ are defined.
+#endif
+
+#ifdef _KERNEL
+#ifdef _KERNEL_OPT
+#include "opt_compat_netbsd.h"
+#endif
+#ifdef COMPAT_16
+/*
+ * Up to 1.6, the ELF dynamic loader (ld.elf_so) was not relocatable.
+ * Tell the kernel ELF exec code not to try relocating the interpreter
+ * for dynamically-linked ELF binaries.
+ */
+#define ELF_INTERP_NON_RELOCATABLE
+#endif /* COMPAT_16 */
+
+/*
+ * We need to be able to include the ELF header so we can pick out the
+ * ABI being used.
+ */
+#ifdef ELFSIZE
+#define	ELF_MD_PROBE_FUNC	ELFNAME2(mips_netbsd,probe)
+#define	ELF_MD_COREDUMP_SETUP	ELFNAME2(coredump,setup)
+#endif
+
+struct exec_package;
+
+int mips_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
+	vaddr_t *);
+void coredump_elf32_setup(struct lwp *, void *);
+
+int mips_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *,
+	vaddr_t *);
+void coredump_elf64_setup(struct lwp *, void *);
+#endif /* _KERNEL */
+
+#endif /* _MIPS_ELF_MACHDEP_H_ */
diff --git a/libc/arch-mips64/include/machine/endian.h b/libc/arch-mips64/include/machine/endian.h
new file mode 100644
index 0000000..41a9004
--- /dev/null
+++ b/libc/arch-mips64/include/machine/endian.h
@@ -0,0 +1,70 @@
+/*	$OpenBSD: endian.h,v 1.5 2006/02/27 23:35:59 miod Exp $ */
+
+/*
+ * Copyright (c) 2001-2002 Opsycon AB  (www.opsycon.se / www.opsycon.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MIPS64_ENDIAN_H_
+#define _MIPS64_ENDIAN_H_
+
+#ifdef __GNUC__
+
+#if defined(__mips_isa_rev) && (__mips_isa_rev >= 2)
+#define __swap16md(x) ({					\
+    register uint16_t _x = (x);					\
+    register uint16_t _r;					\
+    __asm volatile ("wsbh %0, %1" : "=r" (_r) : "r" (_x));	\
+    _r;								\
+})
+
+#define __swap32md(x) ({					\
+    register uint32_t _x = (x);					\
+    register uint32_t _r;					\
+    __asm volatile ("wsbh %0, %1; rotr %0, %0, 16" : "=r" (_r) : "r" (_x)); \
+    _r;								\
+})
+
+#define __swap64md(x) ({					\
+    uint64_t _swap64md_x = (x);					\
+    (uint64_t) __swap32md(_swap64md_x >> 32) |			\
+        (uint64_t) __swap32md(_swap64md_x & 0xffffffff) << 32;	\
+})
+
+/* Tell sys/endian.h we have MD variants of the swap macros.  */
+#define MD_SWAP
+
+#endif  /* __mips32r2__ */
+#endif  /* __GNUC__ */
+
+#if defined(__MIPSEB__)
+#define _BYTE_ORDER _BIG_ENDIAN
+#else
+#define _BYTE_ORDER _LITTLE_ENDIAN
+#endif
+#define __STRICT_ALIGNMENT
+#include <sys/types.h>
+#include <sys/endian.h>
+
+#endif /* _MIPS64_ENDIAN_H_ */
diff --git a/libc/arch-mips64/include/machine/exec.h b/libc/arch-mips64/include/machine/exec.h
new file mode 100644
index 0000000..3c63f74
--- /dev/null
+++ b/libc/arch-mips64/include/machine/exec.h
@@ -0,0 +1,188 @@
+/*	$OpenBSD: exec.h,v 1.1 2004/10/18 19:05:36 grange Exp $	*/
+
+/*
+ * Copyright (c) 1996-2004 Per Fogelstrom, Opsycon AB
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MIPS64_EXEC_H_
+#define _MIPS64_EXEC_H_
+
+#define	__LDPGSZ	4096
+
+/*
+ *  Define what exec "formats" we should handle.
+ */
+#define NATIVE_EXEC_ELF
+#define NATIVE_ELFSIZE 64
+#define	EXEC_SCRIPT
+
+/*
+ *  If included from sys/exec.h define kernels ELF format.
+ */
+#ifdef __LP64__
+#define	ARCH_ELFSIZE 64
+#define DB_ELFSIZE 64
+#define ELF_TARG_CLASS  ELFCLASS64
+#else
+#define	ARCH_ELFSIZE 32
+#define DB_ELFSIZE 32
+#define ELF_TARG_CLASS  ELFCLASS32
+#endif
+
+#if defined(__MIPSEB__)
+#define ELF_TARG_DATA		ELFDATA2MSB
+#else
+#define ELF_TARG_DATA		ELFDATA2LSB
+#endif
+#define ELF_TARG_MACH		EM_MIPS
+
+#define _NLIST_DO_ELF
+
+#if defined(_LP64)
+#define _KERN_DO_ELF64
+#if defined(COMPAT_O32)
+#define _KERN_DO_ELF
+#endif
+#else
+#define _KERN_DO_ELF
+#endif
+
+/* Information taken from MIPS ABI supplemental */
+
+/* Architecture dependent Segment types - p_type */
+#define PT_MIPS_REGINFO 0x70000000      /* Register usage information */
+
+/* Architecture dependent d_tag field for Elf32_Dyn.  */
+#define DT_MIPS_RLD_VERSION  0x70000001 /* Runtime Linker Interface ID */
+#define DT_MIPS_TIME_STAMP   0x70000002 /* Timestamp */
+#define DT_MIPS_ICHECKSUM    0x70000003 /* Cksum of ext. str. and com. sizes */
+#define DT_MIPS_IVERSION     0x70000004 /* Version string (string tbl index) */
+#define DT_MIPS_FLAGS        0x70000005 /* Flags */
+#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Segment base address */
+#define DT_MIPS_CONFLICT     0x70000008 /* Adr of .conflict section */
+#define DT_MIPS_LIBLIST      0x70000009 /* Address of .liblist section */
+#define DT_MIPS_LOCAL_GOTNO  0x7000000a /* Number of local .GOT entries */
+#define DT_MIPS_CONFLICTNO   0x7000000b /* Number of .conflict entries */
+#define DT_MIPS_LIBLISTNO    0x70000010 /* Number of .liblist entries */
+#define DT_MIPS_SYMTABNO     0x70000011 /* Number of .dynsym entries */
+#define DT_MIPS_UNREFEXTNO   0x70000012 /* First external DYNSYM */
+#define DT_MIPS_GOTSYM       0x70000013 /* First GOT entry in .dynsym */
+#define DT_MIPS_HIPAGENO     0x70000014 /* Number of GOT page table entries */
+#define DT_MIPS_RLD_MAP      0x70000016 /* Address of debug map pointer */
+
+#define DT_PROCNUM (DT_MIPS_RLD_MAP - DT_LOPROC + 1)
+
+/*
+ * Legal values for e_flags field of Elf32_Ehdr.
+ */
+#define EF_MIPS_NOREORDER	0x00000001	/* .noreorder was used */
+#define EF_MIPS_PIC		0x00000002	/* Contains PIC code */
+#define EF_MIPS_CPIC		0x00000004	/* Uses PIC calling sequence */
+#define	EF_MIPS_ABI2		0x00000020	/* -n32 on Irix 6 */
+#define	EF_MIPS_32BITMODE	0x00000100	/* 64 bit in 32 bit mode... */
+#define EF_MIPS_ARCH		0xf0000000	/* MIPS architecture level */
+#define	E_MIPS_ARCH_1		0x00000000
+#define	E_MIPS_ARCH_2		0x10000000
+#define	E_MIPS_ARCH_3		0x20000000
+#define	E_MIPS_ARCH_4		0x30000000
+#define	EF_MIPS_ABI		0x0000f000	/* ABI level */
+#define	E_MIPS_ABI_NONE		0x00000000	/* ABI level not set */
+#define	E_MIPS_ABI_O32		0x00001000
+#define	E_MIPS_ABI_O64		0x00002000
+#define	E_MIPS_ABI_EABI32	0x00004000
+#define	E_MIPS_ABI_EABI64	0x00004000
+
+/*
+ * Mips special sections.
+ */
+#define	SHN_MIPS_ACOMMON	0xff00		/* Allocated common symbols */
+#define	SHN_MIPS_SCOMMON	0xff03		/* Small common symbols */
+#define	SHN_MIPS_SUNDEFINED	0xff04		/* Small undefined symbols */
+
+/*
+ * Legal values for sh_type field of Elf32_Shdr.
+ */
+#define	SHT_MIPS_LIBLIST  0x70000000	/* Shared objects used in link */
+#define	SHT_MIPS_CONFLICT 0x70000002	/* Conflicting symbols */
+#define	SHT_MIPS_GPTAB    0x70000003	/* Global data area sizes */
+#define	SHT_MIPS_UCODE    0x70000004	/* Reserved for SGI/MIPS compilers */
+#define	SHT_MIPS_DEBUG    0x70000005	/* MIPS ECOFF debugging information */
+#define	SHT_MIPS_REGINFO  0x70000006	/* Register usage information */
+
+/*
+ * Legal values for sh_flags field of Elf32_Shdr.
+ */
+#define	SHF_MIPS_GPREL	0x10000000	/* Must be part of global data area */
+
+#if 0
+/*
+ * Entries found in sections of type SHT_MIPS_GPTAB.
+ */
+typedef union {
+	struct {
+		Elf32_Word gt_current_g_value;	/* -G val used in compilation */
+		Elf32_Word gt_unused;	/* Not used */
+	} gt_header;			/* First entry in section */
+	struct {
+		Elf32_Word gt_g_value;	/* If this val were used for -G */
+		Elf32_Word gt_bytes;	/* This many bytes would be used */
+	} gt_entry;			/* Subsequent entries in section */
+} Elf32_gptab;
+
+/*
+ * Entry found in sections of type SHT_MIPS_REGINFO.
+ */
+typedef struct {
+	Elf32_Word	ri_gprmask;	/* General registers used */
+	Elf32_Word	ri_cprmask[4];	/* Coprocessor registers used */
+	Elf32_Sword	ri_gp_value;	/* $gp register value */
+} Elf32_RegInfo;
+#endif
+
+
+/*
+ * Mips relocations.
+ */
+
+#define	R_MIPS_NONE	0	/* No reloc */
+#define	R_MIPS_16	1	/* Direct 16 bit */
+#define	R_MIPS_32	2	/* Direct 32 bit */
+#define	R_MIPS_REL32	3	/* PC relative 32 bit */
+#define	R_MIPS_26	4	/* Direct 26 bit shifted */
+#define	R_MIPS_HI16	5	/* High 16 bit */
+#define	R_MIPS_LO16	6	/* Low 16 bit */
+#define	R_MIPS_GPREL16	7	/* GP relative 16 bit */
+#define	R_MIPS_LITERAL	8	/* 16 bit literal entry */
+#define	R_MIPS_GOT16	9	/* 16 bit GOT entry */
+#define	R_MIPS_PC16	10	/* PC relative 16 bit */
+#define	R_MIPS_CALL16	11	/* 16 bit GOT entry for function */
+#define	R_MIPS_GPREL32	12	/* GP relative 32 bit */
+
+#define	R_MIPS_64	18
+
+#define	R_MIPS_REL32_64	((R_MIPS_64 << 8) | R_MIPS_REL32)
+
+
+#endif	/* !_MIPS64_EXEC_H_ */
diff --git a/libc/arch-mips64/include/machine/regdef.h b/libc/arch-mips64/include/machine/regdef.h
new file mode 100644
index 0000000..3a7cd68
--- /dev/null
+++ b/libc/arch-mips64/include/machine/regdef.h
@@ -0,0 +1,99 @@
+/*	$OpenBSD: regdef.h,v 1.3 2005/08/07 07:29:44 miod Exp $	*/
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell. This file is derived from the MIPS RISC
+ * Architecture book by Gerry Kane.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)regdef.h	8.1 (Berkeley) 6/10/93
+ */
+#ifndef _MIPS_REGDEF_H_
+#define _MIPS_REGDEF_H_
+
+#if (_MIPS_SIM == _ABI64) && !defined(__mips_n64)
+#define __mips_n64 1
+#endif
+#if (_MIPS_SIM == _ABIN32) &&  !defined(__mips_n32)
+#define __mips_n32 1
+#endif
+
+#define zero	$0	/* always zero */
+#define AT	$at	/* assembler temp */
+#define v0	$2	/* return value */
+#define v1	$3
+#define a0	$4	/* argument registers */
+#define a1	$5
+#define a2	$6
+#define a3	$7
+#if defined(__mips_n32) || defined(__mips_n64)
+#define a4	$8	/* expanded register arguments */
+#define a5	$9
+#define a6	$10
+#define a7	$11
+#define ta0	$8	/* alias */
+#define ta1	$9
+#define ta2	$10
+#define ta3	$11
+#define t0	$12	/* temp registers (not saved across subroutine calls) */
+#define t1	$13
+#define t2	$14
+#define t3	$15
+#else
+#define t0	$8	/* temp registers (not saved across subroutine calls) */
+#define t1	$9
+#define t2	$10
+#define t3	$11
+#define t4	$12
+#define t5	$13
+#define t6	$14
+#define t7	$15
+#define ta0	$12	/* alias */
+#define ta1	$13
+#define ta2	$14
+#define ta3	$15
+#endif
+#define s0	$16	/* saved across subroutine calls (callee saved) */
+#define s1	$17
+#define s2	$18
+#define s3	$19
+#define s4	$20
+#define s5	$21
+#define s6	$22
+#define s7	$23
+#define t8	$24	/* two more temp registers */
+#define t9	$25
+#define k0	$26	/* kernel temporary */
+#define k1	$27
+#define gp	$28	/* global pointer */
+#define sp	$29	/* stack pointer */
+#define s8	$30	/* one more callee saved */
+#define ra	$31	/* return address */
+
+#endif /* !_MIPS_REGDEF_H_ */
diff --git a/libc/arch-mips64/include/machine/regnum.h b/libc/arch-mips64/include/machine/regnum.h
new file mode 100644
index 0000000..bfe1280
--- /dev/null
+++ b/libc/arch-mips64/include/machine/regnum.h
@@ -0,0 +1,119 @@
+/*	$OpenBSD: regnum.h,v 1.3 2004/08/10 20:28:13 deraadt Exp $ */
+
+/*
+ * Copyright (c) 2001-2002 Opsycon AB  (www.opsycon.se / www.opsycon.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MIPS64_REGNUM_H_
+#define _MIPS64_REGNUM_H_
+
+/*
+ * Location of the saved registers relative to ZERO.
+ * Usage is p->p_regs[XX].
+ */
+#define ZERO	0
+#define AST	1
+#define V0	2
+#define V1	3
+#define A0	4
+#define A1	5
+#define A2	6
+#define A3	7
+#define T0	8
+#define T1	9
+#define T2	10
+#define T3	11
+#define T4	12
+#define T5	13
+#define T6	14
+#define T7	15
+#define S0	16
+#define S1	17
+#define S2	18
+#define S3	19
+#define S4	20
+#define S5	21
+#define S6	22
+#define S7	23
+#define T8	24
+#define T9	25
+#define K0	26
+#define K1	27
+#define GP	28
+#define SP	29
+#define S8	30
+#define RA	31
+#define	SR	32
+#define	PS	SR	/* alias for SR */
+#define MULLO	33
+#define MULHI	34
+#define BADVADDR 35
+#define CAUSE	36
+#define	PC	37
+#define	IC	38
+#define	CPL	39
+
+#define	NUMSAVEREGS 40		/* Number of registers saved in trap */
+
+#define FPBASE	NUMSAVEREGS
+#define F0	(FPBASE+0)
+#define F1	(FPBASE+1)
+#define F2	(FPBASE+2)
+#define F3	(FPBASE+3)
+#define F4	(FPBASE+4)
+#define F5	(FPBASE+5)
+#define F6	(FPBASE+6)
+#define F7	(FPBASE+7)
+#define F8	(FPBASE+8)
+#define F9	(FPBASE+9)
+#define F10	(FPBASE+10)
+#define F11	(FPBASE+11)
+#define F12	(FPBASE+12)
+#define F13	(FPBASE+13)
+#define F14	(FPBASE+14)
+#define F15	(FPBASE+15)
+#define F16	(FPBASE+16)
+#define F17	(FPBASE+17)
+#define F18	(FPBASE+18)
+#define F19	(FPBASE+19)
+#define F20	(FPBASE+20)
+#define F21	(FPBASE+21)
+#define F22	(FPBASE+22)
+#define F23	(FPBASE+23)
+#define F24	(FPBASE+24)
+#define F25	(FPBASE+25)
+#define F26	(FPBASE+26)
+#define F27	(FPBASE+27)
+#define F28	(FPBASE+28)
+#define F29	(FPBASE+29)
+#define F30	(FPBASE+30)
+#define F31	(FPBASE+31)
+#define	FSR	(FPBASE+32)
+
+#define	NUMFPREGS 33
+
+#define	NREGS	(NUMSAVEREGS + NUMFPREGS)
+
+#endif /* !_MIPS64_REGNUM_H_ */
diff --git a/libc/arch-mips64/include/machine/setjmp.h b/libc/arch-mips64/include/machine/setjmp.h
new file mode 100644
index 0000000..55ba7be
--- /dev/null
+++ b/libc/arch-mips64/include/machine/setjmp.h
@@ -0,0 +1,10 @@
+/*	$OpenBSD: setjmp.h,v 1.2 2004/08/10 21:10:56 pefo Exp $	*/
+
+/* Public domain */
+
+#ifndef _MIPS_SETJMP_H_
+#define _MIPS_SETJMP_H_
+
+#define	_JBLEN	157		/* size, in longs, of a jmp_buf */
+
+#endif /* !_MIPS_SETJMP_H_ */
diff --git a/libc/arch-mips64/include/machine/signal.h b/libc/arch-mips64/include/machine/signal.h
new file mode 100644
index 0000000..b31715c
--- /dev/null
+++ b/libc/arch-mips64/include/machine/signal.h
@@ -0,0 +1,51 @@
+/*	$OpenBSD: signal.h,v 1.8 2006/01/09 18:18:37 millert Exp $	*/
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)signal.h	8.1 (Berkeley) 6/10/93
+ */
+
+#ifndef _MIPS_SIGNAL_H_
+#define _MIPS_SIGNAL_H_
+
+#define	SC_REGMASK	(0*REGSZ)
+#define	SC_STATUS	(1*REGSZ)
+#define	SC_PC		(2*REGSZ)
+#define	SC_REGS		(SC_PC+8)
+#define	SC_FPREGS	(SC_REGS+32*8)
+#define	SC_ACX		(SC_FPREGS+32*REGSZ_FP)
+#define	SC_USED_MATH	(SC_ACX+3*REGSZ)
+/* OpenBSD compatibility */
+#define	SC_MASK		SC_REGMASK
+#define	SC_FPUSED	SC_USED_MATH
+
+#endif	/* !_MIPS_SIGNAL_H_ */
diff --git a/libc/arch-mips64/mips64.mk b/libc/arch-mips64/mips64.mk
new file mode 100644
index 0000000..230cb26
--- /dev/null
+++ b/libc/arch-mips64/mips64.mk
@@ -0,0 +1,72 @@
+# mips64 specific configs
+
+libc_common_src_files_mips64 := \
+    bionic/memchr.c \
+    bionic/memcmp.c \
+    bionic/memmove.c \
+    bionic/memrchr.c \
+    bionic/strchr.cpp \
+    bionic/strnlen.c \
+    bionic/strrchr.cpp \
+    upstream-freebsd/lib/libc/string/wcscat.c \
+    upstream-freebsd/lib/libc/string/wcschr.c \
+    upstream-freebsd/lib/libc/string/wcscmp.c \
+    upstream-freebsd/lib/libc/string/wcscpy.c \
+    upstream-freebsd/lib/libc/string/wcslen.c \
+    upstream-freebsd/lib/libc/string/wcsrchr.c \
+    upstream-freebsd/lib/libc/string/wmemcmp.c \
+    upstream-freebsd/lib/libc/string/wmemmove.c \
+    upstream-openbsd/lib/libc/string/stpcpy.c \
+    upstream-openbsd/lib/libc/string/stpncpy.c \
+    upstream-openbsd/lib/libc/string/strcat.c \
+    upstream-openbsd/lib/libc/string/strcmp.c \
+    upstream-openbsd/lib/libc/string/strcpy.c \
+    upstream-openbsd/lib/libc/string/strlcat.c \
+    upstream-openbsd/lib/libc/string/strlcpy.c \
+    upstream-openbsd/lib/libc/string/strlen.c \
+    upstream-openbsd/lib/libc/string/strncat.c \
+    upstream-openbsd/lib/libc/string/strncmp.c \
+    upstream-openbsd/lib/libc/string/strncpy.c \
+
+# Fortify implementations of libc functions.
+libc_common_src_files_mips64 += \
+    bionic/__memcpy_chk.cpp \
+    bionic/__memset_chk.cpp \
+    bionic/__strcpy_chk.cpp \
+    bionic/__strcat_chk.cpp \
+
+
+##########################################
+### CPU specific source files
+libc_bionic_src_files_mips64 := \
+    arch-mips64/bionic/__bionic_clone.S \
+    arch-mips64/bionic/_exit_with_stack_teardown.S \
+    arch-mips64/bionic/__get_sp.S \
+    arch-mips64/bionic/_setjmp.S \
+    arch-mips64/bionic/setjmp.S \
+    arch-mips64/bionic/sigsetjmp.S \
+    arch-mips64/bionic/syscall.S \
+    arch-mips64/bionic/vfork.S \
+
+# FIXME TODO
+## libc_bionic_src_files_mips64 += arch-mips64/string/memcpy.S
+## libc_bionic_src_files_mips64 += arch-mips64/string/memset.S
+libc_bionic_src_files_mips64 += bionic/memcpy.cpp
+libc_bionic_src_files_mips64 += bionic/memset.c
+
+
+libc_crt_target_cflags_mips64 := \
+    $($(my_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \
+    -I$(LOCAL_PATH)/arch-mips64/include
+
+libc_crt_target_crtbegin_file_mips64 := \
+    $(LOCAL_PATH)/arch-mips64/bionic/crtbegin.c
+
+libc_crt_target_crtbegin_so_file_mips64 := \
+    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
+
+libc_crt_target_so_cflags_mips64 := \
+    -fPIC
+
+libc_crt_target_ldflags_mips64 := \
+    -melf64ltsmip
diff --git a/libc/arch-mips64/string/memcpy.S b/libc/arch-mips64/string/memcpy.S
new file mode 100644
index 0000000..dc91096
--- /dev/null
+++ b/libc/arch-mips64/string/memcpy.S
@@ -0,0 +1,423 @@
+/*
+ * Copyright (c) 2009
+ *      MIPS Technologies, Inc., California.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/************************************************************************
+ *
+ *  memcpy.S
+ *  Version: "043009"
+ *
+ ************************************************************************/
+
+
+/************************************************************************
+ *  Include files
+ ************************************************************************/
+
+#include <private/bionic_asm.h>
+
+
+/*
+ * This routine could be optimized for MIPS64. The current code only
+ * uses MIPS32 instructions.
+ */
+#if defined(__MIPSEB__)
+#  define LWHI	lwl		/* high part is left in big-endian	*/
+#  define SWHI	swl		/* high part is left in big-endian	*/
+#  define LWLO	lwr		/* low part is right in big-endian	*/
+#  define SWLO	swr		/* low part is right in big-endian	*/
+#endif
+
+#if defined(__MIPSEL__)
+#  define LWHI	lwr		/* high part is right in little-endian	*/
+#  define SWHI	swr		/* high part is right in little-endian	*/
+#  define LWLO	lwl		/* low part is left in big-endian	*/
+#  define SWLO	swl		/* low part is left in big-endian	*/
+#endif
+
+LEAF(memcpy,0)
+
+	.set	noreorder
+	.set	noat
+/*
+ * Below we handle the case where memcpy is called with overlapping src and dst.
+ * Although memcpy is not required to handle this case, some parts of Android like Skia
+ * rely on such usage. We call memmove to handle such cases.
+ */
+	subu	t0,a0,a1
+	sra	AT,t0,31
+	xor	t1,t0,AT
+	subu	t0,t1,AT
+	sltu	AT,t0,a2
+	beq	AT,zero,.Lmemcpy
+	 la	t9,memmove
+	jr	t9
+	 nop
+.Lmemcpy:
+	slti	AT,a2,8
+	bne	AT,zero,.Llast8
+	 move	v0,a0	# memcpy returns the dst pointer
+
+# Test if the src and dst are word-aligned, or can be made word-aligned
+	xor	t8,a1,a0
+	andi	t8,t8,0x3		# t8 is a0/a1 word-displacement
+
+	bne	t8,zero,.Lunaligned
+	 negu	a3,a0
+
+	andi	a3,a3,0x3	# we need to copy a3 bytes to make a0/a1 aligned
+	beq	a3,zero,.Lchk16w # when a3=0 then the dst (a0) is word-aligned
+	 subu	a2,a2,a3	# now a2 is the remining bytes count
+
+	LWHI	t8,0(a1)
+	addu	a1,a1,a3
+	SWHI	t8,0(a0)
+	addu	a0,a0,a3
+
+# Now the dst/src are mutually word-aligned with word-aligned addresses
+.Lchk16w:
+	andi	t8,a2,0x3f	# any whole 64-byte chunks?
+				# t8 is the byte count after 64-byte chunks
+
+	beq	a2,t8,.Lchk8w	# if a2==t8, no 64-byte chunks
+				# There will be at most 1 32-byte chunk after it
+	 subu	a3,a2,t8	# subtract from a2 the reminder
+                                # Here a3 counts bytes in 16w chunks
+	addu	a3,a0,a3	# Now a3 is the final dst after 64-byte chunks
+
+	addu	t0,a0,a2	# t0 is the "past the end" address
+
+# When in the loop we exercise "pref 30,x(a0)", the a0+x should not be past
+# the "t0-32" address
+# This means: for x=128 the last "safe" a0 address is "t0-160"
+# Alternatively, for x=64 the last "safe" a0 address is "t0-96"
+# In the current version we will use "pref 30,128(a0)", so "t0-160" is the limit
+	subu	t9,t0,160	# t9 is the "last safe pref 30,128(a0)" address
+
+	pref    0,0(a1)		# bring the first line of src, addr 0
+	pref    0,32(a1)	# bring the second line of src, addr 32
+	pref    0,64(a1)	# bring the third line of src, addr 64
+	pref	30,32(a0)	# safe, as we have at least 64 bytes ahead
+# In case the a0 > t9 don't use "pref 30" at all
+	sgtu	v1,a0,t9
+	bgtz	v1,.Lloop16w	# skip "pref 30,64(a0)" for too short arrays
+	 nop
+# otherwise, start with using pref30
+	pref	30,64(a0)
+.Lloop16w:
+	pref	0,96(a1)
+	lw	t0,0(a1)
+	bgtz	v1,.Lskip_pref30_96	# skip "pref 30,96(a0)"
+	 lw	t1,4(a1)
+	pref    30,96(a0)   # continue setting up the dest, addr 96
+.Lskip_pref30_96:
+	lw	t2,8(a1)
+	lw	t3,12(a1)
+	lw	t4,16(a1)
+	lw	t5,20(a1)
+	lw	t6,24(a1)
+	lw	t7,28(a1)
+        pref    0,128(a1)    # bring the next lines of src, addr 128
+
+	sw	t0,0(a0)
+	sw	t1,4(a0)
+	sw	t2,8(a0)
+	sw	t3,12(a0)
+	sw	t4,16(a0)
+	sw	t5,20(a0)
+	sw	t6,24(a0)
+	sw	t7,28(a0)
+
+	lw	t0,32(a1)
+	bgtz	v1,.Lskip_pref30_128	# skip "pref 30,128(a0)"
+	 lw	t1,36(a1)
+	pref    30,128(a0)   # continue setting up the dest, addr 128
+.Lskip_pref30_128:
+	lw	t2,40(a1)
+	lw	t3,44(a1)
+	lw	t4,48(a1)
+	lw	t5,52(a1)
+	lw	t6,56(a1)
+	lw	t7,60(a1)
+        pref    0, 160(a1)    # bring the next lines of src, addr 160
+
+	sw	t0,32(a0)
+	sw	t1,36(a0)
+	sw	t2,40(a0)
+	sw	t3,44(a0)
+	sw	t4,48(a0)
+	sw	t5,52(a0)
+	sw	t6,56(a0)
+	sw	t7,60(a0)
+
+	addiu	a0,a0,64	# adding 64 to dest
+	sgtu	v1,a0,t9
+	bne	a0,a3,.Lloop16w
+	 addiu	a1,a1,64	# adding 64 to src
+	move	a2,t8
+
+# Here we have src and dest word-aligned but less than 64-bytes to go
+
+.Lchk8w:
+	pref 0, 0x0(a1)
+	andi	t8,a2,0x1f	# is there a 32-byte chunk?
+				# the t8 is the reminder count past 32-bytes
+	beq	a2,t8,.Lchk1w	# when a2=t8, no 32-byte chunk
+	 nop
+
+	lw	t0,0(a1)
+	lw	t1,4(a1)
+	lw	t2,8(a1)
+	lw	t3,12(a1)
+	lw	t4,16(a1)
+	lw	t5,20(a1)
+	lw	t6,24(a1)
+	lw	t7,28(a1)
+	addiu	a1,a1,32
+
+	sw	t0,0(a0)
+	sw	t1,4(a0)
+	sw	t2,8(a0)
+	sw	t3,12(a0)
+	sw	t4,16(a0)
+	sw	t5,20(a0)
+	sw	t6,24(a0)
+	sw	t7,28(a0)
+	addiu	a0,a0,32
+
+.Lchk1w:
+	andi	a2,t8,0x3	# now a2 is the reminder past 1w chunks
+	beq	a2,t8,.Llast8
+	 subu	a3,t8,a2	# a3 is count of bytes in 1w chunks
+	addu	a3,a0,a3	# now a3 is the dst address past the 1w chunks
+
+# copying in words (4-byte chunks)
+.LwordCopy_loop:
+	lw	t3,0(a1)	# the first t3 may be equal t0 ... optimize?
+	addiu	a1,a1,4
+	addiu	a0,a0,4
+	bne	a0,a3,.LwordCopy_loop
+	 sw	t3,-4(a0)
+
+# For the last (<8) bytes
+.Llast8:
+	blez	a2,.Lleave
+	 addu	a3,a0,a2	# a3 is the last dst address
+.Llast8loop:
+	lb	v1,0(a1)
+	addiu	a1,a1,1
+	addiu	a0,a0,1
+	bne	a0,a3,.Llast8loop
+	 sb	v1,-1(a0)
+
+.Lleave:
+	j	ra
+	 nop
+
+#
+# UNALIGNED case
+#
+
+.Lunaligned:
+	# got here with a3="negu a0"
+	andi	a3,a3,0x3	# test if the a0 is word aligned
+	beqz	a3,.Lua_chk16w
+	 subu	a2,a2,a3	# bytes left after initial a3 bytes
+
+	LWHI	v1,0(a1)
+	LWLO	v1,3(a1)
+	addu	a1,a1,a3	# a3 may be here 1, 2 or 3
+	SWHI	v1,0(a0)
+	addu	a0,a0,a3	# below the dst will be word aligned (NOTE1)
+
+.Lua_chk16w:
+	andi	t8,a2,0x3f	# any whole 64-byte chunks?
+				# t8 is the byte count after 64-byte chunks
+	beq	a2,t8,.Lua_chk8w # if a2==t8, no 64-byte chunks
+				# There will be at most 1 32-byte chunk after it
+	 subu	a3,a2,t8	# subtract from a2 the reminder
+                                # Here a3 counts bytes in 16w chunks
+	addu	a3,a0,a3	# Now a3 is the final dst after 64-byte chunks
+
+	addu	t0,a0,a2	# t0 is the "past the end" address
+
+	subu	t9,t0,160	# t9 is the "last safe pref 30,128(a0)" address
+
+	pref    0,0(a1)		# bring the first line of src, addr 0
+	pref    0,32(a1)	# bring the second line of src, addr 32
+	pref    0,64(a1)	# bring the third line of src, addr 64
+	pref	30,32(a0)	# safe, as we have at least 64 bytes ahead
+# In case the a0 > t9 don't use "pref 30" at all
+	sgtu	v1,a0,t9
+	bgtz	v1,.Lua_loop16w	# skip "pref 30,64(a0)" for too short arrays
+	 nop
+# otherwise, start with using pref30
+	pref	30,64(a0)
+.Lua_loop16w:
+	pref	0,96(a1)
+	LWHI	t0,0(a1)
+	LWLO	t0,3(a1)
+	LWHI	t1,4(a1)
+	bgtz	v1,.Lua_skip_pref30_96
+	 LWLO	t1,7(a1)
+	pref    30,96(a0)   # continue setting up the dest, addr 96
+.Lua_skip_pref30_96:
+	LWHI	t2,8(a1)
+	LWLO	t2,11(a1)
+	LWHI	t3,12(a1)
+	LWLO	t3,15(a1)
+	LWHI	t4,16(a1)
+	LWLO	t4,19(a1)
+	LWHI	t5,20(a1)
+	LWLO	t5,23(a1)
+	LWHI	t6,24(a1)
+	LWLO	t6,27(a1)
+	LWHI	t7,28(a1)
+	LWLO	t7,31(a1)
+        pref    0,128(a1)    # bring the next lines of src, addr 128
+
+	sw	t0,0(a0)
+	sw	t1,4(a0)
+	sw	t2,8(a0)
+	sw	t3,12(a0)
+	sw	t4,16(a0)
+	sw	t5,20(a0)
+	sw	t6,24(a0)
+	sw	t7,28(a0)
+
+	LWHI	t0,32(a1)
+	LWLO	t0,35(a1)
+	LWHI	t1,36(a1)
+	bgtz	v1,.Lua_skip_pref30_128
+	LWLO	t1,39(a1)
+	pref    30,128(a0)   # continue setting up the dest, addr 128
+.Lua_skip_pref30_128:
+	LWHI	t2,40(a1)
+	LWLO	t2,43(a1)
+	LWHI	t3,44(a1)
+	LWLO	t3,47(a1)
+	LWHI	t4,48(a1)
+	LWLO	t4,51(a1)
+	LWHI	t5,52(a1)
+	LWLO	t5,55(a1)
+	LWHI	t6,56(a1)
+	LWLO	t6,59(a1)
+	LWHI	t7,60(a1)
+	LWLO	t7,63(a1)
+        pref    0, 160(a1)    # bring the next lines of src, addr 160
+
+	sw	t0,32(a0)
+	sw	t1,36(a0)
+	sw	t2,40(a0)
+	sw	t3,44(a0)
+	sw	t4,48(a0)
+	sw	t5,52(a0)
+	sw	t6,56(a0)
+	sw	t7,60(a0)
+
+	addiu	a0,a0,64	# adding 64 to dest
+	sgtu	v1,a0,t9
+	bne	a0,a3,.Lua_loop16w
+	 addiu	a1,a1,64	# adding 64 to src
+	move	a2,t8
+
+# Here we have src and dest word-aligned but less than 64-bytes to go
+
+.Lua_chk8w:
+	pref 0, 0x0(a1)
+	andi	t8,a2,0x1f	# is there a 32-byte chunk?
+				# the t8 is the reminder count
+	beq	a2,t8,.Lua_chk1w # when a2=t8, no 32-byte chunk
+	 nop
+
+	LWHI	t0,0(a1)
+	LWLO	t0,3(a1)
+	LWHI	t1,4(a1)
+	LWLO	t1,7(a1)
+	LWHI	t2,8(a1)
+	LWLO	t2,11(a1)
+	LWHI	t3,12(a1)
+	LWLO	t3,15(a1)
+	LWHI	t4,16(a1)
+	LWLO	t4,19(a1)
+	LWHI	t5,20(a1)
+	LWLO	t5,23(a1)
+	LWHI	t6,24(a1)
+	LWLO	t6,27(a1)
+	LWHI	t7,28(a1)
+	LWLO	t7,31(a1)
+	addiu	a1,a1,32
+
+	sw	t0,0(a0)
+	sw	t1,4(a0)
+	sw	t2,8(a0)
+	sw	t3,12(a0)
+	sw	t4,16(a0)
+	sw	t5,20(a0)
+	sw	t6,24(a0)
+	sw	t7,28(a0)
+	addiu	a0,a0,32
+
+.Lua_chk1w:
+	andi	a2,t8,0x3	# now a2 is the reminder past 1w chunks
+	beq	a2,t8,.Lua_smallCopy
+	 subu	a3,t8,a2	# a3 is count of bytes in 1w chunks
+	addu	a3,a0,a3	# now a3 is the dst address past the 1w chunks
+
+# copying in words (4-byte chunks)
+.Lua_wordCopy_loop:
+	LWHI	v1,0(a1)
+	LWLO	v1,3(a1)
+	addiu	a1,a1,4
+	addiu	a0,a0,4		# note: dst=a0 is word aligned here, see NOTE1
+	bne	a0,a3,.Lua_wordCopy_loop
+	 sw	v1,-4(a0)
+
+# Now less than 4 bytes (value in a2) left to copy
+.Lua_smallCopy:
+	beqz	a2,.Lleave
+	addu	a3,a0,a2	# a3 is the last dst address
+.Lua_smallCopy_loop:
+	lb	v1,0(a1)
+	addiu	a1,a1,1
+	addiu	a0,a0,1
+	bne	a0,a3,.Lua_smallCopy_loop
+	 sb	v1,-1(a0)
+
+	j	ra
+	 nop
+
+	.set	at
+	.set	reorder
+
+END(memcpy)
+
+
+/************************************************************************
+ *  Implementation : Static functions
+ ************************************************************************/
diff --git a/libc/arch-mips64/string/memset.S b/libc/arch-mips64/string/memset.S
new file mode 100644
index 0000000..3e630ca
--- /dev/null
+++ b/libc/arch-mips64/string/memset.S
@@ -0,0 +1,322 @@
+/*
+ * Copyright (c) 2009
+ *      MIPS Technologies, Inc., California.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/************************************************************************
+ *
+ *  memset.S, version "64h" with 1 cache line horizon for "pref 30" and 14 nops
+ *  Version: "043009"
+ *
+ ************************************************************************/
+
+
+/************************************************************************
+ *  Include files
+ ************************************************************************/
+
+#include <private/bionic_asm.h>
+
+/*
+ * This routine could be optimized for MIPS64. The current code only
+ * uses MIPS32 instructions.
+ */
+
+#if defined(__MIPSEB__)
+#  define SWHI	swl		/* high part is left in big-endian	*/
+#  define SWLO	swr		/* low part is right in big-endian	*/
+#endif
+
+#if defined(__MIPSEL__)
+#  define SWHI	swr		/* high part is right in little-endian	*/
+#  define SWLO	swl		/* low part is left in little-endian	*/
+#endif
+
+#if !(defined(XGPROF) || defined(XPROF))
+#undef SETUP_GP
+#define SETUP_GP
+#endif
+
+#ifdef NDEBUG
+#define DBG #
+#else
+#define DBG
+#endif
+
+/*
+ * void _memset16(uint16_t* dst, uint16_t value, size_t size);
+ */
+
+LEAF(_memset16,0)
+	.set noreorder
+DBG	/* Check parameters */
+DBG	andi	t0,a0,1			# a0 must be halfword aligned
+DBG	tne	t0,zero
+DBG	andi	t2,a2,1			# a2 must be even
+DBG	tne	t2,zero
+
+#ifdef FIXARGS
+	# ensure count is even
+#if (__mips==32) && (__mips_isa_rev>=2)
+	ins	a2,zero,0,1
+#else
+	ori	a2,1
+	xori	a2,1
+#endif
+#endif
+
+#if (__mips==32) && (__mips_isa_rev>=2)
+	ins	a1,a1,16,16
+#else
+	andi	a1,0xffff
+	sll	t3,a1,16
+	or	a1,t3
+#endif
+
+	beqz	a2,.Ldone
+	 andi	t1,a0,2
+	beqz	t1,.Lalignok
+	 addu	t0,a0,a2		# t0 is the "past the end" address
+	sh	a1,0(a0)		# store one halfword to get aligned
+	addu	a0,2
+	subu	a2,2
+.Lalignok:
+	slti	t1,a2,4			# .Laligned for 4 or more bytes
+	beqz	t1,.Laligned
+	 sne	t1,a2,2			# one more halfword?
+	bnez	t1,.Ldone
+	 nop
+	sh	a1,0(a0)
+.Ldone:
+	j	ra
+	 nop
+	.set reorder
+END(_memset16)
+
+/*
+ * void _memset32(uint32_t* dst, uint32_t value, size_t size);
+ */
+
+LEAF(_memset32,0)
+	.set noreorder
+DBG	/* Check parameters */
+DBG	andi	t0,a0,3			# a0 must be word aligned
+DBG	tne	t0,zero
+DBG	andi	t2,a2,3			# a2 must be a multiple of 4 bytes
+DBG	tne	t2,zero
+
+#ifdef FIXARGS
+	# ensure count is a multiple of 4
+#if (__mips==32) && (__mips_isa_rev>=2)
+	ins	$a2,$0,0,2
+#else
+	ori	a2,3
+	xori	a2,3
+#endif
+#endif
+
+	bnez	a2,.Laligned		# any work to do?
+	 addu	t0,a0,a2		# t0 is the "past the end" address
+
+	j	ra
+	 nop
+	.set reorder
+END(_memset32)
+
+LEAF(memset,0)
+
+	.set	noreorder
+	.set	noat
+
+	addu	t0,a0,a2		# t0 is the "past the end" address
+	slti	AT,a2,4			# is a2 less than 4?
+	bne	AT,zero,.Llast4		# if yes, go to last4
+	 move	v0,a0			# memset returns the dst pointer
+
+	beq	a1,zero,.Lset0
+	 subu	v1,zero,a0
+
+	# smear byte into 32 bit word
+#if (__mips==32) && (__mips_isa_rev>=2)
+	ins     a1, a1, 8, 8        # Replicate fill byte into half-word.
+	ins     a1, a1, 16, 16      # Replicate fill byte into word.
+#else
+	and	a1,0xff
+	sll	AT,a1,8
+	or	a1,AT
+	sll	AT,a1,16
+	or	a1,AT
+#endif
+
+.Lset0:
+	andi	v1,v1,0x3		# word-unaligned address?
+	beq	v1,zero,.Laligned	# v1 is the unalignment count
+	 subu	a2,a2,v1
+	SWHI	a1,0(a0)
+	addu	a0,a0,v1
+
+# Here we have the "word-aligned" a0 (until the "last4")
+.Laligned:
+	andi	t8,a2,0x3f	# any 64-byte chunks?
+				# t8 is the byte count past 64-byte chunks
+	beq	a2,t8,.Lchk8w	# when a2==t8, no 64-byte chunks
+				# There will be at most 1 32-byte chunk then
+	 subu	a3,a2,t8	# subtract from a2 the reminder
+				# Here a3 counts bytes in 16w chunks
+	addu	a3,a0,a3	# Now a3 is the final dst after 64-byte chunks
+
+# Find out, if there are any 64-byte chunks after which will be still at least
+# 96 bytes left. The value "96" is calculated as needed buffer for
+# "pref 30,64(a0)" prefetch, which can be used as "pref 30,0(a0)" after
+# incrementing "a0" by 64.
+# For "a2" below 160 there will be no such "pref 30 safe" 64-byte chunk.
+#
+	sltiu	v1,a2,160
+	bgtz	v1,.Lloop16w_nopref30	# skip "pref 30,0(a0)"
+	 subu	t7,a2,96	# subtract "pref 30 unsafe" region
+		# below we have at least 1 64-byte chunk which is "pref 30 safe"
+	andi	t6,t7,0x3f	# t6 is past "64-byte safe chunks" reminder
+	subu	t5,t7,t6	# subtract from t7 the reminder
+				# Here t5 counts bytes in 16w "safe" chunks
+	addu	t4,a0,t5	# Now t4 is the dst after 64-byte "safe" chunks
+
+# Don't use "pref 30,0(a0)" for a0 in a "middle" of a cache line
+#	pref	30,0(a0)
+# Here we are in the region, where it is safe to use "pref 30,64(a0)"
+.Lloop16w:
+	addiu	a0,a0,64
+	pref	30,-32(a0)	# continue setting up the dest, addr 64-32
+	sw	a1,-64(a0)
+	sw	a1,-60(a0)
+	sw	a1,-56(a0)
+	sw	a1,-52(a0)
+	sw	a1,-48(a0)
+	sw	a1,-44(a0)
+	sw	a1,-40(a0)
+	sw	a1,-36(a0)
+	nop
+	nop			# the extra nop instructions help to balance
+	nop			# cycles needed for "store" + "fill" + "evict"
+	nop			# For 64byte store there are needed 8 fill
+	nop			# and 8 evict cycles, i.e. at least 32 instr.
+	nop
+	nop
+	pref	30,0(a0)	# continue setting up the dest, addr 64-0
+	sw	a1,-32(a0)
+	sw	a1,-28(a0)
+	sw	a1,-24(a0)
+	sw	a1,-20(a0)
+	sw	a1,-16(a0)
+	sw	a1,-12(a0)
+	sw	a1,-8(a0)
+	sw	a1,-4(a0)
+	nop
+	nop
+	nop
+	nop			# NOTE: adding 14 nop-s instead of 12 nop-s
+	nop			# gives better results for "fast" memory
+	nop
+	bne	a0,t4,.Lloop16w
+	 nop
+
+	beq	a0,a3,.Lchk8w	# maybe no more 64-byte chunks?
+	 nop			# this "delayed slot" is useless ...
+
+.Lloop16w_nopref30:	# there could be up to 3 "64-byte nopref30" chunks
+	addiu	a0,a0,64
+	sw	a1,-64(a0)
+	sw	a1,-60(a0)
+	sw	a1,-56(a0)
+	sw	a1,-52(a0)
+	sw	a1,-48(a0)
+	sw	a1,-44(a0)
+	sw	a1,-40(a0)
+	sw	a1,-36(a0)
+	sw	a1,-32(a0)
+	sw	a1,-28(a0)
+	sw	a1,-24(a0)
+	sw	a1,-20(a0)
+	sw	a1,-16(a0)
+	sw	a1,-12(a0)
+	sw	a1,-8(a0)
+	bne	a0,a3,.Lloop16w_nopref30
+	 sw	a1,-4(a0)
+
+.Lchk8w:		# t8 here is the byte count past 64-byte chunks
+
+	andi	t7,t8,0x1f	# is there a 32-byte chunk?
+				# the t7 is the reminder count past 32-bytes
+	beq	t8,t7,.Lchk1w	# when t8==t7, no 32-byte chunk
+	 move	a2,t7
+
+	sw	a1,0(a0)
+	sw	a1,4(a0)
+	sw	a1,8(a0)
+	sw	a1,12(a0)
+	sw	a1,16(a0)
+	sw	a1,20(a0)
+	sw	a1,24(a0)
+	sw	a1,28(a0)
+	addiu	a0,a0,32
+
+.Lchk1w:
+	andi	t8,a2,0x3	# now t8 is the reminder past 1w chunks
+	beq	a2,t8,.Llast4aligned
+	 subu	a3,a2,t8	# a3 is the count of bytes in 1w chunks
+	addu	a3,a0,a3	# now a3 is the dst address past the 1w chunks
+
+# copying in words (4-byte chunks)
+.LwordCopy_loop:
+	addiu	a0,a0,4
+	bne	a0,a3,.LwordCopy_loop
+	 sw	a1,-4(a0)
+
+# store last 0-3 bytes
+# this will repeat the last store if the memset finishes on a word boundary
+.Llast4aligned:
+	j	ra
+	 SWLO	a1,-1(t0)
+
+.Llast4:
+	beq	a0,t0,.Llast4e
+.Llast4l:
+	 addiu	a0,a0,1
+	bne	a0,t0,.Llast4l
+	 sb	a1,-1(a0)
+.Llast4e:
+	j	ra
+	 nop
+
+	.set	at
+	.set	reorder
+
+END(memset)
+
+
+/************************************************************************
+ *  Implementation : Static functions
+ ************************************************************************/
diff --git a/libc/arch-mips64/string/mips-string-ops.h b/libc/arch-mips64/string/mips-string-ops.h
new file mode 100644
index 0000000..e635ba1
--- /dev/null
+++ b/libc/arch-mips64/string/mips-string-ops.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2010 MIPS Technologies, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *        notice, this list of conditions and the following disclaimer.
+ *      * Redistributions in binary form must reproduce the above copyright
+ *        notice, this list of conditions and the following disclaimer
+ *        in the documentation and/or other materials provided with
+ *        the distribution.
+ *      * Neither the name of MIPS Technologies Inc. nor the names of its
+ *        contributors may be used to endorse or promote products derived
+ *        from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MIPS_STRING_OPS_H
+#define __MIPS_STRING_OPS_H
+    /* This definition of the byte bitfields uses the
+       assumption that the layout of the bitfields is
+       equivalent to the layout in memory.  Generally,
+       for the MIPS ABIs, this is true. If you compile
+       the strcmp.c file with -DSMOKE_TEST_NEW_STRCMP,
+       this assumption will be tested.
+
+       Also, regardless of char signedness, ANSI C dictates that
+       strcmp() treats each character as unsigned char.  For
+       strlen and the like, signedness doesn't matter.
+
+       Also, this code assumes that there are 8-bits per 'char'.  */
+
+#if __mips64
+typedef struct bits
+{
+  unsigned long B0:8, B1:8, B2:8, B3:8, B4:8, B5:8, B6:8, B7:8;
+} bits_t;
+#else
+typedef struct bits
+{
+  unsigned long B0:8, B1:8, B2:8, B3:8;
+} bits_t;
+#endif
+
+#ifndef _ULW
+    /* for MIPS GCC, there is no unaligned builtins - so this code forces
+       the compiler to treat the pointer access as unaligned.  */
+struct ulw
+{
+  unsigned long b;
+} __attribute__ ((packed));
+
+#define _ULW(__x) ((struct ulw *) ((char *)(&__x)))->b;
+#endif
+
+/* This union assumes that small structures can be in registers.  If
+   not, then memory accesses will be done - not optimal, but ok.  */
+typedef union
+{
+  unsigned long v;
+  bits_t b;
+} bitfields_t;
+
+#ifndef detect_zero
+/* __mips_dsp, __mips_dspr2, and __mips64 are predefined by
+   the compiler, based on command line options.  */
+#if (__mips_dsp || __mips_dspr2) && !__mips64
+#define __mips_using_dsp 1
+
+/* DSP 4-lane (8 unsigned bits per line) subtract and saturate
+ * Intrinsic operation. How this works:
+ *     Given a 4-byte string of "ABC\0", subtract this as
+ *     an unsigned integer from 0x01010101:
+ *	   0x01010101
+ *       - 0x41424300
+ *        -----------
+ (         0xbfbebe01 <-- answer without saturation
+ *	   0x00000001 <-- answer with saturation
+ * When this 4-lane vector is treated as an unsigned int value,
+ * a non-zero answer indicates the presence of a zero in the
+ * original 4-byte argument.  */
+
+typedef signed char v4i8 __attribute__ ((vector_size (4)));
+
+#define detect_zero(__x,__y,__01s,__80s)\
+       ((unsigned) __builtin_mips_subu_s_qb((v4i8) __01s,(v4i8) __x))
+
+    /* sets all 4 lanes to requested byte.  */
+#define set_byte_lanes(__x) ((unsigned) __builtin_mips_repl_qb(__x))
+
+    /* sets all 4 lanes to 0x01.  */
+#define def_and_set_01(__x) unsigned long __x = (unsigned) __builtin_mips_repl_qb(0x01)
+
+    /* sets all 4 lanes to 0x80. Not needed when subu_s.qb used. */
+#define def_and_set_80(__x) /* do nothing */
+
+#else
+    /* this version, originally published in the 80's, uses
+       a reverse-carry-set like determination of the zero byte.
+       The steps are, for __x = 0x31ff0001:
+       __x - _01s = 0x30fdff00
+       ~__x = 0xce00fffe
+       ((__x - _01s) & ~__x) = 0x0000ff00
+       x & _80s = 0x00008000 <- byte 3 was zero
+       Some implementaions naively assume that characters are
+       always 7-bit unsigned ASCII. With that assumption, the
+       "& ~x" is usually discarded. Since character strings
+       are 8-bit, the and is needed to catch the case of
+       a false positive when the byte is 0x80. */
+
+#define detect_zero(__x,__y,_01s,_80s)\
+	((unsigned) (((__x) - _01s) & ~(__x)) & _80s)
+
+#if __mips64
+#define def_and_set_80(__x) unsigned long __x =  0x8080808080808080ul
+#define def_and_set_01(__x)  unsigned long __x = 0x0101010101010101ul
+#else
+#define def_and_set_80(__x) unsigned long __x = 0x80808080ul
+#define def_and_set_01(__x) unsigned long __x = 0x01010101ul
+#endif
+
+#endif
+#endif
+
+/* dealing with 'void *' conversions without using extra variables. */
+#define get_byte(__x,__idx) (((unsigned char *) (__x))[__idx])
+#define set_byte(__x,__idx,__fill) ((unsigned char *) (__x))[__idx] = (__fill)
+#define get_word(__x,__idx) (((unsigned long *) (__x))[__idx])
+#define set_word(__x,__idx,__fill) ((unsigned long *) (__x))[__idx] = (__fill)
+#define inc_ptr_as(__type,__x,__inc) __x = (void *) (((__type) __x) + (__inc))
+#define cvt_ptr_to(__type,__x) ((__type) (__x))
+
+#endif
diff --git a/libc/arch-mips64/string/mips_strlen.c b/libc/arch-mips64/string/mips_strlen.c
new file mode 100644
index 0000000..37e5865
--- /dev/null
+++ b/libc/arch-mips64/string/mips_strlen.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2010 MIPS Technologies, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *        notice, this list of conditions and the following disclaimer.
+ *      * Redistributions in binary form must reproduce the above copyright
+ *        notice, this list of conditions and the following disclaimer
+ *        in the documentation and/or other materials provided with
+ *        the distribution.
+ *      * Neither the name of MIPS Technologies Inc. nor the names of its
+ *        contributors may be used to endorse or promote products derived
+ *        from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include "mips-string-ops.h"
+
+#define do_strlen_word(__av) {\
+    if (detect_zero(x,x,_01s,_80s)) break;\
+    x = __av;\
+    cnt += sizeof (unsigned);\
+    }
+
+#define do_strlen_byte(__x) {\
+  if ((bx.b.B##__x) == 0) break;\
+  ++cnt;\
+  }
+
+#if SMOKE_TEST_MIPS_STRLEN
+#define strlen my_strlen
+#endif
+
+size_t
+strlen (const char *_a)
+{
+  int cnt = 0;
+  unsigned long x;
+
+  /* align the string to word boundary so we can do word at a time.  */
+  if ((cvt_ptr_to (unsigned long, _a) & (sizeof (unsigned long) - 1)) != 0)
+    {
+      if ((cvt_ptr_to (unsigned long, _a) & 1) != 0)
+	{
+	  if (get_byte (_a, 0) == 0)
+	    return cnt;
+	  /* set bit 1 so 2-bytes are checked and incremented. */
+	  inc_ptr_as (char *, _a, 1);
+	  ++cnt;
+	}
+      if ((cvt_ptr_to (unsigned long, _a) & 2) != 0)
+	{
+	  if (get_byte (_a, 0) == 0)
+	    return cnt + 0;
+	  if (get_byte (_a, 1) == 0)
+	    return cnt + 1;
+	  inc_ptr_as (char *, _a, 2);
+	  cnt += 2;
+	}
+    }
+
+#if __mips64
+#error strlen: mips64 check for 4-byte alignment not implemented.
+#endif
+
+  if (1)
+    {
+      def_and_set_01 (_01s);
+      def_and_set_80 (_80s);
+
+      /* as advantagous as it is to performance, this code cannot pre-load
+         the following word, nor can it prefetch the next line at the start
+         of the loop since the string can be at the end of a page with the
+         following page unmapped. There are tests in the suite to catch
+         any attempt to go beyond the current word. */
+      x = get_word (_a, 0);
+      while (1)
+	{
+	  /* doing 8 words should cover most strings.  */
+	  do_strlen_word (get_word (_a, 1));
+	  do_strlen_word (get_word (_a, 2));
+	  do_strlen_word (get_word (_a, 3));
+	  do_strlen_word (get_word (_a, 4));
+	  do_strlen_word (get_word (_a, 5));
+	  do_strlen_word (get_word (_a, 6));
+	  do_strlen_word (get_word (_a, 7));
+	  do_strlen_word (get_word (_a, 8));
+	  inc_ptr_as (unsigned long*, _a, 8);
+	}
+    }
+  while (1)
+    {
+      /* pull apart the last word processed and find the zero.  */
+      bitfields_t bx;
+      bx.v = x;
+#if __mips64
+      do_strlen_byte (0);
+      do_strlen_byte (1);
+      do_strlen_byte (2);
+      do_strlen_byte (3);
+      do_strlen_byte (4);
+      do_strlen_byte (5);
+      do_strlen_byte (6);
+#else
+      do_strlen_byte (0);
+      do_strlen_byte (1);
+      do_strlen_byte (2);
+#endif
+      /* last byte is zero */
+      break;
+    }
+  return cnt;
+}
+
+#undef do_strlen_byte
+#undef do_strlen_word
+
+#if SMOKE_TEST_MIPS_STRLEN
+#include <stdio.h>
+char str1[] = "DHRYSTONE PROGRAM, 1'ST STRING";
+char str2[] = "DHRYSTONE PROGRAM, 2'ST STRING";
+
+char str3[] = "another string";
+char str4[] = "another";
+
+char str5[] = "somes tring";
+char str6[] = "somes_tring";
+
+char str7[16], str8[16];
+
+static char *
+chk (unsigned long mine, unsigned long libs, int *errors)
+{
+  static char answer[1024];
+  char *result = mine == libs ? "PASS" : "FAIL";
+  sprintf (answer, "new_strlen=%d: lib_strlen=%d: %s!", mine, libs, result);
+  if (mine != libs)
+    (*errors)++;
+  return answer;
+}
+
+int
+main (int argc, char **argv)
+{
+  int errors = 0;
+  /* set -1 in one position */
+  str6[5] = 0xff;
+  /* set zero in same position with junk in following 3 */
+  str7[0] = str8[0] = 0;
+  str7[1] = 0xff;
+  str7[2] = 'a';
+  str7[3] = 2;
+  str8[1] = 's';
+  str8[2] = -2;
+  str8[3] = 0;
+
+  fprintf (stderr, "========== mips_strlen%s test...\n",
+	   argv[0] ? argv[0] : "unknown strlen");
+#define P(__x,__y) {\
+    int a = my_strlen(__x + __y);\
+    int b = (strlen)(__x + __y) /* library version */;\
+    fprintf(stderr,"%s+%d: %s\n",#__x,__y,chk(a,b,&errors));\
+    }
+
+  P (str1, 0);
+  P (str1, 1);
+  P (str1, 2);
+  P (str1, 3);
+
+  P (str2, 0);
+  P (str2, 1);
+  P (str2, 2);
+  P (str2, 3);
+
+  P (str3, 0);
+  P (str3, 1);
+  P (str3, 2);
+  P (str3, 3);
+
+  P (str4, 0);
+  P (str4, 1);
+  P (str4, 2);
+  P (str4, 3);
+
+  P (str5, 0);
+  P (str5, 1);
+  P (str5, 2);
+  P (str5, 3);
+
+  P (str6, 0);
+  P (str6, 1);
+  P (str6, 2);
+  P (str6, 3);
+
+  P (str7, 0);
+  P (str7, 1);
+  P (str7, 2);
+  P (str7, 3);
+
+  P (str8, 0);
+  P (str8, 1);
+  P (str8, 2);
+  P (str8, 3);
+
+  return errors;
+}
+#endif
diff --git a/libc/arch-mips64/syscalls/__accept4.S b/libc/arch-mips64/syscalls/__accept4.S
new file mode 100644
index 0000000..ed9b6c7
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__accept4.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__accept4)
+    .set push
+    .set noreorder
+    li v0, __NR_accept4
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__accept4)
+.hidden __accept4
diff --git a/libc/arch-mips64/syscalls/__brk.S b/libc/arch-mips64/syscalls/__brk.S
new file mode 100644
index 0000000..e1f89c7
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__brk.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__brk)
+    .set push
+    .set noreorder
+    li v0, __NR_brk
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__brk)
+.hidden __brk
diff --git a/libc/arch-mips64/syscalls/__connect.S b/libc/arch-mips64/syscalls/__connect.S
new file mode 100644
index 0000000..8c44464
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__connect.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__connect)
+    .set push
+    .set noreorder
+    li v0, __NR_connect
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__connect)
+.hidden __connect
diff --git a/libc/arch-mips64/syscalls/__epoll_pwait.S b/libc/arch-mips64/syscalls/__epoll_pwait.S
new file mode 100644
index 0000000..5dfb380
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__epoll_pwait.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__epoll_pwait)
+    .set push
+    .set noreorder
+    li v0, __NR_epoll_pwait
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__epoll_pwait)
+.hidden __epoll_pwait
diff --git a/libc/arch-mips64/syscalls/__exit.S b/libc/arch-mips64/syscalls/__exit.S
new file mode 100644
index 0000000..2d5e03d
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__exit.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__exit)
+    .set push
+    .set noreorder
+    li v0, __NR_exit
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__exit)
+.hidden __exit
diff --git a/libc/arch-mips64/syscalls/__fadvise64.S b/libc/arch-mips64/syscalls/__fadvise64.S
new file mode 100644
index 0000000..90aceb0
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__fadvise64.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__fadvise64)
+    .set push
+    .set noreorder
+    li v0, __NR_fadvise64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__fadvise64)
+.hidden __fadvise64
diff --git a/libc/arch-mips64/syscalls/__getcpu.S b/libc/arch-mips64/syscalls/__getcpu.S
new file mode 100644
index 0000000..a16c21e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__getcpu.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getcpu)
+    .set push
+    .set noreorder
+    li v0, __NR_getcpu
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__getcpu)
+.hidden __getcpu
diff --git a/libc/arch-mips64/syscalls/__getcwd.S b/libc/arch-mips64/syscalls/__getcwd.S
new file mode 100644
index 0000000..53eeb68
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__getcwd.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getcwd)
+    .set push
+    .set noreorder
+    li v0, __NR_getcwd
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__getcwd)
+.hidden __getcwd
diff --git a/libc/arch-mips64/syscalls/__getdents64.S b/libc/arch-mips64/syscalls/__getdents64.S
new file mode 100644
index 0000000..3720b8e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__getdents64.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getdents64)
+    .set push
+    .set noreorder
+    li v0, __NR_getdents64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__getdents64)
+.hidden __getdents64
diff --git a/libc/arch-mips64/syscalls/__getpid.S b/libc/arch-mips64/syscalls/__getpid.S
new file mode 100644
index 0000000..6d5d926
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__getpid.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getpid)
+    .set push
+    .set noreorder
+    li v0, __NR_getpid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__getpid)
+.hidden __getpid
diff --git a/libc/arch-mips64/syscalls/__getpriority.S b/libc/arch-mips64/syscalls/__getpriority.S
new file mode 100644
index 0000000..19327ab
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__getpriority.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getpriority)
+    .set push
+    .set noreorder
+    li v0, __NR_getpriority
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__getpriority)
+.hidden __getpriority
diff --git a/libc/arch-mips64/syscalls/__ioctl.S b/libc/arch-mips64/syscalls/__ioctl.S
new file mode 100644
index 0000000..7fad0d1
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__ioctl.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__ioctl)
+    .set push
+    .set noreorder
+    li v0, __NR_ioctl
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__ioctl)
+.hidden __ioctl
diff --git a/libc/arch-mips64/syscalls/__openat.S b/libc/arch-mips64/syscalls/__openat.S
new file mode 100644
index 0000000..d3ac13a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__openat.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__openat)
+    .set push
+    .set noreorder
+    li v0, __NR_openat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__openat)
+.hidden __openat
diff --git a/libc/arch-mips64/syscalls/__ppoll.S b/libc/arch-mips64/syscalls/__ppoll.S
new file mode 100644
index 0000000..4e6fb8a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__ppoll.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__ppoll)
+    .set push
+    .set noreorder
+    li v0, __NR_ppoll
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__ppoll)
+.hidden __ppoll
diff --git a/libc/arch-mips64/syscalls/__pselect6.S b/libc/arch-mips64/syscalls/__pselect6.S
new file mode 100644
index 0000000..6d49d1c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__pselect6.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__pselect6)
+    .set push
+    .set noreorder
+    li v0, __NR_pselect6
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__pselect6)
+.hidden __pselect6
diff --git a/libc/arch-mips64/syscalls/__ptrace.S b/libc/arch-mips64/syscalls/__ptrace.S
new file mode 100644
index 0000000..5a3ce16
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__ptrace.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__ptrace)
+    .set push
+    .set noreorder
+    li v0, __NR_ptrace
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__ptrace)
+.hidden __ptrace
diff --git a/libc/arch-mips64/syscalls/__reboot.S b/libc/arch-mips64/syscalls/__reboot.S
new file mode 100644
index 0000000..587310d
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__reboot.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__reboot)
+    .set push
+    .set noreorder
+    li v0, __NR_reboot
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__reboot)
+.hidden __reboot
diff --git a/libc/arch-mips64/syscalls/__rt_sigaction.S b/libc/arch-mips64/syscalls/__rt_sigaction.S
new file mode 100644
index 0000000..7dd3cae
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__rt_sigaction.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__rt_sigaction)
+    .set push
+    .set noreorder
+    li v0, __NR_rt_sigaction
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__rt_sigaction)
+.hidden __rt_sigaction
diff --git a/libc/arch-mips64/syscalls/__rt_sigpending.S b/libc/arch-mips64/syscalls/__rt_sigpending.S
new file mode 100644
index 0000000..68ae39a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__rt_sigpending.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__rt_sigpending)
+    .set push
+    .set noreorder
+    li v0, __NR_rt_sigpending
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__rt_sigpending)
+.hidden __rt_sigpending
diff --git a/libc/arch-mips64/syscalls/__rt_sigprocmask.S b/libc/arch-mips64/syscalls/__rt_sigprocmask.S
new file mode 100644
index 0000000..54620e9
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__rt_sigprocmask.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__rt_sigprocmask)
+    .set push
+    .set noreorder
+    li v0, __NR_rt_sigprocmask
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__rt_sigprocmask)
+.hidden __rt_sigprocmask
diff --git a/libc/arch-mips64/syscalls/__rt_sigsuspend.S b/libc/arch-mips64/syscalls/__rt_sigsuspend.S
new file mode 100644
index 0000000..ea15def
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__rt_sigsuspend.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__rt_sigsuspend)
+    .set push
+    .set noreorder
+    li v0, __NR_rt_sigsuspend
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__rt_sigsuspend)
+.hidden __rt_sigsuspend
diff --git a/libc/arch-mips64/syscalls/__rt_sigtimedwait.S b/libc/arch-mips64/syscalls/__rt_sigtimedwait.S
new file mode 100644
index 0000000..177f17c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__rt_sigtimedwait.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__rt_sigtimedwait)
+    .set push
+    .set noreorder
+    li v0, __NR_rt_sigtimedwait
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__rt_sigtimedwait)
+.hidden __rt_sigtimedwait
diff --git a/libc/arch-mips64/syscalls/__sched_getaffinity.S b/libc/arch-mips64/syscalls/__sched_getaffinity.S
new file mode 100644
index 0000000..2081706
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__sched_getaffinity.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__sched_getaffinity)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_getaffinity
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__sched_getaffinity)
+.hidden __sched_getaffinity
diff --git a/libc/arch-mips64/syscalls/__set_tid_address.S b/libc/arch-mips64/syscalls/__set_tid_address.S
new file mode 100644
index 0000000..cd966dd
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__set_tid_address.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__set_tid_address)
+    .set push
+    .set noreorder
+    li v0, __NR_set_tid_address
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__set_tid_address)
+.hidden __set_tid_address
diff --git a/libc/arch-mips64/syscalls/__set_tls.S b/libc/arch-mips64/syscalls/__set_tls.S
new file mode 100644
index 0000000..cc98150
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__set_tls.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__set_tls)
+    .set push
+    .set noreorder
+    li v0, __NR_set_thread_area
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__set_tls)
+.hidden __set_tls
diff --git a/libc/arch-mips64/syscalls/__signalfd4.S b/libc/arch-mips64/syscalls/__signalfd4.S
new file mode 100644
index 0000000..ea6eef1
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__signalfd4.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__signalfd4)
+    .set push
+    .set noreorder
+    li v0, __NR_signalfd4
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__signalfd4)
+.hidden __signalfd4
diff --git a/libc/arch-mips64/syscalls/__socket.S b/libc/arch-mips64/syscalls/__socket.S
new file mode 100644
index 0000000..a499359
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__socket.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__socket)
+    .set push
+    .set noreorder
+    li v0, __NR_socket
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__socket)
+.hidden __socket
diff --git a/libc/arch-mips64/syscalls/__timer_create.S b/libc/arch-mips64/syscalls/__timer_create.S
new file mode 100644
index 0000000..c66d8f9
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__timer_create.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__timer_create)
+    .set push
+    .set noreorder
+    li v0, __NR_timer_create
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__timer_create)
+.hidden __timer_create
diff --git a/libc/arch-mips64/syscalls/__timer_delete.S b/libc/arch-mips64/syscalls/__timer_delete.S
new file mode 100644
index 0000000..45cf5e8
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__timer_delete.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__timer_delete)
+    .set push
+    .set noreorder
+    li v0, __NR_timer_delete
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__timer_delete)
+.hidden __timer_delete
diff --git a/libc/arch-mips64/syscalls/__timer_getoverrun.S b/libc/arch-mips64/syscalls/__timer_getoverrun.S
new file mode 100644
index 0000000..8a73160
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__timer_getoverrun.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__timer_getoverrun)
+    .set push
+    .set noreorder
+    li v0, __NR_timer_getoverrun
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__timer_getoverrun)
+.hidden __timer_getoverrun
diff --git a/libc/arch-mips64/syscalls/__timer_gettime.S b/libc/arch-mips64/syscalls/__timer_gettime.S
new file mode 100644
index 0000000..32ee5bf
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__timer_gettime.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__timer_gettime)
+    .set push
+    .set noreorder
+    li v0, __NR_timer_gettime
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__timer_gettime)
+.hidden __timer_gettime
diff --git a/libc/arch-mips64/syscalls/__timer_settime.S b/libc/arch-mips64/syscalls/__timer_settime.S
new file mode 100644
index 0000000..59764d8
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__timer_settime.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__timer_settime)
+    .set push
+    .set noreorder
+    li v0, __NR_timer_settime
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__timer_settime)
+.hidden __timer_settime
diff --git a/libc/arch-mips64/syscalls/__waitid.S b/libc/arch-mips64/syscalls/__waitid.S
new file mode 100644
index 0000000..5ee090d
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__waitid.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__waitid)
+    .set push
+    .set noreorder
+    li v0, __NR_waitid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__waitid)
+.hidden __waitid
diff --git a/libc/arch-mips64/syscalls/_exit.S b/libc/arch-mips64/syscalls/_exit.S
new file mode 100644
index 0000000..da5a2f7
--- /dev/null
+++ b/libc/arch-mips64/syscalls/_exit.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(_exit)
+    .set push
+    .set noreorder
+    li v0, __NR_exit_group
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(_exit)
+
+    .globl _Exit
+    .equ _Exit, _exit
diff --git a/libc/arch-mips64/syscalls/_flush_cache.S b/libc/arch-mips64/syscalls/_flush_cache.S
new file mode 100644
index 0000000..a9e4842
--- /dev/null
+++ b/libc/arch-mips64/syscalls/_flush_cache.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(_flush_cache)
+    .set push
+    .set noreorder
+    li v0, __NR_cacheflush
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(_flush_cache)
diff --git a/libc/arch-mips64/syscalls/acct.S b/libc/arch-mips64/syscalls/acct.S
new file mode 100644
index 0000000..ff728dc
--- /dev/null
+++ b/libc/arch-mips64/syscalls/acct.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(acct)
+    .set push
+    .set noreorder
+    li v0, __NR_acct
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(acct)
diff --git a/libc/arch-mips64/syscalls/bind.S b/libc/arch-mips64/syscalls/bind.S
new file mode 100644
index 0000000..9c2b5b8
--- /dev/null
+++ b/libc/arch-mips64/syscalls/bind.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(bind)
+    .set push
+    .set noreorder
+    li v0, __NR_bind
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(bind)
diff --git a/libc/arch-mips64/syscalls/capget.S b/libc/arch-mips64/syscalls/capget.S
new file mode 100644
index 0000000..9d05438
--- /dev/null
+++ b/libc/arch-mips64/syscalls/capget.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(capget)
+    .set push
+    .set noreorder
+    li v0, __NR_capget
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(capget)
diff --git a/libc/arch-mips64/syscalls/capset.S b/libc/arch-mips64/syscalls/capset.S
new file mode 100644
index 0000000..e947028
--- /dev/null
+++ b/libc/arch-mips64/syscalls/capset.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(capset)
+    .set push
+    .set noreorder
+    li v0, __NR_capset
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(capset)
diff --git a/libc/arch-mips64/syscalls/chdir.S b/libc/arch-mips64/syscalls/chdir.S
new file mode 100644
index 0000000..14b22c9
--- /dev/null
+++ b/libc/arch-mips64/syscalls/chdir.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(chdir)
+    .set push
+    .set noreorder
+    li v0, __NR_chdir
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(chdir)
diff --git a/libc/arch-mips64/syscalls/chroot.S b/libc/arch-mips64/syscalls/chroot.S
new file mode 100644
index 0000000..e805f51
--- /dev/null
+++ b/libc/arch-mips64/syscalls/chroot.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(chroot)
+    .set push
+    .set noreorder
+    li v0, __NR_chroot
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(chroot)
diff --git a/libc/arch-mips64/syscalls/clock_getres.S b/libc/arch-mips64/syscalls/clock_getres.S
new file mode 100644
index 0000000..41003a0
--- /dev/null
+++ b/libc/arch-mips64/syscalls/clock_getres.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(clock_getres)
+    .set push
+    .set noreorder
+    li v0, __NR_clock_getres
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(clock_getres)
diff --git a/libc/arch-mips64/syscalls/clock_gettime.S b/libc/arch-mips64/syscalls/clock_gettime.S
new file mode 100644
index 0000000..0813560
--- /dev/null
+++ b/libc/arch-mips64/syscalls/clock_gettime.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(clock_gettime)
+    .set push
+    .set noreorder
+    li v0, __NR_clock_gettime
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(clock_gettime)
diff --git a/libc/arch-mips64/syscalls/clock_nanosleep.S b/libc/arch-mips64/syscalls/clock_nanosleep.S
new file mode 100644
index 0000000..c958a10
--- /dev/null
+++ b/libc/arch-mips64/syscalls/clock_nanosleep.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(clock_nanosleep)
+    .set push
+    .set noreorder
+    li v0, __NR_clock_nanosleep
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(clock_nanosleep)
diff --git a/libc/arch-mips64/syscalls/clock_settime.S b/libc/arch-mips64/syscalls/clock_settime.S
new file mode 100644
index 0000000..77b6ae4
--- /dev/null
+++ b/libc/arch-mips64/syscalls/clock_settime.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(clock_settime)
+    .set push
+    .set noreorder
+    li v0, __NR_clock_settime
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(clock_settime)
diff --git a/libc/arch-mips64/syscalls/close.S b/libc/arch-mips64/syscalls/close.S
new file mode 100644
index 0000000..5e237dd
--- /dev/null
+++ b/libc/arch-mips64/syscalls/close.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(close)
+    .set push
+    .set noreorder
+    li v0, __NR_close
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(close)
diff --git a/libc/arch-mips64/syscalls/delete_module.S b/libc/arch-mips64/syscalls/delete_module.S
new file mode 100644
index 0000000..8396537
--- /dev/null
+++ b/libc/arch-mips64/syscalls/delete_module.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(delete_module)
+    .set push
+    .set noreorder
+    li v0, __NR_delete_module
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(delete_module)
diff --git a/libc/arch-mips64/syscalls/dup.S b/libc/arch-mips64/syscalls/dup.S
new file mode 100644
index 0000000..d1ca5e7
--- /dev/null
+++ b/libc/arch-mips64/syscalls/dup.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(dup)
+    .set push
+    .set noreorder
+    li v0, __NR_dup
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(dup)
diff --git a/libc/arch-mips64/syscalls/dup3.S b/libc/arch-mips64/syscalls/dup3.S
new file mode 100644
index 0000000..5601f31
--- /dev/null
+++ b/libc/arch-mips64/syscalls/dup3.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(dup3)
+    .set push
+    .set noreorder
+    li v0, __NR_dup3
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(dup3)
diff --git a/libc/arch-mips64/syscalls/epoll_create1.S b/libc/arch-mips64/syscalls/epoll_create1.S
new file mode 100644
index 0000000..11f1ceb
--- /dev/null
+++ b/libc/arch-mips64/syscalls/epoll_create1.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(epoll_create1)
+    .set push
+    .set noreorder
+    li v0, __NR_epoll_create1
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(epoll_create1)
diff --git a/libc/arch-mips64/syscalls/epoll_ctl.S b/libc/arch-mips64/syscalls/epoll_ctl.S
new file mode 100644
index 0000000..9eba605
--- /dev/null
+++ b/libc/arch-mips64/syscalls/epoll_ctl.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(epoll_ctl)
+    .set push
+    .set noreorder
+    li v0, __NR_epoll_ctl
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(epoll_ctl)
diff --git a/libc/arch-mips64/syscalls/eventfd.S b/libc/arch-mips64/syscalls/eventfd.S
new file mode 100644
index 0000000..5cd63e4
--- /dev/null
+++ b/libc/arch-mips64/syscalls/eventfd.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(eventfd)
+    .set push
+    .set noreorder
+    li v0, __NR_eventfd2
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(eventfd)
diff --git a/libc/arch-mips64/syscalls/execve.S b/libc/arch-mips64/syscalls/execve.S
new file mode 100644
index 0000000..bcd5d60
--- /dev/null
+++ b/libc/arch-mips64/syscalls/execve.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(execve)
+    .set push
+    .set noreorder
+    li v0, __NR_execve
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(execve)
diff --git a/libc/arch-mips64/syscalls/faccessat.S b/libc/arch-mips64/syscalls/faccessat.S
new file mode 100644
index 0000000..18bb800
--- /dev/null
+++ b/libc/arch-mips64/syscalls/faccessat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(faccessat)
+    .set push
+    .set noreorder
+    li v0, __NR_faccessat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(faccessat)
diff --git a/libc/arch-mips64/syscalls/fallocate.S b/libc/arch-mips64/syscalls/fallocate.S
new file mode 100644
index 0000000..c1ef0ed
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fallocate.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fallocate)
+    .set push
+    .set noreorder
+    li v0, __NR_fallocate
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fallocate)
+
+    .globl fallocate64
+    .equ fallocate64, fallocate
diff --git a/libc/arch-mips64/syscalls/fchdir.S b/libc/arch-mips64/syscalls/fchdir.S
new file mode 100644
index 0000000..e05625c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fchdir.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fchdir)
+    .set push
+    .set noreorder
+    li v0, __NR_fchdir
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fchdir)
diff --git a/libc/arch-mips64/syscalls/fchmod.S b/libc/arch-mips64/syscalls/fchmod.S
new file mode 100644
index 0000000..a877b78
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fchmod.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fchmod)
+    .set push
+    .set noreorder
+    li v0, __NR_fchmod
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fchmod)
diff --git a/libc/arch-mips64/syscalls/fchmodat.S b/libc/arch-mips64/syscalls/fchmodat.S
new file mode 100644
index 0000000..151492a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fchmodat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fchmodat)
+    .set push
+    .set noreorder
+    li v0, __NR_fchmodat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fchmodat)
diff --git a/libc/arch-mips64/syscalls/fchown.S b/libc/arch-mips64/syscalls/fchown.S
new file mode 100644
index 0000000..5dc33c0
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fchown.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fchown)
+    .set push
+    .set noreorder
+    li v0, __NR_fchown
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fchown)
diff --git a/libc/arch-mips64/syscalls/fchownat.S b/libc/arch-mips64/syscalls/fchownat.S
new file mode 100644
index 0000000..f4cefe0
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fchownat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fchownat)
+    .set push
+    .set noreorder
+    li v0, __NR_fchownat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fchownat)
diff --git a/libc/arch-mips64/syscalls/fcntl.S b/libc/arch-mips64/syscalls/fcntl.S
new file mode 100644
index 0000000..dabc65b
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fcntl.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fcntl)
+    .set push
+    .set noreorder
+    li v0, __NR_fcntl
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fcntl)
diff --git a/libc/arch-mips64/syscalls/fdatasync.S b/libc/arch-mips64/syscalls/fdatasync.S
new file mode 100644
index 0000000..52be110
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fdatasync.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fdatasync)
+    .set push
+    .set noreorder
+    li v0, __NR_fdatasync
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fdatasync)
diff --git a/libc/arch-mips64/syscalls/fgetxattr.S b/libc/arch-mips64/syscalls/fgetxattr.S
new file mode 100644
index 0000000..44c248a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fgetxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fgetxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_fgetxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fgetxattr)
diff --git a/libc/arch-mips64/syscalls/flistxattr.S b/libc/arch-mips64/syscalls/flistxattr.S
new file mode 100644
index 0000000..1d5b1b0
--- /dev/null
+++ b/libc/arch-mips64/syscalls/flistxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(flistxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_flistxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(flistxattr)
diff --git a/libc/arch-mips64/syscalls/flock.S b/libc/arch-mips64/syscalls/flock.S
new file mode 100644
index 0000000..d74a5db
--- /dev/null
+++ b/libc/arch-mips64/syscalls/flock.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(flock)
+    .set push
+    .set noreorder
+    li v0, __NR_flock
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(flock)
diff --git a/libc/arch-mips64/syscalls/fremovexattr.S b/libc/arch-mips64/syscalls/fremovexattr.S
new file mode 100644
index 0000000..417be4a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fremovexattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fremovexattr)
+    .set push
+    .set noreorder
+    li v0, __NR_fremovexattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fremovexattr)
diff --git a/libc/arch-mips64/syscalls/fsetxattr.S b/libc/arch-mips64/syscalls/fsetxattr.S
new file mode 100644
index 0000000..0ad1f90
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fsetxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fsetxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_fsetxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fsetxattr)
diff --git a/libc/arch-mips64/syscalls/fstat64.S b/libc/arch-mips64/syscalls/fstat64.S
new file mode 100644
index 0000000..a14d51c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fstat64.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstat64)
+    .set push
+    .set noreorder
+    li v0, __NR_fstat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fstat64)
+
+    .globl fstat
+    .equ fstat, fstat64
diff --git a/libc/arch-mips64/syscalls/fstatat64.S b/libc/arch-mips64/syscalls/fstatat64.S
new file mode 100644
index 0000000..7888a43
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fstatat64.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatat64)
+    .set push
+    .set noreorder
+    li v0, __NR_newfstatat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fstatat64)
+
+    .globl fstatat
+    .equ fstatat, fstatat64
diff --git a/libc/arch-mips64/syscalls/fstatfs64.S b/libc/arch-mips64/syscalls/fstatfs64.S
new file mode 100644
index 0000000..12e885c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fstatfs64.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatfs64)
+    .set push
+    .set noreorder
+    li v0, __NR_fstatfs
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fstatfs64)
+
+    .globl fstatfs
+    .equ fstatfs, fstatfs64
diff --git a/libc/arch-mips64/syscalls/fsync.S b/libc/arch-mips64/syscalls/fsync.S
new file mode 100644
index 0000000..7056e36
--- /dev/null
+++ b/libc/arch-mips64/syscalls/fsync.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fsync)
+    .set push
+    .set noreorder
+    li v0, __NR_fsync
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(fsync)
diff --git a/libc/arch-mips64/syscalls/ftruncate.S b/libc/arch-mips64/syscalls/ftruncate.S
new file mode 100644
index 0000000..58b847b
--- /dev/null
+++ b/libc/arch-mips64/syscalls/ftruncate.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(ftruncate)
+    .set push
+    .set noreorder
+    li v0, __NR_ftruncate
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(ftruncate)
+
+    .globl ftruncate64
+    .equ ftruncate64, ftruncate
diff --git a/libc/arch-mips64/syscalls/getegid.S b/libc/arch-mips64/syscalls/getegid.S
new file mode 100644
index 0000000..439c6f0
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getegid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getegid)
+    .set push
+    .set noreorder
+    li v0, __NR_getegid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getegid)
diff --git a/libc/arch-mips64/syscalls/geteuid.S b/libc/arch-mips64/syscalls/geteuid.S
new file mode 100644
index 0000000..5619dc6
--- /dev/null
+++ b/libc/arch-mips64/syscalls/geteuid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(geteuid)
+    .set push
+    .set noreorder
+    li v0, __NR_geteuid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(geteuid)
diff --git a/libc/arch-mips64/syscalls/getgid.S b/libc/arch-mips64/syscalls/getgid.S
new file mode 100644
index 0000000..777be1a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getgid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getgid)
+    .set push
+    .set noreorder
+    li v0, __NR_getgid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getgid)
diff --git a/libc/arch-mips64/syscalls/getgroups.S b/libc/arch-mips64/syscalls/getgroups.S
new file mode 100644
index 0000000..93c4fa1
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getgroups.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getgroups)
+    .set push
+    .set noreorder
+    li v0, __NR_getgroups
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getgroups)
diff --git a/libc/arch-mips64/syscalls/getitimer.S b/libc/arch-mips64/syscalls/getitimer.S
new file mode 100644
index 0000000..fe78a97
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getitimer.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getitimer)
+    .set push
+    .set noreorder
+    li v0, __NR_getitimer
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getitimer)
diff --git a/libc/arch-mips64/syscalls/getpeername.S b/libc/arch-mips64/syscalls/getpeername.S
new file mode 100644
index 0000000..121f1a6
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getpeername.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getpeername)
+    .set push
+    .set noreorder
+    li v0, __NR_getpeername
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getpeername)
diff --git a/libc/arch-mips64/syscalls/getpgid.S b/libc/arch-mips64/syscalls/getpgid.S
new file mode 100644
index 0000000..19dc77f
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getpgid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getpgid)
+    .set push
+    .set noreorder
+    li v0, __NR_getpgid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getpgid)
diff --git a/libc/arch-mips64/syscalls/getppid.S b/libc/arch-mips64/syscalls/getppid.S
new file mode 100644
index 0000000..d00f309
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getppid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getppid)
+    .set push
+    .set noreorder
+    li v0, __NR_getppid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getppid)
diff --git a/libc/arch-mips64/syscalls/getresgid.S b/libc/arch-mips64/syscalls/getresgid.S
new file mode 100644
index 0000000..18cb5a1
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getresgid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getresgid)
+    .set push
+    .set noreorder
+    li v0, __NR_getresgid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getresgid)
diff --git a/libc/arch-mips64/syscalls/getresuid.S b/libc/arch-mips64/syscalls/getresuid.S
new file mode 100644
index 0000000..c217bf7
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getresuid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getresuid)
+    .set push
+    .set noreorder
+    li v0, __NR_getresuid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getresuid)
diff --git a/libc/arch-mips64/syscalls/getrlimit.S b/libc/arch-mips64/syscalls/getrlimit.S
new file mode 100644
index 0000000..7576c17
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getrlimit.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getrlimit)
+    .set push
+    .set noreorder
+    li v0, __NR_getrlimit
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getrlimit)
+
+    .globl getrlimit64
+    .equ getrlimit64, getrlimit
diff --git a/libc/arch-mips64/syscalls/getrusage.S b/libc/arch-mips64/syscalls/getrusage.S
new file mode 100644
index 0000000..4bf557e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getrusage.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getrusage)
+    .set push
+    .set noreorder
+    li v0, __NR_getrusage
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getrusage)
diff --git a/libc/arch-mips64/syscalls/getsid.S b/libc/arch-mips64/syscalls/getsid.S
new file mode 100644
index 0000000..030c91d
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getsid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getsid)
+    .set push
+    .set noreorder
+    li v0, __NR_getsid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getsid)
diff --git a/libc/arch-mips64/syscalls/getsockname.S b/libc/arch-mips64/syscalls/getsockname.S
new file mode 100644
index 0000000..88a9426
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getsockname.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getsockname)
+    .set push
+    .set noreorder
+    li v0, __NR_getsockname
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getsockname)
diff --git a/libc/arch-mips64/syscalls/getsockopt.S b/libc/arch-mips64/syscalls/getsockopt.S
new file mode 100644
index 0000000..08ee634
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getsockopt.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getsockopt)
+    .set push
+    .set noreorder
+    li v0, __NR_getsockopt
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getsockopt)
diff --git a/libc/arch-mips64/syscalls/gettimeofday.S b/libc/arch-mips64/syscalls/gettimeofday.S
new file mode 100644
index 0000000..3a6d417
--- /dev/null
+++ b/libc/arch-mips64/syscalls/gettimeofday.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(gettimeofday)
+    .set push
+    .set noreorder
+    li v0, __NR_gettimeofday
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(gettimeofday)
diff --git a/libc/arch-mips64/syscalls/getuid.S b/libc/arch-mips64/syscalls/getuid.S
new file mode 100644
index 0000000..3d5f940
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getuid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getuid)
+    .set push
+    .set noreorder
+    li v0, __NR_getuid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getuid)
diff --git a/libc/arch-mips64/syscalls/getxattr.S b/libc/arch-mips64/syscalls/getxattr.S
new file mode 100644
index 0000000..1c443f2
--- /dev/null
+++ b/libc/arch-mips64/syscalls/getxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(getxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_getxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(getxattr)
diff --git a/libc/arch-mips64/syscalls/init_module.S b/libc/arch-mips64/syscalls/init_module.S
new file mode 100644
index 0000000..3e2f074
--- /dev/null
+++ b/libc/arch-mips64/syscalls/init_module.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(init_module)
+    .set push
+    .set noreorder
+    li v0, __NR_init_module
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(init_module)
diff --git a/libc/arch-mips64/syscalls/inotify_add_watch.S b/libc/arch-mips64/syscalls/inotify_add_watch.S
new file mode 100644
index 0000000..bffdad8
--- /dev/null
+++ b/libc/arch-mips64/syscalls/inotify_add_watch.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(inotify_add_watch)
+    .set push
+    .set noreorder
+    li v0, __NR_inotify_add_watch
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(inotify_add_watch)
diff --git a/libc/arch-mips64/syscalls/inotify_init1.S b/libc/arch-mips64/syscalls/inotify_init1.S
new file mode 100644
index 0000000..c70d101
--- /dev/null
+++ b/libc/arch-mips64/syscalls/inotify_init1.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(inotify_init1)
+    .set push
+    .set noreorder
+    li v0, __NR_inotify_init1
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(inotify_init1)
diff --git a/libc/arch-mips64/syscalls/inotify_rm_watch.S b/libc/arch-mips64/syscalls/inotify_rm_watch.S
new file mode 100644
index 0000000..d893787
--- /dev/null
+++ b/libc/arch-mips64/syscalls/inotify_rm_watch.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(inotify_rm_watch)
+    .set push
+    .set noreorder
+    li v0, __NR_inotify_rm_watch
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(inotify_rm_watch)
diff --git a/libc/arch-mips64/syscalls/kill.S b/libc/arch-mips64/syscalls/kill.S
new file mode 100644
index 0000000..475b615
--- /dev/null
+++ b/libc/arch-mips64/syscalls/kill.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(kill)
+    .set push
+    .set noreorder
+    li v0, __NR_kill
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(kill)
diff --git a/libc/arch-mips64/syscalls/klogctl.S b/libc/arch-mips64/syscalls/klogctl.S
new file mode 100644
index 0000000..98b9f0b
--- /dev/null
+++ b/libc/arch-mips64/syscalls/klogctl.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(klogctl)
+    .set push
+    .set noreorder
+    li v0, __NR_syslog
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(klogctl)
diff --git a/libc/arch-mips64/syscalls/lgetxattr.S b/libc/arch-mips64/syscalls/lgetxattr.S
new file mode 100644
index 0000000..55d7c42
--- /dev/null
+++ b/libc/arch-mips64/syscalls/lgetxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(lgetxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_lgetxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(lgetxattr)
diff --git a/libc/arch-mips64/syscalls/linkat.S b/libc/arch-mips64/syscalls/linkat.S
new file mode 100644
index 0000000..df749eb
--- /dev/null
+++ b/libc/arch-mips64/syscalls/linkat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(linkat)
+    .set push
+    .set noreorder
+    li v0, __NR_linkat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(linkat)
diff --git a/libc/arch-mips64/syscalls/listen.S b/libc/arch-mips64/syscalls/listen.S
new file mode 100644
index 0000000..195cade
--- /dev/null
+++ b/libc/arch-mips64/syscalls/listen.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(listen)
+    .set push
+    .set noreorder
+    li v0, __NR_listen
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(listen)
diff --git a/libc/arch-mips64/syscalls/listxattr.S b/libc/arch-mips64/syscalls/listxattr.S
new file mode 100644
index 0000000..30b0f2b
--- /dev/null
+++ b/libc/arch-mips64/syscalls/listxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(listxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_listxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(listxattr)
diff --git a/libc/arch-mips64/syscalls/llistxattr.S b/libc/arch-mips64/syscalls/llistxattr.S
new file mode 100644
index 0000000..d349116
--- /dev/null
+++ b/libc/arch-mips64/syscalls/llistxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(llistxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_llistxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(llistxattr)
diff --git a/libc/arch-mips64/syscalls/lremovexattr.S b/libc/arch-mips64/syscalls/lremovexattr.S
new file mode 100644
index 0000000..db4e4d3
--- /dev/null
+++ b/libc/arch-mips64/syscalls/lremovexattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(lremovexattr)
+    .set push
+    .set noreorder
+    li v0, __NR_lremovexattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(lremovexattr)
diff --git a/libc/arch-mips64/syscalls/lseek.S b/libc/arch-mips64/syscalls/lseek.S
new file mode 100644
index 0000000..5c92d70
--- /dev/null
+++ b/libc/arch-mips64/syscalls/lseek.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(lseek)
+    .set push
+    .set noreorder
+    li v0, __NR_lseek
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(lseek)
+
+    .globl lseek64
+    .equ lseek64, lseek
diff --git a/libc/arch-mips64/syscalls/lsetxattr.S b/libc/arch-mips64/syscalls/lsetxattr.S
new file mode 100644
index 0000000..c161eb3
--- /dev/null
+++ b/libc/arch-mips64/syscalls/lsetxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(lsetxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_lsetxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(lsetxattr)
diff --git a/libc/arch-mips64/syscalls/madvise.S b/libc/arch-mips64/syscalls/madvise.S
new file mode 100644
index 0000000..88f3830
--- /dev/null
+++ b/libc/arch-mips64/syscalls/madvise.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(madvise)
+    .set push
+    .set noreorder
+    li v0, __NR_madvise
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(madvise)
diff --git a/libc/arch-mips64/syscalls/mincore.S b/libc/arch-mips64/syscalls/mincore.S
new file mode 100644
index 0000000..695c9b2
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mincore.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mincore)
+    .set push
+    .set noreorder
+    li v0, __NR_mincore
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mincore)
diff --git a/libc/arch-mips64/syscalls/mkdirat.S b/libc/arch-mips64/syscalls/mkdirat.S
new file mode 100644
index 0000000..71cdfd1
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mkdirat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mkdirat)
+    .set push
+    .set noreorder
+    li v0, __NR_mkdirat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mkdirat)
diff --git a/libc/arch-mips64/syscalls/mknodat.S b/libc/arch-mips64/syscalls/mknodat.S
new file mode 100644
index 0000000..9943e49
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mknodat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mknodat)
+    .set push
+    .set noreorder
+    li v0, __NR_mknodat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mknodat)
diff --git a/libc/arch-mips64/syscalls/mlock.S b/libc/arch-mips64/syscalls/mlock.S
new file mode 100644
index 0000000..081f12b
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mlock.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mlock)
+    .set push
+    .set noreorder
+    li v0, __NR_mlock
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mlock)
diff --git a/libc/arch-mips64/syscalls/mlockall.S b/libc/arch-mips64/syscalls/mlockall.S
new file mode 100644
index 0000000..0e158f4
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mlockall.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mlockall)
+    .set push
+    .set noreorder
+    li v0, __NR_mlockall
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mlockall)
diff --git a/libc/arch-mips64/syscalls/mmap.S b/libc/arch-mips64/syscalls/mmap.S
new file mode 100644
index 0000000..393271a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mmap.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mmap)
+    .set push
+    .set noreorder
+    li v0, __NR_mmap
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mmap)
+
+    .globl mmap64
+    .equ mmap64, mmap
diff --git a/libc/arch-mips64/syscalls/mount.S b/libc/arch-mips64/syscalls/mount.S
new file mode 100644
index 0000000..50c7541
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mount.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mount)
+    .set push
+    .set noreorder
+    li v0, __NR_mount
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mount)
diff --git a/libc/arch-mips64/syscalls/mprotect.S b/libc/arch-mips64/syscalls/mprotect.S
new file mode 100644
index 0000000..d755489
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mprotect.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mprotect)
+    .set push
+    .set noreorder
+    li v0, __NR_mprotect
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mprotect)
diff --git a/libc/arch-mips64/syscalls/mremap.S b/libc/arch-mips64/syscalls/mremap.S
new file mode 100644
index 0000000..cf7f1de
--- /dev/null
+++ b/libc/arch-mips64/syscalls/mremap.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(mremap)
+    .set push
+    .set noreorder
+    li v0, __NR_mremap
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(mremap)
diff --git a/libc/arch-mips64/syscalls/msync.S b/libc/arch-mips64/syscalls/msync.S
new file mode 100644
index 0000000..efe31c1
--- /dev/null
+++ b/libc/arch-mips64/syscalls/msync.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(msync)
+    .set push
+    .set noreorder
+    li v0, __NR_msync
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(msync)
diff --git a/libc/arch-mips64/syscalls/munlock.S b/libc/arch-mips64/syscalls/munlock.S
new file mode 100644
index 0000000..44b930a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/munlock.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(munlock)
+    .set push
+    .set noreorder
+    li v0, __NR_munlock
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(munlock)
diff --git a/libc/arch-mips64/syscalls/munlockall.S b/libc/arch-mips64/syscalls/munlockall.S
new file mode 100644
index 0000000..ffeb5e1
--- /dev/null
+++ b/libc/arch-mips64/syscalls/munlockall.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(munlockall)
+    .set push
+    .set noreorder
+    li v0, __NR_munlockall
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(munlockall)
diff --git a/libc/arch-mips64/syscalls/munmap.S b/libc/arch-mips64/syscalls/munmap.S
new file mode 100644
index 0000000..cd0c05c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/munmap.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(munmap)
+    .set push
+    .set noreorder
+    li v0, __NR_munmap
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(munmap)
diff --git a/libc/arch-mips64/syscalls/nanosleep.S b/libc/arch-mips64/syscalls/nanosleep.S
new file mode 100644
index 0000000..bdaf256
--- /dev/null
+++ b/libc/arch-mips64/syscalls/nanosleep.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(nanosleep)
+    .set push
+    .set noreorder
+    li v0, __NR_nanosleep
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(nanosleep)
diff --git a/libc/arch-mips64/syscalls/personality.S b/libc/arch-mips64/syscalls/personality.S
new file mode 100644
index 0000000..6a12c95
--- /dev/null
+++ b/libc/arch-mips64/syscalls/personality.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(personality)
+    .set push
+    .set noreorder
+    li v0, __NR_personality
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(personality)
diff --git a/libc/arch-mips64/syscalls/pipe2.S b/libc/arch-mips64/syscalls/pipe2.S
new file mode 100644
index 0000000..1b08a45
--- /dev/null
+++ b/libc/arch-mips64/syscalls/pipe2.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(pipe2)
+    .set push
+    .set noreorder
+    li v0, __NR_pipe2
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(pipe2)
diff --git a/libc/arch-mips64/syscalls/prctl.S b/libc/arch-mips64/syscalls/prctl.S
new file mode 100644
index 0000000..61bb7c2
--- /dev/null
+++ b/libc/arch-mips64/syscalls/prctl.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(prctl)
+    .set push
+    .set noreorder
+    li v0, __NR_prctl
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(prctl)
diff --git a/libc/arch-mips64/syscalls/pread64.S b/libc/arch-mips64/syscalls/pread64.S
new file mode 100644
index 0000000..90e0612
--- /dev/null
+++ b/libc/arch-mips64/syscalls/pread64.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(pread64)
+    .set push
+    .set noreorder
+    li v0, __NR_pread64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(pread64)
+
+    .globl pread
+    .equ pread, pread64
diff --git a/libc/arch-mips64/syscalls/prlimit64.S b/libc/arch-mips64/syscalls/prlimit64.S
new file mode 100644
index 0000000..5f0ba1d
--- /dev/null
+++ b/libc/arch-mips64/syscalls/prlimit64.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(prlimit64)
+    .set push
+    .set noreorder
+    li v0, __NR_prlimit64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(prlimit64)
+
+    .globl prlimit
+    .equ prlimit, prlimit64
diff --git a/libc/arch-mips64/syscalls/pwrite64.S b/libc/arch-mips64/syscalls/pwrite64.S
new file mode 100644
index 0000000..e34f8db
--- /dev/null
+++ b/libc/arch-mips64/syscalls/pwrite64.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(pwrite64)
+    .set push
+    .set noreorder
+    li v0, __NR_pwrite64
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(pwrite64)
+
+    .globl pwrite
+    .equ pwrite, pwrite64
diff --git a/libc/arch-mips64/syscalls/read.S b/libc/arch-mips64/syscalls/read.S
new file mode 100644
index 0000000..74d39df
--- /dev/null
+++ b/libc/arch-mips64/syscalls/read.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(read)
+    .set push
+    .set noreorder
+    li v0, __NR_read
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(read)
diff --git a/libc/arch-mips64/syscalls/readahead.S b/libc/arch-mips64/syscalls/readahead.S
new file mode 100644
index 0000000..ae511d9
--- /dev/null
+++ b/libc/arch-mips64/syscalls/readahead.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(readahead)
+    .set push
+    .set noreorder
+    li v0, __NR_readahead
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(readahead)
diff --git a/libc/arch-mips64/syscalls/readlinkat.S b/libc/arch-mips64/syscalls/readlinkat.S
new file mode 100644
index 0000000..473a946
--- /dev/null
+++ b/libc/arch-mips64/syscalls/readlinkat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(readlinkat)
+    .set push
+    .set noreorder
+    li v0, __NR_readlinkat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(readlinkat)
diff --git a/libc/arch-mips64/syscalls/readv.S b/libc/arch-mips64/syscalls/readv.S
new file mode 100644
index 0000000..daa800c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/readv.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(readv)
+    .set push
+    .set noreorder
+    li v0, __NR_readv
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(readv)
diff --git a/libc/arch-mips64/syscalls/recvfrom.S b/libc/arch-mips64/syscalls/recvfrom.S
new file mode 100644
index 0000000..4c9b5fa
--- /dev/null
+++ b/libc/arch-mips64/syscalls/recvfrom.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(recvfrom)
+    .set push
+    .set noreorder
+    li v0, __NR_recvfrom
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(recvfrom)
diff --git a/libc/arch-mips64/syscalls/recvmmsg.S b/libc/arch-mips64/syscalls/recvmmsg.S
new file mode 100644
index 0000000..817250c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/recvmmsg.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(recvmmsg)
+    .set push
+    .set noreorder
+    li v0, __NR_recvmmsg
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(recvmmsg)
diff --git a/libc/arch-mips64/syscalls/recvmsg.S b/libc/arch-mips64/syscalls/recvmsg.S
new file mode 100644
index 0000000..877899d
--- /dev/null
+++ b/libc/arch-mips64/syscalls/recvmsg.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(recvmsg)
+    .set push
+    .set noreorder
+    li v0, __NR_recvmsg
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(recvmsg)
diff --git a/libc/arch-mips64/syscalls/removexattr.S b/libc/arch-mips64/syscalls/removexattr.S
new file mode 100644
index 0000000..c9d8a0e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/removexattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(removexattr)
+    .set push
+    .set noreorder
+    li v0, __NR_removexattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(removexattr)
diff --git a/libc/arch-mips64/syscalls/renameat.S b/libc/arch-mips64/syscalls/renameat.S
new file mode 100644
index 0000000..16b9333
--- /dev/null
+++ b/libc/arch-mips64/syscalls/renameat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(renameat)
+    .set push
+    .set noreorder
+    li v0, __NR_renameat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(renameat)
diff --git a/libc/arch-mips64/syscalls/sched_get_priority_max.S b/libc/arch-mips64/syscalls/sched_get_priority_max.S
new file mode 100644
index 0000000..67e2675
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_get_priority_max.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_get_priority_max)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_get_priority_max
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_get_priority_max)
diff --git a/libc/arch-mips64/syscalls/sched_get_priority_min.S b/libc/arch-mips64/syscalls/sched_get_priority_min.S
new file mode 100644
index 0000000..957f523
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_get_priority_min.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_get_priority_min)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_get_priority_min
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_get_priority_min)
diff --git a/libc/arch-mips64/syscalls/sched_getparam.S b/libc/arch-mips64/syscalls/sched_getparam.S
new file mode 100644
index 0000000..77bb4eb
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_getparam.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_getparam)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_getparam
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_getparam)
diff --git a/libc/arch-mips64/syscalls/sched_getscheduler.S b/libc/arch-mips64/syscalls/sched_getscheduler.S
new file mode 100644
index 0000000..324fa21
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_getscheduler.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_getscheduler)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_getscheduler
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_getscheduler)
diff --git a/libc/arch-mips64/syscalls/sched_rr_get_interval.S b/libc/arch-mips64/syscalls/sched_rr_get_interval.S
new file mode 100644
index 0000000..3019554
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_rr_get_interval.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_rr_get_interval)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_rr_get_interval
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_rr_get_interval)
diff --git a/libc/arch-mips64/syscalls/sched_setaffinity.S b/libc/arch-mips64/syscalls/sched_setaffinity.S
new file mode 100644
index 0000000..1520902
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_setaffinity.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_setaffinity)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_setaffinity
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_setaffinity)
diff --git a/libc/arch-mips64/syscalls/sched_setparam.S b/libc/arch-mips64/syscalls/sched_setparam.S
new file mode 100644
index 0000000..a37b15c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_setparam.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_setparam)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_setparam
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_setparam)
diff --git a/libc/arch-mips64/syscalls/sched_setscheduler.S b/libc/arch-mips64/syscalls/sched_setscheduler.S
new file mode 100644
index 0000000..ea4c6c4
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_setscheduler.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_setscheduler)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_setscheduler
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_setscheduler)
diff --git a/libc/arch-mips64/syscalls/sched_yield.S b/libc/arch-mips64/syscalls/sched_yield.S
new file mode 100644
index 0000000..5d86ea5
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sched_yield.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sched_yield)
+    .set push
+    .set noreorder
+    li v0, __NR_sched_yield
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sched_yield)
diff --git a/libc/arch-mips64/syscalls/sendfile.S b/libc/arch-mips64/syscalls/sendfile.S
new file mode 100644
index 0000000..f330242
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sendfile.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendfile)
+    .set push
+    .set noreorder
+    li v0, __NR_sendfile
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sendfile)
+
+    .globl sendfile64
+    .equ sendfile64, sendfile
diff --git a/libc/arch-mips64/syscalls/sendmmsg.S b/libc/arch-mips64/syscalls/sendmmsg.S
new file mode 100644
index 0000000..4a8d855
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sendmmsg.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendmmsg)
+    .set push
+    .set noreorder
+    li v0, __NR_sendmmsg
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sendmmsg)
diff --git a/libc/arch-mips64/syscalls/sendmsg.S b/libc/arch-mips64/syscalls/sendmsg.S
new file mode 100644
index 0000000..519dce4
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sendmsg.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendmsg)
+    .set push
+    .set noreorder
+    li v0, __NR_sendmsg
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sendmsg)
diff --git a/libc/arch-mips64/syscalls/sendto.S b/libc/arch-mips64/syscalls/sendto.S
new file mode 100644
index 0000000..84efc09
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sendto.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendto)
+    .set push
+    .set noreorder
+    li v0, __NR_sendto
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sendto)
diff --git a/libc/arch-mips64/syscalls/setfsgid.S b/libc/arch-mips64/syscalls/setfsgid.S
new file mode 100644
index 0000000..db1bd7f
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setfsgid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsgid)
+    .set push
+    .set noreorder
+    li v0, __NR_setfsgid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setfsgid)
diff --git a/libc/arch-mips64/syscalls/setfsuid.S b/libc/arch-mips64/syscalls/setfsuid.S
new file mode 100644
index 0000000..4254b18
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setfsuid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsuid)
+    .set push
+    .set noreorder
+    li v0, __NR_setfsuid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setfsuid)
diff --git a/libc/arch-mips64/syscalls/setgid.S b/libc/arch-mips64/syscalls/setgid.S
new file mode 100644
index 0000000..166a6d6
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setgid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setgid)
+    .set push
+    .set noreorder
+    li v0, __NR_setgid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setgid)
diff --git a/libc/arch-mips64/syscalls/setgroups.S b/libc/arch-mips64/syscalls/setgroups.S
new file mode 100644
index 0000000..24649f7
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setgroups.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setgroups)
+    .set push
+    .set noreorder
+    li v0, __NR_setgroups
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setgroups)
diff --git a/libc/arch-mips64/syscalls/setitimer.S b/libc/arch-mips64/syscalls/setitimer.S
new file mode 100644
index 0000000..5764573
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setitimer.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setitimer)
+    .set push
+    .set noreorder
+    li v0, __NR_setitimer
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setitimer)
diff --git a/libc/arch-mips64/syscalls/setns.S b/libc/arch-mips64/syscalls/setns.S
new file mode 100644
index 0000000..6b6178f
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setns.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setns)
+    .set push
+    .set noreorder
+    li v0, __NR_setns
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setns)
diff --git a/libc/arch-mips64/syscalls/setpgid.S b/libc/arch-mips64/syscalls/setpgid.S
new file mode 100644
index 0000000..233f784
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setpgid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setpgid)
+    .set push
+    .set noreorder
+    li v0, __NR_setpgid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setpgid)
diff --git a/libc/arch-mips64/syscalls/setpriority.S b/libc/arch-mips64/syscalls/setpriority.S
new file mode 100644
index 0000000..d88a2ff
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setpriority.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setpriority)
+    .set push
+    .set noreorder
+    li v0, __NR_setpriority
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setpriority)
diff --git a/libc/arch-mips64/syscalls/setregid.S b/libc/arch-mips64/syscalls/setregid.S
new file mode 100644
index 0000000..c82b4fd
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setregid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setregid)
+    .set push
+    .set noreorder
+    li v0, __NR_setregid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setregid)
diff --git a/libc/arch-mips64/syscalls/setresgid.S b/libc/arch-mips64/syscalls/setresgid.S
new file mode 100644
index 0000000..90b2939
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setresgid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setresgid)
+    .set push
+    .set noreorder
+    li v0, __NR_setresgid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setresgid)
diff --git a/libc/arch-mips64/syscalls/setresuid.S b/libc/arch-mips64/syscalls/setresuid.S
new file mode 100644
index 0000000..501ac5d
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setresuid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setresuid)
+    .set push
+    .set noreorder
+    li v0, __NR_setresuid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setresuid)
diff --git a/libc/arch-mips64/syscalls/setreuid.S b/libc/arch-mips64/syscalls/setreuid.S
new file mode 100644
index 0000000..1b3203c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setreuid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setreuid)
+    .set push
+    .set noreorder
+    li v0, __NR_setreuid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setreuid)
diff --git a/libc/arch-mips64/syscalls/setrlimit.S b/libc/arch-mips64/syscalls/setrlimit.S
new file mode 100644
index 0000000..0e5e80e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setrlimit.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setrlimit)
+    .set push
+    .set noreorder
+    li v0, __NR_setrlimit
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setrlimit)
+
+    .globl setrlimit64
+    .equ setrlimit64, setrlimit
diff --git a/libc/arch-mips64/syscalls/setsid.S b/libc/arch-mips64/syscalls/setsid.S
new file mode 100644
index 0000000..6d872d3
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setsid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setsid)
+    .set push
+    .set noreorder
+    li v0, __NR_setsid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setsid)
diff --git a/libc/arch-mips64/syscalls/setsockopt.S b/libc/arch-mips64/syscalls/setsockopt.S
new file mode 100644
index 0000000..b2fc736
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setsockopt.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setsockopt)
+    .set push
+    .set noreorder
+    li v0, __NR_setsockopt
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setsockopt)
diff --git a/libc/arch-mips64/syscalls/settimeofday.S b/libc/arch-mips64/syscalls/settimeofday.S
new file mode 100644
index 0000000..9f1acfe
--- /dev/null
+++ b/libc/arch-mips64/syscalls/settimeofday.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(settimeofday)
+    .set push
+    .set noreorder
+    li v0, __NR_settimeofday
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(settimeofday)
diff --git a/libc/arch-mips64/syscalls/setuid.S b/libc/arch-mips64/syscalls/setuid.S
new file mode 100644
index 0000000..dcd39ff
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setuid.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setuid)
+    .set push
+    .set noreorder
+    li v0, __NR_setuid
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setuid)
diff --git a/libc/arch-mips64/syscalls/setxattr.S b/libc/arch-mips64/syscalls/setxattr.S
new file mode 100644
index 0000000..4a1b87a
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setxattr.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setxattr)
+    .set push
+    .set noreorder
+    li v0, __NR_setxattr
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setxattr)
diff --git a/libc/arch-mips64/syscalls/shutdown.S b/libc/arch-mips64/syscalls/shutdown.S
new file mode 100644
index 0000000..d654288
--- /dev/null
+++ b/libc/arch-mips64/syscalls/shutdown.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(shutdown)
+    .set push
+    .set noreorder
+    li v0, __NR_shutdown
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(shutdown)
diff --git a/libc/arch-mips64/syscalls/sigaltstack.S b/libc/arch-mips64/syscalls/sigaltstack.S
new file mode 100644
index 0000000..92778c1
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sigaltstack.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sigaltstack)
+    .set push
+    .set noreorder
+    li v0, __NR_sigaltstack
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sigaltstack)
diff --git a/libc/arch-mips64/syscalls/socketpair.S b/libc/arch-mips64/syscalls/socketpair.S
new file mode 100644
index 0000000..8fbf7a8
--- /dev/null
+++ b/libc/arch-mips64/syscalls/socketpair.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(socketpair)
+    .set push
+    .set noreorder
+    li v0, __NR_socketpair
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(socketpair)
diff --git a/libc/arch-mips64/syscalls/splice.S b/libc/arch-mips64/syscalls/splice.S
new file mode 100644
index 0000000..ea745cf
--- /dev/null
+++ b/libc/arch-mips64/syscalls/splice.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    .set push
+    .set noreorder
+    li v0, __NR_splice
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(splice)
diff --git a/libc/arch-mips64/syscalls/statfs64.S b/libc/arch-mips64/syscalls/statfs64.S
new file mode 100644
index 0000000..74351f7
--- /dev/null
+++ b/libc/arch-mips64/syscalls/statfs64.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(statfs64)
+    .set push
+    .set noreorder
+    li v0, __NR_statfs
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(statfs64)
+
+    .globl statfs
+    .equ statfs, statfs64
diff --git a/libc/arch-mips64/syscalls/swapoff.S b/libc/arch-mips64/syscalls/swapoff.S
new file mode 100644
index 0000000..8c0048d
--- /dev/null
+++ b/libc/arch-mips64/syscalls/swapoff.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(swapoff)
+    .set push
+    .set noreorder
+    li v0, __NR_swapoff
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(swapoff)
diff --git a/libc/arch-mips64/syscalls/swapon.S b/libc/arch-mips64/syscalls/swapon.S
new file mode 100644
index 0000000..e8f6ff2
--- /dev/null
+++ b/libc/arch-mips64/syscalls/swapon.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(swapon)
+    .set push
+    .set noreorder
+    li v0, __NR_swapon
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(swapon)
diff --git a/libc/arch-mips64/syscalls/symlinkat.S b/libc/arch-mips64/syscalls/symlinkat.S
new file mode 100644
index 0000000..592b8e2
--- /dev/null
+++ b/libc/arch-mips64/syscalls/symlinkat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(symlinkat)
+    .set push
+    .set noreorder
+    li v0, __NR_symlinkat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(symlinkat)
diff --git a/libc/arch-mips64/syscalls/sync.S b/libc/arch-mips64/syscalls/sync.S
new file mode 100644
index 0000000..8997c1b
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sync.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sync)
+    .set push
+    .set noreorder
+    li v0, __NR_sync
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sync)
diff --git a/libc/arch-mips64/syscalls/sysinfo.S b/libc/arch-mips64/syscalls/sysinfo.S
new file mode 100644
index 0000000..a54e158
--- /dev/null
+++ b/libc/arch-mips64/syscalls/sysinfo.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sysinfo)
+    .set push
+    .set noreorder
+    li v0, __NR_sysinfo
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(sysinfo)
diff --git a/libc/arch-mips64/syscalls/tee.S b/libc/arch-mips64/syscalls/tee.S
new file mode 100644
index 0000000..99cf84b
--- /dev/null
+++ b/libc/arch-mips64/syscalls/tee.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(tee)
+    .set push
+    .set noreorder
+    li v0, __NR_tee
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(tee)
diff --git a/libc/arch-mips64/syscalls/tgkill.S b/libc/arch-mips64/syscalls/tgkill.S
new file mode 100644
index 0000000..f37f792
--- /dev/null
+++ b/libc/arch-mips64/syscalls/tgkill.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(tgkill)
+    .set push
+    .set noreorder
+    li v0, __NR_tgkill
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(tgkill)
diff --git a/libc/arch-mips64/syscalls/timerfd_create.S b/libc/arch-mips64/syscalls/timerfd_create.S
new file mode 100644
index 0000000..0e53a15
--- /dev/null
+++ b/libc/arch-mips64/syscalls/timerfd_create.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(timerfd_create)
+    .set push
+    .set noreorder
+    li v0, __NR_timerfd_create
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(timerfd_create)
diff --git a/libc/arch-mips64/syscalls/timerfd_gettime.S b/libc/arch-mips64/syscalls/timerfd_gettime.S
new file mode 100644
index 0000000..26d6832
--- /dev/null
+++ b/libc/arch-mips64/syscalls/timerfd_gettime.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(timerfd_gettime)
+    .set push
+    .set noreorder
+    li v0, __NR_timerfd_gettime
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(timerfd_gettime)
diff --git a/libc/arch-mips64/syscalls/timerfd_settime.S b/libc/arch-mips64/syscalls/timerfd_settime.S
new file mode 100644
index 0000000..b06290e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/timerfd_settime.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(timerfd_settime)
+    .set push
+    .set noreorder
+    li v0, __NR_timerfd_settime
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(timerfd_settime)
diff --git a/libc/arch-mips64/syscalls/times.S b/libc/arch-mips64/syscalls/times.S
new file mode 100644
index 0000000..fa7f64f
--- /dev/null
+++ b/libc/arch-mips64/syscalls/times.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(times)
+    .set push
+    .set noreorder
+    li v0, __NR_times
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(times)
diff --git a/libc/arch-mips64/syscalls/truncate.S b/libc/arch-mips64/syscalls/truncate.S
new file mode 100644
index 0000000..fb3b7eb
--- /dev/null
+++ b/libc/arch-mips64/syscalls/truncate.S
@@ -0,0 +1,28 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(truncate)
+    .set push
+    .set noreorder
+    li v0, __NR_truncate
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(truncate)
+
+    .globl truncate64
+    .equ truncate64, truncate
diff --git a/libc/arch-mips64/syscalls/umask.S b/libc/arch-mips64/syscalls/umask.S
new file mode 100644
index 0000000..9349030
--- /dev/null
+++ b/libc/arch-mips64/syscalls/umask.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(umask)
+    .set push
+    .set noreorder
+    li v0, __NR_umask
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(umask)
diff --git a/libc/arch-mips64/syscalls/umount2.S b/libc/arch-mips64/syscalls/umount2.S
new file mode 100644
index 0000000..cc9ad16
--- /dev/null
+++ b/libc/arch-mips64/syscalls/umount2.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(umount2)
+    .set push
+    .set noreorder
+    li v0, __NR_umount2
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(umount2)
diff --git a/libc/arch-mips64/syscalls/uname.S b/libc/arch-mips64/syscalls/uname.S
new file mode 100644
index 0000000..16157da
--- /dev/null
+++ b/libc/arch-mips64/syscalls/uname.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(uname)
+    .set push
+    .set noreorder
+    li v0, __NR_uname
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(uname)
diff --git a/libc/arch-mips64/syscalls/unlinkat.S b/libc/arch-mips64/syscalls/unlinkat.S
new file mode 100644
index 0000000..4b11679
--- /dev/null
+++ b/libc/arch-mips64/syscalls/unlinkat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(unlinkat)
+    .set push
+    .set noreorder
+    li v0, __NR_unlinkat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(unlinkat)
diff --git a/libc/arch-mips64/syscalls/unshare.S b/libc/arch-mips64/syscalls/unshare.S
new file mode 100644
index 0000000..2c82fea
--- /dev/null
+++ b/libc/arch-mips64/syscalls/unshare.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(unshare)
+    .set push
+    .set noreorder
+    li v0, __NR_unshare
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(unshare)
diff --git a/libc/arch-mips64/syscalls/utimensat.S b/libc/arch-mips64/syscalls/utimensat.S
new file mode 100644
index 0000000..48da938
--- /dev/null
+++ b/libc/arch-mips64/syscalls/utimensat.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(utimensat)
+    .set push
+    .set noreorder
+    li v0, __NR_utimensat
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(utimensat)
diff --git a/libc/arch-mips64/syscalls/vmsplice.S b/libc/arch-mips64/syscalls/vmsplice.S
new file mode 100644
index 0000000..3bcae74
--- /dev/null
+++ b/libc/arch-mips64/syscalls/vmsplice.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(vmsplice)
+    .set push
+    .set noreorder
+    li v0, __NR_vmsplice
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(vmsplice)
diff --git a/libc/arch-mips64/syscalls/wait4.S b/libc/arch-mips64/syscalls/wait4.S
new file mode 100644
index 0000000..f9c3974
--- /dev/null
+++ b/libc/arch-mips64/syscalls/wait4.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(wait4)
+    .set push
+    .set noreorder
+    li v0, __NR_wait4
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(wait4)
diff --git a/libc/arch-mips64/syscalls/write.S b/libc/arch-mips64/syscalls/write.S
new file mode 100644
index 0000000..ef9b19e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/write.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(write)
+    .set push
+    .set noreorder
+    li v0, __NR_write
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(write)
diff --git a/libc/arch-mips64/syscalls/writev.S b/libc/arch-mips64/syscalls/writev.S
new file mode 100644
index 0000000..d103d71
--- /dev/null
+++ b/libc/arch-mips64/syscalls/writev.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(writev)
+    .set push
+    .set noreorder
+    li v0, __NR_writev
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(writev)
diff --git a/libc/arch-x86/atom/atom.mk b/libc/arch-x86/atom/atom.mk
new file mode 100644
index 0000000..3f28fb2
--- /dev/null
+++ b/libc/arch-x86/atom/atom.mk
@@ -0,0 +1,32 @@
+libc_bionic_src_files_x86 += \
+    arch-x86/atom/string/sse2-bzero-atom.S \
+    arch-x86/atom/string/sse2-memchr-atom.S \
+    arch-x86/atom/string/sse2-memrchr-atom.S \
+    arch-x86/atom/string/sse2-memset-atom.S \
+    arch-x86/atom/string/sse2-strchr-atom.S \
+    arch-x86/atom/string/sse2-strlen-atom.S \
+    arch-x86/atom/string/sse2-strnlen-atom.S \
+    arch-x86/atom/string/sse2-strrchr-atom.S \
+    arch-x86/atom/string/sse2-wcschr-atom.S \
+    arch-x86/atom/string/sse2-wcsrchr-atom.S \
+    arch-x86/atom/string/sse2-wcslen-atom.S \
+    arch-x86/atom/string/sse2-wcscmp-atom.S \
+    arch-x86/atom/string/ssse3-bcopy-atom.S \
+    arch-x86/atom/string/ssse3-memcmp-atom.S \
+    arch-x86/atom/string/ssse3-memcpy-atom.S \
+    arch-x86/atom/string/ssse3-memmove-atom.S \
+    arch-x86/atom/string/ssse3-strcat-atom.S \
+    arch-x86/atom/string/ssse3-strcmp-atom.S \
+    arch-x86/atom/string/ssse3-strcpy-atom.S \
+    arch-x86/atom/string/ssse3-strlcat-atom.S \
+    arch-x86/atom/string/ssse3-strlcpy-atom.S \
+    arch-x86/atom/string/ssse3-strncat-atom.S \
+    arch-x86/atom/string/ssse3-strncmp-atom.S \
+    arch-x86/atom/string/ssse3-strncpy-atom.S \
+    arch-x86/atom/string/ssse3-wcscat-atom.S \
+    arch-x86/atom/string/ssse3-wcscpy-atom.S \
+    arch-x86/atom/string/ssse3-wmemcmp-atom.S
+
+libc_bionic_src_files_x86 += \
+    arch-x86/silvermont/string/sse2-stpcpy-slm.S \
+    arch-x86/silvermont/string/sse2-stpncpy-slm.S
diff --git a/libc/arch-x86/atom/string/cache.h b/libc/arch-x86/atom/string/cache.h
new file mode 100644
index 0000000..823bb1e
--- /dev/null
+++ b/libc/arch-x86/atom/string/cache.h
@@ -0,0 +1,36 @@
+/*
+Copyright (c) 2010, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Values are optimized for Atom */
+#define SHARED_CACHE_SIZE	(512*1024)			/* Atom L2 Cache */
+#define DATA_CACHE_SIZE		(24*1024)			/* Atom L1 Data Cache */
+
+#define SHARED_CACHE_SIZE_HALF	(SHARED_CACHE_SIZE / 2)
+#define DATA_CACHE_SIZE_HALF	(DATA_CACHE_SIZE / 2)
diff --git a/libc/arch-x86/string/sse2-bzero-atom.S b/libc/arch-x86/atom/string/sse2-bzero-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-bzero-atom.S
rename to libc/arch-x86/atom/string/sse2-bzero-atom.S
diff --git a/libc/arch-x86/string/sse2-memchr-atom.S b/libc/arch-x86/atom/string/sse2-memchr-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-memchr-atom.S
rename to libc/arch-x86/atom/string/sse2-memchr-atom.S
diff --git a/libc/arch-x86/string/sse2-memrchr-atom.S b/libc/arch-x86/atom/string/sse2-memrchr-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-memrchr-atom.S
rename to libc/arch-x86/atom/string/sse2-memrchr-atom.S
diff --git a/libc/arch-x86/atom/string/sse2-memset-atom.S b/libc/arch-x86/atom/string/sse2-memset-atom.S
new file mode 100644
index 0000000..b0963a1
--- /dev/null
+++ b/libc/arch-x86/atom/string/sse2-memset-atom.S
@@ -0,0 +1,920 @@
+/*
+Copyright (c) 2010, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef ALIGN
+# define ALIGN(n)	.p2align n
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc			.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc			.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)		.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)			\
+	.type name,  @function; 	\
+	.globl name;			\
+	.p2align 4;			\
+name:					\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)			\
+	cfi_endproc;			\
+	.size name, .-name
+#endif
+
+#define CFI_PUSH(REG)						\
+  cfi_adjust_cfa_offset (4);					\
+  cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)						\
+  cfi_adjust_cfa_offset (-4);					\
+  cfi_restore (REG)
+
+#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
+#define POP(REG)	popl REG; CFI_POP (REG)
+
+#ifdef USE_AS_BZERO
+# define DEST		PARMS
+# define LEN		DEST+4
+# define SETRTNVAL
+#else
+# define DEST		PARMS
+# define CHR		DEST+4
+# define LEN		CHR+4
+# define SETRTNVAL	movl DEST(%esp), %eax
+#endif
+
+#if (defined SHARED || defined __PIC__)
+# define ENTRANCE	PUSH (%ebx);
+# define RETURN_END	POP (%ebx); ret
+# define RETURN		RETURN_END; CFI_PUSH (%ebx)
+# define PARMS		8		/* Preserve EBX.  */
+# define JMPTBL(I, B)	I - B
+
+/* Load an entry in a jump table into EBX and branch to it.  TABLE is a
+   jump table with relative offsets.   */
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE)				\
+    /* We first load PC into EBX.  */				\
+    call	__x86.get_pc_thunk.bx;				\
+    /* Get the address of the jump table.  */			\
+    add		$(TABLE - .), %ebx;				\
+    /* Get the entry and convert the relative offset to the	\
+       absolute address.  */					\
+    add		(%ebx,%ecx,4), %ebx;				\
+    add		%ecx, %edx;					\
+    /* We loaded the jump table and adjuested EDX. Go.  */	\
+    jmp		*%ebx
+
+	.section	.gnu.linkonce.t.__x86.get_pc_thunk.bx,"ax",@progbits
+	.globl	__x86.get_pc_thunk.bx
+	.hidden	__x86.get_pc_thunk.bx
+	ALIGN (4)
+	.type	__x86.get_pc_thunk.bx,@function
+__x86.get_pc_thunk.bx:
+	movl	(%esp), %ebx
+	ret
+#else
+# define ENTRANCE
+# define RETURN_END	ret
+# define RETURN		RETURN_END
+# define PARMS		4
+# define JMPTBL(I, B)	I
+
+/* Branch to an entry in a jump table.  TABLE is a jump table with
+   absolute offsets.  */
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE)				\
+    add		%ecx, %edx;					\
+    jmp		*TABLE(,%ecx,4)
+#endif
+
+#ifndef MEMSET
+# define MEMSET memset
+#endif
+
+	.section .text.sse2,"ax",@progbits
+	ALIGN (4)
+ENTRY (MEMSET)
+	ENTRANCE
+
+	movl	LEN(%esp), %ecx
+#ifdef USE_AS_BZERO
+	xor	%eax, %eax
+#else
+	movzbl	CHR(%esp), %eax
+	movb	%al, %ah
+	/* Fill the whole EAX with pattern.  */
+	movl	%eax, %edx
+	shl	$16, %eax
+	or	%edx, %eax
+#endif
+	movl	DEST(%esp), %edx
+	cmp	$32, %ecx
+	jae	L(32bytesormore)
+
+L(write_less32bytes):
+	BRANCH_TO_JMPTBL_ENTRY (L(table_less_32bytes))
+
+
+	.pushsection .rodata.sse2,"a",@progbits
+	ALIGN (2)
+L(table_less_32bytes):
+	.int	JMPTBL (L(write_0bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_1bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_2bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_3bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_4bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_5bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_6bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_7bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_8bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_9bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_10bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_11bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_12bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_13bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_14bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_15bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_16bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_17bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_18bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_19bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_20bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_21bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_22bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_23bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_24bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_25bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_26bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_27bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_28bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_29bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_30bytes), L(table_less_32bytes))
+	.int	JMPTBL (L(write_31bytes), L(table_less_32bytes))
+	.popsection
+
+	ALIGN (4)
+L(write_28bytes):
+	movl	%eax, -28(%edx)
+L(write_24bytes):
+	movl	%eax, -24(%edx)
+L(write_20bytes):
+	movl	%eax, -20(%edx)
+L(write_16bytes):
+	movl	%eax, -16(%edx)
+L(write_12bytes):
+	movl	%eax, -12(%edx)
+L(write_8bytes):
+	movl	%eax, -8(%edx)
+L(write_4bytes):
+	movl	%eax, -4(%edx)
+L(write_0bytes):
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(write_29bytes):
+	movl	%eax, -29(%edx)
+L(write_25bytes):
+	movl	%eax, -25(%edx)
+L(write_21bytes):
+	movl	%eax, -21(%edx)
+L(write_17bytes):
+	movl	%eax, -17(%edx)
+L(write_13bytes):
+	movl	%eax, -13(%edx)
+L(write_9bytes):
+	movl	%eax, -9(%edx)
+L(write_5bytes):
+	movl	%eax, -5(%edx)
+L(write_1bytes):
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(write_30bytes):
+	movl	%eax, -30(%edx)
+L(write_26bytes):
+	movl	%eax, -26(%edx)
+L(write_22bytes):
+	movl	%eax, -22(%edx)
+L(write_18bytes):
+	movl	%eax, -18(%edx)
+L(write_14bytes):
+	movl	%eax, -14(%edx)
+L(write_10bytes):
+	movl	%eax, -10(%edx)
+L(write_6bytes):
+	movl	%eax, -6(%edx)
+L(write_2bytes):
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(write_31bytes):
+	movl	%eax, -31(%edx)
+L(write_27bytes):
+	movl	%eax, -27(%edx)
+L(write_23bytes):
+	movl	%eax, -23(%edx)
+L(write_19bytes):
+	movl	%eax, -19(%edx)
+L(write_15bytes):
+	movl	%eax, -15(%edx)
+L(write_11bytes):
+	movl	%eax, -11(%edx)
+L(write_7bytes):
+	movl	%eax, -7(%edx)
+L(write_3bytes):
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+/* ECX > 32 and EDX is 4 byte aligned.  */
+L(32bytesormore):
+	/* Fill xmm0 with the pattern.  */
+#ifdef USE_AS_BZERO
+	pxor	%xmm0, %xmm0
+#else
+	movd	%eax, %xmm0
+	pshufd	$0, %xmm0, %xmm0
+#endif
+	testl	$0xf, %edx
+	jz	L(aligned_16)
+/* ECX > 32 and EDX is not 16 byte aligned.  */
+L(not_aligned_16):
+	movdqu	%xmm0, (%edx)
+	movl	%edx, %eax
+	and	$-16, %edx
+	add	$16, %edx
+	sub	%edx, %eax
+	add	%eax, %ecx
+	movd	%xmm0, %eax
+
+	ALIGN (4)
+L(aligned_16):
+	cmp	$128, %ecx
+	jae	L(128bytesormore)
+
+L(aligned_16_less128bytes):
+	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+
+	ALIGN (4)
+L(128bytesormore):
+#ifdef SHARED_CACHE_SIZE
+	PUSH (%ebx)
+	mov	$SHARED_CACHE_SIZE, %ebx
+#else
+# if (defined SHARED || defined __PIC__)
+	call	__x86.get_pc_thunk.bx
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	mov	__x86_shared_cache_size@GOTOFF(%ebx), %ebx
+# else
+	PUSH (%ebx)
+	mov	__x86_shared_cache_size, %ebx
+# endif
+#endif
+	cmp	%ebx, %ecx
+	jae	L(128bytesormore_nt_start)
+
+
+#ifdef DATA_CACHE_SIZE
+	POP (%ebx)
+# define RESTORE_EBX_STATE CFI_PUSH (%ebx)
+	cmp	$DATA_CACHE_SIZE, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+#  define RESTORE_EBX_STATE
+	call	__x86.get_pc_thunk.bx
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size@GOTOFF(%ebx), %ecx
+# else
+	POP (%ebx)
+#  define RESTORE_EBX_STATE CFI_PUSH (%ebx)
+	cmp	__x86_data_cache_size, %ecx
+# endif
+#endif
+
+	jae	L(128bytes_L2_normal)
+	subl	$128, %ecx
+L(128bytesormore_normal):
+	sub	$128, %ecx
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm0, 0x10(%edx)
+	movdqa	%xmm0, 0x20(%edx)
+	movdqa	%xmm0, 0x30(%edx)
+	movdqa	%xmm0, 0x40(%edx)
+	movdqa	%xmm0, 0x50(%edx)
+	movdqa	%xmm0, 0x60(%edx)
+	movdqa	%xmm0, 0x70(%edx)
+	lea	128(%edx), %edx
+	jb	L(128bytesless_normal)
+
+
+	sub	$128, %ecx
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm0, 0x10(%edx)
+	movdqa	%xmm0, 0x20(%edx)
+	movdqa	%xmm0, 0x30(%edx)
+	movdqa	%xmm0, 0x40(%edx)
+	movdqa	%xmm0, 0x50(%edx)
+	movdqa	%xmm0, 0x60(%edx)
+	movdqa	%xmm0, 0x70(%edx)
+	lea	128(%edx), %edx
+	jae	L(128bytesormore_normal)
+
+L(128bytesless_normal):
+	add	$128, %ecx
+	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+
+	ALIGN (4)
+L(128bytes_L2_normal):
+	prefetcht0	0x380(%edx)
+	prefetcht0	0x3c0(%edx)
+	sub	$128, %ecx
+	movdqa	%xmm0, (%edx)
+	movaps	%xmm0, 0x10(%edx)
+	movaps	%xmm0, 0x20(%edx)
+	movaps	%xmm0, 0x30(%edx)
+	movaps	%xmm0, 0x40(%edx)
+	movaps	%xmm0, 0x50(%edx)
+	movaps	%xmm0, 0x60(%edx)
+	movaps	%xmm0, 0x70(%edx)
+	add	$128, %edx
+	cmp	$128, %ecx
+	jae	L(128bytes_L2_normal)
+
+L(128bytesless_L2_normal):
+	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+
+	RESTORE_EBX_STATE
+L(128bytesormore_nt_start):
+	sub	%ebx, %ecx
+	mov	%ebx, %eax
+	and	$0x7f, %eax
+	add	%eax, %ecx
+	movd	%xmm0, %eax
+	ALIGN (4)
+L(128bytesormore_shared_cache_loop):
+	prefetcht0	0x3c0(%edx)
+	prefetcht0	0x380(%edx)
+	sub	$0x80, %ebx
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm0, 0x10(%edx)
+	movdqa	%xmm0, 0x20(%edx)
+	movdqa	%xmm0, 0x30(%edx)
+	movdqa	%xmm0, 0x40(%edx)
+	movdqa	%xmm0, 0x50(%edx)
+	movdqa	%xmm0, 0x60(%edx)
+	movdqa	%xmm0, 0x70(%edx)
+	add	$0x80, %edx
+	cmp	$0x80, %ebx
+	jae	L(128bytesormore_shared_cache_loop)
+	cmp	$0x80, %ecx
+	jb	L(shared_cache_loop_end)
+	ALIGN (4)
+L(128bytesormore_nt):
+	sub	$0x80, %ecx
+	movntdq	%xmm0, (%edx)
+	movntdq	%xmm0, 0x10(%edx)
+	movntdq	%xmm0, 0x20(%edx)
+	movntdq	%xmm0, 0x30(%edx)
+	movntdq	%xmm0, 0x40(%edx)
+	movntdq	%xmm0, 0x50(%edx)
+	movntdq	%xmm0, 0x60(%edx)
+	movntdq	%xmm0, 0x70(%edx)
+	add	$0x80, %edx
+	cmp	$0x80, %ecx
+	jae	L(128bytesormore_nt)
+	sfence
+L(shared_cache_loop_end):
+#if defined DATA_CACHE_SIZE || !(defined SHARED || defined __PIC__)
+	POP (%ebx)
+#endif
+	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+
+
+	.pushsection .rodata.sse2,"a",@progbits
+	ALIGN (2)
+L(table_16_128bytes):
+	.int	JMPTBL (L(aligned_16_0bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_1bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_2bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_3bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_4bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_5bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_6bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_7bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_8bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_9bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_10bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_11bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_12bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_13bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_14bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_15bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_16bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_17bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_18bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_19bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_20bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_21bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_22bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_23bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_24bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_25bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_26bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_27bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_28bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_29bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_30bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_31bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_32bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_33bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_34bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_35bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_36bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_37bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_38bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_39bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_40bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_41bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_42bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_43bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_44bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_45bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_46bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_47bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_48bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_49bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_50bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_51bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_52bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_53bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_54bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_55bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_56bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_57bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_58bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_59bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_60bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_61bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_62bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_63bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_64bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_65bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_66bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_67bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_68bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_69bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_70bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_71bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_72bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_73bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_74bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_75bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_76bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_77bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_78bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_79bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_80bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_81bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_82bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_83bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_84bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_85bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_86bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_87bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_88bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_89bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_90bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_91bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_92bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_93bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_94bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_95bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_96bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_97bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_98bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_99bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_100bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_101bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_102bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_103bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_104bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_105bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_106bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_107bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_108bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_109bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_110bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_111bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_112bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_113bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_114bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_115bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_116bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_117bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_118bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_119bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_120bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_121bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_122bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_123bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_124bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_125bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_126bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_127bytes), L(table_16_128bytes))
+	.popsection
+
+	ALIGN (4)
+L(aligned_16_112bytes):
+	movdqa	%xmm0, -112(%edx)
+L(aligned_16_96bytes):
+	movdqa	%xmm0, -96(%edx)
+L(aligned_16_80bytes):
+	movdqa	%xmm0, -80(%edx)
+L(aligned_16_64bytes):
+	movdqa	%xmm0, -64(%edx)
+L(aligned_16_48bytes):
+	movdqa	%xmm0, -48(%edx)
+L(aligned_16_32bytes):
+	movdqa	%xmm0, -32(%edx)
+L(aligned_16_16bytes):
+	movdqa	%xmm0, -16(%edx)
+L(aligned_16_0bytes):
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_113bytes):
+	movdqa	%xmm0, -113(%edx)
+L(aligned_16_97bytes):
+	movdqa	%xmm0, -97(%edx)
+L(aligned_16_81bytes):
+	movdqa	%xmm0, -81(%edx)
+L(aligned_16_65bytes):
+	movdqa	%xmm0, -65(%edx)
+L(aligned_16_49bytes):
+	movdqa	%xmm0, -49(%edx)
+L(aligned_16_33bytes):
+	movdqa	%xmm0, -33(%edx)
+L(aligned_16_17bytes):
+	movdqa	%xmm0, -17(%edx)
+L(aligned_16_1bytes):
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_114bytes):
+	movdqa	%xmm0, -114(%edx)
+L(aligned_16_98bytes):
+	movdqa	%xmm0, -98(%edx)
+L(aligned_16_82bytes):
+	movdqa	%xmm0, -82(%edx)
+L(aligned_16_66bytes):
+	movdqa	%xmm0, -66(%edx)
+L(aligned_16_50bytes):
+	movdqa	%xmm0, -50(%edx)
+L(aligned_16_34bytes):
+	movdqa	%xmm0, -34(%edx)
+L(aligned_16_18bytes):
+	movdqa	%xmm0, -18(%edx)
+L(aligned_16_2bytes):
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_115bytes):
+	movdqa	%xmm0, -115(%edx)
+L(aligned_16_99bytes):
+	movdqa	%xmm0, -99(%edx)
+L(aligned_16_83bytes):
+	movdqa	%xmm0, -83(%edx)
+L(aligned_16_67bytes):
+	movdqa	%xmm0, -67(%edx)
+L(aligned_16_51bytes):
+	movdqa	%xmm0, -51(%edx)
+L(aligned_16_35bytes):
+	movdqa	%xmm0, -35(%edx)
+L(aligned_16_19bytes):
+	movdqa	%xmm0, -19(%edx)
+L(aligned_16_3bytes):
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_116bytes):
+	movdqa	%xmm0, -116(%edx)
+L(aligned_16_100bytes):
+	movdqa	%xmm0, -100(%edx)
+L(aligned_16_84bytes):
+	movdqa	%xmm0, -84(%edx)
+L(aligned_16_68bytes):
+	movdqa	%xmm0, -68(%edx)
+L(aligned_16_52bytes):
+	movdqa	%xmm0, -52(%edx)
+L(aligned_16_36bytes):
+	movdqa	%xmm0, -36(%edx)
+L(aligned_16_20bytes):
+	movdqa	%xmm0, -20(%edx)
+L(aligned_16_4bytes):
+	movl	%eax, -4(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_117bytes):
+	movdqa	%xmm0, -117(%edx)
+L(aligned_16_101bytes):
+	movdqa	%xmm0, -101(%edx)
+L(aligned_16_85bytes):
+	movdqa	%xmm0, -85(%edx)
+L(aligned_16_69bytes):
+	movdqa	%xmm0, -69(%edx)
+L(aligned_16_53bytes):
+	movdqa	%xmm0, -53(%edx)
+L(aligned_16_37bytes):
+	movdqa	%xmm0, -37(%edx)
+L(aligned_16_21bytes):
+	movdqa	%xmm0, -21(%edx)
+L(aligned_16_5bytes):
+	movl	%eax, -5(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_118bytes):
+	movdqa	%xmm0, -118(%edx)
+L(aligned_16_102bytes):
+	movdqa	%xmm0, -102(%edx)
+L(aligned_16_86bytes):
+	movdqa	%xmm0, -86(%edx)
+L(aligned_16_70bytes):
+	movdqa	%xmm0, -70(%edx)
+L(aligned_16_54bytes):
+	movdqa	%xmm0, -54(%edx)
+L(aligned_16_38bytes):
+	movdqa	%xmm0, -38(%edx)
+L(aligned_16_22bytes):
+	movdqa	%xmm0, -22(%edx)
+L(aligned_16_6bytes):
+	movl	%eax, -6(%edx)
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_119bytes):
+	movdqa	%xmm0, -119(%edx)
+L(aligned_16_103bytes):
+	movdqa	%xmm0, -103(%edx)
+L(aligned_16_87bytes):
+	movdqa	%xmm0, -87(%edx)
+L(aligned_16_71bytes):
+	movdqa	%xmm0, -71(%edx)
+L(aligned_16_55bytes):
+	movdqa	%xmm0, -55(%edx)
+L(aligned_16_39bytes):
+	movdqa	%xmm0, -39(%edx)
+L(aligned_16_23bytes):
+	movdqa	%xmm0, -23(%edx)
+L(aligned_16_7bytes):
+	movl	%eax, -7(%edx)
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_120bytes):
+	movdqa	%xmm0, -120(%edx)
+L(aligned_16_104bytes):
+	movdqa	%xmm0, -104(%edx)
+L(aligned_16_88bytes):
+	movdqa	%xmm0, -88(%edx)
+L(aligned_16_72bytes):
+	movdqa	%xmm0, -72(%edx)
+L(aligned_16_56bytes):
+	movdqa	%xmm0, -56(%edx)
+L(aligned_16_40bytes):
+	movdqa	%xmm0, -40(%edx)
+L(aligned_16_24bytes):
+	movdqa	%xmm0, -24(%edx)
+L(aligned_16_8bytes):
+	movq	%xmm0, -8(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_121bytes):
+	movdqa	%xmm0, -121(%edx)
+L(aligned_16_105bytes):
+	movdqa	%xmm0, -105(%edx)
+L(aligned_16_89bytes):
+	movdqa	%xmm0, -89(%edx)
+L(aligned_16_73bytes):
+	movdqa	%xmm0, -73(%edx)
+L(aligned_16_57bytes):
+	movdqa	%xmm0, -57(%edx)
+L(aligned_16_41bytes):
+	movdqa	%xmm0, -41(%edx)
+L(aligned_16_25bytes):
+	movdqa	%xmm0, -25(%edx)
+L(aligned_16_9bytes):
+	movq	%xmm0, -9(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_122bytes):
+	movdqa	%xmm0, -122(%edx)
+L(aligned_16_106bytes):
+	movdqa	%xmm0, -106(%edx)
+L(aligned_16_90bytes):
+	movdqa	%xmm0, -90(%edx)
+L(aligned_16_74bytes):
+	movdqa	%xmm0, -74(%edx)
+L(aligned_16_58bytes):
+	movdqa	%xmm0, -58(%edx)
+L(aligned_16_42bytes):
+	movdqa	%xmm0, -42(%edx)
+L(aligned_16_26bytes):
+	movdqa	%xmm0, -26(%edx)
+L(aligned_16_10bytes):
+	movq	%xmm0, -10(%edx)
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_123bytes):
+	movdqa	%xmm0, -123(%edx)
+L(aligned_16_107bytes):
+	movdqa	%xmm0, -107(%edx)
+L(aligned_16_91bytes):
+	movdqa	%xmm0, -91(%edx)
+L(aligned_16_75bytes):
+	movdqa	%xmm0, -75(%edx)
+L(aligned_16_59bytes):
+	movdqa	%xmm0, -59(%edx)
+L(aligned_16_43bytes):
+	movdqa	%xmm0, -43(%edx)
+L(aligned_16_27bytes):
+	movdqa	%xmm0, -27(%edx)
+L(aligned_16_11bytes):
+	movq	%xmm0, -11(%edx)
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_124bytes):
+	movdqa	%xmm0, -124(%edx)
+L(aligned_16_108bytes):
+	movdqa	%xmm0, -108(%edx)
+L(aligned_16_92bytes):
+	movdqa	%xmm0, -92(%edx)
+L(aligned_16_76bytes):
+	movdqa	%xmm0, -76(%edx)
+L(aligned_16_60bytes):
+	movdqa	%xmm0, -60(%edx)
+L(aligned_16_44bytes):
+	movdqa	%xmm0, -44(%edx)
+L(aligned_16_28bytes):
+	movdqa	%xmm0, -28(%edx)
+L(aligned_16_12bytes):
+	movq	%xmm0, -12(%edx)
+	movl	%eax, -4(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_125bytes):
+	movdqa	%xmm0, -125(%edx)
+L(aligned_16_109bytes):
+	movdqa	%xmm0, -109(%edx)
+L(aligned_16_93bytes):
+	movdqa	%xmm0, -93(%edx)
+L(aligned_16_77bytes):
+	movdqa	%xmm0, -77(%edx)
+L(aligned_16_61bytes):
+	movdqa	%xmm0, -61(%edx)
+L(aligned_16_45bytes):
+	movdqa	%xmm0, -45(%edx)
+L(aligned_16_29bytes):
+	movdqa	%xmm0, -29(%edx)
+L(aligned_16_13bytes):
+	movq	%xmm0, -13(%edx)
+	movl	%eax, -5(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_126bytes):
+	movdqa	%xmm0, -126(%edx)
+L(aligned_16_110bytes):
+	movdqa	%xmm0, -110(%edx)
+L(aligned_16_94bytes):
+	movdqa	%xmm0, -94(%edx)
+L(aligned_16_78bytes):
+	movdqa	%xmm0, -78(%edx)
+L(aligned_16_62bytes):
+	movdqa	%xmm0, -62(%edx)
+L(aligned_16_46bytes):
+	movdqa	%xmm0, -46(%edx)
+L(aligned_16_30bytes):
+	movdqa	%xmm0, -30(%edx)
+L(aligned_16_14bytes):
+	movq	%xmm0, -14(%edx)
+	movl	%eax, -6(%edx)
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_127bytes):
+	movdqa	%xmm0, -127(%edx)
+L(aligned_16_111bytes):
+	movdqa	%xmm0, -111(%edx)
+L(aligned_16_95bytes):
+	movdqa	%xmm0, -95(%edx)
+L(aligned_16_79bytes):
+	movdqa	%xmm0, -79(%edx)
+L(aligned_16_63bytes):
+	movdqa	%xmm0, -63(%edx)
+L(aligned_16_47bytes):
+	movdqa	%xmm0, -47(%edx)
+L(aligned_16_31bytes):
+	movdqa	%xmm0, -31(%edx)
+L(aligned_16_15bytes):
+	movq	%xmm0, -15(%edx)
+	movl	%eax, -7(%edx)
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN_END
+
+END (MEMSET)
diff --git a/libc/arch-x86/string/sse2-strchr-atom.S b/libc/arch-x86/atom/string/sse2-strchr-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-strchr-atom.S
rename to libc/arch-x86/atom/string/sse2-strchr-atom.S
diff --git a/libc/arch-x86/string/sse2-strlen-atom.S b/libc/arch-x86/atom/string/sse2-strlen-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-strlen-atom.S
rename to libc/arch-x86/atom/string/sse2-strlen-atom.S
diff --git a/libc/arch-x86/string/sse2-strnlen-atom.S b/libc/arch-x86/atom/string/sse2-strnlen-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-strnlen-atom.S
rename to libc/arch-x86/atom/string/sse2-strnlen-atom.S
diff --git a/libc/arch-x86/string/sse2-strrchr-atom.S b/libc/arch-x86/atom/string/sse2-strrchr-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-strrchr-atom.S
rename to libc/arch-x86/atom/string/sse2-strrchr-atom.S
diff --git a/libc/arch-x86/string/sse2-wcschr-atom.S b/libc/arch-x86/atom/string/sse2-wcschr-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-wcschr-atom.S
rename to libc/arch-x86/atom/string/sse2-wcschr-atom.S
diff --git a/libc/arch-x86/string/sse2-wcscmp-atom.S b/libc/arch-x86/atom/string/sse2-wcscmp-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-wcscmp-atom.S
rename to libc/arch-x86/atom/string/sse2-wcscmp-atom.S
diff --git a/libc/arch-x86/string/sse2-wcslen-atom.S b/libc/arch-x86/atom/string/sse2-wcslen-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-wcslen-atom.S
rename to libc/arch-x86/atom/string/sse2-wcslen-atom.S
diff --git a/libc/arch-x86/string/sse2-wcsrchr-atom.S b/libc/arch-x86/atom/string/sse2-wcsrchr-atom.S
similarity index 100%
rename from libc/arch-x86/string/sse2-wcsrchr-atom.S
rename to libc/arch-x86/atom/string/sse2-wcsrchr-atom.S
diff --git a/libc/arch-x86/string/ssse3-bcopy-atom.S b/libc/arch-x86/atom/string/ssse3-bcopy-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-bcopy-atom.S
rename to libc/arch-x86/atom/string/ssse3-bcopy-atom.S
diff --git a/libc/arch-x86/string/ssse3-memcmp-atom.S b/libc/arch-x86/atom/string/ssse3-memcmp-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-memcmp-atom.S
rename to libc/arch-x86/atom/string/ssse3-memcmp-atom.S
diff --git a/libc/arch-x86/atom/string/ssse3-memcpy-atom.S b/libc/arch-x86/atom/string/ssse3-memcpy-atom.S
new file mode 100644
index 0000000..ac5ec2d
--- /dev/null
+++ b/libc/arch-x86/atom/string/ssse3-memcpy-atom.S
@@ -0,0 +1,3198 @@
+/*
+Copyright (c) 2010, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef MEMCPY
+# define MEMCPY	memcpy
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)		\
+	.type name,  @function;		\
+	.globl name;		\
+	.p2align 4;		\
+name:		\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)		\
+	cfi_endproc;		\
+	.size name, .-name
+#endif
+
+#ifdef USE_AS_BCOPY
+# define SRC		PARMS
+# define DEST		SRC+4
+# define LEN		DEST+4
+#else
+# define DEST		PARMS
+# define SRC		DEST+4
+# define LEN		SRC+4
+#endif
+
+#define CFI_PUSH(REG)		\
+  cfi_adjust_cfa_offset (4);		\
+  cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)		\
+  cfi_adjust_cfa_offset (-4);		\
+  cfi_restore (REG)
+
+#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
+#define POP(REG)	popl REG; CFI_POP (REG)
+
+#if (defined SHARED || defined __PIC__)
+# define PARMS		8		/* Preserve EBX.  */
+# define ENTRANCE	PUSH (%ebx);
+# define RETURN_END	POP (%ebx); ret
+# define RETURN		RETURN_END; CFI_PUSH (%ebx)
+# define JMPTBL(I, B)	I - B
+
+# define SETUP_PIC_REG(x)	call	__x86.get_pc_thunk.x
+
+/* Load an entry in a jump table into EBX and branch to it.  TABLE is a
+	jump table with relative offsets.  INDEX is a register contains the
+	index into the jump table.   SCALE is the scale of INDEX. */
+
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)		\
+    /* We first load PC into EBX.  */		\
+	SETUP_PIC_REG(bx);		\
+    /* Get the address of the jump table.  */		\
+	addl	$(TABLE - .), %ebx;		\
+    /* Get the entry and convert the relative offset to the		\
+	absolute	address.  */		\
+	addl	(%ebx, INDEX, SCALE), %ebx;		\
+    /* We loaded the jump table.  Go.  */		\
+	jmp	*%ebx
+#else
+
+# define PARMS		4
+# define ENTRANCE
+# define RETURN_END	ret
+# define RETURN		RETURN_END
+# define JMPTBL(I, B)	I
+
+/* Branch to an entry in a jump table.  TABLE is a jump table with
+	absolute offsets.  INDEX is a register contains the index into the
+	jump table.  SCALE is the scale of INDEX. */
+
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)		\
+	jmp	*TABLE(, INDEX, SCALE)
+#endif
+
+	.section .text.ssse3,"ax",@progbits
+ENTRY (MEMCPY)
+	ENTRANCE
+	movl	LEN(%esp), %ecx
+	movl	SRC(%esp), %eax
+	movl	DEST(%esp), %edx
+
+#ifdef USE_AS_MEMMOVE
+	cmp	%eax, %edx
+	jb	L(copy_forward)
+	je	L(fwd_write_0bytes)
+	cmp	$32, %ecx
+	jae	L(memmove_bwd)
+	jmp	L(bk_write_less32bytes_2)
+
+	.p2align 4
+L(memmove_bwd):
+	add	%ecx, %eax
+	cmp	%eax, %edx
+	movl	SRC(%esp), %eax
+	jb	L(copy_backward)
+
+L(copy_forward):
+#endif
+	cmp	$48, %ecx
+	jae	L(48bytesormore)
+
+L(fwd_write_less32bytes):
+#ifndef USE_AS_MEMMOVE
+	cmp	%dl, %al
+	jb	L(bk_write)
+#endif
+	add	%ecx, %edx
+	add	%ecx, %eax
+	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd), %ecx, 4)
+#ifndef USE_AS_MEMMOVE
+	.p2align 4
+L(bk_write):
+	BRANCH_TO_JMPTBL_ENTRY (L(table_48_bytes_bwd), %ecx, 4)
+#endif
+
+	.p2align 4
+L(48bytesormore):
+#ifndef USE_AS_MEMMOVE
+	movlpd	(%eax), %xmm0
+	movlpd	8(%eax), %xmm1
+	movlpd	%xmm0, (%edx)
+	movlpd	%xmm1, 8(%edx)
+#else
+	movdqu	(%eax), %xmm0
+#endif
+	PUSH (%edi)
+	movl	%edx, %edi
+	and	$-16, %edx
+	add	$16, %edx
+	sub	%edx, %edi
+	add	%edi, %ecx
+	sub	%edi, %eax
+
+#ifdef SHARED_CACHE_SIZE_HALF
+	cmp	$SHARED_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_shared_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_shared_cache_size_half, %ecx
+# endif
+#endif
+
+	mov	%eax, %edi
+	jae	L(large_page)
+	and	$0xf, %edi
+	jz	L(shl_0)
+	BRANCH_TO_JMPTBL_ENTRY (L(shl_table), %edi, 4)
+
+	.p2align 4
+L(shl_0):
+#ifdef USE_AS_MEMMOVE
+	movl	DEST+4(%esp), %edi
+	movdqu	%xmm0, (%edi)
+#endif
+	xor	%edi, %edi
+	cmp	$127, %ecx
+	ja	L(shl_0_gobble)
+	lea	-32(%ecx), %ecx
+
+	.p2align 4
+L(shl_0_loop):
+	movdqa	(%eax, %edi), %xmm0
+	movdqa	16(%eax, %edi), %xmm1
+	sub	$32, %ecx
+	movdqa	%xmm0, (%edx, %edi)
+	movdqa	%xmm1, 16(%edx, %edi)
+	lea	32(%edi), %edi
+	jb	L(shl_0_end)
+
+	movdqa	(%eax, %edi), %xmm0
+	movdqa	16(%eax, %edi), %xmm1
+	sub	$32, %ecx
+	movdqa	%xmm0, (%edx, %edi)
+	movdqa	%xmm1, 16(%edx, %edi)
+	lea	32(%edi), %edi
+	jb	L(shl_0_end)
+
+	movdqa	(%eax, %edi), %xmm0
+	movdqa	16(%eax, %edi), %xmm1
+	sub	$32, %ecx
+	movdqa	%xmm0, (%edx, %edi)
+	movdqa	%xmm1, 16(%edx, %edi)
+	lea	32(%edi), %edi
+	jb	L(shl_0_end)
+
+	movdqa	(%eax, %edi), %xmm0
+	movdqa	16(%eax, %edi), %xmm1
+	sub	$32, %ecx
+	movdqa	%xmm0, (%edx, %edi)
+	movdqa	%xmm1, 16(%edx, %edi)
+	lea	32(%edi), %edi
+
+L(shl_0_end):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	add	%edi, %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd_align), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_0_gobble):
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	POP	(%edi)
+	lea	-128(%ecx), %ecx
+	jae	L(shl_0_gobble_mem_loop)
+
+	.p2align 4
+L(shl_0_gobble_cache_loop):
+	movdqa	(%eax), %xmm0
+	movdqa	0x10(%eax), %xmm1
+	movdqa	0x20(%eax), %xmm2
+	movdqa	0x30(%eax), %xmm3
+	movdqa	0x40(%eax), %xmm4
+	movdqa	0x50(%eax), %xmm5
+	movdqa	0x60(%eax), %xmm6
+	movdqa	0x70(%eax), %xmm7
+	lea	0x80(%eax), %eax
+	sub	$128, %ecx
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm1, 0x10(%edx)
+	movdqa	%xmm2, 0x20(%edx)
+	movdqa	%xmm3, 0x30(%edx)
+	movdqa	%xmm4, 0x40(%edx)
+	movdqa	%xmm5, 0x50(%edx)
+	movdqa	%xmm6, 0x60(%edx)
+	movdqa	%xmm7, 0x70(%edx)
+	lea	0x80(%edx), %edx
+
+	jae	L(shl_0_gobble_cache_loop)
+	cmp	$-0x40, %ecx
+	lea	0x80(%ecx), %ecx
+	jl	L(shl_0_cache_less_64bytes)
+
+	movdqa	(%eax), %xmm0
+	sub	$0x40, %ecx
+	movdqa	0x10(%eax), %xmm1
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm1, 0x10(%edx)
+	movdqa	0x20(%eax), %xmm0
+	movdqa	0x30(%eax), %xmm1
+	add	$0x40, %eax
+	movdqa	%xmm0, 0x20(%edx)
+	movdqa	%xmm1, 0x30(%edx)
+	add	$0x40, %edx
+
+L(shl_0_cache_less_64bytes):
+	cmp	$0x20, %ecx
+	jb	L(shl_0_cache_less_32bytes)
+	movdqa	(%eax), %xmm0
+	sub	$0x20, %ecx
+	movdqa	0x10(%eax), %xmm1
+	add	$0x20, %eax
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm1, 0x10(%edx)
+	add	$0x20, %edx
+
+L(shl_0_cache_less_32bytes):
+	cmp	$0x10, %ecx
+	jb	L(shl_0_cache_less_16bytes)
+	sub	$0x10, %ecx
+	movdqa	(%eax), %xmm0
+	add	$0x10, %eax
+	movdqa	%xmm0, (%edx)
+	add	$0x10, %edx
+
+L(shl_0_cache_less_16bytes):
+	add	%ecx, %edx
+	add	%ecx, %eax
+	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd), %ecx, 4)
+
+	.p2align 4
+L(shl_0_gobble_mem_loop):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x280(%eax)
+	prefetcht0 0x1c0(%edx)
+
+	movdqa	(%eax), %xmm0
+	movdqa	0x10(%eax), %xmm1
+	movdqa	0x20(%eax), %xmm2
+	movdqa	0x30(%eax), %xmm3
+	movdqa	0x40(%eax), %xmm4
+	movdqa	0x50(%eax), %xmm5
+	movdqa	0x60(%eax), %xmm6
+	movdqa	0x70(%eax), %xmm7
+	lea	0x80(%eax), %eax
+	sub	$0x80, %ecx
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm1, 0x10(%edx)
+	movdqa	%xmm2, 0x20(%edx)
+	movdqa	%xmm3, 0x30(%edx)
+	movdqa	%xmm4, 0x40(%edx)
+	movdqa	%xmm5, 0x50(%edx)
+	movdqa	%xmm6, 0x60(%edx)
+	movdqa	%xmm7, 0x70(%edx)
+	lea	0x80(%edx), %edx
+
+	jae	L(shl_0_gobble_mem_loop)
+	cmp	$-0x40, %ecx
+	lea	0x80(%ecx), %ecx
+	jl	L(shl_0_mem_less_64bytes)
+
+	movdqa	(%eax), %xmm0
+	sub	$0x40, %ecx
+	movdqa	0x10(%eax), %xmm1
+
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm1, 0x10(%edx)
+
+	movdqa	0x20(%eax), %xmm0
+	movdqa	0x30(%eax), %xmm1
+	add	$0x40, %eax
+
+	movdqa	%xmm0, 0x20(%edx)
+	movdqa	%xmm1, 0x30(%edx)
+	add	$0x40, %edx
+
+L(shl_0_mem_less_64bytes):
+	cmp	$0x20, %ecx
+	jb	L(shl_0_mem_less_32bytes)
+	movdqa	(%eax), %xmm0
+	sub	$0x20, %ecx
+	movdqa	0x10(%eax), %xmm1
+	add	$0x20, %eax
+	movdqa	%xmm0, (%edx)
+	movdqa	%xmm1, 0x10(%edx)
+	add	$0x20, %edx
+
+L(shl_0_mem_less_32bytes):
+	cmp	$0x10, %ecx
+	jb	L(shl_0_mem_less_16bytes)
+	sub	$0x10, %ecx
+	movdqa	(%eax), %xmm0
+	add	$0x10, %eax
+	movdqa	%xmm0, (%edx)
+	add	$0x10, %edx
+
+L(shl_0_mem_less_16bytes):
+	add	%ecx, %edx
+	add	%ecx, %eax
+	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd_align), %ecx, 4)
+
+	.p2align 4
+L(shl_1):
+#ifndef USE_AS_MEMMOVE
+	movaps	-1(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-1(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_1_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl1LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	15(%eax), %xmm2
+	movaps	31(%eax), %xmm3
+	movaps	47(%eax), %xmm4
+	movaps	63(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$1, %xmm4, %xmm5
+	palignr	$1, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$1, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$1, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl1LoopStart)
+
+L(Shl1LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	15(%eax), %xmm2
+	movaps	31(%eax), %xmm3
+	palignr	$1, %xmm2, %xmm3
+	palignr	$1, %xmm1, %xmm2
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_1_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-1(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_1_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$1, %xmm2, %xmm3
+	palignr	$1, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_1_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$1, %xmm2, %xmm3
+	palignr	$1, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_1_no_prefetch_loop)
+
+L(sh_1_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	1(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_2):
+#ifndef USE_AS_MEMMOVE
+	movaps	-2(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-2(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_2_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl2LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	14(%eax), %xmm2
+	movaps	30(%eax), %xmm3
+	movaps	46(%eax), %xmm4
+	movaps	62(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$2, %xmm4, %xmm5
+	palignr	$2, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$2, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$2, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl2LoopStart)
+
+L(Shl2LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	14(%eax), %xmm2
+	movaps	30(%eax), %xmm3
+	palignr	$2, %xmm2, %xmm3
+	palignr	$2, %xmm1, %xmm2
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_2_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-2(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_2_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$2, %xmm2, %xmm3
+	palignr	$2, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_2_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$2, %xmm2, %xmm3
+	palignr	$2, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_2_no_prefetch_loop)
+
+L(sh_2_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	2(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_3):
+#ifndef USE_AS_MEMMOVE
+	movaps	-3(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-3(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_3_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl3LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	13(%eax), %xmm2
+	movaps	29(%eax), %xmm3
+	movaps	45(%eax), %xmm4
+	movaps	61(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$3, %xmm4, %xmm5
+	palignr	$3, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$3, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$3, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl3LoopStart)
+
+L(Shl3LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	13(%eax), %xmm2
+	movaps	29(%eax), %xmm3
+	palignr	$3, %xmm2, %xmm3
+	palignr	$3, %xmm1, %xmm2
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_3_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-3(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_3_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$3, %xmm2, %xmm3
+	palignr	$3, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+
+	jb	L(sh_3_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$3, %xmm2, %xmm3
+	palignr	$3, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+
+	jae	L(sh_3_no_prefetch_loop)
+
+L(sh_3_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	3(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_4):
+#ifndef USE_AS_MEMMOVE
+	movaps	-4(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-4(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_4_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl4LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	12(%eax), %xmm2
+	movaps	28(%eax), %xmm3
+	movaps	44(%eax), %xmm4
+	movaps	60(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$4, %xmm4, %xmm5
+	palignr	$4, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$4, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$4, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl4LoopStart)
+
+L(Shl4LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	12(%eax), %xmm2
+	movaps	28(%eax), %xmm3
+	palignr	$4, %xmm2, %xmm3
+	palignr	$4, %xmm1, %xmm2
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_4_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-4(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_4_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$4, %xmm2, %xmm3
+	palignr	$4, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+
+	jb	L(sh_4_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$4, %xmm2, %xmm3
+	palignr	$4, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+
+	jae	L(sh_4_no_prefetch_loop)
+
+L(sh_4_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	4(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_5):
+#ifndef USE_AS_MEMMOVE
+	movaps	-5(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-5(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_5_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl5LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	11(%eax), %xmm2
+	movaps	27(%eax), %xmm3
+	movaps	43(%eax), %xmm4
+	movaps	59(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$5, %xmm4, %xmm5
+	palignr	$5, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$5, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$5, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl5LoopStart)
+
+L(Shl5LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	11(%eax), %xmm2
+	movaps	27(%eax), %xmm3
+	palignr	$5, %xmm2, %xmm3
+	palignr	$5, %xmm1, %xmm2
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_5_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-5(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_5_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$5, %xmm2, %xmm3
+	palignr	$5, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+
+	jb	L(sh_5_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$5, %xmm2, %xmm3
+	palignr	$5, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+
+	jae	L(sh_5_no_prefetch_loop)
+
+L(sh_5_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	5(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_6):
+#ifndef USE_AS_MEMMOVE
+	movaps	-6(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-6(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_6_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl6LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	10(%eax), %xmm2
+	movaps	26(%eax), %xmm3
+	movaps	42(%eax), %xmm4
+	movaps	58(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$6, %xmm4, %xmm5
+	palignr	$6, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$6, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$6, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl6LoopStart)
+
+L(Shl6LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	10(%eax), %xmm2
+	movaps	26(%eax), %xmm3
+	palignr	$6, %xmm2, %xmm3
+	palignr	$6, %xmm1, %xmm2
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_6_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-6(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_6_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$6, %xmm2, %xmm3
+	palignr	$6, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+
+	jb	L(sh_6_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$6, %xmm2, %xmm3
+	palignr	$6, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+
+	jae	L(sh_6_no_prefetch_loop)
+
+L(sh_6_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	6(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_7):
+#ifndef USE_AS_MEMMOVE
+	movaps	-7(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-7(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_7_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl7LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	9(%eax), %xmm2
+	movaps	25(%eax), %xmm3
+	movaps	41(%eax), %xmm4
+	movaps	57(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$7, %xmm4, %xmm5
+	palignr	$7, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$7, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$7, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl7LoopStart)
+
+L(Shl7LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	9(%eax), %xmm2
+	movaps	25(%eax), %xmm3
+	palignr	$7, %xmm2, %xmm3
+	palignr	$7, %xmm1, %xmm2
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_7_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-7(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_7_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$7, %xmm2, %xmm3
+	palignr	$7, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_7_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$7, %xmm2, %xmm3
+	palignr	$7, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_7_no_prefetch_loop)
+
+L(sh_7_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	7(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_8):
+#ifndef USE_AS_MEMMOVE
+	movaps	-8(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-8(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_8_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl8LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	8(%eax), %xmm2
+	movaps	24(%eax), %xmm3
+	movaps	40(%eax), %xmm4
+	movaps	56(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$8, %xmm4, %xmm5
+	palignr	$8, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$8, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$8, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl8LoopStart)
+
+L(LoopLeave8):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	8(%eax), %xmm2
+	movaps	24(%eax), %xmm3
+	palignr	$8, %xmm2, %xmm3
+	palignr	$8, %xmm1, %xmm2
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_8_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-8(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_8_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$8, %xmm2, %xmm3
+	palignr	$8, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_8_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$8, %xmm2, %xmm3
+	palignr	$8, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_8_no_prefetch_loop)
+
+L(sh_8_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	8(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_9):
+#ifndef USE_AS_MEMMOVE
+	movaps	-9(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-9(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_9_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl9LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	7(%eax), %xmm2
+	movaps	23(%eax), %xmm3
+	movaps	39(%eax), %xmm4
+	movaps	55(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$9, %xmm4, %xmm5
+	palignr	$9, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$9, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$9, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl9LoopStart)
+
+L(Shl9LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	7(%eax), %xmm2
+	movaps	23(%eax), %xmm3
+	palignr	$9, %xmm2, %xmm3
+	palignr	$9, %xmm1, %xmm2
+
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_9_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-9(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_9_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$9, %xmm2, %xmm3
+	palignr	$9, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_9_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$9, %xmm2, %xmm3
+	palignr	$9, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_9_no_prefetch_loop)
+
+L(sh_9_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	9(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_10):
+#ifndef USE_AS_MEMMOVE
+	movaps	-10(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-10(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_10_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl10LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	6(%eax), %xmm2
+	movaps	22(%eax), %xmm3
+	movaps	38(%eax), %xmm4
+	movaps	54(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$10, %xmm4, %xmm5
+	palignr	$10, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$10, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$10, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl10LoopStart)
+
+L(Shl10LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	6(%eax), %xmm2
+	movaps	22(%eax), %xmm3
+	palignr	$10, %xmm2, %xmm3
+	palignr	$10, %xmm1, %xmm2
+
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_10_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-10(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_10_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$10, %xmm2, %xmm3
+	palignr	$10, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_10_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$10, %xmm2, %xmm3
+	palignr	$10, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_10_no_prefetch_loop)
+
+L(sh_10_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	10(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_11):
+#ifndef USE_AS_MEMMOVE
+	movaps	-11(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-11(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_11_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl11LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	5(%eax), %xmm2
+	movaps	21(%eax), %xmm3
+	movaps	37(%eax), %xmm4
+	movaps	53(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$11, %xmm4, %xmm5
+	palignr	$11, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$11, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$11, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl11LoopStart)
+
+L(Shl11LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	5(%eax), %xmm2
+	movaps	21(%eax), %xmm3
+	palignr	$11, %xmm2, %xmm3
+	palignr	$11, %xmm1, %xmm2
+
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_11_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-11(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_11_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$11, %xmm2, %xmm3
+	palignr	$11, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_11_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$11, %xmm2, %xmm3
+	palignr	$11, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_11_no_prefetch_loop)
+
+L(sh_11_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	11(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_12):
+#ifndef USE_AS_MEMMOVE
+	movaps	-12(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-12(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_12_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl12LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	4(%eax), %xmm2
+	movaps	20(%eax), %xmm3
+	movaps	36(%eax), %xmm4
+	movaps	52(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$12, %xmm4, %xmm5
+	palignr	$12, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$12, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$12, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl12LoopStart)
+
+L(Shl12LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	4(%eax), %xmm2
+	movaps	20(%eax), %xmm3
+	palignr	$12, %xmm2, %xmm3
+	palignr	$12, %xmm1, %xmm2
+
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_12_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-12(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_12_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$12, %xmm2, %xmm3
+	palignr	$12, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_12_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$12, %xmm2, %xmm3
+	palignr	$12, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_12_no_prefetch_loop)
+
+L(sh_12_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	12(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_13):
+#ifndef USE_AS_MEMMOVE
+	movaps	-13(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-13(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_13_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl13LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	3(%eax), %xmm2
+	movaps	19(%eax), %xmm3
+	movaps	35(%eax), %xmm4
+	movaps	51(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$13, %xmm4, %xmm5
+	palignr	$13, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$13, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$13, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl13LoopStart)
+
+L(Shl13LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	3(%eax), %xmm2
+	movaps	19(%eax), %xmm3
+	palignr	$13, %xmm2, %xmm3
+	palignr	$13, %xmm1, %xmm2
+
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_13_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-13(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_13_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$13, %xmm2, %xmm3
+	palignr	$13, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_13_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$13, %xmm2, %xmm3
+	palignr	$13, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_13_no_prefetch_loop)
+
+L(sh_13_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	13(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_14):
+#ifndef USE_AS_MEMMOVE
+	movaps	-14(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-14(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_14_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl14LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	2(%eax), %xmm2
+	movaps	18(%eax), %xmm3
+	movaps	34(%eax), %xmm4
+	movaps	50(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$14, %xmm4, %xmm5
+	palignr	$14, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$14, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$14, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl14LoopStart)
+
+L(Shl14LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	2(%eax), %xmm2
+	movaps	18(%eax), %xmm3
+	palignr	$14, %xmm2, %xmm3
+	palignr	$14, %xmm1, %xmm2
+
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_14_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-14(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_14_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$14, %xmm2, %xmm3
+	palignr	$14, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_14_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$14, %xmm2, %xmm3
+	palignr	$14, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_14_no_prefetch_loop)
+
+L(sh_14_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	14(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_15):
+#ifndef USE_AS_MEMMOVE
+	movaps	-15(%eax), %xmm1
+#else
+	movl	DEST+4(%esp), %edi
+	movaps	-15(%eax), %xmm1
+	movdqu	%xmm0, (%edi)
+#endif
+#ifdef DATA_CACHE_SIZE_HALF
+	cmp	$DATA_CACHE_SIZE_HALF, %ecx
+#else
+# if (defined SHARED || defined __PIC__)
+	SETUP_PIC_REG(bx)
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
+# else
+	cmp	__x86_data_cache_size_half, %ecx
+# endif
+#endif
+	jb L(sh_15_no_prefetch)
+
+	lea	-64(%ecx), %ecx
+
+	.p2align 4
+L(Shl15LoopStart):
+	prefetcht0 0x1c0(%eax)
+	prefetcht0 0x1c0(%edx)
+	movaps	1(%eax), %xmm2
+	movaps	17(%eax), %xmm3
+	movaps	33(%eax), %xmm4
+	movaps	49(%eax), %xmm5
+	movaps	%xmm5, %xmm7
+	palignr	$15, %xmm4, %xmm5
+	palignr	$15, %xmm3, %xmm4
+	movaps	%xmm5, 48(%edx)
+	palignr	$15, %xmm2, %xmm3
+	lea	64(%eax), %eax
+	palignr	$15, %xmm1, %xmm2
+	movaps	%xmm4, 32(%edx)
+	movaps	%xmm3, 16(%edx)
+	movaps	%xmm7, %xmm1
+	movaps	%xmm2, (%edx)
+	lea	64(%edx), %edx
+	sub	$64, %ecx
+	ja	L(Shl15LoopStart)
+
+L(Shl15LoopLeave):
+	add	$32, %ecx
+	jle	L(shl_end_0)
+
+	movaps	1(%eax), %xmm2
+	movaps	17(%eax), %xmm3
+	palignr	$15, %xmm2, %xmm3
+	palignr	$15, %xmm1, %xmm2
+
+	movaps	%xmm2, (%edx)
+	movaps	%xmm3, 16(%edx)
+	lea	32(%edx, %ecx), %edx
+	lea	32(%eax, %ecx), %eax
+	POP (%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(sh_15_no_prefetch):
+	lea	-32(%ecx), %ecx
+	lea	-15(%eax), %eax
+	xor	%edi, %edi
+
+	.p2align 4
+L(sh_15_no_prefetch_loop):
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm4
+	palignr	$15, %xmm2, %xmm3
+	palignr	$15, %xmm1, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jb	L(sh_15_end_no_prefetch_loop)
+
+	movdqa	16(%eax, %edi), %xmm2
+	sub	$32, %ecx
+	movdqa	32(%eax, %edi), %xmm3
+	movdqa	%xmm3, %xmm1
+	palignr	$15, %xmm2, %xmm3
+	palignr	$15, %xmm4, %xmm2
+	lea	32(%edi), %edi
+	movdqa	%xmm2, -32(%edx, %edi)
+	movdqa	%xmm3, -16(%edx, %edi)
+	jae	L(sh_15_no_prefetch_loop)
+
+L(sh_15_end_no_prefetch_loop):
+	lea	32(%ecx), %ecx
+	add	%ecx, %edi
+	add	%edi, %edx
+	lea	15(%edi, %eax), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(shl_end_0):
+	lea	32(%ecx), %ecx
+	lea	(%edx, %ecx), %edx
+	lea	(%eax, %ecx), %eax
+	POP	(%edi)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
+
+	.p2align 4
+L(fwd_write_44bytes):
+	movq	-44(%eax), %xmm0
+	movq	%xmm0, -44(%edx)
+L(fwd_write_36bytes):
+	movq	-36(%eax), %xmm0
+	movq	%xmm0, -36(%edx)
+L(fwd_write_28bytes):
+	movq	-28(%eax), %xmm0
+	movq	%xmm0, -28(%edx)
+L(fwd_write_20bytes):
+	movq	-20(%eax), %xmm0
+	movq	%xmm0, -20(%edx)
+L(fwd_write_12bytes):
+	movq	-12(%eax), %xmm0
+	movq	%xmm0, -12(%edx)
+L(fwd_write_4bytes):
+	movl	-4(%eax), %ecx
+	movl	%ecx, -4(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_40bytes):
+	movq	-40(%eax), %xmm0
+	movq	%xmm0, -40(%edx)
+L(fwd_write_32bytes):
+	movq	-32(%eax), %xmm0
+	movq	%xmm0, -32(%edx)
+L(fwd_write_24bytes):
+	movq	-24(%eax), %xmm0
+	movq	%xmm0, -24(%edx)
+L(fwd_write_16bytes):
+	movq	-16(%eax), %xmm0
+	movq	%xmm0, -16(%edx)
+L(fwd_write_8bytes):
+	movq	-8(%eax), %xmm0
+	movq	%xmm0, -8(%edx)
+L(fwd_write_0bytes):
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_5bytes):
+	movl	-5(%eax), %ecx
+	movl	-4(%eax), %eax
+	movl	%ecx, -5(%edx)
+	movl	%eax, -4(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_45bytes):
+	movq	-45(%eax), %xmm0
+	movq	%xmm0, -45(%edx)
+L(fwd_write_37bytes):
+	movq	-37(%eax), %xmm0
+	movq	%xmm0, -37(%edx)
+L(fwd_write_29bytes):
+	movq	-29(%eax), %xmm0
+	movq	%xmm0, -29(%edx)
+L(fwd_write_21bytes):
+	movq	-21(%eax), %xmm0
+	movq	%xmm0, -21(%edx)
+L(fwd_write_13bytes):
+	movq	-13(%eax), %xmm0
+	movq	%xmm0, -13(%edx)
+	movl	-5(%eax), %ecx
+	movl	%ecx, -5(%edx)
+	movzbl	-1(%eax), %ecx
+	movb	%cl, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_41bytes):
+	movq	-41(%eax), %xmm0
+	movq	%xmm0, -41(%edx)
+L(fwd_write_33bytes):
+	movq	-33(%eax), %xmm0
+	movq	%xmm0, -33(%edx)
+L(fwd_write_25bytes):
+	movq	-25(%eax), %xmm0
+	movq	%xmm0, -25(%edx)
+L(fwd_write_17bytes):
+	movq	-17(%eax), %xmm0
+	movq	%xmm0, -17(%edx)
+L(fwd_write_9bytes):
+	movq	-9(%eax), %xmm0
+	movq	%xmm0, -9(%edx)
+L(fwd_write_1bytes):
+	movzbl	-1(%eax), %ecx
+	movb	%cl, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_46bytes):
+	movq	-46(%eax), %xmm0
+	movq	%xmm0, -46(%edx)
+L(fwd_write_38bytes):
+	movq	-38(%eax), %xmm0
+	movq	%xmm0, -38(%edx)
+L(fwd_write_30bytes):
+	movq	-30(%eax), %xmm0
+	movq	%xmm0, -30(%edx)
+L(fwd_write_22bytes):
+	movq	-22(%eax), %xmm0
+	movq	%xmm0, -22(%edx)
+L(fwd_write_14bytes):
+	movq	-14(%eax), %xmm0
+	movq	%xmm0, -14(%edx)
+L(fwd_write_6bytes):
+	movl	-6(%eax), %ecx
+	movl	%ecx, -6(%edx)
+	movzwl	-2(%eax), %ecx
+	movw	%cx, -2(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_42bytes):
+	movq	-42(%eax), %xmm0
+	movq	%xmm0, -42(%edx)
+L(fwd_write_34bytes):
+	movq	-34(%eax), %xmm0
+	movq	%xmm0, -34(%edx)
+L(fwd_write_26bytes):
+	movq	-26(%eax), %xmm0
+	movq	%xmm0, -26(%edx)
+L(fwd_write_18bytes):
+	movq	-18(%eax), %xmm0
+	movq	%xmm0, -18(%edx)
+L(fwd_write_10bytes):
+	movq	-10(%eax), %xmm0
+	movq	%xmm0, -10(%edx)
+L(fwd_write_2bytes):
+	movzwl	-2(%eax), %ecx
+	movw	%cx, -2(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_47bytes):
+	movq	-47(%eax), %xmm0
+	movq	%xmm0, -47(%edx)
+L(fwd_write_39bytes):
+	movq	-39(%eax), %xmm0
+	movq	%xmm0, -39(%edx)
+L(fwd_write_31bytes):
+	movq	-31(%eax), %xmm0
+	movq	%xmm0, -31(%edx)
+L(fwd_write_23bytes):
+	movq	-23(%eax), %xmm0
+	movq	%xmm0, -23(%edx)
+L(fwd_write_15bytes):
+	movq	-15(%eax), %xmm0
+	movq	%xmm0, -15(%edx)
+L(fwd_write_7bytes):
+	movl	-7(%eax), %ecx
+	movl	%ecx, -7(%edx)
+	movzwl	-3(%eax), %ecx
+	movzbl	-1(%eax), %eax
+	movw	%cx, -3(%edx)
+	movb	%al, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_43bytes):
+	movq	-43(%eax), %xmm0
+	movq	%xmm0, -43(%edx)
+L(fwd_write_35bytes):
+	movq	-35(%eax), %xmm0
+	movq	%xmm0, -35(%edx)
+L(fwd_write_27bytes):
+	movq	-27(%eax), %xmm0
+	movq	%xmm0, -27(%edx)
+L(fwd_write_19bytes):
+	movq	-19(%eax), %xmm0
+	movq	%xmm0, -19(%edx)
+L(fwd_write_11bytes):
+	movq	-11(%eax), %xmm0
+	movq	%xmm0, -11(%edx)
+L(fwd_write_3bytes):
+	movzwl	-3(%eax), %ecx
+	movzbl	-1(%eax), %eax
+	movw	%cx, -3(%edx)
+	movb	%al, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_40bytes_align):
+	movdqa	-40(%eax), %xmm0
+	movdqa	%xmm0, -40(%edx)
+L(fwd_write_24bytes_align):
+	movdqa	-24(%eax), %xmm0
+	movdqa	%xmm0, -24(%edx)
+L(fwd_write_8bytes_align):
+	movq	-8(%eax), %xmm0
+	movq	%xmm0, -8(%edx)
+L(fwd_write_0bytes_align):
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_32bytes_align):
+	movdqa	-32(%eax), %xmm0
+	movdqa	%xmm0, -32(%edx)
+L(fwd_write_16bytes_align):
+	movdqa	-16(%eax), %xmm0
+	movdqa	%xmm0, -16(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_5bytes_align):
+	movl	-5(%eax), %ecx
+	movl	-4(%eax), %eax
+	movl	%ecx, -5(%edx)
+	movl	%eax, -4(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_45bytes_align):
+	movdqa	-45(%eax), %xmm0
+	movdqa	%xmm0, -45(%edx)
+L(fwd_write_29bytes_align):
+	movdqa	-29(%eax), %xmm0
+	movdqa	%xmm0, -29(%edx)
+L(fwd_write_13bytes_align):
+	movq	-13(%eax), %xmm0
+	movq	%xmm0, -13(%edx)
+	movl	-5(%eax), %ecx
+	movl	%ecx, -5(%edx)
+	movzbl	-1(%eax), %ecx
+	movb	%cl, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_37bytes_align):
+	movdqa	-37(%eax), %xmm0
+	movdqa	%xmm0, -37(%edx)
+L(fwd_write_21bytes_align):
+	movdqa	-21(%eax), %xmm0
+	movdqa	%xmm0, -21(%edx)
+	movl	-5(%eax), %ecx
+	movl	%ecx, -5(%edx)
+	movzbl	-1(%eax), %ecx
+	movb	%cl, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_41bytes_align):
+	movdqa	-41(%eax), %xmm0
+	movdqa	%xmm0, -41(%edx)
+L(fwd_write_25bytes_align):
+	movdqa	-25(%eax), %xmm0
+	movdqa	%xmm0, -25(%edx)
+L(fwd_write_9bytes_align):
+	movq	-9(%eax), %xmm0
+	movq	%xmm0, -9(%edx)
+L(fwd_write_1bytes_align):
+	movzbl	-1(%eax), %ecx
+	movb	%cl, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_33bytes_align):
+	movdqa	-33(%eax), %xmm0
+	movdqa	%xmm0, -33(%edx)
+L(fwd_write_17bytes_align):
+	movdqa	-17(%eax), %xmm0
+	movdqa	%xmm0, -17(%edx)
+	movzbl	-1(%eax), %ecx
+	movb	%cl, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_46bytes_align):
+	movdqa	-46(%eax), %xmm0
+	movdqa	%xmm0, -46(%edx)
+L(fwd_write_30bytes_align):
+	movdqa	-30(%eax), %xmm0
+	movdqa	%xmm0, -30(%edx)
+L(fwd_write_14bytes_align):
+	movq	-14(%eax), %xmm0
+	movq	%xmm0, -14(%edx)
+L(fwd_write_6bytes_align):
+	movl	-6(%eax), %ecx
+	movl	%ecx, -6(%edx)
+	movzwl	-2(%eax), %ecx
+	movw	%cx, -2(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_38bytes_align):
+	movdqa	-38(%eax), %xmm0
+	movdqa	%xmm0, -38(%edx)
+L(fwd_write_22bytes_align):
+	movdqa	-22(%eax), %xmm0
+	movdqa	%xmm0, -22(%edx)
+	movl	-6(%eax), %ecx
+	movl	%ecx, -6(%edx)
+	movzwl	-2(%eax), %ecx
+	movw	%cx, -2(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_42bytes_align):
+	movdqa	-42(%eax), %xmm0
+	movdqa	%xmm0, -42(%edx)
+L(fwd_write_26bytes_align):
+	movdqa	-26(%eax), %xmm0
+	movdqa	%xmm0, -26(%edx)
+L(fwd_write_10bytes_align):
+	movq	-10(%eax), %xmm0
+	movq	%xmm0, -10(%edx)
+L(fwd_write_2bytes_align):
+	movzwl	-2(%eax), %ecx
+	movw	%cx, -2(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_34bytes_align):
+	movdqa	-34(%eax), %xmm0
+	movdqa	%xmm0, -34(%edx)
+L(fwd_write_18bytes_align):
+	movdqa	-18(%eax), %xmm0
+	movdqa	%xmm0, -18(%edx)
+	movzwl	-2(%eax), %ecx
+	movw	%cx, -2(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_47bytes_align):
+	movdqa	-47(%eax), %xmm0
+	movdqa	%xmm0, -47(%edx)
+L(fwd_write_31bytes_align):
+	movdqa	-31(%eax), %xmm0
+	movdqa	%xmm0, -31(%edx)
+L(fwd_write_15bytes_align):
+	movq	-15(%eax), %xmm0
+	movq	%xmm0, -15(%edx)
+L(fwd_write_7bytes_align):
+	movl	-7(%eax), %ecx
+	movl	%ecx, -7(%edx)
+	movzwl	-3(%eax), %ecx
+	movzbl	-1(%eax), %eax
+	movw	%cx, -3(%edx)
+	movb	%al, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_39bytes_align):
+	movdqa	-39(%eax), %xmm0
+	movdqa	%xmm0, -39(%edx)
+L(fwd_write_23bytes_align):
+	movdqa	-23(%eax), %xmm0
+	movdqa	%xmm0, -23(%edx)
+	movl	-7(%eax), %ecx
+	movl	%ecx, -7(%edx)
+	movzwl	-3(%eax), %ecx
+	movzbl	-1(%eax), %eax
+	movw	%cx, -3(%edx)
+	movb	%al, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_43bytes_align):
+	movdqa	-43(%eax), %xmm0
+	movdqa	%xmm0, -43(%edx)
+L(fwd_write_27bytes_align):
+	movdqa	-27(%eax), %xmm0
+	movdqa	%xmm0, -27(%edx)
+L(fwd_write_11bytes_align):
+	movq	-11(%eax), %xmm0
+	movq	%xmm0, -11(%edx)
+L(fwd_write_3bytes_align):
+	movzwl	-3(%eax), %ecx
+	movzbl	-1(%eax), %eax
+	movw	%cx, -3(%edx)
+	movb	%al, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_35bytes_align):
+	movdqa	-35(%eax), %xmm0
+	movdqa	%xmm0, -35(%edx)
+L(fwd_write_19bytes_align):
+	movdqa	-19(%eax), %xmm0
+	movdqa	%xmm0, -19(%edx)
+	movzwl	-3(%eax), %ecx
+	movzbl	-1(%eax), %eax
+	movw	%cx, -3(%edx)
+	movb	%al, -1(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_44bytes_align):
+	movdqa	-44(%eax), %xmm0
+	movdqa	%xmm0, -44(%edx)
+L(fwd_write_28bytes_align):
+	movdqa	-28(%eax), %xmm0
+	movdqa	%xmm0, -28(%edx)
+L(fwd_write_12bytes_align):
+	movq	-12(%eax), %xmm0
+	movq	%xmm0, -12(%edx)
+L(fwd_write_4bytes_align):
+	movl	-4(%eax), %ecx
+	movl	%ecx, -4(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(fwd_write_36bytes_align):
+	movdqa	-36(%eax), %xmm0
+	movdqa	%xmm0, -36(%edx)
+L(fwd_write_20bytes_align):
+	movdqa	-20(%eax), %xmm0
+	movdqa	%xmm0, -20(%edx)
+	movl	-4(%eax), %ecx
+	movl	%ecx, -4(%edx)
+#ifndef USE_AS_BCOPY
+# ifdef USE_AS_MEMPCPY
+	movl	%edx, %eax
+# else
+	movl	DEST(%esp), %eax
+# endif
+#endif
+	RETURN_END
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(large_page):
+	movdqu	(%eax), %xmm1
+#ifdef USE_AS_MEMMOVE
+	movl	DEST+4(%esp), %edi
+	movdqu	%xmm0, (%edi)
+#endif
+	lea	16(%eax), %eax
+	movntdq	%xmm1, (%edx)
+	lea	16(%edx), %edx
+	lea	-0x90(%ecx), %ecx
+	POP (%edi)
+
+	.p2align 4
+L(large_page_loop):
+	movdqu	(%eax), %xmm0
+	movdqu	0x10(%eax), %xmm1
+	movdqu	0x20(%eax), %xmm2
+	movdqu	0x30(%eax), %xmm3
+	movdqu	0x40(%eax), %xmm4
+	movdqu	0x50(%eax), %xmm5
+	movdqu	0x60(%eax), %xmm6
+	movdqu	0x70(%eax), %xmm7
+	lea	0x80(%eax), %eax
+
+	sub	$0x80, %ecx
+	movntdq	%xmm0, (%edx)
+	movntdq	%xmm1, 0x10(%edx)
+	movntdq	%xmm2, 0x20(%edx)
+	movntdq	%xmm3, 0x30(%edx)
+	movntdq	%xmm4, 0x40(%edx)
+	movntdq	%xmm5, 0x50(%edx)
+	movntdq	%xmm6, 0x60(%edx)
+	movntdq	%xmm7, 0x70(%edx)
+	lea	0x80(%edx), %edx
+	jae	L(large_page_loop)
+	cmp	$-0x40, %ecx
+	lea	0x80(%ecx), %ecx
+	jl	L(large_page_less_64bytes)
+
+	movdqu	(%eax), %xmm0
+	movdqu	0x10(%eax), %xmm1
+	movdqu	0x20(%eax), %xmm2
+	movdqu	0x30(%eax), %xmm3
+	lea	0x40(%eax), %eax
+
+	movntdq	%xmm0, (%edx)
+	movntdq	%xmm1, 0x10(%edx)
+	movntdq	%xmm2, 0x20(%edx)
+	movntdq	%xmm3, 0x30(%edx)
+	lea	0x40(%edx), %edx
+	sub	$0x40, %ecx
+L(large_page_less_64bytes):
+	cmp	$32, %ecx
+	jb	L(large_page_less_32bytes)
+	movdqu	(%eax), %xmm0
+	movdqu	0x10(%eax), %xmm1
+	lea	0x20(%eax), %eax
+	movntdq	%xmm0, (%edx)
+	movntdq	%xmm1, 0x10(%edx)
+	lea	0x20(%edx), %edx
+	sub	$0x20, %ecx
+L(large_page_less_32bytes):
+	add	%ecx, %edx
+	add	%ecx, %eax
+	sfence
+	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd), %ecx, 4)
+
+	.p2align 4
+L(bk_write_44bytes):
+	movq	36(%eax), %xmm0
+	movq	%xmm0, 36(%edx)
+L(bk_write_36bytes):
+	movq	28(%eax), %xmm0
+	movq	%xmm0, 28(%edx)
+L(bk_write_28bytes):
+	movq	20(%eax), %xmm0
+	movq	%xmm0, 20(%edx)
+L(bk_write_20bytes):
+	movq	12(%eax), %xmm0
+	movq	%xmm0, 12(%edx)
+L(bk_write_12bytes):
+	movq	4(%eax), %xmm0
+	movq	%xmm0, 4(%edx)
+L(bk_write_4bytes):
+	movl	(%eax), %ecx
+	movl	%ecx, (%edx)
+L(bk_write_0bytes):
+#ifndef USE_AS_BCOPY
+	movl	DEST(%esp), %eax
+# ifdef USE_AS_MEMPCPY
+	movl	LEN(%esp), %ecx
+	add	%ecx, %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(bk_write_40bytes):
+	movq	32(%eax), %xmm0
+	movq	%xmm0, 32(%edx)
+L(bk_write_32bytes):
+	movq	24(%eax), %xmm0
+	movq	%xmm0, 24(%edx)
+L(bk_write_24bytes):
+	movq	16(%eax), %xmm0
+	movq	%xmm0, 16(%edx)
+L(bk_write_16bytes):
+	movq	8(%eax), %xmm0
+	movq	%xmm0, 8(%edx)
+L(bk_write_8bytes):
+	movq	(%eax), %xmm0
+	movq	%xmm0, (%edx)
+#ifndef USE_AS_BCOPY
+	movl	DEST(%esp), %eax
+# ifdef USE_AS_MEMPCPY
+	movl	LEN(%esp), %ecx
+	add	%ecx, %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(bk_write_45bytes):
+	movq	37(%eax), %xmm0
+	movq	%xmm0, 37(%edx)
+L(bk_write_37bytes):
+	movq	29(%eax), %xmm0
+	movq	%xmm0, 29(%edx)
+L(bk_write_29bytes):
+	movq	21(%eax), %xmm0
+	movq	%xmm0, 21(%edx)
+L(bk_write_21bytes):
+	movq	13(%eax), %xmm0
+	movq	%xmm0, 13(%edx)
+L(bk_write_13bytes):
+	movq	5(%eax), %xmm0
+	movq	%xmm0, 5(%edx)
+L(bk_write_5bytes):
+	movl	1(%eax), %ecx
+	movl	%ecx, 1(%edx)
+L(bk_write_1bytes):
+	movzbl	(%eax), %ecx
+	movb	%cl, (%edx)
+#ifndef USE_AS_BCOPY
+	movl	DEST(%esp), %eax
+# ifdef USE_AS_MEMPCPY
+	movl	LEN(%esp), %ecx
+	add	%ecx, %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(bk_write_41bytes):
+	movq	33(%eax), %xmm0
+	movq	%xmm0, 33(%edx)
+L(bk_write_33bytes):
+	movq	25(%eax), %xmm0
+	movq	%xmm0, 25(%edx)
+L(bk_write_25bytes):
+	movq	17(%eax), %xmm0
+	movq	%xmm0, 17(%edx)
+L(bk_write_17bytes):
+	movq	9(%eax), %xmm0
+	movq	%xmm0, 9(%edx)
+L(bk_write_9bytes):
+	movq	1(%eax), %xmm0
+	movq	%xmm0, 1(%edx)
+	movzbl	(%eax), %ecx
+	movb	%cl, (%edx)
+#ifndef USE_AS_BCOPY
+	movl	DEST(%esp), %eax
+# ifdef USE_AS_MEMPCPY
+	movl	LEN(%esp), %ecx
+	add	%ecx, %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(bk_write_46bytes):
+	movq	38(%eax), %xmm0
+	movq	%xmm0, 38(%edx)
+L(bk_write_38bytes):
+	movq	30(%eax), %xmm0
+	movq	%xmm0, 30(%edx)
+L(bk_write_30bytes):
+	movq	22(%eax), %xmm0
+	movq	%xmm0, 22(%edx)
+L(bk_write_22bytes):
+	movq	14(%eax), %xmm0
+	movq	%xmm0, 14(%edx)
+L(bk_write_14bytes):
+	movq	6(%eax), %xmm0
+	movq	%xmm0, 6(%edx)
+L(bk_write_6bytes):
+	movl	2(%eax), %ecx
+	movl	%ecx, 2(%edx)
+	movzwl	(%eax), %ecx
+	movw	%cx, (%edx)
+#ifndef USE_AS_BCOPY
+	movl	DEST(%esp), %eax
+# ifdef USE_AS_MEMPCPY
+	movl	LEN(%esp), %ecx
+	add	%ecx, %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(bk_write_42bytes):
+	movq	34(%eax), %xmm0
+	movq	%xmm0, 34(%edx)
+L(bk_write_34bytes):
+	movq	26(%eax), %xmm0
+	movq	%xmm0, 26(%edx)
+L(bk_write_26bytes):
+	movq	18(%eax), %xmm0
+	movq	%xmm0, 18(%edx)
+L(bk_write_18bytes):
+	movq	10(%eax), %xmm0
+	movq	%xmm0, 10(%edx)
+L(bk_write_10bytes):
+	movq	2(%eax), %xmm0
+	movq	%xmm0, 2(%edx)
+L(bk_write_2bytes):
+	movzwl	(%eax), %ecx
+	movw	%cx, (%edx)
+#ifndef USE_AS_BCOPY
+	movl	DEST(%esp), %eax
+# ifdef USE_AS_MEMPCPY
+	movl	LEN(%esp), %ecx
+	add	%ecx, %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(bk_write_47bytes):
+	movq	39(%eax), %xmm0
+	movq	%xmm0, 39(%edx)
+L(bk_write_39bytes):
+	movq	31(%eax), %xmm0
+	movq	%xmm0, 31(%edx)
+L(bk_write_31bytes):
+	movq	23(%eax), %xmm0
+	movq	%xmm0, 23(%edx)
+L(bk_write_23bytes):
+	movq	15(%eax), %xmm0
+	movq	%xmm0, 15(%edx)
+L(bk_write_15bytes):
+	movq	7(%eax), %xmm0
+	movq	%xmm0, 7(%edx)
+L(bk_write_7bytes):
+	movl	3(%eax), %ecx
+	movl	%ecx, 3(%edx)
+	movzwl	1(%eax), %ecx
+	movw	%cx, 1(%edx)
+	movzbl	(%eax), %eax
+	movb	%al, (%edx)
+#ifndef USE_AS_BCOPY
+	movl	DEST(%esp), %eax
+# ifdef USE_AS_MEMPCPY
+	movl	LEN(%esp), %ecx
+	add	%ecx, %eax
+# endif
+#endif
+	RETURN
+
+	.p2align 4
+L(bk_write_43bytes):
+	movq	35(%eax), %xmm0
+	movq	%xmm0, 35(%edx)
+L(bk_write_35bytes):
+	movq	27(%eax), %xmm0
+	movq	%xmm0, 27(%edx)
+L(bk_write_27bytes):
+	movq	19(%eax), %xmm0
+	movq	%xmm0, 19(%edx)
+L(bk_write_19bytes):
+	movq	11(%eax), %xmm0
+	movq	%xmm0, 11(%edx)
+L(bk_write_11bytes):
+	movq	3(%eax), %xmm0
+	movq	%xmm0, 3(%edx)
+L(bk_write_3bytes):
+	movzwl	1(%eax), %ecx
+	movw	%cx, 1(%edx)
+	movzbl	(%eax), %eax
+	movb	%al, (%edx)
+#ifndef USE_AS_BCOPY
+	movl	DEST(%esp), %eax
+# ifdef USE_AS_MEMPCPY
+	movl	LEN(%esp), %ecx
+	add	%ecx, %eax
+# endif
+#endif
+	RETURN_END
+
+
+	.pushsection .rodata.ssse3,"a",@progbits
+	.p2align 2
+L(table_48bytes_fwd):
+	.int	JMPTBL (L(fwd_write_0bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_1bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_2bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_3bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_4bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_5bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_6bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_7bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_8bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_9bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_10bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_11bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_12bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_13bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_14bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_15bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_16bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_17bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_18bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_19bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_20bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_21bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_22bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_23bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_24bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_25bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_26bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_27bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_28bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_29bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_30bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_31bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_32bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_33bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_34bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_35bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_36bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_37bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_38bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_39bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_40bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_41bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_42bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_43bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_44bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_45bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_46bytes), L(table_48bytes_fwd))
+	.int	JMPTBL (L(fwd_write_47bytes), L(table_48bytes_fwd))
+
+	.p2align 2
+L(table_48bytes_fwd_align):
+	.int	JMPTBL (L(fwd_write_0bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_1bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_2bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_3bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_4bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_5bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_6bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_7bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_8bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_9bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_10bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_11bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_12bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_13bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_14bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_15bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_16bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_17bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_18bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_19bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_20bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_21bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_22bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_23bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_24bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_25bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_26bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_27bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_28bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_29bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_30bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_31bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_32bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_33bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_34bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_35bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_36bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_37bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_38bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_39bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_40bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_41bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_42bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_43bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_44bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_45bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_46bytes_align), L(table_48bytes_fwd_align))
+	.int	JMPTBL (L(fwd_write_47bytes_align), L(table_48bytes_fwd_align))
+
+	.p2align 2
+L(shl_table):
+	.int	JMPTBL (L(shl_0), L(shl_table))
+	.int	JMPTBL (L(shl_1), L(shl_table))
+	.int	JMPTBL (L(shl_2), L(shl_table))
+	.int	JMPTBL (L(shl_3), L(shl_table))
+	.int	JMPTBL (L(shl_4), L(shl_table))
+	.int	JMPTBL (L(shl_5), L(shl_table))
+	.int	JMPTBL (L(shl_6), L(shl_table))
+	.int	JMPTBL (L(shl_7), L(shl_table))
+	.int	JMPTBL (L(shl_8), L(shl_table))
+	.int	JMPTBL (L(shl_9), L(shl_table))
+	.int	JMPTBL (L(shl_10), L(shl_table))
+	.int	JMPTBL (L(shl_11), L(shl_table))
+	.int	JMPTBL (L(shl_12), L(shl_table))
+	.int	JMPTBL (L(shl_13), L(shl_table))
+	.int	JMPTBL (L(shl_14), L(shl_table))
+	.int	JMPTBL (L(shl_15), L(shl_table))
+
+	.p2align 2
+L(table_48_bytes_bwd):
+	.int	JMPTBL (L(bk_write_0bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_1bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_2bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_3bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_4bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_5bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_6bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_7bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_8bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_9bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_10bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_11bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_12bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_13bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_14bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_15bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_16bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_17bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_18bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_19bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_20bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_21bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_22bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_23bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_24bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_25bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_26bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_27bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_28bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_29bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_30bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_31bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_32bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_33bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_34bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_35bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_36bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_37bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_38bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_39bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_40bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_41bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_42bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_43bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_44bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_45bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_46bytes), L(table_48_bytes_bwd))
+	.int	JMPTBL (L(bk_write_47bytes), L(table_48_bytes_bwd))
+
+	.popsection
+
+#ifdef USE_AS_MEMMOVE
+	.p2align 4
+L(copy_backward):
+	PUSH (%edi)
+	movl	%eax, %edi
+	lea	(%ecx,%edx,1),%edx
+	lea	(%ecx,%edi,1),%edi
+	testl	$0x3, %edx
+	jnz	L(bk_align)
+
+L(bk_aligned_4):
+	cmp	$64, %ecx
+	jae	L(bk_write_more64bytes)
+
+L(bk_write_64bytesless):
+	cmp	$32, %ecx
+	jb	L(bk_write_less32bytes)
+
+L(bk_write_more32bytes):
+	/* Copy 32 bytes at a time.  */
+	sub	$32, %ecx
+	movq	-8(%edi), %xmm0
+	movq	%xmm0, -8(%edx)
+	movq	-16(%edi), %xmm0
+	movq	%xmm0, -16(%edx)
+	movq	-24(%edi), %xmm0
+	movq	%xmm0, -24(%edx)
+	movq	-32(%edi), %xmm0
+	movq	%xmm0, -32(%edx)
+	sub	$32, %edx
+	sub	$32, %edi
+
+L(bk_write_less32bytes):
+	movl	%edi, %eax
+	sub	%ecx, %edx
+	sub	%ecx, %eax
+	POP (%edi)
+L(bk_write_less32bytes_2):
+	BRANCH_TO_JMPTBL_ENTRY (L(table_48_bytes_bwd), %ecx, 4)
+
+	CFI_PUSH (%edi)
+
+	.p2align 4
+L(bk_align):
+	cmp	$8, %ecx
+	jbe	L(bk_write_less32bytes)
+	testl	$1, %edx
+	/* We get here only if (EDX & 3 ) != 0 so if (EDX & 1) ==0,
+	then	(EDX & 2) must be != 0.  */
+	jz	L(bk_got2)
+	sub	$1, %edi
+	sub	$1, %ecx
+	sub	$1, %edx
+	movzbl	(%edi), %eax
+	movb	%al, (%edx)
+
+	testl	$2, %edx
+	jz	L(bk_aligned_4)
+
+L(bk_got2):
+	sub	$2, %edi
+	sub	$2, %ecx
+	sub	$2, %edx
+	movzwl	(%edi), %eax
+	movw	%ax, (%edx)
+	jmp	L(bk_aligned_4)
+
+	.p2align 4
+L(bk_write_more64bytes):
+	/* Check alignment of last byte.  */
+	testl	$15, %edx
+	jz	L(bk_ssse3_cpy_pre)
+
+/* EDX is aligned 4 bytes, but not 16 bytes.  */
+L(bk_ssse3_align):
+	sub	$4, %edi
+	sub	$4, %ecx
+	sub	$4, %edx
+	movl	(%edi), %eax
+	movl	%eax, (%edx)
+
+	testl	$15, %edx
+	jz	L(bk_ssse3_cpy_pre)
+
+	sub	$4, %edi
+	sub	$4, %ecx
+	sub	$4, %edx
+	movl	(%edi), %eax
+	movl	%eax, (%edx)
+
+	testl	$15, %edx
+	jz	L(bk_ssse3_cpy_pre)
+
+	sub	$4, %edi
+	sub	$4, %ecx
+	sub	$4, %edx
+	movl	(%edi), %eax
+	movl	%eax, (%edx)
+
+L(bk_ssse3_cpy_pre):
+	cmp	$64, %ecx
+	jb	L(bk_write_more32bytes)
+
+	.p2align 4
+L(bk_ssse3_cpy):
+	sub	$64, %edi
+	sub	$64, %ecx
+	sub	$64, %edx
+	movdqu	0x30(%edi), %xmm3
+	movdqa	%xmm3, 0x30(%edx)
+	movdqu	0x20(%edi), %xmm2
+	movdqa	%xmm2, 0x20(%edx)
+	movdqu	0x10(%edi), %xmm1
+	movdqa	%xmm1, 0x10(%edx)
+	movdqu	(%edi), %xmm0
+	movdqa	%xmm0, (%edx)
+	cmp	$64, %ecx
+	jae	L(bk_ssse3_cpy)
+	jmp	L(bk_write_64bytesless)
+
+#endif
+
+END (MEMCPY)
diff --git a/libc/arch-x86/string/ssse3-memmove-atom.S b/libc/arch-x86/atom/string/ssse3-memmove-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-memmove-atom.S
rename to libc/arch-x86/atom/string/ssse3-memmove-atom.S
diff --git a/libc/arch-x86/string/ssse3-strcat-atom.S b/libc/arch-x86/atom/string/ssse3-strcat-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-strcat-atom.S
rename to libc/arch-x86/atom/string/ssse3-strcat-atom.S
diff --git a/libc/arch-x86/string/ssse3-strcmp-atom.S b/libc/arch-x86/atom/string/ssse3-strcmp-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-strcmp-atom.S
rename to libc/arch-x86/atom/string/ssse3-strcmp-atom.S
diff --git a/libc/arch-x86/string/ssse3-strcpy-atom.S b/libc/arch-x86/atom/string/ssse3-strcpy-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-strcpy-atom.S
rename to libc/arch-x86/atom/string/ssse3-strcpy-atom.S
diff --git a/libc/arch-x86/string/ssse3-strlcat-atom.S b/libc/arch-x86/atom/string/ssse3-strlcat-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-strlcat-atom.S
rename to libc/arch-x86/atom/string/ssse3-strlcat-atom.S
diff --git a/libc/arch-x86/string/ssse3-strlcpy-atom.S b/libc/arch-x86/atom/string/ssse3-strlcpy-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-strlcpy-atom.S
rename to libc/arch-x86/atom/string/ssse3-strlcpy-atom.S
diff --git a/libc/arch-x86/string/ssse3-strncat-atom.S b/libc/arch-x86/atom/string/ssse3-strncat-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-strncat-atom.S
rename to libc/arch-x86/atom/string/ssse3-strncat-atom.S
diff --git a/libc/arch-x86/string/ssse3-strncmp-atom.S b/libc/arch-x86/atom/string/ssse3-strncmp-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-strncmp-atom.S
rename to libc/arch-x86/atom/string/ssse3-strncmp-atom.S
diff --git a/libc/arch-x86/string/ssse3-strncpy-atom.S b/libc/arch-x86/atom/string/ssse3-strncpy-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-strncpy-atom.S
rename to libc/arch-x86/atom/string/ssse3-strncpy-atom.S
diff --git a/libc/arch-x86/string/ssse3-wcscat-atom.S b/libc/arch-x86/atom/string/ssse3-wcscat-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-wcscat-atom.S
rename to libc/arch-x86/atom/string/ssse3-wcscat-atom.S
diff --git a/libc/arch-x86/string/ssse3-wcscpy-atom.S b/libc/arch-x86/atom/string/ssse3-wcscpy-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-wcscpy-atom.S
rename to libc/arch-x86/atom/string/ssse3-wcscpy-atom.S
diff --git a/libc/arch-x86/string/ssse3-wmemcmp-atom.S b/libc/arch-x86/atom/string/ssse3-wmemcmp-atom.S
similarity index 100%
rename from libc/arch-x86/string/ssse3-wmemcmp-atom.S
rename to libc/arch-x86/atom/string/ssse3-wmemcmp-atom.S
diff --git a/libc/arch-x86/bionic/__bionic_clone.S b/libc/arch-x86/bionic/__bionic_clone.S
index 3823ecc..ef78aee 100644
--- a/libc/arch-x86/bionic/__bionic_clone.S
+++ b/libc/arch-x86/bionic/__bionic_clone.S
@@ -1,5 +1,4 @@
-#include <asm/unistd.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
 ENTRY(__bionic_clone)
@@ -7,9 +6,12 @@
         pushl   %esi
         pushl   %edi
 
-        # Align child stack.
-        movl    20(%esp), %ecx
-        andl    $~15, %ecx
+        # Load system call arguments into registers.
+        movl    16(%esp), %ebx   # flags
+        movl    20(%esp), %ecx   # child_stack
+        movl    24(%esp), %edx   # parent_tid
+        movl    28(%esp), %esi   # tls
+        movl    32(%esp), %edi   # child_tid
 
         # Copy 'fn' and 'arg' onto the child stack
         movl    36(%esp), %eax   # Read 'fn'.
@@ -20,35 +22,32 @@
 
         # Make the system call.
         movl    $__NR_clone, %eax
-        movl    16(%esp), %ebx  # flags
-        #movl   %ecx, %ecx      # child stack (already there)
-        movl    24(%esp), %edx  # parent_tid
-        movl    28(%esp), %esi  # tls
-        movl    32(%esp), %edi  # child_tid
         int     $0x80
 
         # Check result.
-        cmpl    $0, %eax
-        je      bc_child
-        jg      bc_parent
+        testl    %eax, %eax
+        jz      .L_bc_child
+        jg      .L_bc_parent
 
         # An error occurred, so set errno and return -1.
         negl    %eax
         pushl   %eax
-        call    __set_errno
+        call    __set_errno_internal
         addl    $4, %esp
-        orl     $-1, %eax
-        jmp     bc_return
+        jmp     .L_bc_return
 
-bc_child:
-        call    __bionic_clone_entry
+.L_bc_child:
+        # We don't want anyone to unwind past this point.
+        .cfi_undefined %eip
+        call    __start_thread
         hlt
 
-bc_parent:
-        # we're the parent; nothing to do.
-bc_return:
+.L_bc_parent:
+        # We're the parent; nothing to do.
+.L_bc_return:
         popl    %edi
         popl    %esi
         popl    %ebx
         ret
 END(__bionic_clone)
+.hidden __bionic_clone
diff --git a/libc/arch-x86/bionic/__get_sp.S b/libc/arch-x86/bionic/__get_sp.S
deleted file mode 100644
index 0739d79..0000000
--- a/libc/arch-x86/bionic/__get_sp.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-
-ENTRY(__get_sp)
-  mov  %esp, %eax
-  ret
-END(__get_sp)
diff --git a/libc/arch-x86/bionic/__set_tls.c b/libc/arch-x86/bionic/__set_tls.c
index 7ed4b01..38ed3c9 100644
--- a/libc/arch-x86/bionic/__set_tls.c
+++ b/libc/arch-x86/bionic/__set_tls.c
@@ -25,77 +25,50 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
+#include <limits.h>
 #include <pthread.h>
+#include <stdbool.h>
 
+#include <asm/ldt.h>
 
-struct user_desc {
-    unsigned int    entry_number;
-    unsigned long   base_addr;
-    unsigned int    limit;
-    unsigned int    seg_32bit:1;
-    unsigned int    contents:2;
-    unsigned int    read_exec_only:1;
-    unsigned int    limit_in_pages:1;
-    unsigned int    seg_not_present:1;
-    unsigned int    useable:1;
-    unsigned int    empty:25;
-};
+extern int __set_thread_area(struct user_desc*);
 
-extern int __set_thread_area(struct user_desc *u_info);
+__LIBC_HIDDEN__ void __init_user_desc(struct user_desc* result, bool allocate, void* base_addr) {
+  if (allocate) {
+    // Let the kernel choose.
+    result->entry_number = -1;
+  } else {
+    // Get the existing entry number from %gs.
+    uint32_t gs;
+    __asm__ __volatile__("movw %%gs, %w0" : "=q"(gs) /*output*/);
+    result->entry_number = (gs & 0xffff) >> 3;
+  }
 
-/* the following can't be const, since the first call will
- * update the 'entry_number' field
- */
-static struct user_desc  _tls_desc =
-{
-    -1,
-    0,
-    0x1000,
-    1,
-    0,
-    0,
-    1,
-    0,
-    1,
-    0
-};
+  result->base_addr = (uintptr_t) base_addr;
 
-static pthread_mutex_t  _tls_desc_lock = PTHREAD_MUTEX_INITIALIZER;
+  result->limit = PAGE_SIZE;
 
-struct _thread_area_head {
-    void *self;
-};
-
-/* we implement thread local storage through the gs: segment descriptor
- * we create a segment descriptor for the tls
- */
-int __set_tls(void *ptr)
-{
-    int   rc, segment;
-
-    pthread_mutex_lock(&_tls_desc_lock);
-    _tls_desc.base_addr = (unsigned long)ptr;
-
-    /* We also need to write the location of the tls to ptr[0] */
-    ((struct _thread_area_head *)ptr)->self = ptr;
-
-    rc = __set_thread_area( &_tls_desc );
-    if (rc != 0)
-    {
-        /* could not set thread local area */
-        pthread_mutex_unlock(&_tls_desc_lock);
-        return -1;
-    }
-
-    /* this weird computation comes from GLibc */
-    segment = _tls_desc.entry_number*8 + 3;
-    asm __volatile__ (
-        "   movw %w0, %%gs" :: "q"(segment)
-    );
-    pthread_mutex_unlock(&_tls_desc_lock);
-
-    return 0;
+  result->seg_32bit = 1;
+  result->contents = MODIFY_LDT_CONTENTS_DATA;
+  result->read_exec_only = 0;
+  result->limit_in_pages = 1;
+  result->seg_not_present = 0;
+  result->useable = 1;
 }
 
+__LIBC_HIDDEN__ int __set_tls(void* ptr) {
+  struct user_desc tls_descriptor;
+  __init_user_desc(&tls_descriptor, true, ptr);
 
+  int rc = __set_thread_area(&tls_descriptor);
+  if (rc != -1) {
+    // Change %gs to be new GDT entry.
+    uint16_t table_indicator = 0;  // GDT
+    uint16_t rpl = 3;  // Requested privilege level
+    uint16_t selector = (tls_descriptor.entry_number << 3) | table_indicator | rpl;
+    __asm__ __volatile__("movw %w0, %%gs" : /*output*/ : "q"(selector) /*input*/ : /*clobber*/);
+  }
 
+  return rc;
+}
diff --git a/libc/arch-x86/bionic/__stack_chk_fail_local.h b/libc/arch-x86/bionic/__stack_chk_fail_local.h
index 4f3699a..0b0fd7f 100644
--- a/libc/arch-x86/bionic/__stack_chk_fail_local.h
+++ b/libc/arch-x86/bionic/__stack_chk_fail_local.h
@@ -26,6 +26,7 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 
 /*
    __stack_chk_fail routine is runtime part of stack protector compiler
@@ -48,13 +49,9 @@
 */
 
 #ifdef __i386__
-#ifdef __PIC__
 extern void __stack_chk_fail();
 
-__attribute__ ((visibility ("hidden")))
-void __stack_chk_fail_local()
-{
+__LIBC_HIDDEN__ void __stack_chk_fail_local() {
   __stack_chk_fail();
 }
 #endif
-#endif
diff --git a/libc/arch-x86/bionic/_exit_with_stack_teardown.S b/libc/arch-x86/bionic/_exit_with_stack_teardown.S
index e94ae90..ce8c2ea 100644
--- a/libc/arch-x86/bionic/_exit_with_stack_teardown.S
+++ b/libc/arch-x86/bionic/_exit_with_stack_teardown.S
@@ -1,7 +1,7 @@
 #include <private/bionic_asm.h>
 
 // void _exit_with_stack_teardown(void* stackBase, size_t stackSize)
-ENTRY(_exit_with_stack_teardown)
+ENTRY_PRIVATE(_exit_with_stack_teardown)
   // We can trash registers because this function never returns.
   mov 4(%esp), %ebx             // stackBase
   mov 8(%esp), %ecx             // stackSize
diff --git a/libc/arch-x86/bionic/_setjmp.S b/libc/arch-x86/bionic/_setjmp.S
index 9221138..0b256a2 100644
--- a/libc/arch-x86/bionic/_setjmp.S
+++ b/libc/arch-x86/bionic/_setjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * C library -- _setjmp, _longjmp
diff --git a/libc/arch-x86/bionic/futex_x86.S b/libc/arch-x86/bionic/futex_x86.S
deleted file mode 100644
index 8dd2ad0..0000000
--- a/libc/arch-x86/bionic/futex_x86.S
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <private/bionic_asm.h>
-
-#define FUTEX_WAIT 0
-#define FUTEX_WAKE 1
-
-// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout)
-ENTRY(__futex_wait)
-    pushl   %ebx
-    pushl   %esi
-    mov     12(%esp), %ebx           /* ftx */
-    movl    $FUTEX_WAIT, %ecx
-    mov     16(%esp), %edx           /* val */
-    mov     20(%esp), %esi           /* timeout */
-    movl    $__NR_futex, %eax
-    int     $0x80
-    popl    %esi
-    popl    %ebx
-    ret
-END(__futex_wait)
-
-// int __futex_wake(volatile void* ftx, int count)
-ENTRY(__futex_wake)
-    pushl   %ebx
-    mov     8(%esp), %ebx            /* ftx */
-    movl    $FUTEX_WAKE, %ecx
-    mov     12(%esp), %edx           /* count */
-    movl    $__NR_futex, %eax
-    int     $0x80
-    popl    %ebx
-    ret
-END(__futex_wake)
-
-// int __futex_syscall3(volatile void* ftx, int op, int count)
-ENTRY(__futex_syscall3)
-    pushl   %ebx
-    movl    8(%esp), %ebx      /* ftx */
-    movl    12(%esp), %ecx      /* op */
-    movl    16(%esp), %edx      /* value */
-    movl    $__NR_futex, %eax
-    int     $0x80
-    popl    %ebx
-    ret
-END(__futex_syscall3)
-
-// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout)
-ENTRY(__futex_syscall4)
-    pushl   %ebx
-    pushl   %esi
-    movl    12(%esp), %ebx      /* ftx */
-    movl    16(%esp), %ecx      /* op */
-    movl    20(%esp), %edx      /* val */
-    movl    24(%esp), %esi      /* timeout */
-    movl    $__NR_futex, %eax
-    int     $0x80
-    popl    %esi
-    popl    %ebx
-    ret
-END(__futex_syscall4)
diff --git a/libc/arch-x86/bionic/libgcc_compat.c b/libc/arch-x86/bionic/libgcc_compat.c
new file mode 100644
index 0000000..c723263
--- /dev/null
+++ b/libc/arch-x86/bionic/libgcc_compat.c
@@ -0,0 +1,15 @@
+/* Generated by genlibgcc_compat.py */
+
+extern char __divdi3;
+extern char __moddi3;
+extern char __popcountsi2;
+extern char __udivdi3;
+extern char __umoddi3;
+
+void* __bionic_libgcc_compat_symbols[] = {
+    &__divdi3,
+    &__moddi3,
+    &__popcountsi2,
+    &__udivdi3,
+    &__umoddi3,
+};
diff --git a/libc/arch-x86/bionic/setjmp.S b/libc/arch-x86/bionic/setjmp.S
index c0df647..8f9d67c 100644
--- a/libc/arch-x86/bionic/setjmp.S
+++ b/libc/arch-x86/bionic/setjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * C library -- setjmp, longjmp
@@ -46,11 +46,7 @@
 ENTRY(setjmp)
 	PIC_PROLOGUE
 	pushl	$0
-#ifdef PIC
-	call	PIC_PLT(_C_LABEL(sigblock))
-#else
-	call	_C_LABEL(sigblock)
-#endif
+	call	PIC_PLT(sigblock)
 	addl	$4,%esp
 	PIC_EPILOGUE
 
@@ -71,11 +67,7 @@
 	movl	4(%esp),%edx
 	PIC_PROLOGUE
 	pushl	24(%edx)
-#ifdef PIC
-	call	PIC_PLT(_C_LABEL(sigsetmask))
-#else
-	call	_C_LABEL(sigsetmask)
-#endif
+	call	PIC_PLT(sigsetmask)
 	addl	$4,%esp
 	PIC_EPILOGUE
 
diff --git a/libc/arch-x86/bionic/sigsetjmp.S b/libc/arch-x86/bionic/sigsetjmp.S
index 70cc6db..250c606 100644
--- a/libc/arch-x86/bionic/sigsetjmp.S
+++ b/libc/arch-x86/bionic/sigsetjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(sigsetjmp)
 	movl	4(%esp),%ecx
@@ -42,11 +42,7 @@
 
 	PIC_PROLOGUE
 	pushl	$0
-#ifdef PIC
-	call	PIC_PLT(_C_LABEL(sigblock))
-#else
-	call	_C_LABEL(sigblock)
-#endif
+	call	PIC_PLT(sigblock)
 	addl	$4,%esp
 	PIC_EPILOGUE
 
@@ -70,11 +66,7 @@
 
 	PIC_PROLOGUE
 	pushl	24(%edx)
-#ifdef PIC
-	call	PIC_PLT(_C_LABEL(sigsetmask))
-#else
-	call	_C_LABEL(sigsetmask)
-#endif
+	call	PIC_PLT(sigsetmask)
 	addl	$4,%esp
 	PIC_EPILOGUE
 
diff --git a/libc/arch-x86/bionic/syscall.S b/libc/arch-x86/bionic/syscall.S
index 0178f41..f85ec39 100644
--- a/libc/arch-x86/bionic/syscall.S
+++ b/libc/arch-x86/bionic/syscall.S
@@ -38,9 +38,8 @@
     # Yes, so set errno.
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     # Restore the callee save registers.
     pop    %ebp
diff --git a/libc/arch-x86/bionic/vfork.S b/libc/arch-x86/bionic/vfork.S
index ec6f6ca..6c02910 100644
--- a/libc/arch-x86/bionic/vfork.S
+++ b/libc/arch-x86/bionic/vfork.S
@@ -38,8 +38,7 @@
   jb      1f
   negl    %eax
   pushl   %eax
-  call    __set_errno
-  orl     $-1, %eax
+  call    __set_errno_internal
 1:
-    jmp     *%ecx  // Jump to the stored return address.
+  jmp     *%ecx  // Jump to the stored return address.
 END(vfork)
diff --git a/libc/arch-x86/generic/generic.mk b/libc/arch-x86/generic/generic.mk
new file mode 100644
index 0000000..4aee5dc
--- /dev/null
+++ b/libc/arch-x86/generic/generic.mk
@@ -0,0 +1,52 @@
+libc_bionic_src_files_x86 += \
+    arch-x86/atom/string/sse2-memchr-atom.S \
+    arch-x86/atom/string/sse2-memrchr-atom.S \
+    arch-x86/atom/string/sse2-strchr-atom.S \
+    arch-x86/atom/string/sse2-strnlen-atom.S \
+    arch-x86/atom/string/sse2-strrchr-atom.S \
+    arch-x86/atom/string/sse2-wcschr-atom.S \
+    arch-x86/atom/string/sse2-wcsrchr-atom.S \
+    arch-x86/atom/string/sse2-wcslen-atom.S \
+    arch-x86/atom/string/sse2-wcscmp-atom.S \
+    arch-x86/silvermont/string/sse2-bcopy-slm.S \
+    arch-x86/silvermont/string/sse2-bzero-slm.S \
+    arch-x86/silvermont/string/sse2-memcpy-slm.S \
+    arch-x86/silvermont/string/sse2-memmove-slm.S \
+    arch-x86/silvermont/string/sse2-memset-slm.S \
+    arch-x86/silvermont/string/sse2-stpcpy-slm.S \
+    arch-x86/silvermont/string/sse2-stpncpy-slm.S \
+    arch-x86/silvermont/string/sse2-strcpy-slm.S \
+    arch-x86/silvermont/string/sse2-strlen-slm.S \
+    arch-x86/silvermont/string/sse2-strncpy-slm.S
+
+ifeq ($(ARCH_X86_HAVE_SSSE3),true)
+libc_bionic_src_files_x86 += \
+    arch-x86/atom/string/ssse3-strncat-atom.S \
+    arch-x86/atom/string/ssse3-strlcat-atom.S \
+    arch-x86/atom/string/ssse3-strlcpy-atom.S \
+    arch-x86/atom/string/ssse3-strcmp-atom.S \
+    arch-x86/atom/string/ssse3-strncmp-atom.S \
+    arch-x86/atom/string/ssse3-strcat-atom.S \
+    arch-x86/atom/string/ssse3-wcscat-atom.S \
+    arch-x86/atom/string/ssse3-wcscpy-atom.S
+else
+libc_bionic_src_files_x86 += \
+    arch-x86/generic/string/strcmp.S \
+    arch-x86/generic/string/strncmp.S \
+    arch-x86/generic/string/strcat.S \
+    upstream-freebsd/lib/libc/string/wcscpy.c \
+    upstream-freebsd/lib/libc/string/wcscat.c \
+    upstream-openbsd/lib/libc/string/strlcat.c \
+    upstream-openbsd/lib/libc/string/strlcpy.c \
+    upstream-openbsd/lib/libc/string/strncat.c
+endif
+
+ifeq ($(ARCH_X86_HAVE_SSE4),true)
+ libc_bionic_src_files_x86 += \
+    arch-x86/silvermont/string/sse4-memcmp-slm.S \
+    arch-x86/silvermont/string/sse4-wmemcmp-slm.S
+else
+libc_bionic_src_files_x86 += \
+    arch-x86/generic/string/memcmp.S \
+    upstream-freebsd/lib/libc/string/wmemcmp.c
+endif
diff --git a/libc/arch-x86/generic/string/bcopy.S b/libc/arch-x86/generic/string/bcopy.S
new file mode 100644
index 0000000..f425c58
--- /dev/null
+++ b/libc/arch-x86/generic/string/bcopy.S
@@ -0,0 +1,98 @@
+/*	$OpenBSD: bcopy.S,v 1.5 2005/08/07 11:30:38 espie Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from locore.s.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+	/*
+	 * (ov)bcopy (src,dst,cnt)
+	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
+	 */
+
+#if defined(MEMCOPY)
+ENTRY(memcpy)
+#elif defined(MEMMOVE)
+ENTRY(memmove)
+#else
+ENTRY(bcopy)
+#endif
+	pushl	%esi
+	pushl	%edi
+#if defined(MEMCOPY) || defined(MEMMOVE)
+	movl	12(%esp),%edi
+	movl	16(%esp),%esi
+	movl	%edi, %eax
+#else
+	movl	12(%esp),%esi
+	movl	16(%esp),%edi
+#endif
+	movl	20(%esp),%ecx
+	movl	%ecx,%edx
+	cmpl	%esi,%edi	/* potentially overlapping? */
+	jnb	1f
+	cld			/* nope, copy forwards. */
+	shrl	$2,%ecx		/* copy by words */
+	rep
+	movsl
+	movl	%edx,%ecx
+	andl	$3,%ecx		/* any bytes left? */
+	rep
+	movsb
+	popl	%edi
+	popl	%esi
+	ret
+1:
+	addl	%ecx,%edi	/* copy backwards. */
+	addl	%ecx,%esi
+	std
+	andl	$3,%ecx		/* any fractional bytes? */
+	decl	%edi
+	decl	%esi
+	rep
+	movsb
+	movl	%edx,%ecx
+	shrl	$2,%ecx
+	subl	$3,%esi
+	subl	$3,%edi
+	rep
+	movsl
+	popl	%edi
+	popl	%esi
+	cld
+	ret
+#if defined(MEMCOPY)
+END(memcpy)
+#elif defined(MEMMOVE)
+END(memmove)
+#else
+END(bcopy)
+#endif
diff --git a/libc/arch-x86/generic/string/memcmp.S b/libc/arch-x86/generic/string/memcmp.S
new file mode 100644
index 0000000..ef36b4f
--- /dev/null
+++ b/libc/arch-x86/generic/string/memcmp.S
@@ -0,0 +1,44 @@
+/*	$OpenBSD: memcmp.S,v 1.4 2005/08/07 11:30:38 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <private/bionic_asm.h>
+
+ENTRY(memcmp)
+	pushl	%edi
+	pushl	%esi
+	movl	12(%esp),%edi
+	movl	16(%esp),%esi
+	cld				/* set compare direction forward */
+
+	movl	20(%esp),%ecx		/* compare by words */
+	shrl	$2,%ecx
+	repe
+	cmpsl
+	jne	L5			/* do we match so far? */
+
+	movl	20(%esp),%ecx		/* compare remainder by bytes */
+	andl	$3,%ecx
+	repe
+	cmpsb
+	jne	L6			/* do we match? */
+
+	xorl	%eax,%eax		/* we match, return zero	*/
+	popl	%esi
+	popl	%edi
+	ret
+
+L5:	movl	$4,%ecx			/* We know that one of the next	*/
+	subl	%ecx,%edi		/* four pairs of bytes do not	*/
+	subl	%ecx,%esi		/* match.			*/
+	repe
+	cmpsb
+L6:	movzbl  -1(%edi),%eax		/* Perform unsigned comparison	*/
+	movzbl	-1(%esi),%edx
+	subl	%edx,%eax
+	popl	%esi
+	popl	%edi
+	ret
+END(memcmp)
diff --git a/libc/arch-x86/string/memcpy.S b/libc/arch-x86/generic/string/memcpy.S
similarity index 100%
rename from libc/arch-x86/string/memcpy.S
rename to libc/arch-x86/generic/string/memcpy.S
diff --git a/libc/arch-x86/string/memmove.S b/libc/arch-x86/generic/string/memmove.S
similarity index 100%
rename from libc/arch-x86/string/memmove.S
rename to libc/arch-x86/generic/string/memmove.S
diff --git a/libc/arch-x86/generic/string/strcat.S b/libc/arch-x86/generic/string/strcat.S
new file mode 100644
index 0000000..49e8eee
--- /dev/null
+++ b/libc/arch-x86/generic/string/strcat.S
@@ -0,0 +1,74 @@
+/*	$OpenBSD: strcat.S,v 1.8 2005/08/07 11:30:38 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <private/bionic_asm.h>
+
+#if defined(APIWARN)
+#APP
+	.section .gnu.warning.strcat
+	.ascii "warning: strcat() is almost always misused, please use strlcat()"
+#NO_APP
+#endif
+
+/*
+ * NOTE: I've unrolled the loop eight times: large enough to make a
+ * significant difference, and small enough not to totally trash the
+ * cache.
+ */
+
+ENTRY(strcat)
+	pushl	%edi			/* save edi */
+	movl	8(%esp),%edi		/* dst address */
+	movl	12(%esp),%edx		/* src address */
+	pushl	%edi			/* push destination address */
+
+	cld				/* set search forward */
+	xorl	%eax,%eax		/* set search for null terminator */
+	movl	$-1,%ecx		/* set search for lots of characters */
+	repne				/* search! */
+	scasb
+
+	leal	-1(%edi),%ecx		/* correct dst address */
+
+	.align 2,0x90
+L1:	movb	(%edx),%al		/* unroll loop, but not too much */
+	movb	%al,(%ecx)
+	testb	%al,%al
+	jz	L2
+	movb	1(%edx),%al
+	movb	%al,1(%ecx)
+	testb	%al,%al
+	jz	L2
+	movb	2(%edx),%al
+	movb	%al,2(%ecx)
+	testb	%al,%al
+	jz	L2
+	movb	3(%edx),%al
+	movb	%al,3(%ecx)
+	testb	%al,%al
+	jz	L2
+	movb	4(%edx),%al
+	movb	%al,4(%ecx)
+	testb	%al,%al
+	jz	L2
+	movb	5(%edx),%al
+	movb	%al,5(%ecx)
+	testb	%al,%al
+	jz	L2
+	movb	6(%edx),%al
+	movb	%al,6(%ecx)
+	testb	%al,%al
+	jz	L2
+	movb	7(%edx),%al
+	movb	%al,7(%ecx)
+	addl	$8,%edx
+	addl	$8,%ecx
+	testb	%al,%al
+	jnz	L1
+L2:	popl	%eax			/* pop destination address */
+	popl	%edi			/* restore edi */
+	ret
+END(strcat)
diff --git a/libc/arch-x86/generic/string/strcmp.S b/libc/arch-x86/generic/string/strcmp.S
new file mode 100644
index 0000000..580f4d5
--- /dev/null
+++ b/libc/arch-x86/generic/string/strcmp.S
@@ -0,0 +1,82 @@
+/*	$OpenBSD: strcmp.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <private/bionic_asm.h>
+
+/*
+ * NOTE: I've unrolled the loop eight times: large enough to make a
+ * significant difference, and small enough not to totally trash the
+ * cache.
+ */
+
+ENTRY(strcmp)
+	movl	0x04(%esp),%eax
+	movl	0x08(%esp),%edx
+	jmp	L2			/* Jump into the loop! */
+
+	.align	2,0x90
+L1:	incl	%eax
+	incl	%edx
+L2:	movb	(%eax),%cl
+	testb	%cl,%cl			/* null terminator??? */
+	jz	L3
+	cmpb	%cl,(%edx)		/* chars match??? */
+	jne	L3
+	incl	%eax
+	incl	%edx
+	movb	(%eax),%cl
+	testb	%cl,%cl
+	jz	L3
+	cmpb	%cl,(%edx)
+	jne	L3
+	incl	%eax
+	incl	%edx
+	movb	(%eax),%cl
+	testb	%cl,%cl
+	jz	L3
+	cmpb	%cl,(%edx)
+	jne	L3
+	incl	%eax
+	incl	%edx
+	movb	(%eax),%cl
+	testb	%cl,%cl
+	jz	L3
+	cmpb	%cl,(%edx)
+	jne	L3
+	incl	%eax
+	incl	%edx
+	movb	(%eax),%cl
+	testb	%cl,%cl
+	jz	L3
+	cmpb	%cl,(%edx)
+	jne	L3
+	incl	%eax
+	incl	%edx
+	movb	(%eax),%cl
+	testb	%cl,%cl
+	jz	L3
+	cmpb	%cl,(%edx)
+	jne	L3
+	incl	%eax
+	incl	%edx
+	movb	(%eax),%cl
+	testb	%cl,%cl
+	jz	L3
+	cmpb	%cl,(%edx)
+	jne	L3
+	incl	%eax
+	incl	%edx
+	movb	(%eax),%cl
+	testb	%cl,%cl
+	jz	L3
+	cmpb	%cl,(%edx)
+	je	L1
+	.align 2, 0x90
+L3:	movzbl	(%eax),%eax		/* unsigned comparison */
+	movzbl	(%edx),%edx
+	subl	%edx,%eax
+	ret
+END(strcmp)
diff --git a/libc/arch-x86/generic/string/strncmp.S b/libc/arch-x86/generic/string/strncmp.S
new file mode 100644
index 0000000..9ba83a1
--- /dev/null
+++ b/libc/arch-x86/generic/string/strncmp.S
@@ -0,0 +1,114 @@
+/*	$OpenBSD: strncmp.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <private/bionic_asm.h>
+
+/*
+ * NOTE: I've unrolled the loop eight times: large enough to make a
+ * significant difference, and small enough not to totally trash the
+ * cache.
+ */
+
+ENTRY(strncmp)
+	pushl	%ebx
+	movl	8(%esp),%eax
+	movl	12(%esp),%ecx
+	movl	16(%esp),%edx
+	testl	%edx,%edx
+	jmp	L2			/* Jump into the loop! */
+
+	.align 2,0x90
+L1:	incl	%eax
+	incl	%ecx
+	decl	%edx
+L2:	jz	L4			/* strings are equal */
+	movb	(%eax),%bl
+	testb	%bl,%bl
+	jz	L3
+	cmpb	%bl,(%ecx)
+	jne	L3
+
+	incl	%eax
+	incl	%ecx
+	decl	%edx
+	jz	L4
+	movb	(%eax),%bl
+	testb	%bl,%bl
+	jz	L3
+	cmpb	%bl,(%ecx)
+	jne	L3
+
+	incl	%eax
+	incl	%ecx
+	decl	%edx
+	jz	L4
+	movb	(%eax),%bl
+	testb	%bl,%bl
+	jz	L3
+	cmpb	%bl,(%ecx)
+	jne	L3
+
+	incl	%eax
+	incl	%ecx
+	decl	%edx
+	jz	L4
+	movb	(%eax),%bl
+	testb	%bl,%bl
+	jz	L3
+	cmpb	%bl,(%ecx)
+	jne	L3
+
+	incl	%eax
+	incl	%ecx
+	decl	%edx
+	jz	L4
+	movb	(%eax),%bl
+	testb	%bl,%bl
+	jz	L3
+	cmpb	%bl,(%ecx)
+	jne	L3
+
+	incl	%eax
+	incl	%ecx
+	decl	%edx
+	jz	L4
+	movb	(%eax),%bl
+	testb	%bl,%bl
+	jz	L3
+	cmpb	%bl,(%ecx)
+	jne	L3
+
+	incl	%eax
+	incl	%ecx
+	decl	%edx
+	jz	L4
+	movb	(%eax),%bl
+	testb	%bl,%bl
+	jz	L3
+	cmpb	%bl,(%ecx)
+	jne	L3
+
+	incl	%eax
+	incl	%ecx
+	decl	%edx
+	jz	L4
+	movb	(%eax),%bl
+	testb	%bl,%bl
+	jz	L3
+	cmpb	%bl,(%ecx)
+	je	L1
+
+	.align 2,0x90
+L3:	movzbl	(%eax),%eax		/* unsigned comparision */
+	movzbl	(%ecx),%ecx
+	subl	%ecx,%eax
+	popl	%ebx
+	ret
+	.align 2,0x90
+L4:	xorl	%eax,%eax
+	popl	%ebx
+	ret
+END(strncmp)
diff --git a/libc/arch-x86/include/machine/_types.h b/libc/arch-x86/include/machine/_types.h
deleted file mode 100644
index 3806f78..0000000
--- a/libc/arch-x86/include/machine/_types.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*	$OpenBSD: _types.h,v 1.2 2006/01/13 17:50:06 millert Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)types.h	8.3 (Berkeley) 1/5/94
- *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
- */
-
-#ifndef _I386__TYPES_H_
-#define _I386__TYPES_H_
-
-/* 7.18.1.1 Exact-width integer types */
-typedef	__signed char		__int8_t;
-typedef	unsigned char		__uint8_t;
-typedef	short			__int16_t;
-typedef	unsigned short		__uint16_t;
-typedef	int			__int32_t;
-typedef	unsigned int		__uint32_t;
-/* LONGLONG */
-typedef	long long		__int64_t;
-/* LONGLONG */
-typedef	unsigned long long	__uint64_t;
-
-/* 7.18.1.2 Minimum-width integer types */
-typedef	__int8_t		__int_least8_t;
-typedef	__uint8_t		__uint_least8_t;
-typedef	__int16_t		__int_least16_t;
-typedef	__uint16_t		__uint_least16_t;
-typedef	__int32_t		__int_least32_t;
-typedef	__uint32_t		__uint_least32_t;
-typedef	__int64_t		__int_least64_t;
-typedef	__uint64_t		__uint_least64_t;
-
-/* 7.18.1.3 Fastest minimum-width integer types */
-typedef	__int32_t		__int_fast8_t;
-typedef	__uint32_t		__uint_fast8_t;
-typedef	__int32_t		__int_fast16_t;
-typedef	__uint32_t		__uint_fast16_t;
-typedef	__int32_t		__int_fast32_t;
-typedef	__uint32_t		__uint_fast32_t;
-typedef	__int64_t		__int_fast64_t;
-typedef	__uint64_t		__uint_fast64_t;
-
-/* 7.18.1.4 Integer types capable of holding object pointers */
-typedef	int 			__intptr_t;
-typedef	unsigned int 	__uintptr_t;
-
-/* 7.18.1.5 Greatest-width integer types */
-typedef	__int64_t		__intmax_t;
-typedef	__uint64_t		__uintmax_t;
-
-/* Register size */
-typedef __int32_t		__register_t;
-
-/* VM system types */
-typedef unsigned long		__vaddr_t;
-typedef unsigned long		__paddr_t;
-typedef unsigned long		__vsize_t;
-typedef unsigned long		__psize_t;
-
-/* Standard system types */
-typedef int			__clock_t;
-typedef int			__clockid_t;
-typedef double			__double_t;
-typedef float			__float_t;
-typedef long			__ptrdiff_t;
-typedef	int			__time_t;
-typedef int			__timer_t;
-#if defined(__GNUC__) && __GNUC__ >= 3
-typedef	__builtin_va_list	__va_list;
-#else
-typedef	char *			__va_list;
-#endif
-
-/* Wide character support types */
-#ifndef __cplusplus
-typedef	int			__wchar_t;
-#endif
-typedef int			__wint_t;
-typedef	int			__rune_t;
-typedef	void *			__wctrans_t;
-typedef	void *			__wctype_t;
-
-/* Feature test macros */
-#define __HAVE_CPUINFO
-#define __HAVE_MUTEX
-
-#endif	/* _I386__TYPES_H_ */
diff --git a/libc/arch-x86/include/machine/asm.h b/libc/arch-x86/include/machine/asm.h
index 5ccf78f..672493d 100644
--- a/libc/arch-x86/include/machine/asm.h
+++ b/libc/arch-x86/include/machine/asm.h
@@ -37,50 +37,17 @@
 #ifndef _I386_ASM_H_
 #define _I386_ASM_H_
 
-#ifdef _KERNEL_OPT
-#include "opt_multiprocessor.h"
-#endif
-
-#ifdef PIC
 #define PIC_PROLOGUE	\
 	pushl	%ebx;	\
-	call	1f;	\
-1:			\
+	call	666f;	\
+666:			\
 	popl	%ebx;	\
-	addl	$_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+	addl	$_GLOBAL_OFFSET_TABLE_+[.-666b], %ebx
 #define PIC_EPILOGUE	\
 	popl	%ebx
 #define PIC_PLT(x)	x@PLT
 #define PIC_GOT(x)	x@GOT(%ebx)
 #define PIC_GOTOFF(x)	x@GOTOFF(%ebx)
-#else
-#define PIC_PROLOGUE
-#define PIC_EPILOGUE
-#define PIC_PLT(x)	x
-#define PIC_GOT(x)	x
-#define PIC_GOTOFF(x)	x
-#endif
-
-#ifdef __ELF__
-# define _C_LABEL(x)	x
-#else
-# ifdef __STDC__
-#  define _C_LABEL(x)	_ ## x
-# else
-#  define _C_LABEL(x)	_/**/x
-# endif
-#endif
-#define	_ASM_LABEL(x)	x
-
-#define CVAROFF(x, y)		_C_LABEL(x) + y
-
-#ifdef __STDC__
-# define __CONCAT(x,y)	x ## y
-# define __STRING(x)	#x
-#else
-# define __CONCAT(x,y)	x/**/y
-# define __STRING(x)	"x"
-#endif
 
 /* let kernels and others override entrypoint alignment */
 #if !defined(_ALIGN_TEXT) && !defined(_KERNEL)
@@ -93,126 +60,4 @@
 # endif
 #endif
 
-#define _ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,@function; x: .cfi_startproc;
-#define _LABEL(x) \
-	.globl x; x:
-
-#ifdef _KERNEL
-
-#define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off)
-
-/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
-#ifdef __ELF__
-#ifdef __STDC__
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
-#define	IDTVEC_END(name) \
-	.size X ## name, . - X ## name
-#else 
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
-#define	IDTVEC_END(name) \
-	.size X/**/name, . - X/**/name
-#endif /* __STDC__ */ 
-#else 
-#ifdef __STDC__
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name: 
-#define	IDTVEC_END(name) \
-	.size _X ## name, . - _X ## name
-#else
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name:
-#define	IDTVEC_END(name) \
-	.size _X/**/name, . - _X/**/name
-#endif /* __STDC__ */
-#endif /* __ELF__ */
-
-#ifdef _STANDALONE
-#define ALIGN_DATA	.align	4
-#define ALIGN_TEXT	.align	4	/* 4-byte boundaries */
-#define SUPERALIGN_TEXT	.align	16	/* 15-byte boundaries */
-#elif defined __ELF__
-#define ALIGN_DATA	.align	4
-#define ALIGN_TEXT	.align	16	/* 16-byte boundaries */
-#define SUPERALIGN_TEXT	.align	16	/* 16-byte boundaries */
-#else
-#define ALIGN_DATA	.align	2
-#define ALIGN_TEXT	.align	4	/* 16-byte boundaries */
-#define SUPERALIGN_TEXT	.align	4	/* 16-byte boundaries */
-#endif /* __ELF__ */
-
-#define _ALIGN_TEXT ALIGN_TEXT
-
-#ifdef GPROF
-#ifdef __ELF__
-#define	MCOUNT_ASM	call	_C_LABEL(__mcount)
-#else /* __ELF__ */
-#define	MCOUNT_ASM	call	_C_LABEL(mcount)
-#endif /* __ELF__ */
-#else /* GPROF */
-#define	MCOUNT_ASM	/* nothing */
-#endif /* GPROF */
-
-#endif /* _KERNEL */
-
-
-
-#ifdef GPROF
-# ifdef __ELF__
-#  define _PROF_PROLOGUE	\
-	pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp
-# else 
-#  define _PROF_PROLOGUE	\
-	pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp
-# endif
-#else
-# define _PROF_PROLOGUE
-#endif
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
-#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	LABEL(y)	_LABEL(_C_LABEL(y))
-#define	END(y)		.cfi_endproc; .size y, . - y
-
-#define	ASMSTR		.asciz
-
-#ifdef __ELF__
-#define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
-#else
-#define RCSID(x)	.text; .asciz x
-#endif
-
-#ifdef NO_KERNEL_RCSIDS
-#define	__KERNEL_RCSID(_n, _s)	/* nothing */
-#else
-#define	__KERNEL_RCSID(_n, _s)	RCSID(_s)
-#endif
-
-#ifdef __ELF__
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-#endif
-/*
- * STRONG_ALIAS: create a strong alias.
- */
-#define STRONG_ALIAS(alias,sym)						\
-	.globl alias;							\
-	alias = sym
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning. ## sym;				\
-	.ascii msg;							\
-	.popsection
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning./**/sym;				\
-	.ascii msg;							\
-	.popsection
-#endif /* __STDC__ */
-
 #endif /* !_I386_ASM_H_ */
diff --git a/libc/arch-x86/include/machine/ieee.h b/libc/arch-x86/include/machine/ieee.h
deleted file mode 100644
index 55b3703..0000000
--- a/libc/arch-x86/include/machine/ieee.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*	$OpenBSD: ieee.h,v 1.2 2003/06/02 23:27:47 millert Exp $ */
-/*	$NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */
-
-/*
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Lawrence Berkeley Laboratory.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
- */
-
-/*
- * ieee.h defines the machine-dependent layout of the machine's IEEE
- * floating point.  It does *not* define (yet?) any of the rounding
- * mode bits, exceptions, and so forth.
- */
-
-/*
- * Define the number of bits in each fraction and exponent.
- *
- *		     k	         k+1
- * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
- *
- *					  (-exp_bias+1)
- * as fractions that look like 0.fffff x 2             .  This means that
- *
- *			 -126
- * the number 0.10000 x 2    , for instance, is the same as the normalized
- *
- *		-127			   -128
- * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
- *
- *				  -129
- * in the fraction; to represent 2    , we need two, and so on.  This
- *
- *						     (-exp_bias-fracbits+1)
- * implies that the smallest denormalized number is 2
- *
- * for whichever format we are talking about: for single precision, for
- *
- *						-126		-149
- * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
- *
- * -149 == -127 - 23 + 1.
- */
-#define	SNG_EXPBITS	8
-#define	SNG_FRACBITS	23
-
-#define	DBL_EXPBITS	11
-#define	DBL_FRACBITS	52
-
-#define	EXT_EXPBITS	15
-#define	EXT_FRACBITS	112
-
-struct ieee_single {
-	u_int	sng_frac:23;
-	u_int	sng_exp:8;
-	u_int	sng_sign:1;
-};
-
-struct ieee_double {
-	u_int	dbl_fracl;
-	u_int	dbl_frach:20;
-	u_int	dbl_exp:11;
-	u_int	dbl_sign:1;
-};
-
-struct ieee_ext {
-	u_int	ext_fracl;
-	u_int	ext_fraclm;
-	u_int	ext_frachm;
-	u_int	ext_frach:16;
-	u_int	ext_exp:15;
-	u_int	ext_sign:1;
-};
-
-/*
- * Floats whose exponent is in [1..INFNAN) (of whatever type) are
- * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
- * Floats whose exponent is zero are either zero (iff all fraction
- * bits are zero) or subnormal values.
- *
- * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
- * high fraction; if the bit is set, it is a `quiet NaN'.
- */
-#define	SNG_EXP_INFNAN	255
-#define	DBL_EXP_INFNAN	2047
-#define	EXT_EXP_INFNAN	32767
-
-#if 0
-#define	SNG_QUIETNAN	(1 << 22)
-#define	DBL_QUIETNAN	(1 << 19)
-#define	EXT_QUIETNAN	(1 << 15)
-#endif
-
-/*
- * Exponent biases.
- */
-#define	SNG_EXP_BIAS	127
-#define	DBL_EXP_BIAS	1023
-#define	EXT_EXP_BIAS	16383
diff --git a/libc/arch-x86/include/machine/limits.h b/libc/arch-x86/include/machine/limits.h
deleted file mode 100644
index 86fd854..0000000
--- a/libc/arch-x86/include/machine/limits.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.11 2006/01/06 22:48:47 millert Exp $	*/
-/*	$NetBSD: limits.h,v 1.11 1995/12/21 01:08:59 mycroft Exp $	*/
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)limits.h	7.2 (Berkeley) 6/28/90
- */
-
-#ifndef _MACHINE_LIMITS_H_
-#define _MACHINE_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	1		/* no multibyte characters */
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	UINT_MAX	/* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define	SSIZE_MAX	INT_MAX		/* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	UINT_MAX	/* max value for a size_t (historic) */
-
-#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
-#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
-#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#define LONGLONG_BIT    64
-#define LONGLONG_MIN    (-9223372036854775807LL-1)
-#define LONGLONG_MAX    9223372036854775807LL
-#define ULONGLONG_MAX   18446744073709551615ULL
-
-#endif /* _MACHINE_LIMITS_H_ */
diff --git a/libc/arch-x86/silvermont/silvermont.mk b/libc/arch-x86/silvermont/silvermont.mk
new file mode 100644
index 0000000..176bee3
--- /dev/null
+++ b/libc/arch-x86/silvermont/silvermont.mk
@@ -0,0 +1,32 @@
+libc_bionic_src_files_x86 += \
+    arch-x86/silvermont/string/sse2-bcopy-slm.S \
+    arch-x86/silvermont/string/sse2-bzero-slm.S \
+    arch-x86/silvermont/string/sse2-memcpy-slm.S \
+    arch-x86/silvermont/string/sse2-memmove-slm.S \
+    arch-x86/silvermont/string/sse2-memset-slm.S \
+    arch-x86/silvermont/string/sse2-stpcpy-slm.S \
+    arch-x86/silvermont/string/sse2-stpncpy-slm.S \
+    arch-x86/silvermont/string/sse2-strcpy-slm.S \
+    arch-x86/silvermont/string/sse2-strlen-slm.S \
+    arch-x86/silvermont/string/sse2-strncpy-slm.S \
+    arch-x86/silvermont/string/sse4-memcmp-slm.S \
+    arch-x86/silvermont/string/sse4-wmemcmp-slm.S
+
+libc_bionic_src_files_x86 += \
+    arch-x86/atom/string/sse2-memchr-atom.S \
+    arch-x86/atom/string/sse2-memrchr-atom.S \
+    arch-x86/atom/string/sse2-strchr-atom.S \
+    arch-x86/atom/string/sse2-strrchr-atom.S \
+    arch-x86/atom/string/sse2-strnlen-atom.S \
+    arch-x86/atom/string/sse2-wcschr-atom.S \
+    arch-x86/atom/string/sse2-wcsrchr-atom.S \
+    arch-x86/atom/string/sse2-wcslen-atom.S \
+    arch-x86/atom/string/sse2-wcscmp-atom.S \
+    arch-x86/atom/string/ssse3-strncat-atom.S \
+    arch-x86/atom/string/ssse3-strlcat-atom.S \
+    arch-x86/atom/string/ssse3-strlcpy-atom.S \
+    arch-x86/atom/string/ssse3-strcmp-atom.S \
+    arch-x86/atom/string/ssse3-strncmp-atom.S \
+    arch-x86/atom/string/ssse3-strcat-atom.S \
+    arch-x86/atom/string/ssse3-wcscat-atom.S \
+    arch-x86/atom/string/ssse3-wcscpy-atom.S
diff --git a/libc/arch-x86/silvermont/string/cache.h b/libc/arch-x86/silvermont/string/cache.h
new file mode 100644
index 0000000..c342b1c
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/cache.h
@@ -0,0 +1,36 @@
+/*
+Copyright (c) 2010, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Values are optimized for Silvermont */
+#define SHARED_CACHE_SIZE	(1024*1024)			/* Silvermont L2 Cache */
+#define DATA_CACHE_SIZE		(24*1024)			/* Silvermont L1 Data Cache */
+
+#define SHARED_CACHE_SIZE_HALF	(SHARED_CACHE_SIZE / 2)
+#define DATA_CACHE_SIZE_HALF	(DATA_CACHE_SIZE / 2)
diff --git a/libc/arch-x86/silvermont/string/sse2-bcopy-slm.S b/libc/arch-x86/silvermont/string/sse2-bcopy-slm.S
new file mode 100644
index 0000000..190d52f
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-bcopy-slm.S
@@ -0,0 +1,34 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#define MEMMOVE	bcopy
+#define USE_AS_BCOPY
+#include "sse2-memmove-slm.S"
diff --git a/libc/arch-x86/silvermont/string/sse2-bzero-slm.S b/libc/arch-x86/silvermont/string/sse2-bzero-slm.S
new file mode 100644
index 0000000..b682ed6
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-bzero-slm.S
@@ -0,0 +1,33 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define USE_AS_BZERO
+#define MEMSET  bzero
+#include "sse2-memset-slm.S"
diff --git a/libc/arch-x86/silvermont/string/sse2-memcpy-slm.S b/libc/arch-x86/silvermont/string/sse2-memcpy-slm.S
new file mode 100644
index 0000000..1b305c7
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-memcpy-slm.S
@@ -0,0 +1,308 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef MEMCPY
+# define MEMCPY	memcpy
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)		\
+	.type name,  @function;		\
+	.globl name;		\
+	.p2align 4;		\
+name:		\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)		\
+	cfi_endproc;		\
+	.size name, .-name
+#endif
+
+#define DEST		PARMS
+#define SRC		DEST+4
+#define LEN		SRC+4
+
+#define CFI_PUSH(REG)		\
+  cfi_adjust_cfa_offset (4);		\
+  cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)		\
+  cfi_adjust_cfa_offset (-4);		\
+  cfi_restore (REG)
+
+#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
+#define POP(REG)	popl REG; CFI_POP (REG)
+
+#define PARMS		8		/* Preserve EBX.  */
+#define ENTRANCE	PUSH (%ebx);
+#define RETURN_END	POP (%ebx); ret
+#define RETURN		RETURN_END; CFI_PUSH (%ebx)
+
+	.section .text.sse2,"ax",@progbits
+ENTRY (MEMCPY)
+	ENTRANCE
+	movl	LEN(%esp), %ecx
+	movl	SRC(%esp), %eax
+	movl	DEST(%esp), %edx
+
+	cmp	%eax, %edx
+	je	L(return)
+
+	cmp	$16, %ecx
+	jbe	L(len_0_16_bytes)
+
+	cmp     $SHARED_CACHE_SIZE_HALF, %ecx
+	jae     L(large_page)
+
+	movdqu	(%eax), %xmm0
+	movdqu	-16(%eax, %ecx), %xmm1
+	cmpl    $32, %ecx
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, -16(%edx, %ecx)
+	jbe	L(return)
+
+	movdqu	16(%eax), %xmm0
+	movdqu	-32(%eax, %ecx), %xmm1
+	cmpl    $64, %ecx
+	movdqu	%xmm0, 16(%edx)
+	movdqu	%xmm1, -32(%edx, %ecx)
+	jbe	L(return)
+
+	movdqu	32(%eax), %xmm0
+	movdqu	48(%eax), %xmm1
+	movdqu	-48(%eax, %ecx), %xmm2
+	movdqu	-64(%eax, %ecx), %xmm3
+	cmpl    $128, %ecx
+	movdqu	%xmm0, 32(%edx)
+	movdqu	%xmm1, 48(%edx)
+	movdqu	%xmm2, -48(%edx, %ecx)
+	movdqu	%xmm3, -64(%edx, %ecx)
+	jbe	L(return)
+
+/* Now the main loop: we align the address of the destination.  */
+	leal	64(%edx), %ebx
+	andl	$-64, %ebx
+
+	addl	%edx, %ecx
+	andl	$-64, %ecx
+
+	subl	%edx, %eax
+
+/* We should stop two iterations before the termination
+	(in order not to misprefetch).  */
+	subl	$64, %ecx
+	cmpl	%ebx, %ecx
+	je	L(main_loop_just_one_iteration)
+
+	subl	$64, %ecx
+	cmpl	%ebx, %ecx
+	je	L(main_loop_last_two_iterations)
+
+
+	.p2align 4
+L(main_loop_cache):
+
+	prefetcht0 128(%ebx, %eax)
+
+	movdqu	(%ebx, %eax), %xmm0
+	movdqu	16(%ebx, %eax), %xmm1
+	movdqu	32(%ebx, %eax), %xmm2
+	movdqu	48(%ebx, %eax), %xmm3
+	movdqa	%xmm0, (%ebx)
+	movdqa	%xmm1, 16(%ebx)
+	movdqa	%xmm2, 32(%ebx)
+	movdqa	%xmm3, 48(%ebx)
+	lea	64(%ebx), %ebx
+	cmpl	%ebx, %ecx
+	jne	L(main_loop_cache)
+
+L(main_loop_last_two_iterations):
+	movdqu	(%ebx, %eax), %xmm0
+	movdqu	16(%ebx, %eax), %xmm1
+	movdqu	32(%ebx, %eax), %xmm2
+	movdqu	48(%ebx, %eax), %xmm3
+	movdqu	64(%ebx, %eax), %xmm4
+	movdqu	80(%ebx, %eax), %xmm5
+	movdqu	96(%ebx, %eax), %xmm6
+	movdqu	112(%ebx, %eax), %xmm7
+	movdqa	%xmm0, (%ebx)
+	movdqa	%xmm1, 16(%ebx)
+	movdqa	%xmm2, 32(%ebx)
+	movdqa	%xmm3, 48(%ebx)
+	movdqa	%xmm4, 64(%ebx)
+	movdqa	%xmm5, 80(%ebx)
+	movdqa	%xmm6, 96(%ebx)
+	movdqa	%xmm7, 112(%ebx)
+	jmp	L(return)
+
+L(main_loop_just_one_iteration):
+	movdqu	(%ebx, %eax), %xmm0
+	movdqu	16(%ebx, %eax), %xmm1
+	movdqu	32(%ebx, %eax), %xmm2
+	movdqu	48(%ebx, %eax), %xmm3
+	movdqa	%xmm0, (%ebx)
+	movdqa	%xmm1, 16(%ebx)
+	movdqa	%xmm2, 32(%ebx)
+	movdqa	%xmm3, 48(%ebx)
+	jmp	L(return)
+
+L(large_page):
+	movdqu	(%eax), %xmm0
+	movdqu	16(%eax), %xmm1
+	movdqu	32(%eax), %xmm2
+	movdqu	48(%eax), %xmm3
+	movdqu	-64(%eax, %ecx), %xmm4
+	movdqu	-48(%eax, %ecx), %xmm5
+	movdqu	-32(%eax, %ecx), %xmm6
+	movdqu	-16(%eax, %ecx), %xmm7
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, 16(%edx)
+	movdqu	%xmm2, 32(%edx)
+	movdqu	%xmm3, 48(%edx)
+	movdqu	%xmm4, -64(%edx, %ecx)
+	movdqu	%xmm5, -48(%edx, %ecx)
+	movdqu	%xmm6, -32(%edx, %ecx)
+	movdqu	%xmm7, -16(%edx, %ecx)
+
+	movdqu	64(%eax), %xmm0
+	movdqu	80(%eax), %xmm1
+	movdqu	96(%eax), %xmm2
+	movdqu	112(%eax), %xmm3
+	movdqu	-128(%eax, %ecx), %xmm4
+	movdqu	-112(%eax, %ecx), %xmm5
+	movdqu	-96(%eax, %ecx), %xmm6
+	movdqu	-80(%eax, %ecx), %xmm7
+	movdqu	%xmm0, 64(%edx)
+	movdqu	%xmm1, 80(%edx)
+	movdqu	%xmm2, 96(%edx)
+	movdqu	%xmm3, 112(%edx)
+	movdqu	%xmm4, -128(%edx, %ecx)
+	movdqu	%xmm5, -112(%edx, %ecx)
+	movdqu	%xmm6, -96(%edx, %ecx)
+	movdqu	%xmm7, -80(%edx, %ecx)
+
+/* Now the main loop with non temporal stores. We align
+	the address of the destination.  */
+	leal	128(%edx), %ebx
+	andl	$-128, %ebx
+
+	addl	%edx, %ecx
+	andl	$-128, %ecx
+
+	subl	%edx, %eax
+
+	.p2align 4
+L(main_loop_large_page):
+	movdqu	(%ebx, %eax), %xmm0
+	movdqu	16(%ebx, %eax), %xmm1
+	movdqu	32(%ebx, %eax), %xmm2
+	movdqu	48(%ebx, %eax), %xmm3
+	movdqu	64(%ebx, %eax), %xmm4
+	movdqu	80(%ebx, %eax), %xmm5
+	movdqu	96(%ebx, %eax), %xmm6
+	movdqu	112(%ebx, %eax), %xmm7
+	movntdq	%xmm0, (%ebx)
+	movntdq	%xmm1, 16(%ebx)
+	movntdq	%xmm2, 32(%ebx)
+	movntdq	%xmm3, 48(%ebx)
+	movntdq	%xmm4, 64(%ebx)
+	movntdq	%xmm5, 80(%ebx)
+	movntdq	%xmm6, 96(%ebx)
+	movntdq	%xmm7, 112(%ebx)
+	lea	128(%ebx), %ebx
+	cmpl	%ebx, %ecx
+	jne	L(main_loop_large_page)
+	sfence
+	jmp	L(return)
+
+L(len_0_16_bytes):
+	testb	$24, %cl
+	jne	L(len_9_16_bytes)
+	testb	$4, %cl
+	.p2align 4,,5
+	jne	L(len_5_8_bytes)
+	testl	%ecx, %ecx
+	.p2align 4,,2
+	je	L(return)
+	movzbl	(%eax), %ebx
+	testb	$2, %cl
+	movb	%bl, (%edx)
+	je	L(return)
+	movzwl	-2(%eax,%ecx), %ebx
+	movw	%bx, -2(%edx,%ecx)
+	jmp	L(return)
+
+L(len_9_16_bytes):
+	movq	(%eax), %xmm0
+	movq	-8(%eax, %ecx), %xmm1
+	movq	%xmm0, (%edx)
+	movq	%xmm1, -8(%edx, %ecx)
+	jmp	L(return)
+
+L(len_5_8_bytes):
+	movl	(%eax), %ebx
+	movl	%ebx, (%edx)
+	movl	-4(%eax,%ecx), %ebx
+	movl	%ebx, -4(%edx,%ecx)
+	jmp	L(return)
+
+L(return):
+	movl	%edx, %eax
+	RETURN
+
+END (MEMCPY)
diff --git a/libc/arch-x86/silvermont/string/sse2-memmove-slm.S b/libc/arch-x86/silvermont/string/sse2-memmove-slm.S
new file mode 100644
index 0000000..b971f0b
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-memmove-slm.S
@@ -0,0 +1,542 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef MEMMOVE
+# define MEMMOVE	memmove
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)		\
+	.type name,  @function;		\
+	.globl name;		\
+	.p2align 4;		\
+name:		\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)		\
+	cfi_endproc;		\
+	.size name, .-name
+#endif
+
+#ifdef USE_AS_BCOPY
+# define SRC		PARMS
+# define DEST		SRC+4
+# define LEN		DEST+4
+#else
+# define DEST		PARMS
+# define SRC		DEST+4
+# define LEN		SRC+4
+#endif
+
+#define CFI_PUSH(REG)		\
+  cfi_adjust_cfa_offset (4);		\
+  cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)		\
+  cfi_adjust_cfa_offset (-4);		\
+  cfi_restore (REG)
+
+#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
+#define POP(REG)	popl REG; CFI_POP (REG)
+
+#define PARMS		8		/* Preserve EBX.  */
+#define ENTRANCE	PUSH (%ebx);
+#define RETURN_END	POP (%ebx); ret
+#define RETURN		RETURN_END; CFI_PUSH (%ebx)
+
+	.section .text.sse2,"ax",@progbits
+ENTRY (MEMMOVE)
+	ENTRANCE
+	movl	LEN(%esp), %ecx
+	movl	SRC(%esp), %eax
+	movl	DEST(%esp), %edx
+
+/* Check whether we should copy backward or forward.  */
+	cmp	%eax, %edx
+	je	L(mm_return)
+	jg	L(mm_len_0_or_more_backward)
+
+/* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128]
+	separately.  */
+	cmp	$16, %ecx
+	jbe	L(mm_len_0_16_bytes_forward)
+
+	cmpl	$32, %ecx
+	ja	L(mm_len_32_or_more_forward)
+
+/* Copy [0..32] and return.  */
+	movdqu	(%eax), %xmm0
+	movdqu	-16(%eax, %ecx), %xmm1
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, -16(%edx, %ecx)
+	jmp	L(mm_return)
+
+L(mm_len_32_or_more_forward):
+	cmpl	$64, %ecx
+	ja	L(mm_len_64_or_more_forward)
+
+/* Copy [0..64] and return.  */
+	movdqu	(%eax), %xmm0
+	movdqu	16(%eax), %xmm1
+	movdqu	-16(%eax, %ecx), %xmm2
+	movdqu	-32(%eax, %ecx), %xmm3
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, 16(%edx)
+	movdqu	%xmm2, -16(%edx, %ecx)
+	movdqu	%xmm3, -32(%edx, %ecx)
+	jmp	L(mm_return)
+
+L(mm_len_64_or_more_forward):
+	cmpl	$128, %ecx
+	ja	L(mm_len_128_or_more_forward)
+
+/* Copy [0..128] and return.  */
+	movdqu	(%eax), %xmm0
+	movdqu	16(%eax), %xmm1
+	movdqu	32(%eax), %xmm2
+	movdqu	48(%eax), %xmm3
+	movdqu	-64(%eax, %ecx), %xmm4
+	movdqu	-48(%eax, %ecx), %xmm5
+	movdqu	-32(%eax, %ecx), %xmm6
+	movdqu	-16(%eax, %ecx), %xmm7
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, 16(%edx)
+	movdqu	%xmm2, 32(%edx)
+	movdqu	%xmm3, 48(%edx)
+	movdqu	%xmm4, -64(%edx, %ecx)
+	movdqu	%xmm5, -48(%edx, %ecx)
+	movdqu	%xmm6, -32(%edx, %ecx)
+	movdqu	%xmm7, -16(%edx, %ecx)
+	jmp	L(mm_return)
+
+L(mm_len_128_or_more_forward):
+	PUSH (%esi)
+	PUSH (%edi)
+
+/* Aligning the address of destination.  */
+	movdqu	(%eax), %xmm0
+	movdqu	16(%eax), %xmm1
+	movdqu	32(%eax), %xmm2
+	movdqu	48(%eax), %xmm3
+
+	leal	64(%edx), %edi
+	andl	$-64, %edi
+	subl	%edx, %eax
+
+	movdqu	(%eax, %edi), %xmm4
+	movdqu	16(%eax, %edi), %xmm5
+	movdqu	32(%eax, %edi), %xmm6
+	movdqu	48(%eax, %edi), %xmm7
+
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, 16(%edx)
+	movdqu	%xmm2, 32(%edx)
+	movdqu	%xmm3, 48(%edx)
+	movdqa	%xmm4, (%edi)
+	movaps	%xmm5, 16(%edi)
+	movaps	%xmm6, 32(%edi)
+	movaps	%xmm7, 48(%edi)
+	addl	$64, %edi
+
+	leal	(%edx, %ecx), %ebx
+	andl	$-64, %ebx
+	cmp	%edi, %ebx
+	jbe	L(mm_copy_remaining_forward)
+
+	cmp	$SHARED_CACHE_SIZE_HALF, %ecx
+	jae	L(mm_large_page_loop_forward)
+
+	.p2align 4
+L(mm_main_loop_forward):
+
+	prefetcht0 128(%eax, %edi)
+
+	movdqu	(%eax, %edi), %xmm0
+	movdqu	16(%eax, %edi), %xmm1
+	movdqu	32(%eax, %edi), %xmm2
+	movdqu	48(%eax, %edi), %xmm3
+	movdqa	%xmm0, (%edi)
+	movaps	%xmm1, 16(%edi)
+	movaps	%xmm2, 32(%edi)
+	movaps	%xmm3, 48(%edi)
+	leal	64(%edi), %edi
+	cmp	%edi, %ebx
+	ja	L(mm_main_loop_forward)
+
+L(mm_copy_remaining_forward):
+	addl	%edx, %ecx
+	subl	%edi, %ecx
+/* We copied all up till %edi position in the dst.
+	In %ecx now is how many bytes are left to copy.
+	Now we need to advance %esi. */
+	leal	(%edi, %eax), %esi
+
+L(mm_remaining_0_64_bytes_forward):
+	cmp	$32, %ecx
+	ja	L(mm_remaining_33_64_bytes_forward)
+	cmp	$16, %ecx
+	ja	L(mm_remaining_17_32_bytes_forward)
+	testl	%ecx, %ecx
+	.p2align 4,,2
+	je	L(mm_return_pop_all)
+
+	cmpb	$8, %cl
+	ja	L(mm_remaining_9_16_bytes_forward)
+	cmpb	$4, %cl
+	.p2align 4,,5
+	ja	L(mm_remaining_5_8_bytes_forward)
+	cmpb	$2, %cl
+	.p2align 4,,1
+	ja	L(mm_remaining_3_4_bytes_forward)
+	movzbl	-1(%esi,%ecx), %eax
+	movzbl	(%esi), %ebx
+	movb	%al, -1(%edi,%ecx)
+	movb	%bl, (%edi)
+	jmp	L(mm_return_pop_all)
+
+L(mm_remaining_33_64_bytes_forward):
+	movdqu	(%esi), %xmm0
+	movdqu	16(%esi), %xmm1
+	movdqu	-32(%esi, %ecx), %xmm2
+	movdqu	-16(%esi, %ecx), %xmm3
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm1, 16(%edi)
+	movdqu	%xmm2, -32(%edi, %ecx)
+	movdqu	%xmm3, -16(%edi, %ecx)
+	jmp	L(mm_return_pop_all)
+
+L(mm_remaining_17_32_bytes_forward):
+	movdqu	(%esi), %xmm0
+	movdqu	-16(%esi, %ecx), %xmm1
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm1, -16(%edi, %ecx)
+	jmp	L(mm_return_pop_all)
+
+L(mm_remaining_9_16_bytes_forward):
+	movq	(%esi), %xmm0
+	movq	-8(%esi, %ecx), %xmm1
+	movq	%xmm0, (%edi)
+	movq	%xmm1, -8(%edi, %ecx)
+	jmp	L(mm_return_pop_all)
+
+L(mm_remaining_5_8_bytes_forward):
+	movl	(%esi), %eax
+	movl	-4(%esi,%ecx), %ebx
+	movl	%eax, (%edi)
+	movl	%ebx, -4(%edi,%ecx)
+	jmp	L(mm_return_pop_all)
+
+L(mm_remaining_3_4_bytes_forward):
+	movzwl	-2(%esi,%ecx), %eax
+	movzwl	(%esi), %ebx
+	movw	%ax, -2(%edi,%ecx)
+	movw	%bx, (%edi)
+	jmp	L(mm_return_pop_all)
+
+L(mm_len_0_16_bytes_forward):
+	testb	$24, %cl
+	jne	L(mm_len_9_16_bytes_forward)
+	testb	$4, %cl
+	.p2align 4,,5
+	jne	L(mm_len_5_8_bytes_forward)
+	testl	%ecx, %ecx
+	.p2align 4,,2
+	je	L(mm_return)
+	testb	$2, %cl
+	.p2align 4,,1
+	jne	L(mm_len_2_4_bytes_forward)
+	movzbl	-1(%eax,%ecx), %ebx
+	movzbl	(%eax), %eax
+	movb	%bl, -1(%edx,%ecx)
+	movb	%al, (%edx)
+	jmp	L(mm_return)
+
+L(mm_len_2_4_bytes_forward):
+	movzwl	-2(%eax,%ecx), %ebx
+	movzwl	(%eax), %eax
+	movw	%bx, -2(%edx,%ecx)
+	movw	%ax, (%edx)
+	jmp	L(mm_return)
+
+L(mm_len_5_8_bytes_forward):
+	movl	(%eax), %ebx
+	movl	-4(%eax,%ecx), %eax
+	movl	%ebx, (%edx)
+	movl	%eax, -4(%edx,%ecx)
+	jmp	L(mm_return)
+
+L(mm_len_9_16_bytes_forward):
+	movq	(%eax), %xmm0
+	movq	-8(%eax, %ecx), %xmm1
+	movq	%xmm0, (%edx)
+	movq	%xmm1, -8(%edx, %ecx)
+	jmp	L(mm_return)
+
+L(mm_recalc_len):
+/* Compute in %ecx how many bytes are left to copy after
+	the main loop stops.  */
+	movl	%ebx, %ecx
+	subl	%edx, %ecx
+/* The code for copying backwards.  */
+L(mm_len_0_or_more_backward):
+
+/* Now do checks for lengths. We do [0..16], [16..32], [32..64], [64..128]
+	separately.  */
+	cmp	$16, %ecx
+	jbe	L(mm_len_0_16_bytes_backward)
+
+	cmpl	$32, %ecx
+	jg	L(mm_len_32_or_more_backward)
+
+/* Copy [0..32] and return.  */
+	movdqu	(%eax), %xmm0
+	movdqu	-16(%eax, %ecx), %xmm1
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, -16(%edx, %ecx)
+	jmp	L(mm_return)
+
+L(mm_len_32_or_more_backward):
+	cmpl	$64, %ecx
+	jg	L(mm_len_64_or_more_backward)
+
+/* Copy [0..64] and return.  */
+	movdqu	(%eax), %xmm0
+	movdqu	16(%eax), %xmm1
+	movdqu	-16(%eax, %ecx), %xmm2
+	movdqu	-32(%eax, %ecx), %xmm3
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, 16(%edx)
+	movdqu	%xmm2, -16(%edx, %ecx)
+	movdqu	%xmm3, -32(%edx, %ecx)
+	jmp	L(mm_return)
+
+L(mm_len_64_or_more_backward):
+	cmpl	$128, %ecx
+	jg	L(mm_len_128_or_more_backward)
+
+/* Copy [0..128] and return.  */
+	movdqu	(%eax), %xmm0
+	movdqu	16(%eax), %xmm1
+	movdqu	32(%eax), %xmm2
+	movdqu	48(%eax), %xmm3
+	movdqu	-64(%eax, %ecx), %xmm4
+	movdqu	-48(%eax, %ecx), %xmm5
+	movdqu	-32(%eax, %ecx), %xmm6
+	movdqu	-16(%eax, %ecx), %xmm7
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm1, 16(%edx)
+	movdqu	%xmm2, 32(%edx)
+	movdqu	%xmm3, 48(%edx)
+	movdqu	%xmm4, -64(%edx, %ecx)
+	movdqu	%xmm5, -48(%edx, %ecx)
+	movdqu	%xmm6, -32(%edx, %ecx)
+	movdqu	%xmm7, -16(%edx, %ecx)
+	jmp	L(mm_return)
+
+L(mm_len_128_or_more_backward):
+	PUSH (%esi)
+	PUSH (%edi)
+
+/* Aligning the address of destination. We need to save
+	16 bits from the source in order not to overwrite them.  */
+	movdqu	-16(%eax, %ecx), %xmm0
+	movdqu	-32(%eax, %ecx), %xmm1
+	movdqu	-48(%eax, %ecx), %xmm2
+	movdqu	-64(%eax, %ecx), %xmm3
+
+	leal	(%edx, %ecx), %edi
+	andl	$-64, %edi
+
+	movl	%eax, %esi
+	subl	%edx, %esi
+
+	movdqu	-16(%edi, %esi), %xmm4
+	movdqu	-32(%edi, %esi), %xmm5
+	movdqu	-48(%edi, %esi), %xmm6
+	movdqu	-64(%edi, %esi), %xmm7
+
+	movdqu	%xmm0, -16(%edx, %ecx)
+	movdqu	%xmm1, -32(%edx, %ecx)
+	movdqu	%xmm2, -48(%edx, %ecx)
+	movdqu	%xmm3, -64(%edx, %ecx)
+	movdqa	%xmm4, -16(%edi)
+	movdqa	%xmm5, -32(%edi)
+	movdqa	%xmm6, -48(%edi)
+	movdqa	%xmm7, -64(%edi)
+	leal	-64(%edi), %edi
+
+	leal	64(%edx), %ebx
+	andl	$-64, %ebx
+
+	cmp	%edi, %ebx
+	jae	L(mm_main_loop_backward_end)
+
+	cmp	$SHARED_CACHE_SIZE_HALF, %ecx
+	jae	L(mm_large_page_loop_backward)
+
+	.p2align 4
+L(mm_main_loop_backward):
+
+	prefetcht0 -128(%edi, %esi)
+
+	movdqu	-64(%edi, %esi), %xmm0
+	movdqu	-48(%edi, %esi), %xmm1
+	movdqu	-32(%edi, %esi), %xmm2
+	movdqu	-16(%edi, %esi), %xmm3
+	movdqa	%xmm0, -64(%edi)
+	movdqa	%xmm1, -48(%edi)
+	movdqa	%xmm2, -32(%edi)
+	movdqa	%xmm3, -16(%edi)
+	leal	-64(%edi), %edi
+	cmp	%edi, %ebx
+	jb	L(mm_main_loop_backward)
+L(mm_main_loop_backward_end):
+	POP (%edi)
+	POP (%esi)
+	jmp	L(mm_recalc_len)
+
+/* Copy [0..16] and return.  */
+L(mm_len_0_16_bytes_backward):
+	testb	$24, %cl
+	jnz	L(mm_len_9_16_bytes_backward)
+	testb	$4, %cl
+	.p2align 4,,5
+	jnz	L(mm_len_5_8_bytes_backward)
+	testl	%ecx, %ecx
+	.p2align 4,,2
+	je	L(mm_return)
+	testb	$2, %cl
+	.p2align 4,,1
+	jne	L(mm_len_3_4_bytes_backward)
+	movzbl	-1(%eax,%ecx), %ebx
+	movzbl	(%eax), %eax
+	movb	%bl, -1(%edx,%ecx)
+	movb	%al, (%edx)
+	jmp	L(mm_return)
+
+L(mm_len_3_4_bytes_backward):
+	movzwl	-2(%eax,%ecx), %ebx
+	movzwl	(%eax), %eax
+	movw	%bx, -2(%edx,%ecx)
+	movw	%ax, (%edx)
+	jmp	L(mm_return)
+
+L(mm_len_9_16_bytes_backward):
+	PUSH (%esi)
+	movl	-4(%eax,%ecx), %ebx
+	movl	-8(%eax,%ecx), %esi
+	movl	%ebx, -4(%edx,%ecx)
+	movl	%esi, -8(%edx,%ecx)
+	subl	$8, %ecx
+	POP (%esi)
+	jmp	L(mm_len_0_16_bytes_backward)
+
+L(mm_len_5_8_bytes_backward):
+	movl	(%eax), %ebx
+	movl	-4(%eax,%ecx), %eax
+	movl	%ebx, (%edx)
+	movl	%eax, -4(%edx,%ecx)
+
+L(mm_return):
+	movl	%edx, %eax
+	RETURN
+
+L(mm_return_pop_all):
+	movl	%edx, %eax
+	POP (%edi)
+	POP (%esi)
+	RETURN
+
+/* Big length copy forward part.  */
+
+	.p2align 4
+L(mm_large_page_loop_forward):
+	movdqu	(%eax, %edi), %xmm0
+	movdqu	16(%eax, %edi), %xmm1
+	movdqu	32(%eax, %edi), %xmm2
+	movdqu	48(%eax, %edi), %xmm3
+	movntdq	%xmm0, (%edi)
+	movntdq	%xmm1, 16(%edi)
+	movntdq	%xmm2, 32(%edi)
+	movntdq	%xmm3, 48(%edi)
+	leal	64(%edi), %edi
+	cmp	%edi, %ebx
+	ja	L(mm_large_page_loop_forward)
+	sfence
+	jmp	L(mm_copy_remaining_forward)
+
+/* Big length copy backward part.  */
+	.p2align 4
+L(mm_large_page_loop_backward):
+	movdqu	-64(%edi, %esi), %xmm0
+	movdqu	-48(%edi, %esi), %xmm1
+	movdqu	-32(%edi, %esi), %xmm2
+	movdqu	-16(%edi, %esi), %xmm3
+	movntdq	%xmm0, -64(%edi)
+	movntdq	%xmm1, -48(%edi)
+	movntdq	%xmm2, -32(%edi)
+	movntdq	%xmm3, -16(%edi)
+	leal	-64(%edi), %edi
+	cmp	%edi, %ebx
+	jb	L(mm_large_page_loop_backward)
+	sfence
+	POP (%edi)
+	POP (%esi)
+	jmp	L(mm_recalc_len)
+
+END (MEMMOVE)
diff --git a/libc/arch-x86/silvermont/string/sse2-memset-slm.S b/libc/arch-x86/silvermont/string/sse2-memset-slm.S
new file mode 100644
index 0000000..c30bf74
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-memset-slm.S
@@ -0,0 +1,841 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef MEMSET
+# define MEMSET memset
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef ALIGN
+# define ALIGN(n)	.p2align n
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc			.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc			.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)		.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)			\
+	.type name,  @function;		\
+	.globl name;			\
+	.p2align 4;			\
+name:					\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)			\
+	cfi_endproc;			\
+	.size name, .-name
+#endif
+
+#define CFI_PUSH(REG)						\
+  cfi_adjust_cfa_offset (4);					\
+  cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)						\
+  cfi_adjust_cfa_offset (-4);					\
+  cfi_restore (REG)
+
+#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
+#define POP(REG)	popl REG; CFI_POP (REG)
+
+#ifdef USE_AS_BZERO
+# define DEST		PARMS
+# define LEN		DEST+4
+# define SETRTNVAL
+#else
+# define DEST		PARMS
+# define CHR		DEST+4
+# define LEN		CHR+4
+# define SETRTNVAL	movl DEST(%esp), %eax
+#endif
+
+#if (defined SHARED || defined __PIC__)
+# define ENTRANCE	PUSH (%ebx);
+# define RETURN_END	POP (%ebx); ret
+# define RETURN		RETURN_END; CFI_PUSH (%ebx)
+# define PARMS		8		/* Preserve EBX.  */
+# define JMPTBL(I, B)	I - B
+
+/* Load an entry in a jump table into EBX and branch to it.  TABLE is a
+   jump table with relative offsets.   */
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE)				\
+    /* We first load PC into EBX.  */				\
+    call	__x86.get_pc_thunk.bx;				\
+    /* Get the address of the jump table.  */			\
+    add		$(TABLE - .), %ebx;				\
+    /* Get the entry and convert the relative offset to the	\
+       absolute address.  */					\
+    add		(%ebx,%ecx,4), %ebx;				\
+    add		%ecx, %edx;					\
+    /* We loaded the jump table and adjuested EDX. Go.  */	\
+    jmp		*%ebx
+
+	.section	.gnu.linkonce.t.__x86.get_pc_thunk.bx,"ax",@progbits
+	.globl	__x86.get_pc_thunk.bx
+	.hidden	__x86.get_pc_thunk.bx
+	ALIGN (4)
+	.type	__x86.get_pc_thunk.bx,@function
+__x86.get_pc_thunk.bx:
+	movl	(%esp), %ebx
+	ret
+#else
+# define ENTRANCE
+# define RETURN_END	ret
+# define RETURN		RETURN_END
+# define PARMS		4
+# define JMPTBL(I, B)	I
+
+/* Branch to an entry in a jump table.  TABLE is a jump table with
+   absolute offsets.  */
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE)				\
+    add		%ecx, %edx;					\
+    jmp		*TABLE(,%ecx,4)
+#endif
+
+	.section .text.sse2,"ax",@progbits
+	ALIGN (4)
+ENTRY (MEMSET)
+	ENTRANCE
+
+	movl	LEN(%esp), %ecx
+	cmp	$0, %ecx
+	ja	L(1byteormore)
+	SETRTNVAL
+	RETURN
+
+L(1byteormore):
+#ifdef USE_AS_BZERO
+	xor	%eax, %eax
+#else
+	movzbl	CHR(%esp), %eax
+	movb	%al, %ah
+	/* Fill the whole EAX with pattern.  */
+	movl	%eax, %edx
+	shl	 $16, %eax
+	or	%edx, %eax
+#endif
+	movl	DEST(%esp), %edx
+	cmp	$1, %ecx
+	je	L(1byte)
+	cmp	$16, %ecx
+	jae	L(16bytesormore)
+
+	cmp	$4, %ecx
+	jb	L(4bytesless)
+	movl	%eax, (%edx)
+	movl	%eax, -4(%edx, %ecx)
+	cmp	$8, %ecx
+	jb	L(8bytesless)
+	movl	%eax, 4(%edx)
+	movl	%eax, -8(%edx, %ecx)
+L(8bytesless):
+	SETRTNVAL
+	RETURN
+
+L(4bytesless):
+	movw	%ax, (%edx)
+	movw	%ax, -2(%edx, %ecx)
+	SETRTNVAL
+	RETURN
+
+L(1byte):
+	movb	%al, (%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(16bytesormore):
+#ifdef USE_AS_BZERO
+	pxor	%xmm0, %xmm0
+#else
+	movd	%eax, %xmm0
+	pshufd	$0, %xmm0, %xmm0
+#endif
+
+	cmp	$64, %ecx
+	ja	L(64bytesmore)
+	movdqu	%xmm0, (%edx)
+	movdqu	%xmm0, -16(%edx, %ecx)
+	cmp	$32, %ecx
+	jbe	L(32bytesless)
+	movdqu	%xmm0, 16(%edx)
+	movdqu	%xmm0, -32(%edx, %ecx)
+L(32bytesless):
+	SETRTNVAL
+	RETURN
+
+L(64bytesmore):
+	testl	$0xf, %edx
+	jz	L(aligned_16)
+L(not_aligned_16):
+	movdqu	%xmm0, (%edx)
+	movl	%edx, %eax
+	and	$-16, %edx
+	add	$16, %edx
+	sub	%edx, %eax
+	add	%eax, %ecx
+	movd	%xmm0, %eax
+
+	ALIGN (4)
+L(aligned_16):
+	cmp	$128, %ecx
+	jae	L(128bytesormore)
+
+L(aligned_16_less128bytes):
+	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+
+	ALIGN (4)
+L(128bytesormore):
+#ifdef SHARED_CACHE_SIZE
+	PUSH (%ebx)
+	mov	$SHARED_CACHE_SIZE, %ebx
+#else
+# if (defined SHARED || defined __PIC__)
+	call	__x86.get_pc_thunk.bx
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	mov	$__x86_shared_cache_size@GOTOFF(%ebx), %ebx
+# else
+	PUSH (%ebx)
+	mov	$__x86_shared_cache_size, %ebx
+# endif
+#endif
+	cmp	%ebx, %ecx
+	jae	L(128bytesormore_nt_start)
+
+	POP (%ebx)
+
+#ifdef DATA_CACHE_SIZE
+	PUSH (%ebx)
+	mov	$DATA_CACHE_SIZE, %ebx
+#else
+# if (defined SHARED || defined __PIC__)
+	call	__x86.get_pc_thunk.bx
+	add	$_GLOBAL_OFFSET_TABLE_, %ebx
+	mov	$__x86_data_cache_size@GOTOFF(%ebx), %ebx
+# else
+	PUSH (%ebx)
+	mov	$__x86_data_cache_size, %ebx
+# endif
+#endif
+
+	cmp	%ebx, %ecx
+	jae	L(128bytes_L2_normal)
+	subl	$128, %ecx
+L(128bytesormore_normal):
+	sub	$128, %ecx
+	movdqa	%xmm0, (%edx)
+	movaps	%xmm0, 0x10(%edx)
+	movaps	%xmm0, 0x20(%edx)
+	movaps	%xmm0, 0x30(%edx)
+	movaps	%xmm0, 0x40(%edx)
+	movaps	%xmm0, 0x50(%edx)
+	movaps	%xmm0, 0x60(%edx)
+	movaps	%xmm0, 0x70(%edx)
+	lea	128(%edx), %edx
+	jb	L(128bytesless_normal)
+
+
+	sub	$128, %ecx
+	movdqa	%xmm0, (%edx)
+	movaps	%xmm0, 0x10(%edx)
+	movaps	%xmm0, 0x20(%edx)
+	movaps	%xmm0, 0x30(%edx)
+	movaps	%xmm0, 0x40(%edx)
+	movaps	%xmm0, 0x50(%edx)
+	movaps	%xmm0, 0x60(%edx)
+	movaps	%xmm0, 0x70(%edx)
+	lea	128(%edx), %edx
+	jae	L(128bytesormore_normal)
+
+L(128bytesless_normal):
+	lea	128(%ecx), %ecx
+#if defined DATA_CACHE_SIZE || !(defined SHARED || defined __PIC__)
+	POP (%ebx)
+#endif
+	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+
+	ALIGN (4)
+L(128bytes_L2_normal):
+	prefetchnta	0x380(%edx)
+	prefetchnta	0x3c0(%edx)
+	sub	$128, %ecx
+	movdqa	%xmm0, (%edx)
+	movaps	%xmm0, 0x10(%edx)
+	movaps	%xmm0, 0x20(%edx)
+	movaps	%xmm0, 0x30(%edx)
+	movaps	%xmm0, 0x40(%edx)
+	movaps	%xmm0, 0x50(%edx)
+	movaps	%xmm0, 0x60(%edx)
+	movaps	%xmm0, 0x70(%edx)
+	add	$128, %edx
+	cmp	$128, %ecx
+	jae	L(128bytes_L2_normal)
+
+L(128bytesless_L2_normal):
+#if defined DATA_CACHE_SIZE || !(defined SHARED || defined __PIC__)
+	POP (%ebx)
+#endif
+	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+
+L(128bytesormore_nt_start):
+	sub	%ebx, %ecx
+	ALIGN (4)
+L(128bytesormore_shared_cache_loop):
+	prefetchnta	0x3c0(%edx)
+	prefetchnta	0x380(%edx)
+	sub	$0x80, %ebx
+	movdqa	%xmm0, (%edx)
+	movaps	%xmm0, 0x10(%edx)
+	movaps	%xmm0, 0x20(%edx)
+	movaps	%xmm0, 0x30(%edx)
+	movaps	%xmm0, 0x40(%edx)
+	movaps	%xmm0, 0x50(%edx)
+	movaps	%xmm0, 0x60(%edx)
+	movaps	%xmm0, 0x70(%edx)
+	add	$0x80, %edx
+	cmp	$0x80, %ebx
+	jae	L(128bytesormore_shared_cache_loop)
+	cmp	$0x80, %ecx
+	jb	L(shared_cache_loop_end)
+	ALIGN (4)
+L(128bytesormore_nt):
+	sub	$0x80, %ecx
+	movntdq	%xmm0, (%edx)
+	movntdq	%xmm0, 0x10(%edx)
+	movntdq	%xmm0, 0x20(%edx)
+	movntdq	%xmm0, 0x30(%edx)
+	movntdq	%xmm0, 0x40(%edx)
+	movntdq	%xmm0, 0x50(%edx)
+	movntdq	%xmm0, 0x60(%edx)
+	movntdq	%xmm0, 0x70(%edx)
+	add	$0x80, %edx
+	cmp	$0x80, %ecx
+	jae	L(128bytesormore_nt)
+	sfence
+L(shared_cache_loop_end):
+#if defined SHARED_CACHE_SIZE || !(defined SHARED || defined __PIC__)
+	POP (%ebx)
+#endif
+	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+
+
+	.pushsection .rodata.sse2,"a",@progbits
+	ALIGN (2)
+L(table_16_128bytes):
+	.int	JMPTBL (L(aligned_16_0bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_1bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_2bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_3bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_4bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_5bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_6bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_7bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_8bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_9bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_10bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_11bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_12bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_13bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_14bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_15bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_16bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_17bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_18bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_19bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_20bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_21bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_22bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_23bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_24bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_25bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_26bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_27bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_28bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_29bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_30bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_31bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_32bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_33bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_34bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_35bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_36bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_37bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_38bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_39bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_40bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_41bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_42bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_43bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_44bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_45bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_46bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_47bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_48bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_49bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_50bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_51bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_52bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_53bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_54bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_55bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_56bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_57bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_58bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_59bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_60bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_61bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_62bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_63bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_64bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_65bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_66bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_67bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_68bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_69bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_70bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_71bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_72bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_73bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_74bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_75bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_76bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_77bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_78bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_79bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_80bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_81bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_82bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_83bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_84bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_85bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_86bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_87bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_88bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_89bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_90bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_91bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_92bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_93bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_94bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_95bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_96bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_97bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_98bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_99bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_100bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_101bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_102bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_103bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_104bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_105bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_106bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_107bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_108bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_109bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_110bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_111bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_112bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_113bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_114bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_115bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_116bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_117bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_118bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_119bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_120bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_121bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_122bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_123bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_124bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_125bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_126bytes), L(table_16_128bytes))
+	.int	JMPTBL (L(aligned_16_127bytes), L(table_16_128bytes))
+	.popsection
+
+	ALIGN (4)
+L(aligned_16_112bytes):
+	movdqa	%xmm0, -112(%edx)
+L(aligned_16_96bytes):
+	movdqa	%xmm0, -96(%edx)
+L(aligned_16_80bytes):
+	movdqa	%xmm0, -80(%edx)
+L(aligned_16_64bytes):
+	movdqa	%xmm0, -64(%edx)
+L(aligned_16_48bytes):
+	movdqa	%xmm0, -48(%edx)
+L(aligned_16_32bytes):
+	movdqa	%xmm0, -32(%edx)
+L(aligned_16_16bytes):
+	movdqa	%xmm0, -16(%edx)
+L(aligned_16_0bytes):
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_113bytes):
+	movdqa	%xmm0, -113(%edx)
+L(aligned_16_97bytes):
+	movdqa	%xmm0, -97(%edx)
+L(aligned_16_81bytes):
+	movdqa	%xmm0, -81(%edx)
+L(aligned_16_65bytes):
+	movdqa	%xmm0, -65(%edx)
+L(aligned_16_49bytes):
+	movdqa	%xmm0, -49(%edx)
+L(aligned_16_33bytes):
+	movdqa	%xmm0, -33(%edx)
+L(aligned_16_17bytes):
+	movdqa	%xmm0, -17(%edx)
+L(aligned_16_1bytes):
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_114bytes):
+	movdqa	%xmm0, -114(%edx)
+L(aligned_16_98bytes):
+	movdqa	%xmm0, -98(%edx)
+L(aligned_16_82bytes):
+	movdqa	%xmm0, -82(%edx)
+L(aligned_16_66bytes):
+	movdqa	%xmm0, -66(%edx)
+L(aligned_16_50bytes):
+	movdqa	%xmm0, -50(%edx)
+L(aligned_16_34bytes):
+	movdqa	%xmm0, -34(%edx)
+L(aligned_16_18bytes):
+	movdqa	%xmm0, -18(%edx)
+L(aligned_16_2bytes):
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_115bytes):
+	movdqa	%xmm0, -115(%edx)
+L(aligned_16_99bytes):
+	movdqa	%xmm0, -99(%edx)
+L(aligned_16_83bytes):
+	movdqa	%xmm0, -83(%edx)
+L(aligned_16_67bytes):
+	movdqa	%xmm0, -67(%edx)
+L(aligned_16_51bytes):
+	movdqa	%xmm0, -51(%edx)
+L(aligned_16_35bytes):
+	movdqa	%xmm0, -35(%edx)
+L(aligned_16_19bytes):
+	movdqa	%xmm0, -19(%edx)
+L(aligned_16_3bytes):
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_116bytes):
+	movdqa	%xmm0, -116(%edx)
+L(aligned_16_100bytes):
+	movdqa	%xmm0, -100(%edx)
+L(aligned_16_84bytes):
+	movdqa	%xmm0, -84(%edx)
+L(aligned_16_68bytes):
+	movdqa	%xmm0, -68(%edx)
+L(aligned_16_52bytes):
+	movdqa	%xmm0, -52(%edx)
+L(aligned_16_36bytes):
+	movdqa	%xmm0, -36(%edx)
+L(aligned_16_20bytes):
+	movdqa	%xmm0, -20(%edx)
+L(aligned_16_4bytes):
+	movl	%eax, -4(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_117bytes):
+	movdqa	%xmm0, -117(%edx)
+L(aligned_16_101bytes):
+	movdqa	%xmm0, -101(%edx)
+L(aligned_16_85bytes):
+	movdqa	%xmm0, -85(%edx)
+L(aligned_16_69bytes):
+	movdqa	%xmm0, -69(%edx)
+L(aligned_16_53bytes):
+	movdqa	%xmm0, -53(%edx)
+L(aligned_16_37bytes):
+	movdqa	%xmm0, -37(%edx)
+L(aligned_16_21bytes):
+	movdqa	%xmm0, -21(%edx)
+L(aligned_16_5bytes):
+	movl	%eax, -5(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_118bytes):
+	movdqa	%xmm0, -118(%edx)
+L(aligned_16_102bytes):
+	movdqa	%xmm0, -102(%edx)
+L(aligned_16_86bytes):
+	movdqa	%xmm0, -86(%edx)
+L(aligned_16_70bytes):
+	movdqa	%xmm0, -70(%edx)
+L(aligned_16_54bytes):
+	movdqa	%xmm0, -54(%edx)
+L(aligned_16_38bytes):
+	movdqa	%xmm0, -38(%edx)
+L(aligned_16_22bytes):
+	movdqa	%xmm0, -22(%edx)
+L(aligned_16_6bytes):
+	movl	%eax, -6(%edx)
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_119bytes):
+	movdqa	%xmm0, -119(%edx)
+L(aligned_16_103bytes):
+	movdqa	%xmm0, -103(%edx)
+L(aligned_16_87bytes):
+	movdqa	%xmm0, -87(%edx)
+L(aligned_16_71bytes):
+	movdqa	%xmm0, -71(%edx)
+L(aligned_16_55bytes):
+	movdqa	%xmm0, -55(%edx)
+L(aligned_16_39bytes):
+	movdqa	%xmm0, -39(%edx)
+L(aligned_16_23bytes):
+	movdqa	%xmm0, -23(%edx)
+L(aligned_16_7bytes):
+	movl	%eax, -7(%edx)
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_120bytes):
+	movdqa	%xmm0, -120(%edx)
+L(aligned_16_104bytes):
+	movdqa	%xmm0, -104(%edx)
+L(aligned_16_88bytes):
+	movdqa	%xmm0, -88(%edx)
+L(aligned_16_72bytes):
+	movdqa	%xmm0, -72(%edx)
+L(aligned_16_56bytes):
+	movdqa	%xmm0, -56(%edx)
+L(aligned_16_40bytes):
+	movdqa	%xmm0, -40(%edx)
+L(aligned_16_24bytes):
+	movdqa	%xmm0, -24(%edx)
+L(aligned_16_8bytes):
+	movq	%xmm0, -8(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_121bytes):
+	movdqa	%xmm0, -121(%edx)
+L(aligned_16_105bytes):
+	movdqa	%xmm0, -105(%edx)
+L(aligned_16_89bytes):
+	movdqa	%xmm0, -89(%edx)
+L(aligned_16_73bytes):
+	movdqa	%xmm0, -73(%edx)
+L(aligned_16_57bytes):
+	movdqa	%xmm0, -57(%edx)
+L(aligned_16_41bytes):
+	movdqa	%xmm0, -41(%edx)
+L(aligned_16_25bytes):
+	movdqa	%xmm0, -25(%edx)
+L(aligned_16_9bytes):
+	movq	%xmm0, -9(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_122bytes):
+	movdqa	%xmm0, -122(%edx)
+L(aligned_16_106bytes):
+	movdqa	%xmm0, -106(%edx)
+L(aligned_16_90bytes):
+	movdqa	%xmm0, -90(%edx)
+L(aligned_16_74bytes):
+	movdqa	%xmm0, -74(%edx)
+L(aligned_16_58bytes):
+	movdqa	%xmm0, -58(%edx)
+L(aligned_16_42bytes):
+	movdqa	%xmm0, -42(%edx)
+L(aligned_16_26bytes):
+	movdqa	%xmm0, -26(%edx)
+L(aligned_16_10bytes):
+	movq	%xmm0, -10(%edx)
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_123bytes):
+	movdqa	%xmm0, -123(%edx)
+L(aligned_16_107bytes):
+	movdqa	%xmm0, -107(%edx)
+L(aligned_16_91bytes):
+	movdqa	%xmm0, -91(%edx)
+L(aligned_16_75bytes):
+	movdqa	%xmm0, -75(%edx)
+L(aligned_16_59bytes):
+	movdqa	%xmm0, -59(%edx)
+L(aligned_16_43bytes):
+	movdqa	%xmm0, -43(%edx)
+L(aligned_16_27bytes):
+	movdqa	%xmm0, -27(%edx)
+L(aligned_16_11bytes):
+	movq	%xmm0, -11(%edx)
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_124bytes):
+	movdqa	%xmm0, -124(%edx)
+L(aligned_16_108bytes):
+	movdqa	%xmm0, -108(%edx)
+L(aligned_16_92bytes):
+	movdqa	%xmm0, -92(%edx)
+L(aligned_16_76bytes):
+	movdqa	%xmm0, -76(%edx)
+L(aligned_16_60bytes):
+	movdqa	%xmm0, -60(%edx)
+L(aligned_16_44bytes):
+	movdqa	%xmm0, -44(%edx)
+L(aligned_16_28bytes):
+	movdqa	%xmm0, -28(%edx)
+L(aligned_16_12bytes):
+	movq	%xmm0, -12(%edx)
+	movl	%eax, -4(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_125bytes):
+	movdqa	%xmm0, -125(%edx)
+L(aligned_16_109bytes):
+	movdqa	%xmm0, -109(%edx)
+L(aligned_16_93bytes):
+	movdqa	%xmm0, -93(%edx)
+L(aligned_16_77bytes):
+	movdqa	%xmm0, -77(%edx)
+L(aligned_16_61bytes):
+	movdqa	%xmm0, -61(%edx)
+L(aligned_16_45bytes):
+	movdqa	%xmm0, -45(%edx)
+L(aligned_16_29bytes):
+	movdqa	%xmm0, -29(%edx)
+L(aligned_16_13bytes):
+	movq	%xmm0, -13(%edx)
+	movl	%eax, -5(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_126bytes):
+	movdqa	%xmm0, -126(%edx)
+L(aligned_16_110bytes):
+	movdqa	%xmm0, -110(%edx)
+L(aligned_16_94bytes):
+	movdqa	%xmm0, -94(%edx)
+L(aligned_16_78bytes):
+	movdqa	%xmm0, -78(%edx)
+L(aligned_16_62bytes):
+	movdqa	%xmm0, -62(%edx)
+L(aligned_16_46bytes):
+	movdqa	%xmm0, -46(%edx)
+L(aligned_16_30bytes):
+	movdqa	%xmm0, -30(%edx)
+L(aligned_16_14bytes):
+	movq	%xmm0, -14(%edx)
+	movl	%eax, -6(%edx)
+	movw	%ax, -2(%edx)
+	SETRTNVAL
+	RETURN
+
+	ALIGN (4)
+L(aligned_16_127bytes):
+	movdqa	%xmm0, -127(%edx)
+L(aligned_16_111bytes):
+	movdqa	%xmm0, -111(%edx)
+L(aligned_16_95bytes):
+	movdqa	%xmm0, -95(%edx)
+L(aligned_16_79bytes):
+	movdqa	%xmm0, -79(%edx)
+L(aligned_16_63bytes):
+	movdqa	%xmm0, -63(%edx)
+L(aligned_16_47bytes):
+	movdqa	%xmm0, -47(%edx)
+L(aligned_16_31bytes):
+	movdqa	%xmm0, -31(%edx)
+L(aligned_16_15bytes):
+	movq	%xmm0, -15(%edx)
+	movl	%eax, -7(%edx)
+	movw	%ax, -3(%edx)
+	movb	%al, -1(%edx)
+	SETRTNVAL
+	RETURN_END
+
+END (MEMSET)
diff --git a/libc/arch-x86/silvermont/string/sse2-stpcpy-slm.S b/libc/arch-x86/silvermont/string/sse2-stpcpy-slm.S
new file mode 100755
index 0000000..5c43fa5
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-stpcpy-slm.S
@@ -0,0 +1,33 @@
+/*

+Copyright (c) 2014, Intel Corporation

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+

+    * Redistributions of source code must retain the above copyright notice,

+    * this list of conditions and the following disclaimer.

+

+    * Redistributions in binary form must reproduce the above copyright notice,

+    * this list of conditions and the following disclaimer in the documentation

+    * and/or other materials provided with the distribution.

+

+    * Neither the name of Intel Corporation nor the names of its contributors

+    * may be used to endorse or promote products derived from this software

+    * without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+*/

+

+#define USE_AS_STPCPY

+#define STRCPY stpcpy

+#include "sse2-strcpy-slm.S"

diff --git a/libc/arch-x86/silvermont/string/sse2-stpncpy-slm.S b/libc/arch-x86/silvermont/string/sse2-stpncpy-slm.S
new file mode 100644
index 0000000..af5c0d3
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-stpncpy-slm.S
@@ -0,0 +1,34 @@
+/*

+Copyright (c) 2014, Intel Corporation

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+

+    * Redistributions of source code must retain the above copyright notice,

+    * this list of conditions and the following disclaimer.

+

+    * Redistributions in binary form must reproduce the above copyright notice,

+    * this list of conditions and the following disclaimer in the documentation

+    * and/or other materials provided with the distribution.

+

+    * Neither the name of Intel Corporation nor the names of its contributors

+    * may be used to endorse or promote products derived from this software

+    * without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+*/

+

+#define USE_AS_STRNCPY

+#define USE_AS_STPCPY

+#define STRCPY stpncpy

+#include "sse2-strcpy-slm.S"

diff --git a/libc/arch-x86/silvermont/string/sse2-strcpy-slm.S b/libc/arch-x86/silvermont/string/sse2-strcpy-slm.S
new file mode 100755
index 0000000..b5d84b5
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-strcpy-slm.S
@@ -0,0 +1,2157 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)             \
+	.type name, @function;   \
+	.globl name;             \
+	.p2align 4;              \
+name:                            \
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)               \
+	cfi_endproc;             \
+	.size name, .-name
+#endif
+
+#define CFI_PUSH(REG)                  \
+	cfi_adjust_cfa_offset (4);     \
+	cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)                   \
+	cfi_adjust_cfa_offset (-4);    \
+	cfi_restore (REG)
+
+#define PUSH(REG) pushl REG; CFI_PUSH (REG)
+#define POP(REG) popl REG; CFI_POP (REG)
+
+#ifndef STRCPY
+# define STRCPY  strcpy
+#endif
+
+#ifdef USE_AS_STPNCPY
+# define USE_AS_STRNCPY
+# define USE_AS_STPCPY
+#endif
+
+#ifdef USE_AS_STRNCPY
+# define PARMS  16
+# define ENTRANCE PUSH(%ebx); PUSH(%esi); PUSH(%edi)
+# define RETURN  POP(%edi); POP(%esi); POP(%ebx); ret; CFI_PUSH(%ebx); CFI_PUSH(%edi); CFI_PUSH(%edi);
+#else
+# define PARMS  12
+# define ENTRANCE PUSH(%esi); PUSH(%edi)
+# define RETURN  POP(%edi); POP(%esi); ret; CFI_PUSH(%esi); CFI_PUSH(%edi);
+#endif
+
+#define STR1  PARMS
+#define STR2  STR1+4
+#define LEN  STR2+4
+
+
+#if (defined SHARED || defined __PIC__)
+# define JMPTBL(I, B)	I - B
+
+/* Load an entry in a jump table into ECX and branch to it.  TABLE is a
+	jump	table with relative offsets.  INDEX is a register contains the
+	index	into the jump table.   SCALE is the scale of INDEX. */
+
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)            \
+	/* We first load PC into ECX.  */                       \
+	call	__x86.get_pc_thunk.cx;                         \
+	/* Get the address of the jump table.  */               \
+	addl	$(TABLE - .), %ecx;                             \
+	/* Get the entry and convert the relative offset to the \
+	absolute	address.  */                            \
+	addl	(%ecx,INDEX,SCALE), %ecx;                       \
+	/* We loaded the jump table and adjuested ECX. Go.  */  \
+	jmp	*%ecx
+#else
+# define JMPTBL(I, B)	I
+
+/* Branch to an entry in a jump table.  TABLE is a jump table with
+	absolute	offsets.  INDEX is a register contains the index into the
+	jump	table.  SCALE is the scale of INDEX. */
+
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)		\
+	jmp	*TABLE(,INDEX,SCALE)
+#endif
+
+.text
+ENTRY (STRCPY)
+	ENTRANCE
+	mov	STR1(%esp), %edi
+	mov	STR2(%esp), %esi
+#ifdef USE_AS_STRNCPY
+	movl	LEN(%esp), %ebx
+	test	%ebx, %ebx
+	jz	L(ExitZero)
+#endif
+
+	mov	%esi, %ecx
+#ifndef USE_AS_STPCPY
+	mov	%edi, %eax      /* save result */
+#endif
+	and	$15, %ecx
+	jz	L(SourceStringAlignmentZero)
+
+	and	$-16, %esi
+	pxor	%xmm0, %xmm0
+	pxor	%xmm1, %xmm1
+
+	pcmpeqb	(%esi), %xmm1
+#ifdef USE_AS_STRNCPY
+	add	%ecx, %ebx
+#endif
+	pmovmskb %xmm1, %edx
+	shr	%cl, %edx
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	cmp	$16, %ebx
+	jbe	L(CopyFrom1To16BytesTailCase2OrCase3)
+#else
+	cmp	$17, %ebx
+	jbe	L(CopyFrom1To16BytesTailCase2OrCase3)
+#endif
+#endif
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesTail)
+
+	pcmpeqb	16(%esi), %xmm0
+	pmovmskb %xmm0, %edx
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	cmp	$32, %ebx
+	jbe	L(CopyFrom1To32BytesCase2OrCase3)
+#else
+	cmp	$33, %ebx
+	jbe	L(CopyFrom1To32BytesCase2OrCase3)
+#endif
+#endif
+	test	%edx, %edx
+	jnz	L(CopyFrom1To32Bytes)
+
+	movdqu	(%esi, %ecx), %xmm1   /* copy 16 bytes */
+	movdqu	%xmm1, (%edi)
+
+	sub	%ecx, %edi
+	mov	%edi, %edx
+	mov	$16, %ecx
+	and	$15, %edx
+	jz	L(Align16Both)
+
+/* If source adress alignment != destination adress alignment */
+	.p2align 4
+L(Unalign16Both):
+	movdqa	(%esi, %ecx), %xmm1
+	movaps	16(%esi, %ecx), %xmm2
+	movdqu	%xmm1, (%edi, %ecx)
+	pcmpeqb	%xmm2, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$16, %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$48, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm2)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%esi, %ecx), %xmm3
+	movdqu	%xmm2, (%edi, %ecx)
+	pcmpeqb	%xmm3, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$16, %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm3)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%esi, %ecx), %xmm4
+	movdqu	%xmm3, (%edi, %ecx)
+	pcmpeqb	%xmm4, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$16, %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm4)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%esi, %ecx), %xmm1
+	movdqu	%xmm4, (%edi, %ecx)
+	pcmpeqb	%xmm1, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$16, %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm1)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%esi, %ecx), %xmm2
+	movdqu	%xmm1, (%edi, %ecx)
+	pcmpeqb	%xmm2, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$16, %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm2)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%esi, %ecx), %xmm3
+	movdqu	%xmm2, (%edi, %ecx)
+	pcmpeqb	%xmm3, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$16, %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm3)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movdqu	%xmm3, (%edi, %ecx)
+	mov	%esi, %edx
+	lea	16(%esi, %ecx), %esi
+	and	$-0x40, %esi
+	sub	%esi, %edx
+	sub	%edx, %edi
+#ifdef USE_AS_STRNCPY
+	lea	64+64(%ebx, %edx), %ebx
+#endif
+L(Unaligned64Loop):
+	movaps	(%esi), %xmm2
+	movaps	%xmm2, %xmm4
+	movaps	16(%esi), %xmm5
+	movaps	32(%esi), %xmm3
+	movaps	%xmm3, %xmm6
+	movaps	48(%esi), %xmm7
+	pminub	%xmm5, %xmm2
+	pminub	%xmm7, %xmm3
+	pminub	%xmm2, %xmm3
+	pcmpeqb	%xmm0, %xmm3
+	pmovmskb %xmm3, %edx
+#ifdef USE_AS_STRNCPY
+	sub	$64, %ebx
+	jbe	L(UnalignedLeaveCase2OrCase3)
+#endif
+	test	%edx, %edx
+	jnz	L(Unaligned64Leave)
+
+L(Unaligned64Loop_start):
+	add	$64, %edi
+	add	$64, %esi
+	movdqu	%xmm4, -64(%edi)
+	movaps	(%esi), %xmm2
+	movdqa	%xmm2, %xmm4
+	movdqu	%xmm5, -48(%edi)
+	movaps	16(%esi), %xmm5
+	pminub	%xmm5, %xmm2
+	movaps	32(%esi), %xmm3
+	movdqu	%xmm6, -32(%edi)
+	movaps	%xmm3, %xmm6
+	movdqu	%xmm7, -16(%edi)
+	movaps	48(%esi), %xmm7
+	pminub	%xmm7, %xmm3
+	pminub	%xmm2, %xmm3
+	pcmpeqb	%xmm3, %xmm0
+	pmovmskb %xmm0, %edx
+#ifdef USE_AS_STRNCPY
+	sub	$64, %ebx
+	jbe	L(UnalignedLeaveCase2OrCase3)
+#endif
+	test	%edx, %edx
+	jz	L(Unaligned64Loop_start)
+
+L(Unaligned64Leave):
+	pxor	%xmm0, %xmm0
+	pxor	%xmm1, %xmm1
+
+	pcmpeqb	%xmm4, %xmm0
+	pcmpeqb	%xmm5, %xmm1
+	pmovmskb %xmm0, %edx
+	pmovmskb %xmm1, %ecx
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnaligned_0)
+	test	%ecx, %ecx
+	jnz	L(CopyFrom1To16BytesUnaligned_16)
+
+	pcmpeqb	%xmm6, %xmm0
+	pcmpeqb	%xmm7, %xmm1
+	pmovmskb %xmm0, %edx
+	pmovmskb %xmm1, %ecx
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnaligned_32)
+
+	bsf	%ecx, %edx
+	movdqu	%xmm4, (%edi)
+	movdqu	%xmm5, 16(%edi)
+	movdqu	%xmm6, 32(%edi)
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	lea	48(%edi, %edx), %eax
+#endif
+	movdqu	%xmm7, 48(%edi)
+	add	$15, %ebx
+	sub	%edx, %ebx
+	lea	49(%edi, %edx), %edi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$48, %esi
+	add	$48, %edi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+
+/* If source adress alignment == destination adress alignment */
+
+L(SourceStringAlignmentZero):
+	pxor	%xmm0, %xmm0
+	movdqa	(%esi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pmovmskb %xmm0, %edx
+
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	cmp	$16, %ebx
+	jbe	L(CopyFrom1To16BytesTail1Case2OrCase3)
+#else
+	cmp	$17, %ebx
+	jbe	L(CopyFrom1To16BytesTail1Case2OrCase3)
+#endif
+#endif
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesTail1)
+
+	pcmpeqb	16(%esi), %xmm0
+	movdqu	%xmm1, (%edi)
+	pmovmskb %xmm0, %edx
+
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	cmp	$32, %ebx
+	jbe	L(CopyFrom1To32Bytes1Case2OrCase3)
+#else
+	cmp	$33, %ebx
+	jbe	L(CopyFrom1To32Bytes1Case2OrCase3)
+#endif
+#endif
+	test	%edx, %edx
+	jnz	L(CopyFrom1To32Bytes1)
+
+	mov	%edi, %edx
+	mov	$16, %ecx
+	and	$15, %edx
+	jnz	L(Unalign16Both)
+
+L(Align16Both):
+	movdqa	(%esi, %ecx), %xmm1
+	movdqa	16(%esi, %ecx), %xmm2
+	movdqa	%xmm1, (%edi, %ecx)
+	pcmpeqb	%xmm2, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$16, %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$48, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm2)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movdqa	16(%esi, %ecx), %xmm3
+	movdqa	%xmm2, (%edi, %ecx)
+	pcmpeqb	%xmm3, %xmm0
+	pmovmskb %xmm0, %edx
+	lea	16(%ecx), %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm3)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movdqa	16(%esi, %ecx), %xmm4
+	movdqa	%xmm3, (%edi, %ecx)
+	pcmpeqb	%xmm4, %xmm0
+	pmovmskb %xmm0, %edx
+	lea	16(%ecx), %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm4)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movdqa	16(%esi, %ecx), %xmm1
+	movdqa	%xmm4, (%edi, %ecx)
+	pcmpeqb	%xmm1, %xmm0
+	pmovmskb %xmm0, %edx
+	lea	16(%ecx), %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm1)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movdqa	16(%esi, %ecx), %xmm2
+	movdqa	%xmm1, (%edi, %ecx)
+	pcmpeqb	%xmm2, %xmm0
+	pmovmskb %xmm0, %edx
+	lea	16(%ecx), %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm2)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movdqa	16(%esi, %ecx), %xmm3
+	movdqa	%xmm2, (%edi, %ecx)
+	pcmpeqb	%xmm3, %xmm0
+	pmovmskb %xmm0, %edx
+	lea	16(%ecx), %ecx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm3)
+#else
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movdqa	%xmm3, (%edi, %ecx)
+	mov	%esi, %edx
+	lea	16(%esi, %ecx), %esi
+	and	$-0x40, %esi
+	sub	%esi, %edx
+	sub	%edx, %edi
+#ifdef USE_AS_STRNCPY
+	lea	64+64(%ebx, %edx), %ebx
+#endif
+L(Aligned64Loop):
+	movdqa	(%esi), %xmm2
+	movdqa	%xmm2, %xmm4
+	movaps	16(%esi), %xmm5
+	movdqa	32(%esi), %xmm3
+	movdqa	%xmm3, %xmm6
+	movaps	48(%esi), %xmm7
+	pminub	%xmm5, %xmm2
+	pminub	%xmm7, %xmm3
+	pminub	%xmm2, %xmm3
+	pcmpeqb	%xmm0, %xmm3
+	pmovmskb %xmm3, %edx
+#ifdef USE_AS_STRNCPY
+	sub	$64, %ebx
+	jbe	L(AlignedLeaveCase2OrCase3)
+#endif
+	test	%edx, %edx
+	jnz	L(Aligned64Leave)
+
+L(Aligned64Loop_start):
+	add	$64, %esi
+	add	$64, %edi
+	movaps	%xmm4, -64(%edi)
+	movdqa	(%esi), %xmm2
+	movdqa	%xmm2, %xmm4
+	movaps	%xmm5, -48(%edi)
+	movaps	16(%esi), %xmm5
+	pminub	%xmm5, %xmm2
+	movaps	32(%esi), %xmm3
+	movaps	%xmm6, -32(%edi)
+	movdqa	%xmm3, %xmm6
+	movaps	%xmm7, -16(%edi)
+	movaps	48(%esi), %xmm7
+	pminub	%xmm7, %xmm3
+	pminub	%xmm2, %xmm3
+	pcmpeqb	%xmm3, %xmm0
+	pmovmskb %xmm0, %edx
+#ifdef USE_AS_STRNCPY
+	sub	$64, %ebx
+	jbe	L(AlignedLeaveCase2OrCase3)
+#endif
+	test	%edx, %edx
+	jz	L(Aligned64Loop_start)
+
+L(Aligned64Leave):
+	pxor	%xmm0, %xmm0
+	pxor	%xmm1, %xmm1
+
+	pcmpeqb	%xmm4, %xmm0
+	pcmpeqb	%xmm5, %xmm1
+	pmovmskb %xmm0, %edx
+	pmovmskb %xmm1, %ecx
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes_0)
+	test	%ecx, %ecx
+	jnz	L(CopyFrom1To16Bytes_16)
+
+	pcmpeqb	%xmm6, %xmm0
+	pcmpeqb	%xmm7, %xmm1
+	pmovmskb %xmm0, %edx
+	pmovmskb %xmm1, %ecx
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16Bytes_32)
+
+	bsf	%ecx, %edx
+	movdqa	%xmm4, (%edi)
+	movdqa	%xmm5, 16(%edi)
+	movdqa	%xmm6, 32(%edi)
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	lea	48(%edi, %edx), %eax
+#endif
+	movdqa	%xmm7, 48(%edi)
+	add	$15, %ebx
+	sub	%edx, %ebx
+	lea	49(%edi, %edx), %edi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$48, %esi
+	add	$48, %edi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+
+/*----------------------------------------------------*/
+
+/* Case1 */
+#ifndef USE_AS_STRNCPY
+	.p2align 4
+L(CopyFrom1To16Bytes):
+	add	%ecx, %edi
+	add	%ecx, %esi
+	bsf	%edx, %edx
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+	.p2align 4
+L(CopyFrom1To16BytesTail):
+#ifdef USE_AS_STRNCPY
+	sub	%ecx, %ebx
+#endif
+	add	%ecx, %esi
+	bsf	%edx, %edx
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+
+	.p2align 4
+L(CopyFrom1To32Bytes1):
+	add	$16, %esi
+	add	$16, %edi
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+#endif
+L(CopyFrom1To16BytesTail1):
+	bsf	%edx, %edx
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+
+	.p2align 4
+L(CopyFrom1To32Bytes):
+#ifdef USE_AS_STRNCPY
+	sub	%ecx, %ebx
+#endif
+	bsf	%edx, %edx
+	add	%ecx, %esi
+	add	$16, %edx
+	sub	%ecx, %edx
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+
+	.p2align 4
+L(CopyFrom1To16Bytes_0):
+	bsf	%edx, %edx
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	lea	(%edi, %edx), %eax
+#endif
+	movdqa	%xmm4, (%edi)
+	add	$63, %ebx
+	sub	%edx, %ebx
+	lea	1(%edi, %edx), %edi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+
+	.p2align 4
+L(CopyFrom1To16Bytes_16):
+	bsf	%ecx, %edx
+	movdqa	%xmm4, (%edi)
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	lea	16(%edi, %edx), %eax
+#endif
+	movdqa	%xmm5, 16(%edi)
+	add	$47, %ebx
+	sub	%edx, %ebx
+	lea	17(%edi, %edx), %edi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$16, %esi
+	add	$16, %edi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+
+	.p2align 4
+L(CopyFrom1To16Bytes_32):
+	bsf	%edx, %edx
+	movdqa	%xmm4, (%edi)
+	movdqa	%xmm5, 16(%edi)
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	lea	32(%edi, %edx), %eax
+#endif
+	movdqa	%xmm6, 32(%edi)
+	add	$31, %ebx
+	sub	%edx, %ebx
+	lea	33(%edi, %edx), %edi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$32, %esi
+	add	$32, %edi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+
+	.p2align 4
+L(CopyFrom1To16BytesUnaligned_0):
+	bsf	%edx, %edx
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	lea	(%edi, %edx), %eax
+#endif
+	movdqu	%xmm4, (%edi)
+	add	$63, %ebx
+	sub	%edx, %ebx
+	lea	1(%edi, %edx), %edi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+
+	.p2align 4
+L(CopyFrom1To16BytesUnaligned_16):
+	bsf	%ecx, %edx
+	movdqu	%xmm4, (%edi)
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	lea	16(%edi, %edx), %eax
+#endif
+	movdqu	%xmm5, 16(%edi)
+	add	$47, %ebx
+	sub	%edx, %ebx
+	lea	17(%edi, %edx), %edi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$16, %esi
+	add	$16, %edi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+
+	.p2align 4
+L(CopyFrom1To16BytesUnaligned_32):
+	bsf	%edx, %edx
+	movdqu	%xmm4, (%edi)
+	movdqu	%xmm5, 16(%edi)
+#ifdef USE_AS_STRNCPY
+#ifdef USE_AS_STPCPY
+	lea	32(%edi, %edx), %eax
+#endif
+	movdqu	%xmm6, 32(%edi)
+	add	$31, %ebx
+	sub	%edx, %ebx
+	lea	33(%edi, %edx), %edi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$32, %esi
+	add	$32, %edi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+#endif
+
+#ifdef USE_AS_STRNCPY
+	.p2align 4
+L(CopyFrom1To16BytesXmm6):
+	movdqa	%xmm6, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesXmm5):
+	movdqa	%xmm5, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesXmm4):
+	movdqa	%xmm4, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesXmm3):
+	movdqa	%xmm3, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesXmm2):
+	movdqa	%xmm2, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesXmm1):
+	movdqa	%xmm1, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm6):
+	movdqu	%xmm6, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm5):
+	movdqu	%xmm5, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm4):
+	movdqu	%xmm4, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm3):
+	movdqu	%xmm3, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm1):
+	movdqu	%xmm1, (%edi, %ecx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesExit):
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %edx, 4)
+
+/* Case2 */
+
+	.p2align 4
+L(CopyFrom1To16BytesCase2):
+	add	$16, %ebx
+	add	%ecx, %edi
+	add	%ecx, %esi
+	bsf	%edx, %edx
+	cmp	%ebx, %edx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+	.p2align 4
+L(CopyFrom1To32BytesCase2):
+	sub	%ecx, %ebx
+	add	%ecx, %esi
+	bsf	%edx, %edx
+	add	$16, %edx
+	sub	%ecx, %edx
+	cmp	%ebx, %edx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+L(CopyFrom1To16BytesTailCase2):
+	sub	%ecx, %ebx
+	add	%ecx, %esi
+	bsf	%edx, %edx
+	cmp	%ebx, %edx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+L(CopyFrom1To16BytesTail1Case2):
+	bsf	%edx, %edx
+	cmp	%ebx, %edx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+/* Case2 or Case3,  Case3 */
+
+	.p2align 4
+L(CopyFrom1To16BytesCase2OrCase3):
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesCase2)
+L(CopyFrom1To16BytesCase3):
+	add	$16, %ebx
+	add	%ecx, %edi
+	add	%ecx, %esi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+	.p2align 4
+L(CopyFrom1To32BytesCase2OrCase3):
+	test	%edx, %edx
+	jnz	L(CopyFrom1To32BytesCase2)
+	sub	%ecx, %ebx
+	add	%ecx, %esi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+	.p2align 4
+L(CopyFrom1To16BytesTailCase2OrCase3):
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesTailCase2)
+	sub	%ecx, %ebx
+	add	%ecx, %esi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+	.p2align 4
+L(CopyFrom1To32Bytes1Case2OrCase3):
+	add	$16, %edi
+	add	$16, %esi
+	sub	$16, %ebx
+L(CopyFrom1To16BytesTail1Case2OrCase3):
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesTail1Case2)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+#endif
+
+/*-----------------------------------------------------------------*/
+	.p2align 4
+L(Exit0):
+#ifdef USE_AS_STPCPY
+	mov	%edi, %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit1):
+	movb	%dh, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$1, %ebx
+	lea	1(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit2):
+	movw	(%esi), %dx
+	movw	%dx, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	1(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$2, %ebx
+	lea	2(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit3):
+	movw	(%esi), %cx
+	movw	%cx, (%edi)
+	movb	%dh, 2(%edi)
+#ifdef USE_AS_STPCPY
+	lea	2(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$3, %ebx
+	lea	3(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit4):
+	movl	(%esi), %edx
+	movl	%edx, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	3(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$4, %ebx
+	lea	4(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit5):
+	movl	(%esi), %ecx
+	movb	%dh, 4(%edi)
+	movl	%ecx, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	4(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$5, %ebx
+	lea	5(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit6):
+	movl	(%esi), %ecx
+	movw	4(%esi), %dx
+	movl	%ecx, (%edi)
+	movw	%dx, 4(%edi)
+#ifdef USE_AS_STPCPY
+	lea	5(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$6, %ebx
+	lea	6(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit7):
+	movl	(%esi), %ecx
+	movl	3(%esi), %edx
+	movl	%ecx, (%edi)
+	movl	%edx, 3(%edi)
+#ifdef USE_AS_STPCPY
+	lea	6(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$7, %ebx
+	lea	7(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit8):
+	movlpd	(%esi), %xmm0
+	movlpd	%xmm0, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	7(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$8, %ebx
+	lea	8(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit9):
+	movlpd	(%esi), %xmm0
+	movb	%dh, 8(%edi)
+	movlpd	%xmm0, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	8(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$9, %ebx
+	lea	9(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit10):
+	movlpd	(%esi), %xmm0
+	movw	8(%esi), %dx
+	movlpd	%xmm0, (%edi)
+	movw	%dx, 8(%edi)
+#ifdef USE_AS_STPCPY
+	lea	9(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$10, %ebx
+	lea	10(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit11):
+	movlpd	(%esi), %xmm0
+	movl	7(%esi), %edx
+	movlpd	%xmm0, (%edi)
+	movl	%edx, 7(%edi)
+#ifdef USE_AS_STPCPY
+	lea	10(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$11, %ebx
+	lea	11(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit12):
+	movlpd	(%esi), %xmm0
+	movl	8(%esi), %edx
+	movlpd	%xmm0, (%edi)
+	movl	%edx, 8(%edi)
+#ifdef USE_AS_STPCPY
+	lea	11(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$12, %ebx
+	lea	12(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit13):
+	movlpd	(%esi), %xmm0
+	movlpd	5(%esi), %xmm1
+	movlpd	%xmm0, (%edi)
+	movlpd	%xmm1, 5(%edi)
+#ifdef USE_AS_STPCPY
+	lea	12(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$13, %ebx
+	lea	13(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit14):
+	movlpd	(%esi), %xmm0
+	movlpd	6(%esi), %xmm1
+	movlpd	%xmm0, (%edi)
+	movlpd	%xmm1, 6(%edi)
+#ifdef USE_AS_STPCPY
+	lea	13(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$14, %ebx
+	lea	14(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit15):
+	movlpd	(%esi), %xmm0
+	movlpd	7(%esi), %xmm1
+	movlpd	%xmm0, (%edi)
+	movlpd	%xmm1, 7(%edi)
+#ifdef USE_AS_STPCPY
+	lea	14(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$15, %ebx
+	lea	15(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit16):
+	movdqu	(%esi), %xmm0
+	movdqu	%xmm0, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	15(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$16, %ebx
+	lea	16(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit17):
+	movdqu	(%esi), %xmm0
+	xor	%cl, %cl
+	movdqu	%xmm0, (%edi)
+	movb	%cl, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	16(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$17, %ebx
+	lea	17(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit18):
+	movdqu	(%esi), %xmm0
+	movw	16(%esi), %cx
+	movdqu	%xmm0, (%edi)
+	movw	%cx, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	17(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$18, %ebx
+	lea	18(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit19):
+	movdqu	(%esi), %xmm0
+	movl	15(%esi), %ecx
+	movdqu	%xmm0, (%edi)
+	movl	%ecx, 15(%edi)
+#ifdef USE_AS_STPCPY
+	lea	18(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$19, %ebx
+	lea	19(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit20):
+	movdqu	(%esi), %xmm0
+	movl	16(%esi), %ecx
+	movdqu	%xmm0, (%edi)
+	movl	%ecx, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	19(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$20, %ebx
+	lea	20(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit21):
+	movdqu	(%esi), %xmm0
+	movl	16(%esi), %ecx
+	xor	%dl, %dl
+	movdqu	%xmm0, (%edi)
+	movl	%ecx, 16(%edi)
+	movb	%dl, 20(%edi)
+#ifdef USE_AS_STPCPY
+	lea	20(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$21, %ebx
+	lea	21(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit22):
+	movdqu	(%esi), %xmm0
+	movlpd	14(%esi), %xmm3
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm3, 14(%edi)
+#ifdef USE_AS_STPCPY
+	lea	21(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$22, %ebx
+	lea	22(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit23):
+	movdqu	(%esi), %xmm0
+	movlpd	15(%esi), %xmm3
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm3, 15(%edi)
+#ifdef USE_AS_STPCPY
+	lea	22(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$23, %ebx
+	lea	23(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit24):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	23(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$24, %ebx
+	lea	24(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit25):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	xor	%cl, %cl
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+	movb	%cl, 24(%edi)
+#ifdef USE_AS_STPCPY
+	lea	24(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$25, %ebx
+	lea	25(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit26):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movw	24(%esi), %cx
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+	movw	%cx, 24(%edi)
+#ifdef USE_AS_STPCPY
+	lea	25(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$26, %ebx
+	lea	26(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit27):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movl	23(%esi), %ecx
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+	movl	%ecx, 23(%edi)
+#ifdef USE_AS_STPCPY
+	lea	26(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$27, %ebx
+	lea	27(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit28):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movl	24(%esi), %ecx
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+	movl	%ecx, 24(%edi)
+#ifdef USE_AS_STPCPY
+	lea	27(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$28, %ebx
+	lea	28(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit29):
+	movdqu	(%esi), %xmm0
+	movdqu	13(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 13(%edi)
+#ifdef USE_AS_STPCPY
+	lea	28(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$29, %ebx
+	lea	29(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit30):
+	movdqu	(%esi), %xmm0
+	movdqu	14(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 14(%edi)
+#ifdef USE_AS_STPCPY
+	lea	29(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$30, %ebx
+	lea	30(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+
+	.p2align 4
+L(Exit31):
+	movdqu	(%esi), %xmm0
+	movdqu	15(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 15(%edi)
+#ifdef USE_AS_STPCPY
+	lea	30(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$31, %ebx
+	lea	31(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit32):
+	movdqu	(%esi), %xmm0
+	movdqu	16(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	31(%edi), %eax
+#endif
+#ifdef USE_AS_STRNCPY
+	sub	$32, %ebx
+	lea	32(%edi), %edi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+#ifdef USE_AS_STRNCPY
+
+	.p2align 4
+L(StrncpyExit1):
+	movb	(%esi), %dl
+	movb	%dl, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	1(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit2):
+	movw	(%esi), %dx
+	movw	%dx, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	2(%edi), %eax
+#endif
+	RETURN
+	.p2align 4
+L(StrncpyExit3):
+	movw	(%esi), %cx
+	movb	2(%esi), %dl
+	movw	%cx, (%edi)
+	movb	%dl, 2(%edi)
+#ifdef USE_AS_STPCPY
+	lea	3(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit4):
+	movl	(%esi), %edx
+	movl	%edx, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	4(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit5):
+	movl	(%esi), %ecx
+	movb	4(%esi), %dl
+	movl	%ecx, (%edi)
+	movb	%dl, 4(%edi)
+#ifdef USE_AS_STPCPY
+	lea	5(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit6):
+	movl	(%esi), %ecx
+	movw	4(%esi), %dx
+	movl	%ecx, (%edi)
+	movw	%dx, 4(%edi)
+#ifdef USE_AS_STPCPY
+	lea	6(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit7):
+	movl	(%esi), %ecx
+	movl	3(%esi), %edx
+	movl	%ecx, (%edi)
+	movl	%edx, 3(%edi)
+#ifdef USE_AS_STPCPY
+	lea	7(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit8):
+	movlpd	(%esi), %xmm0
+	movlpd	%xmm0, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	8(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit9):
+	movlpd	(%esi), %xmm0
+	movb	8(%esi), %dl
+	movlpd	%xmm0, (%edi)
+	movb	%dl, 8(%edi)
+#ifdef USE_AS_STPCPY
+	lea	9(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit10):
+	movlpd	(%esi), %xmm0
+	movw	8(%esi), %dx
+	movlpd	%xmm0, (%edi)
+	movw	%dx, 8(%edi)
+#ifdef USE_AS_STPCPY
+	lea	10(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit11):
+	movlpd	(%esi), %xmm0
+	movl	7(%esi), %edx
+	movlpd	%xmm0, (%edi)
+	movl	%edx, 7(%edi)
+#ifdef USE_AS_STPCPY
+	lea	11(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit12):
+	movlpd	(%esi), %xmm0
+	movl	8(%esi), %edx
+	movlpd	%xmm0, (%edi)
+	movl	%edx, 8(%edi)
+#ifdef USE_AS_STPCPY
+	lea	12(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit13):
+	movlpd	(%esi), %xmm0
+	movlpd	5(%esi), %xmm1
+	movlpd	%xmm0, (%edi)
+	movlpd	%xmm1, 5(%edi)
+#ifdef USE_AS_STPCPY
+	lea	13(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit14):
+	movlpd	(%esi), %xmm0
+	movlpd	6(%esi), %xmm1
+	movlpd	%xmm0, (%edi)
+	movlpd	%xmm1, 6(%edi)
+#ifdef USE_AS_STPCPY
+	lea	14(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit15):
+	movlpd	(%esi), %xmm0
+	movlpd	7(%esi), %xmm1
+	movlpd	%xmm0, (%edi)
+	movlpd	%xmm1, 7(%edi)
+#ifdef USE_AS_STPCPY
+	lea	15(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit16):
+	movdqu	(%esi), %xmm0
+	movdqu	%xmm0, (%edi)
+#ifdef USE_AS_STPCPY
+	lea	16(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit17):
+	movdqu	(%esi), %xmm0
+	movb	16(%esi), %cl
+	movdqu	%xmm0, (%edi)
+	movb	%cl, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	17(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit18):
+	movdqu	(%esi), %xmm0
+	movw	16(%esi), %cx
+	movdqu	%xmm0, (%edi)
+	movw	%cx, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	18(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit19):
+	movdqu	(%esi), %xmm0
+	movl	15(%esi), %ecx
+	movdqu	%xmm0, (%edi)
+	movl	%ecx, 15(%edi)
+#ifdef USE_AS_STPCPY
+	lea	19(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit20):
+	movdqu	(%esi), %xmm0
+	movl	16(%esi), %ecx
+	movdqu	%xmm0, (%edi)
+	movl	%ecx, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	20(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit21):
+	movdqu	(%esi), %xmm0
+	movl	16(%esi), %ecx
+	movb	20(%esi), %dl
+	movdqu	%xmm0, (%edi)
+	movl	%ecx, 16(%edi)
+	movb	%dl, 20(%edi)
+#ifdef USE_AS_STPCPY
+	lea	21(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit22):
+	movdqu	(%esi), %xmm0
+	movlpd	14(%esi), %xmm3
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm3, 14(%edi)
+#ifdef USE_AS_STPCPY
+	lea	22(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit23):
+	movdqu	(%esi), %xmm0
+	movlpd	15(%esi), %xmm3
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm3, 15(%edi)
+#ifdef USE_AS_STPCPY
+	lea	23(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit24):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	24(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit25):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movb	24(%esi), %cl
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+	movb	%cl, 24(%edi)
+#ifdef USE_AS_STPCPY
+	lea	25(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit26):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movw	24(%esi), %cx
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+	movw	%cx, 24(%edi)
+#ifdef USE_AS_STPCPY
+	lea	26(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit27):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movl	23(%esi), %ecx
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+	movl	%ecx, 23(%edi)
+#ifdef USE_AS_STPCPY
+	lea	27(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit28):
+	movdqu	(%esi), %xmm0
+	movlpd	16(%esi), %xmm2
+	movl	24(%esi), %ecx
+	movdqu	%xmm0, (%edi)
+	movlpd	%xmm2, 16(%edi)
+	movl	%ecx, 24(%edi)
+#ifdef USE_AS_STPCPY
+	lea	28(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit29):
+	movdqu	(%esi), %xmm0
+	movdqu	13(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 13(%edi)
+#ifdef USE_AS_STPCPY
+	lea	29(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit30):
+	movdqu	(%esi), %xmm0
+	movdqu	14(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 14(%edi)
+#ifdef USE_AS_STPCPY
+	lea	30(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit31):
+	movdqu	(%esi), %xmm0
+	movdqu	15(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 15(%edi)
+#ifdef USE_AS_STPCPY
+	lea	31(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit32):
+	movdqu	(%esi), %xmm0
+	movdqu	16(%esi), %xmm2
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 16(%edi)
+#ifdef USE_AS_STPCPY
+	lea	32(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit33):
+	movdqu	(%esi), %xmm0
+	movdqu	16(%esi), %xmm2
+	movb	32(%esi), %cl
+	movdqu	%xmm0, (%edi)
+	movdqu	%xmm2, 16(%edi)
+	movb	%cl, 32(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill0):
+	RETURN
+
+	.p2align 4
+L(Fill1):
+	movb	%dl, (%edi)
+	RETURN
+
+	.p2align 4
+L(Fill2):
+	movw	%dx, (%edi)
+	RETURN
+
+	.p2align 4
+L(Fill3):
+	movl	%edx, -1(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill4):
+	movl	%edx, (%edi)
+	RETURN
+
+	.p2align 4
+L(Fill5):
+	movl	%edx, (%edi)
+	movb	%dl, 4(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill6):
+	movl	%edx, (%edi)
+	movw	%dx, 4(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill7):
+	movlpd	%xmm0, -1(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill8):
+	movlpd	%xmm0, (%edi)
+	RETURN
+
+	.p2align 4
+L(Fill9):
+	movlpd	%xmm0, (%edi)
+	movb	%dl, 8(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill10):
+	movlpd	%xmm0, (%edi)
+	movw	%dx, 8(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill11):
+	movlpd	%xmm0, (%edi)
+	movl	%edx, 7(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill12):
+	movlpd	%xmm0, (%edi)
+	movl	%edx, 8(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill13):
+	movlpd	%xmm0, (%edi)
+	movlpd	%xmm0, 5(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill14):
+	movlpd	%xmm0, (%edi)
+	movlpd	%xmm0, 6(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill15):
+	movdqu	%xmm0, -1(%edi)
+	RETURN
+
+	.p2align 4
+L(Fill16):
+	movdqu	%xmm0, (%edi)
+	RETURN
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm2):
+	movdqu	%xmm2, (%edi, %ecx)
+
+	.p2align 4
+L(CopyFrom1To16BytesXmmExit):
+	bsf	%edx, %edx
+	add	$15, %ebx
+	add	%ecx, %edi
+#ifdef USE_AS_STPCPY
+	lea	(%edi, %edx), %eax
+#endif
+	sub	%edx, %ebx
+	lea	1(%edi, %edx), %edi
+
+	.p2align 4
+L(StrncpyFillTailWithZero):
+	pxor	%xmm0, %xmm0
+	xor	%edx, %edx
+	sub	$16, %ebx
+	jbe	L(StrncpyFillExit)
+
+	movdqu	%xmm0, (%edi)
+	add	$16, %edi
+
+	mov	%edi, %esi
+	and	$0xf, %esi
+	sub	%esi, %edi
+	add	%esi, %ebx
+	sub	$64, %ebx
+	jb	L(StrncpyFillLess64)
+
+L(StrncpyFillLoopMovdqa):
+	movdqa	%xmm0, (%edi)
+	movdqa	%xmm0, 16(%edi)
+	movdqa	%xmm0, 32(%edi)
+	movdqa	%xmm0, 48(%edi)
+	add	$64, %edi
+	sub	$64, %ebx
+	jae	L(StrncpyFillLoopMovdqa)
+
+L(StrncpyFillLess64):
+	add	$32, %ebx
+	jl	L(StrncpyFillLess32)
+	movdqa	%xmm0, (%edi)
+	movdqa	%xmm0, 16(%edi)
+	add	$32, %edi
+	sub	$16, %ebx
+	jl	L(StrncpyFillExit)
+	movdqa	%xmm0, (%edi)
+	add	$16, %edi
+	BRANCH_TO_JMPTBL_ENTRY (L(FillTable), %ebx, 4)
+
+L(StrncpyFillLess32):
+	add	$16, %ebx
+	jl	L(StrncpyFillExit)
+	movdqa	%xmm0, (%edi)
+	add	$16, %edi
+	BRANCH_TO_JMPTBL_ENTRY (L(FillTable), %ebx, 4)
+
+L(StrncpyFillExit):
+	add	$16, %ebx
+	BRANCH_TO_JMPTBL_ENTRY (L(FillTable), %ebx, 4)
+
+	.p2align 4
+L(AlignedLeaveCase2OrCase3):
+	test	%edx, %edx
+	jnz	L(Aligned64LeaveCase2)
+L(Aligned64LeaveCase3):
+	lea	64(%ebx), %ecx
+	and	$-16, %ecx
+	add	$48, %ebx
+	jl	L(CopyFrom1To16BytesCase3)
+	movdqa	%xmm4, (%edi)
+	sub	$16, %ebx
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqa	%xmm5, 16(%edi)
+	sub	$16, %ebx
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqa	%xmm6, 32(%edi)
+	sub	$16, %ebx
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqa	%xmm7, 48(%edi)
+#ifdef USE_AS_STPCPY
+	lea	64(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(Aligned64LeaveCase2):
+	pxor	%xmm0, %xmm0
+	xor	%ecx, %ecx
+	pcmpeqb	%xmm4, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$48, %ebx
+	jle	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm4)
+
+	pcmpeqb	%xmm5, %xmm0
+	pmovmskb %xmm0, %edx
+	movdqa	%xmm4, (%edi)
+	add	$16, %ecx
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm5)
+
+	pcmpeqb	%xmm6, %xmm0
+	pmovmskb %xmm0, %edx
+	movdqa	%xmm5, 16(%edi)
+	add	$16, %ecx
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesXmm6)
+
+	pcmpeqb	%xmm7, %xmm0
+	pmovmskb %xmm0, %edx
+	movdqa	%xmm6, 32(%edi)
+	lea	16(%edi, %ecx), %edi
+	lea	16(%esi, %ecx), %esi
+	bsf	%edx, %edx
+	cmp	%ebx, %edx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+	.p2align 4
+L(UnalignedLeaveCase2OrCase3):
+	test	%edx, %edx
+	jnz	L(Unaligned64LeaveCase2)
+L(Unaligned64LeaveCase3):
+	lea	64(%ebx), %ecx
+	and	$-16, %ecx
+	add	$48, %ebx
+	jl	L(CopyFrom1To16BytesCase3)
+	movdqu	%xmm4, (%edi)
+	sub	$16, %ebx
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqu	%xmm5, 16(%edi)
+	sub	$16, %ebx
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqu	%xmm6, 32(%edi)
+	sub	$16, %ebx
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqu	%xmm7, 48(%edi)
+#ifdef USE_AS_STPCPY
+	lea	64(%edi), %eax
+#endif
+	RETURN
+
+	.p2align 4
+L(Unaligned64LeaveCase2):
+	pxor	%xmm0, %xmm0
+	xor	%ecx, %ecx
+	pcmpeqb	%xmm4, %xmm0
+	pmovmskb %xmm0, %edx
+	add	$48, %ebx
+	jle	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm4)
+
+	pcmpeqb	%xmm5, %xmm0
+	pmovmskb %xmm0, %edx
+	movdqu	%xmm4, (%edi)
+	add	$16, %ecx
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm5)
+
+	pcmpeqb	%xmm6, %xmm0
+	pmovmskb %xmm0, %edx
+	movdqu	%xmm5, 16(%edi)
+	add	$16, %ecx
+	sub	$16, %ebx
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%edx, %edx
+	jnz	L(CopyFrom1To16BytesUnalignedXmm6)
+
+	pcmpeqb	%xmm7, %xmm0
+	pmovmskb %xmm0, %edx
+	movdqu	%xmm6, 32(%edi)
+	lea	16(%edi, %ecx), %edi
+	lea	16(%esi, %ecx), %esi
+	bsf	%edx, %edx
+	cmp	%ebx, %edx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %ebx, 4)
+
+	.p2align 4
+L(ExitZero):
+	movl	%edi, %eax
+	RETURN
+#endif
+
+END (STRCPY)
+
+	.p2align 4
+	.section .rodata
+L(ExitTable):
+	.int	JMPTBL(L(Exit1), L(ExitTable))
+	.int	JMPTBL(L(Exit2), L(ExitTable))
+	.int	JMPTBL(L(Exit3), L(ExitTable))
+	.int	JMPTBL(L(Exit4), L(ExitTable))
+	.int	JMPTBL(L(Exit5), L(ExitTable))
+	.int	JMPTBL(L(Exit6), L(ExitTable))
+	.int	JMPTBL(L(Exit7), L(ExitTable))
+	.int	JMPTBL(L(Exit8), L(ExitTable))
+	.int	JMPTBL(L(Exit9), L(ExitTable))
+	.int	JMPTBL(L(Exit10), L(ExitTable))
+	.int	JMPTBL(L(Exit11), L(ExitTable))
+	.int	JMPTBL(L(Exit12), L(ExitTable))
+	.int	JMPTBL(L(Exit13), L(ExitTable))
+	.int	JMPTBL(L(Exit14), L(ExitTable))
+	.int	JMPTBL(L(Exit15), L(ExitTable))
+	.int	JMPTBL(L(Exit16), L(ExitTable))
+	.int	JMPTBL(L(Exit17), L(ExitTable))
+	.int	JMPTBL(L(Exit18), L(ExitTable))
+	.int	JMPTBL(L(Exit19), L(ExitTable))
+	.int	JMPTBL(L(Exit20), L(ExitTable))
+	.int	JMPTBL(L(Exit21), L(ExitTable))
+	.int	JMPTBL(L(Exit22), L(ExitTable))
+	.int    JMPTBL(L(Exit23), L(ExitTable))
+	.int	JMPTBL(L(Exit24), L(ExitTable))
+	.int	JMPTBL(L(Exit25), L(ExitTable))
+	.int	JMPTBL(L(Exit26), L(ExitTable))
+	.int	JMPTBL(L(Exit27), L(ExitTable))
+	.int	JMPTBL(L(Exit28), L(ExitTable))
+	.int	JMPTBL(L(Exit29), L(ExitTable))
+	.int	JMPTBL(L(Exit30), L(ExitTable))
+	.int	JMPTBL(L(Exit31), L(ExitTable))
+	.int	JMPTBL(L(Exit32), L(ExitTable))
+#ifdef USE_AS_STRNCPY
+L(ExitStrncpyTable):
+	.int	JMPTBL(L(Exit0), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit1), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit2), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit3), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit4), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit5), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit6), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit7), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit8), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit9), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit10), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit11), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit12), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit13), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit14), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit15), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit16), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit17), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit18), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit19), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit20), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit21), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit22), L(ExitStrncpyTable))
+	.int    JMPTBL(L(StrncpyExit23), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit24), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit25), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit26), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit27), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit28), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit29), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit30), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit31), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit32), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit33), L(ExitStrncpyTable))
+
+	.p2align 4
+L(FillTable):
+	.int	JMPTBL(L(Fill0), L(FillTable))
+	.int	JMPTBL(L(Fill1), L(FillTable))
+	.int	JMPTBL(L(Fill2), L(FillTable))
+	.int	JMPTBL(L(Fill3), L(FillTable))
+	.int	JMPTBL(L(Fill4), L(FillTable))
+	.int	JMPTBL(L(Fill5), L(FillTable))
+	.int	JMPTBL(L(Fill6), L(FillTable))
+	.int	JMPTBL(L(Fill7), L(FillTable))
+	.int	JMPTBL(L(Fill8), L(FillTable))
+	.int	JMPTBL(L(Fill9), L(FillTable))
+	.int	JMPTBL(L(Fill10), L(FillTable))
+	.int	JMPTBL(L(Fill11), L(FillTable))
+	.int	JMPTBL(L(Fill12), L(FillTable))
+	.int	JMPTBL(L(Fill13), L(FillTable))
+	.int	JMPTBL(L(Fill14), L(FillTable))
+	.int	JMPTBL(L(Fill15), L(FillTable))
+	.int	JMPTBL(L(Fill16), L(FillTable))
+#endif
diff --git a/libc/arch-x86/silvermont/string/sse2-strlen-slm.S b/libc/arch-x86/silvermont/string/sse2-strlen-slm.S
new file mode 100755
index 0000000..27cc025
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-strlen-slm.S
@@ -0,0 +1,328 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef STRLEN
+# define STRLEN strlen
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)             \
+	.type name,  @function;  \
+	.globl name;             \
+	.p2align 4;              \
+name:                            \
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)               \
+	cfi_endproc;             \
+	.size name,	.-name
+#endif
+
+#define CFI_PUSH(REG)                   \
+	cfi_adjust_cfa_offset (4);      \
+	cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)                    \
+	cfi_adjust_cfa_offset (-4);     \
+	cfi_restore (REG)
+
+#define PUSH(REG) pushl REG; CFI_PUSH (REG)
+#define POP(REG) popl REG; CFI_POP (REG)
+
+	.section .text.sse2,"ax",@progbits
+ENTRY (STRLEN)
+	mov	4(%esp), %edx
+	mov	%edx, %ecx
+	and	$0x3f, %ecx
+	pxor	%xmm0, %xmm0
+	cmp	$0x30, %ecx
+	ja	L(next)
+	movdqu	(%edx), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pmovmskb %xmm0, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit_less16)
+	mov	%edx, %eax
+	and	$-16, %eax
+	jmp	L(align16_start)
+L(next):
+	mov	%edx, %eax
+	and	$-16, %eax
+	PUSH	(%edi)
+	pcmpeqb	(%eax), %xmm0
+	mov	$-1, %edi
+	sub	%eax, %ecx
+	shl	%cl, %edi
+	pmovmskb %xmm0, %ecx
+	and	%edi, %ecx
+	POP	(%edi)
+	jnz	L(exit_unaligned)
+	pxor	%xmm0, %xmm0
+L(align16_start):
+	pxor	%xmm1, %xmm1
+	pxor	%xmm2, %xmm2
+	pxor	%xmm3, %xmm3
+	pcmpeqb	16(%eax), %xmm0
+	pmovmskb %xmm0, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%eax), %xmm1
+	pmovmskb %xmm1, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%eax), %xmm2
+	pmovmskb %xmm2, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%eax), %xmm3
+	pmovmskb %xmm3, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit64)
+
+	pcmpeqb	80(%eax), %xmm0
+	add	$64, %eax
+	pmovmskb %xmm0, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%eax), %xmm1
+	pmovmskb %xmm1, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%eax), %xmm2
+	pmovmskb %xmm2, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%eax), %xmm3
+	pmovmskb %xmm3, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit64)
+
+	pcmpeqb	80(%eax), %xmm0
+	add	$64, %eax
+	pmovmskb %xmm0, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%eax), %xmm1
+	pmovmskb %xmm1, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%eax), %xmm2
+	pmovmskb %xmm2, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%eax), %xmm3
+	pmovmskb %xmm3, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit64)
+
+	pcmpeqb	80(%eax), %xmm0
+	add	$64, %eax
+	pmovmskb %xmm0, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%eax), %xmm1
+	pmovmskb %xmm1, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%eax), %xmm2
+	pmovmskb %xmm2, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%eax), %xmm3
+	pmovmskb %xmm3, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit64)
+
+
+	test	$0x3f, %eax
+	jz	L(align64_loop)
+
+	pcmpeqb	80(%eax), %xmm0
+	add	$80, %eax
+	pmovmskb %xmm0, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit)
+
+	test	$0x3f, %eax
+	jz	L(align64_loop)
+
+	pcmpeqb	16(%eax), %xmm1
+	add	$16, %eax
+	pmovmskb %xmm1, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit)
+
+	test	$0x3f, %eax
+	jz	L(align64_loop)
+
+	pcmpeqb	16(%eax), %xmm2
+	add	$16, %eax
+	pmovmskb %xmm2, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit)
+
+	test	$0x3f, %eax
+	jz	L(align64_loop)
+
+	pcmpeqb	16(%eax), %xmm3
+	add	$16, %eax
+	pmovmskb %xmm3, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit)
+
+	add	$16, %eax
+	.p2align 4
+L(align64_loop):
+	movaps	(%eax),	%xmm4
+	pminub	16(%eax), 	%xmm4
+	movaps	32(%eax), 	%xmm5
+	pminub	48(%eax), 	%xmm5
+	add	$64, 	%eax
+	pminub	%xmm4,	%xmm5
+	pcmpeqb	%xmm0,	%xmm5
+	pmovmskb %xmm5,	%ecx
+	test	%ecx,	%ecx
+	jz	L(align64_loop)
+
+
+	pcmpeqb	-64(%eax), %xmm0
+	sub	$80, 	%eax
+	pmovmskb %xmm0, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%eax), %xmm1
+	pmovmskb %xmm1, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%eax), %xmm2
+	pmovmskb %xmm2, %ecx
+	test	%ecx, %ecx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%eax), %xmm3
+	pmovmskb %xmm3, %ecx
+	sub	%edx, %eax
+	bsf	%ecx, %ecx
+	add	%ecx, %eax
+	add	$64, %eax
+	ret
+
+	.p2align 4
+L(exit):
+	sub	%edx, %eax
+	bsf	%ecx, %ecx
+	add	%ecx, %eax
+	ret
+
+L(exit_less16):
+	bsf	%ecx, %eax
+	ret
+
+	.p2align 4
+L(exit_unaligned):
+	sub	%edx, %eax
+	bsf	%ecx, %ecx
+	add	%ecx, %eax
+	ret
+
+	.p2align 4
+L(exit16):
+	sub	%edx, %eax
+	bsf	%ecx, %ecx
+	add	%ecx, %eax
+	add	$16, %eax
+	ret
+
+	.p2align 4
+L(exit32):
+	sub	%edx, %eax
+	bsf	%ecx, %ecx
+	add	%ecx, %eax
+	add	$32, %eax
+	ret
+
+	.p2align 4
+L(exit48):
+	sub	%edx, %eax
+	bsf	%ecx, %ecx
+	add	%ecx, %eax
+	add	$48, %eax
+	ret
+
+	.p2align 4
+L(exit64):
+	sub	%edx, %eax
+	bsf	%ecx, %ecx
+	add	%ecx, %eax
+	add	$64, %eax
+	ret
+
+END (STRLEN)
+
diff --git a/libc/arch-x86/silvermont/string/sse2-strncpy-slm.S b/libc/arch-x86/silvermont/string/sse2-strncpy-slm.S
new file mode 100755
index 0000000..591419f
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse2-strncpy-slm.S
@@ -0,0 +1,33 @@
+/*

+Copyright (c) 2014, Intel Corporation

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+

+    * Redistributions of source code must retain the above copyright notice,

+    * this list of conditions and the following disclaimer.

+

+    * Redistributions in binary form must reproduce the above copyright notice,

+    * this list of conditions and the following disclaimer in the documentation

+    * and/or other materials provided with the distribution.

+

+    * Neither the name of Intel Corporation nor the names of its contributors

+    * may be used to endorse or promote products derived from this software

+    * without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+*/

+

+#define USE_AS_STRNCPY

+#define STRCPY strncpy

+#include "sse2-strcpy-slm.S"

diff --git a/libc/arch-x86/silvermont/string/sse4-memcmp-slm.S b/libc/arch-x86/silvermont/string/sse4-memcmp-slm.S
new file mode 100755
index 0000000..e5028ff
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse4-memcmp-slm.S
@@ -0,0 +1,1278 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef cfi_remember_state
+# define cfi_remember_state	.cfi_remember_state
+#endif
+
+#ifndef cfi_restore_state
+# define cfi_restore_state	.cfi_restore_state
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)             \
+	.type name, @function;   \
+	.globl name;             \
+	.p2align 4;              \
+name:                            \
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)               \
+	cfi_endproc;             \
+	.size name, .-name
+#endif
+
+#ifndef MEMCMP
+# define MEMCMP	memcmp
+#endif
+
+#define CFI_PUSH(REG)	\
+	cfi_adjust_cfa_offset (4);	\
+	cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)	\
+	cfi_adjust_cfa_offset (-4);	\
+	cfi_restore (REG)
+
+#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
+#define POP(REG)	popl REG; CFI_POP (REG)
+
+#define PARMS	4
+#define BLK1	PARMS
+#define BLK2	BLK1 + 4
+#define LEN	BLK2 + 4
+#define RETURN	POP (%ebx); ret; CFI_PUSH (%ebx)
+
+
+#if (defined SHARED || defined __PIC__)
+# define JMPTBL(I, B)	I - B
+
+/* Load an entry in a jump table into EBX and branch to it.  TABLE is a
+	jump	table with relative offsets.  INDEX is a register contains the
+	index	into the jump table.   SCALE is the scale of INDEX. */
+
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)	\
+/* We first load PC into EBX.  */	\
+	call	__x86.get_pc_thunk.bx;	\
+/* Get the address of the jump table.  */	\
+	addl	$(TABLE - .), %ebx;	\
+/* Get the entry and convert the relative offset to the	\
+	absolute	address.  */	\
+	addl	(%ebx,INDEX,SCALE), %ebx;	\
+/* We loaded the jump table and adjuested EDX/ESI. Go.  */	\
+	jmp	*%ebx
+#else
+# define JMPTBL(I, B)	I
+
+/* Load an entry in a jump table into EBX and branch to it.  TABLE is a
+	jump	table with relative offsets.  INDEX is a register contains the
+	index	into the jump table.   SCALE is the scale of INDEX. */
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)	\
+	jmp	*TABLE(,INDEX,SCALE)
+#endif
+
+
+/* Warning!
+           wmemcmp has to use SIGNED comparison for elements.
+           memcmp has to use UNSIGNED comparison for elemnts.
+*/
+
+	.section .text.sse4.2,"ax",@progbits
+ENTRY (MEMCMP)
+	movl	BLK1(%esp), %eax
+	movl	BLK2(%esp), %edx
+	movl	LEN(%esp), %ecx
+
+#ifdef USE_AS_WMEMCMP
+	shl	$2, %ecx
+	test	%ecx, %ecx
+	jz	L(return0)
+#else
+	cmp	$1, %ecx
+	jbe	L(less1bytes)
+#endif
+
+	pxor	%xmm0, %xmm0
+	cmp	$64, %ecx
+	ja	L(64bytesormore)
+	cmp	$8, %ecx
+
+#ifndef USE_AS_WMEMCMP
+	PUSH	(%ebx)
+	jb	L(less8bytes)
+#else
+	jb	L(less8bytes)
+	PUSH	(%ebx)
+#endif
+
+	add	%ecx, %edx
+	add	%ecx, %eax
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %ecx, 4)
+
+#ifndef USE_AS_WMEMCMP
+	.p2align 4
+L(less8bytes):
+	mov	(%eax), %bl
+	cmpb	(%edx), %bl
+	jne	L(nonzero)
+
+	mov	1(%eax), %bl
+	cmpb	1(%edx), %bl
+	jne	L(nonzero)
+
+	cmp	$2, %ecx
+	jz	L(0bytes)
+
+	mov	2(%eax), %bl
+	cmpb	2(%edx), %bl
+	jne	L(nonzero)
+
+	cmp	$3, %ecx
+	jz	L(0bytes)
+
+	mov	3(%eax), %bl
+	cmpb	3(%edx), %bl
+	jne	L(nonzero)
+
+	cmp	$4, %ecx
+	jz	L(0bytes)
+
+	mov	4(%eax), %bl
+	cmpb	4(%edx), %bl
+	jne	L(nonzero)
+
+	cmp	$5, %ecx
+	jz	L(0bytes)
+
+	mov	5(%eax), %bl
+	cmpb	5(%edx), %bl
+	jne	L(nonzero)
+
+	cmp	$6, %ecx
+	jz	L(0bytes)
+
+	mov	6(%eax), %bl
+	cmpb	6(%edx), %bl
+	je	L(0bytes)
+
+L(nonzero):
+	POP	(%ebx)
+	mov	$1, %eax
+	ja	L(above)
+	neg	%eax
+L(above):
+	ret
+	CFI_PUSH (%ebx)
+#endif
+
+	.p2align 4
+L(0bytes):
+	POP	(%ebx)
+	xor	%eax, %eax
+	ret
+
+#ifdef USE_AS_WMEMCMP
+
+/* for wmemcmp, case N == 1 */
+
+	.p2align 4
+L(less8bytes):
+	mov	(%eax), %ecx
+	cmp	(%edx), %ecx
+	je	L(return0)
+	mov	$1, %eax
+	jg	L(find_diff_bigger)
+	neg	%eax
+	ret
+
+	.p2align 4
+L(find_diff_bigger):
+	ret
+
+	.p2align 4
+L(return0):
+	xor	%eax, %eax
+	ret
+#endif
+
+#ifndef USE_AS_WMEMCMP
+	.p2align 4
+L(less1bytes):
+	jb	L(0bytesend)
+	movzbl	(%eax), %eax
+	movzbl	(%edx), %edx
+	sub	%edx, %eax
+	ret
+
+	.p2align 4
+L(0bytesend):
+	xor	%eax, %eax
+	ret
+#endif
+	.p2align 4
+L(64bytesormore):
+	PUSH	(%ebx)
+	mov	%ecx, %ebx
+	mov	$64, %ecx
+	sub	$64, %ebx
+L(64bytesormore_loop):
+	movdqu	(%eax), %xmm1
+	movdqu	(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(find_16diff)
+
+	movdqu	16(%eax), %xmm1
+	movdqu	16(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(find_32diff)
+
+	movdqu	32(%eax), %xmm1
+	movdqu	32(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(find_48diff)
+
+	movdqu	48(%eax), %xmm1
+	movdqu	48(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(find_64diff)
+	add	%ecx, %eax
+	add	%ecx, %edx
+	sub	%ecx, %ebx
+	jae	L(64bytesormore_loop)
+	add	%ebx, %ecx
+	add	%ecx, %edx
+	add	%ecx, %eax
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %ecx, 4)
+
+#ifdef USE_AS_WMEMCMP
+
+/* Label needs only for table_64bytes filling */
+L(unreal_case):
+/* no code here */
+
+#endif
+	.p2align 4
+L(find_16diff):
+	sub	$16, %ecx
+L(find_32diff):
+	sub	$16, %ecx
+L(find_48diff):
+	sub	$16, %ecx
+L(find_64diff):
+	add	%ecx, %edx
+	add	%ecx, %eax
+
+#ifndef USE_AS_WMEMCMP
+	.p2align 4
+L(16bytes):
+	mov	-16(%eax), %ecx
+	mov	-16(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(12bytes):
+	mov	-12(%eax), %ecx
+	mov	-12(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(8bytes):
+	mov	-8(%eax), %ecx
+	mov	-8(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(4bytes):
+	mov	-4(%eax), %ecx
+	mov	-4(%edx), %ebx
+	cmp	%ebx, %ecx
+	mov	$0, %eax
+	jne	L(find_diff)
+	RETURN
+#else
+	.p2align 4
+L(16bytes):
+	mov	-16(%eax), %ecx
+	cmp	-16(%edx), %ecx
+	jne	L(find_diff)
+L(12bytes):
+	mov	-12(%eax), %ecx
+	cmp	-12(%edx), %ecx
+	jne	L(find_diff)
+L(8bytes):
+	mov	-8(%eax), %ecx
+	cmp	-8(%edx), %ecx
+	jne	L(find_diff)
+L(4bytes):
+	mov	-4(%eax), %ecx
+	cmp	-4(%edx), %ecx
+	mov	$0, %eax
+	jne	L(find_diff)
+	RETURN
+#endif
+
+#ifndef USE_AS_WMEMCMP
+	.p2align 4
+L(49bytes):
+	movdqu	-49(%eax), %xmm1
+	movdqu	-49(%edx), %xmm2
+	mov	$-49, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(33bytes):
+	movdqu	-33(%eax), %xmm1
+	movdqu	-33(%edx), %xmm2
+	mov	$-33, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(17bytes):
+	mov	-17(%eax), %ecx
+	mov	-17(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(13bytes):
+	mov	-13(%eax), %ecx
+	mov	-13(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(9bytes):
+	mov	-9(%eax), %ecx
+	mov	-9(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(5bytes):
+	mov	-5(%eax), %ecx
+	mov	-5(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzbl	-1(%eax), %ecx
+	cmp	-1(%edx), %cl
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+
+	.p2align 4
+L(50bytes):
+	mov	$-50, %ebx
+	movdqu	-50(%eax), %xmm1
+	movdqu	-50(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(34bytes):
+	mov	$-34, %ebx
+	movdqu	-34(%eax), %xmm1
+	movdqu	-34(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(18bytes):
+	mov	-18(%eax), %ecx
+	mov	-18(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(14bytes):
+	mov	-14(%eax), %ecx
+	mov	-14(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(10bytes):
+	mov	-10(%eax), %ecx
+	mov	-10(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(6bytes):
+	mov	-6(%eax), %ecx
+	mov	-6(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(2bytes):
+	movzwl	-2(%eax), %ecx
+	movzwl	-2(%edx), %ebx
+	cmp	%bl, %cl
+	jne	L(end)
+	cmp	%bh, %ch
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+
+	.p2align 4
+L(51bytes):
+	mov	$-51, %ebx
+	movdqu	-51(%eax), %xmm1
+	movdqu	-51(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(35bytes):
+	mov	$-35, %ebx
+	movdqu	-35(%eax), %xmm1
+	movdqu	-35(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(19bytes):
+	movl	-19(%eax), %ecx
+	movl	-19(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(15bytes):
+	movl	-15(%eax), %ecx
+	movl	-15(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(11bytes):
+	movl	-11(%eax), %ecx
+	movl	-11(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(7bytes):
+	movl	-7(%eax), %ecx
+	movl	-7(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+L(3bytes):
+	movzwl	-3(%eax), %ecx
+	movzwl	-3(%edx), %ebx
+	cmpb	%bl, %cl
+	jne	L(end)
+	cmp	%bx, %cx
+	jne	L(end)
+L(1bytes):
+	movzbl	-1(%eax), %eax
+	cmpb	-1(%edx), %al
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+#endif
+	.p2align 4
+L(52bytes):
+	movdqu	-52(%eax), %xmm1
+	movdqu	-52(%edx), %xmm2
+	mov	$-52, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(36bytes):
+	movdqu	-36(%eax), %xmm1
+	movdqu	-36(%edx), %xmm2
+	mov	$-36, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(20bytes):
+	movdqu	-20(%eax), %xmm1
+	movdqu	-20(%edx), %xmm2
+	mov	$-20, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-4(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-4(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-4(%edx), %ecx
+#endif
+	mov	$0, %eax
+	jne	L(find_diff)
+	RETURN
+
+#ifndef USE_AS_WMEMCMP
+	.p2align 4
+L(53bytes):
+	movdqu	-53(%eax), %xmm1
+	movdqu	-53(%edx), %xmm2
+	mov	$-53, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(37bytes):
+	mov	$-37, %ebx
+	movdqu	-37(%eax), %xmm1
+	movdqu	-37(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(21bytes):
+	mov	$-21, %ebx
+	movdqu	-21(%eax), %xmm1
+	movdqu	-21(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-5(%eax), %ecx
+	mov	-5(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzbl	-1(%eax), %ecx
+	cmp	-1(%edx), %cl
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+
+	.p2align 4
+L(54bytes):
+	movdqu	-54(%eax), %xmm1
+	movdqu	-54(%edx), %xmm2
+	mov	$-54, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(38bytes):
+	mov	$-38, %ebx
+	movdqu	-38(%eax), %xmm1
+	movdqu	-38(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(22bytes):
+	mov	$-22, %ebx
+	movdqu	-22(%eax), %xmm1
+	movdqu	-22(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	mov	-6(%eax), %ecx
+	mov	-6(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzwl	-2(%eax), %ecx
+	movzwl	-2(%edx), %ebx
+	cmp	%bl, %cl
+	jne	L(end)
+	cmp	%bh, %ch
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+
+	.p2align 4
+L(55bytes):
+	movdqu	-55(%eax), %xmm1
+	movdqu	-55(%edx), %xmm2
+	mov	$-55, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(39bytes):
+	mov	$-39, %ebx
+	movdqu	-39(%eax), %xmm1
+	movdqu	-39(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(23bytes):
+	mov	$-23, %ebx
+	movdqu	-23(%eax), %xmm1
+	movdqu	-23(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	movl	-7(%eax), %ecx
+	movl	-7(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzwl	-3(%eax), %ecx
+	movzwl	-3(%edx), %ebx
+	cmpb	%bl, %cl
+	jne	L(end)
+	cmp	%bx, %cx
+	jne	L(end)
+	movzbl	-1(%eax), %eax
+	cmpb	-1(%edx), %al
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+#endif
+	.p2align 4
+L(56bytes):
+	movdqu	-56(%eax), %xmm1
+	movdqu	-56(%edx), %xmm2
+	mov	$-56, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(40bytes):
+	mov	$-40, %ebx
+	movdqu	-40(%eax), %xmm1
+	movdqu	-40(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(24bytes):
+	mov	$-24, %ebx
+	movdqu	-24(%eax), %xmm1
+	movdqu	-24(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	mov	-8(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-8(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-8(%edx), %ecx
+#endif
+	jne	L(find_diff)
+
+	mov	-4(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-4(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-4(%edx), %ecx
+#endif
+	mov	$0, %eax
+	jne	L(find_diff)
+	RETURN
+
+#ifndef USE_AS_WMEMCMP
+	.p2align 4
+L(57bytes):
+	movdqu	-57(%eax), %xmm1
+	movdqu	-57(%edx), %xmm2
+	mov	$-57, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(41bytes):
+	mov	$-41, %ebx
+	movdqu	-41(%eax), %xmm1
+	movdqu	-41(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(25bytes):
+	mov	$-25, %ebx
+	movdqu	-25(%eax), %xmm1
+	movdqu	-25(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-9(%eax), %ecx
+	mov	-9(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	mov	-5(%eax), %ecx
+	mov	-5(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzbl	-1(%eax), %ecx
+	cmp	-1(%edx), %cl
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+
+	.p2align 4
+L(58bytes):
+	movdqu	-58(%eax), %xmm1
+	movdqu	-58(%edx), %xmm2
+	mov	$-58, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(42bytes):
+	mov	$-42, %ebx
+	movdqu	-42(%eax), %xmm1
+	movdqu	-42(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(26bytes):
+	mov	$-26, %ebx
+	movdqu	-26(%eax), %xmm1
+	movdqu	-26(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	mov	-10(%eax), %ecx
+	mov	-10(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+
+	mov	-6(%eax), %ecx
+	mov	-6(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+
+	movzwl	-2(%eax), %ecx
+	movzwl	-2(%edx), %ebx
+	cmp	%bl, %cl
+	jne	L(end)
+	cmp	%bh, %ch
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+
+	.p2align 4
+L(59bytes):
+	movdqu	-59(%eax), %xmm1
+	movdqu	-59(%edx), %xmm2
+	mov	$-59, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(43bytes):
+	mov	$-43, %ebx
+	movdqu	-43(%eax), %xmm1
+	movdqu	-43(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(27bytes):
+	mov	$-27, %ebx
+	movdqu	-27(%eax), %xmm1
+	movdqu	-27(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	movl	-11(%eax), %ecx
+	movl	-11(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movl	-7(%eax), %ecx
+	movl	-7(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzwl	-3(%eax), %ecx
+	movzwl	-3(%edx), %ebx
+	cmpb	%bl, %cl
+	jne	L(end)
+	cmp	%bx, %cx
+	jne	L(end)
+	movzbl	-1(%eax), %eax
+	cmpb	-1(%edx), %al
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+#endif
+	.p2align 4
+L(60bytes):
+	movdqu	-60(%eax), %xmm1
+	movdqu	-60(%edx), %xmm2
+	mov	$-60, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(44bytes):
+	mov	$-44, %ebx
+	movdqu	-44(%eax), %xmm1
+	movdqu	-44(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(28bytes):
+	mov	$-28, %ebx
+	movdqu	-28(%eax), %xmm1
+	movdqu	-28(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	mov	-12(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-12(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-12(%edx), %ecx
+#endif
+	jne	L(find_diff)
+
+	mov	-8(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-8(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-8(%edx), %ecx
+#endif
+	jne	L(find_diff)
+
+	mov	-4(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-4(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-4(%edx), %ecx
+#endif
+	mov	$0, %eax
+	jne	L(find_diff)
+	RETURN
+
+#ifndef USE_AS_WMEMCMP
+	.p2align 4
+L(61bytes):
+	movdqu	-61(%eax), %xmm1
+	movdqu	-61(%edx), %xmm2
+	mov	$-61, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(45bytes):
+	mov	$-45, %ebx
+	movdqu	-45(%eax), %xmm1
+	movdqu	-45(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(29bytes):
+	mov	$-29, %ebx
+	movdqu	-29(%eax), %xmm1
+	movdqu	-29(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	mov	-13(%eax), %ecx
+	mov	-13(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+
+	mov	-9(%eax), %ecx
+	mov	-9(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+
+	mov	-5(%eax), %ecx
+	mov	-5(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzbl	-1(%eax), %ecx
+	cmp	-1(%edx), %cl
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+
+	.p2align 4
+L(62bytes):
+	movdqu	-62(%eax), %xmm1
+	movdqu	-62(%edx), %xmm2
+	mov	$-62, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(46bytes):
+	mov	$-46, %ebx
+	movdqu	-46(%eax), %xmm1
+	movdqu	-46(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(30bytes):
+	mov	$-30, %ebx
+	movdqu	-30(%eax), %xmm1
+	movdqu	-30(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-14(%eax), %ecx
+	mov	-14(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	mov	-10(%eax), %ecx
+	mov	-10(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	mov	-6(%eax), %ecx
+	mov	-6(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzwl	-2(%eax), %ecx
+	movzwl	-2(%edx), %ebx
+	cmp	%bl, %cl
+	jne	L(end)
+	cmp	%bh, %ch
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+
+	.p2align 4
+L(63bytes):
+	movdqu	-63(%eax), %xmm1
+	movdqu	-63(%edx), %xmm2
+	mov	$-63, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(47bytes):
+	mov	$-47, %ebx
+	movdqu	-47(%eax), %xmm1
+	movdqu	-47(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(31bytes):
+	mov	$-31, %ebx
+	movdqu	-31(%eax), %xmm1
+	movdqu	-31(%edx), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	movl	-15(%eax), %ecx
+	movl	-15(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movl	-11(%eax), %ecx
+	movl	-11(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movl	-7(%eax), %ecx
+	movl	-7(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+	movzwl	-3(%eax), %ecx
+	movzwl	-3(%edx), %ebx
+	cmpb	%bl, %cl
+	jne	L(end)
+	cmp	%bx, %cx
+	jne	L(end)
+	movzbl	-1(%eax), %eax
+	cmpb	-1(%edx), %al
+	mov	$0, %eax
+	jne	L(end)
+	RETURN
+#endif
+
+	.p2align 4
+L(64bytes):
+	movdqu	-64(%eax), %xmm1
+	movdqu	-64(%edx), %xmm2
+	mov	$-64, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(48bytes):
+	movdqu	-48(%eax), %xmm1
+	movdqu	-48(%edx), %xmm2
+	mov	$-48, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(32bytes):
+	movdqu	-32(%eax), %xmm1
+	movdqu	-32(%edx), %xmm2
+	mov	$-32, %ebx
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	mov	-16(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-16(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-16(%edx), %ecx
+#endif
+	jne	L(find_diff)
+
+	mov	-12(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-12(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-12(%edx), %ecx
+#endif
+	jne	L(find_diff)
+
+	mov	-8(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-8(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-8(%edx), %ecx
+#endif
+	jne	L(find_diff)
+
+	mov	-4(%eax), %ecx
+#ifndef USE_AS_WMEMCMP
+	mov	-4(%edx), %ebx
+	cmp	%ebx, %ecx
+#else
+	cmp	-4(%edx), %ecx
+#endif
+	mov	$0, %eax
+	jne	L(find_diff)
+	RETURN
+
+#ifndef USE_AS_WMEMCMP
+	.p2align 4
+L(less16bytes):
+	add	%ebx, %eax
+	add	%ebx, %edx
+
+	mov	(%eax), %ecx
+	mov	(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+
+	mov	4(%eax), %ecx
+	mov	4(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+
+	mov	8(%eax), %ecx
+	mov	8(%edx), %ebx
+	cmp	%ebx, %ecx
+	jne	L(find_diff)
+
+	mov	12(%eax), %ecx
+	mov	12(%edx), %ebx
+	cmp	%ebx, %ecx
+	mov	$0, %eax
+	jne	L(find_diff)
+	RETURN
+#else
+	.p2align 4
+L(less16bytes):
+	add	%ebx, %eax
+	add	%ebx, %edx
+
+	mov	(%eax), %ecx
+	cmp	(%edx), %ecx
+	jne	L(find_diff)
+
+	mov	4(%eax), %ecx
+	cmp	4(%edx), %ecx
+	jne	L(find_diff)
+
+	mov	8(%eax), %ecx
+	cmp	8(%edx), %ecx
+	jne	L(find_diff)
+
+	mov	12(%eax), %ecx
+	cmp	12(%edx), %ecx
+
+	mov	$0, %eax
+	jne	L(find_diff)
+	RETURN
+#endif
+
+	.p2align 4
+L(find_diff):
+#ifndef USE_AS_WMEMCMP
+	cmpb	%bl, %cl
+	jne	L(end)
+	cmp	%bx, %cx
+	jne	L(end)
+	shr	$16,%ecx
+	shr	$16,%ebx
+	cmp	%bl, %cl
+	jne	L(end)
+	cmp	%bx, %cx
+L(end):
+	POP	(%ebx)
+	mov	$1, %eax
+	ja	L(bigger)
+	neg	%eax
+L(bigger):
+	ret
+#else
+	POP	(%ebx)
+	mov	$1, %eax
+	jg	L(bigger)
+	neg	%eax
+	ret
+
+	.p2align 4
+L(bigger):
+	ret
+#endif
+END (MEMCMP)
+
+	.section .rodata.sse4.2,"a",@progbits
+	.p2align 2
+	.type	L(table_64bytes), @object
+#ifndef USE_AS_WMEMCMP
+L(table_64bytes):
+	.int	JMPTBL (L(0bytes), L(table_64bytes))
+	.int	JMPTBL (L(1bytes), L(table_64bytes))
+	.int	JMPTBL (L(2bytes), L(table_64bytes))
+	.int	JMPTBL (L(3bytes), L(table_64bytes))
+	.int	JMPTBL (L(4bytes), L(table_64bytes))
+	.int	JMPTBL (L(5bytes), L(table_64bytes))
+	.int	JMPTBL (L(6bytes), L(table_64bytes))
+	.int	JMPTBL (L(7bytes), L(table_64bytes))
+	.int	JMPTBL (L(8bytes), L(table_64bytes))
+	.int	JMPTBL (L(9bytes), L(table_64bytes))
+	.int	JMPTBL (L(10bytes), L(table_64bytes))
+	.int	JMPTBL (L(11bytes), L(table_64bytes))
+	.int	JMPTBL (L(12bytes), L(table_64bytes))
+	.int	JMPTBL (L(13bytes), L(table_64bytes))
+	.int	JMPTBL (L(14bytes), L(table_64bytes))
+	.int	JMPTBL (L(15bytes), L(table_64bytes))
+	.int	JMPTBL (L(16bytes), L(table_64bytes))
+	.int	JMPTBL (L(17bytes), L(table_64bytes))
+	.int	JMPTBL (L(18bytes), L(table_64bytes))
+	.int	JMPTBL (L(19bytes), L(table_64bytes))
+	.int	JMPTBL (L(20bytes), L(table_64bytes))
+	.int	JMPTBL (L(21bytes), L(table_64bytes))
+	.int	JMPTBL (L(22bytes), L(table_64bytes))
+	.int	JMPTBL (L(23bytes), L(table_64bytes))
+	.int	JMPTBL (L(24bytes), L(table_64bytes))
+	.int	JMPTBL (L(25bytes), L(table_64bytes))
+	.int	JMPTBL (L(26bytes), L(table_64bytes))
+	.int	JMPTBL (L(27bytes), L(table_64bytes))
+	.int	JMPTBL (L(28bytes), L(table_64bytes))
+	.int	JMPTBL (L(29bytes), L(table_64bytes))
+	.int	JMPTBL (L(30bytes), L(table_64bytes))
+	.int	JMPTBL (L(31bytes), L(table_64bytes))
+	.int	JMPTBL (L(32bytes), L(table_64bytes))
+	.int	JMPTBL (L(33bytes), L(table_64bytes))
+	.int	JMPTBL (L(34bytes), L(table_64bytes))
+	.int	JMPTBL (L(35bytes), L(table_64bytes))
+	.int	JMPTBL (L(36bytes), L(table_64bytes))
+	.int	JMPTBL (L(37bytes), L(table_64bytes))
+	.int	JMPTBL (L(38bytes), L(table_64bytes))
+	.int	JMPTBL (L(39bytes), L(table_64bytes))
+	.int	JMPTBL (L(40bytes), L(table_64bytes))
+	.int	JMPTBL (L(41bytes), L(table_64bytes))
+	.int	JMPTBL (L(42bytes), L(table_64bytes))
+	.int	JMPTBL (L(43bytes), L(table_64bytes))
+	.int	JMPTBL (L(44bytes), L(table_64bytes))
+	.int	JMPTBL (L(45bytes), L(table_64bytes))
+	.int	JMPTBL (L(46bytes), L(table_64bytes))
+	.int	JMPTBL (L(47bytes), L(table_64bytes))
+	.int	JMPTBL (L(48bytes), L(table_64bytes))
+	.int	JMPTBL (L(49bytes), L(table_64bytes))
+	.int	JMPTBL (L(50bytes), L(table_64bytes))
+	.int	JMPTBL (L(51bytes), L(table_64bytes))
+	.int	JMPTBL (L(52bytes), L(table_64bytes))
+	.int	JMPTBL (L(53bytes), L(table_64bytes))
+	.int	JMPTBL (L(54bytes), L(table_64bytes))
+	.int	JMPTBL (L(55bytes), L(table_64bytes))
+	.int	JMPTBL (L(56bytes), L(table_64bytes))
+	.int	JMPTBL (L(57bytes), L(table_64bytes))
+	.int	JMPTBL (L(58bytes), L(table_64bytes))
+	.int	JMPTBL (L(59bytes), L(table_64bytes))
+	.int	JMPTBL (L(60bytes), L(table_64bytes))
+	.int	JMPTBL (L(61bytes), L(table_64bytes))
+	.int	JMPTBL (L(62bytes), L(table_64bytes))
+	.int	JMPTBL (L(63bytes), L(table_64bytes))
+	.int	JMPTBL (L(64bytes), L(table_64bytes))
+#else
+L(table_64bytes):
+	.int	JMPTBL (L(0bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(4bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(8bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(12bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(16bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(20bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(24bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(28bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(32bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(36bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(40bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(44bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(48bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(52bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(56bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(60bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(64bytes), L(table_64bytes))
+#endif
diff --git a/libc/arch-x86/silvermont/string/sse4-wmemcmp-slm.S b/libc/arch-x86/silvermont/string/sse4-wmemcmp-slm.S
new file mode 100755
index 0000000..2c350bb
--- /dev/null
+++ b/libc/arch-x86/silvermont/string/sse4-wmemcmp-slm.S
@@ -0,0 +1,33 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define USE_AS_WMEMCMP
+#define MEMCMP wmemcmp
+#include "sse4-memcmp-slm.S"
diff --git a/libc/arch-x86/string/bcopy.S b/libc/arch-x86/string/bcopy.S
deleted file mode 100644
index 40df1d0..0000000
--- a/libc/arch-x86/string/bcopy.S
+++ /dev/null
@@ -1,98 +0,0 @@
-/*	$OpenBSD: bcopy.S,v 1.5 2005/08/07 11:30:38 espie Exp $	*/
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from locore.s.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-
-	/*
-	 * (ov)bcopy (src,dst,cnt)
-	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
-	 */
-
-#if defined(MEMCOPY)
-ENTRY(memcpy)
-#elif defined(MEMMOVE)
-ENTRY(memmove)
-#else
-ENTRY(bcopy)
-#endif
-	pushl	%esi
-	pushl	%edi
-#if defined(MEMCOPY) || defined(MEMMOVE)
-	movl	12(%esp),%edi
-	movl	16(%esp),%esi
-	movl	%edi, %eax
-#else
-	movl	12(%esp),%esi
-	movl	16(%esp),%edi
-#endif
-	movl	20(%esp),%ecx
-	movl	%ecx,%edx
-	cmpl	%esi,%edi	/* potentially overlapping? */
-	jnb	1f
-	cld			/* nope, copy forwards. */
-	shrl	$2,%ecx		/* copy by words */
-	rep
-	movsl
-	movl	%edx,%ecx
-	andl	$3,%ecx		/* any bytes left? */
-	rep
-	movsb
-	popl	%edi
-	popl	%esi
-	ret
-1:
-	addl	%ecx,%edi	/* copy backwards. */
-	addl	%ecx,%esi
-	std
-	andl	$3,%ecx		/* any fractional bytes? */
-	decl	%edi
-	decl	%esi
-	rep
-	movsb
-	movl	%edx,%ecx
-	shrl	$2,%ecx
-	subl	$3,%esi
-	subl	$3,%edi
-	rep
-	movsl
-	popl	%edi
-	popl	%esi
-	cld
-	ret
-#if defined(MEMCOPY)
-END(memcpy)
-#elif defined(MEMMOVE)
-END(memmove)
-#else
-END(bcopy)
-#endif
diff --git a/libc/arch-x86/string/cache.h b/libc/arch-x86/string/cache.h
deleted file mode 100644
index d9aff5c..0000000
--- a/libc/arch-x86/string/cache.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-Copyright (c) 2010, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-    * Redistributions of source code must retain the above copyright notice,
-    * this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above copyright notice,
-    * this list of conditions and the following disclaimer in the documentation
-    * and/or other materials provided with the distribution.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/* Values are optimized for Atom */
-#define SHARED_CACHE_SIZE	(512*1024)			/* Atom L2 Cache */
-#define DATA_CACHE_SIZE		(24*1024)			/* Atom L1 Data Cache */
-#define SHARED_CACHE_SIZE_HALF	(SHARED_CACHE_SIZE / 2)
-#define DATA_CACHE_SIZE_HALF	(DATA_CACHE_SIZE / 2)
diff --git a/libc/arch-x86/string/memcmp.S b/libc/arch-x86/string/memcmp.S
deleted file mode 100644
index 3b50530..0000000
--- a/libc/arch-x86/string/memcmp.S
+++ /dev/null
@@ -1,44 +0,0 @@
-/*	$OpenBSD: memcmp.S,v 1.4 2005/08/07 11:30:38 espie Exp $ */
-/*
- * Written by J.T. Conklin <jtc@netbsd.org>.
- * Public domain.
- */
-
-#include <machine/asm.h>
-
-ENTRY(memcmp)
-	pushl	%edi
-	pushl	%esi
-	movl	12(%esp),%edi
-	movl	16(%esp),%esi
-	cld				/* set compare direction forward */
-
-	movl	20(%esp),%ecx		/* compare by words */
-	shrl	$2,%ecx
-	repe
-	cmpsl
-	jne	L5			/* do we match so far? */
-
-	movl	20(%esp),%ecx		/* compare remainder by bytes */
-	andl	$3,%ecx
-	repe
-	cmpsb
-	jne	L6			/* do we match? */
-
-	xorl	%eax,%eax		/* we match, return zero	*/
-	popl	%esi
-	popl	%edi
-	ret
-
-L5:	movl	$4,%ecx			/* We know that one of the next	*/
-	subl	%ecx,%edi		/* four pairs of bytes do not	*/
-	subl	%ecx,%esi		/* match.			*/
-	repe
-	cmpsb
-L6:	movzbl  -1(%edi),%eax		/* Perform unsigned comparison	*/
-	movzbl	-1(%esi),%edx
-	subl	%edx,%eax
-	popl	%esi
-	popl	%edi
-	ret
-END(memcmp)
diff --git a/libc/arch-x86/string/sse2-index-atom.S b/libc/arch-x86/string/sse2-index-atom.S
deleted file mode 100644
index d51e1d4..0000000
--- a/libc/arch-x86/string/sse2-index-atom.S
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-Copyright (c) 2011, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-    * Redistributions of source code must retain the above copyright notice,
-    * this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above copyright notice,
-    * this list of conditions and the following disclaimer in the documentation
-    * and/or other materials provided with the distribution.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#define strchr  index
-#include "sse2-strchr-atom.S"
diff --git a/libc/arch-x86/string/sse2-memset-atom.S b/libc/arch-x86/string/sse2-memset-atom.S
deleted file mode 100644
index a54bf51..0000000
--- a/libc/arch-x86/string/sse2-memset-atom.S
+++ /dev/null
@@ -1,921 +0,0 @@
-/*
-Copyright (c) 2010, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-    * Redistributions of source code must retain the above copyright notice,
-    * this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above copyright notice,
-    * this list of conditions and the following disclaimer in the documentation
-    * and/or other materials provided with the distribution.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include "cache.h"
-#undef __i686
-
-#ifndef L
-# define L(label)	.L##label
-#endif
-
-#ifndef ALIGN
-# define ALIGN(n)	.p2align n
-#endif
-
-#ifndef cfi_startproc
-# define cfi_startproc			.cfi_startproc
-#endif
-
-#ifndef cfi_endproc
-# define cfi_endproc			.cfi_endproc
-#endif
-
-#ifndef cfi_rel_offset
-# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
-#endif
-
-#ifndef cfi_restore
-# define cfi_restore(reg)		.cfi_restore reg
-#endif
-
-#ifndef cfi_adjust_cfa_offset
-# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
-#endif
-
-#ifndef ENTRY
-# define ENTRY(name)			\
-	.type name,  @function; 	\
-	.globl name;			\
-	.p2align 4;			\
-name:					\
-	cfi_startproc
-#endif
-
-#ifndef END
-# define END(name)			\
-	cfi_endproc;			\
-	.size name, .-name
-#endif
-
-#define CFI_PUSH(REG)						\
-  cfi_adjust_cfa_offset (4);					\
-  cfi_rel_offset (REG, 0)
-
-#define CFI_POP(REG)						\
-  cfi_adjust_cfa_offset (-4);					\
-  cfi_restore (REG)
-
-#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
-#define POP(REG)	popl REG; CFI_POP (REG)
-
-#ifdef USE_AS_BZERO
-# define DEST		PARMS
-# define LEN		DEST+4
-# define SETRTNVAL
-#else
-# define DEST		PARMS
-# define CHR		DEST+4
-# define LEN		CHR+4
-# define SETRTNVAL	movl DEST(%esp), %eax
-#endif
-
-#if (defined SHARED || defined __PIC__)
-# define ENTRANCE	PUSH (%ebx);
-# define RETURN_END	POP (%ebx); ret
-# define RETURN		RETURN_END; CFI_PUSH (%ebx)
-# define PARMS		8		/* Preserve EBX.  */
-# define JMPTBL(I, B)	I - B
-
-/* Load an entry in a jump table into EBX and branch to it.  TABLE is a
-   jump table with relative offsets.   */
-# define BRANCH_TO_JMPTBL_ENTRY(TABLE)				\
-    /* We first load PC into EBX.  */				\
-    call	__i686.get_pc_thunk.bx;				\
-    /* Get the address of the jump table.  */			\
-    add		$(TABLE - .), %ebx;				\
-    /* Get the entry and convert the relative offset to the	\
-       absolute address.  */					\
-    add		(%ebx,%ecx,4), %ebx;				\
-    add		%ecx, %edx;					\
-    /* We loaded the jump table and adjuested EDX. Go.  */	\
-    jmp		*%ebx
-
-	.section	.gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
-	.globl	__i686.get_pc_thunk.bx
-	.hidden	__i686.get_pc_thunk.bx
-	ALIGN (4)
-	.type	__i686.get_pc_thunk.bx,@function
-__i686.get_pc_thunk.bx:
-	movl	(%esp), %ebx
-	ret
-#else
-# define ENTRANCE
-# define RETURN_END	ret
-# define RETURN		RETURN_END
-# define PARMS		4
-# define JMPTBL(I, B)	I
-
-/* Branch to an entry in a jump table.  TABLE is a jump table with
-   absolute offsets.  */
-# define BRANCH_TO_JMPTBL_ENTRY(TABLE)				\
-    add		%ecx, %edx;					\
-    jmp		*TABLE(,%ecx,4)
-#endif
-
-#ifndef MEMSET
-# define MEMSET memset
-#endif
-
-	.section .text.sse2,"ax",@progbits
-	ALIGN (4)
-ENTRY (MEMSET)
-	ENTRANCE
-
-	movl	LEN(%esp), %ecx
-#ifdef USE_AS_BZERO
-	xor	%eax, %eax
-#else
-	movzbl	CHR(%esp), %eax
-	movb	%al, %ah
-	/* Fill the whole EAX with pattern.  */
-	movl	%eax, %edx
-	shl	$16, %eax
-	or	%edx, %eax
-#endif
-	movl	DEST(%esp), %edx
-	cmp	$32, %ecx
-	jae	L(32bytesormore)
-
-L(write_less32bytes):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_less_32bytes))
-
-
-	.pushsection .rodata.sse2,"a",@progbits
-	ALIGN (2)
-L(table_less_32bytes):
-	.int	JMPTBL (L(write_0bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_1bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_2bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_3bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_4bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_5bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_6bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_7bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_8bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_9bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_10bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_11bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_12bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_13bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_14bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_15bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_16bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_17bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_18bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_19bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_20bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_21bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_22bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_23bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_24bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_25bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_26bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_27bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_28bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_29bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_30bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_31bytes), L(table_less_32bytes))
-	.popsection
-
-	ALIGN (4)
-L(write_28bytes):
-	movl	%eax, -28(%edx)
-L(write_24bytes):
-	movl	%eax, -24(%edx)
-L(write_20bytes):
-	movl	%eax, -20(%edx)
-L(write_16bytes):
-	movl	%eax, -16(%edx)
-L(write_12bytes):
-	movl	%eax, -12(%edx)
-L(write_8bytes):
-	movl	%eax, -8(%edx)
-L(write_4bytes):
-	movl	%eax, -4(%edx)
-L(write_0bytes):
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(write_29bytes):
-	movl	%eax, -29(%edx)
-L(write_25bytes):
-	movl	%eax, -25(%edx)
-L(write_21bytes):
-	movl	%eax, -21(%edx)
-L(write_17bytes):
-	movl	%eax, -17(%edx)
-L(write_13bytes):
-	movl	%eax, -13(%edx)
-L(write_9bytes):
-	movl	%eax, -9(%edx)
-L(write_5bytes):
-	movl	%eax, -5(%edx)
-L(write_1bytes):
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(write_30bytes):
-	movl	%eax, -30(%edx)
-L(write_26bytes):
-	movl	%eax, -26(%edx)
-L(write_22bytes):
-	movl	%eax, -22(%edx)
-L(write_18bytes):
-	movl	%eax, -18(%edx)
-L(write_14bytes):
-	movl	%eax, -14(%edx)
-L(write_10bytes):
-	movl	%eax, -10(%edx)
-L(write_6bytes):
-	movl	%eax, -6(%edx)
-L(write_2bytes):
-	movw	%ax, -2(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(write_31bytes):
-	movl	%eax, -31(%edx)
-L(write_27bytes):
-	movl	%eax, -27(%edx)
-L(write_23bytes):
-	movl	%eax, -23(%edx)
-L(write_19bytes):
-	movl	%eax, -19(%edx)
-L(write_15bytes):
-	movl	%eax, -15(%edx)
-L(write_11bytes):
-	movl	%eax, -11(%edx)
-L(write_7bytes):
-	movl	%eax, -7(%edx)
-L(write_3bytes):
-	movw	%ax, -3(%edx)
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-/* ECX > 32 and EDX is 4 byte aligned.  */
-L(32bytesormore):
-	/* Fill xmm0 with the pattern.  */
-#ifdef USE_AS_BZERO
-	pxor	%xmm0, %xmm0
-#else
-	movd	%eax, %xmm0
-	pshufd	$0, %xmm0, %xmm0
-#endif
-	testl	$0xf, %edx
-	jz	L(aligned_16)
-/* ECX > 32 and EDX is not 16 byte aligned.  */
-L(not_aligned_16):
-	movdqu	%xmm0, (%edx)
-	movl	%edx, %eax
-	and	$-16, %edx
-	add	$16, %edx
-	sub	%edx, %eax
-	add	%eax, %ecx
-	movd	%xmm0, %eax
-
-	ALIGN (4)
-L(aligned_16):
-	cmp	$128, %ecx
-	jae	L(128bytesormore)
-
-L(aligned_16_less128bytes):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
-
-	ALIGN (4)
-L(128bytesormore):
-#ifdef SHARED_CACHE_SIZE
-	PUSH (%ebx)
-	mov	$SHARED_CACHE_SIZE, %ebx
-#else
-# if (defined SHARED || defined __PIC__)
-	call	__i686.get_pc_thunk.bx
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	mov	__x86_shared_cache_size@GOTOFF(%ebx), %ebx
-# else
-	PUSH (%ebx)
-	mov	__x86_shared_cache_size, %ebx
-# endif
-#endif
-	cmp	%ebx, %ecx
-	jae	L(128bytesormore_nt_start)
-
-
-#ifdef DATA_CACHE_SIZE
-	POP (%ebx)
-# define RESTORE_EBX_STATE CFI_PUSH (%ebx)
-	cmp	$DATA_CACHE_SIZE, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-#  define RESTORE_EBX_STATE
-	call	__i686.get_pc_thunk.bx
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size@GOTOFF(%ebx), %ecx
-# else
-	POP (%ebx)
-#  define RESTORE_EBX_STATE CFI_PUSH (%ebx)
-	cmp	__x86_data_cache_size, %ecx
-# endif
-#endif
-
-	jae	L(128bytes_L2_normal)
-	subl	$128, %ecx
-L(128bytesormore_normal):
-	sub	$128, %ecx
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm0, 0x10(%edx)
-	movdqa	%xmm0, 0x20(%edx)
-	movdqa	%xmm0, 0x30(%edx)
-	movdqa	%xmm0, 0x40(%edx)
-	movdqa	%xmm0, 0x50(%edx)
-	movdqa	%xmm0, 0x60(%edx)
-	movdqa	%xmm0, 0x70(%edx)
-	lea	128(%edx), %edx
-	jb	L(128bytesless_normal)
-
-
-	sub	$128, %ecx
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm0, 0x10(%edx)
-	movdqa	%xmm0, 0x20(%edx)
-	movdqa	%xmm0, 0x30(%edx)
-	movdqa	%xmm0, 0x40(%edx)
-	movdqa	%xmm0, 0x50(%edx)
-	movdqa	%xmm0, 0x60(%edx)
-	movdqa	%xmm0, 0x70(%edx)
-	lea	128(%edx), %edx
-	jae	L(128bytesormore_normal)
-
-L(128bytesless_normal):
-	add	$128, %ecx
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
-
-	ALIGN (4)
-L(128bytes_L2_normal):
-	prefetcht0	0x380(%edx)
-	prefetcht0	0x3c0(%edx)
-	sub	$128, %ecx
-	movdqa	%xmm0, (%edx)
-	movaps	%xmm0, 0x10(%edx)
-	movaps	%xmm0, 0x20(%edx)
-	movaps	%xmm0, 0x30(%edx)
-	movaps	%xmm0, 0x40(%edx)
-	movaps	%xmm0, 0x50(%edx)
-	movaps	%xmm0, 0x60(%edx)
-	movaps	%xmm0, 0x70(%edx)
-	add	$128, %edx
-	cmp	$128, %ecx
-	jae	L(128bytes_L2_normal)
-
-L(128bytesless_L2_normal):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
-
-	RESTORE_EBX_STATE
-L(128bytesormore_nt_start):
-	sub	%ebx, %ecx
-	mov	%ebx, %eax
-	and	$0x7f, %eax
-	add	%eax, %ecx
-	movd	%xmm0, %eax
-	ALIGN (4)
-L(128bytesormore_shared_cache_loop):
-	prefetcht0	0x3c0(%edx)
-	prefetcht0	0x380(%edx)
-	sub	$0x80, %ebx
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm0, 0x10(%edx)
-	movdqa	%xmm0, 0x20(%edx)
-	movdqa	%xmm0, 0x30(%edx)
-	movdqa	%xmm0, 0x40(%edx)
-	movdqa	%xmm0, 0x50(%edx)
-	movdqa	%xmm0, 0x60(%edx)
-	movdqa	%xmm0, 0x70(%edx)
-	add	$0x80, %edx
-	cmp	$0x80, %ebx
-	jae	L(128bytesormore_shared_cache_loop)
-	cmp	$0x80, %ecx
-	jb	L(shared_cache_loop_end)
-	ALIGN (4)
-L(128bytesormore_nt):
-	sub	$0x80, %ecx
-	movntdq	%xmm0, (%edx)
-	movntdq	%xmm0, 0x10(%edx)
-	movntdq	%xmm0, 0x20(%edx)
-	movntdq	%xmm0, 0x30(%edx)
-	movntdq	%xmm0, 0x40(%edx)
-	movntdq	%xmm0, 0x50(%edx)
-	movntdq	%xmm0, 0x60(%edx)
-	movntdq	%xmm0, 0x70(%edx)
-	add	$0x80, %edx
-	cmp	$0x80, %ecx
-	jae	L(128bytesormore_nt)
-	sfence
-L(shared_cache_loop_end):
-#if defined DATA_CACHE_SIZE || !(defined SHARED || defined __PIC__)
-	POP (%ebx)
-#endif
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
-
-
-	.pushsection .rodata.sse2,"a",@progbits
-	ALIGN (2)
-L(table_16_128bytes):
-	.int	JMPTBL (L(aligned_16_0bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_1bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_2bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_3bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_4bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_5bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_6bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_7bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_8bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_9bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_10bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_11bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_12bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_13bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_14bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_15bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_16bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_17bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_18bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_19bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_20bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_21bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_22bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_23bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_24bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_25bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_26bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_27bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_28bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_29bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_30bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_31bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_32bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_33bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_34bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_35bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_36bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_37bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_38bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_39bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_40bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_41bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_42bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_43bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_44bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_45bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_46bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_47bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_48bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_49bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_50bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_51bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_52bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_53bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_54bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_55bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_56bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_57bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_58bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_59bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_60bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_61bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_62bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_63bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_64bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_65bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_66bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_67bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_68bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_69bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_70bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_71bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_72bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_73bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_74bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_75bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_76bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_77bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_78bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_79bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_80bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_81bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_82bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_83bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_84bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_85bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_86bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_87bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_88bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_89bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_90bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_91bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_92bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_93bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_94bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_95bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_96bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_97bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_98bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_99bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_100bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_101bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_102bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_103bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_104bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_105bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_106bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_107bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_108bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_109bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_110bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_111bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_112bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_113bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_114bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_115bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_116bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_117bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_118bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_119bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_120bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_121bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_122bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_123bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_124bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_125bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_126bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_127bytes), L(table_16_128bytes))
-	.popsection
-
-	ALIGN (4)
-L(aligned_16_112bytes):
-	movdqa	%xmm0, -112(%edx)
-L(aligned_16_96bytes):
-	movdqa	%xmm0, -96(%edx)
-L(aligned_16_80bytes):
-	movdqa	%xmm0, -80(%edx)
-L(aligned_16_64bytes):
-	movdqa	%xmm0, -64(%edx)
-L(aligned_16_48bytes):
-	movdqa	%xmm0, -48(%edx)
-L(aligned_16_32bytes):
-	movdqa	%xmm0, -32(%edx)
-L(aligned_16_16bytes):
-	movdqa	%xmm0, -16(%edx)
-L(aligned_16_0bytes):
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_113bytes):
-	movdqa	%xmm0, -113(%edx)
-L(aligned_16_97bytes):
-	movdqa	%xmm0, -97(%edx)
-L(aligned_16_81bytes):
-	movdqa	%xmm0, -81(%edx)
-L(aligned_16_65bytes):
-	movdqa	%xmm0, -65(%edx)
-L(aligned_16_49bytes):
-	movdqa	%xmm0, -49(%edx)
-L(aligned_16_33bytes):
-	movdqa	%xmm0, -33(%edx)
-L(aligned_16_17bytes):
-	movdqa	%xmm0, -17(%edx)
-L(aligned_16_1bytes):
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_114bytes):
-	movdqa	%xmm0, -114(%edx)
-L(aligned_16_98bytes):
-	movdqa	%xmm0, -98(%edx)
-L(aligned_16_82bytes):
-	movdqa	%xmm0, -82(%edx)
-L(aligned_16_66bytes):
-	movdqa	%xmm0, -66(%edx)
-L(aligned_16_50bytes):
-	movdqa	%xmm0, -50(%edx)
-L(aligned_16_34bytes):
-	movdqa	%xmm0, -34(%edx)
-L(aligned_16_18bytes):
-	movdqa	%xmm0, -18(%edx)
-L(aligned_16_2bytes):
-	movw	%ax, -2(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_115bytes):
-	movdqa	%xmm0, -115(%edx)
-L(aligned_16_99bytes):
-	movdqa	%xmm0, -99(%edx)
-L(aligned_16_83bytes):
-	movdqa	%xmm0, -83(%edx)
-L(aligned_16_67bytes):
-	movdqa	%xmm0, -67(%edx)
-L(aligned_16_51bytes):
-	movdqa	%xmm0, -51(%edx)
-L(aligned_16_35bytes):
-	movdqa	%xmm0, -35(%edx)
-L(aligned_16_19bytes):
-	movdqa	%xmm0, -19(%edx)
-L(aligned_16_3bytes):
-	movw	%ax, -3(%edx)
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_116bytes):
-	movdqa	%xmm0, -116(%edx)
-L(aligned_16_100bytes):
-	movdqa	%xmm0, -100(%edx)
-L(aligned_16_84bytes):
-	movdqa	%xmm0, -84(%edx)
-L(aligned_16_68bytes):
-	movdqa	%xmm0, -68(%edx)
-L(aligned_16_52bytes):
-	movdqa	%xmm0, -52(%edx)
-L(aligned_16_36bytes):
-	movdqa	%xmm0, -36(%edx)
-L(aligned_16_20bytes):
-	movdqa	%xmm0, -20(%edx)
-L(aligned_16_4bytes):
-	movl	%eax, -4(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_117bytes):
-	movdqa	%xmm0, -117(%edx)
-L(aligned_16_101bytes):
-	movdqa	%xmm0, -101(%edx)
-L(aligned_16_85bytes):
-	movdqa	%xmm0, -85(%edx)
-L(aligned_16_69bytes):
-	movdqa	%xmm0, -69(%edx)
-L(aligned_16_53bytes):
-	movdqa	%xmm0, -53(%edx)
-L(aligned_16_37bytes):
-	movdqa	%xmm0, -37(%edx)
-L(aligned_16_21bytes):
-	movdqa	%xmm0, -21(%edx)
-L(aligned_16_5bytes):
-	movl	%eax, -5(%edx)
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_118bytes):
-	movdqa	%xmm0, -118(%edx)
-L(aligned_16_102bytes):
-	movdqa	%xmm0, -102(%edx)
-L(aligned_16_86bytes):
-	movdqa	%xmm0, -86(%edx)
-L(aligned_16_70bytes):
-	movdqa	%xmm0, -70(%edx)
-L(aligned_16_54bytes):
-	movdqa	%xmm0, -54(%edx)
-L(aligned_16_38bytes):
-	movdqa	%xmm0, -38(%edx)
-L(aligned_16_22bytes):
-	movdqa	%xmm0, -22(%edx)
-L(aligned_16_6bytes):
-	movl	%eax, -6(%edx)
-	movw	%ax, -2(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_119bytes):
-	movdqa	%xmm0, -119(%edx)
-L(aligned_16_103bytes):
-	movdqa	%xmm0, -103(%edx)
-L(aligned_16_87bytes):
-	movdqa	%xmm0, -87(%edx)
-L(aligned_16_71bytes):
-	movdqa	%xmm0, -71(%edx)
-L(aligned_16_55bytes):
-	movdqa	%xmm0, -55(%edx)
-L(aligned_16_39bytes):
-	movdqa	%xmm0, -39(%edx)
-L(aligned_16_23bytes):
-	movdqa	%xmm0, -23(%edx)
-L(aligned_16_7bytes):
-	movl	%eax, -7(%edx)
-	movw	%ax, -3(%edx)
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_120bytes):
-	movdqa	%xmm0, -120(%edx)
-L(aligned_16_104bytes):
-	movdqa	%xmm0, -104(%edx)
-L(aligned_16_88bytes):
-	movdqa	%xmm0, -88(%edx)
-L(aligned_16_72bytes):
-	movdqa	%xmm0, -72(%edx)
-L(aligned_16_56bytes):
-	movdqa	%xmm0, -56(%edx)
-L(aligned_16_40bytes):
-	movdqa	%xmm0, -40(%edx)
-L(aligned_16_24bytes):
-	movdqa	%xmm0, -24(%edx)
-L(aligned_16_8bytes):
-	movq	%xmm0, -8(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_121bytes):
-	movdqa	%xmm0, -121(%edx)
-L(aligned_16_105bytes):
-	movdqa	%xmm0, -105(%edx)
-L(aligned_16_89bytes):
-	movdqa	%xmm0, -89(%edx)
-L(aligned_16_73bytes):
-	movdqa	%xmm0, -73(%edx)
-L(aligned_16_57bytes):
-	movdqa	%xmm0, -57(%edx)
-L(aligned_16_41bytes):
-	movdqa	%xmm0, -41(%edx)
-L(aligned_16_25bytes):
-	movdqa	%xmm0, -25(%edx)
-L(aligned_16_9bytes):
-	movq	%xmm0, -9(%edx)
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_122bytes):
-	movdqa	%xmm0, -122(%edx)
-L(aligned_16_106bytes):
-	movdqa	%xmm0, -106(%edx)
-L(aligned_16_90bytes):
-	movdqa	%xmm0, -90(%edx)
-L(aligned_16_74bytes):
-	movdqa	%xmm0, -74(%edx)
-L(aligned_16_58bytes):
-	movdqa	%xmm0, -58(%edx)
-L(aligned_16_42bytes):
-	movdqa	%xmm0, -42(%edx)
-L(aligned_16_26bytes):
-	movdqa	%xmm0, -26(%edx)
-L(aligned_16_10bytes):
-	movq	%xmm0, -10(%edx)
-	movw	%ax, -2(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_123bytes):
-	movdqa	%xmm0, -123(%edx)
-L(aligned_16_107bytes):
-	movdqa	%xmm0, -107(%edx)
-L(aligned_16_91bytes):
-	movdqa	%xmm0, -91(%edx)
-L(aligned_16_75bytes):
-	movdqa	%xmm0, -75(%edx)
-L(aligned_16_59bytes):
-	movdqa	%xmm0, -59(%edx)
-L(aligned_16_43bytes):
-	movdqa	%xmm0, -43(%edx)
-L(aligned_16_27bytes):
-	movdqa	%xmm0, -27(%edx)
-L(aligned_16_11bytes):
-	movq	%xmm0, -11(%edx)
-	movw	%ax, -3(%edx)
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_124bytes):
-	movdqa	%xmm0, -124(%edx)
-L(aligned_16_108bytes):
-	movdqa	%xmm0, -108(%edx)
-L(aligned_16_92bytes):
-	movdqa	%xmm0, -92(%edx)
-L(aligned_16_76bytes):
-	movdqa	%xmm0, -76(%edx)
-L(aligned_16_60bytes):
-	movdqa	%xmm0, -60(%edx)
-L(aligned_16_44bytes):
-	movdqa	%xmm0, -44(%edx)
-L(aligned_16_28bytes):
-	movdqa	%xmm0, -28(%edx)
-L(aligned_16_12bytes):
-	movq	%xmm0, -12(%edx)
-	movl	%eax, -4(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_125bytes):
-	movdqa	%xmm0, -125(%edx)
-L(aligned_16_109bytes):
-	movdqa	%xmm0, -109(%edx)
-L(aligned_16_93bytes):
-	movdqa	%xmm0, -93(%edx)
-L(aligned_16_77bytes):
-	movdqa	%xmm0, -77(%edx)
-L(aligned_16_61bytes):
-	movdqa	%xmm0, -61(%edx)
-L(aligned_16_45bytes):
-	movdqa	%xmm0, -45(%edx)
-L(aligned_16_29bytes):
-	movdqa	%xmm0, -29(%edx)
-L(aligned_16_13bytes):
-	movq	%xmm0, -13(%edx)
-	movl	%eax, -5(%edx)
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_126bytes):
-	movdqa	%xmm0, -126(%edx)
-L(aligned_16_110bytes):
-	movdqa	%xmm0, -110(%edx)
-L(aligned_16_94bytes):
-	movdqa	%xmm0, -94(%edx)
-L(aligned_16_78bytes):
-	movdqa	%xmm0, -78(%edx)
-L(aligned_16_62bytes):
-	movdqa	%xmm0, -62(%edx)
-L(aligned_16_46bytes):
-	movdqa	%xmm0, -46(%edx)
-L(aligned_16_30bytes):
-	movdqa	%xmm0, -30(%edx)
-L(aligned_16_14bytes):
-	movq	%xmm0, -14(%edx)
-	movl	%eax, -6(%edx)
-	movw	%ax, -2(%edx)
-	SETRTNVAL
-	RETURN
-
-	ALIGN (4)
-L(aligned_16_127bytes):
-	movdqa	%xmm0, -127(%edx)
-L(aligned_16_111bytes):
-	movdqa	%xmm0, -111(%edx)
-L(aligned_16_95bytes):
-	movdqa	%xmm0, -95(%edx)
-L(aligned_16_79bytes):
-	movdqa	%xmm0, -79(%edx)
-L(aligned_16_63bytes):
-	movdqa	%xmm0, -63(%edx)
-L(aligned_16_47bytes):
-	movdqa	%xmm0, -47(%edx)
-L(aligned_16_31bytes):
-	movdqa	%xmm0, -31(%edx)
-L(aligned_16_15bytes):
-	movq	%xmm0, -15(%edx)
-	movl	%eax, -7(%edx)
-	movw	%ax, -3(%edx)
-	movb	%al, -1(%edx)
-	SETRTNVAL
-	RETURN_END
-
-END (MEMSET)
diff --git a/libc/arch-x86/string/ssse3-memcmp16-atom.S b/libc/arch-x86/string/ssse3-memcmp16-atom.S
deleted file mode 100644
index 1be8f3d..0000000
--- a/libc/arch-x86/string/ssse3-memcmp16-atom.S
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-Copyright (c) 2013, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-    * Redistributions of source code must retain the above copyright notice,
-    * this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above copyright notice,
-    * this list of conditions and the following disclaimer in the documentation
-    * and/or other materials provided with the distribution.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#define MEMCMP  __memcmp16
-
-/* int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n); */
-
-#define USE_UTF16
-#define USE_AS_MEMCMP16 1
-#include "ssse3-memcmp-atom.S"
diff --git a/libc/arch-x86/string/ssse3-memcpy-atom.S b/libc/arch-x86/string/ssse3-memcpy-atom.S
deleted file mode 100644
index 1080a38..0000000
--- a/libc/arch-x86/string/ssse3-memcpy-atom.S
+++ /dev/null
@@ -1,3200 +0,0 @@
-/*
-Copyright (c) 2010, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-    * Redistributions of source code must retain the above copyright notice,
-    * this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above copyright notice,
-    * this list of conditions and the following disclaimer in the documentation
-    * and/or other materials provided with the distribution.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include "cache.h"
-#undef __i686
-
-#ifndef MEMCPY
-# define MEMCPY	memcpy
-#endif
-
-#ifndef L
-# define L(label)	.L##label
-#endif
-
-#ifndef cfi_startproc
-# define cfi_startproc	.cfi_startproc
-#endif
-
-#ifndef cfi_endproc
-# define cfi_endproc	.cfi_endproc
-#endif
-
-#ifndef cfi_rel_offset
-# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
-#endif
-
-#ifndef cfi_restore
-# define cfi_restore(reg)	.cfi_restore reg
-#endif
-
-#ifndef cfi_adjust_cfa_offset
-# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
-#endif
-
-#ifndef ENTRY
-# define ENTRY(name)		\
-	.type name,  @function;		\
-	.globl name;		\
-	.p2align 4;		\
-name:		\
-	cfi_startproc
-#endif
-
-#ifndef END
-# define END(name)		\
-	cfi_endproc;		\
-	.size name, .-name
-#endif
-
-#ifdef USE_AS_BCOPY
-# define SRC		PARMS
-# define DEST		SRC+4
-# define LEN		DEST+4
-#else
-# define DEST		PARMS
-# define SRC		DEST+4
-# define LEN		SRC+4
-#endif
-
-#define CFI_PUSH(REG)		\
-  cfi_adjust_cfa_offset (4);		\
-  cfi_rel_offset (REG, 0)
-
-#define CFI_POP(REG)		\
-  cfi_adjust_cfa_offset (-4);		\
-  cfi_restore (REG)
-
-#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
-#define POP(REG)	popl REG; CFI_POP (REG)
-
-#if (defined SHARED || defined __PIC__)
-# define PARMS		8		/* Preserve EBX.  */
-# define ENTRANCE	PUSH (%ebx);
-# define RETURN_END	POP (%ebx); ret
-# define RETURN		RETURN_END; CFI_PUSH (%ebx)
-# define JMPTBL(I, B)	I - B
-# undef __i686
-
-# define SETUP_PIC_REG(x)	call	__i686.get_pc_thunk.x
-
-/* Load an entry in a jump table into EBX and branch to it.  TABLE is a
-	jump table with relative offsets.  INDEX is a register contains the
-	index into the jump table.   SCALE is the scale of INDEX. */
-
-# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)		\
-    /* We first load PC into EBX.  */		\
-	SETUP_PIC_REG(bx);		\
-    /* Get the address of the jump table.  */		\
-	addl	$(TABLE - .), %ebx;		\
-    /* Get the entry and convert the relative offset to the		\
-	absolute	address.  */		\
-	addl	(%ebx, INDEX, SCALE), %ebx;		\
-    /* We loaded the jump table.  Go.  */		\
-	jmp	*%ebx
-#else
-
-# define PARMS		4
-# define ENTRANCE
-# define RETURN_END	ret
-# define RETURN		RETURN_END
-# define JMPTBL(I, B)	I
-
-/* Branch to an entry in a jump table.  TABLE is a jump table with
-	absolute offsets.  INDEX is a register contains the index into the
-	jump table.  SCALE is the scale of INDEX. */
-
-# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)		\
-	jmp	*TABLE(, INDEX, SCALE)
-#endif
-
-	.section .text.ssse3,"ax",@progbits
-ENTRY (MEMCPY)
-	ENTRANCE
-	movl	LEN(%esp), %ecx
-	movl	SRC(%esp), %eax
-	movl	DEST(%esp), %edx
-
-#ifdef USE_AS_MEMMOVE
-	cmp	%eax, %edx
-	jb	L(copy_forward)
-	je	L(fwd_write_0bytes)
-	cmp	$32, %ecx
-	jae	L(memmove_bwd)
-	jmp	L(bk_write_less32bytes_2)
-
-	.p2align 4
-L(memmove_bwd):
-	add	%ecx, %eax
-	cmp	%eax, %edx
-	movl	SRC(%esp), %eax
-	jb	L(copy_backward)
-
-L(copy_forward):
-#endif
-	cmp	$48, %ecx
-	jae	L(48bytesormore)
-
-L(fwd_write_less32bytes):
-#ifndef USE_AS_MEMMOVE
-	cmp	%dl, %al
-	jb	L(bk_write)
-#endif
-	add	%ecx, %edx
-	add	%ecx, %eax
-	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd), %ecx, 4)
-#ifndef USE_AS_MEMMOVE
-	.p2align 4
-L(bk_write):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_48_bytes_bwd), %ecx, 4)
-#endif
-
-	.p2align 4
-L(48bytesormore):
-#ifndef USE_AS_MEMMOVE
-	movlpd	(%eax), %xmm0
-	movlpd	8(%eax), %xmm1
-	movlpd	%xmm0, (%edx)
-	movlpd	%xmm1, 8(%edx)
-#else
-	movdqu	(%eax), %xmm0
-#endif
-	PUSH (%edi)
-	movl	%edx, %edi
-	and	$-16, %edx
-	add	$16, %edx
-	sub	%edx, %edi
-	add	%edi, %ecx
-	sub	%edi, %eax
-
-#ifdef SHARED_CACHE_SIZE_HALF
-	cmp	$SHARED_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_shared_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_shared_cache_size_half, %ecx
-# endif
-#endif
-
-	mov	%eax, %edi
-	jae	L(large_page)
-	and	$0xf, %edi
-	jz	L(shl_0)
-	BRANCH_TO_JMPTBL_ENTRY (L(shl_table), %edi, 4)
-
-	.p2align 4
-L(shl_0):
-#ifdef USE_AS_MEMMOVE
-	movl	DEST+4(%esp), %edi
-	movdqu	%xmm0, (%edi)
-#endif
-	xor	%edi, %edi
-	cmp	$127, %ecx
-	ja	L(shl_0_gobble)
-	lea	-32(%ecx), %ecx
-
-	.p2align 4
-L(shl_0_loop):
-	movdqa	(%eax, %edi), %xmm0
-	movdqa	16(%eax, %edi), %xmm1
-	sub	$32, %ecx
-	movdqa	%xmm0, (%edx, %edi)
-	movdqa	%xmm1, 16(%edx, %edi)
-	lea	32(%edi), %edi
-	jb	L(shl_0_end)
-
-	movdqa	(%eax, %edi), %xmm0
-	movdqa	16(%eax, %edi), %xmm1
-	sub	$32, %ecx
-	movdqa	%xmm0, (%edx, %edi)
-	movdqa	%xmm1, 16(%edx, %edi)
-	lea	32(%edi), %edi
-	jb	L(shl_0_end)
-
-	movdqa	(%eax, %edi), %xmm0
-	movdqa	16(%eax, %edi), %xmm1
-	sub	$32, %ecx
-	movdqa	%xmm0, (%edx, %edi)
-	movdqa	%xmm1, 16(%edx, %edi)
-	lea	32(%edi), %edi
-	jb	L(shl_0_end)
-
-	movdqa	(%eax, %edi), %xmm0
-	movdqa	16(%eax, %edi), %xmm1
-	sub	$32, %ecx
-	movdqa	%xmm0, (%edx, %edi)
-	movdqa	%xmm1, 16(%edx, %edi)
-	lea	32(%edi), %edi
-
-L(shl_0_end):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	add	%edi, %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd_align), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_0_gobble):
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	POP	(%edi)
-	lea	-128(%ecx), %ecx
-	jae	L(shl_0_gobble_mem_loop)
-
-	.p2align 4
-L(shl_0_gobble_cache_loop):
-	movdqa	(%eax), %xmm0
-	movdqa	0x10(%eax), %xmm1
-	movdqa	0x20(%eax), %xmm2
-	movdqa	0x30(%eax), %xmm3
-	movdqa	0x40(%eax), %xmm4
-	movdqa	0x50(%eax), %xmm5
-	movdqa	0x60(%eax), %xmm6
-	movdqa	0x70(%eax), %xmm7
-	lea	0x80(%eax), %eax
-	sub	$128, %ecx
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm1, 0x10(%edx)
-	movdqa	%xmm2, 0x20(%edx)
-	movdqa	%xmm3, 0x30(%edx)
-	movdqa	%xmm4, 0x40(%edx)
-	movdqa	%xmm5, 0x50(%edx)
-	movdqa	%xmm6, 0x60(%edx)
-	movdqa	%xmm7, 0x70(%edx)
-	lea	0x80(%edx), %edx
-
-	jae	L(shl_0_gobble_cache_loop)
-	cmp	$-0x40, %ecx
-	lea	0x80(%ecx), %ecx
-	jl	L(shl_0_cache_less_64bytes)
-
-	movdqa	(%eax), %xmm0
-	sub	$0x40, %ecx
-	movdqa	0x10(%eax), %xmm1
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm1, 0x10(%edx)
-	movdqa	0x20(%eax), %xmm0
-	movdqa	0x30(%eax), %xmm1
-	add	$0x40, %eax
-	movdqa	%xmm0, 0x20(%edx)
-	movdqa	%xmm1, 0x30(%edx)
-	add	$0x40, %edx
-
-L(shl_0_cache_less_64bytes):
-	cmp	$0x20, %ecx
-	jb	L(shl_0_cache_less_32bytes)
-	movdqa	(%eax), %xmm0
-	sub	$0x20, %ecx
-	movdqa	0x10(%eax), %xmm1
-	add	$0x20, %eax
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm1, 0x10(%edx)
-	add	$0x20, %edx
-
-L(shl_0_cache_less_32bytes):
-	cmp	$0x10, %ecx
-	jb	L(shl_0_cache_less_16bytes)
-	sub	$0x10, %ecx
-	movdqa	(%eax), %xmm0
-	add	$0x10, %eax
-	movdqa	%xmm0, (%edx)
-	add	$0x10, %edx
-
-L(shl_0_cache_less_16bytes):
-	add	%ecx, %edx
-	add	%ecx, %eax
-	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd), %ecx, 4)
-
-	.p2align 4
-L(shl_0_gobble_mem_loop):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x280(%eax)
-	prefetcht0 0x1c0(%edx)
-
-	movdqa	(%eax), %xmm0
-	movdqa	0x10(%eax), %xmm1
-	movdqa	0x20(%eax), %xmm2
-	movdqa	0x30(%eax), %xmm3
-	movdqa	0x40(%eax), %xmm4
-	movdqa	0x50(%eax), %xmm5
-	movdqa	0x60(%eax), %xmm6
-	movdqa	0x70(%eax), %xmm7
-	lea	0x80(%eax), %eax
-	sub	$0x80, %ecx
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm1, 0x10(%edx)
-	movdqa	%xmm2, 0x20(%edx)
-	movdqa	%xmm3, 0x30(%edx)
-	movdqa	%xmm4, 0x40(%edx)
-	movdqa	%xmm5, 0x50(%edx)
-	movdqa	%xmm6, 0x60(%edx)
-	movdqa	%xmm7, 0x70(%edx)
-	lea	0x80(%edx), %edx
-
-	jae	L(shl_0_gobble_mem_loop)
-	cmp	$-0x40, %ecx
-	lea	0x80(%ecx), %ecx
-	jl	L(shl_0_mem_less_64bytes)
-
-	movdqa	(%eax), %xmm0
-	sub	$0x40, %ecx
-	movdqa	0x10(%eax), %xmm1
-
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm1, 0x10(%edx)
-
-	movdqa	0x20(%eax), %xmm0
-	movdqa	0x30(%eax), %xmm1
-	add	$0x40, %eax
-
-	movdqa	%xmm0, 0x20(%edx)
-	movdqa	%xmm1, 0x30(%edx)
-	add	$0x40, %edx
-
-L(shl_0_mem_less_64bytes):
-	cmp	$0x20, %ecx
-	jb	L(shl_0_mem_less_32bytes)
-	movdqa	(%eax), %xmm0
-	sub	$0x20, %ecx
-	movdqa	0x10(%eax), %xmm1
-	add	$0x20, %eax
-	movdqa	%xmm0, (%edx)
-	movdqa	%xmm1, 0x10(%edx)
-	add	$0x20, %edx
-
-L(shl_0_mem_less_32bytes):
-	cmp	$0x10, %ecx
-	jb	L(shl_0_mem_less_16bytes)
-	sub	$0x10, %ecx
-	movdqa	(%eax), %xmm0
-	add	$0x10, %eax
-	movdqa	%xmm0, (%edx)
-	add	$0x10, %edx
-
-L(shl_0_mem_less_16bytes):
-	add	%ecx, %edx
-	add	%ecx, %eax
-	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd_align), %ecx, 4)
-
-	.p2align 4
-L(shl_1):
-#ifndef USE_AS_MEMMOVE
-	movaps	-1(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-1(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_1_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl1LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	15(%eax), %xmm2
-	movaps	31(%eax), %xmm3
-	movaps	47(%eax), %xmm4
-	movaps	63(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$1, %xmm4, %xmm5
-	palignr	$1, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$1, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$1, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl1LoopStart)
-
-L(Shl1LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	15(%eax), %xmm2
-	movaps	31(%eax), %xmm3
-	palignr	$1, %xmm2, %xmm3
-	palignr	$1, %xmm1, %xmm2
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_1_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-1(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_1_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$1, %xmm2, %xmm3
-	palignr	$1, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_1_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$1, %xmm2, %xmm3
-	palignr	$1, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_1_no_prefetch_loop)
-
-L(sh_1_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	1(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_2):
-#ifndef USE_AS_MEMMOVE
-	movaps	-2(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-2(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_2_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl2LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	14(%eax), %xmm2
-	movaps	30(%eax), %xmm3
-	movaps	46(%eax), %xmm4
-	movaps	62(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$2, %xmm4, %xmm5
-	palignr	$2, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$2, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$2, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl2LoopStart)
-
-L(Shl2LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	14(%eax), %xmm2
-	movaps	30(%eax), %xmm3
-	palignr	$2, %xmm2, %xmm3
-	palignr	$2, %xmm1, %xmm2
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_2_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-2(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_2_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$2, %xmm2, %xmm3
-	palignr	$2, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_2_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$2, %xmm2, %xmm3
-	palignr	$2, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_2_no_prefetch_loop)
-
-L(sh_2_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	2(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_3):
-#ifndef USE_AS_MEMMOVE
-	movaps	-3(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-3(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_3_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl3LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	13(%eax), %xmm2
-	movaps	29(%eax), %xmm3
-	movaps	45(%eax), %xmm4
-	movaps	61(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$3, %xmm4, %xmm5
-	palignr	$3, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$3, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$3, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl3LoopStart)
-
-L(Shl3LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	13(%eax), %xmm2
-	movaps	29(%eax), %xmm3
-	palignr	$3, %xmm2, %xmm3
-	palignr	$3, %xmm1, %xmm2
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_3_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-3(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_3_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$3, %xmm2, %xmm3
-	palignr	$3, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-
-	jb	L(sh_3_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$3, %xmm2, %xmm3
-	palignr	$3, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-
-	jae	L(sh_3_no_prefetch_loop)
-
-L(sh_3_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	3(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_4):
-#ifndef USE_AS_MEMMOVE
-	movaps	-4(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-4(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_4_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl4LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	12(%eax), %xmm2
-	movaps	28(%eax), %xmm3
-	movaps	44(%eax), %xmm4
-	movaps	60(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$4, %xmm4, %xmm5
-	palignr	$4, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$4, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$4, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl4LoopStart)
-
-L(Shl4LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	12(%eax), %xmm2
-	movaps	28(%eax), %xmm3
-	palignr	$4, %xmm2, %xmm3
-	palignr	$4, %xmm1, %xmm2
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_4_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-4(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_4_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$4, %xmm2, %xmm3
-	palignr	$4, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-
-	jb	L(sh_4_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$4, %xmm2, %xmm3
-	palignr	$4, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-
-	jae	L(sh_4_no_prefetch_loop)
-
-L(sh_4_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	4(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_5):
-#ifndef USE_AS_MEMMOVE
-	movaps	-5(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-5(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_5_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl5LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	11(%eax), %xmm2
-	movaps	27(%eax), %xmm3
-	movaps	43(%eax), %xmm4
-	movaps	59(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$5, %xmm4, %xmm5
-	palignr	$5, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$5, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$5, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl5LoopStart)
-
-L(Shl5LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	11(%eax), %xmm2
-	movaps	27(%eax), %xmm3
-	palignr	$5, %xmm2, %xmm3
-	palignr	$5, %xmm1, %xmm2
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_5_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-5(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_5_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$5, %xmm2, %xmm3
-	palignr	$5, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-
-	jb	L(sh_5_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$5, %xmm2, %xmm3
-	palignr	$5, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-
-	jae	L(sh_5_no_prefetch_loop)
-
-L(sh_5_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	5(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_6):
-#ifndef USE_AS_MEMMOVE
-	movaps	-6(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-6(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_6_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl6LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	10(%eax), %xmm2
-	movaps	26(%eax), %xmm3
-	movaps	42(%eax), %xmm4
-	movaps	58(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$6, %xmm4, %xmm5
-	palignr	$6, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$6, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$6, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl6LoopStart)
-
-L(Shl6LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	10(%eax), %xmm2
-	movaps	26(%eax), %xmm3
-	palignr	$6, %xmm2, %xmm3
-	palignr	$6, %xmm1, %xmm2
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_6_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-6(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_6_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$6, %xmm2, %xmm3
-	palignr	$6, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-
-	jb	L(sh_6_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$6, %xmm2, %xmm3
-	palignr	$6, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-
-	jae	L(sh_6_no_prefetch_loop)
-
-L(sh_6_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	6(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_7):
-#ifndef USE_AS_MEMMOVE
-	movaps	-7(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-7(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_7_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl7LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	9(%eax), %xmm2
-	movaps	25(%eax), %xmm3
-	movaps	41(%eax), %xmm4
-	movaps	57(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$7, %xmm4, %xmm5
-	palignr	$7, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$7, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$7, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl7LoopStart)
-
-L(Shl7LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	9(%eax), %xmm2
-	movaps	25(%eax), %xmm3
-	palignr	$7, %xmm2, %xmm3
-	palignr	$7, %xmm1, %xmm2
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_7_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-7(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_7_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$7, %xmm2, %xmm3
-	palignr	$7, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_7_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$7, %xmm2, %xmm3
-	palignr	$7, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_7_no_prefetch_loop)
-
-L(sh_7_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	7(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_8):
-#ifndef USE_AS_MEMMOVE
-	movaps	-8(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-8(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_8_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl8LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	8(%eax), %xmm2
-	movaps	24(%eax), %xmm3
-	movaps	40(%eax), %xmm4
-	movaps	56(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$8, %xmm4, %xmm5
-	palignr	$8, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$8, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$8, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl8LoopStart)
-
-L(LoopLeave8):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	8(%eax), %xmm2
-	movaps	24(%eax), %xmm3
-	palignr	$8, %xmm2, %xmm3
-	palignr	$8, %xmm1, %xmm2
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_8_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-8(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_8_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$8, %xmm2, %xmm3
-	palignr	$8, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_8_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$8, %xmm2, %xmm3
-	palignr	$8, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_8_no_prefetch_loop)
-
-L(sh_8_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	8(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_9):
-#ifndef USE_AS_MEMMOVE
-	movaps	-9(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-9(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_9_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl9LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	7(%eax), %xmm2
-	movaps	23(%eax), %xmm3
-	movaps	39(%eax), %xmm4
-	movaps	55(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$9, %xmm4, %xmm5
-	palignr	$9, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$9, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$9, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl9LoopStart)
-
-L(Shl9LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	7(%eax), %xmm2
-	movaps	23(%eax), %xmm3
-	palignr	$9, %xmm2, %xmm3
-	palignr	$9, %xmm1, %xmm2
-
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_9_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-9(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_9_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$9, %xmm2, %xmm3
-	palignr	$9, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_9_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$9, %xmm2, %xmm3
-	palignr	$9, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_9_no_prefetch_loop)
-
-L(sh_9_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	9(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_10):
-#ifndef USE_AS_MEMMOVE
-	movaps	-10(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-10(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_10_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl10LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	6(%eax), %xmm2
-	movaps	22(%eax), %xmm3
-	movaps	38(%eax), %xmm4
-	movaps	54(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$10, %xmm4, %xmm5
-	palignr	$10, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$10, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$10, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl10LoopStart)
-
-L(Shl10LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	6(%eax), %xmm2
-	movaps	22(%eax), %xmm3
-	palignr	$10, %xmm2, %xmm3
-	palignr	$10, %xmm1, %xmm2
-
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_10_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-10(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_10_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$10, %xmm2, %xmm3
-	palignr	$10, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_10_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$10, %xmm2, %xmm3
-	palignr	$10, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_10_no_prefetch_loop)
-
-L(sh_10_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	10(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_11):
-#ifndef USE_AS_MEMMOVE
-	movaps	-11(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-11(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_11_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl11LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	5(%eax), %xmm2
-	movaps	21(%eax), %xmm3
-	movaps	37(%eax), %xmm4
-	movaps	53(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$11, %xmm4, %xmm5
-	palignr	$11, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$11, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$11, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl11LoopStart)
-
-L(Shl11LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	5(%eax), %xmm2
-	movaps	21(%eax), %xmm3
-	palignr	$11, %xmm2, %xmm3
-	palignr	$11, %xmm1, %xmm2
-
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_11_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-11(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_11_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$11, %xmm2, %xmm3
-	palignr	$11, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_11_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$11, %xmm2, %xmm3
-	palignr	$11, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_11_no_prefetch_loop)
-
-L(sh_11_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	11(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_12):
-#ifndef USE_AS_MEMMOVE
-	movaps	-12(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-12(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_12_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl12LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	4(%eax), %xmm2
-	movaps	20(%eax), %xmm3
-	movaps	36(%eax), %xmm4
-	movaps	52(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$12, %xmm4, %xmm5
-	palignr	$12, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$12, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$12, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl12LoopStart)
-
-L(Shl12LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	4(%eax), %xmm2
-	movaps	20(%eax), %xmm3
-	palignr	$12, %xmm2, %xmm3
-	palignr	$12, %xmm1, %xmm2
-
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_12_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-12(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_12_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$12, %xmm2, %xmm3
-	palignr	$12, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_12_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$12, %xmm2, %xmm3
-	palignr	$12, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_12_no_prefetch_loop)
-
-L(sh_12_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	12(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_13):
-#ifndef USE_AS_MEMMOVE
-	movaps	-13(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-13(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_13_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl13LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	3(%eax), %xmm2
-	movaps	19(%eax), %xmm3
-	movaps	35(%eax), %xmm4
-	movaps	51(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$13, %xmm4, %xmm5
-	palignr	$13, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$13, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$13, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl13LoopStart)
-
-L(Shl13LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	3(%eax), %xmm2
-	movaps	19(%eax), %xmm3
-	palignr	$13, %xmm2, %xmm3
-	palignr	$13, %xmm1, %xmm2
-
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_13_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-13(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_13_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$13, %xmm2, %xmm3
-	palignr	$13, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_13_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$13, %xmm2, %xmm3
-	palignr	$13, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_13_no_prefetch_loop)
-
-L(sh_13_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	13(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_14):
-#ifndef USE_AS_MEMMOVE
-	movaps	-14(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-14(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_14_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl14LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	2(%eax), %xmm2
-	movaps	18(%eax), %xmm3
-	movaps	34(%eax), %xmm4
-	movaps	50(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$14, %xmm4, %xmm5
-	palignr	$14, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$14, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$14, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl14LoopStart)
-
-L(Shl14LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	2(%eax), %xmm2
-	movaps	18(%eax), %xmm3
-	palignr	$14, %xmm2, %xmm3
-	palignr	$14, %xmm1, %xmm2
-
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_14_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-14(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_14_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$14, %xmm2, %xmm3
-	palignr	$14, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_14_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$14, %xmm2, %xmm3
-	palignr	$14, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_14_no_prefetch_loop)
-
-L(sh_14_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	14(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_15):
-#ifndef USE_AS_MEMMOVE
-	movaps	-15(%eax), %xmm1
-#else
-	movl	DEST+4(%esp), %edi
-	movaps	-15(%eax), %xmm1
-	movdqu	%xmm0, (%edi)
-#endif
-#ifdef DATA_CACHE_SIZE_HALF
-	cmp	$DATA_CACHE_SIZE_HALF, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-	SETUP_PIC_REG(bx)
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size_half@GOTOFF(%ebx), %ecx
-# else
-	cmp	__x86_data_cache_size_half, %ecx
-# endif
-#endif
-	jb L(sh_15_no_prefetch)
-
-	lea	-64(%ecx), %ecx
-
-	.p2align 4
-L(Shl15LoopStart):
-	prefetcht0 0x1c0(%eax)
-	prefetcht0 0x1c0(%edx)
-	movaps	1(%eax), %xmm2
-	movaps	17(%eax), %xmm3
-	movaps	33(%eax), %xmm4
-	movaps	49(%eax), %xmm5
-	movaps	%xmm5, %xmm7
-	palignr	$15, %xmm4, %xmm5
-	palignr	$15, %xmm3, %xmm4
-	movaps	%xmm5, 48(%edx)
-	palignr	$15, %xmm2, %xmm3
-	lea	64(%eax), %eax
-	palignr	$15, %xmm1, %xmm2
-	movaps	%xmm4, 32(%edx)
-	movaps	%xmm3, 16(%edx)
-	movaps	%xmm7, %xmm1
-	movaps	%xmm2, (%edx)
-	lea	64(%edx), %edx
-	sub	$64, %ecx
-	ja	L(Shl15LoopStart)
-
-L(Shl15LoopLeave):
-	add	$32, %ecx
-	jle	L(shl_end_0)
-
-	movaps	1(%eax), %xmm2
-	movaps	17(%eax), %xmm3
-	palignr	$15, %xmm2, %xmm3
-	palignr	$15, %xmm1, %xmm2
-
-	movaps	%xmm2, (%edx)
-	movaps	%xmm3, 16(%edx)
-	lea	32(%edx, %ecx), %edx
-	lea	32(%eax, %ecx), %eax
-	POP (%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(sh_15_no_prefetch):
-	lea	-32(%ecx), %ecx
-	lea	-15(%eax), %eax
-	xor	%edi, %edi
-
-	.p2align 4
-L(sh_15_no_prefetch_loop):
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm4
-	palignr	$15, %xmm2, %xmm3
-	palignr	$15, %xmm1, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jb	L(sh_15_end_no_prefetch_loop)
-
-	movdqa	16(%eax, %edi), %xmm2
-	sub	$32, %ecx
-	movdqa	32(%eax, %edi), %xmm3
-	movdqa	%xmm3, %xmm1
-	palignr	$15, %xmm2, %xmm3
-	palignr	$15, %xmm4, %xmm2
-	lea	32(%edi), %edi
-	movdqa	%xmm2, -32(%edx, %edi)
-	movdqa	%xmm3, -16(%edx, %edi)
-	jae	L(sh_15_no_prefetch_loop)
-
-L(sh_15_end_no_prefetch_loop):
-	lea	32(%ecx), %ecx
-	add	%ecx, %edi
-	add	%edi, %edx
-	lea	15(%edi, %eax), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(shl_end_0):
-	lea	32(%ecx), %ecx
-	lea	(%edx, %ecx), %edx
-	lea	(%eax, %ecx), %eax
-	POP	(%edi)
-	BRANCH_TO_JMPTBL_ENTRY(L(table_48bytes_fwd), %ecx, 4)
-
-	.p2align 4
-L(fwd_write_44bytes):
-	movq	-44(%eax), %xmm0
-	movq	%xmm0, -44(%edx)
-L(fwd_write_36bytes):
-	movq	-36(%eax), %xmm0
-	movq	%xmm0, -36(%edx)
-L(fwd_write_28bytes):
-	movq	-28(%eax), %xmm0
-	movq	%xmm0, -28(%edx)
-L(fwd_write_20bytes):
-	movq	-20(%eax), %xmm0
-	movq	%xmm0, -20(%edx)
-L(fwd_write_12bytes):
-	movq	-12(%eax), %xmm0
-	movq	%xmm0, -12(%edx)
-L(fwd_write_4bytes):
-	movl	-4(%eax), %ecx
-	movl	%ecx, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_40bytes):
-	movq	-40(%eax), %xmm0
-	movq	%xmm0, -40(%edx)
-L(fwd_write_32bytes):
-	movq	-32(%eax), %xmm0
-	movq	%xmm0, -32(%edx)
-L(fwd_write_24bytes):
-	movq	-24(%eax), %xmm0
-	movq	%xmm0, -24(%edx)
-L(fwd_write_16bytes):
-	movq	-16(%eax), %xmm0
-	movq	%xmm0, -16(%edx)
-L(fwd_write_8bytes):
-	movq	-8(%eax), %xmm0
-	movq	%xmm0, -8(%edx)
-L(fwd_write_0bytes):
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_5bytes):
-	movl	-5(%eax), %ecx
-	movl	-4(%eax), %eax
-	movl	%ecx, -5(%edx)
-	movl	%eax, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_45bytes):
-	movq	-45(%eax), %xmm0
-	movq	%xmm0, -45(%edx)
-L(fwd_write_37bytes):
-	movq	-37(%eax), %xmm0
-	movq	%xmm0, -37(%edx)
-L(fwd_write_29bytes):
-	movq	-29(%eax), %xmm0
-	movq	%xmm0, -29(%edx)
-L(fwd_write_21bytes):
-	movq	-21(%eax), %xmm0
-	movq	%xmm0, -21(%edx)
-L(fwd_write_13bytes):
-	movq	-13(%eax), %xmm0
-	movq	%xmm0, -13(%edx)
-	movl	-5(%eax), %ecx
-	movl	%ecx, -5(%edx)
-	movzbl	-1(%eax), %ecx
-	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_41bytes):
-	movq	-41(%eax), %xmm0
-	movq	%xmm0, -41(%edx)
-L(fwd_write_33bytes):
-	movq	-33(%eax), %xmm0
-	movq	%xmm0, -33(%edx)
-L(fwd_write_25bytes):
-	movq	-25(%eax), %xmm0
-	movq	%xmm0, -25(%edx)
-L(fwd_write_17bytes):
-	movq	-17(%eax), %xmm0
-	movq	%xmm0, -17(%edx)
-L(fwd_write_9bytes):
-	movq	-9(%eax), %xmm0
-	movq	%xmm0, -9(%edx)
-L(fwd_write_1bytes):
-	movzbl	-1(%eax), %ecx
-	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_46bytes):
-	movq	-46(%eax), %xmm0
-	movq	%xmm0, -46(%edx)
-L(fwd_write_38bytes):
-	movq	-38(%eax), %xmm0
-	movq	%xmm0, -38(%edx)
-L(fwd_write_30bytes):
-	movq	-30(%eax), %xmm0
-	movq	%xmm0, -30(%edx)
-L(fwd_write_22bytes):
-	movq	-22(%eax), %xmm0
-	movq	%xmm0, -22(%edx)
-L(fwd_write_14bytes):
-	movq	-14(%eax), %xmm0
-	movq	%xmm0, -14(%edx)
-L(fwd_write_6bytes):
-	movl	-6(%eax), %ecx
-	movl	%ecx, -6(%edx)
-	movzwl	-2(%eax), %ecx
-	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_42bytes):
-	movq	-42(%eax), %xmm0
-	movq	%xmm0, -42(%edx)
-L(fwd_write_34bytes):
-	movq	-34(%eax), %xmm0
-	movq	%xmm0, -34(%edx)
-L(fwd_write_26bytes):
-	movq	-26(%eax), %xmm0
-	movq	%xmm0, -26(%edx)
-L(fwd_write_18bytes):
-	movq	-18(%eax), %xmm0
-	movq	%xmm0, -18(%edx)
-L(fwd_write_10bytes):
-	movq	-10(%eax), %xmm0
-	movq	%xmm0, -10(%edx)
-L(fwd_write_2bytes):
-	movzwl	-2(%eax), %ecx
-	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_47bytes):
-	movq	-47(%eax), %xmm0
-	movq	%xmm0, -47(%edx)
-L(fwd_write_39bytes):
-	movq	-39(%eax), %xmm0
-	movq	%xmm0, -39(%edx)
-L(fwd_write_31bytes):
-	movq	-31(%eax), %xmm0
-	movq	%xmm0, -31(%edx)
-L(fwd_write_23bytes):
-	movq	-23(%eax), %xmm0
-	movq	%xmm0, -23(%edx)
-L(fwd_write_15bytes):
-	movq	-15(%eax), %xmm0
-	movq	%xmm0, -15(%edx)
-L(fwd_write_7bytes):
-	movl	-7(%eax), %ecx
-	movl	%ecx, -7(%edx)
-	movzwl	-3(%eax), %ecx
-	movzbl	-1(%eax), %eax
-	movw	%cx, -3(%edx)
-	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_43bytes):
-	movq	-43(%eax), %xmm0
-	movq	%xmm0, -43(%edx)
-L(fwd_write_35bytes):
-	movq	-35(%eax), %xmm0
-	movq	%xmm0, -35(%edx)
-L(fwd_write_27bytes):
-	movq	-27(%eax), %xmm0
-	movq	%xmm0, -27(%edx)
-L(fwd_write_19bytes):
-	movq	-19(%eax), %xmm0
-	movq	%xmm0, -19(%edx)
-L(fwd_write_11bytes):
-	movq	-11(%eax), %xmm0
-	movq	%xmm0, -11(%edx)
-L(fwd_write_3bytes):
-	movzwl	-3(%eax), %ecx
-	movzbl	-1(%eax), %eax
-	movw	%cx, -3(%edx)
-	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_40bytes_align):
-	movdqa	-40(%eax), %xmm0
-	movdqa	%xmm0, -40(%edx)
-L(fwd_write_24bytes_align):
-	movdqa	-24(%eax), %xmm0
-	movdqa	%xmm0, -24(%edx)
-L(fwd_write_8bytes_align):
-	movq	-8(%eax), %xmm0
-	movq	%xmm0, -8(%edx)
-L(fwd_write_0bytes_align):
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_32bytes_align):
-	movdqa	-32(%eax), %xmm0
-	movdqa	%xmm0, -32(%edx)
-L(fwd_write_16bytes_align):
-	movdqa	-16(%eax), %xmm0
-	movdqa	%xmm0, -16(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_5bytes_align):
-	movl	-5(%eax), %ecx
-	movl	-4(%eax), %eax
-	movl	%ecx, -5(%edx)
-	movl	%eax, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_45bytes_align):
-	movdqa	-45(%eax), %xmm0
-	movdqa	%xmm0, -45(%edx)
-L(fwd_write_29bytes_align):
-	movdqa	-29(%eax), %xmm0
-	movdqa	%xmm0, -29(%edx)
-L(fwd_write_13bytes_align):
-	movq	-13(%eax), %xmm0
-	movq	%xmm0, -13(%edx)
-	movl	-5(%eax), %ecx
-	movl	%ecx, -5(%edx)
-	movzbl	-1(%eax), %ecx
-	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_37bytes_align):
-	movdqa	-37(%eax), %xmm0
-	movdqa	%xmm0, -37(%edx)
-L(fwd_write_21bytes_align):
-	movdqa	-21(%eax), %xmm0
-	movdqa	%xmm0, -21(%edx)
-	movl	-5(%eax), %ecx
-	movl	%ecx, -5(%edx)
-	movzbl	-1(%eax), %ecx
-	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_41bytes_align):
-	movdqa	-41(%eax), %xmm0
-	movdqa	%xmm0, -41(%edx)
-L(fwd_write_25bytes_align):
-	movdqa	-25(%eax), %xmm0
-	movdqa	%xmm0, -25(%edx)
-L(fwd_write_9bytes_align):
-	movq	-9(%eax), %xmm0
-	movq	%xmm0, -9(%edx)
-L(fwd_write_1bytes_align):
-	movzbl	-1(%eax), %ecx
-	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_33bytes_align):
-	movdqa	-33(%eax), %xmm0
-	movdqa	%xmm0, -33(%edx)
-L(fwd_write_17bytes_align):
-	movdqa	-17(%eax), %xmm0
-	movdqa	%xmm0, -17(%edx)
-	movzbl	-1(%eax), %ecx
-	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_46bytes_align):
-	movdqa	-46(%eax), %xmm0
-	movdqa	%xmm0, -46(%edx)
-L(fwd_write_30bytes_align):
-	movdqa	-30(%eax), %xmm0
-	movdqa	%xmm0, -30(%edx)
-L(fwd_write_14bytes_align):
-	movq	-14(%eax), %xmm0
-	movq	%xmm0, -14(%edx)
-L(fwd_write_6bytes_align):
-	movl	-6(%eax), %ecx
-	movl	%ecx, -6(%edx)
-	movzwl	-2(%eax), %ecx
-	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_38bytes_align):
-	movdqa	-38(%eax), %xmm0
-	movdqa	%xmm0, -38(%edx)
-L(fwd_write_22bytes_align):
-	movdqa	-22(%eax), %xmm0
-	movdqa	%xmm0, -22(%edx)
-	movl	-6(%eax), %ecx
-	movl	%ecx, -6(%edx)
-	movzwl	-2(%eax), %ecx
-	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_42bytes_align):
-	movdqa	-42(%eax), %xmm0
-	movdqa	%xmm0, -42(%edx)
-L(fwd_write_26bytes_align):
-	movdqa	-26(%eax), %xmm0
-	movdqa	%xmm0, -26(%edx)
-L(fwd_write_10bytes_align):
-	movq	-10(%eax), %xmm0
-	movq	%xmm0, -10(%edx)
-L(fwd_write_2bytes_align):
-	movzwl	-2(%eax), %ecx
-	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_34bytes_align):
-	movdqa	-34(%eax), %xmm0
-	movdqa	%xmm0, -34(%edx)
-L(fwd_write_18bytes_align):
-	movdqa	-18(%eax), %xmm0
-	movdqa	%xmm0, -18(%edx)
-	movzwl	-2(%eax), %ecx
-	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_47bytes_align):
-	movdqa	-47(%eax), %xmm0
-	movdqa	%xmm0, -47(%edx)
-L(fwd_write_31bytes_align):
-	movdqa	-31(%eax), %xmm0
-	movdqa	%xmm0, -31(%edx)
-L(fwd_write_15bytes_align):
-	movq	-15(%eax), %xmm0
-	movq	%xmm0, -15(%edx)
-L(fwd_write_7bytes_align):
-	movl	-7(%eax), %ecx
-	movl	%ecx, -7(%edx)
-	movzwl	-3(%eax), %ecx
-	movzbl	-1(%eax), %eax
-	movw	%cx, -3(%edx)
-	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_39bytes_align):
-	movdqa	-39(%eax), %xmm0
-	movdqa	%xmm0, -39(%edx)
-L(fwd_write_23bytes_align):
-	movdqa	-23(%eax), %xmm0
-	movdqa	%xmm0, -23(%edx)
-	movl	-7(%eax), %ecx
-	movl	%ecx, -7(%edx)
-	movzwl	-3(%eax), %ecx
-	movzbl	-1(%eax), %eax
-	movw	%cx, -3(%edx)
-	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_43bytes_align):
-	movdqa	-43(%eax), %xmm0
-	movdqa	%xmm0, -43(%edx)
-L(fwd_write_27bytes_align):
-	movdqa	-27(%eax), %xmm0
-	movdqa	%xmm0, -27(%edx)
-L(fwd_write_11bytes_align):
-	movq	-11(%eax), %xmm0
-	movq	%xmm0, -11(%edx)
-L(fwd_write_3bytes_align):
-	movzwl	-3(%eax), %ecx
-	movzbl	-1(%eax), %eax
-	movw	%cx, -3(%edx)
-	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_35bytes_align):
-	movdqa	-35(%eax), %xmm0
-	movdqa	%xmm0, -35(%edx)
-L(fwd_write_19bytes_align):
-	movdqa	-19(%eax), %xmm0
-	movdqa	%xmm0, -19(%edx)
-	movzwl	-3(%eax), %ecx
-	movzbl	-1(%eax), %eax
-	movw	%cx, -3(%edx)
-	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_44bytes_align):
-	movdqa	-44(%eax), %xmm0
-	movdqa	%xmm0, -44(%edx)
-L(fwd_write_28bytes_align):
-	movdqa	-28(%eax), %xmm0
-	movdqa	%xmm0, -28(%edx)
-L(fwd_write_12bytes_align):
-	movq	-12(%eax), %xmm0
-	movq	%xmm0, -12(%edx)
-L(fwd_write_4bytes_align):
-	movl	-4(%eax), %ecx
-	movl	%ecx, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(fwd_write_36bytes_align):
-	movdqa	-36(%eax), %xmm0
-	movdqa	%xmm0, -36(%edx)
-L(fwd_write_20bytes_align):
-	movdqa	-20(%eax), %xmm0
-	movdqa	%xmm0, -20(%edx)
-	movl	-4(%eax), %ecx
-	movl	%ecx, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
-	movl	%edx, %eax
-# else
-	movl	DEST(%esp), %eax
-# endif
-#endif
-	RETURN_END
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(large_page):
-	movdqu	(%eax), %xmm1
-#ifdef USE_AS_MEMMOVE
-	movl	DEST+4(%esp), %edi
-	movdqu	%xmm0, (%edi)
-#endif
-	lea	16(%eax), %eax
-	movntdq	%xmm1, (%edx)
-	lea	16(%edx), %edx
-	lea	-0x90(%ecx), %ecx
-	POP (%edi)
-
-	.p2align 4
-L(large_page_loop):
-	movdqu	(%eax), %xmm0
-	movdqu	0x10(%eax), %xmm1
-	movdqu	0x20(%eax), %xmm2
-	movdqu	0x30(%eax), %xmm3
-	movdqu	0x40(%eax), %xmm4
-	movdqu	0x50(%eax), %xmm5
-	movdqu	0x60(%eax), %xmm6
-	movdqu	0x70(%eax), %xmm7
-	lea	0x80(%eax), %eax
-
-	sub	$0x80, %ecx
-	movntdq	%xmm0, (%edx)
-	movntdq	%xmm1, 0x10(%edx)
-	movntdq	%xmm2, 0x20(%edx)
-	movntdq	%xmm3, 0x30(%edx)
-	movntdq	%xmm4, 0x40(%edx)
-	movntdq	%xmm5, 0x50(%edx)
-	movntdq	%xmm6, 0x60(%edx)
-	movntdq	%xmm7, 0x70(%edx)
-	lea	0x80(%edx), %edx
-	jae	L(large_page_loop)
-	cmp	$-0x40, %ecx
-	lea	0x80(%ecx), %ecx
-	jl	L(large_page_less_64bytes)
-
-	movdqu	(%eax), %xmm0
-	movdqu	0x10(%eax), %xmm1
-	movdqu	0x20(%eax), %xmm2
-	movdqu	0x30(%eax), %xmm3
-	lea	0x40(%eax), %eax
-
-	movntdq	%xmm0, (%edx)
-	movntdq	%xmm1, 0x10(%edx)
-	movntdq	%xmm2, 0x20(%edx)
-	movntdq	%xmm3, 0x30(%edx)
-	lea	0x40(%edx), %edx
-	sub	$0x40, %ecx
-L(large_page_less_64bytes):
-	cmp	$32, %ecx
-	jb	L(large_page_less_32bytes)
-	movdqu	(%eax), %xmm0
-	movdqu	0x10(%eax), %xmm1
-	lea	0x20(%eax), %eax
-	movntdq	%xmm0, (%edx)
-	movntdq	%xmm1, 0x10(%edx)
-	lea	0x20(%edx), %edx
-	sub	$0x20, %ecx
-L(large_page_less_32bytes):
-	add	%ecx, %edx
-	add	%ecx, %eax
-	sfence
-	BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd), %ecx, 4)
-
-	.p2align 4
-L(bk_write_44bytes):
-	movq	36(%eax), %xmm0
-	movq	%xmm0, 36(%edx)
-L(bk_write_36bytes):
-	movq	28(%eax), %xmm0
-	movq	%xmm0, 28(%edx)
-L(bk_write_28bytes):
-	movq	20(%eax), %xmm0
-	movq	%xmm0, 20(%edx)
-L(bk_write_20bytes):
-	movq	12(%eax), %xmm0
-	movq	%xmm0, 12(%edx)
-L(bk_write_12bytes):
-	movq	4(%eax), %xmm0
-	movq	%xmm0, 4(%edx)
-L(bk_write_4bytes):
-	movl	(%eax), %ecx
-	movl	%ecx, (%edx)
-L(bk_write_0bytes):
-#ifndef USE_AS_BCOPY
-	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
-	movl	LEN(%esp), %ecx
-	add	%ecx, %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(bk_write_40bytes):
-	movq	32(%eax), %xmm0
-	movq	%xmm0, 32(%edx)
-L(bk_write_32bytes):
-	movq	24(%eax), %xmm0
-	movq	%xmm0, 24(%edx)
-L(bk_write_24bytes):
-	movq	16(%eax), %xmm0
-	movq	%xmm0, 16(%edx)
-L(bk_write_16bytes):
-	movq	8(%eax), %xmm0
-	movq	%xmm0, 8(%edx)
-L(bk_write_8bytes):
-	movq	(%eax), %xmm0
-	movq	%xmm0, (%edx)
-#ifndef USE_AS_BCOPY
-	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
-	movl	LEN(%esp), %ecx
-	add	%ecx, %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(bk_write_45bytes):
-	movq	37(%eax), %xmm0
-	movq	%xmm0, 37(%edx)
-L(bk_write_37bytes):
-	movq	29(%eax), %xmm0
-	movq	%xmm0, 29(%edx)
-L(bk_write_29bytes):
-	movq	21(%eax), %xmm0
-	movq	%xmm0, 21(%edx)
-L(bk_write_21bytes):
-	movq	13(%eax), %xmm0
-	movq	%xmm0, 13(%edx)
-L(bk_write_13bytes):
-	movq	5(%eax), %xmm0
-	movq	%xmm0, 5(%edx)
-L(bk_write_5bytes):
-	movl	1(%eax), %ecx
-	movl	%ecx, 1(%edx)
-L(bk_write_1bytes):
-	movzbl	(%eax), %ecx
-	movb	%cl, (%edx)
-#ifndef USE_AS_BCOPY
-	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
-	movl	LEN(%esp), %ecx
-	add	%ecx, %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(bk_write_41bytes):
-	movq	33(%eax), %xmm0
-	movq	%xmm0, 33(%edx)
-L(bk_write_33bytes):
-	movq	25(%eax), %xmm0
-	movq	%xmm0, 25(%edx)
-L(bk_write_25bytes):
-	movq	17(%eax), %xmm0
-	movq	%xmm0, 17(%edx)
-L(bk_write_17bytes):
-	movq	9(%eax), %xmm0
-	movq	%xmm0, 9(%edx)
-L(bk_write_9bytes):
-	movq	1(%eax), %xmm0
-	movq	%xmm0, 1(%edx)
-	movzbl	(%eax), %ecx
-	movb	%cl, (%edx)
-#ifndef USE_AS_BCOPY
-	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
-	movl	LEN(%esp), %ecx
-	add	%ecx, %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(bk_write_46bytes):
-	movq	38(%eax), %xmm0
-	movq	%xmm0, 38(%edx)
-L(bk_write_38bytes):
-	movq	30(%eax), %xmm0
-	movq	%xmm0, 30(%edx)
-L(bk_write_30bytes):
-	movq	22(%eax), %xmm0
-	movq	%xmm0, 22(%edx)
-L(bk_write_22bytes):
-	movq	14(%eax), %xmm0
-	movq	%xmm0, 14(%edx)
-L(bk_write_14bytes):
-	movq	6(%eax), %xmm0
-	movq	%xmm0, 6(%edx)
-L(bk_write_6bytes):
-	movl	2(%eax), %ecx
-	movl	%ecx, 2(%edx)
-	movzwl	(%eax), %ecx
-	movw	%cx, (%edx)
-#ifndef USE_AS_BCOPY
-	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
-	movl	LEN(%esp), %ecx
-	add	%ecx, %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(bk_write_42bytes):
-	movq	34(%eax), %xmm0
-	movq	%xmm0, 34(%edx)
-L(bk_write_34bytes):
-	movq	26(%eax), %xmm0
-	movq	%xmm0, 26(%edx)
-L(bk_write_26bytes):
-	movq	18(%eax), %xmm0
-	movq	%xmm0, 18(%edx)
-L(bk_write_18bytes):
-	movq	10(%eax), %xmm0
-	movq	%xmm0, 10(%edx)
-L(bk_write_10bytes):
-	movq	2(%eax), %xmm0
-	movq	%xmm0, 2(%edx)
-L(bk_write_2bytes):
-	movzwl	(%eax), %ecx
-	movw	%cx, (%edx)
-#ifndef USE_AS_BCOPY
-	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
-	movl	LEN(%esp), %ecx
-	add	%ecx, %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(bk_write_47bytes):
-	movq	39(%eax), %xmm0
-	movq	%xmm0, 39(%edx)
-L(bk_write_39bytes):
-	movq	31(%eax), %xmm0
-	movq	%xmm0, 31(%edx)
-L(bk_write_31bytes):
-	movq	23(%eax), %xmm0
-	movq	%xmm0, 23(%edx)
-L(bk_write_23bytes):
-	movq	15(%eax), %xmm0
-	movq	%xmm0, 15(%edx)
-L(bk_write_15bytes):
-	movq	7(%eax), %xmm0
-	movq	%xmm0, 7(%edx)
-L(bk_write_7bytes):
-	movl	3(%eax), %ecx
-	movl	%ecx, 3(%edx)
-	movzwl	1(%eax), %ecx
-	movw	%cx, 1(%edx)
-	movzbl	(%eax), %eax
-	movb	%al, (%edx)
-#ifndef USE_AS_BCOPY
-	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
-	movl	LEN(%esp), %ecx
-	add	%ecx, %eax
-# endif
-#endif
-	RETURN
-
-	.p2align 4
-L(bk_write_43bytes):
-	movq	35(%eax), %xmm0
-	movq	%xmm0, 35(%edx)
-L(bk_write_35bytes):
-	movq	27(%eax), %xmm0
-	movq	%xmm0, 27(%edx)
-L(bk_write_27bytes):
-	movq	19(%eax), %xmm0
-	movq	%xmm0, 19(%edx)
-L(bk_write_19bytes):
-	movq	11(%eax), %xmm0
-	movq	%xmm0, 11(%edx)
-L(bk_write_11bytes):
-	movq	3(%eax), %xmm0
-	movq	%xmm0, 3(%edx)
-L(bk_write_3bytes):
-	movzwl	1(%eax), %ecx
-	movw	%cx, 1(%edx)
-	movzbl	(%eax), %eax
-	movb	%al, (%edx)
-#ifndef USE_AS_BCOPY
-	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
-	movl	LEN(%esp), %ecx
-	add	%ecx, %eax
-# endif
-#endif
-	RETURN_END
-
-
-	.pushsection .rodata.ssse3,"a",@progbits
-	.p2align 2
-L(table_48bytes_fwd):
-	.int	JMPTBL (L(fwd_write_0bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_1bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_2bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_3bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_4bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_5bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_6bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_7bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_8bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_9bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_10bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_11bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_12bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_13bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_14bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_15bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_16bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_17bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_18bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_19bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_20bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_21bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_22bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_23bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_24bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_25bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_26bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_27bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_28bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_29bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_30bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_31bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_32bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_33bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_34bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_35bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_36bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_37bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_38bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_39bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_40bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_41bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_42bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_43bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_44bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_45bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_46bytes), L(table_48bytes_fwd))
-	.int	JMPTBL (L(fwd_write_47bytes), L(table_48bytes_fwd))
-
-	.p2align 2
-L(table_48bytes_fwd_align):
-	.int	JMPTBL (L(fwd_write_0bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_1bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_2bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_3bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_4bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_5bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_6bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_7bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_8bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_9bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_10bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_11bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_12bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_13bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_14bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_15bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_16bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_17bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_18bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_19bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_20bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_21bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_22bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_23bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_24bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_25bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_26bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_27bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_28bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_29bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_30bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_31bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_32bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_33bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_34bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_35bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_36bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_37bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_38bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_39bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_40bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_41bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_42bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_43bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_44bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_45bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_46bytes_align), L(table_48bytes_fwd_align))
-	.int	JMPTBL (L(fwd_write_47bytes_align), L(table_48bytes_fwd_align))
-
-	.p2align 2
-L(shl_table):
-	.int	JMPTBL (L(shl_0), L(shl_table))
-	.int	JMPTBL (L(shl_1), L(shl_table))
-	.int	JMPTBL (L(shl_2), L(shl_table))
-	.int	JMPTBL (L(shl_3), L(shl_table))
-	.int	JMPTBL (L(shl_4), L(shl_table))
-	.int	JMPTBL (L(shl_5), L(shl_table))
-	.int	JMPTBL (L(shl_6), L(shl_table))
-	.int	JMPTBL (L(shl_7), L(shl_table))
-	.int	JMPTBL (L(shl_8), L(shl_table))
-	.int	JMPTBL (L(shl_9), L(shl_table))
-	.int	JMPTBL (L(shl_10), L(shl_table))
-	.int	JMPTBL (L(shl_11), L(shl_table))
-	.int	JMPTBL (L(shl_12), L(shl_table))
-	.int	JMPTBL (L(shl_13), L(shl_table))
-	.int	JMPTBL (L(shl_14), L(shl_table))
-	.int	JMPTBL (L(shl_15), L(shl_table))
-
-	.p2align 2
-L(table_48_bytes_bwd):
-	.int	JMPTBL (L(bk_write_0bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_1bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_2bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_3bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_4bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_5bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_6bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_7bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_8bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_9bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_10bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_11bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_12bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_13bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_14bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_15bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_16bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_17bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_18bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_19bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_20bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_21bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_22bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_23bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_24bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_25bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_26bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_27bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_28bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_29bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_30bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_31bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_32bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_33bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_34bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_35bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_36bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_37bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_38bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_39bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_40bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_41bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_42bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_43bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_44bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_45bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_46bytes), L(table_48_bytes_bwd))
-	.int	JMPTBL (L(bk_write_47bytes), L(table_48_bytes_bwd))
-
-	.popsection
-
-#ifdef USE_AS_MEMMOVE
-	.p2align 4
-L(copy_backward):
-	PUSH (%edi)
-	movl	%eax, %edi
-	lea	(%ecx,%edx,1),%edx
-	lea	(%ecx,%edi,1),%edi
-	testl	$0x3, %edx
-	jnz	L(bk_align)
-
-L(bk_aligned_4):
-	cmp	$64, %ecx
-	jae	L(bk_write_more64bytes)
-
-L(bk_write_64bytesless):
-	cmp	$32, %ecx
-	jb	L(bk_write_less32bytes)
-
-L(bk_write_more32bytes):
-	/* Copy 32 bytes at a time.  */
-	sub	$32, %ecx
-	movq	-8(%edi), %xmm0
-	movq	%xmm0, -8(%edx)
-	movq	-16(%edi), %xmm0
-	movq	%xmm0, -16(%edx)
-	movq	-24(%edi), %xmm0
-	movq	%xmm0, -24(%edx)
-	movq	-32(%edi), %xmm0
-	movq	%xmm0, -32(%edx)
-	sub	$32, %edx
-	sub	$32, %edi
-
-L(bk_write_less32bytes):
-	movl	%edi, %eax
-	sub	%ecx, %edx
-	sub	%ecx, %eax
-	POP (%edi)
-L(bk_write_less32bytes_2):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_48_bytes_bwd), %ecx, 4)
-
-	CFI_PUSH (%edi)
-
-	.p2align 4
-L(bk_align):
-	cmp	$8, %ecx
-	jbe	L(bk_write_less32bytes)
-	testl	$1, %edx
-	/* We get here only if (EDX & 3 ) != 0 so if (EDX & 1) ==0,
-	then	(EDX & 2) must be != 0.  */
-	jz	L(bk_got2)
-	sub	$1, %edi
-	sub	$1, %ecx
-	sub	$1, %edx
-	movzbl	(%edi), %eax
-	movb	%al, (%edx)
-
-	testl	$2, %edx
-	jz	L(bk_aligned_4)
-
-L(bk_got2):
-	sub	$2, %edi
-	sub	$2, %ecx
-	sub	$2, %edx
-	movzwl	(%edi), %eax
-	movw	%ax, (%edx)
-	jmp	L(bk_aligned_4)
-
-	.p2align 4
-L(bk_write_more64bytes):
-	/* Check alignment of last byte.  */
-	testl	$15, %edx
-	jz	L(bk_ssse3_cpy_pre)
-
-/* EDX is aligned 4 bytes, but not 16 bytes.  */
-L(bk_ssse3_align):
-	sub	$4, %edi
-	sub	$4, %ecx
-	sub	$4, %edx
-	movl	(%edi), %eax
-	movl	%eax, (%edx)
-
-	testl	$15, %edx
-	jz	L(bk_ssse3_cpy_pre)
-
-	sub	$4, %edi
-	sub	$4, %ecx
-	sub	$4, %edx
-	movl	(%edi), %eax
-	movl	%eax, (%edx)
-
-	testl	$15, %edx
-	jz	L(bk_ssse3_cpy_pre)
-
-	sub	$4, %edi
-	sub	$4, %ecx
-	sub	$4, %edx
-	movl	(%edi), %eax
-	movl	%eax, (%edx)
-
-L(bk_ssse3_cpy_pre):
-	cmp	$64, %ecx
-	jb	L(bk_write_more32bytes)
-
-	.p2align 4
-L(bk_ssse3_cpy):
-	sub	$64, %edi
-	sub	$64, %ecx
-	sub	$64, %edx
-	movdqu	0x30(%edi), %xmm3
-	movdqa	%xmm3, 0x30(%edx)
-	movdqu	0x20(%edi), %xmm2
-	movdqa	%xmm2, 0x20(%edx)
-	movdqu	0x10(%edi), %xmm1
-	movdqa	%xmm1, 0x10(%edx)
-	movdqu	(%edi), %xmm0
-	movdqa	%xmm0, (%edx)
-	cmp	$64, %ecx
-	jae	L(bk_ssse3_cpy)
-	jmp	L(bk_write_64bytesless)
-
-#endif
-
-END (MEMCPY)
diff --git a/libc/arch-x86/string/strcat.S b/libc/arch-x86/string/strcat.S
deleted file mode 100644
index c75f38a..0000000
--- a/libc/arch-x86/string/strcat.S
+++ /dev/null
@@ -1,74 +0,0 @@
-/*	$OpenBSD: strcat.S,v 1.8 2005/08/07 11:30:38 espie Exp $ */
-/*
- * Written by J.T. Conklin <jtc@netbsd.org>.
- * Public domain.
- */
-
-#include <machine/asm.h>
-
-#if defined(APIWARN)
-#APP
-	.section .gnu.warning.strcat
-	.ascii "warning: strcat() is almost always misused, please use strlcat()"
-#NO_APP
-#endif
-
-/*
- * NOTE: I've unrolled the loop eight times: large enough to make a
- * significant difference, and small enough not to totally trash the
- * cache.
- */
-
-ENTRY(strcat)
-	pushl	%edi			/* save edi */
-	movl	8(%esp),%edi		/* dst address */
-	movl	12(%esp),%edx		/* src address */
-	pushl	%edi			/* push destination address */
-
-	cld				/* set search forward */
-	xorl	%eax,%eax		/* set search for null terminator */
-	movl	$-1,%ecx		/* set search for lots of characters */
-	repne				/* search! */
-	scasb
-
-	leal	-1(%edi),%ecx		/* correct dst address */
-
-	.align 2,0x90
-L1:	movb	(%edx),%al		/* unroll loop, but not too much */
-	movb	%al,(%ecx)
-	testb	%al,%al
-	jz	L2
-	movb	1(%edx),%al
-	movb	%al,1(%ecx)
-	testb	%al,%al
-	jz	L2
-	movb	2(%edx),%al
-	movb	%al,2(%ecx)
-	testb	%al,%al
-	jz	L2
-	movb	3(%edx),%al
-	movb	%al,3(%ecx)
-	testb	%al,%al
-	jz	L2
-	movb	4(%edx),%al
-	movb	%al,4(%ecx)
-	testb	%al,%al
-	jz	L2
-	movb	5(%edx),%al
-	movb	%al,5(%ecx)
-	testb	%al,%al
-	jz	L2
-	movb	6(%edx),%al
-	movb	%al,6(%ecx)
-	testb	%al,%al
-	jz	L2
-	movb	7(%edx),%al
-	movb	%al,7(%ecx)
-	addl	$8,%edx
-	addl	$8,%ecx
-	testb	%al,%al
-	jnz	L1
-L2:	popl	%eax			/* pop destination address */
-	popl	%edi			/* restore edi */
-	ret
-END(strcat)
diff --git a/libc/arch-x86/string/strcmp.S b/libc/arch-x86/string/strcmp.S
deleted file mode 100644
index 5d3f4fc..0000000
--- a/libc/arch-x86/string/strcmp.S
+++ /dev/null
@@ -1,82 +0,0 @@
-/*	$OpenBSD: strcmp.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
-/*
- * Written by J.T. Conklin <jtc@netbsd.org>.
- * Public domain.
- */
-
-#include <machine/asm.h>
-
-/*
- * NOTE: I've unrolled the loop eight times: large enough to make a
- * significant difference, and small enough not to totally trash the
- * cache.
- */
-
-ENTRY(strcmp)
-	movl	0x04(%esp),%eax
-	movl	0x08(%esp),%edx
-	jmp	L2			/* Jump into the loop! */
-
-	.align	2,0x90
-L1:	incl	%eax
-	incl	%edx
-L2:	movb	(%eax),%cl
-	testb	%cl,%cl			/* null terminator??? */
-	jz	L3
-	cmpb	%cl,(%edx)		/* chars match??? */
-	jne	L3
-	incl	%eax
-	incl	%edx
-	movb	(%eax),%cl
-	testb	%cl,%cl
-	jz	L3
-	cmpb	%cl,(%edx)
-	jne	L3
-	incl	%eax
-	incl	%edx
-	movb	(%eax),%cl
-	testb	%cl,%cl
-	jz	L3
-	cmpb	%cl,(%edx)
-	jne	L3
-	incl	%eax
-	incl	%edx
-	movb	(%eax),%cl
-	testb	%cl,%cl
-	jz	L3
-	cmpb	%cl,(%edx)
-	jne	L3
-	incl	%eax
-	incl	%edx
-	movb	(%eax),%cl
-	testb	%cl,%cl
-	jz	L3
-	cmpb	%cl,(%edx)
-	jne	L3
-	incl	%eax
-	incl	%edx
-	movb	(%eax),%cl
-	testb	%cl,%cl
-	jz	L3
-	cmpb	%cl,(%edx)
-	jne	L3
-	incl	%eax
-	incl	%edx
-	movb	(%eax),%cl
-	testb	%cl,%cl
-	jz	L3
-	cmpb	%cl,(%edx)
-	jne	L3
-	incl	%eax
-	incl	%edx
-	movb	(%eax),%cl
-	testb	%cl,%cl
-	jz	L3
-	cmpb	%cl,(%edx)
-	je	L1
-	.align 2, 0x90
-L3:	movzbl	(%eax),%eax		/* unsigned comparison */
-	movzbl	(%edx),%edx
-	subl	%edx,%eax
-	ret
-END(strcmp)
diff --git a/libc/arch-x86/string/strncmp.S b/libc/arch-x86/string/strncmp.S
deleted file mode 100644
index 6649473..0000000
--- a/libc/arch-x86/string/strncmp.S
+++ /dev/null
@@ -1,114 +0,0 @@
-/*	$OpenBSD: strncmp.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
-/*
- * Written by J.T. Conklin <jtc@netbsd.org>.
- * Public domain.
- */
-
-#include <machine/asm.h>
-
-/*
- * NOTE: I've unrolled the loop eight times: large enough to make a
- * significant difference, and small enough not to totally trash the
- * cache.
- */
-
-ENTRY(strncmp)
-	pushl	%ebx
-	movl	8(%esp),%eax
-	movl	12(%esp),%ecx
-	movl	16(%esp),%edx
-	testl	%edx,%edx
-	jmp	L2			/* Jump into the loop! */
-
-	.align 2,0x90
-L1:	incl	%eax
-	incl	%ecx
-	decl	%edx
-L2:	jz	L4			/* strings are equal */
-	movb	(%eax),%bl
-	testb	%bl,%bl
-	jz	L3
-	cmpb	%bl,(%ecx)
-	jne	L3
-
-	incl	%eax
-	incl	%ecx
-	decl	%edx
-	jz	L4
-	movb	(%eax),%bl
-	testb	%bl,%bl
-	jz	L3
-	cmpb	%bl,(%ecx)
-	jne	L3
-
-	incl	%eax
-	incl	%ecx
-	decl	%edx
-	jz	L4
-	movb	(%eax),%bl
-	testb	%bl,%bl
-	jz	L3
-	cmpb	%bl,(%ecx)
-	jne	L3
-
-	incl	%eax
-	incl	%ecx
-	decl	%edx
-	jz	L4
-	movb	(%eax),%bl
-	testb	%bl,%bl
-	jz	L3
-	cmpb	%bl,(%ecx)
-	jne	L3
-
-	incl	%eax
-	incl	%ecx
-	decl	%edx
-	jz	L4
-	movb	(%eax),%bl
-	testb	%bl,%bl
-	jz	L3
-	cmpb	%bl,(%ecx)
-	jne	L3
-
-	incl	%eax
-	incl	%ecx
-	decl	%edx
-	jz	L4
-	movb	(%eax),%bl
-	testb	%bl,%bl
-	jz	L3
-	cmpb	%bl,(%ecx)
-	jne	L3
-
-	incl	%eax
-	incl	%ecx
-	decl	%edx
-	jz	L4
-	movb	(%eax),%bl
-	testb	%bl,%bl
-	jz	L3
-	cmpb	%bl,(%ecx)
-	jne	L3
-
-	incl	%eax
-	incl	%ecx
-	decl	%edx
-	jz	L4
-	movb	(%eax),%bl
-	testb	%bl,%bl
-	jz	L3
-	cmpb	%bl,(%ecx)
-	je	L1
-
-	.align 2,0x90
-L3:	movzbl	(%eax),%eax		/* unsigned comparision */
-	movzbl	(%ecx),%ecx
-	subl	%ecx,%eax
-	popl	%ebx
-	ret
-	.align 2,0x90
-L4:	xorl	%eax,%eax
-	popl	%ebx
-	ret
-END(strncmp)
diff --git a/libc/arch-x86/string/swab.S b/libc/arch-x86/string/swab.S
deleted file mode 100644
index 2f6cfb2..0000000
--- a/libc/arch-x86/string/swab.S
+++ /dev/null
@@ -1,68 +0,0 @@
-/*	$OpenBSD: swab.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
-/*
- * Written by J.T. Conklin <jtc@netbsd.org>.
- * Public domain.
- */
-
-#include <machine/asm.h>
-
-/*
- * On the i486, this code is negligibly faster than the code generated
- * by gcc at about half the size.  If my i386 databook is correct, it
- * should be considerably faster than the gcc code on a i386.
- */
-
-ENTRY(swab)
-	pushl	%esi
-	pushl	%edi
-	movl	12(%esp),%esi
-	movl	16(%esp),%edi
-	movl	20(%esp),%ecx
-
-	cld				# set direction forward
-
-	shrl	$1,%ecx
-	testl	$7,%ecx			# copy first group of 1 to 7 words
-	jz	L2			# while swaping alternate bytes.
-	.align	2,0x90
-L1:	lodsw
-	rorw	$8,%ax
-	stosw
-	decl	%ecx
-	testl	$7,%ecx
-	jnz	L1
-
-L2:	shrl	$3,%ecx			# copy remainder 8 words at a time
-	jz	L4			# while swapping alternate bytes.
-	.align	2,0x90
-L3:	lodsw
-	rorw	$8,%ax
-	stosw
-	lodsw
-	rorw	$8,%ax
-	stosw
-	lodsw
-	rorw	$8,%ax
-	stosw
-	lodsw
-	rorw	$8,%ax
-	stosw
-	lodsw
-	rorw	$8,%ax
-	stosw
-	lodsw
-	rorw	$8,%ax
-	stosw
-	lodsw
-	rorw	$8,%ax
-	stosw
-	lodsw
-	rorw	$8,%ax
-	stosw
-	decl	%ecx
-	jnz	L3
-
-L4:	popl	%edi
-	popl	%esi
-	ret
-END(swab)
diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk
deleted file mode 100644
index b7d1e08..0000000
--- a/libc/arch-x86/syscalls.mk
+++ /dev/null
@@ -1,196 +0,0 @@
-# Generated by gensyscalls.py. Do not edit.
-syscall_src :=
-syscall_src += arch-x86/syscalls/__brk.S
-syscall_src += arch-x86/syscalls/__epoll_pwait.S
-syscall_src += arch-x86/syscalls/__exit.S
-syscall_src += arch-x86/syscalls/__fcntl64.S
-syscall_src += arch-x86/syscalls/__fstatfs64.S
-syscall_src += arch-x86/syscalls/__getcpu.S
-syscall_src += arch-x86/syscalls/__getcwd.S
-syscall_src += arch-x86/syscalls/__getpriority.S
-syscall_src += arch-x86/syscalls/__ioctl.S
-syscall_src += arch-x86/syscalls/__llseek.S
-syscall_src += arch-x86/syscalls/__mmap2.S
-syscall_src += arch-x86/syscalls/__openat.S
-syscall_src += arch-x86/syscalls/__ppoll.S
-syscall_src += arch-x86/syscalls/__pselect6.S
-syscall_src += arch-x86/syscalls/__ptrace.S
-syscall_src += arch-x86/syscalls/__reboot.S
-syscall_src += arch-x86/syscalls/__rt_sigaction.S
-syscall_src += arch-x86/syscalls/__rt_sigpending.S
-syscall_src += arch-x86/syscalls/__rt_sigprocmask.S
-syscall_src += arch-x86/syscalls/__rt_sigsuspend.S
-syscall_src += arch-x86/syscalls/__rt_sigtimedwait.S
-syscall_src += arch-x86/syscalls/__sched_getaffinity.S
-syscall_src += arch-x86/syscalls/__set_thread_area.S
-syscall_src += arch-x86/syscalls/__set_tid_address.S
-syscall_src += arch-x86/syscalls/__sigaction.S
-syscall_src += arch-x86/syscalls/__statfs64.S
-syscall_src += arch-x86/syscalls/__syslog.S
-syscall_src += arch-x86/syscalls/__timer_create.S
-syscall_src += arch-x86/syscalls/__timer_delete.S
-syscall_src += arch-x86/syscalls/__timer_getoverrun.S
-syscall_src += arch-x86/syscalls/__timer_gettime.S
-syscall_src += arch-x86/syscalls/__timer_settime.S
-syscall_src += arch-x86/syscalls/__waitid.S
-syscall_src += arch-x86/syscalls/_exit.S
-syscall_src += arch-x86/syscalls/accept.S
-syscall_src += arch-x86/syscalls/acct.S
-syscall_src += arch-x86/syscalls/bind.S
-syscall_src += arch-x86/syscalls/capget.S
-syscall_src += arch-x86/syscalls/capset.S
-syscall_src += arch-x86/syscalls/chdir.S
-syscall_src += arch-x86/syscalls/chroot.S
-syscall_src += arch-x86/syscalls/clock_getres.S
-syscall_src += arch-x86/syscalls/clock_gettime.S
-syscall_src += arch-x86/syscalls/clock_nanosleep.S
-syscall_src += arch-x86/syscalls/clock_settime.S
-syscall_src += arch-x86/syscalls/close.S
-syscall_src += arch-x86/syscalls/connect.S
-syscall_src += arch-x86/syscalls/delete_module.S
-syscall_src += arch-x86/syscalls/dup.S
-syscall_src += arch-x86/syscalls/dup3.S
-syscall_src += arch-x86/syscalls/epoll_create1.S
-syscall_src += arch-x86/syscalls/epoll_ctl.S
-syscall_src += arch-x86/syscalls/eventfd.S
-syscall_src += arch-x86/syscalls/execve.S
-syscall_src += arch-x86/syscalls/faccessat.S
-syscall_src += arch-x86/syscalls/fchdir.S
-syscall_src += arch-x86/syscalls/fchmod.S
-syscall_src += arch-x86/syscalls/fchmodat.S
-syscall_src += arch-x86/syscalls/fchown.S
-syscall_src += arch-x86/syscalls/fchownat.S
-syscall_src += arch-x86/syscalls/fdatasync.S
-syscall_src += arch-x86/syscalls/fgetxattr.S
-syscall_src += arch-x86/syscalls/flistxattr.S
-syscall_src += arch-x86/syscalls/flock.S
-syscall_src += arch-x86/syscalls/fremovexattr.S
-syscall_src += arch-x86/syscalls/fsetxattr.S
-syscall_src += arch-x86/syscalls/fstat.S
-syscall_src += arch-x86/syscalls/fstatat.S
-syscall_src += arch-x86/syscalls/fsync.S
-syscall_src += arch-x86/syscalls/ftruncate.S
-syscall_src += arch-x86/syscalls/ftruncate64.S
-syscall_src += arch-x86/syscalls/futex.S
-syscall_src += arch-x86/syscalls/getdents.S
-syscall_src += arch-x86/syscalls/getegid.S
-syscall_src += arch-x86/syscalls/geteuid.S
-syscall_src += arch-x86/syscalls/getgid.S
-syscall_src += arch-x86/syscalls/getgroups.S
-syscall_src += arch-x86/syscalls/getitimer.S
-syscall_src += arch-x86/syscalls/getpeername.S
-syscall_src += arch-x86/syscalls/getpgid.S
-syscall_src += arch-x86/syscalls/getpid.S
-syscall_src += arch-x86/syscalls/getppid.S
-syscall_src += arch-x86/syscalls/getresgid.S
-syscall_src += arch-x86/syscalls/getresuid.S
-syscall_src += arch-x86/syscalls/getrlimit.S
-syscall_src += arch-x86/syscalls/getrusage.S
-syscall_src += arch-x86/syscalls/getsid.S
-syscall_src += arch-x86/syscalls/getsockname.S
-syscall_src += arch-x86/syscalls/getsockopt.S
-syscall_src += arch-x86/syscalls/gettid.S
-syscall_src += arch-x86/syscalls/gettimeofday.S
-syscall_src += arch-x86/syscalls/getuid.S
-syscall_src += arch-x86/syscalls/getxattr.S
-syscall_src += arch-x86/syscalls/init_module.S
-syscall_src += arch-x86/syscalls/inotify_add_watch.S
-syscall_src += arch-x86/syscalls/inotify_init1.S
-syscall_src += arch-x86/syscalls/inotify_rm_watch.S
-syscall_src += arch-x86/syscalls/ioprio_get.S
-syscall_src += arch-x86/syscalls/ioprio_set.S
-syscall_src += arch-x86/syscalls/kill.S
-syscall_src += arch-x86/syscalls/klogctl.S
-syscall_src += arch-x86/syscalls/lgetxattr.S
-syscall_src += arch-x86/syscalls/linkat.S
-syscall_src += arch-x86/syscalls/listen.S
-syscall_src += arch-x86/syscalls/listxattr.S
-syscall_src += arch-x86/syscalls/llistxattr.S
-syscall_src += arch-x86/syscalls/lremovexattr.S
-syscall_src += arch-x86/syscalls/lseek.S
-syscall_src += arch-x86/syscalls/lsetxattr.S
-syscall_src += arch-x86/syscalls/madvise.S
-syscall_src += arch-x86/syscalls/mincore.S
-syscall_src += arch-x86/syscalls/mkdirat.S
-syscall_src += arch-x86/syscalls/mknodat.S
-syscall_src += arch-x86/syscalls/mlock.S
-syscall_src += arch-x86/syscalls/mlockall.S
-syscall_src += arch-x86/syscalls/mount.S
-syscall_src += arch-x86/syscalls/mprotect.S
-syscall_src += arch-x86/syscalls/mremap.S
-syscall_src += arch-x86/syscalls/msync.S
-syscall_src += arch-x86/syscalls/munlock.S
-syscall_src += arch-x86/syscalls/munlockall.S
-syscall_src += arch-x86/syscalls/munmap.S
-syscall_src += arch-x86/syscalls/nanosleep.S
-syscall_src += arch-x86/syscalls/perf_event_open.S
-syscall_src += arch-x86/syscalls/personality.S
-syscall_src += arch-x86/syscalls/pipe2.S
-syscall_src += arch-x86/syscalls/prctl.S
-syscall_src += arch-x86/syscalls/pread64.S
-syscall_src += arch-x86/syscalls/prlimit64.S
-syscall_src += arch-x86/syscalls/pwrite64.S
-syscall_src += arch-x86/syscalls/read.S
-syscall_src += arch-x86/syscalls/readahead.S
-syscall_src += arch-x86/syscalls/readlinkat.S
-syscall_src += arch-x86/syscalls/readv.S
-syscall_src += arch-x86/syscalls/recvfrom.S
-syscall_src += arch-x86/syscalls/recvmsg.S
-syscall_src += arch-x86/syscalls/removexattr.S
-syscall_src += arch-x86/syscalls/renameat.S
-syscall_src += arch-x86/syscalls/sched_get_priority_max.S
-syscall_src += arch-x86/syscalls/sched_get_priority_min.S
-syscall_src += arch-x86/syscalls/sched_getparam.S
-syscall_src += arch-x86/syscalls/sched_getscheduler.S
-syscall_src += arch-x86/syscalls/sched_rr_get_interval.S
-syscall_src += arch-x86/syscalls/sched_setaffinity.S
-syscall_src += arch-x86/syscalls/sched_setparam.S
-syscall_src += arch-x86/syscalls/sched_setscheduler.S
-syscall_src += arch-x86/syscalls/sched_yield.S
-syscall_src += arch-x86/syscalls/sendfile.S
-syscall_src += arch-x86/syscalls/sendfile64.S
-syscall_src += arch-x86/syscalls/sendmsg.S
-syscall_src += arch-x86/syscalls/sendto.S
-syscall_src += arch-x86/syscalls/setgid.S
-syscall_src += arch-x86/syscalls/setgroups.S
-syscall_src += arch-x86/syscalls/setitimer.S
-syscall_src += arch-x86/syscalls/setns.S
-syscall_src += arch-x86/syscalls/setpgid.S
-syscall_src += arch-x86/syscalls/setpriority.S
-syscall_src += arch-x86/syscalls/setregid.S
-syscall_src += arch-x86/syscalls/setresgid.S
-syscall_src += arch-x86/syscalls/setresuid.S
-syscall_src += arch-x86/syscalls/setreuid.S
-syscall_src += arch-x86/syscalls/setrlimit.S
-syscall_src += arch-x86/syscalls/setsid.S
-syscall_src += arch-x86/syscalls/setsockopt.S
-syscall_src += arch-x86/syscalls/settimeofday.S
-syscall_src += arch-x86/syscalls/setuid.S
-syscall_src += arch-x86/syscalls/setxattr.S
-syscall_src += arch-x86/syscalls/shutdown.S
-syscall_src += arch-x86/syscalls/sigaltstack.S
-syscall_src += arch-x86/syscalls/signalfd4.S
-syscall_src += arch-x86/syscalls/socket.S
-syscall_src += arch-x86/syscalls/socketpair.S
-syscall_src += arch-x86/syscalls/swapoff.S
-syscall_src += arch-x86/syscalls/swapon.S
-syscall_src += arch-x86/syscalls/symlinkat.S
-syscall_src += arch-x86/syscalls/sync.S
-syscall_src += arch-x86/syscalls/sysinfo.S
-syscall_src += arch-x86/syscalls/tgkill.S
-syscall_src += arch-x86/syscalls/timerfd_create.S
-syscall_src += arch-x86/syscalls/timerfd_gettime.S
-syscall_src += arch-x86/syscalls/timerfd_settime.S
-syscall_src += arch-x86/syscalls/times.S
-syscall_src += arch-x86/syscalls/tkill.S
-syscall_src += arch-x86/syscalls/truncate.S
-syscall_src += arch-x86/syscalls/truncate64.S
-syscall_src += arch-x86/syscalls/umask.S
-syscall_src += arch-x86/syscalls/umount2.S
-syscall_src += arch-x86/syscalls/uname.S
-syscall_src += arch-x86/syscalls/unlinkat.S
-syscall_src += arch-x86/syscalls/unshare.S
-syscall_src += arch-x86/syscalls/utimensat.S
-syscall_src += arch-x86/syscalls/wait4.S
-syscall_src += arch-x86/syscalls/write.S
-syscall_src += arch-x86/syscalls/writev.S
diff --git a/libc/arch-x86/syscalls/__accept4.S b/libc/arch-x86/syscalls/__accept4.S
new file mode 100644
index 0000000..7b16dd4
--- /dev/null
+++ b/libc/arch-x86/syscalls/__accept4.S
@@ -0,0 +1,27 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__accept4)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    mov     $18, %ebx
+    mov     %esp, %ecx
+    addl    $12, %ecx
+    movl    $__NR_socketcall, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
+END(__accept4)
diff --git a/libc/arch-x86/syscalls/__brk.S b/libc/arch-x86/syscalls/__brk.S
index 728bf81..22acdad 100644
--- a/libc/arch-x86/syscalls/__brk.S
+++ b/libc/arch-x86/syscalls/__brk.S
@@ -4,7 +4,7 @@
 
 ENTRY(__brk)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_brk, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__connect.S b/libc/arch-x86/syscalls/__connect.S
new file mode 100644
index 0000000..475d452
--- /dev/null
+++ b/libc/arch-x86/syscalls/__connect.S
@@ -0,0 +1,27 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__connect)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    mov     $3, %ebx
+    mov     %esp, %ecx
+    addl    $12, %ecx
+    movl    $__NR_socketcall, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
+END(__connect)
diff --git a/libc/arch-x86/syscalls/__epoll_pwait.S b/libc/arch-x86/syscalls/__epoll_pwait.S
index 9bcc142..171caa5 100644
--- a/libc/arch-x86/syscalls/__epoll_pwait.S
+++ b/libc/arch-x86/syscalls/__epoll_pwait.S
@@ -4,18 +4,23 @@
 
 ENTRY(__epoll_pwait)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    pushl   %ebp
-    .cfi_def_cfa_offset 24
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
-    .cfi_rel_offset ebp, 20
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
+    pushl   %ebp
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ebp, 0
     mov     28(%esp), %ebx
     mov     32(%esp), %ecx
     mov     36(%esp), %edx
@@ -28,9 +33,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebp
     popl    %edi
diff --git a/libc/arch-x86/syscalls/__exit.S b/libc/arch-x86/syscalls/__exit.S
index eaddc5e..8cf3663 100644
--- a/libc/arch-x86/syscalls/__exit.S
+++ b/libc/arch-x86/syscalls/__exit.S
@@ -4,7 +4,7 @@
 
 ENTRY(__exit)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_exit, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__fadvise64.S b/libc/arch-x86/syscalls/__fadvise64.S
new file mode 100644
index 0000000..6e4298a
--- /dev/null
+++ b/libc/arch-x86/syscalls/__fadvise64.S
@@ -0,0 +1,46 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__fadvise64)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
+    pushl   %ebp
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ebp, 0
+    mov     28(%esp), %ebx
+    mov     32(%esp), %ecx
+    mov     36(%esp), %edx
+    mov     40(%esp), %esi
+    mov     44(%esp), %edi
+    mov     48(%esp), %ebp
+    movl    $__NR_fadvise64_64, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ebp
+    popl    %edi
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(__fadvise64)
diff --git a/libc/arch-x86/syscalls/__fcntl64.S b/libc/arch-x86/syscalls/__fcntl64.S
index faefa65..d900a52 100644
--- a/libc/arch-x86/syscalls/__fcntl64.S
+++ b/libc/arch-x86/syscalls/__fcntl64.S
@@ -4,12 +4,14 @@
 
 ENTRY(__fcntl64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__fstatfs64.S b/libc/arch-x86/syscalls/__fstatfs64.S
index dfd04af..9b44743 100644
--- a/libc/arch-x86/syscalls/__fstatfs64.S
+++ b/libc/arch-x86/syscalls/__fstatfs64.S
@@ -4,12 +4,14 @@
 
 ENTRY(__fstatfs64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__getcpu.S b/libc/arch-x86/syscalls/__getcpu.S
index d1da871..bb4c41f 100644
--- a/libc/arch-x86/syscalls/__getcpu.S
+++ b/libc/arch-x86/syscalls/__getcpu.S
@@ -4,12 +4,14 @@
 
 ENTRY(__getcpu)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__getcwd.S b/libc/arch-x86/syscalls/__getcwd.S
index a9834e2..8decd99 100644
--- a/libc/arch-x86/syscalls/__getcwd.S
+++ b/libc/arch-x86/syscalls/__getcwd.S
@@ -4,10 +4,11 @@
 
 ENTRY(__getcwd)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_getcwd, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__getdents64.S b/libc/arch-x86/syscalls/__getdents64.S
new file mode 100644
index 0000000..5190a68
--- /dev/null
+++ b/libc/arch-x86/syscalls/__getdents64.S
@@ -0,0 +1,31 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getdents64)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    mov     16(%esp), %ebx
+    mov     20(%esp), %ecx
+    mov     24(%esp), %edx
+    movl    $__NR_getdents64, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(__getdents64)
diff --git a/libc/arch-x86/syscalls/__getpid.S b/libc/arch-x86/syscalls/__getpid.S
new file mode 100644
index 0000000..197202c
--- /dev/null
+++ b/libc/arch-x86/syscalls/__getpid.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getpid)
+    movl    $__NR_getpid, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    ret
+END(__getpid)
diff --git a/libc/arch-x86/syscalls/__getpriority.S b/libc/arch-x86/syscalls/__getpriority.S
index 99d33bb..dd5591f 100644
--- a/libc/arch-x86/syscalls/__getpriority.S
+++ b/libc/arch-x86/syscalls/__getpriority.S
@@ -4,10 +4,11 @@
 
 ENTRY(__getpriority)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_getpriority, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__ioctl.S b/libc/arch-x86/syscalls/__ioctl.S
index ad617f0..b6ee9f2 100644
--- a/libc/arch-x86/syscalls/__ioctl.S
+++ b/libc/arch-x86/syscalls/__ioctl.S
@@ -4,12 +4,14 @@
 
 ENTRY(__ioctl)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__llseek.S b/libc/arch-x86/syscalls/__llseek.S
index 2dab8a9..5cc907a 100644
--- a/libc/arch-x86/syscalls/__llseek.S
+++ b/libc/arch-x86/syscalls/__llseek.S
@@ -4,16 +4,20 @@
 
 ENTRY(__llseek)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/__mmap2.S b/libc/arch-x86/syscalls/__mmap2.S
index 963abf3..08314c8 100644
--- a/libc/arch-x86/syscalls/__mmap2.S
+++ b/libc/arch-x86/syscalls/__mmap2.S
@@ -4,18 +4,23 @@
 
 ENTRY(__mmap2)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    pushl   %ebp
-    .cfi_def_cfa_offset 24
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
-    .cfi_rel_offset ebp, 20
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
+    pushl   %ebp
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ebp, 0
     mov     28(%esp), %ebx
     mov     32(%esp), %ecx
     mov     36(%esp), %edx
@@ -28,9 +33,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebp
     popl    %edi
diff --git a/libc/arch-x86/syscalls/__openat.S b/libc/arch-x86/syscalls/__openat.S
index 6b05bec..4c11709 100644
--- a/libc/arch-x86/syscalls/__openat.S
+++ b/libc/arch-x86/syscalls/__openat.S
@@ -4,14 +4,17 @@
 
 ENTRY(__openat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__ppoll.S b/libc/arch-x86/syscalls/__ppoll.S
index e5af93c..2a1f76e 100644
--- a/libc/arch-x86/syscalls/__ppoll.S
+++ b/libc/arch-x86/syscalls/__ppoll.S
@@ -4,16 +4,20 @@
 
 ENTRY(__ppoll)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/__pselect6.S b/libc/arch-x86/syscalls/__pselect6.S
index 984a67e..8ff102a 100644
--- a/libc/arch-x86/syscalls/__pselect6.S
+++ b/libc/arch-x86/syscalls/__pselect6.S
@@ -4,18 +4,23 @@
 
 ENTRY(__pselect6)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    pushl   %ebp
-    .cfi_def_cfa_offset 24
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
-    .cfi_rel_offset ebp, 20
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
+    pushl   %ebp
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ebp, 0
     mov     28(%esp), %ebx
     mov     32(%esp), %ecx
     mov     36(%esp), %edx
@@ -28,9 +33,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebp
     popl    %edi
diff --git a/libc/arch-x86/syscalls/__ptrace.S b/libc/arch-x86/syscalls/__ptrace.S
index d3b8031..d982cec 100644
--- a/libc/arch-x86/syscalls/__ptrace.S
+++ b/libc/arch-x86/syscalls/__ptrace.S
@@ -4,14 +4,17 @@
 
 ENTRY(__ptrace)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__reboot.S b/libc/arch-x86/syscalls/__reboot.S
index b644906..3d169bf 100644
--- a/libc/arch-x86/syscalls/__reboot.S
+++ b/libc/arch-x86/syscalls/__reboot.S
@@ -4,14 +4,17 @@
 
 ENTRY(__reboot)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__rt_sigaction.S b/libc/arch-x86/syscalls/__rt_sigaction.S
index 1c5fdcc..59c3882 100644
--- a/libc/arch-x86/syscalls/__rt_sigaction.S
+++ b/libc/arch-x86/syscalls/__rt_sigaction.S
@@ -4,14 +4,17 @@
 
 ENTRY(__rt_sigaction)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__rt_sigpending.S b/libc/arch-x86/syscalls/__rt_sigpending.S
index 5522195..9c6a106 100644
--- a/libc/arch-x86/syscalls/__rt_sigpending.S
+++ b/libc/arch-x86/syscalls/__rt_sigpending.S
@@ -4,10 +4,11 @@
 
 ENTRY(__rt_sigpending)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_rt_sigpending, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__rt_sigprocmask.S b/libc/arch-x86/syscalls/__rt_sigprocmask.S
index 0df7301..9b1532f 100644
--- a/libc/arch-x86/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-x86/syscalls/__rt_sigprocmask.S
@@ -4,14 +4,17 @@
 
 ENTRY(__rt_sigprocmask)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__rt_sigsuspend.S b/libc/arch-x86/syscalls/__rt_sigsuspend.S
index 0e7dbdf..b05acd8 100644
--- a/libc/arch-x86/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-x86/syscalls/__rt_sigsuspend.S
@@ -4,10 +4,11 @@
 
 ENTRY(__rt_sigsuspend)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_rt_sigsuspend, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__rt_sigtimedwait.S b/libc/arch-x86/syscalls/__rt_sigtimedwait.S
index cfbc7a6..14cb70f 100644
--- a/libc/arch-x86/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-x86/syscalls/__rt_sigtimedwait.S
@@ -4,14 +4,17 @@
 
 ENTRY(__rt_sigtimedwait)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__sched_getaffinity.S b/libc/arch-x86/syscalls/__sched_getaffinity.S
index a9b9f79..0b0a970 100644
--- a/libc/arch-x86/syscalls/__sched_getaffinity.S
+++ b/libc/arch-x86/syscalls/__sched_getaffinity.S
@@ -4,12 +4,14 @@
 
 ENTRY(__sched_getaffinity)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__set_thread_area.S b/libc/arch-x86/syscalls/__set_thread_area.S
index ce06233..8cd6880 100644
--- a/libc/arch-x86/syscalls/__set_thread_area.S
+++ b/libc/arch-x86/syscalls/__set_thread_area.S
@@ -4,7 +4,7 @@
 
 ENTRY(__set_thread_area)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_set_thread_area, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__set_tid_address.S b/libc/arch-x86/syscalls/__set_tid_address.S
index 6a3943d..08acce9 100644
--- a/libc/arch-x86/syscalls/__set_tid_address.S
+++ b/libc/arch-x86/syscalls/__set_tid_address.S
@@ -4,7 +4,7 @@
 
 ENTRY(__set_tid_address)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_set_tid_address, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__sigaction.S b/libc/arch-x86/syscalls/__sigaction.S
index 8824a85..0238247 100644
--- a/libc/arch-x86/syscalls/__sigaction.S
+++ b/libc/arch-x86/syscalls/__sigaction.S
@@ -4,12 +4,14 @@
 
 ENTRY(__sigaction)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__signalfd4.S b/libc/arch-x86/syscalls/__signalfd4.S
new file mode 100644
index 0000000..02ddc73
--- /dev/null
+++ b/libc/arch-x86/syscalls/__signalfd4.S
@@ -0,0 +1,36 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__signalfd4)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    mov     20(%esp), %ebx
+    mov     24(%esp), %ecx
+    mov     28(%esp), %edx
+    mov     32(%esp), %esi
+    movl    $__NR_signalfd4, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(__signalfd4)
diff --git a/libc/arch-x86/syscalls/__socket.S b/libc/arch-x86/syscalls/__socket.S
new file mode 100644
index 0000000..75952ee
--- /dev/null
+++ b/libc/arch-x86/syscalls/__socket.S
@@ -0,0 +1,27 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__socket)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    mov     $1, %ebx
+    mov     %esp, %ecx
+    addl    $12, %ecx
+    movl    $__NR_socketcall, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
+END(__socket)
diff --git a/libc/arch-x86/syscalls/__statfs64.S b/libc/arch-x86/syscalls/__statfs64.S
index 7a91f1d..b9bccb0 100644
--- a/libc/arch-x86/syscalls/__statfs64.S
+++ b/libc/arch-x86/syscalls/__statfs64.S
@@ -4,12 +4,14 @@
 
 ENTRY(__statfs64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__syslog.S b/libc/arch-x86/syscalls/__syslog.S
deleted file mode 100644
index 1da01be..0000000
--- a/libc/arch-x86/syscalls/__syslog.S
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(__syslog)
-    pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    mov     16(%esp), %ebx
-    mov     20(%esp), %ecx
-    mov     24(%esp), %edx
-    movl    $__NR_syslog, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %edx
-    popl    %ecx
-    popl    %ebx
-    ret
-END(__syslog)
diff --git a/libc/arch-x86/syscalls/__timer_create.S b/libc/arch-x86/syscalls/__timer_create.S
index 68480d1..b22f408 100644
--- a/libc/arch-x86/syscalls/__timer_create.S
+++ b/libc/arch-x86/syscalls/__timer_create.S
@@ -4,12 +4,14 @@
 
 ENTRY(__timer_create)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/__timer_delete.S b/libc/arch-x86/syscalls/__timer_delete.S
index a2732e1..d77ae3e 100644
--- a/libc/arch-x86/syscalls/__timer_delete.S
+++ b/libc/arch-x86/syscalls/__timer_delete.S
@@ -4,7 +4,7 @@
 
 ENTRY(__timer_delete)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_timer_delete, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__timer_getoverrun.S b/libc/arch-x86/syscalls/__timer_getoverrun.S
index a340bfe..f21b08f 100644
--- a/libc/arch-x86/syscalls/__timer_getoverrun.S
+++ b/libc/arch-x86/syscalls/__timer_getoverrun.S
@@ -4,7 +4,7 @@
 
 ENTRY(__timer_getoverrun)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_timer_getoverrun, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/__timer_gettime.S b/libc/arch-x86/syscalls/__timer_gettime.S
index 4aeb8eb..73c8539 100644
--- a/libc/arch-x86/syscalls/__timer_gettime.S
+++ b/libc/arch-x86/syscalls/__timer_gettime.S
@@ -4,10 +4,11 @@
 
 ENTRY(__timer_gettime)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_timer_gettime, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/__timer_settime.S b/libc/arch-x86/syscalls/__timer_settime.S
index f93bca4..1a6a8ec 100644
--- a/libc/arch-x86/syscalls/__timer_settime.S
+++ b/libc/arch-x86/syscalls/__timer_settime.S
@@ -4,14 +4,17 @@
 
 ENTRY(__timer_settime)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/__waitid.S b/libc/arch-x86/syscalls/__waitid.S
index cda5238..2061abc 100644
--- a/libc/arch-x86/syscalls/__waitid.S
+++ b/libc/arch-x86/syscalls/__waitid.S
@@ -4,16 +4,20 @@
 
 ENTRY(__waitid)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/_exit.S b/libc/arch-x86/syscalls/_exit.S
index 2ff5faf..8528ee4 100644
--- a/libc/arch-x86/syscalls/_exit.S
+++ b/libc/arch-x86/syscalls/_exit.S
@@ -4,7 +4,7 @@
 
 ENTRY(_exit)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_exit_group, %eax
@@ -13,10 +13,12 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
 END(_exit)
+
+    .globl _Exit
+    .equ _Exit, _exit
diff --git a/libc/arch-x86/syscalls/accept.S b/libc/arch-x86/syscalls/accept.S
deleted file mode 100644
index f7e8a58..0000000
--- a/libc/arch-x86/syscalls/accept.S
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(accept)
-    pushl   %ebx
-    pushl   %ecx
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    mov     $5, %ebx
-    mov     %esp, %ecx
-    addl    $12, %ecx
-    movl    $__NR_socketcall, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %ecx
-    popl    %ebx
-    ret
-END(accept)
diff --git a/libc/arch-x86/syscalls/acct.S b/libc/arch-x86/syscalls/acct.S
index 6abaffc..d831771 100644
--- a/libc/arch-x86/syscalls/acct.S
+++ b/libc/arch-x86/syscalls/acct.S
@@ -4,7 +4,7 @@
 
 ENTRY(acct)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_acct, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/bind.S b/libc/arch-x86/syscalls/bind.S
index 7c2acb5..9ef817e 100644
--- a/libc/arch-x86/syscalls/bind.S
+++ b/libc/arch-x86/syscalls/bind.S
@@ -4,10 +4,11 @@
 
 ENTRY(bind)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $2, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/capget.S b/libc/arch-x86/syscalls/capget.S
index aa7b432..81c24e8 100644
--- a/libc/arch-x86/syscalls/capget.S
+++ b/libc/arch-x86/syscalls/capget.S
@@ -4,10 +4,11 @@
 
 ENTRY(capget)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_capget, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/capset.S b/libc/arch-x86/syscalls/capset.S
index 6c31083..4e311e9 100644
--- a/libc/arch-x86/syscalls/capset.S
+++ b/libc/arch-x86/syscalls/capset.S
@@ -4,10 +4,11 @@
 
 ENTRY(capset)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_capset, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/chdir.S b/libc/arch-x86/syscalls/chdir.S
index a51ac6e..2226a1a 100644
--- a/libc/arch-x86/syscalls/chdir.S
+++ b/libc/arch-x86/syscalls/chdir.S
@@ -4,7 +4,7 @@
 
 ENTRY(chdir)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_chdir, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/chroot.S b/libc/arch-x86/syscalls/chroot.S
index be8f686..95ed0b5 100644
--- a/libc/arch-x86/syscalls/chroot.S
+++ b/libc/arch-x86/syscalls/chroot.S
@@ -4,7 +4,7 @@
 
 ENTRY(chroot)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_chroot, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/clock_getres.S b/libc/arch-x86/syscalls/clock_getres.S
index ce7e6f7..9501799 100644
--- a/libc/arch-x86/syscalls/clock_getres.S
+++ b/libc/arch-x86/syscalls/clock_getres.S
@@ -4,10 +4,11 @@
 
 ENTRY(clock_getres)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_clock_getres, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/clock_gettime.S b/libc/arch-x86/syscalls/clock_gettime.S
index b1cdb1a..0875cfb 100644
--- a/libc/arch-x86/syscalls/clock_gettime.S
+++ b/libc/arch-x86/syscalls/clock_gettime.S
@@ -4,10 +4,11 @@
 
 ENTRY(clock_gettime)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_clock_gettime, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/clock_nanosleep.S b/libc/arch-x86/syscalls/clock_nanosleep.S
index 6c025e3..5e2cc03 100644
--- a/libc/arch-x86/syscalls/clock_nanosleep.S
+++ b/libc/arch-x86/syscalls/clock_nanosleep.S
@@ -4,14 +4,17 @@
 
 ENTRY(clock_nanosleep)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/clock_settime.S b/libc/arch-x86/syscalls/clock_settime.S
index 7c863e1..96fafed 100644
--- a/libc/arch-x86/syscalls/clock_settime.S
+++ b/libc/arch-x86/syscalls/clock_settime.S
@@ -4,10 +4,11 @@
 
 ENTRY(clock_settime)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_clock_settime, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/close.S b/libc/arch-x86/syscalls/close.S
index 3eb3be1..f6cce62 100644
--- a/libc/arch-x86/syscalls/close.S
+++ b/libc/arch-x86/syscalls/close.S
@@ -4,7 +4,7 @@
 
 ENTRY(close)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_close, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/connect.S b/libc/arch-x86/syscalls/connect.S
deleted file mode 100644
index c0d73ca..0000000
--- a/libc/arch-x86/syscalls/connect.S
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(connect)
-    pushl   %ebx
-    pushl   %ecx
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    mov     $3, %ebx
-    mov     %esp, %ecx
-    addl    $12, %ecx
-    movl    $__NR_socketcall, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %ecx
-    popl    %ebx
-    ret
-END(connect)
diff --git a/libc/arch-x86/syscalls/delete_module.S b/libc/arch-x86/syscalls/delete_module.S
index 11ff762..58b8d6b 100644
--- a/libc/arch-x86/syscalls/delete_module.S
+++ b/libc/arch-x86/syscalls/delete_module.S
@@ -4,10 +4,11 @@
 
 ENTRY(delete_module)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_delete_module, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/dup.S b/libc/arch-x86/syscalls/dup.S
index 98070e2..0fd9cce 100644
--- a/libc/arch-x86/syscalls/dup.S
+++ b/libc/arch-x86/syscalls/dup.S
@@ -4,7 +4,7 @@
 
 ENTRY(dup)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_dup, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/dup3.S b/libc/arch-x86/syscalls/dup3.S
index 4380e6a..8348660 100644
--- a/libc/arch-x86/syscalls/dup3.S
+++ b/libc/arch-x86/syscalls/dup3.S
@@ -4,12 +4,14 @@
 
 ENTRY(dup3)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/epoll_create1.S b/libc/arch-x86/syscalls/epoll_create1.S
index ca5d4d1..0fcd09c 100644
--- a/libc/arch-x86/syscalls/epoll_create1.S
+++ b/libc/arch-x86/syscalls/epoll_create1.S
@@ -4,7 +4,7 @@
 
 ENTRY(epoll_create1)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_epoll_create1, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/epoll_ctl.S b/libc/arch-x86/syscalls/epoll_ctl.S
index df345cd..092c1e0 100644
--- a/libc/arch-x86/syscalls/epoll_ctl.S
+++ b/libc/arch-x86/syscalls/epoll_ctl.S
@@ -4,14 +4,17 @@
 
 ENTRY(epoll_ctl)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/eventfd.S b/libc/arch-x86/syscalls/eventfd.S
index 333bca4..cc165e5 100644
--- a/libc/arch-x86/syscalls/eventfd.S
+++ b/libc/arch-x86/syscalls/eventfd.S
@@ -4,10 +4,11 @@
 
 ENTRY(eventfd)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_eventfd2, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/execve.S b/libc/arch-x86/syscalls/execve.S
index 95523bc..e1c0253 100644
--- a/libc/arch-x86/syscalls/execve.S
+++ b/libc/arch-x86/syscalls/execve.S
@@ -4,12 +4,14 @@
 
 ENTRY(execve)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/faccessat.S b/libc/arch-x86/syscalls/faccessat.S
index 0ad6224..9d52231 100644
--- a/libc/arch-x86/syscalls/faccessat.S
+++ b/libc/arch-x86/syscalls/faccessat.S
@@ -4,14 +4,17 @@
 
 ENTRY(faccessat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/fallocate64.S b/libc/arch-x86/syscalls/fallocate64.S
new file mode 100644
index 0000000..e2a7c3e
--- /dev/null
+++ b/libc/arch-x86/syscalls/fallocate64.S
@@ -0,0 +1,46 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fallocate64)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
+    pushl   %ebp
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ebp, 0
+    mov     28(%esp), %ebx
+    mov     32(%esp), %ecx
+    mov     36(%esp), %edx
+    mov     40(%esp), %esi
+    mov     44(%esp), %edi
+    mov     48(%esp), %ebp
+    movl    $__NR_fallocate, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ebp
+    popl    %edi
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(fallocate64)
diff --git a/libc/arch-x86/syscalls/fchdir.S b/libc/arch-x86/syscalls/fchdir.S
index 4298c2a..c40c2c1 100644
--- a/libc/arch-x86/syscalls/fchdir.S
+++ b/libc/arch-x86/syscalls/fchdir.S
@@ -4,7 +4,7 @@
 
 ENTRY(fchdir)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_fchdir, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/fchmod.S b/libc/arch-x86/syscalls/fchmod.S
index d4ef36f..37851ff 100644
--- a/libc/arch-x86/syscalls/fchmod.S
+++ b/libc/arch-x86/syscalls/fchmod.S
@@ -4,10 +4,11 @@
 
 ENTRY(fchmod)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_fchmod, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/fchmodat.S b/libc/arch-x86/syscalls/fchmodat.S
index 4fb6995..f515512 100644
--- a/libc/arch-x86/syscalls/fchmodat.S
+++ b/libc/arch-x86/syscalls/fchmodat.S
@@ -4,14 +4,17 @@
 
 ENTRY(fchmodat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/fchown.S b/libc/arch-x86/syscalls/fchown.S
index 326fe16..1a4f749 100644
--- a/libc/arch-x86/syscalls/fchown.S
+++ b/libc/arch-x86/syscalls/fchown.S
@@ -4,12 +4,14 @@
 
 ENTRY(fchown)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/fchownat.S b/libc/arch-x86/syscalls/fchownat.S
index 802dc44..c2b358e 100644
--- a/libc/arch-x86/syscalls/fchownat.S
+++ b/libc/arch-x86/syscalls/fchownat.S
@@ -4,16 +4,20 @@
 
 ENTRY(fchownat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/fdatasync.S b/libc/arch-x86/syscalls/fdatasync.S
index 02e09be..debd4e3 100644
--- a/libc/arch-x86/syscalls/fdatasync.S
+++ b/libc/arch-x86/syscalls/fdatasync.S
@@ -4,7 +4,7 @@
 
 ENTRY(fdatasync)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_fdatasync, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/fgetxattr.S b/libc/arch-x86/syscalls/fgetxattr.S
index 99a920d..1eff931 100644
--- a/libc/arch-x86/syscalls/fgetxattr.S
+++ b/libc/arch-x86/syscalls/fgetxattr.S
@@ -4,14 +4,17 @@
 
 ENTRY(fgetxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/flistxattr.S b/libc/arch-x86/syscalls/flistxattr.S
index a1691fc..fc81a37 100644
--- a/libc/arch-x86/syscalls/flistxattr.S
+++ b/libc/arch-x86/syscalls/flistxattr.S
@@ -4,12 +4,14 @@
 
 ENTRY(flistxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/flock.S b/libc/arch-x86/syscalls/flock.S
index a4388e9..0fc76a8 100644
--- a/libc/arch-x86/syscalls/flock.S
+++ b/libc/arch-x86/syscalls/flock.S
@@ -4,10 +4,11 @@
 
 ENTRY(flock)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_flock, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/fremovexattr.S b/libc/arch-x86/syscalls/fremovexattr.S
index 6377974..2053a9a 100644
--- a/libc/arch-x86/syscalls/fremovexattr.S
+++ b/libc/arch-x86/syscalls/fremovexattr.S
@@ -4,10 +4,11 @@
 
 ENTRY(fremovexattr)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_fremovexattr, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/fsetxattr.S b/libc/arch-x86/syscalls/fsetxattr.S
index 2f926a5..7af0ef0 100644
--- a/libc/arch-x86/syscalls/fsetxattr.S
+++ b/libc/arch-x86/syscalls/fsetxattr.S
@@ -4,16 +4,20 @@
 
 ENTRY(fsetxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/fstat.S b/libc/arch-x86/syscalls/fstat.S
deleted file mode 100644
index daa4d7f..0000000
--- a/libc/arch-x86/syscalls/fstat.S
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstat)
-    pushl   %ebx
-    pushl   %ecx
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    mov     12(%esp), %ebx
-    mov     16(%esp), %ecx
-    movl    $__NR_fstat64, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %ecx
-    popl    %ebx
-    ret
-END(fstat)
diff --git a/libc/arch-x86/syscalls/fstat64.S b/libc/arch-x86/syscalls/fstat64.S
new file mode 100644
index 0000000..fc16233
--- /dev/null
+++ b/libc/arch-x86/syscalls/fstat64.S
@@ -0,0 +1,29 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstat64)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    mov     12(%esp), %ebx
+    mov     16(%esp), %ecx
+    movl    $__NR_fstat64, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
+END(fstat64)
+
+    .globl fstat
+    .equ fstat, fstat64
diff --git a/libc/arch-x86/syscalls/fstatat.S b/libc/arch-x86/syscalls/fstatat.S
deleted file mode 100644
index 7be868c..0000000
--- a/libc/arch-x86/syscalls/fstatat.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstatat)
-    pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    mov     20(%esp), %ebx
-    mov     24(%esp), %ecx
-    mov     28(%esp), %edx
-    mov     32(%esp), %esi
-    movl    $__NR_fstatat64, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %esi
-    popl    %edx
-    popl    %ecx
-    popl    %ebx
-    ret
-END(fstatat)
diff --git a/libc/arch-x86/syscalls/fstatat64.S b/libc/arch-x86/syscalls/fstatat64.S
new file mode 100644
index 0000000..a3697e6
--- /dev/null
+++ b/libc/arch-x86/syscalls/fstatat64.S
@@ -0,0 +1,39 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatat64)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    mov     20(%esp), %ebx
+    mov     24(%esp), %ecx
+    mov     28(%esp), %edx
+    mov     32(%esp), %esi
+    movl    $__NR_fstatat64, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(fstatat64)
+
+    .globl fstatat
+    .equ fstatat, fstatat64
diff --git a/libc/arch-x86/syscalls/fsync.S b/libc/arch-x86/syscalls/fsync.S
index 71183cb..b19a3ab 100644
--- a/libc/arch-x86/syscalls/fsync.S
+++ b/libc/arch-x86/syscalls/fsync.S
@@ -4,7 +4,7 @@
 
 ENTRY(fsync)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_fsync, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/ftruncate.S b/libc/arch-x86/syscalls/ftruncate.S
index 1003077..78d1e18 100644
--- a/libc/arch-x86/syscalls/ftruncate.S
+++ b/libc/arch-x86/syscalls/ftruncate.S
@@ -4,10 +4,11 @@
 
 ENTRY(ftruncate)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_ftruncate, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/ftruncate64.S b/libc/arch-x86/syscalls/ftruncate64.S
index 586086d..7233447 100644
--- a/libc/arch-x86/syscalls/ftruncate64.S
+++ b/libc/arch-x86/syscalls/ftruncate64.S
@@ -4,12 +4,14 @@
 
 ENTRY(ftruncate64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/futex.S b/libc/arch-x86/syscalls/futex.S
deleted file mode 100644
index 7a52913..0000000
--- a/libc/arch-x86/syscalls/futex.S
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(futex)
-    pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    pushl   %ebp
-    .cfi_def_cfa_offset 24
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
-    .cfi_rel_offset ebp, 20
-    mov     28(%esp), %ebx
-    mov     32(%esp), %ecx
-    mov     36(%esp), %edx
-    mov     40(%esp), %esi
-    mov     44(%esp), %edi
-    mov     48(%esp), %ebp
-    movl    $__NR_futex, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %ebp
-    popl    %edi
-    popl    %esi
-    popl    %edx
-    popl    %ecx
-    popl    %ebx
-    ret
-END(futex)
diff --git a/libc/arch-x86/syscalls/getdents.S b/libc/arch-x86/syscalls/getdents.S
deleted file mode 100644
index 9823feb..0000000
--- a/libc/arch-x86/syscalls/getdents.S
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getdents)
-    pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    mov     16(%esp), %ebx
-    mov     20(%esp), %ecx
-    mov     24(%esp), %edx
-    movl    $__NR_getdents64, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %edx
-    popl    %ecx
-    popl    %ebx
-    ret
-END(getdents)
diff --git a/libc/arch-x86/syscalls/getegid.S b/libc/arch-x86/syscalls/getegid.S
index 61e7839..729b7ad 100644
--- a/libc/arch-x86/syscalls/getegid.S
+++ b/libc/arch-x86/syscalls/getegid.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(getegid)
diff --git a/libc/arch-x86/syscalls/geteuid.S b/libc/arch-x86/syscalls/geteuid.S
index 80bcf7a..dcc76b1 100644
--- a/libc/arch-x86/syscalls/geteuid.S
+++ b/libc/arch-x86/syscalls/geteuid.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(geteuid)
diff --git a/libc/arch-x86/syscalls/getgid.S b/libc/arch-x86/syscalls/getgid.S
index 87d31a7..b36a2c9 100644
--- a/libc/arch-x86/syscalls/getgid.S
+++ b/libc/arch-x86/syscalls/getgid.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(getgid)
diff --git a/libc/arch-x86/syscalls/getgroups.S b/libc/arch-x86/syscalls/getgroups.S
index e4247e7..0a5de35 100644
--- a/libc/arch-x86/syscalls/getgroups.S
+++ b/libc/arch-x86/syscalls/getgroups.S
@@ -4,10 +4,11 @@
 
 ENTRY(getgroups)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_getgroups32, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getitimer.S b/libc/arch-x86/syscalls/getitimer.S
index 2deebc9..a0cb761 100644
--- a/libc/arch-x86/syscalls/getitimer.S
+++ b/libc/arch-x86/syscalls/getitimer.S
@@ -4,10 +4,11 @@
 
 ENTRY(getitimer)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_getitimer, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getpeername.S b/libc/arch-x86/syscalls/getpeername.S
index e894093..6773e6a 100644
--- a/libc/arch-x86/syscalls/getpeername.S
+++ b/libc/arch-x86/syscalls/getpeername.S
@@ -4,10 +4,11 @@
 
 ENTRY(getpeername)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $7, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getpgid.S b/libc/arch-x86/syscalls/getpgid.S
index c50a09f..f702cfd 100644
--- a/libc/arch-x86/syscalls/getpgid.S
+++ b/libc/arch-x86/syscalls/getpgid.S
@@ -4,7 +4,7 @@
 
 ENTRY(getpgid)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_getpgid, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/getpid.S b/libc/arch-x86/syscalls/getpid.S
deleted file mode 100644
index cecaf74..0000000
--- a/libc/arch-x86/syscalls/getpid.S
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getpid)
-    movl    $__NR_getpid, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    ret
-END(getpid)
diff --git a/libc/arch-x86/syscalls/getppid.S b/libc/arch-x86/syscalls/getppid.S
index b932044..edbe384 100644
--- a/libc/arch-x86/syscalls/getppid.S
+++ b/libc/arch-x86/syscalls/getppid.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(getppid)
diff --git a/libc/arch-x86/syscalls/getresgid.S b/libc/arch-x86/syscalls/getresgid.S
index ad74e56..9f1a9dd 100644
--- a/libc/arch-x86/syscalls/getresgid.S
+++ b/libc/arch-x86/syscalls/getresgid.S
@@ -4,12 +4,14 @@
 
 ENTRY(getresgid)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/getresuid.S b/libc/arch-x86/syscalls/getresuid.S
index 6cf60b3..61e1370 100644
--- a/libc/arch-x86/syscalls/getresuid.S
+++ b/libc/arch-x86/syscalls/getresuid.S
@@ -4,12 +4,14 @@
 
 ENTRY(getresuid)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/getrlimit.S b/libc/arch-x86/syscalls/getrlimit.S
index 5e75b6b..c3acff3 100644
--- a/libc/arch-x86/syscalls/getrlimit.S
+++ b/libc/arch-x86/syscalls/getrlimit.S
@@ -4,10 +4,11 @@
 
 ENTRY(getrlimit)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_ugetrlimit, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getrusage.S b/libc/arch-x86/syscalls/getrusage.S
index 2dfd005..0d715cd 100644
--- a/libc/arch-x86/syscalls/getrusage.S
+++ b/libc/arch-x86/syscalls/getrusage.S
@@ -4,10 +4,11 @@
 
 ENTRY(getrusage)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_getrusage, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getsid.S b/libc/arch-x86/syscalls/getsid.S
index 1f60309..e142c05 100644
--- a/libc/arch-x86/syscalls/getsid.S
+++ b/libc/arch-x86/syscalls/getsid.S
@@ -4,7 +4,7 @@
 
 ENTRY(getsid)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_getsid, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/getsockname.S b/libc/arch-x86/syscalls/getsockname.S
index 5c22bdf..6050190 100644
--- a/libc/arch-x86/syscalls/getsockname.S
+++ b/libc/arch-x86/syscalls/getsockname.S
@@ -4,10 +4,11 @@
 
 ENTRY(getsockname)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $6, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getsockopt.S b/libc/arch-x86/syscalls/getsockopt.S
index 9c02d23..aec40cf 100644
--- a/libc/arch-x86/syscalls/getsockopt.S
+++ b/libc/arch-x86/syscalls/getsockopt.S
@@ -4,10 +4,11 @@
 
 ENTRY(getsockopt)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $15, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/gettid.S b/libc/arch-x86/syscalls/gettid.S
deleted file mode 100644
index 1f264b1..0000000
--- a/libc/arch-x86/syscalls/gettid.S
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(gettid)
-    movl    $__NR_gettid, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    ret
-END(gettid)
diff --git a/libc/arch-x86/syscalls/gettimeofday.S b/libc/arch-x86/syscalls/gettimeofday.S
index 10c5de9..a508c14 100644
--- a/libc/arch-x86/syscalls/gettimeofday.S
+++ b/libc/arch-x86/syscalls/gettimeofday.S
@@ -4,10 +4,11 @@
 
 ENTRY(gettimeofday)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_gettimeofday, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/getuid.S b/libc/arch-x86/syscalls/getuid.S
index e91305a..cc62884 100644
--- a/libc/arch-x86/syscalls/getuid.S
+++ b/libc/arch-x86/syscalls/getuid.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(getuid)
diff --git a/libc/arch-x86/syscalls/getxattr.S b/libc/arch-x86/syscalls/getxattr.S
index f491a0c..a2cf137 100644
--- a/libc/arch-x86/syscalls/getxattr.S
+++ b/libc/arch-x86/syscalls/getxattr.S
@@ -4,14 +4,17 @@
 
 ENTRY(getxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/init_module.S b/libc/arch-x86/syscalls/init_module.S
index 1a159d3..1d0f111 100644
--- a/libc/arch-x86/syscalls/init_module.S
+++ b/libc/arch-x86/syscalls/init_module.S
@@ -4,12 +4,14 @@
 
 ENTRY(init_module)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/inotify_add_watch.S b/libc/arch-x86/syscalls/inotify_add_watch.S
index 424698d..8cadc6e 100644
--- a/libc/arch-x86/syscalls/inotify_add_watch.S
+++ b/libc/arch-x86/syscalls/inotify_add_watch.S
@@ -4,12 +4,14 @@
 
 ENTRY(inotify_add_watch)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/inotify_init1.S b/libc/arch-x86/syscalls/inotify_init1.S
index 1b437c6..23671e0 100644
--- a/libc/arch-x86/syscalls/inotify_init1.S
+++ b/libc/arch-x86/syscalls/inotify_init1.S
@@ -4,7 +4,7 @@
 
 ENTRY(inotify_init1)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_inotify_init1, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/inotify_rm_watch.S b/libc/arch-x86/syscalls/inotify_rm_watch.S
index 18ec3ca..c246c00 100644
--- a/libc/arch-x86/syscalls/inotify_rm_watch.S
+++ b/libc/arch-x86/syscalls/inotify_rm_watch.S
@@ -4,10 +4,11 @@
 
 ENTRY(inotify_rm_watch)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_inotify_rm_watch, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/ioprio_get.S b/libc/arch-x86/syscalls/ioprio_get.S
deleted file mode 100644
index 6dfc767..0000000
--- a/libc/arch-x86/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    pushl   %ebx
-    pushl   %ecx
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    mov     12(%esp), %ebx
-    mov     16(%esp), %ecx
-    movl    $__NR_ioprio_get, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %ecx
-    popl    %ebx
-    ret
-END(ioprio_get)
diff --git a/libc/arch-x86/syscalls/ioprio_set.S b/libc/arch-x86/syscalls/ioprio_set.S
deleted file mode 100644
index bcefacb..0000000
--- a/libc/arch-x86/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    mov     16(%esp), %ebx
-    mov     20(%esp), %ecx
-    mov     24(%esp), %edx
-    movl    $__NR_ioprio_set, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %edx
-    popl    %ecx
-    popl    %ebx
-    ret
-END(ioprio_set)
diff --git a/libc/arch-x86/syscalls/kill.S b/libc/arch-x86/syscalls/kill.S
index 499158b..edc9cde 100644
--- a/libc/arch-x86/syscalls/kill.S
+++ b/libc/arch-x86/syscalls/kill.S
@@ -4,10 +4,11 @@
 
 ENTRY(kill)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_kill, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/klogctl.S b/libc/arch-x86/syscalls/klogctl.S
index f422ac8..5de9a31 100644
--- a/libc/arch-x86/syscalls/klogctl.S
+++ b/libc/arch-x86/syscalls/klogctl.S
@@ -4,12 +4,14 @@
 
 ENTRY(klogctl)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/lgetxattr.S b/libc/arch-x86/syscalls/lgetxattr.S
index def7c66..55697a0 100644
--- a/libc/arch-x86/syscalls/lgetxattr.S
+++ b/libc/arch-x86/syscalls/lgetxattr.S
@@ -4,14 +4,17 @@
 
 ENTRY(lgetxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/linkat.S b/libc/arch-x86/syscalls/linkat.S
index ffb1b5d..8b2646d 100644
--- a/libc/arch-x86/syscalls/linkat.S
+++ b/libc/arch-x86/syscalls/linkat.S
@@ -4,16 +4,20 @@
 
 ENTRY(linkat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/listen.S b/libc/arch-x86/syscalls/listen.S
index 7e4d2f3..8ae4186 100644
--- a/libc/arch-x86/syscalls/listen.S
+++ b/libc/arch-x86/syscalls/listen.S
@@ -4,10 +4,11 @@
 
 ENTRY(listen)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $4, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/listxattr.S b/libc/arch-x86/syscalls/listxattr.S
index 5b94a72..a73dc1a 100644
--- a/libc/arch-x86/syscalls/listxattr.S
+++ b/libc/arch-x86/syscalls/listxattr.S
@@ -4,12 +4,14 @@
 
 ENTRY(listxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/llistxattr.S b/libc/arch-x86/syscalls/llistxattr.S
index 1c64591..63d4489 100644
--- a/libc/arch-x86/syscalls/llistxattr.S
+++ b/libc/arch-x86/syscalls/llistxattr.S
@@ -4,12 +4,14 @@
 
 ENTRY(llistxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/lremovexattr.S b/libc/arch-x86/syscalls/lremovexattr.S
index d67b221..42c7e0f 100644
--- a/libc/arch-x86/syscalls/lremovexattr.S
+++ b/libc/arch-x86/syscalls/lremovexattr.S
@@ -4,10 +4,11 @@
 
 ENTRY(lremovexattr)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_lremovexattr, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/lseek.S b/libc/arch-x86/syscalls/lseek.S
index 5a58b81..bfe9e63 100644
--- a/libc/arch-x86/syscalls/lseek.S
+++ b/libc/arch-x86/syscalls/lseek.S
@@ -4,12 +4,14 @@
 
 ENTRY(lseek)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/lsetxattr.S b/libc/arch-x86/syscalls/lsetxattr.S
index f2dba39..f36fc6a 100644
--- a/libc/arch-x86/syscalls/lsetxattr.S
+++ b/libc/arch-x86/syscalls/lsetxattr.S
@@ -4,16 +4,20 @@
 
 ENTRY(lsetxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/madvise.S b/libc/arch-x86/syscalls/madvise.S
index edd37b5..b69f5d4 100644
--- a/libc/arch-x86/syscalls/madvise.S
+++ b/libc/arch-x86/syscalls/madvise.S
@@ -4,12 +4,14 @@
 
 ENTRY(madvise)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/mincore.S b/libc/arch-x86/syscalls/mincore.S
index 44ea364..6d1df67 100644
--- a/libc/arch-x86/syscalls/mincore.S
+++ b/libc/arch-x86/syscalls/mincore.S
@@ -4,12 +4,14 @@
 
 ENTRY(mincore)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/mkdirat.S b/libc/arch-x86/syscalls/mkdirat.S
index d80e3fb..5b6ae18 100644
--- a/libc/arch-x86/syscalls/mkdirat.S
+++ b/libc/arch-x86/syscalls/mkdirat.S
@@ -4,12 +4,14 @@
 
 ENTRY(mkdirat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/mknodat.S b/libc/arch-x86/syscalls/mknodat.S
index 20560df..b19d972 100644
--- a/libc/arch-x86/syscalls/mknodat.S
+++ b/libc/arch-x86/syscalls/mknodat.S
@@ -4,14 +4,17 @@
 
 ENTRY(mknodat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/mlock.S b/libc/arch-x86/syscalls/mlock.S
index 78cfa58..517e5a5 100644
--- a/libc/arch-x86/syscalls/mlock.S
+++ b/libc/arch-x86/syscalls/mlock.S
@@ -4,10 +4,11 @@
 
 ENTRY(mlock)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_mlock, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/mlockall.S b/libc/arch-x86/syscalls/mlockall.S
index 4e78fef..756ca16 100644
--- a/libc/arch-x86/syscalls/mlockall.S
+++ b/libc/arch-x86/syscalls/mlockall.S
@@ -4,7 +4,7 @@
 
 ENTRY(mlockall)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_mlockall, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/mount.S b/libc/arch-x86/syscalls/mount.S
index cc1a518..0537528 100644
--- a/libc/arch-x86/syscalls/mount.S
+++ b/libc/arch-x86/syscalls/mount.S
@@ -4,16 +4,20 @@
 
 ENTRY(mount)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/mprotect.S b/libc/arch-x86/syscalls/mprotect.S
index 9c30af4..1ba186c 100644
--- a/libc/arch-x86/syscalls/mprotect.S
+++ b/libc/arch-x86/syscalls/mprotect.S
@@ -4,12 +4,14 @@
 
 ENTRY(mprotect)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/mremap.S b/libc/arch-x86/syscalls/mremap.S
index 1439ef5..869ef5d 100644
--- a/libc/arch-x86/syscalls/mremap.S
+++ b/libc/arch-x86/syscalls/mremap.S
@@ -4,14 +4,17 @@
 
 ENTRY(mremap)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/msync.S b/libc/arch-x86/syscalls/msync.S
index d330967..81bd598 100644
--- a/libc/arch-x86/syscalls/msync.S
+++ b/libc/arch-x86/syscalls/msync.S
@@ -4,12 +4,14 @@
 
 ENTRY(msync)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/munlock.S b/libc/arch-x86/syscalls/munlock.S
index ce6197d..67ca3fe 100644
--- a/libc/arch-x86/syscalls/munlock.S
+++ b/libc/arch-x86/syscalls/munlock.S
@@ -4,10 +4,11 @@
 
 ENTRY(munlock)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_munlock, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/munlockall.S b/libc/arch-x86/syscalls/munlockall.S
index 238f812..bf0bfa1 100644
--- a/libc/arch-x86/syscalls/munlockall.S
+++ b/libc/arch-x86/syscalls/munlockall.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(munlockall)
diff --git a/libc/arch-x86/syscalls/munmap.S b/libc/arch-x86/syscalls/munmap.S
index be7eec6..272cb52 100644
--- a/libc/arch-x86/syscalls/munmap.S
+++ b/libc/arch-x86/syscalls/munmap.S
@@ -4,10 +4,11 @@
 
 ENTRY(munmap)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_munmap, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/nanosleep.S b/libc/arch-x86/syscalls/nanosleep.S
index 9faa06b..5c46a4a 100644
--- a/libc/arch-x86/syscalls/nanosleep.S
+++ b/libc/arch-x86/syscalls/nanosleep.S
@@ -4,10 +4,11 @@
 
 ENTRY(nanosleep)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_nanosleep, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/perf_event_open.S b/libc/arch-x86/syscalls/perf_event_open.S
deleted file mode 100644
index ebbe1f0..0000000
--- a/libc/arch-x86/syscalls/perf_event_open.S
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(perf_event_open)
-    pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
-    mov     24(%esp), %ebx
-    mov     28(%esp), %ecx
-    mov     32(%esp), %edx
-    mov     36(%esp), %esi
-    mov     40(%esp), %edi
-    movl    $__NR_perf_event_open, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %edi
-    popl    %esi
-    popl    %edx
-    popl    %ecx
-    popl    %ebx
-    ret
-END(perf_event_open)
diff --git a/libc/arch-x86/syscalls/personality.S b/libc/arch-x86/syscalls/personality.S
index 8116e2d..d60ced1 100644
--- a/libc/arch-x86/syscalls/personality.S
+++ b/libc/arch-x86/syscalls/personality.S
@@ -4,7 +4,7 @@
 
 ENTRY(personality)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_personality, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/pipe2.S b/libc/arch-x86/syscalls/pipe2.S
index c2e11a2..ee49ff8 100644
--- a/libc/arch-x86/syscalls/pipe2.S
+++ b/libc/arch-x86/syscalls/pipe2.S
@@ -4,10 +4,11 @@
 
 ENTRY(pipe2)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_pipe2, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/prctl.S b/libc/arch-x86/syscalls/prctl.S
index 1a5daca..496591e 100644
--- a/libc/arch-x86/syscalls/prctl.S
+++ b/libc/arch-x86/syscalls/prctl.S
@@ -4,16 +4,20 @@
 
 ENTRY(prctl)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/pread64.S b/libc/arch-x86/syscalls/pread64.S
index 32a76c5..42e54ec 100644
--- a/libc/arch-x86/syscalls/pread64.S
+++ b/libc/arch-x86/syscalls/pread64.S
@@ -4,16 +4,20 @@
 
 ENTRY(pread64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/prlimit64.S b/libc/arch-x86/syscalls/prlimit64.S
index 2256425..07b5585 100644
--- a/libc/arch-x86/syscalls/prlimit64.S
+++ b/libc/arch-x86/syscalls/prlimit64.S
@@ -4,14 +4,17 @@
 
 ENTRY(prlimit64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/pwrite64.S b/libc/arch-x86/syscalls/pwrite64.S
index b003435..d5c9b31 100644
--- a/libc/arch-x86/syscalls/pwrite64.S
+++ b/libc/arch-x86/syscalls/pwrite64.S
@@ -4,16 +4,20 @@
 
 ENTRY(pwrite64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/read.S b/libc/arch-x86/syscalls/read.S
index ad1c19a..c10a83b 100644
--- a/libc/arch-x86/syscalls/read.S
+++ b/libc/arch-x86/syscalls/read.S
@@ -4,12 +4,14 @@
 
 ENTRY(read)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/readahead.S b/libc/arch-x86/syscalls/readahead.S
index a4d634f..1c0ccfc 100644
--- a/libc/arch-x86/syscalls/readahead.S
+++ b/libc/arch-x86/syscalls/readahead.S
@@ -4,14 +4,17 @@
 
 ENTRY(readahead)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/readlinkat.S b/libc/arch-x86/syscalls/readlinkat.S
index 37df8d8..4a24c2c 100644
--- a/libc/arch-x86/syscalls/readlinkat.S
+++ b/libc/arch-x86/syscalls/readlinkat.S
@@ -4,14 +4,17 @@
 
 ENTRY(readlinkat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/readv.S b/libc/arch-x86/syscalls/readv.S
index 05445c0..c18c1b1 100644
--- a/libc/arch-x86/syscalls/readv.S
+++ b/libc/arch-x86/syscalls/readv.S
@@ -4,12 +4,14 @@
 
 ENTRY(readv)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/recvfrom.S b/libc/arch-x86/syscalls/recvfrom.S
index df489c8..88c9d0a 100644
--- a/libc/arch-x86/syscalls/recvfrom.S
+++ b/libc/arch-x86/syscalls/recvfrom.S
@@ -4,10 +4,11 @@
 
 ENTRY(recvfrom)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $12, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/recvmmsg.S b/libc/arch-x86/syscalls/recvmmsg.S
new file mode 100644
index 0000000..09404d4
--- /dev/null
+++ b/libc/arch-x86/syscalls/recvmmsg.S
@@ -0,0 +1,27 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(recvmmsg)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    mov     $19, %ebx
+    mov     %esp, %ecx
+    addl    $12, %ecx
+    movl    $__NR_socketcall, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
+END(recvmmsg)
diff --git a/libc/arch-x86/syscalls/recvmsg.S b/libc/arch-x86/syscalls/recvmsg.S
index a587b00..6cfcd63 100644
--- a/libc/arch-x86/syscalls/recvmsg.S
+++ b/libc/arch-x86/syscalls/recvmsg.S
@@ -4,10 +4,11 @@
 
 ENTRY(recvmsg)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $17, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/removexattr.S b/libc/arch-x86/syscalls/removexattr.S
index 99192f0..b067a9f 100644
--- a/libc/arch-x86/syscalls/removexattr.S
+++ b/libc/arch-x86/syscalls/removexattr.S
@@ -4,10 +4,11 @@
 
 ENTRY(removexattr)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_removexattr, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/renameat.S b/libc/arch-x86/syscalls/renameat.S
index 831b24c..bb2181e 100644
--- a/libc/arch-x86/syscalls/renameat.S
+++ b/libc/arch-x86/syscalls/renameat.S
@@ -4,14 +4,17 @@
 
 ENTRY(renameat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/sched_get_priority_max.S b/libc/arch-x86/syscalls/sched_get_priority_max.S
index 0b7c269..be66cfb 100644
--- a/libc/arch-x86/syscalls/sched_get_priority_max.S
+++ b/libc/arch-x86/syscalls/sched_get_priority_max.S
@@ -4,7 +4,7 @@
 
 ENTRY(sched_get_priority_max)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_sched_get_priority_max, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sched_get_priority_min.S b/libc/arch-x86/syscalls/sched_get_priority_min.S
index ce28f8c..8dde67b 100644
--- a/libc/arch-x86/syscalls/sched_get_priority_min.S
+++ b/libc/arch-x86/syscalls/sched_get_priority_min.S
@@ -4,7 +4,7 @@
 
 ENTRY(sched_get_priority_min)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_sched_get_priority_min, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sched_getparam.S b/libc/arch-x86/syscalls/sched_getparam.S
index 2c3b7b9..d0551ef 100644
--- a/libc/arch-x86/syscalls/sched_getparam.S
+++ b/libc/arch-x86/syscalls/sched_getparam.S
@@ -4,10 +4,11 @@
 
 ENTRY(sched_getparam)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_sched_getparam, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sched_getscheduler.S b/libc/arch-x86/syscalls/sched_getscheduler.S
index 6a3842a..5b7c817 100644
--- a/libc/arch-x86/syscalls/sched_getscheduler.S
+++ b/libc/arch-x86/syscalls/sched_getscheduler.S
@@ -4,7 +4,7 @@
 
 ENTRY(sched_getscheduler)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_sched_getscheduler, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sched_rr_get_interval.S b/libc/arch-x86/syscalls/sched_rr_get_interval.S
index c1055da..073f3c7 100644
--- a/libc/arch-x86/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-x86/syscalls/sched_rr_get_interval.S
@@ -4,10 +4,11 @@
 
 ENTRY(sched_rr_get_interval)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_sched_rr_get_interval, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sched_setaffinity.S b/libc/arch-x86/syscalls/sched_setaffinity.S
index bd3d0ab..79ec113 100644
--- a/libc/arch-x86/syscalls/sched_setaffinity.S
+++ b/libc/arch-x86/syscalls/sched_setaffinity.S
@@ -4,12 +4,14 @@
 
 ENTRY(sched_setaffinity)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/sched_setparam.S b/libc/arch-x86/syscalls/sched_setparam.S
index 2329268..970747d 100644
--- a/libc/arch-x86/syscalls/sched_setparam.S
+++ b/libc/arch-x86/syscalls/sched_setparam.S
@@ -4,10 +4,11 @@
 
 ENTRY(sched_setparam)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_sched_setparam, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sched_setscheduler.S b/libc/arch-x86/syscalls/sched_setscheduler.S
index a3ce8ab..da50aaf 100644
--- a/libc/arch-x86/syscalls/sched_setscheduler.S
+++ b/libc/arch-x86/syscalls/sched_setscheduler.S
@@ -4,12 +4,14 @@
 
 ENTRY(sched_setscheduler)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/sched_yield.S b/libc/arch-x86/syscalls/sched_yield.S
index fb563c4..e3878e3 100644
--- a/libc/arch-x86/syscalls/sched_yield.S
+++ b/libc/arch-x86/syscalls/sched_yield.S
@@ -4,7 +4,7 @@
 
 ENTRY(sched_yield)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_sched_yield, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sendfile.S b/libc/arch-x86/syscalls/sendfile.S
index 280a4ae..c5f9a2d 100644
--- a/libc/arch-x86/syscalls/sendfile.S
+++ b/libc/arch-x86/syscalls/sendfile.S
@@ -4,14 +4,17 @@
 
 ENTRY(sendfile)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/sendfile64.S b/libc/arch-x86/syscalls/sendfile64.S
index 383c8c6..bc5d0dd 100644
--- a/libc/arch-x86/syscalls/sendfile64.S
+++ b/libc/arch-x86/syscalls/sendfile64.S
@@ -4,14 +4,17 @@
 
 ENTRY(sendfile64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/sendmmsg.S b/libc/arch-x86/syscalls/sendmmsg.S
new file mode 100644
index 0000000..784c6b6
--- /dev/null
+++ b/libc/arch-x86/syscalls/sendmmsg.S
@@ -0,0 +1,27 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendmmsg)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    mov     $20, %ebx
+    mov     %esp, %ecx
+    addl    $12, %ecx
+    movl    $__NR_socketcall, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
+END(sendmmsg)
diff --git a/libc/arch-x86/syscalls/sendmsg.S b/libc/arch-x86/syscalls/sendmsg.S
index 70bad29..bf0d1fb 100644
--- a/libc/arch-x86/syscalls/sendmsg.S
+++ b/libc/arch-x86/syscalls/sendmsg.S
@@ -4,10 +4,11 @@
 
 ENTRY(sendmsg)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $16, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sendto.S b/libc/arch-x86/syscalls/sendto.S
index dbe520d..b39eaf0 100644
--- a/libc/arch-x86/syscalls/sendto.S
+++ b/libc/arch-x86/syscalls/sendto.S
@@ -4,10 +4,11 @@
 
 ENTRY(sendto)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $11, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setfsgid.S b/libc/arch-x86/syscalls/setfsgid.S
new file mode 100644
index 0000000..dc81f72
--- /dev/null
+++ b/libc/arch-x86/syscalls/setfsgid.S
@@ -0,0 +1,21 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsgid)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    mov     8(%esp), %ebx
+    movl    $__NR_setfsgid, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ebx
+    ret
+END(setfsgid)
diff --git a/libc/arch-x86/syscalls/setfsuid.S b/libc/arch-x86/syscalls/setfsuid.S
new file mode 100644
index 0000000..fdf7850
--- /dev/null
+++ b/libc/arch-x86/syscalls/setfsuid.S
@@ -0,0 +1,21 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsuid)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    mov     8(%esp), %ebx
+    movl    $__NR_setfsuid, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ebx
+    ret
+END(setfsuid)
diff --git a/libc/arch-x86/syscalls/setgid.S b/libc/arch-x86/syscalls/setgid.S
index 69ac15b..ce6ee26 100644
--- a/libc/arch-x86/syscalls/setgid.S
+++ b/libc/arch-x86/syscalls/setgid.S
@@ -4,7 +4,7 @@
 
 ENTRY(setgid)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_setgid32, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/setgroups.S b/libc/arch-x86/syscalls/setgroups.S
index f704c46..7e46ad0 100644
--- a/libc/arch-x86/syscalls/setgroups.S
+++ b/libc/arch-x86/syscalls/setgroups.S
@@ -4,10 +4,11 @@
 
 ENTRY(setgroups)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_setgroups32, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setitimer.S b/libc/arch-x86/syscalls/setitimer.S
index 1573816..370ab5e 100644
--- a/libc/arch-x86/syscalls/setitimer.S
+++ b/libc/arch-x86/syscalls/setitimer.S
@@ -4,12 +4,14 @@
 
 ENTRY(setitimer)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/setns.S b/libc/arch-x86/syscalls/setns.S
index 2c39a21..736df59 100644
--- a/libc/arch-x86/syscalls/setns.S
+++ b/libc/arch-x86/syscalls/setns.S
@@ -4,10 +4,11 @@
 
 ENTRY(setns)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_setns, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setpgid.S b/libc/arch-x86/syscalls/setpgid.S
index ae69633..0bff10a 100644
--- a/libc/arch-x86/syscalls/setpgid.S
+++ b/libc/arch-x86/syscalls/setpgid.S
@@ -4,10 +4,11 @@
 
 ENTRY(setpgid)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_setpgid, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setpriority.S b/libc/arch-x86/syscalls/setpriority.S
index b58cd13..4233871 100644
--- a/libc/arch-x86/syscalls/setpriority.S
+++ b/libc/arch-x86/syscalls/setpriority.S
@@ -4,12 +4,14 @@
 
 ENTRY(setpriority)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/setregid.S b/libc/arch-x86/syscalls/setregid.S
index 561a658..a56ccfd 100644
--- a/libc/arch-x86/syscalls/setregid.S
+++ b/libc/arch-x86/syscalls/setregid.S
@@ -4,10 +4,11 @@
 
 ENTRY(setregid)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_setregid32, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setresgid.S b/libc/arch-x86/syscalls/setresgid.S
index a210975..2299831 100644
--- a/libc/arch-x86/syscalls/setresgid.S
+++ b/libc/arch-x86/syscalls/setresgid.S
@@ -4,12 +4,14 @@
 
 ENTRY(setresgid)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/setresuid.S b/libc/arch-x86/syscalls/setresuid.S
index 920e68b..8624e15 100644
--- a/libc/arch-x86/syscalls/setresuid.S
+++ b/libc/arch-x86/syscalls/setresuid.S
@@ -4,12 +4,14 @@
 
 ENTRY(setresuid)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/setreuid.S b/libc/arch-x86/syscalls/setreuid.S
index 7f911ad..9f6e117 100644
--- a/libc/arch-x86/syscalls/setreuid.S
+++ b/libc/arch-x86/syscalls/setreuid.S
@@ -4,10 +4,11 @@
 
 ENTRY(setreuid)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_setreuid32, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setrlimit.S b/libc/arch-x86/syscalls/setrlimit.S
index e103ecf..2024688 100644
--- a/libc/arch-x86/syscalls/setrlimit.S
+++ b/libc/arch-x86/syscalls/setrlimit.S
@@ -4,10 +4,11 @@
 
 ENTRY(setrlimit)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_setrlimit, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setsid.S b/libc/arch-x86/syscalls/setsid.S
index 382ad0c..dda6ad8 100644
--- a/libc/arch-x86/syscalls/setsid.S
+++ b/libc/arch-x86/syscalls/setsid.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     ret
 END(setsid)
diff --git a/libc/arch-x86/syscalls/setsockopt.S b/libc/arch-x86/syscalls/setsockopt.S
index f56f812..29e73bb 100644
--- a/libc/arch-x86/syscalls/setsockopt.S
+++ b/libc/arch-x86/syscalls/setsockopt.S
@@ -4,10 +4,11 @@
 
 ENTRY(setsockopt)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $14, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/settimeofday.S b/libc/arch-x86/syscalls/settimeofday.S
index 1ae4d58..4a861ab 100644
--- a/libc/arch-x86/syscalls/settimeofday.S
+++ b/libc/arch-x86/syscalls/settimeofday.S
@@ -4,10 +4,11 @@
 
 ENTRY(settimeofday)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_settimeofday, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/setuid.S b/libc/arch-x86/syscalls/setuid.S
index 6549fd4..048e0c1 100644
--- a/libc/arch-x86/syscalls/setuid.S
+++ b/libc/arch-x86/syscalls/setuid.S
@@ -4,7 +4,7 @@
 
 ENTRY(setuid)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_setuid32, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/setxattr.S b/libc/arch-x86/syscalls/setxattr.S
index fae04df..1e87bf0 100644
--- a/libc/arch-x86/syscalls/setxattr.S
+++ b/libc/arch-x86/syscalls/setxattr.S
@@ -4,16 +4,20 @@
 
 ENTRY(setxattr)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    pushl   %edi
-    .cfi_def_cfa_offset 20
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    .cfi_rel_offset edi, 16
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
     mov     24(%esp), %ebx
     mov     28(%esp), %ecx
     mov     32(%esp), %edx
@@ -25,9 +29,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edi
     popl    %esi
diff --git a/libc/arch-x86/syscalls/shutdown.S b/libc/arch-x86/syscalls/shutdown.S
index 13e8fd9..f224fc6 100644
--- a/libc/arch-x86/syscalls/shutdown.S
+++ b/libc/arch-x86/syscalls/shutdown.S
@@ -4,10 +4,11 @@
 
 ENTRY(shutdown)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $13, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/sigaltstack.S b/libc/arch-x86/syscalls/sigaltstack.S
index 71fdb12..875ef8c 100644
--- a/libc/arch-x86/syscalls/sigaltstack.S
+++ b/libc/arch-x86/syscalls/sigaltstack.S
@@ -4,10 +4,11 @@
 
 ENTRY(sigaltstack)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_sigaltstack, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/signalfd4.S b/libc/arch-x86/syscalls/signalfd4.S
deleted file mode 100644
index 1fe6c68..0000000
--- a/libc/arch-x86/syscalls/signalfd4.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(signalfd4)
-    pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
-    mov     20(%esp), %ebx
-    mov     24(%esp), %ecx
-    mov     28(%esp), %edx
-    mov     32(%esp), %esi
-    movl    $__NR_signalfd4, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %esi
-    popl    %edx
-    popl    %ecx
-    popl    %ebx
-    ret
-END(signalfd4)
diff --git a/libc/arch-x86/syscalls/socket.S b/libc/arch-x86/syscalls/socket.S
deleted file mode 100644
index 282681e..0000000
--- a/libc/arch-x86/syscalls/socket.S
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(socket)
-    pushl   %ebx
-    pushl   %ecx
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    mov     $1, %ebx
-    mov     %esp, %ecx
-    addl    $12, %ecx
-    movl    $__NR_socketcall, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %ecx
-    popl    %ebx
-    ret
-END(socket)
diff --git a/libc/arch-x86/syscalls/socketpair.S b/libc/arch-x86/syscalls/socketpair.S
index 3681c4f..4c5154e 100644
--- a/libc/arch-x86/syscalls/socketpair.S
+++ b/libc/arch-x86/syscalls/socketpair.S
@@ -4,10 +4,11 @@
 
 ENTRY(socketpair)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     $8, %ebx
     mov     %esp, %ecx
     addl    $12, %ecx
@@ -17,9 +18,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/splice.S b/libc/arch-x86/syscalls/splice.S
new file mode 100644
index 0000000..1dc9037
--- /dev/null
+++ b/libc/arch-x86/syscalls/splice.S
@@ -0,0 +1,46 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
+    pushl   %ebp
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ebp, 0
+    mov     28(%esp), %ebx
+    mov     32(%esp), %ecx
+    mov     36(%esp), %edx
+    mov     40(%esp), %esi
+    mov     44(%esp), %edi
+    mov     48(%esp), %ebp
+    movl    $__NR_splice, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ebp
+    popl    %edi
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(splice)
diff --git a/libc/arch-x86/syscalls/swapoff.S b/libc/arch-x86/syscalls/swapoff.S
index 31f8be1..0788529 100644
--- a/libc/arch-x86/syscalls/swapoff.S
+++ b/libc/arch-x86/syscalls/swapoff.S
@@ -4,7 +4,7 @@
 
 ENTRY(swapoff)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_swapoff, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/swapon.S b/libc/arch-x86/syscalls/swapon.S
index 687c492..1070d8e 100644
--- a/libc/arch-x86/syscalls/swapon.S
+++ b/libc/arch-x86/syscalls/swapon.S
@@ -4,10 +4,11 @@
 
 ENTRY(swapon)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_swapon, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/symlinkat.S b/libc/arch-x86/syscalls/symlinkat.S
index 1f33f7b..e7fe69e 100644
--- a/libc/arch-x86/syscalls/symlinkat.S
+++ b/libc/arch-x86/syscalls/symlinkat.S
@@ -4,12 +4,14 @@
 
 ENTRY(symlinkat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/sync.S b/libc/arch-x86/syscalls/sync.S
index f80296f..252c666 100644
--- a/libc/arch-x86/syscalls/sync.S
+++ b/libc/arch-x86/syscalls/sync.S
@@ -4,7 +4,7 @@
 
 ENTRY(sync)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_sync, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/sysinfo.S b/libc/arch-x86/syscalls/sysinfo.S
index 8b9a23e..f59a0c3 100644
--- a/libc/arch-x86/syscalls/sysinfo.S
+++ b/libc/arch-x86/syscalls/sysinfo.S
@@ -4,7 +4,7 @@
 
 ENTRY(sysinfo)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_sysinfo, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/tee.S b/libc/arch-x86/syscalls/tee.S
new file mode 100644
index 0000000..b47c460
--- /dev/null
+++ b/libc/arch-x86/syscalls/tee.S
@@ -0,0 +1,36 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(tee)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    mov     20(%esp), %ebx
+    mov     24(%esp), %ecx
+    mov     28(%esp), %edx
+    mov     32(%esp), %esi
+    movl    $__NR_tee, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(tee)
diff --git a/libc/arch-x86/syscalls/tgkill.S b/libc/arch-x86/syscalls/tgkill.S
index e57645c..7a43a01 100644
--- a/libc/arch-x86/syscalls/tgkill.S
+++ b/libc/arch-x86/syscalls/tgkill.S
@@ -4,12 +4,14 @@
 
 ENTRY(tgkill)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/timerfd_create.S b/libc/arch-x86/syscalls/timerfd_create.S
index 33b2980..ad099a5 100644
--- a/libc/arch-x86/syscalls/timerfd_create.S
+++ b/libc/arch-x86/syscalls/timerfd_create.S
@@ -4,10 +4,11 @@
 
 ENTRY(timerfd_create)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_timerfd_create, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/timerfd_gettime.S b/libc/arch-x86/syscalls/timerfd_gettime.S
index 66b004b..c679b7c 100644
--- a/libc/arch-x86/syscalls/timerfd_gettime.S
+++ b/libc/arch-x86/syscalls/timerfd_gettime.S
@@ -4,10 +4,11 @@
 
 ENTRY(timerfd_gettime)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_timerfd_gettime, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/timerfd_settime.S b/libc/arch-x86/syscalls/timerfd_settime.S
index 3f4035e..4e889ea 100644
--- a/libc/arch-x86/syscalls/timerfd_settime.S
+++ b/libc/arch-x86/syscalls/timerfd_settime.S
@@ -4,14 +4,17 @@
 
 ENTRY(timerfd_settime)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/times.S b/libc/arch-x86/syscalls/times.S
index b9e2845..0ba0b6f 100644
--- a/libc/arch-x86/syscalls/times.S
+++ b/libc/arch-x86/syscalls/times.S
@@ -4,7 +4,7 @@
 
 ENTRY(times)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_times, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/tkill.S b/libc/arch-x86/syscalls/tkill.S
deleted file mode 100644
index f8da369..0000000
--- a/libc/arch-x86/syscalls/tkill.S
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(tkill)
-    pushl   %ebx
-    pushl   %ecx
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    mov     12(%esp), %ebx
-    mov     16(%esp), %ecx
-    movl    $__NR_tkill, %eax
-    int     $0x80
-    cmpl    $-MAX_ERRNO, %eax
-    jb      1f
-    negl    %eax
-    pushl   %eax
-    call    __set_errno
-    addl    $4, %esp
-    orl     $-1, %eax
-1:
-    popl    %ecx
-    popl    %ebx
-    ret
-END(tkill)
diff --git a/libc/arch-x86/syscalls/truncate.S b/libc/arch-x86/syscalls/truncate.S
index 019894c..31fec17 100644
--- a/libc/arch-x86/syscalls/truncate.S
+++ b/libc/arch-x86/syscalls/truncate.S
@@ -4,10 +4,11 @@
 
 ENTRY(truncate)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_truncate, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/truncate64.S b/libc/arch-x86/syscalls/truncate64.S
index 99b71b0..45e24d0 100644
--- a/libc/arch-x86/syscalls/truncate64.S
+++ b/libc/arch-x86/syscalls/truncate64.S
@@ -4,12 +4,14 @@
 
 ENTRY(truncate64)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/umask.S b/libc/arch-x86/syscalls/umask.S
index 485b326..9b4d3c7 100644
--- a/libc/arch-x86/syscalls/umask.S
+++ b/libc/arch-x86/syscalls/umask.S
@@ -4,7 +4,7 @@
 
 ENTRY(umask)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_umask, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/umount2.S b/libc/arch-x86/syscalls/umount2.S
index 100d38c..13757ab 100644
--- a/libc/arch-x86/syscalls/umount2.S
+++ b/libc/arch-x86/syscalls/umount2.S
@@ -4,10 +4,11 @@
 
 ENTRY(umount2)
     pushl   %ebx
-    pushl   %ecx
     .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
     mov     12(%esp), %ebx
     mov     16(%esp), %ecx
     movl    $__NR_umount2, %eax
@@ -16,9 +17,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ecx
     popl    %ebx
diff --git a/libc/arch-x86/syscalls/uname.S b/libc/arch-x86/syscalls/uname.S
index f1ba3b9..dab7e0d 100644
--- a/libc/arch-x86/syscalls/uname.S
+++ b/libc/arch-x86/syscalls/uname.S
@@ -4,7 +4,7 @@
 
 ENTRY(uname)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_uname, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/unlinkat.S b/libc/arch-x86/syscalls/unlinkat.S
index 1a573d4..6faf71e 100644
--- a/libc/arch-x86/syscalls/unlinkat.S
+++ b/libc/arch-x86/syscalls/unlinkat.S
@@ -4,12 +4,14 @@
 
 ENTRY(unlinkat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/unshare.S b/libc/arch-x86/syscalls/unshare.S
index 95fdbf6..b724798 100644
--- a/libc/arch-x86/syscalls/unshare.S
+++ b/libc/arch-x86/syscalls/unshare.S
@@ -4,7 +4,7 @@
 
 ENTRY(unshare)
     pushl   %ebx
-    .cfi_def_cfa_offset 4
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
     mov     8(%esp), %ebx
     movl    $__NR_unshare, %eax
@@ -13,9 +13,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %ebx
     ret
diff --git a/libc/arch-x86/syscalls/utimensat.S b/libc/arch-x86/syscalls/utimensat.S
index 099f551..07eca45 100644
--- a/libc/arch-x86/syscalls/utimensat.S
+++ b/libc/arch-x86/syscalls/utimensat.S
@@ -4,14 +4,17 @@
 
 ENTRY(utimensat)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/vmsplice.S b/libc/arch-x86/syscalls/vmsplice.S
new file mode 100644
index 0000000..f12cc65
--- /dev/null
+++ b/libc/arch-x86/syscalls/vmsplice.S
@@ -0,0 +1,36 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(vmsplice)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    mov     20(%esp), %ebx
+    mov     24(%esp), %ecx
+    mov     28(%esp), %edx
+    mov     32(%esp), %esi
+    movl    $__NR_vmsplice, %eax
+    int     $0x80
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(vmsplice)
diff --git a/libc/arch-x86/syscalls/wait4.S b/libc/arch-x86/syscalls/wait4.S
index b6196f8..bed7c40 100644
--- a/libc/arch-x86/syscalls/wait4.S
+++ b/libc/arch-x86/syscalls/wait4.S
@@ -4,14 +4,17 @@
 
 ENTRY(wait4)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    pushl   %esi
-    .cfi_def_cfa_offset 16
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
-    .cfi_rel_offset esi, 12
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
     mov     20(%esp), %ebx
     mov     24(%esp), %ecx
     mov     28(%esp), %edx
@@ -22,9 +25,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %esi
     popl    %edx
diff --git a/libc/arch-x86/syscalls/write.S b/libc/arch-x86/syscalls/write.S
index 971cb30..e147208 100644
--- a/libc/arch-x86/syscalls/write.S
+++ b/libc/arch-x86/syscalls/write.S
@@ -4,12 +4,14 @@
 
 ENTRY(write)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/syscalls/writev.S b/libc/arch-x86/syscalls/writev.S
index ab8e705..07ba7b5 100644
--- a/libc/arch-x86/syscalls/writev.S
+++ b/libc/arch-x86/syscalls/writev.S
@@ -4,12 +4,14 @@
 
 ENTRY(writev)
     pushl   %ebx
-    pushl   %ecx
-    pushl   %edx
-    .cfi_def_cfa_offset 12
+    .cfi_def_cfa_offset 8
     .cfi_rel_offset ebx, 0
-    .cfi_rel_offset ecx, 4
-    .cfi_rel_offset edx, 8
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
     mov     16(%esp), %ebx
     mov     20(%esp), %ecx
     mov     24(%esp), %edx
@@ -19,9 +21,8 @@
     jb      1f
     negl    %eax
     pushl   %eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %esp
-    orl     $-1, %eax
 1:
     popl    %edx
     popl    %ecx
diff --git a/libc/arch-x86/x86.mk b/libc/arch-x86/x86.mk
index 9c74084..2a0609d 100644
--- a/libc/arch-x86/x86.mk
+++ b/libc/arch-x86/x86.mk
@@ -1,8 +1,31 @@
-_LIBC_ARCH_COMMON_SRC_FILES := \
+# x86 specific configs
+
+# These are shared by all the 32-bit targets, but not the 64-bit ones.
+libc_common_src_files_x86 := \
+    bionic/legacy_32_bit_support.cpp \
+    bionic/ndk_cruft.cpp \
+    bionic/time64.c \
+    upstream-openbsd/lib/libc/stdio/putw.c \
+
+# Fortify implementations of libc functions.
+libc_common_src_files_x86 += \
+    bionic/__memcpy_chk.cpp \
+    bionic/__memset_chk.cpp \
+    bionic/__strcpy_chk.cpp \
+    bionic/__strcat_chk.cpp \
+    upstream-freebsd/lib/libc/string/wmemmove.c \
+
+
+# These are shared by all the 32-bit targets, but not the 64-bit ones.
+libc_bionic_src_files_x86 := \
+    bionic/mmap.cpp
+
+##########################################
+### CPU specific source files
+libc_bionic_src_files_x86 += \
     arch-x86/bionic/__bionic_clone.S \
     arch-x86/bionic/_exit_with_stack_teardown.S \
-    arch-x86/bionic/futex_x86.S \
-    arch-x86/bionic/__get_sp.S \
+    arch-x86/bionic/libgcc_compat.c \
     arch-x86/bionic/_setjmp.S \
     arch-x86/bionic/setjmp.S \
     arch-x86/bionic/__set_tls.c \
@@ -10,60 +33,30 @@
     arch-x86/bionic/syscall.S \
     arch-x86/bionic/vfork.S \
 
-ifeq ($(ARCH_X86_HAVE_SSSE3),true)
-_LIBC_ARCH_COMMON_SRC_FILES += \
-	arch-x86/string/ssse3-memcpy-atom.S \
-	arch-x86/string/ssse3-memmove-atom.S \
-	arch-x86/string/ssse3-bcopy-atom.S \
-	arch-x86/string/ssse3-strncat-atom.S \
-	arch-x86/string/ssse3-strncpy-atom.S \
-	arch-x86/string/ssse3-strlcat-atom.S \
-	arch-x86/string/ssse3-strlcpy-atom.S \
-	arch-x86/string/ssse3-strcmp-atom.S \
-	arch-x86/string/ssse3-strncmp-atom.S \
-	arch-x86/string/ssse3-strcat-atom.S \
-	arch-x86/string/ssse3-strcpy-atom.S \
-	arch-x86/string/ssse3-memcmp-atom.S \
-	arch-x86/string/ssse3-wmemcmp-atom.S \
-	arch-x86/string/ssse3-memcmp16-atom.S \
-	arch-x86/string/ssse3-wcscat-atom.S \
-	arch-x86/string/ssse3-wcscpy-atom.S
-else
-_LIBC_ARCH_COMMON_SRC_FILES += \
-	arch-x86/string/memcpy.S \
-	arch-x86/string/memmove.S \
-	arch-x86/string/bcopy.S \
-	arch-x86/string/strcmp.S \
-	arch-x86/string/strncmp.S \
-	arch-x86/string/strcat.S \
-	arch-x86/string/memcmp.S \
-	string/memcmp16.c \
-	string/strcpy.c \
-	string/strncat.c \
-	string/strncpy.c \
-	string/strlcat.c \
-	string/strlcpy.c \
-	upstream-freebsd/lib/libc/string/wcscpy.c \
-	upstream-freebsd/lib/libc/string/wcscat.c \
-	upstream-freebsd/lib/libc/string/wmemcmp.c
+## ARCH variant specific source files
+arch_variant_mk := $(LOCAL_PATH)/arch-x86/$(TARGET_ARCH_VARIANT)/$(TARGET_ARCH_VARIANT).mk
+ifeq ($(wildcard $(arch_variant_mk)),)
+    arch_variant_mk := $(LOCAL_PATH)/arch-x86/generic/generic.mk
 endif
+include $(arch_variant_mk)
+libc_common_additional_dependencies += $(arch_variant_mk)
 
-_LIBC_ARCH_COMMON_SRC_FILES += \
-	arch-x86/string/sse2-memset-atom.S \
-	arch-x86/string/sse2-bzero-atom.S \
-	arch-x86/string/sse2-memchr-atom.S \
-	arch-x86/string/sse2-memrchr-atom.S \
-	arch-x86/string/sse2-strchr-atom.S \
-	arch-x86/string/sse2-strrchr-atom.S \
-	arch-x86/string/sse2-index-atom.S \
-	arch-x86/string/sse2-strlen-atom.S \
-	arch-x86/string/sse2-strnlen-atom.S \
-	arch-x86/string/sse2-wcschr-atom.S \
-	arch-x86/string/sse2-wcsrchr-atom.S \
-	arch-x86/string/sse2-wcslen-atom.S \
-	arch-x86/string/sse2-wcscmp-atom.S \
+libc_netbsd_src_files_x86 := \
+    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
 
-_LIBC_ARCH_STATIC_SRC_FILES := \
-    bionic/dl_iterate_phdr_static.c \
+arch_variant_mk :=
 
-_LIBC_ARCH_DYNAMIC_SRC_FILES :=
+libc_crt_target_cflags_x86 := \
+    -m32 \
+    -I$(LOCAL_PATH)/arch-x86/include
+
+libc_crt_target_ldflags_x86 := -melf_i386
+
+libc_crt_target_crtbegin_file_x86 := \
+     $(LOCAL_PATH)/arch-common/bionic/crtbegin.c
+
+libc_crt_target_crtbegin_so_file_x86 := \
+    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
+
+libc_crt_target_so_cflags_x86 := \
+    -fPIC
diff --git a/libc/arch-x86_64/bionic/__bionic_clone.S b/libc/arch-x86_64/bionic/__bionic_clone.S
index 7692013..0c73e5f 100644
--- a/libc/arch-x86_64/bionic/__bionic_clone.S
+++ b/libc/arch-x86_64/bionic/__bionic_clone.S
@@ -26,14 +26,10 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
 ENTRY(__bionic_clone)
-        # Enforce 16-byte alignment for child stack.
-        andq    $~15, %rsi
-
         # Copy 'fn' and 'arg' onto the child stack.
         movq    %r9, -16(%rsi)  # fn
         movq    8(%rsp), %rax   # Read 'arg'.
@@ -49,25 +45,33 @@
         # Make the system call.
         movl    $__NR_clone, %eax
         syscall
-        testl   %eax, %eax
-        jns     1f
+
+        # Check result.
+        testq   %rax, %rax
+        jz      .L_bc_child
+        jg      .L_bc_parent
 
         # An error occurred, set errno and return -1.
         negl    %eax
         movl    %eax, %edi
-        call    __set_errno
-        orl     $-1, %eax
-        jmp     2f
-1:
-        jnz     2f
+        call    __set_errno_internal
+        ret
 
-        # We're in the child now, so call __bionic_clone_entry
+.L_bc_child:
+        # We don't want anyone to unwind past this point.
+        .cfi_undefined %rip
+        .cfi_undefined %rbp
+
+        # We're in the child now, so call __start_thread
         # with the arguments from the child stack moved into
         # the appropriate registers.
         popq    %rdi  # fn
         popq    %rsi  # arg
-        call    __bionic_clone_entry
+        call    __start_thread
         hlt
-2:
+
+.L_bc_parent:
+        # We're the parent; nothing to do.
         ret
 END(__bionic_clone)
+.hidden __bionic_clone
diff --git a/libc/arch-x86_64/bionic/__get_sp.S b/libc/arch-x86_64/bionic/__get_sp.S
deleted file mode 100644
index 0c693b3..0000000
--- a/libc/arch-x86_64/bionic/__get_sp.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-
-ENTRY(__get_sp)
-  mov  %rsp, %rax
-  ret
-END(__get_sp)
diff --git a/libc/arch-x86_64/bionic/__rt_sigreturn.S b/libc/arch-x86_64/bionic/__rt_sigreturn.S
index e03bb88..eddceb1 100644
--- a/libc/arch-x86_64/bionic/__rt_sigreturn.S
+++ b/libc/arch-x86_64/bionic/__rt_sigreturn.S
@@ -26,11 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
-ENTRY(__rt_sigreturn)
-  .hidden _C_LABEL(__rt_sigreturn) // TODO: add an ENTRY_PRIVATE macro for x86_64.
+ENTRY_PRIVATE(__rt_sigreturn)
   movl $__NR_rt_sigreturn, %eax
   syscall
 END(__rt_sigreturn)
diff --git a/libc/arch-x86_64/bionic/__set_tls.c b/libc/arch-x86_64/bionic/__set_tls.c
index 9a69449..10fd36f 100644
--- a/libc/arch-x86_64/bionic/__set_tls.c
+++ b/libc/arch-x86_64/bionic/__set_tls.c
@@ -26,13 +26,12 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #include <asm/prctl.h>
 #include <stdint.h>
 
 extern int __arch_prctl(int, unsigned long);
 
-int __set_tls(void* ptr) {
-  // We also need to write the location of the tls to ptr[0].
-  *(void**) ptr = ptr;
+__LIBC_HIDDEN__ int __set_tls(void* ptr) {
   return __arch_prctl(ARCH_SET_FS, (uintptr_t) ptr);
 }
diff --git a/libc/arch-x86_64/bionic/_exit_with_stack_teardown.S b/libc/arch-x86_64/bionic/_exit_with_stack_teardown.S
index f7bc962..d1f53af 100644
--- a/libc/arch-x86_64/bionic/_exit_with_stack_teardown.S
+++ b/libc/arch-x86_64/bionic/_exit_with_stack_teardown.S
@@ -29,7 +29,7 @@
 #include <private/bionic_asm.h>
 
 // void _exit_with_stack_teardown(void* stackBase, size_t stackSize)
-ENTRY(_exit_with_stack_teardown)
+ENTRY_PRIVATE(_exit_with_stack_teardown)
   mov $__NR_munmap, %eax
   syscall
   // If munmap failed, we ignore the failure and exit anyway.
diff --git a/libc/arch-x86_64/bionic/_setjmp.S b/libc/arch-x86_64/bionic/_setjmp.S
index e9b8dbb..c617030 100644
--- a/libc/arch-x86_64/bionic/_setjmp.S
+++ b/libc/arch-x86_64/bionic/_setjmp.S
@@ -36,8 +36,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
diff --git a/libc/arch-x86_64/bionic/futex_x86_64.S b/libc/arch-x86_64/bionic/futex_x86_64.S
deleted file mode 100644
index f85d583..0000000
--- a/libc/arch-x86_64/bionic/futex_x86_64.S
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <private/bionic_asm.h>
-
-#define FUTEX_WAIT 0
-#define FUTEX_WAKE 1
-
-// int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout)
-ENTRY(__futex_wait)
-    mov     %rdx, %r10           /* timeout */
-    mov     %esi, %edx           /* val */
-    mov     $FUTEX_WAIT, %esi    /* op */
-    mov     $__NR_futex, %eax
-    syscall
-    ret
-END(__futex_wait)
-
-// int __futex_wake(volatile void* ftx, int count)
-ENTRY(__futex_wake)
-    mov     %esi, %edx
-    mov     $FUTEX_WAKE, %esi
-    mov     $__NR_futex, %eax
-    syscall
-    ret
-END(__futex_wake)
-
-// int __futex_syscall3(volatile void* ftx, int op, int count)
-ENTRY(__futex_syscall3)
-    mov     $__NR_futex, %eax
-    syscall
-    ret
-END(__futex_syscall3)
-
-// int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout)
-ENTRY(__futex_syscall4)
-    mov     %rcx, %r10      /* timeout */
-    mov     $__NR_futex, %eax
-    syscall
-    ret
-END(__futex_syscall4)
diff --git a/libc/arch-x86_64/bionic/setjmp.S b/libc/arch-x86_64/bionic/setjmp.S
index 4dd9028..f356877 100644
--- a/libc/arch-x86_64/bionic/setjmp.S
+++ b/libc/arch-x86_64/bionic/setjmp.S
@@ -36,8 +36,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -53,11 +52,7 @@
 ENTRY(setjmp)
 	pushq	%rdi
 	xorq	%rdi,%rdi
-#ifdef __PIC__
-	call	PIC_PLT(_C_LABEL(sigblock))
-#else
-	call	_C_LABEL(sigblock)
-#endif
+	call	PIC_PLT(sigblock)
 	popq	%rdi
 	movq	%rax,(_JB_SIGMASK * 8)(%rdi)
 
@@ -81,11 +76,7 @@
 
 	movq	(_JB_SIGMASK * 8)(%rdi),%rdi
 	pushq	%r8
-#ifdef __PIC__
-	call	PIC_PLT(_C_LABEL(sigsetmask))
-#else
-	call	_C_LABEL(sigsetmask)
-#endif
+	call	PIC_PLT(sigsetmask)
 	popq	%r8
 	movq	(_JB_RBX * 8)(%r12),%rbx
 	movq	(_JB_RBP * 8)(%r12),%rbp
diff --git a/libc/arch-x86_64/bionic/sigsetjmp.S b/libc/arch-x86_64/bionic/sigsetjmp.S
index 842d6ff..571fea3 100644
--- a/libc/arch-x86_64/bionic/sigsetjmp.S
+++ b/libc/arch-x86_64/bionic/sigsetjmp.S
@@ -37,7 +37,7 @@
  */
 
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -57,11 +57,7 @@
 
 	pushq	%rdi
 	xorq	%rdi,%rdi
-#ifdef __PIC__
-	call	PIC_PLT(_C_LABEL(sigblock))
-#else
-	call	_C_LABEL(sigblock)
-#endif
+	call	PIC_PLT(sigblock)
 	popq	%rdi
 	movq	%rax,(_JB_SIGMASK * 8)(%rdi)
 
@@ -86,11 +82,7 @@
 	jz      2f
 
 	movq	(_JB_SIGMASK * 8)(%rdi),%rdi
-#ifdef __PIC__
-	call	PIC_PLT(_C_LABEL(sigsetmask))
-#else
-	call	_C_LABEL(sigsetmask)
-#endif
+	call	PIC_PLT(sigsetmask)
 2:	popq	%rax
 	movq	(_JB_RBX * 8)(%r12),%rbx
 	movq	(_JB_RBP * 8)(%r12),%rbp
diff --git a/libc/arch-x86_64/bionic/syscall.S b/libc/arch-x86_64/bionic/syscall.S
index a98a436..87939ba 100644
--- a/libc/arch-x86_64/bionic/syscall.S
+++ b/libc/arch-x86_64/bionic/syscall.S
@@ -57,8 +57,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(syscall)
diff --git a/libc/arch-x86_64/bionic/vfork.S b/libc/arch-x86_64/bionic/vfork.S
index b323f30..129f1db 100644
--- a/libc/arch-x86_64/bionic/vfork.S
+++ b/libc/arch-x86_64/bionic/vfork.S
@@ -39,8 +39,7 @@
   jb      1f
   negl    %eax
   movl    %eax, %edi
-  call    __set_errno
-  orq     $-1, %rax
+  call    __set_errno_internal
 1:
   ret
 END(vfork)
diff --git a/libc/arch-x86_64/include/machine/_types.h b/libc/arch-x86_64/include/machine/_types.h
deleted file mode 100644
index 234e652..0000000
--- a/libc/arch-x86_64/include/machine/_types.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*	$OpenBSD: _types.h,v 1.13 2013/07/05 19:46:27 guenther Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)types.h	8.3 (Berkeley) 1/5/94
- *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
- */
-
-#ifndef _MACHINE__TYPES_H_
-#define _MACHINE__TYPES_H_
-
-/*
- * _ALIGN(p) rounds p (pointer or byte index) up to a correctly-aligned
- * value for all data types (int, long, ...).   The result is an
- * unsigned long and must be cast to any desired pointer type.
- *
- * _ALIGNED_POINTER is a boolean macro that checks whether an address
- * is valid to fetch data elements of type t from on this architecture.
- * This does not reflect the optimal alignment, just the possibility
- * (within reasonable limits). 
- */
-#define	_ALIGNBYTES	(sizeof(long) - 1)
-#define	_ALIGN(p)	(((unsigned long)(p) + _ALIGNBYTES) &~_ALIGNBYTES)
-#define	_ALIGNED_POINTER(p,t)	1
-
-#if defined(_KERNEL)
-typedef struct label_t {
-	long val[8];
-} label_t;
-#endif
-
-/* 7.18.1.1 Exact-width integer types */
-typedef	__signed char		__int8_t;
-typedef	unsigned char		__uint8_t;
-typedef	short			__int16_t;
-typedef	unsigned short		__uint16_t;
-typedef	int			__int32_t;
-typedef	unsigned int		__uint32_t;
-typedef	long                    __int64_t;
-typedef	unsigned long           __uint64_t;
-
-/* 7.18.1.2 Minimum-width integer types */
-typedef	__int8_t		__int_least8_t;
-typedef	__uint8_t		__uint_least8_t;
-typedef	__int16_t		__int_least16_t;
-typedef	__uint16_t		__uint_least16_t;
-typedef	__int32_t		__int_least32_t;
-typedef	__uint32_t		__uint_least32_t;
-typedef	__int64_t		__int_least64_t;
-typedef	__uint64_t		__uint_least64_t;
-
-/* 7.18.1.3 Fastest minimum-width integer types */
-typedef	__int32_t		__int_fast8_t;
-typedef	__uint32_t		__uint_fast8_t;
-typedef	__int32_t		__int_fast16_t;
-typedef	__uint32_t		__uint_fast16_t;
-typedef	__int32_t		__int_fast32_t;
-typedef	__uint32_t		__uint_fast32_t;
-typedef	__int64_t		__int_fast64_t;
-typedef	__uint64_t		__uint_fast64_t;
-#define	__INT_FAST8_MIN		INT32_MIN
-#define	__INT_FAST16_MIN	INT32_MIN
-#define	__INT_FAST32_MIN	INT32_MIN
-#define	__INT_FAST64_MIN	INT64_MIN
-#define	__INT_FAST8_MAX		INT32_MAX
-#define	__INT_FAST16_MAX	INT32_MAX
-#define	__INT_FAST32_MAX	INT32_MAX
-#define	__INT_FAST64_MAX	INT64_MAX
-#define	__UINT_FAST8_MAX	UINT32_MAX
-#define	__UINT_FAST16_MAX	UINT32_MAX
-#define	__UINT_FAST32_MAX	UINT32_MAX
-#define	__UINT_FAST64_MAX	UINT64_MAX
-
-/* 7.18.1.4 Integer types capable of holding object pointers */
-typedef	long			__intptr_t;
-typedef	unsigned long		__uintptr_t;
-
-/* 7.18.1.5 Greatest-width integer types */
-typedef	__int64_t		__intmax_t;
-typedef	__uint64_t		__uintmax_t;
-
-/* Register size */
-typedef long			__register_t;
-
-/* VM system types */
-typedef unsigned long		__vaddr_t;
-typedef unsigned long		__paddr_t;
-typedef unsigned long		__vsize_t;
-typedef unsigned long		__psize_t;
-
-/* Standard system types */
-typedef	double			__double_t;
-typedef	float			__float_t;
-typedef long			__ptrdiff_t;
-typedef	long			__ssize_t;
-#if defined(__GNUC__) && __GNUC__ >= 3
-typedef	__builtin_va_list	__va_list;
-#else
-typedef char *			__va_list;
-#endif
-
-/* Wide character support types */
-#ifndef __cplusplus
-typedef	int			__wchar_t;
-#endif
-typedef int			__wint_t;
-typedef	int			__rune_t;
-typedef	void *			__wctrans_t;
-typedef	void *			__wctype_t;
-
-#endif	/* _MACHINE__TYPES_H_ */
diff --git a/libc/arch-x86_64/include/machine/asm.h b/libc/arch-x86_64/include/machine/asm.h
index 310b230..06da39a 100644
--- a/libc/arch-x86_64/include/machine/asm.h
+++ b/libc/arch-x86_64/include/machine/asm.h
@@ -37,28 +37,8 @@
 #ifndef _AMD64_ASM_H_
 #define _AMD64_ASM_H_
 
-#ifdef __x86_64__
-
-#ifdef __PIC__
 #define PIC_PLT(x)	x@PLT
 #define PIC_GOT(x)	x@GOTPCREL(%rip)
-#else
-#define PIC_PLT(x)	x
-#define PIC_GOT(x)	x
-#endif
-
-# define _C_LABEL(x)	x
-#define	_ASM_LABEL(x)	x
-
-#define CVAROFF(x,y)		(_C_LABEL(x)+y)(%rip)
-
-#ifdef __STDC__
-# define __CONCAT(x,y)	x ## y
-# define __STRING(x)	#x
-#else
-# define __CONCAT(x,y)	x/**/y
-# define __STRING(x)	"x"
-#endif
 
 /* let kernels and others override entrypoint alignment */
 #ifndef _ALIGN_TEXT
@@ -69,78 +49,4 @@
 # endif
 #endif
 
-#define _ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,@function; x: .cfi_startproc;
-#define _LABEL(x) \
-	.globl x; x:
-
-#ifdef _KERNEL
-/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
-#ifdef __STDC__
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
-#define	IDTVEC_END(name) \
-	.size X ## name, . - X ## name
-#else 
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
-#define	IDTVEC_END(name) \
-	.size X/**/name, . - X/**/name
-#endif /* __STDC__ */ 
-#endif /* _KERNEL */
-
-#ifdef __STDC__
-#define CPUVAR(off)	%gs:CPU_INFO_ ## off
-#else
-#define CPUVAR(off)     %gs:CPU_INFO_/**/off
-#endif
-
-
-#ifdef GPROF
-# define _PROF_PROLOGUE	\
-	pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp
-#else
-# define _PROF_PROLOGUE
-#endif
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
-#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
-#define	ALTENTRY(x)	NENTRY(x)
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	LABEL(y)	_LABEL(_C_LABEL(y))
-#define	END(y)		.cfi_endproc; .size y, . - y
-
-#define	ASMSTR		.asciz
-
-#define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
-
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-
-/*
- * STRONG_ALIAS: create a strong alias.
- */
-#define STRONG_ALIAS(alias,sym)						\
-	.globl alias;							\
-	alias = sym
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning. ## sym;				\
-	.ascii msg;							\
-	.popsection
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning./**/sym;				\
-	.ascii msg;							\
-	.popsection
-#endif /* __STDC__ */
-
-#else	/*	__x86_64__	*/
-
-#include <i386/asm.h>
-
-#endif	/*	__x86_64__	*/
-
 #endif /* !_AMD64_ASM_H_ */
diff --git a/libc/arch-x86_64/include/machine/ieee.h b/libc/arch-x86_64/include/machine/ieee.h
deleted file mode 100644
index 74856b2..0000000
--- a/libc/arch-x86_64/include/machine/ieee.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*	$OpenBSD: ieee.h,v 1.2 2008/09/07 20:36:06 martynas Exp $ */
-/*	$NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */
-
-/*
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Lawrence Berkeley Laboratory.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
- */
-
-/*
- * ieee.h defines the machine-dependent layout of the machine's IEEE
- * floating point.  It does *not* define (yet?) any of the rounding
- * mode bits, exceptions, and so forth.
- */
-
-/*
- * Define the number of bits in each fraction and exponent.
- *
- *		     k	         k+1
- * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
- *
- *					  (-exp_bias+1)
- * as fractions that look like 0.fffff x 2             .  This means that
- *
- *			 -126
- * the number 0.10000 x 2    , for instance, is the same as the normalized
- *
- *		-127			   -128
- * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
- *
- *				  -129
- * in the fraction; to represent 2    , we need two, and so on.  This
- *
- *						     (-exp_bias-fracbits+1)
- * implies that the smallest denormalized number is 2
- *
- * for whichever format we are talking about: for single precision, for
- *
- *						-126		-149
- * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
- *
- * -149 == -127 - 23 + 1.
- */
-#define	SNG_EXPBITS	8
-#define	SNG_FRACBITS	23
-
-#define	DBL_EXPBITS	11
-#define	DBL_FRACHBITS	20
-#define	DBL_FRACLBITS	32
-#define	DBL_FRACBITS	52
-
-#define	EXT_EXPBITS	15
-#define	EXT_FRACHBITS	32
-#define	EXT_FRACLBITS	32
-#define	EXT_FRACBITS	64
-
-#define	EXT_TO_ARRAY32(p, a) do {		\
-	(a)[0] = (uint32_t)(p)->ext_fracl;	\
-	(a)[1] = (uint32_t)(p)->ext_frach;	\
-} while(0)
-
-struct ieee_single {
-	u_int	sng_frac:23;
-	u_int	sng_exp:8;
-	u_int	sng_sign:1;
-};
-
-struct ieee_double {
-	u_int	dbl_fracl;
-	u_int	dbl_frach:20;
-	u_int	dbl_exp:11;
-	u_int	dbl_sign:1;
-};
-
-struct ieee_ext {
-	u_int	ext_fracl;
-	u_int	ext_frach;
-	u_int	ext_exp:15;
-	u_int	ext_sign:1;
-	u_int	ext_padl:16;
-	u_int	ext_padh;
-};
-
-/*
- * Floats whose exponent is in [1..INFNAN) (of whatever type) are
- * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
- * Floats whose exponent is zero are either zero (iff all fraction
- * bits are zero) or subnormal values.
- *
- * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
- * high fraction; if the bit is set, it is a `quiet NaN'.
- */
-#define	SNG_EXP_INFNAN	255
-#define	DBL_EXP_INFNAN	2047
-#define	EXT_EXP_INFNAN	32767
-
-#if 0
-#define	SNG_QUIETNAN	(1 << 22)
-#define	DBL_QUIETNAN	(1 << 19)
-#define	EXT_QUIETNAN	(1 << 15)
-#endif
-
-/*
- * Exponent biases.
- */
-#define	SNG_EXP_BIAS	127
-#define	DBL_EXP_BIAS	1023
-#define	EXT_EXP_BIAS	16383
diff --git a/libc/arch-x86_64/include/machine/limits.h b/libc/arch-x86_64/include/machine/limits.h
deleted file mode 100644
index a8c4a88..0000000
--- a/libc/arch-x86_64/include/machine/limits.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.5 2009/11/27 19:54:35 guenther Exp $	*/
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)limits.h	7.2 (Berkeley) 6/28/90
- */
-
-#ifndef	_MACHINE_LIMITS_H_
-#define	_MACHINE_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#if __POSIX_VISIBLE || __XPG_VISIBLE
-#ifndef	SIZE_MAX
-#define SIZE_MAX	ULONG_MAX	/* max value for a size_t */
-#endif
-#define SSIZE_MAX	LONG_MAX	/* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t (historic) */
-
-#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
-#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
-#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#endif /* _MACHINE_LIMITS_H_ */
diff --git a/libc/arch-x86_64/string/cache.h b/libc/arch-x86_64/string/cache.h
new file mode 100644
index 0000000..38acc6e
--- /dev/null
+++ b/libc/arch-x86_64/string/cache.h
@@ -0,0 +1,36 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Values are optimized for Silvermont */
+#define SHARED_CACHE_SIZE	(1024*1024)			/* Silvermont L2 Cache */
+#define DATA_CACHE_SIZE		(24*1024)			/* Silvermont L1 Data Cache */
+
+#define SHARED_CACHE_SIZE_HALF	(SHARED_CACHE_SIZE / 2)
+#define DATA_CACHE_SIZE_HALF	(DATA_CACHE_SIZE / 2)
diff --git a/libc/arch-x86_64/string/sse2-memcpy-slm.S b/libc/arch-x86_64/string/sse2-memcpy-slm.S
new file mode 100644
index 0000000..4c30fb6
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-memcpy-slm.S
@@ -0,0 +1,299 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef MEMCPY
+# define MEMCPY		memcpy
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)		\
+	.type name,  @function;		\
+	.globl name;		\
+	.p2align 4;		\
+name:		\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)		\
+	cfi_endproc;		\
+	.size name, .-name
+#endif
+
+#define CFI_PUSH(REG)		\
+	cfi_adjust_cfa_offset (4);		\
+	cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)		\
+	cfi_adjust_cfa_offset (-4);		\
+	cfi_restore (REG)
+
+#define PUSH(REG)	push REG;
+#define POP(REG)	pop REG;
+
+#define ENTRANCE	PUSH (%rbx);
+#define RETURN_END	POP (%rbx); ret
+#define RETURN		RETURN_END;
+
+	.section .text.sse2,"ax",@progbits
+ENTRY (MEMCPY)
+	ENTRANCE
+	cmp	%rsi, %rdi
+	je	L(return)
+
+	cmp	$16, %rdx
+	jbe	L(len_0_16_bytes)
+
+	cmp	$SHARED_CACHE_SIZE_HALF, %rdx
+	jae	L(large_page)
+
+	movdqu	(%rsi), %xmm0
+	movdqu	-16(%rsi, %rdx), %xmm1
+	cmp	$32, %rdx
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, -16(%rdi, %rdx)
+	jbe	L(return)
+
+	movdqu	16(%rsi), %xmm0
+	movdqu	-32(%rsi, %rdx), %xmm1
+	cmp	$64, %rdx
+	movdqu	%xmm0, 16(%rdi)
+	movdqu	%xmm1, -32(%rdi, %rdx)
+	jbe	L(return)
+
+	movdqu	32(%rsi), %xmm0
+	movdqu	48(%rsi), %xmm1
+	movdqu	-48(%rsi, %rdx), %xmm2
+	movdqu	-64(%rsi, %rdx), %xmm3
+	cmp	$128, %rdx
+	movdqu	%xmm0, 32(%rdi)
+	movdqu	%xmm1, 48(%rdi)
+	movdqu	%xmm2, -48(%rdi, %rdx)
+	movdqu	%xmm3, -64(%rdi, %rdx)
+	jbe	L(return)
+
+/* Now the main loop: we align the address of the destination.  */
+	lea	64(%rdi), %r8
+	and	$-64, %r8
+
+	add	%rdi, %rdx
+	and	$-64, %rdx
+
+	sub	%rdi, %rsi
+
+/* We should stop two iterations before the termination
+	(in order not to misprefetch).  */
+	sub	$64, %rdx
+	cmp	%r8, %rdx
+	je	L(main_loop_just_one_iteration)
+
+	sub	$64, %rdx
+	cmp	%r8, %rdx
+	je	L(main_loop_last_two_iterations)
+
+
+	.p2align 4
+L(main_loop_cache):
+
+	prefetcht0 128(%r8, %rsi)
+
+	movdqu	(%r8, %rsi), %xmm0
+	movdqu	16(%r8, %rsi), %xmm1
+	movdqu	32(%r8, %rsi), %xmm2
+	movdqu	48(%r8, %rsi), %xmm3
+	movdqa	%xmm0, (%r8)
+	movdqa	%xmm1, 16(%r8)
+	movdqa	%xmm2, 32(%r8)
+	movdqa	%xmm3, 48(%r8)
+	lea	64(%r8), %r8
+	cmp	%r8, %rdx
+	jne	L(main_loop_cache)
+
+L(main_loop_last_two_iterations):
+	movdqu	(%r8, %rsi), %xmm0
+	movdqu	16(%r8, %rsi), %xmm1
+	movdqu	32(%r8, %rsi), %xmm2
+	movdqu	48(%r8, %rsi), %xmm3
+	movdqu	64(%r8, %rsi), %xmm4
+	movdqu	80(%r8, %rsi), %xmm5
+	movdqu	96(%r8, %rsi), %xmm6
+	movdqu	112(%r8, %rsi), %xmm7
+	movdqa	%xmm0, (%r8)
+	movdqa	%xmm1, 16(%r8)
+	movdqa	%xmm2, 32(%r8)
+	movdqa	%xmm3, 48(%r8)
+	movdqa	%xmm4, 64(%r8)
+	movdqa	%xmm5, 80(%r8)
+	movdqa	%xmm6, 96(%r8)
+	movdqa	%xmm7, 112(%r8)
+	jmp	L(return)
+
+L(main_loop_just_one_iteration):
+	movdqu	(%r8, %rsi), %xmm0
+	movdqu	16(%r8, %rsi), %xmm1
+	movdqu	32(%r8, %rsi), %xmm2
+	movdqu	48(%r8, %rsi), %xmm3
+	movdqa	%xmm0, (%r8)
+	movdqa	%xmm1, 16(%r8)
+	movdqa	%xmm2, 32(%r8)
+	movdqa	%xmm3, 48(%r8)
+	jmp	L(return)
+
+L(large_page):
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	32(%rsi), %xmm2
+	movdqu	48(%rsi), %xmm3
+	movdqu	-64(%rsi, %rdx), %xmm4
+	movdqu	-48(%rsi, %rdx), %xmm5
+	movdqu	-32(%rsi, %rdx), %xmm6
+	movdqu	-16(%rsi, %rdx), %xmm7
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqu	%xmm4, -64(%rdi, %rdx)
+	movdqu	%xmm5, -48(%rdi, %rdx)
+	movdqu	%xmm6, -32(%rdi, %rdx)
+	movdqu	%xmm7, -16(%rdi, %rdx)
+
+	movdqu	64(%rsi), %xmm0
+	movdqu	80(%rsi), %xmm1
+	movdqu	96(%rsi), %xmm2
+	movdqu	112(%rsi), %xmm3
+	movdqu	-128(%rsi, %rdx), %xmm4
+	movdqu	-112(%rsi, %rdx), %xmm5
+	movdqu	-96(%rsi, %rdx), %xmm6
+	movdqu	-80(%rsi, %rdx), %xmm7
+	movdqu	%xmm0, 64(%rdi)
+	movdqu	%xmm1, 80(%rdi)
+	movdqu	%xmm2, 96(%rdi)
+	movdqu	%xmm3, 112(%rdi)
+	movdqu	%xmm4, -128(%rdi, %rdx)
+	movdqu	%xmm5, -112(%rdi, %rdx)
+	movdqu	%xmm6, -96(%rdi, %rdx)
+	movdqu	%xmm7, -80(%rdi, %rdx)
+
+/* Now the main loop with non temporal stores. We align
+	the address of the destination.  */
+	lea	128(%rdi), %r8
+	and	$-128, %r8
+
+	add	%rdi, %rdx
+	and	$-128, %rdx
+
+	sub	%rdi, %rsi
+
+	.p2align 4
+L(main_loop_large_page):
+	movdqu	(%r8, %rsi), %xmm0
+	movdqu	16(%r8, %rsi), %xmm1
+	movdqu	32(%r8, %rsi), %xmm2
+	movdqu	48(%r8, %rsi), %xmm3
+	movdqu	64(%r8, %rsi), %xmm4
+	movdqu	80(%r8, %rsi), %xmm5
+	movdqu	96(%r8, %rsi), %xmm6
+	movdqu	112(%r8, %rsi), %xmm7
+	movntdq	%xmm0, (%r8)
+	movntdq	%xmm1, 16(%r8)
+	movntdq	%xmm2, 32(%r8)
+	movntdq	%xmm3, 48(%r8)
+	movntdq	%xmm4, 64(%r8)
+	movntdq	%xmm5, 80(%r8)
+	movntdq	%xmm6, 96(%r8)
+	movntdq	%xmm7, 112(%r8)
+	lea	128(%r8), %r8
+	cmp	%r8, %rdx
+	jne	L(main_loop_large_page)
+	sfence
+	jmp	L(return)
+
+L(len_0_16_bytes):
+	testb	$24, %dl
+	jne	L(len_9_16_bytes)
+	testb	$4, %dl
+	.p2align 4,,5
+	jne	L(len_5_8_bytes)
+	test	%rdx, %rdx
+	.p2align 4,,2
+	je	L(return)
+	movzbl	(%rsi), %ebx
+	testb	$2, %dl
+	movb	%bl, (%rdi)
+	je	L(return)
+	movzwl	-2(%rsi,%rdx), %ebx
+	movw	%bx, -2(%rdi,%rdx)
+	jmp	L(return)
+
+L(len_9_16_bytes):
+	movq	(%rsi), %xmm0
+	movq	-8(%rsi, %rdx), %xmm1
+	movq	%xmm0, (%rdi)
+	movq	%xmm1, -8(%rdi, %rdx)
+	jmp	L(return)
+
+L(len_5_8_bytes):
+	movl	(%rsi), %ebx
+	movl	%ebx, (%rdi)
+	movl	-4(%rsi,%rdx), %ebx
+	movl	%ebx, -4(%rdi,%rdx)
+	jmp	L(return)
+
+L(return):
+	mov 	%rdi, %rax
+	RETURN
+
+END (MEMCPY)
diff --git a/libc/arch-x86_64/string/sse2-memmove-slm.S b/libc/arch-x86_64/string/sse2-memmove-slm.S
new file mode 100644
index 0000000..0dbffad
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-memmove-slm.S
@@ -0,0 +1,513 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef MEMMOVE
+# define MEMMOVE		memmove
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc	.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc	.cfi_endproc
+#endif
+
+#ifndef cfi_rel_offset
+# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
+#endif
+
+#ifndef cfi_restore
+# define cfi_restore(reg)	.cfi_restore reg
+#endif
+
+#ifndef cfi_adjust_cfa_offset
+# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)		\
+	.type name,  @function;		\
+	.globl name;		\
+	.p2align 4;		\
+name:		\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)		\
+	cfi_endproc;		\
+	.size name, .-name
+#endif
+
+#define CFI_PUSH(REG)		\
+	cfi_adjust_cfa_offset (4);		\
+	cfi_rel_offset (REG, 0)
+
+#define CFI_POP(REG)		\
+	cfi_adjust_cfa_offset (-4);		\
+	cfi_restore (REG)
+
+#define PUSH(REG)	push REG;
+#define POP(REG)	pop REG;
+
+#define ENTRANCE	PUSH (%rbx);
+#define RETURN_END	POP (%rbx); ret
+#define RETURN		RETURN_END;
+
+	.section .text.sse2,"ax",@progbits
+ENTRY (MEMMOVE)
+	ENTRANCE
+#ifdef USE_AS_BCOPY
+	xchg	%rsi, %rdi
+#endif
+	mov	%rdi, %rax
+
+/* Check whether we should copy backward or forward.  */
+	cmp	%rsi, %rdi
+	je	L(mm_return)
+	jg	L(mm_len_0_or_more_backward)
+
+/* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128]
+	separately.  */
+	cmp	$16, %rdx
+	jbe	L(mm_len_0_16_bytes_forward)
+
+	cmp	$32, %rdx
+	ja	L(mm_len_32_or_more_forward)
+
+/* Copy [0..32] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	-16(%rsi, %rdx), %xmm1
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_32_or_more_forward):
+	cmp	$64, %rdx
+	ja	L(mm_len_64_or_more_forward)
+
+/* Copy [0..64] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	-16(%rsi, %rdx), %xmm2
+	movdqu	-32(%rsi, %rdx), %xmm3
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, -16(%rdi, %rdx)
+	movdqu	%xmm3, -32(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_64_or_more_forward):
+	cmp	$128, %rdx
+	ja	L(mm_len_128_or_more_forward)
+
+/* Copy [0..128] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	32(%rsi), %xmm2
+	movdqu	48(%rsi), %xmm3
+	movdqu	-64(%rsi, %rdx), %xmm4
+	movdqu	-48(%rsi, %rdx), %xmm5
+	movdqu	-32(%rsi, %rdx), %xmm6
+	movdqu	-16(%rsi, %rdx), %xmm7
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqu	%xmm4, -64(%rdi, %rdx)
+	movdqu	%xmm5, -48(%rdi, %rdx)
+	movdqu	%xmm6, -32(%rdi, %rdx)
+	movdqu	%xmm7, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_128_or_more_forward):
+/* Aligning the address of destination.  */
+/*  save first unaligned 64 bytes */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	32(%rsi), %xmm2
+	movdqu	48(%rsi), %xmm3
+
+	lea	64(%rdi), %r8
+	and	$-64, %r8  /* r8 now aligned to next 64 byte boundary */
+	sub	%rdi, %rsi /* rsi = src - dst = diff */
+
+	movdqu	(%r8, %rsi), %xmm4
+	movdqu	16(%r8, %rsi), %xmm5
+	movdqu	32(%r8, %rsi), %xmm6
+	movdqu	48(%r8, %rsi), %xmm7
+
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqa	%xmm4, (%r8)
+	movaps	%xmm5, 16(%r8)
+	movaps	%xmm6, 32(%r8)
+	movaps	%xmm7, 48(%r8)
+	add	$64, %r8
+
+	lea	(%rdi, %rdx), %rbx
+	and	$-64, %rbx
+	cmp	%r8, %rbx
+	jbe	L(mm_copy_remaining_forward)
+
+	cmp	$SHARED_CACHE_SIZE_HALF, %rdx
+	jae	L(mm_large_page_loop_forward)
+
+	.p2align 4
+L(mm_main_loop_forward):
+
+	prefetcht0 128(%r8, %rsi)
+
+	movdqu	(%r8, %rsi), %xmm0
+	movdqu	16(%r8, %rsi), %xmm1
+	movdqu	32(%r8, %rsi), %xmm2
+	movdqu	48(%r8, %rsi), %xmm3
+	movdqa	%xmm0, (%r8)
+	movaps	%xmm1, 16(%r8)
+	movaps	%xmm2, 32(%r8)
+	movaps	%xmm3, 48(%r8)
+	lea	64(%r8), %r8
+	cmp	%r8, %rbx
+	ja	L(mm_main_loop_forward)
+
+L(mm_copy_remaining_forward):
+	add	%rdi, %rdx
+	sub	%r8, %rdx
+/* We copied all up till %rdi position in the dst.
+	In %rdx now is how many bytes are left to copy.
+	Now we need to advance %r8. */
+	lea	(%r8, %rsi), %r9
+
+L(mm_remaining_0_64_bytes_forward):
+	cmp	$32, %rdx
+	ja	L(mm_remaining_33_64_bytes_forward)
+	cmp	$16, %rdx
+	ja	L(mm_remaining_17_32_bytes_forward)
+	test	%rdx, %rdx
+	.p2align 4,,2
+	je	L(mm_return)
+
+	cmpb	$8, %dl
+	ja	L(mm_remaining_9_16_bytes_forward)
+	cmpb	$4, %dl
+	.p2align 4,,5
+	ja	L(mm_remaining_5_8_bytes_forward)
+	cmpb	$2, %dl
+	.p2align 4,,1
+	ja	L(mm_remaining_3_4_bytes_forward)
+	movzbl	-1(%r9,%rdx), %esi
+	movzbl	(%r9), %ebx
+	movb	%sil, -1(%r8,%rdx)
+	movb	%bl, (%r8)
+	jmp	L(mm_return)
+
+L(mm_remaining_33_64_bytes_forward):
+	movdqu	(%r9), %xmm0
+	movdqu	16(%r9), %xmm1
+	movdqu	-32(%r9, %rdx), %xmm2
+	movdqu	-16(%r9, %rdx), %xmm3
+	movdqu	%xmm0, (%r8)
+	movdqu	%xmm1, 16(%r8)
+	movdqu	%xmm2, -32(%r8, %rdx)
+	movdqu	%xmm3, -16(%r8, %rdx)
+	jmp	L(mm_return)
+
+L(mm_remaining_17_32_bytes_forward):
+	movdqu	(%r9), %xmm0
+	movdqu	-16(%r9, %rdx), %xmm1
+	movdqu	%xmm0, (%r8)
+	movdqu	%xmm1, -16(%r8, %rdx)
+	jmp	L(mm_return)
+
+L(mm_remaining_5_8_bytes_forward):
+	movl	(%r9), %esi
+	movl	-4(%r9,%rdx), %ebx
+	movl	%esi, (%r8)
+	movl	%ebx, -4(%r8,%rdx)
+	jmp	L(mm_return)
+
+L(mm_remaining_9_16_bytes_forward):
+	mov	(%r9), %rsi
+	mov	-8(%r9, %rdx), %rbx
+	mov	%rsi, (%r8)
+	mov	%rbx, -8(%r8, %rdx)
+	jmp	L(mm_return)
+
+L(mm_remaining_3_4_bytes_forward):
+	movzwl	-2(%r9,%rdx), %esi
+	movzwl	(%r9), %ebx
+	movw	%si, -2(%r8,%rdx)
+	movw	%bx, (%r8)
+	jmp	L(mm_return)
+
+L(mm_len_0_16_bytes_forward):
+	testb	$24, %dl
+	jne	L(mm_len_9_16_bytes_forward)
+	testb	$4, %dl
+	.p2align 4,,5
+	jne	L(mm_len_5_8_bytes_forward)
+	test	%rdx, %rdx
+	.p2align 4,,2
+	je	L(mm_return)
+	testb	$2, %dl
+	.p2align 4,,1
+	jne	L(mm_len_2_4_bytes_forward)
+	movzbl	-1(%rsi,%rdx), %ebx
+	movzbl	(%rsi), %esi
+	movb	%bl, -1(%rdi,%rdx)
+	movb	%sil, (%rdi)
+	jmp	L(mm_return)
+
+L(mm_len_2_4_bytes_forward):
+	movzwl	-2(%rsi,%rdx), %ebx
+	movzwl	(%rsi), %esi
+	movw	%bx, -2(%rdi,%rdx)
+	movw	%si, (%rdi)
+	jmp	L(mm_return)
+
+L(mm_len_5_8_bytes_forward):
+	movl	(%rsi), %ebx
+	movl	-4(%rsi,%rdx), %esi
+	movl	%ebx, (%rdi)
+	movl	%esi, -4(%rdi,%rdx)
+	jmp	L(mm_return)
+
+L(mm_len_9_16_bytes_forward):
+	mov	(%rsi), %rbx
+	mov	-8(%rsi, %rdx), %rsi
+	mov	%rbx, (%rdi)
+	mov	%rsi, -8(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_recalc_len):
+/* Compute in %rdx how many bytes are left to copy after
+	the main loop stops.  */
+	mov 	%rbx, %rdx
+	sub 	%rdi, %rdx
+/* The code for copying backwards.  */
+L(mm_len_0_or_more_backward):
+
+/* Now do checks for lengths. We do [0..16], [16..32], [32..64], [64..128]
+	separately.  */
+	cmp	$16, %rdx
+	jbe	L(mm_len_0_16_bytes_backward)
+
+	cmp	$32, %rdx
+	ja	L(mm_len_32_or_more_backward)
+
+/* Copy [0..32] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	-16(%rsi, %rdx), %xmm1
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_32_or_more_backward):
+	cmp	$64, %rdx
+	ja	L(mm_len_64_or_more_backward)
+
+/* Copy [0..64] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	-16(%rsi, %rdx), %xmm2
+	movdqu	-32(%rsi, %rdx), %xmm3
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, -16(%rdi, %rdx)
+	movdqu	%xmm3, -32(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_64_or_more_backward):
+	cmp	$128, %rdx
+	ja	L(mm_len_128_or_more_backward)
+
+/* Copy [0..128] and return.  */
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm1
+	movdqu	32(%rsi), %xmm2
+	movdqu	48(%rsi), %xmm3
+	movdqu	-64(%rsi, %rdx), %xmm4
+	movdqu	-48(%rsi, %rdx), %xmm5
+	movdqu	-32(%rsi, %rdx), %xmm6
+	movdqu	-16(%rsi, %rdx), %xmm7
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm1, 16(%rdi)
+	movdqu	%xmm2, 32(%rdi)
+	movdqu	%xmm3, 48(%rdi)
+	movdqu	%xmm4, -64(%rdi, %rdx)
+	movdqu	%xmm5, -48(%rdi, %rdx)
+	movdqu	%xmm6, -32(%rdi, %rdx)
+	movdqu	%xmm7, -16(%rdi, %rdx)
+	jmp	L(mm_return)
+
+L(mm_len_128_or_more_backward):
+/* Aligning the address of destination. We need to save
+	16 bits from the source in order not to overwrite them.  */
+	movdqu	-16(%rsi, %rdx), %xmm0
+	movdqu	-32(%rsi, %rdx), %xmm1
+	movdqu	-48(%rsi, %rdx), %xmm2
+	movdqu	-64(%rsi, %rdx), %xmm3
+
+	lea	(%rdi, %rdx), %r9
+	and	$-64, %r9 /* r9 = aligned dst */
+
+	mov	%rsi, %r8
+	sub	%rdi, %r8 /* r8 = src - dst, diff */
+
+	movdqu	-16(%r9, %r8), %xmm4
+	movdqu	-32(%r9, %r8), %xmm5
+	movdqu	-48(%r9, %r8), %xmm6
+	movdqu	-64(%r9, %r8), %xmm7
+
+	movdqu	%xmm0, -16(%rdi, %rdx)
+	movdqu	%xmm1, -32(%rdi, %rdx)
+	movdqu	%xmm2, -48(%rdi, %rdx)
+	movdqu	%xmm3, -64(%rdi, %rdx)
+	movdqa	%xmm4, -16(%r9)
+	movaps	%xmm5, -32(%r9)
+	movaps	%xmm6, -48(%r9)
+	movaps	%xmm7, -64(%r9)
+	lea	-64(%r9), %r9
+
+	lea	64(%rdi), %rbx
+	and	$-64, %rbx
+
+	cmp	%r9, %rbx
+	jae	L(mm_recalc_len)
+
+	cmp	$SHARED_CACHE_SIZE_HALF, %rdx
+	jae	L(mm_large_page_loop_backward)
+
+	.p2align 4
+L(mm_main_loop_backward):
+
+	prefetcht0 -128(%r9, %r8)
+
+	movdqu	-64(%r9, %r8), %xmm0
+	movdqu	-48(%r9, %r8), %xmm1
+	movdqu	-32(%r9, %r8), %xmm2
+	movdqu	-16(%r9, %r8), %xmm3
+	movdqa	%xmm0, -64(%r9)
+	movaps	%xmm1, -48(%r9)
+	movaps	%xmm2, -32(%r9)
+	movaps	%xmm3, -16(%r9)
+	lea	-64(%r9), %r9
+	cmp	%r9, %rbx
+	jb	L(mm_main_loop_backward)
+	jmp	L(mm_recalc_len)
+
+/* Copy [0..16] and return.  */
+L(mm_len_0_16_bytes_backward):
+	testb	$24, %dl
+	jnz	L(mm_len_9_16_bytes_backward)
+	testb	$4, %dl
+	.p2align 4,,5
+	jnz	L(mm_len_5_8_bytes_backward)
+	test	%rdx, %rdx
+	.p2align 4,,2
+	je	L(mm_return)
+	testb	$2, %dl
+	.p2align 4,,1
+	jne	L(mm_len_3_4_bytes_backward)
+	movzbl	-1(%rsi,%rdx), %ebx
+	movzbl	(%rsi), %ecx
+	movb	%bl, -1(%rdi,%rdx)
+	movb	%cl, (%rdi)
+	jmp	L(mm_return)
+
+L(mm_len_3_4_bytes_backward):
+	movzwl	-2(%rsi,%rdx), %ebx
+	movzwl	(%rsi), %ecx
+	movw	%bx, -2(%rdi,%rdx)
+	movw	%cx, (%rdi)
+	jmp	L(mm_return)
+
+L(mm_len_9_16_bytes_backward):
+	movl	-4(%rsi,%rdx), %ebx
+	movl	-8(%rsi,%rdx), %ecx
+	movl	%ebx, -4(%rdi,%rdx)
+	movl	%ecx, -8(%rdi,%rdx)
+	sub	$8, %rdx
+	jmp	L(mm_len_0_16_bytes_backward)
+
+L(mm_len_5_8_bytes_backward):
+	movl	(%rsi), %ebx
+	movl	-4(%rsi,%rdx), %ecx
+	movl	%ebx, (%rdi)
+	movl	%ecx, -4(%rdi,%rdx)
+
+L(mm_return):
+	RETURN
+
+/* Big length copy forward part.  */
+
+	.p2align 4
+L(mm_large_page_loop_forward):
+	movdqu	(%r8, %rsi), %xmm0
+	movdqu	16(%r8, %rsi), %xmm1
+	movdqu	32(%r8, %rsi), %xmm2
+	movdqu	48(%r8, %rsi), %xmm3
+	movntdq	%xmm0, (%r8)
+	movntdq	%xmm1, 16(%r8)
+	movntdq	%xmm2, 32(%r8)
+	movntdq	%xmm3, 48(%r8)
+	lea 	64(%r8), %r8
+	cmp	%r8, %rbx
+	ja	L(mm_large_page_loop_forward)
+	sfence
+	jmp	L(mm_copy_remaining_forward)
+
+/* Big length copy backward part.  */
+	.p2align 4
+L(mm_large_page_loop_backward):
+	movdqu	-64(%r9, %r8), %xmm0
+	movdqu	-48(%r9, %r8), %xmm1
+	movdqu	-32(%r9, %r8), %xmm2
+	movdqu	-16(%r9, %r8), %xmm3
+	movntdq	%xmm0, -64(%r9)
+	movntdq	%xmm1, -48(%r9)
+	movntdq	%xmm2, -32(%r9)
+	movntdq	%xmm3, -16(%r9)
+	lea 	-64(%r9), %r9
+	cmp	%r9, %rbx
+	jb	L(mm_large_page_loop_backward)
+	sfence
+	jmp	L(mm_recalc_len)
+
+END (MEMMOVE)
diff --git a/libc/arch-x86_64/string/sse2-memset-slm.S b/libc/arch-x86_64/string/sse2-memset-slm.S
new file mode 100644
index 0000000..bfcafae
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-memset-slm.S
@@ -0,0 +1,173 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef MEMSET
+# define MEMSET		memset
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef ALIGN
+# define ALIGN(n)	.p2align n
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc			.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc			.cfi_endproc
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)			\
+	.type name,  @function;	\
+	.globl name;			\
+name:					\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)			\
+	cfi_endproc;			\
+	.size name, .-name
+#endif
+
+	.section .text.sse2,"ax",@progbits
+ENTRY (MEMSET)
+	movq	%rdi, %rax
+#ifdef USE_AS_BZERO_P
+	mov	%rsi, %rdx
+	xor	%rcx, %rcx
+#else
+	and	$0xff, %rsi
+	mov	$0x0101010101010101, %rcx
+	imul	%rsi, %rcx
+#endif
+	cmpq	$16, %rdx
+	jae	L(16bytesormore)
+	testb	$8, %dl
+	jnz	L(8_15bytes)
+	testb	$4, %dl
+	jnz	L(4_7bytes)
+	testb	$2, %dl
+	jnz	L(2_3bytes)
+	testb	$1, %dl
+	jz	L(return)
+	movb	%cl, (%rdi)
+L(return):
+	ret
+
+L(8_15bytes):
+	movq	%rcx, (%rdi)
+	movq	%rcx, -8(%rdi, %rdx)
+	ret
+
+L(4_7bytes):
+	movl	%ecx, (%rdi)
+	movl	%ecx, -4(%rdi, %rdx)
+	ret
+
+L(2_3bytes):
+	movw	%cx, (%rdi)
+	movw	%cx, -2(%rdi, %rdx)
+	ret
+
+	ALIGN (4)
+L(16bytesormore):
+#ifdef USE_AS_BZERO_P
+	pxor	%xmm0, %xmm0
+#else
+	movd	%rcx, %xmm0
+	pshufd	$0, %xmm0, %xmm0
+#endif
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm0, -16(%rdi, %rdx)
+	cmpq	$32, %rdx
+	jbe	L(32bytesless)
+	movdqu	%xmm0, 16(%rdi)
+	movdqu	%xmm0, -32(%rdi, %rdx)
+	cmpq	$64, %rdx
+	jbe	L(64bytesless)
+	movdqu	%xmm0, 32(%rdi)
+	movdqu	%xmm0, 48(%rdi)
+	movdqu	%xmm0, -64(%rdi, %rdx)
+	movdqu	%xmm0, -48(%rdi, %rdx)
+	cmpq	$128, %rdx
+	ja	L(128bytesmore)
+L(32bytesless):
+L(64bytesless):
+	ret
+
+	ALIGN (4)
+L(128bytesmore):
+	leaq	64(%rdi), %rcx
+	andq	$-64, %rcx
+	movq	%rdx, %r8
+	addq	%rdi, %rdx
+	andq	$-64, %rdx
+	cmpq	%rcx, %rdx
+	je	L(return)
+
+#ifdef SHARED_CACHE_SIZE
+	cmp	$SHARED_CACHE_SIZE, %r8
+#else
+	cmp	__x86_64_shared_cache_size(%rip), %r8
+#endif
+	ja	L(128bytesmore_nt)
+
+	ALIGN (4)
+L(128bytesmore_normal):
+	movdqa	%xmm0, (%rcx)
+	movaps	%xmm0, 0x10(%rcx)
+	movaps	%xmm0, 0x20(%rcx)
+	movaps	%xmm0, 0x30(%rcx)
+	addq	$64, %rcx
+	cmpq	%rcx, %rdx
+	jne	L(128bytesmore_normal)
+	ret
+
+	ALIGN (4)
+L(128bytesmore_nt):
+	movntdq	%xmm0, (%rcx)
+	movntdq	%xmm0, 0x10(%rcx)
+	movntdq	%xmm0, 0x20(%rcx)
+	movntdq	%xmm0, 0x30(%rcx)
+	leaq	64(%rcx), %rcx
+	cmpq	%rcx, %rdx
+	jne	L(128bytesmore_nt)
+	sfence
+	ret
+
+END (MEMSET)
diff --git a/libc/arch-x86_64/string/sse2-stpcpy-slm.S b/libc/arch-x86_64/string/sse2-stpcpy-slm.S
new file mode 100644
index 0000000..0ad2d44
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-stpcpy-slm.S
@@ -0,0 +1,33 @@
+/*

+Copyright (c) 2014, Intel Corporation

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+

+    * Redistributions of source code must retain the above copyright notice,

+    * this list of conditions and the following disclaimer.

+

+    * Redistributions in binary form must reproduce the above copyright notice,

+    * this list of conditions and the following disclaimer in the documentation

+    * and/or other materials provided with the distribution.

+

+    * Neither the name of Intel Corporation nor the names of its contributors

+    * may be used to endorse or promote products derived from this software

+    * without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+*/

+

+#define USE_AS_STPCPY

+#define STRCPY		stpcpy

+#include "sse2-strcpy-slm.S"

diff --git a/libc/arch-x86_64/string/sse2-stpncpy-slm.S b/libc/arch-x86_64/string/sse2-stpncpy-slm.S
new file mode 100644
index 0000000..3066685
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-stpncpy-slm.S
@@ -0,0 +1,34 @@
+/*

+Copyright (c) 2014, Intel Corporation

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+

+    * Redistributions of source code must retain the above copyright notice,

+    * this list of conditions and the following disclaimer.

+

+    * Redistributions in binary form must reproduce the above copyright notice,

+    * this list of conditions and the following disclaimer in the documentation

+    * and/or other materials provided with the distribution.

+

+    * Neither the name of Intel Corporation nor the names of its contributors

+    * may be used to endorse or promote products derived from this software

+    * without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+*/

+

+#define USE_AS_STRNCPY

+#define USE_AS_STPCPY

+#define STRCPY		stpncpy

+#include "sse2-strcpy-slm.S"

diff --git a/libc/arch-x86_64/string/sse2-strcat-slm.S b/libc/arch-x86_64/string/sse2-strcat-slm.S
new file mode 100644
index 0000000..dd8207f
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-strcat-slm.S
@@ -0,0 +1,87 @@
+/*

+Copyright (c) 2014, Intel Corporation

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+

+    * Redistributions of source code must retain the above copyright notice,

+    * this list of conditions and the following disclaimer.

+

+    * Redistributions in binary form must reproduce the above copyright notice,

+    * this list of conditions and the following disclaimer in the documentation

+    * and/or other materials provided with the distribution.

+

+    * Neither the name of Intel Corporation nor the names of its contributors

+    * may be used to endorse or promote products derived from this software

+    * without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+*/

+

+#ifndef STRCAT

+# define STRCAT		strcat

+#endif

+

+#ifndef L

+# define L(label)		.L##label

+#endif

+

+#ifndef cfi_startproc

+# define cfi_startproc		 .cfi_startproc

+#endif

+

+#ifndef cfi_endproc

+# define cfi_endproc		.cfi_endproc

+#endif

+

+#ifndef ENTRY

+# define ENTRY(name)		\

+	.type name,  @function;		\

+	.globl name;		\

+	.p2align 4;		\

+name:		\

+	cfi_startproc

+#endif

+

+#ifndef END

+# define END(name)		\

+	cfi_endproc;		\

+	.size name, .-name

+#endif

+

+#define USE_AS_STRCAT

+

+.text

+ENTRY (STRCAT)

+	mov	%rdi, %r9

+#ifdef USE_AS_STRNCAT

+	mov	%rdx, %r8

+#endif

+

+#define RETURN jmp L(Strcpy)

+#include "sse2-strlen-slm.S"

+

+#undef RETURN

+#define RETURN ret

+

+L(Strcpy):

+	lea	(%r9, %rax), %rdi

+	mov	%rsi, %rcx

+	mov	%r9, %rax	/* save result */

+

+#ifdef USE_AS_STRNCAT

+	test	%r8, %r8

+	jz	L(ExitZero)

+# define USE_AS_STRNCPY

+#endif

+#include "sse2-strcpy-slm.S"

diff --git a/libc/arch-x86_64/string/sse2-strcpy-slm.S b/libc/arch-x86_64/string/sse2-strcpy-slm.S
new file mode 100644
index 0000000..3e146bf
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-strcpy-slm.S
@@ -0,0 +1,1921 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef USE_AS_STRCAT
+
+# ifndef STRCPY
+#  define STRCPY	strcpy
+# endif
+
+# ifndef L
+#  define L(label)	.L##label
+# endif
+
+# ifndef cfi_startproc
+#  define cfi_startproc	.cfi_startproc
+# endif
+
+# ifndef cfi_endproc
+#  define cfi_endproc	.cfi_endproc
+# endif
+
+# ifndef ENTRY
+#  define ENTRY(name)	\
+	.type name, @function;	\
+	.globl name;	\
+	.p2align 4;	\
+name:	\
+	cfi_startproc
+# endif
+
+# ifndef END
+#  define END(name)	\
+	cfi_endproc;	\
+	.size name, .-name
+# endif
+
+#endif
+
+#define JMPTBL(I, B)	I - B
+#define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)	\
+	lea	TABLE(%rip), %r11;	\
+	movslq	(%r11, INDEX, SCALE), %rcx;	\
+	lea	(%r11, %rcx), %rcx;	\
+	jmp	*%rcx
+
+#ifndef USE_AS_STRCAT
+
+# define RETURN ret
+
+.text
+ENTRY (STRCPY)
+# ifdef USE_AS_STRNCPY
+	mov	%rdx, %r8
+	test	%r8, %r8
+	jz	L(ExitZero)
+# endif
+	mov	%rsi, %rcx
+# ifndef USE_AS_STPCPY
+	mov	%rdi, %rax      /* save result */
+# endif
+
+#endif
+	and	$63, %rcx
+	cmp	$32, %rcx
+	jbe	L(SourceStringAlignmentLess32)
+
+	and	$-16, %rsi
+	and	$15, %rcx
+	pxor	%xmm0, %xmm0
+	pxor	%xmm1, %xmm1
+
+	pcmpeqb	(%rsi), %xmm1
+	pmovmskb %xmm1, %rdx
+	shr	%cl, %rdx
+#ifdef USE_AS_STRNCPY
+# if defined USE_AS_STPCPY || defined USE_AS_STRCAT
+	mov	$16, %r10
+	sub	%rcx, %r10
+	cmp	%r10, %r8
+# else
+	mov	$17, %r10
+	sub	%rcx, %r10
+	cmp	%r10, %r8
+# endif
+	jbe	L(CopyFrom1To16BytesTailCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To16BytesTail)
+
+	pcmpeqb	16(%rsi), %xmm0
+	pmovmskb %xmm0, %rdx
+#ifdef USE_AS_STRNCPY
+	add	$16, %r10
+	cmp	%r10, %r8
+	jbe	L(CopyFrom1To32BytesCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To32Bytes)
+
+	movdqu	(%rsi, %rcx), %xmm1   /* copy 16 bytes */
+	movdqu	%xmm1, (%rdi)
+
+/* If source adress alignment != destination adress alignment */
+	.p2align 4
+L(Unalign16Both):
+	sub	%rcx, %rdi
+#ifdef USE_AS_STRNCPY
+	add	%rcx, %r8
+#endif
+	mov	$16, %rcx
+	movdqa	(%rsi, %rcx), %xmm1
+	movaps	16(%rsi, %rcx), %xmm2
+	movdqu	%xmm1, (%rdi, %rcx)
+	pcmpeqb	%xmm2, %xmm0
+	pmovmskb %xmm0, %rdx
+	add	$16, %rcx
+#ifdef USE_AS_STRNCPY
+	sub	$48, %r8
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm2)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%rsi, %rcx), %xmm3
+	movdqu	%xmm2, (%rdi, %rcx)
+	pcmpeqb	%xmm3, %xmm0
+	pmovmskb %xmm0, %rdx
+	add	$16, %rcx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %r8
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm3)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%rsi, %rcx), %xmm4
+	movdqu	%xmm3, (%rdi, %rcx)
+	pcmpeqb	%xmm4, %xmm0
+	pmovmskb %xmm0, %rdx
+	add	$16, %rcx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %r8
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm4)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%rsi, %rcx), %xmm1
+	movdqu	%xmm4, (%rdi, %rcx)
+	pcmpeqb	%xmm1, %xmm0
+	pmovmskb %xmm0, %rdx
+	add	$16, %rcx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %r8
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm1)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%rsi, %rcx), %xmm2
+	movdqu	%xmm1, (%rdi, %rcx)
+	pcmpeqb	%xmm2, %xmm0
+	pmovmskb %xmm0, %rdx
+	add	$16, %rcx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %r8
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm2)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movaps	16(%rsi, %rcx), %xmm3
+	movdqu	%xmm2, (%rdi, %rcx)
+	pcmpeqb	%xmm3, %xmm0
+	pmovmskb %xmm0, %rdx
+	add	$16, %rcx
+#ifdef USE_AS_STRNCPY
+	sub	$16, %r8
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm3)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	movdqu	%xmm3, (%rdi, %rcx)
+	mov	%rsi, %rdx
+	lea	16(%rsi, %rcx), %rsi
+	and	$-0x40, %rsi
+	sub	%rsi, %rdx
+	sub	%rdx, %rdi
+#ifdef USE_AS_STRNCPY
+	lea	128(%r8, %rdx), %r8
+#endif
+L(Unaligned64Loop):
+	movaps	(%rsi), %xmm2
+	movaps	%xmm2, %xmm4
+	movaps	16(%rsi), %xmm5
+	movaps	32(%rsi), %xmm3
+	movaps	%xmm3, %xmm6
+	movaps	48(%rsi), %xmm7
+	pminub	%xmm5, %xmm2
+	pminub	%xmm7, %xmm3
+	pminub	%xmm2, %xmm3
+	pcmpeqb	%xmm0, %xmm3
+	pmovmskb %xmm3, %rdx
+#ifdef USE_AS_STRNCPY
+	sub	$64, %r8
+	jbe	L(UnalignedLeaveCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+	jnz	L(Unaligned64Leave)
+
+L(Unaligned64Loop_start):
+	add	$64, %rdi
+	add	$64, %rsi
+	movdqu	%xmm4, -64(%rdi)
+	movaps	(%rsi), %xmm2
+	movdqa	%xmm2, %xmm4
+	movdqu	%xmm5, -48(%rdi)
+	movaps	16(%rsi), %xmm5
+	pminub	%xmm5, %xmm2
+	movaps	32(%rsi), %xmm3
+	movdqu	%xmm6, -32(%rdi)
+	movaps	%xmm3, %xmm6
+	movdqu	%xmm7, -16(%rdi)
+	movaps	48(%rsi), %xmm7
+	pminub	%xmm7, %xmm3
+	pminub	%xmm2, %xmm3
+	pcmpeqb	%xmm0, %xmm3
+	pmovmskb %xmm3, %rdx
+#ifdef USE_AS_STRNCPY
+	sub	$64, %r8
+	jbe	L(UnalignedLeaveCase2OrCase3)
+#endif
+	test	%rdx, %rdx
+	jz	L(Unaligned64Loop_start)
+
+L(Unaligned64Leave):
+	pxor	%xmm1, %xmm1
+
+	pcmpeqb	%xmm4, %xmm0
+	pcmpeqb	%xmm5, %xmm1
+	pmovmskb %xmm0, %rdx
+	pmovmskb %xmm1, %rcx
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To16BytesUnaligned_0)
+	test	%rcx, %rcx
+	jnz	L(CopyFrom1To16BytesUnaligned_16)
+
+	pcmpeqb	%xmm6, %xmm0
+	pcmpeqb	%xmm7, %xmm1
+	pmovmskb %xmm0, %rdx
+	pmovmskb %xmm1, %rcx
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To16BytesUnaligned_32)
+
+	bsf	%rcx, %rdx
+	movdqu	%xmm4, (%rdi)
+	movdqu	%xmm5, 16(%rdi)
+	movdqu	%xmm6, 32(%rdi)
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+# ifdef USE_AS_STPCPY
+	lea	48(%rdi, %rdx), %rax
+# endif
+	movdqu	%xmm7, 48(%rdi)
+	add	$15, %r8
+	sub	%rdx, %r8
+	lea	49(%rdi, %rdx), %rdi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$48, %rsi
+	add	$48, %rdi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+#endif
+
+/* If source adress alignment == destination adress alignment */
+
+L(SourceStringAlignmentLess32):
+	pxor	%xmm0, %xmm0
+	movdqu	(%rsi), %xmm1
+	movdqu	16(%rsi), %xmm2
+	pcmpeqb	%xmm1, %xmm0
+	pmovmskb %xmm0, %rdx
+
+#ifdef USE_AS_STRNCPY
+# if defined USE_AS_STPCPY || defined USE_AS_STRCAT
+	cmp	$16, %r8
+# else
+	cmp	$17, %r8
+# endif
+	jbe	L(CopyFrom1To16BytesTail1Case2OrCase3)
+#endif
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To16BytesTail1)
+
+	pcmpeqb	%xmm2, %xmm0
+	movdqu	%xmm1, (%rdi)
+	pmovmskb %xmm0, %rdx
+
+#ifdef USE_AS_STRNCPY
+# if defined USE_AS_STPCPY || defined USE_AS_STRCAT
+	cmp	$32, %r8
+# else
+	cmp	$33, %r8
+# endif
+	jbe	L(CopyFrom1To32Bytes1Case2OrCase3)
+#endif
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To32Bytes1)
+
+	and	$15, %rcx
+	and	$-16, %rsi
+
+	jmp	L(Unalign16Both)
+
+/*------End of main part with loops---------------------*/
+
+/* Case1 */
+
+#if (!defined USE_AS_STRNCPY) || (defined USE_AS_STRCAT)
+	.p2align 4
+L(CopyFrom1To16Bytes):
+	add	%rcx, %rdi
+	add	%rcx, %rsi
+	bsf	%rdx, %rdx
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+#endif
+	.p2align 4
+L(CopyFrom1To16BytesTail):
+	add	%rcx, %rsi
+	bsf	%rdx, %rdx
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+
+	.p2align 4
+L(CopyFrom1To32Bytes1):
+	add	$16, %rsi
+	add	$16, %rdi
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$16, %r8
+#endif
+L(CopyFrom1To16BytesTail1):
+	bsf	%rdx, %rdx
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+
+	.p2align 4
+L(CopyFrom1To32Bytes):
+	bsf	%rdx, %rdx
+	add	%rcx, %rsi
+	add	$16, %rdx
+	sub	%rcx, %rdx
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnaligned_0):
+	bsf	%rdx, %rdx
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+# ifdef USE_AS_STPCPY
+	lea	(%rdi, %rdx), %rax
+# endif
+	movdqu	%xmm4, (%rdi)
+	add	$63, %r8
+	sub	%rdx, %r8
+	lea	1(%rdi, %rdx), %rdi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+#endif
+
+	.p2align 4
+L(CopyFrom1To16BytesUnaligned_16):
+	bsf	%rcx, %rdx
+	movdqu	%xmm4, (%rdi)
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+# ifdef USE_AS_STPCPY
+	lea	16(%rdi, %rdx), %rax
+# endif
+	movdqu	%xmm5, 16(%rdi)
+	add	$47, %r8
+	sub	%rdx, %r8
+	lea	17(%rdi, %rdx), %rdi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$16, %rsi
+	add	$16, %rdi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+#endif
+
+	.p2align 4
+L(CopyFrom1To16BytesUnaligned_32):
+	bsf	%rdx, %rdx
+	movdqu	%xmm4, (%rdi)
+	movdqu	%xmm5, 16(%rdi)
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+# ifdef USE_AS_STPCPY
+	lea	32(%rdi, %rdx), %rax
+# endif
+	movdqu	%xmm6, 32(%rdi)
+	add	$31, %r8
+	sub	%rdx, %r8
+	lea	33(%rdi, %rdx), %rdi
+	jmp	L(StrncpyFillTailWithZero)
+#else
+	add	$32, %rsi
+	add	$32, %rdi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+#endif
+
+#ifdef USE_AS_STRNCPY
+# ifndef USE_AS_STRCAT 
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm6):
+	movdqu	%xmm6, (%rdi, %rcx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm5):
+	movdqu	%xmm5, (%rdi, %rcx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm4):
+	movdqu	%xmm4, (%rdi, %rcx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm3):
+	movdqu	%xmm3, (%rdi, %rcx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm1):
+	movdqu	%xmm1, (%rdi, %rcx)
+	jmp	L(CopyFrom1To16BytesXmmExit)
+# endif
+
+	.p2align 4
+L(CopyFrom1To16BytesExit):
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
+
+/* Case2 */
+
+	.p2align 4
+L(CopyFrom1To16BytesCase2):
+	add	$16, %r8
+	add	%rcx, %rdi
+	add	%rcx, %rsi
+	bsf	%rdx, %rdx
+	cmp	%r8, %rdx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+	.p2align 4
+L(CopyFrom1To32BytesCase2):
+	add	%rcx, %rsi
+	bsf	%rdx, %rdx
+	add	$16, %rdx
+	sub	%rcx, %rdx
+	cmp	%r8, %rdx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+L(CopyFrom1To16BytesTailCase2):
+	add	%rcx, %rsi
+	bsf	%rdx, %rdx
+	cmp	%r8, %rdx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+L(CopyFrom1To16BytesTail1Case2):
+	bsf	%rdx, %rdx
+	cmp	%r8, %rdx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+/* Case2 or Case3,  Case3 */
+
+	.p2align 4
+L(CopyFrom1To16BytesCase2OrCase3):
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To16BytesCase2)
+L(CopyFrom1To16BytesCase3):
+	add	$16, %r8
+	add	%rcx, %rdi
+	add	%rcx, %rsi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+	.p2align 4
+L(CopyFrom1To32BytesCase2OrCase3):
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To32BytesCase2)
+	add	%rcx, %rsi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+	.p2align 4
+L(CopyFrom1To16BytesTailCase2OrCase3):
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To16BytesTailCase2)
+	add	%rcx, %rsi
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+	.p2align 4
+L(CopyFrom1To32Bytes1Case2OrCase3):
+	add	$16, %rdi
+	add	$16, %rsi
+	sub	$16, %r8
+L(CopyFrom1To16BytesTail1Case2OrCase3):
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To16BytesTail1Case2)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+#endif
+
+/*------------End labels regarding with copying 1-16 bytes--and 1-32 bytes----*/
+
+	.p2align 4
+L(Exit1):
+	mov	%dh, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$1, %r8
+	lea	1(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit2):
+	mov	(%rsi), %dx
+	mov	%dx, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	1(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$2, %r8
+	lea	2(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit3):
+	mov	(%rsi), %cx
+	mov	%cx, (%rdi)
+	mov	%dh, 2(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	2(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$3, %r8
+	lea	3(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit4):
+	mov	(%rsi), %edx
+	mov	%edx, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	3(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$4, %r8
+	lea	4(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit5):
+	mov	(%rsi), %ecx
+	mov	%dh, 4(%rdi)
+	mov	%ecx, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	4(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$5, %r8
+	lea	5(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit6):
+	mov	(%rsi), %ecx
+	mov	4(%rsi), %dx
+	mov	%ecx, (%rdi)
+	mov	%dx, 4(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	5(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$6, %r8
+	lea	6(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit7):
+	mov	(%rsi), %ecx
+	mov	3(%rsi), %edx
+	mov	%ecx, (%rdi)
+	mov	%edx, 3(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	6(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$7, %r8
+	lea	7(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit8):
+	mov	(%rsi), %rdx
+	mov	%rdx, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	7(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$8, %r8
+	lea	8(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit9):
+	mov	(%rsi), %rcx
+	mov	%dh, 8(%rdi)
+	mov	%rcx, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	8(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$9, %r8
+	lea	9(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit10):
+	mov	(%rsi), %rcx
+	mov	8(%rsi), %dx
+	mov	%rcx, (%rdi)
+	mov	%dx, 8(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	9(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$10, %r8
+	lea	10(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit11):
+	mov	(%rsi), %rcx
+	mov	7(%rsi), %edx
+	mov	%rcx, (%rdi)
+	mov	%edx, 7(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	10(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$11, %r8
+	lea	11(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit12):
+	mov	(%rsi), %rcx
+	mov	8(%rsi), %edx
+	mov	%rcx, (%rdi)
+	mov	%edx, 8(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	11(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$12, %r8
+	lea	12(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit13):
+	mov	(%rsi), %rcx
+	mov	5(%rsi), %rdx
+	mov	%rcx, (%rdi)
+	mov	%rdx, 5(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	12(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$13, %r8
+	lea	13(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit14):
+	mov	(%rsi), %rcx
+	mov	6(%rsi), %rdx
+	mov	%rcx, (%rdi)
+	mov	%rdx, 6(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	13(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$14, %r8
+	lea	14(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit15):
+	mov	(%rsi), %rcx
+	mov	7(%rsi), %rdx
+	mov	%rcx, (%rdi)
+	mov	%rdx, 7(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	14(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$15, %r8
+	lea	15(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit16):
+	movdqu	(%rsi), %xmm0
+	movdqu	%xmm0, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	15(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$16, %r8
+	lea	16(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit17):
+	movdqu	(%rsi), %xmm0
+	movdqu	%xmm0, (%rdi)
+	mov	%dh, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	16(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$17, %r8
+	lea	17(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit18):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %cx
+	movdqu	%xmm0, (%rdi)
+	mov	%cx, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	17(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$18, %r8
+	lea	18(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit19):
+	movdqu	(%rsi), %xmm0
+	mov	15(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%ecx, 15(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	18(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$19, %r8
+	lea	19(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit20):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%ecx, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	19(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$20, %r8
+	lea	20(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit21):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%ecx, 16(%rdi)
+	mov	%dh, 20(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	20(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$21, %r8
+	lea	21(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit22):
+	movdqu	(%rsi), %xmm0
+	mov	14(%rsi), %rcx
+	movdqu	%xmm0, (%rdi)
+	mov	%rcx, 14(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	21(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$22, %r8
+	lea	22(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit23):
+	movdqu	(%rsi), %xmm0
+	mov	15(%rsi), %rcx
+	movdqu	%xmm0, (%rdi)
+	mov	%rcx, 15(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	22(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$23, %r8
+	lea	23(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit24):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rcx
+	movdqu	%xmm0, (%rdi)
+	mov	%rcx, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	23(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$24, %r8
+	lea	24(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit25):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rcx
+	movdqu	%xmm0, (%rdi)
+	mov	%rcx, 16(%rdi)
+	mov	%dh, 24(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	24(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$25, %r8
+	lea	25(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit26):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rdx
+	mov	24(%rsi), %cx
+	movdqu	%xmm0, (%rdi)
+	mov	%rdx, 16(%rdi)
+	mov	%cx, 24(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	25(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$26, %r8
+	lea	26(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit27):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rdx
+	mov	23(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%rdx, 16(%rdi)
+	mov	%ecx, 23(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	26(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$27, %r8
+	lea	27(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit28):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rdx
+	mov	24(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%rdx, 16(%rdi)
+	mov	%ecx, 24(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	27(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$28, %r8
+	lea	28(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit29):
+	movdqu	(%rsi), %xmm0
+	movdqu	13(%rsi), %xmm2
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 13(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	28(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$29, %r8
+	lea	29(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit30):
+	movdqu	(%rsi), %xmm0
+	movdqu	14(%rsi), %xmm2
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 14(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	29(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$30, %r8
+	lea	30(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit31):
+	movdqu	(%rsi), %xmm0
+	movdqu	15(%rsi), %xmm2
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 15(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	30(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$31, %r8
+	lea	31(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+	.p2align 4
+L(Exit32):
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm2
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	31(%rdi), %rax
+#endif
+#if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
+	sub	$32, %r8
+	lea	32(%rdi), %rdi
+	jnz	L(StrncpyFillTailWithZero)
+#endif
+	RETURN
+
+#ifdef USE_AS_STRNCPY
+
+	.p2align 4
+L(StrncpyExit0):
+#ifdef USE_AS_STPCPY
+	mov	%rdi, %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, (%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit1):
+	mov	(%rsi), %dl
+	mov	%dl, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	1(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 1(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit2):
+	mov	(%rsi), %dx
+	mov	%dx, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	2(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 2(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit3):
+	mov	(%rsi), %cx
+	mov	2(%rsi), %dl
+	mov	%cx, (%rdi)
+	mov	%dl, 2(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	3(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 3(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit4):
+	mov	(%rsi), %edx
+	mov	%edx, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	4(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 4(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit5):
+	mov	(%rsi), %ecx
+	mov	4(%rsi), %dl
+	mov	%ecx, (%rdi)
+	mov	%dl, 4(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	5(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 5(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit6):
+	mov	(%rsi), %ecx
+	mov	4(%rsi), %dx
+	mov	%ecx, (%rdi)
+	mov	%dx, 4(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	6(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 6(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit7):
+	mov	(%rsi), %ecx
+	mov	3(%rsi), %edx
+	mov	%ecx, (%rdi)
+	mov	%edx, 3(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	7(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 7(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit8):
+	mov	(%rsi), %rdx
+	mov	%rdx, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	8(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 8(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit9):
+	mov	(%rsi), %rcx
+	mov	8(%rsi), %dl
+	mov	%rcx, (%rdi)
+	mov	%dl, 8(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	9(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 9(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit10):
+	mov	(%rsi), %rcx
+	mov	8(%rsi), %dx
+	mov	%rcx, (%rdi)
+	mov	%dx, 8(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	10(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 10(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit11):
+	mov	(%rsi), %rcx
+	mov	7(%rsi), %edx
+	mov	%rcx, (%rdi)
+	mov	%edx, 7(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	11(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 11(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit12):
+	mov	(%rsi), %rcx
+	mov	8(%rsi), %edx
+	mov	%rcx, (%rdi)
+	mov	%edx, 8(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	12(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 12(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit13):
+	mov	(%rsi), %rcx
+	mov	5(%rsi), %rdx
+	mov	%rcx, (%rdi)
+	mov	%rdx, 5(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	13(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 13(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit14):
+	mov	(%rsi), %rcx
+	mov	6(%rsi), %rdx
+	mov	%rcx, (%rdi)
+	mov	%rdx, 6(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	14(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 14(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit15):
+	mov	(%rsi), %rcx
+	mov	7(%rsi), %rdx
+	mov	%rcx, (%rdi)
+	mov	%rdx, 7(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	15(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 15(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit16):
+	movdqu	(%rsi), %xmm0
+	movdqu	%xmm0, (%rdi)
+#ifdef USE_AS_STPCPY
+	lea	16(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 16(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit17):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %cl
+	movdqu	%xmm0, (%rdi)
+	mov	%cl, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	17(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 17(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit18):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %cx
+	movdqu	%xmm0, (%rdi)
+	mov	%cx, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	18(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 18(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit19):
+	movdqu	(%rsi), %xmm0
+	mov	15(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%ecx, 15(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	19(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 19(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit20):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%ecx, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	20(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 20(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit21):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %ecx
+	mov	20(%rsi), %dl
+	movdqu	%xmm0, (%rdi)
+	mov	%ecx, 16(%rdi)
+	mov	%dl, 20(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	21(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 21(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit22):
+	movdqu	(%rsi), %xmm0
+	mov	14(%rsi), %rcx
+	movdqu	%xmm0, (%rdi)
+	mov	%rcx, 14(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	22(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 22(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit23):
+	movdqu	(%rsi), %xmm0
+	mov	15(%rsi), %rcx
+	movdqu	%xmm0, (%rdi)
+	mov	%rcx, 15(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	23(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 23(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit24):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rcx
+	movdqu	%xmm0, (%rdi)
+	mov	%rcx, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	24(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 24(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit25):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rdx
+	mov	24(%rsi), %cl
+	movdqu	%xmm0, (%rdi)
+	mov	%rdx, 16(%rdi)
+	mov	%cl, 24(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	25(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 25(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit26):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rdx
+	mov	24(%rsi), %cx
+	movdqu	%xmm0, (%rdi)
+	mov	%rdx, 16(%rdi)
+	mov	%cx, 24(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	26(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 26(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit27):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rdx
+	mov	23(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%rdx, 16(%rdi)
+	mov	%ecx, 23(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	27(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 27(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit28):
+	movdqu	(%rsi), %xmm0
+	mov	16(%rsi), %rdx
+	mov	24(%rsi), %ecx
+	movdqu	%xmm0, (%rdi)
+	mov	%rdx, 16(%rdi)
+	mov	%ecx, 24(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	28(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 28(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit29):
+	movdqu	(%rsi), %xmm0
+	movdqu	13(%rsi), %xmm2
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 13(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	29(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 29(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit30):
+	movdqu	(%rsi), %xmm0
+	movdqu	14(%rsi), %xmm2
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 14(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	30(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 30(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit31):
+	movdqu	(%rsi), %xmm0
+	movdqu	15(%rsi), %xmm2
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 15(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	31(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 31(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit32):
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm2
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 16(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	32(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 32(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(StrncpyExit33):
+	movdqu	(%rsi), %xmm0
+	movdqu	16(%rsi), %xmm2
+	mov	32(%rsi), %cl
+	movdqu	%xmm0, (%rdi)
+	movdqu	%xmm2, 16(%rdi)
+	mov	%cl, 32(%rdi)
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 33(%rdi)
+#endif
+	RETURN
+
+#ifndef USE_AS_STRCAT
+
+	.p2align 4
+L(Fill0):
+	RETURN
+
+	.p2align 4
+L(Fill1):
+	mov	%dl, (%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill2):
+	mov	%dx, (%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill3):
+	mov	%edx, -1(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill4):
+	mov	%edx, (%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill5):
+	mov	%edx, (%rdi)
+	mov	%dl, 4(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill6):
+	mov	%edx, (%rdi)
+	mov	%dx, 4(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill7):
+	mov	%rdx, -1(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill8):
+	mov	%rdx, (%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill9):
+	mov	%rdx, (%rdi)
+	mov	%dl, 8(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill10):
+	mov	%rdx, (%rdi)
+	mov	%dx, 8(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill11):
+	mov	%rdx, (%rdi)
+	mov	%edx, 7(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill12):
+	mov	%rdx, (%rdi)
+	mov	%edx, 8(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill13):
+	mov	%rdx, (%rdi)
+	mov	%rdx, 5(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill14):
+	mov	%rdx, (%rdi)
+	mov	%rdx, 6(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill15):
+	movdqu	%xmm0, -1(%rdi)
+	RETURN
+
+	.p2align 4
+L(Fill16):
+	movdqu	%xmm0, (%rdi)
+	RETURN
+
+	.p2align 4
+L(CopyFrom1To16BytesUnalignedXmm2):
+	movdqu	%xmm2, (%rdi, %rcx)
+
+	.p2align 4
+L(CopyFrom1To16BytesXmmExit):
+	bsf	%rdx, %rdx
+	add	$15, %r8
+	add	%rcx, %rdi
+#ifdef USE_AS_STPCPY
+	lea	(%rdi, %rdx), %rax
+#endif
+	sub	%rdx, %r8
+	lea	1(%rdi, %rdx), %rdi
+
+	.p2align 4
+L(StrncpyFillTailWithZero):
+	pxor	%xmm0, %xmm0
+	xor	%rdx, %rdx
+	sub	$16, %r8
+	jbe	L(StrncpyFillExit)
+
+	movdqu	%xmm0, (%rdi)
+	add	$16, %rdi
+
+	mov	%rdi, %rsi
+	and	$0xf, %rsi
+	sub	%rsi, %rdi
+	add	%rsi, %r8
+	sub	$64, %r8
+	jb	L(StrncpyFillLess64)
+
+L(StrncpyFillLoopMovdqa):
+	movdqa	%xmm0, (%rdi)
+	movdqa	%xmm0, 16(%rdi)
+	movdqa	%xmm0, 32(%rdi)
+	movdqa	%xmm0, 48(%rdi)
+	add	$64, %rdi
+	sub	$64, %r8
+	jae	L(StrncpyFillLoopMovdqa)
+
+L(StrncpyFillLess64):
+	add	$32, %r8
+	jl	L(StrncpyFillLess32)
+	movdqa	%xmm0, (%rdi)
+	movdqa	%xmm0, 16(%rdi)
+	add	$32, %rdi
+	sub	$16, %r8
+	jl	L(StrncpyFillExit)
+	movdqa	%xmm0, (%rdi)
+	add	$16, %rdi
+	BRANCH_TO_JMPTBL_ENTRY (L(FillTable), %r8, 4)
+
+L(StrncpyFillLess32):
+	add	$16, %r8
+	jl	L(StrncpyFillExit)
+	movdqa	%xmm0, (%rdi)
+	add	$16, %rdi
+	BRANCH_TO_JMPTBL_ENTRY (L(FillTable), %r8, 4)
+
+L(StrncpyFillExit):
+	add	$16, %r8
+	BRANCH_TO_JMPTBL_ENTRY (L(FillTable), %r8, 4)
+
+/* end of ifndef USE_AS_STRCAT */
+#endif
+
+	.p2align 4
+L(UnalignedLeaveCase2OrCase3):
+	test	%rdx, %rdx
+	jnz	L(Unaligned64LeaveCase2)
+L(Unaligned64LeaveCase3):
+	lea	64(%r8), %rcx
+	and	$-16, %rcx
+	add	$48, %r8
+	jl	L(CopyFrom1To16BytesCase3)
+	movdqu	%xmm4, (%rdi)
+	sub	$16, %r8
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqu	%xmm5, 16(%rdi)
+	sub	$16, %r8
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqu	%xmm6, 32(%rdi)
+	sub	$16, %r8
+	jb	L(CopyFrom1To16BytesCase3)
+	movdqu	%xmm7, 48(%rdi)
+#ifdef USE_AS_STPCPY
+	lea	64(%rdi), %rax
+#endif
+#ifdef USE_AS_STRCAT
+	xor	%ch, %ch
+	movb	%ch, 64(%rdi)
+#endif
+	RETURN
+
+	.p2align 4
+L(Unaligned64LeaveCase2):
+	xor	%rcx, %rcx
+	pcmpeqb	%xmm4, %xmm0
+	pmovmskb %xmm0, %rdx
+	add	$48, %r8
+	jle	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%rdx, %rdx
+#ifndef USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm4)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+	pcmpeqb	%xmm5, %xmm0
+	pmovmskb %xmm0, %rdx
+	movdqu	%xmm4, (%rdi)
+	add	$16, %rcx
+	sub	$16, %r8
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%rdx, %rdx
+#ifndef USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm5)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	pcmpeqb	%xmm6, %xmm0
+	pmovmskb %xmm0, %rdx
+	movdqu	%xmm5, 16(%rdi)
+	add	$16, %rcx
+	sub	$16, %r8
+	jbe	L(CopyFrom1To16BytesCase2OrCase3)
+	test	%rdx, %rdx
+#ifndef USE_AS_STRCAT
+	jnz	L(CopyFrom1To16BytesUnalignedXmm6)
+#else
+	jnz	L(CopyFrom1To16Bytes)
+#endif
+
+	pcmpeqb	%xmm7, %xmm0
+	pmovmskb %xmm0, %rdx
+	movdqu	%xmm6, 32(%rdi)
+	lea	16(%rdi, %rcx), %rdi
+	lea	16(%rsi, %rcx), %rsi
+	bsf	%rdx, %rdx
+	cmp	%r8, %rdx
+	jb	L(CopyFrom1To16BytesExit)
+	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
+
+	.p2align 4
+L(ExitZero):
+#ifndef USE_AS_STRCAT
+	mov	%rdi, %rax
+#endif
+	RETURN
+
+#endif
+
+#ifndef USE_AS_STRCAT
+END (STRCPY)
+#else
+END (STRCAT)
+#endif
+	.p2align 4
+	.section .rodata
+L(ExitTable):
+	.int	JMPTBL(L(Exit1), L(ExitTable))
+	.int	JMPTBL(L(Exit2), L(ExitTable))
+	.int	JMPTBL(L(Exit3), L(ExitTable))
+	.int	JMPTBL(L(Exit4), L(ExitTable))
+	.int	JMPTBL(L(Exit5), L(ExitTable))
+	.int	JMPTBL(L(Exit6), L(ExitTable))
+	.int	JMPTBL(L(Exit7), L(ExitTable))
+	.int	JMPTBL(L(Exit8), L(ExitTable))
+	.int	JMPTBL(L(Exit9), L(ExitTable))
+	.int	JMPTBL(L(Exit10), L(ExitTable))
+	.int	JMPTBL(L(Exit11), L(ExitTable))
+	.int	JMPTBL(L(Exit12), L(ExitTable))
+	.int	JMPTBL(L(Exit13), L(ExitTable))
+	.int	JMPTBL(L(Exit14), L(ExitTable))
+	.int	JMPTBL(L(Exit15), L(ExitTable))
+	.int	JMPTBL(L(Exit16), L(ExitTable))
+	.int	JMPTBL(L(Exit17), L(ExitTable))
+	.int	JMPTBL(L(Exit18), L(ExitTable))
+	.int	JMPTBL(L(Exit19), L(ExitTable))
+	.int	JMPTBL(L(Exit20), L(ExitTable))
+	.int	JMPTBL(L(Exit21), L(ExitTable))
+	.int	JMPTBL(L(Exit22), L(ExitTable))
+	.int	JMPTBL(L(Exit23), L(ExitTable))
+	.int	JMPTBL(L(Exit24), L(ExitTable))
+	.int	JMPTBL(L(Exit25), L(ExitTable))
+	.int	JMPTBL(L(Exit26), L(ExitTable))
+	.int	JMPTBL(L(Exit27), L(ExitTable))
+	.int	JMPTBL(L(Exit28), L(ExitTable))
+	.int	JMPTBL(L(Exit29), L(ExitTable))
+	.int	JMPTBL(L(Exit30), L(ExitTable))
+	.int	JMPTBL(L(Exit31), L(ExitTable))
+	.int	JMPTBL(L(Exit32), L(ExitTable))
+#ifdef USE_AS_STRNCPY
+L(ExitStrncpyTable):
+	.int	JMPTBL(L(StrncpyExit0), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit1), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit2), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit3), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit4), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit5), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit6), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit7), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit8), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit9), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit10), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit11), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit12), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit13), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit14), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit15), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit16), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit17), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit18), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit19), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit20), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit21), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit22), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit23), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit24), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit25), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit26), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit27), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit28), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit29), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit30), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit31), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit32), L(ExitStrncpyTable))
+	.int	JMPTBL(L(StrncpyExit33), L(ExitStrncpyTable))
+# ifndef USE_AS_STRCAT
+	.p2align 4
+L(FillTable):
+	.int	JMPTBL(L(Fill0), L(FillTable))
+	.int	JMPTBL(L(Fill1), L(FillTable))
+	.int	JMPTBL(L(Fill2), L(FillTable))
+	.int	JMPTBL(L(Fill3), L(FillTable))
+	.int	JMPTBL(L(Fill4), L(FillTable))
+	.int	JMPTBL(L(Fill5), L(FillTable))
+	.int	JMPTBL(L(Fill6), L(FillTable))
+	.int	JMPTBL(L(Fill7), L(FillTable))
+	.int	JMPTBL(L(Fill8), L(FillTable))
+	.int	JMPTBL(L(Fill9), L(FillTable))
+	.int	JMPTBL(L(Fill10), L(FillTable))
+	.int	JMPTBL(L(Fill11), L(FillTable))
+	.int	JMPTBL(L(Fill12), L(FillTable))
+	.int	JMPTBL(L(Fill13), L(FillTable))
+	.int	JMPTBL(L(Fill14), L(FillTable))
+	.int	JMPTBL(L(Fill15), L(FillTable))
+	.int	JMPTBL(L(Fill16), L(FillTable))
+# endif
+#endif
diff --git a/libc/arch-x86_64/string/sse2-strlen-slm.S b/libc/arch-x86_64/string/sse2-strlen-slm.S
new file mode 100644
index 0000000..3772fe7
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-strlen-slm.S
@@ -0,0 +1,294 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef USE_AS_STRCAT
+
+#ifndef STRLEN
+# define STRLEN		strlen
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc			.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc			.cfi_endproc
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)			\
+	.type name,  @function; 	\
+	.globl name;			\
+	.p2align 4;			\
+name:					\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)			\
+	cfi_endproc;			\
+	.size name, .-name
+#endif
+#define RETURN ret
+	.section .text.sse2,"ax",@progbits
+ENTRY (STRLEN)
+/* end ifndef USE_AS_STRCAT */
+#endif
+	xor	%rax, %rax
+	mov	%edi, %ecx
+	and	$0x3f, %ecx
+	pxor	%xmm0, %xmm0
+	cmp	$0x30, %ecx
+	ja	L(next)
+	movdqu	(%rdi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pmovmskb %xmm0, %edx
+	test	%edx, %edx
+	jnz	L(exit_less16)
+	mov	%rdi, %rax
+	and	$-16, %rax
+	jmp	L(align16_start)
+L(next):
+	mov	%rdi, %rax
+	and	$-16, %rax
+	pcmpeqb	(%rax), %xmm0
+	mov	$-1, %r10d
+	sub	%rax, %rcx
+	shl	%cl, %r10d
+	pmovmskb %xmm0, %edx
+	and	%r10d, %edx
+	jnz	L(exit)
+L(align16_start):
+	pxor	%xmm0, %xmm0
+	pxor	%xmm1, %xmm1
+	pxor	%xmm2, %xmm2
+	pxor	%xmm3, %xmm3
+	pcmpeqb	16(%rax), %xmm0
+	pmovmskb %xmm0, %edx
+	test	%edx, %edx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%rax), %xmm1
+	pmovmskb %xmm1, %edx
+	test	%edx, %edx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%rax), %xmm2
+	pmovmskb %xmm2, %edx
+	test	%edx, %edx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%rax), %xmm3
+	pmovmskb %xmm3, %edx
+	test	%edx, %edx
+	jnz	L(exit64)
+
+	pcmpeqb	80(%rax), %xmm0
+	add	$64, %rax
+	pmovmskb %xmm0, %edx
+	test	%edx, %edx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%rax), %xmm1
+	pmovmskb %xmm1, %edx
+	test	%edx, %edx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%rax), %xmm2
+	pmovmskb %xmm2, %edx
+	test	%edx, %edx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%rax), %xmm3
+	pmovmskb %xmm3, %edx
+	test	%edx, %edx
+	jnz	L(exit64)
+
+	pcmpeqb	80(%rax), %xmm0
+	add	$64, %rax
+	pmovmskb %xmm0, %edx
+	test	%edx, %edx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%rax), %xmm1
+	pmovmskb %xmm1, %edx
+	test	%edx, %edx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%rax), %xmm2
+	pmovmskb %xmm2, %edx
+	test	%edx, %edx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%rax), %xmm3
+	pmovmskb %xmm3, %edx
+	test	%edx, %edx
+	jnz	L(exit64)
+	
+	pcmpeqb	80(%rax), %xmm0
+	add	$64, %rax
+	pmovmskb %xmm0, %edx
+	test	%edx, %edx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%rax), %xmm1
+	pmovmskb %xmm1, %edx
+	test	%edx, %edx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%rax), %xmm2
+	pmovmskb %xmm2, %edx
+	test	%edx, %edx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%rax), %xmm3
+	pmovmskb %xmm3, %edx
+	test	%edx, %edx
+	jnz	L(exit64)
+	
+
+	test	$0x3f, %rax
+	jz	L(align64_loop)
+
+	pcmpeqb	80(%rax), %xmm0
+	add	$80, %rax
+	pmovmskb %xmm0, %edx
+	test	%edx, %edx
+	jnz	L(exit)
+
+	test	$0x3f, %rax
+	jz	L(align64_loop)
+
+	pcmpeqb	16(%rax), %xmm1
+	add	$16, %rax
+	pmovmskb %xmm1, %edx
+	test	%edx, %edx
+	jnz	L(exit)
+
+	test	$0x3f, %rax
+	jz	L(align64_loop)
+
+	pcmpeqb	16(%rax), %xmm2
+	add	$16, %rax
+	pmovmskb %xmm2, %edx
+	test	%edx, %edx
+	jnz	L(exit)
+
+	test	$0x3f, %rax
+	jz	L(align64_loop)
+
+	pcmpeqb	16(%rax), %xmm3
+	add	$16, %rax
+	pmovmskb %xmm3, %edx
+	test	%edx, %edx
+	jnz	L(exit)
+
+	add	$16, %rax
+	.p2align 4
+	L(align64_loop):
+	movaps	(%rax),	%xmm4
+	pminub	16(%rax), 	%xmm4
+	movaps	32(%rax), 	%xmm5
+	pminub	48(%rax), 	%xmm5
+	add	$64, 	%rax
+	pminub	%xmm4,	%xmm5
+	pcmpeqb	%xmm0,	%xmm5
+	pmovmskb %xmm5,	%edx
+	test	%edx,	%edx
+	jz	L(align64_loop)
+
+
+	pcmpeqb	-64(%rax), %xmm0
+	sub	$80, 	%rax
+	pmovmskb %xmm0, %edx
+	test	%edx, %edx
+	jnz	L(exit16)
+
+	pcmpeqb	32(%rax), %xmm1
+	pmovmskb %xmm1, %edx
+	test	%edx, %edx
+	jnz	L(exit32)
+
+	pcmpeqb	48(%rax), %xmm2
+	pmovmskb %xmm2, %edx
+	test	%edx, %edx
+	jnz	L(exit48)
+
+	pcmpeqb	64(%rax), %xmm3
+	pmovmskb %xmm3, %edx
+	sub	%rdi, %rax
+	bsf	%rdx, %rdx
+	add	%rdx, %rax
+	add	$64, %rax
+	RETURN
+
+	.p2align 4
+L(exit):
+	sub	%rdi, %rax
+L(exit_less16):
+	bsf	%rdx, %rdx
+	add	%rdx, %rax
+	RETURN
+	.p2align 4
+L(exit16):
+	sub	%rdi, %rax
+	bsf	%rdx, %rdx
+	add	%rdx, %rax
+	add	$16, %rax
+	RETURN
+	.p2align 4
+L(exit32):
+	sub	%rdi, %rax
+	bsf	%rdx, %rdx
+	add	%rdx, %rax
+	add	$32, %rax
+	RETURN
+	.p2align 4
+L(exit48):
+	sub	%rdi, %rax
+	bsf	%rdx, %rdx
+	add	%rdx, %rax
+	add	$48, %rax
+	RETURN
+	.p2align 4
+L(exit64):
+	sub	%rdi, %rax
+	bsf	%rdx, %rdx
+	add	%rdx, %rax
+	add	$64, %rax
+#ifndef USE_AS_STRCAT
+	RETURN
+
+END (STRLEN)
+#endif
diff --git a/libc/arch-x86_64/string/sse2-strncat-slm.S b/libc/arch-x86_64/string/sse2-strncat-slm.S
new file mode 100644
index 0000000..6b4a430
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-strncat-slm.S
@@ -0,0 +1,33 @@
+/*

+Copyright (c) 2014, Intel Corporation

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+

+    * Redistributions of source code must retain the above copyright notice,

+    * this list of conditions and the following disclaimer.

+

+    * Redistributions in binary form must reproduce the above copyright notice,

+    * this list of conditions and the following disclaimer in the documentation

+    * and/or other materials provided with the distribution.

+

+    * Neither the name of Intel Corporation nor the names of its contributors

+    * may be used to endorse or promote products derived from this software

+    * without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+*/

+

+#define USE_AS_STRNCAT

+#define STRCAT		strncat

+#include "sse2-strcat-slm.S"

diff --git a/libc/arch-x86_64/string/sse2-strncpy-slm.S b/libc/arch-x86_64/string/sse2-strncpy-slm.S
new file mode 100644
index 0000000..594e78f
--- /dev/null
+++ b/libc/arch-x86_64/string/sse2-strncpy-slm.S
@@ -0,0 +1,33 @@
+/*

+Copyright (c) 2014, Intel Corporation

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+

+    * Redistributions of source code must retain the above copyright notice,

+    * this list of conditions and the following disclaimer.

+

+    * Redistributions in binary form must reproduce the above copyright notice,

+    * this list of conditions and the following disclaimer in the documentation

+    * and/or other materials provided with the distribution.

+

+    * Neither the name of Intel Corporation nor the names of its contributors

+    * may be used to endorse or promote products derived from this software

+    * without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+*/

+

+#define USE_AS_STRNCPY

+#define STRCPY		strncpy

+#include "sse2-strcpy-slm.S"

diff --git a/libc/arch-x86_64/string/sse4-memcmp-slm.S b/libc/arch-x86_64/string/sse4-memcmp-slm.S
new file mode 100644
index 0000000..8a8b180
--- /dev/null
+++ b/libc/arch-x86_64/string/sse4-memcmp-slm.S
@@ -0,0 +1,1799 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "cache.h"
+
+#ifndef MEMCMP
+# define MEMCMP		memcmp
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef ALIGN
+# define ALIGN(n)	.p2align n
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc			.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc			.cfi_endproc
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)			\
+	.type name,  @function; 	\
+	.globl name;			\
+	.p2align 4;			\
+name:					\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)			\
+	cfi_endproc;			\
+	.size name, .-name
+#endif
+
+#ifndef ALIGN
+# define ALIGN(n)	.p2align n
+#endif
+
+#define JMPTBL(I, B)	(I - B)
+
+#define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)		\
+  lea		TABLE(%rip), %r11;				\
+  movslq	(%r11, INDEX, SCALE), %rcx;			\
+  add		%r11, %rcx;					\
+  jmp		*%rcx;						\
+  ud2
+
+	.section .text.sse4.1,"ax",@progbits
+ENTRY (MEMCMP)
+#ifdef USE_AS_WMEMCMP
+	shl	$2, %rdx
+#endif
+	pxor	%xmm0, %xmm0
+	cmp	$79, %rdx
+	ja	L(79bytesormore)
+#ifndef USE_AS_WMEMCMP
+	cmp	$1, %rdx
+	je	L(firstbyte)
+#endif
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+#ifndef USE_AS_WMEMCMP
+	ALIGN (4)
+L(firstbyte):
+	movzbl	(%rdi), %eax
+	movzbl	(%rsi), %ecx
+	sub	%ecx, %eax
+	ret
+#endif
+
+	ALIGN (4)
+L(79bytesormore):
+	movdqu	(%rsi), %xmm1
+	movdqu	(%rdi), %xmm2
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+	mov	%rsi, %rcx
+	and	$-16, %rsi
+	add	$16, %rsi
+	sub	%rsi, %rcx
+
+	sub	%rcx, %rdi
+	add	%rcx, %rdx
+	test	$0xf, %rdi
+	jz	L(2aligned)
+
+	cmp	$128, %rdx
+	ja	L(128bytesormore)
+L(less128bytes):
+	sub	$64, %rdx
+
+	movdqu	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqu	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+
+	movdqu	32(%rdi), %xmm2
+	pxor	32(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(48bytesin256)
+
+	movdqu	48(%rdi), %xmm2
+	pxor	48(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(64bytesin256)
+	cmp	$32, %rdx
+	jb	L(less32bytesin64)
+
+	movdqu	64(%rdi), %xmm2
+	pxor	64(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(80bytesin256)
+
+	movdqu	80(%rdi), %xmm2
+	pxor	80(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(96bytesin256)
+	sub	$32, %rdx
+	add	$32, %rdi
+	add	$32, %rsi
+L(less32bytesin64):
+	add	$64, %rdi
+	add	$64, %rsi
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+L(128bytesormore):
+	cmp	$512, %rdx
+	ja	L(512bytesormore)
+	cmp	$256, %rdx
+	ja	L(less512bytes)
+L(less256bytes):
+	sub	$128, %rdx
+
+	movdqu	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqu	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+
+	movdqu	32(%rdi), %xmm2
+	pxor	32(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(48bytesin256)
+
+	movdqu	48(%rdi), %xmm2
+	pxor	48(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(64bytesin256)
+
+	movdqu	64(%rdi), %xmm2
+	pxor	64(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(80bytesin256)
+
+	movdqu	80(%rdi), %xmm2
+	pxor	80(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(96bytesin256)
+
+	movdqu	96(%rdi), %xmm2
+	pxor	96(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(112bytesin256)
+
+	movdqu	112(%rdi), %xmm2
+	pxor	112(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(128bytesin256)
+
+	add	$128, %rsi
+	add	$128, %rdi
+
+	cmp	$64, %rdx
+	jae	L(less128bytes)
+
+	cmp	$32, %rdx
+	jb	L(less32bytesin128)
+
+	movdqu	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqu	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+	sub	$32, %rdx
+	add	$32, %rdi
+	add	$32, %rsi
+L(less32bytesin128):
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+L(less512bytes):
+	sub	$256, %rdx
+	movdqu	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqu	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+
+	movdqu	32(%rdi), %xmm2
+	pxor	32(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(48bytesin256)
+
+	movdqu	48(%rdi), %xmm2
+	pxor	48(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(64bytesin256)
+
+	movdqu	64(%rdi), %xmm2
+	pxor	64(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(80bytesin256)
+
+	movdqu	80(%rdi), %xmm2
+	pxor	80(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(96bytesin256)
+
+	movdqu	96(%rdi), %xmm2
+	pxor	96(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(112bytesin256)
+
+	movdqu	112(%rdi), %xmm2
+	pxor	112(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(128bytesin256)
+
+	movdqu	128(%rdi), %xmm2
+	pxor	128(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(144bytesin256)
+
+	movdqu	144(%rdi), %xmm2
+	pxor	144(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(160bytesin256)
+
+	movdqu	160(%rdi), %xmm2
+	pxor	160(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(176bytesin256)
+
+	movdqu	176(%rdi), %xmm2
+	pxor	176(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(192bytesin256)
+
+	movdqu	192(%rdi), %xmm2
+	pxor	192(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(208bytesin256)
+
+	movdqu	208(%rdi), %xmm2
+	pxor	208(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(224bytesin256)
+
+	movdqu	224(%rdi), %xmm2
+	pxor	224(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(240bytesin256)
+
+	movdqu	240(%rdi), %xmm2
+	pxor	240(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(256bytesin256)
+
+	add	$256, %rsi
+	add	$256, %rdi
+
+	cmp	$128, %rdx
+	jae	L(less256bytes)
+
+	cmp	$64, %rdx
+	jae	L(less128bytes)
+
+	cmp	$32, %rdx
+	jb	L(less32bytesin256)
+
+	movdqu	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqu	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+	sub	$32, %rdx
+	add	$32, %rdi
+	add	$32, %rsi
+L(less32bytesin256):
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+	ALIGN (4)
+L(512bytesormore):
+#ifdef DATA_CACHE_SIZE_HALF
+	mov	$DATA_CACHE_SIZE_HALF, %r8
+#else
+	mov	__x86_64_data_cache_size_half(%rip), %r8
+#endif
+	mov	%r8, %r9
+	shr	$1, %r8
+	add	%r9, %r8
+	cmp	%r8, %rdx
+	ja	L(L2_L3_cache_unaglined)
+	sub	$64, %rdx
+	ALIGN (4)
+L(64bytesormore_loop):
+	movdqu	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	movdqa	%xmm2, %xmm1
+
+	movdqu	16(%rdi), %xmm3
+	pxor	16(%rsi), %xmm3
+	por	%xmm3, %xmm1
+
+	movdqu	32(%rdi), %xmm4
+	pxor	32(%rsi), %xmm4
+	por	%xmm4, %xmm1
+
+	movdqu	48(%rdi), %xmm5
+	pxor	48(%rsi), %xmm5
+	por	%xmm5, %xmm1
+
+	ptest	%xmm1, %xmm0
+	jnc	L(64bytesormore_loop_end)
+	add	$64, %rsi
+	add	$64, %rdi
+	sub	$64, %rdx
+	jae	L(64bytesormore_loop)
+
+	add	$64, %rdx
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+L(L2_L3_cache_unaglined):
+	sub	$64, %rdx
+	ALIGN (4)
+L(L2_L3_unaligned_128bytes_loop):
+	prefetchnta 0x1c0(%rdi)
+	prefetchnta 0x1c0(%rsi)
+	movdqu	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	movdqa	%xmm2, %xmm1
+
+	movdqu	16(%rdi), %xmm3
+	pxor	16(%rsi), %xmm3
+	por	%xmm3, %xmm1
+
+	movdqu	32(%rdi), %xmm4
+	pxor	32(%rsi), %xmm4
+	por	%xmm4, %xmm1
+
+	movdqu	48(%rdi), %xmm5
+	pxor	48(%rsi), %xmm5
+	por	%xmm5, %xmm1
+
+	ptest	%xmm1, %xmm0
+	jnc	L(64bytesormore_loop_end)
+	add	$64, %rsi
+	add	$64, %rdi
+	sub	$64, %rdx
+	jae	L(L2_L3_unaligned_128bytes_loop)
+
+	add	$64, %rdx
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+/*
+ * This case is for machines which are sensitive for unaligned instructions.
+ */
+	ALIGN (4)
+L(2aligned):
+	cmp	$128, %rdx
+	ja	L(128bytesormorein2aligned)
+L(less128bytesin2aligned):
+	sub	$64, %rdx
+
+	movdqa	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqa	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+
+	movdqa	32(%rdi), %xmm2
+	pxor	32(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(48bytesin256)
+
+	movdqa	48(%rdi), %xmm2
+	pxor	48(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(64bytesin256)
+	cmp	$32, %rdx
+	jb	L(less32bytesin64in2alinged)
+
+	movdqa	64(%rdi), %xmm2
+	pxor	64(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(80bytesin256)
+
+	movdqa	80(%rdi), %xmm2
+	pxor	80(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(96bytesin256)
+	sub	$32, %rdx
+	add	$32, %rdi
+	add	$32, %rsi
+L(less32bytesin64in2alinged):
+	add	$64, %rdi
+	add	$64, %rsi
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+	ALIGN (4)
+L(128bytesormorein2aligned):
+	cmp	$512, %rdx
+	ja	L(512bytesormorein2aligned)
+	cmp	$256, %rdx
+	ja	L(256bytesormorein2aligned)
+L(less256bytesin2alinged):
+	sub	$128, %rdx
+
+	movdqa	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqa	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+
+	movdqa	32(%rdi), %xmm2
+	pxor	32(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(48bytesin256)
+
+	movdqa	48(%rdi), %xmm2
+	pxor	48(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(64bytesin256)
+
+	movdqa	64(%rdi), %xmm2
+	pxor	64(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(80bytesin256)
+
+	movdqa	80(%rdi), %xmm2
+	pxor	80(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(96bytesin256)
+
+	movdqa	96(%rdi), %xmm2
+	pxor	96(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(112bytesin256)
+
+	movdqa	112(%rdi), %xmm2
+	pxor	112(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(128bytesin256)
+
+	add	$128, %rsi
+	add	$128, %rdi
+
+	cmp	$64, %rdx
+	jae	L(less128bytesin2aligned)
+
+	cmp	$32, %rdx
+	jb	L(less32bytesin128in2aligned)
+
+	movdqu	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqu	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+	sub	$32, %rdx
+	add	$32, %rdi
+	add	$32, %rsi
+L(less32bytesin128in2aligned):
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+	ALIGN (4)
+L(256bytesormorein2aligned):
+
+	sub	$256, %rdx
+	movdqa	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqa	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+
+	movdqa	32(%rdi), %xmm2
+	pxor	32(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(48bytesin256)
+
+	movdqa	48(%rdi), %xmm2
+	pxor	48(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(64bytesin256)
+
+	movdqa	64(%rdi), %xmm2
+	pxor	64(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(80bytesin256)
+
+	movdqa	80(%rdi), %xmm2
+	pxor	80(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(96bytesin256)
+
+	movdqa	96(%rdi), %xmm2
+	pxor	96(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(112bytesin256)
+
+	movdqa	112(%rdi), %xmm2
+	pxor	112(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(128bytesin256)
+
+	movdqa	128(%rdi), %xmm2
+	pxor	128(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(144bytesin256)
+
+	movdqa	144(%rdi), %xmm2
+	pxor	144(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(160bytesin256)
+
+	movdqa	160(%rdi), %xmm2
+	pxor	160(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(176bytesin256)
+
+	movdqa	176(%rdi), %xmm2
+	pxor	176(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(192bytesin256)
+
+	movdqa	192(%rdi), %xmm2
+	pxor	192(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(208bytesin256)
+
+	movdqa	208(%rdi), %xmm2
+	pxor	208(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(224bytesin256)
+
+	movdqa	224(%rdi), %xmm2
+	pxor	224(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(240bytesin256)
+
+	movdqa	240(%rdi), %xmm2
+	pxor	240(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(256bytesin256)
+
+	add	$256, %rsi
+	add	$256, %rdi
+
+	cmp	$128, %rdx
+	jae	L(less256bytesin2alinged)
+
+	cmp	$64, %rdx
+	jae	L(less128bytesin2aligned)
+
+	cmp	$32, %rdx
+	jb	L(less32bytesin256in2alinged)
+
+	movdqa	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytesin256)
+
+	movdqa	16(%rdi), %xmm2
+	pxor	16(%rsi), %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(32bytesin256)
+	sub	$32, %rdx
+	add	$32, %rdi
+	add	$32, %rsi
+L(less32bytesin256in2alinged):
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+	ALIGN (4)
+L(512bytesormorein2aligned):
+#ifdef DATA_CACHE_SIZE_HALF
+	mov	$DATA_CACHE_SIZE_HALF, %r8
+#else
+	mov	__x86_64_data_cache_size_half(%rip), %r8
+#endif
+	mov	%r8, %r9
+	shr	$1, %r8
+	add	%r9, %r8
+	cmp	%r8, %rdx
+	ja	L(L2_L3_cache_aglined)
+
+	sub	$64, %rdx
+	ALIGN (4)
+L(64bytesormore_loopin2aligned):
+	movdqa	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	movdqa	%xmm2, %xmm1
+
+	movdqa	16(%rdi), %xmm3
+	pxor	16(%rsi), %xmm3
+	por	%xmm3, %xmm1
+
+	movdqa	32(%rdi), %xmm4
+	pxor	32(%rsi), %xmm4
+	por	%xmm4, %xmm1
+
+	movdqa	48(%rdi), %xmm5
+	pxor	48(%rsi), %xmm5
+	por	%xmm5, %xmm1
+
+	ptest	%xmm1, %xmm0
+	jnc	L(64bytesormore_loop_end)
+	add	$64, %rsi
+	add	$64, %rdi
+	sub	$64, %rdx
+	jae	L(64bytesormore_loopin2aligned)
+
+	add	$64, %rdx
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+L(L2_L3_cache_aglined):
+	sub	$64, %rdx
+	ALIGN (4)
+L(L2_L3_aligned_128bytes_loop):
+	prefetchnta 0x1c0(%rdi)
+	prefetchnta 0x1c0(%rsi)
+	movdqa	(%rdi), %xmm2
+	pxor	(%rsi), %xmm2
+	movdqa	%xmm2, %xmm1
+
+	movdqa	16(%rdi), %xmm3
+	pxor	16(%rsi), %xmm3
+	por	%xmm3, %xmm1
+
+	movdqa	32(%rdi), %xmm4
+	pxor	32(%rsi), %xmm4
+	por	%xmm4, %xmm1
+
+	movdqa	48(%rdi), %xmm5
+	pxor	48(%rsi), %xmm5
+	por	%xmm5, %xmm1
+
+	ptest	%xmm1, %xmm0
+	jnc	L(64bytesormore_loop_end)
+	add	$64, %rsi
+	add	$64, %rdi
+	sub	$64, %rdx
+	jae	L(L2_L3_aligned_128bytes_loop)
+
+	add	$64, %rdx
+	add	%rdx, %rsi
+	add	%rdx, %rdi
+	BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
+
+
+	ALIGN (4)
+L(64bytesormore_loop_end):
+	add	$16, %rdi
+	add	$16, %rsi
+	ptest	%xmm2, %xmm0
+	jnc	L(16bytes)
+
+	add	$16, %rdi
+	add	$16, %rsi
+	ptest	%xmm3, %xmm0
+	jnc	L(16bytes)
+
+	add	$16, %rdi
+	add	$16, %rsi
+	ptest	%xmm4, %xmm0
+	jnc	L(16bytes)
+
+	add	$16, %rdi
+	add	$16, %rsi
+	jmp	L(16bytes)
+
+L(256bytesin256):
+	add	$256, %rdi
+	add	$256, %rsi
+	jmp	L(16bytes)
+L(240bytesin256):
+	add	$240, %rdi
+	add	$240, %rsi
+	jmp	L(16bytes)
+L(224bytesin256):
+	add	$224, %rdi
+	add	$224, %rsi
+	jmp	L(16bytes)
+L(208bytesin256):
+	add	$208, %rdi
+	add	$208, %rsi
+	jmp	L(16bytes)
+L(192bytesin256):
+	add	$192, %rdi
+	add	$192, %rsi
+	jmp	L(16bytes)
+L(176bytesin256):
+	add	$176, %rdi
+	add	$176, %rsi
+	jmp	L(16bytes)
+L(160bytesin256):
+	add	$160, %rdi
+	add	$160, %rsi
+	jmp	L(16bytes)
+L(144bytesin256):
+	add	$144, %rdi
+	add	$144, %rsi
+	jmp	L(16bytes)
+L(128bytesin256):
+	add	$128, %rdi
+	add	$128, %rsi
+	jmp	L(16bytes)
+L(112bytesin256):
+	add	$112, %rdi
+	add	$112, %rsi
+	jmp	L(16bytes)
+L(96bytesin256):
+	add	$96, %rdi
+	add	$96, %rsi
+	jmp	L(16bytes)
+L(80bytesin256):
+	add	$80, %rdi
+	add	$80, %rsi
+	jmp	L(16bytes)
+L(64bytesin256):
+	add	$64, %rdi
+	add	$64, %rsi
+	jmp	L(16bytes)
+L(48bytesin256):
+	add	$16, %rdi
+	add	$16, %rsi
+L(32bytesin256):
+	add	$16, %rdi
+	add	$16, %rsi
+L(16bytesin256):
+	add	$16, %rdi
+	add	$16, %rsi
+L(16bytes):
+	mov	-16(%rdi), %rax
+	mov	-16(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+L(8bytes):
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(12bytes):
+	mov	-12(%rdi), %rax
+	mov	-12(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+L(4bytes):
+	mov	-4(%rsi), %ecx
+	mov	-4(%rdi), %eax
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+L(0bytes):
+	xor	%eax, %eax
+	ret
+
+#ifndef USE_AS_WMEMCMP
+/* unreal case for wmemcmp */
+	ALIGN (4)
+L(65bytes):
+	movdqu	-65(%rdi), %xmm1
+	movdqu	-65(%rsi), %xmm2
+	mov	$-65, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(49bytes):
+	movdqu	-49(%rdi), %xmm1
+	movdqu	-49(%rsi), %xmm2
+	mov	$-49, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(33bytes):
+	movdqu	-33(%rdi), %xmm1
+	movdqu	-33(%rsi), %xmm2
+	mov	$-33, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(17bytes):
+	mov	-17(%rdi), %rax
+	mov	-17(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+L(9bytes):
+	mov	-9(%rdi), %rax
+	mov	-9(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	movzbl	-1(%rdi), %eax
+	movzbl	-1(%rsi), %edx
+	sub	%edx, %eax
+	ret
+
+	ALIGN (4)
+L(13bytes):
+	mov	-13(%rdi), %rax
+	mov	-13(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(5bytes):
+	mov	-5(%rdi), %eax
+	mov	-5(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	movzbl	-1(%rdi), %eax
+	movzbl	-1(%rsi), %edx
+	sub	%edx, %eax
+	ret
+
+	ALIGN (4)
+L(66bytes):
+	movdqu	-66(%rdi), %xmm1
+	movdqu	-66(%rsi), %xmm2
+	mov	$-66, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(50bytes):
+	movdqu	-50(%rdi), %xmm1
+	movdqu	-50(%rsi), %xmm2
+	mov	$-50, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(34bytes):
+	movdqu	-34(%rdi), %xmm1
+	movdqu	-34(%rsi), %xmm2
+	mov	$-34, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(18bytes):
+	mov	-18(%rdi), %rax
+	mov	-18(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+L(10bytes):
+	mov	-10(%rdi), %rax
+	mov	-10(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	movzwl	-2(%rdi), %eax
+	movzwl	-2(%rsi), %ecx
+	cmp	%cl, %al
+	jne	L(end)
+	and	$0xffff, %eax
+	and	$0xffff, %ecx
+	sub	%ecx, %eax
+	ret
+
+	ALIGN (4)
+L(14bytes):
+	mov	-14(%rdi), %rax
+	mov	-14(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(6bytes):
+	mov	-6(%rdi), %eax
+	mov	-6(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+L(2bytes):
+	movzwl	-2(%rsi), %ecx
+	movzwl	-2(%rdi), %eax
+	cmp	%cl, %al
+	jne	L(end)
+	and	$0xffff, %eax
+	and	$0xffff, %ecx
+	sub	%ecx, %eax
+	ret
+
+	ALIGN (4)
+L(67bytes):
+	movdqu	-67(%rdi), %xmm2
+	movdqu	-67(%rsi), %xmm1
+	mov	$-67, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(51bytes):
+	movdqu	-51(%rdi), %xmm2
+	movdqu	-51(%rsi), %xmm1
+	mov	$-51, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(35bytes):
+	movdqu	-35(%rsi), %xmm1
+	movdqu	-35(%rdi), %xmm2
+	mov	$-35, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(19bytes):
+	mov	-19(%rdi), %rax
+	mov	-19(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+L(11bytes):
+	mov	-11(%rdi), %rax
+	mov	-11(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	-4(%rdi), %eax
+	mov	-4(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(15bytes):
+	mov	-15(%rdi), %rax
+	mov	-15(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(7bytes):
+	mov	-7(%rdi), %eax
+	mov	-7(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	mov	-4(%rdi), %eax
+	mov	-4(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(3bytes):
+	movzwl	-3(%rdi), %eax
+	movzwl	-3(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin2bytes)
+L(1bytes):
+	movzbl	-1(%rdi), %eax
+	movzbl	-1(%rsi), %ecx
+	sub	%ecx, %eax
+	ret
+#endif
+
+	ALIGN (4)
+L(68bytes):
+	movdqu	-68(%rdi), %xmm2
+	movdqu	-68(%rsi), %xmm1
+	mov	$-68, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(52bytes):
+	movdqu	-52(%rdi), %xmm2
+	movdqu	-52(%rsi), %xmm1
+	mov	$-52, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(36bytes):
+	movdqu	-36(%rdi), %xmm2
+	movdqu	-36(%rsi), %xmm1
+	mov	$-36, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(20bytes):
+	movdqu	-20(%rdi), %xmm2
+	movdqu	-20(%rsi), %xmm1
+	mov	$-20, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-4(%rdi), %eax
+	mov	-4(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	xor	%eax, %eax
+	ret
+
+#ifndef USE_AS_WMEMCMP
+/* unreal cases for wmemcmp */
+	ALIGN (4)
+L(69bytes):
+	movdqu	-69(%rsi), %xmm1
+	movdqu	-69(%rdi), %xmm2
+	mov	$-69, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(53bytes):
+	movdqu	-53(%rsi), %xmm1
+	movdqu	-53(%rdi), %xmm2
+	mov	$-53, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(37bytes):
+	movdqu	-37(%rsi), %xmm1
+	movdqu	-37(%rdi), %xmm2
+	mov	$-37, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(21bytes):
+	movdqu	-21(%rsi), %xmm1
+	movdqu	-21(%rdi), %xmm2
+	mov	$-21, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(70bytes):
+	movdqu	-70(%rsi), %xmm1
+	movdqu	-70(%rdi), %xmm2
+	mov	$-70, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(54bytes):
+	movdqu	-54(%rsi), %xmm1
+	movdqu	-54(%rdi), %xmm2
+	mov	$-54, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(38bytes):
+	movdqu	-38(%rsi), %xmm1
+	movdqu	-38(%rdi), %xmm2
+	mov	$-38, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(22bytes):
+	movdqu	-22(%rsi), %xmm1
+	movdqu	-22(%rdi), %xmm2
+	mov	$-22, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(71bytes):
+	movdqu	-71(%rsi), %xmm1
+	movdqu	-71(%rdi), %xmm2
+	mov	$-71, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(55bytes):
+	movdqu	-55(%rdi), %xmm2
+	movdqu	-55(%rsi), %xmm1
+	mov	$-55, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(39bytes):
+	movdqu	-39(%rdi), %xmm2
+	movdqu	-39(%rsi), %xmm1
+	mov	$-39, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(23bytes):
+	movdqu	-23(%rdi), %xmm2
+	movdqu	-23(%rsi), %xmm1
+	mov	$-23, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+#endif
+
+	ALIGN (4)
+L(72bytes):
+	movdqu	-72(%rsi), %xmm1
+	movdqu	-72(%rdi), %xmm2
+	mov	$-72, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(56bytes):
+	movdqu	-56(%rdi), %xmm2
+	movdqu	-56(%rsi), %xmm1
+	mov	$-56, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(40bytes):
+	movdqu	-40(%rdi), %xmm2
+	movdqu	-40(%rsi), %xmm1
+	mov	$-40, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(24bytes):
+	movdqu	-24(%rdi), %xmm2
+	movdqu	-24(%rsi), %xmm1
+	mov	$-24, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+#ifndef USE_AS_WMEMCMP
+/* unreal cases for wmemcmp */
+	ALIGN (4)
+L(73bytes):
+	movdqu	-73(%rsi), %xmm1
+	movdqu	-73(%rdi), %xmm2
+	mov	$-73, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(57bytes):
+	movdqu	-57(%rdi), %xmm2
+	movdqu	-57(%rsi), %xmm1
+	mov	$-57, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(41bytes):
+	movdqu	-41(%rdi), %xmm2
+	movdqu	-41(%rsi), %xmm1
+	mov	$-41, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(25bytes):
+	movdqu	-25(%rdi), %xmm2
+	movdqu	-25(%rsi), %xmm1
+	mov	$-25, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-9(%rdi), %rax
+	mov	-9(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	movzbl	-1(%rdi), %eax
+	movzbl	-1(%rsi), %ecx
+	sub	%ecx, %eax
+	ret
+
+	ALIGN (4)
+L(74bytes):
+	movdqu	-74(%rsi), %xmm1
+	movdqu	-74(%rdi), %xmm2
+	mov	$-74, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(58bytes):
+	movdqu	-58(%rdi), %xmm2
+	movdqu	-58(%rsi), %xmm1
+	mov	$-58, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(42bytes):
+	movdqu	-42(%rdi), %xmm2
+	movdqu	-42(%rsi), %xmm1
+	mov	$-42, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(26bytes):
+	movdqu	-26(%rdi), %xmm2
+	movdqu	-26(%rsi), %xmm1
+	mov	$-26, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-10(%rdi), %rax
+	mov	-10(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	movzwl	-2(%rdi), %eax
+	movzwl	-2(%rsi), %ecx
+	jmp	L(diffin2bytes)
+
+	ALIGN (4)
+L(75bytes):
+	movdqu	-75(%rsi), %xmm1
+	movdqu	-75(%rdi), %xmm2
+	mov	$-75, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(59bytes):
+	movdqu	-59(%rdi), %xmm2
+	movdqu	-59(%rsi), %xmm1
+	mov	$-59, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(43bytes):
+	movdqu	-43(%rdi), %xmm2
+	movdqu	-43(%rsi), %xmm1
+	mov	$-43, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(27bytes):
+	movdqu	-27(%rdi), %xmm2
+	movdqu	-27(%rsi), %xmm1
+	mov	$-27, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-11(%rdi), %rax
+	mov	-11(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	-4(%rdi), %eax
+	mov	-4(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	xor	%eax, %eax
+	ret
+#endif
+	ALIGN (4)
+L(76bytes):
+	movdqu	-76(%rsi), %xmm1
+	movdqu	-76(%rdi), %xmm2
+	mov	$-76, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(60bytes):
+	movdqu	-60(%rdi), %xmm2
+	movdqu	-60(%rsi), %xmm1
+	mov	$-60, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(44bytes):
+	movdqu	-44(%rdi), %xmm2
+	movdqu	-44(%rsi), %xmm1
+	mov	$-44, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(28bytes):
+	movdqu	-28(%rdi), %xmm2
+	movdqu	-28(%rsi), %xmm1
+	mov	$-28, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-12(%rdi), %rax
+	mov	-12(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	-4(%rdi), %eax
+	mov	-4(%rsi), %ecx
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	xor	%eax, %eax
+	ret
+
+#ifndef USE_AS_WMEMCMP
+/* unreal cases for wmemcmp */
+	ALIGN (4)
+L(77bytes):
+	movdqu	-77(%rsi), %xmm1
+	movdqu	-77(%rdi), %xmm2
+	mov	$-77, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(61bytes):
+	movdqu	-61(%rdi), %xmm2
+	movdqu	-61(%rsi), %xmm1
+	mov	$-61, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(45bytes):
+	movdqu	-45(%rdi), %xmm2
+	movdqu	-45(%rsi), %xmm1
+	mov	$-45, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(29bytes):
+	movdqu	-29(%rdi), %xmm2
+	movdqu	-29(%rsi), %xmm1
+	mov	$-29, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	mov	-13(%rdi), %rax
+	mov	-13(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(78bytes):
+	movdqu	-78(%rsi), %xmm1
+	movdqu	-78(%rdi), %xmm2
+	mov	$-78, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(62bytes):
+	movdqu	-62(%rdi), %xmm2
+	movdqu	-62(%rsi), %xmm1
+	mov	$-62, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(46bytes):
+	movdqu	-46(%rdi), %xmm2
+	movdqu	-46(%rsi), %xmm1
+	mov	$-46, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(30bytes):
+	movdqu	-30(%rdi), %xmm2
+	movdqu	-30(%rsi), %xmm1
+	mov	$-30, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-14(%rdi), %rax
+	mov	-14(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+	ALIGN (4)
+L(79bytes):
+	movdqu	-79(%rsi), %xmm1
+	movdqu	-79(%rdi), %xmm2
+	mov	$-79, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(63bytes):
+	movdqu	-63(%rdi), %xmm2
+	movdqu	-63(%rsi), %xmm1
+	mov	$-63, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(47bytes):
+	movdqu	-47(%rdi), %xmm2
+	movdqu	-47(%rsi), %xmm1
+	mov	$-47, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(31bytes):
+	movdqu	-31(%rdi), %xmm2
+	movdqu	-31(%rsi), %xmm1
+	mov	$-31, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+	mov	-15(%rdi), %rax
+	mov	-15(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+#endif
+	ALIGN (4)
+L(64bytes):
+	movdqu	-64(%rdi), %xmm2
+	movdqu	-64(%rsi), %xmm1
+	mov	$-64, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(48bytes):
+	movdqu	-48(%rdi), %xmm2
+	movdqu	-48(%rsi), %xmm1
+	mov	$-48, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+L(32bytes):
+	movdqu	-32(%rdi), %xmm2
+	movdqu	-32(%rsi), %xmm1
+	mov	$-32, %dl
+	pxor	%xmm1, %xmm2
+	ptest	%xmm2, %xmm0
+	jnc	L(less16bytes)
+
+	mov	-16(%rdi), %rax
+	mov	-16(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+
+	mov	-8(%rdi), %rax
+	mov	-8(%rsi), %rcx
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	xor	%eax, %eax
+	ret
+
+/*
+ * Aligned 8 bytes to avoid 2 branch "taken" in one 16 alinged code block.
+ */
+	ALIGN (3)
+L(less16bytes):
+	movsbq	%dl, %rdx
+	mov	(%rsi, %rdx), %rcx
+	mov	(%rdi, %rdx), %rax
+	cmp	%rax, %rcx
+	jne	L(diffin8bytes)
+	mov	8(%rsi, %rdx), %rcx
+	mov	8(%rdi, %rdx), %rax
+L(diffin8bytes):
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	shr	$32, %rcx
+	shr	$32, %rax
+
+#ifdef USE_AS_WMEMCMP
+/* for wmemcmp */
+	cmp	%eax, %ecx
+	jne	L(diffin4bytes)
+	xor	%eax, %eax
+	ret
+#endif
+
+L(diffin4bytes):
+#ifndef USE_AS_WMEMCMP
+	cmp	%cx, %ax
+	jne	L(diffin2bytes)
+	shr	$16, %ecx
+	shr	$16, %eax
+L(diffin2bytes):
+	cmp	%cl, %al
+	jne	L(end)
+	and	$0xffff, %eax
+	and	$0xffff, %ecx
+	sub	%ecx, %eax
+	ret
+#else
+
+/* for wmemcmp */
+	mov	$1, %eax
+	jl	L(nequal_bigger)
+	neg	%eax
+	ret
+
+	ALIGN (4)
+L(nequal_bigger):
+	ret
+
+L(unreal_case):
+	xor	%eax, %eax
+	ret
+#endif
+
+	ALIGN (4)
+L(end):
+	and	$0xff, %eax
+	and	$0xff, %ecx
+	sub	%ecx, %eax
+	ret
+
+END (MEMCMP)
+
+	.section .rodata.sse4.1,"a",@progbits
+	ALIGN (3)
+#ifndef USE_AS_WMEMCMP
+L(table_64bytes):
+	.int	JMPTBL (L(0bytes), L(table_64bytes))
+	.int	JMPTBL (L(1bytes), L(table_64bytes))
+	.int	JMPTBL (L(2bytes), L(table_64bytes))
+	.int	JMPTBL (L(3bytes), L(table_64bytes))
+	.int	JMPTBL (L(4bytes), L(table_64bytes))
+	.int	JMPTBL (L(5bytes), L(table_64bytes))
+	.int	JMPTBL (L(6bytes), L(table_64bytes))
+	.int	JMPTBL (L(7bytes), L(table_64bytes))
+	.int	JMPTBL (L(8bytes), L(table_64bytes))
+	.int	JMPTBL (L(9bytes), L(table_64bytes))
+	.int	JMPTBL (L(10bytes), L(table_64bytes))
+	.int	JMPTBL (L(11bytes), L(table_64bytes))
+	.int	JMPTBL (L(12bytes), L(table_64bytes))
+	.int	JMPTBL (L(13bytes), L(table_64bytes))
+	.int	JMPTBL (L(14bytes), L(table_64bytes))
+	.int	JMPTBL (L(15bytes), L(table_64bytes))
+	.int	JMPTBL (L(16bytes), L(table_64bytes))
+	.int	JMPTBL (L(17bytes), L(table_64bytes))
+	.int	JMPTBL (L(18bytes), L(table_64bytes))
+	.int	JMPTBL (L(19bytes), L(table_64bytes))
+	.int	JMPTBL (L(20bytes), L(table_64bytes))
+	.int	JMPTBL (L(21bytes), L(table_64bytes))
+	.int	JMPTBL (L(22bytes), L(table_64bytes))
+	.int	JMPTBL (L(23bytes), L(table_64bytes))
+	.int	JMPTBL (L(24bytes), L(table_64bytes))
+	.int	JMPTBL (L(25bytes), L(table_64bytes))
+	.int	JMPTBL (L(26bytes), L(table_64bytes))
+	.int	JMPTBL (L(27bytes), L(table_64bytes))
+	.int	JMPTBL (L(28bytes), L(table_64bytes))
+	.int	JMPTBL (L(29bytes), L(table_64bytes))
+	.int	JMPTBL (L(30bytes), L(table_64bytes))
+	.int	JMPTBL (L(31bytes), L(table_64bytes))
+	.int	JMPTBL (L(32bytes), L(table_64bytes))
+	.int	JMPTBL (L(33bytes), L(table_64bytes))
+	.int	JMPTBL (L(34bytes), L(table_64bytes))
+	.int	JMPTBL (L(35bytes), L(table_64bytes))
+	.int	JMPTBL (L(36bytes), L(table_64bytes))
+	.int	JMPTBL (L(37bytes), L(table_64bytes))
+	.int	JMPTBL (L(38bytes), L(table_64bytes))
+	.int	JMPTBL (L(39bytes), L(table_64bytes))
+	.int	JMPTBL (L(40bytes), L(table_64bytes))
+	.int	JMPTBL (L(41bytes), L(table_64bytes))
+	.int	JMPTBL (L(42bytes), L(table_64bytes))
+	.int	JMPTBL (L(43bytes), L(table_64bytes))
+	.int	JMPTBL (L(44bytes), L(table_64bytes))
+	.int	JMPTBL (L(45bytes), L(table_64bytes))
+	.int	JMPTBL (L(46bytes), L(table_64bytes))
+	.int	JMPTBL (L(47bytes), L(table_64bytes))
+	.int	JMPTBL (L(48bytes), L(table_64bytes))
+	.int	JMPTBL (L(49bytes), L(table_64bytes))
+	.int	JMPTBL (L(50bytes), L(table_64bytes))
+	.int	JMPTBL (L(51bytes), L(table_64bytes))
+	.int	JMPTBL (L(52bytes), L(table_64bytes))
+	.int	JMPTBL (L(53bytes), L(table_64bytes))
+	.int	JMPTBL (L(54bytes), L(table_64bytes))
+	.int	JMPTBL (L(55bytes), L(table_64bytes))
+	.int	JMPTBL (L(56bytes), L(table_64bytes))
+	.int	JMPTBL (L(57bytes), L(table_64bytes))
+	.int	JMPTBL (L(58bytes), L(table_64bytes))
+	.int	JMPTBL (L(59bytes), L(table_64bytes))
+	.int	JMPTBL (L(60bytes), L(table_64bytes))
+	.int	JMPTBL (L(61bytes), L(table_64bytes))
+	.int	JMPTBL (L(62bytes), L(table_64bytes))
+	.int	JMPTBL (L(63bytes), L(table_64bytes))
+	.int	JMPTBL (L(64bytes), L(table_64bytes))
+	.int	JMPTBL (L(65bytes), L(table_64bytes))
+	.int	JMPTBL (L(66bytes), L(table_64bytes))
+	.int	JMPTBL (L(67bytes), L(table_64bytes))
+	.int	JMPTBL (L(68bytes), L(table_64bytes))
+	.int	JMPTBL (L(69bytes), L(table_64bytes))
+	.int	JMPTBL (L(70bytes), L(table_64bytes))
+	.int	JMPTBL (L(71bytes), L(table_64bytes))
+	.int	JMPTBL (L(72bytes), L(table_64bytes))
+	.int	JMPTBL (L(73bytes), L(table_64bytes))
+	.int	JMPTBL (L(74bytes), L(table_64bytes))
+	.int	JMPTBL (L(75bytes), L(table_64bytes))
+	.int	JMPTBL (L(76bytes), L(table_64bytes))
+	.int	JMPTBL (L(77bytes), L(table_64bytes))
+	.int	JMPTBL (L(78bytes), L(table_64bytes))
+	.int	JMPTBL (L(79bytes), L(table_64bytes))
+#else
+L(table_64bytes):
+	.int	JMPTBL (L(0bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(4bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(8bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(12bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(16bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(20bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(24bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(28bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(32bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(36bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(40bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(44bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(48bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(52bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(56bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(60bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(64bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(68bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(72bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(76bytes), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+	.int	JMPTBL (L(unreal_case), L(table_64bytes))
+#endif
diff --git a/libc/arch-x86_64/string/ssse3-strcmp-slm.S b/libc/arch-x86_64/string/ssse3-strcmp-slm.S
new file mode 100644
index 0000000..0dd8c27
--- /dev/null
+++ b/libc/arch-x86_64/string/ssse3-strcmp-slm.S
@@ -0,0 +1,1925 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef USE_AS_STRNCMP
+/* Since the counter, %r11, is unsigned, we branch to strcmp_exitz
+   if the new counter > the old one or is 0.  */
+#define UPDATE_STRNCMP_COUNTER				\
+	/* calculate left number to compare */		\
+	lea	-16(%rcx, %r11), %r9;			\
+	cmp	%r9, %r11;				\
+	jb	L(strcmp_exitz);			\
+	test	%r9, %r9;				\
+	je	L(strcmp_exitz);			\
+	mov	%r9, %r11
+
+#else
+#define UPDATE_STRNCMP_COUNTER
+#ifndef STRCMP
+#define STRCMP		strcmp
+#endif
+#endif
+
+#ifndef L
+# define L(label)	.L##label
+#endif
+
+#ifndef cfi_startproc
+# define cfi_startproc			.cfi_startproc
+#endif
+
+#ifndef cfi_endproc
+# define cfi_endproc			.cfi_endproc
+#endif
+
+#ifndef ENTRY
+# define ENTRY(name)			\
+	.type name,  @function; 	\
+	.globl name;			\
+	.p2align 4;			\
+name:					\
+	cfi_startproc
+#endif
+
+#ifndef END
+# define END(name)			\
+	cfi_endproc;			\
+	.size name, .-name
+#endif
+#define RETURN ret
+	.section .text.ssse3,"ax",@progbits
+ENTRY (STRCMP)
+/*
+ * This implementation uses SSE to compare up to 16 bytes at a time.
+ */
+#ifdef USE_AS_STRNCMP
+	test	%rdx, %rdx
+	je	L(strcmp_exitz)
+	cmp	$1, %rdx
+	je	L(Byte0)
+	mov	%rdx, %r11
+#endif
+	mov	%esi, %ecx
+	mov	%edi, %eax
+/* Use 64bit AND here to avoid long NOP padding.  */
+	and	$0x3f, %rcx		/* rsi alignment in cache line */
+	and	$0x3f, %rax		/* rdi alignment in cache line */
+	cmp	$0x30, %ecx
+	ja	L(crosscache)	/* rsi: 16-byte load will cross cache line */
+	cmp	$0x30, %eax
+	ja	L(crosscache)	/* rdi: 16-byte load will cross cache line */
+	movlpd	(%rdi), %xmm1
+	movlpd	(%rsi), %xmm2
+	movhpd	8(%rdi), %xmm1
+	movhpd	8(%rsi), %xmm2
+	pxor	%xmm0, %xmm0		/* clear %xmm0 for null char checks */
+	pcmpeqb	%xmm1, %xmm0		/* Any null chars? */
+	pcmpeqb	%xmm2, %xmm1		/* compare first 16 bytes for equality */
+	psubb	%xmm0, %xmm1		/* packed sub of comparison results*/
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx		/* if first 16 bytes are same, edx == 0xffff */
+	jnz	L(less16bytes)	/* If not, find different value or null char */
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)	/* finish comparision */
+#endif
+	add	$16, %rsi		/* prepare to search next 16 bytes */
+	add	$16, %rdi		/* prepare to search next 16 bytes */
+
+	/*
+	 * Determine source and destination string offsets from 16-byte alignment.
+	 * Use relative offset difference between the two to determine which case
+	 * below to use.
+	 */
+	.p2align 4
+L(crosscache):
+	and	$0xfffffffffffffff0, %rsi	/* force %rsi is 16 byte aligned */
+	and	$0xfffffffffffffff0, %rdi	/* force %rdi is 16 byte aligned */
+	mov	$0xffff, %edx			/* for equivalent offset */
+	xor	%r8d, %r8d
+	and	$0xf, %ecx			/* offset of rsi */
+	and	$0xf, %eax			/* offset of rdi */
+	cmp	%eax, %ecx
+	je	L(ashr_0)			/* rsi and rdi relative offset same */
+	ja	L(bigger)
+	mov	%edx, %r8d			/* r8d is offset flag for exit tail */
+	xchg	%ecx, %eax
+	xchg	%rsi, %rdi
+L(bigger):
+	lea	15(%rax), %r9
+	sub	%rcx, %r9
+	lea	L(unaligned_table)(%rip), %r10
+	movslq	(%r10, %r9,4), %r9
+	lea	(%r10, %r9), %r10
+	jmp	*%r10				/* jump to corresponding case */
+
+/*
+ * The following cases will be handled by ashr_0
+ *  rcx(offset of rsi)  rax(offset of rdi)  relative offset  corresponding case
+ *        n(0~15)            n(0~15)           15(15+ n-n)         ashr_0
+ */
+	.p2align 4
+L(ashr_0):
+
+	movdqa	(%rsi), %xmm1
+	pxor	%xmm0, %xmm0			/* clear %xmm0 for null char check */
+	pcmpeqb	%xmm1, %xmm0			/* Any null chars? */
+	pcmpeqb	(%rdi), %xmm1			/* compare 16 bytes for equality */
+	psubb	%xmm0, %xmm1			/* packed sub of comparison results*/
+	pmovmskb %xmm1, %r9d
+	shr	%cl, %edx			/* adjust 0xffff for offset */
+	shr	%cl, %r9d			/* adjust for 16-byte offset */
+	sub	%r9d, %edx
+	/*
+	 * edx must be the same with r9d if in left byte (16-rcx) is equal to
+	 * the start from (16-rax) and no null char was seen.
+	 */
+	jne	L(less32bytes)		/* mismatch or null char */
+	UPDATE_STRNCMP_COUNTER
+	mov	$16, %rcx
+	mov	$16, %r9
+	pxor	%xmm0, %xmm0			/* clear xmm0, may have changed above */
+
+	/*
+	 * Now both strings are aligned at 16-byte boundary. Loop over strings
+	 * checking 32-bytes per iteration.
+	 */
+	.p2align 4
+L(loop_ashr_0):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)		/* mismatch or null char seen */
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+	add	$16, %rcx
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+	add	$16, %rcx
+	jmp	L(loop_ashr_0)
+
+/*
+ * The following cases will be handled by ashr_1
+ * rcx(offset of rsi)  rax(offset of rdi)   relative offset   	corresponding case
+ *        n(15)            n -15            0(15 +(n-15) - n)         ashr_1
+ */
+	.p2align 4
+L(ashr_1):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0		/* Any null chars? */
+	pslldq	$15, %xmm2		/* shift first string to align with second */
+	pcmpeqb	%xmm1, %xmm2		/* compare 16 bytes for equality */
+	psubb	%xmm0, %xmm2		/* packed sub of comparison results*/
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx		/* adjust 0xffff for offset */
+	shr	%cl, %r9d		/* adjust for 16-byte offset */
+	sub	%r9d, %edx
+	jnz	L(less32bytes)	/* mismatch or null char seen */
+	movdqa	(%rdi), %xmm3
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx		/* index for loads*/
+	mov	$1, %r9d		/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	1(%rdi), %r10
+	and	$0xfff, %r10		/* offset into 4K page */
+	sub	$0x1000, %r10		/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_1):
+	add	$16, %r10
+	jg	L(nibble_ashr_1)	/* cross page boundary */
+
+L(gobble_ashr_1):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4		 /* store for next cycle */
+
+	palignr $1, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_1)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4		/* store for next cycle */
+
+	palignr $1, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_1)
+
+	/*
+	 * Nibble avoids loads across page boundary. This is to avoid a potential
+	 * access into unmapped memory.
+	 */
+	.p2align 4
+L(nibble_ashr_1):
+	pcmpeqb	%xmm3, %xmm0		 /* check nibble for null char*/
+	pmovmskb %xmm0, %edx
+	test	$0xfffe, %edx
+	jnz	L(ashr_1_exittail)	/* find null char*/
+
+#ifdef USE_AS_STRNCMP
+	cmp	$14, %r11
+	jbe	L(ashr_1_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10		/* substract 4K from %r10 */
+	jmp	L(gobble_ashr_1)
+
+	/*
+	 * Once find null char, determine if there is a string mismatch
+	 * before the null char.
+	 */
+	.p2align 4
+L(ashr_1_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$1, %xmm0
+	psrldq	$1, %xmm3
+	jmp	L(aftertail)
+
+/*
+ * The following cases will be handled by ashr_2
+ * rcx(offset of rsi)  rax(offset of rdi)   relative offset   	corresponding case
+ *        n(14~15)            n -14         1(15 +(n-14) - n)         ashr_2
+ */
+	.p2align 4
+L(ashr_2):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$14, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$2, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	2(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_2):
+	add	$16, %r10
+	jg	L(nibble_ashr_2)
+
+L(gobble_ashr_2):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $2, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_2)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $2, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_2)
+
+	.p2align 4
+L(nibble_ashr_2):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xfffc, %edx
+	jnz	L(ashr_2_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$13, %r11
+	jbe	L(ashr_2_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_2)
+
+	.p2align 4
+L(ashr_2_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$2, %xmm0
+	psrldq	$2, %xmm3
+	jmp	L(aftertail)
+
+/*
+ * The following cases will be handled by ashr_3
+ *  rcx(offset of rsi)  rax(offset of rdi)  relative offset	 corresponding case
+ *        n(13~15)            n -13         2(15 +(n-13) - n)         ashr_3
+ */
+	.p2align 4
+L(ashr_3):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$13, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$3, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	3(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_3):
+	add	$16, %r10
+	jg	L(nibble_ashr_3)
+
+L(gobble_ashr_3):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $3, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_3)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $3, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_3)
+
+	.p2align 4
+L(nibble_ashr_3):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xfff8, %edx
+	jnz	L(ashr_3_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$12, %r11
+	jbe	L(ashr_3_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_3)
+
+	.p2align 4
+L(ashr_3_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$3, %xmm0
+	psrldq	$3, %xmm3
+	jmp	L(aftertail)
+
+/*
+ * The following cases will be handled by ashr_4
+ *  rcx(offset of rsi)  rax(offset of rdi)  relative offset	 corresponding case
+ *        n(12~15)            n -12         3(15 +(n-12) - n)         ashr_4
+ */
+	.p2align 4
+L(ashr_4):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$12, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$4, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	4(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_4):
+	add	$16, %r10
+	jg	L(nibble_ashr_4)
+
+L(gobble_ashr_4):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $4, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_4)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $4, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_4)
+
+	.p2align 4
+L(nibble_ashr_4):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xfff0, %edx
+	jnz	L(ashr_4_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$11, %r11
+	jbe	L(ashr_4_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_4)
+
+	.p2align 4
+L(ashr_4_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$4, %xmm0
+	psrldq	$4, %xmm3
+	jmp	L(aftertail)
+
+/*
+ * The following cases will be handled by ashr_5
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset      corresponding case
+ *        n(11~15)          n - 11      	  4(15 +(n-11) - n)         ashr_5
+ */
+	.p2align 4
+L(ashr_5):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$11, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$5, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	5(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_5):
+	add	$16, %r10
+	jg	L(nibble_ashr_5)
+
+L(gobble_ashr_5):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $5, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_5)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $5, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_5)
+
+	.p2align 4
+L(nibble_ashr_5):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xffe0, %edx
+	jnz	L(ashr_5_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$10, %r11
+	jbe	L(ashr_5_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_5)
+
+	.p2align 4
+L(ashr_5_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$5, %xmm0
+	psrldq	$5, %xmm3
+	jmp	L(aftertail)
+
+/*
+ * The following cases will be handled by ashr_6
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset      corresponding case
+ *        n(10~15)          n - 10      	  5(15 +(n-10) - n)         ashr_6
+ */
+	.p2align 4
+L(ashr_6):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$10, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$6, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	6(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_6):
+	add	$16, %r10
+	jg	L(nibble_ashr_6)
+
+L(gobble_ashr_6):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $6, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_6)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $6, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_6)
+
+	.p2align 4
+L(nibble_ashr_6):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xffc0, %edx
+	jnz	L(ashr_6_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$9, %r11
+	jbe	L(ashr_6_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_6)
+
+	.p2align 4
+L(ashr_6_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$6, %xmm0
+	psrldq	$6, %xmm3
+	jmp	L(aftertail)
+
+/*
+ * The following cases will be handled by ashr_7
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset      corresponding case
+ *        n(9~15)          n - 9      	        6(15 +(n - 9) - n)         ashr_7
+ */
+	.p2align 4
+L(ashr_7):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$9, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$7, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	7(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_7):
+	add	$16, %r10
+	jg	L(nibble_ashr_7)
+
+L(gobble_ashr_7):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $7, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_7)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $7, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_7)
+
+	.p2align 4
+L(nibble_ashr_7):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xff80, %edx
+	jnz	L(ashr_7_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$8, %r11
+	jbe	L(ashr_7_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_7)
+
+	.p2align 4
+L(ashr_7_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$7, %xmm0
+	psrldq	$7, %xmm3
+	jmp	L(aftertail)
+
+/*
+ *  The following cases will be handled by ashr_8
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset	 corresponding case
+ *        n(8~15)          n - 8      	        7(15 +(n - 8) - n)         ashr_8
+ */
+	.p2align 4
+L(ashr_8):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$8, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$8, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	8(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_8):
+	add	$16, %r10
+	jg	L(nibble_ashr_8)
+
+L(gobble_ashr_8):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $8, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_8)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $8, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_8)
+
+	.p2align 4
+L(nibble_ashr_8):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xff00, %edx
+	jnz	L(ashr_8_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$7, %r11
+	jbe	L(ashr_8_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_8)
+
+	.p2align 4
+L(ashr_8_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$8, %xmm0
+	psrldq	$8, %xmm3
+	jmp	L(aftertail)
+
+/*
+ *  The following cases will be handled by ashr_9
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset	 corresponding case
+ *        n(7~15)          n - 7      	        8(15 +(n - 7) - n)         ashr_9
+ */
+	.p2align 4
+L(ashr_9):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$7, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$9, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	9(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_9):
+	add	$16, %r10
+	jg	L(nibble_ashr_9)
+
+L(gobble_ashr_9):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $9, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_9)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $9, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3		/* store for next cycle */
+	jmp	L(loop_ashr_9)
+
+	.p2align 4
+L(nibble_ashr_9):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xfe00, %edx
+	jnz	L(ashr_9_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$6, %r11
+	jbe	L(ashr_9_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_9)
+
+	.p2align 4
+L(ashr_9_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$9, %xmm0
+	psrldq	$9, %xmm3
+	jmp	L(aftertail)
+
+/*
+ *  The following cases will be handled by ashr_10
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset	 corresponding case
+ *        n(6~15)          n - 6      	        9(15 +(n - 6) - n)         ashr_10
+ */
+	.p2align 4
+L(ashr_10):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$6, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$10, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	10(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_10):
+	add	$16, %r10
+	jg	L(nibble_ashr_10)
+
+L(gobble_ashr_10):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $10, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_10)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $10, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_10)
+
+	.p2align 4
+L(nibble_ashr_10):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xfc00, %edx
+	jnz	L(ashr_10_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$5, %r11
+	jbe	L(ashr_10_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_10)
+
+	.p2align 4
+L(ashr_10_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$10, %xmm0
+	psrldq	$10, %xmm3
+	jmp	L(aftertail)
+
+/*
+ *  The following cases will be handled by ashr_11
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset	 corresponding case
+ *        n(5~15)          n - 5      	        10(15 +(n - 5) - n)         ashr_11
+ */
+	.p2align 4
+L(ashr_11):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$5, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$11, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	11(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_11):
+	add	$16, %r10
+	jg	L(nibble_ashr_11)
+
+L(gobble_ashr_11):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $11, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_11)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $11, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_11)
+
+	.p2align 4
+L(nibble_ashr_11):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xf800, %edx
+	jnz	L(ashr_11_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$4, %r11
+	jbe	L(ashr_11_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_11)
+
+	.p2align 4
+L(ashr_11_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$11, %xmm0
+	psrldq	$11, %xmm3
+	jmp	L(aftertail)
+
+/*
+ *  The following cases will be handled by ashr_12
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset	 corresponding case
+ *        n(4~15)          n - 4      	        11(15 +(n - 4) - n)         ashr_12
+ */
+	.p2align 4
+L(ashr_12):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$4, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$12, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	12(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_12):
+	add	$16, %r10
+	jg	L(nibble_ashr_12)
+
+L(gobble_ashr_12):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $12, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_12)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $12, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_12)
+
+	.p2align 4
+L(nibble_ashr_12):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xf000, %edx
+	jnz	L(ashr_12_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$3, %r11
+	jbe	L(ashr_12_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_12)
+
+	.p2align 4
+L(ashr_12_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$12, %xmm0
+	psrldq	$12, %xmm3
+	jmp	L(aftertail)
+
+/*
+ *  The following cases will be handled by ashr_13
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset	 corresponding case
+ *        n(3~15)          n - 3      	        12(15 +(n - 3) - n)         ashr_13
+ */
+	.p2align 4
+L(ashr_13):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$3, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$13, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	13(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_13):
+	add	$16, %r10
+	jg	L(nibble_ashr_13)
+
+L(gobble_ashr_13):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $13, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_13)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $13, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_13)
+
+	.p2align 4
+L(nibble_ashr_13):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xe000, %edx
+	jnz	L(ashr_13_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$2, %r11
+	jbe	L(ashr_13_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_13)
+
+	.p2align 4
+L(ashr_13_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq  $13, %xmm0
+	psrldq  $13, %xmm3
+	jmp	L(aftertail)
+
+/*
+ *  The following cases will be handled by ashr_14
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset	 corresponding case
+ *        n(2~15)          n - 2      	        13(15 +(n - 2) - n)         ashr_14
+ */
+	.p2align 4
+L(ashr_14):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq  $2, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$14, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	14(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_14):
+	add	$16, %r10
+	jg	L(nibble_ashr_14)
+
+L(gobble_ashr_14):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $14, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_14)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $14, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_14)
+
+	.p2align 4
+L(nibble_ashr_14):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0xc000, %edx
+	jnz	L(ashr_14_exittail)
+
+#ifdef USE_AS_STRNCMP
+	cmp	$1, %r11
+	jbe	L(ashr_14_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_14)
+
+	.p2align 4
+L(ashr_14_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$14, %xmm0
+	psrldq	$14, %xmm3
+	jmp	L(aftertail)
+
+/*
+ *  The following cases will be handled by ashr_15
+ *  rcx(offset of rsi)  rax(offset of rdi)        relative offset	 corresponding case
+ *        n(1~15)          n - 1      	        14(15 +(n - 1) - n)         ashr_15
+ */
+	.p2align 4
+L(ashr_15):
+	pxor	%xmm0, %xmm0
+	movdqa	(%rdi), %xmm2
+	movdqa	(%rsi), %xmm1
+	pcmpeqb	%xmm1, %xmm0
+	pslldq	$1, %xmm2
+	pcmpeqb	%xmm1, %xmm2
+	psubb	%xmm0, %xmm2
+	pmovmskb %xmm2, %r9d
+	shr	%cl, %edx
+	shr	%cl, %r9d
+	sub	%r9d, %edx
+	jnz	L(less32bytes)
+
+	movdqa	(%rdi), %xmm3
+
+	UPDATE_STRNCMP_COUNTER
+
+	pxor	%xmm0, %xmm0
+	mov	$16, %rcx	/* index for loads */
+	mov	$15, %r9d	/* byte position left over from less32bytes case */
+	/*
+	 * Setup %r10 value allows us to detect crossing a page boundary.
+	 * When %r10 goes positive we have crossed a page boundary and
+	 * need to do a nibble.
+	 */
+	lea	15(%rdi), %r10
+	and	$0xfff, %r10	/* offset into 4K page */
+
+	sub	$0x1000, %r10	/* subtract 4K pagesize */
+
+	.p2align 4
+L(loop_ashr_15):
+	add	$16, %r10
+	jg	L(nibble_ashr_15)
+
+L(gobble_ashr_15):
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $15, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+
+	add	$16, %r10
+	jg	L(nibble_ashr_15)	/* cross page boundary */
+
+	movdqa	(%rsi, %rcx), %xmm1
+	movdqa	(%rdi, %rcx), %xmm2
+	movdqa	%xmm2, %xmm4
+
+	palignr $15, %xmm3, %xmm2        /* merge into one 16byte value */
+
+	pcmpeqb	%xmm1, %xmm0
+	pcmpeqb	%xmm2, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	sub	$0xffff, %edx
+	jnz	L(exit)
+
+#ifdef USE_AS_STRNCMP
+	sub	$16, %r11
+	jbe	L(strcmp_exitz)
+#endif
+
+	add	$16, %rcx
+	movdqa	%xmm4, %xmm3
+	jmp	L(loop_ashr_15)
+
+	.p2align 4
+L(nibble_ashr_15):
+	pcmpeqb	%xmm3, %xmm0		/* check nibble for null char */
+	pmovmskb %xmm0, %edx
+	test	$0x8000, %edx
+	jnz	L(ashr_15_exittail)
+
+#ifdef USE_AS_STRNCMP
+	test	%r11, %r11
+	je	L(ashr_15_exittail)
+#endif
+
+	pxor	%xmm0, %xmm0
+	sub	$0x1000, %r10
+	jmp	L(gobble_ashr_15)
+
+	.p2align 4
+L(ashr_15_exittail):
+	movdqa	(%rsi, %rcx), %xmm1
+	psrldq	$15, %xmm3
+	psrldq	$15, %xmm0
+
+	.p2align 4
+L(aftertail):
+	pcmpeqb	%xmm3, %xmm1
+	psubb	%xmm0, %xmm1
+	pmovmskb %xmm1, %edx
+	not	%edx
+
+	.p2align 4
+L(exit):
+	lea	-16(%r9, %rcx), %rax	/* locate the exact offset for rdi */
+L(less32bytes):
+	lea	(%rdi, %rax), %rdi	/* locate the exact address for first operand(rdi) */
+	lea	(%rsi, %rcx), %rsi	/* locate the exact address for second operand(rsi) */
+	test	%r8d, %r8d
+	jz	L(ret)
+	xchg	%rsi, %rdi		/* recover original order according to flag(%r8d) */
+
+	.p2align 4
+L(ret):
+L(less16bytes):
+	bsf	%rdx, %rdx		/* find and store bit index in %rdx */
+
+#ifdef USE_AS_STRNCMP
+	sub	%rdx, %r11
+	jbe	L(strcmp_exitz)
+#endif
+	movzbl	(%rsi, %rdx), %ecx
+	movzbl	(%rdi, %rdx), %eax
+
+	sub	%ecx, %eax
+	ret
+
+L(strcmp_exitz):
+	xor	%eax, %eax
+	ret
+
+	.p2align 4
+L(Byte0):
+	movzx	(%rsi), %ecx
+	movzx	(%rdi), %eax
+
+	sub	%ecx, %eax
+	ret
+END (STRCMP)
+
+	.section .rodata,"a",@progbits
+	.p2align 3
+L(unaligned_table):
+	.int	L(ashr_1) - L(unaligned_table)
+	.int	L(ashr_2) - L(unaligned_table)
+	.int	L(ashr_3) - L(unaligned_table)
+	.int	L(ashr_4) - L(unaligned_table)
+	.int	L(ashr_5) - L(unaligned_table)
+	.int	L(ashr_6) - L(unaligned_table)
+	.int	L(ashr_7) - L(unaligned_table)
+	.int	L(ashr_8) - L(unaligned_table)
+	.int	L(ashr_9) - L(unaligned_table)
+	.int	L(ashr_10) - L(unaligned_table)
+	.int	L(ashr_11) - L(unaligned_table)
+	.int	L(ashr_12) - L(unaligned_table)
+	.int	L(ashr_13) - L(unaligned_table)
+	.int	L(ashr_14) - L(unaligned_table)
+	.int	L(ashr_15) - L(unaligned_table)
+	.int	L(ashr_0) - L(unaligned_table)
diff --git a/libc/arch-x86_64/string/ssse3-strncmp-slm.S b/libc/arch-x86_64/string/ssse3-strncmp-slm.S
new file mode 100644
index 0000000..0e40775
--- /dev/null
+++ b/libc/arch-x86_64/string/ssse3-strncmp-slm.S
@@ -0,0 +1,33 @@
+/*
+Copyright (c) 2014, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+    * this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+    * this list of conditions and the following disclaimer in the documentation
+    * and/or other materials provided with the distribution.
+
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define USE_AS_STRNCMP
+#define STRCMP		strncmp
+#include "ssse3-strcmp-slm.S"
diff --git a/libc/arch-x86_64/syscalls.mk b/libc/arch-x86_64/syscalls.mk
deleted file mode 100644
index ec09e77..0000000
--- a/libc/arch-x86_64/syscalls.mk
+++ /dev/null
@@ -1,191 +0,0 @@
-# Generated by gensyscalls.py. Do not edit.
-syscall_src :=
-syscall_src += arch-x86_64/syscalls/__arch_prctl.S
-syscall_src += arch-x86_64/syscalls/__brk.S
-syscall_src += arch-x86_64/syscalls/__epoll_pwait.S
-syscall_src += arch-x86_64/syscalls/__exit.S
-syscall_src += arch-x86_64/syscalls/__getcpu.S
-syscall_src += arch-x86_64/syscalls/__getcwd.S
-syscall_src += arch-x86_64/syscalls/__getpriority.S
-syscall_src += arch-x86_64/syscalls/__ioctl.S
-syscall_src += arch-x86_64/syscalls/__openat.S
-syscall_src += arch-x86_64/syscalls/__ppoll.S
-syscall_src += arch-x86_64/syscalls/__pselect6.S
-syscall_src += arch-x86_64/syscalls/__ptrace.S
-syscall_src += arch-x86_64/syscalls/__reboot.S
-syscall_src += arch-x86_64/syscalls/__rt_sigaction.S
-syscall_src += arch-x86_64/syscalls/__rt_sigpending.S
-syscall_src += arch-x86_64/syscalls/__rt_sigprocmask.S
-syscall_src += arch-x86_64/syscalls/__rt_sigsuspend.S
-syscall_src += arch-x86_64/syscalls/__rt_sigtimedwait.S
-syscall_src += arch-x86_64/syscalls/__sched_getaffinity.S
-syscall_src += arch-x86_64/syscalls/__set_tid_address.S
-syscall_src += arch-x86_64/syscalls/__syslog.S
-syscall_src += arch-x86_64/syscalls/__timer_create.S
-syscall_src += arch-x86_64/syscalls/__timer_delete.S
-syscall_src += arch-x86_64/syscalls/__timer_getoverrun.S
-syscall_src += arch-x86_64/syscalls/__timer_gettime.S
-syscall_src += arch-x86_64/syscalls/__timer_settime.S
-syscall_src += arch-x86_64/syscalls/__waitid.S
-syscall_src += arch-x86_64/syscalls/_exit.S
-syscall_src += arch-x86_64/syscalls/accept.S
-syscall_src += arch-x86_64/syscalls/acct.S
-syscall_src += arch-x86_64/syscalls/bind.S
-syscall_src += arch-x86_64/syscalls/capget.S
-syscall_src += arch-x86_64/syscalls/capset.S
-syscall_src += arch-x86_64/syscalls/chdir.S
-syscall_src += arch-x86_64/syscalls/chroot.S
-syscall_src += arch-x86_64/syscalls/clock_getres.S
-syscall_src += arch-x86_64/syscalls/clock_gettime.S
-syscall_src += arch-x86_64/syscalls/clock_nanosleep.S
-syscall_src += arch-x86_64/syscalls/clock_settime.S
-syscall_src += arch-x86_64/syscalls/close.S
-syscall_src += arch-x86_64/syscalls/connect.S
-syscall_src += arch-x86_64/syscalls/delete_module.S
-syscall_src += arch-x86_64/syscalls/dup.S
-syscall_src += arch-x86_64/syscalls/dup3.S
-syscall_src += arch-x86_64/syscalls/epoll_create1.S
-syscall_src += arch-x86_64/syscalls/epoll_ctl.S
-syscall_src += arch-x86_64/syscalls/eventfd.S
-syscall_src += arch-x86_64/syscalls/execve.S
-syscall_src += arch-x86_64/syscalls/faccessat.S
-syscall_src += arch-x86_64/syscalls/fchdir.S
-syscall_src += arch-x86_64/syscalls/fchmod.S
-syscall_src += arch-x86_64/syscalls/fchmodat.S
-syscall_src += arch-x86_64/syscalls/fchown.S
-syscall_src += arch-x86_64/syscalls/fchownat.S
-syscall_src += arch-x86_64/syscalls/fcntl.S
-syscall_src += arch-x86_64/syscalls/fdatasync.S
-syscall_src += arch-x86_64/syscalls/fgetxattr.S
-syscall_src += arch-x86_64/syscalls/flistxattr.S
-syscall_src += arch-x86_64/syscalls/flock.S
-syscall_src += arch-x86_64/syscalls/fremovexattr.S
-syscall_src += arch-x86_64/syscalls/fsetxattr.S
-syscall_src += arch-x86_64/syscalls/fstat.S
-syscall_src += arch-x86_64/syscalls/fstatat.S
-syscall_src += arch-x86_64/syscalls/fstatfs.S
-syscall_src += arch-x86_64/syscalls/fsync.S
-syscall_src += arch-x86_64/syscalls/ftruncate.S
-syscall_src += arch-x86_64/syscalls/futex.S
-syscall_src += arch-x86_64/syscalls/getdents.S
-syscall_src += arch-x86_64/syscalls/getegid.S
-syscall_src += arch-x86_64/syscalls/geteuid.S
-syscall_src += arch-x86_64/syscalls/getgid.S
-syscall_src += arch-x86_64/syscalls/getgroups.S
-syscall_src += arch-x86_64/syscalls/getitimer.S
-syscall_src += arch-x86_64/syscalls/getpeername.S
-syscall_src += arch-x86_64/syscalls/getpgid.S
-syscall_src += arch-x86_64/syscalls/getpid.S
-syscall_src += arch-x86_64/syscalls/getppid.S
-syscall_src += arch-x86_64/syscalls/getresgid.S
-syscall_src += arch-x86_64/syscalls/getresuid.S
-syscall_src += arch-x86_64/syscalls/getrlimit.S
-syscall_src += arch-x86_64/syscalls/getrusage.S
-syscall_src += arch-x86_64/syscalls/getsid.S
-syscall_src += arch-x86_64/syscalls/getsockname.S
-syscall_src += arch-x86_64/syscalls/getsockopt.S
-syscall_src += arch-x86_64/syscalls/gettid.S
-syscall_src += arch-x86_64/syscalls/gettimeofday.S
-syscall_src += arch-x86_64/syscalls/getuid.S
-syscall_src += arch-x86_64/syscalls/getxattr.S
-syscall_src += arch-x86_64/syscalls/init_module.S
-syscall_src += arch-x86_64/syscalls/inotify_add_watch.S
-syscall_src += arch-x86_64/syscalls/inotify_init1.S
-syscall_src += arch-x86_64/syscalls/inotify_rm_watch.S
-syscall_src += arch-x86_64/syscalls/ioprio_get.S
-syscall_src += arch-x86_64/syscalls/ioprio_set.S
-syscall_src += arch-x86_64/syscalls/kill.S
-syscall_src += arch-x86_64/syscalls/klogctl.S
-syscall_src += arch-x86_64/syscalls/lgetxattr.S
-syscall_src += arch-x86_64/syscalls/linkat.S
-syscall_src += arch-x86_64/syscalls/listen.S
-syscall_src += arch-x86_64/syscalls/listxattr.S
-syscall_src += arch-x86_64/syscalls/llistxattr.S
-syscall_src += arch-x86_64/syscalls/lremovexattr.S
-syscall_src += arch-x86_64/syscalls/lseek.S
-syscall_src += arch-x86_64/syscalls/lsetxattr.S
-syscall_src += arch-x86_64/syscalls/madvise.S
-syscall_src += arch-x86_64/syscalls/mincore.S
-syscall_src += arch-x86_64/syscalls/mkdirat.S
-syscall_src += arch-x86_64/syscalls/mknodat.S
-syscall_src += arch-x86_64/syscalls/mlock.S
-syscall_src += arch-x86_64/syscalls/mlockall.S
-syscall_src += arch-x86_64/syscalls/mmap.S
-syscall_src += arch-x86_64/syscalls/mount.S
-syscall_src += arch-x86_64/syscalls/mprotect.S
-syscall_src += arch-x86_64/syscalls/mremap.S
-syscall_src += arch-x86_64/syscalls/msync.S
-syscall_src += arch-x86_64/syscalls/munlock.S
-syscall_src += arch-x86_64/syscalls/munlockall.S
-syscall_src += arch-x86_64/syscalls/munmap.S
-syscall_src += arch-x86_64/syscalls/nanosleep.S
-syscall_src += arch-x86_64/syscalls/perf_event_open.S
-syscall_src += arch-x86_64/syscalls/personality.S
-syscall_src += arch-x86_64/syscalls/pipe2.S
-syscall_src += arch-x86_64/syscalls/prctl.S
-syscall_src += arch-x86_64/syscalls/pread64.S
-syscall_src += arch-x86_64/syscalls/prlimit64.S
-syscall_src += arch-x86_64/syscalls/pwrite64.S
-syscall_src += arch-x86_64/syscalls/read.S
-syscall_src += arch-x86_64/syscalls/readahead.S
-syscall_src += arch-x86_64/syscalls/readlinkat.S
-syscall_src += arch-x86_64/syscalls/readv.S
-syscall_src += arch-x86_64/syscalls/recvfrom.S
-syscall_src += arch-x86_64/syscalls/recvmsg.S
-syscall_src += arch-x86_64/syscalls/removexattr.S
-syscall_src += arch-x86_64/syscalls/renameat.S
-syscall_src += arch-x86_64/syscalls/sched_get_priority_max.S
-syscall_src += arch-x86_64/syscalls/sched_get_priority_min.S
-syscall_src += arch-x86_64/syscalls/sched_getparam.S
-syscall_src += arch-x86_64/syscalls/sched_getscheduler.S
-syscall_src += arch-x86_64/syscalls/sched_rr_get_interval.S
-syscall_src += arch-x86_64/syscalls/sched_setaffinity.S
-syscall_src += arch-x86_64/syscalls/sched_setparam.S
-syscall_src += arch-x86_64/syscalls/sched_setscheduler.S
-syscall_src += arch-x86_64/syscalls/sched_yield.S
-syscall_src += arch-x86_64/syscalls/sendfile.S
-syscall_src += arch-x86_64/syscalls/sendmsg.S
-syscall_src += arch-x86_64/syscalls/sendto.S
-syscall_src += arch-x86_64/syscalls/setgid.S
-syscall_src += arch-x86_64/syscalls/setgroups.S
-syscall_src += arch-x86_64/syscalls/setitimer.S
-syscall_src += arch-x86_64/syscalls/setns.S
-syscall_src += arch-x86_64/syscalls/setpgid.S
-syscall_src += arch-x86_64/syscalls/setpriority.S
-syscall_src += arch-x86_64/syscalls/setregid.S
-syscall_src += arch-x86_64/syscalls/setresgid.S
-syscall_src += arch-x86_64/syscalls/setresuid.S
-syscall_src += arch-x86_64/syscalls/setreuid.S
-syscall_src += arch-x86_64/syscalls/setrlimit.S
-syscall_src += arch-x86_64/syscalls/setsid.S
-syscall_src += arch-x86_64/syscalls/setsockopt.S
-syscall_src += arch-x86_64/syscalls/settimeofday.S
-syscall_src += arch-x86_64/syscalls/setuid.S
-syscall_src += arch-x86_64/syscalls/setxattr.S
-syscall_src += arch-x86_64/syscalls/shutdown.S
-syscall_src += arch-x86_64/syscalls/sigaltstack.S
-syscall_src += arch-x86_64/syscalls/signalfd4.S
-syscall_src += arch-x86_64/syscalls/socket.S
-syscall_src += arch-x86_64/syscalls/socketpair.S
-syscall_src += arch-x86_64/syscalls/statfs.S
-syscall_src += arch-x86_64/syscalls/swapoff.S
-syscall_src += arch-x86_64/syscalls/swapon.S
-syscall_src += arch-x86_64/syscalls/symlinkat.S
-syscall_src += arch-x86_64/syscalls/sync.S
-syscall_src += arch-x86_64/syscalls/sysinfo.S
-syscall_src += arch-x86_64/syscalls/tgkill.S
-syscall_src += arch-x86_64/syscalls/timerfd_create.S
-syscall_src += arch-x86_64/syscalls/timerfd_gettime.S
-syscall_src += arch-x86_64/syscalls/timerfd_settime.S
-syscall_src += arch-x86_64/syscalls/times.S
-syscall_src += arch-x86_64/syscalls/tkill.S
-syscall_src += arch-x86_64/syscalls/truncate.S
-syscall_src += arch-x86_64/syscalls/umask.S
-syscall_src += arch-x86_64/syscalls/umount2.S
-syscall_src += arch-x86_64/syscalls/uname.S
-syscall_src += arch-x86_64/syscalls/unlinkat.S
-syscall_src += arch-x86_64/syscalls/unshare.S
-syscall_src += arch-x86_64/syscalls/utimensat.S
-syscall_src += arch-x86_64/syscalls/wait4.S
-syscall_src += arch-x86_64/syscalls/write.S
-syscall_src += arch-x86_64/syscalls/writev.S
diff --git a/libc/arch-x86_64/syscalls/__accept4.S b/libc/arch-x86_64/syscalls/__accept4.S
new file mode 100644
index 0000000..aa5beba
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__accept4.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__accept4)
+    movq    %rcx, %r10
+    movl    $__NR_accept4, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__accept4)
+.hidden __accept4
diff --git a/libc/arch-x86_64/syscalls/__arch_prctl.S b/libc/arch-x86_64/syscalls/__arch_prctl.S
index e878679..0a604f4 100644
--- a/libc/arch-x86_64/syscalls/__arch_prctl.S
+++ b/libc/arch-x86_64/syscalls/__arch_prctl.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__arch_prctl)
-.hidden _C_LABEL(__arch_prctl)
+.hidden __arch_prctl
diff --git a/libc/arch-x86_64/syscalls/__brk.S b/libc/arch-x86_64/syscalls/__brk.S
index 18c2997..b6c0f2f 100644
--- a/libc/arch-x86_64/syscalls/__brk.S
+++ b/libc/arch-x86_64/syscalls/__brk.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__brk)
-.hidden _C_LABEL(__brk)
+.hidden __brk
diff --git a/libc/arch-x86_64/syscalls/__clock_gettime.S b/libc/arch-x86_64/syscalls/__clock_gettime.S
new file mode 100644
index 0000000..ccacdb2
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__clock_gettime.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__clock_gettime)
+    movl    $__NR_clock_gettime, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__clock_gettime)
+.hidden __clock_gettime
diff --git a/libc/arch-x86_64/syscalls/__connect.S b/libc/arch-x86_64/syscalls/__connect.S
new file mode 100644
index 0000000..d7531ad
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__connect.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__connect)
+    movl    $__NR_connect, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__connect)
+.hidden __connect
diff --git a/libc/arch-x86_64/syscalls/__epoll_pwait.S b/libc/arch-x86_64/syscalls/__epoll_pwait.S
index ed913b0..b486c4a 100644
--- a/libc/arch-x86_64/syscalls/__epoll_pwait.S
+++ b/libc/arch-x86_64/syscalls/__epoll_pwait.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__epoll_pwait)
-.hidden _C_LABEL(__epoll_pwait)
+.hidden __epoll_pwait
diff --git a/libc/arch-x86_64/syscalls/__exit.S b/libc/arch-x86_64/syscalls/__exit.S
index da1f9f8..99b11fc 100644
--- a/libc/arch-x86_64/syscalls/__exit.S
+++ b/libc/arch-x86_64/syscalls/__exit.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__exit)
-.hidden _C_LABEL(__exit)
+.hidden __exit
diff --git a/libc/arch-x86_64/syscalls/__fadvise64.S b/libc/arch-x86_64/syscalls/__fadvise64.S
new file mode 100644
index 0000000..8810d88
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__fadvise64.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__fadvise64)
+    movq    %rcx, %r10
+    movl    $__NR_fadvise64, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__fadvise64)
+.hidden __fadvise64
diff --git a/libc/arch-x86_64/syscalls/__getcpu.S b/libc/arch-x86_64/syscalls/__getcpu.S
index 5a18494..3903e9f 100644
--- a/libc/arch-x86_64/syscalls/__getcpu.S
+++ b/libc/arch-x86_64/syscalls/__getcpu.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__getcpu)
-.hidden _C_LABEL(__getcpu)
+.hidden __getcpu
diff --git a/libc/arch-x86_64/syscalls/__getcwd.S b/libc/arch-x86_64/syscalls/__getcwd.S
index c9e9942..d39c1d7 100644
--- a/libc/arch-x86_64/syscalls/__getcwd.S
+++ b/libc/arch-x86_64/syscalls/__getcwd.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__getcwd)
-.hidden _C_LABEL(__getcwd)
+.hidden __getcwd
diff --git a/libc/arch-x86_64/syscalls/__getdents64.S b/libc/arch-x86_64/syscalls/__getdents64.S
new file mode 100644
index 0000000..b5eb943
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__getdents64.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getdents64)
+    movl    $__NR_getdents64, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__getdents64)
+.hidden __getdents64
diff --git a/libc/arch-x86_64/syscalls/__getpid.S b/libc/arch-x86_64/syscalls/__getpid.S
new file mode 100644
index 0000000..ec4316e
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__getpid.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__getpid)
+    movl    $__NR_getpid, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__getpid)
+.hidden __getpid
diff --git a/libc/arch-x86_64/syscalls/__getpriority.S b/libc/arch-x86_64/syscalls/__getpriority.S
index f5230e1..7c618a1 100644
--- a/libc/arch-x86_64/syscalls/__getpriority.S
+++ b/libc/arch-x86_64/syscalls/__getpriority.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__getpriority)
-.hidden _C_LABEL(__getpriority)
+.hidden __getpriority
diff --git a/libc/arch-x86_64/syscalls/__gettimeofday.S b/libc/arch-x86_64/syscalls/__gettimeofday.S
new file mode 100644
index 0000000..69b9b6e
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__gettimeofday.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__gettimeofday)
+    movl    $__NR_gettimeofday, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__gettimeofday)
+.hidden __gettimeofday
diff --git a/libc/arch-x86_64/syscalls/__ioctl.S b/libc/arch-x86_64/syscalls/__ioctl.S
index 8f30eb6..0eb34f0 100644
--- a/libc/arch-x86_64/syscalls/__ioctl.S
+++ b/libc/arch-x86_64/syscalls/__ioctl.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__ioctl)
-.hidden _C_LABEL(__ioctl)
+.hidden __ioctl
diff --git a/libc/arch-x86_64/syscalls/__openat.S b/libc/arch-x86_64/syscalls/__openat.S
index cd6a07f..14f53ca 100644
--- a/libc/arch-x86_64/syscalls/__openat.S
+++ b/libc/arch-x86_64/syscalls/__openat.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__openat)
-.hidden _C_LABEL(__openat)
+.hidden __openat
diff --git a/libc/arch-x86_64/syscalls/__ppoll.S b/libc/arch-x86_64/syscalls/__ppoll.S
index dd639ae..82b97dd 100644
--- a/libc/arch-x86_64/syscalls/__ppoll.S
+++ b/libc/arch-x86_64/syscalls/__ppoll.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__ppoll)
-.hidden _C_LABEL(__ppoll)
+.hidden __ppoll
diff --git a/libc/arch-x86_64/syscalls/__pselect6.S b/libc/arch-x86_64/syscalls/__pselect6.S
index c37483a..c11d814 100644
--- a/libc/arch-x86_64/syscalls/__pselect6.S
+++ b/libc/arch-x86_64/syscalls/__pselect6.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__pselect6)
-.hidden _C_LABEL(__pselect6)
+.hidden __pselect6
diff --git a/libc/arch-x86_64/syscalls/__ptrace.S b/libc/arch-x86_64/syscalls/__ptrace.S
index be42b91..729e007 100644
--- a/libc/arch-x86_64/syscalls/__ptrace.S
+++ b/libc/arch-x86_64/syscalls/__ptrace.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__ptrace)
-.hidden _C_LABEL(__ptrace)
+.hidden __ptrace
diff --git a/libc/arch-x86_64/syscalls/__reboot.S b/libc/arch-x86_64/syscalls/__reboot.S
index fc8e58d..b462dc7 100644
--- a/libc/arch-x86_64/syscalls/__reboot.S
+++ b/libc/arch-x86_64/syscalls/__reboot.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__reboot)
-.hidden _C_LABEL(__reboot)
+.hidden __reboot
diff --git a/libc/arch-x86_64/syscalls/__rt_sigaction.S b/libc/arch-x86_64/syscalls/__rt_sigaction.S
index 70602df..17c5995 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigaction.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigaction.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__rt_sigaction)
-.hidden _C_LABEL(__rt_sigaction)
+.hidden __rt_sigaction
diff --git a/libc/arch-x86_64/syscalls/__rt_sigpending.S b/libc/arch-x86_64/syscalls/__rt_sigpending.S
index 1caf131..b5b81bb 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigpending.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigpending.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__rt_sigpending)
-.hidden _C_LABEL(__rt_sigpending)
+.hidden __rt_sigpending
diff --git a/libc/arch-x86_64/syscalls/__rt_sigprocmask.S b/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
index d7e44a7..e8b3f2a 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__rt_sigprocmask)
-.hidden _C_LABEL(__rt_sigprocmask)
+.hidden __rt_sigprocmask
diff --git a/libc/arch-x86_64/syscalls/__rt_sigsuspend.S b/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
index 851b93e..f6366a2 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__rt_sigsuspend)
-.hidden _C_LABEL(__rt_sigsuspend)
+.hidden __rt_sigsuspend
diff --git a/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S b/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
index 6962d4a..9bcb811 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__rt_sigtimedwait)
-.hidden _C_LABEL(__rt_sigtimedwait)
+.hidden __rt_sigtimedwait
diff --git a/libc/arch-x86_64/syscalls/__sched_getaffinity.S b/libc/arch-x86_64/syscalls/__sched_getaffinity.S
index 861f06b..0ca6818 100644
--- a/libc/arch-x86_64/syscalls/__sched_getaffinity.S
+++ b/libc/arch-x86_64/syscalls/__sched_getaffinity.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__sched_getaffinity)
-.hidden _C_LABEL(__sched_getaffinity)
+.hidden __sched_getaffinity
diff --git a/libc/arch-x86_64/syscalls/__set_tid_address.S b/libc/arch-x86_64/syscalls/__set_tid_address.S
index fe7260f..3dad660 100644
--- a/libc/arch-x86_64/syscalls/__set_tid_address.S
+++ b/libc/arch-x86_64/syscalls/__set_tid_address.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__set_tid_address)
-.hidden _C_LABEL(__set_tid_address)
+.hidden __set_tid_address
diff --git a/libc/arch-x86_64/syscalls/__signalfd4.S b/libc/arch-x86_64/syscalls/__signalfd4.S
new file mode 100644
index 0000000..b44bfe5
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__signalfd4.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__signalfd4)
+    movq    %rcx, %r10
+    movl    $__NR_signalfd4, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__signalfd4)
+.hidden __signalfd4
diff --git a/libc/arch-x86_64/syscalls/__socket.S b/libc/arch-x86_64/syscalls/__socket.S
new file mode 100644
index 0000000..0563d2f
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__socket.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__socket)
+    movl    $__NR_socket, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__socket)
+.hidden __socket
diff --git a/libc/arch-x86_64/syscalls/__syslog.S b/libc/arch-x86_64/syscalls/__syslog.S
deleted file mode 100644
index 4e41149..0000000
--- a/libc/arch-x86_64/syscalls/__syslog.S
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(__syslog)
-    movl    $__NR_syslog, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(__syslog)
-.hidden _C_LABEL(__syslog)
diff --git a/libc/arch-x86_64/syscalls/__timer_create.S b/libc/arch-x86_64/syscalls/__timer_create.S
index 1c5c68e..cb955a4 100644
--- a/libc/arch-x86_64/syscalls/__timer_create.S
+++ b/libc/arch-x86_64/syscalls/__timer_create.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__timer_create)
-.hidden _C_LABEL(__timer_create)
+.hidden __timer_create
diff --git a/libc/arch-x86_64/syscalls/__timer_delete.S b/libc/arch-x86_64/syscalls/__timer_delete.S
index c826757..7abc7d8 100644
--- a/libc/arch-x86_64/syscalls/__timer_delete.S
+++ b/libc/arch-x86_64/syscalls/__timer_delete.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__timer_delete)
-.hidden _C_LABEL(__timer_delete)
+.hidden __timer_delete
diff --git a/libc/arch-x86_64/syscalls/__timer_getoverrun.S b/libc/arch-x86_64/syscalls/__timer_getoverrun.S
index 772b05e..f2a0e24 100644
--- a/libc/arch-x86_64/syscalls/__timer_getoverrun.S
+++ b/libc/arch-x86_64/syscalls/__timer_getoverrun.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__timer_getoverrun)
-.hidden _C_LABEL(__timer_getoverrun)
+.hidden __timer_getoverrun
diff --git a/libc/arch-x86_64/syscalls/__timer_gettime.S b/libc/arch-x86_64/syscalls/__timer_gettime.S
index 181069b..62c2b47 100644
--- a/libc/arch-x86_64/syscalls/__timer_gettime.S
+++ b/libc/arch-x86_64/syscalls/__timer_gettime.S
@@ -9,9 +9,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__timer_gettime)
-.hidden _C_LABEL(__timer_gettime)
+.hidden __timer_gettime
diff --git a/libc/arch-x86_64/syscalls/__timer_settime.S b/libc/arch-x86_64/syscalls/__timer_settime.S
index 11fe04e..225fa8e 100644
--- a/libc/arch-x86_64/syscalls/__timer_settime.S
+++ b/libc/arch-x86_64/syscalls/__timer_settime.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__timer_settime)
-.hidden _C_LABEL(__timer_settime)
+.hidden __timer_settime
diff --git a/libc/arch-x86_64/syscalls/__waitid.S b/libc/arch-x86_64/syscalls/__waitid.S
index 4317d78..ff8a3c5 100644
--- a/libc/arch-x86_64/syscalls/__waitid.S
+++ b/libc/arch-x86_64/syscalls/__waitid.S
@@ -10,9 +10,8 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(__waitid)
-.hidden _C_LABEL(__waitid)
+.hidden __waitid
diff --git a/libc/arch-x86_64/syscalls/_exit.S b/libc/arch-x86_64/syscalls/_exit.S
index f40cfe3..c79091d 100644
--- a/libc/arch-x86_64/syscalls/_exit.S
+++ b/libc/arch-x86_64/syscalls/_exit.S
@@ -9,8 +9,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(_exit)
+
+    .globl _Exit
+    .equ _Exit, _exit
diff --git a/libc/arch-x86_64/syscalls/accept.S b/libc/arch-x86_64/syscalls/accept.S
deleted file mode 100644
index 588fb82..0000000
--- a/libc/arch-x86_64/syscalls/accept.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(accept)
-    movl    $__NR_accept, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(accept)
diff --git a/libc/arch-x86_64/syscalls/acct.S b/libc/arch-x86_64/syscalls/acct.S
index 59af17d..a739707 100644
--- a/libc/arch-x86_64/syscalls/acct.S
+++ b/libc/arch-x86_64/syscalls/acct.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(acct)
diff --git a/libc/arch-x86_64/syscalls/bind.S b/libc/arch-x86_64/syscalls/bind.S
index 20dfa2d..e5bc263 100644
--- a/libc/arch-x86_64/syscalls/bind.S
+++ b/libc/arch-x86_64/syscalls/bind.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(bind)
diff --git a/libc/arch-x86_64/syscalls/capget.S b/libc/arch-x86_64/syscalls/capget.S
index 9cf73fb..9ce1583 100644
--- a/libc/arch-x86_64/syscalls/capget.S
+++ b/libc/arch-x86_64/syscalls/capget.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(capget)
diff --git a/libc/arch-x86_64/syscalls/capset.S b/libc/arch-x86_64/syscalls/capset.S
index f6cf2eb..2776756 100644
--- a/libc/arch-x86_64/syscalls/capset.S
+++ b/libc/arch-x86_64/syscalls/capset.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(capset)
diff --git a/libc/arch-x86_64/syscalls/chdir.S b/libc/arch-x86_64/syscalls/chdir.S
index a04f3aa..269905c 100644
--- a/libc/arch-x86_64/syscalls/chdir.S
+++ b/libc/arch-x86_64/syscalls/chdir.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(chdir)
diff --git a/libc/arch-x86_64/syscalls/chroot.S b/libc/arch-x86_64/syscalls/chroot.S
index 491086d..713b1b3 100644
--- a/libc/arch-x86_64/syscalls/chroot.S
+++ b/libc/arch-x86_64/syscalls/chroot.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(chroot)
diff --git a/libc/arch-x86_64/syscalls/clock_getres.S b/libc/arch-x86_64/syscalls/clock_getres.S
index d1d491e..f65d127 100644
--- a/libc/arch-x86_64/syscalls/clock_getres.S
+++ b/libc/arch-x86_64/syscalls/clock_getres.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(clock_getres)
diff --git a/libc/arch-x86_64/syscalls/clock_gettime.S b/libc/arch-x86_64/syscalls/clock_gettime.S
deleted file mode 100644
index 89ae616..0000000
--- a/libc/arch-x86_64/syscalls/clock_gettime.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(clock_gettime)
-    movl    $__NR_clock_gettime, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(clock_gettime)
diff --git a/libc/arch-x86_64/syscalls/clock_nanosleep.S b/libc/arch-x86_64/syscalls/clock_nanosleep.S
index 3833113..2a79bdd 100644
--- a/libc/arch-x86_64/syscalls/clock_nanosleep.S
+++ b/libc/arch-x86_64/syscalls/clock_nanosleep.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(clock_nanosleep)
diff --git a/libc/arch-x86_64/syscalls/clock_settime.S b/libc/arch-x86_64/syscalls/clock_settime.S
index 15b27aa..26070a4 100644
--- a/libc/arch-x86_64/syscalls/clock_settime.S
+++ b/libc/arch-x86_64/syscalls/clock_settime.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(clock_settime)
diff --git a/libc/arch-x86_64/syscalls/close.S b/libc/arch-x86_64/syscalls/close.S
index 361d82f..8a7ada1 100644
--- a/libc/arch-x86_64/syscalls/close.S
+++ b/libc/arch-x86_64/syscalls/close.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(close)
diff --git a/libc/arch-x86_64/syscalls/connect.S b/libc/arch-x86_64/syscalls/connect.S
deleted file mode 100644
index 23cdbae..0000000
--- a/libc/arch-x86_64/syscalls/connect.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(connect)
-    movl    $__NR_connect, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(connect)
diff --git a/libc/arch-x86_64/syscalls/delete_module.S b/libc/arch-x86_64/syscalls/delete_module.S
index 33f2354..63f17ad 100644
--- a/libc/arch-x86_64/syscalls/delete_module.S
+++ b/libc/arch-x86_64/syscalls/delete_module.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(delete_module)
diff --git a/libc/arch-x86_64/syscalls/dup.S b/libc/arch-x86_64/syscalls/dup.S
index dfc0def..5016f77 100644
--- a/libc/arch-x86_64/syscalls/dup.S
+++ b/libc/arch-x86_64/syscalls/dup.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(dup)
diff --git a/libc/arch-x86_64/syscalls/dup3.S b/libc/arch-x86_64/syscalls/dup3.S
index dcb4155..9abd168 100644
--- a/libc/arch-x86_64/syscalls/dup3.S
+++ b/libc/arch-x86_64/syscalls/dup3.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(dup3)
diff --git a/libc/arch-x86_64/syscalls/epoll_create1.S b/libc/arch-x86_64/syscalls/epoll_create1.S
index fa3c6d7..d1e4bfc 100644
--- a/libc/arch-x86_64/syscalls/epoll_create1.S
+++ b/libc/arch-x86_64/syscalls/epoll_create1.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(epoll_create1)
diff --git a/libc/arch-x86_64/syscalls/epoll_ctl.S b/libc/arch-x86_64/syscalls/epoll_ctl.S
index 72df97f..f429b96 100644
--- a/libc/arch-x86_64/syscalls/epoll_ctl.S
+++ b/libc/arch-x86_64/syscalls/epoll_ctl.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(epoll_ctl)
diff --git a/libc/arch-x86_64/syscalls/eventfd.S b/libc/arch-x86_64/syscalls/eventfd.S
index 99f585c..dcc5105 100644
--- a/libc/arch-x86_64/syscalls/eventfd.S
+++ b/libc/arch-x86_64/syscalls/eventfd.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(eventfd)
diff --git a/libc/arch-x86_64/syscalls/execve.S b/libc/arch-x86_64/syscalls/execve.S
index ea89d7d..947baa4 100644
--- a/libc/arch-x86_64/syscalls/execve.S
+++ b/libc/arch-x86_64/syscalls/execve.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(execve)
diff --git a/libc/arch-x86_64/syscalls/faccessat.S b/libc/arch-x86_64/syscalls/faccessat.S
index 238a4e1..05a6e78 100644
--- a/libc/arch-x86_64/syscalls/faccessat.S
+++ b/libc/arch-x86_64/syscalls/faccessat.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(faccessat)
diff --git a/libc/arch-x86_64/syscalls/fallocate.S b/libc/arch-x86_64/syscalls/fallocate.S
new file mode 100644
index 0000000..8307f7e
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/fallocate.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fallocate)
+    movq    %rcx, %r10
+    movl    $__NR_fallocate, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(fallocate)
+
+    .globl fallocate64
+    .equ fallocate64, fallocate
diff --git a/libc/arch-x86_64/syscalls/fchdir.S b/libc/arch-x86_64/syscalls/fchdir.S
index da14edd..d005c14 100644
--- a/libc/arch-x86_64/syscalls/fchdir.S
+++ b/libc/arch-x86_64/syscalls/fchdir.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fchdir)
diff --git a/libc/arch-x86_64/syscalls/fchmod.S b/libc/arch-x86_64/syscalls/fchmod.S
index a6d15fc..b35bd21 100644
--- a/libc/arch-x86_64/syscalls/fchmod.S
+++ b/libc/arch-x86_64/syscalls/fchmod.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fchmod)
diff --git a/libc/arch-x86_64/syscalls/fchmodat.S b/libc/arch-x86_64/syscalls/fchmodat.S
index daf71ab..2d78d8e 100644
--- a/libc/arch-x86_64/syscalls/fchmodat.S
+++ b/libc/arch-x86_64/syscalls/fchmodat.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fchmodat)
diff --git a/libc/arch-x86_64/syscalls/fchown.S b/libc/arch-x86_64/syscalls/fchown.S
index 8c68a15..d5bdc71 100644
--- a/libc/arch-x86_64/syscalls/fchown.S
+++ b/libc/arch-x86_64/syscalls/fchown.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fchown)
diff --git a/libc/arch-x86_64/syscalls/fchownat.S b/libc/arch-x86_64/syscalls/fchownat.S
index e5265dd..ff05e9e 100644
--- a/libc/arch-x86_64/syscalls/fchownat.S
+++ b/libc/arch-x86_64/syscalls/fchownat.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fchownat)
diff --git a/libc/arch-x86_64/syscalls/fcntl.S b/libc/arch-x86_64/syscalls/fcntl.S
index c562385..f28195b 100644
--- a/libc/arch-x86_64/syscalls/fcntl.S
+++ b/libc/arch-x86_64/syscalls/fcntl.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fcntl)
diff --git a/libc/arch-x86_64/syscalls/fdatasync.S b/libc/arch-x86_64/syscalls/fdatasync.S
index 3f9ee72..27239b9 100644
--- a/libc/arch-x86_64/syscalls/fdatasync.S
+++ b/libc/arch-x86_64/syscalls/fdatasync.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fdatasync)
diff --git a/libc/arch-x86_64/syscalls/fgetxattr.S b/libc/arch-x86_64/syscalls/fgetxattr.S
index 77f095b..7762474 100644
--- a/libc/arch-x86_64/syscalls/fgetxattr.S
+++ b/libc/arch-x86_64/syscalls/fgetxattr.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fgetxattr)
diff --git a/libc/arch-x86_64/syscalls/flistxattr.S b/libc/arch-x86_64/syscalls/flistxattr.S
index cd39298..aa02db1 100644
--- a/libc/arch-x86_64/syscalls/flistxattr.S
+++ b/libc/arch-x86_64/syscalls/flistxattr.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(flistxattr)
diff --git a/libc/arch-x86_64/syscalls/flock.S b/libc/arch-x86_64/syscalls/flock.S
index af2dbef..1bc6678 100644
--- a/libc/arch-x86_64/syscalls/flock.S
+++ b/libc/arch-x86_64/syscalls/flock.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(flock)
diff --git a/libc/arch-x86_64/syscalls/fremovexattr.S b/libc/arch-x86_64/syscalls/fremovexattr.S
index 4387563..517094c 100644
--- a/libc/arch-x86_64/syscalls/fremovexattr.S
+++ b/libc/arch-x86_64/syscalls/fremovexattr.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fremovexattr)
diff --git a/libc/arch-x86_64/syscalls/fsetxattr.S b/libc/arch-x86_64/syscalls/fsetxattr.S
index 610890c..97822c4 100644
--- a/libc/arch-x86_64/syscalls/fsetxattr.S
+++ b/libc/arch-x86_64/syscalls/fsetxattr.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fsetxattr)
diff --git a/libc/arch-x86_64/syscalls/fstat.S b/libc/arch-x86_64/syscalls/fstat.S
deleted file mode 100644
index 35f487d..0000000
--- a/libc/arch-x86_64/syscalls/fstat.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstat)
-    movl    $__NR_fstat, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(fstat)
diff --git a/libc/arch-x86_64/syscalls/fstat64.S b/libc/arch-x86_64/syscalls/fstat64.S
new file mode 100644
index 0000000..de57668
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/fstat64.S
@@ -0,0 +1,18 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstat64)
+    movl    $__NR_fstat, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(fstat64)
+
+    .globl fstat
+    .equ fstat, fstat64
diff --git a/libc/arch-x86_64/syscalls/fstatat.S b/libc/arch-x86_64/syscalls/fstatat.S
deleted file mode 100644
index c5d79bd..0000000
--- a/libc/arch-x86_64/syscalls/fstatat.S
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstatat)
-    movq    %rcx, %r10
-    movl    $__NR_newfstatat, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(fstatat)
diff --git a/libc/arch-x86_64/syscalls/fstatat64.S b/libc/arch-x86_64/syscalls/fstatat64.S
new file mode 100644
index 0000000..47785bb
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/fstatat64.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatat64)
+    movq    %rcx, %r10
+    movl    $__NR_newfstatat, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(fstatat64)
+
+    .globl fstatat
+    .equ fstatat, fstatat64
diff --git a/libc/arch-x86_64/syscalls/fstatfs.S b/libc/arch-x86_64/syscalls/fstatfs.S
deleted file mode 100644
index 59a90fb..0000000
--- a/libc/arch-x86_64/syscalls/fstatfs.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(fstatfs)
-    movl    $__NR_fstatfs, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(fstatfs)
diff --git a/libc/arch-x86_64/syscalls/fstatfs64.S b/libc/arch-x86_64/syscalls/fstatfs64.S
new file mode 100644
index 0000000..f727350
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/fstatfs64.S
@@ -0,0 +1,18 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(fstatfs64)
+    movl    $__NR_fstatfs, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(fstatfs64)
+
+    .globl fstatfs
+    .equ fstatfs, fstatfs64
diff --git a/libc/arch-x86_64/syscalls/fsync.S b/libc/arch-x86_64/syscalls/fsync.S
index 0392620..e7ec6da 100644
--- a/libc/arch-x86_64/syscalls/fsync.S
+++ b/libc/arch-x86_64/syscalls/fsync.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(fsync)
diff --git a/libc/arch-x86_64/syscalls/ftruncate.S b/libc/arch-x86_64/syscalls/ftruncate.S
index 80cbe79..0365368 100644
--- a/libc/arch-x86_64/syscalls/ftruncate.S
+++ b/libc/arch-x86_64/syscalls/ftruncate.S
@@ -9,11 +9,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(ftruncate)
 
-    .globl _C_LABEL(ftruncate64)
-    .equ _C_LABEL(ftruncate64), _C_LABEL(ftruncate)
+    .globl ftruncate64
+    .equ ftruncate64, ftruncate
diff --git a/libc/arch-x86_64/syscalls/futex.S b/libc/arch-x86_64/syscalls/futex.S
deleted file mode 100644
index 62f64bd..0000000
--- a/libc/arch-x86_64/syscalls/futex.S
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(futex)
-    movq    %rcx, %r10
-    movl    $__NR_futex, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(futex)
diff --git a/libc/arch-x86_64/syscalls/getdents.S b/libc/arch-x86_64/syscalls/getdents.S
deleted file mode 100644
index a47c26b..0000000
--- a/libc/arch-x86_64/syscalls/getdents.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getdents)
-    movl    $__NR_getdents64, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(getdents)
diff --git a/libc/arch-x86_64/syscalls/getegid.S b/libc/arch-x86_64/syscalls/getegid.S
index c1b8fae..84ba240 100644
--- a/libc/arch-x86_64/syscalls/getegid.S
+++ b/libc/arch-x86_64/syscalls/getegid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getegid)
diff --git a/libc/arch-x86_64/syscalls/geteuid.S b/libc/arch-x86_64/syscalls/geteuid.S
index f2f1035..18a991a 100644
--- a/libc/arch-x86_64/syscalls/geteuid.S
+++ b/libc/arch-x86_64/syscalls/geteuid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(geteuid)
diff --git a/libc/arch-x86_64/syscalls/getgid.S b/libc/arch-x86_64/syscalls/getgid.S
index e9b38c7..5e4b0ef 100644
--- a/libc/arch-x86_64/syscalls/getgid.S
+++ b/libc/arch-x86_64/syscalls/getgid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getgid)
diff --git a/libc/arch-x86_64/syscalls/getgroups.S b/libc/arch-x86_64/syscalls/getgroups.S
index b12836e..b5dd81c 100644
--- a/libc/arch-x86_64/syscalls/getgroups.S
+++ b/libc/arch-x86_64/syscalls/getgroups.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getgroups)
diff --git a/libc/arch-x86_64/syscalls/getitimer.S b/libc/arch-x86_64/syscalls/getitimer.S
index 79484d1..c4bb120 100644
--- a/libc/arch-x86_64/syscalls/getitimer.S
+++ b/libc/arch-x86_64/syscalls/getitimer.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getitimer)
diff --git a/libc/arch-x86_64/syscalls/getpeername.S b/libc/arch-x86_64/syscalls/getpeername.S
index a276cac..0b212be 100644
--- a/libc/arch-x86_64/syscalls/getpeername.S
+++ b/libc/arch-x86_64/syscalls/getpeername.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getpeername)
diff --git a/libc/arch-x86_64/syscalls/getpgid.S b/libc/arch-x86_64/syscalls/getpgid.S
index c2f5c09..d1b0e8b 100644
--- a/libc/arch-x86_64/syscalls/getpgid.S
+++ b/libc/arch-x86_64/syscalls/getpgid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getpgid)
diff --git a/libc/arch-x86_64/syscalls/getpid.S b/libc/arch-x86_64/syscalls/getpid.S
deleted file mode 100644
index 65b8df4..0000000
--- a/libc/arch-x86_64/syscalls/getpid.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(getpid)
-    movl    $__NR_getpid, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(getpid)
diff --git a/libc/arch-x86_64/syscalls/getppid.S b/libc/arch-x86_64/syscalls/getppid.S
index ce3dbda..e1cfee0 100644
--- a/libc/arch-x86_64/syscalls/getppid.S
+++ b/libc/arch-x86_64/syscalls/getppid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getppid)
diff --git a/libc/arch-x86_64/syscalls/getresgid.S b/libc/arch-x86_64/syscalls/getresgid.S
index 0edc20a..0b7ea7a 100644
--- a/libc/arch-x86_64/syscalls/getresgid.S
+++ b/libc/arch-x86_64/syscalls/getresgid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getresgid)
diff --git a/libc/arch-x86_64/syscalls/getresuid.S b/libc/arch-x86_64/syscalls/getresuid.S
index b900c99..0d7a054 100644
--- a/libc/arch-x86_64/syscalls/getresuid.S
+++ b/libc/arch-x86_64/syscalls/getresuid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getresuid)
diff --git a/libc/arch-x86_64/syscalls/getrlimit.S b/libc/arch-x86_64/syscalls/getrlimit.S
index 0b3536c..2d272a1 100644
--- a/libc/arch-x86_64/syscalls/getrlimit.S
+++ b/libc/arch-x86_64/syscalls/getrlimit.S
@@ -9,11 +9,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getrlimit)
 
-    .globl _C_LABEL(getrlimit64)
-    .equ _C_LABEL(getrlimit64), _C_LABEL(getrlimit)
+    .globl getrlimit64
+    .equ getrlimit64, getrlimit
diff --git a/libc/arch-x86_64/syscalls/getrusage.S b/libc/arch-x86_64/syscalls/getrusage.S
index 210d586..eef7fb8 100644
--- a/libc/arch-x86_64/syscalls/getrusage.S
+++ b/libc/arch-x86_64/syscalls/getrusage.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getrusage)
diff --git a/libc/arch-x86_64/syscalls/getsid.S b/libc/arch-x86_64/syscalls/getsid.S
index de3e3c0..022f959 100644
--- a/libc/arch-x86_64/syscalls/getsid.S
+++ b/libc/arch-x86_64/syscalls/getsid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getsid)
diff --git a/libc/arch-x86_64/syscalls/getsockname.S b/libc/arch-x86_64/syscalls/getsockname.S
index ccabf71..36fdcf7 100644
--- a/libc/arch-x86_64/syscalls/getsockname.S
+++ b/libc/arch-x86_64/syscalls/getsockname.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getsockname)
diff --git a/libc/arch-x86_64/syscalls/getsockopt.S b/libc/arch-x86_64/syscalls/getsockopt.S
index c4f456e..c1e11e7 100644
--- a/libc/arch-x86_64/syscalls/getsockopt.S
+++ b/libc/arch-x86_64/syscalls/getsockopt.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getsockopt)
diff --git a/libc/arch-x86_64/syscalls/gettid.S b/libc/arch-x86_64/syscalls/gettid.S
deleted file mode 100644
index 65ecc16..0000000
--- a/libc/arch-x86_64/syscalls/gettid.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(gettid)
-    movl    $__NR_gettid, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(gettid)
diff --git a/libc/arch-x86_64/syscalls/gettimeofday.S b/libc/arch-x86_64/syscalls/gettimeofday.S
deleted file mode 100644
index 261bb6e..0000000
--- a/libc/arch-x86_64/syscalls/gettimeofday.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(gettimeofday)
-    movl    $__NR_gettimeofday, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(gettimeofday)
diff --git a/libc/arch-x86_64/syscalls/getuid.S b/libc/arch-x86_64/syscalls/getuid.S
index 4cb9efd..93cd0f8 100644
--- a/libc/arch-x86_64/syscalls/getuid.S
+++ b/libc/arch-x86_64/syscalls/getuid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getuid)
diff --git a/libc/arch-x86_64/syscalls/getxattr.S b/libc/arch-x86_64/syscalls/getxattr.S
index 6bdb762..01378b0 100644
--- a/libc/arch-x86_64/syscalls/getxattr.S
+++ b/libc/arch-x86_64/syscalls/getxattr.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(getxattr)
diff --git a/libc/arch-x86_64/syscalls/init_module.S b/libc/arch-x86_64/syscalls/init_module.S
index eb048c0..c005de4 100644
--- a/libc/arch-x86_64/syscalls/init_module.S
+++ b/libc/arch-x86_64/syscalls/init_module.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(init_module)
diff --git a/libc/arch-x86_64/syscalls/inotify_add_watch.S b/libc/arch-x86_64/syscalls/inotify_add_watch.S
index 3e124e7..edf2930 100644
--- a/libc/arch-x86_64/syscalls/inotify_add_watch.S
+++ b/libc/arch-x86_64/syscalls/inotify_add_watch.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(inotify_add_watch)
diff --git a/libc/arch-x86_64/syscalls/inotify_init1.S b/libc/arch-x86_64/syscalls/inotify_init1.S
index 8d82115..b158018 100644
--- a/libc/arch-x86_64/syscalls/inotify_init1.S
+++ b/libc/arch-x86_64/syscalls/inotify_init1.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(inotify_init1)
diff --git a/libc/arch-x86_64/syscalls/inotify_rm_watch.S b/libc/arch-x86_64/syscalls/inotify_rm_watch.S
index ece1510..f2fc10e 100644
--- a/libc/arch-x86_64/syscalls/inotify_rm_watch.S
+++ b/libc/arch-x86_64/syscalls/inotify_rm_watch.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(inotify_rm_watch)
diff --git a/libc/arch-x86_64/syscalls/ioprio_get.S b/libc/arch-x86_64/syscalls/ioprio_get.S
deleted file mode 100644
index 48c1402..0000000
--- a/libc/arch-x86_64/syscalls/ioprio_get.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_get)
-    movl    $__NR_ioprio_get, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(ioprio_get)
diff --git a/libc/arch-x86_64/syscalls/ioprio_set.S b/libc/arch-x86_64/syscalls/ioprio_set.S
deleted file mode 100644
index 4cdc8b3..0000000
--- a/libc/arch-x86_64/syscalls/ioprio_set.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(ioprio_set)
-    movl    $__NR_ioprio_set, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(ioprio_set)
diff --git a/libc/arch-x86_64/syscalls/kill.S b/libc/arch-x86_64/syscalls/kill.S
index 51ca35c..fe93f34 100644
--- a/libc/arch-x86_64/syscalls/kill.S
+++ b/libc/arch-x86_64/syscalls/kill.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(kill)
diff --git a/libc/arch-x86_64/syscalls/klogctl.S b/libc/arch-x86_64/syscalls/klogctl.S
index 8c0ccce..fb2aca3 100644
--- a/libc/arch-x86_64/syscalls/klogctl.S
+++ b/libc/arch-x86_64/syscalls/klogctl.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(klogctl)
diff --git a/libc/arch-x86_64/syscalls/lgetxattr.S b/libc/arch-x86_64/syscalls/lgetxattr.S
index 6f195ea..36202a2 100644
--- a/libc/arch-x86_64/syscalls/lgetxattr.S
+++ b/libc/arch-x86_64/syscalls/lgetxattr.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(lgetxattr)
diff --git a/libc/arch-x86_64/syscalls/linkat.S b/libc/arch-x86_64/syscalls/linkat.S
index b9a2b14..d195e19 100644
--- a/libc/arch-x86_64/syscalls/linkat.S
+++ b/libc/arch-x86_64/syscalls/linkat.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(linkat)
diff --git a/libc/arch-x86_64/syscalls/listen.S b/libc/arch-x86_64/syscalls/listen.S
index 104b514..756b629 100644
--- a/libc/arch-x86_64/syscalls/listen.S
+++ b/libc/arch-x86_64/syscalls/listen.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(listen)
diff --git a/libc/arch-x86_64/syscalls/listxattr.S b/libc/arch-x86_64/syscalls/listxattr.S
index fe57e39..d0b2112 100644
--- a/libc/arch-x86_64/syscalls/listxattr.S
+++ b/libc/arch-x86_64/syscalls/listxattr.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(listxattr)
diff --git a/libc/arch-x86_64/syscalls/llistxattr.S b/libc/arch-x86_64/syscalls/llistxattr.S
index aa0a54d..49fb969 100644
--- a/libc/arch-x86_64/syscalls/llistxattr.S
+++ b/libc/arch-x86_64/syscalls/llistxattr.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(llistxattr)
diff --git a/libc/arch-x86_64/syscalls/lremovexattr.S b/libc/arch-x86_64/syscalls/lremovexattr.S
index 4b5ee65..1e1bc30 100644
--- a/libc/arch-x86_64/syscalls/lremovexattr.S
+++ b/libc/arch-x86_64/syscalls/lremovexattr.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(lremovexattr)
diff --git a/libc/arch-x86_64/syscalls/lseek.S b/libc/arch-x86_64/syscalls/lseek.S
index a06b3ec..153b935 100644
--- a/libc/arch-x86_64/syscalls/lseek.S
+++ b/libc/arch-x86_64/syscalls/lseek.S
@@ -9,11 +9,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(lseek)
 
-    .globl _C_LABEL(lseek64)
-    .equ _C_LABEL(lseek64), _C_LABEL(lseek)
+    .globl lseek64
+    .equ lseek64, lseek
diff --git a/libc/arch-x86_64/syscalls/lsetxattr.S b/libc/arch-x86_64/syscalls/lsetxattr.S
index 67d93eb..965ee03 100644
--- a/libc/arch-x86_64/syscalls/lsetxattr.S
+++ b/libc/arch-x86_64/syscalls/lsetxattr.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(lsetxattr)
diff --git a/libc/arch-x86_64/syscalls/madvise.S b/libc/arch-x86_64/syscalls/madvise.S
index e4ef923..75d47f6 100644
--- a/libc/arch-x86_64/syscalls/madvise.S
+++ b/libc/arch-x86_64/syscalls/madvise.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(madvise)
diff --git a/libc/arch-x86_64/syscalls/mincore.S b/libc/arch-x86_64/syscalls/mincore.S
index d92755c..2d8a28a 100644
--- a/libc/arch-x86_64/syscalls/mincore.S
+++ b/libc/arch-x86_64/syscalls/mincore.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mincore)
diff --git a/libc/arch-x86_64/syscalls/mkdirat.S b/libc/arch-x86_64/syscalls/mkdirat.S
index 9e5dbd6..8a76013 100644
--- a/libc/arch-x86_64/syscalls/mkdirat.S
+++ b/libc/arch-x86_64/syscalls/mkdirat.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mkdirat)
diff --git a/libc/arch-x86_64/syscalls/mknodat.S b/libc/arch-x86_64/syscalls/mknodat.S
index 49aac35..a8859d4 100644
--- a/libc/arch-x86_64/syscalls/mknodat.S
+++ b/libc/arch-x86_64/syscalls/mknodat.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mknodat)
diff --git a/libc/arch-x86_64/syscalls/mlock.S b/libc/arch-x86_64/syscalls/mlock.S
index f0b0c6e..d34b3ae 100644
--- a/libc/arch-x86_64/syscalls/mlock.S
+++ b/libc/arch-x86_64/syscalls/mlock.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mlock)
diff --git a/libc/arch-x86_64/syscalls/mlockall.S b/libc/arch-x86_64/syscalls/mlockall.S
index 420cb03..31ccaa0 100644
--- a/libc/arch-x86_64/syscalls/mlockall.S
+++ b/libc/arch-x86_64/syscalls/mlockall.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mlockall)
diff --git a/libc/arch-x86_64/syscalls/mmap.S b/libc/arch-x86_64/syscalls/mmap.S
index d6f9687..8aa4780 100644
--- a/libc/arch-x86_64/syscalls/mmap.S
+++ b/libc/arch-x86_64/syscalls/mmap.S
@@ -10,11 +10,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mmap)
 
-    .globl _C_LABEL(mmap64)
-    .equ _C_LABEL(mmap64), _C_LABEL(mmap)
+    .globl mmap64
+    .equ mmap64, mmap
diff --git a/libc/arch-x86_64/syscalls/mount.S b/libc/arch-x86_64/syscalls/mount.S
index df488c3..dcbd473 100644
--- a/libc/arch-x86_64/syscalls/mount.S
+++ b/libc/arch-x86_64/syscalls/mount.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mount)
diff --git a/libc/arch-x86_64/syscalls/mprotect.S b/libc/arch-x86_64/syscalls/mprotect.S
index 9ef61b5..2ad4b25 100644
--- a/libc/arch-x86_64/syscalls/mprotect.S
+++ b/libc/arch-x86_64/syscalls/mprotect.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mprotect)
diff --git a/libc/arch-x86_64/syscalls/mremap.S b/libc/arch-x86_64/syscalls/mremap.S
index 55e24bf..a6042cb 100644
--- a/libc/arch-x86_64/syscalls/mremap.S
+++ b/libc/arch-x86_64/syscalls/mremap.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(mremap)
diff --git a/libc/arch-x86_64/syscalls/msync.S b/libc/arch-x86_64/syscalls/msync.S
index 40524e3..099dbbf 100644
--- a/libc/arch-x86_64/syscalls/msync.S
+++ b/libc/arch-x86_64/syscalls/msync.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(msync)
diff --git a/libc/arch-x86_64/syscalls/munlock.S b/libc/arch-x86_64/syscalls/munlock.S
index b508259..bb5940c 100644
--- a/libc/arch-x86_64/syscalls/munlock.S
+++ b/libc/arch-x86_64/syscalls/munlock.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(munlock)
diff --git a/libc/arch-x86_64/syscalls/munlockall.S b/libc/arch-x86_64/syscalls/munlockall.S
index 4314e2b..f9579df 100644
--- a/libc/arch-x86_64/syscalls/munlockall.S
+++ b/libc/arch-x86_64/syscalls/munlockall.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(munlockall)
diff --git a/libc/arch-x86_64/syscalls/munmap.S b/libc/arch-x86_64/syscalls/munmap.S
index 15d503c..d1c580e 100644
--- a/libc/arch-x86_64/syscalls/munmap.S
+++ b/libc/arch-x86_64/syscalls/munmap.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(munmap)
diff --git a/libc/arch-x86_64/syscalls/nanosleep.S b/libc/arch-x86_64/syscalls/nanosleep.S
index d303fcb..b19f7f5 100644
--- a/libc/arch-x86_64/syscalls/nanosleep.S
+++ b/libc/arch-x86_64/syscalls/nanosleep.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(nanosleep)
diff --git a/libc/arch-x86_64/syscalls/perf_event_open.S b/libc/arch-x86_64/syscalls/perf_event_open.S
deleted file mode 100644
index d9fc71e..0000000
--- a/libc/arch-x86_64/syscalls/perf_event_open.S
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(perf_event_open)
-    movq    %rcx, %r10
-    movl    $__NR_perf_event_open, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(perf_event_open)
diff --git a/libc/arch-x86_64/syscalls/personality.S b/libc/arch-x86_64/syscalls/personality.S
index 0379707..6937e4c 100644
--- a/libc/arch-x86_64/syscalls/personality.S
+++ b/libc/arch-x86_64/syscalls/personality.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(personality)
diff --git a/libc/arch-x86_64/syscalls/pipe2.S b/libc/arch-x86_64/syscalls/pipe2.S
index d0a6768..d488c87 100644
--- a/libc/arch-x86_64/syscalls/pipe2.S
+++ b/libc/arch-x86_64/syscalls/pipe2.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(pipe2)
diff --git a/libc/arch-x86_64/syscalls/prctl.S b/libc/arch-x86_64/syscalls/prctl.S
index f7f561b..4f3d2ae 100644
--- a/libc/arch-x86_64/syscalls/prctl.S
+++ b/libc/arch-x86_64/syscalls/prctl.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(prctl)
diff --git a/libc/arch-x86_64/syscalls/pread64.S b/libc/arch-x86_64/syscalls/pread64.S
index 58b3176..3aa56e5 100644
--- a/libc/arch-x86_64/syscalls/pread64.S
+++ b/libc/arch-x86_64/syscalls/pread64.S
@@ -10,11 +10,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(pread64)
 
-    .globl _C_LABEL(pread)
-    .equ _C_LABEL(pread), _C_LABEL(pread64)
+    .globl pread
+    .equ pread, pread64
diff --git a/libc/arch-x86_64/syscalls/prlimit64.S b/libc/arch-x86_64/syscalls/prlimit64.S
index b451e8f..63ec492 100644
--- a/libc/arch-x86_64/syscalls/prlimit64.S
+++ b/libc/arch-x86_64/syscalls/prlimit64.S
@@ -10,11 +10,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(prlimit64)
 
-    .globl _C_LABEL(prlimit)
-    .equ _C_LABEL(prlimit), _C_LABEL(prlimit64)
+    .globl prlimit
+    .equ prlimit, prlimit64
diff --git a/libc/arch-x86_64/syscalls/pwrite64.S b/libc/arch-x86_64/syscalls/pwrite64.S
index 96215ce..2779fb4 100644
--- a/libc/arch-x86_64/syscalls/pwrite64.S
+++ b/libc/arch-x86_64/syscalls/pwrite64.S
@@ -10,11 +10,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(pwrite64)
 
-    .globl _C_LABEL(pwrite)
-    .equ _C_LABEL(pwrite), _C_LABEL(pwrite64)
+    .globl pwrite
+    .equ pwrite, pwrite64
diff --git a/libc/arch-x86_64/syscalls/read.S b/libc/arch-x86_64/syscalls/read.S
index 0ff6c2a..df70e7f 100644
--- a/libc/arch-x86_64/syscalls/read.S
+++ b/libc/arch-x86_64/syscalls/read.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(read)
diff --git a/libc/arch-x86_64/syscalls/readahead.S b/libc/arch-x86_64/syscalls/readahead.S
index a32c1c2..38cb1c0 100644
--- a/libc/arch-x86_64/syscalls/readahead.S
+++ b/libc/arch-x86_64/syscalls/readahead.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(readahead)
diff --git a/libc/arch-x86_64/syscalls/readlinkat.S b/libc/arch-x86_64/syscalls/readlinkat.S
index a1c3ade..9fd64e5 100644
--- a/libc/arch-x86_64/syscalls/readlinkat.S
+++ b/libc/arch-x86_64/syscalls/readlinkat.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(readlinkat)
diff --git a/libc/arch-x86_64/syscalls/readv.S b/libc/arch-x86_64/syscalls/readv.S
index a6f51cf..2510c56 100644
--- a/libc/arch-x86_64/syscalls/readv.S
+++ b/libc/arch-x86_64/syscalls/readv.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(readv)
diff --git a/libc/arch-x86_64/syscalls/recvfrom.S b/libc/arch-x86_64/syscalls/recvfrom.S
index feb3a63..6c09078 100644
--- a/libc/arch-x86_64/syscalls/recvfrom.S
+++ b/libc/arch-x86_64/syscalls/recvfrom.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(recvfrom)
diff --git a/libc/arch-x86_64/syscalls/recvmmsg.S b/libc/arch-x86_64/syscalls/recvmmsg.S
new file mode 100644
index 0000000..78da691
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/recvmmsg.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(recvmmsg)
+    movq    %rcx, %r10
+    movl    $__NR_recvmmsg, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(recvmmsg)
diff --git a/libc/arch-x86_64/syscalls/recvmsg.S b/libc/arch-x86_64/syscalls/recvmsg.S
index 6716aca..945f17b 100644
--- a/libc/arch-x86_64/syscalls/recvmsg.S
+++ b/libc/arch-x86_64/syscalls/recvmsg.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(recvmsg)
diff --git a/libc/arch-x86_64/syscalls/removexattr.S b/libc/arch-x86_64/syscalls/removexattr.S
index 89b2c4f..9b47615 100644
--- a/libc/arch-x86_64/syscalls/removexattr.S
+++ b/libc/arch-x86_64/syscalls/removexattr.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(removexattr)
diff --git a/libc/arch-x86_64/syscalls/renameat.S b/libc/arch-x86_64/syscalls/renameat.S
index 9d69c3e..3a94a75 100644
--- a/libc/arch-x86_64/syscalls/renameat.S
+++ b/libc/arch-x86_64/syscalls/renameat.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(renameat)
diff --git a/libc/arch-x86_64/syscalls/sched_get_priority_max.S b/libc/arch-x86_64/syscalls/sched_get_priority_max.S
index 41b2d1d..1a0da23 100644
--- a/libc/arch-x86_64/syscalls/sched_get_priority_max.S
+++ b/libc/arch-x86_64/syscalls/sched_get_priority_max.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_get_priority_max)
diff --git a/libc/arch-x86_64/syscalls/sched_get_priority_min.S b/libc/arch-x86_64/syscalls/sched_get_priority_min.S
index 61b746f..3785877 100644
--- a/libc/arch-x86_64/syscalls/sched_get_priority_min.S
+++ b/libc/arch-x86_64/syscalls/sched_get_priority_min.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_get_priority_min)
diff --git a/libc/arch-x86_64/syscalls/sched_getparam.S b/libc/arch-x86_64/syscalls/sched_getparam.S
index 23d34b2..409b501 100644
--- a/libc/arch-x86_64/syscalls/sched_getparam.S
+++ b/libc/arch-x86_64/syscalls/sched_getparam.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_getparam)
diff --git a/libc/arch-x86_64/syscalls/sched_getscheduler.S b/libc/arch-x86_64/syscalls/sched_getscheduler.S
index 12f0ba0..5200504 100644
--- a/libc/arch-x86_64/syscalls/sched_getscheduler.S
+++ b/libc/arch-x86_64/syscalls/sched_getscheduler.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_getscheduler)
diff --git a/libc/arch-x86_64/syscalls/sched_rr_get_interval.S b/libc/arch-x86_64/syscalls/sched_rr_get_interval.S
index 0ff852f..276feb1 100644
--- a/libc/arch-x86_64/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-x86_64/syscalls/sched_rr_get_interval.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_rr_get_interval)
diff --git a/libc/arch-x86_64/syscalls/sched_setaffinity.S b/libc/arch-x86_64/syscalls/sched_setaffinity.S
index 250ecb6..1fb87e5 100644
--- a/libc/arch-x86_64/syscalls/sched_setaffinity.S
+++ b/libc/arch-x86_64/syscalls/sched_setaffinity.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_setaffinity)
diff --git a/libc/arch-x86_64/syscalls/sched_setparam.S b/libc/arch-x86_64/syscalls/sched_setparam.S
index 30a7963..91ca83b 100644
--- a/libc/arch-x86_64/syscalls/sched_setparam.S
+++ b/libc/arch-x86_64/syscalls/sched_setparam.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_setparam)
diff --git a/libc/arch-x86_64/syscalls/sched_setscheduler.S b/libc/arch-x86_64/syscalls/sched_setscheduler.S
index 137f9f0..7fa499a 100644
--- a/libc/arch-x86_64/syscalls/sched_setscheduler.S
+++ b/libc/arch-x86_64/syscalls/sched_setscheduler.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_setscheduler)
diff --git a/libc/arch-x86_64/syscalls/sched_yield.S b/libc/arch-x86_64/syscalls/sched_yield.S
index 097c7dc..8eb10f6 100644
--- a/libc/arch-x86_64/syscalls/sched_yield.S
+++ b/libc/arch-x86_64/syscalls/sched_yield.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sched_yield)
diff --git a/libc/arch-x86_64/syscalls/sendfile.S b/libc/arch-x86_64/syscalls/sendfile.S
index b56f487..117b0aa 100644
--- a/libc/arch-x86_64/syscalls/sendfile.S
+++ b/libc/arch-x86_64/syscalls/sendfile.S
@@ -10,11 +10,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sendfile)
 
-    .globl _C_LABEL(sendfile64)
-    .equ _C_LABEL(sendfile64), _C_LABEL(sendfile)
+    .globl sendfile64
+    .equ sendfile64, sendfile
diff --git a/libc/arch-x86_64/syscalls/sendmmsg.S b/libc/arch-x86_64/syscalls/sendmmsg.S
new file mode 100644
index 0000000..cf4a78d
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/sendmmsg.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(sendmmsg)
+    movq    %rcx, %r10
+    movl    $__NR_sendmmsg, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(sendmmsg)
diff --git a/libc/arch-x86_64/syscalls/sendmsg.S b/libc/arch-x86_64/syscalls/sendmsg.S
index e56e58c..84566b5 100644
--- a/libc/arch-x86_64/syscalls/sendmsg.S
+++ b/libc/arch-x86_64/syscalls/sendmsg.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sendmsg)
diff --git a/libc/arch-x86_64/syscalls/sendto.S b/libc/arch-x86_64/syscalls/sendto.S
index f0c14b0..be3bace 100644
--- a/libc/arch-x86_64/syscalls/sendto.S
+++ b/libc/arch-x86_64/syscalls/sendto.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sendto)
diff --git a/libc/arch-x86_64/syscalls/setfsgid.S b/libc/arch-x86_64/syscalls/setfsgid.S
new file mode 100644
index 0000000..22a36b2
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/setfsgid.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsgid)
+    movl    $__NR_setfsgid, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(setfsgid)
diff --git a/libc/arch-x86_64/syscalls/setfsuid.S b/libc/arch-x86_64/syscalls/setfsuid.S
new file mode 100644
index 0000000..0bd0c97
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/setfsuid.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setfsuid)
+    movl    $__NR_setfsuid, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(setfsuid)
diff --git a/libc/arch-x86_64/syscalls/setgid.S b/libc/arch-x86_64/syscalls/setgid.S
index abaf343..650f8e2 100644
--- a/libc/arch-x86_64/syscalls/setgid.S
+++ b/libc/arch-x86_64/syscalls/setgid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setgid)
diff --git a/libc/arch-x86_64/syscalls/setgroups.S b/libc/arch-x86_64/syscalls/setgroups.S
index 4bbc7ec..c798c14 100644
--- a/libc/arch-x86_64/syscalls/setgroups.S
+++ b/libc/arch-x86_64/syscalls/setgroups.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setgroups)
diff --git a/libc/arch-x86_64/syscalls/setitimer.S b/libc/arch-x86_64/syscalls/setitimer.S
index da81d0b..c5fabb2 100644
--- a/libc/arch-x86_64/syscalls/setitimer.S
+++ b/libc/arch-x86_64/syscalls/setitimer.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setitimer)
diff --git a/libc/arch-x86_64/syscalls/setns.S b/libc/arch-x86_64/syscalls/setns.S
index bab147b..c2ae97d 100644
--- a/libc/arch-x86_64/syscalls/setns.S
+++ b/libc/arch-x86_64/syscalls/setns.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setns)
diff --git a/libc/arch-x86_64/syscalls/setpgid.S b/libc/arch-x86_64/syscalls/setpgid.S
index 6dfefa3..4d4313c 100644
--- a/libc/arch-x86_64/syscalls/setpgid.S
+++ b/libc/arch-x86_64/syscalls/setpgid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setpgid)
diff --git a/libc/arch-x86_64/syscalls/setpriority.S b/libc/arch-x86_64/syscalls/setpriority.S
index 89770e9..3c508c3 100644
--- a/libc/arch-x86_64/syscalls/setpriority.S
+++ b/libc/arch-x86_64/syscalls/setpriority.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setpriority)
diff --git a/libc/arch-x86_64/syscalls/setregid.S b/libc/arch-x86_64/syscalls/setregid.S
index 9eaa7e9..181a8b9 100644
--- a/libc/arch-x86_64/syscalls/setregid.S
+++ b/libc/arch-x86_64/syscalls/setregid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setregid)
diff --git a/libc/arch-x86_64/syscalls/setresgid.S b/libc/arch-x86_64/syscalls/setresgid.S
index 95206b3..fe44786 100644
--- a/libc/arch-x86_64/syscalls/setresgid.S
+++ b/libc/arch-x86_64/syscalls/setresgid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setresgid)
diff --git a/libc/arch-x86_64/syscalls/setresuid.S b/libc/arch-x86_64/syscalls/setresuid.S
index c42dda9..58cd2ca 100644
--- a/libc/arch-x86_64/syscalls/setresuid.S
+++ b/libc/arch-x86_64/syscalls/setresuid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setresuid)
diff --git a/libc/arch-x86_64/syscalls/setreuid.S b/libc/arch-x86_64/syscalls/setreuid.S
index 935f751..e25658b 100644
--- a/libc/arch-x86_64/syscalls/setreuid.S
+++ b/libc/arch-x86_64/syscalls/setreuid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setreuid)
diff --git a/libc/arch-x86_64/syscalls/setrlimit.S b/libc/arch-x86_64/syscalls/setrlimit.S
index e445ec0..ef03068 100644
--- a/libc/arch-x86_64/syscalls/setrlimit.S
+++ b/libc/arch-x86_64/syscalls/setrlimit.S
@@ -9,11 +9,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setrlimit)
 
-    .globl _C_LABEL(setrlimit64)
-    .equ _C_LABEL(setrlimit64), _C_LABEL(setrlimit)
+    .globl setrlimit64
+    .equ setrlimit64, setrlimit
diff --git a/libc/arch-x86_64/syscalls/setsid.S b/libc/arch-x86_64/syscalls/setsid.S
index 9c50a89..01d9269 100644
--- a/libc/arch-x86_64/syscalls/setsid.S
+++ b/libc/arch-x86_64/syscalls/setsid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setsid)
diff --git a/libc/arch-x86_64/syscalls/setsockopt.S b/libc/arch-x86_64/syscalls/setsockopt.S
index 2332ec9..629fdf0 100644
--- a/libc/arch-x86_64/syscalls/setsockopt.S
+++ b/libc/arch-x86_64/syscalls/setsockopt.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setsockopt)
diff --git a/libc/arch-x86_64/syscalls/settimeofday.S b/libc/arch-x86_64/syscalls/settimeofday.S
index 121c0b6..ac5b9b1 100644
--- a/libc/arch-x86_64/syscalls/settimeofday.S
+++ b/libc/arch-x86_64/syscalls/settimeofday.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(settimeofday)
diff --git a/libc/arch-x86_64/syscalls/setuid.S b/libc/arch-x86_64/syscalls/setuid.S
index f426705..f335a76 100644
--- a/libc/arch-x86_64/syscalls/setuid.S
+++ b/libc/arch-x86_64/syscalls/setuid.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setuid)
diff --git a/libc/arch-x86_64/syscalls/setxattr.S b/libc/arch-x86_64/syscalls/setxattr.S
index c02aa84..d750423 100644
--- a/libc/arch-x86_64/syscalls/setxattr.S
+++ b/libc/arch-x86_64/syscalls/setxattr.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(setxattr)
diff --git a/libc/arch-x86_64/syscalls/shutdown.S b/libc/arch-x86_64/syscalls/shutdown.S
index 96a65f8..a030c97 100644
--- a/libc/arch-x86_64/syscalls/shutdown.S
+++ b/libc/arch-x86_64/syscalls/shutdown.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(shutdown)
diff --git a/libc/arch-x86_64/syscalls/sigaltstack.S b/libc/arch-x86_64/syscalls/sigaltstack.S
index 57dc41a..71ce537 100644
--- a/libc/arch-x86_64/syscalls/sigaltstack.S
+++ b/libc/arch-x86_64/syscalls/sigaltstack.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sigaltstack)
diff --git a/libc/arch-x86_64/syscalls/signalfd4.S b/libc/arch-x86_64/syscalls/signalfd4.S
deleted file mode 100644
index 4d8a1b6..0000000
--- a/libc/arch-x86_64/syscalls/signalfd4.S
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(signalfd4)
-    movq    %rcx, %r10
-    movl    $__NR_signalfd4, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(signalfd4)
diff --git a/libc/arch-x86_64/syscalls/socket.S b/libc/arch-x86_64/syscalls/socket.S
deleted file mode 100644
index 9665ee4..0000000
--- a/libc/arch-x86_64/syscalls/socket.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(socket)
-    movl    $__NR_socket, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(socket)
diff --git a/libc/arch-x86_64/syscalls/socketpair.S b/libc/arch-x86_64/syscalls/socketpair.S
index 4e76e83..dbcf50d 100644
--- a/libc/arch-x86_64/syscalls/socketpair.S
+++ b/libc/arch-x86_64/syscalls/socketpair.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(socketpair)
diff --git a/libc/arch-x86_64/syscalls/splice.S b/libc/arch-x86_64/syscalls/splice.S
new file mode 100644
index 0000000..1b2ec84
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/splice.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(splice)
+    movq    %rcx, %r10
+    movl    $__NR_splice, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(splice)
diff --git a/libc/arch-x86_64/syscalls/statfs.S b/libc/arch-x86_64/syscalls/statfs.S
deleted file mode 100644
index 8b4b2e5..0000000
--- a/libc/arch-x86_64/syscalls/statfs.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(statfs)
-    movl    $__NR_statfs, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(statfs)
diff --git a/libc/arch-x86_64/syscalls/statfs64.S b/libc/arch-x86_64/syscalls/statfs64.S
new file mode 100644
index 0000000..16f6bdd
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/statfs64.S
@@ -0,0 +1,18 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(statfs64)
+    movl    $__NR_statfs, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(statfs64)
+
+    .globl statfs
+    .equ statfs, statfs64
diff --git a/libc/arch-x86_64/syscalls/swapoff.S b/libc/arch-x86_64/syscalls/swapoff.S
index 2f2dafe..df922a0 100644
--- a/libc/arch-x86_64/syscalls/swapoff.S
+++ b/libc/arch-x86_64/syscalls/swapoff.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(swapoff)
diff --git a/libc/arch-x86_64/syscalls/swapon.S b/libc/arch-x86_64/syscalls/swapon.S
index 3db7921..036b422 100644
--- a/libc/arch-x86_64/syscalls/swapon.S
+++ b/libc/arch-x86_64/syscalls/swapon.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(swapon)
diff --git a/libc/arch-x86_64/syscalls/symlinkat.S b/libc/arch-x86_64/syscalls/symlinkat.S
index 54b4d4e..fdbced5 100644
--- a/libc/arch-x86_64/syscalls/symlinkat.S
+++ b/libc/arch-x86_64/syscalls/symlinkat.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(symlinkat)
diff --git a/libc/arch-x86_64/syscalls/sync.S b/libc/arch-x86_64/syscalls/sync.S
index f58c788..a4153fd 100644
--- a/libc/arch-x86_64/syscalls/sync.S
+++ b/libc/arch-x86_64/syscalls/sync.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sync)
diff --git a/libc/arch-x86_64/syscalls/sysinfo.S b/libc/arch-x86_64/syscalls/sysinfo.S
index d483693..754ef61 100644
--- a/libc/arch-x86_64/syscalls/sysinfo.S
+++ b/libc/arch-x86_64/syscalls/sysinfo.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(sysinfo)
diff --git a/libc/arch-x86_64/syscalls/tee.S b/libc/arch-x86_64/syscalls/tee.S
new file mode 100644
index 0000000..31d66dc
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/tee.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(tee)
+    movq    %rcx, %r10
+    movl    $__NR_tee, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(tee)
diff --git a/libc/arch-x86_64/syscalls/tgkill.S b/libc/arch-x86_64/syscalls/tgkill.S
index 7d217b0..9c46887 100644
--- a/libc/arch-x86_64/syscalls/tgkill.S
+++ b/libc/arch-x86_64/syscalls/tgkill.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(tgkill)
diff --git a/libc/arch-x86_64/syscalls/timerfd_create.S b/libc/arch-x86_64/syscalls/timerfd_create.S
index a518e4f..56b45e8 100644
--- a/libc/arch-x86_64/syscalls/timerfd_create.S
+++ b/libc/arch-x86_64/syscalls/timerfd_create.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(timerfd_create)
diff --git a/libc/arch-x86_64/syscalls/timerfd_gettime.S b/libc/arch-x86_64/syscalls/timerfd_gettime.S
index 1d0853a..8c9b5d6 100644
--- a/libc/arch-x86_64/syscalls/timerfd_gettime.S
+++ b/libc/arch-x86_64/syscalls/timerfd_gettime.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(timerfd_gettime)
diff --git a/libc/arch-x86_64/syscalls/timerfd_settime.S b/libc/arch-x86_64/syscalls/timerfd_settime.S
index a23af4e..a524c0c 100644
--- a/libc/arch-x86_64/syscalls/timerfd_settime.S
+++ b/libc/arch-x86_64/syscalls/timerfd_settime.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(timerfd_settime)
diff --git a/libc/arch-x86_64/syscalls/times.S b/libc/arch-x86_64/syscalls/times.S
index 520d062..89502bd 100644
--- a/libc/arch-x86_64/syscalls/times.S
+++ b/libc/arch-x86_64/syscalls/times.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(times)
diff --git a/libc/arch-x86_64/syscalls/tkill.S b/libc/arch-x86_64/syscalls/tkill.S
deleted file mode 100644
index d8529ef..0000000
--- a/libc/arch-x86_64/syscalls/tkill.S
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(tkill)
-    movl    $__NR_tkill, %eax
-    syscall
-    cmpq    $-MAX_ERRNO, %rax
-    jb      1f
-    negl    %eax
-    movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
-1:
-    ret
-END(tkill)
diff --git a/libc/arch-x86_64/syscalls/truncate.S b/libc/arch-x86_64/syscalls/truncate.S
index 5e5eb8e..2ecd05b 100644
--- a/libc/arch-x86_64/syscalls/truncate.S
+++ b/libc/arch-x86_64/syscalls/truncate.S
@@ -9,11 +9,10 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(truncate)
 
-    .globl _C_LABEL(truncate64)
-    .equ _C_LABEL(truncate64), _C_LABEL(truncate)
+    .globl truncate64
+    .equ truncate64, truncate
diff --git a/libc/arch-x86_64/syscalls/umask.S b/libc/arch-x86_64/syscalls/umask.S
index 360ad71..acd37e8 100644
--- a/libc/arch-x86_64/syscalls/umask.S
+++ b/libc/arch-x86_64/syscalls/umask.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(umask)
diff --git a/libc/arch-x86_64/syscalls/umount2.S b/libc/arch-x86_64/syscalls/umount2.S
index e2de44b..438aedb 100644
--- a/libc/arch-x86_64/syscalls/umount2.S
+++ b/libc/arch-x86_64/syscalls/umount2.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(umount2)
diff --git a/libc/arch-x86_64/syscalls/uname.S b/libc/arch-x86_64/syscalls/uname.S
index 8ad40fa..6f077df 100644
--- a/libc/arch-x86_64/syscalls/uname.S
+++ b/libc/arch-x86_64/syscalls/uname.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(uname)
diff --git a/libc/arch-x86_64/syscalls/unlinkat.S b/libc/arch-x86_64/syscalls/unlinkat.S
index 83bb59f..80f0251 100644
--- a/libc/arch-x86_64/syscalls/unlinkat.S
+++ b/libc/arch-x86_64/syscalls/unlinkat.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(unlinkat)
diff --git a/libc/arch-x86_64/syscalls/unshare.S b/libc/arch-x86_64/syscalls/unshare.S
index 044af99..8316d20 100644
--- a/libc/arch-x86_64/syscalls/unshare.S
+++ b/libc/arch-x86_64/syscalls/unshare.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(unshare)
diff --git a/libc/arch-x86_64/syscalls/utimensat.S b/libc/arch-x86_64/syscalls/utimensat.S
index 4d263ff..3e43826 100644
--- a/libc/arch-x86_64/syscalls/utimensat.S
+++ b/libc/arch-x86_64/syscalls/utimensat.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(utimensat)
diff --git a/libc/arch-x86_64/syscalls/vmsplice.S b/libc/arch-x86_64/syscalls/vmsplice.S
new file mode 100644
index 0000000..df775c6
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/vmsplice.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(vmsplice)
+    movq    %rcx, %r10
+    movl    $__NR_vmsplice, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(vmsplice)
diff --git a/libc/arch-x86_64/syscalls/wait4.S b/libc/arch-x86_64/syscalls/wait4.S
index 7de78ac..d392dc7 100644
--- a/libc/arch-x86_64/syscalls/wait4.S
+++ b/libc/arch-x86_64/syscalls/wait4.S
@@ -10,8 +10,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(wait4)
diff --git a/libc/arch-x86_64/syscalls/write.S b/libc/arch-x86_64/syscalls/write.S
index eab3904..145c793 100644
--- a/libc/arch-x86_64/syscalls/write.S
+++ b/libc/arch-x86_64/syscalls/write.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(write)
diff --git a/libc/arch-x86_64/syscalls/writev.S b/libc/arch-x86_64/syscalls/writev.S
index b21e3d6..8f8956f 100644
--- a/libc/arch-x86_64/syscalls/writev.S
+++ b/libc/arch-x86_64/syscalls/writev.S
@@ -9,8 +9,7 @@
     jb      1f
     negl    %eax
     movl    %eax, %edi
-    call    __set_errno
-    orq     $-1, %rax
+    call    __set_errno_internal
 1:
     ret
 END(writev)
diff --git a/libc/arch-x86_64/x86_64.mk b/libc/arch-x86_64/x86_64.mk
index 2614537..b001b5e 100644
--- a/libc/arch-x86_64/x86_64.mk
+++ b/libc/arch-x86_64/x86_64.mk
@@ -1,8 +1,35 @@
-_LIBC_ARCH_COMMON_SRC_FILES := \
+# x86_64 specific configs
+
+libc_common_src_files_x86_64 := \
+    bionic/memchr.c \
+    bionic/memrchr.c \
+    bionic/strchr.cpp \
+    bionic/strnlen.c \
+    bionic/strrchr.cpp \
+    upstream-freebsd/lib/libc/string/wcscat.c \
+    upstream-freebsd/lib/libc/string/wcschr.c \
+    upstream-freebsd/lib/libc/string/wcscmp.c \
+    upstream-freebsd/lib/libc/string/wcscpy.c \
+    upstream-freebsd/lib/libc/string/wcslen.c \
+    upstream-freebsd/lib/libc/string/wcsrchr.c \
+    upstream-freebsd/lib/libc/string/wmemcmp.c \
+    upstream-freebsd/lib/libc/string/wmemmove.c \
+    upstream-openbsd/lib/libc/string/strlcat.c \
+    upstream-openbsd/lib/libc/string/strlcpy.c \
+
+# Fortify implementations of libc functions.
+libc_common_src_files_x86_64 += \
+    bionic/__memcpy_chk.cpp \
+    bionic/__memset_chk.cpp \
+    bionic/__strcpy_chk.cpp \
+    bionic/__strcat_chk.cpp \
+
+
+##########################################
+### CPU specific source files
+libc_bionic_src_files_x86_64 := \
     arch-x86_64/bionic/__bionic_clone.S \
     arch-x86_64/bionic/_exit_with_stack_teardown.S \
-    arch-x86_64/bionic/futex_x86_64.S \
-    arch-x86_64/bionic/__get_sp.S \
     arch-x86_64/bionic/__rt_sigreturn.S \
     arch-x86_64/bionic/_setjmp.S \
     arch-x86_64/bionic/setjmp.S \
@@ -10,9 +37,33 @@
     arch-x86_64/bionic/sigsetjmp.S \
     arch-x86_64/bionic/syscall.S \
     arch-x86_64/bionic/vfork.S \
-    string/memcmp16.c \
 
-_LIBC_ARCH_STATIC_SRC_FILES := \
-    bionic/dl_iterate_phdr_static.c \
+libc_bionic_src_files_x86_64 += \
+    arch-x86_64/string/sse2-memcpy-slm.S \
+    arch-x86_64/string/sse2-memmove-slm.S \
+    arch-x86_64/string/sse2-memset-slm.S \
+    arch-x86_64/string/sse2-stpcpy-slm.S \
+    arch-x86_64/string/sse2-stpncpy-slm.S \
+    arch-x86_64/string/sse2-strcat-slm.S \
+    arch-x86_64/string/sse2-strcpy-slm.S \
+    arch-x86_64/string/sse2-strlen-slm.S \
+    arch-x86_64/string/sse2-strncat-slm.S \
+    arch-x86_64/string/sse2-strncpy-slm.S \
+    arch-x86_64/string/sse4-memcmp-slm.S \
+    arch-x86_64/string/ssse3-strcmp-slm.S \
+    arch-x86_64/string/ssse3-strncmp-slm.S \
 
-_LIBC_ARCH_DYNAMIC_SRC_FILES :=
+libc_crt_target_cflags_x86_64 += \
+    -m64 \
+    -I$(LOCAL_PATH)/arch-x86_64/include
+
+libc_crt_target_ldflags_x86_64 := -melf_x86_64
+
+libc_crt_target_crtbegin_file_x86_64 := \
+    $(LOCAL_PATH)/arch-common/bionic/crtbegin.c
+
+libc_crt_target_crtbegin_so_file_x86_64 := \
+    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
+
+libc_crt_target_so_cflags_x86_64 := \
+    -fPIC
diff --git a/libc/bionic/NetdClient.cpp b/libc/bionic/NetdClient.cpp
new file mode 100644
index 0000000..5b0f4fd
--- /dev/null
+++ b/libc/bionic/NetdClient.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef LIBC_STATIC
+#error NetdClient.cpp should NOT be included in static libc builds.
+#endif
+
+#include "private/libc_logging.h"
+#include "private/NetdClientDispatch.h"
+
+#include <dlfcn.h>
+#include <pthread.h>
+
+template <typename FunctionType>
+static void netdClientInitFunction(void* handle, const char* symbol, FunctionType* function) {
+    typedef void (*InitFunctionType)(FunctionType*);
+    InitFunctionType initFunction = reinterpret_cast<InitFunctionType>(dlsym(handle, symbol));
+    if (initFunction != NULL) {
+        initFunction(function);
+    }
+}
+
+static void netdClientInitImpl() {
+    void* netdClientHandle = dlopen("libnetd_client.so", RTLD_LAZY);
+    if (netdClientHandle == NULL) {
+        // If the library is not available, it's not an error. We'll just use
+        // default implementations of functions that it would've overridden.
+        return;
+    }
+    netdClientInitFunction(netdClientHandle, "netdClientInitAccept4",
+                           &__netdClientDispatch.accept4);
+    netdClientInitFunction(netdClientHandle, "netdClientInitConnect",
+                           &__netdClientDispatch.connect);
+    netdClientInitFunction(netdClientHandle, "netdClientInitNetIdForResolv",
+                           &__netdClientDispatch.netIdForResolv);
+    netdClientInitFunction(netdClientHandle, "netdClientInitSocket", &__netdClientDispatch.socket);
+}
+
+static pthread_once_t netdClientInitOnce = PTHREAD_ONCE_INIT;
+
+extern "C" __LIBC_HIDDEN__ void netdClientInit() {
+    if (pthread_once(&netdClientInitOnce, netdClientInitImpl)) {
+        __libc_format_log(ANDROID_LOG_ERROR, "netdClient", "Failed to initialize netd_client");
+    }
+}
diff --git a/libc/bionic/NetdClientDispatch.cpp b/libc/bionic/NetdClientDispatch.cpp
new file mode 100644
index 0000000..67fa197
--- /dev/null
+++ b/libc/bionic/NetdClientDispatch.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "private/NetdClientDispatch.h"
+
+#ifdef __i386__
+#define __socketcall __attribute__((__cdecl__))
+#else
+#define __socketcall
+#endif
+
+extern "C" __socketcall int __accept4(int, sockaddr*, socklen_t*, int);
+extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t);
+extern "C" __socketcall int __socket(int, int, int);
+
+static unsigned fallBackNetIdForResolv(unsigned netId) {
+    return netId;
+}
+
+// This structure is modified only at startup (when libc.so is loaded) and never
+// afterwards, so it's okay that it's read later at runtime without a lock.
+__LIBC_HIDDEN__ NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
+    __accept4,
+    __connect,
+    __socket,
+    fallBackNetIdForResolv,
+};
diff --git a/libc/bionic/__cmsg_nxthdr.cpp b/libc/bionic/__cmsg_nxthdr.cpp
new file mode 100644
index 0000000..f962788
--- /dev/null
+++ b/libc/bionic/__cmsg_nxthdr.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/socket.h>
+
+cmsghdr* __cmsg_nxthdr(msghdr* msg, cmsghdr* cmsg) {
+  cmsghdr* ptr;
+  ptr = reinterpret_cast<cmsghdr*>(reinterpret_cast<char*>(cmsg) + CMSG_ALIGN(cmsg->cmsg_len));
+  size_t len = reinterpret_cast<char*>(ptr+1) - reinterpret_cast<char*>(msg->msg_control);
+  if (len > msg->msg_controllen) {
+    return NULL;
+  }
+  return ptr;
+}
diff --git a/libc/bionic/__cxa_guard.cpp b/libc/bionic/__cxa_guard.cpp
new file mode 100644
index 0000000..5b0d57d
--- /dev/null
+++ b/libc/bionic/__cxa_guard.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stddef.h>
+#include <endian.h>
+
+#include "private/bionic_atomic_inline.h"
+#include "private/bionic_futex.h"
+
+// This file contains C++ ABI support functions for one time
+// constructors as defined in the "Run-time ABI for the ARM Architecture"
+// section 4.4.2
+//
+// ARM C++ ABI and Itanium/x86 C++ ABI has different definition for
+// one time construction:
+//
+//    ARM C++ ABI defines the LSB of guard variable should be tested
+//    by compiler-generated code before calling __cxa_guard_acquire et al.
+//
+//    The Itanium/x86 C++ ABI defines the low-order _byte_ should be
+//    tested instead.
+//
+//    Meanwhile, guard variable are 32bit aligned for ARM, and 64bit
+//    aligned for x86.
+//
+// Reference documentation:
+//
+//    section 3.2.3 of ARM IHI 0041C (for ARM)
+//    section 3.3.2 of the Itanium C++ ABI specification v1.83 (for x86).
+//
+// There is no C++ ABI available for other ARCH. But the gcc source
+// shows all other ARCH follow the definition of Itanium/x86 C++ ABI.
+
+#if defined(__arm__)
+// The ARM C++ ABI mandates that guard variables are 32-bit aligned, 32-bit
+// values. The LSB is tested by the compiler-generated code before calling
+// __cxa_guard_acquire.
+union _guard_t {
+    int volatile state;
+    int32_t aligner;
+};
+
+const static int ready = 0x1;
+const static int pending = 0x2;
+const static int waiting = 0x6;
+
+#else
+// The Itanium/x86 C++ ABI (used by all other architectures) mandates that
+// guard variables are 64-bit aligned, 64-bit values. The LSB is tested by
+// the compiler-generated code before calling __cxa_guard_acquire.
+union _guard_t {
+    int volatile state;
+    int64_t aligner;
+};
+
+const static int ready     = letoh32(0x1);
+const static int pending   = letoh32(0x100);
+const static int waiting   = letoh32(0x10000);
+#endif
+
+extern "C" int __cxa_guard_acquire(_guard_t* gv) {
+    // 0 -> pending, return 1
+    // pending -> waiting, wait and return 0
+    // waiting: untouched, wait and return 0
+    // ready: untouched, return 0
+
+retry:
+    if (__bionic_cmpxchg(0, pending, &gv->state) == 0) {
+        ANDROID_MEMBAR_FULL();
+        return 1;
+    }
+    __bionic_cmpxchg(pending, waiting, &gv->state); // Indicate there is a waiter
+    __futex_wait(&gv->state, waiting, NULL);
+
+    if (gv->state != ready) {
+        // __cxa_guard_abort was called, let every thread try since there is no return code for this condition
+        goto retry;
+    }
+
+    ANDROID_MEMBAR_FULL();
+    return 0;
+}
+
+extern "C" void __cxa_guard_release(_guard_t* gv) {
+    // pending -> ready
+    // waiting -> ready, and wake
+
+    ANDROID_MEMBAR_FULL();
+    if (__bionic_cmpxchg(pending, ready, &gv->state) == 0) {
+        return;
+    }
+
+    gv->state = ready;
+    __futex_wake(&gv->state, 0x7fffffff);
+}
+
+extern "C" void __cxa_guard_abort(_guard_t* gv) {
+    ANDROID_MEMBAR_FULL();
+    gv->state= 0;
+    __futex_wake(&gv->state, 0x7fffffff);
+}
diff --git a/libc/bionic/__cxa_pure_virtual.cpp b/libc/bionic/__cxa_pure_virtual.cpp
new file mode 100644
index 0000000..30b581f
--- /dev/null
+++ b/libc/bionic/__cxa_pure_virtual.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <private/libc_logging.h>
+
+extern "C" void __cxa_pure_virtual() {
+  __libc_fatal("Pure virtual function called. Are you calling virtual methods from a destructor?");
+}
diff --git a/libc/bionic/__libc_current_sigrtmax.cpp b/libc/bionic/__libc_current_sigrtmax.cpp
new file mode 100644
index 0000000..27fcb35
--- /dev/null
+++ b/libc/bionic/__libc_current_sigrtmax.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <signal.h>
+
+int __libc_current_sigrtmax(void) {
+  return __SIGRTMAX;
+}
diff --git a/libc/bionic/__libc_current_sigrtmin.cpp b/libc/bionic/__libc_current_sigrtmin.cpp
new file mode 100644
index 0000000..16b037d
--- /dev/null
+++ b/libc/bionic/__libc_current_sigrtmin.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <signal.h>
+
+// POSIX timers use __SIGRTMIN + 0.
+// libbacktrace uses __SIGRTMIN + 1.
+// libcore uses __SIGRTMIN + 2.
+
+int __libc_current_sigrtmin(void) {
+  return __SIGRTMIN + 3;
+}
diff --git a/libc/bionic/__set_errno.cpp b/libc/bionic/__set_errno.cpp
index af6a68e..30df350 100644
--- a/libc/bionic/__set_errno.cpp
+++ b/libc/bionic/__set_errno.cpp
@@ -31,8 +31,25 @@
 // This function is called from our assembler syscall stubs.
 // C/C++ code should just assign 'errno' instead.
 
-// TODO: this should be __LIBC_HIDDEN__ but was exposed in <errno.h> in the NDK.
-extern "C" int __set_errno(int n) {
+// The return type is 'long' because we use the same routine in calls
+// that return an int as in ones that return a ssize_t. On a 32-bit
+// system these are the same size, but on a 64-bit system they're not.
+// 'long' gives us 32-bit on 32-bit systems, 64-bit on 64-bit systems.
+
+// __set_errno was mistakenly exposed in <errno.h> in the 32-bit NDK.
+// We need the extra level of indirection so that the .hidden directives
+// in the system call stubs don't cause __set_errno to be hidden, breaking
+// old NDK apps.
+
+// This one is for internal use only and used by both LP32 and LP64 assembler.
+extern "C" __LIBC_HIDDEN__ long __set_errno_internal(int n) {
   errno = n;
   return -1;
 }
+
+// This one exists for the LP32 NDK and is not present at all in LP64.
+#if !defined(__LP64__)
+extern "C" long __set_errno(int n) {
+  return __set_errno_internal(n);
+}
+#endif
diff --git a/libc/bionic/__stpcpy_chk.cpp b/libc/bionic/__stpcpy_chk.cpp
new file mode 100644
index 0000000..3ce81ee
--- /dev/null
+++ b/libc/bionic/__stpcpy_chk.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#undef _FORTIFY_SOURCE
+
+#include <string.h>
+#include <stdlib.h>
+#include "private/libc_logging.h"
+
+/*
+ * Runtime implementation of __builtin____stpcpy_chk.
+ *
+ * See
+ *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
+ *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
+ * for details.
+ *
+ * This stpcpy check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+extern "C" char* __stpcpy_chk(char* dest, const char* src, size_t dest_len) {
+  // TODO: optimize so we don't scan src twice.
+  size_t src_len = strlen(src) + 1;
+  if (__predict_false(src_len > dest_len)) {
+    __fortify_chk_fail("stpcpy: prevented write past end of buffer",
+                       BIONIC_EVENT_STPCPY_BUFFER_OVERFLOW);
+  }
+
+  return stpcpy(dest, src);
+}
diff --git a/libc/bionic/__stpncpy_chk.cpp b/libc/bionic/__stpncpy_chk.cpp
new file mode 100644
index 0000000..6c9215c
--- /dev/null
+++ b/libc/bionic/__stpncpy_chk.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#undef _FORTIFY_SOURCE
+
+#include <string.h>
+#include <stdlib.h>
+#include "private/libc_logging.h"
+
+/*
+ * Runtime implementation of __builtin____stpncpy_chk.
+ *
+ * See
+ *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
+ *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
+ * for details.
+ *
+ * This stpncpy check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+extern "C" char* __stpncpy_chk(char* __restrict dest, const char* __restrict src,
+                               size_t len, size_t dest_len) {
+  if (__predict_false(len > dest_len)) {
+    __fortify_chk_fail("stpncpy: prevented write past end of buffer",
+                       BIONIC_EVENT_STPNCPY_BUFFER_OVERFLOW);
+  }
+
+  return stpncpy(dest, src, len);
+}
+
+/*
+ * __stpncpy_chk2
+ *
+ * This is a variant of __stpncpy_chk, but it also checks to make
+ * sure we don't read beyond the end of "src". The code for this is
+ * based on the original version of stpncpy, but modified to check
+ * how much we read from "src" at the end of the copy operation.
+ */
+extern "C" char* __stpncpy_chk2(char* __restrict dst, const char* __restrict src,
+              size_t n, size_t dest_len, size_t src_len)
+{
+  if (__predict_false(n > dest_len)) {
+    __fortify_chk_fail("stpncpy: prevented write past end of buffer",
+                       BIONIC_EVENT_STPNCPY_BUFFER_OVERFLOW);
+  }
+  if (n != 0) {
+    char* d = dst;
+    const char* s = src;
+
+    do {
+      if ((*d++ = *s++) == 0) {
+        /* NUL pad the remaining n-1 bytes */
+        while (--n != 0) {
+          *d++ = 0;
+        }
+        break;
+      }
+    } while (--n != 0);
+
+    size_t s_copy_len = static_cast<size_t>(s - src);
+    if (__predict_false(s_copy_len > src_len)) {
+      __fortify_chk_fail("stpncpy: prevented read past end of buffer", 0);
+    }
+  }
+
+  return dst;
+}
diff --git a/libc/bionic/__strcpy_chk.cpp b/libc/bionic/__strcpy_chk.cpp
index 1f6bc80..ad3ef50 100644
--- a/libc/bionic/__strcpy_chk.cpp
+++ b/libc/bionic/__strcpy_chk.cpp
@@ -26,6 +26,8 @@
  * SUCH DAMAGE.
  */
 
+#undef _FORTIFY_SOURCE
+
 #include <string.h>
 #include <stdlib.h>
 #include "private/libc_logging.h"
@@ -41,7 +43,7 @@
  * This strcpy check is called if _FORTIFY_SOURCE is defined and
  * greater than 0.
  */
-extern "C" char* __strcpy_chk (char* dest, const char* src, size_t dest_len) {
+extern "C" char* __strcpy_chk(char* dest, const char* src, size_t dest_len) {
   // TODO: optimize so we don't scan src twice.
   size_t src_len = strlen(src) + 1;
   if (__predict_false(src_len > dest_len)) {
diff --git a/libc/bionic/__strrchr_chk.cpp b/libc/bionic/__strrchr_chk.cpp
index 4037207..69198c0 100644
--- a/libc/bionic/__strrchr_chk.cpp
+++ b/libc/bionic/__strrchr_chk.cpp
@@ -1,4 +1,3 @@
-/*	$OpenBSD: rindex.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
 /*
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
diff --git a/libc/bionic/abort.cpp b/libc/bionic/abort.cpp
index 6fcdfda..75413c6 100644
--- a/libc/bionic/abort.cpp
+++ b/libc/bionic/abort.cpp
@@ -30,9 +30,6 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include "atexit.h"
-
-__LIBC_HIDDEN__ void (*__cleanup)();
 
 #ifdef __arm__
 extern "C" __LIBC_HIDDEN__ void __libc_android_abort()
@@ -47,11 +44,6 @@
   sigdelset(&mask, SIGABRT);
   sigprocmask(SIG_SETMASK, &mask, NULL);
 
-  // POSIX requires we flush stdio buffers on abort.
-  if (__cleanup) {
-    (*__cleanup)();
-  }
-
   raise(SIGABRT);
 
   // If SIGABRT ignored, or caught and the handler returns,
diff --git a/libc/bionic/accept.cpp b/libc/bionic/accept.cpp
new file mode 100644
index 0000000..7f7aa06
--- /dev/null
+++ b/libc/bionic/accept.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/socket.h>
+
+int accept(int sockfd, sockaddr* addr, socklen_t* addrlen) {
+    return accept4(sockfd, addr, addrlen, 0);
+}
diff --git a/libc/bionic/accept4.cpp b/libc/bionic/accept4.cpp
new file mode 100644
index 0000000..9f58dc1
--- /dev/null
+++ b/libc/bionic/accept4.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "private/NetdClientDispatch.h"
+
+#include <sys/socket.h>
+
+int accept4(int sockfd, sockaddr* addr, socklen_t* addrlen, int flags) {
+    return __netdClientDispatch.accept4(sockfd, addr, addrlen, flags);
+}
diff --git a/libc/bionic/arc4random.c b/libc/bionic/arc4random.c
deleted file mode 100644
index eac4b0c..0000000
--- a/libc/bionic/arc4random.c
+++ /dev/null
@@ -1,308 +0,0 @@
-/*      $OpenBSD: arc4random.c,v 1.19 2008/06/04 00:50:23 djm Exp $        */
-
-/*
- * Copyright (c) 1996, David Mazieres <dm@uun.org>
- * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
- *
- * Permission to use, copy, modify, and 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.
- */
-
-/*
- * Arc4 random number generator for OpenBSD.
- *
- * This code is derived from section 17.1 of Applied Cryptography,
- * second edition, which describes a stream cipher allegedly
- * compatible with RSA Labs "RC4" cipher (the actual description of
- * which is a trade secret).  The same algorithm is used as a stream
- * cipher called "arcfour" in Tatu Ylonen's ssh package.
- *
- * Here the stream cipher has been modified always to include the time
- * when initializing the state.  That makes it impossible to
- * regenerate the same random sequence twice, so this can't be used
- * for encryption, but will generate good random numbers.
- *
- * RC4 is a registered trademark of RSA Laboratories.
- */
-
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include "private/thread_private.h"
-
-/* BIONIC-BEGIN */
-/* this lock should protect the global variables in this file */
-static pthread_mutex_t  _arc4_lock = PTHREAD_MUTEX_INITIALIZER;
-#define  _ARC4_LOCK()      pthread_mutex_lock(&_arc4_lock)
-#define  _ARC4_UNLOCK()    pthread_mutex_unlock(&_arc4_lock)
-/* BIONIC-END */
-
-#ifdef __GNUC__
-#define inline __inline
-#else                           /* !__GNUC__ */
-#define inline
-#endif                          /* !__GNUC__ */
-
-struct arc4_stream {
-        u_int8_t i;
-        u_int8_t j;
-        u_int8_t s[256];
-};
-
-static int rs_initialized;
-static struct arc4_stream rs;
-static pid_t arc4_stir_pid;
-static int arc4_count;
-
-static inline u_int8_t arc4_getbyte(void);
-
-static inline void
-arc4_init(void)
-{
-        int     n;
-
-        for (n = 0; n < 256; n++)
-                rs.s[n] = n;
-        rs.i = 0;
-        rs.j = 0;
-}
-
-static inline void
-arc4_addrandom(u_char *dat, int datlen)
-{
-        int     n;
-        u_int8_t si;
-
-        rs.i--;
-        for (n = 0; n < 256; n++) {
-                rs.i = (rs.i + 1);
-                si = rs.s[rs.i];
-                rs.j = (rs.j + si + dat[n % datlen]);
-                rs.s[rs.i] = rs.s[rs.j];
-                rs.s[rs.j] = si;
-        }
-        rs.j = rs.i;
-}
-
-static void
-arc4_stir(void)
-{
-#if 1  /* BIONIC-BEGIN */
-	int     i, fd;
-	union {
-		struct timeval tv;
-		u_int rnd[128 / sizeof(u_int)];
-	}       rdat;
-	int	n;
-
-        if (!rs_initialized) {
-                arc4_init();
-                rs_initialized = 1;
-        }
-
-	fd = open("/dev/urandom", O_RDONLY);
-	if (fd != -1) {
-		read(fd, rdat.rnd, sizeof(rdat.rnd));
-		close(fd);
-	}
-        else
-        {
-	    /* fd < 0 ?  Ah, what the heck. We'll just take
-	     * whatever was on the stack. just add a little more
-             * time-based randomness though
-             */
-            gettimeofday(&rdat.tv, NULL);
-        }
-
-        arc4_stir_pid = getpid();
-	arc4_addrandom((void *) &rdat, sizeof(rdat));
-#else  /* BIONIC-END */
-        int     i, mib[2];
-        size_t        len;
-        u_char rnd[128];
-
-        if (!rs_initialized) {
-                arc4_init();
-                rs_initialized = 1;
-        }
-
-        mib[0] = CTL_KERN;
-        mib[1] = KERN_ARND;
-
-        len = sizeof(rnd);
-        sysctl(mib, 2, rnd, &len, NULL, 0);
-
-        arc4_stir_pid = getpid();
-        arc4_addrandom(rnd, sizeof(rnd));
-#endif
-        /*
-         * Discard early keystream, as per recommendations in:
-         * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
-         */
-        for (i = 0; i < 256; i++)
-                (void)arc4_getbyte();
-        arc4_count = 1600000;
-}
-
-static inline u_int8_t
-arc4_getbyte(void)
-{
-        u_int8_t si, sj;
-
-        rs.i = (rs.i + 1);
-        si = rs.s[rs.i];
-        rs.j = (rs.j + si);
-        sj = rs.s[rs.j];
-        rs.s[rs.i] = sj;
-        rs.s[rs.j] = si;
-        return (rs.s[(si + sj) & 0xff]);
-}
-
-u_int8_t
-__arc4_getbyte(void)
-{
-        u_int8_t val;
-
-        _ARC4_LOCK();
-        if (--arc4_count == 0 || !rs_initialized)
-                arc4_stir();
-        val = arc4_getbyte();
-        _ARC4_UNLOCK();
-        return val;
-}
-
-static inline u_int32_t
-arc4_getword(void)
-{
-        u_int32_t val;
-        val = arc4_getbyte() << 24;
-        val |= arc4_getbyte() << 16;
-        val |= arc4_getbyte() << 8;
-        val |= arc4_getbyte();
-        return val;
-}
-
-void
-arc4random_stir(void)
-{
-        _ARC4_LOCK();
-        arc4_stir();
-        _ARC4_UNLOCK();
-}
-
-void
-arc4random_addrandom(u_char *dat, int datlen)
-{
-        _ARC4_LOCK();
-        if (!rs_initialized)
-                arc4_stir();
-        arc4_addrandom(dat, datlen);
-        _ARC4_UNLOCK();
-}
-
-u_int32_t
-arc4random(void)
-{
-        u_int32_t val;
-        _ARC4_LOCK();
-        arc4_count -= 4;
-        if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != getpid())
-                arc4_stir();
-        val = arc4_getword();
-        _ARC4_UNLOCK();
-        return val;
-}
-
-void
-arc4random_buf(void *_buf, size_t n)
-{
-        u_char *buf = (u_char *)_buf;
-        _ARC4_LOCK();
-        if (!rs_initialized || arc4_stir_pid != getpid())
-                arc4_stir();
-        while (n--) {
-                if (--arc4_count <= 0)
-                        arc4_stir();
-                buf[n] = arc4_getbyte();
-        }
-        _ARC4_UNLOCK();
-}
-
-/*
- * Calculate a uniformly distributed random number less than upper_bound
- * avoiding "modulo bias".
- *
- * Uniformity is achieved by generating new random numbers until the one
- * returned is outside the range [0, 2**32 % upper_bound).  This
- * guarantees the selected random number will be inside
- * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
- * after reduction modulo upper_bound.
- */
-u_int32_t
-arc4random_uniform(u_int32_t upper_bound)
-{
-        u_int32_t r, min;
-
-        if (upper_bound < 2)
-                return 0;
-
-#if (ULONG_MAX > 0xffffffffUL)
-        min = 0x100000000UL % upper_bound;
-#else
-        /* Calculate (2**32 % upper_bound) avoiding 64-bit math */
-        if (upper_bound > 0x80000000)
-                min = 1 + ~upper_bound;                /* 2**32 - upper_bound */
-        else {
-                /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
-                min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
-        }
-#endif
-
-        /*
-         * This could theoretically loop forever but each retry has
-         * p > 0.5 (worst case, usually far better) of selecting a
-         * number inside the range we need, so it should rarely need
-         * to re-roll.
-         */
-        for (;;) {
-                r = arc4random();
-                if (r >= min)
-                        break;
-        }
-
-        return r % upper_bound;
-}
-
-#if 0
-/*-------- Test code for i386 --------*/
-#include <stdio.h>
-#include <machine/pctr.h>
-int
-main(int argc, char **argv)
-{
-        const int iter = 1000000;
-        int     i;
-        pctrval v;
-
-        v = rdtsc();
-        for (i = 0; i < iter; i++)
-                arc4random();
-        v = rdtsc() - v;
-        v /= iter;
-
-        printf("%qd cycles\n", v);
-}
-#endif
diff --git a/libc/bionic/assert.cpp b/libc/bionic/assert.cpp
index ba67143..985fc38 100644
--- a/libc/bionic/assert.cpp
+++ b/libc/bionic/assert.cpp
@@ -34,10 +34,12 @@
 
 void __assert(const char* file, int line, const char* failed_expression) {
   __libc_fatal("%s:%d: assertion \"%s\" failed", file, line, failed_expression);
-  /* NOTREACHED */
 }
 
 void __assert2(const char* file, int line, const char* function, const char* failed_expression) {
   __libc_fatal("%s:%d: %s: assertion \"%s\" failed", file, line, function, failed_expression);
-  /* NOTREACHED */
+}
+
+extern "C" __LIBC_HIDDEN__ void longjmperror() {
+  __libc_fatal("longjmp botch");
 }
diff --git a/libc/bionic/atof.cpp b/libc/bionic/atof.cpp
new file mode 100644
index 0000000..e77ccdd
--- /dev/null
+++ b/libc/bionic/atof.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+double atof(const char* s) {
+  // Despite the 'f' in the name, this returns a double and is
+  // specified to be equivalent to strtod.
+  return strtod(s, NULL);
+}
diff --git a/libc/bionic/atoi.c b/libc/bionic/atoi.c
deleted file mode 100644
index 9a65543..0000000
--- a/libc/bionic/atoi.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <inttypes.h>
-
-int  atoi(const char*  s)
-{
-    return (int)strtoimax(s, NULL, 10);
-}
diff --git a/libc/bionic/atol.c b/libc/bionic/atol.c
deleted file mode 100644
index 83dc05c..0000000
--- a/libc/bionic/atol.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <inttypes.h>
-
-long  atol(const char*  s)
-{
-    return (long)strtoimax(s, NULL, 10);
-}
diff --git a/libc/bionic/atoll.c b/libc/bionic/atoll.c
deleted file mode 100644
index 953878f..0000000
--- a/libc/bionic/atoll.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <inttypes.h>
-
-long long atoll(const char*  s)
-{
-    return (long long)strtoimax(s, NULL, 10);
-}
diff --git a/libc/bionic/brk.cpp b/libc/bionic/brk.cpp
index 633b914..4e46193 100644
--- a/libc/bionic/brk.cpp
+++ b/libc/bionic/brk.cpp
@@ -26,16 +26,49 @@
  * SUCH DAMAGE.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
-/* Shared with sbrk.c. */
-extern "C" void* __bionic_brk; // TODO: should be __LIBC_HIDDEN__ but accidentally exported by NDK :-(
+#if __LP64__
+static void* __bionic_brk;
+#else
+void* __bionic_brk; // Accidentally exported by the NDK.
+#endif
 
 int brk(void* end_data) {
-  void* new_brk = __brk(end_data);
-  if (new_brk != end_data) {
+  __bionic_brk = __brk(end_data);
+  if (__bionic_brk < end_data) {
+    errno = ENOMEM;
     return -1;
   }
-  __bionic_brk = new_brk;
   return 0;
 }
+
+void* sbrk(ptrdiff_t increment) {
+  // Initialize __bionic_brk if necessary.
+  if (__bionic_brk == NULL) {
+    __bionic_brk = __brk(NULL);
+  }
+
+  // Don't ask the kernel if we already know the answer.
+  if (increment == 0) {
+    return __bionic_brk;
+  }
+
+  // Avoid overflow.
+  uintptr_t old_brk = reinterpret_cast<uintptr_t>(__bionic_brk);
+  if ((increment > 0 && static_cast<uintptr_t>(increment) > (UINTPTR_MAX - old_brk)) ||
+      (increment < 0 && static_cast<uintptr_t>(-increment) > old_brk)) {
+    errno = ENOMEM;
+    return reinterpret_cast<void*>(-1);
+  }
+
+  void* desired_brk = reinterpret_cast<void*>(old_brk + increment);
+  __bionic_brk = __brk(desired_brk);
+  if (__bionic_brk < desired_brk) {
+    errno = ENOMEM;
+    return reinterpret_cast<void*>(-1);
+  }
+
+  return reinterpret_cast<void*>(old_brk);
+}
diff --git a/libc/bionic/c16rtomb.cpp b/libc/bionic/c16rtomb.cpp
new file mode 100644
index 0000000..77512be
--- /dev/null
+++ b/libc/bionic/c16rtomb.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <uchar.h>
+#include <wchar.h>
+
+#include "private/bionic_mbstate.h"
+
+static inline constexpr bool is_high_surrogate(char16_t c16) {
+  return c16 >= 0xd800 && c16 < 0xdc00;
+}
+
+static inline constexpr bool is_low_surrogate(char16_t c16) {
+  return c16 >= 0xdc00 && c16 < 0xe000;
+}
+
+size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps) {
+  static mbstate_t __private_state;
+  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  if (mbsinit(state)) {
+    if (is_high_surrogate(c16)) {
+      char32_t c32 = (c16 & ~0xd800) << 10;
+      mbstate_set_byte(state, 3, (c32 & 0xff0000) >> 16);
+      mbstate_set_byte(state, 2, (c32 & 0x00ff00) >> 8);
+      return 0;
+    } else if (is_low_surrogate(c16)) {
+      return reset_and_return_illegal(EINVAL, state);
+    } else {
+      return c32rtomb(s, static_cast<char32_t>(c16), state);
+    }
+  } else {
+    if (!is_low_surrogate(c16)) {
+      return reset_and_return_illegal(EINVAL, state);
+    }
+
+    char32_t c32 = ((mbstate_get_byte(state, 3) << 16) |
+                    (mbstate_get_byte(state, 2) << 8) |
+                    (c16 & ~0xdc00)) + 0x10000;
+    return reset_and_return(c32rtomb(s, c32, NULL), state);
+  }
+}
diff --git a/libc/bionic/c32rtomb.cpp b/libc/bionic/c32rtomb.cpp
new file mode 100644
index 0000000..d3231c0
--- /dev/null
+++ b/libc/bionic/c32rtomb.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <uchar.h>
+#include <wchar.h>
+
+#include "private/bionic_mbstate.h"
+
+size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps) {
+  static mbstate_t __private_state;
+  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+
+  if (s == NULL) {
+    // Equivalent to c32rtomb(buf, U'\0', ps).
+    return reset_and_return(1, state);
+  }
+
+  // POSIX states that if char32_t is a null wide character, a null byte shall
+  // be stored, preceded by any shift sequence needed to restore the initial
+  // shift state. Since shift states are not supported, only the null byte is
+  // stored.
+  if (c32 == U'\0') {
+    *s = '\0';
+    reset_and_return(1, state);
+  }
+
+  if (!mbsinit(state)) {
+    return reset_and_return_illegal(EILSEQ, state);
+  }
+
+  if ((c32 & ~0x7f) == 0) {
+    // Fast path for plain ASCII characters.
+    *s = c32;
+    return 1;
+  }
+
+  // Determine the number of octets needed to represent this character.
+  // We always output the shortest sequence possible. Also specify the
+  // first few bits of the first octet, which contains the information
+  // about the sequence length.
+  uint8_t lead;
+  size_t length;
+  if ((c32 & ~0x7f) == 0) {
+    lead = 0;
+    length = 1;
+  } else if ((c32 & ~0x7ff) == 0) {
+    lead = 0xc0;
+    length = 2;
+  } else if ((c32 & ~0xffff) == 0) {
+    lead = 0xe0;
+    length = 3;
+  } else if ((c32 & ~0x1fffff) == 0) {
+    lead = 0xf0;
+    length = 4;
+  } else {
+    errno = EILSEQ;
+    return __MB_ERR_ILLEGAL_SEQUENCE;
+  }
+
+  // Output the octets representing the character in chunks
+  // of 6 bits, least significant last. The first octet is
+  // a special case because it contains the sequence length
+  // information.
+  for (size_t i = length - 1; i > 0; i--) {
+    s[i] = (c32 & 0x3f) | 0x80;
+    c32 >>= 6;
+  }
+  *s = (c32 & 0xff) | lead;
+
+  return length;
+}
diff --git a/libc/bionic/clearenv.c b/libc/bionic/clearenv.c
deleted file mode 100644
index 0f6f066..0000000
--- a/libc/bionic/clearenv.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stddef.h>
-
-extern char** environ;
-
-int clearenv(void)
-{
-    char **P = environ;
-
-    if (P != NULL) {
-        for (; *P; ++P)
-            *P = NULL;
-    }
-    return 0;
-}
diff --git a/libc/bionic/clearenv.cpp b/libc/bionic/clearenv.cpp
new file mode 100644
index 0000000..c70cc3e
--- /dev/null
+++ b/libc/bionic/clearenv.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+
+int clearenv() {
+  char** e = environ;
+  if (e != NULL) {
+    for (; *e; ++e) {
+      *e = NULL;
+    }
+  }
+  return 0;
+}
diff --git a/libc/bionic/clock.cpp b/libc/bionic/clock.cpp
new file mode 100644
index 0000000..5bd32f9
--- /dev/null
+++ b/libc/bionic/clock.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <time.h>
+#include <sys/sysconf.h>
+#include <sys/times.h>
+
+#define NS_PER_S 1000000000 // No "private/bionic_constants.h" in lmp-dev.
+
+// http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock.html
+clock_t clock() {
+  timespec ts;
+  if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1) {
+    return -1;
+  }
+  return (ts.tv_sec * CLOCKS_PER_SEC) + (ts.tv_nsec / (NS_PER_S / CLOCKS_PER_SEC));
+}
diff --git a/libc/bionic/clone.cpp b/libc/bionic/clone.cpp
index 1d997fe..0a0fdd5 100644
--- a/libc/bionic/clone.cpp
+++ b/libc/bionic/clone.cpp
@@ -31,11 +31,13 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
+#include "pthread_internal.h"
+
 extern "C" pid_t __bionic_clone(uint32_t flags, void* child_stack, int* parent_tid, void* tls, int* child_tid, int (*fn)(void*), void* arg);
-extern "C" void __exit(int status);
+extern "C" __noreturn void __exit(int status);
 
 // Called from the __bionic_clone assembler to call the thread function then exit.
-extern "C" void __bionic_clone_entry(int (*fn)(void*), void* arg) {
+extern "C" __LIBC_HIDDEN__ void __start_thread(int (*fn)(void*), void* arg) {
   int status = (*fn)(arg);
   __exit(status);
 }
@@ -59,5 +61,23 @@
   }
   va_end(args);
 
-  return __bionic_clone(flags, child_stack, parent_tid, new_tls, child_tid, fn, arg);
+  // Align 'child_stack' to 16 bytes.
+  uintptr_t child_stack_addr = reinterpret_cast<uintptr_t>(child_stack);
+  child_stack_addr &= ~0xf;
+  child_stack = reinterpret_cast<void*>(child_stack_addr);
+
+  // Remember the parent pid and invalidate the cached value while we clone.
+  pthread_internal_t* self = __get_thread();
+  pid_t parent_pid = self->invalidate_cached_pid();
+
+  // Actually do the clone.
+  int clone_result = __bionic_clone(flags, child_stack, parent_tid, new_tls, child_tid, fn, arg);
+
+  // We're the parent, so put our known pid back in place.
+  // We leave the child without a cached pid, but:
+  // 1. pthread_create gives its children their own pthread_internal_t with the correct pid.
+  // 2. fork makes a clone system call directly.
+  // If any other cases become important, we could use a double trampoline like __pthread_start.
+  self->set_cached_pid(parent_pid);
+  return clone_result;
 }
diff --git a/libc/bionic/connect.cpp b/libc/bionic/connect.cpp
new file mode 100644
index 0000000..1673f4a
--- /dev/null
+++ b/libc/bionic/connect.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "private/NetdClientDispatch.h"
+
+#include <sys/socket.h>
+
+int connect(int sockfd, const sockaddr* addr, socklen_t addrlen) {
+    return __netdClientDispatch.connect(sockfd, addr, addrlen);
+}
diff --git a/libc/bionic/ctype.cpp b/libc/bionic/ctype.cpp
new file mode 100644
index 0000000..2b31d52
--- /dev/null
+++ b/libc/bionic/ctype.cpp
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+
+int isalnum_l(int c, locale_t) {
+  return isalnum(c);
+}
+
+int isalpha_l(int c, locale_t) {
+  return isalpha(c);
+}
+
+int isblank_l(int c, locale_t) {
+  return isblank(c);
+}
+
+int iscntrl_l(int c, locale_t) {
+  return iscntrl(c);
+}
+
+int isdigit_l(int c, locale_t) {
+  return isdigit(c);
+}
+
+int isgraph_l(int c, locale_t) {
+  return isgraph(c);
+}
+
+int islower_l(int c, locale_t) {
+  return islower(c);
+}
+
+int isprint_l(int c, locale_t) {
+  return isprint(c);
+}
+
+int ispunct_l(int c, locale_t) {
+  return ispunct(c);
+}
+
+int isspace_l(int c, locale_t) {
+  return isspace(c);
+}
+
+int isupper_l(int c, locale_t) {
+  return isupper(c);
+}
+
+int isxdigit_l(int c, locale_t) {
+  return isxdigit(c);
+}
+
+int toupper_l(int c, locale_t) {
+  return toupper(c);
+}
+
+int tolower_l(int c, locale_t) {
+  return tolower(c);
+}
diff --git a/libc/bionic/debug_mapinfo.cpp b/libc/bionic/debug_mapinfo.cpp
index c5b9aa7..d83799a 100644
--- a/libc/bionic/debug_mapinfo.cpp
+++ b/libc/bionic/debug_mapinfo.cpp
@@ -26,38 +26,48 @@
  * SUCH DAMAGE.
  */
 
+#include <ctype.h>
+#include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
-#include "dlmalloc.h"
 #include "debug_mapinfo.h"
+#include "malloc_debug_disable.h"
 
-// 6f000000-6f01e000 rwxp 00000000 00:0c 16389419   /system/lib/libcomposer.so
-// 012345678901234567890123456789012345678901234567890123456789
-// 0         1         2         3         4         5
-
+// Format of /proc/<PID>/maps:
+//   6f000000-6f01e000 rwxp 00000000 00:0c 16389419   /system/lib/libcomposer.so
 static mapinfo_t* parse_maps_line(char* line) {
-  int len = strlen(line);
+  uintptr_t start;
+  uintptr_t end;
+  int name_pos;
+  if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %*4s %*x %*x:%*x %*d%n", &start,
+             &end, &name_pos) < 2) {
+    return NULL;
+  }
 
-  if (len < 1) return 0;
-  line[--len] = 0;
+  while (isspace(line[name_pos])) {
+    name_pos += 1;
+  }
+  const char* name = line + name_pos;
+  size_t name_len = strlen(name);
+  if (name_len && name[name_len - 1] == '\n') {
+    name_len -= 1;
+  }
 
-  if (len < 50) return 0;
-  if (line[20] != 'x') return 0;
-
-  mapinfo_t* mi = static_cast<mapinfo_t*>(dlmalloc(sizeof(mapinfo_t) + (len - 47)));
-  if (mi == 0) return 0;
-
-  mi->start = strtoul(line, 0, 16);
-  mi->end = strtoul(line + 9, 0, 16);
-  mi->next = 0;
-  strcpy(mi->name, line + 49);
-
+  mapinfo_t* mi = reinterpret_cast<mapinfo_t*>(calloc(1, sizeof(mapinfo_t) + name_len + 1));
+  if (mi) {
+    mi->start = start;
+    mi->end = end;
+    memcpy(mi->name, name, name_len);
+    mi->name[name_len] = '\0';
+  }
   return mi;
 }
 
 __LIBC_HIDDEN__ mapinfo_t* mapinfo_create(pid_t pid) {
+  ScopedDisableDebugCalls disable;
+
   struct mapinfo_t* milist = NULL;
   char data[1024]; // Used to read lines as well as to construct the filename.
   snprintf(data, sizeof(data), "/proc/%d/maps", pid);
@@ -76,10 +86,12 @@
 }
 
 __LIBC_HIDDEN__ void mapinfo_destroy(mapinfo_t* mi) {
+  ScopedDisableDebugCalls disable;
+
   while (mi != NULL) {
     mapinfo_t* del = mi;
     mi = mi->next;
-    dlfree(del);
+    free(del);
   }
 }
 
diff --git a/libc/bionic/debug_mapinfo.h b/libc/bionic/debug_mapinfo.h
index cccd2e3..926b377 100644
--- a/libc/bionic/debug_mapinfo.h
+++ b/libc/bionic/debug_mapinfo.h
@@ -33,8 +33,8 @@
 
 struct mapinfo_t {
   struct mapinfo_t* next;
-  unsigned start;
-  unsigned end;
+  uintptr_t start;
+  uintptr_t end;
   char name[];
 };
 
diff --git a/libc/bionic/debug_stacktrace.cpp b/libc/bionic/debug_stacktrace.cpp
index 5ddc00c..b86e2af 100644
--- a/libc/bionic/debug_stacktrace.cpp
+++ b/libc/bionic/debug_stacktrace.cpp
@@ -35,8 +35,15 @@
 #include <sys/types.h>
 
 #include "debug_mapinfo.h"
+#include "malloc_debug_disable.h"
 #include "private/libc_logging.h"
 
+#if defined(__LP64__)
+#define PAD_PTR "016" PRIxPTR
+#else
+#define PAD_PTR "08" PRIxPTR
+#endif
+
 /* depends how the system includes define this */
 #ifdef HAVE_UNWIND_CONTEXT_STRUCT
 typedef struct _Unwind_Context __unwind_context;
@@ -44,30 +51,34 @@
 typedef _Unwind_Context __unwind_context;
 #endif
 
-static mapinfo_t* gMapInfo = NULL;
-static void* gDemangler;
+static mapinfo_t* g_map_info = NULL;
+static void* g_demangler;
 typedef char* (*DemanglerFn)(const char*, char*, size_t*, int*);
-static DemanglerFn gDemanglerFn = NULL;
+static DemanglerFn g_demangler_fn = NULL;
 
 __LIBC_HIDDEN__ void backtrace_startup() {
-  gMapInfo = mapinfo_create(getpid());
-  gDemangler = dlopen("libgccdemangle.so", RTLD_NOW);
-  if (gDemangler != NULL) {
-    void* sym = dlsym(gDemangler, "__cxa_demangle");
-    gDemanglerFn = reinterpret_cast<DemanglerFn>(sym);
+  ScopedDisableDebugCalls disable;
+
+  g_map_info = mapinfo_create(getpid());
+  g_demangler = dlopen("libgccdemangle.so", RTLD_NOW);
+  if (g_demangler != NULL) {
+    void* sym = dlsym(g_demangler, "__cxa_demangle");
+    g_demangler_fn = reinterpret_cast<DemanglerFn>(sym);
   }
 }
 
 __LIBC_HIDDEN__ void backtrace_shutdown() {
-  mapinfo_destroy(gMapInfo);
-  dlclose(gDemangler);
+  ScopedDisableDebugCalls disable;
+
+  mapinfo_destroy(g_map_info);
+  dlclose(g_demangler);
 }
 
 static char* demangle(const char* symbol) {
-  if (gDemanglerFn == NULL) {
+  if (g_demangler_fn == NULL) {
     return NULL;
   }
-  return (*gDemanglerFn)(symbol, NULL, NULL, NULL);
+  return (*g_demangler_fn)(symbol, NULL, NULL, NULL);
 }
 
 struct stack_crawl_state_t {
@@ -81,18 +92,6 @@
   }
 };
 
-#if defined(__arm__) && !defined(_Unwind_GetIP)
-// Older versions of Clang don't provide a definition of _Unwind_GetIP(), so
-// we include an appropriate version of our own. Once we have updated to
-// Clang 3.4, this code can be removed.
-static __inline__
-uintptr_t _Unwind_GetIP(struct _Unwind_Context *__context) {
-  uintptr_t __ip = 0;
-  _Unwind_VRS_Get(__context, _UVRSC_CORE, 15, _UVRSD_UINT32, &__ip);
-  return __ip & ~0x1;
-}
-#endif
-
 static _Unwind_Reason_Code trace_function(__unwind_context* context, void* arg) {
   stack_crawl_state_t* state = static_cast<stack_crawl_state_t*>(arg);
 
@@ -104,7 +103,7 @@
     return _URC_NO_REASON;
   }
 
-#ifdef __arm__
+#if defined(__arm__)
   /*
    * The instruction pointer is pointing at the instruction after the bl(x), and
    * the _Unwind_Backtrace routine already masks the Thumb mode indicator (LSB
@@ -127,12 +126,16 @@
 }
 
 __LIBC_HIDDEN__ int get_backtrace(uintptr_t* frames, size_t max_depth) {
+  ScopedDisableDebugCalls disable;
+
   stack_crawl_state_t state(frames, max_depth);
   _Unwind_Backtrace(trace_function, &state);
   return state.frame_count;
 }
 
 __LIBC_HIDDEN__ void log_backtrace(uintptr_t* frames, size_t frame_count) {
+  ScopedDisableDebugCalls disable;
+
   uintptr_t self_bt[16];
   if (frames == NULL) {
     frame_count = get_backtrace(self_bt, 16);
@@ -152,8 +155,8 @@
       symbol = info.dli_sname;
     }
 
-    uintptr_t rel_pc;
-    const mapinfo_t* mi = (gMapInfo != NULL) ? mapinfo_find(gMapInfo, frames[i], &rel_pc) : NULL;
+    uintptr_t rel_pc = offset;
+    const mapinfo_t* mi = (g_map_info != NULL) ? mapinfo_find(g_map_info, frames[i], &rel_pc) : NULL;
     const char* soname = (mi != NULL) ? mi->name : info.dli_fname;
     if (soname == NULL) {
       soname = "<unknown>";
@@ -164,19 +167,14 @@
       const char* best_name = (demangled_symbol != NULL) ? demangled_symbol : symbol;
 
       __libc_format_log(ANDROID_LOG_ERROR, "libc",
-                        "          #%02zd  pc %0*" PRIxPTR "  %s (%s+%" PRIuPTR ")",
-                        i,
-                        static_cast<int>(2 * sizeof(void*)), rel_pc,
-                        soname,
-                        best_name, frames[i] - offset);
+                        "          #%02zd  pc %" PAD_PTR "  %s (%s+%" PRIuPTR ")",
+                        i, rel_pc, soname, best_name, frames[i] - offset);
 
       free(demangled_symbol);
     } else {
       __libc_format_log(ANDROID_LOG_ERROR, "libc",
-                        "          #%02zd  pc %0*" PRIxPTR "  %s",
-                        i,
-                        static_cast<int>(2 * sizeof(void*)), rel_pc,
-                        soname);
+                        "          #%02zd  pc %" PAD_PTR "  %s",
+                        i, rel_pc, soname);
     }
   }
 }
diff --git a/libc/bionic/dirent.cpp b/libc/bionic/dirent.cpp
index 0565698..7abc7f3 100644
--- a/libc/bionic/dirent.cpp
+++ b/libc/bionic/dirent.cpp
@@ -37,6 +37,8 @@
 #include "private/ErrnoRestorer.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
+extern "C" int __getdents64(unsigned int, dirent*, unsigned int);
+
 struct DIR {
   int fd_;
   size_t available_bytes_;
@@ -81,7 +83,7 @@
 }
 
 static bool __fill_DIR(DIR* d) {
-  int rc = TEMP_FAILURE_RETRY(getdents(d->fd_, d->buff_, sizeof(d->buff_)));
+  int rc = TEMP_FAILURE_RETRY(__getdents64(d->fd_, d->buff_, sizeof(d->buff_)));
   if (rc <= 0) {
     return false;
   }
@@ -105,6 +107,7 @@
   ScopedPthreadMutexLocker locker(&d->mutex_);
   return __readdir_locked(d);
 }
+__strong_alias(readdir64, readdir);
 
 int readdir_r(DIR* d, dirent* entry, dirent** result) {
   ErrnoRestorer errno_restorer;
@@ -125,6 +128,7 @@
   }
   return 0;
 }
+__strong_alias(readdir64_r, readdir_r);
 
 int closedir(DIR* d) {
   if (d == NULL) {
@@ -147,3 +151,4 @@
 int alphasort(const dirent** a, const dirent** b) {
   return strcoll((*a)->d_name, (*b)->d_name);
 }
+__strong_alias(alphasort64, alphasort);
diff --git a/libc/bionic/dl_iterate_phdr_static.c b/libc/bionic/dl_iterate_phdr_static.c
deleted file mode 100644
index d03d3d2..0000000
--- a/libc/bionic/dl_iterate_phdr_static.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <elf.h>
-#include <sys/auxv.h>
-#include <sys/types.h>
-#include <link.h>
-
-/* ld provides this to us in the default link script */
-extern void* __executable_start;
-
-int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) {
-    Elf_Ehdr* ehdr = (Elf_Ehdr*) &__executable_start;
-
-    // TODO: again, copied from linker.c. Find a better home for this later.
-    if (ehdr->e_ident[EI_MAG0] != ELFMAG0) return -1;
-    if (ehdr->e_ident[EI_MAG1] != ELFMAG1) return -1;
-    if (ehdr->e_ident[EI_MAG2] != ELFMAG2) return -1;
-    if (ehdr->e_ident[EI_MAG3] != ELFMAG3) return -1;
-
-    // Dynamic binaries get their dl_iterate_phdr from the dynamic linker, but
-    // static binaries get this. We don't have a list of shared objects to
-    // iterate over, since there's really only a single monolithic blob of
-    // code/data, plus optionally a VDSO.
-
-    struct dl_phdr_info exe_info;
-    exe_info.dlpi_addr = 0;
-    exe_info.dlpi_name = NULL;
-    exe_info.dlpi_phdr = (Elf_Phdr*) ((unsigned long) ehdr + ehdr->e_phoff);
-    exe_info.dlpi_phnum = ehdr->e_phnum;
-
-#ifdef AT_SYSINFO_EHDR
-    // Try the executable first.
-    int rc = cb(&exe_info, sizeof(exe_info), data);
-    if (rc != 0) {
-        return rc;
-    }
-
-    // Try the VDSO if that didn't work.
-    Elf_Ehdr* ehdr_vdso = (Elf_Ehdr*) getauxval(AT_SYSINFO_EHDR);
-    struct dl_phdr_info vdso_info;
-    vdso_info.dlpi_addr = 0;
-    vdso_info.dlpi_name = NULL;
-    vdso_info.dlpi_phdr = (Elf_Phdr*) ((char*) ehdr_vdso + ehdr_vdso->e_phoff);
-    vdso_info.dlpi_phnum = ehdr_vdso->e_phnum;
-    for (size_t i = 0; i < vdso_info.dlpi_phnum; ++i) {
-        if (vdso_info.dlpi_phdr[i].p_type == PT_LOAD) {
-            vdso_info.dlpi_addr = (Elf_Addr) ehdr_vdso - vdso_info.dlpi_phdr[i].p_vaddr;
-            break;
-        }
-    }
-    return cb(&vdso_info, sizeof(vdso_info), data);
-#else
-    // There's only the executable to try.
-    return cb(&exe_info, sizeof(exe_info), data);
-#endif
-}
diff --git a/libc/bionic/dl_iterate_phdr_static.cpp b/libc/bionic/dl_iterate_phdr_static.cpp
new file mode 100644
index 0000000..155a7a0
--- /dev/null
+++ b/libc/bionic/dl_iterate_phdr_static.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <elf.h>
+#include <string.h>
+#include <sys/auxv.h>
+#include <sys/types.h>
+#include <link.h>
+
+/* ld provides this to us in the default link script */
+extern "C" void* __executable_start;
+
+int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) {
+  ElfW(Ehdr)* ehdr = reinterpret_cast<ElfW(Ehdr)*>(&__executable_start);
+
+  if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0) {
+    return -1;
+  }
+
+  // Dynamic binaries get their dl_iterate_phdr from the dynamic linker, but
+  // static binaries get this. We don't have a list of shared objects to
+  // iterate over, since there's really only a single monolithic blob of
+  // code/data, plus optionally a VDSO.
+
+  struct dl_phdr_info exe_info;
+  exe_info.dlpi_addr = 0;
+  exe_info.dlpi_name = NULL;
+  exe_info.dlpi_phdr = reinterpret_cast<ElfW(Phdr)*>(reinterpret_cast<uintptr_t>(ehdr) + ehdr->e_phoff);
+  exe_info.dlpi_phnum = ehdr->e_phnum;
+
+#if defined(AT_SYSINFO_EHDR)
+  // Try the executable first.
+  int rc = cb(&exe_info, sizeof(exe_info), data);
+  if (rc != 0) {
+    return rc;
+  }
+
+  // Try the VDSO if that didn't work.
+  ElfW(Ehdr)* ehdr_vdso = reinterpret_cast<ElfW(Ehdr)*>(getauxval(AT_SYSINFO_EHDR));
+  struct dl_phdr_info vdso_info;
+  vdso_info.dlpi_addr = 0;
+  vdso_info.dlpi_name = NULL;
+  vdso_info.dlpi_phdr = reinterpret_cast<ElfW(Phdr)*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff);
+  vdso_info.dlpi_phnum = ehdr_vdso->e_phnum;
+  for (size_t i = 0; i < vdso_info.dlpi_phnum; ++i) {
+    if (vdso_info.dlpi_phdr[i].p_type == PT_LOAD) {
+      vdso_info.dlpi_addr = (ElfW(Addr)) ehdr_vdso - vdso_info.dlpi_phdr[i].p_vaddr;
+      break;
+    }
+  }
+  return cb(&vdso_info, sizeof(vdso_info), data);
+#else
+  // There's only the executable to try.
+  return cb(&exe_info, sizeof(exe_info), data);
+#endif
+}
diff --git a/libc/bionic/dlmalloc.c b/libc/bionic/dlmalloc.c
index 66a825b..e89c5d1 100644
--- a/libc/bionic/dlmalloc.c
+++ b/libc/bionic/dlmalloc.c
@@ -16,7 +16,7 @@
 
 #include "dlmalloc.h"
 
-#include "private/bionic_name_mem.h"
+#include "private/bionic_prctl.h"
 #include "private/libc_logging.h"
 
 // Send dlmalloc errors to the log.
@@ -26,7 +26,7 @@
 #define CORRUPTION_ERROR_ACTION(m) __bionic_heap_corruption_error(__FUNCTION__)
 #define USAGE_ERROR_ACTION(m,p) __bionic_heap_usage_error(__FUNCTION__, p)
 
-/* Bionic named anonymous memory declarations */
+// Bionic named anonymous memory declarations.
 static void* named_anonymous_mmap(size_t length);
 #define MMAP(s) named_anonymous_mmap(s)
 #define DIRECT_MMAP(s) named_anonymous_mmap(s)
@@ -34,10 +34,7 @@
 // Ugly inclusion of C file so that bionic specific #defines configure dlmalloc.
 #include "../upstream-dlmalloc/malloc.c"
 
-extern void (*__cleanup)();
-
 static void __bionic_heap_corruption_error(const char* function) {
-  __cleanup = NULL; // The heap is corrupt. We can forget trying to shut down stdio.
   __libc_fatal("heap corruption detected by %s", function);
 }
 
@@ -49,14 +46,11 @@
   *((int**) 0xdeadbaad) = (int*) address;
 }
 
-static void* named_anonymous_mmap(size_t length)
-{
-    void* ret;
-    ret = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-    if (ret == MAP_FAILED)
-        return ret;
-
-    __bionic_name_mem(ret, length, "libc_malloc");
-
-    return ret;
+static void* named_anonymous_mmap(size_t length) {
+  void* map = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  if (map == MAP_FAILED) {
+    return map;
+  }
+  prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, map, length, "libc_malloc");
+  return map;
 }
diff --git a/libc/bionic/dlmalloc.h b/libc/bionic/dlmalloc.h
index 71b3be8..ef78814 100644
--- a/libc/bionic/dlmalloc.h
+++ b/libc/bionic/dlmalloc.h
@@ -17,6 +17,9 @@
 #ifndef LIBC_BIONIC_DLMALLOC_H_
 #define LIBC_BIONIC_DLMALLOC_H_
 
+#include <sys/cdefs.h>
+#include <stddef.h>
+
 /* Configure dlmalloc. */
 #define HAVE_GETPAGESIZE 1
 #define MALLOC_INSPECT_ALL 1
@@ -29,6 +32,21 @@
 #define USE_SPIN_LOCKS 0
 #define DEFAULT_MMAP_THRESHOLD (64U * 1024U)
 
+#define malloc_getpagesize getpagesize()
+
+/* dlmalloc_usable_size was exposed in the NDK, so change the name
+ * of the function on 32 bit architectures.
+ */
+#if !defined(__LP64__)
+#define dlmalloc_usable_size dlmalloc_usable_size_real
+#endif
+
+/* Export two symbols used by the VM. */
+__BEGIN_DECLS
+int dlmalloc_trim(size_t) __LIBC_ABI_PUBLIC__;
+void dlmalloc_inspect_all(void (*handler)(void*, void*, size_t, void*), void*) __LIBC_ABI_PUBLIC__;
+__END_DECLS
+
 /* Include the proper definitions. */
 #include "../upstream-dlmalloc/malloc.h"
 
diff --git a/libc/bionic/fdprintf.c b/libc/bionic/fdprintf.c
deleted file mode 100644
index c1d05ad..0000000
--- a/libc/bionic/fdprintf.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-int vfdprintf(int fd, const char * __restrict format, __va_list ap)
-{
-	char *buf=0;
-	int ret;
-	ret = vasprintf(&buf, format, ap);
-	if (ret < 0)
-		goto end;
-
-	ret = write(fd, buf, ret);
-	free(buf);
-end:
-	return ret;
-}
-
-int fdprintf(int fd, const char * __restrict format, ...)
-{
-	__va_list ap;
-	int ret;
-
-	va_start(ap, format);
-	ret = vfdprintf(fd, format, ap);
-	va_end(ap);
-
-	return ret;
-}
diff --git a/libc/bionic/flockfile.c b/libc/bionic/flockfile.c
deleted file mode 100644
index 368fb15..0000000
--- a/libc/bionic/flockfile.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* implement flockfile(), ftrylockfile() and funlockfile()
- *
- * we can't use the OpenBSD implementation which uses kernel-specific
- * APIs not available on Linux.
- *
- * Instead, we use a pthread_mutex_t within the FILE* internal state.
- * See fileext.h for details.
- *
- * the behaviour, if fclose() is called while the corresponding
- * file is locked is totally undefined.
- */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include "fileext.h"
-
-
-void
-flockfile(FILE * fp)
-{
-    if (fp != NULL) {
-        _FLOCK_LOCK(fp);
-    }
-}
-
-
-int
-ftrylockfile(FILE *fp)
-{
-    /* The specification for ftrylockfile() says it returns 0 on success,
-     * or non-zero on error. So return an errno code directly on error.
-     */
-    int  ret = EINVAL;
-
-    if (fp != NULL) {
-        ret = _FLOCK_TRYLOCK(fp);
-    }
-    return ret;
-}
-
-void
-funlockfile(FILE * fp)
-{
-    if (fp != NULL) {
-        _FLOCK_UNLOCK(fp);
-    }
-}
diff --git a/libc/bionic/flockfile.cpp b/libc/bionic/flockfile.cpp
new file mode 100644
index 0000000..3381e8e
--- /dev/null
+++ b/libc/bionic/flockfile.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+
+#include "local.h"
+
+// We can't use the OpenBSD implementation which uses kernel-specific
+// APIs not available on Linux. Instead we use a pthread_mutex_t within
+// struct __sfileext (see fileext.h).
+
+void flockfile(FILE* fp) {
+  if (fp != NULL) {
+    pthread_mutex_lock(&_FLOCK(fp));
+  }
+}
+
+int ftrylockfile(FILE* fp) {
+  // The specification for ftrylockfile() says it returns 0 on success,
+  // or non-zero on error. So return an errno code directly on error.
+  if (fp == NULL) {
+    return EINVAL;
+  }
+
+  return pthread_mutex_trylock(&_FLOCK(fp));
+}
+
+void funlockfile(FILE* fp) {
+  if (fp != NULL) {
+    pthread_mutex_unlock(&_FLOCK(fp));
+  }
+}
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp
index 9fa5fcf..6cfc736 100644
--- a/libc/bionic/fork.cpp
+++ b/libc/bionic/fork.cpp
@@ -29,28 +29,28 @@
 #include <unistd.h>
 #include <sys/syscall.h>
 
-#include "private/libc_logging.h"
 #include "pthread_internal.h"
 
+#define FORK_FLAGS (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD)
+
 int fork() {
-  // POSIX mandates that the timers of a fork child process be
-  // disarmed, but not destroyed. To avoid a race condition, we're
-  // going to stop all timers now, and only re-start them in case
-  // of error, or in the parent process
-  __timer_table_start_stop(1);
   __bionic_atfork_run_prepare();
 
   pthread_internal_t* self = __get_thread();
-  int flags = CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD;
+
+  // Remember the parent pid and invalidate the cached value while we fork.
+  pid_t parent_pid = self->invalidate_cached_pid();
+
 #if defined(__x86_64__) // sys_clone's last two arguments are flipped on x86-64.
-  int result = syscall(__NR_clone, flags, NULL, NULL, &(self->tid), NULL);
+  int result = syscall(__NR_clone, FORK_FLAGS, NULL, NULL, &(self->tid), NULL);
 #else
-  int result = syscall(__NR_clone, flags, NULL, NULL, NULL, &(self->tid));
+  int result = syscall(__NR_clone, FORK_FLAGS, NULL, NULL, NULL, &(self->tid));
 #endif
   if (result == 0) {
+    self->set_cached_pid(gettid());
     __bionic_atfork_run_child();
   } else {
-    __timer_table_start_stop(0);
+    self->set_cached_pid(parent_pid);
     __bionic_atfork_run_parent();
   }
   return result;
diff --git a/libc/bionic/fpclassify.cpp b/libc/bionic/fpclassify.cpp
new file mode 100644
index 0000000..21ff946
--- /dev/null
+++ b/libc/bionic/fpclassify.cpp
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <math.h>
+#include <machine/ieee.h>
+
+// These aren't declared in our <math.h>.
+extern "C" int __isinf(double);
+extern "C" int __isnan(double);
+
+union float_u {
+  float f;
+  ieee_single bits;
+};
+
+union double_u {
+  double d;
+  ieee_double bits;
+};
+
+int __fpclassifyd(double d) {
+  double_u u;
+  u.d = d;
+  if (u.bits.dbl_exp == 0) {
+    return ((u.bits.dbl_fracl | u.bits.dbl_frach) == 0) ? FP_ZERO : FP_SUBNORMAL;
+  }
+  if (u.bits.dbl_exp == DBL_EXP_INFNAN) {
+    return ((u.bits.dbl_fracl | u.bits.dbl_frach) == 0) ? FP_INFINITE : FP_NAN;
+  }
+  return FP_NORMAL;
+}
+__strong_alias(__fpclassify, __fpclassifyd); // glibc uses __fpclassify, BSD __fpclassifyd.
+
+int __fpclassifyf(float f) {
+  float_u u;
+  u.f = f;
+  if (u.bits.sng_exp == 0) {
+    return (u.bits.sng_frac == 0) ? FP_ZERO : FP_SUBNORMAL;
+  }
+  if (u.bits.sng_exp == SNG_EXP_INFNAN) {
+    return (u.bits.sng_frac == 0) ? FP_INFINITE : FP_NAN;
+  }
+  return FP_NORMAL;
+}
+
+int __isinf(double d) {
+  return (__fpclassifyd(d) == FP_INFINITE);
+}
+__strong_alias(isinf, __isinf);
+
+int __isinff(float f) {
+  return (__fpclassifyf(f) == FP_INFINITE);
+}
+__strong_alias(isinff, __isinff);
+
+int __isnan(double d) {
+  return (__fpclassifyd(d) == FP_NAN);
+}
+__strong_alias(isnan, __isnan);
+
+int __isnanf(float f) {
+  return (__fpclassifyf(f) == FP_NAN);
+}
+__strong_alias(isnanf, __isnanf);
+
+int __isfinite(double d) {
+  int type = __fpclassifyd(d);
+  return ((type != FP_NAN) && (type != FP_INFINITE));
+}
+__strong_alias(isfinite, __isfinite);
+
+int __isfinitef(float f) {
+  int type = __fpclassifyf(f);
+  return ((type != FP_NAN) && (type != FP_INFINITE));
+}
+__strong_alias(isfinitef, __isfinitef);
+
+int __isnormal(double d) {
+  return (__fpclassifyd(d) == FP_NORMAL);
+}
+__strong_alias(isnormal, __isnormal);
+
+int __isnormalf(float f) {
+  return (__fpclassifyf(f) == FP_NORMAL);
+}
+__strong_alias(isnormalf, __isnormalf);
+
+#if __LP64__
+
+// LP64 uses 128-bit long doubles.
+
+union long_double_u {
+  long double ld;
+  ieee_ext bits;
+};
+
+#define zero_frac(b) ((b.ext_fracl | b.ext_fraclm | b.ext_frachm | b.ext_frach) == 0)
+
+int __fpclassifyl(long double ld) {
+  long_double_u u;
+  u.ld = ld;
+  if (u.bits.ext_exp == 0) {
+    return zero_frac(u.bits) ? FP_ZERO : FP_SUBNORMAL;
+  }
+  if (u.bits.ext_exp == EXT_EXP_INFNAN) {
+    return zero_frac(u.bits) ? FP_INFINITE : FP_NAN;
+  }
+  return FP_NORMAL;
+}
+
+int __isinfl(long double ld) {
+  return (__fpclassifyl(ld) == FP_INFINITE);
+}
+
+int __isnanl(long double ld) {
+  return (__fpclassifyl(ld) == FP_NAN);
+}
+
+int __isfinitel(long double ld) {
+  int type = __fpclassifyl(ld);
+  return ((type != FP_NAN) && (type != FP_INFINITE));
+}
+
+int __isnormall(long double ld) {
+  return (__fpclassifyl(ld) == FP_NORMAL);
+}
+
+#else
+
+// LP32 uses double as long double.
+
+__strong_alias(__fpclassifyl, __fpclassify);
+__strong_alias(__isinfl, __isinf);
+__strong_alias(__isnanl, __isnan);
+__strong_alias(__isfinitel, __isfinite);
+__strong_alias(__isnormall, __isnormal);
+
+#endif
+
+__strong_alias(isinfl, __isinfl);
+__strong_alias(isnanl, __isnanl);
+__strong_alias(isfinitel, __isfinitel);
+__strong_alias(isnormall, __isnormall);
diff --git a/libc/bionic/ftime.c b/libc/bionic/ftime.c
deleted file mode 100644
index 6513593..0000000
--- a/libc/bionic/ftime.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <sys/timeb.h>
-
-int ftime(struct timeb *tb)
-{
-    struct timeval  tv;
-    struct timezone tz;
-
-    if (gettimeofday (&tv, &tz) < 0)
-        return -1;
-
-    tb->time    = tv.tv_sec;
-    tb->millitm = (tv.tv_usec + 500) / 1000;
-
-    if (tb->millitm == 1000) {
-        ++tb->time;
-        tb->millitm = 0;
-    }
-    tb->timezone = tz.tz_minuteswest;
-    tb->dstflag  = tz.tz_dsttime;
-
-    return 0;
-}
diff --git a/libc/bionic/ftok.c b/libc/bionic/ftok.c
deleted file mode 100644
index 638bd0a..0000000
--- a/libc/bionic/ftok.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <unistd.h>
-#include <sys/ipc.h>
-#include <sys/stat.h>
-
-key_t  ftok(const char*  path, int  id)
-{
-    struct stat   st;
-
-    if ( lstat(path, &st) < 0 )
-        return -1;
-
-    return (key_t)( (st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 255) << 24) );
-}
diff --git a/libc/bionic/fts.c b/libc/bionic/fts.c
index c7770b6..c491b6a 100644
--- a/libc/bionic/fts.c
+++ b/libc/bionic/fts.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fts.c,v 1.43 2009/08/27 16:19:27 millert Exp $	*/
+/*	$OpenBSD: fts.c,v 1.46 2014/05/25 17:47:04 tedu Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -36,12 +36,11 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <fts.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-#define MAX(a,b) ((a)>(b)?(a):(b))
-
 static FTSENT	*fts_alloc(FTS *, char *, size_t);
 static FTSENT	*fts_build(FTS *, int);
 static void	 fts_lfree(FTSENT *);
@@ -53,6 +52,9 @@
 static u_short	 fts_stat(FTS *, FTSENT *, int);
 static int	 fts_safe_changedir(FTS *, FTSENT *, int, char *);
 
+#define ALIGNBYTES (sizeof(uintptr_t) - 1)
+#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
+
 #define	ISDOT(a)	(a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
 
 #define	CLR(opt)	(sp->fts_options &= ~(opt))
@@ -96,7 +98,7 @@
 	 * Start out with 1K of path space, and enough, in any case,
 	 * to hold the user's paths.
 	 */
-	if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
+	if (fts_palloc(sp, MAX(fts_maxarglen(argv), PATH_MAX)))
 		goto mem1;
 
 	/* Allocate/initialize root's parent. */
@@ -446,7 +448,7 @@
  */
 /* ARGSUSED */
 int
-fts_set(FTS *sp, FTSENT *p, int instr)
+fts_set(FTS *sp __unused, FTSENT *p, int instr)
 {
 	if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
 	    instr != FTS_NOINSTR && instr != FTS_SKIP) {
@@ -636,7 +638,7 @@
 	maxlen = sp->fts_pathlen - len;
 
 	/*
-	 * fts_level is a short so we must prevent it from wrapping
+	 * fts_level is signed so we must prevent it from wrapping
 	 * around to FTS_ROOTLEVEL and FTS_ROOTPARENTLEVEL.
 	 */
 	level = cur->fts_level;
@@ -907,10 +909,9 @@
 	len = sizeof(FTSENT) + namelen;
 	if (!ISSET(FTS_NOSTAT))
 		len += sizeof(struct stat) + ALIGNBYTES;
-	if ((p = malloc(len)) == NULL)
+	if ((p = calloc(1, len)) == NULL)
 		return (NULL);
 
-	memset(p, 0, len);
 	p->fts_path = sp->fts_path;
 	p->fts_namelen = namelen;
 	p->fts_instr = FTS_NOINSTR;
@@ -935,7 +936,7 @@
 
 /*
  * Allow essentially unlimited paths; find, rm, ls should all work on any tree.
- * Most systems will allow creation of paths much longer than MAXPATHLEN, even
+ * Most systems will allow creation of paths much longer than PATH_MAX, even
  * though the kernel won't resolve them.  Add the size (not just what's needed)
  * plus 256 bytes so don't realloc the path 2 bytes at a time.
  */
diff --git a/libc/bionic/getauxval.cpp b/libc/bionic/getauxval.cpp
index 3ee31d6..bc41824 100644
--- a/libc/bionic/getauxval.cpp
+++ b/libc/bionic/getauxval.cpp
@@ -32,10 +32,10 @@
 #include <private/bionic_auxv.h>
 #include <elf.h>
 
-__LIBC_HIDDEN__ Elf_auxv_t* __libc_auxv = NULL;
+__LIBC_HIDDEN__ ElfW(auxv_t)* __libc_auxv = NULL;
 
 extern "C" unsigned long int getauxval(unsigned long int type) {
-  for (Elf_auxv_t* v = __libc_auxv; v->a_type != AT_NULL; ++v) {
+  for (ElfW(auxv_t)* v = __libc_auxv; v->a_type != AT_NULL; ++v) {
     if (v->a_type == type) {
       return v->a_un.a_val;
     }
diff --git a/libc/bionic/getdtablesize.c b/libc/bionic/getdtablesize.c
deleted file mode 100644
index 91315a5..0000000
--- a/libc/bionic/getdtablesize.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <sys/resource.h>
-#include <sys/sysconf.h>
-
-int getdtablesize()
-{
-    struct rlimit r;
-
-    if (getrlimit(RLIMIT_NOFILE, &r) < 0) {
-        return sysconf(_SC_OPEN_MAX);
-    }
-    return r.rlim_cur;
-}
diff --git a/libc/bionic/getentropy_linux.c b/libc/bionic/getentropy_linux.c
new file mode 100644
index 0000000..409bd7d
--- /dev/null
+++ b/libc/bionic/getentropy_linux.c
@@ -0,0 +1,565 @@
+/*	$OpenBSD: getentropy_linux.c,v 1.28 2014/07/20 03:24:10 deraadt Exp $	*/
+
+/*
+ * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
+ * Copyright (c) 2014 Bob Beck <beck@obtuse.com>
+ *
+ * Permission to use, copy, modify, and 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.
+ *
+ * Emulation of getentropy(2) as documented at:
+ * http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2
+ */
+
+#define	_POSIX_C_SOURCE	199309L
+#define	_GNU_SOURCE	1
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#ifdef HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
+#include <sys/statvfs.h>
+#include <sys/socket.h>
+#include <sys/mount.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <link.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <time.h>
+#ifdef HAVE_OPENSSL
+#include <openssl/sha.h>
+#endif
+
+#include <linux/random.h>
+#include <linux/sysctl.h>
+#ifdef HAVE_GETAUXVAL
+#include <sys/auxv.h>
+#endif
+#include <sys/vfs.h>
+
+#define REPEAT 5
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+
+#define HX(a, b) \
+	do { \
+		if ((a)) \
+			HD(errno); \
+		else \
+			HD(b); \
+	} while (0)
+
+#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
+#define HD(x)	 (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
+#define HF(x)    (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
+
+int	getentropy(void *buf, size_t len);
+
+static int gotdata(char *buf, size_t len);
+#ifdef SYS__getrandom
+static int getentropy_getrandom(void *buf, size_t len);
+#endif
+static int getentropy_urandom(void *buf, size_t len);
+#ifdef SYS__sysctl
+static int getentropy_sysctl(void *buf, size_t len);
+#endif
+#ifdef HAVE_OPENSSL
+static int getentropy_fallback(void *buf, size_t len);
+static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data);
+#endif
+
+int
+getentropy(void *buf, size_t len)
+{
+	int ret = -1;
+
+	if (len > 256) {
+		errno = EIO;
+		return -1;
+	}
+
+#ifdef SYS__getrandom
+	/*
+	 * Try descriptor-less getrandom()
+	 */
+	ret = getentropy_getrandom(buf, len);
+	if (ret != -1)
+		return (ret);
+#endif
+
+	/*
+	 * Try to get entropy with /dev/urandom
+	 *
+	 * This can fail if the process is inside a chroot or if file
+	 * descriptors are exhausted.
+	 */
+	ret = getentropy_urandom(buf, len);
+	if (ret != -1)
+		return (ret);
+
+#ifdef SYS__sysctl
+	/*
+	 * Try to use sysctl CTL_KERN, KERN_RANDOM, RANDOM_UUID.
+	 * sysctl is a failsafe API, so it guarantees a result.  This
+	 * should work inside a chroot, or when file descriptors are
+	 * exhuasted.
+	 *
+	 * However this can fail if the Linux kernel removes support
+	 * for sysctl.  Starting in 2007, there have been efforts to
+	 * deprecate the sysctl API/ABI, and push callers towards use
+	 * of the chroot-unavailable fd-using /proc mechanism --
+	 * essentially the same problems as /dev/urandom.
+	 *
+	 * Numerous setbacks have been encountered in their deprecation
+	 * schedule, so as of June 2014 the kernel ABI still exists on
+	 * most Linux architectures. The sysctl() stub in libc is missing
+	 * on some systems.  There are also reports that some kernels
+	 * spew messages to the console.
+	 */
+	ret = getentropy_sysctl(buf, len);
+	if (ret != -1)
+		return (ret);
+#endif /* SYS__sysctl */
+
+	/*
+	 * Entropy collection via /dev/urandom and sysctl have failed.
+	 *
+	 * No other API exists for collecting entropy.  See the large
+	 * comment block above.
+	 *
+	 * We have very few options:
+	 *     - Even syslog_r is unsafe to call at this low level, so
+	 *	 there is no way to alert the user or program.
+	 *     - Cannot call abort() because some systems have unsafe
+	 *	 corefiles.
+	 *     - Could raise(SIGKILL) resulting in silent program termination.
+	 *     - Return EIO, to hint that arc4random's stir function
+	 *       should raise(SIGKILL)
+	 *     - Do the best under the circumstances....
+	 *
+	 * This code path exists to bring light to the issue that Linux
+	 * does not provide a failsafe API for entropy collection.
+	 *
+	 * We hope this demonstrates that Linux should either retain their
+	 * sysctl ABI, or consider providing a new failsafe API which
+	 * works in a chroot or when file descriptors are exhausted.
+	 */
+#undef FAIL_INSTEAD_OF_TRYING_FALLBACK
+#ifdef FAIL_INSTEAD_OF_TRYING_FALLBACK
+	raise(SIGKILL);
+#endif
+#ifdef HAVE_OPENSSL
+	ret = getentropy_fallback(buf, len);
+	if (ret != -1)
+		return (ret);
+#endif
+
+	errno = EIO;
+	return (ret);
+}
+
+/*
+ * Basic sanity checking; wish we could do better.
+ */
+static int
+gotdata(char *buf, size_t len)
+{
+	char	any_set = 0;
+	size_t	i;
+
+	for (i = 0; i < len; ++i)
+		any_set |= buf[i];
+	if (any_set == 0)
+		return -1;
+	return 0;
+}
+
+#ifdef SYS__getrandom
+static int
+getentropy_getrandom(void *buf, size_t len)
+{
+#if 0
+
+/* Hand-definitions until the API becomes commonplace */
+#ifndef SYS__getrandom
+#ifdef __LP64__
+#define SYS__getrandom 317
+#else
+#define SYS__getrandom 354
+#endif
+#endif
+	struct __getrandom_args args = {
+		.buf = buf;
+		.len = len;
+		.flags = 0;
+	};
+
+	if (len > 256)
+		return (-1);
+	ret = syscall(SYS__getrandom, &args);
+	if (ret == len)
+		return (0);
+#endif
+	return -1;
+}
+#endif
+
+static int
+getentropy_urandom(void *buf, size_t len)
+{
+	struct stat st;
+	size_t i;
+	int fd, cnt, flags;
+	int save_errno = errno;
+
+start:
+
+	flags = O_RDONLY;
+#ifdef O_NOFOLLOW
+	flags |= O_NOFOLLOW;
+#endif
+#ifdef O_CLOEXEC
+	flags |= O_CLOEXEC;
+#endif
+	fd = open("/dev/urandom", flags, 0);
+	if (fd == -1) {
+		if (errno == EINTR)
+			goto start;
+		goto nodevrandom;
+	}
+#ifndef O_CLOEXEC
+	fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+#endif
+
+	/* Lightly verify that the device node looks sane */
+	if (fstat(fd, &st) == -1 || !S_ISCHR(st.st_mode)) {
+		close(fd);
+		goto nodevrandom;
+	}
+	if (ioctl(fd, RNDGETENTCNT, &cnt) == -1) {
+		close(fd);
+		goto nodevrandom;
+	}
+	for (i = 0; i < len; ) {
+		size_t wanted = len - i;
+		ssize_t ret = read(fd, (char *)buf + i, wanted);
+
+		if (ret == -1) {
+			if (errno == EAGAIN || errno == EINTR)
+				continue;
+			close(fd);
+			goto nodevrandom;
+		}
+		i += ret;
+	}
+	close(fd);
+	if (gotdata(buf, len) == 0) {
+		errno = save_errno;
+		return 0;		/* satisfied */
+	}
+nodevrandom:
+	errno = EIO;
+	return -1;
+}
+
+#ifdef SYS__sysctl
+static int
+getentropy_sysctl(void *buf, size_t len)
+{
+	static int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID };
+	size_t i;
+	int save_errno = errno;
+
+	for (i = 0; i < len; ) {
+		size_t chunk = min(len - i, 16);
+
+		/* SYS__sysctl because some systems already removed sysctl() */
+		struct __sysctl_args args = {
+			.name = mib,
+			.nlen = 3,
+			.oldval = (char*) buf + i,
+			.oldlenp = &chunk,
+		};
+		if (syscall(SYS__sysctl, &args) != 0)
+			goto sysctlfailed;
+		i += chunk;
+	}
+	if (gotdata(buf, len) == 0) {
+		errno = save_errno;
+		return (0);			/* satisfied */
+	}
+sysctlfailed:
+	errno = EIO;
+	return -1;
+}
+#endif /* SYS__sysctl */
+
+#ifdef HAVE_OPENSSL
+
+static int cl[] = {
+	CLOCK_REALTIME,
+#ifdef CLOCK_MONOTONIC
+	CLOCK_MONOTONIC,
+#endif
+#ifdef CLOCK_MONOTONIC_RAW
+	CLOCK_MONOTONIC_RAW,
+#endif
+#ifdef CLOCK_TAI
+	CLOCK_TAI,
+#endif
+#ifdef CLOCK_VIRTUAL
+	CLOCK_VIRTUAL,
+#endif
+#ifdef CLOCK_UPTIME
+	CLOCK_UPTIME,
+#endif
+#ifdef CLOCK_PROCESS_CPUTIME_ID
+	CLOCK_PROCESS_CPUTIME_ID,
+#endif
+#ifdef CLOCK_THREAD_CPUTIME_ID
+	CLOCK_THREAD_CPUTIME_ID,
+#endif
+};
+
+static int
+getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data)
+{
+	SHA512_CTX *ctx = data;
+
+	SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr));
+	return 0;
+}
+
+static int
+getentropy_fallback(void *buf, size_t len)
+{
+	uint8_t results[SHA512_DIGEST_LENGTH];
+	int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat;
+	static int cnt;
+	struct timespec ts;
+	struct timeval tv;
+	struct rusage ru;
+	sigset_t sigset;
+	struct stat st;
+	SHA512_CTX ctx;
+	static pid_t lastpid;
+	pid_t pid;
+	size_t i, ii, m;
+	char *p;
+
+	pid = getpid();
+	if (lastpid == pid) {
+		faster = 1;
+		repeat = 2;
+	} else {
+		faster = 0;
+		lastpid = pid;
+		repeat = REPEAT;
+	}
+	for (i = 0; i < len; ) {
+		int j;
+		SHA512_Init(&ctx);
+		for (j = 0; j < repeat; j++) {
+			HX((e = gettimeofday(&tv, NULL)) == -1, tv);
+			if (e != -1) {
+				cnt += (int)tv.tv_sec;
+				cnt += (int)tv.tv_usec;
+			}
+
+			dl_iterate_phdr(getentropy_phdr, &ctx);
+
+			for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++)
+				HX(clock_gettime(cl[ii], &ts) == -1, ts);
+
+			HX((pid = getpid()) == -1, pid);
+			HX((pid = getsid(pid)) == -1, pid);
+			HX((pid = getppid()) == -1, pid);
+			HX((pid = getpgid(0)) == -1, pid);
+			HX((e = getpriority(0, 0)) == -1, e);
+
+			if (!faster) {
+				ts.tv_sec = 0;
+				ts.tv_nsec = 1;
+				(void) nanosleep(&ts, NULL);
+			}
+
+			HX(sigpending(&sigset) == -1, sigset);
+			HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1,
+			    sigset);
+
+			HF(getentropy);	/* an addr in this library */
+			HF(printf);		/* an addr in libc */
+			p = (char *)&p;
+			HD(p);		/* an addr on stack */
+			p = (char *)&errno;
+			HD(p);		/* the addr of errno */
+
+			if (i == 0) {
+				struct sockaddr_storage ss;
+				struct statvfs stvfs;
+				struct termios tios;
+				struct statfs stfs;
+				socklen_t ssl;
+				off_t off;
+
+				/*
+				 * Prime-sized mappings encourage fragmentation;
+				 * thus exposing some address entropy.
+				 */
+				struct mm {
+					size_t	npg;
+					void	*p;
+				} mm[] =	 {
+					{ 17, MAP_FAILED }, { 3, MAP_FAILED },
+					{ 11, MAP_FAILED }, { 2, MAP_FAILED },
+					{ 5, MAP_FAILED }, { 3, MAP_FAILED },
+					{ 7, MAP_FAILED }, { 1, MAP_FAILED },
+					{ 57, MAP_FAILED }, { 3, MAP_FAILED },
+					{ 131, MAP_FAILED }, { 1, MAP_FAILED },
+				};
+
+				for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) {
+					HX(mm[m].p = mmap(NULL,
+					    mm[m].npg * pgs,
+					    PROT_READ|PROT_WRITE,
+					    MAP_PRIVATE|MAP_ANON, -1,
+					    (off_t)0), mm[m].p);
+					if (mm[m].p != MAP_FAILED) {
+						size_t mo;
+
+						/* Touch some memory... */
+						p = mm[m].p;
+						mo = cnt %
+						    (mm[m].npg * pgs - 1);
+						p[mo] = 1;
+						cnt += (int)((long)(mm[m].p)
+						    / pgs);
+					}
+
+					/* Check cnts and times... */
+					for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]);
+					    ii++) {
+						HX((e = clock_gettime(cl[ii],
+						    &ts)) == -1, ts);
+						if (e != -1)
+							cnt += (int)ts.tv_nsec;
+					}
+
+					HX((e = getrusage(RUSAGE_SELF,
+					    &ru)) == -1, ru);
+					if (e != -1) {
+						cnt += (int)ru.ru_utime.tv_sec;
+						cnt += (int)ru.ru_utime.tv_usec;
+					}
+				}
+
+				for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) {
+					if (mm[m].p != MAP_FAILED)
+						munmap(mm[m].p, mm[m].npg * pgs);
+					mm[m].p = MAP_FAILED;
+				}
+
+				HX(stat(".", &st) == -1, st);
+				HX(statvfs(".", &stvfs) == -1, stvfs);
+				HX(statfs(".", &stfs) == -1, stfs);
+
+				HX(stat("/", &st) == -1, st);
+				HX(statvfs("/", &stvfs) == -1, stvfs);
+				HX(statfs("/", &stfs) == -1, stfs);
+
+				HX((e = fstat(0, &st)) == -1, st);
+				if (e == -1) {
+					if (S_ISREG(st.st_mode) ||
+					    S_ISFIFO(st.st_mode) ||
+					    S_ISSOCK(st.st_mode)) {
+						HX(fstatvfs(0, &stvfs) == -1,
+						    stvfs);
+						HX(fstatfs(0, &stfs) == -1,
+						    stfs);
+						HX((off = lseek(0, (off_t)0,
+						    SEEK_CUR)) < 0, off);
+					}
+					if (S_ISCHR(st.st_mode)) {
+						HX(tcgetattr(0, &tios) == -1,
+						    tios);
+					} else if (S_ISSOCK(st.st_mode)) {
+						memset(&ss, 0, sizeof ss);
+						ssl = sizeof(ss);
+						HX(getpeername(0,
+						    (void *)&ss, &ssl) == -1,
+						    ss);
+					}
+				}
+
+				HX((e = getrusage(RUSAGE_CHILDREN,
+				    &ru)) == -1, ru);
+				if (e != -1) {
+					cnt += (int)ru.ru_utime.tv_sec;
+					cnt += (int)ru.ru_utime.tv_usec;
+				}
+			} else {
+				/* Subsequent hashes absorb previous result */
+				HD(results);
+			}
+
+			HX((e = gettimeofday(&tv, NULL)) == -1, tv);
+			if (e != -1) {
+				cnt += (int)tv.tv_sec;
+				cnt += (int)tv.tv_usec;
+			}
+
+			HD(cnt);
+		}
+#ifdef HAVE_GETAUXVAL
+#ifdef AT_RANDOM
+		/* Not as random as you think but we take what we are given */
+		p = (char *) getauxval(AT_RANDOM);
+		if (p)
+			HR(p, 16);
+#endif
+#ifdef AT_SYSINFO_EHDR
+		p = (char *) getauxval(AT_SYSINFO_EHDR);
+		if (p)
+			HR(p, pgs);
+#endif
+#ifdef AT_BASE
+		p = (char *) getauxval(AT_BASE);
+		if (p)
+			HD(p);
+#endif
+#endif
+
+		SHA512_Final(results, &ctx);
+		memcpy((char *)buf + i, results, min(sizeof(results), len - i));
+		i += min(sizeof(results), len - i);
+	}
+	memset(results, 0, sizeof results);
+	if (gotdata(buf, len) == 0) {
+		errno = save_errno;
+		return 0;		/* satisfied */
+	}
+	errno = EIO;
+	return -1;
+}
+
+#endif /* HAVE_OPENSSL */
diff --git a/libc/bionic/getpgrp.c b/libc/bionic/getpgrp.c
deleted file mode 100644
index af7ced5..0000000
--- a/libc/bionic/getpgrp.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <unistd.h>
-
-pid_t  getpgrp(void) 
-{
-  return getpgid(0);
-}
diff --git a/libc/bionic/getpgrp.cpp b/libc/bionic/getpgrp.cpp
new file mode 100644
index 0000000..9bacbb3
--- /dev/null
+++ b/libc/bionic/getpgrp.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+pid_t getpgrp() {
+  return getpgid(0);
+}
diff --git a/libc/bionic/getpid.cpp b/libc/bionic/getpid.cpp
new file mode 100644
index 0000000..a3d5b35
--- /dev/null
+++ b/libc/bionic/getpid.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+#include "pthread_internal.h"
+
+extern "C" pid_t __getpid();
+
+pid_t getpid() {
+  pthread_internal_t* self = __get_thread();
+
+  // Do we have a valid cached pid?
+  pid_t cached_pid;
+  if (__predict_true(self->get_cached_pid(&cached_pid))) {
+    return cached_pid;
+  }
+
+  // We're still in the dynamic linker or we're in the middle of forking, so ask the kernel.
+  // We don't know whether it's safe to update the cached value, so don't try.
+  return __getpid();
+}
diff --git a/libc/bionic/getpt.c b/libc/bionic/getpt.c
deleted file mode 100644
index 8bb5c11..0000000
--- a/libc/bionic/getpt.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <unistd.h>
-#include <fcntl.h>
-
-int getpt(void)
-{
-  return open("/dev/ptmx", O_RDWR|O_NOCTTY);
-}
diff --git a/libc/bionic/gettid.cpp b/libc/bionic/gettid.cpp
new file mode 100644
index 0000000..f42e36a
--- /dev/null
+++ b/libc/bionic/gettid.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+#include "pthread_internal.h"
+
+pid_t gettid() {
+  return __get_thread()->tid;
+}
diff --git a/libc/bionic/if_indextoname.c b/libc/bionic/if_indextoname.c
index dc08b28..f0db512 100644
--- a/libc/bionic/if_indextoname.c
+++ b/libc/bionic/if_indextoname.c
@@ -41,7 +41,6 @@
 char*
 if_indextoname(unsigned ifindex, char *ifname)
 {
-    int index;
     int ctl_sock;
     struct ifreq ifr;
     char*  ret = NULL;
diff --git a/libc/bionic/issetugid.c b/libc/bionic/issetugid.c
deleted file mode 100644
index 81f8e41..0000000
--- a/libc/bionic/issetugid.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <unistd.h>
-
-int  issetugid(void)
-{
-    /* for Bionic, this is sufficient */
-    return 0;
-}
-
diff --git a/libc/bionic/jemalloc.h b/libc/bionic/jemalloc.h
new file mode 100644
index 0000000..feb1f43
--- /dev/null
+++ b/libc/bionic/jemalloc.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LIBC_BIONIC_JEMALLOC_H_
+#define LIBC_BIONIC_JEMALLOC_H_
+
+#include <jemalloc/jemalloc.h>
+
+// Need to wrap memalign since je_memalign fails on non-power of 2 alignments.
+#define je_memalign je_memalign_round_up_boundary
+
+__BEGIN_DECLS
+
+struct mallinfo je_mallinfo();
+void* je_memalign_round_up_boundary(size_t, size_t);
+void* je_pvalloc(size_t);
+
+__END_DECLS
+
+#endif  // LIBC_BIONIC_DLMALLOC_H_
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp
new file mode 100644
index 0000000..e33d560
--- /dev/null
+++ b/libc/bionic/jemalloc_wrapper.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/param.h>
+#include <unistd.h>
+
+#include "jemalloc.h"
+#include "private/bionic_macros.h"
+
+void* je_pvalloc(size_t bytes) {
+  size_t pagesize = getpagesize();
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) {
+    return NULL;
+  }
+  return je_memalign(pagesize, size);
+}
+
+#ifdef je_memalign
+#undef je_memalign
+#endif
+
+// The man page for memalign says it fails if boundary is not a power of 2,
+// but this is not true. Both glibc and dlmalloc round up to the next power
+// of 2, so we'll do the same.
+void* je_memalign_round_up_boundary(size_t boundary, size_t size) {
+  if (boundary != 0) {
+    if (!powerof2(boundary)) {
+      boundary = BIONIC_ROUND_UP_POWER_OF_2(boundary);
+    }
+  } else {
+    boundary = 1;
+  }
+  return je_memalign(boundary, size);
+}
diff --git a/libc/bionic/ldexp.c b/libc/bionic/ldexp.c
deleted file mode 100644
index ec1f3dd..0000000
--- a/libc/bionic/ldexp.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/* @(#)s_scalbn.c 5.1 93/09/24 */
-/* @(#)fdlibm.h 5.1 93/09/24 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-#include <sys/cdefs.h>
-
-#include <sys/types.h>
-#include <endian.h>
-#include <math.h>
-
-/* Bit fiddling routines copied from msun/src/math_private.h,v 1.15 */
-
-#if BYTE_ORDER == BIG_ENDIAN
-
-typedef union
-{
-  double value;
-  struct
-  {
-    u_int32_t msw;
-    u_int32_t lsw;
-  } parts;
-} ieee_double_shape_type;
-
-#endif
-
-#if BYTE_ORDER == LITTLE_ENDIAN
-
-typedef union
-{
-  double value;
-  struct
-  {
-    u_int32_t lsw;
-    u_int32_t msw;
-  } parts;
-} ieee_double_shape_type;
-
-#endif
-
-/* Get two 32 bit ints from a double.  */
-
-#define EXTRACT_WORDS(ix0,ix1,d)				\
-do {								\
-  ieee_double_shape_type ew_u;					\
-  ew_u.value = (d);						\
-  (ix0) = ew_u.parts.msw;					\
-  (ix1) = ew_u.parts.lsw;					\
-} while (0)
-
-/* Get the more significant 32 bit int from a double.  */
-
-#define GET_HIGH_WORD(i,d)					\
-do {								\
-  ieee_double_shape_type gh_u;					\
-  gh_u.value = (d);						\
-  (i) = gh_u.parts.msw;						\
-} while (0)
-
-/* Set the more significant 32 bits of a double from an int.  */
-
-#define SET_HIGH_WORD(d,v)					\
-do {								\
-  ieee_double_shape_type sh_u;					\
-  sh_u.value = (d);						\
-  sh_u.parts.msw = (v);						\
-  (d) = sh_u.value;						\
-} while (0)
-
-
-static const double
-two54   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
-twom54  =  5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
-huge   = 1.0e+300,
-tiny   = 1.0e-300;
-
-static double
-_copysign(double x, double y)
-{
-	u_int32_t hx,hy;
-	GET_HIGH_WORD(hx,x);
-	GET_HIGH_WORD(hy,y);
-	SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
-	return x;
-}
-
-double
-ldexp(double x, int n)
-{
-	int32_t k,hx,lx;
-	EXTRACT_WORDS(hx,lx,x);
-        k = (hx&0x7ff00000)>>20;		/* extract exponent */
-        if (k==0) {				/* 0 or subnormal x */
-            if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
-	    x *= two54;
-	    GET_HIGH_WORD(hx,x);
-	    k = ((hx&0x7ff00000)>>20) - 54;
-            if (n< -50000) return tiny*x; 	/*underflow*/
-	    }
-        if (k==0x7ff) return x+x;		/* NaN or Inf */
-        k = k+n;
-        if (k >  0x7fe) return huge*_copysign(huge,x); /* overflow  */
-        if (k > 0) 				/* normal result */
-	    {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
-        if (k <= -54) {
-            if (n > 50000) 	/* in case integer overflow in n+k */
-		return huge*_copysign(huge,x);	/*overflow*/
-	    else return tiny*_copysign(tiny,x); 	/*underflow*/
-	}
-        k += 54;				/* subnormal result */
-	SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
-        return x*twom54;
-}
diff --git a/libc/bionic/legacy_32_bit_support.cpp b/libc/bionic/legacy_32_bit_support.cpp
index d7ccdb9..73f77be 100644
--- a/libc/bionic/legacy_32_bit_support.cpp
+++ b/libc/bionic/legacy_32_bit_support.cpp
@@ -27,6 +27,7 @@
  */
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdarg.h>
 #include <sys/resource.h>
 #include <sys/types.h>
@@ -58,11 +59,13 @@
 int fstatfs(int fd, struct statfs* stat) {
   return __fstatfs64(fd, sizeof(*stat), stat);
 }
+__strong_alias(fstatfs64, fstatfs);
 
 // For statfs we need to add the extra argument giving the kernel the size of the buffer.
 int statfs(const char* path, struct statfs* stat) {
   return __statfs64(path, sizeof(*stat), stat);
 }
+__strong_alias(statfs64, statfs);
 
 // For lseek64 we need to use the llseek system call which splits the off64_t in two and
 // returns the off64_t result via a pointer because 32-bit kernels can't return 64-bit results.
@@ -86,6 +89,11 @@
   return pwrite64(fd, buf, byte_count, static_cast<off64_t>(offset));
 }
 
+// There is no fallocate for 32-bit off_t, so we need to widen and call fallocate64.
+int fallocate(int fd, int mode, off_t offset, off_t length) {
+  return fallocate64(fd, mode, static_cast<off64_t>(offset), static_cast<off64_t>(length));
+}
+
 // There is no getrlimit64 system call, so we need to use prlimit64.
 int getrlimit64(int resource, rlimit64* limits64) {
   return prlimit64(0, resource, NULL, limits64);
diff --git a/libc/bionic/lfs64_support.cpp b/libc/bionic/lfs64_support.cpp
new file mode 100644
index 0000000..ab795f5
--- /dev/null
+++ b/libc/bionic/lfs64_support.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ftw.h>
+#include <stdlib.h>
+
+int mkstemp64(char* filename) {
+  // Delegation will work in this case because all the transitive dependencies
+  // are already 64-bit ready. In particular, we don't have non-O_LARGEFILE
+  // open (our open is actually open64) and stat and stat64 are the same.
+  return mkstemp(filename);
+}
+
+typedef int (*ftw_fn)(const char*, const struct stat*, int);
+typedef int (*nftw_fn)(const char*, const struct stat*, int, struct FTW*);
+
+int ftw64(const char *dirpath,
+    int (*fn)(const char*, const struct stat64*, int), int nopenfd) {
+  return ftw(dirpath, reinterpret_cast<ftw_fn>(fn), nopenfd);
+}
+
+int nftw64(const char * dirpath,
+    int (*fn)(const char*, const struct stat64*, int, struct FTW*),
+    int nopenfd, int flags) {
+  return nftw(dirpath, reinterpret_cast<nftw_fn>(fn), nopenfd, flags);
+}
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 1cfaf50..950073a 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -36,10 +36,8 @@
 #include <stdlib.h>
 #include <sys/auxv.h>
 #include <sys/time.h>
-#include <sys/resource.h>
 #include <unistd.h>
 
-#include "atexit.h"
 #include "private/bionic_auxv.h"
 #include "private/bionic_ssp.h"
 #include "private/bionic_tls.h"
@@ -47,11 +45,12 @@
 #include "pthread_internal.h"
 
 extern "C" abort_msg_t** __abort_message_ptr;
-extern "C" uintptr_t __get_sp(void);
 extern "C" int __system_properties_init(void);
 extern "C" int __set_tls(void* ptr);
 extern "C" int __set_tid_address(int* tid_address);
 
+void __libc_init_vdso();
+
 // Not public, but well-known in the BSDs.
 const char* __progname;
 
@@ -61,23 +60,12 @@
 // Declared in "private/bionic_ssp.h".
 uintptr_t __stack_chk_guard = 0;
 
-static size_t get_main_thread_stack_size() {
-  rlimit stack_limit;
-  int rlimit_result = getrlimit(RLIMIT_STACK, &stack_limit);
-  if ((rlimit_result == 0) &&
-      (stack_limit.rlim_cur != RLIM_INFINITY) &&
-      (stack_limit.rlim_cur > PTHREAD_STACK_MIN)) {
-    return (stack_limit.rlim_cur & ~(PAGE_SIZE - 1));
-  }
-  return PTHREAD_STACK_SIZE_DEFAULT;
-}
-
 /* Init TLS for the initial thread. Called by the linker _before_ libc is mapped
  * in memory. Beware: all writes to libc globals from this function will
  * apply to linker-private copies and will not be visible from libc later on.
  *
  * Note: this function creates a pthread_internal_t for the initial thread and
- * stores the pointer in TLS, but does not add it to pthread's gThreadList. This
+ * stores the pointer in TLS, but does not add it to pthread's thread list. This
  * has to be done later from libc itself (see __libc_init_common).
  *
  * This function also stores a pointer to the kernel argument block in a TLS slot to be
@@ -86,22 +74,24 @@
 void __libc_init_tls(KernelArgumentBlock& args) {
   __libc_auxv = args.auxv;
 
-  uintptr_t stack_top = (__get_sp() & ~(PAGE_SIZE - 1)) + PAGE_SIZE;
-  size_t stack_size = get_main_thread_stack_size();
-  uintptr_t stack_bottom = stack_top - stack_size;
-
   static void* tls[BIONIC_TLS_SLOTS];
   static pthread_internal_t main_thread;
   main_thread.tls = tls;
 
   // Tell the kernel to clear our tid field when we exit, so we're like any other pthread.
+  // As a side-effect, this tells us our pid (which is the same as the main thread's tid).
   main_thread.tid = __set_tid_address(&main_thread.tid);
+  main_thread.set_cached_pid(main_thread.tid);
 
-  // We already have a stack, and we don't want to free it up on exit (because things like
-  // environment variables with global scope live on it).
+  // We don't want to free the main thread's stack even when the main thread exits
+  // because things like environment variables with global scope live on it.
+  // We also can't free the pthread_internal_t itself, since that lives on the main
+  // thread's stack rather than on the heap.
   pthread_attr_init(&main_thread.attr);
-  pthread_attr_setstack(&main_thread.attr, (void*) stack_bottom, stack_size);
   main_thread.attr.flags = PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK | PTHREAD_ATTR_FLAG_MAIN_THREAD;
+  main_thread.attr.guard_size = 0; // The main thread has no guard page.
+  main_thread.attr.stack_size = 0; // User code should never see this; we'll compute it when asked.
+  // TODO: the main thread's sched_policy and sched_priority need to be queried.
 
   __init_thread(&main_thread, false);
   __init_tls(&main_thread);
@@ -127,6 +117,8 @@
   _pthread_internal_add(main_thread);
 
   __system_properties_init(); // Requires 'environ'.
+
+  __libc_init_vdso();
 }
 
 /* This function will be called during normal program termination
diff --git a/libc/bionic/libc_init_common.h b/libc/bionic/libc_init_common.h
index 59dc7df..3032f99 100644
--- a/libc/bionic/libc_init_common.h
+++ b/libc/bionic/libc_init_common.h
@@ -43,14 +43,14 @@
 __noreturn void __libc_init(void* raw_args,
                             void (*onexit)(void),
                             int (*slingshot)(int, char**, char**),
-                            structors_array_t const * const structors);
-void __libc_fini(void* finit_array);
+                            structors_array_t const* const structors);
+__LIBC_HIDDEN__ void __libc_fini(void* finit_array);
 
 __END_DECLS
 
 #if defined(__cplusplus)
 class KernelArgumentBlock;
-void __LIBC_HIDDEN__ __libc_init_common(KernelArgumentBlock& args);
+__LIBC_HIDDEN__ void __libc_init_common(KernelArgumentBlock& args);
 #endif
 
 #endif
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index 61fb887..78125f9 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -48,16 +48,16 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <elf.h>
-#include "atexit.h"
 #include "libc_init_common.h"
 
 #include "private/bionic_tls.h"
 #include "private/KernelArgumentBlock.h"
 
 extern "C" {
-  extern void pthread_debug_init(void);
   extern void malloc_debug_init(void);
   extern void malloc_debug_fini(void);
+  extern void netdClientInit(void);
+  extern int __cxa_atexit(void (*)(void *), void *, void *);
 };
 
 // We flag the __libc_preinit function as a constructor to ensure
@@ -76,9 +76,9 @@
 
   __libc_init_common(*args);
 
-  // Hooks for the debug malloc and pthread libraries to let them know that we're starting up.
-  pthread_debug_init();
+  // Hooks for various libraries to let them know that we're starting up.
   malloc_debug_init();
+  netdClientInit();
 }
 
 __LIBC_HIDDEN__ void __libc_postfini() {
@@ -94,7 +94,7 @@
 // Note that the dynamic linker has also run all constructors in the
 // executable at this point.
 __noreturn void __libc_init(void* raw_args,
-                            void (*onexit)(void),
+                            void (*onexit)(void) __unused,
                             int (*slingshot)(int, char**, char**),
                             structors_array_t const * const structors) {
 
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 1825167..bc11f3d 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -46,7 +46,6 @@
 #include <sys/auxv.h>
 #include <sys/mman.h>
 
-#include "atexit.h"
 #include "libc_init_common.h"
 #include "pthread_internal.h"
 
@@ -60,6 +59,8 @@
 // itself at the start of a page.
 #define PAGE_END(x)    PAGE_START((x) + (PAGE_SIZE-1))
 
+extern "C" int __cxa_atexit(void (*)(void *), void *, void *);
+
 static void call_array(void(**list)()) {
   // First element is -1, list is null-terminated
   while (*++list) {
@@ -68,16 +69,16 @@
 }
 
 static void apply_gnu_relro() {
-  Elf_Phdr* phdr_start = reinterpret_cast<Elf_Phdr*>(getauxval(AT_PHDR));
+  ElfW(Phdr)* phdr_start = reinterpret_cast<ElfW(Phdr)*>(getauxval(AT_PHDR));
   unsigned long int phdr_ct = getauxval(AT_PHNUM);
 
-  for (Elf_Phdr* phdr = phdr_start; phdr < (phdr_start + phdr_ct); phdr++) {
+  for (ElfW(Phdr)* phdr = phdr_start; phdr < (phdr_start + phdr_ct); phdr++) {
     if (phdr->p_type != PT_GNU_RELRO) {
       continue;
     }
 
-    Elf_Addr seg_page_start = PAGE_START(phdr->p_vaddr);
-    Elf_Addr seg_page_end = PAGE_END(phdr->p_vaddr + phdr->p_memsz);
+    ElfW(Addr) seg_page_start = PAGE_START(phdr->p_vaddr);
+    ElfW(Addr) seg_page_end = PAGE_END(phdr->p_vaddr + phdr->p_memsz);
 
     // Check return value here? What do we do if we fail?
     mprotect(reinterpret_cast<void*>(seg_page_start), seg_page_end - seg_page_start, PROT_READ);
@@ -85,7 +86,7 @@
 }
 
 __noreturn void __libc_init(void* raw_args,
-                            void (*onexit)(void),
+                            void (*onexit)(void) __unused,
                             int (*slingshot)(int, char**, char**),
                             structors_array_t const * const structors) {
   KernelArgumentBlock args(raw_args);
diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp
index 2d00596..5655526 100644
--- a/libc/bionic/libc_logging.cpp
+++ b/libc/bionic/libc_logging.cpp
@@ -29,6 +29,7 @@
 #include "../private/libc_logging.h" // Relative path so we can #include this .cpp file for testing.
 #include "../private/ScopedPthreadMutexLocker.h"
 
+#include <android/set_abort_message.h>
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -38,10 +39,14 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/types.h>
 #include <sys/uio.h>
+#include <sys/un.h>
+#include <time.h>
 #include <unistd.h>
 
-static pthread_mutex_t gAbortMsgLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_abort_msg_lock = PTHREAD_MUTEX_INITIALIZER;
 
 __LIBC_HIDDEN__ abort_msg_t** __abort_message_ptr; // Accessible to __libc_init_common.
 
@@ -136,7 +141,7 @@
 
     for (;;) {
         int ch = *p;
-        unsigned d = (unsigned)(ch - '0');
+        unsigned d = static_cast<unsigned>(ch - '0');
 
         if (d >= 10U) {
             break;
@@ -289,13 +294,13 @@
         /* parse field width */
         if ((c >= '0' && c <= '9')) {
             nn --;
-            width = (int)parse_decimal(format, &nn);
+            width = static_cast<int>(parse_decimal(format, &nn));
             c = format[nn++];
         }
 
         /* parse precision */
         if (c == '.') {
-            prec = (int)parse_decimal(format, &nn);
+            prec = static_cast<int>(parse_decimal(format, &nn));
             c = format[nn++];
         }
 
@@ -340,10 +345,10 @@
         } else if (c == 'c') {
             /* character */
             /* NOTE: char is promoted to int when passed through the stack */
-            buffer[0] = (char) va_arg(args, int);
+            buffer[0] = static_cast<char>(va_arg(args, int));
             buffer[1] = '\0';
         } else if (c == 'p') {
-            uint64_t  value = (uintptr_t) va_arg(args, void*);
+            uint64_t  value = reinterpret_cast<uintptr_t>(va_arg(args, void*));
             buffer[0] = '0';
             buffer[1] = 'x';
             format_integer(buffer + 2, sizeof(buffer) - 2, value, 'x');
@@ -356,8 +361,8 @@
              *       through the stack
              */
             switch (bytelen) {
-            case 1: value = (uint8_t)  va_arg(args, int); break;
-            case 2: value = (uint16_t) va_arg(args, int); break;
+            case 1: value = static_cast<uint8_t>(va_arg(args, int)); break;
+            case 2: value = static_cast<uint16_t>(va_arg(args, int)); break;
             case 4: value = va_arg(args, uint32_t); break;
             case 8: value = va_arg(args, uint64_t); break;
             default: return;  /* should not happen */
@@ -366,7 +371,7 @@
             /* sign extension, if needed */
             if (is_signed) {
                 int shift = 64 - 8*bytelen;
-                value = (uint64_t)(((int64_t)(value << shift)) >> shift);
+                value = static_cast<uint64_t>((static_cast<int64_t>(value << shift)) >> shift);
             }
 
             /* format the number properly into our buffer */
@@ -440,7 +445,78 @@
   return result;
 }
 
+#ifdef TARGET_USES_LOGD
+static int __libc_open_log_socket()
+{
+  // ToDo: Ideally we want this to fail if the gid of the current
+  // process is AID_LOGD, but will have to wait until we have
+  // registered this in private/android_filesystem_config.h. We have
+  // found that all logd crashes thus far have had no problem stuffing
+  // the UNIX domain socket and moving on so not critical *today*.
+
+  int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0));
+  if (log_fd < 0) {
+    return -1;
+  }
+
+  if (fcntl(log_fd, F_SETFL, O_NONBLOCK) == -1) {
+    close(log_fd);
+    return -1;
+  }
+
+  union {
+    struct sockaddr    addr;
+    struct sockaddr_un addrUn;
+  } u;
+  memset(&u, 0, sizeof(u));
+  u.addrUn.sun_family = AF_UNIX;
+  strlcpy(u.addrUn.sun_path, "/dev/socket/logdw", sizeof(u.addrUn.sun_path));
+
+  if (TEMP_FAILURE_RETRY(connect(log_fd, &u.addr, sizeof(u.addrUn))) != 0) {
+    close(log_fd);
+    return -1;
+  }
+
+  return log_fd;
+}
+
+struct log_time { // Wire format
+  uint32_t tv_sec;
+  uint32_t tv_nsec;
+};
+#endif
+
 static int __libc_write_log(int priority, const char* tag, const char* msg) {
+#ifdef TARGET_USES_LOGD
+  int main_log_fd = __libc_open_log_socket();
+
+  if (main_log_fd == -1) {
+    // Try stderr instead.
+    return __libc_write_stderr(tag, msg);
+  }
+
+  iovec vec[6];
+  char log_id = (priority == ANDROID_LOG_FATAL) ? LOG_ID_CRASH : LOG_ID_MAIN;
+  vec[0].iov_base = &log_id;
+  vec[0].iov_len = sizeof(log_id);
+  uint16_t tid = gettid();
+  vec[1].iov_base = &tid;
+  vec[1].iov_len = sizeof(tid);
+  timespec ts;
+  clock_gettime(CLOCK_REALTIME, &ts);
+  log_time realtime_ts;
+  realtime_ts.tv_sec = ts.tv_sec;
+  realtime_ts.tv_nsec = ts.tv_nsec;
+  vec[2].iov_base = &realtime_ts;
+  vec[2].iov_len = sizeof(realtime_ts);
+
+  vec[3].iov_base = &priority;
+  vec[3].iov_len = 1;
+  vec[4].iov_base = const_cast<char*>(tag);
+  vec[4].iov_len = strlen(tag) + 1;
+  vec[5].iov_base = const_cast<char*>(msg);
+  vec[5].iov_len = strlen(msg) + 1;
+#else
   int main_log_fd = TEMP_FAILURE_RETRY(open("/dev/log/main", O_CLOEXEC | O_WRONLY));
   if (main_log_fd == -1) {
     if (errno == ENOTDIR) {
@@ -457,8 +533,9 @@
   vec[1].iov_len = strlen(tag) + 1;
   vec[2].iov_base = const_cast<char*>(msg);
   vec[2].iov_len = strlen(msg) + 1;
+#endif
 
-  int result = TEMP_FAILURE_RETRY(writev(main_log_fd, vec, 3));
+  int result = TEMP_FAILURE_RETRY(writev(main_log_fd, vec, sizeof(vec) / sizeof(vec[0])));
   close(main_log_fd);
   return result;
 }
@@ -479,6 +556,31 @@
 }
 
 static int __libc_android_log_event(int32_t tag, char type, const void* payload, size_t len) {
+#ifdef TARGET_USES_LOGD
+  iovec vec[6];
+  char log_id = LOG_ID_EVENTS;
+  vec[0].iov_base = &log_id;
+  vec[0].iov_len = sizeof(log_id);
+  uint16_t tid = gettid();
+  vec[1].iov_base = &tid;
+  vec[1].iov_len = sizeof(tid);
+  timespec ts;
+  clock_gettime(CLOCK_REALTIME, &ts);
+  log_time realtime_ts;
+  realtime_ts.tv_sec = ts.tv_sec;
+  realtime_ts.tv_nsec = ts.tv_nsec;
+  vec[2].iov_base = &realtime_ts;
+  vec[2].iov_len = sizeof(realtime_ts);
+
+  vec[3].iov_base = &tag;
+  vec[3].iov_len = sizeof(tag);
+  vec[4].iov_base = &type;
+  vec[4].iov_len = sizeof(type);
+  vec[5].iov_base = const_cast<void*>(payload);
+  vec[5].iov_len = len;
+
+  int event_log_fd = __libc_open_log_socket();
+#else
   iovec vec[3];
   vec[0].iov_base = &tag;
   vec[0].iov_len = sizeof(tag);
@@ -488,10 +590,12 @@
   vec[2].iov_len = len;
 
   int event_log_fd = TEMP_FAILURE_RETRY(open("/dev/log/events", O_CLOEXEC | O_WRONLY));
+#endif
+
   if (event_log_fd == -1) {
     return -1;
   }
-  int result = TEMP_FAILURE_RETRY(writev(event_log_fd, vec, 3));
+  int result = TEMP_FAILURE_RETRY(writev(event_log_fd, vec, sizeof(vec) / sizeof(vec[0])));
   close(event_log_fd);
   return result;
 }
@@ -516,12 +620,17 @@
   BufferOutputStream os(msg, sizeof(msg));
   out_vformat(os, format, args);
 
-  // TODO: log to stderr for the benefit of "adb shell" users.
+  // log to stderr for the benefit of "adb shell" users.
+  struct iovec iov[2] = {
+    {msg, strlen(msg)},
+    {const_cast<void*>(static_cast<const void*>("\n")), 1},
+  };
+  writev(2, iov, 2);
 
   // Log to the log for the benefit of regular app developers (whose stdout and stderr are closed).
   __libc_write_log(ANDROID_LOG_FATAL, "libc", msg);
 
-  __libc_set_abort_message(msg);
+  android_set_abort_message(msg);
 }
 
 void __libc_fatal_no_abort(const char* format, ...) {
@@ -539,21 +648,33 @@
   abort();
 }
 
-void __libc_set_abort_message(const char* msg) {
+void android_set_abort_message(const char* msg) {
+  ScopedPthreadMutexLocker locker(&g_abort_msg_lock);
+
+  if (__abort_message_ptr == NULL) {
+    // We must have crashed _very_ early.
+    return;
+  }
+
+  if (*__abort_message_ptr != NULL) {
+    // We already have an abort message.
+    // Assume that the first crash is the one most worth reporting.
+    return;
+  }
+
   size_t size = sizeof(abort_msg_t) + strlen(msg) + 1;
   void* map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
   if (map == MAP_FAILED) {
     return;
   }
 
-  if (__abort_message_ptr != NULL) {
-    ScopedPthreadMutexLocker locker(&gAbortMsgLock);
-    if (*__abort_message_ptr != NULL) {
-      munmap(*__abort_message_ptr, (*__abort_message_ptr)->size);
-    }
-    abort_msg_t* new_abort_message = reinterpret_cast<abort_msg_t*>(map);
-    new_abort_message->size = size;
-    strcpy(new_abort_message->msg, msg);
-    *__abort_message_ptr = new_abort_message;
+  // TODO: if we stick to the current "one-shot" scheme, we can remove this code and
+  // stop storing the size.
+  if (*__abort_message_ptr != NULL) {
+    munmap(*__abort_message_ptr, (*__abort_message_ptr)->size);
   }
+  abort_msg_t* new_abort_message = reinterpret_cast<abort_msg_t*>(map);
+  new_abort_message->size = size;
+  strcpy(new_abort_message->msg, msg);
+  *__abort_message_ptr = new_abort_message;
 }
diff --git a/libc/bionic/libgen.cpp b/libc/bionic/libgen.cpp
index d8df494..b98f504 100644
--- a/libc/bionic/libgen.cpp
+++ b/libc/bionic/libgen.cpp
@@ -36,22 +36,7 @@
 
 #include "private/ThreadLocalBuffer.h"
 
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(basename);
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(dirname);
-
-char* basename(const char* path) {
-  LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, basename, MAXPATHLEN);
-  int rc = basename_r(path, basename_tls_buffer, basename_tls_buffer_size);
-  return (rc < 0) ? NULL : basename_tls_buffer;
-}
-
-char* dirname(const char* path) {
-  LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, dirname, MAXPATHLEN);
-  int rc = dirname_r(path, dirname_tls_buffer, dirname_tls_buffer_size);
-  return (rc < 0) ? NULL : dirname_tls_buffer;
-}
-
-int basename_r(const char* path, char* buffer, size_t buffer_size) {
+__LIBC64_HIDDEN__ int basename_r(const char* path, char* buffer, size_t buffer_size) {
   const char* startp = NULL;
   const char* endp = NULL;
   int len;
@@ -103,7 +88,7 @@
   return result;
 }
 
-int dirname_r(const char* path, char* buffer, size_t buffer_size) {
+__LIBC64_HIDDEN__ int dirname_r(const char* path, char* buffer, size_t buffer_size) {
   const char* endp = NULL;
   int len;
   int result;
@@ -161,3 +146,18 @@
   }
   return result;
 }
+
+GLOBAL_INIT_THREAD_LOCAL_BUFFER(basename);
+GLOBAL_INIT_THREAD_LOCAL_BUFFER(dirname);
+
+char* basename(const char* path) {
+  LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, basename, MAXPATHLEN);
+  int rc = basename_r(path, basename_tls_buffer, basename_tls_buffer_size);
+  return (rc < 0) ? NULL : basename_tls_buffer;
+}
+
+char* dirname(const char* path) {
+  LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, dirname, MAXPATHLEN);
+  int rc = dirname_r(path, dirname_tls_buffer, dirname_tls_buffer_size);
+  return (rc < 0) ? NULL : dirname_tls_buffer;
+}
diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp
new file mode 100644
index 0000000..ddb49ce
--- /dev/null
+++ b/libc/bionic/locale.cpp
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <locale.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+#include "private/bionic_macros.h"
+
+// We currently support a single locale, the "C" locale (also known as "POSIX").
+
+static bool __bionic_current_locale_is_utf8 = true;
+
+struct __locale_t {
+  size_t mb_cur_max;
+
+  __locale_t(size_t mb_cur_max) : mb_cur_max(mb_cur_max) {
+  }
+
+  __locale_t(const __locale_t* other) {
+    if (other == LC_GLOBAL_LOCALE) {
+      mb_cur_max = __bionic_current_locale_is_utf8 ? 4 : 1;
+    } else {
+      mb_cur_max = other->mb_cur_max;
+    }
+  }
+
+  DISALLOW_COPY_AND_ASSIGN(__locale_t);
+};
+
+static pthread_once_t g_locale_once = PTHREAD_ONCE_INIT;
+static lconv g_locale;
+
+// We don't use pthread_once for this so that we know when the resource (a TLS slot) will be taken.
+static pthread_key_t g_uselocale_key;
+__attribute__((constructor)) static void __bionic_tls_uselocale_key_init() {
+  pthread_key_create(&g_uselocale_key, NULL);
+}
+
+static void __locale_init() {
+  g_locale.decimal_point = const_cast<char*>(".");
+
+  char* not_available = const_cast<char*>("");
+  g_locale.thousands_sep = not_available;
+  g_locale.grouping = not_available;
+  g_locale.int_curr_symbol = not_available;
+  g_locale.currency_symbol = not_available;
+  g_locale.mon_decimal_point = not_available;
+  g_locale.mon_thousands_sep = not_available;
+  g_locale.mon_grouping = not_available;
+  g_locale.positive_sign = not_available;
+  g_locale.negative_sign = not_available;
+
+  g_locale.int_frac_digits = CHAR_MAX;
+  g_locale.frac_digits = CHAR_MAX;
+  g_locale.p_cs_precedes = CHAR_MAX;
+  g_locale.p_sep_by_space = CHAR_MAX;
+  g_locale.n_cs_precedes = CHAR_MAX;
+  g_locale.n_sep_by_space = CHAR_MAX;
+  g_locale.p_sign_posn = CHAR_MAX;
+  g_locale.n_sign_posn = CHAR_MAX;
+  g_locale.int_p_cs_precedes = CHAR_MAX;
+  g_locale.int_p_sep_by_space = CHAR_MAX;
+  g_locale.int_n_cs_precedes = CHAR_MAX;
+  g_locale.int_n_sep_by_space = CHAR_MAX;
+  g_locale.int_p_sign_posn = CHAR_MAX;
+  g_locale.int_n_sign_posn = CHAR_MAX;
+}
+
+size_t __ctype_get_mb_cur_max() {
+  locale_t l = reinterpret_cast<locale_t>(pthread_getspecific(g_uselocale_key));
+  if (l == nullptr || l == LC_GLOBAL_LOCALE) {
+    return __bionic_current_locale_is_utf8 ? 4 : 1;
+  } else {
+    return l->mb_cur_max;
+  }
+}
+
+static bool __is_supported_locale(const char* locale) {
+  return (strcmp(locale, "") == 0 ||
+          strcmp(locale, "C") == 0 ||
+          strcmp(locale, "C.UTF-8") == 0 ||
+          strcmp(locale, "en_US.UTF-8") == 0 ||
+          strcmp(locale, "POSIX") == 0);
+}
+
+lconv* localeconv() {
+  pthread_once(&g_locale_once, __locale_init);
+  return &g_locale;
+}
+
+locale_t duplocale(locale_t l) {
+  return new __locale_t(l);
+}
+
+void freelocale(locale_t l) {
+  delete l;
+}
+
+locale_t newlocale(int category_mask, const char* locale_name, locale_t /*base*/) {
+  // Is 'category_mask' valid?
+  if ((category_mask & ~LC_ALL_MASK) != 0) {
+    errno = EINVAL;
+    return NULL;
+  }
+
+  if (!__is_supported_locale(locale_name)) {
+    errno = ENOENT;
+    return NULL;
+  }
+
+  return new __locale_t(strstr(locale_name, "UTF-8") != NULL ? 4 : 1);
+}
+
+char* setlocale(int category, const char* locale_name) {
+  // Is 'category' valid?
+  if (category < LC_CTYPE || category > LC_IDENTIFICATION) {
+    errno = EINVAL;
+    return NULL;
+  }
+
+  // Caller wants to set the locale rather than just query?
+  if (locale_name != NULL) {
+    if (!__is_supported_locale(locale_name)) {
+      // We don't support this locale.
+      errno = ENOENT;
+      return NULL;
+    }
+    __bionic_current_locale_is_utf8 = (strstr(locale_name, "UTF-8") != NULL);
+  }
+
+  return const_cast<char*>(__bionic_current_locale_is_utf8 ? "C.UTF-8" : "C");
+}
+
+locale_t uselocale(locale_t new_locale) {
+  locale_t old_locale = static_cast<locale_t>(pthread_getspecific(g_uselocale_key));
+
+  // If this is the first call to uselocale(3) on this thread, we return LC_GLOBAL_LOCALE.
+  if (old_locale == NULL) {
+    old_locale = LC_GLOBAL_LOCALE;
+  }
+
+  if (new_locale != NULL) {
+    pthread_setspecific(g_uselocale_key, new_locale);
+  }
+
+  return old_locale;
+}
diff --git a/libc/bionic/lstat.cpp b/libc/bionic/lstat.cpp
index 300d7fa..84d17e2 100644
--- a/libc/bionic/lstat.cpp
+++ b/libc/bionic/lstat.cpp
@@ -34,3 +34,4 @@
 int lstat(const char* path, struct stat* sb) {
   return fstatat(AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW);
 }
+__strong_alias(lstat64, lstat);
diff --git a/libc/bionic/malloc_debug_backtrace.h b/libc/bionic/malloc_debug_backtrace.h
new file mode 100644
index 0000000..774548b
--- /dev/null
+++ b/libc/bionic/malloc_debug_backtrace.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef MALLOC_DEBUG_BACKTRACE_H
+#define MALLOC_DEBUG_BACKTRACE_H
+
+extern bool g_backtrace_enabled;
+
+#define GET_BACKTRACE(bt, depth) \
+  (g_backtrace_enabled ? get_backtrace(bt, depth) : 0)
+
+#endif  // MALLOC_DEBUG_BACKTRACE_H
diff --git a/libc/bionic/malloc_debug_check.cpp b/libc/bionic/malloc_debug_check.cpp
index 7dd8e3c..dee03fa 100644
--- a/libc/bionic/malloc_debug_check.cpp
+++ b/libc/bionic/malloc_debug_check.cpp
@@ -38,6 +38,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/system_properties.h>
 #include <sys/types.h>
@@ -47,15 +48,13 @@
 
 #include "debug_mapinfo.h"
 #include "debug_stacktrace.h"
-#include "dlmalloc.h"
-#include "private/libc_logging.h"
+#include "malloc_debug_backtrace.h"
 #include "malloc_debug_common.h"
+#include "malloc_debug_disable.h"
+#include "private/bionic_macros.h"
+#include "private/libc_logging.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
-/* libc.debug.malloc.backlog */
-extern unsigned int gMallocDebugBacklog;
-extern int gMallocDebugLevel;
-
 #define MAX_BACKTRACE_DEPTH 16
 #define ALLOCATION_TAG      0x1ee7d00d
 #define BACKLOG_TAG         0xbabecafe
@@ -74,7 +73,7 @@
 
 struct hdr_t {
     uint32_t tag;
-    void* base;  // Always points to the memory allocated using dlmalloc.
+    void* base;  // Always points to the memory allocated using malloc.
                  // For memory allocated in chk_memalign, this value will
                  // not be the same as the location of the start of this
                  // structure.
@@ -108,8 +107,10 @@
     return reinterpret_cast<const hdr_t*>(user) - 1;
 }
 
-
-static unsigned gAllocatedBlockCount;
+// TODO: introduce a struct for this global state.
+// There are basically two lists here, the regular list and the backlog list.
+// We should be able to remove the duplication.
+static unsigned g_allocated_block_count;
 static hdr_t* tail;
 static hdr_t* head;
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
@@ -119,6 +120,17 @@
 static hdr_t* backlog_head;
 static pthread_mutex_t backlog_lock = PTHREAD_MUTEX_INITIALIZER;
 
+// This variable is set to the value of property libc.debug.malloc.backlog.
+// It determines the size of the backlog we use to detect multiple frees.
+static unsigned g_malloc_debug_backlog = 100;
+
+// This variable is set to false if the property libc.debug.malloc.nobacktrace
+// is set to non-zero.
+__LIBC_HIDDEN__ bool g_backtrace_enabled = true;
+
+__LIBC_HIDDEN__ HashTable* g_hash_table;
+__LIBC_HIDDEN__ const MallocDebug* g_malloc_dispatch;
+
 static inline void init_front_guard(hdr_t* hdr) {
     memset(hdr->front_guard, FRONT_GUARD, FRONT_GUARD_LEN);
 }
@@ -188,7 +200,7 @@
     hdr->size = size;
     init_front_guard(hdr);
     init_rear_guard(hdr);
-    ++gAllocatedBlockCount;
+    ++g_allocated_block_count;
     add_locked(hdr, &tail, &head);
 }
 
@@ -199,7 +211,7 @@
 
     ScopedPthreadMutexLocker locker(&lock);
     del_locked(hdr, &tail, &head);
-    --gAllocatedBlockCount;
+    --g_allocated_block_count;
     return 0;
 }
 
@@ -266,7 +278,7 @@
         valid = check_guards(hdr, safe);
     }
 
-    if (!valid && *safe) {
+    if (!valid && *safe && g_backtrace_enabled) {
         log_message("+++ ALLOCATION %p SIZE %d ALLOCATED HERE:\n",
                         user(hdr), hdr->size);
         log_backtrace(hdr->bt, hdr->bt_depth);
@@ -306,7 +318,7 @@
 
 static inline int del_leak(hdr_t* hdr, int* safe) {
     ScopedPthreadMutexLocker locker(&lock);
-    return del_and_check_locked(hdr, &tail, &head, &gAllocatedBlockCount, safe);
+    return del_and_check_locked(hdr, &tail, &head, &g_allocated_block_count, safe);
 }
 
 static inline void add_to_backlog(hdr_t* hdr) {
@@ -316,34 +328,46 @@
     add_locked(hdr, &backlog_tail, &backlog_head);
     poison(hdr);
     /* If we've exceeded the maximum backlog, clear it up */
-    while (backlog_num > gMallocDebugBacklog) {
+    while (backlog_num > g_malloc_debug_backlog) {
         hdr_t* gone = backlog_tail;
         del_from_backlog_locked(gone);
-        dlfree(gone->base);
+        g_malloc_dispatch->free(gone->base);
     }
 }
 
-extern "C" void* chk_malloc(size_t size) {
+extern "C" void* chk_malloc(size_t bytes) {
 //  log_message("%s: %s\n", __FILE__, __FUNCTION__);
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->malloc(bytes);
+    }
 
-    hdr_t* hdr = static_cast<hdr_t*>(dlmalloc(sizeof(hdr_t) + size + sizeof(ftr_t)));
+    size_t size = sizeof(hdr_t) + bytes + sizeof(ftr_t);
+    if (size < bytes) { // Overflow
+        errno = ENOMEM;
+        return NULL;
+    }
+    hdr_t* hdr = static_cast<hdr_t*>(g_malloc_dispatch->malloc(size));
     if (hdr) {
         hdr->base = hdr;
-        hdr->bt_depth = get_backtrace(hdr->bt, MAX_BACKTRACE_DEPTH);
-        add(hdr, size);
+        hdr->bt_depth = GET_BACKTRACE(hdr->bt, MAX_BACKTRACE_DEPTH);
+        add(hdr, bytes);
         return user(hdr);
     }
     return NULL;
 }
 
 extern "C" void* chk_memalign(size_t alignment, size_t bytes) {
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->memalign(alignment, bytes);
+    }
+
     if (alignment <= MALLOC_ALIGNMENT) {
         return chk_malloc(bytes);
     }
 
     // Make the alignment a power of two.
-    if (alignment & (alignment-1)) {
-        alignment = 1L << (31 - __builtin_clz(alignment));
+    if (!powerof2(alignment)) {
+        alignment = BIONIC_ROUND_UP_POWER_OF_2(alignment);
     }
 
     // here, alignment is at least MALLOC_ALIGNMENT<<1 bytes
@@ -354,7 +378,7 @@
         return NULL;
     }
 
-    void* base = dlmalloc(sizeof(hdr_t) + size + sizeof(ftr_t));
+    void* base = g_malloc_dispatch->malloc(sizeof(hdr_t) + size + sizeof(ftr_t));
     if (base != NULL) {
         // Check that the actual pointer that will be returned is aligned
         // properly.
@@ -366,7 +390,7 @@
 
         hdr_t* hdr = meta(reinterpret_cast<void*>(ptr));
         hdr->base = base;
-        hdr->bt_depth = get_backtrace(hdr->bt, MAX_BACKTRACE_DEPTH);
+        hdr->bt_depth = GET_BACKTRACE(hdr->bt, MAX_BACKTRACE_DEPTH);
         add(hdr, bytes);
         return user(hdr);
     }
@@ -375,6 +399,9 @@
 
 extern "C" void chk_free(void* ptr) {
 //  log_message("%s: %s\n", __FILE__, __FUNCTION__);
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->free(ptr);
+    }
 
     if (!ptr) /* ignore free(NULL) */
         return;
@@ -383,40 +410,47 @@
 
     if (del(hdr) < 0) {
         uintptr_t bt[MAX_BACKTRACE_DEPTH];
-        int depth = get_backtrace(bt, MAX_BACKTRACE_DEPTH);
+        int depth = GET_BACKTRACE(bt, MAX_BACKTRACE_DEPTH);
         if (hdr->tag == BACKLOG_TAG) {
             log_message("+++ ALLOCATION %p SIZE %d BYTES MULTIPLY FREED!\n",
                        user(hdr), hdr->size);
-            log_message("+++ ALLOCATION %p SIZE %d ALLOCATED HERE:\n",
-                       user(hdr), hdr->size);
-            log_backtrace(hdr->bt, hdr->bt_depth);
-            /* hdr->freed_bt_depth should be nonzero here */
-            log_message("+++ ALLOCATION %p SIZE %d FIRST FREED HERE:\n",
-                       user(hdr), hdr->size);
-            log_backtrace(hdr->freed_bt, hdr->freed_bt_depth);
-            log_message("+++ ALLOCATION %p SIZE %d NOW BEING FREED HERE:\n",
-                       user(hdr), hdr->size);
-            log_backtrace(bt, depth);
+            if (g_backtrace_enabled) {
+                log_message("+++ ALLOCATION %p SIZE %d ALLOCATED HERE:\n",
+                          user(hdr), hdr->size);
+                log_backtrace(hdr->bt, hdr->bt_depth);
+                /* hdr->freed_bt_depth should be nonzero here */
+                log_message("+++ ALLOCATION %p SIZE %d FIRST FREED HERE:\n",
+                          user(hdr), hdr->size);
+                log_backtrace(hdr->freed_bt, hdr->freed_bt_depth);
+                log_message("+++ ALLOCATION %p SIZE %d NOW BEING FREED HERE:\n",
+                          user(hdr), hdr->size);
+                log_backtrace(bt, depth);
+            }
         } else {
             log_message("+++ ALLOCATION %p IS CORRUPTED OR NOT ALLOCATED VIA TRACKER!\n",
                        user(hdr));
-            log_backtrace(bt, depth);
+            if (g_backtrace_enabled) {
+                log_backtrace(bt, depth);
+            }
         }
     } else {
-        hdr->freed_bt_depth = get_backtrace(hdr->freed_bt, MAX_BACKTRACE_DEPTH);
+        hdr->freed_bt_depth = GET_BACKTRACE(hdr->freed_bt, MAX_BACKTRACE_DEPTH);
         add_to_backlog(hdr);
     }
 }
 
-extern "C" void* chk_realloc(void* ptr, size_t size) {
+extern "C" void* chk_realloc(void* ptr, size_t bytes) {
 //  log_message("%s: %s\n", __FILE__, __FUNCTION__);
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->realloc(ptr, bytes);
+    }
 
     if (!ptr) {
-        return chk_malloc(size);
+        return chk_malloc(bytes);
     }
 
 #ifdef REALLOC_ZERO_BYTES_FREE
-    if (!size) {
+    if (!bytes) {
         chk_free(ptr);
         return NULL;
     }
@@ -426,76 +460,95 @@
 
     if (del(hdr) < 0) {
         uintptr_t bt[MAX_BACKTRACE_DEPTH];
-        int depth = get_backtrace(bt, MAX_BACKTRACE_DEPTH);
+        int depth = GET_BACKTRACE(bt, MAX_BACKTRACE_DEPTH);
         if (hdr->tag == BACKLOG_TAG) {
             log_message("+++ REALLOCATION %p SIZE %d OF FREED MEMORY!\n",
-                       user(hdr), size, hdr->size);
-            log_message("+++ ALLOCATION %p SIZE %d ALLOCATED HERE:\n",
-                       user(hdr), hdr->size);
-            log_backtrace(hdr->bt, hdr->bt_depth);
-            /* hdr->freed_bt_depth should be nonzero here */
-            log_message("+++ ALLOCATION %p SIZE %d FIRST FREED HERE:\n",
-                       user(hdr), hdr->size);
-            log_backtrace(hdr->freed_bt, hdr->freed_bt_depth);
-            log_message("+++ ALLOCATION %p SIZE %d NOW BEING REALLOCATED HERE:\n",
-                       user(hdr), hdr->size);
-            log_backtrace(bt, depth);
+                       user(hdr), bytes, hdr->size);
+            if (g_backtrace_enabled) {
+                log_message("+++ ALLOCATION %p SIZE %d ALLOCATED HERE:\n",
+                          user(hdr), hdr->size);
+                log_backtrace(hdr->bt, hdr->bt_depth);
+                /* hdr->freed_bt_depth should be nonzero here */
+                log_message("+++ ALLOCATION %p SIZE %d FIRST FREED HERE:\n",
+                          user(hdr), hdr->size);
+                log_backtrace(hdr->freed_bt, hdr->freed_bt_depth);
+                log_message("+++ ALLOCATION %p SIZE %d NOW BEING REALLOCATED HERE:\n",
+                          user(hdr), hdr->size);
+                log_backtrace(bt, depth);
+            }
 
-             /* We take the memory out of the backlog and fall through so the
+            /* We take the memory out of the backlog and fall through so the
              * reallocation below succeeds.  Since we didn't really free it, we
              * can default to this behavior.
              */
             del_from_backlog(hdr);
         } else {
             log_message("+++ REALLOCATION %p SIZE %d IS CORRUPTED OR NOT ALLOCATED VIA TRACKER!\n",
-                       user(hdr), size);
-            log_backtrace(bt, depth);
+                       user(hdr), bytes);
+            if (g_backtrace_enabled) {
+                log_backtrace(bt, depth);
+            }
             // just get a whole new allocation and leak the old one
-            return dlrealloc(0, size);
-            // return dlrealloc(user(hdr), size); // assuming it was allocated externally
+            return g_malloc_dispatch->realloc(0, bytes);
+            // return realloc(user(hdr), bytes); // assuming it was allocated externally
         }
     }
 
+    size_t size = sizeof(hdr_t) + bytes + sizeof(ftr_t);
+    if (size < bytes) { // Overflow
+        errno = ENOMEM;
+        return NULL;
+    }
     if (hdr->base != hdr) {
         // An allocation from memalign, so create another allocation and
         // copy the data out.
-        void* newMem = dlmalloc(sizeof(hdr_t) + size + sizeof(ftr_t));
-        if (newMem) {
-            memcpy(newMem, hdr, sizeof(hdr_t) + hdr->size);
-            dlfree(hdr->base);
-            hdr = static_cast<hdr_t*>(newMem);
-        } else {
-            dlfree(hdr->base);
-            hdr = NULL;
+        void* newMem = g_malloc_dispatch->malloc(size);
+        if (newMem == NULL) {
+            return NULL;
         }
+        memcpy(newMem, hdr, sizeof(hdr_t) + hdr->size);
+        g_malloc_dispatch->free(hdr->base);
+        hdr = static_cast<hdr_t*>(newMem);
     } else {
-        hdr = static_cast<hdr_t*>(dlrealloc(hdr, sizeof(hdr_t) + size + sizeof(ftr_t)));
+        hdr = static_cast<hdr_t*>(g_malloc_dispatch->realloc(hdr, size));
     }
     if (hdr) {
         hdr->base = hdr;
-        hdr->bt_depth = get_backtrace(hdr->bt, MAX_BACKTRACE_DEPTH);
-        add(hdr, size);
+        hdr->bt_depth = GET_BACKTRACE(hdr->bt, MAX_BACKTRACE_DEPTH);
+        add(hdr, bytes);
         return user(hdr);
     }
-
     return NULL;
 }
 
-extern "C" void* chk_calloc(int nmemb, size_t size) {
+extern "C" void* chk_calloc(size_t nmemb, size_t bytes) {
 //  log_message("%s: %s\n", __FILE__, __FUNCTION__);
-    size_t total_size = nmemb * size;
-    hdr_t* hdr = static_cast<hdr_t*>(dlcalloc(1, sizeof(hdr_t) + total_size + sizeof(ftr_t)));
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->calloc(nmemb, bytes);
+    }
+
+    size_t total_bytes = nmemb * bytes;
+    size_t size = sizeof(hdr_t) + total_bytes + sizeof(ftr_t);
+    if (size < total_bytes || (nmemb && SIZE_MAX / nmemb < bytes)) { // Overflow
+        errno = ENOMEM;
+        return NULL;
+    }
+    hdr_t* hdr = static_cast<hdr_t*>(g_malloc_dispatch->calloc(1, size));
     if (hdr) {
         hdr->base = hdr;
-        hdr->bt_depth = get_backtrace(hdr->bt, MAX_BACKTRACE_DEPTH);
-        add(hdr, total_size);
+        hdr->bt_depth = GET_BACKTRACE(hdr->bt, MAX_BACKTRACE_DEPTH);
+        add(hdr, total_bytes);
         return user(hdr);
     }
     return NULL;
 }
 
 extern "C" size_t chk_malloc_usable_size(const void* ptr) {
-    // dlmalloc_usable_size returns 0 for NULL and unknown blocks.
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->malloc_usable_size(ptr);
+    }
+
+    // malloc_usable_size returns 0 for NULL and unknown blocks.
     if (ptr == NULL)
         return 0;
 
@@ -506,12 +559,49 @@
     return hdr->size;
 }
 
-static void ReportMemoryLeaks() {
-  // We only track leaks at level 10.
-  if (gMallocDebugLevel != 10) {
-    return;
+extern "C" struct mallinfo chk_mallinfo() {
+  return g_malloc_dispatch->mallinfo();
+}
+
+extern "C" int chk_posix_memalign(void** memptr, size_t alignment, size_t size) {
+  if (DebugCallsDisabled()) {
+    return g_malloc_dispatch->posix_memalign(memptr, alignment, size);
   }
 
+  if (!powerof2(alignment)) {
+    return EINVAL;
+  }
+  int saved_errno = errno;
+  *memptr = chk_memalign(alignment, size);
+  errno = saved_errno;
+  return (*memptr != NULL) ? 0 : ENOMEM;
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* chk_pvalloc(size_t bytes) {
+  if (DebugCallsDisabled()) {
+    return g_malloc_dispatch->pvalloc(bytes);
+  }
+
+  size_t pagesize = getpagesize();
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) { // Overflow
+    return NULL;
+  }
+  return chk_memalign(pagesize, size);
+}
+
+extern "C" void* chk_valloc(size_t size) {
+  if (DebugCallsDisabled()) {
+    return g_malloc_dispatch->valloc(size);
+  }
+  return chk_memalign(getpagesize(), size);
+}
+#endif
+
+static void ReportMemoryLeaks() {
+  ScopedDisableDebugCalls disable;
+
   // Use /proc/self/exe link to obtain the program name for logging
   // purposes. If it's not available, we set it to "<unknown>".
   char exe[PATH_MAX];
@@ -522,19 +612,19 @@
     exe[count] = '\0';
   }
 
-  if (gAllocatedBlockCount == 0) {
+  if (g_allocated_block_count == 0) {
     log_message("+++ %s did not leak", exe);
     return;
   }
 
   size_t index = 1;
-  const size_t total = gAllocatedBlockCount;
+  const size_t total = g_allocated_block_count;
   while (head != NULL) {
     int safe;
     hdr_t* block = head;
     log_message("+++ %s leaked block of size %d at %p (leak %d of %d)",
                 exe, block->size, user(block), index++, total);
-    if (del_leak(block, &safe)) {
+    if (del_leak(block, &safe) && g_backtrace_enabled) {
       /* safe == 1, because the allocation is valid */
       log_backtrace(block->bt, block->bt_depth);
     }
@@ -545,12 +635,42 @@
   }
 }
 
-extern "C" int malloc_debug_initialize() {
-  backtrace_startup();
-  return 0;
+pthread_key_t g_debug_calls_disabled;
+
+extern "C" bool malloc_debug_initialize(HashTable* hash_table, const MallocDebug* malloc_dispatch) {
+  g_hash_table = hash_table;
+  g_malloc_dispatch = malloc_dispatch;
+
+  pthread_key_create(&g_debug_calls_disabled, NULL);
+
+  char debug_backlog[PROP_VALUE_MAX];
+  if (__system_property_get("libc.debug.malloc.backlog", debug_backlog)) {
+    g_malloc_debug_backlog = atoi(debug_backlog);
+    info_log("%s: setting backlog length to %d\n", getprogname(), g_malloc_debug_backlog);
+  }
+
+  // Check if backtracing should be disabled.
+  char env[PROP_VALUE_MAX];
+  if (__system_property_get("libc.debug.malloc.nobacktrace", env) && atoi(env) != 0) {
+    g_backtrace_enabled = false;
+    __libc_format_log(ANDROID_LOG_INFO, "libc", "not gathering backtrace information\n");
+  }
+
+  if (g_backtrace_enabled) {
+    backtrace_startup();
+  }
+
+  return true;
 }
 
-extern "C" void malloc_debug_finalize() {
-  ReportMemoryLeaks();
-  backtrace_shutdown();
+extern "C" void malloc_debug_finalize(int malloc_debug_level) {
+  // We only track leaks at level 10.
+  if (malloc_debug_level == 10) {
+    ReportMemoryLeaks();
+  }
+  if (g_backtrace_enabled) {
+    backtrace_shutdown();
+  }
+
+  pthread_setspecific(g_debug_calls_disabled, NULL);
 }
diff --git a/libc/bionic/malloc_debug_common.cpp b/libc/bionic/malloc_debug_common.cpp
index 85f7791..0b6a142 100644
--- a/libc/bionic/malloc_debug_common.cpp
+++ b/libc/bionic/malloc_debug_common.cpp
@@ -26,19 +26,17 @@
  * SUCH DAMAGE.
  */
 
-/*
- * Contains definition of structures, global variables, and implementation of
- * routines that are used by malloc leak detection code and other components in
- * the system. The trick is that some components expect these data and
- * routines to be defined / implemented in libc.so library, regardless
- * whether or not MALLOC_LEAK_CHECK macro is defined. To make things even
- * more tricky, malloc leak detection code, implemented in
- * libc_malloc_debug.so also requires access to these variables and routines
- * (to fill allocation entry hash table, for example). So, all relevant
- * variables and routines are defined / implemented here and exported
- * to all, leak detection code and other components via dynamic (libc.so),
- * or static (libc.a) linking.
- */
+// Contains definition of structures, global variables, and implementation of
+// routines that are used by malloc leak detection code and other components in
+// the system. The trick is that some components expect these data and
+// routines to be defined / implemented in libc.so library, regardless
+// whether or not MALLOC_LEAK_CHECK macro is defined. To make things even
+// more tricky, malloc leak detection code, implemented in
+// libc_malloc_debug.so also requires access to these variables and routines
+// (to fill allocation entry hash table, for example). So, all relevant
+// variables and routines are defined / implemented here and exported
+// to all, leak detection code and other components via dynamic (libc.so),
+// or static (libc.a) linking.
 
 #include "malloc_debug_common.h"
 
@@ -46,483 +44,484 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#include "dlmalloc.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
-/*
- * In a VM process, this is set to 1 after fork()ing out of zygote.
- */
+#if defined(USE_JEMALLOC)
+#include "jemalloc.h"
+#define Malloc(function)  je_ ## function
+#elif defined(USE_DLMALLOC)
+#include "dlmalloc.h"
+#define Malloc(function)  dl ## function
+#else
+#error "Either one of USE_DLMALLOC or USE_JEMALLOC must be defined."
+#endif
+
+// In a VM process, this is set to 1 after fork()ing out of zygote.
 int gMallocLeakZygoteChild = 0;
 
-pthread_mutex_t gAllocationsMutex = PTHREAD_MUTEX_INITIALIZER;
-HashTable gHashTable;
+static HashTable g_hash_table;
+
+// Support for malloc debugging.
+// Table for dispatching malloc calls, initialized with default dispatchers.
+static const MallocDebug __libc_malloc_default_dispatch __attribute__((aligned(32))) = {
+  Malloc(calloc),
+  Malloc(free),
+  Malloc(mallinfo),
+  Malloc(malloc),
+  Malloc(malloc_usable_size),
+  Malloc(memalign),
+  Malloc(posix_memalign),
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  Malloc(pvalloc),
+#endif
+  Malloc(realloc),
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  Malloc(valloc),
+#endif
+};
+
+// Selector of dispatch table to use for dispatching malloc calls.
+static const MallocDebug* __libc_malloc_dispatch = &__libc_malloc_default_dispatch;
+
+// Handle to shared library where actual memory allocation is implemented.
+// This library is loaded and memory allocation calls are redirected there
+// when libc.debug.malloc environment variable contains value other than
+// zero:
+// 1  - For memory leak detections.
+// 5  - For filling allocated / freed memory with patterns defined by
+//      CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros.
+// 10 - For adding pre-, and post- allocation stubs in order to detect
+//      buffer overruns.
+// Note that emulator's memory allocation instrumentation is not controlled by
+// libc.debug.malloc value, but rather by emulator, started with -memcheck
+// option. Note also, that if emulator has started with -memcheck option,
+// emulator's instrumented memory allocation will take over value saved in
+// libc.debug.malloc. In other words, if emulator has started with -memcheck
+// option, libc.debug.malloc value is ignored.
+// Actual functionality for debug levels 1-10 is implemented in
+// libc_malloc_debug_leak.so, while functionality for emulator's instrumented
+// allocations is implemented in libc_malloc_debug_qemu.so and can be run inside
+// the emulator only.
+#if !defined(LIBC_STATIC)
+static void* libc_malloc_impl_handle = NULL;
+#endif
+
+
+// The value of libc.debug.malloc.
+#if !defined(LIBC_STATIC)
+static int g_malloc_debug_level = 0;
+#endif
 
 // =============================================================================
 // output functions
 // =============================================================================
 
 static int hash_entry_compare(const void* arg1, const void* arg2) {
-    int result;
+  int result;
 
-    const HashEntry* e1 = *static_cast<HashEntry* const*>(arg1);
-    const HashEntry* e2 = *static_cast<HashEntry* const*>(arg2);
+  const HashEntry* e1 = *static_cast<HashEntry* const*>(arg1);
+  const HashEntry* e2 = *static_cast<HashEntry* const*>(arg2);
 
-    // if one or both arg pointers are null, deal gracefully
-    if (e1 == NULL) {
-        result = (e2 == NULL) ? 0 : 1;
-    } else if (e2 == NULL) {
-        result = -1;
+  // if one or both arg pointers are null, deal gracefully
+  if (e1 == NULL) {
+    result = (e2 == NULL) ? 0 : 1;
+  } else if (e2 == NULL) {
+    result = -1;
+  } else {
+    size_t nbAlloc1 = e1->allocations;
+    size_t nbAlloc2 = e2->allocations;
+    size_t size1 = e1->size & ~SIZE_FLAG_MASK;
+    size_t size2 = e2->size & ~SIZE_FLAG_MASK;
+    size_t alloc1 = nbAlloc1 * size1;
+    size_t alloc2 = nbAlloc2 * size2;
+
+    // sort in descending order by:
+    // 1) total size
+    // 2) number of allocations
+    //
+    // This is used for sorting, not determination of equality, so we don't
+    // need to compare the bit flags.
+    if (alloc1 > alloc2) {
+      result = -1;
+    } else if (alloc1 < alloc2) {
+      result = 1;
     } else {
-        size_t nbAlloc1 = e1->allocations;
-        size_t nbAlloc2 = e2->allocations;
-        size_t size1 = e1->size & ~SIZE_FLAG_MASK;
-        size_t size2 = e2->size & ~SIZE_FLAG_MASK;
-        size_t alloc1 = nbAlloc1 * size1;
-        size_t alloc2 = nbAlloc2 * size2;
-
-        // sort in descending order by:
-        // 1) total size
-        // 2) number of allocations
-        //
-        // This is used for sorting, not determination of equality, so we don't
-        // need to compare the bit flags.
-        if (alloc1 > alloc2) {
-            result = -1;
-        } else if (alloc1 < alloc2) {
-            result = 1;
-        } else {
-            if (nbAlloc1 > nbAlloc2) {
-                result = -1;
-            } else if (nbAlloc1 < nbAlloc2) {
-                result = 1;
-            } else {
-                result = 0;
-            }
-        }
+      if (nbAlloc1 > nbAlloc2) {
+        result = -1;
+      } else if (nbAlloc1 < nbAlloc2) {
+        result = 1;
+      } else {
+        result = 0;
+      }
     }
-    return result;
+  }
+  return result;
 }
 
-/*
- * Retrieve native heap information.
- *
- * "*info" is set to a buffer we allocate
- * "*overallSize" is set to the size of the "info" buffer
- * "*infoSize" is set to the size of a single entry
- * "*totalMemory" is set to the sum of all allocations we're tracking; does
- *   not include heap overhead
- * "*backtraceSize" is set to the maximum number of entries in the back trace
- */
+// Retrieve native heap information.
+//
+// "*info" is set to a buffer we allocate
+// "*overallSize" is set to the size of the "info" buffer
+// "*infoSize" is set to the size of a single entry
+// "*totalMemory" is set to the sum of all allocations we're tracking; does
+//   not include heap overhead
+// "*backtraceSize" is set to the maximum number of entries in the back trace
+
+// =============================================================================
+// Exported for use by ddms.
+// =============================================================================
 extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overallSize,
-        size_t* infoSize, size_t* totalMemory, size_t* backtraceSize) {
-    // don't do anything if we have invalid arguments
-    if (info == NULL || overallSize == NULL || infoSize == NULL ||
-            totalMemory == NULL || backtraceSize == NULL) {
-        return;
+    size_t* infoSize, size_t* totalMemory, size_t* backtraceSize) {
+  // Don't do anything if we have invalid arguments.
+  if (info == NULL || overallSize == NULL || infoSize == NULL ||
+    totalMemory == NULL || backtraceSize == NULL) {
+    return;
+  }
+  *totalMemory = 0;
+
+  ScopedPthreadMutexLocker locker(&g_hash_table.lock);
+  if (g_hash_table.count == 0) {
+    *info = NULL;
+    *overallSize = 0;
+    *infoSize = 0;
+    *backtraceSize = 0;
+    return;
+  }
+
+  HashEntry** list = static_cast<HashEntry**>(Malloc(malloc)(sizeof(void*) * g_hash_table.count));
+
+  // Get the entries into an array to be sorted.
+  size_t index = 0;
+  for (size_t i = 0 ; i < HASHTABLE_SIZE ; ++i) {
+    HashEntry* entry = g_hash_table.slots[i];
+    while (entry != NULL) {
+      list[index] = entry;
+      *totalMemory = *totalMemory + ((entry->size & ~SIZE_FLAG_MASK) * entry->allocations);
+      index++;
+      entry = entry->next;
     }
-    *totalMemory = 0;
+  }
 
-    ScopedPthreadMutexLocker locker(&gAllocationsMutex);
+  // XXX: the protocol doesn't allow variable size for the stack trace (yet)
+  *infoSize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * BACKTRACE_SIZE);
+  *overallSize = *infoSize * g_hash_table.count;
+  *backtraceSize = BACKTRACE_SIZE;
 
-    if (gHashTable.count == 0) {
-        *info = NULL;
-        *overallSize = 0;
-        *infoSize = 0;
-        *backtraceSize = 0;
-        return;
+  // now get a byte array big enough for this
+  *info = static_cast<uint8_t*>(Malloc(malloc)(*overallSize));
+  if (*info == NULL) {
+    *overallSize = 0;
+    Malloc(free)(list);
+    return;
+  }
+
+  qsort(list, g_hash_table.count, sizeof(void*), hash_entry_compare);
+
+  uint8_t* head = *info;
+  const size_t count = g_hash_table.count;
+  for (size_t i = 0 ; i < count ; ++i) {
+    HashEntry* entry = list[i];
+    size_t entrySize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * entry->numEntries);
+    if (entrySize < *infoSize) {
+      // We're writing less than a full entry, clear out the rest.
+      memset(head + entrySize, 0, *infoSize - entrySize);
+    } else {
+      // Make sure the amount we're copying doesn't exceed the limit.
+      entrySize = *infoSize;
     }
+    memcpy(head, &(entry->size), entrySize);
+    head += *infoSize;
+  }
 
-    HashEntry** list = static_cast<HashEntry**>(dlmalloc(sizeof(void*) * gHashTable.count));
-
-    // get the entries into an array to be sorted
-    int index = 0;
-    for (size_t i = 0 ; i < HASHTABLE_SIZE ; ++i) {
-        HashEntry* entry = gHashTable.slots[i];
-        while (entry != NULL) {
-            list[index] = entry;
-            *totalMemory = *totalMemory +
-                ((entry->size & ~SIZE_FLAG_MASK) * entry->allocations);
-            index++;
-            entry = entry->next;
-        }
-    }
-
-    // XXX: the protocol doesn't allow variable size for the stack trace (yet)
-    *infoSize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * BACKTRACE_SIZE);
-    *overallSize = *infoSize * gHashTable.count;
-    *backtraceSize = BACKTRACE_SIZE;
-
-    // now get a byte array big enough for this
-    *info = static_cast<uint8_t*>(dlmalloc(*overallSize));
-
-    if (*info == NULL) {
-        *overallSize = 0;
-        dlfree(list);
-        return;
-    }
-
-    qsort(list, gHashTable.count, sizeof(void*), hash_entry_compare);
-
-    uint8_t* head = *info;
-    const int count = gHashTable.count;
-    for (int i = 0 ; i < count ; ++i) {
-        HashEntry* entry = list[i];
-        size_t entrySize = (sizeof(size_t) * 2) + (sizeof(uintptr_t) * entry->numEntries);
-        if (entrySize < *infoSize) {
-            /* we're writing less than a full entry, clear out the rest */
-            memset(head + entrySize, 0, *infoSize - entrySize);
-        } else {
-            /* make sure the amount we're copying doesn't exceed the limit */
-            entrySize = *infoSize;
-        }
-        memcpy(head, &(entry->size), entrySize);
-        head += *infoSize;
-    }
-
-    dlfree(list);
+  Malloc(free)(list);
 }
 
 extern "C" void free_malloc_leak_info(uint8_t* info) {
-    dlfree(info);
+  Malloc(free)(info);
 }
 
-extern "C" struct mallinfo mallinfo() {
-    return dlmallinfo();
-}
-
-extern "C" void* valloc(size_t bytes) {
-    return dlvalloc(bytes);
-}
-
-extern "C" void* pvalloc(size_t bytes) {
-    return dlpvalloc(bytes);
-}
-
-extern "C" int posix_memalign(void** memptr, size_t alignment, size_t size) {
-    return dlposix_memalign(memptr, alignment, size);
-}
-
-/* Support for malloc debugging.
- * Note that if USE_DL_PREFIX is not defined, it's assumed that memory
- * allocation routines are implemented somewhere else, so all our custom
- * malloc routines should not be compiled at all.
- */
-#ifdef USE_DL_PREFIX
-
-/* Table for dispatching malloc calls, initialized with default dispatchers. */
-extern const MallocDebug __libc_malloc_default_dispatch;
-const MallocDebug __libc_malloc_default_dispatch __attribute__((aligned(32))) =
-{
-    dlmalloc, dlfree, dlcalloc, dlrealloc, dlmemalign, dlmalloc_usable_size,
-};
-
-/* Selector of dispatch table to use for dispatching malloc calls. */
-const MallocDebug* __libc_malloc_dispatch = &__libc_malloc_default_dispatch;
-
-extern "C" void* malloc(size_t bytes) {
-    return __libc_malloc_dispatch->malloc(bytes);
+// =============================================================================
+// Allocation functions
+// =============================================================================
+extern "C" void* calloc(size_t n_elements, size_t elem_size) {
+  return __libc_malloc_dispatch->calloc(n_elements, elem_size);
 }
 
 extern "C" void free(void* mem) {
-    __libc_malloc_dispatch->free(mem);
+  __libc_malloc_dispatch->free(mem);
 }
 
-extern "C" void* calloc(size_t n_elements, size_t elem_size) {
-    return __libc_malloc_dispatch->calloc(n_elements, elem_size);
+extern "C" struct mallinfo mallinfo() {
+  return __libc_malloc_dispatch->mallinfo();
 }
 
-extern "C" void* realloc(void* oldMem, size_t bytes) {
-    return __libc_malloc_dispatch->realloc(oldMem, bytes);
-}
-
-extern "C" void* memalign(size_t alignment, size_t bytes) {
-    return __libc_malloc_dispatch->memalign(alignment, bytes);
+extern "C" void* malloc(size_t bytes) {
+  return __libc_malloc_dispatch->malloc(bytes);
 }
 
 extern "C" size_t malloc_usable_size(const void* mem) {
-    return __libc_malloc_dispatch->malloc_usable_size(mem);
+  return __libc_malloc_dispatch->malloc_usable_size(mem);
 }
 
-/* We implement malloc debugging only in libc.so, so code below
- * must be excluded if we compile this file for static libc.a
- */
+extern "C" void* memalign(size_t alignment, size_t bytes) {
+  return __libc_malloc_dispatch->memalign(alignment, bytes);
+}
+
+extern "C" int posix_memalign(void** memptr, size_t alignment, size_t size) {
+  return __libc_malloc_dispatch->posix_memalign(memptr, alignment, size);
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* pvalloc(size_t bytes) {
+  return __libc_malloc_dispatch->pvalloc(bytes);
+}
+#endif
+
+extern "C" void* realloc(void* oldMem, size_t bytes) {
+  return __libc_malloc_dispatch->realloc(oldMem, bytes);
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* valloc(size_t bytes) {
+  return __libc_malloc_dispatch->valloc(bytes);
+}
+#endif
+
+// We implement malloc debugging only in libc.so, so the code below
+// must be excluded if we compile this file for static libc.a
 #ifndef LIBC_STATIC
 #include <sys/system_properties.h>
 #include <dlfcn.h>
 #include <stdio.h>
 #include "private/libc_logging.h"
 
-/* Table for dispatching malloc calls, depending on environment. */
-static MallocDebug gMallocUse __attribute__((aligned(32))) = {
-    dlmalloc, dlfree, dlcalloc, dlrealloc, dlmemalign, dlmalloc_usable_size
-};
-
-extern const char* __progname;
-
-/* Handle to shared library where actual memory allocation is implemented.
- * This library is loaded and memory allocation calls are redirected there
- * when libc.debug.malloc environment variable contains value other than
- * zero:
- * 1  - For memory leak detections.
- * 5  - For filling allocated / freed memory with patterns defined by
- *      CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros.
- * 10 - For adding pre-, and post- allocation stubs in order to detect
- *      buffer overruns.
- * Note that emulator's memory allocation instrumentation is not controlled by
- * libc.debug.malloc value, but rather by emulator, started with -memcheck
- * option. Note also, that if emulator has started with -memcheck option,
- * emulator's instrumented memory allocation will take over value saved in
- * libc.debug.malloc. In other words, if emulator has started with -memcheck
- * option, libc.debug.malloc value is ignored.
- * Actual functionality for debug levels 1-10 is implemented in
- * libc_malloc_debug_leak.so, while functionality for emultor's instrumented
- * allocations is implemented in libc_malloc_debug_qemu.so and can be run inside
- * the emulator only.
- */
-static void* libc_malloc_impl_handle = NULL;
-
-/* This variable is set to the value of property libc.debug.malloc.backlog,
- * when the value of libc.debug.malloc = 10.  It determines the size of the
- * backlog we use to detect multiple frees.  If the property is not set, the
- * backlog length defaults to BACKLOG_DEFAULT_LEN.
- */
-unsigned int gMallocDebugBacklog;
-#define BACKLOG_DEFAULT_LEN 100
-
-/* The value of libc.debug.malloc. */
-int gMallocDebugLevel;
-
 template<typename FunctionType>
 static void InitMallocFunction(void* malloc_impl_handler, FunctionType* func, const char* prefix, const char* suffix) {
-    char symbol[128];
-    snprintf(symbol, sizeof(symbol), "%s_%s", prefix, suffix);
-    *func = reinterpret_cast<FunctionType>(dlsym(malloc_impl_handler, symbol));
-    if (*func == NULL) {
-        error_log("%s: dlsym(\"%s\") failed", __progname, symbol);
-    }
+  char symbol[128];
+  snprintf(symbol, sizeof(symbol), "%s_%s", prefix, suffix);
+  *func = reinterpret_cast<FunctionType>(dlsym(malloc_impl_handler, symbol));
+  if (*func == NULL) {
+    error_log("%s: dlsym(\"%s\") failed", getprogname(), symbol);
+  }
 }
 
 static void InitMalloc(void* malloc_impl_handler, MallocDebug* table, const char* prefix) {
-    __libc_format_log(ANDROID_LOG_INFO, "libc", "%s: using libc.debug.malloc %d (%s)\n",
-                      __progname, gMallocDebugLevel, prefix);
+  __libc_format_log(ANDROID_LOG_INFO, "libc", "%s: using libc.debug.malloc %d (%s)\n",
+                    getprogname(), g_malloc_debug_level, prefix);
 
-    InitMallocFunction<MallocDebugMalloc>(malloc_impl_handler, &table->malloc, prefix, "malloc");
-    InitMallocFunction<MallocDebugFree>(malloc_impl_handler, &table->free, prefix, "free");
-    InitMallocFunction<MallocDebugCalloc>(malloc_impl_handler, &table->calloc, prefix, "calloc");
-    InitMallocFunction<MallocDebugRealloc>(malloc_impl_handler, &table->realloc, prefix, "realloc");
-    InitMallocFunction<MallocDebugMemalign>(malloc_impl_handler, &table->memalign, prefix, "memalign");
-    InitMallocFunction<MallocDebugMallocUsableSize>(malloc_impl_handler, &table->malloc_usable_size, prefix, "malloc_usable_size");
+  InitMallocFunction<MallocDebugCalloc>(malloc_impl_handler, &table->calloc, prefix, "calloc");
+  InitMallocFunction<MallocDebugFree>(malloc_impl_handler, &table->free, prefix, "free");
+  InitMallocFunction<MallocDebugMallinfo>(malloc_impl_handler, &table->mallinfo, prefix, "mallinfo");
+  InitMallocFunction<MallocDebugMalloc>(malloc_impl_handler, &table->malloc, prefix, "malloc");
+  InitMallocFunction<MallocDebugMallocUsableSize>(malloc_impl_handler, &table->malloc_usable_size, prefix, "malloc_usable_size");
+  InitMallocFunction<MallocDebugMemalign>(malloc_impl_handler, &table->memalign, prefix, "memalign");
+  InitMallocFunction<MallocDebugPosixMemalign>(malloc_impl_handler, &table->posix_memalign, prefix, "posix_memalign");
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  InitMallocFunction<MallocDebugPvalloc>(malloc_impl_handler, &table->pvalloc, prefix, "pvalloc");
+#endif
+  InitMallocFunction<MallocDebugRealloc>(malloc_impl_handler, &table->realloc, prefix, "realloc");
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  InitMallocFunction<MallocDebugValloc>(malloc_impl_handler, &table->valloc, prefix, "valloc");
+#endif
 }
 
-/* Initializes memory allocation framework once per process. */
+// Initializes memory allocation framework once per process.
 static void malloc_init_impl() {
-    const char* so_name = NULL;
-    MallocDebugInit malloc_debug_initialize = NULL;
-    unsigned int qemu_running = 0;
-    unsigned int memcheck_enabled = 0;
-    char env[PROP_VALUE_MAX];
-    char memcheck_tracing[PROP_VALUE_MAX];
-    char debug_program[PROP_VALUE_MAX];
+  const char* so_name = NULL;
+  MallocDebugInit malloc_debug_initialize = NULL;
+  unsigned int qemu_running = 0;
+  unsigned int memcheck_enabled = 0;
+  char env[PROP_VALUE_MAX];
+  char memcheck_tracing[PROP_VALUE_MAX];
+  char debug_program[PROP_VALUE_MAX];
 
-    /* Get custom malloc debug level. Note that emulator started with
-     * memory checking option will have priority over debug level set in
-     * libc.debug.malloc system property. */
-    if (__system_property_get("ro.kernel.qemu", env) && atoi(env)) {
-        qemu_running = 1;
-        if (__system_property_get("ro.kernel.memcheck", memcheck_tracing)) {
-            if (memcheck_tracing[0] != '0') {
-                // Emulator has started with memory tracing enabled. Enforce it.
-                gMallocDebugLevel = 20;
-                memcheck_enabled = 1;
-            }
-        }
+  // Get custom malloc debug level. Note that emulator started with
+  // memory checking option will have priority over debug level set in
+  // libc.debug.malloc system property.
+  if (__system_property_get("ro.kernel.qemu", env) && atoi(env)) {
+    qemu_running = 1;
+    if (__system_property_get("ro.kernel.memcheck", memcheck_tracing)) {
+      if (memcheck_tracing[0] != '0') {
+        // Emulator has started with memory tracing enabled. Enforce it.
+        g_malloc_debug_level = 20;
+        memcheck_enabled = 1;
+      }
     }
+  }
 
-    /* If debug level has not been set by memcheck option in the emulator,
-     * lets grab it from libc.debug.malloc system property. */
-    if (gMallocDebugLevel == 0 && __system_property_get("libc.debug.malloc", env)) {
-        gMallocDebugLevel = atoi(env);
+  // If debug level has not been set by memcheck option in the emulator,
+  // lets grab it from libc.debug.malloc system property.
+  if (g_malloc_debug_level == 0 && __system_property_get("libc.debug.malloc", env)) {
+    g_malloc_debug_level = atoi(env);
+  }
+
+  // Debug level 0 means that we should use default allocation routines.
+  if (g_malloc_debug_level == 0) {
+    return;
+  }
+
+  // If libc.debug.malloc.program is set and is not a substring of progname,
+  // then exit.
+  if (__system_property_get("libc.debug.malloc.program", debug_program)) {
+    if (!strstr(getprogname(), debug_program)) {
+      return;
     }
+  }
 
-    /* Debug level 0 means that we should use dlxxx allocation
-     * routines (default). */
-    if (gMallocDebugLevel == 0) {
+  // mksh is way too leaky. http://b/7291287.
+  if (g_malloc_debug_level >= 10) {
+    if (strcmp(getprogname(), "sh") == 0 || strcmp(getprogname(), "/system/bin/sh") == 0) {
+      return;
+    }
+  }
+
+  // Choose the appropriate .so for the requested debug level.
+  switch (g_malloc_debug_level) {
+    case 1:
+    case 5:
+    case 10:
+      so_name = "libc_malloc_debug_leak.so";
+      break;
+    case 20:
+      // Quick check: debug level 20 can only be handled in emulator.
+      if (!qemu_running) {
+        error_log("%s: Debug level %d can only be set in emulator\n",
+                  getprogname(), g_malloc_debug_level);
         return;
-    }
-
-    /* If libc.debug.malloc.program is set and is not a substring of progname,
-     * then exit.
-     */
-    if (__system_property_get("libc.debug.malloc.program", debug_program)) {
-        if (!strstr(__progname, debug_program)) {
-            return;
-        }
-    }
-
-    // mksh is way too leaky. http://b/7291287.
-    if (gMallocDebugLevel >= 10) {
-        if (strcmp(__progname, "sh") == 0 || strcmp(__progname, "/system/bin/sh") == 0) {
-            return;
-        }
-    }
-
-    // Choose the appropriate .so for the requested debug level.
-    switch (gMallocDebugLevel) {
-        case 1:
-        case 5:
-        case 10: {
-            char debug_backlog[PROP_VALUE_MAX];
-            if (__system_property_get("libc.debug.malloc.backlog", debug_backlog)) {
-                gMallocDebugBacklog = atoi(debug_backlog);
-                info_log("%s: setting backlog length to %d\n", __progname, gMallocDebugBacklog);
-            }
-            if (gMallocDebugBacklog == 0) {
-                gMallocDebugBacklog = BACKLOG_DEFAULT_LEN;
-            }
-            so_name = "/system/lib/libc_malloc_debug_leak.so";
-            break;
-        }
-        case 20:
-            // Quick check: debug level 20 can only be handled in emulator.
-            if (!qemu_running) {
-                error_log("%s: Debug level %d can only be set in emulator\n",
-                          __progname, gMallocDebugLevel);
-                return;
-            }
-            // Make sure that memory checking has been enabled in emulator.
-            if (!memcheck_enabled) {
-                error_log("%s: Memory checking is not enabled in the emulator\n",
-                          __progname);
-                return;
-            }
-            so_name = "/system/lib/libc_malloc_debug_qemu.so";
-            break;
-        default:
-            error_log("%s: Debug level %d is unknown\n", __progname, gMallocDebugLevel);
-            return;
-    }
-
-    // Load .so that implements the required malloc debugging functionality.
-    void* malloc_impl_handle = dlopen(so_name, RTLD_LAZY);
-    if (malloc_impl_handle == NULL) {
-        error_log("%s: Missing module %s required for malloc debug level %d: %s",
-                  __progname, so_name, gMallocDebugLevel, dlerror());
+      }
+      // Make sure that memory checking has been enabled in emulator.
+      if (!memcheck_enabled) {
+        error_log("%s: Memory checking is not enabled in the emulator\n", getprogname());
         return;
+      }
+      so_name = "libc_malloc_debug_qemu.so";
+      break;
+    default:
+      error_log("%s: Debug level %d is unknown\n", getprogname(), g_malloc_debug_level);
+      return;
+  }
+
+  // Load .so that implements the required malloc debugging functionality.
+  void* malloc_impl_handle = dlopen(so_name, RTLD_LAZY);
+  if (malloc_impl_handle == NULL) {
+    error_log("%s: Missing module %s required for malloc debug level %d: %s",
+              getprogname(), so_name, g_malloc_debug_level, dlerror());
+    return;
+  }
+
+  // Initialize malloc debugging in the loaded module.
+  malloc_debug_initialize = reinterpret_cast<MallocDebugInit>(dlsym(malloc_impl_handle,
+                                                                    "malloc_debug_initialize"));
+  if (malloc_debug_initialize == NULL) {
+    error_log("%s: Initialization routine is not found in %s\n", getprogname(), so_name);
+    dlclose(malloc_impl_handle);
+    return;
+  }
+  if (!malloc_debug_initialize(&g_hash_table, &__libc_malloc_default_dispatch)) {
+    dlclose(malloc_impl_handle);
+    return;
+  }
+
+  if (g_malloc_debug_level == 20) {
+    // For memory checker we need to do extra initialization.
+    typedef int (*MemCheckInit)(int, const char*);
+    MemCheckInit memcheck_initialize =
+      reinterpret_cast<MemCheckInit>(dlsym(malloc_impl_handle, "memcheck_initialize"));
+    if (memcheck_initialize == NULL) {
+      error_log("%s: memcheck_initialize routine is not found in %s\n",
+                getprogname(), so_name);
+      dlclose(malloc_impl_handle);
+      return;
     }
 
-    // Initialize malloc debugging in the loaded module.
-    malloc_debug_initialize = reinterpret_cast<MallocDebugInit>(dlsym(malloc_impl_handle,
-                                                                      "malloc_debug_initialize"));
-    if (malloc_debug_initialize == NULL) {
-        error_log("%s: Initialization routine is not found in %s\n",
-                  __progname, so_name);
-        dlclose(malloc_impl_handle);
-        return;
+    if (memcheck_initialize(MALLOC_ALIGNMENT, memcheck_tracing)) {
+      dlclose(malloc_impl_handle);
+      return;
     }
-    if (malloc_debug_initialize() == -1) {
-        dlclose(malloc_impl_handle);
-        return;
-    }
+  }
 
-    if (gMallocDebugLevel == 20) {
-        // For memory checker we need to do extra initialization.
-        typedef int (*MemCheckInit)(int, const char*);
-        MemCheckInit memcheck_initialize =
-            reinterpret_cast<MemCheckInit>(dlsym(malloc_impl_handle,
-                                                 "memcheck_initialize"));
-        if (memcheck_initialize == NULL) {
-            error_log("%s: memcheck_initialize routine is not found in %s\n",
-                      __progname, so_name);
-            dlclose(malloc_impl_handle);
-            return;
-        }
+  // No need to init the dispatch table because we can only get
+  // here if debug level is 1, 5, 10, or 20.
+  static MallocDebug malloc_dispatch_table __attribute__((aligned(32)));
+  switch (g_malloc_debug_level) {
+    case 1:
+      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "leak");
+      break;
+    case 5:
+      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "fill");
+      break;
+    case 10:
+      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "chk");
+      break;
+    case 20:
+      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "qemu_instrumented");
+      break;
+    default:
+      break;
+  }
 
-        if (memcheck_initialize(MALLOC_ALIGNMENT, memcheck_tracing)) {
-            dlclose(malloc_impl_handle);
-            return;
-        }
-    }
-
-
-    // Initialize malloc dispatch table with appropriate routines.
-    switch (gMallocDebugLevel) {
-        case 1:
-            InitMalloc(malloc_impl_handle, &gMallocUse, "leak");
-            break;
-        case 5:
-            InitMalloc(malloc_impl_handle, &gMallocUse, "fill");
-            break;
-        case 10:
-            InitMalloc(malloc_impl_handle, &gMallocUse, "chk");
-            break;
-        case 20:
-            InitMalloc(malloc_impl_handle, &gMallocUse, "qemu_instrumented");
-            break;
-        default:
-            break;
-    }
-
-    // Make sure dispatch table is initialized
-    if ((gMallocUse.malloc == NULL) ||
-        (gMallocUse.free == NULL) ||
-        (gMallocUse.calloc == NULL) ||
-        (gMallocUse.realloc == NULL) ||
-        (gMallocUse.memalign == NULL) ||
-        (gMallocUse.malloc_usable_size == NULL)) {
-        error_log("%s: some symbols for libc.debug.malloc level %d were not found (see above)",
-                  __progname, gMallocDebugLevel);
-        dlclose(malloc_impl_handle);
-    } else {
-        __libc_malloc_dispatch = &gMallocUse;
-        libc_malloc_impl_handle = malloc_impl_handle;
-    }
+  // Make sure dispatch table is initialized
+  if ((malloc_dispatch_table.calloc == NULL) ||
+      (malloc_dispatch_table.free == NULL) ||
+      (malloc_dispatch_table.mallinfo == NULL) ||
+      (malloc_dispatch_table.malloc == NULL) ||
+      (malloc_dispatch_table.malloc_usable_size == NULL) ||
+      (malloc_dispatch_table.memalign == NULL) ||
+      (malloc_dispatch_table.posix_memalign == NULL) ||
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+      (malloc_dispatch_table.pvalloc == NULL) ||
+#endif
+      (malloc_dispatch_table.realloc == NULL)
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+      || (malloc_dispatch_table.valloc == NULL)
+#endif
+      ) {
+    error_log("%s: some symbols for libc.debug.malloc level %d were not found (see above)",
+              getprogname(), g_malloc_debug_level);
+    dlclose(malloc_impl_handle);
+  } else {
+    __libc_malloc_dispatch = &malloc_dispatch_table;
+    libc_malloc_impl_handle = malloc_impl_handle;
+  }
 }
 
 static void malloc_fini_impl() {
-    // Our BSD stdio implementation doesn't close the standard streams, it only flushes them.
-    // And it doesn't do that until its atexit handler (_cleanup) is run, and we run first!
-    // It's great that other unclosed FILE*s show up as malloc leaks, but we need to manually
-    // clean up the standard streams ourselves.
-    fclose(stdin);
-    fclose(stdout);
-    fclose(stderr);
+  // Our BSD stdio implementation doesn't close the standard streams, it only flushes them.
+  // And it doesn't do that until its atexit handler is run, and we run first!
+  // It's great that other unclosed FILE*s show up as malloc leaks, but we need to manually
+  // clean up the standard streams ourselves.
+  fclose(stdin);
+  fclose(stdout);
+  fclose(stderr);
 
-    if (libc_malloc_impl_handle != NULL) {
-        MallocDebugFini malloc_debug_finalize =
-            reinterpret_cast<MallocDebugFini>(dlsym(libc_malloc_impl_handle,
-                                                    "malloc_debug_finalize"));
-        if (malloc_debug_finalize != NULL) {
-            malloc_debug_finalize();
-        }
+  if (libc_malloc_impl_handle != NULL) {
+    MallocDebugFini malloc_debug_finalize =
+      reinterpret_cast<MallocDebugFini>(dlsym(libc_malloc_impl_handle, "malloc_debug_finalize"));
+    if (malloc_debug_finalize != NULL) {
+      malloc_debug_finalize(g_malloc_debug_level);
     }
+  }
 }
 
-static pthread_once_t  malloc_init_once_ctl = PTHREAD_ONCE_INIT;
-static pthread_once_t  malloc_fini_once_ctl = PTHREAD_ONCE_INIT;
-
 #endif  // !LIBC_STATIC
-#endif  // USE_DL_PREFIX
 
-/* Initializes memory allocation framework.
- * This routine is called from __libc_init routines implemented
- * in libc_init_static.c and libc_init_dynamic.c files.
- */
+// Initializes memory allocation framework.
+// This routine is called from __libc_init routines implemented
+// in libc_init_static.c and libc_init_dynamic.c files.
 extern "C" __LIBC_HIDDEN__ void malloc_debug_init() {
-    /* We need to initialize malloc iff we implement here custom
-     * malloc routines (i.e. USE_DL_PREFIX is defined) for libc.so */
-#if defined(USE_DL_PREFIX) && !defined(LIBC_STATIC)
-    if (pthread_once(&malloc_init_once_ctl, malloc_init_impl)) {
-        error_log("Unable to initialize malloc_debug component.");
-    }
-#endif  // USE_DL_PREFIX && !LIBC_STATIC
+#if !defined(LIBC_STATIC)
+  static pthread_once_t malloc_init_once_ctl = PTHREAD_ONCE_INIT;
+  if (pthread_once(&malloc_init_once_ctl, malloc_init_impl)) {
+    error_log("Unable to initialize malloc_debug component.");
+  }
+#endif  // !LIBC_STATIC
 }
 
 extern "C" __LIBC_HIDDEN__ void malloc_debug_fini() {
-    /* We need to finalize malloc iff we implement here custom
-     * malloc routines (i.e. USE_DL_PREFIX is defined) for libc.so */
-#if defined(USE_DL_PREFIX) && !defined(LIBC_STATIC)
-    if (pthread_once(&malloc_fini_once_ctl, malloc_fini_impl)) {
-        error_log("Unable to finalize malloc_debug component.");
-    }
-#endif  // USE_DL_PREFIX && !LIBC_STATIC
+#if !defined(LIBC_STATIC)
+  static pthread_once_t malloc_fini_once_ctl = PTHREAD_ONCE_INIT;
+  if (pthread_once(&malloc_fini_once_ctl, malloc_fini_impl)) {
+    error_log("Unable to finalize malloc_debug component.");
+  }
+#endif  // !LIBC_STATIC
 }
diff --git a/libc/bionic/malloc_debug_common.h b/libc/bionic/malloc_debug_common.h
index 28be042..5c73da3 100644
--- a/libc/bionic/malloc_debug_common.h
+++ b/libc/bionic/malloc_debug_common.h
@@ -33,8 +33,11 @@
 #ifndef MALLOC_DEBUG_COMMON_H
 #define MALLOC_DEBUG_COMMON_H
 
+#include <pthread.h>
+#include <stdint.h>
 #include <stdlib.h>
 
+#include "private/bionic_config.h"
 #include "private/libc_logging.h"
 
 #define HASHTABLE_SIZE      1543
@@ -43,9 +46,7 @@
 #define SIZE_FLAG_ZYGOTE_CHILD  (1<<31)
 #define SIZE_FLAG_MASK          (SIZE_FLAG_ZYGOTE_CHILD)
 
-#define MAX_SIZE_T           (~(size_t)0)
-
-// This must match the alignment used by dlmalloc.
+// This must match the alignment used by the malloc implementation.
 #ifndef MALLOC_ALIGNMENT
 #define MALLOC_ALIGNMENT ((size_t)(2 * sizeof(void *)))
 #endif
@@ -66,40 +67,46 @@
 };
 
 struct HashTable {
+    pthread_mutex_t lock;
     size_t count;
     HashEntry* slots[HASHTABLE_SIZE];
 };
 
 /* Entry in malloc dispatch table. */
-typedef void* (*MallocDebugMalloc)(size_t);
-typedef void (*MallocDebugFree)(void*);
 typedef void* (*MallocDebugCalloc)(size_t, size_t);
-typedef void* (*MallocDebugRealloc)(void*, size_t);
-typedef void* (*MallocDebugMemalign)(size_t, size_t);
+typedef void (*MallocDebugFree)(void*);
+typedef struct mallinfo (*MallocDebugMallinfo)();
+typedef void* (*MallocDebugMalloc)(size_t);
 typedef size_t (*MallocDebugMallocUsableSize)(const void*);
+typedef void* (*MallocDebugMemalign)(size_t, size_t);
+typedef int (*MallocDebugPosixMemalign)(void**, size_t, size_t);
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+typedef void* (*MallocDebugPvalloc)(size_t);
+#endif
+typedef void* (*MallocDebugRealloc)(void*, size_t);
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+typedef void* (*MallocDebugValloc)(size_t);
+#endif
+
 struct MallocDebug {
-  MallocDebugMalloc malloc;
-  MallocDebugFree free;
   MallocDebugCalloc calloc;
-  MallocDebugRealloc realloc;
-  MallocDebugMemalign memalign;
+  MallocDebugFree free;
+  MallocDebugMallinfo mallinfo;
+  MallocDebugMalloc malloc;
   MallocDebugMallocUsableSize malloc_usable_size;
+  MallocDebugMemalign memalign;
+  MallocDebugPosixMemalign posix_memalign;
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  MallocDebugPvalloc pvalloc;
+#endif
+  MallocDebugRealloc realloc;
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  MallocDebugValloc valloc;
+#endif
 };
 
-/* Malloc debugging initialization and finalization routines.
- *
- * These routines must be implemented in .so modules that implement malloc
- * debugging. The are is called once per process from malloc_init_impl and
- * malloc_fini_impl respectively.
- *
- * They are implemented in bionic/libc/bionic/malloc_debug_common.c when malloc
- * debugging gets initialized for the process.
- *
- * MallocDebugInit returns:
- *    0 on success, -1 on failure.
- */
-typedef int (*MallocDebugInit)();
-typedef void (*MallocDebugFini)();
+typedef bool (*MallocDebugInit)(HashTable*, const MallocDebug*);
+typedef void (*MallocDebugFini)(int);
 
 // =============================================================================
 // log functions
diff --git a/libc/bionic/malloc_debug_disable.h b/libc/bionic/malloc_debug_disable.h
new file mode 100644
index 0000000..9503128
--- /dev/null
+++ b/libc/bionic/malloc_debug_disable.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef MALLOC_DEBUG_DISABLE_H
+#define MALLOC_DEBUG_DISABLE_H
+
+#include <pthread.h>
+
+#include "private/bionic_macros.h"
+
+// =============================================================================
+// Used to disable the debug allocation calls.
+// =============================================================================
+extern pthread_key_t g_debug_calls_disabled;
+
+static inline bool DebugCallsDisabled() {
+  return pthread_getspecific(g_debug_calls_disabled) != NULL;
+}
+
+class ScopedDisableDebugCalls {
+ public:
+  ScopedDisableDebugCalls() : disabled_(DebugCallsDisabled()) {
+    if (!disabled_) {
+      pthread_setspecific(g_debug_calls_disabled, reinterpret_cast<const void*>(1));
+    }
+  }
+  ~ScopedDisableDebugCalls() {
+    if (!disabled_) {
+      pthread_setspecific(g_debug_calls_disabled, NULL);
+    }
+  }
+
+ private:
+  bool disabled_;
+
+  DISALLOW_COPY_AND_ASSIGN(ScopedDisableDebugCalls);
+};
+
+#endif  // MALLOC_DEBUG_DISABLE_H
diff --git a/libc/bionic/malloc_debug_leak.cpp b/libc/bionic/malloc_debug_leak.cpp
index 3397def..df0f997 100644
--- a/libc/bionic/malloc_debug_leak.cpp
+++ b/libc/bionic/malloc_debug_leak.cpp
@@ -37,6 +37,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/param.h>
 #include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/system_properties.h>
@@ -46,9 +47,11 @@
 #include <unwind.h>
 
 #include "debug_stacktrace.h"
-#include "dlmalloc.h"
+#include "malloc_debug_backtrace.h"
 #include "malloc_debug_common.h"
+#include "malloc_debug_disable.h"
 
+#include "private/bionic_macros.h"
 #include "private/libc_logging.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
@@ -59,10 +62,9 @@
 #error MALLOC_LEAK_CHECK is not defined.
 #endif  // !MALLOC_LEAK_CHECK
 
-// Global variables defined in malloc_debug_common.c
 extern int gMallocLeakZygoteChild;
-extern pthread_mutex_t gAllocationsMutex;
-extern HashTable gHashTable;
+extern HashTable* g_hash_table;
+extern const MallocDebug* g_malloc_dispatch;
 
 // =============================================================================
 // stack trace functions
@@ -138,71 +140,67 @@
         size |= SIZE_FLAG_ZYGOTE_CHILD;
     }
 
-    HashEntry* entry = find_entry(&gHashTable, slot, backtrace, numEntries, size);
+    HashEntry* entry = find_entry(g_hash_table, slot, backtrace, numEntries, size);
 
     if (entry != NULL) {
         entry->allocations++;
     } else {
         // create a new entry
-        entry = static_cast<HashEntry*>(dlmalloc(sizeof(HashEntry) + numEntries*sizeof(uintptr_t)));
+        entry = static_cast<HashEntry*>(g_malloc_dispatch->malloc(sizeof(HashEntry) + numEntries*sizeof(uintptr_t)));
         if (!entry) {
             return NULL;
         }
         entry->allocations = 1;
         entry->slot = slot;
         entry->prev = NULL;
-        entry->next = gHashTable.slots[slot];
+        entry->next = g_hash_table->slots[slot];
         entry->numEntries = numEntries;
         entry->size = size;
 
         memcpy(entry->backtrace, backtrace, numEntries * sizeof(uintptr_t));
 
-        gHashTable.slots[slot] = entry;
+        g_hash_table->slots[slot] = entry;
 
         if (entry->next != NULL) {
             entry->next->prev = entry;
         }
 
         // we just added an entry, increase the size of the hashtable
-        gHashTable.count++;
+        g_hash_table->count++;
     }
 
     return entry;
 }
 
 static int is_valid_entry(HashEntry* entry) {
-    if (entry != NULL) {
-        int i;
-        for (i = 0 ; i < HASHTABLE_SIZE ; i++) {
-            HashEntry* e1 = gHashTable.slots[i];
-
-            while (e1 != NULL) {
-                if (e1 == entry) {
-                    return 1;
-                }
-
-                e1 = e1->next;
-            }
+  if (entry != NULL) {
+    for (size_t i = 0; i < HASHTABLE_SIZE; ++i) {
+      HashEntry* e1 = g_hash_table->slots[i];
+      while (e1 != NULL) {
+        if (e1 == entry) {
+          return 1;
         }
+        e1 = e1->next;
+      }
     }
-
-    return 0;
+  }
+  return 0;
 }
 
 static void remove_entry(HashEntry* entry) {
-    HashEntry* prev = entry->prev;
-    HashEntry* next = entry->next;
+  HashEntry* prev = entry->prev;
+  HashEntry* next = entry->next;
 
-    if (prev != NULL) entry->prev->next = next;
-    if (next != NULL) entry->next->prev = prev;
+  if (prev != NULL) entry->prev->next = next;
+  if (next != NULL) entry->next->prev = prev;
 
-    if (prev == NULL) {
-        // we are the head of the list. set the head to be next
-        gHashTable.slots[entry->slot] = entry->next;
-    }
+  if (prev == NULL) {
+    // we are the head of the list. set the head to be next
+    g_hash_table->slots[entry->slot] = entry->next;
+  }
 
-    // we just removed and entry, decrease the size of the hashtable
-    gHashTable.count--;
+  // we just removed and entry, decrease the size of the hashtable
+  g_hash_table->count--;
 }
 
 // =============================================================================
@@ -213,11 +211,11 @@
 #define CHK_SENTINEL_VALUE      0xeb
 
 extern "C" void* fill_calloc(size_t n_elements, size_t elem_size) {
-    return dlcalloc(n_elements, elem_size);
+    return g_malloc_dispatch->calloc(n_elements, elem_size);
 }
 
 extern "C" void* fill_malloc(size_t bytes) {
-    void* buffer = dlmalloc(bytes);
+    void* buffer = g_malloc_dispatch->malloc(bytes);
     if (buffer) {
         memset(buffer, CHK_SENTINEL_VALUE, bytes);
     }
@@ -225,17 +223,17 @@
 }
 
 extern "C" void fill_free(void* mem) {
-    size_t bytes = dlmalloc_usable_size(mem);
+    size_t bytes = g_malloc_dispatch->malloc_usable_size(mem);
     memset(mem, CHK_FILL_FREE, bytes);
-    dlfree(mem);
+    g_malloc_dispatch->free(mem);
 }
 
 extern "C" void* fill_realloc(void* mem, size_t bytes) {
-    size_t oldSize = dlmalloc_usable_size(mem);
-    void* newMem = dlrealloc(mem, bytes);
+    size_t oldSize = g_malloc_dispatch->malloc_usable_size(mem);
+    void* newMem = g_malloc_dispatch->realloc(mem, bytes);
     if (newMem) {
         // If this is larger than before, fill the extra with our pattern.
-        size_t newSize = dlmalloc_usable_size(newMem);
+        size_t newSize = g_malloc_dispatch->malloc_usable_size(newMem);
         if (newSize > oldSize) {
             memset(reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(newMem)+oldSize), CHK_FILL_FREE, newSize-oldSize);
         }
@@ -244,7 +242,7 @@
 }
 
 extern "C" void* fill_memalign(size_t alignment, size_t bytes) {
-    void* buffer = dlmemalign(alignment, bytes);
+    void* buffer = g_malloc_dispatch->memalign(alignment, bytes);
     if (buffer) {
         memset(buffer, CHK_SENTINEL_VALUE, bytes);
     }
@@ -254,9 +252,38 @@
 extern "C" size_t fill_malloc_usable_size(const void* mem) {
     // Since we didn't allocate extra bytes before or after, we can
     // report the normal usable size here.
-    return dlmalloc_usable_size(mem);
+    return g_malloc_dispatch->malloc_usable_size(mem);
 }
 
+extern "C" struct mallinfo fill_mallinfo() {
+  return g_malloc_dispatch->mallinfo();
+}
+
+extern "C" int fill_posix_memalign(void** memptr, size_t alignment, size_t size) {
+  if (!powerof2(alignment)) {
+    return EINVAL;
+  }
+  int saved_errno = errno;
+  *memptr = fill_memalign(alignment, size);
+  errno = saved_errno;
+  return (*memptr != NULL) ? 0 : ENOMEM;
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* fill_pvalloc(size_t bytes) {
+  size_t pagesize = getpagesize();
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) { // Overflow
+    return NULL;
+  }
+  return fill_memalign(pagesize, size);
+}
+
+extern "C" void* fill_valloc(size_t size) {
+  return fill_memalign(getpagesize(), size);
+}
+#endif
+
 // =============================================================================
 // malloc leak functions
 // =============================================================================
@@ -264,6 +291,10 @@
 static uint32_t MEMALIGN_GUARD      = 0xA1A41520;
 
 extern "C" void* leak_malloc(size_t bytes) {
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->malloc(bytes);
+    }
+
     // allocate enough space infront of the allocation to store the pointer for
     // the alloc structure. This will making free'ing the structer really fast!
 
@@ -272,15 +303,16 @@
 
     size_t size = bytes + sizeof(AllocationEntry);
     if (size < bytes) { // Overflow.
+        errno = ENOMEM;
         return NULL;
     }
 
-    void* base = dlmalloc(size);
+    void* base = g_malloc_dispatch->malloc(size);
     if (base != NULL) {
-        ScopedPthreadMutexLocker locker(&gAllocationsMutex);
+        ScopedPthreadMutexLocker locker(&g_hash_table->lock);
 
         uintptr_t backtrace[BACKTRACE_SIZE];
-        size_t numEntries = get_backtrace(backtrace, BACKTRACE_SIZE);
+        size_t numEntries = GET_BACKTRACE(backtrace, BACKTRACE_SIZE);
 
         AllocationEntry* header = reinterpret_cast<AllocationEntry*>(base);
         header->entry = record_backtrace(backtrace, numEntries, bytes);
@@ -295,43 +327,54 @@
 }
 
 extern "C" void leak_free(void* mem) {
-    if (mem != NULL) {
-        ScopedPthreadMutexLocker locker(&gAllocationsMutex);
+  if (DebugCallsDisabled()) {
+    return g_malloc_dispatch->free(mem);
+  }
 
-        // check the guard to make sure it is valid
-        AllocationEntry* header = to_header(mem);
+  if (mem == NULL) {
+    return;
+  }
 
-        if (header->guard != GUARD) {
-            // could be a memaligned block
-            if (header->guard == MEMALIGN_GUARD) {
-                // For memaligned blocks, header->entry points to the memory
-                // allocated through leak_malloc.
-                header = to_header(header->entry);
-            }
-        }
+  ScopedPthreadMutexLocker locker(&g_hash_table->lock);
 
-        if (header->guard == GUARD || is_valid_entry(header->entry)) {
-            // decrement the allocations
-            HashEntry* entry = header->entry;
-            entry->allocations--;
-            if (entry->allocations <= 0) {
-                remove_entry(entry);
-                dlfree(entry);
-            }
+  // check the guard to make sure it is valid
+  AllocationEntry* header = to_header(mem);
 
-            // now free the memory!
-            dlfree(header);
-        } else {
-            debug_log("WARNING bad header guard: '0x%x'! and invalid entry: %p\n",
-                    header->guard, header->entry);
-        }
+  if (header->guard != GUARD) {
+    // could be a memaligned block
+    if (header->guard == MEMALIGN_GUARD) {
+      // For memaligned blocks, header->entry points to the memory
+      // allocated through leak_malloc.
+      header = to_header(header->entry);
     }
+  }
+
+  if (header->guard == GUARD || is_valid_entry(header->entry)) {
+    // decrement the allocations
+    HashEntry* entry = header->entry;
+    entry->allocations--;
+    if (entry->allocations <= 0) {
+      remove_entry(entry);
+      g_malloc_dispatch->free(entry);
+    }
+
+    // now free the memory!
+    g_malloc_dispatch->free(header);
+  } else {
+    debug_log("WARNING bad header guard: '0x%x'! and invalid entry: %p\n",
+              header->guard, header->entry);
+  }
 }
 
 extern "C" void* leak_calloc(size_t n_elements, size_t elem_size) {
-    /* Fail on overflow - just to be safe even though this code runs only
-     * within the debugging C library, not the production one */
-    if (n_elements && MAX_SIZE_T / n_elements < elem_size) {
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->calloc(n_elements, elem_size);
+    }
+
+    // Fail on overflow - just to be safe even though this code runs only
+    // within the debugging C library, not the production one.
+    if (n_elements && SIZE_MAX / n_elements < elem_size) {
+        errno = ENOMEM;
         return NULL;
     }
     size_t size = n_elements * elem_size;
@@ -342,7 +385,41 @@
     return ptr;
 }
 
+extern "C" size_t leak_malloc_usable_size(const void* mem) {
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->malloc_usable_size(mem);
+    }
+
+    if (mem == NULL) {
+        return 0;
+    }
+
+    // Check the guard to make sure it is valid.
+    const AllocationEntry* header = const_to_header(mem);
+
+    if (header->guard == MEMALIGN_GUARD) {
+        // If this is a memalign'd pointer, then grab the header from
+        // entry.
+        header = const_to_header(header->entry);
+    } else if (header->guard != GUARD) {
+        debug_log("WARNING bad header guard: '0x%x'! and invalid entry: %p\n",
+                  header->guard, header->entry);
+        return 0;
+    }
+
+    size_t ret = g_malloc_dispatch->malloc_usable_size(header);
+    if (ret != 0) {
+        // The usable area starts at 'mem' and stops at 'header+ret'.
+        return reinterpret_cast<uintptr_t>(header) + ret - reinterpret_cast<uintptr_t>(mem);
+    }
+    return 0;
+}
+
 extern "C" void* leak_realloc(void* oldMem, size_t bytes) {
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->realloc(oldMem, bytes);
+    }
+
     if (oldMem == NULL) {
         return leak_malloc(bytes);
     }
@@ -355,29 +432,34 @@
     } else if (header->guard != GUARD) {
         debug_log("WARNING bad header guard: '0x%x'! and invalid entry: %p\n",
                    header->guard, header->entry);
+        errno = ENOMEM;
         return NULL;
     }
 
     newMem = leak_malloc(bytes);
     if (newMem != NULL) {
-        size_t oldSize = header->entry->size & ~SIZE_FLAG_MASK;
+        size_t oldSize = leak_malloc_usable_size(oldMem);
         size_t copySize = (oldSize <= bytes) ? oldSize : bytes;
         memcpy(newMem, oldMem, copySize);
+        leak_free(oldMem);
     }
-    leak_free(oldMem);
 
     return newMem;
 }
 
 extern "C" void* leak_memalign(size_t alignment, size_t bytes) {
+    if (DebugCallsDisabled()) {
+        return g_malloc_dispatch->memalign(alignment, bytes);
+    }
+
     // we can just use malloc
     if (alignment <= MALLOC_ALIGNMENT) {
         return leak_malloc(bytes);
     }
 
     // need to make sure it's a power of two
-    if (alignment & (alignment-1)) {
-        alignment = 1L << (31 - __builtin_clz(alignment));
+    if (!powerof2(alignment)) {
+        alignment = BIONIC_ROUND_UP_POWER_OF_2(alignment);
     }
 
     // here, alignment is at least MALLOC_ALIGNMENT<<1 bytes
@@ -410,26 +492,43 @@
     return base;
 }
 
-extern "C" size_t leak_malloc_usable_size(const void* mem) {
-    if (mem != NULL) {
-        // Check the guard to make sure it is valid.
-        const AllocationEntry* header = const_to_header((void*)mem);
-
-        if (header->guard == MEMALIGN_GUARD) {
-            // If this is a memalign'd pointer, then grab the header from
-            // entry.
-            header = const_to_header(header->entry);
-        } else if (header->guard != GUARD) {
-            debug_log("WARNING bad header guard: '0x%x'! and invalid entry: %p\n",
-                      header->guard, header->entry);
-            return 0;
-        }
-
-        size_t ret = dlmalloc_usable_size(header);
-        if (ret != 0) {
-            // The usable area starts at 'mem' and stops at 'header+ret'.
-            return reinterpret_cast<uintptr_t>(header) + ret - reinterpret_cast<uintptr_t>(mem);
-        }
-    }
-    return 0;
+extern "C" struct mallinfo leak_mallinfo() {
+  return g_malloc_dispatch->mallinfo();
 }
+
+extern "C" int leak_posix_memalign(void** memptr, size_t alignment, size_t size) {
+  if (DebugCallsDisabled()) {
+    return g_malloc_dispatch->posix_memalign(memptr, alignment, size);
+  }
+
+  if (!powerof2(alignment)) {
+    return EINVAL;
+  }
+  int saved_errno = errno;
+  *memptr = leak_memalign(alignment, size);
+  errno = saved_errno;
+  return (*memptr != NULL) ? 0 : ENOMEM;
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* leak_pvalloc(size_t bytes) {
+  if (DebugCallsDisabled()) {
+    return g_malloc_dispatch->pvalloc(bytes);
+  }
+
+  size_t pagesize = getpagesize();
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) { // Overflow
+    return NULL;
+  }
+  return leak_memalign(pagesize, size);
+}
+
+extern "C" void* leak_valloc(size_t size) {
+  if (DebugCallsDisabled()) {
+    return g_malloc_dispatch->valloc(size);
+  }
+
+  return leak_memalign(getpagesize(), size);
+}
+#endif
diff --git a/libc/bionic/malloc_debug_qemu.cpp b/libc/bionic/malloc_debug_qemu.cpp
index 5a91daa..b3b604d 100644
--- a/libc/bionic/malloc_debug_qemu.cpp
+++ b/libc/bionic/malloc_debug_qemu.cpp
@@ -47,12 +47,13 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <sys/param.h>
 #include <pthread.h>
 #include <unistd.h>
 #include <errno.h>
-#include "dlmalloc.h"
-#include "private/libc_logging.h"
 #include "malloc_debug_common.h"
+#include "private/bionic_macros.h"
+#include "private/libc_logging.h"
 
 /* This file should be included into the build only when
  * MALLOC_QEMU_INSTRUMENT macro is defined. */
@@ -335,6 +336,9 @@
 // Static data
 // =============================================================================
 
+// The underlying malloc implementation to use to get memory.
+static const MallocDebug* g_malloc_dispatch = NULL;
+
 /* Emulator's magic page address.
  * This page (mapped on /dev/qemu_trace device) is used to fire up events
  * in the emulator. */
@@ -344,7 +348,7 @@
  * has been initialized. */
 static uint32_t malloc_pid = 0;
 
-/* Memory allocation alignment that is used in dlmalloc.
+/* Memory allocation alignment that is used in the malloc implementation.
  * This variable is updated by memcheck_initialize routine. */
 static uint32_t malloc_alignment = 8;
 
@@ -574,12 +578,16 @@
 // API routines
 // =============================================================================
 
-extern "C" void* qemu_instrumented_malloc(size_t bytes);
-extern "C" void  qemu_instrumented_free(void* mem);
-extern "C" void* qemu_instrumented_calloc(size_t n_elements, size_t elem_size);
-extern "C" void* qemu_instrumented_realloc(void* mem, size_t bytes);
-extern "C" void* qemu_instrumented_memalign(size_t alignment, size_t bytes);
-extern "C" size_t qemu_instrumented_malloc_usable_size(const void* mem);
+extern "C" void* qemu_instrumented_calloc(size_t, size_t);
+extern "C" void  qemu_instrumented_free(void*);
+extern "C" struct mallinfo qemu_instrumented_mallinfo();
+extern "C" void* qemu_instrumented_malloc(size_t);
+extern "C" size_t qemu_instrumented_malloc_usable_size(const void*);
+extern "C" void* qemu_instrumented_memalign(size_t, size_t);
+extern "C" int qemu_instrumented_posix_memalign(void**, size_t, size_t);
+extern "C" void* qemu_instrumented_pvalloc(size_t);
+extern "C" void* qemu_instrumented_realloc(void*, size_t);
+extern "C" void* qemu_instrumented_valloc(size_t);
 
 /* Initializes malloc debugging instrumentation for the emulator.
  * This routine is called from malloc_init_impl routine implemented in
@@ -590,7 +598,9 @@
  * Return:
  *  0 on success, or -1 on failure.
 */
-extern "C" int malloc_debug_initialize() {
+extern "C" bool malloc_debug_initialize(HashTable*, const MallocDebug* malloc_dispatch) {
+    g_malloc_dispatch = malloc_dispatch;
+
     /* We will be using emulator's magic page to report memory allocation
      * activities. In essence, what magic page does, it translates writes to
      * the memory mapped spaces into writes to an I/O port that emulator
@@ -599,7 +609,7 @@
     int fd = open("/dev/qemu_trace", O_RDWR);
     if (fd < 0) {
         error_log("Unable to open /dev/qemu_trace");
-        return -1;
+        return false;
     } else {
         qtrace = mmap(NULL, PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
         close(fd);
@@ -607,14 +617,13 @@
         if (qtrace == MAP_FAILED) {
             qtrace = NULL;
             error_log("Unable to mmap /dev/qemu_trace");
-            return -1;
+            return false;
         }
     }
 
     /* Cache pid of the process this library has been initialized for. */
     malloc_pid = getpid();
-
-    return 0;
+    return true;
 }
 
 /* Completes malloc debugging instrumentation for the emulator.
@@ -677,15 +686,22 @@
 extern "C" void* qemu_instrumented_malloc(size_t bytes) {
     MallocDesc desc;
 
-    /* Initialize block descriptor and allocate memory. Note that dlmalloc
+    /* Initialize block descriptor and allocate memory. Note that malloc
      * returns a valid pointer on zero allocation. Lets mimic this behavior. */
     desc.prefix_size = DEFAULT_PREFIX_SIZE;
     desc.requested_bytes = bytes;
     desc.suffix_size = DEFAULT_SUFFIX_SIZE;
-    desc.ptr = dlmalloc(mallocdesc_alloc_size(&desc));
+    size_t size = mallocdesc_alloc_size(&desc);
+    if (size < bytes) { // Overflow
+        qemu_error_log("<libc_pid=%03u, pid=%03u> malloc: malloc(%zu) overflow caused failure.",
+                       malloc_pid, getpid(), bytes);
+        errno = ENOMEM;
+        return NULL;
+    }
+    desc.ptr = g_malloc_dispatch->malloc(size);
     if (desc.ptr == NULL) {
-        qemu_error_log("<libc_pid=%03u, pid=%03u> malloc(%zd): dlmalloc(%u) failed.",
-                  malloc_pid, getpid(), bytes, mallocdesc_alloc_size(&desc));
+        qemu_error_log("<libc_pid=%03u, pid=%03u> malloc(%zu): malloc(%zu) failed.",
+                       malloc_pid, getpid(), bytes, size);
         return NULL;
     }
 
@@ -693,13 +709,14 @@
     if (notify_qemu_malloc(&desc)) {
         log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: malloc: notify_malloc failed for ",
                   malloc_pid, getpid());
-        dlfree(desc.ptr);
+        g_malloc_dispatch->free(desc.ptr);
+        errno = ENOMEM;
         return NULL;
     } else {
 #if TEST_ACCESS_VIOLATIONS
         test_access_violation(&desc);
 #endif  // TEST_ACCESS_VIOLATIONS
-        log_mdesc(info, &desc, "+++ <libc_pid=%03u, pid=%03u> malloc(%zd) -> ",
+        log_mdesc(info, &desc, "+++ <libc_pid=%03u, pid=%03u> malloc(%zu) -> ",
                   malloc_pid, getpid(), bytes);
         return mallocdesc_user_ptr(&desc);
     }
@@ -714,7 +731,7 @@
 
     if (mem == NULL) {
         // Just let go NULL free
-        dlfree(mem);
+        g_malloc_dispatch->free(mem);
         return;
     }
 
@@ -745,7 +762,7 @@
     } else {
         log_mdesc(info, &desc, "--- <libc_pid=%03u, pid=%03u> free(%p) -> ",
                   malloc_pid, getpid(), mem);
-        dlfree(desc.ptr);
+        g_malloc_dispatch->free(desc.ptr);
     }
 }
 
@@ -756,13 +773,16 @@
     if (n_elements == 0 || elem_size == 0) {
         // Just let go zero bytes allocation.
         qemu_info_log("::: <libc_pid=%03u, pid=%03u>: Zero calloc redir to malloc",
-                 malloc_pid, getpid());
+                      malloc_pid, getpid());
         return qemu_instrumented_malloc(0);
     }
 
-    /* Fail on overflow - just to be safe even though this code runs only
-     * within the debugging C library, not the production one */
-    if (n_elements && MAX_SIZE_T / n_elements < elem_size) {
+    // Fail on overflow - just to be safe even though this code runs only
+    // within the debugging C library, not the production one.
+    if (n_elements && SIZE_MAX / n_elements < elem_size) {
+        qemu_error_log("<libc_pid=%03u, pid=%03u> calloc: calloc(%zu, %zu) overflow caused failure.",
+                       malloc_pid, getpid(), n_elements, elem_size);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -788,6 +808,12 @@
     }
     desc.requested_bytes = n_elements * elem_size;
     size_t total_size = desc.requested_bytes + desc.prefix_size + desc.suffix_size;
+    if (total_size < desc.requested_bytes) { // Overflow
+        qemu_error_log("<libc_pid=%03u, pid=%03u> calloc: calloc(%zu, %zu) overflow caused failure.",
+                       malloc_pid, getpid(), n_elements, elem_size);
+        errno = ENOMEM;
+        return NULL;
+    }
     size_t total_elements = total_size / elem_size;
     total_size %= elem_size;
     if (total_size != 0) {
@@ -795,24 +821,25 @@
         total_elements++;
         desc.suffix_size += (elem_size - total_size);
     }
-    desc.ptr = dlcalloc(total_elements, elem_size);
+    desc.ptr = g_malloc_dispatch->calloc(total_elements, elem_size);
     if (desc.ptr == NULL) {
-        error_log("<libc_pid=%03u, pid=%03u> calloc: dlcalloc(%zd(%zd), %zd) (prx=%u, sfx=%u) failed.",
+        error_log("<libc_pid=%03u, pid=%03u> calloc: calloc(%zu(%zu), %zu) (prx=%u, sfx=%u) failed.",
                    malloc_pid, getpid(), n_elements, total_elements, elem_size,
                    desc.prefix_size, desc.suffix_size);
         return NULL;
     }
 
     if (notify_qemu_malloc(&desc)) {
-        log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: calloc(%zd(%zd), %zd): notify_malloc failed for ",
+        log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: calloc(%zu(%zu), %zu): notify_malloc failed for ",
                   malloc_pid, getpid(), n_elements, total_elements, elem_size);
-        dlfree(desc.ptr);
+        g_malloc_dispatch->free(desc.ptr);
+        errno = ENOMEM;
         return NULL;
     } else {
 #if TEST_ACCESS_VIOLATIONS
         test_access_violation(&desc);
 #endif  // TEST_ACCESS_VIOLATIONS
-        log_mdesc(info, &desc, "### <libc_pid=%03u, pid=%03u> calloc(%zd(%zd), %zd) -> ",
+        log_mdesc(info, &desc, "### <libc_pid=%03u, pid=%03u> calloc(%zu(%zu), %zu) -> ",
                   malloc_pid, getpid(), n_elements, total_elements, elem_size);
         return mallocdesc_user_ptr(&desc);
     }
@@ -825,33 +852,30 @@
  * should not expect that pointer returned after shrinking will remain the same.
  */
 extern "C" void* qemu_instrumented_realloc(void* mem, size_t bytes) {
-    MallocDesc new_desc;
-    MallocDesc cur_desc;
-    size_t to_copy;
-    void* ret;
-
     if (mem == NULL) {
         // Nothing to realloc. just do regular malloc.
-        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %zd) redir to malloc",
-                 malloc_pid, getpid(), mem, bytes);
+        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %zu) redir to malloc",
+                      malloc_pid, getpid(), mem, bytes);
         return qemu_instrumented_malloc(bytes);
     }
 
     if (bytes == 0) {
         // This is a "free" condition.
-        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %zd) redir to free and malloc",
-                 malloc_pid, getpid(), mem, bytes);
+        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %zu) redir to free and malloc",
+                      malloc_pid, getpid(), mem, bytes);
         qemu_instrumented_free(mem);
 
-        // This is what dlrealloc does for a "free" realloc.
+        // This is what realloc does for a "free" realloc.
         return NULL;
     }
 
     // Query emulator for the reallocating block information.
+    MallocDesc cur_desc;
     if (query_qemu_malloc_info(mem, &cur_desc, 2)) {
         // Note that this violation should be already caught in the emulator.
-        error_log("<libc_pid=%03u, pid=%03u>: realloc(%p, %zd) query_info failed.",
+        error_log("<libc_pid=%03u, pid=%03u>: realloc(%p, %zu) query_info failed.",
                   malloc_pid, getpid(), mem, bytes);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -863,8 +887,9 @@
      * for this memory block. Note that this violation should be already caught
      * in the emulator.*/
     if (mem != mallocdesc_user_ptr(&cur_desc)) {
-        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zd) is invalid for ",
+        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu) is invalid for ",
                   malloc_pid, getpid(), mem, bytes);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -874,31 +899,38 @@
      * for this block that is stored in the emulator. */
 
     // Initialize descriptor for the new block.
+    MallocDesc new_desc;
     new_desc.prefix_size = DEFAULT_PREFIX_SIZE;
     new_desc.requested_bytes = bytes;
     new_desc.suffix_size = DEFAULT_SUFFIX_SIZE;
-    new_desc.ptr = dlmalloc(mallocdesc_alloc_size(&new_desc));
-    if (new_desc.ptr == NULL) {
-        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zd): dlmalloc(%u) failed on ",
-                  malloc_pid, getpid(), mem, bytes,
-                  mallocdesc_alloc_size(&new_desc));
+    size_t new_size = mallocdesc_alloc_size(&new_desc);
+    if (new_size < bytes) { // Overflow
+        qemu_error_log("<libc_pid=%03u, pid=%03u>: realloc(%p, %zu): malloc(%zu) failed due to overflow",
+                       malloc_pid, getpid(), mem, bytes, new_size);
+        errno = ENOMEM;
         return NULL;
     }
-    ret = mallocdesc_user_ptr(&new_desc);
+    new_desc.ptr = g_malloc_dispatch->malloc(new_size);
+    if (new_desc.ptr == NULL) {
+        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu): malloc(%zu) failed on ",
+                  malloc_pid, getpid(), mem, bytes, new_size);
+        return NULL;
+    }
+    void* new_mem = mallocdesc_user_ptr(&new_desc);
 
     // Copy user data from old block to the new one.
-    to_copy = bytes < cur_desc.requested_bytes ? bytes :
-                                                 cur_desc.requested_bytes;
+    size_t to_copy = bytes < cur_desc.requested_bytes ? bytes : cur_desc.requested_bytes;
     if (to_copy != 0) {
-        memcpy(ret, mallocdesc_user_ptr(&cur_desc), to_copy);
+        memcpy(new_mem, mallocdesc_user_ptr(&cur_desc), to_copy);
     }
 
     // Register new block with emulator.
     if (notify_qemu_malloc(&new_desc)) {
-        log_mdesc(error, &new_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zd) notify_malloc failed -> ",
+        log_mdesc(error, &new_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu) notify_malloc failed -> ",
                   malloc_pid, getpid(), mem, bytes);
         log_mdesc(error, &cur_desc, "                                                                <- ");
-        dlfree(new_desc.ptr);
+        g_malloc_dispatch->free(new_desc.ptr);
+        errno = ENOMEM;
         return NULL;
     }
 
@@ -908,21 +940,22 @@
 
     // Free old block.
     if (notify_qemu_free(mem)) {
-        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zd): notify_free failed for ",
+        log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %zu): notify_free failed for ",
                   malloc_pid, getpid(), mem, bytes);
         /* Since we registered new decriptor with the emulator, we need
          * to unregister it before freeing newly allocated block. */
         notify_qemu_free(mallocdesc_user_ptr(&new_desc));
-        dlfree(new_desc.ptr);
+        g_malloc_dispatch->free(new_desc.ptr);
+        errno = ENOMEM;
         return NULL;
     }
-    dlfree(cur_desc.ptr);
+    g_malloc_dispatch->free(cur_desc.ptr);
 
-    log_mdesc(info, &new_desc, "=== <libc_pid=%03u, pid=%03u>: realloc(%p, %zd) -> ",
+    log_mdesc(info, &new_desc, "=== <libc_pid=%03u, pid=%03u>: realloc(%p, %zu) -> ",
               malloc_pid, getpid(), mem, bytes);
     log_mdesc(info, &cur_desc, "                                               <- ");
 
-    return ret;
+    return new_mem;
 }
 
 /* This routine serves as entry point for 'memalign'.
@@ -933,30 +966,40 @@
 
     if (bytes == 0) {
         // Just let go zero bytes allocation.
-        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: memalign(%zx, %zd) redir to malloc",
+        qemu_info_log("::: <libc_pid=%03u, pid=%03u>: memalign(%zx, %zu) redir to malloc",
                  malloc_pid, getpid(), alignment, bytes);
         return qemu_instrumented_malloc(0);
     }
 
-    /* Prefix size for aligned allocation must be equal to the alignment used
-     * for allocation in order to ensure proper alignment of the returned
-     * pointer, in case that alignment requirement is greater than prefix
-     * size. */
-    desc.prefix_size = alignment > DEFAULT_PREFIX_SIZE ? alignment :
-                                                         DEFAULT_PREFIX_SIZE;
+    // Prefix size for aligned allocation must be equal to the alignment used
+    // for allocation in order to ensure proper alignment of the returned
+    // pointer. in case that alignment requirement is greater than prefix
+    // size.
+    if (alignment < DEFAULT_PREFIX_SIZE) {
+        alignment = DEFAULT_PREFIX_SIZE;
+    } else if (!powerof2(alignment)) {
+        alignment = BIONIC_ROUND_UP_POWER_OF_2(alignment);
+    }
+    desc.prefix_size = alignment;
     desc.requested_bytes = bytes;
     desc.suffix_size = DEFAULT_SUFFIX_SIZE;
-    desc.ptr = dlmemalign(desc.prefix_size, mallocdesc_alloc_size(&desc));
+    size_t size = mallocdesc_alloc_size(&desc);
+    if (size < bytes) { // Overflow
+        qemu_error_log("<libc_pid=%03u, pid=%03u> memalign(%zx, %zu): malloc(%zu) failed due to overflow.",
+                       malloc_pid, getpid(), alignment, bytes, size);
+
+        return NULL;
+    }
+    desc.ptr = g_malloc_dispatch->memalign(desc.prefix_size, size);
     if (desc.ptr == NULL) {
-        error_log("<libc_pid=%03u, pid=%03u> memalign(%zx, %zd): dlmalloc(%u) failed.",
-                  malloc_pid, getpid(), alignment, bytes,
-                  mallocdesc_alloc_size(&desc));
+        error_log("<libc_pid=%03u, pid=%03u> memalign(%zx, %zu): malloc(%zu) failed.",
+                  malloc_pid, getpid(), alignment, bytes, size);
         return NULL;
     }
     if (notify_qemu_malloc(&desc)) {
-        log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: memalign(%zx, %zd): notify_malloc failed for ",
+        log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: memalign(%zx, %zu): notify_malloc failed for ",
                   malloc_pid, getpid(), alignment, bytes);
-        dlfree(desc.ptr);
+        g_malloc_dispatch->free(desc.ptr);
         return NULL;
     }
 
@@ -964,7 +1007,7 @@
     test_access_violation(&desc);
 #endif  // TEST_ACCESS_VIOLATIONS
 
-    log_mdesc(info, &desc, "@@@ <libc_pid=%03u, pid=%03u> memalign(%zx, %zd) -> ",
+    log_mdesc(info, &desc, "@@@ <libc_pid=%03u, pid=%03u> memalign(%zx, %zu) -> ",
               malloc_pid, getpid(), alignment, bytes);
     return mallocdesc_user_ptr(&desc);
 }
@@ -992,3 +1035,34 @@
     /* during instrumentation, we can't really report anything more than requested_bytes */
     return cur_desc.requested_bytes;
 }
+
+extern "C" struct mallinfo qemu_instrumented_mallinfo() {
+  return g_malloc_dispatch->mallinfo();
+}
+
+extern "C" int qemu_instrumented_posix_memalign(void** memptr, size_t alignment, size_t size) {
+  if ((alignment & (alignment - 1)) != 0) {
+    qemu_error_log("<libc_pid=%03u, pid=%03u> posix_memalign(%p, %zu, %zu): invalid alignment.",
+                   malloc_pid, getpid(), memptr, alignment, size);
+    return EINVAL;
+  }
+  int saved_errno = errno;
+  *memptr = qemu_instrumented_memalign(alignment, size);
+  errno = saved_errno;
+  return (*memptr != NULL) ? 0 : ENOMEM;
+}
+
+extern "C" void* qemu_instrumented_pvalloc(size_t bytes) {
+  size_t pagesize = getpagesize();
+  size_t size = BIONIC_ALIGN(bytes, pagesize);
+  if (size < bytes) { // Overflow
+    qemu_error_log("<libc_pid=%03u, pid=%03u> pvalloc(%zu): overflow (%zu).",
+                   malloc_pid, getpid(), bytes, size);
+    return NULL;
+  }
+  return qemu_instrumented_memalign(pagesize, size);
+}
+
+extern "C" void* qemu_instrumented_valloc(size_t size) {
+  return qemu_instrumented_memalign(getpagesize(), size);
+}
diff --git a/libc/bionic/mbrtoc16.cpp b/libc/bionic/mbrtoc16.cpp
new file mode 100644
index 0000000..6878a11
--- /dev/null
+++ b/libc/bionic/mbrtoc16.cpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <uchar.h>
+#include <wchar.h>
+
+#include "private/bionic_mbstate.h"
+
+static inline bool mbspartialc16(const mbstate_t* state) {
+  return mbstate_get_byte(state, 3) != 0;
+}
+
+static size_t begin_surrogate(char32_t c32, char16_t* pc16,
+                              size_t nconv, mbstate_t* state) {
+  c32 -= 0x10000;
+  char16_t trail = (c32 & 0x3ff) | 0xdc00;
+
+  mbstate_set_byte(state, 0, trail & 0x00ff);
+  mbstate_set_byte(state, 1, (trail & 0xff00) >> 8);
+  mbstate_set_byte(state, 3, nconv & 0xff);
+
+  *pc16 = ((c32 & 0xffc00) >> 10) | 0xd800;
+  // Defined by POSIX as return value for first surrogate character.
+  return static_cast<size_t>(-3);
+}
+
+static size_t finish_surrogate(char16_t* pc16, mbstate_t* state) {
+  char16_t trail = mbstate_get_byte(state, 1) << 8 |
+                   mbstate_get_byte(state, 0);
+  *pc16 = trail;
+  return reset_and_return(mbstate_get_byte(state, 3), state);
+}
+
+size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps) {
+  static mbstate_t __private_state;
+  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+
+  char16_t __private_pc16;
+  if (pc16 == NULL) {
+    pc16 = &__private_pc16;
+  }
+
+  if (mbspartialc16(state)) {
+    return finish_surrogate(pc16, state);
+  }
+
+  char32_t c32;
+  size_t nconv = mbrtoc32(&c32, s, n, state);
+  if (__MB_IS_ERR(nconv)) {
+    return nconv;
+  } else if (nconv == 0) {
+    return reset_and_return(nconv, state);
+  } else if (c32 > 0x10ffff) {
+    // Input cannot be encoded as UTF-16.
+    return reset_and_return_illegal(EILSEQ, state);
+  } else if (c32 < 0x10000) {
+    *pc16 = static_cast<char16_t>(c32);
+    return reset_and_return(nconv, state);
+  } else {
+    return begin_surrogate(c32, pc16, nconv, state);
+  }
+}
diff --git a/libc/bionic/mbrtoc32.cpp b/libc/bionic/mbrtoc32.cpp
new file mode 100644
index 0000000..bd40ecf
--- /dev/null
+++ b/libc/bionic/mbrtoc32.cpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <sys/param.h>
+#include <uchar.h>
+#include <wchar.h>
+
+#include "private/bionic_mbstate.h"
+
+size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps) {
+  static mbstate_t __private_state;
+  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+
+  // We should never get to a state which has all 4 bytes of the sequence set.
+  // Full state verification is done when decoding the sequence (after we have
+  // all the bytes).
+  if (mbstate_get_byte(state, 3) != 0) {
+    return reset_and_return_illegal(EINVAL, state);
+  }
+
+  if (s == NULL) {
+    s = "";
+    n = 1;
+    pc32 = NULL;
+  }
+
+  if (n == 0) {
+    return 0;
+  }
+
+  uint8_t ch;
+  if (mbsinit(state) && (((ch = static_cast<uint8_t>(*s)) & ~0x7f) == 0)) {
+    // Fast path for plain ASCII characters.
+    if (pc32 != NULL) {
+      *pc32 = ch;
+    }
+    return (ch != '\0' ? 1 : 0);
+  }
+
+  // Determine the number of octets that make up this character
+  // from the first octet, and a mask that extracts the
+  // interesting bits of the first octet. We already know
+  // the character is at least two bytes long.
+  size_t length;
+  int mask;
+
+  // We also specify a lower bound for the character code to
+  // detect redundant, non-"shortest form" encodings. For
+  // example, the sequence C0 80 is _not_ a legal representation
+  // of the null character. This enforces a 1-to-1 mapping
+  // between character codes and their multibyte representations.
+  char32_t lower_bound;
+
+  // The first byte in the state (if any) tells the length.
+  size_t bytes_so_far = mbstate_bytes_so_far(state);
+  ch = bytes_so_far > 0 ? mbstate_get_byte(state, 0) : static_cast<uint8_t>(*s);
+  if ((ch & 0x80) == 0) {
+    mask = 0x7f;
+    length = 1;
+    lower_bound = 0;
+  } else if ((ch & 0xe0) == 0xc0) {
+    mask = 0x1f;
+    length = 2;
+    lower_bound = 0x80;
+  } else if ((ch & 0xf0) == 0xe0) {
+    mask = 0x0f;
+    length = 3;
+    lower_bound = 0x800;
+  } else if ((ch & 0xf8) == 0xf0) {
+    mask = 0x07;
+    length = 4;
+    lower_bound = 0x10000;
+  } else {
+    // Malformed input; input is not UTF-8. See RFC 3629.
+    return reset_and_return_illegal(EILSEQ, state);
+  }
+
+  // Fill in the state.
+  size_t bytes_wanted = length - bytes_so_far;
+  size_t i;
+  for (i = 0; i < MIN(bytes_wanted, n); i++) {
+    if (!mbsinit(state) && ((*s & 0xc0) != 0x80)) {
+      // Malformed input; bad characters in the middle of a character.
+      return reset_and_return_illegal(EILSEQ, state);
+    }
+    mbstate_set_byte(state, bytes_so_far + i, *s++);
+  }
+  if (i < bytes_wanted) {
+    return __MB_ERR_INCOMPLETE_SEQUENCE;
+  }
+
+  // Decode the octet sequence representing the character in chunks
+  // of 6 bits, most significant first.
+  char32_t c32 = mbstate_get_byte(state, 0) & mask;
+  for (i = 1; i < length; i++) {
+    c32 <<= 6;
+    c32 |= mbstate_get_byte(state, i) & 0x3f;
+  }
+
+  if (c32 < lower_bound) {
+    // Malformed input; redundant encoding.
+    return reset_and_return_illegal(EILSEQ, state);
+  }
+  if ((c32 >= 0xd800 && c32 <= 0xdfff) || c32 == 0xfffe || c32 == 0xffff) {
+    // Malformed input; invalid code points.
+    return reset_and_return_illegal(EILSEQ, state);
+  }
+  if (pc32 != NULL) {
+    *pc32 = c32;
+  }
+  return reset_and_return(c32 == U'\0' ? 0 : bytes_wanted, state);
+}
diff --git a/libc/bionic/mbstate.cpp b/libc/bionic/mbstate.cpp
new file mode 100644
index 0000000..cb327d8
--- /dev/null
+++ b/libc/bionic/mbstate.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "private/bionic_mbstate.h"
+
+#include <errno.h>
+
+__LIBC_HIDDEN__ size_t mbstate_bytes_so_far(const mbstate_t* ps) {
+  return
+    (ps->__seq[2] != 0) ? 3 :
+    (ps->__seq[1] != 0) ? 2 :
+    (ps->__seq[0] != 0) ? 1 : 0;
+}
+
+__LIBC_HIDDEN__ void mbstate_set_byte(mbstate_t* ps, int i, char byte) {
+  ps->__seq[i] = static_cast<uint8_t>(byte);
+}
+
+__LIBC_HIDDEN__ uint8_t mbstate_get_byte(const mbstate_t* ps, int n) {
+  return ps->__seq[n];
+}
+
+__LIBC_HIDDEN__ size_t reset_and_return_illegal(int _errno, mbstate_t* ps) {
+  errno = _errno;
+  *(reinterpret_cast<uint32_t*>(ps->__seq)) = 0;
+  return __MB_ERR_ILLEGAL_SEQUENCE;
+}
+
+__LIBC_HIDDEN__ size_t reset_and_return(int _return, mbstate_t* ps) {
+  *(reinterpret_cast<uint32_t*>(ps->__seq)) = 0;
+  return _return;
+}
diff --git a/libc/bionic/md5.c b/libc/bionic/md5.c
deleted file mode 100644
index ba4aaed..0000000
--- a/libc/bionic/md5.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-
-__RCSID("$Heimdal: md5.c,v 1.15 2001/01/29 04:33:44 assar Exp $"
-        "$NetBSD: md5.c,v 1.1.1.4 2002/09/12 12:41:42 joda Exp $");
-#endif
-
-#include <endian.h>
-#include "md5.h"
-#include "hash.h"
-
-#define A m->counter[0]
-#define B m->counter[1]
-#define C m->counter[2]
-#define D m->counter[3]
-#define X data
-
-void
-MD5_Init (struct md5 *m)
-{
-  m->sz[0] = 0;
-  m->sz[1] = 0;
-  D = 0x10325476;
-  C = 0x98badcfe;
-  B = 0xefcdab89;
-  A = 0x67452301;
-}
-
-#define F(x,y,z) CRAYFIX((x & y) | (~x & z))
-#define G(x,y,z) CRAYFIX((x & z) | (y & ~z))
-#define H(x,y,z) (x ^ y ^ z)
-#define I(x,y,z) CRAYFIX(y ^ (x | ~z))
-
-#define DOIT(a,b,c,d,k,s,i,OP) \
-a = b + cshift(a + OP(b,c,d) + X[k] + (i), s)
-
-#define DO1(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,F)
-#define DO2(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,G)
-#define DO3(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,H)
-#define DO4(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,I)
-
-static inline void
-calc (struct md5 *m, u_int32_t *data)
-{
-  u_int32_t AA, BB, CC, DD;
-
-  AA = A;
-  BB = B;
-  CC = C;
-  DD = D;
-
-  /* Round 1 */
-
-  DO1(A,B,C,D,0,7,0xd76aa478);
-  DO1(D,A,B,C,1,12,0xe8c7b756);
-  DO1(C,D,A,B,2,17,0x242070db);
-  DO1(B,C,D,A,3,22,0xc1bdceee);
-
-  DO1(A,B,C,D,4,7,0xf57c0faf);
-  DO1(D,A,B,C,5,12,0x4787c62a);
-  DO1(C,D,A,B,6,17,0xa8304613);
-  DO1(B,C,D,A,7,22,0xfd469501);
-
-  DO1(A,B,C,D,8,7,0x698098d8);
-  DO1(D,A,B,C,9,12,0x8b44f7af);
-  DO1(C,D,A,B,10,17,0xffff5bb1);
-  DO1(B,C,D,A,11,22,0x895cd7be);
-
-  DO1(A,B,C,D,12,7,0x6b901122);
-  DO1(D,A,B,C,13,12,0xfd987193);
-  DO1(C,D,A,B,14,17,0xa679438e);
-  DO1(B,C,D,A,15,22,0x49b40821);
-
-  /* Round 2 */
-
-  DO2(A,B,C,D,1,5,0xf61e2562);
-  DO2(D,A,B,C,6,9,0xc040b340);
-  DO2(C,D,A,B,11,14,0x265e5a51);
-  DO2(B,C,D,A,0,20,0xe9b6c7aa);
-
-  DO2(A,B,C,D,5,5,0xd62f105d);
-  DO2(D,A,B,C,10,9,0x2441453);
-  DO2(C,D,A,B,15,14,0xd8a1e681);
-  DO2(B,C,D,A,4,20,0xe7d3fbc8);
-
-  DO2(A,B,C,D,9,5,0x21e1cde6);
-  DO2(D,A,B,C,14,9,0xc33707d6);
-  DO2(C,D,A,B,3,14,0xf4d50d87);
-  DO2(B,C,D,A,8,20,0x455a14ed);
-
-  DO2(A,B,C,D,13,5,0xa9e3e905);
-  DO2(D,A,B,C,2,9,0xfcefa3f8);
-  DO2(C,D,A,B,7,14,0x676f02d9);
-  DO2(B,C,D,A,12,20,0x8d2a4c8a);
-
-  /* Round 3 */
-
-  DO3(A,B,C,D,5,4,0xfffa3942);
-  DO3(D,A,B,C,8,11,0x8771f681);
-  DO3(C,D,A,B,11,16,0x6d9d6122);
-  DO3(B,C,D,A,14,23,0xfde5380c);
-
-  DO3(A,B,C,D,1,4,0xa4beea44);
-  DO3(D,A,B,C,4,11,0x4bdecfa9);
-  DO3(C,D,A,B,7,16,0xf6bb4b60);
-  DO3(B,C,D,A,10,23,0xbebfbc70);
-
-  DO3(A,B,C,D,13,4,0x289b7ec6);
-  DO3(D,A,B,C,0,11,0xeaa127fa);
-  DO3(C,D,A,B,3,16,0xd4ef3085);
-  DO3(B,C,D,A,6,23,0x4881d05);
-
-  DO3(A,B,C,D,9,4,0xd9d4d039);
-  DO3(D,A,B,C,12,11,0xe6db99e5);
-  DO3(C,D,A,B,15,16,0x1fa27cf8);
-  DO3(B,C,D,A,2,23,0xc4ac5665);
-
-  /* Round 4 */
-
-  DO4(A,B,C,D,0,6,0xf4292244);
-  DO4(D,A,B,C,7,10,0x432aff97);
-  DO4(C,D,A,B,14,15,0xab9423a7);
-  DO4(B,C,D,A,5,21,0xfc93a039);
-
-  DO4(A,B,C,D,12,6,0x655b59c3);
-  DO4(D,A,B,C,3,10,0x8f0ccc92);
-  DO4(C,D,A,B,10,15,0xffeff47d);
-  DO4(B,C,D,A,1,21,0x85845dd1);
-
-  DO4(A,B,C,D,8,6,0x6fa87e4f);
-  DO4(D,A,B,C,15,10,0xfe2ce6e0);
-  DO4(C,D,A,B,6,15,0xa3014314);
-  DO4(B,C,D,A,13,21,0x4e0811a1);
-
-  DO4(A,B,C,D,4,6,0xf7537e82);
-  DO4(D,A,B,C,11,10,0xbd3af235);
-  DO4(C,D,A,B,2,15,0x2ad7d2bb);
-  DO4(B,C,D,A,9,21,0xeb86d391);
-
-  A += AA;
-  B += BB;
-  C += CC;
-  D += DD;
-}
-
-/*
- * From `Performance analysis of MD5' by Joseph D. Touch <touch@isi.edu>
- */
-#if !defined(__BYTE_ORDER) || !defined (__BIG_ENDIAN)
-#error __BYTE_ORDER macros not defined
-#endif
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-static inline u_int32_t
-swap_u_int32_t (u_int32_t t)
-{
-  u_int32_t temp1, temp2;
-
-  temp1   = cshift(t, 16);
-  temp2   = temp1 >> 8;
-  temp1  &= 0x00ff00ff;
-  temp2  &= 0x00ff00ff;
-  temp1 <<= 8;
-  return temp1 | temp2;
-}
-#endif
-
-struct x32{
-  unsigned int a:32;
-  unsigned int b:32;
-};
-
-void
-MD5_Update (struct md5 *m, const void *v, size_t len)
-{
-  const unsigned char *p = v;
-  size_t old_sz = m->sz[0];
-  size_t offset;
-
-  m->sz[0] += len * 8;
-  if (m->sz[0] < old_sz)
-      ++m->sz[1];
-  offset = (old_sz / 8)  % 64;
-  while(len > 0){
-    size_t l = min(len, 64 - offset);
-    memcpy(m->save + offset, p, l);
-    offset += l;
-    p += l;
-    len -= l;
-    if(offset == 64){
-#if __BYTE_ORDER == __BIG_ENDIAN
-      int i;
-      u_int32_t current[16];
-      struct x32 *u = (struct x32*)m->save;
-      for(i = 0; i < 8; i++){
-	current[2*i+0] = swap_u_int32_t(u[i].a);
-	current[2*i+1] = swap_u_int32_t(u[i].b);
-      }
-      calc(m, current);
-#else
-      calc(m, (u_int32_t*)m->save);
-#endif
-      offset = 0;
-    }
-  }
-}
-
-void
-MD5_Final (void *res, struct md5 *m)
-{
-  unsigned char zeros[72];
-  unsigned offset = (m->sz[0] / 8) % 64;
-  unsigned int dstart = (120 - offset - 1) % 64 + 1;
-
-  *zeros = 0x80;
-  memset (zeros + 1, 0, sizeof(zeros) - 1);
-  zeros[dstart+0] = (m->sz[0] >> 0) & 0xff;
-  zeros[dstart+1] = (m->sz[0] >> 8) & 0xff;
-  zeros[dstart+2] = (m->sz[0] >> 16) & 0xff;
-  zeros[dstart+3] = (m->sz[0] >> 24) & 0xff;
-  zeros[dstart+4] = (m->sz[1] >> 0) & 0xff;
-  zeros[dstart+5] = (m->sz[1] >> 8) & 0xff;
-  zeros[dstart+6] = (m->sz[1] >> 16) & 0xff;
-  zeros[dstart+7] = (m->sz[1] >> 24) & 0xff;
-  MD5_Update (m, zeros, dstart + 8);
-  {
-      int i;
-      unsigned char *r = (unsigned char *)res;
-
-      for (i = 0; i < 4; ++i) {
-	  r[4*i]   = m->counter[i] & 0xFF;
-	  r[4*i+1] = (m->counter[i] >> 8) & 0xFF;
-	  r[4*i+2] = (m->counter[i] >> 16) & 0xFF;
-	  r[4*i+3] = (m->counter[i] >> 24) & 0xFF;
-      }
-  }
-#if 0
-  {
-    int i;
-    u_int32_t *r = (u_int32_t *)res;
-
-    for (i = 0; i < 4; ++i)
-      r[i] = swap_u_int32_t (m->counter[i]);
-  }
-#endif
-}
diff --git a/libc/bionic/md5.h b/libc/bionic/md5.h
deleted file mode 100644
index a381994..0000000
--- a/libc/bionic/md5.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* $Heimdal: md5.h,v 1.8 2001/01/29 02:08:57 assar Exp $
-   $NetBSD: md5.h,v 1.1.1.4 2002/09/12 12:41:42 joda Exp $ */
-
-#include <stdlib.h>
-#include <sys/types.h>
-
-struct md5 {
-  unsigned int sz[2];
-  u_int32_t counter[4];
-  unsigned char save[64];
-};
-
-typedef struct md5 MD5_CTX;
-
-void MD5_Init (struct md5 *m);
-void MD5_Update (struct md5 *m, const void *p, size_t len);
-void MD5_Final (void *res, struct md5 *m); /* u_int32_t res[4] */
diff --git a/libc/bionic/memcpy.c b/libc/bionic/memcpy.c
deleted file mode 100644
index dea78b2..0000000
--- a/libc/bionic/memcpy.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#define MEMCOPY
-#include "bcopy.c"
diff --git a/libc/bionic/memcpy.cpp b/libc/bionic/memcpy.cpp
new file mode 100644
index 0000000..d527e85
--- /dev/null
+++ b/libc/bionic/memcpy.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#undef _FORTIFY_SOURCE
+#include <string.h>
+#include <strings.h>
+
+// Our unoptimized memcpy just calls the best bcopy available.
+// (It's this way round rather than the opposite because we're based on BSD source.)
+void* memcpy(void* dst, const void* src, size_t n) {
+  bcopy(src, dst, n);
+  return dst;
+}
diff --git a/libc/bionic/memmove.c b/libc/bionic/memmove.c
index a9fc1b5..39c766e 100644
--- a/libc/bionic/memmove.c
+++ b/libc/bionic/memmove.c
@@ -25,22 +25,6 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#undef _FORTIFY_SOURCE
-#include <string.h>
-#include <strings.h>
 
-void *memmove(void *dst, const void *src, size_t n)
-{
-  const char *p = src;
-  char *q = dst;
-  /* We can use the optimized memcpy if the source and destination
-   * don't overlap.
-   */
-  if (__builtin_expect(((q < p) && ((size_t)(p - q) >= n))
-                    || ((p < q) && ((size_t)(q - p) >= n)), 1)) {
-    return memcpy(dst, src, n);
-  } else {
-    bcopy(src, dst, n);
-    return dst;
-  }
-}
+#define MEMMOVE
+#include "upstream-openbsd/lib/libc/string/bcopy.c"
diff --git a/libc/bionic/memswap.c b/libc/bionic/memswap.c
deleted file mode 100644
index 35b0b32..0000000
--- a/libc/bionic/memswap.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <string.h>
-
-void memswap(void *m1, void *m2, size_t n)
-{
-    char*  p     = m1;
-    char*  p_end = p + n;
-    char*  q     = m2;
-
-    while (p < p_end) {
-        char  tmp = *p;
-        *p = *q;
-        *q = tmp;
-        p++;
-        q++;
-    }
-}
diff --git a/libc/bionic/mmap.cpp b/libc/bionic/mmap.cpp
index 28a47cc..8f25a89 100644
--- a/libc/bionic/mmap.cpp
+++ b/libc/bionic/mmap.cpp
@@ -37,16 +37,23 @@
 
 #define MMAP2_SHIFT 12 // 2**12 == 4096
 
+static bool kernel_has_MADV_MERGEABLE = true;
+
 void* mmap64(void* addr, size_t size, int prot, int flags, int fd, off64_t offset) {
   if (offset < 0 || (offset & ((1UL << MMAP2_SHIFT)-1)) != 0) {
     errno = EINVAL;
     return MAP_FAILED;
   }
 
+  bool is_private_anonymous = (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) != 0;
   void* result = __mmap2(addr, size, prot, flags, fd, offset >> MMAP2_SHIFT);
-  if (result != MAP_FAILED && (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) != 0) {
+
+  if (result != MAP_FAILED && kernel_has_MADV_MERGEABLE && is_private_anonymous) {
     ErrnoRestorer errno_restorer;
-    madvise(result, size, MADV_MERGEABLE);
+    int rc = madvise(result, size, MADV_MERGEABLE);
+    if (rc == -1 && errno == EINVAL) {
+      kernel_has_MADV_MERGEABLE = false;
+    }
   }
 
   return result;
diff --git a/libc/bionic/mntent.cpp b/libc/bionic/mntent.cpp
new file mode 100644
index 0000000..93b6915
--- /dev/null
+++ b/libc/bionic/mntent.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <mntent.h>
+
+mntent* getmntent(FILE*) {
+  return NULL;
+}
+
+mntent* getmntent_r(FILE*, struct mntent*, char*, int) {
+  return NULL;
+}
+
+FILE* setmntent(const char* path, const char* mode) {
+  return fopen(path, mode);
+}
+
+int endmntent(FILE* fp) {
+  if (fp != NULL) {
+    fclose(fp);
+  }
+  return 1;
+}
diff --git a/libc/bionic/name_mem.c b/libc/bionic/name_mem.c
deleted file mode 100644
index 69e10c2..0000000
--- a/libc/bionic/name_mem.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "private/bionic_name_mem.h"
-
-/*
- * Local definitions of custom prctl arguments to set a vma name in some kernels
- */
-#define BIONIC_PR_SET_VMA               0x53564d41
-#define BIONIC_PR_SET_VMA_ANON_NAME     0
-
-/*
- * Names a region of memory.  The name is expected to show up in /proc/pid/maps
- * and /proc/pid/smaps.  There is no guarantee that it will work, and it if it
- * does work it is likely to only work on memory that was allocated with
- * mmap(MAP_ANONYMOUS), and only on regions that are page aligned.  name should
- * be a pointer to a string that is valid for as long as the memory is mapped,
- * preferably a compile-time constant string.
- *
- * Returns -1 on error and sets errno.  If it returns an error naming page
- * aligned anonymous memory the kernel doesn't support naming, and an alternate
- * method of naming memory should be used (like ashmem).
- */
-int __bionic_name_mem(void *addr, size_t len, const char *name)
-{
-    return prctl(BIONIC_PR_SET_VMA, BIONIC_PR_SET_VMA_ANON_NAME,
-                 addr, len, name);
-}
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index 3637c3e..829e8f3 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -29,18 +29,27 @@
 // This file perpetuates the mistakes of the past, but only for 32-bit targets.
 #if !defined(__LP64__)
 
+#include <ctype.h>
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/resource.h>
+#include <sys/syscall.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <wchar.h>
 
 // These were accidentally declared in <unistd.h> because we stupidly used to inline
 // getpagesize() and __getpageshift(). Needed for backwards compatibility with old NDK apps.
 extern "C" {
   unsigned int __page_size = PAGE_SIZE;
-  unsigned int __page_shift = PAGE_SHIFT;
+  unsigned int __page_shift = 12;
 }
 
 // TODO: remove this backward compatibility hack (for jb-mr1 strace binaries).
@@ -59,4 +68,256 @@
   return __get_tls();
 }
 
+// This non-standard function was in our <string.h> for some reason.
+extern "C" void memswap(void* m1, void* m2, size_t n) {
+  char* p = reinterpret_cast<char*>(m1);
+  char* p_end = p + n;
+  char* q = reinterpret_cast<char*>(m2);
+  while (p < p_end) {
+    char tmp = *p;
+    *p = *q;
+    *q = tmp;
+    p++;
+    q++;
+  }
+}
+
+extern "C" int pthread_attr_setstackaddr(pthread_attr_t*, void*) {
+  // This was removed from POSIX.1-2008, and is not implemented on bionic.
+  // Needed for ABI compatibility with the NDK.
+  return ENOSYS;
+}
+
+extern "C" int pthread_attr_getstackaddr(const pthread_attr_t* attr, void** stack_addr) {
+  // This was removed from POSIX.1-2008.
+  // Needed for ABI compatibility with the NDK.
+  *stack_addr = (char*)attr->stack_base + attr->stack_size;
+  return 0;
+}
+
+// Non-standard cruft that should only ever have been in system/core/toolbox.
+extern "C" char* strtotimeval(const char* str, struct timeval* ts) {
+  char* s;
+  ts->tv_sec = strtoumax(str, &s, 10);
+
+  long fractional_seconds = 0;
+  if (*s == '.') {
+    s++;
+    int count = 0;
+
+    // Read up to 6 digits (microseconds).
+    while (*s && isdigit(*s)) {
+      if (++count < 7) {
+        fractional_seconds = fractional_seconds*10 + (*s - '0');
+      }
+      s++;
+    }
+
+    for (; count < 6; count++) {
+      fractional_seconds *= 10;
+    }
+  }
+
+  ts->tv_usec = fractional_seconds;
+  return s;
+}
+
+static inline int digitval(int ch) {
+  unsigned d;
+
+  d = (unsigned)(ch - '0');
+  if (d < 10) return (int)d;
+
+  d = (unsigned)(ch - 'a');
+  if (d < 6) return (int)(d+10);
+
+  d = (unsigned)(ch - 'A');
+  if (d < 6) return (int)(d+10);
+
+  return -1;
+}
+
+// This non-standard function was in our <inttypes.h> for some reason.
+extern "C" uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n) {
+  const unsigned char*  p   = (const unsigned char *)nptr;
+  const unsigned char*  end = p + n;
+  int                   minus = 0;
+  uintmax_t             v = 0;
+  int                   d;
+
+  while (p < end && isspace(*p)) {
+    p++;
+  }
+
+  if (p < end) {
+    char c = p[0];
+    if (c == '-' || c == '+') {
+      minus = (c == '-');
+      p++;
+    }
+  }
+
+  if (base == 0) {
+    if (p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
+      p += 2;
+      base = 16;
+    } else if (p+1 < end && p[0] == '0') {
+      p   += 1;
+      base = 8;
+    } else {
+      base = 10;
+    }
+  } else if (base == 16) {
+    if (p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
+      p += 2;
+    }
+  }
+
+  while (p < end && (d = digitval(*p)) >= 0 && d < base) {
+    v = v*base + d;
+    p += 1;
+  }
+
+  if (endptr) {
+    *endptr = (char*) p;
+  }
+
+  return minus ? -v : v;
+}
+
+// This non-standard function was in our <inttypes.h> for some reason.
+extern "C" intmax_t strntoimax(const char* nptr, char** endptr, int base, size_t n) {
+  return (intmax_t) strntoumax(nptr, endptr, base, n);
+}
+
+// POSIX calls this dprintf, but LP32 Android had fdprintf instead.
+extern "C" int fdprintf(int fd, const char* fmt, ...) {
+  va_list ap;
+  va_start(ap, fmt);
+  int rc = vdprintf(fd, fmt, ap);
+  va_end(ap);
+  return rc;
+}
+
+// POSIX calls this vdprintf, but LP32 Android had fdprintf instead.
+extern "C" int vfdprintf(int fd, const char* fmt, va_list ap) {
+  return vdprintf(fd, fmt, ap);
+}
+
+#define __futex_wake __real_futex_wake
+#define __futex_wait __real_futex_wait
+#include "private/bionic_futex.h"
+#undef __futex_wake
+#undef __futex_wait
+
+// This used to be in <sys/atomics.h>.
+extern "C" int __futex_wake(volatile void* ftx, int count) {
+  return __real_futex_wake(ftx, count);
+}
+
+// This used to be in <sys/atomics.h>.
+extern "C" int __futex_wait(volatile void* ftx, int value, const struct timespec* timeout) {
+  return __real_futex_wait(ftx, value, timeout);
+}
+
+// Unity's libmono uses this.
+extern "C" int tkill(pid_t tid, int sig) {
+  return syscall(__NR_tkill, tid, sig);
+}
+
+// This was removed from POSIX 2008.
+extern "C" wchar_t* wcswcs(wchar_t* haystack, wchar_t* needle) {
+  return wcsstr(haystack, needle);
+}
+
+// This was removed from POSIX 2008.
+extern "C" sighandler_t bsd_signal(int signum, sighandler_t handler) {
+  return signal(signum, handler);
+}
+
+// sysv_signal() was never in POSIX.
+extern sighandler_t _signal(int signum, sighandler_t handler, int flags);
+extern "C" sighandler_t sysv_signal(int signum, sighandler_t handler) {
+  return _signal(signum, handler, SA_RESETHAND);
+}
+
+// This is a system call that was never in POSIX. Use readdir(3) instead.
+extern "C" int __getdents64(unsigned int, dirent*, unsigned int);
+extern "C" int getdents(unsigned int fd, dirent* dirp, unsigned int count) {
+  return __getdents64(fd, dirp, count);
+}
+
+// This is a BSDism that we never implemented correctly. Used by Firefox.
+extern "C" int issetugid() {
+  return 0;
+}
+
+// This was removed from POSIX 2004.
+extern "C" pid_t wait3(int* status, int options, struct rusage* rusage) {
+  return wait4(-1, status, options, rusage);
+}
+
+// This was removed from POSIX 2004.
+extern "C" int getdtablesize() {
+  struct rlimit r;
+
+  if (getrlimit(RLIMIT_NOFILE, &r) < 0) {
+    return sysconf(_SC_OPEN_MAX);
+  }
+
+  return r.rlim_cur;
+}
+
+// Only used by ftime, which was removed from POSIX 2008.
+struct timeb {
+  time_t          time;
+  unsigned short  millitm;
+  short           timezone;
+  short           dstflag;
+};
+
+// This was removed from POSIX 2008.
+extern "C" int ftime(struct timeb* tb) {
+  struct timeval  tv;
+  struct timezone tz;
+
+  if (gettimeofday(&tv, &tz) < 0)
+    return -1;
+
+  tb->time    = tv.tv_sec;
+  tb->millitm = (tv.tv_usec + 500) / 1000;
+
+  if (tb->millitm == 1000) {
+    ++tb->time;
+    tb->millitm = 0;
+  }
+
+  tb->timezone = tz.tz_minuteswest;
+  tb->dstflag  = tz.tz_dsttime;
+
+  return 0;
+}
+
+// This was removed from POSIX 2008.
+extern "C" char* index(const char* str, int ch) {
+  return strchr(str, ch);
+}
+
+// This was removed from BSD.
+extern "C" void arc4random_stir(void) {
+  // The current implementation stirs itself as needed.
+}
+
+// This was removed from BSD.
+extern "C" void arc4random_addrandom(unsigned char*, int) {
+  // The current implementation adds randomness as needed.
+}
+
+// Old versions of the NDK did not export malloc_usable_size, but did
+// export dlmalloc_usable_size. We are moving away from dlmalloc in L
+// so make this call malloc_usable_size.
+extern "C" size_t dlmalloc_usable_size(void* ptr) {
+  return malloc_usable_size(ptr);
+}
+
 #endif
diff --git a/libc/bionic/new.cpp b/libc/bionic/new.cpp
new file mode 100644
index 0000000..fcfd1bd
--- /dev/null
+++ b/libc/bionic/new.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <new>
+#include <stdlib.h>
+
+#include "private/libc_logging.h"
+
+const std::nothrow_t std::nothrow = {};
+
+void* operator new(std::size_t size) {
+    void* p = malloc(size);
+    if (p == NULL) {
+        __libc_fatal("new failed to allocate %zu bytes", size);
+    }
+    return p;
+}
+
+void* operator new[](std::size_t size) {
+    void* p = malloc(size);
+    if (p == NULL) {
+        __libc_fatal("new[] failed to allocate %zu bytes", size);
+    }
+    return p;
+}
+
+void  operator delete(void* ptr) {
+    free(ptr);
+}
+
+void  operator delete[](void* ptr) {
+    free(ptr);
+}
+
+void* operator new(std::size_t size, const std::nothrow_t&) {
+    return malloc(size);
+}
+
+void* operator new[](std::size_t size, const std::nothrow_t&) {
+    return malloc(size);
+}
+
+void  operator delete(void* ptr, const std::nothrow_t&) {
+    free(ptr);
+}
+
+void  operator delete[](void* ptr, const std::nothrow_t&) {
+    free(ptr);
+}
diff --git a/libc/bionic/open.cpp b/libc/bionic/open.cpp
index 986ed1c..bd832c0 100644
--- a/libc/bionic/open.cpp
+++ b/libc/bionic/open.cpp
@@ -43,6 +43,11 @@
 #endif
 }
 
+int creat(const char* pathname, mode_t mode) {
+  return open(pathname, O_CREAT | O_TRUNC | O_WRONLY, mode);
+}
+__strong_alias(creat64, creat);
+
 int open(const char* pathname, int flags, ...) {
   mode_t mode = 0;
 
@@ -55,6 +60,7 @@
 
   return __openat(AT_FDCWD, pathname, force_O_LARGEFILE(flags), mode);
 }
+__strong_alias(open64, open);
 
 int __open_2(const char* pathname, int flags) {
   if (__predict_false((flags & O_CREAT) != 0)) {
@@ -76,6 +82,7 @@
 
   return __openat(fd, pathname, force_O_LARGEFILE(flags), mode);
 }
+__strong_alias(openat64, openat);
 
 int __openat_2(int fd, const char* pathname, int flags) {
   if ((flags & O_CREAT) != 0) {
diff --git a/libc/bionic/perror.c b/libc/bionic/perror.c
deleted file mode 100644
index de55f72..0000000
--- a/libc/bionic/perror.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-
-void perror(const char *prefix)
-{
-    char   buff[256];
-
-    strerror_r( errno, buff, sizeof(buff) );
-
-    if (prefix) {
-        write( 2, prefix, strlen(prefix) );
-        write( 2, ": ", 2 );
-    }
-    write( 2, buff, strlen(buff) );
-    write( 2, "\n", 1 );
-}
diff --git a/libc/bionic/posix_fadvise.cpp b/libc/bionic/posix_fadvise.cpp
new file mode 100644
index 0000000..3a74af3
--- /dev/null
+++ b/libc/bionic/posix_fadvise.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+
+#include "private/ErrnoRestorer.h"
+
+extern "C" int __arm_fadvise64_64(int, int, off64_t, off64_t);
+extern "C" int __fadvise64(int, off64_t, off64_t, int);
+
+// No architecture actually has the 32-bit off_t system call.
+int posix_fadvise(int fd, off_t offset, off_t length, int advice) {
+  return posix_fadvise64(fd, offset, length, advice);
+}
+
+#if defined(__arm__)
+int posix_fadvise64(int fd, off64_t offset, off64_t length, int advice) {
+  ErrnoRestorer errno_restorer;
+  return (__arm_fadvise64_64(fd, advice, offset, length) == 0) ? 0 : errno;
+}
+#else
+int posix_fadvise64(int fd, off64_t offset, off64_t length, int advice) {
+  ErrnoRestorer errno_restorer;
+  return (__fadvise64(fd, offset, length, advice) == 0) ? 0 : errno;
+}
+#endif
diff --git a/libc/bionic/posix_fallocate.cpp b/libc/bionic/posix_fallocate.cpp
new file mode 100644
index 0000000..bdc1636
--- /dev/null
+++ b/libc/bionic/posix_fallocate.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+
+#include "private/ErrnoRestorer.h"
+
+int posix_fallocate(int fd, off_t offset, off_t length) {
+  ErrnoRestorer errno_restorer;
+  return (fallocate(fd, 0, offset, length) == 0) ? 0 : errno;
+}
+
+int posix_fallocate64(int fd, off64_t offset, off64_t length) {
+  ErrnoRestorer errno_restorer;
+  return (fallocate64(fd, 0, offset, length) == 0) ? 0 : errno;
+}
diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp
new file mode 100644
index 0000000..7ad0ef1
--- /dev/null
+++ b/libc/bionic/posix_timers.cpp
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "pthread_internal.h"
+#include "private/bionic_futex.h"
+#include "private/kernel_sigset_t.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+// System calls.
+extern "C" int __rt_sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*, size_t);
+extern "C" int __timer_create(clockid_t, sigevent*, __kernel_timer_t*);
+extern "C" int __timer_delete(__kernel_timer_t);
+extern "C" int __timer_getoverrun(__kernel_timer_t);
+extern "C" int __timer_gettime(__kernel_timer_t, itimerspec*);
+extern "C" int __timer_settime(__kernel_timer_t, int, const itimerspec*, itimerspec*);
+
+// Most POSIX timers are handled directly by the kernel. We translate SIGEV_THREAD timers
+// into SIGEV_THREAD_ID timers so the kernel handles all the time-related stuff and we just
+// need to worry about running user code on a thread.
+
+// We can't use SIGALRM because too many other C library functions throw that around, and since
+// they don't send to a specific thread, all threads are eligible to handle the signal and we can
+// end up with one of our POSIX timer threads handling it (meaning that the intended recipient
+// doesn't). glibc uses SIGRTMIN for its POSIX timer implementation, so in the absence of any
+// reason to use anything else, we use that too.
+static const int TIMER_SIGNAL = (__SIGRTMIN + 0);
+
+struct PosixTimer {
+  __kernel_timer_t kernel_timer_id;
+
+  int sigev_notify;
+
+  // These fields are only needed for a SIGEV_THREAD timer.
+  pthread_t callback_thread;
+  void (*callback)(sigval_t);
+  sigval_t callback_argument;
+};
+
+static __kernel_timer_t to_kernel_timer_id(timer_t timer) {
+  return reinterpret_cast<PosixTimer*>(timer)->kernel_timer_id;
+}
+
+static void* __timer_thread_start(void* arg) {
+  PosixTimer* timer = reinterpret_cast<PosixTimer*>(arg);
+
+  kernel_sigset_t sigset;
+  sigaddset(sigset.get(), TIMER_SIGNAL);
+
+  while (true) {
+    // Wait for a signal...
+    siginfo_t si;
+    memset(&si, 0, sizeof(si));
+    int rc = __rt_sigtimedwait(sigset.get(), &si, NULL, sizeof(sigset));
+    if (rc == -1) {
+      continue;
+    }
+
+    if (si.si_code == SI_TIMER) {
+      // This signal was sent because a timer fired, so call the callback.
+      timer->callback(timer->callback_argument);
+    } else if (si.si_code == SI_TKILL) {
+      // This signal was sent because someone wants us to exit.
+      free(timer);
+      return NULL;
+    }
+  }
+}
+
+static void __timer_thread_stop(PosixTimer* timer) {
+  pthread_kill(timer->callback_thread, TIMER_SIGNAL);
+}
+
+// http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html
+int timer_create(clockid_t clock_id, sigevent* evp, timer_t* timer_id) {
+  PosixTimer* timer = reinterpret_cast<PosixTimer*>(malloc(sizeof(PosixTimer)));
+  if (timer == NULL) {
+    return -1;
+  }
+
+  timer->sigev_notify = (evp == NULL) ? SIGEV_SIGNAL : evp->sigev_notify;
+
+  // If not a SIGEV_THREAD timer, the kernel can handle it without our help.
+  if (timer->sigev_notify != SIGEV_THREAD) {
+    if (__timer_create(clock_id, evp, &timer->kernel_timer_id) == -1) {
+      free(timer);
+      return -1;
+    }
+
+    *timer_id = timer;
+    return 0;
+  }
+
+  // Otherwise, this must be SIGEV_THREAD timer...
+  timer->callback = evp->sigev_notify_function;
+  timer->callback_argument = evp->sigev_value;
+
+  // Check arguments that the kernel doesn't care about but we do.
+  if (timer->callback == NULL) {
+    free(timer);
+    errno = EINVAL;
+    return -1;
+  }
+
+  // Create this timer's thread.
+  pthread_attr_t thread_attributes;
+  if (evp->sigev_notify_attributes == NULL) {
+    pthread_attr_init(&thread_attributes);
+  } else {
+    thread_attributes = *reinterpret_cast<pthread_attr_t*>(evp->sigev_notify_attributes);
+  }
+  pthread_attr_setdetachstate(&thread_attributes, PTHREAD_CREATE_DETACHED);
+
+  // We start the thread with TIMER_SIGNAL blocked by blocking the signal here and letting it
+  // inherit. If it tried to block the signal itself, there would be a race.
+  kernel_sigset_t sigset;
+  sigaddset(sigset.get(), TIMER_SIGNAL);
+  kernel_sigset_t old_sigset;
+  pthread_sigmask(SIG_BLOCK, sigset.get(), old_sigset.get());
+
+  int rc = pthread_create(&timer->callback_thread, &thread_attributes, __timer_thread_start, timer);
+
+  pthread_sigmask(SIG_SETMASK, old_sigset.get(), NULL);
+
+  if (rc != 0) {
+    free(timer);
+    errno = rc;
+    return -1;
+  }
+
+  sigevent se = *evp;
+  se.sigev_signo = TIMER_SIGNAL;
+  se.sigev_notify = SIGEV_THREAD_ID;
+  se.sigev_notify_thread_id = pthread_gettid_np(timer->callback_thread);
+  if (__timer_create(clock_id, &se, &timer->kernel_timer_id) == -1) {
+    __timer_thread_stop(timer);
+    return -1;
+  }
+
+  // Give the thread a meaningful name.
+  // It can't do this itself because the kernel timer isn't created until after it's running.
+  char name[32];
+  snprintf(name, sizeof(name), "POSIX interval timer %d", to_kernel_timer_id(timer));
+  pthread_setname_np(timer->callback_thread, name);
+
+  *timer_id = timer;
+  return 0;
+}
+
+// http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_delete.html
+int timer_delete(timer_t id) {
+  int rc = __timer_delete(to_kernel_timer_id(id));
+  if (rc == -1) {
+    return -1;
+  }
+
+  PosixTimer* timer = reinterpret_cast<PosixTimer*>(id);
+  if (timer->sigev_notify == SIGEV_THREAD) {
+    // Stopping the timer's thread frees the timer data when it's safe.
+    __timer_thread_stop(timer);
+  } else {
+    // For timers without threads, we can just free right away.
+    free(timer);
+  }
+
+  return 0;
+}
+
+// http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_getoverrun.html
+int timer_gettime(timer_t id, itimerspec* ts) {
+  return __timer_gettime(to_kernel_timer_id(id), ts);
+}
+
+// http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_getoverrun.html
+int timer_settime(timer_t id, int flags, const itimerspec* ts, itimerspec* ots) {
+  return __timer_settime(to_kernel_timer_id(id), flags, ts, ots);
+}
+
+// http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_getoverrun.html
+int timer_getoverrun(timer_t id) {
+  return __timer_getoverrun(to_kernel_timer_id(id));
+}
diff --git a/libc/bionic/pthread_accessor.h b/libc/bionic/pthread_accessor.h
index 2a320f6..df4a5a2 100644
--- a/libc/bionic/pthread_accessor.h
+++ b/libc/bionic/pthread_accessor.h
@@ -19,13 +19,14 @@
 
 #include <pthread.h>
 
+#include "private/bionic_macros.h"
 #include "pthread_internal.h"
 
 class pthread_accessor {
  public:
   explicit pthread_accessor(pthread_t desired_thread) {
     Lock();
-    for (thread_ = gThreadList; thread_ != NULL; thread_ = thread_->next) {
+    for (thread_ = g_thread_list; thread_ != NULL; thread_ = thread_->next) {
       if (thread_ == reinterpret_cast<pthread_internal_t*>(desired_thread)) {
         break;
       }
@@ -40,7 +41,7 @@
     if (is_locked_) {
       is_locked_ = false;
       thread_ = NULL;
-      pthread_mutex_unlock(&gThreadListLock);
+      pthread_mutex_unlock(&g_thread_list_lock);
     }
   }
 
@@ -53,13 +54,11 @@
   bool is_locked_;
 
   void Lock() {
-    pthread_mutex_lock(&gThreadListLock);
+    pthread_mutex_lock(&g_thread_list_lock);
     is_locked_ = true;
   }
 
-  // Disallow copy and assignment.
-  pthread_accessor(const pthread_accessor&);
-  void operator=(const pthread_accessor&);
+  DISALLOW_COPY_AND_ASSIGN(pthread_accessor);
 };
 
 #endif // PTHREAD_ACCESSOR_H
diff --git a/libc/bionic/pthread_atfork.cpp b/libc/bionic/pthread_atfork.cpp
index 5bf63fb..b845f7d 100644
--- a/libc/bionic/pthread_atfork.cpp
+++ b/libc/bionic/pthread_atfork.cpp
@@ -29,8 +29,6 @@
 #include <errno.h>
 #include <pthread.h>
 
-static pthread_mutex_t gAtForkListMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
-
 struct atfork_t {
   atfork_t* next;
   atfork_t* prev;
@@ -45,23 +43,22 @@
   atfork_t* last;
 };
 
-static atfork_list_t gAtForkList = { NULL, NULL };
+static pthread_mutex_t g_atfork_list_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+static atfork_list_t g_atfork_list = { NULL, NULL };
 
 void __bionic_atfork_run_prepare() {
-  // We will lock this here, and unlock it in the parent and child functions.
+  // We lock the atfork list here, unlock it in the parent, and reset it in the child.
   // This ensures that nobody can modify the handler array between the calls
   // to the prepare and parent/child handlers.
   //
-  // TODO: If a handler mucks with the list, it could cause problems.  Right
-  //       now it's ok because all they can do is add new items to the end
-  //       of the list, but if/when we implement cleanup in dlclose() things
-  //       will get more interesting...
-  pthread_mutex_lock(&gAtForkListMutex);
+  // TODO: If a handler tries to mutate the list, they'll block. We should probably copy
+  // the list before forking, and have prepare, parent, and child all work on the consistent copy.
+  pthread_mutex_lock(&g_atfork_list_mutex);
 
   // Call pthread_atfork() prepare handlers. POSIX states that the prepare
   // handlers should be called in the reverse order of the parent/child
   // handlers, so we iterate backwards.
-  for (atfork_t* it = gAtForkList.last; it != NULL; it = it->prev) {
+  for (atfork_t* it = g_atfork_list.last; it != NULL; it = it->prev) {
     if (it->prepare != NULL) {
       it->prepare();
     }
@@ -69,26 +66,23 @@
 }
 
 void __bionic_atfork_run_child() {
-  for (atfork_t* it = gAtForkList.first; it != NULL; it = it->next) {
+  for (atfork_t* it = g_atfork_list.first; it != NULL; it = it->next) {
     if (it->child != NULL) {
       it->child();
     }
   }
 
-  pthread_mutexattr_t attr;
-  pthread_mutexattr_init(&attr);
-  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-  pthread_mutex_init(&gAtForkListMutex, &attr);
+  g_atfork_list_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
 }
 
 void __bionic_atfork_run_parent() {
-  for (atfork_t* it = gAtForkList.first; it != NULL; it = it->next) {
+  for (atfork_t* it = g_atfork_list.first; it != NULL; it = it->next) {
     if (it->parent != NULL) {
       it->parent();
     }
   }
 
-  pthread_mutex_unlock(&gAtForkListMutex);
+  pthread_mutex_unlock(&g_atfork_list_mutex);
 }
 
 int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void)) {
@@ -101,20 +95,20 @@
   entry->parent = parent;
   entry->child = child;
 
-  pthread_mutex_lock(&gAtForkListMutex);
+  pthread_mutex_lock(&g_atfork_list_mutex);
 
   // Append 'entry' to the list.
   entry->next = NULL;
-  entry->prev = gAtForkList.last;
+  entry->prev = g_atfork_list.last;
   if (entry->prev != NULL) {
     entry->prev->next = entry;
   }
-  if (gAtForkList.first == NULL) {
-    gAtForkList.first = entry;
+  if (g_atfork_list.first == NULL) {
+    g_atfork_list.first = entry;
   }
-  gAtForkList.last = entry;
+  g_atfork_list.last = entry;
 
-  pthread_mutex_unlock(&gAtForkListMutex);
+  pthread_mutex_unlock(&g_atfork_list_mutex);
 
   return 0;
 }
diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp
index fdf2965..c93970a 100644
--- a/libc/bionic/pthread_attr.cpp
+++ b/libc/bionic/pthread_attr.cpp
@@ -28,6 +28,13 @@
 
 #include <pthread.h>
 
+#include <inttypes.h>
+#include <stdio.h>
+#include <sys/resource.h>
+
+#include "private/bionic_string_utils.h"
+#include "private/ErrnoRestorer.h"
+#include "private/libc_logging.h"
 #include "pthread_internal.h"
 
 int pthread_attr_init(pthread_attr_t* attr) {
@@ -90,21 +97,8 @@
 }
 
 int pthread_attr_getstacksize(const pthread_attr_t* attr, size_t* stack_size) {
-  *stack_size = attr->stack_size;
-  return 0;
-}
-
-int pthread_attr_setstackaddr(pthread_attr_t*, void*) {
-  // This was removed from POSIX.1-2008, and is not implemented on bionic.
-  // Needed for ABI compatibility with the NDK.
-  return ENOSYS;
-}
-
-int pthread_attr_getstackaddr(const pthread_attr_t* attr, void** stack_addr) {
-  // This was removed from POSIX.1-2008.
-  // Needed for ABI compatibility with the NDK.
-  *stack_addr = (char*)attr->stack_base + attr->stack_size;
-  return 0;
+  void* unused;
+  return pthread_attr_getstack(attr, &unused, stack_size);
 }
 
 int pthread_attr_setstack(pthread_attr_t* attr, void* stack_base, size_t stack_size) {
@@ -119,7 +113,43 @@
   return 0;
 }
 
+static int __pthread_attr_getstack_main_thread(void** stack_base, size_t* stack_size) {
+  ErrnoRestorer errno_restorer;
+
+  rlimit stack_limit;
+  if (getrlimit(RLIMIT_STACK, &stack_limit) == -1) {
+    return errno;
+  }
+
+  // If the current RLIMIT_STACK is RLIM_INFINITY, only admit to an 8MiB stack for sanity's sake.
+  if (stack_limit.rlim_cur == RLIM_INFINITY) {
+    stack_limit.rlim_cur = 8 * 1024 * 1024;
+  }
+
+  // It doesn't matter which thread we are; we're just looking for "[stack]".
+  FILE* fp = fopen("/proc/self/maps", "re");
+  if (fp == NULL) {
+    return errno;
+  }
+  char line[BUFSIZ];
+  while (fgets(line, sizeof(line), fp) != NULL) {
+    if (ends_with(line, " [stack]\n")) {
+      uintptr_t lo, hi;
+      if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &lo, &hi) == 2) {
+        *stack_size = stack_limit.rlim_cur;
+        *stack_base = reinterpret_cast<void*>(hi - *stack_size);
+        fclose(fp);
+        return 0;
+      }
+    }
+  }
+  __libc_fatal("No [stack] line found in /proc/self/maps!");
+}
+
 int pthread_attr_getstack(const pthread_attr_t* attr, void** stack_base, size_t* stack_size) {
+  if ((attr->flags & PTHREAD_ATTR_FLAG_MAIN_THREAD) != 0) {
+    return __pthread_attr_getstack_main_thread(stack_base, stack_size);
+  }
   *stack_base = attr->stack_base;
   *stack_size = attr->stack_size;
   return 0;
@@ -135,9 +165,8 @@
   return 0;
 }
 
-int pthread_getattr_np(pthread_t thid, pthread_attr_t* attr) {
-  pthread_internal_t* thread = (pthread_internal_t*) thid;
-  *attr = thread->attr;
+int pthread_getattr_np(pthread_t t, pthread_attr_t* attr) {
+  *attr = reinterpret_cast<pthread_internal_t*>(t)->attr;
   return 0;
 }
 
diff --git a/libc/bionic/pthread_cond.cpp b/libc/bionic/pthread_cond.cpp
index 4583cef..e623b62 100644
--- a/libc/bionic/pthread_cond.cpp
+++ b/libc/bionic/pthread_cond.cpp
@@ -30,8 +30,8 @@
 
 #include <errno.h>
 #include <limits.h>
-#include <sys/atomics.h>
 #include <sys/mman.h>
+#include <time.h>
 #include <unistd.h>
 
 #include "pthread_internal.h"
@@ -40,50 +40,64 @@
 #include "private/bionic_futex.h"
 #include "private/bionic_time_conversions.h"
 #include "private/bionic_tls.h"
-#include "private/thread_private.h"
+
+// We use one bit in pthread_condattr_t (long) values as the 'shared' flag
+// and one bit for the clock type (CLOCK_REALTIME is ((clockid_t) 1), and
+// CLOCK_MONOTONIC is ((clockid_t) 0).). The rest of the bits are a counter.
+//
+// The 'value' field pthread_cond_t has the same layout.
+
+#define COND_SHARED_MASK 0x0001
+#define COND_CLOCK_MASK 0x0002
+#define COND_COUNTER_STEP 0x0004
+#define COND_FLAGS_MASK (COND_SHARED_MASK | COND_CLOCK_MASK)
+#define COND_COUNTER_MASK (~COND_FLAGS_MASK)
+
+#define COND_IS_SHARED(c) (((c) & COND_SHARED_MASK) != 0)
+#define COND_GET_CLOCK(c) (((c) & COND_CLOCK_MASK) >> 1)
+#define COND_SET_CLOCK(attr, c) ((attr) | (c << 1))
+
 
 int pthread_condattr_init(pthread_condattr_t* attr) {
-  if (attr == NULL) {
-    return EINVAL;
-  }
-  *attr = PTHREAD_PROCESS_PRIVATE;
+  *attr = 0;
+  *attr |= PTHREAD_PROCESS_PRIVATE;
+  *attr |= (CLOCK_REALTIME << 1);
   return 0;
 }
 
 int pthread_condattr_getpshared(const pthread_condattr_t* attr, int* pshared) {
-  if (attr == NULL || pshared == NULL) {
-    return EINVAL;
-  }
-  *pshared = *attr;
+  *pshared = static_cast<int>(COND_IS_SHARED(*attr));
   return 0;
 }
 
 int pthread_condattr_setpshared(pthread_condattr_t* attr, int pshared) {
-  if (attr == NULL) {
-    return EINVAL;
-  }
   if (pshared != PTHREAD_PROCESS_SHARED && pshared != PTHREAD_PROCESS_PRIVATE) {
     return EINVAL;
   }
-  *attr = pshared;
+
+  *attr |= pshared;
+  return 0;
+}
+
+int pthread_condattr_getclock(const pthread_condattr_t* attr, clockid_t* clock) {
+  *clock = COND_GET_CLOCK(*attr);
+  return 0;
+}
+
+int pthread_condattr_setclock(pthread_condattr_t* attr, clockid_t clock) {
+  if (clock != CLOCK_MONOTONIC && clock != CLOCK_REALTIME) {
+    return EINVAL;
+  }
+
+  *attr = COND_SET_CLOCK(*attr, clock);
   return 0;
 }
 
 int pthread_condattr_destroy(pthread_condattr_t* attr) {
-  if (attr == NULL) {
-    return EINVAL;
-  }
   *attr = 0xdeada11d;
   return 0;
 }
 
-// We use one bit in condition variable values as the 'shared' flag
-// The rest is a counter.
-#define COND_SHARED_MASK        0x0001
-#define COND_COUNTER_INCREMENT  0x0002
-#define COND_COUNTER_MASK       (~COND_SHARED_MASK)
-
-#define COND_IS_SHARED(c)  (((c)->value & COND_SHARED_MASK) != 0)
 
 // XXX *technically* there is a race condition that could allow
 // XXX a signal to be missed.  If thread A is preempted in _wait()
@@ -93,24 +107,16 @@
 // XXX then the signal will be lost.
 
 int pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr) {
-  if (cond == NULL) {
-    return EINVAL;
-  }
-
-  cond->value = 0;
-
-  if (attr != NULL && *attr == PTHREAD_PROCESS_SHARED) {
-    cond->value |= COND_SHARED_MASK;
+  if (attr != NULL) {
+    cond->value = (*attr & COND_FLAGS_MASK);
+  } else {
+    cond->value = 0;
   }
 
   return 0;
 }
 
 int pthread_cond_destroy(pthread_cond_t* cond) {
-  if (cond == NULL) {
-    return EINVAL;
-  }
-
   cond->value = 0xdeadc04d;
   return 0;
 }
@@ -119,14 +125,10 @@
 // pthread_cond_signal to atomically decrement the counter
 // then wake up 'counter' threads.
 static int __pthread_cond_pulse(pthread_cond_t* cond, int counter) {
-  if (__predict_false(cond == NULL)) {
-    return EINVAL;
-  }
-
-  long flags = (cond->value & ~COND_COUNTER_MASK);
+  int flags = (cond->value & COND_FLAGS_MASK);
   while (true) {
-    long old_value = cond->value;
-    long new_value = ((old_value - COND_COUNTER_INCREMENT) & COND_COUNTER_MASK) | flags;
+    int old_value = cond->value;
+    int new_value = ((old_value - COND_COUNTER_STEP) & COND_COUNTER_MASK) | flags;
     if (__bionic_cmpxchg(old_value, new_value, &cond->value) == 0) {
       break;
     }
@@ -142,7 +144,7 @@
   // hold the mutex, they're subject to race conditions anyway.
   ANDROID_MEMBAR_FULL();
 
-  __futex_wake_ex(&cond->value, COND_IS_SHARED(cond), counter);
+  __futex_wake_ex(&cond->value, COND_IS_SHARED(cond->value), counter);
   return 0;
 }
 
@@ -151,7 +153,7 @@
   int old_value = cond->value;
 
   pthread_mutex_unlock(mutex);
-  int status = __futex_wait_ex(&cond->value, COND_IS_SHARED(cond), old_value, reltime);
+  int status = __futex_wait_ex(&cond->value, COND_IS_SHARED(cond->value), old_value, reltime);
   pthread_mutex_lock(mutex);
 
   if (status == -ETIMEDOUT) {
@@ -166,7 +168,7 @@
   timespec* tsp;
 
   if (abstime != NULL) {
-    if (__timespec_to_absolute(&ts, abstime, clock) < 0) {
+    if (__timespec_from_absolute(&ts, abstime, clock) < 0) {
       return ETIMEDOUT;
     }
     tsp = &ts;
@@ -186,28 +188,30 @@
 }
 
 int pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) {
-  return __pthread_cond_timedwait(cond, mutex, NULL, CLOCK_REALTIME);
+  return __pthread_cond_timedwait(cond, mutex, NULL, COND_GET_CLOCK(cond->value));
 }
 
 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t * mutex, const timespec *abstime) {
-  return __pthread_cond_timedwait(cond, mutex, abstime, CLOCK_REALTIME);
+  return __pthread_cond_timedwait(cond, mutex, abstime, COND_GET_CLOCK(cond->value));
 }
 
-// TODO: this exists only for backward binary compatibility.
-int pthread_cond_timedwait_monotonic(pthread_cond_t* cond, pthread_mutex_t* mutex, const timespec* abstime) {
+#if !defined(__LP64__)
+// TODO: this exists only for backward binary compatibility on 32 bit platforms.
+extern "C" int pthread_cond_timedwait_monotonic(pthread_cond_t* cond, pthread_mutex_t* mutex, const timespec* abstime) {
   return __pthread_cond_timedwait(cond, mutex, abstime, CLOCK_MONOTONIC);
 }
 
-int pthread_cond_timedwait_monotonic_np(pthread_cond_t* cond, pthread_mutex_t* mutex, const timespec* abstime) {
+extern "C" int pthread_cond_timedwait_monotonic_np(pthread_cond_t* cond, pthread_mutex_t* mutex, const timespec* abstime) {
   return __pthread_cond_timedwait(cond, mutex, abstime, CLOCK_MONOTONIC);
 }
 
-int pthread_cond_timedwait_relative_np(pthread_cond_t* cond, pthread_mutex_t* mutex, const timespec* reltime) {
+extern "C" int pthread_cond_timedwait_relative_np(pthread_cond_t* cond, pthread_mutex_t* mutex, const timespec* reltime) {
   return __pthread_cond_timedwait_relative(cond, mutex, reltime);
 }
 
-int pthread_cond_timeout_np(pthread_cond_t* cond, pthread_mutex_t* mutex, unsigned ms) {
+extern "C" int pthread_cond_timeout_np(pthread_cond_t* cond, pthread_mutex_t* mutex, unsigned ms) {
   timespec ts;
   timespec_from_ms(ts, ms);
   return __pthread_cond_timedwait_relative(cond, mutex, &ts);
 }
+#endif // !defined(__LP64__)
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index b790e2b..fc8afa2 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -30,41 +30,32 @@
 
 #include <errno.h>
 #include <sys/mman.h>
+#include <unistd.h>
 
 #include "pthread_internal.h"
 
+#include "private/bionic_macros.h"
 #include "private/bionic_ssp.h"
 #include "private/bionic_tls.h"
 #include "private/libc_logging.h"
-#include "private/thread_private.h"
 #include "private/ErrnoRestorer.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
-extern "C" pid_t __bionic_clone(uint32_t flags, void* child_stack, int* parent_tid, void* tls, int* child_tid, int (*fn)(void*), void* arg);
-extern "C" int __set_tls(void*);
-
-// Used by gdb to track thread creation. See libthread_db.
-#ifdef __i386__
-extern "C" __attribute__((noinline)) __attribute__((fastcall)) void _thread_created_hook(pid_t) {}
-#else
-extern "C" __attribute__((noinline)) void _thread_created_hook(pid_t) {}
+// x86 uses segment descriptors rather than a direct pointer to TLS.
+#if __i386__
+#include <asm/ldt.h>
+extern "C" __LIBC_HIDDEN__ void __init_user_desc(struct user_desc*, int, void*);
 #endif
 
-static pthread_mutex_t gPthreadStackCreationLock = PTHREAD_MUTEX_INITIALIZER;
-
-static pthread_mutex_t gDebuggerNotificationLock = PTHREAD_MUTEX_INITIALIZER;
+extern "C" int __isthreaded;
 
 // This code is used both by each new pthread and the code that initializes the main thread.
 void __init_tls(pthread_internal_t* thread) {
-  // Zero-initialize all the slots after TLS_SLOT_SELF and TLS_SLOT_THREAD_ID.
-  for (size_t i = TLS_SLOT_ERRNO; i < BIONIC_TLS_SLOTS; ++i) {
-    thread->tls[i] = NULL;
+  if (thread->user_allocated_stack()) {
+    // We don't know where the user got their stack, so assume the worst and zero the TLS area.
+    memset(&thread->tls[0], 0, BIONIC_TLS_SLOTS * sizeof(void*));
   }
 
-#if defined(__i386__)
-  __set_tls(thread->tls);
-#endif
-
   // Slot 0 must point to itself. The x86 Linux kernel reads the TLS from %fs:0.
   thread->tls[TLS_SLOT_SELF] = thread->tls;
   thread->tls[TLS_SLOT_THREAD_ID] = thread;
@@ -75,7 +66,7 @@
 void __init_alternate_signal_stack(pthread_internal_t* thread) {
   // Create and set an alternate signal stack.
   stack_t ss;
-  ss.ss_sp = mmap(NULL, SIGSTKSZ, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+  ss.ss_sp = mmap(NULL, SIGSTKSZ, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
   if (ss.ss_sp != MAP_FAILED) {
     ss.ss_size = SIGSTKSZ;
     ss.ss_flags = 0;
@@ -111,8 +102,6 @@
 }
 
 static void* __create_thread_stack(pthread_internal_t* thread) {
-  ScopedPthreadMutexLocker lock(&gPthreadStackCreationLock);
-
   // Create a new private anonymous map.
   int prot = PROT_READ | PROT_WRITE;
   int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
@@ -144,11 +133,8 @@
   // notify gdb about this thread before we start doing anything.
   // This also provides the memory barrier needed to ensure that all memory
   // accesses previously made by the creating thread are visible to us.
-  pthread_mutex_t* start_mutex = (pthread_mutex_t*) &thread->tls[TLS_SLOT_START_MUTEX];
-  pthread_mutex_lock(start_mutex);
-  pthread_mutex_destroy(start_mutex);
-
-  __init_tls(thread);
+  pthread_mutex_lock(&thread->startup_handshake_mutex);
+  pthread_mutex_destroy(&thread->startup_handshake_mutex);
 
   __init_alternate_signal_stack(thread);
 
@@ -169,11 +155,7 @@
                    void* (*start_routine)(void*), void* arg) {
   ErrnoRestorer errno_restorer;
 
-  // Inform the rest of the C library that at least one thread
-  // was created. This will enforce certain functions to acquire/release
-  // locks (e.g. atexit()) to protect shared global structures.
-  // This works because pthread_create() is not called by the C library
-  // initialization routine that sets up the main thread's data structures.
+  // Inform the rest of the C library that at least one thread was created.
   __isthreaded = 1;
 
   pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(calloc(sizeof(*thread), 1));
@@ -190,8 +172,8 @@
   }
 
   // Make sure the stack size and guard size are multiples of PAGE_SIZE.
-  thread->attr.stack_size = (thread->attr.stack_size + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
-  thread->attr.guard_size = (thread->attr.guard_size + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
+  thread->attr.stack_size = BIONIC_ALIGN(thread->attr.stack_size, PAGE_SIZE);
+  thread->attr.guard_size = BIONIC_ALIGN(thread->attr.guard_size, PAGE_SIZE);
 
   if (thread->attr.stack_base == NULL) {
     // The caller didn't provide a stack, so allocate one.
@@ -209,8 +191,10 @@
   // The child stack is the same address, just growing in the opposite direction.
   // At offsets >= 0, we have the TLS slots.
   // At offsets < 0, we have the child stack.
-  thread->tls = (void**)((uint8_t*)(thread->attr.stack_base) + thread->attr.stack_size - BIONIC_TLS_SLOTS * sizeof(void*));
+  thread->tls = reinterpret_cast<void**>(reinterpret_cast<uint8_t*>(thread->attr.stack_base) +
+                                         thread->attr.stack_size - BIONIC_TLS_SLOTS * sizeof(void*));
   void* child_stack = thread->tls;
+  __init_tls(thread);
 
   // Create a mutex for the thread in TLS to wait on once it starts so we can keep
   // it from doing anything until after we notify the debugger about it
@@ -218,31 +202,32 @@
   // This also provides the memory barrier we need to ensure that all
   // memory accesses previously performed by this thread are visible to
   // the new thread.
-  pthread_mutex_t* start_mutex = (pthread_mutex_t*) &thread->tls[TLS_SLOT_START_MUTEX];
-  pthread_mutex_init(start_mutex, NULL);
-  pthread_mutex_lock(start_mutex);
-
-  thread->tls[TLS_SLOT_THREAD_ID] = thread;
+  pthread_mutex_init(&thread->startup_handshake_mutex, NULL);
+  pthread_mutex_lock(&thread->startup_handshake_mutex);
 
   thread->start_routine = start_routine;
   thread->start_routine_arg = arg;
 
+  thread->set_cached_pid(getpid());
+
   int flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM |
       CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID;
+  void* tls = thread->tls;
 #if defined(__i386__)
   // On x86 (but not x86-64), CLONE_SETTLS takes a pointer to a struct user_desc rather than
-  // a pointer to the TLS itself. Rather than try to deal with that here, we just let x86 set
-  // the TLS manually in __init_tls, like all architectures used to.
-  flags &= ~CLONE_SETTLS;
+  // a pointer to the TLS itself.
+  user_desc tls_descriptor;
+  __init_user_desc(&tls_descriptor, false, tls);
+  tls = &tls_descriptor;
 #endif
-  int rc = __bionic_clone(flags, child_stack, &(thread->tid), thread->tls, &(thread->tid), __pthread_start, thread);
+  int rc = clone(__pthread_start, child_stack, flags, thread, &(thread->tid), tls, &(thread->tid));
   if (rc == -1) {
     int clone_errno = errno;
     // We don't have to unlock the mutex at all because clone(2) failed so there's no child waiting to
     // be unblocked, but we're about to unmap the memory the mutex is stored in, so this serves as a
     // reminder that you can't rewrite this function to use a ScopedPthreadMutexLocker.
-    pthread_mutex_unlock(start_mutex);
-    if ((thread->attr.flags & PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK) == 0) {
+    pthread_mutex_unlock(&thread->startup_handshake_mutex);
+    if (!thread->user_allocated_stack()) {
       munmap(thread->attr.stack_base, thread->attr.stack_size);
     }
     free(thread);
@@ -256,19 +241,13 @@
     // Letting the thread run is the easiest way to clean up its resources.
     thread->attr.flags |= PTHREAD_ATTR_FLAG_DETACHED;
     thread->start_routine = __do_nothing;
-    pthread_mutex_unlock(start_mutex);
+    pthread_mutex_unlock(&thread->startup_handshake_mutex);
     return init_errno;
   }
 
-  // Notify any debuggers about the new thread.
-  {
-    ScopedPthreadMutexLocker debugger_locker(&gDebuggerNotificationLock);
-    _thread_created_hook(thread->tid);
-  }
-
   // Publish the pthread_t and unlock the mutex to let the new thread start running.
   *thread_out = reinterpret_cast<pthread_t>(thread);
-  pthread_mutex_unlock(start_mutex);
+  pthread_mutex_unlock(&thread->startup_handshake_mutex);
 
   return 0;
 }
diff --git a/libc/bionic/pthread_debug.cpp b/libc/bionic/pthread_debug.cpp
deleted file mode 100644
index f01f040..0000000
--- a/libc/bionic/pthread_debug.cpp
+++ /dev/null
@@ -1,717 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/atomics.h>
-#include <sys/system_properties.h>
-#include <sys/mman.h>
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <pthread.h>
-#include <unwind.h>
-#include <unistd.h>
-
-#include "private/bionic_tls.h"
-#include "debug_mapinfo.h"
-#include "debug_stacktrace.h"
-#include "private/libc_logging.h"
-
-/*
- * ===========================================================================
- *      Deadlock prediction
- * ===========================================================================
- */
-/*
-The idea is to predict the possibility of deadlock by recording the order
-in which locks are acquired.  If we see an attempt to acquire a lock
-out of order, we can identify the locks and offending code.
-
-To make this work, we need to keep track of the locks held by each thread,
-and create history trees for each lock.  When a thread tries to acquire
-a new lock, we walk through the "history children" of the lock, looking
-for a match with locks the thread already holds.  If we find a match,
-it means the thread has made a request that could result in a deadlock.
-
-To support recursive locks, we always allow re-locking a currently-held
-lock, and maintain a recursion depth count.
-
-An ASCII-art example, where letters represent locks:
-
-        A
-       /|\
-      / | \
-     B  |  D
-      \ |
-       \|
-        C
-
-The above is the tree we'd have after handling lock synchronization
-sequences "ABC", "AC", "AD".  A has three children, {B, C, D}.  C is also
-a child of B.  (The lines represent pointers between parent and child.
-Every node can have multiple parents and multiple children.)
-
-If we hold AC, and want to lock B, we recursively search through B's
-children to see if A or C appears.  It does, so we reject the attempt.
-(A straightforward way to implement it: add a link from C to B, then
-determine whether the graph starting at B contains a cycle.)
-
-If we hold AC and want to lock D, we would succeed, creating a new link
-from C to D.
-
-Updates to MutexInfo structs are only allowed for the thread that holds
-the lock, so we actually do most of our deadlock prediction work after
-the lock has been acquired.
-*/
-
-#if PTHREAD_DEBUG_ENABLED
-
-// =============================================================================
-// log functions
-// =============================================================================
-
-#define LOGD(format, ...)  \
-    __libc_format_log(ANDROID_LOG_DEBUG, "pthread_debug", (format), ##__VA_ARGS__ )
-
-#define LOGW(format, ...)  \
-    __libc_format_log(ANDROID_LOG_WARN, "pthread_debug", (format), ##__VA_ARGS__ )
-
-#define LOGE(format, ...)  \
-    __libc_format_log(ANDROID_LOG_ERROR, "pthread_debug", (format), ##__VA_ARGS__ )
-
-#define LOGI(format, ...)  \
-    __libc_format_log(ANDROID_LOG_INFO, "pthread_debug", (format), ##__VA_ARGS__ )
-
-static const char* const kStartBanner =
-        "===============================================================";
-
-static const char* const kEndBanner =
-        "===============================================================";
-
-extern const char* __progname;
-
-#define STACK_TRACE_DEPTH 16
-
-/****************************************************************************/
-
-/*
- * level <= 0 : deadlock prediction disabled
- * level    1 : deadlock prediction enabled, w/o call stacks
- * level    2 : deadlock prediction enabled w/ call stacks
- */
-#define CAPTURE_CALLSTACK 2
-static int sPthreadDebugLevel = 0;
-static pid_t sPthreadDebugDisabledThread = -1;
-static pthread_mutex_t sDbgLock = PTHREAD_MUTEX_INITIALIZER;
-
-/****************************************************************************/
-
-/* some simple/lame malloc replacement
- * NOT thread-safe and leaks everything
- */
-
-#define DBG_ALLOC_BLOCK_SIZE PAGESIZE
-static size_t sDbgAllocOffset = DBG_ALLOC_BLOCK_SIZE;
-static char* sDbgAllocPtr = NULL;
-
-template <typename T>
-static T* DbgAllocLocked(size_t count = 1) {
-    size_t size = sizeof(T) * count;
-    if ((sDbgAllocOffset + size) > DBG_ALLOC_BLOCK_SIZE) {
-        sDbgAllocOffset = 0;
-        sDbgAllocPtr = reinterpret_cast<char*>(mmap(NULL, DBG_ALLOC_BLOCK_SIZE,
-                                                    PROT_READ|PROT_WRITE,
-                                                    MAP_ANON | MAP_PRIVATE, 0, 0));
-        if (sDbgAllocPtr == MAP_FAILED) {
-            return NULL;
-        }
-    }
-    void* addr = sDbgAllocPtr + sDbgAllocOffset;
-    sDbgAllocOffset += size;
-    return reinterpret_cast<T*>(addr);
-}
-
-static void* debug_realloc(void *ptr, size_t size, size_t old_size) {
-    void* addr = mmap(NULL, size, PROT_READ|PROT_WRITE,
-            MAP_ANON | MAP_PRIVATE, 0, 0);
-    if (addr != MAP_FAILED) {
-        if (ptr) {
-            memcpy(addr, ptr, old_size);
-            munmap(ptr, old_size);
-        }
-    } else {
-        addr = NULL;
-    }
-    return addr;
-}
-
-/*****************************************************************************/
-
-struct MutexInfo;
-
-typedef struct CallStack {
-    uintptr_t    depth;
-    uintptr_t*   addrs;
-} CallStack;
-
-typedef struct MutexInfo* MutexInfoListEntry;
-typedef struct CallStack  CallStackListEntry;
-
-typedef struct GrowingList {
-    int alloc;
-    int count;
-    union {
-        void*               data;
-        MutexInfoListEntry* list;
-        CallStackListEntry* stack;
-    };
-} GrowingList;
-
-typedef GrowingList MutexInfoList;
-typedef GrowingList CallStackList;
-
-typedef struct MutexInfo {
-    // thread currently holding the lock or 0
-    pid_t               owner;
-
-    // most-recently-locked doubly-linked list
-    struct MutexInfo*   prev;
-    struct MutexInfo*   next;
-
-    // for reentrant locks
-    int                 lockCount;
-    // when looking for loops in the graph, marks visited nodes
-    int                 historyMark;
-    // the actual mutex
-    pthread_mutex_t*    mutex;
-    // list of locks directly acquired AFTER this one in the same thread
-    MutexInfoList       children;
-    // list of locks directly acquired BEFORE this one in the same thread
-    MutexInfoList       parents;
-    // list of call stacks when a new link is established to this lock form its parent
-    CallStackList       stacks;
-    // call stack when this lock was acquired last
-    int                 stackDepth;
-    uintptr_t           stackTrace[STACK_TRACE_DEPTH];
-} MutexInfo;
-
-static void growingListInit(GrowingList* list) {
-    list->alloc = 0;
-    list->count = 0;
-    list->data = NULL;
-}
-
-static void growingListAdd(GrowingList* pList, size_t objSize) {
-    if (pList->count == pList->alloc) {
-        size_t oldsize = pList->alloc * objSize;
-        pList->alloc += PAGESIZE / objSize;
-        size_t size = pList->alloc * objSize;
-        pList->data = debug_realloc(pList->data, size, oldsize);
-    }
-    pList->count++;
-}
-
-static void initMutexInfo(MutexInfo* object, pthread_mutex_t* mutex) {
-    object->owner = 0;
-    object->prev = 0;
-    object->next = 0;
-    object->lockCount = 0;
-    object->historyMark = 0;
-    object->mutex = mutex;
-    growingListInit(&object->children);
-    growingListInit(&object->parents);
-    growingListInit(&object->stacks);
-    object->stackDepth = 0;
-}
-
-typedef struct ThreadInfo {
-    pid_t       pid;
-    MutexInfo*  mrl;
-} ThreadInfo;
-
-static void initThreadInfo(ThreadInfo* object, pid_t pid) {
-    object->pid = pid;
-    object->mrl = NULL;
-}
-
-/****************************************************************************/
-
-static MutexInfo* get_mutex_info(pthread_mutex_t *mutex);
-static void mutex_lock_checked(MutexInfo* mrl, MutexInfo* object);
-static void mutex_unlock_checked(MutexInfo* object);
-
-/****************************************************************************/
-
-extern "C" int pthread_mutex_lock_impl(pthread_mutex_t *mutex);
-extern "C" int pthread_mutex_unlock_impl(pthread_mutex_t *mutex);
-
-static int pthread_mutex_lock_unchecked(pthread_mutex_t *mutex) {
-    return pthread_mutex_lock_impl(mutex);
-}
-
-static int pthread_mutex_unlock_unchecked(pthread_mutex_t *mutex) {
-    return pthread_mutex_unlock_impl(mutex);
-}
-
-/****************************************************************************/
-
-static void dup_backtrace(CallStack* stack, size_t count, uintptr_t const* addrs) {
-    stack->depth = count;
-    stack->addrs = DbgAllocLocked<uintptr_t>(count);
-    memcpy(stack->addrs, addrs, count * sizeof(uintptr_t));
-}
-
-/****************************************************************************/
-
-static int historyListHas(
-        const MutexInfoList* list, MutexInfo const * obj) {
-    int i;
-    for (i=0; i<list->count; i++) {
-        if (list->list[i] == obj) {
-            return i;
-        }
-    }
-    return -1;
-}
-
-static void historyListAdd(MutexInfoList* pList, MutexInfo* obj) {
-    growingListAdd(pList, sizeof(MutexInfoListEntry));
-    pList->list[pList->count - 1] = obj;
-}
-
-static int historyListRemove(MutexInfoList* pList, MutexInfo* obj) {
-    int i;
-    for (i = pList->count-1; i >= 0; i--) {
-        if (pList->list[i] == obj) {
-            break;
-        }
-    }
-    if (i < 0) {
-        // not found!
-        return 0;
-    }
-
-    if (i != pList->count-1) {
-        // copy the last entry to the new free slot
-        pList->list[i] = pList->list[pList->count-1];
-    }
-    pList->count--;
-    memset(&pList->list[pList->count], 0, sizeof(MutexInfoListEntry));
-    return 1;
-}
-
-static void linkParentToChild(MutexInfo* parent, MutexInfo* child) {
-    historyListAdd(&parent->children, child);
-    historyListAdd(&child->parents, parent);
-}
-
-static void unlinkParentFromChild(MutexInfo* parent, MutexInfo* child) {
-    historyListRemove(&parent->children, child);
-    historyListRemove(&child->parents, parent);
-}
-
-/****************************************************************************/
-
-static void callstackListAdd(CallStackList* pList,
-        int count, uintptr_t const* addrs) {
-    growingListAdd(pList, sizeof(CallStackListEntry));
-    dup_backtrace(&pList->stack[pList->count - 1], count, addrs);
-}
-
-/****************************************************************************/
-
-/*
- * Recursively traverse the object hierarchy starting at "obj".  We mark
- * ourselves on entry and clear the mark on exit.  If we ever encounter
- * a marked object, we have a cycle.
- *
- * Returns "true" if all is well, "false" if we found a cycle.
- */
-
-static int traverseTree(MutexInfo* obj, MutexInfo const* objParent)
-{
-    /*
-     * Have we been here before?
-     */
-    if (obj->historyMark) {
-        int stackDepth;
-        uintptr_t addrs[STACK_TRACE_DEPTH];
-
-        /* Turn off prediction temporarily in this thread while logging */
-        sPthreadDebugDisabledThread = gettid();
-
-        backtrace_startup();
-
-        LOGW("%s\n", kStartBanner);
-        LOGW("pid: %d, tid: %d >>> %s <<<", getpid(), gettid(), __progname);
-        LOGW("Illegal lock attempt:\n");
-        LOGW("--- pthread_mutex_t at %p\n", obj->mutex);
-        stackDepth = get_backtrace(addrs, STACK_TRACE_DEPTH);
-        log_backtrace(addrs, stackDepth);
-
-        LOGW("+++ Currently held locks in this thread (in reverse order):");
-        MutexInfo* cur = obj;
-        pid_t ourtid = gettid();
-        int i;
-        for (i=0 ; i<cur->parents.count ; i++) {
-            MutexInfo* parent = cur->parents.list[i];
-            if (parent->owner == ourtid) {
-                LOGW("--- pthread_mutex_t at %p\n", parent->mutex);
-                if (sPthreadDebugLevel >= CAPTURE_CALLSTACK) {
-                    log_backtrace(parent->stackTrace, parent->stackDepth);
-                }
-                cur = parent;
-                break;
-            }
-        }
-
-        LOGW("+++ Earlier, the following lock order (from last to first) was established\n");
-        return 0;
-    }
-
-    obj->historyMark = 1;
-
-    MutexInfoList* pList = &obj->children;
-    int result = 1;
-    int i;
-    for (i = pList->count-1; i >= 0; i--) {
-        MutexInfo* child = pList->list[i];
-        if (!traverseTree(child,  obj)) {
-            LOGW("--- pthread_mutex_t at %p\n", obj->mutex);
-            if (sPthreadDebugLevel >= CAPTURE_CALLSTACK) {
-                int index = historyListHas(&obj->parents, objParent);
-                if ((size_t)index < (size_t)obj->stacks.count) {
-                    log_backtrace(obj->stacks.stack[index].addrs, obj->stacks.stack[index].depth);
-                } else {
-                    log_backtrace(obj->stackTrace, obj->stackDepth);
-                }
-            }
-            result = 0;
-            break;
-        }
-    }
-
-    obj->historyMark = 0;
-    return result;
-}
-
-/****************************************************************************/
-
-static void mutex_lock_checked(MutexInfo* mrl, MutexInfo* object)
-{
-    pid_t tid = gettid();
-    if (object->owner == tid) {
-        object->lockCount++;
-        return;
-    }
-
-    object->owner = tid;
-    object->lockCount = 0;
-
-    if (sPthreadDebugLevel >= CAPTURE_CALLSTACK) {
-        // always record the call stack when acquiring a lock.
-        // it's not efficient, but is useful during diagnostics
-        object->stackDepth = get_backtrace(object->stackTrace, STACK_TRACE_DEPTH);
-    }
-
-    // no other locks held in this thread -- no deadlock possible!
-    if (mrl == NULL)
-        return;
-
-    // check if the lock we're trying to acquire is a direct descendant of
-    // the most recently locked mutex in this thread, in which case we're
-    // in a good situation -- no deadlock possible
-    if (historyListHas(&mrl->children, object) >= 0)
-        return;
-
-    pthread_mutex_lock_unchecked(&sDbgLock);
-
-    linkParentToChild(mrl, object);
-    if (!traverseTree(object, mrl)) {
-        backtrace_shutdown();
-        LOGW("%s\n", kEndBanner);
-        unlinkParentFromChild(mrl, object);
-        // reenable pthread debugging for this thread
-        sPthreadDebugDisabledThread = -1;
-    } else {
-        // record the call stack for this link
-        // NOTE: the call stack is added at the same index
-        // as mrl in object->parents[]
-        // ie: object->parents.count == object->stacks.count, which is
-        // also the index.
-        if (sPthreadDebugLevel >= CAPTURE_CALLSTACK) {
-            callstackListAdd(&object->stacks,
-                    object->stackDepth, object->stackTrace);
-        }
-    }
-
-    pthread_mutex_unlock_unchecked(&sDbgLock);
-}
-
-static void mutex_unlock_checked(MutexInfo* object)
-{
-    pid_t tid = gettid();
-    if (object->owner == tid) {
-        if (object->lockCount == 0) {
-            object->owner = 0;
-        } else {
-            object->lockCount--;
-        }
-    }
-}
-
-
-// =============================================================================
-// Hash Table functions
-// =============================================================================
-
-/****************************************************************************/
-
-#define HASHTABLE_SIZE      256
-
-typedef struct HashEntry HashEntry;
-struct HashEntry {
-    size_t slot;
-    HashEntry* prev;
-    HashEntry* next;
-    void* data;
-};
-
-typedef struct HashTable HashTable;
-struct HashTable {
-    HashEntry* slots[HASHTABLE_SIZE];
-};
-
-static HashTable sMutexMap;
-static HashTable sThreadMap;
-
-/****************************************************************************/
-
-static uint32_t get_hashcode(void const * key, size_t keySize)
-{
-    uint32_t h = keySize;
-    char const* data = (char const*)key;
-    size_t i;
-    for (i = 0; i < keySize; i++) {
-        h = h * 31 + *data;
-        data++;
-    }
-    return (uint32_t)h;
-}
-
-static size_t get_index(uint32_t h)
-{
-    // We apply this secondary hashing discovered by Doug Lea to defend
-    // against bad hashes.
-    h += ~(h << 9);
-    h ^= (((unsigned int) h) >> 14);
-    h += (h << 4);
-    h ^= (((unsigned int) h) >> 10);
-    return (size_t)h & (HASHTABLE_SIZE - 1);
-}
-
-/****************************************************************************/
-
-static void hashmap_init(HashTable* table) {
-    memset(table, 0, sizeof(HashTable));
-}
-
-static void hashmap_removeEntry(HashTable* table, HashEntry* entry)
-{
-    HashEntry* prev = entry->prev;
-    HashEntry* next = entry->next;
-    if (prev != NULL) entry->prev->next = next;
-    if (next != NULL) entry->next->prev = prev;
-    if (prev == NULL) {
-        // we are the head of the list. set the head to be next
-        table->slots[entry->slot] = entry->next;
-    }
-}
-
-static HashEntry* hashmap_lookup(HashTable* table,
-        void const* key, size_t ksize,
-        int (*equals)(void const* data, void const* key))
-{
-    const uint32_t hash = get_hashcode(key, ksize);
-    const size_t slot = get_index(hash);
-
-    HashEntry* entry = table->slots[slot];
-    while (entry) {
-        if (equals(entry->data, key)) {
-            break;
-        }
-        entry = entry->next;
-    }
-
-    if (entry == NULL) {
-        // create a new entry
-        entry = DbgAllocLocked<HashEntry>();
-        entry->data = NULL;
-        entry->slot = slot;
-        entry->prev = NULL;
-        entry->next = table->slots[slot];
-        if (entry->next != NULL) {
-            entry->next->prev = entry;
-        }
-        table->slots[slot] = entry;
-    }
-    return entry;
-}
-
-/****************************************************************************/
-
-static int MutexInfo_equals(void const* data, void const* key) {
-    return ((MutexInfo const *)data)->mutex == *(pthread_mutex_t **)key;
-}
-
-static MutexInfo* get_mutex_info(pthread_mutex_t *mutex)
-{
-    pthread_mutex_lock_unchecked(&sDbgLock);
-
-    HashEntry* entry = hashmap_lookup(&sMutexMap,
-            &mutex, sizeof(mutex),
-            &MutexInfo_equals);
-    if (entry->data == NULL) {
-        MutexInfo* mutex_info = DbgAllocLocked<MutexInfo>();
-        entry->data = mutex_info;
-        initMutexInfo(mutex_info, mutex);
-    }
-
-    pthread_mutex_unlock_unchecked(&sDbgLock);
-
-    return (MutexInfo *)entry->data;
-}
-
-/****************************************************************************/
-
-static int ThreadInfo_equals(void const* data, void const* key) {
-    return ((ThreadInfo const *)data)->pid == *(pid_t *)key;
-}
-
-static ThreadInfo* get_thread_info(pid_t pid)
-{
-    pthread_mutex_lock_unchecked(&sDbgLock);
-
-    HashEntry* entry = hashmap_lookup(&sThreadMap,
-            &pid, sizeof(pid),
-            &ThreadInfo_equals);
-    if (entry->data == NULL) {
-        ThreadInfo* thread_info = DbgAllocLocked<ThreadInfo>();
-        entry->data = thread_info;
-        initThreadInfo(thread_info, pid);
-    }
-
-    pthread_mutex_unlock_unchecked(&sDbgLock);
-
-    return (ThreadInfo *)entry->data;
-}
-
-static void push_most_recently_locked(MutexInfo* mrl) {
-    ThreadInfo* tinfo = get_thread_info(gettid());
-    mrl->next = NULL;
-    mrl->prev = tinfo->mrl;
-    tinfo->mrl = mrl;
-}
-
-static void remove_most_recently_locked(MutexInfo* mrl) {
-    ThreadInfo* tinfo = get_thread_info(gettid());
-    if (mrl->next) {
-        (mrl->next)->prev = mrl->prev;
-    }
-    if (mrl->prev) {
-        (mrl->prev)->next = mrl->next;
-    }
-    if (tinfo->mrl == mrl) {
-        tinfo->mrl = mrl->next;
-    }
-}
-
-static MutexInfo* get_most_recently_locked() {
-    ThreadInfo* tinfo = get_thread_info(gettid());
-    return tinfo->mrl;
-}
-
-/****************************************************************************/
-
-/*
- * See if we were allowed to grab the lock at this time.  We do it
- * *after* acquiring the lock, rather than before, so that we can
- * freely update the MutexInfo struct.  This seems counter-intuitive,
- * but our goal is deadlock *prediction* not deadlock *prevention*.
- * (If we actually deadlock, the situation is easy to diagnose from
- * a thread dump, so there's no point making a special effort to do
- * the checks before the lock is held.)
- */
-
-extern "C" __LIBC_HIDDEN__ void pthread_debug_mutex_lock_check(pthread_mutex_t *mutex)
-{
-    if (sPthreadDebugLevel == 0) return;
-    // prediction disabled for this thread
-    if (sPthreadDebugDisabledThread == gettid())
-        return;
-    MutexInfo* object = get_mutex_info(mutex);
-    MutexInfo* mrl = get_most_recently_locked();
-    mutex_lock_checked(mrl, object);
-    push_most_recently_locked(object);
-}
-
-/*
- * pthread_debug_mutex_unlock_check() must be called with the mutex
- * still held (ie: before calling the real unlock)
- */
-
-extern "C" __LIBC_HIDDEN__ void pthread_debug_mutex_unlock_check(pthread_mutex_t *mutex)
-{
-    if (sPthreadDebugLevel == 0) return;
-    // prediction disabled for this thread
-    if (sPthreadDebugDisabledThread == gettid())
-        return;
-    MutexInfo* object = get_mutex_info(mutex);
-    remove_most_recently_locked(object);
-    mutex_unlock_checked(object);
-}
-
-#endif // PTHREAD_DEBUG_ENABLED
-
-// Called from libc_init_dynamic() just after system properties have been initialized.
-extern "C" __LIBC_HIDDEN__ void pthread_debug_init() {
-#if PTHREAD_DEBUG_ENABLED
-    char env[PROP_VALUE_MAX];
-    if (__system_property_get("debug.libc.pthread", env)) {
-        int level = atoi(env);
-        if (level) {
-            LOGI("pthread deadlock detection level %d enabled for pid %d (%s)",
-                    level, getpid(), __progname);
-            hashmap_init(&sMutexMap);
-            sPthreadDebugLevel = level;
-        }
-    }
-#endif
-}
diff --git a/libc/bionic/pthread_detach.cpp b/libc/bionic/pthread_detach.cpp
index 95f11ac..a8608e3 100644
--- a/libc/bionic/pthread_detach.cpp
+++ b/libc/bionic/pthread_detach.cpp
@@ -44,6 +44,12 @@
     return 0; // Already being joined; silently do nothing, like glibc.
   }
 
+  if (thread->tid == 0) {
+    // Already exited; clean up.
+    _pthread_internal_remove_locked(thread.get());
+    return 0;
+  }
+
   thread->attr.flags |= PTHREAD_ATTR_FLAG_DETACHED;
   return 0;
 }
diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp
index 2692762..6cd5311 100644
--- a/libc/bionic/pthread_exit.cpp
+++ b/libc/bionic/pthread_exit.cpp
@@ -34,8 +34,8 @@
 
 #include "pthread_internal.h"
 
-extern "C" void _exit_with_stack_teardown(void*, size_t);
-extern "C" void __exit(int);
+extern "C" __noreturn void _exit_with_stack_teardown(void*, size_t);
+extern "C" __noreturn void __exit(int);
 extern "C" int __set_tid_address(int*);
 
 /* CAVEAT: our implementation of pthread_cleanup_push/pop doesn't support C++ exceptions
@@ -90,9 +90,9 @@
   // Keep track of what we need to know about the stack before we lose the pthread_internal_t.
   void* stack_base = thread->attr.stack_base;
   size_t stack_size = thread->attr.stack_size;
-  bool user_allocated_stack = ((thread->attr.flags & PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK) != 0);
+  bool user_allocated_stack = thread->user_allocated_stack();
 
-  pthread_mutex_lock(&gThreadListLock);
+  pthread_mutex_lock(&g_thread_list_lock);
   if ((thread->attr.flags & PTHREAD_ATTR_FLAG_DETACHED) != 0) {
     // The thread is detached, so we can free the pthread_internal_t.
     // First make sure that the kernel does not try to clear the tid field
@@ -110,7 +110,13 @@
     // pthread_join is responsible for destroying the pthread_internal_t for non-detached threads.
     // The kernel will futex_wake on the pthread_internal_t::tid field to wake pthread_join.
   }
-  pthread_mutex_unlock(&gThreadListLock);
+  pthread_mutex_unlock(&g_thread_list_lock);
+
+  // Perform a second key cleanup. When using jemalloc, a call to free from
+  // _pthread_internal_remove_locked causes the memory associated with a key
+  // to be reallocated.
+  // TODO: When b/16847284 is fixed this call can be removed.
+  pthread_key_clean_all();
 
   if (user_allocated_stack) {
     // Cleaning up this thread's stack is the creator's responsibility, not ours.
@@ -127,7 +133,4 @@
 
     _exit_with_stack_teardown(stack_base, stack_size);
   }
-
-  // NOTREACHED, but we told the compiler this function is noreturn, and it doesn't believe us.
-  abort();
 }
diff --git a/libc/bionic/pthread_gettid_np.cpp b/libc/bionic/pthread_gettid_np.cpp
new file mode 100644
index 0000000..f4663a7
--- /dev/null
+++ b/libc/bionic/pthread_gettid_np.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "pthread_internal.h"
+#include "private/bionic_pthread.h"
+
+pid_t pthread_gettid_np(pthread_t t) {
+  return reinterpret_cast<pthread_internal_t*>(t)->tid;
+}
+
+// TODO: move callers over to pthread_gettid_np and remove this.
+pid_t __pthread_gettid(pthread_t t) {
+  return pthread_gettid_np(t);
+}
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h
index 31ed07c..a5b3002 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -30,12 +30,48 @@
 
 #include <pthread.h>
 
+/* Has the thread been detached by a pthread_join or pthread_detach call? */
+#define PTHREAD_ATTR_FLAG_DETACHED 0x00000001
+
+/* Was the thread's stack allocated by the user rather than by us? */
+#define PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK 0x00000002
+
+/* Has the thread been joined by another thread? */
+#define PTHREAD_ATTR_FLAG_JOINED 0x00000004
+
+/* Is this the main thread? */
+#define PTHREAD_ATTR_FLAG_MAIN_THREAD 0x80000000
+
 struct pthread_internal_t {
   struct pthread_internal_t* next;
   struct pthread_internal_t* prev;
 
   pid_t tid;
 
+ private:
+  pid_t cached_pid_;
+
+ public:
+  pid_t invalidate_cached_pid() {
+    pid_t old_value;
+    get_cached_pid(&old_value);
+    set_cached_pid(0);
+    return old_value;
+  }
+
+  void set_cached_pid(pid_t value) {
+    cached_pid_ = value;
+  }
+
+  bool get_cached_pid(pid_t* cached_pid) {
+    *cached_pid = cached_pid_;
+    return (*cached_pid != 0);
+  }
+
+  bool user_allocated_stack() {
+    return (attr.flags & PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK) != 0;
+  }
+
   void** tls;
 
   pthread_attr_t attr;
@@ -48,6 +84,8 @@
 
   void* alternate_signal_stack;
 
+  pthread_mutex_t startup_handshake_mutex;
+
   /*
    * The dynamic linker implements dlerror(3), which makes it hard for us to implement this
    * per-thread buffer by simply using malloc(3) and free(3).
@@ -60,25 +98,15 @@
 __LIBC_HIDDEN__ void __init_tls(pthread_internal_t* thread);
 __LIBC_HIDDEN__ void __init_alternate_signal_stack(pthread_internal_t*);
 __LIBC_HIDDEN__ void _pthread_internal_add(pthread_internal_t* thread);
-__LIBC_HIDDEN__ pthread_internal_t* __get_thread(void);
+
+/* Various third-party apps contain a backport of our pthread_rwlock implementation that uses this. */
+extern "C" __LIBC64_HIDDEN__ pthread_internal_t* __get_thread(void);
 
 __LIBC_HIDDEN__ void pthread_key_clean_all(void);
 __LIBC_HIDDEN__ void _pthread_internal_remove_locked(pthread_internal_t* thread);
 
-/* Has the thread been detached by a pthread_join or pthread_detach call? */
-#define PTHREAD_ATTR_FLAG_DETACHED 0x00000001
-
-/* Was the thread's stack allocated by the user rather than by us? */
-#define PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK 0x00000002
-
-/* Has the thread been joined by another thread? */
-#define PTHREAD_ATTR_FLAG_JOINED 0x00000004
-
-/* Is this the main thread? */
-#define PTHREAD_ATTR_FLAG_MAIN_THREAD 0x80000000
-
 /*
- * Traditionally we give threads a 1MiB stack. When we started
+ * Traditionally we gave threads a 1MiB stack. When we started
  * allocating per-thread alternate signal stacks to ease debugging of
  * stack overflows, we subtracted the same amount we were using there
  * from the default thread stack size. This should keep memory usage
@@ -86,13 +114,12 @@
  */
 #define PTHREAD_STACK_SIZE_DEFAULT ((1 * 1024 * 1024) - SIGSTKSZ)
 
-__LIBC_HIDDEN__ extern pthread_internal_t* gThreadList;
-__LIBC_HIDDEN__ extern pthread_mutex_t gThreadListLock;
+__LIBC_HIDDEN__ extern pthread_internal_t* g_thread_list;
+__LIBC_HIDDEN__ extern pthread_mutex_t g_thread_list_lock;
 
-__LIBC_HIDDEN__ int __timespec_to_absolute(timespec*, const timespec*, clockid_t);
+__LIBC_HIDDEN__ int __timespec_from_absolute(timespec*, const timespec*, clockid_t);
 
-/* needed by fork.c */
-__LIBC_HIDDEN__ extern void __timer_table_start_stop(int);
+/* Needed by fork. */
 __LIBC_HIDDEN__ extern void __bionic_atfork_run_prepare();
 __LIBC_HIDDEN__ extern void __bionic_atfork_run_child();
 __LIBC_HIDDEN__ extern void __bionic_atfork_run_parent();
diff --git a/libc/bionic/pthread_internals.cpp b/libc/bionic/pthread_internals.cpp
index 09c48dc..4c08ba8 100644
--- a/libc/bionic/pthread_internals.cpp
+++ b/libc/bionic/pthread_internals.cpp
@@ -29,12 +29,11 @@
 #include "pthread_internal.h"
 
 #include "private/bionic_futex.h"
-#include "private/bionic_pthread.h"
 #include "private/bionic_tls.h"
 #include "private/ScopedPthreadMutexLocker.h"
 
-pthread_internal_t* gThreadList = NULL;
-pthread_mutex_t gThreadListLock = PTHREAD_MUTEX_INITIALIZER;
+pthread_internal_t* g_thread_list = NULL;
+pthread_mutex_t g_thread_list_lock = PTHREAD_MUTEX_INITIALIZER;
 
 void _pthread_internal_remove_locked(pthread_internal_t* thread) {
   if (thread->next != NULL) {
@@ -43,7 +42,7 @@
   if (thread->prev != NULL) {
     thread->prev->next = thread->next;
   } else {
-    gThreadList = thread->next;
+    g_thread_list = thread->next;
   }
 
   // The main thread is not heap-allocated. See __libc_init_tls for the declaration,
@@ -54,28 +53,24 @@
 }
 
 void _pthread_internal_add(pthread_internal_t* thread) {
-  ScopedPthreadMutexLocker locker(&gThreadListLock);
+  ScopedPthreadMutexLocker locker(&g_thread_list_lock);
 
   // We insert at the head.
-  thread->next = gThreadList;
+  thread->next = g_thread_list;
   thread->prev = NULL;
   if (thread->next != NULL) {
     thread->next->prev = thread;
   }
-  gThreadList = thread;
+  g_thread_list = thread;
 }
 
 pthread_internal_t* __get_thread(void) {
   return reinterpret_cast<pthread_internal_t*>(__get_tls()[TLS_SLOT_THREAD_ID]);
 }
 
-pid_t __pthread_gettid(pthread_t t) {
-  return reinterpret_cast<pthread_internal_t*>(t)->tid;
-}
-
 // Initialize 'ts' with the difference between 'abstime' and the current time
 // according to 'clock'. Returns -1 if abstime already expired, or 0 otherwise.
-int __timespec_to_absolute(timespec* ts, const timespec* abstime, clockid_t clock) {
+int __timespec_from_absolute(timespec* ts, const timespec* abstime, clockid_t clock) {
   clock_gettime(clock, ts);
   ts->tv_sec  = abstime->tv_sec - ts->tv_sec;
   ts->tv_nsec = abstime->tv_nsec - ts->tv_nsec;
@@ -88,11 +83,3 @@
   }
   return 0;
 }
-
-int __futex_wake_ex(volatile void* ftx, int pshared, int val) {
-  return __futex_syscall3(ftx, pshared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, val);
-}
-
-int __futex_wait_ex(volatile void* ftx, int pshared, int val, const timespec* timeout) {
-  return __futex_syscall4(ftx, pshared ? FUTEX_WAIT : FUTEX_WAIT_PRIVATE, val, timeout);
-}
diff --git a/libc/bionic/pthread_key.cpp b/libc/bionic/pthread_key.cpp
index 6cc68af..27eab27 100644
--- a/libc/bionic/pthread_key.cpp
+++ b/libc/bionic/pthread_key.cpp
@@ -210,8 +210,8 @@
   }
 
   // Clear value in all threads.
-  pthread_mutex_lock(&gThreadListLock);
-  for (pthread_internal_t*  t = gThreadList; t != NULL; t = t->next) {
+  pthread_mutex_lock(&g_thread_list_lock);
+  for (pthread_internal_t*  t = g_thread_list; t != NULL; t = t->next) {
     // Skip zombie threads. They don't have a valid TLS area any more.
     // Similarly, it is possible to have t->tls == NULL for threads that
     // were just recently created through pthread_create() but whose
@@ -226,7 +226,7 @@
   }
   tls_map.DeleteKey(key);
 
-  pthread_mutex_unlock(&gThreadListLock);
+  pthread_mutex_unlock(&g_thread_list_lock);
   return 0;
 }
 
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 0d992b3..5461661 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -30,7 +30,6 @@
 
 #include <errno.h>
 #include <limits.h>
-#include <sys/atomics.h>
 #include <sys/mman.h>
 #include <unistd.h>
 
@@ -39,7 +38,6 @@
 #include "private/bionic_atomic_inline.h"
 #include "private/bionic_futex.h"
 #include "private/bionic_tls.h"
-#include "private/thread_private.h"
 
 extern void pthread_debug_mutex_lock_check(pthread_mutex_t *mutex);
 extern void pthread_debug_mutex_unlock_check(pthread_mutex_t *mutex);
@@ -207,55 +205,42 @@
 
 int pthread_mutexattr_init(pthread_mutexattr_t *attr)
 {
-    if (attr) {
-        *attr = PTHREAD_MUTEX_DEFAULT;
-        return 0;
-    } else {
-        return EINVAL;
-    }
+    *attr = PTHREAD_MUTEX_DEFAULT;
+    return 0;
 }
 
 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
 {
-    if (attr) {
-        *attr = -1;
-        return 0;
-    } else {
-        return EINVAL;
-    }
+    *attr = -1;
+    return 0;
 }
 
-int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
+int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type_p)
 {
-    if (attr) {
-        int  atype = (*attr & MUTEXATTR_TYPE_MASK);
+    int type = (*attr & MUTEXATTR_TYPE_MASK);
 
-         if (atype >= PTHREAD_MUTEX_NORMAL &&
-             atype <= PTHREAD_MUTEX_ERRORCHECK) {
-            *type = atype;
-            return 0;
-        }
+    if (type < PTHREAD_MUTEX_NORMAL || type > PTHREAD_MUTEX_ERRORCHECK) {
+        return EINVAL;
     }
-    return EINVAL;
+
+    *type_p = type;
+    return 0;
 }
 
 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
 {
-    if (attr && type >= PTHREAD_MUTEX_NORMAL &&
-                type <= PTHREAD_MUTEX_ERRORCHECK ) {
-        *attr = (*attr & ~MUTEXATTR_TYPE_MASK) | type;
-        return 0;
+    if (type < PTHREAD_MUTEX_NORMAL || type > PTHREAD_MUTEX_ERRORCHECK ) {
+        return EINVAL;
     }
-    return EINVAL;
+
+    *attr = (*attr & ~MUTEXATTR_TYPE_MASK) | type;
+    return 0;
 }
 
 /* process-shared mutexes are not supported at the moment */
 
 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int  pshared)
 {
-    if (!attr)
-        return EINVAL;
-
     switch (pshared) {
     case PTHREAD_PROCESS_PRIVATE:
         *attr &= ~MUTEXATTR_SHARED_MASK;
@@ -274,11 +259,7 @@
 }
 
 int pthread_mutexattr_getpshared(const pthread_mutexattr_t* attr, int* pshared) {
-    if (!attr || !pshared)
-        return EINVAL;
-
-    *pshared = (*attr & MUTEXATTR_SHARED_MASK) ? PTHREAD_PROCESS_SHARED
-                                               : PTHREAD_PROCESS_PRIVATE;
+    *pshared = (*attr & MUTEXATTR_SHARED_MASK) ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE;
     return 0;
 }
 
@@ -324,9 +305,7 @@
  * "type" value is zero, so the only bits that will be set are the ones in
  * the lock state field.
  */
-static __inline__ void
-_normal_lock(pthread_mutex_t*  mutex, int shared)
-{
+static inline void _normal_lock(pthread_mutex_t* mutex, int shared) {
     /* convenience shortcuts */
     const int unlocked           = shared | MUTEX_STATE_BITS_UNLOCKED;
     const int locked_uncontended = shared | MUTEX_STATE_BITS_LOCKED_UNCONTENDED;
@@ -354,8 +333,9 @@
          * that the mutex is in state 2 when we go to sleep on it, which
          * guarantees a wake-up call.
          */
-        while (__bionic_swap(locked_contended, &mutex->value) != unlocked)
-            __futex_wait_ex(&mutex->value, shared, locked_contended, 0);
+        while (__bionic_swap(locked_contended, &mutex->value) != unlocked) {
+            __futex_wait_ex(&mutex->value, shared, locked_contended, NULL);
+        }
     }
     ANDROID_MEMBAR_FULL();
 }
@@ -364,9 +344,7 @@
  * Release a non-recursive mutex.  The caller is responsible for determining
  * that we are in fact the owner of this lock.
  */
-static __inline__ void
-_normal_unlock(pthread_mutex_t*  mutex, int shared)
-{
+static inline void _normal_unlock(pthread_mutex_t* mutex, int shared) {
     ANDROID_MEMBAR_FULL();
 
     /*
@@ -428,9 +406,7 @@
  * mvalue is the current mutex value (already loaded)
  * mutex pointers to the mutex.
  */
-static __inline__ __attribute__((always_inline)) int
-_recursive_increment(pthread_mutex_t* mutex, int mvalue, int mtype)
-{
+static inline __always_inline int _recursive_increment(pthread_mutex_t* mutex, int mvalue, int mtype) {
     if (mtype == MUTEX_TYPE_BITS_ERRORCHECK) {
         /* trying to re-lock a mutex we already acquired */
         return EDEADLK;
@@ -463,16 +439,14 @@
     }
 }
 
-__LIBC_HIDDEN__
-int pthread_mutex_lock_impl(pthread_mutex_t *mutex)
-{
+int pthread_mutex_lock(pthread_mutex_t* mutex) {
     int mvalue, mtype, tid, shared;
 
     mvalue = mutex->value;
     mtype = (mvalue & MUTEX_TYPE_MASK);
     shared = (mvalue & MUTEX_SHARED_MASK);
 
-    /* Handle normal case first */
+    /* Handle non-recursive case first */
     if ( __predict_true(mtype == MUTEX_TYPE_BITS_NORMAL) ) {
         _normal_lock(mutex, shared);
         return 0;
@@ -541,20 +515,7 @@
     /* NOTREACHED */
 }
 
-int pthread_mutex_lock(pthread_mutex_t *mutex)
-{
-    int err = pthread_mutex_lock_impl(mutex);
-    if (PTHREAD_DEBUG_ENABLED) {
-        if (!err) {
-            pthread_debug_mutex_lock_check(mutex);
-        }
-    }
-    return err;
-}
-
-__LIBC_HIDDEN__
-int pthread_mutex_unlock_impl(pthread_mutex_t *mutex)
-{
+int pthread_mutex_unlock(pthread_mutex_t* mutex) {
     int mvalue, mtype, tid, shared;
 
     mvalue = mutex->value;
@@ -606,17 +567,7 @@
     return 0;
 }
 
-int pthread_mutex_unlock(pthread_mutex_t *mutex)
-{
-    if (PTHREAD_DEBUG_ENABLED) {
-        pthread_debug_mutex_unlock_check(mutex);
-    }
-    return pthread_mutex_unlock_impl(mutex);
-}
-
-__LIBC_HIDDEN__
-int pthread_mutex_trylock_impl(pthread_mutex_t *mutex)
-{
+int pthread_mutex_trylock(pthread_mutex_t* mutex) {
     int mvalue, mtype, tid, shared;
 
     mvalue = mutex->value;
@@ -656,163 +607,136 @@
     return EBUSY;
 }
 
-int pthread_mutex_trylock(pthread_mutex_t *mutex)
-{
-    int err = pthread_mutex_trylock_impl(mutex);
-    if (PTHREAD_DEBUG_ENABLED) {
-        if (!err) {
-            pthread_debug_mutex_lock_check(mutex);
-        }
+static int __pthread_mutex_timedlock(pthread_mutex_t* mutex, const timespec* abs_timeout, clockid_t clock) {
+  timespec ts;
+
+  int mvalue = mutex->value;
+  int mtype  = (mvalue & MUTEX_TYPE_MASK);
+  int shared = (mvalue & MUTEX_SHARED_MASK);
+
+  // Handle common case first.
+  if (__predict_true(mtype == MUTEX_TYPE_BITS_NORMAL)) {
+    const int unlocked           = shared | MUTEX_STATE_BITS_UNLOCKED;
+    const int locked_uncontended = shared | MUTEX_STATE_BITS_LOCKED_UNCONTENDED;
+    const int locked_contended   = shared | MUTEX_STATE_BITS_LOCKED_CONTENDED;
+
+    // Fast path for uncontended lock. Note: MUTEX_TYPE_BITS_NORMAL is 0.
+    if (__bionic_cmpxchg(unlocked, locked_uncontended, &mutex->value) == 0) {
+      ANDROID_MEMBAR_FULL();
+      return 0;
     }
-    return err;
-}
 
-/* initialize 'abstime' to the current time according to 'clock' plus 'msecs'
- * milliseconds.
- */
-static void __timespec_to_relative_msec(timespec* abstime, unsigned msecs, clockid_t clock) {
-    clock_gettime(clock, abstime);
-    abstime->tv_sec  += msecs/1000;
-    abstime->tv_nsec += (msecs%1000)*1000000;
-    if (abstime->tv_nsec >= 1000000000) {
-        abstime->tv_sec++;
-        abstime->tv_nsec -= 1000000000;
+    // Loop while needed.
+    while (__bionic_swap(locked_contended, &mutex->value) != unlocked) {
+      if (__timespec_from_absolute(&ts, abs_timeout, clock) < 0) {
+        return ETIMEDOUT;
+      }
+      __futex_wait_ex(&mutex->value, shared, locked_contended, &ts);
     }
-}
+    ANDROID_MEMBAR_FULL();
+    return 0;
+  }
 
-__LIBC_HIDDEN__
-int pthread_mutex_lock_timeout_np_impl(pthread_mutex_t *mutex, unsigned msecs)
-{
-    clockid_t        clock = CLOCK_MONOTONIC;
-    timespec  abstime;
-    timespec  ts;
-    int               mvalue, mtype, tid, shared;
+  // Do we already own this recursive or error-check mutex?
+  pid_t tid = __get_thread()->tid;
+  if (tid == MUTEX_OWNER_FROM_BITS(mvalue)) {
+    return _recursive_increment(mutex, mvalue, mtype);
+  }
 
-    /* compute absolute expiration time */
-    __timespec_to_relative_msec(&abstime, msecs, clock);
+  // The following implements the same loop as pthread_mutex_lock_impl
+  // but adds checks to ensure that the operation never exceeds the
+  // absolute expiration time.
+  mtype |= shared;
 
+  // First try a quick lock.
+  if (mvalue == mtype) {
+    mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_UNCONTENDED;
+    if (__predict_true(__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0)) {
+      ANDROID_MEMBAR_FULL();
+      return 0;
+    }
     mvalue = mutex->value;
-    mtype  = (mvalue & MUTEX_TYPE_MASK);
-    shared = (mvalue & MUTEX_SHARED_MASK);
+  }
 
-    /* Handle common case first */
-    if ( __predict_true(mtype == MUTEX_TYPE_BITS_NORMAL) )
-    {
-        const int unlocked           = shared | MUTEX_STATE_BITS_UNLOCKED;
-        const int locked_uncontended = shared | MUTEX_STATE_BITS_LOCKED_UNCONTENDED;
-        const int locked_contended   = shared | MUTEX_STATE_BITS_LOCKED_CONTENDED;
-
-        /* fast path for uncontended lock. Note: MUTEX_TYPE_BITS_NORMAL is 0 */
-        if (__bionic_cmpxchg(unlocked, locked_uncontended, &mutex->value) == 0) {
-            ANDROID_MEMBAR_FULL();
-            return 0;
-        }
-
-        /* loop while needed */
-        while (__bionic_swap(locked_contended, &mutex->value) != unlocked) {
-            if (__timespec_to_absolute(&ts, &abstime, clock) < 0)
-                return EBUSY;
-
-            __futex_wait_ex(&mutex->value, shared, locked_contended, &ts);
-        }
+  while (true) {
+    // If the value is 'unlocked', try to acquire it directly.
+    // NOTE: put state to 2 since we know there is contention.
+    if (mvalue == mtype) { // Unlocked.
+      mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_CONTENDED;
+      if (__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0) {
         ANDROID_MEMBAR_FULL();
         return 0;
+      }
+      // The value changed before we could lock it. We need to check
+      // the time to avoid livelocks, reload the value, then loop again.
+      if (__timespec_from_absolute(&ts, abs_timeout, clock) < 0) {
+        return ETIMEDOUT;
+      }
+
+      mvalue = mutex->value;
+      continue;
     }
 
-    /* Do we already own this recursive or error-check mutex ? */
-    tid = __get_thread()->tid;
-    if ( tid == MUTEX_OWNER_FROM_BITS(mvalue) )
-        return _recursive_increment(mutex, mvalue, mtype);
-
-    /* the following implements the same loop than pthread_mutex_lock_impl
-     * but adds checks to ensure that the operation never exceeds the
-     * absolute expiration time.
-     */
-    mtype |= shared;
-
-    /* first try a quick lock */
-    if (mvalue == mtype) {
-        mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_UNCONTENDED;
-        if (__predict_true(__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0)) {
-            ANDROID_MEMBAR_FULL();
-            return 0;
-        }
+    // The value is locked. If 'uncontended', try to switch its state
+    // to 'contented' to ensure we get woken up later.
+    if (MUTEX_STATE_BITS_IS_LOCKED_UNCONTENDED(mvalue)) {
+      int newval = MUTEX_STATE_BITS_FLIP_CONTENTION(mvalue);
+      if (__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0) {
+        // This failed because the value changed, reload it.
         mvalue = mutex->value;
+      } else {
+        // This succeeded, update mvalue.
+        mvalue = newval;
+      }
     }
 
-    for (;;) {
-        timespec ts;
-
-        /* if the value is 'unlocked', try to acquire it directly */
-        /* NOTE: put state to 2 since we know there is contention */
-        if (mvalue == mtype) /* unlocked */ {
-            mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_CONTENDED;
-            if (__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0) {
-                ANDROID_MEMBAR_FULL();
-                return 0;
-            }
-            /* the value changed before we could lock it. We need to check
-             * the time to avoid livelocks, reload the value, then loop again. */
-            if (__timespec_to_absolute(&ts, &abstime, clock) < 0)
-                return EBUSY;
-
-            mvalue = mutex->value;
-            continue;
-        }
-
-        /* The value is locked. If 'uncontended', try to switch its state
-         * to 'contented' to ensure we get woken up later. */
-        if (MUTEX_STATE_BITS_IS_LOCKED_UNCONTENDED(mvalue)) {
-            int newval = MUTEX_STATE_BITS_FLIP_CONTENTION(mvalue);
-            if (__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0) {
-                /* this failed because the value changed, reload it */
-                mvalue = mutex->value;
-            } else {
-                /* this succeeded, update mvalue */
-                mvalue = newval;
-            }
-        }
-
-        /* check time and update 'ts' */
-        if (__timespec_to_absolute(&ts, &abstime, clock) < 0)
-            return EBUSY;
-
-        /* Only wait to be woken up if the state is '2', otherwise we'll
-         * simply loop right now. This can happen when the second cmpxchg
-         * in our loop failed because the mutex was unlocked by another
-         * thread.
-         */
-        if (MUTEX_STATE_BITS_IS_LOCKED_CONTENDED(mvalue)) {
-            if (__futex_wait_ex(&mutex->value, shared, mvalue, &ts) == -ETIMEDOUT) {
-                return EBUSY;
-            }
-            mvalue = mutex->value;
-        }
+    // Check time and update 'ts'.
+    if (__timespec_from_absolute(&ts, abs_timeout, clock) < 0) {
+      return ETIMEDOUT;
     }
-    /* NOTREACHED */
+
+    // Only wait to be woken up if the state is '2', otherwise we'll
+    // simply loop right now. This can happen when the second cmpxchg
+    // in our loop failed because the mutex was unlocked by another thread.
+    if (MUTEX_STATE_BITS_IS_LOCKED_CONTENDED(mvalue)) {
+      if (__futex_wait_ex(&mutex->value, shared, mvalue, &ts) == -ETIMEDOUT) {
+        return ETIMEDOUT;
+      }
+      mvalue = mutex->value;
+    }
+  }
+  /* NOTREACHED */
 }
 
-int pthread_mutex_lock_timeout_np(pthread_mutex_t *mutex, unsigned msecs)
-{
-    int err = pthread_mutex_lock_timeout_np_impl(mutex, msecs);
-    if (PTHREAD_DEBUG_ENABLED) {
-        if (!err) {
-            pthread_debug_mutex_lock_check(mutex);
-        }
-    }
-    return err;
+#if !defined(__LP64__)
+extern "C" int pthread_mutex_lock_timeout_np(pthread_mutex_t* mutex, unsigned ms) {
+  timespec abs_timeout;
+  clock_gettime(CLOCK_MONOTONIC, &abs_timeout);
+  abs_timeout.tv_sec  += ms / 1000;
+  abs_timeout.tv_nsec += (ms % 1000) * 1000000;
+  if (abs_timeout.tv_nsec >= 1000000000) {
+    abs_timeout.tv_sec++;
+    abs_timeout.tv_nsec -= 1000000000;
+  }
+
+  int error = __pthread_mutex_timedlock(mutex, &abs_timeout, CLOCK_MONOTONIC);
+  if (error == ETIMEDOUT) {
+    error = EBUSY;
+  }
+  return error;
+}
+#endif
+
+int pthread_mutex_timedlock(pthread_mutex_t* mutex, const timespec* abs_timeout) {
+  return __pthread_mutex_timedlock(mutex, abs_timeout, CLOCK_REALTIME);
 }
 
-int pthread_mutex_destroy(pthread_mutex_t *mutex)
-{
-    int ret;
-
-    /* use trylock to ensure that the mutex value is
-     * valid and is not already locked. */
-    ret = pthread_mutex_trylock_impl(mutex);
-    if (ret != 0)
-        return ret;
-
-    mutex->value = 0xdead10cc;
-    return 0;
+int pthread_mutex_destroy(pthread_mutex_t* mutex) {
+  // Use trylock to ensure that the mutex is valid and not already locked.
+  int error = pthread_mutex_trylock(mutex);
+  if (error != 0) {
+    return error;
+  }
+  mutex->value = 0xdead10cc;
+  return 0;
 }
diff --git a/libc/bionic/pthread_rwlock.cpp b/libc/bionic/pthread_rwlock.cpp
index 0182ef3..063137b 100644
--- a/libc/bionic/pthread_rwlock.cpp
+++ b/libc/bionic/pthread_rwlock.cpp
@@ -26,9 +26,11 @@
  * SUCH DAMAGE.
  */
 
-#include "pthread_internal.h"
 #include <errno.h>
 
+#include "pthread_internal.h"
+#include "private/bionic_futex.h"
+
 /* Technical note:
  *
  * Possible states of a read/write lock:
@@ -40,300 +42,239 @@
  * Additionally:
  *  - trying to get the write-lock while there are any readers blocks
  *  - trying to get the read-lock while there is a writer blocks
- *  - a single thread can acquire the lock multiple times in the same mode
+ *  - a single thread can acquire the lock multiple times in read mode
  *
- *  - Posix states that behavior is undefined it a thread tries to acquire
- *    the lock in two distinct modes (e.g. write after read, or read after write).
+ *  - Posix states that behavior is undefined (may deadlock) if a thread tries
+ *    to acquire the lock
+ *      - in write mode while already holding the lock (whether in read or write mode)
+ *      - in read mode while already holding the lock in write mode.
+ *  - This implementation will return EDEADLK in "write after write" and "read after
+ *    write" cases and will deadlock in write after read case.
  *
- *  - This implementation tries to avoid writer starvation by making the readers
- *    block as soon as there is a waiting writer on the lock. However, it cannot
- *    completely eliminate it: each time the lock is unlocked, all waiting threads
- *    are woken and battle for it, which one gets it depends on the kernel scheduler
- *    and is semi-random.
+ * TODO: VERY CAREFULLY convert this to use C++11 atomics when possible. All volatile
+ * members of pthread_rwlock_t should be converted to atomics<> and __sync_bool_compare_and_swap
+ * should be changed to compare_exchange_strong accompanied by the proper ordering
+ * constraints (comments have been added with the intending ordering across the code).
+ *
+ * TODO: As it stands now, pending_readers and pending_writers could be merged into a
+ * a single waiters variable.  Keeping them separate adds a bit of clarity and keeps
+ * the door open for a writer-biased implementation.
  *
  */
 
-#define  RWLOCKATTR_DEFAULT     0
-#define  RWLOCKATTR_SHARED_MASK 0x0010
+#define RWLOCKATTR_DEFAULT     0
+#define RWLOCKATTR_SHARED_MASK 0x0010
 
-extern pthread_internal_t* __get_thread(void);
-
-int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
-{
-    if (!attr)
-        return EINVAL;
-
-    *attr = PTHREAD_PROCESS_PRIVATE;
-    return 0;
+static inline bool rwlock_is_shared(const pthread_rwlock_t* rwlock) {
+  return rwlock->attr == PTHREAD_PROCESS_SHARED;
 }
 
-int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
-{
-    if (!attr)
-        return EINVAL;
-
-    *attr = -1;
-    return 0;
+static bool timespec_from_absolute(timespec* rel_timeout, const timespec* abs_timeout) {
+  if (abs_timeout != NULL) {
+    if (__timespec_from_absolute(rel_timeout, abs_timeout, CLOCK_REALTIME) < 0) {
+      return false;
+    }
+  }
+  return true;
 }
 
-int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int  pshared)
-{
-    if (!attr)
-        return EINVAL;
+int pthread_rwlockattr_init(pthread_rwlockattr_t* attr) {
+  *attr = PTHREAD_PROCESS_PRIVATE;
+  return 0;
+}
 
-    switch (pshared) {
+int pthread_rwlockattr_destroy(pthread_rwlockattr_t* attr) {
+  *attr = -1;
+  return 0;
+}
+
+int pthread_rwlockattr_setpshared(pthread_rwlockattr_t* attr, int pshared) {
+  switch (pshared) {
     case PTHREAD_PROCESS_PRIVATE:
     case PTHREAD_PROCESS_SHARED:
-        *attr = pshared;
-        return 0;
+      *attr = pshared;
+      return 0;
     default:
-        return EINVAL;
-    }
+      return EINVAL;
+  }
 }
 
 int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t* attr, int* pshared) {
-    if (!attr || !pshared)
-        return EINVAL;
-
-    *pshared = *attr;
-    return 0;
+  *pshared = *attr;
+  return 0;
 }
 
-int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
-{
-    pthread_mutexattr_t*  lock_attr = NULL;
-    pthread_condattr_t*   cond_attr = NULL;
-    pthread_mutexattr_t   lock_attr0;
-    pthread_condattr_t    cond_attr0;
-    int                   ret;
-
-    if (rwlock == NULL)
+int pthread_rwlock_init(pthread_rwlock_t* rwlock, const pthread_rwlockattr_t* attr) {
+  if (attr != NULL) {
+    switch (*attr) {
+      case PTHREAD_PROCESS_SHARED:
+      case PTHREAD_PROCESS_PRIVATE:
+        rwlock->attr= *attr;
+        break;
+      default:
         return EINVAL;
-
-    if (attr && *attr == PTHREAD_PROCESS_SHARED) {
-        lock_attr = &lock_attr0;
-        pthread_mutexattr_init(lock_attr);
-        pthread_mutexattr_setpshared(lock_attr, PTHREAD_PROCESS_SHARED);
-
-        cond_attr = &cond_attr0;
-        pthread_condattr_init(cond_attr);
-        pthread_condattr_setpshared(cond_attr, PTHREAD_PROCESS_SHARED);
     }
+  }
 
-    ret = pthread_mutex_init(&rwlock->lock, lock_attr);
-    if (ret != 0)
-        return ret;
+  rwlock->state = 0;
+  rwlock->pending_readers = 0;
+  rwlock->pending_writers = 0;
+  rwlock->writer_thread_id = 0;
 
-    ret = pthread_cond_init(&rwlock->cond, cond_attr);
-    if (ret != 0) {
-        pthread_mutex_destroy(&rwlock->lock);
-        return ret;
-    }
-
-    rwlock->numLocks = 0;
-    rwlock->pendingReaders = 0;
-    rwlock->pendingWriters = 0;
-    rwlock->writerThreadId = 0;
-
-    return 0;
+  return 0;
 }
 
-int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
-{
-    if (rwlock == NULL)
-        return EINVAL;
-
-    if (rwlock->numLocks > 0)
-        return EBUSY;
-
-    pthread_cond_destroy(&rwlock->cond);
-    pthread_mutex_destroy(&rwlock->lock);
-    return 0;
-}
-
-/* Returns TRUE iff we can acquire a read lock. */
-static __inline__ int read_precondition(pthread_rwlock_t* rwlock, int tid)
-{
-    /* We can't have the lock if any writer is waiting for it (writer bias).
-     * This tries to avoid starvation when there are multiple readers racing.
-     */
-    if (rwlock->pendingWriters > 0)
-        return 0;
-
-    /* We can have the lock if there is no writer, or if we write-own it */
-    /* The second test avoids a self-dead lock in case of buggy code. */
-    if (rwlock->writerThreadId == 0 || rwlock->writerThreadId == tid)
-        return 1;
-
-    /* Otherwise, we can't have it */
-    return 0;
-}
-
-/* returns TRUE iff we can acquire a write lock. */
-static __inline__ int write_precondition(pthread_rwlock_t* rwlock, int tid)
-{
-    /* We can get the lock if nobody has it */
-    if (rwlock->numLocks == 0)
-        return 1;
-
-    /* Or if we already own it */
-    if (rwlock->writerThreadId == tid)
-        return 1;
-
-    /* Otherwise, not */
-    return 0;
-}
-
-/* This function is used to waken any waiting thread contending
- * for the lock. One of them should be able to grab it after
- * that.
- */
-static void _pthread_rwlock_pulse(pthread_rwlock_t *rwlock)
-{
-    if (rwlock->pendingReaders > 0 || rwlock->pendingWriters > 0)
-        pthread_cond_broadcast(&rwlock->cond);
+int pthread_rwlock_destroy(pthread_rwlock_t* rwlock) {
+  if (rwlock->state != 0) {
+    return EBUSY;
+  }
+  return 0;
 }
 
 static int __pthread_rwlock_timedrdlock(pthread_rwlock_t* rwlock, const timespec* abs_timeout) {
-  int ret = 0;
-
-  if (rwlock == NULL) {
-    return EINVAL;
+  if (__predict_false(__get_thread()->tid == rwlock->writer_thread_id)) {
+    return EDEADLK;
   }
 
-  pthread_mutex_lock(&rwlock->lock);
-  int tid = __get_thread()->tid;
-  if (__predict_false(!read_precondition(rwlock, tid))) {
-    rwlock->pendingReaders += 1;
-    do {
-      ret = pthread_cond_timedwait(&rwlock->cond, &rwlock->lock, abs_timeout);
-    } while (ret == 0 && !read_precondition(rwlock, tid));
-    rwlock->pendingReaders -= 1;
-    if (ret != 0) {
-      goto EXIT;
+  timespec ts;
+  timespec* rel_timeout = (abs_timeout == NULL) ? NULL : &ts;
+  bool done = false;
+  do {
+    // This is actually a race read as there's nothing that guarantees the atomicity of integer
+    // reads / writes. However, in practice this "never" happens so until we switch to C++11 this
+    // should work fine. The same applies in the other places this idiom is used.
+    int32_t cur_state = rwlock->state;  // C++11 relaxed atomic read
+    if (__predict_true(cur_state >= 0)) {
+      // Add as an extra reader.
+      done = __sync_bool_compare_and_swap(&rwlock->state, cur_state, cur_state + 1);  // C++11 memory_order_aquire
+    } else {
+      if (!timespec_from_absolute(rel_timeout, abs_timeout)) {
+        return ETIMEDOUT;
+      }
+      // Owner holds it in write mode, hang up.
+      // To avoid losing wake ups the pending_readers update and the state read should be
+      // sequentially consistent. (currently enforced by __sync_fetch_and_add which creates a full barrier)
+      __sync_fetch_and_add(&rwlock->pending_readers, 1);  // C++11 memory_order_relaxed (if the futex_wait ensures the ordering)
+      int ret = __futex_wait_ex(&rwlock->state, rwlock_is_shared(rwlock), cur_state, rel_timeout);
+      __sync_fetch_and_sub(&rwlock->pending_readers, 1);  // C++11 memory_order_relaxed
+      if (ret == -ETIMEDOUT) {
+        return ETIMEDOUT;
+      }
     }
-  }
-  ++rwlock->numLocks;
-EXIT:
-  pthread_mutex_unlock(&rwlock->lock);
-  return ret;
+  } while (!done);
+
+  return 0;
 }
 
 static int __pthread_rwlock_timedwrlock(pthread_rwlock_t* rwlock, const timespec* abs_timeout) {
-  int ret = 0;
-
-  if (rwlock == NULL) {
-    return EINVAL;
-  }
-
-  pthread_mutex_lock(&rwlock->lock);
   int tid = __get_thread()->tid;
-  if (__predict_false(!write_precondition(rwlock, tid))) {
-    // If we can't read yet, wait until the rwlock is unlocked
-    // and try again. Increment pendingReaders to get the
-    // cond broadcast when that happens.
-    rwlock->pendingWriters += 1;
-    do {
-      ret = pthread_cond_timedwait(&rwlock->cond, &rwlock->lock, abs_timeout);
-    } while (ret == 0 && !write_precondition(rwlock, tid));
-    rwlock->pendingWriters -= 1;
-    if (ret != 0) {
-      goto EXIT;
-    }
+  if (__predict_false(tid == rwlock->writer_thread_id)) {
+    return EDEADLK;
   }
-  ++rwlock->numLocks;
-  rwlock->writerThreadId = tid;
-EXIT:
-  pthread_mutex_unlock(&rwlock->lock);
-  return ret;
+
+  timespec ts;
+  timespec* rel_timeout = (abs_timeout == NULL) ? NULL : &ts;
+  bool done = false;
+  do {
+    int32_t cur_state = rwlock->state;
+    if (__predict_true(cur_state == 0)) {
+      // Change state from 0 to -1.
+      done =  __sync_bool_compare_and_swap(&rwlock->state, 0 /* cur state */, -1 /* new state */);  // C++11 memory_order_aquire
+    } else {
+      if (!timespec_from_absolute(rel_timeout, abs_timeout)) {
+        return ETIMEDOUT;
+      }
+      // Failed to acquire, hang up.
+      // To avoid losing wake ups the pending_writers update and the state read should be
+      // sequentially consistent. (currently enforced by __sync_fetch_and_add which creates a full barrier)
+      __sync_fetch_and_add(&rwlock->pending_writers, 1);  // C++11 memory_order_relaxed (if the futex_wait ensures the ordering)
+      int ret = __futex_wait_ex(&rwlock->state, rwlock_is_shared(rwlock), cur_state, rel_timeout);
+      __sync_fetch_and_sub(&rwlock->pending_writers, 1);  // C++11 memory_order_relaxed
+      if (ret == -ETIMEDOUT) {
+        return ETIMEDOUT;
+      }
+    }
+  } while (!done);
+
+  rwlock->writer_thread_id = tid;
+  return 0;
 }
 
 int pthread_rwlock_rdlock(pthread_rwlock_t* rwlock) {
   return __pthread_rwlock_timedrdlock(rwlock, NULL);
 }
 
-int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
-{
-    int ret = 0;
-
-    if (rwlock == NULL)
-        return EINVAL;
-
-    pthread_mutex_lock(&rwlock->lock);
-    if (__predict_false(!read_precondition(rwlock, __get_thread()->tid)))
-        ret = EBUSY;
-    else
-        ++rwlock->numLocks;
-    pthread_mutex_unlock(&rwlock->lock);
-
-    return ret;
-}
-
 int pthread_rwlock_timedrdlock(pthread_rwlock_t* rwlock, const timespec* abs_timeout) {
   return __pthread_rwlock_timedrdlock(rwlock, abs_timeout);
 }
 
+int pthread_rwlock_tryrdlock(pthread_rwlock_t* rwlock) {
+  int32_t cur_state = rwlock->state;
+  if ((cur_state >= 0) &&
+      __sync_bool_compare_and_swap(&rwlock->state, cur_state, cur_state + 1)) {  // C++11 memory_order_acquire
+    return 0;
+  }
+  return EBUSY;
+}
+
 int pthread_rwlock_wrlock(pthread_rwlock_t* rwlock) {
   return __pthread_rwlock_timedwrlock(rwlock, NULL);
 }
 
-int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
-{
-    int ret = 0;
-
-    if (rwlock == NULL)
-        return EINVAL;
-
-    pthread_mutex_lock(&rwlock->lock);
-    int tid = __get_thread()->tid;
-    if (__predict_false(!write_precondition(rwlock, tid))) {
-        ret = EBUSY;
-    } else {
-        ++rwlock->numLocks;
-        rwlock->writerThreadId = tid;
-    }
-    pthread_mutex_unlock(&rwlock->lock);
-    return ret;
-}
-
 int pthread_rwlock_timedwrlock(pthread_rwlock_t* rwlock, const timespec* abs_timeout) {
   return __pthread_rwlock_timedwrlock(rwlock, abs_timeout);
 }
 
-int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
-{
-    int  ret = 0;
+int pthread_rwlock_trywrlock(pthread_rwlock_t* rwlock) {
+  int tid = __get_thread()->tid;
+  int32_t cur_state = rwlock->state;
+  if ((cur_state == 0) &&
+      __sync_bool_compare_and_swap(&rwlock->state, 0 /* cur state */, -1 /* new state */)) {  // C++11 memory_order_acquire
+    rwlock->writer_thread_id = tid;
+    return 0;
+  }
+  return EBUSY;
+}
 
-    if (rwlock == NULL)
-        return EINVAL;
 
-    pthread_mutex_lock(&rwlock->lock);
-
-    /* The lock must be held */
-    if (rwlock->numLocks == 0) {
-        ret = EPERM;
-        goto EXIT;
+int pthread_rwlock_unlock(pthread_rwlock_t* rwlock) {
+  int tid = __get_thread()->tid;
+  bool done = false;
+  do {
+    int32_t cur_state = rwlock->state;
+    if (cur_state == 0) {
+      return EPERM;
     }
+    if (cur_state == -1) {
+      if (rwlock->writer_thread_id != tid) {
+        return EPERM;
+      }
+      // We're no longer the owner.
+      rwlock->writer_thread_id = 0;
+      // Change state from -1 to 0.
+      // We use __sync_bool_compare_and_swap to achieve sequential consistency of the state store and
+      // the following pendingX loads. A simple store with memory_order_release semantics
+      // is not enough to guarantee that the pendingX loads are not reordered before the
+      // store (which may lead to a lost wakeup).
+      __sync_bool_compare_and_swap( &rwlock->state, -1 /* cur state*/, 0 /* new state */);  // C++11 maybe memory_order_seq_cst?
 
-    /* If it has only readers, writerThreadId is 0 */
-    if (rwlock->writerThreadId == 0) {
-        if (--rwlock->numLocks == 0)
-            _pthread_rwlock_pulse(rwlock);
-    }
-    /* Otherwise, it has only a single writer, which
-     * must be ourselves.
-     */
-    else {
-        if (rwlock->writerThreadId != __get_thread()->tid) {
-            ret = EPERM;
-            goto EXIT;
+      // Wake any waiters.
+      if (__predict_false(rwlock->pending_readers > 0 || rwlock->pending_writers > 0)) {
+        __futex_wake_ex(&rwlock->state, rwlock_is_shared(rwlock), INT_MAX);
+      }
+      done = true;
+    } else { // cur_state > 0
+      // Reduce state by 1.
+      // See the comment above on why we need __sync_bool_compare_and_swap.
+      done = __sync_bool_compare_and_swap(&rwlock->state, cur_state, cur_state - 1);  // C++11 maybe memory_order_seq_cst?
+      if (done && (cur_state - 1) == 0) {
+        // There are no more readers, wake any waiters.
+        if (__predict_false(rwlock->pending_readers > 0 || rwlock->pending_writers > 0)) {
+          __futex_wake_ex(&rwlock->state, rwlock_is_shared(rwlock), INT_MAX);
         }
-        if (--rwlock->numLocks == 0) {
-            rwlock->writerThreadId = 0;
-            _pthread_rwlock_pulse(rwlock);
-        }
+      }
     }
-EXIT:
-    pthread_mutex_unlock(&rwlock->lock);
-    return ret;
+  } while (!done);
+
+  return 0;
 }
diff --git a/libc/bionic/pthread_setname_np.cpp b/libc/bionic/pthread_setname_np.cpp
index e0ecace..1ddf810 100644
--- a/libc/bionic/pthread_setname_np.cpp
+++ b/libc/bionic/pthread_setname_np.cpp
@@ -46,10 +46,6 @@
 int pthread_setname_np(pthread_t t, const char* thread_name) {
   ErrnoRestorer errno_restorer;
 
-  if (thread_name == NULL) {
-    return EINVAL;
-  }
-
   size_t thread_name_len = strlen(thread_name);
   if (thread_name_len >= MAX_TASK_COMM_LEN) {
     return ERANGE;
diff --git a/libc/bionic/ptrace.cpp b/libc/bionic/ptrace.cpp
index 5715b09..5156ec2 100644
--- a/libc/bionic/ptrace.cpp
+++ b/libc/bionic/ptrace.cpp
@@ -26,28 +26,30 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/types.h>
+#include <stdarg.h>
 #include <sys/ptrace.h>
 
-extern "C" long __ptrace(int request, pid_t pid, void* addr, void* data);
+extern "C" long __ptrace(int req, pid_t pid, void* addr, void* data);
 
-long ptrace(int request, pid_t pid, void* addr, void* data) {
-  switch (request) {
-    case PTRACE_PEEKUSR:
-    case PTRACE_PEEKTEXT:
-    case PTRACE_PEEKDATA:
-      {
-      long word;
-      long ret = __ptrace(request, pid, addr, &word);
-      if (ret == 0) {
-        return word;
-      } else {
-        // __ptrace already set errno for us.
-        return -1;
-      }
-    }
+long ptrace(int req, ...) {
+  bool is_peek = (req == PTRACE_PEEKUSR || req == PTRACE_PEEKTEXT || req == PTRACE_PEEKDATA);
+  long peek_result;
 
-    default:
-      return __ptrace(request, pid, addr, data);
+  va_list args;
+  va_start(args, req);
+  pid_t pid = va_arg(args, pid_t);
+  void* addr = va_arg(args, void*);
+  void* data;
+  if (is_peek) {
+    data = &peek_result;
+  } else {
+    data = va_arg(args, void*);
   }
+  va_end(args);
+
+  long result = __ptrace(req, pid, addr, data);
+  if (is_peek && result == 0) {
+    return peek_result;
+  }
+  return result;
 }
diff --git a/libc/bionic/ptsname.c b/libc/bionic/ptsname.c
deleted file mode 100644
index 24d5d30..0000000
--- a/libc/bionic/ptsname.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stdio.h>
-#include <unistd.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-/* not thread-safe */
-char*  ptsname( int fd )
-{
-    unsigned int  pty_num;
-    static char   buff[64];
-
-    if ( ioctl( fd, TIOCGPTN, &pty_num ) != 0 )
-        return NULL;
-
-    snprintf( buff, sizeof(buff), "/dev/pts/%u", pty_num );
-    return buff;
-}
diff --git a/libc/bionic/ptsname_r.c b/libc/bionic/ptsname_r.c
deleted file mode 100644
index 2fa4c3d..0000000
--- a/libc/bionic/ptsname_r.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stdio.h>
-#include <unistd.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <string.h>
-
-int    ptsname_r( int  fd, char*  buf, size_t  buflen)
-{
-    unsigned int  pty_num;
-    char          buff[64];
-    int           len;
-
-    if (buf == NULL) {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if ( ioctl( fd, TIOCGPTN, &pty_num ) != 0 ) {
-        errno = ENOTTY;
-        return -1;
-    }
-
-    len = snprintf( buff, sizeof(buff), "/dev/pts/%u", pty_num );
-    if (len+1 > (int)buflen) {
-        errno = ERANGE;
-        return -1;
-    }
-    memcpy( buf, buff, len+1 );
-    return 0;
-}
diff --git a/libc/bionic/pty.cpp b/libc/bionic/pty.cpp
new file mode 100644
index 0000000..995e006
--- /dev/null
+++ b/libc/bionic/pty.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <unistd.h>
+
+int getpt(void) {
+  return posix_openpt(O_RDWR|O_NOCTTY);
+}
+
+int grantpt(int) {
+  return 0;
+}
+
+int posix_openpt(int flags) {
+  return open("/dev/ptmx", flags);
+}
+
+char* ptsname(int fd) {
+  static char buf[64];
+  return ptsname_r(fd, buf, sizeof(buf)) == 0 ? buf : NULL;
+}
+
+int ptsname_r(int fd, char* buf, size_t len) {
+  if (buf == NULL) {
+    errno = EINVAL;
+    return errno;
+  }
+
+  unsigned int pty_num;
+  if (ioctl(fd, TIOCGPTN, &pty_num) != 0) {
+    errno = ENOTTY;
+    return errno;
+  }
+
+  if (snprintf(buf, len, "/dev/pts/%u", pty_num) >= static_cast<int>(len)) {
+    errno = ERANGE;
+    return errno;
+  }
+
+  return 0;
+}
+
+char* ttyname(int fd) {
+  static char buf[64];
+  return ttyname_r(fd, buf, sizeof(buf)) == 0 ? buf : NULL;
+}
+
+int ttyname_r(int fd, char* buf, size_t len) {
+  if (buf == NULL) {
+    errno = EINVAL;
+    return errno;
+  }
+
+  if (!isatty(fd)) {
+    return errno;
+  }
+
+  char path[64];
+  snprintf(path, sizeof(path), "/proc/self/fd/%d", fd);
+
+  ssize_t count = readlink(path, buf, len);
+  if (count == -1) {
+    return errno;
+  }
+  if (static_cast<size_t>(count) == len) {
+    errno = ERANGE;
+    return errno;
+  }
+  buf[count] = '\0';
+  return 0;
+}
+
+int unlockpt(int fd) {
+  int unlock = 0;
+  return ioctl(fd, TIOCSPTLCK, &unlock);
+}
diff --git a/libc/bionic/rand.cpp b/libc/bionic/rand.cpp
new file mode 100644
index 0000000..0074f2d
--- /dev/null
+++ b/libc/bionic/rand.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+
+// The BSD rand/srand is very weak. glibc just uses random/srandom instead.
+// Since we're likely to run code intended for glibc, and POSIX doesn't seem
+// to disallow this, we go that route too.
+
+int rand() {
+  return random();
+}
+
+void srand(unsigned int seed) {
+  return srandom(seed);
+}
diff --git a/libc/bionic/reboot.c b/libc/bionic/reboot.c
deleted file mode 100644
index 0fe8cdc..0000000
--- a/libc/bionic/reboot.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <unistd.h>
-#include <sys/reboot.h>
-
-int reboot (int  mode) 
-{
-    return __reboot( LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, NULL );
-}
diff --git a/libc/bionic/reboot.cpp b/libc/bionic/reboot.cpp
new file mode 100644
index 0000000..9cf4411
--- /dev/null
+++ b/libc/bionic/reboot.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+#include <sys/reboot.h>
+
+extern "C" int __reboot(int, int, int, void*);
+
+int reboot(int mode) {
+  return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, NULL);
+}
diff --git a/libc/bionic/recv.c b/libc/bionic/recv.c
deleted file mode 100644
index 779d7fa..0000000
--- a/libc/bionic/recv.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stddef.h>
-#include <sys/socket.h>
-
-ssize_t recv(int socket, void *buf, size_t buflen, unsigned int flags)
-{
-    return recvfrom(socket, buf, buflen, flags, NULL, 0);
-}
diff --git a/libc/bionic/recv.cpp b/libc/bionic/recv.cpp
new file mode 100644
index 0000000..061cd46
--- /dev/null
+++ b/libc/bionic/recv.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#undef _FORTIFY_SOURCE
+#include <sys/socket.h>
+
+ssize_t recv(int socket, void *buf, size_t len, int flags) {
+  return recvfrom(socket, buf, len, flags, NULL, 0);
+}
diff --git a/libc/bionic/sbrk.cpp b/libc/bionic/sbrk.cpp
deleted file mode 100644
index 6c9b534..0000000
--- a/libc/bionic/sbrk.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <unistd.h>
-#include <errno.h>
-
-/* Shared with brk.c. */
-extern "C" {
-  void* __bionic_brk; // TODO: should be __LIBC_HIDDEN__ but accidentally exported by NDK :-(
-}
-
-void* sbrk(ptrdiff_t increment) {
-  if (__bionic_brk == NULL) {
-    __bionic_brk = __brk(NULL);
-  }
-
-  void* original_brk = __bionic_brk;
-  void* desired_brk = (void*) ((uintptr_t) original_brk + increment);
-
-  void* new_brk = __brk(desired_brk);
-  if (new_brk == (void*) -1) {
-    return new_brk;
-  } else if (new_brk < desired_brk) {
-    errno = ENOMEM;
-    return (void*) -1;
-  }
-
-  __bionic_brk = new_brk;
-  return original_brk;
-}
diff --git a/libc/bionic/scandir.cpp b/libc/bionic/scandir.cpp
index dd22b22..9f731ab 100644
--- a/libc/bionic/scandir.cpp
+++ b/libc/bionic/scandir.cpp
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <stdlib.h>
 
+#include "private/bionic_macros.h"
 #include "private/ScopedReaddir.h"
 
 // A smart pointer to the scandir dirent**.
@@ -84,9 +85,7 @@
     return copy;
   }
 
-  // Disallow copy and assignment.
-  ScandirResult(const ScandirResult&);
-  void operator=(const ScandirResult&);
+  DISALLOW_COPY_AND_ASSIGN(ScandirResult);
 };
 
 int scandir(const char* dirname, dirent*** name_list,
@@ -113,3 +112,4 @@
   *name_list = names.release();
   return size;
 }
+__strong_alias(scandir64, scandir);
diff --git a/libc/bionic/sched_cpucount.c b/libc/bionic/sched_cpucount.c
index 9458dc8..2ea1d3f 100644
--- a/libc/bionic/sched_cpucount.c
+++ b/libc/bionic/sched_cpucount.c
@@ -28,13 +28,14 @@
 #define _GNU_SOURCE 1
 #include <sched.h>
 
-int __sched_cpucount(size_t setsize, cpu_set_t* set)
-{
-    int nn = 0, nn_max = setsize / sizeof(__CPU_BITTYPE);
-    int count = 0;
+int __sched_cpucount(size_t setsize, cpu_set_t* set) {
+  int nn = 0;
+  int nn_max = setsize / sizeof(__CPU_BITTYPE);
+  int count = 0;
 
-    for ( ; nn < nn_max; nn++ )
-        count += __builtin_popcount(set->__bits[nn]);
+  for ( ; nn < nn_max; nn++ ) {
+    count += __builtin_popcountl(set->__bits[nn]);
+  }
 
-    return count;
+  return count;
 }
diff --git a/libc/bionic/semaphore.c b/libc/bionic/semaphore.c
index 28fcb1b..1fa019e 100644
--- a/libc/bionic/semaphore.c
+++ b/libc/bionic/semaphore.c
@@ -28,7 +28,6 @@
 #include <semaphore.h>
 #include <errno.h>
 #include <sys/time.h>
-#include <sys/atomics.h>
 #include <time.h>
 #include <limits.h>
 
@@ -127,11 +126,8 @@
 }
 
 
-sem_t *sem_open(const char *name, int oflag, ...)
+sem_t *sem_open(const char *name __unused, int oflag __unused, ...)
 {
-    name=name;
-    oflag=oflag;
-
     errno = ENOSYS;
     return SEM_FAILED;
 }
@@ -148,7 +144,7 @@
 }
 
 
-int sem_unlink(const char * name)
+int sem_unlink(const char* name __unused)
 {
     errno = ENOSYS;
     return -1;
@@ -267,7 +263,6 @@
 
 int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
 {
-    int  ret;
     unsigned int shared;
 
     if (sem == NULL) {
diff --git a/libc/bionic/send.c b/libc/bionic/send.c
deleted file mode 100644
index 9978f98..0000000
--- a/libc/bionic/send.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stddef.h>
-#include <sys/socket.h>
-
-ssize_t send(int socket, const void *buf, size_t buflen, unsigned int flags)
-{
-    return (ssize_t) sendto(socket, buf, buflen, flags, NULL, 0);
-}
diff --git a/libc/bionic/send.cpp b/libc/bionic/send.cpp
new file mode 100644
index 0000000..2e5d457
--- /dev/null
+++ b/libc/bionic/send.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/socket.h>
+
+ssize_t send(int socket, const void* buf, size_t len, int flags) {
+  return sendto(socket, buf, len, flags, NULL, 0);
+}
diff --git a/libc/bionic/setlocale.cpp b/libc/bionic/setlocale.cpp
deleted file mode 100644
index e8fdc9e..0000000
--- a/libc/bionic/setlocale.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <locale.h>
-#include <stdlib.h>
-
-// setlocale(3) always fails on bionic.
-char* setlocale(int /*category*/, char const* /*locale*/) {
-    return NULL;
-}
diff --git a/libc/bionic/setpgrp.c b/libc/bionic/setpgrp.c
deleted file mode 100644
index 6dff822..0000000
--- a/libc/bionic/setpgrp.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <unistd.h>
-
-int setpgrp(void)
-{
-  return setpgid(0,0);
-}
diff --git a/libc/bionic/setpgrp.cpp b/libc/bionic/setpgrp.cpp
new file mode 100644
index 0000000..4334cd1
--- /dev/null
+++ b/libc/bionic/setpgrp.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+int setpgrp() {
+  return setpgid(0, 0);
+}
diff --git a/libc/bionic/sigaction.cpp b/libc/bionic/sigaction.cpp
index 6468b2d..225a823 100644
--- a/libc/bionic/sigaction.cpp
+++ b/libc/bionic/sigaction.cpp
@@ -42,12 +42,14 @@
     kernel_new_action.sa_flags = bionic_new_action->sa_flags;
     kernel_new_action.sa_handler = bionic_new_action->sa_handler;
     kernel_new_action.sa_mask = bionic_new_action->sa_mask;
+#ifdef SA_RESTORER
     kernel_new_action.sa_restorer = bionic_new_action->sa_restorer;
 
     if (!(kernel_new_action.sa_flags & SA_RESTORER)) {
       kernel_new_action.sa_flags |= SA_RESTORER;
       kernel_new_action.sa_restorer = &__rt_sigreturn;
     }
+#endif
   }
 
   __kernel_sigaction kernel_old_action;
@@ -60,11 +62,13 @@
     bionic_old_action->sa_flags = kernel_old_action.sa_flags;
     bionic_old_action->sa_handler = kernel_old_action.sa_handler;
     bionic_old_action->sa_mask = kernel_old_action.sa_mask;
+#ifdef SA_RESTORER
     bionic_old_action->sa_restorer = kernel_old_action.sa_restorer;
 
     if (bionic_old_action->sa_restorer == &__rt_sigreturn) {
       bionic_old_action->sa_flags &= ~SA_RESTORER;
     }
+#endif
   }
 
   return result;
diff --git a/libc/bionic/siglist.c b/libc/bionic/siglist.c
deleted file mode 100644
index f1c3377..0000000
--- a/libc/bionic/siglist.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <signal.h>
-
-const char * const sys_siglist[NSIG] = {
-#define  __BIONIC_SIGDEF(x,y,z)   [ SIG##x ] = z,
-#include <sys/_sigdefs.h>
-};
diff --git a/libc/bionic/signal.cpp b/libc/bionic/signal.cpp
index 48b2e72..66d75bd 100644
--- a/libc/bionic/signal.cpp
+++ b/libc/bionic/signal.cpp
@@ -28,7 +28,12 @@
 
 #include <signal.h>
 
-static sighandler_t _signal(int signum, sighandler_t handler, int flags) {
+#ifdef __LP64__
+static
+#else
+__LIBC_HIDDEN__
+#endif
+sighandler_t _signal(int signum, sighandler_t handler, int flags) {
   struct sigaction sa;
   sigemptyset(&sa.sa_mask);
   sa.sa_handler = handler;
@@ -41,14 +46,6 @@
   return (sighandler_t) sa.sa_handler;
 }
 
-sighandler_t bsd_signal(int signum, sighandler_t handler) {
-  return _signal(signum, handler, SA_RESTART);
-}
-
-sighandler_t sysv_signal(int signum, sighandler_t handler) {
-  return _signal(signum, handler, SA_RESETHAND);
-}
-
 sighandler_t signal(int signum, sighandler_t handler) {
-  return bsd_signal(signum, handler);
+  return _signal(signum, handler, SA_RESTART);
 }
diff --git a/libc/bionic/signalfd.cpp b/libc/bionic/signalfd.cpp
index 36ef81d..63e1db4 100644
--- a/libc/bionic/signalfd.cpp
+++ b/libc/bionic/signalfd.cpp
@@ -30,9 +30,9 @@
 
 #include "private/kernel_sigset_t.h"
 
-extern "C" int signalfd4(int fd, kernel_sigset_t* mask, size_t sizemask, int flags);
+extern "C" int __signalfd4(int fd, kernel_sigset_t* mask, size_t sizemask, int flags);
 
 int signalfd(int fd, const sigset_t* mask, int flags) {
   kernel_sigset_t in_set(mask);
-  return signalfd4(fd, &in_set, sizeof(in_set), flags);
+  return __signalfd4(fd, &in_set, sizeof(in_set), flags);
 }
diff --git a/libc/bionic/signame.c b/libc/bionic/signame.c
deleted file mode 100644
index 4611e44..0000000
--- a/libc/bionic/signame.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <signal.h>
-
-const char * const sys_signame[NSIG] = {
-#define  __BIONIC_SIGDEF(x,y,z)   [ SIG##x ] = #x,
-#include <sys/_sigdefs.h>
-};
diff --git a/libc/bionic/socket.cpp b/libc/bionic/socket.cpp
new file mode 100644
index 0000000..2f9e145
--- /dev/null
+++ b/libc/bionic/socket.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "private/NetdClientDispatch.h"
+
+#include <sys/socket.h>
+
+int socket(int domain, int type, int protocol) {
+    return __netdClientDispatch.socket(domain, type, protocol);
+}
diff --git a/libc/bionic/stat.cpp b/libc/bionic/stat.cpp
index 62387c5..e71d9d4 100644
--- a/libc/bionic/stat.cpp
+++ b/libc/bionic/stat.cpp
@@ -34,3 +34,4 @@
 int stat(const char* path, struct stat* sb) {
   return fstatat(AT_FDCWD, path, sb, 0);
 }
+__strong_alias(stat64, stat);
diff --git a/libc/bionic/statvfs.cpp b/libc/bionic/statvfs.cpp
index 39c9332..f1e2833 100644
--- a/libc/bionic/statvfs.cpp
+++ b/libc/bionic/statvfs.cpp
@@ -53,6 +53,7 @@
   __statfs_to_statvfs(tmp, result);
   return 0;
 }
+__strong_alias(statvfs64, statvfs);
 
 int fstatvfs(int fd, struct statvfs* result) {
   struct statfs tmp;
@@ -63,3 +64,4 @@
   __statfs_to_statvfs(tmp, result);
   return 0;
 }
+__strong_alias(fstatvfs64, fstatvfs);
diff --git a/libc/bionic/strchr.cpp b/libc/bionic/strchr.cpp
index 029fbd9..5bd3f19 100644
--- a/libc/bionic/strchr.cpp
+++ b/libc/bionic/strchr.cpp
@@ -30,6 +30,6 @@
 #undef _FORTIFY_SOURCE
 #include <string.h>
 
-extern "C" char* strchr(const char* p, int ch) {
+char* strchr(const char* p, int ch) {
   return __strchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
 }
diff --git a/libc/bionic/strcoll_l.cpp b/libc/bionic/strcoll_l.cpp
new file mode 100644
index 0000000..7d7c28b
--- /dev/null
+++ b/libc/bionic/strcoll_l.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+int strcoll_l(const char *s1, const char *s2, locale_t) {
+  return strcoll(s1, s2);
+}
diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp
index 81120ec..1e57cc0 100644
--- a/libc/bionic/strerror_r.cpp
+++ b/libc/bionic/strerror_r.cpp
@@ -8,6 +8,7 @@
 #include <string.h>
 
 #include "private/ErrnoRestorer.h"
+#include "private/libc_logging.h"
 
 struct Pair {
   int code;
@@ -34,7 +35,7 @@
 }
 
 static const Pair _sys_signal_strings[] = {
-#define  __BIONIC_SIGDEF(x,y,z)  { y, z },
+#define  __BIONIC_SIGDEF(signal_number, signal_description)  { signal_number, signal_description },
 #include <sys/_sigdefs.h>
   { 0, NULL }
 };
@@ -49,9 +50,9 @@
 
   const char* error_name = __strerror_lookup(error_number);
   if (error_name != NULL) {
-    length = snprintf(buf, buf_len, "%s", error_name);
+    length = strlcpy(buf, error_name, buf_len);
   } else {
-    length = snprintf(buf, buf_len, "Unknown error %d", error_number);
+    length = __libc_format_buffer(buf, buf_len, "Unknown error %d", error_number);
   }
   if (length >= buf_len) {
     errno_restorer.override(ERANGE);
diff --git a/libc/bionic/strftime_l.cpp b/libc/bionic/strftime_l.cpp
new file mode 100644
index 0000000..fb01da5
--- /dev/null
+++ b/libc/bionic/strftime_l.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <time.h>
+
+size_t strftime_l(char *s, size_t max, const char *format, const struct tm *tm,
+                  locale_t) {
+  return strftime(s, max, format, tm);
+}
diff --git a/libc/bionic/strndup.c b/libc/bionic/strndup.c
deleted file mode 100644
index 9dca79c..0000000
--- a/libc/bionic/strndup.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <string.h>
-#include <stdlib.h>
-
-char*  strndup(const char*  s, size_t n)
-{
-    size_t  slen = (size_t)strlen(s);
-    char*   copy;
-
-    if (slen < n)
-        n = slen;
-    copy = malloc(n+1);
-    if (copy) {
-        memcpy(copy, s, n);
-        copy[n] = 0;
-    }
-    return copy;
-}
diff --git a/libc/bionic/strntoimax.c b/libc/bionic/strntoimax.c
deleted file mode 100644
index 2f3cd9a..0000000
--- a/libc/bionic/strntoimax.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stddef.h>
-#include <inttypes.h>
-
-intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
-{
-  return (intmax_t) strntoumax(nptr, endptr, base, n);
-}
diff --git a/libc/bionic/strntoumax.c b/libc/bionic/strntoumax.c
deleted file mode 100644
index 050d718..0000000
--- a/libc/bionic/strntoumax.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stddef.h>
-#include <stdint.h>
-#include <ctype.h>
-
-static inline int digitval(int ch)
-{
-    unsigned  d;
-
-    d = (unsigned)(ch - '0');
-    if (d < 10) return (int)d;
-
-    d = (unsigned)(ch - 'a');
-    if (d < 6) return (int)(d+10);
-
-    d = (unsigned)(ch - 'A');
-    if (d < 6) return (int)(d+10);
-
-    return -1;
-}
-
-uintmax_t
-strntoumax(const char *nptr, char **endptr, int base, size_t n)
-{
-    const unsigned char*  p   = (const unsigned char *)nptr;
-    const unsigned char*  end = p + n;
-    int                   minus = 0;
-    uintmax_t             v = 0;
-    int                   d;
-
-    /* skip leading space */
-    while (p < end && isspace(*p))
-        p++;
-
-    /* Single optional + or - */
-    if (p < end) {
-        char c = p[0];
-        if ( c == '-' || c == '+' ) {
-            minus = (c == '-');
-            p++;
-        }
-    }
-
-    if ( base == 0 ) {
-        if ( p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X') ) {
-            p += 2;
-            base = 16;
-        } else if ( p+1 < end && p[0] == '0' ) {
-            p   += 1;
-            base = 8;
-        } else {
-            base = 10;
-        }
-    } else if ( base == 16 ) {
-        if ( p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X') ) {
-            p += 2;
-        }
-    }
-
-    while ( p < end && (d = digitval(*p)) >= 0 && d < base ) {
-        v = v*base + d;
-        p += 1;
-    }
-
-    if ( endptr )
-        *endptr = (char *)p;
-
-    return minus ? -v : v;
-}
diff --git a/libc/bionic/strrchr.cpp b/libc/bionic/strrchr.cpp
new file mode 100644
index 0000000..3fdb47c
--- /dev/null
+++ b/libc/bionic/strrchr.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#undef _FORTIFY_SOURCE
+#include <string.h>
+
+char* strrchr(const char* p, int ch) {
+  return __strrchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
+}
diff --git a/libc/bionic/strtold.cpp b/libc/bionic/strtold.cpp
new file mode 100644
index 0000000..5616cf7
--- /dev/null
+++ b/libc/bionic/strtold.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <float.h>
+#include <stdlib.h>
+
+extern "C" int __strtorQ(const char*, char**, int, void*);
+
+long double strtold(const char* s, char** end_ptr) {
+#if __LP64__
+  long double result;
+  __strtorQ(s, end_ptr, FLT_ROUNDS, &result);
+  return result;
+#else
+  // This is fine for LP32 where long double is just double.
+  return strtod(s, end_ptr);
+#endif
+}
diff --git a/libc/bionic/strtold_l.cpp b/libc/bionic/strtold_l.cpp
new file mode 100644
index 0000000..4b230b9
--- /dev/null
+++ b/libc/bionic/strtold_l.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+long double strtold_l(const char *nptr, char **endptr, locale_t) {
+  return strtold(nptr, endptr);
+}
diff --git a/libc/bionic/strtoll_l.cpp b/libc/bionic/strtoll_l.cpp
new file mode 100644
index 0000000..47b126e
--- /dev/null
+++ b/libc/bionic/strtoll_l.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+long long strtoll_l(const char *nptr, char **endptr, int base, locale_t) {
+  return strtoll(nptr, endptr, base);
+}
diff --git a/libc/bionic/strtotimeval.c b/libc/bionic/strtotimeval.c
deleted file mode 100644
index 1c132ec..0000000
--- a/libc/bionic/strtotimeval.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <ctype.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <sys/time.h>
-
-char * strtotimeval (const char *str, struct timeval *ts)
-{
-    int n;
-    char *s, *s0;
-    long  fs;	/* Fractional seconds */
-
-    ts->tv_sec = strtoumax(str, &s, 10);
-    fs = 0;
-
-    if ( *s == '.' ) {
-	int  count;
-
-        s0 = s+1;
-
-	/* read up to 6 digits */
-	fs    = 0;
-	count = 0;
-	while ( *s && isdigit(*s) )
-	{
-            if ( ++count < 7 )
-	        fs = fs*10 + (*s - '0');
-	    s++;
-	}
-
-	for ( ; count < 6; count++ )
-	    fs *= 10;
-    }
-
-    ts->tv_usec = fs;
-    return s;
-}
diff --git a/libc/bionic/strtoull_l.cpp b/libc/bionic/strtoull_l.cpp
new file mode 100644
index 0000000..398ba0e
--- /dev/null
+++ b/libc/bionic/strtoull_l.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+unsigned long long strtoull_l(const char *nptr, char **endptr, int base,
+                              locale_t) {
+  return strtoull(nptr, endptr, base);
+}
diff --git a/libc/bionic/strxfrm_l.cpp b/libc/bionic/strxfrm_l.cpp
new file mode 100644
index 0000000..afe3b96
--- /dev/null
+++ b/libc/bionic/strxfrm_l.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+size_t strxfrm_l(char *dest, const char *src, size_t n, locale_t) {
+  return strxfrm(dest, src, n);
+}
diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp
index 707036a..b1e38be 100644
--- a/libc/bionic/stubs.cpp
+++ b/libc/bionic/stubs.cpp
@@ -89,9 +89,11 @@
   // Copy the strings.
   snprintf(buf, byte_count, "%s%c%s%c%s", src->pw_name, 0, src->pw_dir, 0, src->pw_shell);
 
-  // pw_passwd is non-POSIX and unused (always NULL) in bionic.
-  // pw_gecos is non-POSIX and missing in bionic.
+  // pw_passwd and pw_gecos are non-POSIX and unused (always NULL) in bionic.
   dst->pw_passwd = NULL;
+#ifdef __LP64__
+  dst->pw_gecos = NULL;
+#endif
 
   // Copy the integral fields.
   dst->pw_gid = src->pw_gid;
@@ -442,31 +444,6 @@
   UNIMPLEMENTED;
 }
 
-mntent* getmntent(FILE* /*f*/) {
-  UNIMPLEMENTED;
-  return NULL;
-}
-
-FILE* setmntent(const char*, const char*) {
-  UNIMPLEMENTED;
-  return NULL;
-}
-
-int endmntent(FILE*) {
-  UNIMPLEMENTED;
-  return 1; /* Allways returns 1 according to man */
-}
-
-char* ttyname(int /*fd*/) { // NOLINT: implementing bad function.
-  UNIMPLEMENTED;
-  return NULL;
-}
-
-int ttyname_r(int /*fd*/, char* /*buf*/, size_t /*buflen*/) {
-  UNIMPLEMENTED;
-  return -ERANGE;
-}
-
 char* getusershell() {
   UNIMPLEMENTED;
   return NULL;
@@ -480,7 +457,8 @@
   UNIMPLEMENTED;
 }
 
-// Portable code should use sysconf(_SC_PAGESIZE) directly instead.
+// Portable code should use sysconf(_SC_PAGE_SIZE) directly instead.
 int getpagesize() {
-  return sysconf(_SC_PAGESIZE);
+  // We dont use sysconf(3) here because that drags in stdio, which makes static binaries fat.
+  return PAGE_SIZE;
 }
diff --git a/libc/bionic/sys_siglist.c b/libc/bionic/sys_siglist.c
new file mode 100644
index 0000000..3cfddbf
--- /dev/null
+++ b/libc/bionic/sys_siglist.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <signal.h>
+
+const char* const sys_siglist[NSIG] = {
+#define __BIONIC_SIGDEF(signal_number, signal_description) [ signal_number ] = signal_description,
+#include <sys/_sigdefs.h>
+};
diff --git a/libc/bionic/sys_signame.c b/libc/bionic/sys_signame.c
new file mode 100644
index 0000000..e1286f2
--- /dev/null
+++ b/libc/bionic/sys_signame.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <signal.h>
+
+const char* const sys_signame[NSIG] = {
+#define __BIONIC_SIGDEF(signal_number, unused) [ signal_number ] = #signal_number + 3,
+#include <sys/_sigdefs.h>
+};
diff --git a/libc/bionic/sysconf.cpp b/libc/bionic/sysconf.cpp
index db808c2..8309f08 100644
--- a/libc/bionic/sysconf.cpp
+++ b/libc/bionic/sysconf.cpp
@@ -229,8 +229,11 @@
 #endif
     case _SC_ATEXIT_MAX:        return SYSTEM_ATEXIT_MAX;
     case _SC_IOV_MAX:           return SYSTEM_IOV_MAX;
-    case _SC_PAGESIZE:          return PAGE_SIZE;
-    case _SC_PAGE_SIZE:         return PAGE_SIZE;
+
+    case _SC_PAGESIZE:
+    case _SC_PAGE_SIZE:
+        return PAGE_SIZE;
+
 #ifdef _XOPEN_UNIX
     case _SC_XOPEN_UNIX:        return _XOPEN_UNIX;
 #endif
@@ -306,7 +309,7 @@
       return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
 
     case _SC_THREAD_KEYS_MAX:
-      return (BIONIC_TLS_SLOTS - TLS_SLOT_FIRST_USER_SLOT - GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT);
+      return (BIONIC_TLS_SLOTS - TLS_SLOT_FIRST_USER_SLOT - BIONIC_TLS_RESERVED_SLOTS);
 
     case _SC_THREAD_STACK_MIN:    return PTHREAD_STACK_MIN;
     case _SC_THREAD_THREADS_MAX:  return SYSTEM_THREAD_THREADS_MAX;
@@ -314,12 +317,10 @@
 #ifdef _POSIX_THREADS
     case _SC_THREADS:             return _POSIX_THREADS;
 #endif
-#ifdef _POSIX_THREAD_ATTR_STACKADDR
-    case _SC_THREAD_ATTR_STACKADDR:   return _POSIX_THREAD_ATTR_STACKADDR;
-#endif
-#ifdef _POSIX_THREAD_ATTR_STACKSIZE
-    case _SC_THREAD_ATTR_STACKSIZE:   return _POSIX_THREAD_ATTR_STACKSIZE;
-#endif
+
+    case _SC_THREAD_ATTR_STACKADDR:   return -1; // Removed in POSIX 2008
+    case _SC_THREAD_ATTR_STACKSIZE:   return -1; // Removed in POSIX 2008
+
 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
     case _SC_THREAD_PRIORITY_SCHEDULING:  return _POSIX_THREAD_PRIORITY_SCHEDULING;
 #endif
diff --git a/libc/bionic/syslog.cpp b/libc/bionic/syslog.cpp
new file mode 100644
index 0000000..d8b8b19
--- /dev/null
+++ b/libc/bionic/syslog.cpp
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <syslog.h>
+
+#include "private/libc_logging.h"
+
+static const char* syslog_log_tag = NULL;
+static int syslog_priority_mask = 0xff;
+
+void closelog() {
+  syslog_log_tag = NULL;
+}
+
+void openlog(const char* log_tag, int /*options*/, int /*facility*/) {
+  syslog_log_tag = log_tag;
+}
+
+int setlogmask(int new_mask) {
+  int old_mask = syslog_priority_mask;
+  // 0 is used to query the current mask.
+  if (new_mask != 0) {
+    syslog_priority_mask = new_mask;
+  }
+  return old_mask;
+}
+
+void syslog(int priority, const char* fmt, ...) {
+  va_list args;
+  va_start(args, fmt);
+  vsyslog(priority, fmt, args);
+  va_end(args);
+}
+
+void vsyslog(int priority, const char* fmt, va_list args) {
+  int caller_errno = errno;
+
+  // Check whether we're supposed to be logging messages of this priority.
+  if ((syslog_priority_mask & LOG_MASK(LOG_PRI(priority))) == 0) {
+    return;
+  }
+
+  // What's our log tag?
+  const char* log_tag = syslog_log_tag;
+  if (log_tag == NULL) {
+    log_tag = getprogname();
+  }
+
+  // What's our Android log priority?
+  priority &= LOG_PRIMASK;
+  int android_log_priority;
+  if (priority <= LOG_ERR) {
+    android_log_priority = ANDROID_LOG_ERROR;
+  } else if (priority == LOG_WARNING) {
+    android_log_priority = ANDROID_LOG_WARN;
+  } else if (priority <= LOG_INFO) {
+    android_log_priority = ANDROID_LOG_INFO;
+  } else {
+    android_log_priority = ANDROID_LOG_DEBUG;
+  }
+
+  // glibc's printf family support %m directly, but our BSD-based one doesn't.
+  // If the format string seems to contain "%m", rewrite it.
+  const char* log_fmt = fmt;
+  if (strstr(fmt, "%m") != NULL) {
+    size_t dst_len = 1024;
+    char* dst = reinterpret_cast<char*>(malloc(dst_len));
+    log_fmt = dst;
+
+    const char* src = fmt;
+    for (; dst_len > 0 && *src != '\0'; ++src) {
+      if (*src == '%' && *(src + 1) == 'm') {
+        // Expand %m.
+        size_t n = strlcpy(dst, strerror(caller_errno), dst_len);
+        if (n >= dst_len) {
+          n = dst_len;
+        }
+        dst += n;
+        dst_len -= n;
+        ++src;
+      } else if (*src == '%' && *(src + 1) == '%') {
+        // We need to copy pairs of '%'s so the %m test works.
+        if (dst_len <= 2) {
+          break;
+        }
+        *dst++ = '%'; --dst_len;
+        *dst++ = '%'; --dst_len;
+        ++src;
+      } else {
+        *dst++ = *src; --dst_len;
+      }
+    }
+    *dst = '\0';
+  }
+
+  // We can't let __libc_format_log do the formatting because it doesn't support
+  // all the printf functionality.
+  char log_line[1024];
+  vsnprintf(log_line, sizeof(log_line), log_fmt, args);
+
+  if (log_fmt != fmt) {
+    free(const_cast<char*>(log_fmt));
+  }
+
+  __libc_format_log(android_log_priority, log_tag, "%s", log_line);
+}
diff --git a/libc/bionic/system_properties.c b/libc/bionic/system_properties.c
deleted file mode 100644
index 825894f..0000000
--- a/libc/bionic/system_properties.c
+++ /dev/null
@@ -1,714 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <errno.h>
-#include <poll.h>
-#include <fcntl.h>
-#include <stdbool.h>
-#include <string.h>
-
-#include <sys/mman.h>
-
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/select.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <unistd.h>
-
-#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
-#include <sys/_system_properties.h>
-
-#include <sys/atomics.h>
-
-#include "private/bionic_atomic_inline.h"
-
-#define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
-
-struct prop_area {
-    unsigned bytes_used;
-    unsigned volatile serial;
-    unsigned magic;
-    unsigned version;
-    unsigned reserved[28];
-    char data[0];
-};
-
-typedef struct prop_area prop_area;
-
-struct prop_info {
-    unsigned volatile serial;
-    char value[PROP_VALUE_MAX];
-    char name[0];
-};
-
-typedef struct prop_info prop_info;
-
-/*
- * Properties are stored in a hybrid trie/binary tree structure.
- * Each property's name is delimited at '.' characters, and the tokens are put
- * into a trie structure.  Siblings at each level of the trie are stored in a
- * binary tree.  For instance, "ro.secure"="1" could be stored as follows:
- *
- * +-----+   children    +----+   children    +--------+
- * |     |-------------->| ro |-------------->| secure |
- * +-----+               +----+               +--------+
- *                       /    \                /   |
- *                 left /      \ right   left /    |  prop   +===========+
- *                     v        v            v     +-------->| ro.secure |
- *                  +-----+   +-----+     +-----+            +-----------+
- *                  | net |   | sys |     | com |            |     1     |
- *                  +-----+   +-----+     +-----+            +===========+
- */
-
-typedef volatile uint32_t prop_off_t;
-struct prop_bt {
-    uint8_t namelen;
-    uint8_t reserved[3];
-
-    prop_off_t prop;
-
-    prop_off_t left;
-    prop_off_t right;
-
-    prop_off_t children;
-
-    char name[0];
-};
-
-typedef struct prop_bt prop_bt;
-
-static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
-static char property_filename[PATH_MAX] = PROP_FILENAME;
-static bool compat_mode = false;
-
-prop_area *__system_property_area__ = NULL;
-
-size_t pa_data_size;
-size_t pa_size;
-
-static int get_fd_from_env(void)
-{
-    char *env = getenv("ANDROID_PROPERTY_WORKSPACE");
-
-    if (!env) {
-        return -1;
-    }
-
-    return atoi(env);
-}
-
-static int map_prop_area_rw()
-{
-    prop_area *pa;
-    int fd;
-    int ret;
-
-    /* dev is a tmpfs that we can use to carve a shared workspace
-     * out of, so let's do that...
-     */
-    fd = open(property_filename, O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC |
-            O_EXCL, 0444);
-    if (fd < 0) {
-        if (errno == EACCES) {
-            /* for consistency with the case where the process has already
-             * mapped the page in and segfaults when trying to write to it
-             */
-            abort();
-        }
-        return -1;
-    }
-
-    ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
-    if (ret < 0)
-        goto out;
-
-    if (ftruncate(fd, PA_SIZE) < 0)
-        goto out;
-
-    pa_size = PA_SIZE;
-    pa_data_size = pa_size - sizeof(prop_area);
-    compat_mode = false;
-
-    pa = mmap(NULL, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-    if(pa == MAP_FAILED)
-        goto out;
-
-    memset(pa, 0, pa_size);
-    pa->magic = PROP_AREA_MAGIC;
-    pa->version = PROP_AREA_VERSION;
-    /* reserve root node */
-    pa->bytes_used = sizeof(prop_bt);
-
-    /* plug into the lib property services */
-    __system_property_area__ = pa;
-
-    close(fd);
-    return 0;
-
-out:
-    close(fd);
-    return -1;
-}
-
-int __system_property_set_filename(const char *filename)
-{
-    size_t len = strlen(filename);
-    if (len >= sizeof(property_filename))
-        return -1;
-
-    strcpy(property_filename, filename);
-    return 0;
-}
-
-int __system_property_area_init()
-{
-    return map_prop_area_rw();
-}
-
-static int map_prop_area()
-{
-    bool fromFile = true;
-    int result = -1;
-    int fd;
-    int ret;
-
-    fd = open(property_filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
-    if (fd >= 0) {
-        /* For old kernels that don't support O_CLOEXEC */
-        ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
-        if (ret < 0)
-            goto cleanup;
-    }
-
-    if ((fd < 0) && (errno == ENOENT)) {
-        /*
-         * For backwards compatibility, if the file doesn't
-         * exist, we use the environment to get the file descriptor.
-         * For security reasons, we only use this backup if the kernel
-         * returns ENOENT. We don't want to use the backup if the kernel
-         * returns other errors such as ENOMEM or ENFILE, since it
-         * might be possible for an external program to trigger this
-         * condition.
-         */
-        fd = get_fd_from_env();
-        fromFile = false;
-    }
-
-    if (fd < 0) {
-        return -1;
-    }
-
-    struct stat fd_stat;
-    if (fstat(fd, &fd_stat) < 0) {
-        goto cleanup;
-    }
-
-    if ((fd_stat.st_uid != 0)
-            || (fd_stat.st_gid != 0)
-            || ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0)
-            || (fd_stat.st_size < sizeof(prop_area)) ) {
-        goto cleanup;
-    }
-
-    pa_size = fd_stat.st_size;
-    pa_data_size = pa_size - sizeof(prop_area);
-    prop_area *pa = mmap(NULL, pa_size, PROT_READ, MAP_SHARED, fd, 0);
-
-    if (pa == MAP_FAILED) {
-        goto cleanup;
-    }
-
-    if((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION &&
-                pa->version != PROP_AREA_VERSION_COMPAT)) {
-        munmap(pa, pa_size);
-        goto cleanup;
-    }
-
-    if (pa->version == PROP_AREA_VERSION_COMPAT) {
-        compat_mode = true;
-    }
-
-    result = 0;
-
-    __system_property_area__ = pa;
-
-cleanup:
-    if (fromFile) {
-        close(fd);
-    }
-
-    return result;
-}
-
-int __system_properties_init()
-{
-    return map_prop_area();
-}
-
-static void *new_prop_obj(size_t size, prop_off_t *off)
-{
-    prop_area *pa = __system_property_area__;
-    size = ALIGN(size, sizeof(uint32_t));
-
-    if (pa->bytes_used + size > pa_data_size)
-        return NULL;
-
-    *off = pa->bytes_used;
-    __system_property_area__->bytes_used += size;
-    return __system_property_area__->data + *off;
-}
-
-static prop_bt *new_prop_bt(const char *name, uint8_t namelen, prop_off_t *off)
-{
-    prop_off_t off_tmp;
-    prop_bt *bt = new_prop_obj(sizeof(prop_bt) + namelen + 1, &off_tmp);
-    if (bt) {
-        memcpy(bt->name, name, namelen);
-        bt->name[namelen] = '\0';
-        bt->namelen = namelen;
-        ANDROID_MEMBAR_FULL();
-        *off = off_tmp;
-    }
-
-    return bt;
-}
-
-static prop_info *new_prop_info(const char *name, uint8_t namelen,
-        const char *value, uint8_t valuelen, prop_off_t *off)
-{
-    prop_off_t off_tmp;
-    prop_info *info = new_prop_obj(sizeof(prop_info) + namelen + 1, &off_tmp);
-    if (info) {
-        memcpy(info->name, name, namelen);
-        info->name[namelen] = '\0';
-        info->serial = (valuelen << 24);
-        memcpy(info->value, value, valuelen);
-        info->value[valuelen] = '\0';
-        ANDROID_MEMBAR_FULL();
-        *off = off_tmp;
-    }
-
-    return info;
-}
-
-static void *to_prop_obj(prop_off_t off)
-{
-    if (off > pa_data_size)
-        return NULL;
-    if (!__system_property_area__)
-        return NULL;
-
-    return __system_property_area__->data + off;
-}
-
-static prop_bt *root_node()
-{
-    return to_prop_obj(0);
-}
-
-static int cmp_prop_name(const char *one, uint8_t one_len, const char *two,
-        uint8_t two_len)
-{
-    if (one_len < two_len)
-        return -1;
-    else if (one_len > two_len)
-        return 1;
-    else
-        return strncmp(one, two, one_len);
-}
-
-static prop_bt *find_prop_bt(prop_bt *bt, const char *name, uint8_t namelen,
-        bool alloc_if_needed)
-{
-    while (true) {
-        int ret;
-        if (!bt)
-            return bt;
-        ret = cmp_prop_name(name, namelen, bt->name, bt->namelen);
-
-        if (ret == 0) {
-            return bt;
-        } else if (ret < 0) {
-            if (bt->left) {
-                bt = to_prop_obj(bt->left);
-            } else {
-                if (!alloc_if_needed)
-                   return NULL;
-
-                bt = new_prop_bt(name, namelen, &bt->left);
-            }
-        } else {
-            if (bt->right) {
-                bt = to_prop_obj(bt->right);
-            } else {
-                if (!alloc_if_needed)
-                   return NULL;
-
-                bt = new_prop_bt(name, namelen, &bt->right);
-            }
-        }
-    }
-}
-
-static const prop_info *find_property(prop_bt *trie, const char *name,
-        uint8_t namelen, const char *value, uint8_t valuelen,
-        bool alloc_if_needed)
-{
-    const char *remaining_name = name;
-
-    if (!trie) return NULL;
-
-    while (true) {
-        char *sep = strchr(remaining_name, '.');
-        bool want_subtree = (sep != NULL);
-        uint8_t substr_size;
-
-        prop_bt *root;
-
-        if (want_subtree) {
-            substr_size = sep - remaining_name;
-        } else {
-            substr_size = strlen(remaining_name);
-        }
-
-        if (!substr_size)
-            return NULL;
-
-        if (trie->children) {
-            root = to_prop_obj(trie->children);
-        } else if (alloc_if_needed) {
-            root = new_prop_bt(remaining_name, substr_size, &trie->children);
-        } else {
-            root = NULL;
-        }
-
-        if (!root)
-            return NULL;
-
-        trie = find_prop_bt(root, remaining_name, substr_size, alloc_if_needed);
-        if (!trie)
-            return NULL;
-
-        if (!want_subtree)
-            break;
-
-        remaining_name = sep + 1;
-    }
-
-    if (trie->prop) {
-        return to_prop_obj(trie->prop);
-    } else if (alloc_if_needed) {
-        return new_prop_info(name, namelen, value, valuelen, &trie->prop);
-    } else {
-        return NULL;
-    }
-}
-
-const prop_info *__system_property_find(const char *name)
-{
-    if (__predict_false(compat_mode)) {
-        return __system_property_find_compat(name);
-    }
-    return find_property(root_node(), name, strlen(name), NULL, 0, false);
-}
-
-int __system_property_read(const prop_info *pi, char *name, char *value)
-{
-    unsigned serial, len;
-
-    if (__predict_false(compat_mode)) {
-        return __system_property_read_compat(pi, name, value);
-    }
-
-    for(;;) {
-        serial = pi->serial;
-        while(SERIAL_DIRTY(serial)) {
-            __futex_wait((volatile void *)&pi->serial, serial, NULL);
-            serial = pi->serial;
-        }
-        len = SERIAL_VALUE_LEN(serial);
-        memcpy(value, pi->value, len + 1);
-        ANDROID_MEMBAR_FULL();
-        if(serial == pi->serial) {
-            if(name != 0) {
-                strcpy(name, pi->name);
-            }
-            return len;
-        }
-    }
-}
-
-int __system_property_get(const char *name, char *value)
-{
-    const prop_info *pi = __system_property_find(name);
-
-    if(pi != 0) {
-        return __system_property_read(pi, 0, value);
-    } else {
-        value[0] = 0;
-        return 0;
-    }
-}
-
-
-static int send_prop_msg(prop_msg *msg)
-{
-    struct pollfd pollfds[1];
-    struct sockaddr_un addr;
-    socklen_t alen;
-    size_t namelen;
-    int s;
-    int r;
-    int result = -1;
-
-    s = socket(AF_LOCAL, SOCK_STREAM, 0);
-    if(s < 0) {
-        return result;
-    }
-
-    memset(&addr, 0, sizeof(addr));
-    namelen = strlen(property_service_socket);
-    strlcpy(addr.sun_path, property_service_socket, sizeof addr.sun_path);
-    addr.sun_family = AF_LOCAL;
-    alen = namelen + offsetof(struct sockaddr_un, sun_path) + 1;
-
-    if(TEMP_FAILURE_RETRY(connect(s, (struct sockaddr *) &addr, alen)) < 0) {
-        close(s);
-        return result;
-    }
-
-    r = TEMP_FAILURE_RETRY(send(s, msg, sizeof(prop_msg), 0));
-
-    if(r == sizeof(prop_msg)) {
-        // We successfully wrote to the property server but now we
-        // wait for the property server to finish its work.  It
-        // acknowledges its completion by closing the socket so we
-        // poll here (on nothing), waiting for the socket to close.
-        // If you 'adb shell setprop foo bar' you'll see the POLLHUP
-        // once the socket closes.  Out of paranoia we cap our poll
-        // at 250 ms.
-        pollfds[0].fd = s;
-        pollfds[0].events = 0;
-        r = TEMP_FAILURE_RETRY(poll(pollfds, 1, 250 /* ms */));
-        if (r == 1 && (pollfds[0].revents & POLLHUP) != 0) {
-            result = 0;
-        } else {
-            // Ignore the timeout and treat it like a success anyway.
-            // The init process is single-threaded and its property
-            // service is sometimes slow to respond (perhaps it's off
-            // starting a child process or something) and thus this
-            // times out and the caller thinks it failed, even though
-            // it's still getting around to it.  So we fake it here,
-            // mostly for ctl.* properties, but we do try and wait 250
-            // ms so callers who do read-after-write can reliably see
-            // what they've written.  Most of the time.
-            // TODO: fix the system properties design.
-            result = 0;
-        }
-    }
-
-    close(s);
-    return result;
-}
-
-int __system_property_set(const char *key, const char *value)
-{
-    int err;
-    prop_msg msg;
-
-    if(key == 0) return -1;
-    if(value == 0) value = "";
-    if(strlen(key) >= PROP_NAME_MAX) return -1;
-    if(strlen(value) >= PROP_VALUE_MAX) return -1;
-
-    memset(&msg, 0, sizeof msg);
-    msg.cmd = PROP_MSG_SETPROP;
-    strlcpy(msg.name, key, sizeof msg.name);
-    strlcpy(msg.value, value, sizeof msg.value);
-
-    err = send_prop_msg(&msg);
-    if(err < 0) {
-        return err;
-    }
-
-    return 0;
-}
-
-int __system_property_wait(const prop_info *pi)
-{
-    unsigned n;
-    if(pi == 0) {
-        prop_area *pa = __system_property_area__;
-        n = pa->serial;
-        do {
-            __futex_wait(&pa->serial, n, NULL);
-        } while(n == pa->serial);
-    } else {
-        n = pi->serial;
-        do {
-            __futex_wait((volatile void *)&pi->serial, n, NULL);
-        } while(n == pi->serial);
-    }
-    return 0;
-}
-
-int __system_property_update(prop_info *pi, const char *value, unsigned int len)
-{
-    prop_area *pa = __system_property_area__;
-
-    if (len >= PROP_VALUE_MAX)
-        return -1;
-
-    pi->serial = pi->serial | 1;
-    ANDROID_MEMBAR_FULL();
-    memcpy(pi->value, value, len + 1);
-    ANDROID_MEMBAR_FULL();
-    pi->serial = (len << 24) | ((pi->serial + 1) & 0xffffff);
-    __futex_wake(&pi->serial, INT32_MAX);
-
-    pa->serial++;
-    __futex_wake(&pa->serial, INT32_MAX);
-
-    return 0;
-}
-
-int __system_property_add(const char *name, unsigned int namelen,
-            const char *value, unsigned int valuelen)
-{
-    prop_area *pa = __system_property_area__;
-    const prop_info *pi;
-
-    if (namelen >= PROP_NAME_MAX)
-        return -1;
-    if (valuelen >= PROP_VALUE_MAX)
-        return -1;
-    if (namelen < 1)
-        return -1;
-
-    pi = find_property(root_node(), name, namelen, value, valuelen, true);
-    if (!pi)
-        return -1;
-
-    pa->serial++;
-    __futex_wake(&pa->serial, INT32_MAX);
-    return 0;
-}
-
-unsigned int __system_property_serial(const prop_info *pi)
-{
-    return pi->serial;
-}
-
-unsigned int __system_property_wait_any(unsigned int serial)
-{
-    prop_area *pa = __system_property_area__;
-
-    do {
-        __futex_wait(&pa->serial, serial, NULL);
-    } while(pa->serial == serial);
-
-    return pa->serial;
-}
-
-struct find_nth_cookie {
-    unsigned count;
-    unsigned n;
-    const prop_info *pi;
-};
-
-static void find_nth_fn(const prop_info *pi, void *ptr)
-{
-    struct find_nth_cookie *cookie = ptr;
-
-    if (cookie->n == cookie->count)
-        cookie->pi = pi;
-
-    cookie->count++;
-}
-
-const prop_info *__system_property_find_nth(unsigned n)
-{
-    struct find_nth_cookie cookie;
-    int err;
-
-    memset(&cookie, 0, sizeof(cookie));
-    cookie.n = n;
-
-    err = __system_property_foreach(find_nth_fn, &cookie);
-    if (err < 0)
-        return NULL;
-
-    return cookie.pi;
-}
-
-static int foreach_property(prop_off_t off,
-        void (*propfn)(const prop_info *pi, void *cookie), void *cookie)
-{
-    prop_bt *trie = to_prop_obj(off);
-    if (!trie)
-        return -1;
-
-    if (trie->left) {
-        int err = foreach_property(trie->left, propfn, cookie);
-        if (err < 0)
-            return -1;
-    }
-    if (trie->prop) {
-        prop_info *info = to_prop_obj(trie->prop);
-        if (!info)
-            return -1;
-        propfn(info, cookie);
-    }
-    if (trie->children) {
-        int err = foreach_property(trie->children, propfn, cookie);
-        if (err < 0)
-            return -1;
-    }
-    if (trie->right) {
-        int err = foreach_property(trie->right, propfn, cookie);
-        if (err < 0)
-            return -1;
-    }
-
-    return 0;
-}
-
-int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie),
-        void *cookie)
-{
-    if (__predict_false(compat_mode)) {
-        return __system_property_foreach_compat(propfn, cookie);
-	}
-    return foreach_property(0, propfn, cookie);
-}
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
new file mode 100644
index 0000000..a564c39
--- /dev/null
+++ b/libc/bionic/system_properties.cpp
@@ -0,0 +1,737 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <new>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stddef.h>
+#include <errno.h>
+#include <poll.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <sys/mman.h>
+
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <unistd.h>
+
+#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
+#include <sys/_system_properties.h>
+#include <sys/system_properties.h>
+
+#include "private/bionic_atomic_inline.h"
+#include "private/bionic_futex.h"
+#include "private/bionic_macros.h"
+
+static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
+
+
+/*
+ * Properties are stored in a hybrid trie/binary tree structure.
+ * Each property's name is delimited at '.' characters, and the tokens are put
+ * into a trie structure.  Siblings at each level of the trie are stored in a
+ * binary tree.  For instance, "ro.secure"="1" could be stored as follows:
+ *
+ * +-----+   children    +----+   children    +--------+
+ * |     |-------------->| ro |-------------->| secure |
+ * +-----+               +----+               +--------+
+ *                       /    \                /   |
+ *                 left /      \ right   left /    |  prop   +===========+
+ *                     v        v            v     +-------->| ro.secure |
+ *                  +-----+   +-----+     +-----+            +-----------+
+ *                  | net |   | sys |     | com |            |     1     |
+ *                  +-----+   +-----+     +-----+            +===========+
+ */
+
+// Represents a node in the trie.
+struct prop_bt {
+    uint8_t namelen;
+    uint8_t reserved[3];
+
+    volatile uint32_t prop;
+
+    volatile uint32_t left;
+    volatile uint32_t right;
+
+    volatile uint32_t children;
+
+    char name[0];
+
+    prop_bt(const char *name, const uint8_t name_length) {
+        this->namelen = name_length;
+        memcpy(this->name, name, name_length);
+        this->name[name_length] = '\0';
+        ANDROID_MEMBAR_FULL();
+    }
+
+private:
+    DISALLOW_COPY_AND_ASSIGN(prop_bt);
+};
+
+struct prop_area {
+    uint32_t bytes_used;
+    volatile uint32_t serial;
+    uint32_t magic;
+    uint32_t version;
+    uint32_t reserved[28];
+    char data[0];
+
+    prop_area(const uint32_t magic, const uint32_t version) :
+        serial(0), magic(magic), version(version) {
+        memset(reserved, 0, sizeof(reserved));
+        // Allocate enough space for the root node.
+        bytes_used = sizeof(prop_bt);
+    }
+
+private:
+    DISALLOW_COPY_AND_ASSIGN(prop_area);
+};
+
+struct prop_info {
+    volatile uint32_t serial;
+    char value[PROP_VALUE_MAX];
+    char name[0];
+
+    prop_info(const char *name, const uint8_t namelen, const char *value,
+              const uint8_t valuelen) {
+        memcpy(this->name, name, namelen);
+        this->name[namelen] = '\0';
+        this->serial = (valuelen << 24);
+        memcpy(this->value, value, valuelen);
+        this->value[valuelen] = '\0';
+        ANDROID_MEMBAR_FULL();
+    }
+private:
+    DISALLOW_COPY_AND_ASSIGN(prop_info);
+};
+
+struct find_nth_cookie {
+    uint32_t count;
+    const uint32_t n;
+    const prop_info *pi;
+
+    find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
+    }
+};
+
+static char property_filename[PATH_MAX] = PROP_FILENAME;
+static bool compat_mode = false;
+static size_t pa_data_size;
+static size_t pa_size;
+
+// NOTE: This isn't static because system_properties_compat.c
+// requires it.
+prop_area *__system_property_area__ = NULL;
+
+static int get_fd_from_env(void)
+{
+    // This environment variable consistes of two decimal integer
+    // values separated by a ",". The first value is a file descriptor
+    // and the second is the size of the system properties area. The
+    // size is currently unused.
+    char *env = getenv("ANDROID_PROPERTY_WORKSPACE");
+
+    if (!env) {
+        return -1;
+    }
+
+    return atoi(env);
+}
+
+static int map_prop_area_rw()
+{
+    /* dev is a tmpfs that we can use to carve a shared workspace
+     * out of, so let's do that...
+     */
+    const int fd = open(property_filename,
+                        O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC | O_EXCL, 0444);
+
+    if (fd < 0) {
+        if (errno == EACCES) {
+            /* for consistency with the case where the process has already
+             * mapped the page in and segfaults when trying to write to it
+             */
+            abort();
+        }
+        return -1;
+    }
+
+    // TODO: Is this really required ? Does android run on any kernels that
+    // don't support O_CLOEXEC ?
+    const int ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
+    if (ret < 0) {
+        close(fd);
+        return -1;
+    }
+
+    if (ftruncate(fd, PA_SIZE) < 0) {
+        close(fd);
+        return -1;
+    }
+
+    pa_size = PA_SIZE;
+    pa_data_size = pa_size - sizeof(prop_area);
+    compat_mode = false;
+
+    void *const memory_area = mmap(NULL, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    if (memory_area == MAP_FAILED) {
+        close(fd);
+        return -1;
+    }
+
+    prop_area *pa = new(memory_area) prop_area(PROP_AREA_MAGIC, PROP_AREA_VERSION);
+
+    /* plug into the lib property services */
+    __system_property_area__ = pa;
+
+    close(fd);
+    return 0;
+}
+
+static int map_fd_ro(const int fd) {
+    struct stat fd_stat;
+    if (fstat(fd, &fd_stat) < 0) {
+        return -1;
+    }
+
+    if ((fd_stat.st_uid != 0)
+            || (fd_stat.st_gid != 0)
+            || ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0)
+            || (fd_stat.st_size < static_cast<off_t>(sizeof(prop_area))) ) {
+        return -1;
+    }
+
+    pa_size = fd_stat.st_size;
+    pa_data_size = pa_size - sizeof(prop_area);
+
+    void* const map_result = mmap(NULL, pa_size, PROT_READ, MAP_SHARED, fd, 0);
+    if (map_result == MAP_FAILED) {
+        return -1;
+    }
+
+    prop_area* pa = reinterpret_cast<prop_area*>(map_result);
+    if ((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION &&
+                pa->version != PROP_AREA_VERSION_COMPAT)) {
+        munmap(pa, pa_size);
+        return -1;
+    }
+
+    if (pa->version == PROP_AREA_VERSION_COMPAT) {
+        compat_mode = true;
+    }
+
+    __system_property_area__ = pa;
+    return 0;
+}
+
+static int map_prop_area()
+{
+    int fd(open(property_filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
+    if (fd >= 0) {
+        /* For old kernels that don't support O_CLOEXEC */
+        const int ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
+        if (ret < 0) {
+            close(fd);
+            return -1;
+        }
+    }
+
+    bool close_fd = true;
+    if ((fd < 0) && (errno == ENOENT)) {
+        /*
+         * For backwards compatibility, if the file doesn't
+         * exist, we use the environment to get the file descriptor.
+         * For security reasons, we only use this backup if the kernel
+         * returns ENOENT. We don't want to use the backup if the kernel
+         * returns other errors such as ENOMEM or ENFILE, since it
+         * might be possible for an external program to trigger this
+         * condition.
+         */
+        fd = get_fd_from_env();
+        close_fd = false;
+    }
+
+    if (fd < 0) {
+        return -1;
+    }
+
+    const int map_result = map_fd_ro(fd);
+    if (close_fd) {
+        close(fd);
+    }
+
+    return map_result;
+}
+
+static void *allocate_obj(const size_t size, uint32_t *const off)
+{
+    prop_area *pa = __system_property_area__;
+    const size_t aligned = BIONIC_ALIGN(size, sizeof(uint32_t));
+    if (pa->bytes_used + aligned > pa_data_size) {
+        return NULL;
+    }
+
+    *off = pa->bytes_used;
+    pa->bytes_used += aligned;
+    return pa->data + *off;
+}
+
+static prop_bt *new_prop_bt(const char *name, uint8_t namelen, uint32_t *const off)
+{
+    uint32_t new_offset;
+    void *const offset = allocate_obj(sizeof(prop_bt) + namelen + 1, &new_offset);
+    if (offset) {
+        prop_bt* bt = new(offset) prop_bt(name, namelen);
+        *off = new_offset;
+        return bt;
+    }
+
+    return NULL;
+}
+
+static prop_info *new_prop_info(const char *name, uint8_t namelen,
+        const char *value, uint8_t valuelen, uint32_t *const off)
+{
+    uint32_t off_tmp;
+    void* const offset = allocate_obj(sizeof(prop_info) + namelen + 1, &off_tmp);
+    if (offset) {
+        prop_info* info = new(offset) prop_info(name, namelen, value, valuelen);
+        *off = off_tmp;
+        return info;
+    }
+
+    return NULL;
+}
+
+static void *to_prop_obj(const uint32_t off)
+{
+    if (off > pa_data_size)
+        return NULL;
+    if (!__system_property_area__)
+        return NULL;
+
+    return (__system_property_area__->data + off);
+}
+
+static prop_bt *root_node()
+{
+    return reinterpret_cast<prop_bt*>(to_prop_obj(0));
+}
+
+static int cmp_prop_name(const char *one, uint8_t one_len, const char *two,
+        uint8_t two_len)
+{
+    if (one_len < two_len)
+        return -1;
+    else if (one_len > two_len)
+        return 1;
+    else
+        return strncmp(one, two, one_len);
+}
+
+static prop_bt *find_prop_bt(prop_bt *const bt, const char *name,
+                             uint8_t namelen, bool alloc_if_needed)
+{
+
+    prop_bt* current = bt;
+    while (true) {
+        if (!current) {
+            return NULL;
+        }
+
+        const int ret = cmp_prop_name(name, namelen, current->name, current->namelen);
+        if (ret == 0) {
+            return current;
+        }
+
+        if (ret < 0) {
+            if (current->left) {
+                current = reinterpret_cast<prop_bt*>(to_prop_obj(current->left));
+            } else {
+                if (!alloc_if_needed) {
+                   return NULL;
+                }
+
+                // Note that there isn't a race condition here. "clients" never
+                // reach this code-path since It's only the (single threaded) server
+                // that allocates new nodes. Though "bt->left" is volatile, it can't
+                // have changed since the last value was last read.
+                uint32_t new_offset = 0;
+                prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
+                if (new_bt) {
+                    current->left = new_offset;
+                }
+                return new_bt;
+            }
+        } else {
+            if (current->right) {
+                current = reinterpret_cast<prop_bt*>(to_prop_obj(current->right));
+            } else {
+                if (!alloc_if_needed) {
+                   return NULL;
+                }
+
+                uint32_t new_offset;
+                prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
+                if (new_bt) {
+                    current->right = new_offset;
+                }
+                return new_bt;
+            }
+        }
+    }
+}
+
+static const prop_info *find_property(prop_bt *const trie, const char *name,
+        uint8_t namelen, const char *value, uint8_t valuelen,
+        bool alloc_if_needed)
+{
+    if (!trie) return NULL;
+
+    const char *remaining_name = name;
+    prop_bt* current = trie;
+    while (true) {
+        const char *sep = strchr(remaining_name, '.');
+        const bool want_subtree = (sep != NULL);
+        const uint8_t substr_size = (want_subtree) ?
+            sep - remaining_name : strlen(remaining_name);
+
+        if (!substr_size) {
+            return NULL;
+        }
+
+        prop_bt* root = NULL;
+        if (current->children) {
+            root = reinterpret_cast<prop_bt*>(to_prop_obj(current->children));
+        } else if (alloc_if_needed) {
+            uint32_t new_bt_offset;
+            root = new_prop_bt(remaining_name, substr_size, &new_bt_offset);
+            if (root) {
+                current->children = new_bt_offset;
+            }
+        }
+
+        if (!root) {
+            return NULL;
+        }
+
+        current = find_prop_bt(root, remaining_name, substr_size, alloc_if_needed);
+        if (!current) {
+            return NULL;
+        }
+
+        if (!want_subtree)
+            break;
+
+        remaining_name = sep + 1;
+    }
+
+    if (current->prop) {
+        return reinterpret_cast<prop_info*>(to_prop_obj(current->prop));
+    } else if (alloc_if_needed) {
+        uint32_t new_info_offset;
+        prop_info* new_info = new_prop_info(name, namelen, value, valuelen, &new_info_offset);
+        if (new_info) {
+            current->prop = new_info_offset;
+        }
+
+        return new_info;
+    } else {
+        return NULL;
+    }
+}
+
+static int send_prop_msg(const prop_msg *msg)
+{
+    const int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+    if (fd < 0) {
+        return -1;
+    }
+
+    const size_t namelen = strlen(property_service_socket);
+
+    sockaddr_un addr;
+    memset(&addr, 0, sizeof(addr));
+    strlcpy(addr.sun_path, property_service_socket, sizeof(addr.sun_path));
+    addr.sun_family = AF_LOCAL;
+    socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
+    if (TEMP_FAILURE_RETRY(connect(fd, reinterpret_cast<sockaddr*>(&addr), alen)) < 0) {
+        close(fd);
+        return -1;
+    }
+
+    const int num_bytes = TEMP_FAILURE_RETRY(send(fd, msg, sizeof(prop_msg), 0));
+
+    int result = -1;
+    if (num_bytes == sizeof(prop_msg)) {
+        // We successfully wrote to the property server but now we
+        // wait for the property server to finish its work.  It
+        // acknowledges its completion by closing the socket so we
+        // poll here (on nothing), waiting for the socket to close.
+        // If you 'adb shell setprop foo bar' you'll see the POLLHUP
+        // once the socket closes.  Out of paranoia we cap our poll
+        // at 250 ms.
+        pollfd pollfds[1];
+        pollfds[0].fd = fd;
+        pollfds[0].events = 0;
+        const int poll_result = TEMP_FAILURE_RETRY(poll(pollfds, 1, 250 /* ms */));
+        if (poll_result == 1 && (pollfds[0].revents & POLLHUP) != 0) {
+            result = 0;
+        } else {
+            // Ignore the timeout and treat it like a success anyway.
+            // The init process is single-threaded and its property
+            // service is sometimes slow to respond (perhaps it's off
+            // starting a child process or something) and thus this
+            // times out and the caller thinks it failed, even though
+            // it's still getting around to it.  So we fake it here,
+            // mostly for ctl.* properties, but we do try and wait 250
+            // ms so callers who do read-after-write can reliably see
+            // what they've written.  Most of the time.
+            // TODO: fix the system properties design.
+            result = 0;
+        }
+    }
+
+    close(fd);
+    return result;
+}
+
+static void find_nth_fn(const prop_info *pi, void *ptr)
+{
+    find_nth_cookie *cookie = reinterpret_cast<find_nth_cookie*>(ptr);
+
+    if (cookie->n == cookie->count)
+        cookie->pi = pi;
+
+    cookie->count++;
+}
+
+static int foreach_property(const uint32_t off,
+        void (*propfn)(const prop_info *pi, void *cookie), void *cookie)
+{
+    prop_bt *trie = reinterpret_cast<prop_bt*>(to_prop_obj(off));
+    if (!trie)
+        return -1;
+
+    if (trie->left) {
+        const int err = foreach_property(trie->left, propfn, cookie);
+        if (err < 0)
+            return -1;
+    }
+    if (trie->prop) {
+        prop_info *info = reinterpret_cast<prop_info*>(to_prop_obj(trie->prop));
+        if (!info)
+            return -1;
+        propfn(info, cookie);
+    }
+    if (trie->children) {
+        const int err = foreach_property(trie->children, propfn, cookie);
+        if (err < 0)
+            return -1;
+    }
+    if (trie->right) {
+        const int err = foreach_property(trie->right, propfn, cookie);
+        if (err < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
+int __system_properties_init()
+{
+    return map_prop_area();
+}
+
+int __system_property_set_filename(const char *filename)
+{
+    size_t len = strlen(filename);
+    if (len >= sizeof(property_filename))
+        return -1;
+
+    strcpy(property_filename, filename);
+    return 0;
+}
+
+int __system_property_area_init()
+{
+    return map_prop_area_rw();
+}
+
+const prop_info *__system_property_find(const char *name)
+{
+    if (__predict_false(compat_mode)) {
+        return __system_property_find_compat(name);
+    }
+    return find_property(root_node(), name, strlen(name), NULL, 0, false);
+}
+
+int __system_property_read(const prop_info *pi, char *name, char *value)
+{
+    if (__predict_false(compat_mode)) {
+        return __system_property_read_compat(pi, name, value);
+    }
+
+    while (true) {
+        uint32_t serial = __system_property_serial(pi);
+        size_t len = SERIAL_VALUE_LEN(serial);
+        memcpy(value, pi->value, len + 1);
+        ANDROID_MEMBAR_FULL();
+        if (serial == pi->serial) {
+            if (name != 0) {
+                strcpy(name, pi->name);
+            }
+            return len;
+        }
+    }
+}
+
+int __system_property_get(const char *name, char *value)
+{
+    const prop_info *pi = __system_property_find(name);
+
+    if (pi != 0) {
+        return __system_property_read(pi, 0, value);
+    } else {
+        value[0] = 0;
+        return 0;
+    }
+}
+
+int __system_property_set(const char *key, const char *value)
+{
+    if (key == 0) return -1;
+    if (value == 0) value = "";
+    if (strlen(key) >= PROP_NAME_MAX) return -1;
+    if (strlen(value) >= PROP_VALUE_MAX) return -1;
+
+    prop_msg msg;
+    memset(&msg, 0, sizeof msg);
+    msg.cmd = PROP_MSG_SETPROP;
+    strlcpy(msg.name, key, sizeof msg.name);
+    strlcpy(msg.value, value, sizeof msg.value);
+
+    const int err = send_prop_msg(&msg);
+    if (err < 0) {
+        return err;
+    }
+
+    return 0;
+}
+
+int __system_property_update(prop_info *pi, const char *value, unsigned int len)
+{
+    prop_area *pa = __system_property_area__;
+
+    if (len >= PROP_VALUE_MAX)
+        return -1;
+
+    pi->serial = pi->serial | 1;
+    ANDROID_MEMBAR_FULL();
+    memcpy(pi->value, value, len + 1);
+    ANDROID_MEMBAR_FULL();
+    pi->serial = (len << 24) | ((pi->serial + 1) & 0xffffff);
+    __futex_wake(&pi->serial, INT32_MAX);
+
+    pa->serial++;
+    __futex_wake(&pa->serial, INT32_MAX);
+
+    return 0;
+}
+
+int __system_property_add(const char *name, unsigned int namelen,
+            const char *value, unsigned int valuelen)
+{
+    prop_area *pa = __system_property_area__;
+    const prop_info *pi;
+
+    if (namelen >= PROP_NAME_MAX)
+        return -1;
+    if (valuelen >= PROP_VALUE_MAX)
+        return -1;
+    if (namelen < 1)
+        return -1;
+
+    pi = find_property(root_node(), name, namelen, value, valuelen, true);
+    if (!pi)
+        return -1;
+
+    pa->serial++;
+    __futex_wake(&pa->serial, INT32_MAX);
+    return 0;
+}
+
+unsigned int __system_property_serial(const prop_info *pi)
+{
+    uint32_t serial = pi->serial;
+    while (SERIAL_DIRTY(serial)) {
+        __futex_wait(const_cast<volatile uint32_t*>(&pi->serial), serial, NULL);
+        serial = pi->serial;
+    }
+    return serial;
+}
+
+unsigned int __system_property_wait_any(unsigned int serial)
+{
+    prop_area *pa = __system_property_area__;
+
+    do {
+        __futex_wait(&pa->serial, serial, NULL);
+    } while (pa->serial == serial);
+
+    return pa->serial;
+}
+
+const prop_info *__system_property_find_nth(unsigned n)
+{
+    find_nth_cookie cookie(n);
+
+    const int err = __system_property_foreach(find_nth_fn, &cookie);
+    if (err < 0) {
+        return NULL;
+    }
+
+    return cookie.pi;
+}
+
+int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie),
+        void *cookie)
+{
+    if (__predict_false(compat_mode)) {
+        return __system_property_foreach_compat(propfn, cookie);
+    }
+
+    return foreach_property(0, propfn, cookie);
+}
diff --git a/libc/bionic/system_properties_compat.c b/libc/bionic/system_properties_compat.c
index b4c2494..6aeaa0c 100644
--- a/libc/bionic/system_properties_compat.c
+++ b/libc/bionic/system_properties_compat.c
@@ -35,7 +35,8 @@
  */
 
 #include <string.h>
-#include <sys/atomics.h>
+
+#include "private/bionic_futex.h"
 
 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
 #include <sys/_system_properties.h>
@@ -67,7 +68,7 @@
 
 extern prop_area *__system_property_area__;
 
-const prop_info *__system_property_find_compat(const char *name)
+__LIBC_HIDDEN__ const prop_info *__system_property_find_compat(const char *name)
 {
     prop_area_compat *pa = (prop_area_compat *)__system_property_area__;
     unsigned count = pa->count;
@@ -93,7 +94,7 @@
     return 0;
 }
 
-int __system_property_read_compat(const prop_info *_pi, char *name, char *value)
+__LIBC_HIDDEN__ int __system_property_read_compat(const prop_info *_pi, char *name, char *value)
 {
     unsigned serial, len;
     const prop_info_compat *pi = (const prop_info_compat *)_pi;
@@ -115,7 +116,7 @@
     }
 }
 
-int __system_property_foreach_compat(
+__LIBC_HIDDEN__ int __system_property_foreach_compat(
         void (*propfn)(const prop_info *pi, void *cookie),
         void *cookie)
 {
diff --git a/libc/bionic/tcgetpgrp.c b/libc/bionic/tcgetpgrp.c
deleted file mode 100644
index ebff66a..0000000
--- a/libc/bionic/tcgetpgrp.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-** Copyright 2006, The Android Open Source Project
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**     * Redistributions of source code must retain the above copyright
-**       notice, this list of conditions and the following disclaimer.
-**     * Redistributions in binary form must reproduce the above copyright
-**       notice, this list of conditions and the following disclaimer in the
-**       documentation and/or other materials provided with the distribution.
-**     * Neither the name of Google Inc. nor the names of its contributors may
-**       be used to endorse or promote products derived from this software
-**       without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
-** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include <unistd.h>
-#include <termios.h>
-
-pid_t tcgetpgrp(int fd)
-{
-    pid_t _pid;
-    return ioctl(fd, TIOCGPGRP, &_pid) ? (pid_t)-1 : _pid;
-}
diff --git a/libc/bionic/tcsetpgrp.c b/libc/bionic/tcsetpgrp.c
deleted file mode 100644
index 06d9cd0..0000000
--- a/libc/bionic/tcsetpgrp.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-** Copyright 2006, The Android Open Source Project
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**     * Redistributions of source code must retain the above copyright
-**       notice, this list of conditions and the following disclaimer.
-**     * Redistributions in binary form must reproduce the above copyright
-**       notice, this list of conditions and the following disclaimer in the
-**       documentation and/or other materials provided with the distribution.
-**     * Neither the name of Google Inc. nor the names of its contributors may
-**       be used to endorse or promote products derived from this software
-**       without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
-** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include <unistd.h>
-#include <termios.h>
-
-int tcsetpgrp(int fd, pid_t _pid)
-{
-    return ioctl(fd, TIOCSPGRP, &_pid);
-}
diff --git a/libc/bionic/tdestroy.cpp b/libc/bionic/tdestroy.cpp
index decde4d..49614b8 100644
--- a/libc/bionic/tdestroy.cpp
+++ b/libc/bionic/tdestroy.cpp
@@ -19,7 +19,7 @@
 #include <stdlib.h>
 
 // Destroy a tree and free all allocated resources.
-// This is a GNU extension, not available from NetBSD.
+// This is a GNU extension, not available from BSD.
 void tdestroy(void* root, void (*destroy_func)(void*)) {
   node_t* root_node = (node_t*) root;
   if (root_node == NULL) {
diff --git a/libc/bionic/termios.cpp b/libc/bionic/termios.cpp
new file mode 100644
index 0000000..082dcdc
--- /dev/null
+++ b/libc/bionic/termios.cpp
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <termios.h>
+#include <unistd.h>
+
+static speed_t cfgetspeed(const termios* s) {
+  return (s->c_cflag & CBAUD);
+}
+
+speed_t cfgetispeed(const termios* s) {
+  return cfgetspeed(s);
+}
+
+speed_t cfgetospeed(const termios* s) {
+  return cfgetspeed(s);
+}
+
+void cfmakeraw(termios* s) {
+  s->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
+  s->c_oflag &= ~OPOST;
+  s->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+  s->c_cflag &= ~(CSIZE|PARENB);
+  s->c_cflag |= CS8;
+}
+
+int cfsetispeed(termios* s, speed_t speed) {
+  return cfsetspeed(s, speed);
+}
+
+int cfsetospeed(termios* s, speed_t speed) {
+  return cfsetspeed(s, speed);
+}
+
+int cfsetspeed(termios* s, speed_t speed) {
+  // TODO: check 'speed' is valid.
+  s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
+  return 0;
+}
+
+int tcdrain(int fd) {
+  // A non-zero argument to TCSBRK means "don't send a break".
+  // The drain is a side-effect of the ioctl!
+  return ioctl(fd, TCSBRK, static_cast<unsigned long>(1));
+}
+
+int tcflow(int fd, int action) {
+  return ioctl(fd, TCXONC, static_cast<unsigned long>(action));
+}
+
+int tcflush(int fd, int queue) {
+  return ioctl(fd, TCFLSH, static_cast<unsigned long>(queue));
+}
+
+int tcgetattr(int fd, termios* s) {
+  return ioctl(fd, TCGETS, s);
+}
+
+pid_t tcgetsid(int fd) {
+  pid_t sid;
+  if (ioctl(fd, TIOCGSID, &sid) == -1) {
+    return -1;
+  }
+  return sid;
+}
+
+int tcsendbreak(int fd, int duration) {
+  return ioctl(fd, TCSBRKP, static_cast<unsigned long>(duration));
+}
+
+int tcsetattr(int fd, int optional_actions, const termios* s) {
+  int cmd;
+  switch (optional_actions) {
+    case TCSANOW: cmd = TCSETS; break;
+    case TCSADRAIN: cmd = TCSETSW; break;
+    case TCSAFLUSH: cmd = TCSETSF; break;
+    default: errno = EINVAL; return -1;
+  }
+  return ioctl(fd, cmd, s);
+}
+
+pid_t tcgetpgrp(int fd) {
+  pid_t pid;
+  if (ioctl(fd, TIOCGPGRP, &pid) == -1) {
+    return -1;
+  }
+  return pid;
+}
+
+int tcsetpgrp(int fd, pid_t pid) {
+  return ioctl(fd, TIOCSPGRP, &pid);
+}
diff --git a/libc/bionic/thread_atexit.cpp b/libc/bionic/thread_atexit.cpp
deleted file mode 100644
index cad65d3..0000000
--- a/libc/bionic/thread_atexit.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* some simple glue used to make the BSD atexit code happy */
-
-#include <pthread.h>
-
-static pthread_mutex_t gAtExitLock = PTHREAD_MUTEX_INITIALIZER;
-
-__BEGIN_DECLS
-__LIBC_HIDDEN__ void _thread_atexit_lock();
-__LIBC_HIDDEN__ void _thread_atexit_unlock();
-__END_DECLS
-
-void _thread_atexit_lock() {
-  pthread_mutex_lock(&gAtExitLock);
-}
-
-void _thread_atexit_unlock() {
-  pthread_mutex_unlock(&gAtExitLock);
-}
diff --git a/libc/bionic/thread_private.cpp b/libc/bionic/thread_private.cpp
new file mode 100644
index 0000000..1c04019
--- /dev/null
+++ b/libc/bionic/thread_private.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <pthread.h>
+#include "private/thread_private.h"
+
+// Some simple glue used to make BSD code thread-safe.
+
+static pthread_mutex_t g_atexit_lock = PTHREAD_MUTEX_INITIALIZER;
+
+void _thread_atexit_lock() {
+  pthread_mutex_lock(&g_atexit_lock);
+}
+
+void _thread_atexit_unlock() {
+  pthread_mutex_unlock(&g_atexit_lock);
+}
+
+static pthread_mutex_t g_arc4_lock = PTHREAD_MUTEX_INITIALIZER;
+
+void _thread_arc4_lock() {
+  pthread_mutex_lock(&g_arc4_lock);
+}
+
+void _thread_arc4_unlock() {
+  pthread_mutex_unlock(&g_arc4_lock);
+}
diff --git a/libc/bionic/time64.c b/libc/bionic/time64.c
index 9aa5d4f..95dfab5 100644
--- a/libc/bionic/time64.c
+++ b/libc/bionic/time64.c
@@ -28,6 +28,10 @@
 
 /* See http://code.google.com/p/y2038 for this code's origin */
 
+#if defined(__LP64__)
+#error This cruft should be LP32 only!
+#endif
+
 /*
 
 Programmers who have available to them 64-bit time values as a 'long
@@ -133,17 +137,6 @@
     1992, 1993, 1994, 1995,
 };
 
-/* This isn't used, but it's handy to look at */
-static const int dow_year_start[SOLAR_CYCLE_LENGTH] = {
-    5, 0, 1, 2,     /* 0       2016 - 2019 */
-    3, 5, 6, 0,     /* 4  */
-    1, 3, 4, 5,     /* 8       1996 - 1998, 1971*/
-    6, 1, 2, 3,     /* 12      1972 - 1975 */
-    4, 6, 0, 1,     /* 16 */
-    2, 4, 5, 6,     /* 20      2036, 2037, 2010, 2011 */
-    0, 2, 3, 4      /* 24      2012, 2013, 2014, 2015 */
-};
-
 /* Let's assume people are going to be looking for dates in the future.
    Let's provide some cheats so you can skip ahead.
    This has a 4x speed boost when near 2008.
@@ -248,6 +241,7 @@
 }
 
 
+#if !defined(NDEBUG)
 static int check_tm(struct TM *tm)
 {
     /* Don't forget leap seconds */
@@ -268,7 +262,7 @@
 
     assert(tm->tm_wday >= 0);
     assert(tm->tm_wday <= 6);
-   
+
     assert(tm->tm_yday >= 0);
     assert(tm->tm_yday <= length_of_year[IS_LEAP(tm->tm_year)]);
 
@@ -279,6 +273,7 @@
 
     return 1;
 }
+#endif
 
 
 /* The exceptional centuries without leap years cause the cycle to
diff --git a/libc/bionic/timer.cpp b/libc/bionic/timer.cpp
deleted file mode 100644
index ed73821..0000000
--- a/libc/bionic/timer.cpp
+++ /dev/null
@@ -1,636 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "pthread_internal.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-extern int __pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const timespec*, clockid_t);
-extern int __pthread_cond_timedwait_relative(pthread_cond_t*, pthread_mutex_t*, const timespec*);
-
-// Normal (i.e. non-SIGEV_THREAD) timers are created directly by the kernel
-// and are passed as is to/from the caller.
-//
-// This file also implements the support required for SIGEV_THREAD ("POSIX interval")
-// timers. See the following pages for additional details:
-//
-// www.opengroup.org/onlinepubs/000095399/functions/timer_create.html
-// www.opengroup.org/onlinepubs/000095399/functions/timer_settime.html
-// www.opengroup.org/onlinepubs/000095399/functions/xsh_chap02_04.html#tag_02_04_01
-//
-// The Linux kernel doesn't support these, so we need to implement them in the
-// C library. We use a very basic scheme where each timer is associated to a
-// thread that will loop, waiting for timeouts or messages from the program
-// corresponding to calls to timer_settime() and timer_delete().
-//
-// Note also an important thing: Posix mandates that in the case of fork(),
-// the timers of the child process should be disarmed, but not deleted.
-// this is implemented by providing a fork() wrapper (see bionic/fork.c) which
-// stops all timers before the fork, and only re-start them in case of error
-// or in the parent process.
-//
-// This stop/start is implemented by the __timer_table_start_stop() function
-// below.
-//
-// A SIGEV_THREAD timer ID will always have its TIMER_ID_WRAP_BIT
-// set to 1. In this implementation, this is always bit 31, which is
-// guaranteed to never be used by kernel-provided timer ids
-//
-// (See code in <kernel>/lib/idr.c, used to manage IDs, to see why.)
-
-#define  TIMER_ID_WRAP_BIT        0x80000000
-#define  TIMER_ID_WRAP(id)        ((timer_t)((id) |  TIMER_ID_WRAP_BIT))
-#define  TIMER_ID_UNWRAP(id)      ((timer_t)((id) & ~TIMER_ID_WRAP_BIT))
-#define  TIMER_ID_IS_WRAPPED(id)  (((id) & TIMER_ID_WRAP_BIT) != 0)
-
-/* this value is used internally to indicate a 'free' or 'zombie'
- * thr_timer structure. Here, 'zombie' means that timer_delete()
- * has been called, but that the corresponding thread hasn't
- * exited yet.
- */
-#define  TIMER_ID_NONE            ((timer_t)0xffffffff)
-
-/* True iff a timer id is valid */
-#define  TIMER_ID_IS_VALID(id)    ((id) != TIMER_ID_NONE)
-
-/* the maximum value of overrun counters */
-#define  DELAYTIMER_MAX    0x7fffffff
-
-typedef struct thr_timer          thr_timer_t;
-typedef struct thr_timer_table    thr_timer_table_t;
-
-/* The Posix spec says the function receives an unsigned parameter, but
- * it's really a 'union sigval' a.k.a. sigval_t */
-typedef void (*thr_timer_func_t)( sigval_t );
-
-struct thr_timer {
-    thr_timer_t*       next;     /* next in free list */
-    timer_t            id;       /* TIMER_ID_NONE iff free or dying */
-    clockid_t          clock;
-    pthread_t          thread;
-    pthread_attr_t     attributes;
-    thr_timer_func_t   callback;
-    sigval_t           value;
-
-    /* the following are used to communicate between
-     * the timer thread and the timer_XXX() functions
-     */
-    pthread_mutex_t           mutex;     /* lock */
-    pthread_cond_t            cond;      /* signal a state change to thread */
-    int volatile              done;      /* set by timer_delete */
-    int volatile              stopped;   /* set by _start_stop() */
-    timespec volatile  expires;   /* next expiration time, or 0 */
-    timespec volatile  period;    /* reload value, or 0 */
-    int volatile              overruns;  /* current number of overruns */
-};
-
-#define  MAX_THREAD_TIMERS  32
-
-struct thr_timer_table {
-    pthread_mutex_t  lock;
-    thr_timer_t*     free_timer;
-    thr_timer_t      timers[ MAX_THREAD_TIMERS ];
-};
-
-/** GLOBAL TABLE OF THREAD TIMERS
- **/
-
-static void
-thr_timer_table_init( thr_timer_table_t*  t )
-{
-    int  nn;
-
-    memset(t, 0, sizeof *t);
-    pthread_mutex_init( &t->lock, NULL );
-
-    for (nn = 0; nn < MAX_THREAD_TIMERS; nn++)
-        t->timers[nn].id = TIMER_ID_NONE;
-
-    t->free_timer = &t->timers[0];
-    for (nn = 1; nn < MAX_THREAD_TIMERS; nn++)
-        t->timers[nn-1].next = &t->timers[nn];
-}
-
-
-static thr_timer_t*
-thr_timer_table_alloc( thr_timer_table_t*  t )
-{
-    thr_timer_t*  timer;
-
-    if (t == NULL)
-        return NULL;
-
-    pthread_mutex_lock(&t->lock);
-    timer = t->free_timer;
-    if (timer != NULL) {
-        t->free_timer = timer->next;
-        timer->next   = NULL;
-        timer->id     = TIMER_ID_WRAP((timer - t->timers));
-    }
-    pthread_mutex_unlock(&t->lock);
-    return timer;
-}
-
-
-static void
-thr_timer_table_free( thr_timer_table_t*  t, thr_timer_t*  timer )
-{
-    pthread_mutex_lock( &t->lock );
-    timer->id     = TIMER_ID_NONE;
-    timer->thread = 0;
-    timer->next   = t->free_timer;
-    t->free_timer = timer;
-    pthread_mutex_unlock( &t->lock );
-}
-
-
-static void thr_timer_table_start_stop(thr_timer_table_t* t, int stop) {
-  if (t == NULL) {
-    return;
-  }
-
-  pthread_mutex_lock(&t->lock);
-  for (int nn = 0; nn < MAX_THREAD_TIMERS; ++nn) {
-    thr_timer_t*  timer  = &t->timers[nn];
-    if (TIMER_ID_IS_VALID(timer->id)) {
-      // Tell the thread to start/stop.
-      pthread_mutex_lock(&timer->mutex);
-      timer->stopped = stop;
-      pthread_cond_signal( &timer->cond );
-      pthread_mutex_unlock(&timer->mutex);
-    }
-  }
-  pthread_mutex_unlock(&t->lock);
-}
-
-
-/* convert a timer_id into the corresponding thr_timer_t* pointer
- * returns NULL if the id is not wrapped or is invalid/free
- */
-static thr_timer_t*
-thr_timer_table_from_id( thr_timer_table_t*  t,
-                         timer_t             id,
-                         int                 remove )
-{
-    unsigned      index;
-    thr_timer_t*  timer;
-
-    if (t == NULL || !TIMER_ID_IS_WRAPPED(id))
-        return NULL;
-
-    index = (unsigned) TIMER_ID_UNWRAP(id);
-    if (index >= MAX_THREAD_TIMERS)
-        return NULL;
-
-    pthread_mutex_lock(&t->lock);
-
-    timer = &t->timers[index];
-
-    if (!TIMER_ID_IS_VALID(timer->id)) {
-        timer = NULL;
-    } else {
-        /* if we're removing this timer, clear the id
-         * right now to prevent another thread to
-         * use the same id after the unlock */
-        if (remove)
-            timer->id = TIMER_ID_NONE;
-    }
-    pthread_mutex_unlock(&t->lock);
-
-    return timer;
-}
-
-/* the static timer table - we only create it if the process
- * really wants to use SIGEV_THREAD timers, which should be
- * pretty infrequent
- */
-
-static pthread_once_t __timer_table_once = PTHREAD_ONCE_INIT;
-static thr_timer_table_t* __timer_table;
-
-static void __timer_table_init(void) {
-  __timer_table = reinterpret_cast<thr_timer_table_t*>(calloc(1, sizeof(*__timer_table)));
-  if (__timer_table != NULL) {
-    thr_timer_table_init(__timer_table);
-  }
-}
-
-static thr_timer_table_t* __timer_table_get(void) {
-  pthread_once(&__timer_table_once, __timer_table_init);
-  return __timer_table;
-}
-
-/** POSIX THREAD TIMERS CLEANUP ON FORK
- **
- ** this should be called from the 'fork()' wrapper to stop/start
- ** all active thread timers. this is used to implement a Posix
- ** requirements: the timers of fork child processes must be
- ** disarmed but not deleted.
- **/
-void __timer_table_start_stop(int stop) {
-  // We access __timer_table directly so we don't create it if it doesn't yet exist.
-  thr_timer_table_start_stop(__timer_table, stop);
-}
-
-static thr_timer_t*
-thr_timer_from_id( timer_t   id )
-{
-    thr_timer_table_t*  table = __timer_table_get();
-    thr_timer_t*        timer = thr_timer_table_from_id( table, id, 0 );
-
-    return timer;
-}
-
-
-static __inline__ void
-thr_timer_lock( thr_timer_t*  t )
-{
-    pthread_mutex_lock(&t->mutex);
-}
-
-static __inline__ void
-thr_timer_unlock( thr_timer_t*  t )
-{
-    pthread_mutex_unlock(&t->mutex);
-}
-
-
-static __inline__ void timespec_add(timespec* a, const timespec* b) {
-  a->tv_sec  += b->tv_sec;
-  a->tv_nsec += b->tv_nsec;
-  if (a->tv_nsec >= 1000000000) {
-    a->tv_nsec -= 1000000000;
-    a->tv_sec  += 1;
-  }
-}
-
-static __inline__ void timespec_sub(timespec* a, const timespec* b) {
-  a->tv_sec  -= b->tv_sec;
-  a->tv_nsec -= b->tv_nsec;
-  if (a->tv_nsec < 0) {
-    a->tv_nsec += 1000000000;
-    a->tv_sec  -= 1;
-  }
-}
-
-static __inline__ void timespec_zero(timespec* a) {
-  a->tv_sec = a->tv_nsec = 0;
-}
-
-static __inline__ int timespec_is_zero(const timespec* a) {
-  return (a->tv_sec == 0 && a->tv_nsec == 0);
-}
-
-static __inline__ int timespec_cmp(const timespec* a, const timespec* b) {
-  if (a->tv_sec  < b->tv_sec)  return -1;
-  if (a->tv_sec  > b->tv_sec)  return +1;
-  if (a->tv_nsec < b->tv_nsec) return -1;
-  if (a->tv_nsec > b->tv_nsec) return +1;
-  return 0;
-}
-
-static __inline__ int timespec_cmp0(const timespec* a) {
-  if (a->tv_sec < 0) return -1;
-  if (a->tv_sec > 0) return +1;
-  if (a->tv_nsec < 0) return -1;
-  if (a->tv_nsec > 0) return +1;
-  return 0;
-}
-
-/** POSIX TIMERS APIs */
-
-extern "C" int __timer_create(clockid_t, sigevent*, timer_t*);
-extern "C" int __timer_delete(timer_t);
-extern "C" int __timer_gettime(timer_t, itimerspec*);
-extern "C" int __timer_settime(timer_t, int, const itimerspec*, itimerspec*);
-extern "C" int __timer_getoverrun(timer_t);
-
-static void* timer_thread_start(void*);
-
-int timer_create(clockid_t clock_id, sigevent* evp, timer_t* timer_id) {
-  // If not a SIGEV_THREAD timer, the kernel can handle it without our help.
-  if (__predict_true(evp == NULL || evp->sigev_notify != SIGEV_THREAD)) {
-    return __timer_create(clock_id, evp, timer_id);
-  }
-
-  // Check arguments.
-  if (evp->sigev_notify_function == NULL) {
-    errno = EINVAL;
-    return -1;
-  }
-
-  // Check that the clock id is supported by the kernel.
-  timespec dummy;
-  if (clock_gettime(clock_id, &dummy) < 0 && errno == EINVAL) {
-    return -1;
-  }
-
-  // Create a new timer and its thread.
-  // TODO: use a single global thread for all timers.
-  thr_timer_table_t* table = __timer_table_get();
-  thr_timer_t* timer = thr_timer_table_alloc(table);
-  if (timer == NULL) {
-    errno = ENOMEM;
-    return -1;
-  }
-
-  // Copy the thread attributes.
-  if (evp->sigev_notify_attributes == NULL) {
-    pthread_attr_init(&timer->attributes);
-  } else {
-    timer->attributes = ((pthread_attr_t*) evp->sigev_notify_attributes)[0];
-  }
-
-  // Posix says that the default is PTHREAD_CREATE_DETACHED and
-  // that PTHREAD_CREATE_JOINABLE has undefined behavior.
-  // So simply always use DETACHED :-)
-  pthread_attr_setdetachstate(&timer->attributes, PTHREAD_CREATE_DETACHED);
-
-  timer->callback = evp->sigev_notify_function;
-  timer->value = evp->sigev_value;
-  timer->clock = clock_id;
-
-  pthread_mutex_init(&timer->mutex, NULL);
-  pthread_cond_init(&timer->cond, NULL);
-
-  timer->done = 0;
-  timer->stopped = 0;
-  timer->expires.tv_sec = timer->expires.tv_nsec = 0;
-  timer->period.tv_sec = timer->period.tv_nsec  = 0;
-  timer->overruns = 0;
-
-  // Create the thread.
-  int rc = pthread_create(&timer->thread, &timer->attributes, timer_thread_start, timer);
-  if (rc != 0) {
-    thr_timer_table_free(table, timer);
-    errno = rc;
-    return -1;
-  }
-
-  *timer_id = timer->id;
-  return 0;
-}
-
-
-int
-timer_delete( timer_t  id )
-{
-    if ( __predict_true(!TIMER_ID_IS_WRAPPED(id)) )
-        return __timer_delete( id );
-    else
-    {
-        thr_timer_table_t*  table = __timer_table_get();
-        thr_timer_t*        timer = thr_timer_table_from_id(table, id, 1);
-
-        if (timer == NULL) {
-            errno = EINVAL;
-            return -1;
-        }
-
-        /* tell the timer's thread to stop */
-        thr_timer_lock(timer);
-        timer->done = 1;
-        pthread_cond_signal( &timer->cond );
-        thr_timer_unlock(timer);
-
-        /* NOTE: the thread will call __timer_table_free() to free the
-         * timer object. the '1' parameter to thr_timer_table_from_id
-         * above ensured that the object and its timer_id cannot be
-         * reused before that.
-         */
-        return 0;
-    }
-}
-
-/* return the relative time until the next expiration, or 0 if
- * the timer is disarmed */
-static void timer_gettime_internal(thr_timer_t* timer, itimerspec* spec) {
-  timespec diff = const_cast<timespec&>(timer->expires);
-  if (!timespec_is_zero(&diff)) {
-    timespec now;
-
-    clock_gettime(timer->clock, &now);
-    timespec_sub(&diff, &now);
-
-    /* in case of overrun, return 0 */
-    if (timespec_cmp0(&diff) < 0) {
-      timespec_zero(&diff);
-    }
-  }
-
-  spec->it_value = diff;
-  spec->it_interval = const_cast<timespec&>(timer->period);
-}
-
-
-int timer_gettime(timer_t id, itimerspec* ospec) {
-    if (ospec == NULL) {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if ( __predict_true(!TIMER_ID_IS_WRAPPED(id)) ) {
-        return __timer_gettime( id, ospec );
-    } else {
-        thr_timer_t*  timer = thr_timer_from_id(id);
-
-        if (timer == NULL) {
-            errno = EINVAL;
-            return -1;
-        }
-        thr_timer_lock(timer);
-        timer_gettime_internal( timer, ospec );
-        thr_timer_unlock(timer);
-    }
-    return 0;
-}
-
-
-int
-timer_settime(timer_t id, int flags, const itimerspec* spec, itimerspec* ospec) {
-    if (spec == NULL) {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if ( __predict_true(!TIMER_ID_IS_WRAPPED(id)) ) {
-        return __timer_settime( id, flags, spec, ospec );
-    } else {
-        thr_timer_t*        timer = thr_timer_from_id(id);
-        timespec     expires, now;
-
-        if (timer == NULL) {
-            errno = EINVAL;
-            return -1;
-        }
-        thr_timer_lock(timer);
-
-        /* return current timer value if ospec isn't NULL */
-        if (ospec != NULL) {
-            timer_gettime_internal(timer, ospec );
-        }
-
-        /* compute next expiration time. note that if the
-         * new it_interval is 0, we should disarm the timer
-         */
-        expires = spec->it_value;
-        if (!timespec_is_zero(&expires)) {
-            clock_gettime( timer->clock, &now );
-            if (!(flags & TIMER_ABSTIME)) {
-                timespec_add(&expires, &now);
-            } else {
-                if (timespec_cmp(&expires, &now) < 0)
-                    expires = now;
-            }
-        }
-        const_cast<timespec&>(timer->expires) = expires;
-        const_cast<timespec&>(timer->period) = spec->it_interval;
-        thr_timer_unlock( timer );
-
-        /* signal the change to the thread */
-        pthread_cond_signal( &timer->cond );
-    }
-    return 0;
-}
-
-
-int
-timer_getoverrun(timer_t  id)
-{
-    if ( __predict_true(!TIMER_ID_IS_WRAPPED(id)) ) {
-        return __timer_getoverrun( id );
-    } else {
-        thr_timer_t*  timer = thr_timer_from_id(id);
-        int           result;
-
-        if (timer == NULL) {
-            errno = EINVAL;
-            return -1;
-        }
-
-        thr_timer_lock(timer);
-        result = timer->overruns;
-        thr_timer_unlock(timer);
-
-        return result;
-    }
-}
-
-
-static void* timer_thread_start(void* arg) {
-  thr_timer_t* timer = reinterpret_cast<thr_timer_t*>(arg);
-
-  thr_timer_lock(timer);
-
-  // Give this thread a meaningful name.
-  char name[32];
-  snprintf(name, sizeof(name), "POSIX interval timer 0x%08x", timer->id);
-  pthread_setname_np(pthread_self(), name);
-
-  // We loop until timer->done is set in timer_delete().
-  while (!timer->done) {
-    timespec expires = const_cast<timespec&>(timer->expires);
-    timespec period = const_cast<timespec&>(timer->period);
-
-    // If the timer is stopped or disarmed, wait indefinitely
-    // for a state change from timer_settime/_delete/_start_stop.
-    if (timer->stopped || timespec_is_zero(&expires)) {
-      pthread_cond_wait(&timer->cond, &timer->mutex);
-      continue;
-    }
-
-    // Otherwise, we need to do a timed wait until either a
-    // state change of the timer expiration time.
-    timespec now;
-    clock_gettime(timer->clock, &now);
-
-    if (timespec_cmp(&expires, &now) > 0) {
-      // Cool, there was no overrun, so compute the
-      // relative timeout as 'expires - now', then wait.
-      timespec diff = expires;
-      timespec_sub(&diff, &now);
-
-      int ret = __pthread_cond_timedwait_relative(&timer->cond, &timer->mutex, &diff);
-
-      // If we didn't time out, it means that a state change
-      // occurred, so loop to take care of it.
-      if (ret != ETIMEDOUT) {
-        continue;
-      }
-    } else {
-      // Overrun was detected before we could wait!
-      if (!timespec_is_zero(&period)) {
-        // For periodic timers, compute total overrun count.
-        do {
-          timespec_add(&expires, &period);
-          if (timer->overruns < DELAYTIMER_MAX) {
-            timer->overruns += 1;
-          }
-        } while (timespec_cmp(&expires, &now) < 0);
-
-        // Backtrack the last one, because we're going to
-        // add the same value just a bit later.
-        timespec_sub(&expires, &period);
-      } else {
-        // For non-periodic timers, things are simple.
-        timer->overruns = 1;
-      }
-    }
-
-    // If we get here, a timeout was detected.
-    // First reload/disarm the timer as needed.
-    if (!timespec_is_zero(&period)) {
-      timespec_add(&expires, &period);
-    } else {
-      timespec_zero(&expires);
-    }
-    const_cast<timespec&>(timer->expires) = expires;
-
-    // Now call the timer callback function. Release the
-    // lock to allow the function to modify the timer setting
-    // or call timer_getoverrun().
-    // NOTE: at this point we trust the callback not to be a
-    //      total moron and pthread_kill() the timer thread
-    thr_timer_unlock(timer);
-    timer->callback(timer->value);
-    thr_timer_lock(timer);
-
-    // Now clear the overruns counter. it only makes sense
-    // within the callback.
-    timer->overruns = 0;
-  }
-
-  thr_timer_unlock(timer);
-
-  // Free the timer object.
-  thr_timer_table_free(__timer_table_get(), timer);
-
-  return NULL;
-}
diff --git a/libc/bionic/tmpfile.cpp b/libc/bionic/tmpfile.cpp
index 8419ff5..602d407 100644
--- a/libc/bionic/tmpfile.cpp
+++ b/libc/bionic/tmpfile.cpp
@@ -57,22 +57,23 @@
 };
 
 static FILE* __tmpfile_dir(const char* tmp_dir) {
-  char buf[PATH_MAX];
-  int path_length = snprintf(buf, sizeof(buf), "%s/tmp.XXXXXXXXXX", tmp_dir);
-  if (path_length >= static_cast<int>(sizeof(buf))) {
+  char* path = NULL;
+  if (asprintf(&path, "%s/tmp.XXXXXXXXXX", tmp_dir) == -1) {
     return NULL;
   }
 
   int fd;
   {
     ScopedSignalBlocker ssb;
-    fd = mkstemp(buf);
+    fd = mkstemp(path);
     if (fd == -1) {
+      free(path);
       return NULL;
     }
 
     // Unlink the file now so that it's removed when closed.
-    unlink(buf);
+    unlink(path);
+    free(path);
 
     // Can we still use the file now it's unlinked?
     // File systems without hard link support won't have the usual Unix semantics.
diff --git a/libc/bionic/umount.c b/libc/bionic/umount.c
deleted file mode 100644
index 642e42c..0000000
--- a/libc/bionic/umount.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <unistd.h>
-
-extern int  umount2(const char*, int);
-
-int  umount(const char*  dir)
-{
-  return umount2(dir, 0);
-}
diff --git a/libc/bionic/umount.cpp b/libc/bionic/umount.cpp
new file mode 100644
index 0000000..fc80baf
--- /dev/null
+++ b/libc/bionic/umount.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/mount.h>
+
+int umount(const char* target) {
+  return umount2(target, 0);
+}
diff --git a/libc/bionic/unlockpt.c b/libc/bionic/unlockpt.c
deleted file mode 100644
index 998b7a3..0000000
--- a/libc/bionic/unlockpt.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <unistd.h>
-#include <sys/ioctl.h>
-
-int  unlockpt( int  fd )
-{
-    int  unlock = 0;
-
-    return ioctl( fd, TIOCSPTLCK, &unlock );
-}
diff --git a/libc/bionic/utmp.c b/libc/bionic/utmp.c
deleted file mode 100644
index c3b55da..0000000
--- a/libc/bionic/utmp.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Christos Zoulas.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-#include <sys/cdefs.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <utmp.h>
-
-static struct utmp utmp;
-static FILE *ut;
-static char utfile[MAXPATHLEN] = _PATH_UTMP;
-
-void
-setutent(void)
-{
-	if (ut == NULL)
-		return;
-	(void)fseeko(ut, (off_t)0, SEEK_SET);
-}
-
-struct utmp *
-getutent(void)
-{
-	if (ut == NULL) {
-		if ((ut = fopen(utfile, "r")) == NULL)
-			return NULL;
-	}
-	if (fread(&utmp, sizeof(utmp), 1, ut) == 1)
-		return &utmp;
-	return NULL;
-}
-
-void
-endutent(void)
-{
-	if (ut != NULL) {
-		(void)fclose(ut);
-		ut = NULL;
-	}
-}
-
-int
-utmpname(const char *fname)
-{
-	size_t len = strlen(fname);
-
-	if (len >= sizeof(utfile))
-		return 0;
-
-	/* must not end in x! */
-	if (fname[len - 1] == 'x')
-		return 0;
-
-	(void)strlcpy(utfile, fname, sizeof(utfile));
-	endutent();
-	return 1;
-}
diff --git a/libc/bionic/vdso.cpp b/libc/bionic/vdso.cpp
new file mode 100644
index 0000000..0875ee6
--- /dev/null
+++ b/libc/bionic/vdso.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <link.h>
+#include <sys/auxv.h>
+#include <unistd.h>
+
+// x86 has a vdso, but there's nothing useful to us in it.
+#if defined(__aarch64__) || defined(__x86_64__)
+
+#if defined(__aarch64__)
+#define VDSO_CLOCK_GETTIME_SYMBOL "__kernel_clock_gettime"
+#define VDSO_GETTIMEOFDAY_SYMBOL  "__kernel_gettimeofday"
+#elif defined(__x86_64__)
+#define VDSO_CLOCK_GETTIME_SYMBOL "__vdso_clock_gettime"
+#define VDSO_GETTIMEOFDAY_SYMBOL  "__vdso_gettimeofday"
+#endif
+
+#include <time.h>
+
+extern "C" int __clock_gettime(int, timespec*);
+extern "C" int __gettimeofday(timeval*, struct timezone*);
+
+struct vdso_entry {
+  const char* name;
+  void* fn;
+};
+
+enum {
+  VDSO_CLOCK_GETTIME = 0,
+  VDSO_GETTIMEOFDAY,
+  VDSO_END
+};
+
+static vdso_entry vdso_entries[] = {
+  [VDSO_CLOCK_GETTIME] = { VDSO_CLOCK_GETTIME_SYMBOL, reinterpret_cast<void*>(__clock_gettime) },
+  [VDSO_GETTIMEOFDAY] = { VDSO_GETTIMEOFDAY_SYMBOL, reinterpret_cast<void*>(__gettimeofday) },
+};
+
+int clock_gettime(int clock_id, timespec* tp) {
+  static int (*vdso_clock_gettime)(int, timespec*) =
+      (int (*)(int, timespec*)) vdso_entries[VDSO_CLOCK_GETTIME].fn;
+  return vdso_clock_gettime(clock_id, tp);
+}
+
+int gettimeofday(timeval* tv, struct timezone* tz) {
+  static int (*vdso_gettimeofday)(timeval*, struct timezone*) =
+      (int (*)(timeval*, struct timezone*)) vdso_entries[VDSO_GETTIMEOFDAY].fn;
+  return vdso_gettimeofday(tv, tz);
+}
+
+void __libc_init_vdso() {
+  // Do we have a vdso?
+  uintptr_t vdso_ehdr_addr = getauxval(AT_SYSINFO_EHDR);
+  ElfW(Ehdr)* vdso_ehdr = reinterpret_cast<ElfW(Ehdr)*>(vdso_ehdr_addr);
+  if (vdso_ehdr == NULL) {
+    return;
+  }
+
+  // How many symbols does it have?
+  size_t symbol_count = 0;
+  ElfW(Shdr)* vdso_shdr = reinterpret_cast<ElfW(Shdr)*>(vdso_ehdr_addr + vdso_ehdr->e_shoff);
+  for (size_t i = 0; i < vdso_ehdr->e_shnum; ++i) {
+    if (vdso_shdr[i].sh_type == SHT_DYNSYM) {
+      symbol_count = vdso_shdr[i].sh_size / sizeof(ElfW(Sym));
+    }
+  }
+  if (symbol_count == 0) {
+    return;
+  }
+
+  // Where's the dynamic table?
+  ElfW(Addr) vdso_addr = 0;
+  ElfW(Dyn)* vdso_dyn = NULL;
+  ElfW(Phdr)* vdso_phdr = reinterpret_cast<ElfW(Phdr)*>(vdso_ehdr_addr + vdso_ehdr->e_phoff);
+  for (size_t i = 0; i < vdso_ehdr->e_phnum; ++i) {
+    if (vdso_phdr[i].p_type == PT_DYNAMIC) {
+      vdso_dyn = reinterpret_cast<ElfW(Dyn)*>(vdso_ehdr_addr + vdso_phdr[i].p_offset);
+    } else if (vdso_phdr[i].p_type == PT_LOAD) {
+      vdso_addr = vdso_ehdr_addr + vdso_phdr[i].p_offset - vdso_phdr[i].p_vaddr;
+    }
+  }
+  if (vdso_addr == 0 || vdso_dyn == NULL) {
+    return;
+  }
+
+  // Where are the string and symbol tables?
+  const char* strtab = NULL;
+  ElfW(Sym)* symtab = NULL;
+  for (ElfW(Dyn)* d = vdso_dyn; d->d_tag != DT_NULL; ++d) {
+    if (d->d_tag == DT_STRTAB) {
+      strtab = reinterpret_cast<const char*>(vdso_addr + d->d_un.d_ptr);
+    } else if (d->d_tag == DT_SYMTAB) {
+      symtab = reinterpret_cast<ElfW(Sym)*>(vdso_addr + d->d_un.d_ptr);
+    }
+  }
+  if (strtab == NULL || symtab == NULL) {
+    return;
+  }
+
+  // Are there any symbols we want?
+  for (size_t i = 0; i < symbol_count; ++i) {
+    for (size_t j = 0; j < VDSO_END; ++j) {
+      if (strcmp(vdso_entries[j].name, strtab + symtab[i].st_name) == 0) {
+        vdso_entries[j].fn = reinterpret_cast<void*>(vdso_addr + symtab[i].st_value);
+      }
+    }
+  }
+}
+
+#else
+
+void __libc_init_vdso() {
+}
+
+#endif
diff --git a/libc/bionic/wait.cpp b/libc/bionic/wait.cpp
index cd75c10..e5c93aa 100644
--- a/libc/bionic/wait.cpp
+++ b/libc/bionic/wait.cpp
@@ -35,10 +35,6 @@
   return wait4(-1, status, 0, NULL);
 }
 
-pid_t wait3(int* status, int options, struct rusage* rusage) {
-  return wait4(-1, status, options, rusage);
-}
-
 pid_t waitpid(pid_t pid, int* status, int options) {
   return wait4(pid, status, options, NULL);
 }
diff --git a/libc/bionic/wchar.cpp b/libc/bionic/wchar.cpp
index 50a3875..e0879b9 100644
--- a/libc/bionic/wchar.cpp
+++ b/libc/bionic/wchar.cpp
@@ -1,286 +1,245 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
+/*	$OpenBSD: citrus_utf8.c,v 1.6 2012/12/05 23:19:59 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
- *  * Redistributions of source code must retain the above copyright
+ * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
 
-#include <ctype.h>
 #include <errno.h>
-#include <stdlib.h>
+#include <sys/param.h>
 #include <string.h>
 #include <wchar.h>
+#include <uchar.h>
 
-/* stubs for wide-char functions */
+#include "private/bionic_mbstate.h"
 
-wint_t btowc(int c) {
-  return (c == EOF) ? WEOF : c;
+//
+// This file is basically OpenBSD's citrus_utf8.c but rewritten to not require a
+// 12-byte mbstate_t so we're backwards-compatible with our LP32 ABI where
+// mbstate_t was only 4 bytes.
+//
+// The state is the UTF-8 sequence. We only support <= 4-bytes sequences so LP32
+// mbstate_t already has enough space (out of the 4 available bytes we only
+// need 3 since we should never need to store the entire sequence in the
+// intermediary state).
+//
+// The C standard leaves the conversion state undefined after a bad conversion.
+// To avoid unexpected failures due to the possible use of the internal private
+// state we always reset the conversion state when encountering illegal
+// sequences.
+//
+// We also implement the POSIX interface directly rather than being accessed via
+// function pointers.
+//
+
+int mbsinit(const mbstate_t* ps) {
+  return (ps == NULL || (*(reinterpret_cast<const uint32_t*>(ps->__seq)) == 0));
 }
 
-int fwprintf(FILE* stream, const wchar_t* format, ...) {
-  va_list args;
-  va_start(args, format);
-  int result = vfwprintf(stream, format, args);
-  va_end(args);
-  return result;
+size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps) {
+  static mbstate_t __private_state;
+  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+
+  // Our wchar_t is UTF-32
+  return mbrtoc32(reinterpret_cast<char32_t*>(pwc), s, n, state);
 }
 
-int wprintf(const wchar_t* format, ...) {
-  va_list args;
-  va_start(args, format);
-  int result = vwprintf(format, args);
-  va_end(args);
-  return result;
-}
+size_t mbsnrtowcs(wchar_t* dst, const char** src, size_t nmc, size_t len, mbstate_t* ps) {
+  static mbstate_t __private_state;
+  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+  size_t i, o, r;
 
-int swprintf(wchar_t* s, size_t n, const wchar_t* format, ...) {
-  va_list args;
-  va_start(args, format);
-  int result = vswprintf(s, n, format, args);
-  va_end(args);
-  return result;
-}
-
-int vwprintf(const wchar_t* format, va_list arg) {
-  return vfwprintf(stdout, format, arg);
-}
-
-int vfwprintf(FILE* /*stream*/, const wchar_t* /*format*/, va_list /*arg*/) {
-  errno = ENOTSUP;
-  return -1;
-}
-
-int vswprintf(wchar_t* /*s*/, size_t /*n*/, const wchar_t* /*format*/, va_list /*arg*/) {
-  errno = ENOTSUP;
-  return -1;
-}
-
-int fwscanf(FILE* /*stream*/, const wchar_t* /*format*/, ... ) {
-  errno = ENOTSUP;
-  return -1;
-}
-
-int wscanf(const wchar_t* format, ... ) {
-  va_list args;
-  va_start (args, format);
-  int result = fwscanf(stdout, format, args );
-  va_end (args);
-  return result;
-}
-
-int swscanf(const wchar_t* /*s*/, const wchar_t* /*format*/, ... ) {
-  errno = ENOTSUP;
-  return -1;
-}
-
-int iswalnum(wint_t wc) { return isalnum(wc); }
-int iswalpha(wint_t wc) { return isalpha(wc); }
-int iswcntrl(wint_t wc) { return iscntrl(wc); }
-int iswdigit(wint_t wc) { return isdigit(wc); }
-int iswgraph(wint_t wc) { return isgraph(wc); }
-int iswlower(wint_t wc) { return islower(wc); }
-int iswprint(wint_t wc) { return isprint(wc); }
-int iswpunct(wint_t wc) { return ispunct(wc); }
-int iswspace(wint_t wc) { return isspace(wc); }
-int iswupper(wint_t wc) { return isupper(wc); }
-int iswxdigit(wint_t wc) { return isxdigit(wc); }
-
-int iswctype(wint_t wc, wctype_t char_class) {
-  switch (char_class) {
-    case WC_TYPE_ALNUM: return isalnum(wc);
-    case WC_TYPE_ALPHA: return isalpha(wc);
-    case WC_TYPE_BLANK: return isblank(wc);
-    case WC_TYPE_CNTRL: return iscntrl(wc);
-    case WC_TYPE_DIGIT: return isdigit(wc);
-    case WC_TYPE_GRAPH: return isgraph(wc);
-    case WC_TYPE_LOWER: return islower(wc);
-    case WC_TYPE_PRINT: return isprint(wc);
-    case WC_TYPE_PUNCT: return ispunct(wc);
-    case WC_TYPE_SPACE: return isspace(wc);
-    case WC_TYPE_UPPER: return isupper(wc);
-    case WC_TYPE_XDIGIT: return isxdigit(wc);
-    default: return 0;
+  if (dst == NULL) {
+    /*
+     * The fast path in the loop below is not safe if an ASCII
+     * character appears as anything but the first byte of a
+     * multibyte sequence. Check now to avoid doing it in the loop.
+     */
+    if ((nmc > 0) && (mbstate_bytes_so_far(state) > 0)
+        && (static_cast<uint8_t>((*src)[0]) < 0x80)) {
+      return reset_and_return_illegal(EILSEQ, state);
+    }
+    for (i = o = 0; i < nmc; i += r, o++) {
+      if (static_cast<uint8_t>((*src)[i]) < 0x80) {
+        // Fast path for plain ASCII characters.
+        if ((*src)[i] == '\0') {
+          *src = nullptr;
+          return reset_and_return(o, state);
+        }
+        r = 1;
+      } else {
+        r = mbrtowc(NULL, *src + i, nmc - i, state);
+        if (r == __MB_ERR_ILLEGAL_SEQUENCE) {
+          return reset_and_return_illegal(EILSEQ, state);
+        }
+        if (r == __MB_ERR_INCOMPLETE_SEQUENCE) {
+          return reset_and_return_illegal(EILSEQ, state);
+        }
+        if (r == 0) {
+          *src = nullptr;
+          return reset_and_return(o, state);
+        }
+      }
+    }
+    return reset_and_return(o, state);
   }
-}
 
-wint_t fgetwc(FILE* stream) {
-  return static_cast<wint_t>(fgetc(stream));
-}
-
-wchar_t* fgetws(wchar_t* ws, int n, FILE* stream) {
-  return reinterpret_cast<wchar_t*>(fgets(reinterpret_cast<char*>(ws), n, stream));
-}
-
-wint_t fputwc(wchar_t wc, FILE* stream) {
-  return static_cast<wint_t>(fputc(static_cast<char>(wc), stream));
-}
-
-int fputws(const wchar_t* str, FILE* stream) {
-  return fputs(reinterpret_cast<const char*>(str), stream );
-}
-
-int fwide(FILE* /*stream*/, int mode) {
-  return mode;
-}
-
-wint_t getwc(FILE* stream) {
-  return getc(stream);
-}
-
-wint_t getwchar() {
-  return getchar();
-}
-
-int mbsinit(const mbstate_t* /*ps*/) {
-  return 1;
-}
-
-size_t mbrlen(const char* /*s*/, size_t n, mbstate_t* /*ps*/) {
-  return (n != 0);
-}
-
-size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* /*ps*/) {
-  if (s == NULL) {
-    s   = "";
-    pwc = NULL;
+  /*
+   * The fast path in the loop below is not safe if an ASCII
+   * character appears as anything but the first byte of a
+   * multibyte sequence. Check now to avoid doing it in the loop.
+   */
+  if ((nmc > 0) && (mbstate_bytes_so_far(state) > 0)
+      && (static_cast<uint8_t>((*src)[0]) < 0x80)) {
+    return reset_and_return_illegal(EILSEQ, state);
   }
-  if (n == 0) {
-    if (pwc) {
-      *pwc = 0;
-      return 0;
+  for (i = o = 0; i < nmc && o < len; i += r, o++) {
+    if (static_cast<uint8_t>((*src)[i]) < 0x80) {
+      // Fast path for plain ASCII characters.
+      dst[o] = (*src)[i];
+      r = 1;
+      if ((*src)[i] == '\0') {
+        *src = nullptr;
+        return reset_and_return(o, state);
+      }
+    } else {
+      r = mbrtowc(dst + o, *src + i, nmc - i, state);
+      if (r == __MB_ERR_ILLEGAL_SEQUENCE) {
+        *src += i;
+        return reset_and_return_illegal(EILSEQ, state);
+      }
+      if (r == __MB_ERR_INCOMPLETE_SEQUENCE) {
+        *src += nmc;
+        return reset_and_return(EILSEQ, state);
+      }
+      if (r == 0) {
+        *src = NULL;
+        return reset_and_return(o, state);
+      }
     }
   }
-  if (pwc) {
-    *pwc = *s;
-  }
-  return (*s != 0);
+  *src += i;
+  return reset_and_return(o, state);
 }
 
-size_t mbsrtowcs(wchar_t* dst, const char** src, size_t len, mbstate_t* /*ps*/) {
-  const char* s  = *src;
-  const char* s2 = reinterpret_cast<const char*>(memchr(s, 0, len));
+size_t mbsrtowcs(wchar_t* dst, const char** src, size_t len, mbstate_t* ps) {
+  return mbsnrtowcs(dst, src, SIZE_MAX, len, ps);
+}
 
-  if (s2 != NULL) {
-    len = (size_t)(s2 - s) + 1U;
+size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps) {
+  static mbstate_t __private_state;
+  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+
+  // Our wchar_t is UTF-32
+  return c32rtomb(s, static_cast<char32_t>(wc), state);
+}
+
+size_t wcsnrtombs(char* dst, const wchar_t** src, size_t nwc, size_t len, mbstate_t* ps) {
+  static mbstate_t __private_state;
+  mbstate_t* state = (ps == NULL) ? &__private_state : ps;
+
+  if (!mbsinit(state)) {
+    return reset_and_return_illegal(EILSEQ, state);
   }
 
-  if (dst) {
-    memcpy(reinterpret_cast<char*>(dst), s, len );
+  char buf[MB_LEN_MAX];
+  size_t i, o, r;
+  if (dst == NULL) {
+    for (i = o = 0; i < nwc; i++, o += r) {
+      wchar_t wc = (*src)[i];
+      if (static_cast<uint32_t>(wc) < 0x80) {
+        // Fast path for plain ASCII characters.
+        if (wc == 0) {
+          return o;
+        }
+        r = 1;
+      } else {
+        r = wcrtomb(buf, wc, state);
+        if (r == __MB_ERR_ILLEGAL_SEQUENCE) {
+          return r;
+        }
+      }
+    }
+    return o;
   }
 
-  *src = s + len;
-  return len;
-}
-
-size_t mbstowcs(wchar_t* dst, const char* src, size_t len) {
-  return mbsrtowcs(dst, &src, len, NULL);
-}
-
-wint_t putwc(wchar_t wc, FILE* stream) {
-  return fputc(static_cast<char>(wc), stream);
-}
-
-wint_t putwchar(wchar_t wc) {
-  return putchar(static_cast<char>(wc));
-}
-
-wint_t towlower(wint_t wc) {
-  return tolower(wc);
-}
-
-wint_t towupper(wint_t wc) {
-  return toupper(wc);
-}
-
-wint_t ungetwc(wint_t wc, FILE* stream) {
-  return ungetc(static_cast<char>(wc), stream);
-}
-
-size_t wcrtomb(char* s, wchar_t /*wc*/, mbstate_t* /*ps*/) {
-  if (s != NULL) {
-    *s = 1;
-  }
-  return 1;
-}
-
-size_t wcsftime(wchar_t* wcs, size_t maxsize, const wchar_t* format,  const struct tm* timptr) {
-  return strftime(reinterpret_cast<char*>(wcs), maxsize, reinterpret_cast<const char*>(format), timptr);
-}
-
-size_t wcsrtombs(char* dst, const wchar_t** src, size_t len, mbstate_t* /*ps*/) {
-  const char* s = reinterpret_cast<const char*>(*src);
-  const char* s2 = reinterpret_cast<const char*>(memchr(s, 0, len));
-  if (s2 != NULL) {
-    len = (s2 - s)+1;
-  }
-  if (dst != NULL) {
-    memcpy( dst, s, len );
-  }
-  *src = (wchar_t*)(s + len);
-  return len;
-}
-
-size_t wcstombs(char* dst, const wchar_t* src, size_t len) {
-  return wcsrtombs(dst, &src, len, NULL);
-}
-
-double wcstod(const wchar_t* nptr, wchar_t** endptr) {
-  return strtod(reinterpret_cast<const char*>(nptr), reinterpret_cast<char**>(endptr));
-}
-
-long int wcstol(const wchar_t* nptr, wchar_t** endptr, int base) {
-  return strtol(reinterpret_cast<const char*>(nptr), reinterpret_cast<char**>(endptr), base);
-}
-
-unsigned long int wcstoul(const wchar_t* nptr, wchar_t** endptr, int base) {
-  return strtoul(reinterpret_cast<const char*>(nptr), reinterpret_cast<char**>(endptr), base);
-}
-
-wchar_t* wcswcs(const wchar_t* ws1, const wchar_t* ws2) {
-  const char* s1 = reinterpret_cast<const char*>(ws1);
-  const char* s2 = reinterpret_cast<const char*>(ws2);
-  return reinterpret_cast<wchar_t*>(strstr(s1, s2));
-}
-
-int wctob(wint_t c) {
-  return c;
-}
-
-wctype_t wctype(const char* property) {
-  static const char* const  properties[WC_TYPE_MAX] = {
-    "<invalid>",
-    "alnum", "alpha", "blank", "cntrl", "digit", "graph",
-    "lower", "print", "punct", "space", "upper", "xdigit"
-  };
-  for (size_t i = 0; i < WC_TYPE_MAX; ++i) {
-    if (!strcmp(properties[i], property)) {
-      return static_cast<wctype_t>(i);
+  for (i = o = 0; i < nwc && o < len; i++, o += r) {
+    wchar_t wc = (*src)[i];
+    if (static_cast<uint32_t>(wc) < 0x80) {
+      // Fast path for plain ASCII characters.
+      dst[o] = wc;
+      if (wc == 0) {
+        *src = NULL;
+        return o;
+      }
+      r = 1;
+    } else if (len - o >= sizeof(buf)) {
+      // Enough space to translate in-place.
+      r = wcrtomb(dst + o, wc, state);
+      if (r == __MB_ERR_ILLEGAL_SEQUENCE) {
+        *src += i;
+        return r;
+      }
+    } else {
+      // May not be enough space; use temp buffer.
+      r = wcrtomb(buf, wc, state);
+      if (r == __MB_ERR_ILLEGAL_SEQUENCE) {
+        *src += i;
+        return r;
+      }
+      if (r > len - o) {
+        break;
+      }
+      memcpy(dst + o, buf, r);
     }
   }
-  return static_cast<wctype_t>(0);
+  *src += i;
+  return o;
 }
 
-int wcwidth(wchar_t wc) {
-  return (wc > 0);
+size_t wcsrtombs(char* dst, const wchar_t** src, size_t len, mbstate_t* ps) {
+  return wcsnrtombs(dst, src, SIZE_MAX, len, ps);
+}
+
+int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t) {
+  return wcscoll(ws1, ws2);
+}
+
+size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src, size_t n, locale_t) {
+  return wcsxfrm(dest, src, n);
+}
+
+long long wcstoll_l(const wchar_t *nptr, wchar_t **endptr, int base,
+                    locale_t) {
+  return wcstoll(nptr, endptr, base);
+}
+
+unsigned long long wcstoull_l(const wchar_t *nptr, wchar_t **endptr,
+                              int base, locale_t) {
+  return wcstoull(nptr, endptr, base);
+}
+
+long double wcstold_l(const wchar_t *nptr, wchar_t **endptr, locale_t) {
+  return wcstold(nptr, endptr);
 }
diff --git a/libc/bionic/wcscoll.c b/libc/bionic/wcscoll.c
deleted file mode 100644
index 6e843b7..0000000
--- a/libc/bionic/wcscoll.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <wchar.h>
-/*
- * Compare strings using the current locale.  Since Bionic really does not
- * support locales, we assume we always use the C locale and call wcscmp.
- *
- * This function is provided to make libstdc++-v3 usable.
- */
-int
-wcscoll(const wchar_t *ws1, const wchar_t *ws2)
-{
-    return wcscmp(ws1, ws2);
-}
diff --git a/libc/bionic/wctype.cpp b/libc/bionic/wctype.cpp
new file mode 100644
index 0000000..f2d7861
--- /dev/null
+++ b/libc/bionic/wctype.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+// TODO: these only work for the ASCII range; rewrite to dlsym icu4c? http://b/14499654
+
+int iswalnum(wint_t wc) { return isalnum(wc); }
+int iswalpha(wint_t wc) { return isalpha(wc); }
+int iswblank(wint_t wc) { return isblank(wc); }
+int iswcntrl(wint_t wc) { return iscntrl(wc); }
+int iswdigit(wint_t wc) { return isdigit(wc); }
+int iswgraph(wint_t wc) { return isgraph(wc); }
+int iswlower(wint_t wc) { return islower(wc); }
+int iswprint(wint_t wc) { return isprint(wc); }
+int iswpunct(wint_t wc) { return ispunct(wc); }
+int iswspace(wint_t wc) { return isspace(wc); }
+int iswupper(wint_t wc) { return isupper(wc); }
+int iswxdigit(wint_t wc) { return isxdigit(wc); }
+
+int iswalnum_l(wint_t c, locale_t) { return iswalnum(c); }
+int iswalpha_l(wint_t c, locale_t) { return iswalpha(c); }
+int iswblank_l(wint_t c, locale_t) { return iswblank(c); }
+int iswcntrl_l(wint_t c, locale_t) { return iswcntrl(c); }
+int iswdigit_l(wint_t c, locale_t) { return iswdigit(c); }
+int iswgraph_l(wint_t c, locale_t) { return iswgraph(c); }
+int iswlower_l(wint_t c, locale_t) { return iswlower(c); }
+int iswprint_l(wint_t c, locale_t) { return iswprint(c); }
+int iswpunct_l(wint_t c, locale_t) { return iswpunct(c); }
+int iswspace_l(wint_t c, locale_t) { return iswspace(c); }
+int iswupper_l(wint_t c, locale_t) { return iswupper(c); }
+int iswxdigit_l(wint_t c, locale_t) { return iswxdigit(c); }
+
+int iswctype(wint_t wc, wctype_t char_class) {
+  switch (char_class) {
+    case WC_TYPE_ALNUM: return iswalnum(wc);
+    case WC_TYPE_ALPHA: return iswalpha(wc);
+    case WC_TYPE_BLANK: return iswblank(wc);
+    case WC_TYPE_CNTRL: return iswcntrl(wc);
+    case WC_TYPE_DIGIT: return iswdigit(wc);
+    case WC_TYPE_GRAPH: return iswgraph(wc);
+    case WC_TYPE_LOWER: return iswlower(wc);
+    case WC_TYPE_PRINT: return iswprint(wc);
+    case WC_TYPE_PUNCT: return iswpunct(wc);
+    case WC_TYPE_SPACE: return iswspace(wc);
+    case WC_TYPE_UPPER: return iswupper(wc);
+    case WC_TYPE_XDIGIT: return iswxdigit(wc);
+    default: return 0;
+  }
+}
+
+int iswctype_l(wint_t wc, wctype_t char_class, locale_t) {
+  return iswctype(wc, char_class);
+}
+
+wint_t towlower(wint_t wc) { return tolower(wc); }
+wint_t towupper(wint_t wc) { return toupper(wc); }
+
+int towupper_l(int c, locale_t) { return towupper(c); }
+int towlower_l(int c, locale_t) { return towlower(c); }
+
+wctype_t wctype(const char* property) {
+  static const char* const  properties[WC_TYPE_MAX] = {
+    "<invalid>",
+    "alnum", "alpha", "blank", "cntrl", "digit", "graph",
+    "lower", "print", "punct", "space", "upper", "xdigit"
+  };
+  for (size_t i = 0; i < WC_TYPE_MAX; ++i) {
+    if (!strcmp(properties[i], property)) {
+      return static_cast<wctype_t>(i);
+    }
+  }
+  return static_cast<wctype_t>(0);
+}
+
+wctype_t wctype_l(const char* property, locale_t) {
+  return wctype(property);
+}
+
+int wcwidth(wchar_t wc) {
+  return (wc > 0);
+}
diff --git a/libc/crt.mk b/libc/crt.mk
new file mode 100644
index 0000000..c3ba54b
--- /dev/null
+++ b/libc/crt.mk
@@ -0,0 +1,149 @@
+# Define the libc run-time (crt) support object files that must be built,
+# which are needed to build all other objects (shared/static libs and
+# executables)
+# ==========================================================================
+# AArch64, ARM, MIPS, and x86 all need crtbegin_so/crtend_so.
+#
+# For x86, the .init section must point to a function that calls all
+# entries in the .ctors section. (on ARM this is done through the
+# .init_array section instead).
+#
+# For all the platforms, the .fini_array section must point to a function
+# that will call __cxa_finalize(&__dso_handle) in order to ensure that
+# static C++ destructors are properly called on dlclose().
+#
+# Args:
+#     my_2nd_arch_prefix: set to $(TARGET_2ND_ARCH_VAR_PREFIX) if it's
+#                         for the 2nd arch; otherwise empty.
+
+my_arch := $(TARGET_$(my_2nd_arch_prefix)ARCH)
+
+my_libc_crt_target_crtbegin_file := $(libc_crt_target_crtbegin_file_$(my_arch))
+my_libc_crt_target_crtbegin_so_file := $(libc_crt_target_crtbegin_so_file_$(my_arch))
+
+my_libc_crt_target_cflags := \
+    $(libc_crt_target_cflags) \
+    $(libc_crt_target_cflags_$(my_arch))
+
+my_libc_crt_target_so_cflags := \
+    $(libc_crt_target_so_cflags_$(my_arch)) \
+    $(my_libc_crt_target_cflags)
+
+my_libc_crt_target_ldflags := $(libc_crt_target_ldflags_$(my_arch))
+
+
+# See the comment in crtbrand.c for the reason why we need to generate
+# crtbrand.s before generating crtbrand.o.
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.s
+$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
+$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
+$(GEN): $(LOCAL_PATH)/bionic/crtbrand.c
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) -S \
+		-MD -MF $(@:%.s=%.d) -o $@ $<
+	$(hide) sed -i -e '/\.note\.ABI-tag/s/progbits/note/' $@
+	$(call transform-d-to-p-args,$(@:%.s=%.d),$(@:%.s=%.P))
+-include $(GEN:%.s=%.P)
+
+
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
+$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
+$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
+$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.s
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) -o $@ -c $<
+
+
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
+$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
+$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
+$(GEN): $(my_libc_crt_target_crtbegin_so_file)
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
+		-MD -MF $(@:%.o=%.d) -o $@ -c $<
+	$(transform-d-to-p)
+-include $(GEN:%.o=%.P)
+
+
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
+$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
+$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
+$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend_so.S
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
+		-MD -MF $(@:%.o=%.d) -o $@ -c $<
+	$(transform-d-to-p)
+-include $(GEN:%.o=%.P)
+
+
+# The following two are installed to device
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_SHARED_LIBRARIES)/crtbegin_so.o
+$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
+	$(hide) mkdir -p $(dir $@) && cp -f $< $@
+ALL_GENERATED_SOURCES += $(GEN)
+
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_SHARED_LIBRARIES)/crtend_so.o
+$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
+	$(hide) mkdir -p $(dir $@) && cp -f $< $@
+ALL_GENERATED_SOURCES += $(GEN)
+
+
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o
+$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
+$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
+$(GEN): $(my_libc_crt_target_crtbegin_file)
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
+		-MD -MF $(@:%.o=%.d) -o $@ -c $<
+	$(transform-d-to-p)
+-include $(GEN:%.o=%.P)
+
+
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
+$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD)
+$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags)
+$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o \
+    $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^
+
+
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o
+$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
+$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
+$(GEN): $(my_libc_crt_target_crtbegin_file)
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
+		-MD -MF $(@:%.o=%.d) -o $@ -c $<
+	$(transform-d-to-p)
+-include $(GEN:%.o=%.P)
+
+
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
+$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD)
+$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags)
+$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o \
+    $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^
+
+
+# We rename crtend.o to crtend_android.o to avoid a
+# name clash between gcc and bionic.
+GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
+$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
+$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
+$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend.S
+	@mkdir -p $(dir $@)
+	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
+		-MD -MF $(@:%.o=%.d) -o $@ -c $<
+	$(transform-d-to-p)
+-include $(GEN:%.o=%.P)
+
+# Clear temp vars
+my_libc_crt_target_ldflags :=
+my_libc_crt_target_so_cflags :=
+my_libc_crt_target_cflags :=
+my_libc_crt_target_crtbegin_so_file :=
+my_libc_crt_target_crtbegin_file :=
+my_arch :=
diff --git a/libc/dns/gethnamaddr.c b/libc/dns/gethnamaddr.c
new file mode 100644
index 0000000..1d847b8
--- /dev/null
+++ b/libc/dns/gethnamaddr.c
@@ -0,0 +1,1416 @@
+/*	$NetBSD: gethnamaddr.c,v 1.70 2006/03/22 00:03:51 christos Exp $	*/
+
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ * -
+ * --Copyright--
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include "NetdClientDispatch.h"
+#include "resolv_netid.h"
+#include "resolv_private.h"
+#include "resolv_cache.h"
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <strings.h>
+#include <syslog.h>
+#include <unistd.h>
+
+#define ALIGNBYTES (sizeof(uintptr_t) - 1)
+#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
+
+#ifndef LOG_AUTH
+# define LOG_AUTH 0
+#endif
+
+#define MULTI_PTRS_ARE_ALIASES 1	/* XXX - experimental */
+
+#include "nsswitch.h"
+#include <stdlib.h>
+#include <string.h>
+
+// This should be synchronized to ResponseCode.h
+static const int DnsProxyQueryResult = 222;
+
+static const char AskedForGot[] =
+			  "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
+
+#define	MAXPACKET	(64*1024)
+
+typedef union {
+    HEADER hdr;
+    u_char buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+    int32_t al;
+    char ac;
+} align;
+
+#ifdef DEBUG
+static void dprintf(const char *, res_state, ...)
+	__attribute__((__format__(__printf__, 1, 3)));
+#endif
+static struct hostent *getanswer(const querybuf *, int, const char *, int,
+    res_state);
+static void map_v4v6_address(const char *, char *);
+static void map_v4v6_hostent(struct hostent *, char **, char *);
+static void addrsort(char **, int, res_state);
+
+static void _sethtent(int);
+static void _endhtent(void);
+static struct hostent *_gethtent(void);
+void ht_sethostent(int);
+void ht_endhostent(void);
+struct hostent *ht_gethostbyname(char *);
+struct hostent *ht_gethostbyaddr(const char *, int, int);
+void dns_service(void);
+#undef dn_skipname
+int dn_skipname(const u_char *, const u_char *);
+static int _gethtbyaddr(void *, void *, va_list);
+static int _gethtbyname(void *, void *, va_list);
+static struct hostent *_gethtbyname2(const char *, int);
+static int _dns_gethtbyaddr(void *, void *, va_list);
+static int _dns_gethtbyname(void *, void *, va_list);
+
+static struct hostent *gethostbyname_internal(const char *, int, res_state, unsigned, unsigned);
+
+static const ns_src default_dns_files[] = {
+	{ NSSRC_FILES, 	NS_SUCCESS },
+	{ NSSRC_DNS, 	NS_SUCCESS },
+	{ 0, 0 }
+};
+
+
+#ifdef DEBUG
+static void
+dprintf(const char *msg, res_state res, ...)
+{
+	assert(msg != NULL);
+
+	if (res->options & RES_DEBUG) {
+		int save = errno;
+		va_list ap;
+
+		va_start (ap, res);
+		vprintf(msg, ap);
+		va_end (ap);
+
+		errno = save;
+	}
+}
+#else
+# define dprintf(msg, res, num) ((void)0) /*nada*/
+#endif
+
+#define BOUNDED_INCR(x) \
+	do { \
+		cp += (x); \
+		if (cp > eom) { \
+			h_errno = NO_RECOVERY; \
+			return NULL; \
+		} \
+	} while (/*CONSTCOND*/0)
+
+#define BOUNDS_CHECK(ptr, count) \
+	do { \
+		if ((ptr) + (count) > eom) { \
+			h_errno = NO_RECOVERY; \
+			return NULL; \
+		} \
+	} while (/*CONSTCOND*/0)
+
+static struct hostent *
+getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
+    res_state res)
+{
+	const HEADER *hp;
+	const u_char *cp;
+	int n;
+	const u_char *eom, *erdata;
+	char *bp, **ap, **hap, *ep;
+	int type, class, ancount, qdcount;
+	int haveanswer, had_error;
+	int toobig = 0;
+	char tbuf[MAXDNAME];
+	const char *tname;
+	int (*name_ok)(const char *);
+	res_static  rs = __res_get_static();
+
+	assert(answer != NULL);
+	assert(qname != NULL);
+
+	tname = qname;
+	rs->host.h_name = NULL;
+	eom = answer->buf + anslen;
+	switch (qtype) {
+	case T_A:
+	case T_AAAA:
+		name_ok = res_hnok;
+		break;
+	case T_PTR:
+		name_ok = res_dnok;
+		break;
+	default:
+		return NULL;	/* XXX should be abort(); */
+	}
+	/*
+	 * find first satisfactory answer
+	 */
+	hp = &answer->hdr;
+	ancount = ntohs(hp->ancount);
+	qdcount = ntohs(hp->qdcount);
+	bp = rs->hostbuf;
+	ep = rs->hostbuf + sizeof rs->hostbuf;
+	cp = answer->buf;
+	BOUNDED_INCR(HFIXEDSZ);
+	if (qdcount != 1) {
+		h_errno = NO_RECOVERY;
+		return NULL;
+	}
+	n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
+	if ((n < 0) || !(*name_ok)(bp)) {
+		h_errno = NO_RECOVERY;
+		return NULL;
+	}
+	BOUNDED_INCR(n + QFIXEDSZ);
+	if (qtype == T_A || qtype == T_AAAA) {
+		/* res_send() has already verified that the query name is the
+		 * same as the one we sent; this just gets the expanded name
+		 * (i.e., with the succeeding search-domain tacked on).
+		 */
+		n = strlen(bp) + 1;		/* for the \0 */
+		if (n >= MAXHOSTNAMELEN) {
+			h_errno = NO_RECOVERY;
+			return NULL;
+		}
+		rs->host.h_name = bp;
+		bp += n;
+		/* The qname can be abbreviated, but h_name is now absolute. */
+		qname = rs->host.h_name;
+	}
+	ap = rs->host_aliases;
+	*ap = NULL;
+	rs->host.h_aliases = rs->host_aliases;
+	hap = rs->h_addr_ptrs;
+	*hap = NULL;
+	rs->host.h_addr_list = rs->h_addr_ptrs;
+	haveanswer = 0;
+	had_error = 0;
+	while (ancount-- > 0 && cp < eom && !had_error) {
+		n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
+		if ((n < 0) || !(*name_ok)(bp)) {
+			had_error++;
+			continue;
+		}
+		cp += n;			/* name */
+		BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
+		type = _getshort(cp);
+ 		cp += INT16SZ;			/* type */
+		class = _getshort(cp);
+ 		cp += INT16SZ + INT32SZ;	/* class, TTL */
+		n = _getshort(cp);
+		cp += INT16SZ;			/* len */
+		BOUNDS_CHECK(cp, n);
+		erdata = cp + n;
+		if (class != C_IN) {
+			/* XXX - debug? syslog? */
+			cp += n;
+			continue;		/* XXX - had_error++ ? */
+		}
+		if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
+			if (ap >= &rs->host_aliases[MAXALIASES-1])
+				continue;
+			n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+			if ((n < 0) || !(*name_ok)(tbuf)) {
+				had_error++;
+				continue;
+			}
+			cp += n;
+			if (cp != erdata) {
+				h_errno = NO_RECOVERY;
+				return NULL;
+			}
+			/* Store alias. */
+			*ap++ = bp;
+			n = strlen(bp) + 1;	/* for the \0 */
+			if (n >= MAXHOSTNAMELEN) {
+				had_error++;
+				continue;
+			}
+			bp += n;
+			/* Get canonical name. */
+			n = strlen(tbuf) + 1;	/* for the \0 */
+			if (n > ep - bp || n >= MAXHOSTNAMELEN) {
+				had_error++;
+				continue;
+			}
+			strlcpy(bp, tbuf, (size_t)(ep - bp));
+			rs->host.h_name = bp;
+			bp += n;
+			continue;
+		}
+		if (qtype == T_PTR && type == T_CNAME) {
+			n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+			if (n < 0 || !res_dnok(tbuf)) {
+				had_error++;
+				continue;
+			}
+			cp += n;
+			if (cp != erdata) {
+				h_errno = NO_RECOVERY;
+				return NULL;
+			}
+			/* Get canonical name. */
+			n = strlen(tbuf) + 1;	/* for the \0 */
+			if (n > ep - bp || n >= MAXHOSTNAMELEN) {
+				had_error++;
+				continue;
+			}
+			strlcpy(bp, tbuf, (size_t)(ep - bp));
+			tname = bp;
+			bp += n;
+			continue;
+		}
+		if (type != qtype) {
+			if (type != T_KEY && type != T_SIG)
+				syslog(LOG_NOTICE|LOG_AUTH,
+	       "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
+				       qname, p_class(C_IN), p_type(qtype),
+				       p_type(type));
+			cp += n;
+			continue;		/* XXX - had_error++ ? */
+		}
+		switch (type) {
+		case T_PTR:
+			if (strcasecmp(tname, bp) != 0) {
+				syslog(LOG_NOTICE|LOG_AUTH,
+				       AskedForGot, qname, bp);
+				cp += n;
+				continue;	/* XXX - had_error++ ? */
+			}
+			n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
+			if ((n < 0) || !res_hnok(bp)) {
+				had_error++;
+				break;
+			}
+#if MULTI_PTRS_ARE_ALIASES
+			cp += n;
+			if (cp != erdata) {
+				h_errno = NO_RECOVERY;
+				return NULL;
+			}
+			if (!haveanswer)
+				rs->host.h_name = bp;
+			else if (ap < &rs->host_aliases[MAXALIASES-1])
+				*ap++ = bp;
+			else
+				n = -1;
+			if (n != -1) {
+				n = strlen(bp) + 1;	/* for the \0 */
+				if (n >= MAXHOSTNAMELEN) {
+					had_error++;
+					break;
+				}
+				bp += n;
+			}
+			break;
+#else
+			rs->host.h_name = bp;
+			if (res->options & RES_USE_INET6) {
+				n = strlen(bp) + 1;	/* for the \0 */
+				if (n >= MAXHOSTNAMELEN) {
+					had_error++;
+					break;
+				}
+				bp += n;
+				map_v4v6_hostent(&rs->host, &bp, ep);
+			}
+			h_errno = NETDB_SUCCESS;
+			return &rs->host;
+#endif
+		case T_A:
+		case T_AAAA:
+			if (strcasecmp(rs->host.h_name, bp) != 0) {
+				syslog(LOG_NOTICE|LOG_AUTH,
+				       AskedForGot, rs->host.h_name, bp);
+				cp += n;
+				continue;	/* XXX - had_error++ ? */
+			}
+			if (n != rs->host.h_length) {
+				cp += n;
+				continue;
+			}
+			if (type == T_AAAA) {
+				struct in6_addr in6;
+				memcpy(&in6, cp, IN6ADDRSZ);
+				if (IN6_IS_ADDR_V4MAPPED(&in6)) {
+					cp += n;
+					continue;
+				}
+			}
+			if (!haveanswer) {
+				int nn;
+
+				rs->host.h_name = bp;
+				nn = strlen(bp) + 1;	/* for the \0 */
+				bp += nn;
+			}
+
+			bp += sizeof(align) -
+			    (size_t)((u_long)bp % sizeof(align));
+
+			if (bp + n >= &rs->hostbuf[sizeof rs->hostbuf]) {
+				dprintf("size (%d) too big\n", res, n);
+				had_error++;
+				continue;
+			}
+			if (hap >= &rs->h_addr_ptrs[MAXADDRS-1]) {
+				if (!toobig++)
+					dprintf("Too many addresses (%d)\n",
+						res, MAXADDRS);
+				cp += n;
+				continue;
+			}
+			(void)memcpy(*hap++ = bp, cp, (size_t)n);
+			bp += n;
+			cp += n;
+			if (cp != erdata) {
+				h_errno = NO_RECOVERY;
+				return NULL;
+			}
+			break;
+		default:
+			abort();
+		}
+		if (!had_error)
+			haveanswer++;
+	}
+	if (haveanswer) {
+		*ap = NULL;
+		*hap = NULL;
+		/*
+		 * Note: we sort even if host can take only one address
+		 * in its return structures - should give it the "best"
+		 * address in that case, not some random one
+		 */
+		if (res->nsort && haveanswer > 1 && qtype == T_A)
+			addrsort(rs->h_addr_ptrs, haveanswer, res);
+		if (!rs->host.h_name) {
+			n = strlen(qname) + 1;	/* for the \0 */
+			if (n > ep - bp || n >= MAXHOSTNAMELEN)
+				goto no_recovery;
+			strlcpy(bp, qname, (size_t)(ep - bp));
+			rs->host.h_name = bp;
+			bp += n;
+		}
+		if (res->options & RES_USE_INET6)
+			map_v4v6_hostent(&rs->host, &bp, ep);
+		h_errno = NETDB_SUCCESS;
+		return &rs->host;
+	}
+ no_recovery:
+	h_errno = NO_RECOVERY;
+	return NULL;
+}
+
+int
+gethostbyname_r(const char *name, struct hostent *hp, char *buf, size_t buflen,
+    struct hostent**result, int *errorp)
+{
+        struct hostent *res;
+
+        res = gethostbyname(name);
+        *errorp = h_errno;
+        if (res == NULL) {
+                *result = NULL;
+                return -1;
+        }
+        memcpy(hp, res, sizeof *hp);
+        *result = hp;
+        return 0;
+}
+
+struct hostent *
+gethostbyname(const char *name)
+{
+	struct hostent *hp;
+	res_state res = __res_get_state();
+
+	if (res == NULL)
+		return NULL;
+
+	assert(name != NULL);
+
+	/* try IPv6 first - if that fails do IPv4 */
+	if (res->options & RES_USE_INET6) {
+		hp = gethostbyname_internal(name, AF_INET6, res, NETID_UNSET, MARK_UNSET);
+		if (hp) {
+			__res_put_state(res);
+			return hp;
+		}
+	}
+	hp = gethostbyname_internal(name, AF_INET, res, NETID_UNSET, MARK_UNSET);
+	__res_put_state(res);
+	return hp;
+}
+
+struct hostent *
+gethostbyname2(const char *name, int af)
+{
+	return android_gethostbynamefornet(name, af, NETID_UNSET, MARK_UNSET);
+}
+
+struct hostent *
+android_gethostbynamefornet(const char *name, int af, unsigned netid, unsigned mark)
+{
+	struct hostent *hp;
+	res_state res = __res_get_state();
+
+	if (res == NULL)
+		return NULL;
+	hp = gethostbyname_internal(name, af, res, netid, mark);
+	__res_put_state(res);
+	return hp;
+}
+
+
+static FILE* android_open_proxy()
+{
+	int sock;
+	const int one = 1;
+	struct sockaddr_un proxy_addr;
+
+	sock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+	if (sock < 0) {
+		return NULL;
+	}
+
+	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+	memset(&proxy_addr, 0, sizeof(proxy_addr));
+	proxy_addr.sun_family = AF_UNIX;
+	strlcpy(proxy_addr.sun_path, "/dev/socket/dnsproxyd", sizeof(proxy_addr.sun_path));
+	if (TEMP_FAILURE_RETRY(connect(sock,
+			(const struct sockaddr*) &proxy_addr,
+			sizeof(proxy_addr))) != 0) {
+		close(sock);
+		return NULL;
+	}
+
+	return fdopen(sock, "r+");
+}
+
+static struct hostent *
+android_read_hostent(FILE* proxy)
+{
+	uint32_t size;
+	char buf[4];
+	if (fread(buf, 1, sizeof(buf), proxy) != sizeof(buf)) return NULL;
+
+	/* This is reading serialized data from system/netd/server/DnsProxyListener.cpp
+	 * and changes here need to be matched there */
+	int result_code = strtol(buf, NULL, 10);
+	if (result_code != DnsProxyQueryResult) {
+		fread(&size, 1, sizeof(size), proxy);
+		return NULL;
+	}
+
+	if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
+	size = ntohl(size);
+	res_static rs = __res_get_static();
+	memset(&rs->host, 0, sizeof(rs->host));
+	char *ptr = rs->hostbuf;
+
+	if (fread(ptr, 1, size, proxy) != size) return NULL;
+	ptr += size;
+	rs->host.h_name = rs->hostbuf;
+
+	char **aliases = rs->host_aliases;
+	rs->host.h_aliases = rs->host_aliases;
+	while (1) {
+		if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
+		size = ntohl(size);
+
+		if (size == 0) {
+			*aliases = NULL;
+			break;
+		}
+		if (fread(ptr, 1, size, proxy) != size) return NULL;
+		*aliases++ = ptr;
+		ptr += size;
+	}
+
+	if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
+	rs->host.h_addrtype = ntohl(size);
+
+	if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
+	rs->host.h_length = ntohl(size);
+
+	char **addrs = rs->h_addr_ptrs;
+	rs->host.h_addr_list = rs->h_addr_ptrs;
+	while (1) {
+		if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
+		size = ntohl(size);
+		if (size == 0) {
+			*addrs = NULL;
+			break;
+		}
+		if (fread(ptr, 1, size, proxy) != size) return NULL;
+		*addrs++ = ptr;
+		ptr += size;
+	}
+
+	return &rs->host;
+}
+
+
+static struct hostent *
+gethostbyname_internal_real(const char *name, int af, res_state res)
+{
+	const char *cp;
+	char *bp, *ep;
+	int size;
+	struct hostent *hp;
+	res_static rs = __res_get_static();
+
+	static const ns_dtab dtab[] = {
+		NS_FILES_CB(_gethtbyname, NULL)
+		{ NSSRC_DNS, _dns_gethtbyname, NULL },	/* force -DHESIOD */
+		{ 0, 0, 0 }
+	};
+
+	assert(name != NULL);
+
+	switch (af) {
+	case AF_INET:
+		size = INADDRSZ;
+		break;
+	case AF_INET6:
+		size = IN6ADDRSZ;
+		break;
+	default:
+		h_errno = NETDB_INTERNAL;
+		errno = EAFNOSUPPORT;
+		return NULL;
+	}
+
+	rs->host.h_addrtype = af;
+	rs->host.h_length = size;
+
+	/*
+	 * if there aren't any dots, it could be a user-level alias.
+	 * this is also done in res_nquery() since we are not the only
+	 * function that looks up host names.
+	 */
+	if (!strchr(name, '.') && (cp = __hostalias(name)))
+		name = cp;
+
+	/*
+	 * disallow names consisting only of digits/dots, unless
+	 * they end in a dot.
+	 */
+	if (isdigit((u_char) name[0]))
+		for (cp = name;; ++cp) {
+			if (!*cp) {
+				if (*--cp == '.')
+					break;
+				/*
+				 * All-numeric, no dot at the end.
+				 * Fake up a hostent as if we'd actually
+				 * done a lookup.
+				 */
+				if (inet_pton(af, name,
+				    (char *)(void *)rs->host_addr) <= 0) {
+					h_errno = HOST_NOT_FOUND;
+					return NULL;
+				}
+				strncpy(rs->hostbuf, name, MAXDNAME);
+				rs->hostbuf[MAXDNAME] = '\0';
+				bp = rs->hostbuf + MAXDNAME;
+				ep = rs->hostbuf + sizeof rs->hostbuf;
+				rs->host.h_name = rs->hostbuf;
+				rs->host.h_aliases = rs->host_aliases;
+				rs->host_aliases[0] = NULL;
+				rs->h_addr_ptrs[0] = (char *)(void *)rs->host_addr;
+				rs->h_addr_ptrs[1] = NULL;
+				rs->host.h_addr_list = rs->h_addr_ptrs;
+				if (res->options & RES_USE_INET6)
+					map_v4v6_hostent(&rs->host, &bp, ep);
+				h_errno = NETDB_SUCCESS;
+				return &rs->host;
+			}
+			if (!isdigit((u_char) *cp) && *cp != '.')
+				break;
+		}
+	if ((isxdigit((u_char) name[0]) && strchr(name, ':') != NULL) ||
+	    name[0] == ':')
+		for (cp = name;; ++cp) {
+			if (!*cp) {
+				if (*--cp == '.')
+					break;
+				/*
+				 * All-IPv6-legal, no dot at the end.
+				 * Fake up a hostent as if we'd actually
+				 * done a lookup.
+				 */
+				if (inet_pton(af, name,
+				    (char *)(void *)rs->host_addr) <= 0) {
+					h_errno = HOST_NOT_FOUND;
+					return NULL;
+				}
+				strncpy(rs->hostbuf, name, MAXDNAME);
+				rs->hostbuf[MAXDNAME] = '\0';
+				bp = rs->hostbuf + MAXDNAME;
+				ep = rs->hostbuf + sizeof rs->hostbuf;
+				rs->host.h_name = rs->hostbuf;
+				rs->host.h_aliases = rs->host_aliases;
+				rs->host_aliases[0] = NULL;
+				rs->h_addr_ptrs[0] = (char *)(void *)rs->host_addr;
+				rs->h_addr_ptrs[1] = NULL;
+				rs->host.h_addr_list = rs->h_addr_ptrs;
+				h_errno = NETDB_SUCCESS;
+				return &rs->host;
+			}
+			if (!isxdigit((u_char) *cp) && *cp != ':' && *cp != '.')
+				break;
+		}
+
+	hp = NULL;
+	h_errno = NETDB_INTERNAL;
+	if (nsdispatch(&hp, dtab, NSDB_HOSTS, "gethostbyname",
+	    default_dns_files, name, strlen(name), af) != NS_SUCCESS) {
+		return NULL;
+	}
+	h_errno = NETDB_SUCCESS;
+	return hp;
+}
+
+
+// very similar in proxy-ness to android_getaddrinfo_proxy
+static struct hostent *
+gethostbyname_internal(const char *name, int af, res_state res, unsigned netid, unsigned mark)
+{
+	const char *cache_mode = getenv("ANDROID_DNS_MODE");
+	FILE* proxy = NULL;
+	struct hostent *result = NULL;
+
+	if (cache_mode != NULL && strcmp(cache_mode, "local") == 0) {
+		res_setnetid(res, netid);
+		res_setmark(res, mark);
+		return gethostbyname_internal_real(name, af, res);
+	}
+
+	proxy = android_open_proxy();
+	if (proxy == NULL) goto exit;
+
+	netid = __netdClientDispatch.netIdForResolv(netid);
+
+	/* This is writing to system/netd/server/DnsProxyListener.cpp and changes
+	 * here need to be matched there */
+	if (fprintf(proxy, "gethostbyname %u %s %d",
+			netid,
+			name == NULL ? "^" : name,
+			af) < 0) {
+		goto exit;
+	}
+
+	if (fputc(0, proxy) == EOF || fflush(proxy) != 0) {
+		goto exit;
+	}
+
+	result = android_read_hostent(proxy);
+
+exit:
+	if (proxy != NULL) {
+		fclose(proxy);
+	}
+	return result;
+}
+
+
+struct hostent *
+android_gethostbyaddrfornet_proxy(const void *addr,
+    socklen_t len, int af, unsigned netid)
+{
+	struct hostent *result = NULL;
+	FILE* proxy = android_open_proxy();
+
+	if (proxy == NULL) goto exit;
+
+	char buf[INET6_ADDRSTRLEN];  //big enough for IPv4 and IPv6
+	const char * addrStr = inet_ntop(af, addr, buf, sizeof(buf));
+	if (addrStr == NULL) goto exit;
+
+	netid = __netdClientDispatch.netIdForResolv(netid);
+
+	if (fprintf(proxy, "gethostbyaddr %s %d %d %u",
+			addrStr, len, af, netid) < 0) {
+		goto exit;
+	}
+
+	if (fputc(0, proxy) == EOF || fflush(proxy) != 0) {
+		goto exit;
+	}
+
+	result = android_read_hostent(proxy);
+exit:
+	if (proxy != NULL) {
+		fclose(proxy);
+	}
+	return result;
+}
+
+struct hostent *
+android_gethostbyaddrfornet_real(const void *addr,
+    socklen_t len, int af, unsigned netid, unsigned mark)
+{
+	const u_char *uaddr = (const u_char *)addr;
+	socklen_t size;
+	struct hostent *hp;
+	static const ns_dtab dtab[] = {
+		NS_FILES_CB(_gethtbyaddr, NULL)
+		{ NSSRC_DNS, _dns_gethtbyaddr, NULL },	/* force -DHESIOD */
+		{ 0, 0, 0 }
+	};
+
+	assert(addr != NULL);
+
+	if (af == AF_INET6 && len == NS_IN6ADDRSZ &&
+	    (IN6_IS_ADDR_LINKLOCAL((const struct in6_addr *)addr) ||
+	     IN6_IS_ADDR_SITELOCAL((const struct in6_addr *)addr))) {
+		h_errno = HOST_NOT_FOUND;
+		return NULL;
+	}
+	if (af == AF_INET6 && len == NS_IN6ADDRSZ &&
+	    (IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)addr) ||
+	     IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)addr))) {
+		/* Unmap. */
+		uaddr += NS_IN6ADDRSZ - NS_INADDRSZ;
+		addr = uaddr;
+		af = AF_INET;
+		len = NS_INADDRSZ;
+	}
+	switch (af) {
+	case AF_INET:
+		size = NS_INADDRSZ;
+		break;
+	case AF_INET6:
+		size = NS_IN6ADDRSZ;
+		break;
+	default:
+		errno = EAFNOSUPPORT;
+		h_errno = NETDB_INTERNAL;
+		return NULL;
+	}
+	if (size != len) {
+		errno = EINVAL;
+		h_errno = NETDB_INTERNAL;
+		return NULL;
+	}
+	hp = NULL;
+	h_errno = NETDB_INTERNAL;
+	if (nsdispatch(&hp, dtab, NSDB_HOSTS, "gethostbyaddr",
+		default_dns_files, uaddr, len, af, netid, mark) != NS_SUCCESS)
+		return NULL;
+	h_errno = NETDB_SUCCESS;
+	return hp;
+}
+
+struct hostent *
+android_gethostbyaddrfornet(const void *addr, socklen_t len, int af, unsigned netid, unsigned mark)
+{
+	const char *cache_mode = getenv("ANDROID_DNS_MODE");
+
+	if (cache_mode == NULL || strcmp(cache_mode, "local") != 0) {
+		return android_gethostbyaddrfornet_proxy(addr, len, af, netid);
+	} else {
+		return android_gethostbyaddrfornet_real(addr,len, af, netid, mark);
+	}
+}
+
+struct hostent *
+gethostbyaddr(const void *addr, socklen_t len, int af)
+{
+	return android_gethostbyaddrfornet(addr, len, af, NETID_UNSET, MARK_UNSET);
+}
+
+
+static void
+_sethtent(int f)
+{
+    res_static  rs = __res_get_static();
+    if (rs == NULL) return;
+	if (!rs->hostf)
+		rs->hostf = fopen(_PATH_HOSTS, "r" );
+	else
+		rewind(rs->hostf);
+	rs->stayopen = f;
+}
+
+static void
+_endhtent(void)
+{
+    res_static  rs = __res_get_static();
+    if (rs == NULL) return;
+
+	if (rs->hostf && !rs->stayopen) {
+		(void) fclose(rs->hostf);
+		rs->hostf = NULL;
+	}
+}
+
+static struct hostent *
+_gethtent(void)
+{
+	char *p;
+	char *cp, **q;
+	int af, len;
+	res_static  rs = __res_get_static();
+
+	if (!rs->hostf && !(rs->hostf = fopen(_PATH_HOSTS, "r" ))) {
+		h_errno = NETDB_INTERNAL;
+		return NULL;
+	}
+ again:
+	if (!(p = fgets(rs->hostbuf, sizeof rs->hostbuf, rs->hostf))) {
+		h_errno = HOST_NOT_FOUND;
+		return NULL;
+	}
+	if (*p == '#')
+		goto again;
+	if (!(cp = strpbrk(p, "#\n")))
+		goto again;
+	*cp = '\0';
+	if (!(cp = strpbrk(p, " \t")))
+		goto again;
+	*cp++ = '\0';
+	if (inet_pton(AF_INET6, p, (char *)(void *)rs->host_addr) > 0) {
+		af = AF_INET6;
+		len = IN6ADDRSZ;
+	} else if (inet_pton(AF_INET, p, (char *)(void *)rs->host_addr) > 0) {
+		res_state res = __res_get_state();
+		if (res == NULL)
+			return NULL;
+		if (res->options & RES_USE_INET6) {
+			map_v4v6_address((char *)(void *)rs->host_addr,
+			    (char *)(void *)rs->host_addr);
+			af = AF_INET6;
+			len = IN6ADDRSZ;
+		} else {
+			af = AF_INET;
+			len = INADDRSZ;
+		}
+		__res_put_state(res);
+	} else {
+		goto again;
+	}
+	/* if this is not something we're looking for, skip it. */
+	if (rs->host.h_addrtype != 0 && rs->host.h_addrtype != af)
+		goto again;
+	if (rs->host.h_length != 0 && rs->host.h_length != len)
+		goto again;
+	rs->h_addr_ptrs[0] = (char *)(void *)rs->host_addr;
+	rs->h_addr_ptrs[1] = NULL;
+	rs->host.h_addr_list = rs->h_addr_ptrs;
+	rs->host.h_length = len;
+	rs->host.h_addrtype = af;
+	while (*cp == ' ' || *cp == '\t')
+		cp++;
+	rs->host.h_name = cp;
+	q = rs->host.h_aliases = rs->host_aliases;
+	if ((cp = strpbrk(cp, " \t")) != NULL)
+		*cp++ = '\0';
+	while (cp && *cp) {
+		if (*cp == ' ' || *cp == '\t') {
+			cp++;
+			continue;
+		}
+		if (q < &rs->host_aliases[MAXALIASES - 1])
+			*q++ = cp;
+		if ((cp = strpbrk(cp, " \t")) != NULL)
+			*cp++ = '\0';
+	}
+	*q = NULL;
+	h_errno = NETDB_SUCCESS;
+	return &rs->host;
+}
+
+/*ARGSUSED*/
+int
+_gethtbyname(void *rv, void *cb_data, va_list ap)
+{
+	struct hostent *hp;
+	const char *name;
+	int af;
+
+	assert(rv != NULL);
+
+	name = va_arg(ap, char *);
+	/* NOSTRICT skip len */(void)va_arg(ap, int);
+	af = va_arg(ap, int);
+
+	hp = NULL;
+#if 0
+	{
+		res_state res = __res_get_state();
+		if (res == NULL)
+			return NS_NOTFOUND;
+		if (res->options & RES_USE_INET6)
+			hp = _gethtbyname2(name, AF_INET6);
+		if (hp==NULL)
+			hp = _gethtbyname2(name, AF_INET);
+		__res_put_state(res);
+	}
+#else
+	hp = _gethtbyname2(name, af);
+#endif
+	*((struct hostent **)rv) = hp;
+	if (hp == NULL) {
+		h_errno = HOST_NOT_FOUND;
+		return NS_NOTFOUND;
+	}
+	return NS_SUCCESS;
+}
+
+static struct hostent *
+_gethtbyname2(const char *name, int af)
+{
+	struct hostent *p;
+	char *tmpbuf, *ptr, **cp;
+	int num;
+	size_t len;
+	res_static rs = __res_get_static();
+
+	assert(name != NULL);
+
+	_sethtent(rs->stayopen);
+	ptr = tmpbuf = NULL;
+	num = 0;
+	while ((p = _gethtent()) != NULL && num < MAXADDRS) {
+		if (p->h_addrtype != af)
+			continue;
+		if (strcasecmp(p->h_name, name) != 0) {
+			for (cp = p->h_aliases; *cp != NULL; cp++)
+				if (strcasecmp(*cp, name) == 0)
+					break;
+			if (*cp == NULL) continue;
+		}
+
+		if (num == 0) {
+			size_t bufsize;
+			char *src;
+
+			bufsize = strlen(p->h_name) + 2 +
+				  MAXADDRS * p->h_length +
+				  ALIGNBYTES;
+			for (cp = p->h_aliases; *cp != NULL; cp++)
+				bufsize += strlen(*cp) + 1;
+
+			if ((tmpbuf = malloc(bufsize)) == NULL) {
+				h_errno = NETDB_INTERNAL;
+				return NULL;
+			}
+
+			ptr = tmpbuf;
+			src = p->h_name;
+			while ((*ptr++ = *src++) != '\0');
+			for (cp = p->h_aliases; *cp != NULL; cp++) {
+				src = *cp;
+				while ((*ptr++ = *src++) != '\0');
+			}
+			*ptr++ = '\0';
+
+			ptr = (char *)(void *)ALIGN(ptr);
+		}
+
+		(void)memcpy(ptr, p->h_addr_list[0], (size_t)p->h_length);
+		ptr += p->h_length;
+		num++;
+	}
+	_endhtent();
+	if (num == 0) return NULL;
+
+	len = ptr - tmpbuf;
+	if (len > (sizeof(rs->hostbuf) - ALIGNBYTES)) {
+		free(tmpbuf);
+		errno = ENOSPC;
+		h_errno = NETDB_INTERNAL;
+		return NULL;
+	}
+	ptr = memcpy((void *)ALIGN(rs->hostbuf), tmpbuf, len);
+	free(tmpbuf);
+
+	rs->host.h_name = ptr;
+	while (*ptr++);
+
+	cp = rs->host_aliases;
+	while (*ptr) {
+		*cp++ = ptr;
+		while (*ptr++);
+	}
+	ptr++;
+	*cp = NULL;
+
+	ptr = (char *)(void *)ALIGN(ptr);
+	cp = rs->h_addr_ptrs;
+	while (num--) {
+		*cp++ = ptr;
+		ptr += rs->host.h_length;
+	}
+	*cp = NULL;
+
+	return &rs->host;
+}
+
+/*ARGSUSED*/
+static int
+_gethtbyaddr(void *rv, void *cb_data, va_list ap)
+{
+	struct hostent *p;
+	const unsigned char *addr;
+	int len, af;
+	res_static  rs = __res_get_static();
+
+	assert(rv != NULL);
+
+	addr = va_arg(ap, unsigned char *);
+	len = va_arg(ap, int);
+	af = va_arg(ap, int);
+
+	rs->host.h_length = len;
+	rs->host.h_addrtype = af;
+
+	_sethtent(rs->stayopen);
+	while ((p = _gethtent()) != NULL)
+		if (p->h_addrtype == af && !memcmp(p->h_addr, addr,
+		    (size_t)len))
+			break;
+	_endhtent();
+	*((struct hostent **)rv) = p;
+	if (p==NULL) {
+		h_errno = HOST_NOT_FOUND;
+		return NS_NOTFOUND;
+	}
+	return NS_SUCCESS;
+}
+
+static void
+map_v4v6_address(const char *src, char *dst)
+{
+	u_char *p = (u_char *)dst;
+	char tmp[INADDRSZ];
+	int i;
+
+	assert(src != NULL);
+	assert(dst != NULL);
+
+	/* Stash a temporary copy so our caller can update in place. */
+	(void)memcpy(tmp, src, INADDRSZ);
+	/* Mark this ipv6 addr as a mapped ipv4. */
+	for (i = 0; i < 10; i++)
+		*p++ = 0x00;
+	*p++ = 0xff;
+	*p++ = 0xff;
+	/* Retrieve the saved copy and we're done. */
+	(void)memcpy((void *)p, tmp, INADDRSZ);
+}
+
+static void
+map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep)
+{
+	char **ap;
+
+	assert(hp != NULL);
+	assert(bpp != NULL);
+	assert(ep != NULL);
+
+	if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
+		return;
+	hp->h_addrtype = AF_INET6;
+	hp->h_length = IN6ADDRSZ;
+	for (ap = hp->h_addr_list; *ap; ap++) {
+		int i = sizeof(align) - (size_t)((u_long)*bpp % sizeof(align));
+
+		if (ep - *bpp < (i + IN6ADDRSZ)) {
+			/* Out of memory.  Truncate address list here.  XXX */
+			*ap = NULL;
+			return;
+		}
+		*bpp += i;
+		map_v4v6_address(*ap, *bpp);
+		*ap = *bpp;
+		*bpp += IN6ADDRSZ;
+	}
+}
+
+static void
+addrsort(char **ap, int num, res_state res)
+{
+	int i, j;
+	char **p;
+	short aval[MAXADDRS];
+	int needsort = 0;
+
+	assert(ap != NULL);
+
+	p = ap;
+	for (i = 0; i < num; i++, p++) {
+	    for (j = 0 ; (unsigned)j < res->nsort; j++)
+		if (res->sort_list[j].addr.s_addr ==
+		    (((struct in_addr *)(void *)(*p))->s_addr &
+		    res->sort_list[j].mask))
+			break;
+	    aval[i] = j;
+	    if (needsort == 0 && i > 0 && j < aval[i-1])
+		needsort = i;
+	}
+	if (!needsort)
+	    return;
+
+	while (needsort < num) {
+	    for (j = needsort - 1; j >= 0; j--) {
+		if (aval[j] > aval[j+1]) {
+		    char *hp;
+
+		    i = aval[j];
+		    aval[j] = aval[j+1];
+		    aval[j+1] = i;
+
+		    hp = ap[j];
+		    ap[j] = ap[j+1];
+		    ap[j+1] = hp;
+		} else
+		    break;
+	    }
+	    needsort++;
+	}
+}
+
+struct hostent *
+gethostent(void)
+{
+    res_static  rs = __res_get_static();
+	rs->host.h_addrtype = 0;
+	rs->host.h_length = 0;
+	return _gethtent();
+}
+
+/*ARGSUSED*/
+static int
+_dns_gethtbyname(void *rv, void *cb_data, va_list ap)
+{
+	querybuf *buf;
+	int n, type;
+	struct hostent *hp;
+	const char *name;
+	int af;
+	res_state res;
+
+	assert(rv != NULL);
+
+	name = va_arg(ap, char *);
+	/* NOSTRICT skip len */(void)va_arg(ap, int);
+	af = va_arg(ap, int);
+
+	switch (af) {
+	case AF_INET:
+		type = T_A;
+		break;
+	case AF_INET6:
+		type = T_AAAA;
+		break;
+	default:
+		return NS_UNAVAIL;
+	}
+	buf = malloc(sizeof(*buf));
+	if (buf == NULL) {
+		h_errno = NETDB_INTERNAL;
+		return NS_NOTFOUND;
+	}
+	res = __res_get_state();
+	if (res == NULL) {
+		free(buf);
+		return NS_NOTFOUND;
+	}
+	n = res_nsearch(res, name, C_IN, type, buf->buf, sizeof(buf->buf));
+	if (n < 0) {
+		free(buf);
+		dprintf("res_nsearch failed (%d)\n", res, n);
+		__res_put_state(res);
+		return NS_NOTFOUND;
+	}
+	hp = getanswer(buf, n, name, type, res);
+	free(buf);
+	__res_put_state(res);
+	if (hp == NULL)
+		switch (h_errno) {
+		case HOST_NOT_FOUND:
+			return NS_NOTFOUND;
+		case TRY_AGAIN:
+			return NS_TRYAGAIN;
+		default:
+			return NS_UNAVAIL;
+		}
+	*((struct hostent **)rv) = hp;
+	return NS_SUCCESS;
+}
+
+/*ARGSUSED*/
+static int
+_dns_gethtbyaddr(void *rv, void	*cb_data, va_list ap)
+{
+	char qbuf[MAXDNAME + 1], *qp, *ep;
+	int n;
+	querybuf *buf;
+	struct hostent *hp;
+	const unsigned char *uaddr;
+	int len, af, advance;
+	res_state res;
+	unsigned netid, mark;
+	res_static rs = __res_get_static();
+
+	assert(rv != NULL);
+
+	uaddr = va_arg(ap, unsigned char *);
+	len = va_arg(ap, int);
+	af = va_arg(ap, int);
+	netid = va_arg(ap, unsigned);
+	mark = va_arg(ap, unsigned);
+
+	switch (af) {
+	case AF_INET:
+		(void)snprintf(qbuf, sizeof(qbuf), "%u.%u.%u.%u.in-addr.arpa",
+		    (uaddr[3] & 0xff), (uaddr[2] & 0xff),
+		    (uaddr[1] & 0xff), (uaddr[0] & 0xff));
+		break;
+
+	case AF_INET6:
+		qp = qbuf;
+		ep = qbuf + sizeof(qbuf) - 1;
+		for (n = IN6ADDRSZ - 1; n >= 0; n--) {
+			advance = snprintf(qp, (size_t)(ep - qp), "%x.%x.",
+			    uaddr[n] & 0xf,
+			    ((unsigned int)uaddr[n] >> 4) & 0xf);
+			if (advance > 0 && qp + advance < ep)
+				qp += advance;
+			else {
+				h_errno = NETDB_INTERNAL;
+				return NS_NOTFOUND;
+			}
+		}
+		if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) {
+			h_errno = NETDB_INTERNAL;
+			return NS_NOTFOUND;
+		}
+		break;
+	default:
+		abort();
+	}
+
+	buf = malloc(sizeof(*buf));
+	if (buf == NULL) {
+		h_errno = NETDB_INTERNAL;
+		return NS_NOTFOUND;
+	}
+	res = __res_get_state();
+	if (res == NULL) {
+		free(buf);
+		return NS_NOTFOUND;
+	}
+	res_setnetid(res, netid);
+	res_setmark(res, mark);
+	n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf));
+	if (n < 0) {
+		free(buf);
+		dprintf("res_nquery failed (%d)\n", res, n);
+		__res_put_state(res);
+		return NS_NOTFOUND;
+	}
+	hp = getanswer(buf, n, qbuf, T_PTR, res);
+	free(buf);
+	if (hp == NULL) {
+		__res_put_state(res);
+		switch (h_errno) {
+		case HOST_NOT_FOUND:
+			return NS_NOTFOUND;
+		case TRY_AGAIN:
+			return NS_TRYAGAIN;
+		default:
+			return NS_UNAVAIL;
+		}
+	}
+	hp->h_addrtype = af;
+	hp->h_length = len;
+	(void)memcpy(rs->host_addr, uaddr, (size_t)len);
+	rs->h_addr_ptrs[0] = (char *)(void *)rs->host_addr;
+	rs->h_addr_ptrs[1] = NULL;
+	if (af == AF_INET && (res->options & RES_USE_INET6)) {
+		map_v4v6_address((char *)(void *)rs->host_addr,
+		    (char *)(void *)rs->host_addr);
+		hp->h_addrtype = AF_INET6;
+		hp->h_length = IN6ADDRSZ;
+	}
+
+	__res_put_state(res);
+	*((struct hostent **)rv) = hp;
+	h_errno = NETDB_SUCCESS;
+	return NS_SUCCESS;
+}
diff --git a/libc/dns/include/resolv_cache.h b/libc/dns/include/resolv_cache.h
new file mode 100644
index 0000000..e049d95
--- /dev/null
+++ b/libc/dns/include/resolv_cache.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef _RESOLV_CACHE_H_
+#define _RESOLV_CACHE_H_
+
+#include <stddef.h>
+#include <sys/cdefs.h>
+
+struct __res_state;
+
+/* sets the name server addresses to the provided res_state structure. The
+ * name servers are retrieved from the cache which is associated
+ * with the network to which the res_state structure is associated */
+__LIBC_HIDDEN__
+extern void _resolv_populate_res_for_net(struct __res_state* statp);
+
+typedef enum {
+    RESOLV_CACHE_UNSUPPORTED,  /* the cache can't handle that kind of queries */
+                               /* or the answer buffer is too small */
+    RESOLV_CACHE_NOTFOUND,     /* the cache doesn't know about this query */
+    RESOLV_CACHE_FOUND         /* the cache found the answer */
+} ResolvCacheStatus;
+
+__LIBC_HIDDEN__
+extern ResolvCacheStatus
+_resolv_cache_lookup( unsigned              netid,
+                      const void*           query,
+                      int                   querylen,
+                      void*                 answer,
+                      int                   answersize,
+                      int                  *answerlen );
+
+/* add a (query,answer) to the cache, only call if _resolv_cache_lookup
+ * did return RESOLV_CACHE_NOTFOUND
+ */
+__LIBC_HIDDEN__
+extern void
+_resolv_cache_add( unsigned              netid,
+                   const void*           query,
+                   int                   querylen,
+                   const void*           answer,
+                   int                   answerlen );
+
+/* Notify the cache a request failed */
+__LIBC_HIDDEN__
+extern void
+_resolv_cache_query_failed( unsigned     netid,
+                   const void* query,
+                   int         querylen);
+
+#endif /* _RESOLV_CACHE_H_ */
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
new file mode 100644
index 0000000..e5521b8
--- /dev/null
+++ b/libc/dns/include/resolv_netid.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef _RESOLV_NETID_H
+#define _RESOLV_NETID_H
+
+/* This header contains declarations related to per-network DNS
+ * server selection. They are used by system/netd/ and should not be
+ * exposed by the C library's public NDK headers.
+ */
+#include <sys/cdefs.h>
+#include <netinet/in.h>
+
+/*
+ * Passing NETID_UNSET as the netId causes system/netd/server/DnsProxyListener.cpp to
+ * fill in the appropriate default netId for the query.
+ */
+#define NETID_UNSET 0u
+
+/*
+ * MARK_UNSET represents the default (i.e. unset) value for a socket mark.
+ */
+#define MARK_UNSET 0u
+
+__BEGIN_DECLS
+
+struct addrinfo;
+
+#define __used_in_netd __attribute__((visibility ("default")))
+
+struct hostent *android_gethostbyaddrfornet(const void *, socklen_t, int, unsigned, unsigned) __used_in_netd;
+struct hostent *android_gethostbynamefornet(const char *, int, unsigned, unsigned) __used_in_netd;
+int android_getaddrinfofornet(const char *, const char *, const struct addrinfo *, unsigned,
+		unsigned, struct addrinfo **) __used_in_netd;
+
+/* set name servers for a network */
+extern void _resolv_set_nameservers_for_net(unsigned netid,
+    const char** servers, int numservers, const char *domains) __used_in_netd;
+
+/* flush the cache associated with a certain network */
+extern void _resolv_flush_cache_for_net(unsigned netid) __used_in_netd;
+
+/* delete the cache associated with a certain network */
+extern void _resolv_delete_cache_for_net(unsigned netid) __used_in_netd;
+
+/* Internal use only. */
+struct hostent *android_gethostbyaddrfornet_proxy(const void *, socklen_t, int , unsigned);
+int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t,
+		 int, unsigned, unsigned);
+
+/* delete the cache associated with a certain network */
+extern void _resolv_delete_cache_for_net(unsigned netid);
+
+__END_DECLS
+
+#endif /* _RESOLV_NETID_H */
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
new file mode 100644
index 0000000..a91a4b8
--- /dev/null
+++ b/libc/dns/include/resolv_private.h
@@ -0,0 +1,515 @@
+/*	$NetBSD: resolv.h,v 1.31 2005/12/26 19:01:47 perry Exp $	*/
+
+/*
+ * Copyright (c) 1983, 1987, 1989
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+/*
+ *	@(#)resolv.h	8.1 (Berkeley) 6/2/93
+ *	Id: resolv.h,v 1.7.2.11.4.2 2004/06/25 00:41:05 marka Exp
+ */
+
+#ifndef _RESOLV_PRIVATE_H_
+#define	_RESOLV_PRIVATE_H_
+
+#include <sys/cdefs.h>
+
+#include <resolv.h>
+#include "resolv_static.h"
+#include <net/if.h>
+
+/* Despite this file's name, it's part of libresolv. On Android, that means it's part of libc :-( */
+#pragma GCC visibility push(default)
+
+/*
+ * Revision information.  This is the release date in YYYYMMDD format.
+ * It can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__RES > 19931104)".  Do not
+ * compare for equality; rather, use it to determine whether your resolver
+ * is new enough to contain a certain feature.
+ */
+
+#define	__RES	20030124
+
+/*
+ * This used to be defined in res_query.c, now it's in herror.c.
+ * [XXX no it's not.  It's in irs/irs_data.c]
+ * It was
+ * never extern'd by any *.h file before it was placed here.  For thread
+ * aware programs, the last h_errno value set is stored in res->h_errno.
+ *
+ * XXX:	There doesn't seem to be a good reason for exposing RES_SET_H_ERRNO
+ *	(and __h_errno_set) to the public via <resolv.h>.
+ * XXX:	__h_errno_set is really part of IRS, not part of the resolver.
+ *	If somebody wants to build and use a resolver that doesn't use IRS,
+ *	what do they do?  Perhaps something like
+ *		#ifdef WANT_IRS
+ *		# define RES_SET_H_ERRNO(r,x) __h_errno_set(r,x)
+ *		#else
+ *		# define RES_SET_H_ERRNO(r,x) (h_errno = (r)->res_h_errno = (x))
+ *		#endif
+ */
+
+#define RES_SET_H_ERRNO(r,x) (h_errno = (r)->res_h_errno = (x))
+struct __res_state; /* forward */
+
+/*
+ * Resolver configuration file.
+ * Normally not present, but may contain the address of the
+ * initial name server(s) to query and the domain search list.
+ */
+
+#ifndef _PATH_RESCONF
+#ifdef ANDROID_CHANGES
+#define _PATH_RESCONF        "/etc/ppp/resolv.conf"
+#else
+#define _PATH_RESCONF        "/etc/resolv.conf"
+#endif
+#endif
+
+typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
+	res_sendhookact;
+
+typedef res_sendhookact (*res_send_qhook)(struct sockaddr * const *,
+					      const u_char **, int *,
+					      u_char *, int, int *);
+
+typedef res_sendhookact (*res_send_rhook)(const struct sockaddr *,
+					      const u_char *, int, u_char *,
+					      int, int *);
+
+struct res_sym {
+	int		number;	   /* Identifying number, like T_MX */
+	const char *	name;	   /* Its symbolic name, like "MX" */
+	const char *	humanname; /* Its fun name, like "mail exchanger" */
+};
+
+/*
+ * Global defines and variables for resolver stub.
+ */
+#define	MAXNS			3	/* max # name servers we'll track */
+#define	MAXDFLSRCH		3	/* # default domain levels to try */
+#define	MAXDNSRCH		6	/* max # domains in search path */
+#define	LOCALDOMAINPARTS	2	/* min levels in name that is "local" */
+
+#define	RES_TIMEOUT		5	/* min. seconds between retries */
+#define	MAXRESOLVSORT		10	/* number of net to sort on */
+#define	RES_MAXNDOTS		15	/* should reflect bit field size */
+#define	RES_MAXRETRANS		30	/* only for resolv.conf/RES_OPTIONS */
+#define	RES_MAXRETRY		5	/* only for resolv.conf/RES_OPTIONS */
+#define	RES_DFLRETRY		2	/* Default #/tries. */
+#define	RES_MAXTIME		65535	/* Infinity, in milliseconds. */
+
+struct __res_state_ext;
+
+struct __res_state {
+	unsigned	netid;			/* NetId: cache key and socket mark */
+	int	retrans;	 	/* retransmission time interval */
+	int	retry;			/* number of times to retransmit */
+#ifdef sun
+	u_int	options;		/* option flags - see below. */
+#else
+	u_long	options;		/* option flags - see below. */
+#endif
+	int	nscount;		/* number of name servers */
+	struct sockaddr_in
+		nsaddr_list[MAXNS];	/* address of name server */
+#define	nsaddr	nsaddr_list[0]		/* for backward compatibility */
+	u_short	id;			/* current message id */
+	char	*dnsrch[MAXDNSRCH+1];	/* components of domain to search */
+	char	defdname[256];		/* default domain (deprecated) */
+#ifdef sun
+	u_int	pfcode;			/* RES_PRF_ flags - see below. */
+#else
+	u_long	pfcode;			/* RES_PRF_ flags - see below. */
+#endif
+	unsigned ndots:4;		/* threshold for initial abs. query */
+	unsigned nsort:4;		/* number of elements in sort_list[] */
+	char	unused[3];
+	struct {
+		struct in_addr	addr;
+		uint32_t	mask;
+	} sort_list[MAXRESOLVSORT];
+#ifdef __OLD_RES_STATE
+	char lookups[4];
+#else
+	res_send_qhook qhook;		/* query hook */
+	res_send_rhook rhook;		/* response hook */
+	int	res_h_errno;		/* last one set for this context */
+	unsigned _mark;			/* If non-0 SET_MARK to _mark on all request sockets */
+	int	_vcsock;		/* PRIVATE: for res_send VC i/o */
+	u_int	_flags;			/* PRIVATE: see below */
+	u_int	_pad;			/* make _u 64 bit aligned */
+	union {
+		/* On an 32-bit arch this means 512b total. */
+		char	pad[72 - 4*sizeof (int) - 2*sizeof (void *)];
+		struct {
+			uint16_t		nscount;
+			uint16_t		nstimes[MAXNS];	/* ms. */
+			int			nssocks[MAXNS];
+			struct __res_state_ext *ext;	/* extention for IPv6 */
+		} _ext;
+	} _u;
+#endif
+        struct res_static   rstatic[1];
+};
+
+typedef struct __res_state *res_state;
+
+union res_sockaddr_union {
+	struct sockaddr_in	sin;
+#ifdef IN6ADDR_ANY_INIT
+	struct sockaddr_in6	sin6;
+#endif
+#ifdef ISC_ALIGN64
+	int64_t			__align64;	/* 64bit alignment */
+#else
+	int32_t			__align32;	/* 32bit alignment */
+#endif
+	char			__space[128];   /* max size */
+};
+
+/*
+ * Resolver flags (used to be discrete per-module statics ints).
+ */
+#define	RES_F_VC	0x00000001	/* socket is TCP */
+#define	RES_F_CONN	0x00000002	/* socket is connected */
+#define	RES_F_EDNS0ERR	0x00000004	/* EDNS0 caused errors */
+#define	RES_F__UNUSED	0x00000008	/* (unused) */
+#define	RES_F_LASTMASK	0x000000F0	/* ordinal server of last res_nsend */
+#define	RES_F_LASTSHIFT	4		/* bit position of LASTMASK "flag" */
+#define	RES_GETLAST(res) (((res)._flags & RES_F_LASTMASK) >> RES_F_LASTSHIFT)
+
+/* res_findzonecut2() options */
+#define	RES_EXHAUSTIVE	0x00000001	/* always do all queries */
+#define	RES_IPV4ONLY	0x00000002	/* IPv4 only */
+#define	RES_IPV6ONLY	0x00000004	/* IPv6 only */
+
+/*
+ * Resolver options (keep these in synch with res_debug.c, please)
+ */
+#define RES_INIT	0x00000001	/* address initialized */
+#define RES_DEBUG	0x00000002	/* print debug messages */
+#define RES_AAONLY	0x00000004	/* authoritative answers only (!IMPL)*/
+#define RES_USEVC	0x00000008	/* use virtual circuit */
+#define RES_PRIMARY	0x00000010	/* query primary server only (!IMPL) */
+#define RES_IGNTC	0x00000020	/* ignore trucation errors */
+#define RES_RECURSE	0x00000040	/* recursion desired */
+#define RES_DEFNAMES	0x00000080	/* use default domain name */
+#define RES_STAYOPEN	0x00000100	/* Keep TCP socket open */
+#define RES_DNSRCH	0x00000200	/* search up local domain tree */
+#define	RES_INSECURE1	0x00000400	/* type 1 security disabled */
+#define	RES_INSECURE2	0x00000800	/* type 2 security disabled */
+#define	RES_NOALIASES	0x00001000	/* shuts off HOSTALIASES feature */
+#define	RES_USE_INET6	0x00002000	/* use/map IPv6 in gethostbyname() */
+#define RES_ROTATE	0x00004000	/* rotate ns list after each query */
+#define	RES_NOCHECKNAME	0x00008000	/* do not check names for sanity. */
+#define	RES_KEEPTSIG	0x00010000	/* do not strip TSIG records */
+#define	RES_BLAST	0x00020000	/* blast all recursive servers */
+#define RES_NOTLDQUERY	0x00100000	/* don't unqualified name as a tld */
+#define RES_USE_DNSSEC	0x00200000	/* use DNSSEC using OK bit in OPT */
+/* #define RES_DEBUG2	0x00400000 */	/* nslookup internal */
+/* KAME extensions: use higher bit to avoid conflict with ISC use */
+#define RES_USE_DNAME	0x10000000	/* use DNAME */
+#define RES_USE_EDNS0	0x40000000	/* use EDNS0 if configured */
+#define RES_NO_NIBBLE2	0x80000000	/* disable alternate nibble lookup */
+
+#define RES_DEFAULT	(RES_RECURSE | RES_DEFNAMES | \
+			 RES_DNSRCH | RES_NO_NIBBLE2)
+
+/*
+ * Resolver "pfcode" values.  Used by dig.
+ */
+#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
+#define RES_PRF_TRUNC	0x00008000
+/*			0x00010000	*/
+
+/* Things involving an internal (static) resolver context. */
+__BEGIN_DECLS
+
+__LIBC_HIDDEN__ extern struct __res_state *__res_get_state(void);
+__LIBC_HIDDEN__ extern void __res_put_state(struct __res_state *);
+
+#ifndef ANDROID_CHANGES
+/*
+ * Source and Binary compatibility; _res will not work properly
+ * with multi-threaded programs.
+ */
+extern struct __res_state *__res_state(void);
+#define _res (*__res_state())
+#endif
+
+__END_DECLS
+
+#ifndef __BIND_NOSTATIC
+#define fp_nquery		__fp_nquery
+#define fp_query		__fp_query
+#define hostalias		__hostalias
+#define p_query			__p_query
+#define res_close		__res_close
+#define res_opt			__res_opt
+#define res_isourserver		__res_isourserver
+#define	res_querydomain		__res_querydomain
+#define res_send		__res_send
+#define res_sendsigned		__res_sendsigned
+
+#ifdef BIND_RES_POSIX3
+#define	dn_expand	__dn_expand
+#define	res_init	__res_init
+#define	res_query	__res_query
+#define	res_search	__res_search
+#define	res_mkquery	__res_mkquery
+#endif
+
+__BEGIN_DECLS
+void		fp_nquery(const u_char *, int, FILE *);
+void		fp_query(const u_char *, FILE *);
+const char *	hostalias(const char *);
+void		p_query(const u_char *);
+void		res_close(void);
+int		res_init(void);
+__LIBC_HIDDEN__ int		res_opt(int, u_char *, int, int);
+int		res_isourserver(const struct sockaddr_in *);
+int		res_mkquery(int, const char *, int, int, const u_char *, int, const u_char *, u_char *, int);
+int		res_query(const char *, int, int, u_char *, int);
+int		res_querydomain(const char *, const char *, int, int, u_char *, int);
+int		res_search(const char *, int, int, u_char *, int);
+int		res_send(const u_char *, int, u_char *, int);
+int		res_sendsigned(const u_char *, int, ns_tsig_key *, u_char *, int);
+__END_DECLS
+#endif
+
+#if !defined(SHARED_LIBBIND) || defined(LIB)
+/*
+ * If libbind is a shared object (well, DLL anyway)
+ * these externs break the linker when resolv.h is
+ * included by a lib client (like named)
+ * Make them go away if a client is including this
+ *
+ */
+__LIBC_HIDDEN__ extern const struct res_sym __p_key_syms[];
+__LIBC_HIDDEN__ extern const struct res_sym __p_cert_syms[];
+extern const struct res_sym __p_class_syms[];
+extern const struct res_sym __p_type_syms[];
+__LIBC_HIDDEN__ extern const struct res_sym __p_rcode_syms[];
+#endif /* SHARED_LIBBIND */
+
+#ifndef ANDROID_CHANGES
+#define dn_comp			__dn_comp
+#endif
+#define dn_count_labels		__dn_count_labels
+#define dn_skipname		__dn_skipname
+#define fp_resstat		__fp_resstat
+#define loc_aton		__loc_aton
+#define loc_ntoa		__loc_ntoa
+#define p_cdname		__p_cdname
+#define p_cdnname		__p_cdnname
+#define p_class			__p_class
+#define p_fqname		__p_fqname
+#define p_fqnname		__p_fqnname
+#define p_option		__p_option
+#define p_secstodate		__p_secstodate
+#define p_section		__p_section
+#define p_time			__p_time
+#define p_type			__p_type
+#define p_rcode			__p_rcode
+#define p_sockun		__p_sockun
+#define putlong			__putlong
+#define putshort		__putshort
+#define res_dnok		__res_dnok
+#define res_findzonecut		__res_findzonecut
+#define res_findzonecut2	__res_findzonecut2
+#define res_hnok		__res_hnok
+#define res_hostalias		__res_hostalias
+#define res_mailok		__res_mailok
+#define res_nameinquery		__res_nameinquery
+#define res_nclose		__res_nclose
+#define res_ninit		__res_ninit
+#define res_nmkquery		__res_nmkquery
+#define res_pquery		__res_pquery
+#define res_nquery		__res_nquery
+#define res_nquerydomain	__res_nquerydomain
+#define res_nsearch		__res_nsearch
+#define res_nsend		__res_nsend
+#define res_nsendsigned		__res_nsendsigned
+#define res_nisourserver	__res_nisourserver
+#define res_ownok		__res_ownok
+#define res_queriesmatch	__res_queriesmatch
+#define res_randomid		__res_randomid
+#define sym_ntop		__sym_ntop
+#define sym_ntos		__sym_ntos
+#define sym_ston		__sym_ston
+#define res_nopt		__res_nopt
+#define res_ndestroy		__res_ndestroy
+#define	res_nametoclass		__res_nametoclass
+#define	res_nametotype		__res_nametotype
+#define	res_setservers		__res_setservers
+#define	res_getservers		__res_getservers
+#define	res_buildprotolist	__res_buildprotolist
+#define	res_destroyprotolist	__res_destroyprotolist
+#define	res_destroyservicelist	__res_destroyservicelist
+#define	res_get_nibblesuffix	__res_get_nibblesuffix
+#define	res_get_nibblesuffix2	__res_get_nibblesuffix2
+#define	res_ourserver_p		__res_ourserver_p
+#define	res_protocolname	__res_protocolname
+#define	res_protocolnumber	__res_protocolnumber
+#define	res_send_setqhook	__res_send_setqhook
+#define	res_send_setrhook	__res_send_setrhook
+#define	res_servicename		__res_servicename
+#define	res_servicenumber	__res_servicenumber
+__BEGIN_DECLS
+int		res_hnok(const char *);
+int		res_ownok(const char *);
+int		res_mailok(const char *);
+int		res_dnok(const char *);
+int		sym_ston(const struct res_sym *, const char *, int *);
+const char *	sym_ntos(const struct res_sym *, int, int *);
+const char *	sym_ntop(const struct res_sym *, int, int *);
+#ifndef ANDROID_CHANGES
+int		b64_ntop(u_char const *, size_t, char *, size_t);
+int		b64_pton(char const *, u_char *, size_t);
+#endif
+int		loc_aton(const char *, u_char *);
+const char *	loc_ntoa(const u_char *, char *);
+int		dn_skipname(const u_char *, const u_char *);
+void		putlong(uint32_t, u_char *);
+void		putshort(uint16_t, u_char *);
+#ifndef __ultrix__
+uint16_t	_getshort(const u_char *);
+uint32_t	_getlong(const u_char *);
+#endif
+const char *	p_class(int);
+const char *	p_time(uint32_t);
+const char *	p_type(int);
+const char *	p_rcode(int);
+__LIBC_HIDDEN__ const char *	p_sockun(union res_sockaddr_union, char *, size_t);
+const u_char *	p_cdnname(const u_char *, const u_char *, int, FILE *);
+const u_char *	p_cdname(const u_char *, const u_char *, FILE *);
+const u_char *	p_fqnname(const u_char *, const u_char *,
+			       int, char *, int);
+const u_char *	p_fqname(const u_char *, const u_char *, FILE *);
+const char *	p_option(u_long);
+char *		p_secstodate(u_long);
+int		dn_count_labels(const char *);
+u_int		res_randomid(void);
+int		res_nameinquery(const char *, int, int, const u_char *,
+				     const u_char *);
+int		res_queriesmatch(const u_char *, const u_char *,
+				      const u_char *, const u_char *);
+__LIBC_HIDDEN__ const char *	p_section(int, int);
+/* Things involving a resolver context. */
+int		res_ninit(res_state);
+int		res_nisourserver(const res_state, const struct sockaddr_in *);
+void		fp_resstat(const res_state, FILE *);
+__LIBC_HIDDEN__ void		res_pquery(const res_state, const u_char *, int, FILE *);
+const char *	res_hostalias(const res_state, const char *, char *, size_t);
+int		res_nquery(res_state, const char *, int, int, u_char *, int);
+int		res_nsearch(res_state, const char *, int, int, u_char *, int);
+int		res_nquerydomain(res_state, const char *, const char *,
+				      int, int, u_char *, int);
+int		res_nmkquery(res_state, int, const char *, int, int,
+				  const u_char *, int, const u_char *,
+				  u_char *, int);
+int		res_nsend(res_state, const u_char *, int, u_char *, int);
+int		res_nsendsigned(res_state, const u_char *, int,
+				     ns_tsig_key *, u_char *, int);
+int		res_findzonecut(res_state, const char *, ns_class, int,
+				     char *, size_t, struct in_addr *, int);
+int		res_findzonecut2(res_state, const char *, ns_class, int,
+				      char *, size_t,
+				      union res_sockaddr_union *, int);
+void		res_nclose(res_state);
+__LIBC_HIDDEN__ int		res_nopt(res_state, int, u_char *, int, int);
+void		res_send_setqhook(res_send_qhook);
+void		res_send_setrhook(res_send_rhook);
+__LIBC_HIDDEN__ int		__res_vinit(res_state, int);
+void		res_destroyservicelist(void);
+const char *	res_servicename(uint16_t, const char *);
+const char *	res_protocolname(int);
+void		res_destroyprotolist(void);
+void		res_buildprotolist(void);
+__LIBC_HIDDEN__ const char *	res_get_nibblesuffix(res_state);
+__LIBC_HIDDEN__ const char *	res_get_nibblesuffix2(res_state);
+__LIBC_HIDDEN__ void		res_ndestroy(res_state);
+__LIBC_HIDDEN__ uint16_t	res_nametoclass(const char *, int *);
+__LIBC_HIDDEN__ uint16_t	res_nametotype(const char *, int *);
+__LIBC_HIDDEN__ void		res_setservers(res_state,
+				    const union res_sockaddr_union *, int);
+__LIBC_HIDDEN__ int		res_getservers(res_state,
+				    union res_sockaddr_union *, int);
+
+__LIBC_HIDDEN__ void res_setnetid(res_state, unsigned);
+__LIBC_HIDDEN__ void res_setmark(res_state, unsigned);
+u_int  res_randomid(void);
+
+#ifdef __i386__
+# define __socketcall extern __attribute__((__cdecl__))
+#else
+# define __socketcall extern
+#endif
+
+__socketcall int __connect(int, const struct sockaddr*, socklen_t);
+
+#undef __socketcall
+
+__END_DECLS
+
+#pragma GCC visibility pop
+
+#endif /* !_RESOLV_PRIVATE_H_ */
diff --git a/libc/private/resolv_static.h b/libc/dns/include/resolv_static.h
similarity index 100%
rename from libc/private/resolv_static.h
rename to libc/dns/include/resolv_static.h
diff --git a/libc/dns/nameser/ns_name.c b/libc/dns/nameser/ns_name.c
new file mode 100644
index 0000000..e3759ab
--- /dev/null
+++ b/libc/dns/nameser/ns_name.c
@@ -0,0 +1,1175 @@
+/*	$NetBSD: ns_name.c,v 1.9 2012/03/13 21:13:39 christos Exp $	*/
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#ifdef notdef
+static const char rcsid[] = "Id: ns_name.c,v 1.11 2009/01/23 19:59:16 each Exp";
+#else
+__RCSID("$NetBSD: ns_name.c,v 1.9 2012/03/13 21:13:39 christos Exp $");
+#endif
+#endif
+
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+#include <assert.h>
+#include <errno.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) ((int)strlen(sprintf/**/x))
+#else
+# define SPRINTF(x) (sprintf x)
+#endif
+
+#define NS_TYPE_ELT			0x40 /* EDNS0 extended label type */
+#define DNS_LABELTYPE_BITSTRING		0x41
+
+/* Data. */
+
+static const char	digits[] = "0123456789";
+
+static const char digitvalue[256] = {
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,	/*16*/
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
+	 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1, /*64*/
+	-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
+	-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
+};
+
+/* Forward. */
+
+static int		special(int);
+static int		printable(int);
+static int		dn_find(const u_char *, const u_char *,
+				const u_char * const *,
+				const u_char * const *);
+static int		encode_bitsring(const char **, const char *,
+					unsigned char **, unsigned char **,
+					unsigned const char *);
+static int		labellen(const u_char *);
+static int		decode_bitstring(const unsigned char **,
+					 char *, const char *);
+
+/* Public. */
+
+/*
+ *	Convert an encoded domain name to printable ascii as per RFC1035.
+ * return:
+ *	Number of bytes written to buffer, or -1 (with errno set)
+ *
+ * notes:
+ *	The root is returned as "."
+ *	All other domains are returned in non absolute form
+ */
+int
+ns_name_ntop(const u_char *src, char *dst, size_t dstsiz)
+{
+	const u_char *cp;
+	char *dn, *eom;
+	u_char c;
+	u_int n;
+	int l;
+
+	cp = src;
+	dn = dst;
+	eom = dst + dstsiz;
+
+	while ((n = *cp++) != 0) {
+		if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
+			/* Some kind of compression pointer. */
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		if (dn != dst) {
+			if (dn >= eom) {
+				errno = EMSGSIZE;
+				return (-1);
+			}
+			*dn++ = '.';
+		}
+		if ((l = labellen(cp - 1)) < 0) {
+			errno = EMSGSIZE; /* XXX */
+			return(-1);
+		}
+		if (dn + l >= eom) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) {
+			int m;
+
+			if (n != DNS_LABELTYPE_BITSTRING) {
+				/* XXX: labellen should reject this case */
+				errno = EINVAL;
+				return(-1);
+			}
+			if ((m = decode_bitstring(&cp, dn, eom)) < 0)
+			{
+				errno = EMSGSIZE;
+				return(-1);
+			}
+			dn += m;
+			continue;
+		}
+		for (; l > 0; l--) {
+			c = *cp++;
+			if (special(c)) {
+				if (dn + 1 >= eom) {
+					errno = EMSGSIZE;
+					return (-1);
+				}
+				*dn++ = '\\';
+				*dn++ = (char)c;
+			} else if (!printable(c)) {
+				if (dn + 3 >= eom) {
+					errno = EMSGSIZE;
+					return (-1);
+				}
+				*dn++ = '\\';
+				*dn++ = digits[c / 100];
+				*dn++ = digits[(c % 100) / 10];
+				*dn++ = digits[c % 10];
+			} else {
+				if (dn >= eom) {
+					errno = EMSGSIZE;
+					return (-1);
+				}
+				*dn++ = (char)c;
+			}
+		}
+	}
+	if (dn == dst) {
+		if (dn >= eom) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		*dn++ = '.';
+	}
+	if (dn >= eom) {
+		errno = EMSGSIZE;
+		return (-1);
+	}
+	*dn++ = '\0';
+	_DIAGASSERT(__type_fit(int, dn - dst));
+	return (int)(dn - dst);
+}
+
+/*
+ *	Convert a ascii string into an encoded domain name as per RFC1035.
+ *
+ * return:
+ *
+ *	-1 if it fails
+ *	1 if string was fully qualified
+ *	0 is string was not fully qualified
+ *
+ * notes:
+ *	Enforces label and domain length limits.
+ */
+int
+ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
+	return (ns_name_pton2(src, dst, dstsiz, NULL));
+}
+
+/*
+ * ns_name_pton2(src, dst, dstsiz, *dstlen)
+ *	Convert a ascii string into an encoded domain name as per RFC1035.
+ * return:
+ *	-1 if it fails
+ *	1 if string was fully qualified
+ *	0 is string was not fully qualified
+ * side effects:
+ *	fills in *dstlen (if non-NULL)
+ * notes:
+ *	Enforces label and domain length limits.
+ */
+
+int
+ns_name_pton2(const char *src, u_char *dst, size_t dstsiz, size_t *dstlen) {
+	u_char *label, *bp, *eom;
+	int c, n, escaped, e = 0;
+	char *cp;
+
+	escaped = 0;
+	bp = dst;
+	eom = dst + dstsiz;
+	label = bp++;
+
+	while ((c = *src++) != 0) {
+		if (escaped) {
+			if (c == '[') { /* start a bit string label */
+				if ((cp = strchr(src, ']')) == NULL) {
+					errno = EINVAL; /* ??? */
+					return(-1);
+				}
+				if ((e = encode_bitsring(&src, cp + 2,
+							 &label, &bp, eom))
+				    != 0) {
+					errno = e;
+					return(-1);
+				}
+				escaped = 0;
+				label = bp++;
+				if ((c = *src++) == 0)
+					goto done;
+				else if (c != '.') {
+					errno = EINVAL;
+					return(-1);
+				}
+				continue;
+			}
+			else if ((cp = strchr(digits, c)) != NULL) {
+				n = (int)(cp - digits) * 100;
+				if ((c = *src++) == 0 ||
+				    (cp = strchr(digits, c)) == NULL) {
+					errno = EMSGSIZE;
+					return (-1);
+				}
+				n += (int)(cp - digits) * 10;
+				if ((c = *src++) == 0 ||
+				    (cp = strchr(digits, c)) == NULL) {
+					errno = EMSGSIZE;
+					return (-1);
+				}
+				n += (int)(cp - digits);
+				if (n > 255) {
+					errno = EMSGSIZE;
+					return (-1);
+				}
+				c = n;
+			}
+			escaped = 0;
+		} else if (c == '\\') {
+			escaped = 1;
+			continue;
+		} else if (c == '.') {
+			c = (int)(bp - label - 1);
+			if ((c & NS_CMPRSFLGS) != 0) {	/* Label too big. */
+				errno = EMSGSIZE;
+				return (-1);
+			}
+			if (label >= eom) {
+				errno = EMSGSIZE;
+				return (-1);
+			}
+			*label = c;
+			/* Fully qualified ? */
+			if (*src == '\0') {
+				if (c != 0) {
+					if (bp >= eom) {
+						errno = EMSGSIZE;
+						return (-1);
+					}
+					*bp++ = '\0';
+				}
+				if ((bp - dst) > MAXCDNAME) {
+					errno = EMSGSIZE;
+					return (-1);
+				}
+				if (dstlen != NULL)
+					*dstlen = (bp - dst);
+				return (1);
+			}
+			if (c == 0 || *src == '.') {
+				errno = EMSGSIZE;
+				return (-1);
+			}
+			label = bp++;
+			continue;
+		}
+		if (bp >= eom) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		*bp++ = (u_char)c;
+	}
+	c = (int)(bp - label - 1);
+	if ((c & NS_CMPRSFLGS) != 0) {		/* Label too big. */
+		errno = EMSGSIZE;
+		return (-1);
+	}
+  done:
+	if (label >= eom) {
+		errno = EMSGSIZE;
+		return (-1);
+	}
+	*label = c;
+	if (c != 0) {
+		if (bp >= eom) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		*bp++ = 0;
+	}
+	if ((bp - dst) > MAXCDNAME) {	/* src too big */
+		errno = EMSGSIZE;
+		return (-1);
+	}
+	if (dstlen != NULL)
+		*dstlen = (bp - dst);
+	return (0);
+}
+
+/*
+ *	Convert a network strings labels into all lowercase.
+ *
+ * return:
+ *	Number of bytes written to buffer, or -1 (with errno set)
+ *
+ * notes:
+ *	Enforces label and domain length limits.
+ */
+
+int
+ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz)
+{
+	const u_char *cp;
+	u_char *dn, *eom;
+	u_char c;
+	u_int n;
+	int l;
+
+	cp = src;
+	dn = dst;
+	eom = dst + dstsiz;
+
+	if (dn >= eom) {
+		errno = EMSGSIZE;
+		return (-1);
+	}
+	while ((n = *cp++) != 0) {
+		if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
+			/* Some kind of compression pointer. */
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		*dn++ = n;
+		if ((l = labellen(cp - 1)) < 0) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		if (dn + l >= eom) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		for (; l > 0; l--) {
+			c = *cp++;
+			if (isascii(c) && isupper(c))
+				*dn++ = tolower(c);
+			else
+				*dn++ = c;
+		}
+	}
+	*dn++ = '\0';
+	_DIAGASSERT(__type_fit(int, dn - dst));
+	return (int)(dn - dst);
+}
+
+/*
+ *	Unpack a domain name from a message, source may be compressed.
+ *
+ * return:
+ *	-1 if it fails, or consumed octets if it succeeds.
+ */
+int
+ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
+	       u_char *dst, size_t dstsiz)
+{
+	return (ns_name_unpack2(msg, eom, src, dst, dstsiz, NULL));
+}
+
+/*
+ * ns_name_unpack2(msg, eom, src, dst, dstsiz, *dstlen)
+ *	Unpack a domain name from a message, source may be compressed.
+ * return:
+ *	-1 if it fails, or consumed octets if it succeeds.
+ * side effect:
+ *	fills in *dstlen (if non-NULL).
+ */
+int
+ns_name_unpack2(const u_char *msg, const u_char *eom, const u_char *src,
+		u_char *dst, size_t dstsiz, size_t *dstlen)
+{
+	const u_char *srcp, *dstlim;
+	u_char *dstp;
+	int n, len, checked, l;
+
+	len = -1;
+	checked = 0;
+	dstp = dst;
+	srcp = src;
+	dstlim = dst + dstsiz;
+	if (srcp < msg || srcp >= eom) {
+		errno = EMSGSIZE;
+		return (-1);
+	}
+	/* Fetch next label in domain name. */
+	while ((n = *srcp++) != 0) {
+		/* Check for indirection. */
+		switch (n & NS_CMPRSFLGS) {
+		case 0:
+		case NS_TYPE_ELT:
+			/* Limit checks. */
+			if ((l = labellen(srcp - 1)) < 0) {
+				errno = EMSGSIZE;
+				return(-1);
+			}
+			if (dstp + l + 1 >= dstlim || srcp + l >= eom) {
+				errno = EMSGSIZE;
+				return (-1);
+			}
+			checked += l + 1;
+			*dstp++ = n;
+			memcpy(dstp, srcp, (size_t)l);
+			dstp += l;
+			srcp += l;
+			break;
+
+		case NS_CMPRSFLGS:
+			if (srcp >= eom) {
+				errno = EMSGSIZE;
+				return (-1);
+			}
+			if (len < 0) {
+				_DIAGASSERT(__type_fit(int, srcp - src + 1));
+				len = (int)(srcp - src + 1);
+			}
+			// BEGIN android-changed: safer pointer overflow check
+			l = (((n & 0x3f) << 8) | (*srcp & 0xff));
+			if (l >= eom - msg) {  /* Out of range. */
+				errno = EMSGSIZE;
+				return (-1);
+			}
+			srcp = msg + l;
+			// END android-changed
+			checked += 2;
+			/*
+			 * Check for loops in the compressed name;
+			 * if we've looked at the whole message,
+			 * there must be a loop.
+			 */
+			if (checked >= eom - msg) {
+				errno = EMSGSIZE;
+				return (-1);
+			}
+			break;
+
+		default:
+			errno = EMSGSIZE;
+			return (-1);			/* flag error */
+		}
+	}
+	*dstp++ = 0;
+	if (dstlen != NULL)
+		*dstlen = dstp - dst;
+	if (len < 0) {
+		_DIAGASSERT(__type_fit(int, srcp - src));
+		len = (int)(srcp - src);
+	}
+	return len;
+}
+
+/*
+ *	Pack domain name 'domain' into 'comp_dn'.
+ *
+ * return:
+ *	Size of the compressed name, or -1.
+ *
+ * notes:
+ *	'dnptrs' is an array of pointers to previous compressed names.
+ *	dnptrs[0] is a pointer to the beginning of the message. The array
+ *	ends with NULL.
+ *	'lastdnptr' is a pointer to the end of the array pointed to
+ *	by 'dnptrs'.
+ *
+ * Side effects:
+ *	The list of pointers in dnptrs is updated for labels inserted into
+ *	the message as we compress the name.  If 'dnptr' is NULL, we don't
+ *	try to compress names. If 'lastdnptr' is NULL, we don't update the
+ *	list.
+ */
+int
+ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
+	     const u_char **dnptrs, const u_char **lastdnptr)
+{
+	u_char *dstp;
+	const u_char **cpp, **lpp, *eob, *msg;
+	const u_char *srcp;
+	int n, l, first = 1;
+
+	srcp = src;
+	dstp = dst;
+	eob = dstp + dstsiz;
+	lpp = cpp = NULL;
+	if (dnptrs != NULL) {
+		if ((msg = *dnptrs++) != NULL) {
+			for (cpp = dnptrs; *cpp != NULL; cpp++)
+				continue;
+			lpp = cpp;	/* end of list to search */
+		}
+	} else
+		msg = NULL;
+
+	/* make sure the domain we are about to add is legal */
+	l = 0;
+	do {
+		int l0;
+
+		n = *srcp;
+		if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		if ((l0 = labellen(srcp)) < 0) {
+			errno = EINVAL;
+			return(-1);
+		}
+		l += l0 + 1;
+		if (l > MAXCDNAME) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		srcp += l0 + 1;
+	} while (n != 0);
+
+	/* from here on we need to reset compression pointer array on error */
+	srcp = src;
+	do {
+		/* Look to see if we can use pointers. */
+		n = *srcp;
+		if (n != 0 && msg != NULL) {
+			l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
+				    (const u_char * const *)lpp);
+			if (l >= 0) {
+				if (dstp + 1 >= eob) {
+					goto cleanup;
+				}
+				*dstp++ = ((u_int32_t)l >> 8) | NS_CMPRSFLGS;
+				*dstp++ = l % 256;
+				_DIAGASSERT(__type_fit(int, dstp - dst));
+				return (int)(dstp - dst);
+			}
+			/* Not found, save it. */
+			if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
+			    (dstp - msg) < 0x4000 && first) {
+				*cpp++ = dstp;
+				*cpp = NULL;
+				first = 0;
+			}
+		}
+		/* copy label to buffer */
+		if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
+			/* Should not happen. */
+			goto cleanup;
+		}
+		n = labellen(srcp);
+		if (dstp + 1 + n >= eob) {
+			goto cleanup;
+		}
+		memcpy(dstp, srcp, (size_t)(n + 1));
+		srcp += n + 1;
+		dstp += n + 1;
+	} while (n != 0);
+
+	if (dstp > eob) {
+cleanup:
+		if (msg != NULL)
+			*lpp = NULL;
+		errno = EMSGSIZE;
+		return (-1);
+	}
+	_DIAGASSERT(__type_fit(int, dstp - dst));
+	return (int)(dstp - dst);
+}
+
+/*
+ *	Expand compressed domain name to presentation format.
+ *
+ * return:
+ *	Number of bytes read out of `src', or -1 (with errno set).
+ *
+ * note:
+ *	Root domain returns as "." not "".
+ */
+int
+ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
+		   char *dst, size_t dstsiz)
+{
+	u_char tmp[NS_MAXCDNAME];
+	int n;
+
+	if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
+		return (-1);
+	if (ns_name_ntop(tmp, dst, dstsiz) == -1)
+		return (-1);
+	return (n);
+}
+
+/*
+ *	Compress a domain name into wire format, using compression pointers.
+ *
+ * return:
+ *	Number of bytes consumed in `dst' or -1 (with errno set).
+ *
+ * notes:
+ *	'dnptrs' is an array of pointers to previous compressed names.
+ *	dnptrs[0] is a pointer to the beginning of the message.
+ *	The list ends with NULL.  'lastdnptr' is a pointer to the end of the
+ *	array pointed to by 'dnptrs'. Side effect is to update the list of
+ *	pointers for labels inserted into the message as we compress the name.
+ *	If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
+ *	is NULL, we don't update the list.
+ */
+int
+ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
+		 const u_char **dnptrs, const u_char **lastdnptr)
+{
+	u_char tmp[NS_MAXCDNAME];
+
+	if (ns_name_pton(src, tmp, sizeof tmp) == -1)
+		return (-1);
+	return (ns_name_pack(tmp, dst, (int)dstsiz, dnptrs, lastdnptr));
+}
+
+/*
+ * Reset dnptrs so that there are no active references to pointers at or
+ * after src.
+ */
+void
+ns_name_rollback(const u_char *src, const u_char **dnptrs,
+		 const u_char **lastdnptr)
+{
+	while (dnptrs < lastdnptr && *dnptrs != NULL) {
+		if (*dnptrs >= src) {
+			*dnptrs = NULL;
+			break;
+		}
+		dnptrs++;
+	}
+}
+
+/*
+ *	Advance *ptrptr to skip over the compressed name it points at.
+ *
+ * return:
+ *	0 on success, -1 (with errno set) on failure.
+ */
+int
+ns_name_skip(const u_char **ptrptr, const u_char *eom)
+{
+	const u_char *cp;
+	u_int n;
+	int l;
+
+	cp = *ptrptr;
+	while (cp < eom && (n = *cp++) != 0) {
+		/* Check for indirection. */
+		switch (n & NS_CMPRSFLGS) {
+		case 0:			/* normal case, n == len */
+			cp += n;
+			continue;
+		case NS_TYPE_ELT: /* EDNS0 extended label */
+			if ((l = labellen(cp - 1)) < 0) {
+				errno = EMSGSIZE; /* XXX */
+				return(-1);
+			}
+			cp += l;
+			continue;
+		case NS_CMPRSFLGS:	/* indirection */
+			cp++;
+			break;
+		default:		/* illegal type */
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		break;
+	}
+	if (cp > eom) {
+		errno = EMSGSIZE;
+		return (-1);
+	}
+	*ptrptr = cp;
+	return (0);
+}
+
+/* Find the number of octets an nname takes up, including the root label.
+ * (This is basically ns_name_skip() without compression-pointer support.)
+ * ((NOTE: can only return zero if passed-in namesiz argument is zero.))
+ */
+ssize_t
+ns_name_length(ns_nname_ct nname, size_t namesiz) {
+	ns_nname_ct orig = nname;
+	u_int n;
+
+	while (namesiz-- > 0 && (n = *nname++) != 0) {
+		if ((n & NS_CMPRSFLGS) != 0) {
+			errno = EISDIR;
+			return (-1);
+		}
+		if (n > namesiz) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		nname += n;
+		namesiz -= n;
+	}
+	return (nname - orig);
+}
+
+/* Compare two nname's for equality.  Return -1 on error (setting errno).
+ */
+int
+ns_name_eq(ns_nname_ct a, size_t as, ns_nname_ct b, size_t bs) {
+	ns_nname_ct ae = a + as, be = b + bs;
+	int ac, bc;
+
+	while (ac = *a, bc = *b, ac != 0 && bc != 0) {
+		if ((ac & NS_CMPRSFLGS) != 0 || (bc & NS_CMPRSFLGS) != 0) {
+			errno = EISDIR;
+			return (-1);
+		}
+		if (a + ac >= ae || b + bc >= be) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		if (ac != bc || strncasecmp((const char *) ++a,
+					    (const char *) ++b,
+					    (size_t)ac) != 0)
+			return (0);
+		a += ac, b += bc;
+	}
+	return (ac == 0 && bc == 0);
+}
+
+/* Is domain "A" owned by (at or below) domain "B"?
+ */
+int
+ns_name_owned(ns_namemap_ct a, int an, ns_namemap_ct b, int bn) {
+	/* If A is shorter, it cannot be owned by B. */
+	if (an < bn)
+		return (0);
+
+	/* If they are unequal before the length of the shorter, A cannot... */
+	while (bn > 0) {
+		if (a->len != b->len ||
+		    strncasecmp((const char *) a->base,
+				(const char *) b->base, (size_t)a->len) != 0)
+			return (0);
+		a++, an--;
+		b++, bn--;
+	}
+
+	/* A might be longer or not, but either way, B owns it. */
+	return (1);
+}
+
+/* Build an array of <base,len> tuples from an nname, top-down order.
+ * Return the number of tuples (labels) thus discovered.
+ */
+int
+ns_name_map(ns_nname_ct nname, size_t namelen, ns_namemap_t map, int mapsize) {
+	u_int n;
+	int l;
+
+	n = *nname++;
+	namelen--;
+
+	/* Root zone? */
+	if (n == 0) {
+		/* Extra data follows name? */
+		if (namelen > 0) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		return (0);
+	}
+
+	/* Compression pointer? */
+	if ((n & NS_CMPRSFLGS) != 0) {
+		errno = EISDIR;
+		return (-1);
+	}
+
+	/* Label too long? */
+	if (n > namelen) {
+		errno = EMSGSIZE;
+		return (-1);
+	}
+
+	/* Recurse to get rest of name done first. */
+	l = ns_name_map(nname + n, namelen - n, map, mapsize);
+	if (l < 0)
+		return (-1);
+
+	/* Too many labels? */
+	if (l >= mapsize) {
+		errno = ENAMETOOLONG;
+		return (-1);
+	}
+
+	/* We're on our way back up-stack, store current map data. */
+	map[l].base = nname;
+	map[l].len = n;
+	return (l + 1);
+}
+
+/* Count the labels in a domain name.  Root counts, so COM. has two.  This
+ * is to make the result comparable to the result of ns_name_map().
+ */
+int
+ns_name_labels(ns_nname_ct nname, size_t namesiz) {
+	int ret = 0;
+	u_int n;
+
+	while (namesiz-- > 0 && (n = *nname++) != 0) {
+		if ((n & NS_CMPRSFLGS) != 0) {
+			errno = EISDIR;
+			return (-1);
+		}
+		if (n > namesiz) {
+			errno = EMSGSIZE;
+			return (-1);
+		}
+		nname += n;
+		namesiz -= n;
+		ret++;
+	}
+	return (ret + 1);
+}
+/* Private. */
+
+/*
+ *	Thinking in noninternationalized USASCII (per the DNS spec),
+ *	is this characted special ("in need of quoting") ?
+ *
+ * return:
+ *	boolean.
+ */
+static int
+special(int ch) {
+	switch (ch) {
+	case 0x22: /* '"' */
+	case 0x2E: /* '.' */
+	case 0x3B: /* ';' */
+	case 0x5C: /* '\\' */
+	case 0x28: /* '(' */
+	case 0x29: /* ')' */
+	/* Special modifiers in zone files. */
+	case 0x40: /* '@' */
+	case 0x24: /* '$' */
+		return (1);
+	default:
+		return (0);
+	}
+}
+
+/*
+ *	Thinking in noninternationalized USASCII (per the DNS spec),
+ *	is this character visible and not a space when printed ?
+ *
+ * return:
+ *	boolean.
+ */
+static int
+printable(int ch) {
+	return (ch > 0x20 && ch < 0x7f);
+}
+
+/*
+ *	Thinking in noninternationalized USASCII (per the DNS spec),
+ *	convert this character to lower case if it's upper case.
+ */
+static int
+mklower(int ch) {
+	if (ch >= 0x41 && ch <= 0x5A)
+		return (ch + 0x20);
+	return (ch);
+}
+
+/*
+ *	Search for the counted-label name in an array of compressed names.
+ *
+ * return:
+ *	offset from msg if found, or -1.
+ *
+ * notes:
+ *	dnptrs is the pointer to the first name on the list,
+ *	not the pointer to the start of the message.
+ */
+static int
+dn_find(const u_char *domain, const u_char *msg,
+	const u_char * const *dnptrs,
+	const u_char * const *lastdnptr)
+{
+	const u_char *dn, *cp, *sp;
+	const u_char * const *cpp;
+	u_int n;
+
+	for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
+		sp = *cpp;
+		/*
+		 * terminate search on:
+		 * root label
+		 * compression pointer
+		 * unusable offset
+		 */
+		while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 &&
+		       (sp - msg) < 0x4000) {
+			dn = domain;
+			cp = sp;
+			while ((n = *cp++) != 0) {
+				/*
+				 * check for indirection
+				 */
+				switch (n & NS_CMPRSFLGS) {
+				case 0:		/* normal case, n == len */
+					n = labellen(cp - 1); /* XXX */
+
+					if (n != *dn++)
+						goto next;
+
+					for (; n > 0; n--)
+						if (mklower(*dn++) !=
+						    mklower(*cp++))
+							goto next;
+					/* Is next root for both ? */
+					if (*dn == '\0' && *cp == '\0') {
+						_DIAGASSERT(__type_fit(int,
+						    sp - msg));
+						return (int)(sp - msg);
+					}
+					if (*dn)
+						continue;
+					goto next;
+				case NS_CMPRSFLGS:	/* indirection */
+					cp = msg + (((n & 0x3f) << 8) | *cp);
+					break;
+
+				default:	/* illegal type */
+					errno = EMSGSIZE;
+					return (-1);
+				}
+			}
+ next: ;
+			sp += *sp + 1;
+		}
+	}
+	errno = ENOENT;
+	return (-1);
+}
+
+static int
+decode_bitstring(const unsigned char **cpp, char *dn, const char *eom)
+{
+	const unsigned char *cp = *cpp;
+	char *beg = dn, tc;
+	int b, blen, plen, i;
+
+	if ((blen = (*cp & 0xff)) == 0)
+		blen = 256;
+	plen = (blen + 3) / 4;
+	plen += (int)sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1);
+	if (dn + plen >= eom)
+		return(-1);
+
+	cp++;
+	i = SPRINTF((dn, "\\[x"));
+	if (i < 0)
+		return (-1);
+	dn += i;
+	for (b = blen; b > 7; b -= 8, cp++) {
+		i = SPRINTF((dn, "%02x", *cp & 0xff));
+		if (i < 0)
+			return (-1);
+		dn += i;
+	}
+	if (b > 4) {
+		tc = *cp++;
+		i = SPRINTF((dn, "%02x", tc & (0xff << (8 - b))));
+		if (i < 0)
+			return (-1);
+		dn += i;
+	} else if (b > 0) {
+		tc = *cp++;
+		i = SPRINTF((dn, "%1x",
+			       (((u_int32_t)tc >> 4) & 0x0f) & (0x0f << (4 - b))));
+		if (i < 0)
+			return (-1);
+		dn += i;
+	}
+	i = SPRINTF((dn, "/%d]", blen));
+	if (i < 0)
+		return (-1);
+	dn += i;
+
+	*cpp = cp;
+	_DIAGASSERT(__type_fit(int, dn - beg));
+	return (int)(dn - beg);
+}
+
+static int
+encode_bitsring(const char **bp, const char *end, unsigned char **labelp,
+	        unsigned char ** dst, unsigned const char *eom)
+{
+	int afterslash = 0;
+	const char *cp = *bp;
+	unsigned char *tp;
+	char c;
+	const char *beg_blen;
+	char *end_blen = NULL;
+	int value = 0, count = 0, tbcount = 0, blen = 0;
+
+	beg_blen = end_blen = NULL;
+
+	/* a bitstring must contain at least 2 characters */
+	if (end - cp < 2)
+		return(EINVAL);
+
+	/* XXX: currently, only hex strings are supported */
+	if (*cp++ != 'x')
+		return(EINVAL);
+	if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */
+		return(EINVAL);
+
+	for (tp = *dst + 1; cp < end && tp < eom; cp++) {
+		switch((c = *cp)) {
+		case ']':	/* end of the bitstring */
+			if (afterslash) {
+				if (beg_blen == NULL)
+					return(EINVAL);
+				blen = (int)strtol(beg_blen, &end_blen, 10);
+				if (*end_blen != ']')
+					return(EINVAL);
+			}
+			if (count)
+				*tp++ = ((value << 4) & 0xff);
+			cp++;	/* skip ']' */
+			goto done;
+		case '/':
+			afterslash = 1;
+			break;
+		default:
+			if (afterslash) {
+				if (!isdigit(c&0xff))
+					return(EINVAL);
+				if (beg_blen == NULL) {
+
+					if (c == '0') {
+						/* blen never begings with 0 */
+						return(EINVAL);
+					}
+					beg_blen = cp;
+				}
+			} else {
+				if (!isxdigit(c&0xff))
+					return(EINVAL);
+				value <<= 4;
+				value += digitvalue[(int)c];
+				count += 4;
+				tbcount += 4;
+				if (tbcount > 256)
+					return(EINVAL);
+				if (count == 8) {
+					*tp++ = value;
+					count = 0;
+				}
+			}
+			break;
+		}
+	}
+  done:
+	if (cp >= end || tp >= eom)
+		return(EMSGSIZE);
+
+	/*
+	 * bit length validation:
+	 * If a <length> is present, the number of digits in the <bit-data>
+	 * MUST be just sufficient to contain the number of bits specified
+	 * by the <length>. If there are insignificant bits in a final
+	 * hexadecimal or octal digit, they MUST be zero.
+	 * RFC 2673, Section 3.2.
+	 */
+	if (blen > 0) {
+		int traillen;
+
+		if (((blen + 3) & ~3) != tbcount)
+			return(EINVAL);
+		traillen = tbcount - blen; /* between 0 and 3 */
+		if (((value << (8 - traillen)) & 0xff) != 0)
+			return(EINVAL);
+	}
+	else
+		blen = tbcount;
+	if (blen == 256)
+		blen = 0;
+
+	/* encode the type and the significant bit fields */
+	**labelp = DNS_LABELTYPE_BITSTRING;
+	**dst = blen;
+
+	*bp = cp;
+	*dst = tp;
+
+	return(0);
+}
+
+static int
+labellen(const u_char *lp)
+{
+	int bitlen;
+	u_char l = *lp;
+
+	if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
+		/* should be avoided by the caller */
+		return(-1);
+	}
+
+	if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT) {
+		if (l == DNS_LABELTYPE_BITSTRING) {
+			if ((bitlen = *(lp + 1)) == 0)
+				bitlen = 256;
+			return((bitlen + 7 ) / 8 + 1);
+		}
+		return(-1);	/* unknwon ELT */
+	}
+	return(l);
+}
diff --git a/libc/dns/nameser/ns_netint.c b/libc/dns/nameser/ns_netint.c
new file mode 100644
index 0000000..8b546f8
--- /dev/null
+++ b/libc/dns/nameser/ns_netint.c
@@ -0,0 +1,59 @@
+/*	$NetBSD: ns_netint.c,v 1.7 2012/03/13 21:13:39 christos Exp $	*/
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#ifdef notdef
+static const char rcsid[] = "Id: ns_netint.c,v 1.3 2005/04/27 04:56:40 sra Exp";
+#else
+__RCSID("$NetBSD: ns_netint.c,v 1.7 2012/03/13 21:13:39 christos Exp $");
+#endif
+#endif
+
+/* Import. */
+
+#include <arpa/nameser.h>
+
+/* Public. */
+
+uint16_t
+ns_get16(const u_char *src) {
+	uint16_t dst;
+
+	NS_GET16(dst, src);
+	return dst;
+}
+
+uint32_t
+ns_get32(const u_char *src) {
+	u_int32_t dst;
+
+	NS_GET32(dst, src);
+	return dst;
+}
+
+void
+ns_put16(uint16_t src, u_char *dst) {
+	NS_PUT16(src, dst);
+}
+
+void
+ns_put32(uint32_t src, u_char *dst) {
+	NS_PUT32(src, dst);
+}
diff --git a/libc/dns/nameser/ns_parse.c b/libc/dns/nameser/ns_parse.c
new file mode 100644
index 0000000..2d6d530
--- /dev/null
+++ b/libc/dns/nameser/ns_parse.c
@@ -0,0 +1,275 @@
+/*	$NetBSD: ns_parse.c,v 1.9 2012/03/13 21:13:39 christos Exp $	*/
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#ifdef notdef
+static const char rcsid[] = "Id: ns_parse.c,v 1.10 2009/01/23 19:59:16 each Exp";
+#else
+__RCSID("$NetBSD: ns_parse.c,v 1.9 2012/03/13 21:13:39 christos Exp $");
+#endif
+#endif
+
+/* Import. */
+
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+#include <assert.h>
+#include <errno.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <string.h>
+
+/* Forward. */
+
+static void	setsection(ns_msg *msg, ns_sect sect);
+
+/* Macros. */
+
+#define RETERR(err) do { errno = (err); return (-1); } while (/*NOTREACHED*//*CONSTCOND*/0)
+
+/* Public. */
+
+/* These need to be in the same order as the nres.h:ns_flag enum. */
+const struct _ns_flagdata _ns_flagdata[16] = {
+	{ 0x8000, 15 },		/* qr. */
+	{ 0x7800, 11 },		/* opcode. */
+	{ 0x0400, 10 },		/* aa. */
+	{ 0x0200, 9 },		/* tc. */
+	{ 0x0100, 8 },		/* rd. */
+	{ 0x0080, 7 },		/* ra. */
+	{ 0x0040, 6 },		/* z. */
+	{ 0x0020, 5 },		/* ad. */
+	{ 0x0010, 4 },		/* cd. */
+	{ 0x000f, 0 },		/* rcode. */
+	{ 0x0000, 0 },		/* expansion (1/6). */
+	{ 0x0000, 0 },		/* expansion (2/6). */
+	{ 0x0000, 0 },		/* expansion (3/6). */
+	{ 0x0000, 0 },		/* expansion (4/6). */
+	{ 0x0000, 0 },		/* expansion (5/6). */
+	{ 0x0000, 0 },		/* expansion (6/6). */
+};
+
+int ns_msg_getflag(ns_msg handle, int flag) {
+	return((u_int32_t)((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift);
+}
+
+int
+ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
+	const u_char *optr = ptr;
+
+	for (; count > 0; count--) {
+		int b, rdlength;
+
+		b = dn_skipname(ptr, eom);
+		if (b < 0)
+			RETERR(EMSGSIZE);
+		ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;
+		if (section != ns_s_qd) {
+			if (ptr + NS_INT32SZ + NS_INT16SZ > eom)
+				RETERR(EMSGSIZE);
+			ptr += NS_INT32SZ/*TTL*/;
+			NS_GET16(rdlength, ptr);
+			ptr += rdlength/*RData*/;
+		}
+	}
+	if (ptr > eom)
+		RETERR(EMSGSIZE);
+	_DIAGASSERT(__type_fit(int, ptr - optr));
+	return (int)(ptr - optr);
+}
+
+int
+ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
+	const u_char *eom = msg + msglen;
+	int i;
+
+	handle->_msg = msg;
+	handle->_eom = eom;
+	if (msg + NS_INT16SZ > eom)
+		RETERR(EMSGSIZE);
+	NS_GET16(handle->_id, msg);
+	if (msg + NS_INT16SZ > eom)
+		RETERR(EMSGSIZE);
+	NS_GET16(handle->_flags, msg);
+	for (i = 0; i < ns_s_max; i++) {
+		if (msg + NS_INT16SZ > eom)
+			RETERR(EMSGSIZE);
+		NS_GET16(handle->_counts[i], msg);
+	}
+	for (i = 0; i < ns_s_max; i++)
+		if (handle->_counts[i] == 0)
+			handle->_sections[i] = NULL;
+		else {
+			int b = ns_skiprr(msg, eom, (ns_sect)i,
+					  handle->_counts[i]);
+
+			if (b < 0)
+				return (-1);
+			handle->_sections[i] = msg;
+			msg += b;
+		}
+	if (msg != eom)
+		RETERR(EMSGSIZE);
+	setsection(handle, ns_s_max);
+	return (0);
+}
+
+int
+ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
+	int b;
+	int tmp;
+
+	/* Make section right. */
+	tmp = section;
+	if (tmp < 0 || section >= ns_s_max)
+		RETERR(ENODEV);
+	if (section != handle->_sect)
+		setsection(handle, section);
+
+	/* Make rrnum right. */
+	if (rrnum == -1)
+		rrnum = handle->_rrnum;
+	if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
+		RETERR(ENODEV);
+	if (rrnum < handle->_rrnum)
+		setsection(handle, section);
+	if (rrnum > handle->_rrnum) {
+		b = ns_skiprr(handle->_msg_ptr, handle->_eom, section,
+			      rrnum - handle->_rrnum);
+
+		if (b < 0)
+			return (-1);
+		handle->_msg_ptr += b;
+		handle->_rrnum = rrnum;
+	}
+
+	/* Do the parse. */
+	b = dn_expand(handle->_msg, handle->_eom,
+		      handle->_msg_ptr, rr->name, NS_MAXDNAME);
+	if (b < 0)
+		return (-1);
+	handle->_msg_ptr += b;
+	if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom)
+		RETERR(EMSGSIZE);
+	NS_GET16(rr->type, handle->_msg_ptr);
+	NS_GET16(rr->rr_class, handle->_msg_ptr);
+	if (section == ns_s_qd) {
+		rr->ttl = 0;
+		rr->rdlength = 0;
+		rr->rdata = NULL;
+	} else {
+		if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom)
+			RETERR(EMSGSIZE);
+		NS_GET32(rr->ttl, handle->_msg_ptr);
+		NS_GET16(rr->rdlength, handle->_msg_ptr);
+		if (handle->_msg_ptr + rr->rdlength > handle->_eom)
+			RETERR(EMSGSIZE);
+		rr->rdata = handle->_msg_ptr;
+		handle->_msg_ptr += rr->rdlength;
+	}
+	if (++handle->_rrnum > handle->_counts[(int)section])
+		setsection(handle, (ns_sect)((int)section + 1));
+
+	/* All done. */
+	return (0);
+}
+
+/*
+ * This is identical to the above but uses network-format (uncompressed) names.
+ */
+int
+ns_parserr2(ns_msg *handle, ns_sect section, int rrnum, ns_rr2 *rr) {
+	int b;
+	int tmp;
+
+	/* Make section right. */
+	tmp = section;
+	if (tmp < 0 || section >= ns_s_max)
+		RETERR(ENODEV);
+	if (section != handle->_sect)
+		setsection(handle, section);
+
+	/* Make rrnum right. */
+	if (rrnum == -1)
+		rrnum = handle->_rrnum;
+	if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
+		RETERR(ENODEV);
+	if (rrnum < handle->_rrnum)
+		setsection(handle, section);
+	if (rrnum > handle->_rrnum) {
+		b = ns_skiprr(handle->_msg_ptr, handle->_eom, section,
+			      rrnum - handle->_rrnum);
+
+		if (b < 0)
+			return (-1);
+		handle->_msg_ptr += b;
+		handle->_rrnum = rrnum;
+	}
+
+	/* Do the parse. */
+	b = ns_name_unpack2(handle->_msg, handle->_eom, handle->_msg_ptr,
+			    rr->nname, NS_MAXNNAME, &rr->nnamel);
+	if (b < 0)
+		return (-1);
+	handle->_msg_ptr += b;
+	if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom)
+		RETERR(EMSGSIZE);
+	NS_GET16(rr->type, handle->_msg_ptr);
+	NS_GET16(rr->rr_class, handle->_msg_ptr);
+	if (section == ns_s_qd) {
+		rr->ttl = 0;
+		rr->rdlength = 0;
+		rr->rdata = NULL;
+	} else {
+		if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom)
+			RETERR(EMSGSIZE);
+		NS_GET32(rr->ttl, handle->_msg_ptr);
+		NS_GET16(rr->rdlength, handle->_msg_ptr);
+		if (handle->_msg_ptr + rr->rdlength > handle->_eom)
+			RETERR(EMSGSIZE);
+		rr->rdata = handle->_msg_ptr;
+		handle->_msg_ptr += rr->rdlength;
+	}
+	if (++handle->_rrnum > handle->_counts[(int)section])
+		setsection(handle, (ns_sect)((int)section + 1));
+
+	/* All done. */
+	return (0);
+}
+
+/* Private. */
+
+static void
+setsection(ns_msg *msg, ns_sect sect) {
+	msg->_sect = sect;
+	if (sect == ns_s_max) {
+		msg->_rrnum = -1;
+		msg->_msg_ptr = NULL;
+	} else {
+		msg->_rrnum = 0;
+		msg->_msg_ptr = msg->_sections[(int)sect];
+	}
+}
diff --git a/libc/dns/nameser/ns_print.c b/libc/dns/nameser/ns_print.c
new file mode 100644
index 0000000..0a6a1d6
--- /dev/null
+++ b/libc/dns/nameser/ns_print.c
@@ -0,0 +1,1265 @@
+/*	$NetBSD: ns_print.c,v 1.11 2012/03/13 21:13:39 christos Exp $	*/
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#ifdef notdef
+static const char rcsid[] = "Id: ns_print.c,v 1.12 2009/03/03 05:29:58 each Exp";
+#else
+__RCSID("$NetBSD: ns_print.c,v 1.11 2012/03/13 21:13:39 christos Exp $");
+#endif
+#endif
+
+/* Import. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <isc/assertions.h>
+#include <isc/dst.h>
+#include <assert.h>
+#include <errno.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <stddef.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) ((int)strlen(sprintf/**/x))
+#else
+# define SPRINTF(x) (sprintf x)
+#endif
+
+#ifndef MIN
+#define	MIN(x,y)	((x)<(y)?(x):(y))
+#endif
+
+/* Forward. */
+
+static size_t	prune_origin(const char *name, const char *origin);
+static int	charstr(const u_char *rdata, const u_char *edata,
+			char **buf, size_t *buflen);
+static int	addname(const u_char *msg, size_t msglen,
+			const u_char **p, const char *origin,
+			char **buf, size_t *buflen);
+static void	addlen(size_t len, char **buf, size_t *buflen);
+static int	addstr(const char *src, size_t len,
+		       char **buf, size_t *buflen);
+static int	addtab(size_t len, size_t target, int spaced,
+		       char **buf, size_t *buflen);
+
+/* Macros. */
+
+#define	T(x) \
+	do { \
+		if ((x) < 0) \
+			return (-1); \
+	} while (/*CONSTCOND*/0)
+
+static const char base32hex[] =
+        "0123456789ABCDEFGHIJKLMNOPQRSTUV=0123456789abcdefghijklmnopqrstuv";
+/* Public. */
+
+/*
+ *	Convert an RR to presentation format.
+ *
+ * return:
+ *	Number of characters written to buf, or -1 (check errno).
+ */
+int
+ns_sprintrr(const ns_msg *handle, const ns_rr *rr,
+	    const char *name_ctx, const char *origin,
+	    char *buf, size_t buflen)
+{
+	int n;
+
+	n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),
+			 ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),
+			 ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),
+			 name_ctx, origin, buf, buflen);
+	return (n);
+}
+
+/*
+ *	Convert the fields of an RR into presentation format.
+ *
+ * return:
+ *	Number of characters written to buf, or -1 (check errno).
+ */
+int
+ns_sprintrrf(const u_char *msg, size_t msglen,
+	    const char *name, ns_class class, ns_type type,
+	    u_long ttl, const u_char *rdata, size_t rdlen,
+	    const char *name_ctx, const char *origin,
+	    char *buf, size_t buflen)
+{
+	const char *obuf = buf;
+	const u_char *edata = rdata + rdlen;
+	int spaced = 0;
+
+	const char *comment;
+	char tmp[100];
+	int len, x;
+
+	/*
+	 * Owner.
+	 */
+	if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) {
+		T(addstr("\t\t\t", (size_t)3, &buf, &buflen));
+	} else {
+		len = (int)prune_origin(name, origin);
+		if (*name == '\0') {
+			goto root;
+		} else if (len == 0) {
+			T(addstr("@\t\t\t", (size_t)4, &buf, &buflen));
+		} else {
+			T(addstr(name, (size_t)len, &buf, &buflen));
+			/* Origin not used or not root, and no trailing dot? */
+			if (((origin == NULL || origin[0] == '\0') ||
+			    (origin[0] != '.' && origin[1] != '\0' &&
+			    name[len] == '\0')) && name[len - 1] != '.') {
+ root:
+				T(addstr(".", (size_t)1, &buf, &buflen));
+				len++;
+			}
+			T(spaced = addtab((size_t)len, 24, spaced, &buf, &buflen));
+		}
+	}
+
+	/*
+	 * TTL, Class, Type.
+	 */
+	T(x = ns_format_ttl(ttl, buf, buflen));
+	addlen((size_t)x, &buf, &buflen);
+	len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
+	T(addstr(tmp, (size_t)len, &buf, &buflen));
+	T(spaced = addtab((size_t)(x + len), (size_t)16, spaced, &buf, &buflen));
+
+	/*
+	 * RData.
+	 */
+	switch (type) {
+	case ns_t_a:
+		if (rdlen != (size_t)NS_INADDRSZ)
+			goto formerr;
+		(void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen);
+		addlen(strlen(buf), &buf, &buflen);
+		break;
+
+	case ns_t_cname:
+	case ns_t_mb:
+	case ns_t_mg:
+	case ns_t_mr:
+	case ns_t_ns:
+	case ns_t_ptr:
+	case ns_t_dname:
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		break;
+
+	case ns_t_hinfo:
+	case ns_t_isdn:
+		/* First word. */
+		T(len = charstr(rdata, edata, &buf, &buflen));
+		if (len == 0)
+			goto formerr;
+		rdata += len;
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+
+
+		/* Second word, optional in ISDN records. */
+		if (type == ns_t_isdn && rdata == edata)
+			break;
+
+		T(len = charstr(rdata, edata, &buf, &buflen));
+		if (len == 0)
+			goto formerr;
+		rdata += len;
+		break;
+
+	case ns_t_soa: {
+		u_long t;
+
+		/* Server name. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+
+		/* Administrator name. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		T(addstr(" (\n", (size_t)3, &buf, &buflen));
+		spaced = 0;
+
+		if ((edata - rdata) != 5*NS_INT32SZ)
+			goto formerr;
+
+		/* Serial number. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
+		len = SPRINTF((tmp, "%lu", t));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
+		T(addstr("; serial\n", (size_t)9, &buf, &buflen));
+		spaced = 0;
+
+		/* Refresh interval. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
+		T(len = ns_format_ttl(t, buf, buflen));
+		addlen((size_t)len, &buf, &buflen);
+		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
+		T(addstr("; refresh\n", (size_t)10, &buf, &buflen));
+		spaced = 0;
+
+		/* Retry interval. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
+		T(len = ns_format_ttl(t, buf, buflen));
+		addlen((size_t)len, &buf, &buflen);
+		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
+		T(addstr("; retry\n", (size_t)8, &buf, &buflen));
+		spaced = 0;
+
+		/* Expiry. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
+		T(len = ns_format_ttl(t, buf, buflen));
+		addlen((size_t)len, &buf, &buflen);
+		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
+		T(addstr("; expiry\n", (size_t)9, &buf, &buflen));
+		spaced = 0;
+
+		/* Minimum TTL. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
+		T(len = ns_format_ttl(t, buf, buflen));
+		addlen((size_t)len, &buf, &buflen);
+		T(addstr(" )", (size_t)2, &buf, &buflen));
+		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
+		T(addstr("; minimum\n", (size_t)10, &buf, &buflen));
+
+		break;
+	    }
+
+	case ns_t_mx:
+	case ns_t_afsdb:
+	case ns_t_rt:
+	case ns_t_kx: {
+		u_int t;
+
+		if (rdlen < (size_t)NS_INT16SZ)
+			goto formerr;
+
+		/* Priority. */
+		t = ns_get16(rdata);
+		rdata += NS_INT16SZ;
+		len = SPRINTF((tmp, "%u ", t));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* Target. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+		break;
+	    }
+
+	case ns_t_px: {
+		u_int t;
+
+		if (rdlen < (size_t)NS_INT16SZ)
+			goto formerr;
+
+		/* Priority. */
+		t = ns_get16(rdata);
+		rdata += NS_INT16SZ;
+		len = SPRINTF((tmp, "%u ", t));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* Name1. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+
+		/* Name2. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+		break;
+	    }
+
+	case ns_t_x25:
+		T(len = charstr(rdata, edata, &buf, &buflen));
+		if (len == 0)
+			goto formerr;
+		rdata += len;
+		break;
+
+	case ns_t_txt:
+	case ns_t_spf:
+		while (rdata < edata) {
+			T(len = charstr(rdata, edata, &buf, &buflen));
+			if (len == 0)
+				goto formerr;
+			rdata += len;
+			if (rdata < edata)
+				T(addstr(" ", (size_t)1, &buf, &buflen));
+		}
+		break;
+
+	case ns_t_nsap: {
+		char t[2+255*3];
+
+		(void) inet_nsap_ntoa((int)rdlen, rdata, t);
+		T(addstr(t, strlen(t), &buf, &buflen));
+		break;
+	    }
+
+	case ns_t_aaaa:
+		if (rdlen != (size_t)NS_IN6ADDRSZ)
+			goto formerr;
+		(void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen);
+		addlen(strlen(buf), &buf, &buflen);
+		break;
+
+	case ns_t_loc: {
+		char t[255];
+
+		/* XXX protocol format checking? */
+		(void) loc_ntoa(rdata, t);
+		T(addstr(t, strlen(t), &buf, &buflen));
+		break;
+	    }
+
+	case ns_t_naptr: {
+		u_int order, preference;
+		char t[50];
+
+		if (rdlen < 2U*NS_INT16SZ)
+			goto formerr;
+
+		/* Order, Precedence. */
+		order = ns_get16(rdata);	rdata += NS_INT16SZ;
+		preference = ns_get16(rdata);	rdata += NS_INT16SZ;
+		len = SPRINTF((t, "%u %u ", order, preference));
+		T(addstr(t, (size_t)len, &buf, &buflen));
+
+		/* Flags. */
+		T(len = charstr(rdata, edata, &buf, &buflen));
+		if (len == 0)
+			goto formerr;
+		rdata += len;
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+
+		/* Service. */
+		T(len = charstr(rdata, edata, &buf, &buflen));
+		if (len == 0)
+			goto formerr;
+		rdata += len;
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+
+		/* Regexp. */
+		T(len = charstr(rdata, edata, &buf, &buflen));
+		if (len < 0)
+			return (-1);
+		if (len == 0)
+			goto formerr;
+		rdata += len;
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+
+		/* Server. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		break;
+	    }
+
+	case ns_t_srv: {
+		u_int priority, weight, port;
+		char t[50];
+
+		if (rdlen < 3U*NS_INT16SZ)
+			goto formerr;
+
+		/* Priority, Weight, Port. */
+		priority = ns_get16(rdata);  rdata += NS_INT16SZ;
+		weight   = ns_get16(rdata);  rdata += NS_INT16SZ;
+		port     = ns_get16(rdata);  rdata += NS_INT16SZ;
+		len = SPRINTF((t, "%u %u %u ", priority, weight, port));
+		T(addstr(t, (size_t)len, &buf, &buflen));
+
+		/* Server. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		break;
+	    }
+
+	case ns_t_minfo:
+	case ns_t_rp:
+		/* Name1. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+
+		/* Name2. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+		break;
+
+	case ns_t_wks: {
+		int n, lcnt;
+
+		if (rdlen < 1U + NS_INT32SZ)
+			goto formerr;
+
+		/* Address. */
+		(void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen);
+		addlen(strlen(buf), &buf, &buflen);
+		rdata += NS_INADDRSZ;
+
+		/* Protocol. */
+		len = SPRINTF((tmp, " %u ( ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		rdata += NS_INT8SZ;
+
+		/* Bit map. */
+		n = 0;
+		lcnt = 0;
+		while (rdata < edata) {
+			u_int c = *rdata++;
+			do {
+				if (c & 0200) {
+					if (lcnt == 0) {
+						T(addstr("\n\t\t\t\t", (size_t)5,
+							 &buf, &buflen));
+						lcnt = 10;
+						spaced = 0;
+					}
+					len = SPRINTF((tmp, "%d ", n));
+					T(addstr(tmp, (size_t)len, &buf, &buflen));
+					lcnt--;
+				}
+				c <<= 1;
+			} while (++n & 07);
+		}
+		T(addstr(")", (size_t)1, &buf, &buflen));
+
+		break;
+	    }
+
+	case ns_t_key:
+	case ns_t_dnskey: {
+		char base64_key[NS_MD5RSA_MAX_BASE64];
+		u_int keyflags, protocol, algorithm, key_id;
+		const char *leader;
+		int n;
+
+		if (rdlen < 0U + NS_INT16SZ + NS_INT8SZ + NS_INT8SZ)
+			goto formerr;
+
+		/* Key flags, Protocol, Algorithm. */
+#ifndef _LIBC
+		key_id = dst_s_dns_key_id(rdata, edata-rdata);
+#else
+		key_id = 0;
+#endif
+		keyflags = ns_get16(rdata);  rdata += NS_INT16SZ;
+		protocol = *rdata++;
+		algorithm = *rdata++;
+		len = SPRINTF((tmp, "0x%04x %u %u",
+			       keyflags, protocol, algorithm));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* Public key data. */
+		len = b64_ntop(rdata, (size_t)(edata - rdata),
+			       base64_key, sizeof base64_key);
+		if (len < 0)
+			goto formerr;
+		if (len > 15) {
+			T(addstr(" (", (size_t)2, &buf, &buflen));
+			leader = "\n\t\t";
+			spaced = 0;
+		} else
+			leader = " ";
+		for (n = 0; n < len; n += 48) {
+			T(addstr(leader, strlen(leader), &buf, &buflen));
+			T(addstr(base64_key + n, (size_t)MIN(len - n, 48),
+				 &buf, &buflen));
+		}
+		if (len > 15)
+			T(addstr(" )", (size_t)2, &buf, &buflen));
+		n = SPRINTF((tmp, " ; key_tag= %u", key_id));
+		T(addstr(tmp, (size_t)n, &buf, &buflen));
+
+		break;
+	    }
+
+	case ns_t_sig:
+	case ns_t_rrsig: {
+		char base64_key[NS_MD5RSA_MAX_BASE64];
+		u_int typ, algorithm, labels, footprint;
+		const char *leader;
+		u_long t;
+		int n;
+
+		if (rdlen < 22U)
+			goto formerr;
+
+		/* Type covered, Algorithm, Label count, Original TTL. */
+	        typ = ns_get16(rdata);  rdata += NS_INT16SZ;
+		algorithm = *rdata++;
+		labels = *rdata++;
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		len = SPRINTF((tmp, "%s %d %d %lu ",
+			       p_type((int)typ), algorithm, labels, t));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		if (labels > (u_int)dn_count_labels(name))
+			goto formerr;
+
+		/* Signature expiry. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* Time signed. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* Signature Footprint. */
+		footprint = ns_get16(rdata);  rdata += NS_INT16SZ;
+		len = SPRINTF((tmp, "%u ", footprint));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* Signer's name. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+		/* Signature. */
+		len = b64_ntop(rdata, (size_t)(edata - rdata),
+			       base64_key, sizeof base64_key);
+		if (len > 15) {
+			T(addstr(" (", (size_t)2, &buf, &buflen));
+			leader = "\n\t\t";
+			spaced = 0;
+		} else
+			leader = " ";
+		if (len < 0)
+			goto formerr;
+		for (n = 0; n < len; n += 48) {
+			T(addstr(leader, strlen(leader), &buf, &buflen));
+			T(addstr(base64_key + n, (size_t)MIN(len - n, 48),
+				 &buf, &buflen));
+		}
+		if (len > 15)
+			T(addstr(" )", (size_t)2, &buf, &buflen));
+		break;
+	    }
+
+	case ns_t_nxt: {
+		ptrdiff_t n, c;
+
+		/* Next domain name. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+		/* Type bit map. */
+		n = edata - rdata;
+		for (c = 0; c < n*8; c++)
+			if (NS_NXT_BIT_ISSET(c, rdata)) {
+				len = SPRINTF((tmp, " %s", p_type((int)c)));
+				T(addstr(tmp, (size_t)len, &buf, &buflen));
+			}
+		break;
+	    }
+
+	case ns_t_cert: {
+		u_int c_type, key_tag, alg;
+		int n;
+		size_t siz;
+		char base64_cert[8192], tmp1[40];
+		const char *leader;
+
+		c_type  = ns_get16(rdata); rdata += NS_INT16SZ;
+		key_tag = ns_get16(rdata); rdata += NS_INT16SZ;
+		alg = (u_int) *rdata++;
+
+		len = SPRINTF((tmp1, "%d %d %d ", c_type, key_tag, alg));
+		T(addstr(tmp1, (size_t)len, &buf, &buflen));
+		siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
+		if (siz > sizeof(base64_cert) * 3/4) {
+			const char *str = "record too long to print";
+			T(addstr(str, strlen(str), &buf, &buflen));
+		}
+		else {
+			len = b64_ntop(rdata, (size_t)(edata-rdata),
+			    base64_cert, siz);
+
+			if (len < 0)
+				goto formerr;
+			else if (len > 15) {
+				T(addstr(" (", (size_t)2, &buf, &buflen));
+				leader = "\n\t\t";
+				spaced = 0;
+			}
+			else
+				leader = " ";
+
+			for (n = 0; n < len; n += 48) {
+				T(addstr(leader, strlen(leader),
+					 &buf, &buflen));
+				T(addstr(base64_cert + n, (size_t)MIN(len - n, 48),
+					 &buf, &buflen));
+			}
+			if (len > 15)
+				T(addstr(" )", (size_t)2, &buf, &buflen));
+		}
+		break;
+	    }
+
+	case ns_t_tkey: {
+		/* KJD - need to complete this */
+		u_long t;
+		int mode, err, keysize;
+
+		/* Algorithm name. */
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+
+		/* Inception. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* Experation. */
+		t = ns_get32(rdata);  rdata += NS_INT32SZ;
+		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* Mode , Error, Key Size. */
+		/* Priority, Weight, Port. */
+		mode = ns_get16(rdata);  rdata += NS_INT16SZ;
+		err  = ns_get16(rdata);  rdata += NS_INT16SZ;
+		keysize  = ns_get16(rdata);  rdata += NS_INT16SZ;
+		len = SPRINTF((tmp, "%u %u %u ", mode, err, keysize));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		/* XXX need to dump key, print otherdata length & other data */
+		break;
+	    }
+
+	case ns_t_tsig: {
+		/* BEW - need to complete this */
+		int n;
+
+		T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen));
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+		rdata += 8; /* time */
+		n = ns_get16(rdata); rdata += INT16SZ;
+		rdata += n; /* sig */
+		n = ns_get16(rdata); rdata += INT16SZ; /* original id */
+		sprintf(buf, "%d", ns_get16(rdata));
+		rdata += INT16SZ;
+		addlen(strlen(buf), &buf, &buflen);
+		break;
+	    }
+
+	case ns_t_a6: {
+		struct in6_addr a;
+		int pbyte, pbit;
+
+		/* prefix length */
+		if (rdlen == 0U) goto formerr;
+		len = SPRINTF((tmp, "%d ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		pbit = *rdata;
+		if (pbit > 128) goto formerr;
+		pbyte = (pbit & ~7) / 8;
+		rdata++;
+
+		/* address suffix: provided only when prefix len != 128 */
+		if (pbit < 128) {
+			if (rdata + pbyte >= edata) goto formerr;
+			memset(&a, 0, sizeof(a));
+			memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte);
+			(void) inet_ntop(AF_INET6, &a, buf, (socklen_t)buflen);
+			addlen(strlen(buf), &buf, &buflen);
+			rdata += sizeof(a) - pbyte;
+		}
+
+		/* prefix name: provided only when prefix len > 0 */
+		if (pbit == 0)
+			break;
+		if (rdata >= edata) goto formerr;
+		T(addstr(" ", (size_t)1, &buf, &buflen));
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+		break;
+	    }
+
+	case ns_t_opt: {
+		len = SPRINTF((tmp, "%u bytes", class));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		break;
+	    }
+
+	case ns_t_ds:
+	case ns_t_dlv:
+	case ns_t_sshfp: {
+		u_int t;
+
+		if (type == ns_t_ds || type == ns_t_dlv) {
+			if (rdlen < 4U) goto formerr;
+			t = ns_get16(rdata);
+			rdata += NS_INT16SZ;
+			len = SPRINTF((tmp, "%u ", t));
+			T(addstr(tmp, (size_t)len, &buf, &buflen));
+		} else
+			if (rdlen < 2U) goto formerr;
+
+		len = SPRINTF((tmp, "%u ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		rdata++;
+
+		len = SPRINTF((tmp, "%u ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		rdata++;
+
+		while (rdata < edata) {
+			len = SPRINTF((tmp, "%02X", *rdata));
+			T(addstr(tmp, (size_t)len, &buf, &buflen));
+			rdata++;
+		}
+		break;
+	    }
+
+	case ns_t_nsec3:
+	case ns_t_nsec3param: {
+		u_int t, w, l, j, k, c;
+
+		len = SPRINTF((tmp, "%u ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		rdata++;
+
+		len = SPRINTF((tmp, "%u ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		rdata++;
+
+		t = ns_get16(rdata);
+		rdata += NS_INT16SZ;
+		len = SPRINTF((tmp, "%u ", t));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+		t = *rdata++;
+		if (t == 0) {
+			T(addstr("-", 1, &buf, &buflen));
+		} else {
+			while (t-- > 0) {
+				len = SPRINTF((tmp, "%02X", *rdata));
+				T(addstr(tmp, (size_t)len, &buf, &buflen));
+				rdata++;
+			}
+		}
+		if (type == ns_t_nsec3param)
+			break;
+		T(addstr(" ", 1, &buf, &buflen));
+
+		t = *rdata++;
+		while (t > 0) {
+			switch (t) {
+			case 1:
+				tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)];
+				tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)];
+				tmp[2] = tmp[3] = tmp[4] = '=';
+				tmp[5] = tmp[6] = tmp[7] = '=';
+				break;
+			case 2:
+				tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)];
+				tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)|
+						   (((uint32_t)rdata[1]>>6)&0x03)];
+				tmp[2] = base32hex[(((uint32_t)rdata[1]>>1)&0x1f)];
+				tmp[3] = base32hex[(((uint32_t)rdata[1]<<4)&0x10)];
+				tmp[4] = tmp[5] = tmp[6] = tmp[7] = '=';
+				break;
+			case 3:
+				tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)];
+				tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)|
+						   (((uint32_t)rdata[1]>>6)&0x03)];
+				tmp[2] = base32hex[(((uint32_t)rdata[1]>>1)&0x1f)];
+				tmp[3] = base32hex[(((uint32_t)rdata[1]<<4)&0x10)|
+						   (((uint32_t)rdata[2]>>4)&0x0f)];
+				tmp[4] = base32hex[(((uint32_t)rdata[2]<<1)&0x1e)];
+				tmp[5] = tmp[6] = tmp[7] = '=';
+				break;
+			case 4:
+				tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)];
+				tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)|
+						   (((uint32_t)rdata[1]>>6)&0x03)];
+				tmp[2] = base32hex[(((uint32_t)rdata[1]>>1)&0x1f)];
+				tmp[3] = base32hex[(((uint32_t)rdata[1]<<4)&0x10)|
+						   (((uint32_t)rdata[2]>>4)&0x0f)];
+				tmp[4] = base32hex[(((uint32_t)rdata[2]<<1)&0x1e)|
+						   (((uint32_t)rdata[3]>>7)&0x01)];
+				tmp[5] = base32hex[(((uint32_t)rdata[3]>>2)&0x1f)];
+				tmp[6] = base32hex[((uint32_t)rdata[3]<<3)&0x18];
+				tmp[7] = '=';
+				break;
+			default:
+				tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)];
+				tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)|
+						   (((uint32_t)rdata[1]>>6)&0x03)];
+				tmp[2] = base32hex[(((uint32_t)rdata[1]>>1)&0x1f)];
+				tmp[3] = base32hex[(((uint32_t)rdata[1]<<4)&0x10)|
+						   (((uint32_t)rdata[2]>>4)&0x0f)];
+				tmp[4] = base32hex[(((uint32_t)rdata[2]<<1)&0x1e)|
+						   (((uint32_t)rdata[3]>>7)&0x01)];
+				tmp[5] = base32hex[(((uint32_t)rdata[3]>>2)&0x1f)];
+				tmp[6] = base32hex[(((uint32_t)rdata[3]<<3)&0x18)|
+						   (((uint32_t)rdata[4]>>5)&0x07)];
+				tmp[7] = base32hex[(rdata[4]&0x1f)];
+				break;
+			}
+			T(addstr(tmp, 8, &buf, &buflen));
+			if (t >= 5) {
+				rdata += 5;
+				t -= 5;
+			} else {
+				rdata += t;
+				t -= t;
+			}
+		}
+
+		while (rdata < edata) {
+			w = *rdata++;
+			l = *rdata++;
+			for (j = 0; j < l; j++) {
+				if (rdata[j] == 0)
+					continue;
+				for (k = 0; k < 8; k++) {
+					if ((rdata[j] & (0x80 >> k)) == 0)
+						continue;
+					c = w * 256 + j * 8 + k;
+					len = SPRINTF((tmp, " %s", p_type((ns_type)c)));
+					T(addstr(tmp, (size_t)len, &buf, &buflen));
+				}
+			}
+			rdata += l;
+		}
+		break;
+	    }
+
+	case ns_t_nsec: {
+		u_int w, l, j, k, c;
+
+		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+		while (rdata < edata) {
+			w = *rdata++;
+			l = *rdata++;
+			for (j = 0; j < l; j++) {
+				if (rdata[j] == 0)
+					continue;
+				for (k = 0; k < 8; k++) {
+					if ((rdata[j] & (0x80 >> k)) == 0)
+						continue;
+					c = w * 256 + j * 8 + k;
+					len = SPRINTF((tmp, " %s", p_type((ns_type)c)));
+					T(addstr(tmp, (size_t)len, &buf, &buflen));
+				}
+			}
+			rdata += l;
+		}
+		break;
+	    }
+
+	case ns_t_dhcid: {
+		int n;
+		unsigned int siz;
+		char base64_dhcid[8192];
+		const char *leader;
+
+		siz = (int)(edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
+		if (siz > sizeof(base64_dhcid) * 3/4) {
+			const char *str = "record too long to print";
+			T(addstr(str, strlen(str), &buf, &buflen));
+		} else {
+			len = b64_ntop(rdata, (size_t)(edata-rdata),
+			    base64_dhcid, siz);
+
+			if (len < 0)
+				goto formerr;
+
+			else if (len > 15) {
+				T(addstr(" (", 2, &buf, &buflen));
+				leader = "\n\t\t";
+				spaced = 0;
+			}
+			else
+				leader = " ";
+
+			for (n = 0; n < len; n += 48) {
+				T(addstr(leader, strlen(leader),
+					 &buf, &buflen));
+				T(addstr(base64_dhcid + n,
+				    (size_t)MIN(len - n, 48), &buf, &buflen));
+			}
+			if (len > 15)
+				T(addstr(" )", 2, &buf, &buflen));
+		}
+		break;
+	}
+
+	case ns_t_ipseckey: {
+		int n;
+		unsigned int siz;
+		char base64_key[8192];
+		const char *leader;
+
+		if (rdlen < 2)
+			goto formerr;
+
+		switch (rdata[1]) {
+		case 0:
+		case 3:
+			if (rdlen < 3)
+				goto formerr;
+			break;
+		case 1:
+			if (rdlen < 7)
+				goto formerr;
+			break;
+		case 2:
+			if (rdlen < 19)
+				goto formerr;
+			break;
+		default:
+			comment = "unknown IPSECKEY gateway type";
+			goto hexify;
+		}
+
+		len = SPRINTF((tmp, "%u ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		rdata++;
+
+		len = SPRINTF((tmp, "%u ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		rdata++;
+
+		len = SPRINTF((tmp, "%u ", *rdata));
+		T(addstr(tmp, (size_t)len, &buf, &buflen));
+		rdata++;
+
+		switch (rdata[-2]) {
+		case 0:
+			T(addstr(".", 1, &buf, &buflen));
+			break;
+		case 1:
+			(void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen);
+			addlen(strlen(buf), &buf, &buflen);
+			rdata += 4;
+			break;
+		case 2:
+			(void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen);
+			addlen(strlen(buf), &buf, &buflen);
+			rdata += 16;
+			break;
+		case 3:
+			T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+			break;
+		}
+
+		if (rdata >= edata)
+			break;
+
+		siz = (int)(edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
+		if (siz > sizeof(base64_key) * 3/4) {
+			const char *str = "record too long to print";
+			T(addstr(str, strlen(str), &buf, &buflen));
+		} else {
+			len = b64_ntop(rdata, (size_t)(edata-rdata),
+			    base64_key, siz);
+
+			if (len < 0)
+				goto formerr;
+
+			else if (len > 15) {
+				T(addstr(" (", 2, &buf, &buflen));
+				leader = "\n\t\t";
+				spaced = 0;
+			}
+			else
+				leader = " ";
+
+			for (n = 0; n < len; n += 48) {
+				T(addstr(leader, strlen(leader),
+					 &buf, &buflen));
+				T(addstr(base64_key + n,
+				    (size_t)MIN(len - n, 48), &buf, &buflen));
+			}
+			if (len > 15)
+				T(addstr(" )", 2, &buf, &buflen));
+		}
+		break;
+	}
+
+	case ns_t_hip: {
+		unsigned int i, hip_len, algorithm, key_len;
+		char base64_key[NS_MD5RSA_MAX_BASE64];
+		unsigned int siz;
+		const char *leader = "\n\t\t\t\t\t";
+
+		hip_len = *rdata++;
+		algorithm = *rdata++;
+		key_len = ns_get16(rdata);
+		rdata += NS_INT16SZ;
+
+		siz = key_len*4/3 + 4; /* "+4" accounts for trailing \0 */
+		if (siz > sizeof(base64_key) * 3/4) {
+			const char *str = "record too long to print";
+			T(addstr(str, strlen(str), &buf, &buflen));
+		} else {
+			len = sprintf(tmp, "( %u ", algorithm);
+			T(addstr(tmp, (size_t)len, &buf, &buflen));
+
+			for (i = 0; i < hip_len; i++) {
+				len = sprintf(tmp, "%02X", *rdata);
+				T(addstr(tmp, (size_t)len, &buf, &buflen));
+				rdata++;
+			}
+			T(addstr(leader, strlen(leader), &buf, &buflen));
+
+			len = b64_ntop(rdata, key_len, base64_key, siz);
+			if (len < 0)
+				goto formerr;
+
+			T(addstr(base64_key, (size_t)len, &buf, &buflen));
+
+			rdata += key_len;
+			while (rdata < edata) {
+				T(addstr(leader, strlen(leader), &buf, &buflen));
+				T(addname(msg, msglen, &rdata, origin,
+					  &buf, &buflen));
+			}
+			T(addstr(" )", 2, &buf, &buflen));
+		}
+		break;
+	    }
+
+	default:
+		comment = "unknown RR type";
+		goto hexify;
+	}
+	_DIAGASSERT(__type_fit(int, buf - obuf));
+	return (int)(buf - obuf);
+ formerr:
+	comment = "RR format error";
+ hexify: {
+	int n, m;
+	char *p;
+
+	len = SPRINTF((tmp, "\\# %u%s\t; %s", (unsigned)(edata - rdata),
+		       rdlen != 0U ? " (" : "", comment));
+	T(addstr(tmp, (size_t)len, &buf, &buflen));
+	while (rdata < edata) {
+		p = tmp;
+		p += SPRINTF((p, "\n\t"));
+		spaced = 0;
+		n = MIN(16, (int)(edata - rdata));
+		for (m = 0; m < n; m++)
+			p += SPRINTF((p, "%02x ", rdata[m]));
+		T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen));
+		if (n < 16) {
+			T(addstr(")", (size_t)1, &buf, &buflen));
+			T(addtab((size_t)(p - tmp + 1), (size_t)48, spaced, &buf, &buflen));
+		}
+		p = tmp;
+		p += SPRINTF((p, "; "));
+		for (m = 0; m < n; m++)
+			*p++ = (isascii(rdata[m]) && isprint(rdata[m]))
+				? rdata[m]
+				: '.';
+		T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen));
+		rdata += n;
+	}
+	_DIAGASSERT(__type_fit(int, buf - obuf));
+	return (int)(buf - obuf);
+    }
+}
+
+/* Private. */
+
+/*
+ * size_t
+ * prune_origin(name, origin)
+ *	Find out if the name is at or under the current origin.
+ * return:
+ *	Number of characters in name before start of origin,
+ *	or length of name if origin does not match.
+ * notes:
+ *	This function should share code with samedomain().
+ */
+static size_t
+prune_origin(const char *name, const char *origin) {
+	const char *oname = name;
+
+	while (*name != '\0') {
+		if (origin != NULL && ns_samename(name, origin) == 1)
+			return (name - oname - (name > oname));
+		while (*name != '\0') {
+			if (*name == '\\') {
+				name++;
+				/* XXX need to handle \nnn form. */
+				if (*name == '\0')
+					break;
+			} else if (*name == '.') {
+				name++;
+				break;
+			}
+			name++;
+		}
+	}
+	return (name - oname);
+}
+
+/*
+ * int
+ * charstr(rdata, edata, buf, buflen)
+ *	Format a <character-string> into the presentation buffer.
+ * return:
+ *	Number of rdata octets consumed
+ *	0 for protocol format error
+ *	-1 for output buffer error
+ * side effects:
+ *	buffer is advanced on success.
+ */
+static int
+charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
+	const u_char *odata = rdata;
+	size_t save_buflen = *buflen;
+	char *save_buf = *buf;
+
+	if (addstr("\"", (size_t)1, buf, buflen) < 0)
+		goto enospc;
+	if (rdata < edata) {
+		int n = *rdata;
+
+		if (rdata + 1 + n <= edata) {
+			rdata++;
+			while (n-- > 0) {
+				if (strchr("\n\"\\", *rdata) != NULL)
+					if (addstr("\\", (size_t)1, buf, buflen) < 0)
+						goto enospc;
+				if (addstr((const char *)rdata, (size_t)1,
+					   buf, buflen) < 0)
+					goto enospc;
+				rdata++;
+			}
+		}
+	}
+	if (addstr("\"", (size_t)1, buf, buflen) < 0)
+		goto enospc;
+	_DIAGASSERT(__type_fit(int, rdata - odata));
+	return (int)(rdata - odata);
+ enospc:
+	errno = ENOSPC;
+	*buf = save_buf;
+	*buflen = save_buflen;
+	return (-1);
+}
+
+static int
+addname(const u_char *msg, size_t msglen,
+	const u_char **pp, const char *origin,
+	char **buf, size_t *buflen)
+{
+	size_t newlen, save_buflen = *buflen;
+	char *save_buf = *buf;
+	int n;
+
+	n = dn_expand(msg, msg + msglen, *pp, *buf, (int)*buflen);
+	if (n < 0)
+		goto enospc;	/* Guess. */
+	newlen = prune_origin(*buf, origin);
+	if (**buf == '\0') {
+		goto root;
+	} else if (newlen == 0U) {
+		/* Use "@" instead of name. */
+		if (newlen + 2 > *buflen)
+			goto enospc;        /* No room for "@\0". */
+		(*buf)[newlen++] = '@';
+		(*buf)[newlen] = '\0';
+	} else {
+		if (((origin == NULL || origin[0] == '\0') ||
+		    (origin[0] != '.' && origin[1] != '\0' &&
+		    (*buf)[newlen] == '\0')) && (*buf)[newlen - 1] != '.') {
+			/* No trailing dot. */
+ root:
+			if (newlen + 2 > *buflen)
+				goto enospc;	/* No room for ".\0". */
+			(*buf)[newlen++] = '.';
+			(*buf)[newlen] = '\0';
+		}
+	}
+	*pp += n;
+	addlen(newlen, buf, buflen);
+	**buf = '\0';
+	_DIAGASSERT(__type_fit(int, newlen));
+	return (int)newlen;
+ enospc:
+	errno = ENOSPC;
+	*buf = save_buf;
+	*buflen = save_buflen;
+	return (-1);
+}
+
+static void
+addlen(size_t len, char **buf, size_t *buflen) {
+	assert(len <= *buflen);
+	*buf += len;
+	*buflen -= len;
+}
+
+static int
+addstr(const char *src, size_t len, char **buf, size_t *buflen) {
+	if (len >= *buflen) {
+		errno = ENOSPC;
+		return (-1);
+	}
+	memcpy(*buf, src, len);
+	addlen(len, buf, buflen);
+	**buf = '\0';
+	return (0);
+}
+
+static int
+addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) {
+	size_t save_buflen = *buflen;
+	char *save_buf = *buf;
+	ptrdiff_t t;
+
+	if (spaced || len >= target - 1) {
+		T(addstr("  ", (size_t)2, buf, buflen));
+		spaced = 1;
+	} else {
+		for (t = (target - len - 1) / 8; t >= 0; t--)
+			if (addstr("\t", (size_t)1, buf, buflen) < 0) {
+				*buflen = save_buflen;
+				*buf = save_buf;
+				return (-1);
+			}
+		spaced = 0;
+	}
+	return (spaced);
+}
diff --git a/libc/dns/nameser/ns_samedomain.c b/libc/dns/nameser/ns_samedomain.c
new file mode 100644
index 0000000..0be0c28
--- /dev/null
+++ b/libc/dns/nameser/ns_samedomain.c
@@ -0,0 +1,210 @@
+/*	$NetBSD: ns_samedomain.c,v 1.8 2012/11/22 20:22:31 christos Exp $	*/
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1995,1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#ifdef notdef
+static const char rcsid[] = "Id: ns_samedomain.c,v 1.6 2005/04/27 04:56:40 sra Exp";
+#else
+__RCSID("$NetBSD: ns_samedomain.c,v 1.8 2012/11/22 20:22:31 christos Exp $");
+#endif
+#endif
+
+#include <sys/types.h>
+#include <arpa/nameser.h>
+#include <errno.h>
+#include <string.h>
+
+#ifdef _LIBRESOLV
+/*
+ *	Check whether a name belongs to a domain.
+ *
+ * Inputs:
+ *	a - the domain whose ancestory is being verified
+ *	b - the potential ancestor we're checking against
+ *
+ * Return:
+ *	boolean - is a at or below b?
+ *
+ * Notes:
+ *	Trailing dots are first removed from name and domain.
+ *	Always compare complete subdomains, not only whether the
+ *	domain name is the trailing string of the given name.
+ *
+ *	"host.foobar.top" lies in "foobar.top" and in "top" and in ""
+ *	but NOT in "bar.top"
+ */
+
+int
+ns_samedomain(const char *a, const char *b) {
+	size_t la, lb, i;
+	int diff, escaped;
+	const char *cp;
+
+	la = strlen(a);
+	lb = strlen(b);
+
+	/* Ignore a trailing label separator (i.e. an unescaped dot) in 'a'. */
+	if (la != 0U && a[la - 1] == '.') {
+		escaped = 0;
+		/* Note this loop doesn't get executed if la==1. */
+		for (i = la - 1; i > 0; i--)
+			if (a[i - 1] == '\\') {
+				if (escaped)
+					escaped = 0;
+				else
+					escaped = 1;
+			} else
+				break;
+		if (!escaped)
+			la--;
+	}
+
+	/* Ignore a trailing label separator (i.e. an unescaped dot) in 'b'. */
+	if (lb != 0U && b[lb - 1] == '.') {
+		escaped = 0;
+		/* note this loop doesn't get executed if lb==1 */
+		for (i = lb - 1; i > 0; i--)
+			if (b[i - 1] == '\\') {
+				if (escaped)
+					escaped = 0;
+				else
+					escaped = 1;
+			} else
+				break;
+		if (!escaped)
+			lb--;
+	}
+
+	/* lb == 0 means 'b' is the root domain, so 'a' must be in 'b'. */
+	if (lb == 0U)
+		return (1);
+
+	/* 'b' longer than 'a' means 'a' can't be in 'b'. */
+	if (lb > la)
+		return (0);
+
+	/* 'a' and 'b' being equal at this point indicates sameness. */
+	if (lb == la)
+		return (strncasecmp(a, b, lb) == 0);
+
+	/* Ok, we know la > lb. */
+
+	diff = (int)(la - lb);
+
+	/*
+	 * If 'a' is only 1 character longer than 'b', then it can't be
+	 * a subdomain of 'b' (because of the need for the '.' label
+	 * separator).
+	 */
+	if (diff < 2)
+		return (0);
+
+	/*
+	 * If the character before the last 'lb' characters of 'b'
+	 * isn't '.', then it can't be a match (this lets us avoid
+	 * having "foobar.com" match "bar.com").
+	 */
+	if (a[diff - 1] != '.')
+		return (0);
+
+	/*
+	 * We're not sure about that '.', however.  It could be escaped
+         * and thus not a really a label separator.
+	 */
+	escaped = 0;
+	for (i = diff - 1; i > 0; i--)
+		if (a[i - 1] == '\\') {
+			if (escaped)
+				escaped = 0;
+			else
+				escaped = 1;
+		} else
+			break;
+	if (escaped)
+		return (0);
+
+	/* Now compare aligned trailing substring. */
+	cp = a + diff;
+	return (strncasecmp(cp, b, lb) == 0);
+}
+
+/*
+ *	is "a" a subdomain of "b"?
+ */
+int
+ns_subdomain(const char *a, const char *b) {
+	return (ns_samename(a, b) != 1 && ns_samedomain(a, b));
+}
+#endif
+
+#ifdef _LIBC
+/*
+ *	make a canonical copy of domain name "src"
+ *
+ * notes:
+ *	foo -> foo.
+ *	foo. -> foo.
+ *	foo.. -> foo.
+ *	foo\. -> foo\..
+ *	foo\\. -> foo\\.
+ */
+
+int
+ns_makecanon(const char *src, char *dst, size_t dstsize) {
+	size_t n = strlen(src);
+
+	if (n + sizeof "." > dstsize) {			/* Note: sizeof == 2 */
+		errno = EMSGSIZE;
+		return (-1);
+	}
+	strcpy(dst, src);
+	while (n >= 1U && dst[n - 1] == '.')		/* Ends in "." */
+		if (n >= 2U && dst[n - 2] == '\\' &&	/* Ends in "\." */
+		    (n < 3U || dst[n - 3] != '\\'))	/* But not "\\." */
+			break;
+		else
+			dst[--n] = '\0';
+	dst[n++] = '.';
+	dst[n] = '\0';
+	return (0);
+}
+
+/*
+ *	determine whether domain name "a" is the same as domain name "b"
+ *
+ * return:
+ *	-1 on error
+ *	0 if names differ
+ *	1 if names are the same
+ */
+
+int
+ns_samename(const char *a, const char *b) {
+	char ta[NS_MAXDNAME], tb[NS_MAXDNAME];
+
+	if (ns_makecanon(a, ta, sizeof ta) < 0 ||
+	    ns_makecanon(b, tb, sizeof tb) < 0)
+		return (-1);
+	if (strcasecmp(ta, tb) == 0)
+		return (1);
+	else
+		return (0);
+}
+#endif
diff --git a/libc/dns/nameser/ns_ttl.c b/libc/dns/nameser/ns_ttl.c
new file mode 100644
index 0000000..2395b99
--- /dev/null
+++ b/libc/dns/nameser/ns_ttl.c
@@ -0,0 +1,167 @@
+/*	$NetBSD: ns_ttl.c,v 1.8 2012/03/13 21:13:39 christos Exp $	*/
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#ifdef notdef
+static const char rcsid[] = "Id: ns_ttl.c,v 1.4 2005/07/28 06:51:49 marka Exp";
+#else
+__RCSID("$NetBSD: ns_ttl.c,v 1.8 2012/03/13 21:13:39 christos Exp $");
+#endif
+#endif
+
+/* Import. */
+
+#include <arpa/nameser.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+/* Forward. */
+
+static int	fmt1(int t, char s, char **buf, size_t *buflen);
+
+/* Macros. */
+
+#define T(x) do { if ((x) < 0) return (-1); } while(0)
+
+/* Public. */
+
+int
+ns_format_ttl(u_long src, char *dst, size_t dstlen) {
+	char *odst = dst;
+	int secs, mins, hours, days, weeks, x;
+	char *p;
+
+	secs = (int)(src % 60);   src /= 60;
+	mins = (int)(src % 60);   src /= 60;
+	hours = (int)(src % 24);  src /= 24;
+	days = (int)(src % 7);    src /= 7;
+	weeks = (int)src;       src = 0;
+
+	x = 0;
+	if (weeks) {
+		T(fmt1(weeks, 'W', &dst, &dstlen));
+		x++;
+	}
+	if (days) {
+		T(fmt1(days, 'D', &dst, &dstlen));
+		x++;
+	}
+	if (hours) {
+		T(fmt1(hours, 'H', &dst, &dstlen));
+		x++;
+	}
+	if (mins) {
+		T(fmt1(mins, 'M', &dst, &dstlen));
+		x++;
+	}
+	if (secs || !(weeks || days || hours || mins)) {
+		T(fmt1(secs, 'S', &dst, &dstlen));
+		x++;
+	}
+
+	if (x > 1) {
+		int ch;
+
+		for (p = odst; (ch = *p) != '\0'; p++)
+			if (isascii(ch) && isupper(ch))
+				*p = tolower(ch);
+	}
+
+	_DIAGASSERT(__type_fit(int, dst - odst));
+	return (int)(dst - odst);
+}
+
+#ifndef _LIBC
+int
+ns_parse_ttl(const char *src, u_long *dst) {
+	u_long ttl, tmp;
+	int ch, digits, dirty;
+
+	ttl = 0;
+	tmp = 0;
+	digits = 0;
+	dirty = 0;
+	while ((ch = *src++) != '\0') {
+		if (!isascii(ch) || !isprint(ch))
+			goto einval;
+		if (isdigit(ch)) {
+			tmp *= 10;
+			tmp += (ch - '0');
+			digits++;
+			continue;
+		}
+		if (digits == 0)
+			goto einval;
+		if (islower(ch))
+			ch = toupper(ch);
+		switch (ch) {
+		case 'W':  tmp *= 7;	/*FALLTHROUGH*/
+		case 'D':  tmp *= 24;	/*FALLTHROUGH*/
+		case 'H':  tmp *= 60;	/*FALLTHROUGH*/
+		case 'M':  tmp *= 60;	/*FALLTHROUGH*/
+		case 'S':  break;
+		default:   goto einval;
+		}
+		ttl += tmp;
+		tmp = 0;
+		digits = 0;
+		dirty = 1;
+	}
+	if (digits > 0) {
+		if (dirty)
+			goto einval;
+		else
+			ttl += tmp;
+	} else if (!dirty)
+		goto einval;
+	*dst = ttl;
+	return (0);
+
+ einval:
+	errno = EINVAL;
+	return (-1);
+}
+#endif
+
+/* Private. */
+
+static int
+fmt1(int t, char s, char **buf, size_t *buflen) {
+	char tmp[50];
+	size_t len;
+
+	len = SPRINTF((tmp, "%d%c", t, s));
+	if (len + 1 > *buflen)
+		return (-1);
+	strcpy(*buf, tmp);
+	*buf += len;
+	*buflen -= len;
+	return (0);
+}
diff --git a/libc/dns/net/base64.c b/libc/dns/net/base64.c
new file mode 100644
index 0000000..1886986
--- /dev/null
+++ b/libc/dns/net/base64.c
@@ -0,0 +1,340 @@
+/*	$NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $	*/
+
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM 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.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <assert.h>
+#include <ctype.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <stdio.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+static const char Base64[] =
+	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char Pad64 = '=';
+
+/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
+   The following encoding technique is taken from RFC 1521 by Borenstein
+   and Freed.  It is reproduced here in a slightly edited form for
+   convenience.
+
+   A 65-character subset of US-ASCII is used, enabling 6 bits to be
+   represented per printable character. (The extra 65th character, "=",
+   is used to signify a special processing function.)
+
+   The encoding process represents 24-bit groups of input bits as output
+   strings of 4 encoded characters. Proceeding from left to right, a
+   24-bit input group is formed by concatenating 3 8-bit input groups.
+   These 24 bits are then treated as 4 concatenated 6-bit groups, each
+   of which is translated into a single digit in the base64 alphabet.
+
+   Each 6-bit group is used as an index into an array of 64 printable
+   characters. The character referenced by the index is placed in the
+   output string.
+
+                         Table 1: The Base64 Alphabet
+
+      Value Encoding  Value Encoding  Value Encoding  Value Encoding
+          0 A            17 R            34 i            51 z
+          1 B            18 S            35 j            52 0
+          2 C            19 T            36 k            53 1
+          3 D            20 U            37 l            54 2
+          4 E            21 V            38 m            55 3
+          5 F            22 W            39 n            56 4
+          6 G            23 X            40 o            57 5
+          7 H            24 Y            41 p            58 6
+          8 I            25 Z            42 q            59 7
+          9 J            26 a            43 r            60 8
+         10 K            27 b            44 s            61 9
+         11 L            28 c            45 t            62 +
+         12 M            29 d            46 u            63 /
+         13 N            30 e            47 v
+         14 O            31 f            48 w         (pad) =
+         15 P            32 g            49 x
+         16 Q            33 h            50 y
+
+   Special processing is performed if fewer than 24 bits are available
+   at the end of the data being encoded.  A full encoding quantum is
+   always completed at the end of a quantity.  When fewer than 24 input
+   bits are available in an input group, zero bits are added (on the
+   right) to form an integral number of 6-bit groups.  Padding at the
+   end of the data is performed using the '=' character.
+
+   Since all base64 input is an integral number of octets, only the
+         -------------------------------------------------
+   following cases can arise:
+
+       (1) the final quantum of encoding input is an integral
+           multiple of 24 bits; here, the final unit of encoded
+	   output will be an integral multiple of 4 characters
+	   with no "=" padding,
+       (2) the final quantum of encoding input is exactly 8 bits;
+           here, the final unit of encoded output will be two
+	   characters followed by two "=" padding characters, or
+       (3) the final quantum of encoding input is exactly 16 bits;
+           here, the final unit of encoded output will be three
+	   characters followed by one "=" padding character.
+   */
+
+int
+b64_ntop(src, srclength, target, targsize)
+	u_char const *src;
+	size_t srclength;
+	char *target;
+	size_t targsize;
+{
+	size_t datalength = 0;
+	u_char input[3] = { 0, 0, 0 };  /* make compiler happy */
+	u_char output[4];
+	size_t i;
+
+	assert(src != NULL);
+	assert(target != NULL);
+
+	while (2 < srclength) {
+		input[0] = *src++;
+		input[1] = *src++;
+		input[2] = *src++;
+		srclength -= 3;
+
+		output[0] = (u_int32_t)input[0] >> 2;
+		output[1] = ((u_int32_t)(input[0] & 0x03) << 4) +
+		    ((u_int32_t)input[1] >> 4);
+		output[2] = ((u_int32_t)(input[1] & 0x0f) << 2) +
+		    ((u_int32_t)input[2] >> 6);
+		output[3] = input[2] & 0x3f;
+		assert(output[0] < 64);
+		assert(output[1] < 64);
+		assert(output[2] < 64);
+		assert(output[3] < 64);
+
+		if (datalength + 4 > targsize)
+			return (-1);
+		target[datalength++] = Base64[output[0]];
+		target[datalength++] = Base64[output[1]];
+		target[datalength++] = Base64[output[2]];
+		target[datalength++] = Base64[output[3]];
+	}
+
+	/* Now we worry about padding. */
+	if (0 != srclength) {
+		/* Get what's left. */
+		input[0] = input[1] = input[2] = '\0';
+		for (i = 0; i < srclength; i++)
+			input[i] = *src++;
+
+		output[0] = (u_int32_t)input[0] >> 2;
+		output[1] = ((u_int32_t)(input[0] & 0x03) << 4) +
+		    ((u_int32_t)input[1] >> 4);
+		output[2] = ((u_int32_t)(input[1] & 0x0f) << 2) +
+		    ((u_int32_t)input[2] >> 6);
+		assert(output[0] < 64);
+		assert(output[1] < 64);
+		assert(output[2] < 64);
+
+		if (datalength + 4 > targsize)
+			return (-1);
+		target[datalength++] = Base64[output[0]];
+		target[datalength++] = Base64[output[1]];
+		if (srclength == 1)
+			target[datalength++] = Pad64;
+		else
+			target[datalength++] = Base64[output[2]];
+		target[datalength++] = Pad64;
+	}
+	if (datalength >= targsize)
+		return (-1);
+	target[datalength] = '\0';	/* Returned value doesn't count \0. */
+	return (datalength);
+}
+
+/* skips all whitespace anywhere.
+   converts characters, four at a time, starting at (or after)
+   src from base - 64 numbers into three 8 bit bytes in the target area.
+   it returns the number of data bytes stored at the target, or -1 on error.
+ */
+
+int
+b64_pton(src, target, targsize)
+	char const *src;
+	u_char *target;
+	size_t targsize;
+{
+	size_t tarindex;
+	int state, ch;
+	char *pos;
+
+	assert(src != NULL);
+	assert(target != NULL);
+
+	state = 0;
+	tarindex = 0;
+
+	while ((ch = (u_char) *src++) != '\0') {
+		if (isspace(ch))	/* Skip whitespace anywhere. */
+			continue;
+
+		if (ch == Pad64)
+			break;
+
+		pos = strchr(Base64, ch);
+		if (pos == 0) 		/* A non-base64 character. */
+			return (-1);
+
+		switch (state) {
+		case 0:
+			if (target) {
+				if (tarindex >= targsize)
+					return (-1);
+				target[tarindex] = (pos - Base64) << 2;
+			}
+			state = 1;
+			break;
+		case 1:
+			if (target) {
+				if (tarindex + 1 >= targsize)
+					return (-1);
+				target[tarindex] |=
+				    (u_int32_t)(pos - Base64) >> 4;
+				target[tarindex+1]  = ((pos - Base64) & 0x0f)
+							<< 4 ;
+			}
+			tarindex++;
+			state = 2;
+			break;
+		case 2:
+			if (target) {
+				if (tarindex + 1 >= targsize)
+					return (-1);
+				target[tarindex] |=
+					(u_int32_t)(pos - Base64) >> 2;
+				target[tarindex+1] = ((pos - Base64) & 0x03)
+							<< 6;
+			}
+			tarindex++;
+			state = 3;
+			break;
+		case 3:
+			if (target) {
+				if (tarindex >= targsize)
+					return (-1);
+				target[tarindex] |= (pos - Base64);
+			}
+			tarindex++;
+			state = 0;
+			break;
+		default:
+			abort();
+		}
+	}
+
+	/*
+	 * We are done decoding Base-64 chars.  Let's see if we ended
+	 * on a byte boundary, and/or with erroneous trailing characters.
+	 */
+
+	if (ch == Pad64) {		/* We got a pad char. */
+		ch = *src++;		/* Skip it, get next. */
+		switch (state) {
+		case 0:		/* Invalid = in first position */
+		case 1:		/* Invalid = in second position */
+			return (-1);
+
+		case 2:		/* Valid, means one byte of info */
+			/* Skip any number of spaces. */
+			for (; ch != '\0'; ch = (u_char) *src++)
+				if (!isspace(ch))
+					break;
+			/* Make sure there is another trailing = sign. */
+			if (ch != Pad64)
+				return (-1);
+			ch = *src++;		/* Skip the = */
+			/* Fall through to "single trailing =" case. */
+			/* FALLTHROUGH */
+
+		case 3:		/* Valid, means two bytes of info */
+			/*
+			 * We know this char is an =.  Is there anything but
+			 * whitespace after it?
+			 */
+			for (; ch != '\0'; ch = (u_char) *src++)
+				if (!isspace(ch))
+					return (-1);
+
+			/*
+			 * Now make sure for cases 2 and 3 that the "extra"
+			 * bits that slopped past the last full byte were
+			 * zeros.  If we don't check them, they become a
+			 * subliminal channel.
+			 */
+			if (target && target[tarindex] != 0)
+				return (-1);
+		}
+	} else {
+		/*
+		 * We ended by seeing the end of the string.  Make sure we
+		 * have no partial bytes lying around.
+		 */
+		if (state != 0)
+			return (-1);
+	}
+
+	return (tarindex);
+}
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
new file mode 100644
index 0000000..2612d6a
--- /dev/null
+++ b/libc/dns/net/getaddrinfo.c
@@ -0,0 +1,2438 @@
+/*	$NetBSD: getaddrinfo.c,v 1.82 2006/03/25 12:09:40 rpaulo Exp $	*/
+/*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
+
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Issues to be discussed:
+ * - Thread safe-ness must be checked.
+ * - Return values.  There are nonstandard return values defined and used
+ *   in the source code.  This is because RFC2553 is silent about which error
+ *   code must be returned for which situation.
+ * - IPv4 classful (shortened) form.  RFC2553 is silent about it.  XNET 5.2
+ *   says to use inet_aton() to convert IPv4 numeric to binary (alows
+ *   classful form as a result).
+ *   current code - disallow classful form for IPv4 (due to use of inet_pton).
+ * - freeaddrinfo(NULL).  RFC2553 is silent about it.  XNET 5.2 says it is
+ *   invalid.
+ *   current code - SEGV on freeaddrinfo(NULL)
+ * Note:
+ * - We use getipnodebyname() just for thread-safeness.  There's no intent
+ *   to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to
+ *   getipnodebyname().
+ * - The code filters out AFs that are not supported by the kernel,
+ *   when globbing NULL hostname (to loopback, or wildcard).  Is it the right
+ *   thing to do?  What is the relationship with post-RFC2553 AI_ADDRCONFIG
+ *   in ai_flags?
+ * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague.
+ *   (1) what should we do against numeric hostname (2) what should we do
+ *   against NULL hostname (3) what is AI_ADDRCONFIG itself.  AF not ready?
+ *   non-loopback address configured?  global address configured?
+ * - To avoid search order issue, we have a big amount of code duplicate
+ *   from gethnamaddr.c and some other places.  The issues that there's no
+ *   lower layer function to lookup "IPv4 or IPv6" record.  Calling
+ *   gethostbyname2 from getaddrinfo will end up in wrong search order, as
+ *   follows:
+ *	- The code makes use of following calls when asked to resolver with
+ *	  ai_family  = PF_UNSPEC:
+ *		getipnodebyname(host, AF_INET6);
+ *		getipnodebyname(host, AF_INET);
+ *	  This will result in the following queries if the node is configure to
+ *	  prefer /etc/hosts than DNS:
+ *		lookup /etc/hosts for IPv6 address
+ *		lookup DNS for IPv6 address
+ *		lookup /etc/hosts for IPv4 address
+ *		lookup DNS for IPv4 address
+ *	  which may not meet people's requirement.
+ *	  The right thing to happen is to have underlying layer which does
+ *	  PF_UNSPEC lookup (lookup both) and return chain of addrinfos.
+ *	  This would result in a bit of code duplicate with _dns_ghbyname() and
+ *	  friends.
+ */
+
+#include <fcntl.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include "NetdClientDispatch.h"
+#include "resolv_cache.h"
+#include "resolv_netid.h"
+#include "resolv_private.h"
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+
+#include <syslog.h>
+#include <stdarg.h>
+#include "nsswitch.h"
+
+#ifdef ANDROID_CHANGES
+#include <sys/system_properties.h>
+#endif /* ANDROID_CHANGES */
+
+typedef union sockaddr_union {
+    struct sockaddr     generic;
+    struct sockaddr_in  in;
+    struct sockaddr_in6 in6;
+} sockaddr_union;
+
+#define SUCCESS 0
+#define ANY 0
+#define YES 1
+#define NO  0
+
+static const char in_addrany[] = { 0, 0, 0, 0 };
+static const char in_loopback[] = { 127, 0, 0, 1 };
+#ifdef INET6
+static const char in6_addrany[] = {
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+static const char in6_loopback[] = {
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
+};
+#endif
+
+// This should be synchronized to ResponseCode.h
+static const int DnsProxyQueryResult = 222;
+
+static const struct afd {
+	int a_af;
+	int a_addrlen;
+	int a_socklen;
+	int a_off;
+	const char *a_addrany;
+	const char *a_loopback;
+	int a_scoped;
+} afdl [] = {
+#ifdef INET6
+	{PF_INET6, sizeof(struct in6_addr),
+	 sizeof(struct sockaddr_in6),
+	 offsetof(struct sockaddr_in6, sin6_addr),
+	 in6_addrany, in6_loopback, 1},
+#endif
+	{PF_INET, sizeof(struct in_addr),
+	 sizeof(struct sockaddr_in),
+	 offsetof(struct sockaddr_in, sin_addr),
+	 in_addrany, in_loopback, 0},
+	{0, 0, 0, 0, NULL, NULL, 0},
+};
+
+struct explore {
+	int e_af;
+	int e_socktype;
+	int e_protocol;
+	const char *e_protostr;
+	int e_wild;
+#define WILD_AF(ex)		((ex)->e_wild & 0x01)
+#define WILD_SOCKTYPE(ex)	((ex)->e_wild & 0x02)
+#define WILD_PROTOCOL(ex)	((ex)->e_wild & 0x04)
+};
+
+static const struct explore explore[] = {
+#if 0
+	{ PF_LOCAL, 0, ANY, ANY, NULL, 0x01 },
+#endif
+#ifdef INET6
+	{ PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
+	{ PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
+	{ PF_INET6, SOCK_RAW, ANY, NULL, 0x05 },
+#endif
+	{ PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
+	{ PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
+	{ PF_INET, SOCK_RAW, ANY, NULL, 0x05 },
+	{ PF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
+	{ PF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
+	{ PF_UNSPEC, SOCK_RAW, ANY, NULL, 0x05 },
+	{ -1, 0, 0, NULL, 0 },
+};
+
+#ifdef INET6
+#define PTON_MAX	16
+#else
+#define PTON_MAX	4
+#endif
+
+static const ns_src default_dns_files[] = {
+	{ NSSRC_FILES, 	NS_SUCCESS },
+	{ NSSRC_DNS, 	NS_SUCCESS },
+	{ 0, 0 }
+};
+
+#define MAXPACKET	(64*1024)
+
+typedef union {
+	HEADER hdr;
+	u_char buf[MAXPACKET];
+} querybuf;
+
+struct res_target {
+	struct res_target *next;
+	const char *name;	/* domain name */
+	int qclass, qtype;	/* class and type of query */
+	u_char *answer;		/* buffer to put answer */
+	int anslen;		/* size of answer buffer */
+	int n;			/* result length */
+};
+
+static int str2number(const char *);
+static int explore_fqdn(const struct addrinfo *, const char *,
+	const char *, struct addrinfo **, unsigned netid, unsigned mark);
+static int explore_null(const struct addrinfo *,
+	const char *, struct addrinfo **);
+static int explore_numeric(const struct addrinfo *, const char *,
+	const char *, struct addrinfo **, const char *);
+static int explore_numeric_scope(const struct addrinfo *, const char *,
+	const char *, struct addrinfo **);
+static int get_canonname(const struct addrinfo *,
+	struct addrinfo *, const char *);
+static struct addrinfo *get_ai(const struct addrinfo *,
+	const struct afd *, const char *);
+static int get_portmatch(const struct addrinfo *, const char *);
+static int get_port(const struct addrinfo *, const char *, int);
+static const struct afd *find_afd(int);
+#ifdef INET6
+static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *);
+#endif
+
+static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
+	const struct addrinfo *);
+static int _dns_getaddrinfo(void *, void *, va_list);
+static void _sethtent(FILE **);
+static void _endhtent(FILE **);
+static struct addrinfo *_gethtent(FILE **, const char *,
+    const struct addrinfo *);
+static int _files_getaddrinfo(void *, void *, va_list);
+
+static int res_queryN(const char *, struct res_target *, res_state);
+static int res_searchN(const char *, struct res_target *, res_state);
+static int res_querydomainN(const char *, const char *,
+	struct res_target *, res_state);
+
+static const char * const ai_errlist[] = {
+	"Success",
+	"Address family for hostname not supported",	/* EAI_ADDRFAMILY */
+	"Temporary failure in name resolution",		/* EAI_AGAIN      */
+	"Invalid value for ai_flags",		       	/* EAI_BADFLAGS   */
+	"Non-recoverable failure in name resolution", 	/* EAI_FAIL       */
+	"ai_family not supported",			/* EAI_FAMILY     */
+	"Memory allocation failure", 			/* EAI_MEMORY     */
+	"No address associated with hostname", 		/* EAI_NODATA     */
+	"hostname nor servname provided, or not known",	/* EAI_NONAME     */
+	"servname not supported for ai_socktype",	/* EAI_SERVICE    */
+	"ai_socktype not supported", 			/* EAI_SOCKTYPE   */
+	"System error returned in errno", 		/* EAI_SYSTEM     */
+	"Invalid value for hints",			/* EAI_BADHINTS	  */
+	"Resolved protocol is unknown",			/* EAI_PROTOCOL   */
+	"Argument buffer overflow",			/* EAI_OVERFLOW   */
+	"Unknown error", 				/* EAI_MAX        */
+};
+
+/* XXX macros that make external reference is BAD. */
+
+#define GET_AI(ai, afd, addr) 					\
+do { 								\
+	/* external reference: pai, error, and label free */ 	\
+	(ai) = get_ai(pai, (afd), (addr)); 			\
+	if ((ai) == NULL) { 					\
+		error = EAI_MEMORY; 				\
+		goto free; 					\
+	} 							\
+} while (/*CONSTCOND*/0)
+
+#define GET_PORT(ai, serv) 					\
+do { 								\
+	/* external reference: error and label free */ 		\
+	error = get_port((ai), (serv), 0); 			\
+	if (error != 0) 					\
+		goto free; 					\
+} while (/*CONSTCOND*/0)
+
+#define GET_CANONNAME(ai, str) 					\
+do { 								\
+	/* external reference: pai, error and label free */ 	\
+	error = get_canonname(pai, (ai), (str)); 		\
+	if (error != 0) 					\
+		goto free; 					\
+} while (/*CONSTCOND*/0)
+
+#define ERR(err) 						\
+do { 								\
+	/* external reference: error, and label bad */ 		\
+	error = (err); 						\
+	goto bad; 						\
+	/*NOTREACHED*/ 						\
+} while (/*CONSTCOND*/0)
+
+#define MATCH_FAMILY(x, y, w) 						\
+	((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || 	\
+	    (y) == PF_UNSPEC)))
+#define MATCH(x, y, w) 							\
+	((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY)))
+
+const char *
+gai_strerror(int ecode)
+{
+	if (ecode < 0 || ecode > EAI_MAX)
+		ecode = EAI_MAX;
+	return ai_errlist[ecode];
+}
+
+void
+freeaddrinfo(struct addrinfo *ai)
+{
+	struct addrinfo *next;
+
+	assert(ai != NULL);
+
+	do {
+		next = ai->ai_next;
+		if (ai->ai_canonname)
+			free(ai->ai_canonname);
+		/* no need to free(ai->ai_addr) */
+		free(ai);
+		ai = next;
+	} while (ai);
+}
+
+static int
+str2number(const char *p)
+{
+	char *ep;
+	unsigned long v;
+
+	assert(p != NULL);
+
+	if (*p == '\0')
+		return -1;
+	ep = NULL;
+	errno = 0;
+	v = strtoul(p, &ep, 10);
+	if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX)
+		return v;
+	else
+		return -1;
+}
+
+/*
+ * Connect a UDP socket to a given unicast address. This will cause no network
+ * traffic, but will fail fast if the system has no or limited reachability to
+ * the destination (e.g., no IPv4 address, no IPv6 default route, ...).
+ */
+static int
+_test_connect(int pf, struct sockaddr *addr, size_t addrlen, unsigned mark) {
+	int s = socket(pf, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
+	if (s < 0)
+		return 0;
+	if (mark != MARK_UNSET && setsockopt(s, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0)
+		return 0;
+	int ret;
+	do {
+		ret = __connect(s, addr, addrlen);
+	} while (ret < 0 && errno == EINTR);
+	int success = (ret == 0);
+	do {
+		ret = close(s);
+	} while (ret < 0 && errno == EINTR);
+	return success;
+}
+
+/*
+ * The following functions determine whether IPv4 or IPv6 connectivity is
+ * available in order to implement AI_ADDRCONFIG.
+ *
+ * Strictly speaking, AI_ADDRCONFIG should not look at whether connectivity is
+ * available, but whether addresses of the specified family are "configured
+ * on the local system". However, bionic doesn't currently support getifaddrs,
+ * so checking for connectivity is the next best thing.
+ */
+static int
+_have_ipv6(unsigned mark) {
+	static const struct sockaddr_in6 sin6_test = {
+		.sin6_family = AF_INET6,
+		.sin6_addr.s6_addr = {  // 2000::
+			0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+		};
+	sockaddr_union addr = { .in6 = sin6_test };
+	return _test_connect(PF_INET6, &addr.generic, sizeof(addr.in6), mark);
+}
+
+static int
+_have_ipv4(unsigned mark) {
+	static const struct sockaddr_in sin_test = {
+		.sin_family = AF_INET,
+		.sin_addr.s_addr = __constant_htonl(0x08080808L)  // 8.8.8.8
+	};
+	sockaddr_union addr = { .in = sin_test };
+	return _test_connect(PF_INET, &addr.generic, sizeof(addr.in), mark);
+}
+
+// Returns 0 on success, else returns on error.
+static int
+android_getaddrinfo_proxy(
+    const char *hostname, const char *servname,
+    const struct addrinfo *hints, struct addrinfo **res, unsigned netid)
+{
+	int sock;
+	const int one = 1;
+	struct sockaddr_un proxy_addr;
+	FILE* proxy = NULL;
+	int success = 0;
+
+	// Clear this at start, as we use its non-NULLness later (in the
+	// error path) to decide if we have to free up any memory we
+	// allocated in the process (before failing).
+	*res = NULL;
+
+	// Bogus things we can't serialize.  Don't use the proxy.  These will fail - let them.
+	if ((hostname != NULL &&
+	     strcspn(hostname, " \n\r\t^'\"") != strlen(hostname)) ||
+	    (servname != NULL &&
+	     strcspn(servname, " \n\r\t^'\"") != strlen(servname))) {
+		return EAI_NODATA;
+	}
+
+	sock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+	if (sock < 0) {
+		return EAI_NODATA;
+	}
+
+	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+	memset(&proxy_addr, 0, sizeof(proxy_addr));
+	proxy_addr.sun_family = AF_UNIX;
+	strlcpy(proxy_addr.sun_path, "/dev/socket/dnsproxyd",
+		sizeof(proxy_addr.sun_path));
+	if (TEMP_FAILURE_RETRY(connect(sock,
+				       (const struct sockaddr*) &proxy_addr,
+				       sizeof(proxy_addr))) != 0) {
+		close(sock);
+		return EAI_NODATA;
+	}
+
+	netid = __netdClientDispatch.netIdForResolv(netid);
+
+	// Send the request.
+	proxy = fdopen(sock, "r+");
+	if (fprintf(proxy, "getaddrinfo %s %s %d %d %d %d %u",
+		    hostname == NULL ? "^" : hostname,
+		    servname == NULL ? "^" : servname,
+		    hints == NULL ? -1 : hints->ai_flags,
+		    hints == NULL ? -1 : hints->ai_family,
+		    hints == NULL ? -1 : hints->ai_socktype,
+		    hints == NULL ? -1 : hints->ai_protocol,
+		    netid) < 0) {
+		goto exit;
+	}
+	// literal NULL byte at end, required by FrameworkListener
+	if (fputc(0, proxy) == EOF ||
+	    fflush(proxy) != 0) {
+		goto exit;
+	}
+
+	char buf[4];
+	// read result code for gethostbyaddr
+	if (fread(buf, 1, sizeof(buf), proxy) != sizeof(buf)) {
+		goto exit;
+	}
+
+	int result_code = (int)strtol(buf, NULL, 10);
+	// verify the code itself
+	if (result_code != DnsProxyQueryResult ) {
+		fread(buf, 1, sizeof(buf), proxy);
+		goto exit;
+	}
+
+	struct addrinfo* ai = NULL;
+	struct addrinfo** nextres = res;
+	while (1) {
+		uint32_t addrinfo_len;
+		if (fread(&addrinfo_len, sizeof(addrinfo_len),
+			  1, proxy) != 1) {
+			break;
+		}
+		addrinfo_len = ntohl(addrinfo_len);
+		if (addrinfo_len == 0) {
+			success = 1;
+			break;
+		}
+
+		if (addrinfo_len < sizeof(struct addrinfo)) {
+			break;
+		}
+		struct addrinfo* ai = calloc(1, addrinfo_len +
+					     sizeof(struct sockaddr_storage));
+		if (ai == NULL) {
+			break;
+		}
+
+		if (fread(ai, addrinfo_len, 1, proxy) != 1) {
+			// Error; fall through.
+			break;
+		}
+
+		// Zero out the pointer fields we copied which aren't
+		// valid in this address space.
+		ai->ai_addr = NULL;
+		ai->ai_canonname = NULL;
+		ai->ai_next = NULL;
+
+		// struct sockaddr
+		uint32_t addr_len;
+		if (fread(&addr_len, sizeof(addr_len), 1, proxy) != 1) {
+			break;
+		}
+		addr_len = ntohl(addr_len);
+		if (addr_len != 0) {
+			if (addr_len > sizeof(struct sockaddr_storage)) {
+				// Bogus; too big.
+				break;
+			}
+			struct sockaddr* addr = (struct sockaddr*)(ai + 1);
+			if (fread(addr, addr_len, 1, proxy) != 1) {
+				break;
+			}
+			ai->ai_addr = addr;
+		}
+
+		// cannonname
+		uint32_t name_len;
+		if (fread(&name_len, sizeof(name_len), 1, proxy) != 1) {
+			break;
+		}
+		name_len = ntohl(name_len);
+		if (name_len != 0) {
+			ai->ai_canonname = (char*) malloc(name_len);
+			if (fread(ai->ai_canonname, name_len, 1, proxy) != 1) {
+				break;
+			}
+			if (ai->ai_canonname[name_len - 1] != '\0') {
+				// The proxy should be returning this
+				// NULL-terminated.
+				break;
+			}
+		}
+
+		*nextres = ai;
+		nextres = &ai->ai_next;
+		ai = NULL;
+	}
+
+	if (ai != NULL) {
+		// Clean up partially-built addrinfo that we never ended up
+		// attaching to the response.
+		freeaddrinfo(ai);
+	}
+exit:
+	if (proxy != NULL) {
+		fclose(proxy);
+	}
+
+	if (success) {
+		return 0;
+	}
+
+	// Proxy failed;
+	// clean up memory we might've allocated.
+	if (*res) {
+		freeaddrinfo(*res);
+		*res = NULL;
+	}
+	return EAI_NODATA;
+}
+
+int
+getaddrinfo(const char *hostname, const char *servname,
+    const struct addrinfo *hints, struct addrinfo **res)
+{
+	return android_getaddrinfofornet(hostname, servname, hints, NETID_UNSET, MARK_UNSET, res);
+}
+
+int
+android_getaddrinfofornet(const char *hostname, const char *servname,
+    const struct addrinfo *hints, unsigned netid, unsigned mark, struct addrinfo **res)
+{
+	struct addrinfo sentinel;
+	struct addrinfo *cur;
+	int error = 0;
+	struct addrinfo ai;
+	struct addrinfo ai0;
+	struct addrinfo *pai;
+	const struct explore *ex;
+	const char* cache_mode = getenv("ANDROID_DNS_MODE");
+
+	/* hostname is allowed to be NULL */
+	/* servname is allowed to be NULL */
+	/* hints is allowed to be NULL */
+	assert(res != NULL);
+	memset(&sentinel, 0, sizeof(sentinel));
+	cur = &sentinel;
+	pai = &ai;
+	pai->ai_flags = 0;
+	pai->ai_family = PF_UNSPEC;
+	pai->ai_socktype = ANY;
+	pai->ai_protocol = ANY;
+	pai->ai_addrlen = 0;
+	pai->ai_canonname = NULL;
+	pai->ai_addr = NULL;
+	pai->ai_next = NULL;
+
+	if (hostname == NULL && servname == NULL)
+		return EAI_NONAME;
+	if (hints) {
+		/* error check for hints */
+		if (hints->ai_addrlen || hints->ai_canonname ||
+		    hints->ai_addr || hints->ai_next)
+			ERR(EAI_BADHINTS); /* xxx */
+		if (hints->ai_flags & ~AI_MASK)
+			ERR(EAI_BADFLAGS);
+		switch (hints->ai_family) {
+		case PF_UNSPEC:
+		case PF_INET:
+#ifdef INET6
+		case PF_INET6:
+#endif
+			break;
+		default:
+			ERR(EAI_FAMILY);
+		}
+		memcpy(pai, hints, sizeof(*pai));
+
+		/*
+		 * if both socktype/protocol are specified, check if they
+		 * are meaningful combination.
+		 */
+		if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) {
+			for (ex = explore; ex->e_af >= 0; ex++) {
+				if (pai->ai_family != ex->e_af)
+					continue;
+				if (ex->e_socktype == ANY)
+					continue;
+				if (ex->e_protocol == ANY)
+					continue;
+				if (pai->ai_socktype == ex->e_socktype
+				 && pai->ai_protocol != ex->e_protocol) {
+					ERR(EAI_BADHINTS);
+				}
+			}
+		}
+	}
+
+	/*
+	 * check for special cases.  (1) numeric servname is disallowed if
+	 * socktype/protocol are left unspecified. (2) servname is disallowed
+	 * for raw and other inet{,6} sockets.
+	 */
+	if (MATCH_FAMILY(pai->ai_family, PF_INET, 1)
+#ifdef PF_INET6
+	 || MATCH_FAMILY(pai->ai_family, PF_INET6, 1)
+#endif
+	    ) {
+		ai0 = *pai;	/* backup *pai */
+
+		if (pai->ai_family == PF_UNSPEC) {
+#ifdef PF_INET6
+			pai->ai_family = PF_INET6;
+#else
+			pai->ai_family = PF_INET;
+#endif
+		}
+		error = get_portmatch(pai, servname);
+		if (error)
+			ERR(error);
+
+		*pai = ai0;
+	}
+
+	ai0 = *pai;
+
+	/* NULL hostname, or numeric hostname */
+	for (ex = explore; ex->e_af >= 0; ex++) {
+		*pai = ai0;
+
+		/* PF_UNSPEC entries are prepared for DNS queries only */
+		if (ex->e_af == PF_UNSPEC)
+			continue;
+
+		if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex)))
+			continue;
+		if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex)))
+			continue;
+		if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex)))
+			continue;
+
+		if (pai->ai_family == PF_UNSPEC)
+			pai->ai_family = ex->e_af;
+		if (pai->ai_socktype == ANY && ex->e_socktype != ANY)
+			pai->ai_socktype = ex->e_socktype;
+		if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
+			pai->ai_protocol = ex->e_protocol;
+
+		if (hostname == NULL)
+			error = explore_null(pai, servname, &cur->ai_next);
+		else
+			error = explore_numeric_scope(pai, hostname, servname,
+			    &cur->ai_next);
+
+		if (error)
+			goto free;
+
+		while (cur->ai_next)
+			cur = cur->ai_next;
+	}
+
+	/*
+	 * XXX
+	 * If numeric representation of AF1 can be interpreted as FQDN
+	 * representation of AF2, we need to think again about the code below.
+	 */
+	if (sentinel.ai_next)
+		goto good;
+
+	if (hostname == NULL)
+		ERR(EAI_NODATA);
+	if (pai->ai_flags & AI_NUMERICHOST)
+		ERR(EAI_NONAME);
+
+        /*
+         * BEGIN ANDROID CHANGES; proxying to the cache
+         */
+	if (cache_mode == NULL || strcmp(cache_mode, "local") != 0) {
+		// we're not the proxy - pass the request to them
+		return android_getaddrinfo_proxy(hostname, servname, hints, res, netid);
+	}
+
+	/*
+	 * hostname as alphabetical name.
+	 * we would like to prefer AF_INET6 than AF_INET, so we'll make a
+	 * outer loop by AFs.
+	 */
+	for (ex = explore; ex->e_af >= 0; ex++) {
+		*pai = ai0;
+
+		/* require exact match for family field */
+		if (pai->ai_family != ex->e_af)
+			continue;
+
+		if (!MATCH(pai->ai_socktype, ex->e_socktype,
+				WILD_SOCKTYPE(ex))) {
+			continue;
+		}
+		if (!MATCH(pai->ai_protocol, ex->e_protocol,
+				WILD_PROTOCOL(ex))) {
+			continue;
+		}
+
+		if (pai->ai_socktype == ANY && ex->e_socktype != ANY)
+			pai->ai_socktype = ex->e_socktype;
+		if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
+			pai->ai_protocol = ex->e_protocol;
+
+		error = explore_fqdn(pai, hostname, servname,
+			&cur->ai_next, netid, mark);
+
+		while (cur && cur->ai_next)
+			cur = cur->ai_next;
+	}
+
+	/* XXX */
+	if (sentinel.ai_next)
+		error = 0;
+
+	if (error)
+		goto free;
+	if (error == 0) {
+		if (sentinel.ai_next) {
+ good:
+			*res = sentinel.ai_next;
+			return SUCCESS;
+		} else
+			error = EAI_FAIL;
+	}
+ free:
+ bad:
+	if (sentinel.ai_next)
+		freeaddrinfo(sentinel.ai_next);
+	*res = NULL;
+	return error;
+}
+
+/*
+ * FQDN hostname, DNS lookup
+ */
+static int
+explore_fqdn(const struct addrinfo *pai, const char *hostname,
+    const char *servname, struct addrinfo **res, unsigned netid, unsigned mark)
+{
+	struct addrinfo *result;
+	struct addrinfo *cur;
+	int error = 0;
+	static const ns_dtab dtab[] = {
+		NS_FILES_CB(_files_getaddrinfo, NULL)
+		{ NSSRC_DNS, _dns_getaddrinfo, NULL },	/* force -DHESIOD */
+		NS_NIS_CB(_yp_getaddrinfo, NULL)
+		{ 0, 0, 0 }
+	};
+
+	assert(pai != NULL);
+	/* hostname may be NULL */
+	/* servname may be NULL */
+	assert(res != NULL);
+
+	result = NULL;
+
+	/*
+	 * if the servname does not match socktype/protocol, ignore it.
+	 */
+	if (get_portmatch(pai, servname) != 0)
+		return 0;
+
+	switch (nsdispatch(&result, dtab, NSDB_HOSTS, "getaddrinfo",
+			default_dns_files, hostname, pai, netid, mark)) {
+	case NS_TRYAGAIN:
+		error = EAI_AGAIN;
+		goto free;
+	case NS_UNAVAIL:
+		error = EAI_FAIL;
+		goto free;
+	case NS_NOTFOUND:
+		error = EAI_NODATA;
+		goto free;
+	case NS_SUCCESS:
+		error = 0;
+		for (cur = result; cur; cur = cur->ai_next) {
+			GET_PORT(cur, servname);
+			/* canonname should be filled already */
+		}
+		break;
+	}
+
+	*res = result;
+
+	return 0;
+
+free:
+	if (result)
+		freeaddrinfo(result);
+	return error;
+}
+
+/*
+ * hostname == NULL.
+ * passive socket -> anyaddr (0.0.0.0 or ::)
+ * non-passive socket -> localhost (127.0.0.1 or ::1)
+ */
+static int
+explore_null(const struct addrinfo *pai, const char *servname,
+    struct addrinfo **res)
+{
+	int s;
+	const struct afd *afd;
+	struct addrinfo *cur;
+	struct addrinfo sentinel;
+	int error;
+
+	assert(pai != NULL);
+	/* servname may be NULL */
+	assert(res != NULL);
+
+	*res = NULL;
+	sentinel.ai_next = NULL;
+	cur = &sentinel;
+
+	/*
+	 * filter out AFs that are not supported by the kernel
+	 * XXX errno?
+	 */
+	s = socket(pai->ai_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (s < 0) {
+		if (errno != EMFILE)
+			return 0;
+	} else
+		close(s);
+
+	/*
+	 * if the servname does not match socktype/protocol, ignore it.
+	 */
+	if (get_portmatch(pai, servname) != 0)
+		return 0;
+
+	afd = find_afd(pai->ai_family);
+	if (afd == NULL)
+		return 0;
+
+	if (pai->ai_flags & AI_PASSIVE) {
+		GET_AI(cur->ai_next, afd, afd->a_addrany);
+		/* xxx meaningless?
+		 * GET_CANONNAME(cur->ai_next, "anyaddr");
+		 */
+		GET_PORT(cur->ai_next, servname);
+	} else {
+		GET_AI(cur->ai_next, afd, afd->a_loopback);
+		/* xxx meaningless?
+		 * GET_CANONNAME(cur->ai_next, "localhost");
+		 */
+		GET_PORT(cur->ai_next, servname);
+	}
+	cur = cur->ai_next;
+
+	*res = sentinel.ai_next;
+	return 0;
+
+free:
+	if (sentinel.ai_next)
+		freeaddrinfo(sentinel.ai_next);
+	return error;
+}
+
+/*
+ * numeric hostname
+ */
+static int
+explore_numeric(const struct addrinfo *pai, const char *hostname,
+    const char *servname, struct addrinfo **res, const char *canonname)
+{
+	const struct afd *afd;
+	struct addrinfo *cur;
+	struct addrinfo sentinel;
+	int error;
+	char pton[PTON_MAX];
+
+	assert(pai != NULL);
+	/* hostname may be NULL */
+	/* servname may be NULL */
+	assert(res != NULL);
+
+	*res = NULL;
+	sentinel.ai_next = NULL;
+	cur = &sentinel;
+
+	/*
+	 * if the servname does not match socktype/protocol, ignore it.
+	 */
+	if (get_portmatch(pai, servname) != 0)
+		return 0;
+
+	afd = find_afd(pai->ai_family);
+	if (afd == NULL)
+		return 0;
+
+	switch (afd->a_af) {
+#if 0 /*X/Open spec*/
+	case AF_INET:
+		if (inet_aton(hostname, (struct in_addr *)pton) == 1) {
+			if (pai->ai_family == afd->a_af ||
+			    pai->ai_family == PF_UNSPEC /*?*/) {
+				GET_AI(cur->ai_next, afd, pton);
+				GET_PORT(cur->ai_next, servname);
+				if ((pai->ai_flags & AI_CANONNAME)) {
+					/*
+					 * Set the numeric address itself as
+					 * the canonical name, based on a
+					 * clarification in rfc2553bis-03.
+					 */
+					GET_CANONNAME(cur->ai_next, canonname);
+				}
+				while (cur && cur->ai_next)
+					cur = cur->ai_next;
+			} else
+				ERR(EAI_FAMILY);	/*xxx*/
+		}
+		break;
+#endif
+	default:
+		if (inet_pton(afd->a_af, hostname, pton) == 1) {
+			if (pai->ai_family == afd->a_af ||
+			    pai->ai_family == PF_UNSPEC /*?*/) {
+				GET_AI(cur->ai_next, afd, pton);
+				GET_PORT(cur->ai_next, servname);
+				if ((pai->ai_flags & AI_CANONNAME)) {
+					/*
+					 * Set the numeric address itself as
+					 * the canonical name, based on a
+					 * clarification in rfc2553bis-03.
+					 */
+					GET_CANONNAME(cur->ai_next, canonname);
+				}
+				while (cur->ai_next)
+					cur = cur->ai_next;
+			} else
+				ERR(EAI_FAMILY);	/*xxx*/
+		}
+		break;
+	}
+
+	*res = sentinel.ai_next;
+	return 0;
+
+free:
+bad:
+	if (sentinel.ai_next)
+		freeaddrinfo(sentinel.ai_next);
+	return error;
+}
+
+/*
+ * numeric hostname with scope
+ */
+static int
+explore_numeric_scope(const struct addrinfo *pai, const char *hostname,
+    const char *servname, struct addrinfo **res)
+{
+#if !defined(SCOPE_DELIMITER) || !defined(INET6)
+	return explore_numeric(pai, hostname, servname, res, hostname);
+#else
+	const struct afd *afd;
+	struct addrinfo *cur;
+	int error;
+	char *cp, *hostname2 = NULL, *scope, *addr;
+	struct sockaddr_in6 *sin6;
+
+	assert(pai != NULL);
+	/* hostname may be NULL */
+	/* servname may be NULL */
+	assert(res != NULL);
+
+	/*
+	 * if the servname does not match socktype/protocol, ignore it.
+	 */
+	if (get_portmatch(pai, servname) != 0)
+		return 0;
+
+	afd = find_afd(pai->ai_family);
+	if (afd == NULL)
+		return 0;
+
+	if (!afd->a_scoped)
+		return explore_numeric(pai, hostname, servname, res, hostname);
+
+	cp = strchr(hostname, SCOPE_DELIMITER);
+	if (cp == NULL)
+		return explore_numeric(pai, hostname, servname, res, hostname);
+
+	/*
+	 * Handle special case of <scoped_address><delimiter><scope id>
+	 */
+	hostname2 = strdup(hostname);
+	if (hostname2 == NULL)
+		return EAI_MEMORY;
+	/* terminate at the delimiter */
+	hostname2[cp - hostname] = '\0';
+	addr = hostname2;
+	scope = cp + 1;
+
+	error = explore_numeric(pai, addr, servname, res, hostname);
+	if (error == 0) {
+		u_int32_t scopeid;
+
+		for (cur = *res; cur; cur = cur->ai_next) {
+			if (cur->ai_family != AF_INET6)
+				continue;
+			sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr;
+			if (ip6_str2scopeid(scope, sin6, &scopeid) == -1) {
+				free(hostname2);
+				return(EAI_NODATA); /* XXX: is return OK? */
+			}
+			sin6->sin6_scope_id = scopeid;
+		}
+	}
+
+	free(hostname2);
+
+	return error;
+#endif
+}
+
+static int
+get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str)
+{
+
+	assert(pai != NULL);
+	assert(ai != NULL);
+	assert(str != NULL);
+
+	if ((pai->ai_flags & AI_CANONNAME) != 0) {
+		ai->ai_canonname = strdup(str);
+		if (ai->ai_canonname == NULL)
+			return EAI_MEMORY;
+	}
+	return 0;
+}
+
+static struct addrinfo *
+get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr)
+{
+	char *p;
+	struct addrinfo *ai;
+
+	assert(pai != NULL);
+	assert(afd != NULL);
+	assert(addr != NULL);
+
+	ai = (struct addrinfo *)malloc(sizeof(struct addrinfo)
+		+ (afd->a_socklen));
+	if (ai == NULL)
+		return NULL;
+
+	memcpy(ai, pai, sizeof(struct addrinfo));
+	ai->ai_addr = (struct sockaddr *)(void *)(ai + 1);
+	memset(ai->ai_addr, 0, (size_t)afd->a_socklen);
+
+#ifdef HAVE_SA_LEN
+	ai->ai_addr->sa_len = afd->a_socklen;
+#endif
+
+	ai->ai_addrlen = afd->a_socklen;
+#if defined (__alpha__) || (defined(__i386__) && defined(_LP64)) || defined(__sparc64__)
+	ai->__ai_pad0 = 0;
+#endif
+	ai->ai_addr->sa_family = ai->ai_family = afd->a_af;
+	p = (char *)(void *)(ai->ai_addr);
+	memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen);
+	return ai;
+}
+
+static int
+get_portmatch(const struct addrinfo *ai, const char *servname)
+{
+
+	assert(ai != NULL);
+	/* servname may be NULL */
+
+	return get_port(ai, servname, 1);
+}
+
+static int
+get_port(const struct addrinfo *ai, const char *servname, int matchonly)
+{
+	const char *proto;
+	struct servent *sp;
+	int port;
+	int allownumeric;
+
+	assert(ai != NULL);
+	/* servname may be NULL */
+
+	if (servname == NULL)
+		return 0;
+	switch (ai->ai_family) {
+	case AF_INET:
+#ifdef AF_INET6
+	case AF_INET6:
+#endif
+		break;
+	default:
+		return 0;
+	}
+
+	switch (ai->ai_socktype) {
+	case SOCK_RAW:
+		return EAI_SERVICE;
+	case SOCK_DGRAM:
+	case SOCK_STREAM:
+		allownumeric = 1;
+		break;
+	case ANY:
+#if 1  /* ANDROID-SPECIFIC CHANGE TO MATCH GLIBC */
+		allownumeric = 1;
+#else
+		allownumeric = 0;
+#endif
+		break;
+	default:
+		return EAI_SOCKTYPE;
+	}
+
+	port = str2number(servname);
+	if (port >= 0) {
+		if (!allownumeric)
+			return EAI_SERVICE;
+		if (port < 0 || port > 65535)
+			return EAI_SERVICE;
+		port = htons(port);
+	} else {
+		if (ai->ai_flags & AI_NUMERICSERV)
+			return EAI_NONAME;
+
+		switch (ai->ai_socktype) {
+		case SOCK_DGRAM:
+			proto = "udp";
+			break;
+		case SOCK_STREAM:
+			proto = "tcp";
+			break;
+		default:
+			proto = NULL;
+			break;
+		}
+
+		if ((sp = getservbyname(servname, proto)) == NULL)
+			return EAI_SERVICE;
+		port = sp->s_port;
+	}
+
+	if (!matchonly) {
+		switch (ai->ai_family) {
+		case AF_INET:
+			((struct sockaddr_in *)(void *)
+			    ai->ai_addr)->sin_port = port;
+			break;
+#ifdef INET6
+		case AF_INET6:
+			((struct sockaddr_in6 *)(void *)
+			    ai->ai_addr)->sin6_port = port;
+			break;
+#endif
+		}
+	}
+
+	return 0;
+}
+
+static const struct afd *
+find_afd(int af)
+{
+	const struct afd *afd;
+
+	if (af == PF_UNSPEC)
+		return NULL;
+	for (afd = afdl; afd->a_af; afd++) {
+		if (afd->a_af == af)
+			return afd;
+	}
+	return NULL;
+}
+
+#ifdef INET6
+/* convert a string to a scope identifier. XXX: IPv6 specific */
+static int
+ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, u_int32_t *scopeid)
+{
+	u_long lscopeid;
+	struct in6_addr *a6;
+	char *ep;
+
+	assert(scope != NULL);
+	assert(sin6 != NULL);
+	assert(scopeid != NULL);
+
+	a6 = &sin6->sin6_addr;
+
+	/* empty scopeid portion is invalid */
+	if (*scope == '\0')
+		return -1;
+
+	if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) {
+		/*
+		 * We currently assume a one-to-one mapping between links
+		 * and interfaces, so we simply use interface indices for
+		 * like-local scopes.
+		 */
+		*scopeid = if_nametoindex(scope);
+		if (*scopeid == 0)
+			goto trynumeric;
+		return 0;
+	}
+
+	/* still unclear about literal, allow numeric only - placeholder */
+	if (IN6_IS_ADDR_SITELOCAL(a6) || IN6_IS_ADDR_MC_SITELOCAL(a6))
+		goto trynumeric;
+	if (IN6_IS_ADDR_MC_ORGLOCAL(a6))
+		goto trynumeric;
+	else
+		goto trynumeric;	/* global */
+
+	/* try to convert to a numeric id as a last resort */
+  trynumeric:
+	errno = 0;
+	lscopeid = strtoul(scope, &ep, 10);
+	*scopeid = (u_int32_t)(lscopeid & 0xffffffffUL);
+	if (errno == 0 && ep && *ep == '\0' && *scopeid == lscopeid)
+		return 0;
+	else
+		return -1;
+}
+#endif
+
+/* code duplicate with gethnamaddr.c */
+
+static const char AskedForGot[] =
+	"gethostby*.getanswer: asked for \"%s\", got \"%s\"";
+
+static struct addrinfo *
+getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
+    const struct addrinfo *pai)
+{
+	struct addrinfo sentinel, *cur;
+	struct addrinfo ai;
+	const struct afd *afd;
+	char *canonname;
+	const HEADER *hp;
+	const u_char *cp;
+	int n;
+	const u_char *eom;
+	char *bp, *ep;
+	int type, class, ancount, qdcount;
+	int haveanswer, had_error;
+	char tbuf[MAXDNAME];
+	int (*name_ok) (const char *);
+	char hostbuf[8*1024];
+
+	assert(answer != NULL);
+	assert(qname != NULL);
+	assert(pai != NULL);
+
+	memset(&sentinel, 0, sizeof(sentinel));
+	cur = &sentinel;
+
+	canonname = NULL;
+	eom = answer->buf + anslen;
+	switch (qtype) {
+	case T_A:
+	case T_AAAA:
+	case T_ANY:	/*use T_ANY only for T_A/T_AAAA lookup*/
+		name_ok = res_hnok;
+		break;
+	default:
+		return NULL;	/* XXX should be abort(); */
+	}
+	/*
+	 * find first satisfactory answer
+	 */
+	hp = &answer->hdr;
+	ancount = ntohs(hp->ancount);
+	qdcount = ntohs(hp->qdcount);
+	bp = hostbuf;
+	ep = hostbuf + sizeof hostbuf;
+	cp = answer->buf + HFIXEDSZ;
+	if (qdcount != 1) {
+		h_errno = NO_RECOVERY;
+		return (NULL);
+	}
+	n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
+	if ((n < 0) || !(*name_ok)(bp)) {
+		h_errno = NO_RECOVERY;
+		return (NULL);
+	}
+	cp += n + QFIXEDSZ;
+	if (qtype == T_A || qtype == T_AAAA || qtype == T_ANY) {
+		/* res_send() has already verified that the query name is the
+		 * same as the one we sent; this just gets the expanded name
+		 * (i.e., with the succeeding search-domain tacked on).
+		 */
+		n = strlen(bp) + 1;		/* for the \0 */
+		if (n >= MAXHOSTNAMELEN) {
+			h_errno = NO_RECOVERY;
+			return (NULL);
+		}
+		canonname = bp;
+		bp += n;
+		/* The qname can be abbreviated, but h_name is now absolute. */
+		qname = canonname;
+	}
+	haveanswer = 0;
+	had_error = 0;
+	while (ancount-- > 0 && cp < eom && !had_error) {
+		n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
+		if ((n < 0) || !(*name_ok)(bp)) {
+			had_error++;
+			continue;
+		}
+		cp += n;			/* name */
+		type = _getshort(cp);
+ 		cp += INT16SZ;			/* type */
+		class = _getshort(cp);
+ 		cp += INT16SZ + INT32SZ;	/* class, TTL */
+		n = _getshort(cp);
+		cp += INT16SZ;			/* len */
+		if (class != C_IN) {
+			/* XXX - debug? syslog? */
+			cp += n;
+			continue;		/* XXX - had_error++ ? */
+		}
+		if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) &&
+		    type == T_CNAME) {
+			n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+			if ((n < 0) || !(*name_ok)(tbuf)) {
+				had_error++;
+				continue;
+			}
+			cp += n;
+			/* Get canonical name. */
+			n = strlen(tbuf) + 1;	/* for the \0 */
+			if (n > ep - bp || n >= MAXHOSTNAMELEN) {
+				had_error++;
+				continue;
+			}
+			strlcpy(bp, tbuf, (size_t)(ep - bp));
+			canonname = bp;
+			bp += n;
+			continue;
+		}
+		if (qtype == T_ANY) {
+			if (!(type == T_A || type == T_AAAA)) {
+				cp += n;
+				continue;
+			}
+		} else if (type != qtype) {
+			if (type != T_KEY && type != T_SIG)
+				syslog(LOG_NOTICE|LOG_AUTH,
+	       "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
+				       qname, p_class(C_IN), p_type(qtype),
+				       p_type(type));
+			cp += n;
+			continue;		/* XXX - had_error++ ? */
+		}
+		switch (type) {
+		case T_A:
+		case T_AAAA:
+			if (strcasecmp(canonname, bp) != 0) {
+				syslog(LOG_NOTICE|LOG_AUTH,
+				       AskedForGot, canonname, bp);
+				cp += n;
+				continue;	/* XXX - had_error++ ? */
+			}
+			if (type == T_A && n != INADDRSZ) {
+				cp += n;
+				continue;
+			}
+			if (type == T_AAAA && n != IN6ADDRSZ) {
+				cp += n;
+				continue;
+			}
+			if (type == T_AAAA) {
+				struct in6_addr in6;
+				memcpy(&in6, cp, IN6ADDRSZ);
+				if (IN6_IS_ADDR_V4MAPPED(&in6)) {
+					cp += n;
+					continue;
+				}
+			}
+			if (!haveanswer) {
+				int nn;
+
+				canonname = bp;
+				nn = strlen(bp) + 1;	/* for the \0 */
+				bp += nn;
+			}
+
+			/* don't overwrite pai */
+			ai = *pai;
+			ai.ai_family = (type == T_A) ? AF_INET : AF_INET6;
+			afd = find_afd(ai.ai_family);
+			if (afd == NULL) {
+				cp += n;
+				continue;
+			}
+			cur->ai_next = get_ai(&ai, afd, (const char *)cp);
+			if (cur->ai_next == NULL)
+				had_error++;
+			while (cur && cur->ai_next)
+				cur = cur->ai_next;
+			cp += n;
+			break;
+		default:
+			abort();
+		}
+		if (!had_error)
+			haveanswer++;
+	}
+	if (haveanswer) {
+		if (!canonname)
+			(void)get_canonname(pai, sentinel.ai_next, qname);
+		else
+			(void)get_canonname(pai, sentinel.ai_next, canonname);
+		h_errno = NETDB_SUCCESS;
+		return sentinel.ai_next;
+	}
+
+	h_errno = NO_RECOVERY;
+	return NULL;
+}
+
+struct addrinfo_sort_elem {
+	struct addrinfo *ai;
+	int has_src_addr;
+	sockaddr_union src_addr;
+	int original_order;
+};
+
+/*ARGSUSED*/
+static int
+_get_scope(const struct sockaddr *addr)
+{
+	if (addr->sa_family == AF_INET6) {
+		const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
+		if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr)) {
+			return IPV6_ADDR_MC_SCOPE(&addr6->sin6_addr);
+		} else if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr) ||
+			   IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)) {
+			/*
+			 * RFC 4291 section 2.5.3 says loopback is to be treated as having
+			 * link-local scope.
+			 */
+			return IPV6_ADDR_SCOPE_LINKLOCAL;
+		} else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
+			return IPV6_ADDR_SCOPE_SITELOCAL;
+		} else {
+			return IPV6_ADDR_SCOPE_GLOBAL;
+		}
+	} else if (addr->sa_family == AF_INET) {
+		const struct sockaddr_in *addr4 = (const struct sockaddr_in *)addr;
+		unsigned long int na = ntohl(addr4->sin_addr.s_addr);
+
+		if (IN_LOOPBACK(na) ||                          /* 127.0.0.0/8 */
+		    (na & 0xffff0000) == 0xa9fe0000) {          /* 169.254.0.0/16 */
+			return IPV6_ADDR_SCOPE_LINKLOCAL;
+		} else {
+			/*
+			 * RFC 6724 section 3.2. Other IPv4 addresses, including private addresses
+			 * and shared addresses (100.64.0.0/10), are assigned global scope.
+			 */
+			return IPV6_ADDR_SCOPE_GLOBAL;
+		}
+	} else {
+		/*
+		 * This should never happen.
+		 * Return a scope with low priority as a last resort.
+		 */
+		return IPV6_ADDR_SCOPE_NODELOCAL;
+	}
+}
+
+/* These macros are modelled after the ones in <netinet/in6.h>. */
+
+/* RFC 4380, section 2.6 */
+#define IN6_IS_ADDR_TEREDO(a)	 \
+	((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == ntohl(0x20010000)))
+
+/* RFC 3056, section 2. */
+#define IN6_IS_ADDR_6TO4(a)	 \
+	(((a)->s6_addr[0] == 0x20) && ((a)->s6_addr[1] == 0x02))
+
+/* 6bone testing address area (3ffe::/16), deprecated in RFC 3701. */
+#define IN6_IS_ADDR_6BONE(a)      \
+	(((a)->s6_addr[0] == 0x3f) && ((a)->s6_addr[1] == 0xfe))
+
+/*
+ * Get the label for a given IPv4/IPv6 address.
+ * RFC 6724, section 2.1.
+ */
+
+/*ARGSUSED*/
+static int
+_get_label(const struct sockaddr *addr)
+{
+	if (addr->sa_family == AF_INET) {
+		return 4;
+	} else if (addr->sa_family == AF_INET6) {
+		const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *) addr;
+		if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)) {
+			return 0;
+		} else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
+			return 4;
+		} else if (IN6_IS_ADDR_6TO4(&addr6->sin6_addr)) {
+			return 2;
+		} else if (IN6_IS_ADDR_TEREDO(&addr6->sin6_addr)) {
+			return 5;
+		} else if (IN6_IS_ADDR_ULA(&addr6->sin6_addr)) {
+			return 13;
+		} else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr)) {
+			return 3;
+		} else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
+			return 11;
+		} else if (IN6_IS_ADDR_6BONE(&addr6->sin6_addr)) {
+			return 12;
+		} else {
+			/* All other IPv6 addresses, including global unicast addresses. */
+			return 1;
+		}
+	} else {
+		/*
+		 * This should never happen.
+		 * Return a semi-random label as a last resort.
+		 */
+		return 1;
+	}
+}
+
+/*
+ * Get the precedence for a given IPv4/IPv6 address.
+ * RFC 6724, section 2.1.
+ */
+
+/*ARGSUSED*/
+static int
+_get_precedence(const struct sockaddr *addr)
+{
+	if (addr->sa_family == AF_INET) {
+		return 35;
+	} else if (addr->sa_family == AF_INET6) {
+		const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
+		if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)) {
+			return 50;
+		} else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
+			return 35;
+		} else if (IN6_IS_ADDR_6TO4(&addr6->sin6_addr)) {
+			return 30;
+		} else if (IN6_IS_ADDR_TEREDO(&addr6->sin6_addr)) {
+			return 5;
+		} else if (IN6_IS_ADDR_ULA(&addr6->sin6_addr)) {
+			return 3;
+		} else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr) ||
+		           IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr) ||
+		           IN6_IS_ADDR_6BONE(&addr6->sin6_addr)) {
+			return 1;
+		} else {
+			/* All other IPv6 addresses, including global unicast addresses. */
+			return 40;
+		}
+	} else {
+		return 1;
+	}
+}
+
+/*
+ * Find number of matching initial bits between the two addresses a1 and a2.
+ */
+
+/*ARGSUSED*/
+static int
+_common_prefix_len(const struct in6_addr *a1, const struct in6_addr *a2)
+{
+	const char *p1 = (const char *)a1;
+	const char *p2 = (const char *)a2;
+	unsigned i;
+
+	for (i = 0; i < sizeof(*a1); ++i) {
+		int x, j;
+
+		if (p1[i] == p2[i]) {
+			continue;
+		}
+		x = p1[i] ^ p2[i];
+		for (j = 0; j < CHAR_BIT; ++j) {
+			if (x & (1 << (CHAR_BIT - 1))) {
+				return i * CHAR_BIT + j;
+			}
+			x <<= 1;
+		}
+	}
+	return sizeof(*a1) * CHAR_BIT;
+}
+
+/*
+ * Compare two source/destination address pairs.
+ * RFC 6724, section 6.
+ */
+
+/*ARGSUSED*/
+static int
+_rfc6724_compare(const void *ptr1, const void* ptr2)
+{
+	const struct addrinfo_sort_elem *a1 = (const struct addrinfo_sort_elem *)ptr1;
+	const struct addrinfo_sort_elem *a2 = (const struct addrinfo_sort_elem *)ptr2;
+	int scope_src1, scope_dst1, scope_match1;
+	int scope_src2, scope_dst2, scope_match2;
+	int label_src1, label_dst1, label_match1;
+	int label_src2, label_dst2, label_match2;
+	int precedence1, precedence2;
+	int prefixlen1, prefixlen2;
+
+	/* Rule 1: Avoid unusable destinations. */
+	if (a1->has_src_addr != a2->has_src_addr) {
+		return a2->has_src_addr - a1->has_src_addr;
+	}
+
+	/* Rule 2: Prefer matching scope. */
+	scope_src1 = _get_scope(&a1->src_addr.generic);
+	scope_dst1 = _get_scope(a1->ai->ai_addr);
+	scope_match1 = (scope_src1 == scope_dst1);
+
+	scope_src2 = _get_scope(&a2->src_addr.generic);
+	scope_dst2 = _get_scope(a2->ai->ai_addr);
+	scope_match2 = (scope_src2 == scope_dst2);
+
+	if (scope_match1 != scope_match2) {
+		return scope_match2 - scope_match1;
+	}
+
+	/*
+	 * Rule 3: Avoid deprecated addresses.
+	 * TODO(sesse): We don't currently have a good way of finding this.
+	 */
+
+	/*
+	 * Rule 4: Prefer home addresses.
+	 * TODO(sesse): We don't currently have a good way of finding this.
+	 */
+
+	/* Rule 5: Prefer matching label. */
+	label_src1 = _get_label(&a1->src_addr.generic);
+	label_dst1 = _get_label(a1->ai->ai_addr);
+	label_match1 = (label_src1 == label_dst1);
+
+	label_src2 = _get_label(&a2->src_addr.generic);
+	label_dst2 = _get_label(a2->ai->ai_addr);
+	label_match2 = (label_src2 == label_dst2);
+
+	if (label_match1 != label_match2) {
+		return label_match2 - label_match1;
+	}
+
+	/* Rule 6: Prefer higher precedence. */
+	precedence1 = _get_precedence(a1->ai->ai_addr);
+	precedence2 = _get_precedence(a2->ai->ai_addr);
+	if (precedence1 != precedence2) {
+		return precedence2 - precedence1;
+	}
+
+	/*
+	 * Rule 7: Prefer native transport.
+	 * TODO(sesse): We don't currently have a good way of finding this.
+	 */
+
+	/* Rule 8: Prefer smaller scope. */
+	if (scope_dst1 != scope_dst2) {
+		return scope_dst1 - scope_dst2;
+	}
+
+	/*
+	 * Rule 9: Use longest matching prefix.
+         * We implement this for IPv6 only, as the rules in RFC 6724 don't seem
+         * to work very well directly applied to IPv4. (glibc uses information from
+         * the routing table for a custom IPv4 implementation here.)
+	 */
+	if (a1->has_src_addr && a1->ai->ai_addr->sa_family == AF_INET6 &&
+	    a2->has_src_addr && a2->ai->ai_addr->sa_family == AF_INET6) {
+		const struct sockaddr_in6 *a1_src = &a1->src_addr.in6;
+		const struct sockaddr_in6 *a1_dst = (const struct sockaddr_in6 *)a1->ai->ai_addr;
+		const struct sockaddr_in6 *a2_src = &a2->src_addr.in6;
+		const struct sockaddr_in6 *a2_dst = (const struct sockaddr_in6 *)a2->ai->ai_addr;
+		prefixlen1 = _common_prefix_len(&a1_src->sin6_addr, &a1_dst->sin6_addr);
+		prefixlen2 = _common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr);
+		if (prefixlen1 != prefixlen2) {
+			return prefixlen2 - prefixlen1;
+		}
+	}
+
+	/*
+	 * Rule 10: Leave the order unchanged.
+	 * We need this since qsort() is not necessarily stable.
+	 */
+	return a1->original_order - a2->original_order;
+}
+
+/*
+ * Find the source address that will be used if trying to connect to the given
+ * address. src_addr must be large enough to hold a struct sockaddr_in6.
+ *
+ * Returns 1 if a source address was found, 0 if the address is unreachable,
+ * and -1 if a fatal error occurred. If 0 or 1, the contents of src_addr are
+ * undefined.
+ */
+
+/*ARGSUSED*/
+static int
+_find_src_addr(const struct sockaddr *addr, struct sockaddr *src_addr, unsigned mark)
+{
+	int sock;
+	int ret;
+	socklen_t len;
+
+	switch (addr->sa_family) {
+	case AF_INET:
+		len = sizeof(struct sockaddr_in);
+		break;
+	case AF_INET6:
+		len = sizeof(struct sockaddr_in6);
+		break;
+	default:
+		/* No known usable source address for non-INET families. */
+		return 0;
+	}
+
+	sock = socket(addr->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
+	if (sock == -1) {
+		if (errno == EAFNOSUPPORT) {
+			return 0;
+		} else {
+			return -1;
+		}
+	}
+	if (mark != MARK_UNSET && setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0)
+		return 0;
+	do {
+		ret = __connect(sock, addr, len);
+	} while (ret == -1 && errno == EINTR);
+
+	if (ret == -1) {
+		close(sock);
+		return 0;
+	}
+
+	if (getsockname(sock, src_addr, &len) == -1) {
+		close(sock);
+		return -1;
+	}
+	close(sock);
+	return 1;
+}
+
+/*
+ * Sort the linked list starting at sentinel->ai_next in RFC6724 order.
+ * Will leave the list unchanged if an error occurs.
+ */
+
+/*ARGSUSED*/
+static void
+_rfc6724_sort(struct addrinfo *list_sentinel, unsigned mark)
+{
+	struct addrinfo *cur;
+	int nelem = 0, i;
+	struct addrinfo_sort_elem *elems;
+
+	cur = list_sentinel->ai_next;
+	while (cur) {
+		++nelem;
+		cur = cur->ai_next;
+	}
+
+	elems = (struct addrinfo_sort_elem *)malloc(nelem * sizeof(struct addrinfo_sort_elem));
+	if (elems == NULL) {
+		goto error;
+	}
+
+	/*
+	 * Convert the linked list to an array that also contains the candidate
+	 * source address for each destination address.
+	 */
+	for (i = 0, cur = list_sentinel->ai_next; i < nelem; ++i, cur = cur->ai_next) {
+		int has_src_addr;
+		assert(cur != NULL);
+		elems[i].ai = cur;
+		elems[i].original_order = i;
+
+		has_src_addr = _find_src_addr(cur->ai_addr, &elems[i].src_addr.generic, mark);
+		if (has_src_addr == -1) {
+			goto error;
+		}
+		elems[i].has_src_addr = has_src_addr;
+	}
+
+	/* Sort the addresses, and rearrange the linked list so it matches the sorted order. */
+	qsort((void *)elems, nelem, sizeof(struct addrinfo_sort_elem), _rfc6724_compare);
+
+	list_sentinel->ai_next = elems[0].ai;
+	for (i = 0; i < nelem - 1; ++i) {
+		elems[i].ai->ai_next = elems[i + 1].ai;
+	}
+	elems[nelem - 1].ai->ai_next = NULL;
+
+error:
+	free(elems);
+}
+
+/*ARGSUSED*/
+static int
+_dns_getaddrinfo(void *rv, void	*cb_data, va_list ap)
+{
+	struct addrinfo *ai;
+	querybuf *buf, *buf2;
+	const char *name;
+	const struct addrinfo *pai;
+	struct addrinfo sentinel, *cur;
+	struct res_target q, q2;
+	res_state res;
+	unsigned netid, mark;
+
+	name = va_arg(ap, char *);
+	pai = va_arg(ap, const struct addrinfo *);
+	netid = va_arg(ap, unsigned);
+	mark = va_arg(ap, unsigned);
+	//fprintf(stderr, "_dns_getaddrinfo() name = '%s'\n", name);
+
+	memset(&q, 0, sizeof(q));
+	memset(&q2, 0, sizeof(q2));
+	memset(&sentinel, 0, sizeof(sentinel));
+	cur = &sentinel;
+
+	buf = malloc(sizeof(*buf));
+	if (buf == NULL) {
+		h_errno = NETDB_INTERNAL;
+		return NS_NOTFOUND;
+	}
+	buf2 = malloc(sizeof(*buf2));
+	if (buf2 == NULL) {
+		free(buf);
+		h_errno = NETDB_INTERNAL;
+		return NS_NOTFOUND;
+	}
+
+	switch (pai->ai_family) {
+	case AF_UNSPEC:
+		/* prefer IPv6 */
+		q.name = name;
+		q.qclass = C_IN;
+		q.answer = buf->buf;
+		q.anslen = sizeof(buf->buf);
+		int query_ipv6 = 1, query_ipv4 = 1;
+		if (pai->ai_flags & AI_ADDRCONFIG) {
+			query_ipv6 = _have_ipv6(mark);
+			query_ipv4 = _have_ipv4(mark);
+		}
+		if (query_ipv6) {
+			q.qtype = T_AAAA;
+			if (query_ipv4) {
+				q.next = &q2;
+				q2.name = name;
+				q2.qclass = C_IN;
+				q2.qtype = T_A;
+				q2.answer = buf2->buf;
+				q2.anslen = sizeof(buf2->buf);
+			}
+		} else if (query_ipv4) {
+			q.qtype = T_A;
+		} else {
+			free(buf);
+			free(buf2);
+			return NS_NOTFOUND;
+		}
+		break;
+	case AF_INET:
+		q.name = name;
+		q.qclass = C_IN;
+		q.qtype = T_A;
+		q.answer = buf->buf;
+		q.anslen = sizeof(buf->buf);
+		break;
+	case AF_INET6:
+		q.name = name;
+		q.qclass = C_IN;
+		q.qtype = T_AAAA;
+		q.answer = buf->buf;
+		q.anslen = sizeof(buf->buf);
+		break;
+	default:
+		free(buf);
+		free(buf2);
+		return NS_UNAVAIL;
+	}
+
+	res = __res_get_state();
+	if (res == NULL) {
+		free(buf);
+		free(buf2);
+		return NS_NOTFOUND;
+	}
+
+	/* this just sets our netid val in the thread private data so we don't have to
+	 * modify the api's all the way down to res_send.c's res_nsend.  We could
+	 * fully populate the thread private data here, but if we get down there
+	 * and have a cache hit that would be wasted, so we do the rest there on miss
+	 */
+	res_setnetid(res, netid);
+	res_setmark(res, mark);
+	if (res_searchN(name, &q, res) < 0) {
+		__res_put_state(res);
+		free(buf);
+		free(buf2);
+		return NS_NOTFOUND;
+	}
+	ai = getanswer(buf, q.n, q.name, q.qtype, pai);
+	if (ai) {
+		cur->ai_next = ai;
+		while (cur && cur->ai_next)
+			cur = cur->ai_next;
+	}
+	if (q.next) {
+		ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai);
+		if (ai)
+			cur->ai_next = ai;
+	}
+	free(buf);
+	free(buf2);
+	if (sentinel.ai_next == NULL) {
+		__res_put_state(res);
+		switch (h_errno) {
+		case HOST_NOT_FOUND:
+			return NS_NOTFOUND;
+		case TRY_AGAIN:
+			return NS_TRYAGAIN;
+		default:
+			return NS_UNAVAIL;
+		}
+	}
+
+	_rfc6724_sort(&sentinel, netid);
+
+	__res_put_state(res);
+
+	*((struct addrinfo **)rv) = sentinel.ai_next;
+	return NS_SUCCESS;
+}
+
+static void
+_sethtent(FILE **hostf)
+{
+
+	if (!*hostf)
+		*hostf = fopen(_PATH_HOSTS, "r" );
+	else
+		rewind(*hostf);
+}
+
+static void
+_endhtent(FILE **hostf)
+{
+
+	if (*hostf) {
+		(void) fclose(*hostf);
+		*hostf = NULL;
+	}
+}
+
+static struct addrinfo *
+_gethtent(FILE **hostf, const char *name, const struct addrinfo *pai)
+{
+	char *p;
+	char *cp, *tname, *cname;
+	struct addrinfo hints, *res0, *res;
+	int error;
+	const char *addr;
+	char hostbuf[8*1024];
+
+//	fprintf(stderr, "_gethtent() name = '%s'\n", name);
+	assert(name != NULL);
+	assert(pai != NULL);
+
+	if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "r" )))
+		return (NULL);
+ again:
+	if (!(p = fgets(hostbuf, sizeof hostbuf, *hostf)))
+		return (NULL);
+	if (*p == '#')
+		goto again;
+	if (!(cp = strpbrk(p, "#\n")))
+		goto again;
+	*cp = '\0';
+	if (!(cp = strpbrk(p, " \t")))
+		goto again;
+	*cp++ = '\0';
+	addr = p;
+	/* if this is not something we're looking for, skip it. */
+	cname = NULL;
+	while (cp && *cp) {
+		if (*cp == ' ' || *cp == '\t') {
+			cp++;
+			continue;
+		}
+		if (!cname)
+			cname = cp;
+		tname = cp;
+		if ((cp = strpbrk(cp, " \t")) != NULL)
+			*cp++ = '\0';
+//		fprintf(stderr, "\ttname = '%s'", tname);
+		if (strcasecmp(name, tname) == 0)
+			goto found;
+	}
+	goto again;
+
+found:
+	hints = *pai;
+	hints.ai_flags = AI_NUMERICHOST;
+	error = getaddrinfo(addr, NULL, &hints, &res0);
+	if (error)
+		goto again;
+	for (res = res0; res; res = res->ai_next) {
+		/* cover it up */
+		res->ai_flags = pai->ai_flags;
+
+		if (pai->ai_flags & AI_CANONNAME) {
+			if (get_canonname(pai, res, cname) != 0) {
+				freeaddrinfo(res0);
+				goto again;
+			}
+		}
+	}
+	return res0;
+}
+
+/*ARGSUSED*/
+static int
+_files_getaddrinfo(void *rv, void *cb_data, va_list ap)
+{
+	const char *name;
+	const struct addrinfo *pai;
+	struct addrinfo sentinel, *cur;
+	struct addrinfo *p;
+	FILE *hostf = NULL;
+
+	name = va_arg(ap, char *);
+	pai = va_arg(ap, struct addrinfo *);
+
+//	fprintf(stderr, "_files_getaddrinfo() name = '%s'\n", name);
+	memset(&sentinel, 0, sizeof(sentinel));
+	cur = &sentinel;
+
+	_sethtent(&hostf);
+	while ((p = _gethtent(&hostf, name, pai)) != NULL) {
+		cur->ai_next = p;
+		while (cur && cur->ai_next)
+			cur = cur->ai_next;
+	}
+	_endhtent(&hostf);
+
+	*((struct addrinfo **)rv) = sentinel.ai_next;
+	if (sentinel.ai_next == NULL)
+		return NS_NOTFOUND;
+	return NS_SUCCESS;
+}
+
+/* resolver logic */
+
+/*
+ * Formulate a normal query, send, and await answer.
+ * Returned answer is placed in supplied buffer "answer".
+ * Perform preliminary check of answer, returning success only
+ * if no error is indicated and the answer count is nonzero.
+ * Return the size of the response on success, -1 on error.
+ * Error number is left in h_errno.
+ *
+ * Caller must parse answer and determine whether it answers the question.
+ */
+static int
+res_queryN(const char *name, /* domain name */ struct res_target *target,
+    res_state res)
+{
+	u_char buf[MAXPACKET];
+	HEADER *hp;
+	int n;
+	struct res_target *t;
+	int rcode;
+	int ancount;
+
+	assert(name != NULL);
+	/* XXX: target may be NULL??? */
+
+	rcode = NOERROR;
+	ancount = 0;
+
+	for (t = target; t; t = t->next) {
+		int class, type;
+		u_char *answer;
+		int anslen;
+
+		hp = (HEADER *)(void *)t->answer;
+		hp->rcode = NOERROR;	/* default */
+
+		/* make it easier... */
+		class = t->qclass;
+		type = t->qtype;
+		answer = t->answer;
+		anslen = t->anslen;
+#ifdef DEBUG
+		if (res->options & RES_DEBUG)
+			printf(";; res_nquery(%s, %d, %d)\n", name, class, type);
+#endif
+
+		n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL,
+		    buf, sizeof(buf));
+#ifdef RES_USE_EDNS0
+		if (n > 0 && (res->options & RES_USE_EDNS0) != 0)
+			n = res_nopt(res, n, buf, sizeof(buf), anslen);
+#endif
+		if (n <= 0) {
+#ifdef DEBUG
+			if (res->options & RES_DEBUG)
+				printf(";; res_nquery: mkquery failed\n");
+#endif
+			h_errno = NO_RECOVERY;
+			return n;
+		}
+		n = res_nsend(res, buf, n, answer, anslen);
+#if 0
+		if (n < 0) {
+#ifdef DEBUG
+			if (res->options & RES_DEBUG)
+				printf(";; res_query: send error\n");
+#endif
+			h_errno = TRY_AGAIN;
+			return n;
+		}
+#endif
+
+		if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
+			rcode = hp->rcode;	/* record most recent error */
+#ifdef DEBUG
+			if (res->options & RES_DEBUG)
+				printf(";; rcode = %u, ancount=%u\n", hp->rcode,
+				    ntohs(hp->ancount));
+#endif
+			continue;
+		}
+
+		ancount += ntohs(hp->ancount);
+
+		t->n = n;
+	}
+
+	if (ancount == 0) {
+		switch (rcode) {
+		case NXDOMAIN:
+			h_errno = HOST_NOT_FOUND;
+			break;
+		case SERVFAIL:
+			h_errno = TRY_AGAIN;
+			break;
+		case NOERROR:
+			h_errno = NO_DATA;
+			break;
+		case FORMERR:
+		case NOTIMP:
+		case REFUSED:
+		default:
+			h_errno = NO_RECOVERY;
+			break;
+		}
+		return -1;
+	}
+	return ancount;
+}
+
+/*
+ * Formulate a normal query, send, and retrieve answer in supplied buffer.
+ * Return the size of the response on success, -1 on error.
+ * If enabled, implement search rules until answer or unrecoverable failure
+ * is detected.  Error code, if any, is left in h_errno.
+ */
+static int
+res_searchN(const char *name, struct res_target *target, res_state res)
+{
+	const char *cp, * const *domain;
+	HEADER *hp;
+	u_int dots;
+	int trailing_dot, ret, saved_herrno;
+	int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
+
+	assert(name != NULL);
+	assert(target != NULL);
+
+	hp = (HEADER *)(void *)target->answer;	/*XXX*/
+
+	errno = 0;
+	h_errno = HOST_NOT_FOUND;	/* default, if we never query */
+	dots = 0;
+	for (cp = name; *cp; cp++)
+		dots += (*cp == '.');
+	trailing_dot = 0;
+	if (cp > name && *--cp == '.')
+		trailing_dot++;
+
+
+        //fprintf(stderr, "res_searchN() name = '%s'\n", name);
+
+	/*
+	 * if there aren't any dots, it could be a user-level alias
+	 */
+	if (!dots && (cp = __hostalias(name)) != NULL) {
+		ret = res_queryN(cp, target, res);
+		return ret;
+	}
+
+	/*
+	 * If there are dots in the name already, let's just give it a try
+	 * 'as is'.  The threshold can be set with the "ndots" option.
+	 */
+	saved_herrno = -1;
+	if (dots >= res->ndots) {
+		ret = res_querydomainN(name, NULL, target, res);
+		if (ret > 0)
+			return (ret);
+		saved_herrno = h_errno;
+		tried_as_is++;
+	}
+
+	/*
+	 * We do at least one level of search if
+	 *	- there is no dot and RES_DEFNAME is set, or
+	 *	- there is at least one dot, there is no trailing dot,
+	 *	  and RES_DNSRCH is set.
+	 */
+	if ((!dots && (res->options & RES_DEFNAMES)) ||
+	    (dots && !trailing_dot && (res->options & RES_DNSRCH))) {
+		int done = 0;
+
+		/* Unfortunately we need to set stuff up before
+		 * the domain stuff is tried.  Will have a better
+		 * fix after thread pools are used.
+		 */
+		_resolv_populate_res_for_net(res);
+
+		for (domain = (const char * const *)res->dnsrch;
+		   *domain && !done;
+		   domain++) {
+
+			ret = res_querydomainN(name, *domain, target, res);
+			if (ret > 0)
+				return ret;
+
+			/*
+			 * If no server present, give up.
+			 * If name isn't found in this domain,
+			 * keep trying higher domains in the search list
+			 * (if that's enabled).
+			 * On a NO_DATA error, keep trying, otherwise
+			 * a wildcard entry of another type could keep us
+			 * from finding this entry higher in the domain.
+			 * If we get some other error (negative answer or
+			 * server failure), then stop searching up,
+			 * but try the input name below in case it's
+			 * fully-qualified.
+			 */
+			if (errno == ECONNREFUSED) {
+				h_errno = TRY_AGAIN;
+				return -1;
+			}
+
+			switch (h_errno) {
+			case NO_DATA:
+				got_nodata++;
+				/* FALLTHROUGH */
+			case HOST_NOT_FOUND:
+				/* keep trying */
+				break;
+			case TRY_AGAIN:
+				if (hp->rcode == SERVFAIL) {
+					/* try next search element, if any */
+					got_servfail++;
+					break;
+				}
+				/* FALLTHROUGH */
+			default:
+				/* anything else implies that we're done */
+				done++;
+			}
+			/*
+			 * if we got here for some reason other than DNSRCH,
+			 * we only wanted one iteration of the loop, so stop.
+			 */
+			if (!(res->options & RES_DNSRCH))
+			        done++;
+		}
+	}
+
+	/*
+	 * if we have not already tried the name "as is", do that now.
+	 * note that we do this regardless of how many dots were in the
+	 * name or whether it ends with a dot.
+	 */
+	if (!tried_as_is) {
+		ret = res_querydomainN(name, NULL, target, res);
+		if (ret > 0)
+			return ret;
+	}
+
+	/*
+	 * if we got here, we didn't satisfy the search.
+	 * if we did an initial full query, return that query's h_errno
+	 * (note that we wouldn't be here if that query had succeeded).
+	 * else if we ever got a nodata, send that back as the reason.
+	 * else send back meaningless h_errno, that being the one from
+	 * the last DNSRCH we did.
+	 */
+	if (saved_herrno != -1)
+		h_errno = saved_herrno;
+	else if (got_nodata)
+		h_errno = NO_DATA;
+	else if (got_servfail)
+		h_errno = TRY_AGAIN;
+	return -1;
+}
+
+/*
+ * Perform a call on res_query on the concatenation of name and domain,
+ * removing a trailing dot from name if domain is NULL.
+ */
+static int
+res_querydomainN(const char *name, const char *domain,
+    struct res_target *target, res_state res)
+{
+	char nbuf[MAXDNAME];
+	const char *longname = nbuf;
+	size_t n, d;
+
+	assert(name != NULL);
+	/* XXX: target may be NULL??? */
+
+#ifdef DEBUG
+	if (res->options & RES_DEBUG)
+		printf(";; res_querydomain(%s, %s)\n",
+			name, domain?domain:"<Nil>");
+#endif
+	if (domain == NULL) {
+		/*
+		 * Check for trailing '.';
+		 * copy without '.' if present.
+		 */
+		n = strlen(name);
+		if (n + 1 > sizeof(nbuf)) {
+			h_errno = NO_RECOVERY;
+			return -1;
+		}
+		if (n > 0 && name[--n] == '.') {
+			strncpy(nbuf, name, n);
+			nbuf[n] = '\0';
+		} else
+			longname = name;
+	} else {
+		n = strlen(name);
+		d = strlen(domain);
+		if (n + 1 + d + 1 > sizeof(nbuf)) {
+			h_errno = NO_RECOVERY;
+			return -1;
+		}
+		snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain);
+	}
+	return res_queryN(longname, target, res);
+}
diff --git a/libc/dns/net/getnameinfo.c b/libc/dns/net/getnameinfo.c
new file mode 100644
index 0000000..b9c0280
--- /dev/null
+++ b/libc/dns/net/getnameinfo.c
@@ -0,0 +1,433 @@
+/*	$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $	*/
+/*	$KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $	*/
+
+/*
+ * Copyright (c) 2000 Ben Harris.
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Issues to be discussed:
+ * - Thread safe-ness must be checked
+ * - RFC2553 says that we should raise error on short buffer.  X/Open says
+ *   we need to truncate the result.  We obey RFC2553 (and X/Open should be
+ *   modified).  ipngwg rough consensus seems to follow RFC2553.
+ * - What is "local" in NI_FQDN?
+ * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other.
+ * - (KAME extension) always attach textual scopeid (fe80::1%lo0), if
+ *   sin6_scope_id is filled - standardization status?
+ *   XXX breaks backward compat for code that expects no scopeid.
+ *   beware on merge.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <net/if.h>
+#include <net/if_ieee1394.h>
+#include <net/if_types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <assert.h>
+#include <limits.h>
+#include <netdb.h>
+#include <arpa/nameser.h>
+#include "resolv_netid.h"
+#include "resolv_private.h"
+#include <sys/system_properties.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stddef.h>
+#include <string.h>
+
+static const struct afd {
+	int		a_af;
+	socklen_t	a_addrlen;
+	socklen_t	a_socklen;
+	int		a_off;
+} afdl [] = {
+#ifdef INET6
+	{PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
+		offsetof(struct sockaddr_in6, sin6_addr)},
+#endif
+	{PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
+		offsetof(struct sockaddr_in, sin_addr)},
+	{0, 0, 0, 0},
+};
+
+struct sockinet {
+	u_char	si_len;
+	u_char	si_family;
+	u_short	si_port;
+};
+
+static int getnameinfo_inet(const struct sockaddr *, socklen_t, char *,
+    socklen_t, char *, socklen_t, int, unsigned, unsigned);
+#ifdef INET6
+static int ip6_parsenumeric(const struct sockaddr *, const char *, char *,
+				 socklen_t, int);
+static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int);
+#endif
+static int getnameinfo_local(const struct sockaddr *, socklen_t, char *,
+    socklen_t, char *, socklen_t, int);
+
+/*
+ * Top-level getnameinfo() code.  Look at the address family, and pick an
+ * appropriate function to call.
+ */
+int getnameinfo(const struct sockaddr* sa, socklen_t salen, char* host, size_t hostlen,
+		char* serv, size_t servlen, int flags)
+{
+	return android_getnameinfofornet(sa, salen, host, hostlen, serv, servlen, flags,
+			NETID_UNSET, MARK_UNSET);
+}
+
+int android_getnameinfofornet(const struct sockaddr* sa, socklen_t salen, char* host,
+		size_t hostlen, char* serv, size_t servlen, int flags, unsigned netid,
+		unsigned mark)
+{
+	switch (sa->sa_family) {
+	case AF_INET:
+	case AF_INET6:
+		return getnameinfo_inet(sa, salen, host, hostlen,
+				serv, servlen, flags, netid, mark);
+	case AF_LOCAL:
+		return getnameinfo_local(sa, salen, host, hostlen,
+		    serv, servlen, flags);
+	default:
+		return EAI_FAMILY;
+	}
+}
+
+/*
+ * getnameinfo_local():
+ * Format an local address into a printable format.
+ */
+/* ARGSUSED */
+static int
+getnameinfo_local(const struct sockaddr *sa, socklen_t salen,
+    char *host, socklen_t hostlen, char *serv, socklen_t servlen,
+    int flags __attribute__((unused)))
+{
+       const struct sockaddr_un *sun =
+           (const struct sockaddr_un *)(const void *)sa;
+
+       if (salen < (socklen_t) offsetof(struct sockaddr_un, sun_path)) {
+           return EAI_FAMILY;
+       }
+
+       if (serv != NULL && servlen > 0)
+               serv[0] = '\0';
+
+       if (host && hostlen > 0)
+               strlcpy(host, sun->sun_path,
+                   MIN((socklen_t) sizeof(sun->sun_path) + 1, hostlen));
+
+       return 0;
+}
+
+/*
+ * getnameinfo_inet():
+ * Format an IPv4 or IPv6 sockaddr into a printable string.
+ */
+static int
+getnameinfo_inet(const struct sockaddr* sa, socklen_t salen,
+       char *host, socklen_t hostlen,
+       char *serv, socklen_t servlen,
+       int flags, unsigned netid, unsigned mark)
+{
+	const struct afd *afd;
+	struct servent *sp;
+	struct hostent *hp;
+	u_short port;
+	int family, i;
+	const char *addr;
+	uint32_t v4a;
+	char numserv[512];
+	char numaddr[512];
+
+	/* sa is checked below */
+	/* host may be NULL */
+	/* serv may be NULL */
+
+	if (sa == NULL)
+		return EAI_FAIL;
+
+	family = sa->sa_family;
+	for (i = 0; afdl[i].a_af; i++)
+		if (afdl[i].a_af == family) {
+			afd = &afdl[i];
+			goto found;
+		}
+	return EAI_FAMILY;
+
+ found:
+	// http://b/1889275: callers should be allowed to provide too much
+	// space, but not too little.
+	if (salen < afd->a_socklen) {
+		return EAI_FAMILY;
+	}
+
+	/* network byte order */
+	port = ((const struct sockinet *)(const void *)sa)->si_port;
+	addr = (const char *)(const void *)sa + afd->a_off;
+
+	if (serv == NULL || servlen == 0) {
+		/*
+		 * do nothing in this case.
+		 * in case you are wondering if "&&" is more correct than
+		 * "||" here: rfc2553bis-03 says that serv == NULL OR
+		 * servlen == 0 means that the caller does not want the result.
+		 */
+	} else {
+		if (flags & NI_NUMERICSERV)
+			sp = NULL;
+		else {
+			sp = getservbyport(port,
+				(flags & NI_DGRAM) ? "udp" : "tcp");
+		}
+		if (sp) {
+			if (strlen(sp->s_name) + 1 > (size_t)servlen)
+				return EAI_MEMORY;
+			strlcpy(serv, sp->s_name, servlen);
+		} else {
+			snprintf(numserv, sizeof(numserv), "%u", ntohs(port));
+			if (strlen(numserv) + 1 > (size_t)servlen)
+				return EAI_MEMORY;
+			strlcpy(serv, numserv, servlen);
+		}
+	}
+
+	switch (sa->sa_family) {
+	case AF_INET:
+		v4a = (uint32_t)
+		    ntohl(((const struct sockaddr_in *)
+		    (const void *)sa)->sin_addr.s_addr);
+		if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
+			flags |= NI_NUMERICHOST;
+		v4a >>= IN_CLASSA_NSHIFT;
+		if (v4a == 0)
+			flags |= NI_NUMERICHOST;
+		break;
+#ifdef INET6
+	case AF_INET6:
+	    {
+		const struct sockaddr_in6 *sin6;
+		sin6 = (const struct sockaddr_in6 *)(const void *)sa;
+		switch (sin6->sin6_addr.s6_addr[0]) {
+		case 0x00:
+			if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
+				;
+			else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
+				;
+			else
+				flags |= NI_NUMERICHOST;
+			break;
+		default:
+			if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
+				flags |= NI_NUMERICHOST;
+			}
+			else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
+				flags |= NI_NUMERICHOST;
+			break;
+		}
+	    }
+		break;
+#endif
+	}
+	if (host == NULL || hostlen == 0) {
+		/*
+		 * do nothing in this case.
+		 * in case you are wondering if "&&" is more correct than
+		 * "||" here: rfc2553bis-03 says that host == NULL or
+		 * hostlen == 0 means that the caller does not want the result.
+		 */
+	} else if (flags & NI_NUMERICHOST) {
+		size_t numaddrlen;
+
+		/* NUMERICHOST and NAMEREQD conflicts with each other */
+		if (flags & NI_NAMEREQD)
+			return EAI_NONAME;
+
+		switch(afd->a_af) {
+#ifdef INET6
+		case AF_INET6:
+		{
+			int error;
+
+			if ((error = ip6_parsenumeric(sa, addr, host,
+						      hostlen, flags)) != 0)
+				return(error);
+			break;
+		}
+#endif
+		default:
+			if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr))
+			    == NULL)
+				return EAI_SYSTEM;
+			numaddrlen = strlen(numaddr);
+			if (numaddrlen + 1 > (size_t)hostlen) /* don't forget terminator */
+				return EAI_MEMORY;
+			strlcpy(host, numaddr, hostlen);
+			break;
+		}
+	} else {
+		hp = android_gethostbyaddrfornet_proxy(addr, afd->a_addrlen, afd->a_af, netid);
+		if (hp) {
+#if 0
+			/*
+			 * commented out, since "for local host" is not
+			 * implemented here - see RFC2553 p30
+			 */
+			if (flags & NI_NOFQDN) {
+				char *p;
+				p = strchr(hp->h_name, '.');
+				if (p)
+					TODO: Before uncommenting rewrite to avoid modifying hp.
+					*p = '\0';
+			}
+#endif
+			if (strlen(hp->h_name) + 1 > (size_t)hostlen) {
+				return EAI_MEMORY;
+			}
+			strlcpy(host, hp->h_name, hostlen);
+		} else {
+			if (flags & NI_NAMEREQD)
+				return EAI_NONAME;
+			switch(afd->a_af) {
+#ifdef INET6
+			case AF_INET6:
+			{
+				int error;
+
+				if ((error = ip6_parsenumeric(sa, addr, host,
+							      hostlen,
+							      flags)) != 0)
+					return(error);
+				break;
+			}
+#endif
+			default:
+				if (inet_ntop(afd->a_af, addr, host,
+				    hostlen) == NULL)
+					return EAI_SYSTEM;
+				break;
+			}
+		}
+	}
+	return(0);
+}
+
+#ifdef INET6
+static int
+ip6_parsenumeric(const struct sockaddr *sa, const char *addr, char *host,
+       socklen_t hostlen, int flags)
+{
+	size_t numaddrlen;
+	char numaddr[512];
+
+	assert(sa != NULL);
+	assert(addr != NULL);
+	assert(host != NULL);
+
+	if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL)
+		return EAI_SYSTEM;
+
+	numaddrlen = strlen(numaddr);
+	if (numaddrlen + 1 > (size_t)hostlen) /* don't forget terminator */
+		return EAI_OVERFLOW;
+	strlcpy(host, numaddr, hostlen);
+
+	if (((const struct sockaddr_in6 *)(const void *)sa)->sin6_scope_id) {
+		char zonebuf[MAXHOSTNAMELEN];
+		int zonelen;
+
+		zonelen = ip6_sa2str(
+		    (const struct sockaddr_in6 *)(const void *)sa,
+		    zonebuf, sizeof(zonebuf), flags);
+		if (zonelen < 0)
+			return EAI_OVERFLOW;
+		if ((size_t) zonelen + 1 + numaddrlen + 1 > (size_t)hostlen)
+			return EAI_OVERFLOW;
+		/* construct <numeric-addr><delim><zoneid> */
+		memcpy(host + numaddrlen + 1, zonebuf,
+		    (size_t)zonelen);
+		host[numaddrlen] = SCOPE_DELIMITER;
+		host[numaddrlen + 1 + zonelen] = '\0';
+	}
+
+	return 0;
+}
+
+/* ARGSUSED */
+static int
+ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags)
+{
+	unsigned int ifindex;
+	const struct in6_addr *a6;
+	int n;
+
+	assert(sa6 != NULL);
+	assert(buf != NULL);
+
+	ifindex = (unsigned int)sa6->sin6_scope_id;
+	a6 = &sa6->sin6_addr;
+
+#ifdef NI_NUMERICSCOPE
+	if ((flags & NI_NUMERICSCOPE) != 0) {
+		n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
+		if (n < 0 || n >= bufsiz)
+			return -1;
+		else
+			return n;
+	}
+#endif
+
+	/* if_indextoname() does not take buffer size.  not a good api... */
+	if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) &&
+	    bufsiz >= IF_NAMESIZE) {
+		char *p = if_indextoname(ifindex, buf);
+		if (p) {
+			return(strlen(p));
+		}
+	}
+
+	/* last resort */
+	n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
+	if (n < 0 || (size_t) n >= bufsiz)
+		return -1;
+	else
+		return n;
+}
+#endif /* INET6 */
diff --git a/libc/dns/net/getservbyname.c b/libc/dns/net/getservbyname.c
new file mode 100644
index 0000000..c95c9b0
--- /dev/null
+++ b/libc/dns/net/getservbyname.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <netdb.h>
+#include "servent.h"
+
+struct servent *
+getservbyname(const char *name, const char *proto)
+{
+    res_static       rs = __res_get_static();
+
+    if (rs == NULL || proto == NULL || name == NULL) {
+        errno = EINVAL;
+        return NULL;
+    }
+
+    rs->servent_ptr = NULL;
+    while (1) {
+        struct servent*  s = getservent_r(rs);
+        if (s == NULL)
+            break;
+        if ( !strcmp( s->s_name, name ) && !strcmp( s->s_proto, proto ) )
+            return s;
+    }
+
+    return NULL;
+}
diff --git a/libc/dns/net/getservbyport.c b/libc/dns/net/getservbyport.c
new file mode 100644
index 0000000..7dcaafb
--- /dev/null
+++ b/libc/dns/net/getservbyport.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+#include <netdb.h>
+#include "servent.h"
+
+struct servent *
+getservbyport(int port, const char *proto)
+{
+    res_static       rs = __res_get_static();
+
+    if (rs == NULL || proto == NULL) {
+        errno = EINVAL;
+        return NULL;
+    }
+
+    rs->servent_ptr = NULL;
+    while (1) {
+        struct servent*  s = getservent_r(rs);
+        if (s == NULL)
+            break;
+        if ( s->s_port == port && !strcmp( s->s_proto, proto ) )
+            return s;
+    }
+
+    return NULL;
+}
diff --git a/libc/netbsd/net/getservent.c b/libc/dns/net/getservent.c
similarity index 100%
rename from libc/netbsd/net/getservent.c
rename to libc/dns/net/getservent.c
diff --git a/libc/dns/net/nsdispatch.c b/libc/dns/net/nsdispatch.c
new file mode 100644
index 0000000..fb6d8f6
--- /dev/null
+++ b/libc/dns/net/nsdispatch.c
@@ -0,0 +1,141 @@
+/*	$NetBSD: nsdispatch.c,v 1.30 2005/11/29 03:11:59 christos Exp $	*/
+
+/*-
+ * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Luke Mewburn; and by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (c) 2003 Networks Associates Technology, Inc.
+ * All rights reserved.
+ *
+ * Portions of this software were developed for the FreeBSD Project by
+ * Jacques A. Vidrine, Safeport Network Services, and Network
+ * Associates Laboratories, the Security Research Division of Network
+ * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
+ * ("CBOSS"), as part of the DARPA CHATS research program.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+#include <assert.h>
+#include <nsswitch.h>
+#include <stdarg.h>
+#include <strings.h>
+
+static nss_method
+_nsmethod(const char *source, const char *database __unused, const char *method __unused,
+    const ns_dtab disp_tab[], void **cb_data)
+{
+	int	curdisp;
+
+	if (disp_tab != NULL) {
+		for (curdisp = 0; disp_tab[curdisp].src != NULL; curdisp++) {
+			if (strcasecmp(source, disp_tab[curdisp].src) == 0) {
+				*cb_data = disp_tab[curdisp].cb_data;
+				return (disp_tab[curdisp].callback);
+			}
+		}
+	}
+
+	*cb_data = NULL;
+	return (NULL);
+}
+
+int
+/*ARGSUSED*/
+nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
+	    const char *method, const ns_src defaults[], ...)
+{
+	va_list		 ap;
+	int		 i, result;
+	const ns_src	*srclist;
+	int		 srclistsize;
+	nss_method	 cb;
+	void		*cb_data;
+
+	/* retval may be NULL */
+	/* disp_tab may be NULL */
+	assert(database != NULL);
+	assert(method != NULL);
+	assert(defaults != NULL);
+	if (database == NULL || method == NULL || defaults == NULL)
+		return (NS_UNAVAIL);
+
+        srclist = defaults;
+        srclistsize = 0;
+        while (srclist[srclistsize].name != NULL)
+                srclistsize++;
+
+	result = 0;
+
+	for (i = 0; i < srclistsize; i++) {
+		cb = _nsmethod(srclist[i].name, database, method,
+		    disp_tab, &cb_data);
+		result = 0;
+		if (cb != NULL) {
+			va_start(ap, defaults);
+			result = (*cb)(retval, cb_data, ap);
+			va_end(ap);
+			if (defaults[0].flags & NS_FORCEALL)
+				continue;
+			if (result & srclist[i].flags)
+				break;
+		}
+	}
+	result &= NS_STATUSMASK;	/* clear private flags in result */
+
+	return (result ? result : NS_NOTFOUND);
+}
diff --git a/libc/netbsd/net/servent.h b/libc/dns/net/servent.h
similarity index 100%
rename from libc/netbsd/net/servent.h
rename to libc/dns/net/servent.h
diff --git a/libc/netbsd/net/services.h b/libc/dns/net/services.h
similarity index 100%
rename from libc/netbsd/net/services.h
rename to libc/dns/net/services.h
diff --git a/libc/netbsd/resolv/__dn_comp.c b/libc/dns/resolv/__dn_comp.c
similarity index 100%
rename from libc/netbsd/resolv/__dn_comp.c
rename to libc/dns/resolv/__dn_comp.c
diff --git a/libc/netbsd/resolv/__res_close.c b/libc/dns/resolv/__res_close.c
similarity index 100%
rename from libc/netbsd/resolv/__res_close.c
rename to libc/dns/resolv/__res_close.c
diff --git a/libc/netbsd/resolv/__res_send.c b/libc/dns/resolv/__res_send.c
similarity index 100%
rename from libc/netbsd/resolv/__res_send.c
rename to libc/dns/resolv/__res_send.c
diff --git a/libc/dns/resolv/herror.c b/libc/dns/resolv/herror.c
new file mode 100644
index 0000000..9aaf696
--- /dev/null
+++ b/libc/dns/resolv/herror.c
@@ -0,0 +1,133 @@
+/*	$NetBSD: herror.c,v 1.4 2004/05/23 05:09:52 christos Exp $	*/
+
+/*
+ * Copyright (c) 1987, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#ifdef notdef
+static const char sccsid[] = "@(#)herror.c	8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "Id: herror.c,v 1.2.206.1 2004/03/09 08:33:54 marka Exp";
+#else
+__RCSID("$NetBSD: herror.c,v 1.4 2004/05/23 05:09:52 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/uio.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+#include <netdb.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <string.h>
+#include <unistd.h>
+
+#ifndef DE_CONST
+#define DE_CONST(c,v)   v = ((c) ? \
+    strchr((const void *)(c), *(const char *)(const void *)(c)) : NULL)
+#endif
+
+const char * const h_errlist[] = {
+	"Resolver Error 0 (no error)",
+	"Unknown host",				/* 1 HOST_NOT_FOUND */
+	"Host name lookup failure",		/* 2 TRY_AGAIN */
+	"Unknown server error",			/* 3 NO_RECOVERY */
+	"No address associated with name",	/* 4 NO_ADDRESS */
+};
+const int	h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
+
+/*
+ * herror --
+ *	print the error indicated by the h_errno value.
+ */
+void
+herror(const char *s) {
+	struct iovec iov[4], *v = iov;
+	char *t;
+
+	if (s != NULL && *s != '\0') {
+		DE_CONST(s, t);
+		v->iov_base = t;
+		v->iov_len = strlen(t);
+		v++;
+		DE_CONST(": ", t);
+		v->iov_base = t;
+		v->iov_len = 2;
+		v++;
+	}
+	DE_CONST(hstrerror(h_errno), t);
+	v->iov_base = t;
+	v->iov_len = strlen(v->iov_base);
+	v++;
+	DE_CONST("\n", t);
+	v->iov_base = t;
+	v->iov_len = 1;
+	writev(STDERR_FILENO, iov, (v - iov) + 1);
+}
+
+/*
+ * hstrerror --
+ *	return the string associated with a given "host" errno value.
+ */
+const char *
+hstrerror(int err) {
+	if (err < 0)
+		return ("Resolver internal error");
+	else if (err < h_nerr)
+		return (h_errlist[err]);
+	return ("Unknown resolver error");
+}
diff --git a/libc/dns/resolv/res_cache.c b/libc/dns/resolv/res_cache.c
new file mode 100644
index 0000000..d68ec3b
--- /dev/null
+++ b/libc/dns/resolv/res_cache.c
@@ -0,0 +1,2099 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "resolv_cache.h"
+#include <resolv.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "pthread.h"
+
+#include <errno.h>
+#include <arpa/nameser.h>
+#include <sys/system_properties.h>
+#include <net/if.h>
+#include <netdb.h>
+#include <linux/if.h>
+
+#include <arpa/inet.h>
+#include "resolv_private.h"
+#include "resolv_netid.h"
+#include "res_private.h"
+
+/* This code implements a small and *simple* DNS resolver cache.
+ *
+ * It is only used to cache DNS answers for a time defined by the smallest TTL
+ * among the answer records in order to reduce DNS traffic. It is not supposed
+ * to be a full DNS cache, since we plan to implement that in the future in a
+ * dedicated process running on the system.
+ *
+ * Note that its design is kept simple very intentionally, i.e.:
+ *
+ *  - it takes raw DNS query packet data as input, and returns raw DNS
+ *    answer packet data as output
+ *
+ *    (this means that two similar queries that encode the DNS name
+ *     differently will be treated distinctly).
+ *
+ *    the smallest TTL value among the answer records are used as the time
+ *    to keep an answer in the cache.
+ *
+ *    this is bad, but we absolutely want to avoid parsing the answer packets
+ *    (and should be solved by the later full DNS cache process).
+ *
+ *  - the implementation is just a (query-data) => (answer-data) hash table
+ *    with a trivial least-recently-used expiration policy.
+ *
+ * Doing this keeps the code simple and avoids to deal with a lot of things
+ * that a full DNS cache is expected to do.
+ *
+ * The API is also very simple:
+ *
+ *   - the client calls _resolv_cache_get() to obtain a handle to the cache.
+ *     this will initialize the cache on first usage. the result can be NULL
+ *     if the cache is disabled.
+ *
+ *   - the client calls _resolv_cache_lookup() before performing a query
+ *
+ *     if the function returns RESOLV_CACHE_FOUND, a copy of the answer data
+ *     has been copied into the client-provided answer buffer.
+ *
+ *     if the function returns RESOLV_CACHE_NOTFOUND, the client should perform
+ *     a request normally, *then* call _resolv_cache_add() to add the received
+ *     answer to the cache.
+ *
+ *     if the function returns RESOLV_CACHE_UNSUPPORTED, the client should
+ *     perform a request normally, and *not* call _resolv_cache_add()
+ *
+ *     note that RESOLV_CACHE_UNSUPPORTED is also returned if the answer buffer
+ *     is too short to accomodate the cached result.
+ */
+
+/* the name of an environment variable that will be checked the first time
+ * this code is called if its value is "0", then the resolver cache is
+ * disabled.
+ */
+#define  CONFIG_ENV  "BIONIC_DNSCACHE"
+
+/* entries older than CONFIG_SECONDS seconds are always discarded.
+ */
+#define  CONFIG_SECONDS    (60*10)    /* 10 minutes */
+
+/* default number of entries kept in the cache. This value has been
+ * determined by browsing through various sites and counting the number
+ * of corresponding requests. Keep in mind that our framework is currently
+ * performing two requests per name lookup (one for IPv4, the other for IPv6)
+ *
+ *    www.google.com      4
+ *    www.ysearch.com     6
+ *    www.amazon.com      8
+ *    www.nytimes.com     22
+ *    www.espn.com        28
+ *    www.msn.com         28
+ *    www.lemonde.fr      35
+ *
+ * (determined in 2009-2-17 from Paris, France, results may vary depending
+ *  on location)
+ *
+ * most high-level websites use lots of media/ad servers with different names
+ * but these are generally reused when browsing through the site.
+ *
+ * As such, a value of 64 should be relatively comfortable at the moment.
+ *
+ * ******************************************
+ * * NOTE - this has changed.
+ * * 1) we've added IPv6 support so each dns query results in 2 responses
+ * * 2) we've made this a system-wide cache, so the cost is less (it's not
+ * *    duplicated in each process) and the need is greater (more processes
+ * *    making different requests).
+ * * Upping by 2x for IPv6
+ * * Upping by another 5x for the centralized nature
+ * *****************************************
+ */
+#define  CONFIG_MAX_ENTRIES    64 * 2 * 5
+/* name of the system property that can be used to set the cache size */
+
+/****************************************************************************/
+/****************************************************************************/
+/*****                                                                  *****/
+/*****                                                                  *****/
+/*****                                                                  *****/
+/****************************************************************************/
+/****************************************************************************/
+
+/* set to 1 to debug cache operations */
+#define  DEBUG       0
+
+/* set to 1 to debug query data */
+#define  DEBUG_DATA  0
+
+#undef XLOG
+#if DEBUG
+#  include "private/libc_logging.h"
+#  define XLOG(...)  __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__)
+
+#include <stdio.h>
+#include <stdarg.h>
+
+/** BOUNDED BUFFER FORMATTING
+ **/
+
+/* technical note:
+ *
+ *   the following debugging routines are used to append data to a bounded
+ *   buffer they take two parameters that are:
+ *
+ *   - p : a pointer to the current cursor position in the buffer
+ *         this value is initially set to the buffer's address.
+ *
+ *   - end : the address of the buffer's limit, i.e. of the first byte
+ *           after the buffer. this address should never be touched.
+ *
+ *           IMPORTANT: it is assumed that end > buffer_address, i.e.
+ *                      that the buffer is at least one byte.
+ *
+ *   the _bprint_() functions return the new value of 'p' after the data
+ *   has been appended, and also ensure the following:
+ *
+ *   - the returned value will never be strictly greater than 'end'
+ *
+ *   - a return value equal to 'end' means that truncation occured
+ *     (in which case, end[-1] will be set to 0)
+ *
+ *   - after returning from a _bprint_() function, the content of the buffer
+ *     is always 0-terminated, even in the event of truncation.
+ *
+ *  these conventions allow you to call _bprint_ functions multiple times and
+ *  only check for truncation at the end of the sequence, as in:
+ *
+ *     char  buff[1000], *p = buff, *end = p + sizeof(buff);
+ *
+ *     p = _bprint_c(p, end, '"');
+ *     p = _bprint_s(p, end, my_string);
+ *     p = _bprint_c(p, end, '"');
+ *
+ *     if (p >= end) {
+ *        // buffer was too small
+ *     }
+ *
+ *     printf( "%s", buff );
+ */
+
+/* add a char to a bounded buffer */
+static char*
+_bprint_c( char*  p, char*  end, int  c )
+{
+    if (p < end) {
+        if (p+1 == end)
+            *p++ = 0;
+        else {
+            *p++ = (char) c;
+            *p   = 0;
+        }
+    }
+    return p;
+}
+
+/* add a sequence of bytes to a bounded buffer */
+static char*
+_bprint_b( char*  p, char*  end, const char*  buf, int  len )
+{
+    int  avail = end - p;
+
+    if (avail <= 0 || len <= 0)
+        return p;
+
+    if (avail > len)
+        avail = len;
+
+    memcpy( p, buf, avail );
+    p += avail;
+
+    if (p < end)
+        p[0] = 0;
+    else
+        end[-1] = 0;
+
+    return p;
+}
+
+/* add a string to a bounded buffer */
+static char*
+_bprint_s( char*  p, char*  end, const char*  str )
+{
+    return _bprint_b(p, end, str, strlen(str));
+}
+
+/* add a formatted string to a bounded buffer */
+static char*
+_bprint( char*  p, char*  end, const char*  format, ... )
+{
+    int      avail, n;
+    va_list  args;
+
+    avail = end - p;
+
+    if (avail <= 0)
+        return p;
+
+    va_start(args, format);
+    n = vsnprintf( p, avail, format, args);
+    va_end(args);
+
+    /* certain C libraries return -1 in case of truncation */
+    if (n < 0 || n > avail)
+        n = avail;
+
+    p += n;
+    /* certain C libraries do not zero-terminate in case of truncation */
+    if (p == end)
+        p[-1] = 0;
+
+    return p;
+}
+
+/* add a hex value to a bounded buffer, up to 8 digits */
+static char*
+_bprint_hex( char*  p, char*  end, unsigned  value, int  numDigits )
+{
+    char   text[sizeof(unsigned)*2];
+    int    nn = 0;
+
+    while (numDigits-- > 0) {
+        text[nn++] = "0123456789abcdef"[(value >> (numDigits*4)) & 15];
+    }
+    return _bprint_b(p, end, text, nn);
+}
+
+/* add the hexadecimal dump of some memory area to a bounded buffer */
+static char*
+_bprint_hexdump( char*  p, char*  end, const uint8_t*  data, int  datalen )
+{
+    int   lineSize = 16;
+
+    while (datalen > 0) {
+        int  avail = datalen;
+        int  nn;
+
+        if (avail > lineSize)
+            avail = lineSize;
+
+        for (nn = 0; nn < avail; nn++) {
+            if (nn > 0)
+                p = _bprint_c(p, end, ' ');
+            p = _bprint_hex(p, end, data[nn], 2);
+        }
+        for ( ; nn < lineSize; nn++ ) {
+            p = _bprint_s(p, end, "   ");
+        }
+        p = _bprint_s(p, end, "  ");
+
+        for (nn = 0; nn < avail; nn++) {
+            int  c = data[nn];
+
+            if (c < 32 || c > 127)
+                c = '.';
+
+            p = _bprint_c(p, end, c);
+        }
+        p = _bprint_c(p, end, '\n');
+
+        data    += avail;
+        datalen -= avail;
+    }
+    return p;
+}
+
+/* dump the content of a query of packet to the log */
+static void
+XLOG_BYTES( const void*  base, int  len )
+{
+    char  buff[1024];
+    char*  p = buff, *end = p + sizeof(buff);
+
+    p = _bprint_hexdump(p, end, base, len);
+    XLOG("%s",buff);
+}
+
+#else /* !DEBUG */
+#  define  XLOG(...)        ((void)0)
+#  define  XLOG_BYTES(a,b)  ((void)0)
+#endif
+
+static time_t
+_time_now( void )
+{
+    struct timeval  tv;
+
+    gettimeofday( &tv, NULL );
+    return tv.tv_sec;
+}
+
+/* reminder: the general format of a DNS packet is the following:
+ *
+ *    HEADER  (12 bytes)
+ *    QUESTION  (variable)
+ *    ANSWER (variable)
+ *    AUTHORITY (variable)
+ *    ADDITIONNAL (variable)
+ *
+ * the HEADER is made of:
+ *
+ *   ID     : 16 : 16-bit unique query identification field
+ *
+ *   QR     :  1 : set to 0 for queries, and 1 for responses
+ *   Opcode :  4 : set to 0 for queries
+ *   AA     :  1 : set to 0 for queries
+ *   TC     :  1 : truncation flag, will be set to 0 in queries
+ *   RD     :  1 : recursion desired
+ *
+ *   RA     :  1 : recursion available (0 in queries)
+ *   Z      :  3 : three reserved zero bits
+ *   RCODE  :  4 : response code (always 0=NOERROR in queries)
+ *
+ *   QDCount: 16 : question count
+ *   ANCount: 16 : Answer count (0 in queries)
+ *   NSCount: 16: Authority Record count (0 in queries)
+ *   ARCount: 16: Additionnal Record count (0 in queries)
+ *
+ * the QUESTION is made of QDCount Question Record (QRs)
+ * the ANSWER is made of ANCount RRs
+ * the AUTHORITY is made of NSCount RRs
+ * the ADDITIONNAL is made of ARCount RRs
+ *
+ * Each Question Record (QR) is made of:
+ *
+ *   QNAME   : variable : Query DNS NAME
+ *   TYPE    : 16       : type of query (A=1, PTR=12, MX=15, AAAA=28, ALL=255)
+ *   CLASS   : 16       : class of query (IN=1)
+ *
+ * Each Resource Record (RR) is made of:
+ *
+ *   NAME    : variable : DNS NAME
+ *   TYPE    : 16       : type of query (A=1, PTR=12, MX=15, AAAA=28, ALL=255)
+ *   CLASS   : 16       : class of query (IN=1)
+ *   TTL     : 32       : seconds to cache this RR (0=none)
+ *   RDLENGTH: 16       : size of RDDATA in bytes
+ *   RDDATA  : variable : RR data (depends on TYPE)
+ *
+ * Each QNAME contains a domain name encoded as a sequence of 'labels'
+ * terminated by a zero. Each label has the following format:
+ *
+ *    LEN  : 8     : lenght of label (MUST be < 64)
+ *    NAME : 8*LEN : label length (must exclude dots)
+ *
+ * A value of 0 in the encoding is interpreted as the 'root' domain and
+ * terminates the encoding. So 'www.android.com' will be encoded as:
+ *
+ *   <3>www<7>android<3>com<0>
+ *
+ * Where <n> represents the byte with value 'n'
+ *
+ * Each NAME reflects the QNAME of the question, but has a slightly more
+ * complex encoding in order to provide message compression. This is achieved
+ * by using a 2-byte pointer, with format:
+ *
+ *    TYPE   : 2  : 0b11 to indicate a pointer, 0b01 and 0b10 are reserved
+ *    OFFSET : 14 : offset to another part of the DNS packet
+ *
+ * The offset is relative to the start of the DNS packet and must point
+ * A pointer terminates the encoding.
+ *
+ * The NAME can be encoded in one of the following formats:
+ *
+ *   - a sequence of simple labels terminated by 0 (like QNAMEs)
+ *   - a single pointer
+ *   - a sequence of simple labels terminated by a pointer
+ *
+ * A pointer shall always point to either a pointer of a sequence of
+ * labels (which can themselves be terminated by either a 0 or a pointer)
+ *
+ * The expanded length of a given domain name should not exceed 255 bytes.
+ *
+ * NOTE: we don't parse the answer packets, so don't need to deal with NAME
+ *       records, only QNAMEs.
+ */
+
+#define  DNS_HEADER_SIZE  12
+
+#define  DNS_TYPE_A   "\00\01"   /* big-endian decimal 1 */
+#define  DNS_TYPE_PTR "\00\014"  /* big-endian decimal 12 */
+#define  DNS_TYPE_MX  "\00\017"  /* big-endian decimal 15 */
+#define  DNS_TYPE_AAAA "\00\034" /* big-endian decimal 28 */
+#define  DNS_TYPE_ALL "\00\0377" /* big-endian decimal 255 */
+
+#define  DNS_CLASS_IN "\00\01"   /* big-endian decimal 1 */
+
+typedef struct {
+    const uint8_t*  base;
+    const uint8_t*  end;
+    const uint8_t*  cursor;
+} DnsPacket;
+
+static void
+_dnsPacket_init( DnsPacket*  packet, const uint8_t*  buff, int  bufflen )
+{
+    packet->base   = buff;
+    packet->end    = buff + bufflen;
+    packet->cursor = buff;
+}
+
+static void
+_dnsPacket_rewind( DnsPacket*  packet )
+{
+    packet->cursor = packet->base;
+}
+
+static void
+_dnsPacket_skip( DnsPacket*  packet, int  count )
+{
+    const uint8_t*  p = packet->cursor + count;
+
+    if (p > packet->end)
+        p = packet->end;
+
+    packet->cursor = p;
+}
+
+static int
+_dnsPacket_readInt16( DnsPacket*  packet )
+{
+    const uint8_t*  p = packet->cursor;
+
+    if (p+2 > packet->end)
+        return -1;
+
+    packet->cursor = p+2;
+    return (p[0]<< 8) | p[1];
+}
+
+/** QUERY CHECKING
+ **/
+
+/* check bytes in a dns packet. returns 1 on success, 0 on failure.
+ * the cursor is only advanced in the case of success
+ */
+static int
+_dnsPacket_checkBytes( DnsPacket*  packet, int  numBytes, const void*  bytes )
+{
+    const uint8_t*  p = packet->cursor;
+
+    if (p + numBytes > packet->end)
+        return 0;
+
+    if (memcmp(p, bytes, numBytes) != 0)
+        return 0;
+
+    packet->cursor = p + numBytes;
+    return 1;
+}
+
+/* parse and skip a given QNAME stored in a query packet,
+ * from the current cursor position. returns 1 on success,
+ * or 0 for malformed data.
+ */
+static int
+_dnsPacket_checkQName( DnsPacket*  packet )
+{
+    const uint8_t*  p   = packet->cursor;
+    const uint8_t*  end = packet->end;
+
+    for (;;) {
+        int  c;
+
+        if (p >= end)
+            break;
+
+        c = *p++;
+
+        if (c == 0) {
+            packet->cursor = p;
+            return 1;
+        }
+
+        /* we don't expect label compression in QNAMEs */
+        if (c >= 64)
+            break;
+
+        p += c;
+        /* we rely on the bound check at the start
+         * of the loop here */
+    }
+    /* malformed data */
+    XLOG("malformed QNAME");
+    return 0;
+}
+
+/* parse and skip a given QR stored in a packet.
+ * returns 1 on success, and 0 on failure
+ */
+static int
+_dnsPacket_checkQR( DnsPacket*  packet )
+{
+    if (!_dnsPacket_checkQName(packet))
+        return 0;
+
+    /* TYPE must be one of the things we support */
+    if (!_dnsPacket_checkBytes(packet, 2, DNS_TYPE_A) &&
+        !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_PTR) &&
+        !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_MX) &&
+        !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_AAAA) &&
+        !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_ALL))
+    {
+        XLOG("unsupported TYPE");
+        return 0;
+    }
+    /* CLASS must be IN */
+    if (!_dnsPacket_checkBytes(packet, 2, DNS_CLASS_IN)) {
+        XLOG("unsupported CLASS");
+        return 0;
+    }
+
+    return 1;
+}
+
+/* check the header of a DNS Query packet, return 1 if it is one
+ * type of query we can cache, or 0 otherwise
+ */
+static int
+_dnsPacket_checkQuery( DnsPacket*  packet )
+{
+    const uint8_t*  p = packet->base;
+    int             qdCount, anCount, dnCount, arCount;
+
+    if (p + DNS_HEADER_SIZE > packet->end) {
+        XLOG("query packet too small");
+        return 0;
+    }
+
+    /* QR must be set to 0, opcode must be 0 and AA must be 0 */
+    /* RA, Z, and RCODE must be 0 */
+    if ((p[2] & 0xFC) != 0 || p[3] != 0) {
+        XLOG("query packet flags unsupported");
+        return 0;
+    }
+
+    /* Note that we ignore the TC and RD bits here for the
+     * following reasons:
+     *
+     * - there is no point for a query packet sent to a server
+     *   to have the TC bit set, but the implementation might
+     *   set the bit in the query buffer for its own needs
+     *   between a _resolv_cache_lookup and a
+     *   _resolv_cache_add. We should not freak out if this
+     *   is the case.
+     *
+     * - we consider that the result from a RD=0 or a RD=1
+     *   query might be different, hence that the RD bit
+     *   should be used to differentiate cached result.
+     *
+     *   this implies that RD is checked when hashing or
+     *   comparing query packets, but not TC
+     */
+
+    /* ANCOUNT, DNCOUNT and ARCOUNT must be 0 */
+    qdCount = (p[4] << 8) | p[5];
+    anCount = (p[6] << 8) | p[7];
+    dnCount = (p[8] << 8) | p[9];
+    arCount = (p[10]<< 8) | p[11];
+
+    if (anCount != 0 || dnCount != 0 || arCount != 0) {
+        XLOG("query packet contains non-query records");
+        return 0;
+    }
+
+    if (qdCount == 0) {
+        XLOG("query packet doesn't contain query record");
+        return 0;
+    }
+
+    /* Check QDCOUNT QRs */
+    packet->cursor = p + DNS_HEADER_SIZE;
+
+    for (;qdCount > 0; qdCount--)
+        if (!_dnsPacket_checkQR(packet))
+            return 0;
+
+    return 1;
+}
+
+/** QUERY DEBUGGING
+ **/
+#if DEBUG
+static char*
+_dnsPacket_bprintQName(DnsPacket*  packet, char*  bp, char*  bend)
+{
+    const uint8_t*  p   = packet->cursor;
+    const uint8_t*  end = packet->end;
+    int             first = 1;
+
+    for (;;) {
+        int  c;
+
+        if (p >= end)
+            break;
+
+        c = *p++;
+
+        if (c == 0) {
+            packet->cursor = p;
+            return bp;
+        }
+
+        /* we don't expect label compression in QNAMEs */
+        if (c >= 64)
+            break;
+
+        if (first)
+            first = 0;
+        else
+            bp = _bprint_c(bp, bend, '.');
+
+        bp = _bprint_b(bp, bend, (const char*)p, c);
+
+        p += c;
+        /* we rely on the bound check at the start
+         * of the loop here */
+    }
+    /* malformed data */
+    bp = _bprint_s(bp, bend, "<MALFORMED>");
+    return bp;
+}
+
+static char*
+_dnsPacket_bprintQR(DnsPacket*  packet, char*  p, char*  end)
+{
+#define  QQ(x)   { DNS_TYPE_##x, #x }
+    static const struct {
+        const char*  typeBytes;
+        const char*  typeString;
+    } qTypes[] =
+    {
+        QQ(A), QQ(PTR), QQ(MX), QQ(AAAA), QQ(ALL),
+        { NULL, NULL }
+    };
+    int          nn;
+    const char*  typeString = NULL;
+
+    /* dump QNAME */
+    p = _dnsPacket_bprintQName(packet, p, end);
+
+    /* dump TYPE */
+    p = _bprint_s(p, end, " (");
+
+    for (nn = 0; qTypes[nn].typeBytes != NULL; nn++) {
+        if (_dnsPacket_checkBytes(packet, 2, qTypes[nn].typeBytes)) {
+            typeString = qTypes[nn].typeString;
+            break;
+        }
+    }
+
+    if (typeString != NULL)
+        p = _bprint_s(p, end, typeString);
+    else {
+        int  typeCode = _dnsPacket_readInt16(packet);
+        p = _bprint(p, end, "UNKNOWN-%d", typeCode);
+    }
+
+    p = _bprint_c(p, end, ')');
+
+    /* skip CLASS */
+    _dnsPacket_skip(packet, 2);
+    return p;
+}
+
+/* this function assumes the packet has already been checked */
+static char*
+_dnsPacket_bprintQuery( DnsPacket*  packet, char*  p, char*  end )
+{
+    int   qdCount;
+
+    if (packet->base[2] & 0x1) {
+        p = _bprint_s(p, end, "RECURSIVE ");
+    }
+
+    _dnsPacket_skip(packet, 4);
+    qdCount = _dnsPacket_readInt16(packet);
+    _dnsPacket_skip(packet, 6);
+
+    for ( ; qdCount > 0; qdCount-- ) {
+        p = _dnsPacket_bprintQR(packet, p, end);
+    }
+    return p;
+}
+#endif
+
+
+/** QUERY HASHING SUPPORT
+ **
+ ** THE FOLLOWING CODE ASSUMES THAT THE INPUT PACKET HAS ALREADY
+ ** BEEN SUCCESFULLY CHECKED.
+ **/
+
+/* use 32-bit FNV hash function */
+#define  FNV_MULT   16777619U
+#define  FNV_BASIS  2166136261U
+
+static unsigned
+_dnsPacket_hashBytes( DnsPacket*  packet, int  numBytes, unsigned  hash )
+{
+    const uint8_t*  p   = packet->cursor;
+    const uint8_t*  end = packet->end;
+
+    while (numBytes > 0 && p < end) {
+        hash = hash*FNV_MULT ^ *p++;
+    }
+    packet->cursor = p;
+    return hash;
+}
+
+
+static unsigned
+_dnsPacket_hashQName( DnsPacket*  packet, unsigned  hash )
+{
+    const uint8_t*  p   = packet->cursor;
+    const uint8_t*  end = packet->end;
+
+    for (;;) {
+        int  c;
+
+        if (p >= end) {  /* should not happen */
+            XLOG("%s: INTERNAL_ERROR: read-overflow !!\n", __FUNCTION__);
+            break;
+        }
+
+        c = *p++;
+
+        if (c == 0)
+            break;
+
+        if (c >= 64) {
+            XLOG("%s: INTERNAL_ERROR: malformed domain !!\n", __FUNCTION__);
+            break;
+        }
+        if (p + c >= end) {
+            XLOG("%s: INTERNAL_ERROR: simple label read-overflow !!\n",
+                    __FUNCTION__);
+            break;
+        }
+        while (c > 0) {
+            hash = hash*FNV_MULT ^ *p++;
+            c   -= 1;
+        }
+    }
+    packet->cursor = p;
+    return hash;
+}
+
+static unsigned
+_dnsPacket_hashQR( DnsPacket*  packet, unsigned  hash )
+{
+    hash = _dnsPacket_hashQName(packet, hash);
+    hash = _dnsPacket_hashBytes(packet, 4, hash); /* TYPE and CLASS */
+    return hash;
+}
+
+static unsigned
+_dnsPacket_hashQuery( DnsPacket*  packet )
+{
+    unsigned  hash = FNV_BASIS;
+    int       count;
+    _dnsPacket_rewind(packet);
+
+    /* we ignore the TC bit for reasons explained in
+     * _dnsPacket_checkQuery().
+     *
+     * however we hash the RD bit to differentiate
+     * between answers for recursive and non-recursive
+     * queries.
+     */
+    hash = hash*FNV_MULT ^ (packet->base[2] & 1);
+
+    /* assume: other flags are 0 */
+    _dnsPacket_skip(packet, 4);
+
+    /* read QDCOUNT */
+    count = _dnsPacket_readInt16(packet);
+
+    /* assume: ANcount, NScount, ARcount are 0 */
+    _dnsPacket_skip(packet, 6);
+
+    /* hash QDCOUNT QRs */
+    for ( ; count > 0; count-- )
+        hash = _dnsPacket_hashQR(packet, hash);
+
+    return hash;
+}
+
+
+/** QUERY COMPARISON
+ **
+ ** THE FOLLOWING CODE ASSUMES THAT THE INPUT PACKETS HAVE ALREADY
+ ** BEEN SUCCESFULLY CHECKED.
+ **/
+
+static int
+_dnsPacket_isEqualDomainName( DnsPacket*  pack1, DnsPacket*  pack2 )
+{
+    const uint8_t*  p1   = pack1->cursor;
+    const uint8_t*  end1 = pack1->end;
+    const uint8_t*  p2   = pack2->cursor;
+    const uint8_t*  end2 = pack2->end;
+
+    for (;;) {
+        int  c1, c2;
+
+        if (p1 >= end1 || p2 >= end2) {
+            XLOG("%s: INTERNAL_ERROR: read-overflow !!\n", __FUNCTION__);
+            break;
+        }
+        c1 = *p1++;
+        c2 = *p2++;
+        if (c1 != c2)
+            break;
+
+        if (c1 == 0) {
+            pack1->cursor = p1;
+            pack2->cursor = p2;
+            return 1;
+        }
+        if (c1 >= 64) {
+            XLOG("%s: INTERNAL_ERROR: malformed domain !!\n", __FUNCTION__);
+            break;
+        }
+        if ((p1+c1 > end1) || (p2+c1 > end2)) {
+            XLOG("%s: INTERNAL_ERROR: simple label read-overflow !!\n",
+                    __FUNCTION__);
+            break;
+        }
+        if (memcmp(p1, p2, c1) != 0)
+            break;
+        p1 += c1;
+        p2 += c1;
+        /* we rely on the bound checks at the start of the loop */
+    }
+    /* not the same, or one is malformed */
+    XLOG("different DN");
+    return 0;
+}
+
+static int
+_dnsPacket_isEqualBytes( DnsPacket*  pack1, DnsPacket*  pack2, int  numBytes )
+{
+    const uint8_t*  p1 = pack1->cursor;
+    const uint8_t*  p2 = pack2->cursor;
+
+    if ( p1 + numBytes > pack1->end || p2 + numBytes > pack2->end )
+        return 0;
+
+    if ( memcmp(p1, p2, numBytes) != 0 )
+        return 0;
+
+    pack1->cursor += numBytes;
+    pack2->cursor += numBytes;
+    return 1;
+}
+
+static int
+_dnsPacket_isEqualQR( DnsPacket*  pack1, DnsPacket*  pack2 )
+{
+    /* compare domain name encoding + TYPE + CLASS */
+    if ( !_dnsPacket_isEqualDomainName(pack1, pack2) ||
+         !_dnsPacket_isEqualBytes(pack1, pack2, 2+2) )
+        return 0;
+
+    return 1;
+}
+
+static int
+_dnsPacket_isEqualQuery( DnsPacket*  pack1, DnsPacket*  pack2 )
+{
+    int  count1, count2;
+
+    /* compare the headers, ignore most fields */
+    _dnsPacket_rewind(pack1);
+    _dnsPacket_rewind(pack2);
+
+    /* compare RD, ignore TC, see comment in _dnsPacket_checkQuery */
+    if ((pack1->base[2] & 1) != (pack2->base[2] & 1)) {
+        XLOG("different RD");
+        return 0;
+    }
+
+    /* assume: other flags are all 0 */
+    _dnsPacket_skip(pack1, 4);
+    _dnsPacket_skip(pack2, 4);
+
+    /* compare QDCOUNT */
+    count1 = _dnsPacket_readInt16(pack1);
+    count2 = _dnsPacket_readInt16(pack2);
+    if (count1 != count2 || count1 < 0) {
+        XLOG("different QDCOUNT");
+        return 0;
+    }
+
+    /* assume: ANcount, NScount and ARcount are all 0 */
+    _dnsPacket_skip(pack1, 6);
+    _dnsPacket_skip(pack2, 6);
+
+    /* compare the QDCOUNT QRs */
+    for ( ; count1 > 0; count1-- ) {
+        if (!_dnsPacket_isEqualQR(pack1, pack2)) {
+            XLOG("different QR");
+            return 0;
+        }
+    }
+    return 1;
+}
+
+/****************************************************************************/
+/****************************************************************************/
+/*****                                                                  *****/
+/*****                                                                  *****/
+/*****                                                                  *****/
+/****************************************************************************/
+/****************************************************************************/
+
+/* cache entry. for simplicity, 'hash' and 'hlink' are inlined in this
+ * structure though they are conceptually part of the hash table.
+ *
+ * similarly, mru_next and mru_prev are part of the global MRU list
+ */
+typedef struct Entry {
+    unsigned int     hash;   /* hash value */
+    struct Entry*    hlink;  /* next in collision chain */
+    struct Entry*    mru_prev;
+    struct Entry*    mru_next;
+
+    const uint8_t*   query;
+    int              querylen;
+    const uint8_t*   answer;
+    int              answerlen;
+    time_t           expires;   /* time_t when the entry isn't valid any more */
+    int              id;        /* for debugging purpose */
+} Entry;
+
+/**
+ * Find the TTL for a negative DNS result.  This is defined as the minimum
+ * of the SOA records TTL and the MINIMUM-TTL field (RFC-2308).
+ *
+ * Return 0 if not found.
+ */
+static u_long
+answer_getNegativeTTL(ns_msg handle) {
+    int n, nscount;
+    u_long result = 0;
+    ns_rr rr;
+
+    nscount = ns_msg_count(handle, ns_s_ns);
+    for (n = 0; n < nscount; n++) {
+        if ((ns_parserr(&handle, ns_s_ns, n, &rr) == 0) && (ns_rr_type(rr) == ns_t_soa)) {
+            const u_char *rdata = ns_rr_rdata(rr); // find the data
+            const u_char *edata = rdata + ns_rr_rdlen(rr); // add the len to find the end
+            int len;
+            u_long ttl, rec_result = ns_rr_ttl(rr);
+
+            // find the MINIMUM-TTL field from the blob of binary data for this record
+            // skip the server name
+            len = dn_skipname(rdata, edata);
+            if (len == -1) continue; // error skipping
+            rdata += len;
+
+            // skip the admin name
+            len = dn_skipname(rdata, edata);
+            if (len == -1) continue; // error skipping
+            rdata += len;
+
+            if (edata - rdata != 5*NS_INT32SZ) continue;
+            // skip: serial number + refresh interval + retry interval + expiry
+            rdata += NS_INT32SZ * 4;
+            // finally read the MINIMUM TTL
+            ttl = ns_get32(rdata);
+            if (ttl < rec_result) {
+                rec_result = ttl;
+            }
+            // Now that the record is read successfully, apply the new min TTL
+            if (n == 0 || rec_result < result) {
+                result = rec_result;
+            }
+        }
+    }
+    return result;
+}
+
+/**
+ * Parse the answer records and find the appropriate
+ * smallest TTL among the records.  This might be from
+ * the answer records if found or from the SOA record
+ * if it's a negative result.
+ *
+ * The returned TTL is the number of seconds to
+ * keep the answer in the cache.
+ *
+ * In case of parse error zero (0) is returned which
+ * indicates that the answer shall not be cached.
+ */
+static u_long
+answer_getTTL(const void* answer, int answerlen)
+{
+    ns_msg handle;
+    int ancount, n;
+    u_long result, ttl;
+    ns_rr rr;
+
+    result = 0;
+    if (ns_initparse(answer, answerlen, &handle) >= 0) {
+        // get number of answer records
+        ancount = ns_msg_count(handle, ns_s_an);
+
+        if (ancount == 0) {
+            // a response with no answers?  Cache this negative result.
+            result = answer_getNegativeTTL(handle);
+        } else {
+            for (n = 0; n < ancount; n++) {
+                if (ns_parserr(&handle, ns_s_an, n, &rr) == 0) {
+                    ttl = ns_rr_ttl(rr);
+                    if (n == 0 || ttl < result) {
+                        result = ttl;
+                    }
+                } else {
+                    XLOG("ns_parserr failed ancount no = %d. errno = %s\n", n, strerror(errno));
+                }
+            }
+        }
+    } else {
+        XLOG("ns_parserr failed. %s\n", strerror(errno));
+    }
+
+    XLOG("TTL = %d\n", result);
+
+    return result;
+}
+
+static void
+entry_free( Entry*  e )
+{
+    /* everything is allocated in a single memory block */
+    if (e) {
+        free(e);
+    }
+}
+
+static __inline__ void
+entry_mru_remove( Entry*  e )
+{
+    e->mru_prev->mru_next = e->mru_next;
+    e->mru_next->mru_prev = e->mru_prev;
+}
+
+static __inline__ void
+entry_mru_add( Entry*  e, Entry*  list )
+{
+    Entry*  first = list->mru_next;
+
+    e->mru_next = first;
+    e->mru_prev = list;
+
+    list->mru_next  = e;
+    first->mru_prev = e;
+}
+
+/* compute the hash of a given entry, this is a hash of most
+ * data in the query (key) */
+static unsigned
+entry_hash( const Entry*  e )
+{
+    DnsPacket  pack[1];
+
+    _dnsPacket_init(pack, e->query, e->querylen);
+    return _dnsPacket_hashQuery(pack);
+}
+
+/* initialize an Entry as a search key, this also checks the input query packet
+ * returns 1 on success, or 0 in case of unsupported/malformed data */
+static int
+entry_init_key( Entry*  e, const void*  query, int  querylen )
+{
+    DnsPacket  pack[1];
+
+    memset(e, 0, sizeof(*e));
+
+    e->query    = query;
+    e->querylen = querylen;
+    e->hash     = entry_hash(e);
+
+    _dnsPacket_init(pack, query, querylen);
+
+    return _dnsPacket_checkQuery(pack);
+}
+
+/* allocate a new entry as a cache node */
+static Entry*
+entry_alloc( const Entry*  init, const void*  answer, int  answerlen )
+{
+    Entry*  e;
+    int     size;
+
+    size = sizeof(*e) + init->querylen + answerlen;
+    e    = calloc(size, 1);
+    if (e == NULL)
+        return e;
+
+    e->hash     = init->hash;
+    e->query    = (const uint8_t*)(e+1);
+    e->querylen = init->querylen;
+
+    memcpy( (char*)e->query, init->query, e->querylen );
+
+    e->answer    = e->query + e->querylen;
+    e->answerlen = answerlen;
+
+    memcpy( (char*)e->answer, answer, e->answerlen );
+
+    return e;
+}
+
+static int
+entry_equals( const Entry*  e1, const Entry*  e2 )
+{
+    DnsPacket  pack1[1], pack2[1];
+
+    if (e1->querylen != e2->querylen) {
+        return 0;
+    }
+    _dnsPacket_init(pack1, e1->query, e1->querylen);
+    _dnsPacket_init(pack2, e2->query, e2->querylen);
+
+    return _dnsPacket_isEqualQuery(pack1, pack2);
+}
+
+/****************************************************************************/
+/****************************************************************************/
+/*****                                                                  *****/
+/*****                                                                  *****/
+/*****                                                                  *****/
+/****************************************************************************/
+/****************************************************************************/
+
+/* We use a simple hash table with external collision lists
+ * for simplicity, the hash-table fields 'hash' and 'hlink' are
+ * inlined in the Entry structure.
+ */
+
+/* Maximum time for a thread to wait for an pending request */
+#define PENDING_REQUEST_TIMEOUT 20;
+
+typedef struct pending_req_info {
+    unsigned int                hash;
+    pthread_cond_t              cond;
+    struct pending_req_info*    next;
+} PendingReqInfo;
+
+typedef struct resolv_cache {
+    int              max_entries;
+    int              num_entries;
+    Entry            mru_list;
+    int              last_id;
+    Entry*           entries;
+    PendingReqInfo   pending_requests;
+} Cache;
+
+struct resolv_cache_info {
+    unsigned                    netid;
+    Cache*                      cache;
+    struct resolv_cache_info*   next;
+    char*                       nameservers[MAXNS +1];
+    struct addrinfo*            nsaddrinfo[MAXNS + 1];
+    char                        defdname[256];
+    int                         dnsrch_offset[MAXDNSRCH+1];  // offsets into defdname
+};
+
+#define  HTABLE_VALID(x)  ((x) != NULL && (x) != HTABLE_DELETED)
+
+static pthread_once_t        _res_cache_once = PTHREAD_ONCE_INIT;
+static void _res_cache_init(void);
+
+// lock protecting everything in the _resolve_cache_info structs (next ptr, etc)
+static pthread_mutex_t _res_cache_list_lock;
+
+/* gets cache associated with a network, or NULL if none exists */
+static struct resolv_cache* _find_named_cache_locked(unsigned netid);
+
+static void
+_cache_flush_pending_requests_locked( struct resolv_cache* cache )
+{
+    struct pending_req_info *ri, *tmp;
+    if (cache) {
+        ri = cache->pending_requests.next;
+
+        while (ri) {
+            tmp = ri;
+            ri = ri->next;
+            pthread_cond_broadcast(&tmp->cond);
+
+            pthread_cond_destroy(&tmp->cond);
+            free(tmp);
+        }
+
+        cache->pending_requests.next = NULL;
+    }
+}
+
+/* Return 0 if no pending request is found matching the key.
+ * If a matching request is found the calling thread will wait until
+ * the matching request completes, then update *cache and return 1. */
+static int
+_cache_check_pending_request_locked( struct resolv_cache** cache, Entry* key, unsigned netid )
+{
+    struct pending_req_info *ri, *prev;
+    int exist = 0;
+
+    if (*cache && key) {
+        ri = (*cache)->pending_requests.next;
+        prev = &(*cache)->pending_requests;
+        while (ri) {
+            if (ri->hash == key->hash) {
+                exist = 1;
+                break;
+            }
+            prev = ri;
+            ri = ri->next;
+        }
+
+        if (!exist) {
+            ri = calloc(1, sizeof(struct pending_req_info));
+            if (ri) {
+                ri->hash = key->hash;
+                pthread_cond_init(&ri->cond, NULL);
+                prev->next = ri;
+            }
+        } else {
+            struct timespec ts = {0,0};
+            XLOG("Waiting for previous request");
+            ts.tv_sec = _time_now() + PENDING_REQUEST_TIMEOUT;
+            pthread_cond_timedwait(&ri->cond, &_res_cache_list_lock, &ts);
+            /* Must update *cache as it could have been deleted. */
+            *cache = _find_named_cache_locked(netid);
+        }
+    }
+
+    return exist;
+}
+
+/* notify any waiting thread that waiting on a request
+ * matching the key has been added to the cache */
+static void
+_cache_notify_waiting_tid_locked( struct resolv_cache* cache, Entry* key )
+{
+    struct pending_req_info *ri, *prev;
+
+    if (cache && key) {
+        ri = cache->pending_requests.next;
+        prev = &cache->pending_requests;
+        while (ri) {
+            if (ri->hash == key->hash) {
+                pthread_cond_broadcast(&ri->cond);
+                break;
+            }
+            prev = ri;
+            ri = ri->next;
+        }
+
+        // remove item from list and destroy
+        if (ri) {
+            prev->next = ri->next;
+            pthread_cond_destroy(&ri->cond);
+            free(ri);
+        }
+    }
+}
+
+/* notify the cache that the query failed */
+void
+_resolv_cache_query_failed( unsigned    netid,
+                   const void* query,
+                   int         querylen)
+{
+    Entry    key[1];
+    Cache*   cache;
+
+    if (!entry_init_key(key, query, querylen))
+        return;
+
+    pthread_mutex_lock(&_res_cache_list_lock);
+
+    cache = _find_named_cache_locked(netid);
+
+    if (cache) {
+        _cache_notify_waiting_tid_locked(cache, key);
+    }
+
+    pthread_mutex_unlock(&_res_cache_list_lock);
+}
+
+static void
+_cache_flush_locked( Cache*  cache )
+{
+    int     nn;
+
+    for (nn = 0; nn < cache->max_entries; nn++)
+    {
+        Entry**  pnode = (Entry**) &cache->entries[nn];
+
+        while (*pnode != NULL) {
+            Entry*  node = *pnode;
+            *pnode = node->hlink;
+            entry_free(node);
+        }
+    }
+
+    // flush pending request
+    _cache_flush_pending_requests_locked(cache);
+
+    cache->mru_list.mru_next = cache->mru_list.mru_prev = &cache->mru_list;
+    cache->num_entries       = 0;
+    cache->last_id           = 0;
+
+    XLOG("*************************\n"
+         "*** DNS CACHE FLUSHED ***\n"
+         "*************************");
+}
+
+static int
+_res_cache_get_max_entries( void )
+{
+    int cache_size = CONFIG_MAX_ENTRIES;
+
+    const char* cache_mode = getenv("ANDROID_DNS_MODE");
+    if (cache_mode == NULL || strcmp(cache_mode, "local") != 0) {
+        // Don't use the cache in local mode. This is used by the proxy itself.
+        cache_size = 0;
+    }
+
+    XLOG("cache size: %d", cache_size);
+    return cache_size;
+}
+
+static struct resolv_cache*
+_resolv_cache_create( void )
+{
+    struct resolv_cache*  cache;
+
+    cache = calloc(sizeof(*cache), 1);
+    if (cache) {
+        cache->max_entries = _res_cache_get_max_entries();
+        cache->entries = calloc(sizeof(*cache->entries), cache->max_entries);
+        if (cache->entries) {
+            cache->mru_list.mru_prev = cache->mru_list.mru_next = &cache->mru_list;
+            XLOG("%s: cache created\n", __FUNCTION__);
+        } else {
+            free(cache);
+            cache = NULL;
+        }
+    }
+    return cache;
+}
+
+
+#if DEBUG
+static void
+_dump_query( const uint8_t*  query, int  querylen )
+{
+    char       temp[256], *p=temp, *end=p+sizeof(temp);
+    DnsPacket  pack[1];
+
+    _dnsPacket_init(pack, query, querylen);
+    p = _dnsPacket_bprintQuery(pack, p, end);
+    XLOG("QUERY: %s", temp);
+}
+
+static void
+_cache_dump_mru( Cache*  cache )
+{
+    char    temp[512], *p=temp, *end=p+sizeof(temp);
+    Entry*  e;
+
+    p = _bprint(temp, end, "MRU LIST (%2d): ", cache->num_entries);
+    for (e = cache->mru_list.mru_next; e != &cache->mru_list; e = e->mru_next)
+        p = _bprint(p, end, " %d", e->id);
+
+    XLOG("%s", temp);
+}
+
+static void
+_dump_answer(const void* answer, int answerlen)
+{
+    res_state statep;
+    FILE* fp;
+    char* buf;
+    int fileLen;
+
+    fp = fopen("/data/reslog.txt", "w+");
+    if (fp != NULL) {
+        statep = __res_get_state();
+
+        res_pquery(statep, answer, answerlen, fp);
+
+        //Get file length
+        fseek(fp, 0, SEEK_END);
+        fileLen=ftell(fp);
+        fseek(fp, 0, SEEK_SET);
+        buf = (char *)malloc(fileLen+1);
+        if (buf != NULL) {
+            //Read file contents into buffer
+            fread(buf, fileLen, 1, fp);
+            XLOG("%s\n", buf);
+            free(buf);
+        }
+        fclose(fp);
+        remove("/data/reslog.txt");
+    }
+    else {
+        errno = 0; // else debug is introducing error signals
+        XLOG("%s: can't open file\n", __FUNCTION__);
+    }
+}
+#endif
+
+#if DEBUG
+#  define  XLOG_QUERY(q,len)   _dump_query((q), (len))
+#  define  XLOG_ANSWER(a, len) _dump_answer((a), (len))
+#else
+#  define  XLOG_QUERY(q,len)   ((void)0)
+#  define  XLOG_ANSWER(a,len)  ((void)0)
+#endif
+
+/* This function tries to find a key within the hash table
+ * In case of success, it will return a *pointer* to the hashed key.
+ * In case of failure, it will return a *pointer* to NULL
+ *
+ * So, the caller must check '*result' to check for success/failure.
+ *
+ * The main idea is that the result can later be used directly in
+ * calls to _resolv_cache_add or _resolv_cache_remove as the 'lookup'
+ * parameter. This makes the code simpler and avoids re-searching
+ * for the key position in the htable.
+ *
+ * The result of a lookup_p is only valid until you alter the hash
+ * table.
+ */
+static Entry**
+_cache_lookup_p( Cache*   cache,
+                 Entry*   key )
+{
+    int      index = key->hash % cache->max_entries;
+    Entry**  pnode = (Entry**) &cache->entries[ index ];
+
+    while (*pnode != NULL) {
+        Entry*  node = *pnode;
+
+        if (node == NULL)
+            break;
+
+        if (node->hash == key->hash && entry_equals(node, key))
+            break;
+
+        pnode = &node->hlink;
+    }
+    return pnode;
+}
+
+/* Add a new entry to the hash table. 'lookup' must be the
+ * result of an immediate previous failed _lookup_p() call
+ * (i.e. with *lookup == NULL), and 'e' is the pointer to the
+ * newly created entry
+ */
+static void
+_cache_add_p( Cache*   cache,
+              Entry**  lookup,
+              Entry*   e )
+{
+    *lookup = e;
+    e->id = ++cache->last_id;
+    entry_mru_add(e, &cache->mru_list);
+    cache->num_entries += 1;
+
+    XLOG("%s: entry %d added (count=%d)", __FUNCTION__,
+         e->id, cache->num_entries);
+}
+
+/* Remove an existing entry from the hash table,
+ * 'lookup' must be the result of an immediate previous
+ * and succesful _lookup_p() call.
+ */
+static void
+_cache_remove_p( Cache*   cache,
+                 Entry**  lookup )
+{
+    Entry*  e  = *lookup;
+
+    XLOG("%s: entry %d removed (count=%d)", __FUNCTION__,
+         e->id, cache->num_entries-1);
+
+    entry_mru_remove(e);
+    *lookup = e->hlink;
+    entry_free(e);
+    cache->num_entries -= 1;
+}
+
+/* Remove the oldest entry from the hash table.
+ */
+static void
+_cache_remove_oldest( Cache*  cache )
+{
+    Entry*   oldest = cache->mru_list.mru_prev;
+    Entry**  lookup = _cache_lookup_p(cache, oldest);
+
+    if (*lookup == NULL) { /* should not happen */
+        XLOG("%s: OLDEST NOT IN HTABLE ?", __FUNCTION__);
+        return;
+    }
+    if (DEBUG) {
+        XLOG("Cache full - removing oldest");
+        XLOG_QUERY(oldest->query, oldest->querylen);
+    }
+    _cache_remove_p(cache, lookup);
+}
+
+/* Remove all expired entries from the hash table.
+ */
+static void _cache_remove_expired(Cache* cache) {
+    Entry* e;
+    time_t now = _time_now();
+
+    for (e = cache->mru_list.mru_next; e != &cache->mru_list;) {
+        // Entry is old, remove
+        if (now >= e->expires) {
+            Entry** lookup = _cache_lookup_p(cache, e);
+            if (*lookup == NULL) { /* should not happen */
+                XLOG("%s: ENTRY NOT IN HTABLE ?", __FUNCTION__);
+                return;
+            }
+            e = e->mru_next;
+            _cache_remove_p(cache, lookup);
+        } else {
+            e = e->mru_next;
+        }
+    }
+}
+
+ResolvCacheStatus
+_resolv_cache_lookup( unsigned              netid,
+                      const void*           query,
+                      int                   querylen,
+                      void*                 answer,
+                      int                   answersize,
+                      int                  *answerlen )
+{
+    Entry      key[1];
+    Entry**    lookup;
+    Entry*     e;
+    time_t     now;
+    Cache*     cache;
+
+    ResolvCacheStatus  result = RESOLV_CACHE_NOTFOUND;
+
+    XLOG("%s: lookup", __FUNCTION__);
+    XLOG_QUERY(query, querylen);
+
+    /* we don't cache malformed queries */
+    if (!entry_init_key(key, query, querylen)) {
+        XLOG("%s: unsupported query", __FUNCTION__);
+        return RESOLV_CACHE_UNSUPPORTED;
+    }
+    /* lookup cache */
+    pthread_once(&_res_cache_once, _res_cache_init);
+    pthread_mutex_lock(&_res_cache_list_lock);
+
+    cache = _find_named_cache_locked(netid);
+    if (cache == NULL) {
+        result = RESOLV_CACHE_UNSUPPORTED;
+        goto Exit;
+    }
+
+    /* see the description of _lookup_p to understand this.
+     * the function always return a non-NULL pointer.
+     */
+    lookup = _cache_lookup_p(cache, key);
+    e      = *lookup;
+
+    if (e == NULL) {
+        XLOG( "NOT IN CACHE");
+        // calling thread will wait if an outstanding request is found
+        // that matching this query
+        if (!_cache_check_pending_request_locked(&cache, key, netid) || cache == NULL) {
+            goto Exit;
+        } else {
+            lookup = _cache_lookup_p(cache, key);
+            e = *lookup;
+            if (e == NULL) {
+                goto Exit;
+            }
+        }
+    }
+
+    now = _time_now();
+
+    /* remove stale entries here */
+    if (now >= e->expires) {
+        XLOG( " NOT IN CACHE (STALE ENTRY %p DISCARDED)", *lookup );
+        XLOG_QUERY(e->query, e->querylen);
+        _cache_remove_p(cache, lookup);
+        goto Exit;
+    }
+
+    *answerlen = e->answerlen;
+    if (e->answerlen > answersize) {
+        /* NOTE: we return UNSUPPORTED if the answer buffer is too short */
+        result = RESOLV_CACHE_UNSUPPORTED;
+        XLOG(" ANSWER TOO LONG");
+        goto Exit;
+    }
+
+    memcpy( answer, e->answer, e->answerlen );
+
+    /* bump up this entry to the top of the MRU list */
+    if (e != cache->mru_list.mru_next) {
+        entry_mru_remove( e );
+        entry_mru_add( e, &cache->mru_list );
+    }
+
+    XLOG( "FOUND IN CACHE entry=%p", e );
+    result = RESOLV_CACHE_FOUND;
+
+Exit:
+    pthread_mutex_unlock(&_res_cache_list_lock);
+    return result;
+}
+
+
+void
+_resolv_cache_add( unsigned              netid,
+                   const void*           query,
+                   int                   querylen,
+                   const void*           answer,
+                   int                   answerlen )
+{
+    Entry    key[1];
+    Entry*   e;
+    Entry**  lookup;
+    u_long   ttl;
+    Cache*   cache = NULL;
+
+    /* don't assume that the query has already been cached
+     */
+    if (!entry_init_key( key, query, querylen )) {
+        XLOG( "%s: passed invalid query ?", __FUNCTION__);
+        return;
+    }
+
+    pthread_mutex_lock(&_res_cache_list_lock);
+
+    cache = _find_named_cache_locked(netid);
+    if (cache == NULL) {
+        goto Exit;
+    }
+
+    XLOG( "%s: query:", __FUNCTION__ );
+    XLOG_QUERY(query,querylen);
+    XLOG_ANSWER(answer, answerlen);
+#if DEBUG_DATA
+    XLOG( "answer:");
+    XLOG_BYTES(answer,answerlen);
+#endif
+
+    lookup = _cache_lookup_p(cache, key);
+    e      = *lookup;
+
+    if (e != NULL) { /* should not happen */
+        XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
+             __FUNCTION__, e);
+        goto Exit;
+    }
+
+    if (cache->num_entries >= cache->max_entries) {
+        _cache_remove_expired(cache);
+        if (cache->num_entries >= cache->max_entries) {
+            _cache_remove_oldest(cache);
+        }
+        /* need to lookup again */
+        lookup = _cache_lookup_p(cache, key);
+        e      = *lookup;
+        if (e != NULL) {
+            XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
+                __FUNCTION__, e);
+            goto Exit;
+        }
+    }
+
+    ttl = answer_getTTL(answer, answerlen);
+    if (ttl > 0) {
+        e = entry_alloc(key, answer, answerlen);
+        if (e != NULL) {
+            e->expires = ttl + _time_now();
+            _cache_add_p(cache, lookup, e);
+        }
+    }
+#if DEBUG
+    _cache_dump_mru(cache);
+#endif
+Exit:
+    if (cache != NULL) {
+      _cache_notify_waiting_tid_locked(cache, key);
+    }
+    pthread_mutex_unlock(&_res_cache_list_lock);
+}
+
+/****************************************************************************/
+/****************************************************************************/
+/*****                                                                  *****/
+/*****                                                                  *****/
+/*****                                                                  *****/
+/****************************************************************************/
+/****************************************************************************/
+
+// Head of the list of caches.  Protected by _res_cache_list_lock.
+static struct resolv_cache_info _res_cache_list;
+
+/* insert resolv_cache_info into the list of resolv_cache_infos */
+static void _insert_cache_info_locked(struct resolv_cache_info* cache_info);
+/* creates a resolv_cache_info */
+static struct resolv_cache_info* _create_cache_info( void );
+/* gets a resolv_cache_info associated with a network, or NULL if not found */
+static struct resolv_cache_info* _find_cache_info_locked(unsigned netid);
+/* look up the named cache, and creates one if needed */
+static struct resolv_cache* _get_res_cache_for_net_locked(unsigned netid);
+/* empty the named cache */
+static void _flush_cache_for_net_locked(unsigned netid);
+/* empty the nameservers set for the named cache */
+static void _free_nameservers_locked(struct resolv_cache_info* cache_info);
+/* return 1 if the provided list of name servers differs from the list of name servers
+ * currently attached to the provided cache_info */
+static int _resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
+        const char** servers, int numservers);
+
+static void
+_res_cache_init(void)
+{
+    const char*  env = getenv(CONFIG_ENV);
+
+    if (env && atoi(env) == 0) {
+        /* the cache is disabled */
+        return;
+    }
+
+    memset(&_res_cache_list, 0, sizeof(_res_cache_list));
+    pthread_mutex_init(&_res_cache_list_lock, NULL);
+}
+
+static struct resolv_cache*
+_get_res_cache_for_net_locked(unsigned netid)
+{
+    struct resolv_cache* cache = _find_named_cache_locked(netid);
+    if (!cache) {
+        struct resolv_cache_info* cache_info = _create_cache_info();
+        if (cache_info) {
+            cache = _resolv_cache_create();
+            if (cache) {
+                cache_info->cache = cache;
+                cache_info->netid = netid;
+                _insert_cache_info_locked(cache_info);
+            } else {
+                free(cache_info);
+            }
+        }
+    }
+    return cache;
+}
+
+void
+_resolv_flush_cache_for_net(unsigned netid)
+{
+    pthread_once(&_res_cache_once, _res_cache_init);
+    pthread_mutex_lock(&_res_cache_list_lock);
+
+    _flush_cache_for_net_locked(netid);
+
+    pthread_mutex_unlock(&_res_cache_list_lock);
+}
+
+static void
+_flush_cache_for_net_locked(unsigned netid)
+{
+    struct resolv_cache* cache = _find_named_cache_locked(netid);
+    if (cache) {
+        _cache_flush_locked(cache);
+    }
+}
+
+void _resolv_delete_cache_for_net(unsigned netid)
+{
+    pthread_once(&_res_cache_once, _res_cache_init);
+    pthread_mutex_lock(&_res_cache_list_lock);
+
+    struct resolv_cache_info* prev_cache_info = &_res_cache_list;
+
+    while (prev_cache_info->next) {
+        struct resolv_cache_info* cache_info = prev_cache_info->next;
+
+        if (cache_info->netid == netid) {
+            prev_cache_info->next = cache_info->next;
+            _cache_flush_locked(cache_info->cache);
+            free(cache_info->cache->entries);
+            free(cache_info->cache);
+            _free_nameservers_locked(cache_info);
+            free(cache_info);
+            break;
+        }
+
+        prev_cache_info = prev_cache_info->next;
+    }
+
+    pthread_mutex_unlock(&_res_cache_list_lock);
+}
+
+static struct resolv_cache_info*
+_create_cache_info(void)
+{
+    struct resolv_cache_info* cache_info;
+
+    cache_info = calloc(sizeof(*cache_info), 1);
+    return cache_info;
+}
+
+static void
+_insert_cache_info_locked(struct resolv_cache_info* cache_info)
+{
+    struct resolv_cache_info* last;
+
+    for (last = &_res_cache_list; last->next; last = last->next);
+
+    last->next = cache_info;
+
+}
+
+static struct resolv_cache*
+_find_named_cache_locked(unsigned netid) {
+
+    struct resolv_cache_info* info = _find_cache_info_locked(netid);
+
+    if (info != NULL) return info->cache;
+
+    return NULL;
+}
+
+static struct resolv_cache_info*
+_find_cache_info_locked(unsigned netid)
+{
+    struct resolv_cache_info* cache_info = _res_cache_list.next;
+
+    while (cache_info) {
+        if (cache_info->netid == netid) {
+            break;
+        }
+
+        cache_info = cache_info->next;
+    }
+    return cache_info;
+}
+
+void
+_resolv_set_nameservers_for_net(unsigned netid, const char** servers, int numservers,
+        const char *domains)
+{
+    int i, rt, index;
+    struct addrinfo hints;
+    char sbuf[NI_MAXSERV];
+    register char *cp;
+    int *offset;
+
+    pthread_once(&_res_cache_once, _res_cache_init);
+    pthread_mutex_lock(&_res_cache_list_lock);
+
+    // creates the cache if not created
+    _get_res_cache_for_net_locked(netid);
+
+    struct resolv_cache_info* cache_info = _find_cache_info_locked(netid);
+
+    if (cache_info != NULL &&
+            !_resolv_is_nameservers_equal_locked(cache_info, servers, numservers)) {
+        // free current before adding new
+        _free_nameservers_locked(cache_info);
+
+        memset(&hints, 0, sizeof(hints));
+        hints.ai_family = PF_UNSPEC;
+        hints.ai_socktype = SOCK_DGRAM; /*dummy*/
+        hints.ai_flags = AI_NUMERICHOST;
+        sprintf(sbuf, "%u", NAMESERVER_PORT);
+
+        index = 0;
+        for (i = 0; i < numservers && i < MAXNS; i++) {
+            rt = getaddrinfo(servers[i], sbuf, &hints, &cache_info->nsaddrinfo[index]);
+            if (rt == 0) {
+                cache_info->nameservers[index] = strdup(servers[i]);
+                index++;
+                XLOG("%s: netid = %u, addr = %s\n", __FUNCTION__, netid, servers[i]);
+            } else {
+                cache_info->nsaddrinfo[index] = NULL;
+            }
+        }
+
+        // code moved from res_init.c, load_domain_search_list
+        strlcpy(cache_info->defdname, domains, sizeof(cache_info->defdname));
+        if ((cp = strchr(cache_info->defdname, '\n')) != NULL)
+            *cp = '\0';
+        cp = cache_info->defdname;
+        offset = cache_info->dnsrch_offset;
+        while (offset < cache_info->dnsrch_offset + MAXDNSRCH) {
+            while (*cp == ' ' || *cp == '\t') /* skip leading white space */
+                cp++;
+            if (*cp == '\0') /* stop if nothing more to do */
+                break;
+            *offset++ = cp - cache_info->defdname; /* record this search domain */
+            while (*cp) { /* zero-terminate it */
+                if (*cp == ' '|| *cp == '\t') {
+                    *cp++ = '\0';
+                    break;
+                }
+                cp++;
+            }
+        }
+        *offset = -1; /* cache_info->dnsrch_offset has MAXDNSRCH+1 items */
+
+        // flush cache since new settings
+        _flush_cache_for_net_locked(netid);
+
+    }
+
+    pthread_mutex_unlock(&_res_cache_list_lock);
+}
+
+static int
+_resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
+        const char** servers, int numservers)
+{
+    int i;
+    char** ns;
+    int currentservers;
+    int equal = 1;
+
+    if (numservers > MAXNS) numservers = MAXNS;
+
+    // Find out how many nameservers we had before.
+    currentservers = 0;
+    for (ns = cache_info->nameservers; *ns; ns++)
+        currentservers++;
+
+    if (currentservers != numservers)
+        return 0;
+
+    // Compare each name server against current name servers.
+    // TODO: this is incorrect if the list of current or previous nameservers
+    // contains duplicates. This does not really matter because the framework
+    // filters out duplicates, but we should probably fix it. It's also
+    // insensitive to the order of the nameservers; we should probably fix that
+    // too.
+    for (i = 0; i < numservers && equal; i++) {
+        ns = cache_info->nameservers;
+        equal = 0;
+        while(*ns) {
+            if (strcmp(*ns, servers[i]) == 0) {
+                equal = 1;
+                break;
+            }
+            ns++;
+        }
+    }
+
+    return equal;
+}
+
+static void
+_free_nameservers_locked(struct resolv_cache_info* cache_info)
+{
+    int i;
+    for (i = 0; i <= MAXNS; i++) {
+        free(cache_info->nameservers[i]);
+        cache_info->nameservers[i] = NULL;
+        if (cache_info->nsaddrinfo[i] != NULL) {
+            freeaddrinfo(cache_info->nsaddrinfo[i]);
+            cache_info->nsaddrinfo[i] = NULL;
+        }
+    }
+}
+
+void
+_resolv_populate_res_for_net(res_state statp)
+{
+    if (statp == NULL) {
+        return;
+    }
+
+    pthread_once(&_res_cache_once, _res_cache_init);
+    pthread_mutex_lock(&_res_cache_list_lock);
+
+    struct resolv_cache_info* info = _find_cache_info_locked(statp->netid);
+    if (info != NULL) {
+        int nserv;
+        struct addrinfo* ai;
+        XLOG("%s: %u\n", __FUNCTION__, statp->netid);
+        for (nserv = 0; nserv < MAXNS; nserv++) {
+            ai = info->nsaddrinfo[nserv];
+            if (ai == NULL) {
+                break;
+            }
+
+            if ((size_t) ai->ai_addrlen <= sizeof(statp->_u._ext.ext->nsaddrs[0])) {
+                if (statp->_u._ext.ext != NULL) {
+                    memcpy(&statp->_u._ext.ext->nsaddrs[nserv], ai->ai_addr, ai->ai_addrlen);
+                    statp->nsaddr_list[nserv].sin_family = AF_UNSPEC;
+                } else {
+                    if ((size_t) ai->ai_addrlen
+                            <= sizeof(statp->nsaddr_list[0])) {
+                        memcpy(&statp->nsaddr_list[nserv], ai->ai_addr,
+                                ai->ai_addrlen);
+                    } else {
+                        statp->nsaddr_list[nserv].sin_family = AF_UNSPEC;
+                    }
+                }
+            } else {
+                XLOG("%s: found too long addrlen", __FUNCTION__);
+            }
+        }
+        statp->nscount = nserv;
+        // now do search domains.  Note that we cache the offsets as this code runs alot
+        // but the setting/offset-computer only runs when set/changed
+        strlcpy(statp->defdname, info->defdname, sizeof(statp->defdname));
+        register char **pp = statp->dnsrch;
+        register int *p = info->dnsrch_offset;
+        while (pp < statp->dnsrch + MAXDNSRCH && *p != -1) {
+            *pp++ = &statp->defdname[0] + *p++;
+        }
+    }
+    pthread_mutex_unlock(&_res_cache_list_lock);
+}
diff --git a/libc/dns/resolv/res_comp.c b/libc/dns/resolv/res_comp.c
new file mode 100644
index 0000000..987b228
--- /dev/null
+++ b/libc/dns/resolv/res_comp.c
@@ -0,0 +1,266 @@
+/*	$NetBSD: res_comp.c,v 1.6 2004/05/22 23:47:09 christos Exp $	*/
+
+/*
+ * Copyright (c) 1985, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#ifdef notdef
+static const char sccsid[] = "@(#)res_comp.c	8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "Id: res_comp.c,v 1.1.2.1.4.1 2004/03/09 08:33:54 marka Exp";
+#else
+__RCSID("$NetBSD: res_comp.c,v 1.6 2004/05/22 23:47:09 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Expand compressed domain name 'src' to full domain name.
+ * 'msg' is a pointer to the begining of the message,
+ * 'eom' points to the first location after the message,
+ * 'dst' is a pointer to a buffer of size 'dstsiz' for the result.
+ * Return size of compressed name or -1 if there was an error.
+ */
+int
+dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
+	  char *dst, int dstsiz)
+{
+	int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
+
+	if (n > 0 && dst[0] == '.')
+		dst[0] = '\0';
+	return (n);
+}
+
+/*
+ * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
+ * Return the size of the compressed name or -1.
+ * 'length' is the size of the array pointed to by 'comp_dn'.
+ */
+int
+dn_comp(const char *src, u_char *dst, int dstsiz,
+	u_char **dnptrs, u_char **lastdnptr)
+{
+	return (ns_name_compress(src, dst, (size_t)dstsiz,
+				 (const u_char **)dnptrs,
+				 (const u_char **)lastdnptr));
+}
+
+/*
+ * Skip over a compressed domain name. Return the size or -1.
+ */
+int
+dn_skipname(const u_char *ptr, const u_char *eom) {
+	const u_char *saveptr = ptr;
+
+	if (ns_name_skip(&ptr, eom) == -1)
+		return (-1);
+	return (ptr - saveptr);
+}
+
+/*
+ * Verify that a domain name uses an acceptable character set.
+ */
+
+/*
+ * Note the conspicuous absence of ctype macros in these definitions.  On
+ * non-ASCII hosts, we can't depend on string literals or ctype macros to
+ * tell us anything about network-format data.  The rest of the BIND system
+ * is not careful about this, but for some reason, we're doing it right here.
+ */
+
+/* BIONIC: We also accept underscores in the middle of labels.
+ *         This extension is needed to make resolution on some VPN networks
+ *         work properly.
+ */
+
+#define PERIOD 0x2e
+#define	hyphenchar(c) ((c) == 0x2d)
+#define bslashchar(c) ((c) == 0x5c)
+#define periodchar(c) ((c) == PERIOD)
+#define asterchar(c) ((c) == 0x2a)
+#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
+		   || ((c) >= 0x61 && (c) <= 0x7a))
+#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
+#define underscorechar(c)  ((c) == 0x5f)
+
+#define borderchar(c) (alphachar(c) || digitchar(c))
+#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c))
+#define	domainchar(c) ((c) > 0x20 && (c) < 0x7f)
+
+int
+res_hnok(const char *dn) {
+	int pch = PERIOD, ch = *dn++;
+
+	while (ch != '\0') {
+		int nch = *dn++;
+
+		if (periodchar(ch)) {
+			;
+		} else if (periodchar(pch)) {
+			if (!borderchar(ch))
+				return (0);
+		} else if (periodchar(nch) || nch == '\0') {
+			if (!borderchar(ch))
+				return (0);
+		} else {
+			if (!middlechar(ch))
+				return (0);
+		}
+		pch = ch, ch = nch;
+	}
+	return (1);
+}
+
+/*
+ * hostname-like (A, MX, WKS) owners can have "*" as their first label
+ * but must otherwise be as a host name.
+ */
+int
+res_ownok(const char *dn) {
+	if (asterchar(dn[0])) {
+		if (periodchar(dn[1]))
+			return (res_hnok(dn+2));
+		if (dn[1] == '\0')
+			return (1);
+	}
+	return (res_hnok(dn));
+}
+
+/*
+ * SOA RNAMEs and RP RNAMEs can have any printable character in their first
+ * label, but the rest of the name has to look like a host name.
+ */
+int
+res_mailok(const char *dn) {
+	int ch, escaped = 0;
+
+	/* "." is a valid missing representation */
+	if (*dn == '\0')
+		return (1);
+
+	/* otherwise <label>.<hostname> */
+	while ((ch = *dn++) != '\0') {
+		if (!domainchar(ch))
+			return (0);
+		if (!escaped && periodchar(ch))
+			break;
+		if (escaped)
+			escaped = 0;
+		else if (bslashchar(ch))
+			escaped = 1;
+	}
+	if (periodchar(ch))
+		return (res_hnok(dn));
+	return (0);
+}
+
+/*
+ * This function is quite liberal, since RFC 1034's character sets are only
+ * recommendations.
+ */
+int
+res_dnok(const char *dn) {
+	int ch;
+
+	while ((ch = *dn++) != '\0')
+		if (!domainchar(ch))
+			return (0);
+	return (1);
+}
+
+#ifdef BIND_4_COMPAT
+/*
+ * This module must export the following externally-visible symbols:
+ *	___putlong
+ *	___putshort
+ *	__getlong
+ *	__getshort
+ * Note that one _ comes from C and the others come from us.
+ */
+void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
+void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
+#ifndef __ultrix__
+u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
+u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
+#endif /*__ultrix__*/
+#endif /*BIND_4_COMPAT*/
diff --git a/libc/dns/resolv/res_data.c b/libc/dns/resolv/res_data.c
new file mode 100644
index 0000000..9bc02e7
--- /dev/null
+++ b/libc/dns/resolv/res_data.c
@@ -0,0 +1,327 @@
+/*	$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $	*/
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1995-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#ifdef notdef
+static const char rcsid[] = "Id: res_data.c,v 1.1.206.2 2004/03/16 12:34:18 marka Exp";
+#else
+__RCSID("$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <netdb.h>
+#include "resolv_private.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+__LIBC_HIDDEN__
+const char * const _res_opcodes[] = {
+	"QUERY",
+	"IQUERY",
+	"CQUERYM",
+	"CQUERYU",	/* experimental */
+	"NOTIFY",	/* experimental */
+	"UPDATE",
+	"6",
+	"7",
+	"8",
+	"9",
+	"10",
+	"11",
+	"12",
+	"13",
+	"ZONEINIT",
+	"ZONEREF",
+};
+
+#ifdef BIND_UPDATE
+const char * const _res_sectioncodes[] = {
+	"ZONE",
+	"PREREQUISITES",
+	"UPDATE",
+	"ADDITIONAL",
+};
+#endif
+
+#ifndef __BIND_NOSTATIC
+extern struct __res_state _nres;
+
+/* Proto. */
+
+int  res_ourserver_p(const res_state, const struct sockaddr *);
+
+#define res_need_init()   ((_nres.options & RES_INIT) == 0U)
+
+int
+res_init(void) {
+	int rv;
+	extern int __res_vinit(res_state, int);
+#ifdef COMPAT__RES
+	/*
+	 * Compatibility with program that were accessing _res directly
+	 * to set options. We keep another struct res that is the same
+	 * size as the original res structure, and then copy fields to
+	 * it so that we achieve the same initialization
+	 */
+	extern void *__res_get_old_state(void);
+	extern void __res_put_old_state(void *);
+	res_state ores = __res_get_old_state();
+
+	if (ores->options != 0)
+		_nres.options = ores->options;
+	if (ores->retrans != 0)
+		_nres.retrans = ores->retrans;
+	if (ores->retry != 0)
+		_nres.retry = ores->retry;
+#endif
+
+	/*
+	 * These three fields used to be statically initialized.  This made
+	 * it hard to use this code in a shared library.  It is necessary,
+	 * now that we're doing dynamic initialization here, that we preserve
+	 * the old semantics: if an application modifies one of these three
+	 * fields of _res before res_init() is called, res_init() will not
+	 * alter them.  Of course, if an application is setting them to
+	 * _zero_ before calling res_init(), hoping to override what used
+	 * to be the static default, we can't detect it and unexpected results
+	 * will follow.  Zero for any of these fields would make no sense,
+	 * so one can safely assume that the applications were already getting
+	 * unexpected results.
+	 *
+	 * _nres.options is tricky since some apps were known to diddle the bits
+	 * before res_init() was first called. We can't replicate that semantic
+	 * with dynamic initialization (they may have turned bits off that are
+	 * set in RES_DEFAULT).  Our solution is to declare such applications
+	 * "broken".  They could fool us by setting RES_INIT but none do (yet).
+	 */
+	if (!_nres.retrans)
+		_nres.retrans = RES_TIMEOUT;
+	if (!_nres.retry)
+		_nres.retry = 4;
+	if (!(_nres.options & RES_INIT))
+		_nres.options = RES_DEFAULT;
+
+	/*
+	 * This one used to initialize implicitly to zero, so unless the app
+	 * has set it to something in particular, we can randomize it now.
+	 */
+	if (!_nres.id)
+		_nres.id = res_randomid();
+
+	rv = __res_vinit(&_nres, 1);
+#ifdef COMPAT__RES
+	__res_put_old_state(&_nres);
+#endif
+	return rv;
+}
+
+void
+p_query(const u_char *msg) {
+	fp_query(msg, stdout);
+}
+
+void
+fp_query(const u_char *msg, FILE *file) {
+	fp_nquery(msg, PACKETSZ, file);
+}
+
+void
+fp_nquery(const u_char *msg, int len, FILE *file) {
+	if (res_need_init() && res_init() == -1)
+		return;
+
+	res_pquery(&_nres, msg, len, file);
+}
+
+int
+res_mkquery(int op,			/* opcode of query */
+	    const char *dname,		/* domain name */
+	    int class, int type,	/* class and type of query */
+	    const u_char *data,		/* resource record data */
+	    int datalen,		/* length of data */
+	    const u_char *newrr_in,	/* new rr for modify or append */
+	    u_char *buf,		/* buffer to put query */
+	    int buflen)			/* size of buffer */
+{
+	if (res_need_init() && res_init() == -1) {
+		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
+		return (-1);
+	}
+	return (res_nmkquery(&_nres, op, dname, class, type,
+			     data, datalen,
+			     newrr_in, buf, buflen));
+}
+
+#ifdef _LIBRESOLV
+int
+res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
+	if (res_need_init() && res_init() == -1) {
+		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
+		return (-1);
+	}
+
+	return (res_nmkupdate(&_nres, rrecp_in, buf, buflen));
+}
+#endif
+
+int
+res_query(const char *name,	/* domain name */
+	  int class, int type,	/* class and type of query */
+	  u_char *answer,	/* buffer to put answer */
+	  int anslen)		/* size of answer buffer */
+{
+	if (res_need_init() && res_init() == -1) {
+		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
+		return (-1);
+	}
+	return (res_nquery(&_nres, name, class, type, answer, anslen));
+}
+
+void
+res_send_setqhook(res_send_qhook hook) {
+	_nres.qhook = hook;
+}
+
+void
+res_send_setrhook(res_send_rhook hook) {
+	_nres.rhook = hook;
+}
+
+int
+res_isourserver(const struct sockaddr_in *inp) {
+	return (res_ourserver_p(&_nres, (const struct sockaddr *)(const void *)inp));
+}
+
+int
+res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) {
+	if (res_need_init() && res_init() == -1) {
+		/* errno should have been set by res_init() in this case. */
+		return (-1);
+	}
+
+	return (res_nsend(&_nres, buf, buflen, ans, anssiz));
+}
+
+#ifdef _LIBRESOLV
+int
+res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
+	       u_char *ans, int anssiz)
+{
+	if (res_need_init() && res_init() == -1) {
+		/* errno should have been set by res_init() in this case. */
+		return (-1);
+	}
+
+	return (res_nsendsigned(&_nres, buf, buflen, key, ans, anssiz));
+}
+#endif
+
+void
+res_close(void) {
+	res_nclose(&_nres);
+}
+
+#ifdef _LIBRESOLV
+int
+res_update(ns_updrec *rrecp_in) {
+	if (res_need_init() && res_init() == -1) {
+		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
+		return (-1);
+	}
+
+	return (res_nupdate(&_nres, rrecp_in, NULL));
+}
+#endif
+
+int
+res_search(const char *name,	/* domain name */
+	   int class, int type,	/* class and type of query */
+	   u_char *answer,	/* buffer to put answer */
+	   int anslen)		/* size of answer */
+{
+	if (res_need_init() && res_init() == -1) {
+		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
+		return (-1);
+	}
+
+	return (res_nsearch(&_nres, name, class, type, answer, anslen));
+}
+
+int
+res_querydomain(const char *name,
+		const char *domain,
+		int class, int type,	/* class and type of query */
+		u_char *answer,		/* buffer to put answer */
+		int anslen)		/* size of answer */
+{
+	if (res_need_init() && res_init() == -1) {
+		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
+		return (-1);
+	}
+
+	return (res_nquerydomain(&_nres, name, domain,
+				 class, type,
+				 answer, anslen));
+}
+
+int
+res_opt(int a, u_char *b, int c, int d)
+{
+	return res_nopt(&_nres, a, b, c, d);
+}
+
+const char *
+hostalias(const char *name) {
+	return NULL;
+}
+
+#ifdef ultrix
+int
+local_hostname_length(const char *hostname) {
+	int len_host, len_domain;
+
+	if (!*_nres.defdname)
+		res_init();
+	len_host = strlen(hostname);
+	len_domain = strlen(_nres.defdname);
+	if (len_host > len_domain &&
+	    !strcasecmp(hostname + len_host - len_domain, _nres.defdname) &&
+	    hostname[len_host - len_domain - 1] == '.')
+		return (len_host - len_domain - 1);
+	return (0);
+}
+#endif /*ultrix*/
+
+#endif
diff --git a/libc/dns/resolv/res_debug.c b/libc/dns/resolv/res_debug.c
new file mode 100644
index 0000000..7a05a5f
--- /dev/null
+++ b/libc/dns/resolv/res_debug.c
@@ -0,0 +1,1233 @@
+/*	$NetBSD: res_debug.c,v 1.13 2012/06/25 22:32:45 abs Exp $	*/
+
+/*
+ * Portions Copyright (C) 2004, 2005, 2008, 2009  Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (C) 1996-2003  Internet Software Consortium.
+ *
+ * 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 ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+/*
+ * Copyright (c) 1985
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#ifdef notdef
+static const char sccsid[] = "@(#)res_debug.c	8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "Id: res_debug.c,v 1.19 2009/02/26 11:20:20 tbox Exp";
+#else
+__RCSID("$NetBSD: res_debug.c,v 1.13 2012/06/25 22:32:45 abs Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <math.h>
+#include <netdb.h>
+#include "resolv_private.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <time.h>
+
+
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) sprintf x
+#endif
+
+extern const char * const _res_opcodes[];
+extern const char * const _res_sectioncodes[];
+
+#ifndef _LIBC
+/*
+ * Print the current options.
+ */
+void
+fp_resstat(const res_state statp, FILE *file) {
+	u_long mask;
+
+	fprintf(file, ";; res options:");
+	for (mask = 1;  mask != 0U;  mask <<= 1)
+		if (statp->options & mask)
+			fprintf(file, " %s", p_option(mask));
+	putc('\n', file);
+}
+#endif
+
+static void
+do_section(const res_state statp,
+	   ns_msg *handle, ns_sect section,
+	   int pflag, FILE *file)
+{
+	int n, sflag, rrnum;
+	int buflen = 2048;
+	char *buf;
+	ns_opcode opcode;
+	ns_rr rr;
+
+	/*
+	 * Print answer records.
+	 */
+	sflag = (int)(statp->pfcode & pflag);
+	if (statp->pfcode && !sflag)
+		return;
+
+	buf = malloc((size_t)buflen);
+	if (buf == NULL) {
+		fprintf(file, ";; memory allocation failure\n");
+		return;
+	}
+
+	opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode);
+	rrnum = 0;
+	for (;;) {
+		if (ns_parserr(handle, section, rrnum, &rr)) {
+			if (errno != ENODEV)
+				fprintf(file, ";; ns_parserr: %s\n",
+					strerror(errno));
+			else if (rrnum > 0 && sflag != 0 &&
+				 (statp->pfcode & RES_PRF_HEAD1))
+				putc('\n', file);
+			goto cleanup;
+		}
+		if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
+			fprintf(file, ";; %s SECTION:\n",
+				p_section(section, opcode));
+		if (section == ns_s_qd)
+			fprintf(file, ";;\t%s, type = %s, class = %s\n",
+				ns_rr_name(rr),
+				p_type(ns_rr_type(rr)),
+				p_class(ns_rr_class(rr)));
+		else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
+			size_t rdatalen, ttl;
+			uint16_t optcode, optlen;
+
+			rdatalen = ns_rr_rdlen(rr);
+			ttl = ns_rr_ttl(rr);
+			fprintf(file,
+				"; EDNS: version: %zu, udp=%u, flags=%04zx\n",
+				(ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff);
+			while (rdatalen >= 4) {
+				const u_char *cp = ns_rr_rdata(rr);
+				int i;
+
+				GETSHORT(optcode, cp);
+				GETSHORT(optlen, cp);
+
+				if (optcode == NS_OPT_NSID) {
+					fputs("; NSID: ", file);
+					if (optlen == 0) {
+						fputs("; NSID\n", file);
+					} else {
+						fputs("; NSID: ", file);
+						for (i = 0; i < optlen; i++)
+							fprintf(file, "%02x ",
+								cp[i]);
+						fputs(" (",file);
+						for (i = 0; i < optlen; i++)
+							fprintf(file, "%c",
+								isprint(cp[i])?
+								cp[i] : '.');
+						fputs(")\n", file);
+					}
+				} else {
+					if (optlen == 0) {
+						fprintf(file, "; OPT=%u\n",
+							optcode);
+					} else {
+						fprintf(file, "; OPT=%u: ",
+							optcode);
+						for (i = 0; i < optlen; i++)
+							fprintf(file, "%02x ",
+								cp[i]);
+						fputs(" (",file);
+						for (i = 0; i < optlen; i++)
+							fprintf(file, "%c",
+								isprint(cp[i]) ?
+									cp[i] : '.');
+						fputs(")\n", file);
+					}
+				}
+				rdatalen -= 4 + optlen;
+			}
+		} else {
+			n = ns_sprintrr(handle, &rr, NULL, NULL,
+					buf, (u_int)buflen);
+			if (n < 0) {
+				if (errno == ENOSPC) {
+					free(buf);
+					buf = NULL;
+					if (buflen < 131072)
+						buf = malloc((size_t)(buflen += 1024));
+					if (buf == NULL) {
+						fprintf(file,
+				              ";; memory allocation failure\n");
+					      return;
+					}
+					continue;
+				}
+				fprintf(file, ";; ns_sprintrr: %s\n",
+					strerror(errno));
+				goto cleanup;
+			}
+			fputs(buf, file);
+			fputc('\n', file);
+		}
+		rrnum++;
+	}
+ cleanup:
+	if (buf != NULL)
+		free(buf);
+}
+
+/*
+ * Print the contents of a query.
+ * This is intended to be primarily a debugging routine.
+ */
+void
+res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
+	ns_msg handle;
+	int qdcount, ancount, nscount, arcount;
+	u_int opcode, rcode, id;
+
+	if (ns_initparse(msg, len, &handle) < 0) {
+		fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
+		return;
+	}
+	opcode = ns_msg_getflag(handle, ns_f_opcode);
+	rcode = ns_msg_getflag(handle, ns_f_rcode);
+	id = ns_msg_id(handle);
+	qdcount = ns_msg_count(handle, ns_s_qd);
+	ancount = ns_msg_count(handle, ns_s_an);
+	nscount = ns_msg_count(handle, ns_s_ns);
+	arcount = ns_msg_count(handle, ns_s_ar);
+
+	/*
+	 * Print header fields.
+	 */
+	if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
+		fprintf(file,
+			";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
+			_res_opcodes[opcode], p_rcode((int)rcode), id);
+	if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX))
+		putc(';', file);
+	if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) {
+		fprintf(file, "; flags:");
+		if (ns_msg_getflag(handle, ns_f_qr))
+			fprintf(file, " qr");
+		if (ns_msg_getflag(handle, ns_f_aa))
+			fprintf(file, " aa");
+		if (ns_msg_getflag(handle, ns_f_tc))
+			fprintf(file, " tc");
+		if (ns_msg_getflag(handle, ns_f_rd))
+			fprintf(file, " rd");
+		if (ns_msg_getflag(handle, ns_f_ra))
+			fprintf(file, " ra");
+		if (ns_msg_getflag(handle, ns_f_z))
+			fprintf(file, " ??");
+		if (ns_msg_getflag(handle, ns_f_ad))
+			fprintf(file, " ad");
+		if (ns_msg_getflag(handle, ns_f_cd))
+			fprintf(file, " cd");
+	}
+	if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) {
+		fprintf(file, "; %s: %d",
+			p_section(ns_s_qd, (int)opcode), qdcount);
+		fprintf(file, ", %s: %d",
+			p_section(ns_s_an, (int)opcode), ancount);
+		fprintf(file, ", %s: %d",
+			p_section(ns_s_ns, (int)opcode), nscount);
+		fprintf(file, ", %s: %d",
+			p_section(ns_s_ar, (int)opcode), arcount);
+	}
+	if ((!statp->pfcode) || (statp->pfcode &
+		(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
+		putc('\n',file);
+	}
+	/*
+	 * Print the various sections.
+	 */
+	do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file);
+	do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file);
+	do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file);
+	do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file);
+	if (qdcount == 0 && ancount == 0 &&
+	    nscount == 0 && arcount == 0)
+		putc('\n', file);
+}
+
+const u_char *
+p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
+	char name[MAXDNAME];
+	int n;
+
+	if ((n = dn_expand(msg, msg + len, cp, name, (int)sizeof name)) < 0)
+		return (NULL);
+	if (name[0] == '\0')
+		putc('.', file);
+	else
+		fputs(name, file);
+	return (cp + n);
+}
+
+const u_char *
+p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
+	return (p_cdnname(cp, msg, PACKETSZ, file));
+}
+
+/* Return a fully-qualified domain name from a compressed name (with
+   length supplied).  */
+
+const u_char *
+p_fqnname(const u_char *cp, const u_char *msg, int msglen, char *name,
+    int namelen)
+{
+	int n;
+	size_t newlen;
+
+	if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
+		return (NULL);
+	newlen = strlen(name);
+	if (newlen == 0 || name[newlen - 1] != '.') {
+		if ((int)newlen + 1 >= namelen)	/* Lack space for final dot */
+			return (NULL);
+		else
+			strcpy(name + newlen, ".");
+	}
+	return (cp + n);
+}
+
+/* XXX:	the rest of these functions need to become length-limited, too. */
+
+const u_char *
+p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
+	char name[MAXDNAME];
+	const u_char *n;
+
+	n = p_fqnname(cp, msg, MAXCDNAME, name, (int)sizeof name);
+	if (n == NULL)
+		return (NULL);
+	fputs(name, file);
+	return (n);
+}
+
+/*
+ * Names of RR classes and qclasses.  Classes and qclasses are the same, except
+ * that C_ANY is a qclass but not a class.  (You can ask for records of class
+ * C_ANY, but you can't have any records of that class in the database.)
+ */
+const struct res_sym __p_class_syms[] = {
+	{C_IN,		"IN",		(char *)0},
+	{C_CHAOS,	"CH",		(char *)0},
+	{C_CHAOS,	"CHAOS",	(char *)0},
+	{C_HS,		"HS",		(char *)0},
+	{C_HS,		"HESIOD",	(char *)0},
+	{C_ANY,		"ANY",		(char *)0},
+	{C_NONE,	"NONE",		(char *)0},
+	{C_IN, 		(char *)0,	(char *)0}
+};
+
+/*
+ * Names of message sections.
+ */
+static const struct res_sym __p_default_section_syms[] = {
+	{ns_s_qd,	"QUERY",	(char *)0},
+	{ns_s_an,	"ANSWER",	(char *)0},
+	{ns_s_ns,	"AUTHORITY",	(char *)0},
+	{ns_s_ar,	"ADDITIONAL",	(char *)0},
+	{0,             (char *)0,	(char *)0}
+};
+
+static const struct res_sym __p_update_section_syms[] = {
+	{S_ZONE,	"ZONE",		(char *)0},
+	{S_PREREQ,	"PREREQUISITE",	(char *)0},
+	{S_UPDATE,	"UPDATE",	(char *)0},
+	{S_ADDT,	"ADDITIONAL",	(char *)0},
+	{0,             (char *)0,	(char *)0}
+};
+
+const struct res_sym __p_key_syms[] = {
+	{NS_ALG_MD5RSA,		"RSA",		"RSA KEY with MD5 hash"},
+	{NS_ALG_DH,		"DH",		"Diffie Hellman"},
+	{NS_ALG_DSA,		"DSA",		"Digital Signature Algorithm"},
+	{NS_ALG_EXPIRE_ONLY,	"EXPIREONLY",	"No algorithm"},
+	{NS_ALG_PRIVATE_OID,	"PRIVATE",	"Algorithm obtained from OID"},
+	{0,			NULL,		NULL}
+};
+
+const struct res_sym __p_cert_syms[] = {
+	{cert_t_pkix,	"PKIX",		"PKIX (X.509v3) Certificate"},
+	{cert_t_spki,	"SPKI",		"SPKI certificate"},
+	{cert_t_pgp,	"PGP",		"PGP certificate"},
+	{cert_t_url,	"URL",		"URL Private"},
+	{cert_t_oid,	"OID",		"OID Private"},
+	{0,		NULL,		NULL}
+};
+
+/*
+ * Names of RR types and qtypes.  Types and qtypes are the same, except
+ * that T_ANY is a qtype but not a type.  (You can ask for records of type
+ * T_ANY, but you can't have any records of that type in the database.)
+ */
+const struct res_sym __p_type_syms[] = {
+	{ns_t_a,	"A",		"address"},
+	{ns_t_ns,	"NS",		"name server"},
+	{ns_t_md,	"MD",		"mail destination (deprecated)"},
+	{ns_t_mf,	"MF",		"mail forwarder (deprecated)"},
+	{ns_t_cname,	"CNAME",	"canonical name"},
+	{ns_t_soa,	"SOA",		"start of authority"},
+	{ns_t_mb,	"MB",		"mailbox"},
+	{ns_t_mg,	"MG",		"mail group member"},
+	{ns_t_mr,	"MR",		"mail rename"},
+	{ns_t_null,	"NULL",		"null"},
+	{ns_t_wks,	"WKS",		"well-known service (deprecated)"},
+	{ns_t_ptr,	"PTR",		"domain name pointer"},
+	{ns_t_hinfo,	"HINFO",	"host information"},
+	{ns_t_minfo,	"MINFO",	"mailbox information"},
+	{ns_t_mx,	"MX",		"mail exchanger"},
+	{ns_t_txt,	"TXT",		"text"},
+	{ns_t_rp,	"RP",		"responsible person"},
+	{ns_t_afsdb,	"AFSDB",	"DCE or AFS server"},
+	{ns_t_x25,	"X25",		"X25 address"},
+	{ns_t_isdn,	"ISDN",		"ISDN address"},
+	{ns_t_rt,	"RT",		"router"},
+	{ns_t_nsap,	"NSAP",		"nsap address"},
+	{ns_t_nsap_ptr,	"NSAP_PTR",	"domain name pointer"},
+	{ns_t_sig,	"SIG",		"signature"},
+	{ns_t_key,	"KEY",		"key"},
+	{ns_t_px,	"PX",		"mapping information"},
+	{ns_t_gpos,	"GPOS",		"geographical position (withdrawn)"},
+	{ns_t_aaaa,	"AAAA",		"IPv6 address"},
+	{ns_t_loc,	"LOC",		"location"},
+	{ns_t_nxt,	"NXT",		"next valid name (unimplemented)"},
+	{ns_t_eid,	"EID",		"endpoint identifier (unimplemented)"},
+	{ns_t_nimloc,	"NIMLOC",	"NIMROD locator (unimplemented)"},
+	{ns_t_srv,	"SRV",		"server selection"},
+	{ns_t_atma,	"ATMA",		"ATM address (unimplemented)"},
+	{ns_t_naptr,	"NAPTR",	"naptr"},
+	{ns_t_kx,	"KX",		"key exchange"},
+	{ns_t_cert,	"CERT",		"certificate"},
+	{ns_t_a6,	"A",		"IPv6 address (experminental)"},
+	{ns_t_dname,	"DNAME",	"non-terminal redirection"},
+	{ns_t_opt,	"OPT",		"opt"},
+	{ns_t_apl,	"apl",		"apl"},
+	{ns_t_ds,	"DS",		"delegation signer"},
+	{ns_t_sshfp,	"SSFP",		"SSH fingerprint"},
+	{ns_t_ipseckey,	"IPSECKEY",	"IPSEC key"},
+	{ns_t_rrsig,	"RRSIG",	"rrsig"},
+	{ns_t_nsec,	"NSEC",		"nsec"},
+	{ns_t_dnskey,	"DNSKEY",	"DNS key"},
+	{ns_t_dhcid,	"DHCID",       "dynamic host configuration identifier"},
+	{ns_t_nsec3,	"NSEC3",	"nsec3"},
+	{ns_t_nsec3param, "NSEC3PARAM", "NSEC3 parameters"},
+	{ns_t_hip,	"HIP",		"host identity protocol"},
+	{ns_t_spf,	"SPF",		"sender policy framework"},
+	{ns_t_tkey,	"TKEY",		"tkey"},
+	{ns_t_tsig,	"TSIG",		"transaction signature"},
+	{ns_t_ixfr,	"IXFR",		"incremental zone transfer"},
+	{ns_t_axfr,	"AXFR",		"zone transfer"},
+	{ns_t_zxfr,	"ZXFR",		"compressed zone transfer"},
+	{ns_t_mailb,	"MAILB",	"mailbox-related data (deprecated)"},
+	{ns_t_maila,	"MAILA",	"mail agent (deprecated)"},
+	{ns_t_naptr,	"NAPTR",	"URN Naming Authority"},
+	{ns_t_kx,	"KX",		"Key Exchange"},
+	{ns_t_cert,	"CERT",		"Certificate"},
+	{ns_t_a6,	"A6",		"IPv6 Address"},
+	{ns_t_dname,	"DNAME",	"dname"},
+	{ns_t_sink,	"SINK",		"Kitchen Sink (experimental)"},
+	{ns_t_opt,	"OPT",		"EDNS Options"},
+	{ns_t_any,	"ANY",		"\"any\""},
+	{ns_t_dlv,	"DLV",		"DNSSEC look-aside validation"},
+	{0, 		NULL,		NULL}
+};
+
+/*
+ * Names of DNS rcodes.
+ */
+const struct res_sym __p_rcode_syms[] = {
+	{ns_r_noerror,	"NOERROR",		"no error"},
+	{ns_r_formerr,	"FORMERR",		"format error"},
+	{ns_r_servfail,	"SERVFAIL",		"server failed"},
+	{ns_r_nxdomain,	"NXDOMAIN",		"no such domain name"},
+	{ns_r_notimpl,	"NOTIMP",		"not implemented"},
+	{ns_r_refused,	"REFUSED",		"refused"},
+	{ns_r_yxdomain,	"YXDOMAIN",		"domain name exists"},
+	{ns_r_yxrrset,	"YXRRSET",		"rrset exists"},
+	{ns_r_nxrrset,	"NXRRSET",		"rrset doesn't exist"},
+	{ns_r_notauth,	"NOTAUTH",		"not authoritative"},
+	{ns_r_notzone,	"NOTZONE",		"Not in zone"},
+	{ns_r_max,	"",			""},
+	{ns_r_badsig,	"BADSIG",		"bad signature"},
+	{ns_r_badkey,	"BADKEY",		"bad key"},
+	{ns_r_badtime,	"BADTIME",		"bad time"},
+	{0, 		NULL,			NULL}
+};
+
+int
+sym_ston(const struct res_sym *syms, const char *name, int *success) {
+	for (; syms->name != 0; syms++) {
+		if (strcasecmp (name, syms->name) == 0) {
+			if (success)
+				*success = 1;
+			return (syms->number);
+		}
+	}
+	if (success)
+		*success = 0;
+	return (syms->number);		/* The default value. */
+}
+
+const char *
+sym_ntos(const struct res_sym *syms, int number, int *success) {
+	static char unname[20];
+
+	for (; syms->name != 0; syms++) {
+		if (number == syms->number) {
+			if (success)
+				*success = 1;
+			return (syms->name);
+		}
+	}
+
+	sprintf(unname, "%d", number);		/* XXX nonreentrant */
+	if (success)
+		*success = 0;
+	return (unname);
+}
+
+const char *
+sym_ntop(const struct res_sym *syms, int number, int *success) {
+	static char unname[20];
+
+	for (; syms->name != 0; syms++) {
+		if (number == syms->number) {
+			if (success)
+				*success = 1;
+			return (syms->humanname);
+		}
+	}
+	sprintf(unname, "%d", number);		/* XXX nonreentrant */
+	if (success)
+		*success = 0;
+	return (unname);
+}
+
+/*
+ * Return a string for the type.
+ */
+const char *
+p_type(int type) {
+	int success;
+	const char *result;
+	static char typebuf[20];
+
+	result = sym_ntos(__p_type_syms, type, &success);
+	if (success)
+		return (result);
+	if (type < 0 || type > 0xffff)
+		return ("BADTYPE");
+	sprintf(typebuf, "TYPE%d", type);
+	return (typebuf);
+}
+
+/*
+ * Return a string for the type.
+ */
+const char *
+p_section(int section, int opcode) {
+	const struct res_sym *symbols;
+
+	switch (opcode) {
+	case ns_o_update:
+		symbols = __p_update_section_syms;
+		break;
+	default:
+		symbols = __p_default_section_syms;
+		break;
+	}
+	return (sym_ntos(symbols, section, (int *)0));
+}
+
+/*
+ * Return a mnemonic for class.
+ */
+const char *
+p_class(int class) {
+	int success;
+	const char *result;
+	static char classbuf[20];
+
+	result = sym_ntos(__p_class_syms, class, &success);
+	if (success)
+		return (result);
+	if (class < 0 || class > 0xffff)
+		return ("BADCLASS");
+	sprintf(classbuf, "CLASS%d", class);
+	return (classbuf);
+}
+
+/*
+ * Return a mnemonic for an option
+ */
+const char *
+p_option(u_long option) {
+	static char nbuf[40];
+
+	switch (option) {
+	case RES_INIT:		return "init";
+	case RES_DEBUG:		return "debug";
+	case RES_AAONLY:	return "aaonly(unimpl)";
+	case RES_USEVC:		return "usevc";
+	case RES_PRIMARY:	return "primry(unimpl)";
+	case RES_IGNTC:		return "igntc";
+	case RES_RECURSE:	return "recurs";
+	case RES_DEFNAMES:	return "defnam";
+	case RES_STAYOPEN:	return "styopn";
+	case RES_DNSRCH:	return "dnsrch";
+	case RES_INSECURE1:	return "insecure1";
+	case RES_INSECURE2:	return "insecure2";
+	case RES_NOALIASES:	return "noaliases";
+	case RES_USE_INET6:	return "inet6";
+#ifdef RES_USE_EDNS0	/* KAME extension */
+	case RES_USE_EDNS0:	return "edns0";
+#endif
+#ifdef RES_USE_DNAME
+	case RES_USE_DNAME:	return "dname";
+#endif
+#ifdef RES_USE_DNSSEC
+	case RES_USE_DNSSEC:	return "dnssec";
+#endif
+#ifdef RES_NOTLDQUERY
+	case RES_NOTLDQUERY:	return "no-tld-query";
+#endif
+#ifdef RES_NO_NIBBLE2
+	case RES_NO_NIBBLE2:	return "no-nibble2";
+#endif
+				/* XXX nonreentrant */
+	default:		sprintf(nbuf, "?0x%lx?", (u_long)option);
+				return (nbuf);
+	}
+}
+
+/*
+ * Return a mnemonic for a time to live.
+ */
+const char *
+p_time(u_int32_t value) {
+	static char nbuf[40];		/* XXX nonreentrant */
+
+	if (ns_format_ttl((u_long)value, nbuf, sizeof nbuf) < 0)
+		sprintf(nbuf, "%u", value);
+	return (nbuf);
+}
+
+/*
+ * Return a string for the rcode.
+ */
+const char *
+p_rcode(int rcode) {
+	return (sym_ntos(__p_rcode_syms, rcode, (int *)0));
+}
+
+/*
+ * Return a string for a res_sockaddr_union.
+ */
+const char *
+p_sockun(union res_sockaddr_union u, char *buf, size_t size) {
+	char ret[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:123.123.123.123"];
+
+	switch (u.sin.sin_family) {
+	case AF_INET:
+		inet_ntop(AF_INET, &u.sin.sin_addr, ret, (socklen_t)sizeof ret);
+		break;
+#ifdef HAS_INET6_STRUCTS
+	case AF_INET6:
+		inet_ntop(AF_INET6, &u.sin6.sin6_addr, ret, sizeof ret);
+		break;
+#endif
+	default:
+		sprintf(ret, "[af%d]", u.sin.sin_family);
+		break;
+	}
+	if (size > 0U) {
+		strncpy(buf, ret, size - 1);
+		buf[size - 1] = '0';
+	}
+	return (buf);
+}
+
+/*
+ * routines to convert between on-the-wire RR format and zone file format.
+ * Does not contain conversion to/from decimal degrees; divide or multiply
+ * by 60*60*1000 for that.
+ */
+
+static const unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
+				      1000000,10000000,100000000,1000000000};
+
+/* takes an XeY precision/size value, returns a string representation. */
+static const char *
+precsize_ntoa(u_int32_t prec)
+{
+	static char retbuf[sizeof "90000000.00"];	/* XXX nonreentrant */
+	unsigned long val;
+	int mantissa, exponent;
+
+	mantissa = (int)((prec >> 4) & 0x0f) % 10;
+	exponent = (int)((prec >> 0) & 0x0f) % 10;
+
+	val = mantissa * poweroften[exponent];
+
+	(void) sprintf(retbuf, "%lu.%.2lu", val/100, val%100);
+	return (retbuf);
+}
+
+/* converts ascii size/precision X * 10**Y(cm) to 0xXY.  moves pointer. */
+static u_int8_t
+precsize_aton(const char **strptr) {
+	unsigned int mval = 0, cmval = 0;
+	u_int8_t retval = 0;
+	const char *cp;
+	int exponent;
+	int mantissa;
+
+	cp = *strptr;
+
+	while (isdigit((unsigned char)*cp))
+		mval = mval * 10 + (*cp++ - '0');
+
+	if (*cp == '.') {		/* centimeters */
+		cp++;
+		if (isdigit((unsigned char)*cp)) {
+			cmval = (*cp++ - '0') * 10;
+			if (isdigit((unsigned char)*cp)) {
+				cmval += (*cp++ - '0');
+			}
+		}
+	}
+	cmval = (mval * 100) + cmval;
+
+	for (exponent = 0; exponent < 9; exponent++)
+		if (cmval < poweroften[exponent+1])
+			break;
+
+	mantissa = cmval / poweroften[exponent];
+	if (mantissa > 9)
+		mantissa = 9;
+
+	retval = (mantissa << 4) | exponent;
+
+	*strptr = cp;
+
+	return (retval);
+}
+
+/* converts ascii lat/lon to unsigned encoded 32-bit number.  moves pointer. */
+static u_int32_t
+latlon2ul(const char **latlonstrptr, int *which) {
+	const char *cp;
+	u_int32_t retval;
+	int deg = 0, min = 0, secs = 0, secsfrac = 0;
+
+	cp = *latlonstrptr;
+
+	while (isdigit((unsigned char)*cp))
+		deg = deg * 10 + (*cp++ - '0');
+
+	while (isspace((unsigned char)*cp))
+		cp++;
+
+	if (!(isdigit((unsigned char)*cp)))
+		goto fndhemi;
+
+	while (isdigit((unsigned char)*cp))
+		min = min * 10 + (*cp++ - '0');
+
+	while (isspace((unsigned char)*cp))
+		cp++;
+
+	if (!(isdigit((unsigned char)*cp)))
+		goto fndhemi;
+
+	while (isdigit((unsigned char)*cp))
+		secs = secs * 10 + (*cp++ - '0');
+
+	if (*cp == '.') {		/* decimal seconds */
+		cp++;
+		if (isdigit((unsigned char)*cp)) {
+			secsfrac = (*cp++ - '0') * 100;
+			if (isdigit((unsigned char)*cp)) {
+				secsfrac += (*cp++ - '0') * 10;
+				if (isdigit((unsigned char)*cp)) {
+					secsfrac += (*cp++ - '0');
+				}
+			}
+		}
+	}
+
+	while (!isspace((unsigned char)*cp))	/* if any trailing garbage */
+		cp++;
+
+	while (isspace((unsigned char)*cp))
+		cp++;
+
+ fndhemi:
+	switch (*cp) {
+	case 'N': case 'n':
+	case 'E': case 'e':
+		retval = ((unsigned)1<<31)
+			+ (((((deg * 60) + min) * 60) + secs) * 1000)
+			+ secsfrac;
+		break;
+	case 'S': case 's':
+	case 'W': case 'w':
+		retval = ((unsigned)1<<31)
+			- (((((deg * 60) + min) * 60) + secs) * 1000)
+			- secsfrac;
+		break;
+	default:
+		retval = 0;	/* invalid value -- indicates error */
+		break;
+	}
+
+	switch (*cp) {
+	case 'N': case 'n':
+	case 'S': case 's':
+		*which = 1;	/* latitude */
+		break;
+	case 'E': case 'e':
+	case 'W': case 'w':
+		*which = 2;	/* longitude */
+		break;
+	default:
+		*which = 0;	/* error */
+		break;
+	}
+
+	cp++;			/* skip the hemisphere */
+
+	while (!isspace((unsigned char)*cp))	/* if any trailing garbage */
+		cp++;
+
+	while (isspace((unsigned char)*cp))	/* move to next field */
+		cp++;
+
+	*latlonstrptr = cp;
+
+	return (retval);
+}
+
+/* converts a zone file representation in a string to an RDATA on-the-wire
+ * representation. */
+int
+loc_aton(const char *ascii, u_char *binary)
+{
+	const char *cp, *maxcp;
+	u_char *bcp;
+
+	u_int32_t latit = 0, longit = 0, alt = 0;
+	u_int32_t lltemp1 = 0, lltemp2 = 0;
+	int altmeters = 0, altfrac = 0, altsign = 1;
+	u_int8_t hp = 0x16;	/* default = 1e6 cm = 10000.00m = 10km */
+	u_int8_t vp = 0x13;	/* default = 1e3 cm = 10.00m */
+	u_int8_t siz = 0x12;	/* default = 1e2 cm = 1.00m */
+	int which1 = 0, which2 = 0;
+
+	cp = ascii;
+	maxcp = cp + strlen(ascii);
+
+	lltemp1 = latlon2ul(&cp, &which1);
+
+	lltemp2 = latlon2ul(&cp, &which2);
+
+	switch (which1 + which2) {
+	case 3:			/* 1 + 2, the only valid combination */
+		if ((which1 == 1) && (which2 == 2)) { /* normal case */
+			latit = lltemp1;
+			longit = lltemp2;
+		} else if ((which1 == 2) && (which2 == 1)) { /* reversed */
+			longit = lltemp1;
+			latit = lltemp2;
+		} else {	/* some kind of brokenness */
+			return (0);
+		}
+		break;
+	default:		/* we didn't get one of each */
+		return (0);
+	}
+
+	/* altitude */
+	if (*cp == '-') {
+		altsign = -1;
+		cp++;
+	}
+
+	if (*cp == '+')
+		cp++;
+
+	while (isdigit((unsigned char)*cp))
+		altmeters = altmeters * 10 + (*cp++ - '0');
+
+	if (*cp == '.') {		/* decimal meters */
+		cp++;
+		if (isdigit((unsigned char)*cp)) {
+			altfrac = (*cp++ - '0') * 10;
+			if (isdigit((unsigned char)*cp)) {
+				altfrac += (*cp++ - '0');
+			}
+		}
+	}
+
+	alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
+
+	while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+		cp++;
+
+	while (isspace((unsigned char)*cp) && (cp < maxcp))
+		cp++;
+
+	if (cp >= maxcp)
+		goto defaults;
+
+	siz = precsize_aton(&cp);
+
+	while (!isspace((unsigned char)*cp) && (cp < maxcp))	/* if trailing garbage or m */
+		cp++;
+
+	while (isspace((unsigned char)*cp) && (cp < maxcp))
+		cp++;
+
+	if (cp >= maxcp)
+		goto defaults;
+
+	hp = precsize_aton(&cp);
+
+	while (!isspace((unsigned char)*cp) && (cp < maxcp))	/* if trailing garbage or m */
+		cp++;
+
+	while (isspace((unsigned char)*cp) && (cp < maxcp))
+		cp++;
+
+	if (cp >= maxcp)
+		goto defaults;
+
+	vp = precsize_aton(&cp);
+
+ defaults:
+
+	bcp = binary;
+	*bcp++ = (u_int8_t) 0;	/* version byte */
+	*bcp++ = siz;
+	*bcp++ = hp;
+	*bcp++ = vp;
+	PUTLONG(latit,bcp);
+	PUTLONG(longit,bcp);
+	PUTLONG(alt,bcp);
+
+	return (16);		/* size of RR in octets */
+}
+
+/* takes an on-the-wire LOC RR and formats it in a human readable format. */
+const char *
+loc_ntoa(const u_char *binary, char *ascii)
+{
+	static const char *error = "?";
+	static char tmpbuf[sizeof
+"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
+	const u_char *cp = binary;
+
+	int latdeg, latmin, latsec, latsecfrac;
+	int longdeg, longmin, longsec, longsecfrac;
+	char northsouth, eastwest;
+	const char *altsign;
+	int altmeters, altfrac;
+
+	const u_int32_t referencealt = 100000 * 100;
+
+	int32_t latval, longval, altval;
+	u_int32_t templ;
+	u_int8_t sizeval, hpval, vpval, versionval;
+
+	char *sizestr, *hpstr, *vpstr;
+
+	versionval = *cp++;
+
+	if (ascii == NULL)
+		ascii = tmpbuf;
+
+	if (versionval) {
+		(void) sprintf(ascii, "; error: unknown LOC RR version");
+		return (ascii);
+	}
+
+	sizeval = *cp++;
+
+	hpval = *cp++;
+	vpval = *cp++;
+
+	GETLONG(templ, cp);
+	latval = (templ - ((unsigned)1<<31));
+
+	GETLONG(templ, cp);
+	longval = (templ - ((unsigned)1<<31));
+
+	GETLONG(templ, cp);
+	if (templ < referencealt) { /* below WGS 84 spheroid */
+		altval = referencealt - templ;
+		altsign = "-";
+	} else {
+		altval = templ - referencealt;
+		altsign = "";
+	}
+
+	if (latval < 0) {
+		northsouth = 'S';
+		latval = -latval;
+	} else
+		northsouth = 'N';
+
+	latsecfrac = latval % 1000;
+	latval = latval / 1000;
+	latsec = latval % 60;
+	latval = latval / 60;
+	latmin = latval % 60;
+	latval = latval / 60;
+	latdeg = latval;
+
+	if (longval < 0) {
+		eastwest = 'W';
+		longval = -longval;
+	} else
+		eastwest = 'E';
+
+	longsecfrac = longval % 1000;
+	longval = longval / 1000;
+	longsec = longval % 60;
+	longval = longval / 60;
+	longmin = longval % 60;
+	longval = longval / 60;
+	longdeg = longval;
+
+	altfrac = altval % 100;
+	altmeters = (altval / 100);
+
+	sizestr = strdup(precsize_ntoa((u_int32_t)sizeval));
+	hpstr = strdup(precsize_ntoa((u_int32_t)hpval));
+	vpstr = strdup(precsize_ntoa((u_int32_t)vpval));
+
+	sprintf(ascii,
+	    "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %s%d.%.2dm %sm %sm %sm",
+		latdeg, latmin, latsec, latsecfrac, northsouth,
+		longdeg, longmin, longsec, longsecfrac, eastwest,
+		altsign, altmeters, altfrac,
+		(sizestr != NULL) ? sizestr : error,
+		(hpstr != NULL) ? hpstr : error,
+		(vpstr != NULL) ? vpstr : error);
+
+	if (sizestr != NULL)
+		free(sizestr);
+	if (hpstr != NULL)
+		free(hpstr);
+	if (vpstr != NULL)
+		free(vpstr);
+
+	return (ascii);
+}
+
+
+/* Return the number of DNS hierarchy levels in the name. */
+int
+dn_count_labels(const char *name) {
+	size_t len, i, count;
+
+	len = strlen(name);
+	for (i = 0, count = 0; i < len; i++) {
+		/* XXX need to check for \. or use named's nlabels(). */
+		if (name[i] == '.')
+			count++;
+	}
+
+	/* don't count initial wildcard */
+	if (name[0] == '*')
+		if (count)
+			count--;
+
+	/* don't count the null label for root. */
+	/* if terminating '.' not found, must adjust */
+	/* count to include last label */
+	if (len > 0 && name[len-1] != '.')
+		count++;
+	_DIAGASSERT(__type_fit(int, count));
+	return (int)count;
+}
+
+
+/*
+ * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
+ * SIG records are required to be printed like this, by the Secure DNS RFC.
+ */
+char *
+p_secstodate (u_long secs) {
+	/* XXX nonreentrant */
+	static char output[15];		/* YYYYMMDDHHMMSS and null */
+	time_t myclock = secs;
+	struct tm *mytime;
+#ifdef HAVE_TIME_R
+	struct tm res;
+
+	mytime = gmtime_r(&myclock, &res);
+#else
+	mytime = gmtime(&myclock);
+#endif
+	mytime->tm_year += 1900;
+	mytime->tm_mon += 1;
+	sprintf(output, "%04d%02d%02d%02d%02d%02d",
+		mytime->tm_year, mytime->tm_mon, mytime->tm_mday,
+		mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
+	return (output);
+}
+
+u_int16_t
+res_nametoclass(const char *buf, int *successp) {
+	unsigned long result;
+	char *endptr;
+	int success;
+
+	result = sym_ston(__p_class_syms, buf, &success);
+	if (success)
+		goto done;
+
+	if (strncasecmp(buf, "CLASS", 5) != 0 ||
+	    !isdigit((unsigned char)buf[5]))
+		goto done;
+	errno = 0;
+	result = strtoul(buf + 5, &endptr, 10);
+	if (errno == 0 && *endptr == '\0' && result <= 0xffffU)
+		success = 1;
+ done:
+	if (successp)
+		*successp = success;
+	return (u_int16_t)(result);
+}
+
+u_int16_t
+res_nametotype(const char *buf, int *successp) {
+	unsigned long result;
+	char *endptr;
+	int success;
+
+	result = sym_ston(__p_type_syms, buf, &success);
+	if (success)
+		goto done;
+
+	if (strncasecmp(buf, "type", 4) != 0 ||
+	    !isdigit((unsigned char)buf[4]))
+		goto done;
+	errno = 0;
+	result = strtoul(buf + 4, &endptr, 10);
+	if (errno == 0 && *endptr == '\0' && result <= 0xffffU)
+		success = 1;
+ done:
+	if (successp)
+		*successp = success;
+	return (u_int16_t)(result);
+}
diff --git a/libc/netbsd/resolv/res_debug.h b/libc/dns/resolv/res_debug.h
similarity index 100%
rename from libc/netbsd/resolv/res_debug.h
rename to libc/dns/resolv/res_debug.h
diff --git a/libc/dns/resolv/res_init.c b/libc/dns/resolv/res_init.c
new file mode 100644
index 0000000..f1cbed8
--- /dev/null
+++ b/libc/dns/resolv/res_init.c
@@ -0,0 +1,825 @@
+/*	$NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $	*/
+
+/*
+ * Copyright (c) 1985, 1989, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#ifdef notdef
+static const char sccsid[] = "@(#)res_init.c	8.1 (Berkeley) 6/7/93";
+static const char rcsid[] = "Id: res_init.c,v 1.9.2.5.4.2 2004/03/16 12:34:18 marka Exp";
+#else
+__RCSID("$NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <netdb.h>
+
+#ifdef ANDROID_CHANGES
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/system_properties.h>
+#endif /* ANDROID_CHANGES */
+
+/* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
+#ifdef ANDROID_CHANGES
+#include "resolv_netid.h"
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+
+#include "res_private.h"
+
+/* Options.  Should all be left alone. */
+#ifndef DEBUG
+#define DEBUG
+#endif
+
+static void res_setoptions __P((res_state, const char *, const char *));
+
+#ifdef RESOLVSORT
+static const char sort_mask[] = "/&";
+#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
+static uint32_t net_mask(struct in_addr);
+#endif
+
+#if !defined(isascii)	/* XXX - could be a function */
+# define isascii(c) (!(c & 0200))
+#endif
+
+/*
+ * Resolver state default settings.
+ */
+
+/*
+ * Set up default settings.  If the configuration file exist, the values
+ * there will have precedence.  Otherwise, the server address is set to
+ * INADDR_ANY and the default domain name comes from the gethostname().
+ *
+ * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
+ * rather than INADDR_ANY ("0.0.0.0") as the default name server address
+ * since it was noted that INADDR_ANY actually meant ``the first interface
+ * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
+ * it had to be "up" in order for you to reach your own name server.  It
+ * was later decided that since the recommended practice is to always
+ * install local static routes through 127.0.0.1 for all your network
+ * interfaces, that we could solve this problem without a code change.
+ *
+ * The configuration file should always be used, since it is the only way
+ * to specify a default domain.  If you are running a server on your local
+ * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
+ * in the configuration file.
+ *
+ * Return 0 if completes successfully, -1 on error
+ */
+int
+res_ninit(res_state statp) {
+	extern int __res_vinit(res_state, int);
+
+	return (__res_vinit(statp, 0));
+}
+
+/* This function has to be reachable by res_data.c but not publicly. */
+int
+__res_vinit(res_state statp, int preinit) {
+#if !defined(__ANDROID__)
+	register FILE *fp;
+#endif
+	register char *cp, **pp;
+#if !defined(__ANDROID__)
+	register int n;
+#endif
+	char buf[BUFSIZ];
+	int nserv = 0;    /* number of nameserver records read from file */
+#if !defined(__ANDROID__)
+	int haveenv = 0;
+#endif
+	int havesearch = 0;
+#ifdef RESOLVSORT
+	int nsort = 0;
+#endif
+#if !defined(__ANDROID__)
+	char *net;
+#endif
+	int dots;
+	union res_sockaddr_union u[2];
+
+        if ((statp->options & RES_INIT) != 0U)
+                res_ndestroy(statp);
+
+	if (!preinit) {
+		statp->netid = NETID_UNSET;
+		statp->retrans = RES_TIMEOUT;
+		statp->retry = RES_DFLRETRY;
+		statp->options = RES_DEFAULT;
+		statp->id = res_randomid();
+		statp->_mark = MARK_UNSET;
+	}
+
+	memset(u, 0, sizeof(u));
+#ifdef USELOOPBACK
+	u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
+#else
+	u[nserv].sin.sin_addr.s_addr = INADDR_ANY;
+#endif
+	u[nserv].sin.sin_family = AF_INET;
+	u[nserv].sin.sin_port = htons(NAMESERVER_PORT);
+#ifdef HAVE_SA_LEN
+	u[nserv].sin.sin_len = sizeof(struct sockaddr_in);
+#endif
+	nserv++;
+#ifdef HAS_INET6_STRUCTS
+#ifdef USELOOPBACK
+	u[nserv].sin6.sin6_addr = in6addr_loopback;
+#else
+	u[nserv].sin6.sin6_addr = in6addr_any;
+#endif
+	u[nserv].sin6.sin6_family = AF_INET6;
+	u[nserv].sin6.sin6_port = htons(NAMESERVER_PORT);
+#ifdef HAVE_SA_LEN
+	u[nserv].sin6.sin6_len = sizeof(struct sockaddr_in6);
+#endif
+	nserv++;
+#endif
+	statp->nscount = 0;
+	statp->ndots = 1;
+	statp->pfcode = 0;
+	statp->_vcsock = -1;
+	statp->_flags = 0;
+	statp->qhook = NULL;
+	statp->rhook = NULL;
+	statp->_u._ext.nscount = 0;
+	statp->_u._ext.ext = malloc(sizeof(*statp->_u._ext.ext));
+	if (statp->_u._ext.ext != NULL) {
+	        memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext));
+		statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr;
+		strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa");
+		strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int");
+	}
+	statp->nsort = 0;
+	res_setservers(statp, u, nserv);
+
+#if !defined(__ANDROID__) /* IGNORE THE ENVIRONMENT */
+	/* Allow user to override the local domain definition */
+	if ((cp = getenv("LOCALDOMAIN")) != NULL) {
+		(void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
+		statp->defdname[sizeof(statp->defdname) - 1] = '\0';
+		haveenv++;
+
+		/*
+		 * Set search list to be blank-separated strings
+		 * from rest of env value.  Permits users of LOCALDOMAIN
+		 * to still have a search list, and anyone to set the
+		 * one that they want to use as an individual (even more
+		 * important now that the rfc1535 stuff restricts searches)
+		 */
+		cp = statp->defdname;
+		pp = statp->dnsrch;
+		*pp++ = cp;
+		for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
+			if (*cp == '\n')	/* silly backwards compat */
+				break;
+			else if (*cp == ' ' || *cp == '\t') {
+				*cp = 0;
+				n = 1;
+			} else if (n) {
+				*pp++ = cp;
+				n = 0;
+				havesearch = 1;
+			}
+		}
+		/* null terminate last domain if there are excess */
+		while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
+			cp++;
+		*cp = '\0';
+		*pp++ = 0;
+	}
+	if (nserv > 0)
+		statp->nscount = nserv;
+#endif
+
+#ifndef ANDROID_CHANGES /* !ANDROID_CHANGES - IGNORE resolv.conf in Android */
+#define	MATCH(line, name) \
+	(!strncmp(line, name, sizeof(name) - 1) && \
+	(line[sizeof(name) - 1] == ' ' || \
+	 line[sizeof(name) - 1] == '\t'))
+
+	nserv = 0;
+	if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
+	    /* read the config file */
+	    while (fgets(buf, sizeof(buf), fp) != NULL) {
+		/* skip comments */
+		if (*buf == ';' || *buf == '#')
+			continue;
+		/* read default domain name */
+		if (MATCH(buf, "domain")) {
+		    if (haveenv)	/* skip if have from environ */
+			    continue;
+		    cp = buf + sizeof("domain") - 1;
+		    while (*cp == ' ' || *cp == '\t')
+			    cp++;
+		    if ((*cp == '\0') || (*cp == '\n'))
+			    continue;
+		    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
+		    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
+		    if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL)
+			    *cp = '\0';
+		    havesearch = 0;
+		    continue;
+		}
+		/* set search list */
+		if (MATCH(buf, "search")) {
+		    if (haveenv)	/* skip if have from environ */
+			    continue;
+		    cp = buf + sizeof("search") - 1;
+		    while (*cp == ' ' || *cp == '\t')
+			    cp++;
+		    if ((*cp == '\0') || (*cp == '\n'))
+			    continue;
+		    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
+		    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
+		    if ((cp = strchr(statp->defdname, '\n')) != NULL)
+			    *cp = '\0';
+		    /*
+		     * Set search list to be blank-separated strings
+		     * on rest of line.
+		     */
+		    cp = statp->defdname;
+		    pp = statp->dnsrch;
+		    *pp++ = cp;
+		    for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
+			    if (*cp == ' ' || *cp == '\t') {
+				    *cp = 0;
+				    n = 1;
+			    } else if (n) {
+				    *pp++ = cp;
+				    n = 0;
+			    }
+		    }
+		    /* null terminate last domain if there are excess */
+		    while (*cp != '\0' && *cp != ' ' && *cp != '\t')
+			    cp++;
+		    *cp = '\0';
+		    *pp++ = 0;
+		    havesearch = 1;
+		    continue;
+		}
+		/* read nameservers to query */
+		if (MATCH(buf, "nameserver") && nserv < MAXNS) {
+		    struct addrinfo hints, *ai;
+		    char sbuf[NI_MAXSERV];
+		    const size_t minsiz =
+		        sizeof(statp->_u._ext.ext->nsaddrs[0]);
+
+		    cp = buf + sizeof("nameserver") - 1;
+		    while (*cp == ' ' || *cp == '\t')
+			cp++;
+		    cp[strcspn(cp, ";# \t\n")] = '\0';
+		    if ((*cp != '\0') && (*cp != '\n')) {
+			memset(&hints, 0, sizeof(hints));
+			hints.ai_family = PF_UNSPEC;
+			hints.ai_socktype = SOCK_DGRAM;	/*dummy*/
+			hints.ai_flags = AI_NUMERICHOST;
+			sprintf(sbuf, "%u", NAMESERVER_PORT);
+			if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 &&
+			    ai->ai_addrlen <= minsiz) {
+			    if (statp->_u._ext.ext != NULL) {
+				memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
+				    ai->ai_addr, ai->ai_addrlen);
+			    }
+			    if (ai->ai_addrlen <=
+			        sizeof(statp->nsaddr_list[nserv])) {
+				memcpy(&statp->nsaddr_list[nserv],
+				    ai->ai_addr, ai->ai_addrlen);
+			    } else
+				statp->nsaddr_list[nserv].sin_family = 0;
+			    freeaddrinfo(ai);
+			    nserv++;
+			}
+		    }
+		    continue;
+		}
+		if (MATCH(buf, "sortlist")) {
+		    struct in_addr a;
+
+		    cp = buf + sizeof("sortlist") - 1;
+		    while (nsort < MAXRESOLVSORT) {
+			while (*cp == ' ' || *cp == '\t')
+			    cp++;
+			if (*cp == '\0' || *cp == '\n' || *cp == ';')
+			    break;
+			net = cp;
+			while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
+			       isascii(*cp) && !isspace((unsigned char)*cp))
+				cp++;
+			n = *cp;
+			*cp = 0;
+			if (inet_aton(net, &a)) {
+			    statp->sort_list[nsort].addr = a;
+			    if (ISSORTMASK(n)) {
+				*cp++ = n;
+				net = cp;
+				while (*cp && *cp != ';' &&
+					isascii(*cp) &&
+					!isspace((unsigned char)*cp))
+				    cp++;
+				n = *cp;
+				*cp = 0;
+				if (inet_aton(net, &a)) {
+				    statp->sort_list[nsort].mask = a.s_addr;
+				} else {
+				    statp->sort_list[nsort].mask =
+					net_mask(statp->sort_list[nsort].addr);
+				}
+			    } else {
+				statp->sort_list[nsort].mask =
+				    net_mask(statp->sort_list[nsort].addr);
+			    }
+			    nsort++;
+			}
+			*cp = n;
+		    }
+		    continue;
+		}
+		if (MATCH(buf, "options")) {
+		    res_setoptions(statp, buf + sizeof("options") - 1, "conf");
+		    continue;
+		}
+	    }
+	    if (nserv > 0)
+		statp->nscount = nserv;
+	    statp->nsort = nsort;
+	    (void) fclose(fp);
+	}
+#endif /* !ANDROID_CHANGES */
+/*
+ * Last chance to get a nameserver.  This should not normally
+ * be necessary
+ */
+#ifdef NO_RESOLV_CONF
+	if(nserv == 0)
+		nserv = get_nameservers(statp);
+#endif
+
+	if (statp->defdname[0] == 0 &&
+	    gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
+	    (cp = strchr(buf, '.')) != NULL)
+		strcpy(statp->defdname, cp + 1);
+
+	/* find components of local domain that might be searched */
+	if (havesearch == 0) {
+		pp = statp->dnsrch;
+		*pp++ = statp->defdname;
+		*pp = NULL;
+
+		dots = 0;
+		for (cp = statp->defdname; *cp; cp++)
+			dots += (*cp == '.');
+
+		cp = statp->defdname;
+		while (pp < statp->dnsrch + MAXDFLSRCH) {
+			if (dots < LOCALDOMAINPARTS)
+				break;
+			cp = strchr(cp, '.') + 1;    /* we know there is one */
+			*pp++ = cp;
+			dots--;
+		}
+		*pp = NULL;
+#ifdef DEBUG
+		if (statp->options & RES_DEBUG) {
+			printf(";; res_init()... default dnsrch list:\n");
+			for (pp = statp->dnsrch; *pp; pp++)
+				printf(";;\t%s\n", *pp);
+			printf(";;\t..END..\n");
+		}
+#endif
+	}
+
+	if ((cp = getenv("RES_OPTIONS")) != NULL)
+		res_setoptions(statp, cp, "env");
+	if (nserv > 0) {
+		statp->nscount = nserv;
+		statp->options |= RES_INIT;
+	}
+	return (0);
+}
+
+static void
+res_setoptions(res_state statp, const char *options, const char *source)
+{
+	const char *cp = options;
+	int i;
+	struct __res_state_ext *ext = statp->_u._ext.ext;
+
+#ifdef DEBUG
+	if (statp->options & RES_DEBUG)
+		printf(";; res_setoptions(\"%s\", \"%s\")...\n",
+		       options, source);
+#endif
+	while (*cp) {
+		/* skip leading and inner runs of spaces */
+		while (*cp == ' ' || *cp == '\t')
+			cp++;
+		/* search for and process individual options */
+		if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
+			i = atoi(cp + sizeof("ndots:") - 1);
+			if (i <= RES_MAXNDOTS)
+				statp->ndots = i;
+			else
+				statp->ndots = RES_MAXNDOTS;
+#ifdef DEBUG
+			if (statp->options & RES_DEBUG)
+				printf(";;\tndots=%d\n", statp->ndots);
+#endif
+		} else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
+			i = atoi(cp + sizeof("timeout:") - 1);
+			if (i <= RES_MAXRETRANS)
+				statp->retrans = i;
+			else
+				statp->retrans = RES_MAXRETRANS;
+#ifdef DEBUG
+			if (statp->options & RES_DEBUG)
+				printf(";;\ttimeout=%d\n", statp->retrans);
+#endif
+		} else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
+			i = atoi(cp + sizeof("attempts:") - 1);
+			if (i <= RES_MAXRETRY)
+				statp->retry = i;
+			else
+				statp->retry = RES_MAXRETRY;
+#ifdef DEBUG
+			if (statp->options & RES_DEBUG)
+				printf(";;\tattempts=%d\n", statp->retry);
+#endif
+		} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
+#ifdef DEBUG
+			if (!(statp->options & RES_DEBUG)) {
+				printf(";; res_setoptions(\"%s\", \"%s\")..\n",
+				       options, source);
+				statp->options |= RES_DEBUG;
+			}
+			printf(";;\tdebug\n");
+#endif
+		} else if (!strncmp(cp, "no_tld_query",
+				    sizeof("no_tld_query") - 1) ||
+			   !strncmp(cp, "no-tld-query",
+				    sizeof("no-tld-query") - 1)) {
+			statp->options |= RES_NOTLDQUERY;
+		} else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
+			statp->options |= RES_USE_INET6;
+		} else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
+			statp->options |= RES_ROTATE;
+		} else if (!strncmp(cp, "no-check-names",
+				    sizeof("no-check-names") - 1)) {
+			statp->options |= RES_NOCHECKNAME;
+		}
+#ifdef RES_USE_EDNS0
+		else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
+			statp->options |= RES_USE_EDNS0;
+		}
+#endif
+		else if (!strncmp(cp, "dname", sizeof("dname") - 1)) {
+			statp->options |= RES_USE_DNAME;
+		}
+		else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) {
+			if (ext == NULL)
+				goto skip;
+			cp += sizeof("nibble:") - 1;
+			i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1);
+			strncpy(ext->nsuffix, cp, (size_t)i);
+			ext->nsuffix[i] = '\0';
+		}
+		else if (!strncmp(cp, "nibble2:", sizeof("nibble2:") - 1)) {
+			if (ext == NULL)
+				goto skip;
+			cp += sizeof("nibble2:") - 1;
+			i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1);
+			strncpy(ext->nsuffix2, cp, (size_t)i);
+			ext->nsuffix2[i] = '\0';
+		}
+		else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) {
+			cp += sizeof("v6revmode:") - 1;
+			/* "nibble" and "bitstring" used to be valid */
+			if (!strncmp(cp, "single", sizeof("single") - 1)) {
+				statp->options |= RES_NO_NIBBLE2;
+			} else if (!strncmp(cp, "both", sizeof("both") - 1)) {
+				statp->options &=
+					 ~RES_NO_NIBBLE2;
+			}
+		}
+		else {
+			/* XXX - print a warning here? */
+		}
+   skip:
+		/* skip to next run of spaces */
+		while (*cp && *cp != ' ' && *cp != '\t')
+			cp++;
+	}
+}
+
+#ifdef RESOLVSORT
+/* XXX - should really support CIDR which means explicit masks always. */
+static uint32_t
+net_mask(struct in_addr in)	/*!< XXX - should really use system's version of this */
+{
+	register uint32_t i = ntohl(in.s_addr);
+
+	if (IN_CLASSA(i))
+		return (htonl(IN_CLASSA_NET));
+	else if (IN_CLASSB(i))
+		return (htonl(IN_CLASSB_NET));
+	return (htonl(IN_CLASSC_NET));
+}
+#endif
+
+#ifdef ANDROID_CHANGES
+static int
+real_randomid(u_int *random_value) {
+	/* open the nonblocking random device, returning -1 on failure */
+	int random_device = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
+	if (random_device < 0) {
+		return -1;
+	}
+
+	/* read from the random device, returning -1 on failure (or too many retries)*/
+	for (u_int retry = 5; retry > 0; retry--) {
+		int retval = read(random_device, random_value, sizeof(u_int));
+		if (retval == sizeof(u_int)) {
+			*random_value &= 0xffff;
+			close(random_device);
+			return 0;
+		} else if ((retval < 0) && (errno != EINTR)) {
+			break;
+		}
+	}
+
+	close(random_device);
+	return -1;
+}
+#endif /* ANDROID_CHANGES */
+
+u_int
+res_randomid(void) {
+#ifdef ANDROID_CHANGES
+	int status = 0;
+	u_int output = 0;
+	status = real_randomid(&output);
+	if (status != -1) {
+		return output;
+	}
+#endif /* ANDROID_CHANGES */
+	struct timeval now;
+	gettimeofday(&now, NULL);
+	return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
+}
+
+/*%
+ * This routine is for closing the socket if a virtual circuit is used and
+ * the program wants to close it.  This provides support for endhostent()
+ * which expects to close the socket.
+ *
+ * This routine is not expected to be user visible.
+ */
+void
+res_nclose(res_state statp)
+{
+	int ns;
+
+	if (statp->_vcsock >= 0) {
+		(void) close(statp->_vcsock);
+		statp->_vcsock = -1;
+		statp->_flags &= ~(RES_F_VC | RES_F_CONN);
+	}
+	for (ns = 0; ns < statp->_u._ext.nscount; ns++) {
+		if (statp->_u._ext.nssocks[ns] != -1) {
+			(void) close(statp->_u._ext.nssocks[ns]);
+			statp->_u._ext.nssocks[ns] = -1;
+		}
+	}
+}
+
+void
+res_ndestroy(res_state statp)
+{
+	res_nclose(statp);
+	if (statp->_u._ext.ext != NULL)
+		free(statp->_u._ext.ext);
+	statp->options &= ~RES_INIT;
+	statp->_u._ext.ext = NULL;
+}
+
+const char *
+res_get_nibblesuffix(res_state statp)
+{
+	if (statp->_u._ext.ext)
+		return (statp->_u._ext.ext->nsuffix);
+	return ("ip6.arpa");
+}
+
+const char *
+res_get_nibblesuffix2(res_state statp)
+{
+	if (statp->_u._ext.ext)
+		return (statp->_u._ext.ext->nsuffix2);
+	return ("ip6.int");
+}
+
+void
+res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt)
+{
+	int i, nserv;
+	size_t size;
+
+	/* close open servers */
+	res_nclose(statp);
+
+	/* cause rtt times to be forgotten */
+	statp->_u._ext.nscount = 0;
+
+	nserv = 0;
+	for (i = 0; i < cnt && nserv < MAXNS; i++) {
+		switch (set->sin.sin_family) {
+		case AF_INET:
+			size = sizeof(set->sin);
+			if (statp->_u._ext.ext)
+				memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
+					&set->sin, size);
+			if (size <= sizeof(statp->nsaddr_list[nserv]))
+				memcpy(&statp->nsaddr_list[nserv],
+					&set->sin, size);
+			else
+				statp->nsaddr_list[nserv].sin_family = 0;
+			nserv++;
+			break;
+
+#ifdef HAS_INET6_STRUCTS
+		case AF_INET6:
+			size = sizeof(set->sin6);
+			if (statp->_u._ext.ext)
+				memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
+					&set->sin6, size);
+			if (size <= sizeof(statp->nsaddr_list[nserv]))
+				memcpy(&statp->nsaddr_list[nserv],
+					&set->sin6, size);
+			else
+				statp->nsaddr_list[nserv].sin_family = 0;
+			nserv++;
+			break;
+#endif
+
+		default:
+			break;
+		}
+		set++;
+	}
+	statp->nscount = nserv;
+
+}
+
+int
+res_getservers(res_state statp, union res_sockaddr_union *set, int cnt)
+{
+	int i;
+	size_t size;
+	uint16_t family;
+
+	for (i = 0; i < statp->nscount && i < cnt; i++) {
+		if (statp->_u._ext.ext)
+			family = statp->_u._ext.ext->nsaddrs[i].sin.sin_family;
+		else
+			family = statp->nsaddr_list[i].sin_family;
+
+		switch (family) {
+		case AF_INET:
+			size = sizeof(set->sin);
+			if (statp->_u._ext.ext)
+				memcpy(&set->sin,
+				       &statp->_u._ext.ext->nsaddrs[i],
+				       size);
+			else
+				memcpy(&set->sin, &statp->nsaddr_list[i],
+				       size);
+			break;
+
+#ifdef HAS_INET6_STRUCTS
+		case AF_INET6:
+			size = sizeof(set->sin6);
+			if (statp->_u._ext.ext)
+				memcpy(&set->sin6,
+				       &statp->_u._ext.ext->nsaddrs[i],
+				       size);
+			else
+				memcpy(&set->sin6, &statp->nsaddr_list[i],
+				       size);
+			break;
+#endif
+
+		default:
+			set->sin.sin_family = 0;
+			break;
+		}
+		set++;
+	}
+	return (statp->nscount);
+}
+
+#ifdef ANDROID_CHANGES
+void res_setnetid(res_state statp, unsigned netid)
+{
+	if (statp != NULL) {
+		statp->netid = netid;
+	}
+}
+
+void res_setmark(res_state statp, unsigned mark)
+{
+	if (statp != NULL) {
+		statp->_mark = mark;
+	}
+}
+
+#endif /* ANDROID_CHANGES */
diff --git a/libc/dns/resolv/res_mkquery.c b/libc/dns/resolv/res_mkquery.c
new file mode 100644
index 0000000..3736aa1
--- /dev/null
+++ b/libc/dns/resolv/res_mkquery.c
@@ -0,0 +1,276 @@
+/*	$NetBSD: res_mkquery.c,v 1.6 2006/01/24 17:40:32 christos Exp $	*/
+
+/*
+ * Copyright (c) 2008  Android Open Source Project (query id randomization)
+ * Copyright (c) 1985, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#ifdef notdef
+static const char sccsid[] = "@(#)res_mkquery.c	8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "Id: res_mkquery.c,v 1.1.2.2.4.2 2004/03/16 12:34:18 marka Exp";
+#else
+__RCSID("$NetBSD: res_mkquery.c,v 1.6 2006/01/24 17:40:32 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+
+/* Options.  Leave them on. */
+#ifndef DEBUG
+#define DEBUG
+#endif
+
+#ifndef lint
+#define UNUSED(a)	(void)&a
+#else
+#define UNUSED(a)	a = a
+#endif
+
+extern const char *_res_opcodes[];
+
+/*
+ * Form all types of queries.
+ * Returns the size of the result or -1.
+ */
+int
+res_nmkquery(res_state statp,
+	     int op,			/* opcode of query */
+	     const char *dname,		/* domain name */
+	     int class, int type,	/* class and type of query */
+	     const u_char *data,	/* resource record data */
+	     int datalen,		/* length of data */
+	     const u_char *newrr_in,	/* new rr for modify or append */
+	     u_char *buf,		/* buffer to put query */
+	     int buflen)		/* size of buffer */
+{
+	register HEADER *hp;
+	register u_char *cp, *ep;
+	register int n;
+	u_char *dnptrs[20], **dpp, **lastdnptr;
+
+	UNUSED(newrr_in);
+
+#ifdef DEBUG
+	if (statp->options & RES_DEBUG)
+		printf(";; res_nmkquery(%s, %s, %s, %s)\n",
+		       _res_opcodes[op], dname, p_class(class), p_type(type));
+#endif
+	/*
+	 * Initialize header fields.
+	 */
+	if ((buf == NULL) || (buflen < HFIXEDSZ))
+		return (-1);
+	memset(buf, 0, HFIXEDSZ);
+	hp = (HEADER *)(void *)buf;
+	hp->id = htons(res_randomid());
+	hp->opcode = op;
+	hp->rd = (statp->options & RES_RECURSE) != 0U;
+	hp->rcode = NOERROR;
+	cp = buf + HFIXEDSZ;
+	ep = buf + buflen;
+	dpp = dnptrs;
+	*dpp++ = buf;
+	*dpp++ = NULL;
+	lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+	/*
+	 * perform opcode specific processing
+	 */
+	switch (op) {
+	case QUERY:	/*FALLTHROUGH*/
+	case NS_NOTIFY_OP:
+		if (ep - cp < QFIXEDSZ)
+			return (-1);
+		if ((n = dn_comp(dname, cp, ep - cp - QFIXEDSZ, dnptrs,
+		    lastdnptr)) < 0)
+			return (-1);
+		cp += n;
+		ns_put16(type, cp);
+		cp += INT16SZ;
+		ns_put16(class, cp);
+		cp += INT16SZ;
+		hp->qdcount = htons(1);
+		if (op == QUERY || data == NULL)
+			break;
+		/*
+		 * Make an additional record for completion domain.
+		 */
+		if ((ep - cp) < RRFIXEDSZ)
+			return (-1);
+		n = dn_comp((const char *)data, cp, ep - cp - RRFIXEDSZ,
+			    dnptrs, lastdnptr);
+		if (n < 0)
+			return (-1);
+		cp += n;
+		ns_put16(T_NULL, cp);
+		cp += INT16SZ;
+		ns_put16(class, cp);
+		cp += INT16SZ;
+		ns_put32(0, cp);
+		cp += INT32SZ;
+		ns_put16(0, cp);
+		cp += INT16SZ;
+		hp->arcount = htons(1);
+		break;
+
+	case IQUERY:
+		/*
+		 * Initialize answer section
+		 */
+		if (ep - cp < 1 + RRFIXEDSZ + datalen)
+			return (-1);
+		*cp++ = '\0';	/* no domain name */
+		ns_put16(type, cp);
+		cp += INT16SZ;
+		ns_put16(class, cp);
+		cp += INT16SZ;
+		ns_put32(0, cp);
+		cp += INT32SZ;
+		ns_put16(datalen, cp);
+		cp += INT16SZ;
+		if (datalen) {
+			memcpy(cp, data, (size_t)datalen);
+			cp += datalen;
+		}
+		hp->ancount = htons(1);
+		break;
+
+	default:
+		return (-1);
+	}
+	return (cp - buf);
+}
+
+#ifdef RES_USE_EDNS0
+/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
+#ifndef T_OPT
+#define T_OPT	41
+#endif
+
+int
+res_nopt(res_state statp,
+	 int n0,		/* current offset in buffer */
+	 u_char *buf,		/* buffer to put query */
+	 int buflen,		/* size of buffer */
+	 int anslen)		/* UDP answer buffer size */
+{
+	register HEADER *hp;
+	register u_char *cp, *ep;
+	u_int16_t flags = 0;
+
+#ifdef DEBUG
+	if ((statp->options & RES_DEBUG) != 0U)
+		printf(";; res_nopt()\n");
+#endif
+
+	hp = (HEADER *)(void *)buf;
+	cp = buf + n0;
+	ep = buf + buflen;
+
+	if ((ep - cp) < 1 + RRFIXEDSZ)
+		return (-1);
+
+	*cp++ = 0;	/* "." */
+
+	ns_put16(T_OPT, cp);	/* TYPE */
+	cp += INT16SZ;
+	ns_put16(anslen & 0xffff, cp);	/* CLASS = UDP payload size */
+	cp += INT16SZ;
+	*cp++ = NOERROR;	/* extended RCODE */
+	*cp++ = 0;		/* EDNS version */
+	if (statp->options & RES_USE_DNSSEC) {
+#ifdef DEBUG
+		if (statp->options & RES_DEBUG)
+			printf(";; res_opt()... ENDS0 DNSSEC\n");
+#endif
+		flags |= NS_OPT_DNSSEC_OK;
+	}
+	ns_put16(flags, cp);
+	cp += INT16SZ;
+	ns_put16(0, cp);	/* RDLEN */
+	cp += INT16SZ;
+	hp->arcount = htons(ntohs(hp->arcount) + 1);
+
+	return (cp - buf);
+}
+#endif
diff --git a/libc/netbsd/resolv/res_private.h b/libc/dns/resolv/res_private.h
similarity index 100%
rename from libc/netbsd/resolv/res_private.h
rename to libc/dns/resolv/res_private.h
diff --git a/libc/dns/resolv/res_query.c b/libc/dns/resolv/res_query.c
new file mode 100644
index 0000000..6cd9b15
--- /dev/null
+++ b/libc/dns/resolv/res_query.c
@@ -0,0 +1,425 @@
+/*	$NetBSD: res_query.c,v 1.7 2006/01/24 17:41:25 christos Exp $	*/
+
+/*
+ * Copyright (c) 1988, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#ifdef notdef
+static const char sccsid[] = "@(#)res_query.c	8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "Id: res_query.c,v 1.2.2.3.4.2 2004/03/16 12:34:19 marka Exp";
+#else
+__RCSID("$NetBSD: res_query.c,v 1.7 2006/01/24 17:41:25 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_cache.h"
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#define DISABLE_HOST_ALIAS 1
+
+/* Options.  Leave them on. */
+#ifndef DEBUG
+#define DEBUG
+#endif
+
+#if PACKETSZ > 1024
+#define MAXPACKET	PACKETSZ
+#else
+#define MAXPACKET	1024
+#endif
+
+/*
+ * Formulate a normal query, send, and await answer.
+ * Returned answer is placed in supplied buffer "answer".
+ * Perform preliminary check of answer, returning success only
+ * if no error is indicated and the answer count is nonzero.
+ * Return the size of the response on success, -1 on error.
+ * Error number is left in H_ERRNO.
+ *
+ * Caller must parse answer and determine whether it answers the question.
+ */
+int
+res_nquery(res_state statp,
+	   const char *name,	/* domain name */
+	   int class, int type,	/* class and type of query */
+	   u_char *answer,	/* buffer to put answer */
+	   int anslen)		/* size of answer buffer */
+{
+	u_char buf[MAXPACKET];
+	HEADER *hp = (HEADER *)(void *)answer;
+	int n;
+	u_int oflags;
+
+	oflags = statp->_flags;
+
+again:
+	hp->rcode = NOERROR;	/* default */
+
+#ifdef DEBUG
+	if (statp->options & RES_DEBUG)
+		printf(";; res_query(%s, %d, %d)\n", name, class, type);
+#endif
+
+	n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL,
+			 buf, sizeof(buf));
+#ifdef RES_USE_EDNS0
+	if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
+	    (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U)
+		n = res_nopt(statp, n, buf, sizeof(buf), anslen);
+#endif
+	if (n <= 0) {
+#ifdef DEBUG
+		if (statp->options & RES_DEBUG)
+			printf(";; res_query: mkquery failed\n");
+#endif
+		RES_SET_H_ERRNO(statp, NO_RECOVERY);
+		return (n);
+	}
+	n = res_nsend(statp, buf, n, answer, anslen);
+	if (n < 0) {
+#ifdef RES_USE_EDNS0
+		/* if the query choked with EDNS0, retry without EDNS0 */
+		if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U &&
+		    ((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) {
+			statp->_flags |= RES_F_EDNS0ERR;
+			if (statp->options & RES_DEBUG)
+				printf(";; res_nquery: retry without EDNS0\n");
+			goto again;
+		}
+#endif
+#ifdef DEBUG
+		if (statp->options & RES_DEBUG)
+			printf(";; res_query: send error\n");
+#endif
+		RES_SET_H_ERRNO(statp, TRY_AGAIN);
+		return (n);
+	}
+
+	if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
+#ifdef DEBUG
+		if (statp->options & RES_DEBUG)
+			printf(";; rcode = (%s), counts = an:%d ns:%d ar:%d\n",
+			       p_rcode(hp->rcode),
+			       ntohs(hp->ancount),
+			       ntohs(hp->nscount),
+			       ntohs(hp->arcount));
+#endif
+		switch (hp->rcode) {
+		case NXDOMAIN:
+			RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
+			break;
+		case SERVFAIL:
+			RES_SET_H_ERRNO(statp, TRY_AGAIN);
+			break;
+		case NOERROR:
+			RES_SET_H_ERRNO(statp, NO_DATA);
+			break;
+		case FORMERR:
+		case NOTIMP:
+		case REFUSED:
+		default:
+			RES_SET_H_ERRNO(statp, NO_RECOVERY);
+			break;
+		}
+		return (-1);
+	}
+	return (n);
+}
+
+/*
+ * Formulate a normal query, send, and retrieve answer in supplied buffer.
+ * Return the size of the response on success, -1 on error.
+ * If enabled, implement search rules until answer or unrecoverable failure
+ * is detected.  Error code, if any, is left in H_ERRNO.
+ */
+int
+res_nsearch(res_state statp,
+	    const char *name,	/* domain name */
+	    int class, int type,	/* class and type of query */
+	    u_char *answer,	/* buffer to put answer */
+	    int anslen)		/* size of answer */
+{
+	const char *cp, * const *domain;
+	HEADER *hp = (HEADER *)(void *)answer;
+	char tmp[NS_MAXDNAME];
+	u_int dots;
+	int trailing_dot, ret, saved_herrno;
+	int got_nodata = 0, got_servfail = 0, root_on_list = 0;
+	int tried_as_is = 0;
+	int searched = 0;
+
+	errno = 0;
+	RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);  /* True if we never query. */
+
+	dots = 0;
+	for (cp = name; *cp != '\0'; cp++)
+		dots += (*cp == '.');
+	trailing_dot = 0;
+	if (cp > name && *--cp == '.')
+		trailing_dot++;
+
+	/* If there aren't any dots, it could be a user-level alias. */
+	if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL)
+		return (res_nquery(statp, cp, class, type, answer, anslen));
+
+	/*
+	 * If there are enough dots in the name, let's just give it a
+	 * try 'as is'. The threshold can be set with the "ndots" option.
+	 * Also, query 'as is', if there is a trailing dot in the name.
+	 */
+	saved_herrno = -1;
+	if (dots >= statp->ndots || trailing_dot) {
+		ret = res_nquerydomain(statp, name, NULL, class, type,
+					 answer, anslen);
+		if (ret > 0 || trailing_dot)
+			return (ret);
+		saved_herrno = statp->res_h_errno;
+		tried_as_is++;
+	}
+
+	/*
+	 * We do at least one level of search if
+	 *	- there is no dot and RES_DEFNAME is set, or
+	 *	- there is at least one dot, there is no trailing dot,
+	 *	  and RES_DNSRCH is set.
+	 */
+	if ((!dots && (statp->options & RES_DEFNAMES) != 0U) ||
+	    (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
+		int done = 0;
+
+		/* Unfortunately we need to load network-specific info
+		 * (dns servers, search domains) before
+		 * the domain stuff is tried.  Will have a better
+		 * fix after thread pools are used as this will
+		 * be loaded once for the thread instead of each
+		 * time a query is tried.
+		 */
+		_resolv_populate_res_for_net(statp);
+
+		for (domain = (const char * const *)statp->dnsrch;
+		     *domain && !done;
+		     domain++) {
+			searched = 1;
+
+			if (domain[0][0] == '\0' ||
+			    (domain[0][0] == '.' && domain[0][1] == '\0'))
+				root_on_list++;
+
+			ret = res_nquerydomain(statp, name, *domain,
+					       class, type,
+					       answer, anslen);
+			if (ret > 0)
+				return (ret);
+
+			/*
+			 * If no server present, give up.
+			 * If name isn't found in this domain,
+			 * keep trying higher domains in the search list
+			 * (if that's enabled).
+			 * On a NO_DATA error, keep trying, otherwise
+			 * a wildcard entry of another type could keep us
+			 * from finding this entry higher in the domain.
+			 * If we get some other error (negative answer or
+			 * server failure), then stop searching up,
+			 * but try the input name below in case it's
+			 * fully-qualified.
+			 */
+			if (errno == ECONNREFUSED) {
+				RES_SET_H_ERRNO(statp, TRY_AGAIN);
+				return (-1);
+			}
+
+			switch (statp->res_h_errno) {
+			case NO_DATA:
+				got_nodata++;
+				/* FALLTHROUGH */
+			case HOST_NOT_FOUND:
+				/* keep trying */
+				break;
+			case TRY_AGAIN:
+				if (hp->rcode == SERVFAIL) {
+					/* try next search element, if any */
+					got_servfail++;
+					break;
+				}
+				/* FALLTHROUGH */
+			default:
+				/* anything else implies that we're done */
+				done++;
+			}
+
+			/* if we got here for some reason other than DNSRCH,
+			 * we only wanted one iteration of the loop, so stop.
+			 */
+			if ((statp->options & RES_DNSRCH) == 0U)
+				done++;
+		}
+	}
+
+	/*
+	 * If the query has not already been tried as is then try it
+	 * unless RES_NOTLDQUERY is set and there were no dots.
+	 */
+	if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) &&
+	    !(tried_as_is || root_on_list)) {
+		ret = res_nquerydomain(statp, name, NULL, class, type,
+				       answer, anslen);
+		if (ret > 0)
+			return (ret);
+	}
+
+	/* if we got here, we didn't satisfy the search.
+	 * if we did an initial full query, return that query's H_ERRNO
+	 * (note that we wouldn't be here if that query had succeeded).
+	 * else if we ever got a nodata, send that back as the reason.
+	 * else send back meaningless H_ERRNO, that being the one from
+	 * the last DNSRCH we did.
+	 */
+	if (saved_herrno != -1)
+		RES_SET_H_ERRNO(statp, saved_herrno);
+	else if (got_nodata)
+		RES_SET_H_ERRNO(statp, NO_DATA);
+	else if (got_servfail)
+		RES_SET_H_ERRNO(statp, TRY_AGAIN);
+	return (-1);
+}
+
+/*
+ * Perform a call on res_query on the concatenation of name and domain,
+ * removing a trailing dot from name if domain is NULL.
+ */
+int
+res_nquerydomain(res_state statp,
+	    const char *name,
+	    const char *domain,
+	    int class, int type,	/* class and type of query */
+	    u_char *answer,		/* buffer to put answer */
+	    int anslen)		/* size of answer */
+{
+	char nbuf[MAXDNAME];
+	const char *longname = nbuf;
+	int n, d;
+
+#ifdef DEBUG
+	if (statp->options & RES_DEBUG)
+		printf(";; res_nquerydomain(%s, %s, %d, %d)\n",
+		       name, domain?domain:"<Nil>", class, type);
+#endif
+	if (domain == NULL) {
+		/*
+		 * Check for trailing '.';
+		 * copy without '.' if present.
+		 */
+		n = strlen(name);
+		if (n >= MAXDNAME) {
+			RES_SET_H_ERRNO(statp, NO_RECOVERY);
+			return (-1);
+		}
+		n--;
+		if (n >= 0 && name[n] == '.') {
+			strncpy(nbuf, name, (size_t)n);
+			nbuf[n] = '\0';
+		} else
+			longname = name;
+	} else {
+		n = strlen(name);
+		d = strlen(domain);
+		if (n + d + 1 >= MAXDNAME) {
+			RES_SET_H_ERRNO(statp, NO_RECOVERY);
+			return (-1);
+		}
+		sprintf(nbuf, "%s.%s", name, domain);
+	}
+	return (res_nquery(statp, longname, class, type, answer, anslen));
+}
+
+const char *
+res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) {
+	return (NULL);
+}
diff --git a/libc/dns/resolv/res_send.c b/libc/dns/resolv/res_send.c
new file mode 100644
index 0000000..6439e31
--- /dev/null
+++ b/libc/dns/resolv/res_send.c
@@ -0,0 +1,1349 @@
+/*	$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $	*/
+
+/*
+ * Copyright 2008  Android Open Source Project (source port randomization)
+ * Copyright (c) 1985, 1989, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#ifdef notdef
+static const char sccsid[] = "@(#)res_send.c	8.1 (Berkeley) 6/4/93";
+static const char rcsid[] = "Id: res_send.c,v 1.5.2.2.4.5 2004/08/10 02:19:56 marka Exp";
+#else
+__RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+/* set to 1 to use our small/simple/limited DNS cache */
+#define  USE_RESOLV_CACHE  1
+
+/*
+ * Send query to name server and wait for reply.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#ifdef ANDROID_CHANGES
+#include "resolv_netid.h"
+#include "resolv_private.h"
+#else
+#include <resolv.h>
+#endif
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <isc/eventlib.h>
+
+#if USE_RESOLV_CACHE
+#  include <resolv_cache.h>
+#endif
+
+#include "private/libc_logging.h"
+
+#ifndef DE_CONST
+#define DE_CONST(c,v)   v = ((c) ? \
+    strchr((const void *)(c), *(const char *)(const void *)(c)) : NULL)
+#endif
+
+/* Options.  Leave them on. */
+#ifndef DEBUG
+#define DEBUG
+#endif
+#include "res_debug.h"
+#include "res_private.h"
+
+#define EXT(res) ((res)->_u._ext)
+#define DBG 0
+
+static const int highestFD = FD_SETSIZE - 1;
+
+/* Forward. */
+
+static int		get_salen __P((const struct sockaddr *));
+static struct sockaddr * get_nsaddr __P((res_state, size_t));
+static int		send_vc(res_state, const u_char *, int,
+				u_char *, int, int *, int);
+static int		send_dg(res_state, const u_char *, int,
+				u_char *, int, int *, int,
+				int *, int *);
+static void		Aerror(const res_state, FILE *, const char *, int,
+			       const struct sockaddr *, int);
+static void		Perror(const res_state, FILE *, const char *, int);
+static int		sock_eq(struct sockaddr *, struct sockaddr *);
+#ifdef NEED_PSELECT
+static int		pselect(int, void *, void *, void *,
+				struct timespec *,
+				const sigset_t *);
+#endif
+void res_pquery(const res_state, const u_char *, int, FILE *);
+static int connect_with_timeout(int sock, const struct sockaddr *nsap,
+			socklen_t salen, int sec);
+static int retrying_select(const int sock, fd_set *readset, fd_set *writeset,
+			const struct timespec *finish);
+
+/* BIONIC-BEGIN: implement source port randomization */
+typedef union {
+    struct sockaddr      sa;
+    struct sockaddr_in   sin;
+    struct sockaddr_in6  sin6;
+} _sockaddr_union;
+
+static int
+random_bind( int  s, int  family )
+{
+    _sockaddr_union  u;
+    int              j;
+    socklen_t        slen;
+
+    /* clear all, this also sets the IP4/6 address to 'any' */
+    memset( &u, 0, sizeof u );
+
+    switch (family) {
+        case AF_INET:
+            u.sin.sin_family = family;
+            slen             = sizeof u.sin;
+            break;
+        case AF_INET6:
+            u.sin6.sin6_family = family;
+            slen               = sizeof u.sin6;
+            break;
+        default:
+            errno = EPROTO;
+            return -1;
+    }
+
+    /* first try to bind to a random source port a few times */
+    for (j = 0; j < 10; j++) {
+        /* find a random port between 1025 .. 65534 */
+        int  port = 1025 + (res_randomid() % (65535-1025));
+        if (family == AF_INET)
+            u.sin.sin_port = htons(port);
+        else
+            u.sin6.sin6_port = htons(port);
+
+        if ( !bind( s, &u.sa, slen ) )
+            return 0;
+    }
+
+    /* nothing after 10 tries, our network table is probably busy */
+    /* let the system decide which port is best */
+    if (family == AF_INET)
+        u.sin.sin_port = 0;
+    else
+        u.sin6.sin6_port = 0;
+
+    return bind( s, &u.sa, slen );
+}
+/* BIONIC-END */
+
+static const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
+
+/* Public. */
+
+/* int
+ * res_isourserver(ina)
+ *	looks up "ina" in _res.ns_addr_list[]
+ * returns:
+ *	0  : not found
+ *	>0 : found
+ * author:
+ *	paul vixie, 29may94
+ */
+__LIBC_HIDDEN__ int
+res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
+	const struct sockaddr_in *inp, *srv;
+	const struct sockaddr_in6 *in6p, *srv6;
+	int ns;
+
+	switch (sa->sa_family) {
+	case AF_INET:
+		inp = (const struct sockaddr_in *)(const void *)sa;
+		for (ns = 0;  ns < statp->nscount;  ns++) {
+			srv = (struct sockaddr_in *)(void *)get_nsaddr(statp, (size_t)ns);
+			if (srv->sin_family == inp->sin_family &&
+			    srv->sin_port == inp->sin_port &&
+			    (srv->sin_addr.s_addr == INADDR_ANY ||
+			     srv->sin_addr.s_addr == inp->sin_addr.s_addr))
+				return (1);
+		}
+		break;
+	case AF_INET6:
+		if (EXT(statp).ext == NULL)
+			break;
+		in6p = (const struct sockaddr_in6 *)(const void *)sa;
+		for (ns = 0;  ns < statp->nscount;  ns++) {
+			srv6 = (struct sockaddr_in6 *)(void *)get_nsaddr(statp, (size_t)ns);
+			if (srv6->sin6_family == in6p->sin6_family &&
+			    srv6->sin6_port == in6p->sin6_port &&
+#ifdef HAVE_SIN6_SCOPE_ID
+			    (srv6->sin6_scope_id == 0 ||
+			     srv6->sin6_scope_id == in6p->sin6_scope_id) &&
+#endif
+			    (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) ||
+			     IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr, &in6p->sin6_addr)))
+				return (1);
+		}
+		break;
+	default:
+		break;
+	}
+	return (0);
+}
+
+/* int
+ * res_nameinquery(name, type, class, buf, eom)
+ *	look for (name,type,class) in the query section of packet (buf,eom)
+ * requires:
+ *	buf + HFIXEDSZ <= eom
+ * returns:
+ *	-1 : format error
+ *	0  : not found
+ *	>0 : found
+ * author:
+ *	paul vixie, 29may94
+ */
+int
+res_nameinquery(const char *name, int type, int class,
+		const u_char *buf, const u_char *eom)
+{
+	const u_char *cp = buf + HFIXEDSZ;
+	int qdcount = ntohs(((const HEADER*)(const void *)buf)->qdcount);
+
+	while (qdcount-- > 0) {
+		char tname[MAXDNAME+1];
+		int n, ttype, tclass;
+
+		n = dn_expand(buf, eom, cp, tname, sizeof tname);
+		if (n < 0)
+			return (-1);
+		cp += n;
+		if (cp + 2 * INT16SZ > eom)
+			return (-1);
+		ttype = ns_get16(cp); cp += INT16SZ;
+		tclass = ns_get16(cp); cp += INT16SZ;
+		if (ttype == type && tclass == class &&
+		    ns_samename(tname, name) == 1)
+			return (1);
+	}
+	return (0);
+}
+
+/* int
+ * res_queriesmatch(buf1, eom1, buf2, eom2)
+ *	is there a 1:1 mapping of (name,type,class)
+ *	in (buf1,eom1) and (buf2,eom2)?
+ * returns:
+ *	-1 : format error
+ *	0  : not a 1:1 mapping
+ *	>0 : is a 1:1 mapping
+ * author:
+ *	paul vixie, 29may94
+ */
+int
+res_queriesmatch(const u_char *buf1, const u_char *eom1,
+		 const u_char *buf2, const u_char *eom2)
+{
+	const u_char *cp = buf1 + HFIXEDSZ;
+	int qdcount = ntohs(((const HEADER*)(const void *)buf1)->qdcount);
+
+	if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
+		return (-1);
+
+	/*
+	 * Only header section present in replies to
+	 * dynamic update packets.
+	 */
+	if ((((const HEADER *)(const void *)buf1)->opcode == ns_o_update) &&
+	    (((const HEADER *)(const void *)buf2)->opcode == ns_o_update))
+		return (1);
+
+	if (qdcount != ntohs(((const HEADER*)(const void *)buf2)->qdcount))
+		return (0);
+	while (qdcount-- > 0) {
+		char tname[MAXDNAME+1];
+		int n, ttype, tclass;
+
+		n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
+		if (n < 0)
+			return (-1);
+		cp += n;
+		if (cp + 2 * INT16SZ > eom1)
+			return (-1);
+		ttype = ns_get16(cp);	cp += INT16SZ;
+		tclass = ns_get16(cp); cp += INT16SZ;
+		if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
+			return (0);
+	}
+	return (1);
+}
+
+
+int
+res_nsend(res_state statp,
+	  const u_char *buf, int buflen, u_char *ans, int anssiz)
+{
+	int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
+	char abuf[NI_MAXHOST];
+#if USE_RESOLV_CACHE
+        ResolvCacheStatus     cache_status = RESOLV_CACHE_UNSUPPORTED;
+#endif
+
+#if !USE_RESOLV_CACHE
+	if (statp->nscount == 0) {
+		errno = ESRCH;
+		return (-1);
+	}
+#endif
+
+	if (anssiz < HFIXEDSZ) {
+		errno = EINVAL;
+		return (-1);
+	}
+	DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),
+		(stdout, ";; res_send()\n"), buf, buflen);
+	v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
+	gotsomewhere = 0;
+	terrno = ETIMEDOUT;
+
+#if USE_RESOLV_CACHE
+	int  anslen = 0;
+	cache_status = _resolv_cache_lookup(
+			statp->netid, buf, buflen,
+			ans, anssiz, &anslen);
+
+	if (cache_status == RESOLV_CACHE_FOUND) {
+		return anslen;
+	} else if (cache_status != RESOLV_CACHE_UNSUPPORTED) {
+		// had a cache miss for a known network, so populate the thread private
+		// data so the normal resolve path can do its thing
+		_resolv_populate_res_for_net(statp);
+	}
+
+	if (statp->nscount == 0) {
+		errno = ESRCH;
+		return (-1);
+	}
+#endif
+
+	/*
+	 * If the ns_addr_list in the resolver context has changed, then
+	 * invalidate our cached copy and the associated timing data.
+	 */
+	if (EXT(statp).nscount != 0) {
+		int needclose = 0;
+		struct sockaddr_storage peer;
+		socklen_t peerlen;
+
+		if (EXT(statp).nscount != statp->nscount)
+			needclose++;
+		else
+			for (ns = 0; ns < statp->nscount; ns++) {
+				if (statp->nsaddr_list[ns].sin_family &&
+				    !sock_eq((struct sockaddr *)(void *)&statp->nsaddr_list[ns],
+					     (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[ns])) {
+					needclose++;
+					break;
+				}
+
+				if (EXT(statp).nssocks[ns] == -1)
+					continue;
+				peerlen = sizeof(peer);
+				if (getpeername(EXT(statp).nssocks[ns],
+				    (struct sockaddr *)(void *)&peer, &peerlen) < 0) {
+					needclose++;
+					break;
+				}
+				if (!sock_eq((struct sockaddr *)(void *)&peer,
+				    get_nsaddr(statp, (size_t)ns))) {
+					needclose++;
+					break;
+				}
+			}
+		if (needclose) {
+			res_nclose(statp);
+			EXT(statp).nscount = 0;
+		}
+	}
+
+	/*
+	 * Maybe initialize our private copy of the ns_addr_list.
+	 */
+	if (EXT(statp).nscount == 0) {
+		for (ns = 0; ns < statp->nscount; ns++) {
+			EXT(statp).nstimes[ns] = RES_MAXTIME;
+			EXT(statp).nssocks[ns] = -1;
+			if (!statp->nsaddr_list[ns].sin_family)
+				continue;
+			EXT(statp).ext->nsaddrs[ns].sin =
+				 statp->nsaddr_list[ns];
+		}
+		EXT(statp).nscount = statp->nscount;
+	}
+
+	/*
+	 * Some resolvers want to even out the load on their nameservers.
+	 * Note that RES_BLAST overrides RES_ROTATE.
+	 */
+	if ((statp->options & RES_ROTATE) != 0U &&
+	    (statp->options & RES_BLAST) == 0U) {
+		union res_sockaddr_union inu;
+		struct sockaddr_in ina;
+		int lastns = statp->nscount - 1;
+		int fd;
+		u_int16_t nstime;
+
+		if (EXT(statp).ext != NULL)
+			inu = EXT(statp).ext->nsaddrs[0];
+		ina = statp->nsaddr_list[0];
+		fd = EXT(statp).nssocks[0];
+		nstime = EXT(statp).nstimes[0];
+		for (ns = 0; ns < lastns; ns++) {
+			if (EXT(statp).ext != NULL)
+                                EXT(statp).ext->nsaddrs[ns] =
+					EXT(statp).ext->nsaddrs[ns + 1];
+			statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
+			EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
+			EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1];
+		}
+		if (EXT(statp).ext != NULL)
+			EXT(statp).ext->nsaddrs[lastns] = inu;
+		statp->nsaddr_list[lastns] = ina;
+		EXT(statp).nssocks[lastns] = fd;
+		EXT(statp).nstimes[lastns] = nstime;
+	}
+
+	/*
+	 * Send request, RETRY times, or until successful.
+	 */
+	for (try = 0; try < statp->retry; try++) {
+	    for (ns = 0; ns < statp->nscount; ns++) {
+		struct sockaddr *nsap;
+		int nsaplen;
+		nsap = get_nsaddr(statp, (size_t)ns);
+		nsaplen = get_salen(nsap);
+		statp->_flags &= ~RES_F_LASTMASK;
+		statp->_flags |= (ns << RES_F_LASTSHIFT);
+ same_ns:
+		if (statp->qhook) {
+			int done = 0, loops = 0;
+
+			do {
+				res_sendhookact act;
+
+				act = (*statp->qhook)(&nsap, &buf, &buflen,
+						      ans, anssiz, &resplen);
+				switch (act) {
+				case res_goahead:
+					done = 1;
+					break;
+				case res_nextns:
+					res_nclose(statp);
+					goto next_ns;
+				case res_done:
+					return (resplen);
+				case res_modified:
+					/* give the hook another try */
+					if (++loops < 42) /*doug adams*/
+						break;
+					/*FALLTHROUGH*/
+				case res_error:
+					/*FALLTHROUGH*/
+				default:
+					goto fail;
+				}
+			} while (!done);
+		}
+
+		Dprint(((statp->options & RES_DEBUG) &&
+			getnameinfo(nsap, (socklen_t)nsaplen, abuf, sizeof(abuf),
+				NULL, 0, niflags) == 0),
+				(stdout, ";; Querying server (# %d) address = %s\n",
+				ns + 1, abuf));
+
+
+		if (v_circuit) {
+			/* Use VC; at most one attempt per server. */
+			try = statp->retry;
+
+			n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
+				    ns);
+
+			if (DBG) {
+				__libc_format_log(ANDROID_LOG_DEBUG, "libc",
+					"used send_vc %d\n", n);
+			}
+
+			if (n < 0)
+				goto fail;
+			if (n == 0)
+				goto next_ns;
+			resplen = n;
+		} else {
+			/* Use datagrams. */
+			if (DBG) {
+				__libc_format_log(ANDROID_LOG_DEBUG, "libc", "using send_dg\n");
+			}
+
+			n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
+				    ns, &v_circuit, &gotsomewhere);
+			if (DBG) {
+				__libc_format_log(ANDROID_LOG_DEBUG, "libc", "used send_dg %d\n",n);
+			}
+
+			if (n < 0)
+				goto fail;
+			if (n == 0)
+				goto next_ns;
+			if (DBG) {
+				__libc_format_log(ANDROID_LOG_DEBUG, "libc", "time=%ld\n",
+                                                  time(NULL));
+			}
+			if (v_circuit)
+				goto same_ns;
+			resplen = n;
+		}
+
+		Dprint((statp->options & RES_DEBUG) ||
+		       ((statp->pfcode & RES_PRF_REPLY) &&
+			(statp->pfcode & RES_PRF_HEAD1)),
+		       (stdout, ";; got answer:\n"));
+
+		DprintQ((statp->options & RES_DEBUG) ||
+			(statp->pfcode & RES_PRF_REPLY),
+			(stdout, "%s", ""),
+			ans, (resplen > anssiz) ? anssiz : resplen);
+
+#if USE_RESOLV_CACHE
+                if (cache_status == RESOLV_CACHE_NOTFOUND) {
+                    _resolv_cache_add(statp->netid, buf, buflen,
+                                      ans, resplen);
+                }
+#endif
+		/*
+		 * If we have temporarily opened a virtual circuit,
+		 * or if we haven't been asked to keep a socket open,
+		 * close the socket.
+		 */
+		if ((v_circuit && (statp->options & RES_USEVC) == 0U) ||
+		    (statp->options & RES_STAYOPEN) == 0U) {
+			res_nclose(statp);
+		}
+		if (statp->rhook) {
+			int done = 0, loops = 0;
+
+			do {
+				res_sendhookact act;
+
+				act = (*statp->rhook)(nsap, buf, buflen,
+						      ans, anssiz, &resplen);
+				switch (act) {
+				case res_goahead:
+				case res_done:
+					done = 1;
+					break;
+				case res_nextns:
+					res_nclose(statp);
+					goto next_ns;
+				case res_modified:
+					/* give the hook another try */
+					if (++loops < 42) /*doug adams*/
+						break;
+					/*FALLTHROUGH*/
+				case res_error:
+					/*FALLTHROUGH*/
+				default:
+					goto fail;
+				}
+			} while (!done);
+
+		}
+		return (resplen);
+ next_ns: ;
+	   } /*foreach ns*/
+	} /*foreach retry*/
+	res_nclose(statp);
+	if (!v_circuit) {
+		if (!gotsomewhere)
+			errno = ECONNREFUSED;	/* no nameservers found */
+		else
+			errno = ETIMEDOUT;	/* no answer obtained */
+	} else
+		errno = terrno;
+
+#if USE_RESOLV_CACHE
+        _resolv_cache_query_failed(statp->netid, buf, buflen);
+#endif
+
+	return (-1);
+ fail:
+#if USE_RESOLV_CACHE
+	_resolv_cache_query_failed(statp->netid, buf, buflen);
+#endif
+	res_nclose(statp);
+	return (-1);
+}
+
+/* Private */
+
+static int
+get_salen(sa)
+	const struct sockaddr *sa;
+{
+
+#ifdef HAVE_SA_LEN
+	/* There are people do not set sa_len.  Be forgiving to them. */
+	if (sa->sa_len)
+		return (sa->sa_len);
+#endif
+
+	if (sa->sa_family == AF_INET)
+		return (sizeof(struct sockaddr_in));
+	else if (sa->sa_family == AF_INET6)
+		return (sizeof(struct sockaddr_in6));
+	else
+		return (0);	/* unknown, die on connect */
+}
+
+/*
+ * pick appropriate nsaddr_list for use.  see res_init() for initialization.
+ */
+static struct sockaddr *
+get_nsaddr(statp, n)
+	res_state statp;
+	size_t n;
+{
+
+	if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) {
+		/*
+		 * - EXT(statp).ext->nsaddrs[n] holds an address that is larger
+		 *   than struct sockaddr, and
+		 * - user code did not update statp->nsaddr_list[n].
+		 */
+		return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
+	} else {
+		/*
+		 * - user code updated statp->nsaddr_list[n], or
+		 * - statp->nsaddr_list[n] has the same content as
+		 *   EXT(statp).ext->nsaddrs[n].
+		 */
+		return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
+	}
+}
+
+static int get_timeout(const res_state statp, const int ns)
+{
+	int timeout = (statp->retrans << ns);
+	if (ns > 0) {
+		timeout /= statp->nscount;
+	}
+	if (timeout <= 0) {
+		timeout = 1;
+	}
+	if (DBG) {
+		__libc_format_log(ANDROID_LOG_DEBUG, "libc", "using timeout of %d sec\n", timeout);
+	}
+
+	return timeout;
+}
+
+static int
+send_vc(res_state statp,
+	const u_char *buf, int buflen, u_char *ans, int anssiz,
+	int *terrno, int ns)
+{
+	const HEADER *hp = (const HEADER *)(const void *)buf;
+	HEADER *anhp = (HEADER *)(void *)ans;
+	struct sockaddr *nsap;
+	int nsaplen;
+	int truncating, connreset, resplen, n;
+	struct iovec iov[2];
+	u_short len;
+	u_char *cp;
+	void *tmp;
+
+	if (DBG) {
+		__libc_format_log(ANDROID_LOG_DEBUG, "libc", "using send_vc\n");
+	}
+
+	nsap = get_nsaddr(statp, (size_t)ns);
+	nsaplen = get_salen(nsap);
+
+	connreset = 0;
+ same_ns:
+	truncating = 0;
+
+	/* Are we still talking to whom we want to talk to? */
+	if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
+		struct sockaddr_storage peer;
+		socklen_t size = sizeof peer;
+		unsigned old_mark;
+		socklen_t mark_size = sizeof(old_mark);
+		if (getpeername(statp->_vcsock,
+				(struct sockaddr *)(void *)&peer, &size) < 0 ||
+		    !sock_eq((struct sockaddr *)(void *)&peer, nsap) ||
+			getsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &old_mark, &mark_size) < 0 ||
+			old_mark != statp->_mark) {
+			res_nclose(statp);
+			statp->_flags &= ~RES_F_VC;
+		}
+	}
+
+	if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) {
+		if (statp->_vcsock >= 0)
+			res_nclose(statp);
+
+		statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0);
+		if (statp->_vcsock > highestFD) {
+			res_nclose(statp);
+			errno = ENOTSOCK;
+		}
+		if (statp->_vcsock < 0) {
+			switch (errno) {
+			case EPROTONOSUPPORT:
+#ifdef EPFNOSUPPORT
+			case EPFNOSUPPORT:
+#endif
+			case EAFNOSUPPORT:
+				Perror(statp, stderr, "socket(vc)", errno);
+				return (0);
+			default:
+				*terrno = errno;
+				Perror(statp, stderr, "socket(vc)", errno);
+				return (-1);
+			}
+		}
+		if (statp->_mark != MARK_UNSET) {
+			if (setsockopt(statp->_vcsock, SOL_SOCKET,
+				        SO_MARK, &statp->_mark, sizeof(statp->_mark)) < 0) {
+				*terrno = errno;
+				Perror(statp, stderr, "setsockopt", errno);
+				return -1;
+			}
+		}
+		errno = 0;
+		if (random_bind(statp->_vcsock,nsap->sa_family) < 0) {
+			*terrno = errno;
+			Aerror(statp, stderr, "bind/vc", errno, nsap,
+			    nsaplen);
+			res_nclose(statp);
+			return (0);
+		}
+		if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t)nsaplen,
+				get_timeout(statp, ns)) < 0) {
+			*terrno = errno;
+			Aerror(statp, stderr, "connect/vc", errno, nsap,
+			    nsaplen);
+			res_nclose(statp);
+			return (0);
+		}
+		statp->_flags |= RES_F_VC;
+	}
+
+	/*
+	 * Send length & message
+	 */
+	ns_put16((u_short)buflen, (u_char*)(void *)&len);
+	iov[0] = evConsIovec(&len, INT16SZ);
+	DE_CONST(buf, tmp);
+	iov[1] = evConsIovec(tmp, (size_t)buflen);
+	if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
+		*terrno = errno;
+		Perror(statp, stderr, "write failed", errno);
+		res_nclose(statp);
+		return (0);
+	}
+	/*
+	 * Receive length & response
+	 */
+ read_len:
+	cp = ans;
+	len = INT16SZ;
+	while ((n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0) {
+		cp += n;
+		if ((len -= n) == 0)
+			break;
+	}
+	if (n <= 0) {
+		*terrno = errno;
+		Perror(statp, stderr, "read failed", errno);
+		res_nclose(statp);
+		/*
+		 * A long running process might get its TCP
+		 * connection reset if the remote server was
+		 * restarted.  Requery the server instead of
+		 * trying a new one.  When there is only one
+		 * server, this means that a query might work
+		 * instead of failing.  We only allow one reset
+		 * per query to prevent looping.
+		 */
+		if (*terrno == ECONNRESET && !connreset) {
+			connreset = 1;
+			res_nclose(statp);
+			goto same_ns;
+		}
+		res_nclose(statp);
+		return (0);
+	}
+	resplen = ns_get16(ans);
+	if (resplen > anssiz) {
+		Dprint(statp->options & RES_DEBUG,
+		       (stdout, ";; response truncated\n")
+		       );
+		truncating = 1;
+		len = anssiz;
+	} else
+		len = resplen;
+	if (len < HFIXEDSZ) {
+		/*
+		 * Undersized message.
+		 */
+		Dprint(statp->options & RES_DEBUG,
+		       (stdout, ";; undersized: %d\n", len));
+		*terrno = EMSGSIZE;
+		res_nclose(statp);
+		return (0);
+	}
+	cp = ans;
+	while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0){
+		cp += n;
+		len -= n;
+	}
+	if (n <= 0) {
+		*terrno = errno;
+		Perror(statp, stderr, "read(vc)", errno);
+		res_nclose(statp);
+		return (0);
+	}
+	if (truncating) {
+		/*
+		 * Flush rest of answer so connection stays in synch.
+		 */
+		anhp->tc = 1;
+		len = resplen - anssiz;
+		while (len != 0) {
+			char junk[PACKETSZ];
+
+			n = read(statp->_vcsock, junk,
+				 (len > sizeof junk) ? sizeof junk : len);
+			if (n > 0)
+				len -= n;
+			else
+				break;
+		}
+	}
+	/*
+	 * If the calling applicating has bailed out of
+	 * a previous call and failed to arrange to have
+	 * the circuit closed or the server has got
+	 * itself confused, then drop the packet and
+	 * wait for the correct one.
+	 */
+	if (hp->id != anhp->id) {
+		DprintQ((statp->options & RES_DEBUG) ||
+			(statp->pfcode & RES_PRF_REPLY),
+			(stdout, ";; old answer (unexpected):\n"),
+			ans, (resplen > anssiz) ? anssiz: resplen);
+		goto read_len;
+	}
+
+	/*
+	 * All is well, or the error is fatal.  Signal that the
+	 * next nameserver ought not be tried.
+	 */
+	return (resplen);
+}
+
+/* return -1 on error (errno set), 0 on success */
+static int
+connect_with_timeout(int sock, const struct sockaddr *nsap, socklen_t salen, int sec)
+{
+	int res, origflags;
+	fd_set rset, wset;
+	struct timespec now, timeout, finish;
+
+	origflags = fcntl(sock, F_GETFL, 0);
+	fcntl(sock, F_SETFL, origflags | O_NONBLOCK);
+
+	res = __connect(sock, nsap, salen);
+	if (res < 0 && errno != EINPROGRESS) {
+                res = -1;
+                goto done;
+	}
+	if (res != 0) {
+		now = evNowTime();
+		timeout = evConsTime((long)sec, 0L);
+		finish = evAddTime(now, timeout);
+		if (DBG) {
+			__libc_format_log(ANDROID_LOG_DEBUG, "libc", "  %d send_vc\n", sock);
+		}
+
+		res = retrying_select(sock, &rset, &wset, &finish);
+		if (res <= 0) {
+                        res = -1;
+		}
+	}
+done:
+	fcntl(sock, F_SETFL, origflags);
+	if (DBG) {
+		__libc_format_log(ANDROID_LOG_DEBUG, "libc",
+			"  %d connect_with_timeout returning %d\n", sock, res);
+	}
+	return res;
+}
+
+static int
+retrying_select(const int sock, fd_set *readset, fd_set *writeset, const struct timespec *finish)
+{
+	struct timespec now, timeout;
+	int n, error;
+	socklen_t len;
+
+
+retry:
+	if (DBG) {
+		__libc_format_log(ANDROID_LOG_DEBUG, "libc", "  %d retying_select\n", sock);
+	}
+
+	now = evNowTime();
+	if (readset) {
+		FD_ZERO(readset);
+		FD_SET(sock, readset);
+	}
+	if (writeset) {
+		FD_ZERO(writeset);
+		FD_SET(sock, writeset);
+	}
+	if (evCmpTime(*finish, now) > 0)
+		timeout = evSubTime(*finish, now);
+	else
+		timeout = evConsTime(0L, 0L);
+
+	n = pselect(sock + 1, readset, writeset, NULL, &timeout, NULL);
+	if (n == 0) {
+		if (DBG) {
+			__libc_format_log(ANDROID_LOG_DEBUG, " libc",
+				"  %d retrying_select timeout\n", sock);
+		}
+		errno = ETIMEDOUT;
+		return 0;
+	}
+	if (n < 0) {
+		if (errno == EINTR)
+			goto retry;
+		if (DBG) {
+			__libc_format_log(ANDROID_LOG_DEBUG, "libc",
+				"  %d retrying_select got error %d\n",sock, n);
+		}
+		return n;
+	}
+	if ((readset && FD_ISSET(sock, readset)) || (writeset && FD_ISSET(sock, writeset))) {
+		len = sizeof(error);
+		if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
+			errno = error;
+			if (DBG) {
+				__libc_format_log(ANDROID_LOG_DEBUG, "libc",
+					"  %d retrying_select dot error2 %d\n", sock, errno);
+			}
+
+			return -1;
+		}
+	}
+	if (DBG) {
+		__libc_format_log(ANDROID_LOG_DEBUG, "libc",
+			"  %d retrying_select returning %d\n",sock, n);
+	}
+
+	return n;
+}
+
+
+static int
+send_dg(res_state statp,
+	const u_char *buf, int buflen, u_char *ans, int anssiz,
+	int *terrno, int ns, int *v_circuit, int *gotsomewhere)
+{
+	const HEADER *hp = (const HEADER *)(const void *)buf;
+	HEADER *anhp = (HEADER *)(void *)ans;
+	const struct sockaddr *nsap;
+	int nsaplen;
+	struct timespec now, timeout, finish;
+	fd_set dsmask;
+	struct sockaddr_storage from;
+	socklen_t fromlen;
+	int resplen, seconds, n, s;
+
+	nsap = get_nsaddr(statp, (size_t)ns);
+	nsaplen = get_salen(nsap);
+	if (EXT(statp).nssocks[ns] == -1) {
+		EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+		if (EXT(statp).nssocks[ns] > highestFD) {
+			res_nclose(statp);
+			errno = ENOTSOCK;
+		}
+		if (EXT(statp).nssocks[ns] < 0) {
+			switch (errno) {
+			case EPROTONOSUPPORT:
+#ifdef EPFNOSUPPORT
+			case EPFNOSUPPORT:
+#endif
+			case EAFNOSUPPORT:
+				Perror(statp, stderr, "socket(dg)", errno);
+				return (0);
+			default:
+				*terrno = errno;
+				Perror(statp, stderr, "socket(dg)", errno);
+				return (-1);
+			}
+		}
+
+		if (statp->_mark != MARK_UNSET) {
+			if (setsockopt(EXT(statp).nssocks[ns], SOL_SOCKET,
+					SO_MARK, &(statp->_mark), sizeof(statp->_mark)) < 0) {
+				res_nclose(statp);
+				return -1;
+			}
+		}
+#ifndef CANNOT_CONNECT_DGRAM
+		/*
+		 * On a 4.3BSD+ machine (client and server,
+		 * actually), sending to a nameserver datagram
+		 * port with no nameserver will cause an
+		 * ICMP port unreachable message to be returned.
+		 * If our datagram socket is "connected" to the
+		 * server, we get an ECONNREFUSED error on the next
+		 * socket operation, and select returns if the
+		 * error message is received.  We can thus detect
+		 * the absence of a nameserver without timing out.
+		 */
+		if (random_bind(EXT(statp).nssocks[ns], nsap->sa_family) < 0) {
+			Aerror(statp, stderr, "bind(dg)", errno, nsap,
+			    nsaplen);
+			res_nclose(statp);
+			return (0);
+		}
+		if (__connect(EXT(statp).nssocks[ns], nsap, (socklen_t)nsaplen) < 0) {
+			Aerror(statp, stderr, "connect(dg)", errno, nsap,
+			    nsaplen);
+			res_nclose(statp);
+			return (0);
+		}
+#endif /* !CANNOT_CONNECT_DGRAM */
+		Dprint(statp->options & RES_DEBUG,
+		       (stdout, ";; new DG socket\n"))
+
+	}
+	s = EXT(statp).nssocks[ns];
+#ifndef CANNOT_CONNECT_DGRAM
+	if (send(s, (const char*)buf, (size_t)buflen, 0) != buflen) {
+		Perror(statp, stderr, "send", errno);
+		res_nclose(statp);
+		return (0);
+	}
+#else /* !CANNOT_CONNECT_DGRAM */
+	if (sendto(s, (const char*)buf, buflen, 0, nsap, nsaplen) != buflen)
+	{
+		Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
+		res_nclose(statp);
+		return (0);
+	}
+#endif /* !CANNOT_CONNECT_DGRAM */
+
+	/*
+	 * Wait for reply.
+	 */
+	seconds = get_timeout(statp, ns);
+	now = evNowTime();
+	timeout = evConsTime((long)seconds, 0L);
+	finish = evAddTime(now, timeout);
+retry:
+	n = retrying_select(s, &dsmask, NULL, &finish);
+
+	if (n == 0) {
+		Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
+		*gotsomewhere = 1;
+		return (0);
+	}
+	if (n < 0) {
+		Perror(statp, stderr, "select", errno);
+		res_nclose(statp);
+		return (0);
+	}
+	errno = 0;
+	fromlen = sizeof(from);
+	resplen = recvfrom(s, (char*)ans, (size_t)anssiz,0,
+			   (struct sockaddr *)(void *)&from, &fromlen);
+	if (resplen <= 0) {
+		Perror(statp, stderr, "recvfrom", errno);
+		res_nclose(statp);
+		return (0);
+	}
+	*gotsomewhere = 1;
+	if (resplen < HFIXEDSZ) {
+		/*
+		 * Undersized message.
+		 */
+		Dprint(statp->options & RES_DEBUG,
+		       (stdout, ";; undersized: %d\n",
+			resplen));
+		*terrno = EMSGSIZE;
+		res_nclose(statp);
+		return (0);
+	}
+	if (hp->id != anhp->id) {
+		/*
+		 * response from old query, ignore it.
+		 * XXX - potential security hazard could
+		 *	 be detected here.
+		 */
+#ifdef ANDROID_CHANGES
+		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_OLD_RESPONSE);
+#endif
+		DprintQ((statp->options & RES_DEBUG) ||
+			(statp->pfcode & RES_PRF_REPLY),
+			(stdout, ";; old answer:\n"),
+			ans, (resplen > anssiz) ? anssiz : resplen);
+		goto retry;
+	}
+	if (!(statp->options & RES_INSECURE1) &&
+	    !res_ourserver_p(statp, (struct sockaddr *)(void *)&from)) {
+		/*
+		 * response from wrong server? ignore it.
+		 * XXX - potential security hazard could
+		 *	 be detected here.
+		 */
+#ifdef ANDROID_CHANGES
+		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_WRONG_SERVER);
+#endif
+		DprintQ((statp->options & RES_DEBUG) ||
+			(statp->pfcode & RES_PRF_REPLY),
+			(stdout, ";; not our server:\n"),
+			ans, (resplen > anssiz) ? anssiz : resplen);
+		goto retry;
+	}
+#ifdef RES_USE_EDNS0
+	if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
+		/*
+		 * Do not retry if the server do not understand EDNS0.
+		 * The case has to be captured here, as FORMERR packet do not
+		 * carry query section, hence res_queriesmatch() returns 0.
+		 */
+		DprintQ(statp->options & RES_DEBUG,
+			(stdout, "server rejected query with EDNS0:\n"),
+			ans, (resplen > anssiz) ? anssiz : resplen);
+		/* record the error */
+		statp->_flags |= RES_F_EDNS0ERR;
+		res_nclose(statp);
+		return (0);
+	}
+#endif
+	if (!(statp->options & RES_INSECURE2) &&
+	    !res_queriesmatch(buf, buf + buflen,
+			      ans, ans + anssiz)) {
+		/*
+		 * response contains wrong query? ignore it.
+		 * XXX - potential security hazard could
+		 *	 be detected here.
+		 */
+#ifdef ANDROID_CHANGES
+		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_WRONG_QUERY);
+#endif
+		DprintQ((statp->options & RES_DEBUG) ||
+			(statp->pfcode & RES_PRF_REPLY),
+			(stdout, ";; wrong query name:\n"),
+			ans, (resplen > anssiz) ? anssiz : resplen);
+		goto retry;;
+	}
+	if (anhp->rcode == SERVFAIL ||
+	    anhp->rcode == NOTIMP ||
+	    anhp->rcode == REFUSED) {
+		DprintQ(statp->options & RES_DEBUG,
+			(stdout, "server rejected query:\n"),
+			ans, (resplen > anssiz) ? anssiz : resplen);
+		res_nclose(statp);
+		/* don't retry if called from dig */
+		if (!statp->pfcode)
+			return (0);
+	}
+	if (!(statp->options & RES_IGNTC) && anhp->tc) {
+		/*
+		 * To get the rest of answer,
+		 * use TCP with same server.
+		 */
+		Dprint(statp->options & RES_DEBUG,
+		       (stdout, ";; truncated answer\n"));
+		*v_circuit = 1;
+		res_nclose(statp);
+		return (1);
+	}
+	/*
+	 * All is well, or the error is fatal.  Signal that the
+	 * next nameserver ought not be tried.
+	 */
+	return (resplen);
+}
+
+static void
+Aerror(const res_state statp, FILE *file, const char *string, int error,
+       const struct sockaddr *address, int alen)
+{
+	int save = errno;
+	char hbuf[NI_MAXHOST];
+	char sbuf[NI_MAXSERV];
+
+	if ((statp->options & RES_DEBUG) != 0U) {
+		if (getnameinfo(address, (socklen_t)alen, hbuf, sizeof(hbuf),
+		    sbuf, sizeof(sbuf), niflags)) {
+			strncpy(hbuf, "?", sizeof(hbuf) - 1);
+			hbuf[sizeof(hbuf) - 1] = '\0';
+			strncpy(sbuf, "?", sizeof(sbuf) - 1);
+			sbuf[sizeof(sbuf) - 1] = '\0';
+		}
+		fprintf(file, "res_send: %s ([%s].%s): %s\n",
+			string, hbuf, sbuf, strerror(error));
+	}
+	errno = save;
+}
+
+static void
+Perror(const res_state statp, FILE *file, const char *string, int error) {
+	int save = errno;
+
+	if ((statp->options & RES_DEBUG) != 0U)
+		fprintf(file, "res_send: %s: %s\n",
+			string, strerror(error));
+	errno = save;
+}
+
+static int
+sock_eq(struct sockaddr *a, struct sockaddr *b) {
+	struct sockaddr_in *a4, *b4;
+	struct sockaddr_in6 *a6, *b6;
+
+	if (a->sa_family != b->sa_family)
+		return 0;
+	switch (a->sa_family) {
+	case AF_INET:
+		a4 = (struct sockaddr_in *)(void *)a;
+		b4 = (struct sockaddr_in *)(void *)b;
+		return a4->sin_port == b4->sin_port &&
+		    a4->sin_addr.s_addr == b4->sin_addr.s_addr;
+	case AF_INET6:
+		a6 = (struct sockaddr_in6 *)(void *)a;
+		b6 = (struct sockaddr_in6 *)(void *)b;
+		return a6->sin6_port == b6->sin6_port &&
+#ifdef HAVE_SIN6_SCOPE_ID
+		    a6->sin6_scope_id == b6->sin6_scope_id &&
+#endif
+		    IN6_ARE_ADDR_EQUAL(&a6->sin6_addr, &b6->sin6_addr);
+	default:
+		return 0;
+	}
+}
+
+#ifdef NEED_PSELECT
+/* XXX needs to move to the porting library. */
+static int
+pselect(int nfds, void *rfds, void *wfds, void *efds,
+	struct timespec *tsp, const sigset_t *sigmask)
+{
+	struct timeval tv, *tvp;
+	sigset_t sigs;
+	int n;
+
+	if (tsp) {
+		tvp = &tv;
+		tv = evTimeVal(*tsp);
+	} else
+		tvp = NULL;
+	if (sigmask)
+		sigprocmask(SIG_SETMASK, sigmask, &sigs);
+	n = select(nfds, rfds, wfds, efds, tvp);
+	if (sigmask)
+		sigprocmask(SIG_SETMASK, &sigs, NULL);
+	if (tsp)
+		*tsp = evTimeSpec(tv);
+	return (n);
+}
+#endif
diff --git a/libc/dns/resolv/res_state.c b/libc/dns/resolv/res_state.c
new file mode 100644
index 0000000..57791d1
--- /dev/null
+++ b/libc/dns/resolv/res_state.c
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include "resolv_private.h"
+#include "resolv_cache.h"
+#include <pthread.h>
+#include <stdlib.h>
+
+#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
+#include <sys/_system_properties.h>
+
+/* Set to 1 to enable debug traces */
+#define DEBUG 0
+
+#if DEBUG
+#  include "private/libc_logging.h"
+#  include <unistd.h>  /* for gettid() */
+#  define D(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc", __VA_ARGS__)
+#else
+#  define D(...)  do{}while(0)
+#endif
+
+static pthread_key_t   _res_key;
+static pthread_once_t  _res_once = PTHREAD_ONCE_INIT;
+
+typedef struct {
+    int                  _h_errno;
+    // TODO: Have one __res_state per network so we don't have to repopulate frequently.
+    struct __res_state  _nres[1];
+    unsigned             _serial;
+    struct prop_info*   _pi;
+    struct res_static   _rstatic[1];
+} _res_thread;
+
+static _res_thread*
+_res_thread_alloc(void)
+{
+    _res_thread*  rt = calloc(1, sizeof(*rt));
+
+    if (rt) {
+        rt->_h_errno = 0;
+        /* Special system property which tracks any changes to 'net.*'. */
+        rt->_serial = 0;
+        rt->_pi = (struct prop_info*) __system_property_find("net.change");
+        if (rt->_pi) {
+            rt->_serial = __system_property_serial(rt->_pi);
+        }
+        memset(rt->_rstatic, 0, sizeof rt->_rstatic);
+    }
+    return rt;
+}
+
+static void
+_res_static_done( res_static  rs )
+{
+    /* fortunately, there is nothing to do here, since the
+     * points in h_addr_ptrs and host_aliases should all
+     * point to 'hostbuf'
+     */
+    if (rs->hostf) {  /* should not happen in theory, but just be safe */
+        fclose(rs->hostf);
+        rs->hostf = NULL;
+    }
+    free(rs->servent.s_aliases);
+}
+
+static void
+_res_thread_free( void*  _rt )
+{
+    _res_thread*  rt = _rt;
+
+    D("%s: rt=%p for thread=%d", __FUNCTION__, rt, gettid());
+
+    _res_static_done(rt->_rstatic);
+    res_ndestroy(rt->_nres);
+    free(rt);
+}
+
+static void
+_res_init_key( void )
+{
+    pthread_key_create( &_res_key, _res_thread_free );
+}
+
+static _res_thread*
+_res_thread_get(void)
+{
+    _res_thread*  rt;
+    pthread_once( &_res_once, _res_init_key );
+    rt = pthread_getspecific( _res_key );
+
+    if (rt != NULL) {
+        /* We already have one thread-specific DNS state object.
+         * Check the serial value for any changes to net.* properties */
+        D("%s: Called for tid=%d rt=%p rt->pi=%p rt->serial=%d",
+           __FUNCTION__, gettid(), rt, rt->_pi, rt->_serial);
+        if (rt->_pi == NULL) {
+            /* The property wasn't created when _res_thread_get() was
+             * called the last time. This should only happen very
+             * early during the boot sequence. First, let's try to see if it
+             * is here now. */
+            rt->_pi = (struct prop_info*) __system_property_find("net.change");
+            if (rt->_pi == NULL) {
+                /* Still nothing, return current state */
+                D("%s: exiting for tid=%d rt=%d since system property not found",
+                  __FUNCTION__, gettid(), rt);
+                return rt;
+            }
+        }
+        if (rt->_serial == __system_property_serial(rt->_pi)) {
+            /* Nothing changed, so return the current state */
+            D("%s: tid=%d rt=%p nothing changed, returning",
+              __FUNCTION__, gettid(), rt);
+            return rt;
+        }
+        /* Update the recorded serial number, and go reset the state */
+        rt->_serial = __system_property_serial(rt->_pi);
+        goto RESET_STATE;
+    }
+
+    /* It is the first time this function is called in this thread,
+     * we need to create a new thread-specific DNS resolver state. */
+    rt = _res_thread_alloc();
+    if (rt == NULL) {
+        return NULL;
+    }
+    pthread_setspecific( _res_key, rt );
+    D("%s: tid=%d Created new DNS state rt=%p",
+      __FUNCTION__, gettid(), rt);
+
+RESET_STATE:
+    /* Reset the state, note that res_ninit() can now properly reset
+     * an existing state without leaking memory.
+     */
+    D("%s: tid=%d, rt=%p, resetting DNS state (options RES_INIT=%d)",
+      __FUNCTION__, gettid(), rt, (rt->_nres->options & RES_INIT) != 0);
+    if ( res_ninit( rt->_nres ) < 0 ) {
+        /* This should not happen */
+        D("%s: tid=%d rt=%p, woot, res_ninit() returned < 0",
+          __FUNCTION__, gettid(), rt);
+        _res_thread_free(rt);
+        pthread_setspecific( _res_key, NULL );
+        return NULL;
+    }
+    return rt;
+}
+
+__LIBC_HIDDEN__
+struct __res_state _nres;
+
+#if 0
+struct resolv_cache*
+__get_res_cache(void)
+{
+    _res_thread*  rt = _res_thread_get();
+
+    if (!rt)
+        return NULL;
+
+    if (!rt->_cache) {
+        rt->_cache = _resolv_cache_create();
+    }
+    return rt->_cache;
+}
+#endif
+
+int*
+__get_h_errno(void)
+{
+    _res_thread*  rt    = _res_thread_get();
+    static int    panic = NETDB_INTERNAL;
+
+    return rt ? &rt->_h_errno : &panic;
+}
+
+res_state
+__res_get_state(void)
+{
+    _res_thread*  rt = _res_thread_get();
+
+    return rt ? rt->_nres : NULL;
+}
+
+void
+__res_put_state(res_state res __unused)
+{
+    /* nothing to do */
+}
+
+res_static
+__res_get_static(void)
+{
+    _res_thread*  rt = _res_thread_get();
+
+    return rt ? rt->_rstatic : NULL;
+}
diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h
index 611fdfb..2d2f096 100644
--- a/libc/include/android/api-level.h
+++ b/libc/include/android/api-level.h
@@ -25,9 +25,14 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef ANDROID_API_LEVEL_H
 #define ANDROID_API_LEVEL_H
 
-#define __ANDROID_API__ 10
+/*
+ * Magic version number for a current development build, which has
+ * not yet turned into an official release.
+ */
+#define __ANDROID_API__ 10000
 
 #endif /* ANDROID_API_LEVEL_H */
diff --git a/libc/include/android/dlext.h b/libc/include/android/dlext.h
new file mode 100644
index 0000000..5c3a206
--- /dev/null
+++ b/libc/include/android/dlext.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ANDROID_DLEXT_H__
+#define __ANDROID_DLEXT_H__
+
+#include <stddef.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+/* bitfield definitions for android_dlextinfo.flags */
+enum {
+  /* When set, the reserved_addr and reserved_size fields must point to an
+   * already-reserved region of address space which will be used to load the
+   * library if it fits. If the reserved region is not large enough, the load
+   * will fail.
+   */
+  ANDROID_DLEXT_RESERVED_ADDRESS      = 0x1,
+
+  /* As DLEXT_RESERVED_ADDRESS, but if the reserved region is not large enough,
+   * the linker will choose an available address instead.
+   */
+  ANDROID_DLEXT_RESERVED_ADDRESS_HINT = 0x2,
+
+  /* When set, write the GNU RELRO section of the mapped library to relro_fd
+   * after relocation has been performed, to allow it to be reused by another
+   * process loading the same library at the same address. This implies
+   * ANDROID_DLEXT_USE_RELRO.
+   */
+  ANDROID_DLEXT_WRITE_RELRO           = 0x4,
+
+  /* When set, compare the GNU RELRO section of the mapped library to relro_fd
+   * after relocation has been performed, and replace any relocated pages that
+   * are identical with a version mapped from the file.
+   */
+  ANDROID_DLEXT_USE_RELRO             = 0x8,
+
+  /* Instruct dlopen to use library_fd instead of opening file by name.
+   * The filename parameter is still used to identify the library.
+   */
+  ANDROID_DLEXT_USE_LIBRARY_FD        = 0x10,
+
+  /* Mask of valid bits */
+  ANDROID_DLEXT_VALID_FLAG_BITS       = ANDROID_DLEXT_RESERVED_ADDRESS |
+                                        ANDROID_DLEXT_RESERVED_ADDRESS_HINT |
+                                        ANDROID_DLEXT_WRITE_RELRO |
+                                        ANDROID_DLEXT_USE_RELRO |
+                                        ANDROID_DLEXT_USE_LIBRARY_FD,
+};
+
+typedef struct {
+  uint64_t flags;
+  void*   reserved_addr;
+  size_t  reserved_size;
+  int     relro_fd;
+  int     library_fd;
+} android_dlextinfo;
+
+extern void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo);
+
+__END_DECLS
+
+#endif /* __ANDROID_DLEXT_H__ */
diff --git a/libc/include/android/set_abort_message.h b/libc/include/android/set_abort_message.h
new file mode 100644
index 0000000..4b3d82b
--- /dev/null
+++ b/libc/include/android/set_abort_message.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SET_ABORT_MESSAGE_H
+#define _SET_ABORT_MESSAGE_H
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+void android_set_abort_message(const char* msg);
+
+__END_DECLS
+
+#endif // _SET_ABORT_MESSAGE_H
diff --git a/libc/include/arpa/inet.h b/libc/include/arpa/inet.h
index b008812..067be1f 100644
--- a/libc/include/arpa/inet.h
+++ b/libc/include/arpa/inet.h
@@ -36,19 +36,18 @@
 
 typedef uint32_t in_addr_t;
 
-extern uint32_t      inet_addr(const char *);
-
-extern int           inet_aton(const char *, struct in_addr *);
-extern char*         inet_ntoa(struct in_addr);
-
-extern int           inet_pton(int, const char *, void *);
-extern const char*   inet_ntop(int, const void *, char *, socklen_t);
-
-extern unsigned int  inet_nsap_addr(const char *, unsigned char *, int);
-extern char*         inet_nsap_ntoa(int, const unsigned char *, char *);
+in_addr_t inet_addr(const char*);
+int inet_aton(const char*, struct in_addr*);
+in_addr_t inet_lnaof(struct in_addr);
+struct in_addr inet_makeaddr(in_addr_t, in_addr_t);
+in_addr_t inet_netof(struct in_addr);
+in_addr_t inet_network(const char*);
+char* inet_ntoa(struct in_addr);
+const char* inet_ntop(int, const void*, char*, socklen_t);
+unsigned int inet_nsap_addr(const char*, unsigned char*, int);
+char* inet_nsap_ntoa(int, const unsigned char*, char*);
+int inet_pton(int, const char*, void*);
 
 __END_DECLS
 
 #endif /* _ARPA_INET_H_ */
-
-
diff --git a/libc/include/arpa/nameser.h b/libc/include/arpa/nameser.h
index 028eadc..a87ac91 100644
--- a/libc/include/arpa/nameser.h
+++ b/libc/include/arpa/nameser.h
@@ -1,41 +1,668 @@
+/*	$NetBSD: nameser.h,v 1.25 2009/04/12 17:07:34 christos Exp $	*/
+
 /*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
+ * Portions Copyright (C) 2004, 2005, 2008, 2009  Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (C) 1996-2003  Internet Software Consortium.
+ *
+ * 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 ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+/*
+ * Copyright (c) 1983, 1989, 1993
+ *    The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
- *  * Redistributions of source code must retain the above copyright
+ * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _arpa_nameser_h
-#define _arpa_nameser_h
+
+/*
+ *	Id: nameser.h,v 1.16 2009/03/03 01:52:48 each Exp
+ */
+
+#ifndef _ARPA_NAMESER_H_
+#define _ARPA_NAMESER_H_
+
+#define BIND_4_COMPAT
 
 #include <sys/types.h>
 #include <sys/cdefs.h>
 
-/* this header intentionally blank
- *
- * the definitions normally found in <arpa/nameser.h> are
- * really a bunch of resolver's internal declarations that
- * should not be exposed to client code in any way
+/*
+ * Revision information.  This is the release date in YYYYMMDD format.
+ * It can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__NAMESER > 19931104)".  Do not
+ * compare for equality; rather, use it to determine whether your libbind.a
+ * contains a new enough lib/nameser/ to support the feature you need.
  */
 
-#endif /* _arpa_nameser_h */
+#define __NAMESER	20090302	/*%< New interface version stamp. */
+
+/*
+ * Define constants based on RFC0883, RFC1034, RFC 1035
+ */
+#define NS_PACKETSZ	512	/* default UDP packet size */
+#define NS_MAXDNAME	1025	/* maximum domain name (presentation format)*/
+#define NS_MAXMSG	65535	/* maximum message size */
+#define NS_MAXCDNAME	255	/* maximum compressed domain name */
+#define NS_MAXLABEL	63	/* maximum length of domain label */
+#define NS_MAXLABELS	128	/* theoretical max #/labels per domain name */
+#define NS_MAXNNAME	256	/* maximum uncompressed (binary) domain name*/
+#define	NS_MAXPADDR	(sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
+#define NS_HFIXEDSZ	12	/* #/bytes of fixed data in header */
+#define NS_QFIXEDSZ	4	/* #/bytes of fixed data in query */
+#define NS_RRFIXEDSZ	10	/* #/bytes of fixed data in r record */
+#define NS_INT32SZ	4	/* #/bytes of data in a uint32_t */
+#define NS_INT16SZ	2	/* #/bytes of data in a uint16_t */
+#define NS_INT8SZ	1	/* #/bytes of data in a uint8_t */
+#define NS_INADDRSZ	4	/* IPv4 T_A */
+#define NS_IN6ADDRSZ	16	/* IPv6 T_AAAA */
+#define NS_CMPRSFLGS	0xc0	/* Flag bits indicating name compression. */
+#define NS_DEFAULTPORT	53	/* For both TCP and UDP. */
+
+/*
+ * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
+ * in synch with it.
+ */
+typedef enum __ns_sect {
+	ns_s_qd = 0,		/* Query: Question. */
+	ns_s_zn = 0,		/* Update: Zone. */
+	ns_s_an = 1,		/* Query: Answer. */
+	ns_s_pr = 1,		/* Update: Prerequisites. */
+	ns_s_ns = 2,		/* Query: Name servers. */
+	ns_s_ud = 2,		/* Update: Update. */
+	ns_s_ar = 3,		/* Query|Update: Additional records. */
+	ns_s_max = 4
+} ns_sect;
+
+/*
+ * Network name (compressed or not) type.  Equivilent to a pointer when used
+ * in a function prototype.  Can be const'd.
+ */
+typedef u_char ns_nname[NS_MAXNNAME];
+typedef const u_char *ns_nname_ct;
+typedef u_char *ns_nname_t;
+
+struct ns_namemap { ns_nname_ct base; int len; };
+typedef struct ns_namemap *ns_namemap_t;
+typedef const struct ns_namemap *ns_namemap_ct;
+
+/*
+ * This is a message handle.  It is caller allocated and has no dynamic data.
+ * This structure is intended to be opaque to all but ns_parse.c, thus the
+ * leading _'s on the member names.  Use the accessor functions, not the _'s.
+ */
+typedef struct __ns_msg {
+	const u_char	*_msg, *_eom;
+	uint16_t	_id, _flags, _counts[ns_s_max];
+	const u_char	*_sections[ns_s_max];
+	ns_sect		_sect;
+	int		_rrnum;
+	const u_char	*_msg_ptr;
+} ns_msg;
+/*
+ * This is a newmsg handle, used when constructing new messages with
+ * ns_newmsg_init, et al.
+ */
+struct ns_newmsg {
+	ns_msg		msg;
+	const u_char	*dnptrs[25];
+	const u_char	**lastdnptr;
+};
+typedef struct ns_newmsg ns_newmsg;
+
+/* Private data structure - do not use from outside library. */
+struct _ns_flagdata {  int mask, shift;  };
+extern const struct _ns_flagdata _ns_flagdata[];
+
+/* Accessor macros - this is part of the public interface. */
+
+#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) ((size_t)((handle)._eom - (handle)._msg))
+#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
+
+/*
+ * This is a parsed record.  It is caller allocated and has no dynamic data.
+ */
+typedef	struct __ns_rr {
+	char		name[NS_MAXDNAME];
+	uint16_t	type;
+	uint16_t	rr_class;
+	uint32_t	ttl;
+	uint16_t	rdlength;
+	const u_char *	rdata;
+} ns_rr;
+
+/*
+ * Same thing, but using uncompressed network binary names, and real C types.
+ */
+typedef	struct __ns_rr2 {
+	ns_nname	nname;
+	size_t		nnamel;
+	int		type;
+	int		rr_class;
+	u_int		ttl;
+	int		rdlength;
+	const u_char *	rdata;
+} ns_rr2;
+/* Accessor macros - this is part of the public interface. */
+#define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
+#define ns_rr_nname(rr)	((const ns_nname_t)(rr).nname)
+#define ns_rr_nnamel(rr) ((rr).nnamel + 0)
+#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)	((u_long)(rr).ttl + 0)
+#define ns_rr_rdlen(rr)	((size_t)(rr).rdlength + 0)
+#define ns_rr_rdata(rr)	((rr).rdata + 0)
+
+/*
+ * These don't have to be in the same order as in the packet flags word,
+ * and they can even overlap in some cases, but they will need to be kept
+ * in synch with ns_parse.c:ns_flagdata[].
+ */
+typedef enum __ns_flag {
+	ns_f_qr,		/* Question/Response. */
+	ns_f_opcode,		/* Operation code. */
+	ns_f_aa,		/* Authoritative Answer. */
+	ns_f_tc,		/* Truncation occurred. */
+	ns_f_rd,		/* Recursion Desired. */
+	ns_f_ra,		/* Recursion Available. */
+	ns_f_z,			/* MBZ. */
+	ns_f_ad,		/* Authentic Data (DNSSEC). */
+	ns_f_cd,		/* Checking Disabled (DNSSEC). */
+	ns_f_rcode,		/* Response code. */
+	ns_f_max
+} ns_flag;
+
+/*
+ * Currently defined opcodes.
+ */
+typedef enum __ns_opcode {
+	ns_o_query = 0,		/* Standard query. */
+	ns_o_iquery = 1,	/* Inverse query (deprecated/unsupported). */
+	ns_o_status = 2,	/* Name server status query (unsupported). */
+				/* Opcode 3 is undefined/reserved. */
+	ns_o_notify = 4,	/* Zone change notification. */
+	ns_o_update = 5,	/* Zone update message. */
+	ns_o_max = 6
+} ns_opcode;
+
+/*
+ * Currently defined response codes.
+ */
+typedef	enum __ns_rcode {
+	ns_r_noerror = 0,	/* No error occurred. */
+	ns_r_formerr = 1,	/* Format error. */
+	ns_r_servfail = 2,	/* Server failure. */
+	ns_r_nxdomain = 3,	/* Name error. */
+	ns_r_notimpl = 4,	/* Unimplemented. */
+	ns_r_refused = 5,	/* Operation refused. */
+	/* these are for BIND_UPDATE */
+	ns_r_yxdomain = 6,	/* Name exists */
+	ns_r_yxrrset = 7,	/* RRset exists */
+	ns_r_nxrrset = 8,	/* RRset does not exist */
+	ns_r_notauth = 9,	/* Not authoritative for zone */
+	ns_r_notzone = 10,	/* Zone of record different from zone section */
+	ns_r_max = 11,
+	/* The following are EDNS extended rcodes */
+	ns_r_badvers = 16,
+	/* The following are TSIG errors */
+	ns_r_badsig = 16,
+	ns_r_badkey = 17,
+	ns_r_badtime = 18
+} ns_rcode;
+
+/* BIND_UPDATE */
+typedef enum __ns_update_operation {
+	ns_uop_delete = 0,
+	ns_uop_add = 1,
+	ns_uop_max = 2
+} ns_update_operation;
+
+/*
+ * This structure is used for TSIG authenticated messages
+ */
+struct ns_tsig_key {
+        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
+        unsigned char *data;
+        int len;
+};
+typedef struct ns_tsig_key ns_tsig_key;
+
+/*
+ * This structure is used for TSIG authenticated TCP messages
+ */
+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
+
+/*
+ * Currently defined type values for resources and queries.
+ */
+typedef enum __ns_type {
+	ns_t_invalid = 0,	/* Cookie. */
+	ns_t_a = 1,		/* Host address. */
+	ns_t_ns = 2,		/* Authoritative server. */
+	ns_t_md = 3,		/* Mail destination. */
+	ns_t_mf = 4,		/* Mail forwarder. */
+	ns_t_cname = 5,		/* Canonical name. */
+	ns_t_soa = 6,		/* Start of authority zone. */
+	ns_t_mb = 7,		/* Mailbox domain name. */
+	ns_t_mg = 8,		/* Mail group member. */
+	ns_t_mr = 9,		/* Mail rename name. */
+	ns_t_null = 10,		/* Null resource record. */
+	ns_t_wks = 11,		/* Well known service. */
+	ns_t_ptr = 12,		/* Domain name pointer. */
+	ns_t_hinfo = 13,	/* Host information. */
+	ns_t_minfo = 14,	/* Mailbox information. */
+	ns_t_mx = 15,		/* Mail routing information. */
+	ns_t_txt = 16,		/* Text strings. */
+	ns_t_rp = 17,		/* Responsible person. */
+	ns_t_afsdb = 18,	/* AFS cell database. */
+	ns_t_x25 = 19,		/* X_25 calling address. */
+	ns_t_isdn = 20,		/* ISDN calling address. */
+	ns_t_rt = 21,		/* Router. */
+	ns_t_nsap = 22,		/* NSAP address. */
+	ns_t_nsap_ptr = 23,	/* Reverse NSAP lookup (deprecated). */
+	ns_t_sig = 24,		/* Security signature. */
+	ns_t_key = 25,		/* Security key. */
+	ns_t_px = 26,		/* X.400 mail mapping. */
+	ns_t_gpos = 27,		/* Geographical position (withdrawn). */
+	ns_t_aaaa = 28,		/* IPv6 Address. */
+	ns_t_loc = 29,		/* Location Information. */
+	ns_t_nxt = 30,		/* Next domain (security). */
+	ns_t_eid = 31,		/* Endpoint identifier. */
+	ns_t_nimloc = 32,	/* Nimrod Locator. */
+	ns_t_srv = 33,		/* Server Selection. */
+	ns_t_atma = 34,		/* ATM Address */
+	ns_t_naptr = 35,	/* Naming Authority PoinTeR */
+	ns_t_kx = 36,		/* Key Exchange */
+	ns_t_cert = 37,		/* Certification record */
+	ns_t_a6 = 38,		/* IPv6 address (experimental) */
+	ns_t_dname = 39,	/* Non-terminal DNAME */
+	ns_t_sink = 40,		/* Kitchen sink (experimentatl) */
+	ns_t_opt = 41,		/* EDNS0 option (meta-RR) */
+	ns_t_apl = 42,		/* Address prefix list (RFC 3123) */
+	ns_t_ds = 43,		/* Delegation Signer */
+	ns_t_sshfp = 44,	/* SSH Fingerprint */
+	ns_t_ipseckey = 45,	/* IPSEC Key */
+	ns_t_rrsig = 46,	/* RRset Signature */
+	ns_t_nsec = 47,		/* Negative security */
+	ns_t_dnskey = 48,	/* DNS Key */
+	ns_t_dhcid = 49,	/* Dynamic host configuratin identifier */
+	ns_t_nsec3 = 50,	/* Negative security type 3 */
+	ns_t_nsec3param = 51,	/* Negative security type 3 parameters */
+	ns_t_hip = 55,		/* Host Identity Protocol */
+	ns_t_spf = 99,		/* Sender Policy Framework */
+	ns_t_tkey = 249,	/* Transaction key */
+	ns_t_tsig = 250,	/* Transaction signature. */
+	ns_t_ixfr = 251,	/* Incremental zone transfer. */
+	ns_t_axfr = 252,	/* Transfer zone of authority. */
+	ns_t_mailb = 253,	/* Transfer mailbox records. */
+	ns_t_maila = 254,	/* Transfer mail agent records. */
+	ns_t_any = 255,		/* Wildcard match. */
+	ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */
+	ns_t_dlv = 32769,	/* DNSSEC look-aside validatation. */
+	ns_t_max = 65536
+} ns_type;
+
+/* Exclusively a QTYPE? (not also an RTYPE) */
+#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
+		      (t) == ns_t_mailb || (t) == ns_t_maila)
+/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
+#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
+/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
+#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)
+
+/*
+ * Values for class field
+ */
+typedef enum __ns_class {
+	ns_c_invalid = 0,	/* Cookie. */
+	ns_c_in = 1,		/* Internet. */
+	ns_c_2 = 2,		/* unallocated/unsupported. */
+	ns_c_chaos = 3,		/* MIT Chaos-net. */
+	ns_c_hs = 4,		/* MIT Hesiod. */
+	/* Query class values which do not appear in resource records */
+	ns_c_none = 254,	/* for prereq. sections in update requests */
+	ns_c_any = 255,		/* Wildcard match. */
+	ns_c_max = 65536
+} ns_class;
+
+/* DNSSEC constants. */
+
+typedef enum __ns_key_types {
+	ns_kt_rsa = 1,		/* key type RSA/MD5 */
+	ns_kt_dh  = 2,		/* Diffie Hellman */
+	ns_kt_dsa = 3,		/* Digital Signature Standard (MANDATORY) */
+	ns_kt_private = 254	/* Private key type starts with OID */
+} ns_key_types;
+
+typedef enum __ns_cert_types {
+	cert_t_pkix = 1,	/* PKIX (X.509v3) */
+	cert_t_spki = 2,	/* SPKI */
+	cert_t_pgp  = 3,	/* PGP */
+	cert_t_url  = 253,	/* URL private type */
+	cert_t_oid  = 254	/* OID private type */
+} ns_cert_types;
+
+/* Flags field of the KEY RR rdata. */
+#define	NS_KEY_TYPEMASK		0xC000	/* Mask for "type" bits */
+#define	NS_KEY_TYPE_AUTH_CONF	0x0000	/* Key usable for both */
+#define	NS_KEY_TYPE_CONF_ONLY	0x8000	/* Key usable for confidentiality */
+#define	NS_KEY_TYPE_AUTH_ONLY	0x4000	/* Key usable for authentication */
+#define	NS_KEY_TYPE_NO_KEY	0xC000	/* No key usable for either; no key */
+/* The type bits can also be interpreted independently, as single bits: */
+#define	NS_KEY_NO_AUTH		0x8000	/* Key unusable for authentication */
+#define	NS_KEY_NO_CONF		0x4000	/* Key unusable for confidentiality */
+#define	NS_KEY_RESERVED2	0x2000	/* Security is *mandatory* if bit=0 */
+#define	NS_KEY_EXTENDED_FLAGS	0x1000	/* reserved - must be zero */
+#define	NS_KEY_RESERVED4	0x0800  /* reserved - must be zero */
+#define	NS_KEY_RESERVED5	0x0400  /* reserved - must be zero */
+#define	NS_KEY_NAME_TYPE	0x0300	/* these bits determine the type */
+#define	NS_KEY_NAME_USER	0x0000	/* key is assoc. with user */
+#define	NS_KEY_NAME_ENTITY	0x0200	/* key is assoc. with entity eg host */
+#define	NS_KEY_NAME_ZONE	0x0100	/* key is zone key */
+#define	NS_KEY_NAME_RESERVED	0x0300	/* reserved meaning */
+#define	NS_KEY_RESERVED8	0x0080  /* reserved - must be zero */
+#define	NS_KEY_RESERVED9	0x0040  /* reserved - must be zero */
+#define	NS_KEY_RESERVED10	0x0020  /* reserved - must be zero */
+#define	NS_KEY_RESERVED11	0x0010  /* reserved - must be zero */
+#define	NS_KEY_SIGNATORYMASK	0x000F	/* key can sign RR's of same name */
+#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 /* no bits defined here */
+
+/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
+#define	NS_ALG_MD5RSA		1	/* MD5 with RSA */
+#define	NS_ALG_DH               2	/* Diffie Hellman KEY */
+#define	NS_ALG_DSA              3	/* DSA KEY */
+#define	NS_ALG_DSS              NS_ALG_DSA
+#define	NS_ALG_EXPIRE_ONLY	253	/* No alg, no security */
+#define	NS_ALG_PRIVATE_OID	254	/* Key begins with OID giving alg */
+
+/* Protocol values  */
+/* value 0 is reserved */
+#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
+
+/* Signatures */
+#define	NS_MD5RSA_MIN_BITS	 512	/* Size of a mod or exp in bits */
+#define	NS_MD5RSA_MAX_BITS	4096
+	/* Total of binary mod and exp */
+#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
+	/* Max length of text sig block */
+#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
+
+/* Offsets into SIG record rdata to find various values */
+#define	NS_SIG_TYPE	0	/* Type flags */
+#define	NS_SIG_ALG	2	/* Algorithm */
+#define	NS_SIG_LABELS	3	/* How many labels in name */
+#define	NS_SIG_OTTL	4	/* Original TTL */
+#define	NS_SIG_EXPIR	8	/* Expiration time */
+#define	NS_SIG_SIGNED	12	/* Signature time */
+#define	NS_SIG_FOOT	16	/* Key footprint */
+#define	NS_SIG_SIGNER	18	/* Domain name of who signed it */
+
+/* How RR types are represented as bit-flags in NXT records */
+#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
+
+/*
+ * EDNS0 extended flags and option codes, host order.
+ */
+#define NS_OPT_DNSSEC_OK	0x8000U
+#define NS_OPT_NSID             3
+
+/*
+ * Inline versions of get/put short/long.  Pointer is advanced.
+ */
+#define NS_GET16(s, cp) do { \
+	const u_char *t_cp = (const u_char *)(cp); \
+	(s) = ((uint16_t)t_cp[0] << 8) \
+	    | ((uint16_t)t_cp[1]) \
+	    ; \
+	(cp) += NS_INT16SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_GET32(l, cp) do { \
+	const u_char *t_cp = (const u_char *)(cp); \
+	(l) = ((uint32_t)t_cp[0] << 24) \
+	    | ((uint32_t)t_cp[1] << 16) \
+	    | ((uint32_t)t_cp[2] << 8) \
+	    | ((uint32_t)t_cp[3]) \
+	    ; \
+	(cp) += NS_INT32SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_PUT16(s, cp) do { \
+	uint32_t t_s = (uint32_t)(s); \
+	u_char *t_cp = (u_char *)(cp); \
+	*t_cp++ = t_s >> 8; \
+	*t_cp   = t_s; \
+	(cp) += NS_INT16SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_PUT32(l, cp) do { \
+	uint32_t t_l = (uint32_t)(l); \
+	u_char *t_cp = (u_char *)(cp); \
+	*t_cp++ = t_l >> 24; \
+	*t_cp++ = t_l >> 16; \
+	*t_cp++ = t_l >> 8; \
+	*t_cp   = t_l; \
+	(cp) += NS_INT32SZ; \
+} while (/*CONSTCOND*/0)
+
+/*
+ * ANSI C identifier hiding for bind's lib/nameser.
+ */
+#define	ns_msg_getflag		__ns_msg_getflag
+#define ns_get16		__ns_get16
+#define ns_get32		__ns_get32
+#define ns_put16		__ns_put16
+#define ns_put32		__ns_put32
+#define ns_initparse		__ns_initparse
+#define ns_skiprr		__ns_skiprr
+#define ns_parserr		__ns_parserr
+#define ns_parserr2		__ns_parserr2
+#define	ns_sprintrr		__ns_sprintrr
+#define	ns_sprintrrf		__ns_sprintrrf
+#define	ns_format_ttl		__ns_format_ttl
+#define	ns_parse_ttl		__ns_parse_ttl
+#define ns_datetosecs		__ns_datetosecs
+#define	ns_name_ntol		__ns_name_ntol
+#define	ns_name_ntop		__ns_name_ntop
+#define	ns_name_pton		__ns_name_pton
+#define	ns_name_pton2		__ns_name_pton2
+#define	ns_name_unpack		__ns_name_unpack
+#define	ns_name_unpack2		__ns_name_unpack2
+#define	ns_name_pack		__ns_name_pack
+#define	ns_name_compress	__ns_name_compress
+#define	ns_name_uncompress	__ns_name_uncompress
+#define	ns_name_skip		__ns_name_skip
+#define	ns_name_rollback	__ns_name_rollback
+#define	ns_name_length		__ns_name_length
+#define	ns_name_eq		__ns_name_eq
+#define	ns_name_owned		__ns_name_owned
+#define	ns_name_map		__ns_name_map
+#define	ns_name_labels		__ns_name_labels
+#define	ns_sign			__ns_sign
+#define	ns_sign2		__ns_sign2
+#define	ns_sign_tcp		__ns_sign_tcp
+#define	ns_sign_tcp2		__ns_sign_tcp2
+#define	ns_sign_tcp_init	__ns_sign_tcp_init
+#define ns_find_tsig		__ns_find_tsig
+#define	ns_verify		__ns_verify
+#define	ns_verify_tcp		__ns_verify_tcp
+#define	ns_verify_tcp_init	__ns_verify_tcp_init
+#define	ns_samedomain		__ns_samedomain
+#define	ns_subdomain		__ns_subdomain
+#define	ns_makecanon		__ns_makecanon
+#define	ns_samename		__ns_samename
+#define	ns_newmsg_init		__ns_newmsg_init
+#define	ns_newmsg_copy		__ns_newmsg_copy
+#define	ns_newmsg_id		__ns_newmsg_id
+#define	ns_newmsg_flag		__ns_newmsg_flag
+#define	ns_newmsg_q		__ns_newmsg_q
+#define	ns_newmsg_rr		__ns_newmsg_rr
+#define	ns_newmsg_done		__ns_newmsg_done
+#define	ns_rdata_unpack		__ns_rdata_unpack
+#define	ns_rdata_equal		__ns_rdata_equal
+#define	ns_rdata_refers		__ns_rdata_refers
+
+__BEGIN_DECLS
+int		ns_msg_getflag(ns_msg, int);
+uint16_t	ns_get16(const u_char *);
+uint32_t	ns_get32(const u_char *);
+void		ns_put16(uint16_t, u_char *);
+void		ns_put32(uint32_t, u_char *);
+int		ns_initparse(const u_char *, int, ns_msg *);
+int		ns_skiprr(const u_char *, const u_char *, ns_sect, int);
+int		ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
+int		ns_parserr2(ns_msg *, ns_sect, int, ns_rr2 *);
+int		ns_sprintrr(const ns_msg *, const ns_rr *,
+				 const char *, const char *, char *, size_t);
+int		ns_sprintrrf(const u_char *, size_t, const char *,
+				  ns_class, ns_type, u_long, const u_char *,
+				  size_t, const char *, const char *,
+				  char *, size_t);
+int		ns_format_ttl(u_long, char *, size_t);
+int		ns_parse_ttl(const char *, u_long *);
+uint32_t	ns_datetosecs(const char *cp, int *errp);
+int		ns_name_ntol(const u_char *, u_char *, size_t);
+int		ns_name_ntop(const u_char *, char *, size_t);
+int		ns_name_pton(const char *, u_char *, size_t);
+int		ns_name_pton2(const char *, u_char *, size_t, size_t *);
+int		ns_name_unpack(const u_char *, const u_char *,
+				    const u_char *, u_char *, size_t);
+int		ns_name_unpack2(const u_char *, const u_char *,
+				     const u_char *, u_char *, size_t,
+				     size_t *);
+int		ns_name_pack(const u_char *, u_char *, int,
+				  const u_char **, const u_char **);
+int		ns_name_uncompress(const u_char *, const u_char *,
+					const u_char *, char *, size_t);
+int		ns_name_compress(const char *, u_char *, size_t,
+				      const u_char **, const u_char **);
+int		ns_name_skip(const u_char **, const u_char *);
+void		ns_name_rollback(const u_char *, const u_char **,
+				      const u_char **);
+int		ns_sign(u_char *, int *, int, int, void *,
+			     const u_char *, int, u_char *, int *, time_t);
+int		ns_sign2(u_char *, int *, int, int, void *,
+			      const u_char *, int, u_char *, int *, time_t,
+			      u_char **, u_char **);
+ssize_t		ns_name_length(ns_nname_ct, size_t);
+int		ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t);
+int		ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int);
+int		ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int);
+int		ns_name_labels(ns_nname_ct, size_t);
+int		ns_sign_tcp(u_char *, int *, int, int,
+				 ns_tcp_tsig_state *, int);
+int		ns_sign_tcp2(u_char *, int *, int, int,
+				  ns_tcp_tsig_state *, int,
+				  u_char **, u_char **);
+int		ns_sign_tcp_init(void *, const u_char *, int,
+					ns_tcp_tsig_state *);
+u_char		*ns_find_tsig(u_char *, u_char *);
+int		ns_verify(u_char *, int *, void *,
+			       const u_char *, int, u_char *, int *,
+			       time_t *, int);
+int		ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);
+int		ns_verify_tcp_init(void *, const u_char *, int,
+					ns_tcp_tsig_state *);
+int		ns_samedomain(const char *, const char *);
+int		ns_subdomain(const char *, const char *);
+int		ns_makecanon(const char *, char *, size_t);
+int		ns_samename(const char *, const char *);
+int		ns_newmsg_init(u_char *buffer, size_t bufsiz, ns_newmsg *);
+int		ns_newmsg_copy(ns_newmsg *, ns_msg *);
+void		ns_newmsg_id(ns_newmsg *handle, uint16_t id);
+void		ns_newmsg_flag(ns_newmsg *handle, ns_flag flag, u_int value);
+int		ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname,
+			    ns_type qtype, ns_class qclass);
+int		ns_newmsg_rr(ns_newmsg *handle, ns_sect sect,
+			     ns_nname_ct name, ns_type type,
+			     ns_class rr_class, uint32_t ttl,
+			     uint16_t rdlen, const u_char *rdata);
+size_t		ns_newmsg_done(ns_newmsg *handle);
+ssize_t		ns_rdata_unpack(const u_char *, const u_char *, ns_type,
+				const u_char *, size_t, u_char *, size_t);
+int		ns_rdata_equal(ns_type,
+			       const u_char *, size_t,
+			       const u_char *, size_t);
+int		ns_rdata_refers(ns_type,
+				const u_char *, size_t,
+				const u_char *);
+__END_DECLS
+
+#ifdef BIND_4_COMPAT
+#include <arpa/nameser_compat.h>
+#endif
+
+#endif /* !_ARPA_NAMESER_H_ */
diff --git a/libc/include/arpa/nameser_compat.h b/libc/include/arpa/nameser_compat.h
new file mode 100644
index 0000000..e060f60
--- /dev/null
+++ b/libc/include/arpa/nameser_compat.h
@@ -0,0 +1,238 @@
+/*	$NetBSD: nameser_compat.h,v 1.1.1.2 2004/11/07 01:28:27 christos Exp $	*/
+
+/* Copyright (c) 1983, 1989
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ *      from nameser.h	8.1 (Berkeley) 6/2/93
+ *	Id: nameser_compat.h,v 1.8 2006/05/19 02:33:40 marka Exp
+ */
+
+#ifndef _ARPA_NAMESER_COMPAT_
+#define	_ARPA_NAMESER_COMPAT_
+
+#define	__BIND		19950621	/* (DEAD) interface version stamp. */
+
+#include <endian.h>
+
+#ifndef BYTE_ORDER
+#if (BSD >= 199103)
+# include <machine/endian.h>
+#else
+#ifdef __linux__
+# include <endian.h>
+#else
+#define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax, pc) */
+#define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
+#define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp)*/
+
+#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
+    defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
+    defined(__i386__) || defined(__i386) || defined(__amd64__) || \
+    defined(__x86_64__) || defined(MIPSEL) || defined(_MIPSEL) || \
+    defined(BIT_ZERO_ON_RIGHT) || defined(__alpha__) || defined(__alpha) || \
+    (defined(__Lynx__) && defined(__x86__))
+#define BYTE_ORDER	LITTLE_ENDIAN
+#endif
+
+#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
+    defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
+    defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
+    defined(apollo) || defined(__convex__) || defined(_CRAY) || \
+    defined(__hppa) || defined(__hp9000) || \
+    defined(__hp9000s300) || defined(__hp9000s700) || \
+    defined(__hp3000s900) || defined(__hpux) || defined(MPE) || \
+    defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) ||  \
+    (defined(__Lynx__) && \
+     (defined(__68k__) || defined(__sparc__) || defined(__powerpc__)))
+#define BYTE_ORDER	BIG_ENDIAN
+#endif
+#endif /* __linux */
+#endif /* BSD */
+#endif /* BYTE_ORDER */
+
+#if !defined(BYTE_ORDER) || \
+    (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
+    BYTE_ORDER != PDP_ENDIAN)
+	/* you must determine what the correct bit order is for
+	 * your compiler - the next line is an intentional error
+	 * which will force your compiles to bomb until you fix
+	 * the above macros.
+	 */
+  #error "Undefined or invalid BYTE_ORDER";
+#endif
+
+/*
+ * Structure for query header.  The order of the fields is machine- and
+ * compiler-dependent, depending on the byte/bit order and the layout
+ * of bit fields.  We use bit fields only in int variables, as this
+ * is all ANSI requires.  This requires a somewhat confusing rearrangement.
+ */
+
+typedef struct {
+	unsigned	id :16;		/* query identification number */
+#if BYTE_ORDER == BIG_ENDIAN
+			/* fields in third byte */
+	unsigned	qr: 1;		/* response flag */
+	unsigned	opcode: 4;	/* purpose of message */
+	unsigned	aa: 1;		/* authoritive answer */
+	unsigned	tc: 1;		/* truncated message */
+	unsigned	rd: 1;		/* recursion desired */
+			/* fields in fourth byte */
+	unsigned	ra: 1;		/* recursion available */
+	unsigned	unused :1;	/* unused bits (MBZ as of 4.9.3a3) */
+	unsigned	ad: 1;		/* authentic data from named */
+	unsigned	cd: 1;		/* checking disabled by resolver */
+	unsigned	rcode :4;	/* response code */
+#endif
+#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
+			/* fields in third byte */
+	unsigned	rd :1;		/* recursion desired */
+	unsigned	tc :1;		/* truncated message */
+	unsigned	aa :1;		/* authoritive answer */
+	unsigned	opcode :4;	/* purpose of message */
+	unsigned	qr :1;		/* response flag */
+			/* fields in fourth byte */
+	unsigned	rcode :4;	/* response code */
+	unsigned	cd: 1;		/* checking disabled by resolver */
+	unsigned	ad: 1;		/* authentic data from named */
+	unsigned	unused :1;	/* unused bits (MBZ as of 4.9.3a3) */
+	unsigned	ra :1;		/* recursion available */
+#endif
+			/* remaining bytes */
+	unsigned	qdcount :16;	/* number of question entries */
+	unsigned	ancount :16;	/* number of answer entries */
+	unsigned	nscount :16;	/* number of authority entries */
+	unsigned	arcount :16;	/* number of resource entries */
+} 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 BADSIG		ns_r_badsig*/
+/*#define BADKEY		ns_r_badkey*/
+/*#define BADTIME		ns_r_badtime*/
+
+
+#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_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
+/* BIND_UPDATE */
+#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
+
+#endif /* _ARPA_NAMESER_COMPAT_ */
diff --git a/libc/include/asm/page.h b/libc/include/asm/page.h
deleted file mode 100644
index d401a3f..0000000
--- a/libc/include/asm/page.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ASM_PAGE_H
-#define __ASM_PAGE_H
-
-/* New code should use sysconf(_SC_PAGESIZE) instead. */
-#define PAGE_SHIFT 12
-#define PAGE_SIZE (1ULL << PAGE_SHIFT)
-#define PAGE_MASK (~(PAGE_SIZE - 1))
-
-#endif
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index 5557e31..d05a952 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -41,32 +41,22 @@
 #define _CTYPE_H_
 
 #include <sys/cdefs.h>
+#include <xlocale.h>
 
 #define	_CTYPE_U	0x01
 #define	_CTYPE_L	0x02
-#define	_CTYPE_N	0x04
+#define	_CTYPE_D	0x04
 #define	_CTYPE_S	0x08
 #define	_CTYPE_P	0x10
 #define	_CTYPE_C	0x20
 #define	_CTYPE_X	0x40
 #define	_CTYPE_B	0x80
+#define	_CTYPE_R	(_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_D|_CTYPE_B)
+#define	_CTYPE_A	(_CTYPE_L|_CTYPE_U)
 
 __BEGIN_DECLS
 
 extern const char	*_ctype_;
-extern const short	*_tolower_tab_;
-extern const short	*_toupper_tab_;
-
-/* extern __inline is a GNU C extension */
-#ifdef __GNUC__
-#  if defined(__GNUC_STDC_INLINE__)
-#define	__CTYPE_INLINE	extern __inline __attribute__((__gnu_inline__))
-#  else
-#define	__CTYPE_INLINE	extern __inline
-#  endif
-#else
-#define	__CTYPE_INLINE	static __inline
-#endif
 
 #if defined(__GNUC__) || defined(_ANSI_LIBRARY) || defined(lint)
 int	isalnum(int);
@@ -83,6 +73,21 @@
 int	tolower(int);
 int	toupper(int);
 
+int isalnum_l(int, locale_t);
+int isalpha_l(int, locale_t);
+int isblank_l(int, locale_t);
+int iscntrl_l(int, locale_t);
+int isdigit_l(int, locale_t);
+int isgraph_l(int, locale_t);
+int islower_l(int, locale_t);
+int isprint_l(int, locale_t);
+int ispunct_l(int, locale_t);
+int isspace_l(int, locale_t);
+int isupper_l(int, locale_t);
+int isxdigit_l(int, locale_t);
+int tolower_l(int, locale_t);
+int toupper_l(int, locale_t);
+
 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
     || __XPG_VISIBLE > 600
 int	isblank(int);
@@ -97,111 +102,6 @@
 
 #endif /* __GNUC__ || _ANSI_LIBRARY || lint */
 
-#if defined(NDEBUG)
-
-__CTYPE_INLINE int isalnum(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_U|_CTYPE_L|_CTYPE_N)));
-}
-
-__CTYPE_INLINE int isalpha(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_U|_CTYPE_L)));
-}
-
-__CTYPE_INLINE int iscntrl(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_C));
-}
-
-__CTYPE_INLINE int isdigit(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_N));
-}
-
-__CTYPE_INLINE int isgraph(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N)));
-}
-
-__CTYPE_INLINE int islower(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_L));
-}
-
-__CTYPE_INLINE int isprint(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B)));
-}
-
-__CTYPE_INLINE int ispunct(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_P));
-}
-
-__CTYPE_INLINE int isspace(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_S));
-}
-
-__CTYPE_INLINE int isupper(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_U));
-}
-
-__CTYPE_INLINE int isxdigit(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_N|_CTYPE_X)));
-}
-
-__CTYPE_INLINE int tolower(int c)
-{
-	if ((unsigned int)c > 255)
-		return (c);
-	return ((_tolower_tab_ + 1)[c]);
-}
-
-__CTYPE_INLINE int toupper(int c)
-{
-	if ((unsigned int)c > 255)
-		return (c);
-	return ((_toupper_tab_ + 1)[c]);
-}
-
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
-    || __XPG_VISIBLE > 600
-__CTYPE_INLINE int isblank(int c)
-{
-	return (c == ' ' || c == '\t');
-}
-#endif
-
-#if __BSD_VISIBLE || __XPG_VISIBLE
-__CTYPE_INLINE int isascii(int c)
-{
-	return ((unsigned int)c <= 0177);
-}
-
-__CTYPE_INLINE int toascii(int c)
-{
-	return (c & 0177);
-}
-
-__CTYPE_INLINE int _tolower(int c)
-{
-	return (c - 'A' + 'a');
-}
-
-__CTYPE_INLINE int _toupper(int c)
-{
-	return (c - 'a' + 'A');
-}
-#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
-
-#endif /* NDEBUG */
-
 __END_DECLS
 
-#undef __CTYPE_INLINE
-
 #endif /* !_CTYPE_H_ */
diff --git a/libc/include/dirent.h b/libc/include/dirent.h
index 129cdfa..a849a61 100644
--- a/libc/include/dirent.h
+++ b/libc/include/dirent.h
@@ -46,28 +46,35 @@
 #define DT_WHT 14
 #endif
 
-struct dirent {
-  uint64_t         d_ino;
-  int64_t          d_off;
-  unsigned short   d_reclen;
-  unsigned char    d_type;
-  char             d_name[256];
-};
+#define __DIRENT64_BODY \
+    uint64_t         d_ino; \
+    int64_t          d_off; \
+    unsigned short   d_reclen; \
+    unsigned char    d_type; \
+    char             d_name[256]; \
+
+struct dirent { __DIRENT64_BODY };
+struct dirent64 { __DIRENT64_BODY };
+
+#undef __DIRENT64_BODY
+
 #define d_fileno d_ino
-#define dirent64 dirent
 
 typedef struct DIR DIR;
 
 extern DIR* opendir(const char*);
 extern DIR* fdopendir(int);
 extern struct dirent* readdir(DIR*);
+extern struct dirent64* readdir64(DIR*);
 extern int readdir_r(DIR*, struct dirent*, struct dirent**);
+extern int readdir64_r(DIR*, struct dirent64*, struct dirent64**);
 extern int closedir(DIR*);
 extern void rewinddir(DIR*);
 extern int dirfd(DIR*);
 extern int alphasort(const struct dirent**, const struct dirent**);
+extern int alphasort64(const struct dirent64**, const struct dirent64**);
 extern int scandir(const char*, struct dirent***, int (*)(const struct dirent*), int (*)(const struct dirent**, const struct dirent**));
-extern int getdents(unsigned int, struct dirent*, unsigned int);
+extern int scandir64(const char*, struct dirent64***, int (*)(const struct dirent64*), int (*)(const struct dirent64**, const struct dirent64**));
 
 __END_DECLS
 
diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h
index 7daa8f7..8dde08c 100644
--- a/libc/include/dlfcn.h
+++ b/libc/include/dlfcn.h
@@ -50,15 +50,29 @@
 extern int          dladdr(const void* addr, Dl_info *info);
 
 enum {
+#if defined(__LP64__)
+  RTLD_NOW  = 2,
+#else
   RTLD_NOW  = 0,
+#endif
   RTLD_LAZY = 1,
 
   RTLD_LOCAL  = 0,
+#if defined(__LP64__)
+  RTLD_GLOBAL = 0x00100,
+#else
   RTLD_GLOBAL = 2,
+#endif
+  RTLD_NOLOAD = 4,
 };
 
+#if defined (__LP64__)
+#define RTLD_DEFAULT  ((void*) 0)
+#define RTLD_NEXT     ((void*) -1L)
+#else
 #define RTLD_DEFAULT  ((void*) 0xffffffff)
 #define RTLD_NEXT     ((void*) 0xfffffffe)
+#endif
 
 __END_DECLS
 
diff --git a/libc/include/elf.h b/libc/include/elf.h
index 3f2e4f2..0975b7a 100644
--- a/libc/include/elf.h
+++ b/libc/include/elf.h
@@ -28,33 +28,55 @@
 #ifndef _ELF_H
 #define _ELF_H
 
-#include <stdint.h>
 #include <linux/auxvec.h>
+#include <linux/elf.h>
+#include <linux/elf-em.h>
 
-/* TODO: can we switch to <linux/elf.h> instead? http://b/12476126. */
-#include <sys/exec_elf.h>
+#include <machine/elf_machdep.h>
 
 typedef struct {
-  uint32_t a_type;
+  __u32 a_type;
   union {
-    uint32_t a_val;
+    __u32 a_val;
   } a_un;
 } Elf32_auxv_t;
 
 typedef struct {
-  uint64_t a_type;
+  __u64 a_type;
   union {
-    uint64_t a_val;
+    __u64 a_val;
   } a_un;
 } Elf64_auxv_t;
 
-#ifdef __LP64__
-#  define Elf_auxv_t Elf64_auxv_t
-#else
-#  define Elf_auxv_t Elf32_auxv_t
-#endif
+#define DF_ORIGIN     0x00000001
+#define DF_SYMBOLIC   0x00000002
+#define DF_TEXTREL    0x00000004
+#define DF_BIND_NOW   0x00000008
+#define DF_STATIC_TLS 0x00000010
 
-/* <sys/exec_elf.h> doesn't contain any NT_ constants. aarch64 strace needs this one. */
-#define NT_PRSTATUS 1
+#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
+/* glibc and BSD disagree for DT_ENCODING; glibc looks wrong. */
+#define DT_PREINIT_ARRAY 32
+#define DT_PREINIT_ARRAYSZ 33
+
+#define ELFOSABI_SYSV 0 /* Synonym for ELFOSABI_NONE used by valgrind. */
+
+#define PT_GNU_RELRO 0x6474e552
+
+#define STB_LOOS   10
+#define STB_HIOS   12
+#define STB_LOPROC 13
+#define STB_HIPROC 15
+
+#define STT_LOOS   10
+#define STT_HIOS   12
+#define STT_LOPROC 13
+#define STT_HIPROC 15
 
 #endif /* _ELF_H */
diff --git a/libc/include/err.h b/libc/include/err.h
index f24da61..ca62c9e 100644
--- a/libc/include/err.h
+++ b/libc/include/err.h
@@ -33,57 +33,25 @@
  */
 
 #ifndef _ERR_H_
-#define	_ERR_H_
+#define _ERR_H_
 
-/*
- * Don't use va_list in the err/warn prototypes.   Va_list is typedef'd in two
- * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
- * of them here we may collide with the utility's includes.  It's unreasonable
- * for utilities to have to include one of them to include err.h, so we get
- * __va_list from <machine/_types.h> and use it.
- */
 #include <sys/cdefs.h>
-#include <machine/_types.h>
+#include <sys/types.h>
 
 __BEGIN_DECLS
 
-__noreturn void	err(int, const char *, ...)
-			__printflike(2, 3);
-__noreturn void	verr(int, const char *, __va_list)
-			__printflike(2, 0);
-__noreturn void	errx(int, const char *, ...)
-			__printflike(2, 3);
-__noreturn void	verrx(int, const char *, __va_list)
-			__printflike(2, 0);
-void		warn(const char *, ...)
-			__printflike(1, 2);
-void		vwarn(const char *, __va_list)
-			__printflike(1, 0);
-void		warnx(const char *, ...)
-			__printflike(1, 2);
-void		vwarnx(const char *, __va_list)
-			__printflike(1, 0);
+/* printf's format string isn't nullable; the err family's one is,
+ * so we can't use __errlike here. */
+#define __errlike(x, y) __attribute__((__format__(printf, x, y)))
 
-/*
- * The _* versions are for use in library functions so user-defined
- * versions of err*,warn* do not get used.
- */
-__noreturn void	_err(int, const char *, ...)
-			__printflike(2, 3);
-__noreturn void	_verr(int, const char *, __va_list)
-			__printflike(2, 0);
-__noreturn void	_errx(int, const char *, ...)
-			__printflike(2, 3);
-__noreturn void	_verrx(int, const char *, __va_list)
-			__printflike(2, 0);
-void		_warn(const char *, ...)
-			__printflike(1, 2);
-void		_vwarn(const char *, __va_list)
-			__printflike(1, 0);
-void		_warnx(const char *, ...)
-			__printflike(1, 2);
-void		_vwarnx(const char *, __va_list)
-			__printflike(1, 0);
+__noreturn void err(int, const char *, ...) __errlike(2, 3);
+__noreturn void verr(int, const char *, __va_list) __errlike(2, 0);
+__noreturn void errx(int, const char *, ...) __errlike(2, 3);
+__noreturn void verrx(int, const char *, __va_list) __errlike(2, 0);
+void warn(const char *, ...) __errlike(1, 2);
+void vwarn(const char *, __va_list) __errlike(1, 0);
+void warnx(const char *, ...) __errlike(1, 2);
+void vwarnx(const char *, __va_list) __errlike(1, 0);
 
 __END_DECLS
 
diff --git a/libc/include/errno.h b/libc/include/errno.h
index 2e5ce5f..1a36b7a 100644
--- a/libc/include/errno.h
+++ b/libc/include/errno.h
@@ -41,7 +41,7 @@
 #endif
 
 /* internal function returning the address of the thread-specific errno */
-extern volatile int*   __errno(void);
+extern volatile int* __errno(void) __pure2;
 
 /* a macro expanding to the errno l-value */
 #define  errno   (*__errno())
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index f6a89ef..8f89afb 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -33,19 +33,53 @@
 #include <sys/types.h>
 #include <linux/fadvise.h>
 #include <linux/fcntl.h>
+#include <linux/uio.h>
 #include <unistd.h>  /* this is not required, but makes client code much happier */
 
 __BEGIN_DECLS
 
-#ifndef O_ASYNC
-#define O_ASYNC  FASYNC
+#ifdef __LP64__
+/* LP64 kernels don't have flock64 because their flock is 64-bit. */
+struct flock64 {
+  short l_type;
+  short l_whence;
+  off64_t l_start;
+  off64_t l_len;
+  pid_t l_pid;
+};
+#define F_GETLK64  F_GETLK
+#define F_SETLK64  F_SETLK
+#define F_SETLKW64 F_SETLKW
 #endif
 
-extern int  open(const char*  path, int  mode, ...);
-extern int  openat(int fd, const char*  path, int  mode, ...);
-extern int  unlinkat(int dirfd, const char *pathname, int flags);
-extern int  fcntl(int   fd, int   command, ...);
-extern int  creat(const char*  path, mode_t  mode);
+#define O_ASYNC FASYNC
+
+#define SPLICE_F_MOVE 1
+#define SPLICE_F_NONBLOCK 2
+#define SPLICE_F_MORE 4
+#define SPLICE_F_GIFT 8
+
+#define SYNC_FILE_RANGE_WAIT_BEFORE 1
+#define SYNC_FILE_RANGE_WRITE 2
+#define SYNC_FILE_RANGE_WAIT_AFTER 4
+
+extern int creat(const char*, mode_t);
+extern int creat64(const char*, mode_t);
+extern int fallocate64(int, int, off64_t, off64_t);
+extern int fallocate(int, int, off_t, off_t);
+extern int fcntl(int, int, ...);
+extern int openat(int, const char*, int, ...);
+extern int openat64(int, const char*, int, ...);
+extern int open(const char*, int, ...);
+extern int open64(const char*, int, ...);
+extern int posix_fadvise64(int, off64_t, off64_t, int);
+extern int posix_fadvise(int, off_t, off_t, int);
+extern int posix_fallocate64(int, off64_t, off64_t);
+extern int posix_fallocate(int, off_t, off_t);
+extern ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int);
+extern ssize_t tee(int, int, size_t, unsigned int);
+extern int unlinkat(int, const char*, int);
+extern ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int);
 
 #if defined(__BIONIC_FORTIFY)
 
diff --git a/libc/include/ftw.h b/libc/include/ftw.h
index 3bebea3..af524d0 100644
--- a/libc/include/ftw.h
+++ b/libc/include/ftw.h
@@ -57,6 +57,9 @@
 int	ftw(const char *, int (*)(const char *, const struct stat *, int), int);
 int	nftw(const char *, int (*)(const char *, const struct stat *, int,
 	    struct FTW *), int, int);
+int	ftw64(const char *, int (*)(const char *, const struct stat64 *, int), int);
+int	nftw64(const char *, int (*)(const char *, const struct stat64 *, int,
+	    struct FTW *), int, int);
 __END_DECLS
 
 #endif	/* !_FTW_H */
diff --git a/libc/include/grp.h b/libc/include/grp.h
index 86d99f3..fc4d520 100644
--- a/libc/include/grp.h
+++ b/libc/include/grp.h
@@ -43,10 +43,6 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
-#if __BSD_VISIBLE
-#define	_PATH_GROUP		"/etc/group"
-#endif
-
 struct group {
 	char	*gr_name;		/* group name */
 	char	*gr_passwd;		/* group password */
@@ -57,7 +53,7 @@
 __BEGIN_DECLS
 struct group	*getgrgid(gid_t);
 struct group	*getgrnam(const char *);
-#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE
+#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE
 struct group	*getgrent(void);
 void		 setgrent(void);
 void		 endgrent(void);
@@ -66,11 +62,6 @@
 int		 getgrnam_r(const char *, struct group *, char *,
 		    size_t, struct group **);
 #endif
-#if __BSD_VISIBLE
-void		 setgrfile(const char *);
-int		 setgroupent(int);
-char		*group_from_gid(gid_t, int);
-#endif
 
 int   getgrouplist (const char *user, gid_t group,
                   gid_t *groups, int *ngroups);
diff --git a/libc/include/inttypes.h b/libc/include/inttypes.h
index 2fd2415..8853c08 100644
--- a/libc/include/inttypes.h
+++ b/libc/include/inttypes.h
@@ -254,16 +254,14 @@
 } imaxdiv_t;
 
 __BEGIN_DECLS
-
 intmax_t	imaxabs(intmax_t) __pure2;
 imaxdiv_t	imaxdiv(intmax_t, intmax_t) __pure2;
-
 intmax_t	strtoimax(const char *, char **, int);
 uintmax_t	strtoumax(const char *, char **, int);
-
-intmax_t	strntoimax(const char *nptr, char **endptr, int base, size_t n);
-uintmax_t	strntoumax(const char *nptr, char **endptr, int base, size_t n);
-
+intmax_t	wcstoimax(const wchar_t * __restrict,
+		    wchar_t ** __restrict, int);
+uintmax_t	wcstoumax(const wchar_t * __restrict,
+		    wchar_t ** __restrict, int);
 __END_DECLS
 
 #endif /* _INTTYPES_H_ */
diff --git a/libc/include/libgen.h b/libc/include/libgen.h
index c5fc76a..9dcec75 100644
--- a/libc/include/libgen.h
+++ b/libc/include/libgen.h
@@ -33,24 +33,15 @@
 
 __BEGIN_DECLS
 
-/* our version of dirname/basename don't modify the input path */
-extern char*  dirname (const char*  path);
-extern char*  basename(const char*  path);
+/* On Android these don't modify their input, and use thread-local storage for their results. */
+extern char* basename(const char*);
+extern char* dirname(const char*);
 
-/* special thread-safe Bionic versions
- *
- * if 'buffer' is NULL, 'bufflen' is ignored and the length of the result is returned
- * otherwise, place result in 'buffer'
- *
- * at most bufflen-1 characters written, plus a terminating zero
- *
- * return length of result, or -1 in case of error, with errno set to:
- *
- *    ERANGE:        buffer is too short
- *    ENAMETOOLONG:  the result is too long for a valid path
- */
-extern int    dirname_r(const char*  path, char*  buffer, size_t  bufflen);
-extern int    basename_r(const char*  path, char*  buffer, size_t  bufflen);
+#if !defined(__LP64__)
+/* These non-standard functions are not needed on Android; basename and dirname use thread-local storage. */
+extern int dirname_r(const char*, char*, size_t);
+extern int basename_r(const char*, char*, size_t);
+#endif
 
 __END_DECLS
 
diff --git a/libc/include/limits.h b/libc/include/limits.h
index b9d4354..fb09657 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -105,9 +105,24 @@
 #define ULONG_LONG_MAX  ULLONG_MAX
 #endif
 
+/* BSD compatibility definitions. */
+#if __BSD_VISIBLE
+#define SIZE_T_MAX ULONG_MAX
+#endif /* __BSD_VISIBLE */
+
+#define SSIZE_MAX LONG_MAX
+
+#define MB_LEN_MAX 4
+
+/* New code should use sysconf(_SC_PAGE_SIZE) instead. */
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
 #ifndef PAGESIZE
-#include <asm/page.h>
 #define  PAGESIZE  PAGE_SIZE
 #endif
 
+/* glibc's PAGE_MASK is the bitwise negation of BSD's! TODO: remove? */
+#define PAGE_MASK (~(PAGE_SIZE - 1))
+
 #endif /* !_LIMITS_H_ */
diff --git a/libc/include/link.h b/libc/include/link.h
index 341fbf1..cb8e139 100644
--- a/libc/include/link.h
+++ b/libc/include/link.h
@@ -33,7 +33,11 @@
 
 __BEGIN_DECLS
 
-#define ElfW(type) Elf_##type
+#if __LP64__
+#define ElfW(type) Elf64_ ## type
+#else
+#define ElfW(type) Elf32_ ## type
+#endif
 
 struct dl_phdr_info {
   ElfW(Addr) dlpi_addr;
@@ -42,13 +46,35 @@
   ElfW(Half) dlpi_phnum;
 };
 
-int dl_iterate_phdr(int (*cb)(struct dl_phdr_info*, size_t, void*), void*);
+int dl_iterate_phdr(int (*)(struct dl_phdr_info*, size_t, void*), void*);
 
 #ifdef __arm__
 typedef long unsigned int* _Unwind_Ptr;
-_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
+_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr, int*);
 #endif
 
+/* Used by the dynamic linker to communicate with the debugger. */
+struct link_map {
+  ElfW(Addr) l_addr;
+  char* l_name;
+  ElfW(Dyn)* l_ld;
+  struct link_map* l_next;
+  struct link_map* l_prev;
+};
+
+/* Used by the dynamic linker to communicate with the debugger. */
+struct r_debug {
+  int32_t r_version;
+  struct link_map* r_map;
+  ElfW(Addr) r_brk;
+  enum {
+    RT_CONSISTENT,
+    RT_ADD,
+    RT_DELETE
+  } r_state;
+  ElfW(Addr) r_ldbase;
+};
+
 __END_DECLS
 
 #endif /* _LINK_H_ */
diff --git a/libc/include/locale.h b/libc/include/locale.h
index 65b5c7d..7fd8c2c 100644
--- a/libc/include/locale.h
+++ b/libc/include/locale.h
@@ -29,31 +29,78 @@
 #define _LOCALE_H_
 
 #include <sys/cdefs.h>
+#include <xlocale.h>
 
 __BEGIN_DECLS
 
-enum {
-    LC_CTYPE     = 0,
-    LC_NUMERIC   = 1,
-    LC_TIME      = 2,
-    LC_COLLATE   = 3,
-    LC_MONETARY  = 4,
-    LC_MESSAGES  = 5,
-    LC_ALL       = 6,
-    LC_PAPER     = 7,
-    LC_NAME      = 8,
-    LC_ADDRESS   = 9,
+#define LC_CTYPE           0
+#define LC_NUMERIC         1
+#define LC_TIME            2
+#define LC_COLLATE         3
+#define LC_MONETARY        4
+#define LC_MESSAGES        5
+#define LC_ALL             6
+#define LC_PAPER           7
+#define LC_NAME            8
+#define LC_ADDRESS         9
+#define LC_TELEPHONE      10
+#define LC_MEASUREMENT    11
+#define LC_IDENTIFICATION 12
 
-    LC_TELEPHONE      = 10,
-    LC_MEASUREMENT    = 11,
-    LC_IDENTIFICATION = 12
+#define LC_CTYPE_MASK          (1 << LC_CTYPE)
+#define LC_NUMERIC_MASK        (1 << LC_NUMERIC)
+#define LC_TIME_MASK           (1 << LC_TIME)
+#define LC_COLLATE_MASK        (1 << LC_COLLATE)
+#define LC_MONETARY_MASK       (1 << LC_MONETARY)
+#define LC_MESSAGES_MASK       (1 << LC_MESSAGES)
+#define LC_PAPER_MASK          (1 << LC_PAPER)
+#define LC_NAME_MASK           (1 << LC_NAME)
+#define LC_ADDRESS_MASK        (1 << LC_ADDRESS)
+#define LC_TELEPHONE_MASK      (1 << LC_TELEPHONE)
+#define LC_MEASUREMENT_MASK    (1 << LC_MEASUREMENT)
+#define LC_IDENTIFICATION_MASK (1 << LC_IDENTIFICATION)
+
+#define LC_ALL_MASK (LC_CTYPE_MASK | LC_NUMERIC_MASK | LC_TIME_MASK | LC_COLLATE_MASK | \
+                     LC_MONETARY_MASK | LC_MESSAGES_MASK | LC_PAPER_MASK | LC_NAME_MASK | \
+                     LC_ADDRESS_MASK | LC_TELEPHONE_MASK | LC_MEASUREMENT_MASK | \
+                     LC_IDENTIFICATION_MASK)
+
+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_p_sep_by_space;
+    char  int_n_cs_precedes;
+    char  int_n_sep_by_space;
+    char  int_p_sign_posn;
+    char  int_n_sign_posn;
 };
 
-extern char *setlocale(int category, const char *locale);
+struct lconv* localeconv(void);
 
-/* Make libstdc++-v3 happy.  */
-struct lconv { };
-struct lconv *localeconv(void);
+locale_t duplocale(locale_t);
+void freelocale(locale_t);
+locale_t newlocale(int, const char*, locale_t);
+char* setlocale(int, const char*);
+locale_t uselocale(locale_t);
+
+#define LC_GLOBAL_LOCALE ((locale_t) -1L)
 
 __END_DECLS
 
diff --git a/libc/include/machine/ieee.h b/libc/include/machine/ieee.h
new file mode 100644
index 0000000..c579969
--- /dev/null
+++ b/libc/include/machine/ieee.h
@@ -0,0 +1,118 @@
+/*	$OpenBSD: ieee.h,v 1.4 2011/11/08 17:06:51 deraadt Exp $	*/
+/*	$NetBSD: ieee.h,v 1.2 2001/02/21 17:43:50 bjh21 Exp $	*/
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Lawrence Berkeley Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
+ */
+
+#ifndef _MACHINE_IEEE_H_
+#define _MACHINE_IEEE_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+#define SNG_EXPBITS	8
+#define SNG_FRACBITS	23
+
+#define SNG_EXP_INFNAN	255
+#define SNG_EXP_BIAS	127
+
+struct ieee_single {
+  unsigned sng_frac:23;
+  unsigned sng_exp:8;
+  unsigned sng_sign:1;
+};
+
+#define DBL_EXPBITS	11
+#define DBL_FRACHBITS	20
+#define DBL_FRACLBITS	32
+#define DBL_FRACBITS	52
+
+#define DBL_EXP_INFNAN	2047
+#define DBL_EXP_BIAS	1023
+
+struct ieee_double {
+  unsigned dbl_fracl;
+  unsigned dbl_frach:20;
+  unsigned dbl_exp:11;
+  unsigned dbl_sign:1;
+};
+
+#if __LP64__
+
+/* 64-bit Android uses ld128 long doubles. */
+
+#define EXT_EXPBITS	15
+#define EXT_FRACHBITS	16
+#define EXT_FRACHMBITS	32
+#define EXT_FRACLMBITS	32
+#define EXT_FRACLBITS	32
+#define EXT_FRACBITS	112
+
+#define EXT_EXP_INFNAN	32767
+#define EXT_EXP_BIAS	16383
+
+#define EXT_IMPLICIT_NBIT
+
+#define EXT_TO_ARRAY32(p, a) do { \
+  (a)[0] = (uint32_t)(p)->ext_fracl; \
+  (a)[1] = (uint32_t)(p)->ext_fraclm; \
+  (a)[2] = (uint32_t)(p)->ext_frachm; \
+  (a)[3] = (uint32_t)(p)->ext_frach; \
+} while(0)
+
+struct ieee_ext {
+  unsigned ext_fracl;
+  unsigned ext_fraclm;
+  unsigned ext_frachm;
+  unsigned ext_frach:16;
+  unsigned ext_exp:15;
+  unsigned ext_sign:1;
+};
+
+#endif
+
+__END_DECLS
+
+#endif /* _MACHINE_IEEE_H_ */
diff --git a/libc/include/machine/wchar_limits.h b/libc/include/machine/wchar_limits.h
new file mode 100644
index 0000000..94cbd7e
--- /dev/null
+++ b/libc/include/machine/wchar_limits.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _MACHINE_WCHAR_LIMITS_H_
+#define _MACHINE_WCHAR_LIMITS_H_
+
+/* Both GCC and clang define __WCHAR_MAX__. */
+#define WCHAR_MAX __WCHAR_MAX__
+
+/* As of 3.4, clang still doesn't define __WCHAR_MIN__. */
+#if defined(__WCHAR_UNSIGNED__)
+#  define WCHAR_MIN L'\0'
+#else
+#  define WCHAR_MIN (-(WCHAR_MAX) - 1)
+#endif
+
+#endif /* _MACHINE_WCHAR_LIMITS_H_ */
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 9a4e324..e6ea276 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -35,9 +35,6 @@
 extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(2)));
 extern size_t malloc_usable_size(const void* p);
 
-extern void* valloc(size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(1)));
-extern void* pvalloc(size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(1)));
-
 #ifndef STRUCT_MALLINFO_DECLARED
 #define STRUCT_MALLINFO_DECLARED 1
 struct mallinfo {
diff --git a/libc/include/mntent.h b/libc/include/mntent.h
index 6cc0b18..de285d0 100644
--- a/libc/include/mntent.h
+++ b/libc/include/mntent.h
@@ -35,23 +35,21 @@
 #define MOUNTED _PATH_MOUNTED
 #define MNTTYPE_IGNORE "ignore"
 
-struct mntent
-{
-    char* mnt_fsname;
-    char* mnt_dir;
-    char* mnt_type;
-    char* mnt_opts;
-    int mnt_freq;
-    int mnt_passno;
+struct mntent {
+  char* mnt_fsname;
+  char* mnt_dir;
+  char* mnt_type;
+  char* mnt_opts;
+  int mnt_freq;
+  int mnt_passno;
 };
 
-
 __BEGIN_DECLS
 
-
-struct mntent* getmntent(FILE*);
-FILE* setmntent(const char*, const char*);
 int endmntent(FILE*);
+struct mntent* getmntent(FILE*);
+struct mntent* getmntent_r(FILE*, struct mntent*, char*, int);
+FILE* setmntent(const char*, const char*);
 
 __END_DECLS
 
diff --git a/libc/include/netdb.h b/libc/include/netdb.h
index 62a7a3c..527d5c1 100644
--- a/libc/include/netdb.h
+++ b/libc/include/netdb.h
@@ -196,6 +196,8 @@
 #define	SCOPE_DELIMITER	'%'
 
 __BEGIN_DECLS
+#pragma GCC visibility push(default)
+
 /* BIONIC-BEGIN */
 #define  h_errno   (*__get_h_errno())
 int*  __get_h_errno(void);
@@ -207,13 +209,11 @@
 void endservent(void);
 void freehostent(struct hostent *);
 struct hostent	*gethostbyaddr(const void *, socklen_t, int);
-struct hostent	*android_gethostbyaddrforiface(const void *, socklen_t, int, const char*, int);
 int gethostbyaddr_r(const void *, int, int, struct hostent *, char *, size_t, struct hostent **, int *);
 struct hostent	*gethostbyname(const char *);
 int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
 struct hostent	*gethostbyname2(const char *, int);
 int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*android_gethostbynameforiface(const char *, int, const char *, int);
 struct hostent	*gethostent(void);
 int gethostent_r(struct hostent *, char *, size_t, struct hostent **, int *);
 struct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
@@ -241,14 +241,13 @@
 void setnetent(int);
 void setprotoent(int);
 int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
-int android_getaddrinfoforiface(const char *, const char *, const struct addrinfo *, const char *, int, struct addrinfo **);
 int getnameinfo(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int);
-int android_getnameinfoforiface(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int, const char *, int);
 void freeaddrinfo(struct addrinfo *);
 const char	*gai_strerror(int);
 void setnetgrent(const char *);
 void setservent(int);
 
+#pragma GCC visibility pop
 __END_DECLS
 
 #endif /* !_NETDB_H_ */
diff --git a/libc/include/nsswitch.h b/libc/include/nsswitch.h
index d19d055..af88433 100644
--- a/libc/include/nsswitch.h
+++ b/libc/include/nsswitch.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: nsswitch.h,v 1.18 2005/11/29 03:12:58 christos Exp $	*/
+/*	$NetBSD: nsswitch.h,v 1.21 2011/07/17 20:54:34 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -15,13 +15,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -54,7 +47,7 @@
 /*
  * Layout of:
  *	uint32_t ns_src.flags
- */ 
+ */
 	/* nsswitch.conf status codes and nsdispatch(3) return values */
 #define	NS_SUCCESS	(1<<0)		/* entry was found */
 #define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
@@ -125,7 +118,7 @@
  */
 #define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	__UNCONST(C) },
 #define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	__UNCONST(C) },
- 
+
 #ifdef HESIOD
 #   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	__UNCONST(C) },
 #else
@@ -137,6 +130,7 @@
 #else
 #   define NS_NIS_CB(F,C)
 #endif
+#define	NS_NULL_CB		{ .src = NULL },
 
 /*
  * ns_src - `nsswitch source'
@@ -221,7 +215,7 @@
 
 __BEGIN_DECLS
 int	nsdispatch(void *, const ns_dtab [], const char *,
-			const char *, const ns_src [], ...);
+			const char *, const ns_src [], ...) __LIBC_ABI_PUBLIC__;
 
 #ifdef _NS_PRIVATE
 int		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index c5380be..86a1005 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -35,17 +35,26 @@
 #include <limits.h>
 #include <sys/types.h>
 
+#if defined(__LP64__)
+  #define __RESERVED_INITIALIZER , {0}
+#else
+  #define __RESERVED_INITIALIZER
+#endif
+
 typedef struct {
   int volatile value;
+#ifdef __LP64__
+  char __reserved[36];
+#endif
 } pthread_mutex_t;
 
 #define  __PTHREAD_MUTEX_INIT_VALUE            0
 #define  __PTHREAD_RECURSIVE_MUTEX_INIT_VALUE  0x4000
 #define  __PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE 0x8000
 
-#define  PTHREAD_MUTEX_INITIALIZER             {__PTHREAD_MUTEX_INIT_VALUE}
-#define  PTHREAD_RECURSIVE_MUTEX_INITIALIZER   {__PTHREAD_RECURSIVE_MUTEX_INIT_VALUE}
-#define  PTHREAD_ERRORCHECK_MUTEX_INITIALIZER  {__PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE}
+#define  PTHREAD_MUTEX_INITIALIZER             {__PTHREAD_MUTEX_INIT_VALUE __RESERVED_INITIALIZER}
+#define  PTHREAD_RECURSIVE_MUTEX_INITIALIZER   {__PTHREAD_RECURSIVE_MUTEX_INIT_VALUE __RESERVED_INITIALIZER}
+#define  PTHREAD_ERRORCHECK_MUTEX_INITIALIZER  {__PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE __RESERVED_INITIALIZER}
 
 enum {
     PTHREAD_MUTEX_NORMAL = 0,
@@ -60,9 +69,12 @@
 
 typedef struct {
   int volatile value;
+#ifdef __LP64__
+  char __reserved[44];
+#endif
 } pthread_cond_t;
 
-#define PTHREAD_COND_INITIALIZER  {0}
+#define PTHREAD_COND_INITIALIZER  {0 __RESERVED_INITIALIZER}
 
 typedef struct {
   uint32_t flags;
@@ -71,33 +83,52 @@
   size_t guard_size;
   int32_t sched_policy;
   int32_t sched_priority;
+#ifdef __LP64__
+  char __reserved[16];
+#endif
 } pthread_attr_t;
 
 typedef long pthread_mutexattr_t;
 typedef long pthread_condattr_t;
 
-typedef int pthread_rwlockattr_t;
+typedef long pthread_rwlockattr_t;
 
 typedef struct {
-  pthread_mutex_t  lock;
-  pthread_cond_t   cond;
-  int              numLocks;
-  int              writerThreadId;
-  int              pendingReaders;
-  int              pendingWriters;
-  void*            reserved[4];  /* for future extensibility */
+#if !defined(__LP64__)
+  pthread_mutex_t __unused_lock;
+  pthread_cond_t __unused_cond;
+#endif
+  volatile int32_t state; // 0=unlock, -1=writer lock, +n=reader lock
+  volatile int32_t writer_thread_id;
+  volatile int32_t pending_readers;
+  volatile int32_t pending_writers;
+  int32_t attr;
+#ifdef __LP64__
+  char __reserved[36];
+#else
+  char __reserved[12];
+#endif
+
 } pthread_rwlock_t;
 
-#define PTHREAD_RWLOCK_INITIALIZER  { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0, 0, 0, { NULL, NULL, NULL, NULL } }
+#ifdef __LP64__
+  #define PTHREAD_RWLOCK_INITIALIZER  { 0, 0, 0, 0, 0, { 0 } }
+#else
+  #define PTHREAD_RWLOCK_INITIALIZER  { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0, 0, 0, 0, { 0 } }
+#endif
 
 typedef int pthread_key_t;
 typedef long pthread_t;
 
 typedef volatile int pthread_once_t;
 
-#define PTHREAD_ONCE_INIT    0
+#define PTHREAD_ONCE_INIT 0
 
+#if defined(__LP64__)
+#define PTHREAD_STACK_MIN (4 * PAGE_SIZE)
+#else
 #define PTHREAD_STACK_MIN (2 * PAGE_SIZE)
+#endif
 
 #define PTHREAD_CREATE_DETACHED  0x00000001
 #define PTHREAD_CREATE_JOINABLE  0x00000000
@@ -127,11 +158,13 @@
 int pthread_attr_setschedpolicy(pthread_attr_t*, int) __nonnull((1));
 int pthread_attr_setscope(pthread_attr_t*, int) __nonnull((1));
 int pthread_attr_setstack(pthread_attr_t*, void*, size_t) __nonnull((1));
-int pthread_attr_setstacksize(pthread_attr_t * attr, size_t stack_size) __nonnull((1));
+int pthread_attr_setstacksize(pthread_attr_t*, size_t stack_size) __nonnull((1));
 
 int pthread_condattr_destroy(pthread_condattr_t*) __nonnull((1));
+int pthread_condattr_getclock(const pthread_condattr_t*, clockid_t*) __nonnull((1, 2));
 int pthread_condattr_getpshared(const pthread_condattr_t*, int*) __nonnull((1, 2));
 int pthread_condattr_init(pthread_condattr_t*) __nonnull((1));
+int pthread_condattr_setclock(pthread_condattr_t*, clockid_t) __nonnull((1));
 int pthread_condattr_setpshared(pthread_condattr_t*, int) __nonnull((1));
 
 int pthread_cond_broadcast(pthread_cond_t*) __nonnull((1));
@@ -155,6 +188,8 @@
 
 void* pthread_getspecific(pthread_key_t);
 
+pid_t pthread_gettid_np(pthread_t);
+
 int pthread_join(pthread_t, void**);
 
 int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1));
@@ -172,7 +207,7 @@
 int pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1));
 int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1));
 int pthread_mutex_lock(pthread_mutex_t*) __nonnull((1));
-int pthread_mutex_timedlock(pthread_mutex_t*, struct timespec*) __nonnull((1, 2));
+int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2));
 int pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1));
 int pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1));
 
@@ -193,7 +228,7 @@
 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) __nonnull((1));
 int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1));
 
-pthread_t pthread_self(void);
+pthread_t pthread_self(void) __pure2;
 
 int pthread_setname_np(pthread_t, const char*) __nonnull((2));
 
@@ -232,32 +267,17 @@
 
 #if !defined(__LP64__)
 
-/* Deprecated by POSIX. TODO: support for LP64 but add deprecated attribute instead? */
-int pthread_attr_getstackaddr(const pthread_attr_t*, void**) __nonnull((1, 2)); /* deprecated */
-int pthread_attr_setstackaddr(pthread_attr_t*, void*) __nonnull((1)); /* deprecated */
-
-/* Bionic additions that are deprecated even in the 32-bit ABI. */
+// Bionic additions that are deprecated even in the 32-bit ABI.
+//
+// TODO: Remove them once chromium_org / NFC have switched over.
 int pthread_cond_timedwait_monotonic_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
 int pthread_cond_timedwait_monotonic(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
-#define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC 1
 
-/*
- * Like pthread_cond_timedwait except 'reltime' is relative to the current time.
- * TODO: not like glibc; include in LP64?
- */
-int pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
-#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1
+int pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
+#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1 /* TODO: stop defining this to push LP32 off this API sooner. */
+int pthread_cond_timeout_np(pthread_cond_t*, pthread_mutex_t*, unsigned) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
 
-/* TODO: not like glibc; include in LP64? */
-int pthread_cond_timeout_np(pthread_cond_t*, pthread_mutex_t*, unsigned);
-
-/* Like pthread_mutex_lock(), but will wait up to 'msecs' milli-seconds
- * before returning. Same return values as pthread_mutex_trylock though, i.e.
- * returns EBUSY if the lock could not be acquired after the timeout expired.
- *
- * TODO: replace with pthread_mutex_timedlock_np for LP64.
- */
-int pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned);
+int pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned) __attribute__((deprecated("use pthread_mutex_timedlock instead")));
 
 #endif /* !defined(__LP64__) */
 
diff --git a/libc/include/pwd.h b/libc/include/pwd.h
index 6f3fad5..6d483c0 100644
--- a/libc/include/pwd.h
+++ b/libc/include/pwd.h
@@ -100,12 +100,15 @@
 
 struct passwd
 {
-    char* pw_name;
-    char* pw_passwd;
-    uid_t pw_uid;
-    gid_t pw_gid;
-    char* pw_dir;
-    char* pw_shell;
+  char* pw_name;
+  char* pw_passwd;
+  uid_t pw_uid;
+  gid_t pw_gid;
+#ifdef __LP64__
+  char* pw_gecos;
+#endif
+  char* pw_dir;
+  char* pw_shell;
 };
 
 __BEGIN_DECLS
diff --git a/libc/include/resolv.h b/libc/include/resolv.h
index 36b93ee..c8899ed 100644
--- a/libc/include/resolv.h
+++ b/libc/include/resolv.h
@@ -37,6 +37,7 @@
 #include <netinet/in.h>
 
 __BEGIN_DECLS
+#pragma GCC visibility push(default)
 
 struct res_state;
 
@@ -52,6 +53,7 @@
 extern int dn_comp(const char*, u_char*, int, u_char**, u_char**);
 extern int dn_expand(const u_char*, const u_char*, const u_char*, char*, int);
 
+#pragma GCC visibility pop
 __END_DECLS
 
 #endif /* _RESOLV_H_ */
diff --git a/libc/include/sched.h b/libc/include/sched.h
index 7649e83..e43b6cc 100644
--- a/libc/include/sched.h
+++ b/libc/include/sched.h
@@ -59,151 +59,90 @@
 extern int sched_getcpu(void);
 extern int setns(int, int);
 
-/* Our implementation supports up to 32 independent CPUs, which is also
- * the maximum supported by the kernel at the moment. GLibc uses 1024 by
- * default.
- *
- * If you want to use more than that, you should use CPU_ALLOC() / CPU_FREE()
- * and the CPU_XXX_S() macro variants.
- */
-#define CPU_SETSIZE   32
+#ifdef __LP64__
+#define CPU_SETSIZE 1024
+#else
+#define CPU_SETSIZE 32
+#endif
 
-#define __CPU_BITTYPE    unsigned long int  /* mandated by the kernel  */
-#define __CPU_BITSHIFT   5                  /* should be log2(BITTYPE) */
-#define __CPU_BITS       (1 << __CPU_BITSHIFT)
-#define __CPU_ELT(x)     ((x) >> __CPU_BITSHIFT)
-#define __CPU_MASK(x)    ((__CPU_BITTYPE)1 << ((x) & (__CPU_BITS-1)))
+#define __CPU_BITTYPE  unsigned long int  /* mandated by the kernel  */
+#define __CPU_BITS     (8 * sizeof(__CPU_BITTYPE))
+#define __CPU_ELT(x)   ((x) / __CPU_BITS)
+#define __CPU_MASK(x)  ((__CPU_BITTYPE)1 << ((x) & (__CPU_BITS - 1)))
 
 typedef struct {
-    __CPU_BITTYPE  __bits[ CPU_SETSIZE / __CPU_BITS ];
+  __CPU_BITTYPE  __bits[ CPU_SETSIZE / __CPU_BITS ];
 } cpu_set_t;
 
 extern int sched_setaffinity(pid_t pid, size_t setsize, const cpu_set_t* set);
 
 extern int sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set);
 
-/* Provide optimized implementation for 32-bit cpu_set_t */
-#if CPU_SETSIZE == __CPU_BITS
+#define CPU_ZERO(set)          CPU_ZERO_S(sizeof(cpu_set_t), set)
+#define CPU_SET(cpu, set)      CPU_SET_S(cpu, sizeof(cpu_set_t), set)
+#define CPU_CLR(cpu, set)      CPU_CLR_S(cpu, sizeof(cpu_set_t), set)
+#define CPU_ISSET(cpu, set)    CPU_ISSET_S(cpu, sizeof(cpu_set_t), set)
+#define CPU_COUNT(set)         CPU_COUNT_S(sizeof(cpu_set_t), set)
+#define CPU_EQUAL(set1, set2)  CPU_EQUAL_S(sizeof(cpu_set_t), set1, set2)
 
-#  define CPU_ZERO(set_)   \
-    do{ \
-        (set_)->__bits[0] = 0; \
-    }while(0)
+#define CPU_AND(dst, set1, set2)  __CPU_OP(dst, set1, set2, &)
+#define CPU_OR(dst, set1, set2)   __CPU_OP(dst, set1, set2, |)
+#define CPU_XOR(dst, set1, set2)  __CPU_OP(dst, set1, set2, ^)
 
-#  define CPU_SET(cpu_,set_) \
-    do {\
-        size_t __cpu = (cpu_); \
-        if (__cpu < CPU_SETSIZE) \
-            (set_)->__bits[0] |= __CPU_MASK(__cpu); \
-    }while (0)
-
-#  define CPU_CLR(cpu_,set_) \
-    do {\
-        size_t __cpu = (cpu_); \
-        if (__cpu < CPU_SETSIZE) \
-            (set_)->__bits[0] &= ~__CPU_MASK(__cpu); \
-    }while (0)
-
-#  define CPU_ISSET(cpu_, set_) \
-    (__extension__({\
-        size_t  __cpu = (cpu_); \
-        (cpu_ < CPU_SETSIZE) \
-            ? ((set_)->__bits[0] & __CPU_MASK(__cpu)) != 0 \
-            : 0; \
-    }))
-
-#  define CPU_EQUAL(set1_, set2_) \
-    ((set1_)->__bits[0] == (set2_)->__bits[0])
-
-#  define __CPU_OP(dst_, set1_, set2_, op_) \
-    do { \
-        (dst_)->__bits[0] = (set1_)->__bits[0] op_ (set2_)->__bits[0]; \
-    } while (0)
-
-#  define CPU_COUNT(set_)  __builtin_popcountl((set_)->__bits[0])
-
-#else /* CPU_SETSIZE != __CPU_BITS */
-
-#  define CPU_ZERO(set_)          CPU_ZERO_S(sizeof(cpu_set_t), set_)
-#  define CPU_SET(cpu_,set_)      CPU_SET_S(cpu_,sizeof(cpu_set_t),set_)
-#  define CPU_CLR(cpu_,set_)      CPU_CLR_S(cpu_,sizeof(cpu_set_t),set_)
-#  define CPU_ISSET(cpu_,set_)    CPU_ISSET_S(cpu_,sizeof(cpu_set_t),set_)
-#  define CPU_COUNT(set_)         CPU_COUNT_S(sizeof(cpu_set_t),set_)
-#  define CPU_EQUAL(set1_,set2_)  CPU_EQUAL_S(sizeof(cpu_set_t),set1_,set2_)
-
-#  define __CPU_OP(dst_,set1_,set2_,op_)  __CPU_OP_S(sizeof(cpu_set_t),dst_,set1_,set2_,op_)
-
-#endif /* CPU_SETSIZE != __CPU_BITS */
-
-#define CPU_AND(set1_,set2_)   __CPU_OP(set1_,set2_,&)
-#define CPU_OR(set1_,set2_)    __CPU_OP(set1_,set2_,|)
-#define CPU_XOR(set1_,set2_)   __CPU_OP(set1_,set2_,^)
+#define __CPU_OP(dst, set1, set2, op)  __CPU_OP_S(sizeof(cpu_set_t), dst, set1, set2, op)
 
 /* Support for dynamically-allocated cpu_set_t */
 
 #define CPU_ALLOC_SIZE(count) \
-    __CPU_ELT((count) + (__CPU_BITS-1))*sizeof(__CPU_BITTYPE)
+  __CPU_ELT((count) + (__CPU_BITS - 1)) * sizeof(__CPU_BITTYPE)
 
-#define CPU_ALLOC(count)   __sched_cpualloc((count));
-#define CPU_FREE(set)      __sched_cpufree((set))
+#define CPU_ALLOC(count)  __sched_cpualloc((count))
+#define CPU_FREE(set)     __sched_cpufree((set))
 
 extern cpu_set_t* __sched_cpualloc(size_t count);
 extern void       __sched_cpufree(cpu_set_t* set);
 
-#define CPU_ZERO_S(setsize_,set_)  \
-    do { \
-        size_t __nn = 0; \
-        size_t __nn_max = (setsize_)/sizeof(__CPU_BITTYPE); \
-        for (; __nn < __nn_max; __nn++) \
-            (set_)->__bits[__nn] = 0; \
-    } while (0)
+#define CPU_ZERO_S(setsize, set)  __builtin_memset(set, 0, setsize)
 
-#define CPU_SET_S(cpu_,setsize_,set_) \
-    do { \
-        size_t __cpu = (cpu_); \
-        if (__cpu < 8*(setsize_)) \
-            (set_)->__bits[__CPU_ELT(__cpu)] |= __CPU_MASK(__cpu); \
-    } while (0)
+#define CPU_SET_S(cpu, setsize, set) \
+  do { \
+    size_t __cpu = (cpu); \
+    if (__cpu < 8 * (setsize)) \
+      (set)->__bits[__CPU_ELT(__cpu)] |= __CPU_MASK(__cpu); \
+  } while (0)
 
-#define CPU_CLR_S(cpu_,setsize_,set_) \
-    do { \
-        size_t __cpu = (cpu_); \
-        if (__cpu < 8*(setsize_)) \
-            (set_)->__bits[__CPU_ELT(__cpu)] &= ~__CPU_MASK(__cpu); \
-    } while (0)
+#define CPU_CLR_S(cpu, setsize, set) \
+  do { \
+    size_t __cpu = (cpu); \
+    if (__cpu < 8 * (setsize)) \
+      (set)->__bits[__CPU_ELT(__cpu)] &= ~__CPU_MASK(__cpu); \
+  } while (0)
 
-#define CPU_ISSET_S(cpu_, setsize_, set_) \
-    (__extension__ ({ \
-        size_t __cpu = (cpu_); \
-        (__cpu < 8*(setsize_)) \
-          ? ((set_)->__bits[__CPU_ELT(__cpu)] & __CPU_MASK(__cpu)) != 0 \
-          : 0; \
-    }))
+#define CPU_ISSET_S(cpu, setsize, set) \
+  (__extension__ ({ \
+    size_t __cpu = (cpu); \
+    (__cpu < 8 * (setsize)) \
+      ? ((set)->__bits[__CPU_ELT(__cpu)] & __CPU_MASK(__cpu)) != 0 \
+      : 0; \
+  }))
 
-#define CPU_EQUAL_S(setsize_, set1_, set2_) \
-    (__extension__ ({ \
-        __const __CPU_BITTYPE* __src1 = (set1_)->__bits; \
-        __const __CPU_BITTYPE* __src2 = (set2_)->__bits; \
-        size_t __nn = 0, __nn_max = (setsize_)/sizeof(__CPU_BITTYPE); \
-        for (; __nn < __nn_max; __nn++) { \
-            if (__src1[__nn] != __src2[__nn]) \
-                break; \
-        } \
-        __nn == __nn_max; \
-    }))
+#define CPU_EQUAL_S(setsize, set1, set2)  (__builtin_memcmp(set1, set2, setsize) == 0)
 
-#define __CPU_OP_S(setsize_, dstset_, srcset1_, srcset2_, op) \
-    do { \
-        cpu_set_t* __dst = (dstset); \
-        const __CPU_BITTYPE* __src1 = (srcset1)->__bits; \
-        const __CPU_BITTYPE* __src2 = (srcset2)->__bits; \
-        size_t __nn = 0, __nn_max = (setsize_)/sizeof(__CPU_BITTYPE); \
-        for (; __nn < __nn_max; __nn++) \
-            (__dst)->__bits[__nn] = __src1[__nn] op __src2[__nn]; \
-    } while (0)
+#define CPU_AND_S(setsize, dst, set1, set2)  __CPU_OP_S(setsize, dst, set1, set2, &)
+#define CPU_OR_S(setsize, dst, set1, set2)   __CPU_OP_S(setsize, dst, set1, set2, |)
+#define CPU_XOR_S(setsize, dst, set1, set2)  __CPU_OP_S(setsize, dst, set1, set2, ^)
 
-#define CPU_COUNT_S(setsize_, set_) \
-    __sched_cpucount((setsize_), (set_))
+#define __CPU_OP_S(setsize, dstset, srcset1, srcset2, op) \
+  do { \
+    cpu_set_t* __dst = (dstset); \
+    const __CPU_BITTYPE* __src1 = (srcset1)->__bits; \
+    const __CPU_BITTYPE* __src2 = (srcset2)->__bits; \
+    size_t __nn = 0, __nn_max = (setsize)/sizeof(__CPU_BITTYPE); \
+    for (; __nn < __nn_max; __nn++) \
+      (__dst)->__bits[__nn] = __src1[__nn] op __src2[__nn]; \
+  } while (0)
+
+#define CPU_COUNT_S(setsize, set)  __sched_cpucount((setsize), (set))
 
 extern int __sched_cpucount(size_t setsize, cpu_set_t* set);
 
diff --git a/libc/include/search.h b/libc/include/search.h
index e12e49e..9b01e12 100644
--- a/libc/include/search.h
+++ b/libc/include/search.h
@@ -10,30 +10,37 @@
 #define _SEARCH_H_
 
 #include <sys/cdefs.h>
-#include <sys/_types.h>
+#include <sys/types.h>
 
-typedef	enum {
-	preorder,
-	postorder,
-	endorder,
-	leaf
+typedef enum {
+  preorder,
+  postorder,
+  endorder,
+  leaf
 } VISIT;
 
 #ifdef _SEARCH_PRIVATE
-typedef	struct node {
-	char         *key;
-	struct node  *llink, *rlink;
+typedef struct node {
+  char* key;
+  struct node* llink;
+  struct node* rlink;
 } node_t;
 #endif
 
 __BEGIN_DECLS
-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));
-void	 tdestroy(void *, void (*)(void *));
+
+void insque(void*, void*);
+void remque(void*);
+
+void* lfind(const void*, const void*, size_t*, size_t, int (*)(const void*, const void*));
+void* lsearch(const void*, void*, size_t*, size_t, int (*)(const void*, const void*));
+
+void* tdelete(const void* __restrict, void** __restrict, int (*)(const void*, const void*));
+void tdestroy(void*, void (*)(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));
+
 __END_DECLS
 
 #endif /* !_SEARCH_H_ */
diff --git a/libc/include/semaphore.h b/libc/include/semaphore.h
index 30e3123..7ae3c3a 100644
--- a/libc/include/semaphore.h
+++ b/libc/include/semaphore.h
@@ -33,10 +33,13 @@
 __BEGIN_DECLS
 
 typedef struct {
-    volatile unsigned int  count;
+  volatile unsigned int count;
+#ifdef __LP64__
+  int __reserved[3];
+#endif
 } sem_t;
 
-#define  SEM_FAILED  NULL
+#define SEM_FAILED NULL
 
 extern int sem_init(sem_t *sem, int pshared, unsigned int value);
 
diff --git a/libc/include/setjmp.h b/libc/include/setjmp.h
index 68fdcef..02b06f5 100644
--- a/libc/include/setjmp.h
+++ b/libc/include/setjmp.h
@@ -50,7 +50,6 @@
 
 int     _setjmp(jmp_buf);
 void    _longjmp(jmp_buf, int);
-void    longjmperror(void);
 
 int     setjmp(jmp_buf);
 void    longjmp(jmp_buf, int);
diff --git a/libc/include/sha1.h b/libc/include/sha1.h
deleted file mode 100644
index 7f6cf5d..0000000
--- a/libc/include/sha1.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SHA1_H_
-#define _SHA1_H_
-
-#warning "include <sys/sha1.h> instead for better portability"
-#include <sys/sha1.h>
-
-#endif
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 0159bf2..f1849c5 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -34,6 +34,7 @@
 #include <limits.h>		/* For LONG_BIT */
 #include <string.h>		/* For memset() */
 #include <sys/types.h>
+#include <asm/sigcontext.h>
 
 #if defined(__LP64__) || defined(__mips__)
 /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
@@ -51,20 +52,29 @@
 
 typedef int sig_atomic_t;
 
-/* TODO: 64-bit: we should probably #undef the uapi NSIG and add a unit test that NSIG == _NSIG && NSIG >= 64. */
-#ifndef _NSIG
-#  define _NSIG 64
-#endif
-#ifndef NSIG
-#  define NSIG _NSIG
+/* The arm and x86 kernel header files don't define _NSIG. */
+#ifndef _KERNEL__NSIG
+#define _KERNEL__NSIG 64
 #endif
 
+/* Userspace's NSIG is the kernel's _NSIG + 1. */
+#define _NSIG (_KERNEL__NSIG + 1)
+#define NSIG _NSIG
+
+/* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
+#define SIGRTMIN (__libc_current_sigrtmin())
+#define SIGRTMAX (__libc_current_sigrtmax())
+extern int __libc_current_sigrtmin(void);
+extern int __libc_current_sigrtmax(void);
+
 extern const char* const sys_siglist[];
-extern const char* const sys_signame[];
+extern const char* const sys_signame[]; /* BSD compatibility. */
 
 typedef __sighandler_t sig_t; /* BSD compatibility. */
 typedef __sighandler_t sighandler_t; /* glibc compatibility. */
 
+#define si_timerid si_tid /* glibc compatibility. */
+
 #if defined(__LP64__)
 
 struct sigaction {
@@ -93,8 +103,6 @@
 extern int sigaction(int, const struct sigaction*, struct sigaction*);
 
 extern sighandler_t signal(int, sighandler_t);
-extern sighandler_t bsd_signal(int, sighandler_t);
-extern sighandler_t sysv_signal(int, sighandler_t);
 
 extern int siginterrupt(int, int);
 
diff --git a/libc/include/stdatomic.h b/libc/include/stdatomic.h
new file mode 100644
index 0000000..3db25a7
--- /dev/null
+++ b/libc/include/stdatomic.h
@@ -0,0 +1,575 @@
+/*-
+ * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
+ *                    David Chisnall <theraven@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _STDATOMIC_H_
+#define	_STDATOMIC_H_
+
+#include <sys/cdefs.h>
+
+
+#if defined(__cplusplus) && defined(_USING_LIBCXX)
+# ifdef __clang__
+#  if __has_feature(cxx_atomic)
+#   define _STDATOMIC_HAVE_ATOMIC
+#  endif
+# else /* gcc */
+#  if __GNUC_PREREQ(4, 7)
+#   define _STDATOMIC_HAVE_ATOMIC
+#  endif
+# endif
+#endif
+
+#ifdef _STDATOMIC_HAVE_ATOMIC
+
+/* We have a usable C++ <atomic>; use it instead.  */
+
+#include <atomic>
+
+#undef _Atomic
+        /* Also defined by <atomic> for gcc.  But not used in macros. */
+        /* Also a clang intrinsic.                                    */
+        /* Should not be used by client code before this file is      */
+        /* included.  The definitions in <atomic> themselves see      */
+        /* the old definition, as they should.                        */
+        /* Client code sees the following definition.                 */
+
+#define _Atomic(t) std::atomic<t>
+
+using std::atomic_is_lock_free;
+using std::atomic_init;
+using std::atomic_store;
+using std::atomic_store_explicit;
+using std::atomic_load;
+using std::atomic_load_explicit;
+using std::atomic_exchange;
+using std::atomic_exchange_explicit;
+using std::atomic_compare_exchange_strong;
+using std::atomic_compare_exchange_strong_explicit;
+using std::atomic_compare_exchange_weak;
+using std::atomic_compare_exchange_weak_explicit;
+using std::atomic_fetch_add;
+using std::atomic_fetch_add_explicit;
+using std::atomic_fetch_sub;
+using std::atomic_fetch_sub_explicit;
+using std::atomic_fetch_or;
+using std::atomic_fetch_or_explicit;
+using std::atomic_fetch_xor;
+using std::atomic_fetch_xor_explicit;
+using std::atomic_fetch_and;
+using std::atomic_fetch_and_explicit;
+using std::atomic_thread_fence;
+using std::atomic_signal_fence;
+
+using std::memory_order;
+using std::memory_order_relaxed;
+using std::memory_order_consume;
+using std::memory_order_release;
+using std::memory_order_acq_rel;
+using std::memory_order_seq_cst;
+
+using std::atomic_bool;
+using std::atomic_char;
+using std::atomic_schar;
+using std::atomic_uchar;
+using std::atomic_short;
+using std::atomic_ushort;
+using std::atomic_int;
+using std::atomic_uint;
+using std::atomic_long;
+using std::atomic_ulong;
+using std::atomic_llong;
+using std::atomic_ullong;
+using std::atomic_char16_t;
+using std::atomic_char32_t;
+using std::atomic_wchar_t;
+using std::atomic_int_least8_t;
+using std::atomic_uint_least8_t;
+using std::atomic_int_least16_t;
+using std::atomic_uint_least16_t;
+using std::atomic_int_least32_t;
+using std::atomic_uint_least32_t;
+using std::atomic_int_least64_t;
+using std::atomic_uint_least64_t;
+using std::atomic_int_fast8_t;
+using std::atomic_uint_fast8_t;
+using std::atomic_int_fast16_t;
+using std::atomic_uint_fast16_t;
+using std::atomic_int_fast32_t;
+using std::atomic_uint_fast32_t;
+using std::atomic_int_fast64_t;
+using std::atomic_uint_fast64_t;
+using std::atomic_intptr_t;
+using std::atomic_uintptr_t;
+using std::atomic_size_t;
+using std::atomic_ptrdiff_t;
+using std::atomic_intmax_t;
+using std::atomic_uintmax_t;
+
+#else /* <atomic> unavailable, possibly because this is C, not C++ */
+
+#include <sys/types.h>
+#include <stdbool.h>
+
+/*
+ * C: Do it ourselves.
+ * Note that the runtime representation defined here should be compatible
+ * with the C++ one, i.e. an _Atomic(T) needs to contain the same
+ * bits as a T.
+ */
+
+#include <stddef.h>  /* For ptrdiff_t.                          */
+#include <stdint.h>  /* TODO: Should pollute namespace less.    */
+#if __STDC_VERSION__ >= 201112L
+# include <uchar.h>  /* For char16_t and char32_t.              */
+#endif
+
+#ifdef __clang__
+# if __has_extension(c_atomic) || __has_extension(cxx_atomic)
+#  define       __CLANG_ATOMICS
+# else
+#  error "stdatomic.h does not support your compiler"
+# endif
+# if __has_builtin(__sync_swap)
+#  define __HAS_BUILTIN_SYNC_SWAP
+# endif
+#else
+# if __GNUC_PREREQ(4, 7)
+#  define	__GNUC_ATOMICS
+# else
+#  define	__SYNC_ATOMICS
+#  ifdef __cplusplus
+#   define       __ATOMICS_AVOID_DOT_INIT
+#  endif
+# endif
+#endif
+
+/*
+ * 7.17.1 Atomic lock-free macros.
+ */
+
+#ifdef __GCC_ATOMIC_BOOL_LOCK_FREE
+#define	ATOMIC_BOOL_LOCK_FREE		__GCC_ATOMIC_BOOL_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_BOOL_LOCK_FREE           2 /* For all modern platforms */
+#endif
+#ifdef __GCC_ATOMIC_CHAR_LOCK_FREE
+#define	ATOMIC_CHAR_LOCK_FREE		__GCC_ATOMIC_CHAR_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_CHAR_LOCK_FREE           2
+#endif
+#ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE
+#define	ATOMIC_CHAR16_T_LOCK_FREE	__GCC_ATOMIC_CHAR16_T_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_CHAR16_T_LOCK_FREE       2
+#endif
+#ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE
+#define	ATOMIC_CHAR32_T_LOCK_FREE	__GCC_ATOMIC_CHAR32_T_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_CHAR32_T_LOCK_FREE       2
+#endif
+#ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE
+#define	ATOMIC_WCHAR_T_LOCK_FREE	__GCC_ATOMIC_WCHAR_T_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_WCHAR_T_LOCK_FREE        2
+#endif
+#ifdef __GCC_ATOMIC_SHORT_LOCK_FREE
+#define	ATOMIC_SHORT_LOCK_FREE		__GCC_ATOMIC_SHORT_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_SHORT_LOCK_FREE          2
+#endif
+#ifdef __GCC_ATOMIC_INT_LOCK_FREE
+#define	ATOMIC_INT_LOCK_FREE		__GCC_ATOMIC_INT_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_INT_LOCK_FREE            2
+#endif
+#ifdef __GCC_ATOMIC_LONG_LOCK_FREE
+#define	ATOMIC_LONG_LOCK_FREE		__GCC_ATOMIC_LONG_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_LONG_LOCK_FREE           2
+#endif
+#ifdef __GCC_ATOMIC_LLONG_LOCK_FREE
+#define	ATOMIC_LLONG_LOCK_FREE		__GCC_ATOMIC_LLONG_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_LLONG_LOCK_FREE          1 /* maybe */
+#endif
+#ifdef __GCC_ATOMIC_POINTER_LOCK_FREE
+#define	ATOMIC_POINTER_LOCK_FREE	__GCC_ATOMIC_POINTER_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_POINTER_LOCK_FREE        2
+#endif
+
+/*
+ * 7.17.2 Initialization.
+ */
+
+#if defined(__CLANG_ATOMICS)
+#define	ATOMIC_VAR_INIT(value)		(value)
+#define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
+#else
+#ifdef __ATOMICS_AVOID_DOT_INIT
+#define	ATOMIC_VAR_INIT(value)		{ value }
+#else
+#define	ATOMIC_VAR_INIT(value)		{ .__val = (value) }
+#endif
+#define	atomic_init(obj, value)		((void)((obj)->__val = (value)))
+#endif
+
+/*
+ * Clang and recent GCC both provide predefined macros for the memory
+ * orderings.  If we are using a compiler that doesn't define them, use the
+ * clang values - these will be ignored in the fallback path.
+ */
+
+#ifndef __ATOMIC_RELAXED
+#define __ATOMIC_RELAXED		0
+#endif
+#ifndef __ATOMIC_CONSUME
+#define __ATOMIC_CONSUME		1
+#endif
+#ifndef __ATOMIC_ACQUIRE
+#define __ATOMIC_ACQUIRE		2
+#endif
+#ifndef __ATOMIC_RELEASE
+#define __ATOMIC_RELEASE		3
+#endif
+#ifndef __ATOMIC_ACQ_REL
+#define __ATOMIC_ACQ_REL		4
+#endif
+#ifndef __ATOMIC_SEQ_CST
+#define __ATOMIC_SEQ_CST		5
+#endif
+
+/*
+ * 7.17.3 Order and consistency.
+ *
+ * The memory_order_* constants that denote the barrier behaviour of the
+ * atomic operations.
+ * The enum values must be identical to those used by the
+ * C++ <atomic> header.
+ */
+
+typedef enum {
+	memory_order_relaxed = __ATOMIC_RELAXED,
+	memory_order_consume = __ATOMIC_CONSUME,
+	memory_order_acquire = __ATOMIC_ACQUIRE,
+	memory_order_release = __ATOMIC_RELEASE,
+	memory_order_acq_rel = __ATOMIC_ACQ_REL,
+	memory_order_seq_cst = __ATOMIC_SEQ_CST
+} memory_order;
+
+/*
+ * 7.17.4 Fences.
+ */
+
+static __inline void
+atomic_thread_fence(memory_order __order __attribute__((unused)))
+{
+
+#ifdef __CLANG_ATOMICS
+	__c11_atomic_thread_fence(__order);
+#elif defined(__GNUC_ATOMICS)
+	__atomic_thread_fence(__order);
+#else
+	__sync_synchronize();
+#endif
+}
+
+static __inline void
+atomic_signal_fence(memory_order __order __attribute__((unused)))
+{
+
+#ifdef __CLANG_ATOMICS
+	__c11_atomic_signal_fence(__order);
+#elif defined(__GNUC_ATOMICS)
+	__atomic_signal_fence(__order);
+#else
+	__asm volatile ("" ::: "memory");
+#endif
+}
+
+/*
+ * 7.17.5 Lock-free property.
+ */
+
+#if defined(_KERNEL)
+/* Atomics in kernelspace are always lock-free. */
+#define	atomic_is_lock_free(obj) \
+	((void)(obj), (_Bool)1)
+#elif defined(__CLANG_ATOMICS)
+#define	atomic_is_lock_free(obj) \
+	__c11_atomic_is_lock_free(sizeof(*(obj)))
+#elif defined(__GNUC_ATOMICS)
+#define	atomic_is_lock_free(obj) \
+	__atomic_is_lock_free(sizeof((obj)->__val), &(obj)->__val)
+#else
+#define	atomic_is_lock_free(obj) \
+	((void)(obj), sizeof((obj)->__val) <= sizeof(void *))
+#endif
+
+/*
+ * 7.17.6 Atomic integer types.
+ */
+
+#ifndef __CLANG_ATOMICS
+/*
+ * No native support for _Atomic(). Place object in structure to prevent
+ * most forms of direct non-atomic access.
+ */
+#define _Atomic(T)              struct { T volatile __val; }
+#endif
+
+typedef _Atomic(bool)			atomic_bool;
+typedef _Atomic(char)			atomic_char;
+typedef _Atomic(signed char)		atomic_schar;
+typedef _Atomic(unsigned char)		atomic_uchar;
+typedef _Atomic(short)			atomic_short;
+typedef _Atomic(unsigned short)		atomic_ushort;
+typedef _Atomic(int)			atomic_int;
+typedef _Atomic(unsigned int)		atomic_uint;
+typedef _Atomic(long)			atomic_long;
+typedef _Atomic(unsigned long)		atomic_ulong;
+typedef _Atomic(long long)		atomic_llong;
+typedef _Atomic(unsigned long long)	atomic_ullong;
+#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
+  typedef _Atomic(char16_t)		atomic_char16_t;
+  typedef _Atomic(char32_t)		atomic_char32_t;
+#endif
+typedef _Atomic(wchar_t)		atomic_wchar_t;
+typedef _Atomic(int_least8_t)		atomic_int_least8_t;
+typedef _Atomic(uint_least8_t)	atomic_uint_least8_t;
+typedef _Atomic(int_least16_t)	atomic_int_least16_t;
+typedef _Atomic(uint_least16_t)	atomic_uint_least16_t;
+typedef _Atomic(int_least32_t)	atomic_int_least32_t;
+typedef _Atomic(uint_least32_t)	atomic_uint_least32_t;
+typedef _Atomic(int_least64_t)	atomic_int_least64_t;
+typedef _Atomic(uint_least64_t)	atomic_uint_least64_t;
+typedef _Atomic(int_fast8_t)		atomic_int_fast8_t;
+typedef _Atomic(uint_fast8_t)		atomic_uint_fast8_t;
+typedef _Atomic(int_fast16_t)		atomic_int_fast16_t;
+typedef _Atomic(uint_fast16_t)	atomic_uint_fast16_t;
+typedef _Atomic(int_fast32_t)		atomic_int_fast32_t;
+typedef _Atomic(uint_fast32_t)	atomic_uint_fast32_t;
+typedef _Atomic(int_fast64_t)		atomic_int_fast64_t;
+typedef _Atomic(uint_fast64_t)	atomic_uint_fast64_t;
+typedef _Atomic(intptr_t)		atomic_intptr_t;
+typedef _Atomic(uintptr_t)		atomic_uintptr_t;
+typedef _Atomic(size_t)		atomic_size_t;
+typedef _Atomic(ptrdiff_t)		atomic_ptrdiff_t;
+typedef _Atomic(intmax_t)		atomic_intmax_t;
+typedef _Atomic(uintmax_t)		atomic_uintmax_t;
+
+/*
+ * 7.17.7 Operations on atomic types.
+ */
+
+/*
+ * Compiler-specific operations.
+ */
+
+#if defined(__CLANG_ATOMICS)
+#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 defined(__GNUC_ATOMICS)
+#define	atomic_compare_exchange_strong_explicit(object, expected,	\
+    desired, success, failure)						\
+	__atomic_compare_exchange_n(&(object)->__val, expected,		\
+	    desired, 0, success, failure)
+#define	atomic_compare_exchange_weak_explicit(object, expected,		\
+    desired, success, failure)						\
+	__atomic_compare_exchange_n(&(object)->__val, expected,		\
+	    desired, 1, success, failure)
+#define	atomic_exchange_explicit(object, desired, order)		\
+	__atomic_exchange_n(&(object)->__val, desired, order)
+#define	atomic_fetch_add_explicit(object, operand, order)		\
+	__atomic_fetch_add(&(object)->__val, operand, order)
+#define	atomic_fetch_and_explicit(object, operand, order)		\
+	__atomic_fetch_and(&(object)->__val, operand, order)
+#define	atomic_fetch_or_explicit(object, operand, order)		\
+	__atomic_fetch_or(&(object)->__val, operand, order)
+#define	atomic_fetch_sub_explicit(object, operand, order)		\
+	__atomic_fetch_sub(&(object)->__val, operand, order)
+#define	atomic_fetch_xor_explicit(object, operand, order)		\
+	__atomic_fetch_xor(&(object)->__val, operand, order)
+#define	atomic_load_explicit(object, order)				\
+	__atomic_load_n(&(object)->__val, order)
+#define	atomic_store_explicit(object, desired, order)			\
+	__atomic_store_n(&(object)->__val, desired, order)
+#else
+#define	__atomic_apply_stride(object, operand) \
+	(((__typeof__((object)->__val))0) + (operand))
+#define	atomic_compare_exchange_strong_explicit(object, expected,	\
+    desired, success, failure)	__extension__ ({			\
+	__typeof__(expected) __ep = (expected);				\
+	__typeof__(*__ep) __e = *__ep;					\
+	(void)(success); (void)(failure);				\
+	(bool)((*__ep = __sync_val_compare_and_swap(&(object)->__val,	\
+	    __e, desired)) == __e);					\
+})
+#define	atomic_compare_exchange_weak_explicit(object, expected,		\
+    desired, success, failure)						\
+	atomic_compare_exchange_strong_explicit(object, expected,	\
+		desired, success, failure)
+#ifdef __HAS_BUILTIN_SYNC_SWAP
+/* Clang provides a full-barrier atomic exchange - use it if available. */
+#define	atomic_exchange_explicit(object, desired, order)		\
+	((void)(order), __sync_swap(&(object)->__val, desired))
+#else
+/*
+ * __sync_lock_test_and_set() is only an acquire barrier in theory (although in
+ * practice it is usually a full barrier) so we need an explicit barrier before
+ * it.
+ */
+#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)->__val, __d);			\
+})
+#endif
+#define	atomic_fetch_add_explicit(object, operand, order)		\
+	((void)(order), __sync_fetch_and_add(&(object)->__val,		\
+	    __atomic_apply_stride(object, operand)))
+#define	atomic_fetch_and_explicit(object, operand, order)		\
+	((void)(order), __sync_fetch_and_and(&(object)->__val, operand))
+#define	atomic_fetch_or_explicit(object, operand, order)		\
+	((void)(order), __sync_fetch_and_or(&(object)->__val, operand))
+#define	atomic_fetch_sub_explicit(object, operand, order)		\
+	((void)(order), __sync_fetch_and_sub(&(object)->__val,		\
+	    __atomic_apply_stride(object, operand)))
+#define	atomic_fetch_xor_explicit(object, operand, order)		\
+	((void)(order), __sync_fetch_and_xor(&(object)->__val, operand))
+#define	atomic_load_explicit(object, order)				\
+	((void)(order), __sync_fetch_and_add(&(object)->__val, 0))
+#define	atomic_store_explicit(object, desired, order)			\
+	((void)atomic_exchange_explicit(object, desired, order))
+#endif
+
+/*
+ * Convenience functions.
+ *
+ * Don't provide these in kernel space. In kernel space, we should be
+ * disciplined enough to always provide explicit barriers.
+ */
+
+#ifndef _KERNEL
+#define	atomic_compare_exchange_strong(object, expected, desired)	\
+	atomic_compare_exchange_strong_explicit(object, expected,	\
+	    desired, memory_order_seq_cst, memory_order_seq_cst)
+#define	atomic_compare_exchange_weak(object, expected, desired)		\
+	atomic_compare_exchange_weak_explicit(object, expected,		\
+	    desired, memory_order_seq_cst, memory_order_seq_cst)
+#define	atomic_exchange(object, desired)				\
+	atomic_exchange_explicit(object, desired, memory_order_seq_cst)
+#define	atomic_fetch_add(object, operand)				\
+	atomic_fetch_add_explicit(object, operand, memory_order_seq_cst)
+#define	atomic_fetch_and(object, operand)				\
+	atomic_fetch_and_explicit(object, operand, memory_order_seq_cst)
+#define	atomic_fetch_or(object, operand)				\
+	atomic_fetch_or_explicit(object, operand, memory_order_seq_cst)
+#define	atomic_fetch_sub(object, operand)				\
+	atomic_fetch_sub_explicit(object, operand, memory_order_seq_cst)
+#define	atomic_fetch_xor(object, operand)				\
+	atomic_fetch_xor_explicit(object, operand, memory_order_seq_cst)
+#define	atomic_load(object)						\
+	atomic_load_explicit(object, memory_order_seq_cst)
+#define	atomic_store(object, desired)					\
+	atomic_store_explicit(object, desired, memory_order_seq_cst)
+#endif /* !_KERNEL */
+
+/*
+ * 7.17.8 Atomic flag type and operations.
+ *
+ * XXX: Assume atomic_bool can be used as an atomic_flag. Is there some
+ * kind of compiler built-in type we could use?
+ */
+
+typedef struct {
+	atomic_bool	__flag;
+} atomic_flag;
+
+#define	ATOMIC_FLAG_INIT		{ ATOMIC_VAR_INIT(false) }
+
+static __inline bool
+atomic_flag_test_and_set_explicit(volatile atomic_flag *__object,
+    memory_order __order)
+{
+	return (atomic_exchange_explicit(&__object->__flag, 1, __order));
+}
+
+static __inline void
+atomic_flag_clear_explicit(volatile atomic_flag *__object, memory_order __order)
+{
+
+	atomic_store_explicit(&__object->__flag, 0, __order);
+}
+
+#ifndef _KERNEL
+static __inline bool
+atomic_flag_test_and_set(volatile atomic_flag *__object)
+{
+
+	return (atomic_flag_test_and_set_explicit(__object,
+	    memory_order_seq_cst));
+}
+
+static __inline void
+atomic_flag_clear(volatile atomic_flag *__object)
+{
+
+	atomic_flag_clear_explicit(__object, memory_order_seq_cst);
+}
+#endif /* !_KERNEL */
+
+#endif /* <atomic> unavailable */
+
+#endif /* !_STDATOMIC_H_ */
diff --git a/libc/include/stdint.h b/libc/include/stdint.h
index be49485..a6f8505 100644
--- a/libc/include/stdint.h
+++ b/libc/include/stdint.h
@@ -30,7 +30,29 @@
 #define _STDINT_H
 
 #include <stddef.h>
-#include <sys/_types.h>
+#include <machine/wchar_limits.h>
+
+typedef __signed char __int8_t;
+typedef unsigned char __uint8_t;
+typedef short __int16_t;
+typedef unsigned short __uint16_t;
+typedef int __int32_t;
+typedef unsigned int __uint32_t;
+#if __LP64__
+typedef long __int64_t;
+typedef unsigned long __uint64_t;
+#else
+typedef long long __int64_t;
+typedef unsigned long long __uint64_t;
+#endif
+
+#if __LP64__
+typedef long __intptr_t;
+typedef unsigned long __uintptr_t;
+#else
+typedef int __intptr_t;
+typedef unsigned int __uintptr_t;
+#endif
 
 typedef __int8_t      int8_t;
 typedef __uint8_t     uint8_t;
@@ -44,40 +66,41 @@
 typedef __int64_t     int64_t;
 typedef __uint64_t    uint64_t;
 
-typedef int8_t        int_least8_t;
-typedef int8_t        int_fast8_t;
+typedef __intptr_t    intptr_t;
+typedef __uintptr_t   uintptr_t;
 
+typedef int8_t        int_least8_t;
 typedef uint8_t       uint_least8_t;
-typedef uint8_t       uint_fast8_t;
 
 typedef int16_t       int_least16_t;
-typedef int32_t       int_fast16_t;
-
 typedef uint16_t      uint_least16_t;
-typedef uint32_t      uint_fast16_t;
 
 typedef int32_t       int_least32_t;
-typedef int32_t       int_fast32_t;
-
 typedef uint32_t      uint_least32_t;
-typedef uint32_t      uint_fast32_t;
 
 typedef int64_t       int_least64_t;
-typedef int64_t       int_fast64_t;
-
 typedef uint64_t      uint_least64_t;
+
+typedef int8_t        int_fast8_t;
+typedef uint8_t       uint_fast8_t;
+
+typedef int64_t       int_fast64_t;
 typedef uint64_t      uint_fast64_t;
 
-#ifdef __LP64__
-typedef long          intptr_t;
-typedef unsigned long uintptr_t;
+#if defined(__LP64__)
+typedef int64_t       int_fast16_t;
+typedef uint64_t      uint_fast16_t;
+typedef int64_t       int_fast32_t;
+typedef uint64_t      uint_fast32_t;
 #else
-typedef int           intptr_t;
-typedef unsigned int  uintptr_t;
+typedef int32_t       int_fast16_t;
+typedef uint32_t      uint_fast16_t;
+typedef int32_t       int_fast32_t;
+typedef uint32_t      uint_fast32_t;
 #endif
 
-typedef uint64_t uintmax_t;
-typedef int64_t  intmax_t;
+typedef uint64_t      uintmax_t;
+typedef int64_t       intmax_t;
 
 /* Keep the kernel from trying to define these types... */
 #define __BIT_TYPES_DEFINED__
@@ -113,7 +136,7 @@
 #define INTMAX_C(c)       INT64_C(c)
 #define UINTMAX_C(c)      UINT64_C(c)
 
-#ifdef __LP64__
+#if defined(__LP64__)
 #  define INT64_C(c)      c ## L
 #  define UINT64_C(c)     c ## UL
 #  define INTPTR_C(c)     INT64_C(c)
@@ -178,15 +201,15 @@
 #define SIG_ATOMIC_MAX   INT32_MAX
 #define SIG_ATOMIC_MIN   INT32_MIN
 
-#ifndef WCHAR_MAX /* These might also have been defined by <wchar.h>. */
-#  define WCHAR_MAX      INT32_MAX
-#  define WCHAR_MIN      INT32_MIN
+#if defined(__WINT_UNSIGNED__)
+#  define WINT_MAX       UINT32_MAX
+#  define WINT_MIN       0
+#else
+#  define WINT_MAX       INT32_MAX
+#  define WINT_MIN       INT32_MIN
 #endif
 
-#define WINT_MAX         INT32_MAX
-#define WINT_MIN         INT32_MIN
-
-#ifdef __LP64__
+#if defined(__LP64__)
 #  define INTPTR_MIN     INT64_MIN
 #  define INTPTR_MAX     INT64_MAX
 #  define UINTPTR_MAX    UINT64_MAX
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index c241d94..43b0fbf 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -58,10 +58,17 @@
  */
 
 /* stdio buffers */
+#if defined(__LP64__)
+struct __sbuf {
+  unsigned char* _base;
+  size_t _size;
+};
+#else
 struct __sbuf {
 	unsigned char *_base;
 	int	_size;
 };
+#endif
 
 /*
  * stdio state variables.
@@ -94,8 +101,13 @@
 	unsigned char *_p;	/* current position in (some) buffer */
 	int	_r;		/* read space left for getc() */
 	int	_w;		/* write space left for putc() */
+#if defined(__LP64__)
+	int	_flags;		/* flags, below; this FILE is free if 0 */
+	int	_file;		/* fileno, if Unix descriptor, else -1 */
+#else
 	short	_flags;		/* flags, below; this FILE is free if 0 */
 	short	_file;		/* fileno, if Unix descriptor, else -1 */
+#endif
 	struct	__sbuf _bf;	/* the buffer (at least 1 byte, if !NULL) */
 	int	_lbfsize;	/* 0 or -_bf._size, for inline putc */
 
@@ -223,12 +235,6 @@
 	    FILE * __restrict);
 ssize_t	 getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
 
-#if __BSD_VISIBLE && !defined(__SYS_ERRLIST)
-#define __SYS_ERRLIST
-extern int sys_nerr;			/* perror(3) external variables */
-extern char *sys_errlist[];
-#endif
-
 void	 perror(const char *);
 int	 printf(const char * __restrict, ...)
 		__printflike(1, 2);
@@ -250,8 +256,13 @@
 int	 vprintf(const char * __restrict, __va_list)
 		__printflike(1, 0);
 
+int dprintf(int, const char * __restrict, ...) __printflike(2, 3);
+int vdprintf(int, const char * __restrict, __va_list) __printflike(2, 0);
+
 #ifndef __AUDIT__
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
 char* gets(char*) __warnattr("gets is very unsafe; consider using fgets");
+#endif
 int sprintf(char* __restrict, const char* __restrict, ...)
     __printflike(2, 3) __warnattr("sprintf is often misused; please use snprintf");
 char* tmpnam(char*) __warnattr("tmpnam possibly used unsafely; consider using mkstemp");
@@ -293,13 +304,8 @@
  */
 #if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
 #define	L_ctermid	1024	/* size for ctermid(); PATH_MAX */
-#define L_cuserid	9	/* size for cuserid(); UT_NAMESIZE + 1 */
 
 __BEGIN_DECLS
-#if 0 /* MISSING FROM BIONIC */
-char	*ctermid(char *);
-char	*cuserid(char *);
-#endif /* MISSING */
 FILE	*fdopen(int, const char *);
 int	 fileno(FILE *);
 
@@ -336,8 +342,6 @@
 		__printflike(2, 3);
 char	*fgetln(FILE * __restrict, size_t * __restrict);
 int	 fpurge(FILE *);
-int	 getw(FILE *);
-int	 putw(int, FILE *);
 void	 setbuffer(FILE *, char *, int);
 int	 setlinebuf(FILE *);
 int	 vasprintf(char ** __restrict, const char * __restrict,
@@ -359,98 +363,6 @@
 #define	fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
 #endif /* __BSD_VISIBLE */
 
-/*
- * Functions internal to the implementation.
- */
-__BEGIN_DECLS
-int	__srget(FILE *);
-int	__swbuf(int, FILE *);
-__END_DECLS
-
-/*
- * The __sfoo macros are here so that we can
- * define function versions in the C library.
- */
-#define	__sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
-#if defined(__GNUC__)
-static __inline int __sputc(int _c, FILE *_p) {
-	if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
-		return (*_p->_p++ = _c);
-	else
-		return (__swbuf(_c, _p));
-}
-#else
-/*
- * This has been tuned to generate reasonable code on the vax using pcc.
- */
-#define	__sputc(c, p) \
-	(--(p)->_w < 0 ? \
-		(p)->_w >= (p)->_lbfsize ? \
-			(*(p)->_p = (c)), *(p)->_p != '\n' ? \
-				(int)*(p)->_p++ : \
-				__swbuf('\n', p) : \
-			__swbuf((int)(c), p) : \
-		(*(p)->_p = (c), (int)*(p)->_p++))
-#endif
-
-#define	__sfeof(p)	(((p)->_flags & __SEOF) != 0)
-#define	__sferror(p)	(((p)->_flags & __SERR) != 0)
-#define	__sclearerr(p)	((void)((p)->_flags &= ~(__SERR|__SEOF)))
-#define	__sfileno(p)	((p)->_file)
-
-extern	int __isthreaded;
-
-#define	feof(p)		(!__isthreaded ? __sfeof(p) : (feof)(p))
-#define	ferror(p)	(!__isthreaded ? __sferror(p) : (ferror)(p))
-#define	clearerr(p)	(!__isthreaded ? __sclearerr(p) : (clearerr)(p))
-
-#if __POSIX_VISIBLE
-#define	fileno(p)	(!__isthreaded ? __sfileno(p) : (fileno)(p))
-#endif
-
-#define	getc(fp)	(!__isthreaded ? __sgetc(fp) : (getc)(fp))
-
-#if __BSD_VISIBLE
-/*
- * The macro implementations of putc and putc_unlocked are not
- * fully POSIX compliant; they do not set errno on failure
- */
-#define putc(x, fp)	(!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
-#endif /* __BSD_VISIBLE */
-
-#ifndef lint
-#if __POSIX_VISIBLE >= 199506
-#define	getc_unlocked(fp)	__sgetc(fp)
-/*
- * The macro implementations of putc and putc_unlocked are not
- * fully POSIX compliant; they do not set errno on failure
- */
-#if __BSD_VISIBLE
-#define putc_unlocked(x, fp)	__sputc(x, fp)
-#endif /* __BSD_VISIBLE */
-#endif /* __POSIX_VISIBLE >= 199506 */
-#endif /* lint */
-
-#define	getchar()	getc(stdin)
-#define	putchar(x)	putc(x, stdout)
-#define	getchar_unlocked()	getc_unlocked(stdin)
-#define	putchar_unlocked(c)	putc_unlocked(c, stdout)
-
-#ifdef _GNU_SOURCE
-/*
- * glibc defines dprintf(int, const char*, ...), which is poorly named
- * and likely to conflict with locally defined debugging printfs
- * fdprintf is a better name, and some programs that use fdprintf use a
- * #define fdprintf dprintf for compatibility
- */
-__BEGIN_DECLS
-int fdprintf(int, const char*, ...)
-		__printflike(2, 3);
-int vfdprintf(int, const char*, __va_list)
-		__printflike(2, 0);
-__END_DECLS
-#endif /* _GNU_SOURCE */
-
 #if defined(__BIONIC_FORTIFY)
 
 __BEGIN_DECLS
@@ -470,8 +382,10 @@
 }
 
 #if defined(__clang__)
-#define __wrap_snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__)
-#define snprintf(...) __wrap_snprintf(__VA_ARGS__)
+  #if !defined(snprintf)
+    #define __wrap_snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__)
+    #define snprintf(...) __wrap_snprintf(__VA_ARGS__)
+  #endif
 #else
 __BIONIC_FORTIFY_INLINE
 __printflike(3, 4)
@@ -483,8 +397,10 @@
 #endif
 
 #if defined(__clang__)
-#define __wrap_sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__)
-#define sprintf(...) __wrap_sprintf(__VA_ARGS__)
+  #if !defined(sprintf)
+    #define __wrap_sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__)
+    #define sprintf(...) __wrap_sprintf(__VA_ARGS__)
+  #endif
 #else
 __BIONIC_FORTIFY_INLINE
 __printflike(2, 3)
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 72b554f..52f371b 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -41,41 +41,47 @@
 #define EXIT_FAILURE 1
 #define EXIT_SUCCESS 0
 
-extern __noreturn void exit(int);
 extern __noreturn void abort(void);
+extern __noreturn void exit(int);
+extern __noreturn void _Exit(int);
 extern int atexit(void (*)(void));
 
-extern char *getenv(const char *);
-extern int putenv(const char *);
-extern int setenv(const char *, const char *, int);
-extern int unsetenv(const char *);
+#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
+int at_quick_exit(void (*)(void));
+void quick_exit(int) __noreturn;
+#endif
+
+extern char* getenv(const char*);
+extern int putenv(char*);
+extern int setenv(const char*, const char*, int);
+extern int unsetenv(const char*);
 extern int clearenv(void);
 
 extern char* mkdtemp(char*);
 extern char* mktemp(char*) __warnattr("mktemp possibly used unsafely; consider using mkstemp");
 extern int mkstemp(char*);
+extern int mkstemp64(char*);
 
 extern long strtol(const char *, char **, int);
 extern long long strtoll(const char *, char **, int);
 extern unsigned long strtoul(const char *, char **, int);
 extern unsigned long long strtoull(const char *, char **, int);
-extern double strtod(const char *nptr, char **endptr);
 
 extern int posix_memalign(void **memptr, size_t alignment, size_t size);
 
-static __inline__ float strtof(const char *nptr, char **endptr)
-{
-    return (float)strtod(nptr, endptr);
-}
+extern double atof(const char*);
 
-extern int atoi(const char *) __purefunc;
-extern long atol(const char *) __purefunc;
-extern long long atoll(const char *) __purefunc;
+extern double strtod(const char*, char**) __LIBC_ABI_PUBLIC__;
+extern float strtof(const char*, char**) __LIBC_ABI_PUBLIC__;
+extern long double strtold(const char*, char**) __LIBC_ABI_PUBLIC__;
 
-static __inline__ double atof(const char *nptr)
-{
-    return (strtod(nptr, NULL));
-}
+extern long double strtold_l(const char *, char **, locale_t) __LIBC_ABI_PUBLIC__;
+extern long long strtoll_l(const char *, char **, int, locale_t) __LIBC_ABI_PUBLIC__;
+extern unsigned long long strtoull_l(const char *, char **, int, locale_t) __LIBC_ABI_PUBLIC__;
+
+extern int atoi(const char*) __purefunc;
+extern long atol(const char*) __purefunc;
+extern long long atoll(const char*) __purefunc;
 
 extern int abs(int) __pure2;
 extern long labs(long) __pure2;
@@ -98,61 +104,54 @@
 extern double erand48(unsigned short xsubi[3]);
 extern double drand48(void);
 extern void srand48(long);
-extern unsigned int arc4random(void);
-extern void arc4random_stir(void);
-extern void arc4random_addrandom(unsigned char *, int);
+
+unsigned int arc4random(void);
+unsigned int arc4random_uniform(unsigned int);
+void arc4random_buf(void*, size_t);
 
 #define RAND_MAX 0x7fffffff
-static __inline__ int rand(void) {
-    return (int)lrand48();
-}
-static __inline__ void srand(unsigned int __s) {
-    srand48(__s);
-}
-static __inline__ long random(void)
-{
-    return lrand48();
-}
-static __inline__ void srandom(unsigned int __s)
-{
-    srand48(__s);
-}
 
-/* Basic PTY functions.  These only work if devpts is mounted! */
+int rand(void);
+int rand_r(unsigned int*);
+void srand(unsigned int);
 
-extern int    unlockpt(int);
-extern char*  ptsname(int);
-extern int    ptsname_r(int, char*, size_t);
-extern int    getpt(void);
+char* initstate(unsigned int, char*, size_t);
+long random(void);
+char* setstate(char*);
+void srandom(unsigned int);
 
-static __inline__ int grantpt(int __fd __attribute((unused)))
-{
-  (void)__fd;
-  return 0;     /* devpts does this all for us! */
-}
+int getpt(void);
+int grantpt(int);
+int posix_openpt(int);
+char* ptsname(int) __warnattr("ptsname is not thread-safe; use ptsname_r instead");
+int ptsname_r(int, char*, size_t);
+int unlockpt(int);
 
 typedef struct {
     int  quot;
     int  rem;
 } div_t;
 
-extern div_t   div(int, int);
+extern div_t   div(int, int) __pure2;
 
 typedef struct {
     long int  quot;
     long int  rem;
 } ldiv_t;
 
-extern ldiv_t   ldiv(long, long);
+extern ldiv_t   ldiv(long, long) __pure2;
 
 typedef struct {
     long long int  quot;
     long long int  rem;
 } lldiv_t;
 
-extern lldiv_t   lldiv(long long, long long);
+extern lldiv_t   lldiv(long long, long long) __pure2;
 
-#if 1 /* MISSING FROM BIONIC - ENABLED FOR STLPort and libstdc++-v3 */
+/* BSD compatibility. */
+extern const char* getprogname(void);
+extern void setprogname(const char*);
+
 /* make STLPort happy */
 extern int      mblen(const char *, size_t);
 extern size_t   mbstowcs(wchar_t *, const char *, size_t);
@@ -161,13 +160,9 @@
 /* Likewise, make libstdc++-v3 happy.  */
 extern int	wctomb(char *, wchar_t);
 extern size_t	wcstombs(char *, const wchar_t *, size_t);
-#endif /* MISSING */
 
-#define MB_CUR_MAX 1
-
-#if 0 /* MISSING FROM BIONIC */
-extern int on_exit(void (*)(int, void *), void *);
-#endif /* MISSING */
+extern size_t __ctype_get_mb_cur_max(void);
+#define MB_CUR_MAX __ctype_get_mb_cur_max()
 
 __END_DECLS
 
diff --git a/libc/include/string.h b/libc/include/string.h
index 37d22c4..8df68e3 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -31,6 +31,7 @@
 #include <sys/cdefs.h>
 #include <stddef.h>
 #include <malloc.h>
+#include <xlocale.h>
 
 __BEGIN_DECLS
 
@@ -42,17 +43,17 @@
 extern void*  memmove(void *, const void *, size_t);
 extern void*  memset(void *, int, size_t);
 extern void*  memmem(const void *, size_t, const void *, size_t) __purefunc;
-extern void   memswap(void *, void *, size_t);
 
-extern char*  index(const char *, int) __purefunc;
 extern char*  strchr(const char *, int) __purefunc;
 extern char* __strchr_chk(const char *, int, size_t);
 
 extern char*  strrchr(const char *, int) __purefunc;
+extern char* __strrchr_chk(const char *, int, size_t);
 
 extern size_t strlen(const char *) __purefunc;
 extern size_t __strlen_chk(const char *, size_t);
 extern int    strcmp(const char *, const char *) __purefunc;
+extern char*  stpcpy(char* __restrict, const char* __restrict);
 extern char*  strcpy(char* __restrict, const char* __restrict);
 extern char*  strcat(char* __restrict, const char* __restrict);
 
@@ -72,6 +73,7 @@
 extern char*  strncat(char* __restrict, const char* __restrict, size_t);
 extern char*  strndup(const char *, size_t);
 extern int    strncmp(const char *, const char *, size_t) __purefunc;
+extern char*  stpncpy(char* __restrict, const char* __restrict, size_t);
 extern char*  strncpy(char* __restrict, const char* __restrict, size_t);
 
 extern size_t strlcat(char* __restrict, const char* __restrict, size_t);
@@ -87,10 +89,10 @@
 extern int    strcoll(const char *, const char *) __purefunc;
 extern size_t strxfrm(char* __restrict, const char* __restrict, size_t);
 
-#if defined(__BIONIC_FORTIFY)
+extern int    strcoll_l(const char *, const char *, locale_t) __purefunc;
+extern size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t);
 
-__errordecl(__memcpy_dest_size_error, "memcpy called with size bigger than destination");
-__errordecl(__memcpy_src_size_error, "memcpy called with size bigger than source");
+#if defined(__BIONIC_FORTIFY)
 
 __BIONIC_FORTIFY_INLINE
 void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amount) {
@@ -99,14 +101,6 @@
     size_t s_len = __bos0(s);
     size_t d_len = __bos0(d);
 
-    if (__builtin_constant_p(copy_amount) && (copy_amount > d_len)) {
-        __memcpy_dest_size_error();
-    }
-
-    if (__builtin_constant_p(copy_amount) && (copy_amount > s_len)) {
-        __memcpy_src_size_error();
-    }
-
     return __builtin___memcpy_chk(dest, src, copy_amount, d_len);
 }
 
@@ -116,20 +110,44 @@
 }
 
 __BIONIC_FORTIFY_INLINE
+char* stpcpy(char* __restrict dest, const char* __restrict src) {
+    return __builtin___stpcpy_chk(dest, src, __bos(dest));
+}
+
+__BIONIC_FORTIFY_INLINE
 char* strcpy(char* __restrict dest, const char* __restrict src) {
     return __builtin___strcpy_chk(dest, src, __bos(dest));
 }
 
-__errordecl(__strncpy_error, "strncpy called with size bigger than buffer");
+extern char* __stpncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
+
+__BIONIC_FORTIFY_INLINE
+char* stpncpy(char* __restrict dest, const char* __restrict src, size_t n) {
+    size_t bos_dest = __bos(dest);
+    size_t bos_src = __bos(src);
+
+    if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
+        return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+    }
+
+    if (__builtin_constant_p(n) && (n <= bos_src)) {
+        return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+    }
+
+    size_t slen = __builtin_strlen(src);
+    if (__builtin_constant_p(slen)) {
+        return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+    }
+
+    return __stpncpy_chk2(dest, src, n, bos_dest, bos_src);
+}
+
 extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
 
 __BIONIC_FORTIFY_INLINE
 char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
     size_t bos_dest = __bos(dest);
     size_t bos_src = __bos(src);
-    if (__builtin_constant_p(n) && (n > bos_dest)) {
-        __strncpy_error();
-    }
 
     if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
         return __builtin___strncpy_chk(dest, src, n, bos_dest);
@@ -164,7 +182,6 @@
 
 extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t)
     __asm__(__USER_LABEL_PREFIX__ "strlcpy");
-__errordecl(__strlcpy_error, "strlcpy called with size bigger than buffer");
 extern size_t __strlcpy_chk(char *, const char *, size_t, size_t);
 
 __BIONIC_FORTIFY_INLINE
@@ -182,12 +199,6 @@
     if (__builtin_constant_p(size) && (size <= bos)) {
         return __strlcpy_real(dest, src, size);
     }
-
-    // Compiler can prove, at compile time, that the passed in size
-    // is always > the actual object size. Force a compiler error.
-    if (__builtin_constant_p(size) && (size > bos)) {
-        __strlcpy_error();
-    }
 #endif /* !defined(__clang__) */
 
     return __strlcpy_chk(dest, src, size, bos);
@@ -195,7 +206,6 @@
 
 extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t)
     __asm__(__USER_LABEL_PREFIX__ "strlcat");
-__errordecl(__strlcat_error, "strlcat called with size bigger than buffer");
 extern size_t __strlcat_chk(char* __restrict, const char* __restrict, size_t, size_t);
 
 
@@ -214,12 +224,6 @@
     if (__builtin_constant_p(size) && (size <= bos)) {
         return __strlcat_real(dest, src, size);
     }
-
-    // Compiler can prove, at compile time, that the passed in size
-    // is always > the actual object size. Force a compiler error.
-    if (__builtin_constant_p(size) && (size > bos)) {
-        __strlcat_error();
-    }
 #endif /* !defined(__clang__) */
 
     return __strlcat_chk(dest, src, size, bos);
@@ -263,8 +267,6 @@
     return __strchr_chk(s, c, bos);
 }
 
-extern char* __strrchr_chk(const char *, int, size_t);
-
 __BIONIC_FORTIFY_INLINE
 char* strrchr(const char *s, int c) {
     size_t bos = __bos(s);
diff --git a/libc/include/strings.h b/libc/include/strings.h
index e72798b..ae261cf 100644
--- a/libc/include/strings.h
+++ b/libc/include/strings.h
@@ -43,20 +43,21 @@
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
-void	 bcopy(const void *, void *, size_t);
-void	 bzero(void *, size_t);
+#if defined(__BIONIC_FORTIFY)
+#define bcopy(b1, b2, len) \
+  (void)(__builtin___memmove_chk((b2), (b1), (len), __bos0(b2)))
+#define bzero(b, len) \
+  (void)(__builtin___memset_chk((b), '\0', (len), __bos0(b)))
+#else
+#define bcopy(b1, b2, len) (void)(__builtin_memmove((b2), (b1), (len)))
+#define bzero(b, len) (void)(__builtin_memset((b), '\0', (len)))
+#endif
+
+
 int	 ffs(int);
-char	*index(const char *, int);
 int	 strcasecmp(const char *, const char *);
 int	 strncasecmp(const char *, const char *, size_t);
 
-#if defined(__BIONIC_FORTIFY)
-__BIONIC_FORTIFY_INLINE
-void bzero (void *s, size_t n) {
-    __builtin___memset_chk(s, '\0', n, __builtin_object_size (s, 0));
-}
-#endif /* defined(__BIONIC_FORTIFY) */
-
 __END_DECLS
 
 #endif /* !defined(_STRINGS_H_) */
diff --git a/libc/include/sys/_sigdefs.h b/libc/include/sys/_sigdefs.h
index eadf7b9..44d60d9 100644
--- a/libc/include/sys/_sigdefs.h
+++ b/libc/include/sys/_sigdefs.h
@@ -35,67 +35,41 @@
 #error __BIONIC_SIGDEF not defined
 #endif
 
-__BIONIC_SIGDEF(HUP,1,"Hangup")
-__BIONIC_SIGDEF(INT,2,"Interrupt")
-__BIONIC_SIGDEF(QUIT,3,"Quit")
-__BIONIC_SIGDEF(ILL,4,"Illegal instruction")
-__BIONIC_SIGDEF(TRAP,5,"Trap")
-__BIONIC_SIGDEF(ABRT,6,"Aborted")
-#ifdef __mips__
-__BIONIC_SIGDEF(EMT,7,"EMT")
-#else
-__BIONIC_SIGDEF(BUS,7,"Bus error")
+__BIONIC_SIGDEF(SIGHUP,    "Hangup")
+__BIONIC_SIGDEF(SIGINT,    "Interrupt")
+__BIONIC_SIGDEF(SIGQUIT,   "Quit")
+__BIONIC_SIGDEF(SIGILL,    "Illegal instruction")
+__BIONIC_SIGDEF(SIGTRAP,   "Trap")
+__BIONIC_SIGDEF(SIGABRT,   "Aborted")
+#ifdef SIGEMT
+__BIONIC_SIGDEF(SIGEMT,    "EMT")
 #endif
-__BIONIC_SIGDEF(FPE,8,"Floating point exception")
-__BIONIC_SIGDEF(KILL,9,"Killed")
-#ifdef __mips__
-__BIONIC_SIGDEF(BUS,10,"Bus error")
-#else
-__BIONIC_SIGDEF(USR1,10,"User signal 1")
+__BIONIC_SIGDEF(SIGFPE,    "Floating point exception")
+__BIONIC_SIGDEF(SIGKILL,   "Killed")
+__BIONIC_SIGDEF(SIGBUS,    "Bus error")
+__BIONIC_SIGDEF(SIGSEGV,   "Segmentation fault")
+__BIONIC_SIGDEF(SIGPIPE,   "Broken pipe")
+__BIONIC_SIGDEF(SIGALRM,   "Alarm clock")
+__BIONIC_SIGDEF(SIGTERM,   "Terminated")
+__BIONIC_SIGDEF(SIGUSR1,   "User signal 1")
+__BIONIC_SIGDEF(SIGUSR2,   "User signal 2")
+__BIONIC_SIGDEF(SIGCHLD,   "Child exited")
+__BIONIC_SIGDEF(SIGPWR,    "Power failure")
+__BIONIC_SIGDEF(SIGWINCH,  "Window size changed")
+__BIONIC_SIGDEF(SIGURG,    "Urgent I/O condition")
+__BIONIC_SIGDEF(SIGIO,     "I/O possible")
+__BIONIC_SIGDEF(SIGSTOP,   "Stopped (signal)")
+__BIONIC_SIGDEF(SIGTSTP,   "Stopped")
+__BIONIC_SIGDEF(SIGCONT,   "Continue")
+__BIONIC_SIGDEF(SIGTTIN,   "Stopped (tty input)")
+__BIONIC_SIGDEF(SIGTTOU,   "Stopped (tty output)")
+__BIONIC_SIGDEF(SIGVTALRM, "Virtual timer expired")
+__BIONIC_SIGDEF(SIGPROF,   "Profiling timer expired")
+__BIONIC_SIGDEF(SIGXCPU,   "CPU time limit exceeded")
+__BIONIC_SIGDEF(SIGXFSZ,   "File size limit exceeded")
+#if defined(SIGSTKFLT)
+__BIONIC_SIGDEF(SIGSTKFLT, "Stack fault")
 #endif
-__BIONIC_SIGDEF(SEGV,11,"Segmentation fault")
-#ifdef __mips__
-__BIONIC_SIGDEF(SYS,12,"Bad system call")
-#else
-__BIONIC_SIGDEF(USR2,12,"User signal 2")
-#endif
-__BIONIC_SIGDEF(PIPE,13,"Broken pipe")
-__BIONIC_SIGDEF(ALRM,14,"Alarm clock")
-__BIONIC_SIGDEF(TERM,15,"Terminated")
-#ifdef __mips__
-__BIONIC_SIGDEF(USR1,16,"User signal 1")
-__BIONIC_SIGDEF(USR2,17,"User signal 2")
-__BIONIC_SIGDEF(CHLD,18,"Child exited")
-__BIONIC_SIGDEF(PWR,19,"Power failure")
-__BIONIC_SIGDEF(WINCH,20,"Window size changed")
-__BIONIC_SIGDEF(URG,21,"Urgent I/O condition")
-__BIONIC_SIGDEF(IO,22,"I/O possible")
-__BIONIC_SIGDEF(STOP,23,"Stopped (signal)")
-__BIONIC_SIGDEF(TSTP,24,"Stopped")
-__BIONIC_SIGDEF(CONT,25,"Continue")
-__BIONIC_SIGDEF(TTIN,26,"Stopped (tty input)")
-__BIONIC_SIGDEF(TTOU,27,"Stopped (tty output)")
-__BIONIC_SIGDEF(VTALRM,28,"Virtual timer expired")
-__BIONIC_SIGDEF(PROF,29,"Profiling timer expired")
-__BIONIC_SIGDEF(XCPU,30,"CPU time limit exceeded")
-__BIONIC_SIGDEF(XFSZ,31,"File size limit exceeded")
-#else
-__BIONIC_SIGDEF(STKFLT,16,"Stack fault")
-__BIONIC_SIGDEF(CHLD,17,"Child exited")
-__BIONIC_SIGDEF(CONT,18,"Continue")
-__BIONIC_SIGDEF(STOP,19,"Stopped (signal)")
-__BIONIC_SIGDEF(TSTP,20,"Stopped")
-__BIONIC_SIGDEF(TTIN,21,"Stopped (tty input)")
-__BIONIC_SIGDEF(TTOU,22,"Stopped (tty output)")
-__BIONIC_SIGDEF(URG,23,"Urgent I/O condition")
-__BIONIC_SIGDEF(XCPU,24,"CPU time limit exceeded")
-__BIONIC_SIGDEF(XFSZ,25,"File size limit exceeded")
-__BIONIC_SIGDEF(VTALRM,26,"Virtual timer expired")
-__BIONIC_SIGDEF(PROF,27,"Profiling timer expired")
-__BIONIC_SIGDEF(WINCH,28,"Window size changed")
-__BIONIC_SIGDEF(IO,29,"I/O possible")
-__BIONIC_SIGDEF(PWR,30,"Power failure")
-__BIONIC_SIGDEF(SYS,31,"Bad system call")
-#endif
+__BIONIC_SIGDEF(SIGSYS,    "Bad system call")
 
 #undef __BIONIC_SIGDEF
diff --git a/libc/include/sys/_system_properties.h b/libc/include/sys/_system_properties.h
index 5eee7f0..5a681df 100644
--- a/libc/include/sys/_system_properties.h
+++ b/libc/include/sys/_system_properties.h
@@ -139,6 +139,14 @@
         void (*propfn)(const prop_info *pi, void *cookie),
         void *cookie);
 
+/* Initialize the system properties area in read only mode.
+ * Should be done by all processes that need to read system
+ * properties.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+int __system_properties_init();
+
 __END_DECLS
 
 #endif
diff --git a/libc/include/sys/_types.h b/libc/include/sys/_types.h
deleted file mode 100644
index 9d313d1..0000000
--- a/libc/include/sys/_types.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*	$OpenBSD: _types.h,v 1.1 2006/01/06 18:53:05 millert Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)types.h	8.3 (Berkeley) 1/5/94
- */
-
-#ifndef _SYS__TYPES_H_
-#define	_SYS__TYPES_H_
-
-#include <machine/_types.h>
-
-typedef	unsigned long	__cpuid_t;	/* CPU id */
-typedef	__uint32_t	__fixpt_t;	/* fixed point number */
-typedef	__uint32_t	__gid_t;	/* group id */
-typedef	__uint32_t	__id_t;		/* may contain pid, uid or gid */
-typedef __uint32_t	__in_addr_t;	/* base type for internet address */
-typedef __uint16_t	__in_port_t;	/* IP port type */
-typedef	__uint32_t	__ino_t;	/* inode number */
-typedef	long		__key_t;	/* IPC key (for Sys V IPC) */
-typedef	__uint32_t	__mode_t;	/* permissions */
-typedef	__uint32_t	__nlink_t;	/* link count */
-typedef	__int32_t	__pid_t;	/* process id */
-typedef __uint64_t	__rlim_t;	/* resource limit */
-typedef __uint16_t	__sa_family_t;	/* sockaddr address family type */
-typedef	__int32_t	__segsz_t;	/* segment size */
-typedef __uint32_t	__socklen_t;	/* length type for network syscalls */
-typedef	__int32_t	__swblk_t;	/* swap offset */
-typedef	__uint32_t	__uid_t;	/* user id */
-typedef	__uint32_t	__useconds_t;	/* microseconds */
-typedef	__int32_t	__suseconds_t;	/* microseconds (signed) */
-
-/*
- * mbstate_t is an opaque object to keep conversion state, during multibyte
- * stream conversions. The content must not be referenced by user programs.
- */
-typedef union {
-	char __mbstate8[128];
-	__int64_t __mbstateL;			/* for alignment */
-} __mbstate_t;
-
-#endif /* !_SYS__TYPES_H_ */
diff --git a/libc/include/sys/atomics.h b/libc/include/sys/atomics.h
deleted file mode 100644
index 143bc4b..0000000
--- a/libc/include/sys/atomics.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#ifndef _SYS_ATOMICS_H
-#define _SYS_ATOMICS_H
-
-#include <sys/cdefs.h>
-#include <sys/time.h>
-
-__BEGIN_DECLS
-
-/* Note: atomic operations that were exported by the C library didn't
- *       provide any memory barriers, which created potential issues on
- *       multi-core devices. We now define them as inlined calls to
- *       GCC sync builtins, which always provide a full barrier.
- *
- *       NOTE: The C library still exports atomic functions by the same
- *              name to ensure ABI stability for existing NDK machine code.
- *
- *       If you are an NDK developer, we encourage you to rebuild your
- *       unmodified sources against this header as soon as possible.
- */
-#define __ATOMIC_INLINE__ static __inline__ __attribute__((always_inline))
-
-__ATOMIC_INLINE__ int
-__atomic_cmpxchg(int old_value, int new_value, volatile int* ptr)
-{
-    /* We must return 0 on success */
-    return __sync_val_compare_and_swap(ptr, old_value, new_value) != old_value;
-}
-
-__ATOMIC_INLINE__ int
-__atomic_swap(int new_value, volatile int *ptr)
-{
-    int old_value;
-    do {
-        old_value = *ptr;
-    } while (__sync_val_compare_and_swap(ptr, old_value, new_value) != old_value);
-    return old_value;
-}
-
-__ATOMIC_INLINE__ int
-__atomic_dec(volatile int *ptr)
-{
-  return __sync_fetch_and_sub (ptr, 1);
-}
-
-__ATOMIC_INLINE__ int
-__atomic_inc(volatile int *ptr)
-{
-  return __sync_fetch_and_add (ptr, 1);
-}
-
-
-int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout);
-int __futex_wake(volatile void *ftx, int count);
-
-__END_DECLS
-
-#endif /* _SYS_ATOMICS_H */
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index b4dad74..9a8dfdd 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -38,22 +38,40 @@
 #define	_SYS_CDEFS_H_
 
 /*
+ * Testing against Clang-specific extensions.
+ */
+
+#ifndef __has_extension
+#define __has_extension         __has_feature
+#endif
+#ifndef __has_feature
+#define __has_feature(x)        0
+#endif
+#ifndef __has_include
+#define __has_include(x)        0
+#endif
+#ifndef __has_builtin
+#define __has_builtin(x)        0
+#endif
+
+
+/*
  * Macro to test if we're using a GNU C compiler of a specific vintage
  * or later, for e.g. features that appeared in a particular version
  * of GNU C.  Usage:
  *
- *	#if __GNUC_PREREQ__(major, minor)
+ *	#if __GNUC_PREREQ(major, minor)
  *	...cool feature...
  *	#else
  *	...delete feature...
  *	#endif
  */
 #ifdef __GNUC__
-#define	__GNUC_PREREQ__(x, y)						\
+#define	__GNUC_PREREQ(x, y)						\
 	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||			\
 	 (__GNUC__ > (x)))
 #else
-#define	__GNUC_PREREQ__(x, y)	0
+#define	__GNUC_PREREQ(x, y)	0
 #endif
 
 #include <sys/cdefs_elf.h>
@@ -145,7 +163,7 @@
  * GCC2 provides __extension__ to suppress warnings for various GNU C
  * language extensions under "-ansi -pedantic".
  */
-#if !__GNUC_PREREQ__(2, 0)
+#if !__GNUC_PREREQ(2, 0)
 #define	__extension__		/* delete __extension__ if non-gcc or gcc1 */
 #endif
 
@@ -157,7 +175,7 @@
  * these work for GNU C++ (modulo a slight glitch in the C++ grammar
  * in the distribution version of 2.5.5).
  */
-#if !__GNUC_PREREQ__(2, 5)
+#if !__GNUC_PREREQ(2, 5)
 #define	__attribute__(x)	/* delete __attribute__ if non-gcc or gcc1 */
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 #define	__dead		__volatile
@@ -171,7 +189,7 @@
 #define	__pure
 #endif
 
-#if __GNUC_PREREQ__(2, 7)
+#if __GNUC_PREREQ(2, 7)
 #define	__unused	__attribute__((__unused__))
 #else
 #define	__unused	/* delete */
@@ -179,13 +197,13 @@
 
 #define __pure2 __attribute__((__const__)) /* Android-added: used by FreeBSD libm */
 
-#if __GNUC_PREREQ__(3, 1)
+#if __GNUC_PREREQ(3, 1)
 #define	__used		__attribute__((__used__))
 #else
 #define	__used		/* delete */
 #endif
 
-#if __GNUC_PREREQ__(2, 7)
+#if __GNUC_PREREQ(2, 7)
 #define	__packed	__attribute__((__packed__))
 #define	__aligned(x)	__attribute__((__aligned__(x)))
 #define	__section(x)	__attribute__((__section__(x)))
@@ -199,11 +217,11 @@
 #define	__section(x)	error: no __section for this compiler
 #endif
 
-#if !__GNUC_PREREQ__(2, 8)
+#if !__GNUC_PREREQ(2, 8)
 #define	__extension__
 #endif
 
-#if __GNUC_PREREQ__(2, 8)
+#if __GNUC_PREREQ(2, 8)
 #define __statement(x)	__extension__(x)
 #elif defined(lint)
 #define __statement(x)	(0)
@@ -223,7 +241,7 @@
 #if defined(__STDC__VERSION__) && __STDC_VERSION__ >= 199901L
 #define	__restrict	restrict
 #else
-#if !__GNUC_PREREQ__(2, 92)
+#if !__GNUC_PREREQ(2, 92)
 #define	__restrict	/* delete __restrict when not supported */
 #endif
 #endif
@@ -233,9 +251,9 @@
  * in GCC 2.95.
  */
 #if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
-#if __GNUC_PREREQ__(2, 6)
+#if __GNUC_PREREQ(2, 6)
 #define	__func__	__PRETTY_FUNCTION__
-#elif __GNUC_PREREQ__(2, 4)
+#elif __GNUC_PREREQ(2, 4)
 #define	__func__	__FUNCTION__
 #else
 #define	__func__	""
@@ -268,7 +286,7 @@
  * register values. This is gcc specific, the version is more or less
  * arbitrary, might work with older compilers.
  */
-#if __GNUC_PREREQ__(2, 95)
+#if __GNUC_PREREQ(2, 95)
 #define	__insn_barrier()	__asm __volatile("":::"memory")
 #else
 #define	__insn_barrier()	/* */
@@ -302,7 +320,7 @@
  *	  basic block reordering that this affects can often generate
  *	  larger code.
  */
-#if __GNUC_PREREQ__(2, 96)
+#if __GNUC_PREREQ(2, 96)
 #define	__predict_true(exp)	__builtin_expect((exp) != 0, 1)
 #define	__predict_false(exp)	__builtin_expect((exp) != 0, 0)
 #else
@@ -310,7 +328,7 @@
 #define	__predict_false(exp)	(exp)
 #endif
 
-#if __GNUC_PREREQ__(2, 96)
+#if __GNUC_PREREQ(2, 96)
 #define __noreturn    __attribute__((__noreturn__))
 #define __mallocfunc  __attribute__((malloc))
 #define __purefunc    __attribute__((pure))
@@ -320,19 +338,19 @@
 #define __purefunc
 #endif
 
-#if __GNUC_PREREQ__(3, 1)
+#if __GNUC_PREREQ(3, 1)
 #define __always_inline __attribute__((__always_inline__))
 #else
 #define __always_inline
 #endif
 
-#if __GNUC_PREREQ__(3, 4)
+#if __GNUC_PREREQ(3, 4)
 #define __wur __attribute__((__warn_unused_result__))
 #else
 #define __wur
 #endif
 
-#if __GNUC_PREREQ__(4, 3)
+#if __GNUC_PREREQ(4, 3)
 #define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg)))
 #define __warnattr(msg) __attribute__((__warning__(msg)))
 #else
@@ -528,6 +546,13 @@
 #define  __BIONIC__   1
 #include <android/api-level.h>
 
+/* glibc compatibility. */
+#if __LP64__
+#define __WORDSIZE 64
+#else
+#define __WORDSIZE 32
+#endif
+
 /*
  * When _FORTIFY_SOURCE is defined, automatic bounds checking is
  * added to commonly used libc functions. If a buffer overrun is
@@ -546,7 +571,7 @@
 #define __bos0(s) __builtin_object_size((s), 0)
 
 #define __BIONIC_FORTIFY_INLINE \
-    extern inline \
+    extern __inline__ \
     __attribute__ ((always_inline)) \
     __attribute__ ((gnu_inline))
 #endif
diff --git a/libc/include/sys/cdefs_elf.h b/libc/include/sys/cdefs_elf.h
index bb846b7..4dd7dc3 100644
--- a/libc/include/sys/cdefs_elf.h
+++ b/libc/include/sys/cdefs_elf.h
@@ -61,24 +61,18 @@
 #define	__SECTIONSTRING(_sec, _str)					\
 	__asm__(".section " #_sec "\n\t.asciz \"" _str "\"\n\t.previous")
 
-/* GCC visibility helper macro */
-/* This must be used to tag non-static functions that are private, i.e.
- * never exposed by the shared library. */
-#define __LIBC_HIDDEN__							\
-	__attribute__ ((visibility ("hidden")))
+/* Used to tag non-static symbols that are private and never exposed by the shared library. */
+#define __LIBC_HIDDEN__ __attribute__((visibility ("hidden")))
 
-/* This must be used to tag non-static functions that are public, i.e.
- * exposed by the shared library, and part of the stable NDK ABI */
-#define __LIBC_ABI_PUBLIC__ \
-        __attribute__ ((visibility ("default")))
+/* Like __LIBC_HIDDEN__, but preserves binary compatibility for LP32. */
+#ifdef __LP64__
+#define __LIBC64_HIDDEN__ __LIBC_HIDDEN__
+#else
+#define __LIBC64_HIDDEN__ __LIBC_ABI_PUBLIC__
+#endif
 
-/* This must be used to tag non-static functions that must be exported
- * by the shared library, but whose implementation is private to the
- * platform. For now this is equivalent to __LIBC_ABI_PUBLIC__, but we
- * may want to change this later.
- */
-#define __LIBC_ABI_PRIVATE__ \
-        __attribute__ ((visibility ("default")))
+/* Used to tag non-static symbols that are public and exposed by the shared library. */
+#define __LIBC_ABI_PUBLIC__ __attribute__((visibility ("default")))
 
 #define	__IDSTRING(_n,_s)		__SECTIONSTRING(.ident,_s)
 
diff --git a/libc/include/sys/endian.h b/libc/include/sys/endian.h
index b0365d8..be4c905 100644
--- a/libc/include/sys/endian.h
+++ b/libc/include/sys/endian.h
@@ -38,7 +38,8 @@
 
 #include <sys/cdefs.h>
 #include <machine/endian.h>
-#include <machine/_types.h>
+
+#include <stdint.h>
 
 #define _LITTLE_ENDIAN	1234
 #define _BIG_ENDIAN	4321
@@ -187,14 +188,22 @@
 #define letoh64(x) (x)
 #endif /* __BSD_VISIBLE */
 
-#define htons(x) __swap16(x)
+/* glibc compatibility. */
+__BEGIN_DECLS
+uint32_t htonl(uint32_t) __pure2;
+uint16_t htons(uint16_t) __pure2;
+uint32_t ntohl(uint32_t) __pure2;
+uint16_t ntohs(uint16_t) __pure2;
+__END_DECLS
+
 #define htonl(x) __swap32(x)
-#define ntohs(x) __swap16(x)
+#define htons(x) __swap16(x)
 #define ntohl(x) __swap32(x)
+#define ntohs(x) __swap16(x)
 
 /* Bionic additions */
-#define ntohq(x) __swap64(x)
 #define htonq(x) __swap64(x)
+#define ntohq(x) __swap64(x)
 
 #define __LITTLE_ENDIAN_BITFIELD
 
diff --git a/libc/include/sys/epoll.h b/libc/include/sys/epoll.h
index c06a081..4a5a37c 100644
--- a/libc/include/sys/epoll.h
+++ b/libc/include/sys/epoll.h
@@ -67,7 +67,11 @@
 struct epoll_event {
   uint32_t events;
   epoll_data_t data;
-};
+}
+#ifdef __x86_64__
+__packed
+#endif
+;
 
 int epoll_create(int);
 int epoll_create1(int);
diff --git a/libc/include/sys/exec_elf.h b/libc/include/sys/exec_elf.h
deleted file mode 100644
index 3c1467c..0000000
--- a/libc/include/sys/exec_elf.h
+++ /dev/null
@@ -1,1267 +0,0 @@
-/*	$NetBSD: exec_elf.h,v 1.131 2013/10/29 00:22:59 christos Exp $	*/
-
-/*-
- * Copyright (c) 1994 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Christos Zoulas.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _SYS_EXEC_ELF_H_
-#define _SYS_EXEC_ELF_H_
-
-/*
- * The current ELF ABI specification is available at:
- *	http://www.sco.com/developers/gabi/
- *
- * Current header definitions are in:
- *	http://www.sco.com/developers/gabi/latest/ch4.eheader.html
- */
-
-#if defined(_KERNEL) || defined(_STANDALONE)
-#include <sys/types.h>
-#else
-#include <inttypes.h>
-#endif /* _KERNEL || _STANDALONE */
-
-#if HAVE_NBTOOL_CONFIG_H
-#include <nbinclude/machine/elf_machdep.h>
-#else
-#include <machine/elf_machdep.h>
-#endif
-
-typedef uint8_t		Elf_Byte;
-
-typedef uint32_t	Elf32_Addr;
-#define ELF32_FSZ_ADDR	4
-typedef uint32_t	Elf32_Off;
-typedef int32_t		Elf32_SOff;
-#define ELF32_FSZ_OFF	4
-typedef int32_t		Elf32_Sword;
-#define ELF32_FSZ_SWORD 4
-typedef uint32_t	Elf32_Word;
-#define ELF32_FSZ_WORD	4
-typedef uint16_t	Elf32_Half;
-#define ELF32_FSZ_HALF	2
-typedef uint64_t	Elf32_Lword;
-#define ELF32_FSZ_LWORD 8
-
-typedef uint64_t	Elf64_Addr;
-#define ELF64_FSZ_ADDR	8
-typedef uint64_t	Elf64_Off;
-typedef int64_t		Elf64_SOff;
-#define ELF64_FSZ_OFF	8
-typedef int32_t		Elf64_Shalf;
-#define ELF64_FSZ_SHALF 4
-
-typedef int32_t		Elf64_Sword;
-#define ELF64_FSZ_SWORD 4
-typedef uint32_t	Elf64_Word;
-#define ELF64_FSZ_WORD	4
-
-typedef int64_t		Elf64_Sxword;
-#define ELF64_FSZ_SXWORD 8
-typedef uint64_t	Elf64_Xword;
-#define ELF64_FSZ_XWORD 8
-typedef uint64_t	Elf64_Lword;
-#define ELF64_FSZ_LWORD 8
-typedef uint16_t	Elf64_Half;
-#define ELF64_FSZ_HALF 2
-
-/*
- * ELF Header
- */
-#define ELF_NIDENT	16
-
-typedef struct {
-	unsigned char	e_ident[ELF_NIDENT];	/* Id bytes */
-	Elf32_Half	e_type;			/* file type */
-	Elf32_Half	e_machine;		/* machine type */
-	Elf32_Word	e_version;		/* version number */
-	Elf32_Addr	e_entry;		/* entry point */
-	Elf32_Off	e_phoff;		/* Program hdr offset */
-	Elf32_Off	e_shoff;		/* Section hdr offset */
-	Elf32_Word	e_flags;		/* Processor flags */
-	Elf32_Half	e_ehsize;		/* sizeof ehdr */
-	Elf32_Half	e_phentsize;		/* Program header entry size */
-	Elf32_Half	e_phnum;		/* Number of program headers */
-	Elf32_Half	e_shentsize;		/* Section header entry size */
-	Elf32_Half	e_shnum;		/* Number of section headers */
-	Elf32_Half	e_shstrndx;		/* String table index */
-} Elf32_Ehdr;
-
-typedef struct {
-	unsigned char	e_ident[ELF_NIDENT];	/* Id bytes */
-	Elf64_Half	e_type;			/* file type */
-	Elf64_Half	e_machine;		/* machine type */
-	Elf64_Word	e_version;		/* version number */
-	Elf64_Addr	e_entry;		/* entry point */
-	Elf64_Off	e_phoff;		/* Program hdr offset */
-	Elf64_Off	e_shoff;		/* Section hdr offset */
-	Elf64_Word	e_flags;		/* Processor flags */
-	Elf64_Half	e_ehsize;		/* sizeof ehdr */
-	Elf64_Half	e_phentsize;		/* Program header entry size */
-	Elf64_Half	e_phnum;		/* Number of program headers */
-	Elf64_Half	e_shentsize;		/* Section header entry size */
-	Elf64_Half	e_shnum;		/* Number of section headers */
-	Elf64_Half	e_shstrndx;		/* String table index */
-} Elf64_Ehdr;
-
-/* e_ident offsets */
-#define EI_MAG0		0	/* '\177' */
-#define EI_MAG1		1	/* 'E'	  */
-#define EI_MAG2		2	/* 'L'	  */
-#define EI_MAG3		3	/* 'F'	  */
-#define EI_CLASS	4	/* File class */
-#define EI_DATA		5	/* Data encoding */
-#define EI_VERSION	6	/* File version */
-#define EI_OSABI	7	/* Operating system/ABI identification */
-#define EI_ABIVERSION	8	/* ABI version */
-#define EI_PAD		9	/* Start of padding bytes up to EI_NIDENT*/
-#define EI_NIDENT	16	/* First non-ident header byte */
-
-/* e_ident[EI_MAG0,EI_MAG3] */
-#define ELFMAG0		0x7f
-#define ELFMAG1		'E'
-#define ELFMAG2		'L'
-#define ELFMAG3		'F'
-#define ELFMAG		"\177ELF"
-#define SELFMAG		4
-
-/* e_ident[EI_CLASS] */
-#define ELFCLASSNONE	0	/* Invalid class */
-#define ELFCLASS32	1	/* 32-bit objects */
-#define ELFCLASS64	2	/* 64-bit objects */
-#define ELFCLASSNUM	3
-
-/* e_ident[EI_DATA] */
-#define ELFDATANONE	0	/* Invalid data encoding */
-#define ELFDATA2LSB	1	/* 2's complement values, LSB first */
-#define ELFDATA2MSB	2	/* 2's complement values, MSB first */
-
-/* e_ident[EI_VERSION] */
-#define EV_NONE		0	/* Invalid version */
-#define EV_CURRENT	1	/* Current version */
-#define EV_NUM		2
-
-/* e_ident[EI_OSABI] */
-#define ELFOSABI_SYSV		0	/* UNIX System V ABI */
-#define ELFOSABI_HPUX		1	/* HP-UX operating system */
-#define ELFOSABI_NETBSD		2	/* NetBSD */
-#define ELFOSABI_LINUX		3	/* GNU/Linux */
-#define ELFOSABI_HURD		4	/* GNU/Hurd */
-#define ELFOSABI_86OPEN		5	/* 86Open */
-#define ELFOSABI_SOLARIS	6	/* Solaris */
-#define ELFOSABI_MONTEREY	7	/* Monterey */
-#define ELFOSABI_IRIX		8	/* IRIX */
-#define ELFOSABI_FREEBSD	9	/* FreeBSD */
-#define ELFOSABI_TRU64		10	/* TRU64 UNIX */
-#define ELFOSABI_MODESTO	11	/* Novell Modesto */
-#define ELFOSABI_OPENBSD	12	/* OpenBSD */
-#define ELFOSABI_OPENVMS	13	/* OpenVMS */
-#define ELFOSABI_NSK		14	/* HP Non-Stop Kernel */
-#define ELFOSABI_AROS		15	/* Amiga Research OS */
-/* Unofficial OSABIs follow */
-#define ELFOSABI_ARM		97	/* ARM */
-#define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
-
-#define ELFOSABI_NONE		ELFOSABI_SYSV
-#define ELFOSABI_AIX		ELFOSABI_MONTEREY
-
-/* e_type */
-#define ET_NONE		0	/* No file type */
-#define ET_REL		1	/* Relocatable file */
-#define ET_EXEC		2	/* Executable file */
-#define ET_DYN		3	/* Shared object file */
-#define ET_CORE		4	/* Core file */
-#define ET_NUM		5
-
-#define ET_LOOS		0xfe00	/* Operating system specific range */
-#define ET_HIOS		0xfeff
-#define ET_LOPROC	0xff00	/* Processor-specific range */
-#define ET_HIPROC	0xffff
-
-/* e_machine */
-#define EM_NONE		0	/* No machine */
-#define EM_M32		1	/* AT&T WE 32100 */
-#define EM_SPARC	2	/* SPARC */
-#define EM_386		3	/* Intel 80386 */
-#define EM_68K		4	/* Motorola 68000 */
-#define EM_88K		5	/* Motorola 88000 */
-#define EM_486		6	/* Intel 80486 */
-#define EM_860		7	/* Intel 80860 */
-#define EM_MIPS		8	/* MIPS I Architecture */
-#define EM_S370		9	/* Amdahl UTS on System/370 */
-#define EM_MIPS_RS3_LE	10	/* MIPS RS3000 Little-endian */
-			/* 11-14 - Reserved */
-#define EM_RS6000	11	/* IBM RS/6000 XXX reserved */
-#define EM_PARISC	15	/* Hewlett-Packard PA-RISC */
-#define EM_NCUBE	16	/* NCube XXX reserved */
-#define EM_VPP500	17	/* Fujitsu VPP500 */
-#define EM_SPARC32PLUS	18	/* Enhanced instruction set SPARC */
-#define EM_960		19	/* Intel 80960 */
-#define EM_PPC		20	/* PowerPC */
-#define EM_PPC64	21	/* 64-bit PowerPC */
-			/* 22-35 - Reserved */
-#define EM_S390		22	/* System/390 XXX reserved */
-#define EM_V800		36	/* NEC V800 */
-#define EM_FR20		37	/* Fujitsu FR20 */
-#define EM_RH32		38	/* TRW RH-32 */
-#define EM_RCE		39	/* Motorola RCE */
-#define EM_ARM		40	/* Advanced RISC Machines ARM */
-#define EM_ALPHA	41	/* DIGITAL Alpha */
-#define EM_SH		42	/* Hitachi Super-H */
-#define EM_SPARCV9	43	/* SPARC Version 9 */
-#define EM_TRICORE	44	/* Siemens Tricore */
-#define EM_ARC		45	/* Argonaut RISC Core */
-#define EM_H8_300	46	/* Hitachi H8/300 */
-#define EM_H8_300H	47	/* Hitachi H8/300H */
-#define EM_H8S		48	/* Hitachi H8S */
-#define EM_H8_500	49	/* Hitachi H8/500 */
-#define EM_IA_64	50	/* Intel Merced Processor */
-#define EM_MIPS_X	51	/* Stanford MIPS-X */
-#define EM_COLDFIRE	52	/* Motorola Coldfire */
-#define EM_68HC12	53	/* Motorola MC68HC12 */
-#define EM_MMA		54	/* Fujitsu MMA Multimedia Accelerator */
-#define EM_PCP		55	/* Siemens PCP */
-#define EM_NCPU		56	/* Sony nCPU embedded RISC processor */
-#define EM_NDR1		57	/* Denso NDR1 microprocessor */
-#define EM_STARCORE	58	/* Motorola Star*Core processor */
-#define EM_ME16		59	/* Toyota ME16 processor */
-#define EM_ST100	60	/* STMicroelectronics ST100 processor */
-#define EM_TINYJ	61	/* Advanced Logic Corp. TinyJ embedded family processor */
-#define EM_X86_64	62	/* AMD x86-64 architecture */
-#define EM_PDSP		63	/* Sony DSP Processor */
-#define EM_PDP10	64	/* Digital Equipment Corp. PDP-10 */
-#define EM_PDP11	65	/* Digital Equipment Corp. PDP-11 */
-#define EM_FX66		66	/* Siemens FX66 microcontroller */
-#define EM_ST9PLUS	67	/* STMicroelectronics ST9+ 8/16 bit microcontroller */
-#define EM_ST7		68	/* STMicroelectronics ST7 8-bit microcontroller */
-#define EM_68HC16	69	/* Motorola MC68HC16 Microcontroller */
-#define EM_68HC11	70	/* Motorola MC68HC11 Microcontroller */
-#define EM_68HC08	71	/* Motorola MC68HC08 Microcontroller */
-#define EM_68HC05	72	/* Motorola MC68HC05 Microcontroller */
-#define EM_SVX		73	/* Silicon Graphics SVx */
-#define EM_ST19		74	/* STMicroelectronics ST19 8-bit CPU */
-#define EM_VAX		75	/* Digital VAX */
-#define EM_CRIS		76	/* Axis Communications 32-bit embedded processor */
-#define EM_JAVELIN	77	/* Infineon Technologies 32-bit embedded CPU */
-#define EM_FIREPATH	78	/* Element 14 64-bit DSP processor */
-#define EM_ZSP		79	/* LSI Logic's 16-bit DSP processor */
-#define EM_MMIX		80	/* Donald Knuth's educational 64-bit processor */
-#define EM_HUANY	81	/* Harvard's machine-independent format */
-#define EM_PRISM	82	/* SiTera Prism */
-#define EM_AVR		83	/* Atmel AVR 8-bit microcontroller */
-#define EM_FR30		84	/* Fujitsu FR30 */
-#define EM_D10V		85	/* Mitsubishi D10V */
-#define EM_D30V		86	/* Mitsubishi D30V */
-#define EM_V850		87	/* NEC v850 */
-#define EM_M32R		88	/* Mitsubishi M32R */
-#define EM_MN10300	89	/* Matsushita MN10300 */
-#define EM_MN10200	90	/* Matsushita MN10200 */
-#define EM_PJ		91	/* picoJava */
-#define EM_OPENRISC	92	/* OpenRISC 32-bit embedded processor */
-#define EM_ARC_A5	93	/* ARC Cores Tangent-A5 */
-#define EM_XTENSA	94	/* Tensilica Xtensa Architecture */
-#define EM_VIDEOCORE	95	/* Alphamosaic VideoCore processor */
-#define EM_TMM_GPP	96	/* Thompson Multimedia General Purpose Processor */
-#define EM_NS32K	97	/* National Semiconductor 32000 series */
-#define EM_TPC		98	/* Tenor Network TPC processor */
-#define EM_SNP1K	99	/* Trebia SNP 1000 processor */
-#define EM_ST200	100	/* STMicroelectronics ST200 microcontroller */
-#define EM_IP2K		101	/* Ubicom IP2xxx microcontroller family */
-#define EM_MAX		102	/* MAX processor */
-#define EM_CR		103	/* National Semiconductor CompactRISC micorprocessor */
-#define EM_F2MC16	104	/* Fujitsu F2MC16 */
-#define EM_MSP430	105	/* Texas Instruments MSP430 */
-#define EM_BLACKFIN	106	/* Analog Devices Blackfin DSP */
-#define EM_SE_C33	107	/* Seiko Epson S1C33 family */
-#define EM_SEP		108	/* Sharp embedded microprocessor */
-#define EM_ARCA		109	/* Arca RISC microprocessor */
-#define EM_UNICORE	110	/* UNICORE from PKU-Unity Ltd. and MPRC Peking University */
-#define EM_AARCH64	183	/* AArch64 64-bit ARM microprocessor */
-
-/* Unofficial machine types follow */
-#define EM_AVR32	6317	/* used by NetBSD/avr32 */
-#define EM_ALPHA_EXP	36902	/* used by NetBSD/alpha; obsolete */
-#define EM_NUM		36903
-
-/*
- * Program Header
- */
-typedef struct {
-	Elf32_Word	p_type;		/* entry type */
-	Elf32_Off	p_offset;	/* offset */
-	Elf32_Addr	p_vaddr;	/* virtual address */
-	Elf32_Addr	p_paddr;	/* physical address */
-	Elf32_Word	p_filesz;	/* file size */
-	Elf32_Word	p_memsz;	/* memory size */
-	Elf32_Word	p_flags;	/* flags */
-	Elf32_Word	p_align;	/* memory & file alignment */
-} Elf32_Phdr;
-
-typedef struct {
-	Elf64_Word	p_type;		/* entry type */
-	Elf64_Word	p_flags;	/* flags */
-	Elf64_Off	p_offset;	/* offset */
-	Elf64_Addr	p_vaddr;	/* virtual address */
-	Elf64_Addr	p_paddr;	/* physical address */
-	Elf64_Xword	p_filesz;	/* file size */
-	Elf64_Xword	p_memsz;	/* memory size */
-	Elf64_Xword	p_align;	/* memory & file alignment */
-} Elf64_Phdr;
-
-/* p_type */
-#define PT_NULL		0		/* Program header table entry unused */
-#define PT_LOAD		1		/* Loadable program segment */
-#define PT_DYNAMIC	2		/* Dynamic linking information */
-#define PT_INTERP	3		/* Program interpreter */
-#define PT_NOTE		4		/* Auxiliary information */
-#define PT_SHLIB	5		/* Reserved, unspecified semantics */
-#define PT_PHDR		6		/* Entry for header table itself */
-#define PT_TLS		7		/* TLS initialisation image */
-#define PT_NUM		8
-
-#define PT_LOOS		0x60000000	/* OS-specific range */
-
-/* GNU-specific */
-#define PT_GNU_EH_FRAME 0x6474e550	/* EH frame segment */
-#define PT_GNU_STACK	0x6474e551	/* Indicate executable stack */
-#define PT_GNU_RELRO	0x6474e552	/* Make read-only after relocation */
-
-#define PT_HIOS		0x6fffffff
-#define PT_LOPROC	0x70000000	/* Processor-specific range */
-#define PT_HIPROC	0x7fffffff
-
-#define PT_MIPS_REGINFO 0x70000000
-
-/* p_flags */
-#define PF_R		0x4		/* Segment is readable */
-#define PF_W		0x2		/* Segment is writable */
-#define PF_X		0x1		/* Segment is executable */
-
-#define PF_MASKOS	0x0ff00000	/* Operating system specific values */
-#define PF_MASKPROC	0xf0000000	/* Processor-specific values */
-
-/* Extended program header index. */
-#define PN_XNUM		0xffff
-
-/*
- * Section Headers
- */
-typedef struct {
-	Elf32_Word	sh_name;	/* section name (.shstrtab index) */
-	Elf32_Word	sh_type;	/* section type */
-	Elf32_Word	sh_flags;	/* section flags */
-	Elf32_Addr	sh_addr;	/* virtual address */
-	Elf32_Off	sh_offset;	/* file offset */
-	Elf32_Word	sh_size;	/* section size */
-	Elf32_Word	sh_link;	/* link to another */
-	Elf32_Word	sh_info;	/* misc info */
-	Elf32_Word	sh_addralign;	/* memory alignment */
-	Elf32_Word	sh_entsize;	/* table entry size */
-} Elf32_Shdr;
-
-typedef struct {
-	Elf64_Word	sh_name;	/* section name (.shstrtab index) */
-	Elf64_Word	sh_type;	/* section type */
-	Elf64_Xword	sh_flags;	/* section flags */
-	Elf64_Addr	sh_addr;	/* virtual address */
-	Elf64_Off	sh_offset;	/* file offset */
-	Elf64_Xword	sh_size;	/* section size */
-	Elf64_Word	sh_link;	/* link to another */
-	Elf64_Word	sh_info;	/* misc info */
-	Elf64_Xword	sh_addralign;	/* memory alignment */
-	Elf64_Xword	sh_entsize;	/* table entry size */
-} Elf64_Shdr;
-
-/* sh_type */
-#define SHT_NULL	      0		/* Section header table entry unused */
-#define SHT_PROGBITS	      1		/* Program information */
-#define SHT_SYMTAB	      2		/* Symbol table */
-#define SHT_STRTAB	      3		/* String table */
-#define SHT_RELA	      4		/* Relocation information w/ addend */
-#define SHT_HASH	      5		/* Symbol hash table */
-#define SHT_DYNAMIC	      6		/* Dynamic linking information */
-#define SHT_NOTE	      7		/* Auxiliary information */
-#define SHT_NOBITS	      8		/* No space allocated in file image */
-#define SHT_REL		      9		/* Relocation information w/o addend */
-#define SHT_SHLIB	     10		/* Reserved, unspecified semantics */
-#define SHT_DYNSYM	     11		/* Symbol table for dynamic linker */
-#define SHT_INIT_ARRAY	     14		/* Initialization function pointers */
-#define SHT_FINI_ARRAY	     15		/* Termination function pointers */
-#define SHT_PREINIT_ARRAY    16		/* Pre-initialization function ptrs */
-#define SHT_GROUP	     17		/* Section group */
-#define SHT_SYMTAB_SHNDX     18		/* Section indexes (see SHN_XINDEX) */
-#define SHT_NUM		     19
-
-#define SHT_LOOS	     0x60000000 /* Operating system specific range */
-#define SHT_GNU_HASH	     0x6ffffff6 /* GNU style symbol hash table */
-#define SHT_SUNW_move	     0x6ffffffa
-#define SHT_SUNW_syminfo     0x6ffffffc
-#define SHT_SUNW_verdef	     0x6ffffffd /* Versions defined by file */
-#define SHT_GNU_verdef	     SHT_SUNW_verdef
-#define SHT_SUNW_verneed     0x6ffffffe /* Versions needed by file */
-#define SHT_GNU_verneed	     SHT_SUNW_verneed
-#define SHT_SUNW_versym	     0x6fffffff /* Symbol versions */
-#define SHT_GNU_versym	     SHT_SUNW_versym
-#define SHT_HIOS	     0x6fffffff
-#define SHT_LOPROC	     0x70000000 /* Processor-specific range */
-#define SHT_AMD64_UNWIND     0x70000001 /* unwind information */
-#define SHT_ARM_EXIDX	     0x70000001	/* exception index table */
-#define SHT_ARM_PREEMPTMAP   0x70000002 /* BPABI DLL dynamic linking
-					 * pre-emption map */
-#define SHT_ARM_ATTRIBUTES   0x70000003 /* Object file compatibility
-					 * attributes */
-#define SHT_ARM_DEBUGOVERLAY 0x70000004 /* See DBGOVL for details */
-#define SHT_ARM_OVERLAYSECTION 0x70000005
-#define SHT_HIPROC	     0x7fffffff
-#define SHT_LOUSER	     0x80000000 /* Application-specific range */
-#define SHT_HIUSER	     0xffffffff
-
-/* sh_flags */
-#define SHF_WRITE	     0x00000001 /* Contains writable data */
-#define SHF_ALLOC	     0x00000002 /* Occupies memory */
-#define SHF_EXECINSTR	     0x00000004 /* Contains executable insns */
-#define SHF_MERGE	     0x00000010 /* Might be merged */
-#define SHF_STRINGS	     0x00000020 /* Contains nul terminated strings */
-#define SHF_INFO_LINK	     0x00000040 /* "sh_info" contains SHT index */
-#define SHF_LINK_ORDER	     0x00000080 /* Preserve order after combining */
-#define SHF_OS_NONCONFORMING 0x00000100 /* OS specific handling required */
-#define SHF_GROUP	     0x00000200 /* Is member of a group */
-#define SHF_TLS		     0x00000400 /* Holds thread-local data */
-#define SHF_MASKOS	     0x0ff00000 /* Operating system specific values */
-#define SHF_MASKPROC	     0xf0000000 /* Processor-specific values */
-#define SHF_ORDERED	     0x40000000 /* Ordering requirement (Solaris) */
-#define SHF_EXCLUDE	     0x80000000 /* Excluded unless unles ref/alloc
-					   (Solaris).*/
-/*
- * Symbol Table
- */
-typedef struct {
-	Elf32_Word	st_name;	/* Symbol name (.strtab index) */
-	Elf32_Word	st_value;	/* value of symbol */
-	Elf32_Word	st_size;	/* size of symbol */
-	Elf_Byte	st_info;	/* type / binding attrs */
-	Elf_Byte	st_other;	/* unused */
-	Elf32_Half	st_shndx;	/* section index of symbol */
-} Elf32_Sym;
-
-typedef struct {
-	Elf64_Word	st_name;	/* Symbol name (.strtab index) */
-	Elf_Byte	st_info;	/* type / binding attrs */
-	Elf_Byte	st_other;	/* unused */
-	Elf64_Half	st_shndx;	/* section index of symbol */
-	Elf64_Addr	st_value;	/* value of symbol */
-	Elf64_Xword	st_size;	/* size of symbol */
-} Elf64_Sym;
-
-/* Symbol Table index of the undefined symbol */
-#define ELF_SYM_UNDEFINED	0
-
-#define STN_UNDEF		0	/* undefined index */
-
-/* st_info: Symbol Bindings */
-#define STB_LOCAL		0	/* local symbol */
-#define STB_GLOBAL		1	/* global symbol */
-#define STB_WEAK		2	/* weakly defined global symbol */
-#define STB_NUM			3
-
-#define STB_LOOS		10	/* Operating system specific range */
-#define STB_HIOS		12
-#define STB_LOPROC		13	/* Processor-specific range */
-#define STB_HIPROC		15
-
-/* st_info: Symbol Types */
-#define STT_NOTYPE		0	/* Type not specified */
-#define STT_OBJECT		1	/* Associated with a data object */
-#define STT_FUNC		2	/* Associated with a function */
-#define STT_SECTION		3	/* Associated with a section */
-#define STT_FILE		4	/* Associated with a file name */
-#define STT_COMMON		5	/* Uninitialised common block */
-#define STT_TLS			6	/* Thread local data object */
-#define STT_NUM			7
-
-#define STT_LOOS		10	/* Operating system specific range */
-#define STT_HIOS		12
-#define STT_LOPROC		13	/* Processor-specific range */
-#define STT_HIPROC		15
-
-/* st_other: Visibility Types */
-#define STV_DEFAULT		0	/* use binding type */
-#define STV_INTERNAL		1	/* not referenced from outside */
-#define STV_HIDDEN		2	/* not visible, may be used via ptr */
-#define STV_PROTECTED		3	/* visible, not preemptible */
-#define STV_EXPORTED		4
-#define STV_SINGLETON		5
-#define STV_ELIMINATE		6
-
-/* st_info/st_other utility macros */
-#define ELF_ST_BIND(info)		((uint32_t)(info) >> 4)
-#define ELF_ST_TYPE(info)		((uint32_t)(info) & 0xf)
-#define ELF_ST_INFO(bind,type)		((Elf_Byte)(((bind) << 4) | \
-					 ((type) & 0xf)))
-#define ELF_ST_VISIBILITY(other)	((uint32_t)(other) & 3)
-
-/*
- * Special section indexes
- */
-#define SHN_UNDEF	0		/* Undefined section */
-
-#define SHN_LORESERVE	0xff00		/* Reserved range */
-#define SHN_ABS		0xfff1		/*  Absolute symbols */
-#define SHN_COMMON	0xfff2		/*  Common symbols */
-#define SHN_XINDEX	0xffff		/* Escape -- index stored elsewhere */
-#define SHN_HIRESERVE	0xffff
-
-#define SHN_LOPROC	0xff00		/* Processor-specific range */
-#define SHN_HIPROC	0xff1f
-#define SHN_LOOS	0xff20		/* Operating system specific range */
-#define SHN_HIOS	0xff3f
-
-#define SHN_MIPS_ACOMMON 0xff00
-#define SHN_MIPS_TEXT	0xff01
-#define SHN_MIPS_DATA	0xff02
-#define SHN_MIPS_SCOMMON 0xff03
-
-/*
- * Relocation Entries
- */
-typedef struct {
-	Elf32_Word	r_offset;	/* where to do it */
-	Elf32_Word	r_info;		/* index & type of relocation */
-} Elf32_Rel;
-
-typedef struct {
-	Elf32_Word	r_offset;	/* where to do it */
-	Elf32_Word	r_info;		/* index & type of relocation */
-	Elf32_Sword	r_addend;	/* adjustment value */
-} Elf32_Rela;
-
-/* r_info utility macros */
-#define ELF32_R_SYM(info)	((info) >> 8)
-#define ELF32_R_TYPE(info)	((info) & 0xff)
-#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
-
-typedef struct {
-	Elf64_Addr	r_offset;	/* where to do it */
-	Elf64_Xword	r_info;		/* index & type of relocation */
-} Elf64_Rel;
-
-typedef struct {
-	Elf64_Addr	r_offset;	/* where to do it */
-	Elf64_Xword	r_info;		/* index & type of relocation */
-	Elf64_Sxword	r_addend;	/* adjustment value */
-} Elf64_Rela;
-
-/* r_info utility macros */
-#define ELF64_R_SYM(info)	((info) >> 32)
-#define ELF64_R_TYPE(info)	((info) & 0xffffffff)
-#define ELF64_R_INFO(sym,type)	(((sym) << 32) + (type))
-
-/*
- * Move entries
- */
-typedef struct {
-	Elf32_Lword	m_value;	/* symbol value */
-	Elf32_Word	m_info;		/* size + index */
-	Elf32_Word	m_poffset;	/* symbol offset */
-	Elf32_Half	m_repeat;	/* repeat count */
-	Elf32_Half	m_stride;	/* stride info */
-} Elf32_Move;
-
-#define ELF32_M_SYM(info)	((info) >> 8)
-#define ELF32_M_SIZE(info)	((info) & 0xff)
-#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
-
-typedef struct {
-	Elf64_Lword	m_value;	/* symbol value */
-	Elf64_Xword	m_info;		/* size + index */
-	Elf64_Xword	m_poffset;	/* symbol offset */
-	Elf64_Word	m_repeat;	/* repeat count */
-	Elf64_Word	m_stride;	/* stride info */
-} Elf64_Move;
-
-#define ELF64_M_SYM(info)	((info) >> 8)
-#define ELF64_M_SIZE(info)	((info) & 0xff)
-#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
-
-/*
- * Hardware/software capabilities entry
- */
-typedef struct {
-	Elf32_Word		c_tag;	/* entry tag value */
-	union {
-		Elf32_Addr	c_ptr;
-		Elf32_Word	c_val;
-	} c_un;
-} Elf32_Cap;
-
-typedef struct {
-	Elf64_Xword		c_tag;	/* entry tag value */
-	union {
-		Elf64_Addr	c_ptr;
-		Elf64_Xword	c_val;
-	} c_un;
-} Elf64_Cap;
-
-/*
- * Dynamic Section structure array
- */
-typedef struct {
-	Elf32_Word		d_tag;	/* entry tag value */
-	union {
-		Elf32_Addr	d_ptr;
-		Elf32_Word	d_val;
-	} d_un;
-} Elf32_Dyn;
-
-typedef struct {
-	Elf64_Xword		d_tag;	/* entry tag value */
-	union {
-		Elf64_Addr	d_ptr;
-		Elf64_Xword	d_val;
-	} d_un;
-} Elf64_Dyn;
-
-/* d_tag */
-#define DT_NULL		0	/* Marks end of dynamic array */
-#define DT_NEEDED	1	/* Name of needed library (DT_STRTAB offset) */
-#define DT_PLTRELSZ	2	/* Size, in bytes, of relocations in PLT */
-#define DT_PLTGOT	3	/* Address of PLT and/or GOT */
-#define DT_HASH		4	/* Address of symbol hash table */
-#define DT_STRTAB	5	/* Address of string table */
-#define DT_SYMTAB	6	/* Address of symbol table */
-#define DT_RELA		7	/* Address of Rela relocation table */
-#define DT_RELASZ	8	/* Size, in bytes, of DT_RELA table */
-#define DT_RELAENT	9	/* Size, in bytes, of one DT_RELA entry */
-#define DT_STRSZ	10	/* Size, in bytes, of DT_STRTAB table */
-#define DT_SYMENT	11	/* Size, in bytes, of one DT_SYMTAB entry */
-#define DT_INIT		12	/* Address of initialization function */
-#define DT_FINI		13	/* Address of termination function */
-#define DT_SONAME	14	/* Shared object name (DT_STRTAB offset) */
-#define DT_RPATH	15	/* Library search path (DT_STRTAB offset) */
-#define DT_SYMBOLIC	16	/* Start symbol search within local object */
-#define DT_REL		17	/* Address of Rel relocation table */
-#define DT_RELSZ	18	/* Size, in bytes, of DT_REL table */
-#define DT_RELENT	19	/* Size, in bytes, of one DT_REL entry */
-#define DT_PLTREL	20	/* Type of PLT relocation entries */
-#define DT_DEBUG	21	/* Used for debugging; unspecified */
-#define DT_TEXTREL	22	/* Relocations might modify non-writable seg */
-#define DT_JMPREL	23	/* Address of relocations associated with PLT */
-#define DT_BIND_NOW	24	/* Process all relocations at load-time */
-#define DT_INIT_ARRAY	25	/* Address of initialization function array */
-#define DT_FINI_ARRAY	26	/* Size, in bytes, of DT_INIT_ARRAY array */
-#define DT_INIT_ARRAYSZ 27	/* Address of termination function array */
-#define DT_FINI_ARRAYSZ 28	/* Size, in bytes, of DT_FINI_ARRAY array*/
-#define DT_RUNPATH	29	/* overrides DT_RPATH */
-#define DT_FLAGS	30	/* Encodes ORIGIN, SYMBOLIC, TEXTREL, BIND_NOW, STATIC_TLS */
-#define DT_ENCODING	31	/* ??? */
-#define DT_PREINIT_ARRAY 32	/* Address of pre-init function array */
-#define DT_PREINIT_ARRAYSZ 33	/* Size, in bytes, of DT_PREINIT_ARRAY array */
-#define DT_NUM		34
-
-#define DT_LOOS		0x60000000	/* Operating system specific range */
-#define DT_VERSYM	0x6ffffff0	/* Symbol versions */
-#define DT_FLAGS_1	0x6ffffffb	/* ELF dynamic flags */
-#define DT_VERDEF	0x6ffffffc	/* Versions defined by file */
-#define DT_VERDEFNUM	0x6ffffffd	/* Number of versions defined by file */
-#define DT_VERNEED	0x6ffffffe	/* Versions needed by file */
-#define DT_VERNEEDNUM	0x6fffffff	/* Number of versions needed by file */
-#define DT_HIOS		0x6fffffff
-#define DT_LOPROC	0x70000000	/* Processor-specific range */
-#define DT_HIPROC	0x7fffffff
-
-/* Flag values for DT_FLAGS */
-#define DF_ORIGIN	0x00000001	/* uses $ORIGIN */
-#define DF_SYMBOLIC	0x00000002	/* */
-#define DF_TEXTREL	0x00000004	/* */
-#define DF_BIND_NOW	0x00000008	/* */
-#define DF_STATICT_LS	0x00000010	/* */
-
-/* Flag values for DT_FLAGS_1 (incomplete) */
-#define DF_1_BIND_NOW	0x00000001	/* Same as DF_BIND_NOW */
-#define DF_1_NODELETE	0x00000008	/* Set the RTLD_NODELETE for object */
-#define DF_1_INITFIRST	0x00000020	/* Object's init/fini take priority */
-#define DF_1_NOOPEN	0x00000040	/* Do not allow loading on dlopen() */
-
-/*
- * Auxiliary Vectors
- */
-typedef struct {
-	Elf32_Word	a_type;				/* 32-bit id */
-	Elf32_Word	a_v;				/* 32-bit id */
-} Aux32Info;
-
-typedef struct {
-	Elf64_Word	a_type;		/* 32-bit id */
-	Elf64_Xword	a_v;		/* 64-bit id */
-} Aux64Info;
-
-/* BEGIN android-changed: these constants should come from <linux/auxvec.h>. */
-#if 0
-/* a_type */
-#define AT_NULL		0	/* Marks end of array */
-#define AT_IGNORE	1	/* No meaning, a_un is undefined */
-#define AT_EXECFD	2	/* Open file descriptor of object file */
-#define AT_PHDR		3	/* &phdr[0] */
-#define AT_PHENT	4	/* sizeof(phdr[0]) */
-#define AT_PHNUM	5	/* # phdr entries */
-#define AT_PAGESZ	6	/* PAGESIZE */
-#define AT_BASE		7	/* Interpreter base addr */
-#define AT_FLAGS	8	/* Processor flags */
-#define AT_ENTRY	9	/* Entry address of executable */
-#define AT_DCACHEBSIZE	10	/* Data cache block size */
-#define AT_ICACHEBSIZE	11	/* Instruction cache block size */
-#define AT_UCACHEBSIZE	12	/* Unified cache block size */
-#define AT_STACKBASE	13	/* Base address of the main thread */
-
-	/* Vendor specific */
-#define AT_MIPS_NOTELF	10	/* XXX a_val != 0 -> MIPS XCOFF executable */
-
-#define AT_EUID		2000	/* euid (solaris compatible numbers) */
-#define AT_RUID		2001	/* ruid (solaris compatible numbers) */
-#define AT_EGID		2002	/* egid (solaris compatible numbers) */
-#define AT_RGID		2003	/* rgid (solaris compatible numbers) */
-
-	/* Solaris kernel specific */
-#define AT_SUN_LDELF	2004	/* dynamic linker's ELF header */
-#define AT_SUN_LDSHDR	2005	/* dynamic linker's section header */
-#define AT_SUN_LDNAME	2006	/* dynamic linker's name */
-#define AT_SUN_LPGSIZE	2007	/* large pagesize */
-
-	/* Other information */
-#define AT_SUN_PLATFORM 2008	/* sysinfo(SI_PLATFORM) */
-#define AT_SUN_HWCAP	2009	/* process hardware capabilities */
-#define AT_SUN_IFLUSH	2010	/* do we need to flush the instruction cache? */
-#define AT_SUN_CPU	2011	/* CPU name */
-	/* ibcs2 emulation band aid */
-#define AT_SUN_EMUL_ENTRY 2012	/* coff entry point */
-#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
-	/* Executable's fully resolved name */
-#define AT_SUN_EXECNAME 2014
-#endif
-/* END android-changed */
-
-/*
- * Note Headers
- */
-typedef struct {
-	Elf32_Word n_namesz;
-	Elf32_Word n_descsz;
-	Elf32_Word n_type;
-} Elf32_Nhdr;
-
-typedef struct {
-	Elf64_Word n_namesz;
-	Elf64_Word n_descsz;
-	Elf64_Word n_type;
-} Elf64_Nhdr;
-
-#define ELF_NOTE_GNU_NAMESZ		4
-#define ELF_NOTE_GNU_NAME		"GNU\0"
-
-/*
- * GNU-specific note type: ABI tag
- * name: GNU\0
- * namesz: 4
- * desc:
- *	word[0]: OS tag
- *	word[1]: major version
- *	word[2]: minor version
- *	word[3]: teeny version
- * descsz: 16
- */
-/* GNU-specific note name and description sizes */
-#define ELF_NOTE_TYPE_ABI_TAG		1
-#define ELF_NOTE_ABI_NAME		ELF_NOTE_GNU_NAME
-#define ELF_NOTE_ABI_NAMESZ		ELF_NOTE_GNU_NAMESZ
-#define ELF_NOTE_ABI_DESCSZ		16
-/* GNU-specific OS/version value stuff */
-#define ELF_NOTE_ABI_OS_LINUX		0
-#define ELF_NOTE_ABI_OS_HURD		1
-#define ELF_NOTE_ABI_OS_SOLARIS		2
-#define ELF_NOTE_ABI_OS_KFREEBSD	3
-#define ELF_NOTE_ABI_OS_KNETBSD		4
-
-/*
- * GNU-specific note type: Hardware capabilities
- * name: GNU\0
- * namesz: 4
- * desc:
- *	word[0]: Number of entries
- *	word[1]: Bitmask of enabled entries
- *	Followed by a byte id, and a NUL terminated string per entry
- * descsz: variable
- */
-#define ELF_NOTE_TYPE_GNU_HWCAP		2
-
-/*
- * GNU-specific note type: Build ID generated by ld
- * name: GNU\0
- * desc:
- *	word[0..4] SHA1 [default]
- * or
- *	word[0..3] md5 or uuid
- * descsz: 16 or 20
- */
-#define ELF_NOTE_TYPE_GNU_BUILD_ID	3
-
-/* SuSE-specific note type: ABI
- * name: SuSE\0
- * namesz: 5
- * desc:
- *	half[0] = MMmm
- *
- *	M = product major version
- *	m = product minor version
- * descsz: 2
- */
-#define ELF_NOTE_TYPE_SUSE_TAG	1
-/* SuSE-specific note name and description sizes */
-#define ELF_NOTE_SUSE_NAMESZ	5
-#define ELF_NOTE_SUSE_DESCSZ	2
-/* SuSE-specific note name */
-#define ELF_NOTE_SUSE_NAME		"SuSE\0"
-
-/* SuSE-specific note type: version
- * name: SuSE\0\0\0\0
- * namesz: 8
- * desc:
- *	word[0] = VVTTMMmm
- *
- *	V = version of following data
- *	T = product type: [box, sles, nld, whatever]
- *	M = product major version
- *	m = product minor version
- * descsz: 8
- */
-#define ELF_NOTE_TYPE_SUSE_VERSION_TAG	0x45537553	/* SuSE in LE */
-/* SuSE-specific note name and description sizes */
-#define ELF_NOTE_SUSE_VERSION_NAMESZ	8
-#define ELF_NOTE_SUSE_VERSION_DESCSZ	8
-/* SuSE-specific note name */
-#define ELF_NOTE_SUSE_VERSION_NAME		"SuSE\0\0\0\0"
-
-/* NetBSD-specific note type: Emulation name.
- * name: NetBSD\0\0
- * namesz: 8
- * desc:
- *	word[0]: MMmmrrpp00
- *
- *	M = major version
- *	m = minor version
- *	r = release ["",A-Z,Z[A-Z] but numeric]
- *	p = patchlevel
- * descsz: 4
- */
-#define ELF_NOTE_TYPE_NETBSD_TAG	1
-/* NetBSD-specific note name and description sizes */
-#define ELF_NOTE_NETBSD_NAMESZ		7
-#define ELF_NOTE_NETBSD_DESCSZ		4
-/* NetBSD-specific note name */
-#define ELF_NOTE_NETBSD_NAME		"NetBSD\0\0"
-
-/* NetBSD-specific note type: Checksum.
- * There should be 1 NOTE per PT_LOAD section.
- * name: ???
- * namesz: ???
- * desc:
- *	a tuple of <phnum>(16),<chk-type>(16),<chk-value>.
- * descsz: ???
- */
-#define ELF_NOTE_TYPE_CHECKSUM_TAG	2
-#define ELF_NOTE_CHECKSUM_CRC32		1
-#define ELF_NOTE_CHECKSUM_MD5		2
-#define ELF_NOTE_CHECKSUM_SHA1		3
-#define ELF_NOTE_CHECKSUM_SHA256	4
-
-/*
- * NetBSD-specific note type: PaX.
- * There should be 1 NOTE per executable.
- * name: PaX\0
- * namesz: 4
- * desc:
- *	word[0]: capability bitmask
- * descsz: 4
- */
-#define ELF_NOTE_TYPE_PAX_TAG		3
-#define ELF_NOTE_PAX_MPROTECT		0x01	/* Force enable Mprotect */
-#define ELF_NOTE_PAX_NOMPROTECT		0x02	/* Force disable Mprotect */
-#define ELF_NOTE_PAX_GUARD		0x04	/* Force enable Segvguard */
-#define ELF_NOTE_PAX_NOGUARD		0x08	/* Force disable Servguard */
-#define ELF_NOTE_PAX_ASLR		0x10	/* Force enable ASLR */
-#define ELF_NOTE_PAX_NOASLR		0x20	/* Force disable ASLR */
-#define ELF_NOTE_PAX_NAMESZ		4
-#define ELF_NOTE_PAX_NAME		"PaX\0"
-#define ELF_NOTE_PAX_DESCSZ		4
-
-/*
- * NetBSD-specific core file information.
- *
- * NetBSD ELF core files use notes to provide information about
- * the process's state.	 The note name is "NetBSD-CORE" for
- * information that is global to the process, and "NetBSD-CORE@nn",
- * where "nn" is the lwpid of the LWP that the information belongs
- * to (such as register state).
- *
- * We use the following note identifiers:
- *
- *	ELF_NOTE_NETBSD_CORE_PROCINFO
- *		Note is a "netbsd_elfcore_procinfo" structure.
- *
- * We also use ptrace(2) request numbers (the ones that exist in
- * machine-dependent space) to identify register info notes.  The
- * info in such notes is in the same format that ptrace(2) would
- * export that information.
- *
- * Please try to keep the members of this structure nicely aligned,
- * and if you add elements, add them to the end and bump the version.
- */
-
-#define ELF_NOTE_NETBSD_CORE_NAME	"NetBSD-CORE"
-
-#define ELF_NOTE_NETBSD_CORE_PROCINFO	1
-
-#define NETBSD_ELFCORE_PROCINFO_VERSION 1
-
-struct netbsd_elfcore_procinfo {
-	/* Version 1 fields start here. */
-	uint32_t	cpi_version;		/* our version */
-	uint32_t	cpi_cpisize;		/* sizeof(this struct) */
-	uint32_t	cpi_signo;		/* killing signal */
-	uint32_t	cpi_sigcode;		/* signal code */
-	uint32_t	cpi_sigpend[4];		/* pending signals */
-	uint32_t	cpi_sigmask[4];		/* blocked signals */
-	uint32_t	cpi_sigignore[4];	/* ignored signals */
-	uint32_t	cpi_sigcatch[4];	/* caught signals */
-	int32_t		cpi_pid;		/* process ID */
-	int32_t		cpi_ppid;		/* parent process ID */
-	int32_t		cpi_pgrp;		/* process group ID */
-	int32_t		cpi_sid;		/* session ID */
-	uint32_t	cpi_ruid;		/* real user ID */
-	uint32_t	cpi_euid;		/* effective user ID */
-	uint32_t	cpi_svuid;		/* saved user ID */
-	uint32_t	cpi_rgid;		/* real group ID */
-	uint32_t	cpi_egid;		/* effective group ID */
-	uint32_t	cpi_svgid;		/* saved group ID */
-	uint32_t	cpi_nlwps;		/* number of LWPs */
-	int8_t		cpi_name[32];		/* copy of p->p_comm */
-	/* Add version 2 fields below here. */
-	int32_t		cpi_siglwp;	/* LWP target of killing signal */
-};
-
-/*
- * NetBSD-specific note type: MACHINE_ARCH.
- * There should be 1 NOTE per executable.
- * name:	NetBSD\0
- * namesz:	7
- * desc:	string
- * descsz:	variable
- */
-#define ELF_NOTE_TYPE_MARCH_TAG		5
-/* NetBSD-specific note name and description sizes */
-#define ELF_NOTE_MARCH_NAMESZ		ELF_NOTE_NETBSD_NAMESZ
-/* NetBSD-specific note name */
-#define ELF_NOTE_MARCH_NAME		ELF_NOTE_NETBSD_NAME
-
-#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
-#define ELFSIZE ARCH_ELFSIZE
-#endif
-
-#if defined(ELFSIZE)
-#define CONCAT(x,y)	__CONCAT(x,y)
-#define ELFNAME(x)	CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
-#define ELFNAME2(x,y)	CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
-#define ELFNAMEEND(x)	CONCAT(x,CONCAT(_elf,ELFSIZE))
-#define ELFDEFNNAME(x)	CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
-#endif
-
-#if defined(ELFSIZE) && (ELFSIZE == 32)
-#define Elf_Ehdr	Elf32_Ehdr
-#define Elf_Phdr	Elf32_Phdr
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Rel		Elf32_Rel
-#define Elf_Rela	Elf32_Rela
-#define Elf_Dyn		Elf32_Dyn
-#define Elf_Word	Elf32_Word
-#define Elf_Sword	Elf32_Sword
-#define Elf_Half	Elf32_Half
-#define Elf_Addr	Elf32_Addr
-#define Elf_Off		Elf32_Off
-#define Elf_SOff	Elf32_SOff
-#define Elf_Nhdr	Elf32_Nhdr
-#define Elf_Verdef	Elf32_Verdef
-#define Elf_Verdaux	Elf32_Verdaux
-#define Elf_Verneed	Elf32_Verneed
-#define Elf_Vernaux	Elf32_Vernaux
-#define Elf_Versym	Elf32_Versym
-
-#define ELF_R_SYM	ELF32_R_SYM
-#define ELF_R_TYPE	ELF32_R_TYPE
-#define ELFCLASS	ELFCLASS32
-
-#define AuxInfo		Aux32Info
-#elif defined(ELFSIZE) && (ELFSIZE == 64)
-#define Elf_Ehdr	Elf64_Ehdr
-#define Elf_Phdr	Elf64_Phdr
-#define Elf_Shdr	Elf64_Shdr
-#define Elf_Sym		Elf64_Sym
-#define Elf_Rel		Elf64_Rel
-#define Elf_Rela	Elf64_Rela
-#define Elf_Dyn		Elf64_Dyn
-#define Elf_Word	Elf64_Word
-#define Elf_Sword	Elf64_Sword
-#define Elf_Half	Elf64_Half
-#define Elf_Addr	Elf64_Addr
-#define Elf_Off		Elf64_Off
-#define Elf_SOff	Elf64_SOff
-#define Elf_Nhdr	Elf64_Nhdr
-#define Elf_Verdef	Elf64_Verdef
-#define Elf_Verdaux	Elf64_Verdaux
-#define Elf_Verneed	Elf64_Verneed
-#define Elf_Vernaux	Elf64_Vernaux
-#define Elf_Versym	Elf64_Versym
-
-#define ELF_R_SYM	ELF64_R_SYM
-#define ELF_R_TYPE	ELF64_R_TYPE
-#define ELFCLASS	ELFCLASS64
-
-#define AuxInfo		Aux64Info
-#endif
-
-#ifndef Elf_Symindx
-#define Elf_Symindx	uint32_t
-#endif
-
-#define ELF32_ST_BIND(info)		ELF_ST_BIND(info)
-#define ELF32_ST_TYPE(info)		ELF_ST_TYPE(info)
-#define ELF32_ST_INFO(bind,type)	ELF_ST_INFO(bind,type)
-#define ELF32_ST_VISIBILITY(other)	ELF_ST_VISIBILITY(other)
-
-#define ELF64_ST_BIND(info)		ELF_ST_BIND(info)
-#define ELF64_ST_TYPE(info)		ELF_ST_TYPE(info)
-#define ELF64_ST_INFO(bind,type)	ELF_ST_INFO(bind,type)
-#define ELF64_ST_VISIBILITY(other)	ELF_ST_VISIBILITY(other)
-
-typedef struct {
-	Elf32_Half	si_boundto;	/* direct bindings - symbol bound to */
-	Elf32_Half	si_flags;	/* per symbol flags */
-} Elf32_Syminfo;
-
-typedef struct {
-	Elf64_Word	si_boundto;	/* direct bindings - symbol bound to */
-	Elf64_Word	si_flags;	/* per symbol flags */
-} Elf64_Syminfo;
-
-#define SYMINFO_FLG_DIRECT	0x0001	/* symbol ref has direct association
-					   to object containing definition */
-#define SYMINFO_FLG_PASSTHRU	0x0002	/* ignored - see SYMINFO_FLG_FILTER */
-#define SYMINFO_FLG_COPY	0x0004	/* symbol is a copy-reloc */
-#define SYMINFO_FLG_LAZYLOAD	0x0008	/* object containing defn should be
-					   lazily-loaded */
-#define SYMINFO_FLG_DIRECTBIND	0x0010	/* ref should be bound directly to
-					   object containing definition */
-#define SYMINFO_FLG_NOEXTDIRECT 0x0020	/* don't let an external reference
-					   directly bind to this symbol */
-#define SYMINFO_FLG_FILTER	0x0002	/* symbol ref is associated to a */
-#define SYMINFO_FLG_AUXILIARY	0x0040	/*	standard or auxiliary filter */
-
-#define SYMINFO_BT_SELF		0xffff	/* symbol bound to self */
-#define SYMINFO_BT_PARENT	0xfffe	/* symbol bound to parent */
-#define SYMINFO_BT_NONE		0xfffd	/* no special symbol binding */
-#define SYMINFO_BT_EXTERN	0xfffc	/* symbol defined as external */
-#define SYMINFO_BT_LOWRESERVE	0xff00	/* beginning of reserved entries */
-
-#define SYMINFO_NONE		0	/* Syminfo version */
-#define SYMINFO_CURRENT		1
-#define SYMINFO_NUM		2
-
-/*
- * These constants are used for Elf32_Verdef struct's version number.
- */
-#define VER_DEF_NONE		0
-#define VER_DEF_CURRENT		1
-
-/*
- * These constants are used for Elf32_Verdef struct's vd_ndx.
- */
-#define VER_DEF_IDX(x)		VER_NDX(x)
-
-/*
- * These constants are used for Elf32_Verdef struct's vd_flags.
- */
-#define VER_FLG_BASE		0x1
-#define VER_FLG_WEAK		0x2
-
-/*
- * These are used in an Elf32_Versym field.
- */
-#define VER_NDX_LOCAL		0
-#define VER_NDX_GLOBAL		1
-#define VER_NDX_GIVEN		2
-
-/*
- * These constants are used for Elf32_Verneed struct's version number.
- */
-#define VER_NEED_NONE		0
-#define VER_NEED_CURRENT	1
-
-/*
- * These constants are used for Elf32_Vernaux struct's vna_other.
- */
-#define VER_NEED_HIDDEN		VER_NDX_HIDDEN
-#define VER_NEED_IDX(x)		VER_NDX(x)
-
-/* index */
-#define VER_NDX_HIDDEN		0x8000
-#define VER_NDX(x)		((x) & ~VER_NDX_HIDDEN)
-
-/*
- * GNU Extension hidding symbol
- */
-#define VERSYM_HIDDEN		0x8000
-#define VERSYM_VERSION		0x7fff
-
-#define ELF_VER_CHR		'@'
-
-/*
- * These are current size independent.
- */
-
-typedef struct {
-	Elf32_Half	vd_version;	/* version number of structure */
-	Elf32_Half	vd_flags;	/* flags (VER_FLG_*) */
-	Elf32_Half	vd_ndx;		/* version index */
-	Elf32_Half	vd_cnt;		/* number of verdaux entries */
-	Elf32_Word	vd_hash;	/* hash of name */
-	Elf32_Word	vd_aux;		/* offset to verdaux entries */
-	Elf32_Word	vd_next;	/* offset to next verdef */
-} Elf32_Verdef;
-typedef Elf32_Verdef	Elf64_Verdef;
-
-typedef struct {
-	Elf32_Word	vda_name;	/* string table offset of name */
-	Elf32_Word	vda_next;	/* offset to verdaux */
-} Elf32_Verdaux;
-typedef Elf32_Verdaux	Elf64_Verdaux;
-
-typedef struct {
-	Elf32_Half	vn_version;	/* version number of structure */
-	Elf32_Half	vn_cnt;		/* number of vernaux entries */
-	Elf32_Word	vn_file;	/* string table offset of library name*/
-	Elf32_Word	vn_aux;		/* offset to vernaux entries */
-	Elf32_Word	vn_next;	/* offset to next verneed */
-} Elf32_Verneed;
-typedef Elf32_Verneed	Elf64_Verneed;
-
-typedef struct {
-	Elf32_Word	vna_hash;	/* Hash of dependency name */
-	Elf32_Half	vna_flags;	/* flags (VER_FLG_*) */
-	Elf32_Half	vna_other;	/* unused */
-	Elf32_Word	vna_name;	/* string table offset to version name*/
-	Elf32_Word	vna_next;	/* offset to next vernaux */
-} Elf32_Vernaux;
-typedef Elf32_Vernaux	Elf64_Vernaux;
-
-typedef struct {
-	Elf32_Half	vs_vers;
-} Elf32_Versym;
-typedef Elf32_Versym	Elf64_Versym;
-
-#ifdef _KERNEL
-
-#define ELF_AUX_ENTRIES 15	/* Max size of aux array passed to loader */
-#define ELF32_NO_ADDR	(~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
-#define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */
-#define ELF64_NO_ADDR	(~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
-#define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */
-
-#if defined(ELFSIZE) && (ELFSIZE == 64)
-#define ELF_NO_ADDR	ELF64_NO_ADDR
-#define ELF_LINK_ADDR	ELF64_LINK_ADDR
-#elif defined(ELFSIZE) && (ELFSIZE == 32)
-#define ELF_NO_ADDR	ELF32_NO_ADDR
-#define ELF_LINK_ADDR	ELF32_LINK_ADDR
-#endif
-
-#ifndef ELF32_EHDR_FLAGS_OK
-#define ELF32_EHDR_FLAGS_OK(eh) 1
-#endif
-
-#ifndef ELF64_EHDR_FLAGS_OK
-#define ELF64_EHDR_FLAGS_OK(eh) 1
-#endif
-
-#if defined(ELFSIZE) && (ELFSIZE == 64)
-#define ELF_EHDR_FLAGS_OK(eh)	ELF64_EHDR_FLAGS_OK(eh)
-#else
-#define ELF_EHDR_FLAGS_OK(eh)	ELF32_EHDR_FLAGS_OK(eh)
-#endif
-
-#if defined(ELFSIZE)
-struct elf_args {
-	Elf_Addr	arg_entry;	/* program entry point */
-	Elf_Addr	arg_interp;	/* Interpreter load address */
-	Elf_Addr	arg_phaddr;	/* program header address */
-	Elf_Addr	arg_phentsize;	/* Size of program header */
-	Elf_Addr	arg_phnum;	/* Number of program headers */
-};
-#endif
-
-#ifdef _KERNEL_OPT
-#include "opt_execfmt.h"
-#endif
-
-struct ps_strings;
-
-#ifdef EXEC_ELF32
-int	exec_elf32_makecmds(struct lwp *, struct exec_package *);
-int	elf32_copyargs(struct lwp *, struct exec_package *,
-    struct ps_strings *, char **, void *);
-
-int	coredump_elf32(struct lwp *, void *);
-int	coredump_writenote_elf32(struct proc *, void *, Elf32_Nhdr *,
-    const char *, void *);
-
-int	elf32_check_header(Elf32_Ehdr *, int);
-#endif
-
-#ifdef EXEC_ELF64
-int	exec_elf64_makecmds(struct lwp *, struct exec_package *);
-int	elf64_copyargs(struct lwp *, struct exec_package *,
-    struct ps_strings *, char **, void *);
-
-int	coredump_elf64(struct lwp *, void *);
-int	coredump_writenote_elf64(struct proc *, void *, Elf64_Nhdr *,
-    const char *, void *);
-
-int	elf64_check_header(Elf64_Ehdr *, int);
-#endif
-
-#endif /* _KERNEL */
-
-#endif /* !_SYS_EXEC_ELF_H_ */
diff --git a/libc/include/sys/fsuid.h b/libc/include/sys/fsuid.h
index bc47e3d..03355b7 100644
--- a/libc/include/sys/fsuid.h
+++ b/libc/include/sys/fsuid.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_FSUID_H_
 #define _SYS_FSUID_H_
 
@@ -33,10 +34,8 @@
 
 __BEGIN_DECLS
 
-#if 0 /* MISSING FROM BIONIC */
 extern int setfsuid(uid_t);
 extern int setfsgid(gid_t);
-#endif /* MISSING */
 
 __END_DECLS
 
diff --git a/libc/include/sys/glibc-syscalls.h b/libc/include/sys/glibc-syscalls.h
index 3131b6b..459ee78 100644
--- a/libc/include/sys/glibc-syscalls.h
+++ b/libc/include/sys/glibc-syscalls.h
@@ -217,10 +217,12 @@
 #define SYS_sched_get_priority_max __NR_sched_get_priority_max
 #define SYS_sched_get_priority_min __NR_sched_get_priority_min
 #define SYS_sched_getaffinity __NR_sched_getaffinity
+#define SYS_sched_getattr __NR_sched_getattr
 #define SYS_sched_getparam __NR_sched_getparam
 #define SYS_sched_getscheduler __NR_sched_getscheduler
 #define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
 #define SYS_sched_setaffinity __NR_sched_setaffinity
+#define SYS_sched_setattr __NR_sched_setattr
 #define SYS_sched_setparam __NR_sched_setparam
 #define SYS_sched_setscheduler __NR_sched_setscheduler
 #define SYS_sched_yield __NR_sched_yield
@@ -545,10 +547,12 @@
 #define SYS_sched_get_priority_max __NR_sched_get_priority_max
 #define SYS_sched_get_priority_min __NR_sched_get_priority_min
 #define SYS_sched_getaffinity __NR_sched_getaffinity
+#define SYS_sched_getattr __NR_sched_getattr
 #define SYS_sched_getparam __NR_sched_getparam
 #define SYS_sched_getscheduler __NR_sched_getscheduler
 #define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
 #define SYS_sched_setaffinity __NR_sched_setaffinity
+#define SYS_sched_setattr __NR_sched_setattr
 #define SYS_sched_setparam __NR_sched_setparam
 #define SYS_sched_setscheduler __NR_sched_setscheduler
 #define SYS_sched_yield __NR_sched_yield
@@ -902,10 +906,12 @@
 #define SYS_sched_get_priority_max __NR_sched_get_priority_max
 #define SYS_sched_get_priority_min __NR_sched_get_priority_min
 #define SYS_sched_getaffinity __NR_sched_getaffinity
+#define SYS_sched_getattr __NR_sched_getattr
 #define SYS_sched_getparam __NR_sched_getparam
 #define SYS_sched_getscheduler __NR_sched_getscheduler
 #define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
 #define SYS_sched_setaffinity __NR_sched_setaffinity
+#define SYS_sched_setattr __NR_sched_setattr
 #define SYS_sched_setparam __NR_sched_setparam
 #define SYS_sched_setscheduler __NR_sched_setscheduler
 #define SYS_sched_yield __NR_sched_yield
@@ -1258,10 +1264,12 @@
 #define SYS_sched_get_priority_max __NR_sched_get_priority_max
 #define SYS_sched_get_priority_min __NR_sched_get_priority_min
 #define SYS_sched_getaffinity __NR_sched_getaffinity
+#define SYS_sched_getattr __NR_sched_getattr
 #define SYS_sched_getparam __NR_sched_getparam
 #define SYS_sched_getscheduler __NR_sched_getscheduler
 #define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
 #define SYS_sched_setaffinity __NR_sched_setaffinity
+#define SYS_sched_setattr __NR_sched_setattr
 #define SYS_sched_setparam __NR_sched_setparam
 #define SYS_sched_setscheduler __NR_sched_setscheduler
 #define SYS_sched_yield __NR_sched_yield
@@ -1586,10 +1594,12 @@
 #define SYS_sched_get_priority_max __NR_sched_get_priority_max
 #define SYS_sched_get_priority_min __NR_sched_get_priority_min
 #define SYS_sched_getaffinity __NR_sched_getaffinity
+#define SYS_sched_getattr __NR_sched_getattr
 #define SYS_sched_getparam __NR_sched_getparam
 #define SYS_sched_getscheduler __NR_sched_getscheduler
 #define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
 #define SYS_sched_setaffinity __NR_sched_setaffinity
+#define SYS_sched_setattr __NR_sched_setattr
 #define SYS_sched_setparam __NR_sched_setparam
 #define SYS_sched_setscheduler __NR_sched_setscheduler
 #define SYS_sched_yield __NR_sched_yield
diff --git a/libc/include/sys/ioctl.h b/libc/include/sys/ioctl.h
index 49d452c..a1014dc 100644
--- a/libc/include/sys/ioctl.h
+++ b/libc/include/sys/ioctl.h
@@ -38,6 +38,7 @@
 #include <asm/ioctls.h>
 #include <asm/termbits.h>
 #include <sys/ioctl_compat.h>
+#include <linux/tty.h>
 
 __BEGIN_DECLS
 
diff --git a/libc/include/sys/klog.h b/libc/include/sys/klog.h
index 02851d2..acfaa20 100644
--- a/libc/include/sys/klog.h
+++ b/libc/include/sys/klog.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_KLOG_H_
 #define _SYS_KLOG_H_
 
@@ -45,13 +46,6 @@
 #define KLOG_SIZE_UNREAD   9
 #define KLOG_SIZE_BUFFER   10
 
-/* These are deprecated names that were used in earlier bionic releases. Do not use. */
-#define KLOG_DISABLE 6
-#define KLOG_ENABLE 7
-#define KLOG_SETLEVEL 8
-#define KLOG_UNREADSIZE 9
-#define KLOG_WRITE 10
-
 extern int klogctl(int, char *, int);
 
 __END_DECLS
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index 36f73b2..c50eb10 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -31,9 +31,6 @@
 
 /* Common definitions for limits.h. */
 
-/* Legacy */
-#include <machine/limits.h>
-
 #define	CHAR_BIT	8		/* number of bits in a char */
 
 #define	SCHAR_MAX	0x7f		/* max value for a signed char */
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index 7c5f8d7..5a8c985 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -31,7 +31,6 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 #include <asm/mman.h>
-#include <asm/page.h>
 
 __BEGIN_DECLS
 
@@ -44,23 +43,23 @@
 #define MREMAP_MAYMOVE  1
 #define MREMAP_FIXED    2
 
-extern void*  mmap(void *, size_t, int, int, int, off_t);
-extern void*  mmap64(void *, size_t, int, int, int, off64_t);
-extern int    munmap(void *, size_t);
-extern int    msync(const void *, size_t, int);
-extern int    mprotect(const void *, size_t, int);
-extern void*  mremap(void *, size_t, size_t, unsigned long);
+extern void* mmap(void*, size_t, int, int, int, off_t);
+extern void* mmap64(void*, size_t, int, int, int, off64_t);
+extern int munmap(void*, size_t);
+extern int msync(const void*, size_t, int);
+extern int mprotect(const void*, size_t, int);
+extern void* mremap(void*, size_t, size_t, unsigned long);
 
-extern int    mlockall(int);
-extern int    munlockall(void);
-extern int    mlock(const void *, size_t);
-extern int    munlock(const void *, size_t);
-extern int    madvise(const void *, size_t, int);
+extern int mlockall(int);
+extern int munlockall(void);
+extern int mlock(const void*, size_t);
+extern int munlock(const void*, size_t);
+extern int madvise(const void*, size_t, int);
 
-extern int    mlock(const void *addr, size_t len);
-extern int    munlock(const void *addr, size_t len);
+extern int mlock(const void*, size_t);
+extern int munlock(const void*, size_t);
 
-extern int    mincore(void*  start, size_t  length, unsigned char*  vec);
+extern int mincore(void*, size_t, unsigned char*);
 
 __END_DECLS
 
diff --git a/libc/include/sys/param.h b/libc/include/sys/param.h
index 37c6427..e64d6ce 100644
--- a/libc/include/sys/param.h
+++ b/libc/include/sys/param.h
@@ -34,16 +34,6 @@
 #define MAXPATHLEN  PATH_MAX
 #define MAXSYMLINKS 8
 
-#if __LP64__
-#define ALIGNBYTES 7
-#else
-#define ALIGNBYTES 3
-#endif
-
-#ifndef ALIGN
-#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
-#endif
-
 /* Macros for counting and rounding. */
 #ifndef howmany
 #define howmany(x, y)   (((x)+((y)-1))/(y))
diff --git a/libc/include/sys/prctl.h b/libc/include/sys/prctl.h
index 00e5837..d96b8b6 100644
--- a/libc/include/sys/prctl.h
+++ b/libc/include/sys/prctl.h
@@ -25,23 +25,18 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_PRCTL_H
 #define _SYS_PRCTL_H
 
-#include <linux/prctl.h>
 #include <sys/cdefs.h>
 
+#include <linux/prctl.h>
+
 __BEGIN_DECLS
 
-/* IMPORTANT NOTE: This function is declared as taking a variable number
- *                 of arguments to match the GLibc definition. However
- *                 its declaration inside SYSCALLS.TXT *must* make it
- *                 take 6 arguments to ensure consistency with the kernel
- *                 implementation.
- */
 extern int prctl(int option, ...);
 
 __END_DECLS
 
 #endif /* _SYS_PRCTL_H */
-
diff --git a/libc/include/sys/ptrace.h b/libc/include/sys/ptrace.h
index 848416b..8bba9fe 100644
--- a/libc/include/sys/ptrace.h
+++ b/libc/include/sys/ptrace.h
@@ -30,15 +30,15 @@
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
-/* For all of the defines */
 #include <linux/ptrace.h>
 
 __BEGIN_DECLS
 
-#define PTRACE_POKEUSER     PTRACE_POKEUSR
-#define PTRACE_PEEKUSER     PTRACE_PEEKUSR
+/* glibc uses different names from the kernel for these two... */
+#define PTRACE_POKEUSER PTRACE_POKEUSR
+#define PTRACE_PEEKUSER PTRACE_PEEKUSR
 
-extern long ptrace(int request, pid_t pid, void *addr, void *data);
+extern long ptrace(int, ...);
 
 __END_DECLS
 
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 32d98ea..ae2f238 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -43,8 +43,9 @@
 __BEGIN_DECLS
 
 #define sockaddr_storage __kernel_sockaddr_storage
-typedef __sa_family_t sa_family_t;
-typedef int socklen_t;
+typedef unsigned short sa_family_t;
+
+struct timespec;
 
 #ifdef __mips__
 #define SOCK_DGRAM      1
@@ -76,69 +77,56 @@
 };
 
 struct sockaddr {
- sa_family_t sa_family;
- char sa_data[14];
+  sa_family_t sa_family;
+  char sa_data[14];
 };
 
 struct linger {
- int l_onoff;
- int l_linger;
+  int l_onoff;
+  int l_linger;
 };
 
 struct msghdr {
- void * msg_name;
- int msg_namelen;
- struct iovec * msg_iov;
- __kernel_size_t msg_iovlen;
- void * msg_control;
- __kernel_size_t msg_controllen;
- unsigned msg_flags;
+  void* msg_name;
+  socklen_t msg_namelen;
+  struct iovec* msg_iov;
+  size_t msg_iovlen;
+  void* msg_control;
+  size_t msg_controllen;
+  int msg_flags;
+};
+
+struct mmsghdr {
+  struct msghdr msg_hdr;
+  unsigned int msg_len;
 };
 
 struct cmsghdr {
- __kernel_size_t cmsg_len;
- int cmsg_level;
- int cmsg_type;
+  size_t cmsg_len;
+  int cmsg_level;
+  int cmsg_type;
 };
 
-#define __CMSG_NXTHDR(ctl, len, cmsg) __cmsg_nxthdr((ctl),(len),(cmsg))
-#define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg))
+#define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr((mhdr), (cmsg))
 #define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
-#define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
+#define CMSG_DATA(cmsg) ((void*)((char*)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
 #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
 #define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
-#define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ?   (struct cmsghdr *)(ctl) :   (struct cmsghdr *)NULL)
-#define CMSG_FIRSTHDR(msg) __CMSG_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen)
-#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) &&   (cmsg)->cmsg_len <= (unsigned long)   ((mhdr)->msg_controllen -   ((char *)(cmsg) - (char *)(mhdr)->msg_control)))
+#define CMSG_FIRSTHDR(msg) \
+  ((msg)->msg_controllen >= sizeof(struct cmsghdr) \
+   ? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
+#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) &&   (cmsg)->cmsg_len <= (unsigned long)   ((mhdr)->msg_controllen -   ((char*)(cmsg) - (char*)(mhdr)->msg_control)))
 
-#ifdef __GNUC__
-#define __KINLINE static __inline__
-#elif defined(__cplusplus)
-#define __KINLINE static inline
-#else
-#define __KINLINE static
-#endif
-
-__KINLINE struct cmsghdr * __cmsg_nxthdr(void *__ctl, __kernel_size_t __size, struct cmsghdr *__cmsg) {
- struct cmsghdr * __ptr;
- __ptr = (struct cmsghdr*)(((unsigned char *) __cmsg) + CMSG_ALIGN(__cmsg->cmsg_len));
- if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size)
- return (struct cmsghdr *)0;
- return __ptr;
-}
-
-__KINLINE struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr *__cmsg) {
- return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
-}
+struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*);
 
 #define SCM_RIGHTS 0x01
 #define SCM_CREDENTIALS 0x02
 #define SCM_SECURITY 0x03
 
 struct ucred {
- __u32 pid;
- __u32 uid;
- __u32 gid;
+  pid_t pid;
+  uid_t uid;
+  gid_t gid;
 };
 
 #define AF_UNSPEC 0
@@ -242,6 +230,9 @@
 #define MSG_ERRQUEUE 0x2000
 #define MSG_NOSIGNAL 0x4000
 #define MSG_MORE 0x8000
+#define MSG_WAITFORONE 0x10000
+#define MSG_FASTOPEN 0x20000000
+#define MSG_CMSG_CLOEXEC 0x40000000
 #define MSG_EOF MSG_FIN
 #define MSG_CMSG_COMPAT 0
 
@@ -277,43 +268,46 @@
 # define __socketcall extern
 #endif
 
-__socketcall int socket(int, int, int);
-__socketcall int bind(int, const struct sockaddr *, int);
-__socketcall int connect(int, const struct sockaddr *, socklen_t);
+__socketcall int accept(int, struct sockaddr*, socklen_t*);
+__socketcall int accept4(int, struct sockaddr*, socklen_t*, int);
+__socketcall int bind(int, const struct sockaddr*, int);
+__socketcall int connect(int, const struct sockaddr*, socklen_t);
+__socketcall int getpeername(int, struct sockaddr*, socklen_t*);
+__socketcall int getsockname(int, struct sockaddr*, socklen_t*);
+__socketcall int getsockopt(int, int, int, void*, socklen_t*);
 __socketcall int listen(int, int);
-__socketcall int accept(int, struct sockaddr *, socklen_t *);
-__socketcall int getsockname(int, struct sockaddr *, socklen_t *);
-__socketcall int getpeername(int, struct sockaddr *, socklen_t *);
-__socketcall int socketpair(int, int, int, int *);
+__socketcall int recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*);
+__socketcall int recvmsg(int, struct msghdr*, int);
+__socketcall int sendmmsg(int, const struct mmsghdr*, unsigned int, int);
+__socketcall int sendmsg(int, const struct msghdr*, int);
+__socketcall int setsockopt(int, int, int, const void*, socklen_t);
 __socketcall int shutdown(int, int);
-__socketcall int setsockopt(int, int, int, const void *, socklen_t);
-__socketcall int getsockopt(int, int, int, void *, socklen_t *);
-__socketcall int sendmsg(int, const struct msghdr *, unsigned int);
-__socketcall int recvmsg(int, struct msghdr *, unsigned int);
+__socketcall int socket(int, int, int);
+__socketcall int socketpair(int, int, int, int*);
 
-extern  ssize_t  send(int, const void *, size_t, unsigned int);
-extern  ssize_t  recv(int, void *, size_t, unsigned int);
+extern ssize_t send(int, const void*, size_t, int);
+extern ssize_t recv(int, void*, size_t, int);
 
-__socketcall ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
-__socketcall ssize_t recvfrom(int, void *, size_t, unsigned int, const struct sockaddr *, socklen_t *);
+__socketcall ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t);
+__socketcall ssize_t recvfrom(int, void*, size_t, int, const struct sockaddr*, socklen_t*);
 
 #if defined(__BIONIC_FORTIFY)
 __errordecl(__recvfrom_error, "recvfrom called with size bigger than buffer");
-extern ssize_t __recvfrom_chk(int, void*, size_t, size_t, unsigned int, const struct sockaddr*, socklen_t *);
-extern ssize_t __recvfrom_real(int, void *, size_t, unsigned int, const struct sockaddr*, socklen_t*)
+extern ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, const struct sockaddr*, socklen_t*);
+extern ssize_t __recvfrom_real(int, void*, size_t, int, const struct sockaddr*, socklen_t*)
     __asm__(__USER_LABEL_PREFIX__ "recvfrom");
 
 __BIONIC_FORTIFY_INLINE
-ssize_t recvfrom(int fd, void* buf, size_t len, unsigned int flags, const struct sockaddr* src_addr, socklen_t* addrlen) {
+ssize_t recvfrom(int fd, void* buf, size_t len, int flags, const struct sockaddr* src_addr, socklen_t* addr_len) {
   size_t bos = __bos0(buf);
 
 #if !defined(__clang__)
   if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
-    return __recvfrom_real(fd, buf, len, flags, src_addr, addrlen);
+    return __recvfrom_real(fd, buf, len, flags, src_addr, addr_len);
   }
 
   if (__builtin_constant_p(len) && (len <= bos)) {
-    return __recvfrom_real(fd, buf, len, flags, src_addr, addrlen);
+    return __recvfrom_real(fd, buf, len, flags, src_addr, addr_len);
   }
 
   if (__builtin_constant_p(len) && (len > bos)) {
@@ -321,12 +315,12 @@
   }
 #endif
 
-  return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addrlen);
+  return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len);
 }
 
 __BIONIC_FORTIFY_INLINE
-ssize_t recv(int socket, void *buf, size_t buflen, unsigned int flags) {
-  return recvfrom(socket, buf, buflen, flags, NULL, 0);
+ssize_t recv(int socket, void* buf, size_t len, int flags) {
+  return recvfrom(socket, buf, len, flags, NULL, 0);
 }
 
 #endif /* __BIONIC_FORTIFY */
diff --git a/libc/include/sys/socketcalls.h b/libc/include/sys/socketcalls.h
index c74f463..131e0bb 100644
--- a/libc/include/sys/socketcalls.h
+++ b/libc/include/sys/socketcalls.h
@@ -47,5 +47,8 @@
 #define SYS_GETSOCKOPT  15              /* sys_getsockopt(2)            */
 #define SYS_SENDMSG     16              /* sys_sendmsg(2)               */
 #define SYS_RECVMSG     17              /* sys_recvmsg(2)               */
+#define SYS_ACCEPT4     18              /* sys_accept4(2)               */
+#define SYS_RECVMMSG    19              /* sys_recvmmsg(2)              */
+#define SYS_SENDMMSG    20              /* sys_sendmmsg(2)              */
 
 #endif /* _SYS_SOCKETCALLS_H_ */
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 3d754c0..c0c168b 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -38,101 +38,103 @@
 __BEGIN_DECLS
 
 #if defined(__aarch64__)
-struct stat {
-  unsigned long st_dev;
-  unsigned long st_ino;
-  unsigned int st_mode;
-  unsigned int st_nlink;
-  unsigned int st_uid;
-  unsigned int st_gid;
-  unsigned long st_rdev;
-  unsigned long __pad1;
-  long st_size;
-  int st_blksize;
-  int __pad2;
-  long st_blocks;
-  long st_atime;
-  unsigned long st_atime_nsec;
-  long st_mtime;
-  unsigned long st_mtime_nsec;
-  long st_ctime;
-  unsigned long st_ctime_nsec;
-  unsigned int __unused4;
-  unsigned int __unused5;
-};
+#define __STAT64_BODY \
+  unsigned long st_dev; \
+  unsigned long st_ino; \
+  unsigned int st_mode; \
+  unsigned int st_nlink; \
+  uid_t st_uid; \
+  gid_t st_gid; \
+  unsigned long st_rdev; \
+  unsigned long __pad1; \
+  long st_size; \
+  int st_blksize; \
+  int __pad2; \
+  long st_blocks; \
+  long st_atime; \
+  unsigned long st_atime_nsec; \
+  long st_mtime; \
+  unsigned long st_mtime_nsec; \
+  long st_ctime; \
+  unsigned long st_ctime_nsec; \
+  unsigned int __unused4; \
+  unsigned int __unused5; \
+
 #elif defined(__mips__)
-struct stat {
-  unsigned long st_dev;
-  unsigned long __pad0[3];
-  unsigned long long st_ino;
-  unsigned int st_mode;
-  unsigned int st_nlink;
-  unsigned long st_uid;
-  unsigned long st_gid;
-  unsigned long st_rdev;
-  unsigned long __pad1[3];
-  long long st_size;
-  unsigned long st_atime;
-  unsigned long st_atime_nsec;
-  unsigned long st_mtime;
-  unsigned long st_mtime_nsec;
-  unsigned long st_ctime;
-  unsigned long st_ctime_nsec;
-  unsigned long st_blksize;
-  unsigned long __pad2;
-  unsigned long long st_blocks;
-};
+#define __STAT64_BODY \
+  unsigned int st_dev; \
+  unsigned int __pad0[3]; \
+  unsigned long long st_ino; \
+  unsigned int st_mode; \
+  unsigned int st_nlink; \
+  uid_t st_uid; \
+  gid_t st_gid; \
+  unsigned int st_rdev; \
+  unsigned int __pad1[3]; \
+  long long st_size; \
+  unsigned int st_atime; \
+  unsigned int st_atime_nsec; \
+  unsigned int st_mtime; \
+  unsigned int st_mtime_nsec; \
+  unsigned int st_ctime; \
+  unsigned int st_ctime_nsec; \
+  unsigned int st_blksize; \
+  unsigned int __pad2; \
+  unsigned long long st_blocks; \
+
 #elif defined(__x86_64__)
-struct stat {
-  unsigned long st_dev;
-  unsigned long st_ino;
-  unsigned long st_nlink;
-  unsigned int st_mode;
-  unsigned int st_uid;
-  unsigned int st_gid;
-  unsigned int __pad0;
-  unsigned long st_rdev;
-  long st_size;
-  long st_blksize;
-  long st_blocks;
-  unsigned long st_atime;
-  unsigned long st_atime_nsec;
-  unsigned long st_mtime;
-  unsigned long st_mtime_nsec;
-  unsigned long st_ctime;
-  unsigned long st_ctime_nsec;
-  long __pad3[3];
-};
+#define __STAT64_BODY \
+  unsigned long st_dev; \
+  unsigned long st_ino; \
+  unsigned long st_nlink; \
+  unsigned int st_mode; \
+  uid_t st_uid; \
+  gid_t st_gid; \
+  unsigned int __pad0; \
+  unsigned long st_rdev; \
+  long st_size; \
+  long st_blksize; \
+  long st_blocks; \
+  unsigned long st_atime; \
+  unsigned long st_atime_nsec; \
+  unsigned long st_mtime; \
+  unsigned long st_mtime_nsec; \
+  unsigned long st_ctime; \
+  unsigned long st_ctime_nsec; \
+  long __pad3[3]; \
+
 #else
-struct stat {
-  unsigned long long st_dev;
-  unsigned char __pad0[4];
-  unsigned long __st_ino;
-  unsigned int st_mode;
-  unsigned int st_nlink;
-  unsigned long st_uid;
-  unsigned long st_gid;
-  unsigned long long st_rdev;
-  unsigned char __pad3[4];
-  long long st_size;
-  unsigned long st_blksize;
-  unsigned long long st_blocks;
-  unsigned long st_atime;
-  unsigned long st_atime_nsec;
-  unsigned long st_mtime;
-  unsigned long st_mtime_nsec;
-  unsigned long st_ctime;
-  unsigned long st_ctime_nsec;
-  unsigned long long st_ino;
-};
+#define __STAT64_BODY \
+  unsigned long long st_dev; \
+  unsigned char __pad0[4]; \
+  unsigned long __st_ino; \
+  unsigned int st_mode; \
+  unsigned int st_nlink; \
+  uid_t st_uid; \
+  gid_t st_gid; \
+  unsigned long long st_rdev; \
+  unsigned char __pad3[4]; \
+  long long st_size; \
+  unsigned long st_blksize; \
+  unsigned long long st_blocks; \
+  unsigned long st_atime; \
+  unsigned long st_atime_nsec; \
+  unsigned long st_mtime; \
+  unsigned long st_mtime_nsec; \
+  unsigned long st_ctime; \
+  unsigned long st_ctime_nsec; \
+  unsigned long long st_ino; \
+
 #endif
 
-/* For compatibility with GLibc, we provide macro aliases
- * for the non-Posix nano-seconds accessors.
- */
-#define  st_atimensec  st_atime_nsec
-#define  st_mtimensec  st_mtime_nsec
-#define  st_ctimensec  st_ctime_nsec
+struct stat { __STAT64_BODY };
+struct stat64 { __STAT64_BODY };
+
+#undef __STAT64_BODY
+
+#define st_atimensec st_atime_nsec
+#define st_mtimensec st_mtime_nsec
+#define st_ctimensec st_ctime_nsec
 
 #ifdef __USE_BSD
 /* Permission macros provided by glibc for compatibility with BSDs. */
@@ -141,21 +143,26 @@
 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
 #endif
 
-extern int    chmod(const char *, mode_t);
-extern int    fchmod(int, mode_t);
-extern int    mkdir(const char *, mode_t);
+extern int chmod(const char*, mode_t);
+extern int fchmod(int, mode_t);
+extern int mkdir(const char*, mode_t);
 
-extern int    stat(const char *, struct stat *);
-extern int    fstat(int, struct stat *);
-extern int    lstat(const char *, struct stat *);
-extern int    mknod(const char *, mode_t, dev_t);
+extern int fstat(int, struct stat*);
+extern int fstat64(int, struct stat64*);
+extern int fstatat(int, const char*, struct stat*, int);
+extern int fstatat64(int, const char*, struct stat64*, int);
+extern int lstat(const char*, struct stat*);
+extern int lstat64(const char*, struct stat64*);
+extern int stat(const char*, struct stat*);
+extern int stat64(const char*, struct stat64*);
+
+extern int mknod(const char*, mode_t, dev_t);
 extern mode_t umask(mode_t);
 
 #if defined(__BIONIC_FORTIFY)
 
 extern mode_t __umask_chk(mode_t);
-extern mode_t __umask_real(mode_t)
-    __asm__(__USER_LABEL_PREFIX__ "umask");
+extern mode_t __umask_real(mode_t) __asm__(__USER_LABEL_PREFIX__ "umask");
 __errordecl(__umask_invalid_mode, "umask called with invalid mode");
 
 __BIONIC_FORTIFY_INLINE
@@ -172,20 +179,14 @@
 }
 #endif /* defined(__BIONIC_FORTIFY) */
 
-
-#define  stat64    stat
-#define  fstat64   fstat
-#define  lstat64   lstat
-
 extern int mkfifo(const char*, mode_t);
 
 extern int fchmodat(int, const char*, mode_t, int);
-extern int fstatat(int, const char*, struct stat*, int);
 extern int mkdirat(int, const char*, mode_t);
 extern int mknodat(int, const char*, mode_t, dev_t);
 
-# define UTIME_NOW      ((1l << 30) - 1l)
-# define UTIME_OMIT     ((1l << 30) - 2l)
+#define UTIME_NOW  ((1L << 30) - 1L)
+#define UTIME_OMIT ((1L << 30) - 2L)
 extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
 extern int futimens(int fd, const struct timespec times[2]);
 
diff --git a/libc/include/sys/statvfs.h b/libc/include/sys/statvfs.h
index e910c03..3495546 100644
--- a/libc/include/sys/statvfs.h
+++ b/libc/include/sys/statvfs.h
@@ -23,19 +23,31 @@
 
 __BEGIN_DECLS
 
-struct statvfs {
-  unsigned long f_bsize;
-  unsigned long f_frsize;
-  fsblkcnt_t    f_blocks;
-  fsblkcnt_t    f_bfree;
-  fsblkcnt_t    f_bavail;
-  fsfilcnt_t    f_files;
-  fsfilcnt_t    f_ffree;
-  fsfilcnt_t    f_favail;
-  unsigned long f_fsid;
-  unsigned long f_flag;
-  unsigned long f_namemax;
-};
+#ifdef __LP64__
+#define __STATVFS64_RESERVED uint32_t __f_reserved[6];
+#else
+#define __STATVFS64_RESERVED
+#endif
+
+#define __STATVFS64_BODY \
+  unsigned long f_bsize; \
+  unsigned long f_frsize; \
+  fsblkcnt_t    f_blocks; \
+  fsblkcnt_t    f_bfree; \
+  fsblkcnt_t    f_bavail; \
+  fsfilcnt_t    f_files; \
+  fsfilcnt_t    f_ffree; \
+  fsfilcnt_t    f_favail; \
+  unsigned long f_fsid; \
+  unsigned long f_flag; \
+  unsigned long f_namemax; \
+  __STATVFS64_RESERVED
+
+struct statvfs { __STATVFS64_BODY };
+struct statvfs64 { __STATVFS64_BODY };
+
+#undef __STATVFS64_BODY
+#undef __STATVFS64_RESERVED
 
 #define ST_RDONLY      0x0001
 #define ST_NOSUID      0x0002
@@ -48,7 +60,9 @@
 #define ST_RELATIME    0x1000
 
 extern int statvfs(const char* __restrict, struct statvfs* __restrict) __nonnull((1, 2));
+extern int statvfs64(const char* __restrict, struct statvfs64* __restrict) __nonnull((1, 2));
 extern int fstatvfs(int, struct statvfs*) __nonnull((2));
+extern int fstatvfs64(int, struct statvfs64*) __nonnull((2));
 
 __END_DECLS
 
diff --git a/libc/include/sys/syscall.h b/libc/include/sys/syscall.h
index a44b2e5..34a29df 100644
--- a/libc/include/sys/syscall.h
+++ b/libc/include/sys/syscall.h
@@ -37,7 +37,7 @@
 
 __BEGIN_DECLS
 
-int syscall(int number, ...);
+long syscall(long number, ...);
 
 __END_DECLS
 
diff --git a/libc/include/sys/timeb.h b/libc/include/sys/timeb.h
deleted file mode 100644
index cf6f255..0000000
--- a/libc/include/sys/timeb.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#ifndef _SYS_TIMEB_H
-#define _SYS_TIMEB_H
-
-#include <sys/cdefs.h>
-#include <sys/time.h>
-
-__BEGIN_DECLS
-
-struct timeb {
-    time_t          time;
-    unsigned short  millitm;
-    short           timezone;
-    short           dstflag;
-};
-
-extern int  ftime(struct timeb*  timebuf);
-
-__END_DECLS
-
-#endif /* _SYS_TIMEB_H */
diff --git a/libc/include/sys/times.h b/libc/include/sys/times.h
index 1b9b8b2..6ce5b55 100644
--- a/libc/include/sys/times.h
+++ b/libc/include/sys/times.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_TIMES_H_
 #define _SYS_TIMES_H_
 
@@ -34,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern clock_t times(struct tms *);
+extern clock_t times(struct tms*);
 
 __END_DECLS
 
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index f8ae813..a5fa692 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -35,28 +35,49 @@
 #include <linux/types.h>
 #include <linux/posix_types.h>
 
-/* __kernel_gid_t and __kernel_uid_t are 16 bit for legacy reasons.
- * Android uses __kernel_uid32_t and __kernel_gid32_t instead.
- */
-typedef __kernel_gid32_t gid_t;
-typedef __kernel_uid32_t uid_t;
+/* gids, uids, and pids are all 32-bit. */
+typedef __kernel_gid32_t __gid_t;
+typedef __gid_t gid_t;
+typedef __kernel_uid32_t __uid_t;
+typedef __uid_t uid_t;
+typedef __kernel_pid_t __pid_t;
+typedef __pid_t pid_t;
+typedef uint32_t __id_t;
+typedef __id_t id_t;
 
 typedef unsigned long blkcnt_t;
 typedef unsigned long blksize_t;
 typedef __kernel_caddr_t caddr_t;
 typedef __kernel_clock_t clock_t;
-typedef __kernel_clockid_t clockid_t;
+
+typedef __kernel_clockid_t __clockid_t;
+typedef __clockid_t clockid_t;
+
 typedef __kernel_daddr_t daddr_t;
 typedef unsigned long fsblkcnt_t;
 typedef unsigned long fsfilcnt_t;
-typedef __kernel_ino_t ino_t;
-typedef __kernel_key_t key_t;
-typedef __kernel_mode_t mode_t;
+
+typedef __kernel_mode_t __mode_t;
+typedef __mode_t mode_t;
+
+typedef __kernel_key_t __key_t;
+typedef __key_t key_t;
+
+typedef __kernel_ino_t __ino_t;
+typedef __ino_t ino_t;
+
+typedef uint32_t __nlink_t;
 typedef __nlink_t nlink_t;
-typedef __kernel_pid_t pid_t;
-typedef __kernel_suseconds_t suseconds_t;
-typedef __kernel_timer_t timer_t;
-typedef unsigned int useconds_t;
+
+typedef void* __timer_t;
+typedef __timer_t timer_t;
+
+typedef __kernel_suseconds_t __suseconds_t;
+typedef __suseconds_t suseconds_t;
+
+/* useconds_t is 32-bit on both LP32 and LP64. */
+typedef uint32_t __useconds_t;
+typedef __useconds_t useconds_t;
 
 #if !defined(__LP64__)
 /* This historical accident means that we had a 32-bit dev_t on 32-bit architectures. */
@@ -66,18 +87,21 @@
 #endif
 
 /* This historical accident means that we had a 32-bit time_t on 32-bit architectures. */
-typedef __kernel_time_t time_t;
+typedef __kernel_time_t __time_t;
+typedef __time_t time_t;
 
 /* This historical accident means that we had a 32-bit off_t on 32-bit architectures. */
-#ifndef _OFF_T_DEFINED_
-#define _OFF_T_DEFINED_
+#if !defined(__LP64__)
 typedef __kernel_off_t off_t;
-#endif
 typedef __kernel_loff_t loff_t;
 typedef loff_t off64_t;
-
-/* This one really is meant to be just 32 bits! */
-typedef uint32_t id_t;
+#else
+/* We could re-use the LP32 definitions, but that would mean that although off_t and loff_t/off64_t
+ * would be the same size, they wouldn't actually be the same type, which can lead to warnings. */
+typedef __kernel_off_t off_t;
+typedef off_t loff_t;
+typedef loff_t off64_t;
+#endif
 
 /* while POSIX wants these in <sys/types.h>, we
  * declare then in <pthread.h> instead */
@@ -93,6 +117,17 @@
 typedef  .... pthread_t;
 #endif
 
+#if !defined(__LP64__)
+/* This historical accident means that we had a signed socklen_t on 32-bit architectures. */
+typedef int32_t __socklen_t;
+#else
+/* LP64 still has a 32-bit socklen_t. */
+typedef uint32_t __socklen_t;
+#endif
+typedef __socklen_t socklen_t;
+
+typedef __builtin_va_list __va_list;
+
 #ifndef _SSIZE_T_DEFINED_
 #define _SSIZE_T_DEFINED_
 /* Traditionally, bionic's ssize_t was "long int". This caused GCC to emit warnings when you
diff --git a/libc/include/sys/ucontext.h b/libc/include/sys/ucontext.h
new file mode 100644
index 0000000..f62380d
--- /dev/null
+++ b/libc/include/sys/ucontext.h
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SYS_UCONTEXT_H_
+#define _SYS_UCONTEXT_H_
+
+#include <signal.h>
+#include <sys/user.h>
+
+__BEGIN_DECLS
+
+#if defined(__arm__)
+
+enum {
+  REG_R0 = 0,
+  REG_R1,
+  REG_R2,
+  REG_R3,
+  REG_R4,
+  REG_R5,
+  REG_R6,
+  REG_R7,
+  REG_R8,
+  REG_R9,
+  REG_R10,
+  REG_R11,
+  REG_R12,
+  REG_R13,
+  REG_R14,
+  REG_R15,
+};
+
+#define NGREG 18 /* Like glibc. */
+
+typedef int greg_t;
+typedef greg_t gregset_t[NGREG];
+
+#include <asm/sigcontext.h>
+typedef struct sigcontext mcontext_t;
+
+typedef struct ucontext {
+  unsigned long uc_flags;
+  struct ucontext* uc_link;
+  stack_t uc_stack;
+  mcontext_t uc_mcontext;
+  // Android has a wrong (smaller) sigset_t on ARM.
+  union {
+    sigset_t bionic;
+    uint32_t kernel[2];
+  } uc_sigmask;
+  // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM.
+  char __padding[120];
+  unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
+} ucontext_t;
+
+#elif defined(__aarch64__)
+
+#include <asm/sigcontext.h>
+typedef struct sigcontext mcontext_t;
+
+typedef struct ucontext {
+  unsigned long uc_flags;
+  struct ucontext *uc_link;
+  stack_t uc_stack;
+  sigset_t uc_sigmask;
+  // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64.
+  char __padding[128 - sizeof(sigset_t)];
+  mcontext_t uc_mcontext;
+} ucontext_t;
+
+#elif defined(__i386__)
+
+enum {
+  REG_GS = 0,
+  REG_FS,
+  REG_ES,
+  REG_DS,
+  REG_EDI,
+  REG_ESI,
+  REG_EBP,
+  REG_ESP,
+  REG_EBX,
+  REG_EDX,
+  REG_ECX,
+  REG_EAX,
+  REG_TRAPNO,
+  REG_ERR,
+  REG_EIP,
+  REG_CS,
+  REG_EFL,
+  REG_UESP,
+  REG_SS,
+  NGREG
+};
+
+typedef int greg_t;
+typedef greg_t gregset_t[NGREG];
+
+struct _libc_fpreg {
+  unsigned short significand[4];
+  unsigned short exponent;
+};
+
+struct _libc_fpstate {
+  unsigned long cw;
+  unsigned long sw;
+  unsigned long tag;
+  unsigned long ipoff;
+  unsigned long cssel;
+  unsigned long dataoff;
+  unsigned long datasel;
+  struct _libc_fpreg _st[8];
+  unsigned long status;
+};
+
+typedef struct _libc_fpstate* fpregset_t;
+
+typedef struct {
+  gregset_t gregs;
+  fpregset_t fpregs;
+  unsigned long oldmask;
+  unsigned long cr2;
+} mcontext_t;
+
+typedef struct ucontext {
+  unsigned long uc_flags;
+  struct ucontext* uc_link;
+  stack_t uc_stack;
+  mcontext_t uc_mcontext;
+  // Android has a wrong (smaller) sigset_t on x86.
+  union {
+    sigset_t bionic;
+    uint32_t kernel[2];
+  } uc_sigmask;
+  struct _libc_fpstate __fpregs_mem;
+} ucontext_t;
+
+#elif defined(__mips__)
+
+/* glibc doesn't have names for MIPS registers. */
+
+#define NGREG 32
+#define NFPREG 32
+
+typedef unsigned long long greg_t;
+typedef greg_t gregset_t[NGREG];
+
+typedef struct fpregset {
+  union {
+    double fp_dregs[NFPREG];
+    struct {
+      float _fp_fregs;
+      unsigned _fp_pad;
+    } fp_fregs[NFPREG];
+  } fp_r;
+} fpregset_t;
+
+typedef struct {
+  unsigned regmask;
+  unsigned status;
+  greg_t pc;
+  gregset_t gregs;
+  fpregset_t fpregs;
+  unsigned fp_owned;
+  unsigned fpc_csr;
+  unsigned fpc_eir;
+  unsigned used_math;
+  unsigned dsp;
+  greg_t mdhi;
+  greg_t mdlo;
+  unsigned long hi1;
+  unsigned long lo1;
+  unsigned long hi2;
+  unsigned long lo2;
+  unsigned long hi3;
+  unsigned long lo3;
+} mcontext_t;
+
+typedef struct ucontext {
+  unsigned long uc_flags;
+  struct ucontext* uc_link;
+  stack_t uc_stack;
+  mcontext_t uc_mcontext;
+  sigset_t uc_sigmask;
+} ucontext_t;
+
+#elif defined(__mips64__)
+
+#error TODO
+
+#elif defined(__x86_64__)
+
+enum {
+  REG_R8 = 0,
+  REG_R9,
+  REG_R10,
+  REG_R11,
+  REG_R12,
+  REG_R13,
+  REG_R14,
+  REG_R15,
+  REG_RDI,
+  REG_RSI,
+  REG_RBP,
+  REG_RBX,
+  REG_RDX,
+  REG_RAX,
+  REG_RCX,
+  REG_RSP,
+  REG_RIP,
+  REG_EFL,
+  REG_CSGSFS,
+  REG_ERR,
+  REG_TRAPNO,
+  REG_OLDMASK,
+  REG_CR2,
+  NGREG
+};
+
+typedef long greg_t;
+typedef greg_t gregset_t[NGREG];
+
+struct _libc_fpxreg {
+  unsigned short significand[4];
+  unsigned short exponent;
+  unsigned short padding[3];
+};
+
+struct _libc_xmmreg {
+  uint32_t element[4];
+};
+
+struct _libc_fpstate {
+  uint16_t cwd;
+  uint16_t swd;
+  uint16_t ftw;
+  uint16_t fop;
+  uint64_t rip;
+  uint64_t rdp;
+  uint32_t mxcsr;
+  uint32_t mxcr_mask;
+  struct _libc_fpxreg _st[8];
+  struct _libc_xmmreg _xmm[16];
+  uint32_t padding[24];
+};
+
+typedef struct _libc_fpstate* fpregset_t;
+
+typedef struct {
+  gregset_t gregs;
+  fpregset_t fpregs;
+  unsigned long __reserved1[8];
+} mcontext_t;
+
+typedef struct ucontext {
+  unsigned long uc_flags;
+  struct ucontext* uc_link;
+  stack_t uc_stack;
+  mcontext_t uc_mcontext;
+  sigset_t uc_sigmask;
+  struct _libc_fpstate __fpregs_mem;
+} ucontext_t;
+
+#endif
+
+__END_DECLS
+
+#endif /* _SYS_UCONTEXT_H_ */
diff --git a/libc/include/sys/un.h b/libc/include/sys/un.h
index f89ead3..65ffbdc 100644
--- a/libc/include/sys/un.h
+++ b/libc/include/sys/un.h
@@ -28,8 +28,7 @@
 #ifndef _SYS_UN_H_
 #define _SYS_UN_H_
 
-#include <sys/_types.h>
-typedef __sa_family_t sa_family_t;
+typedef unsigned short sa_family_t;
 
 #include <linux/un.h>
 
diff --git a/libc/include/sys/user.h b/libc/include/sys/user.h
index 9f11a83..18684f1 100644
--- a/libc/include/sys/user.h
+++ b/libc/include/sys/user.h
@@ -30,12 +30,13 @@
 #define _SYS_USER_H_
 
 #include <sys/cdefs.h>
+#include <limits.h> /* For PAGE_SIZE. */
 
 __BEGIN_DECLS
 
 #if __i386__
 
-struct user_i387_struct {
+struct user_fpregs_struct {
   long cwd;
   long swd;
   long twd;
@@ -82,7 +83,7 @@
 struct user {
   struct user_regs_struct regs;
   int u_fpvalid;
-  struct user_i387_struct i387;
+  struct user_fpregs_struct i387;
   unsigned long int u_tsize;
   unsigned long int u_dsize;
   unsigned long int u_ssize;
@@ -91,7 +92,7 @@
   long int signal;
   int reserved;
   unsigned long u_ar0;
-  struct user_i387_struct* u_fpstate;
+  struct user_fpregs_struct* u_fpstate;
   unsigned long magic;
   char u_comm[32];
   int u_debugreg[8];
@@ -99,10 +100,10 @@
 
 #elif defined(__x86_64__)
 
-struct user_i387_struct {
+struct user_fpregs_struct {
   unsigned short cwd;
   unsigned short swd;
-  unsigned short twd;
+  unsigned short ftw;
   unsigned short fop;
   __u64 rip;
   __u64 rdp;
@@ -145,7 +146,7 @@
   struct user_regs_struct regs;
   int u_fpvalid;
   int pad0;
-  struct user_i387_struct i387;
+  struct user_fpregs_struct i387;
   unsigned long int u_tsize;
   unsigned long int u_dsize;
   unsigned long int u_ssize;
@@ -155,7 +156,7 @@
   int reserved;
   int pad1;
   unsigned long u_ar0;
-  struct user_i387_struct* u_fpstate;
+  struct user_fpregs_struct* u_fpstate;
   unsigned long magic;
   char u_comm[32];
   unsigned long u_debugreg[8];
@@ -181,7 +182,7 @@
 
 #elif defined(__arm__)
 
-struct user_fp {
+struct user_fpregs {
   struct fp_reg {
     unsigned int sign1:1;
     unsigned int unused:15;
@@ -196,6 +197,9 @@
   unsigned char ftype[8];
   unsigned int init_flag;
 };
+struct user_regs {
+  unsigned long uregs[18];
+};
 struct user_vfp {
   unsigned long long fpregs[32];
   unsigned long fpscr;
@@ -206,7 +210,7 @@
   unsigned long fpinst2;
 };
 struct user {
-  struct pt_regs regs;
+  struct user_regs regs;
   int u_fpvalid;
   unsigned long int u_tsize;
   unsigned long int u_dsize;
@@ -215,12 +219,12 @@
   unsigned long start_stack;
   long int signal;
   int reserved;
-  unsigned long u_ar0;
+  struct user_regs* u_ar0;
   unsigned long magic;
   char u_comm[32];
   int u_debugreg[8];
-  struct user_fp u_fp;
-  struct user_fp_struct* u_fp0;
+  struct user_fpregs u_fp;
+  struct user_fpregs* u_fp0;
 };
 
 #elif defined(__aarch64__)
diff --git a/libc/include/sys/vfs.h b/libc/include/sys/vfs.h
index 10fe502..5358ffb 100644
--- a/libc/include/sys/vfs.h
+++ b/libc/include/sys/vfs.h
@@ -38,58 +38,76 @@
 typedef struct { int __val[2]; } __fsid_t;
 typedef __fsid_t fsid_t;
 
-#if defined(__LP64__)
-struct statfs {
-  uint64_t f_type;
-  uint64_t f_bsize;
-  uint64_t f_blocks;
-  uint64_t f_bfree;
-  uint64_t f_bavail;
-  uint64_t f_files;
-  uint64_t f_ffree;
-  fsid_t f_fsid;
-  uint64_t f_namelen;
-  uint64_t f_frsize;
-  uint64_t f_flags;
-  uint64_t f_spare[4];
-};
+#if defined(__aarch64__) || defined(__x86_64__)
+#define __STATFS64_BODY \
+  uint64_t f_type; \
+  uint64_t f_bsize; \
+  uint64_t f_blocks; \
+  uint64_t f_bfree; \
+  uint64_t f_bavail; \
+  uint64_t f_files; \
+  uint64_t f_ffree; \
+  fsid_t f_fsid; \
+  uint64_t f_namelen; \
+  uint64_t f_frsize; \
+  uint64_t f_flags; \
+  uint64_t f_spare[4]; \
+
+#elif defined(__mips__) && defined(__LP64__)
+/* 64-bit MIPS. */
+#define __STATFS64_BODY \
+  uint64_t f_type; \
+  uint64_t f_bsize; \
+  uint64_t f_frsize; /* Fragment size - unsupported. */ \
+  uint64_t f_blocks; \
+  uint64_t f_bfree; \
+  uint64_t f_files; \
+  uint64_t f_ffree; \
+  uint64_t f_bavail; \
+  fsid_t f_fsid; \
+  uint64_t f_namelen; \
+  uint64_t f_flags; \
+  uint64_t f_spare[5]; \
+
 #elif defined(__mips__)
 /* 32-bit MIPS (corresponds to the kernel's statfs64 type). */
-struct statfs {
-  uint32_t f_type;
-  uint32_t f_bsize;
-  uint32_t f_frsize;
-  uint32_t __pad;
-  uint64_t f_blocks;
-  uint64_t f_bfree;
-  uint64_t f_files;
-  uint64_t f_ffree;
-  uint64_t f_bavail;
-  fsid_t f_fsid;
-  uint32_t f_namelen;
-  uint32_t f_flags;
-  uint32_t f_spare[5];
-};
+#define __STATFS64_BODY \
+  uint32_t f_type; \
+  uint32_t f_bsize; \
+  uint32_t f_frsize; \
+  uint32_t __pad; \
+  uint64_t f_blocks; \
+  uint64_t f_bfree; \
+  uint64_t f_files; \
+  uint64_t f_ffree; \
+  uint64_t f_bavail; \
+  fsid_t f_fsid; \
+  uint32_t f_namelen; \
+  uint32_t f_flags; \
+  uint32_t f_spare[5]; \
+
 #else
 /* 32-bit ARM or x86 (corresponds to the kernel's statfs64 type). */
-struct statfs {
-  uint32_t f_type;
-  uint32_t f_bsize;
-  uint64_t f_blocks;
-  uint64_t f_bfree;
-  uint64_t f_bavail;
-  uint64_t f_files;
-  uint64_t f_ffree;
-  fsid_t f_fsid;
-  uint32_t f_namelen;
-  uint32_t f_frsize;
-  uint32_t f_flags;
-  uint32_t f_spare[4];
-};
+#define __STATFS64_BODY \
+  uint32_t f_type; \
+  uint32_t f_bsize; \
+  uint64_t f_blocks; \
+  uint64_t f_bfree; \
+  uint64_t f_bavail; \
+  uint64_t f_files; \
+  uint64_t f_ffree; \
+  fsid_t f_fsid; \
+  uint32_t f_namelen; \
+  uint32_t f_frsize; \
+  uint32_t f_flags; \
+  uint32_t f_spare[4]; \
+
 #endif
 
-/* Source compatibility with glibc. */
-#define statfs64 statfs
+struct statfs { __STATFS64_BODY };
+struct statfs64 { __STATFS64_BODY };
+
+#undef __STATFS64_BODY
 
 /* Declare that we have the f_namelen, f_frsize, and f_flags fields. */
 #define _STATFS_F_NAMELEN
@@ -142,7 +160,9 @@
 #define  _XIAFS_SUPER_MAGIC    0x012FD16D
 
 extern int statfs(const char*, struct statfs*) __nonnull((1, 2));
+extern int statfs64(const char*, struct statfs64*) __nonnull((1, 2));
 extern int fstatfs(int, struct statfs*) __nonnull((2));
+extern int fstatfs64(int, struct statfs64*) __nonnull((2));
 
 __END_DECLS
 
diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h
index b30b7ec..8d9a5f6 100644
--- a/libc/include/sys/wait.h
+++ b/libc/include/sys/wait.h
@@ -47,7 +47,6 @@
 
 extern pid_t  wait(int *);
 extern pid_t  waitpid(pid_t, int *, int);
-extern pid_t  wait3(int *, int, struct rusage *);
 extern pid_t  wait4(pid_t, int *, int, struct rusage *);
 
 /* Posix states that idtype_t should be an enumeration type, but
diff --git a/libc/include/syslog.h b/libc/include/syslog.h
index 4677c14..cbceab2 100644
--- a/libc/include/syslog.h
+++ b/libc/include/syslog.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYSLOG_H
 #define _SYSLOG_H
 
@@ -34,82 +35,60 @@
 
 __BEGIN_DECLS
 
-/* Alert levels */
-#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
+/* Priorities are translated to Android log priorities as shown. */
+#define LOG_EMERG   0 /* ERROR */
+#define LOG_ALERT   1 /* ERROR */
+#define LOG_CRIT    2 /* ERROR */
+#define LOG_ERR     3 /* ERROR */
+#define LOG_WARNING 4 /* WARN */
+#define LOG_NOTICE  5 /* INFO */
+#define LOG_INFO    6 /* INFO */
+#define LOG_DEBUG   7 /* DEBUG */
 
-#define LOG_PRIMASK	7
-#define LOG_PRI(x)	((x) & LOG_PRIMASK)
+#define LOG_PRIMASK 7
+#define LOG_PRI(x) ((x) & LOG_PRIMASK)
 
+/* Facilities are currently ignored on Android. */
+#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_LOCAL0   0200
+#define LOG_LOCAL1   0210
+#define LOG_LOCAL2   0220
+#define LOG_LOCAL3   0230
+#define LOG_LOCAL4   0240
+#define LOG_LOCAL5   0250
+#define LOG_LOCAL6   0260
+#define LOG_LOCAL7   0270
 
-/* Facilities; not actually used */
-#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_LOCAL0	0200
-#define LOG_LOCAL1	0210
-#define LOG_LOCAL2	0220
-#define LOG_LOCAL3	0230
-#define LOG_LOCAL4	0240
-#define LOG_LOCAL5	0250
-#define LOG_LOCAL6	0260
-#define LOG_LOCAL7	0270
+#define LOG_FACMASK 01770
+#define LOG_FAC(x) (((x) >> 3) & (LOG_FACMASK >> 3))
 
-#define LOG_FACMASK	01770
-#define LOG_FAC(x)	(((x) >> 3) & (LOG_FACMASK >> 3))
+#define LOG_MASK(pri) (1 << (pri))
+#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1)
 
-#define	LOG_MASK(pri)	(1 << (pri))		/* mask for one priority */
-#define	LOG_UPTO(pri)	((1 << ((pri)+1)) - 1)	/* all priorities through pri */
+/* openlog(3) flags are currently ignored on Android. */
+#define LOG_PID    0x01
+#define LOG_CONS   0x02
+#define LOG_ODELAY 0x04
+#define LOG_NDELAY 0x08
+#define LOG_NOWAIT 0x10
+#define LOG_PERROR 0x20
 
-/* openlog() flags; only LOG_PID and LOG_PERROR supported */
-#define        LOG_PID         0x01    /* include pid with message */
-#define        LOG_CONS        0x02    /* write to console on logger error */
-#define        LOG_ODELAY      0x04    /* delay connection until syslog() */
-#define        LOG_NDELAY      0x08    /* open connection immediately */
-#define        LOG_NOWAIT      0x10    /* wait for child processes (unused on linux) */
-#define        LOG_PERROR      0x20    /* additional logging to stderr */
-
-/* BIONIC: the following definitions are from OpenBSD's sys/syslog.h
- */
-struct syslog_data {
-	int	log_file;
-        int	connected;
-        int	opened;
-        int	log_stat;
-        const char 	*log_tag;
-        int 	log_fac;
-        int 	log_mask;
-};
-
-#define SYSLOG_DATA_INIT {-1, 0, 0, 0, (const char *)0, LOG_USER, 0xff}
-
-#define _PATH_LOG  "/dev/syslog"
-
-extern void	closelog(void);
-extern void	openlog(const char *, int, int);
-extern int	setlogmask(int);
-extern void	syslog(int, const char *, ...) __printflike(2, 3);
-extern void	vsyslog(int, const char *, va_list) __printflike(2, 0);
-extern void	closelog_r(struct syslog_data *);
-extern void	openlog_r(const char *, int, int, struct syslog_data *);
-extern int	setlogmask_r(int, struct syslog_data *);
-extern void	syslog_r(int, struct syslog_data *, const char *, ...) __printflike(3, 4);
-extern void	vsyslog_r(int, struct syslog_data *, const char *, va_list) __printflike(3, 0);
+void closelog(void);
+void openlog(const char*, int, int);
+int setlogmask(int);
+void syslog(int, const char*, ...) __printflike(2, 3);
+void vsyslog(int, const char*, va_list) __printflike(2, 0);
 
 __END_DECLS
 
diff --git a/libc/include/termios.h b/libc/include/termios.h
index 0d44355..b9685ca 100644
--- a/libc/include/termios.h
+++ b/libc/include/termios.h
@@ -31,87 +31,23 @@
 #include <sys/cdefs.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
-#include <stdint.h>
 #include <linux/termios.h>
 
 __BEGIN_DECLS
 
-/* Redefine these to match their ioctl number */
-#undef  TCSANOW
-#define TCSANOW    TCSETS
-
-#undef  TCSADRAIN
-#define TCSADRAIN  TCSETSW
-
-#undef  TCSAFLUSH
-#define TCSAFLUSH  TCSETSF
-
-static __inline__ int tcgetattr(int fd, struct termios *s)
-{
-    return ioctl(fd, TCGETS, s);
-}
-
-static __inline__ int tcsetattr(int fd, int __opt, const struct termios *s)
-{
-    return ioctl(fd, __opt, (void *)s);
-}
-
-static __inline__ int tcflow(int fd, int action)
-{
-    return ioctl(fd, TCXONC, (void *)(intptr_t)action);
-}
-
-static __inline__ int tcflush(int fd, int __queue)
-{
-    return ioctl(fd, TCFLSH, (void *)(intptr_t)__queue);
-}
-
-static __inline__ int tcdrain(int fd)
-{
-    return ioctl(fd, TCSBRK, (void *)(intptr_t)1);
-}
-
-static __inline__ pid_t tcgetsid(int fd)
-{
-    pid_t _pid;
-    return ioctl(fd, TIOCGSID, &_pid) ? (pid_t)-1 : _pid;
-}
-
-static __inline__ int tcsendbreak(int fd, int __duration)
-{
-    return ioctl(fd, TCSBRKP, (void *)(uintptr_t)__duration);
-}
-
-static __inline__ speed_t cfgetospeed(const struct termios *s)
-{
-    return (speed_t)(s->c_cflag & CBAUD);
-}
-
-static __inline__ int cfsetospeed(struct termios *s, speed_t  speed)
-{
-    s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
-    return 0;
-}
-
-static __inline__ speed_t cfgetispeed(const struct termios *s)
-{
-    return (speed_t)(s->c_cflag & CBAUD);
-}
-
-static __inline__ int cfsetispeed(struct termios *s, speed_t  speed)
-{
-    s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
-  return 0;
-}
-
-static __inline__ void cfmakeraw(struct termios *s)
-{
-    s->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
-    s->c_oflag &= ~OPOST;
-    s->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
-    s->c_cflag &= ~(CSIZE|PARENB);
-    s->c_cflag |= CS8;
-}
+speed_t cfgetispeed(const struct termios*);
+speed_t cfgetospeed(const struct termios*);
+void cfmakeraw(struct termios*);
+int cfsetispeed(struct termios*, speed_t);
+int cfsetospeed(struct termios*, speed_t);
+int cfsetspeed(struct termios*, speed_t);
+int tcdrain(int);
+int tcflow(int, int);
+int tcflush(int, int);
+int tcgetattr(int, struct termios*);
+pid_t tcgetsid(int);
+int tcsendbreak(int, int);
+int tcsetattr(int, int, const struct termios*);
 
 __END_DECLS
 
diff --git a/libc/include/time.h b/libc/include/time.h
index 3f2047c..34a53b2 100644
--- a/libc/include/time.h
+++ b/libc/include/time.h
@@ -31,14 +31,15 @@
 
 #include <sys/cdefs.h>
 #include <sys/time.h>
+#include <xlocale.h>
 
 __BEGIN_DECLS
 
 #define CLOCKS_PER_SEC 1000000
 
-extern char* tzname[];
-extern int daylight;
-extern long int timezone;
+extern char* tzname[] __LIBC_ABI_PUBLIC__;
+extern int daylight __LIBC_ABI_PUBLIC__;
+extern long int timezone __LIBC_ABI_PUBLIC__;
 
 struct sigevent;
 
@@ -58,46 +59,44 @@
 
 #define TM_ZONE tm_zone
 
-extern time_t time(time_t*);
-extern int nanosleep(const struct timespec*, struct timespec*);
+extern time_t time(time_t*) __LIBC_ABI_PUBLIC__;
+extern int nanosleep(const struct timespec*, struct timespec*) __LIBC_ABI_PUBLIC__;
 
-extern char* strtotimeval(const char*, struct timeval*);
+extern char* asctime(const struct tm*) __LIBC_ABI_PUBLIC__;
+extern char* asctime_r(const struct tm*, char*) __LIBC_ABI_PUBLIC__;
 
-extern char* asctime(const struct tm*);
-extern char* asctime_r(const struct tm*, char*);
+extern double difftime(time_t, time_t) __LIBC_ABI_PUBLIC__;
+extern time_t mktime(struct tm*) __LIBC_ABI_PUBLIC__;
 
-extern double difftime(time_t, time_t);
-extern time_t mktime(struct tm*);
+extern struct tm* localtime(const time_t*) __LIBC_ABI_PUBLIC__;
+extern struct tm* localtime_r(const time_t*, struct tm*) __LIBC_ABI_PUBLIC__;
 
-extern struct tm* localtime(const time_t*);
-extern struct tm* localtime_r(const time_t*, struct tm*);
+extern struct tm* gmtime(const time_t*) __LIBC_ABI_PUBLIC__;
+extern struct tm* gmtime_r(const time_t*, struct tm*) __LIBC_ABI_PUBLIC__;
 
-extern struct tm* gmtime(const time_t*);
-extern struct tm* gmtime_r(const time_t*, struct tm*);
+extern char* strptime(const char*, const char*, struct tm*) __LIBC_ABI_PUBLIC__;
+extern size_t strftime(char*, size_t, const char*, const struct tm*) __LIBC_ABI_PUBLIC__;
+extern size_t strftime_l(char *, size_t, const char *, const struct tm *, locale_t) __LIBC_ABI_PUBLIC__;
 
-extern char* strptime(const char*, const char*, struct tm*);
-extern size_t strftime(char*, size_t, const char*, const struct tm*);
+extern char* ctime(const time_t*) __LIBC_ABI_PUBLIC__;
+extern char* ctime_r(const time_t*, char*) __LIBC_ABI_PUBLIC__;
 
-extern char* ctime(const time_t*);
-extern char* ctime_r(const time_t*, char*);
+extern void tzset(void) __LIBC_ABI_PUBLIC__;
 
-extern void tzset(void);
+extern clock_t clock(void) __LIBC_ABI_PUBLIC__;
 
-extern clock_t clock(void);
+extern int clock_getres(int, struct timespec*) __LIBC_ABI_PUBLIC__;
+extern int clock_gettime(int, struct timespec*) __LIBC_ABI_PUBLIC__;
 
-extern int clock_getres(int, struct timespec*);
-extern int clock_gettime(int, struct timespec*);
+extern int timer_create(int, struct sigevent*, timer_t*) __LIBC_ABI_PUBLIC__;
+extern int timer_delete(timer_t) __LIBC_ABI_PUBLIC__;
+extern int timer_settime(timer_t, int, const struct itimerspec*, struct itimerspec*) __LIBC_ABI_PUBLIC__;
+extern int timer_gettime(timer_t, struct itimerspec*) __LIBC_ABI_PUBLIC__;
+extern int timer_getoverrun(timer_t) __LIBC_ABI_PUBLIC__;
 
-extern int timer_create(int, struct sigevent*, timer_t*);
-extern int timer_delete(timer_t);
-extern int timer_settime(timer_t, int, const struct itimerspec*, struct itimerspec*);
-extern int timer_gettime(timer_t, struct itimerspec*);
-extern int timer_getoverrun(timer_t);
-
-extern time_t timelocal(struct tm*);
-extern time_t timegm(struct tm*);
-extern time_t time2posix(time_t);
-extern time_t posix2time(time_t);
+/* Non-standard extensions that are in the BSDs and glibc. */
+extern time_t timelocal(struct tm*) __LIBC_ABI_PUBLIC__;
+extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;
 
 __END_DECLS
 
diff --git a/libc/include/time64.h b/libc/include/time64.h
index 7ec05af..905669d 100644
--- a/libc/include/time64.h
+++ b/libc/include/time64.h
@@ -31,29 +31,36 @@
 #ifndef TIME64_H
 #define TIME64_H
 
+#if defined(__LP64__)
+
+#error Your time_t is already 64-bit.
+
+#else
+
+/* Legacy cruft for LP32 where time_t was 32-bit. */
+
 #include <sys/cdefs.h>
 #include <time.h>
 #include <stdint.h>
 
 __BEGIN_DECLS
 
-typedef int64_t  time64_t;
+typedef int64_t time64_t;
 
-struct tm *gmtime64_r (const time64_t *, struct tm *);
-struct tm *localtime64_r (const time64_t *, struct tm *);
-struct tm *gmtime64 (const time64_t *);
-struct tm *localtime64 (const time64_t *);
-
-char *asctime64 (const struct tm *);
-char *asctime64_r (const struct tm *, char *);
-
-char *ctime64 (const time64_t*);
-char *ctime64_r (const time64_t*, char*);
-
-time64_t timegm64 (const struct tm *);
-time64_t mktime64 (const struct tm *);
-time64_t timelocal64 (const struct tm *);
+char* asctime64(const struct tm*);
+char* asctime64_r(const struct tm*, char*);
+char* ctime64(const time64_t*);
+char* ctime64_r(const time64_t*, char*);
+struct tm* gmtime64(const time64_t*);
+struct tm* gmtime64_r(const time64_t*, struct tm*);
+struct tm* localtime64(const time64_t*);
+struct tm* localtime64_r(const time64_t*, struct tm*);
+time64_t mktime64(const struct tm*);
+time64_t timegm64(const struct tm*);
+time64_t timelocal64(const struct tm*);
 
 __END_DECLS
 
+#endif
+
 #endif /* TIME64_H */
diff --git a/libc/include/uchar.h b/libc/include/uchar.h
new file mode 100644
index 0000000..e1fcb5c
--- /dev/null
+++ b/libc/include/uchar.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _UCHAR_H_
+#define _UCHAR_H_
+
+#include <sys/cdefs.h>
+#include <wchar.h>
+
+__BEGIN_DECLS
+
+#define __STD_UTF_16__ 1
+#define __STD_UTF_32__ 1
+
+size_t c16rtomb(char* __restrict, char16_t, mbstate_t* __restrict);
+size_t c32rtomb(char* __restrict, char32_t, mbstate_t* __restrict);
+size_t mbrtoc16(char16_t* __restrict,
+                const char* __restrict,
+                size_t,
+                mbstate_t* __restrict);
+size_t mbrtoc32(char32_t* __restrict,
+                const char* __restrict,
+                size_t,
+                mbstate_t* __restrict);
+
+__END_DECLS
+
+#endif /* _UCHAR_H_ */
diff --git a/libc/include/ucontext.h b/libc/include/ucontext.h
new file mode 100644
index 0000000..5ea2982
--- /dev/null
+++ b/libc/include/ucontext.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _UCONTEXT_H_
+#define _UCONTEXT_H_
+
+#include <sys/ucontext.h>
+
+#endif /* _UCONTEXT_H_ */
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 29758f5..7fbafdf 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -47,13 +47,14 @@
 #define SEEK_CUR 1
 #define SEEK_END 2
 
-extern char **environ;
+extern char** environ;
+
 extern __noreturn void _exit(int);
 
 extern pid_t  fork(void);
 extern pid_t  vfork(void);
 extern pid_t  getpid(void);
-extern pid_t  gettid(void);
+extern pid_t  gettid(void) __pure2;
 extern pid_t  getpgid(pid_t);
 extern int    setpgid(pid_t, pid_t);
 extern pid_t  getppid(void);
@@ -64,14 +65,12 @@
 
 extern int execv(const char *, char * const *);
 extern int execvp(const char *, char * const *);
+extern int execvpe(const char *, char * const *, char * const *);
 extern int execve(const char *, char * const *, char * const *);
 extern int execl(const char *, const char *, ...);
 extern int execlp(const char *, const char *, ...);
 extern int execle(const char *, const char *, ...);
 
-/* IMPORTANT: See comment under <sys/prctl.h> about this declaration */
-extern int prctl(int  option, ...);
-
 extern int nice(int);
 
 extern int setuid(uid_t);
@@ -90,7 +89,6 @@
 extern int setresgid(gid_t, gid_t, gid_t);
 extern int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
 extern int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);
-extern int issetugid(void);
 extern char* getlogin(void);
 extern char* getusershell(void);
 extern void setusershell(void);
@@ -163,8 +161,6 @@
 
 extern int gethostname(char *, size_t);
 
-extern int getdtablesize(void);
-
 extern void *__brk(void *);
 extern int brk(void *);
 extern void *sbrk(ptrdiff_t);
@@ -174,7 +170,7 @@
 extern int optind, opterr, optopt;
 
 extern int isatty(int);
-extern char* ttyname(int);
+extern char* ttyname(int) __warnattr("ttyname is not thread-safe; use ttyname_r instead");
 extern int ttyname_r(int, char*, size_t);
 
 extern int  acct(const char*  filepath);
@@ -185,26 +181,17 @@
 
 extern int daemon(int, int);
 
-/* A special syscall that is only available on the ARM, not x86 function. */
-extern int cacheflush(long start, long end, long flags);
+#if defined(__arm__) || (defined(__mips__) && !defined(__LP64__))
+extern int cacheflush(long, long, long);
+    /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */
+#endif
 
 extern pid_t tcgetpgrp(int fd);
 extern int   tcsetpgrp(int fd, pid_t _pid);
 
-#if 0 /* MISSING FROM BIONIC */
-extern int execvpe(const char *, char * const *, char * const *);
-extern int execlpe(const char *, const char *, ...);
-extern int getfsuid(uid_t);
-extern int setfsuid(uid_t);
-extern int getlogin_r(char* name, size_t namesize);
-extern int sethostname(const char *, size_t);
-extern int getdomainname(char *, size_t);
-extern int setdomainname(const char *, size_t);
-#endif /* MISSING */
-
 /* Used to retry syscalls that can return EINTR. */
 #define TEMP_FAILURE_RETRY(exp) ({         \
-    typeof (exp) _rc;                      \
+    __typeof__(exp) _rc;                   \
     do {                                   \
         _rc = (exp);                       \
     } while (_rc == -1 && errno == EINTR); \
diff --git a/libc/include/utmp.h b/libc/include/utmp.h
index ffd3c92..d764227 100644
--- a/libc/include/utmp.h
+++ b/libc/include/utmp.h
@@ -36,9 +36,15 @@
 #define _PATH_WTMP      "/var/log/wtmp"
 #define _PATH_LASTLOG   "/var/log/lastlog"
 
-#define	UT_NAMESIZE	8
-#define	UT_LINESIZE	8
-#define	UT_HOSTSIZE	16
+#ifdef __LP64__
+#define UT_NAMESIZE 32
+#define UT_LINESIZE 32
+#define UT_HOSTSIZE 256
+#else
+#define UT_NAMESIZE 8
+#define UT_LINESIZE 8
+#define UT_HOSTSIZE 16
+#endif
 
 #define USER_PROCESS 7
 
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 76ac02c..e0e5c82 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -34,21 +34,20 @@
 #include <stdarg.h>
 #include <stddef.h>
 #include <time.h>
-#include <malloc.h>
 
-/* IMPORTANT: Any code that relies on wide character support is essentially
- *            non-portable and/or broken. the only reason this header exist
- *            is because I'm really a nice guy. However, I'm not nice enough
- *            to provide you with a real implementation. instead wchar_t == char
- *            and all wc functions are stubs to their "normal" equivalent...
- */
+#include <machine/wchar_limits.h>
 
 __BEGIN_DECLS
 
-typedef __WINT_TYPE__           wint_t;
-typedef struct { int  dummy; }  mbstate_t;
+typedef __WINT_TYPE__  wint_t;
+typedef struct {
+  uint8_t __seq[4];
+#ifdef __LP64__
+  char __reserved[4];
+#endif
+} mbstate_t;
 
-typedef enum {
+enum {
     WC_TYPE_INVALID = 0,
     WC_TYPE_ALNUM,
     WC_TYPE_ALPHA,
@@ -63,12 +62,9 @@
     WC_TYPE_UPPER,
     WC_TYPE_XDIGIT,
     WC_TYPE_MAX
-} wctype_t;
+};
 
-#ifndef WCHAR_MAX
-#define  WCHAR_MAX   INT_MAX
-#define  WCHAR_MIN   INT_MIN
-#endif
+typedef long wctype_t;
 
 #define  WEOF        ((wint_t)(-1))
 
@@ -77,6 +73,7 @@
 extern int               fwscanf(FILE *, const wchar_t *, ...);
 extern int               iswalnum(wint_t);
 extern int               iswalpha(wint_t);
+extern int               iswblank(wint_t);
 extern int               iswcntrl(wint_t);
 extern int               iswdigit(wint_t);
 extern int               iswgraph(wint_t);
@@ -97,7 +94,8 @@
 extern int               mbsinit(const mbstate_t *);
 extern size_t            mbrlen(const char *, size_t, mbstate_t *);
 extern size_t            mbrtowc(wchar_t *, const char *, size_t, mbstate_t *);
-extern size_t            mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *);
+extern size_t mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*);
+extern size_t mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*);
 extern size_t            mbstowcs(wchar_t *, const char *, size_t);
 extern wint_t            putwc(wchar_t, FILE *);
 extern wint_t            putwchar(wchar_t);
@@ -106,9 +104,12 @@
 extern wint_t            towlower(wint_t);
 extern wint_t            towupper(wint_t);
 extern wint_t            ungetwc(wint_t, FILE *);
-extern int               vfwprintf(FILE *, const wchar_t *, va_list);
-extern int               vwprintf(const wchar_t *, va_list);
-extern int               vswprintf(wchar_t *, size_t, const wchar_t *, va_list);
+extern int vfwprintf(FILE*, const wchar_t*, va_list);
+extern int vfwscanf(FILE*, const wchar_t*, va_list);
+extern int vswprintf(wchar_t*, size_t, const wchar_t*, va_list);
+extern int vswscanf(const wchar_t*, const wchar_t*, va_list);
+extern int vwprintf(const wchar_t*, va_list);
+extern int vwscanf(const wchar_t*, va_list);
 extern size_t            wcrtomb(char *, wchar_t, mbstate_t *);
 extern int               wcscasecmp(const wchar_t *, const wchar_t *);
 extern wchar_t          *wcscat(wchar_t *, const wchar_t *);
@@ -117,23 +118,26 @@
 extern int               wcscoll(const wchar_t *, const wchar_t *);
 extern wchar_t          *wcscpy(wchar_t *, const wchar_t *);
 extern size_t            wcscspn(const wchar_t *, const wchar_t *);
-extern size_t            wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *);
+extern size_t            wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *) __LIBC_ABI_PUBLIC__;
 extern size_t            wcslen(const wchar_t *);
 extern int               wcsncasecmp(const wchar_t *, const wchar_t *, size_t);
 extern wchar_t          *wcsncat(wchar_t *, const wchar_t *, size_t);
 extern int               wcsncmp(const wchar_t *, const wchar_t *, size_t);
 extern wchar_t          *wcsncpy(wchar_t *, const wchar_t *, size_t);
+extern size_t wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*);
 extern wchar_t          *wcspbrk(const wchar_t *, const wchar_t *);
 extern wchar_t          *wcsrchr(const wchar_t *, wchar_t);
-extern size_t            wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *);
+extern size_t wcsrtombs(char*, const wchar_t**, size_t, mbstate_t*);
 extern size_t            wcsspn(const wchar_t *, const wchar_t *);
 extern wchar_t          *wcsstr(const wchar_t *, const wchar_t *);
-extern double            wcstod(const wchar_t *, wchar_t **);
-extern wchar_t          *wcstok(wchar_t *, const wchar_t *, wchar_t **);
-extern long int          wcstol(const wchar_t *, wchar_t **, int);
-extern size_t            wcstombs(char *, const wchar_t *, size_t);
-extern unsigned long int wcstoul(const wchar_t *, wchar_t **, int);
-extern wchar_t          *wcswcs(const wchar_t *, const wchar_t *);
+extern double wcstod(const wchar_t*, wchar_t**);
+extern float wcstof(const wchar_t*, wchar_t**);
+extern wchar_t* wcstok(wchar_t*, const wchar_t*, wchar_t**);
+extern long wcstol(const wchar_t*, wchar_t**, int);
+extern long long wcstoll(const wchar_t*, wchar_t**, int);
+extern long double wcstold(const wchar_t*, wchar_t**);
+extern unsigned long wcstoul(const wchar_t*, wchar_t**, int);
+extern unsigned long long wcstoull(const wchar_t*, wchar_t**, int);
 extern int               wcswidth(const wchar_t *, size_t);
 extern size_t            wcsxfrm(wchar_t *, const wchar_t *, size_t);
 extern int               wctob(wint_t);
@@ -147,12 +151,21 @@
 extern int               wprintf(const wchar_t *, ...);
 extern int               wscanf(const wchar_t *, ...);
 
-/* No really supported.  These are just for making libstdc++-v3 happy.  */
-typedef void *wctrans_t;
-extern wint_t		 towctrans(wint_t, wctrans_t);
-extern wctrans_t	 wctrans (const char *);
+extern long long          wcstoll_l(const wchar_t *, wchar_t **, int, locale_t);
+extern unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t);
+extern long double        wcstold_l(const wchar_t *, wchar_t **, locale_t );
 
-#if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
+extern int    wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
+extern size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t);
+
+extern size_t wcslcat(wchar_t*, const wchar_t*, size_t);
+extern size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
+
+typedef void *wctrans_t;
+extern wint_t towctrans(wint_t, wctrans_t);
+extern wctrans_t wctrans(const char*);
+
+#if __POSIX_VISIBLE >= 200809
 wchar_t* wcsdup(const wchar_t*);
 size_t wcsnlen(const wchar_t*, size_t);
 #endif
diff --git a/libc/include/wctype.h b/libc/include/wctype.h
index b5f18a0..1a4a05e 100644
--- a/libc/include/wctype.h
+++ b/libc/include/wctype.h
@@ -1 +1,56 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _WCTYPE_H_
+#define _WCTYPE_H_
+
 #include <wchar.h>
+
+__BEGIN_DECLS
+
+extern int iswalnum_l(wint_t, locale_t);
+extern int iswalpha_l(wint_t, locale_t);
+extern int iswblank_l(wint_t, locale_t);
+extern int iswcntrl_l(wint_t, locale_t);
+extern int iswdigit_l(wint_t, locale_t);
+extern int iswgraph_l(wint_t, locale_t);
+extern int iswlower_l(wint_t, locale_t);
+extern int iswprint_l(wint_t, locale_t);
+extern int iswpunct_l(wint_t, locale_t);
+extern int iswspace_l(wint_t, locale_t);
+extern int iswupper_l(wint_t, locale_t);
+extern int iswxdigit_l(wint_t, locale_t);
+extern int towlower_l(int, locale_t);
+extern int towupper_l(int, locale_t);
+
+extern int iswctype_l(wint_t, wctype_t, locale_t);
+extern wctype_t wctype_l(const char*, locale_t);
+
+__END_DECLS
+
+#endif /* _WCTYPE_H_ */
diff --git a/libc/include/xlocale.h b/libc/include/xlocale.h
new file mode 100644
index 0000000..f7eb8f4
--- /dev/null
+++ b/libc/include/xlocale.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _XLOCALE_H_
+#define _XLOCALE_H_
+
+/* If we just use void* here, GCC exposes that in error messages. */
+struct __locale_t;
+typedef struct __locale_t* locale_t;
+
+#endif /* _XLOCALE_H_ */
diff --git a/libc/kernel/README.TXT b/libc/kernel/README.TXT
index e4c11a1..e7312ef 100644
--- a/libc/kernel/README.TXT
+++ b/libc/kernel/README.TXT
@@ -1,93 +1,47 @@
-Bionic comes with a set of 'clean' Linux kernel headers that can safely be
-included by userland applications and libraries without fear of hideous
-conflicts. for more information why this is needed, see the "RATIONALE"
-section at the end of this document.
+Bionic comes with a processed set of all of the uapi Linux kernel headers that
+can safely be included by userland applications and libraries.
 
-these clean headers are automatically generated by several scripts located
-in the 'bionic/kernel/tools' directory, which process a set of original
-and unmodified kernel headers in order to get rid of many annoying
+These clean headers are automatically generated by several scripts located
+in the 'bionic/kernel/tools' directory. The tools process the original
+unmodified kernel headers in order to get rid of many annoying
 declarations and constructs that usually result in compilation failure.
 
-the 'clean headers' only contain type and macro definitions, with the
+The 'clean headers' only contain type and macro definitions, with the
 exception of a couple static inline functions used for performance
-reason (e.g. optimized CPU-specific byte-swapping routines)
+reason (e.g. optimized CPU-specific byte-swapping routines).
 
-they can be included from C++, or when compiling code in strict ANSI mode.
-they can be also included before or after any Bionic C library header.
+They can be included from C++, or when compiling code in strict ANSI mode.
+They can be also included before or after any Bionic C library header.
 
-the generation process works as follows:
+Description of the directories involved in generating the parsed kernel headers:
 
   * 'external/kernel-headers/original/'
-    contains a set of kernel headers as normally found in the 'include'
-    directory of a normal Linux kernel source tree. note that this should
-    only contain the files that are really needed by Android (use
-    'find_headers.py' to find these automatically).
+    Contains the uapi kernel headers found in the android kernel. Note this
+    also includes the header files that are generated by building the kernel
+    sources.
 
-  * 'bionic/libc/kernel/common'
-    contains the non-arch-specific clean headers and directories
-    (e.g. linux, asm-generic and mtd)
+  * 'bionic/libc/kernel/uapi'
+    Contains the cleaned kernel headers and mirrors the directory structure
+    in 'external/kernel-headers/original/uapi/'.
 
-  * 'bionic/libc/kernel/arch-arm/'
-    contains the ARM-specific directory tree of clean headers.
+  * 'bionic/libc/kernel/tools'
+    Contains various Python and shell scripts used to get and re-generate
+    the headers.
 
-  * 'bionic/libc/kernel/arch-arm/asm'
-    contains the real ARM-specific headers
+The tools to get/parse the headers:
 
-  * 'bionic/libc/kernel/arch-x86'
-    'bionic/libc/kernel/arch-x86/asm'
-    similarly contains all headers and symlinks to be used on x86
-
-  * 'bionic/libc/kernel/tools' contains various Python and shell scripts used
-    to manage and re-generate the headers
-
-the tools you can use are:
-
-  * tools/find_users.py
-    scans a list of source files or directories and prints which ones do
-    include Linux headers.
-
-  * tools/find_headers.py
-    scans a list of source files or directories and recursively finds all
-    the original kernel headers they need.
+  * tools/generate_uapi_headers.sh
+    Checks out the android kernel and generates all uapi header files.
+    copies all the changed files into external/kernel-headers.
 
   * tools/clean_header.py
-    prints the clean version of a given kernel header. with the -u option,
+    Prints the clean version of a given kernel header. With the -u option,
     this will also update the corresponding clean header file if its
-    content has changed. you can also process more than one file with -u
+    content has changed. You can also process more than one file with -u.
 
   * tools/update_all.py
-    automatically update all clean headers from the content of 
-    'external/kernel-headers/original'. this is the script you're likely going to
-    run whenever you update the original headers.
-
-
-HOW TO BUILD BIONIC AND OTHER PROGRAMS WITH THE CLEAN HEADERS:
-==============================================================
-
-add bionic/kernel/common and bionic/kernel/arch-<yourarch> to your C
-include path. that should be enough. Note that Bionic will not compile properly 
-if you don't.
-
-
-HOW TO SUPPORT ANOTHER ARCHITECTURE:
-====================================
-
-see the content of tools/defaults.py, you will need to make a few updates
-here:
-
-  - add a new item to the 'kernel_archs' list of supported architectures
-
-  - add a proper definition for 'kernel_known_<arch>_statics' with
-    relevant definitions.
-
-  - update 'kernel_known_statics' to map "<arch>" to
-    'kernel_known_<arch>_statics'
-
-then, add the new architecture-specific headers to original/asm-<arch>.
-(please ensure that these are really needed, e.g. with tools/find_headers.py)
-
-finally, run tools/update_all.py
-
+    Automatically update all clean headers from the content of
+    'external/kernel-headers/original'.
 
 
 HOW TO UPDATE THE HEADERS WHEN NEEDED:
@@ -99,81 +53,17 @@
   NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE
   OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT
 
-copy any updated kernel header into the corresponding location under
-'bionic/kernel/original'.
+Grab the latest headers from the android kernel by running this command:
 
-for any new kernel header you want to add, first run tools/find_headers.py to be
-sure that it is really needed by the Android sources. then add it to
-'bionic/kernel/original'
+  bionic/libc/kernel/tools/generate_uapi_headers.sh --download-kernel
 
-then, run tools/update_all.py to re-run the auto-cleaning
+Next, run this command to copy the parsed files to bionic/libc/kernel/uapi:
 
+  bionic/libc/kernel/tools/update_all.py
 
+Finally, run this command to regenerate the syscalls list:
 
-HOW THE CLEANUP PROCESS WORKS:
-==============================
+  bionic/libc/tools/gensyscalls.py
 
-this section describes the action performed by the cleanup program(s) when they
-process the original kernel headers into clean ones:
-
-1. Optimize well-known macros (e.g. __KERNEL__, __KERNEL_STRICT_NAMES)
-
-    this pass gets rid of everything that is guarded by a well-known macro
-    definition. this means that a block like
-
-       #ifdef __KERNEL__
-       ....
-       #endif
-
-    will be totally omitted from the output. the optimizer is smart enough to
-    handle all complex C-preprocessor conditional expression appropriately.
-    this means that, for example:
-
-       #if defined(__KERNEL__) || defined(FOO)
-       ...
-       #endif
-
-    will be transformed into:
-
-       #ifdef FOO
-       ...
-       #endif
-
-    see tools/defaults.py for the list of well-known macros used in this pass,
-    in case you need to update it in the future.
-
-    note that this also remove any reference to a kernel-specific configuration
-    macro like CONFIG_FOO from the clean headers.
-
-
-2. remove variable and function declarations:
-
-  this pass scans non-directive text and only keeps things that look like a
-  typedef/struct/union/enum declaration. this allows to get rid of any variable
-  or function declaration that should only be used within the kernel anyway
-  (and which normally *should* be guarded in a #ifdef __KERNEL__ ... #endif
-  block, if the kernel writers were not so messy)
-
-  there are however a few exceptions: it is seldom useful to keep the definition
-  of some static inline functions performing very simple operations. a good
-  example is the optimized 32-bit byte-swap function found in
-  arch-arm/asm/byteorder.h
-
-  the list of exceptions is in tools/defaults.py in case you need to update it
-  in the future.
-
-  note that we do *not* remove macro definitions, including these macro that
-  perform a call to one of these kernel-header functions, or even define other
-  functions. we consider it safe since userland applications have no business
-  using them anyway.
-
-
-3. whitespace cleanup:
-
-  the final pass remove any comments and empty lines from the final headers.
-
-
-4. add a standard disclaimer:
-
-  prepended to each generated header, contains a message like
-  "do not edit directly - file was auto-generated by ...."
+After this, you will need to build/test the tree to make sure that these
+changes do not introduce any errors.
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index e825ae0..6601817 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -1,5 +1,78 @@
 #!/usr/bin/env python
+
+#------------------------------------------------------------------------------
+# Description of the header clean process
+#------------------------------------------------------------------------------
+# Here is the list of actions performed by this script to clean the original
+# kernel headers.
 #
+# 1. Optimize well-known macros (e.g. __KERNEL__, __KERNEL_STRICT_NAMES)
+#
+#     This pass gets rid of everything that is guarded by a well-known macro
+#     definition. This means that a block like:
+#
+#        #ifdef __KERNEL__
+#        ....
+#        #endif
+#
+#     Will be totally omitted from the output. The optimizer is smart enough to
+#     handle all complex C-preprocessor conditional expression appropriately.
+#     This means that, for example:
+#
+#        #if defined(__KERNEL__) || defined(FOO)
+#        ...
+#        #endif
+#
+#     Will be transformed into:
+#
+#        #ifdef FOO
+#        ...
+#        #endif
+#
+#     See tools/defaults.py for the list of well-known macros used in this pass,
+#     in case you need to update it in the future.
+#
+#     Note that this also removes any reference to a kernel-specific
+#     configuration macro like CONFIG_FOO from the clean headers.
+#
+#
+# 2. Remove variable and function declarations:
+#
+#   This pass scans non-directive text and only keeps things that look like a
+#   typedef/struct/union/enum declaration. This allows us to get rid of any
+#   variables or function declarations that should only be used within the
+#   kernel anyway (and which normally *should* be guarded by an #ifdef
+#   __KERNEL__ ...  #endif block, if the kernel writers were not so messy).
+#
+#   There are, however, a few exceptions: it is seldom useful to keep the
+#   definition of some static inline functions performing very simple
+#   operations. A good example is the optimized 32-bit byte-swap function
+#   found in:
+#
+#     arch-arm/asm/byteorder.h
+#
+#   The list of exceptions is in tools/defaults.py in case you need to update
+#   it in the future.
+#
+#   Note that we do *not* remove macro definitions, including these macro that
+#   perform a call to one of these kernel-header functions, or even define other
+#   functions. We consider it safe since userland applications have no business
+#   using them anyway.
+#
+#
+# 3. Whitespace cleanup:
+#
+#   The final pass removes any comments and empty lines from the final headers.
+#
+#
+# 4. Add a standard disclaimer:
+#
+#   The message:
+#
+#   /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#
+#   Is prepended to each generated header.
+#------------------------------------------------------------------------------
 
 import sys, cpp, kernel, glob, os, re, getopt
 from defaults import *
@@ -7,7 +80,7 @@
 
 noUpdate = 1
 
-def  cleanupFile( path, original_path):
+def cleanupFile(path, original_path):
     """reads an original header and perform the cleanup operation on it
        this functions returns the destination path and the clean header
        as a single string"""
diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py
index 04e4256..2be9532 100644
--- a/libc/kernel/tools/cpp.py
+++ b/libc/kernel/tools/cpp.py
@@ -685,9 +685,9 @@
         # we have the defined keyword, check the rest
         self.i += 1
         self.skip_spaces()
-        use_parens = 0
+        used_parens = 0
         if self.i < self.n and self.tok[self.i].id == tokLPAREN:
-            use_parens = 1
+            used_parens = 1
             self.i += 1
             self.skip_spaces()
 
@@ -699,7 +699,7 @@
             self.throw(CppConstantExpected,i,"### 'defined' must be followed by macro name")
 
         self.i += 1
-        if use_parens:
+        if used_parens:
             self.expectId(tokRPAREN)
 
         return ("defined", t.value)
@@ -1162,7 +1162,7 @@
         return self.directive in ["if","ifdef","ifndef","elif"]
 
     def isInclude(self):
-        """checks wether this is a #include directive. if true, then returns the
+        """checks whether this is a #include directive. if true, then returns the
            corresponding file name (with brackets or double-qoutes). None otherwise"""
         if self.directive != "include":
             return None
@@ -1517,15 +1517,20 @@
         tokens = tokens[:-1]  # remove trailing tokLN
         self.blocks = [ Block(tokens) ] + self.blocks
 
-    def replaceTokens(self,replacements=dict()):
-        """replace tokens according to the given dict
-           """
+    def replaceTokens(self,replacements):
+        """replace tokens according to the given dict"""
         for b in self.blocks:
-            if not b.isDirective():
+            made_change = False
+            if b.isInclude() == None:
                 for tok in b.tokens:
                     if tok.id == tokIDENT:
                         if tok.value in replacements:
                             tok.value = replacements[tok.value]
+                            made_change = True
+
+            if made_change and b.isIf():
+                # Keep 'expr' in sync with 'tokens'.
+                b.expr = CppExpr(b.tokens)
 
 class BlockParser:
     """a class used to convert an input source file into a BlockList object"""
@@ -1798,6 +1803,10 @@
 #define X
 #endif
 
+#ifndef SIGRTMAX
+#define SIGRTMAX 123
+#endif /* SIGRTMAX */
+
 #if 0
 #if 1
 #define  BAD_6
@@ -1817,12 +1826,17 @@
 #define X
 #endif
 
+#ifndef __SIGRTMAX
+#define __SIGRTMAX 123
+#endif
+
 """
 
     out = StringOutput()
     lines = string.split(text, '\n')
     list = BlockParser().parse( CppLinesTokenizer(lines) )
     #D_setlevel(2)
+    list.replaceTokens( kernel_token_replacements )
     list.optimizeAll( {"__KERNEL__":kCppUndefinedMacro} )
     list.write(out)
     if out.get() != expected:
diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py
index f235803..2efd455 100644
--- a/libc/kernel/tools/defaults.py
+++ b/libc/kernel/tools/defaults.py
@@ -6,20 +6,16 @@
 from utils import *
 
 # the list of supported architectures
-#
 kernel_archs = [ 'arm', 'arm64', 'mips', 'x86' ]
 
 # the list of include directories that belong to the kernel
 # tree. used when looking for sources...
-#
 kernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ]
 
 # path to the directory containing the original kernel headers
-#
 kernel_original_path = os.path.normpath( find_program_dir() + '/../../../../external/kernel-headers/original' )
 
 # path to the default location of the cleaned-up headers
-#
 kernel_cleaned_path = os.path.normpath( find_program_dir() + '/..' )
 
 # a special value that is used to indicate that a given macro is known to be
@@ -33,6 +29,7 @@
     "__KERNEL_STRICT_NAMES":"1",
     "__CHECKER__": kCppUndefinedMacro,
     "__CHECK_ENDIAN__": kCppUndefinedMacro,
+    "CONFIG_64BIT": "__LP64__",
     "CONFIG_X86_32": "__i386__",
     "__EXPORTED_HEADERS__": "1",
     }
@@ -45,9 +42,13 @@
 # maps an architecture to a set of default macros that would be provided by
 # toolchain preprocessor
 kernel_default_arch_macros = {
-    "arm": {},
+    "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"},
     "arm64": {},
-    "mips": {"CONFIG_32BIT":"1"},
+    "mips": {"__MIPSEB__": kCppUndefinedMacro,
+             "__MIPSEL__": "1",
+             "CONFIG_32BIT": "_ABIO32",
+             "CONFIG_CPU_LITTLE_ENDIAN": "1",
+             "__SANE_USERSPACE_TYPES__": "1",},
     "x86": {},
     }
 
@@ -57,15 +58,24 @@
     "mips": {"off_t":"__kernel_off_t"},
     "x86": {},
     }
+
 # Replace tokens in the output according to this mapping
 kernel_token_replacements = {
     "asm": "__asm__",
-    "__unused": "__linux_unused", # The kernel usage of __unused conflicts with the macro defined in sys/cdefs.h
+    # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
+    "__unused": "__linux_unused",
+    # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
+    "_NSIG": "_KERNEL__NSIG",
+    "NSIG": "_KERNEL_NSIG",
+    # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few.
+    "SIGRTMIN": "__SIGRTMIN",
+    "SIGRTMAX": "__SIGRTMAX",
     }
 
 # this is the set of known static inline functions that we want to keep
 # in the final ARM headers. this is only used to keep optimized byteswapping
 # static functions and stuff like that.
+# TODO: this isn't working!
 kernel_known_arm_statics = set(
         [ "___arch__swab32",    # asm-arm/byteorder.h
         ]
@@ -88,11 +98,9 @@
     )
 
 kernel_known_generic_statics = set(
-        [ "__invalid_size_argument_for_IOC",  # asm-generic/ioctl.h
-          "__cmsg_nxthdr",                    # linux/socket.h
-          "cmsg_nxthdr",                      # linux/socket.h
-          "ipt_get_target",
-          "ip6t_get_target",
+        [
+          "ipt_get_target",  # uapi/linux/netfilter_ipv4/ip_tables.h
+          "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h
         ]
     )
 
diff --git a/libc/kernel/tools/find_headers.py b/libc/kernel/tools/find_headers.py
deleted file mode 100755
index 9b3572a..0000000
--- a/libc/kernel/tools/find_headers.py
+++ /dev/null
@@ -1,170 +0,0 @@
-#!/usr/bin/env python
-#
-# this program is used to find source code that includes linux kernel headers directly
-# (e.g. with #include <linux/...> or #include <asm/...>)
-#
-# then it lists them on the standard output.
-
-import sys, cpp, glob, os, re, getopt, kernel
-from utils import *
-from defaults import *
-
-program_dir = find_program_dir()
-
-wanted_archs   = kernel_archs
-wanted_config  = None
-
-def usage():
-    print """\
-  usage:  find_headers.py [options] <kernel-root> (file|directory|@listfile)+
-
-     options:
-        -c <file>          specify .config file (none by default)
-
-        -a <archs>         used to specify an alternative list
-                           of architectures to support
-                           ('%s' by default)
-
-        -v                 enable verbose mode
-
-    this program is used to find all the kernel headers that are used
-    by a set of source files or directories containing them. the search
-    is recursive to find *all* required files.
-
-""" % ( string.join(kernel_archs,",") )
-    sys.exit(1)
-
-
-try:
-    optlist, args = getopt.getopt( sys.argv[1:], 'vc:d:a:k:' )
-except:
-    # unrecognized option
-    print "error: unrecognized option"
-    usage()
-
-for opt, arg in optlist:
-    if opt == '-a':
-        wanted_archs = string.split(arg,',')
-    elif opt == '-c':
-        wanted_config = arg
-    elif opt == '-v':
-        kernel.verboseSearch = 1
-        kernel.verboseFind   = 1
-        verbose = 1
-    else:
-        usage()
-
-if len(args) < 2:
-    usage()
-
-kernel_root = args[0]
-if not os.path.exists(kernel_root):
-    sys.stderr.write( "error: directory '%s' does not exist\n" % kernel_root )
-    sys.exit(1)
-
-if not os.path.isdir(kernel_root):
-    sys.stderr.write( "error: '%s' is not a directory\n" % kernel_root )
-    sys.exit(1)
-
-if not os.path.isdir(kernel_root+"/include/linux"):
-    sys.stderr.write( "error: '%s' does not have an 'include/linux' directory\n" % kernel_root )
-    sys.exit(1)
-
-if wanted_config:
-    if not os.path.exists(wanted_config):
-        sys.stderr.write( "error: file '%s' does not exist\n" % wanted_config )
-        sys.exit(1)
-
-    if not os.path.isfile(wanted_config):
-        sys.stderr.write( "error: '%s' is not a file\n" % wanted_config )
-        sys.exit(1)
-
-# find all architectures in the kernel tree
-archs   = []
-for archdir in os.listdir(kernel_root+"/arch"):
-    if os.path.exists("%s/arch/%s/include/asm" % (kernel_root, archdir)):
-        if verbose:
-            print "Found arch '%s'" % archdir
-        archs.append(archdir)
-
-# if we're using the 'kernel_headers' directory, there is only asm/
-# and no other asm-<arch> directories
-#
-in_kernel_headers = False
-if len(archs) == 0:
-    # this can happen when we're using the 'kernel_headers' directory
-    if os.path.isdir(kernel_root+"/asm"):
-        in_kernel_headers = True
-        archs = [ "arm", "mips"]
-
-# if the user has specified some architectures with -a <archs> ensure that
-# all those he wants are available from the kernel include tree
-if wanted_archs != None:
-    if in_kernel_headers and wanted_archs != [ "arm", "mips" ]:
-        sys.stderr.write( "error: when parsing kernel_headers, only 'arm' and 'mips' architectures are supported at the moment\n" )
-        sys.exit(1)
-    missing = []
-    for arch in wanted_archs:
-        if arch not in archs:
-            missing.append(arch)
-    if len(missing) > 0:
-        sys.stderr.write( "error: the following requested architectures are not in the kernel tree: " )
-        for a in missing:
-            sys.stderr.write( " %s" % a )
-        sys.stderr.write( "\n" )
-        sys.exit(1)
-
-    archs = wanted_archs
-
-# helper function used to walk the user files
-def parse_file(path, parser):
-    #print "parse %s" % path
-    parser.parseFile(path)
-
-
-# remove previous destination directory
-#destdir = "/tmp/bionic-kernel-headers/"
-#cleanup_dir(destdir)
-
-# try to read the config file
-try:
-    cparser = kernel.ConfigParser()
-    if wanted_config:
-        cparser.parseFile( wanted_config )
-except:
-    sys.stderr.write( "error: can't parse '%s'" % wanted_config )
-    sys.exit(1)
-
-kernel_config = cparser.getDefinitions()
-
-# first, obtain the list of kernel files used by our clients
-fparser = kernel.HeaderScanner()
-dir_excludes=[".repo","external/kernel-headers","ndk","out","prebuilt","bionic/libc/kernel","development/ndk","external/qemu/distrib"]
-walk_source_files( args[1:], parse_file, fparser, excludes=["./"+f for f in dir_excludes] )
-headers = fparser.getHeaders()
-files   = fparser.getFiles()
-
-# now recursively scan the kernel headers for additionnal sub-included headers
-hparser = kernel.KernelHeaderFinder(headers,archs,kernel_root,kernel_config)
-headers = hparser.scanForAllArchs()
-
-if 0:    # just for debugging
-    dumpHeaderUsers = False
-
-    print "the following %d headers:" % len(headers)
-    for h in sorted(headers):
-        if dumpHeaderUsers:
-            print "  %s (%s)" % (h, repr(hparser.getHeaderUsers(h)))
-        else:
-            print "  %s" % h
-
-    print "are used by the following %d files:" % len(files)
-    for f in sorted(files):
-        print "  %s" % f
-
-    sys.exit(0)
-
-for h in sorted(headers):
-    print "%s" % h
-
-sys.exit(0)
diff --git a/libc/kernel/tools/find_users.py b/libc/kernel/tools/find_users.py
deleted file mode 100755
index 5ee308c..0000000
--- a/libc/kernel/tools/find_users.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python
-#
-# this program is used to find source code that includes linux kernel headers directly
-# (e.g. with #include <linux/...> or #include <asm/...>)
-#
-# then it lists
-
-import sys, cpp, glob, os, re, getopt
-import kernel
-from utils import *
-from defaults import *
-
-
-def usage():
-    print """\
-  usage:  find_users.py [-v] (file|directory|@listfile)+
-
-    this program is used to scan a list of files or directories for
-    sources that include kernel headers directly. the program prints
-    the list of said source files when it's done.
-
-    when scanning directories, only files matching the following
-    extension will be searched: .c .cpp .S .h
-
-    use -v to enable verbose output
-"""
-    sys.exit(1)
-
-
-try:
-    optlist, args = getopt.getopt( sys.argv[1:], 'v' )
-except:
-    # unrecognized option
-    print "error: unrecognized option"
-    usage()
-
-for opt, arg in optlist:
-    if opt == '-v':
-        kernel.verboseSearch = 1
-        kernel.verboseFind   = 1
-    else:
-        usage()
-
-if len(args) < 1:
-    usage()
-
-# helper function used to walk the user files
-def parse_file(path, parser):
-    parser.parseFile(path)
-
-
-# first, obtain the list of kernel files used by our clients
-# avoid parsing the 'kernel_headers' directory itself since we
-# use this program with the Android source tree by default.
-#
-fparser = kernel.HeaderScanner()
-walk_source_files( args, parse_file, fparser, excludes=["kernel_headers","original"] )
-files   = fparser.getFiles()
-
-for f in sorted(files):
-    print f
-
-sys.exit(0)
diff --git a/libc/kernel/tools/generate_uapi_headers.sh b/libc/kernel/tools/generate_uapi_headers.sh
index 9eeb2a5..386159a 100755
--- a/libc/kernel/tools/generate_uapi_headers.sh
+++ b/libc/kernel/tools/generate_uapi_headers.sh
@@ -148,22 +148,28 @@
   exit 1
 fi
 
+if [[ -d "${KERNEL_DIR}/linux-stable" ]]; then
+  src_dir="linux-stable"
+else
+  src_dir="common"
+fi
+
 if [[ ${KERNEL_DOWNLOAD} -eq 1 ]]; then
   TMPDIR=$(mktemp -d /tmp/android_kernelXXXXXXXX)
   cd "${TMPDIR}"
   echo "Fetching android kernel source ${KERNEL_VERSION}"
   git clone https://android.googlesource.com/kernel/common.git
-  cd common
+  cd "${COMMON}"
   git checkout "${KERNEL_VERSION}"
   KERNEL_DIR="${TMPDIR}"
 elif [[ "${KERNEL_DIR}" == "" ]]; then
   echo "Must specify one of --use-kernel-dir or --download-kernel."
   exit 1
-elif [[ ! -d "${KERNEL_DIR}" ]] || [[ ! -d "${KERNEL_DIR}/common" ]]; then
-  echo "The kernel directory $KERNEL_DIR or $KERNEL_DIR/common does not exist."
+elif [[ ! -d "${KERNEL_DIR}" ]] || [[ ! -d "${KERNEL_DIR}/${src_dir}" ]]; then
+  echo "The kernel directory $KERNEL_DIR or $KERNEL_DIR/${src_dir} does not exist."
   exit 1
 else
-  cd "${KERNEL_DIR}/common"
+  cd "${KERNEL_DIR}/${src_dir}"
 fi
 
 if [[ ${SKIP_GENERATION} -eq 0 ]]; then
@@ -175,27 +181,27 @@
 fi
 
 # Copy all of the include/uapi files to the kernel headers uapi directory.
-copy_hdrs "${KERNEL_DIR}/common/include/uapi" "${ANDROID_KERNEL_DIR}/uapi"
+copy_hdrs "${KERNEL_DIR}/${src_dir}/include/uapi" "${ANDROID_KERNEL_DIR}/uapi"
 
 # Copy the staging files to uapi/linux.
-copy_hdrs "${KERNEL_DIR}/common/drivers/staging/android/uapi" \
+copy_hdrs "${KERNEL_DIR}/${src_dir}/drivers/staging/android/uapi" \
           "${ANDROID_KERNEL_DIR}/uapi/linux" "no-copy-dirs"
 
 # Copy the generated headers.
-copy_hdrs "${KERNEL_DIR}/common/include/generated/uapi" \
+copy_hdrs "${KERNEL_DIR}/${src_dir}/include/generated/uapi" \
           "${ANDROID_KERNEL_DIR}/uapi"
 
 for arch in "${ARCH_LIST[@]}"; do
   # Copy arch headers.
-  copy_hdrs "${KERNEL_DIR}/common/arch/${arch}/include/uapi" \
+  copy_hdrs "${KERNEL_DIR}/${src_dir}/arch/${arch}/include/uapi" \
             "${ANDROID_KERNEL_DIR}/uapi/asm-${arch}"
   # Copy the generated arch headers.
-  copy_hdrs "${KERNEL_DIR}/common/arch/${arch}/include/generated/uapi" \
+  copy_hdrs "${KERNEL_DIR}/${src_dir}/arch/${arch}/include/generated/uapi" \
             "${ANDROID_KERNEL_DIR}/uapi/asm-${arch}"
 
   # Special copy of generated header files from arch/<ARCH>/generated/asm that
   # also exist in uapi/asm-generic.
-  copy_if_exists "${KERNEL_DIR}/common/include/uapi/asm-generic" \
-                 "${KERNEL_DIR}/common/arch/${arch}/include/generated/asm" \
+  copy_if_exists "${KERNEL_DIR}/${src_dir}/include/uapi/asm-generic" \
+                 "${KERNEL_DIR}/${src_dir}/arch/${arch}/include/generated/asm" \
                  "${ANDROID_KERNEL_DIR}/uapi/asm-${arch}/asm"
 done
diff --git a/libc/kernel/tools/update_all.py b/libc/kernel/tools/update_all.py
index 3f1d1e6..73862da 100755
--- a/libc/kernel/tools/update_all.py
+++ b/libc/kernel/tools/update_all.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-import sys, cpp, kernel, glob, os, re, getopt, clean_header
+import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
 from defaults import *
 from utils import *
 
@@ -40,11 +40,22 @@
     if not os.path.isdir(original_dir):
         panic( "Missing directory, please specify one through command-line: %s\n" % original_dir )
 
+# Fixme: This should be removed after next release.
+# Do not update ion.h ion_test.h until after next release in aosp.
+source = subprocess.check_output('git remote show', shell=True).strip()
+skip_ion = False
+if source == "aosp":
+    skip_ion = True
+
 # find all source files in 'original'
 #
 sources = []
+warning_ion = []
 for root, dirs, files in os.walk( original_dir ):
     for file in files:
+        if skip_ion and (file == "ion.h" or file == "ion_test.h"):
+            warning_ion.append("  Skipped file %s/%s" % (root, file))
+            continue
         base, ext = os.path.splitext(file)
         if ext == ".h":
             sources.append( "%s/%s" % (root,file) )
@@ -90,4 +101,7 @@
 
 b.updateGitFiles()
 
+if warning_ion:
+    print "NOTE: Due to import into aosp, some files were not processed."
+    print "\n".join(warning_ion)
 sys.exit(0)
diff --git a/libc/kernel/uapi/asm-arm/asm/byteorder.h b/libc/kernel/uapi/asm-arm/asm/byteorder.h
index 0d2bdf3..6f17a48 100644
--- a/libc/kernel/uapi/asm-arm/asm/byteorder.h
+++ b/libc/kernel/uapi/asm-arm/asm/byteorder.h
@@ -18,11 +18,6 @@
  ****************************************************************************/
 #ifndef __ASM_ARM_BYTEORDER_H
 #define __ASM_ARM_BYTEORDER_H
-#ifdef __ARMEB__
-#include <linux/byteorder/big_endian.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#else
 #include <linux/byteorder/little_endian.h>
 #endif
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-arm/asm/hwcap.h b/libc/kernel/uapi/asm-arm/asm/hwcap.h
index 54e433c..e70f3b8 100644
--- a/libc/kernel/uapi/asm-arm/asm/hwcap.h
+++ b/libc/kernel/uapi/asm-arm/asm/hwcap.h
@@ -44,5 +44,7 @@
 #define HWCAP_IDIVT (1 << 18)
 #define HWCAP_VFPD32 (1 << 19)
 #define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT)
-#endif
+#define HWCAP_LPAE (1 << 20)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HWCAP_EVTSTRM (1 << 21)
+#endif
diff --git a/libc/kernel/uapi/asm-arm/asm/kvm.h b/libc/kernel/uapi/asm-arm/asm/kvm.h
index 31a2a2f..2b5a17e 100644
--- a/libc/kernel/uapi/asm-arm/asm/kvm.h
+++ b/libc/kernel/uapi/asm-arm/asm/kvm.h
@@ -61,74 +61,94 @@
 };
 #define KVM_ARM_TARGET_CORTEX_A15 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define KVM_ARM_NUM_TARGETS 1
+#define KVM_ARM_TARGET_CORTEX_A7 1
+#define KVM_ARM_NUM_TARGETS 2
 #define KVM_ARM_DEVICE_TYPE_SHIFT 0
 #define KVM_ARM_DEVICE_TYPE_MASK (0xffff << KVM_ARM_DEVICE_TYPE_SHIFT)
-#define KVM_ARM_DEVICE_ID_SHIFT 16
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ARM_DEVICE_ID_SHIFT 16
 #define KVM_ARM_DEVICE_ID_MASK (0xffff << KVM_ARM_DEVICE_ID_SHIFT)
 #define KVM_ARM_DEVICE_VGIC_V2 0
 #define KVM_VGIC_V2_ADDR_TYPE_DIST 0
-#define KVM_VGIC_V2_ADDR_TYPE_CPU 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_VGIC_V2_ADDR_TYPE_CPU 1
 #define KVM_VGIC_V2_DIST_SIZE 0x1000
 #define KVM_VGIC_V2_CPU_SIZE 0x2000
 #define KVM_ARM_VCPU_POWER_OFF 0
-struct kvm_vcpu_init {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct kvm_vcpu_init {
  __u32 target;
  __u32 features[7];
 };
-struct kvm_sregs {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct kvm_sregs {
 };
 struct kvm_fpu {
 };
-struct kvm_guest_debug_arch {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct kvm_guest_debug_arch {
 };
 struct kvm_debug_exit_arch {
 };
-struct kvm_sync_regs {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct kvm_sync_regs {
 };
 struct kvm_arch_memory_slot {
 };
-#define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000
 #define KVM_REG_ARM_COPROC_SHIFT 16
 #define KVM_REG_ARM_32_OPC2_MASK 0x0000000000000007
 #define KVM_REG_ARM_32_OPC2_SHIFT 0
-#define KVM_REG_ARM_OPC1_MASK 0x0000000000000078
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_OPC1_MASK 0x0000000000000078
 #define KVM_REG_ARM_OPC1_SHIFT 3
 #define KVM_REG_ARM_CRM_MASK 0x0000000000000780
 #define KVM_REG_ARM_CRM_SHIFT 7
-#define KVM_REG_ARM_32_CRN_MASK 0x0000000000007800
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_32_CRN_MASK 0x0000000000007800
 #define KVM_REG_ARM_32_CRN_SHIFT 11
+#define ARM_CP15_REG_SHIFT_MASK(x,n)   (((x) << KVM_REG_ARM_ ## n ## _SHIFT) & KVM_REG_ARM_ ## n ## _MASK)
+#define __ARM_CP15_REG(op1,crn,crm,op2)   (KVM_REG_ARM | (15 << KVM_REG_ARM_COPROC_SHIFT) |   ARM_CP15_REG_SHIFT_MASK(op1, OPC1) |   ARM_CP15_REG_SHIFT_MASK(crn, 32_CRN) |   ARM_CP15_REG_SHIFT_MASK(crm, CRM) |   ARM_CP15_REG_SHIFT_MASK(op2, 32_OPC2))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ARM_CP15_REG32(...) (__ARM_CP15_REG(__VA_ARGS__) | KVM_REG_SIZE_U32)
+#define __ARM_CP15_REG64(op1,crm)   (__ARM_CP15_REG(op1, 0, crm, 0) | KVM_REG_SIZE_U64)
+#define ARM_CP15_REG64(...) __ARM_CP15_REG64(__VA_ARGS__)
+#define KVM_REG_ARM_TIMER_CTL ARM_CP15_REG32(0, 14, 3, 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_TIMER_CNT ARM_CP15_REG64(1, 14)
+#define KVM_REG_ARM_TIMER_CVAL ARM_CP15_REG64(3, 14)
 #define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT)
 #define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / 4)
-#define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT)
 #define KVM_REG_ARM_DEMUX_ID_MASK 0x000000000000FF00
 #define KVM_REG_ARM_DEMUX_ID_SHIFT 8
 #define KVM_REG_ARM_DEMUX_ID_CCSIDR (0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT)
-#define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF
 #define KVM_REG_ARM_DEMUX_VAL_SHIFT 0
 #define KVM_REG_ARM_VFP (0x0012 << KVM_REG_ARM_COPROC_SHIFT)
 #define KVM_REG_ARM_VFP_MASK 0x000000000000FFFF
-#define KVM_REG_ARM_VFP_BASE_REG 0x0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_VFP_BASE_REG 0x0
 #define KVM_REG_ARM_VFP_FPSID 0x1000
 #define KVM_REG_ARM_VFP_FPSCR 0x1001
 #define KVM_REG_ARM_VFP_MVFR1 0x1006
-#define KVM_REG_ARM_VFP_MVFR0 0x1007
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_VFP_MVFR0 0x1007
 #define KVM_REG_ARM_VFP_FPEXC 0x1008
 #define KVM_REG_ARM_VFP_FPINST 0x1009
 #define KVM_REG_ARM_VFP_FPINST2 0x100A
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_DEV_ARM_VGIC_GRP_ADDR 0
+#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
+#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2
+#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
+#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0
+#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)
 #define KVM_ARM_IRQ_TYPE_SHIFT 24
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_ARM_IRQ_TYPE_MASK 0xff
diff --git a/libc/kernel/uapi/asm-arm/asm/perf_regs.h b/libc/kernel/uapi/asm-arm/asm/perf_regs.h
new file mode 100644
index 0000000..745bcf3
--- /dev/null
+++ b/libc/kernel/uapi/asm-arm/asm/perf_regs.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _ASM_ARM_PERF_REGS_H
+#define _ASM_ARM_PERF_REGS_H
+enum perf_event_arm_regs {
+ PERF_REG_ARM_R0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_REG_ARM_R1,
+ PERF_REG_ARM_R2,
+ PERF_REG_ARM_R3,
+ PERF_REG_ARM_R4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_REG_ARM_R5,
+ PERF_REG_ARM_R6,
+ PERF_REG_ARM_R7,
+ PERF_REG_ARM_R8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_REG_ARM_R9,
+ PERF_REG_ARM_R10,
+ PERF_REG_ARM_FP,
+ PERF_REG_ARM_IP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_REG_ARM_SP,
+ PERF_REG_ARM_LR,
+ PERF_REG_ARM_PC,
+ PERF_REG_ARM_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#endif
diff --git a/libc/kernel/uapi/asm-arm/asm/ptrace.h b/libc/kernel/uapi/asm-arm/asm/ptrace.h
index 78191ac..9d39d49 100644
--- a/libc/kernel/uapi/asm-arm/asm/ptrace.h
+++ b/libc/kernel/uapi/asm-arm/asm/ptrace.h
@@ -44,10 +44,10 @@
 #define IRQ26_MODE 0x00000002
 #define SVC26_MODE 0x00000003
 #define USR_MODE 0x00000010
-#define FIQ_MODE 0x00000011
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define IRQ_MODE 0x00000012
 #define SVC_MODE 0x00000013
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FIQ_MODE 0x00000011
+#define IRQ_MODE 0x00000012
 #define ABT_MODE 0x00000017
 #define HYP_MODE 0x0000001a
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -56,63 +56,65 @@
 #define MODE32_BIT 0x00000010
 #define MODE_MASK 0x0000001f
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PSR_T_BIT 0x00000020
+#define V4_PSR_T_BIT 0x00000020
+#define V7M_PSR_T_BIT 0x01000000
+#define PSR_T_BIT V4_PSR_T_BIT
 #define PSR_F_BIT 0x00000040
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_I_BIT 0x00000080
 #define PSR_A_BIT 0x00000100
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_E_BIT 0x00000200
 #define PSR_J_BIT 0x01000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_Q_BIT 0x08000000
 #define PSR_V_BIT 0x10000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_C_BIT 0x20000000
 #define PSR_Z_BIT 0x40000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_N_BIT 0x80000000
 #define PSR_f 0xff000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_s 0x00ff0000
 #define PSR_x 0x0000ff00
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_c 0x000000ff
 #define APSR_MASK 0xf80f0000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_ISET_MASK 0x01000010
 #define PSR_IT_MASK 0x0600fc00
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PSR_ENDIAN_MASK 0x00000200
 #define PSR_ENDSTATE 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PT_TEXT_ADDR 0x10000
 #define PT_DATA_ADDR 0x10004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PT_TEXT_END_ADDR 0x10008
 #ifndef __ASSEMBLY__
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct pt_regs {
  long uregs[18];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define ARM_cpsr uregs[16]
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_pc uregs[15]
 #define ARM_lr uregs[14]
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_sp uregs[13]
 #define ARM_ip uregs[12]
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_fp uregs[11]
 #define ARM_r10 uregs[10]
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_r9 uregs[9]
 #define ARM_r8 uregs[8]
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_r7 uregs[7]
 #define ARM_r6 uregs[6]
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_r5 uregs[5]
 #define ARM_r4 uregs[4]
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_r3 uregs[3]
 #define ARM_r2 uregs[2]
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_r1 uregs[1]
 #define ARM_r0 uregs[0]
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARM_ORIG_r0 uregs[17]
 #define ARM_VFPREGS_SIZE ( 32 * 8   + 4   )
-#endif
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
+#endif
diff --git a/libc/kernel/uapi/asm-arm/asm/signal.h b/libc/kernel/uapi/asm-arm/asm/signal.h
index 9297a70..fd39aaa 100644
--- a/libc/kernel/uapi/asm-arm/asm/signal.h
+++ b/libc/kernel/uapi/asm-arm/asm/signal.h
@@ -21,7 +21,7 @@
 #include <linux/types.h>
 struct siginfo;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define NSIG 32
+#define _KERNEL_NSIG 32
 typedef unsigned long sigset_t;
 #define SIGHUP 1
 #define SIGINT 2
@@ -66,8 +66,8 @@
 #define SIGSYS 31
 #define SIGUNUSED 31
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SIGRTMIN 32
-#define SIGRTMAX _NSIG
+#define __SIGRTMIN 32
+#define __SIGRTMAX _KERNEL__NSIG
 #define SIGSWI 32
 #define SA_NOCLDSTOP 0x00000001
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-arm/asm/stat.h b/libc/kernel/uapi/asm-arm/asm/stat.h
index d8188bf..b3425dd 100644
--- a/libc/kernel/uapi/asm-arm/asm/stat.h
+++ b/libc/kernel/uapi/asm-arm/asm/stat.h
@@ -37,68 +37,55 @@
 #define STAT_HAVE_NSEC
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct stat {
-#ifdef __ARMEB__
- unsigned short st_dev;
- unsigned short __pad1;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#else
  unsigned long st_dev;
-#endif
  unsigned long st_ino;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned short st_mode;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned short st_nlink;
  unsigned short st_uid;
  unsigned short st_gid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#ifdef __ARMEB__
- unsigned short st_rdev;
- unsigned short __pad2;
-#else
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_rdev;
-#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_size;
  unsigned long st_blksize;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_blocks;
  unsigned long st_atime;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_atime_nsec;
  unsigned long st_mtime;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_mtime_nsec;
  unsigned long st_ctime;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_ctime_nsec;
  unsigned long __unused4;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long __unused5;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct stat64 {
  unsigned long long st_dev;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char __pad0[4];
 #define STAT64_HAS_BROKEN_ST_INO 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long __st_ino;
  unsigned int st_mode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int st_nlink;
  unsigned long st_uid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_gid;
  unsigned long long st_rdev;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char __pad3[4];
  long long st_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_blksize;
  unsigned long long st_blocks;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_atime;
  unsigned long st_atime_nsec;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_mtime;
  unsigned long st_mtime_nsec;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long st_ctime;
  unsigned long st_ctime_nsec;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long long st_ino;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-arm/asm/unistd.h b/libc/kernel/uapi/asm-arm/asm/unistd.h
index f99bfb1..be9f36f 100644
--- a/libc/kernel/uapi/asm-arm/asm/unistd.h
+++ b/libc/kernel/uapi/asm-arm/asm/unistd.h
@@ -19,12 +19,7 @@
 #ifndef _UAPI__ASM_ARM_UNISTD_H
 #define _UAPI__ASM_ARM_UNISTD_H
 #define __NR_OABI_SYSCALL_BASE 0x900000
-#if defined(__thumb__) || defined(__ARM_EABI__)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_SYSCALL_BASE 0
-#else
-#define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BASE
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0)
 #define __NR_exit (__NR_SYSCALL_BASE+ 1)
@@ -461,29 +456,29 @@
 #define __NR_kcmp (__NR_SYSCALL_BASE+378)
 #define __NR_finit_module (__NR_SYSCALL_BASE+379)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __NR_sched_setattr (__NR_SYSCALL_BASE+380)
+#define __NR_sched_getattr (__NR_SYSCALL_BASE+381)
 #define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000)
 #define __ARM_NR_breakpoint (__ARM_NR_BASE+1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARM_NR_cacheflush (__ARM_NR_BASE+2)
 #define __ARM_NR_usr26 (__ARM_NR_BASE+3)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARM_NR_usr32 (__ARM_NR_BASE+4)
 #define __ARM_NR_set_tls (__ARM_NR_BASE+5)
-#ifdef __ARM_EABI__
-#undef __NR_time
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#undef __NR_time
 #undef __NR_umount
 #undef __NR_stime
 #undef __NR_alarm
-#undef __NR_utime
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#undef __NR_utime
 #undef __NR_getrlimit
 #undef __NR_select
 #undef __NR_readdir
-#undef __NR_mmap
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#undef __NR_mmap
 #undef __NR_socketcall
 #undef __NR_syscall
 #undef __NR_ipc
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-arm64/asm/byteorder.h b/libc/kernel/uapi/asm-arm64/asm/byteorder.h
index 1908aa6..92b1d48 100644
--- a/libc/kernel/uapi/asm-arm64/asm/byteorder.h
+++ b/libc/kernel/uapi/asm-arm64/asm/byteorder.h
@@ -18,6 +18,11 @@
  ****************************************************************************/
 #ifndef __ASM_BYTEORDER_H
 #define __ASM_BYTEORDER_H
+#ifdef __AARCH64EB__
+#include <linux/byteorder/big_endian.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#else
 #include <linux/byteorder/little_endian.h>
 #endif
+#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-arm64/asm/hwcap.h b/libc/kernel/uapi/asm-arm64/asm/hwcap.h
index 539b725..ccea53d 100644
--- a/libc/kernel/uapi/asm-arm64/asm/hwcap.h
+++ b/libc/kernel/uapi/asm-arm64/asm/hwcap.h
@@ -21,4 +21,11 @@
 #define HWCAP_FP (1 << 0)
 #define HWCAP_ASIMD (1 << 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HWCAP_EVTSTRM (1 << 2)
+#define HWCAP_AES (1 << 3)
+#define HWCAP_PMULL (1 << 4)
+#define HWCAP_SHA1 (1 << 5)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HWCAP_SHA2 (1 << 6)
+#define HWCAP_CRC32 (1 << 7)
 #endif
diff --git a/libc/kernel/uapi/asm-arm64/asm/kvm.h b/libc/kernel/uapi/asm-arm64/asm/kvm.h
new file mode 100644
index 0000000..93abd43
--- /dev/null
+++ b/libc/kernel/uapi/asm-arm64/asm/kvm.h
@@ -0,0 +1,158 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __ARM_KVM_H__
+#define __ARM_KVM_H__
+#define KVM_SPSR_EL1 0
+#define KVM_SPSR_SVC KVM_SPSR_EL1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SPSR_ABT 1
+#define KVM_SPSR_UND 2
+#define KVM_SPSR_IRQ 3
+#define KVM_SPSR_FIQ 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_NR_SPSR 5
+#ifndef __ASSEMBLY__
+#include <asm/types.h>
+#include <asm/ptrace.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __KVM_HAVE_GUEST_DEBUG
+#define __KVM_HAVE_IRQ_LINE
+#define KVM_REG_SIZE(id)   (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
+struct kvm_regs {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct user_pt_regs regs;
+ __u64 sp_el1;
+ __u64 elr_el1;
+ __u64 spsr[KVM_NR_SPSR];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct user_fpsimd_state fp_regs;
+};
+#define KVM_ARM_TARGET_AEM_V8 0
+#define KVM_ARM_TARGET_FOUNDATION_V8 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ARM_TARGET_CORTEX_A57 2
+#define KVM_ARM_TARGET_XGENE_POTENZA 3
+#define KVM_ARM_NUM_TARGETS 4
+#define KVM_ARM_DEVICE_TYPE_SHIFT 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ARM_DEVICE_TYPE_MASK (0xffff << KVM_ARM_DEVICE_TYPE_SHIFT)
+#define KVM_ARM_DEVICE_ID_SHIFT 16
+#define KVM_ARM_DEVICE_ID_MASK (0xffff << KVM_ARM_DEVICE_ID_SHIFT)
+#define KVM_ARM_DEVICE_VGIC_V2 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_VGIC_V2_ADDR_TYPE_DIST 0
+#define KVM_VGIC_V2_ADDR_TYPE_CPU 1
+#define KVM_VGIC_V2_DIST_SIZE 0x1000
+#define KVM_VGIC_V2_CPU_SIZE 0x2000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ARM_VCPU_POWER_OFF 0
+#define KVM_ARM_VCPU_EL1_32BIT 1
+struct kvm_vcpu_init {
+ __u32 target;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 features[7];
+};
+struct kvm_sregs {
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct kvm_fpu {
+};
+struct kvm_guest_debug_arch {
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct kvm_debug_exit_arch {
+};
+struct kvm_sync_regs {
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct kvm_arch_memory_slot {
+};
+#define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000
+#define KVM_REG_ARM_COPROC_SHIFT 16
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / sizeof(__u32))
+#define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM_DEMUX_ID_MASK 0x000000000000FF00
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_DEMUX_ID_SHIFT 8
+#define KVM_REG_ARM_DEMUX_ID_CCSIDR (0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT)
+#define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF
+#define KVM_REG_ARM_DEMUX_VAL_SHIFT 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM64_SYSREG (0x0013 << KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM64_SYSREG_OP0_MASK 0x000000000000c000
+#define KVM_REG_ARM64_SYSREG_OP0_SHIFT 14
+#define KVM_REG_ARM64_SYSREG_OP1_MASK 0x0000000000003800
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM64_SYSREG_OP1_SHIFT 11
+#define KVM_REG_ARM64_SYSREG_CRN_MASK 0x0000000000000780
+#define KVM_REG_ARM64_SYSREG_CRN_SHIFT 7
+#define KVM_REG_ARM64_SYSREG_CRM_MASK 0x0000000000000078
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM64_SYSREG_CRM_SHIFT 3
+#define KVM_REG_ARM64_SYSREG_OP2_MASK 0x0000000000000007
+#define KVM_REG_ARM64_SYSREG_OP2_SHIFT 0
+#define ARM64_SYS_REG_SHIFT_MASK(x,n)   (((x) << KVM_REG_ARM64_SYSREG_ ## n ## _SHIFT) &   KVM_REG_ARM64_SYSREG_ ## n ## _MASK)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __ARM64_SYS_REG(op0,op1,crn,crm,op2)   (KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG |   ARM64_SYS_REG_SHIFT_MASK(op0, OP0) |   ARM64_SYS_REG_SHIFT_MASK(op1, OP1) |   ARM64_SYS_REG_SHIFT_MASK(crn, CRN) |   ARM64_SYS_REG_SHIFT_MASK(crm, CRM) |   ARM64_SYS_REG_SHIFT_MASK(op2, OP2))
+#define ARM64_SYS_REG(...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64)
+#define KVM_REG_ARM_TIMER_CTL ARM64_SYS_REG(3, 3, 14, 3, 1)
+#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2)
+#define KVM_DEV_ARM_VGIC_GRP_ADDR 0
+#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
+#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32
+#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
+#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0
+#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ARM_IRQ_TYPE_SHIFT 24
+#define KVM_ARM_IRQ_TYPE_MASK 0xff
+#define KVM_ARM_IRQ_VCPU_SHIFT 16
+#define KVM_ARM_IRQ_VCPU_MASK 0xff
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ARM_IRQ_NUM_SHIFT 0
+#define KVM_ARM_IRQ_NUM_MASK 0xffff
+#define KVM_ARM_IRQ_TYPE_CPU 0
+#define KVM_ARM_IRQ_TYPE_SPI 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ARM_IRQ_TYPE_PPI 2
+#define KVM_ARM_IRQ_CPU_IRQ 0
+#define KVM_ARM_IRQ_CPU_FIQ 1
+#define KVM_ARM_IRQ_GIC_MAX 127
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_PSCI_FN_BASE 0x95c1ba5e
+#define KVM_PSCI_FN(n) (KVM_PSCI_FN_BASE + (n))
+#define KVM_PSCI_FN_CPU_SUSPEND KVM_PSCI_FN(0)
+#define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2)
+#define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3)
+#define KVM_PSCI_RET_SUCCESS 0
+#define KVM_PSCI_RET_NI ((unsigned long)-1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_PSCI_RET_INVAL ((unsigned long)-2)
+#define KVM_PSCI_RET_DENIED ((unsigned long)-3)
+#endif
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-generic/fcntl.h b/libc/kernel/uapi/asm-generic/fcntl.h
index f7b24a5..a15878f 100644
--- a/libc/kernel/uapi/asm-generic/fcntl.h
+++ b/libc/kernel/uapi/asm-generic/fcntl.h
@@ -86,95 +86,105 @@
 #define O_PATH 010000000
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifndef __O_TMPFILE
+#define __O_TMPFILE 020000000
+#endif
+#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT)
 #ifndef O_NDELAY
 #define O_NDELAY O_NONBLOCK
 #endif
-#define F_DUPFD 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define F_DUPFD 0
 #define F_GETFD 1
 #define F_SETFD 2
 #define F_GETFL 3
-#define F_SETFL 4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define F_SETFL 4
 #ifndef F_GETLK
 #define F_GETLK 5
 #define F_SETLK 6
-#define F_SETLKW 7
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define F_SETLKW 7
 #endif
 #ifndef F_SETOWN
 #define F_SETOWN 8
-#define F_GETOWN 9
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define F_GETOWN 9
 #endif
 #ifndef F_SETSIG
 #define F_SETSIG 10
-#define F_GETSIG 11
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define F_GETSIG 11
 #endif
+#ifndef __LP64__
 #ifndef F_GETLK64
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define F_GETLK64 12
 #define F_SETLK64 13
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define F_SETLKW64 14
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
 #ifndef F_SETOWN_EX
 #define F_SETOWN_EX 15
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define F_GETOWN_EX 16
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #ifndef F_GETOWNER_UIDS
 #define F_GETOWNER_UIDS 17
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define F_OWNER_TID 0
 #define F_OWNER_PID 1
 #define F_OWNER_PGRP 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct f_owner_ex {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int type;
  __kernel_pid_t pid;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define FD_CLOEXEC 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifndef F_RDLCK
 #define F_RDLCK 0
 #define F_WRLCK 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define F_UNLCK 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #ifndef F_EXLCK
 #define F_EXLCK 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define F_SHLCK 8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #define LOCK_SH 1
 #define LOCK_EX 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define LOCK_NB 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define LOCK_UN 8
 #define LOCK_MAND 32
 #define LOCK_READ 64
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define LOCK_WRITE 128
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define LOCK_RW 192
 #define F_LINUX_SPECIFIC_BASE 1024
 #ifndef HAVE_ARCH_STRUCT_FLOCK
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifndef __ARCH_FLOCK_PAD
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARCH_FLOCK_PAD
 #endif
 struct flock {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  short l_type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  short l_whence;
  __kernel_off_t l_start;
  __kernel_off_t l_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __kernel_pid_t l_pid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __ARCH_FLOCK_PAD
 };
 #endif
+#ifndef __LP64__
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifndef HAVE_ARCH_STRUCT_FLOCK64
 #ifndef __ARCH_FLOCK64_PAD
@@ -193,3 +203,4 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #endif
+#endif
diff --git a/libc/kernel/uapi/asm-generic/ipcbuf.h b/libc/kernel/uapi/asm-generic/ipcbuf.h
index c1da1de..cc7274e 100644
--- a/libc/kernel/uapi/asm-generic/ipcbuf.h
+++ b/libc/kernel/uapi/asm-generic/ipcbuf.h
@@ -31,8 +31,8 @@
  unsigned short seq;
  unsigned short __pad2;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long __unused1;
- unsigned long __unused2;
+ __kernel_ulong_t __unused1;
+ __kernel_ulong_t __unused2;
 };
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-generic/msgbuf.h b/libc/kernel/uapi/asm-generic/msgbuf.h
index 0c9e46d..b2500ef 100644
--- a/libc/kernel/uapi/asm-generic/msgbuf.h
+++ b/libc/kernel/uapi/asm-generic/msgbuf.h
@@ -37,14 +37,14 @@
  unsigned long __unused3;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
- unsigned long msg_cbytes;
- unsigned long msg_qnum;
- unsigned long msg_qbytes;
+ __kernel_ulong_t msg_cbytes;
+ __kernel_ulong_t msg_qnum;
+ __kernel_ulong_t msg_qbytes;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __kernel_pid_t msg_lspid;
  __kernel_pid_t msg_lrpid;
- unsigned long __unused4;
- unsigned long __unused5;
+ __kernel_ulong_t __unused4;
+ __kernel_ulong_t __unused5;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
diff --git a/libc/kernel/uapi/asm-generic/poll.h b/libc/kernel/uapi/asm-generic/poll.h
index 45d2c94..7faa0b8 100644
--- a/libc/kernel/uapi/asm-generic/poll.h
+++ b/libc/kernel/uapi/asm-generic/poll.h
@@ -48,11 +48,12 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #define POLLFREE 0x4000
+#define POLL_BUSY_LOOP 0x8000
 struct pollfd {
- int fd;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int fd;
  short events;
  short revents;
 };
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/asm-generic/shmbuf.h b/libc/kernel/uapi/asm-generic/shmbuf.h
index 4cf9efe..68b859d 100644
--- a/libc/kernel/uapi/asm-generic/shmbuf.h
+++ b/libc/kernel/uapi/asm-generic/shmbuf.h
@@ -41,23 +41,23 @@
  __kernel_pid_t shm_cpid;
  __kernel_pid_t shm_lpid;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long shm_nattch;
- unsigned long __unused4;
- unsigned long __unused5;
+ __kernel_ulong_t shm_nattch;
+ __kernel_ulong_t __unused4;
+ __kernel_ulong_t __unused5;
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct shminfo64 {
- unsigned long shmmax;
- unsigned long shmmin;
- unsigned long shmmni;
+ __kernel_ulong_t shmmax;
+ __kernel_ulong_t shmmin;
+ __kernel_ulong_t shmmni;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long shmseg;
- unsigned long shmall;
- unsigned long __unused1;
- unsigned long __unused2;
+ __kernel_ulong_t shmseg;
+ __kernel_ulong_t shmall;
+ __kernel_ulong_t __unused1;
+ __kernel_ulong_t __unused2;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long __unused3;
- unsigned long __unused4;
+ __kernel_ulong_t __unused3;
+ __kernel_ulong_t __unused4;
 };
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-generic/signal.h b/libc/kernel/uapi/asm-generic/signal.h
index c4c7e00..e103240 100644
--- a/libc/kernel/uapi/asm-generic/signal.h
+++ b/libc/kernel/uapi/asm-generic/signal.h
@@ -19,10 +19,10 @@
 #ifndef _UAPI__ASM_GENERIC_SIGNAL_H
 #define _UAPI__ASM_GENERIC_SIGNAL_H
 #include <linux/types.h>
-#define _NSIG 64
+#define _KERNEL__NSIG 64
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define _NSIG_BPW __BITS_PER_LONG
-#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
+#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW)
 #define SIGHUP 1
 #define SIGINT 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -66,9 +66,9 @@
 #define SIGSYS 31
 #define SIGUNUSED 31
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SIGRTMIN 32
-#ifndef SIGRTMAX
-#define SIGRTMAX _NSIG
+#define __SIGRTMIN 32
+#ifndef __SIGRTMAX
+#define __SIGRTMAX _KERNEL__NSIG
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SA_NOCLDSTOP 0x00000001
diff --git a/libc/kernel/uapi/asm-generic/socket.h b/libc/kernel/uapi/asm-generic/socket.h
index 997db00..93daf83 100644
--- a/libc/kernel/uapi/asm-generic/socket.h
+++ b/libc/kernel/uapi/asm-generic/socket.h
@@ -86,4 +86,8 @@
 #define SO_LOCK_FILTER 44
 #define SO_SELECT_ERR_QUEUE 45
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SO_BUSY_POLL 46
+#define SO_MAX_PACING_RATE 47
+#define SO_BPF_EXTENSIONS 48
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-generic/statfs.h b/libc/kernel/uapi/asm-generic/statfs.h
index 860e584..1c8c589 100644
--- a/libc/kernel/uapi/asm-generic/statfs.h
+++ b/libc/kernel/uapi/asm-generic/statfs.h
@@ -22,7 +22,7 @@
 #ifndef __statfs_word
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #if __BITS_PER_LONG == 64
-#define __statfs_word long
+#define __statfs_word __kernel_long_t
 #else
 #define __statfs_word __u32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-generic/unistd.h b/libc/kernel/uapi/asm-generic/unistd.h
index 781941b..becc82d 100644
--- a/libc/kernel/uapi/asm-generic/unistd.h
+++ b/libc/kernel/uapi/asm-generic/unistd.h
@@ -367,150 +367,153 @@
 #define __NR_kcmp 272
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_finit_module 273
+#define __NR_sched_setattr 274
+#define __NR_sched_getattr 275
 #undef __NR_syscalls
-#define __NR_syscalls 274
-#ifdef __ARCH_WANT_SYSCALL_NO_AT
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __NR_syscalls 276
+#ifdef __ARCH_WANT_SYSCALL_NO_AT
 #define __NR_open 1024
 #define __NR_link 1025
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_unlink 1026
 #define __NR_mknod 1027
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_chmod 1028
 #define __NR_chown 1029
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mkdir 1030
 #define __NR_rmdir 1031
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_lchown 1032
 #define __NR_access 1033
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rename 1034
 #define __NR_readlink 1035
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_symlink 1036
 #define __NR_utimes 1037
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR3264_stat 1038
 #define __NR3264_lstat 1039
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #undef __NR_syscalls
 #define __NR_syscalls (__NR3264_lstat+1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #ifdef __ARCH_WANT_SYSCALL_NO_FLAGS
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_pipe 1040
 #define __NR_dup2 1041
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_epoll_create 1042
 #define __NR_inotify_init 1043
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_eventfd 1044
 #define __NR_signalfd 1045
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #undef __NR_syscalls
 #define __NR_syscalls (__NR_signalfd+1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #if (__BITS_PER_LONG == 32 || defined(__SYSCALL_COMPAT)) && defined(__ARCH_WANT_SYSCALL_OFF_T)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sendfile 1046
 #define __NR_ftruncate 1047
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_truncate 1048
 #define __NR_stat 1049
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_lstat 1050
 #define __NR_fstat 1051
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fcntl 1052
 #define __NR_fadvise64 1053
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARCH_WANT_SYS_FADVISE64
 #define __NR_newfstatat 1054
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARCH_WANT_SYS_NEWFSTATAT
 #define __NR_fstatfs 1055
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_statfs 1056
 #define __NR_lseek 1057
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mmap 1058
 #undef __NR_syscalls
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_syscalls (__NR_mmap+1)
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __ARCH_WANT_SYSCALL_DEPRECATED
 #define __NR_alarm 1059
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARCH_WANT_SYS_ALARM
 #define __NR_getpgrp 1060
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARCH_WANT_SYS_GETPGRP
 #define __NR_pause 1061
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARCH_WANT_SYS_PAUSE
 #define __NR_time 1062
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARCH_WANT_SYS_TIME
 #define __ARCH_WANT_COMPAT_SYS_TIME
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_utime 1063
 #define __ARCH_WANT_SYS_UTIME
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_creat 1064
 #define __NR_getdents 1065
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __ARCH_WANT_SYS_GETDENTS
 #define __NR_futimesat 1066
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_select 1067
 #define __ARCH_WANT_SYS_SELECT
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_poll 1068
 #define __NR_epoll_wait 1069
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_ustat 1070
 #define __NR_vfork 1071
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_oldwait4 1072
 #define __NR_recv 1073
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_send 1074
 #define __NR_bdflush 1075
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_umount 1076
 #define __ARCH_WANT_SYS_OLDUMOUNT
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_uselib 1077
 #define __NR__sysctl 1078
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fork 1079
 #undef __NR_syscalls
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_syscalls (__NR_fork+1)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #if __BITS_PER_LONG == 64 && !defined(__SYSCALL_COMPAT)
 #define __NR_fcntl __NR3264_fcntl
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_statfs __NR3264_statfs
 #define __NR_fstatfs __NR3264_fstatfs
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_truncate __NR3264_truncate
 #define __NR_ftruncate __NR3264_ftruncate
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_lseek __NR3264_lseek
 #define __NR_sendfile __NR3264_sendfile
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_newfstatat __NR3264_fstatat
 #define __NR_fstat __NR3264_fstat
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mmap __NR3264_mmap
 #define __NR_fadvise64 __NR3264_fadvise64
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __NR3264_stat
 #define __NR_stat __NR3264_stat
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_lstat __NR3264_lstat
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #else
 #define __NR_fcntl64 __NR3264_fcntl
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_statfs64 __NR3264_statfs
 #define __NR_fstatfs64 __NR3264_fstatfs
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_truncate64 __NR3264_truncate
 #define __NR_ftruncate64 __NR3264_ftruncate
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_llseek __NR3264_lseek
 #define __NR_sendfile64 __NR3264_sendfile
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fstatat64 __NR3264_fstatat
 #define __NR_fstat64 __NR3264_fstat
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mmap2 __NR3264_mmap
 #define __NR_fadvise64_64 __NR3264_fadvise64
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __NR3264_stat
 #define __NR_stat64 __NR3264_stat
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_lstat64 __NR3264_lstat
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-mips/asm/auxvec.h b/libc/kernel/uapi/asm-mips/asm/auxvec.h
index 0c04901..2fa0e6b 100644
--- a/libc/kernel/uapi/asm-mips/asm/auxvec.h
+++ b/libc/kernel/uapi/asm-mips/asm/auxvec.h
@@ -16,6 +16,4 @@
  ***
  ****************************************************************************
  ****************************************************************************/
-#ifndef _ASM_AUXVEC_H
-#define _ASM_AUXVEC_H
-#endif
+#include <asm-generic/auxvec.h>
diff --git a/libc/kernel/uapi/asm-mips/asm/byteorder.h b/libc/kernel/uapi/asm-mips/asm/byteorder.h
index 477c93d..965fd8f 100644
--- a/libc/kernel/uapi/asm-mips/asm/byteorder.h
+++ b/libc/kernel/uapi/asm-mips/asm/byteorder.h
@@ -18,13 +18,6 @@
  ****************************************************************************/
 #ifndef _ASM_BYTEORDER_H
 #define _ASM_BYTEORDER_H
-#ifdef __MIPSEB__
-#include <linux/byteorder/big_endian.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#elif defined(__MIPSEL__)
 #include <linux/byteorder/little_endian.h>
-#else
-#error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
+#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#endif
-#endif
diff --git a/libc/kernel/uapi/asm-mips/asm/fcntl.h b/libc/kernel/uapi/asm-mips/asm/fcntl.h
index 4a9bf5c..02ea3ac 100644
--- a/libc/kernel/uapi/asm-mips/asm/fcntl.h
+++ b/libc/kernel/uapi/asm-mips/asm/fcntl.h
@@ -16,49 +16,53 @@
  ***
  ****************************************************************************
  ****************************************************************************/
-#ifndef _ASM_FCNTL_H
-#define _ASM_FCNTL_H
+#ifndef _UAPI_ASM_FCNTL_H
+#define _UAPI_ASM_FCNTL_H
+#include <asm/sgidefs.h>
 #define O_APPEND 0x0008
-#define O_DSYNC 0x0010
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define O_DSYNC 0x0010
 #define O_NONBLOCK 0x0080
 #define O_CREAT 0x0100
 #define O_TRUNC 0x0200
-#define O_EXCL 0x0400
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define O_EXCL 0x0400
 #define O_NOCTTY 0x0800
 #define FASYNC 0x1000
 #define O_LARGEFILE 0x2000
-#define __O_SYNC 0x4000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __O_SYNC 0x4000
 #define O_SYNC (__O_SYNC|O_DSYNC)
 #define O_DIRECT 0x8000
 #define F_GETLK 14
-#define F_SETLK 6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define F_SETLK 6
 #define F_SETLKW 7
 #define F_SETOWN 24
 #define F_GETOWN 23
-#ifndef __mips64
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifndef __mips64
 #define F_GETLK64 33
 #define F_SETLK64 34
 #define F_SETLKW64 35
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
+#if _MIPS_SIM != _MIPS_SIM_ABI64
 #include <linux/types.h>
 struct flock {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  short l_type;
  short l_whence;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __kernel_off_t l_start;
  __kernel_off_t l_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  long l_sysid;
  __kernel_pid_t l_pid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  long pad[4];
 };
-#define HAVE_ARCH_STRUCT_FLOCK
-#include <asm-generic/fcntl.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HAVE_ARCH_STRUCT_FLOCK
 #endif
+#include <asm-generic/fcntl.h>
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-mips/asm/inst.h b/libc/kernel/uapi/asm-mips/asm/inst.h
index 379286c..c46d09b 100644
--- a/libc/kernel/uapi/asm-mips/asm/inst.h
+++ b/libc/kernel/uapi/asm-mips/asm/inst.h
@@ -97,293 +97,298 @@
 enum cop_op {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  mfc_op = 0x00, dmfc_op = 0x01,
- cfc_op = 0x02, mtc_op = 0x04,
- dmtc_op = 0x05, ctc_op = 0x06,
- bc_op = 0x08, cop_op = 0x10,
+ cfc_op = 0x02, mfhc_op = 0x03,
+ mtc_op = 0x04, dmtc_op = 0x05,
+ ctc_op = 0x06, mthc_op = 0x07,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ bc_op = 0x08, cop_op = 0x10,
  copm_op = 0x18
 };
 enum bcop_op {
- bcf_op, bct_op, bcfl_op, bctl_op
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ bcf_op, bct_op, bcfl_op, bctl_op
 };
 enum cop0_coi_func {
  tlbr_op = 0x01, tlbwi_op = 0x02,
- tlbwr_op = 0x06, tlbp_op = 0x08,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ tlbwr_op = 0x06, tlbp_op = 0x08,
  rfe_op = 0x10, eret_op = 0x18
 };
 enum cop0_com_func {
- tlbr1_op = 0x01, tlbw_op = 0x02,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ tlbr1_op = 0x01, tlbw_op = 0x02,
  tlbp1_op = 0x08, dctr_op = 0x09,
  dctw_op = 0x0a
 };
-enum cop1_fmt {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum cop1_fmt {
  s_fmt, d_fmt, e_fmt, q_fmt,
  w_fmt, l_fmt
 };
-enum cop1_sdw_func {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum cop1_sdw_func {
  fadd_op = 0x00, fsub_op = 0x01,
  fmul_op = 0x02, fdiv_op = 0x03,
  fsqrt_op = 0x04, fabs_op = 0x05,
- fmov_op = 0x06, fneg_op = 0x07,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ fmov_op = 0x06, fneg_op = 0x07,
  froundl_op = 0x08, ftruncl_op = 0x09,
  fceill_op = 0x0a, ffloorl_op = 0x0b,
  fround_op = 0x0c, ftrunc_op = 0x0d,
- fceil_op = 0x0e, ffloor_op = 0x0f,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ fceil_op = 0x0e, ffloor_op = 0x0f,
  fmovc_op = 0x11, fmovz_op = 0x12,
  fmovn_op = 0x13, frecip_op = 0x15,
  frsqrt_op = 0x16, fcvts_op = 0x20,
- fcvtd_op = 0x21, fcvte_op = 0x22,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ fcvtd_op = 0x21, fcvte_op = 0x22,
  fcvtw_op = 0x24, fcvtl_op = 0x25,
  fcmp_op = 0x30
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum cop1x_func {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  lwxc1_op = 0x00, ldxc1_op = 0x01,
- pfetch_op = 0x07, swxc1_op = 0x08,
- sdxc1_op = 0x09, madd_s_op = 0x20,
- madd_d_op = 0x21, madd_e_op = 0x22,
+ swxc1_op = 0x08, sdxc1_op = 0x09,
+ pfetch_op = 0x0f, madd_s_op = 0x20,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ madd_d_op = 0x21, madd_e_op = 0x22,
  msub_s_op = 0x28, msub_d_op = 0x29,
  msub_e_op = 0x2a, nmadd_s_op = 0x30,
  nmadd_d_op = 0x31, nmadd_e_op = 0x32,
- nmsub_s_op = 0x38, nmsub_d_op = 0x39,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ nmsub_s_op = 0x38, nmsub_d_op = 0x39,
  nmsub_e_op = 0x3a
 };
 enum mad_func {
- madd_fp_op = 0x08, msub_fp_op = 0x0a,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ madd_fp_op = 0x08, msub_fp_op = 0x0a,
  nmadd_fp_op = 0x0c, nmsub_fp_op = 0x0e
 };
 enum lx_func {
- lwx_op = 0x00,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ lwx_op = 0x00,
  lhx_op = 0x04,
  lbux_op = 0x06,
  ldx_op = 0x08,
- lwux_op = 0x10,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ lwux_op = 0x10,
  lhux_op = 0x14,
  lbx_op = 0x16,
 };
-enum mm_major_op {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum mm_major_op {
  mm_pool32a_op, mm_pool16a_op, mm_lbu16_op, mm_move16_op,
  mm_addi32_op, mm_lbu32_op, mm_sb32_op, mm_lb32_op,
  mm_pool32b_op, mm_pool16b_op, mm_lhu16_op, mm_andi16_op,
- mm_addiu32_op, mm_lhu32_op, mm_sh32_op, mm_lh32_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_addiu32_op, mm_lhu32_op, mm_sh32_op, mm_lh32_op,
  mm_pool32i_op, mm_pool16c_op, mm_lwsp16_op, mm_pool16d_op,
  mm_ori32_op, mm_pool32f_op, mm_reserved1_op, mm_reserved2_op,
  mm_pool32c_op, mm_lwgp16_op, mm_lw16_op, mm_pool16e_op,
- mm_xori32_op, mm_jals32_op, mm_addiupc_op, mm_reserved3_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_xori32_op, mm_jals32_op, mm_addiupc_op, mm_reserved3_op,
  mm_reserved4_op, mm_pool16f_op, mm_sb16_op, mm_beqz16_op,
  mm_slti32_op, mm_beq32_op, mm_swc132_op, mm_lwc132_op,
  mm_reserved5_op, mm_reserved6_op, mm_sh16_op, mm_bnez16_op,
- mm_sltiu32_op, mm_bne32_op, mm_sdc132_op, mm_ldc132_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_sltiu32_op, mm_bne32_op, mm_sdc132_op, mm_ldc132_op,
  mm_reserved7_op, mm_reserved8_op, mm_swsp16_op, mm_b16_op,
  mm_andi32_op, mm_j32_op, mm_sd32_op, mm_ld32_op,
  mm_reserved11_op, mm_reserved12_op, mm_sw16_op, mm_li16_op,
- mm_jalx32_op, mm_jal32_op, mm_sw32_op, mm_lw32_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_jalx32_op, mm_jal32_op, mm_sw32_op, mm_lw32_op,
 };
 enum mm_32i_minor_op {
  mm_bltz_op, mm_bltzal_op, mm_bgez_op, mm_bgezal_op,
- mm_blez_op, mm_bnezc_op, mm_bgtz_op, mm_beqzc_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_blez_op, mm_bnezc_op, mm_bgtz_op, mm_beqzc_op,
  mm_tlti_op, mm_tgei_op, mm_tltiu_op, mm_tgeiu_op,
  mm_tnei_op, mm_lui_op, mm_teqi_op, mm_reserved13_op,
  mm_synci_op, mm_bltzals_op, mm_reserved14_op, mm_bgezals_op,
- mm_bc2f_op, mm_bc2t_op, mm_reserved15_op, mm_reserved16_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_bc2f_op, mm_bc2t_op, mm_reserved15_op, mm_reserved16_op,
  mm_reserved17_op, mm_reserved18_op, mm_bposge64_op, mm_bposge32_op,
  mm_bc1f_op, mm_bc1t_op, mm_reserved19_op, mm_reserved20_op,
  mm_bc1any2f_op, mm_bc1any2t_op, mm_bc1any4f_op, mm_bc1any4t_op,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum mm_32a_minor_op {
  mm_sll32_op = 0x000,
  mm_ins_op = 0x00c,
- mm_ext_op = 0x02c,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_ext_op = 0x02c,
  mm_pool32axf_op = 0x03c,
  mm_srl32_op = 0x040,
  mm_sra_op = 0x080,
- mm_rotr_op = 0x0c0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_rotr_op = 0x0c0,
  mm_lwxs_op = 0x118,
  mm_addu32_op = 0x150,
  mm_subu32_op = 0x1d0,
- mm_and_op = 0x250,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_and_op = 0x250,
  mm_or32_op = 0x290,
  mm_xor32_op = 0x310,
 };
-enum mm_32b_func {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum mm_32b_func {
  mm_lwc2_func = 0x0,
  mm_lwp_func = 0x1,
  mm_ldc2_func = 0x2,
- mm_ldp_func = 0x4,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_ldp_func = 0x4,
  mm_lwm32_func = 0x5,
  mm_cache_func = 0x6,
  mm_ldm_func = 0x7,
- mm_swc2_func = 0x8,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_swc2_func = 0x8,
  mm_swp_func = 0x9,
  mm_sdc2_func = 0xa,
  mm_sdp_func = 0xc,
- mm_swm32_func = 0xd,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_swm32_func = 0xd,
  mm_sdm_func = 0xf,
 };
 enum mm_32c_func {
- mm_pref_func = 0x2,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_pref_func = 0x2,
  mm_ll_func = 0x3,
  mm_swr_func = 0x9,
  mm_sc_func = 0xb,
- mm_lwu_func = 0xe,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_lwu_func = 0xe,
 };
 enum mm_32axf_minor_op {
  mm_mfc0_op = 0x003,
- mm_mtc0_op = 0x00b,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_mtc0_op = 0x00b,
  mm_tlbp_op = 0x00d,
  mm_jalr_op = 0x03c,
  mm_tlbr_op = 0x04d,
- mm_jalrhb_op = 0x07c,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_jalrhb_op = 0x07c,
  mm_tlbwi_op = 0x08d,
  mm_tlbwr_op = 0x0cd,
  mm_jalrs_op = 0x13c,
- mm_jalrshb_op = 0x17c,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_jalrshb_op = 0x17c,
  mm_syscall_op = 0x22d,
  mm_eret_op = 0x3cd,
 };
-enum mm_32f_minor_op {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum mm_32f_minor_op {
  mm_32f_00_op = 0x00,
  mm_32f_01_op = 0x01,
  mm_32f_02_op = 0x02,
- mm_32f_10_op = 0x08,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_32f_10_op = 0x08,
  mm_32f_11_op = 0x09,
  mm_32f_12_op = 0x0a,
  mm_32f_20_op = 0x10,
- mm_32f_30_op = 0x18,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_32f_30_op = 0x18,
  mm_32f_40_op = 0x20,
  mm_32f_41_op = 0x21,
  mm_32f_42_op = 0x22,
- mm_32f_50_op = 0x28,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_32f_50_op = 0x28,
  mm_32f_51_op = 0x29,
  mm_32f_52_op = 0x2a,
  mm_32f_60_op = 0x30,
- mm_32f_70_op = 0x38,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_32f_70_op = 0x38,
  mm_32f_73_op = 0x3b,
  mm_32f_74_op = 0x3c,
 };
-enum mm_32f_10_minor_op {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum mm_32f_10_minor_op {
  mm_lwxc1_op = 0x1,
  mm_swxc1_op,
  mm_ldxc1_op,
- mm_sdxc1_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_sdxc1_op,
  mm_luxc1_op,
  mm_suxc1_op,
 };
-enum mm_32f_func {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum mm_32f_func {
  mm_lwxc1_func = 0x048,
  mm_swxc1_func = 0x088,
  mm_ldxc1_func = 0x0c8,
- mm_sdxc1_func = 0x108,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_sdxc1_func = 0x108,
 };
 enum mm_32f_40_minor_op {
  mm_fmovf_op,
- mm_fmovt_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_fmovt_op,
 };
 enum mm_32f_60_minor_op {
  mm_fadd_op,
- mm_fsub_op,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_fsub_op,
  mm_fmul_op,
  mm_fdiv_op,
 };
-enum mm_32f_70_minor_op {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum mm_32f_70_minor_op {
  mm_fmovn_op,
  mm_fmovz_op,
 };
-enum mm_32f_73_minor_op {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum mm_32f_73_minor_op {
  mm_fmov0_op = 0x01,
  mm_fcvtl_op = 0x04,
  mm_movf0_op = 0x05,
- mm_frsqrt_op = 0x08,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_frsqrt_op = 0x08,
  mm_ffloorl_op = 0x0c,
  mm_fabs0_op = 0x0d,
  mm_fcvtw_op = 0x24,
- mm_movt0_op = 0x25,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_movt0_op = 0x25,
  mm_fsqrt_op = 0x28,
  mm_ffloorw_op = 0x2c,
  mm_fneg0_op = 0x2d,
- mm_cfc1_op = 0x40,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_cfc1_op = 0x40,
  mm_frecip_op = 0x48,
  mm_fceill_op = 0x4c,
  mm_fcvtd0_op = 0x4d,
- mm_ctc1_op = 0x60,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_ctc1_op = 0x60,
  mm_fceilw_op = 0x6c,
  mm_fcvts0_op = 0x6d,
  mm_mfc1_op = 0x80,
- mm_fmov1_op = 0x81,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_fmov1_op = 0x81,
  mm_movf1_op = 0x85,
  mm_ftruncl_op = 0x8c,
  mm_fabs1_op = 0x8d,
- mm_mtc1_op = 0xa0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_mtc1_op = 0xa0,
  mm_movt1_op = 0xa5,
  mm_ftruncw_op = 0xac,
  mm_fneg1_op = 0xad,
- mm_froundl_op = 0xcc,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mm_mfhc1_op = 0xc0,
+ mm_froundl_op = 0xcc,
  mm_fcvtd1_op = 0xcd,
+ mm_mthc1_op = 0xe0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  mm_froundw_op = 0xec,
  mm_fcvts1_op = 0xed,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum mm_16c_minor_op {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  mm_lwm16_op = 0x04,
  mm_swm16_op = 0x05,
- mm_jr16_op = 0x18,
+ mm_jr16_op = 0x0c,
+ mm_jrc_op = 0x0d,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- mm_jrc_op = 0x1a,
- mm_jalr16_op = 0x1c,
- mm_jalrs16_op = 0x1e,
+ mm_jalr16_op = 0x0e,
+ mm_jalrs16_op = 0x0f,
+ mm_jraddiusp_op = 0x18,
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum mm_16d_minor_op {
@@ -434,453 +439,446 @@
  MIPS16e_swrasp_func = 02,
 };
 #define MM_NOP16 0x0c00
-#ifdef __MIPSEB__
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define BITFIELD_FIELD(field, more)   field;   more
-#elif defined(__MIPSEL__)
 #define BITFIELD_FIELD(field, more)   more   field;
-#else
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#error "MIPS but neither __MIPSEL__ nor __MIPSEB__?"
-#endif
 struct j_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int target : 26,
  ;))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct i_format {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int rs : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rt : 5,
  BITFIELD_FIELD(signed int simmediate : 16,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct u_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rs : 5,
  BITFIELD_FIELD(unsigned int rt : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int uimmediate : 16,
  ;))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct c_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int rs : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int c_op : 3,
  BITFIELD_FIELD(unsigned int cache : 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int simmediate : 16,
  ;)))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct r_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int rs : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rt : 5,
  BITFIELD_FIELD(unsigned int rd : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int re : 5,
  BITFIELD_FIELD(unsigned int func : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct p_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rs : 5,
  BITFIELD_FIELD(unsigned int rt : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rd : 5,
  BITFIELD_FIELD(unsigned int re : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;))))))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct f_format {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fmt : 4,
  BITFIELD_FIELD(unsigned int rt : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rd : 5,
  BITFIELD_FIELD(unsigned int re : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;)))))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ma_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int fr : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int ft : 5,
  BITFIELD_FIELD(unsigned int fs : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fd : 5,
  BITFIELD_FIELD(unsigned int func : 4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fmt : 2,
  ;)))))))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct b_format {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int code : 20,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;)))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ps_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int rs : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int ft : 5,
  BITFIELD_FIELD(unsigned int fs : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fd : 5,
  BITFIELD_FIELD(unsigned int func : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int sel : 4,
  BITFIELD_FIELD(unsigned int fmt : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int vt : 5,
  BITFIELD_FIELD(unsigned int vs : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int vd : 5,
  BITFIELD_FIELD(unsigned int func : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;)))))))
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct fb_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int bc : 5,
  BITFIELD_FIELD(unsigned int cc : 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int flag : 2,
  BITFIELD_FIELD(signed int simmediate : 16,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;)))))
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct fp0_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fmt : 5,
  BITFIELD_FIELD(unsigned int ft : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fs : 5,
  BITFIELD_FIELD(unsigned int fd : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;))))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_fp0_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int ft : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fs : 5,
  BITFIELD_FIELD(unsigned int fd : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fmt : 3,
  BITFIELD_FIELD(unsigned int op : 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;)))))))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct fp1_format {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int op : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rt : 5,
  BITFIELD_FIELD(unsigned int fs : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fd : 5,
  BITFIELD_FIELD(unsigned int func : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))))
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct mm_fp1_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rt : 5,
  BITFIELD_FIELD(unsigned int fs : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fmt : 2,
  BITFIELD_FIELD(unsigned int op : 8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;))))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_fp2_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int fd : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fs : 5,
  BITFIELD_FIELD(unsigned int cc : 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int zero : 2,
  BITFIELD_FIELD(unsigned int fmt : 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int op : 3,
  BITFIELD_FIELD(unsigned int func : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))))))
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct mm_fp3_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rt : 5,
  BITFIELD_FIELD(unsigned int fs : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fmt : 3,
  BITFIELD_FIELD(unsigned int op : 7,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;))))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_fp4_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int rt : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fs : 5,
  BITFIELD_FIELD(unsigned int cc : 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fmt : 3,
  BITFIELD_FIELD(unsigned int cond : 4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;)))))))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_fp5_format {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int index : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int base : 5,
  BITFIELD_FIELD(unsigned int fd : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int op : 5,
  BITFIELD_FIELD(unsigned int func : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))))
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct fp6_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fr : 5,
  BITFIELD_FIELD(unsigned int ft : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fs : 5,
  BITFIELD_FIELD(unsigned int fd : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 6,
  ;))))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_fp6_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int ft : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fs : 5,
  BITFIELD_FIELD(unsigned int fd : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int fr : 5,
  BITFIELD_FIELD(unsigned int func : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct mm_i_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rt : 5,
  BITFIELD_FIELD(unsigned int rs : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(signed int simmediate : 16,
  ;))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_m_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int rd : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int base : 5,
  BITFIELD_FIELD(unsigned int func : 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(signed int simmediate : 12,
  ;)))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_x_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int index : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int base : 5,
  BITFIELD_FIELD(unsigned int rd : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 11,
  ;)))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_b0_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(signed int simmediate : 10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int : 16,
  ;)))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm_b1_format {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int rs : 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(signed int simmediate : 7,
  BITFIELD_FIELD(unsigned int : 16,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct mm16_m_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 4,
  BITFIELD_FIELD(unsigned int rlist : 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int imm : 4,
  BITFIELD_FIELD(unsigned int : 16,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;)))))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct mm16_rb_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rt : 3,
  BITFIELD_FIELD(unsigned int base : 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(signed int simmediate : 4,
  BITFIELD_FIELD(unsigned int : 16,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;)))))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct mm16_r3_format {
  BITFIELD_FIELD(unsigned int opcode : 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rt : 3,
  BITFIELD_FIELD(signed int simmediate : 7,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int : 16,
  ;))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct mm16_r5_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 6,
  BITFIELD_FIELD(unsigned int rt : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(signed int simmediate : 5,
  BITFIELD_FIELD(unsigned int : 16,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct m16e_rr {
  BITFIELD_FIELD(unsigned int opcode : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int rx : 3,
  BITFIELD_FIELD(unsigned int nd : 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int l : 1,
  BITFIELD_FIELD(unsigned int ra : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 5,
  ;))))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct m16e_jal {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 5,
  BITFIELD_FIELD(unsigned int x : 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int imm20_16 : 5,
  BITFIELD_FIELD(signed int imm25_21 : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct m16e_i64 {
  BITFIELD_FIELD(unsigned int opcode : 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 3,
  BITFIELD_FIELD(unsigned int imm : 8,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;)))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct m16e_ri64 {
  BITFIELD_FIELD(unsigned int opcode : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 3,
  BITFIELD_FIELD(unsigned int ry : 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int imm : 5,
  ;))))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct m16e_ri {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 5,
  BITFIELD_FIELD(unsigned int rx : 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int imm : 8,
  ;)))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct m16e_rri {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int opcode : 5,
  BITFIELD_FIELD(unsigned int rx : 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int ry : 3,
  BITFIELD_FIELD(unsigned int imm : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;))))
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct m16e_i8 {
  BITFIELD_FIELD(unsigned int opcode : 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BITFIELD_FIELD(unsigned int func : 3,
  BITFIELD_FIELD(unsigned int imm : 8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ;)))
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 union mips_instruction {
  unsigned int word;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned short halfword[2];
  unsigned char byte[4];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct j_format j_format;
  struct i_format i_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct u_format u_format;
  struct c_format c_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct r_format r_format;
  struct p_format p_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct f_format f_format;
  struct ma_format ma_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct b_format b_format;
  struct ps_format ps_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v_format v_format;
  struct fb_format fb_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct fp0_format fp0_format;
  struct mm_fp0_format mm_fp0_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct fp1_format fp1_format;
  struct mm_fp1_format mm_fp1_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct mm_fp2_format mm_fp2_format;
  struct mm_fp3_format mm_fp3_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct mm_fp4_format mm_fp4_format;
  struct mm_fp5_format mm_fp5_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct fp6_format fp6_format;
  struct mm_fp6_format mm_fp6_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct mm_i_format mm_i_format;
  struct mm_m_format mm_m_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct mm_x_format mm_x_format;
  struct mm_b0_format mm_b0_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct mm_b1_format mm_b1_format;
  struct mm16_m_format mm16_m_format ;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct mm16_rb_format mm16_rb_format;
  struct mm16_r3_format mm16_r3_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct mm16_r5_format mm16_r5_format;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 union mips16e_instruction {
  unsigned int full : 16;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct m16e_rr rr;
  struct m16e_jal jal;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct m16e_i64 i64;
  struct m16e_ri64 ri64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct m16e_ri ri;
  struct m16e_rri rri;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct m16e_i8 i8;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-mips/asm/msgbuf.h b/libc/kernel/uapi/asm-mips/asm/msgbuf.h
index d81da73..efae148 100644
--- a/libc/kernel/uapi/asm-mips/asm/msgbuf.h
+++ b/libc/kernel/uapi/asm-mips/asm/msgbuf.h
@@ -21,21 +21,29 @@
 struct msqid64_ds {
  struct ipc64_perm msg_perm;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long __unused1;
  __kernel_time_t msg_stime;
- unsigned long __unused2;
- __kernel_time_t msg_rtime;
+#ifndef __mips64
+ unsigned long __unused1;
+#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long __unused3;
+ __kernel_time_t msg_rtime;
+#ifndef __mips64
+ unsigned long __unused2;
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __kernel_time_t msg_ctime;
+#ifndef __mips64
+ unsigned long __unused3;
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long msg_cbytes;
  unsigned long msg_qnum;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long msg_qbytes;
  __kernel_pid_t msg_lspid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __kernel_pid_t msg_lrpid;
  unsigned long __unused4;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long __unused5;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-mips/asm/resource.h b/libc/kernel/uapi/asm-mips/asm/resource.h
index 8761697..728a519 100644
--- a/libc/kernel/uapi/asm-mips/asm/resource.h
+++ b/libc/kernel/uapi/asm-mips/asm/resource.h
@@ -24,7 +24,10 @@
 #define RLIMIT_RSS 7
 #define RLIMIT_NPROC 8
 #define RLIMIT_MEMLOCK 9
-#define RLIM_INFINITY 0x7fffffffUL
+#ifndef __mips64
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define RLIM_INFINITY 0x7fffffffUL
+#endif
 #include <asm-generic/resource.h>
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-mips/asm/siginfo.h b/libc/kernel/uapi/asm-mips/asm/siginfo.h
index 4a085f8..599c875 100644
--- a/libc/kernel/uapi/asm-mips/asm/siginfo.h
+++ b/libc/kernel/uapi/asm-mips/asm/siginfo.h
@@ -24,67 +24,82 @@
 #define HAVE_ARCH_SIGINFO_T
 #define HAVE_ARCH_COPY_SIGINFO
 struct siginfo;
-#define __ARCH_SI_PREAMBLE_SIZE (3 * sizeof(int))
+#if _MIPS_SZLONG == 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __ARCH_SI_PREAMBLE_SIZE (3 * sizeof(int))
+#elif _MIPS_SZLONG == 64
+#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
+#else
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#error _MIPS_SZLONG neither 32 nor 64
+#endif
+#define __ARCH_SIGSYS
 #include <asm-generic/siginfo.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef struct siginfo {
  int si_signo;
  int si_code;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int si_errno;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int __pad0[SI_MAX_SIZE / sizeof(int) - SI_PAD_SIZE - 3];
  union {
  int _pad[SI_PAD_SIZE];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  pid_t _pid;
  __ARCH_SI_UID_T _uid;
  } _kill;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  timer_t _tid;
  int _overrun;
  char _pad[sizeof( __ARCH_SI_UID_T) - sizeof(int)];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  sigval_t _sigval;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int _sys_private;
  } _timer;
  struct {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  pid_t _pid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __ARCH_SI_UID_T _uid;
  sigval_t _sigval;
  } _rt;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  pid_t _pid;
  __ARCH_SI_UID_T _uid;
  int _status;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  clock_t _utime;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  clock_t _stime;
  } _sigchld;
  struct {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  pid_t _pid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  clock_t _utime;
  int _status;
  clock_t _stime;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } _irix_sigchld;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  void __user *_addr;
 #ifdef __ARCH_SI_TRAPNO
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int _trapno;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
  short _addr_lsb;
  } _sigfault;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __ARCH_SI_BAND_T _band;
  int _fd;
  } _sigpoll;
+ struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ void __user *_call_addr;
+ int _syscall;
+ unsigned int _arch;
+ } _sigsys;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } _sifields;
 } siginfo_t;
diff --git a/libc/kernel/uapi/asm-mips/asm/signal.h b/libc/kernel/uapi/asm-mips/asm/signal.h
index 771e31a..b774a66 100644
--- a/libc/kernel/uapi/asm-mips/asm/signal.h
+++ b/libc/kernel/uapi/asm-mips/asm/signal.h
@@ -19,10 +19,10 @@
 #ifndef _UAPI_ASM_SIGNAL_H
 #define _UAPI_ASM_SIGNAL_H
 #include <linux/types.h>
-#define _NSIG 128
+#define _KERNEL__NSIG 128
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define _NSIG_BPW (sizeof(unsigned long) * 8)
-#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
+#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW)
 typedef struct {
  unsigned long sig[_NSIG_WORDS];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -71,8 +71,8 @@
 #define SIGXCPU 30
 #define SIGXFSZ 31
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SIGRTMIN 32
-#define SIGRTMAX _NSIG
+#define __SIGRTMIN 32
+#define __SIGRTMAX _KERNEL__NSIG
 #define SA_ONSTACK 0x08000000
 #define SA_RESETHAND 0x80000000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-mips/asm/socket.h b/libc/kernel/uapi/asm-mips/asm/socket.h
index e65f226..38e4e63 100644
--- a/libc/kernel/uapi/asm-mips/asm/socket.h
+++ b/libc/kernel/uapi/asm-mips/asm/socket.h
@@ -84,5 +84,8 @@
 #define SO_NOFCS 43
 #define SO_LOCK_FILTER 44
 #define SO_SELECT_ERR_QUEUE 45
-#endif
+#define SO_BUSY_POLL 46
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SO_MAX_PACING_RATE 47
+#define SO_BPF_EXTENSIONS 48
+#endif
diff --git a/libc/kernel/uapi/asm-mips/asm/swab.h b/libc/kernel/uapi/asm-mips/asm/swab.h
index d188324..41660d0 100644
--- a/libc/kernel/uapi/asm-mips/asm/swab.h
+++ b/libc/kernel/uapi/asm-mips/asm/swab.h
@@ -22,4 +22,13 @@
 #include <linux/types.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __SWAB_64_THRU_32__
+#if defined(__mips_isa_rev) && __mips_isa_rev >= 2
+#define __arch_swab16 __arch_swab16
+#define __arch_swab32 __arch_swab32
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifdef __mips64
+#define __arch_swab64 __arch_swab64
+#endif
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-mips/asm/ucontext.h b/libc/kernel/uapi/asm-mips/asm/ucontext.h
new file mode 100644
index 0000000..aa4d67d
--- /dev/null
+++ b/libc/kernel/uapi/asm-mips/asm/ucontext.h
@@ -0,0 +1,19 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#include <asm-generic/ucontext.h>
diff --git a/libc/kernel/uapi/asm-mips/asm/unistd.h b/libc/kernel/uapi/asm-mips/asm/unistd.h
index 0cdb637..37c3da1 100644
--- a/libc/kernel/uapi/asm-mips/asm/unistd.h
+++ b/libc/kernel/uapi/asm-mips/asm/unistd.h
@@ -457,403 +457,408 @@
 #define __NR_kcmp (__NR_Linux + 347)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_finit_module (__NR_Linux + 348)
-#define __NR_Linux_syscalls 348
+#define __NR_sched_setattr (__NR_Linux + 349)
+#define __NR_sched_getattr (__NR_Linux + 350)
+#define __NR_Linux_syscalls 350
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #define __NR_O32_Linux 4000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define __NR_O32_Linux_syscalls 348
+#define __NR_O32_Linux_syscalls 350
 #if _MIPS_SIM == _MIPS_SIM_ABI64
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_Linux 5000
 #define __NR_read (__NR_Linux + 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_write (__NR_Linux + 1)
 #define __NR_open (__NR_Linux + 2)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_close (__NR_Linux + 3)
 #define __NR_stat (__NR_Linux + 4)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fstat (__NR_Linux + 5)
 #define __NR_lstat (__NR_Linux + 6)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_poll (__NR_Linux + 7)
 #define __NR_lseek (__NR_Linux + 8)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mmap (__NR_Linux + 9)
 #define __NR_mprotect (__NR_Linux + 10)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_munmap (__NR_Linux + 11)
 #define __NR_brk (__NR_Linux + 12)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rt_sigaction (__NR_Linux + 13)
 #define __NR_rt_sigprocmask (__NR_Linux + 14)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_ioctl (__NR_Linux + 15)
 #define __NR_pread64 (__NR_Linux + 16)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_pwrite64 (__NR_Linux + 17)
 #define __NR_readv (__NR_Linux + 18)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_writev (__NR_Linux + 19)
 #define __NR_access (__NR_Linux + 20)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_pipe (__NR_Linux + 21)
 #define __NR__newselect (__NR_Linux + 22)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sched_yield (__NR_Linux + 23)
 #define __NR_mremap (__NR_Linux + 24)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_msync (__NR_Linux + 25)
 #define __NR_mincore (__NR_Linux + 26)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_madvise (__NR_Linux + 27)
 #define __NR_shmget (__NR_Linux + 28)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_shmat (__NR_Linux + 29)
 #define __NR_shmctl (__NR_Linux + 30)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_dup (__NR_Linux + 31)
 #define __NR_dup2 (__NR_Linux + 32)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_pause (__NR_Linux + 33)
 #define __NR_nanosleep (__NR_Linux + 34)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getitimer (__NR_Linux + 35)
 #define __NR_setitimer (__NR_Linux + 36)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_alarm (__NR_Linux + 37)
 #define __NR_getpid (__NR_Linux + 38)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sendfile (__NR_Linux + 39)
 #define __NR_socket (__NR_Linux + 40)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_connect (__NR_Linux + 41)
 #define __NR_accept (__NR_Linux + 42)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sendto (__NR_Linux + 43)
 #define __NR_recvfrom (__NR_Linux + 44)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sendmsg (__NR_Linux + 45)
 #define __NR_recvmsg (__NR_Linux + 46)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_shutdown (__NR_Linux + 47)
 #define __NR_bind (__NR_Linux + 48)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_listen (__NR_Linux + 49)
 #define __NR_getsockname (__NR_Linux + 50)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getpeername (__NR_Linux + 51)
 #define __NR_socketpair (__NR_Linux + 52)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_setsockopt (__NR_Linux + 53)
 #define __NR_getsockopt (__NR_Linux + 54)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_clone (__NR_Linux + 55)
 #define __NR_fork (__NR_Linux + 56)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_execve (__NR_Linux + 57)
 #define __NR_exit (__NR_Linux + 58)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_wait4 (__NR_Linux + 59)
 #define __NR_kill (__NR_Linux + 60)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_uname (__NR_Linux + 61)
 #define __NR_semget (__NR_Linux + 62)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_semop (__NR_Linux + 63)
 #define __NR_semctl (__NR_Linux + 64)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_shmdt (__NR_Linux + 65)
 #define __NR_msgget (__NR_Linux + 66)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_msgsnd (__NR_Linux + 67)
 #define __NR_msgrcv (__NR_Linux + 68)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_msgctl (__NR_Linux + 69)
 #define __NR_fcntl (__NR_Linux + 70)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_flock (__NR_Linux + 71)
 #define __NR_fsync (__NR_Linux + 72)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fdatasync (__NR_Linux + 73)
 #define __NR_truncate (__NR_Linux + 74)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_ftruncate (__NR_Linux + 75)
 #define __NR_getdents (__NR_Linux + 76)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getcwd (__NR_Linux + 77)
 #define __NR_chdir (__NR_Linux + 78)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fchdir (__NR_Linux + 79)
 #define __NR_rename (__NR_Linux + 80)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mkdir (__NR_Linux + 81)
 #define __NR_rmdir (__NR_Linux + 82)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_creat (__NR_Linux + 83)
 #define __NR_link (__NR_Linux + 84)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_unlink (__NR_Linux + 85)
 #define __NR_symlink (__NR_Linux + 86)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_readlink (__NR_Linux + 87)
 #define __NR_chmod (__NR_Linux + 88)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fchmod (__NR_Linux + 89)
 #define __NR_chown (__NR_Linux + 90)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fchown (__NR_Linux + 91)
 #define __NR_lchown (__NR_Linux + 92)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_umask (__NR_Linux + 93)
 #define __NR_gettimeofday (__NR_Linux + 94)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getrlimit (__NR_Linux + 95)
 #define __NR_getrusage (__NR_Linux + 96)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sysinfo (__NR_Linux + 97)
 #define __NR_times (__NR_Linux + 98)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_ptrace (__NR_Linux + 99)
 #define __NR_getuid (__NR_Linux + 100)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_syslog (__NR_Linux + 101)
 #define __NR_getgid (__NR_Linux + 102)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_setuid (__NR_Linux + 103)
 #define __NR_setgid (__NR_Linux + 104)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_geteuid (__NR_Linux + 105)
 #define __NR_getegid (__NR_Linux + 106)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_setpgid (__NR_Linux + 107)
 #define __NR_getppid (__NR_Linux + 108)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getpgrp (__NR_Linux + 109)
 #define __NR_setsid (__NR_Linux + 110)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_setreuid (__NR_Linux + 111)
 #define __NR_setregid (__NR_Linux + 112)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getgroups (__NR_Linux + 113)
 #define __NR_setgroups (__NR_Linux + 114)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_setresuid (__NR_Linux + 115)
 #define __NR_getresuid (__NR_Linux + 116)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_setresgid (__NR_Linux + 117)
 #define __NR_getresgid (__NR_Linux + 118)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getpgid (__NR_Linux + 119)
 #define __NR_setfsuid (__NR_Linux + 120)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_setfsgid (__NR_Linux + 121)
 #define __NR_getsid (__NR_Linux + 122)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_capget (__NR_Linux + 123)
 #define __NR_capset (__NR_Linux + 124)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rt_sigpending (__NR_Linux + 125)
 #define __NR_rt_sigtimedwait (__NR_Linux + 126)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rt_sigqueueinfo (__NR_Linux + 127)
 #define __NR_rt_sigsuspend (__NR_Linux + 128)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sigaltstack (__NR_Linux + 129)
 #define __NR_utime (__NR_Linux + 130)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mknod (__NR_Linux + 131)
 #define __NR_personality (__NR_Linux + 132)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_ustat (__NR_Linux + 133)
 #define __NR_statfs (__NR_Linux + 134)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fstatfs (__NR_Linux + 135)
 #define __NR_sysfs (__NR_Linux + 136)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getpriority (__NR_Linux + 137)
 #define __NR_setpriority (__NR_Linux + 138)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sched_setparam (__NR_Linux + 139)
 #define __NR_sched_getparam (__NR_Linux + 140)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sched_setscheduler (__NR_Linux + 141)
 #define __NR_sched_getscheduler (__NR_Linux + 142)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sched_get_priority_max (__NR_Linux + 143)
 #define __NR_sched_get_priority_min (__NR_Linux + 144)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sched_rr_get_interval (__NR_Linux + 145)
 #define __NR_mlock (__NR_Linux + 146)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_munlock (__NR_Linux + 147)
 #define __NR_mlockall (__NR_Linux + 148)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_munlockall (__NR_Linux + 149)
 #define __NR_vhangup (__NR_Linux + 150)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_pivot_root (__NR_Linux + 151)
 #define __NR__sysctl (__NR_Linux + 152)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_prctl (__NR_Linux + 153)
 #define __NR_adjtimex (__NR_Linux + 154)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_setrlimit (__NR_Linux + 155)
 #define __NR_chroot (__NR_Linux + 156)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sync (__NR_Linux + 157)
 #define __NR_acct (__NR_Linux + 158)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_settimeofday (__NR_Linux + 159)
 #define __NR_mount (__NR_Linux + 160)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_umount2 (__NR_Linux + 161)
 #define __NR_swapon (__NR_Linux + 162)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_swapoff (__NR_Linux + 163)
 #define __NR_reboot (__NR_Linux + 164)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sethostname (__NR_Linux + 165)
 #define __NR_setdomainname (__NR_Linux + 166)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_create_module (__NR_Linux + 167)
 #define __NR_init_module (__NR_Linux + 168)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_delete_module (__NR_Linux + 169)
 #define __NR_get_kernel_syms (__NR_Linux + 170)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_query_module (__NR_Linux + 171)
 #define __NR_quotactl (__NR_Linux + 172)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_nfsservctl (__NR_Linux + 173)
 #define __NR_getpmsg (__NR_Linux + 174)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_putpmsg (__NR_Linux + 175)
 #define __NR_afs_syscall (__NR_Linux + 176)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_reserved177 (__NR_Linux + 177)
 #define __NR_gettid (__NR_Linux + 178)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_readahead (__NR_Linux + 179)
 #define __NR_setxattr (__NR_Linux + 180)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_lsetxattr (__NR_Linux + 181)
 #define __NR_fsetxattr (__NR_Linux + 182)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getxattr (__NR_Linux + 183)
 #define __NR_lgetxattr (__NR_Linux + 184)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fgetxattr (__NR_Linux + 185)
 #define __NR_listxattr (__NR_Linux + 186)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_llistxattr (__NR_Linux + 187)
 #define __NR_flistxattr (__NR_Linux + 188)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_removexattr (__NR_Linux + 189)
 #define __NR_lremovexattr (__NR_Linux + 190)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fremovexattr (__NR_Linux + 191)
 #define __NR_tkill (__NR_Linux + 192)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_reserved193 (__NR_Linux + 193)
 #define __NR_futex (__NR_Linux + 194)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sched_setaffinity (__NR_Linux + 195)
 #define __NR_sched_getaffinity (__NR_Linux + 196)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_cacheflush (__NR_Linux + 197)
 #define __NR_cachectl (__NR_Linux + 198)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sysmips (__NR_Linux + 199)
 #define __NR_io_setup (__NR_Linux + 200)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_io_destroy (__NR_Linux + 201)
 #define __NR_io_getevents (__NR_Linux + 202)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_io_submit (__NR_Linux + 203)
 #define __NR_io_cancel (__NR_Linux + 204)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_exit_group (__NR_Linux + 205)
 #define __NR_lookup_dcookie (__NR_Linux + 206)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_epoll_create (__NR_Linux + 207)
 #define __NR_epoll_ctl (__NR_Linux + 208)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_epoll_wait (__NR_Linux + 209)
 #define __NR_remap_file_pages (__NR_Linux + 210)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rt_sigreturn (__NR_Linux + 211)
 #define __NR_set_tid_address (__NR_Linux + 212)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_restart_syscall (__NR_Linux + 213)
 #define __NR_semtimedop (__NR_Linux + 214)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fadvise64 (__NR_Linux + 215)
 #define __NR_timer_create (__NR_Linux + 216)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_timer_settime (__NR_Linux + 217)
 #define __NR_timer_gettime (__NR_Linux + 218)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_timer_getoverrun (__NR_Linux + 219)
 #define __NR_timer_delete (__NR_Linux + 220)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_clock_settime (__NR_Linux + 221)
 #define __NR_clock_gettime (__NR_Linux + 222)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_clock_getres (__NR_Linux + 223)
 #define __NR_clock_nanosleep (__NR_Linux + 224)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_tgkill (__NR_Linux + 225)
 #define __NR_utimes (__NR_Linux + 226)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mbind (__NR_Linux + 227)
 #define __NR_get_mempolicy (__NR_Linux + 228)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_set_mempolicy (__NR_Linux + 229)
 #define __NR_mq_open (__NR_Linux + 230)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mq_unlink (__NR_Linux + 231)
 #define __NR_mq_timedsend (__NR_Linux + 232)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mq_timedreceive (__NR_Linux + 233)
 #define __NR_mq_notify (__NR_Linux + 234)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mq_getsetattr (__NR_Linux + 235)
 #define __NR_vserver (__NR_Linux + 236)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_waitid (__NR_Linux + 237)
 #define __NR_add_key (__NR_Linux + 239)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_request_key (__NR_Linux + 240)
 #define __NR_keyctl (__NR_Linux + 241)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_set_thread_area (__NR_Linux + 242)
 #define __NR_inotify_init (__NR_Linux + 243)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_inotify_add_watch (__NR_Linux + 244)
 #define __NR_inotify_rm_watch (__NR_Linux + 245)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_migrate_pages (__NR_Linux + 246)
 #define __NR_openat (__NR_Linux + 247)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_mkdirat (__NR_Linux + 248)
 #define __NR_mknodat (__NR_Linux + 249)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fchownat (__NR_Linux + 250)
 #define __NR_futimesat (__NR_Linux + 251)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_newfstatat (__NR_Linux + 252)
 #define __NR_unlinkat (__NR_Linux + 253)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_renameat (__NR_Linux + 254)
 #define __NR_linkat (__NR_Linux + 255)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_symlinkat (__NR_Linux + 256)
 #define __NR_readlinkat (__NR_Linux + 257)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fchmodat (__NR_Linux + 258)
 #define __NR_faccessat (__NR_Linux + 259)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_pselect6 (__NR_Linux + 260)
 #define __NR_ppoll (__NR_Linux + 261)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_unshare (__NR_Linux + 262)
 #define __NR_splice (__NR_Linux + 263)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sync_file_range (__NR_Linux + 264)
 #define __NR_tee (__NR_Linux + 265)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_vmsplice (__NR_Linux + 266)
 #define __NR_move_pages (__NR_Linux + 267)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_set_robust_list (__NR_Linux + 268)
 #define __NR_get_robust_list (__NR_Linux + 269)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_kexec_load (__NR_Linux + 270)
 #define __NR_getcpu (__NR_Linux + 271)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_epoll_pwait (__NR_Linux + 272)
 #define __NR_ioprio_set (__NR_Linux + 273)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_ioprio_get (__NR_Linux + 274)
 #define __NR_utimensat (__NR_Linux + 275)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_signalfd (__NR_Linux + 276)
 #define __NR_timerfd (__NR_Linux + 277)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_eventfd (__NR_Linux + 278)
 #define __NR_fallocate (__NR_Linux + 279)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_timerfd_create (__NR_Linux + 280)
 #define __NR_timerfd_gettime (__NR_Linux + 281)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_timerfd_settime (__NR_Linux + 282)
 #define __NR_signalfd4 (__NR_Linux + 283)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_eventfd2 (__NR_Linux + 284)
 #define __NR_epoll_create1 (__NR_Linux + 285)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_dup3 (__NR_Linux + 286)
 #define __NR_pipe2 (__NR_Linux + 287)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_inotify_init1 (__NR_Linux + 288)
 #define __NR_preadv (__NR_Linux + 289)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_pwritev (__NR_Linux + 290)
 #define __NR_rt_tgsigqueueinfo (__NR_Linux + 291)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_perf_event_open (__NR_Linux + 292)
 #define __NR_accept4 (__NR_Linux + 293)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_recvmmsg (__NR_Linux + 294)
 #define __NR_fanotify_init (__NR_Linux + 295)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_fanotify_mark (__NR_Linux + 296)
 #define __NR_prlimit64 (__NR_Linux + 297)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_name_to_handle_at (__NR_Linux + 298)
 #define __NR_open_by_handle_at (__NR_Linux + 299)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_clock_adjtime (__NR_Linux + 300)
 #define __NR_syncfs (__NR_Linux + 301)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sendmmsg (__NR_Linux + 302)
 #define __NR_setns (__NR_Linux + 303)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_process_vm_readv (__NR_Linux + 304)
 #define __NR_process_vm_writev (__NR_Linux + 305)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_kcmp (__NR_Linux + 306)
 #define __NR_finit_module (__NR_Linux + 307)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getdents64 (__NR_Linux + 308)
-#define __NR_Linux_syscalls 308
+#define __NR_sched_setattr (__NR_Linux + 309)
+#define __NR_sched_getattr (__NR_Linux + 310)
+#define __NR_Linux_syscalls 310
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #define __NR_64_Linux 5000
-#define __NR_64_Linux_syscalls 308
+#define __NR_64_Linux_syscalls 310
 #if _MIPS_SIM == _MIPS_SIM_NABI32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_Linux 6000
@@ -1247,9 +1252,12 @@
 #define __NR_kcmp (__NR_Linux + 311)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_finit_module (__NR_Linux + 312)
-#define __NR_Linux_syscalls 312
+#define __NR_sched_setattr (__NR_Linux + 313)
+#define __NR_sched_getattr (__NR_Linux + 314)
+#define __NR_Linux_syscalls 314
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #define __NR_N32_Linux 6000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define __NR_N32_Linux_syscalls 312
+#define __NR_N32_Linux_syscalls 314
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-x86/asm/bootparam.h b/libc/kernel/uapi/asm-x86/asm/bootparam.h
index af98489..b576825 100644
--- a/libc/kernel/uapi/asm-x86/asm/bootparam.h
+++ b/libc/kernel/uapi/asm-x86/asm/bootparam.h
@@ -23,164 +23,167 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SETUP_DTB 2
 #define SETUP_PCI 3
+#define SETUP_EFI 4
 #define RAMDISK_IMAGE_START_MASK 0x07FF
-#define RAMDISK_PROMPT_FLAG 0x8000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define RAMDISK_PROMPT_FLAG 0x8000
 #define RAMDISK_LOAD_FLAG 0x4000
 #define LOADED_HIGH (1<<0)
 #define QUIET_FLAG (1<<5)
-#define KEEP_SEGMENTS (1<<6)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEEP_SEGMENTS (1<<6)
 #define CAN_USE_HEAP (1<<7)
 #define XLF_KERNEL_64 (1<<0)
 #define XLF_CAN_BE_LOADED_ABOVE_4G (1<<1)
-#define XLF_EFI_HANDOVER_32 (1<<2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define XLF_EFI_HANDOVER_32 (1<<2)
 #define XLF_EFI_HANDOVER_64 (1<<3)
+#define XLF_EFI_KEXEC (1<<4)
 #ifndef __ASSEMBLY__
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #include <linux/types.h>
 #include <linux/screen_info.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #include <linux/apm_bios.h>
 #include <linux/edd.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #include <asm/e820.h>
 #include <asm/ist.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #include <video/edid.h>
 struct setup_data {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 next;
  __u32 type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 len;
  __u8 data[0];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct setup_header {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 setup_sects;
  __u16 root_flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 syssize;
  __u16 ram_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 vid_mode;
  __u16 root_dev;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 boot_flag;
  __u16 jump;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 header;
  __u16 version;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 realmode_swtch;
  __u16 start_sys;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 kernel_version;
  __u8 type_of_loader;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 loadflags;
  __u16 setup_move_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 code32_start;
  __u32 ramdisk_image;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ramdisk_size;
  __u32 bootsect_kludge;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 heap_end_ptr;
  __u8 ext_loader_ver;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 ext_loader_type;
  __u32 cmd_line_ptr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 initrd_addr_max;
  __u32 kernel_alignment;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 relocatable_kernel;
  __u8 min_alignment;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 xloadflags;
  __u32 cmdline_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 hardware_subarch;
  __u64 hardware_subarch_data;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 payload_offset;
  __u32 payload_length;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 setup_data;
  __u64 pref_address;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 init_size;
  __u32 handover_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__((packed));
 struct sys_desc_table {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 length;
  __u8 table[14];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct olpc_ofw_header {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ofw_magic;
  __u32 ofw_version;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cif_handler;
  __u32 irq_desc_table;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__((packed));
 struct efi_info {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 efi_loader_signature;
  __u32 efi_systab;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 efi_memdesc_size;
  __u32 efi_memdesc_version;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 efi_memmap;
  __u32 efi_memmap_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 efi_systab_hi;
  __u32 efi_memmap_hi;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct boot_params {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct screen_info screen_info;
  struct apm_bios_info apm_bios_info;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 _pad2[4];
  __u64 tboot_addr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct ist_info ist_info;
  __u8 _pad3[16];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 hd0_info[16];
  __u8 hd1_info[16];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct sys_desc_table sys_desc_table;
  struct olpc_ofw_header olpc_ofw_header;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ext_ramdisk_image;
  __u32 ext_ramdisk_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ext_cmd_line_ptr;
  __u8 _pad4[116];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct edid_info edid_info;
  struct efi_info efi_info;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 alt_mem_k;
  __u32 scratch;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 e820_entries;
  __u8 eddbuf_entries;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 edd_mbr_sig_buf_entries;
  __u8 kbd_status;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 _pad5[3];
  __u8 sentinel;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 _pad6[1];
  struct setup_header hdr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 _pad7[0x290-0x1f1-sizeof(struct setup_header)];
  __u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct e820entry e820_map[E820MAX];
  __u8 _pad8[48];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct edd_info eddbuf[EDDMAXNR];
  __u8 _pad9[276];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__((packed));
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  X86_SUBARCH_PC = 0,
  X86_SUBARCH_LGUEST,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  X86_SUBARCH_XEN,
- X86_SUBARCH_MRST,
+ X86_SUBARCH_INTEL_MID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  X86_SUBARCH_CE4100,
  X86_NR_SUBARCHS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/hyperv.h b/libc/kernel/uapi/asm-x86/asm/hyperv.h
index 5874e8d..965e80a 100644
--- a/libc/kernel/uapi/asm-x86/asm/hyperv.h
+++ b/libc/kernel/uapi/asm-x86/asm/hyperv.h
@@ -33,99 +33,116 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_MSR_VP_RUNTIME_AVAILABLE (1 << 0)
 #define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE (1 << 1)
+#define HV_X64_MSR_REFERENCE_TSC 0x40000021
+#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 << 11)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 << 11)
 #define HV_X64_MSR_SYNIC_AVAILABLE (1 << 2)
 #define HV_X64_MSR_SYNTIMER_AVAILABLE (1 << 3)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_MSR_APIC_ACCESS_AVAILABLE (1 << 4)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_MSR_HYPERCALL_AVAILABLE (1 << 5)
 #define HV_X64_MSR_VP_INDEX_AVAILABLE (1 << 6)
 #define HV_X64_MSR_RESET_AVAILABLE (1 << 7)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_MSR_STAT_PAGES_AVAILABLE (1 << 8)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_CREATE_PARTITIONS (1 << 0)
 #define HV_X64_ACCESS_PARTITION_ID (1 << 1)
 #define HV_X64_ACCESS_MEMORY_POOL (1 << 2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_ADJUST_MESSAGE_BUFFERS (1 << 3)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_POST_MESSAGES (1 << 4)
 #define HV_X64_SIGNAL_EVENTS (1 << 5)
 #define HV_X64_CREATE_PORT (1 << 6)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_CONNECT_PORT (1 << 7)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_ACCESS_STATS (1 << 8)
 #define HV_X64_DEBUGGING (1 << 11)
 #define HV_X64_CPU_POWER_MANAGEMENT (1 << 12)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_CONFIGURE_PROFILER (1 << 13)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_MWAIT_AVAILABLE (1 << 0)
 #define HV_X64_GUEST_DEBUGGING_AVAILABLE (1 << 1)
 #define HV_X64_PERF_MONITOR_AVAILABLE (1 << 2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE (1 << 3)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE (1 << 4)
 #define HV_X64_GUEST_IDLE_STATE_AVAILABLE (1 << 5)
 #define HV_X64_MWAIT_RECOMMENDED (1 << 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED (1 << 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED (1 << 2)
 #define HV_X64_APIC_ACCESS_RECOMMENDED (1 << 3)
 #define HV_X64_SYSTEM_RESET_RECOMMENDED (1 << 4)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_RELAXED_TIMING_RECOMMENDED (1 << 5)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_MSR_GUEST_OS_ID 0x40000000
 #define HV_X64_MSR_HYPERCALL 0x40000001
 #define HV_X64_MSR_VP_INDEX 0x40000002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_X64_MSR_TIME_REF_COUNT 0x40000020
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_TSC_FREQUENCY 0x40000022
+#define HV_X64_MSR_APIC_FREQUENCY 0x40000023
 #define HV_X64_MSR_EOI 0x40000070
 #define HV_X64_MSR_ICR 0x40000071
-#define HV_X64_MSR_TPR 0x40000072
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_TPR 0x40000072
 #define HV_X64_MSR_APIC_ASSIST_PAGE 0x40000073
 #define HV_X64_MSR_SCONTROL 0x40000080
 #define HV_X64_MSR_SVERSION 0x40000081
-#define HV_X64_MSR_SIEFP 0x40000082
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_SIEFP 0x40000082
 #define HV_X64_MSR_SIMP 0x40000083
 #define HV_X64_MSR_EOM 0x40000084
 #define HV_X64_MSR_SINT0 0x40000090
-#define HV_X64_MSR_SINT1 0x40000091
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_SINT1 0x40000091
 #define HV_X64_MSR_SINT2 0x40000092
 #define HV_X64_MSR_SINT3 0x40000093
 #define HV_X64_MSR_SINT4 0x40000094
-#define HV_X64_MSR_SINT5 0x40000095
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_SINT5 0x40000095
 #define HV_X64_MSR_SINT6 0x40000096
 #define HV_X64_MSR_SINT7 0x40000097
 #define HV_X64_MSR_SINT8 0x40000098
-#define HV_X64_MSR_SINT9 0x40000099
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_SINT9 0x40000099
 #define HV_X64_MSR_SINT10 0x4000009A
 #define HV_X64_MSR_SINT11 0x4000009B
 #define HV_X64_MSR_SINT12 0x4000009C
-#define HV_X64_MSR_SINT13 0x4000009D
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_SINT13 0x4000009D
 #define HV_X64_MSR_SINT14 0x4000009E
 #define HV_X64_MSR_SINT15 0x4000009F
 #define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001
-#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12
 #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK   (~((1ull << HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT) - 1))
 #define HV_X64_HV_NOTIFY_LONG_SPIN_WAIT 0x0008
 #define HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE 0x00000001
-#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT 12
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT 12
 #define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_MASK   (~((1ull << HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT) - 1))
+#define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001
+#define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_PROCESSOR_POWER_STATE_C0 0
 #define HV_PROCESSOR_POWER_STATE_C1 1
 #define HV_PROCESSOR_POWER_STATE_C2 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_PROCESSOR_POWER_STATE_C3 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_STATUS_SUCCESS 0
 #define HV_STATUS_INVALID_HYPERCALL_CODE 2
 #define HV_STATUS_INVALID_HYPERCALL_INPUT 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_STATUS_INVALID_ALIGNMENT 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define HV_STATUS_INSUFFICIENT_BUFFERS 19
+typedef struct _HV_REFERENCE_TSC_PAGE {
+ __u32 tsc_sequence;
+ __u32 res1;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 tsc_scale;
+ __s64 tsc_offset;
+} HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE;
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-x86/asm/kvm.h b/libc/kernel/uapi/asm-x86/asm/kvm.h
index ab301d1..200d818 100644
--- a/libc/kernel/uapi/asm-x86/asm/kvm.h
+++ b/libc/kernel/uapi/asm-x86/asm/kvm.h
@@ -231,9 +231,9 @@
  __u32 padding[3];
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
-#define KVM_CPUID_FLAG_STATEFUL_FUNC 2
-#define KVM_CPUID_FLAG_STATE_READ_NEXT 4
+#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
+#define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
+#define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
 struct kvm_cpuid2 {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 nent;
diff --git a/libc/kernel/uapi/asm-x86/asm/kvm_para.h b/libc/kernel/uapi/asm-x86/asm/kvm_para.h
index e91c18e..7fb5efe 100644
--- a/libc/kernel/uapi/asm-x86/asm/kvm_para.h
+++ b/libc/kernel/uapi/asm-x86/asm/kvm_para.h
@@ -32,68 +32,69 @@
 #define KVM_FEATURE_STEAL_TIME 5
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_FEATURE_PV_EOI 6
+#define KVM_FEATURE_PV_UNHALT 7
 #define KVM_FEATURE_CLOCKSOURCE_STABLE_BIT 24
 #define MSR_KVM_WALL_CLOCK 0x11
-#define MSR_KVM_SYSTEM_TIME 0x12
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_KVM_SYSTEM_TIME 0x12
 #define KVM_MSR_ENABLED 1
 #define MSR_KVM_WALL_CLOCK_NEW 0x4b564d00
 #define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01
-#define MSR_KVM_ASYNC_PF_EN 0x4b564d02
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_KVM_ASYNC_PF_EN 0x4b564d02
 #define MSR_KVM_STEAL_TIME 0x4b564d03
 #define MSR_KVM_PV_EOI_EN 0x4b564d04
 struct kvm_steal_time {
- __u64 steal;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 steal;
  __u32 version;
  __u32 flags;
  __u32 pad[12];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define KVM_STEAL_ALIGNMENT_BITS 5
 #define KVM_STEAL_VALID_BITS ((-1ULL << (KVM_STEAL_ALIGNMENT_BITS + 1)))
 #define KVM_STEAL_RESERVED_MASK (((1 << KVM_STEAL_ALIGNMENT_BITS) - 1 ) << 1)
-#define KVM_MAX_MMU_OP_BATCH 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_MAX_MMU_OP_BATCH 32
 #define KVM_ASYNC_PF_ENABLED (1 << 0)
 #define KVM_ASYNC_PF_SEND_ALWAYS (1 << 1)
 #define KVM_MMU_OP_WRITE_PTE 1
-#define KVM_MMU_OP_FLUSH_TLB 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_MMU_OP_FLUSH_TLB 2
 #define KVM_MMU_OP_RELEASE_PT 3
 struct kvm_mmu_op_header {
  __u32 op;
- __u32 pad;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 pad;
 };
 struct kvm_mmu_op_write_pte {
  struct kvm_mmu_op_header header;
- __u64 pte_phys;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 pte_phys;
  __u64 pte_val;
 };
 struct kvm_mmu_op_flush_tlb {
- struct kvm_mmu_op_header header;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct kvm_mmu_op_header header;
 };
 struct kvm_mmu_op_release_pt {
  struct kvm_mmu_op_header header;
- __u64 pt_phys;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 pt_phys;
 };
 #define KVM_PV_REASON_PAGE_NOT_PRESENT 1
 #define KVM_PV_REASON_PAGE_READY 2
-struct kvm_vcpu_pv_apf_data {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct kvm_vcpu_pv_apf_data {
  __u32 reason;
  __u8 pad[60];
  __u32 enabled;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define KVM_PV_EOI_BIT 0
 #define KVM_PV_EOI_MASK (0x1 << KVM_PV_EOI_BIT)
 #define KVM_PV_EOI_ENABLED KVM_PV_EOI_MASK
-#define KVM_PV_EOI_DISABLED 0x0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_PV_EOI_DISABLED 0x0
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/msr-index.h b/libc/kernel/uapi/asm-x86/asm/msr-index.h
index ce77205..6e4cac7 100644
--- a/libc/kernel/uapi/asm-x86/asm/msr-index.h
+++ b/libc/kernel/uapi/asm-x86/asm/msr-index.h
@@ -161,387 +161,392 @@
 #define MSR_PP1_ENERGY_STATUS 0x00000641
 #define MSR_PP1_POLICY 0x00000642
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_CORE_C1_RES 0x00000660
 #define MSR_AMD64_MC0_MASK 0xc0010044
 #define MSR_IA32_MCx_CTL(x) (MSR_IA32_MC0_CTL + 4*(x))
 #define MSR_IA32_MCx_STATUS(x) (MSR_IA32_MC0_STATUS + 4*(x))
-#define MSR_IA32_MCx_ADDR(x) (MSR_IA32_MC0_ADDR + 4*(x))
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_IA32_MCx_ADDR(x) (MSR_IA32_MC0_ADDR + 4*(x))
 #define MSR_IA32_MCx_MISC(x) (MSR_IA32_MC0_MISC + 4*(x))
 #define MSR_AMD64_MCx_MASK(x) (MSR_AMD64_MC0_MASK + (x))
 #define MSR_IA32_MC0_CTL2 0x00000280
-#define MSR_IA32_MCx_CTL2(x) (MSR_IA32_MC0_CTL2 + (x))
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_IA32_MCx_CTL2(x) (MSR_IA32_MC0_CTL2 + (x))
 #define MSR_P6_PERFCTR0 0x000000c1
 #define MSR_P6_PERFCTR1 0x000000c2
 #define MSR_P6_EVNTSEL0 0x00000186
-#define MSR_P6_EVNTSEL1 0x00000187
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_P6_EVNTSEL1 0x00000187
 #define MSR_KNC_PERFCTR0 0x00000020
 #define MSR_KNC_PERFCTR1 0x00000021
 #define MSR_KNC_EVNTSEL0 0x00000028
-#define MSR_KNC_EVNTSEL1 0x00000029
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_KNC_EVNTSEL1 0x00000029
+#define MSR_IA32_PMC0 0x000004c1
 #define MSR_AMD64_PATCH_LEVEL 0x0000008b
 #define MSR_AMD64_TSC_RATIO 0xc0000104
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_NB_CFG 0xc001001f
 #define MSR_AMD64_PATCH_LOADER 0xc0010020
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_OSVW_ID_LENGTH 0xc0010140
 #define MSR_AMD64_OSVW_STATUS 0xc0010141
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_AMD64_LS_CFG 0xc0011020
 #define MSR_AMD64_DC_CFG 0xc0011022
 #define MSR_AMD64_BU_CFG2 0xc001102a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBSFETCHCTL 0xc0011030
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBSFETCHLINAD 0xc0011031
 #define MSR_AMD64_IBSFETCHPHYSAD 0xc0011032
 #define MSR_AMD64_IBSFETCH_REG_COUNT 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBSFETCH_REG_MASK ((1UL<<MSR_AMD64_IBSFETCH_REG_COUNT)-1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBSOPCTL 0xc0011033
 #define MSR_AMD64_IBSOPRIP 0xc0011034
 #define MSR_AMD64_IBSOPDATA 0xc0011035
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBSOPDATA2 0xc0011036
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBSOPDATA3 0xc0011037
 #define MSR_AMD64_IBSDCLINAD 0xc0011038
 #define MSR_AMD64_IBSDCPHYSAD 0xc0011039
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBSOP_REG_COUNT 7
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBSOP_REG_MASK ((1UL<<MSR_AMD64_IBSOP_REG_COUNT)-1)
 #define MSR_AMD64_IBSCTL 0xc001103a
 #define MSR_AMD64_IBSBRTARGET 0xc001103b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD64_IBS_REG_COUNT_MAX 8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_F16H_L2I_PERF_CTL 0xc0010230
 #define MSR_F16H_L2I_PERF_CTR 0xc0010231
 #define MSR_F15H_PERF_CTL 0xc0010200
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_F15H_PERF_CTR 0xc0010201
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_F15H_NB_PERF_CTL 0xc0010240
 #define MSR_F15H_NB_PERF_CTR 0xc0010241
 #define MSR_FAM10H_MMIO_CONF_BASE 0xc0010058
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define FAM10H_MMIO_CONF_ENABLE (1<<0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define FAM10H_MMIO_CONF_BUSRANGE_MASK 0xf
 #define FAM10H_MMIO_CONF_BUSRANGE_SHIFT 2
 #define FAM10H_MMIO_CONF_BASE_MASK 0xfffffffULL
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define FAM10H_MMIO_CONF_BASE_SHIFT 20
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_FAM10H_NODE_ID 0xc001100c
 #define MSR_K8_TOP_MEM1 0xc001001a
 #define MSR_K8_TOP_MEM2 0xc001001d
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K8_SYSCFG 0xc0010010
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K8_INT_PENDING_MSG 0xc0010055
 #define K8_INTP_C1E_ACTIVE_MASK 0x18000000
 #define MSR_K8_TSEG_ADDR 0xc0010112
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define K8_MTRRFIXRANGE_DRAM_ENABLE 0x00040000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define K8_MTRRFIXRANGE_DRAM_MODIFY 0x00080000
 #define K8_MTRR_RDMEM_WRMEM_MASK 0x18181818
 #define MSR_K7_EVNTSEL0 0xc0010000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K7_PERFCTR0 0xc0010004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K7_EVNTSEL1 0xc0010001
 #define MSR_K7_PERFCTR1 0xc0010005
 #define MSR_K7_EVNTSEL2 0xc0010002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K7_PERFCTR2 0xc0010006
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K7_EVNTSEL3 0xc0010003
 #define MSR_K7_PERFCTR3 0xc0010007
 #define MSR_K7_CLK_CTL 0xc001001b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K7_HWCR 0xc0010015
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K7_FID_VID_CTL 0xc0010041
 #define MSR_K7_FID_VID_STATUS 0xc0010042
 #define MSR_K6_WHCR 0xc0000082
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K6_UWCCR 0xc0000085
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_K6_EPMR 0xc0000086
 #define MSR_K6_PSOR 0xc0000087
 #define MSR_K6_PFIR 0xc0000088
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IDT_FCR1 0x00000107
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IDT_FCR2 0x00000108
 #define MSR_IDT_FCR3 0x00000109
 #define MSR_IDT_FCR4 0x0000010a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IDT_MCR0 0x00000110
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IDT_MCR1 0x00000111
 #define MSR_IDT_MCR2 0x00000112
 #define MSR_IDT_MCR3 0x00000113
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IDT_MCR4 0x00000114
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IDT_MCR5 0x00000115
 #define MSR_IDT_MCR6 0x00000116
 #define MSR_IDT_MCR7 0x00000117
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IDT_MCR_CTRL 0x00000120
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_VIA_FCR 0x00001107
 #define MSR_VIA_LONGHAUL 0x0000110a
 #define MSR_VIA_RNG 0x0000110b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_VIA_BCR2 0x00001147
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_TMTA_LONGRUN_CTRL 0x80868010
 #define MSR_TMTA_LONGRUN_FLAGS 0x80868011
 #define MSR_TMTA_LRTI_READOUT 0x80868018
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_TMTA_LRTI_VOLT_MHZ 0x8086801a
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_P5_MC_ADDR 0x00000000
 #define MSR_IA32_P5_MC_TYPE 0x00000001
 #define MSR_IA32_TSC 0x00000010
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_PLATFORM_ID 0x00000017
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_EBL_CR_POWERON 0x0000002a
 #define MSR_EBC_FREQUENCY_ID 0x0000002c
 #define MSR_SMI_COUNT 0x00000034
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_FEATURE_CONTROL 0x0000003a
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_TSC_ADJUST 0x0000003b
 #define FEATURE_CONTROL_LOCKED (1<<0)
 #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1<<1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_APICBASE 0x0000001b
 #define MSR_IA32_APICBASE_BSP (1<<8)
 #define MSR_IA32_APICBASE_ENABLE (1<<11)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_APICBASE_BASE (0xfffff<<12)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_TSCDEADLINE 0x000006e0
 #define MSR_IA32_UCODE_WRITE 0x00000079
 #define MSR_IA32_UCODE_REV 0x0000008b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_PERF_STATUS 0x00000198
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_PERF_CTL 0x00000199
 #define MSR_AMD_PSTATE_DEF_BASE 0xc0010064
 #define MSR_AMD_PERF_STATUS 0xc0010063
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_AMD_PERF_CTL 0xc0010062
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MPERF 0x000000e7
 #define MSR_IA32_APERF 0x000000e8
 #define MSR_IA32_THERM_CONTROL 0x0000019a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_THERM_INTERRUPT 0x0000019b
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define THERM_INT_HIGH_ENABLE (1 << 0)
 #define THERM_INT_LOW_ENABLE (1 << 1)
 #define THERM_INT_PLN_ENABLE (1 << 24)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_THERM_STATUS 0x0000019c
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define THERM_STATUS_PROCHOT (1 << 0)
 #define THERM_STATUS_POWER_LIMIT (1 << 10)
 #define MSR_THERM2_CTL 0x0000019d
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_THERM2_CTL_TM_SELECT (1ULL << 16)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE 0x000001a0
 #define MSR_IA32_TEMPERATURE_TARGET 0x000001a2
 #define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ENERGY_PERF_BIAS_PERFORMANCE 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ENERGY_PERF_BIAS_NORMAL 6
 #define ENERGY_PERF_BIAS_POWERSAVE 15
 #define MSR_IA32_PACKAGE_THERM_STATUS 0x000001b1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKAGE_THERM_STATUS_PROCHOT (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKAGE_THERM_STATUS_POWER_LIMIT (1 << 10)
 #define MSR_IA32_PACKAGE_THERM_INTERRUPT 0x000001b2
 #define PACKAGE_THERM_INT_HIGH_ENABLE (1 << 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKAGE_THERM_INT_LOW_ENABLE (1 << 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKAGE_THERM_INT_PLN_ENABLE (1 << 24)
 #define THERM_INT_THRESHOLD0_ENABLE (1 << 15)
 #define THERM_SHIFT_THRESHOLD0 8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define THERM_MASK_THRESHOLD0 (0x7f << THERM_SHIFT_THRESHOLD0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define THERM_INT_THRESHOLD1_ENABLE (1 << 23)
 #define THERM_SHIFT_THRESHOLD1 16
 #define THERM_MASK_THRESHOLD1 (0x7f << THERM_SHIFT_THRESHOLD1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define THERM_STATUS_THRESHOLD0 (1 << 6)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define THERM_LOG_THRESHOLD0 (1 << 7)
 #define THERM_STATUS_THRESHOLD1 (1 << 8)
 #define THERM_LOG_THRESHOLD1 (1 << 9)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_FAST_STRING (1ULL << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_TCC (1ULL << 1)
 #define MSR_IA32_MISC_ENABLE_EMON (1ULL << 7)
 #define MSR_IA32_MISC_ENABLE_BTS_UNAVAIL (1ULL << 11)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL (1ULL << 12)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP (1ULL << 16)
 #define MSR_IA32_MISC_ENABLE_MWAIT (1ULL << 18)
 #define MSR_IA32_MISC_ENABLE_LIMIT_CPUID (1ULL << 22)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_XTPR_DISABLE (1ULL << 23)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_XD_DISABLE (1ULL << 34)
 #define MSR_IA32_MISC_ENABLE_X87_COMPAT (1ULL << 2)
 #define MSR_IA32_MISC_ENABLE_TM1 (1ULL << 3)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_SPLIT_LOCK_DISABLE (1ULL << 4)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_L3CACHE_DISABLE (1ULL << 6)
 #define MSR_IA32_MISC_ENABLE_SUPPRESS_LOCK (1ULL << 8)
 #define MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE (1ULL << 9)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_FERR (1ULL << 10)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_FERR_MULTIPLEX (1ULL << 10)
 #define MSR_IA32_MISC_ENABLE_TM2 (1ULL << 13)
 #define MSR_IA32_MISC_ENABLE_ADJ_PREF_DISABLE (1ULL << 19)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_SPEEDSTEP_LOCK (1ULL << 20)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_L1D_CONTEXT (1ULL << 24)
 #define MSR_IA32_MISC_ENABLE_DCU_PREF_DISABLE (1ULL << 37)
 #define MSR_IA32_MISC_ENABLE_TURBO_DISABLE (1ULL << 38)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE (1ULL << 39)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_TSC_DEADLINE 0x000006E0
 #define MSR_IA32_MCG_EAX 0x00000180
 #define MSR_IA32_MCG_EBX 0x00000181
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MCG_ECX 0x00000182
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MCG_EDX 0x00000183
 #define MSR_IA32_MCG_ESI 0x00000184
 #define MSR_IA32_MCG_EDI 0x00000185
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MCG_EBP 0x00000186
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MCG_ESP 0x00000187
 #define MSR_IA32_MCG_EFLAGS 0x00000188
 #define MSR_IA32_MCG_EIP 0x00000189
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_MCG_RESERVED 0x0000018a
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_BPU_PERFCTR0 0x00000300
 #define MSR_P4_BPU_PERFCTR1 0x00000301
 #define MSR_P4_BPU_PERFCTR2 0x00000302
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_BPU_PERFCTR3 0x00000303
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_MS_PERFCTR0 0x00000304
 #define MSR_P4_MS_PERFCTR1 0x00000305
 #define MSR_P4_MS_PERFCTR2 0x00000306
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_MS_PERFCTR3 0x00000307
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_FLAME_PERFCTR0 0x00000308
 #define MSR_P4_FLAME_PERFCTR1 0x00000309
 #define MSR_P4_FLAME_PERFCTR2 0x0000030a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_FLAME_PERFCTR3 0x0000030b
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IQ_PERFCTR0 0x0000030c
 #define MSR_P4_IQ_PERFCTR1 0x0000030d
 #define MSR_P4_IQ_PERFCTR2 0x0000030e
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IQ_PERFCTR3 0x0000030f
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IQ_PERFCTR4 0x00000310
 #define MSR_P4_IQ_PERFCTR5 0x00000311
 #define MSR_P4_BPU_CCCR0 0x00000360
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_BPU_CCCR1 0x00000361
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_BPU_CCCR2 0x00000362
 #define MSR_P4_BPU_CCCR3 0x00000363
 #define MSR_P4_MS_CCCR0 0x00000364
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_MS_CCCR1 0x00000365
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_MS_CCCR2 0x00000366
 #define MSR_P4_MS_CCCR3 0x00000367
 #define MSR_P4_FLAME_CCCR0 0x00000368
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_FLAME_CCCR1 0x00000369
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_FLAME_CCCR2 0x0000036a
 #define MSR_P4_FLAME_CCCR3 0x0000036b
 #define MSR_P4_IQ_CCCR0 0x0000036c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IQ_CCCR1 0x0000036d
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IQ_CCCR2 0x0000036e
 #define MSR_P4_IQ_CCCR3 0x0000036f
 #define MSR_P4_IQ_CCCR4 0x00000370
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IQ_CCCR5 0x00000371
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_ALF_ESCR0 0x000003ca
 #define MSR_P4_ALF_ESCR1 0x000003cb
 #define MSR_P4_BPU_ESCR0 0x000003b2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_BPU_ESCR1 0x000003b3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_BSU_ESCR0 0x000003a0
 #define MSR_P4_BSU_ESCR1 0x000003a1
 #define MSR_P4_CRU_ESCR0 0x000003b8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_CRU_ESCR1 0x000003b9
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_CRU_ESCR2 0x000003cc
 #define MSR_P4_CRU_ESCR3 0x000003cd
 #define MSR_P4_CRU_ESCR4 0x000003e0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_CRU_ESCR5 0x000003e1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_DAC_ESCR0 0x000003a8
 #define MSR_P4_DAC_ESCR1 0x000003a9
 #define MSR_P4_FIRM_ESCR0 0x000003a4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_FIRM_ESCR1 0x000003a5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_FLAME_ESCR0 0x000003a6
 #define MSR_P4_FLAME_ESCR1 0x000003a7
 #define MSR_P4_FSB_ESCR0 0x000003a2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_FSB_ESCR1 0x000003a3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IQ_ESCR0 0x000003ba
 #define MSR_P4_IQ_ESCR1 0x000003bb
 #define MSR_P4_IS_ESCR0 0x000003b4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IS_ESCR1 0x000003b5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_ITLB_ESCR0 0x000003b6
 #define MSR_P4_ITLB_ESCR1 0x000003b7
 #define MSR_P4_IX_ESCR0 0x000003c8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_IX_ESCR1 0x000003c9
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_MOB_ESCR0 0x000003aa
 #define MSR_P4_MOB_ESCR1 0x000003ab
 #define MSR_P4_MS_ESCR0 0x000003c0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_MS_ESCR1 0x000003c1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_PMH_ESCR0 0x000003ac
 #define MSR_P4_PMH_ESCR1 0x000003ad
 #define MSR_P4_RAT_ESCR0 0x000003bc
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_RAT_ESCR1 0x000003bd
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_SAAT_ESCR0 0x000003ae
 #define MSR_P4_SAAT_ESCR1 0x000003af
 #define MSR_P4_SSU_ESCR0 0x000003be
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_SSU_ESCR1 0x000003bf
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_TBPU_ESCR0 0x000003c2
 #define MSR_P4_TBPU_ESCR1 0x000003c3
 #define MSR_P4_TC_ESCR0 0x000003c4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_TC_ESCR1 0x000003c5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_P4_U2L_ESCR0 0x000003b0
 #define MSR_P4_U2L_ESCR1 0x000003b1
 #define MSR_P4_PEBS_MATRIX_VERT 0x000003f2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_CORE_PERF_FIXED_CTR0 0x00000309
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_CORE_PERF_FIXED_CTR1 0x0000030a
 #define MSR_CORE_PERF_FIXED_CTR2 0x0000030b
 #define MSR_CORE_PERF_FIXED_CTR_CTRL 0x0000038d
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_CORE_PERF_GLOBAL_STATUS 0x0000038e
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_CORE_PERF_GLOBAL_CTRL 0x0000038f
 #define MSR_CORE_PERF_GLOBAL_OVF_CTRL 0x00000390
 #define MSR_GEODE_BUSCONT_CONF0 0x00001900
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_BASIC 0x00000480
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_PINBASED_CTLS 0x00000481
 #define MSR_IA32_VMX_PROCBASED_CTLS 0x00000482
 #define MSR_IA32_VMX_EXIT_CTLS 0x00000483
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_ENTRY_CTLS 0x00000484
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_MISC 0x00000485
 #define MSR_IA32_VMX_CR0_FIXED0 0x00000486
 #define MSR_IA32_VMX_CR0_FIXED1 0x00000487
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_CR4_FIXED0 0x00000488
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_CR4_FIXED1 0x00000489
 #define MSR_IA32_VMX_VMCS_ENUM 0x0000048a
 #define MSR_IA32_VMX_PROCBASED_CTLS2 0x0000048b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_EPT_VPID_CAP 0x0000048c
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_TRUE_PINBASED_CTLS 0x0000048d
 #define MSR_IA32_VMX_TRUE_PROCBASED_CTLS 0x0000048e
 #define MSR_IA32_VMX_TRUE_EXIT_CTLS 0x0000048f
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MSR_IA32_VMX_TRUE_ENTRY_CTLS 0x00000490
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_IA32_VMX_VMFUNC 0x00000491
 #define VMX_BASIC_VMCS_SIZE_SHIFT 32
 #define VMX_BASIC_64 0x0001000000000000LLU
 #define VMX_BASIC_MEM_TYPE_SHIFT 50
@@ -551,8 +556,9 @@
 #define VMX_BASIC_INOUT 0x0040000000000000LLU
 #define MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS (1ULL << 29)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSR_IA32_VMX_MISC_PREEMPTION_TIMER_SCALE 0x1F
 #define MSR_VM_CR 0xc0010114
 #define MSR_VM_IGNNE 0xc0010115
 #define MSR_VM_HSAVE_PA 0xc0010117
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/asm-x86/asm/processor-flags.h b/libc/kernel/uapi/asm-x86/asm/processor-flags.h
index ac602a7..aead779 100644
--- a/libc/kernel/uapi/asm-x86/asm/processor-flags.h
+++ b/libc/kernel/uapi/asm-x86/asm/processor-flags.h
@@ -18,86 +18,152 @@
  ****************************************************************************/
 #ifndef _UAPI_ASM_X86_PROCESSOR_FLAGS_H
 #define _UAPI_ASM_X86_PROCESSOR_FLAGS_H
-#define X86_EFLAGS_CF 0x00000001
-#define X86_EFLAGS_BIT1 0x00000002
+#include <linux/const.h>
+#define X86_EFLAGS_CF_BIT 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_EFLAGS_PF 0x00000004
-#define X86_EFLAGS_AF 0x00000010
-#define X86_EFLAGS_ZF 0x00000040
-#define X86_EFLAGS_SF 0x00000080
+#define X86_EFLAGS_CF _BITUL(X86_EFLAGS_CF_BIT)
+#define X86_EFLAGS_FIXED_BIT 1
+#define X86_EFLAGS_FIXED _BITUL(X86_EFLAGS_FIXED_BIT)
+#define X86_EFLAGS_PF_BIT 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_EFLAGS_TF 0x00000100
-#define X86_EFLAGS_IF 0x00000200
-#define X86_EFLAGS_DF 0x00000400
-#define X86_EFLAGS_OF 0x00000800
+#define X86_EFLAGS_PF _BITUL(X86_EFLAGS_PF_BIT)
+#define X86_EFLAGS_AF_BIT 4
+#define X86_EFLAGS_AF _BITUL(X86_EFLAGS_AF_BIT)
+#define X86_EFLAGS_ZF_BIT 6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_EFLAGS_IOPL 0x00003000
-#define X86_EFLAGS_NT 0x00004000
-#define X86_EFLAGS_RF 0x00010000
-#define X86_EFLAGS_VM 0x00020000
+#define X86_EFLAGS_ZF _BITUL(X86_EFLAGS_ZF_BIT)
+#define X86_EFLAGS_SF_BIT 7
+#define X86_EFLAGS_SF _BITUL(X86_EFLAGS_SF_BIT)
+#define X86_EFLAGS_TF_BIT 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_EFLAGS_AC 0x00040000
-#define X86_EFLAGS_VIF 0x00080000
-#define X86_EFLAGS_VIP 0x00100000
-#define X86_EFLAGS_ID 0x00200000
+#define X86_EFLAGS_TF _BITUL(X86_EFLAGS_TF_BIT)
+#define X86_EFLAGS_IF_BIT 9
+#define X86_EFLAGS_IF _BITUL(X86_EFLAGS_IF_BIT)
+#define X86_EFLAGS_DF_BIT 10
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_CR0_PE 0x00000001
-#define X86_CR0_MP 0x00000002
-#define X86_CR0_EM 0x00000004
-#define X86_CR0_TS 0x00000008
+#define X86_EFLAGS_DF _BITUL(X86_EFLAGS_DF_BIT)
+#define X86_EFLAGS_OF_BIT 11
+#define X86_EFLAGS_OF _BITUL(X86_EFLAGS_OF_BIT)
+#define X86_EFLAGS_IOPL_BIT 12
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_CR0_ET 0x00000010
-#define X86_CR0_NE 0x00000020
-#define X86_CR0_WP 0x00010000
-#define X86_CR0_AM 0x00040000
+#define X86_EFLAGS_IOPL (_AC(3,UL) << X86_EFLAGS_IOPL_BIT)
+#define X86_EFLAGS_NT_BIT 14
+#define X86_EFLAGS_NT _BITUL(X86_EFLAGS_NT_BIT)
+#define X86_EFLAGS_RF_BIT 16
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_CR0_NW 0x20000000
-#define X86_CR0_CD 0x40000000
-#define X86_CR0_PG 0x80000000
-#define X86_CR3_PWT 0x00000008
+#define X86_EFLAGS_RF _BITUL(X86_EFLAGS_RF_BIT)
+#define X86_EFLAGS_VM_BIT 17
+#define X86_EFLAGS_VM _BITUL(X86_EFLAGS_VM_BIT)
+#define X86_EFLAGS_AC_BIT 18
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_CR3_PCD 0x00000010
-#define X86_CR3_PCID_MASK 0x00000fff
-#define X86_CR4_VME 0x00000001
-#define X86_CR4_PVI 0x00000002
+#define X86_EFLAGS_AC _BITUL(X86_EFLAGS_AC_BIT)
+#define X86_EFLAGS_AC_BIT 18
+#define X86_EFLAGS_AC _BITUL(X86_EFLAGS_AC_BIT)
+#define X86_EFLAGS_VIF_BIT 19
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_CR4_TSD 0x00000004
-#define X86_CR4_DE 0x00000008
-#define X86_CR4_PSE 0x00000010
-#define X86_CR4_PAE 0x00000020
+#define X86_EFLAGS_VIF _BITUL(X86_EFLAGS_VIF_BIT)
+#define X86_EFLAGS_VIP_BIT 20
+#define X86_EFLAGS_VIP _BITUL(X86_EFLAGS_VIP_BIT)
+#define X86_EFLAGS_ID_BIT 21
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_CR4_MCE 0x00000040
-#define X86_CR4_PGE 0x00000080
-#define X86_CR4_PCE 0x00000100
-#define X86_CR4_OSFXSR 0x00000200
+#define X86_EFLAGS_ID _BITUL(X86_EFLAGS_ID_BIT)
+#define X86_CR0_PE_BIT 0
+#define X86_CR0_PE _BITUL(X86_CR0_PE_BIT)
+#define X86_CR0_MP_BIT 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_CR4_OSXMMEXCPT 0x00000400
-#define X86_CR4_VMXE 0x00002000
-#define X86_CR4_RDWRGSFS 0x00010000
-#define X86_CR4_PCIDE 0x00020000
+#define X86_CR0_MP _BITUL(X86_CR0_MP_BIT)
+#define X86_CR0_EM_BIT 2
+#define X86_CR0_EM _BITUL(X86_CR0_EM_BIT)
+#define X86_CR0_TS_BIT 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define X86_CR4_OSXSAVE 0x00040000
-#define X86_CR4_SMEP 0x00100000
-#define X86_CR4_SMAP 0x00200000
-#define X86_CR8_TPR 0x0000000F
+#define X86_CR0_TS _BITUL(X86_CR0_TS_BIT)
+#define X86_CR0_ET_BIT 4
+#define X86_CR0_ET _BITUL(X86_CR0_ET_BIT)
+#define X86_CR0_NE_BIT 5
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR0_NE _BITUL(X86_CR0_NE_BIT)
+#define X86_CR0_WP_BIT 16
+#define X86_CR0_WP _BITUL(X86_CR0_WP_BIT)
+#define X86_CR0_AM_BIT 18
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR0_AM _BITUL(X86_CR0_AM_BIT)
+#define X86_CR0_NW_BIT 29
+#define X86_CR0_NW _BITUL(X86_CR0_NW_BIT)
+#define X86_CR0_CD_BIT 30
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR0_CD _BITUL(X86_CR0_CD_BIT)
+#define X86_CR0_PG_BIT 31
+#define X86_CR0_PG _BITUL(X86_CR0_PG_BIT)
+#define X86_CR3_PWT_BIT 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR3_PWT _BITUL(X86_CR3_PWT_BIT)
+#define X86_CR3_PCD_BIT 4
+#define X86_CR3_PCD _BITUL(X86_CR3_PCD_BIT)
+#define X86_CR3_PCID_MASK _AC(0x00000fff,UL)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_VME_BIT 0
+#define X86_CR4_VME _BITUL(X86_CR4_VME_BIT)
+#define X86_CR4_PVI_BIT 1
+#define X86_CR4_PVI _BITUL(X86_CR4_PVI_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_TSD_BIT 2
+#define X86_CR4_TSD _BITUL(X86_CR4_TSD_BIT)
+#define X86_CR4_DE_BIT 3
+#define X86_CR4_DE _BITUL(X86_CR4_DE_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_PSE_BIT 4
+#define X86_CR4_PSE _BITUL(X86_CR4_PSE_BIT)
+#define X86_CR4_PAE_BIT 5
+#define X86_CR4_PAE _BITUL(X86_CR4_PAE_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_MCE_BIT 6
+#define X86_CR4_MCE _BITUL(X86_CR4_MCE_BIT)
+#define X86_CR4_PGE_BIT 7
+#define X86_CR4_PGE _BITUL(X86_CR4_PGE_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_PCE_BIT 8
+#define X86_CR4_PCE _BITUL(X86_CR4_PCE_BIT)
+#define X86_CR4_OSFXSR_BIT 9
+#define X86_CR4_OSFXSR _BITUL(X86_CR4_OSFXSR_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_OSXMMEXCPT_BIT 10
+#define X86_CR4_OSXMMEXCPT _BITUL(X86_CR4_OSXMMEXCPT_BIT)
+#define X86_CR4_VMXE_BIT 13
+#define X86_CR4_VMXE _BITUL(X86_CR4_VMXE_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_SMXE_BIT 14
+#define X86_CR4_SMXE _BITUL(X86_CR4_SMXE_BIT)
+#define X86_CR4_FSGSBASE_BIT 16
+#define X86_CR4_FSGSBASE _BITUL(X86_CR4_FSGSBASE_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_PCIDE_BIT 17
+#define X86_CR4_PCIDE _BITUL(X86_CR4_PCIDE_BIT)
+#define X86_CR4_OSXSAVE_BIT 18
+#define X86_CR4_OSXSAVE _BITUL(X86_CR4_OSXSAVE_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR4_SMEP_BIT 20
+#define X86_CR4_SMEP _BITUL(X86_CR4_SMEP_BIT)
+#define X86_CR4_SMAP_BIT 21
+#define X86_CR4_SMAP _BITUL(X86_CR4_SMAP_BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define X86_CR8_TPR _AC(0x0000000f,UL)
 #define CX86_PCR0 0x20
 #define CX86_GCR 0xb8
 #define CX86_CCR0 0xc0
-#define CX86_CCR1 0xc1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CX86_CCR1 0xc1
 #define CX86_CCR2 0xc2
 #define CX86_CCR3 0xc3
 #define CX86_CCR4 0xe8
-#define CX86_CCR5 0xe9
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CX86_CCR5 0xe9
 #define CX86_CCR6 0xea
 #define CX86_CCR7 0xeb
 #define CX86_PCR1 0xf0
-#define CX86_DIR0 0xfe
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CX86_DIR0 0xfe
 #define CX86_DIR1 0xff
 #define CX86_ARR_BASE 0xc4
 #define CX86_RCR_BASE 0xdc
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/asm-x86/asm/sembuf.h b/libc/kernel/uapi/asm-x86/asm/sembuf.h
index d1cb296..41d3b2a 100644
--- a/libc/kernel/uapi/asm-x86/asm/sembuf.h
+++ b/libc/kernel/uapi/asm-x86/asm/sembuf.h
@@ -22,13 +22,13 @@
  struct ipc64_perm sem_perm;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __kernel_time_t sem_otime;
- unsigned long __unused1;
+ __kernel_ulong_t __unused1;
  __kernel_time_t sem_ctime;
- unsigned long __unused2;
+ __kernel_ulong_t __unused2;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long sem_nsems;
- unsigned long __unused3;
- unsigned long __unused4;
+ __kernel_ulong_t sem_nsems;
+ __kernel_ulong_t __unused3;
+ __kernel_ulong_t __unused4;
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/signal.h b/libc/kernel/uapi/asm-x86/asm/signal.h
index bba6bc7..308c7a9 100644
--- a/libc/kernel/uapi/asm-x86/asm/signal.h
+++ b/libc/kernel/uapi/asm-x86/asm/signal.h
@@ -24,7 +24,7 @@
 #include <linux/time.h>
 #include <linux/compiler.h>
 struct siginfo;
-#define NSIG 32
+#define _KERNEL_NSIG 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef unsigned long sigset_t;
 #endif
@@ -71,8 +71,8 @@
 #define SIGSYS 31
 #define SIGUNUSED 31
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SIGRTMIN 32
-#define SIGRTMAX _NSIG
+#define __SIGRTMIN 32
+#define __SIGRTMAX _KERNEL__NSIG
 #define SA_NOCLDSTOP 0x00000001u
 #define SA_NOCLDWAIT 0x00000002u
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-x86/asm/stat.h b/libc/kernel/uapi/asm-x86/asm/stat.h
index 0998106..aebacbd 100644
--- a/libc/kernel/uapi/asm-x86/asm/stat.h
+++ b/libc/kernel/uapi/asm-x86/asm/stat.h
@@ -18,116 +18,117 @@
  ****************************************************************************/
 #ifndef _ASM_X86_STAT_H
 #define _ASM_X86_STAT_H
+#include <asm/posix_types.h>
 #define STAT_HAVE_NSEC 1
-#ifdef __i386__
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifdef __i386__
 struct stat {
  unsigned long st_dev;
  unsigned long st_ino;
- unsigned short st_mode;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned short st_mode;
  unsigned short st_nlink;
  unsigned short st_uid;
  unsigned short st_gid;
- unsigned long st_rdev;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long st_rdev;
  unsigned long st_size;
  unsigned long st_blksize;
  unsigned long st_blocks;
- unsigned long st_atime;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long st_atime;
  unsigned long st_atime_nsec;
  unsigned long st_mtime;
  unsigned long st_mtime_nsec;
- unsigned long st_ctime;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long st_ctime;
  unsigned long st_ctime_nsec;
  unsigned long __unused4;
  unsigned long __unused5;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define INIT_STRUCT_STAT_PADDING(st) do {   st.__unused4 = 0;   st.__unused5 = 0;  } while (0)
 #define STAT64_HAS_BROKEN_ST_INO 1
 struct stat64 {
- unsigned long long st_dev;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long long st_dev;
  unsigned char __pad0[4];
  unsigned long __st_ino;
  unsigned int st_mode;
- unsigned int st_nlink;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int st_nlink;
  unsigned long st_uid;
  unsigned long st_gid;
  unsigned long long st_rdev;
- unsigned char __pad3[4];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char __pad3[4];
  long long st_size;
  unsigned long st_blksize;
  unsigned long long st_blocks;
- unsigned long st_atime;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long st_atime;
  unsigned long st_atime_nsec;
  unsigned long st_mtime;
  unsigned int st_mtime_nsec;
- unsigned long st_ctime;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long st_ctime;
  unsigned long st_ctime_nsec;
  unsigned long long st_ino;
 };
-#define INIT_STRUCT_STAT64_PADDING(st) do {   memset(&st.__pad0, 0, sizeof(st.__pad0));   memset(&st.__pad3, 0, sizeof(st.__pad3));  } while (0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define INIT_STRUCT_STAT64_PADDING(st) do {   memset(&st.__pad0, 0, sizeof(st.__pad0));   memset(&st.__pad3, 0, sizeof(st.__pad3));  } while (0)
 #else
 struct stat {
- unsigned long st_dev;
- unsigned long st_ino;
+ __kernel_ulong_t st_dev;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long st_nlink;
+ __kernel_ulong_t st_ino;
+ __kernel_ulong_t st_nlink;
  unsigned int st_mode;
  unsigned int st_uid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int st_gid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int __pad0;
- unsigned long st_rdev;
- long st_size;
- long st_blksize;
+ __kernel_ulong_t st_rdev;
+ __kernel_long_t st_size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long st_blocks;
- unsigned long st_atime;
- unsigned long st_atime_nsec;
- unsigned long st_mtime;
+ __kernel_long_t st_blksize;
+ __kernel_long_t st_blocks;
+ __kernel_ulong_t st_atime;
+ __kernel_ulong_t st_atime_nsec;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long st_mtime_nsec;
- unsigned long st_ctime;
- unsigned long st_ctime_nsec;
- long __linux_unused[3];
+ __kernel_ulong_t st_mtime;
+ __kernel_ulong_t st_mtime_nsec;
+ __kernel_ulong_t st_ctime;
+ __kernel_ulong_t st_ctime_nsec;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __kernel_long_t __linux_unused[3];
 };
-#define INIT_STRUCT_STAT_PADDING(st) do {   st.__pad0 = 0;   st.__unused[0] = 0;   st.__unused[1] = 0;   st.__unused[2] = 0;  } while (0)
+#define INIT_STRUCT_STAT_PADDING(st) do {   st.__pad0 = 0;   st.__linux_unused[0] = 0;   st.__linux_unused[1] = 0;   st.__linux_unused[2] = 0;  } while (0)
 #endif
-struct __old_kernel_stat {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct __old_kernel_stat {
  unsigned short st_dev;
  unsigned short st_ino;
  unsigned short st_mode;
- unsigned short st_nlink;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned short st_nlink;
  unsigned short st_uid;
  unsigned short st_gid;
  unsigned short st_rdev;
-#ifdef __i386__
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifdef __i386__
  unsigned long st_size;
  unsigned long st_atime;
  unsigned long st_mtime;
- unsigned long st_ctime;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long st_ctime;
 #else
  unsigned int st_size;
  unsigned int st_atime;
- unsigned int st_mtime;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int st_mtime;
  unsigned int st_ctime;
 #endif
 };
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/asm-x86/asm/unistd_32.h b/libc/kernel/uapi/asm-x86/asm/unistd_32.h
index 2dd9fc7..4838ae1 100644
--- a/libc/kernel/uapi/asm-x86/asm/unistd_32.h
+++ b/libc/kernel/uapi/asm-x86/asm/unistd_32.h
@@ -452,4 +452,7 @@
 #define __NR_kcmp 349
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_finit_module 350
+#define __NR_sched_setattr 351
+#define __NR_sched_getattr 352
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-x86/asm/unistd_64.h b/libc/kernel/uapi/asm-x86/asm/unistd_64.h
index c545281..7bdb301 100644
--- a/libc/kernel/uapi/asm-x86/asm/unistd_64.h
+++ b/libc/kernel/uapi/asm-x86/asm/unistd_64.h
@@ -411,4 +411,6 @@
 #define __NR_kcmp 312
 #define __NR_finit_module 313
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __NR_sched_setattr 314
+#define __NR_sched_getattr 315
 #endif
diff --git a/libc/kernel/uapi/asm-x86/asm/unistd_x32.h b/libc/kernel/uapi/asm-x86/asm/unistd_x32.h
index e6d3774..ee51fb5 100644
--- a/libc/kernel/uapi/asm-x86/asm/unistd_x32.h
+++ b/libc/kernel/uapi/asm-x86/asm/unistd_x32.h
@@ -358,43 +358,46 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_kcmp (__X32_SYSCALL_BIT + 312)
 #define __NR_finit_module (__X32_SYSCALL_BIT + 313)
+#define __NR_sched_setattr (__X32_SYSCALL_BIT + 314)
+#define __NR_sched_getattr (__X32_SYSCALL_BIT + 315)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
 #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_ioctl (__X32_SYSCALL_BIT + 514)
 #define __NR_readv (__X32_SYSCALL_BIT + 515)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_writev (__X32_SYSCALL_BIT + 516)
 #define __NR_recvfrom (__X32_SYSCALL_BIT + 517)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sendmsg (__X32_SYSCALL_BIT + 518)
 #define __NR_recvmsg (__X32_SYSCALL_BIT + 519)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_execve (__X32_SYSCALL_BIT + 520)
 #define __NR_ptrace (__X32_SYSCALL_BIT + 521)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rt_sigpending (__X32_SYSCALL_BIT + 522)
 #define __NR_rt_sigtimedwait (__X32_SYSCALL_BIT + 523)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rt_sigqueueinfo (__X32_SYSCALL_BIT + 524)
 #define __NR_sigaltstack (__X32_SYSCALL_BIT + 525)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_timer_create (__X32_SYSCALL_BIT + 526)
 #define __NR_mq_notify (__X32_SYSCALL_BIT + 527)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_kexec_load (__X32_SYSCALL_BIT + 528)
 #define __NR_waitid (__X32_SYSCALL_BIT + 529)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_set_robust_list (__X32_SYSCALL_BIT + 530)
 #define __NR_get_robust_list (__X32_SYSCALL_BIT + 531)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_vmsplice (__X32_SYSCALL_BIT + 532)
 #define __NR_move_pages (__X32_SYSCALL_BIT + 533)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_preadv (__X32_SYSCALL_BIT + 534)
 #define __NR_pwritev (__X32_SYSCALL_BIT + 535)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_rt_tgsigqueueinfo (__X32_SYSCALL_BIT + 536)
 #define __NR_recvmmsg (__X32_SYSCALL_BIT + 537)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_sendmmsg (__X32_SYSCALL_BIT + 538)
 #define __NR_process_vm_readv (__X32_SYSCALL_BIT + 539)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_process_vm_writev (__X32_SYSCALL_BIT + 540)
 #define __NR_setsockopt (__X32_SYSCALL_BIT + 541)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __NR_getsockopt (__X32_SYSCALL_BIT + 542)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/asm-x86/asm/vmx.h b/libc/kernel/uapi/asm-x86/asm/vmx.h
index 6c90937..e10e2b6 100644
--- a/libc/kernel/uapi/asm-x86/asm/vmx.h
+++ b/libc/kernel/uapi/asm-x86/asm/vmx.h
@@ -66,11 +66,13 @@
 #define EXIT_REASON_EPT_VIOLATION 48
 #define EXIT_REASON_EPT_MISCONFIG 49
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EXIT_REASON_INVEPT 50
 #define EXIT_REASON_PREEMPTION_TIMER 52
 #define EXIT_REASON_WBINVD 54
 #define EXIT_REASON_XSETBV 55
-#define EXIT_REASON_APIC_WRITE 56
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EXIT_REASON_APIC_WRITE 56
 #define EXIT_REASON_INVPCID 58
-#define VMX_EXIT_REASONS   { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" },   { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" },   { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" },   { EXIT_REASON_PENDING_INTERRUPT, "PENDING_INTERRUPT" },   { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" },   { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" },   { EXIT_REASON_CPUID, "CPUID" },   { EXIT_REASON_HLT, "HLT" },   { EXIT_REASON_INVLPG, "INVLPG" },   { EXIT_REASON_RDPMC, "RDPMC" },   { EXIT_REASON_RDTSC, "RDTSC" },   { EXIT_REASON_VMCALL, "VMCALL" },   { EXIT_REASON_VMCLEAR, "VMCLEAR" },   { EXIT_REASON_VMLAUNCH, "VMLAUNCH" },   { EXIT_REASON_VMPTRLD, "VMPTRLD" },   { EXIT_REASON_VMPTRST, "VMPTRST" },   { EXIT_REASON_VMREAD, "VMREAD" },   { EXIT_REASON_VMRESUME, "VMRESUME" },   { EXIT_REASON_VMWRITE, "VMWRITE" },   { EXIT_REASON_VMOFF, "VMOFF" },   { EXIT_REASON_VMON, "VMON" },   { EXIT_REASON_CR_ACCESS, "CR_ACCESS" },   { EXIT_REASON_DR_ACCESS, "DR_ACCESS" },   { EXIT_REASON_IO_INSTRUCTION, "IO_INSTRUCTION" },   { EXIT_REASON_MSR_READ, "MSR_READ" },   { EXIT_REASON_MSR_WRITE, "MSR_WRITE" },   { EXIT_REASON_MWAIT_INSTRUCTION, "MWAIT_INSTRUCTION" },   { EXIT_REASON_MONITOR_INSTRUCTION, "MONITOR_INSTRUCTION" },   { EXIT_REASON_PAUSE_INSTRUCTION, "PAUSE_INSTRUCTION" },   { EXIT_REASON_MCE_DURING_VMENTRY, "MCE_DURING_VMENTRY" },   { EXIT_REASON_TPR_BELOW_THRESHOLD, "TPR_BELOW_THRESHOLD" },   { EXIT_REASON_APIC_ACCESS, "APIC_ACCESS" },   { EXIT_REASON_EPT_VIOLATION, "EPT_VIOLATION" },   { EXIT_REASON_EPT_MISCONFIG, "EPT_MISCONFIG" },   { EXIT_REASON_WBINVD, "WBINVD" },   { EXIT_REASON_APIC_WRITE, "APIC_WRITE" },   { EXIT_REASON_EOI_INDUCED, "EOI_INDUCED" },   { EXIT_REASON_INVALID_STATE, "INVALID_STATE" },   { EXIT_REASON_INVD, "INVD" },   { EXIT_REASON_INVPCID, "INVPCID" },   { EXIT_REASON_PREEMPTION_TIMER, "PREEMPTION_TIMER" }
+#define VMX_EXIT_REASONS   { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" },   { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" },   { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" },   { EXIT_REASON_PENDING_INTERRUPT, "PENDING_INTERRUPT" },   { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" },   { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" },   { EXIT_REASON_CPUID, "CPUID" },   { EXIT_REASON_HLT, "HLT" },   { EXIT_REASON_INVLPG, "INVLPG" },   { EXIT_REASON_RDPMC, "RDPMC" },   { EXIT_REASON_RDTSC, "RDTSC" },   { EXIT_REASON_VMCALL, "VMCALL" },   { EXIT_REASON_VMCLEAR, "VMCLEAR" },   { EXIT_REASON_VMLAUNCH, "VMLAUNCH" },   { EXIT_REASON_VMPTRLD, "VMPTRLD" },   { EXIT_REASON_VMPTRST, "VMPTRST" },   { EXIT_REASON_VMREAD, "VMREAD" },   { EXIT_REASON_VMRESUME, "VMRESUME" },   { EXIT_REASON_VMWRITE, "VMWRITE" },   { EXIT_REASON_VMOFF, "VMOFF" },   { EXIT_REASON_VMON, "VMON" },   { EXIT_REASON_CR_ACCESS, "CR_ACCESS" },   { EXIT_REASON_DR_ACCESS, "DR_ACCESS" },   { EXIT_REASON_IO_INSTRUCTION, "IO_INSTRUCTION" },   { EXIT_REASON_MSR_READ, "MSR_READ" },   { EXIT_REASON_MSR_WRITE, "MSR_WRITE" },   { EXIT_REASON_MWAIT_INSTRUCTION, "MWAIT_INSTRUCTION" },   { EXIT_REASON_MONITOR_INSTRUCTION, "MONITOR_INSTRUCTION" },   { EXIT_REASON_PAUSE_INSTRUCTION, "PAUSE_INSTRUCTION" },   { EXIT_REASON_MCE_DURING_VMENTRY, "MCE_DURING_VMENTRY" },   { EXIT_REASON_TPR_BELOW_THRESHOLD, "TPR_BELOW_THRESHOLD" },   { EXIT_REASON_APIC_ACCESS, "APIC_ACCESS" },   { EXIT_REASON_EPT_VIOLATION, "EPT_VIOLATION" },   { EXIT_REASON_EPT_MISCONFIG, "EPT_MISCONFIG" },   { EXIT_REASON_INVEPT, "INVEPT" },   { EXIT_REASON_PREEMPTION_TIMER, "PREEMPTION_TIMER" },   { EXIT_REASON_WBINVD, "WBINVD" },   { EXIT_REASON_APIC_WRITE, "APIC_WRITE" },   { EXIT_REASON_EOI_INDUCED, "EOI_INDUCED" },   { EXIT_REASON_INVALID_STATE, "INVALID_STATE" },   { EXIT_REASON_INVD, "INVD" },   { EXIT_REASON_INVPCID, "INVPCID" }
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/drm/armada_drm.h b/libc/kernel/uapi/drm/armada_drm.h
new file mode 100644
index 0000000..efd7dd4
--- /dev/null
+++ b/libc/kernel/uapi/drm/armada_drm.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef DRM_ARMADA_IOCTL_H
+#define DRM_ARMADA_IOCTL_H
+#define DRM_ARMADA_GEM_CREATE 0x00
+#define DRM_ARMADA_GEM_MMAP 0x02
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_ARMADA_GEM_PWRITE 0x03
+#define ARMADA_IOCTL(dir, name, str)   DRM_##dir(DRM_COMMAND_BASE + DRM_ARMADA_##name, struct drm_armada_##str)
+struct drm_armada_gem_create {
+ uint32_t handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t size;
+};
+#define DRM_IOCTL_ARMADA_GEM_CREATE   ARMADA_IOCTL(IOWR, GEM_CREATE, gem_create)
+struct drm_armada_gem_mmap {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t handle;
+ uint32_t pad;
+ uint64_t offset;
+ uint64_t size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint64_t addr;
+};
+#define DRM_IOCTL_ARMADA_GEM_MMAP   ARMADA_IOCTL(IOWR, GEM_MMAP, gem_mmap)
+struct drm_armada_gem_pwrite {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint64_t ptr;
+ uint32_t handle;
+ uint32_t offset;
+ uint32_t size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define DRM_IOCTL_ARMADA_GEM_PWRITE   ARMADA_IOCTL(IOW, GEM_PWRITE, gem_pwrite)
+#endif
diff --git a/libc/kernel/uapi/drm/drm.h b/libc/kernel/uapi/drm/drm.h
index a652685..ed848a8 100644
--- a/libc/kernel/uapi/drm/drm.h
+++ b/libc/kernel/uapi/drm/drm.h
@@ -128,336 +128,356 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_SCATTER_GATHER = 4,
  _DRM_CONSISTENT = 5,
- _DRM_GEM = 6,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum drm_map_flags {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_RESTRICTED = 0x01,
  _DRM_READ_ONLY = 0x02,
  _DRM_LOCKED = 0x04,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_KERNEL = 0x08,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_WRITE_COMBINING = 0x10,
  _DRM_CONTAINS_LOCK = 0x20,
  _DRM_REMOVABLE = 0x40,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_DRIVER = 0x80
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_ctx_priv_map {
  unsigned int ctx_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  void *handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_map {
  unsigned long offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  enum drm_map_type type;
  enum drm_map_flags flags;
  void *handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int mtrr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_client {
  int idx;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int auth;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long pid;
  unsigned long uid;
  unsigned long magic;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long iocs;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum drm_stat_type {
  _DRM_STAT_LOCK,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_STAT_OPENS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_STAT_CLOSES,
  _DRM_STAT_IOCTLS,
  _DRM_STAT_LOCKS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_STAT_UNLOCKS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_STAT_VALUE,
  _DRM_STAT_BYTE,
  _DRM_STAT_COUNT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_STAT_IRQ,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_STAT_PRIMARY,
  _DRM_STAT_SECONDARY,
  _DRM_STAT_DMA,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_STAT_SPECIAL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_STAT_MISSED
 };
 struct drm_stats {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  unsigned long value;
  enum drm_stat_type type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } data[15];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum drm_lock_flags {
  _DRM_LOCK_READY = 0x01,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_LOCK_QUIESCENT = 0x02,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_LOCK_FLUSH = 0x04,
  _DRM_LOCK_FLUSH_ALL = 0x08,
  _DRM_HALT_ALL_QUEUES = 0x10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_HALT_CUR_QUEUES = 0x20
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_lock {
  int context;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  enum drm_lock_flags flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum drm_dma_flags {
  _DRM_DMA_BLOCK = 0x01,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_DMA_WHILE_LOCKED = 0x02,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_DMA_PRIORITY = 0x04,
  _DRM_DMA_WAIT = 0x10,
  _DRM_DMA_SMALLER_OK = 0x20,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_DMA_LARGER_OK = 0x40
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_buf_desc {
  int count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int low_mark;
  int high_mark;
  enum {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_PAGE_ALIGN = 0x01,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_AGP_BUFFER = 0x02,
  _DRM_SG_BUFFER = 0x04,
  _DRM_FB_BUFFER = 0x08,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_PCI_BUFFER_RO = 0x10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } flags;
  unsigned long agp_start;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_buf_info {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int count;
  struct drm_buf_desc __user *list;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_buf_free {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int count;
  int __user *list;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_buf_pub {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int idx;
  int total;
  int used;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  void __user *address;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_buf_map {
  int count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  void __user *virtual;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct drm_buf_pub __user *list;
 };
 struct drm_dma {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int context;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int send_count;
  int __user *send_indices;
  int __user *send_sizes;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  enum drm_dma_flags flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int request_count;
  int request_size;
  int __user *request_indices;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int __user *request_sizes;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int granted_count;
 };
 enum drm_ctx_flags {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_CONTEXT_PRESERVED = 0x01,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_CONTEXT_2DONLY = 0x02
 };
 struct drm_ctx {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  drm_context_t handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  enum drm_ctx_flags flags;
 };
 struct drm_ctx_res {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct drm_ctx __user *contexts;
 };
 struct drm_draw {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  drm_drawable_t handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 typedef enum {
  DRM_DRAWABLE_CLIPRECTS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } drm_drawable_info_type_t;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_update_draw {
  drm_drawable_t handle;
  unsigned int type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long long data;
 };
 struct drm_auth {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  drm_magic_t magic;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_irq_busid {
  int irq;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int busnum;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int devnum;
  int funcnum;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum drm_vblank_seq_type {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_VBLANK_ABSOLUTE = 0x0,
  _DRM_VBLANK_RELATIVE = 0x1,
  _DRM_VBLANK_HIGH_CRTC_MASK = 0x0000003e,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_VBLANK_EVENT = 0x4000000,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_VBLANK_FLIP = 0x8000000,
  _DRM_VBLANK_NEXTONMISS = 0x10000000,
  _DRM_VBLANK_SECONDARY = 0x20000000,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  _DRM_VBLANK_SIGNAL = 0x40000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define _DRM_VBLANK_HIGH_CRTC_SHIFT 1
 #define _DRM_VBLANK_TYPES_MASK (_DRM_VBLANK_ABSOLUTE | _DRM_VBLANK_RELATIVE)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define _DRM_VBLANK_FLAGS_MASK (_DRM_VBLANK_EVENT | _DRM_VBLANK_SIGNAL |   _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_wait_vblank_request {
  enum drm_vblank_seq_type type;
  unsigned int sequence;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long signal;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_wait_vblank_reply {
  enum drm_vblank_seq_type type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int sequence;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  long tval_sec;
  long tval_usec;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 union drm_wait_vblank {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct drm_wait_vblank_request request;
  struct drm_wait_vblank_reply reply;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define _DRM_PRE_MODESET 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define _DRM_POST_MODESET 2
 struct drm_modeset_ctl {
  __u32 crtc;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cmd;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_agp_mode {
  unsigned long mode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_agp_buffer {
  unsigned long size;
  unsigned long handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long physical;
 };
 struct drm_agp_binding {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long offset;
 };
 struct drm_agp_info {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int agp_version_major;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int agp_version_minor;
  unsigned long mode;
  unsigned long aperture_base;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long aperture_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long memory_allowed;
  unsigned long memory_used;
  unsigned short id_vendor;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned short id_device;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_scatter_gather {
  unsigned long size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_set_version {
  int drm_di_major;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int drm_di_minor;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int drm_dd_major;
  int drm_dd_minor;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_gem_close {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
  __u32 pad;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_gem_flink {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
  __u32 name;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_gem_open {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 name;
  __u32 handle;
  __u64 size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_CAP_DUMB_BUFFER 0x1
+#define DRM_CAP_VBLANK_HIGH_CRTC 0x2
+#define DRM_CAP_DUMB_PREFERRED_DEPTH 0x3
+#define DRM_CAP_DUMB_PREFER_SHADOW 0x4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_CAP_PRIME 0x5
+#define DRM_PRIME_CAP_IMPORT 0x1
+#define DRM_PRIME_CAP_EXPORT 0x2
+#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_CAP_ASYNC_PAGE_FLIP 0x7
+#define DRM_CAP_CURSOR_WIDTH 0x8
+#define DRM_CAP_CURSOR_HEIGHT 0x9
 struct drm_get_cap {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 capability;
  __u64 value;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+#define DRM_CLIENT_CAP_STEREO_3D 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_set_client_cap {
+ __u64 capability;
+ __u64 value;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_CLOEXEC O_CLOEXEC
 struct drm_prime_handle {
  __u32 handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 fd;
 };
 #include <drm/drm_mode.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_BASE 'd'
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IO(nr) _IO(DRM_IOCTL_BASE,nr)
 #define DRM_IOR(nr,type) _IOR(DRM_IOCTL_BASE,nr,type)
 #define DRM_IOW(nr,type) _IOW(DRM_IOCTL_BASE,nr,type)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOWR(nr,type) _IOWR(DRM_IOCTL_BASE,nr,type)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_VERSION DRM_IOWR(0x00, struct drm_version)
 #define DRM_IOCTL_GET_UNIQUE DRM_IOWR(0x01, struct drm_unique)
 #define DRM_IOCTL_GET_MAGIC DRM_IOR( 0x02, struct drm_auth)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_IRQ_BUSID DRM_IOWR(0x03, struct drm_irq_busid)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_GET_MAP DRM_IOWR(0x04, struct drm_map)
 #define DRM_IOCTL_GET_CLIENT DRM_IOWR(0x05, struct drm_client)
 #define DRM_IOCTL_GET_STATS DRM_IOR( 0x06, struct drm_stats)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_SET_VERSION DRM_IOWR(0x07, struct drm_set_version)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_MODESET_CTL DRM_IOW(0x08, struct drm_modeset_ctl)
 #define DRM_IOCTL_GEM_CLOSE DRM_IOW (0x09, struct drm_gem_close)
 #define DRM_IOCTL_GEM_FLINK DRM_IOWR(0x0a, struct drm_gem_flink)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_GEM_OPEN DRM_IOWR(0x0b, struct drm_gem_open)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_GET_CAP DRM_IOWR(0x0c, struct drm_get_cap)
+#define DRM_IOCTL_SET_CLIENT_CAP DRM_IOW( 0x0d, struct drm_set_client_cap)
 #define DRM_IOCTL_SET_UNIQUE DRM_IOW( 0x10, struct drm_unique)
 #define DRM_IOCTL_AUTH_MAGIC DRM_IOW( 0x11, struct drm_auth)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -546,84 +566,75 @@
 #define DRM_IOCTL_MODE_OBJ_GETPROPERTIES DRM_IOWR(0xB9, struct drm_mode_obj_get_properties)
 #define DRM_IOCTL_MODE_OBJ_SETPROPERTY DRM_IOWR(0xBA, struct drm_mode_obj_set_property)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_IOCTL_MODE_CURSOR2 DRM_IOWR(0xBB, struct drm_mode_cursor2)
 #define DRM_COMMAND_BASE 0x40
 #define DRM_COMMAND_END 0xA0
 struct drm_event {
- __u32 type;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 type;
  __u32 length;
 };
 #define DRM_EVENT_VBLANK 0x01
-#define DRM_EVENT_FLIP_COMPLETE 0x02
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_EVENT_FLIP_COMPLETE 0x02
 struct drm_event_vblank {
  struct drm_event base;
  __u64 user_data;
- __u32 tv_sec;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tv_sec;
  __u32 tv_usec;
  __u32 sequence;
  __u32 reserved;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define DRM_CAP_DUMB_BUFFER 0x1
-#define DRM_CAP_VBLANK_HIGH_CRTC 0x2
-#define DRM_CAP_DUMB_PREFERRED_DEPTH 0x3
-#define DRM_CAP_DUMB_PREFER_SHADOW 0x4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define DRM_CAP_PRIME 0x5
-#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
-#define DRM_PRIME_CAP_IMPORT 0x1
-#define DRM_PRIME_CAP_EXPORT 0x2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef struct drm_clip_rect drm_clip_rect_t;
 typedef struct drm_drawable_info drm_drawable_info_t;
 typedef struct drm_tex_region drm_tex_region_t;
-typedef struct drm_hw_lock drm_hw_lock_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_hw_lock drm_hw_lock_t;
 typedef struct drm_version drm_version_t;
 typedef struct drm_unique drm_unique_t;
 typedef struct drm_list drm_list_t;
-typedef struct drm_block drm_block_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_block drm_block_t;
 typedef struct drm_control drm_control_t;
 typedef enum drm_map_type drm_map_type_t;
 typedef enum drm_map_flags drm_map_flags_t;
-typedef struct drm_ctx_priv_map drm_ctx_priv_map_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_ctx_priv_map drm_ctx_priv_map_t;
 typedef struct drm_map drm_map_t;
 typedef struct drm_client drm_client_t;
 typedef enum drm_stat_type drm_stat_type_t;
-typedef struct drm_stats drm_stats_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_stats drm_stats_t;
 typedef enum drm_lock_flags drm_lock_flags_t;
 typedef struct drm_lock drm_lock_t;
 typedef enum drm_dma_flags drm_dma_flags_t;
-typedef struct drm_buf_desc drm_buf_desc_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_buf_desc drm_buf_desc_t;
 typedef struct drm_buf_info drm_buf_info_t;
 typedef struct drm_buf_free drm_buf_free_t;
 typedef struct drm_buf_pub drm_buf_pub_t;
-typedef struct drm_buf_map drm_buf_map_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_buf_map drm_buf_map_t;
 typedef struct drm_dma drm_dma_t;
 typedef union drm_wait_vblank drm_wait_vblank_t;
 typedef struct drm_agp_mode drm_agp_mode_t;
-typedef enum drm_ctx_flags drm_ctx_flags_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef enum drm_ctx_flags drm_ctx_flags_t;
 typedef struct drm_ctx drm_ctx_t;
 typedef struct drm_ctx_res drm_ctx_res_t;
 typedef struct drm_draw drm_draw_t;
-typedef struct drm_update_draw drm_update_draw_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_update_draw drm_update_draw_t;
 typedef struct drm_auth drm_auth_t;
 typedef struct drm_irq_busid drm_irq_busid_t;
 typedef enum drm_vblank_seq_type drm_vblank_seq_type_t;
-typedef struct drm_agp_buffer drm_agp_buffer_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_agp_buffer drm_agp_buffer_t;
 typedef struct drm_agp_binding drm_agp_binding_t;
 typedef struct drm_agp_info drm_agp_info_t;
 typedef struct drm_scatter_gather drm_scatter_gather_t;
-typedef struct drm_set_version drm_set_version_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_set_version drm_set_version_t;
 #endif
diff --git a/libc/kernel/uapi/drm/drm_mode.h b/libc/kernel/uapi/drm/drm_mode.h
index 6b006a6..bbe1c8e 100644
--- a/libc/kernel/uapi/drm/drm_mode.h
+++ b/libc/kernel/uapi/drm/drm_mode.h
@@ -51,139 +51,154 @@
 #define DRM_MODE_FLAG_DBLCLK (1<<12)
 #define DRM_MODE_FLAG_CLKDIV2 (1<<13)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MODE_FLAG_3D_MASK (0x1f<<14)
+#define DRM_MODE_FLAG_3D_NONE (0<<14)
+#define DRM_MODE_FLAG_3D_FRAME_PACKING (1<<14)
+#define DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE (2<<14)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MODE_FLAG_3D_LINE_ALTERNATIVE (3<<14)
+#define DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL (4<<14)
+#define DRM_MODE_FLAG_3D_L_DEPTH (5<<14)
+#define DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH (6<<14)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MODE_FLAG_3D_TOP_AND_BOTTOM (7<<14)
+#define DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF (8<<14)
 #define DRM_MODE_DPMS_ON 0
 #define DRM_MODE_DPMS_STANDBY 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_DPMS_SUSPEND 2
 #define DRM_MODE_DPMS_OFF 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_SCALE_NONE 0
 #define DRM_MODE_SCALE_FULLSCREEN 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_SCALE_CENTER 2
 #define DRM_MODE_SCALE_ASPECT 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_DITHERING_OFF 0
 #define DRM_MODE_DITHERING_ON 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_DITHERING_AUTO 2
 #define DRM_MODE_DIRTY_OFF 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_DIRTY_ON 1
 #define DRM_MODE_DIRTY_ANNOTATE 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_mode_modeinfo {
  __u32 clock;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 hdisplay, hsync_start, hsync_end, htotal, hskew;
  __u16 vdisplay, vsync_start, vsync_end, vtotal, vscan;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 vrefresh;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  char name[DRM_DISPLAY_MODE_LEN];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_mode_card_res {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 fb_id_ptr;
  __u64 crtc_id_ptr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 connector_id_ptr;
  __u64 encoder_id_ptr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 count_fbs;
  __u32 count_crtcs;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 count_connectors;
  __u32 count_encoders;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 min_width, max_width;
  __u32 min_height, max_height;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_mode_crtc {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 set_connectors_ptr;
  __u32 count_connectors;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 crtc_id;
  __u32 fb_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 x, y;
  __u32 gamma_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mode_valid;
  struct drm_mode_modeinfo mode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define DRM_MODE_PRESENT_TOP_FIELD (1<<0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_PRESENT_BOTTOM_FIELD (1<<1)
 struct drm_mode_set_plane {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 plane_id;
  __u32 crtc_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 fb_id;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 crtc_x, crtc_y;
  __u32 crtc_w, crtc_h;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 src_x, src_y;
  __u32 src_h, src_w;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_mode_get_plane {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 plane_id;
  __u32 crtc_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 fb_id;
  __u32 possible_crtcs;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 gamma_size;
  __u32 count_format_types;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 format_type_ptr;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_mode_get_plane_res {
  __u64 plane_id_ptr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 count_planes;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_ENCODER_NONE 0
 #define DRM_MODE_ENCODER_DAC 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_ENCODER_TMDS 2
 #define DRM_MODE_ENCODER_LVDS 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_ENCODER_TVDAC 4
 #define DRM_MODE_ENCODER_VIRTUAL 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MODE_ENCODER_DSI 6
 struct drm_mode_get_encoder {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 encoder_id;
  __u32 encoder_type;
  __u32 crtc_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 possible_crtcs;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 possible_clones;
 };
 #define DRM_MODE_SUBCONNECTOR_Automatic 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_SUBCONNECTOR_Unknown 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_SUBCONNECTOR_DVID 3
 #define DRM_MODE_SUBCONNECTOR_DVIA 4
 #define DRM_MODE_SUBCONNECTOR_Composite 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_SUBCONNECTOR_SVIDEO 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_SUBCONNECTOR_Component 8
 #define DRM_MODE_SUBCONNECTOR_SCART 9
 #define DRM_MODE_CONNECTOR_Unknown 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_CONNECTOR_VGA 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_CONNECTOR_DVII 2
 #define DRM_MODE_CONNECTOR_DVID 3
 #define DRM_MODE_CONNECTOR_DVIA 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_CONNECTOR_Composite 5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_CONNECTOR_SVIDEO 6
 #define DRM_MODE_CONNECTOR_LVDS 7
 #define DRM_MODE_CONNECTOR_Component 8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_CONNECTOR_9PinDIN 9
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_CONNECTOR_DisplayPort 10
 #define DRM_MODE_CONNECTOR_HDMIA 11
 #define DRM_MODE_CONNECTOR_HDMIB 12
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_CONNECTOR_TV 13
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_MODE_CONNECTOR_eDP 14
 #define DRM_MODE_CONNECTOR_VIRTUAL 15
+#define DRM_MODE_CONNECTOR_DSI 16
 struct drm_mode_get_connector {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 encoders_ptr;
@@ -203,116 +218,131 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mm_width, mm_height;
  __u32 subpixel;
+ __u32 pad;
 };
-#define DRM_MODE_PROP_PENDING (1<<0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MODE_PROP_PENDING (1<<0)
 #define DRM_MODE_PROP_RANGE (1<<1)
 #define DRM_MODE_PROP_IMMUTABLE (1<<2)
 #define DRM_MODE_PROP_ENUM (1<<3)
-#define DRM_MODE_PROP_BLOB (1<<4)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MODE_PROP_BLOB (1<<4)
 #define DRM_MODE_PROP_BITMASK (1<<5)
 struct drm_mode_property_enum {
  __u64 value;
- char name[DRM_PROP_NAME_LEN];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ char name[DRM_PROP_NAME_LEN];
 };
 struct drm_mode_get_property {
  __u64 values_ptr;
- __u64 enum_blob_ptr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 enum_blob_ptr;
  __u32 prop_id;
  __u32 flags;
  char name[DRM_PROP_NAME_LEN];
- __u32 count_values;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 count_values;
  __u32 count_enum_blobs;
 };
 struct drm_mode_connector_set_property {
- __u64 value;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 value;
  __u32 prop_id;
  __u32 connector_id;
 };
-struct drm_mode_obj_get_properties {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_mode_obj_get_properties {
  __u64 props_ptr;
  __u64 prop_values_ptr;
  __u32 count_props;
- __u32 obj_id;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 obj_id;
  __u32 obj_type;
 };
 struct drm_mode_obj_set_property {
- __u64 value;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 value;
  __u32 prop_id;
  __u32 obj_id;
  __u32 obj_type;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct drm_mode_get_blob {
  __u32 blob_id;
  __u32 length;
- __u64 data;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 data;
 };
 struct drm_mode_fb_cmd {
  __u32 fb_id;
- __u32 width, height;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 width, height;
  __u32 pitch;
  __u32 bpp;
  __u32 depth;
- __u32 handle;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 handle;
 };
 #define DRM_MODE_FB_INTERLACED (1<<0)
 struct drm_mode_fb_cmd2 {
- __u32 fb_id;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 fb_id;
  __u32 width, height;
  __u32 pixel_format;
  __u32 flags;
- __u32 handles[4];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 handles[4];
  __u32 pitches[4];
  __u32 offsets[4];
 };
-#define DRM_MODE_FB_DIRTY_ANNOTATE_COPY 0x01
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MODE_FB_DIRTY_ANNOTATE_COPY 0x01
 #define DRM_MODE_FB_DIRTY_ANNOTATE_FILL 0x02
 #define DRM_MODE_FB_DIRTY_FLAGS 0x03
 #define DRM_MODE_FB_DIRTY_MAX_CLIPS 256
-struct drm_mode_fb_dirty_cmd {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_mode_fb_dirty_cmd {
  __u32 fb_id;
  __u32 flags;
  __u32 color;
- __u32 num_clips;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 num_clips;
  __u64 clips_ptr;
 };
 struct drm_mode_mode_cmd {
- __u32 connector_id;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 connector_id;
  struct drm_mode_modeinfo mode;
 };
 #define DRM_MODE_CURSOR_BO 0x01
-#define DRM_MODE_CURSOR_MOVE 0x02
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MODE_CURSOR_MOVE 0x02
 #define DRM_MODE_CURSOR_FLAGS 0x03
 struct drm_mode_cursor {
  __u32 flags;
- __u32 crtc_id;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 crtc_id;
  __s32 x;
  __s32 y;
  __u32 width;
- __u32 height;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 height;
  __u32 handle;
 };
+struct drm_mode_cursor2 {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 flags;
+ __u32 crtc_id;
+ __s32 x;
+ __s32 y;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 width;
+ __u32 height;
+ __u32 handle;
+ __s32 hot_x;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s32 hot_y;
+};
 struct drm_mode_crtc_lut {
  __u32 crtc_id;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -323,36 +353,37 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define DRM_MODE_PAGE_FLIP_EVENT 0x01
-#define DRM_MODE_PAGE_FLIP_FLAGS DRM_MODE_PAGE_FLIP_EVENT
-struct drm_mode_crtc_page_flip {
+#define DRM_MODE_PAGE_FLIP_ASYNC 0x02
+#define DRM_MODE_PAGE_FLIP_FLAGS (DRM_MODE_PAGE_FLIP_EVENT|DRM_MODE_PAGE_FLIP_ASYNC)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_mode_crtc_page_flip {
  __u32 crtc_id;
  __u32 fb_id;
  __u32 flags;
- __u32 reserved;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 reserved;
  __u64 user_data;
 };
 struct drm_mode_create_dumb {
- uint32_t height;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t height;
  uint32_t width;
  uint32_t bpp;
  uint32_t flags;
- uint32_t handle;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t handle;
  uint32_t pitch;
  uint64_t size;
 };
-struct drm_mode_map_dumb {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_mode_map_dumb {
  __u32 handle;
  __u32 pad;
  __u64 offset;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct drm_mode_destroy_dumb {
  uint32_t handle;
 };
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/drm/i915_drm.h b/libc/kernel/uapi/drm/i915_drm.h
index 3e53328..7b9810c 100644
--- a/libc/kernel/uapi/drm/i915_drm.h
+++ b/libc/kernel/uapi/drm/i915_drm.h
@@ -19,177 +19,182 @@
 #ifndef _UAPI_I915_DRM_H_
 #define _UAPI_I915_DRM_H_
 #include <drm/drm.h>
-#define I915_NR_TEX_REGIONS 255
+#define I915_L3_PARITY_UEVENT "L3_PARITY_ERROR"
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_ERROR_UEVENT "ERROR"
+#define I915_RESET_UEVENT "RESET"
+#define I915_NR_TEX_REGIONS 255
 #define I915_LOG_MIN_TEX_REGION_SIZE 14
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef struct _drm_i915_init {
  enum {
  I915_INIT_DMA = 0x01,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  I915_CLEANUP_DMA = 0x02,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  I915_RESUME_DMA = 0x03
  } func;
  unsigned int mmio_offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int sarea_priv_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int ring_start;
  unsigned int ring_end;
  unsigned int ring_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int front_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int back_offset;
  unsigned int depth_offset;
  unsigned int w;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int h;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int pitch;
  unsigned int pitch_bits;
  unsigned int back_pitch;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int depth_pitch;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int cpp;
  unsigned int chipset;
 } drm_i915_init_t;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef struct _drm_i915_sarea {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct drm_tex_region texList[I915_NR_TEX_REGIONS + 1];
  int last_upload;
  int last_enqueue;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int last_dispatch;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int ctxOwner;
  int texAge;
  int pf_enabled;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int pf_active;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int pf_current_page;
  int perf_boxes;
  int width, height;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  drm_handle_t front_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int front_offset;
  int front_size;
  drm_handle_t back_handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int back_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int back_size;
  drm_handle_t depth_handle;
  int depth_offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int depth_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  drm_handle_t tex_handle;
  int tex_offset;
  int tex_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int log_tex_granularity;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int pitch;
  int rotation;
  int rotated_offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int rotated_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int rotated_pitch;
  int virtualX, virtualY;
  unsigned int front_tiled;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int back_tiled;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int depth_tiled;
  unsigned int rotated_tiled;
  unsigned int rotated2_tiled;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int pipeA_x;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int pipeA_y;
  int pipeA_w;
  int pipeA_h;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int pipeB_x;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int pipeB_y;
  int pipeB_w;
  int pipeB_h;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  drm_handle_t unused_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 unused1, unused2, unused3;
  __u32 front_bo_handle;
  __u32 back_bo_handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 unused_bo_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 depth_bo_handle;
 } drm_i915_sarea_t;
 #define planeA_x pipeA_x
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define planeA_y pipeA_y
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define planeA_w pipeA_w
 #define planeA_h pipeA_h
 #define planeB_x pipeB_x
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define planeB_y pipeB_y
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define planeB_w pipeB_w
 #define planeB_h pipeB_h
 #define I915_BOX_RING_EMPTY 0x1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_BOX_FLIP 0x2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_BOX_WAIT 0x4
 #define I915_BOX_TEXTURE_LOAD 0x8
 #define I915_BOX_LOST_CONTEXT 0x10
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_INIT 0x00
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_FLUSH 0x01
 #define DRM_I915_FLIP 0x02
 #define DRM_I915_BATCHBUFFER 0x03
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_IRQ_EMIT 0x04
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_IRQ_WAIT 0x05
 #define DRM_I915_GETPARAM 0x06
 #define DRM_I915_SETPARAM 0x07
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_ALLOC 0x08
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_FREE 0x09
 #define DRM_I915_INIT_HEAP 0x0a
 #define DRM_I915_CMDBUFFER 0x0b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_DESTROY_HEAP 0x0c
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_SET_VBLANK_PIPE 0x0d
 #define DRM_I915_GET_VBLANK_PIPE 0x0e
 #define DRM_I915_VBLANK_SWAP 0x0f
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_HWS_ADDR 0x11
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_INIT 0x13
 #define DRM_I915_GEM_EXECBUFFER 0x14
 #define DRM_I915_GEM_PIN 0x15
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_UNPIN 0x16
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_BUSY 0x17
 #define DRM_I915_GEM_THROTTLE 0x18
 #define DRM_I915_GEM_ENTERVT 0x19
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_LEAVEVT 0x1a
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_CREATE 0x1b
 #define DRM_I915_GEM_PREAD 0x1c
 #define DRM_I915_GEM_PWRITE 0x1d
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_MMAP 0x1e
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_SET_DOMAIN 0x1f
 #define DRM_I915_GEM_SW_FINISH 0x20
 #define DRM_I915_GEM_SET_TILING 0x21
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_GET_TILING 0x22
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_GET_APERTURE 0x23
 #define DRM_I915_GEM_MMAP_GTT 0x24
 #define DRM_I915_GET_PIPE_FROM_CRTC_ID 0x25
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_MADVISE 0x26
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_OVERLAY_PUT_IMAGE 0x27
 #define DRM_I915_OVERLAY_ATTRS 0x28
 #define DRM_I915_GEM_EXECBUFFER2 0x29
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GET_SPRITE_COLORKEY 0x2a
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_SET_SPRITE_COLORKEY 0x2b
 #define DRM_I915_GEM_WAIT 0x2c
 #define DRM_I915_GEM_CONTEXT_CREATE 0x2d
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_CONTEXT_DESTROY 0x2e
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_GEM_SET_CACHING 0x2f
 #define DRM_I915_GEM_GET_CACHING 0x30
 #define DRM_I915_REG_READ 0x31
+#define DRM_I915_GET_RESET_STATS 0x32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -251,290 +256,295 @@
 #define DRM_IOCTL_I915_GEM_CONTEXT_DESTROY DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_DESTROY, struct drm_i915_gem_context_destroy)
 #define DRM_IOCTL_I915_REG_READ DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_REG_READ, struct drm_i915_reg_read)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_IOCTL_I915_GET_RESET_STATS DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GET_RESET_STATS, struct drm_i915_reset_stats)
 typedef struct drm_i915_batchbuffer {
  int start;
  int used;
- int DR1;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int DR1;
  int DR4;
  int num_cliprects;
  struct drm_clip_rect __user *cliprects;
-} drm_i915_batchbuffer_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+} drm_i915_batchbuffer_t;
 typedef struct _drm_i915_cmdbuffer {
  char __user *buf;
  int sz;
- int DR1;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int DR1;
  int DR4;
  int num_cliprects;
  struct drm_clip_rect __user *cliprects;
-} drm_i915_cmdbuffer_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+} drm_i915_cmdbuffer_t;
 typedef struct drm_i915_irq_emit {
  int __user *irq_seq;
 } drm_i915_irq_emit_t;
-typedef struct drm_i915_irq_wait {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct drm_i915_irq_wait {
  int irq_seq;
 } drm_i915_irq_wait_t;
 #define I915_PARAM_IRQ_ACTIVE 1
-#define I915_PARAM_ALLOW_BATCHBUFFER 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_PARAM_ALLOW_BATCHBUFFER 2
 #define I915_PARAM_LAST_DISPATCH 3
 #define I915_PARAM_CHIPSET_ID 4
 #define I915_PARAM_HAS_GEM 5
-#define I915_PARAM_NUM_FENCES_AVAIL 6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_PARAM_NUM_FENCES_AVAIL 6
 #define I915_PARAM_HAS_OVERLAY 7
 #define I915_PARAM_HAS_PAGEFLIPPING 8
 #define I915_PARAM_HAS_EXECBUF2 9
-#define I915_PARAM_HAS_BSD 10
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_PARAM_HAS_BSD 10
 #define I915_PARAM_HAS_BLT 11
 #define I915_PARAM_HAS_RELAXED_FENCING 12
 #define I915_PARAM_HAS_COHERENT_RINGS 13
-#define I915_PARAM_HAS_EXEC_CONSTANTS 14
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_PARAM_HAS_EXEC_CONSTANTS 14
 #define I915_PARAM_HAS_RELAXED_DELTA 15
 #define I915_PARAM_HAS_GEN7_SOL_RESET 16
 #define I915_PARAM_HAS_LLC 17
-#define I915_PARAM_HAS_ALIASING_PPGTT 18
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_PARAM_HAS_ALIASING_PPGTT 18
 #define I915_PARAM_HAS_WAIT_TIMEOUT 19
 #define I915_PARAM_HAS_SEMAPHORES 20
 #define I915_PARAM_HAS_PRIME_VMAP_FLUSH 21
-#define I915_PARAM_RSVD_FOR_FUTURE_USE 22
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_PARAM_HAS_VEBOX 22
 #define I915_PARAM_HAS_SECURE_BATCHES 23
 #define I915_PARAM_HAS_PINNED_BATCHES 24
 #define I915_PARAM_HAS_EXEC_NO_RELOC 25
-#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26
+#define I915_PARAM_HAS_WT 27
 typedef struct drm_i915_getparam {
  int param;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int __user *value;
 } drm_i915_getparam_t;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_SETPARAM_USE_MI_BATCHBUFFER_START 1
 #define I915_SETPARAM_TEX_LRU_LOG_GRANULARITY 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_SETPARAM_ALLOW_BATCHBUFFER 3
 #define I915_SETPARAM_NUM_USED_FENCES 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef struct drm_i915_setparam {
  int param;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int value;
 } drm_i915_setparam_t;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_MEM_REGION_AGP 1
 typedef struct drm_i915_mem_alloc {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int region;
  int alignment;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int size;
  int __user *region_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } drm_i915_mem_alloc_t;
 typedef struct drm_i915_mem_free {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int region;
  int region_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } drm_i915_mem_free_t;
 typedef struct drm_i915_mem_init_heap {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int region;
  int size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int start;
 } drm_i915_mem_init_heap_t;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef struct drm_i915_mem_destroy_heap {
  int region;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } drm_i915_mem_destroy_heap_t;
 #define DRM_I915_VBLANK_PIPE_A 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_I915_VBLANK_PIPE_B 2
 typedef struct drm_i915_vblank_pipe {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int pipe;
 } drm_i915_vblank_pipe_t;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef struct drm_i915_vblank_swap {
  drm_drawable_t drawable;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  enum drm_vblank_seq_type seqtype;
  unsigned int sequence;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } drm_i915_vblank_swap_t;
 typedef struct drm_i915_hws_addr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 addr;
 } drm_i915_hws_addr_t;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_i915_gem_init {
  __u64 gtt_start;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 gtt_end;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_i915_gem_create {
  __u64 size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
  __u32 pad;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_pread {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
  __u32 pad;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 offset;
  __u64 size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 data_ptr;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_i915_gem_pwrite {
  __u32 handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pad;
  __u64 offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 size;
  __u64 data_ptr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_mmap {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
  __u32 pad;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 offset;
  __u64 size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 addr_ptr;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_i915_gem_mmap_gtt {
  __u32 handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pad;
  __u64 offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_set_domain {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
  __u32 read_domains;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 write_domain;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_i915_gem_sw_finish {
  __u32 handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_relocation_entry {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 target_handle;
  __u32 delta;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 offset;
  __u64 presumed_offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 read_domains;
  __u32 write_domain;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define I915_GEM_DOMAIN_CPU 0x00000001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_GEM_DOMAIN_RENDER 0x00000002
 #define I915_GEM_DOMAIN_SAMPLER 0x00000004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_GEM_DOMAIN_COMMAND 0x00000008
 #define I915_GEM_DOMAIN_INSTRUCTION 0x00000010
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_GEM_DOMAIN_VERTEX 0x00000020
 #define I915_GEM_DOMAIN_GTT 0x00000040
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_i915_gem_exec_object {
  __u32 handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 relocation_count;
  __u64 relocs_ptr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 alignment;
  __u64 offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_execbuffer {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 buffers_ptr;
  __u32 buffer_count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 batch_start_offset;
  __u32 batch_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 DR1;
  __u32 DR4;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 num_cliprects;
  __u64 cliprects_ptr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_exec_object2 {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
  __u32 relocation_count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 relocs_ptr;
  __u64 alignment;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 offset;
 #define EXEC_OBJECT_NEEDS_FENCE (1<<0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define EXEC_OBJECT_NEEDS_GTT (1<<1)
 #define EXEC_OBJECT_WRITE (1<<2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __EXEC_OBJECT_UNKNOWN_FLAGS -(EXEC_OBJECT_WRITE<<1)
  __u64 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 rsvd1;
  __u64 rsvd2;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_execbuffer2 {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 buffers_ptr;
  __u32 buffer_count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 batch_start_offset;
  __u32 batch_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 DR1;
  __u32 DR4;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 num_cliprects;
  __u64 cliprects_ptr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_EXEC_RING_MASK (7<<0)
 #define I915_EXEC_DEFAULT (0<<0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_EXEC_RENDER (1<<0)
 #define I915_EXEC_BSD (2<<0)
-#define I915_EXEC_BLT (3<<0)
-#define I915_EXEC_CONSTANTS_MASK (3<<6)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I915_EXEC_BLT (3<<0)
+#define I915_EXEC_VEBOX (4<<0)
+#define I915_EXEC_CONSTANTS_MASK (3<<6)
 #define I915_EXEC_CONSTANTS_REL_GENERAL (0<<6)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_EXEC_CONSTANTS_ABSOLUTE (1<<6)
 #define I915_EXEC_CONSTANTS_REL_SURFACE (2<<6)
  __u64 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 rsvd1;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 rsvd2;
 };
 #define I915_EXEC_GEN7_SOL_RESET (1<<8)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_EXEC_SECURE (1<<9)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_EXEC_IS_PINNED (1<<10)
 #define I915_EXEC_NO_RELOC (1<<11)
 #define I915_EXEC_HANDLE_LUT (1<<12)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __I915_EXEC_UNKNOWN_FLAGS -(I915_EXEC_HANDLE_LUT<<1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define I915_EXEC_CONTEXT_ID_MASK (0xffffffff)
 #define i915_execbuffer2_set_context_id(eb2, context)   (eb2).rsvd1 = context & I915_EXEC_CONTEXT_ID_MASK
 #define i915_execbuffer2_get_context_id(eb2)   ((eb2).rsvd1 & I915_EXEC_CONTEXT_ID_MASK)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_i915_gem_pin {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
  __u32 pad;
  __u64 alignment;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_unpin {
  __u32 handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pad;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_i915_gem_busy {
  __u32 handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 busy;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define I915_CACHING_NONE 0
 #define I915_CACHING_CACHED 1
+#define I915_CACHING_DISPLAY 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_i915_gem_caching {
  __u32 handle;
@@ -687,4 +697,14 @@
  __u64 val;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+struct drm_i915_reset_stats {
+ __u32 ctx_id;
+ __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 reset_count;
+ __u32 batch_active;
+ __u32 batch_pending;
+ __u32 pad;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #endif
diff --git a/libc/kernel/uapi/drm/msm_drm.h b/libc/kernel/uapi/drm/msm_drm.h
new file mode 100644
index 0000000..033bb39
--- /dev/null
+++ b/libc/kernel/uapi/drm/msm_drm.h
@@ -0,0 +1,144 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __MSM_DRM_H__
+#define __MSM_DRM_H__
+#include <stddef.h>
+#include <drm/drm.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSM_PIPE_NONE 0x00
+#define MSM_PIPE_2D0 0x01
+#define MSM_PIPE_2D1 0x02
+#define MSM_PIPE_3D0 0x10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_msm_timespec {
+ int64_t tv_sec;
+ int64_t tv_nsec;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSM_PARAM_GPU_ID 0x01
+#define MSM_PARAM_GMEM_SIZE 0x02
+struct drm_msm_param {
+ uint32_t pipe;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t param;
+ uint64_t value;
+};
+#define MSM_BO_SCANOUT 0x00000001
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSM_BO_GPU_READONLY 0x00000002
+#define MSM_BO_CACHE_MASK 0x000f0000
+#define MSM_BO_CACHED 0x00010000
+#define MSM_BO_WC 0x00020000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSM_BO_UNCACHED 0x00040000
+struct drm_msm_gem_new {
+ uint64_t size;
+ uint32_t flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t handle;
+};
+struct drm_msm_gem_info {
+ uint32_t handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t pad;
+ uint64_t offset;
+};
+#define MSM_PREP_READ 0x01
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MSM_PREP_WRITE 0x02
+#define MSM_PREP_NOSYNC 0x04
+struct drm_msm_gem_cpu_prep {
+ uint32_t handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t op;
+ struct drm_msm_timespec timeout;
+};
+struct drm_msm_gem_cpu_fini {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t handle;
+};
+struct drm_msm_gem_submit_reloc {
+ uint32_t submit_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t or;
+ int32_t shift;
+ uint32_t reloc_idx;
+ uint64_t reloc_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define MSM_SUBMIT_CMD_BUF 0x0001
+#define MSM_SUBMIT_CMD_IB_TARGET_BUF 0x0002
+#define MSM_SUBMIT_CMD_CTX_RESTORE_BUF 0x0003
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_msm_gem_submit_cmd {
+ uint32_t type;
+ uint32_t submit_idx;
+ uint32_t submit_offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t size;
+ uint32_t pad;
+ uint32_t nr_relocs;
+ uint64_t __user relocs;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define MSM_SUBMIT_BO_READ 0x0001
+#define MSM_SUBMIT_BO_WRITE 0x0002
+struct drm_msm_gem_submit_bo {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t flags;
+ uint32_t handle;
+ uint64_t presumed;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_msm_gem_submit {
+ uint32_t pipe;
+ uint32_t fence;
+ uint32_t nr_bos;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t nr_cmds;
+ uint64_t __user bos;
+ uint64_t __user cmds;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_msm_wait_fence {
+ uint32_t fence;
+ uint32_t pad;
+ struct drm_msm_timespec timeout;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define DRM_MSM_GET_PARAM 0x00
+#define DRM_MSM_GEM_NEW 0x02
+#define DRM_MSM_GEM_INFO 0x03
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MSM_GEM_CPU_PREP 0x04
+#define DRM_MSM_GEM_CPU_FINI 0x05
+#define DRM_MSM_GEM_SUBMIT 0x06
+#define DRM_MSM_WAIT_FENCE 0x07
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_MSM_NUM_IOCTLS 0x08
+#define DRM_IOCTL_MSM_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GET_PARAM, struct drm_msm_param)
+#define DRM_IOCTL_MSM_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_NEW, struct drm_msm_gem_new)
+#define DRM_IOCTL_MSM_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_INFO, struct drm_msm_gem_info)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_IOCTL_MSM_GEM_CPU_PREP DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_PREP, struct drm_msm_gem_cpu_prep)
+#define DRM_IOCTL_MSM_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_FINI, struct drm_msm_gem_cpu_fini)
+#define DRM_IOCTL_MSM_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_SUBMIT, struct drm_msm_gem_submit)
+#define DRM_IOCTL_MSM_WAIT_FENCE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_WAIT_FENCE, struct drm_msm_wait_fence)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/drm/radeon_drm.h b/libc/kernel/uapi/drm/radeon_drm.h
index a2a58dc..fd0a3a9 100644
--- a/libc/kernel/uapi/drm/radeon_drm.h
+++ b/libc/kernel/uapi/drm/radeon_drm.h
@@ -916,6 +916,11 @@
 #define RADEON_INFO_RING_WORKING 0x15
 #define RADEON_INFO_SI_TILE_MODE_ARRAY 0x16
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define RADEON_INFO_SI_CP_DMA_COMPUTE 0x17
+#define RADEON_INFO_CIK_MACROTILE_MODE_ARRAY 0x18
+#define RADEON_INFO_SI_BACKEND_ENABLED_MASK 0x19
+#define RADEON_INFO_MAX_SCLK 0x1a
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_radeon_info {
  uint32_t request;
  uint32_t pad;
@@ -939,5 +944,6 @@
 #define SI_TILE_MODE_DEPTH_STENCIL_2D_2AA 3
 #define SI_TILE_MODE_DEPTH_STENCIL_2D_4AA 3
 #define SI_TILE_MODE_DEPTH_STENCIL_2D_8AA 2
-#endif
+#define CIK_TILE_MODE_DEPTH_STENCIL_1D 5
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/drm/tegra_drm.h b/libc/kernel/uapi/drm/tegra_drm.h
index 80dc671..91d71be 100644
--- a/libc/kernel/uapi/drm/tegra_drm.h
+++ b/libc/kernel/uapi/drm/tegra_drm.h
@@ -18,50 +18,60 @@
  ****************************************************************************/
 #ifndef _UAPI_TEGRA_DRM_H_
 #define _UAPI_TEGRA_DRM_H_
+#include <drm/drm.h>
+#define DRM_TEGRA_GEM_CREATE_TILED (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_TEGRA_GEM_CREATE_BOTTOM_UP (1 << 1)
 struct drm_tegra_gem_create {
  __u64 size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
 };
 struct drm_tegra_gem_mmap {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 offset;
 };
 struct drm_tegra_syncpt_read {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 value;
 };
 struct drm_tegra_syncpt_incr {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pad;
 };
 struct drm_tegra_syncpt_wait {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 thresh;
  __u32 timeout;
  __u32 value;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_TEGRA_NO_TIMEOUT (0xffffffff)
 struct drm_tegra_open_channel {
  __u32 client;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pad;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 context;
 };
 struct drm_tegra_close_channel {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 context;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_tegra_get_syncpt {
  __u64 context;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 id;
+};
+struct drm_tegra_get_syncpt_base {
+ __u64 context;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 syncpt;
  __u32 id;
 };
 struct drm_tegra_syncpt {
@@ -131,15 +141,18 @@
 #define DRM_TEGRA_GET_SYNCPT 0x07
 #define DRM_TEGRA_SUBMIT 0x08
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_TEGRA_GET_SYNCPT_BASE 0x09
 #define DRM_IOCTL_TEGRA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_CREATE, struct drm_tegra_gem_create)
 #define DRM_IOCTL_TEGRA_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_MMAP, struct drm_tegra_gem_mmap)
 #define DRM_IOCTL_TEGRA_SYNCPT_READ DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_READ, struct drm_tegra_syncpt_read)
-#define DRM_IOCTL_TEGRA_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_INCR, struct drm_tegra_syncpt_incr)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_IOCTL_TEGRA_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_INCR, struct drm_tegra_syncpt_incr)
 #define DRM_IOCTL_TEGRA_SYNCPT_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_WAIT, struct drm_tegra_syncpt_wait)
 #define DRM_IOCTL_TEGRA_OPEN_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_OPEN_CHANNEL, struct drm_tegra_open_channel)
 #define DRM_IOCTL_TEGRA_CLOSE_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_CLOSE_CHANNEL, struct drm_tegra_open_channel)
-#define DRM_IOCTL_TEGRA_GET_SYNCPT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GET_SYNCPT, struct drm_tegra_get_syncpt)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_IOCTL_TEGRA_GET_SYNCPT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GET_SYNCPT, struct drm_tegra_get_syncpt)
 #define DRM_IOCTL_TEGRA_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SUBMIT, struct drm_tegra_submit)
+#define DRM_IOCTL_TEGRA_GET_SYNCPT_BASE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GET_SYNCPT_BASE, struct drm_tegra_get_syncpt_base)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/drm/vmwgfx_drm.h b/libc/kernel/uapi/drm/vmwgfx_drm.h
index a11fc1c..849ef7d 100644
--- a/libc/kernel/uapi/drm/vmwgfx_drm.h
+++ b/libc/kernel/uapi/drm/vmwgfx_drm.h
@@ -18,256 +18,352 @@
  ****************************************************************************/
 #ifndef __VMWGFX_DRM_H__
 #define __VMWGFX_DRM_H__
+#include <drm.h>
 #define DRM_VMW_MAX_SURFACE_FACES 6
-#define DRM_VMW_MAX_MIP_LEVELS 24
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_VMW_MAX_MIP_LEVELS 24
 #define DRM_VMW_GET_PARAM 0
 #define DRM_VMW_ALLOC_DMABUF 1
 #define DRM_VMW_UNREF_DMABUF 2
-#define DRM_VMW_CURSOR_BYPASS 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_VMW_CURSOR_BYPASS 3
 #define DRM_VMW_CONTROL_STREAM 4
 #define DRM_VMW_CLAIM_STREAM 5
 #define DRM_VMW_UNREF_STREAM 6
-#define DRM_VMW_CREATE_CONTEXT 7
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_VMW_CREATE_CONTEXT 7
 #define DRM_VMW_UNREF_CONTEXT 8
 #define DRM_VMW_CREATE_SURFACE 9
 #define DRM_VMW_UNREF_SURFACE 10
-#define DRM_VMW_REF_SURFACE 11
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_VMW_REF_SURFACE 11
 #define DRM_VMW_EXECBUF 12
 #define DRM_VMW_GET_3D_CAP 13
 #define DRM_VMW_FENCE_WAIT 14
-#define DRM_VMW_FENCE_SIGNALED 15
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_VMW_FENCE_SIGNALED 15
 #define DRM_VMW_FENCE_UNREF 16
 #define DRM_VMW_FENCE_EVENT 17
 #define DRM_VMW_PRESENT 18
-#define DRM_VMW_PRESENT_READBACK 19
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_VMW_PRESENT_READBACK 19
 #define DRM_VMW_UPDATE_LAYOUT 20
+#define DRM_VMW_CREATE_SHADER 21
+#define DRM_VMW_UNREF_SHADER 22
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_VMW_GB_SURFACE_CREATE 23
+#define DRM_VMW_GB_SURFACE_REF 24
+#define DRM_VMW_SYNCCPU 25
 #define DRM_VMW_PARAM_NUM_STREAMS 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_VMW_PARAM_NUM_FREE_STREAMS 1
 #define DRM_VMW_PARAM_3D 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_VMW_PARAM_HW_CAPS 3
 #define DRM_VMW_PARAM_FIFO_CAPS 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_VMW_PARAM_MAX_FB_SIZE 5
 #define DRM_VMW_PARAM_FIFO_HW_VERSION 6
+#define DRM_VMW_PARAM_MAX_SURF_MEMORY 7
+#define DRM_VMW_PARAM_3D_CAPS_SIZE 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DRM_VMW_PARAM_MAX_MOB_MEMORY 9
+#define DRM_VMW_PARAM_MAX_MOB_SIZE 10
 struct drm_vmw_getparam_arg {
  uint64_t value;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t param;
  uint32_t pad64;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_context_arg {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t cid;
  uint32_t pad64;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_surface_create_req {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t flags;
  uint32_t format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
  uint64_t size_addr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t shareable;
  int32_t scanout;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_surface_arg {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t sid;
  uint32_t pad64;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_size {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t width;
  uint32_t height;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t depth;
  uint32_t pad64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 union drm_vmw_surface_create_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct drm_vmw_surface_arg rep;
  struct drm_vmw_surface_create_req req;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 union drm_vmw_surface_reference_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct drm_vmw_surface_create_req rep;
  struct drm_vmw_surface_arg req;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define DRM_VMW_EXECBUF_VERSION 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_vmw_execbuf_arg {
  uint64_t commands;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t command_size;
  uint32_t throttle_us;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint64_t fence_rep;
  uint32_t version;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t flags;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_vmw_fence_rep {
  uint32_t handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t mask;
  uint32_t seqno;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t passed_seqno;
  uint32_t pad64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t error;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_vmw_alloc_dmabuf_req {
  uint32_t size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t pad64;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_vmw_dmabuf_rep {
  uint64_t map_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t handle;
  uint32_t cur_gmr_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t cur_gmr_offset;
  uint32_t pad64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 union drm_vmw_alloc_dmabuf_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct drm_vmw_alloc_dmabuf_req req;
  struct drm_vmw_dmabuf_rep rep;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_unref_dmabuf_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t handle;
  uint32_t pad64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_rect {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t x;
  int32_t y;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t w;
  uint32_t h;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_control_stream_arg {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t stream_id;
  uint32_t enabled;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t flags;
  uint32_t color_key;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t handle;
  uint32_t offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t format;
  uint32_t size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t width;
  uint32_t height;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t pitch[3];
  uint32_t pad64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct drm_vmw_rect src;
  struct drm_vmw_rect dst;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define DRM_VMW_CURSOR_BYPASS_ALL (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_VMW_CURSOR_BYPASS_FLAGS (1)
 struct drm_vmw_cursor_bypass_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t flags;
  uint32_t crtc_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t xpos;
  int32_t ypos;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t xhot;
  int32_t yhot;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_stream_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t stream_id;
  uint32_t pad64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_get_3d_cap_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint64_t buffer;
  uint32_t max_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t pad64;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_VMW_FENCE_FLAG_EXEC (1 << 0)
 #define DRM_VMW_FENCE_FLAG_QUERY (1 << 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_VMW_WAIT_OPTION_UNREF (1 << 0)
 struct drm_vmw_fence_wait_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t handle;
  int32_t cookie_valid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint64_t kernel_cookie;
  uint64_t timeout_us;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t lazy;
  int32_t flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t wait_options;
  int32_t pad64;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_fence_signaled_arg {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t handle;
  uint32_t flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t signaled;
  uint32_t passed_seqno;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t signaled_flags;
  uint32_t pad64;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_fence_arg {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t handle;
  uint32_t pad64;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define DRM_VMW_EVENT_FENCE_SIGNALED 0x80000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_vmw_event_fence {
  struct drm_event base;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint64_t user_data;
  uint32_t tv_sec;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t tv_usec;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRM_VMW_FE_FLAG_REQ_TIME (1 << 0)
 struct drm_vmw_fence_event_arg {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint64_t fence_rep;
  uint64_t user_data;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t handle;
  uint32_t flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct drm_vmw_present_arg {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t fb_id;
  uint32_t sid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int32_t dest_x;
  int32_t dest_y;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint64_t clips_ptr;
  uint32_t num_clips;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t pad64;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_vmw_present_readback_arg {
  uint32_t fb_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t num_clips;
  uint64_t clips_ptr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint64_t fence_rep;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct drm_vmw_update_layout_arg {
  uint32_t num_outputs;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint32_t pad64;
  uint64_t rects;
-};
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum drm_vmw_shader_type {
+ drm_vmw_shader_type_vs = 0,
+ drm_vmw_shader_type_ps,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ drm_vmw_shader_type_gs
+};
+struct drm_vmw_shader_create_arg {
+ enum drm_vmw_shader_type shader_type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t size;
+ uint32_t buffer_handle;
+ uint32_t shader_handle;
+ uint64_t offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct drm_vmw_shader_arg {
+ uint32_t handle;
+ uint32_t pad64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum drm_vmw_surface_flags {
+ drm_vmw_surface_flag_shareable = (1 << 0),
+ drm_vmw_surface_flag_scanout = (1 << 1),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ drm_vmw_surface_flag_create_buffer = (1 << 2)
+};
+struct drm_vmw_gb_surface_create_req {
+ uint32_t svga3d_flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t format;
+ uint32_t mip_levels;
+ enum drm_vmw_surface_flags drm_surface_flags;
+ uint32_t multisample_count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t autogen_filter;
+ uint32_t buffer_handle;
+ uint32_t pad64;
+ struct drm_vmw_size base_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct drm_vmw_gb_surface_create_rep {
+ uint32_t handle;
+ uint32_t backup_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t buffer_handle;
+ uint32_t buffer_size;
+ uint64_t buffer_map_handle;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+union drm_vmw_gb_surface_create_arg {
+ struct drm_vmw_gb_surface_create_rep rep;
+ struct drm_vmw_gb_surface_create_req req;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct drm_vmw_gb_surface_ref_rep {
+ struct drm_vmw_gb_surface_create_req creq;
+ struct drm_vmw_gb_surface_create_rep crep;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+union drm_vmw_gb_surface_reference_arg {
+ struct drm_vmw_gb_surface_ref_rep rep;
+ struct drm_vmw_surface_arg req;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum drm_vmw_synccpu_flags {
+ drm_vmw_synccpu_read = (1 << 0),
+ drm_vmw_synccpu_write = (1 << 1),
+ drm_vmw_synccpu_dontblock = (1 << 2),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ drm_vmw_synccpu_allow_cs = (1 << 3)
+};
+enum drm_vmw_synccpu_op {
+ drm_vmw_synccpu_grab,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ drm_vmw_synccpu_release
+};
+struct drm_vmw_synccpu_arg {
+ enum drm_vmw_synccpu_op op;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ enum drm_vmw_synccpu_flags flags;
+ uint32_t handle;
+ uint32_t pad64;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/apm_bios.h b/libc/kernel/uapi/linux/apm_bios.h
index 155b645..f3b6130 100644
--- a/libc/kernel/uapi/linux/apm_bios.h
+++ b/libc/kernel/uapi/linux/apm_bios.h
@@ -66,56 +66,59 @@
 #define APM_STANDBY_RESUME 0x000b
 #define APM_CAPABILITY_CHANGE 0x000c
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define APM_USER_HIBERNATION 0x000d
+#define APM_HIBERNATION_RESUME 0x000e
 #define APM_SUCCESS 0x00
 #define APM_DISABLED 0x01
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_CONNECTED 0x02
 #define APM_NOT_CONNECTED 0x03
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_16_CONNECTED 0x05
 #define APM_16_UNSUPPORTED 0x06
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_32_CONNECTED 0x07
 #define APM_32_UNSUPPORTED 0x08
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_BAD_DEVICE 0x09
 #define APM_BAD_PARAM 0x0a
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_NOT_ENGAGED 0x0b
 #define APM_BAD_FUNCTION 0x0c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_RESUME_DISABLED 0x0d
 #define APM_NO_ERROR 0x53
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_BAD_STATE 0x60
 #define APM_NO_EVENTS 0x80
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_NOT_PRESENT 0x86
 #define APM_DEVICE_BIOS 0x0000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_DEVICE_ALL 0x0001
 #define APM_DEVICE_DISPLAY 0x0100
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_DEVICE_STORAGE 0x0200
 #define APM_DEVICE_PARALLEL 0x0300
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_DEVICE_SERIAL 0x0400
 #define APM_DEVICE_NETWORK 0x0500
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_DEVICE_PCMCIA 0x0600
 #define APM_DEVICE_BATTERY 0x8000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_DEVICE_OEM 0xe000
 #define APM_DEVICE_OLD_ALL 0xffff
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_DEVICE_CLASS 0x00ff
 #define APM_DEVICE_MASK 0xff00
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_MAX_BATTERIES 2
 #define APM_CAP_GLOBAL_STANDBY 0x0001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_CAP_GLOBAL_SUSPEND 0x0002
 #define APM_CAP_RESUME_STANDBY_TIMER 0x0004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_CAP_RESUME_SUSPEND_TIMER 0x0008
 #define APM_CAP_RESUME_STANDBY_RING 0x0010
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_CAP_RESUME_SUSPEND_RING 0x0020
 #define APM_CAP_RESUME_STANDBY_PCMCIA 0x0040
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_CAP_RESUME_SUSPEND_PCMCIA 0x0080
 #include <linux/ioctl.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define APM_IOC_STANDBY _IO('A', 1)
 #define APM_IOC_SUSPEND _IO('A', 2)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/audit.h b/libc/kernel/uapi/linux/audit.h
index 534480f..b506512 100644
--- a/libc/kernel/uapi/linux/audit.h
+++ b/libc/kernel/uapi/linux/audit.h
@@ -43,324 +43,352 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_TTY_GET 1016
 #define AUDIT_TTY_SET 1017
+#define AUDIT_SET_FEATURE 1018
+#define AUDIT_GET_FEATURE 1019
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define AUDIT_FEATURE_CHANGE 1020
 #define AUDIT_FIRST_USER_MSG 1100
 #define AUDIT_USER_AVC 1107
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_USER_TTY 1124
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_LAST_USER_MSG 1199
 #define AUDIT_FIRST_USER_MSG2 2100
 #define AUDIT_LAST_USER_MSG2 2999
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_DAEMON_START 1200
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_DAEMON_END 1201
 #define AUDIT_DAEMON_ABORT 1202
 #define AUDIT_DAEMON_CONFIG 1203
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_SYSCALL 1300
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_PATH 1302
 #define AUDIT_IPC 1303
 #define AUDIT_SOCKETCALL 1304
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_CONFIG_CHANGE 1305
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_SOCKADDR 1306
 #define AUDIT_CWD 1307
 #define AUDIT_EXECVE 1309
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_IPC_SET_PERM 1311
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MQ_OPEN 1312
 #define AUDIT_MQ_SENDRECV 1313
 #define AUDIT_MQ_NOTIFY 1314
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MQ_GETSETATTR 1315
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_KERNEL_OTHER 1316
 #define AUDIT_FD_PAIR 1317
 #define AUDIT_OBJ_PID 1318
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_TTY 1319
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_EOE 1320
 #define AUDIT_BPRM_FCAPS 1321
 #define AUDIT_CAPSET 1322
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MMAP 1323
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_NETFILTER_PKT 1324
 #define AUDIT_NETFILTER_CFG 1325
 #define AUDIT_SECCOMP 1326
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_AVC 1400
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_SELINUX_ERR 1401
 #define AUDIT_AVC_PATH 1402
 #define AUDIT_MAC_POLICY_LOAD 1403
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAC_STATUS 1404
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAC_CONFIG_CHANGE 1405
 #define AUDIT_MAC_UNLBL_ALLOW 1406
 #define AUDIT_MAC_CIPSOV4_ADD 1407
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAC_CIPSOV4_DEL 1408
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAC_MAP_ADD 1409
 #define AUDIT_MAC_MAP_DEL 1410
 #define AUDIT_MAC_IPSEC_ADDSA 1411
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAC_IPSEC_DELSA 1412
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAC_IPSEC_ADDSPD 1413
 #define AUDIT_MAC_IPSEC_DELSPD 1414
 #define AUDIT_MAC_IPSEC_EVENT 1415
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAC_UNLBL_STCADD 1416
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAC_UNLBL_STCDEL 1417
 #define AUDIT_FIRST_KERN_ANOM_MSG 1700
 #define AUDIT_LAST_KERN_ANOM_MSG 1799
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ANOM_PROMISCUOUS 1700
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ANOM_ABEND 1701
 #define AUDIT_ANOM_LINK 1702
 #define AUDIT_INTEGRITY_DATA 1800
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_INTEGRITY_METADATA 1801
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_INTEGRITY_STATUS 1802
 #define AUDIT_INTEGRITY_HASH 1803
 #define AUDIT_INTEGRITY_PCR 1804
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_INTEGRITY_RULE 1805
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_KERNEL 2000
 #define AUDIT_FILTER_USER 0x00
 #define AUDIT_FILTER_TASK 0x01
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FILTER_ENTRY 0x02
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FILTER_WATCH 0x03
 #define AUDIT_FILTER_EXIT 0x04
 #define AUDIT_FILTER_TYPE 0x05
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_NR_FILTERS 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FILTER_PREPEND 0x10
 #define AUDIT_NEVER 0
 #define AUDIT_POSSIBLE 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ALWAYS 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MAX_FIELDS 64
 #define AUDIT_MAX_KEY_LEN 256
 #define AUDIT_BITMASK_SIZE 64
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_WORD(nr) ((__u32)((nr)/32))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_BIT(nr) (1 << ((nr) - AUDIT_WORD(nr)*32))
 #define AUDIT_SYSCALL_CLASSES 16
 #define AUDIT_CLASS_DIR_WRITE 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_CLASS_DIR_WRITE_32 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_CLASS_CHATTR 2
 #define AUDIT_CLASS_CHATTR_32 3
 #define AUDIT_CLASS_READ 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_CLASS_READ_32 5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_CLASS_WRITE 6
 #define AUDIT_CLASS_WRITE_32 7
 #define AUDIT_CLASS_SIGNAL 8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_CLASS_SIGNAL_32 9
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_UNUSED_BITS 0x07FFFC00
 #define AUDIT_COMPARE_UID_TO_OBJ_UID 1
 #define AUDIT_COMPARE_GID_TO_OBJ_GID 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_EUID_TO_OBJ_UID 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_EGID_TO_OBJ_GID 4
 #define AUDIT_COMPARE_AUID_TO_OBJ_UID 5
 #define AUDIT_COMPARE_SUID_TO_OBJ_UID 6
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_SGID_TO_OBJ_GID 7
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_FSUID_TO_OBJ_UID 8
 #define AUDIT_COMPARE_FSGID_TO_OBJ_GID 9
 #define AUDIT_COMPARE_UID_TO_AUID 10
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_UID_TO_EUID 11
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_UID_TO_FSUID 12
 #define AUDIT_COMPARE_UID_TO_SUID 13
 #define AUDIT_COMPARE_AUID_TO_FSUID 14
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_AUID_TO_SUID 15
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_AUID_TO_EUID 16
 #define AUDIT_COMPARE_EUID_TO_SUID 17
 #define AUDIT_COMPARE_EUID_TO_FSUID 18
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_SUID_TO_FSUID 19
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_GID_TO_EGID 20
 #define AUDIT_COMPARE_GID_TO_FSGID 21
 #define AUDIT_COMPARE_GID_TO_SGID 22
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_EGID_TO_FSGID 23
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_COMPARE_EGID_TO_SGID 24
 #define AUDIT_COMPARE_SGID_TO_FSGID 25
 #define AUDIT_MAX_FIELD_COMPARE AUDIT_COMPARE_SGID_TO_FSGID
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_PID 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_UID 1
 #define AUDIT_EUID 2
 #define AUDIT_SUID 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FSUID 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_GID 5
 #define AUDIT_EGID 6
 #define AUDIT_SGID 7
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FSGID 8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_LOGINUID 9
 #define AUDIT_PERS 10
 #define AUDIT_ARCH 11
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_MSGTYPE 12
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_SUBJ_USER 13
 #define AUDIT_SUBJ_ROLE 14
 #define AUDIT_SUBJ_TYPE 15
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_SUBJ_SEN 16
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_SUBJ_CLR 17
 #define AUDIT_PPID 18
 #define AUDIT_OBJ_USER 19
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_OBJ_ROLE 20
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_OBJ_TYPE 21
 #define AUDIT_OBJ_LEV_LOW 22
 #define AUDIT_OBJ_LEV_HIGH 23
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_LOGINUID_SET 24
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_DEVMAJOR 100
 #define AUDIT_DEVMINOR 101
 #define AUDIT_INODE 102
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_EXIT 103
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_SUCCESS 104
 #define AUDIT_WATCH 105
 #define AUDIT_PERM 106
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_DIR 107
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FILETYPE 108
 #define AUDIT_OBJ_UID 109
 #define AUDIT_OBJ_GID 110
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FIELD_COMPARE 111
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARG0 200
 #define AUDIT_ARG1 (AUDIT_ARG0+1)
 #define AUDIT_ARG2 (AUDIT_ARG0+2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARG3 (AUDIT_ARG0+3)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FILTERKEY 210
 #define AUDIT_NEGATE 0x80000000
 #define AUDIT_BIT_MASK 0x08000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_LESS_THAN 0x10000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_GREATER_THAN 0x20000000
 #define AUDIT_NOT_EQUAL 0x30000000
 #define AUDIT_EQUAL 0x40000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_BIT_TEST (AUDIT_BIT_MASK|AUDIT_EQUAL)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_LESS_THAN_OR_EQUAL (AUDIT_LESS_THAN|AUDIT_EQUAL)
 #define AUDIT_GREATER_THAN_OR_EQUAL (AUDIT_GREATER_THAN|AUDIT_EQUAL)
 #define AUDIT_OPERATORS (AUDIT_EQUAL|AUDIT_NOT_EQUAL|AUDIT_BIT_MASK)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  Audit_equal,
  Audit_not_equal,
  Audit_bitmask,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  Audit_bittest,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  Audit_lt,
  Audit_gt,
  Audit_le,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  Audit_ge,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  Audit_bad
 };
 #define AUDIT_STATUS_ENABLED 0x0001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_STATUS_FAILURE 0x0002
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_STATUS_PID 0x0004
 #define AUDIT_STATUS_RATE_LIMIT 0x0008
 #define AUDIT_STATUS_BACKLOG_LIMIT 0x0010
+#define AUDIT_STATUS_BACKLOG_WAIT_TIME 0x0020
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define AUDIT_VERSION_BACKLOG_LIMIT 1
+#define AUDIT_VERSION_BACKLOG_WAIT_TIME 2
+#define AUDIT_VERSION_LATEST AUDIT_VERSION_BACKLOG_WAIT_TIME
 #define AUDIT_FAIL_SILENT 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_FAIL_PRINTK 1
 #define AUDIT_FAIL_PANIC 2
 #define __AUDIT_ARCH_64BIT 0x80000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __AUDIT_ARCH_LE 0x40000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_ALPHA (EM_ALPHA|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_ARM (EM_ARM|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_ARMEB (EM_ARM)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE)
-#define AUDIT_ARCH_FRV (EM_FRV)
-#define AUDIT_ARCH_H8300 (EM_H8_300)
-#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define AUDIT_ARCH_FRV (EM_FRV)
+#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_M32R (EM_M32R)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_M68K (EM_68K)
 #define AUDIT_ARCH_MIPS (EM_MIPS)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_MIPSEL (EM_MIPS|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_MIPS64 (EM_MIPS|__AUDIT_ARCH_64BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_MIPSEL64 (EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_OPENRISC (EM_OPENRISC)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_PARISC (EM_PARISC)
 #define AUDIT_ARCH_PARISC64 (EM_PARISC|__AUDIT_ARCH_64BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_PPC (EM_PPC)
 #define AUDIT_ARCH_PPC64 (EM_PPC64|__AUDIT_ARCH_64BIT)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_S390 (EM_S390)
 #define AUDIT_ARCH_S390X (EM_S390|__AUDIT_ARCH_64BIT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_SH (EM_SH)
 #define AUDIT_ARCH_SHEL (EM_SH|__AUDIT_ARCH_LE)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_SH64 (EM_SH|__AUDIT_ARCH_64BIT)
 #define AUDIT_ARCH_SHEL64 (EM_SH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_SPARC (EM_SPARC)
 #define AUDIT_ARCH_SPARC64 (EM_SPARCV9|__AUDIT_ARCH_64BIT)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_PERM_EXEC 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_PERM_WRITE 2
 #define AUDIT_PERM_READ 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AUDIT_PERM_ATTR 8
+#define AUDIT_MESSAGE_TEXT_MAX 8560
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct audit_status {
  __u32 mask;
  __u32 enabled;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 failure;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pid;
  __u32 rate_limit;
  __u32 backlog_limit;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 lost;
- __u32 backlog;
-};
-struct audit_tty_status {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 backlog;
+ __u32 version;
+ __u32 backlog_wait_time;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct audit_features {
+#define AUDIT_FEATURE_VERSION 1
+ __u32 vers;
+ __u32 mask;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 features;
+ __u32 lock;
+};
+#define AUDIT_FEATURE_ONLY_UNSET_LOGINUID 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define AUDIT_FEATURE_LOGINUID_IMMUTABLE 1
+#define AUDIT_LAST_FEATURE AUDIT_FEATURE_LOGINUID_IMMUTABLE
+#define audit_feature_valid(x) ((x) >= 0 && (x) <= AUDIT_LAST_FEATURE)
+#define AUDIT_FEATURE_TO_MASK(x) (1 << ((x) & 31))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct audit_tty_status {
  __u32 enabled;
  __u32 log_passwd;
 };
-struct audit_rule_data {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define AUDIT_UID_UNSET (unsigned int)-1
+struct audit_rule_data {
  __u32 flags;
  __u32 action;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 field_count;
  __u32 mask[AUDIT_BITMASK_SIZE];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 fields[AUDIT_MAX_FIELDS];
  __u32 values[AUDIT_MAX_FIELDS];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 fieldflags[AUDIT_MAX_FIELDS];
  __u32 buflen;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  char buf[0];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct audit_rule {
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 action;
  __u32 field_count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mask[AUDIT_BITMASK_SIZE];
  __u32 fields[AUDIT_MAX_FIELDS];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 values[AUDIT_MAX_FIELDS];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/bcache.h b/libc/kernel/uapi/linux/bcache.h
new file mode 100644
index 0000000..4d1d454
--- /dev/null
+++ b/libc/kernel/uapi/linux/bcache.h
@@ -0,0 +1,209 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _LINUX_BCACHE_H
+#define _LINUX_BCACHE_H
+#include <asm/types.h>
+#define BITMASK(name, type, field, offset, size)  static inline __u64 name(const type *k)  { return (k->field >> offset) & ~(~0ULL << size); }    static inline void SET_##name(type *k, __u64 v)  {   k->field &= ~(~(~0ULL << size) << offset);   k->field |= (v & ~(~0ULL << size)) << offset;  }
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct bkey {
+ __u64 high;
+ __u64 low;
+ __u64 ptr[];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define KEY_FIELD(name, field, offset, size)   BITMASK(name, struct bkey, field, offset, size)
+#define PTR_FIELD(name, offset, size)  static inline __u64 name(const struct bkey *k, unsigned i)  { return (k->ptr[i] >> offset) & ~(~0ULL << size); }    static inline void SET_##name(struct bkey *k, unsigned i, __u64 v)  {   k->ptr[i] &= ~(~(~0ULL << size) << offset);   k->ptr[i] |= (v & ~(~0ULL << size)) << offset;  }
+#define KEY_SIZE_BITS 16
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_MAX_U64S 8
+#define KEY(inode, offset, size)  ((struct bkey) {   .high = (1ULL << 63) | ((__u64) (size) << 20) | (inode),   .low = (offset)  })
+#define ZERO_KEY KEY(0, 0, 0)
+#define MAX_KEY_INODE (~(~0 << 20))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MAX_KEY_OFFSET (~0ULL >> 1)
+#define MAX_KEY KEY(MAX_KEY_INODE, MAX_KEY_OFFSET, 0)
+#define KEY_START(k) (KEY_OFFSET(k) - KEY_SIZE(k))
+#define START_KEY(k) KEY(KEY_INODE(k), KEY_START(k), 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PTR_DEV_BITS 12
+#define PTR_CHECK_DEV ((1 << PTR_DEV_BITS) - 1)
+#define PTR(gen, offset, dev)   ((((__u64) dev) << 51) | ((__u64) offset) << 8 | gen)
+#define bkey_copy(_dest, _src) memcpy(_dest, _src, bkey_bytes(_src))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BKEY_PAD 8
+#define BKEY_PADDED(key)   union { struct bkey key; __u64 key ## _pad[BKEY_PAD]; }
+#define BCACHE_SB_VERSION_CDEV 0
+#define BCACHE_SB_VERSION_BDEV 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BCACHE_SB_VERSION_CDEV_WITH_UUID 3
+#define BCACHE_SB_VERSION_BDEV_WITH_OFFSET 4
+#define BCACHE_SB_MAX_VERSION 4
+#define SB_SECTOR 8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SB_SIZE 4096
+#define SB_LABEL_SIZE 32
+#define SB_JOURNAL_BUCKETS 256U
+#define MAX_CACHES_PER_SET 8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BDEV_DATA_START_DEFAULT 16
+struct cache_sb {
+ __u64 csum;
+ __u64 offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 version;
+ __u8 magic[16];
+ __u8 uuid[16];
+ union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 set_uuid[16];
+ __u64 set_magic;
+ };
+ __u8 label[SB_LABEL_SIZE];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 flags;
+ __u64 seq;
+ __u64 pad[8];
+ union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct {
+ __u64 nbuckets;
+ __u16 block_size;
+ __u16 bucket_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 nr_in_set;
+ __u16 nr_this_dev;
+ };
+ struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 data_offset;
+ };
+ };
+ __u32 last_mount;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 first_bucket;
+ union {
+ __u16 njournal_buckets;
+ __u16 keys;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ };
+ __u64 d[SB_JOURNAL_BUCKETS];
+};
+#define CACHE_REPLACEMENT_LRU 0U
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CACHE_REPLACEMENT_FIFO 1U
+#define CACHE_REPLACEMENT_RANDOM 2U
+#define CACHE_MODE_WRITETHROUGH 0U
+#define CACHE_MODE_WRITEBACK 1U
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CACHE_MODE_WRITEAROUND 2U
+#define CACHE_MODE_NONE 3U
+#define BDEV_STATE_NONE 0U
+#define BDEV_STATE_CLEAN 1U
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BDEV_STATE_DIRTY 2U
+#define BDEV_STATE_STALE 3U
+#define JSET_MAGIC 0x245235c1a3625032ULL
+#define PSET_MAGIC 0x6750e15f87337f91ULL
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BSET_MAGIC 0x90135c78b99e07f5ULL
+#define BCACHE_JSET_VERSION_UUIDv1 1
+#define BCACHE_JSET_VERSION_UUID 1
+#define BCACHE_JSET_VERSION 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct jset {
+ __u64 csum;
+ __u64 magic;
+ __u64 seq;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 version;
+ __u32 keys;
+ __u64 last_seq;
+ BKEY_PADDED(uuid_bucket);
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BKEY_PADDED(btree_root);
+ __u16 btree_level;
+ __u16 pad[3];
+ __u64 prio_bucket[MAX_CACHES_PER_SET];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union {
+ struct bkey start[0];
+ __u64 d[0];
+ };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct prio_set {
+ __u64 csum;
+ __u64 magic;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 seq;
+ __u32 version;
+ __u32 pad;
+ __u64 next_bucket;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct bucket_disk {
+ __u16 prio;
+ __u8 gen;
+ } __attribute((packed)) data[];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct uuid_entry {
+ union {
+ struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 uuid[16];
+ __u8 label[32];
+ __u32 first_reg;
+ __u32 last_reg;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 invalidated;
+ __u32 flags;
+ __u64 sectors;
+ };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 pad[128];
+ };
+};
+#define BCACHE_BSET_CSUM 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BCACHE_BSET_VERSION 1
+struct bset {
+ __u64 csum;
+ __u64 magic;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 seq;
+ __u32 version;
+ __u32 keys;
+ union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct bkey start[0];
+ __u64 d[0];
+ };
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct uuid_entry_v0 {
+ __u8 uuid[16];
+ __u8 label[32];
+ __u32 first_reg;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 last_reg;
+ __u32 invalidated;
+ __u32 pad;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/binder.h b/libc/kernel/uapi/linux/binder.h
index 1472382..02101ab 100644
--- a/libc/kernel/uapi/linux/binder.h
+++ b/libc/kernel/uapi/linux/binder.h
@@ -36,136 +36,155 @@
  FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifdef BINDER_IPC_32BIT
+typedef __u32 binder_size_t;
+typedef __u32 binder_uintptr_t;
+#else
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef __u64 binder_size_t;
+typedef __u64 binder_uintptr_t;
+#endif
 struct flat_binder_object {
- unsigned long type;
- unsigned long flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 type;
+ __u32 flags;
  union {
+ binder_uintptr_t binder;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- void __user *binder;
- signed long handle;
+ __u32 handle;
  };
- void __user *cookie;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ binder_uintptr_t cookie;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct binder_write_read {
- signed long write_size;
- signed long write_consumed;
+ binder_size_t write_size;
+ binder_size_t write_consumed;
+ binder_uintptr_t write_buffer;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long write_buffer;
- signed long read_size;
- signed long read_consumed;
- unsigned long read_buffer;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ binder_size_t read_size;
+ binder_size_t read_consumed;
+ binder_uintptr_t read_buffer;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct binder_version {
- signed long protocol_version;
+ __s32 protocol_version;
 };
+#ifdef BINDER_IPC_32BIT
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BINDER_CURRENT_PROTOCOL_VERSION 7
+#else
+#define BINDER_CURRENT_PROTOCOL_VERSION 8
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
-#define BINDER_SET_MAX_THREADS _IOW('b', 5, size_t)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
 #define BINDER_VERSION _IOWR('b', 9, struct binder_version)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum transaction_flags {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TF_ONE_WAY = 0x01,
  TF_ROOT_OBJECT = 0x04,
  TF_STATUS_CODE = 0x08,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TF_ACCEPT_FDS = 0x10,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct binder_transaction_data {
  union {
+ __u32 handle;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- size_t handle;
- void *ptr;
+ binder_uintptr_t ptr;
  } target;
- void *cookie;
+ binder_uintptr_t cookie;
+ __u32 code;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned int code;
- unsigned int flags;
+ __u32 flags;
  pid_t sender_pid;
  uid_t sender_euid;
+ binder_size_t data_size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- size_t data_size;
- size_t offsets_size;
+ binder_size_t offsets_size;
  union {
  struct {
+ binder_uintptr_t buffer;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- const void __user *buffer;
- const void __user *offsets;
+ binder_uintptr_t offsets;
  } ptr;
- uint8_t buf[8];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 buf[8];
  } data;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct binder_ptr_cookie {
- void *ptr;
+ binder_uintptr_t ptr;
+ binder_uintptr_t cookie;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- void *cookie;
 };
-struct binder_pri_desc {
- int priority;
+struct binder_handle_cookie {
+ __u32 handle;
+ binder_uintptr_t cookie;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- int desc;
+} __attribute__((packed));
+struct binder_pri_desc {
+ __s32 priority;
+ __u32 desc;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct binder_pri_ptr_cookie {
- int priority;
+ __s32 priority;
+ binder_uintptr_t ptr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- void *ptr;
- void *cookie;
+ binder_uintptr_t cookie;
 };
 enum binder_driver_return_protocol {
+ BR_ERROR = _IOR('r', 0, __s32),
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- BR_ERROR = _IOR('r', 0, int),
  BR_OK = _IO('r', 1),
  BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
  BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
+ BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- BR_ACQUIRE_RESULT = _IOR('r', 4, int),
  BR_DEAD_REPLY = _IO('r', 5),
  BR_TRANSACTION_COMPLETE = _IO('r', 6),
  BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
  BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
  BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BR_NOOP = _IO('r', 12),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BR_SPAWN_LOOPER = _IO('r', 13),
  BR_FINISHED = _IO('r', 14),
- BR_DEAD_BINDER = _IOR('r', 15, void *),
+ BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
+ BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, void *),
  BR_FAILED_REPLY = _IO('r', 17),
 };
 enum binder_driver_command_protocol {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
- BC_ACQUIRE_RESULT = _IOW('c', 2, int),
- BC_FREE_BUFFER = _IOW('c', 3, int),
+ BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
+ BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
+ BC_INCREFS = _IOW('c', 4, __u32),
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- BC_INCREFS = _IOW('c', 4, int),
- BC_ACQUIRE = _IOW('c', 5, int),
- BC_RELEASE = _IOW('c', 6, int),
- BC_DECREFS = _IOW('c', 7, int),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BC_ACQUIRE = _IOW('c', 5, __u32),
+ BC_RELEASE = _IOW('c', 6, __u32),
+ BC_DECREFS = _IOW('c', 7, __u32),
  BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
  BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
  BC_REGISTER_LOOPER = _IO('c', 11),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  BC_ENTER_LOOPER = _IO('c', 12),
- BC_EXIT_LOOPER = _IO('c', 13),
- BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_ptr_cookie),
- BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_ptr_cookie),
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- BC_DEAD_BINDER_DONE = _IOW('c', 16, void *),
+ BC_EXIT_LOOPER = _IO('c', 13),
+ BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_handle_cookie),
+ BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_handle_cookie),
+ BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
diff --git a/libc/kernel/uapi/linux/btrfs.h b/libc/kernel/uapi/linux/btrfs.h
index 69d55f0..11f950f 100644
--- a/libc/kernel/uapi/linux/btrfs.h
+++ b/libc/kernel/uapi/linux/btrfs.h
@@ -174,211 +174,251 @@
  __u8 fsid[BTRFS_FSID_SIZE];
  __u64 reserved[124];
 };
-#define BTRFS_BALANCE_CTL_PAUSE 1
+struct btrfs_ioctl_feature_flags {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 compat_flags;
+ __u64 compat_ro_flags;
+ __u64 incompat_flags;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTRFS_BALANCE_CTL_PAUSE 1
 #define BTRFS_BALANCE_CTL_CANCEL 2
 struct btrfs_balance_args {
  __u64 profiles;
- __u64 usage;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 usage;
  __u64 devid;
  __u64 pstart;
  __u64 pend;
- __u64 vstart;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 vstart;
  __u64 vend;
  __u64 target;
  __u64 flags;
- __u64 unused[8];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 unused[8];
 } __attribute__ ((__packed__));
 struct btrfs_balance_progress {
  __u64 expected;
- __u64 considered;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 considered;
  __u64 completed;
 };
 #define BTRFS_BALANCE_STATE_RUNNING (1ULL << 0)
-#define BTRFS_BALANCE_STATE_PAUSE_REQ (1ULL << 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTRFS_BALANCE_STATE_PAUSE_REQ (1ULL << 1)
 #define BTRFS_BALANCE_STATE_CANCEL_REQ (1ULL << 2)
 struct btrfs_ioctl_balance_args {
  __u64 flags;
- __u64 state;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 state;
  struct btrfs_balance_args data;
  struct btrfs_balance_args meta;
  struct btrfs_balance_args sys;
- struct btrfs_balance_progress stat;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct btrfs_balance_progress stat;
  __u64 unused[72];
 };
 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
-struct btrfs_ioctl_ino_lookup_args {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct btrfs_ioctl_ino_lookup_args {
  __u64 treeid;
  __u64 objectid;
  char name[BTRFS_INO_LOOKUP_PATH_MAX];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct btrfs_ioctl_search_key {
  __u64 tree_id;
  __u64 min_objectid;
- __u64 max_objectid;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 max_objectid;
  __u64 min_offset;
  __u64 max_offset;
  __u64 min_transid;
- __u64 max_transid;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 max_transid;
  __u32 min_type;
  __u32 max_type;
  __u32 nr_items;
- __u32 unused;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 unused;
  __u64 unused1;
  __u64 unused2;
  __u64 unused3;
- __u64 unused4;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 unused4;
 };
 struct btrfs_ioctl_search_header {
  __u64 transid;
- __u64 objectid;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 objectid;
  __u64 offset;
  __u32 type;
  __u32 len;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
 struct btrfs_ioctl_search_args {
  struct btrfs_ioctl_search_key key;
- char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
 };
 struct btrfs_ioctl_clone_range_args {
  __s64 src_fd;
- __u64 src_offset, src_length;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 src_offset, src_length;
  __u64 dest_offset;
 };
 #define BTRFS_DEFRAG_RANGE_COMPRESS 1
-#define BTRFS_DEFRAG_RANGE_START_IO 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTRFS_DEFRAG_RANGE_START_IO 2
+#define BTRFS_SAME_DATA_DIFFERS 1
+struct btrfs_ioctl_same_extent_info {
+ __s64 fd;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 logical_offset;
+ __u64 bytes_deduped;
+ __s32 status;
+ __u32 reserved;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct btrfs_ioctl_same_args {
+ __u64 logical_offset;
+ __u64 length;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 dest_count;
+ __u16 reserved1;
+ __u32 reserved2;
+ struct btrfs_ioctl_same_extent_info info[0];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct btrfs_ioctl_space_info {
  __u64 flags;
  __u64 total_bytes;
- __u64 used_bytes;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 used_bytes;
 };
 struct btrfs_ioctl_space_args {
  __u64 space_slots;
- __u64 total_spaces;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 total_spaces;
  struct btrfs_ioctl_space_info spaces[0];
 };
 struct btrfs_data_container {
- __u32 bytes_left;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 bytes_left;
  __u32 bytes_missing;
  __u32 elem_cnt;
  __u32 elem_missed;
- __u64 val[0];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 val[0];
 };
 struct btrfs_ioctl_ino_path_args {
  __u64 inum;
- __u64 size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 size;
  __u64 reserved[4];
  __u64 fspath;
 };
-struct btrfs_ioctl_logical_ino_args {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct btrfs_ioctl_logical_ino_args {
  __u64 logical;
  __u64 size;
  __u64 reserved[4];
- __u64 inodes;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 inodes;
 };
 enum btrfs_dev_stat_values {
  BTRFS_DEV_STAT_WRITE_ERRS,
- BTRFS_DEV_STAT_READ_ERRS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BTRFS_DEV_STAT_READ_ERRS,
  BTRFS_DEV_STAT_FLUSH_ERRS,
  BTRFS_DEV_STAT_CORRUPTION_ERRS,
  BTRFS_DEV_STAT_GENERATION_ERRS,
- BTRFS_DEV_STAT_VALUES_MAX
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BTRFS_DEV_STAT_VALUES_MAX
 };
 #define BTRFS_DEV_STATS_RESET (1ULL << 0)
 struct btrfs_ioctl_get_dev_stats {
- __u64 devid;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 devid;
  __u64 nr_items;
  __u64 flags;
  __u64 values[BTRFS_DEV_STAT_VALUES_MAX];
- __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX];
 };
 #define BTRFS_QUOTA_CTL_ENABLE 1
 #define BTRFS_QUOTA_CTL_DISABLE 2
-#define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
 struct btrfs_ioctl_quota_ctl_args {
  __u64 cmd;
  __u64 status;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct btrfs_ioctl_quota_rescan_args {
  __u64 flags;
  __u64 progress;
- __u64 reserved[6];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 reserved[6];
 };
 struct btrfs_ioctl_qgroup_assign_args {
  __u64 assign;
- __u64 src;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 src;
  __u64 dst;
 };
 struct btrfs_ioctl_qgroup_create_args {
- __u64 create;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 create;
  __u64 qgroupid;
 };
 struct btrfs_ioctl_timespec {
- __u64 sec;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 sec;
  __u32 nsec;
 };
 struct btrfs_ioctl_received_subvol_args {
- char uuid[BTRFS_UUID_SIZE];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ char uuid[BTRFS_UUID_SIZE];
  __u64 stransid;
  __u64 rtransid;
  struct btrfs_ioctl_timespec stime;
- struct btrfs_ioctl_timespec rtime;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct btrfs_ioctl_timespec rtime;
  __u64 flags;
  __u64 reserved[16];
 };
-#define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1
 #define BTRFS_SEND_FLAG_OMIT_STREAM_HEADER 0x2
 #define BTRFS_SEND_FLAG_OMIT_END_CMD 0x4
 #define BTRFS_SEND_FLAG_MASK   (BTRFS_SEND_FLAG_NO_FILE_DATA |   BTRFS_SEND_FLAG_OMIT_STREAM_HEADER |   BTRFS_SEND_FLAG_OMIT_END_CMD)
-struct btrfs_ioctl_send_args {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct btrfs_ioctl_send_args {
  __s64 send_fd;
  __u64 clone_sources_count;
  __u64 __user *clone_sources;
- __u64 parent_root;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 parent_root;
  __u64 flags;
  __u64 reserved[4];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum btrfs_err_code {
+ notused,
+ BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
+ BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
+ BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
+ BTRFS_ERROR_DEV_TGT_REPLACE,
+ BTRFS_ERROR_DEV_MISSING_NOT_FOUND,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BTRFS_ERROR_DEV_ONLY_WRITABLE,
+ BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
+};
 #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1,   struct btrfs_ioctl_vol_args)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2,   struct btrfs_ioctl_vol_args)
@@ -401,7 +441,7 @@
 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17,   struct btrfs_ioctl_search_args)
 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18,   struct btrfs_ioctl_ino_lookup_args)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)
+#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
 #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20,   struct btrfs_ioctl_space_args)
 #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
 #define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
@@ -434,10 +474,16 @@
 #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43,   struct btrfs_ioctl_qgroup_limit_args)
 #define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44,   struct btrfs_ioctl_quota_rescan_args)
 #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45,   struct btrfs_ioctl_quota_rescan_args)
-#define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49,   char[BTRFS_LABEL_SIZE])
+#define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49,   char[BTRFS_LABEL_SIZE])
 #define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50,   char[BTRFS_LABEL_SIZE])
 #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52,   struct btrfs_ioctl_get_dev_stats)
 #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53,   struct btrfs_ioctl_dev_replace_args)
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54,   struct btrfs_ioctl_same_args)
+#define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57,   struct btrfs_ioctl_feature_flags)
+#define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57,   struct btrfs_ioctl_feature_flags[2])
+#define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57,   struct btrfs_ioctl_feature_flags[3])
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/can/gw.h b/libc/kernel/uapi/linux/can/gw.h
index 3f72a52..dd80d48 100644
--- a/libc/kernel/uapi/linux/can/gw.h
+++ b/libc/kernel/uapi/linux/can/gw.h
@@ -52,58 +52,59 @@
  CGW_FILTER,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CGW_DELETED,
+ CGW_LIM_HOPS,
  __CGW_MAX
 };
-#define CGW_MAX (__CGW_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CGW_MAX (__CGW_MAX - 1)
 #define CGW_FLAGS_CAN_ECHO 0x01
 #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02
 #define CGW_FLAGS_CAN_IIF_TX_OK 0x04
-#define CGW_MOD_FUNCS 4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CGW_MOD_FUNCS 4
 #define CGW_MOD_ID 0x01
 #define CGW_MOD_DLC 0x02
 #define CGW_MOD_DATA 0x04
-#define CGW_FRAME_MODS 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CGW_FRAME_MODS 3
 #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS)
 struct cgw_frame_mod {
  struct can_frame cf;
- __u8 modtype;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 modtype;
 } __attribute__((packed));
 #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod)
 struct cgw_csum_xor {
- __s8 from_idx;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s8 from_idx;
  __s8 to_idx;
  __s8 result_idx;
  __u8 init_xor_val;
-} __attribute__((packed));
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+} __attribute__((packed));
 struct cgw_csum_crc8 {
  __s8 from_idx;
  __s8 to_idx;
- __s8 result_idx;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s8 result_idx;
  __u8 init_crc_val;
  __u8 final_xor_val;
  __u8 crctab[256];
- __u8 profile;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 profile;
  __u8 profile_data[20];
 } __attribute__((packed));
 #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor)
-#define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8)
 enum {
  CGW_CRC8PRF_UNSPEC,
  CGW_CRC8PRF_1U8,
- CGW_CRC8PRF_16U8,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ CGW_CRC8PRF_16U8,
  CGW_CRC8PRF_SFFID_XOR,
  __CGW_CRC8PRF_MAX
 };
-#define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1)
 #endif
diff --git a/libc/kernel/uapi/linux/cifs/cifs_mount.h b/libc/kernel/uapi/linux/cifs/cifs_mount.h
new file mode 100644
index 0000000..0db6b39
--- /dev/null
+++ b/libc/kernel/uapi/linux/cifs/cifs_mount.h
@@ -0,0 +1,28 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _CIFS_MOUNT_H
+#define _CIFS_MOUNT_H
+#define CIFS_MAX_DOMAINNAME_LEN 256
+#define CIFS_MAX_USERNAME_LEN 256
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CIFS_MAX_PASSWORD_LEN 512
+#define CIFS_MAX_SHARE_LEN 256
+#define CIFS_NI_MAXHOST 1024
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/cm4000_cs.h b/libc/kernel/uapi/linux/cm4000_cs.h
index ab1a6a1..99fe701 100644
--- a/libc/kernel/uapi/linux/cm4000_cs.h
+++ b/libc/kernel/uapi/linux/cm4000_cs.h
@@ -19,43 +19,45 @@
 #ifndef _UAPI_CM4000_H_
 #define _UAPI_CM4000_H_
 #include <linux/types.h>
-#define MAX_ATR 33
+#include <linux/ioctl.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MAX_ATR 33
 #define CM4000_MAX_DEV 4
 typedef struct atreq {
  __s32 atr_len;
- unsigned char atr[64];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char atr[64];
  __s32 power_act;
  unsigned char bIFSD;
  unsigned char bIFSC;
-} atreq_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+} atreq_t;
 typedef struct ptsreq {
  __u32 protocol;
  unsigned char flags;
- unsigned char pts1;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char pts1;
  unsigned char pts2;
  unsigned char pts3;
 } ptsreq_t;
-#define CM_IOC_MAGIC 'c'
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CM_IOC_MAGIC 'c'
 #define CM_IOC_MAXNR 255
 #define CM_IOCGSTATUS _IOR (CM_IOC_MAGIC, 0, unsigned char *)
 #define CM_IOCGATR _IOWR(CM_IOC_MAGIC, 1, atreq_t *)
-#define CM_IOCSPTS _IOW (CM_IOC_MAGIC, 2, ptsreq_t *)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CM_IOCSPTS _IOW (CM_IOC_MAGIC, 2, ptsreq_t *)
 #define CM_IOCSRDR _IO (CM_IOC_MAGIC, 3)
 #define CM_IOCARDOFF _IO (CM_IOC_MAGIC, 4)
 #define CM_IOSDBGLVL _IOW(CM_IOC_MAGIC, 250, int*)
-#define CM_CARD_INSERTED 0x01
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CM_CARD_INSERTED 0x01
 #define CM_CARD_POWERED 0x02
 #define CM_ATR_PRESENT 0x04
 #define CM_ATR_VALID 0x08
-#define CM_STATE_VALID 0x0f
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define CM_STATE_VALID 0x0f
 #define CM_NO_READER 0x10
 #define CM_BAD_CARD 0x20
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/const.h b/libc/kernel/uapi/linux/const.h
index d348300..9a85be7 100644
--- a/libc/kernel/uapi/linux/const.h
+++ b/libc/kernel/uapi/linux/const.h
@@ -28,4 +28,7 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define _AT(T,X) ((T)(X))
 #endif
+#define _BITUL(x) (_AC(1,UL) << (x))
+#define _BITULL(x) (_AC(1,ULL) << (x))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/dm-ioctl.h b/libc/kernel/uapi/linux/dm-ioctl.h
index 89f3b90..fbb4cd9 100644
--- a/libc/kernel/uapi/linux/dm-ioctl.h
+++ b/libc/kernel/uapi/linux/dm-ioctl.h
@@ -121,9 +121,9 @@
 #define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
 #define DM_VERSION_MAJOR 4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define DM_VERSION_MINOR 24
+#define DM_VERSION_MINOR 27
 #define DM_VERSION_PATCHLEVEL 0
-#define DM_VERSION_EXTRA "-ioctl (2013-01-15)"
+#define DM_VERSION_EXTRA "-ioctl (2013-10-30)"
 #define DM_READONLY_FLAG (1 << 0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DM_SUSPEND_FLAG (1 << 1)
@@ -143,4 +143,6 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DM_SECURE_DATA_FLAG (1 << 15)
 #define DM_DATA_OUT_FLAG (1 << 16)
+#define DM_DEFERRED_REMOVE (1 << 17)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/dm-log-userspace.h b/libc/kernel/uapi/linux/dm-log-userspace.h
index 45a57f3..47d45f7 100644
--- a/libc/kernel/uapi/linux/dm-log-userspace.h
+++ b/libc/kernel/uapi/linux/dm-log-userspace.h
@@ -43,7 +43,7 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DM_ULOG_REQUEST_MASK 0xFF
 #define DM_ULOG_REQUEST_TYPE(request_type)   (DM_ULOG_REQUEST_MASK & (request_type))
-#define DM_ULOG_REQUEST_VERSION 2
+#define DM_ULOG_REQUEST_VERSION 3
 struct dm_ulog_request {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  uint64_t luid;
diff --git a/libc/kernel/uapi/linux/dn.h b/libc/kernel/uapi/linux/dn.h
index c72952e..013a03f 100644
--- a/libc/kernel/uapi/linux/dn.h
+++ b/libc/kernel/uapi/linux/dn.h
@@ -18,118 +18,121 @@
  ****************************************************************************/
 #ifndef _LINUX_DN_H
 #define _LINUX_DN_H
+#include <linux/ioctl.h>
 #include <linux/types.h>
-#define DNPROTO_NSP 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#include <linux/if_ether.h>
+#define DNPROTO_NSP 2
 #define DNPROTO_ROU 3
 #define DNPROTO_NML 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DNPROTO_EVL 5
 #define DNPROTO_EVR 6
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DNPROTO_NSPT 7
 #define DN_ADDL 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DN_MAXADDL 2
 #define DN_MAXOPTL 16
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DN_MAXOBJL 16
 #define DN_MAXACCL 40
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DN_MAXALIASL 128
 #define DN_MAXNODEL 256
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DNBUFSIZE 65023
 #define SO_CONDATA 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SO_CONACCESS 2
 #define SO_PROXYUSR 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SO_LINKINFO 7
 #define DSO_CONDATA 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DSO_DISDATA 10
 #define DSO_CONACCESS 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DSO_ACCEPTMODE 4
 #define DSO_CONACCEPT 5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DSO_CONREJECT 6
 #define DSO_LINKINFO 7
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DSO_STREAM 8
 #define DSO_SEQPACKET 9
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DSO_MAXWINDOW 11
 #define DSO_NODELAY 12
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DSO_CORK 13
 #define DSO_SERVICES 14
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DSO_INFO 15
 #define DSO_MAX 15
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define LL_INACTIVE 0
 #define LL_CONNECTING 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define LL_RUNNING 2
 #define LL_DISCONNECTING 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ACC_IMMED 0
 #define ACC_DEFER 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SDF_WILD 1
 #define SDF_PROXY 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SDF_UICPROXY 4
 struct dn_naddr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __le16 a_len;
  __u8 a_addr[DN_MAXADDL];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct sockaddr_dn {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 sdn_family;
  __u8 sdn_flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 sdn_objnum;
  __le16 sdn_objnamel;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 sdn_objname[DN_MAXOBJL];
  struct dn_naddr sdn_add;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define sdn_nodeaddrl sdn_add.a_len
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define sdn_nodeaddr sdn_add.a_addr
 struct optdata_dn {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __le16 opt_status;
 #define opt_sts opt_status
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __le16 opt_optl;
  __u8 opt_data[16];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct accessdata_dn {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 acc_accl;
  __u8 acc_acc[DN_MAXACCL];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 acc_passl;
  __u8 acc_pass[DN_MAXACCL];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 acc_userl;
  __u8 acc_user[DN_MAXACCL];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct linkinfo_dn {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 idn_segsize;
  __u8 idn_linkstate;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 union etheraddress {
- __u8 dne_addr[6];
- struct {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 dne_addr[ETH_ALEN];
+ struct {
  __u8 dne_hiord[4];
  __u8 dne_nodeaddr[2];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } dne_remote;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct dn_addr {
  __le16 dna_family;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union etheraddress dna_netaddr;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DECNET_IOCTL_BASE 0x89
 #define SIOCSNETADDR _IOW(DECNET_IOCTL_BASE, 0xe0, struct dn_naddr)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCGNETADDR _IOR(DECNET_IOCTL_BASE, 0xe1, struct dn_naddr)
 #define OSIOCSNETADDR _IOW(DECNET_IOCTL_BASE, 0xe0, int)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OSIOCGNETADDR _IOR(DECNET_IOCTL_BASE, 0xe1, int)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/dqblk_xfs.h b/libc/kernel/uapi/linux/dqblk_xfs.h
index ac93801..31b39d6 100644
--- a/libc/kernel/uapi/linux/dqblk_xfs.h
+++ b/libc/kernel/uapi/linux/dqblk_xfs.h
@@ -36,94 +36,123 @@
 #define Q_XQUOTARM XQM_CMD(6)
 #define Q_XQUOTASYNC XQM_CMD(7)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define Q_XGETQSTATV XQM_CMD(8)
 #define FS_DQUOT_VERSION 1
 typedef struct fs_disk_quota {
  __s8 d_version;
- __s8 d_flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s8 d_flags;
  __u16 d_fieldmask;
  __u32 d_id;
  __u64 d_blk_hardlimit;
- __u64 d_blk_softlimit;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 d_blk_softlimit;
  __u64 d_ino_hardlimit;
  __u64 d_ino_softlimit;
  __u64 d_bcount;
- __u64 d_icount;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 d_icount;
  __s32 d_itimer;
  __s32 d_btimer;
  __u16 d_iwarns;
- __u16 d_bwarns;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 d_bwarns;
  __s32 d_padding2;
  __u64 d_rtb_hardlimit;
  __u64 d_rtb_softlimit;
- __u64 d_rtbcount;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 d_rtbcount;
  __s32 d_rtbtimer;
  __u16 d_rtbwarns;
  __s16 d_padding3;
- char d_padding4[8];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ char d_padding4[8];
 } fs_disk_quota_t;
 #define FS_DQ_ISOFT (1<<0)
 #define FS_DQ_IHARD (1<<1)
-#define FS_DQ_BSOFT (1<<2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FS_DQ_BSOFT (1<<2)
 #define FS_DQ_BHARD (1<<3)
 #define FS_DQ_RTBSOFT (1<<4)
 #define FS_DQ_RTBHARD (1<<5)
-#define FS_DQ_LIMIT_MASK (FS_DQ_ISOFT | FS_DQ_IHARD | FS_DQ_BSOFT |   FS_DQ_BHARD | FS_DQ_RTBSOFT | FS_DQ_RTBHARD)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FS_DQ_LIMIT_MASK (FS_DQ_ISOFT | FS_DQ_IHARD | FS_DQ_BSOFT |   FS_DQ_BHARD | FS_DQ_RTBSOFT | FS_DQ_RTBHARD)
 #define FS_DQ_BTIMER (1<<6)
 #define FS_DQ_ITIMER (1<<7)
 #define FS_DQ_RTBTIMER (1<<8)
-#define FS_DQ_TIMER_MASK (FS_DQ_BTIMER | FS_DQ_ITIMER | FS_DQ_RTBTIMER)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FS_DQ_TIMER_MASK (FS_DQ_BTIMER | FS_DQ_ITIMER | FS_DQ_RTBTIMER)
 #define FS_DQ_BWARNS (1<<9)
 #define FS_DQ_IWARNS (1<<10)
 #define FS_DQ_RTBWARNS (1<<11)
-#define FS_DQ_WARNS_MASK (FS_DQ_BWARNS | FS_DQ_IWARNS | FS_DQ_RTBWARNS)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FS_DQ_WARNS_MASK (FS_DQ_BWARNS | FS_DQ_IWARNS | FS_DQ_RTBWARNS)
 #define FS_DQ_BCOUNT (1<<12)
 #define FS_DQ_ICOUNT (1<<13)
 #define FS_DQ_RTBCOUNT (1<<14)
-#define FS_DQ_ACCT_MASK (FS_DQ_BCOUNT | FS_DQ_ICOUNT | FS_DQ_RTBCOUNT)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FS_DQ_ACCT_MASK (FS_DQ_BCOUNT | FS_DQ_ICOUNT | FS_DQ_RTBCOUNT)
 #define FS_QUOTA_UDQ_ACCT (1<<0)
 #define FS_QUOTA_UDQ_ENFD (1<<1)
 #define FS_QUOTA_GDQ_ACCT (1<<2)
-#define FS_QUOTA_GDQ_ENFD (1<<3)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FS_QUOTA_GDQ_ENFD (1<<3)
 #define FS_QUOTA_PDQ_ACCT (1<<4)
 #define FS_QUOTA_PDQ_ENFD (1<<5)
 #define FS_USER_QUOTA (1<<0)
-#define FS_PROJ_QUOTA (1<<1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FS_PROJ_QUOTA (1<<1)
 #define FS_GROUP_QUOTA (1<<2)
 #define FS_QSTAT_VERSION 1
 typedef struct fs_qfilestat {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 qfs_ino;
+ __u64 qfs_nblks;
+ __u32 qfs_nextents;
+} fs_qfilestat_t;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct fs_quota_stat {
+ __s8 qs_version;
+ __u16 qs_flags;
+ __s8 qs_pad;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ fs_qfilestat_t qs_uquota;
+ fs_qfilestat_t qs_gquota;
+ __u32 qs_incoredqs;
+ __s32 qs_btimelimit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s32 qs_itimelimit;
+ __s32 qs_rtbtimelimit;
+ __u16 qs_bwarnlimit;
+ __u16 qs_iwarnlimit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+} fs_quota_stat_t;
+#define FS_QSTATV_VERSION1 1
+struct fs_qfilestatv {
  __u64 qfs_ino;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 qfs_nblks;
  __u32 qfs_nextents;
-} fs_qfilestat_t;
-typedef struct fs_quota_stat {
+ __u32 qfs_pad;
+};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct fs_quota_statv {
  __s8 qs_version;
+ __u8 qs_pad1;
  __u16 qs_flags;
- __s8 qs_pad;
- fs_qfilestat_t qs_uquota;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- fs_qfilestat_t qs_gquota;
  __u32 qs_incoredqs;
+ struct fs_qfilestatv qs_uquota;
+ struct fs_qfilestatv qs_gquota;
+ struct fs_qfilestatv qs_pquota;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 qs_btimelimit;
  __s32 qs_itimelimit;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 qs_rtbtimelimit;
  __u16 qs_bwarnlimit;
- __u16 qs_iwarnlimit;
-} fs_quota_stat_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 qs_iwarnlimit;
+ __u64 qs_pad2[8];
+};
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/elf-em.h b/libc/kernel/uapi/linux/elf-em.h
index 5802feb..1e86c5c 100644
--- a/libc/kernel/uapi/linux/elf-em.h
+++ b/libc/kernel/uapi/linux/elf-em.h
@@ -38,28 +38,29 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define EM_PPC64 21
 #define EM_SPU 23
+#define EM_ARM 40
 #define EM_SH 42
-#define EM_SPARCV9 43
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EM_SPARCV9 43
 #define EM_IA_64 50
 #define EM_X86_64 62
 #define EM_S390 22
-#define EM_CRIS 76
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EM_CRIS 76
 #define EM_V850 87
 #define EM_M32R 88
-#define EM_H8_300 46
 #define EM_MN10300 89
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define EM_BLACKFIN 106
 #define EM_TI_C6000 140
+#define EM_AARCH64 183
 #define EM_FRV 0x5441
-#define EM_AVR32 0x18ad
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EM_AVR32 0x18ad
 #define EM_ALPHA 0x9026
 #define EM_CYGNUS_V850 0x9080
 #define EM_CYGNUS_M32R 0x9041
-#define EM_S390_OLD 0xA390
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EM_S390_OLD 0xA390
 #define EM_CYGNUS_MN10300 0xbeef
 #endif
diff --git a/libc/kernel/uapi/linux/fd.h b/libc/kernel/uapi/linux/fd.h
index a018777..cfc82a6 100644
--- a/libc/kernel/uapi/linux/fd.h
+++ b/libc/kernel/uapi/linux/fd.h
@@ -127,127 +127,128 @@
  FD_UNUSED_BIT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  FD_DISK_CHANGED_BIT,
- FD_DISK_WRITABLE_BIT
+ FD_DISK_WRITABLE_BIT,
+ FD_OPEN_SHOULD_FAIL_BIT
 };
-#define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params)
 #define FDGETDRVPRM _IOR(2, 0x11, struct floppy_drive_params)
 struct floppy_drive_struct {
  unsigned long flags;
-#define FD_NEED_TWADDLE (1 << FD_NEED_TWADDLE_BIT)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FD_NEED_TWADDLE (1 << FD_NEED_TWADDLE_BIT)
 #define FD_VERIFY (1 << FD_VERIFY_BIT)
 #define FD_DISK_NEWCHANGE (1 << FD_DISK_NEWCHANGE_BIT)
 #define FD_DISK_CHANGED (1 << FD_DISK_CHANGED_BIT)
-#define FD_DISK_WRITABLE (1 << FD_DISK_WRITABLE_BIT)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FD_DISK_WRITABLE (1 << FD_DISK_WRITABLE_BIT)
  unsigned long spinup_date;
  unsigned long select_date;
  unsigned long first_read_date;
- short probed_format;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ short probed_format;
  short track;
  short maxblock;
  short maxtrack;
- int generation;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int generation;
  int keep_data;
  int fd_ref;
  int fd_device;
- unsigned long last_checked;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long last_checked;
  char *dmabuf;
  int bufblocks;
 };
-#define FDGETDRVSTAT _IOR(2, 0x12, struct floppy_drive_struct)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FDGETDRVSTAT _IOR(2, 0x12, struct floppy_drive_struct)
 #define FDPOLLDRVSTAT _IOR(2, 0x13, struct floppy_drive_struct)
 enum reset_mode {
  FD_RESET_IF_NEEDED,
- FD_RESET_IF_RAWCMD,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ FD_RESET_IF_RAWCMD,
  FD_RESET_ALWAYS
 };
 #define FDRESET _IO(2, 0x54)
-struct floppy_fdc_state {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct floppy_fdc_state {
  int spec1;
  int spec2;
  int dtr;
- unsigned char version;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char version;
  unsigned char dor;
  unsigned long address;
  unsigned int rawcmd:2;
- unsigned int reset:1;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int reset:1;
  unsigned int need_configure:1;
  unsigned int perp_mode:2;
  unsigned int has_fifo:1;
- unsigned int driver_version;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int driver_version;
 #define FD_DRIVER_VERSION 0x100
  unsigned char track[4];
 };
-#define FDGETFDCSTAT _IOR(2, 0x15, struct floppy_fdc_state)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FDGETFDCSTAT _IOR(2, 0x15, struct floppy_fdc_state)
 struct floppy_write_errors {
  unsigned int write_errors;
  unsigned long first_error_sector;
- int first_error_generation;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int first_error_generation;
  unsigned long last_error_sector;
  int last_error_generation;
  unsigned int badness;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define FDWERRORCLR _IO(2, 0x56)
 #define FDWERRORGET _IOR(2, 0x17, struct floppy_write_errors)
 #define FDHAVEBATCHEDRAWCMD
-struct floppy_raw_cmd {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct floppy_raw_cmd {
  unsigned int flags;
 #define FD_RAW_READ 1
 #define FD_RAW_WRITE 2
-#define FD_RAW_NO_MOTOR 4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FD_RAW_NO_MOTOR 4
 #define FD_RAW_DISK_CHANGE 4
 #define FD_RAW_INTR 8
 #define FD_RAW_SPIN 0x10
-#define FD_RAW_NO_MOTOR_AFTER 0x20
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FD_RAW_NO_MOTOR_AFTER 0x20
 #define FD_RAW_NEED_DISK 0x40
 #define FD_RAW_NEED_SEEK 0x80
 #define FD_RAW_MORE 0x100
-#define FD_RAW_STOP_IF_FAILURE 0x200
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FD_RAW_STOP_IF_FAILURE 0x200
 #define FD_RAW_STOP_IF_SUCCESS 0x400
 #define FD_RAW_SOFTFAILURE 0x800
 #define FD_RAW_FAILURE 0x10000
-#define FD_RAW_HARDFAILURE 0x20000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FD_RAW_HARDFAILURE 0x20000
  void __user *data;
  char *kernel_data;
  struct floppy_raw_cmd *next;
- long length;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ long length;
  long phys_length;
  int buffer_length;
  unsigned char rate;
- unsigned char cmd_count;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char cmd_count;
  unsigned char cmd[16];
  unsigned char reply_count;
  unsigned char reply[16];
- int track;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int track;
  int resultcode;
  int reserved1;
  int reserved2;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define FDRAWCMD _IO(2, 0x58)
 #define FDTWADDLE _IO(2, 0x59)
 #define FDEJECT _IO(2, 0x5a)
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/fib_rules.h b/libc/kernel/uapi/linux/fib_rules.h
index 500501e..afe6bc0 100644
--- a/libc/kernel/uapi/linux/fib_rules.h
+++ b/libc/kernel/uapi/linux/fib_rules.h
@@ -62,8 +62,8 @@
  FRA_FLOW,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  FRA_UNUSED6,
- FRA_UNUSED7,
- FRA_UNUSED8,
+ FRA_SUPPRESS_IFGROUP,
+ FRA_SUPPRESS_PREFIXLEN,
  FRA_TABLE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  FRA_FWMASK,
diff --git a/libc/kernel/uapi/linux/fiemap.h b/libc/kernel/uapi/linux/fiemap.h
index 58ed947..e4b46c2 100644
--- a/libc/kernel/uapi/linux/fiemap.h
+++ b/libc/kernel/uapi/linux/fiemap.h
@@ -44,20 +44,21 @@
 #define FIEMAP_MAX_OFFSET (~0ULL)
 #define FIEMAP_FLAG_SYNC 0x00000001
 #define FIEMAP_FLAG_XATTR 0x00000002
-#define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
+#define FIEMAP_FLAG_CACHE 0x00000004
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
 #define FIEMAP_EXTENT_LAST 0x00000001
 #define FIEMAP_EXTENT_UNKNOWN 0x00000002
 #define FIEMAP_EXTENT_DELALLOC 0x00000004
-#define FIEMAP_EXTENT_ENCODED 0x00000008
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FIEMAP_EXTENT_ENCODED 0x00000008
 #define FIEMAP_EXTENT_DATA_ENCRYPTED 0x00000080
 #define FIEMAP_EXTENT_NOT_ALIGNED 0x00000100
 #define FIEMAP_EXTENT_DATA_INLINE 0x00000200
-#define FIEMAP_EXTENT_DATA_TAIL 0x00000400
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FIEMAP_EXTENT_DATA_TAIL 0x00000400
 #define FIEMAP_EXTENT_UNWRITTEN 0x00000800
 #define FIEMAP_EXTENT_MERGED 0x00001000
 #define FIEMAP_EXTENT_SHARED 0x00002000
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/fs.h b/libc/kernel/uapi/linux/fs.h
index cc05238..d6fc730 100644
--- a/libc/kernel/uapi/linux/fs.h
+++ b/libc/kernel/uapi/linux/fs.h
@@ -49,10 +49,10 @@
  unsigned long max_files;
 };
 struct inodes_stat_t {
- int nr_inodes;
+ long nr_inodes;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- int nr_unused;
- int dummy[5];
+ long nr_unused;
+ long dummy[5];
 };
 #define NR_FILE 8192
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/gen_stats.h b/libc/kernel/uapi/linux/gen_stats.h
index 07118bf..e1ca73f 100644
--- a/libc/kernel/uapi/linux/gen_stats.h
+++ b/libc/kernel/uapi/linux/gen_stats.h
@@ -27,37 +27,43 @@
  TCA_STATS_QUEUE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_STATS_APP,
+ TCA_STATS_RATE_EST64,
  __TCA_STATS_MAX,
 };
-#define TCA_STATS_MAX (__TCA_STATS_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCA_STATS_MAX (__TCA_STATS_MAX - 1)
 struct gnet_stats_basic {
  __u64 bytes;
  __u32 packets;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct gnet_stats_basic_packed {
  __u64 bytes;
  __u32 packets;
-} __attribute__ ((packed));
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+} __attribute__ ((packed));
 struct gnet_stats_rate_est {
  __u32 bps;
  __u32 pps;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct gnet_stats_rate_est64 {
+ __u64 bps;
+ __u64 pps;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct gnet_stats_queue {
  __u32 qlen;
  __u32 backlog;
- __u32 drops;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 drops;
  __u32 requeues;
  __u32 overlimits;
 };
-struct gnet_estimator {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct gnet_estimator {
  signed char interval;
  unsigned char ewma_log;
 };
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/genetlink.h b/libc/kernel/uapi/linux/genetlink.h
index c5490f8..c069efd 100644
--- a/libc/kernel/uapi/linux/genetlink.h
+++ b/libc/kernel/uapi/linux/genetlink.h
@@ -39,55 +39,57 @@
 #define GENL_CMD_CAP_HASPOL 0x08
 #define GENL_ID_GENERATE 0
 #define GENL_ID_CTRL NLMSG_MIN_TYPE
-enum {
+#define GENL_ID_VFS_DQUOT (NLMSG_MIN_TYPE + 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GENL_ID_PMCRAID (NLMSG_MIN_TYPE + 2)
+enum {
  CTRL_CMD_UNSPEC,
  CTRL_CMD_NEWFAMILY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_CMD_DELFAMILY,
  CTRL_CMD_GETFAMILY,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_CMD_NEWOPS,
  CTRL_CMD_DELOPS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_CMD_GETOPS,
  CTRL_CMD_NEWMCAST_GRP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_CMD_DELMCAST_GRP,
  CTRL_CMD_GETMCAST_GRP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTRL_CMD_MAX,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_ATTR_UNSPEC,
  CTRL_ATTR_FAMILY_ID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_ATTR_FAMILY_NAME,
  CTRL_ATTR_VERSION,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_ATTR_HDRSIZE,
  CTRL_ATTR_MAXATTR,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_ATTR_OPS,
  CTRL_ATTR_MCAST_GROUPS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTRL_ATTR_MAX,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_ATTR_OP_UNSPEC,
  CTRL_ATTR_OP_ID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_ATTR_OP_FLAGS,
  __CTRL_ATTR_OP_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  CTRL_ATTR_MCAST_GRP_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTRL_ATTR_MCAST_GRP_NAME,
  CTRL_ATTR_MCAST_GRP_ID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTRL_ATTR_MCAST_GRP_MAX,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/genwqe/genwqe_card.h b/libc/kernel/uapi/linux/genwqe/genwqe_card.h
new file mode 100644
index 0000000..c831cfc
--- /dev/null
+++ b/libc/kernel/uapi/linux/genwqe/genwqe_card.h
@@ -0,0 +1,331 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __GENWQE_CARD_H__
+#define __GENWQE_CARD_H__
+#include <linux/types.h>
+#include <linux/ioctl.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GENWQE_DEVNAME "genwqe"
+#define GENWQE_TYPE_ALTERA_230 0x00
+#define GENWQE_TYPE_ALTERA_530 0x01
+#define GENWQE_TYPE_ALTERA_A4 0x02
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GENWQE_TYPE_ALTERA_A7 0x03
+#define GENWQE_UID_OFFS(uid) ((uid) << 24)
+#define GENWQE_SLU_OFFS GENWQE_UID_OFFS(0)
+#define GENWQE_HSU_OFFS GENWQE_UID_OFFS(1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GENWQE_APP_OFFS GENWQE_UID_OFFS(2)
+#define GENWQE_MAX_UNITS 3
+#define IO_EXTENDED_ERROR_POINTER 0x00000048
+#define IO_ERROR_INJECT_SELECTOR 0x00000060
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_EXTENDED_DIAG_SELECTOR 0x00000070
+#define IO_EXTENDED_DIAG_READ_MBX 0x00000078
+#define IO_EXTENDED_DIAG_MAP(ring) (0x00000500 | ((ring) << 3))
+#define GENWQE_EXTENDED_DIAG_SELECTOR(ring, trace) (((ring) << 8) | (trace))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLU_UNITCFG 0x00000000
+#define IO_SLU_UNITCFG_TYPE_MASK 0x000000000ff00000
+#define IO_SLU_FIR 0x00000008
+#define IO_SLU_FIR_CLR 0x00000010
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLU_FEC 0x00000018
+#define IO_SLU_ERR_ACT_MASK 0x00000020
+#define IO_SLU_ERR_ATTN_MASK 0x00000028
+#define IO_SLU_FIRX1_ACT_MASK 0x00000030
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLU_FIRX0_ACT_MASK 0x00000038
+#define IO_SLU_SEC_LEM_DEBUG_OVR 0x00000040
+#define IO_SLU_EXTENDED_ERR_PTR 0x00000048
+#define IO_SLU_COMMON_CONFIG 0x00000060
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLU_FLASH_FIR 0x00000108
+#define IO_SLU_SLC_FIR 0x00000110
+#define IO_SLU_RIU_TRAP 0x00000280
+#define IO_SLU_FLASH_FEC 0x00000308
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLU_SLC_FEC 0x00000310
+#define IO_SLC_QUEUE_SEGMENT 0x00010000
+#define IO_SLC_VF_QUEUE_SEGMENT 0x00050000
+#define IO_SLC_QUEUE_OFFSET 0x00010008
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLC_VF_QUEUE_OFFSET 0x00050008
+#define IO_SLC_QUEUE_CONFIG 0x00010010
+#define IO_SLC_VF_QUEUE_CONFIG 0x00050010
+#define IO_SLC_APPJOB_TIMEOUT 0x00010018
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLC_VF_APPJOB_TIMEOUT 0x00050018
+#define TIMEOUT_250MS 0x0000000f
+#define HEARTBEAT_DISABLE 0x0000ff00
+#define IO_SLC_QUEUE_INITSQN 0x00010020
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLC_VF_QUEUE_INITSQN 0x00050020
+#define IO_SLC_QUEUE_WRAP 0x00010028
+#define IO_SLC_VF_QUEUE_WRAP 0x00050028
+#define IO_SLC_QUEUE_STATUS 0x00010100
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLC_VF_QUEUE_STATUS 0x00050100
+#define IO_SLC_QUEUE_WTIME 0x00010030
+#define IO_SLC_VF_QUEUE_WTIME 0x00050030
+#define IO_SLC_QUEUE_ERRCNTS 0x00010038
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLC_VF_QUEUE_ERRCNTS 0x00050038
+#define IO_SLC_QUEUE_LRW 0x00010040
+#define IO_SLC_VF_QUEUE_LRW 0x00050040
+#define IO_SLC_FREE_RUNNING_TIMER 0x00010108
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLC_VF_FREE_RUNNING_TIMER 0x00050108
+#define IO_PF_SLC_VIRTUAL_REGION 0x00050000
+#define IO_PF_SLC_VIRTUAL_WINDOW 0x00060000
+#define IO_PF_SLC_JOBPEND(n) (0x00061000 + 8*(n))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLC_JOBPEND(n) IO_PF_SLC_JOBPEND(n)
+#define IO_SLU_SLC_PARSE_TRAP(n) (0x00011000 + 8*(n))
+#define IO_SLU_SLC_DISP_TRAP(n) (0x00011200 + 8*(n))
+#define IO_SLC_CFGREG_GFIR 0x00020000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GFIR_ERR_TRIGGER 0x0000ffff
+#define IO_SLC_CFGREG_SOFTRESET 0x00020018
+#define IO_SLC_MISC_DEBUG 0x00020060
+#define IO_SLC_MISC_DEBUG_CLR 0x00020068
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLC_MISC_DEBUG_SET 0x00020070
+#define IO_SLU_TEMPERATURE_SENSOR 0x00030000
+#define IO_SLU_TEMPERATURE_CONFIG 0x00030008
+#define IO_SLU_VOLTAGE_CONTROL 0x00030080
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLU_VOLTAGE_NOMINAL 0x00000000
+#define IO_SLU_VOLTAGE_DOWN5 0x00000006
+#define IO_SLU_VOLTAGE_UP5 0x00000007
+#define IO_SLU_LEDCONTROL 0x00030100
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_SLU_FLASH_DIRECTACCESS 0x00040010
+#define IO_SLU_FLASH_DIRECTACCESS2 0x00040020
+#define IO_SLU_FLASH_CMDINTF 0x00040030
+#define IO_SLU_BITSTREAM 0x00040040
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_HSU_ERR_BEHAVIOR 0x01001010
+#define IO_SLC2_SQB_TRAP 0x00062000
+#define IO_SLC2_QUEUE_MANAGER_TRAP 0x00062008
+#define IO_SLC2_FLS_MASTER_TRAP 0x00062010
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_HSU_UNITCFG 0x01000000
+#define IO_HSU_FIR 0x01000008
+#define IO_HSU_FIR_CLR 0x01000010
+#define IO_HSU_FEC 0x01000018
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_HSU_ERR_ACT_MASK 0x01000020
+#define IO_HSU_ERR_ATTN_MASK 0x01000028
+#define IO_HSU_FIRX1_ACT_MASK 0x01000030
+#define IO_HSU_FIRX0_ACT_MASK 0x01000038
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_HSU_SEC_LEM_DEBUG_OVR 0x01000040
+#define IO_HSU_EXTENDED_ERR_PTR 0x01000048
+#define IO_HSU_COMMON_CONFIG 0x01000060
+#define IO_APP_UNITCFG 0x02000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_APP_FIR 0x02000008
+#define IO_APP_FIR_CLR 0x02000010
+#define IO_APP_FEC 0x02000018
+#define IO_APP_ERR_ACT_MASK 0x02000020
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_APP_ERR_ATTN_MASK 0x02000028
+#define IO_APP_FIRX1_ACT_MASK 0x02000030
+#define IO_APP_FIRX0_ACT_MASK 0x02000038
+#define IO_APP_SEC_LEM_DEBUG_OVR 0x02000040
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_APP_EXTENDED_ERR_PTR 0x02000048
+#define IO_APP_COMMON_CONFIG 0x02000060
+#define IO_APP_DEBUG_REG_01 0x02010000
+#define IO_APP_DEBUG_REG_02 0x02010008
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_APP_DEBUG_REG_03 0x02010010
+#define IO_APP_DEBUG_REG_04 0x02010018
+#define IO_APP_DEBUG_REG_05 0x02010020
+#define IO_APP_DEBUG_REG_06 0x02010028
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_APP_DEBUG_REG_07 0x02010030
+#define IO_APP_DEBUG_REG_08 0x02010038
+#define IO_APP_DEBUG_REG_09 0x02010040
+#define IO_APP_DEBUG_REG_10 0x02010048
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_APP_DEBUG_REG_11 0x02010050
+#define IO_APP_DEBUG_REG_12 0x02010058
+#define IO_APP_DEBUG_REG_13 0x02010060
+#define IO_APP_DEBUG_REG_14 0x02010068
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_APP_DEBUG_REG_15 0x02010070
+#define IO_APP_DEBUG_REG_16 0x02010078
+#define IO_APP_DEBUG_REG_17 0x02010080
+#define IO_APP_DEBUG_REG_18 0x02010088
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct genwqe_reg_io {
+ __u64 num;
+ __u64 val64;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IO_ILLEGAL_VALUE 0xffffffffffffffffull
+#define DDCB_ACFUNC_SLU 0x00
+#define DDCB_ACFUNC_APP 0x01
+#define DDCB_RETC_IDLE 0x0000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DDCB_RETC_PENDING 0x0101
+#define DDCB_RETC_COMPLETE 0x0102
+#define DDCB_RETC_FAULT 0x0104
+#define DDCB_RETC_ERROR 0x0108
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DDCB_RETC_FORCED_ERROR 0x01ff
+#define DDCB_RETC_UNEXEC 0x0110
+#define DDCB_RETC_TERM 0x0120
+#define DDCB_RETC_RES0 0x0140
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DDCB_RETC_RES1 0x0180
+#define DDCB_OPT_ECHO_FORCE_NO 0x0000
+#define DDCB_OPT_ECHO_FORCE_102 0x0001
+#define DDCB_OPT_ECHO_FORCE_104 0x0002
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DDCB_OPT_ECHO_FORCE_108 0x0003
+#define DDCB_OPT_ECHO_FORCE_110 0x0004
+#define DDCB_OPT_ECHO_FORCE_120 0x0005
+#define DDCB_OPT_ECHO_FORCE_140 0x0006
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DDCB_OPT_ECHO_FORCE_180 0x0007
+#define DDCB_OPT_ECHO_COPY_NONE (0 << 5)
+#define DDCB_OPT_ECHO_COPY_ALL (1 << 5)
+#define SLCMD_ECHO_SYNC 0x00
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SLCMD_MOVE_FLASH 0x06
+#define SLCMD_MOVE_FLASH_FLAGS_MODE 0x03
+#define SLCMD_MOVE_FLASH_FLAGS_DLOAD 0
+#define SLCMD_MOVE_FLASH_FLAGS_EMUL 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SLCMD_MOVE_FLASH_FLAGS_UPLOAD 2
+#define SLCMD_MOVE_FLASH_FLAGS_VERIFY 3
+#define SLCMD_MOVE_FLASH_FLAG_NOTAP (1 << 2)
+#define SLCMD_MOVE_FLASH_FLAG_POLL (1 << 3)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SLCMD_MOVE_FLASH_FLAG_PARTITION (1 << 4)
+#define SLCMD_MOVE_FLASH_FLAG_ERASE (1 << 5)
+enum genwqe_card_state {
+ GENWQE_CARD_UNUSED = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ GENWQE_CARD_USED = 1,
+ GENWQE_CARD_FATAL_ERROR = 2,
+ GENWQE_CARD_STATE_MAX,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct genwqe_bitstream {
+ __u64 data_addr;
+ __u32 size;
+ __u32 crc;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 target_addr;
+ __u32 partition;
+ __u32 uid;
+ __u64 slu_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 app_id;
+ __u16 retc;
+ __u16 attn;
+ __u32 progress;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define DDCB_LENGTH 256
+#define DDCB_ASIV_LENGTH 104
+#define DDCB_ASIV_LENGTH_ATS 96
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DDCB_ASV_LENGTH 64
+#define DDCB_FIXUPS 12
+struct genwqe_debug_data {
+ char driver_version[64];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 slu_unitcfg;
+ __u64 app_unitcfg;
+ __u8 ddcb_before[DDCB_LENGTH];
+ __u8 ddcb_prev[DDCB_LENGTH];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 ddcb_finished[DDCB_LENGTH];
+};
+#define ATS_TYPE_DATA 0x0ull
+#define ATS_TYPE_FLAT_RD 0x4ull
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ATS_TYPE_FLAT_RDWR 0x5ull
+#define ATS_TYPE_SGL_RD 0x6ull
+#define ATS_TYPE_SGL_RDWR 0x7ull
+#define ATS_SET_FLAGS(_struct, _field, _flags)   (((_flags) & 0xf) << (44 - (4 * (offsetof(_struct, _field) / 8))))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ATS_GET_FLAGS(_ats, _byte_offs)   (((_ats) >> (44 - (4 * ((_byte_offs) / 8)))) & 0xf)
+struct genwqe_ddcb_cmd {
+ __u64 next_addr;
+ __u64 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 acfunc;
+ __u8 cmd;
+ __u8 asiv_length;
+ __u8 asv_length;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 cmdopts;
+ __u16 retc;
+ __u16 attn;
+ __u16 vcrc;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 progress;
+ __u64 deque_ts;
+ __u64 cmplt_ts;
+ __u64 disp_ts;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 ddata_addr;
+ __u8 asv[DDCB_ASV_LENGTH];
+ union {
+ struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 ats;
+ __u8 asiv[DDCB_ASIV_LENGTH_ATS];
+ };
+ __u8 __asiv[DDCB_ASIV_LENGTH];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ };
+};
+#define GENWQE_IOC_CODE 0xa5
+#define GENWQE_READ_REG64 _IOR(GENWQE_IOC_CODE, 30, struct genwqe_reg_io)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GENWQE_WRITE_REG64 _IOW(GENWQE_IOC_CODE, 31, struct genwqe_reg_io)
+#define GENWQE_READ_REG32 _IOR(GENWQE_IOC_CODE, 32, struct genwqe_reg_io)
+#define GENWQE_WRITE_REG32 _IOW(GENWQE_IOC_CODE, 33, struct genwqe_reg_io)
+#define GENWQE_READ_REG16 _IOR(GENWQE_IOC_CODE, 34, struct genwqe_reg_io)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GENWQE_WRITE_REG16 _IOW(GENWQE_IOC_CODE, 35, struct genwqe_reg_io)
+#define GENWQE_GET_CARD_STATE _IOR(GENWQE_IOC_CODE, 36, enum genwqe_card_state)
+struct genwqe_mem {
+ __u64 addr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 size;
+ __u64 direction;
+ __u64 flags;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GENWQE_PIN_MEM _IOWR(GENWQE_IOC_CODE, 40, struct genwqe_mem)
+#define GENWQE_UNPIN_MEM _IOWR(GENWQE_IOC_CODE, 41, struct genwqe_mem)
+#define GENWQE_EXECUTE_DDCB   _IOWR(GENWQE_IOC_CODE, 50, struct genwqe_ddcb_cmd)
+#define GENWQE_EXECUTE_RAW_DDCB   _IOWR(GENWQE_IOC_CODE, 51, struct genwqe_ddcb_cmd)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GENWQE_SLU_UPDATE _IOWR(GENWQE_IOC_CODE, 80, struct genwqe_bitstream)
+#define GENWQE_SLU_READ _IOWR(GENWQE_IOC_CODE, 81, struct genwqe_bitstream)
+#endif
diff --git a/libc/kernel/uapi/linux/gfs2_ondisk.h b/libc/kernel/uapi/linux/gfs2_ondisk.h
index 2e80472..a3106ba 100644
--- a/libc/kernel/uapi/linux/gfs2_ondisk.h
+++ b/libc/kernel/uapi/linux/gfs2_ondisk.h
@@ -274,83 +274,95 @@
  __be16 lf_entries;
  __be32 lf_dirent_format;
  __be64 lf_next;
- __u8 lf_reserved[64];
+ union {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 lf_reserved[64];
+ struct {
+ __be64 lf_inode;
+ __be32 lf_dist;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 lf_nsec;
+ __be64 lf_sec;
+ __u8 lf_reserved2[40];
+ };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ };
 };
 #define GFS2_EA_MAX_NAME_LEN 255
 #define GFS2_EA_MAX_DATA_LEN 65536
-#define GFS2_EATYPE_UNUSED 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GFS2_EATYPE_UNUSED 0
 #define GFS2_EATYPE_USR 1
 #define GFS2_EATYPE_SYS 2
 #define GFS2_EATYPE_SECURITY 3
-#define GFS2_EATYPE_LAST 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GFS2_EATYPE_LAST 3
 #define GFS2_EATYPE_VALID(x) ((x) <= GFS2_EATYPE_LAST)
 #define GFS2_EAFLAG_LAST 0x01
 struct gfs2_ea_header {
- __be32 ea_rec_len;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 ea_rec_len;
  __be32 ea_data_len;
  __u8 ea_name_len;
  __u8 ea_type;
- __u8 ea_flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 ea_flags;
  __u8 ea_num_ptrs;
  __u32 __pad;
 };
-#define GFS2_LOG_HEAD_UNMOUNT 0x00000001
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GFS2_LOG_HEAD_UNMOUNT 0x00000001
 struct gfs2_log_header {
  struct gfs2_meta_header lh_header;
  __be64 lh_sequence;
- __be32 lh_flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 lh_flags;
  __be32 lh_tail;
  __be32 lh_blkno;
  __be32 lh_hash;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define GFS2_LOG_DESC_METADATA 300
 #define GFS2_LOG_DESC_REVOKE 301
 #define GFS2_LOG_DESC_JDATA 302
-struct gfs2_log_descriptor {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct gfs2_log_descriptor {
  struct gfs2_meta_header ld_header;
  __be32 ld_type;
  __be32 ld_length;
- __be32 ld_data1;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 ld_data1;
  __be32 ld_data2;
  __u8 ld_reserved[32];
 };
-#define GFS2_INUM_QUANTUM 1048576
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define GFS2_INUM_QUANTUM 1048576
 struct gfs2_inum_range {
  __be64 ir_start;
  __be64 ir_length;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct gfs2_statfs_change {
  __be64 sc_total;
  __be64 sc_free;
- __be64 sc_dinodes;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be64 sc_dinodes;
 };
 #define GFS2_QCF_USER 0x00000001
 struct gfs2_quota_change {
- __be64 qc_change;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be64 qc_change;
  __be32 qc_flags;
  __be32 qc_id;
 };
-struct gfs2_quota_lvb {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct gfs2_quota_lvb {
  __be32 qb_magic;
  __u32 __pad;
  __be64 qb_limit;
- __be64 qb_warn;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be64 qb_warn;
  __be64 qb_value;
 };
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/hash_info.h b/libc/kernel/uapi/linux/hash_info.h
new file mode 100644
index 0000000..fd3543c
--- /dev/null
+++ b/libc/kernel/uapi/linux/hash_info.h
@@ -0,0 +1,46 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI_LINUX_HASH_INFO_H
+#define _UAPI_LINUX_HASH_INFO_H
+enum hash_algo {
+ HASH_ALGO_MD4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HASH_ALGO_MD5,
+ HASH_ALGO_SHA1,
+ HASH_ALGO_RIPE_MD_160,
+ HASH_ALGO_SHA256,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HASH_ALGO_SHA384,
+ HASH_ALGO_SHA512,
+ HASH_ALGO_SHA224,
+ HASH_ALGO_RIPE_MD_128,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HASH_ALGO_RIPE_MD_256,
+ HASH_ALGO_RIPE_MD_320,
+ HASH_ALGO_WP_256,
+ HASH_ALGO_WP_384,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HASH_ALGO_WP_512,
+ HASH_ALGO_TGR_128,
+ HASH_ALGO_TGR_160,
+ HASH_ALGO_TGR_192,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HASH_ALGO__LAST
+};
+#endif
diff --git a/libc/kernel/uapi/linux/hsr_netlink.h b/libc/kernel/uapi/linux/hsr_netlink.h
new file mode 100644
index 0000000..bf47d64
--- /dev/null
+++ b/libc/kernel/uapi/linux/hsr_netlink.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __UAPI_HSR_NETLINK_H
+#define __UAPI_HSR_NETLINK_H
+enum {
+ HSR_A_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HSR_A_NODE_ADDR,
+ HSR_A_IFINDEX,
+ HSR_A_IF1_AGE,
+ HSR_A_IF2_AGE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HSR_A_NODE_ADDR_B,
+ HSR_A_IF1_SEQ,
+ HSR_A_IF2_SEQ,
+ HSR_A_IF1_IFINDEX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HSR_A_IF2_IFINDEX,
+ HSR_A_ADDR_B_IFINDEX,
+ __HSR_A_MAX,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HSR_A_MAX (__HSR_A_MAX - 1)
+enum {
+ HSR_C_UNSPEC,
+ HSR_C_RING_ERROR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HSR_C_NODE_DOWN,
+ HSR_C_GET_NODE_STATUS,
+ HSR_C_SET_NODE_STATUS,
+ HSR_C_GET_NODE_LIST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ HSR_C_SET_NODE_LIST,
+ __HSR_C_MAX,
+};
+#define HSR_C_MAX (__HSR_C_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/icmpv6.h b/libc/kernel/uapi/linux/icmpv6.h
index 7ec628c..542eca5 100644
--- a/libc/kernel/uapi/linux/icmpv6.h
+++ b/libc/kernel/uapi/linux/icmpv6.h
@@ -133,29 +133,32 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ICMPV6_ADDR_UNREACH 3
 #define ICMPV6_PORT_UNREACH 4
+#define ICMPV6_POLICY_FAIL 5
+#define ICMPV6_REJECT_ROUTE 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ICMPV6_EXC_HOPLIMIT 0
 #define ICMPV6_EXC_FRAGTIME 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ICMPV6_HDR_FIELD 0
 #define ICMPV6_UNK_NEXTHDR 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ICMPV6_UNK_OPTION 2
 #define ICMPV6_FILTER 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ICMPV6_FILTER_BLOCK 1
 #define ICMPV6_FILTER_PASS 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ICMPV6_FILTER_BLOCKOTHERS 3
 #define ICMPV6_FILTER_PASSONLY 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct icmp6_filter {
  __u32 data[8];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define MLD2_MODE_IS_INCLUDE 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MLD2_MODE_IS_EXCLUDE 2
 #define MLD2_CHANGE_TO_INCLUDE 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MLD2_CHANGE_TO_EXCLUDE 4
 #define MLD2_ALLOW_NEW_SOURCES 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MLD2_BLOCK_OLD_SOURCES 6
 #define MLD2_ALL_MCR_INIT { { { 0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,0x16 } } }
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/if.h b/libc/kernel/uapi/linux/if.h
index 2b7133f..4eca84d 100644
--- a/libc/kernel/uapi/linux/if.h
+++ b/libc/kernel/uapi/linux/if.h
@@ -77,134 +77,135 @@
 #define IFF_SUPP_NOFCS 0x80000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFF_LIVE_ADDR_CHANGE 0x100000
+#define IFF_MACVLAN 0x200000
 #define IF_GET_IFACE 0x0001
 #define IF_GET_PROTO 0x0002
-#define IF_IFACE_V35 0x1000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IF_IFACE_V35 0x1000
 #define IF_IFACE_V24 0x1001
 #define IF_IFACE_X21 0x1002
 #define IF_IFACE_T1 0x1003
-#define IF_IFACE_E1 0x1004
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IF_IFACE_E1 0x1004
 #define IF_IFACE_SYNC_SERIAL 0x1005
 #define IF_IFACE_X21D 0x1006
 #define IF_PROTO_HDLC 0x2000
-#define IF_PROTO_PPP 0x2001
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IF_PROTO_PPP 0x2001
 #define IF_PROTO_CISCO 0x2002
 #define IF_PROTO_FR 0x2003
 #define IF_PROTO_FR_ADD_PVC 0x2004
-#define IF_PROTO_FR_DEL_PVC 0x2005
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IF_PROTO_FR_DEL_PVC 0x2005
 #define IF_PROTO_X25 0x2006
 #define IF_PROTO_HDLC_ETH 0x2007
 #define IF_PROTO_FR_ADD_ETH_PVC 0x2008
-#define IF_PROTO_FR_DEL_ETH_PVC 0x2009
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IF_PROTO_FR_DEL_ETH_PVC 0x2009
 #define IF_PROTO_FR_PVC 0x200A
 #define IF_PROTO_FR_ETH_PVC 0x200B
 #define IF_PROTO_RAW 0x200C
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  IF_OPER_UNKNOWN,
  IF_OPER_NOTPRESENT,
  IF_OPER_DOWN,
- IF_OPER_LOWERLAYERDOWN,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IF_OPER_LOWERLAYERDOWN,
  IF_OPER_TESTING,
  IF_OPER_DORMANT,
  IF_OPER_UP,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  IF_LINK_MODE_DEFAULT,
  IF_LINK_MODE_DORMANT,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct ifmap {
  unsigned long mem_start;
  unsigned long mem_end;
- unsigned short base_addr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned short base_addr;
  unsigned char irq;
  unsigned char dma;
  unsigned char port;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct if_settings {
  unsigned int type;
  unsigned int size;
- union {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union {
  raw_hdlc_proto __user *raw_hdlc;
  cisco_proto __user *cisco;
  fr_proto __user *fr;
- fr_proto_pvc __user *fr_pvc;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ fr_proto_pvc __user *fr_pvc;
  fr_proto_pvc_info __user *fr_pvc_info;
  sync_serial_settings __user *sync;
  te1_settings __user *te1;
- } ifs_ifsu;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ } ifs_ifsu;
 };
 struct ifreq {
 #define IFHWADDRLEN 6
- union
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union
  {
  char ifrn_name[IFNAMSIZ];
  } ifr_ifrn;
- union {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union {
  struct sockaddr ifru_addr;
  struct sockaddr ifru_dstaddr;
  struct sockaddr ifru_broadaddr;
- struct sockaddr ifru_netmask;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct sockaddr ifru_netmask;
  struct sockaddr ifru_hwaddr;
  short ifru_flags;
  int ifru_ivalue;
- int ifru_mtu;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int ifru_mtu;
  struct ifmap ifru_map;
  char ifru_slave[IFNAMSIZ];
  char ifru_newname[IFNAMSIZ];
- void __user * ifru_data;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ void __user * ifru_data;
  struct if_settings ifru_settings;
  } ifr_ifru;
 };
-#define ifr_name ifr_ifrn.ifrn_name
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ifr_name ifr_ifrn.ifrn_name
 #define ifr_hwaddr ifr_ifru.ifru_hwaddr
 #define ifr_addr ifr_ifru.ifru_addr
 #define ifr_dstaddr ifr_ifru.ifru_dstaddr
-#define ifr_broadaddr ifr_ifru.ifru_broadaddr
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ifr_broadaddr ifr_ifru.ifru_broadaddr
 #define ifr_netmask ifr_ifru.ifru_netmask
 #define ifr_flags ifr_ifru.ifru_flags
 #define ifr_metric ifr_ifru.ifru_ivalue
-#define ifr_mtu ifr_ifru.ifru_mtu
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ifr_mtu ifr_ifru.ifru_mtu
 #define ifr_map ifr_ifru.ifru_map
 #define ifr_slave ifr_ifru.ifru_slave
 #define ifr_data ifr_ifru.ifru_data
-#define ifr_ifindex ifr_ifru.ifru_ivalue
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ifr_ifindex ifr_ifru.ifru_ivalue
 #define ifr_bandwidth ifr_ifru.ifru_ivalue
 #define ifr_qlen ifr_ifru.ifru_ivalue
 #define ifr_newname ifr_ifru.ifru_newname
-#define ifr_settings ifr_ifru.ifru_settings
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ifr_settings ifr_ifru.ifru_settings
 struct ifconf {
  int ifc_len;
  union {
- char __user *ifcu_buf;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ char __user *ifcu_buf;
  struct ifreq __user *ifcu_req;
  } ifc_ifcu;
 };
-#define ifc_buf ifc_ifcu.ifcu_buf
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ifc_buf ifc_ifcu.ifcu_buf
 #define ifc_req ifc_ifcu.ifcu_req
 #endif
diff --git a/libc/kernel/uapi/linux/if_addr.h b/libc/kernel/uapi/linux/if_addr.h
index bd3a6a7..e08a176 100644
--- a/libc/kernel/uapi/linux/if_addr.h
+++ b/libc/kernel/uapi/linux/if_addr.h
@@ -41,29 +41,33 @@
  IFA_CACHEINFO,
  IFA_MULTICAST,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFA_FLAGS,
  __IFA_MAX,
 };
 #define IFA_MAX (__IFA_MAX - 1)
-#define IFA_F_SECONDARY 0x01
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFA_F_SECONDARY 0x01
 #define IFA_F_TEMPORARY IFA_F_SECONDARY
 #define IFA_F_NODAD 0x02
 #define IFA_F_OPTIMISTIC 0x04
-#define IFA_F_DADFAILED 0x08
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFA_F_DADFAILED 0x08
 #define IFA_F_HOMEADDRESS 0x10
 #define IFA_F_DEPRECATED 0x20
 #define IFA_F_TENTATIVE 0x40
-#define IFA_F_PERMANENT 0x80
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFA_F_PERMANENT 0x80
+#define IFA_F_MANAGETEMPADDR 0x100
+#define IFA_F_NOPREFIXROUTE 0x200
 struct ifa_cacheinfo {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ifa_prefered;
  __u32 ifa_valid;
  __u32 cstamp;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tstamp;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/if_arp.h b/libc/kernel/uapi/linux/if_arp.h
index 5c24de6..09ec01d 100644
--- a/libc/kernel/uapi/linux/if_arp.h
+++ b/libc/kernel/uapi/linux/if_arp.h
@@ -96,48 +96,50 @@
 #define ARPHRD_CAIF 822
 #define ARPHRD_IP6GRE 823
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ARPHRD_NETLINK 824
+#define ARPHRD_6LOWPAN 825
 #define ARPHRD_VOID 0xFFFF
 #define ARPHRD_NONE 0xFFFE
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARPOP_REQUEST 1
 #define ARPOP_REPLY 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARPOP_RREQUEST 3
 #define ARPOP_RREPLY 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARPOP_InREQUEST 8
 #define ARPOP_InREPLY 9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ARPOP_NAK 10
 struct arpreq {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct sockaddr arp_pa;
  struct sockaddr arp_ha;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int arp_flags;
  struct sockaddr arp_netmask;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  char arp_dev[16];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct arpreq_old {
  struct sockaddr arp_pa;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct sockaddr arp_ha;
  int arp_flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct sockaddr arp_netmask;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ATF_COM 0x02
 #define ATF_PERM 0x04
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ATF_PUBL 0x08
 #define ATF_USETRAILERS 0x10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ATF_NETMASK 0x20
 #define ATF_DONTPUB 0x40
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct arphdr {
  __be16 ar_hrd;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __be16 ar_pro;
  unsigned char ar_hln;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char ar_pln;
  __be16 ar_op;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/if_bonding.h b/libc/kernel/uapi/linux/if_bonding.h
index e8a936d..c2fae42 100644
--- a/libc/kernel/uapi/linux/if_bonding.h
+++ b/libc/kernel/uapi/linux/if_bonding.h
@@ -56,28 +56,30 @@
 #define BOND_XMIT_POLICY_LAYER34 1
 #define BOND_XMIT_POLICY_LAYER23 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BOND_XMIT_POLICY_ENCAP23 3
+#define BOND_XMIT_POLICY_ENCAP34 4
 typedef struct ifbond {
  __s32 bond_mode;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 num_slaves;
  __s32 miimon;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } ifbond;
 typedef struct ifslave {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 slave_id;
  char slave_name[IFNAMSIZ];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s8 link;
  __s8 state;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 link_failure_count;
 } ifslave;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ad_info {
  __u16 aggregator_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 ports;
  __u16 actor_key;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 partner_key;
  __u8 partner_system[ETH_ALEN];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/if_bridge.h b/libc/kernel/uapi/linux/if_bridge.h
index 145b84d..366912e 100644
--- a/libc/kernel/uapi/linux/if_bridge.h
+++ b/libc/kernel/uapi/linux/if_bridge.h
@@ -19,181 +19,182 @@
 #ifndef _UAPI_LINUX_IF_BRIDGE_H
 #define _UAPI_LINUX_IF_BRIDGE_H
 #include <linux/types.h>
-#define SYSFS_BRIDGE_ATTR "bridge"
+#include <linux/if_ether.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SYSFS_BRIDGE_ATTR "bridge"
 #define SYSFS_BRIDGE_FDB "brforward"
 #define SYSFS_BRIDGE_PORT_SUBDIR "brif"
 #define SYSFS_BRIDGE_PORT_ATTR "brport"
-#define SYSFS_BRIDGE_PORT_LINK "bridge"
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SYSFS_BRIDGE_PORT_LINK "bridge"
 #define BRCTL_VERSION 1
 #define BRCTL_GET_VERSION 0
 #define BRCTL_GET_BRIDGES 1
-#define BRCTL_ADD_BRIDGE 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BRCTL_ADD_BRIDGE 2
 #define BRCTL_DEL_BRIDGE 3
 #define BRCTL_ADD_IF 4
 #define BRCTL_DEL_IF 5
-#define BRCTL_GET_BRIDGE_INFO 6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BRCTL_GET_BRIDGE_INFO 6
 #define BRCTL_GET_PORT_LIST 7
 #define BRCTL_SET_BRIDGE_FORWARD_DELAY 8
 #define BRCTL_SET_BRIDGE_HELLO_TIME 9
-#define BRCTL_SET_BRIDGE_MAX_AGE 10
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BRCTL_SET_BRIDGE_MAX_AGE 10
 #define BRCTL_SET_AGEING_TIME 11
 #define BRCTL_SET_GC_INTERVAL 12
 #define BRCTL_GET_PORT_INFO 13
-#define BRCTL_SET_BRIDGE_STP_STATE 14
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BRCTL_SET_BRIDGE_STP_STATE 14
 #define BRCTL_SET_BRIDGE_PRIORITY 15
 #define BRCTL_SET_PORT_PRIORITY 16
 #define BRCTL_SET_PATH_COST 17
-#define BRCTL_GET_FDB_ENTRIES 18
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BRCTL_GET_FDB_ENTRIES 18
 #define BR_STATE_DISABLED 0
 #define BR_STATE_LISTENING 1
 #define BR_STATE_LEARNING 2
-#define BR_STATE_FORWARDING 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BR_STATE_FORWARDING 3
 #define BR_STATE_BLOCKING 4
 struct __bridge_info {
  __u64 designated_root;
- __u64 bridge_id;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 bridge_id;
  __u32 root_path_cost;
  __u32 max_age;
  __u32 hello_time;
- __u32 forward_delay;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 forward_delay;
  __u32 bridge_max_age;
  __u32 bridge_hello_time;
  __u32 bridge_forward_delay;
- __u8 topology_change;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 topology_change;
  __u8 topology_change_detected;
  __u8 root_port;
  __u8 stp_enabled;
- __u32 ageing_time;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 ageing_time;
  __u32 gc_interval;
  __u32 hello_timer_value;
  __u32 tcn_timer_value;
- __u32 topology_change_timer_value;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 topology_change_timer_value;
  __u32 gc_timer_value;
 };
 struct __port_info {
- __u64 designated_root;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 designated_root;
  __u64 designated_bridge;
  __u16 port_id;
  __u16 designated_port;
- __u32 path_cost;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 path_cost;
  __u32 designated_cost;
  __u8 state;
  __u8 top_change_ack;
- __u8 config_pending;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 config_pending;
  __u8 unused0;
  __u32 message_age_timer_value;
  __u32 forward_delay_timer_value;
- __u32 hold_timer_value;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 hold_timer_value;
 };
 struct __fdb_entry {
- __u8 mac_addr[6];
- __u8 port_no;
+ __u8 mac_addr[ETH_ALEN];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 port_no;
  __u8 is_local;
  __u32 ageing_timer_value;
  __u8 port_hi;
- __u8 pad0;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 pad0;
  __u16 unused;
 };
 #define BRIDGE_FLAGS_MASTER 1
-#define BRIDGE_FLAGS_SELF 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BRIDGE_FLAGS_SELF 2
 #define BRIDGE_MODE_VEB 0
 #define BRIDGE_MODE_VEPA 1
 enum {
- IFLA_BRIDGE_FLAGS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BRIDGE_FLAGS,
  IFLA_BRIDGE_MODE,
  IFLA_BRIDGE_VLAN_INFO,
  __IFLA_BRIDGE_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
 #define BRIDGE_VLAN_INFO_MASTER (1<<0)
 #define BRIDGE_VLAN_INFO_PVID (1<<1)
-#define BRIDGE_VLAN_INFO_UNTAGGED (1<<2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BRIDGE_VLAN_INFO_UNTAGGED (1<<2)
 struct bridge_vlan_info {
  __u16 flags;
  __u16 vid;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  MDBA_UNSPEC,
  MDBA_MDB,
- MDBA_ROUTER,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ MDBA_ROUTER,
  __MDBA_MAX,
 };
 #define MDBA_MAX (__MDBA_MAX - 1)
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  MDBA_MDB_UNSPEC,
  MDBA_MDB_ENTRY,
  __MDBA_MDB_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define MDBA_MDB_MAX (__MDBA_MDB_MAX - 1)
 enum {
  MDBA_MDB_ENTRY_UNSPEC,
- MDBA_MDB_ENTRY_INFO,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ MDBA_MDB_ENTRY_INFO,
  __MDBA_MDB_ENTRY_MAX,
 };
 #define MDBA_MDB_ENTRY_MAX (__MDBA_MDB_ENTRY_MAX - 1)
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  MDBA_ROUTER_UNSPEC,
  MDBA_ROUTER_PORT,
  __MDBA_ROUTER_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define MDBA_ROUTER_MAX (__MDBA_ROUTER_MAX - 1)
 struct br_port_msg {
  __u8 family;
- __u32 ifindex;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 ifindex;
 };
 struct br_mdb_entry {
  __u32 ifindex;
-#define MDB_TEMPORARY 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MDB_TEMPORARY 0
 #define MDB_PERMANENT 1
  __u8 state;
  struct {
- union {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union {
  __be32 ip4;
  struct in6_addr ip6;
  } u;
- __be16 proto;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 proto;
  } addr;
 };
 enum {
- MDBA_SET_ENTRY_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ MDBA_SET_ENTRY_UNSPEC,
  MDBA_SET_ENTRY,
  __MDBA_SET_ENTRY_MAX,
 };
-#define MDBA_SET_ENTRY_MAX (__MDBA_SET_ENTRY_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MDBA_SET_ENTRY_MAX (__MDBA_SET_ENTRY_MAX - 1)
 #endif
diff --git a/libc/kernel/uapi/linux/if_ether.h b/libc/kernel/uapi/linux/if_ether.h
index 14d679f..610f70b 100644
--- a/libc/kernel/uapi/linux/if_ether.h
+++ b/libc/kernel/uapi/linux/if_ether.h
@@ -81,51 +81,53 @@
 #define ETH_P_MVRP 0x88F5
 #define ETH_P_1588 0x88F7
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_PRP 0x88FB
 #define ETH_P_FCOE 0x8906
 #define ETH_P_TDLS 0x890D
 #define ETH_P_FIP 0x8914
-#define ETH_P_QINQ1 0x9100
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_QINQ1 0x9100
 #define ETH_P_QINQ2 0x9200
 #define ETH_P_QINQ3 0x9300
 #define ETH_P_EDSA 0xDADA
-#define ETH_P_AF_IUCV 0xFBFB
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_AF_IUCV 0xFBFB
 #define ETH_P_802_3_MIN 0x0600
 #define ETH_P_802_3 0x0001
 #define ETH_P_AX25 0x0002
-#define ETH_P_ALL 0x0003
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_ALL 0x0003
 #define ETH_P_802_2 0x0004
 #define ETH_P_SNAP 0x0005
 #define ETH_P_DDCMP 0x0006
-#define ETH_P_WAN_PPP 0x0007
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_WAN_PPP 0x0007
 #define ETH_P_PPP_MP 0x0008
 #define ETH_P_LOCALTALK 0x0009
 #define ETH_P_CAN 0x000C
-#define ETH_P_CANFD 0x000D
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_CANFD 0x000D
 #define ETH_P_PPPTALK 0x0010
 #define ETH_P_TR_802_2 0x0011
 #define ETH_P_MOBITEX 0x0015
-#define ETH_P_CONTROL 0x0016
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_CONTROL 0x0016
 #define ETH_P_IRDA 0x0017
 #define ETH_P_ECONET 0x0018
 #define ETH_P_HDLC 0x0019
-#define ETH_P_ARCNET 0x001A
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_ARCNET 0x001A
 #define ETH_P_DSA 0x001B
 #define ETH_P_TRAILER 0x001C
 #define ETH_P_PHONET 0x00F5
-#define ETH_P_IEEE802154 0x00F6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ETH_P_IEEE802154 0x00F6
 #define ETH_P_CAIF 0x00F7
 struct ethhdr {
  unsigned char h_dest[ETH_ALEN];
- unsigned char h_source[ETH_ALEN];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char h_source[ETH_ALEN];
  __be16 h_proto;
 } __attribute__((packed));
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/if_link.h b/libc/kernel/uapi/linux/if_link.h
index 4b4a844..aa53f0e 100644
--- a/libc/kernel/uapi/linux/if_link.h
+++ b/libc/kernel/uapi/linux/if_link.h
@@ -149,151 +149,221 @@
  IFLA_NUM_TX_QUEUES,
  IFLA_NUM_RX_QUEUES,
  IFLA_CARRIER,
- __IFLA_MAX
+ IFLA_PHYS_PORT_ID,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __IFLA_MAX
 };
 #define IFLA_MAX (__IFLA_MAX - 1)
 #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
-#define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
 enum {
  IFLA_INET_UNSPEC,
  IFLA_INET_CONF,
- __IFLA_INET_MAX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __IFLA_INET_MAX,
 };
 #define IFLA_INET_MAX (__IFLA_INET_MAX - 1)
 enum {
- IFLA_INET6_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_INET6_UNSPEC,
  IFLA_INET6_FLAGS,
  IFLA_INET6_CONF,
  IFLA_INET6_STATS,
- IFLA_INET6_MCAST,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_INET6_MCAST,
  IFLA_INET6_CACHEINFO,
  IFLA_INET6_ICMP6STATS,
  IFLA_INET6_TOKEN,
- __IFLA_INET6_MAX
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __IFLA_INET6_MAX
 };
 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
 enum {
- BRIDGE_MODE_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BRIDGE_MODE_UNSPEC,
  BRIDGE_MODE_HAIRPIN,
 };
 enum {
- IFLA_BRPORT_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BRPORT_UNSPEC,
  IFLA_BRPORT_STATE,
  IFLA_BRPORT_PRIORITY,
  IFLA_BRPORT_COST,
- IFLA_BRPORT_MODE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BRPORT_MODE,
  IFLA_BRPORT_GUARD,
  IFLA_BRPORT_PROTECT,
  IFLA_BRPORT_FAST_LEAVE,
- __IFLA_BRPORT_MAX
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BRPORT_LEARNING,
+ IFLA_BRPORT_UNICAST_FLOOD,
+ __IFLA_BRPORT_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
 struct ifla_cacheinfo {
  __u32 max_reasm_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tstamp;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reachable_time;
  __u32 retrans_time;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_INFO_UNSPEC,
  IFLA_INFO_KIND,
  IFLA_INFO_DATA,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_INFO_XSTATS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_INFO_SLAVE_KIND,
+ IFLA_INFO_SLAVE_DATA,
  __IFLA_INFO_MAX,
 };
-#define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1)
 enum {
  IFLA_VLAN_UNSPEC,
  IFLA_VLAN_ID,
- IFLA_VLAN_FLAGS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_VLAN_FLAGS,
  IFLA_VLAN_EGRESS_QOS,
  IFLA_VLAN_INGRESS_QOS,
  IFLA_VLAN_PROTOCOL,
- __IFLA_VLAN_MAX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __IFLA_VLAN_MAX,
 };
 #define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1)
 struct ifla_vlan_flags {
- __u32 flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 flags;
  __u32 mask;
 };
 enum {
- IFLA_VLAN_QOS_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_VLAN_QOS_UNSPEC,
  IFLA_VLAN_QOS_MAPPING,
  __IFLA_VLAN_QOS_MAX
 };
-#define IFLA_VLAN_QOS_MAX (__IFLA_VLAN_QOS_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFLA_VLAN_QOS_MAX (__IFLA_VLAN_QOS_MAX - 1)
 struct ifla_vlan_qos_mapping {
  __u32 from;
  __u32 to;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  IFLA_MACVLAN_UNSPEC,
  IFLA_MACVLAN_MODE,
- IFLA_MACVLAN_FLAGS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_MACVLAN_FLAGS,
  __IFLA_MACVLAN_MAX,
 };
 #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
-enum macvlan_mode {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum macvlan_mode {
  MACVLAN_MODE_PRIVATE = 1,
  MACVLAN_MODE_VEPA = 2,
  MACVLAN_MODE_BRIDGE = 4,
- MACVLAN_MODE_PASSTHRU = 8,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ MACVLAN_MODE_PASSTHRU = 8,
 };
 #define MACVLAN_FLAG_NOPROMISC 1
 enum {
- IFLA_VXLAN_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_VXLAN_UNSPEC,
  IFLA_VXLAN_ID,
  IFLA_VXLAN_GROUP,
  IFLA_VXLAN_LINK,
- IFLA_VXLAN_LOCAL,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_VXLAN_LOCAL,
  IFLA_VXLAN_TTL,
  IFLA_VXLAN_TOS,
  IFLA_VXLAN_LEARNING,
- IFLA_VXLAN_AGEING,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_VXLAN_AGEING,
  IFLA_VXLAN_LIMIT,
  IFLA_VXLAN_PORT_RANGE,
  IFLA_VXLAN_PROXY,
- IFLA_VXLAN_RSC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_VXLAN_RSC,
  IFLA_VXLAN_L2MISS,
  IFLA_VXLAN_L3MISS,
  IFLA_VXLAN_PORT,
- __IFLA_VXLAN_MAX
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_VXLAN_GROUP6,
+ IFLA_VXLAN_LOCAL6,
+ __IFLA_VXLAN_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
 struct ifla_vxlan_port_range {
  __be16 low;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __be16 high;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum {
+ IFLA_BOND_UNSPEC,
+ IFLA_BOND_MODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_ACTIVE_SLAVE,
+ IFLA_BOND_MIIMON,
+ IFLA_BOND_UPDELAY,
+ IFLA_BOND_DOWNDELAY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_USE_CARRIER,
+ IFLA_BOND_ARP_INTERVAL,
+ IFLA_BOND_ARP_IP_TARGET,
+ IFLA_BOND_ARP_VALIDATE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_ARP_ALL_TARGETS,
+ IFLA_BOND_PRIMARY,
+ IFLA_BOND_PRIMARY_RESELECT,
+ IFLA_BOND_FAIL_OVER_MAC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_XMIT_HASH_POLICY,
+ IFLA_BOND_RESEND_IGMP,
+ IFLA_BOND_NUM_PEER_NOTIF,
+ IFLA_BOND_ALL_SLAVES_ACTIVE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_MIN_LINKS,
+ IFLA_BOND_LP_INTERVAL,
+ IFLA_BOND_PACKETS_PER_SLAVE,
+ IFLA_BOND_AD_LACP_RATE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_AD_SELECT,
+ IFLA_BOND_AD_INFO,
+ __IFLA_BOND_MAX,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1)
+enum {
+ IFLA_BOND_AD_INFO_UNSPEC,
+ IFLA_BOND_AD_INFO_AGGREGATOR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_AD_INFO_NUM_PORTS,
+ IFLA_BOND_AD_INFO_ACTOR_KEY,
+ IFLA_BOND_AD_INFO_PARTNER_KEY,
+ IFLA_BOND_AD_INFO_PARTNER_MAC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __IFLA_BOND_AD_INFO_MAX,
+};
+#define IFLA_BOND_AD_INFO_MAX (__IFLA_BOND_AD_INFO_MAX - 1)
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_SLAVE_UNSPEC,
+ IFLA_BOND_SLAVE_STATE,
+ IFLA_BOND_SLAVE_MII_STATUS,
+ IFLA_BOND_SLAVE_LINK_FAILURE_COUNT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_BOND_SLAVE_PERM_HWADDR,
+ IFLA_BOND_SLAVE_QUEUE_ID,
+ IFLA_BOND_SLAVE_AD_AGGREGATOR_ID,
+ __IFLA_BOND_SLAVE_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define IFLA_BOND_SLAVE_MAX (__IFLA_BOND_SLAVE_MAX - 1)
+enum {
  IFLA_VF_INFO_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_VF_INFO,
@@ -308,104 +378,131 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_VF_TX_RATE,
  IFLA_VF_SPOOFCHK,
+ IFLA_VF_LINK_STATE,
  __IFLA_VF_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define IFLA_VF_MAX (__IFLA_VF_MAX - 1)
 struct ifla_vf_mac {
  __u32 vf;
- __u8 mac[32];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 mac[32];
 };
 struct ifla_vf_vlan {
  __u32 vf;
- __u32 vlan;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 vlan;
  __u32 qos;
 };
 struct ifla_vf_tx_rate {
- __u32 vf;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 vf;
  __u32 rate;
 };
 struct ifla_vf_spoofchk {
- __u32 vf;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 vf;
  __u32 setting;
 };
 enum {
- IFLA_VF_PORT_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_VF_LINK_STATE_AUTO,
+ IFLA_VF_LINK_STATE_ENABLE,
+ IFLA_VF_LINK_STATE_DISABLE,
+ __IFLA_VF_LINK_STATE_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct ifla_vf_link_state {
+ __u32 vf;
+ __u32 link_state;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum {
+ IFLA_VF_PORT_UNSPEC,
  IFLA_VF_PORT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __IFLA_VF_PORT_MAX,
 };
 #define IFLA_VF_PORT_MAX (__IFLA_VF_PORT_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_PORT_UNSPEC,
  IFLA_PORT_VF,
  IFLA_PORT_PROFILE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_PORT_VSI_TYPE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_PORT_INSTANCE_UUID,
  IFLA_PORT_HOST_UUID,
  IFLA_PORT_REQUEST,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_PORT_RESPONSE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __IFLA_PORT_MAX,
 };
 #define IFLA_PORT_MAX (__IFLA_PORT_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PORT_PROFILE_MAX 40
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PORT_UUID_MAX 16
 #define PORT_SELF_VF -1
 enum {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PORT_REQUEST_PREASSOCIATE = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PORT_REQUEST_PREASSOCIATE_RR,
  PORT_REQUEST_ASSOCIATE,
  PORT_REQUEST_DISASSOCIATE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  PORT_VDP_RESPONSE_SUCCESS = 0,
  PORT_VDP_RESPONSE_INVALID_FORMAT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PORT_VDP_RESPONSE_INSUFFICIENT_RESOURCES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PORT_VDP_RESPONSE_UNUSED_VTID,
  PORT_VDP_RESPONSE_VTID_VIOLATION,
  PORT_VDP_RESPONSE_VTID_VERSION_VIOALTION,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PORT_VDP_RESPONSE_OUT_OF_SYNC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PORT_PROFILE_RESPONSE_SUCCESS = 0x100,
  PORT_PROFILE_RESPONSE_INPROGRESS,
  PORT_PROFILE_RESPONSE_INVALID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PORT_PROFILE_RESPONSE_BADSTATE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES,
  PORT_PROFILE_RESPONSE_ERROR,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ifla_port_vsi {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 vsi_mgr_id;
  __u8 vsi_type_id[3];
  __u8 vsi_type_version;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 pad[3];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum {
  IFLA_IPOIB_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_IPOIB_PKEY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IFLA_IPOIB_MODE,
  IFLA_IPOIB_UMCAST,
  __IFLA_IPOIB_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  IPOIB_MODE_DATAGRAM = 0,
  IPOIB_MODE_CONNECTED = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFLA_IPOIB_MAX (__IFLA_IPOIB_MAX - 1)
+enum {
+ IFLA_HSR_UNSPEC,
+ IFLA_HSR_SLAVE1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IFLA_HSR_SLAVE2,
+ IFLA_HSR_MULTICAST_SPEC,
+ IFLA_HSR_SUPERVISION_ADDR,
+ IFLA_HSR_SEQ_NR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __IFLA_HSR_MAX,
+};
+#define IFLA_HSR_MAX (__IFLA_HSR_MAX - 1)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/if_packet.h b/libc/kernel/uapi/linux/if_packet.h
index ae5b392..133c77b 100644
--- a/libc/kernel/uapi/linux/if_packet.h
+++ b/libc/kernel/uapi/linux/if_packet.h
@@ -44,206 +44,218 @@
 #define PACKET_OTHERHOST 3
 #define PACKET_OUTGOING 4
 #define PACKET_LOOPBACK 5
-#define PACKET_FASTROUTE 6
+#define PACKET_USER 6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PACKET_KERNEL 7
+#define PACKET_FASTROUTE 6
 #define PACKET_ADD_MEMBERSHIP 1
 #define PACKET_DROP_MEMBERSHIP 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_RECV_OUTPUT 3
 #define PACKET_RX_RING 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_STATISTICS 6
 #define PACKET_COPY_THRESH 7
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_AUXDATA 8
 #define PACKET_ORIGDEV 9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_VERSION 10
 #define PACKET_HDRLEN 11
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_RESERVE 12
 #define PACKET_TX_RING 13
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_LOSS 14
 #define PACKET_VNET_HDR 15
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_TX_TIMESTAMP 16
 #define PACKET_TIMESTAMP 17
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_FANOUT 18
 #define PACKET_TX_HAS_OFF 19
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PACKET_QDISC_BYPASS 20
 #define PACKET_FANOUT_HASH 0
 #define PACKET_FANOUT_LB 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_FANOUT_CPU 2
-#define PACKET_FANOUT_ROLLOVER 3
-#define PACKET_FANOUT_FLAG_ROLLOVER 0x1000
-#define PACKET_FANOUT_FLAG_DEFRAG 0x8000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PACKET_FANOUT_ROLLOVER 3
+#define PACKET_FANOUT_RND 4
+#define PACKET_FANOUT_QM 5
+#define PACKET_FANOUT_FLAG_ROLLOVER 0x1000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PACKET_FANOUT_FLAG_DEFRAG 0x8000
 struct tpacket_stats {
  unsigned int tp_packets;
  unsigned int tp_drops;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct tpacket_stats_v3 {
  unsigned int tp_packets;
  unsigned int tp_drops;
- unsigned int tp_freeze_q_cnt;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int tp_freeze_q_cnt;
 };
 union tpacket_stats_u {
  struct tpacket_stats stats1;
- struct tpacket_stats_v3 stats3;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct tpacket_stats_v3 stats3;
 };
 struct tpacket_auxdata {
  __u32 tp_status;
- __u32 tp_len;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tp_len;
  __u32 tp_snaplen;
  __u16 tp_mac;
  __u16 tp_net;
- __u16 tp_vlan_tci;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u16 tp_padding;
+ __u16 tp_vlan_tci;
+ __u16 tp_vlan_tpid;
 };
 #define TP_STATUS_KERNEL 0
-#define TP_STATUS_USER (1 << 0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TP_STATUS_USER (1 << 0)
 #define TP_STATUS_COPY (1 << 1)
 #define TP_STATUS_LOSING (1 << 2)
 #define TP_STATUS_CSUMNOTREADY (1 << 3)
-#define TP_STATUS_VLAN_VALID (1 << 4)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TP_STATUS_VLAN_VALID (1 << 4)
 #define TP_STATUS_BLK_TMO (1 << 5)
+#define TP_STATUS_VLAN_TPID_VALID (1 << 6)
 #define TP_STATUS_AVAILABLE 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TP_STATUS_SEND_REQUEST (1 << 0)
 #define TP_STATUS_SENDING (1 << 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TP_STATUS_WRONG_FORMAT (1 << 2)
 #define TP_STATUS_TS_SOFTWARE (1 << 29)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TP_STATUS_TS_SYS_HARDWARE (1 << 30)
 #define TP_STATUS_TS_RAW_HARDWARE (1 << 31)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TP_FT_REQ_FILL_RXHASH 0x1
 struct tpacket_hdr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned long tp_status;
  unsigned int tp_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tp_snaplen;
  unsigned short tp_mac;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned short tp_net;
  unsigned int tp_sec;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tp_usec;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TPACKET_ALIGNMENT 16
 #define TPACKET_ALIGN(x) (((x)+TPACKET_ALIGNMENT-1)&~(TPACKET_ALIGNMENT-1))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TPACKET_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket_hdr)) + sizeof(struct sockaddr_ll))
 struct tpacket2_hdr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tp_status;
  __u32 tp_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tp_snaplen;
  __u16 tp_mac;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 tp_net;
  __u32 tp_sec;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tp_nsec;
  __u16 tp_vlan_tci;
- __u16 tp_padding;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 tp_vlan_tpid;
+ __u8 tp_padding[4];
+};
 struct tpacket_hdr_variant1 {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tp_rxhash;
  __u32 tp_vlan_tci;
-};
+ __u16 tp_vlan_tpid;
+ __u16 tp_padding;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct tpacket3_hdr {
  __u32 tp_next_offset;
  __u32 tp_sec;
- __u32 tp_nsec;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tp_nsec;
  __u32 tp_snaplen;
  __u32 tp_len;
  __u32 tp_status;
- __u16 tp_mac;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 tp_mac;
  __u16 tp_net;
  union {
  struct tpacket_hdr_variant1 hv1;
- };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ };
+ __u8 tp_padding[8];
 };
 struct tpacket_bd_ts {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int ts_sec;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int ts_usec;
  unsigned int ts_nsec;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tpacket_hdr_v1 {
  __u32 block_status;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 num_pkts;
  __u32 offset_to_first_pkt;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 blk_len;
  __aligned_u64 seq_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct tpacket_bd_ts ts_first_pkt, ts_last_pkt;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 union tpacket_bd_header_u {
  struct tpacket_hdr_v1 bh1;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tpacket_block_desc {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 version;
  __u32 offset_to_priv;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union tpacket_bd_header_u hdr;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TPACKET2_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket2_hdr)) + sizeof(struct sockaddr_ll))
 #define TPACKET3_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket3_hdr)) + sizeof(struct sockaddr_ll))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum tpacket_versions {
  TPACKET_V1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TPACKET_V2,
  TPACKET_V3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tpacket_req {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tp_block_size;
  unsigned int tp_block_nr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tp_frame_size;
  unsigned int tp_frame_nr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tpacket_req3 {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tp_block_size;
  unsigned int tp_block_nr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tp_frame_size;
  unsigned int tp_frame_nr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tp_retire_blk_tov;
  unsigned int tp_sizeof_priv;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tp_feature_req_word;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 union tpacket_req_u {
  struct tpacket_req req;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct tpacket_req3 req3;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct packet_mreq {
  int mr_ifindex;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned short mr_type;
  unsigned short mr_alen;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char mr_address[8];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_MR_MULTICAST 0
 #define PACKET_MR_PROMISC 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PACKET_MR_ALLMULTI 2
 #define PACKET_MR_UNICAST 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/if_pppox.h b/libc/kernel/uapi/linux/if_pppox.h
index 3ecaf12..3bc2ddb 100644
--- a/libc/kernel/uapi/linux/if_pppox.h
+++ b/libc/kernel/uapi/linux/if_pppox.h
@@ -24,34 +24,29 @@
 #include <linux/socket.h>
 #include <linux/if_ether.h>
 #include <linux/if_pppol2tp.h>
-#include <linux/if_pppolac.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#include <linux/if_pppopns.h>
 #ifndef AF_PPPOX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AF_PPPOX 24
 #define PF_PPPOX AF_PPPOX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 typedef __be16 sid_t;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct pppoe_addr {
  sid_t sid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char remote[ETH_ALEN];
  char dev[IFNAMSIZ];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct pptp_addr {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __be16 call_id;
+ __u16 call_id;
  struct in_addr sin_addr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define PX_PROTO_OE 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PX_PROTO_OL2TP 1
 #define PX_PROTO_PPTP 2
-#define PX_PROTO_OLAC 3
-#define PX_PROTO_OPNS 4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PX_MAX_PROTO 5
+#define PX_MAX_PROTO 3
 struct sockaddr_pppox {
  __kernel_sa_family_t sa_family;
  unsigned int sa_protocol;
@@ -117,12 +112,12 @@
 struct pppoe_hdr {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __LITTLE_ENDIAN_BITFIELD
- __u8 ver : 4;
  __u8 type : 4;
+ __u8 ver : 4;
 #elif defined(__BIG_ENDIAN_BITFIELD)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u8 type : 4;
  __u8 ver : 4;
+ __u8 type : 4;
 #else
 #error "Please fix <asm/byteorder.h>"
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/if_tun.h b/libc/kernel/uapi/linux/if_tun.h
index edcf7e4..f8f80b9 100644
--- a/libc/kernel/uapi/linux/if_tun.h
+++ b/libc/kernel/uapi/linux/if_tun.h
@@ -58,36 +58,42 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TUNSETVNETHDRSZ _IOW('T', 216, int)
 #define TUNSETQUEUE _IOW('T', 217, int)
+#define TUNSETIFINDEX _IOW('T', 218, unsigned int)
+#define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFF_TUN 0x0001
 #define IFF_TAP 0x0002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFF_NO_PI 0x1000
 #define IFF_ONE_QUEUE 0x2000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFF_VNET_HDR 0x4000
 #define IFF_TUN_EXCL 0x8000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFF_MULTI_QUEUE 0x0100
 #define IFF_ATTACH_QUEUE 0x0200
-#define IFF_DETACH_QUEUE 0x0400
-#define TUN_F_CSUM 0x01
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFF_DETACH_QUEUE 0x0400
+#define IFF_PERSIST 0x0800
+#define IFF_NOFILTER 0x1000
+#define TUN_TX_TIMESTAMP 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TUN_F_CSUM 0x01
 #define TUN_F_TSO4 0x02
 #define TUN_F_TSO6 0x04
 #define TUN_F_TSO_ECN 0x08
-#define TUN_F_UFO 0x10
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TUN_F_UFO 0x10
 #define TUN_PKT_STRIP 0x0001
 struct tun_pi {
  __u16 flags;
- __be16 proto;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 proto;
 };
 #define TUN_FLT_ALLMULTI 0x0001
 struct tun_filter {
- __u16 flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 flags;
  __u16 count;
  __u8 addr[0][ETH_ALEN];
 };
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/in.h b/libc/kernel/uapi/linux/in.h
index 4504132..e90209b 100644
--- a/libc/kernel/uapi/linux/in.h
+++ b/libc/kernel/uapi/linux/in.h
@@ -23,72 +23,107 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  IPPROTO_IP = 0,
+#define IPPROTO_IP IPPROTO_IP
  IPPROTO_ICMP = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_ICMP IPPROTO_ICMP
  IPPROTO_IGMP = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_IGMP IPPROTO_IGMP
  IPPROTO_IPIP = 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_IPIP IPPROTO_IPIP
  IPPROTO_TCP = 6,
+#define IPPROTO_TCP IPPROTO_TCP
  IPPROTO_EGP = 8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_EGP IPPROTO_EGP
  IPPROTO_PUP = 12,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_PUP IPPROTO_PUP
  IPPROTO_UDP = 17,
- IPPROTO_IDP = 22,
- IPPROTO_DCCP = 33,
- IPPROTO_RSVP = 46,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- IPPROTO_GRE = 47,
+#define IPPROTO_UDP IPPROTO_UDP
+ IPPROTO_IDP = 22,
+#define IPPROTO_IDP IPPROTO_IDP
+ IPPROTO_TP = 29,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_TP IPPROTO_TP
+ IPPROTO_DCCP = 33,
+#define IPPROTO_DCCP IPPROTO_DCCP
  IPPROTO_IPV6 = 41,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_IPV6 IPPROTO_IPV6
+ IPPROTO_RSVP = 46,
+#define IPPROTO_RSVP IPPROTO_RSVP
+ IPPROTO_GRE = 47,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_GRE IPPROTO_GRE
  IPPROTO_ESP = 50,
+#define IPPROTO_ESP IPPROTO_ESP
  IPPROTO_AH = 51,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_AH IPPROTO_AH
+ IPPROTO_MTP = 92,
+#define IPPROTO_MTP IPPROTO_MTP
  IPPROTO_BEETPH = 94,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_BEETPH IPPROTO_BEETPH
+ IPPROTO_ENCAP = 98,
+#define IPPROTO_ENCAP IPPROTO_ENCAP
  IPPROTO_PIM = 103,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_PIM IPPROTO_PIM
  IPPROTO_COMP = 108,
+#define IPPROTO_COMP IPPROTO_COMP
  IPPROTO_SCTP = 132,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_SCTP IPPROTO_SCTP
  IPPROTO_UDPLITE = 136,
+#define IPPROTO_UDPLITE IPPROTO_UDPLITE
  IPPROTO_RAW = 255,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPPROTO_RAW IPPROTO_RAW
  IPPROTO_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct in_addr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __be32 s_addr;
 };
 #define IP_TOS 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_TTL 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_HDRINCL 3
 #define IP_OPTIONS 4
 #define IP_ROUTER_ALERT 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_RECVOPTS 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_RETOPTS 7
 #define IP_PKTINFO 8
 #define IP_PKTOPTIONS 9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_MTU_DISCOVER 10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_RECVERR 11
 #define IP_RECVTTL 12
 #define IP_RECVTOS 13
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_MTU 14
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_FREEBIND 15
 #define IP_IPSEC_POLICY 16
 #define IP_XFRM_POLICY 17
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_PASSSEC 18
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_TRANSPARENT 19
 #define IP_RECVRETOPTS IP_RETOPTS
 #define IP_ORIGDSTADDR 20
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_MINTTL 21
 #define IP_NODEFRAG 22
 #define IP_PMTUDISC_DONT 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_PMTUDISC_WANT 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_PMTUDISC_DO 2
 #define IP_PMTUDISC_PROBE 3
+#define IP_PMTUDISC_INTERFACE 4
 #define IP_MULTICAST_IF 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IP_MULTICAST_TTL 33
diff --git a/libc/kernel/uapi/linux/in6.h b/libc/kernel/uapi/linux/in6.h
index 0d00e2b..641a69b 100644
--- a/libc/kernel/uapi/linux/in6.h
+++ b/libc/kernel/uapi/linux/in6.h
@@ -19,19 +19,29 @@
 #ifndef _UAPI_LINUX_IN6_H
 #define _UAPI_LINUX_IN6_H
 #include <linux/types.h>
-struct in6_addr {
+#include <linux/libc-compat.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#if __UAPI_DEF_IN6_ADDR
+struct in6_addr {
  union {
  __u8 u6_addr8[16];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#if __UAPI_DEF_IN6_ADDR_ALT
  __be16 u6_addr16[8];
  __be32 u6_addr32[4];
+#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } in6_u;
 #define s6_addr in6_u.u6_addr8
+#if __UAPI_DEF_IN6_ADDR_ALT
 #define s6_addr16 in6_u.u6_addr16
-#define s6_addr32 in6_u.u6_addr32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define s6_addr32 in6_u.u6_addr32
+#endif
 };
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#if __UAPI_DEF_SOCKADDR_IN6
 struct sockaddr_in6 {
  unsigned short int sin6_family;
  __be16 sin6_port;
@@ -41,109 +51,119 @@
  __u32 sin6_scope_id;
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
+#if __UAPI_DEF_IPV6_MREQ
 struct ipv6_mreq {
  struct in6_addr ipv6mr_multiaddr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int ipv6mr_ifindex;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
 #define ipv6mr_acaddr ipv6mr_multiaddr
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct in6_flowlabel_req {
  struct in6_addr flr_dst;
  __be32 flr_label;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 flr_action;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 flr_share;
  __u16 flr_flags;
  __u16 flr_expires;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 flr_linger;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 __flr_pad;
 };
 #define IPV6_FL_A_GET 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_FL_A_PUT 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_FL_A_RENEW 2
 #define IPV6_FL_F_CREATE 1
 #define IPV6_FL_F_EXCL 2
+#define IPV6_FL_F_REFLECT 4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPV6_FL_F_REMOTE 8
 #define IPV6_FL_S_NONE 0
 #define IPV6_FL_S_EXCL 1
 #define IPV6_FL_S_PROCESS 2
-#define IPV6_FL_S_USER 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPV6_FL_S_USER 3
 #define IPV6_FL_S_ANY 255
 #define IPV6_FLOWINFO_FLOWLABEL 0x000fffff
 #define IPV6_FLOWINFO_PRIORITY 0x0ff00000
-#define IPV6_PRIORITY_UNCHARACTERIZED 0x0000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPV6_PRIORITY_UNCHARACTERIZED 0x0000
 #define IPV6_PRIORITY_FILLER 0x0100
 #define IPV6_PRIORITY_UNATTENDED 0x0200
 #define IPV6_PRIORITY_RESERVED1 0x0300
-#define IPV6_PRIORITY_BULK 0x0400
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPV6_PRIORITY_BULK 0x0400
 #define IPV6_PRIORITY_RESERVED2 0x0500
 #define IPV6_PRIORITY_INTERACTIVE 0x0600
 #define IPV6_PRIORITY_CONTROL 0x0700
-#define IPV6_PRIORITY_8 0x0800
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPV6_PRIORITY_8 0x0800
 #define IPV6_PRIORITY_9 0x0900
 #define IPV6_PRIORITY_10 0x0a00
 #define IPV6_PRIORITY_11 0x0b00
-#define IPV6_PRIORITY_12 0x0c00
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPV6_PRIORITY_12 0x0c00
 #define IPV6_PRIORITY_13 0x0d00
 #define IPV6_PRIORITY_14 0x0e00
 #define IPV6_PRIORITY_15 0x0f00
-#define IPPROTO_HOPOPTS 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#if __UAPI_DEF_IPPROTO_V6
+#define IPPROTO_HOPOPTS 0
 #define IPPROTO_ROUTING 43
 #define IPPROTO_FRAGMENT 44
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPPROTO_ICMPV6 58
 #define IPPROTO_NONE 59
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPPROTO_DSTOPTS 60
 #define IPPROTO_MH 135
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
 #define IPV6_TLV_PAD1 0
 #define IPV6_TLV_PADN 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_TLV_ROUTERALERT 5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_TLV_JUMBO 194
 #define IPV6_TLV_HAO 201
 #define IPV6_ADDRFORM 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_2292PKTINFO 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_2292HOPOPTS 3
 #define IPV6_2292DSTOPTS 4
 #define IPV6_2292RTHDR 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_2292PKTOPTIONS 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_CHECKSUM 7
 #define IPV6_2292HOPLIMIT 8
 #define IPV6_NEXTHOP 9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_AUTHHDR 10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_FLOWINFO 11
 #define IPV6_UNICAST_HOPS 16
 #define IPV6_MULTICAST_IF 17
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_MULTICAST_HOPS 18
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_MULTICAST_LOOP 19
 #define IPV6_ADD_MEMBERSHIP 20
 #define IPV6_DROP_MEMBERSHIP 21
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_ROUTER_ALERT 22
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_MTU_DISCOVER 23
 #define IPV6_MTU 24
 #define IPV6_RECVERR 25
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_V6ONLY 26
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_JOIN_ANYCAST 27
 #define IPV6_LEAVE_ANYCAST 28
 #define IPV6_PMTUDISC_DONT 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_PMTUDISC_WANT 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_PMTUDISC_DO 2
 #define IPV6_PMTUDISC_PROBE 3
+#define IPV6_PMTUDISC_INTERFACE 4
 #define IPV6_FLOWLABEL_MGR 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IPV6_FLOWINFO_SEND 33
diff --git a/libc/kernel/uapi/linux/input.h b/libc/kernel/uapi/linux/input.h
index c7cf932..b9d5b2a 100644
--- a/libc/kernel/uapi/linux/input.h
+++ b/libc/kernel/uapi/linux/input.h
@@ -89,15 +89,15 @@
 #define EVIOCRMFF _IOW('E', 0x81, int)
 #define EVIOCGEFFECTS _IOR('E', 0x84, int)
 #define EVIOCGRAB _IOW('E', 0x90, int)
-#define EVIOCGSUSPENDBLOCK _IOR('E', 0x91, int)
+#define EVIOCREVOKE _IOW('E', 0x91, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EVIOCSSUSPENDBLOCK _IOW('E', 0x91, int)
 #define EVIOCSCLOCKID _IOW('E', 0xa0, int)
 #define INPUT_PROP_POINTER 0x00
 #define INPUT_PROP_DIRECT 0x01
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define INPUT_PROP_BUTTONPAD 0x02
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define INPUT_PROP_SEMI_MT 0x03
+#define INPUT_PROP_TOPBUTTONPAD 0x04
 #define INPUT_PROP_MAX 0x1f
 #define INPUT_PROP_CNT (INPUT_PROP_MAX + 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -123,310 +123,315 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SYN_MT_REPORT 2
 #define SYN_DROPPED 3
+#define SYN_MAX 0xf
+#define SYN_CNT (SYN_MAX+1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_RESERVED 0
 #define KEY_ESC 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_1 2
 #define KEY_2 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_3 4
 #define KEY_4 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_5 6
 #define KEY_6 7
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_7 8
 #define KEY_8 9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_9 10
 #define KEY_0 11
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_MINUS 12
 #define KEY_EQUAL 13
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_BACKSPACE 14
 #define KEY_TAB 15
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_Q 16
 #define KEY_W 17
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_E 18
 #define KEY_R 19
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_T 20
 #define KEY_Y 21
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_U 22
 #define KEY_I 23
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_O 24
 #define KEY_P 25
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_LEFTBRACE 26
 #define KEY_RIGHTBRACE 27
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_ENTER 28
 #define KEY_LEFTCTRL 29
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_A 30
 #define KEY_S 31
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_D 32
 #define KEY_F 33
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_G 34
 #define KEY_H 35
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_J 36
 #define KEY_K 37
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_L 38
 #define KEY_SEMICOLON 39
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_APOSTROPHE 40
 #define KEY_GRAVE 41
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_LEFTSHIFT 42
 #define KEY_BACKSLASH 43
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_Z 44
 #define KEY_X 45
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_C 46
 #define KEY_V 47
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_B 48
 #define KEY_N 49
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_M 50
 #define KEY_COMMA 51
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_DOT 52
 #define KEY_SLASH 53
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_RIGHTSHIFT 54
 #define KEY_KPASTERISK 55
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_LEFTALT 56
 #define KEY_SPACE 57
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_CAPSLOCK 58
 #define KEY_F1 59
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F2 60
 #define KEY_F3 61
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F4 62
 #define KEY_F5 63
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F6 64
 #define KEY_F7 65
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F8 66
 #define KEY_F9 67
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F10 68
 #define KEY_NUMLOCK 69
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_SCROLLLOCK 70
 #define KEY_KP7 71
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KP8 72
 #define KEY_KP9 73
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KPMINUS 74
 #define KEY_KP4 75
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KP5 76
 #define KEY_KP6 77
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KPPLUS 78
 #define KEY_KP1 79
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KP2 80
 #define KEY_KP3 81
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KP0 82
 #define KEY_KPDOT 83
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_ZENKAKUHANKAKU 85
 #define KEY_102ND 86
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F11 87
 #define KEY_F12 88
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_RO 89
 #define KEY_KATAKANA 90
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_HIRAGANA 91
 #define KEY_HENKAN 92
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KATAKANAHIRAGANA 93
 #define KEY_MUHENKAN 94
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KPJPCOMMA 95
 #define KEY_KPENTER 96
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_RIGHTCTRL 97
 #define KEY_KPSLASH 98
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_SYSRQ 99
 #define KEY_RIGHTALT 100
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_LINEFEED 101
 #define KEY_HOME 102
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_UP 103
 #define KEY_PAGEUP 104
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_LEFT 105
 #define KEY_RIGHT 106
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_END 107
 #define KEY_DOWN 108
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PAGEDOWN 109
 #define KEY_INSERT 110
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_DELETE 111
 #define KEY_MACRO 112
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_MUTE 113
 #define KEY_VOLUMEDOWN 114
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_VOLUMEUP 115
 #define KEY_POWER 116
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KPEQUAL 117
 #define KEY_KPPLUSMINUS 118
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PAUSE 119
 #define KEY_SCALE 120
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KPCOMMA 121
 #define KEY_HANGEUL 122
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_HANGUEL KEY_HANGEUL
 #define KEY_HANJA 123
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_YEN 124
 #define KEY_LEFTMETA 125
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_RIGHTMETA 126
 #define KEY_COMPOSE 127
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_STOP 128
 #define KEY_AGAIN 129
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PROPS 130
 #define KEY_UNDO 131
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_FRONT 132
 #define KEY_COPY 133
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_OPEN 134
 #define KEY_PASTE 135
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_FIND 136
 #define KEY_CUT 137
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_HELP 138
 #define KEY_MENU 139
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_CALC 140
 #define KEY_SETUP 141
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_SLEEP 142
 #define KEY_WAKEUP 143
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_FILE 144
 #define KEY_SENDFILE 145
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_DELETEFILE 146
 #define KEY_XFER 147
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PROG1 148
 #define KEY_PROG2 149
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_WWW 150
 #define KEY_MSDOS 151
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_COFFEE 152
 #define KEY_SCREENLOCK KEY_COFFEE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_DIRECTION 153
 #define KEY_CYCLEWINDOWS 154
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_MAIL 155
 #define KEY_BOOKMARKS 156
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_COMPUTER 157
 #define KEY_BACK 158
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_FORWARD 159
 #define KEY_CLOSECD 160
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_EJECTCD 161
 #define KEY_EJECTCLOSECD 162
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_NEXTSONG 163
 #define KEY_PLAYPAUSE 164
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PREVIOUSSONG 165
 #define KEY_STOPCD 166
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_RECORD 167
 #define KEY_REWIND 168
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PHONE 169
 #define KEY_ISO 170
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_CONFIG 171
 #define KEY_HOMEPAGE 172
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_REFRESH 173
 #define KEY_EXIT 174
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_MOVE 175
 #define KEY_EDIT 176
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_SCROLLUP 177
 #define KEY_SCROLLDOWN 178
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KPLEFTPAREN 179
 #define KEY_KPRIGHTPAREN 180
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_NEW 181
 #define KEY_REDO 182
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F13 183
 #define KEY_F14 184
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F15 185
 #define KEY_F16 186
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F17 187
 #define KEY_F18 188
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F19 189
 #define KEY_F20 190
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F21 191
 #define KEY_F22 192
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_F23 193
 #define KEY_F24 194
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PLAYCD 200
 #define KEY_PAUSECD 201
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PROG3 202
 #define KEY_PROG4 203
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_DASHBOARD 204
 #define KEY_SUSPEND 205
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_CLOSE 206
 #define KEY_PLAY 207
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_FASTFORWARD 208
 #define KEY_BASSBOOST 209
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_PRINT 210
 #define KEY_HP 211
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_CAMERA 212
 #define KEY_SOUND 213
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_QUESTION 214
 #define KEY_EMAIL 215
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_CHAT 216
 #define KEY_SEARCH 217
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_CONNECT 218
 #define KEY_FINANCE 219
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_SPORT 220
 #define KEY_SHOP 221
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_ALTERASE 222
 #define KEY_CANCEL 223
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_BRIGHTNESSDOWN 224
 #define KEY_BRIGHTNESSUP 225
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_MEDIA 226
 #define KEY_SWITCHVIDEOMODE 227
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KBDILLUMTOGGLE 228
 #define KEY_KBDILLUMDOWN 229
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_KBDILLUMUP 230
 #define KEY_SEND 231
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_REPLY 232
 #define KEY_FORWARDMAIL 233
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_SAVE 234
 #define KEY_DOCUMENTS 235
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_BATTERY 236
 #define KEY_BLUETOOTH 237
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_WLAN 238
 #define KEY_UWB 239
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_UNKNOWN 240
 #define KEY_VIDEO_NEXT 241
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_VIDEO_PREV 242
 #define KEY_BRIGHTNESS_CYCLE 243
-#define KEY_BRIGHTNESS_ZERO 244
-#define KEY_DISPLAY_OFF 245
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define KEY_WIMAX 246
+#define KEY_BRIGHTNESS_AUTO 244
+#define KEY_BRIGHTNESS_ZERO KEY_BRIGHTNESS_AUTO
+#define KEY_DISPLAY_OFF 245
+#define KEY_WWAN 246
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_WIMAX KEY_WWAN
 #define KEY_RFKILL 247
 #define KEY_MICMUTE 248
 #define BTN_MISC 0x100
@@ -473,12 +478,17 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_DEAD 0x12f
 #define BTN_GAMEPAD 0x130
-#define BTN_A 0x130
-#define BTN_B 0x131
+#define BTN_SOUTH 0x130
+#define BTN_A BTN_SOUTH
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTN_EAST 0x131
+#define BTN_B BTN_EAST
 #define BTN_C 0x132
-#define BTN_X 0x133
-#define BTN_Y 0x134
+#define BTN_NORTH 0x133
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTN_X BTN_NORTH
+#define BTN_WEST 0x134
+#define BTN_Y BTN_WEST
 #define BTN_Z 0x135
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TL 0x136
@@ -616,239 +626,259 @@
 #define KEY_MESSENGER 0x1ae
 #define KEY_DISPLAYTOGGLE 0x1af
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_BRIGHTNESS_TOGGLE KEY_DISPLAYTOGGLE
 #define KEY_SPELLCHECK 0x1b0
 #define KEY_LOGOFF 0x1b1
 #define KEY_DOLLAR 0x1b2
-#define KEY_EURO 0x1b3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_EURO 0x1b3
 #define KEY_FRAMEBACK 0x1b4
 #define KEY_FRAMEFORWARD 0x1b5
 #define KEY_CONTEXT_MENU 0x1b6
-#define KEY_MEDIA_REPEAT 0x1b7
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_MEDIA_REPEAT 0x1b7
 #define KEY_10CHANNELSUP 0x1b8
 #define KEY_10CHANNELSDOWN 0x1b9
 #define KEY_IMAGES 0x1ba
-#define KEY_DEL_EOL 0x1c0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_DEL_EOL 0x1c0
 #define KEY_DEL_EOS 0x1c1
 #define KEY_INS_LINE 0x1c2
 #define KEY_DEL_LINE 0x1c3
-#define KEY_FN 0x1d0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_FN 0x1d0
 #define KEY_FN_ESC 0x1d1
 #define KEY_FN_F1 0x1d2
 #define KEY_FN_F2 0x1d3
-#define KEY_FN_F3 0x1d4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_FN_F3 0x1d4
 #define KEY_FN_F4 0x1d5
 #define KEY_FN_F5 0x1d6
 #define KEY_FN_F6 0x1d7
-#define KEY_FN_F7 0x1d8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_FN_F7 0x1d8
 #define KEY_FN_F8 0x1d9
 #define KEY_FN_F9 0x1da
 #define KEY_FN_F10 0x1db
-#define KEY_FN_F11 0x1dc
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_FN_F11 0x1dc
 #define KEY_FN_F12 0x1dd
 #define KEY_FN_1 0x1de
 #define KEY_FN_2 0x1df
-#define KEY_FN_D 0x1e0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_FN_D 0x1e0
 #define KEY_FN_E 0x1e1
 #define KEY_FN_F 0x1e2
 #define KEY_FN_S 0x1e3
-#define KEY_FN_B 0x1e4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_FN_B 0x1e4
 #define KEY_BRL_DOT1 0x1f1
 #define KEY_BRL_DOT2 0x1f2
 #define KEY_BRL_DOT3 0x1f3
-#define KEY_BRL_DOT4 0x1f4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_BRL_DOT4 0x1f4
 #define KEY_BRL_DOT5 0x1f5
 #define KEY_BRL_DOT6 0x1f6
 #define KEY_BRL_DOT7 0x1f7
-#define KEY_BRL_DOT8 0x1f8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_BRL_DOT8 0x1f8
 #define KEY_BRL_DOT9 0x1f9
 #define KEY_BRL_DOT10 0x1fa
 #define KEY_NUMERIC_0 0x200
-#define KEY_NUMERIC_1 0x201
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_NUMERIC_1 0x201
 #define KEY_NUMERIC_2 0x202
 #define KEY_NUMERIC_3 0x203
 #define KEY_NUMERIC_4 0x204
-#define KEY_NUMERIC_5 0x205
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_NUMERIC_5 0x205
 #define KEY_NUMERIC_6 0x206
 #define KEY_NUMERIC_7 0x207
 #define KEY_NUMERIC_8 0x208
-#define KEY_NUMERIC_9 0x209
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_NUMERIC_9 0x209
 #define KEY_NUMERIC_STAR 0x20a
 #define KEY_NUMERIC_POUND 0x20b
 #define KEY_CAMERA_FOCUS 0x210
-#define KEY_WPS_BUTTON 0x211
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_WPS_BUTTON 0x211
 #define KEY_TOUCHPAD_TOGGLE 0x212
 #define KEY_TOUCHPAD_ON 0x213
 #define KEY_TOUCHPAD_OFF 0x214
-#define KEY_CAMERA_ZOOMIN 0x215
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_CAMERA_ZOOMIN 0x215
 #define KEY_CAMERA_ZOOMOUT 0x216
 #define KEY_CAMERA_UP 0x217
 #define KEY_CAMERA_DOWN 0x218
-#define KEY_CAMERA_LEFT 0x219
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_CAMERA_LEFT 0x219
 #define KEY_CAMERA_RIGHT 0x21a
 #define KEY_ATTENDANT_ON 0x21b
 #define KEY_ATTENDANT_OFF 0x21c
-#define KEY_ATTENDANT_TOGGLE 0x21d
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_ATTENDANT_TOGGLE 0x21d
 #define KEY_LIGHTS_TOGGLE 0x21e
+#define BTN_DPAD_UP 0x220
+#define BTN_DPAD_DOWN 0x221
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define BTN_DPAD_LEFT 0x222
+#define BTN_DPAD_RIGHT 0x223
+#define KEY_ALS_TOGGLE 0x230
+#define KEY_BUTTONCONFIG 0x240
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_TASKMANAGER 0x241
+#define KEY_JOURNAL 0x242
+#define KEY_CONTROLPANEL 0x243
+#define KEY_APPSELECT 0x244
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEY_SCREENSAVER 0x245
+#define KEY_VOICECOMMAND 0x246
+#define KEY_BRIGHTNESS_MIN 0x250
+#define KEY_BRIGHTNESS_MAX 0x251
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY 0x2c0
 #define BTN_TRIGGER_HAPPY1 0x2c0
 #define BTN_TRIGGER_HAPPY2 0x2c1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY3 0x2c2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY4 0x2c3
 #define BTN_TRIGGER_HAPPY5 0x2c4
 #define BTN_TRIGGER_HAPPY6 0x2c5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY7 0x2c6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY8 0x2c7
 #define BTN_TRIGGER_HAPPY9 0x2c8
 #define BTN_TRIGGER_HAPPY10 0x2c9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY11 0x2ca
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY12 0x2cb
 #define BTN_TRIGGER_HAPPY13 0x2cc
 #define BTN_TRIGGER_HAPPY14 0x2cd
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY15 0x2ce
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY16 0x2cf
 #define BTN_TRIGGER_HAPPY17 0x2d0
 #define BTN_TRIGGER_HAPPY18 0x2d1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY19 0x2d2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY20 0x2d3
 #define BTN_TRIGGER_HAPPY21 0x2d4
 #define BTN_TRIGGER_HAPPY22 0x2d5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY23 0x2d6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY24 0x2d7
 #define BTN_TRIGGER_HAPPY25 0x2d8
 #define BTN_TRIGGER_HAPPY26 0x2d9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY27 0x2da
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY28 0x2db
 #define BTN_TRIGGER_HAPPY29 0x2dc
 #define BTN_TRIGGER_HAPPY30 0x2dd
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY31 0x2de
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY32 0x2df
 #define BTN_TRIGGER_HAPPY33 0x2e0
 #define BTN_TRIGGER_HAPPY34 0x2e1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY35 0x2e2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY36 0x2e3
 #define BTN_TRIGGER_HAPPY37 0x2e4
 #define BTN_TRIGGER_HAPPY38 0x2e5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY39 0x2e6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define BTN_TRIGGER_HAPPY40 0x2e7
 #define KEY_MIN_INTERESTING KEY_MUTE
 #define KEY_MAX 0x2ff
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEY_CNT (KEY_MAX+1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define REL_X 0x00
 #define REL_Y 0x01
 #define REL_Z 0x02
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define REL_RX 0x03
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define REL_RY 0x04
 #define REL_RZ 0x05
 #define REL_HWHEEL 0x06
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define REL_DIAL 0x07
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define REL_WHEEL 0x08
 #define REL_MISC 0x09
 #define REL_MAX 0x0f
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define REL_CNT (REL_MAX+1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_X 0x00
 #define ABS_Y 0x01
 #define ABS_Z 0x02
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_RX 0x03
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_RY 0x04
 #define ABS_RZ 0x05
 #define ABS_THROTTLE 0x06
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_RUDDER 0x07
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_WHEEL 0x08
 #define ABS_GAS 0x09
 #define ABS_BRAKE 0x0a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_HAT0X 0x10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_HAT0Y 0x11
 #define ABS_HAT1X 0x12
 #define ABS_HAT1Y 0x13
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_HAT2X 0x14
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_HAT2Y 0x15
 #define ABS_HAT3X 0x16
 #define ABS_HAT3Y 0x17
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_PRESSURE 0x18
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_DISTANCE 0x19
 #define ABS_TILT_X 0x1a
 #define ABS_TILT_Y 0x1b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_TOOL_WIDTH 0x1c
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_VOLUME 0x20
 #define ABS_MISC 0x28
 #define ABS_MT_SLOT 0x2f
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_MT_TOUCH_MAJOR 0x30
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_MT_TOUCH_MINOR 0x31
 #define ABS_MT_WIDTH_MAJOR 0x32
 #define ABS_MT_WIDTH_MINOR 0x33
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_MT_ORIENTATION 0x34
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_MT_POSITION_X 0x35
 #define ABS_MT_POSITION_Y 0x36
 #define ABS_MT_TOOL_TYPE 0x37
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_MT_BLOB_ID 0x38
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_MT_TRACKING_ID 0x39
 #define ABS_MT_PRESSURE 0x3a
 #define ABS_MT_DISTANCE 0x3b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_MT_TOOL_X 0x3c
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ABS_MT_TOOL_Y 0x3d
 #define ABS_MAX 0x3f
 #define ABS_CNT (ABS_MAX+1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_LID 0x00
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_TABLET_MODE 0x01
 #define SW_HEADPHONE_INSERT 0x02
 #define SW_RFKILL_ALL 0x03
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_RADIO SW_RFKILL_ALL
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_MICROPHONE_INSERT 0x04
 #define SW_DOCK 0x05
 #define SW_LINEOUT_INSERT 0x06
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_JACK_PHYSICAL_INSERT 0x07
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_VIDEOOUT_INSERT 0x08
 #define SW_CAMERA_LENS_COVER 0x09
 #define SW_KEYPAD_SLIDE 0x0a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_FRONT_PROXIMITY 0x0b
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_ROTATE_LOCK 0x0c
 #define SW_LINEIN_INSERT 0x0d
+#define SW_MUTE_DEVICE 0x0e
 #define SW_MAX 0x0f
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SW_CNT (SW_MAX+1)
diff --git a/libc/kernel/uapi/linux/ion.h b/libc/kernel/uapi/linux/ion.h
index f18939d..5af39d0 100644
--- a/libc/kernel/uapi/linux/ion.h
+++ b/libc/kernel/uapi/linux/ion.h
@@ -16,56 +16,63 @@
  ***
  ****************************************************************************
  ****************************************************************************/
-#ifndef _LINUX_ION_H
-#define _LINUX_ION_H
+#ifndef _UAPI_LINUX_ION_H
+#define _UAPI_LINUX_ION_H
+#include <linux/ioctl.h>
 #include <linux/types.h>
-struct ion_handle;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef int ion_user_handle_t;
 enum ion_heap_type {
  ION_HEAP_TYPE_SYSTEM,
  ION_HEAP_TYPE_SYSTEM_CONTIG,
- ION_HEAP_TYPE_CARVEOUT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ ION_HEAP_TYPE_CARVEOUT,
+ ION_HEAP_TYPE_CHUNK,
+ ION_HEAP_TYPE_DMA,
  ION_HEAP_TYPE_CUSTOM,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ION_NUM_HEAPS = 16,
 };
 #define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG)
-#define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT)
-#define ION_FLAG_CACHED 1
-#define ION_FLAG_CACHED_NEEDS_SYNC 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT)
+#define ION_HEAP_TYPE_DMA_MASK (1 << ION_HEAP_TYPE_DMA)
+#define ION_NUM_HEAP_IDS sizeof(unsigned int) * 8
+#define ION_FLAG_CACHED 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ION_FLAG_CACHED_NEEDS_SYNC 2
 struct ion_allocation_data {
  size_t len;
  size_t align;
- unsigned int heap_mask;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int heap_id_mask;
  unsigned int flags;
- struct ion_handle *handle;
+ ion_user_handle_t handle;
 };
-struct ion_fd_data {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- struct ion_handle *handle;
+struct ion_fd_data {
+ ion_user_handle_t handle;
  int fd;
 };
-struct ion_handle_data {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- struct ion_handle *handle;
+struct ion_handle_data {
+ ion_user_handle_t handle;
 };
 struct ion_custom_data {
- unsigned int cmd;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int cmd;
  unsigned long arg;
 };
 #define ION_IOC_MAGIC 'I'
-#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0,   struct ion_allocation_data)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0,   struct ion_allocation_data)
 #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
 #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
 #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
-#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
 #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data)
 #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/ip.h b/libc/kernel/uapi/linux/ip.h
index e936331..fc0bd78 100644
--- a/libc/kernel/uapi/linux/ip.h
+++ b/libc/kernel/uapi/linux/ip.h
@@ -139,5 +139,46 @@
  __u8 padlen;
  __u8 reserved;
 };
-#endif
+enum
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+{
+ IPV4_DEVCONF_FORWARDING=1,
+ IPV4_DEVCONF_MC_FORWARDING,
+ IPV4_DEVCONF_PROXY_ARP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPV4_DEVCONF_ACCEPT_REDIRECTS,
+ IPV4_DEVCONF_SECURE_REDIRECTS,
+ IPV4_DEVCONF_SEND_REDIRECTS,
+ IPV4_DEVCONF_SHARED_MEDIA,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPV4_DEVCONF_RP_FILTER,
+ IPV4_DEVCONF_ACCEPT_SOURCE_ROUTE,
+ IPV4_DEVCONF_BOOTP_RELAY,
+ IPV4_DEVCONF_LOG_MARTIANS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPV4_DEVCONF_TAG,
+ IPV4_DEVCONF_ARPFILTER,
+ IPV4_DEVCONF_MEDIUM_ID,
+ IPV4_DEVCONF_NOXFRM,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPV4_DEVCONF_NOPOLICY,
+ IPV4_DEVCONF_FORCE_IGMP_VERSION,
+ IPV4_DEVCONF_ARP_ANNOUNCE,
+ IPV4_DEVCONF_ARP_IGNORE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPV4_DEVCONF_PROMOTE_SECONDARIES,
+ IPV4_DEVCONF_ARP_ACCEPT,
+ IPV4_DEVCONF_ARP_NOTIFY,
+ IPV4_DEVCONF_ACCEPT_LOCAL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPV4_DEVCONF_SRC_VMARK,
+ IPV4_DEVCONF_PROXY_ARP_PVLAN,
+ IPV4_DEVCONF_ROUTE_LOCALNET,
+ IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL,
+ __IPV4_DEVCONF_MAX
+};
+#define IPV4_DEVCONF_MAX (__IPV4_DEVCONF_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/ip_vs.h b/libc/kernel/uapi/linux/ip_vs.h
index 241057a..3aa0f84 100644
--- a/libc/kernel/uapi/linux/ip_vs.h
+++ b/libc/kernel/uapi/linux/ip_vs.h
@@ -26,300 +26,306 @@
 #define IP_VS_SVC_F_HASHED 0x0002
 #define IP_VS_SVC_F_ONEPACKET 0x0004
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SVC_F_SCHED1 0x0008
+#define IP_VS_SVC_F_SCHED2 0x0010
+#define IP_VS_SVC_F_SCHED3 0x0020
+#define IP_VS_SVC_F_SCHED_SH_FALLBACK IP_VS_SVC_F_SCHED1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SVC_F_SCHED_SH_PORT IP_VS_SVC_F_SCHED2
 #define IP_VS_DEST_F_AVAILABLE 0x0001
 #define IP_VS_DEST_F_OVERLOAD 0x0002
 #define IP_VS_STATE_NONE 0x0000
-#define IP_VS_STATE_MASTER 0x0001
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_STATE_MASTER 0x0001
 #define IP_VS_STATE_BACKUP 0x0002
 #define IP_VS_BASE_CTL (64+1024+64)
 #define IP_VS_SO_SET_NONE IP_VS_BASE_CTL
-#define IP_VS_SO_SET_INSERT (IP_VS_BASE_CTL+1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SO_SET_INSERT (IP_VS_BASE_CTL+1)
 #define IP_VS_SO_SET_ADD (IP_VS_BASE_CTL+2)
 #define IP_VS_SO_SET_EDIT (IP_VS_BASE_CTL+3)
 #define IP_VS_SO_SET_DEL (IP_VS_BASE_CTL+4)
-#define IP_VS_SO_SET_FLUSH (IP_VS_BASE_CTL+5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SO_SET_FLUSH (IP_VS_BASE_CTL+5)
 #define IP_VS_SO_SET_LIST (IP_VS_BASE_CTL+6)
 #define IP_VS_SO_SET_ADDDEST (IP_VS_BASE_CTL+7)
 #define IP_VS_SO_SET_DELDEST (IP_VS_BASE_CTL+8)
-#define IP_VS_SO_SET_EDITDEST (IP_VS_BASE_CTL+9)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SO_SET_EDITDEST (IP_VS_BASE_CTL+9)
 #define IP_VS_SO_SET_TIMEOUT (IP_VS_BASE_CTL+10)
 #define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL+11)
 #define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL+12)
-#define IP_VS_SO_SET_RESTORE (IP_VS_BASE_CTL+13)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SO_SET_RESTORE (IP_VS_BASE_CTL+13)
 #define IP_VS_SO_SET_SAVE (IP_VS_BASE_CTL+14)
 #define IP_VS_SO_SET_ZERO (IP_VS_BASE_CTL+15)
 #define IP_VS_SO_SET_MAX IP_VS_SO_SET_ZERO
-#define IP_VS_SO_GET_VERSION IP_VS_BASE_CTL
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SO_GET_VERSION IP_VS_BASE_CTL
 #define IP_VS_SO_GET_INFO (IP_VS_BASE_CTL+1)
 #define IP_VS_SO_GET_SERVICES (IP_VS_BASE_CTL+2)
 #define IP_VS_SO_GET_SERVICE (IP_VS_BASE_CTL+3)
-#define IP_VS_SO_GET_DESTS (IP_VS_BASE_CTL+4)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SO_GET_DESTS (IP_VS_BASE_CTL+4)
 #define IP_VS_SO_GET_DEST (IP_VS_BASE_CTL+5)
 #define IP_VS_SO_GET_TIMEOUT (IP_VS_BASE_CTL+6)
 #define IP_VS_SO_GET_DAEMON (IP_VS_BASE_CTL+7)
-#define IP_VS_SO_GET_MAX IP_VS_SO_GET_DAEMON
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_SO_GET_MAX IP_VS_SO_GET_DAEMON
 #define IP_VS_CONN_F_FWD_MASK 0x0007
 #define IP_VS_CONN_F_MASQ 0x0000
 #define IP_VS_CONN_F_LOCALNODE 0x0001
-#define IP_VS_CONN_F_TUNNEL 0x0002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_CONN_F_TUNNEL 0x0002
 #define IP_VS_CONN_F_DROUTE 0x0003
 #define IP_VS_CONN_F_BYPASS 0x0004
 #define IP_VS_CONN_F_SYNC 0x0020
-#define IP_VS_CONN_F_HASHED 0x0040
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_CONN_F_HASHED 0x0040
 #define IP_VS_CONN_F_NOOUTPUT 0x0080
 #define IP_VS_CONN_F_INACTIVE 0x0100
 #define IP_VS_CONN_F_OUT_SEQ 0x0200
-#define IP_VS_CONN_F_IN_SEQ 0x0400
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_CONN_F_IN_SEQ 0x0400
 #define IP_VS_CONN_F_SEQ_MASK 0x0600
 #define IP_VS_CONN_F_NO_CPORT 0x0800
 #define IP_VS_CONN_F_TEMPLATE 0x1000
-#define IP_VS_CONN_F_ONE_PACKET 0x2000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_CONN_F_ONE_PACKET 0x2000
 #define IP_VS_CONN_F_BACKUP_MASK (IP_VS_CONN_F_FWD_MASK |   IP_VS_CONN_F_NOOUTPUT |   IP_VS_CONN_F_INACTIVE |   IP_VS_CONN_F_SEQ_MASK |   IP_VS_CONN_F_NO_CPORT |   IP_VS_CONN_F_TEMPLATE   )
 #define IP_VS_CONN_F_BACKUP_UPD_MASK (IP_VS_CONN_F_INACTIVE |   IP_VS_CONN_F_SEQ_MASK)
 #define IP_VS_CONN_F_NFCT (1 << 16)
-#define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK |   IP_VS_CONN_F_ONE_PACKET |   IP_VS_CONN_F_NFCT |   0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK |   IP_VS_CONN_F_ONE_PACKET |   IP_VS_CONN_F_NFCT |   0)
 #define IP_VS_SCHEDNAME_MAXLEN 16
 #define IP_VS_PENAME_MAXLEN 16
 #define IP_VS_IFNAME_MAXLEN 16
-#define IP_VS_PEDATA_MAXLEN 255
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_VS_PEDATA_MAXLEN 255
 struct ip_vs_service_user {
  __u16 protocol;
  __be32 addr;
- __be16 port;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 port;
  __u32 fwmark;
  char sched_name[IP_VS_SCHEDNAME_MAXLEN];
  unsigned int flags;
- unsigned int timeout;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int timeout;
  __be32 netmask;
 };
 struct ip_vs_dest_user {
- __be32 addr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 addr;
  __be16 port;
  unsigned int conn_flags;
  int weight;
- __u32 u_threshold;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 u_threshold;
  __u32 l_threshold;
 };
 struct ip_vs_stats_user {
- __u32 conns;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 conns;
  __u32 inpkts;
  __u32 outpkts;
  __u64 inbytes;
- __u64 outbytes;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 outbytes;
  __u32 cps;
  __u32 inpps;
  __u32 outpps;
- __u32 inbps;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 inbps;
  __u32 outbps;
 };
 struct ip_vs_getinfo {
- unsigned int version;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int version;
  unsigned int size;
  unsigned int num_services;
 };
-struct ip_vs_service_entry {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ip_vs_service_entry {
  __u16 protocol;
  __be32 addr;
  __be16 port;
- __u32 fwmark;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 fwmark;
  char sched_name[IP_VS_SCHEDNAME_MAXLEN];
  unsigned int flags;
  unsigned int timeout;
- __be32 netmask;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 netmask;
  unsigned int num_dests;
  struct ip_vs_stats_user stats;
 };
-struct ip_vs_dest_entry {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ip_vs_dest_entry {
  __be32 addr;
  __be16 port;
  unsigned int conn_flags;
- int weight;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int weight;
  __u32 u_threshold;
  __u32 l_threshold;
  __u32 activeconns;
- __u32 inactconns;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 inactconns;
  __u32 persistconns;
  struct ip_vs_stats_user stats;
 };
-struct ip_vs_get_dests {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ip_vs_get_dests {
  __u16 protocol;
  __be32 addr;
  __be16 port;
- __u32 fwmark;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 fwmark;
  unsigned int num_dests;
  struct ip_vs_dest_entry entrytable[0];
 };
-struct ip_vs_get_services {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ip_vs_get_services {
  unsigned int num_services;
  struct ip_vs_service_entry entrytable[0];
 };
-struct ip_vs_timeout_user {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ip_vs_timeout_user {
  int tcp_timeout;
  int tcp_fin_timeout;
  int udp_timeout;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct ip_vs_daemon_user {
  int state;
  char mcast_ifn[IP_VS_IFNAME_MAXLEN];
- int syncid;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int syncid;
 };
 #define IPVS_GENL_NAME "IPVS"
 #define IPVS_GENL_VERSION 0x1
-struct ip_vs_flags {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ip_vs_flags {
  __u32 flags;
  __u32 mask;
 };
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  IPVS_CMD_UNSPEC = 0,
  IPVS_CMD_NEW_SERVICE,
  IPVS_CMD_SET_SERVICE,
- IPVS_CMD_DEL_SERVICE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_CMD_DEL_SERVICE,
  IPVS_CMD_GET_SERVICE,
  IPVS_CMD_NEW_DEST,
  IPVS_CMD_SET_DEST,
- IPVS_CMD_DEL_DEST,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_CMD_DEL_DEST,
  IPVS_CMD_GET_DEST,
  IPVS_CMD_NEW_DAEMON,
  IPVS_CMD_DEL_DAEMON,
- IPVS_CMD_GET_DAEMON,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_CMD_GET_DAEMON,
  IPVS_CMD_SET_CONFIG,
  IPVS_CMD_GET_CONFIG,
  IPVS_CMD_SET_INFO,
- IPVS_CMD_GET_INFO,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_CMD_GET_INFO,
  IPVS_CMD_ZERO,
  IPVS_CMD_FLUSH,
  __IPVS_CMD_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define IPVS_CMD_MAX (__IPVS_CMD_MAX - 1)
 enum {
  IPVS_CMD_ATTR_UNSPEC = 0,
- IPVS_CMD_ATTR_SERVICE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_CMD_ATTR_SERVICE,
  IPVS_CMD_ATTR_DEST,
  IPVS_CMD_ATTR_DAEMON,
  IPVS_CMD_ATTR_TIMEOUT_TCP,
- IPVS_CMD_ATTR_TIMEOUT_TCP_FIN,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_CMD_ATTR_TIMEOUT_TCP_FIN,
  IPVS_CMD_ATTR_TIMEOUT_UDP,
  __IPVS_CMD_ATTR_MAX,
 };
-#define IPVS_CMD_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPVS_CMD_ATTR_MAX (__IPVS_CMD_ATTR_MAX - 1)
 enum {
  IPVS_SVC_ATTR_UNSPEC = 0,
  IPVS_SVC_ATTR_AF,
- IPVS_SVC_ATTR_PROTOCOL,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_SVC_ATTR_PROTOCOL,
  IPVS_SVC_ATTR_ADDR,
  IPVS_SVC_ATTR_PORT,
  IPVS_SVC_ATTR_FWMARK,
- IPVS_SVC_ATTR_SCHED_NAME,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_SVC_ATTR_SCHED_NAME,
  IPVS_SVC_ATTR_FLAGS,
  IPVS_SVC_ATTR_TIMEOUT,
  IPVS_SVC_ATTR_NETMASK,
- IPVS_SVC_ATTR_STATS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_SVC_ATTR_STATS,
  IPVS_SVC_ATTR_PE_NAME,
  __IPVS_SVC_ATTR_MAX,
 };
-#define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
 enum {
  IPVS_DEST_ATTR_UNSPEC = 0,
  IPVS_DEST_ATTR_ADDR,
- IPVS_DEST_ATTR_PORT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_DEST_ATTR_PORT,
  IPVS_DEST_ATTR_FWD_METHOD,
  IPVS_DEST_ATTR_WEIGHT,
  IPVS_DEST_ATTR_U_THRESH,
- IPVS_DEST_ATTR_L_THRESH,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_DEST_ATTR_L_THRESH,
  IPVS_DEST_ATTR_ACTIVE_CONNS,
  IPVS_DEST_ATTR_INACT_CONNS,
  IPVS_DEST_ATTR_PERSIST_CONNS,
- IPVS_DEST_ATTR_STATS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_DEST_ATTR_STATS,
  __IPVS_DEST_ATTR_MAX,
 };
 #define IPVS_DEST_ATTR_MAX (__IPVS_DEST_ATTR_MAX - 1)
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  IPVS_DAEMON_ATTR_UNSPEC = 0,
  IPVS_DAEMON_ATTR_STATE,
  IPVS_DAEMON_ATTR_MCAST_IFN,
- IPVS_DAEMON_ATTR_SYNC_ID,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_DAEMON_ATTR_SYNC_ID,
  __IPVS_DAEMON_ATTR_MAX,
 };
 #define IPVS_DAEMON_ATTR_MAX (__IPVS_DAEMON_ATTR_MAX - 1)
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  IPVS_STATS_ATTR_UNSPEC = 0,
  IPVS_STATS_ATTR_CONNS,
  IPVS_STATS_ATTR_INPKTS,
- IPVS_STATS_ATTR_OUTPKTS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_STATS_ATTR_OUTPKTS,
  IPVS_STATS_ATTR_INBYTES,
  IPVS_STATS_ATTR_OUTBYTES,
  IPVS_STATS_ATTR_CPS,
- IPVS_STATS_ATTR_INPPS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_STATS_ATTR_INPPS,
  IPVS_STATS_ATTR_OUTPPS,
  IPVS_STATS_ATTR_INBPS,
  IPVS_STATS_ATTR_OUTBPS,
- __IPVS_STATS_ATTR_MAX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __IPVS_STATS_ATTR_MAX,
 };
 #define IPVS_STATS_ATTR_MAX (__IPVS_STATS_ATTR_MAX - 1)
 enum {
- IPVS_INFO_ATTR_UNSPEC = 0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPVS_INFO_ATTR_UNSPEC = 0,
  IPVS_INFO_ATTR_VERSION,
  IPVS_INFO_ATTR_CONN_TAB_SIZE,
  __IPVS_INFO_ATTR_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1)
 #endif
diff --git a/libc/kernel/uapi/linux/ipv6.h b/libc/kernel/uapi/linux/ipv6.h
index e933d83..bfe62cf 100644
--- a/libc/kernel/uapi/linux/ipv6.h
+++ b/libc/kernel/uapi/linux/ipv6.h
@@ -141,6 +141,10 @@
  DEVCONF_FORCE_TLLAO,
  DEVCONF_NDISC_NOTIFY,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ DEVCONF_MLDV1_UNSOLICITED_REPORT_INTERVAL,
+ DEVCONF_MLDV2_UNSOLICITED_REPORT_INTERVAL,
+ DEVCONF_SUPPRESS_FRAG_NDISC,
  DEVCONF_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
diff --git a/libc/kernel/uapi/linux/kexec.h b/libc/kernel/uapi/linux/kexec.h
index 977fee6..a17dc23 100644
--- a/libc/kernel/uapi/linux/kexec.h
+++ b/libc/kernel/uapi/linux/kexec.h
@@ -26,24 +26,25 @@
 #define KEXEC_ARCH_DEFAULT ( 0 << 16)
 #define KEXEC_ARCH_386 ( 3 << 16)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEXEC_ARCH_68K ( 4 << 16)
 #define KEXEC_ARCH_X86_64 (62 << 16)
 #define KEXEC_ARCH_PPC (20 << 16)
 #define KEXEC_ARCH_PPC64 (21 << 16)
-#define KEXEC_ARCH_IA_64 (50 << 16)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEXEC_ARCH_IA_64 (50 << 16)
 #define KEXEC_ARCH_ARM (40 << 16)
 #define KEXEC_ARCH_S390 (22 << 16)
 #define KEXEC_ARCH_SH (42 << 16)
-#define KEXEC_ARCH_MIPS_LE (10 << 16)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KEXEC_ARCH_MIPS_LE (10 << 16)
 #define KEXEC_ARCH_MIPS ( 8 << 16)
 #define KEXEC_SEGMENT_MAX 16
 struct kexec_segment {
- const void *buf;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ const void *buf;
  size_t bufsz;
  const void *mem;
  size_t memsz;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #endif
diff --git a/libc/kernel/uapi/linux/keyctl.h b/libc/kernel/uapi/linux/keyctl.h
index 89854b5..941e0d5 100644
--- a/libc/kernel/uapi/linux/keyctl.h
+++ b/libc/kernel/uapi/linux/keyctl.h
@@ -67,4 +67,5 @@
 #define KEYCTL_INSTANTIATE_IOV 20
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KEYCTL_INVALIDATE 21
+#define KEYCTL_GET_PERSISTENT 22
 #endif
diff --git a/libc/kernel/uapi/linux/kvm.h b/libc/kernel/uapi/linux/kvm.h
index 955794b..e64f9b5 100644
--- a/libc/kernel/uapi/linux/kvm.h
+++ b/libc/kernel/uapi/linux/kvm.h
@@ -477,274 +477,284 @@
 #define KVMIO 0xAE
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_VM_S390_UCONTROL 1
+#define KVM_VM_PPC_HV 1
+#define KVM_VM_PPC_PR 2
 #define KVM_S390_SIE_PAGE_OFFSET 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
 #define KVM_CREATE_VM _IO(KVMIO, 0x01)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
 #define KVM_S390_ENABLE_SIE _IO(KVMIO, 0x06)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
 #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_GET_SUPPORTED_CPUID _IOWR(KVMIO, 0x05, struct kvm_cpuid2)
 #define KVM_TRACE_ENABLE __KVM_DEPRECATED_MAIN_W_0x06
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_TRACE_PAUSE __KVM_DEPRECATED_MAIN_0x07
 #define KVM_TRACE_DISABLE __KVM_DEPRECATED_MAIN_0x08
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2)
 #define KVM_CAP_IRQCHIP 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_HLT 1
 #define KVM_CAP_MMU_SHADOW_CACHE_CONTROL 2
 #define KVM_CAP_USER_MEMORY 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_SET_TSS_ADDR 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_VAPIC 6
 #define KVM_CAP_EXT_CPUID 7
 #define KVM_CAP_CLOCKSOURCE 8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_NR_VCPUS 9
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_NR_MEMSLOTS 10
 #define KVM_CAP_PIT 11
 #define KVM_CAP_NOP_IO_DELAY 12
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PV_MMU 13
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_MP_STATE 14
 #define KVM_CAP_COALESCED_MMIO 15
 #define KVM_CAP_SYNC_MMU 16
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_DEVICE_ASSIGNMENT 17
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_IOMMU 18
 #ifdef __KVM_HAVE_MSI
 #define KVM_CAP_DEVICE_MSI 20
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_DESTROY_MEMORY_REGION_WORKS 21
 #ifdef __KVM_HAVE_USER_NMI
 #define KVM_CAP_USER_NMI 22
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __KVM_HAVE_GUEST_DEBUG
 #define KVM_CAP_SET_GUEST_DEBUG 23
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __KVM_HAVE_PIT
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_REINJECT_CONTROL 24
 #endif
 #define KVM_CAP_IRQ_ROUTING 25
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_IRQ_INJECT_STATUS 26
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_DEVICE_DEASSIGNMENT 27
 #ifdef __KVM_HAVE_MSIX
 #define KVM_CAP_DEVICE_MSIX 28
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_ASSIGN_DEV_IRQ 29
 #define KVM_CAP_JOIN_MEMORY_REGIONS_WORKS 30
 #ifdef __KVM_HAVE_MCE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_MCE 31
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #define KVM_CAP_IRQFD 32
 #ifdef __KVM_HAVE_PIT
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PIT2 33
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #define KVM_CAP_SET_BOOT_CPU_ID 34
 #ifdef __KVM_HAVE_PIT_STATE2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PIT_STATE2 35
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #define KVM_CAP_IOEVENTFD 36
 #define KVM_CAP_SET_IDENTITY_MAP_ADDR 37
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __KVM_HAVE_XEN_HVM
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_XEN_HVM 38
 #endif
 #define KVM_CAP_ADJUST_CLOCK 39
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_INTERNAL_ERROR_DATA 40
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __KVM_HAVE_VCPU_EVENTS
 #define KVM_CAP_VCPU_EVENTS 41
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_S390_PSW 42
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_SEGSTATE 43
 #define KVM_CAP_HYPERV 44
 #define KVM_CAP_HYPERV_VAPIC 45
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_HYPERV_SPIN 46
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PCI_SEGMENT 47
 #define KVM_CAP_PPC_PAIRED_SINGLES 48
 #define KVM_CAP_INTR_SHADOW 49
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __KVM_HAVE_DEBUGREGS
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_DEBUGREGS 50
 #endif
 #define KVM_CAP_X86_ROBUST_SINGLESTEP 51
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_OSI 52
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_UNSET_IRQ 53
 #define KVM_CAP_ENABLE_CAP 54
 #ifdef __KVM_HAVE_XSAVE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_XSAVE 55
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
 #ifdef __KVM_HAVE_XCRS
 #define KVM_CAP_XCRS 56
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_GET_PVINFO 57
 #define KVM_CAP_PPC_IRQ_LEVEL 58
 #define KVM_CAP_ASYNC_PF 59
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_TSC_CONTROL 60
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_GET_TSC_KHZ 61
 #define KVM_CAP_PPC_BOOKE_SREGS 62
 #define KVM_CAP_SPAPR_TCE 63
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_SMT 64
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_RMA 65
 #define KVM_CAP_MAX_VCPUS 66
 #define KVM_CAP_PPC_HIOR 67
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_PAPR 68
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_SW_TLB 69
 #define KVM_CAP_ONE_REG 70
 #define KVM_CAP_S390_GMAP 71
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_TSC_DEADLINE_TIMER 72
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_S390_UCONTROL 73
 #define KVM_CAP_SYNC_REGS 74
 #define KVM_CAP_PCI_2_3 75
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_KVMCLOCK_CTRL 76
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_SIGNAL_MSI 77
 #define KVM_CAP_PPC_GET_SMMU_INFO 78
 #define KVM_CAP_S390_COW 79
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_ALLOC_HTAB 80
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __KVM_HAVE_READONLY_MEM
 #define KVM_CAP_READONLY_MEM 81
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_IRQFD_RESAMPLE 82
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_BOOKE_WATCHDOG 83
 #define KVM_CAP_PPC_HTAB_FD 84
 #define KVM_CAP_S390_CSS_SUPPORT 85
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_EPR 86
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_ARM_PSCI 87
 #define KVM_CAP_ARM_SET_DEVICE_ADDR 88
 #define KVM_CAP_DEVICE_CTRL 89
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_IRQ_MPIC 90
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_CAP_PPC_RTAS 91
 #define KVM_CAP_IRQ_XICS 92
-#ifdef KVM_CAP_IRQ_ROUTING
+#define KVM_CAP_ARM_EL1_32BIT 93
+#define KVM_CAP_SPAPR_MULTITCE 94
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_CAP_EXT_EMUL_CPUID 95
+#define KVM_CAP_HYPERV_TIME 96
+#ifdef KVM_CAP_IRQ_ROUTING
 struct kvm_irq_routing_irqchip {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 irqchip;
  __u32 pin;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct kvm_irq_routing_msi {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 address_lo;
  __u32 address_hi;
  __u32 data;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pad;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define KVM_IRQ_ROUTING_IRQCHIP 1
 #define KVM_IRQ_ROUTING_MSI 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct kvm_irq_routing_entry {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 gsi;
  __u32 type;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pad;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  struct kvm_irq_routing_irqchip irqchip;
  struct kvm_irq_routing_msi msi;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pad[8];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } u;
 };
 struct kvm_irq_routing {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 nr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
  struct kvm_irq_routing_entry entries[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef KVM_CAP_MCE
 struct kvm_x86_mce {
  __u64 status;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 addr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 misc;
  __u64 mcg_status;
  __u8 bank;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 pad1[7];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 pad2[3];
 };
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef KVM_CAP_XEN_HVM
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct kvm_xen_hvm_config {
  __u32 flags;
  __u32 msr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 blob_addr_32;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 blob_addr_64;
  __u8 blob_size_32;
  __u8 blob_size_64;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 pad2[30];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
 #define KVM_IRQFD_FLAG_DEASSIGN (1 << 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_IRQFD_FLAG_RESAMPLE (1 << 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct kvm_irqfd {
  __u32 fd;
  __u32 gsi;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 resamplefd;
  __u8 pad[16];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct kvm_clock_data {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 clock;
  __u32 flags;
  __u32 pad[9];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_MMU_FSL_BOOKE_NOHV 0
 #define KVM_MMU_FSL_BOOKE_HV 1
 struct kvm_config_tlb {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 params;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 array;
  __u32 mmu_type;
  __u32 array_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct kvm_dirty_tlb {
  __u64 bitmap;
  __u32 num_dirty;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_REG_ARCH_MASK 0xff00000000000000ULL
 #define KVM_REG_GENERIC 0x0000000000000000ULL
 #define KVM_REG_PPC 0x1000000000000000ULL
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_REG_X86 0x2000000000000000ULL
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_REG_IA64 0x3000000000000000ULL
 #define KVM_REG_ARM 0x4000000000000000ULL
 #define KVM_REG_S390 0x5000000000000000ULL
+#define KVM_REG_ARM64 0x6000000000000000ULL
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_REG_MIPS 0x7000000000000000ULL
 #define KVM_REG_SIZE_SHIFT 52
@@ -802,195 +812,203 @@
 #define KVM_DEV_TYPE_FSL_MPIC_42 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_DEV_TYPE_XICS 3
+#define KVM_DEV_TYPE_VFIO 4
+#define KVM_DEV_VFIO_GROUP 1
+#define KVM_DEV_VFIO_GROUP_ADD 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_DEV_VFIO_GROUP_DEL 2
+#define KVM_DEV_TYPE_ARM_VGIC_V2 5
 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
 #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
-#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
 #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
 #define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44)
 #define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45)
-#define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46,   struct kvm_userspace_memory_region)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46,   struct kvm_userspace_memory_region)
 #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47)
 #define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO, 0x48, __u64)
 struct kvm_s390_ucas_mapping {
- __u64 user_addr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 user_addr;
  __u64 vcpu_addr;
  __u64 length;
 };
-#define KVM_S390_UCAS_MAP _IOW(KVMIO, 0x50, struct kvm_s390_ucas_mapping)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_S390_UCAS_MAP _IOW(KVMIO, 0x50, struct kvm_s390_ucas_mapping)
 #define KVM_S390_UCAS_UNMAP _IOW(KVMIO, 0x51, struct kvm_s390_ucas_mapping)
 #define KVM_S390_VCPU_FAULT _IOW(KVMIO, 0x52, unsigned long)
 #define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60)
-#define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level)
 #define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip)
 #define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip)
 #define KVM_CREATE_PIT _IO(KVMIO, 0x64)
-#define KVM_GET_PIT _IOWR(KVMIO, 0x65, struct kvm_pit_state)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_GET_PIT _IOWR(KVMIO, 0x65, struct kvm_pit_state)
 #define KVM_SET_PIT _IOR(KVMIO, 0x66, struct kvm_pit_state)
 #define KVM_IRQ_LINE_STATUS _IOWR(KVMIO, 0x67, struct kvm_irq_level)
 #define KVM_REGISTER_COALESCED_MMIO   _IOW(KVMIO, 0x67, struct kvm_coalesced_mmio_zone)
-#define KVM_UNREGISTER_COALESCED_MMIO   _IOW(KVMIO, 0x68, struct kvm_coalesced_mmio_zone)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_UNREGISTER_COALESCED_MMIO   _IOW(KVMIO, 0x68, struct kvm_coalesced_mmio_zone)
 #define KVM_ASSIGN_PCI_DEVICE _IOR(KVMIO, 0x69,   struct kvm_assigned_pci_dev)
 #define KVM_SET_GSI_ROUTING _IOW(KVMIO, 0x6a, struct kvm_irq_routing)
 #define KVM_ASSIGN_IRQ __KVM_DEPRECATED_VM_R_0x70
-#define KVM_ASSIGN_DEV_IRQ _IOW(KVMIO, 0x70, struct kvm_assigned_irq)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ASSIGN_DEV_IRQ _IOW(KVMIO, 0x70, struct kvm_assigned_irq)
 #define KVM_REINJECT_CONTROL _IO(KVMIO, 0x71)
 #define KVM_DEASSIGN_PCI_DEVICE _IOW(KVMIO, 0x72,   struct kvm_assigned_pci_dev)
 #define KVM_ASSIGN_SET_MSIX_NR _IOW(KVMIO, 0x73,   struct kvm_assigned_msix_nr)
-#define KVM_ASSIGN_SET_MSIX_ENTRY _IOW(KVMIO, 0x74,   struct kvm_assigned_msix_entry)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ASSIGN_SET_MSIX_ENTRY _IOW(KVMIO, 0x74,   struct kvm_assigned_msix_entry)
 #define KVM_DEASSIGN_DEV_IRQ _IOW(KVMIO, 0x75, struct kvm_assigned_irq)
 #define KVM_IRQFD _IOW(KVMIO, 0x76, struct kvm_irqfd)
 #define KVM_CREATE_PIT2 _IOW(KVMIO, 0x77, struct kvm_pit_config)
-#define KVM_SET_BOOT_CPU_ID _IO(KVMIO, 0x78)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SET_BOOT_CPU_ID _IO(KVMIO, 0x78)
 #define KVM_IOEVENTFD _IOW(KVMIO, 0x79, struct kvm_ioeventfd)
 #define KVM_XEN_HVM_CONFIG _IOW(KVMIO, 0x7a, struct kvm_xen_hvm_config)
 #define KVM_SET_CLOCK _IOW(KVMIO, 0x7b, struct kvm_clock_data)
-#define KVM_GET_CLOCK _IOR(KVMIO, 0x7c, struct kvm_clock_data)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_GET_CLOCK _IOR(KVMIO, 0x7c, struct kvm_clock_data)
 #define KVM_GET_PIT2 _IOR(KVMIO, 0x9f, struct kvm_pit_state2)
 #define KVM_SET_PIT2 _IOW(KVMIO, 0xa0, struct kvm_pit_state2)
 #define KVM_PPC_GET_PVINFO _IOW(KVMIO, 0xa1, struct kvm_ppc_pvinfo)
-#define KVM_SET_TSC_KHZ _IO(KVMIO, 0xa2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SET_TSC_KHZ _IO(KVMIO, 0xa2)
 #define KVM_GET_TSC_KHZ _IO(KVMIO, 0xa3)
 #define KVM_ASSIGN_SET_INTX_MASK _IOW(KVMIO, 0xa4,   struct kvm_assigned_pci_dev)
 #define KVM_SIGNAL_MSI _IOW(KVMIO, 0xa5, struct kvm_msi)
-#define KVM_PPC_GET_SMMU_INFO _IOR(KVMIO, 0xa6, struct kvm_ppc_smmu_info)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_PPC_GET_SMMU_INFO _IOR(KVMIO, 0xa6, struct kvm_ppc_smmu_info)
 #define KVM_PPC_ALLOCATE_HTAB _IOWR(KVMIO, 0xa7, __u32)
 #define KVM_CREATE_SPAPR_TCE _IOW(KVMIO, 0xa8, struct kvm_create_spapr_tce)
 #define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma)
-#define KVM_PPC_GET_HTAB_FD _IOW(KVMIO, 0xaa, struct kvm_get_htab_fd)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_PPC_GET_HTAB_FD _IOW(KVMIO, 0xaa, struct kvm_get_htab_fd)
 #define KVM_ARM_SET_DEVICE_ADDR _IOW(KVMIO, 0xab, struct kvm_arm_device_addr)
 #define KVM_PPC_RTAS_DEFINE_TOKEN _IOW(KVMIO, 0xac, struct kvm_rtas_token_args)
 #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device)
-#define KVM_SET_DEVICE_ATTR _IOW(KVMIO, 0xe1, struct kvm_device_attr)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SET_DEVICE_ATTR _IOW(KVMIO, 0xe1, struct kvm_device_attr)
 #define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)
 #define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr)
 #define KVM_RUN _IO(KVMIO, 0x80)
-#define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
 #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
 #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
 #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
-#define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
 #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
 #define KVM_DEBUG_GUEST __KVM_DEPRECATED_VCPU_W_0x87
 #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
-#define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
 #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
 #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
 #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
-#define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
 #define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state)
 #define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state)
 #define KVM_SET_CPUID2 _IOW(KVMIO, 0x90, struct kvm_cpuid2)
-#define KVM_GET_CPUID2 _IOWR(KVMIO, 0x91, struct kvm_cpuid2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_GET_CPUID2 _IOWR(KVMIO, 0x91, struct kvm_cpuid2)
 #define KVM_TPR_ACCESS_REPORTING _IOWR(KVMIO, 0x92, struct kvm_tpr_access_ctl)
 #define KVM_SET_VAPIC_ADDR _IOW(KVMIO, 0x93, struct kvm_vapic_addr)
 #define KVM_S390_INTERRUPT _IOW(KVMIO, 0x94, struct kvm_s390_interrupt)
-#define KVM_S390_STORE_STATUS_NOADDR (-1ul)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_S390_STORE_STATUS_NOADDR (-1ul)
 #define KVM_S390_STORE_STATUS_PREFIXED (-2ul)
 #define KVM_S390_STORE_STATUS _IOW(KVMIO, 0x95, unsigned long)
 #define KVM_S390_SET_INITIAL_PSW _IOW(KVMIO, 0x96, struct kvm_s390_psw)
-#define KVM_S390_INITIAL_RESET _IO(KVMIO, 0x97)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_S390_INITIAL_RESET _IO(KVMIO, 0x97)
 #define KVM_GET_MP_STATE _IOR(KVMIO, 0x98, struct kvm_mp_state)
 #define KVM_SET_MP_STATE _IOW(KVMIO, 0x99, struct kvm_mp_state)
 #define KVM_NMI _IO(KVMIO, 0x9a)
-#define KVM_SET_GUEST_DEBUG _IOW(KVMIO, 0x9b, struct kvm_guest_debug)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SET_GUEST_DEBUG _IOW(KVMIO, 0x9b, struct kvm_guest_debug)
 #define KVM_X86_SETUP_MCE _IOW(KVMIO, 0x9c, __u64)
 #define KVM_X86_GET_MCE_CAP_SUPPORTED _IOR(KVMIO, 0x9d, __u64)
 #define KVM_X86_SET_MCE _IOW(KVMIO, 0x9e, struct kvm_x86_mce)
-#define KVM_IA64_VCPU_GET_STACK _IOR(KVMIO, 0x9a, void *)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_IA64_VCPU_GET_STACK _IOR(KVMIO, 0x9a, void *)
 #define KVM_IA64_VCPU_SET_STACK _IOW(KVMIO, 0x9b, void *)
 #define KVM_GET_VCPU_EVENTS _IOR(KVMIO, 0x9f, struct kvm_vcpu_events)
 #define KVM_SET_VCPU_EVENTS _IOW(KVMIO, 0xa0, struct kvm_vcpu_events)
-#define KVM_GET_DEBUGREGS _IOR(KVMIO, 0xa1, struct kvm_debugregs)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_GET_DEBUGREGS _IOR(KVMIO, 0xa1, struct kvm_debugregs)
 #define KVM_SET_DEBUGREGS _IOW(KVMIO, 0xa2, struct kvm_debugregs)
 #define KVM_ENABLE_CAP _IOW(KVMIO, 0xa3, struct kvm_enable_cap)
 #define KVM_GET_XSAVE _IOR(KVMIO, 0xa4, struct kvm_xsave)
-#define KVM_SET_XSAVE _IOW(KVMIO, 0xa5, struct kvm_xsave)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_SET_XSAVE _IOW(KVMIO, 0xa5, struct kvm_xsave)
 #define KVM_GET_XCRS _IOR(KVMIO, 0xa6, struct kvm_xcrs)
 #define KVM_SET_XCRS _IOW(KVMIO, 0xa7, struct kvm_xcrs)
 #define KVM_DIRTY_TLB _IOW(KVMIO, 0xaa, struct kvm_dirty_tlb)
-#define KVM_GET_ONE_REG _IOW(KVMIO, 0xab, struct kvm_one_reg)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_GET_ONE_REG _IOW(KVMIO, 0xab, struct kvm_one_reg)
 #define KVM_SET_ONE_REG _IOW(KVMIO, 0xac, struct kvm_one_reg)
 #define KVM_KVMCLOCK_CTRL _IO(KVMIO, 0xad)
 #define KVM_ARM_VCPU_INIT _IOW(KVMIO, 0xae, struct kvm_vcpu_init)
-#define KVM_GET_REG_LIST _IOWR(KVMIO, 0xb0, struct kvm_reg_list)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define KVM_ARM_PREFERRED_TARGET _IOR(KVMIO, 0xaf, struct kvm_vcpu_init)
+#define KVM_GET_REG_LIST _IOWR(KVMIO, 0xb0, struct kvm_reg_list)
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
 #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
 struct kvm_assigned_pci_dev {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 assigned_dev_id;
  __u32 busnr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 devfn;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 segnr;
  union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[11];
  };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define KVM_DEV_IRQ_HOST_INTX (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_DEV_IRQ_HOST_MSI (1 << 1)
 #define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
 #define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
 #define KVM_DEV_IRQ_HOST_MASK 0x00ff
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_DEV_IRQ_GUEST_MASK 0xff00
 struct kvm_assigned_irq {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 assigned_dev_id;
  __u32 host_irq;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 guest_irq;
  __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  __u32 reserved[12];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct kvm_assigned_msix_nr {
  __u32 assigned_dev_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 entry_nr;
  __u16 padding;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define KVM_MAX_MSIX_PER_DEV 256
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct kvm_assigned_msix_entry {
  __u32 assigned_dev_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 gsi;
  __u16 entry;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 padding[3];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/kvm_para.h b/libc/kernel/uapi/linux/kvm_para.h
index ab01e69..d973996 100644
--- a/libc/kernel/uapi/linux/kvm_para.h
+++ b/libc/kernel/uapi/linux/kvm_para.h
@@ -28,6 +28,7 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define KVM_HC_FEATURES 3
 #define KVM_HC_PPC_MAP_MAGIC_PAGE 4
+#define KVM_HC_KICK_CPU 5
 #include <asm/kvm_para.h>
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/libc-compat.h b/libc/kernel/uapi/linux/libc-compat.h
new file mode 100644
index 0000000..826b763
--- /dev/null
+++ b/libc/kernel/uapi/linux/libc-compat.h
@@ -0,0 +1,53 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI_LIBC_COMPAT_H
+#define _UAPI_LIBC_COMPAT_H
+#ifdef __GLIBC__
+#ifdef _NETINET_IN_H
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IN6_ADDR 0
+#if defined(__USE_MISC) || defined(__USE_GNU)
+#define __UAPI_DEF_IN6_ADDR_ALT 0
+#else
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IN6_ADDR_ALT 1
+#endif
+#define __UAPI_DEF_SOCKADDR_IN6 0
+#define __UAPI_DEF_IPV6_MREQ 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IPPROTO_V6 0
+#else
+#define __UAPI_DEF_IN6_ADDR 1
+#define __UAPI_DEF_IN6_ADDR_ALT 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_SOCKADDR_IN6 1
+#define __UAPI_DEF_IPV6_MREQ 1
+#define __UAPI_DEF_IPPROTO_V6 1
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#else
+#define __UAPI_DEF_IN6_ADDR 1
+#define __UAPI_DEF_IN6_ADDR_ALT 1
+#define __UAPI_DEF_SOCKADDR_IN6 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IPV6_MREQ 1
+#define __UAPI_DEF_IPPROTO_V6 1
+#endif
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/magic.h b/libc/kernel/uapi/linux/magic.h
index 19ef392..7c7c6c3 100644
--- a/libc/kernel/uapi/linux/magic.h
+++ b/libc/kernel/uapi/linux/magic.h
@@ -93,4 +93,6 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MTD_INODE_FS_MAGIC 0x11307854
 #define ANON_INODE_FS_MAGIC 0x09041934
+#define BTRFS_TEST_MAGIC 0x73727279
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/major.h b/libc/kernel/uapi/linux/major.h
index 3d1557a..d07d065 100644
--- a/libc/kernel/uapi/linux/major.h
+++ b/libc/kernel/uapi/linux/major.h
@@ -78,118 +78,121 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define AZTECH_CDROM_MAJOR 29
 #define FB_MAJOR 29
+#define MTD_BLOCK_MAJOR 31
 #define CM206_CDROM_MAJOR 32
-#define IDE2_MAJOR 33
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IDE2_MAJOR 33
 #define IDE3_MAJOR 34
 #define Z8530_MAJOR 34
 #define XPRAM_MAJOR 35
-#define NETLINK_MAJOR 36
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETLINK_MAJOR 36
 #define PS2ESDI_MAJOR 36
 #define IDETAPE_MAJOR 37
 #define Z2RAM_MAJOR 37
-#define APBLOCK_MAJOR 38
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define APBLOCK_MAJOR 38
 #define DDV_MAJOR 39
 #define NBD_MAJOR 43
 #define RISCOM8_NORMAL_MAJOR 48
-#define DAC960_MAJOR 48
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DAC960_MAJOR 48
 #define RISCOM8_CALLOUT_MAJOR 49
 #define MKISS_MAJOR 55
 #define DSP56K_MAJOR 55
-#define IDE4_MAJOR 56
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IDE4_MAJOR 56
 #define IDE5_MAJOR 57
 #define SCSI_DISK1_MAJOR 65
 #define SCSI_DISK2_MAJOR 66
-#define SCSI_DISK3_MAJOR 67
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SCSI_DISK3_MAJOR 67
 #define SCSI_DISK4_MAJOR 68
 #define SCSI_DISK5_MAJOR 69
 #define SCSI_DISK6_MAJOR 70
-#define SCSI_DISK7_MAJOR 71
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SCSI_DISK7_MAJOR 71
 #define COMPAQ_SMART2_MAJOR 72
 #define COMPAQ_SMART2_MAJOR1 73
 #define COMPAQ_SMART2_MAJOR2 74
-#define COMPAQ_SMART2_MAJOR3 75
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define COMPAQ_SMART2_MAJOR3 75
 #define COMPAQ_SMART2_MAJOR4 76
 #define COMPAQ_SMART2_MAJOR5 77
 #define COMPAQ_SMART2_MAJOR6 78
-#define COMPAQ_SMART2_MAJOR7 79
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define COMPAQ_SMART2_MAJOR7 79
 #define SPECIALIX_NORMAL_MAJOR 75
 #define SPECIALIX_CALLOUT_MAJOR 76
 #define AURORA_MAJOR 79
-#define I2O_MAJOR 80
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I2O_MAJOR 80
 #define SHMIQ_MAJOR 85
 #define SCSI_CHANGER_MAJOR 86
 #define IDE6_MAJOR 88
-#define IDE7_MAJOR 89
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IDE7_MAJOR 89
 #define IDE8_MAJOR 90
+#define MTD_CHAR_MAJOR 90
 #define IDE9_MAJOR 91
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DASD_MAJOR 94
 #define MDISK_MAJOR 95
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define UBD_MAJOR 98
 #define PP_MAJOR 99
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define JSFD_MAJOR 99
 #define PHONE_MAJOR 100
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define COMPAQ_CISS_MAJOR 104
 #define COMPAQ_CISS_MAJOR1 105
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define COMPAQ_CISS_MAJOR2 106
 #define COMPAQ_CISS_MAJOR3 107
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define COMPAQ_CISS_MAJOR4 108
 #define COMPAQ_CISS_MAJOR5 109
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define COMPAQ_CISS_MAJOR6 110
 #define COMPAQ_CISS_MAJOR7 111
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VIODASD_MAJOR 112
 #define VIOCD_MAJOR 113
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ATARAID_MAJOR 114
 #define SCSI_DISK8_MAJOR 128
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SCSI_DISK9_MAJOR 129
 #define SCSI_DISK10_MAJOR 130
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SCSI_DISK11_MAJOR 131
 #define SCSI_DISK12_MAJOR 132
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SCSI_DISK13_MAJOR 133
 #define SCSI_DISK14_MAJOR 134
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SCSI_DISK15_MAJOR 135
 #define UNIX98_PTY_MASTER_MAJOR 128
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define UNIX98_PTY_MAJOR_COUNT 8
 #define UNIX98_PTY_SLAVE_MAJOR (UNIX98_PTY_MASTER_MAJOR+UNIX98_PTY_MAJOR_COUNT)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define DRBD_MAJOR 147
 #define RTF_MAJOR 150
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RAW_MAJOR 162
 #define USB_ACM_MAJOR 166
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define USB_ACM_AUX_MAJOR 167
 #define USB_CHAR_MAJOR 180
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MMC_BLOCK_MAJOR 179
 #define VXVM_MAJOR 199
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VXSPEC_MAJOR 200
 #define VXDMP_MAJOR 201
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XENVBD_MAJOR 202
 #define MSR_MAJOR 202
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CPUID_MAJOR 203
 #define OSST_MAJOR 206
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IBM_TTY3270_MAJOR 227
 #define IBM_FS3270_MAJOR 228
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VIOTAPE_MAJOR 230
 #define BLOCK_EXT_MAJOR 259
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SCSI_OSD_MAJOR 260
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/media.h b/libc/kernel/uapi/linux/media.h
index 8a2687c..4ba54aa 100644
--- a/libc/kernel/uapi/linux/media.h
+++ b/libc/kernel/uapi/linux/media.h
@@ -92,35 +92,37 @@
 #define MEDIA_PAD_FL_SINK (1 << 0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MEDIA_PAD_FL_SOURCE (1 << 1)
+#define MEDIA_PAD_FL_MUST_CONNECT (1 << 2)
 struct media_pad_desc {
  __u32 entity;
- __u16 index;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 index;
  __u32 flags;
  __u32 reserved[2];
 };
-#define MEDIA_LNK_FL_ENABLED (1 << 0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MEDIA_LNK_FL_ENABLED (1 << 0)
 #define MEDIA_LNK_FL_IMMUTABLE (1 << 1)
 #define MEDIA_LNK_FL_DYNAMIC (1 << 2)
 struct media_link_desc {
- struct media_pad_desc source;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct media_pad_desc source;
  struct media_pad_desc sink;
  __u32 flags;
  __u32 reserved[2];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct media_links_enum {
  __u32 entity;
  struct media_pad_desc __user *pads;
- struct media_link_desc __user *links;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct media_link_desc __user *links;
  __u32 reserved[4];
 };
 #define MEDIA_IOC_DEVICE_INFO _IOWR('|', 0x00, struct media_device_info)
-#define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc)
 #define MEDIA_IOC_ENUM_LINKS _IOWR('|', 0x02, struct media_links_enum)
 #define MEDIA_IOC_SETUP_LINK _IOWR('|', 0x03, struct media_link_desc)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/mic_common.h b/libc/kernel/uapi/linux/mic_common.h
new file mode 100644
index 0000000..30d8308
--- /dev/null
+++ b/libc/kernel/uapi/linux/mic_common.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __MIC_COMMON_H_
+#define __MIC_COMMON_H_
+#include <linux/virtio_ring.h>
+#define __mic_align(a, x) (((a) + (x) - 1) & ~((x) - 1))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct mic_device_desc {
+ __s8 type;
+ __u8 num_vq;
+ __u8 feature_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 config_len;
+ __u8 status;
+ __le64 config[0];
+} __attribute__ ((aligned(8)));
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct mic_device_ctrl {
+ __le64 vdev;
+ __u8 config_change;
+ __u8 vdev_reset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 guest_ack;
+ __u8 host_ack;
+ __u8 used_address_updated;
+ __s8 c2h_vdev_db;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s8 h2c_vdev_db;
+} __attribute__ ((aligned(8)));
+struct mic_bootparam {
+ __le32 magic;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s8 c2h_shutdown_db;
+ __s8 h2c_shutdown_db;
+ __s8 h2c_config_db;
+ __u8 shutdown_status;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 shutdown_card;
+} __attribute__ ((aligned(8)));
+struct mic_device_page {
+ struct mic_bootparam bootparam;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct mic_device_desc desc[0];
+};
+struct mic_vqconfig {
+ __le64 address;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le64 used_address;
+ __le16 num;
+} __attribute__ ((aligned(8)));
+#define MIC_VIRTIO_RING_ALIGN 4096
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MIC_MAX_VRINGS 4
+#define MIC_VRING_ENTRIES 128
+#define MIC_MAX_VRING_ENTRIES 128
+#define MIC_MAX_DESC_BLK_SIZE 256
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct _mic_vring_info {
+ __u16 avail_idx;
+ __le32 magic;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct mic_vring {
+ struct vring vr;
+ struct _mic_vring_info *info;
+ void *va;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int len;
+};
+#define mic_aligned_desc_size(d) __mic_align(mic_desc_size(d), 8)
+#ifndef INTEL_MIC_CARD
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
+#define MIC_DP_SIZE 4096
+#define MIC_MAGIC 0xc0ffee00
+enum mic_states {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ MIC_OFFLINE = 0,
+ MIC_ONLINE,
+ MIC_SHUTTING_DOWN,
+ MIC_RESET_FAILED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ MIC_SUSPENDING,
+ MIC_SUSPENDED,
+ MIC_LAST
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum mic_status {
+ MIC_NOP = 0,
+ MIC_CRASHED,
+ MIC_HALTED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ MIC_POWER_OFF,
+ MIC_RESTART,
+ MIC_STATUS_LAST
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/mic_ioctl.h b/libc/kernel/uapi/linux/mic_ioctl.h
new file mode 100644
index 0000000..9eb1ad2
--- /dev/null
+++ b/libc/kernel/uapi/linux/mic_ioctl.h
@@ -0,0 +1,35 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _MIC_IOCTL_H_
+#define _MIC_IOCTL_H_
+#include <linux/types.h>
+struct mic_copy_desc {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct iovec *iov;
+ __u32 iovcnt;
+ __u8 vr_idx;
+ __u8 update_used;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 out_len;
+};
+#define MIC_VIRTIO_ADD_DEVICE _IOWR('s', 1, struct mic_device_desc *)
+#define MIC_VIRTIO_COPY_DESC _IOWR('s', 2, struct mic_copy_desc *)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MIC_VIRTIO_CONFIG_CHANGE _IOWR('s', 5, __u8 *)
+#endif
diff --git a/libc/kernel/uapi/linux/mqueue.h b/libc/kernel/uapi/linux/mqueue.h
index 9448cfe..4599cdc 100644
--- a/libc/kernel/uapi/linux/mqueue.h
+++ b/libc/kernel/uapi/linux/mqueue.h
@@ -22,12 +22,12 @@
 #define MQ_BYTES_MAX 819200
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct mq_attr {
- long mq_flags;
- long mq_maxmsg;
- long mq_msgsize;
+ __kernel_long_t mq_flags;
+ __kernel_long_t mq_maxmsg;
+ __kernel_long_t mq_msgsize;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long mq_curmsgs;
- long __reserved[4];
+ __kernel_long_t mq_curmsgs;
+ __kernel_long_t __reserved[4];
 };
 #define NOTIFY_NONE 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/msdos_fs.h b/libc/kernel/uapi/linux/msdos_fs.h
index c564f3e..f1190ad 100644
--- a/libc/kernel/uapi/linux/msdos_fs.h
+++ b/libc/kernel/uapi/linux/msdos_fs.h
@@ -101,7 +101,7 @@
 #define FAT_IOCTL_GET_ATTRIBUTES _IOR('r', 0x10, __u32)
 #define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define VFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32)
+#define FAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x13, __u32)
 struct fat_boot_sector {
  __u8 ignored[3];
  __u8 system_id[8];
@@ -126,6 +126,11 @@
  __u8 drive_number;
  __u8 state;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 signature;
+ __u8 vol_id[4];
+ __u8 vol_label[11];
+ __u8 fs_type[8];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } fat16;
  struct {
  __le32 length;
@@ -139,6 +144,11 @@
  __le16 reserved2[6];
  __u8 drive_number;
  __u8 state;
+ __u8 signature;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 vol_id[4];
+ __u8 vol_label[11];
+ __u8 fs_type[8];
  } fat32;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
@@ -153,44 +163,32 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __le32 reserved2[4];
 };
-struct fat_boot_bsx {
- __u8 drive;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u8 reserved1;
- __u8 signature;
- __u8 vol_id[4];
- __u8 vol_label[11];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u8 type[8];
-};
-#define FAT16_BSX_OFFSET 36
-#define FAT32_BSX_OFFSET 64
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct msdos_dir_entry {
  __u8 name[MSDOS_NAME];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 attr;
  __u8 lcase;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 ctime_cs;
  __le16 ctime;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __le16 cdate;
  __le16 adate;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __le16 starthi;
  __le16 time,date,start;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __le32 size;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct msdos_dir_slot {
  __u8 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name0_4[10];
  __u8 attr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 reserved;
  __u8 alias_checksum;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name5_10[12];
  __le16 start;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name11_12[4];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/msg.h b/libc/kernel/uapi/linux/msg.h
index 72751da..8d7c606 100644
--- a/libc/kernel/uapi/linux/msg.h
+++ b/libc/kernel/uapi/linux/msg.h
@@ -47,7 +47,7 @@
 #include <asm/msgbuf.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct msgbuf {
- long mtype;
+ __kernel_long_t mtype;
  char mtext[1];
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netconf.h b/libc/kernel/uapi/linux/netconf.h
index 4c9aad3..2bf09d1 100644
--- a/libc/kernel/uapi/linux/netconf.h
+++ b/libc/kernel/uapi/linux/netconf.h
@@ -32,10 +32,12 @@
  NETCONFA_RP_FILTER,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NETCONFA_MC_FORWARDING,
+ NETCONFA_PROXY_NEIGH,
  __NETCONFA_MAX
 };
-#define NETCONFA_MAX (__NETCONFA_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETCONFA_MAX (__NETCONFA_MAX - 1)
 #define NETCONFA_IFINDEX_ALL -1
 #define NETCONFA_IFINDEX_DEFAULT -2
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter.h b/libc/kernel/uapi/linux/netfilter.h
index 0b0ddac..7804321 100644
--- a/libc/kernel/uapi/linux/netfilter.h
+++ b/libc/kernel/uapi/linux/netfilter.h
@@ -54,22 +54,23 @@
 };
 enum {
  NFPROTO_UNSPEC = 0,
- NFPROTO_IPV4 = 2,
+ NFPROTO_INET = 1,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFPROTO_IPV4 = 2,
  NFPROTO_ARP = 3,
  NFPROTO_BRIDGE = 7,
  NFPROTO_IPV6 = 10,
- NFPROTO_DECNET = 12,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFPROTO_DECNET = 12,
  NFPROTO_NUMPROTO,
 };
 union nf_inet_addr {
- __u32 all[4];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 all[4];
  __be32 ip;
  __be32 ip6[4];
  struct in_addr in;
- struct in6_addr in6;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct in6_addr in6;
 };
 #endif
diff --git a/libc/kernel/uapi/linux/netfilter/ipset/ip_set.h b/libc/kernel/uapi/linux/netfilter/ipset/ip_set.h
index 1da11ef..d85c85b 100644
--- a/libc/kernel/uapi/linux/netfilter/ipset/ip_set.h
+++ b/libc/kernel/uapi/linux/netfilter/ipset/ip_set.h
@@ -21,234 +21,249 @@
 #include <linux/types.h>
 #define IPSET_PROTOCOL 6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IPSET_MAX_COMMENT_SIZE 255
 #define IPSET_MAXNAMELEN 32
 enum ipset_cmd {
  IPSET_CMD_NONE,
- IPSET_CMD_PROTOCOL,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_CMD_PROTOCOL,
  IPSET_CMD_CREATE,
  IPSET_CMD_DESTROY,
  IPSET_CMD_FLUSH,
- IPSET_CMD_RENAME,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_CMD_RENAME,
  IPSET_CMD_SWAP,
  IPSET_CMD_LIST,
  IPSET_CMD_SAVE,
- IPSET_CMD_ADD,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_CMD_ADD,
  IPSET_CMD_DEL,
  IPSET_CMD_TEST,
  IPSET_CMD_HEADER,
- IPSET_CMD_TYPE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_CMD_TYPE,
  IPSET_MSG_MAX,
  IPSET_CMD_RESTORE = IPSET_MSG_MAX,
  IPSET_CMD_HELP,
- IPSET_CMD_VERSION,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_CMD_VERSION,
  IPSET_CMD_QUIT,
  IPSET_CMD_MAX,
  IPSET_CMD_COMMIT = IPSET_CMD_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  IPSET_ATTR_UNSPEC,
  IPSET_ATTR_PROTOCOL,
- IPSET_ATTR_SETNAME,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_SETNAME,
  IPSET_ATTR_TYPENAME,
  IPSET_ATTR_SETNAME2 = IPSET_ATTR_TYPENAME,
  IPSET_ATTR_REVISION,
- IPSET_ATTR_FAMILY,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_FAMILY,
  IPSET_ATTR_FLAGS,
  IPSET_ATTR_DATA,
  IPSET_ATTR_ADT,
- IPSET_ATTR_LINENO,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_LINENO,
  IPSET_ATTR_PROTOCOL_MIN,
  IPSET_ATTR_REVISION_MIN = IPSET_ATTR_PROTOCOL_MIN,
  __IPSET_ATTR_CMD_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define IPSET_ATTR_CMD_MAX (__IPSET_ATTR_CMD_MAX - 1)
 enum {
  IPSET_ATTR_IP = IPSET_ATTR_UNSPEC + 1,
- IPSET_ATTR_IP_FROM = IPSET_ATTR_IP,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_IP_FROM = IPSET_ATTR_IP,
  IPSET_ATTR_IP_TO,
  IPSET_ATTR_CIDR,
  IPSET_ATTR_PORT,
- IPSET_ATTR_PORT_FROM = IPSET_ATTR_PORT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_PORT_FROM = IPSET_ATTR_PORT,
  IPSET_ATTR_PORT_TO,
  IPSET_ATTR_TIMEOUT,
  IPSET_ATTR_PROTO,
- IPSET_ATTR_CADT_FLAGS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_CADT_FLAGS,
  IPSET_ATTR_CADT_LINENO = IPSET_ATTR_LINENO,
  IPSET_ATTR_CADT_MAX = 16,
  IPSET_ATTR_GC,
- IPSET_ATTR_HASHSIZE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_HASHSIZE,
  IPSET_ATTR_MAXELEM,
  IPSET_ATTR_NETMASK,
  IPSET_ATTR_PROBES,
- IPSET_ATTR_RESIZE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_RESIZE,
  IPSET_ATTR_SIZE,
  IPSET_ATTR_ELEMENTS,
  IPSET_ATTR_REFERENCES,
- IPSET_ATTR_MEMSIZE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_MEMSIZE,
  __IPSET_ATTR_CREATE_MAX,
 };
 #define IPSET_ATTR_CREATE_MAX (__IPSET_ATTR_CREATE_MAX - 1)
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  IPSET_ATTR_ETHER = IPSET_ATTR_CADT_MAX + 1,
  IPSET_ATTR_NAME,
  IPSET_ATTR_NAMEREF,
- IPSET_ATTR_IP2,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_IP2,
  IPSET_ATTR_CIDR2,
  IPSET_ATTR_IP2_TO,
  IPSET_ATTR_IFACE,
- IPSET_ATTR_BYTES,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ATTR_BYTES,
  IPSET_ATTR_PACKETS,
+ IPSET_ATTR_COMMENT,
  __IPSET_ATTR_ADT_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define IPSET_ATTR_ADT_MAX (__IPSET_ATTR_ADT_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  IPSET_ATTR_IPADDR_IPV4 = IPSET_ATTR_UNSPEC + 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_ATTR_IPADDR_IPV6,
  __IPSET_ATTR_IPADDR_MAX,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define IPSET_ATTR_IPADDR_MAX (__IPSET_ATTR_IPADDR_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ipset_errno {
  IPSET_ERR_PRIVATE = 4096,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_ERR_PROTOCOL,
  IPSET_ERR_FIND_TYPE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_ERR_MAX_SETS,
  IPSET_ERR_BUSY,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_ERR_EXIST_SETNAME2,
  IPSET_ERR_TYPE_MISMATCH,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_ERR_EXIST,
  IPSET_ERR_INVALID_CIDR,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_ERR_INVALID_NETMASK,
  IPSET_ERR_INVALID_FAMILY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_ERR_TIMEOUT,
  IPSET_ERR_REFERENCED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_ERR_IPADDR_IPV4,
  IPSET_ERR_IPADDR_IPV6,
- IPSET_ERR_COUNTER,
- IPSET_ERR_TYPE_SPECIFIC = 4352,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ERR_COUNTER,
+ IPSET_ERR_COMMENT,
+ IPSET_ERR_TYPE_SPECIFIC = 4352,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ipset_cmd_flags {
  IPSET_FLAG_BIT_EXIST = 0,
  IPSET_FLAG_EXIST = (1 << IPSET_FLAG_BIT_EXIST),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_BIT_LIST_SETNAME = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_LIST_SETNAME = (1 << IPSET_FLAG_BIT_LIST_SETNAME),
  IPSET_FLAG_BIT_LIST_HEADER = 2,
  IPSET_FLAG_LIST_HEADER = (1 << IPSET_FLAG_BIT_LIST_HEADER),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE = 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_SKIP_COUNTER_UPDATE =
  (1 << IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE),
  IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE = 4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_SKIP_SUBCOUNTER_UPDATE =
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  (1 << IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE),
  IPSET_FLAG_BIT_MATCH_COUNTERS = 5,
  IPSET_FLAG_MATCH_COUNTERS = (1 << IPSET_FLAG_BIT_MATCH_COUNTERS),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_BIT_RETURN_NOMATCH = 7,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_RETURN_NOMATCH = (1 << IPSET_FLAG_BIT_RETURN_NOMATCH),
  IPSET_FLAG_CMD_MAX = 15,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ipset_cadt_flags {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_BIT_BEFORE = 0,
  IPSET_FLAG_BEFORE = (1 << IPSET_FLAG_BIT_BEFORE),
  IPSET_FLAG_BIT_PHYSDEV = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_PHYSDEV = (1 << IPSET_FLAG_BIT_PHYSDEV),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_BIT_NOMATCH = 2,
  IPSET_FLAG_NOMATCH = (1 << IPSET_FLAG_BIT_NOMATCH),
  IPSET_FLAG_BIT_WITH_COUNTERS = 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPSET_FLAG_WITH_COUNTERS = (1 << IPSET_FLAG_BIT_WITH_COUNTERS),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_FLAG_BIT_WITH_COMMENT = 4,
+ IPSET_FLAG_WITH_COMMENT = (1 << IPSET_FLAG_BIT_WITH_COMMENT),
  IPSET_FLAG_CADT_MAX = 15,
 };
-enum ipset_adt {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum ipset_adt {
  IPSET_ADD,
  IPSET_DEL,
  IPSET_TEST,
- IPSET_ADT_MAX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_ADT_MAX,
  IPSET_CREATE = IPSET_ADT_MAX,
  IPSET_CADT_MAX,
 };
-typedef __u16 ip_set_id_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef __u16 ip_set_id_t;
 #define IPSET_INVALID_ID 65535
 enum ip_set_dim {
  IPSET_DIM_ZERO = 0,
- IPSET_DIM_ONE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_DIM_ONE,
  IPSET_DIM_TWO,
  IPSET_DIM_THREE,
  IPSET_DIM_MAX = 6,
- IPSET_BIT_RETURN_NOMATCH = 7,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_BIT_RETURN_NOMATCH = 7,
 };
 enum ip_set_kopt {
  IPSET_INV_MATCH = (1 << IPSET_DIM_ZERO),
- IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
  IPSET_DIM_TWO_SRC = (1 << IPSET_DIM_TWO),
  IPSET_DIM_THREE_SRC = (1 << IPSET_DIM_THREE),
  IPSET_RETURN_NOMATCH = (1 << IPSET_BIT_RETURN_NOMATCH),
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  IPSET_COUNTER_NONE = 0,
  IPSET_COUNTER_EQ,
- IPSET_COUNTER_NE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSET_COUNTER_NE,
  IPSET_COUNTER_LT,
  IPSET_COUNTER_GT,
 };
-struct ip_set_counter_match {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ip_set_counter_match {
  __u8 op;
  __u64 value;
 };
-#define SO_IP_SET 83
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SO_IP_SET 83
 union ip_set_name_index {
  char name[IPSET_MAXNAMELEN];
  ip_set_id_t index;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define IP_SET_OP_GET_BYNAME 0x00000006
 struct ip_set_req_get_set {
  unsigned int op;
- unsigned int version;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int version;
  union ip_set_name_index set;
 };
 #define IP_SET_OP_GET_BYINDEX 0x00000007
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IP_SET_OP_GET_FNAME 0x00000008
+struct ip_set_req_get_set_family {
+ unsigned int op;
+ unsigned int version;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int family;
+ union ip_set_name_index set;
+};
 #define IP_SET_OP_VERSION 0x00000100
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ip_set_req_version {
diff --git a/libc/kernel/uapi/linux/netfilter/nf_conntrack_common.h b/libc/kernel/uapi/linux/netfilter/nf_conntrack_common.h
index 6c176ca..05e2d1f 100644
--- a/libc/kernel/uapi/linux/netfilter/nf_conntrack_common.h
+++ b/libc/kernel/uapi/linux/netfilter/nf_conntrack_common.h
@@ -31,58 +31,63 @@
  IP_CT_NUMBER = IP_CT_IS_REPLY * 2 - 1
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NF_CT_STATE_INVALID_BIT (1 << 0)
+#define NF_CT_STATE_BIT(ctinfo) (1 << ((ctinfo) % IP_CT_IS_REPLY + 1))
+#define NF_CT_STATE_UNTRACKED_BIT (1 << (IP_CT_NUMBER + 1))
 enum ip_conntrack_status {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_EXPECTED_BIT = 0,
  IPS_EXPECTED = (1 << IPS_EXPECTED_BIT),
  IPS_SEEN_REPLY_BIT = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_SEEN_REPLY = (1 << IPS_SEEN_REPLY_BIT),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_ASSURED_BIT = 2,
  IPS_ASSURED = (1 << IPS_ASSURED_BIT),
  IPS_CONFIRMED_BIT = 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_CONFIRMED = (1 << IPS_CONFIRMED_BIT),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_SRC_NAT_BIT = 4,
  IPS_SRC_NAT = (1 << IPS_SRC_NAT_BIT),
  IPS_DST_NAT_BIT = 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_DST_NAT = (1 << IPS_DST_NAT_BIT),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_NAT_MASK = (IPS_DST_NAT | IPS_SRC_NAT),
  IPS_SEQ_ADJUST_BIT = 6,
  IPS_SEQ_ADJUST = (1 << IPS_SEQ_ADJUST_BIT),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_SRC_NAT_DONE_BIT = 7,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_SRC_NAT_DONE = (1 << IPS_SRC_NAT_DONE_BIT),
  IPS_DST_NAT_DONE_BIT = 8,
  IPS_DST_NAT_DONE = (1 << IPS_DST_NAT_DONE_BIT),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_NAT_DONE_MASK = (IPS_DST_NAT_DONE | IPS_SRC_NAT_DONE),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_DYING_BIT = 9,
  IPS_DYING = (1 << IPS_DYING_BIT),
  IPS_FIXED_TIMEOUT_BIT = 10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_FIXED_TIMEOUT = (1 << IPS_FIXED_TIMEOUT_BIT),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_TEMPLATE_BIT = 11,
  IPS_TEMPLATE = (1 << IPS_TEMPLATE_BIT),
  IPS_UNTRACKED_BIT = 12,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_UNTRACKED = (1 << IPS_UNTRACKED_BIT),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPS_HELPER_BIT = 13,
  IPS_HELPER = (1 << IPS_HELPER_BIT),
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ip_conntrack_events {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPCT_NEW,
  IPCT_RELATED,
  IPCT_DESTROY,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPCT_REPLY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPCT_ASSURED,
  IPCT_PROTOINFO,
  IPCT_HELPER,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IPCT_MARK,
- IPCT_NATSEQADJ,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPCT_SEQADJ,
+ IPCT_NATSEQADJ = IPCT_SEQADJ,
  IPCT_SECMARK,
  IPCT_LABEL,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter/nf_nat.h b/libc/kernel/uapi/linux/netfilter/nf_nat.h
index 320af8a..b399888 100644
--- a/libc/kernel/uapi/linux/netfilter/nf_nat.h
+++ b/libc/kernel/uapi/linux/netfilter/nf_nat.h
@@ -21,31 +21,34 @@
 #include <linux/netfilter.h>
 #include <linux/netfilter/nf_conntrack_tuple_common.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define NF_NAT_RANGE_MAP_IPS 1
-#define NF_NAT_RANGE_PROTO_SPECIFIED 2
-#define NF_NAT_RANGE_PROTO_RANDOM 4
-#define NF_NAT_RANGE_PERSISTENT 8
+#define NF_NAT_RANGE_MAP_IPS (1 << 0)
+#define NF_NAT_RANGE_PROTO_SPECIFIED (1 << 1)
+#define NF_NAT_RANGE_PROTO_RANDOM (1 << 2)
+#define NF_NAT_RANGE_PERSISTENT (1 << 3)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NF_NAT_RANGE_PROTO_RANDOM_FULLY (1 << 4)
+#define NF_NAT_RANGE_PROTO_RANDOM_ALL   (NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PROTO_RANDOM_FULLY)
 struct nf_nat_ipv4_range {
  unsigned int flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __be32 min_ip;
  __be32 max_ip;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union nf_conntrack_man_proto min;
  union nf_conntrack_man_proto max;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct nf_nat_ipv4_multi_range_compat {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int rangesize;
  struct nf_nat_ipv4_range range[1];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct nf_nat_range {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int flags;
  union nf_inet_addr min_addr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union nf_inet_addr max_addr;
  union nf_conntrack_man_proto min_proto;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union nf_conntrack_man_proto max_proto;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/netfilter/nf_tables.h b/libc/kernel/uapi/linux/netfilter/nf_tables.h
new file mode 100644
index 0000000..34632dd
--- /dev/null
+++ b/libc/kernel/uapi/linux/netfilter/nf_tables.h
@@ -0,0 +1,454 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _LINUX_NF_TABLES_H
+#define _LINUX_NF_TABLES_H
+#define NFT_CHAIN_MAXNAMELEN 32
+enum nft_registers {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_REG_VERDICT,
+ NFT_REG_1,
+ NFT_REG_2,
+ NFT_REG_3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_REG_4,
+ __NFT_REG_MAX
+};
+#define NFT_REG_MAX (__NFT_REG_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_verdicts {
+ NFT_CONTINUE = -1,
+ NFT_BREAK = -2,
+ NFT_JUMP = -3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_GOTO = -4,
+ NFT_RETURN = -5,
+};
+enum nf_tables_msg_types {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_MSG_NEWTABLE,
+ NFT_MSG_GETTABLE,
+ NFT_MSG_DELTABLE,
+ NFT_MSG_NEWCHAIN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_MSG_GETCHAIN,
+ NFT_MSG_DELCHAIN,
+ NFT_MSG_NEWRULE,
+ NFT_MSG_GETRULE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_MSG_DELRULE,
+ NFT_MSG_NEWSET,
+ NFT_MSG_GETSET,
+ NFT_MSG_DELSET,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_MSG_NEWSETELEM,
+ NFT_MSG_GETSETELEM,
+ NFT_MSG_DELSETELEM,
+ NFT_MSG_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum nft_list_attributes {
+ NFTA_LIST_UNPEC,
+ NFTA_LIST_ELEM,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NFTA_LIST_MAX
+};
+#define NFTA_LIST_MAX (__NFTA_LIST_MAX - 1)
+enum nft_hook_attributes {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_HOOK_UNSPEC,
+ NFTA_HOOK_HOOKNUM,
+ NFTA_HOOK_PRIORITY,
+ __NFTA_HOOK_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_HOOK_MAX (__NFTA_HOOK_MAX - 1)
+enum nft_table_flags {
+ NFT_TABLE_F_DORMANT = 0x1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum nft_table_attributes {
+ NFTA_TABLE_UNSPEC,
+ NFTA_TABLE_NAME,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_TABLE_FLAGS,
+ NFTA_TABLE_USE,
+ __NFTA_TABLE_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFTA_TABLE_MAX (__NFTA_TABLE_MAX - 1)
+enum nft_chain_attributes {
+ NFTA_CHAIN_UNSPEC,
+ NFTA_CHAIN_TABLE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_CHAIN_HANDLE,
+ NFTA_CHAIN_NAME,
+ NFTA_CHAIN_HOOK,
+ NFTA_CHAIN_POLICY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_CHAIN_USE,
+ NFTA_CHAIN_TYPE,
+ NFTA_CHAIN_COUNTERS,
+ __NFTA_CHAIN_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_CHAIN_MAX (__NFTA_CHAIN_MAX - 1)
+enum nft_rule_attributes {
+ NFTA_RULE_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_RULE_TABLE,
+ NFTA_RULE_CHAIN,
+ NFTA_RULE_HANDLE,
+ NFTA_RULE_EXPRESSIONS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_RULE_COMPAT,
+ NFTA_RULE_POSITION,
+ __NFTA_RULE_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFTA_RULE_MAX (__NFTA_RULE_MAX - 1)
+enum nft_rule_compat_flags {
+ NFT_RULE_COMPAT_F_INV = (1 << 1),
+ NFT_RULE_COMPAT_F_MASK = NFT_RULE_COMPAT_F_INV,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum nft_rule_compat_attributes {
+ NFTA_RULE_COMPAT_UNSPEC,
+ NFTA_RULE_COMPAT_PROTO,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_RULE_COMPAT_FLAGS,
+ __NFTA_RULE_COMPAT_MAX
+};
+#define NFTA_RULE_COMPAT_MAX (__NFTA_RULE_COMPAT_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_set_flags {
+ NFT_SET_ANONYMOUS = 0x1,
+ NFT_SET_CONSTANT = 0x2,
+ NFT_SET_INTERVAL = 0x4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_SET_MAP = 0x8,
+};
+enum nft_set_attributes {
+ NFTA_SET_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_SET_TABLE,
+ NFTA_SET_NAME,
+ NFTA_SET_FLAGS,
+ NFTA_SET_KEY_TYPE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_SET_KEY_LEN,
+ NFTA_SET_DATA_TYPE,
+ NFTA_SET_DATA_LEN,
+ __NFTA_SET_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_SET_MAX (__NFTA_SET_MAX - 1)
+enum nft_set_elem_flags {
+ NFT_SET_ELEM_INTERVAL_END = 0x1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum nft_set_elem_attributes {
+ NFTA_SET_ELEM_UNSPEC,
+ NFTA_SET_ELEM_KEY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_SET_ELEM_DATA,
+ NFTA_SET_ELEM_FLAGS,
+ __NFTA_SET_ELEM_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFTA_SET_ELEM_MAX (__NFTA_SET_ELEM_MAX - 1)
+enum nft_set_elem_list_attributes {
+ NFTA_SET_ELEM_LIST_UNSPEC,
+ NFTA_SET_ELEM_LIST_TABLE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_SET_ELEM_LIST_SET,
+ NFTA_SET_ELEM_LIST_ELEMENTS,
+ __NFTA_SET_ELEM_LIST_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFTA_SET_ELEM_LIST_MAX (__NFTA_SET_ELEM_LIST_MAX - 1)
+enum nft_data_types {
+ NFT_DATA_VALUE,
+ NFT_DATA_VERDICT = 0xffffff00U,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFT_DATA_RESERVED_MASK 0xffffff00U
+enum nft_data_attributes {
+ NFTA_DATA_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_DATA_VALUE,
+ NFTA_DATA_VERDICT,
+ __NFTA_DATA_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFTA_DATA_MAX (__NFTA_DATA_MAX - 1)
+enum nft_verdict_attributes {
+ NFTA_VERDICT_UNSPEC,
+ NFTA_VERDICT_CODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_VERDICT_CHAIN,
+ __NFTA_VERDICT_MAX
+};
+#define NFTA_VERDICT_MAX (__NFTA_VERDICT_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_expr_attributes {
+ NFTA_EXPR_UNSPEC,
+ NFTA_EXPR_NAME,
+ NFTA_EXPR_DATA,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NFTA_EXPR_MAX
+};
+#define NFTA_EXPR_MAX (__NFTA_EXPR_MAX - 1)
+enum nft_immediate_attributes {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_IMMEDIATE_UNSPEC,
+ NFTA_IMMEDIATE_DREG,
+ NFTA_IMMEDIATE_DATA,
+ __NFTA_IMMEDIATE_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_IMMEDIATE_MAX (__NFTA_IMMEDIATE_MAX - 1)
+enum nft_bitwise_attributes {
+ NFTA_BITWISE_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_BITWISE_SREG,
+ NFTA_BITWISE_DREG,
+ NFTA_BITWISE_LEN,
+ NFTA_BITWISE_MASK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_BITWISE_XOR,
+ __NFTA_BITWISE_MAX
+};
+#define NFTA_BITWISE_MAX (__NFTA_BITWISE_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_byteorder_ops {
+ NFT_BYTEORDER_NTOH,
+ NFT_BYTEORDER_HTON,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_byteorder_attributes {
+ NFTA_BYTEORDER_UNSPEC,
+ NFTA_BYTEORDER_SREG,
+ NFTA_BYTEORDER_DREG,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_BYTEORDER_OP,
+ NFTA_BYTEORDER_LEN,
+ NFTA_BYTEORDER_SIZE,
+ __NFTA_BYTEORDER_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_BYTEORDER_MAX (__NFTA_BYTEORDER_MAX - 1)
+enum nft_cmp_ops {
+ NFT_CMP_EQ,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_CMP_NEQ,
+ NFT_CMP_LT,
+ NFT_CMP_LTE,
+ NFT_CMP_GT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_CMP_GTE,
+};
+enum nft_cmp_attributes {
+ NFTA_CMP_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_CMP_SREG,
+ NFTA_CMP_OP,
+ NFTA_CMP_DATA,
+ __NFTA_CMP_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_CMP_MAX (__NFTA_CMP_MAX - 1)
+enum nft_lookup_attributes {
+ NFTA_LOOKUP_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_LOOKUP_SET,
+ NFTA_LOOKUP_SREG,
+ NFTA_LOOKUP_DREG,
+ __NFTA_LOOKUP_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_LOOKUP_MAX (__NFTA_LOOKUP_MAX - 1)
+enum nft_payload_bases {
+ NFT_PAYLOAD_LL_HEADER,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_PAYLOAD_NETWORK_HEADER,
+ NFT_PAYLOAD_TRANSPORT_HEADER,
+};
+enum nft_payload_attributes {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_PAYLOAD_UNSPEC,
+ NFTA_PAYLOAD_DREG,
+ NFTA_PAYLOAD_BASE,
+ NFTA_PAYLOAD_OFFSET,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_PAYLOAD_LEN,
+ __NFTA_PAYLOAD_MAX
+};
+#define NFTA_PAYLOAD_MAX (__NFTA_PAYLOAD_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_exthdr_attributes {
+ NFTA_EXTHDR_UNSPEC,
+ NFTA_EXTHDR_DREG,
+ NFTA_EXTHDR_TYPE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_EXTHDR_OFFSET,
+ NFTA_EXTHDR_LEN,
+ __NFTA_EXTHDR_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFTA_EXTHDR_MAX (__NFTA_EXTHDR_MAX - 1)
+enum nft_meta_keys {
+ NFT_META_LEN,
+ NFT_META_PROTOCOL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_META_PRIORITY,
+ NFT_META_MARK,
+ NFT_META_IIF,
+ NFT_META_OIF,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_META_IIFNAME,
+ NFT_META_OIFNAME,
+ NFT_META_IIFTYPE,
+ NFT_META_OIFTYPE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_META_SKUID,
+ NFT_META_SKGID,
+ NFT_META_NFTRACE,
+ NFT_META_RTCLASSID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_META_SECMARK,
+ NFT_META_NFPROTO,
+ NFT_META_L4PROTO,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_meta_attributes {
+ NFTA_META_UNSPEC,
+ NFTA_META_DREG,
+ NFTA_META_KEY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_META_SREG,
+ __NFTA_META_MAX
+};
+#define NFTA_META_MAX (__NFTA_META_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_ct_keys {
+ NFT_CT_STATE,
+ NFT_CT_DIRECTION,
+ NFT_CT_STATUS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_CT_MARK,
+ NFT_CT_SECMARK,
+ NFT_CT_EXPIRATION,
+ NFT_CT_HELPER,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_CT_L3PROTOCOL,
+ NFT_CT_SRC,
+ NFT_CT_DST,
+ NFT_CT_PROTOCOL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_CT_PROTO_SRC,
+ NFT_CT_PROTO_DST,
+};
+enum nft_ct_attributes {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_CT_UNSPEC,
+ NFTA_CT_DREG,
+ NFTA_CT_KEY,
+ NFTA_CT_DIRECTION,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_CT_SREG,
+ __NFTA_CT_MAX
+};
+#define NFTA_CT_MAX (__NFTA_CT_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nft_limit_attributes {
+ NFTA_LIMIT_UNSPEC,
+ NFTA_LIMIT_RATE,
+ NFTA_LIMIT_UNIT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NFTA_LIMIT_MAX
+};
+#define NFTA_LIMIT_MAX (__NFTA_LIMIT_MAX - 1)
+enum nft_counter_attributes {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_COUNTER_UNSPEC,
+ NFTA_COUNTER_BYTES,
+ NFTA_COUNTER_PACKETS,
+ __NFTA_COUNTER_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_COUNTER_MAX (__NFTA_COUNTER_MAX - 1)
+enum nft_log_attributes {
+ NFTA_LOG_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_LOG_GROUP,
+ NFTA_LOG_PREFIX,
+ NFTA_LOG_SNAPLEN,
+ NFTA_LOG_QTHRESHOLD,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NFTA_LOG_MAX
+};
+#define NFTA_LOG_MAX (__NFTA_LOG_MAX - 1)
+enum nft_queue_attributes {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_QUEUE_UNSPEC,
+ NFTA_QUEUE_NUM,
+ NFTA_QUEUE_TOTAL,
+ NFTA_QUEUE_FLAGS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NFTA_QUEUE_MAX
+};
+#define NFTA_QUEUE_MAX (__NFTA_QUEUE_MAX - 1)
+#define NFT_QUEUE_FLAG_BYPASS 0x01
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFT_QUEUE_FLAG_CPU_FANOUT 0x02
+#define NFT_QUEUE_FLAG_MASK 0x03
+enum nft_reject_types {
+ NFT_REJECT_ICMP_UNREACH,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFT_REJECT_TCP_RST,
+};
+enum nft_reject_attributes {
+ NFTA_REJECT_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_REJECT_TYPE,
+ NFTA_REJECT_ICMP_CODE,
+ __NFTA_REJECT_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFTA_REJECT_MAX (__NFTA_REJECT_MAX - 1)
+enum nft_nat_types {
+ NFT_NAT_SNAT,
+ NFT_NAT_DNAT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum nft_nat_attributes {
+ NFTA_NAT_UNSPEC,
+ NFTA_NAT_TYPE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_NAT_FAMILY,
+ NFTA_NAT_REG_ADDR_MIN,
+ NFTA_NAT_REG_ADDR_MAX,
+ NFTA_NAT_REG_PROTO_MIN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_NAT_REG_PROTO_MAX,
+ __NFTA_NAT_MAX
+};
+#define NFTA_NAT_MAX (__NFTA_NAT_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/netfilter/nf_tables_compat.h b/libc/kernel/uapi/linux/netfilter/nf_tables_compat.h
new file mode 100644
index 0000000..3367dae
--- /dev/null
+++ b/libc/kernel/uapi/linux/netfilter/nf_tables_compat.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _NFT_COMPAT_NFNETLINK_H_
+#define _NFT_COMPAT_NFNETLINK_H_
+enum nft_target_attributes {
+ NFTA_TARGET_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_TARGET_NAME,
+ NFTA_TARGET_REV,
+ NFTA_TARGET_INFO,
+ __NFTA_TARGET_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_TARGET_MAX (__NFTA_TARGET_MAX - 1)
+enum nft_match_attributes {
+ NFTA_MATCH_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_MATCH_NAME,
+ NFTA_MATCH_REV,
+ NFTA_MATCH_INFO,
+ __NFTA_MATCH_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NFTA_MATCH_MAX (__NFTA_MATCH_MAX - 1)
+#define NFT_COMPAT_NAME_MAX 32
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFNL_MSG_COMPAT_GET,
+ NFNL_MSG_COMPAT_MAX
+};
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFTA_COMPAT_UNSPEC = 0,
+ NFTA_COMPAT_NAME,
+ NFTA_COMPAT_REV,
+ NFTA_COMPAT_TYPE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NFTA_COMPAT_MAX,
+};
+#define NFTA_COMPAT_MAX (__NFTA_COMPAT_MAX - 1)
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter/nfnetlink.h b/libc/kernel/uapi/linux/netfilter/nfnetlink.h
index a5c3f5c..c04f62c 100644
--- a/libc/kernel/uapi/linux/netfilter/nfnetlink.h
+++ b/libc/kernel/uapi/linux/netfilter/nfnetlink.h
@@ -39,32 +39,40 @@
 #define NFNLGRP_CONNTRACK_EXP_UPDATE NFNLGRP_CONNTRACK_EXP_UPDATE
  NFNLGRP_CONNTRACK_EXP_DESTROY,
 #define NFNLGRP_CONNTRACK_EXP_DESTROY NFNLGRP_CONNTRACK_EXP_DESTROY
- __NFNLGRP_MAX,
+ NFNLGRP_NFTABLES,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFNLGRP_NFTABLES NFNLGRP_NFTABLES
+ __NFNLGRP_MAX,
 };
 #define NFNLGRP_MAX (__NFNLGRP_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct nfgenmsg {
  __u8 nfgen_family;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 version;
  __be16 res_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define NFNETLINK_V0 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFNL_SUBSYS_ID(x) ((x & 0xff00) >> 8)
 #define NFNL_MSG_TYPE(x) (x & 0x00ff)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFNL_SUBSYS_NONE 0
 #define NFNL_SUBSYS_CTNETLINK 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFNL_SUBSYS_CTNETLINK_EXP 2
 #define NFNL_SUBSYS_QUEUE 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFNL_SUBSYS_ULOG 4
 #define NFNL_SUBSYS_OSF 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFNL_SUBSYS_IPSET 6
 #define NFNL_SUBSYS_ACCT 7
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFNL_SUBSYS_CTNETLINK_TIMEOUT 8
 #define NFNL_SUBSYS_CTHELPER 9
+#define NFNL_SUBSYS_NFTABLES 10
+#define NFNL_SUBSYS_NFT_COMPAT 11
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define NFNL_SUBSYS_COUNT 10
+#define NFNL_SUBSYS_COUNT 12
+#define NFNL_MSG_BATCH_BEGIN NLMSG_MIN_TYPE
+#define NFNL_MSG_BATCH_END NLMSG_MIN_TYPE+1
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter/nfnetlink_conntrack.h b/libc/kernel/uapi/linux/netfilter/nfnetlink_conntrack.h
index 6c5db5a..2b22c4f 100644
--- a/libc/kernel/uapi/linux/netfilter/nfnetlink_conntrack.h
+++ b/libc/kernel/uapi/linux/netfilter/nfnetlink_conntrack.h
@@ -63,238 +63,251 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_NAT_DST,
  CTA_TUPLE_MASTER,
- CTA_NAT_SEQ_ADJ_ORIG,
- CTA_NAT_SEQ_ADJ_REPLY,
+ CTA_SEQ_ADJ_ORIG,
+ CTA_NAT_SEQ_ADJ_ORIG = CTA_SEQ_ADJ_ORIG,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ CTA_SEQ_ADJ_REPLY,
+ CTA_NAT_SEQ_ADJ_REPLY = CTA_SEQ_ADJ_REPLY,
  CTA_SECMARK,
  CTA_ZONE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_SECCTX,
  CTA_TIMESTAMP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_MARK_MASK,
  CTA_LABELS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_LABELS_MASK,
  __CTA_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_MAX (__CTA_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_tuple {
  CTA_TUPLE_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TUPLE_IP,
  CTA_TUPLE_PROTO,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TUPLE_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TUPLE_MAX (__CTA_TUPLE_MAX - 1)
 enum ctattr_ip {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_IP_UNSPEC,
  CTA_IP_V4_SRC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_IP_V4_DST,
  CTA_IP_V6_SRC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_IP_V6_DST,
  __CTA_IP_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_IP_MAX (__CTA_IP_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_l4proto {
  CTA_PROTO_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTO_NUM,
  CTA_PROTO_SRC_PORT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTO_DST_PORT,
  CTA_PROTO_ICMP_ID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTO_ICMP_TYPE,
  CTA_PROTO_ICMP_CODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTO_ICMPV6_ID,
  CTA_PROTO_ICMPV6_TYPE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTO_ICMPV6_CODE,
  __CTA_PROTO_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_PROTO_MAX (__CTA_PROTO_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_protoinfo {
  CTA_PROTOINFO_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_TCP,
  CTA_PROTOINFO_DCCP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_SCTP,
  __CTA_PROTOINFO_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_PROTOINFO_MAX (__CTA_PROTOINFO_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_protoinfo_tcp {
  CTA_PROTOINFO_TCP_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_TCP_STATE,
  CTA_PROTOINFO_TCP_WSCALE_ORIGINAL,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_TCP_WSCALE_REPLY,
  CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_TCP_FLAGS_REPLY,
  __CTA_PROTOINFO_TCP_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_PROTOINFO_TCP_MAX (__CTA_PROTOINFO_TCP_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_protoinfo_dccp {
  CTA_PROTOINFO_DCCP_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_DCCP_STATE,
  CTA_PROTOINFO_DCCP_ROLE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
  __CTA_PROTOINFO_DCCP_MAX,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_PROTOINFO_DCCP_MAX (__CTA_PROTOINFO_DCCP_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_protoinfo_sctp {
  CTA_PROTOINFO_SCTP_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_SCTP_STATE,
  CTA_PROTOINFO_SCTP_VTAG_ORIGINAL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTOINFO_SCTP_VTAG_REPLY,
  __CTA_PROTOINFO_SCTP_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_PROTOINFO_SCTP_MAX (__CTA_PROTOINFO_SCTP_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_counters {
  CTA_COUNTERS_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_COUNTERS_PACKETS,
  CTA_COUNTERS_BYTES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_COUNTERS32_PACKETS,
  CTA_COUNTERS32_BYTES,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_COUNTERS_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_COUNTERS_MAX (__CTA_COUNTERS_MAX - 1)
 enum ctattr_tstamp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMESTAMP_UNSPEC,
  CTA_TIMESTAMP_START,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMESTAMP_STOP,
  __CTA_TIMESTAMP_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_TIMESTAMP_MAX (__CTA_TIMESTAMP_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_nat {
  CTA_NAT_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_NAT_V4_MINIP,
 #define CTA_NAT_MINIP CTA_NAT_V4_MINIP
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_NAT_V4_MAXIP,
 #define CTA_NAT_MAXIP CTA_NAT_V4_MAXIP
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_NAT_PROTO,
  CTA_NAT_V6_MINIP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_NAT_V6_MAXIP,
  __CTA_NAT_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_NAT_MAX (__CTA_NAT_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_protonat {
  CTA_PROTONAT_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_PROTONAT_PORT_MIN,
  CTA_PROTONAT_PORT_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_PROTONAT_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_PROTONAT_MAX (__CTA_PROTONAT_MAX - 1)
+enum ctattr_seqadj {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ CTA_SEQADJ_UNSPEC,
+ CTA_SEQADJ_CORRECTION_POS,
+ CTA_SEQADJ_OFFSET_BEFORE,
+ CTA_SEQADJ_OFFSET_AFTER,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __CTA_SEQADJ_MAX
+};
+#define CTA_SEQADJ_MAX (__CTA_SEQADJ_MAX - 1)
 enum ctattr_natseq {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_NAT_SEQ_UNSPEC,
  CTA_NAT_SEQ_CORRECTION_POS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_NAT_SEQ_OFFSET_BEFORE,
  CTA_NAT_SEQ_OFFSET_AFTER,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_NAT_SEQ_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_NAT_SEQ_MAX (__CTA_NAT_SEQ_MAX - 1)
 enum ctattr_expect {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_EXPECT_UNSPEC,
  CTA_EXPECT_MASTER,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_EXPECT_TUPLE,
  CTA_EXPECT_MASK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_EXPECT_TIMEOUT,
  CTA_EXPECT_ID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_EXPECT_HELP_NAME,
  CTA_EXPECT_ZONE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_EXPECT_FLAGS,
  CTA_EXPECT_CLASS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_EXPECT_NAT,
  CTA_EXPECT_FN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_EXPECT_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_EXPECT_MAX (__CTA_EXPECT_MAX - 1)
 enum ctattr_expect_nat {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_EXPECT_NAT_UNSPEC,
  CTA_EXPECT_NAT_DIR,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_EXPECT_NAT_TUPLE,
  __CTA_EXPECT_NAT_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_EXPECT_NAT_MAX (__CTA_EXPECT_NAT_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_help {
  CTA_HELP_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_HELP_NAME,
  CTA_HELP_INFO,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_HELP_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_HELP_MAX (__CTA_HELP_MAX - 1)
 enum ctattr_secctx {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_SECCTX_UNSPEC,
  CTA_SECCTX_NAME,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_SECCTX_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_SECCTX_MAX (__CTA_SECCTX_MAX - 1)
 enum ctattr_stats_cpu {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_UNSPEC,
  CTA_STATS_SEARCHED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_FOUND,
  CTA_STATS_NEW,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_INVALID,
  CTA_STATS_IGNORE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_DELETE,
  CTA_STATS_DELETE_LIST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_INSERT,
  CTA_STATS_INSERT_FAILED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_DROP,
  CTA_STATS_EARLY_DROP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_ERROR,
  CTA_STATS_SEARCH_RESTART,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_STATS_MAX,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_STATS_MAX (__CTA_STATS_MAX - 1)
 enum ctattr_stats_global {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_GLOBAL_UNSPEC,
  CTA_STATS_GLOBAL_ENTRIES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_STATS_GLOBAL_MAX,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_STATS_GLOBAL_MAX (__CTA_STATS_GLOBAL_MAX - 1)
 enum ctattr_expect_stats {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_EXP_UNSPEC,
  CTA_STATS_EXP_NEW,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_STATS_EXP_CREATE,
  CTA_STATS_EXP_DELETE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_STATS_EXP_MAX,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_STATS_EXP_MAX (__CTA_STATS_EXP_MAX - 1)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter/nfnetlink_cttimeout.h b/libc/kernel/uapi/linux/netfilter/nfnetlink_cttimeout.h
index 1fe4a55..8925799 100644
--- a/libc/kernel/uapi/linux/netfilter/nfnetlink_cttimeout.h
+++ b/libc/kernel/uapi/linux/netfilter/nfnetlink_cttimeout.h
@@ -24,120 +24,122 @@
  IPCTNL_MSG_TIMEOUT_NEW,
  IPCTNL_MSG_TIMEOUT_GET,
  IPCTNL_MSG_TIMEOUT_DELETE,
- IPCTNL_MSG_TIMEOUT_MAX
+ IPCTNL_MSG_TIMEOUT_DEFAULT_SET,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPCTNL_MSG_TIMEOUT_DEFAULT_GET,
+ IPCTNL_MSG_TIMEOUT_MAX
 };
 enum ctattr_timeout {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_UNSPEC,
  CTA_TIMEOUT_NAME,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_L3PROTO,
  CTA_TIMEOUT_L4PROTO,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_DATA,
  CTA_TIMEOUT_USE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TIMEOUT_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TIMEOUT_MAX (__CTA_TIMEOUT_MAX - 1)
 enum ctattr_timeout_generic {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_GENERIC_UNSPEC,
  CTA_TIMEOUT_GENERIC_TIMEOUT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TIMEOUT_GENERIC_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TIMEOUT_GENERIC_MAX (__CTA_TIMEOUT_GENERIC_MAX - 1)
 enum ctattr_timeout_tcp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_TCP_UNSPEC,
  CTA_TIMEOUT_TCP_SYN_SENT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_TCP_SYN_RECV,
  CTA_TIMEOUT_TCP_ESTABLISHED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_TCP_FIN_WAIT,
  CTA_TIMEOUT_TCP_CLOSE_WAIT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_TCP_LAST_ACK,
  CTA_TIMEOUT_TCP_TIME_WAIT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_TCP_CLOSE,
  CTA_TIMEOUT_TCP_SYN_SENT2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_TCP_RETRANS,
  CTA_TIMEOUT_TCP_UNACK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TIMEOUT_TCP_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TIMEOUT_TCP_MAX (__CTA_TIMEOUT_TCP_MAX - 1)
 enum ctattr_timeout_udp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_UDP_UNSPEC,
  CTA_TIMEOUT_UDP_UNREPLIED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_UDP_REPLIED,
  __CTA_TIMEOUT_UDP_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_TIMEOUT_UDP_MAX (__CTA_TIMEOUT_UDP_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ctattr_timeout_udplite {
  CTA_TIMEOUT_UDPLITE_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_UDPLITE_UNREPLIED,
  CTA_TIMEOUT_UDPLITE_REPLIED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TIMEOUT_UDPLITE_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TIMEOUT_UDPLITE_MAX (__CTA_TIMEOUT_UDPLITE_MAX - 1)
 enum ctattr_timeout_icmp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_ICMP_UNSPEC,
  CTA_TIMEOUT_ICMP_TIMEOUT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TIMEOUT_ICMP_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TIMEOUT_ICMP_MAX (__CTA_TIMEOUT_ICMP_MAX - 1)
 enum ctattr_timeout_dccp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_DCCP_UNSPEC,
  CTA_TIMEOUT_DCCP_REQUEST,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_DCCP_RESPOND,
  CTA_TIMEOUT_DCCP_PARTOPEN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_DCCP_OPEN,
  CTA_TIMEOUT_DCCP_CLOSEREQ,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_DCCP_CLOSING,
  CTA_TIMEOUT_DCCP_TIMEWAIT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TIMEOUT_DCCP_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TIMEOUT_DCCP_MAX (__CTA_TIMEOUT_DCCP_MAX - 1)
 enum ctattr_timeout_sctp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_SCTP_UNSPEC,
  CTA_TIMEOUT_SCTP_CLOSED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_SCTP_COOKIE_WAIT,
  CTA_TIMEOUT_SCTP_COOKIE_ECHOED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_SCTP_ESTABLISHED,
  CTA_TIMEOUT_SCTP_SHUTDOWN_SENT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_SCTP_SHUTDOWN_RECD,
  CTA_TIMEOUT_SCTP_SHUTDOWN_ACK_SENT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TIMEOUT_SCTP_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TIMEOUT_SCTP_MAX (__CTA_TIMEOUT_SCTP_MAX - 1)
 enum ctattr_timeout_icmpv6 {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_ICMPV6_UNSPEC,
  CTA_TIMEOUT_ICMPV6_TIMEOUT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __CTA_TIMEOUT_ICMPV6_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTA_TIMEOUT_ICMPV6_MAX (__CTA_TIMEOUT_ICMPV6_MAX - 1)
 enum ctattr_timeout_gre {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_GRE_UNSPEC,
  CTA_TIMEOUT_GRE_UNREPLIED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  CTA_TIMEOUT_GRE_REPLIED,
  __CTA_TIMEOUT_GRE_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define CTA_TIMEOUT_GRE_MAX (__CTA_TIMEOUT_GRE_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define CTNL_TIMEOUT_NAME_MAX 32
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter/nfnetlink_queue.h b/libc/kernel/uapi/linux/netfilter/nfnetlink_queue.h
index 272d53f..816e344 100644
--- a/libc/kernel/uapi/linux/netfilter/nfnetlink_queue.h
+++ b/libc/kernel/uapi/linux/netfilter/nfnetlink_queue.h
@@ -67,59 +67,65 @@
  NFQA_CAP_LEN,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFQA_SKB_INFO,
+ NFQA_EXP,
+ NFQA_UID,
+ NFQA_GID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NFQA_MAX
 };
 #define NFQA_MAX (__NFQA_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct nfqnl_msg_verdict_hdr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __be32 verdict;
  __be32 id;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nfqnl_msg_config_cmds {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFQNL_CFG_CMD_NONE,
  NFQNL_CFG_CMD_BIND,
  NFQNL_CFG_CMD_UNBIND,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFQNL_CFG_CMD_PF_BIND,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFQNL_CFG_CMD_PF_UNBIND,
 };
 struct nfqnl_msg_config_cmd {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 command;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 _pad;
  __be16 pf;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nfqnl_config_mode {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFQNL_COPY_NONE,
  NFQNL_COPY_META,
  NFQNL_COPY_PACKET,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct nfqnl_msg_config_params {
  __be32 copy_range;
  __u8 copy_mode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nfqnl_attr_config {
  NFQA_CFG_UNSPEC,
  NFQA_CFG_CMD,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFQA_CFG_PARAMS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFQA_CFG_QUEUE_MAXLEN,
  NFQA_CFG_MASK,
  NFQA_CFG_FLAGS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NFQA_CFG_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define NFQA_CFG_MAX (__NFQA_CFG_MAX-1)
 #define NFQA_CFG_F_FAIL_OPEN (1 << 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFQA_CFG_F_CONNTRACK (1 << 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFQA_CFG_F_GSO (1 << 2)
-#define NFQA_CFG_F_MAX (1 << 3)
+#define NFQA_CFG_F_UID_GID (1 << 3)
+#define NFQA_CFG_F_MAX (1 << 4)
 #define NFQA_SKB_CSUMNOTREADY (1 << 0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFQA_SKB_GSO (1 << 1)
+#define NFQA_SKB_CSUM_NOTVERIFIED (1 << 2)
 #endif
diff --git a/libc/kernel/uapi/linux/netfilter/xt_HMARK.h b/libc/kernel/uapi/linux/netfilter/xt_HMARK.h
new file mode 100644
index 0000000..add0302
--- /dev/null
+++ b/libc/kernel/uapi/linux/netfilter/xt_HMARK.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef XT_HMARK_H_
+#define XT_HMARK_H_
+#include <linux/types.h>
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ XT_HMARK_SADDR_MASK,
+ XT_HMARK_DADDR_MASK,
+ XT_HMARK_SPI,
+ XT_HMARK_SPI_MASK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ XT_HMARK_SPORT,
+ XT_HMARK_DPORT,
+ XT_HMARK_SPORT_MASK,
+ XT_HMARK_DPORT_MASK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ XT_HMARK_PROTO_MASK,
+ XT_HMARK_RND,
+ XT_HMARK_MODULUS,
+ XT_HMARK_OFFSET,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ XT_HMARK_CT,
+ XT_HMARK_METHOD_L3,
+ XT_HMARK_METHOD_L3_4,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define XT_HMARK_FLAG(flag) (1 << flag)
+union hmark_ports {
+ struct {
+ __u16 src;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 dst;
+ } p16;
+ struct {
+ __be16 src;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 dst;
+ } b16;
+ __u32 v32;
+ __be32 b32;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct xt_hmark_info {
+ union nf_inet_addr src_mask;
+ union nf_inet_addr dst_mask;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union hmark_ports port_mask;
+ union hmark_ports port_set;
+ __u32 flags;
+ __u16 proto_mask;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 hashrnd;
+ __u32 hmodulus;
+ __u32 hoffset;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/netfilter/xt_IDLETIMER.h b/libc/kernel/uapi/linux/netfilter/xt_IDLETIMER.h
index 9a98f20..1a2c088 100644
--- a/libc/kernel/uapi/linux/netfilter/xt_IDLETIMER.h
+++ b/libc/kernel/uapi/linux/netfilter/xt_IDLETIMER.h
@@ -21,14 +21,9 @@
 #include <linux/types.h>
 #define MAX_IDLETIMER_LABEL_SIZE 28
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define NLMSG_MAX_SIZE 64
-#define NL_EVENT_TYPE_INACTIVE 0
-#define NL_EVENT_TYPE_ACTIVE 1
 struct idletimer_tg_info {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 timeout;
  char label[MAX_IDLETIMER_LABEL_SIZE];
- __u8 send_nl_msg;
  struct idletimer_tg *timer __attribute__((aligned(8)));
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
diff --git a/libc/kernel/uapi/linux/netfilter/xt_SYNPROXY.h b/libc/kernel/uapi/linux/netfilter/xt_SYNPROXY.h
new file mode 100644
index 0000000..b3cd1ff
--- /dev/null
+++ b/libc/kernel/uapi/linux/netfilter/xt_SYNPROXY.h
@@ -0,0 +1,34 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _XT_SYNPROXY_H
+#define _XT_SYNPROXY_H
+#define XT_SYNPROXY_OPT_MSS 0x01
+#define XT_SYNPROXY_OPT_WSCALE 0x02
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define XT_SYNPROXY_OPT_SACK_PERM 0x04
+#define XT_SYNPROXY_OPT_TIMESTAMP 0x08
+#define XT_SYNPROXY_OPT_ECN 0x10
+struct xt_synproxy_info {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 options;
+ __u8 wscale;
+ __u16 mss;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/netfilter/xt_cgroup.h b/libc/kernel/uapi/linux/netfilter/xt_cgroup.h
new file mode 100644
index 0000000..986951b
--- /dev/null
+++ b/libc/kernel/uapi/linux/netfilter/xt_cgroup.h
@@ -0,0 +1,28 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI_XT_CGROUP_H
+#define _UAPI_XT_CGROUP_H
+#include <linux/types.h>
+struct xt_cgroup_info {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 id;
+ __u32 invert;
+};
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter/xt_ipcomp.h b/libc/kernel/uapi/linux/netfilter/xt_ipcomp.h
new file mode 100644
index 0000000..1bd1b56
--- /dev/null
+++ b/libc/kernel/uapi/linux/netfilter/xt_ipcomp.h
@@ -0,0 +1,31 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _XT_IPCOMP_H
+#define _XT_IPCOMP_H
+#include <linux/types.h>
+struct xt_ipcomp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 spis[2];
+ __u8 invflags;
+ __u8 hdrres;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define XT_IPCOMP_INV_SPI 0x01
+#define XT_IPCOMP_INV_MASK 0x01
+#endif
diff --git a/libc/kernel/uapi/linux/netfilter/xt_l2tp.h b/libc/kernel/uapi/linux/netfilter/xt_l2tp.h
new file mode 100644
index 0000000..9a7b82c
--- /dev/null
+++ b/libc/kernel/uapi/linux/netfilter/xt_l2tp.h
@@ -0,0 +1,44 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _LINUX_NETFILTER_XT_L2TP_H
+#define _LINUX_NETFILTER_XT_L2TP_H
+#include <linux/types.h>
+enum xt_l2tp_type {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ XT_L2TP_TYPE_CONTROL,
+ XT_L2TP_TYPE_DATA,
+};
+struct xt_l2tp_info {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tid;
+ __u32 sid;
+ __u8 version;
+ __u8 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 flags;
+};
+enum {
+ XT_L2TP_TID = (1 << 0),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ XT_L2TP_SID = (1 << 1),
+ XT_L2TP_VERSION = (1 << 2),
+ XT_L2TP_TYPE = (1 << 3),
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/netfilter/xt_rpfilter.h b/libc/kernel/uapi/linux/netfilter/xt_rpfilter.h
new file mode 100644
index 0000000..29533d6
--- /dev/null
+++ b/libc/kernel/uapi/linux/netfilter/xt_rpfilter.h
@@ -0,0 +1,34 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _XT_RPATH_H
+#define _XT_RPATH_H
+#include <linux/types.h>
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ XT_RPFILTER_LOOSE = 1 << 0,
+ XT_RPFILTER_VALID_MARK = 1 << 1,
+ XT_RPFILTER_ACCEPT_LOCAL = 1 << 2,
+ XT_RPFILTER_INVERT = 1 << 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct xt_rpfilter_info {
+ __u8 flags;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/netfilter/xt_socket.h b/libc/kernel/uapi/linux/netfilter/xt_socket.h
index 58bc6ae..4170fe6 100644
--- a/libc/kernel/uapi/linux/netfilter/xt_socket.h
+++ b/libc/kernel/uapi/linux/netfilter/xt_socket.h
@@ -22,14 +22,17 @@
 enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  XT_SOCKET_TRANSPARENT = 1 << 0,
+ XT_SOCKET_NOWILDCARD = 1 << 1,
 };
 struct xt_socket_mtinfo1 {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
-struct sock *xt_socket_get4_sk(const struct sk_buff *skb,
- struct xt_action_param *par);
-struct sock *xt_socket_get6_sk(const struct sk_buff *skb,
+#define XT_SOCKET_FLAGS_V1 XT_SOCKET_TRANSPARENT
+struct xt_socket_mtinfo2 {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- struct xt_action_param *par);
+ __u8 flags;
+};
+#define XT_SOCKET_FLAGS_V2 (XT_SOCKET_TRANSPARENT | XT_SOCKET_NOWILDCARD)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter_bridge/ebt_802_3.h b/libc/kernel/uapi/linux/netfilter_bridge/ebt_802_3.h
index 01ef168..09ae7e0 100644
--- a/libc/kernel/uapi/linux/netfilter_bridge/ebt_802_3.h
+++ b/libc/kernel/uapi/linux/netfilter_bridge/ebt_802_3.h
@@ -19,48 +19,50 @@
 #ifndef _UAPI__LINUX_BRIDGE_EBT_802_3_H
 #define _UAPI__LINUX_BRIDGE_EBT_802_3_H
 #include <linux/types.h>
-#define EBT_802_3_SAP 0x01
+#include <linux/if_ether.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EBT_802_3_SAP 0x01
 #define EBT_802_3_TYPE 0x02
 #define EBT_802_3_MATCH "802_3"
 #define CHECK_TYPE 0xaa
-#define IS_UI 0x03
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IS_UI 0x03
 #define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
 struct hdr_ui {
  __u8 dsap;
- __u8 ssap;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 ssap;
  __u8 ctrl;
  __u8 orig[3];
  __be16 type;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct hdr_ni {
  __u8 dsap;
  __u8 ssap;
- __be16 ctrl;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 ctrl;
  __u8 orig[3];
  __be16 type;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ebt_802_3_hdr {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u8 daddr[6];
- __u8 saddr[6];
+ __u8 daddr[ETH_ALEN];
+ __u8 saddr[ETH_ALEN];
  __be16 len;
- union {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union {
  struct hdr_ui ui;
  struct hdr_ni ni;
  } llc;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct ebt_802_3_info {
  __u8 sap;
  __be16 type;
- __u8 bitmask;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 bitmask;
  __u8 invflags;
 };
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter_ipv4/ipt_CLUSTERIP.h b/libc/kernel/uapi/linux/netfilter_ipv4/ipt_CLUSTERIP.h
index 2b8c513..9464545 100644
--- a/libc/kernel/uapi/linux/netfilter_ipv4/ipt_CLUSTERIP.h
+++ b/libc/kernel/uapi/linux/netfilter_ipv4/ipt_CLUSTERIP.h
@@ -19,28 +19,30 @@
 #ifndef _IPT_CLUSTERIP_H_target
 #define _IPT_CLUSTERIP_H_target
 #include <linux/types.h>
-enum clusterip_hashmode {
+#include <linux/if_ether.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum clusterip_hashmode {
  CLUSTERIP_HASHMODE_SIP = 0,
  CLUSTERIP_HASHMODE_SIP_SPT,
  CLUSTERIP_HASHMODE_SIP_SPT_DPT,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define CLUSTERIP_HASHMODE_MAX CLUSTERIP_HASHMODE_SIP_SPT_DPT
 #define CLUSTERIP_MAX_NODES 16
 #define CLUSTERIP_FLAG_NEW 0x00000001
-struct clusterip_config;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct clusterip_config;
 struct ipt_clusterip_tgt_info {
  __u32 flags;
- __u8 clustermac[6];
- __u16 num_total_nodes;
+ __u8 clustermac[ETH_ALEN];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 num_total_nodes;
  __u16 num_local_nodes;
  __u16 local_nodes[CLUSTERIP_MAX_NODES];
  __u32 hash_mode;
- __u32 hash_initval;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 hash_initval;
  struct clusterip_config *config;
 };
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/nfc.h b/libc/kernel/uapi/linux/nfc.h
index 1e71bb2..88979de 100644
--- a/libc/kernel/uapi/linux/nfc.h
+++ b/libc/kernel/uapi/linux/nfc.h
@@ -52,54 +52,74 @@
  NFC_CMD_LLC_SDREQ,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_EVENT_LLC_SDRES,
+ NFC_CMD_FW_DOWNLOAD,
+ NFC_EVENT_SE_ADDED,
+ NFC_EVENT_SE_REMOVED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFC_EVENT_SE_CONNECTIVITY,
+ NFC_EVENT_SE_TRANSACTION,
+ NFC_CMD_GET_SE,
+ NFC_CMD_SE_IO,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NFC_CMD_AFTER_LAST
 };
 #define NFC_CMD_MAX (__NFC_CMD_AFTER_LAST - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nfc_attrs {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_UNSPEC,
  NFC_ATTR_DEVICE_INDEX,
  NFC_ATTR_DEVICE_NAME,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_PROTOCOLS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_TARGET_INDEX,
  NFC_ATTR_TARGET_SENS_RES,
  NFC_ATTR_TARGET_SEL_RES,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_TARGET_NFCID1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_TARGET_SENSB_RES,
  NFC_ATTR_TARGET_SENSF_RES,
  NFC_ATTR_COMM_MODE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_RF_MODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_DEVICE_POWERED,
  NFC_ATTR_IM_PROTOCOLS,
  NFC_ATTR_TM_PROTOCOLS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_LLC_PARAM_LTO,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_LLC_PARAM_RW,
  NFC_ATTR_LLC_PARAM_MIUX,
  NFC_ATTR_SE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NFC_ATTR_LLC_SDP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFC_ATTR_FIRMWARE_NAME,
+ NFC_ATTR_SE_INDEX,
+ NFC_ATTR_SE_TYPE,
+ NFC_ATTR_SE_AID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFC_ATTR_FIRMWARE_DOWNLOAD_STATUS,
+ NFC_ATTR_SE_APDU,
  __NFC_ATTR_AFTER_LAST
 };
-#define NFC_ATTR_MAX (__NFC_ATTR_AFTER_LAST - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFC_ATTR_MAX (__NFC_ATTR_AFTER_LAST - 1)
 enum nfc_sdp_attr {
  NFC_SDP_ATTR_UNSPEC,
  NFC_SDP_ATTR_URI,
- NFC_SDP_ATTR_SAP,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NFC_SDP_ATTR_SAP,
  __NFC_SDP_ATTR_AFTER_LAST
 };
 #define NFC_SDP_ATTR_MAX (__NFC_SDP_ATTR_AFTER_LAST - 1)
-#define NFC_DEVICE_NAME_MAXSIZE 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFC_DEVICE_NAME_MAXSIZE 8
 #define NFC_NFCID1_MAXSIZE 10
+#define NFC_NFCID2_MAXSIZE 8
+#define NFC_NFCID3_MAXSIZE 10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFC_SENSB_RES_MAXSIZE 12
 #define NFC_SENSF_RES_MAXSIZE 18
 #define NFC_GB_MAXSIZE 48
+#define NFC_FIRMWARE_NAME_MAXSIZE 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFC_PROTO_JEWEL 1
 #define NFC_PROTO_MIFARE 2
@@ -123,44 +143,46 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP)
 #define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B)
-#define NFC_SE_NONE 0x0
 #define NFC_SE_UICC 0x1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFC_SE_EMBEDDED 0x2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFC_SE_DISABLED 0x0
+#define NFC_SE_ENABLED 0x1
 struct sockaddr_nfc {
  sa_family_t sa_family;
- __u32 dev_idx;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 dev_idx;
  __u32 target_idx;
  __u32 nfc_protocol;
 };
-#define NFC_LLCP_MAX_SERVICE_NAME 63
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFC_LLCP_MAX_SERVICE_NAME 63
 struct sockaddr_nfc_llcp {
  sa_family_t sa_family;
  __u32 dev_idx;
- __u32 target_idx;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 target_idx;
  __u32 nfc_protocol;
  __u8 dsap;
  __u8 ssap;
- char service_name[NFC_LLCP_MAX_SERVICE_NAME];  ;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ char service_name[NFC_LLCP_MAX_SERVICE_NAME];  ;
  size_t service_name_len;
 };
 #define NFC_SOCKPROTO_RAW 0
-#define NFC_SOCKPROTO_LLCP 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFC_SOCKPROTO_LLCP 1
 #define NFC_SOCKPROTO_MAX 2
 #define NFC_HEADER_SIZE 1
 #define NFC_LLCP_RAW_HEADER_SIZE 2
-#define NFC_LLCP_DIRECTION_RX 0x00
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFC_LLCP_DIRECTION_RX 0x00
 #define NFC_LLCP_DIRECTION_TX 0x01
 #define NFC_LLCP_RW 0
 #define NFC_LLCP_MIUX 1
-#define NFC_LLCP_REMOTE_MIU 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NFC_LLCP_REMOTE_MIU 2
 #define NFC_LLCP_REMOTE_LTO 3
 #define NFC_LLCP_REMOTE_RW 4
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/nfs4.h b/libc/kernel/uapi/linux/nfs4.h
index 09a3c7c..2944693 100644
--- a/libc/kernel/uapi/linux/nfs4.h
+++ b/libc/kernel/uapi/linux/nfs4.h
@@ -157,7 +157,7 @@
 #define NFS4_SECINFO_STYLE4_CURRENT_FH 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NFS4_SECINFO_STYLE4_PARENT 1
-#define NFS4_MAX_UINT64 (~(u64)0)
+#define NFS4_MAX_UINT64 (~(__u64)0)
 #define NFS4_MAX_OPS 8
 #define NFS4_MAX_BACK_CHANNEL_OPS 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/nl80211.h b/libc/kernel/uapi/linux/nl80211.h
index 33f4a82..01c50cd 100644
--- a/libc/kernel/uapi/linux/nl80211.h
+++ b/libc/kernel/uapi/linux/nl80211.h
@@ -19,755 +19,800 @@
 #ifndef __LINUX_NL80211_H
 #define __LINUX_NL80211_H
 #include <linux/types.h>
-enum nl80211_commands {
+#define NL80211_GENL_NAME "nl80211"
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nl80211_commands {
  NL80211_CMD_UNSPEC,
  NL80211_CMD_GET_WIPHY,
  NL80211_CMD_SET_WIPHY,
- NL80211_CMD_NEW_WIPHY,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_NEW_WIPHY,
  NL80211_CMD_DEL_WIPHY,
  NL80211_CMD_GET_INTERFACE,
  NL80211_CMD_SET_INTERFACE,
- NL80211_CMD_NEW_INTERFACE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_NEW_INTERFACE,
  NL80211_CMD_DEL_INTERFACE,
  NL80211_CMD_GET_KEY,
  NL80211_CMD_SET_KEY,
- NL80211_CMD_NEW_KEY,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_NEW_KEY,
  NL80211_CMD_DEL_KEY,
  NL80211_CMD_GET_BEACON,
  NL80211_CMD_SET_BEACON,
- NL80211_CMD_START_AP,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_START_AP,
  NL80211_CMD_NEW_BEACON = NL80211_CMD_START_AP,
  NL80211_CMD_STOP_AP,
  NL80211_CMD_DEL_BEACON = NL80211_CMD_STOP_AP,
- NL80211_CMD_GET_STATION,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_GET_STATION,
  NL80211_CMD_SET_STATION,
  NL80211_CMD_NEW_STATION,
  NL80211_CMD_DEL_STATION,
- NL80211_CMD_GET_MPATH,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_GET_MPATH,
  NL80211_CMD_SET_MPATH,
  NL80211_CMD_NEW_MPATH,
  NL80211_CMD_DEL_MPATH,
- NL80211_CMD_SET_BSS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_SET_BSS,
  NL80211_CMD_SET_REG,
  NL80211_CMD_REQ_SET_REG,
  NL80211_CMD_GET_MESH_CONFIG,
- NL80211_CMD_SET_MESH_CONFIG,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_SET_MESH_CONFIG,
  NL80211_CMD_SET_MGMT_EXTRA_IE  ,
  NL80211_CMD_GET_REG,
  NL80211_CMD_GET_SCAN,
- NL80211_CMD_TRIGGER_SCAN,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_TRIGGER_SCAN,
  NL80211_CMD_NEW_SCAN_RESULTS,
  NL80211_CMD_SCAN_ABORTED,
  NL80211_CMD_REG_CHANGE,
- NL80211_CMD_AUTHENTICATE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_AUTHENTICATE,
  NL80211_CMD_ASSOCIATE,
  NL80211_CMD_DEAUTHENTICATE,
  NL80211_CMD_DISASSOCIATE,
- NL80211_CMD_MICHAEL_MIC_FAILURE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_MICHAEL_MIC_FAILURE,
  NL80211_CMD_REG_BEACON_HINT,
  NL80211_CMD_JOIN_IBSS,
  NL80211_CMD_LEAVE_IBSS,
- NL80211_CMD_TESTMODE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_TESTMODE,
  NL80211_CMD_CONNECT,
  NL80211_CMD_ROAM,
  NL80211_CMD_DISCONNECT,
- NL80211_CMD_SET_WIPHY_NETNS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_SET_WIPHY_NETNS,
  NL80211_CMD_GET_SURVEY,
  NL80211_CMD_NEW_SURVEY_RESULTS,
  NL80211_CMD_SET_PMKSA,
- NL80211_CMD_DEL_PMKSA,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_DEL_PMKSA,
  NL80211_CMD_FLUSH_PMKSA,
  NL80211_CMD_REMAIN_ON_CHANNEL,
  NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
- NL80211_CMD_SET_TX_BITRATE_MASK,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_SET_TX_BITRATE_MASK,
  NL80211_CMD_REGISTER_FRAME,
  NL80211_CMD_REGISTER_ACTION = NL80211_CMD_REGISTER_FRAME,
  NL80211_CMD_FRAME,
- NL80211_CMD_ACTION = NL80211_CMD_FRAME,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_ACTION = NL80211_CMD_FRAME,
  NL80211_CMD_FRAME_TX_STATUS,
  NL80211_CMD_ACTION_TX_STATUS = NL80211_CMD_FRAME_TX_STATUS,
  NL80211_CMD_SET_POWER_SAVE,
- NL80211_CMD_GET_POWER_SAVE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_GET_POWER_SAVE,
  NL80211_CMD_SET_CQM,
  NL80211_CMD_NOTIFY_CQM,
  NL80211_CMD_SET_CHANNEL,
- NL80211_CMD_SET_WDS_PEER,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_SET_WDS_PEER,
  NL80211_CMD_FRAME_WAIT_CANCEL,
  NL80211_CMD_JOIN_MESH,
  NL80211_CMD_LEAVE_MESH,
- NL80211_CMD_UNPROT_DEAUTHENTICATE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_UNPROT_DEAUTHENTICATE,
  NL80211_CMD_UNPROT_DISASSOCIATE,
  NL80211_CMD_NEW_PEER_CANDIDATE,
  NL80211_CMD_GET_WOWLAN,
- NL80211_CMD_SET_WOWLAN,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_SET_WOWLAN,
  NL80211_CMD_START_SCHED_SCAN,
  NL80211_CMD_STOP_SCHED_SCAN,
  NL80211_CMD_SCHED_SCAN_RESULTS,
- NL80211_CMD_SCHED_SCAN_STOPPED,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_SCHED_SCAN_STOPPED,
  NL80211_CMD_SET_REKEY_OFFLOAD,
  NL80211_CMD_PMKSA_CANDIDATE,
  NL80211_CMD_TDLS_OPER,
- NL80211_CMD_TDLS_MGMT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_TDLS_MGMT,
  NL80211_CMD_UNEXPECTED_FRAME,
  NL80211_CMD_PROBE_CLIENT,
  NL80211_CMD_REGISTER_BEACONS,
- NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
  NL80211_CMD_SET_NOACK_MAP,
  NL80211_CMD_CH_SWITCH_NOTIFY,
  NL80211_CMD_START_P2P_DEVICE,
- NL80211_CMD_STOP_P2P_DEVICE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_STOP_P2P_DEVICE,
  NL80211_CMD_CONN_FAILED,
  NL80211_CMD_SET_MCAST_RATE,
  NL80211_CMD_SET_MAC_ACL,
- NL80211_CMD_RADAR_DETECT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_RADAR_DETECT,
  NL80211_CMD_GET_PROTOCOL_FEATURES,
  NL80211_CMD_UPDATE_FT_IES,
  NL80211_CMD_FT_EVENT,
- NL80211_CMD_CRIT_PROTOCOL_START,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_CRIT_PROTOCOL_START,
  NL80211_CMD_CRIT_PROTOCOL_STOP,
+ NL80211_CMD_GET_COALESCE,
+ NL80211_CMD_SET_COALESCE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CMD_CHANNEL_SWITCH,
+ NL80211_CMD_VENDOR,
+ NL80211_CMD_SET_QOS_MAP,
  __NL80211_CMD_AFTER_LAST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_CMD_MAX = __NL80211_CMD_AFTER_LAST - 1
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_CMD_SET_BSS NL80211_CMD_SET_BSS
 #define NL80211_CMD_SET_MGMT_EXTRA_IE NL80211_CMD_SET_MGMT_EXTRA_IE
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_CMD_REG_CHANGE NL80211_CMD_REG_CHANGE
 #define NL80211_CMD_AUTHENTICATE NL80211_CMD_AUTHENTICATE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_CMD_ASSOCIATE NL80211_CMD_ASSOCIATE
 #define NL80211_CMD_DEAUTHENTICATE NL80211_CMD_DEAUTHENTICATE
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_CMD_DISASSOCIATE NL80211_CMD_DISASSOCIATE
 #define NL80211_CMD_REG_BEACON_HINT NL80211_CMD_REG_BEACON_HINT
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_ATTR_FEATURE_FLAGS NL80211_ATTR_FEATURE_FLAGS
 #define NL80211_CMD_GET_MESH_PARAMS NL80211_CMD_GET_MESH_CONFIG
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_CMD_SET_MESH_PARAMS NL80211_CMD_SET_MESH_CONFIG
 #define NL80211_MESH_SETUP_VENDOR_PATH_SEL_IE NL80211_MESH_SETUP_IE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_attrs {
  NL80211_ATTR_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY,
  NL80211_ATTR_WIPHY_NAME,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_IFINDEX,
  NL80211_ATTR_IFNAME,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_IFTYPE,
  NL80211_ATTR_MAC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_KEY_DATA,
  NL80211_ATTR_KEY_IDX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_KEY_CIPHER,
  NL80211_ATTR_KEY_SEQ,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_KEY_DEFAULT,
  NL80211_ATTR_BEACON_INTERVAL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_DTIM_PERIOD,
  NL80211_ATTR_BEACON_HEAD,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_BEACON_TAIL,
  NL80211_ATTR_STA_AID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_STA_FLAGS,
  NL80211_ATTR_STA_LISTEN_INTERVAL,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_STA_SUPPORTED_RATES,
  NL80211_ATTR_STA_VLAN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_STA_INFO,
  NL80211_ATTR_WIPHY_BANDS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MNTR_FLAGS,
  NL80211_ATTR_MESH_ID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_STA_PLINK_ACTION,
  NL80211_ATTR_MPATH_NEXT_HOP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MPATH_INFO,
  NL80211_ATTR_BSS_CTS_PROT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_BSS_SHORT_PREAMBLE,
  NL80211_ATTR_BSS_SHORT_SLOT_TIME,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_HT_CAPABILITY,
  NL80211_ATTR_SUPPORTED_IFTYPES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_REG_ALPHA2,
  NL80211_ATTR_REG_RULES,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MESH_CONFIG,
  NL80211_ATTR_BSS_BASIC_RATES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY_TXQ_PARAMS,
  NL80211_ATTR_WIPHY_FREQ,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY_CHANNEL_TYPE,
  NL80211_ATTR_KEY_DEFAULT_MGMT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MGMT_SUBTYPE,
  NL80211_ATTR_IE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
  NL80211_ATTR_SCAN_FREQUENCIES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_SCAN_SSIDS,
  NL80211_ATTR_GENERATION,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_BSS,
  NL80211_ATTR_REG_INITIATOR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_REG_TYPE,
  NL80211_ATTR_SUPPORTED_COMMANDS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_FRAME,
  NL80211_ATTR_SSID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_AUTH_TYPE,
  NL80211_ATTR_REASON_CODE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_KEY_TYPE,
  NL80211_ATTR_MAX_SCAN_IE_LEN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CIPHER_SUITES,
  NL80211_ATTR_FREQ_BEFORE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_FREQ_AFTER,
  NL80211_ATTR_FREQ_FIXED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY_RETRY_SHORT,
  NL80211_ATTR_WIPHY_RETRY_LONG,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
  NL80211_ATTR_WIPHY_RTS_THRESHOLD,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_TIMED_OUT,
  NL80211_ATTR_USE_MFP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_STA_FLAGS2,
  NL80211_ATTR_CONTROL_PORT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_TESTDATA,
  NL80211_ATTR_PRIVACY,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_DISCONNECTED_BY_AP,
  NL80211_ATTR_STATUS_CODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
  NL80211_ATTR_CIPHER_SUITE_GROUP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WPA_VERSIONS,
  NL80211_ATTR_AKM_SUITES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_REQ_IE,
  NL80211_ATTR_RESP_IE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_PREV_BSSID,
  NL80211_ATTR_KEY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_KEYS,
  NL80211_ATTR_PID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_4ADDR,
  NL80211_ATTR_SURVEY_INFO,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_PMKID,
  NL80211_ATTR_MAX_NUM_PMKIDS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_DURATION,
  NL80211_ATTR_COOKIE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY_COVERAGE_CLASS,
  NL80211_ATTR_TX_RATES,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_FRAME_MATCH,
  NL80211_ATTR_ACK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_PS_STATE,
  NL80211_ATTR_CQM,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_LOCAL_STATE_CHANGE,
  NL80211_ATTR_AP_ISOLATE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY_TX_POWER_SETTING,
  NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_TX_FRAME_TYPES,
  NL80211_ATTR_RX_FRAME_TYPES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_FRAME_TYPE,
  NL80211_ATTR_CONTROL_PORT_ETHERTYPE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT,
  NL80211_ATTR_SUPPORT_IBSS_RSN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY_ANTENNA_TX,
  NL80211_ATTR_WIPHY_ANTENNA_RX,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MCAST_RATE,
  NL80211_ATTR_OFFCHANNEL_TX_OK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_BSS_HT_OPMODE,
  NL80211_ATTR_KEY_DEFAULT_TYPES,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
  NL80211_ATTR_MESH_SETUP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
  NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_SUPPORT_MESH_AUTH,
  NL80211_ATTR_STA_PLINK_STATE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WOWLAN_TRIGGERS,
  NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_SCHED_SCAN_INTERVAL,
  NL80211_ATTR_INTERFACE_COMBINATIONS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_SOFTWARE_IFTYPES,
  NL80211_ATTR_REKEY_DATA,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
  NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_SCAN_SUPP_RATES,
  NL80211_ATTR_HIDDEN_SSID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_IE_PROBE_RESP,
  NL80211_ATTR_IE_ASSOC_RESP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_STA_WME,
  NL80211_ATTR_SUPPORT_AP_UAPSD,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_ROAM_SUPPORT,
  NL80211_ATTR_SCHED_SCAN_MATCH,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MAX_MATCH_SETS,
  NL80211_ATTR_PMKSA_CANDIDATE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_TX_NO_CCK_RATE,
  NL80211_ATTR_TDLS_ACTION,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_TDLS_DIALOG_TOKEN,
  NL80211_ATTR_TDLS_OPERATION,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_TDLS_SUPPORT,
  NL80211_ATTR_TDLS_EXTERNAL_SETUP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_DEVICE_AP_SME,
  NL80211_ATTR_DONT_WAIT_FOR_ACK,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_FEATURE_FLAGS,
  NL80211_ATTR_PROBE_RESP_OFFLOAD,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_PROBE_RESP,
  NL80211_ATTR_DFS_REGION,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_DISABLE_HT,
  NL80211_ATTR_HT_CAPABILITY_MASK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_NOACK_MAP,
  NL80211_ATTR_INACTIVITY_TIMEOUT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_RX_SIGNAL_DBM,
  NL80211_ATTR_BG_SCAN_PERIOD,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_WDEV,
  NL80211_ATTR_USER_REG_HINT_TYPE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CONN_FAILED_REASON,
  NL80211_ATTR_SAE_DATA,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_VHT_CAPABILITY,
  NL80211_ATTR_SCAN_FLAGS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CHANNEL_WIDTH,
  NL80211_ATTR_CENTER_FREQ1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CENTER_FREQ2,
  NL80211_ATTR_P2P_CTWINDOW,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_P2P_OPPPS,
  NL80211_ATTR_LOCAL_MESH_POWER_MODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_ACL_POLICY,
  NL80211_ATTR_MAC_ADDRS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MAC_ACL_MAX,
  NL80211_ATTR_RADAR_EVENT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_EXT_CAPA,
  NL80211_ATTR_EXT_CAPA_MASK,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_STA_CAPABILITY,
  NL80211_ATTR_STA_EXT_CAPABILITY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_PROTOCOL_FEATURES,
  NL80211_ATTR_SPLIT_WIPHY_DUMP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_DISABLE_VHT,
  NL80211_ATTR_VHT_CAPABILITY_MASK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_MDID,
  NL80211_ATTR_IE_RIC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CRIT_PROT_ID,
  NL80211_ATTR_MAX_CRIT_PROT_DURATION,
- __NL80211_ATTR_AFTER_LAST,
- NL80211_ATTR_MAX = __NL80211_ATTR_AFTER_LAST - 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_ATTR_PEER_AID,
+ NL80211_ATTR_COALESCE_RULE,
+ NL80211_ATTR_CH_SWITCH_COUNT,
+ NL80211_ATTR_CH_SWITCH_BLOCK_TX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_ATTR_CSA_IES,
+ NL80211_ATTR_CSA_C_OFF_BEACON,
+ NL80211_ATTR_CSA_C_OFF_PRESP,
+ NL80211_ATTR_RXMGMT_FLAGS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_ATTR_STA_SUPPORTED_CHANNELS,
+ NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
+ NL80211_ATTR_HANDLE_DFS,
+ NL80211_ATTR_SUPPORT_5_MHZ,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_ATTR_SUPPORT_10_MHZ,
+ NL80211_ATTR_OPMODE_NOTIF,
+ NL80211_ATTR_VENDOR_ID,
+ NL80211_ATTR_VENDOR_SUBCMD,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_ATTR_VENDOR_DATA,
+ NL80211_ATTR_VENDOR_EVENTS,
+ NL80211_ATTR_QOS_MAP,
+ __NL80211_ATTR_AFTER_LAST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_ATTR_MAX = __NL80211_ATTR_AFTER_LAST - 1
 };
 #define NL80211_ATTR_SCAN_GENERATION NL80211_ATTR_GENERATION
 #define NL80211_ATTR_MESH_PARAMS NL80211_ATTR_MESH_CONFIG
-#define NL80211_CMD_CONNECT NL80211_CMD_CONNECT
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_CMD_CONNECT NL80211_CMD_CONNECT
 #define NL80211_ATTR_HT_CAPABILITY NL80211_ATTR_HT_CAPABILITY
 #define NL80211_ATTR_BSS_BASIC_RATES NL80211_ATTR_BSS_BASIC_RATES
 #define NL80211_ATTR_WIPHY_TXQ_PARAMS NL80211_ATTR_WIPHY_TXQ_PARAMS
-#define NL80211_ATTR_WIPHY_FREQ NL80211_ATTR_WIPHY_FREQ
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_ATTR_WIPHY_FREQ NL80211_ATTR_WIPHY_FREQ
 #define NL80211_ATTR_WIPHY_CHANNEL_TYPE NL80211_ATTR_WIPHY_CHANNEL_TYPE
 #define NL80211_ATTR_MGMT_SUBTYPE NL80211_ATTR_MGMT_SUBTYPE
 #define NL80211_ATTR_IE NL80211_ATTR_IE
-#define NL80211_ATTR_REG_INITIATOR NL80211_ATTR_REG_INITIATOR
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_ATTR_REG_INITIATOR NL80211_ATTR_REG_INITIATOR
 #define NL80211_ATTR_REG_TYPE NL80211_ATTR_REG_TYPE
 #define NL80211_ATTR_FRAME NL80211_ATTR_FRAME
 #define NL80211_ATTR_SSID NL80211_ATTR_SSID
-#define NL80211_ATTR_AUTH_TYPE NL80211_ATTR_AUTH_TYPE
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_ATTR_AUTH_TYPE NL80211_ATTR_AUTH_TYPE
 #define NL80211_ATTR_REASON_CODE NL80211_ATTR_REASON_CODE
 #define NL80211_ATTR_CIPHER_SUITES_PAIRWISE NL80211_ATTR_CIPHER_SUITES_PAIRWISE
 #define NL80211_ATTR_CIPHER_SUITE_GROUP NL80211_ATTR_CIPHER_SUITE_GROUP
-#define NL80211_ATTR_WPA_VERSIONS NL80211_ATTR_WPA_VERSIONS
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_ATTR_WPA_VERSIONS NL80211_ATTR_WPA_VERSIONS
 #define NL80211_ATTR_AKM_SUITES NL80211_ATTR_AKM_SUITES
 #define NL80211_ATTR_KEY NL80211_ATTR_KEY
 #define NL80211_ATTR_KEYS NL80211_ATTR_KEYS
-#define NL80211_ATTR_FEATURE_FLAGS NL80211_ATTR_FEATURE_FLAGS
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_ATTR_FEATURE_FLAGS NL80211_ATTR_FEATURE_FLAGS
 #define NL80211_MAX_SUPP_RATES 32
 #define NL80211_MAX_SUPP_HT_RATES 77
 #define NL80211_MAX_SUPP_REG_RULES 32
-#define NL80211_TKIP_DATA_OFFSET_ENCR_KEY 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_TKIP_DATA_OFFSET_ENCR_KEY 0
 #define NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY 16
 #define NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY 24
 #define NL80211_HT_CAPABILITY_LEN 26
-#define NL80211_VHT_CAPABILITY_LEN 12
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_VHT_CAPABILITY_LEN 12
 #define NL80211_MAX_NR_CIPHER_SUITES 5
 #define NL80211_MAX_NR_AKM_SUITES 2
 #define NL80211_MIN_REMAIN_ON_CHANNEL_TIME 10
-#define NL80211_SCAN_RSSI_THOLD_OFF -300
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_SCAN_RSSI_THOLD_OFF -300
 #define NL80211_CQM_TXE_MAX_INTVL 1800
 enum nl80211_iftype {
  NL80211_IFTYPE_UNSPECIFIED,
- NL80211_IFTYPE_ADHOC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_IFTYPE_ADHOC,
  NL80211_IFTYPE_STATION,
  NL80211_IFTYPE_AP,
  NL80211_IFTYPE_AP_VLAN,
- NL80211_IFTYPE_WDS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_IFTYPE_WDS,
  NL80211_IFTYPE_MONITOR,
  NL80211_IFTYPE_MESH_POINT,
  NL80211_IFTYPE_P2P_CLIENT,
- NL80211_IFTYPE_P2P_GO,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_IFTYPE_P2P_GO,
  NL80211_IFTYPE_P2P_DEVICE,
  NUM_NL80211_IFTYPES,
  NL80211_IFTYPE_MAX = NUM_NL80211_IFTYPES - 1
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum nl80211_sta_flags {
  __NL80211_STA_FLAG_INVALID,
  NL80211_STA_FLAG_AUTHORIZED,
- NL80211_STA_FLAG_SHORT_PREAMBLE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_FLAG_SHORT_PREAMBLE,
  NL80211_STA_FLAG_WME,
  NL80211_STA_FLAG_MFP,
  NL80211_STA_FLAG_AUTHENTICATED,
- NL80211_STA_FLAG_TDLS_PEER,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_FLAG_TDLS_PEER,
  NL80211_STA_FLAG_ASSOCIATED,
  __NL80211_STA_FLAG_AFTER_LAST,
  NL80211_STA_FLAG_MAX = __NL80211_STA_FLAG_AFTER_LAST - 1
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define NL80211_STA_FLAG_MAX_OLD_API NL80211_STA_FLAG_TDLS_PEER
 struct nl80211_sta_flag_update {
  __u32 mask;
- __u32 set;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 set;
 } __attribute__((packed));
 enum nl80211_rate_info {
  __NL80211_RATE_INFO_INVALID,
- NL80211_RATE_INFO_BITRATE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_RATE_INFO_BITRATE,
  NL80211_RATE_INFO_MCS,
  NL80211_RATE_INFO_40_MHZ_WIDTH,
  NL80211_RATE_INFO_SHORT_GI,
- NL80211_RATE_INFO_BITRATE32,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_RATE_INFO_BITRATE32,
  NL80211_RATE_INFO_VHT_MCS,
  NL80211_RATE_INFO_VHT_NSS,
  NL80211_RATE_INFO_80_MHZ_WIDTH,
- NL80211_RATE_INFO_80P80_MHZ_WIDTH,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_RATE_INFO_80P80_MHZ_WIDTH,
  NL80211_RATE_INFO_160_MHZ_WIDTH,
  __NL80211_RATE_INFO_AFTER_LAST,
  NL80211_RATE_INFO_MAX = __NL80211_RATE_INFO_AFTER_LAST - 1
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum nl80211_sta_bss_param {
  __NL80211_STA_BSS_PARAM_INVALID,
  NL80211_STA_BSS_PARAM_CTS_PROT,
- NL80211_STA_BSS_PARAM_SHORT_PREAMBLE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_BSS_PARAM_SHORT_PREAMBLE,
  NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME,
  NL80211_STA_BSS_PARAM_DTIM_PERIOD,
  NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
- __NL80211_STA_BSS_PARAM_AFTER_LAST,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NL80211_STA_BSS_PARAM_AFTER_LAST,
  NL80211_STA_BSS_PARAM_MAX = __NL80211_STA_BSS_PARAM_AFTER_LAST - 1
 };
 enum nl80211_sta_info {
- __NL80211_STA_INFO_INVALID,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NL80211_STA_INFO_INVALID,
  NL80211_STA_INFO_INACTIVE_TIME,
  NL80211_STA_INFO_RX_BYTES,
  NL80211_STA_INFO_TX_BYTES,
- NL80211_STA_INFO_LLID,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_INFO_LLID,
  NL80211_STA_INFO_PLID,
  NL80211_STA_INFO_PLINK_STATE,
  NL80211_STA_INFO_SIGNAL,
- NL80211_STA_INFO_TX_BITRATE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_INFO_TX_BITRATE,
  NL80211_STA_INFO_RX_PACKETS,
  NL80211_STA_INFO_TX_PACKETS,
  NL80211_STA_INFO_TX_RETRIES,
- NL80211_STA_INFO_TX_FAILED,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_INFO_TX_FAILED,
  NL80211_STA_INFO_SIGNAL_AVG,
  NL80211_STA_INFO_RX_BITRATE,
  NL80211_STA_INFO_BSS_PARAM,
- NL80211_STA_INFO_CONNECTED_TIME,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_INFO_CONNECTED_TIME,
  NL80211_STA_INFO_STA_FLAGS,
  NL80211_STA_INFO_BEACON_LOSS,
  NL80211_STA_INFO_T_OFFSET,
- NL80211_STA_INFO_LOCAL_PM,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_INFO_LOCAL_PM,
  NL80211_STA_INFO_PEER_PM,
  NL80211_STA_INFO_NONPEER_PM,
  NL80211_STA_INFO_RX_BYTES64,
- NL80211_STA_INFO_TX_BYTES64,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_STA_INFO_TX_BYTES64,
+ NL80211_STA_INFO_CHAIN_SIGNAL,
+ NL80211_STA_INFO_CHAIN_SIGNAL_AVG,
  __NL80211_STA_INFO_AFTER_LAST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_STA_INFO_MAX = __NL80211_STA_INFO_AFTER_LAST - 1
 };
 enum nl80211_mpath_flags {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MPATH_FLAG_ACTIVE = 1<<0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MPATH_FLAG_RESOLVING = 1<<1,
  NL80211_MPATH_FLAG_SN_VALID = 1<<2,
  NL80211_MPATH_FLAG_FIXED = 1<<3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MPATH_FLAG_RESOLVED = 1<<4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_mpath_info {
  __NL80211_MPATH_INFO_INVALID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MPATH_INFO_FRAME_QLEN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MPATH_INFO_SN,
  NL80211_MPATH_INFO_METRIC,
  NL80211_MPATH_INFO_EXPTIME,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MPATH_INFO_FLAGS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
  NL80211_MPATH_INFO_DISCOVERY_RETRIES,
  __NL80211_MPATH_INFO_AFTER_LAST,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MPATH_INFO_MAX = __NL80211_MPATH_INFO_AFTER_LAST - 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_band_attr {
  __NL80211_BAND_ATTR_INVALID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_BAND_ATTR_FREQS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_BAND_ATTR_RATES,
  NL80211_BAND_ATTR_HT_MCS_SET,
  NL80211_BAND_ATTR_HT_CAPA,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
  NL80211_BAND_ATTR_VHT_MCS_SET,
  NL80211_BAND_ATTR_VHT_CAPA,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_BAND_ATTR_AFTER_LAST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_BAND_ATTR_MAX = __NL80211_BAND_ATTR_AFTER_LAST - 1
 };
 #define NL80211_BAND_ATTR_HT_CAPA NL80211_BAND_ATTR_HT_CAPA
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_frequency_attr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_FREQUENCY_ATTR_INVALID,
  NL80211_FREQUENCY_ATTR_FREQ,
  NL80211_FREQUENCY_ATTR_DISABLED,
+ NL80211_FREQUENCY_ATTR_NO_IR,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- NL80211_FREQUENCY_ATTR_PASSIVE_SCAN,
- NL80211_FREQUENCY_ATTR_NO_IBSS,
+ __NL80211_FREQUENCY_ATTR_NO_IBSS,
  NL80211_FREQUENCY_ATTR_RADAR,
  NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FREQUENCY_ATTR_DFS_STATE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FREQUENCY_ATTR_DFS_TIME,
  NL80211_FREQUENCY_ATTR_NO_HT40_MINUS,
  NL80211_FREQUENCY_ATTR_NO_HT40_PLUS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FREQUENCY_ATTR_NO_80MHZ,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FREQUENCY_ATTR_NO_160MHZ,
  __NL80211_FREQUENCY_ATTR_AFTER_LAST,
  NL80211_FREQUENCY_ATTR_MAX = __NL80211_FREQUENCY_ATTR_AFTER_LAST - 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_FREQUENCY_ATTR_MAX_TX_POWER NL80211_FREQUENCY_ATTR_MAX_TX_POWER
+#define NL80211_FREQUENCY_ATTR_PASSIVE_SCAN NL80211_FREQUENCY_ATTR_NO_IR
+#define NL80211_FREQUENCY_ATTR_NO_IBSS NL80211_FREQUENCY_ATTR_NO_IR
+#define NL80211_FREQUENCY_ATTR_NO_IR NL80211_FREQUENCY_ATTR_NO_IR
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_bitrate_attr {
  __NL80211_BITRATE_ATTR_INVALID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_BITRATE_ATTR_RATE,
  NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_BITRATE_ATTR_AFTER_LAST,
  NL80211_BITRATE_ATTR_MAX = __NL80211_BITRATE_ATTR_AFTER_LAST - 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_reg_initiator {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_REGDOM_SET_BY_CORE,
  NL80211_REGDOM_SET_BY_USER,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_REGDOM_SET_BY_DRIVER,
  NL80211_REGDOM_SET_BY_COUNTRY_IE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_reg_type {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_REGDOM_TYPE_COUNTRY,
  NL80211_REGDOM_TYPE_WORLD,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_REGDOM_TYPE_CUSTOM_WORLD,
  NL80211_REGDOM_TYPE_INTERSECTION,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_reg_rule_attr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_REG_RULE_ATTR_INVALID,
  NL80211_ATTR_REG_RULE_FLAGS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_FREQ_RANGE_START,
  NL80211_ATTR_FREQ_RANGE_END,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_FREQ_RANGE_MAX_BW,
  NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_POWER_RULE_MAX_EIRP,
  __NL80211_REG_RULE_ATTR_AFTER_LAST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_REG_RULE_ATTR_MAX = __NL80211_REG_RULE_ATTR_AFTER_LAST - 1
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_sched_scan_match_attr {
  __NL80211_SCHED_SCAN_MATCH_ATTR_INVALID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
  NL80211_SCHED_SCAN_MATCH_ATTR_RSSI,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_SCHED_SCAN_MATCH_ATTR_AFTER_LAST,
  NL80211_SCHED_SCAN_MATCH_ATTR_MAX =
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_SCHED_SCAN_MATCH_ATTR_AFTER_LAST - 1
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_ATTR_SCHED_SCAN_MATCH_SSID NL80211_SCHED_SCAN_MATCH_ATTR_SSID
 enum nl80211_reg_rule_flags {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_RRF_NO_OFDM = 1<<0,
  NL80211_RRF_NO_CCK = 1<<1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_RRF_NO_INDOOR = 1<<2,
  NL80211_RRF_NO_OUTDOOR = 1<<3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_RRF_DFS = 1<<4,
  NL80211_RRF_PTP_ONLY = 1<<5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_RRF_PTMP_ONLY = 1<<6,
- NL80211_RRF_PASSIVE_SCAN = 1<<7,
- NL80211_RRF_NO_IBSS = 1<<8,
-};
+ NL80211_RRF_NO_IR = 1<<7,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NL80211_RRF_NO_IBSS = 1<<8,
+};
+#define NL80211_RRF_PASSIVE_SCAN NL80211_RRF_NO_IR
+#define NL80211_RRF_NO_IBSS NL80211_RRF_NO_IR
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_RRF_NO_IR NL80211_RRF_NO_IR
+#define NL80211_RRF_NO_IR_ALL (NL80211_RRF_NO_IR | __NL80211_RRF_NO_IBSS)
 enum nl80211_dfs_regions {
  NL80211_DFS_UNSET = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_DFS_FCC = 1,
  NL80211_DFS_ETSI = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_DFS_JP = 3,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_user_reg_hint_type {
  NL80211_USER_REG_HINT_USER = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_USER_REG_HINT_CELL_BASE = 1,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_survey_info {
  __NL80211_SURVEY_INFO_INVALID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_SURVEY_INFO_FREQUENCY,
  NL80211_SURVEY_INFO_NOISE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_SURVEY_INFO_IN_USE,
  NL80211_SURVEY_INFO_CHANNEL_TIME,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
  NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
  NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_SURVEY_INFO_AFTER_LAST,
  NL80211_SURVEY_INFO_MAX = __NL80211_SURVEY_INFO_AFTER_LAST - 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_mntr_flags {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_MNTR_FLAG_INVALID,
  NL80211_MNTR_FLAG_FCSFAIL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MNTR_FLAG_PLCPFAIL,
  NL80211_MNTR_FLAG_CONTROL,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MNTR_FLAG_OTHER_BSS,
  NL80211_MNTR_FLAG_COOK_FRAMES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_MNTR_FLAG_ACTIVE,
  __NL80211_MNTR_FLAG_AFTER_LAST,
  NL80211_MNTR_FLAG_MAX = __NL80211_MNTR_FLAG_AFTER_LAST - 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_mesh_power_mode {
  NL80211_MESH_POWER_UNKNOWN,
  NL80211_MESH_POWER_ACTIVE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESH_POWER_LIGHT_SLEEP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESH_POWER_DEEP_SLEEP,
  __NL80211_MESH_POWER_AFTER_LAST,
  NL80211_MESH_POWER_MAX = __NL80211_MESH_POWER_AFTER_LAST - 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_meshconf_params {
  __NL80211_MESHCONF_INVALID,
  NL80211_MESHCONF_RETRY_TIMEOUT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_CONFIRM_TIMEOUT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_HOLDING_TIMEOUT,
  NL80211_MESHCONF_MAX_PEER_LINKS,
  NL80211_MESHCONF_MAX_RETRIES,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_TTL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_AUTO_OPEN_PLINKS,
  NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  NL80211_MESHCONF_PATH_REFRESH_TIME,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_HWMP_ROOTMODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_ELEMENT_TTL,
  NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_FORWARDING,
  NL80211_MESHCONF_RSSI_THRESHOLD,
  NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_HT_OPMODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
  NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
  NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_POWER_MODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESHCONF_AWAKE_WINDOW,
+ NL80211_MESHCONF_PLINK_TIMEOUT,
  __NL80211_MESHCONF_ATTR_AFTER_LAST,
  NL80211_MESHCONF_ATTR_MAX = __NL80211_MESHCONF_ATTR_AFTER_LAST - 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -783,53 +828,63 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC,
  NL80211_MESH_SETUP_USERSPACE_MPM,
+ NL80211_MESH_SETUP_AUTH_PROTOCOL,
  __NL80211_MESH_SETUP_ATTR_AFTER_LAST,
- NL80211_MESH_SETUP_ATTR_MAX = __NL80211_MESH_SETUP_ATTR_AFTER_LAST - 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_MESH_SETUP_ATTR_MAX = __NL80211_MESH_SETUP_ATTR_AFTER_LAST - 1
 };
 enum nl80211_txq_attr {
  __NL80211_TXQ_ATTR_INVALID,
- NL80211_TXQ_ATTR_AC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_TXQ_ATTR_AC,
  NL80211_TXQ_ATTR_TXOP,
  NL80211_TXQ_ATTR_CWMIN,
  NL80211_TXQ_ATTR_CWMAX,
- NL80211_TXQ_ATTR_AIFS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_TXQ_ATTR_AIFS,
  __NL80211_TXQ_ATTR_AFTER_LAST,
  NL80211_TXQ_ATTR_MAX = __NL80211_TXQ_ATTR_AFTER_LAST - 1
 };
-enum nl80211_ac {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nl80211_ac {
  NL80211_AC_VO,
  NL80211_AC_VI,
  NL80211_AC_BE,
- NL80211_AC_BK,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_AC_BK,
  NL80211_NUM_ACS
 };
 #define NL80211_TXQ_ATTR_QUEUE NL80211_TXQ_ATTR_AC
-#define NL80211_TXQ_Q_VO NL80211_AC_VO
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL80211_TXQ_Q_VO NL80211_AC_VO
 #define NL80211_TXQ_Q_VI NL80211_AC_VI
 #define NL80211_TXQ_Q_BE NL80211_AC_BE
 #define NL80211_TXQ_Q_BK NL80211_AC_BK
-enum nl80211_channel_type {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nl80211_channel_type {
  NL80211_CHAN_NO_HT,
  NL80211_CHAN_HT20,
  NL80211_CHAN_HT40MINUS,
- NL80211_CHAN_HT40PLUS
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CHAN_HT40PLUS
 };
 enum nl80211_chan_width {
  NL80211_CHAN_WIDTH_20_NOHT,
- NL80211_CHAN_WIDTH_20,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_CHAN_WIDTH_20,
  NL80211_CHAN_WIDTH_40,
  NL80211_CHAN_WIDTH_80,
  NL80211_CHAN_WIDTH_80P80,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_CHAN_WIDTH_160,
+ NL80211_CHAN_WIDTH_5,
+ NL80211_CHAN_WIDTH_10,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nl80211_bss_scan_width {
+ NL80211_BSS_CHAN_WIDTH_20,
+ NL80211_BSS_CHAN_WIDTH_10,
+ NL80211_BSS_CHAN_WIDTH_5,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_bss {
@@ -848,306 +903,346 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_BSS_SEEN_MS_AGO,
  NL80211_BSS_BEACON_IES,
+ NL80211_BSS_CHAN_WIDTH,
  __NL80211_BSS_AFTER_LAST,
- NL80211_BSS_MAX = __NL80211_BSS_AFTER_LAST - 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_BSS_MAX = __NL80211_BSS_AFTER_LAST - 1
 };
 enum nl80211_bss_status {
  NL80211_BSS_STATUS_AUTHENTICATED,
- NL80211_BSS_STATUS_ASSOCIATED,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_BSS_STATUS_ASSOCIATED,
  NL80211_BSS_STATUS_IBSS_JOINED,
 };
 enum nl80211_auth_type {
- NL80211_AUTHTYPE_OPEN_SYSTEM,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_AUTHTYPE_OPEN_SYSTEM,
  NL80211_AUTHTYPE_SHARED_KEY,
  NL80211_AUTHTYPE_FT,
  NL80211_AUTHTYPE_NETWORK_EAP,
- NL80211_AUTHTYPE_SAE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_AUTHTYPE_SAE,
  __NL80211_AUTHTYPE_NUM,
  NL80211_AUTHTYPE_MAX = __NL80211_AUTHTYPE_NUM - 1,
  NL80211_AUTHTYPE_AUTOMATIC
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum nl80211_key_type {
  NL80211_KEYTYPE_GROUP,
  NL80211_KEYTYPE_PAIRWISE,
- NL80211_KEYTYPE_PEERKEY,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_KEYTYPE_PEERKEY,
  NUM_NL80211_KEYTYPES
 };
 enum nl80211_mfp {
- NL80211_MFP_NO,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_MFP_NO,
  NL80211_MFP_REQUIRED,
 };
 enum nl80211_wpa_versions {
- NL80211_WPA_VERSION_1 = 1 << 0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_WPA_VERSION_1 = 1 << 0,
  NL80211_WPA_VERSION_2 = 1 << 1,
 };
 enum nl80211_key_default_types {
- __NL80211_KEY_DEFAULT_TYPE_INVALID,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __NL80211_KEY_DEFAULT_TYPE_INVALID,
  NL80211_KEY_DEFAULT_TYPE_UNICAST,
  NL80211_KEY_DEFAULT_TYPE_MULTICAST,
  NUM_NL80211_KEY_DEFAULT_TYPES
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum nl80211_key_attributes {
  __NL80211_KEY_INVALID,
  NL80211_KEY_DATA,
- NL80211_KEY_IDX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_KEY_IDX,
  NL80211_KEY_CIPHER,
  NL80211_KEY_SEQ,
  NL80211_KEY_DEFAULT,
- NL80211_KEY_DEFAULT_MGMT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_KEY_DEFAULT_MGMT,
  NL80211_KEY_TYPE,
  NL80211_KEY_DEFAULT_TYPES,
  __NL80211_KEY_AFTER_LAST,
- NL80211_KEY_MAX = __NL80211_KEY_AFTER_LAST - 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_KEY_MAX = __NL80211_KEY_AFTER_LAST - 1
 };
 enum nl80211_tx_rate_attributes {
  __NL80211_TXRATE_INVALID,
- NL80211_TXRATE_LEGACY,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- NL80211_TXRATE_MCS,
+ NL80211_TXRATE_LEGACY,
+ NL80211_TXRATE_HT,
+ NL80211_TXRATE_VHT,
  __NL80211_TXRATE_AFTER_LAST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_TXRATE_MAX = __NL80211_TXRATE_AFTER_LAST - 1
 };
+#define NL80211_TXRATE_MCS NL80211_TXRATE_HT
+#define NL80211_VHT_NSS_MAX 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct nl80211_txrate_vht {
+ __u16 mcs[NL80211_VHT_NSS_MAX];
+};
 enum nl80211_band {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_BAND_2GHZ,
  NL80211_BAND_5GHZ,
  NL80211_BAND_60GHZ,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_ps_state {
  NL80211_PS_DISABLED,
  NL80211_PS_ENABLED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_attr_cqm {
  __NL80211_ATTR_CQM_INVALID,
  NL80211_ATTR_CQM_RSSI_THOLD,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CQM_RSSI_HYST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
  NL80211_ATTR_CQM_PKT_LOSS_EVENT,
  NL80211_ATTR_CQM_TXE_RATE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CQM_TXE_PKTS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_ATTR_CQM_TXE_INTVL,
  __NL80211_ATTR_CQM_AFTER_LAST,
  NL80211_ATTR_CQM_MAX = __NL80211_ATTR_CQM_AFTER_LAST - 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_cqm_rssi_threshold_event {
  NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_tx_power_setting {
  NL80211_TX_POWER_AUTOMATIC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_TX_POWER_LIMITED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_TX_POWER_FIXED,
 };
-enum nl80211_wowlan_packet_pattern_attr {
+enum nl80211_packet_pattern_attr {
+ __NL80211_PKTPAT_INVALID,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __NL80211_WOWLAN_PKTPAT_INVALID,
- NL80211_WOWLAN_PKTPAT_MASK,
- NL80211_WOWLAN_PKTPAT_PATTERN,
- NL80211_WOWLAN_PKTPAT_OFFSET,
+ NL80211_PKTPAT_MASK,
+ NL80211_PKTPAT_PATTERN,
+ NL80211_PKTPAT_OFFSET,
+ NUM_NL80211_PKTPAT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- NUM_NL80211_WOWLAN_PKTPAT,
- MAX_NL80211_WOWLAN_PKTPAT = NUM_NL80211_WOWLAN_PKTPAT - 1,
+ MAX_NL80211_PKTPAT = NUM_NL80211_PKTPAT - 1,
 };
-struct nl80211_wowlan_pattern_support {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct nl80211_pattern_support {
  __u32 max_patterns;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 min_pattern_len;
  __u32 max_pattern_len;
  __u32 max_pkt_offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__((packed));
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __NL80211_WOWLAN_PKTPAT_INVALID __NL80211_PKTPAT_INVALID
+#define NL80211_WOWLAN_PKTPAT_MASK NL80211_PKTPAT_MASK
+#define NL80211_WOWLAN_PKTPAT_PATTERN NL80211_PKTPAT_PATTERN
+#define NL80211_WOWLAN_PKTPAT_OFFSET NL80211_PKTPAT_OFFSET
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NUM_NL80211_WOWLAN_PKTPAT NUM_NL80211_PKTPAT
+#define MAX_NL80211_WOWLAN_PKTPAT MAX_NL80211_PKTPAT
+#define nl80211_wowlan_pattern_support nl80211_pattern_support
 enum nl80211_wowlan_triggers {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_WOWLAN_TRIG_INVALID,
  NL80211_WOWLAN_TRIG_ANY,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TRIG_DISCONNECT,
  NL80211_WOWLAN_TRIG_MAGIC_PKT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TRIG_PKT_PATTERN,
  NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE,
  NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE,
  NL80211_WOWLAN_TRIG_RFKILL_RELEASE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211,
  NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023,
  NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TRIG_TCP_CONNECTION,
  NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST,
  NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NUM_NL80211_WOWLAN_TRIG,
  MAX_NL80211_WOWLAN_TRIG = NUM_NL80211_WOWLAN_TRIG - 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct nl80211_wowlan_tcp_data_seq {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 start, offset, len;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct nl80211_wowlan_tcp_data_token {
  __u32 offset, len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 token_stream[];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct nl80211_wowlan_tcp_data_token_feature {
  __u32 min_len, max_len, bufsize;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_wowlan_tcp_attrs {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_WOWLAN_TCP_INVALID,
  NL80211_WOWLAN_TCP_SRC_IPV4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TCP_DST_IPV4,
  NL80211_WOWLAN_TCP_DST_MAC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TCP_SRC_PORT,
  NL80211_WOWLAN_TCP_DST_PORT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
  NL80211_WOWLAN_TCP_DATA_INTERVAL,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
  NL80211_WOWLAN_TCP_WAKE_MASK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NUM_NL80211_WOWLAN_TCP,
  MAX_NL80211_WOWLAN_TCP = NUM_NL80211_WOWLAN_TCP - 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+struct nl80211_coalesce_rule_support {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 max_rules;
+ struct nl80211_pattern_support pat;
+ __u32 max_delay;
+} __attribute__((packed));
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nl80211_attr_coalesce_rule {
+ __NL80211_COALESCE_RULE_INVALID,
+ NL80211_ATTR_COALESCE_RULE_DELAY,
+ NL80211_ATTR_COALESCE_RULE_CONDITION,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL80211_ATTR_COALESCE_RULE_PKT_PATTERN,
+ NUM_NL80211_ATTR_COALESCE_RULE,
+ NL80211_ATTR_COALESCE_RULE_MAX = NUM_NL80211_ATTR_COALESCE_RULE - 1
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nl80211_coalesce_condition {
+ NL80211_COALESCE_CONDITION_MATCH,
+ NL80211_COALESCE_CONDITION_NO_MATCH
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_iface_limit_attrs {
  NL80211_IFACE_LIMIT_UNSPEC,
  NL80211_IFACE_LIMIT_MAX,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_IFACE_LIMIT_TYPES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NUM_NL80211_IFACE_LIMIT,
  MAX_NL80211_IFACE_LIMIT = NUM_NL80211_IFACE_LIMIT - 1
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_if_combination_attrs {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_IFACE_COMB_UNSPEC,
  NL80211_IFACE_COMB_LIMITS,
  NL80211_IFACE_COMB_MAXNUM,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_IFACE_COMB_STA_AP_BI_MATCH,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_IFACE_COMB_NUM_CHANNELS,
  NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
  NUM_NL80211_IFACE_COMB,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  MAX_NL80211_IFACE_COMB = NUM_NL80211_IFACE_COMB - 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_plink_state {
  NL80211_PLINK_LISTEN,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_PLINK_OPN_SNT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_PLINK_OPN_RCVD,
  NL80211_PLINK_CNF_RCVD,
  NL80211_PLINK_ESTAB,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_PLINK_HOLDING,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_PLINK_BLOCKED,
  NUM_NL80211_PLINK_STATES,
  MAX_NL80211_PLINK_STATES = NUM_NL80211_PLINK_STATES - 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum plink_actions {
  NL80211_PLINK_ACTION_NO_ACTION,
  NL80211_PLINK_ACTION_OPEN,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_PLINK_ACTION_BLOCK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NUM_NL80211_PLINK_ACTIONS,
 };
 #define NL80211_KCK_LEN 16
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_KEK_LEN 16
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define NL80211_REPLAY_CTR_LEN 8
 enum nl80211_rekey_data {
  __NL80211_REKEY_DATA_INVALID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_REKEY_DATA_KEK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_REKEY_DATA_KCK,
  NL80211_REKEY_DATA_REPLAY_CTR,
  NUM_NL80211_REKEY_DATA,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  MAX_NL80211_REKEY_DATA = NUM_NL80211_REKEY_DATA - 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_hidden_ssid {
  NL80211_HIDDEN_SSID_NOT_IN_USE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_HIDDEN_SSID_ZERO_LEN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_HIDDEN_SSID_ZERO_CONTENTS
 };
 enum nl80211_sta_wme_attr {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __NL80211_STA_WME_INVALID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_STA_WME_UAPSD_QUEUES,
  NL80211_STA_WME_MAX_SP,
  __NL80211_STA_WME_AFTER_LAST,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_STA_WME_MAX = __NL80211_STA_WME_AFTER_LAST - 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_pmksa_candidate_attr {
  __NL80211_PMKSA_CANDIDATE_INVALID,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_PMKSA_CANDIDATE_INDEX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_PMKSA_CANDIDATE_BSSID,
  NL80211_PMKSA_CANDIDATE_PREAUTH,
  NUM_NL80211_PMKSA_CANDIDATE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  MAX_NL80211_PMKSA_CANDIDATE = NUM_NL80211_PMKSA_CANDIDATE - 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum nl80211_tdls_operation {
  NL80211_TDLS_DISCOVERY_REQ,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_TDLS_SETUP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_TDLS_TEARDOWN,
  NL80211_TDLS_ENABLE_LINK,
  NL80211_TDLS_DISABLE_LINK,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum nl80211_feature_flags {
  NL80211_FEATURE_SK_TX_STATUS = 1 << 0,
  NL80211_FEATURE_HT_IBSS = 1 << 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FEATURE_INACTIVITY_TIMER = 1 << 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FEATURE_CELL_BASE_REG_HINTS = 1 << 3,
  NL80211_FEATURE_P2P_DEVICE_NEEDS_CHANNEL = 1 << 4,
  NL80211_FEATURE_SAE = 1 << 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FEATURE_LOW_PRIORITY_SCAN = 1 << 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FEATURE_SCAN_FLUSH = 1 << 7,
  NL80211_FEATURE_AP_SCAN = 1 << 8,
  NL80211_FEATURE_VIF_TXPOWER = 1 << 9,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FEATURE_NEED_OBSS_SCAN = 1 << 10,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FEATURE_P2P_GO_CTWIN = 1 << 11,
  NL80211_FEATURE_P2P_GO_OPPPS = 1 << 12,
  NL80211_FEATURE_ADVERTISE_CHAN_LIMITS = 1 << 14,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FEATURE_FULL_AP_CLIENT_STATE = 1 << 15,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NL80211_FEATURE_USERSPACE_MPM = 1 << 16,
+ NL80211_FEATURE_ACTIVE_MONITOR = 1 << 17,
 };
 enum nl80211_probe_resp_offload_support_attr {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -1201,4 +1296,14 @@
 };
 #define NL80211_CRIT_PROTO_MAX_DURATION 5000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nl80211_rxmgmt_flags {
+ NL80211_RXMGMT_FLAG_ANSWERED = 1 << 0,
+};
+#define NL80211_VENDOR_ID_IS_LINUX 0x80000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct nl80211_vendor_cmd_info {
+ __u32 vendor_id;
+ __u32 subcmd;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/nvme.h b/libc/kernel/uapi/linux/nvme.h
new file mode 100644
index 0000000..eedea90
--- /dev/null
+++ b/libc/kernel/uapi/linux/nvme.h
@@ -0,0 +1,554 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI_LINUX_NVME_H
+#define _UAPI_LINUX_NVME_H
+#include <linux/types.h>
+struct nvme_id_power_state {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 max_power;
+ __u8 rsvd2;
+ __u8 flags;
+ __le32 entry_lat;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 exit_lat;
+ __u8 read_tput;
+ __u8 read_lat;
+ __u8 write_tput;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 write_lat;
+ __u8 rsvd16[16];
+};
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_PS_FLAGS_MAX_POWER_SCALE = 1 << 0,
+ NVME_PS_FLAGS_NON_OP_STATE = 1 << 1,
+};
+struct nvme_id_ctrl {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 vid;
+ __le16 ssvid;
+ char sn[20];
+ char mn[40];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ char fr[8];
+ __u8 rab;
+ __u8 ieee[3];
+ __u8 mic;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 mdts;
+ __u8 rsvd78[178];
+ __le16 oacs;
+ __u8 acl;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 aerl;
+ __u8 frmw;
+ __u8 lpa;
+ __u8 elpe;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 npss;
+ __u8 rsvd264[248];
+ __u8 sqes;
+ __u8 cqes;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 rsvd514[2];
+ __le32 nn;
+ __le16 oncs;
+ __le16 fuses;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 fna;
+ __u8 vwc;
+ __le16 awun;
+ __le16 awupf;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 rsvd530[1518];
+ struct nvme_id_power_state psd[32];
+ __u8 vs[1024];
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
+ NVME_CTRL_ONCS_COMPARE = 1 << 0,
+ NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1,
+ NVME_CTRL_ONCS_DSM = 1 << 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct nvme_lbaf {
+ __le16 ms;
+ __u8 ds;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 rp;
+};
+struct nvme_id_ns {
+ __le64 nsze;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le64 ncap;
+ __le64 nuse;
+ __u8 nsfeat;
+ __u8 nlbaf;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 flbas;
+ __u8 mc;
+ __u8 dpc;
+ __u8 dps;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 rsvd30[98];
+ struct nvme_lbaf lbaf[16];
+ __u8 rsvd192[192];
+ __u8 vs[3712];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum {
+ NVME_NS_FEAT_THIN = 1 << 0,
+ NVME_LBAF_RP_BEST = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_LBAF_RP_BETTER = 1,
+ NVME_LBAF_RP_GOOD = 2,
+ NVME_LBAF_RP_DEGRADED = 3,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct nvme_smart_log {
+ __u8 critical_warning;
+ __u8 temperature[2];
+ __u8 avail_spare;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 spare_thresh;
+ __u8 percent_used;
+ __u8 rsvd6[26];
+ __u8 data_units_read[16];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 data_units_written[16];
+ __u8 host_reads[16];
+ __u8 host_writes[16];
+ __u8 ctrl_busy_time[16];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 power_cycles[16];
+ __u8 power_on_hours[16];
+ __u8 unsafe_shutdowns[16];
+ __u8 media_errors[16];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 num_err_log_entries[16];
+ __u8 rsvd192[320];
+};
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SMART_CRIT_SPARE = 1 << 0,
+ NVME_SMART_CRIT_TEMPERATURE = 1 << 1,
+ NVME_SMART_CRIT_RELIABILITY = 1 << 2,
+ NVME_SMART_CRIT_MEDIA = 1 << 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SMART_CRIT_VOLATILE_MEMORY = 1 << 4,
+};
+struct nvme_lba_range_type {
+ __u8 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 attributes;
+ __u8 rsvd2[14];
+ __u64 slba;
+ __u64 nlb;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 guid[16];
+ __u8 rsvd48[16];
+};
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_LBART_TYPE_FS = 0x01,
+ NVME_LBART_TYPE_RAID = 0x02,
+ NVME_LBART_TYPE_CACHE = 0x03,
+ NVME_LBART_TYPE_SWAP = 0x04,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_LBART_ATTRIB_TEMP = 1 << 0,
+ NVME_LBART_ATTRIB_HIDE = 1 << 1,
+};
+enum nvme_opcode {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ nvme_cmd_flush = 0x00,
+ nvme_cmd_write = 0x01,
+ nvme_cmd_read = 0x02,
+ nvme_cmd_write_uncor = 0x04,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ nvme_cmd_compare = 0x05,
+ nvme_cmd_dsm = 0x09,
+};
+struct nvme_common_command {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 opcode;
+ __u8 flags;
+ __u16 command_id;
+ __le32 nsid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 cdw2[2];
+ __le64 metadata;
+ __le64 prp1;
+ __le64 prp2;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 cdw10[6];
+};
+struct nvme_rw_command {
+ __u8 opcode;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 flags;
+ __u16 command_id;
+ __le32 nsid;
+ __u64 rsvd2;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le64 metadata;
+ __le64 prp1;
+ __le64 prp2;
+ __le64 slba;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 length;
+ __le16 control;
+ __le32 dsmgmt;
+ __le32 reftag;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 apptag;
+ __le16 appmask;
+};
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_RW_LR = 1 << 15,
+ NVME_RW_FUA = 1 << 14,
+ NVME_RW_DSM_FREQ_UNSPEC = 0,
+ NVME_RW_DSM_FREQ_TYPICAL = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_RW_DSM_FREQ_RARE = 2,
+ NVME_RW_DSM_FREQ_READS = 3,
+ NVME_RW_DSM_FREQ_WRITES = 4,
+ NVME_RW_DSM_FREQ_RW = 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_RW_DSM_FREQ_ONCE = 6,
+ NVME_RW_DSM_FREQ_PREFETCH = 7,
+ NVME_RW_DSM_FREQ_TEMP = 8,
+ NVME_RW_DSM_LATENCY_NONE = 0 << 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
+ NVME_RW_DSM_LATENCY_NORM = 2 << 4,
+ NVME_RW_DSM_LATENCY_LOW = 3 << 4,
+ NVME_RW_DSM_SEQ_REQ = 1 << 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_RW_DSM_COMPRESSED = 1 << 7,
+};
+struct nvme_dsm_cmd {
+ __u8 opcode;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 flags;
+ __u16 command_id;
+ __le32 nsid;
+ __u64 rsvd2[2];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le64 prp1;
+ __le64 prp2;
+ __le32 nr;
+ __le32 attributes;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 rsvd12[4];
+};
+enum {
+ NVME_DSMGMT_IDR = 1 << 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_DSMGMT_IDW = 1 << 1,
+ NVME_DSMGMT_AD = 1 << 2,
+};
+struct nvme_dsm_range {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 cattr;
+ __le32 nlb;
+ __le64 slba;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nvme_admin_opcode {
+ nvme_admin_delete_sq = 0x00,
+ nvme_admin_create_sq = 0x01,
+ nvme_admin_get_log_page = 0x02,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ nvme_admin_delete_cq = 0x04,
+ nvme_admin_create_cq = 0x05,
+ nvme_admin_identify = 0x06,
+ nvme_admin_abort_cmd = 0x08,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ nvme_admin_set_features = 0x09,
+ nvme_admin_get_features = 0x0a,
+ nvme_admin_async_event = 0x0c,
+ nvme_admin_activate_fw = 0x10,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ nvme_admin_download_fw = 0x11,
+ nvme_admin_format_nvm = 0x80,
+ nvme_admin_security_send = 0x81,
+ nvme_admin_security_recv = 0x82,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum {
+ NVME_QUEUE_PHYS_CONTIG = (1 << 0),
+ NVME_CQ_IRQ_ENABLED = (1 << 1),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SQ_PRIO_URGENT = (0 << 1),
+ NVME_SQ_PRIO_HIGH = (1 << 1),
+ NVME_SQ_PRIO_MEDIUM = (2 << 1),
+ NVME_SQ_PRIO_LOW = (3 << 1),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_FEAT_ARBITRATION = 0x01,
+ NVME_FEAT_POWER_MGMT = 0x02,
+ NVME_FEAT_LBA_RANGE = 0x03,
+ NVME_FEAT_TEMP_THRESH = 0x04,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_FEAT_ERR_RECOVERY = 0x05,
+ NVME_FEAT_VOLATILE_WC = 0x06,
+ NVME_FEAT_NUM_QUEUES = 0x07,
+ NVME_FEAT_IRQ_COALESCE = 0x08,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_FEAT_IRQ_CONFIG = 0x09,
+ NVME_FEAT_WRITE_ATOMIC = 0x0a,
+ NVME_FEAT_ASYNC_EVENT = 0x0b,
+ NVME_FEAT_SW_PROGRESS = 0x0c,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_FWACT_REPL = (0 << 3),
+ NVME_FWACT_REPL_ACTV = (1 << 3),
+ NVME_FWACT_ACTV = (2 << 3),
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct nvme_identify {
+ __u8 opcode;
+ __u8 flags;
+ __u16 command_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 nsid;
+ __u64 rsvd2[2];
+ __le64 prp1;
+ __le64 prp2;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 cns;
+ __u32 rsvd11[5];
+};
+struct nvme_features {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 opcode;
+ __u8 flags;
+ __u16 command_id;
+ __le32 nsid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 rsvd2[2];
+ __le64 prp1;
+ __le64 prp2;
+ __le32 fid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 dword11;
+ __u32 rsvd12[4];
+};
+struct nvme_create_cq {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 opcode;
+ __u8 flags;
+ __u16 command_id;
+ __u32 rsvd1[5];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le64 prp1;
+ __u64 rsvd8;
+ __le16 cqid;
+ __le16 qsize;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 cq_flags;
+ __le16 irq_vector;
+ __u32 rsvd12[4];
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct nvme_create_sq {
+ __u8 opcode;
+ __u8 flags;
+ __u16 command_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 rsvd1[5];
+ __le64 prp1;
+ __u64 rsvd8;
+ __le16 sqid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 qsize;
+ __le16 sq_flags;
+ __le16 cqid;
+ __u32 rsvd12[4];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct nvme_delete_queue {
+ __u8 opcode;
+ __u8 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 command_id;
+ __u32 rsvd1[9];
+ __le16 qid;
+ __u16 rsvd10;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 rsvd11[5];
+};
+struct nvme_abort_cmd {
+ __u8 opcode;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 flags;
+ __u16 command_id;
+ __u32 rsvd1[9];
+ __le16 sqid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 cid;
+ __u32 rsvd11[5];
+};
+struct nvme_download_firmware {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 opcode;
+ __u8 flags;
+ __u16 command_id;
+ __u32 rsvd1[5];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le64 prp1;
+ __le64 prp2;
+ __le32 numd;
+ __le32 offset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 rsvd12[4];
+};
+struct nvme_format_cmd {
+ __u8 opcode;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 flags;
+ __u16 command_id;
+ __le32 nsid;
+ __u64 rsvd2[4];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 cdw10;
+ __u32 rsvd11[5];
+};
+struct nvme_command {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union {
+ struct nvme_common_command common;
+ struct nvme_rw_command rw;
+ struct nvme_identify identify;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct nvme_features features;
+ struct nvme_create_cq create_cq;
+ struct nvme_create_sq create_sq;
+ struct nvme_delete_queue delete_queue;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct nvme_download_firmware dlfw;
+ struct nvme_format_cmd format;
+ struct nvme_dsm_cmd dsm;
+ struct nvme_abort_cmd abort;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ };
+};
+enum {
+ NVME_SC_SUCCESS = 0x0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_INVALID_OPCODE = 0x1,
+ NVME_SC_INVALID_FIELD = 0x2,
+ NVME_SC_CMDID_CONFLICT = 0x3,
+ NVME_SC_DATA_XFER_ERROR = 0x4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_POWER_LOSS = 0x5,
+ NVME_SC_INTERNAL = 0x6,
+ NVME_SC_ABORT_REQ = 0x7,
+ NVME_SC_ABORT_QUEUE = 0x8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_FUSED_FAIL = 0x9,
+ NVME_SC_FUSED_MISSING = 0xa,
+ NVME_SC_INVALID_NS = 0xb,
+ NVME_SC_CMD_SEQ_ERROR = 0xc,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_LBA_RANGE = 0x80,
+ NVME_SC_CAP_EXCEEDED = 0x81,
+ NVME_SC_NS_NOT_READY = 0x82,
+ NVME_SC_CQ_INVALID = 0x100,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_QID_INVALID = 0x101,
+ NVME_SC_QUEUE_SIZE = 0x102,
+ NVME_SC_ABORT_LIMIT = 0x103,
+ NVME_SC_ABORT_MISSING = 0x104,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_ASYNC_LIMIT = 0x105,
+ NVME_SC_FIRMWARE_SLOT = 0x106,
+ NVME_SC_FIRMWARE_IMAGE = 0x107,
+ NVME_SC_INVALID_VECTOR = 0x108,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_INVALID_LOG_PAGE = 0x109,
+ NVME_SC_INVALID_FORMAT = 0x10a,
+ NVME_SC_BAD_ATTRIBUTES = 0x180,
+ NVME_SC_WRITE_FAULT = 0x280,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_READ_ERROR = 0x281,
+ NVME_SC_GUARD_CHECK = 0x282,
+ NVME_SC_APPTAG_CHECK = 0x283,
+ NVME_SC_REFTAG_CHECK = 0x284,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NVME_SC_COMPARE_FAILED = 0x285,
+ NVME_SC_ACCESS_DENIED = 0x286,
+};
+struct nvme_completion {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 result;
+ __u32 rsvd;
+ __le16 sq_head;
+ __le16 sq_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 command_id;
+ __le16 status;
+};
+struct nvme_user_io {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 opcode;
+ __u8 flags;
+ __u16 control;
+ __u16 nblocks;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 rsvd;
+ __u64 metadata;
+ __u64 addr;
+ __u64 slba;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 dsmgmt;
+ __u32 reftag;
+ __u16 apptag;
+ __u16 appmask;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct nvme_admin_cmd {
+ __u8 opcode;
+ __u8 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 rsvd1;
+ __u32 nsid;
+ __u32 cdw2;
+ __u32 cdw3;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 metadata;
+ __u64 addr;
+ __u32 metadata_len;
+ __u32 data_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 cdw10;
+ __u32 cdw11;
+ __u32 cdw12;
+ __u32 cdw13;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 cdw14;
+ __u32 cdw15;
+ __u32 timeout_ms;
+ __u32 result;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NVME_IOCTL_ID _IO('N', 0x40)
+#define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd)
+#define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/openvswitch.h b/libc/kernel/uapi/linux/openvswitch.h
index affc3d6..9649b6b 100644
--- a/libc/kernel/uapi/linux/openvswitch.h
+++ b/libc/kernel/uapi/linux/openvswitch.h
@@ -27,264 +27,312 @@
 #define OVS_DATAPATH_FAMILY "ovs_datapath"
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVS_DATAPATH_MCGROUP "ovs_datapath"
-#define OVS_DATAPATH_VERSION 0x1
+#define OVS_DATAPATH_VERSION 2
+#define OVS_DP_VER_FEATURES 2
 enum ovs_datapath_cmd {
- OVS_DP_CMD_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_DP_CMD_UNSPEC,
  OVS_DP_CMD_NEW,
  OVS_DP_CMD_DEL,
  OVS_DP_CMD_GET,
- OVS_DP_CMD_SET
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_DP_CMD_SET
 };
 enum ovs_datapath_attr {
  OVS_DP_ATTR_UNSPEC,
- OVS_DP_ATTR_NAME,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_DP_ATTR_NAME,
  OVS_DP_ATTR_UPCALL_PID,
  OVS_DP_ATTR_STATS,
+ OVS_DP_ATTR_MEGAFLOW_STATS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_DP_ATTR_USER_FEATURES,
  __OVS_DP_ATTR_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVS_DP_ATTR_MAX (__OVS_DP_ATTR_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ovs_dp_stats {
  __u64 n_hit;
  __u64 n_missed;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 n_lost;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 n_flows;
 };
-struct ovs_vport_stats {
+struct ovs_dp_megaflow_stats {
+ __u64 n_mask_hit;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u64 rx_packets;
- __u64 tx_packets;
- __u64 rx_bytes;
- __u64 tx_bytes;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u64 rx_errors;
- __u64 tx_errors;
- __u64 rx_dropped;
- __u64 tx_dropped;
+ __u32 n_masks;
+ __u32 pad0;
+ __u64 pad1;
+ __u64 pad2;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+struct ovs_vport_stats {
+ __u64 rx_packets;
+ __u64 tx_packets;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 rx_bytes;
+ __u64 tx_bytes;
+ __u64 rx_errors;
+ __u64 tx_errors;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 rx_dropped;
+ __u64 tx_dropped;
+};
+#define OVS_DP_F_UNALIGNED (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVSP_LOCAL ((__u32)0)
 #define OVS_PACKET_FAMILY "ovs_packet"
 #define OVS_PACKET_VERSION 0x1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ovs_packet_cmd {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_PACKET_CMD_UNSPEC,
  OVS_PACKET_CMD_MISS,
  OVS_PACKET_CMD_ACTION,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_PACKET_CMD_EXECUTE
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum ovs_packet_attr {
  OVS_PACKET_ATTR_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_PACKET_ATTR_PACKET,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_PACKET_ATTR_KEY,
  OVS_PACKET_ATTR_ACTIONS,
  OVS_PACKET_ATTR_USERDATA,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __OVS_PACKET_ATTR_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define OVS_PACKET_ATTR_MAX (__OVS_PACKET_ATTR_MAX - 1)
 #define OVS_VPORT_FAMILY "ovs_vport"
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVS_VPORT_MCGROUP "ovs_vport"
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVS_VPORT_VERSION 0x1
 enum ovs_vport_cmd {
  OVS_VPORT_CMD_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_VPORT_CMD_NEW,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_VPORT_CMD_DEL,
  OVS_VPORT_CMD_GET,
  OVS_VPORT_CMD_SET
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ovs_vport_type {
  OVS_VPORT_TYPE_UNSPEC,
  OVS_VPORT_TYPE_NETDEV,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_VPORT_TYPE_INTERNAL,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_VPORT_TYPE_GRE,
+ OVS_VPORT_TYPE_VXLAN,
  __OVS_VPORT_TYPE_MAX
 };
-#define OVS_VPORT_TYPE_MAX (__OVS_VPORT_TYPE_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define OVS_VPORT_TYPE_MAX (__OVS_VPORT_TYPE_MAX - 1)
 enum ovs_vport_attr {
  OVS_VPORT_ATTR_UNSPEC,
  OVS_VPORT_ATTR_PORT_NO,
- OVS_VPORT_ATTR_TYPE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_VPORT_ATTR_TYPE,
  OVS_VPORT_ATTR_NAME,
  OVS_VPORT_ATTR_OPTIONS,
  OVS_VPORT_ATTR_UPCALL_PID,
- OVS_VPORT_ATTR_STATS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_VPORT_ATTR_STATS,
  __OVS_VPORT_ATTR_MAX
 };
 #define OVS_VPORT_ATTR_MAX (__OVS_VPORT_ATTR_MAX - 1)
-#define OVS_FLOW_FAMILY "ovs_flow"
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
+ OVS_TUNNEL_ATTR_UNSPEC,
+ OVS_TUNNEL_ATTR_DST_PORT,
+ __OVS_TUNNEL_ATTR_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define OVS_TUNNEL_ATTR_MAX (__OVS_TUNNEL_ATTR_MAX - 1)
+#define OVS_FLOW_FAMILY "ovs_flow"
 #define OVS_FLOW_MCGROUP "ovs_flow"
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVS_FLOW_VERSION 0x1
 enum ovs_flow_cmd {
  OVS_FLOW_CMD_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_FLOW_CMD_NEW,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_FLOW_CMD_DEL,
  OVS_FLOW_CMD_GET,
  OVS_FLOW_CMD_SET
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ovs_flow_stats {
  __u64 n_packets;
  __u64 n_bytes;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ovs_key_attr {
  OVS_KEY_ATTR_UNSPEC,
  OVS_KEY_ATTR_ENCAP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_KEY_ATTR_PRIORITY,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_KEY_ATTR_IN_PORT,
  OVS_KEY_ATTR_ETHERNET,
  OVS_KEY_ATTR_VLAN,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_KEY_ATTR_ETHERTYPE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_KEY_ATTR_IPV4,
  OVS_KEY_ATTR_IPV6,
  OVS_KEY_ATTR_TCP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_KEY_ATTR_UDP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_KEY_ATTR_ICMP,
  OVS_KEY_ATTR_ICMPV6,
  OVS_KEY_ATTR_ARP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_KEY_ATTR_ND,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_KEY_ATTR_SKB_MARK,
+ OVS_KEY_ATTR_TUNNEL,
+ OVS_KEY_ATTR_SCTP,
+ OVS_KEY_ATTR_TCP_FLAGS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __OVS_KEY_ATTR_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1)
+enum ovs_tunnel_key_attr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_TUNNEL_KEY_ATTR_ID,
+ OVS_TUNNEL_KEY_ATTR_IPV4_SRC,
+ OVS_TUNNEL_KEY_ATTR_IPV4_DST,
+ OVS_TUNNEL_KEY_ATTR_TOS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_TUNNEL_KEY_ATTR_TTL,
+ OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT,
+ OVS_TUNNEL_KEY_ATTR_CSUM,
+ __OVS_TUNNEL_KEY_ATTR_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define OVS_TUNNEL_KEY_ATTR_MAX (__OVS_TUNNEL_KEY_ATTR_MAX - 1)
 enum ovs_frag_type {
  OVS_FRAG_TYPE_NONE,
- OVS_FRAG_TYPE_FIRST,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_FRAG_TYPE_FIRST,
  OVS_FRAG_TYPE_LATER,
  __OVS_FRAG_TYPE_MAX
 };
-#define OVS_FRAG_TYPE_MAX (__OVS_FRAG_TYPE_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define OVS_FRAG_TYPE_MAX (__OVS_FRAG_TYPE_MAX - 1)
 struct ovs_key_ethernet {
  __u8 eth_src[ETH_ALEN];
  __u8 eth_dst[ETH_ALEN];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct ovs_key_ipv4 {
  __be32 ipv4_src;
  __be32 ipv4_dst;
- __u8 ipv4_proto;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 ipv4_proto;
  __u8 ipv4_tos;
  __u8 ipv4_ttl;
  __u8 ipv4_frag;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct ovs_key_ipv6 {
  __be32 ipv6_src[4];
  __be32 ipv6_dst[4];
- __be32 ipv6_label;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 ipv6_label;
  __u8 ipv6_proto;
  __u8 ipv6_tclass;
  __u8 ipv6_hlimit;
- __u8 ipv6_frag;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 ipv6_frag;
 };
 struct ovs_key_tcp {
  __be16 tcp_src;
- __be16 tcp_dst;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 tcp_dst;
 };
 struct ovs_key_udp {
  __be16 udp_src;
- __be16 udp_dst;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 udp_dst;
+};
+struct ovs_key_sctp {
+ __be16 sctp_src;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 sctp_dst;
 };
 struct ovs_key_icmp {
  __u8 icmp_type;
- __u8 icmp_code;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 icmp_code;
 };
 struct ovs_key_icmpv6 {
  __u8 icmpv6_type;
- __u8 icmpv6_code;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 icmpv6_code;
 };
 struct ovs_key_arp {
  __be32 arp_sip;
- __be32 arp_tip;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 arp_tip;
  __be16 arp_op;
  __u8 arp_sha[ETH_ALEN];
  __u8 arp_tha[ETH_ALEN];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct ovs_key_nd {
  __u32 nd_target[4];
  __u8 nd_sll[ETH_ALEN];
- __u8 nd_tll[ETH_ALEN];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 nd_tll[ETH_ALEN];
 };
 enum ovs_flow_attr {
  OVS_FLOW_ATTR_UNSPEC,
- OVS_FLOW_ATTR_KEY,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_FLOW_ATTR_KEY,
  OVS_FLOW_ATTR_ACTIONS,
  OVS_FLOW_ATTR_STATS,
  OVS_FLOW_ATTR_TCP_FLAGS,
- OVS_FLOW_ATTR_USED,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ OVS_FLOW_ATTR_USED,
  OVS_FLOW_ATTR_CLEAR,
+ OVS_FLOW_ATTR_MASK,
  __OVS_FLOW_ATTR_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define OVS_FLOW_ATTR_MAX (__OVS_FLOW_ATTR_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ovs_sample_attr {
  OVS_SAMPLE_ATTR_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_SAMPLE_ATTR_PROBABILITY,
  OVS_SAMPLE_ATTR_ACTIONS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __OVS_SAMPLE_ATTR_MAX,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVS_SAMPLE_ATTR_MAX (__OVS_SAMPLE_ATTR_MAX - 1)
 enum ovs_userspace_attr {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_USERSPACE_ATTR_UNSPEC,
  OVS_USERSPACE_ATTR_PID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_USERSPACE_ATTR_USERDATA,
  __OVS_USERSPACE_ATTR_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define OVS_USERSPACE_ATTR_MAX (__OVS_USERSPACE_ATTR_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ovs_action_push_vlan {
  __be16 vlan_tpid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __be16 vlan_tci;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum ovs_action_attr {
  OVS_ACTION_ATTR_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_ACTION_ATTR_OUTPUT,
  OVS_ACTION_ATTR_USERSPACE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_ACTION_ATTR_SET,
  OVS_ACTION_ATTR_PUSH_VLAN,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  OVS_ACTION_ATTR_POP_VLAN,
  OVS_ACTION_ATTR_SAMPLE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __OVS_ACTION_ATTR_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define OVS_ACTION_ATTR_MAX (__OVS_ACTION_ATTR_MAX - 1)
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/pci_regs.h b/libc/kernel/uapi/linux/pci_regs.h
index a404c97..d20f500 100644
--- a/libc/kernel/uapi/linux/pci_regs.h
+++ b/libc/kernel/uapi/linux/pci_regs.h
@@ -326,194 +326,199 @@
 #define PCI_MSIX_PBA_BIR 0x00000007
 #define PCI_MSIX_PBA_OFFSET 0xfffffff8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_MSIX_FLAGS_BIRMASK (7 << 0)
 #define PCI_CAP_MSIX_SIZEOF 12
 #define PCI_MSIX_ENTRY_SIZE 16
 #define PCI_MSIX_ENTRY_LOWER_ADDR 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_MSIX_ENTRY_UPPER_ADDR 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_MSIX_ENTRY_DATA 8
 #define PCI_MSIX_ENTRY_VECTOR_CTRL 12
 #define PCI_MSIX_ENTRY_CTRL_MASKBIT 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_CHSWP_CSR 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_CHSWP_DHA 0x01
 #define PCI_CHSWP_EIM 0x02
 #define PCI_CHSWP_PIE 0x04
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_CHSWP_LOO 0x08
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_CHSWP_PI 0x30
 #define PCI_CHSWP_EXT 0x40
 #define PCI_CHSWP_INS 0x80
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_AF_LENGTH 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_AF_CAP 3
 #define PCI_AF_CAP_TP 0x01
 #define PCI_AF_CAP_FLR 0x02
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_AF_CTRL 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_AF_CTRL_FLR 0x01
 #define PCI_AF_STATUS 5
 #define PCI_AF_STATUS_TP 0x01
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_CAP_AF_SIZEOF 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD 2
 #define PCI_X_CMD_DPERR_E 0x0001
 #define PCI_X_CMD_ERO 0x0002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD_READ_512 0x0000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD_READ_1K 0x0004
 #define PCI_X_CMD_READ_2K 0x0008
 #define PCI_X_CMD_READ_4K 0x000c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD_MAX_READ 0x000c
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD_SPLIT_1 0x0000
 #define PCI_X_CMD_SPLIT_2 0x0010
 #define PCI_X_CMD_SPLIT_3 0x0020
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD_SPLIT_4 0x0030
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD_SPLIT_8 0x0040
 #define PCI_X_CMD_SPLIT_12 0x0050
 #define PCI_X_CMD_SPLIT_16 0x0060
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD_SPLIT_32 0x0070
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_CMD_MAX_SPLIT 0x0070
 #define PCI_X_CMD_VERSION(x) (((x) >> 12) & 3)
 #define PCI_X_STATUS 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_STATUS_DEVFN 0x000000ff
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_STATUS_BUS 0x0000ff00
 #define PCI_X_STATUS_64BIT 0x00010000
 #define PCI_X_STATUS_133MHZ 0x00020000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_STATUS_SPL_DISC 0x00040000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_STATUS_UNX_SPL 0x00080000
 #define PCI_X_STATUS_COMPLEX 0x00100000
 #define PCI_X_STATUS_MAX_READ 0x00600000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_STATUS_MAX_SPLIT 0x03800000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_STATUS_MAX_CUM 0x1c000000
 #define PCI_X_STATUS_SPL_ERR 0x20000000
 #define PCI_X_STATUS_266MHZ 0x40000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_STATUS_533MHZ 0x80000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_ECC_CSR 8
 #define PCI_CAP_PCIX_SIZEOF_V0 8
 #define PCI_CAP_PCIX_SIZEOF_V1 24
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_CAP_PCIX_SIZEOF_V2 PCI_CAP_PCIX_SIZEOF_V1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_BRIDGE_SSTATUS 2
 #define PCI_X_SSTATUS_64BIT 0x0001
 #define PCI_X_SSTATUS_133MHZ 0x0002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_SSTATUS_FREQ 0x03c0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_SSTATUS_VERS 0x3000
 #define PCI_X_SSTATUS_V1 0x1000
 #define PCI_X_SSTATUS_V2 0x2000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_SSTATUS_266MHZ 0x4000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_X_SSTATUS_533MHZ 0x8000
 #define PCI_X_BRIDGE_STATUS 4
 #define PCI_SSVID_VENDOR_ID 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_SSVID_DEVICE_ID 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_FLAGS 2
 #define PCI_EXP_FLAGS_VERS 0x000f
 #define PCI_EXP_FLAGS_TYPE 0x00f0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_TYPE_ENDPOINT 0x0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_TYPE_LEG_END 0x1
 #define PCI_EXP_TYPE_ROOT_PORT 0x4
 #define PCI_EXP_TYPE_UPSTREAM 0x5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_TYPE_DOWNSTREAM 0x6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_TYPE_PCI_BRIDGE 0x7
 #define PCI_EXP_TYPE_PCIE_BRIDGE 0x8
 #define PCI_EXP_TYPE_RC_END 0x9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_TYPE_RC_EC 0xa
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_FLAGS_SLOT 0x0100
 #define PCI_EXP_FLAGS_IRQ 0x3e00
 #define PCI_EXP_DEVCAP 4
+#define PCI_EXP_DEVCAP_PAYLOAD 0x00000007
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_DEVCAP_PAYLOAD 0x07
-#define PCI_EXP_DEVCAP_PHANTOM 0x18
-#define PCI_EXP_DEVCAP_EXT_TAG 0x20
-#define PCI_EXP_DEVCAP_L0S 0x1c0
+#define PCI_EXP_DEVCAP_PHANTOM 0x00000018
+#define PCI_EXP_DEVCAP_EXT_TAG 0x00000020
+#define PCI_EXP_DEVCAP_L0S 0x000001c0
+#define PCI_EXP_DEVCAP_L1 0x00000e00
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_DEVCAP_L1 0xe00
-#define PCI_EXP_DEVCAP_ATN_BUT 0x1000
-#define PCI_EXP_DEVCAP_ATN_IND 0x2000
-#define PCI_EXP_DEVCAP_PWR_IND 0x4000
+#define PCI_EXP_DEVCAP_ATN_BUT 0x00001000
+#define PCI_EXP_DEVCAP_ATN_IND 0x00002000
+#define PCI_EXP_DEVCAP_PWR_IND 0x00004000
+#define PCI_EXP_DEVCAP_RBER 0x00008000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_DEVCAP_RBER 0x8000
-#define PCI_EXP_DEVCAP_PWR_VAL 0x3fc0000
-#define PCI_EXP_DEVCAP_PWR_SCL 0xc000000
+#define PCI_EXP_DEVCAP_PWR_VAL 0x03fc0000
+#define PCI_EXP_DEVCAP_PWR_SCL 0x0c000000
 #define PCI_EXP_DEVCAP_FLR 0x10000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_DEVCTL 8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_DEVCTL_CERE 0x0001
 #define PCI_EXP_DEVCTL_NFERE 0x0002
 #define PCI_EXP_DEVCTL_FERE 0x0004
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_DEVCTL_URRE 0x0008
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_DEVCTL_RELAX_EN 0x0010
 #define PCI_EXP_DEVCTL_PAYLOAD 0x00e0
 #define PCI_EXP_DEVCTL_EXT_TAG 0x0100
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_DEVCTL_PHANTOM 0x0200
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_DEVCTL_AUX_PME 0x0400
 #define PCI_EXP_DEVCTL_NOSNOOP_EN 0x0800
 #define PCI_EXP_DEVCTL_READRQ 0x7000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_DEVCTL_BCR_FLR 0x8000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_DEVSTA 10
-#define PCI_EXP_DEVSTA_CED 0x01
-#define PCI_EXP_DEVSTA_NFED 0x02
+#define PCI_EXP_DEVSTA_CED 0x0001
+#define PCI_EXP_DEVSTA_NFED 0x0002
+#define PCI_EXP_DEVSTA_FED 0x0004
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_DEVSTA_FED 0x04
-#define PCI_EXP_DEVSTA_URD 0x08
-#define PCI_EXP_DEVSTA_AUXPD 0x10
-#define PCI_EXP_DEVSTA_TRPND 0x20
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXP_DEVSTA_URD 0x0008
+#define PCI_EXP_DEVSTA_AUXPD 0x0010
+#define PCI_EXP_DEVSTA_TRPND 0x0020
 #define PCI_EXP_LNKCAP 12
-#define PCI_EXP_LNKCAP_SLS 0x0000000f
-#define PCI_EXP_LNKCAP_SLS_2_5GB 0x1
-#define PCI_EXP_LNKCAP_SLS_5_0GB 0x2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXP_LNKCAP_SLS 0x0000000f
+#define PCI_EXP_LNKCAP_SLS_2_5GB 0x00000001
+#define PCI_EXP_LNKCAP_SLS_5_0GB 0x00000002
 #define PCI_EXP_LNKCAP_MLW 0x000003f0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKCAP_ASPMS 0x00000c00
 #define PCI_EXP_LNKCAP_L0SEL 0x00007000
 #define PCI_EXP_LNKCAP_L1EL 0x00038000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKCAP_CLKPM 0x00040000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKCAP_SDERC 0x00080000
 #define PCI_EXP_LNKCAP_DLLLARC 0x00100000
 #define PCI_EXP_LNKCAP_LBNC 0x00200000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKCAP_PN 0xff000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKCTL 16
 #define PCI_EXP_LNKCTL_ASPMC 0x0003
-#define PCI_EXP_LNKCTL_ASPM_L0S 0x01
+#define PCI_EXP_LNKCTL_ASPM_L0S 0x0001
+#define PCI_EXP_LNKCTL_ASPM_L1 0x0002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_LNKCTL_ASPM_L1 0x02
 #define PCI_EXP_LNKCTL_RCB 0x0008
 #define PCI_EXP_LNKCTL_LD 0x0010
 #define PCI_EXP_LNKCTL_RL 0x0020
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKCTL_CCC 0x0040
-#define PCI_EXP_LNKCTL_ES 0x0080
-#define PCI_EXP_LNKCTL_CLKREQ_EN 0x100
-#define PCI_EXP_LNKCTL_HAWD 0x0200
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXP_LNKCTL_ES 0x0080
+#define PCI_EXP_LNKCTL_CLKREQ_EN 0x0100
+#define PCI_EXP_LNKCTL_HAWD 0x0200
 #define PCI_EXP_LNKCTL_LBMIE 0x0400
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKCTL_LABIE 0x0800
 #define PCI_EXP_LNKSTA 18
 #define PCI_EXP_LNKSTA_CLS 0x000f
+#define PCI_EXP_LNKSTA_CLS_2_5GB 0x0001
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_LNKSTA_CLS_2_5GB 0x01
-#define PCI_EXP_LNKSTA_CLS_5_0GB 0x02
+#define PCI_EXP_LNKSTA_CLS_5_0GB 0x0002
+#define PCI_EXP_LNKSTA_CLS_8_0GB 0x0003
 #define PCI_EXP_LNKSTA_NLW 0x03f0
+#define PCI_EXP_LNKSTA_NLW_X1 0x0010
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXP_LNKSTA_NLW_X2 0x0020
+#define PCI_EXP_LNKSTA_NLW_X4 0x0040
+#define PCI_EXP_LNKSTA_NLW_X8 0x0080
 #define PCI_EXP_LNKSTA_NLW_SHIFT 4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKSTA_LT 0x0800
@@ -549,9 +554,19 @@
 #define PCI_EXP_SLTCTL_CCIE 0x0010
 #define PCI_EXP_SLTCTL_HPIE 0x0020
 #define PCI_EXP_SLTCTL_AIC 0x00c0
-#define PCI_EXP_SLTCTL_PIC 0x0300
+#define PCI_EXP_SLTCTL_ATTN_IND_ON 0x0040
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXP_SLTCTL_ATTN_IND_BLINK 0x0080
+#define PCI_EXP_SLTCTL_ATTN_IND_OFF 0x00c0
+#define PCI_EXP_SLTCTL_PIC 0x0300
+#define PCI_EXP_SLTCTL_PWR_IND_ON 0x0100
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXP_SLTCTL_PWR_IND_BLINK 0x0200
+#define PCI_EXP_SLTCTL_PWR_IND_OFF 0x0300
 #define PCI_EXP_SLTCTL_PCC 0x0400
+#define PCI_EXP_SLTCTL_PWR_ON 0x0000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXP_SLTCTL_PWR_OFF 0x0400
 #define PCI_EXP_SLTCTL_EIC 0x0800
 #define PCI_EXP_SLTCTL_DLLSCE 0x1000
 #define PCI_EXP_SLTSTA 26
@@ -568,46 +583,51 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_SLTSTA_DLLSC 0x0100
 #define PCI_EXP_RTCTL 28
-#define PCI_EXP_RTCTL_SECEE 0x01
-#define PCI_EXP_RTCTL_SENFEE 0x02
+#define PCI_EXP_RTCTL_SECEE 0x0001
+#define PCI_EXP_RTCTL_SENFEE 0x0002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_RTCTL_SEFEE 0x04
-#define PCI_EXP_RTCTL_PMEIE 0x08
-#define PCI_EXP_RTCTL_CRSSVE 0x10
+#define PCI_EXP_RTCTL_SEFEE 0x0004
+#define PCI_EXP_RTCTL_PMEIE 0x0008
+#define PCI_EXP_RTCTL_CRSSVE 0x0010
 #define PCI_EXP_RTCAP 30
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_RTSTA 32
-#define PCI_EXP_RTSTA_PME 0x10000
-#define PCI_EXP_RTSTA_PENDING 0x20000
+#define PCI_EXP_RTSTA_PME 0x00010000
+#define PCI_EXP_RTSTA_PENDING 0x00020000
 #define PCI_EXP_DEVCAP2 36
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_DEVCAP2_ARI 0x20
-#define PCI_EXP_DEVCAP2_LTR 0x800
-#define PCI_EXP_OBFF_MASK 0xc0000
-#define PCI_EXP_OBFF_MSG 0x40000
+#define PCI_EXP_DEVCAP2_ARI 0x00000020
+#define PCI_EXP_DEVCAP2_LTR 0x00000800
+#define PCI_EXP_DEVCAP2_OBFF_MASK 0x000c0000
+#define PCI_EXP_DEVCAP2_OBFF_MSG 0x00040000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_OBFF_WAKE 0x80000
+#define PCI_EXP_DEVCAP2_OBFF_WAKE 0x00080000
 #define PCI_EXP_DEVCTL2 40
-#define PCI_EXP_DEVCTL2_ARI 0x20
-#define PCI_EXP_IDO_REQ_EN 0x100
+#define PCI_EXP_DEVCTL2_COMP_TIMEOUT 0x000f
+#define PCI_EXP_DEVCTL2_ARI 0x0020
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_IDO_CMP_EN 0x200
-#define PCI_EXP_LTR_EN 0x400
-#define PCI_EXP_OBFF_MSGA_EN 0x2000
-#define PCI_EXP_OBFF_MSGB_EN 0x4000
+#define PCI_EXP_DEVCTL2_IDO_REQ_EN 0x0100
+#define PCI_EXP_DEVCTL2_IDO_CMP_EN 0x0200
+#define PCI_EXP_DEVCTL2_LTR_EN 0x0400
+#define PCI_EXP_DEVCTL2_OBFF_MSGA_EN 0x2000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_OBFF_WAKE_EN 0x6000
+#define PCI_EXP_DEVCTL2_OBFF_MSGB_EN 0x4000
+#define PCI_EXP_DEVCTL2_OBFF_WAKE_EN 0x6000
+#define PCI_EXP_DEVSTA2 42
 #define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2 44
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKCAP2 44
-#define PCI_EXP_LNKCAP2_SLS_2_5GB 0x02
+#define PCI_EXP_LNKCAP2_SLS_2_5GB 0x00000002
+#define PCI_EXP_LNKCAP2_SLS_5_0GB 0x00000004
+#define PCI_EXP_LNKCAP2_SLS_8_0GB 0x00000008
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_EXP_LNKCAP2_SLS_5_0GB 0x04
-#define PCI_EXP_LNKCAP2_SLS_8_0GB 0x08
-#define PCI_EXP_LNKCAP2_CROSSLINK 0x100
+#define PCI_EXP_LNKCAP2_CROSSLINK 0x00000100
 #define PCI_EXP_LNKCTL2 48
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_LNKSTA2 50
+#define PCI_EXP_SLTCAP2 52
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_EXP_SLTCTL2 56
+#define PCI_EXP_SLTSTA2 58
 #define PCI_EXT_CAP_ID(header) (header & 0x0000ffff)
 #define PCI_EXT_CAP_VER(header) ((header >> 16) & 0xf)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -712,198 +732,219 @@
 #define PCI_ERR_ROOT_FATAL_RCV 0x00000040
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_ERR_ROOT_ERR_SRC 52
-#define PCI_VC_PORT_REG1 4
-#define PCI_VC_REG1_EVCC 0x7
-#define PCI_VC_PORT_REG2 8
+#define PCI_VC_PORT_CAP1 4
+#define PCI_VC_CAP1_EVCC 0x00000007
+#define PCI_VC_CAP1_LPEVCC 0x00000070
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PCI_VC_REG2_32_PHASE 0x2
-#define PCI_VC_REG2_64_PHASE 0x4
-#define PCI_VC_REG2_128_PHASE 0x8
+#define PCI_VC_CAP1_ARB_SIZE 0x00000c00
+#define PCI_VC_PORT_CAP2 8
+#define PCI_VC_CAP2_32_PHASE 0x00000002
+#define PCI_VC_CAP2_64_PHASE 0x00000004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_VC_CAP2_128_PHASE 0x00000008
+#define PCI_VC_CAP2_ARB_OFF 0xff000000
 #define PCI_VC_PORT_CTRL 12
+#define PCI_VC_PORT_CTRL_LOAD_TABLE 0x00000001
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PCI_VC_PORT_STATUS 14
+#define PCI_VC_PORT_STATUS_TABLE 0x00000001
 #define PCI_VC_RES_CAP 16
-#define PCI_VC_RES_CTRL 20
-#define PCI_VC_RES_STATUS 26
+#define PCI_VC_RES_CAP_32_PHASE 0x00000002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_VC_RES_CAP_64_PHASE 0x00000004
+#define PCI_VC_RES_CAP_128_PHASE 0x00000008
+#define PCI_VC_RES_CAP_128_PHASE_TB 0x00000010
+#define PCI_VC_RES_CAP_256_PHASE 0x00000020
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_VC_RES_CAP_ARB_OFF 0xff000000
+#define PCI_VC_RES_CTRL 20
+#define PCI_VC_RES_CTRL_LOAD_TABLE 0x00010000
+#define PCI_VC_RES_CTRL_ARB_SELECT 0x000e0000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_VC_RES_CTRL_ID 0x07000000
+#define PCI_VC_RES_CTRL_ENABLE 0x80000000
+#define PCI_VC_RES_STATUS 26
+#define PCI_VC_RES_STATUS_TABLE 0x00000001
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_VC_RES_STATUS_NEGO 0x00000002
 #define PCI_CAP_VC_BASE_SIZEOF 0x10
 #define PCI_CAP_VC_PER_VC_SIZEOF 0x0C
 #define PCI_PWR_DSR 4
-#define PCI_PWR_DATA 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_PWR_DATA 8
 #define PCI_PWR_DATA_BASE(x) ((x) & 0xff)
 #define PCI_PWR_DATA_SCALE(x) (((x) >> 8) & 3)
 #define PCI_PWR_DATA_PM_SUB(x) (((x) >> 10) & 7)
-#define PCI_PWR_DATA_PM_STATE(x) (((x) >> 13) & 3)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_PWR_DATA_PM_STATE(x) (((x) >> 13) & 3)
 #define PCI_PWR_DATA_TYPE(x) (((x) >> 15) & 7)
 #define PCI_PWR_DATA_RAIL(x) (((x) >> 18) & 7)
 #define PCI_PWR_CAP 12
-#define PCI_PWR_CAP_BUDGET(x) ((x) & 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_PWR_CAP_BUDGET(x) ((x) & 1)
 #define PCI_EXT_CAP_PWR_SIZEOF 16
 #define PCI_VNDR_HEADER 4
 #define PCI_VNDR_HEADER_ID(x) ((x) & 0xffff)
-#define PCI_VNDR_HEADER_REV(x) (((x) >> 16) & 0xf)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_VNDR_HEADER_REV(x) (((x) >> 16) & 0xf)
 #define PCI_VNDR_HEADER_LEN(x) (((x) >> 20) & 0xfff)
 #define HT_3BIT_CAP_MASK 0xE0
 #define HT_CAPTYPE_SLAVE 0x00
-#define HT_CAPTYPE_HOST 0x20
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HT_CAPTYPE_HOST 0x20
 #define HT_5BIT_CAP_MASK 0xF8
 #define HT_CAPTYPE_IRQ 0x80
 #define HT_CAPTYPE_REMAPPING_40 0xA0
-#define HT_CAPTYPE_REMAPPING_64 0xA2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HT_CAPTYPE_REMAPPING_64 0xA2
 #define HT_CAPTYPE_UNITID_CLUMP 0x90
 #define HT_CAPTYPE_EXTCONF 0x98
 #define HT_CAPTYPE_MSI_MAPPING 0xA8
-#define HT_MSI_FLAGS 0x02
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HT_MSI_FLAGS 0x02
 #define HT_MSI_FLAGS_ENABLE 0x1
 #define HT_MSI_FLAGS_FIXED 0x2
 #define HT_MSI_FIXED_ADDR 0x00000000FEE00000ULL
-#define HT_MSI_ADDR_LO 0x04
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HT_MSI_ADDR_LO 0x04
 #define HT_MSI_ADDR_LO_MASK 0xFFF00000
 #define HT_MSI_ADDR_HI 0x08
 #define HT_CAPTYPE_DIRECT_ROUTE 0xB0
-#define HT_CAPTYPE_VCSET 0xB8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HT_CAPTYPE_VCSET 0xB8
 #define HT_CAPTYPE_ERROR_RETRY 0xC0
 #define HT_CAPTYPE_GEN3 0xD0
 #define HT_CAPTYPE_PM 0xE0
-#define HT_CAP_SIZEOF_LONG 28
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HT_CAP_SIZEOF_LONG 28
 #define HT_CAP_SIZEOF_SHORT 24
 #define PCI_ARI_CAP 0x04
 #define PCI_ARI_CAP_MFVC 0x0001
-#define PCI_ARI_CAP_ACS 0x0002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_ARI_CAP_ACS 0x0002
 #define PCI_ARI_CAP_NFN(x) (((x) >> 8) & 0xff)
 #define PCI_ARI_CTRL 0x06
 #define PCI_ARI_CTRL_MFVC 0x0001
-#define PCI_ARI_CTRL_ACS 0x0002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_ARI_CTRL_ACS 0x0002
 #define PCI_ARI_CTRL_FG(x) (((x) >> 4) & 7)
 #define PCI_EXT_CAP_ARI_SIZEOF 8
 #define PCI_ATS_CAP 0x04
-#define PCI_ATS_CAP_QDEP(x) ((x) & 0x1f)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_ATS_CAP_QDEP(x) ((x) & 0x1f)
 #define PCI_ATS_MAX_QDEP 32
 #define PCI_ATS_CTRL 0x06
 #define PCI_ATS_CTRL_ENABLE 0x8000
-#define PCI_ATS_CTRL_STU(x) ((x) & 0x1f)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_ATS_CTRL_STU(x) ((x) & 0x1f)
 #define PCI_ATS_MIN_STU 12
 #define PCI_EXT_CAP_ATS_SIZEOF 8
 #define PCI_PRI_CTRL 0x04
-#define PCI_PRI_CTRL_ENABLE 0x01
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_PRI_CTRL_ENABLE 0x01
 #define PCI_PRI_CTRL_RESET 0x02
 #define PCI_PRI_STATUS 0x06
 #define PCI_PRI_STATUS_RF 0x001
-#define PCI_PRI_STATUS_UPRGI 0x002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_PRI_STATUS_UPRGI 0x002
 #define PCI_PRI_STATUS_STOPPED 0x100
 #define PCI_PRI_MAX_REQ 0x08
 #define PCI_PRI_ALLOC_REQ 0x0c
-#define PCI_EXT_CAP_PRI_SIZEOF 16
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXT_CAP_PRI_SIZEOF 16
 #define PCI_PASID_CAP 0x04
 #define PCI_PASID_CAP_EXEC 0x02
 #define PCI_PASID_CAP_PRIV 0x04
-#define PCI_PASID_CTRL 0x06
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_PASID_CTRL 0x06
 #define PCI_PASID_CTRL_ENABLE 0x01
 #define PCI_PASID_CTRL_EXEC 0x02
 #define PCI_PASID_CTRL_PRIV 0x04
-#define PCI_EXT_CAP_PASID_SIZEOF 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXT_CAP_PASID_SIZEOF 8
 #define PCI_SRIOV_CAP 0x04
 #define PCI_SRIOV_CAP_VFM 0x01
 #define PCI_SRIOV_CAP_INTR(x) ((x) >> 21)
-#define PCI_SRIOV_CTRL 0x08
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_SRIOV_CTRL 0x08
 #define PCI_SRIOV_CTRL_VFE 0x01
 #define PCI_SRIOV_CTRL_VFM 0x02
 #define PCI_SRIOV_CTRL_INTR 0x04
-#define PCI_SRIOV_CTRL_MSE 0x08
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_SRIOV_CTRL_MSE 0x08
 #define PCI_SRIOV_CTRL_ARI 0x10
 #define PCI_SRIOV_STATUS 0x0a
 #define PCI_SRIOV_STATUS_VFM 0x01
-#define PCI_SRIOV_INITIAL_VF 0x0c
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_SRIOV_INITIAL_VF 0x0c
 #define PCI_SRIOV_TOTAL_VF 0x0e
 #define PCI_SRIOV_NUM_VF 0x10
 #define PCI_SRIOV_FUNC_LINK 0x12
-#define PCI_SRIOV_VF_OFFSET 0x14
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_SRIOV_VF_OFFSET 0x14
 #define PCI_SRIOV_VF_STRIDE 0x16
 #define PCI_SRIOV_VF_DID 0x1a
 #define PCI_SRIOV_SUP_PGSIZE 0x1c
-#define PCI_SRIOV_SYS_PGSIZE 0x20
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_SRIOV_SYS_PGSIZE 0x20
 #define PCI_SRIOV_BAR 0x24
 #define PCI_SRIOV_NUM_BARS 6
 #define PCI_SRIOV_VFM 0x3c
-#define PCI_SRIOV_VFM_BIR(x) ((x) & 7)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_SRIOV_VFM_BIR(x) ((x) & 7)
 #define PCI_SRIOV_VFM_OFFSET(x) ((x) & ~7)
 #define PCI_SRIOV_VFM_UA 0x0
 #define PCI_SRIOV_VFM_MI 0x1
-#define PCI_SRIOV_VFM_MO 0x2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_SRIOV_VFM_MO 0x2
 #define PCI_SRIOV_VFM_AV 0x3
 #define PCI_EXT_CAP_SRIOV_SIZEOF 64
 #define PCI_LTR_MAX_SNOOP_LAT 0x4
-#define PCI_LTR_MAX_NOSNOOP_LAT 0x6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_LTR_MAX_NOSNOOP_LAT 0x6
 #define PCI_LTR_VALUE_MASK 0x000003ff
 #define PCI_LTR_SCALE_MASK 0x00001c00
 #define PCI_LTR_SCALE_SHIFT 10
-#define PCI_EXT_CAP_LTR_SIZEOF 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_EXT_CAP_LTR_SIZEOF 8
 #define PCI_ACS_CAP 0x04
 #define PCI_ACS_SV 0x01
 #define PCI_ACS_TB 0x02
-#define PCI_ACS_RR 0x04
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_ACS_RR 0x04
 #define PCI_ACS_CR 0x08
 #define PCI_ACS_UF 0x10
 #define PCI_ACS_EC 0x20
-#define PCI_ACS_DT 0x40
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_ACS_DT 0x40
 #define PCI_ACS_EGRESS_BITS 0x05
 #define PCI_ACS_CTRL 0x06
 #define PCI_ACS_EGRESS_CTL_V 0x08
-#define PCI_VSEC_HDR 4
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_VSEC_HDR 4
 #define PCI_VSEC_HDR_LEN_SHIFT 20
 #define PCI_SATA_REGS 4
 #define PCI_SATA_REGS_MASK 0xF
-#define PCI_SATA_REGS_INLINE 0xF
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_SATA_REGS_INLINE 0xF
 #define PCI_SATA_SIZEOF_SHORT 8
 #define PCI_SATA_SIZEOF_LONG 16
 #define PCI_REBAR_CTRL 8
-#define PCI_REBAR_CTRL_NBAR_MASK (7 << 5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_REBAR_CTRL_NBAR_MASK (7 << 5)
 #define PCI_REBAR_CTRL_NBAR_SHIFT 5
 #define PCI_DPA_CAP 4
 #define PCI_DPA_CAP_SUBSTATE_MASK 0x1F
-#define PCI_DPA_BASE_SIZEOF 16
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_DPA_BASE_SIZEOF 16
 #define PCI_TPH_CAP 4
 #define PCI_TPH_CAP_LOC_MASK 0x600
 #define PCI_TPH_LOC_NONE 0x000
-#define PCI_TPH_LOC_CAP 0x200
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_TPH_LOC_CAP 0x200
 #define PCI_TPH_LOC_MSIX 0x400
 #define PCI_TPH_CAP_ST_MASK 0x07FF0000
 #define PCI_TPH_CAP_ST_SHIFT 16
-#define PCI_TPH_BASE_SIZEOF 12
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PCI_TPH_BASE_SIZEOF 12
 #endif
diff --git a/libc/kernel/uapi/linux/perf_event.h b/libc/kernel/uapi/linux/perf_event.h
index 5d11bda..5922cbe 100644
--- a/libc/kernel/uapi/linux/perf_event.h
+++ b/libc/kernel/uapi/linux/perf_event.h
@@ -88,107 +88,132 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_COUNT_SW_ALIGNMENT_FAULTS = 7,
  PERF_COUNT_SW_EMULATION_FAULTS = 8,
+ PERF_COUNT_SW_DUMMY = 9,
  PERF_COUNT_SW_MAX,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum perf_event_sample_format {
  PERF_SAMPLE_IP = 1U << 0,
  PERF_SAMPLE_TID = 1U << 1,
- PERF_SAMPLE_TIME = 1U << 2,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_SAMPLE_TIME = 1U << 2,
  PERF_SAMPLE_ADDR = 1U << 3,
  PERF_SAMPLE_READ = 1U << 4,
  PERF_SAMPLE_CALLCHAIN = 1U << 5,
- PERF_SAMPLE_ID = 1U << 6,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_SAMPLE_ID = 1U << 6,
  PERF_SAMPLE_CPU = 1U << 7,
  PERF_SAMPLE_PERIOD = 1U << 8,
  PERF_SAMPLE_STREAM_ID = 1U << 9,
- PERF_SAMPLE_RAW = 1U << 10,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_SAMPLE_RAW = 1U << 10,
  PERF_SAMPLE_BRANCH_STACK = 1U << 11,
  PERF_SAMPLE_REGS_USER = 1U << 12,
  PERF_SAMPLE_STACK_USER = 1U << 13,
- PERF_SAMPLE_WEIGHT = 1U << 14,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_SAMPLE_WEIGHT = 1U << 14,
  PERF_SAMPLE_DATA_SRC = 1U << 15,
- PERF_SAMPLE_MAX = 1U << 16,
+ PERF_SAMPLE_IDENTIFIER = 1U << 16,
+ PERF_SAMPLE_TRANSACTION = 1U << 17,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_SAMPLE_MAX = 1U << 18,
 };
 enum perf_branch_sample_type {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_SAMPLE_BRANCH_USER = 1U << 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_SAMPLE_BRANCH_KERNEL = 1U << 1,
  PERF_SAMPLE_BRANCH_HV = 1U << 2,
  PERF_SAMPLE_BRANCH_ANY = 1U << 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_SAMPLE_BRANCH_ANY_CALL = 1U << 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << 5,
  PERF_SAMPLE_BRANCH_IND_CALL = 1U << 6,
- PERF_SAMPLE_BRANCH_MAX = 1U << 7,
+ PERF_SAMPLE_BRANCH_ABORT_TX = 1U << 7,
+ PERF_SAMPLE_BRANCH_IN_TX = 1U << 8,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_SAMPLE_BRANCH_NO_TX = 1U << 9,
+ PERF_SAMPLE_BRANCH_MAX = 1U << 10,
 };
 #define PERF_SAMPLE_BRANCH_PLM_ALL   (PERF_SAMPLE_BRANCH_USER|  PERF_SAMPLE_BRANCH_KERNEL|  PERF_SAMPLE_BRANCH_HV)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum perf_sample_regs_abi {
  PERF_SAMPLE_REGS_ABI_NONE = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_SAMPLE_REGS_ABI_32 = 1,
  PERF_SAMPLE_REGS_ABI_64 = 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum {
+ PERF_TXN_ELISION = (1 << 0),
+ PERF_TXN_TRANSACTION = (1 << 1),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_TXN_SYNC = (1 << 2),
+ PERF_TXN_ASYNC = (1 << 3),
+ PERF_TXN_RETRY = (1 << 4),
+ PERF_TXN_CONFLICT = (1 << 5),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_TXN_CAPACITY_WRITE = (1 << 6),
+ PERF_TXN_CAPACITY_READ = (1 << 7),
+ PERF_TXN_MAX = (1 << 8),
+ PERF_TXN_ABORT_MASK = (0xffffffffULL << 32),
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_TXN_ABORT_SHIFT = 32,
 };
 enum perf_event_read_format {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
  PERF_FORMAT_ID = 1U << 2,
  PERF_FORMAT_GROUP = 1U << 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PERF_FORMAT_MAX = 1U << 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define PERF_ATTR_SIZE_VER0 64
 #define PERF_ATTR_SIZE_VER1 72
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_ATTR_SIZE_VER2 80
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_ATTR_SIZE_VER3 96
 struct perf_event_attr {
  __u32 type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 config;
  union {
  __u64 sample_period;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 sample_freq;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
  __u64 sample_type;
  __u64 read_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 disabled : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  inherit : 1,
  pinned : 1,
  exclusive : 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  exclude_user : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  exclude_kernel : 1,
  exclude_hv : 1,
  exclude_idle : 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  mmap : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  comm : 1,
  freq : 1,
  inherit_stat : 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  enable_on_exec : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  task : 1,
  watermark : 1,
  precise_ip : 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  mmap_data : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  sample_id_all : 1,
  exclude_host : 1,
  exclude_guest : 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  exclude_callchain_kernel : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  exclude_callchain_user : 1,
- __reserved_1 : 41;
+ mmap2 : 1,
+ __reserved_1 : 40;
  union {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 wakeup_events;
@@ -222,33 +247,43 @@
 #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
+#define PERF_EVENT_IOC_ID _IOR('$', 7, __u64 *)
 enum perf_event_ioc_flags {
  PERF_IOC_FLAG_GROUP = 1U << 0,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct perf_event_mmap_page {
  __u32 version;
  __u32 compat_version;
- __u32 lock;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 lock;
  __u32 index;
  __s64 offset;
  __u64 time_enabled;
- __u64 time_running;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 time_running;
  union {
  __u64 capabilities;
- __u64 cap_usr_time : 1,
- cap_usr_rdpmc : 1,
+ struct {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- cap_____res : 62;
+ __u64 cap_bit0 : 1,
+ cap_bit0_is_deprecated : 1,
+ cap_user_rdpmc : 1,
+ cap_user_time : 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ cap_user_time_zero : 1,
+ cap_____res : 59;
  };
+ };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 pmc_width;
  __u16 time_shift;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 time_mult;
  __u64 time_offset;
- __u64 __reserved[120];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 time_zero;
+ __u32 size;
+ __u8 __reserved[118*8+4];
  __u64 data_head;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 data_tail;
@@ -284,86 +319,100 @@
  PERF_RECORD_FORK = 7,
  PERF_RECORD_READ = 8,
  PERF_RECORD_SAMPLE = 9,
- PERF_RECORD_MAX,
+ PERF_RECORD_MMAP2 = 10,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_RECORD_MAX,
 };
 #define PERF_MAX_STACK_DEPTH 127
 enum perf_callchain_context {
- PERF_CONTEXT_HV = (__u64)-32,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_CONTEXT_HV = (__u64)-32,
  PERF_CONTEXT_KERNEL = (__u64)-128,
  PERF_CONTEXT_USER = (__u64)-512,
  PERF_CONTEXT_GUEST = (__u64)-2048,
- PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
  PERF_CONTEXT_GUEST_USER = (__u64)-2560,
  PERF_CONTEXT_MAX = (__u64)-4095,
 };
-#define PERF_FLAG_FD_NO_GROUP (1U << 0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PERF_FLAG_FD_NO_GROUP (1U << 0)
 #define PERF_FLAG_FD_OUTPUT (1U << 1)
 #define PERF_FLAG_PID_CGROUP (1U << 2)
+#define PERF_FLAG_FD_CLOEXEC (1U << 3)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 union perf_mem_data_src {
  __u64 val;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  __u64 mem_op:5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  mem_lvl:14,
  mem_snoop:5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  mem_lock:2,
  mem_dtlb:7,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  mem_rsvd:31;
  };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define PERF_MEM_OP_NA 0x01
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_OP_LOAD 0x02
 #define PERF_MEM_OP_STORE 0x04
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_OP_PFETCH 0x08
 #define PERF_MEM_OP_EXEC 0x10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_OP_SHIFT 0
 #define PERF_MEM_LVL_NA 0x01
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LVL_HIT 0x02
 #define PERF_MEM_LVL_MISS 0x04
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LVL_L1 0x08
 #define PERF_MEM_LVL_LFB 0x10
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LVL_L2 0x20
 #define PERF_MEM_LVL_L3 0x40
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LVL_LOC_RAM 0x80
 #define PERF_MEM_LVL_REM_RAM1 0x100
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LVL_REM_RAM2 0x200
 #define PERF_MEM_LVL_REM_CCE1 0x400
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LVL_REM_CCE2 0x800
 #define PERF_MEM_LVL_IO 0x1000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LVL_UNC 0x2000
 #define PERF_MEM_LVL_SHIFT 5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_SNOOP_NA 0x01
 #define PERF_MEM_SNOOP_NONE 0x02
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_SNOOP_HIT 0x04
 #define PERF_MEM_SNOOP_MISS 0x08
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_SNOOP_HITM 0x10
 #define PERF_MEM_SNOOP_SHIFT 19
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LOCK_NA 0x01
 #define PERF_MEM_LOCK_LOCKED 0x02
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_LOCK_SHIFT 24
 #define PERF_MEM_TLB_NA 0x01
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_TLB_HIT 0x02
 #define PERF_MEM_TLB_MISS 0x04
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_TLB_L1 0x08
 #define PERF_MEM_TLB_L2 0x10
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PERF_MEM_TLB_WK 0x20
 #define PERF_MEM_TLB_OS 0x40
-#define PERF_MEM_TLB_SHIFT 26
-#define PERF_MEM_S(a, s)   (((u64)PERF_MEM_##a##_##s) << PERF_MEM_##a##_SHIFT)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PERF_MEM_TLB_SHIFT 26
+#define PERF_MEM_S(a, s)   (((__u64)PERF_MEM_##a##_##s) << PERF_MEM_##a##_SHIFT)
+struct perf_branch_entry {
+ __u64 from;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 to;
+ __u64 mispred:1,
+ predicted:1,
+ in_tx:1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ abort:1,
+ reserved:60;
+};
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/pkt_cls.h b/libc/kernel/uapi/linux/pkt_cls.h
index ba443e1..92ea0df 100644
--- a/libc/kernel/uapi/linux/pkt_cls.h
+++ b/libc/kernel/uapi/linux/pkt_cls.h
@@ -371,65 +371,78 @@
 };
 #define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
+ TCA_BPF_UNSPEC,
+ TCA_BPF_ACT,
+ TCA_BPF_POLICE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_BPF_CLASSID,
+ TCA_BPF_OPS_LEN,
+ TCA_BPF_OPS,
+ __TCA_BPF_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
 struct tcf_ematch_tree_hdr {
  __u16 nmatches;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 progid;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  TCA_EMATCH_TREE_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_EMATCH_TREE_HDR,
  TCA_EMATCH_TREE_LIST,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __TCA_EMATCH_TREE_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
 struct tcf_ematch_hdr {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 matchid;
  __u16 kind;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 flags;
  __u16 pad;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TCF_EM_REL_END 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_EM_REL_AND (1<<0)
 #define TCF_EM_REL_OR (1<<1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_EM_INVERT (1<<2)
 #define TCF_EM_SIMPLE (1<<3)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_EM_REL_MASK 3
 #define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  TCF_LAYER_LINK,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCF_LAYER_NETWORK,
  TCF_LAYER_TRANSPORT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __TCF_LAYER_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
 #define TCF_EM_CONTAINER 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_EM_CMP 1
 #define TCF_EM_NBYTE 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_EM_U32 3
 #define TCF_EM_META 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_EM_TEXT 5
 #define TCF_EM_VLAN 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_EM_CANID 7
 #define TCF_EM_IPSET 8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCF_EM_MAX 8
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCF_EM_PROG_TC
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  TCF_EM_OPND_EQ,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCF_EM_OPND_GT,
  TCF_EM_OPND_LT
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/pkt_sched.h b/libc/kernel/uapi/linux/pkt_sched.h
index 39335ce..5b64096 100644
--- a/libc/kernel/uapi/linux/pkt_sched.h
+++ b/libc/kernel/uapi/linux/pkt_sched.h
@@ -56,262 +56,277 @@
 #define TC_H_ROOT (0xFFFFFFFFU)
 #define TC_H_INGRESS (0xFFFFFFF1U)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum tc_link_layer {
+ TC_LINKLAYER_UNAWARE,
+ TC_LINKLAYER_ETHERNET,
+ TC_LINKLAYER_ATM,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define TC_LINKLAYER_MASK 0x0F
 struct tc_ratespec {
  unsigned char cell_log;
- unsigned char __reserved;
- unsigned short overhead;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 linklayer;
+ unsigned short overhead;
  short cell_align;
  unsigned short mpu;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 rate;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TC_RTAB_SIZE 1024
 struct tc_sizespec {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char cell_log;
  unsigned char size_log;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  short cell_align;
  int overhead;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int linklayer;
  unsigned int mpu;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int mtu;
  unsigned int tsize;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_STAB_UNSPEC,
  TCA_STAB_BASE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_STAB_DATA,
  __TCA_STAB_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TCA_STAB_MAX (__TCA_STAB_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_fifo_qopt {
  __u32 limit;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TCQ_PRIO_BANDS 16
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCQ_MIN_PRIO_BANDS 2
 struct tc_prio_qopt {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int bands;
  __u8 priomap[TC_PRIO_MAX+1];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tc_multiq_qopt {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 bands;
  __u16 max_bands;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TCQ_PLUG_BUFFER 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCQ_PLUG_RELEASE_ONE 1
 #define TCQ_PLUG_RELEASE_INDEFINITE 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCQ_PLUG_LIMIT 3
 struct tc_plug_qopt {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int action;
  __u32 limit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tc_tbf_qopt {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct tc_ratespec rate;
  struct tc_ratespec peakrate;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 limit;
  __u32 buffer;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mtu;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  TCA_TBF_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_TBF_PARMS,
  TCA_TBF_RTAB,
- TCA_TBF_PTAB,
- __TCA_TBF_MAX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_TBF_PTAB,
+ TCA_TBF_RATE64,
+ TCA_TBF_PRATE64,
+ TCA_TBF_BURST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_TBF_PBURST,
+ __TCA_TBF_MAX,
 };
 #define TCA_TBF_MAX (__TCA_TBF_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_sfq_qopt {
  unsigned quantum;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int perturb_period;
  __u32 limit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned divisor;
  unsigned flows;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tc_sfqred_stats {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 prob_drop;
  __u32 forced_drop;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 prob_mark;
  __u32 forced_mark;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 prob_mark_head;
  __u32 forced_mark_head;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tc_sfq_qopt_v1 {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct tc_sfq_qopt v0;
  unsigned int depth;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int headdrop;
  __u32 limit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qth_min;
  __u32 qth_max;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char Wlog;
  unsigned char Plog;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char Scell_log;
  unsigned char flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_P;
  struct tc_sfqred_stats stats;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tc_sfq_xstats {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 allot;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  TCA_RED_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_RED_PARMS,
  TCA_RED_STAB,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_RED_MAX_P,
  __TCA_RED_MAX,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TCA_RED_MAX (__TCA_RED_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_red_qopt {
  __u32 limit;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qth_min;
  __u32 qth_max;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char Wlog;
  unsigned char Plog;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char Scell_log;
  unsigned char flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TC_RED_ECN 1
 #define TC_RED_HARDDROP 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TC_RED_ADAPTATIVE 4
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_red_xstats {
  __u32 early;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pdrop;
  __u32 other;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 marked;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MAX_DPs 16
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_GRED_UNSPEC,
  TCA_GRED_PARMS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_GRED_STAB,
  TCA_GRED_DPS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_GRED_MAX_P,
  __TCA_GRED_MAX,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TCA_GRED_MAX (__TCA_GRED_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_gred_qopt {
  __u32 limit;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qth_min;
  __u32 qth_max;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 DP;
  __u32 backlog;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qave;
  __u32 forced;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 early;
  __u32 other;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pdrop;
  __u8 Wlog;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 Plog;
  __u8 Scell_log;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 prio;
  __u32 packets;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 bytesin;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_gred_sopt {
  __u32 DPs;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 def_DP;
  __u8 grio;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 flags;
  __u16 pad1;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_CHOKE_UNSPEC,
  TCA_CHOKE_PARMS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_CHOKE_STAB,
  TCA_CHOKE_MAX_P,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __TCA_CHOKE_MAX,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCA_CHOKE_MAX (__TCA_CHOKE_MAX - 1)
 struct tc_choke_qopt {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 limit;
  __u32 qth_min;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qth_max;
  unsigned char Wlog;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char Plog;
  unsigned char Scell_log;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char flags;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_choke_xstats {
  __u32 early;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pdrop;
  __u32 other;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 marked;
  __u32 matched;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TC_HTB_NUMPRIO 8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TC_HTB_MAXDEPTH 8
 #define TC_HTB_PROTOVER 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_htb_opt {
  struct tc_ratespec rate;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct tc_ratespec ceil;
  __u32 buffer;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cbuffer;
  __u32 quantum;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 level;
  __u32 prio;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct tc_htb_glob {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 version;
  __u32 rate2quantum;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 defcls;
  __u32 debug;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 direct_pkts;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  TCA_HTB_UNSPEC,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_HTB_PARMS,
  TCA_HTB_INIT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_HTB_CTAB,
  TCA_HTB_RTAB,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_HTB_DIRECT_QLEN,
+ TCA_HTB_RATE64,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_HTB_CEIL64,
  __TCA_HTB_MAX,
 };
 #define TCA_HTB_MAX (__TCA_HTB_MAX - 1)
@@ -474,213 +489,300 @@
  TCA_NETEM_LOSS,
  TCA_NETEM_RATE,
  TCA_NETEM_ECN,
- __TCA_NETEM_MAX,
+ TCA_NETEM_RATE64,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __TCA_NETEM_MAX,
 };
 #define TCA_NETEM_MAX (__TCA_NETEM_MAX - 1)
 struct tc_netem_qopt {
- __u32 latency;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 latency;
  __u32 limit;
  __u32 loss;
  __u32 gap;
- __u32 duplicate;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 duplicate;
  __u32 jitter;
 };
 struct tc_netem_corr {
- __u32 delay_corr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 delay_corr;
  __u32 loss_corr;
  __u32 dup_corr;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_netem_reorder {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 probability;
  __u32 correlation;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tc_netem_corrupt {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 probability;
  __u32 correlation;
 };
-struct tc_netem_rate {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct tc_netem_rate {
  __u32 rate;
  __s32 packet_overhead;
  __u32 cell_size;
- __s32 cell_overhead;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s32 cell_overhead;
 };
 enum {
  NETEM_LOSS_UNSPEC,
- NETEM_LOSS_GI,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NETEM_LOSS_GI,
  NETEM_LOSS_GE,
  __NETEM_LOSS_MAX
 };
-#define NETEM_LOSS_MAX (__NETEM_LOSS_MAX - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETEM_LOSS_MAX (__NETEM_LOSS_MAX - 1)
 struct tc_netem_gimodel {
  __u32 p13;
  __u32 p31;
- __u32 p32;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 p32;
  __u32 p14;
  __u32 p23;
 };
-struct tc_netem_gemodel {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct tc_netem_gemodel {
  __u32 p;
  __u32 r;
  __u32 h;
- __u32 k1;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 k1;
 };
 #define NETEM_DIST_SCALE 8192
 #define NETEM_DIST_MAX 16384
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  TCA_DRR_UNSPEC,
  TCA_DRR_QUANTUM,
  __TCA_DRR_MAX
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define TCA_DRR_MAX (__TCA_DRR_MAX - 1)
 struct tc_drr_stats {
  __u32 deficit;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define TC_QOPT_BITMASK 15
 #define TC_QOPT_MAX_QUEUE 16
 struct tc_mqprio_qopt {
- __u8 num_tc;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 num_tc;
  __u8 prio_tc_map[TC_QOPT_BITMASK + 1];
  __u8 hw;
  __u16 count[TC_QOPT_MAX_QUEUE];
- __u16 offset[TC_QOPT_MAX_QUEUE];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 offset[TC_QOPT_MAX_QUEUE];
 };
 enum {
  TCA_SFB_UNSPEC,
- TCA_SFB_PARMS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_SFB_PARMS,
  __TCA_SFB_MAX,
 };
 #define TCA_SFB_MAX (__TCA_SFB_MAX - 1)
-struct tc_sfb_qopt {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct tc_sfb_qopt {
  __u32 rehash_interval;
  __u32 warmup_time;
  __u32 max;
- __u32 bin_size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 bin_size;
  __u32 increment;
  __u32 decrement;
  __u32 limit;
- __u32 penalty_rate;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 penalty_rate;
  __u32 penalty_burst;
 };
 struct tc_sfb_xstats {
- __u32 earlydrop;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 earlydrop;
  __u32 penaltydrop;
  __u32 bucketdrop;
  __u32 queuedrop;
- __u32 childdrop;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 childdrop;
  __u32 marked;
  __u32 maxqlen;
  __u32 maxprob;
- __u32 avgprob;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 avgprob;
 };
 #define SFB_MAX_PROB 0xFFFF
 enum {
- TCA_QFQ_UNSPEC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_QFQ_UNSPEC,
  TCA_QFQ_WEIGHT,
  TCA_QFQ_LMAX,
  __TCA_QFQ_MAX
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define TCA_QFQ_MAX (__TCA_QFQ_MAX - 1)
 struct tc_qfq_stats {
  __u32 weight;
- __u32 lmax;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 lmax;
 };
 enum {
  TCA_CODEL_UNSPEC,
- TCA_CODEL_TARGET,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_CODEL_TARGET,
  TCA_CODEL_LIMIT,
  TCA_CODEL_INTERVAL,
  TCA_CODEL_ECN,
- __TCA_CODEL_MAX
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __TCA_CODEL_MAX
 };
 #define TCA_CODEL_MAX (__TCA_CODEL_MAX - 1)
 struct tc_codel_xstats {
- __u32 maxpacket;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 maxpacket;
  __u32 count;
  __u32 lastcount;
  __u32 ldelay;
- __s32 drop_next;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s32 drop_next;
  __u32 drop_overlimit;
  __u32 ecn_mark;
  __u32 dropping;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  TCA_FQ_CODEL_UNSPEC,
  TCA_FQ_CODEL_TARGET,
- TCA_FQ_CODEL_LIMIT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_FQ_CODEL_LIMIT,
  TCA_FQ_CODEL_INTERVAL,
  TCA_FQ_CODEL_ECN,
  TCA_FQ_CODEL_FLOWS,
- TCA_FQ_CODEL_QUANTUM,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_FQ_CODEL_QUANTUM,
  __TCA_FQ_CODEL_MAX
 };
 #define TCA_FQ_CODEL_MAX (__TCA_FQ_CODEL_MAX - 1)
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  TCA_FQ_CODEL_XSTATS_QDISC,
  TCA_FQ_CODEL_XSTATS_CLASS,
 };
-struct tc_fq_codel_qd_stats {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct tc_fq_codel_qd_stats {
  __u32 maxpacket;
  __u32 drop_overlimit;
  __u32 ecn_mark;
- __u32 new_flow_count;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 new_flow_count;
  __u32 new_flows_len;
  __u32 old_flows_len;
 };
-struct tc_fq_codel_cl_stats {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct tc_fq_codel_cl_stats {
  __s32 deficit;
  __u32 ldelay;
  __u32 count;
- __u32 lastcount;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 lastcount;
  __u32 dropping;
  __s32 drop_next;
 };
-struct tc_fq_codel_xstats {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct tc_fq_codel_xstats {
  __u32 type;
  union {
  struct tc_fq_codel_qd_stats qdisc_stats;
- struct tc_fq_codel_cl_stats class_stats;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct tc_fq_codel_cl_stats class_stats;
  };
 };
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_FQ_UNSPEC,
+ TCA_FQ_PLIMIT,
+ TCA_FQ_FLOW_PLIMIT,
+ TCA_FQ_QUANTUM,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_FQ_INITIAL_QUANTUM,
+ TCA_FQ_RATE_ENABLE,
+ TCA_FQ_FLOW_DEFAULT_RATE,
+ TCA_FQ_FLOW_MAX_RATE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_FQ_BUCKETS_LOG,
+ TCA_FQ_FLOW_REFILL_DELAY,
+ __TCA_FQ_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCA_FQ_MAX (__TCA_FQ_MAX - 1)
+struct tc_fq_qd_stats {
+ __u64 gc_flows;
+ __u64 highprio_packets;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 tcp_retrans;
+ __u64 throttled;
+ __u64 flows_plimit;
+ __u64 pkts_too_long;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 allocation_errors;
+ __s64 time_next_delayed_flow;
+ __u32 flows;
+ __u32 inactive_flows;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 throttled_flows;
+ __u32 pad;
+};
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_HHF_UNSPEC,
+ TCA_HHF_BACKLOG_LIMIT,
+ TCA_HHF_QUANTUM,
+ TCA_HHF_HH_FLOWS_LIMIT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_HHF_RESET_TIMEOUT,
+ TCA_HHF_ADMIT_BYTES,
+ TCA_HHF_EVICT_TIMEOUT,
+ TCA_HHF_NON_HH_WEIGHT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __TCA_HHF_MAX
+};
+#define TCA_HHF_MAX (__TCA_HHF_MAX - 1)
+struct tc_hhf_xstats {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 drop_overlimit;
+ __u32 hh_overlimit;
+ __u32 hh_tot_count;
+ __u32 hh_cur_count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum {
+ TCA_PIE_UNSPEC,
+ TCA_PIE_TARGET,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_PIE_LIMIT,
+ TCA_PIE_TUPDATE,
+ TCA_PIE_ALPHA,
+ TCA_PIE_BETA,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_PIE_ECN,
+ TCA_PIE_BYTEMODE,
+ __TCA_PIE_MAX
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCA_PIE_MAX (__TCA_PIE_MAX - 1)
+struct tc_pie_xstats {
+ __u32 prob;
+ __u32 delay;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 avg_dq_rate;
+ __u32 packets_in;
+ __u32 dropped;
+ __u32 overlimit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 maxq;
+ __u32 ecn_mark;
+};
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/ppp-ioctl.h b/libc/kernel/uapi/linux/ppp-ioctl.h
index 43c4c50..fa2423c 100644
--- a/libc/kernel/uapi/linux/ppp-ioctl.h
+++ b/libc/kernel/uapi/linux/ppp-ioctl.h
@@ -21,110 +21,111 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#include <linux/ppp_defs.h>
 #define SC_COMP_PROT 0x00000001
 #define SC_COMP_AC 0x00000002
 #define SC_COMP_TCP 0x00000004
-#define SC_NO_TCP_CCID 0x00000008
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SC_NO_TCP_CCID 0x00000008
 #define SC_REJ_COMP_AC 0x00000010
 #define SC_REJ_COMP_TCP 0x00000020
 #define SC_CCP_OPEN 0x00000040
-#define SC_CCP_UP 0x00000080
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SC_CCP_UP 0x00000080
 #define SC_ENABLE_IP 0x00000100
 #define SC_LOOP_TRAFFIC 0x00000200
 #define SC_MULTILINK 0x00000400
-#define SC_MP_SHORTSEQ 0x00000800
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SC_MP_SHORTSEQ 0x00000800
 #define SC_COMP_RUN 0x00001000
 #define SC_DECOMP_RUN 0x00002000
 #define SC_MP_XSHORTSEQ 0x00004000
-#define SC_DEBUG 0x00010000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SC_DEBUG 0x00010000
 #define SC_LOG_INPKT 0x00020000
 #define SC_LOG_OUTPKT 0x00040000
 #define SC_LOG_RAWIN 0x00080000
-#define SC_LOG_FLUSH 0x00100000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SC_LOG_FLUSH 0x00100000
 #define SC_SYNC 0x00200000
 #define SC_MUST_COMP 0x00400000
 #define SC_MASK 0x0f600fff
-#define SC_XMIT_BUSY 0x10000000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SC_XMIT_BUSY 0x10000000
 #define SC_RCV_ODDP 0x08000000
 #define SC_RCV_EVNP 0x04000000
 #define SC_RCV_B7_1 0x02000000
-#define SC_RCV_B7_0 0x01000000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SC_RCV_B7_0 0x01000000
 #define SC_DC_FERROR 0x00800000
 #define SC_DC_ERROR 0x00400000
 struct npioctl {
- int protocol;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int protocol;
  enum NPmode mode;
 };
 struct ppp_option_data {
- __u8 __user *ptr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 __user *ptr;
  __u32 length;
  int transmit;
 };
-struct pppol2tp_ioc_stats {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct pppol2tp_ioc_stats {
  __u16 tunnel_id;
  __u16 session_id;
  __u32 using_ipsec:1;
- __aligned_u64 tx_packets;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __aligned_u64 tx_packets;
  __aligned_u64 tx_bytes;
  __aligned_u64 tx_errors;
  __aligned_u64 rx_packets;
- __aligned_u64 rx_bytes;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __aligned_u64 rx_bytes;
  __aligned_u64 rx_seq_discards;
  __aligned_u64 rx_oos_packets;
  __aligned_u64 rx_errors;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define PPPIOCGFLAGS _IOR('t', 90, int)
 #define PPPIOCSFLAGS _IOW('t', 89, int)
 #define PPPIOCGASYNCMAP _IOR('t', 88, int)
-#define PPPIOCSASYNCMAP _IOW('t', 87, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PPPIOCSASYNCMAP _IOW('t', 87, int)
 #define PPPIOCGUNIT _IOR('t', 86, int)
 #define PPPIOCGRASYNCMAP _IOR('t', 85, int)
 #define PPPIOCSRASYNCMAP _IOW('t', 84, int)
-#define PPPIOCGMRU _IOR('t', 83, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PPPIOCGMRU _IOR('t', 83, int)
 #define PPPIOCSMRU _IOW('t', 82, int)
 #define PPPIOCSMAXCID _IOW('t', 81, int)
 #define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm)
-#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm)
 #define PPPIOCXFERUNIT _IO('t', 78)
 #define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data)
 #define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl)
-#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl)
 #define PPPIOCSPASS _IOW('t', 71, struct sock_fprog)
 #define PPPIOCSACTIVE _IOW('t', 70, struct sock_fprog)
 #define PPPIOCGDEBUG _IOR('t', 65, int)
-#define PPPIOCSDEBUG _IOW('t', 64, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PPPIOCSDEBUG _IOW('t', 64, int)
 #define PPPIOCGIDLE _IOR('t', 63, struct ppp_idle)
 #define PPPIOCNEWUNIT _IOWR('t', 62, int)
 #define PPPIOCATTACH _IOW('t', 61, int)
-#define PPPIOCDETACH _IOW('t', 60, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PPPIOCDETACH _IOW('t', 60, int)
 #define PPPIOCSMRRU _IOW('t', 59, int)
 #define PPPIOCCONNECT _IOW('t', 58, int)
 #define PPPIOCDISCONN _IO('t', 57)
-#define PPPIOCATTCHAN _IOW('t', 56, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PPPIOCATTCHAN _IOW('t', 56, int)
 #define PPPIOCGCHAN _IOR('t', 55, int)
 #define PPPIOCGL2TPSTATS _IOR('t', 54, struct pppol2tp_ioc_stats)
 #define SIOCGPPPSTATS (SIOCDEVPRIVATE + 0)
-#define SIOCGPPPVER (SIOCDEVPRIVATE + 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SIOCGPPPVER (SIOCDEVPRIVATE + 1)
 #define SIOCGPPPCSTATS (SIOCDEVPRIVATE + 2)
 #endif
diff --git a/libc/kernel/uapi/linux/prctl.h b/libc/kernel/uapi/linux/prctl.h
index 87c7e2f..a127b5a 100644
--- a/libc/kernel/uapi/linux/prctl.h
+++ b/libc/kernel/uapi/linux/prctl.h
@@ -117,7 +117,4 @@
 #define PR_GET_NO_NEW_PRIVS 39
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PR_GET_TID_ADDRESS 40
-#define PR_SET_VMA 0x53564d41
-#define PR_SET_VMA_ANON_NAME 0
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/ptrace.h b/libc/kernel/uapi/linux/ptrace.h
index a21fbac..6f71b6d 100644
--- a/libc/kernel/uapi/linux/ptrace.h
+++ b/libc/kernel/uapi/linux/ptrace.h
@@ -54,30 +54,32 @@
  __u32 flags;
  __s32 nr;
 };
-#define PTRACE_PEEKSIGINFO_SHARED (1 << 0)
+#define PTRACE_GETSIGMASK 0x420a
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PTRACE_SETSIGMASK 0x420b
+#define PTRACE_PEEKSIGINFO_SHARED (1 << 0)
 #define PTRACE_EVENT_FORK 1
 #define PTRACE_EVENT_VFORK 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PTRACE_EVENT_CLONE 3
 #define PTRACE_EVENT_EXEC 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PTRACE_EVENT_VFORK_DONE 5
 #define PTRACE_EVENT_EXIT 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PTRACE_EVENT_SECCOMP 7
 #define PTRACE_EVENT_STOP 128
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PTRACE_O_TRACESYSGOOD 1
 #define PTRACE_O_TRACEFORK (1 << PTRACE_EVENT_FORK)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PTRACE_O_TRACEVFORK (1 << PTRACE_EVENT_VFORK)
 #define PTRACE_O_TRACECLONE (1 << PTRACE_EVENT_CLONE)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PTRACE_O_TRACEEXEC (1 << PTRACE_EVENT_EXEC)
 #define PTRACE_O_TRACEVFORKDONE (1 << PTRACE_EVENT_VFORK_DONE)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PTRACE_O_TRACEEXIT (1 << PTRACE_EVENT_EXIT)
 #define PTRACE_O_TRACESECCOMP (1 << PTRACE_EVENT_SECCOMP)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PTRACE_O_EXITKILL (1 << 20)
 #define PTRACE_O_MASK (0x000000ff | PTRACE_O_EXITKILL)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #include <asm/ptrace.h>
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/raid/md_p.h b/libc/kernel/uapi/linux/raid/md_p.h
index 52a1dab..fc6e20e 100644
--- a/libc/kernel/uapi/linux/raid/md_p.h
+++ b/libc/kernel/uapi/linux/raid/md_p.h
@@ -19,178 +19,181 @@
 #ifndef _MD_P_H
 #define _MD_P_H
 #include <linux/types.h>
-#define MD_RESERVED_BYTES (64 * 1024)
+#include <asm/byteorder.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_RESERVED_BYTES (64 * 1024)
 #define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512)
 #define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
 #define MD_SB_BYTES 4096
-#define MD_SB_WORDS (MD_SB_BYTES / 4)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_SB_WORDS (MD_SB_BYTES / 4)
 #define MD_SB_SECTORS (MD_SB_BYTES / 512)
 #define MD_SB_GENERIC_OFFSET 0
 #define MD_SB_PERSONALITY_OFFSET 64
-#define MD_SB_DISKS_OFFSET 128
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_SB_DISKS_OFFSET 128
 #define MD_SB_DESCRIPTOR_OFFSET 992
 #define MD_SB_GENERIC_CONSTANT_WORDS 32
 #define MD_SB_GENERIC_STATE_WORDS 32
-#define MD_SB_GENERIC_WORDS (MD_SB_GENERIC_CONSTANT_WORDS + MD_SB_GENERIC_STATE_WORDS)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_SB_GENERIC_WORDS (MD_SB_GENERIC_CONSTANT_WORDS + MD_SB_GENERIC_STATE_WORDS)
 #define MD_SB_PERSONALITY_WORDS 64
 #define MD_SB_DESCRIPTOR_WORDS 32
 #define MD_SB_DISKS 27
-#define MD_SB_DISKS_WORDS (MD_SB_DISKS*MD_SB_DESCRIPTOR_WORDS)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_SB_DISKS_WORDS (MD_SB_DISKS*MD_SB_DESCRIPTOR_WORDS)
 #define MD_SB_RESERVED_WORDS (1024 - MD_SB_GENERIC_WORDS - MD_SB_PERSONALITY_WORDS - MD_SB_DISKS_WORDS - MD_SB_DESCRIPTOR_WORDS)
 #define MD_SB_EQUAL_WORDS (MD_SB_GENERIC_WORDS + MD_SB_PERSONALITY_WORDS + MD_SB_DISKS_WORDS)
 #define MD_DISK_FAULTY 0
-#define MD_DISK_ACTIVE 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_DISK_ACTIVE 1
 #define MD_DISK_SYNC 2
 #define MD_DISK_REMOVED 3
 #define MD_DISK_WRITEMOSTLY 9
-typedef struct mdp_device_descriptor_s {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct mdp_device_descriptor_s {
  __u32 number;
  __u32 major;
  __u32 minor;
- __u32 raid_disk;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 raid_disk;
  __u32 state;
  __u32 reserved[MD_SB_DESCRIPTOR_WORDS - 5];
 } mdp_disk_t;
-#define MD_SB_MAGIC 0xa92b4efc
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_SB_MAGIC 0xa92b4efc
 #define MD_SB_CLEAN 0
 #define MD_SB_ERRORS 1
 #define MD_SB_BITMAP_PRESENT 8
-typedef struct mdp_superblock_s {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct mdp_superblock_s {
  __u32 md_magic;
  __u32 major_version;
  __u32 minor_version;
- __u32 patch_version;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 patch_version;
  __u32 gvalid_words;
  __u32 set_uuid0;
  __u32 ctime;
- __u32 level;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 level;
  __u32 size;
  __u32 nr_disks;
  __u32 raid_disks;
- __u32 md_minor;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 md_minor;
  __u32 not_persistent;
  __u32 set_uuid1;
  __u32 set_uuid2;
- __u32 set_uuid3;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 set_uuid3;
  __u32 gstate_creserved[MD_SB_GENERIC_CONSTANT_WORDS - 16];
  __u32 utime;
  __u32 state;
- __u32 active_disks;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 active_disks;
  __u32 working_disks;
  __u32 failed_disks;
  __u32 spare_disks;
- __u32 sb_csum;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 sb_csum;
 #if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
  __u32 events_hi;
  __u32 events_lo;
- __u32 cp_events_hi;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 cp_events_hi;
  __u32 cp_events_lo;
 #elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
  __u32 events_lo;
- __u32 events_hi;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 events_hi;
  __u32 cp_events_lo;
  __u32 cp_events_hi;
 #else
-#error unspecified endianness
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#error unspecified endianness
 #endif
  __u32 recovery_cp;
  __u64 reshape_position;
- __u32 new_level;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 new_level;
  __u32 delta_disks;
  __u32 new_layout;
  __u32 new_chunk;
- __u32 gstate_sreserved[MD_SB_GENERIC_STATE_WORDS - 18];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 gstate_sreserved[MD_SB_GENERIC_STATE_WORDS - 18];
  __u32 layout;
  __u32 chunk_size;
  __u32 root_pv;
- __u32 root_block;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 root_block;
  __u32 pstate_reserved[MD_SB_PERSONALITY_WORDS - 4];
  mdp_disk_t disks[MD_SB_DISKS];
  __u32 reserved[MD_SB_RESERVED_WORDS];
- mdp_disk_t this_disk;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ mdp_disk_t this_disk;
 } mdp_super_t;
 #define MD_SUPERBLOCK_1_TIME_SEC_MASK ((1ULL<<40) - 1)
 struct mdp_superblock_1 {
- __le32 magic;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 magic;
  __le32 major_version;
  __le32 feature_map;
  __le32 pad0;
- __u8 set_uuid[16];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 set_uuid[16];
  char set_name[32];
  __le64 ctime;
  __le32 level;
- __le32 layout;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 layout;
  __le64 size;
  __le32 chunksize;
  __le32 raid_disks;
- __le32 bitmap_offset;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 bitmap_offset;
  __le32 new_level;
  __le64 reshape_position;
  __le32 delta_disks;
- __le32 new_layout;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 new_layout;
  __le32 new_chunk;
  __le32 new_offset;
  __le64 data_offset;
- __le64 data_size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le64 data_size;
  __le64 super_offset;
  __le64 recovery_offset;
  __le32 dev_number;
- __le32 cnt_corrected_read;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 cnt_corrected_read;
  __u8 device_uuid[16];
  __u8 devflags;
 #define WriteMostly1 1
- __u8 bblog_shift;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 bblog_shift;
  __le16 bblog_size;
  __le32 bblog_offset;
  __le64 utime;
- __le64 events;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le64 events;
  __le64 resync_offset;
  __le32 sb_csum;
  __le32 max_dev;
- __u8 pad3[64-32];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 pad3[64-32];
  __le16 dev_roles[0];
 };
 #define MD_FEATURE_BITMAP_OFFSET 1
-#define MD_FEATURE_RECOVERY_OFFSET 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_FEATURE_RECOVERY_OFFSET 2
 #define MD_FEATURE_RESHAPE_ACTIVE 4
 #define MD_FEATURE_BAD_BLOCKS 8
 #define MD_FEATURE_REPLACEMENT 16
-#define MD_FEATURE_RESHAPE_BACKWARDS 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MD_FEATURE_RESHAPE_BACKWARDS 32
 #define MD_FEATURE_NEW_OFFSET 64
-#define MD_FEATURE_ALL (MD_FEATURE_BITMAP_OFFSET   |MD_FEATURE_RECOVERY_OFFSET   |MD_FEATURE_RESHAPE_ACTIVE   |MD_FEATURE_BAD_BLOCKS   |MD_FEATURE_REPLACEMENT   |MD_FEATURE_RESHAPE_BACKWARDS   |MD_FEATURE_NEW_OFFSET   )
+#define MD_FEATURE_RECOVERY_BITMAP 128
+#define MD_FEATURE_ALL (MD_FEATURE_BITMAP_OFFSET   |MD_FEATURE_RECOVERY_OFFSET   |MD_FEATURE_RESHAPE_ACTIVE   |MD_FEATURE_BAD_BLOCKS   |MD_FEATURE_REPLACEMENT   |MD_FEATURE_RESHAPE_BACKWARDS   |MD_FEATURE_NEW_OFFSET   |MD_FEATURE_RECOVERY_BITMAP   )
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/random.h b/libc/kernel/uapi/linux/random.h
index 43560b6..6215d08 100644
--- a/libc/kernel/uapi/linux/random.h
+++ b/libc/kernel/uapi/linux/random.h
@@ -36,8 +36,4 @@
  __u32 buf[0];
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct rnd_state {
- __u32 s1, s2, s3;
-};
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/reiserfs_xattr.h b/libc/kernel/uapi/linux/reiserfs_xattr.h
index 2abd97a..9056de2 100644
--- a/libc/kernel/uapi/linux/reiserfs_xattr.h
+++ b/libc/kernel/uapi/linux/reiserfs_xattr.h
@@ -27,7 +27,7 @@
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct reiserfs_security_handle {
- char *name;
+ const char *name;
  void *value;
  size_t length;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/resource.h b/libc/kernel/uapi/linux/resource.h
index e78ed60..9d260c2 100644
--- a/libc/kernel/uapi/linux/resource.h
+++ b/libc/kernel/uapi/linux/resource.h
@@ -29,29 +29,29 @@
 struct rusage {
  struct timeval ru_utime;
  struct timeval ru_stime;
- long ru_maxrss;
+ __kernel_long_t ru_maxrss;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long ru_ixrss;
- long ru_idrss;
- long ru_isrss;
- long ru_minflt;
+ __kernel_long_t ru_ixrss;
+ __kernel_long_t ru_idrss;
+ __kernel_long_t ru_isrss;
+ __kernel_long_t ru_minflt;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long ru_majflt;
- long ru_nswap;
- long ru_inblock;
- long ru_oublock;
+ __kernel_long_t ru_majflt;
+ __kernel_long_t ru_nswap;
+ __kernel_long_t ru_inblock;
+ __kernel_long_t ru_oublock;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long ru_msgsnd;
- long ru_msgrcv;
- long ru_nsignals;
- long ru_nvcsw;
+ __kernel_long_t ru_msgsnd;
+ __kernel_long_t ru_msgrcv;
+ __kernel_long_t ru_nsignals;
+ __kernel_long_t ru_nvcsw;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long ru_nivcsw;
+ __kernel_long_t ru_nivcsw;
 };
 struct rlimit {
- unsigned long rlim_cur;
+ __kernel_ulong_t rlim_cur;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long rlim_max;
+ __kernel_ulong_t rlim_max;
 };
 #define RLIM64_INFINITY (~0ULL)
 struct rlimit64 {
diff --git a/libc/kernel/uapi/linux/rtnetlink.h b/libc/kernel/uapi/linux/rtnetlink.h
index 718a2db..3a03e88 100644
--- a/libc/kernel/uapi/linux/rtnetlink.h
+++ b/libc/kernel/uapi/linux/rtnetlink.h
@@ -346,234 +346,236 @@
  RTAX_INITRWND,
 #define RTAX_INITRWND RTAX_INITRWND
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ RTAX_QUICKACK,
+#define RTAX_QUICKACK RTAX_QUICKACK
  __RTAX_MAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTAX_MAX (__RTAX_MAX - 1)
 #define RTAX_FEATURE_ECN 0x00000001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTAX_FEATURE_SACK 0x00000002
 #define RTAX_FEATURE_TIMESTAMP 0x00000004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTAX_FEATURE_ALLFRAG 0x00000008
 struct rta_session {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 proto;
  __u8 pad1;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 pad2;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  __u16 sport;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 dport;
  } ports;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  __u8 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 code;
  __u16 ident;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } icmpt;
  __u32 spi;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } u;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct rta_mfc_stats {
  __u64 mfcs_packets;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 mfcs_bytes;
  __u64 mfcs_wrong_if;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct rtgenmsg {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char rtgen_family;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ifinfomsg {
  unsigned char ifi_family;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char __ifi_pad;
  unsigned short ifi_type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int ifi_index;
  unsigned ifi_flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned ifi_change;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct prefixmsg {
  unsigned char prefix_family;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char prefix_pad1;
  unsigned short prefix_pad2;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int prefix_ifindex;
  unsigned char prefix_type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char prefix_len;
  unsigned char prefix_flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char prefix_pad3;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum
 {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PREFIX_UNSPEC,
  PREFIX_ADDRESS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PREFIX_CACHEINFO,
  __PREFIX_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define PREFIX_MAX (__PREFIX_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct prefix_cacheinfo {
  __u32 preferred_time;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 valid_time;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct tcmsg {
  unsigned char tcm_family;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char tcm__pad1;
  unsigned short tcm__pad2;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int tcm_ifindex;
  __u32 tcm_handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tcm_parent;
  __u32 tcm_info;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_UNSPEC,
  TCA_KIND,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_OPTIONS,
  TCA_STATS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_XSTATS,
  TCA_RATE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_FCNT,
  TCA_STATS2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCA_STAB,
  __TCA_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TCA_MAX (__TCA_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct nduseroptmsg {
  unsigned char nduseropt_family;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char nduseropt_pad1;
  unsigned short nduseropt_opts_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int nduseropt_ifindex;
  __u8 nduseropt_icmp_type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 nduseropt_icmp_code;
  unsigned short nduseropt_pad2;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int nduseropt_pad3;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  NDUSEROPT_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  NDUSEROPT_SRCADDR,
  __NDUSEROPT_MAX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define NDUSEROPT_MAX (__NDUSEROPT_MAX - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTMGRP_LINK 1
 #define RTMGRP_NOTIFY 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTMGRP_NEIGH 4
 #define RTMGRP_TC 8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTMGRP_IPV4_IFADDR 0x10
 #define RTMGRP_IPV4_MROUTE 0x20
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTMGRP_IPV4_ROUTE 0x40
 #define RTMGRP_IPV4_RULE 0x80
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTMGRP_IPV6_IFADDR 0x100
 #define RTMGRP_IPV6_MROUTE 0x200
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTMGRP_IPV6_ROUTE 0x400
 #define RTMGRP_IPV6_IFINFO 0x800
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTMGRP_DECnet_IFADDR 0x1000
 #define RTMGRP_DECnet_ROUTE 0x4000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTMGRP_IPV6_PREFIX 0x20000
 enum rtnetlink_groups {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_NONE,
 #define RTNLGRP_NONE RTNLGRP_NONE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_LINK,
 #define RTNLGRP_LINK RTNLGRP_LINK
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_NOTIFY,
 #define RTNLGRP_NOTIFY RTNLGRP_NOTIFY
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_NEIGH,
 #define RTNLGRP_NEIGH RTNLGRP_NEIGH
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_TC,
 #define RTNLGRP_TC RTNLGRP_TC
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV4_IFADDR,
 #define RTNLGRP_IPV4_IFADDR RTNLGRP_IPV4_IFADDR
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV4_MROUTE,
 #define RTNLGRP_IPV4_MROUTE RTNLGRP_IPV4_MROUTE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV4_ROUTE,
 #define RTNLGRP_IPV4_ROUTE RTNLGRP_IPV4_ROUTE
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV4_RULE,
 #define RTNLGRP_IPV4_RULE RTNLGRP_IPV4_RULE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV6_IFADDR,
 #define RTNLGRP_IPV6_IFADDR RTNLGRP_IPV6_IFADDR
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV6_MROUTE,
 #define RTNLGRP_IPV6_MROUTE RTNLGRP_IPV6_MROUTE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV6_ROUTE,
 #define RTNLGRP_IPV6_ROUTE RTNLGRP_IPV6_ROUTE
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV6_IFINFO,
 #define RTNLGRP_IPV6_IFINFO RTNLGRP_IPV6_IFINFO
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_DECnet_IFADDR,
 #define RTNLGRP_DECnet_IFADDR RTNLGRP_DECnet_IFADDR
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_NOP2,
  RTNLGRP_DECnet_ROUTE,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTNLGRP_DECnet_ROUTE RTNLGRP_DECnet_ROUTE
  RTNLGRP_DECnet_RULE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTNLGRP_DECnet_RULE RTNLGRP_DECnet_RULE
  RTNLGRP_NOP4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV6_PREFIX,
 #define RTNLGRP_IPV6_PREFIX RTNLGRP_IPV6_PREFIX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV6_RULE,
 #define RTNLGRP_IPV6_RULE RTNLGRP_IPV6_RULE
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_ND_USEROPT,
 #define RTNLGRP_ND_USEROPT RTNLGRP_ND_USEROPT
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_PHONET_IFADDR,
 #define RTNLGRP_PHONET_IFADDR RTNLGRP_PHONET_IFADDR
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_PHONET_ROUTE,
 #define RTNLGRP_PHONET_ROUTE RTNLGRP_PHONET_ROUTE
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_DCB,
 #define RTNLGRP_DCB RTNLGRP_DCB
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV4_NETCONF,
 #define RTNLGRP_IPV4_NETCONF RTNLGRP_IPV4_NETCONF
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_IPV6_NETCONF,
 #define RTNLGRP_IPV6_NETCONF RTNLGRP_IPV6_NETCONF
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RTNLGRP_MDB,
 #define RTNLGRP_MDB RTNLGRP_MDB
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __RTNLGRP_MAX
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
 struct tcamsg {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char tca_family;
  unsigned char tca__pad1;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned short tca__pad2;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCA_ACT_TAB 1
 #define TCAA_MAX 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define RTEXT_FILTER_VF (1 << 0)
 #define RTEXT_FILTER_BRVLAN (1 << 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/sched.h b/libc/kernel/uapi/linux/sched.h
index c7542e8..d87bc2a 100644
--- a/libc/kernel/uapi/linux/sched.h
+++ b/libc/kernel/uapi/linux/sched.h
@@ -53,6 +53,8 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SCHED_BATCH 3
 #define SCHED_IDLE 5
+#define SCHED_DEADLINE 6
 #define SCHED_RESET_ON_FORK 0x40000000
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SCHED_FLAG_RESET_ON_FORK 0x01
+#endif
diff --git a/libc/kernel/uapi/linux/serial_core.h b/libc/kernel/uapi/linux/serial_core.h
index 2832a06..59fc32a 100644
--- a/libc/kernel/uapi/linux/serial_core.h
+++ b/libc/kernel/uapi/linux/serial_core.h
@@ -138,4 +138,9 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define PORT_ARC 101
 #define PORT_RP2 102
+#define PORT_LPUART 103
+#define PORT_HSCIF 104
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define PORT_ASC 105
+#define PORT_TILEGX 106
 #endif
diff --git a/libc/kernel/uapi/linux/shm.h b/libc/kernel/uapi/linux/shm.h
index a62c5ef..28e1670 100644
--- a/libc/kernel/uapi/linux/shm.h
+++ b/libc/kernel/uapi/linux/shm.h
@@ -69,12 +69,12 @@
 };
 struct shm_info {
  int used_ids;
- unsigned long shm_tot;
+ __kernel_ulong_t shm_tot;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- unsigned long shm_rss;
- unsigned long shm_swp;
- unsigned long swap_attempts;
- unsigned long swap_successes;
+ __kernel_ulong_t shm_rss;
+ __kernel_ulong_t shm_swp;
+ __kernel_ulong_t swap_attempts;
+ __kernel_ulong_t swap_successes;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
diff --git a/libc/kernel/uapi/linux/snmp.h b/libc/kernel/uapi/linux/snmp.h
index 11b90a7..9d5fb09 100644
--- a/libc/kernel/uapi/linux/snmp.h
+++ b/libc/kernel/uapi/linux/snmp.h
@@ -61,6 +61,11 @@
  IPSTATS_MIB_OUTBCASTOCTETS,
  IPSTATS_MIB_CSUMERRORS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IPSTATS_MIB_NOECTPKTS,
+ IPSTATS_MIB_ECT1PKTS,
+ IPSTATS_MIB_ECT0PKTS,
+ IPSTATS_MIB_CEPKTS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __IPSTATS_MIB_MAX
 };
 enum
@@ -279,47 +284,51 @@
  LINUX_MIB_TCPFASTOPENLISTENOVERFLOW,
  LINUX_MIB_TCPFASTOPENCOOKIEREQD,
  LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES,
- __LINUX_MIB_MAX
+ LINUX_MIB_BUSYPOLLRXPACKETS,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ LINUX_MIB_TCPAUTOCORKING,
+ __LINUX_MIB_MAX
 };
 enum
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 {
  LINUX_MIB_XFRMNUM = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMINERROR,
  LINUX_MIB_XFRMINBUFFERERROR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMINHDRERROR,
  LINUX_MIB_XFRMINNOSTATES,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMINSTATEPROTOERROR,
  LINUX_MIB_XFRMINSTATEMODEERROR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMINSTATESEQERROR,
  LINUX_MIB_XFRMINSTATEEXPIRED,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMINSTATEMISMATCH,
  LINUX_MIB_XFRMINSTATEINVALID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMINTMPLMISMATCH,
  LINUX_MIB_XFRMINNOPOLS,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMINPOLBLOCK,
  LINUX_MIB_XFRMINPOLERROR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMOUTERROR,
  LINUX_MIB_XFRMOUTBUNDLEGENERROR,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMOUTBUNDLECHECKERROR,
  LINUX_MIB_XFRMOUTNOSTATES,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMOUTSTATEPROTOERROR,
  LINUX_MIB_XFRMOUTSTATEMODEERROR,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMOUTSTATESEQERROR,
  LINUX_MIB_XFRMOUTSTATEEXPIRED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMOUTPOLBLOCK,
  LINUX_MIB_XFRMOUTPOLDEAD,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  LINUX_MIB_XFRMOUTPOLERROR,
  LINUX_MIB_XFRMFWDHDRERROR,
- LINUX_MIB_XFRMOUTSTATEINVALID,
- __LINUX_MIB_XFRMMAX
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ LINUX_MIB_XFRMOUTSTATEINVALID,
+ LINUX_MIB_XFRMACQUIREERROR,
+ __LINUX_MIB_XFRMMAX
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/sockios.h b/libc/kernel/uapi/linux/sockios.h
index b4cd102..b5e7c74 100644
--- a/libc/kernel/uapi/linux/sockios.h
+++ b/libc/kernel/uapi/linux/sockios.h
@@ -69,49 +69,49 @@
 #define SIOCDIFADDR 0x8936
 #define SIOCSIFHWBROADCAST 0x8937
 #define SIOCGIFCOUNT 0x8938
-#define SIOCKILLADDR 0x8939
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCGIFBR 0x8940
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCSIFBR 0x8941
 #define SIOCGIFTXQLEN 0x8942
 #define SIOCSIFTXQLEN 0x8943
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCETHTOOL 0x8946
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCGMIIPHY 0x8947
 #define SIOCGMIIREG 0x8948
 #define SIOCSMIIREG 0x8949
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCWANDEV 0x894A
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCOUTQNSD 0x894B
 #define SIOCDARP 0x8953
 #define SIOCGARP 0x8954
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCSARP 0x8955
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCDRARP 0x8960
 #define SIOCGRARP 0x8961
 #define SIOCSRARP 0x8962
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCGIFMAP 0x8970
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCSIFMAP 0x8971
 #define SIOCADDDLCI 0x8980
 #define SIOCDELDLCI 0x8981
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCGIFVLAN 0x8982
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCSIFVLAN 0x8983
 #define SIOCBONDENSLAVE 0x8990
 #define SIOCBONDRELEASE 0x8991
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCBONDSETHWADDR 0x8992
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCBONDSLAVEINFOQUERY 0x8993
 #define SIOCBONDINFOQUERY 0x8994
 #define SIOCBONDCHANGEACTIVE 0x8995
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCBRADDBR 0x89a0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCBRDELBR 0x89a1
 #define SIOCBRADDIF 0x89a2
 #define SIOCBRDELIF 0x89a3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIOCSHWTSTAMP 0x89b0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SIOCGHWTSTAMP 0x89b1
 #define SIOCDEVPRIVATE 0x89F0
 #define SIOCPROTOPRIVATE 0x89E0
 #endif
diff --git a/libc/kernel/uapi/linux/tc_act/tc_defact.h b/libc/kernel/uapi/linux/tc_act/tc_defact.h
new file mode 100644
index 0000000..4454dfc
--- /dev/null
+++ b/libc/kernel/uapi/linux/tc_act/tc_defact.h
@@ -0,0 +1,36 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __LINUX_TC_DEF_H
+#define __LINUX_TC_DEF_H
+#include <linux/pkt_cls.h>
+struct tc_defact {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ tc_gen;
+};
+enum {
+ TCA_DEF_UNSPEC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_DEF_TM,
+ TCA_DEF_PARMS,
+ TCA_DEF_DATA,
+ __TCA_DEF_MAX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define TCA_DEF_MAX (__TCA_DEF_MAX - 1)
+#endif
diff --git a/libc/kernel/uapi/linux/tc_act/tc_ipt.h b/libc/kernel/uapi/linux/tc_act/tc_ipt.h
index 451f8ea..00b88b8 100644
--- a/libc/kernel/uapi/linux/tc_act/tc_ipt.h
+++ b/libc/kernel/uapi/linux/tc_act/tc_ipt.h
@@ -21,18 +21,19 @@
 #include <linux/pkt_cls.h>
 #define TCA_ACT_IPT 6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCA_ACT_XT 10
 enum {
  TCA_IPT_UNSPEC,
  TCA_IPT_TABLE,
- TCA_IPT_HOOK,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_IPT_HOOK,
  TCA_IPT_INDEX,
  TCA_IPT_CNT,
  TCA_IPT_TM,
- TCA_IPT_TARG,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCA_IPT_TARG,
  __TCA_IPT_MAX
 };
 #define TCA_IPT_MAX (__TCA_IPT_MAX - 1)
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/tcp.h b/libc/kernel/uapi/linux/tcp.h
index bb12118..a7b5c5e 100644
--- a/libc/kernel/uapi/linux/tcp.h
+++ b/libc/kernel/uapi/linux/tcp.h
@@ -117,90 +117,92 @@
 #define TCP_FASTOPEN 23
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCP_TIMESTAMP 24
+#define TCP_NOTSENT_LOWAT 25
 struct tcp_repair_opt {
  __u32 opt_code;
- __u32 opt_val;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 opt_val;
 };
 enum {
  TCP_NO_QUEUE,
- TCP_RECV_QUEUE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TCP_RECV_QUEUE,
  TCP_SEND_QUEUE,
  TCP_QUEUES_NR,
 };
-#define TCPI_OPT_TIMESTAMPS 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCPI_OPT_TIMESTAMPS 1
 #define TCPI_OPT_SACK 2
 #define TCPI_OPT_WSCALE 4
 #define TCPI_OPT_ECN 8
-#define TCPI_OPT_ECN_SEEN 16
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCPI_OPT_ECN_SEEN 16
 #define TCPI_OPT_SYN_DATA 32
 enum tcp_ca_state {
  TCP_CA_Open = 0,
-#define TCPF_CA_Open (1<<TCP_CA_Open)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCPF_CA_Open (1<<TCP_CA_Open)
  TCP_CA_Disorder = 1,
 #define TCPF_CA_Disorder (1<<TCP_CA_Disorder)
  TCP_CA_CWR = 2,
-#define TCPF_CA_CWR (1<<TCP_CA_CWR)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCPF_CA_CWR (1<<TCP_CA_CWR)
  TCP_CA_Recovery = 3,
 #define TCPF_CA_Recovery (1<<TCP_CA_Recovery)
  TCP_CA_Loss = 4
-#define TCPF_CA_Loss (1<<TCP_CA_Loss)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TCPF_CA_Loss (1<<TCP_CA_Loss)
 };
 struct tcp_info {
  __u8 tcpi_state;
- __u8 tcpi_ca_state;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 tcpi_ca_state;
  __u8 tcpi_retransmits;
  __u8 tcpi_probes;
  __u8 tcpi_backoff;
- __u8 tcpi_options;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 tcpi_options;
  __u8 tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
  __u32 tcpi_rto;
  __u32 tcpi_ato;
- __u32 tcpi_snd_mss;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tcpi_snd_mss;
  __u32 tcpi_rcv_mss;
  __u32 tcpi_unacked;
  __u32 tcpi_sacked;
- __u32 tcpi_lost;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tcpi_lost;
  __u32 tcpi_retrans;
  __u32 tcpi_fackets;
  __u32 tcpi_last_data_sent;
- __u32 tcpi_last_ack_sent;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tcpi_last_ack_sent;
  __u32 tcpi_last_data_recv;
  __u32 tcpi_last_ack_recv;
  __u32 tcpi_pmtu;
- __u32 tcpi_rcv_ssthresh;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tcpi_rcv_ssthresh;
  __u32 tcpi_rtt;
  __u32 tcpi_rttvar;
  __u32 tcpi_snd_ssthresh;
- __u32 tcpi_snd_cwnd;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tcpi_snd_cwnd;
  __u32 tcpi_advmss;
  __u32 tcpi_reordering;
  __u32 tcpi_rcv_rtt;
- __u32 tcpi_rcv_space;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 tcpi_rcv_space;
  __u32 tcpi_total_retrans;
 };
 #define TCP_MD5SIG_MAXKEYLEN 80
-struct tcp_md5sig {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct tcp_md5sig {
  struct __kernel_sockaddr_storage tcpm_addr;
  __u16 __tcpm_pad1;
  __u16 tcpm_keylen;
- __u32 __tcpm_pad2;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 __tcpm_pad2;
  __u8 tcpm_key[TCP_MD5SIG_MAXKEYLEN];
 };
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/tcp_metrics.h b/libc/kernel/uapi/linux/tcp_metrics.h
index 4826bf0..449ec95 100644
--- a/libc/kernel/uapi/linux/tcp_metrics.h
+++ b/libc/kernel/uapi/linux/tcp_metrics.h
@@ -48,17 +48,19 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCP_METRICS_ATTR_FOPEN_SYN_DROP_TS,
  TCP_METRICS_ATTR_FOPEN_COOKIE,
+ TCP_METRICS_ATTR_SADDR_IPV4,
+ TCP_METRICS_ATTR_SADDR_IPV6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __TCP_METRICS_ATTR_MAX,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define TCP_METRICS_ATTR_MAX (__TCP_METRICS_ATTR_MAX - 1)
 enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCP_METRICS_CMD_UNSPEC,
  TCP_METRICS_CMD_GET,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCP_METRICS_CMD_DEL,
  __TCP_METRICS_CMD_MAX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define TCP_METRICS_CMD_MAX (__TCP_METRICS_CMD_MAX - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/timex.h b/libc/kernel/uapi/linux/timex.h
index 371d64a..a596698 100644
--- a/libc/kernel/uapi/linux/timex.h
+++ b/libc/kernel/uapi/linux/timex.h
@@ -23,28 +23,28 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct timex {
  unsigned int modes;
- long offset;
- long freq;
+ __kernel_long_t offset;
+ __kernel_long_t freq;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long maxerror;
- long esterror;
+ __kernel_long_t maxerror;
+ __kernel_long_t esterror;
  int status;
- long constant;
+ __kernel_long_t constant;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long precision;
- long tolerance;
+ __kernel_long_t precision;
+ __kernel_long_t tolerance;
  struct timeval time;
- long tick;
+ __kernel_long_t tick;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long ppsfreq;
- long jitter;
+ __kernel_long_t ppsfreq;
+ __kernel_long_t jitter;
  int shift;
- long stabil;
+ __kernel_long_t stabil;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- long jitcnt;
- long calcnt;
- long errcnt;
- long stbcnt;
+ __kernel_long_t jitcnt;
+ __kernel_long_t calcnt;
+ __kernel_long_t errcnt;
+ __kernel_long_t stbcnt;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int tai;
  int :32; int :32; int :32; int :32;
diff --git a/libc/kernel/uapi/linux/usb/ch11.h b/libc/kernel/uapi/linux/usb/ch11.h
index e27457e..cbe3d70 100644
--- a/libc/kernel/uapi/linux/usb/ch11.h
+++ b/libc/kernel/uapi/linux/usb/ch11.h
@@ -19,182 +19,183 @@
 #ifndef __LINUX_CH11_H
 #define __LINUX_CH11_H
 #include <linux/types.h>
-#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
+#define USB_MAXCHILDREN 31
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
 #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
 #define HUB_CLEAR_TT_BUFFER 8
 #define HUB_RESET_TT 9
-#define HUB_GET_TT_STATE 10
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HUB_GET_TT_STATE 10
 #define HUB_STOP_TT 11
 #define HUB_SET_DEPTH 12
 #define HUB_GET_PORT_ERR_COUNT 13
-#define C_HUB_LOCAL_POWER 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define C_HUB_LOCAL_POWER 0
 #define C_HUB_OVER_CURRENT 1
 #define USB_PORT_FEAT_CONNECTION 0
 #define USB_PORT_FEAT_ENABLE 1
-#define USB_PORT_FEAT_SUSPEND 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_FEAT_SUSPEND 2
 #define USB_PORT_FEAT_OVER_CURRENT 3
 #define USB_PORT_FEAT_RESET 4
 #define USB_PORT_FEAT_L1 5
-#define USB_PORT_FEAT_POWER 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_FEAT_POWER 8
 #define USB_PORT_FEAT_LOWSPEED 9
 #define USB_PORT_FEAT_C_CONNECTION 16
 #define USB_PORT_FEAT_C_ENABLE 17
-#define USB_PORT_FEAT_C_SUSPEND 18
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_FEAT_C_SUSPEND 18
 #define USB_PORT_FEAT_C_OVER_CURRENT 19
 #define USB_PORT_FEAT_C_RESET 20
 #define USB_PORT_FEAT_TEST 21
-#define USB_PORT_FEAT_INDICATOR 22
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_FEAT_INDICATOR 22
 #define USB_PORT_FEAT_C_PORT_L1 23
 #define USB_PORT_FEAT_LINK_STATE 5
 #define USB_PORT_FEAT_U1_TIMEOUT 23
-#define USB_PORT_FEAT_U2_TIMEOUT 24
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_FEAT_U2_TIMEOUT 24
 #define USB_PORT_FEAT_C_PORT_LINK_STATE 25
 #define USB_PORT_FEAT_C_PORT_CONFIG_ERROR 26
 #define USB_PORT_FEAT_REMOTE_WAKE_MASK 27
-#define USB_PORT_FEAT_BH_PORT_RESET 28
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_FEAT_BH_PORT_RESET 28
 #define USB_PORT_FEAT_C_BH_PORT_RESET 29
 #define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 30
 #define USB_PORT_LPM_TIMEOUT(p) (((p) & 0xff) << 8)
-#define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8)
 #define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT (1 << 9)
 #define USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT (1 << 10)
 struct usb_port_status {
- __le16 wPortStatus;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 wPortStatus;
  __le16 wPortChange;
 } __attribute__ ((packed));
 #define USB_PORT_STAT_CONNECTION 0x0001
-#define USB_PORT_STAT_ENABLE 0x0002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_STAT_ENABLE 0x0002
 #define USB_PORT_STAT_SUSPEND 0x0004
 #define USB_PORT_STAT_OVERCURRENT 0x0008
 #define USB_PORT_STAT_RESET 0x0010
-#define USB_PORT_STAT_L1 0x0020
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_STAT_L1 0x0020
 #define USB_PORT_STAT_POWER 0x0100
 #define USB_PORT_STAT_LOW_SPEED 0x0200
 #define USB_PORT_STAT_HIGH_SPEED 0x0400
-#define USB_PORT_STAT_TEST 0x0800
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_STAT_TEST 0x0800
 #define USB_PORT_STAT_INDICATOR 0x1000
 #define USB_PORT_STAT_LINK_STATE 0x01e0
 #define USB_SS_PORT_STAT_POWER 0x0200
-#define USB_SS_PORT_STAT_SPEED 0x1c00
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_SS_PORT_STAT_SPEED 0x1c00
 #define USB_PORT_STAT_SPEED_5GBPS 0x0000
 #define USB_SS_PORT_STAT_MASK (USB_PORT_STAT_CONNECTION |   USB_PORT_STAT_ENABLE |   USB_PORT_STAT_OVERCURRENT |   USB_PORT_STAT_RESET)
 #define USB_SS_PORT_LS_U0 0x0000
-#define USB_SS_PORT_LS_U1 0x0020
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_SS_PORT_LS_U1 0x0020
 #define USB_SS_PORT_LS_U2 0x0040
 #define USB_SS_PORT_LS_U3 0x0060
 #define USB_SS_PORT_LS_SS_DISABLED 0x0080
-#define USB_SS_PORT_LS_RX_DETECT 0x00a0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_SS_PORT_LS_RX_DETECT 0x00a0
 #define USB_SS_PORT_LS_SS_INACTIVE 0x00c0
 #define USB_SS_PORT_LS_POLLING 0x00e0
 #define USB_SS_PORT_LS_RECOVERY 0x0100
-#define USB_SS_PORT_LS_HOT_RESET 0x0120
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_SS_PORT_LS_HOT_RESET 0x0120
 #define USB_SS_PORT_LS_COMP_MOD 0x0140
 #define USB_SS_PORT_LS_LOOPBACK 0x0160
 #define USB_PORT_STAT_C_CONNECTION 0x0001
-#define USB_PORT_STAT_C_ENABLE 0x0002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_STAT_C_ENABLE 0x0002
 #define USB_PORT_STAT_C_SUSPEND 0x0004
 #define USB_PORT_STAT_C_OVERCURRENT 0x0008
 #define USB_PORT_STAT_C_RESET 0x0010
-#define USB_PORT_STAT_C_L1 0x0020
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_PORT_STAT_C_L1 0x0020
 #define USB_PORT_STAT_C_BH_RESET 0x0020
 #define USB_PORT_STAT_C_LINK_STATE 0x0040
 #define USB_PORT_STAT_C_CONFIG_ERROR 0x0080
-#define HUB_CHAR_LPSM 0x0003
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HUB_CHAR_LPSM 0x0003
 #define HUB_CHAR_COMMON_LPSM 0x0000
 #define HUB_CHAR_INDV_PORT_LPSM 0x0001
 #define HUB_CHAR_NO_LPSM 0x0002
-#define HUB_CHAR_COMPOUND 0x0004
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HUB_CHAR_COMPOUND 0x0004
 #define HUB_CHAR_OCPM 0x0018
 #define HUB_CHAR_COMMON_OCPM 0x0000
 #define HUB_CHAR_INDV_PORT_OCPM 0x0008
-#define HUB_CHAR_NO_OCPM 0x0010
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HUB_CHAR_NO_OCPM 0x0010
 #define HUB_CHAR_TTTT 0x0060
 #define HUB_CHAR_PORTIND 0x0080
 struct usb_hub_status {
- __le16 wHubStatus;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 wHubStatus;
  __le16 wHubChange;
 } __attribute__ ((packed));
 #define HUB_STATUS_LOCAL_POWER 0x0001
-#define HUB_STATUS_OVERCURRENT 0x0002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HUB_STATUS_OVERCURRENT 0x0002
 #define HUB_CHANGE_LOCAL_POWER 0x0001
 #define HUB_CHANGE_OVERCURRENT 0x0002
 #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
-#define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a)
 #define USB_DT_HUB_NONVAR_SIZE 7
 #define USB_DT_SS_HUB_SIZE 12
 #define USB_HUB_PR_FS 0
-#define USB_HUB_PR_HS_NO_TT 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define USB_HUB_PR_HS_NO_TT 0
 #define USB_HUB_PR_HS_SINGLE_TT 1
 #define USB_HUB_PR_HS_MULTI_TT 2
 #define USB_HUB_PR_SS 3
-struct usb_hub_descriptor {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct usb_hub_descriptor {
  __u8 bDescLength;
  __u8 bDescriptorType;
  __u8 bNbrPorts;
- __le16 wHubCharacteristics;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 wHubCharacteristics;
  __u8 bPwrOn2PwrGood;
  __u8 bHubContrCurrent;
  union {
- struct {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct {
  __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
  __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
  } __attribute__ ((packed)) hs;
- struct {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct {
  __u8 bHubHdrDecLat;
  __le16 wHubDelay;
  __le16 DeviceRemovable;
- } __attribute__ ((packed)) ss;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ } __attribute__ ((packed)) ss;
  } u;
 } __attribute__ ((packed));
 #define HUB_LED_AUTO 0
-#define HUB_LED_AMBER 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HUB_LED_AMBER 1
 #define HUB_LED_GREEN 2
 #define HUB_LED_OFF 3
 enum hub_led_mode {
- INDICATOR_AUTO = 0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ INDICATOR_AUTO = 0,
  INDICATOR_CYCLE,
  INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,
  INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,
- INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
 } __attribute__ ((packed));
 #define HUB_TTTT_8_BITS 0x00
 #define HUB_TTTT_16_BITS 0x20
-#define HUB_TTTT_24_BITS 0x40
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HUB_TTTT_24_BITS 0x40
 #define HUB_TTTT_32_BITS 0x60
 #endif
diff --git a/libc/kernel/uapi/linux/v4l2-controls.h b/libc/kernel/uapi/linux/v4l2-controls.h
index 47dce45..2236ff7 100644
--- a/libc/kernel/uapi/linux/v4l2-controls.h
+++ b/libc/kernel/uapi/linux/v4l2-controls.h
@@ -122,773 +122,809 @@
 #define V4L2_CID_USER_S2255_BASE (V4L2_CID_USER_BASE + 0x1030)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_USER_SI476X_BASE (V4L2_CID_USER_BASE + 0x1040)
+#define V4L2_CID_USER_TI_VPE_BASE (V4L2_CID_USER_BASE + 0x1050)
+#define V4L2_CID_USER_SAA7134_BASE (V4L2_CID_USER_BASE + 0x1060)
 #define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_CLASS (V4L2_CTRL_CLASS_MPEG | 1)
 #define V4L2_CID_MPEG_STREAM_TYPE (V4L2_CID_MPEG_BASE+0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_stream_type {
  V4L2_MPEG_STREAM_TYPE_MPEG2_PS = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_STREAM_TYPE_MPEG2_TS = 1,
  V4L2_MPEG_STREAM_TYPE_MPEG1_SS = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_STREAM_TYPE_MPEG2_DVD = 3,
  V4L2_MPEG_STREAM_TYPE_MPEG1_VCD = 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD = 5,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_STREAM_PID_PMT (V4L2_CID_MPEG_BASE+1)
 #define V4L2_CID_MPEG_STREAM_PID_AUDIO (V4L2_CID_MPEG_BASE+2)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_STREAM_PID_VIDEO (V4L2_CID_MPEG_BASE+3)
 #define V4L2_CID_MPEG_STREAM_PID_PCR (V4L2_CID_MPEG_BASE+4)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_STREAM_PES_ID_AUDIO (V4L2_CID_MPEG_BASE+5)
 #define V4L2_CID_MPEG_STREAM_PES_ID_VIDEO (V4L2_CID_MPEG_BASE+6)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_STREAM_VBI_FMT (V4L2_CID_MPEG_BASE+7)
 enum v4l2_mpeg_stream_vbi_fmt {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_STREAM_VBI_FMT_NONE = 0,
  V4L2_MPEG_STREAM_VBI_FMT_IVTV = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ (V4L2_CID_MPEG_BASE+100)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_audio_sampling_freq {
  V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100 = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000 = 1,
  V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000 = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_AUDIO_ENCODING (V4L2_CID_MPEG_BASE+101)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_audio_encoding {
  V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1,
  V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_ENCODING_AAC = 3,
  V4L2_MPEG_AUDIO_ENCODING_AC3 = 4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_AUDIO_L1_BITRATE (V4L2_CID_MPEG_BASE+102)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_audio_l1_bitrate {
  V4L2_MPEG_AUDIO_L1_BITRATE_32K = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L1_BITRATE_64K = 1,
  V4L2_MPEG_AUDIO_L1_BITRATE_96K = 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L1_BITRATE_128K = 3,
  V4L2_MPEG_AUDIO_L1_BITRATE_160K = 4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L1_BITRATE_192K = 5,
  V4L2_MPEG_AUDIO_L1_BITRATE_224K = 6,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L1_BITRATE_256K = 7,
  V4L2_MPEG_AUDIO_L1_BITRATE_288K = 8,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L1_BITRATE_320K = 9,
  V4L2_MPEG_AUDIO_L1_BITRATE_352K = 10,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L1_BITRATE_384K = 11,
  V4L2_MPEG_AUDIO_L1_BITRATE_416K = 12,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L1_BITRATE_448K = 13,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_AUDIO_L2_BITRATE (V4L2_CID_MPEG_BASE+103)
 enum v4l2_mpeg_audio_l2_bitrate {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L2_BITRATE_32K = 0,
  V4L2_MPEG_AUDIO_L2_BITRATE_48K = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L2_BITRATE_56K = 2,
  V4L2_MPEG_AUDIO_L2_BITRATE_64K = 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L2_BITRATE_80K = 4,
  V4L2_MPEG_AUDIO_L2_BITRATE_96K = 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L2_BITRATE_112K = 6,
  V4L2_MPEG_AUDIO_L2_BITRATE_128K = 7,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L2_BITRATE_160K = 8,
  V4L2_MPEG_AUDIO_L2_BITRATE_192K = 9,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L2_BITRATE_224K = 10,
  V4L2_MPEG_AUDIO_L2_BITRATE_256K = 11,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L2_BITRATE_320K = 12,
  V4L2_MPEG_AUDIO_L2_BITRATE_384K = 13,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_AUDIO_L3_BITRATE (V4L2_CID_MPEG_BASE+104)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_audio_l3_bitrate {
  V4L2_MPEG_AUDIO_L3_BITRATE_32K = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L3_BITRATE_40K = 1,
  V4L2_MPEG_AUDIO_L3_BITRATE_48K = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L3_BITRATE_56K = 3,
  V4L2_MPEG_AUDIO_L3_BITRATE_64K = 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L3_BITRATE_80K = 5,
  V4L2_MPEG_AUDIO_L3_BITRATE_96K = 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L3_BITRATE_112K = 7,
  V4L2_MPEG_AUDIO_L3_BITRATE_128K = 8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L3_BITRATE_160K = 9,
  V4L2_MPEG_AUDIO_L3_BITRATE_192K = 10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L3_BITRATE_224K = 11,
  V4L2_MPEG_AUDIO_L3_BITRATE_256K = 12,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_L3_BITRATE_320K = 13,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_AUDIO_MODE (V4L2_CID_MPEG_BASE+105)
 enum v4l2_mpeg_audio_mode {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_MODE_STEREO = 0,
  V4L2_MPEG_AUDIO_MODE_JOINT_STEREO = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_MODE_DUAL = 2,
  V4L2_MPEG_AUDIO_MODE_MONO = 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_AUDIO_MODE_EXTENSION (V4L2_CID_MPEG_BASE+106)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_audio_mode_extension {
  V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4 = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8 = 1,
  V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12 = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16 = 3,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_AUDIO_EMPHASIS (V4L2_CID_MPEG_BASE+107)
 enum v4l2_mpeg_audio_emphasis {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_EMPHASIS_NONE = 0,
  V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17 = 2,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_AUDIO_CRC (V4L2_CID_MPEG_BASE+108)
 enum v4l2_mpeg_audio_crc {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_CRC_NONE = 0,
  V4L2_MPEG_AUDIO_CRC_CRC16 = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_AUDIO_MUTE (V4L2_CID_MPEG_BASE+109)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_AUDIO_AAC_BITRATE (V4L2_CID_MPEG_BASE+110)
 #define V4L2_CID_MPEG_AUDIO_AC3_BITRATE (V4L2_CID_MPEG_BASE+111)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_audio_ac3_bitrate {
  V4L2_MPEG_AUDIO_AC3_BITRATE_32K = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_40K = 1,
  V4L2_MPEG_AUDIO_AC3_BITRATE_48K = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_56K = 3,
  V4L2_MPEG_AUDIO_AC3_BITRATE_64K = 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_80K = 5,
  V4L2_MPEG_AUDIO_AC3_BITRATE_96K = 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_112K = 7,
  V4L2_MPEG_AUDIO_AC3_BITRATE_128K = 8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_160K = 9,
  V4L2_MPEG_AUDIO_AC3_BITRATE_192K = 10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_224K = 11,
  V4L2_MPEG_AUDIO_AC3_BITRATE_256K = 12,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_320K = 13,
  V4L2_MPEG_AUDIO_AC3_BITRATE_384K = 14,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_448K = 15,
  V4L2_MPEG_AUDIO_AC3_BITRATE_512K = 16,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_AC3_BITRATE_576K = 17,
  V4L2_MPEG_AUDIO_AC3_BITRATE_640K = 18,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK (V4L2_CID_MPEG_BASE+112)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_audio_dec_playback {
  V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_DEC_PLAYBACK_STEREO = 1,
  V4L2_MPEG_AUDIO_DEC_PLAYBACK_LEFT = 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_DEC_PLAYBACK_RIGHT = 3,
  V4L2_MPEG_AUDIO_DEC_PLAYBACK_MONO = 4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_AUDIO_DEC_PLAYBACK_SWAPPED_STEREO = 5,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK (V4L2_CID_MPEG_BASE+113)
 #define V4L2_CID_MPEG_VIDEO_ENCODING (V4L2_CID_MPEG_BASE+200)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_video_encoding {
  V4L2_MPEG_VIDEO_ENCODING_MPEG_1 = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_ENCODING_MPEG_2 = 1,
  V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_ASPECT (V4L2_CID_MPEG_BASE+201)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_video_aspect {
  V4L2_MPEG_VIDEO_ASPECT_1x1 = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_ASPECT_4x3 = 1,
  V4L2_MPEG_VIDEO_ASPECT_16x9 = 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_ASPECT_221x100 = 3,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_B_FRAMES (V4L2_CID_MPEG_BASE+202)
 #define V4L2_CID_MPEG_VIDEO_GOP_SIZE (V4L2_CID_MPEG_BASE+203)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE (V4L2_CID_MPEG_BASE+204)
 #define V4L2_CID_MPEG_VIDEO_PULLDOWN (V4L2_CID_MPEG_BASE+205)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_BITRATE_MODE (V4L2_CID_MPEG_BASE+206)
 enum v4l2_mpeg_video_bitrate_mode {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_BITRATE_MODE_VBR = 0,
  V4L2_MPEG_VIDEO_BITRATE_MODE_CBR = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_MPEG_BASE+207)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_MPEG_BASE+208)
 #define V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (V4L2_CID_MPEG_BASE+209)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_MUTE (V4L2_CID_MPEG_BASE+210)
 #define V4L2_CID_MPEG_VIDEO_MUTE_YUV (V4L2_CID_MPEG_BASE+211)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE (V4L2_CID_MPEG_BASE+212)
 #define V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER (V4L2_CID_MPEG_BASE+213)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB (V4L2_CID_MPEG_BASE+214)
 #define V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE (V4L2_CID_MPEG_BASE+215)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_HEADER_MODE (V4L2_CID_MPEG_BASE+216)
 enum v4l2_mpeg_video_header_mode {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE = 0,
  V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_MAX_REF_PIC (V4L2_CID_MPEG_BASE+217)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE (V4L2_CID_MPEG_BASE+218)
 #define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES (V4L2_CID_MPEG_BASE+219)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB (V4L2_CID_MPEG_BASE+220)
 #define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE (V4L2_CID_MPEG_BASE+221)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_video_multi_slice_mode {
  V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB = 1,
  V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_VBV_SIZE (V4L2_CID_MPEG_BASE+222)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_DEC_PTS (V4L2_CID_MPEG_BASE+223)
 #define V4L2_CID_MPEG_VIDEO_DEC_FRAME (V4L2_CID_MPEG_BASE+224)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_VBV_DELAY (V4L2_CID_MPEG_BASE+225)
 #define V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER (V4L2_CID_MPEG_BASE+226)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP (V4L2_CID_MPEG_BASE+300)
 #define V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP (V4L2_CID_MPEG_BASE+301)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP (V4L2_CID_MPEG_BASE+302)
 #define V4L2_CID_MPEG_VIDEO_H263_MIN_QP (V4L2_CID_MPEG_BASE+303)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H263_MAX_QP (V4L2_CID_MPEG_BASE+304)
 #define V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP (V4L2_CID_MPEG_BASE+350)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP (V4L2_CID_MPEG_BASE+351)
 #define V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP (V4L2_CID_MPEG_BASE+352)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_MIN_QP (V4L2_CID_MPEG_BASE+353)
 #define V4L2_CID_MPEG_VIDEO_H264_MAX_QP (V4L2_CID_MPEG_BASE+354)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM (V4L2_CID_MPEG_BASE+355)
 #define V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE (V4L2_CID_MPEG_BASE+356)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE (V4L2_CID_MPEG_BASE+357)
 enum v4l2_mpeg_video_h264_entropy_mode {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC = 0,
  V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_H264_I_PERIOD (V4L2_CID_MPEG_BASE+358)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_LEVEL (V4L2_CID_MPEG_BASE+359)
 enum v4l2_mpeg_video_h264_level {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LEVEL_1_0 = 0,
  V4L2_MPEG_VIDEO_H264_LEVEL_1B = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LEVEL_1_1 = 2,
  V4L2_MPEG_VIDEO_H264_LEVEL_1_2 = 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LEVEL_1_3 = 4,
  V4L2_MPEG_VIDEO_H264_LEVEL_2_0 = 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LEVEL_2_1 = 6,
  V4L2_MPEG_VIDEO_H264_LEVEL_2_2 = 7,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LEVEL_3_0 = 8,
  V4L2_MPEG_VIDEO_H264_LEVEL_3_1 = 9,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LEVEL_3_2 = 10,
  V4L2_MPEG_VIDEO_H264_LEVEL_4_0 = 11,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LEVEL_4_1 = 12,
  V4L2_MPEG_VIDEO_H264_LEVEL_4_2 = 13,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LEVEL_5_0 = 14,
  V4L2_MPEG_VIDEO_H264_LEVEL_5_1 = 15,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA (V4L2_CID_MPEG_BASE+360)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA (V4L2_CID_MPEG_BASE+361)
 #define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE (V4L2_CID_MPEG_BASE+362)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_video_h264_loop_filter_mode {
  V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED = 1,
  V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY = 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_H264_PROFILE (V4L2_CID_MPEG_BASE+363)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_video_h264_profile {
  V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE = 1,
  V4L2_MPEG_VIDEO_H264_PROFILE_MAIN = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED = 3,
  V4L2_MPEG_VIDEO_H264_PROFILE_HIGH = 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10 = 5,
  V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422 = 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE = 7,
  V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10_INTRA = 8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422_INTRA = 9,
  V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_INTRA = 10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_PROFILE_CAVLC_444_INTRA = 11,
  V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_BASELINE = 12,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH = 13,
  V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH_INTRA = 14,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH = 15,
  V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH = 16,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT (V4L2_CID_MPEG_BASE+364)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH (V4L2_CID_MPEG_BASE+365)
 #define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE (V4L2_CID_MPEG_BASE+366)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC (V4L2_CID_MPEG_BASE+367)
 enum v4l2_mpeg_video_h264_vui_sar_idc {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED = 0,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_1x1 = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_12x11 = 2,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_10x11 = 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_16x11 = 4,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_40x33 = 5,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_24x11 = 6,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_20x11 = 7,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_32x11 = 8,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_80x33 = 9,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_18x11 = 10,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_15x11 = 11,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_64x33 = 12,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_160x99 = 13,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_4x3 = 14,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_3x2 = 15,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_2x1 = 16,
  V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED = 17,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_H264_SEI_FRAME_PACKING (V4L2_CID_MPEG_BASE+368)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0 (V4L2_CID_MPEG_BASE+369)
 #define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE (V4L2_CID_MPEG_BASE+370)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_video_h264_sei_fp_arrangement_type {
  V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_CHECKERBOARD = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_COLUMN = 1,
  V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_ROW = 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_SIDE_BY_SIDE = 3,
  V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TOP_BOTTOM = 4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TEMPORAL = 5,
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_FMO (V4L2_CID_MPEG_BASE+371)
 #define V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE (V4L2_CID_MPEG_BASE+372)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_video_h264_fmo_map_type {
  V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES = 1,
  V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_FOREGROUND_WITH_LEFT_OVER = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_BOX_OUT = 3,
  V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN = 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN = 5,
  V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_EXPLICIT = 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_H264_FMO_SLICE_GROUP (V4L2_CID_MPEG_BASE+373)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION (V4L2_CID_MPEG_BASE+374)
 enum v4l2_mpeg_video_h264_fmo_change_dir {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_RIGHT = 0,
  V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_LEFT = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_RATE (V4L2_CID_MPEG_BASE+375)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_FMO_RUN_LENGTH (V4L2_CID_MPEG_BASE+376)
 #define V4L2_CID_MPEG_VIDEO_H264_ASO (V4L2_CID_MPEG_BASE+377)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_ASO_SLICE_ORDER (V4L2_CID_MPEG_BASE+378)
 #define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING (V4L2_CID_MPEG_BASE+379)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE (V4L2_CID_MPEG_BASE+380)
 enum v4l2_mpeg_video_h264_hierarchical_coding_type {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B = 0,
  V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER (V4L2_CID_MPEG_BASE+381)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP (V4L2_CID_MPEG_BASE+382)
 #define V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP (V4L2_CID_MPEG_BASE+400)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP (V4L2_CID_MPEG_BASE+401)
 #define V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP (V4L2_CID_MPEG_BASE+402)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP (V4L2_CID_MPEG_BASE+403)
 #define V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP (V4L2_CID_MPEG_BASE+404)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL (V4L2_CID_MPEG_BASE+405)
 enum v4l2_mpeg_video_mpeg4_level {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_MPEG4_LEVEL_0 = 0,
  V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_MPEG4_LEVEL_1 = 2,
  V4L2_MPEG_VIDEO_MPEG4_LEVEL_2 = 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_MPEG4_LEVEL_3 = 4,
  V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B = 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_MPEG4_LEVEL_4 = 6,
  V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 = 7,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE (V4L2_CID_MPEG_BASE+406)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_mpeg_video_mpeg4_profile {
  V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE = 1,
  V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE = 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE = 3,
  V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY = 4,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_MPEG_BASE+407)
+#define V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS (V4L2_CID_MPEG_BASE+500)
+enum v4l2_vp8_num_partitions {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION = 0,
+ V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS = 1,
+ V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS = 2,
+ V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS = 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4 (V4L2_CID_MPEG_BASE+501)
+#define V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES (V4L2_CID_MPEG_BASE+502)
+enum v4l2_vp8_num_ref_frames {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME = 0,
+ V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME = 1,
+ V4L2_CID_MPEG_VIDEO_VPX_3_REF_FRAME = 2,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL (V4L2_CID_MPEG_BASE+503)
+#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS (V4L2_CID_MPEG_BASE+504)
+#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD (V4L2_CID_MPEG_BASE+505)
+#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL (V4L2_CID_MPEG_BASE+506)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_vp8_golden_frame_sel {
+ V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV = 0,
+ V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD = 1,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_VIDEO_VPX_MIN_QP (V4L2_CID_MPEG_BASE+507)
+#define V4L2_CID_MPEG_VIDEO_VPX_MAX_QP (V4L2_CID_MPEG_BASE+508)
+#define V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP (V4L2_CID_MPEG_BASE+509)
+#define V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP (V4L2_CID_MPEG_BASE+510)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_VIDEO_VPX_PROFILE (V4L2_CID_MPEG_BASE+511)
 #define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000)
 #define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+0)
 enum v4l2_mpeg_cx2341x_video_spatial_filter_mode {
- V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0,
  V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO = 1,
 };
 #define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+1)
-#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+2)
 enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type {
  V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF = 0,
  V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR = 1,
- V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT = 2,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT = 2,
  V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE = 3,
  V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE = 4,
 };
-#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+3)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+3)
 enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type {
  V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF = 0,
  V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR = 1,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+4)
 enum v4l2_mpeg_cx2341x_video_temporal_filter_mode {
  V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL = 0,
- V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO = 1,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO = 1,
 };
 #define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+5)
 #define V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+6)
-enum v4l2_mpeg_cx2341x_video_median_filter_type {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_mpeg_cx2341x_video_median_filter_type {
  V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF = 0,
  V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR = 1,
  V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT = 2,
- V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3,
  V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG = 4,
 };
 #define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+7)
-#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+8)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+8)
 #define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+9)
 #define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10)
 #define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_MPEG_CX2341X_BASE+11)
-#define V4L2_CID_MPEG_MFC51_BASE (V4L2_CTRL_CLASS_MPEG | 0x1100)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_MFC51_BASE (V4L2_CTRL_CLASS_MPEG | 0x1100)
 #define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY (V4L2_CID_MPEG_MFC51_BASE+0)
 #define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE (V4L2_CID_MPEG_MFC51_BASE+1)
 #define V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE (V4L2_CID_MPEG_MFC51_BASE+2)
-enum v4l2_mpeg_mfc51_video_frame_skip_mode {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_mpeg_mfc51_video_frame_skip_mode {
  V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED = 0,
  V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_LEVEL_LIMIT = 1,
  V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT = 2,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE (V4L2_CID_MPEG_MFC51_BASE+3)
 enum v4l2_mpeg_mfc51_video_force_frame_type {
  V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED = 0,
- V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME = 1,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME = 1,
  V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED = 2,
 };
 #define V4L2_CID_MPEG_MFC51_VIDEO_PADDING (V4L2_CID_MPEG_MFC51_BASE+4)
-#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV (V4L2_CID_MPEG_MFC51_BASE+5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV (V4L2_CID_MPEG_MFC51_BASE+5)
 #define V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT (V4L2_CID_MPEG_MFC51_BASE+6)
 #define V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF (V4L2_CID_MPEG_MFC51_BASE+7)
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY (V4L2_CID_MPEG_MFC51_BASE+50)
-#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK (V4L2_CID_MPEG_MFC51_BASE+51)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK (V4L2_CID_MPEG_MFC51_BASE+51)
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH (V4L2_CID_MPEG_MFC51_BASE+52)
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC (V4L2_CID_MPEG_MFC51_BASE+53)
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P (V4L2_CID_MPEG_MFC51_BASE+54)
-#define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
 #define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1)
 #define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1)
 enum v4l2_exposure_auto_type {
- V4L2_EXPOSURE_AUTO = 0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_EXPOSURE_AUTO = 0,
  V4L2_EXPOSURE_MANUAL = 1,
  V4L2_EXPOSURE_SHUTTER_PRIORITY = 2,
  V4L2_EXPOSURE_APERTURE_PRIORITY = 3
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2)
 #define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3)
 #define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4)
-#define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5)
 #define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6)
 #define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7)
 #define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8)
-#define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9)
 #define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10)
 #define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11)
 #define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12)
-#define V4L2_CID_ZOOM_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+13)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_ZOOM_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+13)
 #define V4L2_CID_ZOOM_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+14)
 #define V4L2_CID_ZOOM_CONTINUOUS (V4L2_CID_CAMERA_CLASS_BASE+15)
 #define V4L2_CID_PRIVACY (V4L2_CID_CAMERA_CLASS_BASE+16)
-#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)
 #define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18)
 #define V4L2_CID_AUTO_EXPOSURE_BIAS (V4L2_CID_CAMERA_CLASS_BASE+19)
 #define V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE (V4L2_CID_CAMERA_CLASS_BASE+20)
-enum v4l2_auto_n_preset_white_balance {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_auto_n_preset_white_balance {
  V4L2_WHITE_BALANCE_MANUAL = 0,
  V4L2_WHITE_BALANCE_AUTO = 1,
  V4L2_WHITE_BALANCE_INCANDESCENT = 2,
- V4L2_WHITE_BALANCE_FLUORESCENT = 3,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_WHITE_BALANCE_FLUORESCENT = 3,
  V4L2_WHITE_BALANCE_FLUORESCENT_H = 4,
  V4L2_WHITE_BALANCE_HORIZON = 5,
  V4L2_WHITE_BALANCE_DAYLIGHT = 6,
- V4L2_WHITE_BALANCE_FLASH = 7,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_WHITE_BALANCE_FLASH = 7,
  V4L2_WHITE_BALANCE_CLOUDY = 8,
  V4L2_WHITE_BALANCE_SHADE = 9,
 };
-#define V4L2_CID_WIDE_DYNAMIC_RANGE (V4L2_CID_CAMERA_CLASS_BASE+21)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_WIDE_DYNAMIC_RANGE (V4L2_CID_CAMERA_CLASS_BASE+21)
 #define V4L2_CID_IMAGE_STABILIZATION (V4L2_CID_CAMERA_CLASS_BASE+22)
 #define V4L2_CID_ISO_SENSITIVITY (V4L2_CID_CAMERA_CLASS_BASE+23)
 #define V4L2_CID_ISO_SENSITIVITY_AUTO (V4L2_CID_CAMERA_CLASS_BASE+24)
-enum v4l2_iso_sensitivity_auto_type {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_iso_sensitivity_auto_type {
  V4L2_ISO_SENSITIVITY_MANUAL = 0,
  V4L2_ISO_SENSITIVITY_AUTO = 1,
 };
-#define V4L2_CID_EXPOSURE_METERING (V4L2_CID_CAMERA_CLASS_BASE+25)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_EXPOSURE_METERING (V4L2_CID_CAMERA_CLASS_BASE+25)
 enum v4l2_exposure_metering {
  V4L2_EXPOSURE_METERING_AVERAGE = 0,
  V4L2_EXPOSURE_METERING_CENTER_WEIGHTED = 1,
- V4L2_EXPOSURE_METERING_SPOT = 2,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_EXPOSURE_METERING_SPOT = 2,
  V4L2_EXPOSURE_METERING_MATRIX = 3,
 };
 #define V4L2_CID_SCENE_MODE (V4L2_CID_CAMERA_CLASS_BASE+26)
-enum v4l2_scene_mode {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_scene_mode {
  V4L2_SCENE_MODE_NONE = 0,
  V4L2_SCENE_MODE_BACKLIGHT = 1,
  V4L2_SCENE_MODE_BEACH_SNOW = 2,
- V4L2_SCENE_MODE_CANDLE_LIGHT = 3,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_SCENE_MODE_CANDLE_LIGHT = 3,
  V4L2_SCENE_MODE_DAWN_DUSK = 4,
  V4L2_SCENE_MODE_FALL_COLORS = 5,
  V4L2_SCENE_MODE_FIREWORKS = 6,
- V4L2_SCENE_MODE_LANDSCAPE = 7,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_SCENE_MODE_LANDSCAPE = 7,
  V4L2_SCENE_MODE_NIGHT = 8,
  V4L2_SCENE_MODE_PARTY_INDOOR = 9,
  V4L2_SCENE_MODE_PORTRAIT = 10,
- V4L2_SCENE_MODE_SPORTS = 11,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_SCENE_MODE_SPORTS = 11,
  V4L2_SCENE_MODE_SUNSET = 12,
  V4L2_SCENE_MODE_TEXT = 13,
 };
-#define V4L2_CID_3A_LOCK (V4L2_CID_CAMERA_CLASS_BASE+27)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_3A_LOCK (V4L2_CID_CAMERA_CLASS_BASE+27)
 #define V4L2_LOCK_EXPOSURE (1 << 0)
 #define V4L2_LOCK_WHITE_BALANCE (1 << 1)
 #define V4L2_LOCK_FOCUS (1 << 2)
-#define V4L2_CID_AUTO_FOCUS_START (V4L2_CID_CAMERA_CLASS_BASE+28)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_AUTO_FOCUS_START (V4L2_CID_CAMERA_CLASS_BASE+28)
 #define V4L2_CID_AUTO_FOCUS_STOP (V4L2_CID_CAMERA_CLASS_BASE+29)
 #define V4L2_CID_AUTO_FOCUS_STATUS (V4L2_CID_CAMERA_CLASS_BASE+30)
 #define V4L2_AUTO_FOCUS_STATUS_IDLE (0 << 0)
-#define V4L2_AUTO_FOCUS_STATUS_BUSY (1 << 0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_AUTO_FOCUS_STATUS_BUSY (1 << 0)
 #define V4L2_AUTO_FOCUS_STATUS_REACHED (1 << 1)
 #define V4L2_AUTO_FOCUS_STATUS_FAILED (1 << 2)
 #define V4L2_CID_AUTO_FOCUS_RANGE (V4L2_CID_CAMERA_CLASS_BASE+31)
-enum v4l2_auto_focus_range {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_auto_focus_range {
  V4L2_AUTO_FOCUS_RANGE_AUTO = 0,
  V4L2_AUTO_FOCUS_RANGE_NORMAL = 1,
  V4L2_AUTO_FOCUS_RANGE_MACRO = 2,
- V4L2_AUTO_FOCUS_RANGE_INFINITY = 3,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_AUTO_FOCUS_RANGE_INFINITY = 3,
 };
 #define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900)
 #define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1)
-#define V4L2_CID_RDS_TX_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_RDS_TX_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 1)
 #define V4L2_CID_RDS_TX_PI (V4L2_CID_FM_TX_CLASS_BASE + 2)
 #define V4L2_CID_RDS_TX_PTY (V4L2_CID_FM_TX_CLASS_BASE + 3)
 #define V4L2_CID_RDS_TX_PS_NAME (V4L2_CID_FM_TX_CLASS_BASE + 5)
-#define V4L2_CID_RDS_TX_RADIO_TEXT (V4L2_CID_FM_TX_CLASS_BASE + 6)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_RDS_TX_RADIO_TEXT (V4L2_CID_FM_TX_CLASS_BASE + 6)
 #define V4L2_CID_AUDIO_LIMITER_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 64)
 #define V4L2_CID_AUDIO_LIMITER_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 65)
 #define V4L2_CID_AUDIO_LIMITER_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 66)
-#define V4L2_CID_AUDIO_COMPRESSION_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 80)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_AUDIO_COMPRESSION_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 80)
 #define V4L2_CID_AUDIO_COMPRESSION_GAIN (V4L2_CID_FM_TX_CLASS_BASE + 81)
 #define V4L2_CID_AUDIO_COMPRESSION_THRESHOLD (V4L2_CID_FM_TX_CLASS_BASE + 82)
 #define V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME (V4L2_CID_FM_TX_CLASS_BASE + 83)
-#define V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 84)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 84)
 #define V4L2_CID_PILOT_TONE_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 96)
 #define V4L2_CID_PILOT_TONE_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 97)
 #define V4L2_CID_PILOT_TONE_FREQUENCY (V4L2_CID_FM_TX_CLASS_BASE + 98)
-#define V4L2_CID_TUNE_PREEMPHASIS (V4L2_CID_FM_TX_CLASS_BASE + 112)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_TUNE_PREEMPHASIS (V4L2_CID_FM_TX_CLASS_BASE + 112)
 enum v4l2_preemphasis {
  V4L2_PREEMPHASIS_DISABLED = 0,
  V4L2_PREEMPHASIS_50_uS = 1,
- V4L2_PREEMPHASIS_75_uS = 2,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_PREEMPHASIS_75_uS = 2,
 };
 #define V4L2_CID_TUNE_POWER_LEVEL (V4L2_CID_FM_TX_CLASS_BASE + 113)
 #define V4L2_CID_TUNE_ANTENNA_CAPACITOR (V4L2_CID_FM_TX_CLASS_BASE + 114)
-#define V4L2_CID_FLASH_CLASS_BASE (V4L2_CTRL_CLASS_FLASH | 0x900)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_FLASH_CLASS_BASE (V4L2_CTRL_CLASS_FLASH | 0x900)
 #define V4L2_CID_FLASH_CLASS (V4L2_CTRL_CLASS_FLASH | 1)
 #define V4L2_CID_FLASH_LED_MODE (V4L2_CID_FLASH_CLASS_BASE + 1)
 enum v4l2_flash_led_mode {
- V4L2_FLASH_LED_MODE_NONE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_FLASH_LED_MODE_NONE,
  V4L2_FLASH_LED_MODE_FLASH,
  V4L2_FLASH_LED_MODE_TORCH,
 };
-#define V4L2_CID_FLASH_STROBE_SOURCE (V4L2_CID_FLASH_CLASS_BASE + 2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_FLASH_STROBE_SOURCE (V4L2_CID_FLASH_CLASS_BASE + 2)
 enum v4l2_flash_strobe_source {
  V4L2_FLASH_STROBE_SOURCE_SOFTWARE,
  V4L2_FLASH_STROBE_SOURCE_EXTERNAL,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define V4L2_CID_FLASH_STROBE (V4L2_CID_FLASH_CLASS_BASE + 3)
 #define V4L2_CID_FLASH_STROBE_STOP (V4L2_CID_FLASH_CLASS_BASE + 4)
 #define V4L2_CID_FLASH_STROBE_STATUS (V4L2_CID_FLASH_CLASS_BASE + 5)
-#define V4L2_CID_FLASH_TIMEOUT (V4L2_CID_FLASH_CLASS_BASE + 6)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_FLASH_TIMEOUT (V4L2_CID_FLASH_CLASS_BASE + 6)
 #define V4L2_CID_FLASH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 7)
 #define V4L2_CID_FLASH_TORCH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 8)
 #define V4L2_CID_FLASH_INDICATOR_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 9)
-#define V4L2_CID_FLASH_FAULT (V4L2_CID_FLASH_CLASS_BASE + 10)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_FLASH_FAULT (V4L2_CID_FLASH_CLASS_BASE + 10)
 #define V4L2_FLASH_FAULT_OVER_VOLTAGE (1 << 0)
 #define V4L2_FLASH_FAULT_TIMEOUT (1 << 1)
 #define V4L2_FLASH_FAULT_OVER_TEMPERATURE (1 << 2)
-#define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
 #define V4L2_FLASH_FAULT_OVER_CURRENT (1 << 4)
 #define V4L2_FLASH_FAULT_INDICATOR (1 << 5)
 #define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11)
-#define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12)
 #define V4L2_CID_JPEG_CLASS_BASE (V4L2_CTRL_CLASS_JPEG | 0x900)
 #define V4L2_CID_JPEG_CLASS (V4L2_CTRL_CLASS_JPEG | 1)
 #define V4L2_CID_JPEG_CHROMA_SUBSAMPLING (V4L2_CID_JPEG_CLASS_BASE + 1)
-enum v4l2_jpeg_chroma_subsampling {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_jpeg_chroma_subsampling {
  V4L2_JPEG_CHROMA_SUBSAMPLING_444 = 0,
  V4L2_JPEG_CHROMA_SUBSAMPLING_422 = 1,
  V4L2_JPEG_CHROMA_SUBSAMPLING_420 = 2,
- V4L2_JPEG_CHROMA_SUBSAMPLING_411 = 3,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_JPEG_CHROMA_SUBSAMPLING_411 = 3,
  V4L2_JPEG_CHROMA_SUBSAMPLING_410 = 4,
  V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY = 5,
 };
-#define V4L2_CID_JPEG_RESTART_INTERVAL (V4L2_CID_JPEG_CLASS_BASE + 2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_JPEG_RESTART_INTERVAL (V4L2_CID_JPEG_CLASS_BASE + 2)
 #define V4L2_CID_JPEG_COMPRESSION_QUALITY (V4L2_CID_JPEG_CLASS_BASE + 3)
 #define V4L2_CID_JPEG_ACTIVE_MARKER (V4L2_CID_JPEG_CLASS_BASE + 4)
 #define V4L2_JPEG_ACTIVE_MARKER_APP0 (1 << 0)
-#define V4L2_JPEG_ACTIVE_MARKER_APP1 (1 << 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_JPEG_ACTIVE_MARKER_APP1 (1 << 1)
 #define V4L2_JPEG_ACTIVE_MARKER_COM (1 << 16)
 #define V4L2_JPEG_ACTIVE_MARKER_DQT (1 << 17)
 #define V4L2_JPEG_ACTIVE_MARKER_DHT (1 << 18)
-#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
 #define V4L2_CID_IMAGE_SOURCE_CLASS (V4L2_CTRL_CLASS_IMAGE_SOURCE | 1)
 #define V4L2_CID_VBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 1)
 #define V4L2_CID_HBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 2)
-#define V4L2_CID_ANALOGUE_GAIN (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 3)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_ANALOGUE_GAIN (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 3)
 #define V4L2_CID_IMAGE_PROC_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_PROC | 0x900)
 #define V4L2_CID_IMAGE_PROC_CLASS (V4L2_CTRL_CLASS_IMAGE_PROC | 1)
 #define V4L2_CID_LINK_FREQ (V4L2_CID_IMAGE_PROC_CLASS_BASE + 1)
-#define V4L2_CID_PIXEL_RATE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_PIXEL_RATE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 2)
 #define V4L2_CID_TEST_PATTERN (V4L2_CID_IMAGE_PROC_CLASS_BASE + 3)
 #define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900)
 #define V4L2_CID_DV_CLASS (V4L2_CTRL_CLASS_DV | 1)
-#define V4L2_CID_DV_TX_HOTPLUG (V4L2_CID_DV_CLASS_BASE + 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_DV_TX_HOTPLUG (V4L2_CID_DV_CLASS_BASE + 1)
 #define V4L2_CID_DV_TX_RXSENSE (V4L2_CID_DV_CLASS_BASE + 2)
 #define V4L2_CID_DV_TX_EDID_PRESENT (V4L2_CID_DV_CLASS_BASE + 3)
 #define V4L2_CID_DV_TX_MODE (V4L2_CID_DV_CLASS_BASE + 4)
-enum v4l2_dv_tx_mode {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum v4l2_dv_tx_mode {
  V4L2_DV_TX_MODE_DVI_D = 0,
  V4L2_DV_TX_MODE_HDMI = 1,
 };
-#define V4L2_CID_DV_TX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_DV_TX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 5)
 enum v4l2_dv_rgb_range {
  V4L2_DV_RGB_RANGE_AUTO = 0,
  V4L2_DV_RGB_RANGE_LIMITED = 1,
- V4L2_DV_RGB_RANGE_FULL = 2,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_DV_RGB_RANGE_FULL = 2,
 };
 #define V4L2_CID_DV_RX_POWER_PRESENT (V4L2_CID_DV_CLASS_BASE + 100)
 #define V4L2_CID_DV_RX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 101)
-#define V4L2_CID_FM_RX_CLASS_BASE (V4L2_CTRL_CLASS_FM_RX | 0x900)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_FM_RX_CLASS_BASE (V4L2_CTRL_CLASS_FM_RX | 0x900)
 #define V4L2_CID_FM_RX_CLASS (V4L2_CTRL_CLASS_FM_RX | 1)
 #define V4L2_CID_TUNE_DEEMPHASIS (V4L2_CID_FM_RX_CLASS_BASE + 1)
 enum v4l2_deemphasis {
- V4L2_DEEMPHASIS_DISABLED = V4L2_PREEMPHASIS_DISABLED,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_DEEMPHASIS_DISABLED = V4L2_PREEMPHASIS_DISABLED,
  V4L2_DEEMPHASIS_50_uS = V4L2_PREEMPHASIS_50_uS,
  V4L2_DEEMPHASIS_75_uS = V4L2_PREEMPHASIS_75_uS,
 };
-#define V4L2_CID_RDS_RECEPTION (V4L2_CID_FM_RX_CLASS_BASE + 2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CID_RDS_RECEPTION (V4L2_CID_FM_RX_CLASS_BASE + 2)
 #endif
diff --git a/libc/kernel/uapi/linux/v4l2-dv-timings.h b/libc/kernel/uapi/linux/v4l2-dv-timings.h
index 2c9ec89..bb1374a 100644
--- a/libc/kernel/uapi/linux/v4l2-dv-timings.h
+++ b/libc/kernel/uapi/linux/v4l2-dv-timings.h
@@ -153,6 +153,4 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_BT_DMT_2560X1600P85 {   .type = V4L2_DV_BT_656_1120,   V4L2_INIT_BT_TIMINGS(2560, 1600, 0, V4L2_DV_VSYNC_POS_POL,   505250000, 208, 280, 488, 3, 6, 73, 0, 0, 0,   V4L2_DV_BT_STD_DMT | V4L2_DV_BT_STD_CVT, 0)  }
 #define V4L2_DV_BT_DMT_2560X1600P120_RB {   .type = V4L2_DV_BT_656_1120,   V4L2_INIT_BT_TIMINGS(2560, 1600, 0, V4L2_DV_HSYNC_POS_POL,   552750000, 48, 32, 80, 3, 6, 85, 0, 0, 0,   V4L2_DV_BT_STD_DMT | V4L2_DV_BT_STD_CVT,   V4L2_DV_FL_REDUCED_BLANKING)  }
-#define V4L2_DV_BT_DMT_1366X768P60 {   .type = V4L2_DV_BT_656_1120,   V4L2_INIT_BT_TIMINGS(1366, 768, 0,   V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL,   85500000, 70, 143, 213, 3, 3, 24, 0, 0, 0,   V4L2_DV_BT_STD_DMT, 0)  }
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/v4l2-mediabus.h b/libc/kernel/uapi/linux/v4l2-mediabus.h
index 9c5a4a3..84aa5d3 100644
--- a/libc/kernel/uapi/linux/v4l2-mediabus.h
+++ b/libc/kernel/uapi/linux/v4l2-mediabus.h
@@ -38,76 +38,79 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_RGB888_2X12_BE = 0x100b,
  V4L2_MBUS_FMT_RGB888_2X12_LE = 0x100c,
+ V4L2_MBUS_FMT_ARGB8888_1X32 = 0x100d,
  V4L2_MBUS_FMT_Y8_1X8 = 0x2001,
- V4L2_MBUS_FMT_UV8_1X8 = 0x2015,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MBUS_FMT_UV8_1X8 = 0x2015,
  V4L2_MBUS_FMT_UYVY8_1_5X8 = 0x2002,
  V4L2_MBUS_FMT_VYUY8_1_5X8 = 0x2003,
  V4L2_MBUS_FMT_YUYV8_1_5X8 = 0x2004,
- V4L2_MBUS_FMT_YVYU8_1_5X8 = 0x2005,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MBUS_FMT_YVYU8_1_5X8 = 0x2005,
  V4L2_MBUS_FMT_UYVY8_2X8 = 0x2006,
  V4L2_MBUS_FMT_VYUY8_2X8 = 0x2007,
  V4L2_MBUS_FMT_YUYV8_2X8 = 0x2008,
- V4L2_MBUS_FMT_YVYU8_2X8 = 0x2009,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MBUS_FMT_YVYU8_2X8 = 0x2009,
  V4L2_MBUS_FMT_Y10_1X10 = 0x200a,
  V4L2_MBUS_FMT_YUYV10_2X10 = 0x200b,
  V4L2_MBUS_FMT_YVYU10_2X10 = 0x200c,
- V4L2_MBUS_FMT_Y12_1X12 = 0x2013,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MBUS_FMT_Y12_1X12 = 0x2013,
  V4L2_MBUS_FMT_UYVY8_1X16 = 0x200f,
  V4L2_MBUS_FMT_VYUY8_1X16 = 0x2010,
  V4L2_MBUS_FMT_YUYV8_1X16 = 0x2011,
- V4L2_MBUS_FMT_YVYU8_1X16 = 0x2012,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MBUS_FMT_YVYU8_1X16 = 0x2012,
  V4L2_MBUS_FMT_YDYUYDYV8_1X16 = 0x2014,
  V4L2_MBUS_FMT_YUYV10_1X20 = 0x200d,
  V4L2_MBUS_FMT_YVYU10_1X20 = 0x200e,
- V4L2_MBUS_FMT_YUV10_1X30 = 0x2016,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MBUS_FMT_YUV10_1X30 = 0x2016,
+ V4L2_MBUS_FMT_AYUV8_1X32 = 0x2017,
  V4L2_MBUS_FMT_SBGGR8_1X8 = 0x3001,
  V4L2_MBUS_FMT_SGBRG8_1X8 = 0x3013,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SGRBG8_1X8 = 0x3002,
  V4L2_MBUS_FMT_SRGGB8_1X8 = 0x3014,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SBGGR10_ALAW8_1X8 = 0x3015,
  V4L2_MBUS_FMT_SGBRG10_ALAW8_1X8 = 0x3016,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8 = 0x3017,
  V4L2_MBUS_FMT_SRGGB10_ALAW8_1X8 = 0x3018,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8 = 0x300b,
  V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8 = 0x300c,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 = 0x3009,
  V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8 = 0x300d,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE = 0x3003,
  V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE = 0x3004,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE = 0x3005,
  V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_LE = 0x3006,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SBGGR10_1X10 = 0x3007,
  V4L2_MBUS_FMT_SGBRG10_1X10 = 0x300e,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SGRBG10_1X10 = 0x300a,
  V4L2_MBUS_FMT_SRGGB10_1X10 = 0x300f,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SBGGR12_1X12 = 0x3008,
  V4L2_MBUS_FMT_SGBRG12_1X12 = 0x3010,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_SGRBG12_1X12 = 0x3011,
  V4L2_MBUS_FMT_SRGGB12_1X12 = 0x3012,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_MBUS_FMT_JPEG_1X8 = 0x4001,
  V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8 = 0x5001,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ V4L2_MBUS_FMT_AHSV8888_1X32 = 0x6001,
 };
 struct v4l2_mbus_framefmt {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 width;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 height;
  __u32 code;
  __u32 field;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 colorspace;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[7];
 };
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/version.h b/libc/kernel/uapi/linux/version.h
index acf9f06..71e5373 100644
--- a/libc/kernel/uapi/linux/version.h
+++ b/libc/kernel/uapi/linux/version.h
@@ -16,5 +16,5 @@
  ***
  ****************************************************************************
  ****************************************************************************/
-#define LINUX_VERSION_CODE 199168
+#define LINUX_VERSION_CODE 200192
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
diff --git a/libc/kernel/uapi/linux/vfio.h b/libc/kernel/uapi/linux/vfio.h
index 5ca9274..88cb067 100644
--- a/libc/kernel/uapi/linux/vfio.h
+++ b/libc/kernel/uapi/linux/vfio.h
@@ -23,139 +23,177 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VFIO_API_VERSION 0
 #define VFIO_TYPE1_IOMMU 1
+#define VFIO_SPAPR_TCE_IOMMU 2
 #define VFIO_TYPE (';')
-#define VFIO_BASE 100
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VFIO_BASE 100
 #define VFIO_GET_API_VERSION _IO(VFIO_TYPE, VFIO_BASE + 0)
 #define VFIO_CHECK_EXTENSION _IO(VFIO_TYPE, VFIO_BASE + 1)
 #define VFIO_SET_IOMMU _IO(VFIO_TYPE, VFIO_BASE + 2)
-struct vfio_group_status {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct vfio_group_status {
  __u32 argsz;
  __u32 flags;
 #define VFIO_GROUP_FLAGS_VIABLE (1 << 0)
-#define VFIO_GROUP_FLAGS_CONTAINER_SET (1 << 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VFIO_GROUP_FLAGS_CONTAINER_SET (1 << 1)
 };
 #define VFIO_GROUP_GET_STATUS _IO(VFIO_TYPE, VFIO_BASE + 3)
 #define VFIO_GROUP_SET_CONTAINER _IO(VFIO_TYPE, VFIO_BASE + 4)
-#define VFIO_GROUP_UNSET_CONTAINER _IO(VFIO_TYPE, VFIO_BASE + 5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VFIO_GROUP_UNSET_CONTAINER _IO(VFIO_TYPE, VFIO_BASE + 5)
 #define VFIO_GROUP_GET_DEVICE_FD _IO(VFIO_TYPE, VFIO_BASE + 6)
 struct vfio_device_info {
  __u32 argsz;
- __u32 flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 flags;
 #define VFIO_DEVICE_FLAGS_RESET (1 << 0)
 #define VFIO_DEVICE_FLAGS_PCI (1 << 1)
  __u32 num_regions;
- __u32 num_irqs;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 num_irqs;
 };
 #define VFIO_DEVICE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 7)
 struct vfio_region_info {
- __u32 argsz;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 argsz;
  __u32 flags;
 #define VFIO_REGION_INFO_FLAG_READ (1 << 0)
 #define VFIO_REGION_INFO_FLAG_WRITE (1 << 1)
-#define VFIO_REGION_INFO_FLAG_MMAP (1 << 2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VFIO_REGION_INFO_FLAG_MMAP (1 << 2)
  __u32 index;
  __u32 resv;
  __u64 size;
- __u64 offset;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 offset;
 };
 #define VFIO_DEVICE_GET_REGION_INFO _IO(VFIO_TYPE, VFIO_BASE + 8)
 struct vfio_irq_info {
- __u32 argsz;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 argsz;
  __u32 flags;
 #define VFIO_IRQ_INFO_EVENTFD (1 << 0)
 #define VFIO_IRQ_INFO_MASKABLE (1 << 1)
-#define VFIO_IRQ_INFO_AUTOMASKED (1 << 2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VFIO_IRQ_INFO_AUTOMASKED (1 << 2)
 #define VFIO_IRQ_INFO_NORESIZE (1 << 3)
  __u32 index;
  __u32 count;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define VFIO_DEVICE_GET_IRQ_INFO _IO(VFIO_TYPE, VFIO_BASE + 9)
 struct vfio_irq_set {
  __u32 argsz;
- __u32 flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 flags;
 #define VFIO_IRQ_SET_DATA_NONE (1 << 0)
 #define VFIO_IRQ_SET_DATA_BOOL (1 << 1)
 #define VFIO_IRQ_SET_DATA_EVENTFD (1 << 2)
-#define VFIO_IRQ_SET_ACTION_MASK (1 << 3)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VFIO_IRQ_SET_ACTION_MASK (1 << 3)
 #define VFIO_IRQ_SET_ACTION_UNMASK (1 << 4)
 #define VFIO_IRQ_SET_ACTION_TRIGGER (1 << 5)
  __u32 index;
- __u32 start;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 start;
  __u32 count;
  __u8 data[];
 };
-#define VFIO_DEVICE_SET_IRQS _IO(VFIO_TYPE, VFIO_BASE + 10)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VFIO_DEVICE_SET_IRQS _IO(VFIO_TYPE, VFIO_BASE + 10)
 #define VFIO_IRQ_SET_DATA_TYPE_MASK (VFIO_IRQ_SET_DATA_NONE |   VFIO_IRQ_SET_DATA_BOOL |   VFIO_IRQ_SET_DATA_EVENTFD)
 #define VFIO_IRQ_SET_ACTION_TYPE_MASK (VFIO_IRQ_SET_ACTION_MASK |   VFIO_IRQ_SET_ACTION_UNMASK |   VFIO_IRQ_SET_ACTION_TRIGGER)
 #define VFIO_DEVICE_RESET _IO(VFIO_TYPE, VFIO_BASE + 11)
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  VFIO_PCI_BAR0_REGION_INDEX,
  VFIO_PCI_BAR1_REGION_INDEX,
  VFIO_PCI_BAR2_REGION_INDEX,
- VFIO_PCI_BAR3_REGION_INDEX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ VFIO_PCI_BAR3_REGION_INDEX,
  VFIO_PCI_BAR4_REGION_INDEX,
  VFIO_PCI_BAR5_REGION_INDEX,
  VFIO_PCI_ROM_REGION_INDEX,
- VFIO_PCI_CONFIG_REGION_INDEX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ VFIO_PCI_CONFIG_REGION_INDEX,
  VFIO_PCI_VGA_REGION_INDEX,
  VFIO_PCI_NUM_REGIONS
 };
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  VFIO_PCI_INTX_IRQ_INDEX,
  VFIO_PCI_MSI_IRQ_INDEX,
  VFIO_PCI_MSIX_IRQ_INDEX,
- VFIO_PCI_ERR_IRQ_INDEX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ VFIO_PCI_ERR_IRQ_INDEX,
  VFIO_PCI_NUM_IRQS
 };
-struct vfio_iommu_type1_info {
- __u32 argsz;
+struct vfio_pci_dependent_device {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 group_id;
+ __u16 segment;
+ __u8 bus;
+ __u8 devfn;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct vfio_pci_hot_reset_info {
+ __u32 argsz;
+ __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 count;
+ struct vfio_pci_dependent_device devices[];
+};
+#define VFIO_DEVICE_GET_PCI_HOT_RESET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct vfio_pci_hot_reset {
+ __u32 argsz;
+ __u32 flags;
+ __u32 count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s32 group_fds[];
+};
+#define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13)
+struct vfio_iommu_type1_info {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 argsz;
  __u32 flags;
 #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)
  __u64 iova_pgsizes;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
 struct vfio_iommu_type1_dma_map {
  __u32 argsz;
- __u32 flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 flags;
 #define VFIO_DMA_MAP_FLAG_READ (1 << 0)
 #define VFIO_DMA_MAP_FLAG_WRITE (1 << 1)
  __u64 vaddr;
- __u64 iova;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 iova;
  __u64 size;
 };
 #define VFIO_IOMMU_MAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 13)
-struct vfio_iommu_type1_dma_unmap {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct vfio_iommu_type1_dma_unmap {
  __u32 argsz;
  __u32 flags;
  __u64 iova;
- __u64 size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 size;
 };
 #define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14)
+#define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16)
+struct vfio_iommu_spapr_tce_info {
+ __u32 argsz;
+ __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 dma32_window_start;
+ __u32 dma32_window_size;
+};
+#define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/videodev2.h b/libc/kernel/uapi/linux/videodev2.h
index ee01f80..b1c6042 100644
--- a/libc/kernel/uapi/linux/videodev2.h
+++ b/libc/kernel/uapi/linux/videodev2.h
@@ -106,8 +106,8 @@
  __s32 left;
  __s32 top;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __s32 width;
- __s32 height;
+ __u32 width;
+ __u32 height;
 };
 struct v4l2_fract {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -226,1172 +226,1172 @@
 #define V4L2_PIX_FMT_NV12M v4l2_fourcc('N', 'M', '1', '2')
 #define V4L2_PIX_FMT_NV21M v4l2_fourcc('N', 'M', '2', '1')
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_PIX_FMT_NV16M v4l2_fourcc('N', 'M', '1', '6')
+#define V4L2_PIX_FMT_NV61M v4l2_fourcc('N', 'M', '6', '1')
 #define V4L2_PIX_FMT_NV12MT v4l2_fourcc('T', 'M', '1', '2')
 #define V4L2_PIX_FMT_NV12MT_16X16 v4l2_fourcc('V', 'M', '1', '2')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_YUV420M v4l2_fourcc('Y', 'M', '1', '2')
 #define V4L2_PIX_FMT_YVU420M v4l2_fourcc('Y', 'M', '2', '1')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B', 'A', '8', '1')
 #define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G', 'R', 'B', 'G')
 #define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R', 'G', 'G', 'B')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SBGGR10 v4l2_fourcc('B', 'G', '1', '0')
 #define V4L2_PIX_FMT_SGBRG10 v4l2_fourcc('G', 'B', '1', '0')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SGRBG10 v4l2_fourcc('B', 'A', '1', '0')
 #define V4L2_PIX_FMT_SRGGB10 v4l2_fourcc('R', 'G', '1', '0')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SBGGR12 v4l2_fourcc('B', 'G', '1', '2')
 #define V4L2_PIX_FMT_SGBRG12 v4l2_fourcc('G', 'B', '1', '2')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2')
 #define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SBGGR10ALAW8 v4l2_fourcc('a', 'B', 'A', '8')
 #define V4L2_PIX_FMT_SGBRG10ALAW8 v4l2_fourcc('a', 'G', 'A', '8')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SGRBG10ALAW8 v4l2_fourcc('a', 'g', 'A', '8')
 #define V4L2_PIX_FMT_SRGGB10ALAW8 v4l2_fourcc('a', 'R', 'A', '8')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8')
 #define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SGRBG10DPCM8 v4l2_fourcc('B', 'D', '1', '0')
 #define V4L2_PIX_FMT_SRGGB10DPCM8 v4l2_fourcc('b', 'R', 'A', '8')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2')
 #define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G')
 #define V4L2_PIX_FMT_DV v4l2_fourcc('d', 'v', 's', 'd')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_MPEG v4l2_fourcc('M', 'P', 'E', 'G')
 #define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_H264_NO_SC v4l2_fourcc('A', 'V', 'C', '1')
 #define V4L2_PIX_FMT_H264_MVC v4l2_fourcc('M', '2', '6', '4')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3')
 #define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2')
 #define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D')
 #define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L')
 #define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A')
 #define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S', '9', '1', '0')
 #define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P', 'W', 'C', '1')
 #define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P', 'W', 'C', '2')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E', '6', '2', '5')
 #define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S', '5', '0', '5')
 #define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1')
 #define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0')
 #define V4L2_PIX_FMT_JL2005BCD v4l2_fourcc('J', 'L', '2', '0')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X')
 #define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G')
 #define V4L2_PIX_FMT_OV511 v4l2_fourcc('O', '5', '1', '1')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_OV518 v4l2_fourcc('O', '5', '1', '8')
 #define V4L2_PIX_FMT_STV0680 v4l2_fourcc('S', '6', '8', '0')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_TM6000 v4l2_fourcc('T', 'M', '6', '0')
 #define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_KONICA420 v4l2_fourcc('K', 'O', 'N', 'I')
 #define V4L2_PIX_FMT_JPGL v4l2_fourcc('J', 'P', 'G', 'L')
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_PIX_FMT_SE401 v4l2_fourcc('S', '4', '0', '1')
 #define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I')
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_fmtdesc {
  __u32 index;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 description[32];
  __u32 pixelformat;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[4];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FMT_FLAG_COMPRESSED 0x0001
 #define V4L2_FMT_FLAG_EMULATED 0x0002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_frmsizetypes {
  V4L2_FRMSIZE_TYPE_DISCRETE = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_FRMSIZE_TYPE_CONTINUOUS = 2,
  V4L2_FRMSIZE_TYPE_STEPWISE = 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_frmsize_discrete {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 width;
  __u32 height;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_frmsize_stepwise {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 min_width;
  __u32 max_width;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 step_width;
  __u32 min_height;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_height;
  __u32 step_height;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_frmsizeenum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
  __u32 pixel_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_frmsize_discrete discrete;
  struct v4l2_frmsize_stepwise stepwise;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
  __u32 reserved[2];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum v4l2_frmivaltypes {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_FRMIVAL_TYPE_DISCRETE = 1,
  V4L2_FRMIVAL_TYPE_CONTINUOUS = 2,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_FRMIVAL_TYPE_STEPWISE = 3,
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_frmival_stepwise {
  struct v4l2_fract min;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_fract max;
  struct v4l2_fract step;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_frmivalenum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
  __u32 pixel_format;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 width;
  __u32 height;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_fract discrete;
  struct v4l2_frmival_stepwise stepwise;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
  __u32 reserved[2];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_timecode {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 frames;
  __u8 seconds;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 minutes;
  __u8 hours;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 userbits[4];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TC_TYPE_24FPS 1
 #define V4L2_TC_TYPE_25FPS 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TC_TYPE_30FPS 3
 #define V4L2_TC_TYPE_50FPS 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TC_TYPE_60FPS 5
 #define V4L2_TC_FLAG_DROPFRAME 0x0001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TC_FLAG_COLORFRAME 0x0002
 #define V4L2_TC_USERBITS_field 0x000C
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TC_USERBITS_USERDEFINED 0x0000
 #define V4L2_TC_USERBITS_8BITCHARS 0x0008
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_jpegcompression {
  int quality;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  int APPn;
  int APP_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  char APP_data[60];
  int COM_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  char COM_data[60];
  __u32 jpeg_markers;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_JPEG_MARKER_DHT (1<<3)
 #define V4L2_JPEG_MARKER_DQT (1<<4)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_JPEG_MARKER_DRI (1<<5)
 #define V4L2_JPEG_MARKER_COM (1<<6)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_JPEG_MARKER_APP (1<<7)
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_requestbuffers {
  __u32 count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  __u32 memory;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[2];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_plane {
  __u32 bytesused;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 length;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mem_offset;
  unsigned long userptr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 fd;
  } m;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 data_offset;
  __u32 reserved[11];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_buffer {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 bytesused;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 field;
  struct timeval timestamp;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_timecode timecode;
  __u32 sequence;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 memory;
  union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 offset;
  unsigned long userptr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_plane *planes;
  __s32 fd;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } m;
  __u32 length;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved2;
  __u32 reserved;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_BUF_FLAG_MAPPED 0x0001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_BUF_FLAG_QUEUED 0x0002
 #define V4L2_BUF_FLAG_DONE 0x0004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_BUF_FLAG_KEYFRAME 0x0008
 #define V4L2_BUF_FLAG_PFRAME 0x0010
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_BUF_FLAG_BFRAME 0x0020
 #define V4L2_BUF_FLAG_ERROR 0x0040
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_BUF_FLAG_TIMECODE 0x0100
 #define V4L2_BUF_FLAG_PREPARED 0x0400
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE 0x0800
 #define V4L2_BUF_FLAG_NO_CACHE_CLEAN 0x1000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_BUF_FLAG_TIMESTAMP_MASK 0xe000
 #define V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN 0x0000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC 0x2000
 #define V4L2_BUF_FLAG_TIMESTAMP_COPY 0x4000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_exportbuffer {
  __u32 type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
  __u32 plane;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
  __s32 fd;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[11];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_framebuffer {
  __u32 capability;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
  void *base;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_pix_format fmt;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001
 #define V4L2_FBUF_CAP_CHROMAKEY 0x0002
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004
 #define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FBUF_CAP_LOCAL_ALPHA 0x0010
 #define V4L2_FBUF_CAP_GLOBAL_ALPHA 0x0020
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FBUF_CAP_LOCAL_INV_ALPHA 0x0040
 #define V4L2_FBUF_CAP_SRC_CHROMAKEY 0x0080
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FBUF_FLAG_PRIMARY 0x0001
 #define V4L2_FBUF_FLAG_OVERLAY 0x0002
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FBUF_FLAG_CHROMAKEY 0x0004
 #define V4L2_FBUF_FLAG_LOCAL_ALPHA 0x0008
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FBUF_FLAG_GLOBAL_ALPHA 0x0010
 #define V4L2_FBUF_FLAG_LOCAL_INV_ALPHA 0x0020
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_FBUF_FLAG_SRC_CHROMAKEY 0x0040
 struct v4l2_clip {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_rect c;
  struct v4l2_clip __user *next;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_window {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_rect w;
  __u32 field;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 chromakey;
  struct v4l2_clip __user *clips;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 clipcount;
  void __user *bitmap;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 global_alpha;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_captureparm {
  __u32 capability;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 capturemode;
  struct v4l2_fract timeperframe;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 extendedmode;
  __u32 readbuffers;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[4];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_MODE_HIGHQUALITY 0x0001
 #define V4L2_CAP_TIMEPERFRAME 0x1000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_outputparm {
  __u32 capability;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 outputmode;
  struct v4l2_fract timeperframe;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 extendedmode;
  __u32 writebuffers;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[4];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_cropcap {
  __u32 type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_rect bounds;
  struct v4l2_rect defrect;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_fract pixelaspect;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_crop {
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_rect c;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_selection {
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 target;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_rect r;
  __u32 reserved[9];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 typedef __u64 v4l2_std_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001)
 #define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004)
 #define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010)
 #define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040)
 #define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100)
 #define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400)
 #define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000)
 #define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_NTSC_443 ((v4l2_std_id)0x00004000)
 #define V4L2_STD_NTSC_M_KR ((v4l2_std_id)0x00008000)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000)
 #define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000)
 #define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000)
 #define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000)
 #define V4L2_STD_SECAM_LC ((v4l2_std_id)0x00800000)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000)
 #define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_NTSC (V4L2_STD_NTSC_M |  V4L2_STD_NTSC_M_JP |  V4L2_STD_NTSC_M_KR)
 #define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |  V4L2_STD_SECAM_K |  V4L2_STD_SECAM_K1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_SECAM (V4L2_STD_SECAM_B |  V4L2_STD_SECAM_G |  V4L2_STD_SECAM_H |  V4L2_STD_SECAM_DK |  V4L2_STD_SECAM_L |  V4L2_STD_SECAM_LC)
 #define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |  V4L2_STD_PAL_B1 |  V4L2_STD_PAL_G)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |  V4L2_STD_PAL_D1 |  V4L2_STD_PAL_K)
 #define V4L2_STD_PAL (V4L2_STD_PAL_BG |  V4L2_STD_PAL_DK |  V4L2_STD_PAL_H |  V4L2_STD_PAL_I)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_B (V4L2_STD_PAL_B |  V4L2_STD_PAL_B1 |  V4L2_STD_SECAM_B)
 #define V4L2_STD_G (V4L2_STD_PAL_G |  V4L2_STD_SECAM_G)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_H (V4L2_STD_PAL_H |  V4L2_STD_SECAM_H)
 #define V4L2_STD_L (V4L2_STD_SECAM_L |  V4L2_STD_SECAM_LC)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_GH (V4L2_STD_G |  V4L2_STD_H)
 #define V4L2_STD_DK (V4L2_STD_PAL_DK |  V4L2_STD_SECAM_DK)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_BG (V4L2_STD_B |  V4L2_STD_G)
 #define V4L2_STD_MN (V4L2_STD_PAL_M |  V4L2_STD_PAL_N |  V4L2_STD_PAL_Nc |  V4L2_STD_NTSC)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_MTS (V4L2_STD_NTSC_M |  V4L2_STD_PAL_M |  V4L2_STD_PAL_N |  V4L2_STD_PAL_Nc)
 #define V4L2_STD_525_60 (V4L2_STD_PAL_M |  V4L2_STD_PAL_60 |  V4L2_STD_NTSC |  V4L2_STD_NTSC_443)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_625_50 (V4L2_STD_PAL |  V4L2_STD_PAL_N |  V4L2_STD_PAL_Nc |  V4L2_STD_SECAM)
 #define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |  V4L2_STD_ATSC_16_VSB)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_STD_UNKNOWN 0
 #define V4L2_STD_ALL (V4L2_STD_525_60 |  V4L2_STD_625_50)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_standard {
  __u32 index;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  v4l2_std_id id;
  __u8 name[24];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_fract frameperiod;
  __u32 framelines;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[4];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_bt_timings {
  __u32 width;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 height;
  __u32 interlaced;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 polarities;
  __u64 pixelclock;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 hfrontporch;
  __u32 hsync;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 hbackporch;
  __u32 vfrontporch;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 vsync;
  __u32 vbackporch;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 il_vfrontporch;
  __u32 il_vsync;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 il_vbackporch;
  __u32 standards;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
  __u32 reserved[14];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 #define V4L2_DV_PROGRESSIVE 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_INTERLACED 1
 #define V4L2_DV_VSYNC_POS_POL 0x00000001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_HSYNC_POS_POL 0x00000002
 #define V4L2_DV_BT_STD_CEA861 (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_BT_STD_DMT (1 << 1)
 #define V4L2_DV_BT_STD_CVT (1 << 2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_BT_STD_GTF (1 << 3)
 #define V4L2_DV_FL_REDUCED_BLANKING (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_FL_CAN_REDUCE_FPS (1 << 1)
 #define V4L2_DV_FL_REDUCED_FPS (1 << 2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_FL_HALF_LINE (1 << 3)
+#define V4L2_DV_BT_BLANKING_WIDTH(bt)   (bt->hfrontporch + bt->hsync + bt->hbackporch)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_DV_BT_FRAME_WIDTH(bt)   (bt->width + V4L2_DV_BT_BLANKING_WIDTH(bt))
+#define V4L2_DV_BT_BLANKING_HEIGHT(bt)   (bt->vfrontporch + bt->vsync + bt->vbackporch +   bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch)
+#define V4L2_DV_BT_FRAME_HEIGHT(bt)   (bt->height + V4L2_DV_BT_BLANKING_HEIGHT(bt))
 struct v4l2_dv_timings {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_bt_timings bt;
  __u32 reserved[32];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
 } __attribute__ ((packed));
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_BT_656_1120 0
 struct v4l2_enum_dv_timings {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
  __u32 reserved[3];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_dv_timings timings;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_bt_timings_cap {
  __u32 min_width;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_width;
  __u32 min_height;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_height;
  __u64 min_pixelclock;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 max_pixelclock;
  __u32 standards;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 capabilities;
  __u32 reserved[16];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 #define V4L2_DV_BT_CAP_INTERLACED (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_BT_CAP_PROGRESSIVE (1 << 1)
 #define V4L2_DV_BT_CAP_REDUCED_BLANKING (1 << 2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DV_BT_CAP_CUSTOM (1 << 3)
 struct v4l2_dv_timings_cap {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  __u32 reserved[3];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  struct v4l2_bt_timings_cap bt;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 raw_data[32];
  };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_input {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
  __u8 name[32];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  __u32 audioset;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tuner;
  v4l2_std_id std;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 status;
  __u32 capabilities;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[3];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_INPUT_TYPE_TUNER 1
 #define V4L2_INPUT_TYPE_CAMERA 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_IN_ST_NO_POWER 0x00000001
 #define V4L2_IN_ST_NO_SIGNAL 0x00000002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_IN_ST_NO_COLOR 0x00000004
 #define V4L2_IN_ST_HFLIP 0x00000010
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_IN_ST_VFLIP 0x00000020
 #define V4L2_IN_ST_NO_H_LOCK 0x00000100
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_IN_ST_COLOR_KILL 0x00000200
 #define V4L2_IN_ST_NO_SYNC 0x00010000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_IN_ST_NO_EQU 0x00020000
 #define V4L2_IN_ST_NO_CARRIER 0x00040000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_IN_ST_MACROVISION 0x01000000
 #define V4L2_IN_ST_NO_ACCESS 0x02000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_IN_ST_VTR 0x04000000
 #define V4L2_IN_CAP_DV_TIMINGS 0x00000002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_IN_CAP_CUSTOM_TIMINGS V4L2_IN_CAP_DV_TIMINGS
 #define V4L2_IN_CAP_STD 0x00000004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_output {
  __u32 index;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name[32];
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 audioset;
  __u32 modulator;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  v4l2_std_id std;
  __u32 capabilities;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[3];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_OUTPUT_TYPE_MODULATOR 1
 #define V4L2_OUTPUT_TYPE_ANALOG 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3
 #define V4L2_OUT_CAP_DV_TIMINGS 0x00000002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_OUT_CAP_CUSTOM_TIMINGS V4L2_OUT_CAP_DV_TIMINGS
 #define V4L2_OUT_CAP_STD 0x00000004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_control {
  __u32 id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 value;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_ext_control {
  __u32 id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 size;
  __u32 reserved2[1];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  __s32 value;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s64 value64;
  char *string;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
 } __attribute__ ((packed));
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_ext_controls {
  __u32 ctrl_class;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 count;
  __u32 error_idx;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[2];
  struct v4l2_ext_control *controls;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_CTRL_ID_MASK (0x0fffffff)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL)
 #define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum v4l2_ctrl_type {
  V4L2_CTRL_TYPE_INTEGER = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_CTRL_TYPE_BOOLEAN = 2,
  V4L2_CTRL_TYPE_MENU = 3,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_CTRL_TYPE_BUTTON = 4,
  V4L2_CTRL_TYPE_INTEGER64 = 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_CTRL_TYPE_CTRL_CLASS = 6,
  V4L2_CTRL_TYPE_STRING = 7,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  V4L2_CTRL_TYPE_BITMASK = 8,
  V4L2_CTRL_TYPE_INTEGER_MENU = 9,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_queryctrl {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
  __u32 type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name[32];
  __s32 minimum;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 maximum;
  __s32 step;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 default_value;
  __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[2];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_querymenu {
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name[32];
  __s64 value;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 #define V4L2_CTRL_FLAG_DISABLED 0x0001
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CTRL_FLAG_GRABBED 0x0002
 #define V4L2_CTRL_FLAG_READ_ONLY 0x0004
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CTRL_FLAG_UPDATE 0x0008
 #define V4L2_CTRL_FLAG_INACTIVE 0x0010
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CTRL_FLAG_SLIDER 0x0020
 #define V4L2_CTRL_FLAG_WRITE_ONLY 0x0040
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CTRL_FLAG_VOLATILE 0x0080
 #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CID_MAX_CTRLS 1024
 #define V4L2_CID_PRIVATE_BASE 0x08000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_tuner {
  __u32 index;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name[32];
  __u32 type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 capability;
  __u32 rangelow;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 rangehigh;
  __u32 rxsubchans;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 audmode;
  __s32 signal;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 afc;
  __u32 reserved[4];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_modulator {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 index;
  __u8 name[32];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 capability;
  __u32 rangelow;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 rangehigh;
  __u32 txsubchans;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[4];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_CAP_LOW 0x0001
 #define V4L2_TUNER_CAP_NORM 0x0002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_CAP_HWSEEK_BOUNDED 0x0004
 #define V4L2_TUNER_CAP_HWSEEK_WRAP 0x0008
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_CAP_STEREO 0x0010
 #define V4L2_TUNER_CAP_LANG2 0x0020
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_CAP_SAP 0x0020
 #define V4L2_TUNER_CAP_LANG1 0x0040
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_CAP_RDS 0x0080
 #define V4L2_TUNER_CAP_RDS_BLOCK_IO 0x0100
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_CAP_RDS_CONTROLS 0x0200
 #define V4L2_TUNER_CAP_FREQ_BANDS 0x0400
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_CAP_HWSEEK_PROG_LIM 0x0800
 #define V4L2_TUNER_SUB_MONO 0x0001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_SUB_STEREO 0x0002
 #define V4L2_TUNER_SUB_LANG2 0x0004
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_SUB_SAP 0x0004
 #define V4L2_TUNER_SUB_LANG1 0x0008
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_SUB_RDS 0x0010
 #define V4L2_TUNER_MODE_MONO 0x0000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_MODE_STEREO 0x0001
 #define V4L2_TUNER_MODE_LANG2 0x0002
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_MODE_SAP 0x0002
 #define V4L2_TUNER_MODE_LANG1 0x0003
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_TUNER_MODE_LANG1_LANG2 0x0004
 struct v4l2_frequency {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 tuner;
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 frequency;
  __u32 reserved[8];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_BAND_MODULATION_VSB (1 << 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_BAND_MODULATION_FM (1 << 2)
 #define V4L2_BAND_MODULATION_AM (1 << 3)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_frequency_band {
  __u32 tuner;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  __u32 index;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 capability;
  __u32 rangelow;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 rangehigh;
  __u32 modulation;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[9];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_hw_freq_seek {
  __u32 tuner;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  __u32 seek_upward;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 wrap_around;
  __u32 spacing;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 rangelow;
  __u32 rangehigh;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[5];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_rds_data {
  __u8 lsb;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 msb;
  __u8 block;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 #define V4L2_RDS_BLOCK_MSK 0x7
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_RDS_BLOCK_A 0
 #define V4L2_RDS_BLOCK_B 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_RDS_BLOCK_C 2
 #define V4L2_RDS_BLOCK_D 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_RDS_BLOCK_C_ALT 4
 #define V4L2_RDS_BLOCK_INVALID 7
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_RDS_BLOCK_CORRECTED 0x40
 #define V4L2_RDS_BLOCK_ERROR 0x80
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_audio {
  __u32 index;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name[32];
  __u32 capability;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mode;
  __u32 reserved[2];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_AUDCAP_STEREO 0x00001
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_AUDCAP_AVL 0x00002
 #define V4L2_AUDMODE_AVL 0x00001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_audioout {
  __u32 index;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 name[32];
  __u32 capability;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mode;
  __u32 reserved[2];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_ENC_IDX_FRAME_I (0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_ENC_IDX_FRAME_P (1)
 #define V4L2_ENC_IDX_FRAME_B (2)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_ENC_IDX_FRAME_MASK (0xf)
 struct v4l2_enc_idx_entry {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 offset;
  __u64 pts;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 length;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[2];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_ENC_IDX_ENTRIES (64)
 struct v4l2_enc_idx {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 entries;
  __u32 entries_cap;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[4];
  struct v4l2_enc_idx_entry entry[V4L2_ENC_IDX_ENTRIES];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_ENC_CMD_START (0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_ENC_CMD_STOP (1)
 #define V4L2_ENC_CMD_PAUSE (2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_ENC_CMD_RESUME (3)
 #define V4L2_ENC_CMD_STOP_AT_GOP_END (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_encoder_cmd {
  __u32 cmd;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
  union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  __u32 data[8];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } raw;
  };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_DEC_CMD_START (0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DEC_CMD_STOP (1)
 #define V4L2_DEC_CMD_PAUSE (2)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DEC_CMD_RESUME (3)
 #define V4L2_DEC_CMD_START_MUTE_AUDIO (1 << 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DEC_CMD_PAUSE_TO_BLACK (1 << 0)
 #define V4L2_DEC_CMD_STOP_TO_BLACK (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DEC_CMD_STOP_IMMEDIATELY (1 << 1)
 #define V4L2_DEC_START_FMT_NONE (0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_DEC_START_FMT_GOP (1)
 struct v4l2_decoder_cmd {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cmd;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 pts;
  } stop;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  __s32 speed;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 format;
  } start;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  __u32 data[16];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } raw;
  };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_vbi_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 sampling_rate;
  __u32 offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 samples_per_line;
  __u32 sample_format;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 start[2];
  __u32 count[2];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 flags;
  __u32 reserved[2];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_VBI_UNSYNC (1 << 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_VBI_INTERLACED (1 << 1)
 struct v4l2_sliced_vbi_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 service_set;
  __u16 service_lines[2][24];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 io_size;
  __u32 reserved[2];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define V4L2_SLICED_TELETEXT_B (0x0001)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_SLICED_VPS (0x0400)
 #define V4L2_SLICED_CAPTION_525 (0x1000)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_SLICED_WSS_625 (0x4000)
 #define V4L2_SLICED_VBI_525 (V4L2_SLICED_CAPTION_525)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625)
 struct v4l2_sliced_vbi_cap {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 service_set;
  __u16 service_lines[2][24];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  __u32 reserved[3];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_sliced_vbi_data {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
  __u32 field;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 line;
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 data[48];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_MPEG_VBI_IVTV_TELETEXT_B (1)
 #define V4L2_MPEG_VBI_IVTV_CAPTION_525 (4)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_MPEG_VBI_IVTV_WSS_625 (5)
 #define V4L2_MPEG_VBI_IVTV_VPS (7)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_mpeg_vbi_itv0_line {
  __u8 id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 data[42];
 } __attribute__ ((packed));
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_mpeg_vbi_itv0 {
  __le32 linemask[2];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_mpeg_vbi_itv0_line line[35];
 } __attribute__ ((packed));
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_mpeg_vbi_ITV0 {
  struct v4l2_mpeg_vbi_itv0_line line[36];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 #define V4L2_MPEG_VBI_IVTV_MAGIC0 "itv0"
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_MPEG_VBI_IVTV_MAGIC1 "ITV0"
 struct v4l2_mpeg_vbi_fmt_ivtv {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 magic[4];
  union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_mpeg_vbi_itv0 itv0;
  struct v4l2_mpeg_vbi_ITV0 ITV0;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
 } __attribute__ ((packed));
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_plane_pix_format {
  __u32 sizeimage;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 bytesperline;
  __u16 reserved[7];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 struct v4l2_pix_format_mplane {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 width;
  __u32 height;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pixelformat;
  __u32 field;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 colorspace;
  struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 num_planes;
  __u8 reserved[11];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 struct v4l2_format {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_pix_format pix;
  struct v4l2_pix_format_mplane pix_mp;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_window win;
  struct v4l2_vbi_format vbi;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_sliced_vbi_format sliced;
  __u8 raw_data[200];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } fmt;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_streamparm {
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  struct v4l2_captureparm capture;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_outputparm output;
  __u8 raw_data[200];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } parm;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_EVENT_ALL 0
 #define V4L2_EVENT_VSYNC 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_EVENT_EOS 2
 #define V4L2_EVENT_CTRL 3
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_EVENT_FRAME_SYNC 4
 #define V4L2_EVENT_PRIVATE_START 0x08000000
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_event_vsync {
  __u8 field;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 #define V4L2_EVENT_CTRL_CH_VALUE (1 << 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_EVENT_CTRL_CH_FLAGS (1 << 1)
 #define V4L2_EVENT_CTRL_CH_RANGE (1 << 2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_event_ctrl {
  __u32 changes;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 type;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 value;
  __s64 value64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  };
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 minimum;
  __s32 maximum;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __s32 step;
  __s32 default_value;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct v4l2_event_frame_sync {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 frame_sequence;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_event {
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  struct v4l2_event_vsync vsync;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_event_ctrl ctrl;
  struct v4l2_event_frame_sync frame_sync;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 data[64];
  } u;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pending;
  __u32 sequence;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct timespec timestamp;
  __u32 id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[8];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0)
 #define V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK (1 << 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_event_subscription {
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
  __u32 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[5];
 };
-#define V4L2_CHIP_MATCH_BRIDGE 0
-#define V4L2_CHIP_MATCH_HOST V4L2_CHIP_MATCH_BRIDGE
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CHIP_MATCH_BRIDGE 0
+#define V4L2_CHIP_MATCH_SUBDEV 4
+#define V4L2_CHIP_MATCH_HOST V4L2_CHIP_MATCH_BRIDGE
 #define V4L2_CHIP_MATCH_I2C_DRIVER 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define V4L2_CHIP_MATCH_I2C_ADDR 2
 #define V4L2_CHIP_MATCH_AC97 3
-#define V4L2_CHIP_MATCH_SUBDEV 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct v4l2_dbg_match {
  __u32 type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  __u32 addr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  char name[32];
  };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 } __attribute__ ((packed));
 struct v4l2_dbg_register {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct v4l2_dbg_match match;
  __u32 size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 reg;
  __u64 val;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-} __attribute__ ((packed));
-struct v4l2_dbg_chip_ident {
- struct v4l2_dbg_match match;
- __u32 ident;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u32 revision;
 } __attribute__ ((packed));
 #define V4L2_CHIP_FL_READABLE (1 << 0)
-#define V4L2_CHIP_FL_WRITABLE (1 << 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define V4L2_CHIP_FL_WRITABLE (1 << 1)
 struct v4l2_dbg_chip_info {
  struct v4l2_dbg_match match;
  char name[32];
- __u32 flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 flags;
  __u32 reserved[32];
 } __attribute__ ((packed));
 struct v4l2_create_buffers {
- __u32 index;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 index;
  __u32 count;
  __u32 memory;
  struct v4l2_format format;
- __u32 reserved[8];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 reserved[8];
 };
 #define VIDIOC_QUERYCAP _IOR('V', 0, struct v4l2_capability)
 #define VIDIOC_RESERVED _IO('V', 1)
-#define VIDIOC_ENUM_FMT _IOWR('V', 2, struct v4l2_fmtdesc)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_ENUM_FMT _IOWR('V', 2, struct v4l2_fmtdesc)
 #define VIDIOC_G_FMT _IOWR('V', 4, struct v4l2_format)
 #define VIDIOC_S_FMT _IOWR('V', 5, struct v4l2_format)
 #define VIDIOC_REQBUFS _IOWR('V', 8, struct v4l2_requestbuffers)
-#define VIDIOC_QUERYBUF _IOWR('V', 9, struct v4l2_buffer)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_QUERYBUF _IOWR('V', 9, struct v4l2_buffer)
 #define VIDIOC_G_FBUF _IOR('V', 10, struct v4l2_framebuffer)
 #define VIDIOC_S_FBUF _IOW('V', 11, struct v4l2_framebuffer)
 #define VIDIOC_OVERLAY _IOW('V', 14, int)
-#define VIDIOC_QBUF _IOWR('V', 15, struct v4l2_buffer)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_QBUF _IOWR('V', 15, struct v4l2_buffer)
 #define VIDIOC_EXPBUF _IOWR('V', 16, struct v4l2_exportbuffer)
 #define VIDIOC_DQBUF _IOWR('V', 17, struct v4l2_buffer)
 #define VIDIOC_STREAMON _IOW('V', 18, int)
-#define VIDIOC_STREAMOFF _IOW('V', 19, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_STREAMOFF _IOW('V', 19, int)
 #define VIDIOC_G_PARM _IOWR('V', 21, struct v4l2_streamparm)
 #define VIDIOC_S_PARM _IOWR('V', 22, struct v4l2_streamparm)
 #define VIDIOC_G_STD _IOR('V', 23, v4l2_std_id)
-#define VIDIOC_S_STD _IOW('V', 24, v4l2_std_id)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_S_STD _IOW('V', 24, v4l2_std_id)
 #define VIDIOC_ENUMSTD _IOWR('V', 25, struct v4l2_standard)
 #define VIDIOC_ENUMINPUT _IOWR('V', 26, struct v4l2_input)
 #define VIDIOC_G_CTRL _IOWR('V', 27, struct v4l2_control)
-#define VIDIOC_S_CTRL _IOWR('V', 28, struct v4l2_control)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_S_CTRL _IOWR('V', 28, struct v4l2_control)
 #define VIDIOC_G_TUNER _IOWR('V', 29, struct v4l2_tuner)
 #define VIDIOC_S_TUNER _IOW('V', 30, struct v4l2_tuner)
 #define VIDIOC_G_AUDIO _IOR('V', 33, struct v4l2_audio)
-#define VIDIOC_S_AUDIO _IOW('V', 34, struct v4l2_audio)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_S_AUDIO _IOW('V', 34, struct v4l2_audio)
 #define VIDIOC_QUERYCTRL _IOWR('V', 36, struct v4l2_queryctrl)
 #define VIDIOC_QUERYMENU _IOWR('V', 37, struct v4l2_querymenu)
 #define VIDIOC_G_INPUT _IOR('V', 38, int)
-#define VIDIOC_S_INPUT _IOWR('V', 39, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_S_INPUT _IOWR('V', 39, int)
 #define VIDIOC_G_OUTPUT _IOR('V', 46, int)
 #define VIDIOC_S_OUTPUT _IOWR('V', 47, int)
 #define VIDIOC_ENUMOUTPUT _IOWR('V', 48, struct v4l2_output)
-#define VIDIOC_G_AUDOUT _IOR('V', 49, struct v4l2_audioout)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_G_AUDOUT _IOR('V', 49, struct v4l2_audioout)
 #define VIDIOC_S_AUDOUT _IOW('V', 50, struct v4l2_audioout)
 #define VIDIOC_G_MODULATOR _IOWR('V', 54, struct v4l2_modulator)
 #define VIDIOC_S_MODULATOR _IOW('V', 55, struct v4l2_modulator)
-#define VIDIOC_G_FREQUENCY _IOWR('V', 56, struct v4l2_frequency)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_G_FREQUENCY _IOWR('V', 56, struct v4l2_frequency)
 #define VIDIOC_S_FREQUENCY _IOW('V', 57, struct v4l2_frequency)
 #define VIDIOC_CROPCAP _IOWR('V', 58, struct v4l2_cropcap)
 #define VIDIOC_G_CROP _IOWR('V', 59, struct v4l2_crop)
-#define VIDIOC_S_CROP _IOW('V', 60, struct v4l2_crop)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_S_CROP _IOW('V', 60, struct v4l2_crop)
 #define VIDIOC_G_JPEGCOMP _IOR('V', 61, struct v4l2_jpegcompression)
 #define VIDIOC_S_JPEGCOMP _IOW('V', 62, struct v4l2_jpegcompression)
 #define VIDIOC_QUERYSTD _IOR('V', 63, v4l2_std_id)
-#define VIDIOC_TRY_FMT _IOWR('V', 64, struct v4l2_format)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_TRY_FMT _IOWR('V', 64, struct v4l2_format)
 #define VIDIOC_ENUMAUDIO _IOWR('V', 65, struct v4l2_audio)
 #define VIDIOC_ENUMAUDOUT _IOWR('V', 66, struct v4l2_audioout)
 #define VIDIOC_G_PRIORITY _IOR('V', 67, __u32)
-#define VIDIOC_S_PRIORITY _IOW('V', 68, __u32)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_S_PRIORITY _IOW('V', 68, __u32)
 #define VIDIOC_G_SLICED_VBI_CAP _IOWR('V', 69, struct v4l2_sliced_vbi_cap)
 #define VIDIOC_LOG_STATUS _IO('V', 70)
 #define VIDIOC_G_EXT_CTRLS _IOWR('V', 71, struct v4l2_ext_controls)
-#define VIDIOC_S_EXT_CTRLS _IOWR('V', 72, struct v4l2_ext_controls)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_S_EXT_CTRLS _IOWR('V', 72, struct v4l2_ext_controls)
 #define VIDIOC_TRY_EXT_CTRLS _IOWR('V', 73, struct v4l2_ext_controls)
 #define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum)
 #define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum)
-#define VIDIOC_G_ENC_INDEX _IOR('V', 76, struct v4l2_enc_idx)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_G_ENC_INDEX _IOR('V', 76, struct v4l2_enc_idx)
 #define VIDIOC_ENCODER_CMD _IOWR('V', 77, struct v4l2_encoder_cmd)
 #define VIDIOC_TRY_ENCODER_CMD _IOWR('V', 78, struct v4l2_encoder_cmd)
 #define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register)
-#define VIDIOC_DBG_G_REGISTER _IOWR('V', 80, struct v4l2_dbg_register)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define VIDIOC_DBG_G_CHIP_IDENT _IOWR('V', 81, struct v4l2_dbg_chip_ident)
+#define VIDIOC_DBG_G_REGISTER _IOWR('V', 80, struct v4l2_dbg_register)
 #define VIDIOC_S_HW_FREQ_SEEK _IOW('V', 82, struct v4l2_hw_freq_seek)
 #define VIDIOC_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings)
 #define VIDIOC_G_DV_TIMINGS _IOWR('V', 88, struct v4l2_dv_timings)
diff --git a/libc/kernel/uapi/linux/virtio_config.h b/libc/kernel/uapi/linux/virtio_config.h
index 1d9834d..0d1fc62 100644
--- a/libc/kernel/uapi/linux/virtio_config.h
+++ b/libc/kernel/uapi/linux/virtio_config.h
@@ -28,4 +28,6 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VIRTIO_TRANSPORT_F_END 32
 #define VIRTIO_F_NOTIFY_ON_EMPTY 24
+#define VIRTIO_F_ANY_LAYOUT 27
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/virtio_console.h b/libc/kernel/uapi/linux/virtio_console.h
index 148ffe0..81d515c 100644
--- a/libc/kernel/uapi/linux/virtio_console.h
+++ b/libc/kernel/uapi/linux/virtio_console.h
@@ -24,28 +24,31 @@
 #include <linux/virtio_config.h>
 #define VIRTIO_CONSOLE_F_SIZE 0
 #define VIRTIO_CONSOLE_F_MULTIPORT 1
-#define VIRTIO_CONSOLE_BAD_ID (~(__u32)0)
+#define VIRTIO_CONSOLE_F_EMERG_WRITE 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIRTIO_CONSOLE_BAD_ID (~(__u32)0)
 struct virtio_console_config {
  __u16 cols;
  __u16 rows;
- __u32 max_nr_ports;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 max_nr_ports;
+ __u32 emerg_wr;
 } __attribute__((packed));
 struct virtio_console_control {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
  __u16 event;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 value;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VIRTIO_CONSOLE_DEVICE_READY 0
 #define VIRTIO_CONSOLE_PORT_ADD 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VIRTIO_CONSOLE_PORT_REMOVE 2
 #define VIRTIO_CONSOLE_PORT_READY 3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VIRTIO_CONSOLE_CONSOLE_PORT 4
 #define VIRTIO_CONSOLE_RESIZE 5
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VIRTIO_CONSOLE_PORT_OPEN 6
 #define VIRTIO_CONSOLE_PORT_NAME 7
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/virtio_net.h b/libc/kernel/uapi/linux/virtio_net.h
index b3f942c..aaf1b29 100644
--- a/libc/kernel/uapi/linux/virtio_net.h
+++ b/libc/kernel/uapi/linux/virtio_net.h
@@ -53,7 +53,7 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define VIRTIO_NET_S_ANNOUNCE 2
 struct virtio_net_config {
- __u8 mac[6];
+ __u8 mac[ETH_ALEN];
  __u16 status;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 max_virtqueue_pairs;
diff --git a/libc/kernel/uapi/linux/virtio_pci.h b/libc/kernel/uapi/linux/virtio_pci.h
index eb908e1..affd6c9 100644
--- a/libc/kernel/uapi/linux/virtio_pci.h
+++ b/libc/kernel/uapi/linux/virtio_pci.h
@@ -34,10 +34,11 @@
 #define VIRTIO_MSI_CONFIG_VECTOR 20
 #define VIRTIO_MSI_QUEUE_VECTOR 22
 #define VIRTIO_MSI_NO_VECTOR 0xffff
-#define VIRTIO_PCI_CONFIG(dev) ((dev)->msix_enabled ? 24 : 20)
+#define VIRTIO_PCI_CONFIG_OFF(msix_enabled) ((msix_enabled) ? 24 : 20)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIRTIO_PCI_CONFIG(dev) VIRTIO_PCI_CONFIG_OFF((dev)->msix_enabled)
 #define VIRTIO_PCI_ABI_VERSION 0
 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
 #define VIRTIO_PCI_VRING_ALIGN 4096
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/vsp1.h b/libc/kernel/uapi/linux/vsp1.h
new file mode 100644
index 0000000..b7522e7
--- /dev/null
+++ b/libc/kernel/uapi/linux/vsp1.h
@@ -0,0 +1,29 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __VSP1_USER_H__
+#define __VSP1_USER_H__
+#include <linux/types.h>
+#include <linux/videodev2.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define VIDIOC_VSP1_LUT_CONFIG   _IOWR('V', BASE_VIDIOC_PRIVATE + 1, struct vsp1_lut_config)
+struct vsp1_lut_config {
+ u32 lut[256];
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/linux/wimax/i2400m.h b/libc/kernel/uapi/linux/wimax/i2400m.h
index 643c048..30585a8 100644
--- a/libc/kernel/uapi/linux/wimax/i2400m.h
+++ b/libc/kernel/uapi/linux/wimax/i2400m.h
@@ -19,362 +19,363 @@
 #ifndef __LINUX__WIMAX__I2400M_H__
 #define __LINUX__WIMAX__I2400M_H__
 #include <linux/types.h>
-struct i2400m_bcf_hdr {
+#include <linux/if_ether.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct i2400m_bcf_hdr {
  __le32 module_type;
  __le32 header_len;
  __le32 header_version;
- __le32 module_id;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 module_id;
  __le32 module_vendor;
  __le32 date;
  __le32 size;
- __le32 key_size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 key_size;
  __le32 modulus_size;
  __le32 exponent_size;
  __u8 reserved[88];
-} __attribute__ ((packed));
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+} __attribute__ ((packed));
 enum i2400m_brh_opcode {
  I2400M_BRH_READ = 1,
  I2400M_BRH_WRITE = 2,
- I2400M_BRH_JUMP = 3,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_BRH_JUMP = 3,
  I2400M_BRH_SIGNED_JUMP = 8,
  I2400M_BRH_HASH_PAYLOAD_ONLY = 9,
 };
-enum i2400m_brh {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum i2400m_brh {
  I2400M_BRH_SIGNATURE = 0xcbbc0000,
  I2400M_BRH_SIGNATURE_MASK = 0xffff0000,
  I2400M_BRH_SIGNATURE_SHIFT = 16,
- I2400M_BRH_OPCODE_MASK = 0x0000000f,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_BRH_OPCODE_MASK = 0x0000000f,
  I2400M_BRH_RESPONSE_MASK = 0x000000f0,
  I2400M_BRH_RESPONSE_SHIFT = 4,
  I2400M_BRH_DIRECT_ACCESS = 0x00000400,
- I2400M_BRH_RESPONSE_REQUIRED = 0x00000200,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_BRH_RESPONSE_REQUIRED = 0x00000200,
  I2400M_BRH_USE_CHECKSUM = 0x00000100,
 };
 struct i2400m_bootrom_header {
- __le32 command;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 command;
  __le32 target_addr;
  __le32 data_size;
  __le32 block_checksum;
- char payload[0];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ char payload[0];
 } __attribute__ ((packed));
 enum i2400m_pt {
  I2400M_PT_DATA = 0,
- I2400M_PT_CTRL,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_PT_CTRL,
  I2400M_PT_TRACE,
  I2400M_PT_RESET_WARM,
  I2400M_PT_RESET_COLD,
- I2400M_PT_EDATA,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_PT_EDATA,
  I2400M_PT_ILLEGAL
 };
 struct i2400m_pl_data_hdr {
- __le32 reserved;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 reserved;
 } __attribute__((packed));
 struct i2400m_pl_edata_hdr {
  __le32 reorder;
- __u8 cs;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 cs;
  __u8 reserved[11];
 } __attribute__((packed));
 enum i2400m_cs {
- I2400M_CS_IPV4_0 = 0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_CS_IPV4_0 = 0,
  I2400M_CS_IPV4 = 2,
 };
 enum i2400m_ro {
- I2400M_RO_NEEDED = 0x01,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_RO_NEEDED = 0x01,
  I2400M_RO_TYPE = 0x03,
  I2400M_RO_TYPE_SHIFT = 1,
  I2400M_RO_CIN = 0x0f,
- I2400M_RO_CIN_SHIFT = 4,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_RO_CIN_SHIFT = 4,
  I2400M_RO_FBN = 0x07ff,
  I2400M_RO_FBN_SHIFT = 8,
  I2400M_RO_SN = 0x07ff,
- I2400M_RO_SN_SHIFT = 21,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_RO_SN_SHIFT = 21,
 };
 enum i2400m_ro_type {
  I2400M_RO_TYPE_RESET = 0,
- I2400M_RO_TYPE_PACKET,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_RO_TYPE_PACKET,
  I2400M_RO_TYPE_WS,
  I2400M_RO_TYPE_PACKET_WS,
 };
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  I2400M_PL_ALIGN = 16,
  I2400M_PL_SIZE_MAX = 0x3EFF,
  I2400M_MAX_PLS_IN_MSG = 60,
- I2400M_H2D_PREVIEW_BARKER = 0xcafe900d,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_H2D_PREVIEW_BARKER = 0xcafe900d,
  I2400M_COLD_RESET_BARKER = 0xc01dc01d,
  I2400M_WARM_RESET_BARKER = 0x50f750f7,
  I2400M_NBOOT_BARKER = 0xdeadbeef,
- I2400M_SBOOT_BARKER = 0x0ff1c1a1,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_SBOOT_BARKER = 0x0ff1c1a1,
  I2400M_SBOOT_BARKER_6050 = 0x80000001,
  I2400M_ACK_BARKER = 0xfeedbabe,
  I2400M_D2H_MSG_BARKER = 0xbeefbabe,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct i2400m_pld {
  __le32 val;
 } __attribute__ ((packed));
-#define I2400M_PLD_SIZE_MASK 0x00003fff
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define I2400M_PLD_SIZE_MASK 0x00003fff
 #define I2400M_PLD_TYPE_SHIFT 16
 #define I2400M_PLD_TYPE_MASK 0x000f0000
 struct i2400m_msg_hdr {
- union {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union {
  __le32 barker;
  __u32 size;
  };
- union {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ union {
  __le32 sequence;
  __u32 offset;
  };
- __le16 num_pls;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 num_pls;
  __le16 rsv1;
  __le16 padding;
  __le16 rsv2;
- struct i2400m_pld pld[0];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct i2400m_pld pld[0];
 } __attribute__ ((packed));
 enum {
  I2400M_L3L4_VERSION = 0x0100,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum i2400m_mt {
  I2400M_MT_RESERVED = 0x0000,
  I2400M_MT_INVALID = 0xffff,
- I2400M_MT_REPORT_MASK = 0x8000,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_REPORT_MASK = 0x8000,
  I2400M_MT_GET_SCAN_RESULT = 0x4202,
  I2400M_MT_SET_SCAN_PARAM = 0x4402,
  I2400M_MT_CMD_RF_CONTROL = 0x4602,
- I2400M_MT_CMD_SCAN = 0x4603,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_CMD_SCAN = 0x4603,
  I2400M_MT_CMD_CONNECT = 0x4604,
  I2400M_MT_CMD_DISCONNECT = 0x4605,
  I2400M_MT_CMD_EXIT_IDLE = 0x4606,
- I2400M_MT_GET_LM_VERSION = 0x5201,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_GET_LM_VERSION = 0x5201,
  I2400M_MT_GET_DEVICE_INFO = 0x5202,
  I2400M_MT_GET_LINK_STATUS = 0x5203,
  I2400M_MT_GET_STATISTICS = 0x5204,
- I2400M_MT_GET_STATE = 0x5205,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_GET_STATE = 0x5205,
  I2400M_MT_GET_MEDIA_STATUS = 0x5206,
  I2400M_MT_SET_INIT_CONFIG = 0x5404,
  I2400M_MT_CMD_INIT = 0x5601,
- I2400M_MT_CMD_TERMINATE = 0x5602,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_CMD_TERMINATE = 0x5602,
  I2400M_MT_CMD_MODE_OF_OP = 0x5603,
  I2400M_MT_CMD_RESET_DEVICE = 0x5604,
  I2400M_MT_CMD_MONITOR_CONTROL = 0x5605,
- I2400M_MT_CMD_ENTER_POWERSAVE = 0x5606,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_CMD_ENTER_POWERSAVE = 0x5606,
  I2400M_MT_GET_TLS_OPERATION_RESULT = 0x6201,
  I2400M_MT_SET_EAP_SUCCESS = 0x6402,
  I2400M_MT_SET_EAP_FAIL = 0x6403,
- I2400M_MT_SET_EAP_KEY = 0x6404,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_SET_EAP_KEY = 0x6404,
  I2400M_MT_CMD_SEND_EAP_RESPONSE = 0x6602,
  I2400M_MT_REPORT_SCAN_RESULT = 0xc002,
  I2400M_MT_REPORT_STATE = 0xd002,
- I2400M_MT_REPORT_POWERSAVE_READY = 0xd005,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_REPORT_POWERSAVE_READY = 0xd005,
  I2400M_MT_REPORT_EAP_REQUEST = 0xe002,
  I2400M_MT_REPORT_EAP_RESTART = 0xe003,
  I2400M_MT_REPORT_ALT_ACCEPT = 0xe004,
- I2400M_MT_REPORT_KEY_REQUEST = 0xe005,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MT_REPORT_KEY_REQUEST = 0xe005,
 };
 enum i2400m_ms {
  I2400M_MS_DONE_OK = 0,
- I2400M_MS_DONE_IN_PROGRESS = 1,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MS_DONE_IN_PROGRESS = 1,
  I2400M_MS_INVALID_OP = 2,
  I2400M_MS_BAD_STATE = 3,
  I2400M_MS_ILLEGAL_VALUE = 4,
- I2400M_MS_MISSING_PARAMS = 5,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MS_MISSING_PARAMS = 5,
  I2400M_MS_VERSION_ERROR = 6,
  I2400M_MS_ACCESSIBILITY_ERROR = 7,
  I2400M_MS_BUSY = 8,
- I2400M_MS_CORRUPTED_TLV = 9,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MS_CORRUPTED_TLV = 9,
  I2400M_MS_UNINITIALIZED = 10,
  I2400M_MS_UNKNOWN_ERROR = 11,
  I2400M_MS_PRODUCTION_ERROR = 12,
- I2400M_MS_NO_RF = 13,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MS_NO_RF = 13,
  I2400M_MS_NOT_READY_FOR_POWERSAVE = 14,
  I2400M_MS_THERMAL_CRITICAL = 15,
  I2400M_MS_MAX
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum i2400m_tlv {
  I2400M_TLV_L4_MESSAGE_VERSIONS = 129,
  I2400M_TLV_SYSTEM_STATE = 141,
- I2400M_TLV_MEDIA_STATUS = 161,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_TLV_MEDIA_STATUS = 161,
  I2400M_TLV_RF_OPERATION = 162,
  I2400M_TLV_RF_STATUS = 163,
  I2400M_TLV_DEVICE_RESET_TYPE = 132,
- I2400M_TLV_CONFIG_IDLE_PARAMETERS = 601,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_TLV_CONFIG_IDLE_PARAMETERS = 601,
  I2400M_TLV_CONFIG_IDLE_TIMEOUT = 611,
  I2400M_TLV_CONFIG_D2H_DATA_FORMAT = 614,
  I2400M_TLV_CONFIG_DL_HOST_REORDER = 615,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct i2400m_tlv_hdr {
  __le16 type;
  __le16 length;
- __u8 pl[0];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 pl[0];
 } __attribute__((packed));
 struct i2400m_l3l4_hdr {
  __le16 type;
- __le16 length;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 length;
  __le16 version;
  __le16 resv1;
  __le16 status;
- __le16 resv2;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 resv2;
  struct i2400m_tlv_hdr pl[0];
 } __attribute__((packed));
 enum i2400m_system_state {
- I2400M_SS_UNINITIALIZED = 1,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_SS_UNINITIALIZED = 1,
  I2400M_SS_INIT,
  I2400M_SS_READY,
  I2400M_SS_SCAN,
- I2400M_SS_STANDBY,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_SS_STANDBY,
  I2400M_SS_CONNECTING,
  I2400M_SS_WIMAX_CONNECTED,
  I2400M_SS_DATA_PATH_CONNECTED,
- I2400M_SS_IDLE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_SS_IDLE,
  I2400M_SS_DISCONNECTING,
  I2400M_SS_OUT_OF_ZONE,
  I2400M_SS_SLEEPACTIVE,
- I2400M_SS_PRODUCTION,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_SS_PRODUCTION,
  I2400M_SS_CONFIG,
  I2400M_SS_RF_OFF,
  I2400M_SS_RF_SHUTDOWN,
- I2400M_SS_DEVICE_DISCONNECT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_SS_DEVICE_DISCONNECT,
  I2400M_SS_MAX,
 };
 struct i2400m_tlv_system_state {
- struct i2400m_tlv_hdr hdr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct i2400m_tlv_hdr hdr;
  __le32 state;
 } __attribute__((packed));
 struct i2400m_tlv_l4_message_versions {
- struct i2400m_tlv_hdr hdr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct i2400m_tlv_hdr hdr;
  __le16 major;
  __le16 minor;
  __le16 branch;
- __le16 reserved;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le16 reserved;
 } __attribute__((packed));
 struct i2400m_tlv_detailed_device_info {
  struct i2400m_tlv_hdr hdr;
- __u8 reserved1[400];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __u8 mac_address[6];
+ __u8 reserved1[400];
+ __u8 mac_address[ETH_ALEN];
  __u8 reserved2[2];
 } __attribute__((packed));
-enum i2400m_rf_switch_status {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum i2400m_rf_switch_status {
  I2400M_RF_SWITCH_ON = 1,
  I2400M_RF_SWITCH_OFF = 2,
 };
-struct i2400m_tlv_rf_switches_status {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct i2400m_tlv_rf_switches_status {
  struct i2400m_tlv_hdr hdr;
  __u8 sw_rf_switch;
  __u8 hw_rf_switch;
- __u8 reserved[2];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 reserved[2];
 } __attribute__((packed));
 enum {
  i2400m_rf_operation_on = 1,
- i2400m_rf_operation_off = 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ i2400m_rf_operation_off = 2
 };
 struct i2400m_tlv_rf_operation {
  struct i2400m_tlv_hdr hdr;
- __le32 status;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 status;
 } __attribute__((packed));
 enum i2400m_tlv_reset_type {
  I2400M_RESET_TYPE_COLD = 1,
- I2400M_RESET_TYPE_WARM
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_RESET_TYPE_WARM
 };
 struct i2400m_tlv_device_reset_type {
  struct i2400m_tlv_hdr hdr;
- __le32 reset_type;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 reset_type;
 } __attribute__((packed));
 struct i2400m_tlv_config_idle_parameters {
  struct i2400m_tlv_hdr hdr;
- __le32 idle_timeout;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __le32 idle_timeout;
  __le32 idle_paging_interval;
 } __attribute__((packed));
 enum i2400m_media_status {
- I2400M_MEDIA_STATUS_LINK_UP = 1,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ I2400M_MEDIA_STATUS_LINK_UP = 1,
  I2400M_MEDIA_STATUS_LINK_DOWN,
  I2400M_MEDIA_STATUS_LINK_RENEW,
 };
-struct i2400m_tlv_media_status {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct i2400m_tlv_media_status {
  struct i2400m_tlv_hdr hdr;
  __le32 media_status;
 } __attribute__((packed));
-struct i2400m_tlv_config_idle_timeout {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct i2400m_tlv_config_idle_timeout {
  struct i2400m_tlv_hdr hdr;
  __le32 timeout;
 } __attribute__((packed));
-struct i2400m_tlv_config_d2h_data_format {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct i2400m_tlv_config_d2h_data_format {
  struct i2400m_tlv_hdr hdr;
  __u8 format;
  __u8 reserved[3];
-} __attribute__((packed));
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+} __attribute__((packed));
 struct i2400m_tlv_config_dl_host_reorder {
  struct i2400m_tlv_hdr hdr;
  __u8 reorder;
- __u8 reserved[3];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 reserved[3];
 } __attribute__((packed));
 #endif
diff --git a/libc/kernel/uapi/linux/xattr.h b/libc/kernel/uapi/linux/xattr.h
index c4d9c06..ecadc6a 100644
--- a/libc/kernel/uapi/linux/xattr.h
+++ b/libc/kernel/uapi/linux/xattr.h
@@ -26,44 +26,46 @@
 #define XATTR_MAC_OSX_PREFIX "osx."
 #define XATTR_MAC_OSX_PREFIX_LEN (sizeof(XATTR_MAC_OSX_PREFIX) - 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define XATTR_BTRFS_PREFIX "btrfs."
+#define XATTR_BTRFS_PREFIX_LEN (sizeof(XATTR_BTRFS_PREFIX) - 1)
 #define XATTR_SECURITY_PREFIX "security."
 #define XATTR_SECURITY_PREFIX_LEN (sizeof(XATTR_SECURITY_PREFIX) - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_SYSTEM_PREFIX "system."
 #define XATTR_SYSTEM_PREFIX_LEN (sizeof(XATTR_SYSTEM_PREFIX) - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_TRUSTED_PREFIX "trusted."
 #define XATTR_TRUSTED_PREFIX_LEN (sizeof(XATTR_TRUSTED_PREFIX) - 1)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_USER_PREFIX "user."
 #define XATTR_USER_PREFIX_LEN (sizeof(XATTR_USER_PREFIX) - 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_EVM_SUFFIX "evm"
 #define XATTR_NAME_EVM XATTR_SECURITY_PREFIX XATTR_EVM_SUFFIX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_IMA_SUFFIX "ima"
 #define XATTR_NAME_IMA XATTR_SECURITY_PREFIX XATTR_IMA_SUFFIX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_SELINUX_SUFFIX "selinux"
 #define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_SMACK_SUFFIX "SMACK64"
 #define XATTR_SMACK_IPIN "SMACK64IPIN"
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_SMACK_IPOUT "SMACK64IPOUT"
 #define XATTR_SMACK_EXEC "SMACK64EXEC"
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_SMACK_TRANSMUTE "SMACK64TRANSMUTE"
 #define XATTR_SMACK_MMAP "SMACK64MMAP"
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
 #define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
 #define XATTR_NAME_SMACKEXEC XATTR_SECURITY_PREFIX XATTR_SMACK_EXEC
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_NAME_SMACKTRANSMUTE XATTR_SECURITY_PREFIX XATTR_SMACK_TRANSMUTE
 #define XATTR_NAME_SMACKMMAP XATTR_SECURITY_PREFIX XATTR_SMACK_MMAP
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_CAPS_SUFFIX "capability"
 #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_POSIX_ACL_ACCESS "posix_acl_access"
 #define XATTR_NAME_POSIX_ACL_ACCESS XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_ACCESS
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/zorro.h b/libc/kernel/uapi/linux/zorro.h
new file mode 100644
index 0000000..219ef70
--- /dev/null
+++ b/libc/kernel/uapi/linux/zorro.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI_LINUX_ZORRO_H
+#define _UAPI_LINUX_ZORRO_H
+#include <linux/types.h>
+#define ZORRO_MANUF(id) ((id) >> 16)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD(id) (((id) >> 8) & 0xff)
+#define ZORRO_EPC(id) ((id) & 0xff)
+#define ZORRO_ID(manuf, prod, epc)   ((ZORRO_MANUF_##manuf << 16) | ((prod) << 8) | (epc))
+typedef __u32 zorro_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#include <linux/zorro_ids.h>
+#define GVP_PRODMASK (0xf8)
+#define GVP_SCSICLKMASK (0x01)
+enum GVP_flags {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ GVP_IO = 0x01,
+ GVP_ACCEL = 0x02,
+ GVP_SCSI = 0x04,
+ GVP_24BITDMA = 0x08,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ GVP_25BITDMA = 0x10,
+ GVP_NOBANK = 0x20,
+ GVP_14MHZ = 0x40,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct Node {
+ __be32 ln_Succ;
+ __be32 ln_Pred;
+ __u8 ln_Type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s8 ln_Pri;
+ __be32 ln_Name;
+} __packed;
+struct ExpansionRom {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 er_Type;
+ __u8 er_Product;
+ __u8 er_Flags;
+ __u8 er_Reserved03;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 er_Manufacturer;
+ __be32 er_SerialNumber;
+ __be16 er_InitDiagVec;
+ __u8 er_Reserved0c;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 er_Reserved0d;
+ __u8 er_Reserved0e;
+ __u8 er_Reserved0f;
+} __packed;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ERT_TYPEMASK 0xc0
+#define ERT_ZORROII 0xc0
+#define ERT_ZORROIII 0x80
+#define ERTB_MEMLIST 5
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ERTF_MEMLIST (1<<5)
+struct ConfigDev {
+ struct Node cd_Node;
+ __u8 cd_Flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 cd_Pad;
+ struct ExpansionRom cd_Rom;
+ __be32 cd_BoardAddr;
+ __be32 cd_BoardSize;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be16 cd_SlotAddr;
+ __be16 cd_SlotSize;
+ __be32 cd_Driver;
+ __be32 cd_NextCD;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __be32 cd_Unused[4];
+} __packed;
+#define ZORRO_NUM_AUTO 16
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/zorro_ids.h b/libc/kernel/uapi/linux/zorro_ids.h
new file mode 100644
index 0000000..eebf0b8
--- /dev/null
+++ b/libc/kernel/uapi/linux/zorro_ids.h
@@ -0,0 +1,553 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#define ZORRO_MANUF_PACIFIC_PERIPHERALS 0x00D3
+#define ZORRO_PROD_PACIFIC_PERIPHERALS_SE_2000_A500 ZORRO_ID(PACIFIC_PERIPHERALS, 0x00, 0)
+#define ZORRO_PROD_PACIFIC_PERIPHERALS_SCSI ZORRO_ID(PACIFIC_PERIPHERALS, 0x0A, 0)
+#define ZORRO_MANUF_MACROSYSTEMS_USA_2 0x0100
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MACROSYSTEMS_WARP_ENGINE ZORRO_ID(MACROSYSTEMS_USA_2, 0x13, 0)
+#define ZORRO_MANUF_KUPKE_1 0x00DD
+#define ZORRO_PROD_KUPKE_GOLEM_RAM_BOX_2MB ZORRO_ID(KUPKE_1, 0x00, 0)
+#define ZORRO_MANUF_MEMPHIS 0x0100
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MEMPHIS_STORMBRINGER ZORRO_ID(MEMPHIS, 0x00, 0)
+#define ZORRO_MANUF_3_STATE 0x0200
+#define ZORRO_PROD_3_STATE_MEGAMIX_2000 ZORRO_ID(3_STATE, 0x02, 0)
+#define ZORRO_MANUF_COMMODORE_BRAUNSCHWEIG 0x0201
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CBM_A2088_A2286 ZORRO_ID(COMMODORE_BRAUNSCHWEIG, 0x01, 0)
+#define ZORRO_PROD_CBM_A2286 ZORRO_ID(COMMODORE_BRAUNSCHWEIG, 0x02, 0)
+#define ZORRO_PROD_CBM_A4091_1 ZORRO_ID(COMMODORE_BRAUNSCHWEIG, 0x54, 0)
+#define ZORRO_PROD_CBM_A2386SX_1 ZORRO_ID(COMMODORE_BRAUNSCHWEIG, 0x67, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_COMMODORE_WEST_CHESTER_1 0x0202
+#define ZORRO_PROD_CBM_A2090A ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x01, 0)
+#define ZORRO_PROD_CBM_A590_A2091_1 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x02, 0)
+#define ZORRO_PROD_CBM_A590_A2091_2 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x03, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CBM_A2090B ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x04, 0)
+#define ZORRO_PROD_CBM_A2060 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x09, 0)
+#define ZORRO_PROD_CBM_A590_A2052_A2058_A2091 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x0A, 0)
+#define ZORRO_PROD_CBM_A560_RAM ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x20, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CBM_A2232_PROTOTYPE ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x45, 0)
+#define ZORRO_PROD_CBM_A2232 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x46, 0)
+#define ZORRO_PROD_CBM_A2620 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x50, 0)
+#define ZORRO_PROD_CBM_A2630 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x51, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CBM_A4091_2 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x54, 0)
+#define ZORRO_PROD_CBM_A2065_1 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x5A, 0)
+#define ZORRO_PROD_CBM_ROMULATOR ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x60, 0)
+#define ZORRO_PROD_CBM_A3000_TEST_FIXTURE ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x61, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CBM_A2386SX_2 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x67, 0)
+#define ZORRO_PROD_CBM_A2065_2 ZORRO_ID(COMMODORE_WEST_CHESTER_1, 0x70, 0)
+#define ZORRO_MANUF_COMMODORE_WEST_CHESTER_2 0x0203
+#define ZORRO_PROD_CBM_A2090A_CM ZORRO_ID(COMMODORE_WEST_CHESTER_2, 0x03, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_PROGRESSIVE_PERIPHERALS_AND_SYSTEMS_2 0x02F4
+#define ZORRO_PROD_PPS_EXP8000 ZORRO_ID(PROGRESSIVE_PERIPHERALS_AND_SYSTEMS_2, 0x02, 0)
+#define ZORRO_MANUF_KOLFF_COMPUTER_SUPPLIES 0x02FF
+#define ZORRO_PROD_KCS_POWER_PC_BOARD ZORRO_ID(KOLFF_COMPUTER_SUPPLIES, 0x00, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_CARDCO_1 0x03EC
+#define ZORRO_PROD_CARDCO_KRONOS_2000_1 ZORRO_ID(CARDCO_1, 0x04, 0)
+#define ZORRO_PROD_CARDCO_A1000_1 ZORRO_ID(CARDCO_1, 0x0C, 0)
+#define ZORRO_PROD_CARDCO_ESCORT ZORRO_ID(CARDCO_1, 0x0E, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CARDCO_A2410 ZORRO_ID(CARDCO_1, 0xF5, 0)
+#define ZORRO_MANUF_A_SQUARED 0x03ED
+#define ZORRO_PROD_A_SQUARED_LIVE_2000 ZORRO_ID(A_SQUARED, 0x01, 0)
+#define ZORRO_MANUF_COMSPEC_COMMUNICATIONS 0x03EE
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_COMSPEC_COMMUNICATIONS_AX2000 ZORRO_ID(COMSPEC_COMMUNICATIONS, 0x01, 0)
+#define ZORRO_MANUF_ANAKIN_RESEARCH 0x03F1
+#define ZORRO_PROD_ANAKIN_RESEARCH_EASYL ZORRO_ID(ANAKIN_RESEARCH, 0x01, 0)
+#define ZORRO_MANUF_MICROBOTICS 0x03F2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MICROBOTICS_STARBOARD_II ZORRO_ID(MICROBOTICS, 0x00, 0)
+#define ZORRO_PROD_MICROBOTICS_STARDRIVE ZORRO_ID(MICROBOTICS, 0x02, 0)
+#define ZORRO_PROD_MICROBOTICS_8_UP_A ZORRO_ID(MICROBOTICS, 0x03, 0)
+#define ZORRO_PROD_MICROBOTICS_8_UP_Z ZORRO_ID(MICROBOTICS, 0x04, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MICROBOTICS_DELTA_RAM ZORRO_ID(MICROBOTICS, 0x20, 0)
+#define ZORRO_PROD_MICROBOTICS_8_STAR_RAM ZORRO_ID(MICROBOTICS, 0x40, 0)
+#define ZORRO_PROD_MICROBOTICS_8_STAR ZORRO_ID(MICROBOTICS, 0x41, 0)
+#define ZORRO_PROD_MICROBOTICS_VXL_RAM_32 ZORRO_ID(MICROBOTICS, 0x44, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MICROBOTICS_VXL_68030 ZORRO_ID(MICROBOTICS, 0x45, 0)
+#define ZORRO_PROD_MICROBOTICS_DELTA ZORRO_ID(MICROBOTICS, 0x60, 0)
+#define ZORRO_PROD_MICROBOTICS_MBX_1200_1200Z_RAM ZORRO_ID(MICROBOTICS, 0x81, 0)
+#define ZORRO_PROD_MICROBOTICS_HARDFRAME_2000_1 ZORRO_ID(MICROBOTICS, 0x96, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MICROBOTICS_HARDFRAME_2000_2 ZORRO_ID(MICROBOTICS, 0x9E, 0)
+#define ZORRO_PROD_MICROBOTICS_MBX_1200_1200Z ZORRO_ID(MICROBOTICS, 0xC1, 0)
+#define ZORRO_MANUF_ACCESS_ASSOCIATES_ALEGRA 0x03F4
+#define ZORRO_MANUF_EXPANSION_TECHNOLOGIES 0x03F6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_ASDG 0x03FF
+#define ZORRO_PROD_ASDG_MEMORY_1 ZORRO_ID(ASDG, 0x01, 0)
+#define ZORRO_PROD_ASDG_MEMORY_2 ZORRO_ID(ASDG, 0x02, 0)
+#define ZORRO_PROD_ASDG_EB920_LAN_ROVER ZORRO_ID(ASDG, 0xFE, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_ASDG_GPIB_DUALIEEE488_TWIN_X ZORRO_ID(ASDG, 0xFF, 0)
+#define ZORRO_MANUF_IMTRONICS_1 0x0404
+#define ZORRO_PROD_IMTRONICS_HURRICANE_2800_1 ZORRO_ID(IMTRONICS_1, 0x39, 0)
+#define ZORRO_PROD_IMTRONICS_HURRICANE_2800_2 ZORRO_ID(IMTRONICS_1, 0x57, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_CBM_UNIVERSITY_OF_LOWELL 0x0406
+#define ZORRO_PROD_CBM_A2410 ZORRO_ID(CBM_UNIVERSITY_OF_LOWELL, 0x00, 0)
+#define ZORRO_MANUF_AMERISTAR 0x041D
+#define ZORRO_PROD_AMERISTAR_A2065 ZORRO_ID(AMERISTAR, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_AMERISTAR_A560 ZORRO_ID(AMERISTAR, 0x09, 0)
+#define ZORRO_PROD_AMERISTAR_A4066 ZORRO_ID(AMERISTAR, 0x0A, 0)
+#define ZORRO_MANUF_SUPRA 0x0420
+#define ZORRO_PROD_SUPRA_SUPRADRIVE_4x4 ZORRO_ID(SUPRA, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_SUPRA_1000_RAM ZORRO_ID(SUPRA, 0x02, 0)
+#define ZORRO_PROD_SUPRA_2000_DMA ZORRO_ID(SUPRA, 0x03, 0)
+#define ZORRO_PROD_SUPRA_500 ZORRO_ID(SUPRA, 0x05, 0)
+#define ZORRO_PROD_SUPRA_500_SCSI ZORRO_ID(SUPRA, 0x08, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_SUPRA_500XP_2000_RAM ZORRO_ID(SUPRA, 0x09, 0)
+#define ZORRO_PROD_SUPRA_500RX_2000_RAM ZORRO_ID(SUPRA, 0x0A, 0)
+#define ZORRO_PROD_SUPRA_2400ZI ZORRO_ID(SUPRA, 0x0B, 0)
+#define ZORRO_PROD_SUPRA_500XP_SUPRADRIVE_WORDSYNC ZORRO_ID(SUPRA, 0x0C, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_SUPRA_SUPRADRIVE_WORDSYNC_II ZORRO_ID(SUPRA, 0x0D, 0)
+#define ZORRO_PROD_SUPRA_2400ZIPLUS ZORRO_ID(SUPRA, 0x10, 0)
+#define ZORRO_MANUF_COMPUTER_SYSTEMS_ASSOCIATES 0x0422
+#define ZORRO_PROD_CSA_MAGNUM ZORRO_ID(COMPUTER_SYSTEMS_ASSOCIATES, 0x11, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CSA_12_GAUGE ZORRO_ID(COMPUTER_SYSTEMS_ASSOCIATES, 0x15, 0)
+#define ZORRO_MANUF_MARC_MICHAEL_GROTH 0x0439
+#define ZORRO_MANUF_M_TECH 0x0502
+#define ZORRO_PROD_MTEC_AT500_1 ZORRO_ID(M_TECH, 0x03, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_GREAT_VALLEY_PRODUCTS_1 0x06E1
+#define ZORRO_PROD_GVP_IMPACT_SERIES_I ZORRO_ID(GREAT_VALLEY_PRODUCTS_1, 0x08, 0)
+#define ZORRO_MANUF_BYTEBOX 0x07DA
+#define ZORRO_PROD_BYTEBOX_A500 ZORRO_ID(BYTEBOX, 0x00, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_DKB_POWER_COMPUTING 0x07DC
+#define ZORRO_PROD_DKB_POWER_COMPUTING_SECUREKEY ZORRO_ID(DKB_POWER_COMPUTING, 0x09, 0)
+#define ZORRO_PROD_DKB_POWER_COMPUTING_DKM_3128 ZORRO_ID(DKB_POWER_COMPUTING, 0x0E, 0)
+#define ZORRO_PROD_DKB_POWER_COMPUTING_RAPID_FIRE ZORRO_ID(DKB_POWER_COMPUTING, 0x0F, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_DKB_POWER_COMPUTING_DKM_1202 ZORRO_ID(DKB_POWER_COMPUTING, 0x10, 0)
+#define ZORRO_PROD_DKB_POWER_COMPUTING_COBRA_VIPER_II_68EC030 ZORRO_ID(DKB_POWER_COMPUTING, 0x12, 0)
+#define ZORRO_PROD_DKB_POWER_COMPUTING_WILDFIRE_060_1 ZORRO_ID(DKB_POWER_COMPUTING, 0x17, 0)
+#define ZORRO_PROD_DKB_POWER_COMPUTING_WILDFIRE_060_2 ZORRO_ID(DKB_POWER_COMPUTING, 0xFF, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_GREAT_VALLEY_PRODUCTS_2 0x07E1
+#define ZORRO_PROD_GVP_IMPACT_SERIES_I_4K ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x01, 0)
+#define ZORRO_PROD_GVP_IMPACT_SERIES_I_16K_2 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x02, 0)
+#define ZORRO_PROD_GVP_IMPACT_SERIES_I_16K_3 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x03, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GVP_IMPACT_3001_IDE_1 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x08, 0)
+#define ZORRO_PROD_GVP_IMPACT_3001_RAM ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x09, 0)
+#define ZORRO_PROD_GVP_IMPACT_SERIES_II_RAM_1 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0A, 0)
+#define ZORRO_PROD_GVP_EPC_BASE ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GVP_GFORCE_040_1 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0x20)
+#define ZORRO_PROD_GVP_GFORCE_040_SCSI_1 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0x30)
+#define ZORRO_PROD_GVP_A1291 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0x40)
+#define ZORRO_PROD_GVP_COMBO_030_R4 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0x60)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GVP_COMBO_030_R4_SCSI ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0x70)
+#define ZORRO_PROD_GVP_PHONEPAK ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0x78)
+#define ZORRO_PROD_GVP_IO_EXTENDER ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0x98)
+#define ZORRO_PROD_GVP_GFORCE_030 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0xa0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GVP_GFORCE_030_SCSI ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0xb0)
+#define ZORRO_PROD_GVP_A530 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0xc0)
+#define ZORRO_PROD_GVP_A530_SCSI ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0xd0)
+#define ZORRO_PROD_GVP_COMBO_030_R3 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0xe0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GVP_COMBO_030_R3_SCSI ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0xf0)
+#define ZORRO_PROD_GVP_SERIES_II ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0B, 0xf8)
+#define ZORRO_PROD_GVP_IMPACT_3001_IDE_2 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x0D, 0)
+#define ZORRO_PROD_GVP_GFORCE_040_060 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x16, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GVP_IMPACT_VISION_24 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0x20, 0)
+#define ZORRO_PROD_GVP_GFORCE_040_2 ZORRO_ID(GREAT_VALLEY_PRODUCTS_2, 0xFF, 0)
+#define ZORRO_MANUF_CALIFORNIA_ACCESS_SYNERGY 0x07E5
+#define ZORRO_PROD_CALIFORNIA_ACCESS_SYNERGY_MALIBU ZORRO_ID(CALIFORNIA_ACCESS_SYNERGY, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_XETEC 0x07E6
+#define ZORRO_PROD_XETEC_FASTCARD ZORRO_ID(XETEC, 0x01, 0)
+#define ZORRO_PROD_XETEC_FASTCARD_RAM ZORRO_ID(XETEC, 0x02, 0)
+#define ZORRO_PROD_XETEC_FASTCARD_PLUS ZORRO_ID(XETEC, 0x03, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_PROGRESSIVE_PERIPHERALS_AND_SYSTEMS 0x07EA
+#define ZORRO_PROD_PPS_MERCURY ZORRO_ID(PROGRESSIVE_PERIPHERALS_AND_SYSTEMS, 0x00, 0)
+#define ZORRO_PROD_PPS_A3000_68040 ZORRO_ID(PROGRESSIVE_PERIPHERALS_AND_SYSTEMS, 0x01, 0)
+#define ZORRO_PROD_PPS_A2000_68040 ZORRO_ID(PROGRESSIVE_PERIPHERALS_AND_SYSTEMS, 0x69, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_PPS_ZEUS ZORRO_ID(PROGRESSIVE_PERIPHERALS_AND_SYSTEMS, 0x96, 0)
+#define ZORRO_PROD_PPS_A500_68040 ZORRO_ID(PROGRESSIVE_PERIPHERALS_AND_SYSTEMS, 0xBB, 0)
+#define ZORRO_MANUF_XEBEC 0x07EC
+#define ZORRO_MANUF_SPIRIT_TECHNOLOGY 0x07F2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_SPIRIT_TECHNOLOGY_INSIDER_IN1000 ZORRO_ID(SPIRIT_TECHNOLOGY, 0x01, 0)
+#define ZORRO_PROD_SPIRIT_TECHNOLOGY_INSIDER_IN500 ZORRO_ID(SPIRIT_TECHNOLOGY, 0x02, 0)
+#define ZORRO_PROD_SPIRIT_TECHNOLOGY_SIN500 ZORRO_ID(SPIRIT_TECHNOLOGY, 0x03, 0)
+#define ZORRO_PROD_SPIRIT_TECHNOLOGY_HDA_506 ZORRO_ID(SPIRIT_TECHNOLOGY, 0x04, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_SPIRIT_TECHNOLOGY_AX_S ZORRO_ID(SPIRIT_TECHNOLOGY, 0x05, 0)
+#define ZORRO_PROD_SPIRIT_TECHNOLOGY_OCTABYTE ZORRO_ID(SPIRIT_TECHNOLOGY, 0x06, 0)
+#define ZORRO_PROD_SPIRIT_TECHNOLOGY_INMATE ZORRO_ID(SPIRIT_TECHNOLOGY, 0x08, 0)
+#define ZORRO_MANUF_SPIRIT_TECHNOLOGY_2 0x07F3
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_BSC_ALFADATA_1 0x07FE
+#define ZORRO_PROD_BSC_ALF_3_1 ZORRO_ID(BSC_ALFADATA_1, 0x03, 0)
+#define ZORRO_MANUF_BSC_ALFADATA_2 0x0801
+#define ZORRO_PROD_BSC_ALF_2_1 ZORRO_ID(BSC_ALFADATA_2, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_BSC_ALF_2_2 ZORRO_ID(BSC_ALFADATA_2, 0x02, 0)
+#define ZORRO_PROD_BSC_ALF_3_2 ZORRO_ID(BSC_ALFADATA_2, 0x03, 0)
+#define ZORRO_MANUF_CARDCO_2 0x0802
+#define ZORRO_PROD_CARDCO_KRONOS_2000_2 ZORRO_ID(CARDCO_2, 0x04, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CARDCO_A1000_2 ZORRO_ID(CARDCO_2, 0x0C, 0)
+#define ZORRO_MANUF_JOCHHEIM 0x0804
+#define ZORRO_PROD_JOCHHEIM_RAM ZORRO_ID(JOCHHEIM, 0x01, 0)
+#define ZORRO_MANUF_CHECKPOINT_TECHNOLOGIES 0x0807
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_CHECKPOINT_TECHNOLOGIES_SERIAL_SOLUTION ZORRO_ID(CHECKPOINT_TECHNOLOGIES, 0x00, 0)
+#define ZORRO_MANUF_EDOTRONIK 0x0810
+#define ZORRO_PROD_EDOTRONIK_IEEE_488 ZORRO_ID(EDOTRONIK, 0x01, 0)
+#define ZORRO_PROD_EDOTRONIK_8032 ZORRO_ID(EDOTRONIK, 0x02, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_EDOTRONIK_MULTISERIAL ZORRO_ID(EDOTRONIK, 0x03, 0)
+#define ZORRO_PROD_EDOTRONIK_VIDEODIGITIZER ZORRO_ID(EDOTRONIK, 0x04, 0)
+#define ZORRO_PROD_EDOTRONIK_PARALLEL_IO ZORRO_ID(EDOTRONIK, 0x05, 0)
+#define ZORRO_PROD_EDOTRONIK_PIC_PROTOYPING ZORRO_ID(EDOTRONIK, 0x06, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_EDOTRONIK_ADC ZORRO_ID(EDOTRONIK, 0x07, 0)
+#define ZORRO_PROD_EDOTRONIK_VME ZORRO_ID(EDOTRONIK, 0x08, 0)
+#define ZORRO_PROD_EDOTRONIK_DSP96000 ZORRO_ID(EDOTRONIK, 0x09, 0)
+#define ZORRO_MANUF_NES_INC 0x0813
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_NES_INC_RAM ZORRO_ID(NES_INC, 0x00, 0)
+#define ZORRO_MANUF_ICD 0x0817
+#define ZORRO_PROD_ICD_ADVANTAGE_2000_SCSI ZORRO_ID(ICD, 0x01, 0)
+#define ZORRO_PROD_ICD_ADVANTAGE_IDE ZORRO_ID(ICD, 0x03, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_ICD_ADVANTAGE_2080_RAM ZORRO_ID(ICD, 0x04, 0)
+#define ZORRO_MANUF_KUPKE_2 0x0819
+#define ZORRO_PROD_KUPKE_OMTI ZORRO_ID(KUPKE_2, 0x01, 0)
+#define ZORRO_PROD_KUPKE_SCSI_II ZORRO_ID(KUPKE_2, 0x02, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_KUPKE_GOLEM_BOX ZORRO_ID(KUPKE_2, 0x03, 0)
+#define ZORRO_PROD_KUPKE_030_882 ZORRO_ID(KUPKE_2, 0x04, 0)
+#define ZORRO_PROD_KUPKE_SCSI_AT ZORRO_ID(KUPKE_2, 0x05, 0)
+#define ZORRO_MANUF_GREAT_VALLEY_PRODUCTS_3 0x081D
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GVP_A2000_RAM8 ZORRO_ID(GREAT_VALLEY_PRODUCTS_3, 0x09, 0)
+#define ZORRO_PROD_GVP_IMPACT_SERIES_II_RAM_2 ZORRO_ID(GREAT_VALLEY_PRODUCTS_3, 0x0A, 0)
+#define ZORRO_MANUF_INTERWORKS_NETWORK 0x081E
+#define ZORRO_MANUF_HARDITAL_SYNTHESIS 0x0820
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_HARDITAL_SYNTHESIS_TQM_68030_68882 ZORRO_ID(HARDITAL_SYNTHESIS, 0x14, 0)
+#define ZORRO_MANUF_APPLIED_ENGINEERING 0x0828
+#define ZORRO_PROD_APPLIED_ENGINEERING_DL2000 ZORRO_ID(APPLIED_ENGINEERING, 0x10, 0)
+#define ZORRO_PROD_APPLIED_ENGINEERING_RAM_WORKS ZORRO_ID(APPLIED_ENGINEERING, 0xE0, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_BSC_ALFADATA_3 0x082C
+#define ZORRO_PROD_BSC_OKTAGON_2008 ZORRO_ID(BSC_ALFADATA_3, 0x05, 0)
+#define ZORRO_PROD_BSC_TANDEM_AT_2008_508 ZORRO_ID(BSC_ALFADATA_3, 0x06, 0)
+#define ZORRO_PROD_BSC_ALFA_RAM_1200 ZORRO_ID(BSC_ALFADATA_3, 0x07, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_BSC_OKTAGON_2008_RAM ZORRO_ID(BSC_ALFADATA_3, 0x08, 0)
+#define ZORRO_PROD_BSC_MULTIFACE_I ZORRO_ID(BSC_ALFADATA_3, 0x10, 0)
+#define ZORRO_PROD_BSC_MULTIFACE_II ZORRO_ID(BSC_ALFADATA_3, 0x11, 0)
+#define ZORRO_PROD_BSC_MULTIFACE_III ZORRO_ID(BSC_ALFADATA_3, 0x12, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_BSC_FRAMEMASTER_II ZORRO_ID(BSC_ALFADATA_3, 0x20, 0)
+#define ZORRO_PROD_BSC_GRAFFITI_RAM ZORRO_ID(BSC_ALFADATA_3, 0x21, 0)
+#define ZORRO_PROD_BSC_GRAFFITI_REG ZORRO_ID(BSC_ALFADATA_3, 0x22, 0)
+#define ZORRO_PROD_BSC_ISDN_MASTERCARD ZORRO_ID(BSC_ALFADATA_3, 0x40, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_BSC_ISDN_MASTERCARD_II ZORRO_ID(BSC_ALFADATA_3, 0x41, 0)
+#define ZORRO_MANUF_PHOENIX 0x0835
+#define ZORRO_PROD_PHOENIX_ST506 ZORRO_ID(PHOENIX, 0x21, 0)
+#define ZORRO_PROD_PHOENIX_SCSI ZORRO_ID(PHOENIX, 0x22, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_PHOENIX_RAM ZORRO_ID(PHOENIX, 0xBE, 0)
+#define ZORRO_MANUF_ADVANCED_STORAGE_SYSTEMS 0x0836
+#define ZORRO_PROD_ADVANCED_STORAGE_SYSTEMS_NEXUS ZORRO_ID(ADVANCED_STORAGE_SYSTEMS, 0x01, 0)
+#define ZORRO_PROD_ADVANCED_STORAGE_SYSTEMS_NEXUS_RAM ZORRO_ID(ADVANCED_STORAGE_SYSTEMS, 0x08, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_IMPULSE 0x0838
+#define ZORRO_PROD_IMPULSE_FIRECRACKER_24 ZORRO_ID(IMPULSE, 0x00, 0)
+#define ZORRO_MANUF_IVS 0x0840
+#define ZORRO_PROD_IVS_GRANDSLAM_PIC_2 ZORRO_ID(IVS, 0x02, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_IVS_GRANDSLAM_PIC_1 ZORRO_ID(IVS, 0x04, 0)
+#define ZORRO_PROD_IVS_OVERDRIVE ZORRO_ID(IVS, 0x10, 0)
+#define ZORRO_PROD_IVS_TRUMPCARD_CLASSIC ZORRO_ID(IVS, 0x30, 0)
+#define ZORRO_PROD_IVS_TRUMPCARD_PRO_GRANDSLAM ZORRO_ID(IVS, 0x34, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_IVS_META_4 ZORRO_ID(IVS, 0x40, 0)
+#define ZORRO_PROD_IVS_WAVETOOLS ZORRO_ID(IVS, 0xBF, 0)
+#define ZORRO_PROD_IVS_VECTOR_1 ZORRO_ID(IVS, 0xF3, 0)
+#define ZORRO_PROD_IVS_VECTOR_2 ZORRO_ID(IVS, 0xF4, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_VECTOR_1 0x0841
+#define ZORRO_PROD_VECTOR_CONNECTION_1 ZORRO_ID(VECTOR_1, 0xE3, 0)
+#define ZORRO_MANUF_XPERT_PRODEV 0x0845
+#define ZORRO_PROD_XPERT_PRODEV_VISIONA_RAM ZORRO_ID(XPERT_PRODEV, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_XPERT_PRODEV_VISIONA_REG ZORRO_ID(XPERT_PRODEV, 0x02, 0)
+#define ZORRO_PROD_XPERT_PRODEV_MERLIN_RAM ZORRO_ID(XPERT_PRODEV, 0x03, 0)
+#define ZORRO_PROD_XPERT_PRODEV_MERLIN_REG_1 ZORRO_ID(XPERT_PRODEV, 0x04, 0)
+#define ZORRO_PROD_XPERT_PRODEV_MERLIN_REG_2 ZORRO_ID(XPERT_PRODEV, 0xC9, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_HYDRA_SYSTEMS 0x0849
+#define ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET ZORRO_ID(HYDRA_SYSTEMS, 0x01, 0)
+#define ZORRO_MANUF_SUNRIZE_INDUSTRIES 0x084F
+#define ZORRO_PROD_SUNRIZE_INDUSTRIES_AD1012 ZORRO_ID(SUNRIZE_INDUSTRIES, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_SUNRIZE_INDUSTRIES_AD516 ZORRO_ID(SUNRIZE_INDUSTRIES, 0x02, 0)
+#define ZORRO_PROD_SUNRIZE_INDUSTRIES_DD512 ZORRO_ID(SUNRIZE_INDUSTRIES, 0x03, 0)
+#define ZORRO_MANUF_TRICERATOPS 0x0850
+#define ZORRO_PROD_TRICERATOPS_MULTI_IO ZORRO_ID(TRICERATOPS, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_APPLIED_MAGIC 0x0851
+#define ZORRO_PROD_APPLIED_MAGIC_DMI_RESOLVER ZORRO_ID(APPLIED_MAGIC, 0x01, 0)
+#define ZORRO_PROD_APPLIED_MAGIC_DIGITAL_BROADCASTER ZORRO_ID(APPLIED_MAGIC, 0x06, 0)
+#define ZORRO_MANUF_GFX_BASE 0x085E
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GFX_BASE_GDA_1_VRAM ZORRO_ID(GFX_BASE, 0x00, 0)
+#define ZORRO_PROD_GFX_BASE_GDA_1 ZORRO_ID(GFX_BASE, 0x01, 0)
+#define ZORRO_MANUF_ROCTEC 0x0860
+#define ZORRO_PROD_ROCTEC_RH_800C ZORRO_ID(ROCTEC, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_ROCTEC_RH_800C_RAM ZORRO_ID(ROCTEC, 0x01, 0)
+#define ZORRO_MANUF_KATO 0x0861
+#define ZORRO_PROD_KATO_MELODY ZORRO_ID(KATO, 0x80, 0)
+#define ZORRO_MANUF_HELFRICH_1 0x0861
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_HELFRICH_RAINBOW_II ZORRO_ID(HELFRICH_1, 0x20, 0)
+#define ZORRO_PROD_HELFRICH_RAINBOW_III ZORRO_ID(HELFRICH_1, 0x21, 0)
+#define ZORRO_MANUF_ATLANTIS 0x0862
+#define ZORRO_MANUF_PROTAR 0x0864
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_ACS 0x0865
+#define ZORRO_MANUF_SOFTWARE_RESULTS_ENTERPRISES 0x0866
+#define ZORRO_PROD_SOFTWARE_RESULTS_ENTERPRISES_GOLDEN_GATE_2_BUS_PLUS ZORRO_ID(SOFTWARE_RESULTS_ENTERPRISES, 0x01, 0)
+#define ZORRO_MANUF_MASOBOSHI 0x086D
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MASOBOSHI_MASTER_CARD_SC201 ZORRO_ID(MASOBOSHI, 0x03, 0)
+#define ZORRO_PROD_MASOBOSHI_MASTER_CARD_MC702 ZORRO_ID(MASOBOSHI, 0x04, 0)
+#define ZORRO_PROD_MASOBOSHI_MVD_819 ZORRO_ID(MASOBOSHI, 0x07, 0)
+#define ZORRO_MANUF_MAINHATTAN_DATA 0x086F
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MAINHATTAN_DATA_IDE ZORRO_ID(MAINHATTAN_DATA, 0x01, 0)
+#define ZORRO_MANUF_VILLAGE_TRONIC 0x0877
+#define ZORRO_PROD_VILLAGE_TRONIC_DOMINO_RAM ZORRO_ID(VILLAGE_TRONIC, 0x01, 0)
+#define ZORRO_PROD_VILLAGE_TRONIC_DOMINO_REG ZORRO_ID(VILLAGE_TRONIC, 0x02, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_VILLAGE_TRONIC_DOMINO_16M_PROTOTYPE ZORRO_ID(VILLAGE_TRONIC, 0x03, 0)
+#define ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_RAM ZORRO_ID(VILLAGE_TRONIC, 0x0B, 0)
+#define ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_REG ZORRO_ID(VILLAGE_TRONIC, 0x0C, 0)
+#define ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_SEGMENTED_MODE ZORRO_ID(VILLAGE_TRONIC, 0x0D, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_RAM1 ZORRO_ID(VILLAGE_TRONIC, 0x15, 0)
+#define ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_RAM2 ZORRO_ID(VILLAGE_TRONIC, 0x16, 0)
+#define ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_REG ZORRO_ID(VILLAGE_TRONIC, 0x17, 0)
+#define ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z3 ZORRO_ID(VILLAGE_TRONIC, 0x18, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_VILLAGE_TRONIC_ARIADNE ZORRO_ID(VILLAGE_TRONIC, 0xC9, 0)
+#define ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2 ZORRO_ID(VILLAGE_TRONIC, 0xCA, 0)
+#define ZORRO_MANUF_UTILITIES_UNLIMITED 0x087B
+#define ZORRO_PROD_UTILITIES_UNLIMITED_EMPLANT_DELUXE ZORRO_ID(UTILITIES_UNLIMITED, 0x15, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_UTILITIES_UNLIMITED_EMPLANT_DELUXE2 ZORRO_ID(UTILITIES_UNLIMITED, 0x20, 0)
+#define ZORRO_MANUF_AMITRIX 0x0880
+#define ZORRO_PROD_AMITRIX_MULTI_IO ZORRO_ID(AMITRIX, 0x01, 0)
+#define ZORRO_PROD_AMITRIX_CD_RAM ZORRO_ID(AMITRIX, 0x02, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_ARMAX 0x0885
+#define ZORRO_PROD_ARMAX_OMNIBUS ZORRO_ID(ARMAX, 0x00, 0)
+#define ZORRO_MANUF_ZEUS 0x088D
+#define ZORRO_PROD_ZEUS_SPIDER ZORRO_ID(ZEUS, 0x04, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_NEWTEK 0x088F
+#define ZORRO_PROD_NEWTEK_VIDEOTOASTER ZORRO_ID(NEWTEK, 0x00, 0)
+#define ZORRO_MANUF_M_TECH_GERMANY 0x0890
+#define ZORRO_PROD_MTEC_AT500_2 ZORRO_ID(M_TECH_GERMANY, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MTEC_68030 ZORRO_ID(M_TECH_GERMANY, 0x03, 0)
+#define ZORRO_PROD_MTEC_68020I ZORRO_ID(M_TECH_GERMANY, 0x06, 0)
+#define ZORRO_PROD_MTEC_A1200_T68030_RTC ZORRO_ID(M_TECH_GERMANY, 0x20, 0)
+#define ZORRO_PROD_MTEC_VIPER_MK_V_E_MATRIX_530 ZORRO_ID(M_TECH_GERMANY, 0x21, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MTEC_8_MB_RAM ZORRO_ID(M_TECH_GERMANY, 0x22, 0)
+#define ZORRO_PROD_MTEC_VIPER_MK_V_E_MATRIX_530_SCSI_IDE ZORRO_ID(M_TECH_GERMANY, 0x24, 0)
+#define ZORRO_MANUF_GREAT_VALLEY_PRODUCTS_4 0x0891
+#define ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_RAM ZORRO_ID(GREAT_VALLEY_PRODUCTS_4, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_REG ZORRO_ID(GREAT_VALLEY_PRODUCTS_4, 0x02, 0)
+#define ZORRO_MANUF_APOLLO_1 0x0892
+#define ZORRO_PROD_APOLLO_A1200 ZORRO_ID(APOLLO_1, 0x01, 0)
+#define ZORRO_MANUF_HELFRICH_2 0x0893
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_HELFRICH_PICCOLO_RAM ZORRO_ID(HELFRICH_2, 0x05, 0)
+#define ZORRO_PROD_HELFRICH_PICCOLO_REG ZORRO_ID(HELFRICH_2, 0x06, 0)
+#define ZORRO_PROD_HELFRICH_PEGGY_PLUS_MPEG ZORRO_ID(HELFRICH_2, 0x07, 0)
+#define ZORRO_PROD_HELFRICH_VIDEOCRUNCHER ZORRO_ID(HELFRICH_2, 0x08, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_HELFRICH_SD64_RAM ZORRO_ID(HELFRICH_2, 0x0A, 0)
+#define ZORRO_PROD_HELFRICH_SD64_REG ZORRO_ID(HELFRICH_2, 0x0B, 0)
+#define ZORRO_MANUF_MACROSYSTEMS_USA 0x089B
+#define ZORRO_PROD_MACROSYSTEMS_WARP_ENGINE_40xx ZORRO_ID(MACROSYSTEMS_USA, 0x13, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_ELBOX_COMPUTER 0x089E
+#define ZORRO_PROD_ELBOX_COMPUTER_1200_4 ZORRO_ID(ELBOX_COMPUTER, 0x06, 0)
+#define ZORRO_MANUF_HARMS_PROFESSIONAL 0x0A00
+#define ZORRO_PROD_HARMS_PROFESSIONAL_030_PLUS ZORRO_ID(HARMS_PROFESSIONAL, 0x10, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_HARMS_PROFESSIONAL_3500 ZORRO_ID(HARMS_PROFESSIONAL, 0xD0, 0)
+#define ZORRO_MANUF_MICRONIK 0x0A50
+#define ZORRO_PROD_MICRONIK_RCA_120 ZORRO_ID(MICRONIK, 0x0A, 0)
+#define ZORRO_MANUF_MICRONIK2 0x0F0F
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MICRONIK2_Z3I ZORRO_ID(MICRONIK2, 0x01, 0)
+#define ZORRO_MANUF_MEGAMICRO 0x1000
+#define ZORRO_PROD_MEGAMICRO_SCRAM_500 ZORRO_ID(MEGAMICRO, 0x03, 0)
+#define ZORRO_PROD_MEGAMICRO_SCRAM_500_RAM ZORRO_ID(MEGAMICRO, 0x04, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_IMTRONICS_2 0x1028
+#define ZORRO_PROD_IMTRONICS_HURRICANE_2800_3 ZORRO_ID(IMTRONICS_2, 0x39, 0)
+#define ZORRO_PROD_IMTRONICS_HURRICANE_2800_4 ZORRO_ID(IMTRONICS_2, 0x57, 0)
+#define ZORRO_MANUF_INDIVIDUAL_COMPUTERS 0x1212
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA ZORRO_ID(INDIVIDUAL_COMPUTERS, 0x00, 0)
+#define ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF ZORRO_ID(INDIVIDUAL_COMPUTERS, 0x17, 0)
+#define ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL ZORRO_ID(INDIVIDUAL_COMPUTERS, 0x2A, 0)
+#define ZORRO_MANUF_KUPKE_3 0x1248
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_KUPKE_GOLEM_HD_3000 ZORRO_ID(KUPKE_3, 0x01, 0)
+#define ZORRO_MANUF_ITH 0x1388
+#define ZORRO_PROD_ITH_ISDN_MASTER_II ZORRO_ID(ITH, 0x01, 0)
+#define ZORRO_MANUF_VMC 0x1389
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_VMC_ISDN_BLASTER_Z2 ZORRO_ID(VMC, 0x01, 0)
+#define ZORRO_PROD_VMC_HYPERCOM_4 ZORRO_ID(VMC, 0x02, 0)
+#define ZORRO_MANUF_INFORMATION 0x157C
+#define ZORRO_PROD_INFORMATION_ISDN_ENGINE_I ZORRO_ID(INFORMATION, 0x64, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_VORTEX 0x2017
+#define ZORRO_PROD_VORTEX_GOLDEN_GATE_80386SX ZORRO_ID(VORTEX, 0x07, 0)
+#define ZORRO_PROD_VORTEX_GOLDEN_GATE_RAM ZORRO_ID(VORTEX, 0x08, 0)
+#define ZORRO_PROD_VORTEX_GOLDEN_GATE_80486 ZORRO_ID(VORTEX, 0x09, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_EXPANSION_SYSTEMS 0x2062
+#define ZORRO_PROD_EXPANSION_SYSTEMS_DATAFLYER_4000SX ZORRO_ID(EXPANSION_SYSTEMS, 0x01, 0)
+#define ZORRO_PROD_EXPANSION_SYSTEMS_DATAFLYER_4000SX_RAM ZORRO_ID(EXPANSION_SYSTEMS, 0x02, 0)
+#define ZORRO_MANUF_READYSOFT 0x2100
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_READYSOFT_AMAX_II_IV ZORRO_ID(READYSOFT, 0x01, 0)
+#define ZORRO_MANUF_PHASE5 0x2140
+#define ZORRO_PROD_PHASE5_BLIZZARD_RAM ZORRO_ID(PHASE5, 0x01, 0)
+#define ZORRO_PROD_PHASE5_BLIZZARD ZORRO_ID(PHASE5, 0x02, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_PHASE5_BLIZZARD_1220_IV ZORRO_ID(PHASE5, 0x06, 0)
+#define ZORRO_PROD_PHASE5_FASTLANE_Z3_RAM ZORRO_ID(PHASE5, 0x0A, 0)
+#define ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060 ZORRO_ID(PHASE5, 0x0B, 0)
+#define ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM ZORRO_ID(PHASE5, 0x0C, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_PHASE5_BLIZZARD_1230 ZORRO_ID(PHASE5, 0x0D, 0)
+#define ZORRO_PROD_PHASE5_BLIZZARD_1230_IV_1260 ZORRO_ID(PHASE5, 0x11, 0)
+#define ZORRO_PROD_PHASE5_BLIZZARD_2060 ZORRO_ID(PHASE5, 0x18, 0)
+#define ZORRO_PROD_PHASE5_CYBERSTORM_MK_II ZORRO_ID(PHASE5, 0x19, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_PHASE5_CYBERVISION64 ZORRO_ID(PHASE5, 0x22, 0)
+#define ZORRO_PROD_PHASE5_CYBERVISION64_3D_PROTOTYPE ZORRO_ID(PHASE5, 0x32, 0)
+#define ZORRO_PROD_PHASE5_CYBERVISION64_3D ZORRO_ID(PHASE5, 0x43, 0)
+#define ZORRO_PROD_PHASE5_CYBERSTORM_MK_III ZORRO_ID(PHASE5, 0x64, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_PHASE5_BLIZZARD_603E_PLUS ZORRO_ID(PHASE5, 0x6e, 0)
+#define ZORRO_MANUF_DPS 0x2169
+#define ZORRO_PROD_DPS_PERSONAL_ANIMATION_RECORDER ZORRO_ID(DPS, 0x01, 0)
+#define ZORRO_MANUF_APOLLO_2 0x2200
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_APOLLO_A620_68020_1 ZORRO_ID(APOLLO_2, 0x00, 0)
+#define ZORRO_PROD_APOLLO_A620_68020_2 ZORRO_ID(APOLLO_2, 0x01, 0)
+#define ZORRO_MANUF_APOLLO_3 0x2222
+#define ZORRO_PROD_APOLLO_AT_APOLLO ZORRO_ID(APOLLO_3, 0x22, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_APOLLO_1230_1240_1260_2030_4040_4060 ZORRO_ID(APOLLO_3, 0x23, 0)
+#define ZORRO_MANUF_PETSOFF_LP 0x38A5
+#define ZORRO_PROD_PETSOFF_LP_DELFINA ZORRO_ID(PETSOFF_LP, 0x00, 0)
+#define ZORRO_PROD_PETSOFF_LP_DELFINA_LITE ZORRO_ID(PETSOFF_LP, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_UWE_GERLACH 0x3FF7
+#define ZORRO_PROD_UWE_GERLACH_RAM_ROM ZORRO_ID(UWE_GERLACH, 0xd4, 0)
+#define ZORRO_MANUF_ACT 0x4231
+#define ZORRO_PROD_ACT_PRELUDE ZORRO_ID(ACT, 0x01, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_MACROSYSTEMS_GERMANY 0x4754
+#define ZORRO_PROD_MACROSYSTEMS_MAESTRO ZORRO_ID(MACROSYSTEMS_GERMANY, 0x03, 0)
+#define ZORRO_PROD_MACROSYSTEMS_VLAB ZORRO_ID(MACROSYSTEMS_GERMANY, 0x04, 0)
+#define ZORRO_PROD_MACROSYSTEMS_MAESTRO_PRO ZORRO_ID(MACROSYSTEMS_GERMANY, 0x05, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MACROSYSTEMS_RETINA ZORRO_ID(MACROSYSTEMS_GERMANY, 0x06, 0)
+#define ZORRO_PROD_MACROSYSTEMS_MULTI_EVOLUTION ZORRO_ID(MACROSYSTEMS_GERMANY, 0x08, 0)
+#define ZORRO_PROD_MACROSYSTEMS_TOCCATA ZORRO_ID(MACROSYSTEMS_GERMANY, 0x0C, 0)
+#define ZORRO_PROD_MACROSYSTEMS_RETINA_Z3 ZORRO_ID(MACROSYSTEMS_GERMANY, 0x10, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_MACROSYSTEMS_VLAB_MOTION ZORRO_ID(MACROSYSTEMS_GERMANY, 0x12, 0)
+#define ZORRO_PROD_MACROSYSTEMS_ALTAIS ZORRO_ID(MACROSYSTEMS_GERMANY, 0x13, 0)
+#define ZORRO_PROD_MACROSYSTEMS_FALCON_040 ZORRO_ID(MACROSYSTEMS_GERMANY, 0xFD, 0)
+#define ZORRO_MANUF_COMBITEC 0x6766
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_SKI_PERIPHERALS 0x8000
+#define ZORRO_PROD_SKI_PERIPHERALS_MAST_FIREBALL ZORRO_ID(SKI_PERIPHERALS, 0x08, 0)
+#define ZORRO_PROD_SKI_PERIPHERALS_SCSI_DUAL_SERIAL ZORRO_ID(SKI_PERIPHERALS, 0x80, 0)
+#define ZORRO_MANUF_REIS_WARE_2 0xA9AD
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_REIS_WARE_SCAN_KING ZORRO_ID(REIS_WARE_2, 0x11, 0)
+#define ZORRO_MANUF_CAMERON 0xAA01
+#define ZORRO_PROD_CAMERON_PERSONAL_A4 ZORRO_ID(CAMERON, 0x10, 0)
+#define ZORRO_MANUF_REIS_WARE 0xAA11
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_REIS_WARE_HANDYSCANNER ZORRO_ID(REIS_WARE, 0x11, 0)
+#define ZORRO_MANUF_PHOENIX_2 0xB5A8
+#define ZORRO_PROD_PHOENIX_ST506_2 ZORRO_ID(PHOENIX_2, 0x21, 0)
+#define ZORRO_PROD_PHOENIX_SCSI_2 ZORRO_ID(PHOENIX_2, 0x22, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_PHOENIX_RAM_2 ZORRO_ID(PHOENIX_2, 0xBE, 0)
+#define ZORRO_MANUF_COMBITEC_2 0xC008
+#define ZORRO_PROD_COMBITEC_HD ZORRO_ID(COMBITEC_2, 0x2A, 0)
+#define ZORRO_PROD_COMBITEC_SRAM ZORRO_ID(COMBITEC_2, 0x2B, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_MANUF_HACKER 0x07DB
+#define ZORRO_PROD_GENERAL_PROTOTYPE ZORRO_ID(HACKER, 0x00, 0)
+#define ZORRO_PROD_HACKER_SCSI ZORRO_ID(HACKER, 0x01, 0)
+#define ZORRO_PROD_RESOURCE_MANAGEMENT_FORCE_QUICKNET_QN2000 ZORRO_ID(HACKER, 0x02, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ZORRO_PROD_VECTOR_CONNECTION_2 ZORRO_ID(HACKER, 0xE0, 0)
+#define ZORRO_PROD_VECTOR_CONNECTION_3 ZORRO_ID(HACKER, 0xE1, 0)
+#define ZORRO_PROD_VECTOR_CONNECTION_4 ZORRO_ID(HACKER, 0xE2, 0)
+#define ZORRO_PROD_VECTOR_CONNECTION_5 ZORRO_ID(HACKER, 0xE3, 0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/rdma/ib_user_verbs.h b/libc/kernel/uapi/rdma/ib_user_verbs.h
index ee66c45..dd931d8 100644
--- a/libc/kernel/uapi/rdma/ib_user_verbs.h
+++ b/libc/kernel/uapi/rdma/ib_user_verbs.h
@@ -21,754 +21,871 @@
 #include <linux/types.h>
 #define IB_USER_VERBS_ABI_VERSION 6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IB_USER_VERBS_CMD_THRESHOLD 50
 enum {
  IB_USER_VERBS_CMD_GET_CONTEXT,
  IB_USER_VERBS_CMD_QUERY_DEVICE,
- IB_USER_VERBS_CMD_QUERY_PORT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_QUERY_PORT,
  IB_USER_VERBS_CMD_ALLOC_PD,
  IB_USER_VERBS_CMD_DEALLOC_PD,
  IB_USER_VERBS_CMD_CREATE_AH,
- IB_USER_VERBS_CMD_MODIFY_AH,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_MODIFY_AH,
  IB_USER_VERBS_CMD_QUERY_AH,
  IB_USER_VERBS_CMD_DESTROY_AH,
  IB_USER_VERBS_CMD_REG_MR,
- IB_USER_VERBS_CMD_REG_SMR,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_REG_SMR,
  IB_USER_VERBS_CMD_REREG_MR,
  IB_USER_VERBS_CMD_QUERY_MR,
  IB_USER_VERBS_CMD_DEREG_MR,
- IB_USER_VERBS_CMD_ALLOC_MW,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_ALLOC_MW,
  IB_USER_VERBS_CMD_BIND_MW,
  IB_USER_VERBS_CMD_DEALLOC_MW,
  IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL,
- IB_USER_VERBS_CMD_CREATE_CQ,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_CREATE_CQ,
  IB_USER_VERBS_CMD_RESIZE_CQ,
  IB_USER_VERBS_CMD_DESTROY_CQ,
  IB_USER_VERBS_CMD_POLL_CQ,
- IB_USER_VERBS_CMD_PEEK_CQ,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_PEEK_CQ,
  IB_USER_VERBS_CMD_REQ_NOTIFY_CQ,
  IB_USER_VERBS_CMD_CREATE_QP,
  IB_USER_VERBS_CMD_QUERY_QP,
- IB_USER_VERBS_CMD_MODIFY_QP,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_MODIFY_QP,
  IB_USER_VERBS_CMD_DESTROY_QP,
  IB_USER_VERBS_CMD_POST_SEND,
  IB_USER_VERBS_CMD_POST_RECV,
- IB_USER_VERBS_CMD_ATTACH_MCAST,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_ATTACH_MCAST,
  IB_USER_VERBS_CMD_DETACH_MCAST,
  IB_USER_VERBS_CMD_CREATE_SRQ,
  IB_USER_VERBS_CMD_MODIFY_SRQ,
- IB_USER_VERBS_CMD_QUERY_SRQ,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ IB_USER_VERBS_CMD_QUERY_SRQ,
  IB_USER_VERBS_CMD_DESTROY_SRQ,
  IB_USER_VERBS_CMD_POST_SRQ_RECV,
  IB_USER_VERBS_CMD_OPEN_XRCD,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IB_USER_VERBS_CMD_CLOSE_XRCD,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  IB_USER_VERBS_CMD_CREATE_XSRQ,
- IB_USER_VERBS_CMD_OPEN_QP
+ IB_USER_VERBS_CMD_OPEN_QP,
 };
-struct ib_uverbs_async_event_desc {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
+ IB_USER_VERBS_EX_CMD_CREATE_FLOW = IB_USER_VERBS_CMD_THRESHOLD,
+ IB_USER_VERBS_EX_CMD_DESTROY_FLOW
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_async_event_desc {
  __u64 element;
  __u32 event_type;
  __u32 reserved;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct ib_uverbs_comp_event_desc {
  __u64 cq_handle;
 };
-struct ib_uverbs_cmd_hdr {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IB_USER_VERBS_CMD_COMMAND_MASK 0xff
+#define IB_USER_VERBS_CMD_FLAGS_MASK 0xff000000u
+#define IB_USER_VERBS_CMD_FLAGS_SHIFT 24
+#define IB_USER_VERBS_CMD_FLAG_EXTENDED 0x80
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_cmd_hdr {
  __u32 command;
  __u16 in_words;
  __u16 out_words;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct ib_uverbs_ex_cmd_hdr {
+ __u64 response;
+ __u16 provider_in_words;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 provider_out_words;
+ __u32 cmd_hdr_reserved;
+};
 struct ib_uverbs_get_context {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u64 driver_data[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_get_context_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 async_fd;
  __u32 num_comp_vectors;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_query_device {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u64 driver_data[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_query_device_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 fw_ver;
  __be64 node_guid;
  __be64 sys_image_guid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 max_mr_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 page_size_cap;
  __u32 vendor_id;
  __u32 vendor_part_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 hw_ver;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_qp;
  __u32 max_qp_wr;
  __u32 device_cap_flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_sge;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_sge_rd;
  __u32 max_cq;
  __u32 max_cqe;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_mr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_pd;
  __u32 max_qp_rd_atom;
  __u32 max_ee_rd_atom;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_res_rd_atom;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_qp_init_rd_atom;
  __u32 max_ee_init_rd_atom;
  __u32 atomic_cap;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_ee;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_rdd;
  __u32 max_mw;
  __u32 max_raw_ipv6_qp;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_raw_ethy_qp;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_mcast_grp;
  __u32 max_mcast_qp_attach;
  __u32 max_total_mcast_qp_attach;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_ah;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_fmr;
  __u32 max_map_per_fmr;
  __u32 max_srq;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_srq_wr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_srq_sge;
  __u16 max_pkeys;
  __u8 local_ca_ack_delay;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 phys_port_cnt;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 reserved[4];
 };
 struct ib_uverbs_query_port {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 port_num;
  __u8 reserved[7];
  __u64 driver_data[0];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_query_port_resp {
  __u32 port_cap_flags;
  __u32 max_msg_sz;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 bad_pkey_cntr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qkey_viol_cntr;
  __u32 gid_tbl_len;
  __u16 pkey_tbl_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 lid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 sm_lid;
  __u8 state;
  __u8 max_mtu;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 active_mtu;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 lmc;
  __u8 max_vl_num;
  __u8 sm_sl;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 subnet_timeout;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 init_type_reply;
  __u8 active_width;
  __u8 active_speed;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 phys_state;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 link_layer;
  __u8 reserved[2];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_alloc_pd {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u64 driver_data[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_alloc_pd_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pd_handle;
 };
 struct ib_uverbs_dealloc_pd {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pd_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_open_xrcd {
  __u64 response;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 fd;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 oflags;
  __u64 driver_data[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_open_xrcd_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 xrcd_handle;
 };
 struct ib_uverbs_close_xrcd {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 xrcd_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_reg_mr {
  __u64 response;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 start;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 length;
  __u64 hca_va;
  __u32 pd_handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 access_flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
 };
 struct ib_uverbs_reg_mr_resp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mr_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 lkey;
  __u32 rkey;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_dereg_mr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 mr_handle;
 };
 struct ib_uverbs_alloc_mw {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pd_handle;
  __u8 mw_type;
  __u8 reserved[3];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_alloc_mw_resp {
  __u32 mw_handle;
  __u32 rkey;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_dealloc_mw {
  __u32 mw_handle;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_create_comp_channel {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
 };
 struct ib_uverbs_create_comp_channel_resp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 fd;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_create_cq {
  __u64 response;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 user_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cqe;
  __u32 comp_vector;
  __s32 comp_channel;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
 };
 struct ib_uverbs_create_cq_resp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cq_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cqe;
 };
 struct ib_uverbs_resize_cq {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cq_handle;
  __u32 cqe;
  __u64 driver_data[0];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_resize_cq_resp {
  __u32 cqe;
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_poll_cq {
  __u64 response;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cq_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ne;
 };
 struct ib_uverbs_wc {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 wr_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 status;
  __u32 opcode;
  __u32 vendor_err;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 byte_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  __u32 imm_data;
  __u32 invalidate_rkey;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } ex;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_num;
  __u32 src_qp;
  __u32 wc_flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 pkey_index;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 slid;
  __u8 sl;
  __u8 dlid_path_bits;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 port_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 reserved;
 };
 struct ib_uverbs_poll_cq_resp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved;
  struct ib_uverbs_wc wc[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_req_notify_cq {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cq_handle;
  __u32 solicited_only;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_destroy_cq {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u32 cq_handle;
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_destroy_cq_resp {
  __u32 comp_events_reported;
  __u32 async_events_reported;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_global_route {
  __u8 dgid[16];
  __u32 flow_label;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 sgid_index;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 hop_limit;
  __u8 traffic_class;
  __u8 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_ah_attr {
  struct ib_uverbs_global_route grh;
  __u16 dlid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 sl;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 src_path_bits;
  __u8 static_rate;
  __u8 is_global;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 port_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 reserved;
 };
 struct ib_uverbs_qp_attr {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_attr_mask;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_state;
  __u32 cur_qp_state;
  __u32 path_mtu;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 path_mig_state;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qkey;
  __u32 rq_psn;
  __u32 sq_psn;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 dest_qp_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_access_flags;
  struct ib_uverbs_ah_attr ah_attr;
  struct ib_uverbs_ah_attr alt_ah_attr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_send_wr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_recv_wr;
  __u32 max_send_sge;
  __u32 max_recv_sge;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_inline_data;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 pkey_index;
  __u16 alt_pkey_index;
  __u8 en_sqd_async_notify;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 sq_draining;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 max_rd_atomic;
  __u8 max_dest_rd_atomic;
  __u8 min_rnr_timer;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 port_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 timeout;
  __u8 retry_cnt;
  __u8 rnr_retry;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 alt_port_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 alt_timeout;
  __u8 reserved[5];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_create_qp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u64 user_handle;
  __u32 pd_handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 send_cq_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 recv_cq_handle;
  __u32 srq_handle;
  __u32 max_send_wr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_recv_wr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_send_sge;
  __u32 max_recv_sge;
  __u32 max_inline_data;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 sq_sig_all;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 qp_type;
  __u8 is_srq;
  __u8 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_open_qp {
  __u64 response;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 user_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pd_handle;
  __u32 qpn;
  __u8 qp_type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 reserved[7];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
 };
 struct ib_uverbs_create_qp_resp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qpn;
  __u32 max_send_wr;
  __u32 max_recv_wr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_send_sge;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_recv_sge;
  __u32 max_inline_data;
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_qp_dest {
  __u8 dgid[16];
  __u32 flow_label;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 dlid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 reserved;
  __u8 sgid_index;
  __u8 hop_limit;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 traffic_class;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 sl;
  __u8 src_path_bits;
  __u8 static_rate;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 is_global;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 port_num;
 };
 struct ib_uverbs_query_qp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_handle;
  __u32 attr_mask;
  __u64 driver_data[0];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_query_qp_resp {
  struct ib_uverbs_qp_dest dest;
  struct ib_uverbs_qp_dest alt_dest;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_send_wr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_recv_wr;
  __u32 max_send_sge;
  __u32 max_recv_sge;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_inline_data;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qkey;
  __u32 rq_psn;
  __u32 sq_psn;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 dest_qp_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_access_flags;
  __u16 pkey_index;
  __u16 alt_pkey_index;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 qp_state;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 cur_qp_state;
  __u8 path_mtu;
  __u8 path_mig_state;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 sq_draining;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 max_rd_atomic;
  __u8 max_dest_rd_atomic;
  __u8 min_rnr_timer;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 port_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 timeout;
  __u8 retry_cnt;
  __u8 rnr_retry;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 alt_port_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 alt_timeout;
  __u8 sq_sig_all;
  __u8 reserved[5];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_modify_qp {
  struct ib_uverbs_qp_dest dest;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct ib_uverbs_qp_dest alt_dest;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_handle;
  __u32 attr_mask;
  __u32 qkey;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 rq_psn;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 sq_psn;
  __u32 dest_qp_num;
  __u32 qp_access_flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 pkey_index;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 alt_pkey_index;
  __u8 qp_state;
  __u8 cur_qp_state;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 path_mtu;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 path_mig_state;
  __u8 en_sqd_async_notify;
  __u8 max_rd_atomic;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 max_dest_rd_atomic;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 min_rnr_timer;
  __u8 port_num;
  __u8 timeout;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 retry_cnt;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 rnr_retry;
  __u8 alt_port_num;
  __u8 alt_timeout;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 reserved[2];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
 };
 struct ib_uverbs_modify_qp_resp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_destroy_qp {
  __u64 response;
  __u32 qp_handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_destroy_qp_resp {
  __u32 events_reported;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_sge {
  __u64 addr;
  __u32 length;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 lkey;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_send_wr {
  __u64 wr_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 num_sge;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 opcode;
  __u32 send_flags;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 imm_data;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 invalidate_rkey;
  } ex;
  union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 remote_addr;
  __u32 rkey;
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } rdma;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  __u64 remote_addr;
  __u64 compare_add;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 swap;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 rkey;
  __u32 reserved;
  } atomic;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ah;
  __u32 remote_qpn;
  __u32 remote_qkey;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } ud;
  } wr;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_post_send {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u32 qp_handle;
  __u32 wr_count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 sge_count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 wqe_size;
  struct ib_uverbs_send_wr send_wr[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_post_send_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 bad_wr;
 };
 struct ib_uverbs_recv_wr {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 wr_id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 num_sge;
  __u32 reserved;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_post_recv {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u32 qp_handle;
  __u32 wr_count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 sge_count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 wqe_size;
  struct ib_uverbs_recv_wr recv_wr[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_post_recv_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 bad_wr;
 };
 struct ib_uverbs_post_srq_recv {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 srq_handle;
  __u32 wr_count;
  __u32 sge_count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 wqe_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct ib_uverbs_recv_wr recv[0];
 };
 struct ib_uverbs_post_srq_recv_resp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 bad_wr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_create_ah {
  __u64 response;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 user_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pd_handle;
  __u32 reserved;
  struct ib_uverbs_ah_attr attr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_create_ah_resp {
  __u32 ah_handle;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_destroy_ah {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ah_handle;
 };
 struct ib_uverbs_attach_mcast {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 gid[16];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_handle;
  __u16 mlid;
  __u16 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_detach_mcast {
  __u8 gid[16];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_handle;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 mlid;
  __u16 reserved;
  __u64 driver_data[0];
+};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_flow_spec_hdr {
+ __u32 type;
+ __u16 size;
+ __u16 reserved;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 flow_spec_data[0];
+};
+struct ib_uverbs_flow_eth_filter {
+ __u8 dst_mac[6];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 src_mac[6];
+ __be16 ether_type;
+ __be16 vlan_tag;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_flow_spec_eth {
+ union {
+ struct ib_uverbs_flow_spec_hdr hdr;
+ struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 type;
+ __u16 size;
+ __u16 reserved;
+ };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ };
+ struct ib_uverbs_flow_eth_filter val;
+ struct ib_uverbs_flow_eth_filter mask;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_flow_ipv4_filter {
+ __be32 src_ip;
+ __be32 dst_ip;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_flow_spec_ipv4 {
+ union {
+ struct ib_uverbs_flow_spec_hdr hdr;
+ struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 type;
+ __u16 size;
+ __u16 reserved;
+ };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ };
+ struct ib_uverbs_flow_ipv4_filter val;
+ struct ib_uverbs_flow_ipv4_filter mask;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_flow_tcp_udp_filter {
+ __be16 dst_port;
+ __be16 src_port;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_flow_spec_tcp_udp {
+ union {
+ struct ib_uverbs_flow_spec_hdr hdr;
+ struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 type;
+ __u16 size;
+ __u16 reserved;
+ };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ };
+ struct ib_uverbs_flow_tcp_udp_filter val;
+ struct ib_uverbs_flow_tcp_udp_filter mask;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ib_uverbs_flow_attr {
+ __u32 type;
+ __u16 size;
+ __u16 priority;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 num_of_specs;
+ __u8 reserved[2];
+ __u8 port;
+ __u32 flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct ib_uverbs_flow_spec_hdr flow_specs[0];
+};
+struct ib_uverbs_create_flow {
+ __u32 comp_mask;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 qp_handle;
+ struct ib_uverbs_flow_attr flow_attr;
+};
+struct ib_uverbs_create_flow_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 comp_mask;
+ __u32 flow_handle;
+};
+struct ib_uverbs_destroy_flow {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 comp_mask;
+ __u32 flow_handle;
 };
 struct ib_uverbs_create_srq {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u64 user_handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pd_handle;
  __u32 max_wr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_sge;
  __u32 srq_limit;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_create_xsrq {
  __u64 response;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 user_handle;
  __u32 srq_type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pd_handle;
  __u32 max_wr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_sge;
  __u32 srq_limit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved;
  __u32 xrcd_handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 cq_handle;
  __u64 driver_data[0];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_create_srq_resp {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 srq_handle;
  __u32 max_wr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_sge;
  __u32 srqn;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_modify_srq {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 srq_handle;
  __u32 attr_mask;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_wr;
  __u32 srq_limit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_query_srq {
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 srq_handle;
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 driver_data[0];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_query_srq_resp {
  __u32 max_wr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 max_sge;
  __u32 srq_limit;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ib_uverbs_destroy_srq {
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 srq_handle;
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct ib_uverbs_destroy_srq_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 events_reported;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/rdma/rdma_user_cm.h b/libc/kernel/uapi/rdma/rdma_user_cm.h
index 7ab4cf0..74e5a05 100644
--- a/libc/kernel/uapi/rdma/rdma_user_cm.h
+++ b/libc/kernel/uapi/rdma/rdma_user_cm.h
@@ -29,9 +29,9 @@
 enum {
  RDMA_USER_CM_CMD_CREATE_ID,
  RDMA_USER_CM_CMD_DESTROY_ID,
- RDMA_USER_CM_CMD_BIND_ADDR,
+ RDMA_USER_CM_CMD_BIND_IP,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- RDMA_USER_CM_CMD_RESOLVE_ADDR,
+ RDMA_USER_CM_CMD_RESOLVE_IP,
  RDMA_USER_CM_CMD_RESOLVE_ROUTE,
  RDMA_USER_CM_CMD_QUERY_ROUTE,
  RDMA_USER_CM_CMD_CONNECT,
@@ -47,9 +47,14 @@
  RDMA_USER_CM_CMD_SET_OPTION,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RDMA_USER_CM_CMD_NOTIFY,
- RDMA_USER_CM_CMD_JOIN_MCAST,
+ RDMA_USER_CM_CMD_JOIN_IP_MCAST,
  RDMA_USER_CM_CMD_LEAVE_MCAST,
- RDMA_USER_CM_CMD_MIGRATE_ID
+ RDMA_USER_CM_CMD_MIGRATE_ID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ RDMA_USER_CM_CMD_QUERY,
+ RDMA_USER_CM_CMD_BIND,
+ RDMA_USER_CM_CMD_RESOLVE_ADDR,
+ RDMA_USER_CM_CMD_JOIN_MCAST
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct rdma_ucm_cmd_hdr {
@@ -81,29 +86,54 @@
  __u32 events_reported;
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct rdma_ucm_bind_addr {
+struct rdma_ucm_bind_ip {
  __u64 response;
  struct sockaddr_in6 addr;
  __u32 id;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
-struct rdma_ucm_resolve_addr {
+struct rdma_ucm_bind {
+ __u32 id;
+ __u16 addr_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 reserved;
+ struct sockaddr_storage addr;
+};
+struct rdma_ucm_resolve_ip {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct sockaddr_in6 src_addr;
  struct sockaddr_in6 dst_addr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
  __u32 timeout_ms;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct rdma_ucm_resolve_addr {
+ __u32 id;
+ __u32 timeout_ms;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 src_size;
+ __u16 dst_size;
+ __u32 reserved;
+ struct sockaddr_storage src_addr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct sockaddr_storage dst_addr;
 };
 struct rdma_ucm_resolve_route {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 timeout_ms;
 };
-struct rdma_ucm_query_route {
+enum {
+ RDMA_USER_CM_QUERY_ADDR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ RDMA_USER_CM_QUERY_PATH,
+ RDMA_USER_CM_QUERY_GID
+};
+struct rdma_ucm_query {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
  __u32 id;
- __u32 reserved;
+ __u32 option;
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct rdma_ucm_query_route_resp {
@@ -117,127 +147,155 @@
  __u8 reserved[3];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+struct rdma_ucm_query_addr_resp {
+ __u64 node_guid;
+ __u8 port_num;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u8 reserved;
+ __u16 pkey;
+ __u16 src_size;
+ __u16 dst_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct sockaddr_storage src_addr;
+ struct sockaddr_storage dst_addr;
+};
+struct rdma_ucm_query_path_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 num_paths;
+ __u32 reserved;
+ struct ib_path_rec_data path_data[0];
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct rdma_ucm_conn_param {
  __u32 qp_num;
- __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 qkey;
  __u8 private_data[RDMA_MAX_PRIVATE_DATA];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 private_data_len;
  __u8 srq;
  __u8 responder_resources;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 initiator_depth;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 flow_control;
  __u8 retry_count;
  __u8 rnr_retry_count;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 valid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct rdma_ucm_ud_param {
  __u32 qp_num;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qkey;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct ib_uverbs_ah_attr ah_attr;
  __u8 private_data[RDMA_MAX_PRIVATE_DATA];
  __u8 private_data_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 reserved[7];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct rdma_ucm_connect {
  struct rdma_ucm_conn_param conn_param;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved;
 };
 struct rdma_ucm_listen {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 backlog;
 };
 struct rdma_ucm_accept {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 uid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct rdma_ucm_conn_param conn_param;
  __u32 id;
  __u32 reserved;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct rdma_ucm_reject {
  __u32 id;
  __u8 private_data_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 reserved[3];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 private_data[RDMA_MAX_PRIVATE_DATA];
 };
 struct rdma_ucm_disconnect {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct rdma_ucm_init_qp_attr {
  __u64 response;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 qp_state;
 };
 struct rdma_ucm_notify {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 event;
 };
-struct rdma_ucm_join_mcast {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct rdma_ucm_join_ip_mcast {
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 uid;
  struct sockaddr_in6 addr;
  __u32 id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct rdma_ucm_join_mcast {
+ __u64 response;
+ __u64 uid;
+ __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 addr_size;
+ __u16 reserved;
+ struct sockaddr_storage addr;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct rdma_ucm_get_event {
  __u64 response;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct rdma_ucm_event_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 uid;
  __u32 id;
  __u32 event;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 status;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  struct rdma_ucm_conn_param conn;
  struct rdma_ucm_ud_param ud;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } param;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum {
  RDMA_OPTION_ID = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RDMA_OPTION_IB = 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 enum {
  RDMA_OPTION_ID_TOS = 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RDMA_OPTION_ID_REUSEADDR = 1,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  RDMA_OPTION_ID_AFONLY = 2,
  RDMA_OPTION_IB_PATH = 1
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct rdma_ucm_set_option {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 optval;
  __u32 id;
  __u32 level;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 optname;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 optlen;
 };
 struct rdma_ucm_migrate_id {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u64 response;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 id;
  __u32 fd;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct rdma_ucm_migrate_resp {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 events_reported;
 };
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/sound/asound.h b/libc/kernel/uapi/sound/asound.h
index 500d924..9d187aa 100644
--- a/libc/kernel/uapi/sound/asound.h
+++ b/libc/kernel/uapi/sound/asound.h
@@ -67,923 +67,925 @@
  SNDRV_HWDEP_IFACE_HDA,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  SNDRV_HWDEP_IFACE_USB_STREAM,
- SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_USB_STREAM
+ SNDRV_HWDEP_IFACE_FW_DICE,
+ SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_DICE
 };
-struct snd_hwdep_info {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_hwdep_info {
  unsigned int device;
  int card;
  unsigned char id[64];
- unsigned char name[80];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char name[80];
  int iface;
  unsigned char reserved[64];
 };
-struct snd_hwdep_dsp_status {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_hwdep_dsp_status {
  unsigned int version;
  unsigned char id[32];
  unsigned int num_dsps;
- unsigned int dsp_loaded;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int dsp_loaded;
  unsigned int chip_ready;
  unsigned char reserved[16];
 };
-struct snd_hwdep_dsp_image {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_hwdep_dsp_image {
  unsigned int index;
  unsigned char name[64];
  unsigned char __user *image;
- size_t length;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ size_t length;
  unsigned long driver_data;
 };
 #define SNDRV_HWDEP_IOCTL_PVERSION _IOR ('H', 0x00, int)
-#define SNDRV_HWDEP_IOCTL_INFO _IOR ('H', 0x01, struct snd_hwdep_info)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_HWDEP_IOCTL_INFO _IOR ('H', 0x01, struct snd_hwdep_info)
 #define SNDRV_HWDEP_IOCTL_DSP_STATUS _IOR('H', 0x02, struct snd_hwdep_dsp_status)
 #define SNDRV_HWDEP_IOCTL_DSP_LOAD _IOW('H', 0x03, struct snd_hwdep_dsp_image)
 #define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 11)
-typedef unsigned long snd_pcm_uframes_t;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef unsigned long snd_pcm_uframes_t;
 typedef signed long snd_pcm_sframes_t;
 enum {
  SNDRV_PCM_CLASS_GENERIC = 0,
- SNDRV_PCM_CLASS_MULTI,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_PCM_CLASS_MULTI,
  SNDRV_PCM_CLASS_MODEM,
  SNDRV_PCM_CLASS_DIGITIZER,
  SNDRV_PCM_CLASS_LAST = SNDRV_PCM_CLASS_DIGITIZER,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  SNDRV_PCM_SUBCLASS_GENERIC_MIX = 0,
  SNDRV_PCM_SUBCLASS_MULTI_MIX,
- SNDRV_PCM_SUBCLASS_LAST = SNDRV_PCM_SUBCLASS_MULTI_MIX,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_PCM_SUBCLASS_LAST = SNDRV_PCM_SUBCLASS_MULTI_MIX,
 };
 enum {
  SNDRV_PCM_STREAM_PLAYBACK = 0,
- SNDRV_PCM_STREAM_CAPTURE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_PCM_STREAM_CAPTURE,
  SNDRV_PCM_STREAM_LAST = SNDRV_PCM_STREAM_CAPTURE,
 };
 typedef int __bitwise snd_pcm_access_t;
-#define SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ((__force snd_pcm_access_t) 0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ((__force snd_pcm_access_t) 0)
 #define SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED ((__force snd_pcm_access_t) 1)
 #define SNDRV_PCM_ACCESS_MMAP_COMPLEX ((__force snd_pcm_access_t) 2)
 #define SNDRV_PCM_ACCESS_RW_INTERLEAVED ((__force snd_pcm_access_t) 3)
-#define SNDRV_PCM_ACCESS_RW_NONINTERLEAVED ((__force snd_pcm_access_t) 4)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_ACCESS_RW_NONINTERLEAVED ((__force snd_pcm_access_t) 4)
 #define SNDRV_PCM_ACCESS_LAST SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
 typedef int __bitwise snd_pcm_format_t;
 #define SNDRV_PCM_FORMAT_S8 ((__force snd_pcm_format_t) 0)
-#define SNDRV_PCM_FORMAT_U8 ((__force snd_pcm_format_t) 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_U8 ((__force snd_pcm_format_t) 1)
 #define SNDRV_PCM_FORMAT_S16_LE ((__force snd_pcm_format_t) 2)
 #define SNDRV_PCM_FORMAT_S16_BE ((__force snd_pcm_format_t) 3)
 #define SNDRV_PCM_FORMAT_U16_LE ((__force snd_pcm_format_t) 4)
-#define SNDRV_PCM_FORMAT_U16_BE ((__force snd_pcm_format_t) 5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_U16_BE ((__force snd_pcm_format_t) 5)
 #define SNDRV_PCM_FORMAT_S24_LE ((__force snd_pcm_format_t) 6)
 #define SNDRV_PCM_FORMAT_S24_BE ((__force snd_pcm_format_t) 7)
 #define SNDRV_PCM_FORMAT_U24_LE ((__force snd_pcm_format_t) 8)
-#define SNDRV_PCM_FORMAT_U24_BE ((__force snd_pcm_format_t) 9)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_U24_BE ((__force snd_pcm_format_t) 9)
 #define SNDRV_PCM_FORMAT_S32_LE ((__force snd_pcm_format_t) 10)
 #define SNDRV_PCM_FORMAT_S32_BE ((__force snd_pcm_format_t) 11)
 #define SNDRV_PCM_FORMAT_U32_LE ((__force snd_pcm_format_t) 12)
-#define SNDRV_PCM_FORMAT_U32_BE ((__force snd_pcm_format_t) 13)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_U32_BE ((__force snd_pcm_format_t) 13)
 #define SNDRV_PCM_FORMAT_FLOAT_LE ((__force snd_pcm_format_t) 14)
 #define SNDRV_PCM_FORMAT_FLOAT_BE ((__force snd_pcm_format_t) 15)
 #define SNDRV_PCM_FORMAT_FLOAT64_LE ((__force snd_pcm_format_t) 16)
-#define SNDRV_PCM_FORMAT_FLOAT64_BE ((__force snd_pcm_format_t) 17)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_FLOAT64_BE ((__force snd_pcm_format_t) 17)
 #define SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE ((__force snd_pcm_format_t) 18)
 #define SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE ((__force snd_pcm_format_t) 19)
 #define SNDRV_PCM_FORMAT_MU_LAW ((__force snd_pcm_format_t) 20)
-#define SNDRV_PCM_FORMAT_A_LAW ((__force snd_pcm_format_t) 21)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_A_LAW ((__force snd_pcm_format_t) 21)
 #define SNDRV_PCM_FORMAT_IMA_ADPCM ((__force snd_pcm_format_t) 22)
 #define SNDRV_PCM_FORMAT_MPEG ((__force snd_pcm_format_t) 23)
 #define SNDRV_PCM_FORMAT_GSM ((__force snd_pcm_format_t) 24)
-#define SNDRV_PCM_FORMAT_SPECIAL ((__force snd_pcm_format_t) 31)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_SPECIAL ((__force snd_pcm_format_t) 31)
 #define SNDRV_PCM_FORMAT_S24_3LE ((__force snd_pcm_format_t) 32)
 #define SNDRV_PCM_FORMAT_S24_3BE ((__force snd_pcm_format_t) 33)
 #define SNDRV_PCM_FORMAT_U24_3LE ((__force snd_pcm_format_t) 34)
-#define SNDRV_PCM_FORMAT_U24_3BE ((__force snd_pcm_format_t) 35)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_U24_3BE ((__force snd_pcm_format_t) 35)
 #define SNDRV_PCM_FORMAT_S20_3LE ((__force snd_pcm_format_t) 36)
 #define SNDRV_PCM_FORMAT_S20_3BE ((__force snd_pcm_format_t) 37)
 #define SNDRV_PCM_FORMAT_U20_3LE ((__force snd_pcm_format_t) 38)
-#define SNDRV_PCM_FORMAT_U20_3BE ((__force snd_pcm_format_t) 39)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_U20_3BE ((__force snd_pcm_format_t) 39)
 #define SNDRV_PCM_FORMAT_S18_3LE ((__force snd_pcm_format_t) 40)
 #define SNDRV_PCM_FORMAT_S18_3BE ((__force snd_pcm_format_t) 41)
 #define SNDRV_PCM_FORMAT_U18_3LE ((__force snd_pcm_format_t) 42)
-#define SNDRV_PCM_FORMAT_U18_3BE ((__force snd_pcm_format_t) 43)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_U18_3BE ((__force snd_pcm_format_t) 43)
 #define SNDRV_PCM_FORMAT_G723_24 ((__force snd_pcm_format_t) 44)
 #define SNDRV_PCM_FORMAT_G723_24_1B ((__force snd_pcm_format_t) 45)
 #define SNDRV_PCM_FORMAT_G723_40 ((__force snd_pcm_format_t) 46)
-#define SNDRV_PCM_FORMAT_G723_40_1B ((__force snd_pcm_format_t) 47)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_G723_40_1B ((__force snd_pcm_format_t) 47)
 #define SNDRV_PCM_FORMAT_DSD_U8 ((__force snd_pcm_format_t) 48)
 #define SNDRV_PCM_FORMAT_DSD_U16_LE ((__force snd_pcm_format_t) 49)
 #define SNDRV_PCM_FORMAT_LAST SNDRV_PCM_FORMAT_DSD_U16_LE
-#ifdef SNDRV_LITTLE_ENDIAN
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifdef SNDRV_LITTLE_ENDIAN
 #define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_LE
 #define SNDRV_PCM_FORMAT_U16 SNDRV_PCM_FORMAT_U16_LE
 #define SNDRV_PCM_FORMAT_S24 SNDRV_PCM_FORMAT_S24_LE
-#define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_LE
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_LE
 #define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_LE
 #define SNDRV_PCM_FORMAT_U32 SNDRV_PCM_FORMAT_U32_LE
 #define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_LE
-#define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_LE
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_LE
 #define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE
 #endif
 #ifdef SNDRV_BIG_ENDIAN
-#define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_BE
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_BE
 #define SNDRV_PCM_FORMAT_U16 SNDRV_PCM_FORMAT_U16_BE
 #define SNDRV_PCM_FORMAT_S24 SNDRV_PCM_FORMAT_S24_BE
 #define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_BE
-#define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_BE
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_BE
 #define SNDRV_PCM_FORMAT_U32 SNDRV_PCM_FORMAT_U32_BE
 #define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_BE
 #define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_BE
-#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE
 #endif
 typedef int __bitwise snd_pcm_subformat_t;
 #define SNDRV_PCM_SUBFORMAT_STD ((__force snd_pcm_subformat_t) 0)
-#define SNDRV_PCM_SUBFORMAT_LAST SNDRV_PCM_SUBFORMAT_STD
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_SUBFORMAT_LAST SNDRV_PCM_SUBFORMAT_STD
 #define SNDRV_PCM_INFO_MMAP 0x00000001
 #define SNDRV_PCM_INFO_MMAP_VALID 0x00000002
 #define SNDRV_PCM_INFO_DOUBLE 0x00000004
-#define SNDRV_PCM_INFO_BATCH 0x00000010
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_INFO_BATCH 0x00000010
 #define SNDRV_PCM_INFO_INTERLEAVED 0x00000100
 #define SNDRV_PCM_INFO_NONINTERLEAVED 0x00000200
 #define SNDRV_PCM_INFO_COMPLEX 0x00000400
-#define SNDRV_PCM_INFO_BLOCK_TRANSFER 0x00010000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_INFO_BLOCK_TRANSFER 0x00010000
 #define SNDRV_PCM_INFO_OVERRANGE 0x00020000
 #define SNDRV_PCM_INFO_RESUME 0x00040000
 #define SNDRV_PCM_INFO_PAUSE 0x00080000
-#define SNDRV_PCM_INFO_HALF_DUPLEX 0x00100000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_INFO_HALF_DUPLEX 0x00100000
 #define SNDRV_PCM_INFO_JOINT_DUPLEX 0x00200000
 #define SNDRV_PCM_INFO_SYNC_START 0x00400000
 #define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP 0x00800000
-#define SNDRV_PCM_INFO_HAS_WALL_CLOCK 0x01000000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_INFO_HAS_WALL_CLOCK 0x01000000
 #define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000
 typedef int __bitwise snd_pcm_state_t;
 #define SNDRV_PCM_STATE_OPEN ((__force snd_pcm_state_t) 0)
-#define SNDRV_PCM_STATE_SETUP ((__force snd_pcm_state_t) 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_STATE_SETUP ((__force snd_pcm_state_t) 1)
 #define SNDRV_PCM_STATE_PREPARED ((__force snd_pcm_state_t) 2)
 #define SNDRV_PCM_STATE_RUNNING ((__force snd_pcm_state_t) 3)
 #define SNDRV_PCM_STATE_XRUN ((__force snd_pcm_state_t) 4)
-#define SNDRV_PCM_STATE_DRAINING ((__force snd_pcm_state_t) 5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_STATE_DRAINING ((__force snd_pcm_state_t) 5)
 #define SNDRV_PCM_STATE_PAUSED ((__force snd_pcm_state_t) 6)
 #define SNDRV_PCM_STATE_SUSPENDED ((__force snd_pcm_state_t) 7)
 #define SNDRV_PCM_STATE_DISCONNECTED ((__force snd_pcm_state_t) 8)
-#define SNDRV_PCM_STATE_LAST SNDRV_PCM_STATE_DISCONNECTED
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_STATE_LAST SNDRV_PCM_STATE_DISCONNECTED
 enum {
  SNDRV_PCM_MMAP_OFFSET_DATA = 0x00000000,
  SNDRV_PCM_MMAP_OFFSET_STATUS = 0x80000000,
- SNDRV_PCM_MMAP_OFFSET_CONTROL = 0x81000000,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_PCM_MMAP_OFFSET_CONTROL = 0x81000000,
 };
 union snd_pcm_sync_id {
  unsigned char id[16];
- unsigned short id16[8];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned short id16[8];
  unsigned int id32[4];
 };
 struct snd_pcm_info {
- unsigned int device;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int device;
  unsigned int subdevice;
  int stream;
  int card;
- unsigned char id[64];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char id[64];
  unsigned char name[80];
  unsigned char subname[32];
  int dev_class;
- int dev_subclass;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int dev_subclass;
  unsigned int subdevices_count;
  unsigned int subdevices_avail;
  union snd_pcm_sync_id sync;
- unsigned char reserved[64];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char reserved[64];
 };
 typedef int snd_pcm_hw_param_t;
 #define SNDRV_PCM_HW_PARAM_ACCESS 0
-#define SNDRV_PCM_HW_PARAM_FORMAT 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_HW_PARAM_FORMAT 1
 #define SNDRV_PCM_HW_PARAM_SUBFORMAT 2
 #define SNDRV_PCM_HW_PARAM_FIRST_MASK SNDRV_PCM_HW_PARAM_ACCESS
 #define SNDRV_PCM_HW_PARAM_LAST_MASK SNDRV_PCM_HW_PARAM_SUBFORMAT
-#define SNDRV_PCM_HW_PARAM_SAMPLE_BITS 8
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_HW_PARAM_SAMPLE_BITS 8
 #define SNDRV_PCM_HW_PARAM_FRAME_BITS 9
 #define SNDRV_PCM_HW_PARAM_CHANNELS 10
 #define SNDRV_PCM_HW_PARAM_RATE 11
-#define SNDRV_PCM_HW_PARAM_PERIOD_TIME 12
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_HW_PARAM_PERIOD_TIME 12
 #define SNDRV_PCM_HW_PARAM_PERIOD_SIZE 13
 #define SNDRV_PCM_HW_PARAM_PERIOD_BYTES 14
 #define SNDRV_PCM_HW_PARAM_PERIODS 15
-#define SNDRV_PCM_HW_PARAM_BUFFER_TIME 16
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_HW_PARAM_BUFFER_TIME 16
 #define SNDRV_PCM_HW_PARAM_BUFFER_SIZE 17
 #define SNDRV_PCM_HW_PARAM_BUFFER_BYTES 18
 #define SNDRV_PCM_HW_PARAM_TICK_TIME 19
-#define SNDRV_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_SAMPLE_BITS
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_SAMPLE_BITS
 #define SNDRV_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_TICK_TIME
 #define SNDRV_PCM_HW_PARAMS_NORESAMPLE (1<<0)
 #define SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER (1<<1)
-#define SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP (1<<2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP (1<<2)
 struct snd_interval {
  unsigned int min, max;
  unsigned int openmin:1,
- openmax:1,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ openmax:1,
  integer:1,
  empty:1;
 };
-#define SNDRV_MASK_MAX 256
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_MASK_MAX 256
 struct snd_mask {
  __u32 bits[(SNDRV_MASK_MAX+31)/32];
 };
-struct snd_pcm_hw_params {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_pcm_hw_params {
  unsigned int flags;
  struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -
  SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
- struct snd_mask mres[5];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct snd_mask mres[5];
  struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL -
  SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
  struct snd_interval ires[9];
- unsigned int rmask;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int rmask;
  unsigned int cmask;
  unsigned int info;
  unsigned int msbits;
- unsigned int rate_num;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int rate_num;
  unsigned int rate_den;
  snd_pcm_uframes_t fifo_size;
  unsigned char reserved[64];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  SNDRV_PCM_TSTAMP_NONE = 0,
  SNDRV_PCM_TSTAMP_ENABLE,
- SNDRV_PCM_TSTAMP_LAST = SNDRV_PCM_TSTAMP_ENABLE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_PCM_TSTAMP_LAST = SNDRV_PCM_TSTAMP_ENABLE,
 };
 struct snd_pcm_sw_params {
  int tstamp_mode;
- unsigned int period_step;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int period_step;
  unsigned int sleep_min;
  snd_pcm_uframes_t avail_min;
  snd_pcm_uframes_t xfer_align;
- snd_pcm_uframes_t start_threshold;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ snd_pcm_uframes_t start_threshold;
  snd_pcm_uframes_t stop_threshold;
  snd_pcm_uframes_t silence_threshold;
  snd_pcm_uframes_t silence_size;
- snd_pcm_uframes_t boundary;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ snd_pcm_uframes_t boundary;
  unsigned char reserved[64];
 };
 struct snd_pcm_channel_info {
- unsigned int channel;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int channel;
  __kernel_off_t offset;
  unsigned int first;
  unsigned int step;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct snd_pcm_status {
  snd_pcm_state_t state;
  struct timespec trigger_tstamp;
- struct timespec tstamp;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct timespec tstamp;
  snd_pcm_uframes_t appl_ptr;
  snd_pcm_uframes_t hw_ptr;
  snd_pcm_sframes_t delay;
- snd_pcm_uframes_t avail;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ snd_pcm_uframes_t avail;
  snd_pcm_uframes_t avail_max;
  snd_pcm_uframes_t overrange;
  snd_pcm_state_t suspended_state;
- __u32 reserved_alignment;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 reserved_alignment;
  struct timespec audio_tstamp;
  unsigned char reserved[56-sizeof(struct timespec)];
 };
-struct snd_pcm_mmap_status {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_pcm_mmap_status {
  snd_pcm_state_t state;
  int pad1;
  snd_pcm_uframes_t hw_ptr;
- struct timespec tstamp;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct timespec tstamp;
  snd_pcm_state_t suspended_state;
  struct timespec audio_tstamp;
 };
-struct snd_pcm_mmap_control {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_pcm_mmap_control {
  snd_pcm_uframes_t appl_ptr;
  snd_pcm_uframes_t avail_min;
 };
-#define SNDRV_PCM_SYNC_PTR_HWSYNC (1<<0)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_SYNC_PTR_HWSYNC (1<<0)
 #define SNDRV_PCM_SYNC_PTR_APPL (1<<1)
 #define SNDRV_PCM_SYNC_PTR_AVAIL_MIN (1<<2)
 struct snd_pcm_sync_ptr {
- unsigned int flags;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int flags;
  union {
  struct snd_pcm_mmap_status status;
  unsigned char reserved[64];
- } s;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ } s;
  union {
  struct snd_pcm_mmap_control control;
  unsigned char reserved[64];
- } c;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ } c;
 };
 struct snd_xferi {
  snd_pcm_sframes_t result;
- void __user *buf;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ void __user *buf;
  snd_pcm_uframes_t frames;
 };
 struct snd_xfern {
- snd_pcm_sframes_t result;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ snd_pcm_sframes_t result;
  void __user * __user *bufs;
  snd_pcm_uframes_t frames;
 };
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0,
  SNDRV_PCM_TSTAMP_TYPE_MONOTONIC,
  SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 enum {
  SNDRV_CHMAP_UNKNOWN = 0,
  SNDRV_CHMAP_NA,
- SNDRV_CHMAP_MONO,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_MONO,
  SNDRV_CHMAP_FL,
  SNDRV_CHMAP_FR,
  SNDRV_CHMAP_RL,
- SNDRV_CHMAP_RR,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_RR,
  SNDRV_CHMAP_FC,
  SNDRV_CHMAP_LFE,
  SNDRV_CHMAP_SL,
- SNDRV_CHMAP_SR,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_SR,
  SNDRV_CHMAP_RC,
  SNDRV_CHMAP_FLC,
  SNDRV_CHMAP_FRC,
- SNDRV_CHMAP_RLC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_RLC,
  SNDRV_CHMAP_RRC,
  SNDRV_CHMAP_FLW,
  SNDRV_CHMAP_FRW,
- SNDRV_CHMAP_FLH,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_FLH,
  SNDRV_CHMAP_FCH,
  SNDRV_CHMAP_FRH,
  SNDRV_CHMAP_TC,
- SNDRV_CHMAP_TFL,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_TFL,
  SNDRV_CHMAP_TFR,
  SNDRV_CHMAP_TFC,
  SNDRV_CHMAP_TRL,
- SNDRV_CHMAP_TRR,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_TRR,
  SNDRV_CHMAP_TRC,
  SNDRV_CHMAP_TFLC,
  SNDRV_CHMAP_TFRC,
- SNDRV_CHMAP_TSL,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_TSL,
  SNDRV_CHMAP_TSR,
  SNDRV_CHMAP_LLFE,
  SNDRV_CHMAP_RLFE,
- SNDRV_CHMAP_BC,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_CHMAP_BC,
  SNDRV_CHMAP_BLC,
  SNDRV_CHMAP_BRC,
  SNDRV_CHMAP_LAST = SNDRV_CHMAP_BRC,
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define SNDRV_CHMAP_POSITION_MASK 0xffff
 #define SNDRV_CHMAP_PHASE_INVERSE (0x01 << 16)
 #define SNDRV_CHMAP_DRIVER_SPEC (0x02 << 16)
-#define SNDRV_PCM_IOCTL_PVERSION _IOR('A', 0x00, int)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_IOCTL_PVERSION _IOR('A', 0x00, int)
 #define SNDRV_PCM_IOCTL_INFO _IOR('A', 0x01, struct snd_pcm_info)
 #define SNDRV_PCM_IOCTL_TSTAMP _IOW('A', 0x02, int)
 #define SNDRV_PCM_IOCTL_TTSTAMP _IOW('A', 0x03, int)
-#define SNDRV_PCM_IOCTL_HW_REFINE _IOWR('A', 0x10, struct snd_pcm_hw_params)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_IOCTL_HW_REFINE _IOWR('A', 0x10, struct snd_pcm_hw_params)
 #define SNDRV_PCM_IOCTL_HW_PARAMS _IOWR('A', 0x11, struct snd_pcm_hw_params)
 #define SNDRV_PCM_IOCTL_HW_FREE _IO('A', 0x12)
 #define SNDRV_PCM_IOCTL_SW_PARAMS _IOWR('A', 0x13, struct snd_pcm_sw_params)
-#define SNDRV_PCM_IOCTL_STATUS _IOR('A', 0x20, struct snd_pcm_status)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_IOCTL_STATUS _IOR('A', 0x20, struct snd_pcm_status)
 #define SNDRV_PCM_IOCTL_DELAY _IOR('A', 0x21, snd_pcm_sframes_t)
 #define SNDRV_PCM_IOCTL_HWSYNC _IO('A', 0x22)
 #define SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct snd_pcm_sync_ptr)
-#define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info)
 #define SNDRV_PCM_IOCTL_PREPARE _IO('A', 0x40)
 #define SNDRV_PCM_IOCTL_RESET _IO('A', 0x41)
 #define SNDRV_PCM_IOCTL_START _IO('A', 0x42)
-#define SNDRV_PCM_IOCTL_DROP _IO('A', 0x43)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_IOCTL_DROP _IO('A', 0x43)
 #define SNDRV_PCM_IOCTL_DRAIN _IO('A', 0x44)
 #define SNDRV_PCM_IOCTL_PAUSE _IOW('A', 0x45, int)
 #define SNDRV_PCM_IOCTL_REWIND _IOW('A', 0x46, snd_pcm_uframes_t)
-#define SNDRV_PCM_IOCTL_RESUME _IO('A', 0x47)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_IOCTL_RESUME _IO('A', 0x47)
 #define SNDRV_PCM_IOCTL_XRUN _IO('A', 0x48)
 #define SNDRV_PCM_IOCTL_FORWARD _IOW('A', 0x49, snd_pcm_uframes_t)
 #define SNDRV_PCM_IOCTL_WRITEI_FRAMES _IOW('A', 0x50, struct snd_xferi)
-#define SNDRV_PCM_IOCTL_READI_FRAMES _IOR('A', 0x51, struct snd_xferi)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_IOCTL_READI_FRAMES _IOR('A', 0x51, struct snd_xferi)
 #define SNDRV_PCM_IOCTL_WRITEN_FRAMES _IOW('A', 0x52, struct snd_xfern)
 #define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern)
 #define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int)
-#define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61)
 #define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 0)
 enum {
  SNDRV_RAWMIDI_STREAM_OUTPUT = 0,
- SNDRV_RAWMIDI_STREAM_INPUT,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_RAWMIDI_STREAM_INPUT,
  SNDRV_RAWMIDI_STREAM_LAST = SNDRV_RAWMIDI_STREAM_INPUT,
 };
 #define SNDRV_RAWMIDI_INFO_OUTPUT 0x00000001
-#define SNDRV_RAWMIDI_INFO_INPUT 0x00000002
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_RAWMIDI_INFO_INPUT 0x00000002
 #define SNDRV_RAWMIDI_INFO_DUPLEX 0x00000004
 struct snd_rawmidi_info {
  unsigned int device;
- unsigned int subdevice;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int subdevice;
  int stream;
  int card;
  unsigned int flags;
- unsigned char id[64];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char id[64];
  unsigned char name[80];
  unsigned char subname[32];
  unsigned int subdevices_count;
- unsigned int subdevices_avail;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int subdevices_avail;
  unsigned char reserved[64];
 };
 struct snd_rawmidi_params {
- int stream;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int stream;
  size_t buffer_size;
  size_t avail_min;
  unsigned int no_active_sensing: 1;
- unsigned char reserved[16];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char reserved[16];
 };
 struct snd_rawmidi_status {
  int stream;
- struct timespec tstamp;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct timespec tstamp;
  size_t avail;
  size_t xruns;
  unsigned char reserved[16];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define SNDRV_RAWMIDI_IOCTL_PVERSION _IOR('W', 0x00, int)
 #define SNDRV_RAWMIDI_IOCTL_INFO _IOR('W', 0x01, struct snd_rawmidi_info)
 #define SNDRV_RAWMIDI_IOCTL_PARAMS _IOWR('W', 0x10, struct snd_rawmidi_params)
-#define SNDRV_RAWMIDI_IOCTL_STATUS _IOWR('W', 0x20, struct snd_rawmidi_status)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_RAWMIDI_IOCTL_STATUS _IOWR('W', 0x20, struct snd_rawmidi_status)
 #define SNDRV_RAWMIDI_IOCTL_DROP _IOW('W', 0x30, int)
 #define SNDRV_RAWMIDI_IOCTL_DRAIN _IOW('W', 0x31, int)
 #define SNDRV_TIMER_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 6)
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  SNDRV_TIMER_CLASS_NONE = -1,
  SNDRV_TIMER_CLASS_SLAVE = 0,
  SNDRV_TIMER_CLASS_GLOBAL,
- SNDRV_TIMER_CLASS_CARD,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_TIMER_CLASS_CARD,
  SNDRV_TIMER_CLASS_PCM,
  SNDRV_TIMER_CLASS_LAST = SNDRV_TIMER_CLASS_PCM,
 };
-enum {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
  SNDRV_TIMER_SCLASS_NONE = 0,
  SNDRV_TIMER_SCLASS_APPLICATION,
  SNDRV_TIMER_SCLASS_SEQUENCER,
- SNDRV_TIMER_SCLASS_OSS_SEQUENCER,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_TIMER_SCLASS_OSS_SEQUENCER,
  SNDRV_TIMER_SCLASS_LAST = SNDRV_TIMER_SCLASS_OSS_SEQUENCER,
 };
 #define SNDRV_TIMER_GLOBAL_SYSTEM 0
-#define SNDRV_TIMER_GLOBAL_RTC 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_TIMER_GLOBAL_RTC 1
 #define SNDRV_TIMER_GLOBAL_HPET 2
 #define SNDRV_TIMER_GLOBAL_HRTIMER 3
 #define SNDRV_TIMER_FLG_SLAVE (1<<0)
-struct snd_timer_id {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_timer_id {
  int dev_class;
  int dev_sclass;
  int card;
- int device;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int device;
  int subdevice;
 };
 struct snd_timer_ginfo {
- struct snd_timer_id tid;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct snd_timer_id tid;
  unsigned int flags;
  int card;
  unsigned char id[64];
- unsigned char name[80];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char name[80];
  unsigned long reserved0;
  unsigned long resolution;
  unsigned long resolution_min;
- unsigned long resolution_max;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long resolution_max;
  unsigned int clients;
  unsigned char reserved[32];
 };
-struct snd_timer_gparams {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_timer_gparams {
  struct snd_timer_id tid;
  unsigned long period_num;
  unsigned long period_den;
- unsigned char reserved[32];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char reserved[32];
 };
 struct snd_timer_gstatus {
  struct snd_timer_id tid;
- unsigned long resolution;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned long resolution;
  unsigned long resolution_num;
  unsigned long resolution_den;
  unsigned char reserved[32];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct snd_timer_select {
  struct snd_timer_id id;
  unsigned char reserved[32];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct snd_timer_info {
  unsigned int flags;
  int card;
- unsigned char id[64];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char id[64];
  unsigned char name[80];
  unsigned long reserved0;
  unsigned long resolution;
- unsigned char reserved[64];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char reserved[64];
 };
 #define SNDRV_TIMER_PSFLG_AUTO (1<<0)
 #define SNDRV_TIMER_PSFLG_EXCLUSIVE (1<<1)
-#define SNDRV_TIMER_PSFLG_EARLY_EVENT (1<<2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_TIMER_PSFLG_EARLY_EVENT (1<<2)
 struct snd_timer_params {
  unsigned int flags;
  unsigned int ticks;
- unsigned int queue_size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int queue_size;
  unsigned int reserved0;
  unsigned int filter;
  unsigned char reserved[60];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct snd_timer_status {
  struct timespec tstamp;
  unsigned int resolution;
- unsigned int lost;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int lost;
  unsigned int overrun;
  unsigned int queue;
  unsigned char reserved[64];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define SNDRV_TIMER_IOCTL_PVERSION _IOR('T', 0x00, int)
 #define SNDRV_TIMER_IOCTL_NEXT_DEVICE _IOWR('T', 0x01, struct snd_timer_id)
 #define SNDRV_TIMER_IOCTL_TREAD _IOW('T', 0x02, int)
-#define SNDRV_TIMER_IOCTL_GINFO _IOWR('T', 0x03, struct snd_timer_ginfo)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_TIMER_IOCTL_GINFO _IOWR('T', 0x03, struct snd_timer_ginfo)
 #define SNDRV_TIMER_IOCTL_GPARAMS _IOW('T', 0x04, struct snd_timer_gparams)
 #define SNDRV_TIMER_IOCTL_GSTATUS _IOWR('T', 0x05, struct snd_timer_gstatus)
 #define SNDRV_TIMER_IOCTL_SELECT _IOW('T', 0x10, struct snd_timer_select)
-#define SNDRV_TIMER_IOCTL_INFO _IOR('T', 0x11, struct snd_timer_info)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_TIMER_IOCTL_INFO _IOR('T', 0x11, struct snd_timer_info)
 #define SNDRV_TIMER_IOCTL_PARAMS _IOW('T', 0x12, struct snd_timer_params)
 #define SNDRV_TIMER_IOCTL_STATUS _IOR('T', 0x14, struct snd_timer_status)
 #define SNDRV_TIMER_IOCTL_START _IO('T', 0xa0)
-#define SNDRV_TIMER_IOCTL_STOP _IO('T', 0xa1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_TIMER_IOCTL_STOP _IO('T', 0xa1)
 #define SNDRV_TIMER_IOCTL_CONTINUE _IO('T', 0xa2)
 #define SNDRV_TIMER_IOCTL_PAUSE _IO('T', 0xa3)
 struct snd_timer_read {
- unsigned int resolution;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int resolution;
  unsigned int ticks;
 };
 enum {
- SNDRV_TIMER_EVENT_RESOLUTION = 0,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_TIMER_EVENT_RESOLUTION = 0,
  SNDRV_TIMER_EVENT_TICK,
  SNDRV_TIMER_EVENT_START,
  SNDRV_TIMER_EVENT_STOP,
- SNDRV_TIMER_EVENT_CONTINUE,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_TIMER_EVENT_CONTINUE,
  SNDRV_TIMER_EVENT_PAUSE,
  SNDRV_TIMER_EVENT_EARLY,
  SNDRV_TIMER_EVENT_SUSPEND,
- SNDRV_TIMER_EVENT_RESUME,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_TIMER_EVENT_RESUME,
  SNDRV_TIMER_EVENT_MSTART = SNDRV_TIMER_EVENT_START + 10,
  SNDRV_TIMER_EVENT_MSTOP = SNDRV_TIMER_EVENT_STOP + 10,
  SNDRV_TIMER_EVENT_MCONTINUE = SNDRV_TIMER_EVENT_CONTINUE + 10,
- SNDRV_TIMER_EVENT_MPAUSE = SNDRV_TIMER_EVENT_PAUSE + 10,
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SNDRV_TIMER_EVENT_MPAUSE = SNDRV_TIMER_EVENT_PAUSE + 10,
  SNDRV_TIMER_EVENT_MSUSPEND = SNDRV_TIMER_EVENT_SUSPEND + 10,
  SNDRV_TIMER_EVENT_MRESUME = SNDRV_TIMER_EVENT_RESUME + 10,
 };
-struct snd_timer_tread {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_timer_tread {
  int event;
  struct timespec tstamp;
  unsigned int val;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 #define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 7)
 struct snd_ctl_card_info {
  int card;
- int pad;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int pad;
  unsigned char id[16];
  unsigned char driver[16];
  unsigned char name[32];
- unsigned char longname[80];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char longname[80];
  unsigned char reserved_[16];
  unsigned char mixername[80];
  unsigned char components[128];
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 typedef int __bitwise snd_ctl_elem_type_t;
 #define SNDRV_CTL_ELEM_TYPE_NONE ((__force snd_ctl_elem_type_t) 0)
 #define SNDRV_CTL_ELEM_TYPE_BOOLEAN ((__force snd_ctl_elem_type_t) 1)
-#define SNDRV_CTL_ELEM_TYPE_INTEGER ((__force snd_ctl_elem_type_t) 2)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_ELEM_TYPE_INTEGER ((__force snd_ctl_elem_type_t) 2)
 #define SNDRV_CTL_ELEM_TYPE_ENUMERATED ((__force snd_ctl_elem_type_t) 3)
 #define SNDRV_CTL_ELEM_TYPE_BYTES ((__force snd_ctl_elem_type_t) 4)
 #define SNDRV_CTL_ELEM_TYPE_IEC958 ((__force snd_ctl_elem_type_t) 5)
-#define SNDRV_CTL_ELEM_TYPE_INTEGER64 ((__force snd_ctl_elem_type_t) 6)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_ELEM_TYPE_INTEGER64 ((__force snd_ctl_elem_type_t) 6)
 #define SNDRV_CTL_ELEM_TYPE_LAST SNDRV_CTL_ELEM_TYPE_INTEGER64
 typedef int __bitwise snd_ctl_elem_iface_t;
 #define SNDRV_CTL_ELEM_IFACE_CARD ((__force snd_ctl_elem_iface_t) 0)
-#define SNDRV_CTL_ELEM_IFACE_HWDEP ((__force snd_ctl_elem_iface_t) 1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_ELEM_IFACE_HWDEP ((__force snd_ctl_elem_iface_t) 1)
 #define SNDRV_CTL_ELEM_IFACE_MIXER ((__force snd_ctl_elem_iface_t) 2)
 #define SNDRV_CTL_ELEM_IFACE_PCM ((__force snd_ctl_elem_iface_t) 3)
 #define SNDRV_CTL_ELEM_IFACE_RAWMIDI ((__force snd_ctl_elem_iface_t) 4)
-#define SNDRV_CTL_ELEM_IFACE_TIMER ((__force snd_ctl_elem_iface_t) 5)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_ELEM_IFACE_TIMER ((__force snd_ctl_elem_iface_t) 5)
 #define SNDRV_CTL_ELEM_IFACE_SEQUENCER ((__force snd_ctl_elem_iface_t) 6)
 #define SNDRV_CTL_ELEM_IFACE_LAST SNDRV_CTL_ELEM_IFACE_SEQUENCER
 #define SNDRV_CTL_ELEM_ACCESS_READ (1<<0)
-#define SNDRV_CTL_ELEM_ACCESS_WRITE (1<<1)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_ELEM_ACCESS_WRITE (1<<1)
 #define SNDRV_CTL_ELEM_ACCESS_READWRITE (SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE)
 #define SNDRV_CTL_ELEM_ACCESS_VOLATILE (1<<2)
 #define SNDRV_CTL_ELEM_ACCESS_TIMESTAMP (1<<3)
-#define SNDRV_CTL_ELEM_ACCESS_TLV_READ (1<<4)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_ELEM_ACCESS_TLV_READ (1<<4)
 #define SNDRV_CTL_ELEM_ACCESS_TLV_WRITE (1<<5)
 #define SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE (SNDRV_CTL_ELEM_ACCESS_TLV_READ|SNDRV_CTL_ELEM_ACCESS_TLV_WRITE)
 #define SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND (1<<6)
-#define SNDRV_CTL_ELEM_ACCESS_INACTIVE (1<<8)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_ELEM_ACCESS_INACTIVE (1<<8)
 #define SNDRV_CTL_ELEM_ACCESS_LOCK (1<<9)
 #define SNDRV_CTL_ELEM_ACCESS_OWNER (1<<10)
 #define SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK (1<<28)
-#define SNDRV_CTL_ELEM_ACCESS_USER (1<<29)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_ELEM_ACCESS_USER (1<<29)
 #define SNDRV_CTL_POWER_D0 0x0000
 #define SNDRV_CTL_POWER_D1 0x0100
 #define SNDRV_CTL_POWER_D2 0x0200
-#define SNDRV_CTL_POWER_D3 0x0300
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_CTL_POWER_D3 0x0300
 #define SNDRV_CTL_POWER_D3hot (SNDRV_CTL_POWER_D3|0x0000)
 #define SNDRV_CTL_POWER_D3cold (SNDRV_CTL_POWER_D3|0x0001)
+#define SNDRV_CTL_ELEM_ID_NAME_MAXLEN 44
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct snd_ctl_elem_id {
  unsigned int numid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  snd_ctl_elem_iface_t iface;
  unsigned int device;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int subdevice;
  unsigned char name[44];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int index;
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct snd_ctl_elem_list {
  unsigned int offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int space;
  unsigned int used;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int count;
  struct snd_ctl_elem_id __user *pids;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char reserved[50];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct snd_ctl_elem_info {
  struct snd_ctl_elem_id id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  snd_ctl_elem_type_t type;
  unsigned int access;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int count;
  __kernel_pid_t owner;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  long min;
  long max;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  long step;
  } integer;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct {
  long long min;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  long long max;
  long long step;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } integer64;
  struct {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int items;
  unsigned int item;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  char name[64];
  __u64 names_ptr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int names_length;
  } enumerated;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char reserved[128];
  } value;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  unsigned short d[4];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned short *d_ptr;
  } dimen;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char reserved[64-4*sizeof(unsigned short)];
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct snd_ctl_elem_value {
  struct snd_ctl_elem_id id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int indirect: 1;
  union {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  long value[128];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  long *value_ptr;
  } integer;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  long long value[64];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  long long *value_ptr;
  } integer64;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  unsigned int item[128];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int *item_ptr;
  } enumerated;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  unsigned char data[512];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned char *data_ptr;
  } bytes;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct snd_aes_iec958 iec958;
  } value;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct timespec tstamp;
  unsigned char reserved[128-sizeof(struct timespec)];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 struct snd_ctl_tlv {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int numid;
  unsigned int length;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int tlv[0];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_PVERSION _IOR('U', 0x00, int)
 #define SNDRV_CTL_IOCTL_CARD_INFO _IOR('U', 0x01, struct snd_ctl_card_info)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_ELEM_LIST _IOWR('U', 0x10, struct snd_ctl_elem_list)
 #define SNDRV_CTL_IOCTL_ELEM_INFO _IOWR('U', 0x11, struct snd_ctl_elem_info)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_ELEM_READ _IOWR('U', 0x12, struct snd_ctl_elem_value)
 #define SNDRV_CTL_IOCTL_ELEM_WRITE _IOWR('U', 0x13, struct snd_ctl_elem_value)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_ELEM_LOCK _IOW('U', 0x14, struct snd_ctl_elem_id)
 #define SNDRV_CTL_IOCTL_ELEM_UNLOCK _IOW('U', 0x15, struct snd_ctl_elem_id)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS _IOWR('U', 0x16, int)
 #define SNDRV_CTL_IOCTL_ELEM_ADD _IOWR('U', 0x17, struct snd_ctl_elem_info)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_ELEM_REPLACE _IOWR('U', 0x18, struct snd_ctl_elem_info)
 #define SNDRV_CTL_IOCTL_ELEM_REMOVE _IOWR('U', 0x19, struct snd_ctl_elem_id)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_TLV_READ _IOWR('U', 0x1a, struct snd_ctl_tlv)
 #define SNDRV_CTL_IOCTL_TLV_WRITE _IOWR('U', 0x1b, struct snd_ctl_tlv)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_TLV_COMMAND _IOWR('U', 0x1c, struct snd_ctl_tlv)
 #define SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE _IOWR('U', 0x20, int)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_HWDEP_INFO _IOR('U', 0x21, struct snd_hwdep_info)
 #define SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE _IOR('U', 0x30, int)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_PCM_INFO _IOWR('U', 0x31, struct snd_pcm_info)
 #define SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE _IOW('U', 0x32, int)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE _IOWR('U', 0x40, int)
 #define SNDRV_CTL_IOCTL_RAWMIDI_INFO _IOWR('U', 0x41, struct snd_rawmidi_info)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE _IOW('U', 0x42, int)
 #define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int)
 enum sndrv_ctl_event_type {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  SNDRV_CTL_EVENT_ELEM = 0,
  SNDRV_CTL_EVENT_LAST = SNDRV_CTL_EVENT_ELEM,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define SNDRV_CTL_EVENT_MASK_VALUE (1<<0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_EVENT_MASK_INFO (1<<1)
 #define SNDRV_CTL_EVENT_MASK_ADD (1<<2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_EVENT_MASK_TLV (1<<3)
 #define SNDRV_CTL_EVENT_MASK_REMOVE (~0U)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct snd_ctl_event {
  int type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union {
  struct {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  unsigned int mask;
  struct snd_ctl_elem_id id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } elem;
  unsigned char data8[60];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  } data;
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_NAME_NONE ""
 #define SNDRV_CTL_NAME_PLAYBACK "Playback "
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_NAME_CAPTURE "Capture "
 #define SNDRV_CTL_NAME_IEC958_NONE ""
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_NAME_IEC958_SWITCH "Switch"
 #define SNDRV_CTL_NAME_IEC958_VOLUME "Volume"
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_NAME_IEC958_DEFAULT "Default"
 #define SNDRV_CTL_NAME_IEC958_MASK "Mask"
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_NAME_IEC958_CON_MASK "Con Mask"
 #define SNDRV_CTL_NAME_IEC958_PRO_MASK "Pro Mask"
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SNDRV_CTL_NAME_IEC958_PCM_STREAM "PCM Stream"
 #define SNDRV_CTL_NAME_IEC958(expl,direction,what) "IEC958 " expl SNDRV_CTL_NAME_##direction SNDRV_CTL_NAME_IEC958_##what
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/sound/compress_offload.h b/libc/kernel/uapi/sound/compress_offload.h
index c141b7a..5b06741 100644
--- a/libc/kernel/uapi/sound/compress_offload.h
+++ b/libc/kernel/uapi/sound/compress_offload.h
@@ -22,7 +22,7 @@
 #include <sound/asound.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #include <sound/compress_params.h>
-#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 1)
+#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 2)
 struct snd_compressed_buffer {
  __u32 fragment_size;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -38,8 +38,8 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 byte_offset;
  __u32 copied_total;
- snd_pcm_uframes_t pcm_frames;
- snd_pcm_uframes_t pcm_io_frames;
+ __u32 pcm_frames;
+ __u32 pcm_io_frames;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 sampling_rate;
 };
diff --git a/libc/kernel/uapi/sound/compress_params.h b/libc/kernel/uapi/sound/compress_params.h
index 0bce9a0..8aa0bfe 100644
--- a/libc/kernel/uapi/sound/compress_params.h
+++ b/libc/kernel/uapi/sound/compress_params.h
@@ -23,221 +23,223 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define MAX_NUM_CODEC_DESCRIPTORS 32
 #define MAX_NUM_BITRATES 32
+#define MAX_NUM_SAMPLE_RATES 32
 #define SND_AUDIOCODEC_PCM ((__u32) 0x00000001)
-#define SND_AUDIOCODEC_MP3 ((__u32) 0x00000002)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOCODEC_MP3 ((__u32) 0x00000002)
 #define SND_AUDIOCODEC_AMR ((__u32) 0x00000003)
 #define SND_AUDIOCODEC_AMRWB ((__u32) 0x00000004)
 #define SND_AUDIOCODEC_AMRWBPLUS ((__u32) 0x00000005)
-#define SND_AUDIOCODEC_AAC ((__u32) 0x00000006)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOCODEC_AAC ((__u32) 0x00000006)
 #define SND_AUDIOCODEC_WMA ((__u32) 0x00000007)
 #define SND_AUDIOCODEC_REAL ((__u32) 0x00000008)
 #define SND_AUDIOCODEC_VORBIS ((__u32) 0x00000009)
-#define SND_AUDIOCODEC_FLAC ((__u32) 0x0000000A)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOCODEC_FLAC ((__u32) 0x0000000A)
 #define SND_AUDIOCODEC_IEC61937 ((__u32) 0x0000000B)
 #define SND_AUDIOCODEC_G723_1 ((__u32) 0x0000000C)
 #define SND_AUDIOCODEC_G729 ((__u32) 0x0000000D)
-#define SND_AUDIOCODEC_MAX SND_AUDIOCODEC_G729
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOCODEC_MAX SND_AUDIOCODEC_G729
 #define SND_AUDIOPROFILE_PCM ((__u32) 0x00000001)
 #define SND_AUDIOCHANMODE_MP3_MONO ((__u32) 0x00000001)
 #define SND_AUDIOCHANMODE_MP3_STEREO ((__u32) 0x00000002)
-#define SND_AUDIOCHANMODE_MP3_JOINTSTEREO ((__u32) 0x00000004)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOCHANMODE_MP3_JOINTSTEREO ((__u32) 0x00000004)
 #define SND_AUDIOCHANMODE_MP3_DUAL ((__u32) 0x00000008)
 #define SND_AUDIOPROFILE_AMR ((__u32) 0x00000001)
 #define SND_AUDIOMODE_AMR_DTX_OFF ((__u32) 0x00000001)
-#define SND_AUDIOMODE_AMR_VAD1 ((__u32) 0x00000002)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_AMR_VAD1 ((__u32) 0x00000002)
 #define SND_AUDIOMODE_AMR_VAD2 ((__u32) 0x00000004)
 #define SND_AUDIOSTREAMFORMAT_UNDEFINED ((__u32) 0x00000000)
 #define SND_AUDIOSTREAMFORMAT_CONFORMANCE ((__u32) 0x00000001)
-#define SND_AUDIOSTREAMFORMAT_IF1 ((__u32) 0x00000002)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOSTREAMFORMAT_IF1 ((__u32) 0x00000002)
 #define SND_AUDIOSTREAMFORMAT_IF2 ((__u32) 0x00000004)
 #define SND_AUDIOSTREAMFORMAT_FSF ((__u32) 0x00000008)
 #define SND_AUDIOSTREAMFORMAT_RTPPAYLOAD ((__u32) 0x00000010)
-#define SND_AUDIOSTREAMFORMAT_ITU ((__u32) 0x00000020)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOSTREAMFORMAT_ITU ((__u32) 0x00000020)
 #define SND_AUDIOPROFILE_AMRWB ((__u32) 0x00000001)
 #define SND_AUDIOMODE_AMRWB_DTX_OFF ((__u32) 0x00000001)
 #define SND_AUDIOMODE_AMRWB_VAD1 ((__u32) 0x00000002)
-#define SND_AUDIOMODE_AMRWB_VAD2 ((__u32) 0x00000004)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_AMRWB_VAD2 ((__u32) 0x00000004)
 #define SND_AUDIOPROFILE_AMRWBPLUS ((__u32) 0x00000001)
 #define SND_AUDIOPROFILE_AAC ((__u32) 0x00000001)
 #define SND_AUDIOMODE_AAC_MAIN ((__u32) 0x00000001)
-#define SND_AUDIOMODE_AAC_LC ((__u32) 0x00000002)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_AAC_LC ((__u32) 0x00000002)
 #define SND_AUDIOMODE_AAC_SSR ((__u32) 0x00000004)
 #define SND_AUDIOMODE_AAC_LTP ((__u32) 0x00000008)
 #define SND_AUDIOMODE_AAC_HE ((__u32) 0x00000010)
-#define SND_AUDIOMODE_AAC_SCALABLE ((__u32) 0x00000020)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_AAC_SCALABLE ((__u32) 0x00000020)
 #define SND_AUDIOMODE_AAC_ERLC ((__u32) 0x00000040)
 #define SND_AUDIOMODE_AAC_LD ((__u32) 0x00000080)
 #define SND_AUDIOMODE_AAC_HE_PS ((__u32) 0x00000100)
-#define SND_AUDIOMODE_AAC_HE_MPS ((__u32) 0x00000200)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_AAC_HE_MPS ((__u32) 0x00000200)
 #define SND_AUDIOSTREAMFORMAT_MP2ADTS ((__u32) 0x00000001)
 #define SND_AUDIOSTREAMFORMAT_MP4ADTS ((__u32) 0x00000002)
 #define SND_AUDIOSTREAMFORMAT_MP4LOAS ((__u32) 0x00000004)
-#define SND_AUDIOSTREAMFORMAT_MP4LATM ((__u32) 0x00000008)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOSTREAMFORMAT_MP4LATM ((__u32) 0x00000008)
 #define SND_AUDIOSTREAMFORMAT_ADIF ((__u32) 0x00000010)
 #define SND_AUDIOSTREAMFORMAT_MP4FF ((__u32) 0x00000020)
 #define SND_AUDIOSTREAMFORMAT_RAW ((__u32) 0x00000040)
-#define SND_AUDIOPROFILE_WMA7 ((__u32) 0x00000001)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOPROFILE_WMA7 ((__u32) 0x00000001)
 #define SND_AUDIOPROFILE_WMA8 ((__u32) 0x00000002)
 #define SND_AUDIOPROFILE_WMA9 ((__u32) 0x00000004)
 #define SND_AUDIOPROFILE_WMA10 ((__u32) 0x00000008)
-#define SND_AUDIOMODE_WMA_LEVEL1 ((__u32) 0x00000001)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_WMA_LEVEL1 ((__u32) 0x00000001)
 #define SND_AUDIOMODE_WMA_LEVEL2 ((__u32) 0x00000002)
 #define SND_AUDIOMODE_WMA_LEVEL3 ((__u32) 0x00000004)
 #define SND_AUDIOMODE_WMA_LEVEL4 ((__u32) 0x00000008)
-#define SND_AUDIOMODE_WMAPRO_LEVELM0 ((__u32) 0x00000010)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_WMAPRO_LEVELM0 ((__u32) 0x00000010)
 #define SND_AUDIOMODE_WMAPRO_LEVELM1 ((__u32) 0x00000020)
 #define SND_AUDIOMODE_WMAPRO_LEVELM2 ((__u32) 0x00000040)
 #define SND_AUDIOMODE_WMAPRO_LEVELM3 ((__u32) 0x00000080)
-#define SND_AUDIOSTREAMFORMAT_WMA_ASF ((__u32) 0x00000001)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOSTREAMFORMAT_WMA_ASF ((__u32) 0x00000001)
 #define SND_AUDIOSTREAMFORMAT_WMA_NOASF_HDR ((__u32) 0x00000002)
 #define SND_AUDIOPROFILE_REALAUDIO ((__u32) 0x00000001)
 #define SND_AUDIOMODE_REALAUDIO_G2 ((__u32) 0x00000001)
-#define SND_AUDIOMODE_REALAUDIO_8 ((__u32) 0x00000002)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_REALAUDIO_8 ((__u32) 0x00000002)
 #define SND_AUDIOMODE_REALAUDIO_10 ((__u32) 0x00000004)
 #define SND_AUDIOMODE_REALAUDIO_SURROUND ((__u32) 0x00000008)
 #define SND_AUDIOPROFILE_VORBIS ((__u32) 0x00000001)
-#define SND_AUDIOMODE_VORBIS ((__u32) 0x00000001)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_VORBIS ((__u32) 0x00000001)
 #define SND_AUDIOPROFILE_FLAC ((__u32) 0x00000001)
 #define SND_AUDIOMODE_FLAC_LEVEL0 ((__u32) 0x00000001)
 #define SND_AUDIOMODE_FLAC_LEVEL1 ((__u32) 0x00000002)
-#define SND_AUDIOMODE_FLAC_LEVEL2 ((__u32) 0x00000004)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_FLAC_LEVEL2 ((__u32) 0x00000004)
 #define SND_AUDIOMODE_FLAC_LEVEL3 ((__u32) 0x00000008)
 #define SND_AUDIOMODE_FLAC_LEVEL4 ((__u32) 0x00000010)
 #define SND_AUDIOMODE_FLAC_LEVEL5 ((__u32) 0x00000020)
-#define SND_AUDIOMODE_FLAC_LEVEL6 ((__u32) 0x00000040)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_FLAC_LEVEL6 ((__u32) 0x00000040)
 #define SND_AUDIOMODE_FLAC_LEVEL7 ((__u32) 0x00000080)
 #define SND_AUDIOMODE_FLAC_LEVEL8 ((__u32) 0x00000100)
 #define SND_AUDIOSTREAMFORMAT_FLAC ((__u32) 0x00000001)
-#define SND_AUDIOSTREAMFORMAT_FLAC_OGG ((__u32) 0x00000002)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOSTREAMFORMAT_FLAC_OGG ((__u32) 0x00000002)
 #define SND_AUDIOPROFILE_IEC61937 ((__u32) 0x00000001)
 #define SND_AUDIOPROFILE_IEC61937_SPDIF ((__u32) 0x00000002)
 #define SND_AUDIOMODE_IEC_REF_STREAM_HEADER ((__u32) 0x00000000)
-#define SND_AUDIOMODE_IEC_LPCM ((__u32) 0x00000001)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_IEC_LPCM ((__u32) 0x00000001)
 #define SND_AUDIOMODE_IEC_AC3 ((__u32) 0x00000002)
 #define SND_AUDIOMODE_IEC_MPEG1 ((__u32) 0x00000004)
 #define SND_AUDIOMODE_IEC_MP3 ((__u32) 0x00000008)
-#define SND_AUDIOMODE_IEC_MPEG2 ((__u32) 0x00000010)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_IEC_MPEG2 ((__u32) 0x00000010)
 #define SND_AUDIOMODE_IEC_AACLC ((__u32) 0x00000020)
 #define SND_AUDIOMODE_IEC_DTS ((__u32) 0x00000040)
 #define SND_AUDIOMODE_IEC_ATRAC ((__u32) 0x00000080)
-#define SND_AUDIOMODE_IEC_SACD ((__u32) 0x00000100)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_IEC_SACD ((__u32) 0x00000100)
 #define SND_AUDIOMODE_IEC_EAC3 ((__u32) 0x00000200)
 #define SND_AUDIOMODE_IEC_DTS_HD ((__u32) 0x00000400)
 #define SND_AUDIOMODE_IEC_MLP ((__u32) 0x00000800)
-#define SND_AUDIOMODE_IEC_DST ((__u32) 0x00001000)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_IEC_DST ((__u32) 0x00001000)
 #define SND_AUDIOMODE_IEC_WMAPRO ((__u32) 0x00002000)
 #define SND_AUDIOMODE_IEC_REF_CXT ((__u32) 0x00004000)
 #define SND_AUDIOMODE_IEC_HE_AAC ((__u32) 0x00008000)
-#define SND_AUDIOMODE_IEC_HE_AAC2 ((__u32) 0x00010000)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_IEC_HE_AAC2 ((__u32) 0x00010000)
 #define SND_AUDIOMODE_IEC_MPEG_SURROUND ((__u32) 0x00020000)
 #define SND_AUDIOPROFILE_G723_1 ((__u32) 0x00000001)
 #define SND_AUDIOMODE_G723_1_ANNEX_A ((__u32) 0x00000001)
-#define SND_AUDIOMODE_G723_1_ANNEX_B ((__u32) 0x00000002)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_G723_1_ANNEX_B ((__u32) 0x00000002)
 #define SND_AUDIOMODE_G723_1_ANNEX_C ((__u32) 0x00000004)
 #define SND_AUDIOPROFILE_G729 ((__u32) 0x00000001)
 #define SND_AUDIOMODE_G729_ANNEX_A ((__u32) 0x00000001)
-#define SND_AUDIOMODE_G729_ANNEX_B ((__u32) 0x00000002)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SND_AUDIOMODE_G729_ANNEX_B ((__u32) 0x00000002)
 #define SND_RATECONTROLMODE_CONSTANTBITRATE ((__u32) 0x00000001)
 #define SND_RATECONTROLMODE_VARIABLEBITRATE ((__u32) 0x00000002)
 struct snd_enc_wma {
- __u32 super_block_align;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 super_block_align;
 };
 struct snd_enc_vorbis {
  __s32 quality;
- __u32 managed;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 managed;
  __u32 max_bit_rate;
  __u32 min_bit_rate;
  __u32 downmix;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct snd_enc_real {
  __u32 quant_bits;
  __u32 start_region;
- __u32 num_regions;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 num_regions;
 };
 struct snd_enc_flac {
  __u32 num;
- __u32 gain;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 gain;
 };
 struct snd_enc_generic {
  __u32 bw;
- __s32 reserved[15];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __s32 reserved[15];
 };
 union snd_codec_options {
  struct snd_enc_wma wma;
- struct snd_enc_vorbis vorbis;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct snd_enc_vorbis vorbis;
  struct snd_enc_real real;
  struct snd_enc_flac flac;
  struct snd_enc_generic generic;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
 struct snd_codec_desc {
  __u32 max_ch;
- __u32 sample_rates;
- __u32 bit_rate[MAX_NUM_BITRATES];
+ __u32 sample_rates[MAX_NUM_SAMPLE_RATES];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 num_sample_rates;
+ __u32 bit_rate[MAX_NUM_BITRATES];
  __u32 num_bitrates;
  __u32 rate_control;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 profiles;
  __u32 modes;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 formats;
  __u32 min_buffer;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 reserved[15];
 };
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct snd_codec {
  __u32 id;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 ch_in;
  __u32 ch_out;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 sample_rate;
  __u32 bit_rate;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 rate_control;
  __u32 profile;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 level;
  __u32 ch_mode;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 format;
  __u32 align;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  union snd_codec_options options;
  __u32 reserved[3];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/sound/firewire.h b/libc/kernel/uapi/sound/firewire.h
new file mode 100644
index 0000000..5d0fd14
--- /dev/null
+++ b/libc/kernel/uapi/sound/firewire.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI_SOUND_FIREWIRE_H_INCLUDED
+#define _UAPI_SOUND_FIREWIRE_H_INCLUDED
+#include <linux/ioctl.h>
+#define SNDRV_FIREWIRE_EVENT_LOCK_STATUS 0x000010cc
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION 0xd1ce004e
+struct snd_firewire_event_common {
+ unsigned int type;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_firewire_event_lock_status {
+ unsigned int type;
+ unsigned int status;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct snd_firewire_event_dice_notification {
+ unsigned int type;
+ unsigned int notification;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+union snd_firewire_event {
+ struct snd_firewire_event_common common;
+ struct snd_firewire_event_lock_status lock_status;
+ struct snd_firewire_event_dice_notification dice_notification;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define SNDRV_FIREWIRE_IOCTL_GET_INFO _IOR('H', 0xf8, struct snd_firewire_get_info)
+#define SNDRV_FIREWIRE_IOCTL_LOCK _IO('H', 0xf9)
+#define SNDRV_FIREWIRE_IOCTL_UNLOCK _IO('H', 0xfa)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SNDRV_FIREWIRE_TYPE_DICE 1
+struct snd_firewire_get_info {
+ unsigned int type;
+ unsigned int card;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned char guid[8];
+ char device_name[16];
+};
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/sound/hdspm.h b/libc/kernel/uapi/sound/hdspm.h
index 6fdfa8f..8b3688f 100644
--- a/libc/kernel/uapi/sound/hdspm.h
+++ b/libc/kernel/uapi/sound/hdspm.h
@@ -94,7 +94,7 @@
  enum hdspm_ltc_frame frame;
  enum hdspm_ltc_input_format input_format;
 };
-#define SNDRV_HDSPM_IOCTL_GET_LTC _IOR('H', 0x46, struct hdspm_mixer_ioctl)
+#define SNDRV_HDSPM_IOCTL_GET_LTC _IOR('H', 0x46, struct hdspm_ltc)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum hdspm_sync {
  hdspm_sync_no_lock = 0,
diff --git a/libc/kernel/uapi/video/adf.h b/libc/kernel/uapi/video/adf.h
index 057ec46..fe23e01 100644
--- a/libc/kernel/uapi/video/adf.h
+++ b/libc/kernel/uapi/video/adf.h
@@ -62,7 +62,7 @@
 struct adf_vsync_event {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct adf_event base;
- __u64 timestamp;
+ __aligned_u64 timestamp;
 };
 struct adf_hotplug_event {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -77,12 +77,12 @@
  __u32 h;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 format;
- __s64 fd[ADF_MAX_PLANES];
+ __s32 fd[ADF_MAX_PLANES];
  __u32 offset[ADF_MAX_PLANES];
  __u32 pitch[ADF_MAX_PLANES];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 n_planes;
- __s64 acquire_fence;
+ __s32 acquire_fence;
 };
 #define ADF_MAX_BUFFERS (4096 / sizeof(struct adf_buffer_config))
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -94,7 +94,7 @@
  struct adf_buffer_config __user *bufs;
  size_t custom_data_size;
  void __user *custom_data;
- __s64 complete_fence;
+ __s32 complete_fence;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define ADF_MAX_INTERFACES (4096 / sizeof(__u32))
@@ -103,7 +103,7 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 h;
  __u32 format;
- __s64 fd;
+ __s32 fd;
  __u32 offset;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pitch;
@@ -111,7 +111,7 @@
 struct adf_simple_post_config {
  struct adf_buffer_config buf;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __s64 complete_fence;
+ __s32 complete_fence;
 };
 struct adf_attachment_config {
  __u32 overlay_engine;
@@ -161,18 +161,20 @@
 };
 #define ADF_MAX_SUPPORTED_FORMATS (4096 / sizeof(__u32))
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_SET_EVENT _IOW('D', 0, struct adf_set_event)
-#define ADF_BLANK _IOW('D', 1, __u8)
-#define ADF_POST_CONFIG _IOW('D', 2, struct adf_post_config)
-#define ADF_SET_MODE _IOW('D', 3, struct drm_mode_modeinfo)
+#define ADF_IOCTL_TYPE 'D'
+#define ADF_IOCTL_NR_CUSTOM 128
+#define ADF_SET_EVENT _IOW(ADF_IOCTL_TYPE, 0, struct adf_set_event)
+#define ADF_BLANK _IOW(ADF_IOCTL_TYPE, 1, __u8)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_GET_DEVICE_DATA _IOR('D', 4, struct adf_device_data)
-#define ADF_GET_INTERFACE_DATA _IOR('D', 5, struct adf_interface_data)
-#define ADF_GET_OVERLAY_ENGINE_DATA   _IOR('D', 6, struct adf_overlay_engine_data)
-#define ADF_SIMPLE_POST_CONFIG _IOW('D', 7, struct adf_simple_post_config)
+#define ADF_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 2, struct adf_post_config)
+#define ADF_SET_MODE _IOW(ADF_IOCTL_TYPE, 3,   struct drm_mode_modeinfo)
+#define ADF_GET_DEVICE_DATA _IOR(ADF_IOCTL_TYPE, 4, struct adf_device_data)
+#define ADF_GET_INTERFACE_DATA _IOR(ADF_IOCTL_TYPE, 5,   struct adf_interface_data)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_SIMPLE_BUFFER_ALLOC _IOW('D', 8, struct adf_simple_buffer_alloc)
-#define ADF_ATTACH _IOW('D', 9, struct adf_attachment_config)
-#define ADF_DETACH _IOW('D', 10, struct adf_attachment_config)
+#define ADF_GET_OVERLAY_ENGINE_DATA   _IOR(ADF_IOCTL_TYPE, 6,   struct adf_overlay_engine_data)
+#define ADF_SIMPLE_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 7,   struct adf_simple_post_config)
+#define ADF_SIMPLE_BUFFER_ALLOC _IOW(ADF_IOCTL_TYPE, 8,   struct adf_simple_buffer_alloc)
+#define ADF_ATTACH _IOW(ADF_IOCTL_TYPE, 9,   struct adf_attachment_config)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ADF_DETACH _IOW(ADF_IOCTL_TYPE, 10,   struct adf_attachment_config)
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/xen/gntalloc.h b/libc/kernel/uapi/xen/gntalloc.h
new file mode 100644
index 0000000..2076843
--- /dev/null
+++ b/libc/kernel/uapi/xen/gntalloc.h
@@ -0,0 +1,49 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __LINUX_PUBLIC_GNTALLOC_H__
+#define __LINUX_PUBLIC_GNTALLOC_H__
+#define IOCTL_GNTALLOC_ALLOC_GREF  _IOC(_IOC_NONE, 'G', 5, sizeof(struct ioctl_gntalloc_alloc_gref))
+struct ioctl_gntalloc_alloc_gref {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint16_t domid;
+ uint16_t flags;
+ uint32_t count;
+ uint64_t index;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t gref_ids[1];
+};
+#define GNTALLOC_FLAG_WRITABLE 1
+#define IOCTL_GNTALLOC_DEALLOC_GREF  _IOC(_IOC_NONE, 'G', 6, sizeof(struct ioctl_gntalloc_dealloc_gref))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ioctl_gntalloc_dealloc_gref {
+ uint64_t index;
+ uint32_t count;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IOCTL_GNTALLOC_SET_UNMAP_NOTIFY  _IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntalloc_unmap_notify))
+struct ioctl_gntalloc_unmap_notify {
+ uint64_t index;
+ uint32_t action;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t event_channel_port;
+};
+#define UNMAP_NOTIFY_CLEAR_BYTE 0x1
+#define UNMAP_NOTIFY_SEND_EVENT 0x2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
diff --git a/libc/kernel/uapi/xen/gntdev.h b/libc/kernel/uapi/xen/gntdev.h
new file mode 100644
index 0000000..28a2a3a
--- /dev/null
+++ b/libc/kernel/uapi/xen/gntdev.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __LINUX_PUBLIC_GNTDEV_H__
+#define __LINUX_PUBLIC_GNTDEV_H__
+struct ioctl_gntdev_grant_ref {
+ uint32_t domid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t ref;
+};
+#define IOCTL_GNTDEV_MAP_GRANT_REF  _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_gntdev_map_grant_ref))
+struct ioctl_gntdev_map_grant_ref {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t count;
+ uint32_t pad;
+ uint64_t index;
+ struct ioctl_gntdev_grant_ref refs[1];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define IOCTL_GNTDEV_UNMAP_GRANT_REF  _IOC(_IOC_NONE, 'G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref))
+struct ioctl_gntdev_unmap_grant_ref {
+ uint64_t index;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t count;
+ uint32_t pad;
+};
+#define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR  _IOC(_IOC_NONE, 'G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ioctl_gntdev_get_offset_for_vaddr {
+ uint64_t vaddr;
+ uint64_t offset;
+ uint32_t count;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t pad;
+};
+#define IOCTL_GNTDEV_SET_MAX_GRANTS  _IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
+struct ioctl_gntdev_set_max_grants {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint32_t count;
+};
+#define IOCTL_GNTDEV_SET_UNMAP_NOTIFY  _IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntdev_unmap_notify))
+struct ioctl_gntdev_unmap_notify {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ uint64_t index;
+ uint32_t action;
+ uint32_t event_channel_port;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define UNMAP_NOTIFY_CLEAR_BYTE 0x1
+#define UNMAP_NOTIFY_SEND_EVENT 0x2
+#endif
diff --git a/libc/netbsd/gethnamaddr.c b/libc/netbsd/gethnamaddr.c
deleted file mode 100644
index 5b2f987..0000000
--- a/libc/netbsd/gethnamaddr.c
+++ /dev/null
@@ -1,1408 +0,0 @@
-/*	$NetBSD: gethnamaddr.c,v 1.70 2006/03/22 00:03:51 christos Exp $	*/
-
-/*
- * ++Copyright++ 1985, 1988, 1993
- * -
- * Copyright (c) 1985, 1988, 1993
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * -
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- * -
- * --Copyright--
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-#include "resolv_private.h"
-#include "resolv_cache.h"
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <strings.h>
-#include <syslog.h>
-#include <unistd.h>
-
-#ifndef LOG_AUTH
-# define LOG_AUTH 0
-#endif
-
-#define MULTI_PTRS_ARE_ALIASES 1	/* XXX - experimental */
-
-#include "nsswitch.h"
-#include <stdlib.h>
-#include <string.h>
-
-// This should be synchronized to ResponseCode.h
-static const int DnsProxyQueryResult = 222;
-
-static const char const AskedForGot[] =
-			  "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
-
-#define	MAXPACKET	(64*1024)
-
-typedef union {
-    HEADER hdr;
-    u_char buf[MAXPACKET];
-} querybuf;
-
-typedef union {
-    int32_t al;
-    char ac;
-} align;
-
-#ifdef DEBUG
-static void dprintf(const char *, res_state, ...)
-	__attribute__((__format__(__printf__, 1, 3)));
-#endif
-static struct hostent *getanswer(const querybuf *, int, const char *, int,
-    res_state);
-static void map_v4v6_address(const char *, char *);
-static void map_v4v6_hostent(struct hostent *, char **, char *);
-static void addrsort(char **, int, res_state);
-
-static void _sethtent(int);
-static void _endhtent(void);
-static struct hostent *_gethtent(void);
-void ht_sethostent(int);
-void ht_endhostent(void);
-struct hostent *ht_gethostbyname(char *);
-struct hostent *ht_gethostbyaddr(const char *, int, int);
-void dns_service(void);
-#undef dn_skipname
-int dn_skipname(const u_char *, const u_char *);
-static int _gethtbyaddr(void *, void *, va_list);
-static int _gethtbyname(void *, void *, va_list);
-static struct hostent *_gethtbyname2(const char *, int);
-static int _dns_gethtbyaddr(void *, void *, va_list);
-static int _dns_gethtbyname(void *, void *, va_list);
-
-static struct hostent *gethostbyname_internal(const char *, int, res_state, const char *, int);
-
-static const ns_src default_dns_files[] = {
-	{ NSSRC_FILES, 	NS_SUCCESS },
-	{ NSSRC_DNS, 	NS_SUCCESS },
-	{ 0, 0 }
-};
-
-
-#ifdef DEBUG
-static void
-dprintf(const char *msg, res_state res, ...)
-{
-	assert(msg != NULL);
-
-	if (res->options & RES_DEBUG) {
-		int save = errno;
-		va_list ap;
-
-		va_start (ap, res);
-		vprintf(msg, ap);
-		va_end (ap);
-
-		errno = save;
-	}
-}
-#else
-# define dprintf(msg, res, num) ((void)0) /*nada*/
-#endif
-
-#define BOUNDED_INCR(x) \
-	do { \
-		cp += (x); \
-		if (cp > eom) { \
-			h_errno = NO_RECOVERY; \
-			return NULL; \
-		} \
-	} while (/*CONSTCOND*/0)
-
-#define BOUNDS_CHECK(ptr, count) \
-	do { \
-		if ((ptr) + (count) > eom) { \
-			h_errno = NO_RECOVERY; \
-			return NULL; \
-		} \
-	} while (/*CONSTCOND*/0)
-
-static struct hostent *
-getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
-    res_state res)
-{
-	const HEADER *hp;
-	const u_char *cp;
-	int n;
-	const u_char *eom, *erdata;
-	char *bp, **ap, **hap, *ep;
-	int type, class, ancount, qdcount;
-	int haveanswer, had_error;
-	int toobig = 0;
-	char tbuf[MAXDNAME];
-	const char *tname;
-	int (*name_ok)(const char *);
-	res_static  rs = __res_get_static();
-
-	assert(answer != NULL);
-	assert(qname != NULL);
-
-	tname = qname;
-	rs->host.h_name = NULL;
-	eom = answer->buf + anslen;
-	switch (qtype) {
-	case T_A:
-	case T_AAAA:
-		name_ok = res_hnok;
-		break;
-	case T_PTR:
-		name_ok = res_dnok;
-		break;
-	default:
-		return NULL;	/* XXX should be abort(); */
-	}
-	/*
-	 * find first satisfactory answer
-	 */
-	hp = &answer->hdr;
-	ancount = ntohs(hp->ancount);
-	qdcount = ntohs(hp->qdcount);
-	bp = rs->hostbuf;
-	ep = rs->hostbuf + sizeof rs->hostbuf;
-	cp = answer->buf;
-	BOUNDED_INCR(HFIXEDSZ);
-	if (qdcount != 1) {
-		h_errno = NO_RECOVERY;
-		return NULL;
-	}
-	n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-	if ((n < 0) || !(*name_ok)(bp)) {
-		h_errno = NO_RECOVERY;
-		return NULL;
-	}
-	BOUNDED_INCR(n + QFIXEDSZ);
-	if (qtype == T_A || qtype == T_AAAA) {
-		/* res_send() has already verified that the query name is the
-		 * same as the one we sent; this just gets the expanded name
-		 * (i.e., with the succeeding search-domain tacked on).
-		 */
-		n = strlen(bp) + 1;		/* for the \0 */
-		if (n >= MAXHOSTNAMELEN) {
-			h_errno = NO_RECOVERY;
-			return NULL;
-		}
-		rs->host.h_name = bp;
-		bp += n;
-		/* The qname can be abbreviated, but h_name is now absolute. */
-		qname = rs->host.h_name;
-	}
-	ap = rs->host_aliases;
-	*ap = NULL;
-	rs->host.h_aliases = rs->host_aliases;
-	hap = rs->h_addr_ptrs;
-	*hap = NULL;
-	rs->host.h_addr_list = rs->h_addr_ptrs;
-	haveanswer = 0;
-	had_error = 0;
-	while (ancount-- > 0 && cp < eom && !had_error) {
-		n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-		if ((n < 0) || !(*name_ok)(bp)) {
-			had_error++;
-			continue;
-		}
-		cp += n;			/* name */
-		BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
-		type = _getshort(cp);
- 		cp += INT16SZ;			/* type */
-		class = _getshort(cp);
- 		cp += INT16SZ + INT32SZ;	/* class, TTL */
-		n = _getshort(cp);
-		cp += INT16SZ;			/* len */
-		BOUNDS_CHECK(cp, n);
-		erdata = cp + n;
-		if (class != C_IN) {
-			/* XXX - debug? syslog? */
-			cp += n;
-			continue;		/* XXX - had_error++ ? */
-		}
-		if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
-			if (ap >= &rs->host_aliases[MAXALIASES-1])
-				continue;
-			n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
-			if ((n < 0) || !(*name_ok)(tbuf)) {
-				had_error++;
-				continue;
-			}
-			cp += n;
-			if (cp != erdata) {
-				h_errno = NO_RECOVERY;
-				return NULL;
-			}
-			/* Store alias. */
-			*ap++ = bp;
-			n = strlen(bp) + 1;	/* for the \0 */
-			if (n >= MAXHOSTNAMELEN) {
-				had_error++;
-				continue;
-			}
-			bp += n;
-			/* Get canonical name. */
-			n = strlen(tbuf) + 1;	/* for the \0 */
-			if (n > ep - bp || n >= MAXHOSTNAMELEN) {
-				had_error++;
-				continue;
-			}
-			strlcpy(bp, tbuf, (size_t)(ep - bp));
-			rs->host.h_name = bp;
-			bp += n;
-			continue;
-		}
-		if (qtype == T_PTR && type == T_CNAME) {
-			n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
-			if (n < 0 || !res_dnok(tbuf)) {
-				had_error++;
-				continue;
-			}
-			cp += n;
-			if (cp != erdata) {
-				h_errno = NO_RECOVERY;
-				return NULL;
-			}
-			/* Get canonical name. */
-			n = strlen(tbuf) + 1;	/* for the \0 */
-			if (n > ep - bp || n >= MAXHOSTNAMELEN) {
-				had_error++;
-				continue;
-			}
-			strlcpy(bp, tbuf, (size_t)(ep - bp));
-			tname = bp;
-			bp += n;
-			continue;
-		}
-		if (type != qtype) {
-			if (type != T_KEY && type != T_SIG)
-				syslog(LOG_NOTICE|LOG_AUTH,
-	       "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
-				       qname, p_class(C_IN), p_type(qtype),
-				       p_type(type));
-			cp += n;
-			continue;		/* XXX - had_error++ ? */
-		}
-		switch (type) {
-		case T_PTR:
-			if (strcasecmp(tname, bp) != 0) {
-				syslog(LOG_NOTICE|LOG_AUTH,
-				       AskedForGot, qname, bp);
-				cp += n;
-				continue;	/* XXX - had_error++ ? */
-			}
-			n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-			if ((n < 0) || !res_hnok(bp)) {
-				had_error++;
-				break;
-			}
-#if MULTI_PTRS_ARE_ALIASES
-			cp += n;
-			if (cp != erdata) {
-				h_errno = NO_RECOVERY;
-				return NULL;
-			}
-			if (!haveanswer)
-				rs->host.h_name = bp;
-			else if (ap < &rs->host_aliases[MAXALIASES-1])
-				*ap++ = bp;
-			else
-				n = -1;
-			if (n != -1) {
-				n = strlen(bp) + 1;	/* for the \0 */
-				if (n >= MAXHOSTNAMELEN) {
-					had_error++;
-					break;
-				}
-				bp += n;
-			}
-			break;
-#else
-			rs->host.h_name = bp;
-			if (res->options & RES_USE_INET6) {
-				n = strlen(bp) + 1;	/* for the \0 */
-				if (n >= MAXHOSTNAMELEN) {
-					had_error++;
-					break;
-				}
-				bp += n;
-				map_v4v6_hostent(&rs->host, &bp, ep);
-			}
-			h_errno = NETDB_SUCCESS;
-			return &rs->host;
-#endif
-		case T_A:
-		case T_AAAA:
-			if (strcasecmp(rs->host.h_name, bp) != 0) {
-				syslog(LOG_NOTICE|LOG_AUTH,
-				       AskedForGot, rs->host.h_name, bp);
-				cp += n;
-				continue;	/* XXX - had_error++ ? */
-			}
-			if (n != rs->host.h_length) {
-				cp += n;
-				continue;
-			}
-			if (type == T_AAAA) {
-				struct in6_addr in6;
-				memcpy(&in6, cp, IN6ADDRSZ);
-				if (IN6_IS_ADDR_V4MAPPED(&in6)) {
-					cp += n;
-					continue;
-				}
-			}
-			if (!haveanswer) {
-				int nn;
-
-				rs->host.h_name = bp;
-				nn = strlen(bp) + 1;	/* for the \0 */
-				bp += nn;
-			}
-
-			bp += sizeof(align) -
-			    (size_t)((u_long)bp % sizeof(align));
-
-			if (bp + n >= &rs->hostbuf[sizeof rs->hostbuf]) {
-				dprintf("size (%d) too big\n", res, n);
-				had_error++;
-				continue;
-			}
-			if (hap >= &rs->h_addr_ptrs[MAXADDRS-1]) {
-				if (!toobig++)
-					dprintf("Too many addresses (%d)\n",
-						res, MAXADDRS);
-				cp += n;
-				continue;
-			}
-			(void)memcpy(*hap++ = bp, cp, (size_t)n);
-			bp += n;
-			cp += n;
-			if (cp != erdata) {
-				h_errno = NO_RECOVERY;
-				return NULL;
-			}
-			break;
-		default:
-			abort();
-		}
-		if (!had_error)
-			haveanswer++;
-	}
-	if (haveanswer) {
-		*ap = NULL;
-		*hap = NULL;
-		/*
-		 * Note: we sort even if host can take only one address
-		 * in its return structures - should give it the "best"
-		 * address in that case, not some random one
-		 */
-		if (res->nsort && haveanswer > 1 && qtype == T_A)
-			addrsort(rs->h_addr_ptrs, haveanswer, res);
-		if (!rs->host.h_name) {
-			n = strlen(qname) + 1;	/* for the \0 */
-			if (n > ep - bp || n >= MAXHOSTNAMELEN)
-				goto no_recovery;
-			strlcpy(bp, qname, (size_t)(ep - bp));
-			rs->host.h_name = bp;
-			bp += n;
-		}
-		if (res->options & RES_USE_INET6)
-			map_v4v6_hostent(&rs->host, &bp, ep);
-		h_errno = NETDB_SUCCESS;
-		return &rs->host;
-	}
- no_recovery:
-	h_errno = NO_RECOVERY;
-	return NULL;
-}
-
-int
-gethostbyname_r(const char *name, struct hostent *hp, char *buf, size_t buflen,
-    struct hostent**result, int *errorp)
-{
-        struct hostent *res;
-
-        res = gethostbyname(name);
-        *errorp = h_errno;
-        if (res == NULL) {
-                *result = NULL;
-                return -1;
-        }
-        memcpy(hp, res, sizeof *hp);
-        *result = hp;
-        return 0;
-}
-
-struct hostent *
-gethostbyname(const char *name)
-{
-	struct hostent *hp;
-	res_state res = __res_get_state();
-
-	if (res == NULL)
-		return NULL;
-
-	assert(name != NULL);
-
-	/* try IPv6 first - if that fails do IPv4 */
-	if (res->options & RES_USE_INET6) {
-		hp = gethostbyname_internal(name, AF_INET6, res, NULL, 0);
-		if (hp) {
-			__res_put_state(res);
-			return hp;
-		}
-	}
-	hp = gethostbyname_internal(name, AF_INET, res, NULL, 0);
-	__res_put_state(res);
-	return hp;
-}
-
-struct hostent *
-gethostbyname2(const char *name, int af)
-{
-	return android_gethostbynameforiface(name, af, NULL, 0);
-}
-
-struct hostent *
-android_gethostbynameforiface(const char *name, int af, const char *iface, int mark)
-{
-	struct hostent *hp;
-	res_state res = __res_get_state();
-
-	if (res == NULL)
-		return NULL;
-	hp = gethostbyname_internal(name, af, res, iface, mark);
-	__res_put_state(res);
-	return hp;
-}
-
-
-static FILE* android_open_proxy()
-{
-	int sock;
-	const int one = 1;
-	struct sockaddr_un proxy_addr;
-
-	sock = socket(AF_UNIX, SOCK_STREAM, 0);
-	if (sock < 0) {
-		return NULL;
-	}
-
-	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
-	memset(&proxy_addr, 0, sizeof(proxy_addr));
-	proxy_addr.sun_family = AF_UNIX;
-	strlcpy(proxy_addr.sun_path, "/dev/socket/dnsproxyd", sizeof(proxy_addr.sun_path));
-	if (TEMP_FAILURE_RETRY(connect(sock,
-			(const struct sockaddr*) &proxy_addr,
-			sizeof(proxy_addr))) != 0) {
-		close(sock);
-		return NULL;
-	}
-
-	return fdopen(sock, "r+");
-}
-
-static struct hostent *
-android_read_hostent(FILE* proxy)
-{
-	uint32_t size;
-	char buf[4];
-	if (fread(buf, 1, sizeof(buf), proxy) != sizeof(buf)) return NULL;
-
-	/* This is reading serialized data from system/netd/DnsProxyListener.cpp
-	 * and changes here need to be matched there */
-	int result_code = strtol(buf, NULL, 10);
-	if (result_code != DnsProxyQueryResult) {
-		fread(&size, 1, sizeof(size), proxy);
-		return NULL;
-	}
-
-	if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
-	size = ntohl(size);
-	res_static rs = __res_get_static();
-	memset(&rs->host, 0, sizeof(rs->host));
-	char *ptr = rs->hostbuf;
-
-	if (fread(ptr, 1, size, proxy) != size) return NULL;
-	ptr += size;
-	rs->host.h_name = rs->hostbuf;
-
-	char **aliases = rs->host_aliases;
-	rs->host.h_aliases = rs->host_aliases;
-	while (1) {
-		if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
-		size = ntohl(size);
-
-		if (size == 0) {
-			*aliases = NULL;
-			break;
-		}
-		if (fread(ptr, 1, size, proxy) != size) return NULL;
-		*aliases++ = ptr;
-		ptr += size;
-	}
-
-	if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
-	rs->host.h_addrtype = ntohl(size);
-
-	if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
-	rs->host.h_length = ntohl(size);
-
-	char **addrs = rs->h_addr_ptrs;
-	rs->host.h_addr_list = rs->h_addr_ptrs;
-	while (1) {
-		if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
-		size = ntohl(size);
-		if (size == 0) {
-			*addrs = NULL;
-			break;
-		}
-		if (fread(ptr, 1, size, proxy) != size) return NULL;
-		*addrs++ = ptr;
-		ptr += size;
-	}
-
-	return &rs->host;
-}
-
-
-static struct hostent *
-gethostbyname_internal_real(const char *name, int af, res_state res)
-{
-	const char *cp;
-	char *bp, *ep;
-	int size;
-	struct hostent *hp;
-	res_static rs = __res_get_static();
-
-	static const ns_dtab dtab[] = {
-		NS_FILES_CB(_gethtbyname, NULL)
-		{ NSSRC_DNS, _dns_gethtbyname, NULL },	/* force -DHESIOD */
-		{ 0, 0, 0 }
-	};
-
-	assert(name != NULL);
-
-	switch (af) {
-	case AF_INET:
-		size = INADDRSZ;
-		break;
-	case AF_INET6:
-		size = IN6ADDRSZ;
-		break;
-	default:
-		h_errno = NETDB_INTERNAL;
-		errno = EAFNOSUPPORT;
-		return NULL;
-	}
-
-	rs->host.h_addrtype = af;
-	rs->host.h_length = size;
-
-	/*
-	 * if there aren't any dots, it could be a user-level alias.
-	 * this is also done in res_nquery() since we are not the only
-	 * function that looks up host names.
-	 */
-	if (!strchr(name, '.') && (cp = __hostalias(name)))
-		name = cp;
-
-	/*
-	 * disallow names consisting only of digits/dots, unless
-	 * they end in a dot.
-	 */
-	if (isdigit((u_char) name[0]))
-		for (cp = name;; ++cp) {
-			if (!*cp) {
-				if (*--cp == '.')
-					break;
-				/*
-				 * All-numeric, no dot at the end.
-				 * Fake up a hostent as if we'd actually
-				 * done a lookup.
-				 */
-				if (inet_pton(af, name,
-				    (char *)(void *)rs->host_addr) <= 0) {
-					h_errno = HOST_NOT_FOUND;
-					return NULL;
-				}
-				strncpy(rs->hostbuf, name, MAXDNAME);
-				rs->hostbuf[MAXDNAME] = '\0';
-				bp = rs->hostbuf + MAXDNAME;
-				ep = rs->hostbuf + sizeof rs->hostbuf;
-				rs->host.h_name = rs->hostbuf;
-				rs->host.h_aliases = rs->host_aliases;
-				rs->host_aliases[0] = NULL;
-				rs->h_addr_ptrs[0] = (char *)(void *)rs->host_addr;
-				rs->h_addr_ptrs[1] = NULL;
-				rs->host.h_addr_list = rs->h_addr_ptrs;
-				if (res->options & RES_USE_INET6)
-					map_v4v6_hostent(&rs->host, &bp, ep);
-				h_errno = NETDB_SUCCESS;
-				return &rs->host;
-			}
-			if (!isdigit((u_char) *cp) && *cp != '.')
-				break;
-		}
-	if ((isxdigit((u_char) name[0]) && strchr(name, ':') != NULL) ||
-	    name[0] == ':')
-		for (cp = name;; ++cp) {
-			if (!*cp) {
-				if (*--cp == '.')
-					break;
-				/*
-				 * All-IPv6-legal, no dot at the end.
-				 * Fake up a hostent as if we'd actually
-				 * done a lookup.
-				 */
-				if (inet_pton(af, name,
-				    (char *)(void *)rs->host_addr) <= 0) {
-					h_errno = HOST_NOT_FOUND;
-					return NULL;
-				}
-				strncpy(rs->hostbuf, name, MAXDNAME);
-				rs->hostbuf[MAXDNAME] = '\0';
-				bp = rs->hostbuf + MAXDNAME;
-				ep = rs->hostbuf + sizeof rs->hostbuf;
-				rs->host.h_name = rs->hostbuf;
-				rs->host.h_aliases = rs->host_aliases;
-				rs->host_aliases[0] = NULL;
-				rs->h_addr_ptrs[0] = (char *)(void *)rs->host_addr;
-				rs->h_addr_ptrs[1] = NULL;
-				rs->host.h_addr_list = rs->h_addr_ptrs;
-				h_errno = NETDB_SUCCESS;
-				return &rs->host;
-			}
-			if (!isxdigit((u_char) *cp) && *cp != ':' && *cp != '.')
-				break;
-		}
-
-	hp = NULL;
-	h_errno = NETDB_INTERNAL;
-	if (nsdispatch(&hp, dtab, NSDB_HOSTS, "gethostbyname",
-	    default_dns_files, name, strlen(name), af) != NS_SUCCESS) {
-		return NULL;
-	}
-	h_errno = NETDB_SUCCESS;
-	return hp;
-}
-
-
-// very similar in proxy-ness to android_getaddrinfo_proxy
-static struct hostent *
-gethostbyname_internal(const char *name, int af, res_state res, const char *iface, int mark)
-{
-	const char *cache_mode = getenv("ANDROID_DNS_MODE");
-	FILE* proxy = NULL;
-	struct hostent *result = NULL;
-
-	if (cache_mode != NULL && strcmp(cache_mode, "local") == 0) {
-		res_setiface(res, iface);
-		res_setmark(res, mark);
-		return gethostbyname_internal_real(name, af, res);
-	}
-
-	proxy = android_open_proxy();
-	if (proxy == NULL) goto exit;
-
-	/* This is writing to system/netd/DnsProxyListener.cpp and changes
-	 * here need to be matched there */
-	if (fprintf(proxy, "gethostbyname %s %s %d",
-			iface == NULL ? "^" : iface,
-			name == NULL ? "^" : name,
-			af) < 0) {
-		goto exit;
-	}
-
-	if (fputc(0, proxy) == EOF || fflush(proxy) != 0) {
-		goto exit;
-	}
-
-	result = android_read_hostent(proxy);
-
-exit:
-	if (proxy != NULL) {
-		fclose(proxy);
-	}
-	return result;
-}
-
-
-struct hostent *
-android_gethostbyaddrforiface_proxy(const void *addr,
-    socklen_t len, int af, const char* iface, int mark)
-{
-	struct hostent *result = NULL;
-	FILE* proxy = android_open_proxy();
-
-	if (proxy == NULL) goto exit;
-
-	char buf[INET6_ADDRSTRLEN];  //big enough for IPv4 and IPv6
-	const char * addrStr = inet_ntop(af, addr, buf, sizeof(buf));
-	if (addrStr == NULL) goto exit;
-
-	if (fprintf(proxy, "gethostbyaddr %s %d %d %s",
-			addrStr, len, af, iface == NULL ? "^" : iface) < 0) {
-		goto exit;
-	}
-
-	if (fputc(0, proxy) == EOF || fflush(proxy) != 0) {
-		goto exit;
-	}
-
-	result = android_read_hostent(proxy);
-exit:
-	if (proxy != NULL) {
-		fclose(proxy);
-	}
-	return result;
-}
-
-struct hostent *
-android_gethostbyaddrforiface_real(const void *addr,
-    socklen_t len, int af, const char* iface, int mark)
-{
-	const u_char *uaddr = (const u_char *)addr;
-	socklen_t size;
-	struct hostent *hp;
-	static const ns_dtab dtab[] = {
-		NS_FILES_CB(_gethtbyaddr, NULL)
-		{ NSSRC_DNS, _dns_gethtbyaddr, NULL },	/* force -DHESIOD */
-		{ 0, 0, 0 }
-	};
-
-	assert(addr != NULL);
-
-	if (af == AF_INET6 && len == IN6ADDRSZ &&
-	    (IN6_IS_ADDR_LINKLOCAL((const struct in6_addr *)(const void *)uaddr) ||
-	     IN6_IS_ADDR_SITELOCAL((const struct in6_addr *)(const void *)uaddr))) {
-		h_errno = HOST_NOT_FOUND;
-		return NULL;
-	}
-	if (af == AF_INET6 && len == IN6ADDRSZ &&
-	    (IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)(const void *)uaddr) ||
-	     IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)(const void *)uaddr))) {
-		/* Unmap. */
-		addr += IN6ADDRSZ - INADDRSZ;
-		uaddr += IN6ADDRSZ - INADDRSZ;
-		af = AF_INET;
-		len = INADDRSZ;
-	}
-	switch (af) {
-	case AF_INET:
-		size = INADDRSZ;
-		break;
-	case AF_INET6:
-		size = IN6ADDRSZ;
-		break;
-	default:
-		errno = EAFNOSUPPORT;
-		h_errno = NETDB_INTERNAL;
-		return NULL;
-	}
-	if (size != len) {
-		errno = EINVAL;
-		h_errno = NETDB_INTERNAL;
-		return NULL;
-	}
-	hp = NULL;
-	h_errno = NETDB_INTERNAL;
-	if (nsdispatch(&hp, dtab, NSDB_HOSTS, "gethostbyaddr",
-		default_dns_files, uaddr, len, af, iface, mark) != NS_SUCCESS)
-		return NULL;
-	h_errno = NETDB_SUCCESS;
-	return hp;
-}
-
-struct hostent *
-android_gethostbyaddrforiface(const void *addr, socklen_t len, int af, const char* iface, int mark)
-{
-	const char *cache_mode = getenv("ANDROID_DNS_MODE");
-
-	if (cache_mode == NULL || strcmp(cache_mode, "local") != 0) {
-		return android_gethostbyaddrforiface_proxy(addr, len, af, iface, mark);
-	} else {
-		return android_gethostbyaddrforiface_real(addr,len, af, iface, mark);
-	}
-}
-
-struct hostent *
-gethostbyaddr(const void *addr, socklen_t len, int af)
-{
-	return android_gethostbyaddrforiface(addr, len, af, NULL, 0);
-}
-
-
-static void
-_sethtent(int f)
-{
-    res_static  rs = __res_get_static();
-    if (rs == NULL) return;
-	if (!rs->hostf)
-		rs->hostf = fopen(_PATH_HOSTS, "r" );
-	else
-		rewind(rs->hostf);
-	rs->stayopen = f;
-}
-
-static void
-_endhtent(void)
-{
-    res_static  rs = __res_get_static();
-    if (rs == NULL) return;
-
-	if (rs->hostf && !rs->stayopen) {
-		(void) fclose(rs->hostf);
-		rs->hostf = NULL;
-	}
-}
-
-static struct hostent *
-_gethtent(void)
-{
-	char *p;
-	char *cp, **q;
-	int af, len;
-	res_static  rs = __res_get_static();
-
-	if (!rs->hostf && !(rs->hostf = fopen(_PATH_HOSTS, "r" ))) {
-		h_errno = NETDB_INTERNAL;
-		return NULL;
-	}
- again:
-	if (!(p = fgets(rs->hostbuf, sizeof rs->hostbuf, rs->hostf))) {
-		h_errno = HOST_NOT_FOUND;
-		return NULL;
-	}
-	if (*p == '#')
-		goto again;
-	if (!(cp = strpbrk(p, "#\n")))
-		goto again;
-	*cp = '\0';
-	if (!(cp = strpbrk(p, " \t")))
-		goto again;
-	*cp++ = '\0';
-	if (inet_pton(AF_INET6, p, (char *)(void *)rs->host_addr) > 0) {
-		af = AF_INET6;
-		len = IN6ADDRSZ;
-	} else if (inet_pton(AF_INET, p, (char *)(void *)rs->host_addr) > 0) {
-		res_state res = __res_get_state();
-		if (res == NULL)
-			return NULL;
-		if (res->options & RES_USE_INET6) {
-			map_v4v6_address((char *)(void *)rs->host_addr,
-			    (char *)(void *)rs->host_addr);
-			af = AF_INET6;
-			len = IN6ADDRSZ;
-		} else {
-			af = AF_INET;
-			len = INADDRSZ;
-		}
-		__res_put_state(res);
-	} else {
-		goto again;
-	}
-	/* if this is not something we're looking for, skip it. */
-	if (rs->host.h_addrtype != 0 && rs->host.h_addrtype != af)
-		goto again;
-	if (rs->host.h_length != 0 && rs->host.h_length != len)
-		goto again;
-	rs->h_addr_ptrs[0] = (char *)(void *)rs->host_addr;
-	rs->h_addr_ptrs[1] = NULL;
-	rs->host.h_addr_list = rs->h_addr_ptrs;
-	rs->host.h_length = len;
-	rs->host.h_addrtype = af;
-	while (*cp == ' ' || *cp == '\t')
-		cp++;
-	rs->host.h_name = cp;
-	q = rs->host.h_aliases = rs->host_aliases;
-	if ((cp = strpbrk(cp, " \t")) != NULL)
-		*cp++ = '\0';
-	while (cp && *cp) {
-		if (*cp == ' ' || *cp == '\t') {
-			cp++;
-			continue;
-		}
-		if (q < &rs->host_aliases[MAXALIASES - 1])
-			*q++ = cp;
-		if ((cp = strpbrk(cp, " \t")) != NULL)
-			*cp++ = '\0';
-	}
-	*q = NULL;
-	h_errno = NETDB_SUCCESS;
-	return &rs->host;
-}
-
-/*ARGSUSED*/
-int
-_gethtbyname(void *rv, void *cb_data, va_list ap)
-{
-	struct hostent *hp;
-	const char *name;
-	int af;
-
-	assert(rv != NULL);
-
-	name = va_arg(ap, char *);
-	/* NOSTRICT skip len */(void)va_arg(ap, int);
-	af = va_arg(ap, int);
-
-	hp = NULL;
-#if 0
-	{
-		res_state res = __res_get_state();
-		if (res == NULL)
-			return NS_NOTFOUND;
-		if (res->options & RES_USE_INET6)
-			hp = _gethtbyname2(name, AF_INET6);
-		if (hp==NULL)
-			hp = _gethtbyname2(name, AF_INET);
-		__res_put_state(res);
-	}
-#else
-	hp = _gethtbyname2(name, af);
-#endif
-	*((struct hostent **)rv) = hp;
-	if (hp == NULL) {
-		h_errno = HOST_NOT_FOUND;
-		return NS_NOTFOUND;
-	}
-	return NS_SUCCESS;
-}
-
-static struct hostent *
-_gethtbyname2(const char *name, int af)
-{
-	struct hostent *p;
-	char *tmpbuf, *ptr, **cp;
-	int num;
-	size_t len;
-	res_static rs = __res_get_static();
-
-	assert(name != NULL);
-
-	_sethtent(rs->stayopen);
-	ptr = tmpbuf = NULL;
-	num = 0;
-	while ((p = _gethtent()) != NULL && num < MAXADDRS) {
-		if (p->h_addrtype != af)
-			continue;
-		if (strcasecmp(p->h_name, name) != 0) {
-			for (cp = p->h_aliases; *cp != NULL; cp++)
-				if (strcasecmp(*cp, name) == 0)
-					break;
-			if (*cp == NULL) continue;
-		}
-
-		if (num == 0) {
-			size_t bufsize;
-			char *src;
-
-			bufsize = strlen(p->h_name) + 2 +
-				  MAXADDRS * p->h_length +
-				  ALIGNBYTES;
-			for (cp = p->h_aliases; *cp != NULL; cp++)
-				bufsize += strlen(*cp) + 1;
-
-			if ((tmpbuf = malloc(bufsize)) == NULL) {
-				h_errno = NETDB_INTERNAL;
-				return NULL;
-			}
-
-			ptr = tmpbuf;
-			src = p->h_name;
-			while ((*ptr++ = *src++) != '\0');
-			for (cp = p->h_aliases; *cp != NULL; cp++) {
-				src = *cp;
-				while ((*ptr++ = *src++) != '\0');
-			}
-			*ptr++ = '\0';
-
-			ptr = (char *)(void *)ALIGN(ptr);
-		}
-
-		(void)memcpy(ptr, p->h_addr_list[0], (size_t)p->h_length);
-		ptr += p->h_length;
-		num++;
-	}
-	_endhtent();
-	if (num == 0) return NULL;
-
-	len = ptr - tmpbuf;
-	if (len > (sizeof(rs->hostbuf) - ALIGNBYTES)) {
-		free(tmpbuf);
-		errno = ENOSPC;
-		h_errno = NETDB_INTERNAL;
-		return NULL;
-	}
-	ptr = memcpy((void *)ALIGN(rs->hostbuf), tmpbuf, len);
-	free(tmpbuf);
-
-	rs->host.h_name = ptr;
-	while (*ptr++);
-
-	cp = rs->host_aliases;
-	while (*ptr) {
-		*cp++ = ptr;
-		while (*ptr++);
-	}
-	ptr++;
-	*cp = NULL;
-
-	ptr = (char *)(void *)ALIGN(ptr);
-	cp = rs->h_addr_ptrs;
-	while (num--) {
-		*cp++ = ptr;
-		ptr += rs->host.h_length;
-	}
-	*cp = NULL;
-
-	return &rs->host;
-}
-
-/*ARGSUSED*/
-static int
-_gethtbyaddr(void *rv, void *cb_data, va_list ap)
-{
-	struct hostent *p;
-	const unsigned char *addr;
-	int len, af;
-	res_static  rs = __res_get_static();
-
-	assert(rv != NULL);
-
-	addr = va_arg(ap, unsigned char *);
-	len = va_arg(ap, int);
-	af = va_arg(ap, int);
-
-	rs->host.h_length = len;
-	rs->host.h_addrtype = af;
-
-	_sethtent(rs->stayopen);
-	while ((p = _gethtent()) != NULL)
-		if (p->h_addrtype == af && !memcmp(p->h_addr, addr,
-		    (size_t)len))
-			break;
-	_endhtent();
-	*((struct hostent **)rv) = p;
-	if (p==NULL) {
-		h_errno = HOST_NOT_FOUND;
-		return NS_NOTFOUND;
-	}
-	return NS_SUCCESS;
-}
-
-static void
-map_v4v6_address(const char *src, char *dst)
-{
-	u_char *p = (u_char *)dst;
-	char tmp[INADDRSZ];
-	int i;
-
-	assert(src != NULL);
-	assert(dst != NULL);
-
-	/* Stash a temporary copy so our caller can update in place. */
-	(void)memcpy(tmp, src, INADDRSZ);
-	/* Mark this ipv6 addr as a mapped ipv4. */
-	for (i = 0; i < 10; i++)
-		*p++ = 0x00;
-	*p++ = 0xff;
-	*p++ = 0xff;
-	/* Retrieve the saved copy and we're done. */
-	(void)memcpy((void *)p, tmp, INADDRSZ);
-}
-
-static void
-map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep)
-{
-	char **ap;
-
-	assert(hp != NULL);
-	assert(bpp != NULL);
-	assert(ep != NULL);
-
-	if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
-		return;
-	hp->h_addrtype = AF_INET6;
-	hp->h_length = IN6ADDRSZ;
-	for (ap = hp->h_addr_list; *ap; ap++) {
-		int i = sizeof(align) - (size_t)((u_long)*bpp % sizeof(align));
-
-		if (ep - *bpp < (i + IN6ADDRSZ)) {
-			/* Out of memory.  Truncate address list here.  XXX */
-			*ap = NULL;
-			return;
-		}
-		*bpp += i;
-		map_v4v6_address(*ap, *bpp);
-		*ap = *bpp;
-		*bpp += IN6ADDRSZ;
-	}
-}
-
-static void
-addrsort(char **ap, int num, res_state res)
-{
-	int i, j;
-	char **p;
-	short aval[MAXADDRS];
-	int needsort = 0;
-
-	assert(ap != NULL);
-
-	p = ap;
-	for (i = 0; i < num; i++, p++) {
-	    for (j = 0 ; (unsigned)j < res->nsort; j++)
-		if (res->sort_list[j].addr.s_addr ==
-		    (((struct in_addr *)(void *)(*p))->s_addr &
-		    res->sort_list[j].mask))
-			break;
-	    aval[i] = j;
-	    if (needsort == 0 && i > 0 && j < aval[i-1])
-		needsort = i;
-	}
-	if (!needsort)
-	    return;
-
-	while (needsort < num) {
-	    for (j = needsort - 1; j >= 0; j--) {
-		if (aval[j] > aval[j+1]) {
-		    char *hp;
-
-		    i = aval[j];
-		    aval[j] = aval[j+1];
-		    aval[j+1] = i;
-
-		    hp = ap[j];
-		    ap[j] = ap[j+1];
-		    ap[j+1] = hp;
-		} else
-		    break;
-	    }
-	    needsort++;
-	}
-}
-
-struct hostent *
-gethostent(void)
-{
-    res_static  rs = __res_get_static();
-	rs->host.h_addrtype = 0;
-	rs->host.h_length = 0;
-	return _gethtent();
-}
-
-/*ARGSUSED*/
-static int
-_dns_gethtbyname(void *rv, void *cb_data, va_list ap)
-{
-	querybuf *buf;
-	int n, type;
-	struct hostent *hp;
-	const char *name;
-	int af;
-	res_state res;
-
-	assert(rv != NULL);
-
-	name = va_arg(ap, char *);
-	/* NOSTRICT skip len */(void)va_arg(ap, int);
-	af = va_arg(ap, int);
-
-	switch (af) {
-	case AF_INET:
-		type = T_A;
-		break;
-	case AF_INET6:
-		type = T_AAAA;
-		break;
-	default:
-		return NS_UNAVAIL;
-	}
-	buf = malloc(sizeof(*buf));
-	if (buf == NULL) {
-		h_errno = NETDB_INTERNAL;
-		return NS_NOTFOUND;
-	}
-	res = __res_get_state();
-	if (res == NULL) {
-		free(buf);
-		return NS_NOTFOUND;
-	}
-	n = res_nsearch(res, name, C_IN, type, buf->buf, sizeof(buf->buf));
-	if (n < 0) {
-		free(buf);
-		dprintf("res_nsearch failed (%d)\n", res, n);
-		__res_put_state(res);
-		return NS_NOTFOUND;
-	}
-	hp = getanswer(buf, n, name, type, res);
-	free(buf);
-	__res_put_state(res);
-	if (hp == NULL)
-		switch (h_errno) {
-		case HOST_NOT_FOUND:
-			return NS_NOTFOUND;
-		case TRY_AGAIN:
-			return NS_TRYAGAIN;
-		default:
-			return NS_UNAVAIL;
-		}
-	*((struct hostent **)rv) = hp;
-	return NS_SUCCESS;
-}
-
-/*ARGSUSED*/
-static int
-_dns_gethtbyaddr(void *rv, void	*cb_data, va_list ap)
-{
-	char qbuf[MAXDNAME + 1], *qp, *ep;
-	int n;
-	querybuf *buf;
-	struct hostent *hp;
-	const unsigned char *uaddr;
-	int len, af, advance;
-	res_state res;
-	const char* iface;
-	int mark;
-	res_static rs = __res_get_static();
-
-	assert(rv != NULL);
-
-	uaddr = va_arg(ap, unsigned char *);
-	len = va_arg(ap, int);
-	af = va_arg(ap, int);
-	iface = va_arg(ap, char *);
-	mark = va_arg(ap, int);
-
-	switch (af) {
-	case AF_INET:
-		(void)snprintf(qbuf, sizeof(qbuf), "%u.%u.%u.%u.in-addr.arpa",
-		    (uaddr[3] & 0xff), (uaddr[2] & 0xff),
-		    (uaddr[1] & 0xff), (uaddr[0] & 0xff));
-		break;
-
-	case AF_INET6:
-		qp = qbuf;
-		ep = qbuf + sizeof(qbuf) - 1;
-		for (n = IN6ADDRSZ - 1; n >= 0; n--) {
-			advance = snprintf(qp, (size_t)(ep - qp), "%x.%x.",
-			    uaddr[n] & 0xf,
-			    ((unsigned int)uaddr[n] >> 4) & 0xf);
-			if (advance > 0 && qp + advance < ep)
-				qp += advance;
-			else {
-				h_errno = NETDB_INTERNAL;
-				return NS_NOTFOUND;
-			}
-		}
-		if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) {
-			h_errno = NETDB_INTERNAL;
-			return NS_NOTFOUND;
-		}
-		break;
-	default:
-		abort();
-	}
-
-	buf = malloc(sizeof(*buf));
-	if (buf == NULL) {
-		h_errno = NETDB_INTERNAL;
-		return NS_NOTFOUND;
-	}
-	res = __res_get_state();
-	if (res == NULL) {
-		free(buf);
-		return NS_NOTFOUND;
-	}
-	res_setiface(res, iface);
-	res_setmark(res, mark);
-	n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf));
-	if (n < 0) {
-		free(buf);
-		dprintf("res_nquery failed (%d)\n", res, n);
-		__res_put_state(res);
-		return NS_NOTFOUND;
-	}
-	hp = getanswer(buf, n, qbuf, T_PTR, res);
-	free(buf);
-	if (hp == NULL) {
-		__res_put_state(res);
-		switch (h_errno) {
-		case HOST_NOT_FOUND:
-			return NS_NOTFOUND;
-		case TRY_AGAIN:
-			return NS_TRYAGAIN;
-		default:
-			return NS_UNAVAIL;
-		}
-	}
-	hp->h_addrtype = af;
-	hp->h_length = len;
-	(void)memcpy(rs->host_addr, uaddr, (size_t)len);
-	rs->h_addr_ptrs[0] = (char *)(void *)rs->host_addr;
-	rs->h_addr_ptrs[1] = NULL;
-	if (af == AF_INET && (res->options & RES_USE_INET6)) {
-		map_v4v6_address((char *)(void *)rs->host_addr,
-		    (char *)(void *)rs->host_addr);
-		hp->h_addrtype = AF_INET6;
-		hp->h_length = IN6ADDRSZ;
-	}
-
-	__res_put_state(res);
-	*((struct hostent **)rv) = hp;
-	h_errno = NETDB_SUCCESS;
-	return NS_SUCCESS;
-}
diff --git a/libc/netbsd/inet/nsap_addr.c b/libc/netbsd/inet/nsap_addr.c
deleted file mode 100644
index e18bd33..0000000
--- a/libc/netbsd/inet/nsap_addr.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*	$NetBSD: nsap_addr.c,v 1.2 2004/05/20 23:12:33 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static const char rcsid[] = "Id: nsap_addr.c,v 1.2.206.1 2004/03/09 08:33:33 marka Exp";
-#else
-__RCSID("$NetBSD: nsap_addr.c,v 1.2 2004/05/20 23:12:33 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-
-#include <assert.h>
-#include <ctype.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-
-static char
-xtob(int c) {
-	return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
-}
-
-u_int
-inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) {
-	u_char c, nib;
-	u_int len = 0;
-
-	assert(ascii != NULL);
-	assert(binary != NULL);
-
-	if (ascii[0] != '0' || (ascii[1] != 'x' && ascii[1] != 'X'))
-		return (0);
-	ascii += 2;
-
-	while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
-		if (c == '.' || c == '+' || c == '/')
-			continue;
-		if (!isascii(c))
-			return (0);
-		if (islower(c))
-			c = toupper(c);
-		if (isxdigit(c)) {
-			nib = xtob(c);
-			c = *ascii++;
-			if (c != '\0') {
-				c = toupper(c);
-				if (isxdigit(c)) {
-					*binary++ = (nib << 4) | xtob(c);
-					len++;
-				} else
-					return (0);
-			}
-			else
-				return (0);
-		}
-		else
-			return (0);
-	}
-	return (len);
-}
-
-char *
-inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) {
-	int nib;
-	int i;
-	static char tmpbuf[2+255*3];
-	char *start;
-
-	assert(binary != NULL);
-
-	if (ascii)
-		start = ascii;
-	else {
-		ascii = tmpbuf;
-		start = tmpbuf;
-	}
-
-	*ascii++ = '0';
-	*ascii++ = 'x';
-
-	if (binlen > 255)
-		binlen = 255;
-
-	for (i = 0; i < binlen; i++) {
-		nib = (u_int32_t)*binary >> 4;
-		*ascii++ = nib + (nib < 10 ? '0' : '7');
-		nib = *binary++ & 0x0f;
-		*ascii++ = nib + (nib < 10 ? '0' : '7');
-		if (((i % 2) == 0 && (i + 1) < binlen))
-			*ascii++ = '.';
-	}
-	*ascii = '\0';
-	return (start);
-}
diff --git a/libc/netbsd/nameser/ns_name.c b/libc/netbsd/nameser/ns_name.c
deleted file mode 100644
index 85d2f60..0000000
--- a/libc/netbsd/nameser/ns_name.c
+++ /dev/null
@@ -1,970 +0,0 @@
-/*	$NetBSD: ns_name.c,v 1.3 2004/11/07 02:19:49 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#ifdef notdef
-static const char rcsid[] = "Id: ns_name.c,v 1.3.2.4.4.2 2004/05/04 03:27:47 marka Exp";
-#else
-__RCSID("$NetBSD: ns_name.c,v 1.3 2004/11/07 02:19:49 christos Exp $");
-#endif
-#endif
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include "arpa_nameser.h"
-
-#include <errno.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-#define NS_TYPE_ELT			0x40 /* EDNS0 extended label type */
-#define DNS_LABELTYPE_BITSTRING		0x41
-
-/* Data. */
-
-static const char	digits[] = "0123456789";
-
-static const char digitvalue[256] = {
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,	/*16*/
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
-	 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1, /*64*/
-	-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
-	-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
-};
-
-/* Forward. */
-
-static int		special(int);
-static int		printable(int);
-static int		dn_find(const u_char *, const u_char *,
-				const u_char * const *,
-				const u_char * const *);
-static int		encode_bitsring(const char **, const char *,
-					unsigned char **, unsigned char **,
-					unsigned const char *);
-static int		labellen(const u_char *);
-static int		decode_bitstring(const unsigned char **,
-					 char *, const char *);
-
-/* Public. */
-
-/*
- * ns_name_ntop(src, dst, dstsiz)
- *	Convert an encoded domain name to printable ascii as per RFC1035.
- * return:
- *	Number of bytes written to buffer, or -1 (with errno set)
- * notes:
- *	The root is returned as "."
- *	All other domains are returned in non absolute form
- */
-int
-ns_name_ntop(const u_char *src, char *dst, size_t dstsiz)
-{
-	const u_char *cp;
-	char *dn, *eom;
-	u_char c;
-	u_int n;
-	int l;
-
-	cp = src;
-	dn = dst;
-	eom = dst + dstsiz;
-
-	while ((n = *cp++) != 0) {
-		if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
-			/* Some kind of compression pointer. */
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		if (dn != dst) {
-			if (dn >= eom) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			*dn++ = '.';
-		}
-		if ((l = labellen(cp - 1)) < 0) {
-			errno = EMSGSIZE; /* XXX */
-			return(-1);
-		}
-		if (dn + l >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) {
-			int m;
-
-			if (n != DNS_LABELTYPE_BITSTRING) {
-				/* XXX: labellen should reject this case */
-				errno = EINVAL;
-				return(-1);
-			}
-			if ((m = decode_bitstring(&cp, dn, eom)) < 0)
-			{
-				errno = EMSGSIZE;
-				return(-1);
-			}
-			dn += m;
-			continue;
-		}
-		for (; l > 0; l--) {
-			c = *cp++;
-			if (special(c)) {
-				if (dn + 1 >= eom) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				*dn++ = '\\';
-				*dn++ = (char)c;
-			} else if (!printable(c)) {
-				if (dn + 3 >= eom) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				*dn++ = '\\';
-				*dn++ = digits[c / 100];
-				*dn++ = digits[(c % 100) / 10];
-				*dn++ = digits[c % 10];
-			} else {
-				if (dn >= eom) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				*dn++ = (char)c;
-			}
-		}
-	}
-	if (dn == dst) {
-		if (dn >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		*dn++ = '.';
-	}
-	if (dn >= eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	*dn++ = '\0';
-	return (dn - dst);
-}
-
-/*
- * ns_name_pton(src, dst, dstsiz)
- *	Convert a ascii string into an encoded domain name as per RFC1035.
- * return:
- *	-1 if it fails
- *	1 if string was fully qualified
- *	0 is string was not fully qualified
- * notes:
- *	Enforces label and domain length limits.
- */
-
-int
-ns_name_pton(const char *src, u_char *dst, size_t dstsiz)
-{
-	u_char *label, *bp, *eom;
-	int c, n, escaped, e = 0;
-	char *cp;
-
-	escaped = 0;
-	bp = dst;
-	eom = dst + dstsiz;
-	label = bp++;
-
-	while ((c = *src++) != 0) {
-		if (escaped) {
-			if (c == '[') { /* start a bit string label */
-				if ((cp = strchr(src, ']')) == NULL) {
-					errno = EINVAL; /* ??? */
-					return(-1);
-				}
-				if ((e = encode_bitsring(&src, cp + 2,
-							 &label, &bp, eom))
-				    != 0) {
-					errno = e;
-					return(-1);
-				}
-				escaped = 0;
-				label = bp++;
-				if ((c = *src++) == 0)
-					goto done;
-				else if (c != '.') {
-					errno = EINVAL;
-					return(-1);
-				}
-				continue;
-			}
-			else if ((cp = strchr(digits, c)) != NULL) {
-				n = (cp - digits) * 100;
-				if ((c = *src++) == 0 ||
-				    (cp = strchr(digits, c)) == NULL) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				n += (cp - digits) * 10;
-				if ((c = *src++) == 0 ||
-				    (cp = strchr(digits, c)) == NULL) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				n += (cp - digits);
-				if (n > 255) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				c = n;
-			}
-			escaped = 0;
-		} else if (c == '\\') {
-			escaped = 1;
-			continue;
-		} else if (c == '.') {
-			c = (bp - label - 1);
-			if ((c & NS_CMPRSFLGS) != 0) {	/* Label too big. */
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			if (label >= eom) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			*label = c;
-			/* Fully qualified ? */
-			if (*src == '\0') {
-				if (c != 0) {
-					if (bp >= eom) {
-						errno = EMSGSIZE;
-						return (-1);
-					}
-					*bp++ = '\0';
-				}
-				if ((bp - dst) > MAXCDNAME) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				return (1);
-			}
-			if (c == 0 || *src == '.') {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			label = bp++;
-			continue;
-		}
-		if (bp >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		*bp++ = (u_char)c;
-	}
-	c = (bp - label - 1);
-	if ((c & NS_CMPRSFLGS) != 0) {		/* Label too big. */
-		errno = EMSGSIZE;
-		return (-1);
-	}
-  done:
-	if (label >= eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	*label = c;
-	if (c != 0) {
-		if (bp >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		*bp++ = 0;
-	}
-	if ((bp - dst) > MAXCDNAME) {	/* src too big */
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	return (0);
-}
-
-/*
- * ns_name_ntol(src, dst, dstsiz)
- *	Convert a network strings labels into all lowercase.
- * return:
- *	Number of bytes written to buffer, or -1 (with errno set)
- * notes:
- *	Enforces label and domain length limits.
- */
-
-int
-ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz)
-{
-	const u_char *cp;
-	u_char *dn, *eom;
-	u_char c;
-	u_int n;
-	int l;
-
-	cp = src;
-	dn = dst;
-	eom = dst + dstsiz;
-
-	if (dn >= eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	while ((n = *cp++) != 0) {
-		if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
-			/* Some kind of compression pointer. */
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		*dn++ = n;
-		if ((l = labellen(cp - 1)) < 0) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		if (dn + l >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		for (; l > 0; l--) {
-			c = *cp++;
-			if (isupper(c))
-				*dn++ = tolower(c);
-			else
-				*dn++ = c;
-		}
-	}
-	*dn++ = '\0';
-	return (dn - dst);
-}
-
-/*
- * ns_name_unpack(msg, eom, src, dst, dstsiz)
- *	Unpack a domain name from a message, source may be compressed.
- * return:
- *	-1 if it fails, or consumed octets if it succeeds.
- */
-int
-ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
-	       u_char *dst, size_t dstsiz)
-{
-	const u_char *srcp, *dstlim;
-	u_char *dstp;
-	int n, len, checked, l;
-
-	len = -1;
-	checked = 0;
-	dstp = dst;
-	srcp = src;
-	dstlim = dst + dstsiz;
-	if (srcp < msg || srcp >= eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	/* Fetch next label in domain name. */
-	while ((n = *srcp++) != 0) {
-		/* Check for indirection. */
-		switch (n & NS_CMPRSFLGS) {
-		case 0:
-		case NS_TYPE_ELT:
-			/* Limit checks. */
-			if ((l = labellen(srcp - 1)) < 0) {
-				errno = EMSGSIZE;
-				return(-1);
-			}
-			if (dstp + l + 1 >= dstlim || srcp + l >= eom) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			checked += l + 1;
-			*dstp++ = n;
-			memcpy(dstp, srcp, (size_t)l);
-			dstp += l;
-			srcp += l;
-			break;
-
-		case NS_CMPRSFLGS:
-			if (srcp >= eom) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			if (len < 0)
-				len = srcp - src + 1;
-			srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
-			if (srcp < msg || srcp >= eom) {  /* Out of range. */
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			checked += 2;
-			/*
-			 * Check for loops in the compressed name;
-			 * if we've looked at the whole message,
-			 * there must be a loop.
-			 */
-			if (checked >= eom - msg) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			break;
-
-		default:
-			errno = EMSGSIZE;
-			return (-1);			/* flag error */
-		}
-	}
-	*dstp = '\0';
-	if (len < 0)
-		len = srcp - src;
-	return (len);
-}
-
-/*
- * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
- *	Pack domain name 'domain' into 'comp_dn'.
- * return:
- *	Size of the compressed name, or -1.
- * notes:
- *	'dnptrs' is an array of pointers to previous compressed names.
- *	dnptrs[0] is a pointer to the beginning of the message. The array
- *	ends with NULL.
- *	'lastdnptr' is a pointer to the end of the array pointed to
- *	by 'dnptrs'.
- * Side effects:
- *	The list of pointers in dnptrs is updated for labels inserted into
- *	the message as we compress the name.  If 'dnptr' is NULL, we don't
- *	try to compress names. If 'lastdnptr' is NULL, we don't update the
- *	list.
- */
-int
-ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
-	     const u_char **dnptrs, const u_char **lastdnptr)
-{
-	u_char *dstp;
-	const u_char **cpp, **lpp, *eob, *msg;
-	const u_char *srcp;
-	int n, l, first = 1;
-
-	srcp = src;
-	dstp = dst;
-	eob = dstp + dstsiz;
-	lpp = cpp = NULL;
-	if (dnptrs != NULL) {
-		if ((msg = *dnptrs++) != NULL) {
-			for (cpp = dnptrs; *cpp != NULL; cpp++)
-				;
-			lpp = cpp;	/* end of list to search */
-		}
-	} else
-		msg = NULL;
-
-	/* make sure the domain we are about to add is legal */
-	l = 0;
-	do {
-		int l0;
-
-		n = *srcp;
-		if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		if ((l0 = labellen(srcp)) < 0) {
-			errno = EINVAL;
-			return(-1);
-		}
-		l += l0 + 1;
-		if (l > MAXCDNAME) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		srcp += l0 + 1;
-	} while (n != 0);
-
-	/* from here on we need to reset compression pointer array on error */
-	srcp = src;
-	do {
-		/* Look to see if we can use pointers. */
-		n = *srcp;
-		if (n != 0 && msg != NULL) {
-			l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
-				    (const u_char * const *)lpp);
-			if (l >= 0) {
-				if (dstp + 1 >= eob) {
-					goto cleanup;
-				}
-				*dstp++ = ((u_int32_t)l >> 8) | NS_CMPRSFLGS;
-				*dstp++ = l % 256;
-				return (dstp - dst);
-			}
-			/* Not found, save it. */
-			if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
-			    (dstp - msg) < 0x4000 && first) {
-				*cpp++ = dstp;
-				*cpp = NULL;
-				first = 0;
-			}
-		}
-		/* copy label to buffer */
-		if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
-			/* Should not happen. */
-			goto cleanup;
-		}
-		n = labellen(srcp);
-		if (dstp + 1 + n >= eob) {
-			goto cleanup;
-		}
-		memcpy(dstp, srcp, (size_t)(n + 1));
-		srcp += n + 1;
-		dstp += n + 1;
-	} while (n != 0);
-
-	if (dstp > eob) {
-cleanup:
-		if (msg != NULL)
-			*lpp = NULL;
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	return (dstp - dst);
-}
-
-/*
- * ns_name_uncompress(msg, eom, src, dst, dstsiz)
- *	Expand compressed domain name to presentation format.
- * return:
- *	Number of bytes read out of `src', or -1 (with errno set).
- * note:
- *	Root domain returns as "." not "".
- */
-int
-ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
-		   char *dst, size_t dstsiz)
-{
-	u_char tmp[NS_MAXCDNAME];
-	int n;
-
-	if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
-		return (-1);
-	if (ns_name_ntop(tmp, dst, dstsiz) == -1)
-		return (-1);
-	return (n);
-}
-
-/*
- * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
- *	Compress a domain name into wire format, using compression pointers.
- * return:
- *	Number of bytes consumed in `dst' or -1 (with errno set).
- * notes:
- *	'dnptrs' is an array of pointers to previous compressed names.
- *	dnptrs[0] is a pointer to the beginning of the message.
- *	The list ends with NULL.  'lastdnptr' is a pointer to the end of the
- *	array pointed to by 'dnptrs'. Side effect is to update the list of
- *	pointers for labels inserted into the message as we compress the name.
- *	If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
- *	is NULL, we don't update the list.
- */
-int
-ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
-		 const u_char **dnptrs, const u_char **lastdnptr)
-{
-	u_char tmp[NS_MAXCDNAME];
-
-	if (ns_name_pton(src, tmp, sizeof tmp) == -1)
-		return (-1);
-	return (ns_name_pack(tmp, dst, (int)dstsiz, dnptrs, lastdnptr));
-}
-
-/*
- * Reset dnptrs so that there are no active references to pointers at or
- * after src.
- */
-void
-ns_name_rollback(const u_char *src, const u_char **dnptrs,
-		 const u_char **lastdnptr)
-{
-	while (dnptrs < lastdnptr && *dnptrs != NULL) {
-		if (*dnptrs >= src) {
-			*dnptrs = NULL;
-			break;
-		}
-		dnptrs++;
-	}
-}
-
-/*
- * ns_name_skip(ptrptr, eom)
- *	Advance *ptrptr to skip over the compressed name it points at.
- * return:
- *	0 on success, -1 (with errno set) on failure.
- */
-int
-ns_name_skip(const u_char **ptrptr, const u_char *eom)
-{
-	const u_char *cp;
-	u_int n;
-	int l;
-
-	cp = *ptrptr;
-	while (cp < eom && (n = *cp++) != 0) {
-		/* Check for indirection. */
-		switch (n & NS_CMPRSFLGS) {
-		case 0:			/* normal case, n == len */
-			cp += n;
-			continue;
-		case NS_TYPE_ELT: /* EDNS0 extended label */
-			if ((l = labellen(cp - 1)) < 0) {
-				errno = EMSGSIZE; /* XXX */
-				return(-1);
-			}
-			cp += l;
-			continue;
-		case NS_CMPRSFLGS:	/* indirection */
-			cp++;
-			break;
-		default:		/* illegal type */
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		break;
-	}
-	if (cp > eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	*ptrptr = cp;
-	return (0);
-}
-
-/* Private. */
-
-/*
- * special(ch)
- *	Thinking in noninternationalized USASCII (per the DNS spec),
- *	is this characted special ("in need of quoting") ?
- * return:
- *	boolean.
- */
-static int
-special(int ch) {
-	switch (ch) {
-	case 0x22: /* '"' */
-	case 0x2E: /* '.' */
-	case 0x3B: /* ';' */
-	case 0x5C: /* '\\' */
-	case 0x28: /* '(' */
-	case 0x29: /* ')' */
-	/* Special modifiers in zone files. */
-	case 0x40: /* '@' */
-	case 0x24: /* '$' */
-		return (1);
-	default:
-		return (0);
-	}
-}
-
-/*
- * printable(ch)
- *	Thinking in noninternationalized USASCII (per the DNS spec),
- *	is this character visible and not a space when printed ?
- * return:
- *	boolean.
- */
-static int
-printable(int ch) {
-	return (ch > 0x20 && ch < 0x7f);
-}
-
-/*
- *	Thinking in noninternationalized USASCII (per the DNS spec),
- *	convert this character to lower case if it's upper case.
- */
-static int
-mklower(int ch) {
-	if (ch >= 0x41 && ch <= 0x5A)
-		return (ch + 0x20);
-	return (ch);
-}
-
-/*
- * dn_find(domain, msg, dnptrs, lastdnptr)
- *	Search for the counted-label name in an array of compressed names.
- * return:
- *	offset from msg if found, or -1.
- * notes:
- *	dnptrs is the pointer to the first name on the list,
- *	not the pointer to the start of the message.
- */
-static int
-dn_find(const u_char *domain, const u_char *msg,
-	const u_char * const *dnptrs,
-	const u_char * const *lastdnptr)
-{
-	const u_char *dn, *cp, *sp;
-	const u_char * const *cpp;
-	u_int n;
-
-	for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
-		sp = *cpp;
-		/*
-		 * terminate search on:
-		 * root label
-		 * compression pointer
-		 * unusable offset
-		 */
-		while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 &&
-		       (sp - msg) < 0x4000) {
-			dn = domain;
-			cp = sp;
-			while ((n = *cp++) != 0) {
-				/*
-				 * check for indirection
-				 */
-				switch (n & NS_CMPRSFLGS) {
-				case 0:		/* normal case, n == len */
-					n = labellen(cp - 1); /* XXX */
-
-					if (n != *dn++)
-						goto next;
-
-					for (; n > 0; n--)
-						if (mklower(*dn++) !=
-						    mklower(*cp++))
-							goto next;
-					/* Is next root for both ? */
-					if (*dn == '\0' && *cp == '\0')
-						return (sp - msg);
-					if (*dn)
-						continue;
-					goto next;
-				case NS_CMPRSFLGS:	/* indirection */
-					cp = msg + (((n & 0x3f) << 8) | *cp);
-					break;
-
-				default:	/* illegal type */
-					errno = EMSGSIZE;
-					return (-1);
-				}
-			}
- next: ;
-			sp += *sp + 1;
-		}
-	}
-	errno = ENOENT;
-	return (-1);
-}
-
-static int
-decode_bitstring(const unsigned char **cpp, char *dn, const char *eom)
-{
-	const unsigned char *cp = *cpp;
-	char *beg = dn, tc;
-	int b, blen, plen, i;
-
-	if ((blen = (*cp & 0xff)) == 0)
-		blen = 256;
-	plen = (blen + 3) / 4;
-	plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1);
-	if (dn + plen >= eom)
-		return(-1);
-
-	cp++;
-	i = SPRINTF((dn, "\\[x"));
-	if (i < 0)
-		return (-1);
-	dn += i;
-	for (b = blen; b > 7; b -= 8, cp++) {
-		i = SPRINTF((dn, "%02x", *cp & 0xff));
-		if (i < 0)
-			return (-1);
-		dn += i;
-	}
-	if (b > 4) {
-		tc = *cp++;
-		i = SPRINTF((dn, "%02x", tc & (0xff << (8 - b))));
-		if (i < 0)
-			return (-1);
-		dn += i;
-	} else if (b > 0) {
-		tc = *cp++;
-		i = SPRINTF((dn, "%1x",
-			       (((u_int32_t)tc >> 4) & 0x0f) & (0x0f << (4 - b))));
-		if (i < 0)
-			return (-1);
-		dn += i;
-	}
-	i = SPRINTF((dn, "/%d]", blen));
-	if (i < 0)
-		return (-1);
-	dn += i;
-
-	*cpp = cp;
-	return(dn - beg);
-}
-
-static int
-encode_bitsring(const char **bp, const char *end, unsigned char **labelp,
-	        unsigned char ** dst, unsigned const char *eom)
-{
-	int afterslash = 0;
-	const char *cp = *bp;
-	unsigned char *tp;
-	char c;
-	const char *beg_blen;
-	char *end_blen = NULL;
-	int value = 0, count = 0, tbcount = 0, blen = 0;
-
-	beg_blen = end_blen = NULL;
-
-	/* a bitstring must contain at least 2 characters */
-	if (end - cp < 2)
-		return(EINVAL);
-
-	/* XXX: currently, only hex strings are supported */
-	if (*cp++ != 'x')
-		return(EINVAL);
-	if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */
-		return(EINVAL);
-
-	for (tp = *dst + 1; cp < end && tp < eom; cp++) {
-		switch((c = *cp)) {
-		case ']':	/* end of the bitstring */
-			if (afterslash) {
-				if (beg_blen == NULL)
-					return(EINVAL);
-				blen = (int)strtol(beg_blen, &end_blen, 10);
-				if (*end_blen != ']')
-					return(EINVAL);
-			}
-			if (count)
-				*tp++ = ((value << 4) & 0xff);
-			cp++;	/* skip ']' */
-			goto done;
-		case '/':
-			afterslash = 1;
-			break;
-		default:
-			if (afterslash) {
-				if (!isdigit(c&0xff))
-					return(EINVAL);
-				if (beg_blen == NULL) {
-
-					if (c == '0') {
-						/* blen never begings with 0 */
-						return(EINVAL);
-					}
-					beg_blen = cp;
-				}
-			} else {
-				if (!isxdigit(c&0xff))
-					return(EINVAL);
-				value <<= 4;
-				value += digitvalue[(int)c];
-				count += 4;
-				tbcount += 4;
-				if (tbcount > 256)
-					return(EINVAL);
-				if (count == 8) {
-					*tp++ = value;
-					count = 0;
-				}
-			}
-			break;
-		}
-	}
-  done:
-	if (cp >= end || tp >= eom)
-		return(EMSGSIZE);
-
-	/*
-	 * bit length validation:
-	 * If a <length> is present, the number of digits in the <bit-data>
-	 * MUST be just sufficient to contain the number of bits specified
-	 * by the <length>. If there are insignificant bits in a final
-	 * hexadecimal or octal digit, they MUST be zero.
-	 * RFC 2673, Section 3.2.
-	 */
-	if (blen > 0) {
-		int traillen;
-
-		if (((blen + 3) & ~3) != tbcount)
-			return(EINVAL);
-		traillen = tbcount - blen; /* between 0 and 3 */
-		if (((value << (8 - traillen)) & 0xff) != 0)
-			return(EINVAL);
-	}
-	else
-		blen = tbcount;
-	if (blen == 256)
-		blen = 0;
-
-	/* encode the type and the significant bit fields */
-	**labelp = DNS_LABELTYPE_BITSTRING;
-	**dst = blen;
-
-	*bp = cp;
-	*dst = tp;
-
-	return(0);
-}
-
-static int
-labellen(const u_char *lp)
-{
-	int bitlen;
-	u_char l = *lp;
-
-	if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
-		/* should be avoided by the caller */
-		return(-1);
-	}
-
-	if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT) {
-		if (l == DNS_LABELTYPE_BITSTRING) {
-			if ((bitlen = *(lp + 1)) == 0)
-				bitlen = 256;
-			return((bitlen + 7 ) / 8 + 1);
-		}
-		return(-1);	/* unknwon ELT */
-	}
-	return(l);
-}
diff --git a/libc/netbsd/nameser/ns_netint.c b/libc/netbsd/nameser/ns_netint.c
deleted file mode 100644
index 1b2964f..0000000
--- a/libc/netbsd/nameser/ns_netint.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*	$NetBSD: ns_netint.c,v 1.2 2004/05/20 20:19:00 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#ifdef notdef
-static const char rcsid[] = "Id: ns_netint.c,v 1.1.206.1 2004/03/09 08:33:44 marka Exp";
-#else
-__RCSID("$NetBSD: ns_netint.c,v 1.2 2004/05/20 20:19:00 christos Exp $");
-#endif
-#endif
-
-/* Import. */
-
-#include "arpa_nameser.h"
-
-/* Public. */
-
-u_int16_t
-ns_get16(const u_char *src) {
-	u_int dst;
-
-	NS_GET16(dst, src);
-	return (dst);
-}
-
-u_int32_t
-ns_get32(const u_char *src) {
-	u_long dst;
-
-	NS_GET32(dst, src);
-	return (dst);
-}
-
-void
-ns_put16(u_int16_t src, u_char *dst) {
-	NS_PUT16(src, dst);
-}
-
-void
-ns_put32(u_int32_t src, u_char *dst) {
-	NS_PUT32(src, dst);
-}
diff --git a/libc/netbsd/nameser/ns_parse.c b/libc/netbsd/nameser/ns_parse.c
deleted file mode 100644
index fd94860..0000000
--- a/libc/netbsd/nameser/ns_parse.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*	$NetBSD: ns_parse.c,v 1.2 2004/05/20 20:35:05 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#ifdef notdef
-static const char rcsid[] = "Id: ns_parse.c,v 1.3.2.1.4.1 2004/03/09 08:33:44 marka Exp";
-#else
-__RCSID("$NetBSD: ns_parse.c,v 1.2 2004/05/20 20:35:05 christos Exp $");
-#endif
-#endif
-
-/* Import. */
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include "arpa_nameser.h"
-
-#include <errno.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <string.h>
-
-/* Forward. */
-
-static void	setsection(ns_msg *msg, ns_sect sect);
-
-/* Macros. */
-
-#define RETERR(err) do { errno = (err); return (-1); } while (/*NOTREACHED*//*CONSTCOND*/0)
-
-/* Public. */
-
-/* These need to be in the same order as the nres.h:ns_flag enum. */
-const struct _ns_flagdata _ns_flagdata[16] = {
-	{ 0x8000, 15 },		/* qr. */
-	{ 0x7800, 11 },		/* opcode. */
-	{ 0x0400, 10 },		/* aa. */
-	{ 0x0200, 9 },		/* tc. */
-	{ 0x0100, 8 },		/* rd. */
-	{ 0x0080, 7 },		/* ra. */
-	{ 0x0040, 6 },		/* z. */
-	{ 0x0020, 5 },		/* ad. */
-	{ 0x0010, 4 },		/* cd. */
-	{ 0x000f, 0 },		/* rcode. */
-	{ 0x0000, 0 },		/* expansion (1/6). */
-	{ 0x0000, 0 },		/* expansion (2/6). */
-	{ 0x0000, 0 },		/* expansion (3/6). */
-	{ 0x0000, 0 },		/* expansion (4/6). */
-	{ 0x0000, 0 },		/* expansion (5/6). */
-	{ 0x0000, 0 },		/* expansion (6/6). */
-};
-
-int ns_msg_getflag(ns_msg handle, int flag) {
-	return((u_int32_t)((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift);
-}
-
-int
-ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
-	const u_char *optr = ptr;
-
-	for (; count > 0; count--) {
-		int b, rdlength;
-
-		b = dn_skipname(ptr, eom);
-		if (b < 0)
-			RETERR(EMSGSIZE);
-		ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;
-		if (section != ns_s_qd) {
-			if (ptr + NS_INT32SZ + NS_INT16SZ > eom)
-				RETERR(EMSGSIZE);
-			ptr += NS_INT32SZ/*TTL*/;
-			NS_GET16(rdlength, ptr);
-			ptr += rdlength/*RData*/;
-		}
-	}
-	if (ptr > eom)
-		RETERR(EMSGSIZE);
-	return (ptr - optr);
-}
-
-int
-ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
-	const u_char *eom = msg + msglen;
-	int i;
-
-	memset(handle, 0x5e, sizeof *handle);
-	handle->_msg = msg;
-	handle->_eom = eom;
-	if (msg + NS_INT16SZ > eom)
-		RETERR(EMSGSIZE);
-	NS_GET16(handle->_id, msg);
-	if (msg + NS_INT16SZ > eom)
-		RETERR(EMSGSIZE);
-	NS_GET16(handle->_flags, msg);
-	for (i = 0; i < ns_s_max; i++) {
-		if (msg + NS_INT16SZ > eom)
-			RETERR(EMSGSIZE);
-		NS_GET16(handle->_counts[i], msg);
-	}
-	for (i = 0; i < ns_s_max; i++)
-		if (handle->_counts[i] == 0)
-			handle->_sections[i] = NULL;
-		else {
-			int b = ns_skiprr(msg, eom, (ns_sect)i,
-					  handle->_counts[i]);
-
-			if (b < 0)
-				return (-1);
-			handle->_sections[i] = msg;
-			msg += b;
-		}
-	if (msg != eom)
-		RETERR(EMSGSIZE);
-	setsection(handle, ns_s_max);
-	return (0);
-}
-
-int
-ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
-	int b;
-
-	/* Make section right. */
-	if ((unsigned)section >= (unsigned)ns_s_max)
-		RETERR(ENODEV);
-	if (section != handle->_sect)
-		setsection(handle, section);
-
-	/* Make rrnum right. */
-	if (rrnum == -1)
-		rrnum = handle->_rrnum;
-	if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
-		RETERR(ENODEV);
-	if (rrnum < handle->_rrnum)
-		setsection(handle, section);
-	if (rrnum > handle->_rrnum) {
-		b = ns_skiprr(handle->_msg_ptr, handle->_eom, section,
-			      rrnum - handle->_rrnum);
-
-		if (b < 0)
-			return (-1);
-		handle->_msg_ptr += b;
-		handle->_rrnum = rrnum;
-	}
-
-	/* Do the parse. */
-	b = dn_expand(handle->_msg, handle->_eom,
-		      handle->_msg_ptr, rr->name, NS_MAXDNAME);
-	if (b < 0)
-		return (-1);
-	handle->_msg_ptr += b;
-	if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom)
-		RETERR(EMSGSIZE);
-	NS_GET16(rr->type, handle->_msg_ptr);
-	NS_GET16(rr->rr_class, handle->_msg_ptr);
-	if (section == ns_s_qd) {
-		rr->ttl = 0;
-		rr->rdlength = 0;
-		rr->rdata = NULL;
-	} else {
-		if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom)
-			RETERR(EMSGSIZE);
-		NS_GET32(rr->ttl, handle->_msg_ptr);
-		NS_GET16(rr->rdlength, handle->_msg_ptr);
-		if (handle->_msg_ptr + rr->rdlength > handle->_eom)
-			RETERR(EMSGSIZE);
-		rr->rdata = handle->_msg_ptr;
-		handle->_msg_ptr += rr->rdlength;
-	}
-	if (++handle->_rrnum > handle->_counts[(int)section])
-		setsection(handle, (ns_sect)((int)section + 1));
-
-	/* All done. */
-	return (0);
-}
-
-/* Private. */
-
-static void
-setsection(ns_msg *msg, ns_sect sect) {
-	msg->_sect = sect;
-	if (sect == ns_s_max) {
-		msg->_rrnum = -1;
-		msg->_msg_ptr = NULL;
-	} else {
-		msg->_rrnum = 0;
-		msg->_msg_ptr = msg->_sections[(int)sect];
-	}
-}
diff --git a/libc/netbsd/nameser/ns_print.c b/libc/netbsd/nameser/ns_print.c
deleted file mode 100644
index 7465e62..0000000
--- a/libc/netbsd/nameser/ns_print.c
+++ /dev/null
@@ -1,915 +0,0 @@
-/*	$NetBSD: ns_print.c,v 1.5 2004/11/07 02:19:49 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#ifdef notdef
-static const char rcsid[] = "Id: ns_print.c,v 1.3.2.1.4.5 2004/07/28 20:16:45 marka Exp";
-#else
-__RCSID("$NetBSD: ns_print.c,v 1.5 2004/11/07 02:19:49 christos Exp $");
-#endif
-#endif
-
-/* Import. */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include "arpa_nameser.h"
-#include <arpa/inet.h>
-
-#include <isc/assertions.h>
-#include <isc/dst.h>
-#include <errno.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <string.h>
-#include <ctype.h>
-#include <assert.h>
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-#ifndef MIN
-#define	MIN(x,y)	((x)<(y)?(x):(y))
-#endif
-
-/* Forward. */
-
-static size_t	prune_origin(const char *name, const char *origin);
-static int	charstr(const u_char *rdata, const u_char *edata,
-			char **buf, size_t *buflen);
-static int	addname(const u_char *msg, size_t msglen,
-			const u_char **p, const char *origin,
-			char **buf, size_t *buflen);
-static void	addlen(size_t len, char **buf, size_t *buflen);
-static int	addstr(const char *src, size_t len,
-		       char **buf, size_t *buflen);
-static int	addtab(size_t len, size_t target, int spaced,
-		       char **buf, size_t *buflen);
-
-/* Macros. */
-
-#define	T(x) \
-	do { \
-		if ((x) < 0) \
-			return (-1); \
-	} while (/*CONSTCOND*/0)
-
-/* Public. */
-
-/*
- * int
- * ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen)
- *	Convert an RR to presentation format.
- * return:
- *	Number of characters written to buf, or -1 (check errno).
- */
-int
-ns_sprintrr(const ns_msg *handle, const ns_rr *rr,
-	    const char *name_ctx, const char *origin,
-	    char *buf, size_t buflen)
-{
-	int n;
-
-	n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),
-			 ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),
-			 ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),
-			 name_ctx, origin, buf, buflen);
-	return (n);
-}
-
-/*
- * int
- * ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen,
- *	       name_ctx, origin, buf, buflen)
- *	Convert the fields of an RR into presentation format.
- * return:
- *	Number of characters written to buf, or -1 (check errno).
- */
-int
-ns_sprintrrf(const u_char *msg, size_t msglen,
-	    const char *name, ns_class class, ns_type type,
-	    u_long ttl, const u_char *rdata, size_t rdlen,
-	    const char *name_ctx, const char *origin,
-	    char *buf, size_t buflen)
-{
-	const char *obuf = buf;
-	const u_char *edata = rdata + rdlen;
-	int spaced = 0;
-
-	const char *comment;
-	char tmp[100];
-	int len, x;
-
-	/*
-	 * Owner.
-	 */
-	if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) {
-		T(addstr("\t\t\t", (size_t)3, &buf, &buflen));
-	} else {
-		len = prune_origin(name, origin);
-		if (*name == '\0') {
-			goto root;
-		} else if (len == 0) {
-			T(addstr("@\t\t\t", (size_t)4, &buf, &buflen));
-		} else {
-			T(addstr(name, (size_t)len, &buf, &buflen));
-			/* Origin not used or not root, and no trailing dot? */
-			if (((origin == NULL || origin[0] == '\0') ||
-			    (origin[0] != '.' && origin[1] != '\0' &&
-			    name[len] == '\0')) && name[len - 1] != '.') {
- root:
-				T(addstr(".", (size_t)1, &buf, &buflen));
-				len++;
-			}
-			T(spaced = addtab((size_t)len, 24, spaced, &buf, &buflen));
-		}
-	}
-
-	/*
-	 * TTL, Class, Type.
-	 */
-	T(x = ns_format_ttl(ttl, buf, buflen));
-	addlen((size_t)x, &buf, &buflen);
-	len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
-	T(addstr(tmp, (size_t)len, &buf, &buflen));
-	T(spaced = addtab((size_t)(x + len), (size_t)16, spaced, &buf, &buflen));
-
-	/*
-	 * RData.
-	 */
-	switch (type) {
-	case ns_t_a:
-		if (rdlen != (size_t)NS_INADDRSZ)
-			goto formerr;
-		(void) inet_ntop(AF_INET, rdata, buf, buflen);
-		addlen(strlen(buf), &buf, &buflen);
-		break;
-
-	case ns_t_cname:
-	case ns_t_mb:
-	case ns_t_mg:
-	case ns_t_mr:
-	case ns_t_ns:
-	case ns_t_ptr:
-	case ns_t_dname:
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		break;
-
-	case ns_t_hinfo:
-	case ns_t_isdn:
-		/* First word. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-
-
-		/* Second word, optional in ISDN records. */
-		if (type == ns_t_isdn && rdata == edata)
-			break;
-
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		break;
-
-	case ns_t_soa: {
-		u_long t;
-
-		/* Server name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-
-		/* Administrator name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" (\n", (size_t)3, &buf, &buflen));
-		spaced = 0;
-
-		if ((edata - rdata) != 5*NS_INT32SZ)
-			goto formerr;
-
-		/* Serial number. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
-		len = SPRINTF((tmp, "%lu", t));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
-		T(addstr("; serial\n", (size_t)9, &buf, &buflen));
-		spaced = 0;
-
-		/* Refresh interval. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
-		T(len = ns_format_ttl(t, buf, buflen));
-		addlen((size_t)len, &buf, &buflen);
-		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
-		T(addstr("; refresh\n", (size_t)10, &buf, &buflen));
-		spaced = 0;
-
-		/* Retry interval. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
-		T(len = ns_format_ttl(t, buf, buflen));
-		addlen((size_t)len, &buf, &buflen);
-		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
-		T(addstr("; retry\n", (size_t)8, &buf, &buflen));
-		spaced = 0;
-
-		/* Expiry. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
-		T(len = ns_format_ttl(t, buf, buflen));
-		addlen((size_t)len, &buf, &buflen);
-		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
-		T(addstr("; expiry\n", (size_t)9, &buf, &buflen));
-		spaced = 0;
-
-		/* Minimum TTL. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen));
-		T(len = ns_format_ttl(t, buf, buflen));
-		addlen((size_t)len, &buf, &buflen);
-		T(addstr(" )", (size_t)2, &buf, &buflen));
-		T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen));
-		T(addstr("; minimum\n", (size_t)10, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_mx:
-	case ns_t_afsdb:
-	case ns_t_rt: {
-		u_int t;
-
-		if (rdlen < (size_t)NS_INT16SZ)
-			goto formerr;
-
-		/* Priority. */
-		t = ns_get16(rdata);
-		rdata += NS_INT16SZ;
-		len = SPRINTF((tmp, "%u ", t));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* Target. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_px: {
-		u_int t;
-
-		if (rdlen < (size_t)NS_INT16SZ)
-			goto formerr;
-
-		/* Priority. */
-		t = ns_get16(rdata);
-		rdata += NS_INT16SZ;
-		len = SPRINTF((tmp, "%u ", t));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* Name1. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-
-		/* Name2. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_x25:
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		break;
-
-	case ns_t_txt:
-		while (rdata < edata) {
-			T(len = charstr(rdata, edata, &buf, &buflen));
-			if (len == 0)
-				goto formerr;
-			rdata += len;
-			if (rdata < edata)
-				T(addstr(" ", (size_t)1, &buf, &buflen));
-		}
-		break;
-
-	case ns_t_nsap: {
-		char t[2+255*3];
-
-		(void) inet_nsap_ntoa((int)rdlen, rdata, t);
-		T(addstr(t, strlen(t), &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_aaaa:
-		if (rdlen != (size_t)NS_IN6ADDRSZ)
-			goto formerr;
-		(void) inet_ntop(AF_INET6, rdata, buf, buflen);
-		addlen(strlen(buf), &buf, &buflen);
-		break;
-
-	case ns_t_loc: {
-		char t[255];
-
-		/* XXX protocol format checking? */
-		(void) loc_ntoa(rdata, t);
-		T(addstr(t, strlen(t), &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_naptr: {
-		u_int order, preference;
-		char t[50];
-
-		if (rdlen < 2U*NS_INT16SZ)
-			goto formerr;
-
-		/* Order, Precedence. */
-		order = ns_get16(rdata);	rdata += NS_INT16SZ;
-		preference = ns_get16(rdata);	rdata += NS_INT16SZ;
-		len = SPRINTF((t, "%u %u ", order, preference));
-		T(addstr(t, (size_t)len, &buf, &buflen));
-
-		/* Flags. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-
-		/* Service. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-
-		/* Regexp. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len < 0)
-			return (-1);
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-
-		/* Server. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_srv: {
-		u_int priority, weight, port;
-		char t[50];
-
-		if (rdlen < 3U*NS_INT16SZ)
-			goto formerr;
-
-		/* Priority, Weight, Port. */
-		priority = ns_get16(rdata);  rdata += NS_INT16SZ;
-		weight   = ns_get16(rdata);  rdata += NS_INT16SZ;
-		port     = ns_get16(rdata);  rdata += NS_INT16SZ;
-		len = SPRINTF((t, "%u %u %u ", priority, weight, port));
-		T(addstr(t, (size_t)len, &buf, &buflen));
-
-		/* Server. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_minfo:
-	case ns_t_rp:
-		/* Name1. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-
-		/* Name2. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		break;
-
-	case ns_t_wks: {
-		int n, lcnt;
-
-		if (rdlen < 1U + NS_INT32SZ)
-			goto formerr;
-
-		/* Address. */
-		(void) inet_ntop(AF_INET, rdata, buf, buflen);
-		addlen(strlen(buf), &buf, &buflen);
-		rdata += NS_INADDRSZ;
-
-		/* Protocol. */
-		len = SPRINTF((tmp, " %u ( ", *rdata));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-		rdata += NS_INT8SZ;
-
-		/* Bit map. */
-		n = 0;
-		lcnt = 0;
-		while (rdata < edata) {
-			u_int c = *rdata++;
-			do {
-				if (c & 0200) {
-					if (lcnt == 0) {
-						T(addstr("\n\t\t\t\t", (size_t)5,
-							 &buf, &buflen));
-						lcnt = 10;
-						spaced = 0;
-					}
-					len = SPRINTF((tmp, "%d ", n));
-					T(addstr(tmp, (size_t)len, &buf, &buflen));
-					lcnt--;
-				}
-				c <<= 1;
-			} while (++n & 07);
-		}
-		T(addstr(")", (size_t)1, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_key: {
-		char base64_key[NS_MD5RSA_MAX_BASE64];
-		u_int keyflags, protocol, algorithm, key_id;
-		const char *leader;
-		int n;
-
-		if (rdlen < 0U + NS_INT16SZ + NS_INT8SZ + NS_INT8SZ)
-			goto formerr;
-
-		/* Key flags, Protocol, Algorithm. */
-#ifndef _LIBC
-		key_id = dst_s_dns_key_id(rdata, edata-rdata);
-#else
-		key_id = 0;
-#endif
-		keyflags = ns_get16(rdata);  rdata += NS_INT16SZ;
-		protocol = *rdata++;
-		algorithm = *rdata++;
-		len = SPRINTF((tmp, "0x%04x %u %u",
-			       keyflags, protocol, algorithm));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* Public key data. */
-		len = b64_ntop(rdata, (size_t)(edata - rdata),
-			       base64_key, sizeof base64_key);
-		if (len < 0)
-			goto formerr;
-		if (len > 15) {
-			T(addstr(" (", (size_t)2, &buf, &buflen));
-			leader = "\n\t\t";
-			spaced = 0;
-		} else
-			leader = " ";
-		for (n = 0; n < len; n += 48) {
-			T(addstr(leader, strlen(leader), &buf, &buflen));
-			T(addstr(base64_key + n, (size_t)MIN(len - n, 48),
-				 &buf, &buflen));
-		}
-		if (len > 15)
-			T(addstr(" )", (size_t)2, &buf, &buflen));
-		n = SPRINTF((tmp, " ; key_tag= %u", key_id));
-		T(addstr(tmp, (size_t)n, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_sig: {
-		char base64_key[NS_MD5RSA_MAX_BASE64];
-		u_int typ, algorithm, labels, footprint;
-		const char *leader;
-		u_long t;
-		int n;
-
-		if (rdlen < 22U)
-			goto formerr;
-
-		/* Type covered, Algorithm, Label count, Original TTL. */
-	        typ = ns_get16(rdata);  rdata += NS_INT16SZ;
-		algorithm = *rdata++;
-		labels = *rdata++;
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		len = SPRINTF((tmp, "%s %d %d %lu ",
-			       p_type((int)typ), algorithm, labels, t));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-		if (labels > (u_int)dn_count_labels(name))
-			goto formerr;
-
-		/* Signature expiry. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* Time signed. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* Signature Footprint. */
-		footprint = ns_get16(rdata);  rdata += NS_INT16SZ;
-		len = SPRINTF((tmp, "%u ", footprint));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* Signer's name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		/* Signature. */
-		len = b64_ntop(rdata, (size_t)(edata - rdata),
-			       base64_key, sizeof base64_key);
-		if (len > 15) {
-			T(addstr(" (", (size_t)2, &buf, &buflen));
-			leader = "\n\t\t";
-			spaced = 0;
-		} else
-			leader = " ";
-		if (len < 0)
-			goto formerr;
-		for (n = 0; n < len; n += 48) {
-			T(addstr(leader, strlen(leader), &buf, &buflen));
-			T(addstr(base64_key + n, (size_t)MIN(len - n, 48),
-				 &buf, &buflen));
-		}
-		if (len > 15)
-			T(addstr(" )", (size_t)2, &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_nxt: {
-		int n, c;
-
-		/* Next domain name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		/* Type bit map. */
-		n = edata - rdata;
-		for (c = 0; c < n*8; c++)
-			if (NS_NXT_BIT_ISSET(c, rdata)) {
-				len = SPRINTF((tmp, " %s", p_type(c)));
-				T(addstr(tmp, (size_t)len, &buf, &buflen));
-			}
-		break;
-	    }
-
-	case ns_t_cert: {
-		u_int c_type, key_tag, alg;
-		int n;
-		unsigned int siz;
-		char base64_cert[8192], tmp1[40];
-		const char *leader;
-
-		c_type  = ns_get16(rdata); rdata += NS_INT16SZ;
-		key_tag = ns_get16(rdata); rdata += NS_INT16SZ;
-		alg = (u_int) *rdata++;
-
-		len = SPRINTF((tmp1, "%d %d %d ", c_type, key_tag, alg));
-		T(addstr(tmp1, (size_t)len, &buf, &buflen));
-		siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
-		if (siz > sizeof(base64_cert) * 3/4) {
-			const char *str = "record too long to print";
-			T(addstr(str, strlen(str), &buf, &buflen));
-		}
-		else {
-			len = b64_ntop(rdata, (size_t)(edata-rdata),
-			    base64_cert, siz);
-
-			if (len < 0)
-				goto formerr;
-			else if (len > 15) {
-				T(addstr(" (", (size_t)2, &buf, &buflen));
-				leader = "\n\t\t";
-				spaced = 0;
-			}
-			else
-				leader = " ";
-
-			for (n = 0; n < len; n += 48) {
-				T(addstr(leader, strlen(leader),
-					 &buf, &buflen));
-				T(addstr(base64_cert + n, (size_t)MIN(len - n, 48),
-					 &buf, &buflen));
-			}
-			if (len > 15)
-				T(addstr(" )", (size_t)2, &buf, &buflen));
-		}
-		break;
-	    }
-
-	case ns_t_tkey: {
-		/* KJD - need to complete this */
-		u_long t;
-		int mode, err, keysize;
-
-		/* Algorithm name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-
-		/* Inception. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* Experation. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* Mode , Error, Key Size. */
-		/* Priority, Weight, Port. */
-		mode = ns_get16(rdata);  rdata += NS_INT16SZ;
-		err  = ns_get16(rdata);  rdata += NS_INT16SZ;
-		keysize  = ns_get16(rdata);  rdata += NS_INT16SZ;
-		len = SPRINTF((tmp, "%u %u %u ", mode, err, keysize));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-
-		/* XXX need to dump key, print otherdata length & other data */
-		break;
-	    }
-
-	case ns_t_tsig: {
-		/* BEW - need to complete this */
-		int n;
-
-		T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-		rdata += 8; /* time */
-		n = ns_get16(rdata); rdata += INT16SZ;
-		rdata += n; /* sig */
-		n = ns_get16(rdata); rdata += INT16SZ; /* original id */
-		sprintf(buf, "%d", ns_get16(rdata));
-		rdata += INT16SZ;
-		addlen(strlen(buf), &buf, &buflen);
-		break;
-	    }
-
-	case ns_t_a6: {
-		struct in6_addr a;
-		int pbyte, pbit;
-
-		/* prefix length */
-		if (rdlen == 0U) goto formerr;
-		len = SPRINTF((tmp, "%d ", *rdata));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-		pbit = *rdata;
-		if (pbit > 128) goto formerr;
-		pbyte = (pbit & ~7) / 8;
-		rdata++;
-
-		/* address suffix: provided only when prefix len != 128 */
-		if (pbit < 128) {
-			if (rdata + pbyte >= edata) goto formerr;
-			memset(&a, 0, sizeof(a));
-			memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte);
-			(void) inet_ntop(AF_INET6, &a, buf, buflen);
-			addlen(strlen(buf), &buf, &buflen);
-			rdata += sizeof(a) - pbyte;
-		}
-
-		/* prefix name: provided only when prefix len > 0 */
-		if (pbit == 0)
-			break;
-		if (rdata >= edata) goto formerr;
-		T(addstr(" ", (size_t)1, &buf, &buflen));
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_opt: {
-		len = SPRINTF((tmp, "%u bytes", class));
-		T(addstr(tmp, (size_t)len, &buf, &buflen));
-		break;
-	    }
-
-	default:
-		comment = "unknown RR type";
-		goto hexify;
-	}
-	return (buf - obuf);
- formerr:
-	comment = "RR format error";
- hexify: {
-	int n, m;
-	char *p;
-
-	len = SPRINTF((tmp, "\\# %tu%s\t; %s", edata - rdata,
-		       rdlen != 0 ? " (" : "", comment));
-	T(addstr(tmp, (size_t)len, &buf, &buflen));
-	while (rdata < edata) {
-		p = tmp;
-		p += SPRINTF((p, "\n\t"));
-		spaced = 0;
-		n = MIN(16, edata - rdata);
-		for (m = 0; m < n; m++)
-			p += SPRINTF((p, "%02x ", rdata[m]));
-		T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen));
-		if (n < 16) {
-			T(addstr(")", (size_t)1, &buf, &buflen));
-			T(addtab((size_t)(p - tmp + 1), (size_t)48, spaced, &buf, &buflen));
-		}
-		p = tmp;
-		p += SPRINTF((p, "; "));
-		for (m = 0; m < n; m++)
-			*p++ = (isascii(rdata[m]) && isprint(rdata[m]))
-				? rdata[m]
-				: '.';
-		T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen));
-		rdata += n;
-	}
-	return (buf - obuf);
-    }
-}
-
-/* Private. */
-
-/*
- * size_t
- * prune_origin(name, origin)
- *	Find out if the name is at or under the current origin.
- * return:
- *	Number of characters in name before start of origin,
- *	or length of name if origin does not match.
- * notes:
- *	This function should share code with samedomain().
- */
-static size_t
-prune_origin(const char *name, const char *origin) {
-	const char *oname = name;
-
-	while (*name != '\0') {
-		if (origin != NULL && ns_samename(name, origin) == 1)
-			return (name - oname - (name > oname));
-		while (*name != '\0') {
-			if (*name == '\\') {
-				name++;
-				/* XXX need to handle \nnn form. */
-				if (*name == '\0')
-					break;
-			} else if (*name == '.') {
-				name++;
-				break;
-			}
-			name++;
-		}
-	}
-	return (name - oname);
-}
-
-/*
- * int
- * charstr(rdata, edata, buf, buflen)
- *	Format a <character-string> into the presentation buffer.
- * return:
- *	Number of rdata octets consumed
- *	0 for protocol format error
- *	-1 for output buffer error
- * side effects:
- *	buffer is advanced on success.
- */
-static int
-charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
-	const u_char *odata = rdata;
-	size_t save_buflen = *buflen;
-	char *save_buf = *buf;
-
-	if (addstr("\"", (size_t)1, buf, buflen) < 0)
-		goto enospc;
-	if (rdata < edata) {
-		int n = *rdata;
-
-		if (rdata + 1 + n <= edata) {
-			rdata++;
-			while (n-- > 0) {
-				if (strchr("\n\"\\", *rdata) != NULL)
-					if (addstr("\\", (size_t)1, buf, buflen) < 0)
-						goto enospc;
-				if (addstr((const char *)rdata, (size_t)1,
-					   buf, buflen) < 0)
-					goto enospc;
-				rdata++;
-			}
-		}
-	}
-	if (addstr("\"", (size_t)1, buf, buflen) < 0)
-		goto enospc;
-	return (rdata - odata);
- enospc:
-	errno = ENOSPC;
-	*buf = save_buf;
-	*buflen = save_buflen;
-	return (-1);
-}
-
-static int
-addname(const u_char *msg, size_t msglen,
-	const u_char **pp, const char *origin,
-	char **buf, size_t *buflen)
-{
-	size_t newlen, save_buflen = *buflen;
-	char *save_buf = *buf;
-	int n;
-
-	n = dn_expand(msg, msg + msglen, *pp, *buf, (int)*buflen);
-	if (n < 0)
-		goto enospc;	/* Guess. */
-	newlen = prune_origin(*buf, origin);
-	if (**buf == '\0') {
-		goto root;
-	} else if (newlen == 0U) {
-		/* Use "@" instead of name. */
-		if (newlen + 2 > *buflen)
-			goto enospc;        /* No room for "@\0". */
-		(*buf)[newlen++] = '@';
-		(*buf)[newlen] = '\0';
-	} else {
-		if (((origin == NULL || origin[0] == '\0') ||
-		    (origin[0] != '.' && origin[1] != '\0' &&
-		    (*buf)[newlen] == '\0')) && (*buf)[newlen - 1] != '.') {
-			/* No trailing dot. */
- root:
-			if (newlen + 2 > *buflen)
-				goto enospc;	/* No room for ".\0". */
-			(*buf)[newlen++] = '.';
-			(*buf)[newlen] = '\0';
-		}
-	}
-	*pp += n;
-	addlen(newlen, buf, buflen);
-	**buf = '\0';
-	return (newlen);
- enospc:
-	errno = ENOSPC;
-	*buf = save_buf;
-	*buflen = save_buflen;
-	return (-1);
-}
-
-static void
-addlen(size_t len, char **buf, size_t *buflen) {
-	assert(len <= *buflen);
-	*buf += len;
-	*buflen -= len;
-}
-
-static int
-addstr(const char *src, size_t len, char **buf, size_t *buflen) {
-	if (len >= *buflen) {
-		errno = ENOSPC;
-		return (-1);
-	}
-	memcpy(*buf, src, len);
-	addlen(len, buf, buflen);
-	**buf = '\0';
-	return (0);
-}
-
-static int
-addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) {
-	size_t save_buflen = *buflen;
-	char *save_buf = *buf;
-	int t;
-
-	if (spaced || len >= target - 1) {
-		T(addstr("  ", (size_t)2, buf, buflen));
-		spaced = 1;
-	} else {
-		for (t = (target - len - 1) / 8; t >= 0; t--)
-			if (addstr("\t", (size_t)1, buf, buflen) < 0) {
-				*buflen = save_buflen;
-				*buf = save_buf;
-				return (-1);
-			}
-		spaced = 0;
-	}
-	return (spaced);
-}
diff --git a/libc/netbsd/nameser/ns_samedomain.c b/libc/netbsd/nameser/ns_samedomain.c
deleted file mode 100644
index 04fdb61..0000000
--- a/libc/netbsd/nameser/ns_samedomain.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/*	$NetBSD: ns_samedomain.c,v 1.2 2004/05/20 20:35:05 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1995,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#ifdef notdef
-static const char rcsid[] = "Id: ns_samedomain.c,v 1.1.2.2.4.2 2004/03/16 12:34:17 marka Exp";
-#else
-__RCSID("$NetBSD: ns_samedomain.c,v 1.2 2004/05/20 20:35:05 christos Exp $");
-#endif
-#endif
-
-#include <sys/types.h>
-#include "arpa_nameser.h"
-#include <errno.h>
-#include <string.h>
-
-#ifndef _LIBC
-/*
- * int
- * ns_samedomain(a, b)
- *	Check whether a name belongs to a domain.
- * Inputs:
- *	a - the domain whose ancestory is being verified
- *	b - the potential ancestor we're checking against
- * Return:
- *	boolean - is a at or below b?
- * Notes:
- *	Trailing dots are first removed from name and domain.
- *	Always compare complete subdomains, not only whether the
- *	domain name is the trailing string of the given name.
- *
- *	"host.foobar.top" lies in "foobar.top" and in "top" and in ""
- *	but NOT in "bar.top"
- */
-
-int
-ns_samedomain(const char *a, const char *b) {
-	size_t la, lb;
-	int diff, i, escaped;
-	const char *cp;
-
-	la = strlen(a);
-	lb = strlen(b);
-
-	/* Ignore a trailing label separator (i.e. an unescaped dot) in 'a'. */
-	if (la != 0U && a[la - 1] == '.') {
-		escaped = 0;
-		/* Note this loop doesn't get executed if la==1. */
-		for (i = la - 2; i >= 0; i--)
-			if (a[i] == '\\') {
-				if (escaped)
-					escaped = 0;
-				else
-					escaped = 1;
-			} else
-				break;
-		if (!escaped)
-			la--;
-	}
-
-	/* Ignore a trailing label separator (i.e. an unescaped dot) in 'b'. */
-	if (lb != 0U && b[lb - 1] == '.') {
-		escaped = 0;
-		/* note this loop doesn't get executed if lb==1 */
-		for (i = lb - 2; i >= 0; i--)
-			if (b[i] == '\\') {
-				if (escaped)
-					escaped = 0;
-				else
-					escaped = 1;
-			} else
-				break;
-		if (!escaped)
-			lb--;
-	}
-
-	/* lb == 0 means 'b' is the root domain, so 'a' must be in 'b'. */
-	if (lb == 0U)
-		return (1);
-
-	/* 'b' longer than 'a' means 'a' can't be in 'b'. */
-	if (lb > la)
-		return (0);
-
-	/* 'a' and 'b' being equal at this point indicates sameness. */
-	if (lb == la)
-		return (strncasecmp(a, b, lb) == 0);
-
-	/* Ok, we know la > lb. */
-
-	diff = la - lb;
-
-	/*
-	 * If 'a' is only 1 character longer than 'b', then it can't be
-	 * a subdomain of 'b' (because of the need for the '.' label
-	 * separator).
-	 */
-	if (diff < 2)
-		return (0);
-
-	/*
-	 * If the character before the last 'lb' characters of 'b'
-	 * isn't '.', then it can't be a match (this lets us avoid
-	 * having "foobar.com" match "bar.com").
-	 */
-	if (a[diff - 1] != '.')
-		return (0);
-
-	/*
-	 * We're not sure about that '.', however.  It could be escaped
-         * and thus not a really a label separator.
-	 */
-	escaped = 0;
-	for (i = diff - 2; i >= 0; i--)
-		if (a[i] == '\\') {
-			if (escaped)
-				escaped = 0;
-			else
-				escaped = 1;
-		} else
-			break;
-	if (escaped)
-		return (0);
-
-	/* Now compare aligned trailing substring. */
-	cp = a + diff;
-	return (strncasecmp(cp, b, lb) == 0);
-}
-
-/*
- * int
- * ns_subdomain(a, b)
- *	is "a" a subdomain of "b"?
- */
-int
-ns_subdomain(const char *a, const char *b) {
-	return (ns_samename(a, b) != 1 && ns_samedomain(a, b));
-}
-#endif
-
-/*
- * int
- * ns_makecanon(src, dst, dstsize)
- *	make a canonical copy of domain name "src"
- * notes:
- *	foo -> foo.
- *	foo. -> foo.
- *	foo.. -> foo.
- *	foo\. -> foo\..
- *	foo\\. -> foo\\.
- */
-
-int
-ns_makecanon(const char *src, char *dst, size_t dstsize) {
-	size_t n = strlen(src);
-
-	if (n + sizeof "." > dstsize) {			/* Note: sizeof == 2 */
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	strcpy(dst, src);
-	while (n >= 1U && dst[n - 1] == '.')		/* Ends in "." */
-		if (n >= 2U && dst[n - 2] == '\\' &&	/* Ends in "\." */
-		    (n < 3U || dst[n - 3] != '\\'))	/* But not "\\." */
-			break;
-		else
-			dst[--n] = '\0';
-	dst[n++] = '.';
-	dst[n] = '\0';
-	return (0);
-}
-
-/*
- * int
- * ns_samename(a, b)
- *	determine whether domain name "a" is the same as domain name "b"
- * return:
- *	-1 on error
- *	0 if names differ
- *	1 if names are the same
- */
-
-int
-ns_samename(const char *a, const char *b) {
-	char ta[NS_MAXDNAME], tb[NS_MAXDNAME];
-
-	if (ns_makecanon(a, ta, sizeof ta) < 0 ||
-	    ns_makecanon(b, tb, sizeof tb) < 0)
-		return (-1);
-	if (strcasecmp(ta, tb) == 0)
-		return (1);
-	else
-		return (0);
-}
diff --git a/libc/netbsd/nameser/ns_ttl.c b/libc/netbsd/nameser/ns_ttl.c
deleted file mode 100644
index cc98331..0000000
--- a/libc/netbsd/nameser/ns_ttl.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*	$NetBSD: ns_ttl.c,v 1.2 2004/05/20 20:35:05 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#ifdef notdef
-static const char rcsid[] = "Id: ns_ttl.c,v 1.1.206.1 2004/03/09 08:33:45 marka Exp";
-#else
-__RCSID("$NetBSD: ns_ttl.c,v 1.2 2004/05/20 20:35:05 christos Exp $");
-#endif
-#endif
-
-/* Import. */
-
-#include "arpa_nameser.h"
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/* Forward. */
-
-static int	fmt1(int t, char s, char **buf, size_t *buflen);
-
-/* Macros. */
-
-#define T(x) do { if ((x) < 0) return (-1); } while(0)
-
-/* Public. */
-
-int
-ns_format_ttl(u_long src, char *dst, size_t dstlen) {
-	char *odst = dst;
-	int secs, mins, hours, days, weeks, x;
-	char *p;
-
-	secs = src % 60;   src /= 60;
-	mins = src % 60;   src /= 60;
-	hours = src % 24;  src /= 24;
-	days = src % 7;    src /= 7;
-	weeks = src;       src = 0;
-
-	x = 0;
-	if (weeks) {
-		T(fmt1(weeks, 'W', &dst, &dstlen));
-		x++;
-	}
-	if (days) {
-		T(fmt1(days, 'D', &dst, &dstlen));
-		x++;
-	}
-	if (hours) {
-		T(fmt1(hours, 'H', &dst, &dstlen));
-		x++;
-	}
-	if (mins) {
-		T(fmt1(mins, 'M', &dst, &dstlen));
-		x++;
-	}
-	if (secs || !(weeks || days || hours || mins)) {
-		T(fmt1(secs, 'S', &dst, &dstlen));
-		x++;
-	}
-
-	if (x > 1) {
-		int ch;
-
-		for (p = odst; (ch = *p) != '\0'; p++)
-			if (isascii(ch) && isupper(ch))
-				*p = tolower(ch);
-	}
-
-	return (dst - odst);
-}
-
-#ifndef _LIBC
-int
-ns_parse_ttl(const char *src, u_long *dst) {
-	u_long ttl, tmp;
-	int ch, digits, dirty;
-
-	ttl = 0;
-	tmp = 0;
-	digits = 0;
-	dirty = 0;
-	while ((ch = *src++) != '\0') {
-		if (!isascii(ch) || !isprint(ch))
-			goto einval;
-		if (isdigit(ch)) {
-			tmp *= 10;
-			tmp += (ch - '0');
-			digits++;
-			continue;
-		}
-		if (digits == 0)
-			goto einval;
-		if (islower(ch))
-			ch = toupper(ch);
-		switch (ch) {
-		case 'W':  tmp *= 7;	/*FALLTHROUGH*/
-		case 'D':  tmp *= 24;	/*FALLTHROUGH*/
-		case 'H':  tmp *= 60;	/*FALLTHROUGH*/
-		case 'M':  tmp *= 60;	/*FALLTHROUGH*/
-		case 'S':  break;
-		default:   goto einval;
-		}
-		ttl += tmp;
-		tmp = 0;
-		digits = 0;
-		dirty = 1;
-	}
-	if (digits > 0) {
-		if (dirty)
-			goto einval;
-		else
-			ttl += tmp;
-	}
-	*dst = ttl;
-	return (0);
-
- einval:
-	errno = EINVAL;
-	return (-1);
-}
-#endif
-
-/* Private. */
-
-static int
-fmt1(int t, char s, char **buf, size_t *buflen) {
-	char tmp[50];
-	size_t len;
-
-	len = SPRINTF((tmp, "%d%c", t, s));
-	if (len + 1 > *buflen)
-		return (-1);
-	strcpy(*buf, tmp);
-	*buf += len;
-	*buflen -= len;
-	return (0);
-}
diff --git a/libc/netbsd/net/base64.c b/libc/netbsd/net/base64.c
deleted file mode 100644
index 7270703..0000000
--- a/libc/netbsd/net/base64.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/*	$NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $	*/
-
-/*
- * Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM 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.
- */
-
-/*
- * Portions Copyright (c) 1995 by International Business Machines, Inc.
- *
- * International Business Machines, Inc. (hereinafter called IBM) grants
- * permission under its copyrights to use, copy, modify, and distribute this
- * Software with or without fee, provided that the above copyright notice and
- * all paragraphs of this notice appear in all copies, and that the name of IBM
- * not be used in connection with the marketing of any product incorporating
- * the Software or modifications thereof, without specific, written prior
- * permission.
- *
- * To the extent it has a right to do so, IBM grants an immunity from suit
- * under its patents, if any, for the use, sale or manufacture of products to
- * the extent that such products are used for performing Domain Name System
- * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
- * granted for any product per se or for any other function of any product.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-
-#include <assert.h>
-#include <ctype.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <stdio.h>
-
-#include <stdlib.h>
-#include <string.h>
-
-static const char Base64[] =
-	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char Pad64 = '=';
-
-/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
-   The following encoding technique is taken from RFC 1521 by Borenstein
-   and Freed.  It is reproduced here in a slightly edited form for
-   convenience.
-
-   A 65-character subset of US-ASCII is used, enabling 6 bits to be
-   represented per printable character. (The extra 65th character, "=",
-   is used to signify a special processing function.)
-
-   The encoding process represents 24-bit groups of input bits as output
-   strings of 4 encoded characters. Proceeding from left to right, a
-   24-bit input group is formed by concatenating 3 8-bit input groups.
-   These 24 bits are then treated as 4 concatenated 6-bit groups, each
-   of which is translated into a single digit in the base64 alphabet.
-
-   Each 6-bit group is used as an index into an array of 64 printable
-   characters. The character referenced by the index is placed in the
-   output string.
-
-                         Table 1: The Base64 Alphabet
-
-      Value Encoding  Value Encoding  Value Encoding  Value Encoding
-          0 A            17 R            34 i            51 z
-          1 B            18 S            35 j            52 0
-          2 C            19 T            36 k            53 1
-          3 D            20 U            37 l            54 2
-          4 E            21 V            38 m            55 3
-          5 F            22 W            39 n            56 4
-          6 G            23 X            40 o            57 5
-          7 H            24 Y            41 p            58 6
-          8 I            25 Z            42 q            59 7
-          9 J            26 a            43 r            60 8
-         10 K            27 b            44 s            61 9
-         11 L            28 c            45 t            62 +
-         12 M            29 d            46 u            63 /
-         13 N            30 e            47 v
-         14 O            31 f            48 w         (pad) =
-         15 P            32 g            49 x
-         16 Q            33 h            50 y
-
-   Special processing is performed if fewer than 24 bits are available
-   at the end of the data being encoded.  A full encoding quantum is
-   always completed at the end of a quantity.  When fewer than 24 input
-   bits are available in an input group, zero bits are added (on the
-   right) to form an integral number of 6-bit groups.  Padding at the
-   end of the data is performed using the '=' character.
-
-   Since all base64 input is an integral number of octets, only the
-         -------------------------------------------------
-   following cases can arise:
-
-       (1) the final quantum of encoding input is an integral
-           multiple of 24 bits; here, the final unit of encoded
-	   output will be an integral multiple of 4 characters
-	   with no "=" padding,
-       (2) the final quantum of encoding input is exactly 8 bits;
-           here, the final unit of encoded output will be two
-	   characters followed by two "=" padding characters, or
-       (3) the final quantum of encoding input is exactly 16 bits;
-           here, the final unit of encoded output will be three
-	   characters followed by one "=" padding character.
-   */
-
-int
-b64_ntop(src, srclength, target, targsize)
-	u_char const *src;
-	size_t srclength;
-	char *target;
-	size_t targsize;
-{
-	size_t datalength = 0;
-	u_char input[3] = { 0, 0, 0 };  /* make compiler happy */
-	u_char output[4];
-	size_t i;
-
-	assert(src != NULL);
-	assert(target != NULL);
-
-	while (2 < srclength) {
-		input[0] = *src++;
-		input[1] = *src++;
-		input[2] = *src++;
-		srclength -= 3;
-
-		output[0] = (u_int32_t)input[0] >> 2;
-		output[1] = ((u_int32_t)(input[0] & 0x03) << 4) +
-		    ((u_int32_t)input[1] >> 4);
-		output[2] = ((u_int32_t)(input[1] & 0x0f) << 2) +
-		    ((u_int32_t)input[2] >> 6);
-		output[3] = input[2] & 0x3f;
-		assert(output[0] < 64);
-		assert(output[1] < 64);
-		assert(output[2] < 64);
-		assert(output[3] < 64);
-
-		if (datalength + 4 > targsize)
-			return (-1);
-		target[datalength++] = Base64[output[0]];
-		target[datalength++] = Base64[output[1]];
-		target[datalength++] = Base64[output[2]];
-		target[datalength++] = Base64[output[3]];
-	}
-
-	/* Now we worry about padding. */
-	if (0 != srclength) {
-		/* Get what's left. */
-		input[0] = input[1] = input[2] = '\0';
-		for (i = 0; i < srclength; i++)
-			input[i] = *src++;
-
-		output[0] = (u_int32_t)input[0] >> 2;
-		output[1] = ((u_int32_t)(input[0] & 0x03) << 4) +
-		    ((u_int32_t)input[1] >> 4);
-		output[2] = ((u_int32_t)(input[1] & 0x0f) << 2) +
-		    ((u_int32_t)input[2] >> 6);
-		assert(output[0] < 64);
-		assert(output[1] < 64);
-		assert(output[2] < 64);
-
-		if (datalength + 4 > targsize)
-			return (-1);
-		target[datalength++] = Base64[output[0]];
-		target[datalength++] = Base64[output[1]];
-		if (srclength == 1)
-			target[datalength++] = Pad64;
-		else
-			target[datalength++] = Base64[output[2]];
-		target[datalength++] = Pad64;
-	}
-	if (datalength >= targsize)
-		return (-1);
-	target[datalength] = '\0';	/* Returned value doesn't count \0. */
-	return (datalength);
-}
-
-/* skips all whitespace anywhere.
-   converts characters, four at a time, starting at (or after)
-   src from base - 64 numbers into three 8 bit bytes in the target area.
-   it returns the number of data bytes stored at the target, or -1 on error.
- */
-
-int
-b64_pton(src, target, targsize)
-	char const *src;
-	u_char *target;
-	size_t targsize;
-{
-	size_t tarindex;
-	int state, ch;
-	char *pos;
-
-	assert(src != NULL);
-	assert(target != NULL);
-
-	state = 0;
-	tarindex = 0;
-
-	while ((ch = (u_char) *src++) != '\0') {
-		if (isspace(ch))	/* Skip whitespace anywhere. */
-			continue;
-
-		if (ch == Pad64)
-			break;
-
-		pos = strchr(Base64, ch);
-		if (pos == 0) 		/* A non-base64 character. */
-			return (-1);
-
-		switch (state) {
-		case 0:
-			if (target) {
-				if (tarindex >= targsize)
-					return (-1);
-				target[tarindex] = (pos - Base64) << 2;
-			}
-			state = 1;
-			break;
-		case 1:
-			if (target) {
-				if (tarindex + 1 >= targsize)
-					return (-1);
-				target[tarindex] |=
-				    (u_int32_t)(pos - Base64) >> 4;
-				target[tarindex+1]  = ((pos - Base64) & 0x0f)
-							<< 4 ;
-			}
-			tarindex++;
-			state = 2;
-			break;
-		case 2:
-			if (target) {
-				if (tarindex + 1 >= targsize)
-					return (-1);
-				target[tarindex] |=
-					(u_int32_t)(pos - Base64) >> 2;
-				target[tarindex+1] = ((pos - Base64) & 0x03)
-							<< 6;
-			}
-			tarindex++;
-			state = 3;
-			break;
-		case 3:
-			if (target) {
-				if (tarindex >= targsize)
-					return (-1);
-				target[tarindex] |= (pos - Base64);
-			}
-			tarindex++;
-			state = 0;
-			break;
-		default:
-			abort();
-		}
-	}
-
-	/*
-	 * We are done decoding Base-64 chars.  Let's see if we ended
-	 * on a byte boundary, and/or with erroneous trailing characters.
-	 */
-
-	if (ch == Pad64) {		/* We got a pad char. */
-		ch = *src++;		/* Skip it, get next. */
-		switch (state) {
-		case 0:		/* Invalid = in first position */
-		case 1:		/* Invalid = in second position */
-			return (-1);
-
-		case 2:		/* Valid, means one byte of info */
-			/* Skip any number of spaces. */
-			for (; ch != '\0'; ch = (u_char) *src++)
-				if (!isspace(ch))
-					break;
-			/* Make sure there is another trailing = sign. */
-			if (ch != Pad64)
-				return (-1);
-			ch = *src++;		/* Skip the = */
-			/* Fall through to "single trailing =" case. */
-			/* FALLTHROUGH */
-
-		case 3:		/* Valid, means two bytes of info */
-			/*
-			 * We know this char is an =.  Is there anything but
-			 * whitespace after it?
-			 */
-			for (; ch != '\0'; ch = (u_char) *src++)
-				if (!isspace(ch))
-					return (-1);
-
-			/*
-			 * Now make sure for cases 2 and 3 that the "extra"
-			 * bits that slopped past the last full byte were
-			 * zeros.  If we don't check them, they become a
-			 * subliminal channel.
-			 */
-			if (target && target[tarindex] != 0)
-				return (-1);
-		}
-	} else {
-		/*
-		 * We ended by seeing the end of the string.  Make sure we
-		 * have no partial bytes lying around.
-		 */
-		if (state != 0)
-			return (-1);
-	}
-
-	return (tarindex);
-}
diff --git a/libc/netbsd/net/getaddrinfo.c b/libc/netbsd/net/getaddrinfo.c
deleted file mode 100644
index 937c423..0000000
--- a/libc/netbsd/net/getaddrinfo.c
+++ /dev/null
@@ -1,2451 +0,0 @@
-/*	$NetBSD: getaddrinfo.c,v 1.82 2006/03/25 12:09:40 rpaulo Exp $	*/
-/*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
-
-/*
- * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Issues to be discussed:
- * - Thread safe-ness must be checked.
- * - Return values.  There are nonstandard return values defined and used
- *   in the source code.  This is because RFC2553 is silent about which error
- *   code must be returned for which situation.
- * - IPv4 classful (shortened) form.  RFC2553 is silent about it.  XNET 5.2
- *   says to use inet_aton() to convert IPv4 numeric to binary (alows
- *   classful form as a result).
- *   current code - disallow classful form for IPv4 (due to use of inet_pton).
- * - freeaddrinfo(NULL).  RFC2553 is silent about it.  XNET 5.2 says it is
- *   invalid.
- *   current code - SEGV on freeaddrinfo(NULL)
- * Note:
- * - We use getipnodebyname() just for thread-safeness.  There's no intent
- *   to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to
- *   getipnodebyname().
- * - The code filters out AFs that are not supported by the kernel,
- *   when globbing NULL hostname (to loopback, or wildcard).  Is it the right
- *   thing to do?  What is the relationship with post-RFC2553 AI_ADDRCONFIG
- *   in ai_flags?
- * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague.
- *   (1) what should we do against numeric hostname (2) what should we do
- *   against NULL hostname (3) what is AI_ADDRCONFIG itself.  AF not ready?
- *   non-loopback address configured?  global address configured?
- * - To avoid search order issue, we have a big amount of code duplicate
- *   from gethnamaddr.c and some other places.  The issues that there's no
- *   lower layer function to lookup "IPv4 or IPv6" record.  Calling
- *   gethostbyname2 from getaddrinfo will end up in wrong search order, as
- *   follows:
- *	- The code makes use of following calls when asked to resolver with
- *	  ai_family  = PF_UNSPEC:
- *		getipnodebyname(host, AF_INET6);
- *		getipnodebyname(host, AF_INET);
- *	  This will result in the following queries if the node is configure to
- *	  prefer /etc/hosts than DNS:
- *		lookup /etc/hosts for IPv6 address
- *		lookup DNS for IPv6 address
- *		lookup /etc/hosts for IPv4 address
- *		lookup DNS for IPv4 address
- *	  which may not meet people's requirement.
- *	  The right thing to happen is to have underlying layer which does
- *	  PF_UNSPEC lookup (lookup both) and return chain of addrinfos.
- *	  This would result in a bit of code duplicate with _dns_ghbyname() and
- *	  friends.
- */
-
-#include <fcntl.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
-#include "resolv_private.h"
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-
-#include <syslog.h>
-#include <stdarg.h>
-#include "nsswitch.h"
-
-#ifdef ANDROID_CHANGES
-#include <sys/system_properties.h>
-#endif /* ANDROID_CHANGES */
-
-typedef union sockaddr_union {
-    struct sockaddr     generic;
-    struct sockaddr_in  in;
-    struct sockaddr_in6 in6;
-} sockaddr_union;
-
-#define SUCCESS 0
-#define ANY 0
-#define YES 1
-#define NO  0
-
-static const char in_addrany[] = { 0, 0, 0, 0 };
-static const char in_loopback[] = { 127, 0, 0, 1 };
-#ifdef INET6
-static const char in6_addrany[] = {
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-static const char in6_loopback[] = {
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
-};
-#endif
-
-// This should be synchronized to ResponseCode.h
-static const int DnsProxyQueryResult = 222;
-
-static const struct afd {
-	int a_af;
-	int a_addrlen;
-	int a_socklen;
-	int a_off;
-	const char *a_addrany;
-	const char *a_loopback;
-	int a_scoped;
-} afdl [] = {
-#ifdef INET6
-	{PF_INET6, sizeof(struct in6_addr),
-	 sizeof(struct sockaddr_in6),
-	 offsetof(struct sockaddr_in6, sin6_addr),
-	 in6_addrany, in6_loopback, 1},
-#endif
-	{PF_INET, sizeof(struct in_addr),
-	 sizeof(struct sockaddr_in),
-	 offsetof(struct sockaddr_in, sin_addr),
-	 in_addrany, in_loopback, 0},
-	{0, 0, 0, 0, NULL, NULL, 0},
-};
-
-struct explore {
-	int e_af;
-	int e_socktype;
-	int e_protocol;
-	const char *e_protostr;
-	int e_wild;
-#define WILD_AF(ex)		((ex)->e_wild & 0x01)
-#define WILD_SOCKTYPE(ex)	((ex)->e_wild & 0x02)
-#define WILD_PROTOCOL(ex)	((ex)->e_wild & 0x04)
-};
-
-static const struct explore explore[] = {
-#if 0
-	{ PF_LOCAL, 0, ANY, ANY, NULL, 0x01 },
-#endif
-#ifdef INET6
-	{ PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
-	{ PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
-	{ PF_INET6, SOCK_RAW, ANY, NULL, 0x05 },
-#endif
-	{ PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
-	{ PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
-	{ PF_INET, SOCK_RAW, ANY, NULL, 0x05 },
-	{ PF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
-	{ PF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
-	{ PF_UNSPEC, SOCK_RAW, ANY, NULL, 0x05 },
-	{ -1, 0, 0, NULL, 0 },
-};
-
-#ifdef INET6
-#define PTON_MAX	16
-#else
-#define PTON_MAX	4
-#endif
-
-static const ns_src default_dns_files[] = {
-	{ NSSRC_FILES, 	NS_SUCCESS },
-	{ NSSRC_DNS, 	NS_SUCCESS },
-	{ 0, 0 }
-};
-
-#define MAXPACKET	(64*1024)
-
-typedef union {
-	HEADER hdr;
-	u_char buf[MAXPACKET];
-} querybuf;
-
-struct res_target {
-	struct res_target *next;
-	const char *name;	/* domain name */
-	int qclass, qtype;	/* class and type of query */
-	u_char *answer;		/* buffer to put answer */
-	int anslen;		/* size of answer buffer */
-	int n;			/* result length */
-};
-
-static int str2number(const char *);
-static int explore_fqdn(const struct addrinfo *, const char *,
-	const char *, struct addrinfo **, const char *iface, int mark);
-static int explore_null(const struct addrinfo *,
-	const char *, struct addrinfo **);
-static int explore_numeric(const struct addrinfo *, const char *,
-	const char *, struct addrinfo **, const char *);
-static int explore_numeric_scope(const struct addrinfo *, const char *,
-	const char *, struct addrinfo **);
-static int get_canonname(const struct addrinfo *,
-	struct addrinfo *, const char *);
-static struct addrinfo *get_ai(const struct addrinfo *,
-	const struct afd *, const char *);
-static int get_portmatch(const struct addrinfo *, const char *);
-static int get_port(const struct addrinfo *, const char *, int);
-static const struct afd *find_afd(int);
-#ifdef INET6
-static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *);
-#endif
-
-static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
-	const struct addrinfo *);
-static int _dns_getaddrinfo(void *, void *, va_list);
-static void _sethtent(FILE **);
-static void _endhtent(FILE **);
-static struct addrinfo *_gethtent(FILE **, const char *,
-    const struct addrinfo *);
-static int _files_getaddrinfo(void *, void *, va_list);
-
-static int res_queryN(const char *, struct res_target *, res_state);
-static int res_searchN(const char *, struct res_target *, res_state);
-static int res_querydomainN(const char *, const char *,
-	struct res_target *, res_state);
-
-static const char * const ai_errlist[] = {
-	"Success",
-	"Address family for hostname not supported",	/* EAI_ADDRFAMILY */
-	"Temporary failure in name resolution",		/* EAI_AGAIN      */
-	"Invalid value for ai_flags",		       	/* EAI_BADFLAGS   */
-	"Non-recoverable failure in name resolution", 	/* EAI_FAIL       */
-	"ai_family not supported",			/* EAI_FAMILY     */
-	"Memory allocation failure", 			/* EAI_MEMORY     */
-	"No address associated with hostname", 		/* EAI_NODATA     */
-	"hostname nor servname provided, or not known",	/* EAI_NONAME     */
-	"servname not supported for ai_socktype",	/* EAI_SERVICE    */
-	"ai_socktype not supported", 			/* EAI_SOCKTYPE   */
-	"System error returned in errno", 		/* EAI_SYSTEM     */
-	"Invalid value for hints",			/* EAI_BADHINTS	  */
-	"Resolved protocol is unknown",			/* EAI_PROTOCOL   */
-	"Argument buffer overflow",			/* EAI_OVERFLOW   */
-	"Unknown error", 				/* EAI_MAX        */
-};
-
-/* XXX macros that make external reference is BAD. */
-
-#define GET_AI(ai, afd, addr) 					\
-do { 								\
-	/* external reference: pai, error, and label free */ 	\
-	(ai) = get_ai(pai, (afd), (addr)); 			\
-	if ((ai) == NULL) { 					\
-		error = EAI_MEMORY; 				\
-		goto free; 					\
-	} 							\
-} while (/*CONSTCOND*/0)
-
-#define GET_PORT(ai, serv) 					\
-do { 								\
-	/* external reference: error and label free */ 		\
-	error = get_port((ai), (serv), 0); 			\
-	if (error != 0) 					\
-		goto free; 					\
-} while (/*CONSTCOND*/0)
-
-#define GET_CANONNAME(ai, str) 					\
-do { 								\
-	/* external reference: pai, error and label free */ 	\
-	error = get_canonname(pai, (ai), (str)); 		\
-	if (error != 0) 					\
-		goto free; 					\
-} while (/*CONSTCOND*/0)
-
-#define ERR(err) 						\
-do { 								\
-	/* external reference: error, and label bad */ 		\
-	error = (err); 						\
-	goto bad; 						\
-	/*NOTREACHED*/ 						\
-} while (/*CONSTCOND*/0)
-
-#define MATCH_FAMILY(x, y, w) 						\
-	((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || 	\
-	    (y) == PF_UNSPEC)))
-#define MATCH(x, y, w) 							\
-	((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY)))
-
-const char *
-gai_strerror(int ecode)
-{
-	if (ecode < 0 || ecode > EAI_MAX)
-		ecode = EAI_MAX;
-	return ai_errlist[ecode];
-}
-
-void
-freeaddrinfo(struct addrinfo *ai)
-{
-	struct addrinfo *next;
-
-	assert(ai != NULL);
-
-	do {
-		next = ai->ai_next;
-		if (ai->ai_canonname)
-			free(ai->ai_canonname);
-		/* no need to free(ai->ai_addr) */
-		free(ai);
-		ai = next;
-	} while (ai);
-}
-
-static int
-str2number(const char *p)
-{
-	char *ep;
-	unsigned long v;
-
-	assert(p != NULL);
-
-	if (*p == '\0')
-		return -1;
-	ep = NULL;
-	errno = 0;
-	v = strtoul(p, &ep, 10);
-	if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX)
-		return v;
-	else
-		return -1;
-}
-
-/*
- * Connect a UDP socket to a given unicast address. This will cause no network
- * traffic, but will fail fast if the system has no or limited reachability to
- * the destination (e.g., no IPv4 address, no IPv6 default route, ...).
- */
-static int
-_test_connect(int pf, struct sockaddr *addr, size_t addrlen) {
-	int s = socket(pf, SOCK_DGRAM, IPPROTO_UDP);
-	if (s < 0)
-		return 0;
-	int ret;
-	do {
-		ret = connect(s, addr, addrlen);
-	} while (ret < 0 && errno == EINTR);
-	int success = (ret == 0);
-	do {
-		ret = close(s);
-	} while (ret < 0 && errno == EINTR);
-	return success;
-}
-
-/*
- * The following functions determine whether IPv4 or IPv6 connectivity is
- * available in order to implement AI_ADDRCONFIG.
- *
- * Strictly speaking, AI_ADDRCONFIG should not look at whether connectivity is
- * available, but whether addresses of the specified family are "configured
- * on the local system". However, bionic doesn't currently support getifaddrs,
- * so checking for connectivity is the next best thing.
- */
-static int
-_have_ipv6() {
-	static const struct sockaddr_in6 sin6_test = {
-		.sin6_family = AF_INET6,
-		.sin6_addr.s6_addr = {  // 2000::
-			0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-		};
-        sockaddr_union addr = { .in6 = sin6_test };
-	return _test_connect(PF_INET6, &addr.generic, sizeof(addr.in6));
-}
-
-static int
-_have_ipv4() {
-	static const struct sockaddr_in sin_test = {
-		.sin_family = AF_INET,
-		.sin_addr.s_addr = __constant_htonl(0x08080808L)  // 8.8.8.8
-	};
-        sockaddr_union addr = { .in = sin_test };
-        return _test_connect(PF_INET, &addr.generic, sizeof(addr.in));
-}
-
-// Returns 0 on success, else returns on error.
-static int
-android_getaddrinfo_proxy(
-    const char *hostname, const char *servname,
-    const struct addrinfo *hints, struct addrinfo **res, const char *iface)
-{
-	int sock;
-	const int one = 1;
-	struct sockaddr_un proxy_addr;
-	FILE* proxy = NULL;
-	int success = 0;
-
-	// Clear this at start, as we use its non-NULLness later (in the
-	// error path) to decide if we have to free up any memory we
-	// allocated in the process (before failing).
-	*res = NULL;
-
-	// Bogus things we can't serialize.  Don't use the proxy.  These will fail - let them.
-	if ((hostname != NULL &&
-	     strcspn(hostname, " \n\r\t^'\"") != strlen(hostname)) ||
-	    (servname != NULL &&
-	     strcspn(servname, " \n\r\t^'\"") != strlen(servname))) {
-		return EAI_NODATA;
-	}
-
-	sock = socket(AF_UNIX, SOCK_STREAM, 0);
-	if (sock < 0) {
-		return EAI_NODATA;
-	}
-
-	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
-	memset(&proxy_addr, 0, sizeof(proxy_addr));
-	proxy_addr.sun_family = AF_UNIX;
-	strlcpy(proxy_addr.sun_path, "/dev/socket/dnsproxyd",
-		sizeof(proxy_addr.sun_path));
-	if (TEMP_FAILURE_RETRY(connect(sock,
-				       (const struct sockaddr*) &proxy_addr,
-				       sizeof(proxy_addr))) != 0) {
-		close(sock);
-		return EAI_NODATA;
-	}
-
-	// Send the request.
-	proxy = fdopen(sock, "r+");
-	if (fprintf(proxy, "getaddrinfo %s %s %d %d %d %d %s",
-		    hostname == NULL ? "^" : hostname,
-		    servname == NULL ? "^" : servname,
-		    hints == NULL ? -1 : hints->ai_flags,
-		    hints == NULL ? -1 : hints->ai_family,
-		    hints == NULL ? -1 : hints->ai_socktype,
-		    hints == NULL ? -1 : hints->ai_protocol,
-		    iface == NULL ? "^" : iface) < 0) {
-		goto exit;
-	}
-	// literal NULL byte at end, required by FrameworkListener
-	if (fputc(0, proxy) == EOF ||
-	    fflush(proxy) != 0) {
-		goto exit;
-	}
-
-	char buf[4];
-	// read result code for gethostbyaddr
-	if (fread(buf, 1, sizeof(buf), proxy) != sizeof(buf)) {
-		goto exit;
-	}
-
-	int result_code = (int)strtol(buf, NULL, 10);
-	// verify the code itself
-	if (result_code != DnsProxyQueryResult ) {
-		fread(buf, 1, sizeof(buf), proxy);
-		goto exit;
-	}
-
-	struct addrinfo* ai = NULL;
-	struct addrinfo** nextres = res;
-	while (1) {
-		uint32_t addrinfo_len;
-		if (fread(&addrinfo_len, sizeof(addrinfo_len),
-			  1, proxy) != 1) {
-			break;
-		}
-		addrinfo_len = ntohl(addrinfo_len);
-		if (addrinfo_len == 0) {
-			success = 1;
-			break;
-		}
-
-		if (addrinfo_len < sizeof(struct addrinfo)) {
-			break;
-		}
-		struct addrinfo* ai = calloc(1, addrinfo_len +
-					     sizeof(struct sockaddr_storage));
-		if (ai == NULL) {
-			break;
-		}
-
-		if (fread(ai, addrinfo_len, 1, proxy) != 1) {
-			// Error; fall through.
-			break;
-		}
-
-		// Zero out the pointer fields we copied which aren't
-		// valid in this address space.
-		ai->ai_addr = NULL;
-		ai->ai_canonname = NULL;
-		ai->ai_next = NULL;
-
-		// struct sockaddr
-		uint32_t addr_len;
-		if (fread(&addr_len, sizeof(addr_len), 1, proxy) != 1) {
-			break;
-		}
-		addr_len = ntohl(addr_len);
-		if (addr_len != 0) {
-			if (addr_len > sizeof(struct sockaddr_storage)) {
-				// Bogus; too big.
-				break;
-			}
-			struct sockaddr* addr = (struct sockaddr*)(ai + 1);
-			if (fread(addr, addr_len, 1, proxy) != 1) {
-				break;
-			}
-			ai->ai_addr = addr;
-		}
-
-		// cannonname
-		uint32_t name_len;
-		if (fread(&name_len, sizeof(name_len), 1, proxy) != 1) {
-			break;
-		}
-		name_len = ntohl(name_len);
-		if (name_len != 0) {
-			ai->ai_canonname = (char*) malloc(name_len);
-			if (fread(ai->ai_canonname, name_len, 1, proxy) != 1) {
-				break;
-			}
-			if (ai->ai_canonname[name_len - 1] != '\0') {
-				// The proxy should be returning this
-				// NULL-terminated.
-				break;
-			}
-		}
-
-		*nextres = ai;
-		nextres = &ai->ai_next;
-		ai = NULL;
-	}
-
-	if (ai != NULL) {
-		// Clean up partially-built addrinfo that we never ended up
-		// attaching to the response.
-		freeaddrinfo(ai);
-	}
-exit:
-	if (proxy != NULL) {
-		fclose(proxy);
-	}
-
-	if (success) {
-		return 0;
-	}
-
-	// Proxy failed;
-	// clean up memory we might've allocated.
-	if (*res) {
-		freeaddrinfo(*res);
-		*res = NULL;
-	}
-	return EAI_NODATA;
-}
-
-int
-getaddrinfo(const char *hostname, const char *servname,
-    const struct addrinfo *hints, struct addrinfo **res)
-{
-	return android_getaddrinfoforiface(hostname, servname, hints, NULL, 0, res);
-}
-
-int
-android_getaddrinfoforiface(const char *hostname, const char *servname,
-    const struct addrinfo *hints, const char *iface, int mark, struct addrinfo **res)
-{
-	struct addrinfo sentinel;
-	struct addrinfo *cur;
-	int error = 0;
-	struct addrinfo ai;
-	struct addrinfo ai0;
-	struct addrinfo *pai;
-	const struct explore *ex;
-	const char* cache_mode = getenv("ANDROID_DNS_MODE");
-
-	/* hostname is allowed to be NULL */
-	/* servname is allowed to be NULL */
-	/* hints is allowed to be NULL */
-	assert(res != NULL);
-	memset(&sentinel, 0, sizeof(sentinel));
-	cur = &sentinel;
-	pai = &ai;
-	pai->ai_flags = 0;
-	pai->ai_family = PF_UNSPEC;
-	pai->ai_socktype = ANY;
-	pai->ai_protocol = ANY;
-	pai->ai_addrlen = 0;
-	pai->ai_canonname = NULL;
-	pai->ai_addr = NULL;
-	pai->ai_next = NULL;
-
-	if (hostname == NULL && servname == NULL)
-		return EAI_NONAME;
-	if (hints) {
-		/* error check for hints */
-		if (hints->ai_addrlen || hints->ai_canonname ||
-		    hints->ai_addr || hints->ai_next)
-			ERR(EAI_BADHINTS); /* xxx */
-		if (hints->ai_flags & ~AI_MASK)
-			ERR(EAI_BADFLAGS);
-		switch (hints->ai_family) {
-		case PF_UNSPEC:
-		case PF_INET:
-#ifdef INET6
-		case PF_INET6:
-#endif
-			break;
-		default:
-			ERR(EAI_FAMILY);
-		}
-		memcpy(pai, hints, sizeof(*pai));
-
-		/*
-		 * if both socktype/protocol are specified, check if they
-		 * are meaningful combination.
-		 */
-		if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) {
-			for (ex = explore; ex->e_af >= 0; ex++) {
-				if (pai->ai_family != ex->e_af)
-					continue;
-				if (ex->e_socktype == ANY)
-					continue;
-				if (ex->e_protocol == ANY)
-					continue;
-				if (pai->ai_socktype == ex->e_socktype
-				 && pai->ai_protocol != ex->e_protocol) {
-					ERR(EAI_BADHINTS);
-				}
-			}
-		}
-	}
-
-	/*
-	 * check for special cases.  (1) numeric servname is disallowed if
-	 * socktype/protocol are left unspecified. (2) servname is disallowed
-	 * for raw and other inet{,6} sockets.
-	 */
-	if (MATCH_FAMILY(pai->ai_family, PF_INET, 1)
-#ifdef PF_INET6
-	 || MATCH_FAMILY(pai->ai_family, PF_INET6, 1)
-#endif
-	    ) {
-		ai0 = *pai;	/* backup *pai */
-
-		if (pai->ai_family == PF_UNSPEC) {
-#ifdef PF_INET6
-			pai->ai_family = PF_INET6;
-#else
-			pai->ai_family = PF_INET;
-#endif
-		}
-		error = get_portmatch(pai, servname);
-		if (error)
-			ERR(error);
-
-		*pai = ai0;
-	}
-
-	ai0 = *pai;
-
-	/* NULL hostname, or numeric hostname */
-	for (ex = explore; ex->e_af >= 0; ex++) {
-		*pai = ai0;
-
-		/* PF_UNSPEC entries are prepared for DNS queries only */
-		if (ex->e_af == PF_UNSPEC)
-			continue;
-
-		if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex)))
-			continue;
-		if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex)))
-			continue;
-		if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex)))
-			continue;
-
-		if (pai->ai_family == PF_UNSPEC)
-			pai->ai_family = ex->e_af;
-		if (pai->ai_socktype == ANY && ex->e_socktype != ANY)
-			pai->ai_socktype = ex->e_socktype;
-		if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
-			pai->ai_protocol = ex->e_protocol;
-
-		if (hostname == NULL)
-			error = explore_null(pai, servname, &cur->ai_next);
-		else
-			error = explore_numeric_scope(pai, hostname, servname,
-			    &cur->ai_next);
-
-		if (error)
-			goto free;
-
-		while (cur->ai_next)
-			cur = cur->ai_next;
-	}
-
-	/*
-	 * XXX
-	 * If numeric representation of AF1 can be interpreted as FQDN
-	 * representation of AF2, we need to think again about the code below.
-	 */
-	if (sentinel.ai_next)
-		goto good;
-
-	if (hostname == NULL)
-		ERR(EAI_NODATA);
-	if (pai->ai_flags & AI_NUMERICHOST)
-		ERR(EAI_NONAME);
-
-        /*
-         * BEGIN ANDROID CHANGES; proxying to the cache
-         */
-	if (cache_mode == NULL || strcmp(cache_mode, "local") != 0) {
-		// we're not the proxy - pass the request to them
-		return android_getaddrinfo_proxy(hostname, servname, hints, res, iface);
-	}
-
-	/*
-	 * hostname as alphabetical name.
-	 * we would like to prefer AF_INET6 than AF_INET, so we'll make a
-	 * outer loop by AFs.
-	 */
-	for (ex = explore; ex->e_af >= 0; ex++) {
-		*pai = ai0;
-
-		/* require exact match for family field */
-		if (pai->ai_family != ex->e_af)
-			continue;
-
-		if (!MATCH(pai->ai_socktype, ex->e_socktype,
-				WILD_SOCKTYPE(ex))) {
-			continue;
-		}
-		if (!MATCH(pai->ai_protocol, ex->e_protocol,
-				WILD_PROTOCOL(ex))) {
-			continue;
-		}
-
-		if (pai->ai_socktype == ANY && ex->e_socktype != ANY)
-			pai->ai_socktype = ex->e_socktype;
-		if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
-			pai->ai_protocol = ex->e_protocol;
-
-		error = explore_fqdn(pai, hostname, servname,
-			&cur->ai_next, iface, mark);
-
-		while (cur && cur->ai_next)
-			cur = cur->ai_next;
-	}
-
-	/* XXX */
-	if (sentinel.ai_next)
-		error = 0;
-
-	if (error)
-		goto free;
-	if (error == 0) {
-		if (sentinel.ai_next) {
- good:
-			*res = sentinel.ai_next;
-			return SUCCESS;
-		} else
-			error = EAI_FAIL;
-	}
- free:
- bad:
-	if (sentinel.ai_next)
-		freeaddrinfo(sentinel.ai_next);
-	*res = NULL;
-	return error;
-}
-
-/*
- * FQDN hostname, DNS lookup
- */
-static int
-explore_fqdn(const struct addrinfo *pai, const char *hostname,
-    const char *servname, struct addrinfo **res, const char *iface, int mark)
-{
-	struct addrinfo *result;
-	struct addrinfo *cur;
-	int error = 0;
-	static const ns_dtab dtab[] = {
-		NS_FILES_CB(_files_getaddrinfo, NULL)
-		{ NSSRC_DNS, _dns_getaddrinfo, NULL },	/* force -DHESIOD */
-		NS_NIS_CB(_yp_getaddrinfo, NULL)
-		{ 0, 0, 0 }
-	};
-
-	assert(pai != NULL);
-	/* hostname may be NULL */
-	/* servname may be NULL */
-	assert(res != NULL);
-
-	result = NULL;
-
-	/*
-	 * if the servname does not match socktype/protocol, ignore it.
-	 */
-	if (get_portmatch(pai, servname) != 0)
-		return 0;
-
-	switch (nsdispatch(&result, dtab, NSDB_HOSTS, "getaddrinfo",
-			default_dns_files, hostname, pai, iface, mark)) {
-	case NS_TRYAGAIN:
-		error = EAI_AGAIN;
-		goto free;
-	case NS_UNAVAIL:
-		error = EAI_FAIL;
-		goto free;
-	case NS_NOTFOUND:
-		error = EAI_NODATA;
-		goto free;
-	case NS_SUCCESS:
-		error = 0;
-		for (cur = result; cur; cur = cur->ai_next) {
-			GET_PORT(cur, servname);
-			/* canonname should be filled already */
-		}
-		break;
-	}
-
-	*res = result;
-
-	return 0;
-
-free:
-	if (result)
-		freeaddrinfo(result);
-	return error;
-}
-
-/*
- * hostname == NULL.
- * passive socket -> anyaddr (0.0.0.0 or ::)
- * non-passive socket -> localhost (127.0.0.1 or ::1)
- */
-static int
-explore_null(const struct addrinfo *pai, const char *servname,
-    struct addrinfo **res)
-{
-	int s;
-	const struct afd *afd;
-	struct addrinfo *cur;
-	struct addrinfo sentinel;
-	int error;
-
-	assert(pai != NULL);
-	/* servname may be NULL */
-	assert(res != NULL);
-
-	*res = NULL;
-	sentinel.ai_next = NULL;
-	cur = &sentinel;
-
-	/*
-	 * filter out AFs that are not supported by the kernel
-	 * XXX errno?
-	 */
-	s = socket(pai->ai_family, SOCK_DGRAM, 0);
-	if (s < 0) {
-		if (errno != EMFILE)
-			return 0;
-	} else
-		close(s);
-
-	/*
-	 * if the servname does not match socktype/protocol, ignore it.
-	 */
-	if (get_portmatch(pai, servname) != 0)
-		return 0;
-
-	afd = find_afd(pai->ai_family);
-	if (afd == NULL)
-		return 0;
-
-	if (pai->ai_flags & AI_PASSIVE) {
-		GET_AI(cur->ai_next, afd, afd->a_addrany);
-		/* xxx meaningless?
-		 * GET_CANONNAME(cur->ai_next, "anyaddr");
-		 */
-		GET_PORT(cur->ai_next, servname);
-	} else {
-		GET_AI(cur->ai_next, afd, afd->a_loopback);
-		/* xxx meaningless?
-		 * GET_CANONNAME(cur->ai_next, "localhost");
-		 */
-		GET_PORT(cur->ai_next, servname);
-	}
-	cur = cur->ai_next;
-
-	*res = sentinel.ai_next;
-	return 0;
-
-free:
-	if (sentinel.ai_next)
-		freeaddrinfo(sentinel.ai_next);
-	return error;
-}
-
-/*
- * numeric hostname
- */
-static int
-explore_numeric(const struct addrinfo *pai, const char *hostname,
-    const char *servname, struct addrinfo **res, const char *canonname)
-{
-	const struct afd *afd;
-	struct addrinfo *cur;
-	struct addrinfo sentinel;
-	int error;
-	char pton[PTON_MAX];
-
-	assert(pai != NULL);
-	/* hostname may be NULL */
-	/* servname may be NULL */
-	assert(res != NULL);
-
-	*res = NULL;
-	sentinel.ai_next = NULL;
-	cur = &sentinel;
-
-	/*
-	 * if the servname does not match socktype/protocol, ignore it.
-	 */
-	if (get_portmatch(pai, servname) != 0)
-		return 0;
-
-	afd = find_afd(pai->ai_family);
-	if (afd == NULL)
-		return 0;
-
-	switch (afd->a_af) {
-#if 0 /*X/Open spec*/
-	case AF_INET:
-		if (inet_aton(hostname, (struct in_addr *)pton) == 1) {
-			if (pai->ai_family == afd->a_af ||
-			    pai->ai_family == PF_UNSPEC /*?*/) {
-				GET_AI(cur->ai_next, afd, pton);
-				GET_PORT(cur->ai_next, servname);
-				if ((pai->ai_flags & AI_CANONNAME)) {
-					/*
-					 * Set the numeric address itself as
-					 * the canonical name, based on a
-					 * clarification in rfc2553bis-03.
-					 */
-					GET_CANONNAME(cur->ai_next, canonname);
-				}
-				while (cur && cur->ai_next)
-					cur = cur->ai_next;
-			} else
-				ERR(EAI_FAMILY);	/*xxx*/
-		}
-		break;
-#endif
-	default:
-		if (inet_pton(afd->a_af, hostname, pton) == 1) {
-			if (pai->ai_family == afd->a_af ||
-			    pai->ai_family == PF_UNSPEC /*?*/) {
-				GET_AI(cur->ai_next, afd, pton);
-				GET_PORT(cur->ai_next, servname);
-				if ((pai->ai_flags & AI_CANONNAME)) {
-					/*
-					 * Set the numeric address itself as
-					 * the canonical name, based on a
-					 * clarification in rfc2553bis-03.
-					 */
-					GET_CANONNAME(cur->ai_next, canonname);
-				}
-				while (cur->ai_next)
-					cur = cur->ai_next;
-			} else
-				ERR(EAI_FAMILY);	/*xxx*/
-		}
-		break;
-	}
-
-	*res = sentinel.ai_next;
-	return 0;
-
-free:
-bad:
-	if (sentinel.ai_next)
-		freeaddrinfo(sentinel.ai_next);
-	return error;
-}
-
-/*
- * numeric hostname with scope
- */
-static int
-explore_numeric_scope(const struct addrinfo *pai, const char *hostname,
-    const char *servname, struct addrinfo **res)
-{
-#if !defined(SCOPE_DELIMITER) || !defined(INET6)
-	return explore_numeric(pai, hostname, servname, res, hostname);
-#else
-	const struct afd *afd;
-	struct addrinfo *cur;
-	int error;
-	char *cp, *hostname2 = NULL, *scope, *addr;
-	struct sockaddr_in6 *sin6;
-
-	assert(pai != NULL);
-	/* hostname may be NULL */
-	/* servname may be NULL */
-	assert(res != NULL);
-
-	/*
-	 * if the servname does not match socktype/protocol, ignore it.
-	 */
-	if (get_portmatch(pai, servname) != 0)
-		return 0;
-
-	afd = find_afd(pai->ai_family);
-	if (afd == NULL)
-		return 0;
-
-	if (!afd->a_scoped)
-		return explore_numeric(pai, hostname, servname, res, hostname);
-
-	cp = strchr(hostname, SCOPE_DELIMITER);
-	if (cp == NULL)
-		return explore_numeric(pai, hostname, servname, res, hostname);
-
-	/*
-	 * Handle special case of <scoped_address><delimiter><scope id>
-	 */
-	hostname2 = strdup(hostname);
-	if (hostname2 == NULL)
-		return EAI_MEMORY;
-	/* terminate at the delimiter */
-	hostname2[cp - hostname] = '\0';
-	addr = hostname2;
-	scope = cp + 1;
-
-	error = explore_numeric(pai, addr, servname, res, hostname);
-	if (error == 0) {
-		u_int32_t scopeid;
-
-		for (cur = *res; cur; cur = cur->ai_next) {
-			if (cur->ai_family != AF_INET6)
-				continue;
-			sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr;
-			if (ip6_str2scopeid(scope, sin6, &scopeid) == -1) {
-				free(hostname2);
-				return(EAI_NODATA); /* XXX: is return OK? */
-			}
-			sin6->sin6_scope_id = scopeid;
-		}
-	}
-
-	free(hostname2);
-
-	return error;
-#endif
-}
-
-static int
-get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str)
-{
-
-	assert(pai != NULL);
-	assert(ai != NULL);
-	assert(str != NULL);
-
-	if ((pai->ai_flags & AI_CANONNAME) != 0) {
-		ai->ai_canonname = strdup(str);
-		if (ai->ai_canonname == NULL)
-			return EAI_MEMORY;
-	}
-	return 0;
-}
-
-static struct addrinfo *
-get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr)
-{
-	char *p;
-	struct addrinfo *ai;
-
-	assert(pai != NULL);
-	assert(afd != NULL);
-	assert(addr != NULL);
-
-	ai = (struct addrinfo *)malloc(sizeof(struct addrinfo)
-		+ (afd->a_socklen));
-	if (ai == NULL)
-		return NULL;
-
-	memcpy(ai, pai, sizeof(struct addrinfo));
-	ai->ai_addr = (struct sockaddr *)(void *)(ai + 1);
-	memset(ai->ai_addr, 0, (size_t)afd->a_socklen);
-
-#ifdef HAVE_SA_LEN
-	ai->ai_addr->sa_len = afd->a_socklen;
-#endif
-
-	ai->ai_addrlen = afd->a_socklen;
-#if defined (__alpha__) || (defined(__i386__) && defined(_LP64)) || defined(__sparc64__)
-	ai->__ai_pad0 = 0;
-#endif
-	ai->ai_addr->sa_family = ai->ai_family = afd->a_af;
-	p = (char *)(void *)(ai->ai_addr);
-	memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen);
-	return ai;
-}
-
-static int
-get_portmatch(const struct addrinfo *ai, const char *servname)
-{
-
-	assert(ai != NULL);
-	/* servname may be NULL */
-
-	return get_port(ai, servname, 1);
-}
-
-static int
-get_port(const struct addrinfo *ai, const char *servname, int matchonly)
-{
-	const char *proto;
-	struct servent *sp;
-	int port;
-	int allownumeric;
-
-	assert(ai != NULL);
-	/* servname may be NULL */
-
-	if (servname == NULL)
-		return 0;
-	switch (ai->ai_family) {
-	case AF_INET:
-#ifdef AF_INET6
-	case AF_INET6:
-#endif
-		break;
-	default:
-		return 0;
-	}
-
-	switch (ai->ai_socktype) {
-	case SOCK_RAW:
-		return EAI_SERVICE;
-	case SOCK_DGRAM:
-	case SOCK_STREAM:
-		allownumeric = 1;
-		break;
-	case ANY:
-#if 1  /* ANDROID-SPECIFIC CHANGE TO MATCH GLIBC */
-		allownumeric = 1;
-#else
-		allownumeric = 0;
-#endif
-		break;
-	default:
-		return EAI_SOCKTYPE;
-	}
-
-	port = str2number(servname);
-	if (port >= 0) {
-		if (!allownumeric)
-			return EAI_SERVICE;
-		if (port < 0 || port > 65535)
-			return EAI_SERVICE;
-		port = htons(port);
-	} else {
-		if (ai->ai_flags & AI_NUMERICSERV)
-			return EAI_NONAME;
-
-		switch (ai->ai_socktype) {
-		case SOCK_DGRAM:
-			proto = "udp";
-			break;
-		case SOCK_STREAM:
-			proto = "tcp";
-			break;
-		default:
-			proto = NULL;
-			break;
-		}
-
-		if ((sp = getservbyname(servname, proto)) == NULL)
-			return EAI_SERVICE;
-		port = sp->s_port;
-	}
-
-	if (!matchonly) {
-		switch (ai->ai_family) {
-		case AF_INET:
-			((struct sockaddr_in *)(void *)
-			    ai->ai_addr)->sin_port = port;
-			break;
-#ifdef INET6
-		case AF_INET6:
-			((struct sockaddr_in6 *)(void *)
-			    ai->ai_addr)->sin6_port = port;
-			break;
-#endif
-		}
-	}
-
-	return 0;
-}
-
-static const struct afd *
-find_afd(int af)
-{
-	const struct afd *afd;
-
-	if (af == PF_UNSPEC)
-		return NULL;
-	for (afd = afdl; afd->a_af; afd++) {
-		if (afd->a_af == af)
-			return afd;
-	}
-	return NULL;
-}
-
-#ifdef INET6
-/* convert a string to a scope identifier. XXX: IPv6 specific */
-static int
-ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, u_int32_t *scopeid)
-{
-	u_long lscopeid;
-	struct in6_addr *a6;
-	char *ep;
-
-	assert(scope != NULL);
-	assert(sin6 != NULL);
-	assert(scopeid != NULL);
-
-	a6 = &sin6->sin6_addr;
-
-	/* empty scopeid portion is invalid */
-	if (*scope == '\0')
-		return -1;
-
-	if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) {
-		/*
-		 * We currently assume a one-to-one mapping between links
-		 * and interfaces, so we simply use interface indices for
-		 * like-local scopes.
-		 */
-		*scopeid = if_nametoindex(scope);
-		if (*scopeid == 0)
-			goto trynumeric;
-		return 0;
-	}
-
-	/* still unclear about literal, allow numeric only - placeholder */
-	if (IN6_IS_ADDR_SITELOCAL(a6) || IN6_IS_ADDR_MC_SITELOCAL(a6))
-		goto trynumeric;
-	if (IN6_IS_ADDR_MC_ORGLOCAL(a6))
-		goto trynumeric;
-	else
-		goto trynumeric;	/* global */
-
-	/* try to convert to a numeric id as a last resort */
-  trynumeric:
-	errno = 0;
-	lscopeid = strtoul(scope, &ep, 10);
-	*scopeid = (u_int32_t)(lscopeid & 0xffffffffUL);
-	if (errno == 0 && ep && *ep == '\0' && *scopeid == lscopeid)
-		return 0;
-	else
-		return -1;
-}
-#endif
-
-/* code duplicate with gethnamaddr.c */
-
-static const char AskedForGot[] =
-	"gethostby*.getanswer: asked for \"%s\", got \"%s\"";
-
-static struct addrinfo *
-getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
-    const struct addrinfo *pai)
-{
-	struct addrinfo sentinel, *cur;
-	struct addrinfo ai;
-	const struct afd *afd;
-	char *canonname;
-	const HEADER *hp;
-	const u_char *cp;
-	int n;
-	const u_char *eom;
-	char *bp, *ep;
-	int type, class, ancount, qdcount;
-	int haveanswer, had_error;
-	char tbuf[MAXDNAME];
-	int (*name_ok) (const char *);
-	char hostbuf[8*1024];
-
-	assert(answer != NULL);
-	assert(qname != NULL);
-	assert(pai != NULL);
-
-	memset(&sentinel, 0, sizeof(sentinel));
-	cur = &sentinel;
-
-	canonname = NULL;
-	eom = answer->buf + anslen;
-	switch (qtype) {
-	case T_A:
-	case T_AAAA:
-	case T_ANY:	/*use T_ANY only for T_A/T_AAAA lookup*/
-		name_ok = res_hnok;
-		break;
-	default:
-		return NULL;	/* XXX should be abort(); */
-	}
-	/*
-	 * find first satisfactory answer
-	 */
-	hp = &answer->hdr;
-	ancount = ntohs(hp->ancount);
-	qdcount = ntohs(hp->qdcount);
-	bp = hostbuf;
-	ep = hostbuf + sizeof hostbuf;
-	cp = answer->buf + HFIXEDSZ;
-	if (qdcount != 1) {
-		h_errno = NO_RECOVERY;
-		return (NULL);
-	}
-	n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-	if ((n < 0) || !(*name_ok)(bp)) {
-		h_errno = NO_RECOVERY;
-		return (NULL);
-	}
-	cp += n + QFIXEDSZ;
-	if (qtype == T_A || qtype == T_AAAA || qtype == T_ANY) {
-		/* res_send() has already verified that the query name is the
-		 * same as the one we sent; this just gets the expanded name
-		 * (i.e., with the succeeding search-domain tacked on).
-		 */
-		n = strlen(bp) + 1;		/* for the \0 */
-		if (n >= MAXHOSTNAMELEN) {
-			h_errno = NO_RECOVERY;
-			return (NULL);
-		}
-		canonname = bp;
-		bp += n;
-		/* The qname can be abbreviated, but h_name is now absolute. */
-		qname = canonname;
-	}
-	haveanswer = 0;
-	had_error = 0;
-	while (ancount-- > 0 && cp < eom && !had_error) {
-		n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-		if ((n < 0) || !(*name_ok)(bp)) {
-			had_error++;
-			continue;
-		}
-		cp += n;			/* name */
-		type = _getshort(cp);
- 		cp += INT16SZ;			/* type */
-		class = _getshort(cp);
- 		cp += INT16SZ + INT32SZ;	/* class, TTL */
-		n = _getshort(cp);
-		cp += INT16SZ;			/* len */
-		if (class != C_IN) {
-			/* XXX - debug? syslog? */
-			cp += n;
-			continue;		/* XXX - had_error++ ? */
-		}
-		if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) &&
-		    type == T_CNAME) {
-			n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
-			if ((n < 0) || !(*name_ok)(tbuf)) {
-				had_error++;
-				continue;
-			}
-			cp += n;
-			/* Get canonical name. */
-			n = strlen(tbuf) + 1;	/* for the \0 */
-			if (n > ep - bp || n >= MAXHOSTNAMELEN) {
-				had_error++;
-				continue;
-			}
-			strlcpy(bp, tbuf, (size_t)(ep - bp));
-			canonname = bp;
-			bp += n;
-			continue;
-		}
-		if (qtype == T_ANY) {
-			if (!(type == T_A || type == T_AAAA)) {
-				cp += n;
-				continue;
-			}
-		} else if (type != qtype) {
-			if (type != T_KEY && type != T_SIG)
-				syslog(LOG_NOTICE|LOG_AUTH,
-	       "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
-				       qname, p_class(C_IN), p_type(qtype),
-				       p_type(type));
-			cp += n;
-			continue;		/* XXX - had_error++ ? */
-		}
-		switch (type) {
-		case T_A:
-		case T_AAAA:
-			if (strcasecmp(canonname, bp) != 0) {
-				syslog(LOG_NOTICE|LOG_AUTH,
-				       AskedForGot, canonname, bp);
-				cp += n;
-				continue;	/* XXX - had_error++ ? */
-			}
-			if (type == T_A && n != INADDRSZ) {
-				cp += n;
-				continue;
-			}
-			if (type == T_AAAA && n != IN6ADDRSZ) {
-				cp += n;
-				continue;
-			}
-			if (type == T_AAAA) {
-				struct in6_addr in6;
-				memcpy(&in6, cp, IN6ADDRSZ);
-				if (IN6_IS_ADDR_V4MAPPED(&in6)) {
-					cp += n;
-					continue;
-				}
-			}
-			if (!haveanswer) {
-				int nn;
-
-				canonname = bp;
-				nn = strlen(bp) + 1;	/* for the \0 */
-				bp += nn;
-			}
-
-			/* don't overwrite pai */
-			ai = *pai;
-			ai.ai_family = (type == T_A) ? AF_INET : AF_INET6;
-			afd = find_afd(ai.ai_family);
-			if (afd == NULL) {
-				cp += n;
-				continue;
-			}
-			cur->ai_next = get_ai(&ai, afd, (const char *)cp);
-			if (cur->ai_next == NULL)
-				had_error++;
-			while (cur && cur->ai_next)
-				cur = cur->ai_next;
-			cp += n;
-			break;
-		default:
-			abort();
-		}
-		if (!had_error)
-			haveanswer++;
-	}
-	if (haveanswer) {
-		if (!canonname)
-			(void)get_canonname(pai, sentinel.ai_next, qname);
-		else
-			(void)get_canonname(pai, sentinel.ai_next, canonname);
-		h_errno = NETDB_SUCCESS;
-		return sentinel.ai_next;
-	}
-
-	h_errno = NO_RECOVERY;
-	return NULL;
-}
-
-struct addrinfo_sort_elem {
-	struct addrinfo *ai;
-	int has_src_addr;
-	sockaddr_union src_addr;
-	int original_order;
-};
-
-/*ARGSUSED*/
-static int
-_get_scope(const struct sockaddr *addr)
-{
-	if (addr->sa_family == AF_INET6) {
-		const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
-		if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr)) {
-			return IPV6_ADDR_MC_SCOPE(&addr6->sin6_addr);
-		} else if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr) ||
-			   IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)) {
-			/*
-			 * RFC 4291 section 2.5.3 says loopback is to be treated as having
-			 * link-local scope.
-			 */
-			return IPV6_ADDR_SCOPE_LINKLOCAL;
-		} else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
-			return IPV6_ADDR_SCOPE_SITELOCAL;
-		} else {
-			return IPV6_ADDR_SCOPE_GLOBAL;
-		}
-	} else if (addr->sa_family == AF_INET) {
-		const struct sockaddr_in *addr4 = (const struct sockaddr_in *)addr;
-		unsigned long int na = ntohl(addr4->sin_addr.s_addr);
-
-		if (IN_LOOPBACK(na) ||                          /* 127.0.0.0/8 */
-		    (na & 0xffff0000) == 0xa9fe0000) {          /* 169.254.0.0/16 */
-			return IPV6_ADDR_SCOPE_LINKLOCAL;
-		} else {
-			/*
-			 * RFC 6724 section 3.2. Other IPv4 addresses, including private addresses
-			 * and shared addresses (100.64.0.0/10), are assigned global scope.
-			 */
-			return IPV6_ADDR_SCOPE_GLOBAL;
-		}
-	} else {
-		/*
-		 * This should never happen.
-		 * Return a scope with low priority as a last resort.
-		 */
-		return IPV6_ADDR_SCOPE_NODELOCAL;
-	}
-}
-
-/* These macros are modelled after the ones in <netinet/in6.h>. */
-
-/* RFC 4380, section 2.6 */
-#define IN6_IS_ADDR_TEREDO(a)	 \
-	((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == ntohl(0x20010000)))
-
-/* RFC 3056, section 2. */
-#define IN6_IS_ADDR_6TO4(a)	 \
-	(((a)->s6_addr[0] == 0x20) && ((a)->s6_addr[1] == 0x02))
-
-/* 6bone testing address area (3ffe::/16), deprecated in RFC 3701. */
-#define IN6_IS_ADDR_6BONE(a)      \
-	(((a)->s6_addr[0] == 0x3f) && ((a)->s6_addr[1] == 0xfe))
-
-/*
- * Get the label for a given IPv4/IPv6 address.
- * RFC 6724, section 2.1.
- */
-
-/*ARGSUSED*/
-static int
-_get_label(const struct sockaddr *addr)
-{
-	if (addr->sa_family == AF_INET) {
-		return 4;
-	} else if (addr->sa_family == AF_INET6) {
-		const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *) addr;
-		if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)) {
-			return 0;
-		} else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
-			return 4;
-		} else if (IN6_IS_ADDR_6TO4(&addr6->sin6_addr)) {
-			return 2;
-		} else if (IN6_IS_ADDR_TEREDO(&addr6->sin6_addr)) {
-			return 5;
-		} else if (IN6_IS_ADDR_ULA(&addr6->sin6_addr)) {
-			return 13;
-		} else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr)) {
-			return 3;
-		} else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
-			return 11;
-		} else if (IN6_IS_ADDR_6BONE(&addr6->sin6_addr)) {
-			return 12;
-		} else {
-			/* All other IPv6 addresses, including global unicast addresses. */
-			return 1;
-		}
-	} else {
-		/*
-		 * This should never happen.
-		 * Return a semi-random label as a last resort.
-		 */
-		return 1;
-	}
-}
-
-/*
- * Get the precedence for a given IPv4/IPv6 address.
- * RFC 6724, section 2.1.
- */
-
-/*ARGSUSED*/
-static int
-_get_precedence(const struct sockaddr *addr)
-{
-	if (addr->sa_family == AF_INET) {
-		return 35;
-	} else if (addr->sa_family == AF_INET6) {
-		const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
-		if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)) {
-			return 50;
-		} else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
-			return 35;
-		} else if (IN6_IS_ADDR_6TO4(&addr6->sin6_addr)) {
-			return 30;
-		} else if (IN6_IS_ADDR_TEREDO(&addr6->sin6_addr)) {
-			return 5;
-		} else if (IN6_IS_ADDR_ULA(&addr6->sin6_addr)) {
-			return 3;
-		} else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr) ||
-		           IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr) ||
-		           IN6_IS_ADDR_6BONE(&addr6->sin6_addr)) {
-			return 1;
-		} else {
-			/* All other IPv6 addresses, including global unicast addresses. */
-			return 40;
-		}
-	} else {
-		return 1;
-	}
-}
-
-/*
- * Find number of matching initial bits between the two addresses a1 and a2.
- */
-
-/*ARGSUSED*/
-static int
-_common_prefix_len(const struct in6_addr *a1, const struct in6_addr *a2)
-{
-	const char *p1 = (const char *)a1;
-	const char *p2 = (const char *)a2;
-	unsigned i;
-
-	for (i = 0; i < sizeof(*a1); ++i) {
-		int x, j;
-
-		if (p1[i] == p2[i]) {
-			continue;
-		}
-		x = p1[i] ^ p2[i];
-		for (j = 0; j < CHAR_BIT; ++j) {
-			if (x & (1 << (CHAR_BIT - 1))) {
-				return i * CHAR_BIT + j;
-			}
-			x <<= 1;
-		}
-	}
-	return sizeof(*a1) * CHAR_BIT;
-}
-
-/*
- * Compare two source/destination address pairs.
- * RFC 6724, section 6.
- */
-
-/*ARGSUSED*/
-static int
-_rfc6724_compare(const void *ptr1, const void* ptr2)
-{
-	const struct addrinfo_sort_elem *a1 = (const struct addrinfo_sort_elem *)ptr1;
-	const struct addrinfo_sort_elem *a2 = (const struct addrinfo_sort_elem *)ptr2;
-	int scope_src1, scope_dst1, scope_match1;
-	int scope_src2, scope_dst2, scope_match2;
-	int label_src1, label_dst1, label_match1;
-	int label_src2, label_dst2, label_match2;
-	int precedence1, precedence2;
-	int prefixlen1, prefixlen2;
-
-	/* Rule 1: Avoid unusable destinations. */
-	if (a1->has_src_addr != a2->has_src_addr) {
-		return a2->has_src_addr - a1->has_src_addr;
-	}
-
-	/* Rule 2: Prefer matching scope. */
-	scope_src1 = _get_scope(&a1->src_addr.generic);
-	scope_dst1 = _get_scope(a1->ai->ai_addr);
-	scope_match1 = (scope_src1 == scope_dst1);
-
-	scope_src2 = _get_scope(&a2->src_addr.generic);
-	scope_dst2 = _get_scope(a2->ai->ai_addr);
-	scope_match2 = (scope_src2 == scope_dst2);
-
-	if (scope_match1 != scope_match2) {
-		return scope_match2 - scope_match1;
-	}
-
-	/*
-	 * Rule 3: Avoid deprecated addresses.
-	 * TODO(sesse): We don't currently have a good way of finding this.
-	 */
-
-	/*
-	 * Rule 4: Prefer home addresses.
-	 * TODO(sesse): We don't currently have a good way of finding this.
-	 */
-
-	/* Rule 5: Prefer matching label. */
-	label_src1 = _get_label(&a1->src_addr.generic);
-	label_dst1 = _get_label(a1->ai->ai_addr);
-	label_match1 = (label_src1 == label_dst1);
-
-	label_src2 = _get_label(&a2->src_addr.generic);
-	label_dst2 = _get_label(a2->ai->ai_addr);
-	label_match2 = (label_src2 == label_dst2);
-
-	if (label_match1 != label_match2) {
-		return label_match2 - label_match1;
-	}
-
-	/* Rule 6: Prefer higher precedence. */
-	precedence1 = _get_precedence(a1->ai->ai_addr);
-	precedence2 = _get_precedence(a2->ai->ai_addr);
-	if (precedence1 != precedence2) {
-		return precedence2 - precedence1;
-	}
-
-	/*
-	 * Rule 7: Prefer native transport.
-	 * TODO(sesse): We don't currently have a good way of finding this.
-	 */
-
-	/* Rule 8: Prefer smaller scope. */
-	if (scope_dst1 != scope_dst2) {
-		return scope_dst1 - scope_dst2;
-	}
-
-	/*
-	 * Rule 9: Use longest matching prefix.
-         * We implement this for IPv6 only, as the rules in RFC 6724 don't seem
-         * to work very well directly applied to IPv4. (glibc uses information from
-         * the routing table for a custom IPv4 implementation here.)
-	 */
-	if (a1->has_src_addr && a1->ai->ai_addr->sa_family == AF_INET6 &&
-	    a2->has_src_addr && a2->ai->ai_addr->sa_family == AF_INET6) {
-		const struct sockaddr_in6 *a1_src = &a1->src_addr.in6;
-		const struct sockaddr_in6 *a1_dst = (const struct sockaddr_in6 *)a1->ai->ai_addr;
-		const struct sockaddr_in6 *a2_src = &a2->src_addr.in6;
-		const struct sockaddr_in6 *a2_dst = (const struct sockaddr_in6 *)a2->ai->ai_addr;
-		prefixlen1 = _common_prefix_len(&a1_src->sin6_addr, &a1_dst->sin6_addr);
-		prefixlen2 = _common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr);
-		if (prefixlen1 != prefixlen2) {
-			return prefixlen2 - prefixlen1;
-		}
-	}
-
-	/*
-	 * Rule 10: Leave the order unchanged.
-	 * We need this since qsort() is not necessarily stable.
-	 */
-	return a1->original_order - a2->original_order;
-}
-
-/*
- * Find the source address that will be used if trying to connect to the given
- * address. src_addr must be large enough to hold a struct sockaddr_in6.
- *
- * Returns 1 if a source address was found, 0 if the address is unreachable,
- * and -1 if a fatal error occurred. If 0 or 1, the contents of src_addr are
- * undefined.
- */
-
-/*ARGSUSED*/
-static int
-_find_src_addr(const struct sockaddr *addr, struct sockaddr *src_addr)
-{
-	int sock;
-	int ret;
-	socklen_t len;
-
-	switch (addr->sa_family) {
-	case AF_INET:
-		len = sizeof(struct sockaddr_in);
-		break;
-	case AF_INET6:
-		len = sizeof(struct sockaddr_in6);
-		break;
-	default:
-		/* No known usable source address for non-INET families. */
-		return 0;
-	}
-
-	sock = socket(addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
-	if (sock == -1) {
-		if (errno == EAFNOSUPPORT) {
-			return 0;
-		} else {
-			return -1;
-		}
-	}
-
-	do {
-		ret = connect(sock, addr, len);
-	} while (ret == -1 && errno == EINTR);
-
-	if (ret == -1) {
-		close(sock);
-		return 0;
-	}
-
-	if (getsockname(sock, src_addr, &len) == -1) {
-		close(sock);
-		return -1;
-	}
-	close(sock);
-	return 1;
-}
-
-/*
- * Sort the linked list starting at sentinel->ai_next in RFC6724 order.
- * Will leave the list unchanged if an error occurs.
- */
-
-/*ARGSUSED*/
-static void
-_rfc6724_sort(struct addrinfo *list_sentinel)
-{
-	struct addrinfo *cur;
-	int nelem = 0, i;
-	struct addrinfo_sort_elem *elems;
-
-	cur = list_sentinel->ai_next;
-	while (cur) {
-		++nelem;
-		cur = cur->ai_next;
-	}
-
-	elems = (struct addrinfo_sort_elem *)malloc(nelem * sizeof(struct addrinfo_sort_elem));
-	if (elems == NULL) {
-		goto error;
-	}
-
-	/*
-	 * Convert the linked list to an array that also contains the candidate
-	 * source address for each destination address.
-	 */
-	for (i = 0, cur = list_sentinel->ai_next; i < nelem; ++i, cur = cur->ai_next) {
-		int has_src_addr;
-		assert(cur != NULL);
-		elems[i].ai = cur;
-		elems[i].original_order = i;
-
-		has_src_addr = _find_src_addr(cur->ai_addr, &elems[i].src_addr.generic);
-		if (has_src_addr == -1) {
-			goto error;
-		}
-		elems[i].has_src_addr = has_src_addr;
-	}
-
-	/* Sort the addresses, and rearrange the linked list so it matches the sorted order. */
-	qsort((void *)elems, nelem, sizeof(struct addrinfo_sort_elem), _rfc6724_compare);
-
-	list_sentinel->ai_next = elems[0].ai;
-	for (i = 0; i < nelem - 1; ++i) {
-		elems[i].ai->ai_next = elems[i + 1].ai;
-	}
-	elems[nelem - 1].ai->ai_next = NULL;
-
-error:
-	free(elems);
-}
-
-static bool _using_default_dns(const char *iface)
-{
-	char buf[IF_NAMESIZE+1];
-	size_t if_len;
-
-	// common case
-	if (iface == NULL || *iface == '\0') return true;
-
-	if_len = _resolv_get_default_iface(buf, sizeof(buf));
-	if (if_len != 0 && if_len + 1 <= sizeof(buf)) {
-		if (strcmp(buf, iface) == 0) return true;
-	}
-	return false;
-}
-
-/*ARGSUSED*/
-static int
-_dns_getaddrinfo(void *rv, void	*cb_data, va_list ap)
-{
-	struct addrinfo *ai;
-	querybuf *buf, *buf2;
-	const char *name;
-	const struct addrinfo *pai;
-	struct addrinfo sentinel, *cur;
-	struct res_target q, q2;
-	res_state res;
-	const char* iface;
-	int mark;
-
-	name = va_arg(ap, char *);
-	pai = va_arg(ap, const struct addrinfo *);
-	iface = va_arg(ap, char *);
-	mark = va_arg(ap, int);
-	//fprintf(stderr, "_dns_getaddrinfo() name = '%s'\n", name);
-
-	memset(&q, 0, sizeof(q));
-	memset(&q2, 0, sizeof(q2));
-	memset(&sentinel, 0, sizeof(sentinel));
-	cur = &sentinel;
-
-	buf = malloc(sizeof(*buf));
-	if (buf == NULL) {
-		h_errno = NETDB_INTERNAL;
-		return NS_NOTFOUND;
-	}
-	buf2 = malloc(sizeof(*buf2));
-	if (buf2 == NULL) {
-		free(buf);
-		h_errno = NETDB_INTERNAL;
-		return NS_NOTFOUND;
-	}
-
-	switch (pai->ai_family) {
-	case AF_UNSPEC:
-		/* prefer IPv6 */
-		q.name = name;
-		q.qclass = C_IN;
-		q.answer = buf->buf;
-		q.anslen = sizeof(buf->buf);
-		int query_ipv6 = 1, query_ipv4 = 1;
-		if (pai->ai_flags & AI_ADDRCONFIG) {
-			// Only implement AI_ADDRCONFIG if the application is not
-			// using its own DNS servers, since our implementation
-			// only works on the default connection.
-			if (_using_default_dns(iface)) {
-				query_ipv6 = _have_ipv6();
-				query_ipv4 = _have_ipv4();
-			}
-		}
-		if (query_ipv6) {
-			q.qtype = T_AAAA;
-			if (query_ipv4) {
-				q.next = &q2;
-				q2.name = name;
-				q2.qclass = C_IN;
-				q2.qtype = T_A;
-				q2.answer = buf2->buf;
-				q2.anslen = sizeof(buf2->buf);
-			}
-		} else if (query_ipv4) {
-			q.qtype = T_A;
-		} else {
-			free(buf);
-			free(buf2);
-			return NS_NOTFOUND;
-		}
-		break;
-	case AF_INET:
-		q.name = name;
-		q.qclass = C_IN;
-		q.qtype = T_A;
-		q.answer = buf->buf;
-		q.anslen = sizeof(buf->buf);
-		break;
-	case AF_INET6:
-		q.name = name;
-		q.qclass = C_IN;
-		q.qtype = T_AAAA;
-		q.answer = buf->buf;
-		q.anslen = sizeof(buf->buf);
-		break;
-	default:
-		free(buf);
-		free(buf2);
-		return NS_UNAVAIL;
-	}
-
-	res = __res_get_state();
-	if (res == NULL) {
-		free(buf);
-		free(buf2);
-		return NS_NOTFOUND;
-	}
-
-	/* this just sets our iface val in the thread private data so we don't have to
-	 * modify the api's all the way down to res_send.c's res_nsend.  We could
-	 * fully populate the thread private data here, but if we get down there
-	 * and have a cache hit that would be wasted, so we do the rest there on miss
-	 */
-	res_setiface(res, iface);
-	res_setmark(res, mark);
-	if (res_searchN(name, &q, res) < 0) {
-		__res_put_state(res);
-		free(buf);
-		free(buf2);
-		return NS_NOTFOUND;
-	}
-	ai = getanswer(buf, q.n, q.name, q.qtype, pai);
-	if (ai) {
-		cur->ai_next = ai;
-		while (cur && cur->ai_next)
-			cur = cur->ai_next;
-	}
-	if (q.next) {
-		ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai);
-		if (ai)
-			cur->ai_next = ai;
-	}
-	free(buf);
-	free(buf2);
-	if (sentinel.ai_next == NULL) {
-		__res_put_state(res);
-		switch (h_errno) {
-		case HOST_NOT_FOUND:
-			return NS_NOTFOUND;
-		case TRY_AGAIN:
-			return NS_TRYAGAIN;
-		default:
-			return NS_UNAVAIL;
-		}
-	}
-
-	_rfc6724_sort(&sentinel);
-
-	__res_put_state(res);
-
-	*((struct addrinfo **)rv) = sentinel.ai_next;
-	return NS_SUCCESS;
-}
-
-static void
-_sethtent(FILE **hostf)
-{
-
-	if (!*hostf)
-		*hostf = fopen(_PATH_HOSTS, "r" );
-	else
-		rewind(*hostf);
-}
-
-static void
-_endhtent(FILE **hostf)
-{
-
-	if (*hostf) {
-		(void) fclose(*hostf);
-		*hostf = NULL;
-	}
-}
-
-static struct addrinfo *
-_gethtent(FILE **hostf, const char *name, const struct addrinfo *pai)
-{
-	char *p;
-	char *cp, *tname, *cname;
-	struct addrinfo hints, *res0, *res;
-	int error;
-	const char *addr;
-	char hostbuf[8*1024];
-
-//	fprintf(stderr, "_gethtent() name = '%s'\n", name);
-	assert(name != NULL);
-	assert(pai != NULL);
-
-	if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "r" )))
-		return (NULL);
- again:
-	if (!(p = fgets(hostbuf, sizeof hostbuf, *hostf)))
-		return (NULL);
-	if (*p == '#')
-		goto again;
-	if (!(cp = strpbrk(p, "#\n")))
-		goto again;
-	*cp = '\0';
-	if (!(cp = strpbrk(p, " \t")))
-		goto again;
-	*cp++ = '\0';
-	addr = p;
-	/* if this is not something we're looking for, skip it. */
-	cname = NULL;
-	while (cp && *cp) {
-		if (*cp == ' ' || *cp == '\t') {
-			cp++;
-			continue;
-		}
-		if (!cname)
-			cname = cp;
-		tname = cp;
-		if ((cp = strpbrk(cp, " \t")) != NULL)
-			*cp++ = '\0';
-//		fprintf(stderr, "\ttname = '%s'", tname);
-		if (strcasecmp(name, tname) == 0)
-			goto found;
-	}
-	goto again;
-
-found:
-	hints = *pai;
-	hints.ai_flags = AI_NUMERICHOST;
-	error = getaddrinfo(addr, NULL, &hints, &res0);
-	if (error)
-		goto again;
-	for (res = res0; res; res = res->ai_next) {
-		/* cover it up */
-		res->ai_flags = pai->ai_flags;
-
-		if (pai->ai_flags & AI_CANONNAME) {
-			if (get_canonname(pai, res, cname) != 0) {
-				freeaddrinfo(res0);
-				goto again;
-			}
-		}
-	}
-	return res0;
-}
-
-/*ARGSUSED*/
-static int
-_files_getaddrinfo(void *rv, void *cb_data, va_list ap)
-{
-	const char *name;
-	const struct addrinfo *pai;
-	struct addrinfo sentinel, *cur;
-	struct addrinfo *p;
-	FILE *hostf = NULL;
-
-	name = va_arg(ap, char *);
-	pai = va_arg(ap, struct addrinfo *);
-
-//	fprintf(stderr, "_files_getaddrinfo() name = '%s'\n", name);
-	memset(&sentinel, 0, sizeof(sentinel));
-	cur = &sentinel;
-
-	_sethtent(&hostf);
-	while ((p = _gethtent(&hostf, name, pai)) != NULL) {
-		cur->ai_next = p;
-		while (cur && cur->ai_next)
-			cur = cur->ai_next;
-	}
-	_endhtent(&hostf);
-
-	*((struct addrinfo **)rv) = sentinel.ai_next;
-	if (sentinel.ai_next == NULL)
-		return NS_NOTFOUND;
-	return NS_SUCCESS;
-}
-
-/* resolver logic */
-
-/*
- * Formulate a normal query, send, and await answer.
- * Returned answer is placed in supplied buffer "answer".
- * Perform preliminary check of answer, returning success only
- * if no error is indicated and the answer count is nonzero.
- * Return the size of the response on success, -1 on error.
- * Error number is left in h_errno.
- *
- * Caller must parse answer and determine whether it answers the question.
- */
-static int
-res_queryN(const char *name, /* domain name */ struct res_target *target,
-    res_state res)
-{
-	u_char buf[MAXPACKET];
-	HEADER *hp;
-	int n;
-	struct res_target *t;
-	int rcode;
-	int ancount;
-
-	assert(name != NULL);
-	/* XXX: target may be NULL??? */
-
-	rcode = NOERROR;
-	ancount = 0;
-
-	for (t = target; t; t = t->next) {
-		int class, type;
-		u_char *answer;
-		int anslen;
-
-		hp = (HEADER *)(void *)t->answer;
-		hp->rcode = NOERROR;	/* default */
-
-		/* make it easier... */
-		class = t->qclass;
-		type = t->qtype;
-		answer = t->answer;
-		anslen = t->anslen;
-#ifdef DEBUG
-		if (res->options & RES_DEBUG)
-			printf(";; res_nquery(%s, %d, %d)\n", name, class, type);
-#endif
-
-		n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL,
-		    buf, sizeof(buf));
-#ifdef RES_USE_EDNS0
-		if (n > 0 && (res->options & RES_USE_EDNS0) != 0)
-			n = res_nopt(res, n, buf, sizeof(buf), anslen);
-#endif
-		if (n <= 0) {
-#ifdef DEBUG
-			if (res->options & RES_DEBUG)
-				printf(";; res_nquery: mkquery failed\n");
-#endif
-			h_errno = NO_RECOVERY;
-			return n;
-		}
-		n = res_nsend(res, buf, n, answer, anslen);
-#if 0
-		if (n < 0) {
-#ifdef DEBUG
-			if (res->options & RES_DEBUG)
-				printf(";; res_query: send error\n");
-#endif
-			h_errno = TRY_AGAIN;
-			return n;
-		}
-#endif
-
-		if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
-			rcode = hp->rcode;	/* record most recent error */
-#ifdef DEBUG
-			if (res->options & RES_DEBUG)
-				printf(";; rcode = %u, ancount=%u\n", hp->rcode,
-				    ntohs(hp->ancount));
-#endif
-			continue;
-		}
-
-		ancount += ntohs(hp->ancount);
-
-		t->n = n;
-	}
-
-	if (ancount == 0) {
-		switch (rcode) {
-		case NXDOMAIN:
-			h_errno = HOST_NOT_FOUND;
-			break;
-		case SERVFAIL:
-			h_errno = TRY_AGAIN;
-			break;
-		case NOERROR:
-			h_errno = NO_DATA;
-			break;
-		case FORMERR:
-		case NOTIMP:
-		case REFUSED:
-		default:
-			h_errno = NO_RECOVERY;
-			break;
-		}
-		return -1;
-	}
-	return ancount;
-}
-
-/*
- * Formulate a normal query, send, and retrieve answer in supplied buffer.
- * Return the size of the response on success, -1 on error.
- * If enabled, implement search rules until answer or unrecoverable failure
- * is detected.  Error code, if any, is left in h_errno.
- */
-static int
-res_searchN(const char *name, struct res_target *target, res_state res)
-{
-	const char *cp, * const *domain;
-	HEADER *hp;
-	u_int dots;
-	int trailing_dot, ret, saved_herrno;
-	int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
-
-	assert(name != NULL);
-	assert(target != NULL);
-
-	hp = (HEADER *)(void *)target->answer;	/*XXX*/
-
-	errno = 0;
-	h_errno = HOST_NOT_FOUND;	/* default, if we never query */
-	dots = 0;
-	for (cp = name; *cp; cp++)
-		dots += (*cp == '.');
-	trailing_dot = 0;
-	if (cp > name && *--cp == '.')
-		trailing_dot++;
-
-
-        //fprintf(stderr, "res_searchN() name = '%s'\n", name);
-
-	/*
-	 * if there aren't any dots, it could be a user-level alias
-	 */
-	if (!dots && (cp = __hostalias(name)) != NULL) {
-		ret = res_queryN(cp, target, res);
-		return ret;
-	}
-
-	/*
-	 * If there are dots in the name already, let's just give it a try
-	 * 'as is'.  The threshold can be set with the "ndots" option.
-	 */
-	saved_herrno = -1;
-	if (dots >= res->ndots) {
-		ret = res_querydomainN(name, NULL, target, res);
-		if (ret > 0)
-			return (ret);
-		saved_herrno = h_errno;
-		tried_as_is++;
-	}
-
-	/*
-	 * We do at least one level of search if
-	 *	- there is no dot and RES_DEFNAME is set, or
-	 *	- there is at least one dot, there is no trailing dot,
-	 *	  and RES_DNSRCH is set.
-	 */
-	if ((!dots && (res->options & RES_DEFNAMES)) ||
-	    (dots && !trailing_dot && (res->options & RES_DNSRCH))) {
-		int done = 0;
-
-		/* Unfortunately we need to set stuff up before
-		 * the domain stuff is tried.  Will have a better
-		 * fix after thread pools are used.
-		 */
-		_resolv_populate_res_for_iface(res);
-
-		for (domain = (const char * const *)res->dnsrch;
-		   *domain && !done;
-		   domain++) {
-
-			ret = res_querydomainN(name, *domain, target, res);
-			if (ret > 0)
-				return ret;
-
-			/*
-			 * If no server present, give up.
-			 * If name isn't found in this domain,
-			 * keep trying higher domains in the search list
-			 * (if that's enabled).
-			 * On a NO_DATA error, keep trying, otherwise
-			 * a wildcard entry of another type could keep us
-			 * from finding this entry higher in the domain.
-			 * If we get some other error (negative answer or
-			 * server failure), then stop searching up,
-			 * but try the input name below in case it's
-			 * fully-qualified.
-			 */
-			if (errno == ECONNREFUSED) {
-				h_errno = TRY_AGAIN;
-				return -1;
-			}
-
-			switch (h_errno) {
-			case NO_DATA:
-				got_nodata++;
-				/* FALLTHROUGH */
-			case HOST_NOT_FOUND:
-				/* keep trying */
-				break;
-			case TRY_AGAIN:
-				if (hp->rcode == SERVFAIL) {
-					/* try next search element, if any */
-					got_servfail++;
-					break;
-				}
-				/* FALLTHROUGH */
-			default:
-				/* anything else implies that we're done */
-				done++;
-			}
-			/*
-			 * if we got here for some reason other than DNSRCH,
-			 * we only wanted one iteration of the loop, so stop.
-			 */
-			if (!(res->options & RES_DNSRCH))
-			        done++;
-		}
-	}
-
-	/*
-	 * if we have not already tried the name "as is", do that now.
-	 * note that we do this regardless of how many dots were in the
-	 * name or whether it ends with a dot.
-	 */
-	if (!tried_as_is) {
-		ret = res_querydomainN(name, NULL, target, res);
-		if (ret > 0)
-			return ret;
-	}
-
-	/*
-	 * if we got here, we didn't satisfy the search.
-	 * if we did an initial full query, return that query's h_errno
-	 * (note that we wouldn't be here if that query had succeeded).
-	 * else if we ever got a nodata, send that back as the reason.
-	 * else send back meaningless h_errno, that being the one from
-	 * the last DNSRCH we did.
-	 */
-	if (saved_herrno != -1)
-		h_errno = saved_herrno;
-	else if (got_nodata)
-		h_errno = NO_DATA;
-	else if (got_servfail)
-		h_errno = TRY_AGAIN;
-	return -1;
-}
-
-/*
- * Perform a call on res_query on the concatenation of name and domain,
- * removing a trailing dot from name if domain is NULL.
- */
-static int
-res_querydomainN(const char *name, const char *domain,
-    struct res_target *target, res_state res)
-{
-	char nbuf[MAXDNAME];
-	const char *longname = nbuf;
-	size_t n, d;
-
-	assert(name != NULL);
-	/* XXX: target may be NULL??? */
-
-#ifdef DEBUG
-	if (res->options & RES_DEBUG)
-		printf(";; res_querydomain(%s, %s)\n",
-			name, domain?domain:"<Nil>");
-#endif
-	if (domain == NULL) {
-		/*
-		 * Check for trailing '.';
-		 * copy without '.' if present.
-		 */
-		n = strlen(name);
-		if (n + 1 > sizeof(nbuf)) {
-			h_errno = NO_RECOVERY;
-			return -1;
-		}
-		if (n > 0 && name[--n] == '.') {
-			strncpy(nbuf, name, n);
-			nbuf[n] = '\0';
-		} else
-			longname = name;
-	} else {
-		n = strlen(name);
-		d = strlen(domain);
-		if (n + 1 + d + 1 > sizeof(nbuf)) {
-			h_errno = NO_RECOVERY;
-			return -1;
-		}
-		snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain);
-	}
-	return res_queryN(longname, target, res);
-}
diff --git a/libc/netbsd/net/getnameinfo.c b/libc/netbsd/net/getnameinfo.c
deleted file mode 100644
index 15d2675..0000000
--- a/libc/netbsd/net/getnameinfo.c
+++ /dev/null
@@ -1,460 +0,0 @@
-/*	$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $	*/
-/*	$KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $	*/
-
-/*
- * Copyright (c) 2000 Ben Harris.
- * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Issues to be discussed:
- * - Thread safe-ness must be checked
- * - RFC2553 says that we should raise error on short buffer.  X/Open says
- *   we need to truncate the result.  We obey RFC2553 (and X/Open should be
- *   modified).  ipngwg rough consensus seems to follow RFC2553.
- * - What is "local" in NI_FQDN?
- * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other.
- * - (KAME extension) always attach textual scopeid (fe80::1%lo0), if
- *   sin6_scope_id is filled - standardization status?
- *   XXX breaks backward compat for code that expects no scopeid.
- *   beware on merge.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <net/if.h>
-#include <net/if_ieee1394.h>
-#include <net/if_types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <assert.h>
-#include <limits.h>
-#include <netdb.h>
-#include "arpa_nameser.h"
-#include "resolv_private.h"
-#include <sys/system_properties.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#include <stddef.h>
-#include <string.h>
-
-static const struct afd {
-	int		a_af;
-	socklen_t	a_addrlen;
-	socklen_t	a_socklen;
-	int		a_off;
-} afdl [] = {
-#ifdef INET6
-	{PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
-		offsetof(struct sockaddr_in6, sin6_addr)},
-#endif
-	{PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
-		offsetof(struct sockaddr_in, sin_addr)},
-	{0, 0, 0, 0},
-};
-
-struct sockinet {
-	u_char	si_len;
-	u_char	si_family;
-	u_short	si_port;
-};
-
-static int getnameinfo_inet(const struct sockaddr *, socklen_t, char *,
-    socklen_t, char *, socklen_t, int, const char*, int);
-#ifdef INET6
-static int ip6_parsenumeric(const struct sockaddr *, const char *, char *,
-				 socklen_t, int);
-static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int);
-#endif
-static int getnameinfo_local(const struct sockaddr *, socklen_t, char *,
-    socklen_t, char *, socklen_t, int);
-
-/*
- * Top-level getnameinfo() code.  Look at the address family, and pick an
- * appropriate function to call.
- */
-int getnameinfo(const struct sockaddr* sa, socklen_t salen, char* host, size_t hostlen, char* serv, size_t servlen, int flags)
-{
-	return android_getnameinfoforiface(sa, salen, host, hostlen, serv, servlen, flags, NULL, 0);
-}
-
-int android_getnameinfoforiface(const struct sockaddr* sa, socklen_t salen, char* host, size_t hostlen, char* serv, size_t servlen, int flags, const char* iface, int mark)
-{
-	switch (sa->sa_family) {
-	case AF_INET:
-	case AF_INET6:
-		return getnameinfo_inet(sa, salen, host, hostlen,
-				serv, servlen, flags, iface, mark);
-	case AF_LOCAL:
-		return getnameinfo_local(sa, salen, host, hostlen,
-		    serv, servlen, flags);
-	default:
-		return EAI_FAMILY;
-	}
-}
-
-/*
- * getnameinfo_local():
- * Format an local address into a printable format.
- */
-/* ARGSUSED */
-static int
-getnameinfo_local(const struct sockaddr *sa, socklen_t salen,
-    char *host, socklen_t hostlen, char *serv, socklen_t servlen,
-    int flags __attribute__((unused)))
-{
-       const struct sockaddr_un *sun =
-           (const struct sockaddr_un *)(const void *)sa;
-
-       if (salen < (socklen_t) offsetof(struct sockaddr_un, sun_path)) {
-           return EAI_FAMILY;
-       }
-
-       if (serv != NULL && servlen > 0)
-               serv[0] = '\0';
-
-       if (host && hostlen > 0)
-               strlcpy(host, sun->sun_path,
-                   MIN((socklen_t) sizeof(sun->sun_path) + 1, hostlen));
-
-       return 0;
-}
-
-/* On success length of the host name is returned. A return
- * value of 0 means there's no host name associated with
- * the address. On failure -1 is returned in which case
- * normal execution flow shall continue. */
-static int
-android_gethostbyaddr_proxy(char* nameBuf, size_t nameBufLen, const void *addr, socklen_t addrLen, int addrFamily, const char* iface, int mark)
-{
-	struct hostent *hostResult =
-			android_gethostbyaddrforiface_proxy(addr, addrLen, addrFamily, iface, mark);
-
-	if (hostResult == NULL) return 0;
-
-	int lengthResult = strlen(hostResult->h_name);
-
-	if (nameBuf) strncpy(nameBuf, hostResult->h_name, nameBufLen);
-	return lengthResult;
-}
-
-/*
- * getnameinfo_inet():
- * Format an IPv4 or IPv6 sockaddr into a printable string.
- */
-static int
-getnameinfo_inet(const struct sockaddr* sa, socklen_t salen,
-       char *host, socklen_t hostlen,
-       char *serv, socklen_t servlen,
-       int flags, const char* iface, int mark)
-{
-	const struct afd *afd;
-	struct servent *sp;
-	struct hostent *hp;
-	u_short port;
-	int family, i;
-	const char *addr;
-	uint32_t v4a;
-	char numserv[512];
-	char numaddr[512];
-
-	/* sa is checked below */
-	/* host may be NULL */
-	/* serv may be NULL */
-
-	if (sa == NULL)
-		return EAI_FAIL;
-
-	family = sa->sa_family;
-	for (i = 0; afdl[i].a_af; i++)
-		if (afdl[i].a_af == family) {
-			afd = &afdl[i];
-			goto found;
-		}
-	return EAI_FAMILY;
-
- found:
-	// http://b/1889275: callers should be allowed to provide too much
-	// space, but not too little.
-	if (salen < afd->a_socklen) {
-		return EAI_FAMILY;
-	}
-
-	/* network byte order */
-	port = ((const struct sockinet *)(const void *)sa)->si_port;
-	addr = (const char *)(const void *)sa + afd->a_off;
-
-	if (serv == NULL || servlen == 0) {
-		/*
-		 * do nothing in this case.
-		 * in case you are wondering if "&&" is more correct than
-		 * "||" here: rfc2553bis-03 says that serv == NULL OR
-		 * servlen == 0 means that the caller does not want the result.
-		 */
-	} else {
-		if (flags & NI_NUMERICSERV)
-			sp = NULL;
-		else {
-			sp = getservbyport(port,
-				(flags & NI_DGRAM) ? "udp" : "tcp");
-		}
-		if (sp) {
-			if (strlen(sp->s_name) + 1 > (size_t)servlen)
-				return EAI_MEMORY;
-			strlcpy(serv, sp->s_name, servlen);
-		} else {
-			snprintf(numserv, sizeof(numserv), "%u", ntohs(port));
-			if (strlen(numserv) + 1 > (size_t)servlen)
-				return EAI_MEMORY;
-			strlcpy(serv, numserv, servlen);
-		}
-	}
-
-	switch (sa->sa_family) {
-	case AF_INET:
-		v4a = (uint32_t)
-		    ntohl(((const struct sockaddr_in *)
-		    (const void *)sa)->sin_addr.s_addr);
-		if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
-			flags |= NI_NUMERICHOST;
-		v4a >>= IN_CLASSA_NSHIFT;
-		if (v4a == 0)
-			flags |= NI_NUMERICHOST;
-		break;
-#ifdef INET6
-	case AF_INET6:
-	    {
-		const struct sockaddr_in6 *sin6;
-		sin6 = (const struct sockaddr_in6 *)(const void *)sa;
-		switch (sin6->sin6_addr.s6_addr[0]) {
-		case 0x00:
-			if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
-				;
-			else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
-				;
-			else
-				flags |= NI_NUMERICHOST;
-			break;
-		default:
-			if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
-				flags |= NI_NUMERICHOST;
-			}
-			else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
-				flags |= NI_NUMERICHOST;
-			break;
-		}
-	    }
-		break;
-#endif
-	}
-	if (host == NULL || hostlen == 0) {
-		/*
-		 * do nothing in this case.
-		 * in case you are wondering if "&&" is more correct than
-		 * "||" here: rfc2553bis-03 says that host == NULL or
-		 * hostlen == 0 means that the caller does not want the result.
-		 */
-	} else if (flags & NI_NUMERICHOST) {
-		size_t numaddrlen;
-
-		/* NUMERICHOST and NAMEREQD conflicts with each other */
-		if (flags & NI_NAMEREQD)
-			return EAI_NONAME;
-
-		switch(afd->a_af) {
-#ifdef INET6
-		case AF_INET6:
-		{
-			int error;
-
-			if ((error = ip6_parsenumeric(sa, addr, host,
-						      hostlen, flags)) != 0)
-				return(error);
-			break;
-		}
-#endif
-		default:
-			if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr))
-			    == NULL)
-				return EAI_SYSTEM;
-			numaddrlen = strlen(numaddr);
-			if (numaddrlen + 1 > (size_t)hostlen) /* don't forget terminator */
-				return EAI_MEMORY;
-			strlcpy(host, numaddr, hostlen);
-			break;
-		}
-	} else {
-		struct hostent android_proxy_hostent;
-		char android_proxy_buf[MAXDNAME];
-
-		int hostnamelen = android_gethostbyaddr_proxy(android_proxy_buf,
-				MAXDNAME, addr, afd->a_addrlen, afd->a_af, iface, mark);
-		if (hostnamelen > 0) {
-			hp = &android_proxy_hostent;
-			hp->h_name = android_proxy_buf;
-		} else if (!hostnamelen) {
-			hp = NULL;
-		} else {
-			hp = android_gethostbyaddrforiface(addr, afd->a_addrlen, afd->a_af,
-					iface, mark);
-		}
-
-		if (hp) {
-#if 0
-			/*
-			 * commented out, since "for local host" is not
-			 * implemented here - see RFC2553 p30
-			 */
-			if (flags & NI_NOFQDN) {
-				char *p;
-				p = strchr(hp->h_name, '.');
-				if (p)
-					*p = '\0';
-			}
-#endif
-			if (strlen(hp->h_name) + 1 > (size_t)hostlen) {
-				return EAI_MEMORY;
-			}
-			strlcpy(host, hp->h_name, hostlen);
-		} else {
-			if (flags & NI_NAMEREQD)
-				return EAI_NONAME;
-			switch(afd->a_af) {
-#ifdef INET6
-			case AF_INET6:
-			{
-				int error;
-
-				if ((error = ip6_parsenumeric(sa, addr, host,
-							      hostlen,
-							      flags)) != 0)
-					return(error);
-				break;
-			}
-#endif
-			default:
-				if (inet_ntop(afd->a_af, addr, host,
-				    hostlen) == NULL)
-					return EAI_SYSTEM;
-				break;
-			}
-		}
-	}
-	return(0);
-}
-
-#ifdef INET6
-static int
-ip6_parsenumeric(const struct sockaddr *sa, const char *addr, char *host,
-       socklen_t hostlen, int flags)
-{
-	size_t numaddrlen;
-	char numaddr[512];
-
-	assert(sa != NULL);
-	assert(addr != NULL);
-	assert(host != NULL);
-
-	if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL)
-		return EAI_SYSTEM;
-
-	numaddrlen = strlen(numaddr);
-	if (numaddrlen + 1 > (size_t)hostlen) /* don't forget terminator */
-		return EAI_OVERFLOW;
-	strlcpy(host, numaddr, hostlen);
-
-	if (((const struct sockaddr_in6 *)(const void *)sa)->sin6_scope_id) {
-		char zonebuf[MAXHOSTNAMELEN];
-		int zonelen;
-
-		zonelen = ip6_sa2str(
-		    (const struct sockaddr_in6 *)(const void *)sa,
-		    zonebuf, sizeof(zonebuf), flags);
-		if (zonelen < 0)
-			return EAI_OVERFLOW;
-		if ((size_t) zonelen + 1 + numaddrlen + 1 > (size_t)hostlen)
-			return EAI_OVERFLOW;
-		/* construct <numeric-addr><delim><zoneid> */
-		memcpy(host + numaddrlen + 1, zonebuf,
-		    (size_t)zonelen);
-		host[numaddrlen] = SCOPE_DELIMITER;
-		host[numaddrlen + 1 + zonelen] = '\0';
-	}
-
-	return 0;
-}
-
-/* ARGSUSED */
-static int
-ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags)
-{
-	unsigned int ifindex;
-	const struct in6_addr *a6;
-	int n;
-
-	assert(sa6 != NULL);
-	assert(buf != NULL);
-
-	ifindex = (unsigned int)sa6->sin6_scope_id;
-	a6 = &sa6->sin6_addr;
-
-#ifdef NI_NUMERICSCOPE
-	if ((flags & NI_NUMERICSCOPE) != 0) {
-		n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
-		if (n < 0 || n >= bufsiz)
-			return -1;
-		else
-			return n;
-	}
-#endif
-
-	/* if_indextoname() does not take buffer size.  not a good api... */
-	if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) &&
-	    bufsiz >= IF_NAMESIZE) {
-		char *p = if_indextoname(ifindex, buf);
-		if (p) {
-			return(strlen(p));
-		}
-	}
-
-	/* last resort */
-	n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
-	if (n < 0 || (size_t) n >= bufsiz)
-		return -1;
-	else
-		return n;
-}
-#endif /* INET6 */
diff --git a/libc/netbsd/net/getservbyname.c b/libc/netbsd/net/getservbyname.c
deleted file mode 100644
index 5ea528e..0000000
--- a/libc/netbsd/net/getservbyname.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <netdb.h>
-#include "servent.h"
-
-struct servent *
-getservbyname(const char *name, const char *proto)
-{
-    res_static       rs = __res_get_static();
-    struct servent*  s;
-
-    if (rs == NULL || proto == NULL || name == NULL) {
-        errno = EINVAL;
-        return NULL;
-    }
-
-    rs->servent_ptr = NULL;
-    while (1) {
-        struct servent*  s = getservent_r(rs);
-        if (s == NULL)
-            break;
-        if ( !strcmp( s->s_name, name ) && !strcmp( s->s_proto, proto ) )
-            return s;
-    }
-
-    return NULL;
-}
diff --git a/libc/netbsd/net/getservbyport.c b/libc/netbsd/net/getservbyport.c
deleted file mode 100644
index fad7e23..0000000
--- a/libc/netbsd/net/getservbyport.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <sys/cdefs.h>
-#include <netdb.h>
-#include "servent.h"
-
-struct servent *
-getservbyport(int port, const char *proto)
-{
-    res_static       rs = __res_get_static();
-    struct servent*  s;
-
-    if (rs == NULL || proto == NULL) {
-        errno = EINVAL;
-        return NULL;
-    }
-
-    rs->servent_ptr = NULL;
-    while (1) {
-        struct servent*  s = getservent_r(rs);
-        if (s == NULL)
-            break;
-        if ( s->s_port == port && !strcmp( s->s_proto, proto ) )
-            return s;
-    }
-
-    return NULL;
-}
diff --git a/libc/netbsd/net/nsdispatch.c b/libc/netbsd/net/nsdispatch.c
deleted file mode 100644
index 15282be..0000000
--- a/libc/netbsd/net/nsdispatch.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*	$NetBSD: nsdispatch.c,v 1.30 2005/11/29 03:11:59 christos Exp $	*/
-
-/*-
- * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Luke Mewburn; and by Jason R. Thorpe.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*-
- * Copyright (c) 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * Portions of this software were developed for the FreeBSD Project by
- * Jacques A. Vidrine, Safeport Network Services, and Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
- * ("CBOSS"), as part of the DARPA CHATS research program.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <assert.h>
-#ifdef __ELF__
-#include <dlfcn.h>
-#endif /* __ELF__ */
-#include <fcntl.h>
-#define _NS_PRIVATE
-#include <nsswitch.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-
-static nss_method
-_nsmethod(const char *source, const char *database, const char *method,
-    const ns_dtab disp_tab[], void **cb_data)
-{
-	int	curdisp;
-
-	if (disp_tab != NULL) {
-		for (curdisp = 0; disp_tab[curdisp].src != NULL; curdisp++) {
-			if (strcasecmp(source, disp_tab[curdisp].src) == 0) {
-				*cb_data = disp_tab[curdisp].cb_data;
-				return (disp_tab[curdisp].callback);
-			}
-		}
-	}
-
-	*cb_data = NULL;
-	return (NULL);
-}
-
-int
-/*ARGSUSED*/
-nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
-	    const char *method, const ns_src defaults[], ...)
-{
-	va_list		 ap;
-	int		 i, result;
-	const ns_src	*srclist;
-	int		 srclistsize;
-	nss_method	 cb;
-	void		*cb_data;
-
-	/* retval may be NULL */
-	/* disp_tab may be NULL */
-	assert(database != NULL);
-	assert(method != NULL);
-	assert(defaults != NULL);
-	if (database == NULL || method == NULL || defaults == NULL)
-		return (NS_UNAVAIL);
-
-        srclist = defaults;
-        srclistsize = 0;
-        while (srclist[srclistsize].name != NULL)
-                srclistsize++;
-
-	result = 0;
-
-	for (i = 0; i < srclistsize; i++) {
-		cb = _nsmethod(srclist[i].name, database, method,
-		    disp_tab, &cb_data);
-		result = 0;
-		if (cb != NULL) {
-			va_start(ap, defaults);
-			result = (*cb)(retval, cb_data, ap);
-			va_end(ap);
-			if (defaults[0].flags & NS_FORCEALL)
-				continue;
-			if (result & srclist[i].flags)
-				break;
-		}
-	}
-	result &= NS_STATUSMASK;	/* clear private flags in result */
-
-	return (result ? result : NS_NOTFOUND);
-}
diff --git a/libc/netbsd/net/reentrant.h b/libc/netbsd/net/reentrant.h
deleted file mode 100644
index 60bff08..0000000
--- a/libc/netbsd/net/reentrant.h
+++ /dev/null
@@ -1,269 +0,0 @@
-/*	$NetBSD: reentrant.h,v 1.10 2004/12/14 00:23:19 nathanw Exp $	*/
-
-/*-
- * Copyright (c) 1997, 1998, 2003 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by J.T. Conklin, by Nathan J. Williams, and by Jason R. Thorpe.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Requirements:
- * 
- * 1. The thread safe mechanism should be lightweight so the library can
- *    be used by non-threaded applications without unreasonable overhead.
- * 
- * 2. There should be no dependency on a thread engine for non-threaded
- *    applications.
- * 
- * 3. There should be no dependency on any particular thread engine.
- * 
- * 4. The library should be able to be compiled without support for thread
- *    safety.
- * 
- * 
- * Rationale:
- * 
- * One approach for thread safety is to provide discrete versions of the
- * library: one thread safe, the other not.  The disadvantage of this is
- * that libc is rather large, and two copies of a library which are 99%+
- * identical is not an efficent use of resources.
- * 
- * Another approach is to provide a single thread safe library.  However,
- * it should not add significant run time or code size overhead to non-
- * threaded applications.
- * 
- * Since the NetBSD C library is used in other projects, it should be
- * easy to replace the mutual exclusion primitives with ones provided by
- * another system.  Similarly, it should also be easy to remove all
- * support for thread safety completely if the target environment does
- * not support threads.
- * 
- * 
- * Implementation Details:
- * 
- * The thread primitives used by the library (mutex_t, mutex_lock, etc.)
- * are macros which expand to the cooresponding primitives provided by
- * the thread engine or to nothing.  The latter is used so that code is
- * not unreasonably cluttered with #ifdefs when all thread safe support
- * is removed.
- * 
- * The thread macros can be directly mapped to the mutex primitives from
- * pthreads, however it should be reasonably easy to wrap another mutex
- * implementation so it presents a similar interface.
- * 
- * The thread functions operate by dispatching to symbols which are, by
- * default, weak-aliased to no-op functions in thread-stub/thread-stub.c
- * (some uses of thread operations are conditional on __isthreaded, but
- * not all of them are).
- *
- * When the thread library is linked in, it provides strong-alias versions
- * of those symbols which dispatch to its own real thread operations.
- *
- */
-
-#ifdef _REENTRANT
-
-/*
- * Abtract thread interface for thread-safe libraries.  These routines
- * will use stubs in libc if the application is not linked against the
- * pthread library, and the real function in the pthread library if it
- * is.
- */
-
-#include <pthread.h>
-#include <signal.h>
-#include <sys/cdefs.h>
-
-#define	mutex_t			pthread_mutex_t
-#define	MUTEX_INITIALIZER	PTHREAD_MUTEX_INITIALIZER
-
-#define	mutexattr_t		pthread_mutexattr_t
-
-#define	MUTEX_TYPE_NORMAL	PTHREAD_MUTEX_NORMAL
-#define	MUTEX_TYPE_ERRORCHECK	PTHREAD_MUTEX_ERRORCHECK
-#define	MUTEX_TYPE_RECURSIVE	PTHREAD_MUTEX_RECURSIVE
-
-#define	cond_t			pthread_cond_t
-#define	COND_INITIALIZER	PTHREAD_COND_INITIALIZER
-
-#define	condattr_t		pthread_condattr_t
-
-#define	rwlock_t		pthread_rwlock_t
-#define	RWLOCK_INITIALIZER	PTHREAD_RWLOCK_INITIALIZER
-
-#define	rwlockattr_t		pthread_rwlockattr_t
-
-#define	thread_key_t		pthread_key_t
-
-#define	thr_t			pthread_t
-
-#define	thrattr_t		pthread_attr_t
-
-#define	once_t			pthread_once_t
-#define	ONCE_INITIALIZER	PTHREAD_ONCE_INIT
-
-#ifndef __LIBC_THREAD_STUBS
-
-__BEGIN_DECLS
-int	__libc_mutex_init(mutex_t *, const mutexattr_t *);
-int	__libc_mutex_lock(mutex_t *);
-int	__libc_mutex_trylock(mutex_t *);
-int	__libc_mutex_unlock(mutex_t *);
-int	__libc_mutex_destroy(mutex_t *);
-
-int	__libc_mutexattr_init(mutexattr_t *);
-int	__libc_mutexattr_settype(mutexattr_t *, int);
-int	__libc_mutexattr_destroy(mutexattr_t *);
-__END_DECLS
-
-#define	mutex_init(m, a)	__libc_mutex_init((m), (a))
-#define	mutex_lock(m)		__libc_mutex_lock((m))
-#define	mutex_trylock(m)	__libc_mutex_trylock((m))
-#define	mutex_unlock(m)		__libc_mutex_unlock((m))
-#define	mutex_destroy(m)	__libc_mutex_destroy((m))
-
-#define	mutexattr_init(ma)	__libc_mutexattr_init((ma))
-#define	mutexattr_settype(ma, t) __libc_mutexattr_settype((ma), (t))
-#define	mutexattr_destroy(ma)	__libc_mutexattr_destroy((ma))
-
-__BEGIN_DECLS
-int	__libc_cond_init(cond_t *, const condattr_t *);
-int	__libc_cond_signal(cond_t *);
-int	__libc_cond_broadcast(cond_t *);
-int	__libc_cond_wait(cond_t *, mutex_t *);
-int	__libc_cond_timedwait(cond_t *, mutex_t *, const struct timespec *);
-int	__libc_cond_destroy(cond_t *);
-__END_DECLS
-
-#define	cond_init(c, t, a)     	__libc_cond_init((c), (a))
-#define	cond_signal(c)		__libc_cond_signal((c))
-#define	cond_broadcast(c)	__libc_cond_broadcast((c))
-#define	cond_wait(c, m)		__libc_cond_wait((c), (m))
-#define	cond_timedwait(c, m, t)	__libc_cond_timedwait((c), (m), (t))
-#define	cond_destroy(c)		__libc_cond_destroy((c))
-
-__BEGIN_DECLS
-int	__libc_rwlock_init(rwlock_t *, const rwlockattr_t *);
-int	__libc_rwlock_rdlock(rwlock_t *);
-int	__libc_rwlock_wrlock(rwlock_t *);
-int	__libc_rwlock_tryrdlock(rwlock_t *);
-int	__libc_rwlock_trywrlock(rwlock_t *);
-int	__libc_rwlock_unlock(rwlock_t *);
-int	__libc_rwlock_destroy(rwlock_t *);
-__END_DECLS
-
-#define	rwlock_init(l, a)	__libc_rwlock_init((l), (a))
-#define	rwlock_rdlock(l)	__libc_rwlock_rdlock((l))
-#define	rwlock_wrlock(l)	__libc_rwlock_wrlock((l))
-#define	rwlock_tryrdlock(l)	__libc_rwlock_tryrdlock((l))
-#define	rwlock_trywrlock(l)	__libc_rwlock_trywrlock((l))
-#define	rwlock_unlock(l)	__libc_rwlock_unlock((l))
-#define	rwlock_destroy(l)	__libc_rwlock_destroy((l))
-
-__BEGIN_DECLS
-int	__libc_thr_keycreate(thread_key_t *, void (*)(void *));
-int	__libc_thr_setspecific(thread_key_t, const void *);
-void	*__libc_thr_getspecific(thread_key_t);
-int	__libc_thr_keydelete(thread_key_t);
-__END_DECLS
-
-#define	thr_keycreate(k, d)	__libc_thr_keycreate((k), (d))
-#define	thr_setspecific(k, p)	__libc_thr_setspecific((k), (p))
-#define	thr_getspecific(k)	__libc_thr_getspecific((k))
-#define	thr_keydelete(k)	__libc_thr_keydelete((k))
-
-__BEGIN_DECLS
-int	__libc_thr_once(once_t *, void (*)(void));
-int	__libc_thr_sigsetmask(int, const sigset_t *, sigset_t *);
-thr_t	__libc_thr_self(void);
-int	__libc_thr_yield(void);
-void	__libc_thr_create(thr_t *, const thrattr_t *,
-	    void *(*)(void *), void *);
-void	__libc_thr_exit(void *) __attribute__((__noreturn__));
-int	*__libc_thr_errno(void);
-int	__libc_thr_setcancelstate(int, int *);
-
-extern int __isthreaded;
-__END_DECLS
-
-#define	thr_once(o, f)		__libc_thr_once((o), (f))
-#define	thr_sigsetmask(f, n, o)	__libc_thr_sigsetmask((f), (n), (o))
-#define	thr_self()		__libc_thr_self()
-#define	thr_yield()		__libc_thr_yield()
-#define	thr_create(tp, ta, f, a) __libc_thr_create((tp), (ta), (f), (a))
-#define	thr_exit(v)		__libc_thr_exit((v))
-#define	thr_errno()		__libc_thr_errno()
-#define	thr_enabled()		(__isthreaded)
-#define thr_setcancelstate(n, o) __libc_thr_setcancelstate((n),(o))
-#endif /* __LIBC_THREAD_STUBS */
-
-#define	FLOCKFILE(fp)		__flockfile_internal(fp, 1)
-#define	FUNLOCKFILE(fp)		__funlockfile_internal(fp, 1)
-
-#else /* _REENTRANT */
-
-#define	mutex_init(m, a)
-#define	mutex_lock(m)
-#define	mutex_trylock(m)
-#define	mutex_unlock(m)
-#define	mutex_destroy(m)
-
-#define	cond_init(c, t, a)
-#define	cond_signal(c)
-#define	cond_broadcast(c)
-#define	cond_wait(c, m)
-#define	cond_timedwait(c, m, t)
-#define	cond_destroy(c)
-
-#define	rwlock_init(l, a)
-#define	rwlock_rdlock(l)
-#define	rwlock_wrlock(l)
-#define	rwlock_tryrdlock(l)
-#define	rwlock_trywrlock(l)
-#define	rwlock_unlock(l)
-#define	rwlock_destroy(l)
-
-#define	thr_keycreate(k, d)
-#define	thr_setspecific(k, p)
-#define	thr_getspecific(k)
-#define	thr_keydelete(k)
-
-#define	thr_once(o, f)
-#define	thr_sigsetmask(f, n, o)
-#define	thr_self()
-#define	thr_errno()
-
-#define	FLOCKFILE(fp)		
-#define	FUNLOCKFILE(fp)		
-
-#endif /* _REENTRANT */
diff --git a/libc/netbsd/resolv/herror.c b/libc/netbsd/resolv/herror.c
deleted file mode 100644
index e90e641..0000000
--- a/libc/netbsd/resolv/herror.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*	$NetBSD: herror.c,v 1.4 2004/05/23 05:09:52 christos Exp $	*/
-
-/*
- * Copyright (c) 1987, 1993
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#ifdef notdef
-static const char sccsid[] = "@(#)herror.c	8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "Id: herror.c,v 1.2.206.1 2004/03/09 08:33:54 marka Exp";
-#else
-__RCSID("$NetBSD: herror.c,v 1.4 2004/05/23 05:09:52 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/uio.h>
-
-#include <netinet/in.h>
-#include "arpa_nameser.h"
-
-#include <netdb.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <string.h>
-#include <unistd.h>
-
-#ifndef DE_CONST
-#define DE_CONST(c,v)   v = ((c) ? \
-    strchr((const void *)(c), *(const char *)(const void *)(c)) : NULL)
-#endif
-
-const char * const h_errlist[] = {
-	"Resolver Error 0 (no error)",
-	"Unknown host",				/* 1 HOST_NOT_FOUND */
-	"Host name lookup failure",		/* 2 TRY_AGAIN */
-	"Unknown server error",			/* 3 NO_RECOVERY */
-	"No address associated with name",	/* 4 NO_ADDRESS */
-};
-const int	h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
-
-/*
- * herror --
- *	print the error indicated by the h_errno value.
- */
-void
-herror(const char *s) {
-	struct iovec iov[4], *v = iov;
-	char *t;
-
-	if (s != NULL && *s != '\0') {
-		DE_CONST(s, t);
-		v->iov_base = t;
-		v->iov_len = strlen(t);
-		v++;
-		DE_CONST(": ", t);
-		v->iov_base = t;
-		v->iov_len = 2;
-		v++;
-	}
-	DE_CONST(hstrerror(h_errno), t);
-	v->iov_base = t;
-	v->iov_len = strlen(v->iov_base);
-	v++;
-	DE_CONST("\n", t);
-	v->iov_base = t;
-	v->iov_len = 1;
-	writev(STDERR_FILENO, iov, (v - iov) + 1);
-}
-
-/*
- * hstrerror --
- *	return the string associated with a given "host" errno value.
- */
-const char *
-hstrerror(int err) {
-	if (err < 0)
-		return ("Resolver internal error");
-	else if (err < h_nerr)
-		return (h_errlist[err]);
-	return ("Unknown resolver error");
-}
diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c
deleted file mode 100644
index 3fdf085..0000000
--- a/libc/netbsd/resolv/res_cache.c
+++ /dev/null
@@ -1,2642 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "resolv_cache.h"
-#include <resolv.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "pthread.h"
-
-#include <errno.h>
-#include "arpa_nameser.h"
-#include <sys/system_properties.h>
-#include <net/if.h>
-#include <netdb.h>
-#include <linux/if.h>
-
-#include <arpa/inet.h>
-#include "resolv_private.h"
-#include "resolv_iface.h"
-#include "res_private.h"
-
-/* This code implements a small and *simple* DNS resolver cache.
- *
- * It is only used to cache DNS answers for a time defined by the smallest TTL
- * among the answer records in order to reduce DNS traffic. It is not supposed
- * to be a full DNS cache, since we plan to implement that in the future in a
- * dedicated process running on the system.
- *
- * Note that its design is kept simple very intentionally, i.e.:
- *
- *  - it takes raw DNS query packet data as input, and returns raw DNS
- *    answer packet data as output
- *
- *    (this means that two similar queries that encode the DNS name
- *     differently will be treated distinctly).
- *
- *    the smallest TTL value among the answer records are used as the time
- *    to keep an answer in the cache.
- *
- *    this is bad, but we absolutely want to avoid parsing the answer packets
- *    (and should be solved by the later full DNS cache process).
- *
- *  - the implementation is just a (query-data) => (answer-data) hash table
- *    with a trivial least-recently-used expiration policy.
- *
- * Doing this keeps the code simple and avoids to deal with a lot of things
- * that a full DNS cache is expected to do.
- *
- * The API is also very simple:
- *
- *   - the client calls _resolv_cache_get() to obtain a handle to the cache.
- *     this will initialize the cache on first usage. the result can be NULL
- *     if the cache is disabled.
- *
- *   - the client calls _resolv_cache_lookup() before performing a query
- *
- *     if the function returns RESOLV_CACHE_FOUND, a copy of the answer data
- *     has been copied into the client-provided answer buffer.
- *
- *     if the function returns RESOLV_CACHE_NOTFOUND, the client should perform
- *     a request normally, *then* call _resolv_cache_add() to add the received
- *     answer to the cache.
- *
- *     if the function returns RESOLV_CACHE_UNSUPPORTED, the client should
- *     perform a request normally, and *not* call _resolv_cache_add()
- *
- *     note that RESOLV_CACHE_UNSUPPORTED is also returned if the answer buffer
- *     is too short to accomodate the cached result.
- *
- *  - when network settings change, the cache must be flushed since the list
- *    of DNS servers probably changed. this is done by calling
- *    _resolv_cache_reset()
- *
- *    the parameter to this function must be an ever-increasing generation
- *    number corresponding to the current network settings state.
- *
- *    This is done because several threads could detect the same network
- *    settings change (but at different times) and will all end up calling the
- *    same function. Comparing with the last used generation number ensures
- *    that the cache is only flushed once per network change.
- */
-
-/* the name of an environment variable that will be checked the first time
- * this code is called if its value is "0", then the resolver cache is
- * disabled.
- */
-#define  CONFIG_ENV  "BIONIC_DNSCACHE"
-
-/* entries older than CONFIG_SECONDS seconds are always discarded.
- */
-#define  CONFIG_SECONDS    (60*10)    /* 10 minutes */
-
-/* default number of entries kept in the cache. This value has been
- * determined by browsing through various sites and counting the number
- * of corresponding requests. Keep in mind that our framework is currently
- * performing two requests per name lookup (one for IPv4, the other for IPv6)
- *
- *    www.google.com      4
- *    www.ysearch.com     6
- *    www.amazon.com      8
- *    www.nytimes.com     22
- *    www.espn.com        28
- *    www.msn.com         28
- *    www.lemonde.fr      35
- *
- * (determined in 2009-2-17 from Paris, France, results may vary depending
- *  on location)
- *
- * most high-level websites use lots of media/ad servers with different names
- * but these are generally reused when browsing through the site.
- *
- * As such, a value of 64 should be relatively comfortable at the moment.
- *
- * ******************************************
- * * NOTE - this has changed.
- * * 1) we've added IPv6 support so each dns query results in 2 responses
- * * 2) we've made this a system-wide cache, so the cost is less (it's not
- * *    duplicated in each process) and the need is greater (more processes
- * *    making different requests).
- * * Upping by 2x for IPv6
- * * Upping by another 5x for the centralized nature
- * *****************************************
- */
-#define  CONFIG_MAX_ENTRIES    64 * 2 * 5
-/* name of the system property that can be used to set the cache size */
-
-/****************************************************************************/
-/****************************************************************************/
-/*****                                                                  *****/
-/*****                                                                  *****/
-/*****                                                                  *****/
-/****************************************************************************/
-/****************************************************************************/
-
-/* set to 1 to debug cache operations */
-#define  DEBUG       0
-
-/* set to 1 to debug query data */
-#define  DEBUG_DATA  0
-
-#undef XLOG
-#if DEBUG
-#  include "private/libc_logging.h"
-#  define XLOG(...)  __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__)
-
-#include <stdio.h>
-#include <stdarg.h>
-
-/** BOUNDED BUFFER FORMATTING
- **/
-
-/* technical note:
- *
- *   the following debugging routines are used to append data to a bounded
- *   buffer they take two parameters that are:
- *
- *   - p : a pointer to the current cursor position in the buffer
- *         this value is initially set to the buffer's address.
- *
- *   - end : the address of the buffer's limit, i.e. of the first byte
- *           after the buffer. this address should never be touched.
- *
- *           IMPORTANT: it is assumed that end > buffer_address, i.e.
- *                      that the buffer is at least one byte.
- *
- *   the _bprint_() functions return the new value of 'p' after the data
- *   has been appended, and also ensure the following:
- *
- *   - the returned value will never be strictly greater than 'end'
- *
- *   - a return value equal to 'end' means that truncation occured
- *     (in which case, end[-1] will be set to 0)
- *
- *   - after returning from a _bprint_() function, the content of the buffer
- *     is always 0-terminated, even in the event of truncation.
- *
- *  these conventions allow you to call _bprint_ functions multiple times and
- *  only check for truncation at the end of the sequence, as in:
- *
- *     char  buff[1000], *p = buff, *end = p + sizeof(buff);
- *
- *     p = _bprint_c(p, end, '"');
- *     p = _bprint_s(p, end, my_string);
- *     p = _bprint_c(p, end, '"');
- *
- *     if (p >= end) {
- *        // buffer was too small
- *     }
- *
- *     printf( "%s", buff );
- */
-
-/* add a char to a bounded buffer */
-static char*
-_bprint_c( char*  p, char*  end, int  c )
-{
-    if (p < end) {
-        if (p+1 == end)
-            *p++ = 0;
-        else {
-            *p++ = (char) c;
-            *p   = 0;
-        }
-    }
-    return p;
-}
-
-/* add a sequence of bytes to a bounded buffer */
-static char*
-_bprint_b( char*  p, char*  end, const char*  buf, int  len )
-{
-    int  avail = end - p;
-
-    if (avail <= 0 || len <= 0)
-        return p;
-
-    if (avail > len)
-        avail = len;
-
-    memcpy( p, buf, avail );
-    p += avail;
-
-    if (p < end)
-        p[0] = 0;
-    else
-        end[-1] = 0;
-
-    return p;
-}
-
-/* add a string to a bounded buffer */
-static char*
-_bprint_s( char*  p, char*  end, const char*  str )
-{
-    return _bprint_b(p, end, str, strlen(str));
-}
-
-/* add a formatted string to a bounded buffer */
-static char*
-_bprint( char*  p, char*  end, const char*  format, ... )
-{
-    int      avail, n;
-    va_list  args;
-
-    avail = end - p;
-
-    if (avail <= 0)
-        return p;
-
-    va_start(args, format);
-    n = vsnprintf( p, avail, format, args);
-    va_end(args);
-
-    /* certain C libraries return -1 in case of truncation */
-    if (n < 0 || n > avail)
-        n = avail;
-
-    p += n;
-    /* certain C libraries do not zero-terminate in case of truncation */
-    if (p == end)
-        p[-1] = 0;
-
-    return p;
-}
-
-/* add a hex value to a bounded buffer, up to 8 digits */
-static char*
-_bprint_hex( char*  p, char*  end, unsigned  value, int  numDigits )
-{
-    char   text[sizeof(unsigned)*2];
-    int    nn = 0;
-
-    while (numDigits-- > 0) {
-        text[nn++] = "0123456789abcdef"[(value >> (numDigits*4)) & 15];
-    }
-    return _bprint_b(p, end, text, nn);
-}
-
-/* add the hexadecimal dump of some memory area to a bounded buffer */
-static char*
-_bprint_hexdump( char*  p, char*  end, const uint8_t*  data, int  datalen )
-{
-    int   lineSize = 16;
-
-    while (datalen > 0) {
-        int  avail = datalen;
-        int  nn;
-
-        if (avail > lineSize)
-            avail = lineSize;
-
-        for (nn = 0; nn < avail; nn++) {
-            if (nn > 0)
-                p = _bprint_c(p, end, ' ');
-            p = _bprint_hex(p, end, data[nn], 2);
-        }
-        for ( ; nn < lineSize; nn++ ) {
-            p = _bprint_s(p, end, "   ");
-        }
-        p = _bprint_s(p, end, "  ");
-
-        for (nn = 0; nn < avail; nn++) {
-            int  c = data[nn];
-
-            if (c < 32 || c > 127)
-                c = '.';
-
-            p = _bprint_c(p, end, c);
-        }
-        p = _bprint_c(p, end, '\n');
-
-        data    += avail;
-        datalen -= avail;
-    }
-    return p;
-}
-
-/* dump the content of a query of packet to the log */
-static void
-XLOG_BYTES( const void*  base, int  len )
-{
-    char  buff[1024];
-    char*  p = buff, *end = p + sizeof(buff);
-
-    p = _bprint_hexdump(p, end, base, len);
-    XLOG("%s",buff);
-}
-
-#else /* !DEBUG */
-#  define  XLOG(...)        ((void)0)
-#  define  XLOG_BYTES(a,b)  ((void)0)
-#endif
-
-static time_t
-_time_now( void )
-{
-    struct timeval  tv;
-
-    gettimeofday( &tv, NULL );
-    return tv.tv_sec;
-}
-
-/* reminder: the general format of a DNS packet is the following:
- *
- *    HEADER  (12 bytes)
- *    QUESTION  (variable)
- *    ANSWER (variable)
- *    AUTHORITY (variable)
- *    ADDITIONNAL (variable)
- *
- * the HEADER is made of:
- *
- *   ID     : 16 : 16-bit unique query identification field
- *
- *   QR     :  1 : set to 0 for queries, and 1 for responses
- *   Opcode :  4 : set to 0 for queries
- *   AA     :  1 : set to 0 for queries
- *   TC     :  1 : truncation flag, will be set to 0 in queries
- *   RD     :  1 : recursion desired
- *
- *   RA     :  1 : recursion available (0 in queries)
- *   Z      :  3 : three reserved zero bits
- *   RCODE  :  4 : response code (always 0=NOERROR in queries)
- *
- *   QDCount: 16 : question count
- *   ANCount: 16 : Answer count (0 in queries)
- *   NSCount: 16: Authority Record count (0 in queries)
- *   ARCount: 16: Additionnal Record count (0 in queries)
- *
- * the QUESTION is made of QDCount Question Record (QRs)
- * the ANSWER is made of ANCount RRs
- * the AUTHORITY is made of NSCount RRs
- * the ADDITIONNAL is made of ARCount RRs
- *
- * Each Question Record (QR) is made of:
- *
- *   QNAME   : variable : Query DNS NAME
- *   TYPE    : 16       : type of query (A=1, PTR=12, MX=15, AAAA=28, ALL=255)
- *   CLASS   : 16       : class of query (IN=1)
- *
- * Each Resource Record (RR) is made of:
- *
- *   NAME    : variable : DNS NAME
- *   TYPE    : 16       : type of query (A=1, PTR=12, MX=15, AAAA=28, ALL=255)
- *   CLASS   : 16       : class of query (IN=1)
- *   TTL     : 32       : seconds to cache this RR (0=none)
- *   RDLENGTH: 16       : size of RDDATA in bytes
- *   RDDATA  : variable : RR data (depends on TYPE)
- *
- * Each QNAME contains a domain name encoded as a sequence of 'labels'
- * terminated by a zero. Each label has the following format:
- *
- *    LEN  : 8     : lenght of label (MUST be < 64)
- *    NAME : 8*LEN : label length (must exclude dots)
- *
- * A value of 0 in the encoding is interpreted as the 'root' domain and
- * terminates the encoding. So 'www.android.com' will be encoded as:
- *
- *   <3>www<7>android<3>com<0>
- *
- * Where <n> represents the byte with value 'n'
- *
- * Each NAME reflects the QNAME of the question, but has a slightly more
- * complex encoding in order to provide message compression. This is achieved
- * by using a 2-byte pointer, with format:
- *
- *    TYPE   : 2  : 0b11 to indicate a pointer, 0b01 and 0b10 are reserved
- *    OFFSET : 14 : offset to another part of the DNS packet
- *
- * The offset is relative to the start of the DNS packet and must point
- * A pointer terminates the encoding.
- *
- * The NAME can be encoded in one of the following formats:
- *
- *   - a sequence of simple labels terminated by 0 (like QNAMEs)
- *   - a single pointer
- *   - a sequence of simple labels terminated by a pointer
- *
- * A pointer shall always point to either a pointer of a sequence of
- * labels (which can themselves be terminated by either a 0 or a pointer)
- *
- * The expanded length of a given domain name should not exceed 255 bytes.
- *
- * NOTE: we don't parse the answer packets, so don't need to deal with NAME
- *       records, only QNAMEs.
- */
-
-#define  DNS_HEADER_SIZE  12
-
-#define  DNS_TYPE_A   "\00\01"   /* big-endian decimal 1 */
-#define  DNS_TYPE_PTR "\00\014"  /* big-endian decimal 12 */
-#define  DNS_TYPE_MX  "\00\017"  /* big-endian decimal 15 */
-#define  DNS_TYPE_AAAA "\00\034" /* big-endian decimal 28 */
-#define  DNS_TYPE_ALL "\00\0377" /* big-endian decimal 255 */
-
-#define  DNS_CLASS_IN "\00\01"   /* big-endian decimal 1 */
-
-typedef struct {
-    const uint8_t*  base;
-    const uint8_t*  end;
-    const uint8_t*  cursor;
-} DnsPacket;
-
-static void
-_dnsPacket_init( DnsPacket*  packet, const uint8_t*  buff, int  bufflen )
-{
-    packet->base   = buff;
-    packet->end    = buff + bufflen;
-    packet->cursor = buff;
-}
-
-static void
-_dnsPacket_rewind( DnsPacket*  packet )
-{
-    packet->cursor = packet->base;
-}
-
-static void
-_dnsPacket_skip( DnsPacket*  packet, int  count )
-{
-    const uint8_t*  p = packet->cursor + count;
-
-    if (p > packet->end)
-        p = packet->end;
-
-    packet->cursor = p;
-}
-
-static int
-_dnsPacket_readInt16( DnsPacket*  packet )
-{
-    const uint8_t*  p = packet->cursor;
-
-    if (p+2 > packet->end)
-        return -1;
-
-    packet->cursor = p+2;
-    return (p[0]<< 8) | p[1];
-}
-
-/** QUERY CHECKING
- **/
-
-/* check bytes in a dns packet. returns 1 on success, 0 on failure.
- * the cursor is only advanced in the case of success
- */
-static int
-_dnsPacket_checkBytes( DnsPacket*  packet, int  numBytes, const void*  bytes )
-{
-    const uint8_t*  p = packet->cursor;
-
-    if (p + numBytes > packet->end)
-        return 0;
-
-    if (memcmp(p, bytes, numBytes) != 0)
-        return 0;
-
-    packet->cursor = p + numBytes;
-    return 1;
-}
-
-/* parse and skip a given QNAME stored in a query packet,
- * from the current cursor position. returns 1 on success,
- * or 0 for malformed data.
- */
-static int
-_dnsPacket_checkQName( DnsPacket*  packet )
-{
-    const uint8_t*  p   = packet->cursor;
-    const uint8_t*  end = packet->end;
-
-    for (;;) {
-        int  c;
-
-        if (p >= end)
-            break;
-
-        c = *p++;
-
-        if (c == 0) {
-            packet->cursor = p;
-            return 1;
-        }
-
-        /* we don't expect label compression in QNAMEs */
-        if (c >= 64)
-            break;
-
-        p += c;
-        /* we rely on the bound check at the start
-         * of the loop here */
-    }
-    /* malformed data */
-    XLOG("malformed QNAME");
-    return 0;
-}
-
-/* parse and skip a given QR stored in a packet.
- * returns 1 on success, and 0 on failure
- */
-static int
-_dnsPacket_checkQR( DnsPacket*  packet )
-{
-    if (!_dnsPacket_checkQName(packet))
-        return 0;
-
-    /* TYPE must be one of the things we support */
-    if (!_dnsPacket_checkBytes(packet, 2, DNS_TYPE_A) &&
-        !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_PTR) &&
-        !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_MX) &&
-        !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_AAAA) &&
-        !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_ALL))
-    {
-        XLOG("unsupported TYPE");
-        return 0;
-    }
-    /* CLASS must be IN */
-    if (!_dnsPacket_checkBytes(packet, 2, DNS_CLASS_IN)) {
-        XLOG("unsupported CLASS");
-        return 0;
-    }
-
-    return 1;
-}
-
-/* check the header of a DNS Query packet, return 1 if it is one
- * type of query we can cache, or 0 otherwise
- */
-static int
-_dnsPacket_checkQuery( DnsPacket*  packet )
-{
-    const uint8_t*  p = packet->base;
-    int             qdCount, anCount, dnCount, arCount;
-
-    if (p + DNS_HEADER_SIZE > packet->end) {
-        XLOG("query packet too small");
-        return 0;
-    }
-
-    /* QR must be set to 0, opcode must be 0 and AA must be 0 */
-    /* RA, Z, and RCODE must be 0 */
-    if ((p[2] & 0xFC) != 0 || p[3] != 0) {
-        XLOG("query packet flags unsupported");
-        return 0;
-    }
-
-    /* Note that we ignore the TC and RD bits here for the
-     * following reasons:
-     *
-     * - there is no point for a query packet sent to a server
-     *   to have the TC bit set, but the implementation might
-     *   set the bit in the query buffer for its own needs
-     *   between a _resolv_cache_lookup and a
-     *   _resolv_cache_add. We should not freak out if this
-     *   is the case.
-     *
-     * - we consider that the result from a RD=0 or a RD=1
-     *   query might be different, hence that the RD bit
-     *   should be used to differentiate cached result.
-     *
-     *   this implies that RD is checked when hashing or
-     *   comparing query packets, but not TC
-     */
-
-    /* ANCOUNT, DNCOUNT and ARCOUNT must be 0 */
-    qdCount = (p[4] << 8) | p[5];
-    anCount = (p[6] << 8) | p[7];
-    dnCount = (p[8] << 8) | p[9];
-    arCount = (p[10]<< 8) | p[11];
-
-    if (anCount != 0 || dnCount != 0 || arCount != 0) {
-        XLOG("query packet contains non-query records");
-        return 0;
-    }
-
-    if (qdCount == 0) {
-        XLOG("query packet doesn't contain query record");
-        return 0;
-    }
-
-    /* Check QDCOUNT QRs */
-    packet->cursor = p + DNS_HEADER_SIZE;
-
-    for (;qdCount > 0; qdCount--)
-        if (!_dnsPacket_checkQR(packet))
-            return 0;
-
-    return 1;
-}
-
-/** QUERY DEBUGGING
- **/
-#if DEBUG
-static char*
-_dnsPacket_bprintQName(DnsPacket*  packet, char*  bp, char*  bend)
-{
-    const uint8_t*  p   = packet->cursor;
-    const uint8_t*  end = packet->end;
-    int             first = 1;
-
-    for (;;) {
-        int  c;
-
-        if (p >= end)
-            break;
-
-        c = *p++;
-
-        if (c == 0) {
-            packet->cursor = p;
-            return bp;
-        }
-
-        /* we don't expect label compression in QNAMEs */
-        if (c >= 64)
-            break;
-
-        if (first)
-            first = 0;
-        else
-            bp = _bprint_c(bp, bend, '.');
-
-        bp = _bprint_b(bp, bend, (const char*)p, c);
-
-        p += c;
-        /* we rely on the bound check at the start
-         * of the loop here */
-    }
-    /* malformed data */
-    bp = _bprint_s(bp, bend, "<MALFORMED>");
-    return bp;
-}
-
-static char*
-_dnsPacket_bprintQR(DnsPacket*  packet, char*  p, char*  end)
-{
-#define  QQ(x)   { DNS_TYPE_##x, #x }
-    static const struct {
-        const char*  typeBytes;
-        const char*  typeString;
-    } qTypes[] =
-    {
-        QQ(A), QQ(PTR), QQ(MX), QQ(AAAA), QQ(ALL),
-        { NULL, NULL }
-    };
-    int          nn;
-    const char*  typeString = NULL;
-
-    /* dump QNAME */
-    p = _dnsPacket_bprintQName(packet, p, end);
-
-    /* dump TYPE */
-    p = _bprint_s(p, end, " (");
-
-    for (nn = 0; qTypes[nn].typeBytes != NULL; nn++) {
-        if (_dnsPacket_checkBytes(packet, 2, qTypes[nn].typeBytes)) {
-            typeString = qTypes[nn].typeString;
-            break;
-        }
-    }
-
-    if (typeString != NULL)
-        p = _bprint_s(p, end, typeString);
-    else {
-        int  typeCode = _dnsPacket_readInt16(packet);
-        p = _bprint(p, end, "UNKNOWN-%d", typeCode);
-    }
-
-    p = _bprint_c(p, end, ')');
-
-    /* skip CLASS */
-    _dnsPacket_skip(packet, 2);
-    return p;
-}
-
-/* this function assumes the packet has already been checked */
-static char*
-_dnsPacket_bprintQuery( DnsPacket*  packet, char*  p, char*  end )
-{
-    int   qdCount;
-
-    if (packet->base[2] & 0x1) {
-        p = _bprint_s(p, end, "RECURSIVE ");
-    }
-
-    _dnsPacket_skip(packet, 4);
-    qdCount = _dnsPacket_readInt16(packet);
-    _dnsPacket_skip(packet, 6);
-
-    for ( ; qdCount > 0; qdCount-- ) {
-        p = _dnsPacket_bprintQR(packet, p, end);
-    }
-    return p;
-}
-#endif
-
-
-/** QUERY HASHING SUPPORT
- **
- ** THE FOLLOWING CODE ASSUMES THAT THE INPUT PACKET HAS ALREADY
- ** BEEN SUCCESFULLY CHECKED.
- **/
-
-/* use 32-bit FNV hash function */
-#define  FNV_MULT   16777619U
-#define  FNV_BASIS  2166136261U
-
-static unsigned
-_dnsPacket_hashBytes( DnsPacket*  packet, int  numBytes, unsigned  hash )
-{
-    const uint8_t*  p   = packet->cursor;
-    const uint8_t*  end = packet->end;
-
-    while (numBytes > 0 && p < end) {
-        hash = hash*FNV_MULT ^ *p++;
-    }
-    packet->cursor = p;
-    return hash;
-}
-
-
-static unsigned
-_dnsPacket_hashQName( DnsPacket*  packet, unsigned  hash )
-{
-    const uint8_t*  p   = packet->cursor;
-    const uint8_t*  end = packet->end;
-
-    for (;;) {
-        int  c;
-
-        if (p >= end) {  /* should not happen */
-            XLOG("%s: INTERNAL_ERROR: read-overflow !!\n", __FUNCTION__);
-            break;
-        }
-
-        c = *p++;
-
-        if (c == 0)
-            break;
-
-        if (c >= 64) {
-            XLOG("%s: INTERNAL_ERROR: malformed domain !!\n", __FUNCTION__);
-            break;
-        }
-        if (p + c >= end) {
-            XLOG("%s: INTERNAL_ERROR: simple label read-overflow !!\n",
-                    __FUNCTION__);
-            break;
-        }
-        while (c > 0) {
-            hash = hash*FNV_MULT ^ *p++;
-            c   -= 1;
-        }
-    }
-    packet->cursor = p;
-    return hash;
-}
-
-static unsigned
-_dnsPacket_hashQR( DnsPacket*  packet, unsigned  hash )
-{
-    hash = _dnsPacket_hashQName(packet, hash);
-    hash = _dnsPacket_hashBytes(packet, 4, hash); /* TYPE and CLASS */
-    return hash;
-}
-
-static unsigned
-_dnsPacket_hashQuery( DnsPacket*  packet )
-{
-    unsigned  hash = FNV_BASIS;
-    int       count;
-    _dnsPacket_rewind(packet);
-
-    /* we ignore the TC bit for reasons explained in
-     * _dnsPacket_checkQuery().
-     *
-     * however we hash the RD bit to differentiate
-     * between answers for recursive and non-recursive
-     * queries.
-     */
-    hash = hash*FNV_MULT ^ (packet->base[2] & 1);
-
-    /* assume: other flags are 0 */
-    _dnsPacket_skip(packet, 4);
-
-    /* read QDCOUNT */
-    count = _dnsPacket_readInt16(packet);
-
-    /* assume: ANcount, NScount, ARcount are 0 */
-    _dnsPacket_skip(packet, 6);
-
-    /* hash QDCOUNT QRs */
-    for ( ; count > 0; count-- )
-        hash = _dnsPacket_hashQR(packet, hash);
-
-    return hash;
-}
-
-
-/** QUERY COMPARISON
- **
- ** THE FOLLOWING CODE ASSUMES THAT THE INPUT PACKETS HAVE ALREADY
- ** BEEN SUCCESFULLY CHECKED.
- **/
-
-static int
-_dnsPacket_isEqualDomainName( DnsPacket*  pack1, DnsPacket*  pack2 )
-{
-    const uint8_t*  p1   = pack1->cursor;
-    const uint8_t*  end1 = pack1->end;
-    const uint8_t*  p2   = pack2->cursor;
-    const uint8_t*  end2 = pack2->end;
-
-    for (;;) {
-        int  c1, c2;
-
-        if (p1 >= end1 || p2 >= end2) {
-            XLOG("%s: INTERNAL_ERROR: read-overflow !!\n", __FUNCTION__);
-            break;
-        }
-        c1 = *p1++;
-        c2 = *p2++;
-        if (c1 != c2)
-            break;
-
-        if (c1 == 0) {
-            pack1->cursor = p1;
-            pack2->cursor = p2;
-            return 1;
-        }
-        if (c1 >= 64) {
-            XLOG("%s: INTERNAL_ERROR: malformed domain !!\n", __FUNCTION__);
-            break;
-        }
-        if ((p1+c1 > end1) || (p2+c1 > end2)) {
-            XLOG("%s: INTERNAL_ERROR: simple label read-overflow !!\n",
-                    __FUNCTION__);
-            break;
-        }
-        if (memcmp(p1, p2, c1) != 0)
-            break;
-        p1 += c1;
-        p2 += c1;
-        /* we rely on the bound checks at the start of the loop */
-    }
-    /* not the same, or one is malformed */
-    XLOG("different DN");
-    return 0;
-}
-
-static int
-_dnsPacket_isEqualBytes( DnsPacket*  pack1, DnsPacket*  pack2, int  numBytes )
-{
-    const uint8_t*  p1 = pack1->cursor;
-    const uint8_t*  p2 = pack2->cursor;
-
-    if ( p1 + numBytes > pack1->end || p2 + numBytes > pack2->end )
-        return 0;
-
-    if ( memcmp(p1, p2, numBytes) != 0 )
-        return 0;
-
-    pack1->cursor += numBytes;
-    pack2->cursor += numBytes;
-    return 1;
-}
-
-static int
-_dnsPacket_isEqualQR( DnsPacket*  pack1, DnsPacket*  pack2 )
-{
-    /* compare domain name encoding + TYPE + CLASS */
-    if ( !_dnsPacket_isEqualDomainName(pack1, pack2) ||
-         !_dnsPacket_isEqualBytes(pack1, pack2, 2+2) )
-        return 0;
-
-    return 1;
-}
-
-static int
-_dnsPacket_isEqualQuery( DnsPacket*  pack1, DnsPacket*  pack2 )
-{
-    int  count1, count2;
-
-    /* compare the headers, ignore most fields */
-    _dnsPacket_rewind(pack1);
-    _dnsPacket_rewind(pack2);
-
-    /* compare RD, ignore TC, see comment in _dnsPacket_checkQuery */
-    if ((pack1->base[2] & 1) != (pack2->base[2] & 1)) {
-        XLOG("different RD");
-        return 0;
-    }
-
-    /* assume: other flags are all 0 */
-    _dnsPacket_skip(pack1, 4);
-    _dnsPacket_skip(pack2, 4);
-
-    /* compare QDCOUNT */
-    count1 = _dnsPacket_readInt16(pack1);
-    count2 = _dnsPacket_readInt16(pack2);
-    if (count1 != count2 || count1 < 0) {
-        XLOG("different QDCOUNT");
-        return 0;
-    }
-
-    /* assume: ANcount, NScount and ARcount are all 0 */
-    _dnsPacket_skip(pack1, 6);
-    _dnsPacket_skip(pack2, 6);
-
-    /* compare the QDCOUNT QRs */
-    for ( ; count1 > 0; count1-- ) {
-        if (!_dnsPacket_isEqualQR(pack1, pack2)) {
-            XLOG("different QR");
-            return 0;
-        }
-    }
-    return 1;
-}
-
-/****************************************************************************/
-/****************************************************************************/
-/*****                                                                  *****/
-/*****                                                                  *****/
-/*****                                                                  *****/
-/****************************************************************************/
-/****************************************************************************/
-
-/* cache entry. for simplicity, 'hash' and 'hlink' are inlined in this
- * structure though they are conceptually part of the hash table.
- *
- * similarly, mru_next and mru_prev are part of the global MRU list
- */
-typedef struct Entry {
-    unsigned int     hash;   /* hash value */
-    struct Entry*    hlink;  /* next in collision chain */
-    struct Entry*    mru_prev;
-    struct Entry*    mru_next;
-
-    const uint8_t*   query;
-    int              querylen;
-    const uint8_t*   answer;
-    int              answerlen;
-    time_t           expires;   /* time_t when the entry isn't valid any more */
-    int              id;        /* for debugging purpose */
-} Entry;
-
-/**
- * Find the TTL for a negative DNS result.  This is defined as the minimum
- * of the SOA records TTL and the MINIMUM-TTL field (RFC-2308).
- *
- * Return 0 if not found.
- */
-static u_long
-answer_getNegativeTTL(ns_msg handle) {
-    int n, nscount;
-    u_long result = 0;
-    ns_rr rr;
-
-    nscount = ns_msg_count(handle, ns_s_ns);
-    for (n = 0; n < nscount; n++) {
-        if ((ns_parserr(&handle, ns_s_ns, n, &rr) == 0) && (ns_rr_type(rr) == ns_t_soa)) {
-            const u_char *rdata = ns_rr_rdata(rr); // find the data
-            const u_char *edata = rdata + ns_rr_rdlen(rr); // add the len to find the end
-            int len;
-            u_long ttl, rec_result = ns_rr_ttl(rr);
-
-            // find the MINIMUM-TTL field from the blob of binary data for this record
-            // skip the server name
-            len = dn_skipname(rdata, edata);
-            if (len == -1) continue; // error skipping
-            rdata += len;
-
-            // skip the admin name
-            len = dn_skipname(rdata, edata);
-            if (len == -1) continue; // error skipping
-            rdata += len;
-
-            if (edata - rdata != 5*NS_INT32SZ) continue;
-            // skip: serial number + refresh interval + retry interval + expiry
-            rdata += NS_INT32SZ * 4;
-            // finally read the MINIMUM TTL
-            ttl = ns_get32(rdata);
-            if (ttl < rec_result) {
-                rec_result = ttl;
-            }
-            // Now that the record is read successfully, apply the new min TTL
-            if (n == 0 || rec_result < result) {
-                result = rec_result;
-            }
-        }
-    }
-    return result;
-}
-
-/**
- * Parse the answer records and find the appropriate
- * smallest TTL among the records.  This might be from
- * the answer records if found or from the SOA record
- * if it's a negative result.
- *
- * The returned TTL is the number of seconds to
- * keep the answer in the cache.
- *
- * In case of parse error zero (0) is returned which
- * indicates that the answer shall not be cached.
- */
-static u_long
-answer_getTTL(const void* answer, int answerlen)
-{
-    ns_msg handle;
-    int ancount, n;
-    u_long result, ttl;
-    ns_rr rr;
-
-    result = 0;
-    if (ns_initparse(answer, answerlen, &handle) >= 0) {
-        // get number of answer records
-        ancount = ns_msg_count(handle, ns_s_an);
-
-        if (ancount == 0) {
-            // a response with no answers?  Cache this negative result.
-            result = answer_getNegativeTTL(handle);
-        } else {
-            for (n = 0; n < ancount; n++) {
-                if (ns_parserr(&handle, ns_s_an, n, &rr) == 0) {
-                    ttl = ns_rr_ttl(rr);
-                    if (n == 0 || ttl < result) {
-                        result = ttl;
-                    }
-                } else {
-                    XLOG("ns_parserr failed ancount no = %d. errno = %s\n", n, strerror(errno));
-                }
-            }
-        }
-    } else {
-        XLOG("ns_parserr failed. %s\n", strerror(errno));
-    }
-
-    XLOG("TTL = %d\n", result);
-
-    return result;
-}
-
-static void
-entry_free( Entry*  e )
-{
-    /* everything is allocated in a single memory block */
-    if (e) {
-        free(e);
-    }
-}
-
-static __inline__ void
-entry_mru_remove( Entry*  e )
-{
-    e->mru_prev->mru_next = e->mru_next;
-    e->mru_next->mru_prev = e->mru_prev;
-}
-
-static __inline__ void
-entry_mru_add( Entry*  e, Entry*  list )
-{
-    Entry*  first = list->mru_next;
-
-    e->mru_next = first;
-    e->mru_prev = list;
-
-    list->mru_next  = e;
-    first->mru_prev = e;
-}
-
-/* compute the hash of a given entry, this is a hash of most
- * data in the query (key) */
-static unsigned
-entry_hash( const Entry*  e )
-{
-    DnsPacket  pack[1];
-
-    _dnsPacket_init(pack, e->query, e->querylen);
-    return _dnsPacket_hashQuery(pack);
-}
-
-/* initialize an Entry as a search key, this also checks the input query packet
- * returns 1 on success, or 0 in case of unsupported/malformed data */
-static int
-entry_init_key( Entry*  e, const void*  query, int  querylen )
-{
-    DnsPacket  pack[1];
-
-    memset(e, 0, sizeof(*e));
-
-    e->query    = query;
-    e->querylen = querylen;
-    e->hash     = entry_hash(e);
-
-    _dnsPacket_init(pack, query, querylen);
-
-    return _dnsPacket_checkQuery(pack);
-}
-
-/* allocate a new entry as a cache node */
-static Entry*
-entry_alloc( const Entry*  init, const void*  answer, int  answerlen )
-{
-    Entry*  e;
-    int     size;
-
-    size = sizeof(*e) + init->querylen + answerlen;
-    e    = calloc(size, 1);
-    if (e == NULL)
-        return e;
-
-    e->hash     = init->hash;
-    e->query    = (const uint8_t*)(e+1);
-    e->querylen = init->querylen;
-
-    memcpy( (char*)e->query, init->query, e->querylen );
-
-    e->answer    = e->query + e->querylen;
-    e->answerlen = answerlen;
-
-    memcpy( (char*)e->answer, answer, e->answerlen );
-
-    return e;
-}
-
-static int
-entry_equals( const Entry*  e1, const Entry*  e2 )
-{
-    DnsPacket  pack1[1], pack2[1];
-
-    if (e1->querylen != e2->querylen) {
-        return 0;
-    }
-    _dnsPacket_init(pack1, e1->query, e1->querylen);
-    _dnsPacket_init(pack2, e2->query, e2->querylen);
-
-    return _dnsPacket_isEqualQuery(pack1, pack2);
-}
-
-/****************************************************************************/
-/****************************************************************************/
-/*****                                                                  *****/
-/*****                                                                  *****/
-/*****                                                                  *****/
-/****************************************************************************/
-/****************************************************************************/
-
-/* We use a simple hash table with external collision lists
- * for simplicity, the hash-table fields 'hash' and 'hlink' are
- * inlined in the Entry structure.
- */
-
-/* Maximum time for a thread to wait for an pending request */
-#define PENDING_REQUEST_TIMEOUT 20;
-
-typedef struct pending_req_info {
-    unsigned int                hash;
-    pthread_cond_t              cond;
-    struct pending_req_info*    next;
-} PendingReqInfo;
-
-typedef struct resolv_cache {
-    int              max_entries;
-    int              num_entries;
-    Entry            mru_list;
-    pthread_mutex_t  lock;
-    unsigned         generation;
-    int              last_id;
-    Entry*           entries;
-    PendingReqInfo   pending_requests;
-} Cache;
-
-typedef struct resolv_cache_info {
-    char                        ifname[IF_NAMESIZE + 1];
-    struct in_addr              ifaddr;
-    Cache*                      cache;
-    struct resolv_cache_info*   next;
-    char*                       nameservers[MAXNS +1];
-    struct addrinfo*            nsaddrinfo[MAXNS + 1];
-    char                        defdname[256];
-    int                         dnsrch_offset[MAXDNSRCH+1];  // offsets into defdname
-} CacheInfo;
-
-typedef struct resolv_pidiface_info {
-    int                             pid;
-    char                            ifname[IF_NAMESIZE + 1];
-    struct resolv_pidiface_info*    next;
-} PidIfaceInfo;
-typedef struct resolv_uidiface_info {
-    int                             uid_start;
-    int                             uid_end;
-    char                            ifname[IF_NAMESIZE + 1];
-    struct resolv_uidiface_info*    next;
-} UidIfaceInfo;
-
-#define  HTABLE_VALID(x)  ((x) != NULL && (x) != HTABLE_DELETED)
-
-static void
-_cache_flush_pending_requests_locked( struct resolv_cache* cache )
-{
-    struct pending_req_info *ri, *tmp;
-    if (cache) {
-        ri = cache->pending_requests.next;
-
-        while (ri) {
-            tmp = ri;
-            ri = ri->next;
-            pthread_cond_broadcast(&tmp->cond);
-
-            pthread_cond_destroy(&tmp->cond);
-            free(tmp);
-        }
-
-        cache->pending_requests.next = NULL;
-    }
-}
-
-/* return 0 if no pending request is found matching the key
- * if a matching request is found the calling thread will wait
- * and return 1 when released */
-static int
-_cache_check_pending_request_locked( struct resolv_cache* cache, Entry* key )
-{
-    struct pending_req_info *ri, *prev;
-    int exist = 0;
-
-    if (cache && key) {
-        ri = cache->pending_requests.next;
-        prev = &cache->pending_requests;
-        while (ri) {
-            if (ri->hash == key->hash) {
-                exist = 1;
-                break;
-            }
-            prev = ri;
-            ri = ri->next;
-        }
-
-        if (!exist) {
-            ri = calloc(1, sizeof(struct pending_req_info));
-            if (ri) {
-                ri->hash = key->hash;
-                pthread_cond_init(&ri->cond, NULL);
-                prev->next = ri;
-            }
-        } else {
-            struct timespec ts = {0,0};
-            XLOG("Waiting for previous request");
-            ts.tv_sec = _time_now() + PENDING_REQUEST_TIMEOUT;
-            pthread_cond_timedwait(&ri->cond, &cache->lock, &ts);
-        }
-    }
-
-    return exist;
-}
-
-/* notify any waiting thread that waiting on a request
- * matching the key has been added to the cache */
-static void
-_cache_notify_waiting_tid_locked( struct resolv_cache* cache, Entry* key )
-{
-    struct pending_req_info *ri, *prev;
-
-    if (cache && key) {
-        ri = cache->pending_requests.next;
-        prev = &cache->pending_requests;
-        while (ri) {
-            if (ri->hash == key->hash) {
-                pthread_cond_broadcast(&ri->cond);
-                break;
-            }
-            prev = ri;
-            ri = ri->next;
-        }
-
-        // remove item from list and destroy
-        if (ri) {
-            prev->next = ri->next;
-            pthread_cond_destroy(&ri->cond);
-            free(ri);
-        }
-    }
-}
-
-/* notify the cache that the query failed */
-void
-_resolv_cache_query_failed( struct resolv_cache* cache,
-                   const void* query,
-                   int         querylen)
-{
-    Entry    key[1];
-
-    if (cache && entry_init_key(key, query, querylen)) {
-        pthread_mutex_lock(&cache->lock);
-        _cache_notify_waiting_tid_locked(cache, key);
-        pthread_mutex_unlock(&cache->lock);
-    }
-}
-
-static void
-_cache_flush_locked( Cache*  cache )
-{
-    int     nn;
-
-    for (nn = 0; nn < cache->max_entries; nn++)
-    {
-        Entry**  pnode = (Entry**) &cache->entries[nn];
-
-        while (*pnode != NULL) {
-            Entry*  node = *pnode;
-            *pnode = node->hlink;
-            entry_free(node);
-        }
-    }
-
-    // flush pending request
-    _cache_flush_pending_requests_locked(cache);
-
-    cache->mru_list.mru_next = cache->mru_list.mru_prev = &cache->mru_list;
-    cache->num_entries       = 0;
-    cache->last_id           = 0;
-
-    XLOG("*************************\n"
-         "*** DNS CACHE FLUSHED ***\n"
-         "*************************");
-}
-
-static int
-_res_cache_get_max_entries( void )
-{
-    int cache_size = CONFIG_MAX_ENTRIES;
-
-    const char* cache_mode = getenv("ANDROID_DNS_MODE");
-    if (cache_mode == NULL || strcmp(cache_mode, "local") != 0) {
-        // Don't use the cache in local mode. This is used by the proxy itself.
-        cache_size = 0;
-    }
-
-    XLOG("cache size: %d", cache_size);
-    return cache_size;
-}
-
-static struct resolv_cache*
-_resolv_cache_create( void )
-{
-    struct resolv_cache*  cache;
-
-    cache = calloc(sizeof(*cache), 1);
-    if (cache) {
-        cache->max_entries = _res_cache_get_max_entries();
-        cache->entries = calloc(sizeof(*cache->entries), cache->max_entries);
-        if (cache->entries) {
-            cache->generation = ~0U;
-            pthread_mutex_init( &cache->lock, NULL );
-            cache->mru_list.mru_prev = cache->mru_list.mru_next = &cache->mru_list;
-            XLOG("%s: cache created\n", __FUNCTION__);
-        } else {
-            free(cache);
-            cache = NULL;
-        }
-    }
-    return cache;
-}
-
-
-#if DEBUG
-static void
-_dump_query( const uint8_t*  query, int  querylen )
-{
-    char       temp[256], *p=temp, *end=p+sizeof(temp);
-    DnsPacket  pack[1];
-
-    _dnsPacket_init(pack, query, querylen);
-    p = _dnsPacket_bprintQuery(pack, p, end);
-    XLOG("QUERY: %s", temp);
-}
-
-static void
-_cache_dump_mru( Cache*  cache )
-{
-    char    temp[512], *p=temp, *end=p+sizeof(temp);
-    Entry*  e;
-
-    p = _bprint(temp, end, "MRU LIST (%2d): ", cache->num_entries);
-    for (e = cache->mru_list.mru_next; e != &cache->mru_list; e = e->mru_next)
-        p = _bprint(p, end, " %d", e->id);
-
-    XLOG("%s", temp);
-}
-
-static void
-_dump_answer(const void* answer, int answerlen)
-{
-    res_state statep;
-    FILE* fp;
-    char* buf;
-    int fileLen;
-
-    fp = fopen("/data/reslog.txt", "w+");
-    if (fp != NULL) {
-        statep = __res_get_state();
-
-        res_pquery(statep, answer, answerlen, fp);
-
-        //Get file length
-        fseek(fp, 0, SEEK_END);
-        fileLen=ftell(fp);
-        fseek(fp, 0, SEEK_SET);
-        buf = (char *)malloc(fileLen+1);
-        if (buf != NULL) {
-            //Read file contents into buffer
-            fread(buf, fileLen, 1, fp);
-            XLOG("%s\n", buf);
-            free(buf);
-        }
-        fclose(fp);
-        remove("/data/reslog.txt");
-    }
-    else {
-        errno = 0; // else debug is introducing error signals
-        XLOG("_dump_answer: can't open file\n");
-    }
-}
-#endif
-
-#if DEBUG
-#  define  XLOG_QUERY(q,len)   _dump_query((q), (len))
-#  define  XLOG_ANSWER(a, len) _dump_answer((a), (len))
-#else
-#  define  XLOG_QUERY(q,len)   ((void)0)
-#  define  XLOG_ANSWER(a,len)  ((void)0)
-#endif
-
-/* This function tries to find a key within the hash table
- * In case of success, it will return a *pointer* to the hashed key.
- * In case of failure, it will return a *pointer* to NULL
- *
- * So, the caller must check '*result' to check for success/failure.
- *
- * The main idea is that the result can later be used directly in
- * calls to _resolv_cache_add or _resolv_cache_remove as the 'lookup'
- * parameter. This makes the code simpler and avoids re-searching
- * for the key position in the htable.
- *
- * The result of a lookup_p is only valid until you alter the hash
- * table.
- */
-static Entry**
-_cache_lookup_p( Cache*   cache,
-                 Entry*   key )
-{
-    int      index = key->hash % cache->max_entries;
-    Entry**  pnode = (Entry**) &cache->entries[ index ];
-
-    while (*pnode != NULL) {
-        Entry*  node = *pnode;
-
-        if (node == NULL)
-            break;
-
-        if (node->hash == key->hash && entry_equals(node, key))
-            break;
-
-        pnode = &node->hlink;
-    }
-    return pnode;
-}
-
-/* Add a new entry to the hash table. 'lookup' must be the
- * result of an immediate previous failed _lookup_p() call
- * (i.e. with *lookup == NULL), and 'e' is the pointer to the
- * newly created entry
- */
-static void
-_cache_add_p( Cache*   cache,
-              Entry**  lookup,
-              Entry*   e )
-{
-    *lookup = e;
-    e->id = ++cache->last_id;
-    entry_mru_add(e, &cache->mru_list);
-    cache->num_entries += 1;
-
-    XLOG("%s: entry %d added (count=%d)", __FUNCTION__,
-         e->id, cache->num_entries);
-}
-
-/* Remove an existing entry from the hash table,
- * 'lookup' must be the result of an immediate previous
- * and succesful _lookup_p() call.
- */
-static void
-_cache_remove_p( Cache*   cache,
-                 Entry**  lookup )
-{
-    Entry*  e  = *lookup;
-
-    XLOG("%s: entry %d removed (count=%d)", __FUNCTION__,
-         e->id, cache->num_entries-1);
-
-    entry_mru_remove(e);
-    *lookup = e->hlink;
-    entry_free(e);
-    cache->num_entries -= 1;
-}
-
-/* Remove the oldest entry from the hash table.
- */
-static void
-_cache_remove_oldest( Cache*  cache )
-{
-    Entry*   oldest = cache->mru_list.mru_prev;
-    Entry**  lookup = _cache_lookup_p(cache, oldest);
-
-    if (*lookup == NULL) { /* should not happen */
-        XLOG("%s: OLDEST NOT IN HTABLE ?", __FUNCTION__);
-        return;
-    }
-    if (DEBUG) {
-        XLOG("Cache full - removing oldest");
-        XLOG_QUERY(oldest->query, oldest->querylen);
-    }
-    _cache_remove_p(cache, lookup);
-}
-
-/* Remove all expired entries from the hash table.
- */
-static void _cache_remove_expired(Cache* cache) {
-    Entry* e;
-    time_t now = _time_now();
-
-    for (e = cache->mru_list.mru_next; e != &cache->mru_list;) {
-        // Entry is old, remove
-        if (now >= e->expires) {
-            Entry** lookup = _cache_lookup_p(cache, e);
-            if (*lookup == NULL) { /* should not happen */
-                XLOG("%s: ENTRY NOT IN HTABLE ?", __FUNCTION__);
-                return;
-            }
-            e = e->mru_next;
-            _cache_remove_p(cache, lookup);
-        } else {
-            e = e->mru_next;
-        }
-    }
-}
-
-ResolvCacheStatus
-_resolv_cache_lookup( struct resolv_cache*  cache,
-                      const void*           query,
-                      int                   querylen,
-                      void*                 answer,
-                      int                   answersize,
-                      int                  *answerlen )
-{
-    Entry      key[1];
-    Entry**    lookup;
-    Entry*     e;
-    time_t     now;
-
-    ResolvCacheStatus  result = RESOLV_CACHE_NOTFOUND;
-
-    XLOG("%s: lookup", __FUNCTION__);
-    XLOG_QUERY(query, querylen);
-
-    /* we don't cache malformed queries */
-    if (!entry_init_key(key, query, querylen)) {
-        XLOG("%s: unsupported query", __FUNCTION__);
-        return RESOLV_CACHE_UNSUPPORTED;
-    }
-    /* lookup cache */
-    pthread_mutex_lock( &cache->lock );
-
-    /* see the description of _lookup_p to understand this.
-     * the function always return a non-NULL pointer.
-     */
-    lookup = _cache_lookup_p(cache, key);
-    e      = *lookup;
-
-    if (e == NULL) {
-        XLOG( "NOT IN CACHE");
-        // calling thread will wait if an outstanding request is found
-        // that matching this query
-        if (!_cache_check_pending_request_locked(cache, key)) {
-            goto Exit;
-        } else {
-            lookup = _cache_lookup_p(cache, key);
-            e = *lookup;
-            if (e == NULL) {
-                goto Exit;
-            }
-        }
-    }
-
-    now = _time_now();
-
-    /* remove stale entries here */
-    if (now >= e->expires) {
-        XLOG( " NOT IN CACHE (STALE ENTRY %p DISCARDED)", *lookup );
-        XLOG_QUERY(e->query, e->querylen);
-        _cache_remove_p(cache, lookup);
-        goto Exit;
-    }
-
-    *answerlen = e->answerlen;
-    if (e->answerlen > answersize) {
-        /* NOTE: we return UNSUPPORTED if the answer buffer is too short */
-        result = RESOLV_CACHE_UNSUPPORTED;
-        XLOG(" ANSWER TOO LONG");
-        goto Exit;
-    }
-
-    memcpy( answer, e->answer, e->answerlen );
-
-    /* bump up this entry to the top of the MRU list */
-    if (e != cache->mru_list.mru_next) {
-        entry_mru_remove( e );
-        entry_mru_add( e, &cache->mru_list );
-    }
-
-    XLOG( "FOUND IN CACHE entry=%p", e );
-    result = RESOLV_CACHE_FOUND;
-
-Exit:
-    pthread_mutex_unlock( &cache->lock );
-    return result;
-}
-
-
-void
-_resolv_cache_add( struct resolv_cache*  cache,
-                   const void*           query,
-                   int                   querylen,
-                   const void*           answer,
-                   int                   answerlen )
-{
-    Entry    key[1];
-    Entry*   e;
-    Entry**  lookup;
-    u_long   ttl;
-
-    /* don't assume that the query has already been cached
-     */
-    if (!entry_init_key( key, query, querylen )) {
-        XLOG( "%s: passed invalid query ?", __FUNCTION__);
-        return;
-    }
-
-    pthread_mutex_lock( &cache->lock );
-
-    XLOG( "%s: query:", __FUNCTION__ );
-    XLOG_QUERY(query,querylen);
-    XLOG_ANSWER(answer, answerlen);
-#if DEBUG_DATA
-    XLOG( "answer:");
-    XLOG_BYTES(answer,answerlen);
-#endif
-
-    lookup = _cache_lookup_p(cache, key);
-    e      = *lookup;
-
-    if (e != NULL) { /* should not happen */
-        XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
-             __FUNCTION__, e);
-        goto Exit;
-    }
-
-    if (cache->num_entries >= cache->max_entries) {
-        _cache_remove_expired(cache);
-        if (cache->num_entries >= cache->max_entries) {
-            _cache_remove_oldest(cache);
-        }
-        /* need to lookup again */
-        lookup = _cache_lookup_p(cache, key);
-        e      = *lookup;
-        if (e != NULL) {
-            XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
-                __FUNCTION__, e);
-            goto Exit;
-        }
-    }
-
-    ttl = answer_getTTL(answer, answerlen);
-    if (ttl > 0) {
-        e = entry_alloc(key, answer, answerlen);
-        if (e != NULL) {
-            e->expires = ttl + _time_now();
-            _cache_add_p(cache, lookup, e);
-        }
-    }
-#if DEBUG
-    _cache_dump_mru(cache);
-#endif
-Exit:
-    _cache_notify_waiting_tid_locked(cache, key);
-    pthread_mutex_unlock( &cache->lock );
-}
-
-/****************************************************************************/
-/****************************************************************************/
-/*****                                                                  *****/
-/*****                                                                  *****/
-/*****                                                                  *****/
-/****************************************************************************/
-/****************************************************************************/
-
-static pthread_once_t        _res_cache_once = PTHREAD_ONCE_INIT;
-
-// Head of the list of caches.  Protected by _res_cache_list_lock.
-static struct resolv_cache_info _res_cache_list;
-
-// List of pid iface pairs
-static struct resolv_pidiface_info _res_pidiface_list;
-
-// List of uid iface pairs
-static struct resolv_uidiface_info _res_uidiface_list;
-
-// name of the current default inteface
-static char            _res_default_ifname[IF_NAMESIZE + 1];
-
-// lock protecting everything in the _resolve_cache_info structs (next ptr, etc)
-static pthread_mutex_t _res_cache_list_lock;
-
-// lock protecting the _res_pid_iface_list
-static pthread_mutex_t _res_pidiface_list_lock;
-
-// lock protecting the _res_uidiface_list
-static pthread_mutex_t _res_uidiface_list_lock;
-
-/* lookup the default interface name */
-static char *_get_default_iface_locked();
-/* find the first cache that has an associated interface and return the name of the interface */
-static char* _find_any_iface_name_locked( void );
-
-/* insert resolv_cache_info into the list of resolv_cache_infos */
-static void _insert_cache_info_locked(struct resolv_cache_info* cache_info);
-/* creates a resolv_cache_info */
-static struct resolv_cache_info* _create_cache_info( void );
-/* gets cache associated with an interface name, or NULL if none exists */
-static struct resolv_cache* _find_named_cache_locked(const char* ifname);
-/* gets a resolv_cache_info associated with an interface name, or NULL if not found */
-static struct resolv_cache_info* _find_cache_info_locked(const char* ifname);
-/* look up the named cache, and creates one if needed */
-static struct resolv_cache* _get_res_cache_for_iface_locked(const char* ifname);
-/* empty the named cache */
-static void _flush_cache_for_iface_locked(const char* ifname);
-/* empty the nameservers set for the named cache */
-static void _free_nameservers_locked(struct resolv_cache_info* cache_info);
-/* lookup the namserver for the name interface */
-static int _get_nameserver_locked(const char* ifname, int n, char* addr, int addrLen);
-/* lookup the addr of the nameserver for the named interface */
-static struct addrinfo* _get_nameserver_addr_locked(const char* ifname, int n);
-/* lookup the inteface's address */
-static struct in_addr* _get_addr_locked(const char * ifname);
-/* return 1 if the provided list of name servers differs from the list of name servers
- * currently attached to the provided cache_info */
-static int _resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
-        const char** servers, int numservers);
-/* remove a resolv_pidiface_info structure from _res_pidiface_list */
-static void _remove_pidiface_info_locked(int pid);
-/* get a resolv_pidiface_info structure from _res_pidiface_list with a certain pid */
-static struct resolv_pidiface_info* _get_pid_iface_info_locked(int pid);
-
-/* remove a resolv_pidiface_info structure from _res_uidiface_list */
-static int _remove_uidiface_info_locked(const char* iface, int uid_start, int uid_end);
-/* get a resolv_uidiface_info structure from _res_uidiface_list with a certain uid */
-static struct resolv_uidiface_info* _get_uid_iface_info_locked(int uid);
-
-static void
-_res_cache_init(void)
-{
-    const char*  env = getenv(CONFIG_ENV);
-
-    if (env && atoi(env) == 0) {
-        /* the cache is disabled */
-        return;
-    }
-
-    memset(&_res_default_ifname, 0, sizeof(_res_default_ifname));
-    memset(&_res_cache_list, 0, sizeof(_res_cache_list));
-    memset(&_res_pidiface_list, 0, sizeof(_res_pidiface_list));
-    memset(&_res_uidiface_list, 0, sizeof(_res_uidiface_list));
-    pthread_mutex_init(&_res_cache_list_lock, NULL);
-    pthread_mutex_init(&_res_pidiface_list_lock, NULL);
-    pthread_mutex_init(&_res_uidiface_list_lock, NULL);
-}
-
-struct resolv_cache*
-__get_res_cache(const char* ifname)
-{
-    struct resolv_cache *cache;
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    char* iface;
-    if (ifname == NULL || ifname[0] == '\0') {
-        iface = _get_default_iface_locked();
-        if (iface[0] == '\0') {
-            char* tmp = _find_any_iface_name_locked();
-            if (tmp) {
-                iface = tmp;
-            }
-        }
-    } else {
-        iface = (char *) ifname;
-    }
-
-    cache = _get_res_cache_for_iface_locked(iface);
-
-    pthread_mutex_unlock(&_res_cache_list_lock);
-    XLOG("_get_res_cache: iface = %s, cache=%p\n", iface, cache);
-    return cache;
-}
-
-static struct resolv_cache*
-_get_res_cache_for_iface_locked(const char* ifname)
-{
-    if (ifname == NULL)
-        return NULL;
-
-    struct resolv_cache* cache = _find_named_cache_locked(ifname);
-    if (!cache) {
-        struct resolv_cache_info* cache_info = _create_cache_info();
-        if (cache_info) {
-            cache = _resolv_cache_create();
-            if (cache) {
-                int len = sizeof(cache_info->ifname);
-                cache_info->cache = cache;
-                strncpy(cache_info->ifname, ifname, len - 1);
-                cache_info->ifname[len - 1] = '\0';
-
-                _insert_cache_info_locked(cache_info);
-            } else {
-                free(cache_info);
-            }
-        }
-    }
-    return cache;
-}
-
-void
-_resolv_cache_reset(unsigned  generation)
-{
-    XLOG("%s: generation=%d", __FUNCTION__, generation);
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    char* ifname = _get_default_iface_locked();
-    // if default interface not set then use the first cache
-    // associated with an interface as the default one.
-    // Note: Copied the code from __get_res_cache since this
-    // method will be deleted/obsolete when cache per interface
-    // implemented all over
-    if (ifname[0] == '\0') {
-        struct resolv_cache_info* cache_info = _res_cache_list.next;
-        while (cache_info) {
-            if (cache_info->ifname[0] != '\0') {
-                ifname = cache_info->ifname;
-                break;
-            }
-
-            cache_info = cache_info->next;
-        }
-    }
-    struct resolv_cache* cache = _get_res_cache_for_iface_locked(ifname);
-
-    if (cache != NULL) {
-        pthread_mutex_lock( &cache->lock );
-        if (cache->generation != generation) {
-            _cache_flush_locked(cache);
-            cache->generation = generation;
-        }
-        pthread_mutex_unlock( &cache->lock );
-    }
-
-    pthread_mutex_unlock(&_res_cache_list_lock);
-}
-
-void
-_resolv_flush_cache_for_default_iface(void)
-{
-    char* ifname;
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    ifname = _get_default_iface_locked();
-    _flush_cache_for_iface_locked(ifname);
-
-    pthread_mutex_unlock(&_res_cache_list_lock);
-}
-
-void
-_resolv_flush_cache_for_iface(const char* ifname)
-{
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    _flush_cache_for_iface_locked(ifname);
-
-    pthread_mutex_unlock(&_res_cache_list_lock);
-}
-
-static void
-_flush_cache_for_iface_locked(const char* ifname)
-{
-    struct resolv_cache* cache = _find_named_cache_locked(ifname);
-    if (cache) {
-        pthread_mutex_lock(&cache->lock);
-        _cache_flush_locked(cache);
-        pthread_mutex_unlock(&cache->lock);
-    }
-}
-
-static struct resolv_cache_info*
-_create_cache_info(void)
-{
-    struct resolv_cache_info*  cache_info;
-
-    cache_info = calloc(sizeof(*cache_info), 1);
-    return cache_info;
-}
-
-static void
-_insert_cache_info_locked(struct resolv_cache_info* cache_info)
-{
-    struct resolv_cache_info* last;
-
-    for (last = &_res_cache_list; last->next; last = last->next);
-
-    last->next = cache_info;
-
-}
-
-static struct resolv_cache*
-_find_named_cache_locked(const char* ifname) {
-
-    struct resolv_cache_info* info = _find_cache_info_locked(ifname);
-
-    if (info != NULL) return info->cache;
-
-    return NULL;
-}
-
-static struct resolv_cache_info*
-_find_cache_info_locked(const char* ifname)
-{
-    if (ifname == NULL)
-        return NULL;
-
-    struct resolv_cache_info* cache_info = _res_cache_list.next;
-
-    while (cache_info) {
-        if (strcmp(cache_info->ifname, ifname) == 0) {
-            break;
-        }
-
-        cache_info = cache_info->next;
-    }
-    return cache_info;
-}
-
-static char*
-_get_default_iface_locked(void)
-{
-
-    char* iface = _res_default_ifname;
-
-    return iface;
-}
-
-static char*
-_find_any_iface_name_locked( void ) {
-    char* ifname = NULL;
-
-    struct resolv_cache_info* cache_info = _res_cache_list.next;
-    while (cache_info) {
-        if (cache_info->ifname[0] != '\0') {
-            ifname = cache_info->ifname;
-            break;
-        }
-
-        cache_info = cache_info->next;
-    }
-
-    return ifname;
-}
-
-void
-_resolv_set_default_iface(const char* ifname)
-{
-    XLOG("_resolv_set_default_if ifname %s\n",ifname);
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    int size = sizeof(_res_default_ifname);
-    memset(_res_default_ifname, 0, size);
-    strncpy(_res_default_ifname, ifname, size - 1);
-    _res_default_ifname[size - 1] = '\0';
-
-    pthread_mutex_unlock(&_res_cache_list_lock);
-}
-
-void
-_resolv_set_nameservers_for_iface(const char* ifname, const char** servers, int numservers,
-        const char *domains)
-{
-    int i, rt, index;
-    struct addrinfo hints;
-    char sbuf[NI_MAXSERV];
-    register char *cp;
-    int *offset;
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    // creates the cache if not created
-    _get_res_cache_for_iface_locked(ifname);
-
-    struct resolv_cache_info* cache_info = _find_cache_info_locked(ifname);
-
-    if (cache_info != NULL &&
-            !_resolv_is_nameservers_equal_locked(cache_info, servers, numservers)) {
-        // free current before adding new
-        _free_nameservers_locked(cache_info);
-
-        memset(&hints, 0, sizeof(hints));
-        hints.ai_family = PF_UNSPEC;
-        hints.ai_socktype = SOCK_DGRAM; /*dummy*/
-        hints.ai_flags = AI_NUMERICHOST;
-        sprintf(sbuf, "%u", NAMESERVER_PORT);
-
-        index = 0;
-        for (i = 0; i < numservers && i < MAXNS; i++) {
-            rt = getaddrinfo(servers[i], sbuf, &hints, &cache_info->nsaddrinfo[index]);
-            if (rt == 0) {
-                cache_info->nameservers[index] = strdup(servers[i]);
-                index++;
-                XLOG("_resolv_set_nameservers_for_iface: iface = %s, addr = %s\n",
-                        ifname, servers[i]);
-            } else {
-                cache_info->nsaddrinfo[index] = NULL;
-            }
-        }
-
-        // code moved from res_init.c, load_domain_search_list
-        strlcpy(cache_info->defdname, domains, sizeof(cache_info->defdname));
-        if ((cp = strchr(cache_info->defdname, '\n')) != NULL)
-            *cp = '\0';
-        cp = cache_info->defdname;
-        offset = cache_info->dnsrch_offset;
-        while (offset < cache_info->dnsrch_offset + MAXDNSRCH) {
-            while (*cp == ' ' || *cp == '\t') /* skip leading white space */
-                cp++;
-            if (*cp == '\0') /* stop if nothing more to do */
-                break;
-            *offset++ = cp - cache_info->defdname; /* record this search domain */
-            while (*cp) { /* zero-terminate it */
-                if (*cp == ' '|| *cp == '\t') {
-                    *cp++ = '\0';
-                    break;
-                }
-                cp++;
-            }
-        }
-        *offset = -1; /* cache_info->dnsrch_offset has MAXDNSRCH+1 items */
-
-        // flush cache since new settings
-        _flush_cache_for_iface_locked(ifname);
-
-    }
-
-    pthread_mutex_unlock(&_res_cache_list_lock);
-}
-
-static int
-_resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
-        const char** servers, int numservers)
-{
-    int i;
-    char** ns;
-    int equal = 1;
-
-    // compare each name server against current name servers
-    if (numservers > MAXNS) numservers = MAXNS;
-    for (i = 0; i < numservers && equal; i++) {
-        ns = cache_info->nameservers;
-        equal = 0;
-        while(*ns) {
-            if (strcmp(*ns, servers[i]) == 0) {
-                equal = 1;
-                break;
-            }
-            ns++;
-        }
-    }
-
-    return equal;
-}
-
-static void
-_free_nameservers_locked(struct resolv_cache_info* cache_info)
-{
-    int i;
-    for (i = 0; i <= MAXNS; i++) {
-        free(cache_info->nameservers[i]);
-        cache_info->nameservers[i] = NULL;
-        if (cache_info->nsaddrinfo[i] != NULL) {
-            freeaddrinfo(cache_info->nsaddrinfo[i]);
-            cache_info->nsaddrinfo[i] = NULL;
-        }
-    }
-}
-
-int
-_resolv_cache_get_nameserver(int n, char* addr, int addrLen)
-{
-    char *ifname;
-    int result = 0;
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    ifname = _get_default_iface_locked();
-    result = _get_nameserver_locked(ifname, n, addr, addrLen);
-
-    pthread_mutex_unlock(&_res_cache_list_lock);
-    return result;
-}
-
-static int
-_get_nameserver_locked(const char* ifname, int n, char* addr, int addrLen)
-{
-    int len = 0;
-    char* ns;
-    struct resolv_cache_info* cache_info;
-
-    if (n < 1 || n > MAXNS || !addr)
-        return 0;
-
-    cache_info = _find_cache_info_locked(ifname);
-    if (cache_info) {
-        ns = cache_info->nameservers[n - 1];
-        if (ns) {
-            len = strlen(ns);
-            if (len < addrLen) {
-                strncpy(addr, ns, len);
-                addr[len] = '\0';
-            } else {
-                len = 0;
-            }
-        }
-    }
-
-    return len;
-}
-
-struct addrinfo*
-_cache_get_nameserver_addr(int n)
-{
-    struct addrinfo *result;
-    char* ifname;
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    ifname = _get_default_iface_locked();
-
-    result = _get_nameserver_addr_locked(ifname, n);
-    pthread_mutex_unlock(&_res_cache_list_lock);
-    return result;
-}
-
-static struct addrinfo*
-_get_nameserver_addr_locked(const char* ifname, int n)
-{
-    struct addrinfo* ai = NULL;
-    struct resolv_cache_info* cache_info;
-
-    if (n < 1 || n > MAXNS)
-        return NULL;
-
-    cache_info = _find_cache_info_locked(ifname);
-    if (cache_info) {
-        ai = cache_info->nsaddrinfo[n - 1];
-    }
-    return ai;
-}
-
-void
-_resolv_set_addr_of_iface(const char* ifname, struct in_addr* addr)
-{
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-    struct resolv_cache_info* cache_info = _find_cache_info_locked(ifname);
-    if (cache_info) {
-        memcpy(&cache_info->ifaddr, addr, sizeof(*addr));
-
-        if (DEBUG) {
-            XLOG("address of interface %s is %s\n",
-                    ifname, inet_ntoa(cache_info->ifaddr));
-        }
-    }
-    pthread_mutex_unlock(&_res_cache_list_lock);
-}
-
-struct in_addr*
-_resolv_get_addr_of_default_iface(void)
-{
-    struct in_addr* ai = NULL;
-    char* ifname;
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-    ifname = _get_default_iface_locked();
-    ai = _get_addr_locked(ifname);
-    pthread_mutex_unlock(&_res_cache_list_lock);
-
-    return ai;
-}
-
-struct in_addr*
-_resolv_get_addr_of_iface(const char* ifname)
-{
-    struct in_addr* ai = NULL;
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-    ai =_get_addr_locked(ifname);
-    pthread_mutex_unlock(&_res_cache_list_lock);
-    return ai;
-}
-
-static struct in_addr*
-_get_addr_locked(const char * ifname)
-{
-    struct resolv_cache_info* cache_info = _find_cache_info_locked(ifname);
-    if (cache_info) {
-        return &cache_info->ifaddr;
-    }
-    return NULL;
-}
-
-static void
-_remove_pidiface_info_locked(int pid) {
-    struct resolv_pidiface_info* result = &_res_pidiface_list;
-    struct resolv_pidiface_info* prev = NULL;
-
-    while (result != NULL && result->pid != pid) {
-        prev = result;
-        result = result->next;
-    }
-    if (prev != NULL && result != NULL) {
-        prev->next = result->next;
-        free(result);
-    }
-}
-
-static struct resolv_pidiface_info*
-_get_pid_iface_info_locked(int pid)
-{
-    struct resolv_pidiface_info* result = &_res_pidiface_list;
-    while (result != NULL && result->pid != pid) {
-        result = result->next;
-    }
-
-    return result;
-}
-
-void
-_resolv_set_iface_for_pid(const char* ifname, int pid)
-{
-    // make sure the pid iface list is created
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_pidiface_list_lock);
-
-    struct resolv_pidiface_info* pidiface_info = _get_pid_iface_info_locked(pid);
-    if (!pidiface_info) {
-        pidiface_info = calloc(sizeof(*pidiface_info), 1);
-        if (pidiface_info) {
-            pidiface_info->pid = pid;
-            int len = sizeof(pidiface_info->ifname);
-            strncpy(pidiface_info->ifname, ifname, len - 1);
-            pidiface_info->ifname[len - 1] = '\0';
-
-            pidiface_info->next = _res_pidiface_list.next;
-            _res_pidiface_list.next = pidiface_info;
-
-            XLOG("_resolv_set_iface_for_pid: pid %d , iface %s\n", pid, ifname);
-        } else {
-            XLOG("_resolv_set_iface_for_pid failing calloc");
-        }
-    }
-
-    pthread_mutex_unlock(&_res_pidiface_list_lock);
-}
-
-void
-_resolv_clear_iface_for_pid(int pid)
-{
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_pidiface_list_lock);
-
-    _remove_pidiface_info_locked(pid);
-
-    XLOG("_resolv_clear_iface_for_pid: pid %d\n", pid);
-
-    pthread_mutex_unlock(&_res_pidiface_list_lock);
-}
-
-int
-_resolv_get_pids_associated_interface(int pid, char* buff, int buffLen)
-{
-    int len = 0;
-
-    if (!buff) {
-        return -1;
-    }
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_pidiface_list_lock);
-
-    struct resolv_pidiface_info* pidiface_info = _get_pid_iface_info_locked(pid);
-    buff[0] = '\0';
-    if (pidiface_info) {
-        len = strlen(pidiface_info->ifname);
-        if (len < buffLen) {
-            strncpy(buff, pidiface_info->ifname, len);
-            buff[len] = '\0';
-        }
-    }
-
-    XLOG("_resolv_get_pids_associated_interface buff: %s\n", buff);
-
-    pthread_mutex_unlock(&_res_pidiface_list_lock);
-
-    return len;
-}
-
-static int
-_remove_uidiface_info_locked(const char* ifname, int uid_start, int uid_end) {
-    struct resolv_uidiface_info* result = _res_uidiface_list.next;
-    struct resolv_uidiface_info* prev = &_res_uidiface_list;
-    while (result != NULL && !(result->uid_start == uid_start && result->uid_end == uid_end &&
-            !strcmp(result->ifname, ifname))) {
-        prev = result;
-        result = result->next;
-    }
-    if (prev != NULL && result != NULL) {
-        prev->next = result->next;
-        free(result);
-        return 0;
-    }
-    errno = EINVAL;
-    return -1;
-}
-
-static struct resolv_uidiface_info*
-_get_uid_iface_info_locked(int uid)
-{
-    struct resolv_uidiface_info* result = _res_uidiface_list.next;
-    while (result != NULL && !(result->uid_start <= uid && result->uid_end >= uid)) {
-        result = result->next;
-    }
-
-    return result;
-}
-
-void
-_resolv_clear_iface_uid_range_mapping()
-{
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_uidiface_list_lock);
-    struct resolv_uidiface_info *current = _res_uidiface_list.next;
-    struct resolv_uidiface_info *next;
-    while (current != NULL) {
-        next = current->next;
-        free(current);
-        current = next;
-    }
-    _res_uidiface_list.next = NULL;
-    pthread_mutex_unlock(&_res_uidiface_list_lock);
-}
-
-void
-_resolv_clear_iface_pid_mapping()
-{
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_pidiface_list_lock);
-    struct resolv_pidiface_info *current = _res_pidiface_list.next;
-    struct resolv_pidiface_info *next;
-    while (current != NULL) {
-        next = current->next;
-        free(current);
-        current = next;
-    }
-    _res_pidiface_list.next = NULL;
-    pthread_mutex_unlock(&_res_pidiface_list_lock);
-}
-
-int
-_resolv_set_iface_for_uid_range(const char* ifname, int uid_start, int uid_end)
-{
-    int rv = 0;
-    struct resolv_uidiface_info* uidiface_info;
-    // make sure the uid iface list is created
-    pthread_once(&_res_cache_once, _res_cache_init);
-    if (uid_start > uid_end) {
-        errno = EINVAL;
-        return -1;
-    }
-    pthread_mutex_lock(&_res_uidiface_list_lock);
-    uidiface_info = calloc(sizeof(*uidiface_info), 1);
-    if (uidiface_info) {
-        uidiface_info->uid_start = uid_start;
-        uidiface_info->uid_end = uid_end;
-        int len = sizeof(uidiface_info->ifname);
-        strncpy(uidiface_info->ifname, ifname, len - 1);
-        uidiface_info->ifname[len - 1] = '\0';
-
-        uidiface_info->next = _res_uidiface_list.next;
-        _res_uidiface_list.next = uidiface_info;
-
-        XLOG("_resolv_set_iface_for_uid_range: [%d,%d], iface %s\n", uid_start, uid_end,
-                ifname);
-    } else {
-        XLOG("_resolv_set_iface_for_uid_range failing calloc\n");
-        rv = -1;
-        errno = EINVAL;
-    }
-
-    pthread_mutex_unlock(&_res_uidiface_list_lock);
-    return rv;
-}
-
-int
-_resolv_clear_iface_for_uid_range(const char* ifname, int uid_start, int uid_end)
-{
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_uidiface_list_lock);
-
-    int rv = _remove_uidiface_info_locked(ifname, uid_start, uid_end);
-
-    XLOG("_resolv_clear_iface_for_uid_range: [%d,%d] iface %s\n", uid_start, uid_end, ifname);
-
-    pthread_mutex_unlock(&_res_uidiface_list_lock);
-
-    return rv;
-}
-
-int
-_resolv_get_uids_associated_interface(int uid, char* buff, int buffLen)
-{
-    int len = 0;
-
-    if (!buff) {
-        return -1;
-    }
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_uidiface_list_lock);
-
-    struct resolv_uidiface_info* uidiface_info = _get_uid_iface_info_locked(uid);
-    buff[0] = '\0';
-    if (uidiface_info) {
-        len = strlen(uidiface_info->ifname);
-        if (len < buffLen) {
-            strncpy(buff, uidiface_info->ifname, len);
-            buff[len] = '\0';
-        }
-    }
-
-    XLOG("_resolv_get_uids_associated_interface buff: %s\n", buff);
-
-    pthread_mutex_unlock(&_res_uidiface_list_lock);
-
-    return len;
-}
-
-size_t
-_resolv_get_default_iface(char* buff, size_t buffLen)
-{
-    if (!buff || buffLen == 0) {
-        return 0;
-    }
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    char* ifname = _get_default_iface_locked(); // never null, but may be empty
-
-    // if default interface not set give up.
-    if (ifname[0] == '\0') {
-        pthread_mutex_unlock(&_res_cache_list_lock);
-        return 0;
-    }
-
-    size_t len = strlen(ifname);
-    if (len < buffLen) {
-        strncpy(buff, ifname, len);
-        buff[len] = '\0';
-    } else {
-        buff[0] = '\0';
-    }
-
-    pthread_mutex_unlock(&_res_cache_list_lock);
-
-    return len;
-}
-
-void
-_resolv_populate_res_for_iface(res_state statp)
-{
-    if (statp == NULL) {
-        return;
-    }
-
-    if (statp->iface[0] == '\0') { // no interface set assign default
-        size_t if_len = _resolv_get_default_iface(statp->iface, sizeof(statp->iface));
-        if (if_len + 1 > sizeof(statp->iface)) {
-            XLOG("%s: INTERNAL_ERROR: can't fit interface name into statp->iface.\n", __FUNCTION__);
-            return;
-        }
-        if (if_len == 0) {
-            XLOG("%s: INTERNAL_ERROR: can't find any suitable interfaces.\n", __FUNCTION__);
-            return;
-        }
-    }
-
-    pthread_once(&_res_cache_once, _res_cache_init);
-    pthread_mutex_lock(&_res_cache_list_lock);
-
-    struct resolv_cache_info* info = _find_cache_info_locked(statp->iface);
-    if (info != NULL) {
-        int nserv;
-        struct addrinfo* ai;
-        XLOG("_resolv_populate_res_for_iface: %s\n", statp->iface);
-        for (nserv = 0; nserv < MAXNS; nserv++) {
-            ai = info->nsaddrinfo[nserv];
-            if (ai == NULL) {
-                break;
-            }
-
-            if ((size_t) ai->ai_addrlen <= sizeof(statp->_u._ext.ext->nsaddrs[0])) {
-                if (statp->_u._ext.ext != NULL) {
-                    memcpy(&statp->_u._ext.ext->nsaddrs[nserv], ai->ai_addr, ai->ai_addrlen);
-                    statp->nsaddr_list[nserv].sin_family = AF_UNSPEC;
-                } else {
-                    if ((size_t) ai->ai_addrlen
-                            <= sizeof(statp->nsaddr_list[0])) {
-                        memcpy(&statp->nsaddr_list[nserv], ai->ai_addr,
-                                ai->ai_addrlen);
-                    } else {
-                        statp->nsaddr_list[nserv].sin_family = AF_UNSPEC;
-                    }
-                }
-            } else {
-                XLOG("_resolv_populate_res_for_iface found too long addrlen");
-            }
-        }
-        statp->nscount = nserv;
-        // now do search domains.  Note that we cache the offsets as this code runs alot
-        // but the setting/offset-computer only runs when set/changed
-        strlcpy(statp->defdname, info->defdname, sizeof(statp->defdname));
-        register char **pp = statp->dnsrch;
-        register int *p = info->dnsrch_offset;
-        while (pp < statp->dnsrch + MAXDNSRCH && *p != -1) {
-            *pp++ = &statp->defdname + *p++;
-        }
-    }
-    pthread_mutex_unlock(&_res_cache_list_lock);
-}
diff --git a/libc/netbsd/resolv/res_comp.c b/libc/netbsd/resolv/res_comp.c
deleted file mode 100644
index 77b81b4..0000000
--- a/libc/netbsd/resolv/res_comp.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/*	$NetBSD: res_comp.c,v 1.6 2004/05/22 23:47:09 christos Exp $	*/
-
-/*
- * Copyright (c) 1985, 1993
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#ifdef notdef
-static const char sccsid[] = "@(#)res_comp.c	8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "Id: res_comp.c,v 1.1.2.1.4.1 2004/03/09 08:33:54 marka Exp";
-#else
-__RCSID("$NetBSD: res_comp.c,v 1.6 2004/05/22 23:47:09 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include "arpa_nameser.h"
-#include <ctype.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-/*
- * Expand compressed domain name 'src' to full domain name.
- * 'msg' is a pointer to the begining of the message,
- * 'eom' points to the first location after the message,
- * 'dst' is a pointer to a buffer of size 'dstsiz' for the result.
- * Return size of compressed name or -1 if there was an error.
- */
-int
-dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
-	  char *dst, int dstsiz)
-{
-	int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
-
-	if (n > 0 && dst[0] == '.')
-		dst[0] = '\0';
-	return (n);
-}
-
-/*
- * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
- * Return the size of the compressed name or -1.
- * 'length' is the size of the array pointed to by 'comp_dn'.
- */
-int
-dn_comp(const char *src, u_char *dst, int dstsiz,
-	u_char **dnptrs, u_char **lastdnptr)
-{
-	return (ns_name_compress(src, dst, (size_t)dstsiz,
-				 (const u_char **)dnptrs,
-				 (const u_char **)lastdnptr));
-}
-
-/*
- * Skip over a compressed domain name. Return the size or -1.
- */
-int
-dn_skipname(const u_char *ptr, const u_char *eom) {
-	const u_char *saveptr = ptr;
-
-	if (ns_name_skip(&ptr, eom) == -1)
-		return (-1);
-	return (ptr - saveptr);
-}
-
-/*
- * Verify that a domain name uses an acceptable character set.
- */
-
-/*
- * Note the conspicuous absence of ctype macros in these definitions.  On
- * non-ASCII hosts, we can't depend on string literals or ctype macros to
- * tell us anything about network-format data.  The rest of the BIND system
- * is not careful about this, but for some reason, we're doing it right here.
- */
-
-/* BIONIC: We also accept underscores in the middle of labels.
- *         This extension is needed to make resolution on some VPN networks
- *         work properly.
- */
-
-#define PERIOD 0x2e
-#define	hyphenchar(c) ((c) == 0x2d)
-#define bslashchar(c) ((c) == 0x5c)
-#define periodchar(c) ((c) == PERIOD)
-#define asterchar(c) ((c) == 0x2a)
-#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
-		   || ((c) >= 0x61 && (c) <= 0x7a))
-#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
-#define underscorechar(c)  ((c) == 0x5f)
-
-#define borderchar(c) (alphachar(c) || digitchar(c))
-#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c))
-#define	domainchar(c) ((c) > 0x20 && (c) < 0x7f)
-
-int
-res_hnok(const char *dn) {
-	int pch = PERIOD, ch = *dn++;
-
-	while (ch != '\0') {
-		int nch = *dn++;
-
-		if (periodchar(ch)) {
-			;
-		} else if (periodchar(pch)) {
-			if (!borderchar(ch))
-				return (0);
-		} else if (periodchar(nch) || nch == '\0') {
-			if (!borderchar(ch))
-				return (0);
-		} else {
-			if (!middlechar(ch))
-				return (0);
-		}
-		pch = ch, ch = nch;
-	}
-	return (1);
-}
-
-/*
- * hostname-like (A, MX, WKS) owners can have "*" as their first label
- * but must otherwise be as a host name.
- */
-int
-res_ownok(const char *dn) {
-	if (asterchar(dn[0])) {
-		if (periodchar(dn[1]))
-			return (res_hnok(dn+2));
-		if (dn[1] == '\0')
-			return (1);
-	}
-	return (res_hnok(dn));
-}
-
-/*
- * SOA RNAMEs and RP RNAMEs can have any printable character in their first
- * label, but the rest of the name has to look like a host name.
- */
-int
-res_mailok(const char *dn) {
-	int ch, escaped = 0;
-
-	/* "." is a valid missing representation */
-	if (*dn == '\0')
-		return (1);
-
-	/* otherwise <label>.<hostname> */
-	while ((ch = *dn++) != '\0') {
-		if (!domainchar(ch))
-			return (0);
-		if (!escaped && periodchar(ch))
-			break;
-		if (escaped)
-			escaped = 0;
-		else if (bslashchar(ch))
-			escaped = 1;
-	}
-	if (periodchar(ch))
-		return (res_hnok(dn));
-	return (0);
-}
-
-/*
- * This function is quite liberal, since RFC 1034's character sets are only
- * recommendations.
- */
-int
-res_dnok(const char *dn) {
-	int ch;
-
-	while ((ch = *dn++) != '\0')
-		if (!domainchar(ch))
-			return (0);
-	return (1);
-}
-
-#ifdef BIND_4_COMPAT
-/*
- * This module must export the following externally-visible symbols:
- *	___putlong
- *	___putshort
- *	__getlong
- *	__getshort
- * Note that one _ comes from C and the others come from us.
- */
-void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
-void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
-#ifndef __ultrix__
-u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
-u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
-#endif /*__ultrix__*/
-#endif /*BIND_4_COMPAT*/
diff --git a/libc/netbsd/resolv/res_compat.c b/libc/netbsd/resolv/res_compat.c
deleted file mode 100644
index 19a1d5f..0000000
--- a/libc/netbsd/resolv/res_compat.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*	$NetBSD: res_compat.c,v 1.1 2004/06/09 18:07:03 christos Exp $	*/
-
-/*-
- * Copyright (c) 2004 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Christos Zoulas.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: res_compat.c,v 1.1 2004/06/09 18:07:03 christos Exp $");
-#endif
-
-#include <sys/types.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-#include <netdb.h>
-#include <string.h>
-#define __OLD_RES_STATE
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include "resolv.h"
-#endif
-
-#undef _res
-
-/*
- * Binary Compatibility; this symbol does not appear in a header file
- * Most userland programs use this to set res_options before res_init()
- * is called. There are hooks to res_init() to consult the data in this
- * structure. The hooks are provided indirectly by the two functions below.
- * We depend on the fact the the first 440 [32 bit machines] bytes are
- * shared between the two structures.
- */
-#ifndef __BIND_NOSTATIC
-struct __res_state _res
-#if defined(__BIND_RES_TEXT)
-	= { RES_TIMEOUT, }      /* Motorola, et al. */
-# endif
-;
-
-void *__res_get_old_state(void);
-void __res_put_old_state(void *);
-
-void *
-__res_get_old_state(void)
-{
-	return &_res;
-}
-
-void
-__res_put_old_state(void *res)
-{
-	(void)memcpy(&_res, res, sizeof(_res));
-}
-#endif
diff --git a/libc/netbsd/resolv/res_data.c b/libc/netbsd/resolv/res_data.c
deleted file mode 100644
index 7e5a308..0000000
--- a/libc/netbsd/resolv/res_data.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*	$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1995-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#ifdef notdef
-static const char rcsid[] = "Id: res_data.c,v 1.1.206.2 2004/03/16 12:34:18 marka Exp";
-#else
-__RCSID("$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-
-#include <ctype.h>
-#include <netdb.h>
-#include "resolv_private.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-
-__LIBC_HIDDEN__
-const char * const _res_opcodes[] = {
-	"QUERY",
-	"IQUERY",
-	"CQUERYM",
-	"CQUERYU",	/* experimental */
-	"NOTIFY",	/* experimental */
-	"UPDATE",
-	"6",
-	"7",
-	"8",
-	"9",
-	"10",
-	"11",
-	"12",
-	"13",
-	"ZONEINIT",
-	"ZONEREF",
-};
-
-#ifdef BIND_UPDATE
-const char * const _res_sectioncodes[] = {
-	"ZONE",
-	"PREREQUISITES",
-	"UPDATE",
-	"ADDITIONAL",
-};
-#endif
-
-#ifndef __BIND_NOSTATIC
-extern struct __res_state _nres;
-
-/* Proto. */
-
-int  res_ourserver_p(const res_state, const struct sockaddr *);
-
-#define res_need_init()   ((_nres.options & RES_INIT) == 0U)
-
-int
-res_init(void) {
-	int rv;
-	extern int __res_vinit(res_state, int);
-#ifdef COMPAT__RES
-	/*
-	 * Compatibility with program that were accessing _res directly
-	 * to set options. We keep another struct res that is the same
-	 * size as the original res structure, and then copy fields to
-	 * it so that we achieve the same initialization
-	 */
-	extern void *__res_get_old_state(void);
-	extern void __res_put_old_state(void *);
-	res_state ores = __res_get_old_state();
-
-	if (ores->options != 0)
-		_nres.options = ores->options;
-	if (ores->retrans != 0)
-		_nres.retrans = ores->retrans;
-	if (ores->retry != 0)
-		_nres.retry = ores->retry;
-#endif
-
-	/*
-	 * These three fields used to be statically initialized.  This made
-	 * it hard to use this code in a shared library.  It is necessary,
-	 * now that we're doing dynamic initialization here, that we preserve
-	 * the old semantics: if an application modifies one of these three
-	 * fields of _res before res_init() is called, res_init() will not
-	 * alter them.  Of course, if an application is setting them to
-	 * _zero_ before calling res_init(), hoping to override what used
-	 * to be the static default, we can't detect it and unexpected results
-	 * will follow.  Zero for any of these fields would make no sense,
-	 * so one can safely assume that the applications were already getting
-	 * unexpected results.
-	 *
-	 * _nres.options is tricky since some apps were known to diddle the bits
-	 * before res_init() was first called. We can't replicate that semantic
-	 * with dynamic initialization (they may have turned bits off that are
-	 * set in RES_DEFAULT).  Our solution is to declare such applications
-	 * "broken".  They could fool us by setting RES_INIT but none do (yet).
-	 */
-	if (!_nres.retrans)
-		_nres.retrans = RES_TIMEOUT;
-	if (!_nres.retry)
-		_nres.retry = 4;
-	if (!(_nres.options & RES_INIT))
-		_nres.options = RES_DEFAULT;
-
-	/*
-	 * This one used to initialize implicitly to zero, so unless the app
-	 * has set it to something in particular, we can randomize it now.
-	 */
-	if (!_nres.id)
-		_nres.id = res_randomid();
-
-	rv = __res_vinit(&_nres, 1);
-#ifdef COMPAT__RES
-	__res_put_old_state(&_nres);
-#endif
-	return rv;
-}
-
-void
-p_query(const u_char *msg) {
-	fp_query(msg, stdout);
-}
-
-void
-fp_query(const u_char *msg, FILE *file) {
-	fp_nquery(msg, PACKETSZ, file);
-}
-
-void
-fp_nquery(const u_char *msg, int len, FILE *file) {
-	if (res_need_init() && res_init() == -1)
-		return;
-
-	res_pquery(&_nres, msg, len, file);
-}
-
-int
-res_mkquery(int op,			/* opcode of query */
-	    const char *dname,		/* domain name */
-	    int class, int type,	/* class and type of query */
-	    const u_char *data,		/* resource record data */
-	    int datalen,		/* length of data */
-	    const u_char *newrr_in,	/* new rr for modify or append */
-	    u_char *buf,		/* buffer to put query */
-	    int buflen)			/* size of buffer */
-{
-	if (res_need_init() && res_init() == -1) {
-		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
-		return (-1);
-	}
-	return (res_nmkquery(&_nres, op, dname, class, type,
-			     data, datalen,
-			     newrr_in, buf, buflen));
-}
-
-#ifdef _LIBRESOLV
-int
-res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
-	if (res_need_init() && res_init() == -1) {
-		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
-		return (-1);
-	}
-
-	return (res_nmkupdate(&_nres, rrecp_in, buf, buflen));
-}
-#endif
-
-int
-res_query(const char *name,	/* domain name */
-	  int class, int type,	/* class and type of query */
-	  u_char *answer,	/* buffer to put answer */
-	  int anslen)		/* size of answer buffer */
-{
-	if (res_need_init() && res_init() == -1) {
-		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
-		return (-1);
-	}
-	return (res_nquery(&_nres, name, class, type, answer, anslen));
-}
-
-void
-res_send_setqhook(res_send_qhook hook) {
-	_nres.qhook = hook;
-}
-
-void
-res_send_setrhook(res_send_rhook hook) {
-	_nres.rhook = hook;
-}
-
-int
-res_isourserver(const struct sockaddr_in *inp) {
-	return (res_ourserver_p(&_nres, (const struct sockaddr *)(const void *)inp));
-}
-
-int
-res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) {
-	if (res_need_init() && res_init() == -1) {
-		/* errno should have been set by res_init() in this case. */
-		return (-1);
-	}
-
-	return (res_nsend(&_nres, buf, buflen, ans, anssiz));
-}
-
-#ifdef _LIBRESOLV
-int
-res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
-	       u_char *ans, int anssiz)
-{
-	if (res_need_init() && res_init() == -1) {
-		/* errno should have been set by res_init() in this case. */
-		return (-1);
-	}
-
-	return (res_nsendsigned(&_nres, buf, buflen, key, ans, anssiz));
-}
-#endif
-
-void
-res_close(void) {
-	res_nclose(&_nres);
-}
-
-#ifdef _LIBRESOLV
-int
-res_update(ns_updrec *rrecp_in) {
-	if (res_need_init() && res_init() == -1) {
-		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
-		return (-1);
-	}
-
-	return (res_nupdate(&_nres, rrecp_in, NULL));
-}
-#endif
-
-int
-res_search(const char *name,	/* domain name */
-	   int class, int type,	/* class and type of query */
-	   u_char *answer,	/* buffer to put answer */
-	   int anslen)		/* size of answer */
-{
-	if (res_need_init() && res_init() == -1) {
-		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
-		return (-1);
-	}
-
-	return (res_nsearch(&_nres, name, class, type, answer, anslen));
-}
-
-int
-res_querydomain(const char *name,
-		const char *domain,
-		int class, int type,	/* class and type of query */
-		u_char *answer,		/* buffer to put answer */
-		int anslen)		/* size of answer */
-{
-	if (res_need_init() && res_init() == -1) {
-		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
-		return (-1);
-	}
-
-	return (res_nquerydomain(&_nres, name, domain,
-				 class, type,
-				 answer, anslen));
-}
-
-int
-res_opt(int a, u_char *b, int c, int d)
-{
-	return res_nopt(&_nres, a, b, c, d);
-}
-
-const char *
-hostalias(const char *name) {
-	return NULL;
-}
-
-#ifdef ultrix
-int
-local_hostname_length(const char *hostname) {
-	int len_host, len_domain;
-
-	if (!*_nres.defdname)
-		res_init();
-	len_host = strlen(hostname);
-	len_domain = strlen(_nres.defdname);
-	if (len_host > len_domain &&
-	    !strcasecmp(hostname + len_host - len_domain, _nres.defdname) &&
-	    hostname[len_host - len_domain - 1] == '.')
-		return (len_host - len_domain - 1);
-	return (0);
-}
-#endif /*ultrix*/
-
-#endif
diff --git a/libc/netbsd/resolv/res_debug.c b/libc/netbsd/resolv/res_debug.c
deleted file mode 100644
index 46e583b..0000000
--- a/libc/netbsd/resolv/res_debug.c
+++ /dev/null
@@ -1,1175 +0,0 @@
-/*	$NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $	*/
-
-/*
- * Copyright (c) 1985
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- */
-
-/*
- * Portions Copyright (c) 1995 by International Business Machines, Inc.
- *
- * International Business Machines, Inc. (hereinafter called IBM) grants
- * permission under its copyrights to use, copy, modify, and distribute this
- * Software with or without fee, provided that the above copyright notice and
- * all paragraphs of this notice appear in all copies, and that the name of IBM
- * not be used in connection with the marketing of any product incorporating
- * the Software or modifications thereof, without specific, written prior
- * permission.
- *
- * To the extent it has a right to do so, IBM grants an immunity from suit
- * under its patents, if any, for the use, sale or manufacture of products to
- * the extent that such products are used for performing Domain Name System
- * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
- * granted for any product per se or for any other function of any product.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#ifdef notdef
-static const char sccsid[] = "@(#)res_debug.c	8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "Id: res_debug.c,v 1.3.2.5.4.5 2004/07/28 20:16:46 marka Exp";
-#else
-__RCSID("$NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-
-#include <ctype.h>
-#include <errno.h>
-#include <math.h>
-#include <netdb.h>
-#include "resolv_private.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <time.h>
-
-
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) sprintf x
-#endif
-
-static const char *precsize_ntoa(u_int32_t);
-
-extern const char * const _res_opcodes[];
-extern const char * const _res_sectioncodes[];
-
-#ifndef _LIBC
-/*
- * Print the current options.
- */
-void
-fp_resstat(const res_state statp, FILE *file) {
-	u_long mask;
-
-	fprintf(file, ";; res options:");
-	for (mask = 1;  mask != 0U;  mask <<= 1)
-		if (statp->options & mask)
-			fprintf(file, " %s", p_option(mask));
-	putc('\n', file);
-}
-#endif
-
-static void
-do_section(const res_state statp,
-	   ns_msg *handle, ns_sect section,
-	   int pflag, FILE *file)
-{
-	int n, sflag, rrnum;
-	int buflen = 2048;
-	char *buf;
-	ns_opcode opcode;
-	ns_rr rr;
-
-	/*
-	 * Print answer records.
-	 */
-	sflag = (statp->pfcode & pflag);
-	if (statp->pfcode && !sflag)
-		return;
-
-	buf = malloc((size_t)buflen);
-	if (buf == NULL) {
-		fprintf(file, ";; memory allocation failure\n");
-		return;
-	}
-
-	opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode);
-	rrnum = 0;
-	for (;;) {
-		if (ns_parserr(handle, section, rrnum, &rr)) {
-			if (errno != ENODEV)
-				fprintf(file, ";; ns_parserr: %s\n",
-					strerror(errno));
-			else if (rrnum > 0 && sflag != 0 &&
-				 (statp->pfcode & RES_PRF_HEAD1))
-				putc('\n', file);
-			goto cleanup;
-		}
-		if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
-			fprintf(file, ";; %s SECTION:\n",
-				p_section(section, opcode));
-		if (section == ns_s_qd)
-			fprintf(file, ";;\t%s, type = %s, class = %s\n",
-				ns_rr_name(rr),
-				p_type(ns_rr_type(rr)),
-				p_class(ns_rr_class(rr)));
-		else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
-			u_int32_t ttl = ns_rr_ttl(rr);
-			fprintf(file,
-				"; EDNS: version: %u, udp=%u, flags=%04x\n",
-				(ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff);
-		} else {
-			n = ns_sprintrr(handle, &rr, NULL, NULL,
-					buf, (u_int)buflen);
-			if (n < 0) {
-				if (errno == ENOSPC) {
-					free(buf);
-					buf = NULL;
-					if (buflen < 131072)
-						buf = malloc((size_t)(buflen += 1024));
-					if (buf == NULL) {
-						fprintf(file,
-				              ";; memory allocation failure\n");
-					      return;
-					}
-					continue;
-				}
-				fprintf(file, ";; ns_sprintrr: %s\n",
-					strerror(errno));
-				goto cleanup;
-			}
-			fputs(buf, file);
-			fputc('\n', file);
-		}
-		rrnum++;
-	}
- cleanup:
-	if (buf != NULL)
-		free(buf);
-}
-
-/*
- * Print the contents of a query.
- * This is intended to be primarily a debugging routine.
- */
-void
-res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
-	ns_msg handle;
-	int qdcount, ancount, nscount, arcount;
-	u_int opcode, rcode, id;
-
-	if (ns_initparse(msg, len, &handle) < 0) {
-		fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
-		return;
-	}
-	opcode = ns_msg_getflag(handle, ns_f_opcode);
-	rcode = ns_msg_getflag(handle, ns_f_rcode);
-	id = ns_msg_id(handle);
-	qdcount = ns_msg_count(handle, ns_s_qd);
-	ancount = ns_msg_count(handle, ns_s_an);
-	nscount = ns_msg_count(handle, ns_s_ns);
-	arcount = ns_msg_count(handle, ns_s_ar);
-
-	/*
-	 * Print header fields.
-	 */
-	if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
-		fprintf(file,
-			";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
-			_res_opcodes[opcode], p_rcode((int)rcode), id);
-	if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX))
-		putc(';', file);
-	if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) {
-		fprintf(file, "; flags:");
-		if (ns_msg_getflag(handle, ns_f_qr))
-			fprintf(file, " qr");
-		if (ns_msg_getflag(handle, ns_f_aa))
-			fprintf(file, " aa");
-		if (ns_msg_getflag(handle, ns_f_tc))
-			fprintf(file, " tc");
-		if (ns_msg_getflag(handle, ns_f_rd))
-			fprintf(file, " rd");
-		if (ns_msg_getflag(handle, ns_f_ra))
-			fprintf(file, " ra");
-		if (ns_msg_getflag(handle, ns_f_z))
-			fprintf(file, " ??");
-		if (ns_msg_getflag(handle, ns_f_ad))
-			fprintf(file, " ad");
-		if (ns_msg_getflag(handle, ns_f_cd))
-			fprintf(file, " cd");
-	}
-	if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) {
-		fprintf(file, "; %s: %d",
-			p_section(ns_s_qd, (int)opcode), qdcount);
-		fprintf(file, ", %s: %d",
-			p_section(ns_s_an, (int)opcode), ancount);
-		fprintf(file, ", %s: %d",
-			p_section(ns_s_ns, (int)opcode), nscount);
-		fprintf(file, ", %s: %d",
-			p_section(ns_s_ar, (int)opcode), arcount);
-	}
-	if ((!statp->pfcode) || (statp->pfcode &
-		(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
-		putc('\n',file);
-	}
-	/*
-	 * Print the various sections.
-	 */
-	do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file);
-	do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file);
-	do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file);
-	do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file);
-	if (qdcount == 0 && ancount == 0 &&
-	    nscount == 0 && arcount == 0)
-		putc('\n', file);
-}
-
-const u_char *
-p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
-	char name[MAXDNAME];
-	int n;
-
-	if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
-		return (NULL);
-	if (name[0] == '\0')
-		putc('.', file);
-	else
-		fputs(name, file);
-	return (cp + n);
-}
-
-const u_char *
-p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
-	return (p_cdnname(cp, msg, PACKETSZ, file));
-}
-
-/* Return a fully-qualified domain name from a compressed name (with
-   length supplied).  */
-
-const u_char *
-p_fqnname(cp, msg, msglen, name, namelen)
-	const u_char *cp, *msg;
-	int msglen;
-	char *name;
-	int namelen;
-{
-	int n, newlen;
-
-	if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
-		return (NULL);
-	newlen = strlen(name);
-	if (newlen == 0 || name[newlen - 1] != '.') {
-		if (newlen + 1 >= namelen)	/* Lack space for final dot */
-			return (NULL);
-		else
-			strcpy(name + newlen, ".");
-	}
-	return (cp + n);
-}
-
-/* XXX:	the rest of these functions need to become length-limited, too. */
-
-const u_char *
-p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
-	char name[MAXDNAME];
-	const u_char *n;
-
-	n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
-	if (n == NULL)
-		return (NULL);
-	fputs(name, file);
-	return (n);
-}
-
-/*
- * Names of RR classes and qclasses.  Classes and qclasses are the same, except
- * that C_ANY is a qclass but not a class.  (You can ask for records of class
- * C_ANY, but you can't have any records of that class in the database.)
- */
-const struct res_sym __p_class_syms[] = {
-	{C_IN,		"IN",		(char *)0},
-	{C_CHAOS,	"CH",		(char *)0},
-	{C_CHAOS,	"CHAOS",	(char *)0},
-	{C_HS,		"HS",		(char *)0},
-	{C_HS,		"HESIOD",	(char *)0},
-	{C_ANY,		"ANY",		(char *)0},
-	{C_NONE,	"NONE",		(char *)0},
-	{C_IN, 		(char *)0,	(char *)0}
-};
-
-/*
- * Names of message sections.
- */
-static const struct res_sym __p_default_section_syms[] = {
-	{ns_s_qd,	"QUERY",	(char *)0},
-	{ns_s_an,	"ANSWER",	(char *)0},
-	{ns_s_ns,	"AUTHORITY",	(char *)0},
-	{ns_s_ar,	"ADDITIONAL",	(char *)0},
-	{0,             (char *)0,	(char *)0}
-};
-
-static const struct res_sym __p_update_section_syms[] = {
-	{S_ZONE,	"ZONE",		(char *)0},
-	{S_PREREQ,	"PREREQUISITE",	(char *)0},
-	{S_UPDATE,	"UPDATE",	(char *)0},
-	{S_ADDT,	"ADDITIONAL",	(char *)0},
-	{0,             (char *)0,	(char *)0}
-};
-
-const struct res_sym __p_key_syms[] = {
-	{NS_ALG_MD5RSA,		"RSA",		"RSA KEY with MD5 hash"},
-	{NS_ALG_DH,		"DH",		"Diffie Hellman"},
-	{NS_ALG_DSA,		"DSA",		"Digital Signature Algorithm"},
-	{NS_ALG_EXPIRE_ONLY,	"EXPIREONLY",	"No algorithm"},
-	{NS_ALG_PRIVATE_OID,	"PRIVATE",	"Algorithm obtained from OID"},
-	{0,			NULL,		NULL}
-};
-
-const struct res_sym __p_cert_syms[] = {
-	{cert_t_pkix,	"PKIX",		"PKIX (X.509v3) Certificate"},
-	{cert_t_spki,	"SPKI",		"SPKI certificate"},
-	{cert_t_pgp,	"PGP",		"PGP certificate"},
-	{cert_t_url,	"URL",		"URL Private"},
-	{cert_t_oid,	"OID",		"OID Private"},
-	{0,		NULL,		NULL}
-};
-
-/*
- * Names of RR types and qtypes.  Types and qtypes are the same, except
- * that T_ANY is a qtype but not a type.  (You can ask for records of type
- * T_ANY, but you can't have any records of that type in the database.)
- */
-const struct res_sym __p_type_syms[] = {
-	{ns_t_a,	"A",		"address"},
-	{ns_t_ns,	"NS",		"name server"},
-	{ns_t_md,	"MD",		"mail destination (deprecated)"},
-	{ns_t_mf,	"MF",		"mail forwarder (deprecated)"},
-	{ns_t_cname,	"CNAME",	"canonical name"},
-	{ns_t_soa,	"SOA",		"start of authority"},
-	{ns_t_mb,	"MB",		"mailbox"},
-	{ns_t_mg,	"MG",		"mail group member"},
-	{ns_t_mr,	"MR",		"mail rename"},
-	{ns_t_null,	"NULL",		"null"},
-	{ns_t_wks,	"WKS",		"well-known service (deprecated)"},
-	{ns_t_ptr,	"PTR",		"domain name pointer"},
-	{ns_t_hinfo,	"HINFO",	"host information"},
-	{ns_t_minfo,	"MINFO",	"mailbox information"},
-	{ns_t_mx,	"MX",		"mail exchanger"},
-	{ns_t_txt,	"TXT",		"text"},
-	{ns_t_rp,	"RP",		"responsible person"},
-	{ns_t_afsdb,	"AFSDB",	"DCE or AFS server"},
-	{ns_t_x25,	"X25",		"X25 address"},
-	{ns_t_isdn,	"ISDN",		"ISDN address"},
-	{ns_t_rt,	"RT",		"router"},
-	{ns_t_nsap,	"NSAP",		"nsap address"},
-	{ns_t_nsap_ptr,	"NSAP_PTR",	"domain name pointer"},
-	{ns_t_sig,	"SIG",		"signature"},
-	{ns_t_key,	"KEY",		"key"},
-	{ns_t_px,	"PX",		"mapping information"},
-	{ns_t_gpos,	"GPOS",		"geographical position (withdrawn)"},
-	{ns_t_aaaa,	"AAAA",		"IPv6 address"},
-	{ns_t_loc,	"LOC",		"location"},
-	{ns_t_nxt,	"NXT",		"next valid name (unimplemented)"},
-	{ns_t_eid,	"EID",		"endpoint identifier (unimplemented)"},
-	{ns_t_nimloc,	"NIMLOC",	"NIMROD locator (unimplemented)"},
-	{ns_t_srv,	"SRV",		"server selection"},
-	{ns_t_atma,	"ATMA",		"ATM address (unimplemented)"},
-	{ns_t_tkey,	"TKEY",		"tkey"},
-	{ns_t_tsig,	"TSIG",		"transaction signature"},
-	{ns_t_ixfr,	"IXFR",		"incremental zone transfer"},
-	{ns_t_axfr,	"AXFR",		"zone transfer"},
-	{ns_t_zxfr,	"ZXFR",		"compressed zone transfer"},
-	{ns_t_mailb,	"MAILB",	"mailbox-related data (deprecated)"},
-	{ns_t_maila,	"MAILA",	"mail agent (deprecated)"},
-	{ns_t_naptr,	"NAPTR",	"URN Naming Authority"},
-	{ns_t_kx,	"KX",		"Key Exchange"},
-	{ns_t_cert,	"CERT",		"Certificate"},
-	{ns_t_a6,	"A6",		"IPv6 Address"},
-	{ns_t_dname,	"DNAME",	"dname"},
-	{ns_t_sink,	"SINK",		"Kitchen Sink (experimental)"},
-	{ns_t_opt,	"OPT",		"EDNS Options"},
-	{ns_t_any,	"ANY",		"\"any\""},
-	{0, 		NULL,		NULL}
-};
-
-/*
- * Names of DNS rcodes.
- */
-const struct res_sym __p_rcode_syms[] = {
-	{ns_r_noerror,	"NOERROR",		"no error"},
-	{ns_r_formerr,	"FORMERR",		"format error"},
-	{ns_r_servfail,	"SERVFAIL",		"server failed"},
-	{ns_r_nxdomain,	"NXDOMAIN",		"no such domain name"},
-	{ns_r_notimpl,	"NOTIMP",		"not implemented"},
-	{ns_r_refused,	"REFUSED",		"refused"},
-	{ns_r_yxdomain,	"YXDOMAIN",		"domain name exists"},
-	{ns_r_yxrrset,	"YXRRSET",		"rrset exists"},
-	{ns_r_nxrrset,	"NXRRSET",		"rrset doesn't exist"},
-	{ns_r_notauth,	"NOTAUTH",		"not authoritative"},
-	{ns_r_notzone,	"NOTZONE",		"Not in zone"},
-	{ns_r_max,	"",			""},
-	{ns_r_badsig,	"BADSIG",		"bad signature"},
-	{ns_r_badkey,	"BADKEY",		"bad key"},
-	{ns_r_badtime,	"BADTIME",		"bad time"},
-	{0, 		NULL,			NULL}
-};
-
-int
-sym_ston(const struct res_sym *syms, const char *name, int *success) {
-	for (; syms->name != 0; syms++) {
-		if (strcasecmp (name, syms->name) == 0) {
-			if (success)
-				*success = 1;
-			return (syms->number);
-		}
-	}
-	if (success)
-		*success = 0;
-	return (syms->number);		/* The default value. */
-}
-
-const char *
-sym_ntos(const struct res_sym *syms, int number, int *success) {
-	static char unname[20];
-
-	for (; syms->name != 0; syms++) {
-		if (number == syms->number) {
-			if (success)
-				*success = 1;
-			return (syms->name);
-		}
-	}
-
-	sprintf(unname, "%d", number);		/* XXX nonreentrant */
-	if (success)
-		*success = 0;
-	return (unname);
-}
-
-const char *
-sym_ntop(const struct res_sym *syms, int number, int *success) {
-	static char unname[20];
-
-	for (; syms->name != 0; syms++) {
-		if (number == syms->number) {
-			if (success)
-				*success = 1;
-			return (syms->humanname);
-		}
-	}
-	sprintf(unname, "%d", number);		/* XXX nonreentrant */
-	if (success)
-		*success = 0;
-	return (unname);
-}
-
-/*
- * Return a string for the type.
- */
-const char *
-p_type(int type) {
-	int success;
-	const char *result;
-	static char typebuf[20];
-
-	result = sym_ntos(__p_type_syms, type, &success);
-	if (success)
-		return (result);
-	if (type < 0 || type > 0xffff)
-		return ("BADTYPE");
-	sprintf(typebuf, "TYPE%d", type);
-	return (typebuf);
-}
-
-/*
- * Return a string for the type.
- */
-const char *
-p_section(int section, int opcode) {
-	const struct res_sym *symbols;
-
-	switch (opcode) {
-	case ns_o_update:
-		symbols = __p_update_section_syms;
-		break;
-	default:
-		symbols = __p_default_section_syms;
-		break;
-	}
-	return (sym_ntos(symbols, section, (int *)0));
-}
-
-/*
- * Return a mnemonic for class.
- */
-const char *
-p_class(int class) {
-	int success;
-	const char *result;
-	static char classbuf[20];
-
-	result = sym_ntos(__p_class_syms, class, &success);
-	if (success)
-		return (result);
-	if (class < 0 || class > 0xffff)
-		return ("BADCLASS");
-	sprintf(classbuf, "CLASS%d", class);
-	return (classbuf);
-}
-
-/*
- * Return a mnemonic for an option
- */
-const char *
-p_option(u_long option) {
-	static char nbuf[40];
-
-	switch (option) {
-	case RES_INIT:		return "init";
-	case RES_DEBUG:		return "debug";
-	case RES_AAONLY:	return "aaonly(unimpl)";
-	case RES_USEVC:		return "usevc";
-	case RES_PRIMARY:	return "primry(unimpl)";
-	case RES_IGNTC:		return "igntc";
-	case RES_RECURSE:	return "recurs";
-	case RES_DEFNAMES:	return "defnam";
-	case RES_STAYOPEN:	return "styopn";
-	case RES_DNSRCH:	return "dnsrch";
-	case RES_INSECURE1:	return "insecure1";
-	case RES_INSECURE2:	return "insecure2";
-	case RES_NOALIASES:	return "noaliases";
-	case RES_USE_INET6:	return "inet6";
-#ifdef RES_USE_EDNS0	/* KAME extension */
-	case RES_USE_EDNS0:	return "edns0";
-#endif
-#ifdef RES_USE_DNAME
-	case RES_USE_DNAME:	return "dname";
-#endif
-#ifdef RES_USE_DNSSEC
-	case RES_USE_DNSSEC:	return "dnssec";
-#endif
-#ifdef RES_NOTLDQUERY
-	case RES_NOTLDQUERY:	return "no-tld-query";
-#endif
-#ifdef RES_NO_NIBBLE2
-	case RES_NO_NIBBLE2:	return "no-nibble2";
-#endif
-				/* XXX nonreentrant */
-	default:		sprintf(nbuf, "?0x%lx?", (u_long)option);
-				return (nbuf);
-	}
-}
-
-/*
- * Return a mnemonic for a time to live.
- */
-const char *
-p_time(u_int32_t value) {
-	static char nbuf[40];		/* XXX nonreentrant */
-
-	if (ns_format_ttl((u_long)value, nbuf, sizeof nbuf) < 0)
-		sprintf(nbuf, "%u", value);
-	return (nbuf);
-}
-
-/*
- * Return a string for the rcode.
- */
-const char *
-p_rcode(int rcode) {
-	return (sym_ntos(__p_rcode_syms, rcode, (int *)0));
-}
-
-/*
- * Return a string for a res_sockaddr_union.
- */
-const char *
-p_sockun(union res_sockaddr_union u, char *buf, size_t size) {
-	char ret[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:123.123.123.123"];
-
-	switch (u.sin.sin_family) {
-	case AF_INET:
-		inet_ntop(AF_INET, &u.sin.sin_addr, ret, sizeof ret);
-		break;
-#ifdef HAS_INET6_STRUCTS
-	case AF_INET6:
-		inet_ntop(AF_INET6, &u.sin6.sin6_addr, ret, sizeof ret);
-		break;
-#endif
-	default:
-		sprintf(ret, "[af%d]", u.sin.sin_family);
-		break;
-	}
-	if (size > 0U) {
-		strncpy(buf, ret, size - 1);
-		buf[size - 1] = '0';
-	}
-	return (buf);
-}
-
-/*
- * routines to convert between on-the-wire RR format and zone file format.
- * Does not contain conversion to/from decimal degrees; divide or multiply
- * by 60*60*1000 for that.
- */
-
-static const unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
-				      1000000,10000000,100000000,1000000000};
-
-/* takes an XeY precision/size value, returns a string representation. */
-static const char *
-precsize_ntoa(prec)
-	u_int32_t prec;
-{
-	static char retbuf[sizeof "90000000.00"];	/* XXX nonreentrant */
-	unsigned long val;
-	int mantissa, exponent;
-
-	mantissa = (int)((prec >> 4) & 0x0f) % 10;
-	exponent = (int)((prec >> 0) & 0x0f) % 10;
-
-	val = mantissa * poweroften[exponent];
-
-	(void) sprintf(retbuf, "%lu.%.2lu", val/100, val%100);
-	return (retbuf);
-}
-
-/* converts ascii size/precision X * 10**Y(cm) to 0xXY.  moves pointer. */
-static u_int8_t
-precsize_aton(const char **strptr) {
-	unsigned int mval = 0, cmval = 0;
-	u_int8_t retval = 0;
-	const char *cp;
-	int exponent;
-	int mantissa;
-
-	cp = *strptr;
-
-	while (isdigit((unsigned char)*cp))
-		mval = mval * 10 + (*cp++ - '0');
-
-	if (*cp == '.') {		/* centimeters */
-		cp++;
-		if (isdigit((unsigned char)*cp)) {
-			cmval = (*cp++ - '0') * 10;
-			if (isdigit((unsigned char)*cp)) {
-				cmval += (*cp++ - '0');
-			}
-		}
-	}
-	cmval = (mval * 100) + cmval;
-
-	for (exponent = 0; exponent < 9; exponent++)
-		if (cmval < poweroften[exponent+1])
-			break;
-
-	mantissa = cmval / poweroften[exponent];
-	if (mantissa > 9)
-		mantissa = 9;
-
-	retval = (mantissa << 4) | exponent;
-
-	*strptr = cp;
-
-	return (retval);
-}
-
-/* converts ascii lat/lon to unsigned encoded 32-bit number.  moves pointer. */
-static u_int32_t
-latlon2ul(const char **latlonstrptr, int *which) {
-	const char *cp;
-	u_int32_t retval;
-	int deg = 0, min = 0, secs = 0, secsfrac = 0;
-
-	cp = *latlonstrptr;
-
-	while (isdigit((unsigned char)*cp))
-		deg = deg * 10 + (*cp++ - '0');
-
-	while (isspace((unsigned char)*cp))
-		cp++;
-
-	if (!(isdigit((unsigned char)*cp)))
-		goto fndhemi;
-
-	while (isdigit((unsigned char)*cp))
-		min = min * 10 + (*cp++ - '0');
-
-	while (isspace((unsigned char)*cp))
-		cp++;
-
-	if (!(isdigit((unsigned char)*cp)))
-		goto fndhemi;
-
-	while (isdigit((unsigned char)*cp))
-		secs = secs * 10 + (*cp++ - '0');
-
-	if (*cp == '.') {		/* decimal seconds */
-		cp++;
-		if (isdigit((unsigned char)*cp)) {
-			secsfrac = (*cp++ - '0') * 100;
-			if (isdigit((unsigned char)*cp)) {
-				secsfrac += (*cp++ - '0') * 10;
-				if (isdigit((unsigned char)*cp)) {
-					secsfrac += (*cp++ - '0');
-				}
-			}
-		}
-	}
-
-	while (!isspace((unsigned char)*cp))	/* if any trailing garbage */
-		cp++;
-
-	while (isspace((unsigned char)*cp))
-		cp++;
-
- fndhemi:
-	switch (*cp) {
-	case 'N': case 'n':
-	case 'E': case 'e':
-		retval = ((unsigned)1<<31)
-			+ (((((deg * 60) + min) * 60) + secs) * 1000)
-			+ secsfrac;
-		break;
-	case 'S': case 's':
-	case 'W': case 'w':
-		retval = ((unsigned)1<<31)
-			- (((((deg * 60) + min) * 60) + secs) * 1000)
-			- secsfrac;
-		break;
-	default:
-		retval = 0;	/* invalid value -- indicates error */
-		break;
-	}
-
-	switch (*cp) {
-	case 'N': case 'n':
-	case 'S': case 's':
-		*which = 1;	/* latitude */
-		break;
-	case 'E': case 'e':
-	case 'W': case 'w':
-		*which = 2;	/* longitude */
-		break;
-	default:
-		*which = 0;	/* error */
-		break;
-	}
-
-	cp++;			/* skip the hemisphere */
-
-	while (!isspace((unsigned char)*cp))	/* if any trailing garbage */
-		cp++;
-
-	while (isspace((unsigned char)*cp))	/* move to next field */
-		cp++;
-
-	*latlonstrptr = cp;
-
-	return (retval);
-}
-
-/* converts a zone file representation in a string to an RDATA on-the-wire
- * representation. */
-int
-loc_aton(ascii, binary)
-	const char *ascii;
-	u_char *binary;
-{
-	const char *cp, *maxcp;
-	u_char *bcp;
-
-	u_int32_t latit = 0, longit = 0, alt = 0;
-	u_int32_t lltemp1 = 0, lltemp2 = 0;
-	int altmeters = 0, altfrac = 0, altsign = 1;
-	u_int8_t hp = 0x16;	/* default = 1e6 cm = 10000.00m = 10km */
-	u_int8_t vp = 0x13;	/* default = 1e3 cm = 10.00m */
-	u_int8_t siz = 0x12;	/* default = 1e2 cm = 1.00m */
-	int which1 = 0, which2 = 0;
-
-	cp = ascii;
-	maxcp = cp + strlen(ascii);
-
-	lltemp1 = latlon2ul(&cp, &which1);
-
-	lltemp2 = latlon2ul(&cp, &which2);
-
-	switch (which1 + which2) {
-	case 3:			/* 1 + 2, the only valid combination */
-		if ((which1 == 1) && (which2 == 2)) { /* normal case */
-			latit = lltemp1;
-			longit = lltemp2;
-		} else if ((which1 == 2) && (which2 == 1)) { /* reversed */
-			longit = lltemp1;
-			latit = lltemp2;
-		} else {	/* some kind of brokenness */
-			return (0);
-		}
-		break;
-	default:		/* we didn't get one of each */
-		return (0);
-	}
-
-	/* altitude */
-	if (*cp == '-') {
-		altsign = -1;
-		cp++;
-	}
-
-	if (*cp == '+')
-		cp++;
-
-	while (isdigit((unsigned char)*cp))
-		altmeters = altmeters * 10 + (*cp++ - '0');
-
-	if (*cp == '.') {		/* decimal meters */
-		cp++;
-		if (isdigit((unsigned char)*cp)) {
-			altfrac = (*cp++ - '0') * 10;
-			if (isdigit((unsigned char)*cp)) {
-				altfrac += (*cp++ - '0');
-			}
-		}
-	}
-
-	alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
-
-	while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
-		cp++;
-
-	while (isspace((unsigned char)*cp) && (cp < maxcp))
-		cp++;
-
-	if (cp >= maxcp)
-		goto defaults;
-
-	siz = precsize_aton(&cp);
-
-	while (!isspace((unsigned char)*cp) && (cp < maxcp))	/* if trailing garbage or m */
-		cp++;
-
-	while (isspace((unsigned char)*cp) && (cp < maxcp))
-		cp++;
-
-	if (cp >= maxcp)
-		goto defaults;
-
-	hp = precsize_aton(&cp);
-
-	while (!isspace((unsigned char)*cp) && (cp < maxcp))	/* if trailing garbage or m */
-		cp++;
-
-	while (isspace((unsigned char)*cp) && (cp < maxcp))
-		cp++;
-
-	if (cp >= maxcp)
-		goto defaults;
-
-	vp = precsize_aton(&cp);
-
- defaults:
-
-	bcp = binary;
-	*bcp++ = (u_int8_t) 0;	/* version byte */
-	*bcp++ = siz;
-	*bcp++ = hp;
-	*bcp++ = vp;
-	PUTLONG(latit,bcp);
-	PUTLONG(longit,bcp);
-	PUTLONG(alt,bcp);
-
-	return (16);		/* size of RR in octets */
-}
-
-/* takes an on-the-wire LOC RR and formats it in a human readable format. */
-const char *
-loc_ntoa(binary, ascii)
-	const u_char *binary;
-	char *ascii;
-{
-	static const char *error = "?";
-	static char tmpbuf[sizeof
-"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
-	const u_char *cp = binary;
-
-	int latdeg, latmin, latsec, latsecfrac;
-	int longdeg, longmin, longsec, longsecfrac;
-	char northsouth, eastwest;
-	const char *altsign;
-	int altmeters, altfrac;
-
-	const u_int32_t referencealt = 100000 * 100;
-
-	int32_t latval, longval, altval;
-	u_int32_t templ;
-	u_int8_t sizeval, hpval, vpval, versionval;
-
-	char *sizestr, *hpstr, *vpstr;
-
-	versionval = *cp++;
-
-	if (ascii == NULL)
-		ascii = tmpbuf;
-
-	if (versionval) {
-		(void) sprintf(ascii, "; error: unknown LOC RR version");
-		return (ascii);
-	}
-
-	sizeval = *cp++;
-
-	hpval = *cp++;
-	vpval = *cp++;
-
-	GETLONG(templ, cp);
-	latval = (templ - ((unsigned)1<<31));
-
-	GETLONG(templ, cp);
-	longval = (templ - ((unsigned)1<<31));
-
-	GETLONG(templ, cp);
-	if (templ < referencealt) { /* below WGS 84 spheroid */
-		altval = referencealt - templ;
-		altsign = "-";
-	} else {
-		altval = templ - referencealt;
-		altsign = "";
-	}
-
-	if (latval < 0) {
-		northsouth = 'S';
-		latval = -latval;
-	} else
-		northsouth = 'N';
-
-	latsecfrac = latval % 1000;
-	latval = latval / 1000;
-	latsec = latval % 60;
-	latval = latval / 60;
-	latmin = latval % 60;
-	latval = latval / 60;
-	latdeg = latval;
-
-	if (longval < 0) {
-		eastwest = 'W';
-		longval = -longval;
-	} else
-		eastwest = 'E';
-
-	longsecfrac = longval % 1000;
-	longval = longval / 1000;
-	longsec = longval % 60;
-	longval = longval / 60;
-	longmin = longval % 60;
-	longval = longval / 60;
-	longdeg = longval;
-
-	altfrac = altval % 100;
-	altmeters = (altval / 100);
-
-	sizestr = strdup(precsize_ntoa((u_int32_t)sizeval));
-	hpstr = strdup(precsize_ntoa((u_int32_t)hpval));
-	vpstr = strdup(precsize_ntoa((u_int32_t)vpval));
-
-	sprintf(ascii,
-	    "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %s%d.%.2dm %sm %sm %sm",
-		latdeg, latmin, latsec, latsecfrac, northsouth,
-		longdeg, longmin, longsec, longsecfrac, eastwest,
-		altsign, altmeters, altfrac,
-		(sizestr != NULL) ? sizestr : error,
-		(hpstr != NULL) ? hpstr : error,
-		(vpstr != NULL) ? vpstr : error);
-
-	if (sizestr != NULL)
-		free(sizestr);
-	if (hpstr != NULL)
-		free(hpstr);
-	if (vpstr != NULL)
-		free(vpstr);
-
-	return (ascii);
-}
-
-
-/* Return the number of DNS hierarchy levels in the name. */
-int
-dn_count_labels(const char *name) {
-	int i, len, count;
-
-	len = strlen(name);
-	for (i = 0, count = 0; i < len; i++) {
-		/* XXX need to check for \. or use named's nlabels(). */
-		if (name[i] == '.')
-			count++;
-	}
-
-	/* don't count initial wildcard */
-	if (name[0] == '*')
-		if (count)
-			count--;
-
-	/* don't count the null label for root. */
-	/* if terminating '.' not found, must adjust */
-	/* count to include last label */
-	if (len > 0 && name[len-1] != '.')
-		count++;
-	return (count);
-}
-
-
-/*
- * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
- * SIG records are required to be printed like this, by the Secure DNS RFC.
- */
-char *
-p_secstodate (u_long secs) {
-	/* XXX nonreentrant */
-	static char output[15];		/* YYYYMMDDHHMMSS and null */
-	time_t myclock = secs;
-	struct tm *mytime;
-#ifdef HAVE_TIME_R
-	struct tm res;
-
-	mytime = gmtime_r(&myclock, &res);
-#else
-	mytime = gmtime(&myclock);
-#endif
-	mytime->tm_year += 1900;
-	mytime->tm_mon += 1;
-	sprintf(output, "%04d%02d%02d%02d%02d%02d",
-		mytime->tm_year, mytime->tm_mon, mytime->tm_mday,
-		mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
-	return (output);
-}
-
-u_int16_t
-res_nametoclass(const char *buf, int *successp) {
-	unsigned long result;
-	char *endptr;
-	int success;
-
-	result = sym_ston(__p_class_syms, buf, &success);
-	if (success)
-		goto done;
-
-	if (strncasecmp(buf, "CLASS", 5) != 0 ||
-	    !isdigit((unsigned char)buf[5]))
-		goto done;
-	errno = 0;
-	result = strtoul(buf + 5, &endptr, 10);
-	if (errno == 0 && *endptr == '\0' && result <= 0xffffU)
-		success = 1;
- done:
-	if (successp)
-		*successp = success;
-	return (u_int16_t)(result);
-}
-
-u_int16_t
-res_nametotype(const char *buf, int *successp) {
-	unsigned long result;
-	char *endptr;
-	int success;
-
-	result = sym_ston(__p_type_syms, buf, &success);
-	if (success)
-		goto done;
-
-	if (strncasecmp(buf, "type", 4) != 0 ||
-	    !isdigit((unsigned char)buf[4]))
-		goto done;
-	errno = 0;
-	result = strtoul(buf + 4, &endptr, 10);
-	if (errno == 0 && *endptr == '\0' && result <= 0xffffU)
-		success = 1;
- done:
-	if (successp)
-		*successp = success;
-	return (u_int16_t)(result);
-}
diff --git a/libc/netbsd/resolv/res_init.c b/libc/netbsd/resolv/res_init.c
deleted file mode 100644
index ceb412b..0000000
--- a/libc/netbsd/resolv/res_init.c
+++ /dev/null
@@ -1,816 +0,0 @@
-/*	$NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $	*/
-
-/*
- * Copyright (c) 1985, 1989, 1993
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#ifdef notdef
-static const char sccsid[] = "@(#)res_init.c	8.1 (Berkeley) 6/7/93";
-static const char rcsid[] = "Id: res_init.c,v 1.9.2.5.4.2 2004/03/16 12:34:18 marka Exp";
-#else
-__RCSID("$NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netdb.h>
-
-#ifdef ANDROID_CHANGES
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/system_properties.h>
-#endif /* ANDROID_CHANGES */
-
-#ifndef MIN
-#define	MIN(x,y)	((x)<(y)?(x):(y))
-#endif
-
-/* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-
-#include "res_private.h"
-
-/* Options.  Should all be left alone. */
-#ifndef DEBUG
-#define DEBUG
-#endif
-
-static void res_setoptions __P((res_state, const char *, const char *));
-
-static const char sort_mask[] = "/&";
-#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
-static u_int32_t net_mask __P((struct in_addr));
-
-#if !defined(isascii)	/* XXX - could be a function */
-# define isascii(c) (!(c & 0200))
-#endif
-
-/*
- * Resolver state default settings.
- */
-
-/*
- * Set up default settings.  If the configuration file exist, the values
- * there will have precedence.  Otherwise, the server address is set to
- * INADDR_ANY and the default domain name comes from the gethostname().
- *
- * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
- * rather than INADDR_ANY ("0.0.0.0") as the default name server address
- * since it was noted that INADDR_ANY actually meant ``the first interface
- * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
- * it had to be "up" in order for you to reach your own name server.  It
- * was later decided that since the recommended practice is to always
- * install local static routes through 127.0.0.1 for all your network
- * interfaces, that we could solve this problem without a code change.
- *
- * The configuration file should always be used, since it is the only way
- * to specify a default domain.  If you are running a server on your local
- * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
- * in the configuration file.
- *
- * Return 0 if completes successfully, -1 on error
- */
-int
-res_ninit(res_state statp) {
-	extern int __res_vinit(res_state, int);
-
-	return (__res_vinit(statp, 0));
-}
-
-/* This function has to be reachable by res_data.c but not publicly. */
-int
-__res_vinit(res_state statp, int preinit) {
-	register FILE *fp;
-	register char *cp, **pp;
-	register int n;
-	char buf[BUFSIZ];
-	int nserv = 0;    /* number of nameserver records read from file */
-	int haveenv = 0;
-	int havesearch = 0;
-	int nsort = 0;
-	char *net;
-	int dots;
-	union res_sockaddr_union u[2];
-
-        if ((statp->options & RES_INIT) != 0U)
-                res_ndestroy(statp);
-
-	if (!preinit) {
-		statp->retrans = RES_TIMEOUT;
-		statp->retry = RES_DFLRETRY;
-		statp->options = RES_DEFAULT;
-		statp->id = res_randomid();
-	}
-
-	memset(u, 0, sizeof(u));
-#ifdef USELOOPBACK
-	u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
-#else
-	u[nserv].sin.sin_addr.s_addr = INADDR_ANY;
-#endif
-	u[nserv].sin.sin_family = AF_INET;
-	u[nserv].sin.sin_port = htons(NAMESERVER_PORT);
-#ifdef HAVE_SA_LEN
-	u[nserv].sin.sin_len = sizeof(struct sockaddr_in);
-#endif
-	nserv++;
-#ifdef HAS_INET6_STRUCTS
-#ifdef USELOOPBACK
-	u[nserv].sin6.sin6_addr = in6addr_loopback;
-#else
-	u[nserv].sin6.sin6_addr = in6addr_any;
-#endif
-	u[nserv].sin6.sin6_family = AF_INET6;
-	u[nserv].sin6.sin6_port = htons(NAMESERVER_PORT);
-#ifdef HAVE_SA_LEN
-	u[nserv].sin6.sin6_len = sizeof(struct sockaddr_in6);
-#endif
-	nserv++;
-#endif
-	statp->nscount = 0;
-	statp->ndots = 1;
-	statp->pfcode = 0;
-	statp->_vcsock = -1;
-	statp->_flags = 0;
-	statp->qhook = NULL;
-	statp->rhook = NULL;
-	statp->_u._ext.nscount = 0;
-	statp->_u._ext.ext = malloc(sizeof(*statp->_u._ext.ext));
-	if (statp->_u._ext.ext != NULL) {
-	        memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext));
-		statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr;
-		strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa");
-		strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int");
-	}
-	statp->nsort = 0;
-	res_setservers(statp, u, nserv);
-
-#if 0 /* IGNORE THE ENVIRONMENT */
-	/* Allow user to override the local domain definition */
-	if ((cp = getenv("LOCALDOMAIN")) != NULL) {
-		(void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
-		statp->defdname[sizeof(statp->defdname) - 1] = '\0';
-		haveenv++;
-
-		/*
-		 * Set search list to be blank-separated strings
-		 * from rest of env value.  Permits users of LOCALDOMAIN
-		 * to still have a search list, and anyone to set the
-		 * one that they want to use as an individual (even more
-		 * important now that the rfc1535 stuff restricts searches)
-		 */
-		cp = statp->defdname;
-		pp = statp->dnsrch;
-		*pp++ = cp;
-		for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
-			if (*cp == '\n')	/* silly backwards compat */
-				break;
-			else if (*cp == ' ' || *cp == '\t') {
-				*cp = 0;
-				n = 1;
-			} else if (n) {
-				*pp++ = cp;
-				n = 0;
-				havesearch = 1;
-			}
-		}
-		/* null terminate last domain if there are excess */
-		while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
-			cp++;
-		*cp = '\0';
-		*pp++ = 0;
-	}
-	if (nserv > 0)
-		statp->nscount = nserv;
-#endif
-
-#ifndef ANDROID_CHANGES /* !ANDROID_CHANGES - IGNORE resolv.conf in Android */
-#define	MATCH(line, name) \
-	(!strncmp(line, name, sizeof(name) - 1) && \
-	(line[sizeof(name) - 1] == ' ' || \
-	 line[sizeof(name) - 1] == '\t'))
-
-	nserv = 0;
-	if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
-	    /* read the config file */
-	    while (fgets(buf, sizeof(buf), fp) != NULL) {
-		/* skip comments */
-		if (*buf == ';' || *buf == '#')
-			continue;
-		/* read default domain name */
-		if (MATCH(buf, "domain")) {
-		    if (haveenv)	/* skip if have from environ */
-			    continue;
-		    cp = buf + sizeof("domain") - 1;
-		    while (*cp == ' ' || *cp == '\t')
-			    cp++;
-		    if ((*cp == '\0') || (*cp == '\n'))
-			    continue;
-		    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
-		    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
-		    if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL)
-			    *cp = '\0';
-		    havesearch = 0;
-		    continue;
-		}
-		/* set search list */
-		if (MATCH(buf, "search")) {
-		    if (haveenv)	/* skip if have from environ */
-			    continue;
-		    cp = buf + sizeof("search") - 1;
-		    while (*cp == ' ' || *cp == '\t')
-			    cp++;
-		    if ((*cp == '\0') || (*cp == '\n'))
-			    continue;
-		    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
-		    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
-		    if ((cp = strchr(statp->defdname, '\n')) != NULL)
-			    *cp = '\0';
-		    /*
-		     * Set search list to be blank-separated strings
-		     * on rest of line.
-		     */
-		    cp = statp->defdname;
-		    pp = statp->dnsrch;
-		    *pp++ = cp;
-		    for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
-			    if (*cp == ' ' || *cp == '\t') {
-				    *cp = 0;
-				    n = 1;
-			    } else if (n) {
-				    *pp++ = cp;
-				    n = 0;
-			    }
-		    }
-		    /* null terminate last domain if there are excess */
-		    while (*cp != '\0' && *cp != ' ' && *cp != '\t')
-			    cp++;
-		    *cp = '\0';
-		    *pp++ = 0;
-		    havesearch = 1;
-		    continue;
-		}
-		/* read nameservers to query */
-		if (MATCH(buf, "nameserver") && nserv < MAXNS) {
-		    struct addrinfo hints, *ai;
-		    char sbuf[NI_MAXSERV];
-		    const size_t minsiz =
-		        sizeof(statp->_u._ext.ext->nsaddrs[0]);
-
-		    cp = buf + sizeof("nameserver") - 1;
-		    while (*cp == ' ' || *cp == '\t')
-			cp++;
-		    cp[strcspn(cp, ";# \t\n")] = '\0';
-		    if ((*cp != '\0') && (*cp != '\n')) {
-			memset(&hints, 0, sizeof(hints));
-			hints.ai_family = PF_UNSPEC;
-			hints.ai_socktype = SOCK_DGRAM;	/*dummy*/
-			hints.ai_flags = AI_NUMERICHOST;
-			sprintf(sbuf, "%u", NAMESERVER_PORT);
-			if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 &&
-			    ai->ai_addrlen <= minsiz) {
-			    if (statp->_u._ext.ext != NULL) {
-				memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
-				    ai->ai_addr, ai->ai_addrlen);
-			    }
-			    if (ai->ai_addrlen <=
-			        sizeof(statp->nsaddr_list[nserv])) {
-				memcpy(&statp->nsaddr_list[nserv],
-				    ai->ai_addr, ai->ai_addrlen);
-			    } else
-				statp->nsaddr_list[nserv].sin_family = 0;
-			    freeaddrinfo(ai);
-			    nserv++;
-			}
-		    }
-		    continue;
-		}
-		if (MATCH(buf, "sortlist")) {
-		    struct in_addr a;
-
-		    cp = buf + sizeof("sortlist") - 1;
-		    while (nsort < MAXRESOLVSORT) {
-			while (*cp == ' ' || *cp == '\t')
-			    cp++;
-			if (*cp == '\0' || *cp == '\n' || *cp == ';')
-			    break;
-			net = cp;
-			while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
-			       isascii(*cp) && !isspace((unsigned char)*cp))
-				cp++;
-			n = *cp;
-			*cp = 0;
-			if (inet_aton(net, &a)) {
-			    statp->sort_list[nsort].addr = a;
-			    if (ISSORTMASK(n)) {
-				*cp++ = n;
-				net = cp;
-				while (*cp && *cp != ';' &&
-					isascii(*cp) &&
-					!isspace((unsigned char)*cp))
-				    cp++;
-				n = *cp;
-				*cp = 0;
-				if (inet_aton(net, &a)) {
-				    statp->sort_list[nsort].mask = a.s_addr;
-				} else {
-				    statp->sort_list[nsort].mask =
-					net_mask(statp->sort_list[nsort].addr);
-				}
-			    } else {
-				statp->sort_list[nsort].mask =
-				    net_mask(statp->sort_list[nsort].addr);
-			    }
-			    nsort++;
-			}
-			*cp = n;
-		    }
-		    continue;
-		}
-		if (MATCH(buf, "options")) {
-		    res_setoptions(statp, buf + sizeof("options") - 1, "conf");
-		    continue;
-		}
-	    }
-	    if (nserv > 0)
-		statp->nscount = nserv;
-	    statp->nsort = nsort;
-	    (void) fclose(fp);
-	}
-#endif /* !ANDROID_CHANGES */
-/*
- * Last chance to get a nameserver.  This should not normally
- * be necessary
- */
-#ifdef NO_RESOLV_CONF
-	if(nserv == 0)
-		nserv = get_nameservers(statp);
-#endif
-
-	if (statp->defdname[0] == 0 &&
-	    gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
-	    (cp = strchr(buf, '.')) != NULL)
-		strcpy(statp->defdname, cp + 1);
-
-	/* find components of local domain that might be searched */
-	if (havesearch == 0) {
-		pp = statp->dnsrch;
-		*pp++ = statp->defdname;
-		*pp = NULL;
-
-		dots = 0;
-		for (cp = statp->defdname; *cp; cp++)
-			dots += (*cp == '.');
-
-		cp = statp->defdname;
-		while (pp < statp->dnsrch + MAXDFLSRCH) {
-			if (dots < LOCALDOMAINPARTS)
-				break;
-			cp = strchr(cp, '.') + 1;    /* we know there is one */
-			*pp++ = cp;
-			dots--;
-		}
-		*pp = NULL;
-#ifdef DEBUG
-		if (statp->options & RES_DEBUG) {
-			printf(";; res_init()... default dnsrch list:\n");
-			for (pp = statp->dnsrch; *pp; pp++)
-				printf(";;\t%s\n", *pp);
-			printf(";;\t..END..\n");
-		}
-#endif
-	}
-
-	if ((cp = getenv("RES_OPTIONS")) != NULL)
-		res_setoptions(statp, cp, "env");
-	if (nserv > 0) {
-		statp->nscount = nserv;
-		statp->options |= RES_INIT;
-	}
-	return (0);
-}
-
-static void
-res_setoptions(res_state statp, const char *options, const char *source)
-{
-	const char *cp = options;
-	int i;
-	struct __res_state_ext *ext = statp->_u._ext.ext;
-
-#ifdef DEBUG
-	if (statp->options & RES_DEBUG)
-		printf(";; res_setoptions(\"%s\", \"%s\")...\n",
-		       options, source);
-#endif
-	while (*cp) {
-		/* skip leading and inner runs of spaces */
-		while (*cp == ' ' || *cp == '\t')
-			cp++;
-		/* search for and process individual options */
-		if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
-			i = atoi(cp + sizeof("ndots:") - 1);
-			if (i <= RES_MAXNDOTS)
-				statp->ndots = i;
-			else
-				statp->ndots = RES_MAXNDOTS;
-#ifdef DEBUG
-			if (statp->options & RES_DEBUG)
-				printf(";;\tndots=%d\n", statp->ndots);
-#endif
-		} else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
-			i = atoi(cp + sizeof("timeout:") - 1);
-			if (i <= RES_MAXRETRANS)
-				statp->retrans = i;
-			else
-				statp->retrans = RES_MAXRETRANS;
-#ifdef DEBUG
-			if (statp->options & RES_DEBUG)
-				printf(";;\ttimeout=%d\n", statp->retrans);
-#endif
-		} else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
-			i = atoi(cp + sizeof("attempts:") - 1);
-			if (i <= RES_MAXRETRY)
-				statp->retry = i;
-			else
-				statp->retry = RES_MAXRETRY;
-#ifdef DEBUG
-			if (statp->options & RES_DEBUG)
-				printf(";;\tattempts=%d\n", statp->retry);
-#endif
-		} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
-#ifdef DEBUG
-			if (!(statp->options & RES_DEBUG)) {
-				printf(";; res_setoptions(\"%s\", \"%s\")..\n",
-				       options, source);
-				statp->options |= RES_DEBUG;
-			}
-			printf(";;\tdebug\n");
-#endif
-		} else if (!strncmp(cp, "no_tld_query",
-				    sizeof("no_tld_query") - 1) ||
-			   !strncmp(cp, "no-tld-query",
-				    sizeof("no-tld-query") - 1)) {
-			statp->options |= RES_NOTLDQUERY;
-		} else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
-			statp->options |= RES_USE_INET6;
-		} else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
-			statp->options |= RES_ROTATE;
-		} else if (!strncmp(cp, "no-check-names",
-				    sizeof("no-check-names") - 1)) {
-			statp->options |= RES_NOCHECKNAME;
-		}
-#ifdef RES_USE_EDNS0
-		else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
-			statp->options |= RES_USE_EDNS0;
-		}
-#endif
-		else if (!strncmp(cp, "dname", sizeof("dname") - 1)) {
-			statp->options |= RES_USE_DNAME;
-		}
-		else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) {
-			if (ext == NULL)
-				goto skip;
-			cp += sizeof("nibble:") - 1;
-			i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1);
-			strncpy(ext->nsuffix, cp, (size_t)i);
-			ext->nsuffix[i] = '\0';
-		}
-		else if (!strncmp(cp, "nibble2:", sizeof("nibble2:") - 1)) {
-			if (ext == NULL)
-				goto skip;
-			cp += sizeof("nibble2:") - 1;
-			i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1);
-			strncpy(ext->nsuffix2, cp, (size_t)i);
-			ext->nsuffix2[i] = '\0';
-		}
-		else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) {
-			cp += sizeof("v6revmode:") - 1;
-			/* "nibble" and "bitstring" used to be valid */
-			if (!strncmp(cp, "single", sizeof("single") - 1)) {
-				statp->options |= RES_NO_NIBBLE2;
-			} else if (!strncmp(cp, "both", sizeof("both") - 1)) {
-				statp->options &=
-					 ~RES_NO_NIBBLE2;
-			}
-		}
-		else {
-			/* XXX - print a warning here? */
-		}
-   skip:
-		/* skip to next run of spaces */
-		while (*cp && *cp != ' ' && *cp != '\t')
-			cp++;
-	}
-}
-
-/* XXX - should really support CIDR which means explicit masks always. */
-static u_int32_t
-net_mask(in)		/* XXX - should really use system's version of this */
-	struct in_addr in;
-{
-	register u_int32_t i = ntohl(in.s_addr);
-
-	if (IN_CLASSA(i))
-		return (htonl(IN_CLASSA_NET));
-	else if (IN_CLASSB(i))
-		return (htonl(IN_CLASSB_NET));
-	return (htonl(IN_CLASSC_NET));
-}
-
-#ifdef ANDROID_CHANGES
-static int
-real_randomid(u_int *random_value) {
-	/* open the nonblocking random device, returning -1 on failure */
-	int random_device = open("/dev/urandom", O_RDONLY);
-	if (random_device < 0) {
-		return -1;
-	}
-
-	/* read from the random device, returning -1 on failure (or too many retries)*/
-	u_int retry = 5;
-	for (retry; retry > 0; retry--) {
-		int retval = read(random_device, random_value, sizeof(u_int));
-		if (retval == sizeof(u_int)) {
-			*random_value &= 0xffff;
-			close(random_device);
-			return 0;
-		} else if ((retval < 0) && (errno != EINTR)) {
-			break;
-		}
-	}
-
-	close(random_device);
-	return -1;
-}
-#endif /* ANDROID_CHANGES */
-
-u_int
-res_randomid(void) {
-#ifdef ANDROID_CHANGES
-	int status = 0;
-	u_int output = 0;
-	status = real_randomid(&output);
-	if (status != -1) {
-		return output;
-	}
-#endif /* ANDROID_CHANGES */
-	struct timeval now;
-	gettimeofday(&now, NULL);
-	return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
-}
-
-/*
- * This routine is for closing the socket if a virtual circuit is used and
- * the program wants to close it.  This provides support for endhostent()
- * which expects to close the socket.
- *
- * This routine is not expected to be user visible.
- */
-void
-res_nclose(res_state statp) {
-	int ns;
-
-	if (statp->_vcsock >= 0) {
-		(void) close(statp->_vcsock);
-		statp->_vcsock = -1;
-		statp->_flags &= ~(RES_F_VC | RES_F_CONN);
-	}
-	for (ns = 0; ns < statp->_u._ext.nscount; ns++) {
-		if (statp->_u._ext.nssocks[ns] != -1) {
-			(void) close(statp->_u._ext.nssocks[ns]);
-			statp->_u._ext.nssocks[ns] = -1;
-		}
-	}
-}
-
-void
-res_ndestroy(res_state statp) {
-	res_nclose(statp);
-	if (statp->_u._ext.ext != NULL)
-		free(statp->_u._ext.ext);
-	statp->options &= ~RES_INIT;
-	statp->_u._ext.ext = NULL;
-}
-
-const char *
-res_get_nibblesuffix(res_state statp) {
-	if (statp->_u._ext.ext)
-		return (statp->_u._ext.ext->nsuffix);
-	return ("ip6.arpa");
-}
-
-const char *
-res_get_nibblesuffix2(res_state statp) {
-	if (statp->_u._ext.ext)
-		return (statp->_u._ext.ext->nsuffix2);
-	return ("ip6.int");
-}
-
-void
-res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) {
-	int i, nserv;
-	size_t size;
-
-	/* close open servers */
-	res_nclose(statp);
-
-	/* cause rtt times to be forgotten */
-	statp->_u._ext.nscount = 0;
-
-	nserv = 0;
-	for (i = 0; i < cnt && nserv < MAXNS; i++) {
-		switch (set->sin.sin_family) {
-		case AF_INET:
-			size = sizeof(set->sin);
-			if (statp->_u._ext.ext)
-				memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
-					&set->sin, size);
-			if (size <= sizeof(statp->nsaddr_list[nserv]))
-				memcpy(&statp->nsaddr_list[nserv],
-					&set->sin, size);
-#ifdef notdef
-			else
-				statp->nsaddr_list[nserv].sin_family = 0;
-#endif
-			nserv++;
-			break;
-
-#ifdef HAS_INET6_STRUCTS
-		case AF_INET6:
-			size = sizeof(set->sin6);
-			if (statp->_u._ext.ext)
-				memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
-					&set->sin6, size);
-			if (size <= sizeof(statp->nsaddr_list[nserv]))
-				memcpy(&statp->nsaddr_list[nserv],
-					&set->sin6, size);
-			else
-				statp->nsaddr_list[nserv].sin_family = 0;
-			nserv++;
-			break;
-#endif
-
-		default:
-			break;
-		}
-		set++;
-	}
-	statp->nscount = nserv;
-
-}
-
-int
-res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) {
-	int i;
-	size_t size;
-	u_int16_t family;
-
-	for (i = 0; i < statp->nscount && i < cnt; i++) {
-		if (statp->_u._ext.ext)
-			family = statp->_u._ext.ext->nsaddrs[i].sin.sin_family;
-		else
-			family = statp->nsaddr_list[i].sin_family;
-
-		switch (family) {
-		case AF_INET:
-			size = sizeof(set->sin);
-			if (statp->_u._ext.ext)
-				memcpy(&set->sin,
-				       &statp->_u._ext.ext->nsaddrs[i],
-				       size);
-			else
-				memcpy(&set->sin, &statp->nsaddr_list[i],
-				       size);
-			break;
-
-#ifdef HAS_INET6_STRUCTS
-		case AF_INET6:
-			size = sizeof(set->sin6);
-			if (statp->_u._ext.ext)
-				memcpy(&set->sin6,
-				       &statp->_u._ext.ext->nsaddrs[i],
-				       size);
-			else
-				memcpy(&set->sin6, &statp->nsaddr_list[i],
-				       size);
-			break;
-#endif
-
-		default:
-			set->sin.sin_family = 0;
-			break;
-		}
-		set++;
-	}
-	return (statp->nscount);
-}
-
-#ifdef ANDROID_CHANGES
-void res_setiface(res_state statp, const char* iface)
-{
-	if (statp != NULL) {
-		// set interface
-		if (iface && iface[0] != '\0') {
-			int len = sizeof(statp->iface);
-			strncpy(statp->iface, iface, len - 1);
-			statp->iface[len - 1] = '\0';
-		} else {
-			statp->iface[0] = '\0';
-		}
-	}
-}
-
-void res_setmark(res_state statp, int mark)
-{
-	if (statp != NULL) {
-		statp->_mark = mark;
-	}
-}
-#endif /* ANDROID_CHANGES */
diff --git a/libc/netbsd/resolv/res_mkquery.c b/libc/netbsd/resolv/res_mkquery.c
deleted file mode 100644
index fb4de7f..0000000
--- a/libc/netbsd/resolv/res_mkquery.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/*	$NetBSD: res_mkquery.c,v 1.6 2006/01/24 17:40:32 christos Exp $	*/
-
-/*
- * Copyright (c) 2008  Android Open Source Project (query id randomization)
- * Copyright (c) 1985, 1993
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#ifdef notdef
-static const char sccsid[] = "@(#)res_mkquery.c	8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "Id: res_mkquery.c,v 1.1.2.2.4.2 2004/03/16 12:34:18 marka Exp";
-#else
-__RCSID("$NetBSD: res_mkquery.c,v 1.6 2006/01/24 17:40:32 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include "arpa_nameser.h"
-#include <netdb.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <stdio.h>
-#include <string.h>
-
-/* Options.  Leave them on. */
-#ifndef DEBUG
-#define DEBUG
-#endif
-
-#ifndef lint
-#define UNUSED(a)	(void)&a
-#else
-#define UNUSED(a)	a = a
-#endif
-
-extern const char *_res_opcodes[];
-
-/*
- * Form all types of queries.
- * Returns the size of the result or -1.
- */
-int
-res_nmkquery(res_state statp,
-	     int op,			/* opcode of query */
-	     const char *dname,		/* domain name */
-	     int class, int type,	/* class and type of query */
-	     const u_char *data,	/* resource record data */
-	     int datalen,		/* length of data */
-	     const u_char *newrr_in,	/* new rr for modify or append */
-	     u_char *buf,		/* buffer to put query */
-	     int buflen)		/* size of buffer */
-{
-	register HEADER *hp;
-	register u_char *cp, *ep;
-	register int n;
-	u_char *dnptrs[20], **dpp, **lastdnptr;
-
-	UNUSED(newrr_in);
-
-#ifdef DEBUG
-	if (statp->options & RES_DEBUG)
-		printf(";; res_nmkquery(%s, %s, %s, %s)\n",
-		       _res_opcodes[op], dname, p_class(class), p_type(type));
-#endif
-	/*
-	 * Initialize header fields.
-	 */
-	if ((buf == NULL) || (buflen < HFIXEDSZ))
-		return (-1);
-	memset(buf, 0, HFIXEDSZ);
-	hp = (HEADER *)(void *)buf;
-	hp->id = htons(res_randomid());
-	hp->opcode = op;
-	hp->rd = (statp->options & RES_RECURSE) != 0U;
-	hp->rcode = NOERROR;
-	cp = buf + HFIXEDSZ;
-	ep = buf + buflen;
-	dpp = dnptrs;
-	*dpp++ = buf;
-	*dpp++ = NULL;
-	lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
-	/*
-	 * perform opcode specific processing
-	 */
-	switch (op) {
-	case QUERY:	/*FALLTHROUGH*/
-	case NS_NOTIFY_OP:
-		if (ep - cp < QFIXEDSZ)
-			return (-1);
-		if ((n = dn_comp(dname, cp, ep - cp - QFIXEDSZ, dnptrs,
-		    lastdnptr)) < 0)
-			return (-1);
-		cp += n;
-		ns_put16(type, cp);
-		cp += INT16SZ;
-		ns_put16(class, cp);
-		cp += INT16SZ;
-		hp->qdcount = htons(1);
-		if (op == QUERY || data == NULL)
-			break;
-		/*
-		 * Make an additional record for completion domain.
-		 */
-		if ((ep - cp) < RRFIXEDSZ)
-			return (-1);
-		n = dn_comp((const char *)data, cp, ep - cp - RRFIXEDSZ,
-			    dnptrs, lastdnptr);
-		if (n < 0)
-			return (-1);
-		cp += n;
-		ns_put16(T_NULL, cp);
-		cp += INT16SZ;
-		ns_put16(class, cp);
-		cp += INT16SZ;
-		ns_put32(0, cp);
-		cp += INT32SZ;
-		ns_put16(0, cp);
-		cp += INT16SZ;
-		hp->arcount = htons(1);
-		break;
-
-	case IQUERY:
-		/*
-		 * Initialize answer section
-		 */
-		if (ep - cp < 1 + RRFIXEDSZ + datalen)
-			return (-1);
-		*cp++ = '\0';	/* no domain name */
-		ns_put16(type, cp);
-		cp += INT16SZ;
-		ns_put16(class, cp);
-		cp += INT16SZ;
-		ns_put32(0, cp);
-		cp += INT32SZ;
-		ns_put16(datalen, cp);
-		cp += INT16SZ;
-		if (datalen) {
-			memcpy(cp, data, (size_t)datalen);
-			cp += datalen;
-		}
-		hp->ancount = htons(1);
-		break;
-
-	default:
-		return (-1);
-	}
-	return (cp - buf);
-}
-
-#ifdef RES_USE_EDNS0
-/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
-#ifndef T_OPT
-#define T_OPT	41
-#endif
-
-int
-res_nopt(res_state statp,
-	 int n0,		/* current offset in buffer */
-	 u_char *buf,		/* buffer to put query */
-	 int buflen,		/* size of buffer */
-	 int anslen)		/* UDP answer buffer size */
-{
-	register HEADER *hp;
-	register u_char *cp, *ep;
-	u_int16_t flags = 0;
-
-#ifdef DEBUG
-	if ((statp->options & RES_DEBUG) != 0U)
-		printf(";; res_nopt()\n");
-#endif
-
-	hp = (HEADER *)(void *)buf;
-	cp = buf + n0;
-	ep = buf + buflen;
-
-	if ((ep - cp) < 1 + RRFIXEDSZ)
-		return (-1);
-
-	*cp++ = 0;	/* "." */
-
-	ns_put16(T_OPT, cp);	/* TYPE */
-	cp += INT16SZ;
-	ns_put16(anslen & 0xffff, cp);	/* CLASS = UDP payload size */
-	cp += INT16SZ;
-	*cp++ = NOERROR;	/* extended RCODE */
-	*cp++ = 0;		/* EDNS version */
-	if (statp->options & RES_USE_DNSSEC) {
-#ifdef DEBUG
-		if (statp->options & RES_DEBUG)
-			printf(";; res_opt()... ENDS0 DNSSEC\n");
-#endif
-		flags |= NS_OPT_DNSSEC_OK;
-	}
-	ns_put16(flags, cp);
-	cp += INT16SZ;
-	ns_put16(0, cp);	/* RDLEN */
-	cp += INT16SZ;
-	hp->arcount = htons(ntohs(hp->arcount) + 1);
-
-	return (cp - buf);
-}
-#endif
diff --git a/libc/netbsd/resolv/res_query.c b/libc/netbsd/resolv/res_query.c
deleted file mode 100644
index d31e83c..0000000
--- a/libc/netbsd/resolv/res_query.c
+++ /dev/null
@@ -1,424 +0,0 @@
-/*	$NetBSD: res_query.c,v 1.7 2006/01/24 17:41:25 christos Exp $	*/
-
-/*
- * Copyright (c) 1988, 1993
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#ifdef notdef
-static const char sccsid[] = "@(#)res_query.c	8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "Id: res_query.c,v 1.2.2.3.4.2 2004/03/16 12:34:19 marka Exp";
-#else
-__RCSID("$NetBSD: res_query.c,v 1.7 2006/01/24 17:41:25 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#define DISABLE_HOST_ALIAS 1
-
-/* Options.  Leave them on. */
-#ifndef DEBUG
-#define DEBUG
-#endif
-
-#if PACKETSZ > 1024
-#define MAXPACKET	PACKETSZ
-#else
-#define MAXPACKET	1024
-#endif
-
-/*
- * Formulate a normal query, send, and await answer.
- * Returned answer is placed in supplied buffer "answer".
- * Perform preliminary check of answer, returning success only
- * if no error is indicated and the answer count is nonzero.
- * Return the size of the response on success, -1 on error.
- * Error number is left in H_ERRNO.
- *
- * Caller must parse answer and determine whether it answers the question.
- */
-int
-res_nquery(res_state statp,
-	   const char *name,	/* domain name */
-	   int class, int type,	/* class and type of query */
-	   u_char *answer,	/* buffer to put answer */
-	   int anslen)		/* size of answer buffer */
-{
-	u_char buf[MAXPACKET];
-	HEADER *hp = (HEADER *)(void *)answer;
-	int n;
-	u_int oflags;
-
-	oflags = statp->_flags;
-
-again:
-	hp->rcode = NOERROR;	/* default */
-
-#ifdef DEBUG
-	if (statp->options & RES_DEBUG)
-		printf(";; res_query(%s, %d, %d)\n", name, class, type);
-#endif
-
-	n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL,
-			 buf, sizeof(buf));
-#ifdef RES_USE_EDNS0
-	if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
-	    (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U)
-		n = res_nopt(statp, n, buf, sizeof(buf), anslen);
-#endif
-	if (n <= 0) {
-#ifdef DEBUG
-		if (statp->options & RES_DEBUG)
-			printf(";; res_query: mkquery failed\n");
-#endif
-		RES_SET_H_ERRNO(statp, NO_RECOVERY);
-		return (n);
-	}
-	n = res_nsend(statp, buf, n, answer, anslen);
-	if (n < 0) {
-#ifdef RES_USE_EDNS0
-		/* if the query choked with EDNS0, retry without EDNS0 */
-		if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U &&
-		    ((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) {
-			statp->_flags |= RES_F_EDNS0ERR;
-			if (statp->options & RES_DEBUG)
-				printf(";; res_nquery: retry without EDNS0\n");
-			goto again;
-		}
-#endif
-#ifdef DEBUG
-		if (statp->options & RES_DEBUG)
-			printf(";; res_query: send error\n");
-#endif
-		RES_SET_H_ERRNO(statp, TRY_AGAIN);
-		return (n);
-	}
-
-	if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
-#ifdef DEBUG
-		if (statp->options & RES_DEBUG)
-			printf(";; rcode = (%s), counts = an:%d ns:%d ar:%d\n",
-			       p_rcode(hp->rcode),
-			       ntohs(hp->ancount),
-			       ntohs(hp->nscount),
-			       ntohs(hp->arcount));
-#endif
-		switch (hp->rcode) {
-		case NXDOMAIN:
-			RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
-			break;
-		case SERVFAIL:
-			RES_SET_H_ERRNO(statp, TRY_AGAIN);
-			break;
-		case NOERROR:
-			RES_SET_H_ERRNO(statp, NO_DATA);
-			break;
-		case FORMERR:
-		case NOTIMP:
-		case REFUSED:
-		default:
-			RES_SET_H_ERRNO(statp, NO_RECOVERY);
-			break;
-		}
-		return (-1);
-	}
-	return (n);
-}
-
-/*
- * Formulate a normal query, send, and retrieve answer in supplied buffer.
- * Return the size of the response on success, -1 on error.
- * If enabled, implement search rules until answer or unrecoverable failure
- * is detected.  Error code, if any, is left in H_ERRNO.
- */
-int
-res_nsearch(res_state statp,
-	    const char *name,	/* domain name */
-	    int class, int type,	/* class and type of query */
-	    u_char *answer,	/* buffer to put answer */
-	    int anslen)		/* size of answer */
-{
-	const char *cp, * const *domain;
-	HEADER *hp = (HEADER *)(void *)answer;
-	char tmp[NS_MAXDNAME];
-	u_int dots;
-	int trailing_dot, ret, saved_herrno;
-	int got_nodata = 0, got_servfail = 0, root_on_list = 0;
-	int tried_as_is = 0;
-	int searched = 0;
-
-	errno = 0;
-	RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);  /* True if we never query. */
-
-	dots = 0;
-	for (cp = name; *cp != '\0'; cp++)
-		dots += (*cp == '.');
-	trailing_dot = 0;
-	if (cp > name && *--cp == '.')
-		trailing_dot++;
-
-	/* If there aren't any dots, it could be a user-level alias. */
-	if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL)
-		return (res_nquery(statp, cp, class, type, answer, anslen));
-
-	/*
-	 * If there are enough dots in the name, let's just give it a
-	 * try 'as is'. The threshold can be set with the "ndots" option.
-	 * Also, query 'as is', if there is a trailing dot in the name.
-	 */
-	saved_herrno = -1;
-	if (dots >= statp->ndots || trailing_dot) {
-		ret = res_nquerydomain(statp, name, NULL, class, type,
-					 answer, anslen);
-		if (ret > 0 || trailing_dot)
-			return (ret);
-		saved_herrno = statp->res_h_errno;
-		tried_as_is++;
-	}
-
-	/*
-	 * We do at least one level of search if
-	 *	- there is no dot and RES_DEFNAME is set, or
-	 *	- there is at least one dot, there is no trailing dot,
-	 *	  and RES_DNSRCH is set.
-	 */
-	if ((!dots && (statp->options & RES_DEFNAMES) != 0U) ||
-	    (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
-		int done = 0;
-
-		/* Unfortunately we need to load interface info
-		 * (dns servers, search domains) before
-		 * the domain stuff is tried.  Will have a better
-		 * fix after thread pools are used as this will
-		 * be loaded once for the thread instead of each
-		 * time a query is tried.
-		 */
-		_resolv_populate_res_for_iface(statp);
-
-		for (domain = (const char * const *)statp->dnsrch;
-		     *domain && !done;
-		     domain++) {
-			searched = 1;
-
-			if (domain[0][0] == '\0' ||
-			    (domain[0][0] == '.' && domain[0][1] == '\0'))
-				root_on_list++;
-
-			ret = res_nquerydomain(statp, name, *domain,
-					       class, type,
-					       answer, anslen);
-			if (ret > 0)
-				return (ret);
-
-			/*
-			 * If no server present, give up.
-			 * If name isn't found in this domain,
-			 * keep trying higher domains in the search list
-			 * (if that's enabled).
-			 * On a NO_DATA error, keep trying, otherwise
-			 * a wildcard entry of another type could keep us
-			 * from finding this entry higher in the domain.
-			 * If we get some other error (negative answer or
-			 * server failure), then stop searching up,
-			 * but try the input name below in case it's
-			 * fully-qualified.
-			 */
-			if (errno == ECONNREFUSED) {
-				RES_SET_H_ERRNO(statp, TRY_AGAIN);
-				return (-1);
-			}
-
-			switch (statp->res_h_errno) {
-			case NO_DATA:
-				got_nodata++;
-				/* FALLTHROUGH */
-			case HOST_NOT_FOUND:
-				/* keep trying */
-				break;
-			case TRY_AGAIN:
-				if (hp->rcode == SERVFAIL) {
-					/* try next search element, if any */
-					got_servfail++;
-					break;
-				}
-				/* FALLTHROUGH */
-			default:
-				/* anything else implies that we're done */
-				done++;
-			}
-
-			/* if we got here for some reason other than DNSRCH,
-			 * we only wanted one iteration of the loop, so stop.
-			 */
-			if ((statp->options & RES_DNSRCH) == 0U)
-				done++;
-		}
-	}
-
-	/*
-	 * If the query has not already been tried as is then try it
-	 * unless RES_NOTLDQUERY is set and there were no dots.
-	 */
-	if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) &&
-	    !(tried_as_is || root_on_list)) {
-		ret = res_nquerydomain(statp, name, NULL, class, type,
-				       answer, anslen);
-		if (ret > 0)
-			return (ret);
-	}
-
-	/* if we got here, we didn't satisfy the search.
-	 * if we did an initial full query, return that query's H_ERRNO
-	 * (note that we wouldn't be here if that query had succeeded).
-	 * else if we ever got a nodata, send that back as the reason.
-	 * else send back meaningless H_ERRNO, that being the one from
-	 * the last DNSRCH we did.
-	 */
-	if (saved_herrno != -1)
-		RES_SET_H_ERRNO(statp, saved_herrno);
-	else if (got_nodata)
-		RES_SET_H_ERRNO(statp, NO_DATA);
-	else if (got_servfail)
-		RES_SET_H_ERRNO(statp, TRY_AGAIN);
-	return (-1);
-}
-
-/*
- * Perform a call on res_query on the concatenation of name and domain,
- * removing a trailing dot from name if domain is NULL.
- */
-int
-res_nquerydomain(res_state statp,
-	    const char *name,
-	    const char *domain,
-	    int class, int type,	/* class and type of query */
-	    u_char *answer,		/* buffer to put answer */
-	    int anslen)		/* size of answer */
-{
-	char nbuf[MAXDNAME];
-	const char *longname = nbuf;
-	int n, d;
-
-#ifdef DEBUG
-	if (statp->options & RES_DEBUG)
-		printf(";; res_nquerydomain(%s, %s, %d, %d)\n",
-		       name, domain?domain:"<Nil>", class, type);
-#endif
-	if (domain == NULL) {
-		/*
-		 * Check for trailing '.';
-		 * copy without '.' if present.
-		 */
-		n = strlen(name);
-		if (n >= MAXDNAME) {
-			RES_SET_H_ERRNO(statp, NO_RECOVERY);
-			return (-1);
-		}
-		n--;
-		if (n >= 0 && name[n] == '.') {
-			strncpy(nbuf, name, (size_t)n);
-			nbuf[n] = '\0';
-		} else
-			longname = name;
-	} else {
-		n = strlen(name);
-		d = strlen(domain);
-		if (n + d + 1 >= MAXDNAME) {
-			RES_SET_H_ERRNO(statp, NO_RECOVERY);
-			return (-1);
-		}
-		sprintf(nbuf, "%s.%s", name, domain);
-	}
-	return (res_nquery(statp, longname, class, type, answer, anslen));
-}
-
-const char *
-res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) {
-	return (NULL);
-}
diff --git a/libc/netbsd/resolv/res_random.c b/libc/netbsd/resolv/res_random.c
deleted file mode 100644
index 4570c4f..0000000
--- a/libc/netbsd/resolv/res_random.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/* $OpenBSD: res_random.c,v 1.17 2008/04/13 00:28:35 djm Exp $ */
-
-/*
- * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
- * Copyright 2008 Damien Miller <djm@openbsd.org>
- * Copyright 2008 Android Open Source Project (thread-safety)
- * All rights reserved.
- *
- * Theo de Raadt <deraadt@openbsd.org> came up with the idea of using
- * such a mathematical system to generate more random (yet non-repeating)
- * ids to solve the resolver/named problem.  But Niels designed the
- * actual system based on the constraints.
- *
- * Later modified by Damien Miller to wrap the LCG output in a 15-bit
- * permutation generator based on a Luby-Rackoff block cipher. This
- * ensures the output is non-repeating and preserves the MSB twiddle
- * trick, but makes it more resistant to LCG prediction.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * seed = random 15bit
- * n = prime, g0 = generator to n,
- * j = random so that gcd(j,n-1) == 1
- * g = g0^j mod n will be a generator again.
- *
- * X[0] = random seed.
- * X[n] = a*X[n-1]+b mod m is a Linear Congruential Generator
- * with a = 7^(even random) mod m,
- *      b = random with gcd(b,m) == 1
- *      m = 31104 and a maximal period of m-1.
- *
- * The transaction id is determined by:
- * id[n] = seed xor (g^X[n] mod n)
- *
- * Effectivly the id is restricted to the lower 15 bits, thus
- * yielding two different cycles by toggling the msb on and off.
- * This avoids reuse issues caused by reseeding.
- *
- * The output of this generator is then randomly permuted though a
- * custom 15 bit Luby-Rackoff block cipher.
- */
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include "resolv_private.h"
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
-/* BIONIC-BEGIN */
-static pthread_mutex_t         _res_random_lock = PTHREAD_MUTEX_INITIALIZER;
-#define  _RES_RANDOM_LOCK()    pthread_mutex_lock(&_res_random_lock)
-#define  _RES_RANDOM_UNLOCK()  pthread_mutex_unlock(&_res_random_lock)
-/* BIONIC-END */
-
-#define RU_OUT  	180	/* Time after wich will be reseeded */
-#define RU_MAX		30000	/* Uniq cycle, avoid blackjack prediction */
-#define RU_GEN		2	/* Starting generator */
-#define RU_N		32749	/* RU_N-1 = 2*2*3*2729 */
-#define RU_AGEN		7	/* determine ru_a as RU_AGEN^(2*rand) */
-#define RU_M		31104	/* RU_M = 2^7*3^5 - don't change */
-#define RU_ROUNDS	11	/* Number of rounds for permute (odd) */
-
-struct prf_ctx {
-	/* PRF lookup table for odd rounds (7 bits input to 8 bits output) */
-	u_char prf7[(RU_ROUNDS / 2) * (1 << 7)];
-
-	/* PRF lookup table for even rounds (8 bits input to 7 bits output) */
-	u_char prf8[((RU_ROUNDS + 1) / 2) * (1 << 8)];
-};
-
-#define PFAC_N 3
-const static u_int16_t pfacts[PFAC_N] = {
-	2,
-	3,
-	2729
-};
-
-static u_int16_t ru_x;
-static u_int16_t ru_seed, ru_seed2;
-static u_int16_t ru_a, ru_b;
-static u_int16_t ru_g;
-static u_int16_t ru_counter = 0;
-static u_int16_t ru_msb = 0;
-static struct prf_ctx *ru_prf = NULL;
-static long ru_reseed;
-
-static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t);
-static void res_initid(void);
-
-/*
- * Do a fast modular exponation, returned value will be in the range
- * of 0 - (mod-1)
- */
-static u_int16_t
-pmod(u_int16_t gen, u_int16_t exp, u_int16_t mod)
-{
-	u_int16_t s, t, u;
-
-	s = 1;
-	t = gen;
-	u = exp;
-
-	while (u) {
-		if (u & 1)
-			s = (s * t) % mod;
-		u >>= 1;
-		t = (t * t) % mod;
-	}
-	return (s);
-}
-
-/*
- * 15-bit permutation based on Luby-Rackoff block cipher
- */
-u_int
-permute15(u_int in)
-{
-	int i;
-	u_int left, right, tmp;
-
-	if (ru_prf == NULL)
-		return in;
-
-	left = (in >> 8) & 0x7f;
-	right = in & 0xff;
-
-	/*
-	 * Each round swaps the width of left and right. Even rounds have
-	 * a 7-bit left, odd rounds have an 8-bit left.	Since this uses an
-	 * odd number of rounds, left is always 8 bits wide at the end.
-	 */
-	for (i = 0; i < RU_ROUNDS; i++) {
-		if ((i & 1) == 0)
-			tmp = ru_prf->prf8[(i << (8 - 1)) | right] & 0x7f;
-		else
-			tmp = ru_prf->prf7[((i - 1) << (7 - 1)) | right];
-		tmp ^= left;
-		left = right;
-		right = tmp;
-	}
-
-	return (right << 8) | left;
-}
-
-/*
- * Initializes the seed and chooses a suitable generator. Also toggles
- * the msb flag. The msb flag is used to generate two distinct
- * cycles of random numbers and thus avoiding reuse of ids.
- *
- * This function is called from res_randomid() when needed, an
- * application does not have to worry about it.
- */
-static void
-res_initid(void)
-{
-	u_int16_t j, i;
-	u_int32_t tmp;
-	int noprime = 1;
-	struct timeval tv;
-
-	ru_x = arc4random_uniform(RU_M);
-
-	/* 15 bits of random seed */
-	tmp = arc4random();
-	ru_seed = (tmp >> 16) & 0x7FFF;
-	ru_seed2 = tmp & 0x7FFF;
-
-	/* Determine the LCG we use */
-	tmp = arc4random();
-	ru_b = (tmp & 0xfffe) | 1;
-	ru_a = pmod(RU_AGEN, (tmp >> 16) & 0xfffe, RU_M);
-	while (ru_b % 3 == 0)
-		ru_b += 2;
-
-	j = arc4random_uniform(RU_N);
-
-	/*
-	 * Do a fast gcd(j,RU_N-1), so we can find a j with
-	 * gcd(j, RU_N-1) == 1, giving a new generator for
-	 * RU_GEN^j mod RU_N
-	 */
-
-	while (noprime) {
-		for (i = 0; i < PFAC_N; i++)
-			if (j % pfacts[i] == 0)
-				break;
-
-		if (i >= PFAC_N)
-			noprime = 0;
-		else
-			j = (j + 1) % RU_N;
-	}
-
-	ru_g = pmod(RU_GEN, j, RU_N);
-	ru_counter = 0;
-
-	/* Initialise PRF for Luby-Rackoff permutation */
-	if (ru_prf == NULL)
-		ru_prf = malloc(sizeof(*ru_prf));
-	if (ru_prf != NULL)
-		arc4random_buf(ru_prf, sizeof(*ru_prf));
-
-	gettimeofday(&tv, NULL);
-	ru_reseed = tv.tv_sec + RU_OUT;
-	ru_msb = ru_msb == 0x8000 ? 0 : 0x8000;
-}
-
-u_int
-res_randomid(void)
-{
-	struct timeval tv;
-        u_int  result;
-
-        _RES_RANDOM_LOCK()
-	gettimeofday(&tv, NULL);
-	if (ru_counter >= RU_MAX || tv.tv_sec > ru_reseed)
-		res_initid();
-
-	/* Linear Congruential Generator */
-	ru_x = (ru_a * ru_x + ru_b) % RU_M;
-	ru_counter++;
-
-	result = permute15(ru_seed ^ pmod(ru_g, ru_seed2 + ru_x, RU_N)) | ru_msb;
-        _RES_RANDOM_UNLOCK()
-        return result;
-}
-
-#if 0
-int
-main(int argc, char **argv)
-{
-	int i, n;
-	u_int16_t wert;
-
-	res_initid();
-
-	printf("Generator: %u\n", ru_g);
-	printf("Seed: %u\n", ru_seed);
-	printf("Reseed at %ld\n", ru_reseed);
-	printf("Ru_X: %u\n", ru_x);
-	printf("Ru_A: %u\n", ru_a);
-	printf("Ru_B: %u\n", ru_b);
-
-	n = argc > 1 ? atoi(argv[1]) : 60001;
-	for (i=0;i<n;i++) {
-		wert = res_randomid();
-		printf("%u\n", wert);
-	}
-	return 0;
-}
-#endif
-
diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c
deleted file mode 100644
index e587bdc..0000000
--- a/libc/netbsd/resolv/res_send.c
+++ /dev/null
@@ -1,1355 +0,0 @@
-/*	$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $	*/
-
-/*
- * Copyright 2008  Android Open Source Project (source port randomization)
- * Copyright (c) 1985, 1989, 1993
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#ifdef notdef
-static const char sccsid[] = "@(#)res_send.c	8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "Id: res_send.c,v 1.5.2.2.4.5 2004/08/10 02:19:56 marka Exp";
-#else
-__RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-/* set to 1 to use our small/simple/limited DNS cache */
-#define  USE_RESOLV_CACHE  1
-
-/*
- * Send query to name server and wait for reply.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
-#include <netinet/in.h>
-#include "arpa_nameser.h"
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <isc/eventlib.h>
-
-#if USE_RESOLV_CACHE
-#  include <resolv_cache.h>
-#endif
-
-#include "private/libc_logging.h"
-
-#ifndef DE_CONST
-#define DE_CONST(c,v)   v = ((c) ? \
-    strchr((const void *)(c), *(const char *)(const void *)(c)) : NULL)
-#endif
-
-/* Options.  Leave them on. */
-#ifndef DEBUG
-#define DEBUG
-#endif
-#include "res_debug.h"
-#include "res_private.h"
-
-#define EXT(res) ((res)->_u._ext)
-#define DBG 0
-
-static const int highestFD = FD_SETSIZE - 1;
-
-/* Forward. */
-
-static int		get_salen __P((const struct sockaddr *));
-static struct sockaddr * get_nsaddr __P((res_state, size_t));
-static int		send_vc(res_state, const u_char *, int,
-				u_char *, int, int *, int);
-static int		send_dg(res_state, const u_char *, int,
-				u_char *, int, int *, int,
-				int *, int *);
-static void		Aerror(const res_state, FILE *, const char *, int,
-			       const struct sockaddr *, int);
-static void		Perror(const res_state, FILE *, const char *, int);
-static int		sock_eq(struct sockaddr *, struct sockaddr *);
-#ifdef NEED_PSELECT
-static int		pselect(int, void *, void *, void *,
-				struct timespec *,
-				const sigset_t *);
-#endif
-void res_pquery(const res_state, const u_char *, int, FILE *);
-static int connect_with_timeout(int sock, const struct sockaddr *nsap,
-			socklen_t salen, int sec);
-static int retrying_select(const int sock, fd_set *readset, fd_set *writeset,
-			const struct timespec *finish);
-
-/* BIONIC-BEGIN: implement source port randomization */
-typedef union {
-    struct sockaddr      sa;
-    struct sockaddr_in   sin;
-    struct sockaddr_in6  sin6;
-} _sockaddr_union;
-
-static int
-random_bind( int  s, int  family )
-{
-    _sockaddr_union  u;
-    int              j;
-    socklen_t        slen;
-
-    /* clear all, this also sets the IP4/6 address to 'any' */
-    memset( &u, 0, sizeof u );
-
-    switch (family) {
-        case AF_INET:
-            u.sin.sin_family = family;
-            slen             = sizeof u.sin;
-            break;
-        case AF_INET6:
-            u.sin6.sin6_family = family;
-            slen               = sizeof u.sin6;
-            break;
-        default:
-            errno = EPROTO;
-            return -1;
-    }
-
-    /* first try to bind to a random source port a few times */
-    for (j = 0; j < 10; j++) {
-        /* find a random port between 1025 .. 65534 */
-        int  port = 1025 + (res_randomid() % (65535-1025));
-        if (family == AF_INET)
-            u.sin.sin_port = htons(port);
-        else
-            u.sin6.sin6_port = htons(port);
-
-        if ( !bind( s, &u.sa, slen ) )
-            return 0;
-    }
-
-    /* nothing after 10 tries, our network table is probably busy */
-    /* let the system decide which port is best */
-    if (family == AF_INET)
-        u.sin.sin_port = 0;
-    else
-        u.sin6.sin6_port = 0;
-
-    return bind( s, &u.sa, slen );
-}
-/* BIONIC-END */
-
-static const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
-
-/* Public. */
-
-/* int
- * res_isourserver(ina)
- *	looks up "ina" in _res.ns_addr_list[]
- * returns:
- *	0  : not found
- *	>0 : found
- * author:
- *	paul vixie, 29may94
- */
-__LIBC_HIDDEN__ int
-res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
-	const struct sockaddr_in *inp, *srv;
-	const struct sockaddr_in6 *in6p, *srv6;
-	int ns;
-
-	switch (sa->sa_family) {
-	case AF_INET:
-		inp = (const struct sockaddr_in *)(const void *)sa;
-		for (ns = 0;  ns < statp->nscount;  ns++) {
-			srv = (struct sockaddr_in *)(void *)get_nsaddr(statp, (size_t)ns);
-			if (srv->sin_family == inp->sin_family &&
-			    srv->sin_port == inp->sin_port &&
-			    (srv->sin_addr.s_addr == INADDR_ANY ||
-			     srv->sin_addr.s_addr == inp->sin_addr.s_addr))
-				return (1);
-		}
-		break;
-	case AF_INET6:
-		if (EXT(statp).ext == NULL)
-			break;
-		in6p = (const struct sockaddr_in6 *)(const void *)sa;
-		for (ns = 0;  ns < statp->nscount;  ns++) {
-			srv6 = (struct sockaddr_in6 *)(void *)get_nsaddr(statp, (size_t)ns);
-			if (srv6->sin6_family == in6p->sin6_family &&
-			    srv6->sin6_port == in6p->sin6_port &&
-#ifdef HAVE_SIN6_SCOPE_ID
-			    (srv6->sin6_scope_id == 0 ||
-			     srv6->sin6_scope_id == in6p->sin6_scope_id) &&
-#endif
-			    (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) ||
-			     IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr, &in6p->sin6_addr)))
-				return (1);
-		}
-		break;
-	default:
-		break;
-	}
-	return (0);
-}
-
-/* int
- * res_nameinquery(name, type, class, buf, eom)
- *	look for (name,type,class) in the query section of packet (buf,eom)
- * requires:
- *	buf + HFIXEDSZ <= eom
- * returns:
- *	-1 : format error
- *	0  : not found
- *	>0 : found
- * author:
- *	paul vixie, 29may94
- */
-int
-res_nameinquery(const char *name, int type, int class,
-		const u_char *buf, const u_char *eom)
-{
-	const u_char *cp = buf + HFIXEDSZ;
-	int qdcount = ntohs(((const HEADER*)(const void *)buf)->qdcount);
-
-	while (qdcount-- > 0) {
-		char tname[MAXDNAME+1];
-		int n, ttype, tclass;
-
-		n = dn_expand(buf, eom, cp, tname, sizeof tname);
-		if (n < 0)
-			return (-1);
-		cp += n;
-		if (cp + 2 * INT16SZ > eom)
-			return (-1);
-		ttype = ns_get16(cp); cp += INT16SZ;
-		tclass = ns_get16(cp); cp += INT16SZ;
-		if (ttype == type && tclass == class &&
-		    ns_samename(tname, name) == 1)
-			return (1);
-	}
-	return (0);
-}
-
-/* int
- * res_queriesmatch(buf1, eom1, buf2, eom2)
- *	is there a 1:1 mapping of (name,type,class)
- *	in (buf1,eom1) and (buf2,eom2)?
- * returns:
- *	-1 : format error
- *	0  : not a 1:1 mapping
- *	>0 : is a 1:1 mapping
- * author:
- *	paul vixie, 29may94
- */
-int
-res_queriesmatch(const u_char *buf1, const u_char *eom1,
-		 const u_char *buf2, const u_char *eom2)
-{
-	const u_char *cp = buf1 + HFIXEDSZ;
-	int qdcount = ntohs(((const HEADER*)(const void *)buf1)->qdcount);
-
-	if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
-		return (-1);
-
-	/*
-	 * Only header section present in replies to
-	 * dynamic update packets.
-	 */
-	if ((((const HEADER *)(const void *)buf1)->opcode == ns_o_update) &&
-	    (((const HEADER *)(const void *)buf2)->opcode == ns_o_update))
-		return (1);
-
-	if (qdcount != ntohs(((const HEADER*)(const void *)buf2)->qdcount))
-		return (0);
-	while (qdcount-- > 0) {
-		char tname[MAXDNAME+1];
-		int n, ttype, tclass;
-
-		n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
-		if (n < 0)
-			return (-1);
-		cp += n;
-		if (cp + 2 * INT16SZ > eom1)
-			return (-1);
-		ttype = ns_get16(cp);	cp += INT16SZ;
-		tclass = ns_get16(cp); cp += INT16SZ;
-		if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
-			return (0);
-	}
-	return (1);
-}
-
-
-int
-res_nsend(res_state statp,
-	  const u_char *buf, int buflen, u_char *ans, int anssiz)
-{
-	int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
-	char abuf[NI_MAXHOST];
-#if USE_RESOLV_CACHE
-        struct resolv_cache*  cache;
-        ResolvCacheStatus     cache_status = RESOLV_CACHE_UNSUPPORTED;
-#endif
-
-#if !USE_RESOLV_CACHE
-	if (statp->nscount == 0) {
-		errno = ESRCH;
-		return (-1);
-	}
-#endif
-
-	if (anssiz < HFIXEDSZ) {
-		errno = EINVAL;
-		return (-1);
-	}
-	DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),
-		(stdout, ";; res_send()\n"), buf, buflen);
-	v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
-	gotsomewhere = 0;
-	terrno = ETIMEDOUT;
-
-#if USE_RESOLV_CACHE
-	// get the cache associated with the interface
-	cache = __get_res_cache(statp->iface);
-	if (cache != NULL) {
-		int  anslen = 0;
-		cache_status = _resolv_cache_lookup(
-				cache, buf, buflen,
-				ans, anssiz, &anslen);
-
-		if (cache_status == RESOLV_CACHE_FOUND) {
-			return anslen;
-		} else {
-			// had a cache miss for a known interface, so populate the thread private
-			// data so the normal resolve path can do its thing
-			_resolv_populate_res_for_iface(statp);
-		}
-	}
-
-	if (statp->nscount == 0) {
-		errno = ESRCH;
-		return (-1);
-	}
-#endif
-
-	/*
-	 * If the ns_addr_list in the resolver context has changed, then
-	 * invalidate our cached copy and the associated timing data.
-	 */
-	if (EXT(statp).nscount != 0) {
-		int needclose = 0;
-		struct sockaddr_storage peer;
-		socklen_t peerlen;
-
-		if (EXT(statp).nscount != statp->nscount)
-			needclose++;
-		else
-			for (ns = 0; ns < statp->nscount; ns++) {
-				if (statp->nsaddr_list[ns].sin_family &&
-				    !sock_eq((struct sockaddr *)(void *)&statp->nsaddr_list[ns],
-					     (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[ns])) {
-					needclose++;
-					break;
-				}
-
-				if (EXT(statp).nssocks[ns] == -1)
-					continue;
-				peerlen = sizeof(peer);
-				if (getpeername(EXT(statp).nssocks[ns],
-				    (struct sockaddr *)(void *)&peer, &peerlen) < 0) {
-					needclose++;
-					break;
-				}
-				if (!sock_eq((struct sockaddr *)(void *)&peer,
-				    get_nsaddr(statp, (size_t)ns))) {
-					needclose++;
-					break;
-				}
-			}
-		if (needclose) {
-			res_nclose(statp);
-			EXT(statp).nscount = 0;
-		}
-	}
-
-	/*
-	 * Maybe initialize our private copy of the ns_addr_list.
-	 */
-	if (EXT(statp).nscount == 0) {
-		for (ns = 0; ns < statp->nscount; ns++) {
-			EXT(statp).nstimes[ns] = RES_MAXTIME;
-			EXT(statp).nssocks[ns] = -1;
-			if (!statp->nsaddr_list[ns].sin_family)
-				continue;
-			EXT(statp).ext->nsaddrs[ns].sin =
-				 statp->nsaddr_list[ns];
-		}
-		EXT(statp).nscount = statp->nscount;
-	}
-
-	/*
-	 * Some resolvers want to even out the load on their nameservers.
-	 * Note that RES_BLAST overrides RES_ROTATE.
-	 */
-	if ((statp->options & RES_ROTATE) != 0U &&
-	    (statp->options & RES_BLAST) == 0U) {
-		union res_sockaddr_union inu;
-		struct sockaddr_in ina;
-		int lastns = statp->nscount - 1;
-		int fd;
-		u_int16_t nstime;
-
-		if (EXT(statp).ext != NULL)
-			inu = EXT(statp).ext->nsaddrs[0];
-		ina = statp->nsaddr_list[0];
-		fd = EXT(statp).nssocks[0];
-		nstime = EXT(statp).nstimes[0];
-		for (ns = 0; ns < lastns; ns++) {
-			if (EXT(statp).ext != NULL)
-                                EXT(statp).ext->nsaddrs[ns] =
-					EXT(statp).ext->nsaddrs[ns + 1];
-			statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
-			EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
-			EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1];
-		}
-		if (EXT(statp).ext != NULL)
-			EXT(statp).ext->nsaddrs[lastns] = inu;
-		statp->nsaddr_list[lastns] = ina;
-		EXT(statp).nssocks[lastns] = fd;
-		EXT(statp).nstimes[lastns] = nstime;
-	}
-
-	/*
-	 * Send request, RETRY times, or until successful.
-	 */
-	for (try = 0; try < statp->retry; try++) {
-	    for (ns = 0; ns < statp->nscount; ns++) {
-		struct sockaddr *nsap;
-		int nsaplen;
-		nsap = get_nsaddr(statp, (size_t)ns);
-		nsaplen = get_salen(nsap);
-		statp->_flags &= ~RES_F_LASTMASK;
-		statp->_flags |= (ns << RES_F_LASTSHIFT);
- same_ns:
-		if (statp->qhook) {
-			int done = 0, loops = 0;
-
-			do {
-				res_sendhookact act;
-
-				act = (*statp->qhook)(&nsap, &buf, &buflen,
-						      ans, anssiz, &resplen);
-				switch (act) {
-				case res_goahead:
-					done = 1;
-					break;
-				case res_nextns:
-					res_nclose(statp);
-					goto next_ns;
-				case res_done:
-					return (resplen);
-				case res_modified:
-					/* give the hook another try */
-					if (++loops < 42) /*doug adams*/
-						break;
-					/*FALLTHROUGH*/
-				case res_error:
-					/*FALLTHROUGH*/
-				default:
-					goto fail;
-				}
-			} while (!done);
-		}
-
-		Dprint(((statp->options & RES_DEBUG) &&
-			getnameinfo(nsap, (socklen_t)nsaplen, abuf, sizeof(abuf),
-				NULL, 0, niflags) == 0),
-				(stdout, ";; Querying server (# %d) address = %s\n",
-				ns + 1, abuf));
-
-
-		if (v_circuit) {
-			/* Use VC; at most one attempt per server. */
-			try = statp->retry;
-
-			n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
-				    ns);
-
-			if (DBG) {
-				__libc_format_log(ANDROID_LOG_DEBUG, "libc",
-					"used send_vc %d\n", n);
-			}
-
-			if (n < 0)
-				goto fail;
-			if (n == 0)
-				goto next_ns;
-			resplen = n;
-		} else {
-			/* Use datagrams. */
-			if (DBG) {
-				__libc_format_log(ANDROID_LOG_DEBUG, "libc", "using send_dg\n");
-			}
-
-			n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
-				    ns, &v_circuit, &gotsomewhere);
-			if (DBG) {
-				__libc_format_log(ANDROID_LOG_DEBUG, "libc", "used send_dg %d\n",n);
-			}
-
-			if (n < 0)
-				goto fail;
-			if (n == 0)
-				goto next_ns;
-			if (DBG) {
-				__libc_format_log(ANDROID_LOG_DEBUG, "libc", "time=%ld\n",
-                                                  time(NULL));
-			}
-			if (v_circuit)
-				goto same_ns;
-			resplen = n;
-		}
-
-		Dprint((statp->options & RES_DEBUG) ||
-		       ((statp->pfcode & RES_PRF_REPLY) &&
-			(statp->pfcode & RES_PRF_HEAD1)),
-		       (stdout, ";; got answer:\n"));
-
-		DprintQ((statp->options & RES_DEBUG) ||
-			(statp->pfcode & RES_PRF_REPLY),
-			(stdout, "%s", ""),
-			ans, (resplen > anssiz) ? anssiz : resplen);
-
-#if USE_RESOLV_CACHE
-                if (cache_status == RESOLV_CACHE_NOTFOUND) {
-                    _resolv_cache_add(cache, buf, buflen,
-                                      ans, resplen);
-                }
-#endif
-		/*
-		 * If we have temporarily opened a virtual circuit,
-		 * or if we haven't been asked to keep a socket open,
-		 * close the socket.
-		 */
-		if ((v_circuit && (statp->options & RES_USEVC) == 0U) ||
-		    (statp->options & RES_STAYOPEN) == 0U) {
-			res_nclose(statp);
-		}
-		if (statp->rhook) {
-			int done = 0, loops = 0;
-
-			do {
-				res_sendhookact act;
-
-				act = (*statp->rhook)(nsap, buf, buflen,
-						      ans, anssiz, &resplen);
-				switch (act) {
-				case res_goahead:
-				case res_done:
-					done = 1;
-					break;
-				case res_nextns:
-					res_nclose(statp);
-					goto next_ns;
-				case res_modified:
-					/* give the hook another try */
-					if (++loops < 42) /*doug adams*/
-						break;
-					/*FALLTHROUGH*/
-				case res_error:
-					/*FALLTHROUGH*/
-				default:
-					goto fail;
-				}
-			} while (!done);
-
-		}
-		return (resplen);
- next_ns: ;
-	   } /*foreach ns*/
-	} /*foreach retry*/
-	res_nclose(statp);
-	if (!v_circuit) {
-		if (!gotsomewhere)
-			errno = ECONNREFUSED;	/* no nameservers found */
-		else
-			errno = ETIMEDOUT;	/* no answer obtained */
-	} else
-		errno = terrno;
-
-#if USE_RESOLV_CACHE
-        _resolv_cache_query_failed(cache, buf, buflen);
-#endif
-
-	return (-1);
- fail:
-#if USE_RESOLV_CACHE
-	_resolv_cache_query_failed(cache, buf, buflen);
-#endif
-	res_nclose(statp);
-	return (-1);
-}
-
-/* Private */
-
-static int
-get_salen(sa)
-	const struct sockaddr *sa;
-{
-
-#ifdef HAVE_SA_LEN
-	/* There are people do not set sa_len.  Be forgiving to them. */
-	if (sa->sa_len)
-		return (sa->sa_len);
-#endif
-
-	if (sa->sa_family == AF_INET)
-		return (sizeof(struct sockaddr_in));
-	else if (sa->sa_family == AF_INET6)
-		return (sizeof(struct sockaddr_in6));
-	else
-		return (0);	/* unknown, die on connect */
-}
-
-/*
- * pick appropriate nsaddr_list for use.  see res_init() for initialization.
- */
-static struct sockaddr *
-get_nsaddr(statp, n)
-	res_state statp;
-	size_t n;
-{
-
-	if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) {
-		/*
-		 * - EXT(statp).ext->nsaddrs[n] holds an address that is larger
-		 *   than struct sockaddr, and
-		 * - user code did not update statp->nsaddr_list[n].
-		 */
-		return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
-	} else {
-		/*
-		 * - user code updated statp->nsaddr_list[n], or
-		 * - statp->nsaddr_list[n] has the same content as
-		 *   EXT(statp).ext->nsaddrs[n].
-		 */
-		return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
-	}
-}
-
-static int get_timeout(const res_state statp, const int ns)
-{
-	int timeout = (statp->retrans << ns);
-	if (ns > 0) {
-		timeout /= statp->nscount;
-	}
-	if (timeout <= 0) {
-		timeout = 1;
-	}
-	if (DBG) {
-		__libc_format_log(ANDROID_LOG_DEBUG, "libc", "using timeout of %d sec\n", timeout);
-	}
-
-	return timeout;
-}
-
-static int
-send_vc(res_state statp,
-	const u_char *buf, int buflen, u_char *ans, int anssiz,
-	int *terrno, int ns)
-{
-	const HEADER *hp = (const HEADER *)(const void *)buf;
-	HEADER *anhp = (HEADER *)(void *)ans;
-	struct sockaddr *nsap;
-	int nsaplen;
-	int truncating, connreset, resplen, n;
-	struct iovec iov[2];
-	u_short len;
-	u_char *cp;
-	void *tmp;
-
-	if (DBG) {
-		__libc_format_log(ANDROID_LOG_DEBUG, "libc", "using send_vc\n");
-	}
-
-	nsap = get_nsaddr(statp, (size_t)ns);
-	nsaplen = get_salen(nsap);
-
-	connreset = 0;
- same_ns:
-	truncating = 0;
-
-	/* Are we still talking to whom we want to talk to? */
-	if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
-		struct sockaddr_storage peer;
-		socklen_t size = sizeof peer;
-		int old_mark;
-		int mark_size = sizeof(old_mark);
-		if (getpeername(statp->_vcsock,
-				(struct sockaddr *)(void *)&peer, &size) < 0 ||
-		    !sock_eq((struct sockaddr *)(void *)&peer, nsap) ||
-			getsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &old_mark, &mark_size) < 0 ||
-			old_mark != statp->_mark) {
-			res_nclose(statp);
-			statp->_flags &= ~RES_F_VC;
-		}
-	}
-
-	if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) {
-		if (statp->_vcsock >= 0)
-			res_nclose(statp);
-
-		statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);
-		if (statp->_vcsock > highestFD) {
-			res_nclose(statp);
-			errno = ENOTSOCK;
-		}
-		if (statp->_vcsock < 0) {
-			switch (errno) {
-			case EPROTONOSUPPORT:
-#ifdef EPFNOSUPPORT
-			case EPFNOSUPPORT:
-#endif
-			case EAFNOSUPPORT:
-				Perror(statp, stderr, "socket(vc)", errno);
-				return (0);
-			default:
-				*terrno = errno;
-				Perror(statp, stderr, "socket(vc)", errno);
-				return (-1);
-			}
-		}
-		if (statp->_mark != 0) {
-			if (setsockopt(statp->_vcsock, SOL_SOCKET,
-				        SO_MARK, &statp->_mark, sizeof(statp->_mark)) < 0) {
-				*terrno = errno;
-				Perror(statp, stderr, "setsockopt", errno);
-				return -1;
-			}
-		}
-		errno = 0;
-		if (random_bind(statp->_vcsock,nsap->sa_family) < 0) {
-			*terrno = errno;
-			Aerror(statp, stderr, "bind/vc", errno, nsap,
-			    nsaplen);
-			res_nclose(statp);
-			return (0);
-		}
-		if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t)nsaplen,
-				get_timeout(statp, ns)) < 0) {
-			*terrno = errno;
-			Aerror(statp, stderr, "connect/vc", errno, nsap,
-			    nsaplen);
-			res_nclose(statp);
-			return (0);
-		}
-		statp->_flags |= RES_F_VC;
-	}
-
-	/*
-	 * Send length & message
-	 */
-	ns_put16((u_short)buflen, (u_char*)(void *)&len);
-	iov[0] = evConsIovec(&len, INT16SZ);
-	DE_CONST(buf, tmp);
-	iov[1] = evConsIovec(tmp, (size_t)buflen);
-	if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
-		*terrno = errno;
-		Perror(statp, stderr, "write failed", errno);
-		res_nclose(statp);
-		return (0);
-	}
-	/*
-	 * Receive length & response
-	 */
- read_len:
-	cp = ans;
-	len = INT16SZ;
-	while ((n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0) {
-		cp += n;
-		if ((len -= n) == 0)
-			break;
-	}
-	if (n <= 0) {
-		*terrno = errno;
-		Perror(statp, stderr, "read failed", errno);
-		res_nclose(statp);
-		/*
-		 * A long running process might get its TCP
-		 * connection reset if the remote server was
-		 * restarted.  Requery the server instead of
-		 * trying a new one.  When there is only one
-		 * server, this means that a query might work
-		 * instead of failing.  We only allow one reset
-		 * per query to prevent looping.
-		 */
-		if (*terrno == ECONNRESET && !connreset) {
-			connreset = 1;
-			res_nclose(statp);
-			goto same_ns;
-		}
-		res_nclose(statp);
-		return (0);
-	}
-	resplen = ns_get16(ans);
-	if (resplen > anssiz) {
-		Dprint(statp->options & RES_DEBUG,
-		       (stdout, ";; response truncated\n")
-		       );
-		truncating = 1;
-		len = anssiz;
-	} else
-		len = resplen;
-	if (len < HFIXEDSZ) {
-		/*
-		 * Undersized message.
-		 */
-		Dprint(statp->options & RES_DEBUG,
-		       (stdout, ";; undersized: %d\n", len));
-		*terrno = EMSGSIZE;
-		res_nclose(statp);
-		return (0);
-	}
-	cp = ans;
-	while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0){
-		cp += n;
-		len -= n;
-	}
-	if (n <= 0) {
-		*terrno = errno;
-		Perror(statp, stderr, "read(vc)", errno);
-		res_nclose(statp);
-		return (0);
-	}
-	if (truncating) {
-		/*
-		 * Flush rest of answer so connection stays in synch.
-		 */
-		anhp->tc = 1;
-		len = resplen - anssiz;
-		while (len != 0) {
-			char junk[PACKETSZ];
-
-			n = read(statp->_vcsock, junk,
-				 (len > sizeof junk) ? sizeof junk : len);
-			if (n > 0)
-				len -= n;
-			else
-				break;
-		}
-	}
-	/*
-	 * If the calling applicating has bailed out of
-	 * a previous call and failed to arrange to have
-	 * the circuit closed or the server has got
-	 * itself confused, then drop the packet and
-	 * wait for the correct one.
-	 */
-	if (hp->id != anhp->id) {
-		DprintQ((statp->options & RES_DEBUG) ||
-			(statp->pfcode & RES_PRF_REPLY),
-			(stdout, ";; old answer (unexpected):\n"),
-			ans, (resplen > anssiz) ? anssiz: resplen);
-		goto read_len;
-	}
-
-	/*
-	 * All is well, or the error is fatal.  Signal that the
-	 * next nameserver ought not be tried.
-	 */
-	return (resplen);
-}
-
-/* return -1 on error (errno set), 0 on success */
-static int
-connect_with_timeout(int sock, const struct sockaddr *nsap, socklen_t salen, int sec)
-{
-	int res, origflags;
-	fd_set rset, wset;
-	struct timespec now, timeout, finish;
-
-	origflags = fcntl(sock, F_GETFL, 0);
-	fcntl(sock, F_SETFL, origflags | O_NONBLOCK);
-
-	res = connect(sock, nsap, salen);
-	if (res < 0 && errno != EINPROGRESS) {
-                res = -1;
-                goto done;
-	}
-	if (res != 0) {
-		now = evNowTime();
-		timeout = evConsTime((long)sec, 0L);
-		finish = evAddTime(now, timeout);
-		if (DBG) {
-			__libc_format_log(ANDROID_LOG_DEBUG, "libc", "  %d send_vc\n", sock);
-		}
-
-		res = retrying_select(sock, &rset, &wset, &finish);
-		if (res <= 0) {
-                        res = -1;
-		}
-	}
-done:
-	fcntl(sock, F_SETFL, origflags);
-	if (DBG) {
-		__libc_format_log(ANDROID_LOG_DEBUG, "libc",
-			"  %d connect_with_timeout returning %d\n", sock, res);
-	}
-	return res;
-}
-
-static int
-retrying_select(const int sock, fd_set *readset, fd_set *writeset, const struct timespec *finish)
-{
-	struct timespec now, timeout;
-	int n, error;
-	socklen_t len;
-
-
-retry:
-	if (DBG) {
-		__libc_format_log(ANDROID_LOG_DEBUG, "libc", "  %d retying_select\n", sock);
-	}
-
-	now = evNowTime();
-	if (readset) {
-		FD_ZERO(readset);
-		FD_SET(sock, readset);
-	}
-	if (writeset) {
-		FD_ZERO(writeset);
-		FD_SET(sock, writeset);
-	}
-	if (evCmpTime(*finish, now) > 0)
-		timeout = evSubTime(*finish, now);
-	else
-		timeout = evConsTime(0L, 0L);
-
-	n = pselect(sock + 1, readset, writeset, NULL, &timeout, NULL);
-	if (n == 0) {
-		if (DBG) {
-			__libc_format_log(ANDROID_LOG_DEBUG, " libc",
-				"  %d retrying_select timeout\n", sock);
-		}
-		errno = ETIMEDOUT;
-		return 0;
-	}
-	if (n < 0) {
-		if (errno == EINTR)
-			goto retry;
-		if (DBG) {
-			__libc_format_log(ANDROID_LOG_DEBUG, "libc",
-				"  %d retrying_select got error %d\n",sock, n);
-		}
-		return n;
-	}
-	if ((readset && FD_ISSET(sock, readset)) || (writeset && FD_ISSET(sock, writeset))) {
-		len = sizeof(error);
-		if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
-			errno = error;
-			if (DBG) {
-				__libc_format_log(ANDROID_LOG_DEBUG, "libc",
-					"  %d retrying_select dot error2 %d\n", sock, errno);
-			}
-
-			return -1;
-		}
-	}
-	if (DBG) {
-		__libc_format_log(ANDROID_LOG_DEBUG, "libc",
-			"  %d retrying_select returning %d\n",sock, n);
-	}
-
-	return n;
-}
-
-
-static int
-send_dg(res_state statp,
-	const u_char *buf, int buflen, u_char *ans, int anssiz,
-	int *terrno, int ns, int *v_circuit, int *gotsomewhere)
-{
-	const HEADER *hp = (const HEADER *)(const void *)buf;
-	HEADER *anhp = (HEADER *)(void *)ans;
-	const struct sockaddr *nsap;
-	int nsaplen;
-	struct timespec now, timeout, finish;
-	fd_set dsmask;
-	struct sockaddr_storage from;
-	socklen_t fromlen;
-	int resplen, seconds, n, s;
-
-	nsap = get_nsaddr(statp, (size_t)ns);
-	nsaplen = get_salen(nsap);
-	if (EXT(statp).nssocks[ns] == -1) {
-		EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0);
-		if (EXT(statp).nssocks[ns] > highestFD) {
-			res_nclose(statp);
-			errno = ENOTSOCK;
-		}
-		if (EXT(statp).nssocks[ns] < 0) {
-			switch (errno) {
-			case EPROTONOSUPPORT:
-#ifdef EPFNOSUPPORT
-			case EPFNOSUPPORT:
-#endif
-			case EAFNOSUPPORT:
-				Perror(statp, stderr, "socket(dg)", errno);
-				return (0);
-			default:
-				*terrno = errno;
-				Perror(statp, stderr, "socket(dg)", errno);
-				return (-1);
-			}
-		}
-
-		if (statp->_mark != 0) {
-			if (setsockopt(EXT(statp).nssocks[ns], SOL_SOCKET,
-					SO_MARK, &(statp->_mark), sizeof(statp->_mark)) < 0) {
-				res_nclose(statp);
-				return -1;
-			}
-		}
-#ifndef CANNOT_CONNECT_DGRAM
-		/*
-		 * On a 4.3BSD+ machine (client and server,
-		 * actually), sending to a nameserver datagram
-		 * port with no nameserver will cause an
-		 * ICMP port unreachable message to be returned.
-		 * If our datagram socket is "connected" to the
-		 * server, we get an ECONNREFUSED error on the next
-		 * socket operation, and select returns if the
-		 * error message is received.  We can thus detect
-		 * the absence of a nameserver without timing out.
-		 */
-		if (random_bind(EXT(statp).nssocks[ns], nsap->sa_family) < 0) {
-			Aerror(statp, stderr, "bind(dg)", errno, nsap,
-			    nsaplen);
-			res_nclose(statp);
-			return (0);
-		}
-		if (connect(EXT(statp).nssocks[ns], nsap, (socklen_t)nsaplen) < 0) {
-			Aerror(statp, stderr, "connect(dg)", errno, nsap,
-			    nsaplen);
-			res_nclose(statp);
-			return (0);
-		}
-#endif /* !CANNOT_CONNECT_DGRAM */
-		Dprint(statp->options & RES_DEBUG,
-		       (stdout, ";; new DG socket\n"))
-
-	}
-	s = EXT(statp).nssocks[ns];
-#ifndef CANNOT_CONNECT_DGRAM
-	if (send(s, (const char*)buf, (size_t)buflen, 0) != buflen) {
-		Perror(statp, stderr, "send", errno);
-		res_nclose(statp);
-		return (0);
-	}
-#else /* !CANNOT_CONNECT_DGRAM */
-	if (sendto(s, (const char*)buf, buflen, 0, nsap, nsaplen) != buflen)
-	{
-		Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
-		res_nclose(statp);
-		return (0);
-	}
-#endif /* !CANNOT_CONNECT_DGRAM */
-
-	/*
-	 * Wait for reply.
-	 */
-	seconds = get_timeout(statp, ns);
-	now = evNowTime();
-	timeout = evConsTime((long)seconds, 0L);
-	finish = evAddTime(now, timeout);
-retry:
-	n = retrying_select(s, &dsmask, NULL, &finish);
-
-	if (n == 0) {
-		Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
-		*gotsomewhere = 1;
-		return (0);
-	}
-	if (n < 0) {
-		Perror(statp, stderr, "select", errno);
-		res_nclose(statp);
-		return (0);
-	}
-	errno = 0;
-	fromlen = sizeof(from);
-	resplen = recvfrom(s, (char*)ans, (size_t)anssiz,0,
-			   (struct sockaddr *)(void *)&from, &fromlen);
-	if (resplen <= 0) {
-		Perror(statp, stderr, "recvfrom", errno);
-		res_nclose(statp);
-		return (0);
-	}
-	*gotsomewhere = 1;
-	if (resplen < HFIXEDSZ) {
-		/*
-		 * Undersized message.
-		 */
-		Dprint(statp->options & RES_DEBUG,
-		       (stdout, ";; undersized: %d\n",
-			resplen));
-		*terrno = EMSGSIZE;
-		res_nclose(statp);
-		return (0);
-	}
-	if (hp->id != anhp->id) {
-		/*
-		 * response from old query, ignore it.
-		 * XXX - potential security hazard could
-		 *	 be detected here.
-		 */
-#ifdef ANDROID_CHANGES
-		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_OLD_RESPONSE);
-#endif
-		DprintQ((statp->options & RES_DEBUG) ||
-			(statp->pfcode & RES_PRF_REPLY),
-			(stdout, ";; old answer:\n"),
-			ans, (resplen > anssiz) ? anssiz : resplen);
-		goto retry;
-	}
-	if (!(statp->options & RES_INSECURE1) &&
-	    !res_ourserver_p(statp, (struct sockaddr *)(void *)&from)) {
-		/*
-		 * response from wrong server? ignore it.
-		 * XXX - potential security hazard could
-		 *	 be detected here.
-		 */
-#ifdef ANDROID_CHANGES
-		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_WRONG_SERVER);
-#endif
-		DprintQ((statp->options & RES_DEBUG) ||
-			(statp->pfcode & RES_PRF_REPLY),
-			(stdout, ";; not our server:\n"),
-			ans, (resplen > anssiz) ? anssiz : resplen);
-		goto retry;
-	}
-#ifdef RES_USE_EDNS0
-	if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
-		/*
-		 * Do not retry if the server do not understand EDNS0.
-		 * The case has to be captured here, as FORMERR packet do not
-		 * carry query section, hence res_queriesmatch() returns 0.
-		 */
-		DprintQ(statp->options & RES_DEBUG,
-			(stdout, "server rejected query with EDNS0:\n"),
-			ans, (resplen > anssiz) ? anssiz : resplen);
-		/* record the error */
-		statp->_flags |= RES_F_EDNS0ERR;
-		res_nclose(statp);
-		return (0);
-	}
-#endif
-	if (!(statp->options & RES_INSECURE2) &&
-	    !res_queriesmatch(buf, buf + buflen,
-			      ans, ans + anssiz)) {
-		/*
-		 * response contains wrong query? ignore it.
-		 * XXX - potential security hazard could
-		 *	 be detected here.
-		 */
-#ifdef ANDROID_CHANGES
-		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_WRONG_QUERY);
-#endif
-		DprintQ((statp->options & RES_DEBUG) ||
-			(statp->pfcode & RES_PRF_REPLY),
-			(stdout, ";; wrong query name:\n"),
-			ans, (resplen > anssiz) ? anssiz : resplen);
-		goto retry;;
-	}
-	if (anhp->rcode == SERVFAIL ||
-	    anhp->rcode == NOTIMP ||
-	    anhp->rcode == REFUSED) {
-		DprintQ(statp->options & RES_DEBUG,
-			(stdout, "server rejected query:\n"),
-			ans, (resplen > anssiz) ? anssiz : resplen);
-		res_nclose(statp);
-		/* don't retry if called from dig */
-		if (!statp->pfcode)
-			return (0);
-	}
-	if (!(statp->options & RES_IGNTC) && anhp->tc) {
-		/*
-		 * To get the rest of answer,
-		 * use TCP with same server.
-		 */
-		Dprint(statp->options & RES_DEBUG,
-		       (stdout, ";; truncated answer\n"));
-		*v_circuit = 1;
-		res_nclose(statp);
-		return (1);
-	}
-	/*
-	 * All is well, or the error is fatal.  Signal that the
-	 * next nameserver ought not be tried.
-	 */
-	return (resplen);
-}
-
-static void
-Aerror(const res_state statp, FILE *file, const char *string, int error,
-       const struct sockaddr *address, int alen)
-{
-	int save = errno;
-	char hbuf[NI_MAXHOST];
-	char sbuf[NI_MAXSERV];
-
-	alen = alen;
-
-	if ((statp->options & RES_DEBUG) != 0U) {
-		if (getnameinfo(address, (socklen_t)alen, hbuf, sizeof(hbuf),
-		    sbuf, sizeof(sbuf), niflags)) {
-			strncpy(hbuf, "?", sizeof(hbuf) - 1);
-			hbuf[sizeof(hbuf) - 1] = '\0';
-			strncpy(sbuf, "?", sizeof(sbuf) - 1);
-			sbuf[sizeof(sbuf) - 1] = '\0';
-		}
-		fprintf(file, "res_send: %s ([%s].%s): %s\n",
-			string, hbuf, sbuf, strerror(error));
-	}
-	errno = save;
-}
-
-static void
-Perror(const res_state statp, FILE *file, const char *string, int error) {
-	int save = errno;
-
-	if ((statp->options & RES_DEBUG) != 0U)
-		fprintf(file, "res_send: %s: %s\n",
-			string, strerror(error));
-	errno = save;
-}
-
-static int
-sock_eq(struct sockaddr *a, struct sockaddr *b) {
-	struct sockaddr_in *a4, *b4;
-	struct sockaddr_in6 *a6, *b6;
-
-	if (a->sa_family != b->sa_family)
-		return 0;
-	switch (a->sa_family) {
-	case AF_INET:
-		a4 = (struct sockaddr_in *)(void *)a;
-		b4 = (struct sockaddr_in *)(void *)b;
-		return a4->sin_port == b4->sin_port &&
-		    a4->sin_addr.s_addr == b4->sin_addr.s_addr;
-	case AF_INET6:
-		a6 = (struct sockaddr_in6 *)(void *)a;
-		b6 = (struct sockaddr_in6 *)(void *)b;
-		return a6->sin6_port == b6->sin6_port &&
-#ifdef HAVE_SIN6_SCOPE_ID
-		    a6->sin6_scope_id == b6->sin6_scope_id &&
-#endif
-		    IN6_ARE_ADDR_EQUAL(&a6->sin6_addr, &b6->sin6_addr);
-	default:
-		return 0;
-	}
-}
-
-#ifdef NEED_PSELECT
-/* XXX needs to move to the porting library. */
-static int
-pselect(int nfds, void *rfds, void *wfds, void *efds,
-	struct timespec *tsp, const sigset_t *sigmask)
-{
-	struct timeval tv, *tvp;
-	sigset_t sigs;
-	int n;
-
-	if (tsp) {
-		tvp = &tv;
-		tv = evTimeVal(*tsp);
-	} else
-		tvp = NULL;
-	if (sigmask)
-		sigprocmask(SIG_SETMASK, sigmask, &sigs);
-	n = select(nfds, rfds, wfds, efds, tvp);
-	if (sigmask)
-		sigprocmask(SIG_SETMASK, &sigs, NULL);
-	if (tsp)
-		*tsp = evTimeSpec(tv);
-	return (n);
-}
-#endif
diff --git a/libc/netbsd/resolv/res_state.c b/libc/netbsd/resolv/res_state.c
deleted file mode 100644
index f5d01a1..0000000
--- a/libc/netbsd/resolv/res_state.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-#include <netdb.h>
-#include "resolv_private.h"
-#include "resolv_cache.h"
-#include <pthread.h>
-#include <stdlib.h>
-
-#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
-#include <sys/_system_properties.h>
-
-/* Set to 1 to enable debug traces */
-#define DEBUG 0
-
-#if DEBUG
-#  include "private/libc_logging.h"
-#  include <unistd.h>  /* for gettid() */
-#  define D(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc", __VA_ARGS__)
-#else
-#  define D(...)  do{}while(0)
-#endif
-
-static pthread_key_t   _res_key;
-static pthread_once_t  _res_once = PTHREAD_ONCE_INIT;
-
-typedef struct {
-    int                  _h_errno;
-    struct __res_state  _nres[1];
-    unsigned             _serial;
-    struct prop_info*   _pi;
-    struct res_static   _rstatic[1];
-} _res_thread;
-
-static _res_thread*
-_res_thread_alloc(void)
-{
-    _res_thread*  rt = calloc(1, sizeof(*rt));
-
-    if (rt) {
-        rt->_h_errno = 0;
-        /* Special system property which tracks any changes to 'net.*'. */
-        rt->_serial = 0;
-        rt->_pi = (struct prop_info*) __system_property_find("net.change");
-        if (rt->_pi) {
-            rt->_serial = __system_property_serial(rt->_pi);
-        }
-        memset(rt->_rstatic, 0, sizeof rt->_rstatic);
-    }
-    return rt;
-}
-
-static void
-_res_static_done( res_static  rs )
-{
-    /* fortunately, there is nothing to do here, since the
-     * points in h_addr_ptrs and host_aliases should all
-     * point to 'hostbuf'
-     */
-    if (rs->hostf) {  /* should not happen in theory, but just be safe */
-        fclose(rs->hostf);
-        rs->hostf = NULL;
-    }
-    free(rs->servent.s_aliases);
-}
-
-static void
-_res_thread_free( void*  _rt )
-{
-    _res_thread*  rt = _rt;
-
-    D("%s: rt=%p for thread=%d", __FUNCTION__, rt, gettid());
-
-    _res_static_done(rt->_rstatic);
-    res_ndestroy(rt->_nres);
-    free(rt);
-}
-
-static void
-_res_init_key( void )
-{
-    pthread_key_create( &_res_key, _res_thread_free );
-}
-
-static _res_thread*
-_res_thread_get(void)
-{
-    _res_thread*  rt;
-    pthread_once( &_res_once, _res_init_key );
-    rt = pthread_getspecific( _res_key );
-
-    if (rt != NULL) {
-        /* We already have one thread-specific DNS state object.
-         * Check the serial value for any changes to net.* properties */
-        D("%s: Called for tid=%d rt=%p rt->pi=%p rt->serial=%d",
-           __FUNCTION__, gettid(), rt, rt->_pi, rt->_serial);
-        if (rt->_pi == NULL) {
-            /* The property wasn't created when _res_thread_get() was
-             * called the last time. This should only happen very
-             * early during the boot sequence. First, let's try to see if it
-             * is here now. */
-            rt->_pi = (struct prop_info*) __system_property_find("net.change");
-            if (rt->_pi == NULL) {
-                /* Still nothing, return current state */
-                D("%s: exiting for tid=%d rt=%d since system property not found",
-                  __FUNCTION__, gettid(), rt);
-                return rt;
-            }
-        }
-        if (rt->_serial == __system_property_serial(rt->_pi)) {
-            /* Nothing changed, so return the current state */
-            D("%s: tid=%d rt=%p nothing changed, returning",
-              __FUNCTION__, gettid(), rt);
-            return rt;
-        }
-        /* Update the recorded serial number, and go reset the state */
-        rt->_serial = __system_property_serial(rt->_pi);
-        goto RESET_STATE;
-    }
-
-    /* It is the first time this function is called in this thread,
-     * we need to create a new thread-specific DNS resolver state. */
-    rt = _res_thread_alloc();
-    if (rt == NULL) {
-        return NULL;
-    }
-    pthread_setspecific( _res_key, rt );
-    D("%s: tid=%d Created new DNS state rt=%p",
-      __FUNCTION__, gettid(), rt);
-
-RESET_STATE:
-    /* Reset the state, note that res_ninit() can now properly reset
-     * an existing state without leaking memory.
-     */
-    D("%s: tid=%d, rt=%p, resetting DNS state (options RES_INIT=%d)",
-      __FUNCTION__, gettid(), rt, (rt->_nres->options & RES_INIT) != 0);
-    if ( res_ninit( rt->_nres ) < 0 ) {
-        /* This should not happen */
-        D("%s: tid=%d rt=%p, woot, res_ninit() returned < 0",
-          __FUNCTION__, gettid(), rt);
-        _res_thread_free(rt);
-        pthread_setspecific( _res_key, NULL );
-        return NULL;
-    }
-    return rt;
-}
-
-__LIBC_HIDDEN__
-struct __res_state _nres;
-
-#if 0
-struct resolv_cache*
-__get_res_cache(void)
-{
-    _res_thread*  rt = _res_thread_get();
-
-    if (!rt)
-        return NULL;
-
-    if (!rt->_cache) {
-        rt->_cache = _resolv_cache_create();
-    }
-    return rt->_cache;
-}
-#endif
-
-int*
-__get_h_errno(void)
-{
-    _res_thread*  rt    = _res_thread_get();
-    static int    panic = NETDB_INTERNAL;
-
-    return rt ? &rt->_h_errno : &panic;
-}
-
-res_state
-__res_get_state(void)
-{
-    _res_thread*  rt = _res_thread_get();
-
-    return rt ? rt->_nres : NULL;
-}
-
-void
-__res_put_state(res_state res)
-{
-    /* nothing to do */
-    res=res;
-}
-
-res_static
-__res_get_static(void)
-{
-    _res_thread*  rt = _res_thread_get();
-
-    return rt ? rt->_rstatic : NULL;
-}
diff --git a/libc/private/ErrnoRestorer.h b/libc/private/ErrnoRestorer.h
index ed6ab62..f467393 100644
--- a/libc/private/ErrnoRestorer.h
+++ b/libc/private/ErrnoRestorer.h
@@ -19,6 +19,8 @@
 
 #include <errno.h>
 
+#include "bionic_macros.h"
+
 class ErrnoRestorer {
  public:
   explicit ErrnoRestorer() : saved_errno_(errno) {
@@ -35,9 +37,7 @@
  private:
   int saved_errno_;
 
-  // Disallow copy and assignment.
-  ErrnoRestorer(const ErrnoRestorer&);
-  void operator=(const ErrnoRestorer&);
+  DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer);
 };
 
 #endif // ERRNO_RESTORER_H
diff --git a/libc/private/KernelArgumentBlock.h b/libc/private/KernelArgumentBlock.h
index 105965e..c8ea497 100644
--- a/libc/private/KernelArgumentBlock.h
+++ b/libc/private/KernelArgumentBlock.h
@@ -18,9 +18,12 @@
 #define KERNEL_ARGUMENT_BLOCK_H
 
 #include <elf.h>
+#include <link.h>
 #include <stdint.h>
 #include <sys/auxv.h>
 
+#include "private/bionic_macros.h"
+
 struct abort_msg_t;
 
 // When the kernel starts the dynamic linker, it passes a pointer to a block
@@ -43,14 +46,14 @@
     }
     ++p; // Skip second NULL;
 
-    auxv = reinterpret_cast<Elf_auxv_t*>(p);
+    auxv = reinterpret_cast<ElfW(auxv_t)*>(p);
   }
 
   // Similar to ::getauxval but doesn't require the libc global variables to be set up,
   // so it's safe to call this really early on. This function also lets you distinguish
   // between the inability to find the given type and its value just happening to be 0.
   unsigned long getauxval(unsigned long type, bool* found_match = NULL) {
-    for (Elf_auxv_t* v = auxv; v->a_type != AT_NULL; ++v) {
+    for (ElfW(auxv_t)* v = auxv; v->a_type != AT_NULL; ++v) {
       if (v->a_type == type) {
         if (found_match != NULL) {
             *found_match = true;
@@ -67,14 +70,12 @@
   int argc;
   char** argv;
   char** envp;
-  Elf_auxv_t* auxv;
+  ElfW(auxv_t)* auxv;
 
   abort_msg_t** abort_message_ptr;
 
  private:
-  // Disallow copy and assignment.
-  KernelArgumentBlock(const KernelArgumentBlock&);
-  void operator=(const KernelArgumentBlock&);
+  DISALLOW_COPY_AND_ASSIGN(KernelArgumentBlock);
 };
 
 #endif // KERNEL_ARGUMENT_BLOCK_H
diff --git a/libc/private/NetdClientDispatch.h b/libc/private/NetdClientDispatch.h
new file mode 100644
index 0000000..8d8947d
--- /dev/null
+++ b/libc/private/NetdClientDispatch.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PRIVATE_NETD_CLIENT_DISPATCH_H
+#define PRIVATE_NETD_CLIENT_DISPATCH_H
+
+#include <sys/cdefs.h>
+#include <sys/socket.h>
+
+__BEGIN_DECLS
+
+struct NetdClientDispatch {
+    int (*accept4)(int, struct sockaddr*, socklen_t*, int);
+    int (*connect)(int, const struct sockaddr*, socklen_t);
+    int (*socket)(int, int, int);
+    unsigned (*netIdForResolv)(unsigned);
+};
+
+extern __LIBC_HIDDEN__ struct NetdClientDispatch __netdClientDispatch;
+
+__END_DECLS
+
+#endif  // PRIVATE_NETD_CLIENT_DISPATCH_H
diff --git a/libc/private/ScopeGuard.h b/libc/private/ScopeGuard.h
new file mode 100644
index 0000000..183e322
--- /dev/null
+++ b/libc/private/ScopeGuard.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SCOPE_GUARD_H
+#define SCOPE_GUARD_H
+
+// TODO: include explicit std::move when it becomes available
+template<typename F>
+class ScopeGuard {
+ public:
+  ScopeGuard(F f) : f_(f), active_(true) {}
+
+  ScopeGuard(ScopeGuard&& that) : f_(that.f_), active_(that.active_) {
+    that.active_ = false;
+  }
+
+  ~ScopeGuard() {
+    if (active_) {
+      f_();
+    }
+  }
+
+  void disable() {
+    active_ = false;
+  }
+ private:
+  F f_;
+  bool active_;
+
+  ScopeGuard() = delete;
+  ScopeGuard(const ScopeGuard&) = delete;
+  ScopeGuard& operator=(const ScopeGuard&) = delete;
+};
+
+template<typename T>
+ScopeGuard<T> create_scope_guard(T f) {
+  return ScopeGuard<T>(f);
+}
+
+#endif  // SCOPE_GUARD_H
diff --git a/libc/private/ScopedFd.h b/libc/private/ScopedFd.h
new file mode 100644
index 0000000..e56c139
--- /dev/null
+++ b/libc/private/ScopedFd.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SCOPED_FD_H
+#define SCOPED_FD_H
+
+#include <unistd.h>
+#include "bionic_macros.h"
+
+// A smart pointer that closes the given fd on going out of scope.
+// Use this when the fd is incidental to the purpose of your function,
+// but needs to be cleaned up on exit.
+class ScopedFd {
+public:
+    explicit ScopedFd(int fd) : fd(fd) {
+    }
+
+    ~ScopedFd() {
+      reset();
+    }
+
+    int get() const {
+        return fd;
+    }
+
+    int release() __attribute__((warn_unused_result)) {
+        int localFd = fd;
+        fd = -1;
+        return localFd;
+    }
+
+    void reset(int new_fd = -1) {
+      if (fd != -1) {
+          TEMP_FAILURE_RETRY(close(fd));
+      }
+      fd = new_fd;
+    }
+
+private:
+    int fd;
+
+    // Disallow copy and assignment.
+    DISALLOW_COPY_AND_ASSIGN(ScopedFd);
+};
+
+#endif  // SCOPED_FD_H
diff --git a/libc/private/ScopedPthreadMutexLocker.h b/libc/private/ScopedPthreadMutexLocker.h
index 06b8e37..43dbdc1 100644
--- a/libc/private/ScopedPthreadMutexLocker.h
+++ b/libc/private/ScopedPthreadMutexLocker.h
@@ -19,6 +19,8 @@
 
 #include <pthread.h>
 
+#include "bionic_macros.h"
+
 class ScopedPthreadMutexLocker {
  public:
   explicit ScopedPthreadMutexLocker(pthread_mutex_t* mu) : mu_(mu) {
@@ -32,9 +34,7 @@
  private:
   pthread_mutex_t* mu_;
 
-  // Disallow copy and assignment.
-  ScopedPthreadMutexLocker(const ScopedPthreadMutexLocker&);
-  void operator=(const ScopedPthreadMutexLocker&);
+  DISALLOW_COPY_AND_ASSIGN(ScopedPthreadMutexLocker);
 };
 
 #endif // SCOPED_PTHREAD_MUTEX_LOCKER_H
diff --git a/libc/private/ScopedReaddir.h b/libc/private/ScopedReaddir.h
index 797809a..84c1b93 100644
--- a/libc/private/ScopedReaddir.h
+++ b/libc/private/ScopedReaddir.h
@@ -19,6 +19,8 @@
 
 #include <dirent.h>
 
+#include "private/bionic_macros.h"
+
 class ScopedReaddir {
  public:
   ScopedReaddir(const char* path) {
@@ -42,9 +44,7 @@
  private:
   DIR* dir_;
 
-  // Disallow copy and assignment.
-  ScopedReaddir(const ScopedReaddir&);
-  void operator=(const ScopedReaddir&);
+  DISALLOW_COPY_AND_ASSIGN(ScopedReaddir);
 };
 
 #endif // SCOPED_READDIR_H
diff --git a/libc/private/arpa_nameser.h b/libc/private/arpa_nameser.h
deleted file mode 100644
index 421c3ee..0000000
--- a/libc/private/arpa_nameser.h
+++ /dev/null
@@ -1,576 +0,0 @@
-/*	$NetBSD: nameser.h,v 1.19 2005/12/26 19:01:47 perry Exp $	*/
-
-/*
- * Copyright (c) 1983, 1989, 1993
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-/*
- *	Id: nameser.h,v 1.2.2.4.4.1 2004/03/09 08:33:30 marka Exp
- */
-
-#ifndef _ARPA_NAMESER_H_
-#define _ARPA_NAMESER_H_
-
-#define BIND_4_COMPAT
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-/*
- * Revision information.  This is the release date in YYYYMMDD format.
- * It can change every day so the right thing to do with it is use it
- * in preprocessor commands such as "#if (__NAMESER > 19931104)".  Do not
- * compare for equality; rather, use it to determine whether your libbind.a
- * contains a new enough lib/nameser/ to support the feature you need.
- */
-
-#define __NAMESER	19991006	/* New interface version stamp. */
-
-/*
- * Define constants based on RFC 883, RFC 1034, RFC 1035
- */
-#define NS_PACKETSZ	512	/* default UDP packet size */
-#define NS_MAXDNAME	1025	/* maximum domain name */
-#define NS_MAXMSG	65535	/* maximum message size */
-#define NS_MAXCDNAME	255	/* maximum compressed domain name */
-#define NS_MAXLABEL	63	/* maximum length of domain label */
-#define NS_HFIXEDSZ	12	/* #/bytes of fixed data in header */
-#define NS_QFIXEDSZ	4	/* #/bytes of fixed data in query */
-#define NS_RRFIXEDSZ	10	/* #/bytes of fixed data in r record */
-#define NS_INT32SZ	4	/* #/bytes of data in a uint32_t */
-#define NS_INT16SZ	2	/* #/bytes of data in a uint16_t */
-#define NS_INT8SZ	1	/* #/bytes of data in a uint8_t */
-#define NS_INADDRSZ	4	/* IPv4 T_A */
-#define NS_IN6ADDRSZ	16	/* IPv6 T_AAAA */
-#define NS_CMPRSFLGS	0xc0	/* Flag bits indicating name compression. */
-#define NS_DEFAULTPORT	53	/* For both TCP and UDP. */
-
-/*
- * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
- * in synch with it.
- */
-typedef enum __ns_sect {
-	ns_s_qd = 0,		/* Query: Question. */
-	ns_s_zn = 0,		/* Update: Zone. */
-	ns_s_an = 1,		/* Query: Answer. */
-	ns_s_pr = 1,		/* Update: Prerequisites. */
-	ns_s_ns = 2,		/* Query: Name servers. */
-	ns_s_ud = 2,		/* Update: Update. */
-	ns_s_ar = 3,		/* Query|Update: Additional records. */
-	ns_s_max = 4
-} ns_sect;
-
-/*
- * This is a message handle.  It is caller allocated and has no dynamic data.
- * This structure is intended to be opaque to all but ns_parse.c, thus the
- * leading _'s on the member names.  Use the accessor functions, not the _'s.
- */
-typedef struct __ns_msg {
-	const u_char	*_msg, *_eom;
-	uint16_t	_id, _flags, _counts[ns_s_max];
-	const u_char	*_sections[ns_s_max];
-	ns_sect		_sect;
-	int		_rrnum;
-	const u_char	*_msg_ptr;
-} ns_msg;
-
-/* Private data structure - do not use from outside library. */
-struct _ns_flagdata {  int mask, shift;  };
-extern const struct _ns_flagdata _ns_flagdata[];
-
-/* Accessor macros - this is part of the public interface. */
-
-#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) ((size_t)((handle)._eom - (handle)._msg))
-#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
-
-/*
- * This is a parsed record.  It is caller allocated and has no dynamic data.
- */
-typedef	struct __ns_rr {
-	char		name[NS_MAXDNAME];
-	uint16_t	type;
-	uint16_t	rr_class;
-	uint32_t	ttl;
-	uint16_t	rdlength;
-	const u_char *	rdata;
-} ns_rr;
-
-/* Accessor macros - this is part of the public interface. */
-#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)	((u_long)(rr).ttl + 0)
-#define ns_rr_rdlen(rr)	((size_t)(rr).rdlength + 0)
-#define ns_rr_rdata(rr)	((rr).rdata + 0)
-
-/*
- * These don't have to be in the same order as in the packet flags word,
- * and they can even overlap in some cases, but they will need to be kept
- * in synch with ns_parse.c:ns_flagdata[].
- */
-typedef enum __ns_flag {
-	ns_f_qr,		/* Question/Response. */
-	ns_f_opcode,		/* Operation code. */
-	ns_f_aa,		/* Authoritative Answer. */
-	ns_f_tc,		/* Truncation occurred. */
-	ns_f_rd,		/* Recursion Desired. */
-	ns_f_ra,		/* Recursion Available. */
-	ns_f_z,			/* MBZ. */
-	ns_f_ad,		/* Authentic Data (DNSSEC). */
-	ns_f_cd,		/* Checking Disabled (DNSSEC). */
-	ns_f_rcode,		/* Response code. */
-	ns_f_max
-} ns_flag;
-
-/*
- * Currently defined opcodes.
- */
-typedef enum __ns_opcode {
-	ns_o_query = 0,		/* Standard query. */
-	ns_o_iquery = 1,	/* Inverse query (deprecated/unsupported). */
-	ns_o_status = 2,	/* Name server status query (unsupported). */
-				/* Opcode 3 is undefined/reserved. */
-	ns_o_notify = 4,	/* Zone change notification. */
-	ns_o_update = 5,	/* Zone update message. */
-	ns_o_max = 6
-} ns_opcode;
-
-/*
- * Currently defined response codes.
- */
-typedef	enum __ns_rcode {
-	ns_r_noerror = 0,	/* No error occurred. */
-	ns_r_formerr = 1,	/* Format error. */
-	ns_r_servfail = 2,	/* Server failure. */
-	ns_r_nxdomain = 3,	/* Name error. */
-	ns_r_notimpl = 4,	/* Unimplemented. */
-	ns_r_refused = 5,	/* Operation refused. */
-	/* these are for BIND_UPDATE */
-	ns_r_yxdomain = 6,	/* Name exists */
-	ns_r_yxrrset = 7,	/* RRset exists */
-	ns_r_nxrrset = 8,	/* RRset does not exist */
-	ns_r_notauth = 9,	/* Not authoritative for zone */
-	ns_r_notzone = 10,	/* Zone of record different from zone section */
-	ns_r_max = 11,
-	/* The following are EDNS extended rcodes */
-	ns_r_badvers = 16,
-	/* The following are TSIG errors */
-	ns_r_badsig = 16,
-	ns_r_badkey = 17,
-	ns_r_badtime = 18
-} ns_rcode;
-
-/* BIND_UPDATE */
-typedef enum __ns_update_operation {
-	ns_uop_delete = 0,
-	ns_uop_add = 1,
-	ns_uop_max = 2
-} ns_update_operation;
-
-/*
- * This structure is used for TSIG authenticated messages
- */
-struct ns_tsig_key {
-        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
-        unsigned char *data;
-        int len;
-};
-typedef struct ns_tsig_key ns_tsig_key;
-
-/*
- * This structure is used for TSIG authenticated TCP messages
- */
-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
-
-/*
- * Currently defined type values for resources and queries.
- */
-typedef enum __ns_type {
-	ns_t_invalid = 0,	/* Cookie. */
-	ns_t_a = 1,		/* Host address. */
-	ns_t_ns = 2,		/* Authoritative server. */
-	ns_t_md = 3,		/* Mail destination. */
-	ns_t_mf = 4,		/* Mail forwarder. */
-	ns_t_cname = 5,		/* Canonical name. */
-	ns_t_soa = 6,		/* Start of authority zone. */
-	ns_t_mb = 7,		/* Mailbox domain name. */
-	ns_t_mg = 8,		/* Mail group member. */
-	ns_t_mr = 9,		/* Mail rename name. */
-	ns_t_null = 10,		/* Null resource record. */
-	ns_t_wks = 11,		/* Well known service. */
-	ns_t_ptr = 12,		/* Domain name pointer. */
-	ns_t_hinfo = 13,	/* Host information. */
-	ns_t_minfo = 14,	/* Mailbox information. */
-	ns_t_mx = 15,		/* Mail routing information. */
-	ns_t_txt = 16,		/* Text strings. */
-	ns_t_rp = 17,		/* Responsible person. */
-	ns_t_afsdb = 18,	/* AFS cell database. */
-	ns_t_x25 = 19,		/* X_25 calling address. */
-	ns_t_isdn = 20,		/* ISDN calling address. */
-	ns_t_rt = 21,		/* Router. */
-	ns_t_nsap = 22,		/* NSAP address. */
-	ns_t_nsap_ptr = 23,	/* Reverse NSAP lookup (deprecated). */
-	ns_t_sig = 24,		/* Security signature. */
-	ns_t_key = 25,		/* Security key. */
-	ns_t_px = 26,		/* X.400 mail mapping. */
-	ns_t_gpos = 27,		/* Geographical position (withdrawn). */
-	ns_t_aaaa = 28,		/* Ip6 Address. */
-	ns_t_loc = 29,		/* Location Information. */
-	ns_t_nxt = 30,		/* Next domain (security). */
-	ns_t_eid = 31,		/* Endpoint identifier. */
-	ns_t_nimloc = 32,	/* Nimrod Locator. */
-	ns_t_srv = 33,		/* Server Selection. */
-	ns_t_atma = 34,		/* ATM Address */
-	ns_t_naptr = 35,	/* Naming Authority PoinTeR */
-	ns_t_kx = 36,		/* Key Exchange */
-	ns_t_cert = 37,		/* Certification record */
-	ns_t_a6 = 38,		/* IPv6 address (deprecates AAAA) */
-	ns_t_dname = 39,	/* Non-terminal DNAME (for IPv6) */
-	ns_t_sink = 40,		/* Kitchen sink (experimentatl) */
-	ns_t_opt = 41,		/* EDNS0 option (meta-RR) */
-	ns_t_apl = 42,		/* Address prefix list (RFC 3123) */
-	ns_t_tkey = 249,	/* Transaction key */
-	ns_t_tsig = 250,	/* Transaction signature. */
-	ns_t_ixfr = 251,	/* Incremental zone transfer. */
-	ns_t_axfr = 252,	/* Transfer zone of authority. */
-	ns_t_mailb = 253,	/* Transfer mailbox records. */
-	ns_t_maila = 254,	/* Transfer mail agent records. */
-	ns_t_any = 255,		/* Wildcard match. */
-	ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */
-	ns_t_max = 65536
-} ns_type;
-
-/* Exclusively a QTYPE? (not also an RTYPE) */
-#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
-		      (t) == ns_t_mailb || (t) == ns_t_maila)
-/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
-#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
-/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
-#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)
-
-/*
- * Values for class field
- */
-typedef enum __ns_class {
-	ns_c_invalid = 0,	/* Cookie. */
-	ns_c_in = 1,		/* Internet. */
-	ns_c_2 = 2,		/* unallocated/unsupported. */
-	ns_c_chaos = 3,		/* MIT Chaos-net. */
-	ns_c_hs = 4,		/* MIT Hesiod. */
-	/* Query class values which do not appear in resource records */
-	ns_c_none = 254,	/* for prereq. sections in update requests */
-	ns_c_any = 255,		/* Wildcard match. */
-	ns_c_max = 65536
-} ns_class;
-
-/* DNSSEC constants. */
-
-typedef enum __ns_key_types {
-	ns_kt_rsa = 1,		/* key type RSA/MD5 */
-	ns_kt_dh  = 2,		/* Diffie Hellman */
-	ns_kt_dsa = 3,		/* Digital Signature Standard (MANDATORY) */
-	ns_kt_private = 254	/* Private key type starts with OID */
-} ns_key_types;
-
-typedef enum __ns_cert_types {
-	cert_t_pkix = 1,	/* PKIX (X.509v3) */
-	cert_t_spki = 2,	/* SPKI */
-	cert_t_pgp  = 3,	/* PGP */
-	cert_t_url  = 253,	/* URL private type */
-	cert_t_oid  = 254	/* OID private type */
-} ns_cert_types;
-
-/* Flags field of the KEY RR rdata. */
-#define	NS_KEY_TYPEMASK		0xC000	/* Mask for "type" bits */
-#define	NS_KEY_TYPE_AUTH_CONF	0x0000	/* Key usable for both */
-#define	NS_KEY_TYPE_CONF_ONLY	0x8000	/* Key usable for confidentiality */
-#define	NS_KEY_TYPE_AUTH_ONLY	0x4000	/* Key usable for authentication */
-#define	NS_KEY_TYPE_NO_KEY	0xC000	/* No key usable for either; no key */
-/* The type bits can also be interpreted independently, as single bits: */
-#define	NS_KEY_NO_AUTH		0x8000	/* Key unusable for authentication */
-#define	NS_KEY_NO_CONF		0x4000	/* Key unusable for confidentiality */
-#define	NS_KEY_RESERVED2	0x2000	/* Security is *mandatory* if bit=0 */
-#define	NS_KEY_EXTENDED_FLAGS	0x1000	/* reserved - must be zero */
-#define	NS_KEY_RESERVED4	0x0800  /* reserved - must be zero */
-#define	NS_KEY_RESERVED5	0x0400  /* reserved - must be zero */
-#define	NS_KEY_NAME_TYPE	0x0300	/* these bits determine the type */
-#define	NS_KEY_NAME_USER	0x0000	/* key is assoc. with user */
-#define	NS_KEY_NAME_ENTITY	0x0200	/* key is assoc. with entity eg host */
-#define	NS_KEY_NAME_ZONE	0x0100	/* key is zone key */
-#define	NS_KEY_NAME_RESERVED	0x0300	/* reserved meaning */
-#define	NS_KEY_RESERVED8	0x0080  /* reserved - must be zero */
-#define	NS_KEY_RESERVED9	0x0040  /* reserved - must be zero */
-#define	NS_KEY_RESERVED10	0x0020  /* reserved - must be zero */
-#define	NS_KEY_RESERVED11	0x0010  /* reserved - must be zero */
-#define	NS_KEY_SIGNATORYMASK	0x000F	/* key can sign RR's of same name */
-#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 /* no bits defined here */
-
-/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
-#define	NS_ALG_MD5RSA		1	/* MD5 with RSA */
-#define	NS_ALG_DH               2	/* Diffie Hellman KEY */
-#define	NS_ALG_DSA              3	/* DSA KEY */
-#define	NS_ALG_DSS              NS_ALG_DSA
-#define	NS_ALG_EXPIRE_ONLY	253	/* No alg, no security */
-#define	NS_ALG_PRIVATE_OID	254	/* Key begins with OID giving alg */
-
-/* Protocol values  */
-/* value 0 is reserved */
-#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
-
-/* Signatures */
-#define	NS_MD5RSA_MIN_BITS	 512	/* Size of a mod or exp in bits */
-#define	NS_MD5RSA_MAX_BITS	4096
-	/* Total of binary mod and exp */
-#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
-	/* Max length of text sig block */
-#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
-
-/* Offsets into SIG record rdata to find various values */
-#define	NS_SIG_TYPE	0	/* Type flags */
-#define	NS_SIG_ALG	2	/* Algorithm */
-#define	NS_SIG_LABELS	3	/* How many labels in name */
-#define	NS_SIG_OTTL	4	/* Original TTL */
-#define	NS_SIG_EXPIR	8	/* Expiration time */
-#define	NS_SIG_SIGNED	12	/* Signature time */
-#define	NS_SIG_FOOT	16	/* Key footprint */
-#define	NS_SIG_SIGNER	18	/* Domain name of who signed it */
-
-/* How RR types are represented as bit-flags in NXT records */
-#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
-
-/*
- * EDNS0 extended flags, host order.
- */
-#define NS_OPT_DNSSEC_OK	0x8000U
-
-/*
- * Inline versions of get/put short/long.  Pointer is advanced.
- */
-#define NS_GET16(s, cp) do { \
-	const u_char *t_cp = (const u_char *)(cp); \
-	(s) = ((uint16_t)t_cp[0] << 8) \
-	    | ((uint16_t)t_cp[1]) \
-	    ; \
-	(cp) += NS_INT16SZ; \
-} while (/*CONSTCOND*/0)
-
-#define NS_GET32(l, cp) do { \
-	const u_char *t_cp = (const u_char *)(cp); \
-	(l) = ((uint32_t)t_cp[0] << 24) \
-	    | ((uint32_t)t_cp[1] << 16) \
-	    | ((uint32_t)t_cp[2] << 8) \
-	    | ((uint32_t)t_cp[3]) \
-	    ; \
-	(cp) += NS_INT32SZ; \
-} while (/*CONSTCOND*/0)
-
-#define NS_PUT16(s, cp) do { \
-	uint32_t t_s = (uint32_t)(s); \
-	u_char *t_cp = (u_char *)(cp); \
-	*t_cp++ = t_s >> 8; \
-	*t_cp   = t_s; \
-	(cp) += NS_INT16SZ; \
-} while (/*CONSTCOND*/0)
-
-#define NS_PUT32(l, cp) do { \
-	uint32_t t_l = (uint32_t)(l); \
-	u_char *t_cp = (u_char *)(cp); \
-	*t_cp++ = t_l >> 24; \
-	*t_cp++ = t_l >> 16; \
-	*t_cp++ = t_l >> 8; \
-	*t_cp   = t_l; \
-	(cp) += NS_INT32SZ; \
-} while (/*CONSTCOND*/0)
-
-/*
- * ANSI C identifier hiding for bind's lib/nameser.
- */
-#define	ns_msg_getflag		__ns_msg_getflag
-#define ns_get16		__ns_get16
-#define ns_get32		__ns_get32
-#define ns_put16		__ns_put16
-#define ns_put32		__ns_put32
-#define ns_initparse		__ns_initparse
-#define ns_skiprr		__ns_skiprr
-#define ns_parserr		__ns_parserr
-#define	ns_sprintrr		__ns_sprintrr
-#define	ns_sprintrrf		__ns_sprintrrf
-#define	ns_format_ttl		__ns_format_ttl
-#define	ns_parse_ttl		__ns_parse_ttl
-#define ns_datetosecs		__ns_datetosecs
-#define	ns_name_ntol		__ns_name_ntol
-#define	ns_name_ntop		__ns_name_ntop
-#define	ns_name_pton		__ns_name_pton
-#define	ns_name_unpack		__ns_name_unpack
-#define	ns_name_pack		__ns_name_pack
-#define	ns_name_compress	__ns_name_compress
-#define	ns_name_uncompress	__ns_name_uncompress
-#define	ns_name_skip		__ns_name_skip
-#define	ns_name_rollback	__ns_name_rollback
-#define	ns_sign			__ns_sign
-#define	ns_sign2		__ns_sign2
-#define	ns_sign_tcp		__ns_sign_tcp
-#define	ns_sign_tcp2		__ns_sign_tcp2
-#define	ns_sign_tcp_init	__ns_sign_tcp_init
-#define ns_find_tsig		__ns_find_tsig
-#define	ns_verify		__ns_verify
-#define	ns_verify_tcp		__ns_verify_tcp
-#define	ns_verify_tcp_init	__ns_verify_tcp_init
-#define	ns_samedomain		__ns_samedomain
-#define	ns_subdomain		__ns_subdomain
-#define	ns_makecanon		__ns_makecanon
-#define	ns_samename		__ns_samename
-
-__BEGIN_DECLS
-int		ns_msg_getflag(ns_msg, int);
-uint16_t	ns_get16(const u_char *);
-uint32_t	ns_get32(const u_char *);
-void		ns_put16(uint16_t, u_char *);
-void		ns_put32(uint32_t, u_char *);
-int		ns_initparse(const u_char *, int, ns_msg *);
-int		ns_skiprr(const u_char *, const u_char *, ns_sect, int);
-int		ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
-int		ns_sprintrr(const ns_msg *, const ns_rr *,
-				 const char *, const char *, char *, size_t);
-int		ns_sprintrrf(const u_char *, size_t, const char *,
-				  ns_class, ns_type, u_long, const u_char *,
-				  size_t, const char *, const char *,
-				  char *, size_t);
-int		ns_format_ttl(u_long, char *, size_t);
-int		ns_parse_ttl(const char *, u_long *);
-uint32_t	ns_datetosecs(const char *cp, int *errp);
-int		ns_name_ntol(const u_char *, u_char *, size_t);
-int		ns_name_ntop(const u_char *, char *, size_t);
-int		ns_name_pton(const char *, u_char *, size_t);
-int		ns_name_unpack(const u_char *, const u_char *,
-				    const u_char *, u_char *, size_t);
-int		ns_name_pack(const u_char *, u_char *, int,
-				  const u_char **, const u_char **);
-int		ns_name_uncompress(const u_char *, const u_char *,
-					const u_char *, char *, size_t);
-int		ns_name_compress(const char *, u_char *, size_t,
-				      const u_char **, const u_char **);
-int		ns_name_skip(const u_char **, const u_char *);
-void		ns_name_rollback(const u_char *, const u_char **,
-				      const u_char **);
-int		ns_sign(u_char *, int *, int, int, void *,
-			     const u_char *, int, u_char *, int *, time_t);
-int		ns_sign2(u_char *, int *, int, int, void *,
-			      const u_char *, int, u_char *, int *, time_t,
-			      u_char **, u_char **);
-int		ns_sign_tcp(u_char *, int *, int, int,
-				 ns_tcp_tsig_state *, int);
-int		ns_sign_tcp2(u_char *, int *, int, int,
-				  ns_tcp_tsig_state *, int,
-				  u_char **, u_char **);
-int		ns_sign_tcp_init(void *, const u_char *, int,
-					ns_tcp_tsig_state *);
-u_char		*ns_find_tsig(u_char *, u_char *);
-int		ns_verify(u_char *, int *, void *,
-			       const u_char *, int, u_char *, int *,
-			       time_t *, int);
-int		ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);
-int		ns_verify_tcp_init(void *, const u_char *, int,
-					ns_tcp_tsig_state *);
-int		ns_samedomain(const char *, const char *);
-int		ns_subdomain(const char *, const char *);
-int		ns_makecanon(const char *, char *, size_t);
-int		ns_samename(const char *, const char *);
-__END_DECLS
-
-#ifdef BIND_4_COMPAT
-#include "arpa_nameser_compat.h"
-#endif
-
-#if 0
-#  include "private/libc_logging.h"
-#  define XLOG(...)  __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__)
-#else
-#define  XLOG(...)   do {} while (0)
-#endif
-
-#endif /* !_ARPA_NAMESER_H_ */
diff --git a/libc/private/arpa_nameser_compat.h b/libc/private/arpa_nameser_compat.h
deleted file mode 100644
index 79bdfd0..0000000
--- a/libc/private/arpa_nameser_compat.h
+++ /dev/null
@@ -1,236 +0,0 @@
-/*	$NetBSD: nameser_compat.h,v 1.1.1.2 2004/11/07 01:28:27 christos Exp $	*/
-
-/* Copyright (c) 1983, 1989
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- *      from nameser.h	8.1 (Berkeley) 6/2/93
- *	Id: nameser_compat.h,v 1.1.2.3.4.2 2004/07/01 04:43:41 marka Exp
- */
-
-#ifndef _ARPA_NAMESER_COMPAT_
-#define	_ARPA_NAMESER_COMPAT_
-
-#define	__BIND		19950621	/* (DEAD) interface version stamp. */
-
-#include <endian.h>
-
-#ifndef BYTE_ORDER
-#if (BSD >= 199103)
-# include <machine/endian.h>
-#else
-#ifdef __linux
-# include <endian.h>
-#else
-#define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax, pc) */
-#define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
-#define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp)*/
-
-#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
-    defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
-    defined(__alpha__) || defined(__alpha) || \
-    (defined(__Lynx__) && defined(__x86__))
-#define BYTE_ORDER	LITTLE_ENDIAN
-#endif
-
-#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
-    defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
-    defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
-    defined(apollo) || defined(__convex__) || defined(_CRAY) || \
-    defined(__hppa) || defined(__hp9000) || \
-    defined(__hp9000s300) || defined(__hp9000s700) || \
-    defined(__hp3000s900) || defined(__hpux) || defined(MPE) || \
-    defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) ||  \
-    (defined(__Lynx__) && \
-     (defined(__68k__) || defined(__sparc__) || defined(__powerpc__)))
-#define BYTE_ORDER	BIG_ENDIAN
-#endif
-#endif /* __linux */
-#endif /* BSD */
-#endif /* BYTE_ORDER */
-
-#if !defined(BYTE_ORDER) || \
-    (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
-    BYTE_ORDER != PDP_ENDIAN)
-	/* you must determine what the correct bit order is for
-	 * your compiler - the next line is an intentional error
-	 * which will force your compiles to bomb until you fix
-	 * the above macros.
-	 */
-  #error "Undefined or invalid BYTE_ORDER";
-#endif
-
-/*
- * Structure for query header.  The order of the fields is machine- and
- * compiler-dependent, depending on the byte/bit order and the layout
- * of bit fields.  We use bit fields only in int variables, as this
- * is all ANSI requires.  This requires a somewhat confusing rearrangement.
- */
-
-typedef struct {
-	unsigned	id :16;		/* query identification number */
-#if BYTE_ORDER == BIG_ENDIAN
-			/* fields in third byte */
-	unsigned	qr: 1;		/* response flag */
-	unsigned	opcode: 4;	/* purpose of message */
-	unsigned	aa: 1;		/* authoritive answer */
-	unsigned	tc: 1;		/* truncated message */
-	unsigned	rd: 1;		/* recursion desired */
-			/* fields in fourth byte */
-	unsigned	ra: 1;		/* recursion available */
-	unsigned	unused :1;	/* unused bits (MBZ as of 4.9.3a3) */
-	unsigned	ad: 1;		/* authentic data from named */
-	unsigned	cd: 1;		/* checking disabled by resolver */
-	unsigned	rcode :4;	/* response code */
-#endif
-#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
-			/* fields in third byte */
-	unsigned	rd :1;		/* recursion desired */
-	unsigned	tc :1;		/* truncated message */
-	unsigned	aa :1;		/* authoritive answer */
-	unsigned	opcode :4;	/* purpose of message */
-	unsigned	qr :1;		/* response flag */
-			/* fields in fourth byte */
-	unsigned	rcode :4;	/* response code */
-	unsigned	cd: 1;		/* checking disabled by resolver */
-	unsigned	ad: 1;		/* authentic data from named */
-	unsigned	unused :1;	/* unused bits (MBZ as of 4.9.3a3) */
-	unsigned	ra :1;		/* recursion available */
-#endif
-			/* remaining bytes */
-	unsigned	qdcount :16;	/* number of question entries */
-	unsigned	ancount :16;	/* number of answer entries */
-	unsigned	nscount :16;	/* number of authority entries */
-	unsigned	arcount :16;	/* number of resource entries */
-} 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 BADSIG		ns_r_badsig*/
-/*#define BADKEY		ns_r_badkey*/
-/*#define BADTIME		ns_r_badtime*/
-
-
-#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_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
-/* BIND_UPDATE */
-#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
-
-#endif /* _ARPA_NAMESER_COMPAT_ */
diff --git a/libc/private/bionic_asm.h b/libc/private/bionic_asm.h
index 803ff29..7c2686f 100644
--- a/libc/private/bionic_asm.h
+++ b/libc/private/bionic_asm.h
@@ -29,15 +29,32 @@
 #ifndef _PRIVATE_BIONIC_ASM_H_
 #define _PRIVATE_BIONIC_ASM_H_
 
-#if !defined(__mips__)
-/* <machine/asm.h> causes trouble on mips by including regdefs.h. */
-#include <machine/asm.h>
-#endif
-
 #include <asm/unistd.h> /* For system call numbers. */
 #define MAX_ERRNO 4095  /* For recognizing system call error returns. */
 
-/* TODO: add ENTRY_PRIVATE. */
-/* TODO: add ASM_ALIAS macro. */
+#define __bionic_asm_custom_entry(f)
+#define __bionic_asm_custom_end(f)
+#define __bionic_asm_function_type @function
+
+#include <machine/asm.h>
+
+#define ENTRY(f) \
+    .text; \
+    .globl f; \
+    _ALIGN_TEXT; \
+    .type f, __bionic_asm_function_type; \
+    f: \
+    __bionic_asm_custom_entry(f); \
+    .cfi_startproc \
+
+#define END(f) \
+    .cfi_endproc; \
+    .size f, .-f; \
+    __bionic_asm_custom_end(f) \
+
+/* Like ENTRY, but with hidden visibility. */
+#define ENTRY_PRIVATE(f) \
+    ENTRY(f); \
+    .hidden f \
 
 #endif /* _PRIVATE_BIONIC_ASM_H_ */
diff --git a/libc/private/bionic_auxv.h b/libc/private/bionic_auxv.h
index 69c5341..53fcc49 100644
--- a/libc/private/bionic_auxv.h
+++ b/libc/private/bionic_auxv.h
@@ -29,11 +29,12 @@
 #define _PRIVATE_BIONIC_AUXV_H_
 
 #include <elf.h>
+#include <link.h>
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
 
-extern Elf_auxv_t* __libc_auxv;
+extern ElfW(auxv_t)* __libc_auxv;
 
 __END_DECLS
 
diff --git a/libc/private/bionic_config.h b/libc/private/bionic_config.h
new file mode 100644
index 0000000..0c9811c
--- /dev/null
+++ b/libc/private/bionic_config.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_CONFIG_H_
+#define _BIONIC_CONFIG_H_
+
+// valloc(3) and pvalloc(3) were removed from POSIX 2004. We do not include them
+// for LP64, but the symbols remain in LP32 for binary compatibility.
+#if !defined(__LP64__)
+#define HAVE_DEPRECATED_MALLOC_FUNCS 1
+#endif
+
+#endif // _BIONIC_CONFIG_H_
diff --git a/libc/private/bionic_futex.h b/libc/private/bionic_futex.h
index bfc3520..bd2bd36 100644
--- a/libc/private/bionic_futex.h
+++ b/libc/private/bionic_futex.h
@@ -28,34 +28,43 @@
 #ifndef _BIONIC_FUTEX_H
 #define _BIONIC_FUTEX_H
 
+#include <errno.h>
 #include <linux/futex.h>
+#include <stdbool.h>
+#include <stddef.h>
 #include <sys/cdefs.h>
+#include <sys/syscall.h>
 
 __BEGIN_DECLS
 
-extern int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout);
-extern int __futex_wake(volatile void *ftx, int count);
+struct timespec;
 
-extern int __futex_syscall3(volatile void *ftx, int op, int val);
-extern int __futex_syscall4(volatile void *ftx, int op, int val, const struct timespec *timeout);
+static inline __always_inline int __futex(volatile void* ftx, int op, int value, const struct timespec* timeout) {
+  // Our generated syscall assembler sets errno, but our callers (pthread functions) don't want to.
+  int saved_errno = errno;
+  int result = syscall(__NR_futex, ftx, op, value, timeout);
+  if (__predict_false(result == -1)) {
+    result = -errno;
+    errno = saved_errno;
+  }
+  return result;
+}
 
-#ifndef FUTEX_PRIVATE_FLAG
-#define FUTEX_PRIVATE_FLAG  128
-#endif
+static inline int __futex_wake(volatile void* ftx, int count) {
+  return __futex(ftx, FUTEX_WAKE, count, NULL);
+}
 
-#ifndef FUTEX_WAIT_PRIVATE
-#define FUTEX_WAIT_PRIVATE  (FUTEX_WAIT|FUTEX_PRIVATE_FLAG)
-#endif
+static inline int __futex_wake_ex(volatile void* ftx, bool shared, int count) {
+  return __futex(ftx, shared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, count, NULL);
+}
 
-#ifndef FUTEX_WAKE_PRIVATE
-#define FUTEX_WAKE_PRIVATE  (FUTEX_WAKE|FUTEX_PRIVATE_FLAG)
-#endif
+static inline int __futex_wait(volatile void* ftx, int value, const struct timespec* timeout) {
+  return __futex(ftx, FUTEX_WAIT, value, timeout);
+}
 
-/* Like __futex_wait/wake, but take an additional 'pshared' argument.
- * when non-0, this will use normal futexes. Otherwise, private futexes.
- */
-extern int __futex_wake_ex(volatile void *ftx, int pshared, int val);
-extern int __futex_wait_ex(volatile void *ftx, int pshared, int val, const struct timespec *timeout);
+static inline int __futex_wait_ex(volatile void* ftx, bool shared, int value, const struct timespec* timeout) {
+  return __futex(ftx, shared ? FUTEX_WAIT : FUTEX_WAIT_PRIVATE, value, timeout);
+}
 
 __END_DECLS
 
diff --git a/libc/private/bionic_macros.h b/libc/private/bionic_macros.h
new file mode 100644
index 0000000..61794bd
--- /dev/null
+++ b/libc/private/bionic_macros.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_MACROS_H_
+#define _BIONIC_MACROS_H_
+
+// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions.
+// It goes in the private: declarations in a class.
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+  TypeName(const TypeName&);               \
+  void operator=(const TypeName&)
+
+// A macro to disallow all the implicit constructors, namely the
+// default constructor, copy constructor and operator= functions.
+//
+// This should be used in the private: declarations for a class
+// that wants to prevent anyone from instantiating it. This is
+// especially useful for classes containing only static methods.
+#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
+  TypeName();                                    \
+  DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+#define BIONIC_ALIGN(value, alignment) \
+  (((value) + (alignment) - 1) & ~((alignment) - 1))
+
+#define BIONIC_ROUND_UP_POWER_OF_2(value) \
+  (sizeof(value) == 8) \
+    ? (1UL << (64 - __builtin_clzl(static_cast<unsigned long>(value)))) \
+    : (1UL << (32 - __builtin_clz(static_cast<unsigned int>(value))))
+
+#endif // _BIONIC_MACROS_H_
diff --git a/libc/private/bionic_mbstate.h b/libc/private/bionic_mbstate.h
new file mode 100644
index 0000000..018b47c
--- /dev/null
+++ b/libc/private/bionic_mbstate.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _BIONIC_MBSTATE_H
+#define _BIONIC_MBSTATE_H
+
+#include <wchar.h>
+
+__BEGIN_DECLS
+
+/*
+ * These return values are specified by POSIX for multibyte conversion
+ * functions.
+ */
+#define __MB_ERR_ILLEGAL_SEQUENCE static_cast<size_t>(-1)
+#define __MB_ERR_INCOMPLETE_SEQUENCE static_cast<size_t>(-2)
+
+#define __MB_IS_ERR(rv) (rv == __MB_ERR_ILLEGAL_SEQUENCE || \
+                         rv == __MB_ERR_INCOMPLETE_SEQUENCE)
+
+size_t mbstate_bytes_so_far(const mbstate_t* ps);
+void mbstate_set_byte(mbstate_t* ps, int i, char byte);
+uint8_t mbstate_get_byte(const mbstate_t* ps, int n);
+size_t reset_and_return_illegal(int _errno, mbstate_t* ps);
+size_t reset_and_return(int _return, mbstate_t* ps);
+
+__END_DECLS
+
+#endif // _BIONIC_MBSTATE_H
diff --git a/libc/private/bionic_name_mem.h b/libc/private/bionic_name_mem.h
deleted file mode 100644
index 9f6163d..0000000
--- a/libc/private/bionic_name_mem.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#ifndef _BIONIC_NAME_MEM_H
-#define _BIONIC_NAME_MEM_H
-
-#include <sys/cdefs.h>
-#include <stddef.h>
-
-__BEGIN_DECLS
-
-int __bionic_name_mem(void *addr, size_t len, const char *name);
-
-__END_DECLS
-
-#endif
diff --git a/libc/private/bionic_prctl.h b/libc/private/bionic_prctl.h
new file mode 100644
index 0000000..103cccb
--- /dev/null
+++ b/libc/private/bionic_prctl.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BIONIC_PRCTL_H
+#define BIONIC_PRCTL_H
+
+#include <sys/prctl.h>
+
+// This is only supported by Android kernels, so it's not in the uapi headers.
+#define PR_SET_VMA   0x53564d41
+#define PR_SET_VMA_ANON_NAME    0
+
+#endif // BIONIC_PRCTL_H
diff --git a/libc/private/bionic_string_utils.h b/libc/private/bionic_string_utils.h
new file mode 100644
index 0000000..ab0eccf
--- /dev/null
+++ b/libc/private/bionic_string_utils.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_STRING_UTILS_H_
+#define _BIONIC_STRING_UTILS_H_
+
+#include <string.h>
+
+static inline bool ends_with(const char* s1, const char* s2) {
+  size_t s1_length = strlen(s1);
+  size_t s2_length = strlen(s2);
+  if (s2_length > s1_length) {
+    return false;
+  }
+  return memcmp(s1 + (s1_length - s2_length), s2, s2_length) == 0;
+}
+
+#endif // _BIONIC_STRING_UTILS_H_
diff --git a/libc/private/bionic_time.h b/libc/private/bionic_time.h
index 7c80f59..030dcfd 100644
--- a/libc/private/bionic_time.h
+++ b/libc/private/bionic_time.h
@@ -33,31 +33,8 @@
 
 __BEGIN_DECLS
 
-#ifndef _BIONIC_STRFTIME_TZ_DECLARED
-#define _BIONIC_STRFTIME_TZ_DECLARED
-
-struct strftime_locale {
-    const char *  mon[12];
-    const char *  month[12];
-    const char *  standalone_month[12];
-    const char *  wday[7];
-    const char *  weekday[7];
-    const char *  X_fmt;
-    const char *  x_fmt;
-    const char *  c_fmt;
-    const char *  am;
-    const char *  pm;
-    const char *  date_fmt;
-};
-
-/*
- * Note: you should consider these extensions deprecated and use managed code or icu4c instead.
- */
-extern size_t strftime_tz(char* s, size_t max, const char* format, const struct tm* tm, const struct strftime_locale* lc);
-extern time_t mktime_tz(struct tm* const tmp, char const* tz);
-extern void localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz);
-
-#endif /* _BIONIC_STRFTIME_TZ_DECLARED */
+// We can't remove this (and this file) until we fix MtpUtils.cpp.
+time_t mktime_tz(struct tm* const, char const*);
 
 __END_DECLS
 
diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h
index a42a8ab..56a61be 100644
--- a/libc/private/bionic_tls.h
+++ b/libc/private/bionic_tls.h
@@ -31,6 +31,7 @@
 
 #include <sys/cdefs.h>
 #include <sys/limits.h>
+#include "bionic_macros.h"
 #include "__get_tls.h"
 
 __BEGIN_DECLS
@@ -46,32 +47,27 @@
  ** pre-allocated slot directly for performance reason).
  **/
 
-/* Well-known TLS slots. What data goes in which slot is arbitrary unless otherwise noted. */
+// Well-known TLS slots. What data goes in which slot is arbitrary unless otherwise noted.
 enum {
-  TLS_SLOT_SELF = 0, /* The kernel requires this specific slot for x86. */
+  TLS_SLOT_SELF = 0, // The kernel requires this specific slot for x86.
   TLS_SLOT_THREAD_ID,
   TLS_SLOT_ERRNO,
 
-  /* This slot in the child's TLS is used to synchronize the parent and child
-   * during thread initialization. The child finishes with this mutex before
-   * running any code that can set errno, so we can reuse the errno slot. */
-  TLS_SLOT_START_MUTEX = TLS_SLOT_ERRNO,
-
-  /* These two aren't used by bionic itself, but allow the graphics code to
-   * access TLS directly rather than using the pthread API. */
+  // These two aren't used by bionic itself, but allow the graphics code to
+  // access TLS directly rather than using the pthread API.
   TLS_SLOT_OPENGL_API = 3,
   TLS_SLOT_OPENGL = 4,
 
-  /* This slot is only used to pass information from the dynamic linker to
-   * libc.so when the C library is loaded in to memory. The C runtime init
-   * function will then clear it. Since its use is extremely temporary,
-   * we reuse an existing location that isn't needed during libc startup. */
+  // This slot is only used to pass information from the dynamic linker to
+  // libc.so when the C library is loaded in to memory. The C runtime init
+  // function will then clear it. Since its use is extremely temporary,
+  // we reuse an existing location that isn't needed during libc startup.
   TLS_SLOT_BIONIC_PREINIT = TLS_SLOT_OPENGL_API,
 
-  TLS_SLOT_STACK_GUARD = 5, /* GCC requires this specific slot for x86. */
+  TLS_SLOT_STACK_GUARD = 5, // GCC requires this specific slot for x86.
   TLS_SLOT_DLERROR,
 
-  TLS_SLOT_FIRST_USER_SLOT /* Must come last! */
+  TLS_SLOT_FIRST_USER_SLOT // Must come last!
 };
 
 /*
@@ -80,16 +76,21 @@
  * pthread_key_create; grep for GLOBAL_INIT_THREAD_LOCAL_BUFFER to find those. We need to manually
  * maintain that second number, but pthread_test will fail if we forget.
  */
-#define GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT 4
+#define GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT 5
 
-#define BIONIC_ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
+#if defined(USE_JEMALLOC)
+/* jemalloc uses 5 keys for itself. */
+#define BIONIC_TLS_RESERVED_SLOTS (GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT + 5)
+#else
+#define BIONIC_TLS_RESERVED_SLOTS GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT
+#endif
 
 /*
  * Maximum number of elements in the TLS array.
  * This includes space for pthread keys and our own internal slots.
  * We need to round up to maintain stack alignment.
  */
-#define BIONIC_TLS_SLOTS BIONIC_ALIGN(PTHREAD_KEYS_MAX + TLS_SLOT_FIRST_USER_SLOT + GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT, 4)
+#define BIONIC_TLS_SLOTS BIONIC_ALIGN(PTHREAD_KEYS_MAX + TLS_SLOT_FIRST_USER_SLOT + BIONIC_TLS_RESERVED_SLOTS, 4)
 
 __END_DECLS
 
diff --git a/libc/private/libc_events.h b/libc/private/libc_events.h
index 5d20f4b..f2b973d 100644
--- a/libc/private/libc_events.h
+++ b/libc/private/libc_events.h
@@ -40,6 +40,8 @@
 #define BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW  80120
 #define BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW   80125
 #define BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW   80130
+#define BIONIC_EVENT_STPCPY_BUFFER_OVERFLOW   80135
+#define BIONIC_EVENT_STPNCPY_BUFFER_OVERFLOW  80140
 
 #define BIONIC_EVENT_RESOLVER_OLD_RESPONSE    80300
 #define BIONIC_EVENT_RESOLVER_WRONG_SERVER    80305
diff --git a/libc/private/libc_logging.h b/libc/private/libc_logging.h
index 1cdcb6e..da2192b 100644
--- a/libc/private/libc_logging.h
+++ b/libc/private/libc_logging.h
@@ -52,19 +52,28 @@
   ANDROID_LOG_SILENT,     /* only for SetMinPriority(); must be last */
 };
 
+enum {
+  LOG_ID_MIN = 0,
+
+  LOG_ID_MAIN = 0,
+  LOG_ID_RADIO = 1,
+  LOG_ID_EVENTS = 2,
+  LOG_ID_SYSTEM = 3,
+  LOG_ID_CRASH = 4,
+
+  LOG_ID_MAX
+};
+
 struct abort_msg_t {
   size_t size;
   char msg[0];
 };
 
-__LIBC_HIDDEN__ void __libc_set_abort_message(const char* msg);
-
 //
 // Formats a message to the log (priority 'fatal'), then aborts.
 //
 
-__LIBC_HIDDEN__ __noreturn void __libc_fatal(const char* format, ...)
-    __printflike(1, 2);
+__LIBC_HIDDEN__ __noreturn void __libc_fatal(const char* format, ...) __printflike(1, 2);
 
 //
 // Formats a message to the log (priority 'fatal'), but doesn't abort.
@@ -77,7 +86,7 @@
 
 //
 // Formatting routines for the C library's internal debugging.
-// Unlike the usual alternatives, these don't allocate.
+// Unlike the usual alternatives, these don't allocate, and they don't drag in all of stdio.
 //
 
 __LIBC_HIDDEN__ int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...)
diff --git a/libc/private/nsswitch.h b/libc/private/nsswitch.h
deleted file mode 100644
index e03844b..0000000
--- a/libc/private/nsswitch.h
+++ /dev/null
@@ -1,237 +0,0 @@
-/*	$NetBSD: nsswitch.h,v 1.18 2005/11/29 03:12:58 christos Exp $	*/
-
-/*-
- * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Luke Mewburn.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _NSSWITCH_H
-#define _NSSWITCH_H	1
-
-#include <sys/types.h>
-#include <stdarg.h>
-
-#define	NSS_MODULE_INTERFACE_VERSION	0
-
-#ifndef _PATH_NS_CONF
-#define _PATH_NS_CONF	"/etc/nsswitch.conf"
-#endif
-
-#define	NS_CONTINUE	0
-#define	NS_RETURN	1
-
-/*
- * Layout of:
- *	uint32_t ns_src.flags
- */
-	/* nsswitch.conf status codes and nsdispatch(3) return values */
-#define	NS_SUCCESS	(1<<0)		/* entry was found */
-#define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
-#define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
-#define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retrys */
-#define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
-
-	/* internal nsdispatch(3) flags; not settable in nsswitch.conf(5)  */
-#define	NS_FORCEALL	(1<<8)		/* force all methods to be invoked; */
-
-/*
- * Currently implemented sources.
- */
-#define NSSRC_FILES	"files"		/* local files */
-#define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
-#define	NSSRC_NIS	"nis"		/* YP/NIS */
-#define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
-
-/*
- * Currently implemented databases.
- */
-#define NSDB_HOSTS		"hosts"
-#define NSDB_GROUP		"group"
-#define NSDB_GROUP_COMPAT	"group_compat"
-#define NSDB_NETGROUP		"netgroup"
-#define NSDB_NETWORKS		"networks"
-#define NSDB_PASSWD		"passwd"
-#define NSDB_PASSWD_COMPAT	"passwd_compat"
-#define NSDB_SHELLS		"shells"
-
-/*
- * Suggested databases to implement.
- */
-#define NSDB_ALIASES		"aliases"
-#define NSDB_AUTH		"auth"
-#define NSDB_AUTOMOUNT		"automount"
-#define NSDB_BOOTPARAMS		"bootparams"
-#define NSDB_ETHERS		"ethers"
-#define NSDB_EXPORTS		"exports"
-#define NSDB_NETMASKS		"netmasks"
-#define NSDB_PHONES		"phones"
-#define NSDB_PRINTCAP		"printcap"
-#define NSDB_PROTOCOLS		"protocols"
-#define NSDB_REMOTE		"remote"
-#define NSDB_RPC		"rpc"
-#define NSDB_SENDMAILVARS	"sendmailvars"
-#define NSDB_SERVICES		"services"
-#define NSDB_TERMCAP		"termcap"
-#define NSDB_TTYS		"ttys"
-
-/*
- * ns_dtab `callback' function signature.
- */
-typedef	int (*nss_method)(void *, void *, va_list);
-
-/*
- * ns_dtab - `nsswitch dispatch table'
- * Contains an entry for each source and the appropriate function to call.
- */
-typedef struct {
-	const char	 *src;
-	nss_method	 callback;
-	void		 *cb_data;
-} ns_dtab;
-
-/*
- * Macros to help build an ns_dtab[]
- */
-#define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	__UNCONST(C) },
-#define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	__UNCONST(C) },
-
-#ifdef HESIOD
-#   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	__UNCONST(C) },
-#else
-#   define NS_DNS_CB(F,C)
-#endif
-
-#ifdef YP
-#   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	__UNCONST(C) },
-#else
-#   define NS_NIS_CB(F,C)
-#endif
-
-/*
- * ns_src - `nsswitch source'
- * Used by the nsparser routines to store a mapping between a source
- * and its dispatch control flags for a given database.
- */
-typedef struct {
-	const char	*name;
-	uint32_t	 flags;
-} ns_src;
-
-
-#if 0
-/*
- * Default sourcelists (if nsswitch.conf is missing, corrupt,
- * or the requested database doesn't have an entry)
- */
-extern const ns_src __nsdefaultsrc[];
-extern const ns_src __nsdefaultcompat[];
-extern const ns_src __nsdefaultcompat_forceall[];
-extern const ns_src __nsdefaultfiles[];
-extern const ns_src __nsdefaultfiles_forceall[];
-extern const ns_src __nsdefaultnis[];
-extern const ns_src __nsdefaultnis_forceall[];
-#endif
-
-/*
- * ns_mtab - `nsswitch method table'
- * An nsswitch module provides a mapping from (database name, method name)
- * tuples to the nss_method and associated callback data.  Effectively,
- * ns_dtab, but used for dynamically loaded modules.
- */
-typedef struct {
-	const char	*database;
-	const char	*name;
-	nss_method	 method;
-	void		*mdata;
-} ns_mtab;
-
-/*
- * nss_module_register_fn - module registration function
- *	called at module load
- * nss_module_unregister_fn - module un-registration function
- *	called at module unload
- */
-typedef	void (*nss_module_unregister_fn)(ns_mtab *, u_int);
-typedef	ns_mtab *(*nss_module_register_fn)(const char *, u_int *,
-					   nss_module_unregister_fn *);
-
-#ifdef _NS_PRIVATE
-
-/*
- * Private data structures for back-end nsswitch implementation.
- */
-
-/*
- * ns_dbt - `nsswitch database thang'
- * For each database in /etc/nsswitch.conf there is a ns_dbt, with its
- * name and a list of ns_src's containing the source information.
- */
-typedef struct {
-	const char	*name;		/* name of database */
-	ns_src		*srclist;	/* list of sources */
-	u_int		 srclistsize;	/* size of srclist */
-} ns_dbt;
-
-/*
- * ns_mod - `nsswitch module'
- */
-typedef struct {
-	const char	*name;		/* module name */
-	void		*handle;	/* handle from dlopen() */
-	ns_mtab		*mtab;		/* method table */
-	u_int		 mtabsize;	/* size of mtab */
-					/* called to unload module */
-	nss_module_unregister_fn unregister;
-} ns_mod;
-
-#endif /* _NS_PRIVATE */
-
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-int	nsdispatch(void *, const ns_dtab [], const char *,
-			const char *, const ns_src [], ...);
-
-#ifdef _NS_PRIVATE
-int		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
-void		 _nsdbtdump(const ns_dbt *);
-int		 _nsdbtput(const ns_dbt *);
-void		 _nsyyerror(const char *);
-int		 _nsyylex(void);
-#endif /* _NS_PRIVATE */
-
-__END_DECLS
-
-#endif /* !_NSSWITCH_H */
diff --git a/libc/private/resolv_cache.h b/libc/private/resolv_cache.h
deleted file mode 100644
index 68a1180..0000000
--- a/libc/private/resolv_cache.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#ifndef _RESOLV_CACHE_H_
-#define _RESOLV_CACHE_H_
-
-#include <stddef.h>
-#include <sys/cdefs.h>
-
-struct __res_state;
-struct resolv_cache;  /* forward */
-
-/* gets the cache for an interface. Set ifname argument to NULL or
- * empty buffer ('\0') to get cache for default interface.
- * returned cache might be NULL*/
-__LIBC_HIDDEN__
-extern struct resolv_cache*  __get_res_cache(const char* ifname);
-
-/* this gets called everytime we detect some changes in the DNS configuration
- * and will flush the cache */
-__LIBC_HIDDEN__
-extern void  _resolv_cache_reset( unsigned  generation );
-
-/* Gets the address of the n:th name server for the default interface
- * Return length of address on success else 0.
- * Note: The first name server is at n = 1 */
-__LIBC_HIDDEN__
-extern int _resolv_cache_get_nameserver(int n, char* addr, int addrLen);
-
-/* Gets the address of the n:th name server for a certain interface
- * Return length of address on success else 0.
- * Note: The first name server is at n = 1 */
-__LIBC_HIDDEN__
-extern int _resolv_cache_get_nameserver_for_iface(const char* ifname, int n,
-        char* addr, int addrLen);
-
-/* Gets addrinfo of the n:th name server associated with an interface.
- * NULL is returned if no address if found.
- * Note: The first name server is at n = 1. */
-__LIBC_HIDDEN__
-extern struct addrinfo* _resolv_cache_get_nameserver_addr_for_iface(const char* ifname, int n);
-
-/* Gets addrinfo of the n:th name server associated with the default interface
- * NULL is returned if no address if found.
- * Note: The first name server is at n = 1. */
-__LIBC_HIDDEN__
-extern struct addrinfo* _resolv_cache_get_nameserver_addr(int n);
-
-/* gets the address associated with the default interface */
-__LIBC_HIDDEN__
-extern struct in_addr* _resolv_get_addr_of_default_iface();
-
-/* gets the address associated with the specified interface */
-__LIBC_HIDDEN__
-extern struct in_addr* _resolv_get_addr_of_iface(const char* ifname);
-
-/* Copy the name of the default interface to the provided buffer.
- * Returns the string length of the default interface,
- * be that less or more than the buffLen, or 0 if nothing had been written */
-__LIBC_HIDDEN__
- extern size_t _resolv_get_default_iface(char* buff, size_t buffLen);
-
-/* sets the name server addresses to the provided res_state structure. The
- * name servers are retrieved from the cache which is associated
- * with the interface to which the res_state structure is associated */
-__LIBC_HIDDEN__
-extern void _resolv_populate_res_for_iface(struct __res_state* statp);
-
-typedef enum {
-    RESOLV_CACHE_UNSUPPORTED,  /* the cache can't handle that kind of queries */
-                               /* or the answer buffer is too small */
-    RESOLV_CACHE_NOTFOUND,     /* the cache doesn't know about this query */
-    RESOLV_CACHE_FOUND         /* the cache found the answer */
-} ResolvCacheStatus;
-
-__LIBC_HIDDEN__
-extern ResolvCacheStatus
-_resolv_cache_lookup( struct resolv_cache*  cache,
-                      const void*           query,
-                      int                   querylen,
-                      void*                 answer,
-                      int                   answersize,
-                      int                  *answerlen );
-
-/* add a (query,answer) to the cache, only call if _resolv_cache_lookup
- * did return RESOLV_CACHE_NOTFOUND
- */
-__LIBC_HIDDEN__
-extern void
-_resolv_cache_add( struct resolv_cache*  cache,
-                   const void*           query,
-                   int                   querylen,
-                   const void*           answer,
-                   int                   answerlen );
-
-/* Notify the cache a request failed */
-__LIBC_HIDDEN__
-extern void
-_resolv_cache_query_failed( struct resolv_cache* cache,
-                   const void* query,
-                   int         querylen);
-
-#endif /* _RESOLV_CACHE_H_ */
diff --git a/libc/private/resolv_iface.h b/libc/private/resolv_iface.h
deleted file mode 100644
index 5d24124..0000000
--- a/libc/private/resolv_iface.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#ifndef _RESOLV_IFACE_H
-#define _RESOLV_IFACE_H
-
-/* This header contains declarations related to per-interface DNS
- * server selection. They are used by system/netd/ and should not be
- * exposed by the C library's public NDK headers.
- *
- * NOTE: <resolv.h> contains the same declarations, this will be removed
- *        when we change system/netd to use this header instead.
- */
-#include <sys/cdefs.h>
-#include <netinet/in.h>
-
-__BEGIN_DECLS
-
-/* Use a guard macro until we remove the same definitions from <resolv.h> */
-#ifndef _BIONIC_RESOLV_IFACE_FUNCTIONS_DECLARED
-#define _BIONIC_RESOLV_IFACE_FUNCTIONS_DECLARED
-
-/* Set name of default interface */
-extern void _resolv_set_default_iface(const char* ifname);
-
-/* set name servers for an interface */
-extern void _resolv_set_nameservers_for_iface(const char* ifname, const char** servers, int numservers,
-        const char *domains);
-
-/* tell resolver of the address of an interface */
-extern void _resolv_set_addr_of_iface(const char* ifname, struct in_addr* addr);
-
-/* flush the cache associated with the default interface */
-extern void _resolv_flush_cache_for_default_iface();
-
-/* flush the cache associated with a certain interface */
-extern void _resolv_flush_cache_for_iface(const char* ifname);
-
-/* set a pid to use the name servers of the specified interface */
-extern void _resolv_set_iface_for_pid(const char* ifname, int pid);
-
-/* clear pid from being associated with an interface */
-extern void _resolv_clear_iface_for_pid(int pid);
-
-/* clear the entire mapping of pids to interfaces. */
-extern void _resolv_clear_iface_pid_mapping();
-
-/** Gets the name of the interface to which the pid is attached.
- *  On error, -1 is returned.
- *  If no interface is found, 0 is returned and buff is set to empty ('\0').
- *  If an interface is found, the name is copied to buff and the length of the name is returned.
- *  Arguments:   pid The pid to find an interface for
- *               buff A buffer to copy the result to
- *               buffLen Length of buff. An interface is at most IF_NAMESIZE in length */
-extern int _resolv_get_pids_associated_interface(int pid, char* buff, int buffLen);
-
-
-/** set a uid range to use the name servers of the specified interface */
-extern int _resolv_set_iface_for_uid_range(const char* ifname, int uid_start, int uid_end);
-
-/** Remove a mapping added by _resolv_set_iface_for_uid_range.
- *  If no such rule exists -1 is returned. */
-extern int _resolv_clear_iface_for_uid_range(const char* ifname, int uid_start, int uid_end);
-
-/* clear the entire mapping of uid ranges to interfaces. */
-extern void _resolv_clear_iface_uid_range_mapping();
-
-/** Gets the name of the interface to which the uid is attached.
- *  On error, -1 is returned.
- *  If no interface is found, 0 is returned and buff is set to empty ('\0').
- *  If an interface is found, the name is copied to buff and the length of the name is returned.
- *  If there are multiple rules covering uid the most recently added rule will be returned.
- *  Arguments:   uid The uid to find an interface for
- *               buff A buffer to copy the result to
- *               buffLen Length of buff. An interface is at most IF_NAMESIZE in length */
-extern int _resolv_get_uids_associated_interface(int uid, char* buff, int buffLen);
-
-#endif /* _BIONIC_RESOLV_IFACE_FUNCTIONS_DECLARED */
-
-__END_DECLS
-
-#endif /* _RESOLV_IFACE_H */
diff --git a/libc/private/resolv_private.h b/libc/private/resolv_private.h
deleted file mode 100644
index c7bcb89..0000000
--- a/libc/private/resolv_private.h
+++ /dev/null
@@ -1,499 +0,0 @@
-/*	$NetBSD: resolv.h,v 1.31 2005/12/26 19:01:47 perry Exp $	*/
-
-/*
- * Copyright (c) 1983, 1987, 1989
- *    The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-/*
- *	@(#)resolv.h	8.1 (Berkeley) 6/2/93
- *	Id: resolv.h,v 1.7.2.11.4.2 2004/06/25 00:41:05 marka Exp
- */
-
-#ifndef _RESOLV_PRIVATE_H_
-#define	_RESOLV_PRIVATE_H_
-
-#include <sys/cdefs.h>
-
-#include <resolv.h>
-#include "resolv_static.h"
-#include <net/if.h>
-
-/*
- * Revision information.  This is the release date in YYYYMMDD format.
- * It can change every day so the right thing to do with it is use it
- * in preprocessor commands such as "#if (__RES > 19931104)".  Do not
- * compare for equality; rather, use it to determine whether your resolver
- * is new enough to contain a certain feature.
- */
-
-#define	__RES	20030124
-
-/*
- * This used to be defined in res_query.c, now it's in herror.c.
- * [XXX no it's not.  It's in irs/irs_data.c]
- * It was
- * never extern'd by any *.h file before it was placed here.  For thread
- * aware programs, the last h_errno value set is stored in res->h_errno.
- *
- * XXX:	There doesn't seem to be a good reason for exposing RES_SET_H_ERRNO
- *	(and __h_errno_set) to the public via <resolv.h>.
- * XXX:	__h_errno_set is really part of IRS, not part of the resolver.
- *	If somebody wants to build and use a resolver that doesn't use IRS,
- *	what do they do?  Perhaps something like
- *		#ifdef WANT_IRS
- *		# define RES_SET_H_ERRNO(r,x) __h_errno_set(r,x)
- *		#else
- *		# define RES_SET_H_ERRNO(r,x) (h_errno = (r)->res_h_errno = (x))
- *		#endif
- */
-
-#define RES_SET_H_ERRNO(r,x) (h_errno = (r)->res_h_errno = (x))
-struct __res_state; /* forward */
-
-/*
- * Resolver configuration file.
- * Normally not present, but may contain the address of the
- * initial name server(s) to query and the domain search list.
- */
-
-#ifndef _PATH_RESCONF
-#ifdef ANDROID_CHANGES
-#define _PATH_RESCONF        "/etc/ppp/resolv.conf"
-#else
-#define _PATH_RESCONF        "/etc/resolv.conf"
-#endif
-#endif
-
-typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
-	res_sendhookact;
-
-typedef res_sendhookact (*res_send_qhook)(struct sockaddr * const *,
-					      const u_char **, int *,
-					      u_char *, int, int *);
-
-typedef res_sendhookact (*res_send_rhook)(const struct sockaddr *,
-					      const u_char *, int, u_char *,
-					      int, int *);
-
-struct res_sym {
-	int		number;	   /* Identifying number, like T_MX */
-	const char *	name;	   /* Its symbolic name, like "MX" */
-	const char *	humanname; /* Its fun name, like "mail exchanger" */
-};
-
-/*
- * Global defines and variables for resolver stub.
- */
-#define	MAXNS			3	/* max # name servers we'll track */
-#define	MAXDFLSRCH		3	/* # default domain levels to try */
-#define	MAXDNSRCH		6	/* max # domains in search path */
-#define	LOCALDOMAINPARTS	2	/* min levels in name that is "local" */
-
-#define	RES_TIMEOUT		5	/* min. seconds between retries */
-#define	MAXRESOLVSORT		10	/* number of net to sort on */
-#define	RES_MAXNDOTS		15	/* should reflect bit field size */
-#define	RES_MAXRETRANS		30	/* only for resolv.conf/RES_OPTIONS */
-#define	RES_MAXRETRY		5	/* only for resolv.conf/RES_OPTIONS */
-#define	RES_DFLRETRY		2	/* Default #/tries. */
-#define	RES_MAXTIME		65535	/* Infinity, in milliseconds. */
-
-struct __res_state_ext;
-
-struct __res_state {
-	char	iface[IF_NAMESIZE+1];
-	int	retrans;	 	/* retransmission time interval */
-	int	retry;			/* number of times to retransmit */
-#ifdef sun
-	u_int	options;		/* option flags - see below. */
-#else
-	u_long	options;		/* option flags - see below. */
-#endif
-	int	nscount;		/* number of name servers */
-	struct sockaddr_in
-		nsaddr_list[MAXNS];	/* address of name server */
-#define	nsaddr	nsaddr_list[0]		/* for backward compatibility */
-	u_short	id;			/* current message id */
-	char	*dnsrch[MAXDNSRCH+1];	/* components of domain to search */
-	char	defdname[256];		/* default domain (deprecated) */
-#ifdef sun
-	u_int	pfcode;			/* RES_PRF_ flags - see below. */
-#else
-	u_long	pfcode;			/* RES_PRF_ flags - see below. */
-#endif
-	unsigned ndots:4;		/* threshold for initial abs. query */
-	unsigned nsort:4;		/* number of elements in sort_list[] */
-	char	unused[3];
-	struct {
-		struct in_addr	addr;
-		uint32_t	mask;
-	} sort_list[MAXRESOLVSORT];
-#ifdef __OLD_RES_STATE
-	char lookups[4];
-#else
-	res_send_qhook qhook;		/* query hook */
-	res_send_rhook rhook;		/* response hook */
-	int	res_h_errno;		/* last one set for this context */
-	int _mark;          /* If non-0 SET_MARK to _mark on all request sockets */
-	int	_vcsock;		/* PRIVATE: for res_send VC i/o */
-	u_int	_flags;			/* PRIVATE: see below */
-	u_int	_pad;			/* make _u 64 bit aligned */
-	union {
-		/* On an 32-bit arch this means 512b total. */
-		char	pad[72 - 4*sizeof (int) - 2*sizeof (void *)];
-		struct {
-			uint16_t		nscount;
-			uint16_t		nstimes[MAXNS];	/* ms. */
-			int			nssocks[MAXNS];
-			struct __res_state_ext *ext;	/* extention for IPv6 */
-		} _ext;
-	} _u;
-#endif
-        struct res_static   rstatic[1];
-};
-
-typedef struct __res_state *res_state;
-
-union res_sockaddr_union {
-	struct sockaddr_in	sin;
-#ifdef IN6ADDR_ANY_INIT
-	struct sockaddr_in6	sin6;
-#endif
-#ifdef ISC_ALIGN64
-	int64_t			__align64;	/* 64bit alignment */
-#else
-	int32_t			__align32;	/* 32bit alignment */
-#endif
-	char			__space[128];   /* max size */
-};
-
-/*
- * Resolver flags (used to be discrete per-module statics ints).
- */
-#define	RES_F_VC	0x00000001	/* socket is TCP */
-#define	RES_F_CONN	0x00000002	/* socket is connected */
-#define	RES_F_EDNS0ERR	0x00000004	/* EDNS0 caused errors */
-#define	RES_F__UNUSED	0x00000008	/* (unused) */
-#define	RES_F_LASTMASK	0x000000F0	/* ordinal server of last res_nsend */
-#define	RES_F_LASTSHIFT	4		/* bit position of LASTMASK "flag" */
-#define	RES_GETLAST(res) (((res)._flags & RES_F_LASTMASK) >> RES_F_LASTSHIFT)
-
-/* res_findzonecut2() options */
-#define	RES_EXHAUSTIVE	0x00000001	/* always do all queries */
-#define	RES_IPV4ONLY	0x00000002	/* IPv4 only */
-#define	RES_IPV6ONLY	0x00000004	/* IPv6 only */
-
-/*
- * Resolver options (keep these in synch with res_debug.c, please)
- */
-#define RES_INIT	0x00000001	/* address initialized */
-#define RES_DEBUG	0x00000002	/* print debug messages */
-#define RES_AAONLY	0x00000004	/* authoritative answers only (!IMPL)*/
-#define RES_USEVC	0x00000008	/* use virtual circuit */
-#define RES_PRIMARY	0x00000010	/* query primary server only (!IMPL) */
-#define RES_IGNTC	0x00000020	/* ignore trucation errors */
-#define RES_RECURSE	0x00000040	/* recursion desired */
-#define RES_DEFNAMES	0x00000080	/* use default domain name */
-#define RES_STAYOPEN	0x00000100	/* Keep TCP socket open */
-#define RES_DNSRCH	0x00000200	/* search up local domain tree */
-#define	RES_INSECURE1	0x00000400	/* type 1 security disabled */
-#define	RES_INSECURE2	0x00000800	/* type 2 security disabled */
-#define	RES_NOALIASES	0x00001000	/* shuts off HOSTALIASES feature */
-#define	RES_USE_INET6	0x00002000	/* use/map IPv6 in gethostbyname() */
-#define RES_ROTATE	0x00004000	/* rotate ns list after each query */
-#define	RES_NOCHECKNAME	0x00008000	/* do not check names for sanity. */
-#define	RES_KEEPTSIG	0x00010000	/* do not strip TSIG records */
-#define	RES_BLAST	0x00020000	/* blast all recursive servers */
-#define RES_NOTLDQUERY	0x00100000	/* don't unqualified name as a tld */
-#define RES_USE_DNSSEC	0x00200000	/* use DNSSEC using OK bit in OPT */
-/* #define RES_DEBUG2	0x00400000 */	/* nslookup internal */
-/* KAME extensions: use higher bit to avoid conflict with ISC use */
-#define RES_USE_DNAME	0x10000000	/* use DNAME */
-#define RES_USE_EDNS0	0x40000000	/* use EDNS0 if configured */
-#define RES_NO_NIBBLE2	0x80000000	/* disable alternate nibble lookup */
-
-#define RES_DEFAULT	(RES_RECURSE | RES_DEFNAMES | \
-			 RES_DNSRCH | RES_NO_NIBBLE2)
-
-/*
- * Resolver "pfcode" values.  Used by dig.
- */
-#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
-#define RES_PRF_TRUNC	0x00008000
-/*			0x00010000	*/
-
-/* Things involving an internal (static) resolver context. */
-__BEGIN_DECLS
-extern struct __res_state *__res_get_state(void);
-extern void __res_put_state(struct __res_state *);
-
-#ifndef ANDROID_CHANGES
-/*
- * Source and Binary compatibility; _res will not work properly
- * with multi-threaded programs.
- */
-extern struct __res_state *__res_state(void);
-#define _res (*__res_state())
-#endif
-
-__END_DECLS
-
-#ifndef __BIND_NOSTATIC
-#define fp_nquery		__fp_nquery
-#define fp_query		__fp_query
-#define hostalias		__hostalias
-#define p_query			__p_query
-#define res_close		__res_close
-#define res_opt			__res_opt
-#define res_isourserver		__res_isourserver
-#define	res_querydomain		__res_querydomain
-#define res_send		__res_send
-#define res_sendsigned		__res_sendsigned
-
-#ifdef BIND_RES_POSIX3
-#define	dn_expand	__dn_expand
-#define	res_init	__res_init
-#define	res_query	__res_query
-#define	res_search	__res_search
-#define	res_mkquery	__res_mkquery
-#endif
-
-__BEGIN_DECLS
-void		fp_nquery(const u_char *, int, FILE *);
-void		fp_query(const u_char *, FILE *);
-const char *	hostalias(const char *);
-void		p_query(const u_char *);
-void		res_close(void);
-int		res_init(void);
-int		res_opt(int, u_char *, int, int);
-int		res_isourserver(const struct sockaddr_in *);
-int		res_mkquery(int, const char *, int, int, const u_char *, int, const u_char *, u_char *, int);
-int		res_query(const char *, int, int, u_char *, int);
-int		res_querydomain(const char *, const char *, int, int, u_char *, int);
-int		res_search(const char *, int, int, u_char *, int);
-int		res_send(const u_char *, int, u_char *, int);
-int		res_sendsigned(const u_char *, int, ns_tsig_key *, u_char *, int);
-__END_DECLS
-#endif
-
-#if !defined(SHARED_LIBBIND) || defined(LIB)
-/*
- * If libbind is a shared object (well, DLL anyway)
- * these externs break the linker when resolv.h is
- * included by a lib client (like named)
- * Make them go away if a client is including this
- *
- */
-extern const struct res_sym __p_key_syms[];
-extern const struct res_sym __p_cert_syms[];
-extern const struct res_sym __p_class_syms[];
-extern const struct res_sym __p_type_syms[];
-extern const struct res_sym __p_rcode_syms[];
-#endif /* SHARED_LIBBIND */
-
-#ifndef ANDROID_CHANGES
-#define dn_comp			__dn_comp
-#endif
-#define dn_count_labels		__dn_count_labels
-#define dn_skipname		__dn_skipname
-#define fp_resstat		__fp_resstat
-#define loc_aton		__loc_aton
-#define loc_ntoa		__loc_ntoa
-#define p_cdname		__p_cdname
-#define p_cdnname		__p_cdnname
-#define p_class			__p_class
-#define p_fqname		__p_fqname
-#define p_fqnname		__p_fqnname
-#define p_option		__p_option
-#define p_secstodate		__p_secstodate
-#define p_section		__p_section
-#define p_time			__p_time
-#define p_type			__p_type
-#define p_rcode			__p_rcode
-#define p_sockun		__p_sockun
-#define putlong			__putlong
-#define putshort		__putshort
-#define res_dnok		__res_dnok
-#define res_findzonecut		__res_findzonecut
-#define res_findzonecut2	__res_findzonecut2
-#define res_hnok		__res_hnok
-#define res_hostalias		__res_hostalias
-#define res_mailok		__res_mailok
-#define res_nameinquery		__res_nameinquery
-#define res_nclose		__res_nclose
-#define res_ninit		__res_ninit
-#define res_nmkquery		__res_nmkquery
-#define res_pquery		__res_pquery
-#define res_nquery		__res_nquery
-#define res_nquerydomain	__res_nquerydomain
-#define res_nsearch		__res_nsearch
-#define res_nsend		__res_nsend
-#define res_nsendsigned		__res_nsendsigned
-#define res_nisourserver	__res_nisourserver
-#define res_ownok		__res_ownok
-#define res_queriesmatch	__res_queriesmatch
-#define res_randomid		__res_randomid
-#define sym_ntop		__sym_ntop
-#define sym_ntos		__sym_ntos
-#define sym_ston		__sym_ston
-#define res_nopt		__res_nopt
-#define res_ndestroy		__res_ndestroy
-#define	res_nametoclass		__res_nametoclass
-#define	res_nametotype		__res_nametotype
-#define	res_setservers		__res_setservers
-#define	res_getservers		__res_getservers
-#define	res_buildprotolist	__res_buildprotolist
-#define	res_destroyprotolist	__res_destroyprotolist
-#define	res_destroyservicelist	__res_destroyservicelist
-#define	res_get_nibblesuffix	__res_get_nibblesuffix
-#define	res_get_nibblesuffix2	__res_get_nibblesuffix2
-#define	res_ourserver_p		__res_ourserver_p
-#define	res_protocolname	__res_protocolname
-#define	res_protocolnumber	__res_protocolnumber
-#define	res_send_setqhook	__res_send_setqhook
-#define	res_send_setrhook	__res_send_setrhook
-#define	res_servicename		__res_servicename
-#define	res_servicenumber	__res_servicenumber
-__BEGIN_DECLS
-int		res_hnok(const char *);
-int		res_ownok(const char *);
-int		res_mailok(const char *);
-int		res_dnok(const char *);
-int		sym_ston(const struct res_sym *, const char *, int *);
-const char *	sym_ntos(const struct res_sym *, int, int *);
-const char *	sym_ntop(const struct res_sym *, int, int *);
-#ifndef ANDROID_CHANGES
-int		b64_ntop(u_char const *, size_t, char *, size_t);
-int		b64_pton(char const *, u_char *, size_t);
-#endif
-int		loc_aton(const char *, u_char *);
-const char *	loc_ntoa(const u_char *, char *);
-int		dn_skipname(const u_char *, const u_char *);
-void		putlong(uint32_t, u_char *);
-void		putshort(uint16_t, u_char *);
-#ifndef __ultrix__
-uint16_t	_getshort(const u_char *);
-uint32_t	_getlong(const u_char *);
-#endif
-const char *	p_class(int);
-const char *	p_time(uint32_t);
-const char *	p_type(int);
-const char *	p_rcode(int);
-const char *	p_sockun(union res_sockaddr_union, char *, size_t);
-const u_char *	p_cdnname(const u_char *, const u_char *, int, FILE *);
-const u_char *	p_cdname(const u_char *, const u_char *, FILE *);
-const u_char *	p_fqnname(const u_char *, const u_char *,
-			       int, char *, int);
-const u_char *	p_fqname(const u_char *, const u_char *, FILE *);
-const char *	p_option(u_long);
-char *		p_secstodate(u_long);
-int		dn_count_labels(const char *);
-u_int		res_randomid(void);
-int		res_nameinquery(const char *, int, int, const u_char *,
-				     const u_char *);
-int		res_queriesmatch(const u_char *, const u_char *,
-				      const u_char *, const u_char *);
-const char *	p_section(int, int);
-/* Things involving a resolver context. */
-int		res_ninit(res_state);
-int		res_nisourserver(const res_state, const struct sockaddr_in *);
-void		fp_resstat(const res_state, FILE *);
-void		res_pquery(const res_state, const u_char *, int, FILE *);
-const char *	res_hostalias(const res_state, const char *, char *, size_t);
-int		res_nquery(res_state, const char *, int, int, u_char *, int);
-int		res_nsearch(res_state, const char *, int, int, u_char *, int);
-int		res_nquerydomain(res_state, const char *, const char *,
-				      int, int, u_char *, int);
-int		res_nmkquery(res_state, int, const char *, int, int,
-				  const u_char *, int, const u_char *,
-				  u_char *, int);
-int		res_nsend(res_state, const u_char *, int, u_char *, int);
-int		res_nsendsigned(res_state, const u_char *, int,
-				     ns_tsig_key *, u_char *, int);
-int		res_findzonecut(res_state, const char *, ns_class, int,
-				     char *, size_t, struct in_addr *, int);
-int		res_findzonecut2(res_state, const char *, ns_class, int,
-				      char *, size_t,
-				      union res_sockaddr_union *, int);
-void		res_nclose(res_state);
-int		res_nopt(res_state, int, u_char *, int, int);
-void		res_send_setqhook(res_send_qhook);
-void		res_send_setrhook(res_send_rhook);
-int		__res_vinit(res_state, int);
-void		res_destroyservicelist(void);
-const char *	res_servicename(uint16_t, const char *);
-const char *	res_protocolname(int);
-void		res_destroyprotolist(void);
-void		res_buildprotolist(void);
-const char *	res_get_nibblesuffix(res_state);
-const char *	res_get_nibblesuffix2(res_state);
-void		res_ndestroy(res_state);
-uint16_t	res_nametoclass(const char *, int *);
-uint16_t	res_nametotype(const char *, int *);
-void		res_setservers(res_state,
-				    const union res_sockaddr_union *, int);
-int		res_getservers(res_state,
-				    union res_sockaddr_union *, int);
-
-void res_setiface();
-void res_setmark();
-u_int  res_randomid(void);
-
-__END_DECLS
-
-#endif /* !_RESOLV_PRIVATE_H_ */
diff --git a/libc/private/thread_private.h b/libc/private/thread_private.h
index b19ad09..2e3ac3d 100644
--- a/libc/private/thread_private.h
+++ b/libc/private/thread_private.h
@@ -7,6 +7,8 @@
 
 #include <pthread.h>
 
+__BEGIN_DECLS
+
 /*
  * This file defines the thread library interface to libc.  Thread
  * libraries must implement the functions described here for proper
@@ -15,11 +17,6 @@
  */
 
 /*
- * This variable is 0 until a second thread is created.
- */
-extern int __isthreaded;
-
-/*
  * helper macro to make unique names in the thread namespace
  */
 #define __THREAD_NAME(name)	__CONCAT(_thread_tagname_,name)
@@ -36,16 +33,23 @@
 #define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \
 	pthread_mutex_unlock( &__THREAD_NAME(name)._private_lock )
 
-void	_thread_atexit_lock(void);
-void	_thread_atexit_unlock(void);
+/* Note that these aren't compatible with the usual OpenBSD ones which lazy-initialize! */
+#define _MUTEX_LOCK(l) pthread_mutex_lock((pthread_mutex_t*) l)
+#define _MUTEX_UNLOCK(l) pthread_mutex_unlock((pthread_mutex_t*) l)
 
-#define _ATEXIT_LOCK()		do {					\
-					if (__isthreaded)		\
-						_thread_atexit_lock();	\
-				} while (0)
-#define _ATEXIT_UNLOCK()	do {					\
-					if (__isthreaded)		\
-						_thread_atexit_unlock();\
-				} while (0)
+__LIBC_HIDDEN__ void  _thread_atexit_lock(void);
+__LIBC_HIDDEN__ void  _thread_atexit_unlock(void);
+
+#define _ATEXIT_LOCK() _thread_atexit_lock()
+#define _ATEXIT_UNLOCK() _thread_atexit_unlock()
+
+__LIBC_HIDDEN__ void    _thread_arc4_lock(void);
+__LIBC_HIDDEN__ void    _thread_arc4_unlock(void);
+
+#define _ARC4_LOCK() _thread_arc4_lock()
+#define _ARC4_UNLOCK() _thread_arc4_unlock()
+#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+
+__END_DECLS
 
 #endif /* _THREAD_PRIVATE_H_ */
diff --git a/libc/stdio/asprintf.c b/libc/stdio/asprintf.c
deleted file mode 100644
index c3d8d61..0000000
--- a/libc/stdio/asprintf.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*	$OpenBSD: asprintf.c,v 1.15 2005/10/10 12:00:52 espie Exp $	*/
-
-/*
- * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <stdarg.h>
-#include "local.h"
-
-int
-asprintf(char **str, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-	FILE f;
-	unsigned char *_base;
-
-	f._file = -1;
-	f._flags = __SWR | __SSTR | __SALC;
-	f._bf._base = f._p = (unsigned char *)malloc(128);
-	if (f._bf._base == NULL)
-		goto err;
-	f._bf._size = f._w = 127;		/* Leave room for the NUL */
-	va_start(ap, fmt);
-	ret = __vfprintf(&f, fmt, ap);
-	va_end(ap);
-	if (ret == -1)
-		goto err;
-	*f._p = '\0';
-	_base = realloc(f._bf._base, ret + 1);
-	if (_base == NULL)
-		goto err;
-	*str = (char *)_base;
-	return (ret);
-
-err:
-	free(f._bf._base);
-	*str = NULL;
-	errno = ENOMEM;
-	return (-1);
-}
diff --git a/libc/stdio/fflush.c b/libc/stdio/fflush.c
deleted file mode 100644
index e69bdcc..0000000
--- a/libc/stdio/fflush.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*	$OpenBSD: fflush.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include "local.h"
-
-/* Flush a single file, or (if fp is NULL) all files.  */
-int
-fflush(FILE *fp)
-{
-	int r;
-
-	if (fp == NULL)
-		return (_fwalk(__sflush_locked));
-	FLOCKFILE(fp);
-	if ((fp->_flags & (__SWR | __SRW)) == 0) {
-		errno = EBADF;
-		r = EOF;
-	} else
-		r = __sflush(fp);
-	FUNLOCKFILE(fp);
-	return (r);
-}
-
-int
-__sflush(FILE *fp)
-{
-	unsigned char *p;
-	int n, t;
-
-	t = fp->_flags;
-	if ((t & __SWR) == 0)
-		return (0);
-
-	if ((p = fp->_bf._base) == NULL)
-		return (0);
-
-	n = fp->_p - p;		/* write this much */
-
-	/*
-	 * Set these immediately to avoid problems with longjmp and to allow
-	 * exchange buffering (via setvbuf) in user write function.
-	 */
-	fp->_p = p;
-	fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
-
-	for (; n > 0; n -= t, p += t) {
-		t = (*fp->_write)(fp->_cookie, (char *)p, n);
-		if (t <= 0) {
-			fp->_flags |= __SERR;
-			return (EOF);
-		}
-	}
-	return (0);
-}
-
-int
-__sflush_locked(FILE *fp)
-{
-	int r;
-
-	FLOCKFILE(fp);
-	r = __sflush(fp);
-	FUNLOCKFILE(fp);
-	return (r);
-}
diff --git a/libc/stdio/fgetc.c b/libc/stdio/fgetc.c
deleted file mode 100644
index 0a6d54e..0000000
--- a/libc/stdio/fgetc.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-
-int
-fgetc(FILE *fp)
-{
-	return (getc(fp));
-}
diff --git a/libc/stdio/fileext.h b/libc/stdio/fileext.h
index b36a448..1f2a3a3 100644
--- a/libc/stdio/fileext.h
+++ b/libc/stdio/fileext.h
@@ -29,8 +29,10 @@
  * $Citrus$
  */
 
+#ifndef _FILEEXT_H_
+#define _FILEEXT_H_
+
 #include <pthread.h>
-#include "wcio.h"
 
 /*
  * file extension
@@ -52,20 +54,13 @@
 	_UB(fp)._base = NULL; \
 	_UB(fp)._size = 0; \
 	WCIO_INIT(fp); \
-	_FLOCK_INIT(fp); \
+        _FLOCK(fp).value = __PTHREAD_RECURSIVE_MUTEX_INIT_VALUE; \
 } while (0)
 
-/* Helper macros to avoid a function call when you know that fp is not NULL.
- * Notice that we keep _FLOCK_INIT() fast by slightly breaking our pthread
- * encapsulation.
- */
-#define _FLOCK_INIT(fp)    _FLOCK(fp).value = __PTHREAD_RECURSIVE_MUTEX_INIT_VALUE
-#define _FLOCK_LOCK(fp)    pthread_mutex_lock(&_FLOCK(fp))
-#define _FLOCK_TRYLOCK(fp) pthread_mutex_trylock(&_FLOCK(fp))
-#define _FLOCK_UNLOCK(fp)  pthread_mutex_unlock(&_FLOCK(fp))
-
 #define _FILEEXT_SETUP(f, fext) \
 do { \
 	(f)->_ext._base = (unsigned char *)(fext); \
 	_FILEEXT_INIT(f); \
 } while (0)
+
+#endif /* _FILEEXT_H_ */
diff --git a/libc/stdio/findfp.c b/libc/stdio/findfp.c
deleted file mode 100644
index 943c90a..0000000
--- a/libc/stdio/findfp.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/*	$OpenBSD: findfp.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/param.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include "local.h"
-#include "glue.h"
-#include "private/thread_private.h"
-
-int	__sdidinit;
-
-#define	NDYNAMIC 10		/* add ten more whenever necessary */
-
-#define	std(flags, file) \
-	{0,0,0,flags,file,{0,0},0,__sF+file,__sclose,__sread,__sseek,__swrite, \
-	 {(unsigned char *)(__sFext+file), 0},NULL,0,{0,0,0},{0},{0,0},0,0}
-/*	 p r w flags file _bf z  cookie      close    read    seek    write
-	 ext */
-
-/* the usual - (stdin + stdout + stderr) */
-static FILE usual[FOPEN_MAX - 3];
-static struct __sfileext usualext[FOPEN_MAX - 3];
-static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
-static struct glue *lastglue = &uglue;
-_THREAD_PRIVATE_MUTEX(__sfp_mutex);
-
-static struct __sfileext __sFext[3] = {
-	_FILEEXT_INITIALIZER,
-	_FILEEXT_INITIALIZER,
-	_FILEEXT_INITIALIZER,
-};
-
-FILE __sF[3] = {
-	std(__SRD, STDIN_FILENO),		/* stdin */
-	std(__SWR, STDOUT_FILENO),		/* stdout */
-	std(__SWR|__SNBF, STDERR_FILENO)	/* stderr */
-};
-struct glue __sglue = { &uglue, 3, __sF };
-
-static struct glue *
-moreglue(int n)
-{
-	struct glue *g;
-	FILE *p;
-	struct __sfileext *pext;
-	static FILE empty;
-	char *data;
-
-	data = malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)
-	    + n * sizeof(struct __sfileext));
-	if (data == NULL)
-		return (NULL);
-	g = (struct glue *)data;
-	p = (FILE *)ALIGN(data + sizeof(*g));
-	pext = (struct __sfileext *)
-	    (ALIGN(data + sizeof(*g)) + n * sizeof(FILE));
-	g->next = NULL;
-	g->niobs = n;
-	g->iobs = p;
-	while (--n >= 0) {
-		*p = empty;
-		_FILEEXT_SETUP(p, pext);
-		p++;
-		pext++;
-	}
-	return (g);
-}
-
-/*
- * Find a free FILE for fopen et al.
- */
-FILE *
-__sfp(void)
-{
-	FILE *fp;
-	int n;
-	struct glue *g;
-
-	if (!__sdidinit)
-		__sinit();
-
-	_THREAD_PRIVATE_MUTEX_LOCK(__sfp_mutex);
-	for (g = &__sglue; g != NULL; g = g->next) {
-		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
-			if (fp->_flags == 0)
-				goto found;
-	}
-
-	/* release lock while mallocing */
-	_THREAD_PRIVATE_MUTEX_UNLOCK(__sfp_mutex);
-	if ((g = moreglue(NDYNAMIC)) == NULL)
-		return (NULL);
-	_THREAD_PRIVATE_MUTEX_LOCK(__sfp_mutex);
-	lastglue->next = g;
-	lastglue = g;
-	fp = g->iobs;
-found:
-	fp->_flags = 1;		/* reserve this slot; caller sets real flags */
-	_THREAD_PRIVATE_MUTEX_UNLOCK(__sfp_mutex);
-	fp->_p = NULL;		/* no current pointer */
-	fp->_w = 0;		/* nothing to read or write */
-	fp->_r = 0;
-	fp->_bf._base = NULL;	/* no buffer */
-	fp->_bf._size = 0;
-	fp->_lbfsize = 0;	/* not line buffered */
-	fp->_file = -1;		/* no file */
-/*	fp->_cookie = <any>; */	/* caller sets cookie, _read/_write etc */
-	fp->_lb._base = NULL;	/* no line buffer */
-	fp->_lb._size = 0;
-	_FILEEXT_INIT(fp);
-	return (fp);
-}
-
-#if 0
-#define getdtablesize()	sysconf(_SC_OPEN_MAX)
-
-/*
- * XXX.  Force immediate allocation of internal memory.  Not used by stdio,
- * but documented historically for certain applications.  Bad applications.
- */
-void
-f_prealloc(void)
-{
-	struct glue *g;
-	int n;
-
-	n = getdtablesize() - FOPEN_MAX + 20;		/* 20 for slop. */
-	for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next)
-		/* void */;
-	if (n > 0 && ((g = moreglue(n)) != NULL)) {
-		_THREAD_PRIVATE_MUTEX_LOCK(__sfp_mutex);
-		lastglue->next = g;
-		lastglue = g;
-		_THREAD_PRIVATE_MUTEX_UNLOCK(__sfp_mutex);
-	}
-}
-#endif
-
-/*
- * exit() calls _cleanup() through *__cleanup, set whenever we
- * open or buffer a file.  This chicanery is done so that programs
- * that do not use stdio need not link it all in.
- *
- * The name `_cleanup' is, alas, fairly well known outside stdio.
- */
-void
-_cleanup(void)
-{
-	/* (void) _fwalk(fclose); */
-	(void) _fwalk(__sflush);		/* `cheating' */
-}
-
-/*
- * __sinit() is called whenever stdio's internal variables must be set up.
- */
-void
-__sinit(void)
-{
-	_THREAD_PRIVATE_MUTEX(__sinit_mutex);
-	int i;
-
-	_THREAD_PRIVATE_MUTEX_LOCK(__sinit_mutex);
-	if (__sdidinit)
-		goto out;	/* bail out if caller lost the race */
-	for (i = 0; i < FOPEN_MAX - 3; i++) {
-		_FILEEXT_SETUP(usual+i, usualext+i);
-	}
-	/* make sure we clean up on exit */
-	__cleanup = _cleanup; /* conservative */
-	__sdidinit = 1;
-out:
-	_THREAD_PRIVATE_MUTEX_UNLOCK(__sinit_mutex);
-}
diff --git a/libc/stdio/floatio.h b/libc/stdio/floatio.h
deleted file mode 100644
index 20f9801..0000000
--- a/libc/stdio/floatio.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*	$OpenBSD: floatio.h,v 1.3 2003/06/02 20:18:37 millert Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Floating point scanf/printf (input/output) definitions.
- */
-
-/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
-#define	MAXEXP		308
-/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
-#define	MAXFRACT	39
diff --git a/libc/stdio/fprintf.c b/libc/stdio/fprintf.c
deleted file mode 100644
index 7415b2f..0000000
--- a/libc/stdio/fprintf.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*	$OpenBSD: fprintf.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-
-int
-fprintf(FILE *fp, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfprintf(fp, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/stdio/fputc.c b/libc/stdio/fputc.c
deleted file mode 100644
index 90809e2..0000000
--- a/libc/stdio/fputc.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*	$OpenBSD: fputc.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <errno.h>
-
-int
-fputc(int c, FILE *fp)
-{
-	return (putc(c, fp));
-}
diff --git a/libc/stdio/fread.c b/libc/stdio/fread.c
deleted file mode 100644
index 649db17..0000000
--- a/libc/stdio/fread.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*	$OpenBSD: fread.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include "local.h"
-
-static int
-lflush(FILE *fp)
-{
-    if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
-        return (__sflush_locked(fp));
-    return (0);
-}
-
-size_t
-fread(void *buf, size_t size, size_t count, FILE *fp)
-{
-    size_t resid;
-    char *p;
-    int r;
-    size_t total;
-
-    /*
-     * The ANSI standard requires a return value of 0 for a count
-     * or a size of 0.  Peculiarily, it imposes no such requirements
-     * on fwrite; it only requires fread to be broken.
-     */
-    if ((resid = count * size) == 0)
-        return (0);
-    FLOCKFILE(fp);
-    if (fp->_r < 0)
-        fp->_r = 0;
-    total = resid;
-    p = buf;
-
-#if 1  /* BIONIC: optimize unbuffered reads */
-    if (fp->_flags & __SNBF && fp->_ur == 0)
-    {
-        /* the following comes mainly from __srefill(), with slight
-         * modifications
-         */
-
-        /* make sure stdio is set up */
-        if (!__sdidinit)
-            __sinit();
-
-        fp->_r = 0;     /* largely a convenience for callers */
-
-        /* SysV does not make this test; take it out for compatibility */
-        if (fp->_flags & __SEOF) {
-            FUNLOCKFILE(fp);
-            return (EOF);
-        }
-
-        /* if not already reading, have to be reading and writing */
-        if ((fp->_flags & __SRD) == 0) {
-            if ((fp->_flags & __SRW) == 0) {
-                fp->_flags |= __SERR;
-                FUNLOCKFILE(fp);
-                errno = EBADF;
-                return (EOF);
-            }
-            /* switch to reading */
-            if (fp->_flags & __SWR) {
-                if (__sflush(fp)) {
-                    FUNLOCKFILE(fp);
-                    return (EOF);
-                }
-                fp->_flags &= ~__SWR;
-                fp->_w = 0;
-                fp->_lbfsize = 0;
-            }
-            fp->_flags |= __SRD;
-        } else {
-            /*
-             * We were reading.  If there is an ungetc buffer,
-             * we must have been reading from that.  Drop it,
-             * restoring the previous buffer (if any).  If there
-             * is anything in that buffer, return.
-             */
-            if (HASUB(fp)) {
-                FREEUB(fp);
-            }
-        }
-
-        /*
-         * Before reading from a line buffered or unbuffered file,
-         * flush all line buffered output files, per the ANSI C
-         * standard.
-         */
-
-        if (fp->_flags & (__SLBF|__SNBF)) {
-            /* Ignore this file in _fwalk to deadlock. */
-            fp->_flags |= __SIGN;
-            (void) _fwalk(lflush);
-            fp->_flags &= ~__SIGN;
-
-            /* Now flush this file without locking it. */
-            if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
-                __sflush(fp);
-        }
-
-        while (resid > 0) {
-            int   len = (*fp->_read)(fp->_cookie, p, resid );
-            fp->_flags &= ~__SMOD;
-            if (len <= 0) {
-                if (len == 0)
-                    fp->_flags |= __SEOF;
-                else {
-                    fp->_flags |= __SERR;
-                }
-                FUNLOCKFILE(fp);
-                return ((total - resid) / size);
-            }
-            p     += len;
-            resid -= len;
-        }
-        FUNLOCKFILE(fp);
-        return (count);
-    }
-    else
-#endif
-    {
-        while (resid > (size_t)(r = fp->_r)) {
-            (void)memcpy((void *)p, (void *)fp->_p, (size_t)r);
-            fp->_p += r;
-            /* fp->_r = 0 ... done in __srefill */
-            p += r;
-            resid -= r;
-            if (__srefill(fp)) {
-                /* no more input: return partial result */
-                FUNLOCKFILE(fp);
-                return ((total - resid) / size);
-            }
-        }
-    }
-
-    (void)memcpy((void *)p, (void *)fp->_p, resid);
-    fp->_r -= resid;
-    fp->_p += resid;
-    FUNLOCKFILE(fp);
-    return (count);
-}
diff --git a/libc/stdio/freopen.c b/libc/stdio/freopen.c
deleted file mode 100644
index f0386e9..0000000
--- a/libc/stdio/freopen.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*	$OpenBSD: freopen.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#define __USE_BSD
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "local.h"
-
-/*
- * Re-direct an existing, open (probably) file to some other file.
- * ANSI is written such that the original file gets closed if at
- * all possible, no matter what.
- */
-FILE *
-freopen(const char *file, const char *mode, FILE *fp)
-{
-	int f;
-	int flags, isopen, oflags, sverrno, wantfd;
-
-	if ((flags = __sflags(mode, &oflags)) == 0) {
-		(void) fclose(fp);
-		return (NULL);
-	}
-
-	if (!__sdidinit)
-		__sinit();
-
-	FLOCKFILE(fp);
-
-	/*
-	 * There are actually programs that depend on being able to "freopen"
-	 * descriptors that weren't originally open.  Keep this from breaking.
-	 * Remember whether the stream was open to begin with, and which file
-	 * descriptor (if any) was associated with it.  If it was attached to
-	 * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin)
-	 * should work.  This is unnecessary if it was not a Unix file.
-	 */
-	if (fp->_flags == 0) {
-		fp->_flags = __SEOF;	/* hold on to it */
-		isopen = 0;
-		wantfd = -1;
-	} else {
-		/* flush the stream; ANSI doesn't require this. */
-		if (fp->_flags & __SWR)
-			(void) __sflush(fp);
-		/* if close is NULL, closing is a no-op, hence pointless */
-		isopen = fp->_close != NULL;
-		if ((wantfd = fp->_file) < 0 && isopen) {
-			(void) (*fp->_close)(fp->_cookie);
-			isopen = 0;
-		}
-	}
-
-	/* Get a new descriptor to refer to the new file. */
-	f = open(file, oflags, DEFFILEMODE);
-	if (f < 0 && isopen) {
-		/* If out of fd's close the old one and try again. */
-		if (errno == ENFILE || errno == EMFILE) {
-			(void) (*fp->_close)(fp->_cookie);
-			isopen = 0;
-			f = open(file, oflags, DEFFILEMODE);
-		}
-	}
-	sverrno = errno;
-
-	/*
-	 * Finish closing fp.  Even if the open succeeded above, we cannot
-	 * keep fp->_base: it may be the wrong size.  This loses the effect
-	 * of any setbuffer calls, but stdio has always done this before.
-	 */
-	if (isopen && f != wantfd)
-		(void) (*fp->_close)(fp->_cookie);
-	if (fp->_flags & __SMBF)
-		free((char *)fp->_bf._base);
-	fp->_w = 0;
-	fp->_r = 0;
-	fp->_p = NULL;
-	fp->_bf._base = NULL;
-	fp->_bf._size = 0;
-	fp->_lbfsize = 0;
-	if (HASUB(fp))
-		FREEUB(fp);
-	_UB(fp)._size = 0;
-	WCIO_FREE(fp);
-	if (HASLB(fp))
-		FREELB(fp);
-	fp->_lb._size = 0;
-
-	if (f < 0) {			/* did not get it after all */
-		fp->_flags = 0;		/* set it free */
-		FUNLOCKFILE(fp);
-		errno = sverrno;	/* restore in case _close clobbered */
-		return (NULL);
-	}
-
-	/*
-	 * If reopening something that was open before on a real file, try
-	 * to maintain the descriptor.  Various C library routines (perror)
-	 * assume stderr is always fd STDERR_FILENO, even if being freopen'd.
-	 */
-	if (wantfd >= 0 && f != wantfd) {
-		if (dup2(f, wantfd) >= 0) {
-			(void) close(f);
-			f = wantfd;
-		}
-	}
-
-	fp->_flags = flags;
-	fp->_file = f;
-	fp->_cookie = fp;
-	fp->_read = __sread;
-	fp->_write = __swrite;
-	fp->_seek = __sseek;
-	fp->_close = __sclose;
-
-	/*
-	 * When opening in append mode, even though we use O_APPEND,
-	 * we need to seek to the end so that ftell() gets the right
-	 * answer.  If the user then alters the seek pointer, or
-	 * the file extends, this will fail, but there is not much
-	 * we can do about this.  (We could set __SAPP and check in
-	 * fseek and ftell.)
-	 */
-	if (oflags & O_APPEND)
-		(void) __sseek((void *)fp, (fpos_t)0, SEEK_END);
-	FUNLOCKFILE(fp);
-	return (fp);
-}
diff --git a/libc/stdio/fscanf.c b/libc/stdio/fscanf.c
deleted file mode 100644
index 2f3fceb..0000000
--- a/libc/stdio/fscanf.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*	$OpenBSD: fscanf.c,v 1.9 2005/10/10 17:37:44 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-
-int
-fscanf(FILE *fp, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfscanf(fp, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/stdio/fseek.c b/libc/stdio/fseek.c
deleted file mode 100644
index 38697f5..0000000
--- a/libc/stdio/fseek.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*	$OpenBSD: fseek.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include "local.h"
-
-#define	POS_ERR	(-(fpos_t)1)
-
-/*
- * Seek the given file to the given offset.
- * `Whence' must be one of the three SEEK_* macros.
- */
-int
-fseeko(FILE *fp, off_t offset, int whence)
-{
-	fpos_t (*seekfn)(void *, fpos_t, int);
-	fpos_t target, curoff;
-	size_t n;
-	struct stat st;
-	int havepos;
-
-	/* make sure stdio is set up */
-	if (!__sdidinit)
-		__sinit();
-
-	/*
-	 * Have to be able to seek.
-	 */
-	if ((seekfn = fp->_seek) == NULL) {
-		errno = ESPIPE;			/* historic practice */
-		return (EOF);
-	}
-
-	/*
-	 * Change any SEEK_CUR to SEEK_SET, and check `whence' argument.
-	 * After this, whence is either SEEK_SET or SEEK_END.
-	 */
-	FLOCKFILE(fp);
-	switch (whence) {
-
-	case SEEK_CUR:
-		/*
-		 * In order to seek relative to the current stream offset,
-		 * we have to first find the current stream offset a la
-		 * ftell (see ftell for details).
-		 */
-		__sflush(fp);	/* may adjust seek offset on append stream */
-		if (fp->_flags & __SOFF)
-			curoff = fp->_offset;
-		else {
-			curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
-			if (curoff == (fpos_t)-1) {
-				FUNLOCKFILE(fp);
-				return (EOF);
-			}
-		}
-		if (fp->_flags & __SRD) {
-			curoff -= fp->_r;
-			if (HASUB(fp))
-				curoff -= fp->_ur;
-		} else if (fp->_flags & __SWR && fp->_p != NULL)
-			curoff += fp->_p - fp->_bf._base;
-
-		offset += curoff;
-		whence = SEEK_SET;
-		havepos = 1;
-		break;
-
-	case SEEK_SET:
-	case SEEK_END:
-		curoff = 0;		/* XXX just to keep gcc quiet */
-		havepos = 0;
-		break;
-
-	default:
-		FUNLOCKFILE(fp);
-		errno = EINVAL;
-		return (EOF);
-	}
-
-	/*
-	 * Can only optimise if:
-	 *	reading (and not reading-and-writing);
-	 *	not unbuffered; and
-	 *	this is a `regular' Unix file (and hence seekfn==__sseek).
-	 * We must check __NBF first, because it is possible to have __NBF
-	 * and __SOPT both set.
-	 */
-	if (fp->_bf._base == NULL)
-		__smakebuf(fp);
-	if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT))
-		goto dumb;
-	if ((fp->_flags & __SOPT) == 0) {
-		if (seekfn != __sseek ||
-		    fp->_file < 0 || fstat(fp->_file, &st) ||
-		    (st.st_mode & S_IFMT) != S_IFREG) {
-			fp->_flags |= __SNPT;
-			goto dumb;
-		}
-		fp->_blksize = st.st_blksize;
-		fp->_flags |= __SOPT;
-	}
-
-	/*
-	 * We are reading; we can try to optimise.
-	 * Figure out where we are going and where we are now.
-	 */
-	if (whence == SEEK_SET)
-		target = offset;
-	else {
-		if (fstat(fp->_file, &st))
-			goto dumb;
-		target = st.st_size + offset;
-	}
-
-	if (!havepos) {
-		if (fp->_flags & __SOFF)
-			curoff = fp->_offset;
-		else {
-			curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
-			if (curoff == POS_ERR)
-				goto dumb;
-		}
-		curoff -= fp->_r;
-		if (HASUB(fp))
-			curoff -= fp->_ur;
-	}
-
-	/*
-	 * Compute the number of bytes in the input buffer (pretending
-	 * that any ungetc() input has been discarded).  Adjust current
-	 * offset backwards by this count so that it represents the
-	 * file offset for the first byte in the current input buffer.
-	 */
-	if (HASUB(fp)) {
-		curoff += fp->_r;	/* kill off ungetc */
-		n = fp->_up - fp->_bf._base;
-		curoff -= n;
-		n += fp->_ur;
-	} else {
-		n = fp->_p - fp->_bf._base;
-		curoff -= n;
-		n += fp->_r;
-	}
-
-	/*
-	 * If the target offset is within the current buffer,
-	 * simply adjust the pointers, clear EOF, undo ungetc(),
-	 * and return.  (If the buffer was modified, we have to
-	 * skip this; see fgetln.c.)
-	 */
-	if ((fp->_flags & __SMOD) == 0 &&
-	    target >= curoff && target < (fpos_t)(curoff + n)) {
-		int o = target - curoff;
-
-		fp->_p = fp->_bf._base + o;
-		fp->_r = n - o;
-		if (HASUB(fp))
-			FREEUB(fp);
-		fp->_flags &= ~__SEOF;
-		FUNLOCKFILE(fp);
-		return (0);
-	}
-
-	/*
-	 * The place we want to get to is not within the current buffer,
-	 * but we can still be kind to the kernel copyout mechanism.
-	 * By aligning the file offset to a block boundary, we can let
-	 * the kernel use the VM hardware to map pages instead of
-	 * copying bytes laboriously.  Using a block boundary also
-	 * ensures that we only read one block, rather than two.
-	 */
-	curoff = target & ~(fp->_blksize - 1);
-	if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)
-		goto dumb;
-	fp->_r = 0;
-	fp->_p = fp->_bf._base;
-	if (HASUB(fp))
-		FREEUB(fp);
-	fp->_flags &= ~__SEOF;
-	n = target - curoff;
-	if (n) {
-		if (__srefill(fp) || (size_t)fp->_r < n)
-			goto dumb;
-		fp->_p += n;
-		fp->_r -= n;
-	}
-	FUNLOCKFILE(fp);
-	return (0);
-
-	/*
-	 * We get here if we cannot optimise the seek ... just
-	 * do it.  Allow the seek function to change fp->_bf._base.
-	 */
-dumb:
-	if (__sflush(fp) ||
-	    (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) {
-		FUNLOCKFILE(fp);
-		return (EOF);
-	}
-	/* success: clear EOF indicator and discard ungetc() data */
-	if (HASUB(fp))
-		FREEUB(fp);
-	fp->_p = fp->_bf._base;
-	fp->_r = 0;
-	/* fp->_w = 0; */	/* unnecessary (I think...) */
-	fp->_flags &= ~__SEOF;
-	FUNLOCKFILE(fp);
-	return (0);
-}
-
-/*
- * fseek()'s offset is a long and sizeof(off_t) != sizeof(long) on all arches
- */
-#if defined(__alpha__) && defined(__indr_reference)
-__indr_reference(fseeko, fseek);
-#else
-int
-fseek(FILE *fp, long offset, int whence)
-{
-	off_t off = offset;
-
-	return(fseeko(fp, off, whence));
-}
-#endif
diff --git a/libc/stdio/ftell.c b/libc/stdio/ftell.c
deleted file mode 100644
index 9f850ee..0000000
--- a/libc/stdio/ftell.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*	$OpenBSD: ftell.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include "local.h"
-
-/*
- * ftello: return current offset.
- */
-off_t
-ftello(FILE *fp)
-{
-	fpos_t pos;
-
-	if (fp->_seek == NULL) {
-		errno = ESPIPE;			/* historic practice */
-		pos = -1;
-                goto out;
-	}
-
-	/*
-	 * Find offset of underlying I/O object, then
-	 * adjust for buffered bytes.
-	 */
-        FLOCKFILE(fp);
-	__sflush(fp);		/* may adjust seek offset on append stream */
-	if (fp->_flags & __SOFF)
-		pos = fp->_offset;
-	else {
-		pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
-		if (pos == -1)
-			goto out;
-	}
-	if (fp->_flags & __SRD) {
-		/*
-		 * Reading.  Any unread characters (including
-		 * those from ungetc) cause the position to be
-		 * smaller than that in the underlying object.
-		 */
-		pos -= fp->_r;
-		if (HASUB(fp))
-			pos -= fp->_ur;
-	} else if (fp->_flags & __SWR && fp->_p != NULL) {
-		/*
-		 * Writing.  Any buffered characters cause the
-		 * position to be greater than that in the
-		 * underlying object.
-		 */
-		pos += fp->_p - fp->_bf._base;
-	}
-out:	FUNLOCKFILE(fp);
-	return (pos);
-}
-
-/*
- * ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches
- */
-#if defined(__alpha__) && defined(__indr_reference)
-__indr_reference(ftello, ftell);
-#else
-long
-ftell(FILE *fp)
-{
-	long pos;
-
-	pos = (long)ftello(fp);
-	return(pos);
-}
-#endif
diff --git a/libc/stdio/fvwrite.c b/libc/stdio/fvwrite.c
deleted file mode 100644
index 39d0604..0000000
--- a/libc/stdio/fvwrite.c
+++ /dev/null
@@ -1,208 +0,0 @@
-/*	$OpenBSD: fvwrite.c,v 1.14 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "local.h"
-#include "fvwrite.h"
-
-/*
- * Write some memory regions.  Return zero on success, EOF on error.
- *
- * This routine is large and unsightly, but most of the ugliness due
- * to the three different kinds of output buffering is handled here.
- */
-__LIBC_HIDDEN__ int
-__sfvwrite(FILE *fp, struct __suio *uio)
-{
-	size_t len;
-	const char *p;
-	struct __siov *iov;
-	int w, s;
-	char *nl;
-	int nlknown, nldist;
-
-	if ((len = uio->uio_resid) == 0)
-		return (0);
-	/* make sure we can write */
-	if (cantwrite(fp)) {
-		errno = EBADF;
-		return (EOF);
-	}
-
-#define	MIN(a, b) ((a) < (b) ? (a) : (b))
-#define	COPY(n)	  (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n))
-
-	iov = uio->uio_iov;
-	p = iov->iov_base;
-	len = iov->iov_len;
-	iov++;
-#define GETIOV(extra_work) \
-	while (len == 0) { \
-		extra_work; \
-		p = iov->iov_base; \
-		len = iov->iov_len; \
-		iov++; \
-	}
-	if (fp->_flags & __SNBF) {
-		/*
-		 * Unbuffered: write up to BUFSIZ bytes at a time.
-		 */
-		do {
-			GETIOV(;);
-#if 1  /* BIONIC: don't limit to 1KB writes */
-			w = (*fp->_write)(fp->_cookie, p, len);
-#else
-			w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ2));
-#endif
-			if (w <= 0)
-				goto err;
-			p += w;
-			len -= w;
-		} while ((uio->uio_resid -= w) != 0);
-	} else if ((fp->_flags & __SLBF) == 0) {
-		/*
-		 * Fully buffered: fill partially full buffer, if any,
-		 * and then flush.  If there is no partial buffer, write
-		 * one _bf._size byte chunk directly (without copying).
-		 *
-		 * String output is a special case: write as many bytes
-		 * as fit, but pretend we wrote everything.  This makes
-		 * snprintf() return the number of bytes needed, rather
-		 * than the number used, and avoids its write function
-		 * (so that the write function can be invalid).
-		 */
-		do {
-			GETIOV(;);
-			if ((fp->_flags & (__SALC | __SSTR)) ==
-			    (__SALC | __SSTR) && fp->_w < (int)len) {
-				size_t blen = fp->_p - fp->_bf._base;
-				unsigned char *_base;
-				int _size;
-
-				/* Allocate space exponentially. */
-				_size = fp->_bf._size;
-				do {
-					_size = (_size << 1) + 1;
-				} while (_size < (int)(blen + len));
-				_base = realloc(fp->_bf._base, _size + 1);
-				if (_base == NULL)
-					goto err;
-				fp->_w += _size - fp->_bf._size;
-				fp->_bf._base = _base;
-				fp->_bf._size = _size;
-				fp->_p = _base + blen;
-			}
-			w = fp->_w;
-			if (fp->_flags & __SSTR) {
-				if ((int)len < w)
-					w = len;
-				COPY(w);	/* copy MIN(fp->_w,len), */
-				fp->_w -= w;
-				fp->_p += w;
-				w = len;	/* but pretend copied all */
-			} else if (fp->_p > fp->_bf._base && (int)len > w) {
-				/* fill and flush */
-				COPY(w);
-				/* fp->_w -= w; */ /* unneeded */
-				fp->_p += w;
-				if (fflush(fp))
-					goto err;
-			} else if ((int)len >= (w = fp->_bf._size)) {
-				/* write directly */
-				w = (*fp->_write)(fp->_cookie, p, w);
-				if (w <= 0)
-					goto err;
-			} else {
-				/* fill and done */
-				w = len;
-				COPY(w);
-				fp->_w -= w;
-				fp->_p += w;
-			}
-			p += w;
-			len -= w;
-		} while ((uio->uio_resid -= w) != 0);
-	} else {
-		/*
-		 * Line buffered: like fully buffered, but we
-		 * must check for newlines.  Compute the distance
-		 * to the first newline (including the newline),
-		 * or `infinity' if there is none, then pretend
-		 * that the amount to write is MIN(len,nldist).
-		 */
-		nlknown = 0;
-		nldist = 0;	/* XXX just to keep gcc happy */
-		do {
-			GETIOV(nlknown = 0);
-			if (!nlknown) {
-				nl = memchr((void *)p, '\n', len);
-				nldist = nl ? nl + 1 - p : (int)len + 1;
-				nlknown = 1;
-			}
-			s = MIN((int)len, nldist);
-			w = fp->_w + fp->_bf._size;
-			if (fp->_p > fp->_bf._base && s > w) {
-				COPY(w);
-				/* fp->_w -= w; */
-				fp->_p += w;
-				if (fflush(fp))
-					goto err;
-			} else if (s >= (w = fp->_bf._size)) {
-				w = (*fp->_write)(fp->_cookie, p, w);
-				if (w <= 0)
-					goto err;
-			} else {
-				w = s;
-				COPY(w);
-				fp->_w -= w;
-				fp->_p += w;
-			}
-			if ((nldist -= w) == 0) {
-				/* copied the newline: flush and forget */
-				if (fflush(fp))
-					goto err;
-				nlknown = 0;
-			}
-			p += w;
-			len -= w;
-		} while ((uio->uio_resid -= w) != 0);
-	}
-	return (0);
-
-err:
-	fp->_flags |= __SERR;
-	return (EOF);
-}
diff --git a/libc/stdio/fvwrite.h b/libc/stdio/fvwrite.h
deleted file mode 100644
index 96f65de..0000000
--- a/libc/stdio/fvwrite.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: fvwrite.h,v 1.5 2003/06/02 20:18:37 millert Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * I/O descriptors for __sfvwrite().
- */
-struct __siov {
-	const void	*iov_base;
-	size_t	iov_len;
-};
-struct __suio {
-	struct	__siov *uio_iov;
-	int	uio_iovcnt;
-	int	uio_resid;
-};
-
-extern int __sfvwrite(FILE *, struct __suio *);
diff --git a/libc/stdio/gets.c b/libc/stdio/gets.c
deleted file mode 100644
index 93e2edd..0000000
--- a/libc/stdio/gets.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*	$OpenBSD: gets.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include "local.h"
-
-__warn_references(gets,
-    "warning: gets() is very unsafe; consider using fgets()");
-
-char *
-gets(char *buf)
-{
-	int c;
-	char *s;
-
-	FLOCKFILE(stdin);
-	for (s = buf; (c = getchar_unlocked()) != '\n';)
-		if (c == EOF)
-			if (s == buf) {
-				FUNLOCKFILE(stdin);
-				return (NULL);
-			} else
-				break;
-		else
-			*s++ = c;
-	*s = '\0';
-	FUNLOCKFILE(stdin);
-	return (buf);
-}
diff --git a/libc/stdio/glue.h b/libc/stdio/glue.h
index 73cef63..4ead20a 100644
--- a/libc/stdio/glue.h
+++ b/libc/stdio/glue.h
@@ -42,4 +42,5 @@
 	FILE	*iobs;
 };
 
-extern struct glue __sglue;
+/* This was referenced by a couple of different pieces of middleware and the Crystax NDK. */
+__LIBC64_HIDDEN__ extern struct glue __sglue;
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index a175d6f..eb84833 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -32,37 +32,53 @@
  * SUCH DAMAGE.
  */
 
-#include "wcio.h"
-#include "fileext.h"
-
-
 /*
  * Information local to this implementation of stdio,
  * in particular, macros and private variables.
  */
 
+#include <wchar.h>
+#include "wcio.h"
+#include "fileext.h"
+
+/*
+ * Android <= KitKat had getc/putc macros in <stdio.h> that referred
+ * to __srget/__swbuf, so those symbols need to be public for LP32
+ * but can be hidden for LP64.
+ */
+__LIBC64_HIDDEN__ int __srget(FILE*);
+__LIBC64_HIDDEN__ int __swbuf(int, FILE*);
+__LIBC64_HIDDEN__ int __srefill(FILE*);
+
+/* This was referenced by the apportable middleware for LP32. */
+__LIBC64_HIDDEN__ int __swsetup(FILE*);
+
+/* These were referenced by a couple of different pieces of middleware and the Crystax NDK. */
+__LIBC64_HIDDEN__ extern int __sdidinit;
+__LIBC64_HIDDEN__ int __sflags(const char*, int*);
+__LIBC64_HIDDEN__ FILE* __sfp(void);
+__LIBC64_HIDDEN__ void __sinit(void);
+__LIBC64_HIDDEN__ void __smakebuf(FILE*);
+
+#pragma GCC visibility push(hidden)
+
 int	__sflush(FILE *);
 int	__sflush_locked(FILE *);
-FILE	*__sfp(void);
-int	__srefill(FILE *);
 int	__sread(void *, char *, int);
 int	__swrite(void *, const char *, int);
 fpos_t	__sseek(void *, fpos_t, int);
 int	__sclose(void *);
-void	__sinit(void);
 void	_cleanup(void);
-void	__smakebuf(FILE *);
 int	__swhatbuf(FILE *, size_t *, int *);
 int	_fwalk(int (*)(FILE *));
-int	__swsetup(FILE *);
-int	__sflags(const char *, int *);
+wint_t __fgetwc_unlock(FILE *);
+wint_t	__ungetwc(wint_t, FILE *);
 int	__vfprintf(FILE *, const char *, __va_list);
+int	__svfscanf(FILE * __restrict, const char * __restrict, __va_list);
+int	__vfwprintf(FILE * __restrict, const wchar_t * __restrict, __va_list);
+int	__vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list);
 
-/*
- * Function to clean up streams, called from abort() and exit().
- */
-extern void (*__cleanup)(void);
-extern int __sdidinit;
+extern void __atexit_register_cleanup(void (*)(void));
 
 /*
  * Return true if the given FILE cannot be written now.
@@ -91,7 +107,31 @@
 	(fp)->_lb._base = NULL; \
 }
 
-#define FLOCKFILE(fp)   do { if (__isthreaded) flockfile(fp); } while (0)
-#define FUNLOCKFILE(fp) do { if (__isthreaded) funlockfile(fp); } while (0)
+#define FLOCKFILE(fp)   flockfile(fp)
+#define FUNLOCKFILE(fp) funlockfile(fp)
 
 #define FLOATING_POINT
+#define PRINTF_WIDE_CHAR
+#define SCANF_WIDE_CHAR
+#define NO_PRINTF_PERCENT_N
+
+/* OpenBSD exposes these in <stdio.h>, but we only want them exposed to the implementation. */
+#define __sfeof(p)     (((p)->_flags & __SEOF) != 0)
+#define __sferror(p)   (((p)->_flags & __SERR) != 0)
+#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
+#define __sfileno(p)   ((p)->_file)
+#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
+static __inline int __sputc(int _c, FILE* _p) {
+  if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) {
+    return (*_p->_p++ = _c);
+  } else {
+    return (__swbuf(_c, _p));
+  }
+}
+
+/* OpenBSD declares these in fvwrite.h but we want to ensure they're hidden. */
+struct __suio;
+extern int __sfvwrite(FILE *, struct __suio *);
+wint_t __fputwc_unlock(wchar_t wc, FILE *fp);
+
+#pragma GCC visibility pop
diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c
deleted file mode 100644
index 614b435..0000000
--- a/libc/stdio/printf.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*	$OpenBSD: printf.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-
-int
-printf(const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfprintf(stdout, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/stdio/refill.c b/libc/stdio/refill.c
deleted file mode 100644
index 7cb6b78..0000000
--- a/libc/stdio/refill.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*	$OpenBSD: refill.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "local.h"
-
-static int
-lflush(FILE *fp)
-{
-	if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
-		return (__sflush_locked(fp)); /* ignored... */
-	return (0);
-}
-
-/*
- * Refill a stdio buffer.
- * Return EOF on eof or error, 0 otherwise.
- */
-int
-__srefill(FILE *fp)
-{
-
-	/* make sure stdio is set up */
-	if (!__sdidinit)
-		__sinit();
-
-	fp->_r = 0;		/* largely a convenience for callers */
-
-	/* SysV does not make this test; take it out for compatibility */
-	if (fp->_flags & __SEOF)
-		return (EOF);
-
-	/* if not already reading, have to be reading and writing */
-	if ((fp->_flags & __SRD) == 0) {
-		if ((fp->_flags & __SRW) == 0) {
-			errno = EBADF;
-			fp->_flags |= __SERR;
-			return (EOF);
-		}
-		/* switch to reading */
-		if (fp->_flags & __SWR) {
-			if (__sflush(fp))
-				return (EOF);
-			fp->_flags &= ~__SWR;
-			fp->_w = 0;
-			fp->_lbfsize = 0;
-		}
-		fp->_flags |= __SRD;
-	} else {
-		/*
-		 * We were reading.  If there is an ungetc buffer,
-		 * we must have been reading from that.  Drop it,
-		 * restoring the previous buffer (if any).  If there
-		 * is anything in that buffer, return.
-		 */
-		if (HASUB(fp)) {
-			FREEUB(fp);
-			if ((fp->_r = fp->_ur) != 0) {
-				fp->_p = fp->_up;
-				return (0);
-			}
-		}
-	}
-
-	if (fp->_bf._base == NULL)
-		__smakebuf(fp);
-
-	/*
-	 * Before reading from a line buffered or unbuffered file,
-	 * flush all line buffered output files, per the ANSI C
-	 * standard.
-	 */
-	if (fp->_flags & (__SLBF|__SNBF)) {
-		/* Ignore this file in _fwalk to avoid potential deadlock. */
-		fp->_flags |= __SIGN;
-		(void) _fwalk(lflush);
-		fp->_flags &= ~__SIGN;
-
-		/* Now flush this file without locking it. */
-		if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
-		    __sflush(fp);
-	}
-	fp->_p = fp->_bf._base;
-	fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size);
-	fp->_flags &= ~__SMOD;	/* buffer contents are again pristine */
-	if (fp->_r <= 0) {
-		if (fp->_r == 0)
-			fp->_flags |= __SEOF;
-		else {
-			fp->_r = 0;
-			fp->_flags |= __SERR;
-		}
-		return (EOF);
-	}
-	return (0);
-}
diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c
deleted file mode 100644
index 71194d0..0000000
--- a/libc/stdio/scanf.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*	$OpenBSD: scanf.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-
-int
-scanf(const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfscanf(stdin, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/stdio/sscanf.c b/libc/stdio/sscanf.c
deleted file mode 100644
index a0bdf1c..0000000
--- a/libc/stdio/sscanf.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*	$OpenBSD: sscanf.c,v 1.12 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include "local.h"
-
-/* ARGSUSED */
-static int
-eofread(void *cookie, char *buf, int len)
-{
-
-	return (0);
-}
-
-int
-sscanf(const char *str, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-	FILE f;
-	struct __sfileext fext;
-
-	_FILEEXT_SETUP(&f, &fext);
-	f._flags = __SRD;
-	f._bf._base = f._p = (unsigned char *)str;
-	f._bf._size = f._r = strlen(str);
-	f._read = eofread;
-	f._lb._base = NULL;
-	va_start(ap, fmt);
-	ret = vfscanf(&f, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c
deleted file mode 100644
index 1596ebf..0000000
--- a/libc/stdio/stdio.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*	$OpenBSD: stdio.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include "local.h"
-
-/*
- * Small standard I/O/seek/close functions.
- * These maintain the `known seek offset' for seek optimisation.
- */
-int
-__sread(void *cookie, char *buf, int n)
-{
-	FILE *fp = cookie;
-	int ret;
-
-	ret = read(fp->_file, buf, n);
-	/* if the read succeeded, update the current offset */
-	if (ret >= 0)
-		fp->_offset += ret;
-	else
-		fp->_flags &= ~__SOFF;	/* paranoia */
-	return (ret);
-}
-
-int
-__swrite(void *cookie, const char *buf, int n)
-{
-	FILE *fp = cookie;
-
-	if (fp->_flags & __SAPP)
-		(void) lseek(fp->_file, (off_t)0, SEEK_END);
-	fp->_flags &= ~__SOFF;	/* in case FAPPEND mode is set */
-	return (write(fp->_file, buf, n));
-}
-
-fpos_t
-__sseek(void *cookie, fpos_t offset, int whence)
-{
-	FILE *fp = cookie;
-	off_t ret;
-
-	ret = lseek(fp->_file, (off_t)offset, whence);
-	if (ret == (off_t)-1)
-		fp->_flags &= ~__SOFF;
-	else {
-		fp->_flags |= __SOFF;
-		fp->_offset = ret;
-	}
-	return (ret);
-}
-
-int
-__sclose(void *cookie)
-{
-	return (close(((FILE *)cookie)->_file));
-}
diff --git a/libc/stdio/ungetc.c b/libc/stdio/ungetc.c
deleted file mode 100644
index b493d21..0000000
--- a/libc/stdio/ungetc.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/*	$OpenBSD: ungetc.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "local.h"
-
-static int __submore(FILE *);
-/*
- * Expand the ungetc buffer `in place'.  That is, adjust fp->_p when
- * the buffer moves, so that it points the same distance from the end,
- * and move the bytes in the buffer around as necessary so that they
- * are all at the end (stack-style).
- */
-static int
-__submore(FILE *fp)
-{
-	int i;
-	unsigned char *p;
-
-	if (_UB(fp)._base == fp->_ubuf) {
-		/*
-		 * Get a new buffer (rather than expanding the old one).
-		 */
-		if ((p = malloc((size_t)BUFSIZ)) == NULL)
-			return (EOF);
-		_UB(fp)._base = p;
-		_UB(fp)._size = BUFSIZ;
-		p += BUFSIZ - sizeof(fp->_ubuf);
-		for (i = sizeof(fp->_ubuf); --i >= 0;)
-			p[i] = fp->_ubuf[i];
-		fp->_p = p;
-		return (0);
-	}
-	i = _UB(fp)._size;
-	p = realloc(_UB(fp)._base, i << 1);
-	if (p == NULL)
-		return (EOF);
-	/* no overlap (hence can use memcpy) because we doubled the size */
-	(void)memcpy((void *)(p + i), (void *)p, (size_t)i);
-	fp->_p = p + i;
-	_UB(fp)._base = p;
-	_UB(fp)._size = i << 1;
-	return (0);
-}
-
-int
-ungetc(int c, FILE *fp)
-{
-	if (c == EOF)
-		return (EOF);
-	if (!__sdidinit)
-		__sinit();
-	FLOCKFILE(fp);
-	_SET_ORIENTATION(fp, -1);
-	if ((fp->_flags & __SRD) == 0) {
-		/*
-		 * Not already reading: no good unless reading-and-writing.
-		 * Otherwise, flush any current write stuff.
-		 */
-		if ((fp->_flags & __SRW) == 0) {
-error:			FUNLOCKFILE(fp);
-			return (EOF);
-		}
-		if (fp->_flags & __SWR) {
-			if (__sflush(fp))
-				goto error;
-			fp->_flags &= ~__SWR;
-			fp->_w = 0;
-			fp->_lbfsize = 0;
-		}
-		fp->_flags |= __SRD;
-	}
-	c = (unsigned char)c;
-
-	/*
-	 * If we are in the middle of ungetc'ing, just continue.
-	 * This may require expanding the current ungetc buffer.
-	 */
-	if (HASUB(fp)) {
-		if (fp->_r >= _UB(fp)._size && __submore(fp))
-			goto error;
-		*--fp->_p = c;
-inc_ret:	fp->_r++;
-		FUNLOCKFILE(fp);
-		return (c);
-	}
-	fp->_flags &= ~__SEOF;
-
-	/*
-	 * If we can handle this by simply backing up, do so,
-	 * but never replace the original character.
-	 * (This makes sscanf() work when scanning `const' data.)
-	 */
-	if (fp->_bf._base != NULL && fp->_p > fp->_bf._base &&
-	    fp->_p[-1] == c) {
-		fp->_p--;
-		goto inc_ret;
-	}
-
-	/*
-	 * Create an ungetc buffer.
-	 * Initially, we will use the `reserve' buffer.
-	 */
-	fp->_ur = fp->_r;
-	fp->_up = fp->_p;
-	_UB(fp)._base = fp->_ubuf;
-	_UB(fp)._size = sizeof(fp->_ubuf);
-	fp->_ubuf[sizeof(fp->_ubuf) - 1] = c;
-	fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1];
-	fp->_r = 1;
-	FUNLOCKFILE(fp);
-	return (c);
-}
diff --git a/libc/stdio/vasprintf.c b/libc/stdio/vasprintf.c
deleted file mode 100644
index 1630ccb..0000000
--- a/libc/stdio/vasprintf.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*	$OpenBSD: vasprintf.c,v 1.13 2006/01/06 18:53:04 millert Exp $	*/
-
-/*
- * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "local.h"
-
-int
-vasprintf(char **str, const char *fmt, __va_list ap)
-{
-	int ret;
-	FILE f;
-	struct __sfileext fext;
-	unsigned char *_base;
-
-	_FILEEXT_SETUP(&f, &fext);
-	f._file = -1;
-	f._flags = __SWR | __SSTR | __SALC;
-	f._bf._base = f._p = (unsigned char *)malloc(128);
-	if (f._bf._base == NULL)
-		goto err;
-	f._bf._size = f._w = 127;		/* Leave room for the NUL */
-	ret = __vfprintf(&f, fmt, ap);
-	if (ret == -1)
-		goto err;
-	*f._p = '\0';
-	_base = realloc(f._bf._base, ret + 1);
-	if (_base == NULL)
-		goto err;
-	*str = (char *)_base;
-	return (ret);
-
-err:
-	free(f._bf._base);
-	*str = NULL;
-	errno = ENOMEM;
-	return (-1);
-}
diff --git a/libc/stdio/vfprintf.c b/libc/stdio/vfprintf.c
deleted file mode 100644
index b101145..0000000
--- a/libc/stdio/vfprintf.c
+++ /dev/null
@@ -1,1329 +0,0 @@
-/*	$OpenBSD: vfprintf.c,v 1.37 2006/01/13 17:56:18 millert Exp $	*/
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Actual printf innards.
- *
- * This code is large and complicated...
- */
-
-#include <sys/types.h>
-#include <sys/mman.h>
-
-#include <errno.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "local.h"
-#include "fvwrite.h"
-
-static void __find_arguments(const char *fmt0, va_list ap, va_list **argtable,
-    size_t *argtablesiz);
-static int __grow_type_table(unsigned char **typetable, int *tablesize);
-
-/*
- * Flush out all the vectors defined by the given uio,
- * then reset it so that it can be reused.
- */
-static int
-__sprint(FILE *fp, struct __suio *uio)
-{
-	int err;
-
-	if (uio->uio_resid == 0) {
-		uio->uio_iovcnt = 0;
-		return (0);
-	}
-	err = __sfvwrite(fp, uio);
-	uio->uio_resid = 0;
-	uio->uio_iovcnt = 0;
-	return (err);
-}
-
-/*
- * Helper function for `fprintf to unbuffered unix file': creates a
- * temporary buffer.  We only work on write-only files; this avoids
- * worries about ungetc buffers and so forth.
- */
-static int
-__sbprintf(FILE *fp, const char *fmt, va_list ap)
-{
-	int ret;
-	FILE fake;
-	struct __sfileext fakeext;
-	unsigned char buf[BUFSIZ];
-
-	_FILEEXT_SETUP(&fake, &fakeext);
-	/* copy the important variables */
-	fake._flags = fp->_flags & ~__SNBF;
-	fake._file = fp->_file;
-	fake._cookie = fp->_cookie;
-	fake._write = fp->_write;
-
-	/* set up the buffer */
-	fake._bf._base = fake._p = buf;
-	fake._bf._size = fake._w = sizeof(buf);
-	fake._lbfsize = 0;	/* not actually used, but Just In Case */
-
-	/* do the work, then copy any error status */
-	ret = __vfprintf(&fake, fmt, ap);
-	if (ret >= 0 && __sflush(&fake))
-		ret = EOF;
-	if (fake._flags & __SERR)
-		fp->_flags |= __SERR;
-	return (ret);
-}
-
-
-#ifdef FLOATING_POINT
-#include <locale.h>
-#include <math.h>
-#include "floatio.h"
-
-#define	BUF		(MAXEXP+MAXFRACT+1)	/* + decimal point */
-#define	DEFPREC		6
-
-static char *cvt(double, int, int, char *, int *, int, int *);
-static int exponent(char *, int, int);
-#else /* no FLOATING_POINT */
-#define	BUF		40
-#endif /* FLOATING_POINT */
-
-#define STATIC_ARG_TBL_SIZE 8	/* Size of static argument table. */
-
-/* BIONIC: do not link libm for only two rather simple functions */
-#ifdef FLOATING_POINT
-static  int  _my_isinf(double);
-static  int  _my_isnan(double);
-#endif
-
-/*
- * Macros for converting digits to letters and vice versa
- */
-#define	to_digit(c)	((c) - '0')
-#define is_digit(c)	((unsigned)to_digit(c) <= 9)
-#define	to_char(n)	((n) + '0')
-
-/*
- * Flags used during conversion.
- */
-#define	ALT		0x0001		/* alternate form */
-#define	HEXPREFIX	0x0002		/* add 0x or 0X prefix */
-#define	LADJUST		0x0004		/* left adjustment */
-#define	LONGDBL		0x0008		/* long double; unimplemented */
-#define	LONGINT		0x0010		/* long integer */
-#define	LLONGINT	0x0020		/* long long integer */
-#define	SHORTINT	0x0040		/* short integer */
-#define	ZEROPAD		0x0080		/* zero (as opposed to blank) pad */
-#define FPT		0x0100		/* Floating point number */
-#define PTRINT		0x0200		/* (unsigned) ptrdiff_t */
-#define SIZEINT		0x0400		/* (signed) size_t */
-#define CHARINT		0x0800		/* 8 bit integer */
-#define MAXINT		0x1000		/* largest integer size (intmax_t) */
-
-int
-vfprintf(FILE *fp, const char *fmt0, __va_list ap)
-{
-	int ret;
-
-	FLOCKFILE(fp);
-	ret = __vfprintf(fp, fmt0, ap);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
-
-int
-__vfprintf(FILE *fp, const char *fmt0, __va_list ap)
-{
-	char *fmt;	/* format string */
-	int ch;	/* character from fmt */
-	int n, m, n2;	/* handy integers (short term usage) */
-	char *cp;	/* handy char pointer (short term usage) */
-	char *cp_free = NULL;  /* BIONIC: copy of cp to be freed after usage */
-	struct __siov *iovp;/* for PRINT macro */
-	int flags;	/* flags as above */
-	int ret;		/* return value accumulator */
-	int width;		/* width from format (%8d), or 0 */
-	int prec;		/* precision from format (%.3d), or -1 */
-	char sign;		/* sign prefix (' ', '+', '-', or \0) */
-	wchar_t wc;
-	void* ps;
-#ifdef FLOATING_POINT
-	char *decimal_point = ".";
-	char softsign;		/* temporary negative sign for floats */
-	double _double = 0.;	/* double precision arguments %[eEfgG] */
-	int expt;		/* integer value of exponent */
-	int expsize = 0;	/* character count for expstr */
-	int ndig;		/* actual number of digits returned by cvt */
-	char expstr[7];		/* buffer for exponent string */
-#endif
-
-	uintmax_t _umax;	/* integer arguments %[diouxX] */
-	enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
-	int dprec;		/* a copy of prec if [diouxX], 0 otherwise */
-	int realsz;		/* field size expanded by dprec */
-	int size;		/* size of converted field or string */
-	char* xdigs = NULL;		/* digits for [xX] conversion */
-#define NIOV 8
-	struct __suio uio;	/* output information: summary */
-	struct __siov iov[NIOV];/* ... and individual io vectors */
-	char buf[BUF];		/* space for %c, %[diouxX], %[eEfgG] */
-	char ox[2];		/* space for 0x hex-prefix */
-	va_list *argtable;	/* args, built due to positional arg */
-	va_list statargtable[STATIC_ARG_TBL_SIZE];
-	size_t argtablesiz;
-	int nextarg;		/* 1-based argument index */
-	va_list orgap;		/* original argument pointer */
-	/*
-	 * Choose PADSIZE to trade efficiency vs. size.  If larger printf
-	 * fields occur frequently, increase PADSIZE and make the initialisers
-	 * below longer.
-	 */
-#define	PADSIZE	16		/* pad chunk size */
-	static const char blanks[PADSIZE] =
-	 {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
-	static const char zeroes[PADSIZE] =
-	 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
-
-	/*
-	 * BEWARE, these `goto error' on error, and PAD uses `n'.
-	 */
-#define	PRINT(ptr, len) do { \
-	iovp->iov_base = (ptr); \
-	iovp->iov_len = (len); \
-	uio.uio_resid += (len); \
-	iovp++; \
-	if (++uio.uio_iovcnt >= NIOV) { \
-		if (__sprint(fp, &uio)) \
-			goto error; \
-		iovp = iov; \
-	} \
-} while (0)
-#define	PAD(howmany, with) do { \
-	if ((n = (howmany)) > 0) { \
-		while (n > PADSIZE) { \
-			PRINT(with, PADSIZE); \
-			n -= PADSIZE; \
-		} \
-		PRINT(with, n); \
-	} \
-} while (0)
-#define	FLUSH() do { \
-	if (uio.uio_resid && __sprint(fp, &uio)) \
-		goto error; \
-	uio.uio_iovcnt = 0; \
-	iovp = iov; \
-} while (0)
-
-	/*
-	 * To extend shorts properly, we need both signed and unsigned
-	 * argument extraction methods.
-	 */
-#define	SARG() \
-	((intmax_t)(flags&MAXINT ? GETARG(intmax_t) : \
-	    flags&LLONGINT ? GETARG(long long) : \
-	    flags&LONGINT ? GETARG(long) : \
-	    flags&PTRINT ? GETARG(ptrdiff_t) : \
-	    flags&SIZEINT ? GETARG(ssize_t) : \
-	    flags&SHORTINT ? (short)GETARG(int) : \
-	    flags&CHARINT ? (__signed char)GETARG(int) : \
-	    GETARG(int)))
-#define	UARG() \
-	((uintmax_t)(flags&MAXINT ? GETARG(uintmax_t) : \
-	    flags&LLONGINT ? GETARG(unsigned long long) : \
-	    flags&LONGINT ? GETARG(unsigned long) : \
-	    flags&PTRINT ? (uintptr_t)GETARG(ptrdiff_t) : /* XXX */ \
-	    flags&SIZEINT ? GETARG(size_t) : \
-	    flags&SHORTINT ? (unsigned short)GETARG(int) : \
-	    flags&CHARINT ? (unsigned char)GETARG(int) : \
-	    GETARG(unsigned int)))
-
-	 /*
-	  * Get * arguments, including the form *nn$.  Preserve the nextarg
-	  * that the argument can be gotten once the type is determined.
-	  */
-#define GETASTER(val) \
-	n2 = 0; \
-	cp = fmt; \
-	while (is_digit(*cp)) { \
-		n2 = 10 * n2 + to_digit(*cp); \
-		cp++; \
-	} \
-	if (*cp == '$') { \
-		int hold = nextarg; \
-		if (argtable == NULL) { \
-			argtable = statargtable; \
-			__find_arguments(fmt0, orgap, &argtable, &argtablesiz); \
-		} \
-		nextarg = n2; \
-		val = GETARG(int); \
-		nextarg = hold; \
-		fmt = ++cp; \
-	} else { \
-		val = GETARG(int); \
-	}
-
-/*
-* Get the argument indexed by nextarg.   If the argument table is
-* built, use it to get the argument.  If its not, get the next
-* argument (and arguments must be gotten sequentially).
-*/
-#define GETARG(type) \
-	(((argtable != NULL) ? (void)(ap = argtable[nextarg]) : (void)0), \
-	 nextarg++, va_arg(ap, type))
-
-	_SET_ORIENTATION(fp, -1);
-	/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
-	if (cantwrite(fp)) {
-		errno = EBADF;
-		return (EOF);
-	}
-
-	/* optimise fprintf(stderr) (and other unbuffered Unix files) */
-	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
-	    fp->_file >= 0)
-		return (__sbprintf(fp, fmt0, ap));
-
-	fmt = (char *)fmt0;
-	argtable = NULL;
-	nextarg = 1;
-	va_copy(orgap, ap);
-	uio.uio_iov = iovp = iov;
-	uio.uio_resid = 0;
-	uio.uio_iovcnt = 0;
-	ret = 0;
-
-	memset(&ps, 0, sizeof(ps));
-	/*
-	 * Scan the format for conversions (`%' character).
-	 */
-	for (;;) {
-		cp = fmt;
-#if 1  /* BIONIC */
-                n = -1;
-                while ( (wc = *fmt) != 0 ) {
-                    if (wc == '%') {
-                        n = 1;
-                        break;
-                    }
-                    fmt++;
-                }
-#else
-		while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) {
-			fmt += n;
-			if (wc == '%') {
-				fmt--;
-				break;
-			}
-		}
-#endif
-		if ((m = fmt - cp) != 0) {
-			PRINT(cp, m);
-			ret += m;
-		}
-		if (n <= 0)
-			goto done;
-		fmt++;		/* skip over '%' */
-
-		flags = 0;
-		dprec = 0;
-		width = 0;
-		prec = -1;
-		sign = '\0';
-
-rflag:		ch = *fmt++;
-reswitch:	switch (ch) {
-		case ' ':
-			/*
-			 * ``If the space and + flags both appear, the space
-			 * flag will be ignored.''
-			 *	-- ANSI X3J11
-			 */
-			if (!sign)
-				sign = ' ';
-			goto rflag;
-		case '#':
-			flags |= ALT;
-			goto rflag;
-		case '*':
-			/*
-			 * ``A negative field width argument is taken as a
-			 * - flag followed by a positive field width.''
-			 *	-- ANSI X3J11
-			 * They don't exclude field widths read from args.
-			 */
-			GETASTER(width);
-			if (width >= 0)
-				goto rflag;
-			width = -width;
-			/* FALLTHROUGH */
-		case '-':
-			flags |= LADJUST;
-			goto rflag;
-		case '+':
-			sign = '+';
-			goto rflag;
-		case '.':
-			if ((ch = *fmt++) == '*') {
-				GETASTER(n);
-				prec = n < 0 ? -1 : n;
-				goto rflag;
-			}
-			n = 0;
-			while (is_digit(ch)) {
-				n = 10 * n + to_digit(ch);
-				ch = *fmt++;
-			}
-			if (ch == '$') {
-				nextarg = n;
-				if (argtable == NULL) {
-					argtable = statargtable;
-					__find_arguments(fmt0, orgap,
-					    &argtable, &argtablesiz);
-				}
-				goto rflag;
-			}
-			prec = n < 0 ? -1 : n;
-			goto reswitch;
-		case '0':
-			/*
-			 * ``Note that 0 is taken as a flag, not as the
-			 * beginning of a field width.''
-			 *	-- ANSI X3J11
-			 */
-			flags |= ZEROPAD;
-			goto rflag;
-		case '1': case '2': case '3': case '4':
-		case '5': case '6': case '7': case '8': case '9':
-			n = 0;
-			do {
-				n = 10 * n + to_digit(ch);
-				ch = *fmt++;
-			} while (is_digit(ch));
-			if (ch == '$') {
-				nextarg = n;
-				if (argtable == NULL) {
-					argtable = statargtable;
-					__find_arguments(fmt0, orgap,
-					    &argtable, &argtablesiz);
-				}
-				goto rflag;
-			}
-			width = n;
-			goto reswitch;
-#ifdef FLOATING_POINT
-		case 'L':
-			flags |= LONGDBL;
-			goto rflag;
-#endif
-		case 'h':
-			if (*fmt == 'h') {
-				fmt++;
-				flags |= CHARINT;
-			} else {
-				flags |= SHORTINT;
-			}
-			goto rflag;
-		case 'j':
-			flags |= MAXINT;
-			goto rflag;
-		case 'l':
-			if (*fmt == 'l') {
-				fmt++;
-				flags |= LLONGINT;
-			} else {
-				flags |= LONGINT;
-			}
-			goto rflag;
-		case 'q':
-			flags |= LLONGINT;
-			goto rflag;
-		case 't':
-			flags |= PTRINT;
-			goto rflag;
-		case 'z':
-			flags |= SIZEINT;
-			goto rflag;
-		case 'c':
-			*(cp = buf) = GETARG(int);
-			size = 1;
-			sign = '\0';
-			break;
-		case 'D':
-			flags |= LONGINT;
-			/*FALLTHROUGH*/
-		case 'd':
-		case 'i':
-			_umax = SARG();
-			if ((intmax_t)_umax < 0) {
-				_umax = -_umax;
-				sign = '-';
-			}
-			base = DEC;
-			goto number;
-#ifdef FLOATING_POINT
-		case 'e':
-		case 'E':
-		case 'f':
-		case 'g':
-		case 'G':
-			if (prec == -1) {
-				prec = DEFPREC;
-			} else if ((ch == 'g' || ch == 'G') && prec == 0) {
-				prec = 1;
-			}
-
-			if (flags & LONGDBL) {
-				_double = (double) GETARG(long double);
-			} else {
-				_double = GETARG(double);
-			}
-
-			/* do this before tricky precision changes */
-			if (_my_isinf(_double)) {
-				if (_double < 0)
-					sign = '-';
-				cp = "Inf";
-				size = 3;
-				break;
-			}
-			if (_my_isnan(_double)) {
-				cp = "NaN";
-				size = 3;
-				break;
-			}
-
-			flags |= FPT;
-			cp = cvt(_double, prec, flags, &softsign,
-				&expt, ch, &ndig);
-		    cp_free = cp;
-			if (ch == 'g' || ch == 'G') {
-				if (expt <= -4 || expt > prec)
-					ch = (ch == 'g') ? 'e' : 'E';
-				else
-					ch = 'g';
-			}
-			if (ch <= 'e') {	/* 'e' or 'E' fmt */
-				--expt;
-				expsize = exponent(expstr, expt, ch);
-				size = expsize + ndig;
-				if (ndig > 1 || flags & ALT)
-					++size;
-			} else if (ch == 'f') {		/* f fmt */
-				if (expt > 0) {
-					size = expt;
-					if (prec || flags & ALT)
-						size += prec + 1;
-				} else	/* "0.X" */
-					size = prec + 2;
-			} else if (expt >= ndig) {	/* fixed g fmt */
-				size = expt;
-				if (flags & ALT)
-					++size;
-			} else
-				size = ndig + (expt > 0 ?
-					1 : 2 - expt);
-
-			if (softsign)
-				sign = '-';
-			break;
-#endif /* FLOATING_POINT */
-/* the Android security team suggests removing support for %n
- * since it has no real practical value, and could lead to
- * running malicious code (for really buggy programs that
- * send to printf() user-generated formatting strings).
- */
-#if 0
-		case 'n':
-			if (flags & LLONGINT)
-				*GETARG(long long *) = ret;
-			else if (flags & LONGINT)
-				*GETARG(long *) = ret;
-			else if (flags & SHORTINT)
-				*GETARG(short *) = ret;
-			else if (flags & CHARINT)
-				*GETARG(__signed char *) = ret;
-			else if (flags & PTRINT)
-				*GETARG(ptrdiff_t *) = ret;
-			else if (flags & SIZEINT)
-				*GETARG(ssize_t *) = ret;
-			else if (flags & MAXINT)
-				*GETARG(intmax_t *) = ret;
-			else
-				*GETARG(int *) = ret;
-			continue;	/* no output */
-#endif
-		case 'O':
-			flags |= LONGINT;
-			/*FALLTHROUGH*/
-		case 'o':
-			_umax = UARG();
-			base = OCT;
-			goto nosign;
-		case 'p':
-			/*
-			 * ``The argument shall be a pointer to void.  The
-			 * value of the pointer is converted to a sequence
-			 * of printable characters, in an implementation-
-			 * defined manner.''
-			 *	-- ANSI X3J11
-			 */
-			/* NOSTRICT */
-			_umax = (u_long)GETARG(void *);
-			base = HEX;
-			xdigs = "0123456789abcdef";
-			flags |= HEXPREFIX;
-			ch = 'x';
-			goto nosign;
-		case 's':
-			if ((cp = GETARG(char *)) == NULL)
-				cp = "(null)";
-			if (prec >= 0) {
-				/*
-				 * can't use strlen; can only look for the
-				 * NUL in the first `prec' characters, and
-				 * strlen() will go further.
-				 */
-				char *p = memchr(cp, 0, prec);
-
-				if (p != NULL) {
-					size = p - cp;
-					if (size > prec)
-						size = prec;
-				} else
-					size = prec;
-			} else
-				size = strlen(cp);
-			sign = '\0';
-			break;
-		case 'U':
-			flags |= LONGINT;
-			/*FALLTHROUGH*/
-		case 'u':
-			_umax = UARG();
-			base = DEC;
-			goto nosign;
-		case 'X':
-			xdigs = "0123456789ABCDEF";
-			goto hex;
-		case 'x':
-			xdigs = "0123456789abcdef";
-hex:			_umax = UARG();
-			base = HEX;
-			/* leading 0x/X only if non-zero */
-			if (flags & ALT && _umax != 0)
-				flags |= HEXPREFIX;
-
-			/* unsigned conversions */
-nosign:			sign = '\0';
-			/*
-			 * ``... diouXx conversions ... if a precision is
-			 * specified, the 0 flag will be ignored.''
-			 *	-- ANSI X3J11
-			 */
-number:			if ((dprec = prec) >= 0)
-				flags &= ~ZEROPAD;
-
-			/*
-			 * ``The result of converting a zero value with an
-			 * explicit precision of zero is no characters.''
-			 *	-- ANSI X3J11
-			 */
-			cp = buf + BUF;
-			if (_umax != 0 || prec != 0) {
-				/*
-				 * Unsigned mod is hard, and unsigned mod
-				 * by a constant is easier than that by
-				 * a variable; hence this switch.
-				 */
-				switch (base) {
-				case OCT:
-					do {
-						*--cp = to_char(_umax & 7);
-						_umax >>= 3;
-					} while (_umax);
-					/* handle octal leading 0 */
-					if (flags & ALT && *cp != '0')
-						*--cp = '0';
-					break;
-
-				case DEC:
-					/* many numbers are 1 digit */
-					while (_umax >= 10) {
-						*--cp = to_char(_umax % 10);
-						_umax /= 10;
-					}
-					*--cp = to_char(_umax);
-					break;
-
-				case HEX:
-					do {
-						*--cp = xdigs[_umax & 15];
-						_umax >>= 4;
-					} while (_umax);
-					break;
-
-				default:
-					cp = "bug in vfprintf: bad base";
-					size = strlen(cp);
-					goto skipsize;
-				}
-			}
-			size = buf + BUF - cp;
-		skipsize:
-			break;
-		default:	/* "%?" prints ?, unless ? is NUL */
-			if (ch == '\0')
-				goto done;
-			/* pretend it was %c with argument ch */
-			cp = buf;
-			*cp = ch;
-			size = 1;
-			sign = '\0';
-			break;
-		}
-
-		/*
-		 * All reasonable formats wind up here.  At this point, `cp'
-		 * points to a string which (if not flags&LADJUST) should be
-		 * padded out to `width' places.  If flags&ZEROPAD, it should
-		 * first be prefixed by any sign or other prefix; otherwise,
-		 * it should be blank padded before the prefix is emitted.
-		 * After any left-hand padding and prefixing, emit zeroes
-		 * required by a decimal [diouxX] precision, then print the
-		 * string proper, then emit zeroes required by any leftover
-		 * floating precision; finally, if LADJUST, pad with blanks.
-		 *
-		 * Compute actual size, so we know how much to pad.
-		 * size excludes decimal prec; realsz includes it.
-		 */
-		realsz = dprec > size ? dprec : size;
-		if (sign)
-			realsz++;
-		else if (flags & HEXPREFIX)
-			realsz+= 2;
-
-		/* right-adjusting blank padding */
-		if ((flags & (LADJUST|ZEROPAD)) == 0)
-			PAD(width - realsz, blanks);
-
-		/* prefix */
-		if (sign) {
-			PRINT(&sign, 1);
-		} else if (flags & HEXPREFIX) {
-			ox[0] = '0';
-			ox[1] = ch;
-			PRINT(ox, 2);
-		}
-
-		/* right-adjusting zero padding */
-		if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
-			PAD(width - realsz, zeroes);
-
-		/* leading zeroes from decimal precision */
-		PAD(dprec - size, zeroes);
-
-		/* the string or number proper */
-#ifdef FLOATING_POINT
-		if ((flags & FPT) == 0) {
-			PRINT(cp, size);
-		} else {	/* glue together f_p fragments */
-			if (ch >= 'f') {	/* 'f' or 'g' */
-				if (_double == 0) {
-					/* kludge for __dtoa irregularity */
-					PRINT("0", 1);
-					if (expt < ndig || (flags & ALT) != 0) {
-						PRINT(decimal_point, 1);
-						PAD(ndig - 1, zeroes);
-					}
-				} else if (expt <= 0) {
-					PRINT("0", 1);
-					PRINT(decimal_point, 1);
-					PAD(-expt, zeroes);
-					PRINT(cp, ndig);
-				} else if (expt >= ndig) {
-					PRINT(cp, ndig);
-					PAD(expt - ndig, zeroes);
-					if (flags & ALT)
-						PRINT(".", 1);
-				} else {
-					PRINT(cp, expt);
-					cp += expt;
-					PRINT(".", 1);
-					PRINT(cp, ndig-expt);
-				}
-			} else {	/* 'e' or 'E' */
-				if (ndig > 1 || flags & ALT) {
-					ox[0] = *cp++;
-					ox[1] = '.';
-					PRINT(ox, 2);
-					if (_double) {
-						PRINT(cp, ndig-1);
-					} else	/* 0.[0..] */
-						/* __dtoa irregularity */
-						PAD(ndig - 1, zeroes);
-				} else	/* XeYYY */
-					PRINT(cp, 1);
-				PRINT(expstr, expsize);
-			}
-		}
-#else
-		PRINT(cp, size);
-#endif
-		/* left-adjusting padding (always blank) */
-		if (flags & LADJUST)
-			PAD(width - realsz, blanks);
-
-		/* finally, adjust ret */
-		ret += width > realsz ? width : realsz;
-
-		FLUSH();	/* copy out the I/O vectors */
-#if 1   /* BIONIC: remove memory leak when printing doubles */
-		if (cp_free) {
-		  free(cp_free);
-		  cp_free = NULL;
-		}
-#endif
-	}
-done:
-	FLUSH();
-error:
-#if 1   /* BIONIC: remove memory leak when printing doubles */
-    if (cp_free) {
-        free(cp_free);
-        cp_free = NULL;
-    }
-#endif
-	if (argtable != NULL && argtable != statargtable) {
-		munmap(argtable, argtablesiz);
-		argtable = NULL;
-	}
-        va_end(orgap);
-	return (__sferror(fp) ? EOF : ret);
-	/* NOTREACHED */
-}
-
-/*
- * Type ids for argument type table.
- */
-#define T_UNUSED	0
-#define T_SHORT		1
-#define T_U_SHORT	2
-#define TP_SHORT	3
-#define T_INT		4
-#define T_U_INT		5
-#define TP_INT		6
-#define T_LONG		7
-#define T_U_LONG	8
-#define TP_LONG		9
-#define T_LLONG		10
-#define T_U_LLONG	11
-#define TP_LLONG	12
-#define T_DOUBLE	13
-#define T_LONG_DOUBLE	14
-#define TP_CHAR		15
-#define TP_VOID		16
-#define T_PTRINT	17
-#define TP_PTRINT	18
-#define T_SIZEINT	19
-#define T_SSIZEINT	20
-#define TP_SSIZEINT	21
-#define T_MAXINT	22
-#define T_MAXUINT	23
-#define TP_MAXINT	24
-
-/*
- * Find all arguments when a positional parameter is encountered.  Returns a
- * table, indexed by argument number, of pointers to each arguments.  The
- * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
- * It will be replaced with a mmap-ed one if it overflows (malloc cannot be
- * used since we are attempting to make snprintf thread safe, and alloca is
- * problematic since we have nested functions..)
- */
-static void
-__find_arguments(const char *fmt0, va_list ap, va_list **argtable,
-    size_t *argtablesiz)
-{
-	char *fmt;	/* format string */
-	int ch;	/* character from fmt */
-	int n, n2;	/* handy integer (short term usage) */
-	char *cp;	/* handy char pointer (short term usage) */
-	int flags;	/* flags as above */
-	unsigned char *typetable; /* table of types */
-	unsigned char stattypetable[STATIC_ARG_TBL_SIZE];
-	int tablesize;		/* current size of type table */
-	int tablemax;		/* largest used index in table */
-	int nextarg;		/* 1-based argument index */
-	wchar_t wc;
-	void* ps;
-
-	/*
-	 * Add an argument type to the table, expanding if necessary.
-	 */
-#define ADDTYPE(type) \
-	((nextarg >= tablesize) ? \
-		__grow_type_table(&typetable, &tablesize) : 0, \
-	(nextarg > tablemax) ? tablemax = nextarg : 0, \
-	typetable[nextarg++] = type)
-
-#define	ADDSARG() \
-        ((flags&MAXINT) ? ADDTYPE(T_MAXINT) : \
-	    ((flags&PTRINT) ? ADDTYPE(T_PTRINT) : \
-	    ((flags&SIZEINT) ? ADDTYPE(T_SSIZEINT) : \
-	    ((flags&LLONGINT) ? ADDTYPE(T_LLONG) : \
-	    ((flags&LONGINT) ? ADDTYPE(T_LONG) : \
-	    ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT)))))))
-
-#define	ADDUARG() \
-        ((flags&MAXINT) ? ADDTYPE(T_MAXUINT) : \
-	    ((flags&PTRINT) ? ADDTYPE(T_PTRINT) : \
-	    ((flags&SIZEINT) ? ADDTYPE(T_SIZEINT) : \
-	    ((flags&LLONGINT) ? ADDTYPE(T_U_LLONG) : \
-	    ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \
-	    ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT)))))))
-
-	/*
-	 * Add * arguments to the type array.
-	 */
-#define ADDASTER() \
-	n2 = 0; \
-	cp = fmt; \
-	while (is_digit(*cp)) { \
-		n2 = 10 * n2 + to_digit(*cp); \
-		cp++; \
-	} \
-	if (*cp == '$') { \
-		int hold = nextarg; \
-		nextarg = n2; \
-		ADDTYPE(T_INT); \
-		nextarg = hold; \
-		fmt = ++cp; \
-	} else { \
-		ADDTYPE(T_INT); \
-	}
-	fmt = (char *)fmt0;
-	typetable = stattypetable;
-	tablesize = STATIC_ARG_TBL_SIZE;
-	tablemax = 0;
-	nextarg = 1;
-	memset(typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
-	memset(&ps, 0, sizeof(ps));
-
-	/*
-	 * Scan the format for conversions (`%' character).
-	 */
-	for (;;) {
-		cp = fmt;
-#if 1  /* BIONIC */
-                n = -1;
-                while ((wc = *fmt) != 0) {
-                    if (wc == '%') {
-                        n = 1;
-                        break;
-                    }
-                    fmt++;
-                }
-#else
-		while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) {
-			fmt += n;
-			if (wc == '%') {
-				fmt--;
-				break;
-			}
-		}
-#endif
-		if (n <= 0)
-			goto done;
-		fmt++;		/* skip over '%' */
-
-		flags = 0;
-
-rflag:		ch = *fmt++;
-reswitch:	switch (ch) {
-		case ' ':
-		case '#':
-			goto rflag;
-		case '*':
-			ADDASTER();
-			goto rflag;
-		case '-':
-		case '+':
-			goto rflag;
-		case '.':
-			if ((ch = *fmt++) == '*') {
-				ADDASTER();
-				goto rflag;
-			}
-			while (is_digit(ch)) {
-				ch = *fmt++;
-			}
-			goto reswitch;
-		case '0':
-			goto rflag;
-		case '1': case '2': case '3': case '4':
-		case '5': case '6': case '7': case '8': case '9':
-			n = 0;
-			do {
-				n = 10 * n + to_digit(ch);
-				ch = *fmt++;
-			} while (is_digit(ch));
-			if (ch == '$') {
-				nextarg = n;
-				goto rflag;
-			}
-			goto reswitch;
-#ifdef FLOATING_POINT
-		case 'L':
-			flags |= LONGDBL;
-			goto rflag;
-#endif
-		case 'h':
-			if (*fmt == 'h') {
-				fmt++;
-				flags |= CHARINT;
-			} else {
-				flags |= SHORTINT;
-			}
-			goto rflag;
-		case 'l':
-			if (*fmt == 'l') {
-				fmt++;
-				flags |= LLONGINT;
-			} else {
-				flags |= LONGINT;
-			}
-			goto rflag;
-		case 'q':
-			flags |= LLONGINT;
-			goto rflag;
-		case 't':
-			flags |= PTRINT;
-			goto rflag;
-		case 'z':
-			flags |= SIZEINT;
-			goto rflag;
-		case 'c':
-			ADDTYPE(T_INT);
-			break;
-		case 'D':
-			flags |= LONGINT;
-			/*FALLTHROUGH*/
-		case 'd':
-		case 'i':
-			ADDSARG();
-			break;
-#ifdef FLOATING_POINT
-		case 'e':
-		case 'E':
-		case 'f':
-		case 'g':
-		case 'G':
-			if (flags & LONGDBL)
-				ADDTYPE(T_LONG_DOUBLE);
-			else
-				ADDTYPE(T_DOUBLE);
-			break;
-#endif /* FLOATING_POINT */
-		case 'n':
-			if (flags & LLONGINT)
-				ADDTYPE(TP_LLONG);
-			else if (flags & LONGINT)
-				ADDTYPE(TP_LONG);
-			else if (flags & SHORTINT)
-				ADDTYPE(TP_SHORT);
-			else if (flags & PTRINT)
-				ADDTYPE(TP_PTRINT);
-			else if (flags & SIZEINT)
-				ADDTYPE(TP_SSIZEINT);
-			else if (flags & MAXINT)
-				ADDTYPE(TP_MAXINT);
-			else
-				ADDTYPE(TP_INT);
-			continue;	/* no output */
-		case 'O':
-			flags |= LONGINT;
-			/*FALLTHROUGH*/
-		case 'o':
-			ADDUARG();
-			break;
-		case 'p':
-			ADDTYPE(TP_VOID);
-			break;
-		case 's':
-			ADDTYPE(TP_CHAR);
-			break;
-		case 'U':
-			flags |= LONGINT;
-			/*FALLTHROUGH*/
-		case 'u':
-		case 'X':
-		case 'x':
-			ADDUARG();
-			break;
-		default:	/* "%?" prints ?, unless ? is NUL */
-			if (ch == '\0')
-				goto done;
-			break;
-		}
-	}
-done:
-	/*
-	 * Build the argument table.
-	 */
-	if (tablemax >= STATIC_ARG_TBL_SIZE) {
-		*argtablesiz = sizeof (va_list) * (tablemax + 1);
-		*argtable = (va_list *)mmap(NULL, *argtablesiz,
-		    PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0);
-	}
-
-#if 0
-	/* XXX is this required? */
-	(*argtable) [0] = NULL;
-#endif
-	for (n = 1; n <= tablemax; n++) {
-		va_copy((*argtable)[n], ap);
-		switch (typetable[n]) {
-		case T_UNUSED:
-			(void) va_arg(ap, int);
-			break;
-		case T_SHORT:
-			(void) va_arg(ap, int);
-			break;
-		case T_U_SHORT:
-			(void) va_arg(ap, int);
-			break;
-		case TP_SHORT:
-			(void) va_arg(ap, short *);
-			break;
-		case T_INT:
-			(void) va_arg(ap, int);
-			break;
-		case T_U_INT:
-			(void) va_arg(ap, unsigned int);
-			break;
-		case TP_INT:
-			(void) va_arg(ap, int *);
-			break;
-		case T_LONG:
-			(void) va_arg(ap, long);
-			break;
-		case T_U_LONG:
-			(void) va_arg(ap, unsigned long);
-			break;
-		case TP_LONG:
-			(void) va_arg(ap, long *);
-			break;
-		case T_LLONG:
-			(void) va_arg(ap, long long);
-			break;
-		case T_U_LLONG:
-			(void) va_arg(ap, unsigned long long);
-			break;
-		case TP_LLONG:
-			(void) va_arg(ap, long long *);
-			break;
-		case T_DOUBLE:
-			(void) va_arg(ap, double);
-			break;
-		case T_LONG_DOUBLE:
-			(void) va_arg(ap, long double);
-			break;
-		case TP_CHAR:
-			(void) va_arg(ap, char *);
-			break;
-		case TP_VOID:
-			(void) va_arg(ap, void *);
-			break;
-		case T_PTRINT:
-			(void) va_arg(ap, ptrdiff_t);
-			break;
-		case TP_PTRINT:
-			(void) va_arg(ap, ptrdiff_t *);
-			break;
-		case T_SIZEINT:
-			(void) va_arg(ap, size_t);
-			break;
-		case T_SSIZEINT:
-			(void) va_arg(ap, ssize_t);
-			break;
-		case TP_SSIZEINT:
-			(void) va_arg(ap, ssize_t *);
-			break;
-		case TP_MAXINT:
-			(void) va_arg(ap, intmax_t *);
-			break;
-		}
-	}
-
-	if (typetable != NULL && typetable != stattypetable) {
-		munmap(typetable, *argtablesiz);
-		typetable = NULL;
-	}
-}
-
-/*
- * Increase the size of the type table.
- */
-static int
-__grow_type_table(unsigned char **typetable, int *tablesize)
-{
-	unsigned char *oldtable = *typetable;
-	int newsize = *tablesize * 2;
-
-	if (*tablesize == STATIC_ARG_TBL_SIZE) {
-		*typetable = (unsigned char *)mmap(NULL,
-		    sizeof (unsigned char) * newsize, PROT_WRITE|PROT_READ,
-		    MAP_ANON|MAP_PRIVATE, -1, 0);
-		/* XXX unchecked */
-		memcpy( *typetable, oldtable, *tablesize);
-	} else {
-		unsigned char *new = (unsigned char *)mmap(NULL,
-		    sizeof (unsigned char) * newsize, PROT_WRITE|PROT_READ,
-		    MAP_ANON|MAP_PRIVATE, -1, 0);
-		memmove(new, *typetable, *tablesize);
-		munmap(*typetable, *tablesize);
-		*typetable = new;
-		/* XXX unchecked */
-	}
-	memset(*typetable + *tablesize, T_UNUSED, (newsize - *tablesize));
-
-	*tablesize = newsize;
-	return(0);
-}
-
-
-#ifdef FLOATING_POINT
-
-extern char *__dtoa(double, int, int, int *, int *, char **);
-
-static char *
-cvt(double value, int ndigits, int flags, char *sign, int *decpt, int ch,
-    int *length)
-{
-	int mode, dsgn;
-	char *digits, *bp, *rve;
-
-	if (ch == 'f') {
-		mode = 3;		/* ndigits after the decimal point */
-	} else {
-		/* To obtain ndigits after the decimal point for the 'e'
-		 * and 'E' formats, round to ndigits + 1 significant
-		 * figures.
-		 */
-		if (ch == 'e' || ch == 'E') {
-			ndigits++;
-		}
-		mode = 2;		/* ndigits significant digits */
-	}
-
-	if (value < 0) {
-		value = -value;
-		*sign = '-';
-	} else
-		*sign = '\000';
-	digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
-	if ((ch != 'g' && ch != 'G') || flags & ALT) {	/* Print trailing zeros */
-		bp = digits + ndigits;
-		if (ch == 'f') {
-			if (*digits == '0' && value)
-				*decpt = -ndigits + 1;
-			bp += *decpt;
-		}
-		if (value == 0)	/* kludge for __dtoa irregularity */
-			rve = bp;
-		while (rve < bp)
-			*rve++ = '0';
-	}
-	*length = rve - digits;
-	return (digits);
-}
-
-static int
-exponent(char *p0, int exp, int fmtch)
-{
-	char *p, *t;
-	char expbuf[MAXEXP];
-
-	p = p0;
-	*p++ = fmtch;
-	if (exp < 0) {
-		exp = -exp;
-		*p++ = '-';
-	}
-	else
-		*p++ = '+';
-	t = expbuf + MAXEXP;
-	if (exp > 9) {
-		do {
-			*--t = to_char(exp % 10);
-		} while ((exp /= 10) > 9);
-		*--t = to_char(exp);
-		for (; t < expbuf + MAXEXP; *p++ = *t++);
-	}
-	else {
-		*p++ = '0';
-		*p++ = to_char(exp);
-	}
-	return (p - p0);
-}
-
-
-/* BIONIC */
-#include <machine/ieee.h>
-typedef union {
-    double              d;
-    struct ieee_double  i;
-} ieee_u;
-
-static int
-_my_isinf (double  value)
-{
-    ieee_u   u;
-
-    u.d = value;
-    return (u.i.dbl_exp == 2047 && u.i.dbl_frach == 0 && u.i.dbl_fracl == 0);
-}
-
-static int
-_my_isnan (double  value)
-{
-    ieee_u   u;
-
-    u.d = value;
-    return (u.i.dbl_exp == 2047 && (u.i.dbl_frach != 0 || u.i.dbl_fracl != 0));
-}
-#endif /* FLOATING_POINT */
diff --git a/libc/stdio/vfscanf.c b/libc/stdio/vfscanf.c
deleted file mode 100644
index 78f404e..0000000
--- a/libc/stdio/vfscanf.c
+++ /dev/null
@@ -1,803 +0,0 @@
-/*	$OpenBSD: vfscanf.c,v 1.21 2006/01/13 21:33:28 millert Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <ctype.h>
-#include <inttypes.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "local.h"
-
-#ifdef FLOATING_POINT
-#include "floatio.h"
-#endif
-
-#define	BUF		513	/* Maximum length of numeric string. */
-
-/*
- * Flags used during conversion.
- */
-#define	LONG		0x00001	/* l: long or double */
-#define	LONGDBL		0x00002	/* L: long double; unimplemented */
-#define	SHORT		0x00004	/* h: short */
-#define	SHORTSHORT	0x00008	/* hh: 8 bit integer */
-#define LLONG		0x00010	/* ll: long long (+ deprecated q: quad) */
-#define	POINTER		0x00020	/* p: void * (as hex) */
-#define	SIZEINT		0x00040	/* z: (signed) size_t */
-#define	MAXINT		0x00080	/* j: intmax_t */
-#define	PTRINT		0x00100	/* t: ptrdiff_t */
-#define	NOSKIP		0x00200	/* [ or c: do not skip blanks */
-#define	SUPPRESS	0x00400	/* *: suppress assignment */
-#define	UNSIGNED	0x00800	/* %[oupxX] conversions */
-
-/*
- * The following are used in numeric conversions only:
- * SIGNOK, HAVESIGN, NDIGITS, DPTOK, and EXPOK are for floating point;
- * SIGNOK, HAVESIGN, NDIGITS, PFXOK, and NZDIGITS are for integral.
- */
-#define	SIGNOK		0x01000	/* +/- is (still) legal */
-#define	HAVESIGN	0x02000	/* sign detected */
-#define	NDIGITS		0x04000	/* no digits detected */
-
-#define	DPTOK		0x08000	/* (float) decimal point is still legal */
-#define	EXPOK		0x10000	/* (float) exponent (e+3, etc) still legal */
-
-#define	PFXOK		0x08000	/* 0x prefix is (still) legal */
-#define	NZDIGITS	0x10000	/* no zero digits detected */
-
-/*
- * Conversion types.
- */
-#define	CT_CHAR		0	/* %c conversion */
-#define	CT_CCL		1	/* %[...] conversion */
-#define	CT_STRING	2	/* %s conversion */
-#define	CT_INT		3	/* integer, i.e., strtoimax or strtoumax */
-#define	CT_FLOAT	4	/* floating, i.e., strtod */
-
-#define u_char unsigned char
-#define u_long unsigned long
-
-static u_char *__sccl(char *, u_char *);
-
-#if !defined(VFSCANF)
-#define VFSCANF	vfscanf
-#endif
-
-/*
- * vfscanf
- */
-int
-VFSCANF(FILE *fp, const char *fmt0, __va_list ap)
-{
-	u_char *fmt = (u_char *)fmt0;
-	int c;		/* character from format, or conversion */
-	size_t width;	/* field width, or 0 */
-	char *p;	/* points into all kinds of strings */
-	int n;		/* handy integer */
-	int flags;	/* flags as defined above */
-	char *p0;	/* saves original value of p when necessary */
-	int nassigned;		/* number of fields assigned */
-	int nread;		/* number of characters consumed from fp */
-	int base;		/* base argument to strtoimax/strtouimax */
-	char ccltab[256];	/* character class table for %[...] */
-	char buf[BUF];		/* buffer for numeric conversions */
-
-	/* `basefix' is used to avoid `if' tests in the integer scanner */
-	static short basefix[17] =
-		{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
-
-	FLOCKFILE(fp);
-	_SET_ORIENTATION(fp, -1);
-
-	nassigned = 0;
-	nread = 0;
-	base = 0;		/* XXX just to keep gcc happy */
-	for (;;) {
-		c = *fmt++;
-		if (c == 0) {
-			FUNLOCKFILE(fp);
-			return (nassigned);
-		}
-		if (isspace(c)) {
-			while ((fp->_r > 0 || __srefill(fp) == 0) &&
-			    isspace(*fp->_p))
-				nread++, fp->_r--, fp->_p++;
-			continue;
-		}
-		if (c != '%')
-			goto literal;
-		width = 0;
-		flags = 0;
-		/*
-		 * switch on the format.  continue if done;
-		 * break once format type is derived.
-		 */
-again:		c = *fmt++;
-		switch (c) {
-		case '%':
-literal:
-			if (fp->_r <= 0 && __srefill(fp))
-				goto input_failure;
-			if (*fp->_p != c)
-				goto match_failure;
-			fp->_r--, fp->_p++;
-			nread++;
-			continue;
-
-		case '*':
-			flags |= SUPPRESS;
-			goto again;
-		case 'j':
-			flags |= MAXINT;
-			goto again;
-		case 'L':
-			flags |=
-				(*fmt == 'd') ? LLONG :
-				(*fmt == 'i') ? LLONG :
-				(*fmt == 'o') ? LLONG :
-				(*fmt == 'u') ? LLONG :
-				(*fmt == 'x') ? LLONG :
-				LONGDBL;
-			goto again;
-		case 'h':
-			if (*fmt == 'h') {
-				fmt++;
-				flags |= SHORTSHORT;
-			} else {
-				flags |= SHORT;
-			}
-			goto again;
-		case 'l':
-			if (*fmt == 'l') {
-				fmt++;
-				flags |= LLONG;
-			} else {
-				flags |= LONG;
-			}
-			goto again;
-		case 'q':
-			flags |= LLONG;		/* deprecated */
-			goto again;
-		case 't':
-			flags |= PTRINT;
-			goto again;
-		case 'z':
-			flags |= SIZEINT;
-			goto again;
-
-		case '0': case '1': case '2': case '3': case '4':
-		case '5': case '6': case '7': case '8': case '9':
-			width = width * 10 + c - '0';
-			goto again;
-
-		/*
-		 * Conversions.
-		 * Those marked `compat' are for 4.[123]BSD compatibility.
-		 *
-		 * (According to ANSI, E and X formats are supposed
-		 * to the same as e and x.  Sorry about that.)
-		 */
-		case 'D':	/* compat */
-			flags |= LONG;
-			/* FALLTHROUGH */
-		case 'd':
-			c = CT_INT;
-			base = 10;
-			break;
-
-		case 'i':
-			c = CT_INT;
-			base = 0;
-			break;
-
-		case 'O':	/* compat */
-			flags |= LONG;
-			/* FALLTHROUGH */
-		case 'o':
-			c = CT_INT;
-			flags |= UNSIGNED;
-			base = 8;
-			break;
-
-		case 'u':
-			c = CT_INT;
-			flags |= UNSIGNED;
-			base = 10;
-			break;
-
-		case 'X':
-		case 'x':
-			flags |= PFXOK;	/* enable 0x prefixing */
-			c = CT_INT;
-			flags |= UNSIGNED;
-			base = 16;
-			break;
-
-#ifdef FLOATING_POINT
-		case 'E':
-		case 'G':
-		case 'e': 
-		case 'f': 
-		case 'g':
-			c = CT_FLOAT;
-			break;
-#endif
-
-		case 's':
-			c = CT_STRING;
-			break;
-
-		case '[':
-			fmt = __sccl(ccltab, fmt);
-			flags |= NOSKIP;
-			c = CT_CCL;
-			break;
-
-		case 'c':
-			flags |= NOSKIP;
-			c = CT_CHAR;
-			break;
-
-		case 'p':	/* pointer format is like hex */
-			flags |= POINTER | PFXOK;
-			c = CT_INT;
-			flags |= UNSIGNED;
-			base = 16;
-			break;
-
-		case 'n':
-			if (flags & SUPPRESS)
-				continue;
-			if (flags & SHORTSHORT)
-				*va_arg(ap, __signed char *) = nread;
-			else if (flags & SHORT)
-				*va_arg(ap, short *) = nread;
-			else if (flags & LONG)
-				*va_arg(ap, long *) = nread;
-			else if (flags & SIZEINT)
-				*va_arg(ap, ssize_t *) = nread;
-			else if (flags & PTRINT)
-				*va_arg(ap, ptrdiff_t *) = nread;
-			else if (flags & LLONG)
-				*va_arg(ap, long long *) = nread;
-			else if (flags & MAXINT)
-				*va_arg(ap, intmax_t *) = nread;
-			else
-				*va_arg(ap, int *) = nread;
-			continue;
-
-		/*
-		 * Disgusting backwards compatibility hacks.	XXX
-		 */
-		case '\0':	/* compat */
-			FUNLOCKFILE(fp);
-			return (EOF);
-
-		default:	/* compat */
-			if (isupper(c))
-				flags |= LONG;
-			c = CT_INT;
-			base = 10;
-			break;
-		}
-
-		/*
-		 * We have a conversion that requires input.
-		 */
-		if (fp->_r <= 0 && __srefill(fp))
-			goto input_failure;
-
-		/*
-		 * Consume leading white space, except for formats
-		 * that suppress this.
-		 */
-		if ((flags & NOSKIP) == 0) {
-			while (isspace(*fp->_p)) {
-				nread++;
-				if (--fp->_r > 0)
-					fp->_p++;
-				else if (__srefill(fp))
-					goto input_failure;
-			}
-			/*
-			 * Note that there is at least one character in
-			 * the buffer, so conversions that do not set NOSKIP
-			 * ca no longer result in an input failure.
-			 */
-		}
-
-		/*
-		 * Do the conversion.
-		 */
-		switch (c) {
-
-		case CT_CHAR:
-			/* scan arbitrary characters (sets NOSKIP) */
-			if (width == 0)
-				width = 1;
-			if (flags & SUPPRESS) {
-				size_t sum = 0;
-				for (;;) {
-					if ((n = fp->_r) < (int)width) {
-						sum += n;
-						width -= n;
-						fp->_p += n;
-						if (__srefill(fp)) {
-							if (sum == 0)
-							    goto input_failure;
-							break;
-						}
-					} else {
-						sum += width;
-						fp->_r -= width;
-						fp->_p += width;
-						break;
-					}
-				}
-				nread += sum;
-			} else {
-				size_t r = fread((void *)va_arg(ap, char *), 1,
-				    width, fp);
-
-				if (r == 0)
-					goto input_failure;
-				nread += r;
-				nassigned++;
-			}
-			break;
-
-		case CT_CCL:
-			/* scan a (nonempty) character class (sets NOSKIP) */
-			if (width == 0)
-				width = (size_t)~0;	/* `infinity' */
-			/* take only those things in the class */
-			if (flags & SUPPRESS) {
-				n = 0;
-				while (ccltab[*fp->_p]) {
-					n++, fp->_r--, fp->_p++;
-					if (--width == 0)
-						break;
-					if (fp->_r <= 0 && __srefill(fp)) {
-						if (n == 0)
-							goto input_failure;
-						break;
-					}
-				}
-				if (n == 0)
-					goto match_failure;
-			} else {
-				p0 = p = va_arg(ap, char *);
-				while (ccltab[*fp->_p]) {
-					fp->_r--;
-					*p++ = *fp->_p++;
-					if (--width == 0)
-						break;
-					if (fp->_r <= 0 && __srefill(fp)) {
-						if (p == p0)
-							goto input_failure;
-						break;
-					}
-				}
-				n = p - p0;
-				if (n == 0)
-					goto match_failure;
-				*p = '\0';
-				nassigned++;
-			}
-			nread += n;
-			break;
-
-		case CT_STRING:
-			/* like CCL, but zero-length string OK, & no NOSKIP */
-			if (width == 0)
-				width = (size_t)~0;
-			if (flags & SUPPRESS) {
-				n = 0;
-				while (!isspace(*fp->_p)) {
-					n++, fp->_r--, fp->_p++;
-					if (--width == 0)
-						break;
-					if (fp->_r <= 0 && __srefill(fp))
-						break;
-				}
-				nread += n;
-			} else {
-				p0 = p = va_arg(ap, char *);
-				while (!isspace(*fp->_p)) {
-					fp->_r--;
-					*p++ = *fp->_p++;
-					if (--width == 0)
-						break;
-					if (fp->_r <= 0 && __srefill(fp))
-						break;
-				}
-				*p = '\0';
-				nread += p - p0;
-				nassigned++;
-			}
-			continue;
-
-		case CT_INT:
-			/* scan an integer as if by strtoimax/strtoumax */
-#ifdef hardway
-			if (width == 0 || width > sizeof(buf) - 1)
-				width = sizeof(buf) - 1;
-#else
-			/* size_t is unsigned, hence this optimisation */
-			if (--width > sizeof(buf) - 2)
-				width = sizeof(buf) - 2;
-			width++;
-#endif
-			flags |= SIGNOK | NDIGITS | NZDIGITS;
-			for (p = buf; width; width--) {
-				c = *fp->_p;
-				/*
-				 * Switch on the character; `goto ok'
-				 * if we accept it as a part of number.
-				 */
-				switch (c) {
-
-				/*
-				 * The digit 0 is always legal, but is
-				 * special.  For %i conversions, if no
-				 * digits (zero or nonzero) have been
-				 * scanned (only signs), we will have
-				 * base==0.  In that case, we should set
-				 * it to 8 and enable 0x prefixing.
-				 * Also, if we have not scanned zero digits
-				 * before this, do not turn off prefixing
-				 * (someone else will turn it off if we
-				 * have scanned any nonzero digits).
-				 */
-				case '0':
-					if (base == 0) {
-						base = 8;
-						flags |= PFXOK;
-					}
-					if (flags & NZDIGITS)
-					    flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
-					else
-					    flags &= ~(SIGNOK|PFXOK|NDIGITS);
-					goto ok;
-
-				/* 1 through 7 always legal */
-				case '1': case '2': case '3':
-				case '4': case '5': case '6': case '7':
-					base = basefix[base];
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* digits 8 and 9 ok iff decimal or hex */
-				case '8': case '9':
-					base = basefix[base];
-					if (base <= 8)
-						break;	/* not legal here */
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* letters ok iff hex */
-				case 'A': case 'B': case 'C':
-				case 'D': case 'E': case 'F':
-				case 'a': case 'b': case 'c':
-				case 'd': case 'e': case 'f':
-					/* no need to fix base here */
-					if (base <= 10)
-						break;	/* not legal here */
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* sign ok only as first character */
-				case '+': case '-':
-					if (flags & SIGNOK) {
-						flags &= ~SIGNOK;
-						flags |= HAVESIGN;
-						goto ok;
-					}
-					break;
-
-				/*
-				 * x ok iff flag still set and 2nd char (or
-				 * 3rd char if we have a sign).
-				 */
-				case 'x': case 'X':
-					if ((flags & PFXOK) && p ==
-					    buf + 1 + !!(flags & HAVESIGN)) {
-						base = 16;	/* if %i */
-						flags &= ~PFXOK;
-						goto ok;
-					}
-					break;
-				}
-
-				/*
-				 * If we got here, c is not a legal character
-				 * for a number.  Stop accumulating digits.
-				 */
-				break;
-		ok:
-				/*
-				 * c is legal: store it and look at the next.
-				 */
-				*p++ = c;
-				if (--fp->_r > 0)
-					fp->_p++;
-				else if (__srefill(fp))
-					break;		/* EOF */
-			}
-			/*
-			 * If we had only a sign, it is no good; push
-			 * back the sign.  If the number ends in `x',
-			 * it was [sign] '0' 'x', so push back the x
-			 * and treat it as [sign] '0'.
-			 */
-			if (flags & NDIGITS) {
-				if (p > buf)
-					(void) ungetc(*(u_char *)--p, fp);
-				goto match_failure;
-			}
-			c = ((u_char *)p)[-1];
-			if (c == 'x' || c == 'X') {
-				--p;
-				(void) ungetc(c, fp);
-			}
-			if ((flags & SUPPRESS) == 0) {
-				uintmax_t res;
-
-				*p = '\0';
-				if (flags & UNSIGNED)
-					res = strtoumax(buf, NULL, base);
-				else
-					res = strtoimax(buf, NULL, base);
-				if (flags & POINTER)
-					*va_arg(ap, void **) =
-					    (void *)(uintptr_t)res;
-				else if (flags & MAXINT)
-					*va_arg(ap, intmax_t *) = res;
-				else if (flags & LLONG)
-					*va_arg(ap, long long *) = res;
-				else if (flags & SIZEINT)
-					*va_arg(ap, ssize_t *) = res;
-				else if (flags & PTRINT)
-					*va_arg(ap, ptrdiff_t *) = res;
-				else if (flags & LONG)
-					*va_arg(ap, long *) = res;
-				else if (flags & SHORT)
-					*va_arg(ap, short *) = res;
-				else if (flags & SHORTSHORT)
-					*va_arg(ap, __signed char *) = res;
-				else
-					*va_arg(ap, int *) = res;
-				nassigned++;
-			}
-			nread += p - buf;
-			break;
-
-#ifdef FLOATING_POINT
-		case CT_FLOAT:
-			/* scan a floating point number as if by strtod */
-#ifdef hardway
-			if (width == 0 || width > sizeof(buf) - 1)
-				width = sizeof(buf) - 1;
-#else
-			/* size_t is unsigned, hence this optimisation */
-			if (--width > sizeof(buf) - 2)
-				width = sizeof(buf) - 2;
-			width++;
-#endif
-			flags |= SIGNOK | NDIGITS | DPTOK | EXPOK;
-			for (p = buf; width; width--) {
-				c = *fp->_p;
-				/*
-				 * This code mimicks the integer conversion
-				 * code, but is much simpler.
-				 */
-				switch (c) {
-
-				case '0': case '1': case '2': case '3':
-				case '4': case '5': case '6': case '7':
-				case '8': case '9':
-					flags &= ~(SIGNOK | NDIGITS);
-					goto fok;
-
-				case '+': case '-':
-					if (flags & SIGNOK) {
-						flags &= ~SIGNOK;
-						goto fok;
-					}
-					break;
-				case '.':
-					if (flags & DPTOK) {
-						flags &= ~(SIGNOK | DPTOK);
-						goto fok;
-					}
-					break;
-				case 'e': case 'E':
-					/* no exponent without some digits */
-					if ((flags&(NDIGITS|EXPOK)) == EXPOK) {
-						flags =
-						    (flags & ~(EXPOK|DPTOK)) |
-						    SIGNOK | NDIGITS;
-						goto fok;
-					}
-					break;
-				}
-				break;
-		fok:
-				*p++ = c;
-				if (--fp->_r > 0)
-					fp->_p++;
-				else if (__srefill(fp))
-					break;	/* EOF */
-			}
-			/*
-			 * If no digits, might be missing exponent digits
-			 * (just give back the exponent) or might be missing
-			 * regular digits, but had sign and/or decimal point.
-			 */
-			if (flags & NDIGITS) {
-				if (flags & EXPOK) {
-					/* no digits at all */
-					while (p > buf)
-						ungetc(*(u_char *)--p, fp);
-					goto match_failure;
-				}
-				/* just a bad exponent (e and maybe sign) */
-				c = *(u_char *)--p;
-				if (c != 'e' && c != 'E') {
-					(void) ungetc(c, fp);/* sign */
-					c = *(u_char *)--p;
-				}
-				(void) ungetc(c, fp);
-			}
-			if ((flags & SUPPRESS) == 0) {
-				double res;
-
-				*p = '\0';
-				res = strtod(buf, (char **) NULL);
-				if (flags & LONGDBL)
-					*va_arg(ap, long double *) = res;
-				else if (flags & LONG)
-					*va_arg(ap, double *) = res;
-				else
-					*va_arg(ap, float *) = res;
-				nassigned++;
-			}
-			nread += p - buf;
-			break;
-#endif /* FLOATING_POINT */
-		}
-	}
-input_failure:
-	if (nassigned == 0)
-		nassigned = -1;
-match_failure:
-	FUNLOCKFILE(fp);
-	return (nassigned);
-}
-
-/*
- * Fill in the given table from the scanset at the given format
- * (just after `[').  Return a pointer to the character past the
- * closing `]'.  The table has a 1 wherever characters should be
- * considered part of the scanset.
- */
-static u_char *
-__sccl(char *tab, u_char *fmt)
-{
-	int c, n, v;
-
-	/* first `clear' the whole table */
-	c = *fmt++;		/* first char hat => negated scanset */
-	if (c == '^') {
-		v = 1;		/* default => accept */
-		c = *fmt++;	/* get new first char */
-	} else
-		v = 0;		/* default => reject */
-	/* should probably use memset here */
-	for (n = 0; n < 256; n++)
-		tab[n] = v;
-	if (c == 0)
-		return (fmt - 1);/* format ended before closing ] */
-
-	/*
-	 * Now set the entries corresponding to the actual scanset
-	 * to the opposite of the above.
-	 *
-	 * The first character may be ']' (or '-') without being special;
-	 * the last character may be '-'.
-	 */
-	v = 1 - v;
-	for (;;) {
-		tab[c] = v;		/* take character c */
-doswitch:
-		n = *fmt++;		/* and examine the next */
-		switch (n) {
-
-		case 0:			/* format ended too soon */
-			return (fmt - 1);
-
-		case '-':
-			/*
-			 * A scanset of the form
-			 *	[01+-]
-			 * is defined as `the digit 0, the digit 1,
-			 * the character +, the character -', but
-			 * the effect of a scanset such as
-			 *	[a-zA-Z0-9]
-			 * is implementation defined.  The V7 Unix
-			 * scanf treats `a-z' as `the letters a through
-			 * z', but treats `a-a' as `the letter a, the
-			 * character -, and the letter a'.
-			 *
-			 * For compatibility, the `-' is not considerd
-			 * to define a range if the character following
-			 * it is either a close bracket (required by ANSI)
-			 * or is not numerically greater than the character
-			 * we just stored in the table (c).
-			 */
-			n = *fmt;
-			if (n == ']' || n < c) {
-				c = '-';
-				break;	/* resume the for(;;) */
-			}
-			fmt++;
-			do {		/* fill in the range */
-				tab[++c] = v;
-			} while (c < n);
-#if 1	/* XXX another disgusting compatibility hack */
-			/*
-			 * Alas, the V7 Unix scanf also treats formats
-			 * such as [a-c-e] as `the letters a through e'.
-			 * This too is permitted by the standard....
-			 */
-			goto doswitch;
-#else
-			c = *fmt++;
-			if (c == 0)
-				return (fmt - 1);
-			if (c == ']')
-				return (fmt);
-#endif
-			break;
-
-		case ']':		/* end of scanset */
-			return (fmt);
-
-		default:		/* just another character */
-			c = n;
-			break;
-		}
-	}
-	/* NOTREACHED */
-}
diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c
deleted file mode 100644
index ca30f94..0000000
--- a/libc/stdio/vsnprintf.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*	$OpenBSD: vsnprintf.c,v 1.12 2006/01/06 18:53:04 millert Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include "local.h"
-
-int
-vsnprintf(char *str, size_t n, const char *fmt, __va_list ap)
-{
-	int ret;
-	char dummy;
-	FILE f;
-	struct __sfileext fext;
-
-	_FILEEXT_SETUP(&f, &fext);
-
-	/* While snprintf(3) specifies size_t stdio uses an int internally */
-	if (n > INT_MAX)
-		n = INT_MAX;
-	/* Stdio internals do not deal correctly with zero length buffer */
-	if (n == 0) {
-		str = &dummy;
-		n = 1;
-	}
-	f._file = -1;
-	f._flags = __SWR | __SSTR;
-	f._bf._base = f._p = (unsigned char *)str;
-	f._bf._size = f._w = n - 1;
-	ret = __vfprintf(&f, fmt, ap);
-	*f._p = '\0';
-	return (ret);
-}
diff --git a/libc/stdio/vsprintf.c b/libc/stdio/vsprintf.c
deleted file mode 100644
index 846ee8a..0000000
--- a/libc/stdio/vsprintf.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*	$OpenBSD: vsprintf.c,v 1.13 2006/01/06 18:53:04 millert Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <limits.h>
-#include "local.h"
-
-#if defined(APIWARN)
-__warn_references(vsprintf,
-    "warning: vsprintf() is often misused, please use vsnprintf()");
-#endif
-
-int
-vsprintf(char *str, const char *fmt, __va_list ap)
-{
-	int ret;
-	FILE f;
-	struct __sfileext fext;
-
-	_FILEEXT_SETUP(&f, &fext);
-	f._file = -1;
-	f._flags = __SWR | __SSTR;
-	f._bf._base = f._p = (unsigned char *)str;
-	f._bf._size = f._w = INT_MAX;
-	ret = __vfprintf(&f, fmt, ap);
-	*f._p = '\0';
-	return (ret);
-}
diff --git a/libc/stdio/vsscanf.c b/libc/stdio/vsscanf.c
deleted file mode 100644
index 9c4d805..0000000
--- a/libc/stdio/vsscanf.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*	$OpenBSD: vsscanf.c,v 1.11 2006/01/06 18:53:04 millert Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Donn Seeley at UUNET Technologies, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include "local.h"
-
-/* ARGSUSED */
-static int
-eofread(void *cookie, char *buf, int len)
-{
-	return (0);
-}
-
-int
-vsscanf(const char *str, const char *fmt, __va_list ap)
-{
-	FILE f;
-	struct __sfileext fext;
-
-	_FILEEXT_SETUP(&f, &fext);
-	f._flags = __SRD;
-	f._bf._base = f._p = (unsigned char *)str;
-	f._bf._size = f._r = strlen(str);
-	f._read = eofread;
-	f._lb._base = NULL;
-	return (vfscanf(&f, fmt, ap));
-}
diff --git a/libc/stdio/wbuf.c b/libc/stdio/wbuf.c
deleted file mode 100644
index e09ac59..0000000
--- a/libc/stdio/wbuf.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*	$OpenBSD: wbuf.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include "local.h"
-
-/*
- * Write the given character into the (probably full) buffer for
- * the given file.  Flush the buffer out if it is or becomes full,
- * or if c=='\n' and the file is line buffered.
- */
-int
-__swbuf(int c, FILE *fp)
-{
-	int n;
-
-	_SET_ORIENTATION(fp, -1);
-	/*
-	 * In case we cannot write, or longjmp takes us out early,
-	 * make sure _w is 0 (if fully- or un-buffered) or -_bf._size
-	 * (if line buffered) so that we will get called again.
-	 * If we did not do this, a sufficient number of putc()
-	 * calls might wrap _w from negative to positive.
-	 */
-	fp->_w = fp->_lbfsize;
-	if (cantwrite(fp)) {
-		errno = EBADF;
-		return (EOF);
-	}
-	c = (unsigned char)c;
-
-	/*
-	 * If it is completely full, flush it out.  Then, in any case,
-	 * stuff c into the buffer.  If this causes the buffer to fill
-	 * completely, or if c is '\n' and the file is line buffered,
-	 * flush it (perhaps a second time).  The second flush will always
-	 * happen on unbuffered streams, where _bf._size==1; __sflush()
-	 * guarantees that putc() will always call wbuf() by setting _w
-	 * to 0, so we need not do anything else.
-	 */
-	n = fp->_p - fp->_bf._base;
-	if (n >= fp->_bf._size) {
-		if (__sflush(fp))
-			return (EOF);
-		n = 0;
-	}
-	fp->_w--;
-	*fp->_p++ = c;
-	if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
-		if (__sflush(fp))
-			return (EOF);
-	return (c);
-}
diff --git a/libc/stdio/wcio.h b/libc/stdio/wcio.h
index dd6db21..584a3f2 100644
--- a/libc/stdio/wcio.h
+++ b/libc/stdio/wcio.h
@@ -1,34 +1,34 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
+/*	$OpenBSD: wcio.h,v 1.2 2013/04/17 17:40:35 tedu Exp $	*/
+/* $NetBSD: wcio.h,v 1.3 2003/01/18 11:30:00 thorpej Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
- *  * Redistributions of source code must retain the above copyright
+ * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * $Citrus$
  */
 
-/* this file is only used to quiet the BSD stdio implementation
- * since we don't implement wchar support at all
- */
 #ifndef _WCIO_H_
 #define _WCIO_H_
 
@@ -36,22 +36,46 @@
 #define WCIO_UNGETWC_BUFSIZE 1
 
 struct wchar_io_data {
-        int dummy;
+	mbstate_t wcio_mbstate_in;
+	mbstate_t wcio_mbstate_out;
+
+	wchar_t wcio_ungetwc_buf[WCIO_UNGETWC_BUFSIZE];
+	size_t wcio_ungetwc_inbuf;
+
+	int wcio_mode; /* orientation */
 };
 
-/* BIONIC: disable wchar support */
 #define WCIO_GET(fp) \
-	((struct wchar_io_data*) 0)
+	(_EXT(fp) ? &(_EXT(fp)->_wcio) : (struct wchar_io_data *)0)
 
-#define _SET_ORIENTATION(fp, mode) ((void)0)
+#define _SET_ORIENTATION(fp, mode) \
+do {\
+	struct wchar_io_data *_wcio = WCIO_GET(fp); \
+	if (_wcio && _wcio->wcio_mode == 0) \
+		_wcio->wcio_mode = (mode);\
+} while (0)
 
 /*
  * WCIO_FREE should be called by fclose
  */
-#define WCIO_FREE(fp) ((void)(0))
+#define WCIO_FREE(fp) \
+do {\
+	struct wchar_io_data *_wcio = WCIO_GET(fp); \
+	if (_wcio) { \
+		_wcio->wcio_mode = 0;\
+		_wcio->wcio_ungetwc_inbuf = 0;\
+	} \
+} while (0)
 
-#define WCIO_FREEUB(fp) ((void)0)
+#define WCIO_FREEUB(fp) \
+do {\
+	struct wchar_io_data *_wcio = WCIO_GET(fp); \
+	if (_wcio) { \
+		_wcio->wcio_ungetwc_inbuf = 0;\
+	} \
+} while (0)
 
-#define WCIO_INIT(fp)  ((void)0)
+#define WCIO_INIT(fp) \
+	memset(&(_EXT(fp)->_wcio), 0, sizeof(struct wchar_io_data))
 
 #endif /*_WCIO_H_*/
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
deleted file mode 100644
index 4e14434..0000000
--- a/libc/stdlib/atexit.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*	$OpenBSD: atexit.c,v 1.14 2007/09/05 20:47:47 chl Exp $ */
-/*
- * Copyright (c) 2002 Daniel Hartmeier
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *    - Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *    - Redistributions in binary form must reproduce the above
- *      copyright notice, this list of conditions and the following
- *      disclaimer in the documentation and/or other materials provided
- *      with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "atexit.h"
-#include "private/thread_private.h"
-
-int __atexit_invalid = 1;
-struct atexit *__atexit;
-
-/*
- * Function pointers are stored in a linked list of pages. The list
- * is initially empty, and pages are allocated on demand. The first
- * function pointer in the first allocated page (the last one in
- * the linked list) was reserved for the cleanup function.
- * TODO: switch to the regular FreeBSD/NetBSD atexit implementation.
- *
- * Outside the following functions, all pages are mprotect()'ed
- * to prevent unintentional/malicious corruption.
- */
-
-/*
- * Register a function to be performed at exit or when a shared object
- * with the given dso handle is unloaded dynamically.  Also used as
- * the backend for atexit().  For more info on this API, see:
- *
- *	http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor
- */
-int
-__cxa_atexit(void (*func)(void *), void *arg, void *dso)
-{
-	struct atexit *p = __atexit;
-	struct atexit_fn *fnp;
-	int pgsize = getpagesize();
-	int ret = -1;
-
-	if (pgsize < (int)sizeof(*p))
-		return (-1);
-	_ATEXIT_LOCK();
-	p = __atexit;
-	if (p != NULL) {
-		if (p->ind + 1 >= p->max)
-			p = NULL;
-		else if (mprotect(p, pgsize, PROT_READ | PROT_WRITE))
-			goto unlock;
-	}
-	if (p == NULL) {
-		p = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,
-		    MAP_ANON | MAP_PRIVATE, -1, 0);
-		if (p == MAP_FAILED)
-			goto unlock;
-		if (__atexit == NULL) {
-			memset(&p->fns[0], 0, sizeof(p->fns[0]));
-			p->ind = 1;
-		} else
-			p->ind = 0;
-		p->max = (pgsize - ((char *)&p->fns[0] - (char *)p)) /
-		    sizeof(p->fns[0]);
-		p->next = __atexit;
-		__atexit = p;
-		if (__atexit_invalid)
-			__atexit_invalid = 0;
-	}
-	fnp = &p->fns[p->ind++];
-	fnp->fn_ptr.cxa_func = func;
-	fnp->fn_arg = arg;
-	fnp->fn_dso = dso;
-	if (mprotect(p, pgsize, PROT_READ))
-		goto unlock;
-	ret = 0;
-unlock:
-	_ATEXIT_UNLOCK();
-	return (ret);
-}
-
-/*
- * Call all handlers registered with __cxa_atexit() for the shared
- * object owning 'dso'.
- * Note: if 'dso' is NULL, then all remaining handlers are called.
- */
-void
-__cxa_finalize(void *dso)
-{
-	struct atexit *p, *q;
-	struct atexit_fn fn;
-	int n, pgsize = getpagesize();
-	static int call_depth;
-
-	if (__atexit_invalid)
-		return;
-
-	_ATEXIT_LOCK();
-	call_depth++;
-
-	for (p = __atexit; p != NULL; p = p->next) {
-		for (n = p->ind; --n >= 0;) {
-			if (p->fns[n].fn_ptr.cxa_func == NULL)
-				continue;	/* already called */
-			if (dso != NULL && dso != p->fns[n].fn_dso)
-				continue;	/* wrong DSO */
-
-			/*
-			 * Mark handler as having been already called to avoid
-			 * dupes and loops, then call the appropriate function.
-			 */
-			fn = p->fns[n];
-			if (mprotect(p, pgsize, PROT_READ | PROT_WRITE) == 0) {
-				p->fns[n].fn_ptr.cxa_func = NULL;
-				mprotect(p, pgsize, PROT_READ);
-			}
-			_ATEXIT_UNLOCK();
-#if ANDROID
-                        /* it looks like we should always call the function
-                         * with an argument, even if dso is not NULL. Otherwise
-                         * static destructors will not be called properly on
-                         * the ARM.
-                         */
-                        (*fn.fn_ptr.cxa_func)(fn.fn_arg);
-#else /* !ANDROID */
-			if (dso != NULL)
-				(*fn.fn_ptr.cxa_func)(fn.fn_arg);
-			else
-				(*fn.fn_ptr.std_func)();
-#endif /* !ANDROID */
-			_ATEXIT_LOCK();
-		}
-	}
-
-	/*
-	 * If called via exit(), unmap the pages since we have now run
-	 * all the handlers.  We defer this until calldepth == 0 so that
-	 * we don't unmap things prematurely if called recursively.
-	 */
-	if (dso == NULL && --call_depth == 0) {
-		for (p = __atexit; p != NULL; ) {
-			q = p;
-			p = p->next;
-			munmap(q, pgsize);
-		}
-		__atexit = NULL;
-	}
-	_ATEXIT_UNLOCK();
-}
diff --git a/libc/stdlib/atexit.h b/libc/stdlib/atexit.h
deleted file mode 100644
index 4b3e5ab..0000000
--- a/libc/stdlib/atexit.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*	$OpenBSD: atexit.h,v 1.7 2007/09/03 14:40:16 millert Exp $ */
-
-/*
- * Copyright (c) 2002 Daniel Hartmeier
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *    - Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *    - Redistributions in binary form must reproduce the above
- *      copyright notice, this list of conditions and the following
- *      disclaimer in the documentation and/or other materials provided
- *      with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include <sys/cdefs.h>
-
-struct atexit {
-	struct atexit *next;		/* next in list */
-	int ind;			/* next index in this table */
-	int max;			/* max entries >= ATEXIT_SIZE */
-	struct atexit_fn {
-		union {
-			void (*std_func)(void);
-			void (*cxa_func)(void *);
-		} fn_ptr;
-		void *fn_arg;		/* argument for CXA callback */
-		void *fn_dso;		/* shared module handle */
-	} fns[1];			/* the table itself */
-};
-
-__BEGIN_DECLS
-
-extern int __atexit_invalid;
-extern struct atexit *__atexit;		/* points to head of LIFO stack */
-
-int	__cxa_atexit(void (*)(void *), void *, void *);
-void	__cxa_finalize(void *);
-
-__END_DECLS
diff --git a/libc/stdlib/ctype_.c b/libc/stdlib/ctype_.c
deleted file mode 100644
index 3703f64..0000000
--- a/libc/stdlib/ctype_.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/*	$OpenBSD: ctype_.c,v 1.9 2005/08/08 08:05:33 espie Exp $ */
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <ctype.h>
-#include "ctype_private.h"
-
-#define _U _CTYPE_U
-#define _L _CTYPE_L
-#define _N _CTYPE_N
-#define _S _CTYPE_S
-#define _P _CTYPE_P
-#define _C _CTYPE_C
-#define _X _CTYPE_X
-#define _B _CTYPE_B
-
-const char _C_ctype_[1 + CTYPE_NUM_CHARS] = {
-	0,
-	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
-	_C,	_C|_S,	_C|_S,	_C|_S,	_C|_S,	_C|_S,	_C,	_C,
-	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
-	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
-   _S|(char)_B,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
-	_N,	_N,	_N,	_N,	_N,	_N,	_N,	_N,
-	_N,	_N,	_P,	_P,	_P,	_P,	_P,	_P,
-	_P,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U,
-	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
-	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
-	_U,	_U,	_U,	_P,	_P,	_P,	_P,	_P,
-	_P,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L,
-	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
-	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
-	/* determine printability based on the IS0 8859 8-bit standard */
-	_L,	_L,	_L,	_P,	_P,	_P,	_P,	_C,
-
-	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 80 */
-	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 88 */
-	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 90 */
-	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 98 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* A0 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* A8 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* B0 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* B8 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* C0 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* C8 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* D0 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* D8 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* E0 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* E8 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* F0 */
-	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P  /* F8 */
-};
-
-const char *_ctype_ = _C_ctype_;
-
-
-// TODO: fix the header file so we don't have to duplicate all this inlined stuff.
-
-#if 1 /* ndef NDEBUG */
-int isalnum(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N)));
-}
-
-int isalpha(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L)));
-}
-
-int iscntrl(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _C));
-}
-
-int isdigit(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
-}
-
-int isgraph(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N)));
-}
-
-int islower(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _L));
-}
-
-int isprint(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B)));
-}
-
-int ispunct(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P));
-}
-
-int isspace(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
-}
-
-int isupper(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _U));
-}
-
-int isxdigit(int c)
-{
-	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_N|_X)));
-}
-
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
-    || __XPG_VISIBLE > 600
-int isblank(int c)
-{
-	return (c == ' ' || c == '\t');
-}
-#endif
-
-#if __BSD_VISIBLE || __XPG_VISIBLE
-int isascii(int c)
-{
-	return ((unsigned int)c <= 0177);
-}
-
-int toascii(int c)
-{
-	return (c & 0177);
-}
-
-#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
-
-#endif /* !NDBEUG */
diff --git a/libc/stdlib/getenv.c b/libc/stdlib/getenv.c
deleted file mode 100644
index 72367b3..0000000
--- a/libc/stdlib/getenv.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*	$OpenBSD: getenv.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
-/*
- * Copyright (c) 1987, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-char *__findenv(const char *name, int *offset);
-
-/*
- * __findenv --
- *	Returns pointer to value associated with name, if any, else NULL.
- *	Sets offset to be the offset of the name/value combination in the
- *	environmental array, for use by setenv(3) and unsetenv(3).
- *	Explicitly removes '=' in argument name.
- *
- *	This routine *should* be a static; don't use it.
- */
-char *
-__findenv(const char *name, int *offset)
-{
-	extern char **environ;
-	int len, i;
-	const char *np;
-	char **p, *cp;
-
-	if (name == NULL || environ == NULL)
-		return (NULL);
-	for (np = name; *np && *np != '='; ++np)
-		;
-	len = np - name;
-	for (p = environ; (cp = *p) != NULL; ++p) {
-		for (np = name, i = len; i && *cp; i--)
-			if (*cp++ != *np++)
-				break;
-		if (i == 0 && *cp++ == '=') {
-			*offset = p - environ;
-			return (cp);
-		}
-	}
-	return (NULL);
-}
-
-/*
- * getenv --
- *	Returns ptr to value associated with name, if any, else NULL.
- */
-char *
-getenv(const char *name)
-{
-	int offset;
-
-	return (__findenv(name, &offset));
-}
diff --git a/libc/stdlib/putenv.c b/libc/stdlib/putenv.c
deleted file mode 100644
index 54482f6..0000000
--- a/libc/stdlib/putenv.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*	$OpenBSD: putenv.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */
-/*-
- * Copyright (c) 1988, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-int
-putenv(const char *str)
-{
-	char *p, *equal;
-	int rval;
-
-	if ((p = strdup(str)) == NULL)
-		return (-1);
-	if ((equal = strchr(p, '=')) == NULL) {
-		(void)free(p);
-		return (-1);
-	}
-	*equal = '\0';
-	rval = setenv(p, equal + 1, 1);
-	(void)free(p);
-	return (rval);
-}
diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c
deleted file mode 100644
index 856db5e..0000000
--- a/libc/stdlib/setenv.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*	$OpenBSD: setenv.c,v 1.9 2005/08/08 08:05:37 espie Exp $ */
-/*
- * Copyright (c) 1987 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-char *__findenv(const char *name, int *offset);
-
-extern char **environ;
-
-/*
- * setenv --
- *	Set the value of the environmental variable "name" to be
- *	"value".  If rewrite is set, replace any current value.
- */
-int
-setenv(const char *name, const char *value, int rewrite)
-{
-	static char **lastenv;			/* last value of environ */
-	char *C;
-	int l_value, offset;
-
-	if (*value == '=')			/* no `=' in value */
-		++value;
-	l_value = strlen(value);
-	if ((C = __findenv(name, &offset))) {	/* find if already exists */
-		if (!rewrite)
-			return (0);
-		if ((int)strlen(C) >= l_value) {	/* old larger; copy over */
-			while ((*C++ = *value++))
-				;
-			return (0);
-		}
-	} else {					/* create new slot */
-		size_t cnt;
-		char **P;
-
-		for (P = environ; *P != NULL; P++)
-			;
-		cnt = P - environ;
-        P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
-		if (!P)
-			return (-1);
-		if (lastenv != environ)
-			memcpy(P, environ, cnt * sizeof(char *));
-		lastenv = environ = P;
-		offset = cnt;
-		environ[cnt + 1] = NULL;
-	}
-	for (C = (char *)name; *C && *C != '='; ++C)
-		;				/* no `=' in name */
-	if (!(environ[offset] =			/* name + `=' + value */
-	    malloc((size_t)((int)(C - name) + l_value + 2))))
-		return (-1);
-	for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
-		;
-	for (*C++ = '='; (*C++ = *value++); )
-		;
-	return (0);
-}
-
-/*
- * unsetenv(name) --
- *	Delete environmental variable "name".
- */
-int
-unsetenv(const char *name)
-{
-	char **P;
-	int offset;
-
-	while (__findenv(name, &offset))	/* if set multiple times */
-		for (P = &environ[offset];; ++P)
-			if (!(*P = *(P + 1)))
-				break;
-
-        return 0;
-}
diff --git a/libc/stdlib/strtod.c b/libc/stdlib/strtod.c
deleted file mode 100644
index 3934d9a..0000000
--- a/libc/stdlib/strtod.c
+++ /dev/null
@@ -1,2708 +0,0 @@
-/*	$NetBSD: strtod.c,v 1.45.2.1 2005/04/19 13:35:54 tron Exp $	*/
-
-/****************************************************************
- *
- * The author of this software is David M. Gay.
- *
- * Copyright (c) 1991 by AT&T.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose without fee is hereby granted, provided that this entire notice
- * is included in all copies of any software which is or includes a copy
- * or modification of this software and in all copies of the supporting
- * documentation for such software.
- *
- * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
- * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
- * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
- *
- ***************************************************************/
-
-/* Please send bug reports to
-	David M. Gay
-	AT&T Bell Laboratories, Room 2C-463
-	600 Mountain Avenue
-	Murray Hill, NJ 07974-2070
-	U.S.A.
-	dmg@research.att.com or research!dmg
- */
-
-/* strtod for IEEE-, VAX-, and IBM-arithmetic machines.
- *
- * This strtod returns a nearest machine number to the input decimal
- * string (or sets errno to ERANGE).  With IEEE arithmetic, ties are
- * broken by the IEEE round-even rule.  Otherwise ties are broken by
- * biased rounding (add half and chop).
- *
- * Inspired loosely by William D. Clinger's paper "How to Read Floating
- * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 92-101].
- *
- * Modifications:
- *
- *	1. We only require IEEE, IBM, or VAX double-precision
- *		arithmetic (not IEEE double-extended).
- *	2. We get by with floating-point arithmetic in a case that
- *		Clinger missed -- when we're computing d * 10^n
- *		for a small integer d and the integer n is not too
- *		much larger than 22 (the maximum integer k for which
- *		we can represent 10^k exactly), we may be able to
- *		compute (d*10^k) * 10^(e-k) with just one roundoff.
- *	3. Rather than a bit-at-a-time adjustment of the binary
- *		result in the hard case, we use floating-point
- *		arithmetic to determine the adjustment to within
- *		one bit; only in really hard cases do we need to
- *		compute a second residual.
- *	4. Because of 3., we don't need a large table of powers of 10
- *		for ten-to-e (just some small tables, e.g. of 10^k
- *		for 0 <= k <= 22).
- */
-
-/*
- * #define IEEE_LITTLE_ENDIAN for IEEE-arithmetic machines where the least
- *	significant byte has the lowest address.
- * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most
- *	significant byte has the lowest address.
- * #define Long int on machines with 32-bit ints and 64-bit longs.
- * #define Sudden_Underflow for IEEE-format machines without gradual
- *	underflow (i.e., that flush to zero on underflow).
- * #define IBM for IBM mainframe-style floating-point arithmetic.
- * #define VAX for VAX-style floating-point arithmetic.
- * #define Unsigned_Shifts if >> does treats its left operand as unsigned.
- * #define No_leftright to omit left-right logic in fast floating-point
- *	computation of dtoa.
- * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3.
- * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
- *	that use extended-precision instructions to compute rounded
- *	products and quotients) with IBM.
- * #define ROUND_BIASED for IEEE-format with biased rounding.
- * #define Inaccurate_Divide for IEEE-format with correctly rounded
- *	products but inaccurate quotients, e.g., for Intel i860.
- * #define Just_16 to store 16 bits per 32-bit Long when doing high-precision
- *	integer arithmetic.  Whether this speeds things up or slows things
- *	down depends on the machine and the number being converted.
- * #define KR_headers for old-style C function headers.
- * #define Bad_float_h if your system lacks a float.h or if it does not
- *	define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
- *	FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
- * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
- *	if memory is available and otherwise does something you deem
- *	appropriate.  If MALLOC is undefined, malloc will be invoked
- *	directly -- and assumed always to succeed.
- */
-
-#ifdef ANDROID_CHANGES
-#include <pthread.h>
-#define mutex_lock(x) pthread_mutex_lock(x)
-#define mutex_unlock(x) pthread_mutex_unlock(x)
-#endif
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strtod.c,v 1.45.2.1 2005/04/19 13:35:54 tron Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#define Unsigned_Shifts
-#if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \
-    defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \
-    defined(__powerpc__) || defined(__sh__) || defined(__x86_64__) || \
-    defined(__hppa__) || \
-    (defined(__arm__) && defined(__VFP_FP__)) || defined(__aarch64__)
-#include <endian.h>
-#if BYTE_ORDER == BIG_ENDIAN
-#define IEEE_BIG_ENDIAN
-#else
-#define IEEE_LITTLE_ENDIAN
-#endif
-#endif
-
-#if defined(__arm__) && !defined(__VFP_FP__)
-/*
- * Although the CPU is little endian the FP has different
- * byte and word endianness. The byte order is still little endian
- * but the word order is big endian.
- */
-#define IEEE_BIG_ENDIAN
-#endif
-
-#ifdef __vax__
-#define VAX
-#endif
-
-#if defined(__hppa__) || defined(__mips__) || defined(__sh__)
-#define	NAN_WORD0	0x7ff40000
-#else
-#define	NAN_WORD0	0x7ff80000
-#endif
-#define	NAN_WORD1	0
-
-#define Long	int32_t
-#define ULong	u_int32_t
-
-#ifdef DEBUG
-#include "stdio.h"
-#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
-#endif
-
-#ifdef __cplusplus
-#include "malloc.h"
-#include "memory.h"
-#else
-#ifndef KR_headers
-#include "stdlib.h"
-#include "string.h"
-#ifndef ANDROID_CHANGES
-#include "locale.h"
-#endif /* ANDROID_CHANGES */
-#else
-#include "malloc.h"
-#include "memory.h"
-#endif
-#endif
-#ifndef ANDROID_CHANGES
-#include "extern.h"
-#include "reentrant.h"
-#endif /* ANDROID_CHANGES */
-
-#ifdef MALLOC
-#ifdef KR_headers
-extern char *MALLOC();
-#else
-extern void *MALLOC(size_t);
-#endif
-#else
-#define MALLOC malloc
-#endif
-
-#include "ctype.h"
-#include "errno.h"
-#include "float.h"
-
-#ifndef __MATH_H__
-#include "math.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef CONST
-#ifdef KR_headers
-#define CONST /* blank */
-#else
-#define CONST const
-#endif
-#endif
-
-#ifdef Unsigned_Shifts
-#define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000;
-#else
-#define Sign_Extend(a,b) /*no-op*/
-#endif
-
-#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + \
-    defined(IBM) != 1
-Exactly one of IEEE_LITTLE_ENDIAN IEEE_BIG_ENDIAN, VAX, or
-IBM should be defined.
-#endif
-
-typedef union {
-	double d;
-	ULong ul[2];
-} _double;
-#define value(x) ((x).d)
-#ifdef IEEE_LITTLE_ENDIAN
-#define word0(x) ((x).ul[1])
-#define word1(x) ((x).ul[0])
-#else
-#define word0(x) ((x).ul[0])
-#define word1(x) ((x).ul[1])
-#endif
-
-/* The following definition of Storeinc is appropriate for MIPS processors.
- * An alternative that might be better on some machines is
- * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
- */
-#if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) + defined(__arm__)
-#define Storeinc(a,b,c) \
-    (((u_short *)(void *)a)[1] = \
-	(u_short)b, ((u_short *)(void *)a)[0] = (u_short)c, a++)
-#else
-#define Storeinc(a,b,c) \
-    (((u_short *)(void *)a)[0] = \
-	(u_short)b, ((u_short *)(void *)a)[1] = (u_short)c, a++)
-#endif
-
-/* #define P DBL_MANT_DIG */
-/* Ten_pmax = floor(P*log(2)/log(5)) */
-/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
-/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
-/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
-
-#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN)
-#define Exp_shift  20
-#define Exp_shift1 20
-#define Exp_msk1    0x100000
-#define Exp_msk11   0x100000
-#define Exp_mask  0x7ff00000
-#define P 53
-#define Bias 1023
-#define IEEE_Arith
-#define Emin (-1022)
-#define Exp_1  0x3ff00000
-#define Exp_11 0x3ff00000
-#define Ebits 11
-#define Frac_mask  0xfffff
-#define Frac_mask1 0xfffff
-#define Ten_pmax 22
-#define Bletch 0x10
-#define Bndry_mask  0xfffff
-#define Bndry_mask1 0xfffff
-#define LSB 1
-#define Sign_bit 0x80000000
-#define Log2P 1
-#define Tiny0 0
-#define Tiny1 1
-#define Quick_max 14
-#define Int_max 14
-#define Infinite(x) (word0(x) == 0x7ff00000) /* sufficient test for here */
-#else
-#undef  Sudden_Underflow
-#define Sudden_Underflow
-#ifdef IBM
-#define Exp_shift  24
-#define Exp_shift1 24
-#define Exp_msk1   0x1000000
-#define Exp_msk11  0x1000000
-#define Exp_mask  0x7f000000
-#define P 14
-#define Bias 65
-#define Exp_1  0x41000000
-#define Exp_11 0x41000000
-#define Ebits 8	/* exponent has 7 bits, but 8 is the right value in b2d */
-#define Frac_mask  0xffffff
-#define Frac_mask1 0xffffff
-#define Bletch 4
-#define Ten_pmax 22
-#define Bndry_mask  0xefffff
-#define Bndry_mask1 0xffffff
-#define LSB 1
-#define Sign_bit 0x80000000
-#define Log2P 4
-#define Tiny0 0x100000
-#define Tiny1 0
-#define Quick_max 14
-#define Int_max 15
-#else /* VAX */
-#define Exp_shift  23
-#define Exp_shift1 7
-#define Exp_msk1    0x80
-#define Exp_msk11   0x800000
-#define Exp_mask  0x7f80
-#define P 56
-#define Bias 129
-#define Exp_1  0x40800000
-#define Exp_11 0x4080
-#define Ebits 8
-#define Frac_mask  0x7fffff
-#define Frac_mask1 0xffff007f
-#define Ten_pmax 24
-#define Bletch 2
-#define Bndry_mask  0xffff007f
-#define Bndry_mask1 0xffff007f
-#define LSB 0x10000
-#define Sign_bit 0x8000
-#define Log2P 1
-#define Tiny0 0x80
-#define Tiny1 0
-#define Quick_max 15
-#define Int_max 15
-#endif
-#endif
-
-#ifndef IEEE_Arith
-#define ROUND_BIASED
-#endif
-
-#ifdef RND_PRODQUOT
-#define rounded_product(a,b) a = rnd_prod(a, b)
-#define rounded_quotient(a,b) a = rnd_quot(a, b)
-#ifdef KR_headers
-extern double rnd_prod(), rnd_quot();
-#else
-extern double rnd_prod(double, double), rnd_quot(double, double);
-#endif
-#else
-#define rounded_product(a,b) a *= b
-#define rounded_quotient(a,b) a /= b
-#endif
-
-#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
-#define Big1 0xffffffff
-
-#ifndef Just_16
-/* When Pack_32 is not defined, we store 16 bits per 32-bit Long.
- * This makes some inner loops simpler and sometimes saves work
- * during multiplications, but it often seems to make things slightly
- * slower.  Hence the default is now to store 32 bits per Long.
- */
-#ifndef Pack_32
-#define Pack_32
-#endif
-#endif
-
-#define Kmax 15
-
-#ifdef __cplusplus
-extern "C" double strtod(const char *s00, char **se);
-extern "C" char *__dtoa(double d, int mode, int ndigits,
-			int *decpt, int *sign, char **rve);
-#endif
-
- struct
-Bigint {
-	struct Bigint *next;
-	int k, maxwds, sign, wds;
-	ULong x[1];
-};
-
- typedef struct Bigint Bigint;
-
- static Bigint *freelist[Kmax+1];
-
-#ifdef ANDROID_CHANGES
- static pthread_mutex_t freelist_mutex = PTHREAD_MUTEX_INITIALIZER;
-#else
-#ifdef _REENTRANT
- static mutex_t freelist_mutex = MUTEX_INITIALIZER;
-#endif
-#endif
-
-/* Special value used to indicate an invalid Bigint value,
- * e.g. when a memory allocation fails. The idea is that we
- * want to avoid introducing NULL checks everytime a bigint
- * computation is performed. Also the NULL value can also be
- * already used to indicate "value not initialized yet" and
- * returning NULL might alter the execution code path in
- * case of OOM.
- */
-#define  BIGINT_INVALID   ((Bigint *)&bigint_invalid_value)
-
-static const Bigint bigint_invalid_value;
-
-
-/* Return BIGINT_INVALID on allocation failure.
- *
- * Most of the code here depends on the fact that this function
- * never returns NULL.
- */
- static Bigint *
-Balloc
-#ifdef KR_headers
-	(k) int k;
-#else
-	(int k)
-#endif
-{
-	int x;
-	Bigint *rv;
-
-	mutex_lock(&freelist_mutex);
-
-	if ((rv = freelist[k]) != NULL) {
-		freelist[k] = rv->next;
-	}
-	else {
-		x = 1 << k;
-		rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long));
-		if (rv == NULL) {
-		        rv = BIGINT_INVALID;
-			goto EXIT;
-		}
-		rv->k = k;
-		rv->maxwds = x;
-	}
-	rv->sign = rv->wds = 0;
-EXIT:
-	mutex_unlock(&freelist_mutex);
-
-	return rv;
-}
-
- static void
-Bfree
-#ifdef KR_headers
-	(v) Bigint *v;
-#else
-	(Bigint *v)
-#endif
-{
-	if (v && v != BIGINT_INVALID) {
-		mutex_lock(&freelist_mutex);
-
-		v->next = freelist[v->k];
-		freelist[v->k] = v;
-
-		mutex_unlock(&freelist_mutex);
-	}
-}
-
-#define Bcopy_valid(x,y) memcpy(&(x)->sign, &(y)->sign, \
-    (y)->wds*sizeof(Long) + 2*sizeof(int))
-
-#define Bcopy(x,y)  Bcopy_ptr(&(x),(y))
-
- static void
-Bcopy_ptr(Bigint **px, Bigint *y)
-{
-	if (*px == BIGINT_INVALID)
-		return; /* no space to store copy */
-	if (y == BIGINT_INVALID) {
-		Bfree(*px); /* invalid input */
-		*px = BIGINT_INVALID;
-	} else {
-		Bcopy_valid(*px,y);
-	}
-}
-
- static Bigint *
-multadd
-#ifdef KR_headers
-	(b, m, a) Bigint *b; int m, a;
-#else
-	(Bigint *b, int m, int a)	/* multiply by m and add a */
-#endif
-{
-	int i, wds;
-	ULong *x, y;
-#ifdef Pack_32
-	ULong xi, z;
-#endif
-	Bigint *b1;
-
-	if (b == BIGINT_INVALID)
-		return b;
-
-	wds = b->wds;
-	x = b->x;
-	i = 0;
-	do {
-#ifdef Pack_32
-		xi = *x;
-		y = (xi & 0xffff) * m + a;
-		z = (xi >> 16) * m + (y >> 16);
-		a = (int)(z >> 16);
-		*x++ = (z << 16) + (y & 0xffff);
-#else
-		y = *x * m + a;
-		a = (int)(y >> 16);
-		*x++ = y & 0xffff;
-#endif
-	}
-	while(++i < wds);
-	if (a) {
-		if (wds >= b->maxwds) {
-			b1 = Balloc(b->k+1);
-			if (b1 == BIGINT_INVALID) {
-				Bfree(b);
-				return b1;
-			}
-			Bcopy_valid(b1, b);
-			Bfree(b);
-			b = b1;
-			}
-		b->x[wds++] = a;
-		b->wds = wds;
-	}
-	return b;
-}
-
- static Bigint *
-s2b
-#ifdef KR_headers
-	(s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9;
-#else
-	(CONST char *s, int nd0, int nd, ULong y9)
-#endif
-{
-	Bigint *b;
-	int i, k;
-	Long x, y;
-
-	x = (nd + 8) / 9;
-	for(k = 0, y = 1; x > y; y <<= 1, k++) ;
-#ifdef Pack_32
-	b = Balloc(k);
-	if (b == BIGINT_INVALID)
-		return b;
-	b->x[0] = y9;
-	b->wds = 1;
-#else
-	b = Balloc(k+1);
-	if (b == BIGINT_INVALID)
-		return b;
-
-	b->x[0] = y9 & 0xffff;
-	b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
-#endif
-
-	i = 9;
-	if (9 < nd0) {
-		s += 9;
-		do b = multadd(b, 10, *s++ - '0');
-			while(++i < nd0);
-		s++;
-	}
-	else
-		s += 10;
-	for(; i < nd; i++)
-		b = multadd(b, 10, *s++ - '0');
-	return b;
-}
-
- static int
-hi0bits
-#ifdef KR_headers
-	(x) ULong x;
-#else
-	(ULong x)
-#endif
-{
-	int k = 0;
-
-	if (!(x & 0xffff0000)) {
-		k = 16;
-		x <<= 16;
-	}
-	if (!(x & 0xff000000)) {
-		k += 8;
-		x <<= 8;
-	}
-	if (!(x & 0xf0000000)) {
-		k += 4;
-		x <<= 4;
-	}
-	if (!(x & 0xc0000000)) {
-		k += 2;
-		x <<= 2;
-	}
-	if (!(x & 0x80000000)) {
-		k++;
-		if (!(x & 0x40000000))
-			return 32;
-	}
-	return k;
-}
-
- static int
-lo0bits
-#ifdef KR_headers
-	(y) ULong *y;
-#else
-	(ULong *y)
-#endif
-{
-	int k;
-	ULong x = *y;
-
-	if (x & 7) {
-		if (x & 1)
-			return 0;
-		if (x & 2) {
-			*y = x >> 1;
-			return 1;
-			}
-		*y = x >> 2;
-		return 2;
-	}
-	k = 0;
-	if (!(x & 0xffff)) {
-		k = 16;
-		x >>= 16;
-	}
-	if (!(x & 0xff)) {
-		k += 8;
-		x >>= 8;
-	}
-	if (!(x & 0xf)) {
-		k += 4;
-		x >>= 4;
-	}
-	if (!(x & 0x3)) {
-		k += 2;
-		x >>= 2;
-	}
-	if (!(x & 1)) {
-		k++;
-		x >>= 1;
-		if (!x & 1)
-			return 32;
-	}
-	*y = x;
-	return k;
-}
-
- static Bigint *
-i2b
-#ifdef KR_headers
-	(i) int i;
-#else
-	(int i)
-#endif
-{
-	Bigint *b;
-
-	b = Balloc(1);
-	if (b != BIGINT_INVALID) {
-		b->x[0] = i;
-		b->wds = 1;
-		}
-	return b;
-}
-
- static Bigint *
-mult
-#ifdef KR_headers
-	(a, b) Bigint *a, *b;
-#else
-	(Bigint *a, Bigint *b)
-#endif
-{
-	Bigint *c;
-	int k, wa, wb, wc;
-	ULong carry, y, z;
-	ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
-#ifdef Pack_32
-	ULong z2;
-#endif
-
-	if (a == BIGINT_INVALID || b == BIGINT_INVALID)
-		return BIGINT_INVALID;
-
-	if (a->wds < b->wds) {
-		c = a;
-		a = b;
-		b = c;
-	}
-	k = a->k;
-	wa = a->wds;
-	wb = b->wds;
-	wc = wa + wb;
-	if (wc > a->maxwds)
-		k++;
-	c = Balloc(k);
-	if (c == BIGINT_INVALID)
-		return c;
-	for(x = c->x, xa = x + wc; x < xa; x++)
-		*x = 0;
-	xa = a->x;
-	xae = xa + wa;
-	xb = b->x;
-	xbe = xb + wb;
-	xc0 = c->x;
-#ifdef Pack_32
-	for(; xb < xbe; xb++, xc0++) {
-		if ((y = *xb & 0xffff) != 0) {
-			x = xa;
-			xc = xc0;
-			carry = 0;
-			do {
-				z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
-				carry = z >> 16;
-				z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
-				carry = z2 >> 16;
-				Storeinc(xc, z2, z);
-			}
-			while(x < xae);
-			*xc = carry;
-		}
-		if ((y = *xb >> 16) != 0) {
-			x = xa;
-			xc = xc0;
-			carry = 0;
-			z2 = *xc;
-			do {
-				z = (*x & 0xffff) * y + (*xc >> 16) + carry;
-				carry = z >> 16;
-				Storeinc(xc, z, z2);
-				z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
-				carry = z2 >> 16;
-			}
-			while(x < xae);
-			*xc = z2;
-		}
-	}
-#else
-	for(; xb < xbe; xc0++) {
-		if (y = *xb++) {
-			x = xa;
-			xc = xc0;
-			carry = 0;
-			do {
-				z = *x++ * y + *xc + carry;
-				carry = z >> 16;
-				*xc++ = z & 0xffff;
-			}
-			while(x < xae);
-			*xc = carry;
-		}
-	}
-#endif
-	for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
-	c->wds = wc;
-	return c;
-}
-
- static Bigint *p5s;
- static pthread_mutex_t p5s_mutex = PTHREAD_MUTEX_INITIALIZER;
-
- static Bigint *
-pow5mult
-#ifdef KR_headers
-	(b, k) Bigint *b; int k;
-#else
-	(Bigint *b, int k)
-#endif
-{
-	Bigint *b1, *p5, *p51;
-	int i;
-	static const int p05[3] = { 5, 25, 125 };
-
-	if (b == BIGINT_INVALID)
-		return b;
-
-	if ((i = k & 3) != 0)
-		b = multadd(b, p05[i-1], 0);
-
-	if (!(k = (unsigned int) k >> 2))
-		return b;
-	mutex_lock(&p5s_mutex);
-	if (!(p5 = p5s)) {
-		/* first time */
-		p5 = i2b(625);
-		if (p5 == BIGINT_INVALID) {
-			Bfree(b);
-			mutex_unlock(&p5s_mutex);
-			return p5;
-		}
-		p5s = p5;
-		p5->next = 0;
-	}
-	for(;;) {
-		if (k & 1) {
-			b1 = mult(b, p5);
-			Bfree(b);
-			b = b1;
-		}
-		if (!(k = (unsigned int) k >> 1))
-			break;
-		if (!(p51 = p5->next)) {
-			p51 = mult(p5,p5);
-			if (p51 == BIGINT_INVALID) {
-				Bfree(b);
-				mutex_unlock(&p5s_mutex);
-				return p51;
-			}
-			p5->next = p51;
-			p51->next = 0;
-		}
-		p5 = p51;
-	}
-	mutex_unlock(&p5s_mutex);
-	return b;
-}
-
- static Bigint *
-lshift
-#ifdef KR_headers
-	(b, k) Bigint *b; int k;
-#else
-	(Bigint *b, int k)
-#endif
-{
-	int i, k1, n, n1;
-	Bigint *b1;
-	ULong *x, *x1, *xe, z;
-
-	if (b == BIGINT_INVALID)
-		return b;
-
-#ifdef Pack_32
-	n = (unsigned int)k >> 5;
-#else
-	n = (unsigned int)k >> 4;
-#endif
-	k1 = b->k;
-	n1 = n + b->wds + 1;
-	for(i = b->maxwds; n1 > i; i <<= 1)
-		k1++;
-	b1 = Balloc(k1);
-	if (b1 == BIGINT_INVALID) {
-		Bfree(b);
-		return b1;
-	}
-	x1 = b1->x;
-	for(i = 0; i < n; i++)
-		*x1++ = 0;
-	x = b->x;
-	xe = x + b->wds;
-#ifdef Pack_32
-	if (k &= 0x1f) {
-		k1 = 32 - k;
-		z = 0;
-		do {
-			*x1++ = *x << k | z;
-			z = *x++ >> k1;
-		}
-		while(x < xe);
-		if ((*x1 = z) != 0)
-			++n1;
-	}
-#else
-	if (k &= 0xf) {
-		k1 = 16 - k;
-		z = 0;
-		do {
-			*x1++ = *x << k  & 0xffff | z;
-			z = *x++ >> k1;
-		}
-		while(x < xe);
-		if (*x1 = z)
-			++n1;
-	}
-#endif
-	else do
-		*x1++ = *x++;
-		while(x < xe);
-	b1->wds = n1 - 1;
-	Bfree(b);
-	return b1;
-}
-
- static int
-cmp
-#ifdef KR_headers
-	(a, b) Bigint *a, *b;
-#else
-	(Bigint *a, Bigint *b)
-#endif
-{
-	ULong *xa, *xa0, *xb, *xb0;
-	int i, j;
-
-	if (a == BIGINT_INVALID || b == BIGINT_INVALID)
-#ifdef DEBUG
-		Bug("cmp called with a or b invalid");
-#else
-		return 0; /* equal - the best we can do right now */
-#endif
-
-	i = a->wds;
-	j = b->wds;
-#ifdef DEBUG
-	if (i > 1 && !a->x[i-1])
-		Bug("cmp called with a->x[a->wds-1] == 0");
-	if (j > 1 && !b->x[j-1])
-		Bug("cmp called with b->x[b->wds-1] == 0");
-#endif
-	if (i -= j)
-		return i;
-	xa0 = a->x;
-	xa = xa0 + j;
-	xb0 = b->x;
-	xb = xb0 + j;
-	for(;;) {
-		if (*--xa != *--xb)
-			return *xa < *xb ? -1 : 1;
-		if (xa <= xa0)
-			break;
-	}
-	return 0;
-}
-
- static Bigint *
-diff
-#ifdef KR_headers
-	(a, b) Bigint *a, *b;
-#else
-	(Bigint *a, Bigint *b)
-#endif
-{
-	Bigint *c;
-	int i, wa, wb;
-	Long borrow, y;	/* We need signed shifts here. */
-	ULong *xa, *xae, *xb, *xbe, *xc;
-#ifdef Pack_32
-	Long z;
-#endif
-
-	if (a == BIGINT_INVALID || b == BIGINT_INVALID)
-		return BIGINT_INVALID;
-
-	i = cmp(a,b);
-	if (!i) {
-		c = Balloc(0);
-		if (c != BIGINT_INVALID) {
-			c->wds = 1;
-			c->x[0] = 0;
-			}
-		return c;
-	}
-	if (i < 0) {
-		c = a;
-		a = b;
-		b = c;
-		i = 1;
-	}
-	else
-		i = 0;
-	c = Balloc(a->k);
-	if (c == BIGINT_INVALID)
-		return c;
-	c->sign = i;
-	wa = a->wds;
-	xa = a->x;
-	xae = xa + wa;
-	wb = b->wds;
-	xb = b->x;
-	xbe = xb + wb;
-	xc = c->x;
-	borrow = 0;
-#ifdef Pack_32
-	do {
-		y = (*xa & 0xffff) - (*xb & 0xffff) + borrow;
-		borrow = (ULong)y >> 16;
-		Sign_Extend(borrow, y);
-		z = (*xa++ >> 16) - (*xb++ >> 16) + borrow;
-		borrow = (ULong)z >> 16;
-		Sign_Extend(borrow, z);
-		Storeinc(xc, z, y);
-	}
-	while(xb < xbe);
-	while(xa < xae) {
-		y = (*xa & 0xffff) + borrow;
-		borrow = (ULong)y >> 16;
-		Sign_Extend(borrow, y);
-		z = (*xa++ >> 16) + borrow;
-		borrow = (ULong)z >> 16;
-		Sign_Extend(borrow, z);
-		Storeinc(xc, z, y);
-	}
-#else
-	do {
-		y = *xa++ - *xb++ + borrow;
-		borrow = y >> 16;
-		Sign_Extend(borrow, y);
-		*xc++ = y & 0xffff;
-	}
-	while(xb < xbe);
-	while(xa < xae) {
-		y = *xa++ + borrow;
-		borrow = y >> 16;
-		Sign_Extend(borrow, y);
-		*xc++ = y & 0xffff;
-	}
-#endif
-	while(!*--xc)
-		wa--;
-	c->wds = wa;
-	return c;
-}
-
- static double
-ulp
-#ifdef KR_headers
-	(_x) double _x;
-#else
-	(double _x)
-#endif
-{
-	_double x;
-	Long L;
-	_double a;
-
-	value(x) = _x;
-	L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
-#ifndef Sudden_Underflow
-	if (L > 0) {
-#endif
-#ifdef IBM
-		L |= Exp_msk1 >> 4;
-#endif
-		word0(a) = L;
-		word1(a) = 0;
-#ifndef Sudden_Underflow
-	}
-	else {
-		L = (ULong)-L >> Exp_shift;
-		if (L < Exp_shift) {
-			word0(a) = 0x80000 >> L;
-			word1(a) = 0;
-		}
-		else {
-			word0(a) = 0;
-			L -= Exp_shift;
-			word1(a) = L >= 31 ? 1 : 1 << (31 - L);
-		}
-	}
-#endif
-	return value(a);
-}
-
- static double
-b2d
-#ifdef KR_headers
-	(a, e) Bigint *a; int *e;
-#else
-	(Bigint *a, int *e)
-#endif
-{
-	ULong *xa, *xa0, w, y, z;
-	int k;
-	_double d;
-#ifdef VAX
-	ULong d0, d1;
-#else
-#define d0 word0(d)
-#define d1 word1(d)
-#endif
-
-	if (a == BIGINT_INVALID)
-		return NAN;
-
-	xa0 = a->x;
-	xa = xa0 + a->wds;
-	y = *--xa;
-#ifdef DEBUG
-	if (!y) Bug("zero y in b2d");
-#endif
-	k = hi0bits(y);
-	*e = 32 - k;
-#ifdef Pack_32
-	if (k < Ebits) {
-		d0 = Exp_1 | y >> (Ebits - k);
-		w = xa > xa0 ? *--xa : 0;
-		d1 = y << ((32-Ebits) + k) | w >> (Ebits - k);
-		goto ret_d;
-	}
-	z = xa > xa0 ? *--xa : 0;
-	if (k -= Ebits) {
-		d0 = Exp_1 | y << k | z >> (32 - k);
-		y = xa > xa0 ? *--xa : 0;
-		d1 = z << k | y >> (32 - k);
-	}
-	else {
-		d0 = Exp_1 | y;
-		d1 = z;
-	}
-#else
-	if (k < Ebits + 16) {
-		z = xa > xa0 ? *--xa : 0;
-		d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k;
-		w = xa > xa0 ? *--xa : 0;
-		y = xa > xa0 ? *--xa : 0;
-		d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
-		goto ret_d;
-	}
-	z = xa > xa0 ? *--xa : 0;
-	w = xa > xa0 ? *--xa : 0;
-	k -= Ebits + 16;
-	d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k;
-	y = xa > xa0 ? *--xa : 0;
-	d1 = w << k + 16 | y << k;
-#endif
- ret_d:
-#ifdef VAX
-	word0(d) = d0 >> 16 | d0 << 16;
-	word1(d) = d1 >> 16 | d1 << 16;
-#else
-#undef d0
-#undef d1
-#endif
-	return value(d);
-}
-
- static Bigint *
-d2b
-#ifdef KR_headers
-	(_d, e, bits) double d; int *e, *bits;
-#else
-	(double _d, int *e, int *bits)
-#endif
-{
-	Bigint *b;
-	int de, i, k;
-	ULong *x, y, z;
-	_double d;
-#ifdef VAX
-	ULong d0, d1;
-#endif
-
-	value(d) = _d;
-#ifdef VAX
-	d0 = word0(d) >> 16 | word0(d) << 16;
-	d1 = word1(d) >> 16 | word1(d) << 16;
-#else
-#define d0 word0(d)
-#define d1 word1(d)
-#endif
-
-#ifdef Pack_32
-	b = Balloc(1);
-#else
-	b = Balloc(2);
-#endif
-	if (b == BIGINT_INVALID)
-		return b;
-	x = b->x;
-
-	z = d0 & Frac_mask;
-	d0 &= 0x7fffffff;	/* clear sign bit, which we ignore */
-#ifdef Sudden_Underflow
-	de = (int)(d0 >> Exp_shift);
-#ifndef IBM
-	z |= Exp_msk11;
-#endif
-#else
-	if ((de = (int)(d0 >> Exp_shift)) != 0)
-		z |= Exp_msk1;
-#endif
-#ifdef Pack_32
-	if ((y = d1) != 0) {
-		if ((k = lo0bits(&y)) != 0) {
-			x[0] = y | z << (32 - k);
-			z >>= k;
-		}
-		else
-			x[0] = y;
-		i = b->wds = (x[1] = z) ? 2 : 1;
-	}
-	else {
-#ifdef DEBUG
-		if (!z)
-			Bug("Zero passed to d2b");
-#endif
-		k = lo0bits(&z);
-		x[0] = z;
-		i = b->wds = 1;
-		k += 32;
-	}
-#else
-	if (y = d1) {
-		if (k = lo0bits(&y))
-			if (k >= 16) {
-				x[0] = y | z << 32 - k & 0xffff;
-				x[1] = z >> k - 16 & 0xffff;
-				x[2] = z >> k;
-				i = 2;
-			}
-			else {
-				x[0] = y & 0xffff;
-				x[1] = y >> 16 | z << 16 - k & 0xffff;
-				x[2] = z >> k & 0xffff;
-				x[3] = z >> k+16;
-				i = 3;
-			}
-		else {
-			x[0] = y & 0xffff;
-			x[1] = y >> 16;
-			x[2] = z & 0xffff;
-			x[3] = z >> 16;
-			i = 3;
-		}
-	}
-	else {
-#ifdef DEBUG
-		if (!z)
-			Bug("Zero passed to d2b");
-#endif
-		k = lo0bits(&z);
-		if (k >= 16) {
-			x[0] = z;
-			i = 0;
-		}
-		else {
-			x[0] = z & 0xffff;
-			x[1] = z >> 16;
-			i = 1;
-		}
-		k += 32;
-	}
-	while(!x[i])
-		--i;
-	b->wds = i + 1;
-#endif
-#ifndef Sudden_Underflow
-	if (de) {
-#endif
-#ifdef IBM
-		*e = (de - Bias - (P-1) << 2) + k;
-		*bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask);
-#else
-		*e = de - Bias - (P-1) + k;
-		*bits = P - k;
-#endif
-#ifndef Sudden_Underflow
-	}
-	else {
-		*e = de - Bias - (P-1) + 1 + k;
-#ifdef Pack_32
-		*bits = 32*i - hi0bits(x[i-1]);
-#else
-		*bits = (i+2)*16 - hi0bits(x[i]);
-#endif
-		}
-#endif
-	return b;
-}
-#undef d0
-#undef d1
-
- static double
-ratio
-#ifdef KR_headers
-	(a, b) Bigint *a, *b;
-#else
-	(Bigint *a, Bigint *b)
-#endif
-{
-	_double da, db;
-	int k, ka, kb;
-
-	if (a == BIGINT_INVALID || b == BIGINT_INVALID)
-		return NAN; /* for lack of better value ? */
-
-	value(da) = b2d(a, &ka);
-	value(db) = b2d(b, &kb);
-#ifdef Pack_32
-	k = ka - kb + 32*(a->wds - b->wds);
-#else
-	k = ka - kb + 16*(a->wds - b->wds);
-#endif
-#ifdef IBM
-	if (k > 0) {
-		word0(da) += (k >> 2)*Exp_msk1;
-		if (k &= 3)
-			da *= 1 << k;
-	}
-	else {
-		k = -k;
-		word0(db) += (k >> 2)*Exp_msk1;
-		if (k &= 3)
-			db *= 1 << k;
-	}
-#else
-	if (k > 0)
-		word0(da) += k*Exp_msk1;
-	else {
-		k = -k;
-		word0(db) += k*Exp_msk1;
-	}
-#endif
-	return value(da) / value(db);
-}
-
-static CONST double
-tens[] = {
-		1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
-		1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
-		1e20, 1e21, 1e22
-#ifdef VAX
-		, 1e23, 1e24
-#endif
-};
-
-#ifdef IEEE_Arith
-static CONST double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
-static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 };
-#define n_bigtens 5
-#else
-#ifdef IBM
-static CONST double bigtens[] = { 1e16, 1e32, 1e64 };
-static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 };
-#define n_bigtens 3
-#else
-static CONST double bigtens[] = { 1e16, 1e32 };
-static CONST double tinytens[] = { 1e-16, 1e-32 };
-#define n_bigtens 2
-#endif
-#endif
-
- double
-strtod
-#ifdef KR_headers
-	(s00, se) CONST char *s00; char **se;
-#else
-	(CONST char *s00, char **se)
-#endif
-{
-	int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
-		 e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
-	CONST char *s, *s0, *s1;
-	double aadj, aadj1, adj;
-	_double rv, rv0;
-	Long L;
-	ULong y, z;
-	Bigint *bb1, *bd0;
-	Bigint *bb = NULL, *bd = NULL, *bs = NULL, *delta = NULL;/* pacify gcc */
-
-#ifdef ANDROID_CHANGES
-	CONST char decimal_point = '.';
-#else /* ANDROID_CHANGES */
-#ifndef KR_headers
-	CONST char decimal_point = localeconv()->decimal_point[0];
-#else
-	CONST char decimal_point = '.';
-#endif
-
-#endif /* ANDROID_CHANGES */
-
-	sign = nz0 = nz = 0;
-	value(rv) = 0.;
-
-
-	for(s = s00; isspace((unsigned char) *s); s++)
-		;
-
-	if (*s == '-') {
-		sign = 1;
-		s++;
-	} else if (*s == '+') {
-		s++;
-	}
-
-	if (*s == '\0') {
-		s = s00;
-		goto ret;
-	}
-
-	/* "INF" or "INFINITY" */
-	if (tolower((unsigned char)*s) == 'i' && strncasecmp(s, "inf", 3) == 0) {
-		if (strncasecmp(s + 3, "inity", 5) == 0)
-			s += 8;
-		else
-			s += 3;
-
-		value(rv) = HUGE_VAL;
-		goto ret;
-	}
-
-#ifdef IEEE_Arith
-	/* "NAN" or "NAN(n-char-sequence-opt)" */
-	if (tolower((unsigned char)*s) == 'n' && strncasecmp(s, "nan", 3) == 0) {
-		/* Build a quiet NaN. */
-		word0(rv) = NAN_WORD0;
-		word1(rv) = NAN_WORD1;
-		s+= 3;
-
-		/* Don't interpret (n-char-sequence-opt), for now. */
-		if (*s == '(') {
-			s0 = s;
-			for (s++; *s != ')' && *s != '\0'; s++)
-				;
-			if (*s == ')')
-				s++;	/* Skip over closing paren ... */
-			else
-				s = s0;	/* ... otherwise go back. */
-		}
-
-		goto ret;
-	}
-#endif
-
-	if (*s == '0') {
-		nz0 = 1;
-		while(*++s == '0') ;
-		if (!*s)
-			goto ret;
-	}
-	s0 = s;
-	y = z = 0;
-	for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
-		if (nd < 9)
-			y = 10*y + c - '0';
-		else if (nd < 16)
-			z = 10*z + c - '0';
-	nd0 = nd;
-	if (c == decimal_point) {
-		c = *++s;
-		if (!nd) {
-			for(; c == '0'; c = *++s)
-				nz++;
-			if (c > '0' && c <= '9') {
-				s0 = s;
-				nf += nz;
-				nz = 0;
-				goto have_dig;
-				}
-			goto dig_done;
-		}
-		for(; c >= '0' && c <= '9'; c = *++s) {
- have_dig:
-			nz++;
-			if (c -= '0') {
-				nf += nz;
-				for(i = 1; i < nz; i++)
-					if (nd++ < 9)
-						y *= 10;
-					else if (nd <= DBL_DIG + 1)
-						z *= 10;
-				if (nd++ < 9)
-					y = 10*y + c;
-				else if (nd <= DBL_DIG + 1)
-					z = 10*z + c;
-				nz = 0;
-			}
-		}
-	}
- dig_done:
-	e = 0;
-	if (c == 'e' || c == 'E') {
-		if (!nd && !nz && !nz0) {
-			s = s00;
-			goto ret;
-		}
-		s00 = s;
-		esign = 0;
-		switch(c = *++s) {
-			case '-':
-				esign = 1;
-				/* FALLTHROUGH */
-			case '+':
-				c = *++s;
-		}
-		if (c >= '0' && c <= '9') {
-			while(c == '0')
-				c = *++s;
-			if (c > '0' && c <= '9') {
-				L = c - '0';
-				s1 = s;
-				while((c = *++s) >= '0' && c <= '9')
-					L = 10*L + c - '0';
-				if (s - s1 > 8 || L > 19999)
-					/* Avoid confusion from exponents
-					 * so large that e might overflow.
-					 */
-					e = 19999; /* safe for 16 bit ints */
-				else
-					e = (int)L;
-				if (esign)
-					e = -e;
-			}
-			else
-				e = 0;
-		}
-		else
-			s = s00;
-	}
-	if (!nd) {
-		if (!nz && !nz0)
-			s = s00;
-		goto ret;
-	}
-	e1 = e -= nf;
-
-	/* Now we have nd0 digits, starting at s0, followed by a
-	 * decimal point, followed by nd-nd0 digits.  The number we're
-	 * after is the integer represented by those digits times
-	 * 10**e */
-
-	if (!nd0)
-		nd0 = nd;
-	k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
-	value(rv) = y;
-	if (k > 9)
-		value(rv) = tens[k - 9] * value(rv) + z;
-	bd0 = 0;
-	if (nd <= DBL_DIG
-#ifndef RND_PRODQUOT
-		&& FLT_ROUNDS == 1
-#endif
-		) {
-		if (!e)
-			goto ret;
-		if (e > 0) {
-			if (e <= Ten_pmax) {
-#ifdef VAX
-				goto vax_ovfl_check;
-#else
-				/* value(rv) = */ rounded_product(value(rv),
-				    tens[e]);
-				goto ret;
-#endif
-			}
-			i = DBL_DIG - nd;
-			if (e <= Ten_pmax + i) {
-				/* A fancier test would sometimes let us do
-				 * this for larger i values.
-				 */
-				e -= i;
-				value(rv) *= tens[i];
-#ifdef VAX
-				/* VAX exponent range is so narrow we must
-				 * worry about overflow here...
-				 */
- vax_ovfl_check:
-				word0(rv) -= P*Exp_msk1;
-				/* value(rv) = */ rounded_product(value(rv),
-				    tens[e]);
-				if ((word0(rv) & Exp_mask)
-				 > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
-					goto ovfl;
-				word0(rv) += P*Exp_msk1;
-#else
-				/* value(rv) = */ rounded_product(value(rv),
-				    tens[e]);
-#endif
-				goto ret;
-			}
-		}
-#ifndef Inaccurate_Divide
-		else if (e >= -Ten_pmax) {
-			/* value(rv) = */ rounded_quotient(value(rv),
-			    tens[-e]);
-			goto ret;
-		}
-#endif
-	}
-	e1 += nd - k;
-
-	/* Get starting approximation = rv * 10**e1 */
-
-	if (e1 > 0) {
-		if ((i = e1 & 15) != 0)
-			value(rv) *= tens[i];
-		if (e1 &= ~15) {
-			if (e1 > DBL_MAX_10_EXP) {
- ovfl:
-				errno = ERANGE;
-				value(rv) = HUGE_VAL;
-				if (bd0)
-					goto retfree;
-				goto ret;
-			}
-			if ((e1 = (unsigned int)e1 >> 4) != 0) {
-				for(j = 0; e1 > 1; j++,
-				    e1 = (unsigned int)e1 >> 1)
-					if (e1 & 1)
-						value(rv) *= bigtens[j];
-			/* The last multiplication could overflow. */
-				word0(rv) -= P*Exp_msk1;
-				value(rv) *= bigtens[j];
-				if ((z = word0(rv) & Exp_mask)
-				 > Exp_msk1*(DBL_MAX_EXP+Bias-P))
-					goto ovfl;
-				if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
-					/* set to largest number */
-					/* (Can't trust DBL_MAX) */
-					word0(rv) = Big0;
-					word1(rv) = Big1;
-					}
-				else
-					word0(rv) += P*Exp_msk1;
-			}
-		}
-	}
-	else if (e1 < 0) {
-		e1 = -e1;
-		if ((i = e1 & 15) != 0)
-			value(rv) /= tens[i];
-		if (e1 &= ~15) {
-			e1 = (unsigned int)e1 >> 4;
-			if (e1 >= 1 << n_bigtens)
-				goto undfl;
-			for(j = 0; e1 > 1; j++,
-			    e1 = (unsigned int)e1 >> 1)
-				if (e1 & 1)
-					value(rv) *= tinytens[j];
-			/* The last multiplication could underflow. */
-			value(rv0) = value(rv);
-			value(rv) *= tinytens[j];
-			if (!value(rv)) {
-				value(rv) = 2.*value(rv0);
-				value(rv) *= tinytens[j];
-				if (!value(rv)) {
- undfl:
-					value(rv) = 0.;
-					errno = ERANGE;
-					if (bd0)
-						goto retfree;
-					goto ret;
-				}
-				word0(rv) = Tiny0;
-				word1(rv) = Tiny1;
-				/* The refinement below will clean
-				 * this approximation up.
-				 */
-			}
-		}
-	}
-
-	/* Now the hard part -- adjusting rv to the correct value.*/
-
-	/* Put digits into bd: true value = bd * 10^e */
-
-	bd0 = s2b(s0, nd0, nd, y);
-
-	for(;;) {
-		bd = Balloc(bd0->k);
-		Bcopy(bd, bd0);
-		bb = d2b(value(rv), &bbe, &bbbits);	/* rv = bb * 2^bbe */
-		bs = i2b(1);
-
-		if (e >= 0) {
-			bb2 = bb5 = 0;
-			bd2 = bd5 = e;
-		}
-		else {
-			bb2 = bb5 = -e;
-			bd2 = bd5 = 0;
-		}
-		if (bbe >= 0)
-			bb2 += bbe;
-		else
-			bd2 -= bbe;
-		bs2 = bb2;
-#ifdef Sudden_Underflow
-#ifdef IBM
-		j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
-#else
-		j = P + 1 - bbbits;
-#endif
-#else
-		i = bbe + bbbits - 1;	/* logb(rv) */
-		if (i < Emin)	/* denormal */
-			j = bbe + (P-Emin);
-		else
-			j = P + 1 - bbbits;
-#endif
-		bb2 += j;
-		bd2 += j;
-		i = bb2 < bd2 ? bb2 : bd2;
-		if (i > bs2)
-			i = bs2;
-		if (i > 0) {
-			bb2 -= i;
-			bd2 -= i;
-			bs2 -= i;
-		}
-		if (bb5 > 0) {
-			bs = pow5mult(bs, bb5);
-			bb1 = mult(bs, bb);
-			Bfree(bb);
-			bb = bb1;
-		}
-		if (bb2 > 0)
-			bb = lshift(bb, bb2);
-		if (bd5 > 0)
-			bd = pow5mult(bd, bd5);
-		if (bd2 > 0)
-			bd = lshift(bd, bd2);
-		if (bs2 > 0)
-			bs = lshift(bs, bs2);
-		delta = diff(bb, bd);
-		dsign = delta->sign;
-		delta->sign = 0;
-		i = cmp(delta, bs);
-		if (i < 0) {
-			/* Error is less than half an ulp -- check for
-			 * special case of mantissa a power of two.
-			 */
-			if (dsign || word1(rv) || word0(rv) & Bndry_mask)
-				break;
-			delta = lshift(delta,Log2P);
-			if (cmp(delta, bs) > 0)
-				goto drop_down;
-			break;
-		}
-		if (i == 0) {
-			/* exactly half-way between */
-			if (dsign) {
-				if ((word0(rv) & Bndry_mask1) == Bndry_mask1
-				 &&  word1(rv) == 0xffffffff) {
-					/*boundary case -- increment exponent*/
-					word0(rv) = (word0(rv) & Exp_mask)
-						+ Exp_msk1
-#ifdef IBM
-						| Exp_msk1 >> 4
-#endif
-						;
-					word1(rv) = 0;
-					break;
-				}
-			}
-			else if (!(word0(rv) & Bndry_mask) && !word1(rv)) {
- drop_down:
-				/* boundary case -- decrement exponent */
-#ifdef Sudden_Underflow
-				L = word0(rv) & Exp_mask;
-#ifdef IBM
-				if (L <  Exp_msk1)
-#else
-				if (L <= Exp_msk1)
-#endif
-					goto undfl;
-				L -= Exp_msk1;
-#else
-				L = (word0(rv) & Exp_mask) - Exp_msk1;
-#endif
-				word0(rv) = L | Bndry_mask1;
-				word1(rv) = 0xffffffff;
-#ifdef IBM
-				goto cont;
-#else
-				break;
-#endif
-			}
-#ifndef ROUND_BIASED
-			if (!(word1(rv) & LSB))
-				break;
-#endif
-			if (dsign)
-				value(rv) += ulp(value(rv));
-#ifndef ROUND_BIASED
-			else {
-				value(rv) -= ulp(value(rv));
-#ifndef Sudden_Underflow
-				if (!value(rv))
-					goto undfl;
-#endif
-			}
-#endif
-			break;
-		}
-		if ((aadj = ratio(delta, bs)) <= 2.) {
-			if (dsign)
-				aadj = aadj1 = 1.;
-			else if (word1(rv) || word0(rv) & Bndry_mask) {
-#ifndef Sudden_Underflow
-				if (word1(rv) == Tiny1 && !word0(rv))
-					goto undfl;
-#endif
-				aadj = 1.;
-				aadj1 = -1.;
-			}
-			else {
-				/* special case -- power of FLT_RADIX to be */
-				/* rounded down... */
-
-				if (aadj < 2./FLT_RADIX)
-					aadj = 1./FLT_RADIX;
-				else
-					aadj *= 0.5;
-				aadj1 = -aadj;
-				}
-		}
-		else {
-			aadj *= 0.5;
-			aadj1 = dsign ? aadj : -aadj;
-#ifdef Check_FLT_ROUNDS
-			switch(FLT_ROUNDS) {
-				case 2: /* towards +infinity */
-					aadj1 -= 0.5;
-					break;
-				case 0: /* towards 0 */
-				case 3: /* towards -infinity */
-					aadj1 += 0.5;
-			}
-#else
-			if (FLT_ROUNDS == 0)
-				aadj1 += 0.5;
-#endif
-		}
-		y = word0(rv) & Exp_mask;
-
-		/* Check for overflow */
-
-		if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
-			value(rv0) = value(rv);
-			word0(rv) -= P*Exp_msk1;
-			adj = aadj1 * ulp(value(rv));
-			value(rv) += adj;
-			if ((word0(rv) & Exp_mask) >=
-					Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
-				if (word0(rv0) == Big0 && word1(rv0) == Big1)
-					goto ovfl;
-				word0(rv) = Big0;
-				word1(rv) = Big1;
-				goto cont;
-			}
-			else
-				word0(rv) += P*Exp_msk1;
-		}
-		else {
-#ifdef Sudden_Underflow
-			if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {
-				value(rv0) = value(rv);
-				word0(rv) += P*Exp_msk1;
-				adj = aadj1 * ulp(value(rv));
-				value(rv) += adj;
-#ifdef IBM
-				if ((word0(rv) & Exp_mask) <  P*Exp_msk1)
-#else
-				if ((word0(rv) & Exp_mask) <= P*Exp_msk1)
-#endif
-				{
-					if (word0(rv0) == Tiny0
-					 && word1(rv0) == Tiny1)
-						goto undfl;
-					word0(rv) = Tiny0;
-					word1(rv) = Tiny1;
-					goto cont;
-				}
-				else
-					word0(rv) -= P*Exp_msk1;
-				}
-			else {
-				adj = aadj1 * ulp(value(rv));
-				value(rv) += adj;
-			}
-#else
-			/* Compute adj so that the IEEE rounding rules will
-			 * correctly round rv + adj in some half-way cases.
-			 * If rv * ulp(rv) is denormalized (i.e.,
-			 * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
-			 * trouble from bits lost to denormalization;
-			 * example: 1.2e-307 .
-			 */
-			if (y <= (P-1)*Exp_msk1 && aadj >= 1.) {
-				aadj1 = (double)(int)(aadj + 0.5);
-				if (!dsign)
-					aadj1 = -aadj1;
-			}
-			adj = aadj1 * ulp(value(rv));
-			value(rv) += adj;
-#endif
-		}
-		z = word0(rv) & Exp_mask;
-		if (y == z) {
-			/* Can we stop now? */
-			L = aadj;
-			aadj -= L;
-			/* The tolerances below are conservative. */
-			if (dsign || word1(rv) || word0(rv) & Bndry_mask) {
-				if (aadj < .4999999 || aadj > .5000001)
-					break;
-			}
-			else if (aadj < .4999999/FLT_RADIX)
-				break;
-		}
- cont:
-		Bfree(bb);
-		Bfree(bd);
-		Bfree(bs);
-		Bfree(delta);
-	}
- retfree:
-	Bfree(bb);
-	Bfree(bd);
-	Bfree(bs);
-	Bfree(bd0);
-	Bfree(delta);
- ret:
-	if (se)
-		/* LINTED interface specification */
-		*se = (char *)s;
-	return sign ? -value(rv) : value(rv);
-}
-
- static int
-quorem
-#ifdef KR_headers
-	(b, S) Bigint *b, *S;
-#else
-	(Bigint *b, Bigint *S)
-#endif
-{
-	int n;
-	Long borrow, y;
-	ULong carry, q, ys;
-	ULong *bx, *bxe, *sx, *sxe;
-#ifdef Pack_32
-	Long z;
-	ULong si, zs;
-#endif
-
-	if (b == BIGINT_INVALID || S == BIGINT_INVALID)
-		return 0;
-
-	n = S->wds;
-#ifdef DEBUG
-	/*debug*/ if (b->wds > n)
-	/*debug*/	Bug("oversize b in quorem");
-#endif
-	if (b->wds < n)
-		return 0;
-	sx = S->x;
-	sxe = sx + --n;
-	bx = b->x;
-	bxe = bx + n;
-	q = *bxe / (*sxe + 1);	/* ensure q <= true quotient */
-#ifdef DEBUG
-	/*debug*/ if (q > 9)
-	/*debug*/	Bug("oversized quotient in quorem");
-#endif
-	if (q) {
-		borrow = 0;
-		carry = 0;
-		do {
-#ifdef Pack_32
-			si = *sx++;
-			ys = (si & 0xffff) * q + carry;
-			zs = (si >> 16) * q + (ys >> 16);
-			carry = zs >> 16;
-			y = (*bx & 0xffff) - (ys & 0xffff) + borrow;
-			borrow = (ULong)y >> 16;
-			Sign_Extend(borrow, y);
-			z = (*bx >> 16) - (zs & 0xffff) + borrow;
-			borrow = (ULong)z >> 16;
-			Sign_Extend(borrow, z);
-			Storeinc(bx, z, y);
-#else
-			ys = *sx++ * q + carry;
-			carry = ys >> 16;
-			y = *bx - (ys & 0xffff) + borrow;
-			borrow = y >> 16;
-			Sign_Extend(borrow, y);
-			*bx++ = y & 0xffff;
-#endif
-		}
-		while(sx <= sxe);
-		if (!*bxe) {
-			bx = b->x;
-			while(--bxe > bx && !*bxe)
-				--n;
-			b->wds = n;
-		}
-	}
-	if (cmp(b, S) >= 0) {
-		q++;
-		borrow = 0;
-		carry = 0;
-		bx = b->x;
-		sx = S->x;
-		do {
-#ifdef Pack_32
-			si = *sx++;
-			ys = (si & 0xffff) + carry;
-			zs = (si >> 16) + (ys >> 16);
-			carry = zs >> 16;
-			y = (*bx & 0xffff) - (ys & 0xffff) + borrow;
-			borrow = (ULong)y >> 16;
-			Sign_Extend(borrow, y);
-			z = (*bx >> 16) - (zs & 0xffff) + borrow;
-			borrow = (ULong)z >> 16;
-			Sign_Extend(borrow, z);
-			Storeinc(bx, z, y);
-#else
-			ys = *sx++ + carry;
-			carry = ys >> 16;
-			y = *bx - (ys & 0xffff) + borrow;
-			borrow = y >> 16;
-			Sign_Extend(borrow, y);
-			*bx++ = y & 0xffff;
-#endif
-		}
-		while(sx <= sxe);
-		bx = b->x;
-		bxe = bx + n;
-		if (!*bxe) {
-			while(--bxe > bx && !*bxe)
-				--n;
-			b->wds = n;
-		}
-	}
-	return q;
-}
-
-/* freedtoa(s) must be used to free values s returned by dtoa
- * when MULTIPLE_THREADS is #defined.  It should be used in all cases,
- * but for consistency with earlier versions of dtoa, it is optional
- * when MULTIPLE_THREADS is not defined.
- */
-
-void
-#ifdef KR_headers
-freedtoa(s) char *s;
-#else
-freedtoa(char *s)
-#endif
-{
-	free(s);
-}
-
-
-
-/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
- *
- * Inspired by "How to Print Floating-Point Numbers Accurately" by
- * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101].
- *
- * Modifications:
- *	1. Rather than iterating, we use a simple numeric overestimate
- *	   to determine k = floor(log10(d)).  We scale relevant
- *	   quantities using O(log2(k)) rather than O(k) multiplications.
- *	2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
- *	   try to generate digits strictly left to right.  Instead, we
- *	   compute with fewer bits and propagate the carry if necessary
- *	   when rounding the final digit up.  This is often faster.
- *	3. Under the assumption that input will be rounded nearest,
- *	   mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
- *	   That is, we allow equality in stopping tests when the
- *	   round-nearest rule will give the same floating-point value
- *	   as would satisfaction of the stopping test with strict
- *	   inequality.
- *	4. We remove common factors of powers of 2 from relevant
- *	   quantities.
- *	5. When converting floating-point integers less than 1e16,
- *	   we use floating-point arithmetic rather than resorting
- *	   to multiple-precision integers.
- *	6. When asked to produce fewer than 15 digits, we first try
- *	   to get by with floating-point arithmetic; we resort to
- *	   multiple-precision integer arithmetic only if we cannot
- *	   guarantee that the floating-point calculation has given
- *	   the correctly rounded result.  For k requested digits and
- *	   "uniformly" distributed input, the probability is
- *	   something like 10^(k-15) that we must resort to the Long
- *	   calculation.
- */
-
-__LIBC_HIDDEN__  char *
-__dtoa
-#ifdef KR_headers
-	(_d, mode, ndigits, decpt, sign, rve)
-	double _d; int mode, ndigits, *decpt, *sign; char **rve;
-#else
-	(double _d, int mode, int ndigits, int *decpt, int *sign, char **rve)
-#endif
-{
- /*	Arguments ndigits, decpt, sign are similar to those
-	of ecvt and fcvt; trailing zeros are suppressed from
-	the returned string.  If not null, *rve is set to point
-	to the end of the return value.  If d is +-Infinity or NaN,
-	then *decpt is set to 9999.
-
-	mode:
-		0 ==> shortest string that yields d when read in
-			and rounded to nearest.
-		1 ==> like 0, but with Steele & White stopping rule;
-			e.g. with IEEE P754 arithmetic , mode 0 gives
-			1e23 whereas mode 1 gives 9.999999999999999e22.
-		2 ==> max(1,ndigits) significant digits.  This gives a
-			return value similar to that of ecvt, except
-			that trailing zeros are suppressed.
-		3 ==> through ndigits past the decimal point.  This
-			gives a return value similar to that from fcvt,
-			except that trailing zeros are suppressed, and
-			ndigits can be negative.
-		4-9 should give the same return values as 2-3, i.e.,
-			4 <= mode <= 9 ==> same return as mode
-			2 + (mode & 1).  These modes are mainly for
-			debugging; often they run slower but sometimes
-			faster than modes 2-3.
-		4,5,8,9 ==> left-to-right digit generation.
-		6-9 ==> don't try fast floating-point estimate
-			(if applicable).
-
-		Values of mode other than 0-9 are treated as mode 0.
-
-		Sufficient space is allocated to the return value
-		to hold the suppressed trailing zeros.
-	*/
-
-	int bbits, b2, b5, be, dig, i, ieps, ilim0,
-		j, jj1, k, k0, k_check, leftright, m2, m5, s2, s5,
-		try_quick;
-	int ilim = 0, ilim1 = 0, spec_case = 0;	/* pacify gcc */
-	Long L;
-#ifndef Sudden_Underflow
-	int denorm;
-	ULong x;
-#endif
-	Bigint *b, *b1, *delta, *mhi, *S;
-	Bigint *mlo = NULL; /* pacify gcc */
-	double ds;
-	char *s, *s0;
-	Bigint *result = NULL;
-	int result_k = 0;
-	_double d, d2, eps;
-
-	value(d) = _d;
-
-	if (word0(d) & Sign_bit) {
-		/* set sign for everything, including 0's and NaNs */
-		*sign = 1;
-		word0(d) &= ~Sign_bit;	/* clear sign bit */
-	}
-	else
-		*sign = 0;
-
-#if defined(IEEE_Arith) + defined(VAX)
-#ifdef IEEE_Arith
-	if ((word0(d) & Exp_mask) == Exp_mask)
-#else
-	if (word0(d)  == 0x8000)
-#endif
-	{
-		/* Infinity or NaN */
-		*decpt = 9999;
-		s =
-#ifdef IEEE_Arith
-			!word1(d) && !(word0(d) & 0xfffff) ? "Infinity" :
-#endif
-				"NaN";
-		result = Balloc(strlen(s)+1);
-		if (result == BIGINT_INVALID)
-			return NULL;
-		s0 = (char *)(void *)result;
-		strcpy(s0, s);
-		if (rve)
-			*rve =
-#ifdef IEEE_Arith
-				s0[3] ? s0 + 8 :
-#endif
-				s0 + 3;
-		return s0;
-	}
-#endif
-#ifdef IBM
-	value(d) += 0; /* normalize */
-#endif
-	if (!value(d)) {
-		*decpt = 1;
-		result = Balloc(2);
-		if (result == BIGINT_INVALID)
-			return NULL;
-		s0 = (char *)(void *)result;
-		strcpy(s0, "0");
-		if (rve)
-			*rve = s0 + 1;
-		return s0;
-	}
-
-	b = d2b(value(d), &be, &bbits);
-#ifdef Sudden_Underflow
-	i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
-#else
-	if ((i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) != 0) {
-#endif
-		value(d2) = value(d);
-		word0(d2) &= Frac_mask1;
-		word0(d2) |= Exp_11;
-#ifdef IBM
-		if (j = 11 - hi0bits(word0(d2) & Frac_mask))
-			value(d2) /= 1 << j;
-#endif
-
-		/* log(x)	~=~ log(1.5) + (x-1.5)/1.5
-		 * log10(x)	 =  log(x) / log(10)
-		 *		~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
-		 * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
-		 *
-		 * This suggests computing an approximation k to log10(d) by
-		 *
-		 * k = (i - Bias)*0.301029995663981
-		 *	+ ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
-		 *
-		 * We want k to be too large rather than too small.
-		 * The error in the first-order Taylor series approximation
-		 * is in our favor, so we just round up the constant enough
-		 * to compensate for any error in the multiplication of
-		 * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
-		 * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
-		 * adding 1e-13 to the constant term more than suffices.
-		 * Hence we adjust the constant term to 0.1760912590558.
-		 * (We could get a more accurate k by invoking log10,
-		 *  but this is probably not worthwhile.)
-		 */
-
-		i -= Bias;
-#ifdef IBM
-		i <<= 2;
-		i += j;
-#endif
-#ifndef Sudden_Underflow
-		denorm = 0;
-	}
-	else {
-		/* d is denormalized */
-
-		i = bbits + be + (Bias + (P-1) - 1);
-		x = i > 32  ? word0(d) << (64 - i) | word1(d) >> (i - 32)
-			    : word1(d) << (32 - i);
-		value(d2) = x;
-		word0(d2) -= 31*Exp_msk1; /* adjust exponent */
-		i -= (Bias + (P-1) - 1) + 1;
-		denorm = 1;
-	}
-#endif
-	ds = (value(d2)-1.5)*0.289529654602168 + 0.1760912590558 +
-	    i*0.301029995663981;
-	k = (int)ds;
-	if (ds < 0. && ds != k)
-		k--;	/* want k = floor(ds) */
-	k_check = 1;
-	if (k >= 0 && k <= Ten_pmax) {
-		if (value(d) < tens[k])
-			k--;
-		k_check = 0;
-	}
-	j = bbits - i - 1;
-	if (j >= 0) {
-		b2 = 0;
-		s2 = j;
-	}
-	else {
-		b2 = -j;
-		s2 = 0;
-	}
-	if (k >= 0) {
-		b5 = 0;
-		s5 = k;
-		s2 += k;
-	}
-	else {
-		b2 -= k;
-		b5 = -k;
-		s5 = 0;
-	}
-	if (mode < 0 || mode > 9)
-		mode = 0;
-	try_quick = 1;
-	if (mode > 5) {
-		mode -= 4;
-		try_quick = 0;
-	}
-	leftright = 1;
-	switch(mode) {
-		case 0:
-		case 1:
-			ilim = ilim1 = -1;
-			i = 18;
-			ndigits = 0;
-			break;
-		case 2:
-			leftright = 0;
-			/* FALLTHROUGH */
-		case 4:
-			if (ndigits <= 0)
-				ndigits = 1;
-			ilim = ilim1 = i = ndigits;
-			break;
-		case 3:
-			leftright = 0;
-			/* FALLTHROUGH */
-		case 5:
-			i = ndigits + k + 1;
-			ilim = i;
-			ilim1 = i - 1;
-			if (i <= 0)
-				i = 1;
-	}
-	j = sizeof(ULong);
-        for(result_k = 0; (int)(sizeof(Bigint) - sizeof(ULong)) + j <= i;
-		j <<= 1) result_k++;
-        // this is really a ugly hack, the code uses Balloc
-        // instead of malloc, but casts the result into a char*
-        // it seems the only reason to do that is due to the
-        // complicated way the block size need to be computed
-        // buuurk....
-	result = Balloc(result_k);
-	if (result == BIGINT_INVALID) {
-		Bfree(b);
-		return NULL;
-	}
-	s = s0 = (char *)(void *)result;
-
-	if (ilim >= 0 && ilim <= Quick_max && try_quick) {
-
-		/* Try to get by with floating-point arithmetic. */
-
-		i = 0;
-		value(d2) = value(d);
-		k0 = k;
-		ilim0 = ilim;
-		ieps = 2; /* conservative */
-		if (k > 0) {
-			ds = tens[k&0xf];
-			j = (unsigned int)k >> 4;
-			if (j & Bletch) {
-				/* prevent overflows */
-				j &= Bletch - 1;
-				value(d) /= bigtens[n_bigtens-1];
-				ieps++;
-				}
-			for(; j; j = (unsigned int)j >> 1, i++)
-				if (j & 1) {
-					ieps++;
-					ds *= bigtens[i];
-					}
-			value(d) /= ds;
-		}
-		else if ((jj1 = -k) != 0) {
-			value(d) *= tens[jj1 & 0xf];
-			for(j = (unsigned int)jj1 >> 4; j;
-			    j = (unsigned int)j >> 1, i++)
-				if (j & 1) {
-					ieps++;
-					value(d) *= bigtens[i];
-				}
-		}
-		if (k_check && value(d) < 1. && ilim > 0) {
-			if (ilim1 <= 0)
-				goto fast_failed;
-			ilim = ilim1;
-			k--;
-			value(d) *= 10.;
-			ieps++;
-		}
-		value(eps) = ieps*value(d) + 7.;
-		word0(eps) -= (P-1)*Exp_msk1;
-		if (ilim == 0) {
-			S = mhi = 0;
-			value(d) -= 5.;
-			if (value(d) > value(eps))
-				goto one_digit;
-			if (value(d) < -value(eps))
-				goto no_digits;
-			goto fast_failed;
-		}
-#ifndef No_leftright
-		if (leftright) {
-			/* Use Steele & White method of only
-			 * generating digits needed.
-			 */
-			value(eps) = 0.5/tens[ilim-1] - value(eps);
-			for(i = 0;;) {
-				L = value(d);
-				value(d) -= L;
-				*s++ = '0' + (int)L;
-				if (value(d) < value(eps))
-					goto ret1;
-				if (1. - value(d) < value(eps))
-					goto bump_up;
-				if (++i >= ilim)
-					break;
-				value(eps) *= 10.;
-				value(d) *= 10.;
-				}
-		}
-		else {
-#endif
-			/* Generate ilim digits, then fix them up. */
-			value(eps) *= tens[ilim-1];
-			for(i = 1;; i++, value(d) *= 10.) {
-				L = value(d);
-				value(d) -= L;
-				*s++ = '0' + (int)L;
-				if (i == ilim) {
-					if (value(d) > 0.5 + value(eps))
-						goto bump_up;
-					else if (value(d) < 0.5 - value(eps)) {
-						while(*--s == '0');
-						s++;
-						goto ret1;
-						}
-					break;
-				}
-			}
-#ifndef No_leftright
-		}
-#endif
- fast_failed:
-		s = s0;
-		value(d) = value(d2);
-		k = k0;
-		ilim = ilim0;
-	}
-
-	/* Do we have a "small" integer? */
-
-	if (be >= 0 && k <= Int_max) {
-		/* Yes. */
-		ds = tens[k];
-		if (ndigits < 0 && ilim <= 0) {
-			S = mhi = 0;
-			if (ilim < 0 || value(d) <= 5*ds)
-				goto no_digits;
-			goto one_digit;
-		}
-		for(i = 1;; i++) {
-			L = value(d) / ds;
-			value(d) -= L*ds;
-#ifdef Check_FLT_ROUNDS
-			/* If FLT_ROUNDS == 2, L will usually be high by 1 */
-			if (value(d) < 0) {
-				L--;
-				value(d) += ds;
-			}
-#endif
-			*s++ = '0' + (int)L;
-			if (i == ilim) {
-				value(d) += value(d);
-				if (value(d) > ds || (value(d) == ds && L & 1)) {
- bump_up:
-					while(*--s == '9')
-						if (s == s0) {
-							k++;
-							*s = '0';
-							break;
-						}
-					++*s++;
-				}
-				break;
-			}
-			if (!(value(d) *= 10.))
-				break;
-			}
-		goto ret1;
-	}
-
-	m2 = b2;
-	m5 = b5;
-	mhi = mlo = 0;
-	if (leftright) {
-		if (mode < 2) {
-			i =
-#ifndef Sudden_Underflow
-				denorm ? be + (Bias + (P-1) - 1 + 1) :
-#endif
-#ifdef IBM
-				1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);
-#else
-				1 + P - bbits;
-#endif
-		}
-		else {
-			j = ilim - 1;
-			if (m5 >= j)
-				m5 -= j;
-			else {
-				s5 += j -= m5;
-				b5 += j;
-				m5 = 0;
-			}
-			if ((i = ilim) < 0) {
-				m2 -= i;
-				i = 0;
-			}
-		}
-		b2 += i;
-		s2 += i;
-		mhi = i2b(1);
-	}
-	if (m2 > 0 && s2 > 0) {
-		i = m2 < s2 ? m2 : s2;
-		b2 -= i;
-		m2 -= i;
-		s2 -= i;
-	}
-	if (b5 > 0) {
-		if (leftright) {
-			if (m5 > 0) {
-				mhi = pow5mult(mhi, m5);
-				b1 = mult(mhi, b);
-				Bfree(b);
-				b = b1;
-			}
-			if ((j = b5 - m5) != 0)
-				b = pow5mult(b, j);
-			}
-		else
-			b = pow5mult(b, b5);
-	}
-	S = i2b(1);
-	if (s5 > 0)
-		S = pow5mult(S, s5);
-
-	/* Check for special case that d is a normalized power of 2. */
-
-	if (mode < 2) {
-		if (!word1(d) && !(word0(d) & Bndry_mask)
-#ifndef Sudden_Underflow
-		 && word0(d) & Exp_mask
-#endif
-				) {
-			/* The special case */
-			b2 += Log2P;
-			s2 += Log2P;
-			spec_case = 1;
-			}
-		else
-			spec_case = 0;
-	}
-
-	/* Arrange for convenient computation of quotients:
-	 * shift left if necessary so divisor has 4 leading 0 bits.
-	 *
-	 * Perhaps we should just compute leading 28 bits of S once
-	 * and for all and pass them and a shift to quorem, so it
-	 * can do shifts and ors to compute the numerator for q.
-	 */
-	if (S == BIGINT_INVALID) {
-		i = 0;
-	} else {
-#ifdef Pack_32
-		if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) != 0)
-			i = 32 - i;
-#else
-		if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf)
-			i = 16 - i;
-#endif
-	}
-
-	if (i > 4) {
-		i -= 4;
-		b2 += i;
-		m2 += i;
-		s2 += i;
-	}
-	else if (i < 4) {
-		i += 28;
-		b2 += i;
-		m2 += i;
-		s2 += i;
-	}
-	if (b2 > 0)
-		b = lshift(b, b2);
-	if (s2 > 0)
-		S = lshift(S, s2);
-	if (k_check) {
-		if (cmp(b,S) < 0) {
-			k--;
-			b = multadd(b, 10, 0);	/* we botched the k estimate */
-			if (leftright)
-				mhi = multadd(mhi, 10, 0);
-			ilim = ilim1;
-			}
-	}
-	if (ilim <= 0 && mode > 2) {
-		if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
-			/* no digits, fcvt style */
- no_digits:
-			k = -1 - ndigits;
-			goto ret;
-		}
- one_digit:
-		*s++ = '1';
-		k++;
-		goto ret;
-	}
-	if (leftright) {
-		if (m2 > 0)
-			mhi = lshift(mhi, m2);
-
-		/* Compute mlo -- check for special case
-		 * that d is a normalized power of 2.
-		 */
-
-		mlo = mhi;
-		if (spec_case) {
-			mhi = Balloc(mhi->k);
-			Bcopy(mhi, mlo);
-			mhi = lshift(mhi, Log2P);
-		}
-
-		for(i = 1;;i++) {
-			dig = quorem(b,S) + '0';
-			/* Do we yet have the shortest decimal string
-			 * that will round to d?
-			 */
-			j = cmp(b, mlo);
-			delta = diff(S, mhi);
-			jj1 = delta->sign ? 1 : cmp(b, delta);
-			Bfree(delta);
-#ifndef ROUND_BIASED
-			if (jj1 == 0 && !mode && !(word1(d) & 1)) {
-				if (dig == '9')
-					goto round_9_up;
-				if (j > 0)
-					dig++;
-				*s++ = dig;
-				goto ret;
-			}
-#endif
-			if (j < 0 || (j == 0 && !mode
-#ifndef ROUND_BIASED
-							&& !(word1(d) & 1)
-#endif
-					)) {
-				if (jj1 > 0) {
-					b = lshift(b, 1);
-					jj1 = cmp(b, S);
-					if ((jj1 > 0 || (jj1 == 0 && dig & 1))
-					&& dig++ == '9')
-						goto round_9_up;
-					}
-				*s++ = dig;
-				goto ret;
-			}
-			if (jj1 > 0) {
-				if (dig == '9') { /* possible if i == 1 */
- round_9_up:
-					*s++ = '9';
-					goto roundoff;
-					}
-				*s++ = dig + 1;
-				goto ret;
-			}
-			*s++ = dig;
-			if (i == ilim)
-				break;
-			b = multadd(b, 10, 0);
-			if (mlo == mhi)
-				mlo = mhi = multadd(mhi, 10, 0);
-			else {
-				mlo = multadd(mlo, 10, 0);
-				mhi = multadd(mhi, 10, 0);
-			}
-		}
-	}
-	else
-		for(i = 1;; i++) {
-			*s++ = dig = quorem(b,S) + '0';
-			if (i >= ilim)
-				break;
-			b = multadd(b, 10, 0);
-		}
-
-	/* Round off last digit */
-
-	b = lshift(b, 1);
-	j = cmp(b, S);
-	if (j > 0 || (j == 0 && dig & 1)) {
- roundoff:
-		while(*--s == '9')
-			if (s == s0) {
-				k++;
-				*s++ = '1';
-				goto ret;
-				}
-		++*s++;
-	}
-	else {
-		while(*--s == '0');
-		s++;
-	}
- ret:
-	Bfree(S);
-	if (mhi) {
-		if (mlo && mlo != mhi)
-			Bfree(mlo);
-		Bfree(mhi);
-	}
- ret1:
-	Bfree(b);
-	if (s == s0) {				/* don't return empty string */
-		*s++ = '0';
-		k = 0;
-	}
-	*s = 0;
-	*decpt = k + 1;
-	if (rve)
-		*rve = s;
-	return s0;
-}
-#ifdef __cplusplus
-}
-#endif
diff --git a/libc/stdlib/strtoimax.c b/libc/stdlib/strtoimax.c
deleted file mode 100644
index 0b4323d..0000000
--- a/libc/stdlib/strtoimax.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*	$OpenBSD: strtoimax.c,v 1.1 2006/01/13 17:58:09 millert Exp $	*/
-
-/*-
- * Copyright (c) 1992 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <ctype.h>
-#include <errno.h>
-#include <inttypes.h>
-
-/*
- * Convert a string to an intmax_t
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-intmax_t
-strtoimax(const char *nptr, char **endptr, int base)
-{
-	const char *s;
-	intmax_t acc, cutoff;
-	int c;
-	int neg, any, cutlim;
-
-	/*
-	 * Skip white space and pick up leading +/- sign if any.
-	 * If base is 0, allow 0x for hex and 0 for octal, else
-	 * assume decimal; if base is already 16, allow 0x.
-	 */
-	s = nptr;
-	do {
-		c = (unsigned char) *s++;
-	} while (isspace(c));
-	if (c == '-') {
-		neg = 1;
-		c = *s++;
-	} else {
-		neg = 0;
-		if (c == '+')
-			c = *s++;
-	}
-	if ((base == 0 || base == 16) &&
-	    c == '0' && (*s == 'x' || *s == 'X')) {
-		c = s[1];
-		s += 2;
-		base = 16;
-	}
-	if (base == 0)
-		base = c == '0' ? 8 : 10;
-
-	/*
-	 * Compute the cutoff value between legal numbers and illegal
-	 * numbers.  That is the largest legal value, divided by the
-	 * base.  An input number that is greater than this value, if
-	 * followed by a legal input character, is too big.  One that
-	 * is equal to this value may be valid or not; the limit
-	 * between valid and invalid numbers is then based on the last
-	 * digit.  For instance, if the range for intmax_t is
-	 * [-9223372036854775808..9223372036854775807] and the input base
-	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
-	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
-	 * accumulated a value > 922337203685477580, or equal but the
-	 * next digit is > 7 (or 8), the number is too big, and we will
-	 * return a range error.
-	 *
-	 * Set any if any `digits' consumed; make it negative to indicate
-	 * overflow.
-	 */
-
-	/* BIONIC: avoid division and module for common cases */
-#define  CASE_BASE(x) \
-            case x:  \
-	        if (neg) { \
-                    cutlim = INTMAX_MIN % x; \
-		    cutoff = INTMAX_MIN / x; \
-	        } else { \
-		    cutlim = INTMAX_MAX % x; \
-		    cutoff = INTMAX_MAX / x; \
-		 }; \
-		 break
-
-	switch (base) {
-            case 4:
-                if (neg) {
-                    cutlim = (int)(INTMAX_MIN % 4);
-                    cutoff = INTMAX_MIN / 4;
-                } else {
-                    cutlim = (int)(INTMAX_MAX % 4);
-                    cutoff = INTMAX_MAX / 4;
-                }
-                break;
-
-	    CASE_BASE(8);
-	    CASE_BASE(10);
-	    CASE_BASE(16);
-	    default:
-	              cutoff  = neg ? INTMAX_MIN : INTMAX_MAX;
-		      cutlim  = cutoff % base;
-	              cutoff /= base;
-	}
-#undef CASE_BASE
-
-	if (neg) {
-		if (cutlim > 0) {
-			cutlim -= base;
-			cutoff += 1;
-		}
-		cutlim = -cutlim;
-	}
-	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
-		if (isdigit(c))
-			c -= '0';
-		else if (isalpha(c))
-			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
-		else
-			break;
-		if (c >= base)
-			break;
-		if (any < 0)
-			continue;
-		if (neg) {
-			if (acc < cutoff || (acc == cutoff && c > cutlim)) {
-				any = -1;
-				acc = INTMAX_MIN;
-				errno = ERANGE;
-			} else {
-				any = 1;
-				acc *= base;
-				acc -= c;
-			}
-		} else {
-			if (acc > cutoff || (acc == cutoff && c > cutlim)) {
-				any = -1;
-				acc = INTMAX_MAX;
-				errno = ERANGE;
-			} else {
-				any = 1;
-				acc *= base;
-				acc += c;
-			}
-		}
-	}
-	if (endptr != 0)
-		*endptr = (char *) (any ? s - 1 : nptr);
-	return (acc);
-}
diff --git a/libc/stdlib/strtol.c b/libc/stdlib/strtol.c
deleted file mode 100644
index a3cdbcd..0000000
--- a/libc/stdlib/strtol.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*	$OpenBSD: strtol.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-
-
-/*
- * Convert a string to a long integer.
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-long
-strtol(const char *nptr, char **endptr, int base)
-{
-	const char *s;
-	long acc, cutoff;
-	int c;
-	int neg, any, cutlim;
-
-	/*
-	 * Skip white space and pick up leading +/- sign if any.
-	 * If base is 0, allow 0x for hex and 0 for octal, else
-	 * assume decimal; if base is already 16, allow 0x.
-	 */
-	s = nptr;
-	do {
-		c = (unsigned char) *s++;
-	} while (isspace(c));
-	if (c == '-') {
-		neg = 1;
-		c = *s++;
-	} else {
-		neg = 0;
-		if (c == '+')
-			c = *s++;
-	}
-	if ((base == 0 || base == 16) &&
-	    c == '0' && (*s == 'x' || *s == 'X')) {
-		c = s[1];
-		s += 2;
-		base = 16;
-	}
-	if (base == 0)
-		base = c == '0' ? 8 : 10;
-
-	/*
-	 * Compute the cutoff value between legal numbers and illegal
-	 * numbers.  That is the largest legal value, divided by the
-	 * base.  An input number that is greater than this value, if
-	 * followed by a legal input character, is too big.  One that
-	 * is equal to this value may be valid or not; the limit
-	 * between valid and invalid numbers is then based on the last
-	 * digit.  For instance, if the range for longs is
-	 * [-2147483648..2147483647] and the input base is 10,
-	 * cutoff will be set to 214748364 and cutlim to either
-	 * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
-	 * a value > 214748364, or equal but the next digit is > 7 (or 8),
-	 * the number is too big, and we will return a range error.
-	 *
-	 * Set any if any `digits' consumed; make it negative to indicate
-	 * overflow.
-	 */
-	cutoff = neg ? LONG_MIN : LONG_MAX;
-	cutlim = cutoff % base;
-	cutoff /= base;
-	if (neg) {
-		if (cutlim > 0) {
-			cutlim -= base;
-			cutoff += 1;
-		}
-		cutlim = -cutlim;
-	}
-	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
-		if (isdigit(c))
-			c -= '0';
-		else if (isalpha(c))
-			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
-		else
-			break;
-		if (c >= base)
-			break;
-		if (any < 0)
-			continue;
-		if (neg) {
-			if (acc < cutoff || (acc == cutoff && c > cutlim)) {
-				any = -1;
-				acc = LONG_MIN;
-				errno = ERANGE;
-			} else {
-				any = 1;
-				acc *= base;
-				acc -= c;
-			}
-		} else {
-			if (acc > cutoff || (acc == cutoff && c > cutlim)) {
-				any = -1;
-				acc = LONG_MAX;
-				errno = ERANGE;
-			} else {
-				any = 1;
-				acc *= base;
-				acc += c;
-			}
-		}
-	}
-	if (endptr != 0)
-		*endptr = (char *) (any ? s - 1 : nptr);
-	return (acc);
-}
diff --git a/libc/stdlib/strtoll.c b/libc/stdlib/strtoll.c
deleted file mode 100644
index 3c75271..0000000
--- a/libc/stdlib/strtoll.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* $OpenBSD: strtoll.c,v 1.6 2005/11/10 10:00:17 espie Exp $ */
-/*-
- * Copyright (c) 1992 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-/*
- * Convert a string to a long long.
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-long long
-strtoll(const char *nptr, char **endptr, int base)
-{
-    return strtoimax(nptr, endptr, base);
-}
-
diff --git a/libc/stdlib/strtoul.c b/libc/stdlib/strtoul.c
deleted file mode 100644
index 61dbb6f..0000000
--- a/libc/stdlib/strtoul.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*	$OpenBSD: strtoul.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
-/*
- * Copyright (c) 1990 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-
-/*
- * Convert a string to an unsigned long integer.
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-unsigned long
-strtoul(const char *nptr, char **endptr, int base)
-{
-	const char *s;
-	unsigned long acc, cutoff;
-	int c;
-	int neg, any, cutlim;
-
-	/*
-	 * See strtol for comments as to the logic used.
-	 */
-	s = nptr;
-	do {
-		c = (unsigned char) *s++;
-	} while (isspace(c));
-	if (c == '-') {
-		neg = 1;
-		c = *s++;
-	} else {
-		neg = 0;
-		if (c == '+')
-			c = *s++;
-	}
-	if ((base == 0 || base == 16) &&
-	    c == '0' && (*s == 'x' || *s == 'X')) {
-		c = s[1];
-		s += 2;
-		base = 16;
-	}
-	if (base == 0)
-		base = c == '0' ? 8 : 10;
-
-	cutoff = ULONG_MAX / (unsigned long)base;
-	cutlim = ULONG_MAX % (unsigned long)base;
-	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
-		if (isdigit(c))
-			c -= '0';
-		else if (isalpha(c))
-			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
-		else
-			break;
-		if (c >= base)
-			break;
-		if (any < 0)
-			continue;
-		if (acc > cutoff || (acc == cutoff && c > cutlim)) {
-			any = -1;
-			acc = ULONG_MAX;
-			errno = ERANGE;
-		} else {
-			any = 1;
-			acc *= (unsigned long)base;
-			acc += c;
-		}
-	}
-	if (neg && any > 0)
-		acc = -acc;
-	if (endptr != 0)
-		*endptr = (char *) (any ? s - 1 : nptr);
-	return (acc);
-}
diff --git a/libc/stdlib/strtoull.c b/libc/stdlib/strtoull.c
deleted file mode 100644
index 36698ac..0000000
--- a/libc/stdlib/strtoull.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*	$OpenBSD: strtoull.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */
-/*-
- * Copyright (c) 1992 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-/*
- * Convert a string to an unsigned long long.
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-unsigned long long
-strtoull(const char *nptr, char **endptr, int base)
-{
-    return (unsigned long long)strtoumax(nptr, endptr, base);
-}
diff --git a/libc/stdlib/strtoumax.c b/libc/stdlib/strtoumax.c
deleted file mode 100644
index e1ff623..0000000
--- a/libc/stdlib/strtoumax.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*	$OpenBSD: strtoumax.c,v 1.1 2006/01/13 17:58:09 millert Exp $	*/
-
-/*-
- * Copyright (c) 1992 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <ctype.h>
-#include <errno.h>
-#include <inttypes.h>
-
-/*
- * Convert a string to a uintmax_t.
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-uintmax_t
-strtoumax(const char *nptr, char **endptr, int base)
-{
-	const char *s;
-	uintmax_t acc, cutoff;
-	int c;
-	int neg, any, cutlim;
-
-	/*
-	 * See strtoq for comments as to the logic used.
-	 */
-	s = nptr;
-	do {
-		c = (unsigned char) *s++;
-	} while (isspace(c));
-	if (c == '-') {
-		neg = 1;
-		c = *s++;
-	} else {
-		neg = 0;
-		if (c == '+')
-			c = *s++;
-	}
-	if ((base == 0 || base == 16) &&
-	    c == '0' && (*s == 'x' || *s == 'X')) {
-		c = s[1];
-		s += 2;
-		base = 16;
-	}
-	if (base == 0)
-		base = c == '0' ? 8 : 10;
-
-        /* BIONIC: avoid division and modulo for common cases */
-#define  CASE_BASE(x)                            \
-            case x: cutoff = UINTMAX_MAX / x;    \
-	            cutlim = UINTMAX_MAX % x;    \
-		    break
-
-        switch (base) {
-        CASE_BASE(8);
-	CASE_BASE(10);
-	CASE_BASE(16);
-	default:
-	    cutoff = UINTMAX_MAX / base;
-	    cutlim = UINTMAX_MAX % base;
-	}
-
-	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
-		if (isdigit(c))
-			c -= '0';
-		else if (isalpha(c))
-			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
-		else
-			break;
-		if (c >= base)
-			break;
-		if (any < 0)
-			continue;
-		if (acc > cutoff || (acc == cutoff && c > cutlim)) {
-			any = -1;
-			acc = UINTMAX_MAX;
-			errno = ERANGE;
-		} else {
-			any = 1;
-			acc *= (uintmax_t)base;
-			acc += c;
-		}
-	}
-	if (neg && any > 0)
-		acc = -acc;
-	if (endptr != 0)
-		*endptr = (char *) (any ? s - 1 : nptr);
-	return (acc);
-}
diff --git a/libc/string/index.c b/libc/string/index.c
deleted file mode 100644
index 81bfba4..0000000
--- a/libc/string/index.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*	$OpenBSD: index.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-char *
-index(const char *p, int ch)
-{
-	for (;; ++p) {
-		if (*p == (char) ch)
-			return((char *)p);
-		if (!*p)
-			return((char *)NULL);
-	}
-	/* NOTREACHED */
-}
diff --git a/libc/string/memcmp16.c b/libc/string/memcmp16.c
deleted file mode 100644
index 1267722..0000000
--- a/libc/string/memcmp16.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-Copyright (c) 2013 Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-    * Redistributions of source code must retain the above copyright notice,
-    * this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above copyright notice,
-    * this list of conditions and the following disclaimer in the documentation
-    * and/or other materials provided with the distribution.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include <stddef.h>
-
-/* Unoptimised version of __memcmp16 */
-int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n)
-{
-  size_t i;
-
-  for (i = 0; i < n; i++) {
-    if (*ptr1 != *ptr2)
-      return *ptr1 - *ptr2;
-    ptr1++;
-    ptr2++;
-  }
-  return 0;
-}
diff --git a/libc/string/strcat.c b/libc/string/strcat.c
deleted file mode 100644
index 7cea522..0000000
--- a/libc/string/strcat.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*	$OpenBSD: strcat.c,v 1.8 2005/08/08 08:05:37 espie Exp $	*/
-
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <string.h>
-#else
-#include <lib/libkern/libkern.h>
-#endif
-
-#if defined(APIWARN)
-__warn_references(strcat,
-    "warning: strcat() is almost always misused, please use strlcat()");
-#endif
-
-char *
-strcat(char *s, const char *append)
-{
-	char *save = s;
-
-	for (; *s; ++s);
-	while ((*s++ = *append++) != '\0');
-	return(save);
-}
diff --git a/libc/string/strcmp.c b/libc/string/strcmp.c
deleted file mode 100644
index 816fd11..0000000
--- a/libc/string/strcmp.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*	$OpenBSD: strcmp.c,v 1.7 2005/08/08 08:05:37 espie Exp $	*/
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <string.h>
-#else
-#include <lib/libkern/libkern.h>
-#endif
-
-/*
- * Compare strings.
- */
-int
-strcmp(const char *s1, const char *s2)
-{
-	while (*s1 == *s2++)
-		if (*s1++ == 0)
-			return (0);
-	return (*(unsigned char *)s1 - *(unsigned char *)--s2);
-}
diff --git a/libc/string/strcpy.c b/libc/string/strcpy.c
deleted file mode 100644
index eb21d67..0000000
--- a/libc/string/strcpy.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*	$OpenBSD: strcpy.c,v 1.8 2005/08/08 08:05:37 espie Exp $	*/
-
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-char *
-strcpy(char *to, const char *from)
-{
-	char *save = to;
-
-	for (; (*to = *from) != '\0'; ++from, ++to);
-	return(save);
-}
diff --git a/libc/string/strlen.c b/libc/string/strlen.c
deleted file mode 100644
index 12d9ec4..0000000
--- a/libc/string/strlen.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*	$OpenBSD: strlen.c,v 1.7 2005/08/08 08:05:37 espie Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <string.h>
-#else
-#include <lib/libkern/libkern.h>
-#endif
-
-size_t
-strlen(const char *str)
-{
-	const char *s;
-
-	for (s = str; *s; ++s)
-		;
-	return (s - str);
-}
-
diff --git a/libc/string/strncmp.c b/libc/string/strncmp.c
deleted file mode 100644
index 1768808..0000000
--- a/libc/string/strncmp.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*	$OpenBSD: strncmp.c,v 1.7 2005/08/08 08:05:37 espie Exp $	*/
-
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <string.h>
-#else
-#include <lib/libkern/libkern.h>
-#endif
-
-int
-strncmp(const char *s1, const char *s2, size_t n)
-{
-	if (n == 0)
-		return (0);
-	do {
-		if (*s1 != *s2++)
-			return (*(unsigned char *)s1 - *(unsigned char *)--s2);
-		if (*s1++ == 0)
-			break;
-	} while (--n != 0);
-	return (0);
-}
diff --git a/libc/string/strncpy.c b/libc/string/strncpy.c
deleted file mode 100644
index 4426cbe..0000000
--- a/libc/string/strncpy.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*	$OpenBSD: strncpy.c,v 1.6 2005/08/08 08:05:37 espie Exp $	*/
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <string.h>
-#else
-#include <lib/libkern/libkern.h>
-#endif
-
-/*
- * Copy src to dst, truncating or null-padding to always copy n bytes.
- * Return dst.
- */
-char *
-strncpy(char *dst, const char *src, size_t n)
-{
-	if (n != 0) {
-		char *d = dst;
-		const char *s = src;
-
-		do {
-			if ((*d++ = *s++) == 0) {
-				/* NUL pad the remaining n-1 bytes */
-				while (--n != 0)
-					*d++ = 0;
-				break;
-			}
-		} while (--n != 0);
-	}
-	return (dst);
-}
diff --git a/libc/string/strrchr.c b/libc/string/strrchr.c
deleted file mode 100644
index fe2306a..0000000
--- a/libc/string/strrchr.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*	$OpenBSD: rindex.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-
-char *
-strrchr(const char *p, int ch)
-{
-	return __strrchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
-}
diff --git a/libc/string/strsep.c b/libc/string/strsep.c
deleted file mode 100644
index c44bc5b..0000000
--- a/libc/string/strsep.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*	$OpenBSD: strsep.c,v 1.6 2005/08/08 08:05:37 espie Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <string.h>
-#include <stdio.h>
-
-/*
- * Get next token from string *stringp, where tokens are possibly-empty
- * strings separated by characters from delim.
- *
- * Writes NULs into the string at *stringp to end tokens.
- * delim need not remain constant from call to call.
- * On return, *stringp points past the last NUL written (if there might
- * be further tokens), or is NULL (if there are definitely no more tokens).
- *
- * If *stringp is NULL, strsep returns NULL.
- */
-char *
-strsep(char **stringp, const char *delim)
-{
-	char *s;
-	const char *spanp;
-	int c, sc;
-	char *tok;
-
-	if ((s = *stringp) == NULL)
-		return (NULL);
-	for (tok = s;;) {
-		c = *s++;
-		spanp = delim;
-		do {
-			if ((sc = *spanp++) == c) {
-				if (c == 0)
-					s = NULL;
-				else
-					s[-1] = 0;
-				*stringp = s;
-				return (tok);
-			}
-		} while (sc != 0);
-	}
-	/* NOTREACHED */
-}
diff --git a/libc/tools/bionic_utils.py b/libc/tools/bionic_utils.py
index 88ddd55..c38efb5 100644
--- a/libc/tools/bionic_utils.py
+++ b/libc/tools/bionic_utils.py
@@ -2,7 +2,7 @@
 
 import sys, os, commands, string
 
-all_arches = [ "arm", "arm64", "mips", "x86", "x86_64" ]
+all_arches = [ "arm", "arm64", "mips", "mips64", "x86", "x86_64" ]
 
 # basic debugging trace support
 # call D_setlevel to set the verbosity level
@@ -130,7 +130,7 @@
                 if arch in all_arches:
                     t[arch] = True
                 else:
-                    E("invalid syscall architecture list in '%s'" % line)
+                    E("invalid syscall architecture '%s' in '%s'" % (arch, line))
                     return
 
         self.syscalls.append(t)
diff --git a/libc/tools/check-symbols-glibc.py b/libc/tools/check-symbols-glibc.py
new file mode 100755
index 0000000..58a10e0
--- /dev/null
+++ b/libc/tools/check-symbols-glibc.py
@@ -0,0 +1,153 @@
+#!/usr/bin/python
+
+import glob
+import os
+import re
+import string
+import subprocess
+import sys
+
+toolchain = os.environ['ANDROID_TOOLCHAIN']
+arch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain)
+
+def GetSymbolsFromSo(so_file):
+  # Example readelf output:
+  #   264: 0001623c     4 FUNC    GLOBAL DEFAULT    8 cabsf
+  #   266: 00016244     4 FUNC    GLOBAL DEFAULT    8 dremf
+  #   267: 00019018     4 OBJECT  GLOBAL DEFAULT   11 __fe_dfl_env
+  #   268: 00000000     0 FUNC    GLOBAL DEFAULT  UND __aeabi_dcmplt
+
+  r = re.compile(r' +\d+: [0-9a-f]+ +\d+ (I?FUNC|OBJECT) +\S+ +\S+ +\d+ (\S+)')
+
+  symbols = set()
+
+  for line in subprocess.check_output(['readelf', '--dyn-syms', '-W', so_file]).split('\n'):
+    if ' HIDDEN ' in line or ' UND ' in line:
+      continue
+    m = r.match(line)
+    if m:
+      symbol = m.group(2)
+      symbol = re.sub('@.*', '', symbol)
+      symbols.add(symbol)
+
+  return symbols
+
+def GetSymbolsFromAndroidSo(*files):
+  symbols = set()
+  for f in files:
+    symbols = symbols | GetSymbolsFromSo('%s/system/lib64/%s' % (os.environ['ANDROID_PRODUCT_OUT'], f))
+  return symbols
+
+def GetSymbolsFromSystemSo(*files):
+  symbols = set()
+  for f in files:
+    f = glob.glob('/lib/x86_64-linux-gnu/%s' % f)[-1]
+    symbols = symbols | GetSymbolsFromSo(f)
+  return symbols
+
+def MangleGlibcNameToBionic(name):
+  if name in glibc_to_bionic_names:
+    return glibc_to_bionic_names[name]
+  return name
+
+glibc_to_bionic_names = {
+  '__res_init': 'res_init',
+  '__res_mkquery': 'res_mkquery',
+  '__res_query': 'res_query',
+  '__res_search': 'res_search',
+}
+
+glibc = GetSymbolsFromSystemSo('libc.so.*', 'librt.so.*', 'libpthread.so.*', 'libresolv.so.*', 'libm.so.*')
+bionic = GetSymbolsFromAndroidSo('libc.so', 'libm.so')
+
+glibc = map(MangleGlibcNameToBionic, glibc)
+
+# bionic includes various BSD symbols to ease porting other BSD-licensed code.
+bsd_stuff = set([
+  'basename_r',
+  'dirname_r',
+  'fgetln',
+  'fpurge',
+  'funopen',
+  'gamma_r',
+  'gammaf_r',
+  'getprogname',
+  'setprogname',
+  'strlcat',
+  'strlcpy',
+  'sys_signame',
+  'wcslcat',
+  'wcslcpy'
+])
+# Some symbols are part of the FORTIFY implementation.
+FORTIFY_stuff = set([
+  '__FD_CLR_chk',
+  '__FD_ISSET_chk',
+  '__FD_SET_chk',
+  '__stack_chk_guard',
+  '__stpncpy_chk2',
+  '__strchr_chk',
+  '__strlcat_chk',
+  '__strlcpy_chk',
+  '__strlen_chk',
+  '__strncpy_chk2',
+  '__strrchr_chk',
+  '__umask_chk'
+])
+# Some symbols are used to implement public macros.
+macro_stuff = set([
+  '__assert2',
+  '__errno',
+  '__fe_dfl_env',
+  '__get_h_errno',
+])
+# bionic exposes various Linux features that glibc doesn't.
+linux_stuff = set([
+  'getauxval',
+  'gettid',
+  'tgkill'
+])
+# Some standard stuff isn't yet in the versions of glibc we're using.
+std_stuff = set([
+  'at_quick_exit',
+  'c16rtomb',
+  'c32rtomb',
+  'mbrtoc16',
+  'mbrtoc32',
+])
+# These have mangled names in glibc, with a macro taking the "obvious" name.
+weird_stuff = set([
+  'fstat',
+  'fstat64',
+  'fstatat',
+  'fstatat64',
+  'isfinite',
+  'isfinitef',
+  'isfinitel',
+  'isnormal',
+  'isnormalf',
+  'isnormall',
+  'lstat',
+  'lstat64',
+  'mknod',
+  'mknodat',
+  'stat',
+  'stat64',
+])
+
+print 'glibc:'
+for symbol in sorted(glibc):
+  print symbol
+
+print
+print 'bionic:'
+for symbol in sorted(bionic):
+  print symbol
+
+print
+print 'in bionic but not glibc:'
+allowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff | std_stuff | weird_stuff)
+for symbol in sorted((bionic - allowed_stuff).difference(glibc)):
+  print symbol
+
+sys.exit(0)
diff --git a/libc/tools/generate-NOTICE.py b/libc/tools/generate-NOTICE.py
index 5115317..8cd75a3 100755
--- a/libc/tools/generate-NOTICE.py
+++ b/libc/tools/generate-NOTICE.py
@@ -25,7 +25,7 @@
     return False
 
 def IsAutoGenerated(content):
-    if "generated by gensyscalls.py" in content or "generated by genserv.py" in content:
+    if "Generated by gensyscalls.py" in content or "generated by genserv.py" in content:
         return True
     if "This header was automatically generated from a Linux kernel header" in content:
         return True
@@ -55,10 +55,13 @@
             break
         if "\tcitrus Id: " in lines[i]:
             break
-        if "\t$OpenBSD: " in lines[i] or " $FreeBSD: " in lines[i] or "\t$NetBSD: " in lines[i]:
+        if "\t$Citrus: " in lines[i] or "\t$OpenBSD: " in lines[i] or " $FreeBSD: " in lines[i] or "\t$NetBSD: " in lines[i]:
             break
         if "$FreeBSD$" in lines[i] or "$Citrus$" in lines[i]:
             break
+        # OpenBSD likes to say where stuff originally came from:
+        if "Original version ID:" in lines[i]:
+            break
         i += 1
 
     end = i
@@ -74,7 +77,7 @@
     for line in lines[start:end]:
         line = line.replace("\t", "    ")
         line = line.replace("/* ", "")
-        line = line.replace(" * ", "")
+        line = re.sub("^ \* ", "", line)
         line = line.replace("** ", "")
         line = line.replace("# ", "")
         if line.startswith("++Copyright++"):
@@ -141,7 +144,7 @@
 
             i = 0
             while i < len(lines):
-                if "Copyright" in lines[i]:
+                if "Copyright" in lines[i] and not "@(#) Copyright" in lines[i]:
                     i = ExtractCopyrightAt(lines, i)
                 i += 1
 
diff --git a/libc/tools/genlibgcc_compat.py b/libc/tools/genlibgcc_compat.py
new file mode 100755
index 0000000..628bf92
--- /dev/null
+++ b/libc/tools/genlibgcc_compat.py
@@ -0,0 +1,136 @@
+#!/usr/bin/python
+
+'''
+/* This file generates libgcc_compat.c file that contains dummy
+ * references to libgcc.a functions to force the dynamic linker
+ * to copy their definition into the final libc.so binary.
+ *
+ * They are required to ensure backwards binary compatibility with
+ * libc.so provided by the platform and binaries built with the NDK or
+ * different versions/configurations of toolchains.
+ *
+ * Now, for a more elaborate description of the issue:
+ *
+ * libgcc.a is a compiler-specific library containing various helper
+ * functions used to implement certain operations that are not necessarily
+ * supported by the target CPU. For example, integer division doesn't have a
+ * corresponding CPU instruction on ARMv5, and is instead implemented in the
+ * compiler-generated machine code as a call to an __idiv helper function.
+ *
+ * Normally, one has to place libgcc.a in the link command used to generate
+ * target binaries (shared libraries and executables) after all objects and
+ * static libraries, but before dependent shared libraries, i.e. something
+ * like:
+ *         gcc <options> -o libfoo.so  foo.a libgcc.a -lc -lm
+ *
+ * This ensures that any helper function needed by the code in foo.a is copied
+ * into the final libfoo.so. However, doing so will link a bunch of other __cxa
+ * functions from libgcc.a into each .so and executable, causing 4k+ increase
+ * in every binary. Therefore the Android platform build system has been
+ * using this instead:
+ *
+ *         gcc <options> -o libfoo.so foo.a -lc -lm libgcc.a
+ *
+ * The problem with this is that if one helper function needed by foo.a has
+ * already been copied into libc.so or libm.so, then nothing will be copied
+ * into libfoo.so. Instead, a symbol import definition will be added to it
+ * so libfoo.so can directly call the one in libc.so at runtime.
+ *
+ * When refreshing toolchains for new versions or using different architecture
+ * flags, the set of helper functions copied to libc.so may change, which
+ * resulted in some native shared libraries generated with the NDK or prebuilts
+ * from vendors to fail to load properly.
+ *
+ * The NDK has been fixed after 1.6_r1 to use the correct link command, so
+ * any native shared library generated with it should now be safe from that
+ * problem. On the other hand, existing shared libraries distributed with
+ * applications that were generated with a previous version of the NDK
+ * still need all 1.5/1.6 helper functions in libc.so and libm.so
+ *
+ * After 3.2, the toolchain was updated again, adding __aeabi_f2uiz to the
+ * list of requirements. Technically, this is due to mis-linked NDK libraries
+ * but it is easier to add a single function here than asking several app
+ * developers to fix their build.
+ *
+ * The __aeabi_idiv function is added to the list since cortex-a15 supports
+ * HW idiv instructions so the system libc.so doesn't pull in the reference to
+ * __aeabi_idiv but legacy libraries built against cortex-a9 targets still need
+ * it.
+ *
+ * Final note: some of the functions below should really be in libm.so to
+ *             completely reflect the state of 1.5/1.6 system images. However,
+ *             since libm.so depends on libc.so, it's easier to put all of
+ *             these in libc.so instead, since the dynamic linker will always
+ *             search in libc.so before libm.so for dependencies.
+ */
+'''
+
+import os
+import sys
+import subprocess
+import tempfile
+import re
+
+libgcc_compat_header = "/* Generated by genlibgcc_compat.py */\n\n"
+
+class Generator:
+    def process(self):
+        android_build_top_path = os.environ["ANDROID_BUILD_TOP"]
+
+        print "* ANDROID_BUILD_TOP=" + android_build_top_path
+
+        # Check TARGET_ARCH
+        arch = subprocess.check_output(["CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core make --no-print-directory -f build/core/config.mk dumpvar-TARGET_ARCH"],
+                    cwd=android_build_top_path, shell=True).strip()
+
+        if arch != 'arm' and arch != 'x86':
+            sys.exit("Error: Invalid TARGET_ARCH='" + arch + "' expecting 'arm' or 'x86'")
+
+        build_path =  android_build_top_path + "/bionic/libc"
+        file_name = "libgcc_compat.c"
+        file_path = build_path + "/arch-" + arch + "/bionic/" + file_name
+
+        build_output_file_path = tempfile.mkstemp()[1]
+
+        p = subprocess.Popen(["ONE_SHOT_MAKEFILE=bionic/libc/Android.mk make -C " + android_build_top_path
+                    + " -f build/core/main.mk all_modules TARGET_LIBGCC= -j20 -B 2>&1 | tee " + build_output_file_path],
+                    cwd=build_path, shell=True)
+        p.wait()
+
+        print "* Build complete, logfile: " + build_output_file_path
+
+        symbol_set = set()
+        prog=re.compile("(?<=undefined reference to ')\w+")
+        fd = open(build_output_file_path, 'r')
+        for line in fd:
+            m = prog.search(line)
+            if m:
+                symbol_set.add(m.group(0))
+
+        fd.close()
+
+        symbol_list = sorted(symbol_set)
+
+        print "* Found " + repr(len(symbol_list)) + " referenced symbols: " + repr(symbol_list)
+
+        if 0 == len(symbol_list):
+            sys.exit("Error: symbol list is empty, please check the build log: " + build_output_file_path)
+
+        print "* Generating " + file_path
+        fres = open(file_path, 'w')
+        fres.write(libgcc_compat_header)
+
+        for sym_name in symbol_list:
+            fres.write("extern char "+sym_name+";\n")
+        fres.write("\n");
+
+        fres.write("void* __bionic_libgcc_compat_symbols[] = {\n");
+        for sym_name in symbol_list:
+            fres.write("    &"+sym_name+",\n")
+        fres.write("};\n");
+
+        fres.close()
+
+generator = Generator()
+generator.process()
+
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 97dc628..e8ec636 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -48,8 +48,8 @@
 
 
 function_alias = """
-    .globl _C_LABEL(%(alias)s)
-    .equ _C_LABEL(%(alias)s), _C_LABEL(%(func)s)
+    .globl %(alias)s
+    .equ %(alias)s, %(func)s
 """
 
 
@@ -65,13 +65,12 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(%(func)s)
 """
 
 arm_eabi_call_long = syscall_stub_header + """\
     mov     ip, sp
-    .save   {r4, r5, r6, r7}
     stmfd   sp!, {r4, r5, r6, r7}
     .cfi_def_cfa_offset 16
     .cfi_rel_offset r4, 0
@@ -86,7 +85,7 @@
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
-    b       __set_errno
+    b       __set_errno_internal
 END(%(func)s)
 """
 
@@ -96,19 +95,12 @@
 #
 
 arm64_call = syscall_stub_header + """\
-    stp     x29, x30, [sp, #-16]!
-    mov     x29,  sp
-    str     x8,       [sp, #-16]!
-
     mov     x8, %(__NR_name)s
     svc     #0
 
-    ldr     x8,       [sp], #16
-    ldp     x29, x30, [sp], #16
-
     cmn     x0, #(MAX_ERRNO + 1)
     cneg    x0, x0, hi
-    b.hi    __set_errno
+    b.hi    __set_errno_internal
 
     ret
 END(%(func)s)
@@ -119,29 +111,49 @@
 # MIPS assembler templates for each syscall stub
 #
 
-mips_call = "/* " + warning + " */\n" + \
-"""
-#include <asm/unistd.h>
-    .text
-    .globl %(func)s
-    .align 4
-    .ent %(func)s
-
-%(func)s:
+mips_call = syscall_stub_header + """\
     .set noreorder
-    .cpload $t9
-    li $v0, %(__NR_name)s
+    .cpload t9
+    li v0, %(__NR_name)s
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno_internal
+    j t9
     nop
     .set reorder
-    .end %(func)s
+END(%(func)s)
+"""
+
+
+#
+# MIPS64 assembler templates for each syscall stub
+#
+
+mips64_call = syscall_stub_header + """\
+    .set push
+    .set noreorder
+    li v0, %(__NR_name)s
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(%(func)s)
 """
 
 
@@ -158,9 +170,8 @@
     jb      1f
     negl    %%eax
     pushl   %%eax
-    call    __set_errno
+    call    __set_errno_internal
     addl    $4, %%esp
-    orl     $-1, %%eax
 1:
 """
 
@@ -181,8 +192,7 @@
     jb      1f
     negl    %%eax
     movl    %%eax, %%edi
-    call    __set_errno
-    orq     $-1, %%rax
+    call    __set_errno_internal
 1:
     ret
 END(%(func)s)
@@ -269,7 +279,7 @@
 
     # Use hidden visibility for any functions beginning with underscores.
     if pointer_length == 64 and syscall["func"].startswith("__"):
-        stub += '.hidden _C_LABEL(' + syscall["func"] + ')\n'
+        stub += '.hidden ' + syscall["func"] + '\n'
 
     return stub
 
@@ -289,6 +299,10 @@
     return mips_call % syscall
 
 
+def mips64_genstub(syscall):
+    return mips64_call % syscall
+
+
 def x86_genstub(syscall):
     result     = syscall_stub_header % syscall
 
@@ -296,17 +310,20 @@
     stack_bias = numparams*4 + 4
     offset = 0
     mov_result = ""
-    cfi_result = "    .cfi_def_cfa_offset %d\n" % (numparams*4)
+    first_push = True
     for register in x86_registers[:numparams]:
         result     += "    pushl   %%%s\n" % register
+        if first_push:
+          result   += "    .cfi_def_cfa_offset 8\n"
+          result   += "    .cfi_rel_offset %s, 0\n" % register
+          first_push = False
+        else:
+          result   += "    .cfi_adjust_cfa_offset 4\n"
+          result   += "    .cfi_rel_offset %s, 0\n" % register
         mov_result += "    mov     %d(%%esp), %%%s\n" % (stack_bias+offset, register)
-        cfi_result += "    .cfi_rel_offset %s, %d\n" % (register, offset)
         offset += 4
 
-    if numparams:
-        result += cfi_result
-        result += mov_result
-
+    result += mov_result
     result += x86_call % syscall
 
     for register in reversed(x86_registers[:numparams]):
@@ -326,10 +343,11 @@
 
     # save the regs we need
     result += "    pushl   %ebx\n"
-    result += "    pushl   %ecx\n"
     result += "    .cfi_def_cfa_offset 8\n"
     result += "    .cfi_rel_offset ebx, 0\n"
-    result += "    .cfi_rel_offset ecx, 4\n"
+    result += "    pushl   %ecx\n"
+    result += "    .cfi_adjust_cfa_offset 4\n"
+    result += "    .cfi_rel_offset ecx, 0\n"
     stack_bias = 12
 
     # set the call id (%ebx)
@@ -397,6 +415,9 @@
             if syscall.has_key("mips"):
                 syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
 
+            if syscall.has_key("mips64"):
+                syscall["asm-mips64"] = add_footer(64, mips64_genstub(syscall), syscall)
+
             if syscall.has_key("x86_64"):
                 syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
 
@@ -439,20 +460,6 @@
         self.other_files.append(glibc_syscalls_h_path)
 
 
-    # Write the contents of syscalls.mk.
-    def gen_arch_syscalls_mk(self, arch):
-        path = "arch-%s/syscalls.mk" % arch
-        D("generating " + path)
-        fp = create_file(path)
-        fp.write("# %s\n" % warning)
-        fp.write("syscall_src :=\n")
-        for syscall in sorted(self.syscalls, key=lambda syscall: syscall["func"]):
-            if syscall.has_key("asm-%s" % arch):
-                fp.write("syscall_src += arch-%s/syscalls/%s.S\n" % (arch, syscall["func"]))
-        fp.close()
-        self.other_files.append(path)
-
-
     # Write each syscall stub.
     def gen_syscall_stubs(self):
         for syscall in self.syscalls:
@@ -487,8 +494,6 @@
         D("re-generating stubs and support files...")
 
         self.gen_glibc_syscalls_h()
-        for arch in all_arches:
-            self.gen_arch_syscalls_mk(arch)
         self.gen_syscall_stubs()
 
         D("comparing files...")
diff --git a/libc/tools/zoneinfo/ZoneCompactor.java b/libc/tools/zoneinfo/ZoneCompactor.java
index f47afd1..bf3153e 100644
--- a/libc/tools/zoneinfo/ZoneCompactor.java
+++ b/libc/tools/zoneinfo/ZoneCompactor.java
@@ -1,9 +1,6 @@
 
 import java.io.*;
-import java.nio.ByteOrder;
 import java.util.*;
-import libcore.io.BufferIterator;
-import libcore.util.ZoneInfo;
 
 // usage: java ZoneCompiler <setup file> <data directory> <output directory> <tzdata version>
 //
@@ -27,66 +24,20 @@
 //
 
 public class ZoneCompactor {
-  public static class ByteArrayBufferIteratorBE extends BufferIterator {
-    private final byte[] bytes;
-    private int offset = 0;
-
-    public ByteArrayBufferIteratorBE(byte[] bytes) {
-      this.bytes = bytes;
-      this.offset = 0;
-    }
-
-    public void seek(int offset) {
-      this.offset = offset;
-    }
-
-    public void skip(int byteCount) {
-      this.offset += byteCount;
-    }
-
-    public void readByteArray(byte[] dst, int dstOffset, int byteCount) {
-      System.arraycopy(bytes, offset, dst, dstOffset, byteCount);
-      offset += byteCount;
-    }
-
-    public byte readByte() {
-      return bytes[offset++];
-    }
-
-    public int readInt() {
-      return ((readByte() & 0xff) << 24) | ((readByte() & 0xff) << 16) | ((readByte() & 0xff) << 8) | (readByte() & 0xff);
-    }
-
-    public void readIntArray(int[] dst, int dstOffset, int intCount) {
-      for (int i = 0; i < intCount; ++i) {
-        dst[dstOffset++] = readInt();
-      }
-    }
-
-    public short readShort() {
-      throw new UnsupportedOperationException();
-    }
-  }
-
-  // Maximum number of characters in a zone name, including '\0' terminator
+  // Maximum number of characters in a zone name, including '\0' terminator.
   private static final int MAXNAME = 40;
 
-  // Zone name synonyms
+  // Zone name synonyms.
   private Map<String,String> links = new HashMap<String,String>();
 
-  // File starting bytes by zone name
-  private Map<String,Integer> starts = new HashMap<String,Integer>();
+  // File offsets by zone name.
+  private Map<String,Integer> offsets = new HashMap<String,Integer>();
 
-  // File lengths by zone name
+  // File lengths by zone name.
   private Map<String,Integer> lengths = new HashMap<String,Integer>();
 
-  // Raw GMT offsets by zone name
-  private Map<String,Integer> offsets = new HashMap<String,Integer>();
-  private int start = 0;
-
-  // Concatenate the contents of 'inFile' onto 'out'
-  // and return the contents as a byte array.
-  private static byte[] copyFile(File inFile, OutputStream out) throws Exception {
+  // Concatenate the contents of 'inFile' onto 'out'.
+  private static void copyFile(File inFile, OutputStream out) throws Exception {
     byte[] ret = new byte[0];
 
     InputStream in = new FileInputStream(inFile);
@@ -104,14 +55,14 @@
       ret = nret;
     }
     out.flush();
-    return ret;
   }
 
   public ZoneCompactor(String setupFile, String dataDirectory, String zoneTabFile, String outputDirectory, String version) throws Exception {
-    // Read the setup file, and concatenate all the data.
+    // Read the setup file and concatenate all the data.
     ByteArrayOutputStream allData = new ByteArrayOutputStream();
     BufferedReader reader = new BufferedReader(new FileReader(setupFile));
     String s;
+    int offset = 0;
     while ((s = reader.readLine()) != null) {
       s = s.trim();
       if (s.startsWith("Link")) {
@@ -125,16 +76,11 @@
         if (link == null) {
           File sourceFile = new File(dataDirectory, s);
           long length = sourceFile.length();
-          starts.put(s, start);
+          offsets.put(s, offset);
           lengths.put(s, (int) length);
 
-          start += length;
-          byte[] data = copyFile(sourceFile, allData);
-
-          BufferIterator it = new ByteArrayBufferIteratorBE(data);
-          TimeZone tz = ZoneInfo.makeTimeZone(s, it);
-          int gmtOffset = tz.getRawOffset();
-          offsets.put(s, gmtOffset);
+          offset += length;
+          copyFile(sourceFile, allData);
         }
       }
     }
@@ -146,9 +92,8 @@
       String from = it.next();
       String to = links.get(from);
 
-      starts.put(from, starts.get(to));
-      lengths.put(from, lengths.get(to));
       offsets.put(from, offsets.get(to));
+      lengths.put(from, lengths.get(to));
     }
 
     // Create/truncate the destination file.
@@ -178,7 +123,7 @@
 
     // Write the index.
     ArrayList<String> sortedOlsonIds = new ArrayList<String>();
-    sortedOlsonIds.addAll(starts.keySet());
+    sortedOlsonIds.addAll(offsets.keySet());
     Collections.sort(sortedOlsonIds);
     it = sortedOlsonIds.iterator();
     while (it.hasNext()) {
@@ -188,9 +133,9 @@
       }
 
       f.write(toAscii(new byte[MAXNAME], zoneName));
-      f.writeInt(starts.get(zoneName));
-      f.writeInt(lengths.get(zoneName));
       f.writeInt(offsets.get(zoneName));
+      f.writeInt(lengths.get(zoneName));
+      f.writeInt(0); // Used to be raw GMT offset. No longer used.
     }
 
     int data_offset = (int) f.getFilePointer();
diff --git a/libc/tools/zoneinfo/update-tzdata.py b/libc/tools/zoneinfo/update-tzdata.py
index 8956136..e800e8f 100755
--- a/libc/tools/zoneinfo/update-tzdata.py
+++ b/libc/tools/zoneinfo/update-tzdata.py
@@ -1,36 +1,40 @@
 #!/usr/bin/python
 
-"""Updates the tzdata file."""
+"""Updates the timezone data held in bionic and ICU."""
 
 import ftplib
+import glob
 import httplib
 import os
 import re
+import shutil
 import subprocess
 import sys
 import tarfile
 import tempfile
 
-# Find the bionic directory, searching upward from this script.
-bionic_libc_tools_zoneinfo_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
-bionic_libc_tools_dir = os.path.dirname(bionic_libc_tools_zoneinfo_dir)
-bionic_libc_dir = os.path.dirname(bionic_libc_tools_dir)
-bionic_dir = os.path.dirname(bionic_libc_dir)
-bionic_libc_zoneinfo_dir = '%s/libc/zoneinfo' % bionic_dir
-
-if not os.path.isdir(bionic_libc_tools_zoneinfo_dir):
-  print "Couldn't find bionic/libc/tools/zoneinfo!"
-  sys.exit(1)
-if not os.path.isdir(bionic_libc_zoneinfo_dir):
-  print "Couldn't find bionic/libc/zoneinfo!"
-  sys.exit(1)
-
-print 'Found bionic in %s...' % bionic_dir
-
-
 regions = ['africa', 'antarctica', 'asia', 'australasia', 'backward',
            'etcetera', 'europe', 'northamerica', 'southamerica']
 
+def CheckDirExists(dir, dirname):
+  if not os.path.isdir(dir):
+    print "Couldn't find %s (%s)!" % (dirname, dir)
+    sys.exit(1)
+
+bionic_libc_tools_zoneinfo_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
+
+# Find the bionic directory, searching upward from this script.
+bionic_dir = os.path.realpath('%s/../../..' % bionic_libc_tools_zoneinfo_dir)
+bionic_libc_zoneinfo_dir = '%s/libc/zoneinfo' % bionic_dir
+CheckDirExists(bionic_libc_zoneinfo_dir, 'bionic/libc/zoneinfo')
+CheckDirExists(bionic_libc_tools_zoneinfo_dir, 'bionic/libc/tools/zoneinfo')
+print 'Found bionic in %s ...' % bionic_dir
+
+# Find the icu4c directory.
+icu_dir = os.path.realpath('%s/../external/icu/icu4c/source' % bionic_dir)
+CheckDirExists(icu_dir, 'external/icu/icu4c/source')
+print 'Found icu in %s ...' % icu_dir
+
 
 def GetCurrentTzDataVersion():
   return open('%s/tzdata' % bionic_libc_zoneinfo_dir).read().split('\x00', 1)[0]
@@ -65,50 +69,81 @@
   print 'Created temporary directory "%s"...' % tmp_dir
 
 
-def FtpRetrieve(ftp, filename):
+def FtpRetrieveFile(ftp, filename):
   ftp.retrbinary('RETR %s' % filename, open(filename, 'wb').write)
 
 
-def FtpUpgrade(ftp, data_filename):
+def FtpRetrieveFileAndSignature(ftp, data_filename):
   """Downloads and repackages the given data from the given FTP server."""
-  SwitchToNewTemporaryDirectory()
-
   print 'Downloading data...'
-  FtpRetrieve(ftp, data_filename)
+  FtpRetrieveFile(ftp, data_filename)
 
   print 'Downloading signature...'
   signature_filename = '%s.asc' % data_filename
-  FtpRetrieve(ftp, signature_filename)
-
-  ExtractAndCompile(data_filename)
+  FtpRetrieveFile(ftp, signature_filename)
 
 
-def HttpRetrieve(http, path, output_filename):
+def HttpRetrieveFile(http, path, output_filename):
   http.request("GET", path)
   f = open(output_filename, 'wb')
   f.write(http.getresponse().read())
   f.close()
 
 
-def HttpUpgrade(http, data_filename):
+def HttpRetrieveFileAndSignature(http, data_filename):
   """Downloads and repackages the given data from the given HTTP server."""
-  SwitchToNewTemporaryDirectory()
-
   path = "/time-zones/repository/releases/%s" % data_filename
 
   print 'Downloading data...'
-  HttpRetrieve(http, path, data_filename)
+  HttpRetrieveFile(http, path, data_filename)
 
   print 'Downloading signature...'
   signature_filename = '%s.asc' % data_filename
-  HttpRetrieve(http, "%s.asc" % path, signature_filename)
-
-  ExtractAndCompile(data_filename)
+  HttpRetrievefile(http, "%s.asc" % path, signature_filename)
 
 
-def ExtractAndCompile(data_filename):
-  new_version = re.search('(tzdata.+)\\.tar\\.gz', data_filename).group(1)
+def BuildIcuToolsAndData(data_filename):
+  # Keep track of the original cwd so we can go back to it at the end.
+  original_working_dir = os.getcwd()
 
+  # Create a directory to run 'make' from.
+  icu_working_dir = '%s/icu' % original_working_dir
+  os.mkdir(icu_working_dir)
+  os.chdir(icu_working_dir)
+
+  # Build the ICU tools.
+  print 'Configuring ICU tools...'
+  subprocess.check_call(['%s/runConfigureICU' % icu_dir, 'Linux'])
+  print 'Making ICU tools...'
+  subprocess.check_call(['make', '-j32'])
+
+  # Run the ICU tools.
+  os.chdir('tools/tzcode')
+  shutil.copyfile('%s/%s' % (original_working_dir, data_filename), data_filename)
+  print 'Making ICU data...'
+  subprocess.check_call(['make'])
+
+  # Copy the output files to their ultimate destination.
+  icu_txt_data_dir = '%s/data/misc' % icu_dir
+  print 'Copying zoneinfo64.txt to %s ...' % icu_txt_data_dir
+  shutil.copy('zoneinfo64.txt', icu_txt_data_dir)
+
+  os.chdir(icu_working_dir)
+  icu_dat_data_dir = '%s/stubdata' % icu_dir
+  datfiles = glob.glob('data/out/tmp/icudt??l.dat')
+  if len(datfiles) != 1:
+    print 'ERROR: Unexpectedly found %d .dat files (%s). Halting.' % (len(datfiles), datfiles)
+    sys.exit(1)
+
+  datfile = datfiles[0]
+  print 'Copying %s to %s ...' % (datfile, icu_dat_data_dir)
+  shutil.copy(datfile, icu_dat_data_dir)
+
+  # Switch back to the original working cwd.
+  os.chdir(original_working_dir)
+
+
+def CheckSignature(data_filename):
   signature_filename = '%s.asc' % data_filename
   print 'Verifying signature...'
   # If this fails for you, you probably need to import Paul Eggert's public key:
@@ -116,6 +151,10 @@
   subprocess.check_call(['gpg', '--trusted-key=ED97E90E62AA7E34', '--verify',
                          signature_filename, data_filename])
 
+
+def BuildBionicToolsAndData(data_filename):
+  new_version = re.search('(tzdata.+)\\.tar\\.gz', data_filename).group(1)
+
   print 'Extracting...'
   os.mkdir('extracted')
   tar = tarfile.open(data_filename, 'r')
@@ -130,11 +169,8 @@
   WriteSetupFile()
 
   print 'Calling ZoneCompactor to update bionic to %s...' % new_version
-  libcore_src_dir = '%s/../libcore/luni/src/main/java/' % bionic_dir
   subprocess.check_call(['javac', '-d', '.',
-                         '%s/ZoneCompactor.java' % bionic_libc_tools_zoneinfo_dir,
-                         '%s/libcore/util/ZoneInfo.java' % libcore_src_dir,
-                         '%s/libcore/io/BufferIterator.java' % libcore_src_dir])
+                         '%s/ZoneCompactor.java' % bionic_libc_tools_zoneinfo_dir])
   subprocess.check_call(['java', 'ZoneCompactor',
                          'setup', 'data', 'extracted/zone.tab',
                          bionic_libc_zoneinfo_dir, new_version])
@@ -175,10 +211,16 @@
   for filename in tzdata_filenames:
     if filename > current_filename:
       print 'Found new tzdata: %s' % filename
+      SwitchToNewTemporaryDirectory()
       if use_ftp:
-        FtpUpgrade(ftp, filename)
+        FtpRetrieveFileAndSignature(ftp, filename)
       else:
-        HttpUpgrade(http, filename)
+        HttpRetrieveFileAndSignature(http, filename)
+
+      CheckSignature(filename)
+      BuildIcuToolsAndData(filename)
+      BuildBionicToolsAndData(filename)
+      print 'Look in %s and %s for new data files' % (bionic_dir, icu_dir)
       sys.exit(0)
 
   print 'You already have the latest tzdata (%s)!' % current_version
diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c
index e2599b4..3bbed90 100644
--- a/libc/tzcode/localtime.c
+++ b/libc/tzcode/localtime.c
@@ -74,9 +74,9 @@
 #define WILDABBR    "   "
 #endif /* !defined WILDABBR */
 
-static char     wildabbr[] = WILDABBR;
+static const char       wildabbr[] = WILDABBR;
 
-static const char   gmt[] = "GMT";
+static const char gmt[] = "GMT";
 
 /*
 ** The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
@@ -89,7 +89,7 @@
 #define TZDEFRULESTRING ",M4.1.0,M10.5.0"
 #endif /* !defined TZDEFDST */
 
-struct ttinfo {             /* time type information */
+struct ttinfo {              /* time type information */
     int_fast32_t tt_gmtoff;  /* UT offset in seconds */
     int          tt_isdst;   /* used to set tm_isdst */
     int          tt_abbrind; /* abbreviation list index */
@@ -97,7 +97,7 @@
     int          tt_ttisgmt; /* TRUE if transition is UT */
 };
 
-struct lsinfo {             /* leap second information */
+struct lsinfo {              /* leap second information */
     time_t       ls_trans;   /* transition time */
     int_fast64_t ls_corr;    /* correction to apply */
 };
@@ -112,32 +112,32 @@
 #endif /* !defined TZNAME_MAX */
 
 struct state {
-    int     leapcnt;
-    int     timecnt;
-    int     typecnt;
-    int     charcnt;
-    int     goback;
-    int     goahead;
-    time_t      ats[TZ_MAX_TIMES];
-    unsigned char   types[TZ_MAX_TIMES];
-    struct ttinfo   ttis[TZ_MAX_TYPES];
-    char        chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt),
-                (2 * (MY_TZNAME_MAX + 1)))];
-    struct lsinfo   lsis[TZ_MAX_LEAPS];
-    int defaulttype; /* for early times or if no transitions */
+    int           leapcnt;
+    int           timecnt;
+    int           typecnt;
+    int           charcnt;
+    int           goback;
+    int           goahead;
+    time_t        ats[TZ_MAX_TIMES];
+    unsigned char types[TZ_MAX_TIMES];
+    struct ttinfo ttis[TZ_MAX_TYPES];
+    char          chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt),
+                  (2 * (MY_TZNAME_MAX + 1)))];
+    struct lsinfo lsis[TZ_MAX_LEAPS];
+    int           defaulttype; /* for early times or if no transitions */
 };
 
 struct rule {
-    int          r_type;     /* type of rule--see below */
-    int          r_day;      /* day number of rule */
-    int          r_week;     /* week number of rule */
-    int          r_mon;      /* month number of rule */
-    int_fast32_t r_time;     /* transition time of rule */
+    int          r_type; /* type of rule; see below */
+    int          r_day;  /* day number of rule */
+    int          r_week; /* week number of rule */
+    int          r_mon;  /* month number of rule */
+    int_fast32_t r_time; /* transition time of rule */
 };
 
-#define JULIAN_DAY      0   /* Jn - Julian day */
-#define DAY_OF_YEAR     1   /* n - day of year */
-#define MONTH_NTH_DAY_OF_WEEK   2   /* Mm.n.d - month, week, day of week */
+#define JULIAN_DAY             0       /* Jn = Julian day */
+#define DAY_OF_YEAR            1       /* n = day of year */
+#define MONTH_NTH_DAY_OF_WEEK  2       /* Mm.n.d = month, week, day of week */
 
 /*
 ** Prototypes for static functions.
@@ -147,7 +147,7 @@
 
 static int __bionic_open_tzdata(const char*, int*);
 static int_fast32_t detzcode(const char * codep);
-static time_t   detzcode64(const char * codep);
+static int_fast64_t detzcode64(const char * codep);
 static int      differ_by_repeat(time_t t1, time_t t0);
 static const char * getzname(const char * strp) ATTRIBUTE_PURE;
 static const char * getqzname(const char * strp, const int delim)
@@ -158,13 +158,14 @@
 static const char * getoffset(const char * strp, int_fast32_t * offsetp);
 static const char * getrule(const char * strp, struct rule * rulep);
 static void     gmtload(struct state * sp);
-static struct tm *  gmtsub(const time_t * timep, const int_fast32_t offset,
-                struct tm * tmp, const struct state * sp); // android-changed: added sp.
+static struct tm *  gmtsub(const time_t * timep, int_fast32_t offset,
+                struct tm * tmp, struct state * sp); // android-changed: added sp.
 static struct tm *  localsub(const time_t * timep, int_fast32_t offset,
-                struct tm * tmp, const struct state * sp); // android-changed: added sp.
+                struct tm * tmp, struct state * sp); // android-changed: added sp.
 static int      increment_overflow(int * number, int delta);
 static int      leaps_thru_end_of(int y) ATTRIBUTE_PURE;
 static int      increment_overflow32(int_fast32_t * number, int delta);
+static int      increment_overflow_time(time_t *t, int_fast32_t delta);
 static int      normalize_overflow32(int_fast32_t * tensptr,
                 int * unitsptr, int base);
 static int      normalize_overflow(int * tensptr, int * unitsptr,
@@ -172,32 +173,32 @@
 static void     settzname(void);
 static time_t       time1(struct tm * tmp,
                 struct tm * (*funcp)(const time_t *,
-                int_fast32_t, struct tm *, const struct state *), // android-changed: added state*.
-                int_fast32_t offset, const struct state * sp); // android-changed: added sp.
-static time_t       time2(struct tm * const tmp,
-                struct tm * (*const funcp)(const time_t *,
-                int_fast32_t, struct tm*, const struct state *), // android-changed: added state*.
-                int_fast32_t offset, int * okayp, const struct state * sp); // android-changed: added sp.
+                int_fast32_t, struct tm *, struct state *), // android-changed: added state*.
+                int_fast32_t, struct state * sp); // android-changed: added sp.
+static time_t       time2(struct tm * tmp,
+                struct tm * (*funcp)(const time_t *,
+                int_fast32_t, struct tm*, struct state *), // android-changed: added state*.
+                int_fast32_t offset, int * okayp, struct state * sp); // android-changed: added sp.
 static time_t       time2sub(struct tm *tmp,
                 struct tm * (*funcp) (const time_t *,
-                int_fast32_t, struct tm*, const struct state *), // android-changed: added state*.
-                int_fast32_t offset, int * okayp, int do_norm_secs, const struct state * sp); // android-change: added sp.
+                int_fast32_t, struct tm*, struct state *), // android-changed: added state*.
+                int_fast32_t offset, int * okayp, int do_norm_secs, struct state * sp); // android-change: added sp.
 static struct tm *  timesub(const time_t * timep, int_fast32_t offset,
                 const struct state * sp, struct tm * tmp);
 static int      tmcomp(const struct tm * atmp,
                 const struct tm * btmp);
-static time_t transtime(time_t janfirst, int year,
-                        const struct rule * rulep, int_fast32_t offset)
+static int_fast32_t transtime(int year, const struct rule * rulep,
+                int_fast32_t offset)
         ATTRIBUTE_PURE;
-static int		typesequiv(const struct state * sp, int a, int b);
+static int      typesequiv(const struct state * sp, int a, int b);
 static int      tzload(const char * name, struct state * sp,
                 int doextend);
 static int      tzparse(const char * name, struct state * sp,
                 int lastditch);
 
 #ifdef ALL_STATE
-static struct state *   lclptr;
-static struct state *   gmtptr;
+static struct state * lclptr;
+static struct state * gmtptr;
 #endif /* defined ALL_STATE */
 
 #ifndef ALL_STATE
@@ -211,13 +212,13 @@
 #define TZ_STRLEN_MAX 255
 #endif /* !defined TZ_STRLEN_MAX */
 
-static char     lcl_TZname[TZ_STRLEN_MAX + 1];
-static int      lcl_is_set;
-static int      gmt_is_set;
+static char lcl_TZname[TZ_STRLEN_MAX + 1];
+static int  lcl_is_set;
+static int  gmt_is_set;
 
-char *          tzname[2] = {
-    wildabbr,
-    wildabbr
+char * tzname[2] = {
+    (char *) wildabbr,
+    (char *) wildabbr
 };
 
 /*
@@ -231,46 +232,45 @@
 static struct tm    tmGlobal;
 
 #ifdef USG_COMPAT
-long			timezone = 0;
-int			daylight = 0;
+long                timezone = 0;
+int                 daylight = 0;
 #endif /* defined USG_COMPAT */
 
 #ifdef ALTZONE
-long			altzone = 0;
+long                altzone = 0;
 #endif /* defined ALTZONE */
 
 static int_fast32_t
 detzcode(const char *const codep)
 {
-	register int_fast32_t	result;
-	register int		i;
+    register int_fast32_t result;
+    register int          i;
 
-	result = (codep[0] & 0x80) ? -1 : 0;
-	for (i = 0; i < 4; ++i)
-		result = (result << 8) | (codep[i] & 0xff);
-	return result;
+    result = (codep[0] & 0x80) ? -1 : 0;
+    for (i = 0; i < 4; ++i)
+        result = (result << 8) | (codep[i] & 0xff);
+    return result;
 }
 
-static time_t
+static int_fast64_t
 detzcode64(const char *const codep)
 {
-	register time_t	result;
-	register int	i;
+    register int_fast64_t result;
+    register int          i;
 
-	result = (codep[0] & 0x80) ?  (~(int_fast64_t) 0) : 0;
-	for (i = 0; i < 8; ++i)
-		result = result * 256 + (codep[i] & 0xff);
-	return result;
+    result = (codep[0] & 0x80) ? -1 : 0;
+    for (i = 0; i < 8; ++i)
+        result = (result << 8) | (codep[i] & 0xff);
+    return result;
 }
 
 static void
 settzname(void)
 {
-    register struct state * const   sp = lclptr;
-    register int            i;
+    register struct state * const sp = lclptr;
+    register int                  i;
 
-    tzname[0] = wildabbr;
-    tzname[1] = wildabbr;
+    tzname[0] = tzname[1] = (char *) wildabbr;
 #ifdef USG_COMPAT
     daylight = 0;
     timezone = 0;
@@ -278,12 +278,10 @@
 #ifdef ALTZONE
     altzone = 0;
 #endif /* defined ALTZONE */
-#ifdef ALL_STATE
     if (sp == NULL) {
-        tzname[0] = tzname[1] = gmt;
+        tzname[0] = tzname[1] = (char *) gmt;
         return;
     }
-#endif /* defined ALL_STATE */
     /*
     ** And to get the latest zone names into tzname. . .
     */
@@ -331,12 +329,12 @@
 }
 
 static int
-differ_by_repeat(const time_t t1, const time_t t0)
+differ_by_repeat(const time_t t1 __unused, const time_t t0 __unused)
 {
-	if (TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
-			return 0;
-#if __LP64__ // 32-bit Android only has a signed 32-bit time_t; 64-bit Android is fixed.
-	return t1 - t0 == SECSPERREPEAT;
+    if (TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
+        return 0;
+#if defined(__LP64__) // 32-bit Android only has a signed 32-bit time_t; 64-bit Android is fixed.
+    return t1 - t0 == SECSPERREPEAT;
 #endif
 }
 
@@ -344,42 +342,67 @@
 tzload(register const char* name, register struct state* const sp,
        register const int doextend)
 {
-    register const char *       p;
-    register int            i;
-    register int            fid;
-    register int            stored;
-    register int            nread;
+    register const char * p;
+    register int          i;
+    register int          fid;
+    register int          stored;
+    register int          nread;
     typedef union {
-        struct tzhead   tzhead;
-        char        buf[2 * sizeof(struct tzhead) +
-                    2 * sizeof *sp +
-                    4 * TZ_MAX_TIMES];
+        struct tzhead tzhead;
+        char          buf[2 * sizeof(struct tzhead) +
+                      2 * sizeof *sp +
+                      4 * TZ_MAX_TIMES];
     } u_t;
-#ifdef ALL_STATE
-    register u_t *			up;
+    union local_storage {
+        /*
+        ** Section 4.9.1 of the C standard says that
+        ** "FILENAME_MAX expands to an integral constant expression
+        ** that is the size needed for an array of char large enough
+        ** to hold the longest file name string that the implementation
+        ** guarantees can be opened."
+        */
+        //char            fullname[FILENAME_MAX + 1];
 
-    up = (u_t *) calloc(1, sizeof *up);
-    if (up == NULL)
+        /* The main part of the storage for this function.  */
+        struct {
+            u_t u;
+            struct state st;
+        } u;
+    };
+    //register char *fullname;
+    register u_t *up;
+    register union local_storage *lsp;
+#ifdef ALL_STATE
+    lsp = malloc(sizeof *lsp);
+    if (!lsp)
         return -1;
 #else /* !defined ALL_STATE */
-    u_t				u;
-    register u_t * const		up = &u;
+    union local_storage ls;
+    lsp = &ls;
 #endif /* !defined ALL_STATE */
+    //fullname = lsp->fullname;
+    up = &lsp->u.u;
 
     sp->goback = sp->goahead = FALSE;
-    if (name == NULL && (name = TZDEFAULT) == NULL)
-        goto oops;
+
+    if (! name) {
+        name = TZDEFAULT;
+        if (! name)
+            goto oops;
+    }
+
     int toread;
     fid = __bionic_open_tzdata(name, &toread);
-    if (fid < 0) {
-        return -1;
-    }
-    nread = read(fid, up->buf, toread);
+    if (fid < 0)
+        goto oops;
+
+    nread = read(fid, up->buf, sizeof up->buf);
     if (close(fid) < 0 || nread <= 0)
         goto oops;
     for (stored = 4; stored <= 8; stored *= 2) {
-        int     ttisstdcnt;
-        int     ttisgmtcnt;
+        int ttisstdcnt;
+        int ttisgmtcnt;
+        int timecnt;
 
         ttisstdcnt = (int) detzcode(up->tzhead.tzh_ttisstdcnt);
         ttisgmtcnt = (int) detzcode(up->tzhead.tzh_ttisgmtcnt);
@@ -396,24 +419,45 @@
             (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
                 goto oops;
         if (nread - (p - up->buf) <
-            sp->timecnt * stored +      /* ats */
-            sp->timecnt +           /* types */
-            sp->typecnt * 6 +       /* ttinfos */
-            sp->charcnt +           /* chars */
-            sp->leapcnt * (stored + 4) +    /* lsinfos */
-            ttisstdcnt +            /* ttisstds */
-            ttisgmtcnt)         /* ttisgmts */
+            sp->timecnt * stored +       /* ats */
+            sp->timecnt +                /* types */
+            sp->typecnt * 6 +            /* ttinfos */
+            sp->charcnt +                /* chars */
+            sp->leapcnt * (stored + 4) + /* lsinfos */
+            ttisstdcnt +                 /* ttisstds */
+            ttisgmtcnt)                  /* ttisgmts */
                 goto oops;
+        timecnt = 0;
         for (i = 0; i < sp->timecnt; ++i) {
-            sp->ats[i] = (stored == 4) ?
-                detzcode(p) : detzcode64(p);
+            int_fast64_t at
+              = stored == 4 ? detzcode(p) : detzcode64(p);
+            sp->types[i] = ((TYPE_SIGNED(time_t)
+                     ? time_t_min <= at
+                     : 0 <= at)
+                    && at <= time_t_max);
+            if (sp->types[i]) {
+                if (i && !timecnt && at != time_t_min) {
+                    /*
+                    ** Keep the earlier record, but tweak
+                    ** it so that it starts with the
+                    ** minimum time_t value.
+                    */
+                    sp->types[i - 1] = 1;
+                    sp->ats[timecnt++] = time_t_min;
+                }
+                sp->ats[timecnt++] = at;
+            }
             p += stored;
         }
+        timecnt = 0;
         for (i = 0; i < sp->timecnt; ++i) {
-            sp->types[i] = (unsigned char) *p++;
-            if (sp->types[i] >= sp->typecnt)
+            unsigned char typ = *p++;
+            if (sp->typecnt <= typ)
                 goto oops;
+            if (sp->types[i])
+                sp->types[timecnt++] = typ;
         }
+        sp->timecnt = timecnt;
         for (i = 0; i < sp->typecnt; ++i) {
             register struct ttinfo *    ttisp;
 
@@ -468,44 +512,6 @@
             }
         }
         /*
-        ** Out-of-sort ats should mean we're running on a
-        ** signed time_t system but using a data file with
-        ** unsigned values (or vice versa).
-        */
-        for (i = 0; i < sp->timecnt; ++i)
-            if ((i < sp->timecnt - 1 &&
-                sp->ats[i] > sp->ats[i + 1]) ||
-                (i == sp->timecnt - 1 && !TYPE_SIGNED(time_t) &&
-                sp->ats[i] >
-                ((stored == 4) ? INT32_MAX : INT64_MAX))) {
-                    if (TYPE_SIGNED(time_t)) {
-                        /*
-                        ** Ignore the end (easy).
-                        */
-                        sp->timecnt = i + 1;
-                    } else {
-                        /*
-                        ** Ignore the beginning (harder).
-                        */
-                        register int    j;
-
-                        /*
-                        ** Keep the record right before the
-                        ** epoch boundary,
-                        ** but tweak it so that it starts
-                        ** right with the epoch
-                        ** (thanks to Doug Bailey).
-                        */
-                        sp->ats[i] = 0;
-                        for (j = 0; j + i < sp->timecnt; ++j) {
-                            sp->ats[j] = sp->ats[j + i];
-                            sp->types[j] = sp->types[j + i];
-                        }
-                        sp->timecnt = j;
-                    }
-                    break;
-            }
-        /*
         ** If this is an old file, we're done.
         */
         if (up->tzhead.tzh_version[0] == '\0')
@@ -514,44 +520,44 @@
         for (i = 0; i < nread; ++i)
             up->buf[i] = p[i];
         /*
-        ** If this is a narrow time_t system, we're done.
+        ** If this is a signed narrow time_t system, we're done.
         */
-        if (stored >= (int) sizeof(time_t))
+        if (TYPE_SIGNED(time_t) && stored >= (int) sizeof(time_t))
             break;
     }
     if (doextend && nread > 2 &&
         up->buf[0] == '\n' && up->buf[nread - 1] == '\n' &&
         sp->typecnt + 2 <= TZ_MAX_TYPES) {
-            struct state    ts;
-            register int    result;
+            struct state    *ts = &lsp->u.st;
+            register int result;
 
             up->buf[nread - 1] = '\0';
-            result = tzparse(&up->buf[1], &ts, FALSE);
-            if (result == 0 && ts.typecnt == 2 &&
-                sp->charcnt + ts.charcnt <= TZ_MAX_CHARS) {
+            result = tzparse(&up->buf[1], ts, FALSE);
+            if (result == 0 && ts->typecnt == 2 &&
+                sp->charcnt + ts->charcnt <= TZ_MAX_CHARS) {
                     for (i = 0; i < 2; ++i)
-                        ts.ttis[i].tt_abbrind +=
+                        ts->ttis[i].tt_abbrind +=
                             sp->charcnt;
-                    for (i = 0; i < ts.charcnt; ++i)
+                    for (i = 0; i < ts->charcnt; ++i)
                         sp->chars[sp->charcnt++] =
-                            ts.chars[i];
+                            ts->chars[i];
                     i = 0;
-                    while (i < ts.timecnt &&
-                        ts.ats[i] <=
+                    while (i < ts->timecnt &&
+                        ts->ats[i] <=
                         sp->ats[sp->timecnt - 1])
                             ++i;
-                    while (i < ts.timecnt &&
+                    while (i < ts->timecnt &&
                         sp->timecnt < TZ_MAX_TIMES) {
                         sp->ats[sp->timecnt] =
-                            ts.ats[i];
+                            ts->ats[i];
                         sp->types[sp->timecnt] =
                             sp->typecnt +
-                            ts.types[i];
+                            ts->types[i];
                         ++sp->timecnt;
                         ++i;
                     }
-                    sp->ttis[sp->typecnt++] = ts.ttis[0];
-                    sp->ttis[sp->typecnt++] = ts.ttis[1];
+                    sp->ttis[sp->typecnt++] = ts->ttis[0];
+                    sp->ttis[sp->typecnt++] = ts->ttis[1];
             }
     }
     if (sp->timecnt > 1) {
@@ -618,31 +624,31 @@
 static int
 typesequiv(const struct state *const sp, const int a, const int b)
 {
-	register int	result;
+    register int result;
 
-	if (sp == NULL ||
-		a < 0 || a >= sp->typecnt ||
-		b < 0 || b >= sp->typecnt)
-			result = FALSE;
-	else {
-		register const struct ttinfo *	ap = &sp->ttis[a];
-		register const struct ttinfo *	bp = &sp->ttis[b];
-		result = ap->tt_gmtoff == bp->tt_gmtoff &&
-			ap->tt_isdst == bp->tt_isdst &&
-			ap->tt_ttisstd == bp->tt_ttisstd &&
-			ap->tt_ttisgmt == bp->tt_ttisgmt &&
-			strcmp(&sp->chars[ap->tt_abbrind],
-			&sp->chars[bp->tt_abbrind]) == 0;
-	}
-	return result;
+    if (sp == NULL ||
+        a < 0 || a >= sp->typecnt ||
+        b < 0 || b >= sp->typecnt)
+            result = FALSE;
+    else {
+        register const struct ttinfo *  ap = &sp->ttis[a];
+        register const struct ttinfo *  bp = &sp->ttis[b];
+        result = ap->tt_gmtoff == bp->tt_gmtoff &&
+            ap->tt_isdst == bp->tt_isdst &&
+            ap->tt_ttisstd == bp->tt_ttisstd &&
+            ap->tt_ttisgmt == bp->tt_ttisgmt &&
+            strcmp(&sp->chars[ap->tt_abbrind],
+            &sp->chars[bp->tt_abbrind]) == 0;
+    }
+    return result;
 }
 
-static const int    mon_lengths[2][MONSPERYEAR] = {
+static const int mon_lengths[2][MONSPERYEAR] = {
     { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
     { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
 };
 
-static const int    year_lengths[2] = {
+static const int year_lengths[2] = {
     DAYSPERNYEAR, DAYSPERLYEAR
 };
 
@@ -675,7 +681,7 @@
 static const char *
 getqzname(register const char *strp, const int delim)
 {
-    register int    c;
+    register int c;
 
     while ((c = *strp) != '\0' && c != delim)
         ++strp;
@@ -692,8 +698,8 @@
 static const char *
 getnum(register const char * strp, int * const nump, const int min, const int max)
 {
-    register char   c;
-    register int    num;
+    register char c;
+    register int  num;
 
     if (strp == NULL || !is_digit(c = *strp))
         return NULL;
@@ -724,10 +730,10 @@
     int num;
 
     /*
-    ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
+    ** 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
     ** "M10.4.6/26", which does not conform to Posix,
     ** but which specifies the equivalent of
-    ** ``02:00 on the first Sunday on or after 23 Oct''.
+    ** "02:00 on the first Sunday on or after 23 Oct".
     */
     strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
     if (strp == NULL)
@@ -741,7 +747,7 @@
         *secsp += num * SECSPERMIN;
         if (*strp == ':') {
             ++strp;
-            /* `SECSPERMIN' allows for leap seconds. */
+            /* 'SECSPERMIN' allows for leap seconds. */
             strp = getnum(strp, &num, 0, SECSPERMIN);
             if (strp == NULL)
                 return NULL;
@@ -761,7 +767,7 @@
 static const char *
 getoffset(register const char *strp, int_fast32_t *const offsetp)
 {
-    register int    neg = 0;
+    register int neg = 0;
 
     if (*strp == '-') {
         neg = 1;
@@ -830,19 +836,18 @@
 }
 
 /*
-** Given the Epoch-relative time of January 1, 00:00:00 UTC, in a year, the
-** year, a rule, and the offset from UT at the time that rule takes effect,
-** calculate the Epoch-relative time that rule takes effect.
+** Given a year, a rule, and the offset from UT at the time that rule takes
+** effect, calculate the year-relative time that rule takes effect.
 */
 
-static time_t
-transtime(const time_t janfirst, const int year,
-          register const struct rule *const rulep, const int_fast32_t offset)
+static int_fast32_t
+transtime(const int year, register const struct rule *const rulep,
+          const int_fast32_t offset)
 {
-    register int    leapyear;
-    register time_t value;
-    register int    i;
-    int     d, m1, yy0, yy1, yy2, dow;
+    register int          leapyear;
+    register int_fast32_t value;
+    register int          i;
+    int d, m1, yy0, yy1, yy2, dow;
 
     INITIALIZE(value);
     leapyear = isleap(year);
@@ -856,7 +861,7 @@
         ** add SECSPERDAY times the day number-1 to the time of
         ** January 1, midnight, to get the day.
         */
-        value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
+        value = (rulep->r_day - 1) * SECSPERDAY;
         if (leapyear && rulep->r_day >= 60)
             value += SECSPERDAY;
         break;
@@ -867,16 +872,13 @@
         ** Just add SECSPERDAY times the day number to the time of
         ** January 1, midnight, to get the day.
         */
-        value = janfirst + rulep->r_day * SECSPERDAY;
+        value = rulep->r_day * SECSPERDAY;
         break;
 
     case MONTH_NTH_DAY_OF_WEEK:
         /*
         ** Mm.n.d - nth "dth day" of month m.
         */
-        value = janfirst;
-        for (i = 0; i < rulep->r_mon - 1; ++i)
-            value += mon_lengths[leapyear][i] * SECSPERDAY;
 
         /*
         ** Use Zeller's Congruence to get day-of-week of first day of
@@ -909,13 +911,15 @@
         /*
         ** "d" is the day-of-month (zero-origin) of the day we want.
         */
-        value += d * SECSPERDAY;
+        value = d * SECSPERDAY;
+        for (i = 0; i < rulep->r_mon - 1; ++i)
+            value += mon_lengths[leapyear][i] * SECSPERDAY;
         break;
     }
 
     /*
-    ** "value" is the Epoch-relative time of 00:00:00 UT on the day in
-    ** question. To get the Epoch-relative time of the specified local
+    ** "value" is the year-relative time of 00:00:00 UT on the day in
+    ** question. To get the year-relative time of the specified local
     ** time on that day, add the transition time and the current offset
     ** from UT.
     */
@@ -931,19 +935,16 @@
 tzparse(const char * name, register struct state * const sp,
         const int lastditch)
 {
-    const char *            stdname;
-    const char *            dstname;
-    size_t              stdlen;
-    size_t              dstlen;
-    int_fast32_t                stdoffset;
-    int_fast32_t                dstoffset;
-    register time_t *           atp;
-    register unsigned char *    typep;
-    register char *         cp;
-    register int            load_result;
-    static struct ttinfo    zttinfo;
+    const char *         stdname;
+    const char *         dstname;
+    size_t               stdlen;
+    size_t               dstlen;
+    int_fast32_t         stdoffset;
+    int_fast32_t         dstoffset;
+    register char *      cp;
+    register int         load_result;
+    static struct ttinfo zttinfo;
 
-    INITIALIZE(dstname);
     stdname = name;
     if (lastditch) {
         stdlen = strlen(name);  /* length of standard zone name */
@@ -994,13 +995,12 @@
         if (*name == '\0' && load_result != 0)
             name = TZDEFRULESTRING;
         if (*name == ',' || *name == ';') {
-            struct rule start;
-            struct rule end;
-            register int    year;
-            register int    yearlim;
-            register time_t janfirst;
-            time_t      starttime;
-            time_t      endtime;
+            struct rule  start;
+            struct rule  end;
+            register int year;
+            register int yearlim;
+            register int timecnt;
+            time_t       janfirst;
 
             ++name;
             if ((name = getrule(name, &start)) == NULL)
@@ -1022,46 +1022,48 @@
             sp->ttis[1].tt_gmtoff = -stdoffset;
             sp->ttis[1].tt_isdst = 0;
             sp->ttis[1].tt_abbrind = 0;
-            atp = sp->ats;
-            typep = sp->types;
+            sp->defaulttype = 0;
+            timecnt = 0;
             janfirst = 0;
             yearlim = EPOCH_YEAR + YEARSPERREPEAT;
             for (year = EPOCH_YEAR; year < yearlim; year++) {
-                int_fast32_t yearsecs;
-
-                starttime = transtime(janfirst, year, &start,
-                    stdoffset);
-                endtime = transtime(janfirst, year, &end,
-                    dstoffset);
+                int_fast32_t
+                  starttime = transtime(year, &start, stdoffset),
+                  endtime = transtime(year, &end, dstoffset);
+                int_fast32_t
                 yearsecs = (year_lengths[isleap(year)]
                             * SECSPERDAY);
-                if (starttime > endtime
+                int reversed = endtime < starttime;
+                if (reversed) {
+                    int_fast32_t swap = starttime;
+                    starttime = endtime;
+                    endtime = swap;
+                }
+                if (reversed
                     || (starttime < endtime
                         && (endtime - starttime
                             < (yearsecs
                                + (stdoffset - dstoffset))))) {
-                    if (&sp->ats[TZ_MAX_TIMES - 2] < atp)
+                    if (TZ_MAX_TIMES - 2 < timecnt)
                         break;
                     yearlim = year + YEARSPERREPEAT + 1;
-                    if (starttime > endtime) {
-                        *atp++ = endtime;
-                        *typep++ = 1;   /* DST ends */
-                        *atp++ = starttime;
-                        *typep++ = 0;   /* DST begins */
-                    } else {
-                        *atp++ = starttime;
-                        *typep++ = 0;   /* DST begins */
-                         *atp++ = endtime;
-                        *typep++ = 1;   /* DST ends */
+                    sp->ats[timecnt] = janfirst;
+                    if (increment_overflow_time
+                        (&sp->ats[timecnt], starttime))
+                        break;
+                    sp->types[timecnt++] = reversed;
+                    sp->ats[timecnt] = janfirst;
+                    if (increment_overflow_time
+                        (&sp->ats[timecnt], endtime))
+                        break;
+                    sp->types[timecnt++] = !reversed;
                     }
-                }
-                if (time_t_max - janfirst < yearsecs)
+                if (increment_overflow_time(&janfirst, yearsecs))
                     break;
-                janfirst += yearsecs;
             }
-            sp->timecnt = atp - sp->ats;
-            if (!sp->timecnt)
-                sp->typecnt = 1;	/* Perpetual DST.  */
+            sp->timecnt = timecnt;
+            if (!timecnt)
+                sp->typecnt = 1;    /* Perpetual DST.  */
         } else {
             register int_fast32_t   theirstdoffset;
             register int_fast32_t   theirdstoffset;
@@ -1146,6 +1148,7 @@
             sp->ttis[1].tt_isdst = TRUE;
             sp->ttis[1].tt_abbrind = stdlen + 1;
             sp->typecnt = 2;
+            sp->defaulttype = 0;
         }
     } else {
         dstlen = 0;
@@ -1155,6 +1158,7 @@
         sp->ttis[0].tt_gmtoff = -stdoffset;
         sp->ttis[0].tt_isdst = 0;
         sp->ttis[0].tt_abbrind = 0;
+        sp->defaulttype = 0;
     }
     sp->charcnt = stdlen + 1;
     if (dstlen != 0)
@@ -1195,7 +1199,7 @@
 
 #ifdef ALL_STATE
     if (lclptr == NULL) {
-        lclptr = calloc(1, sizeof *lclptr);
+        lclptr = malloc(sizeof *lclptr);
         if (lclptr == NULL) {
             settzname();    /* all we can do */
             return;
@@ -1212,7 +1216,7 @@
 static void
 tzset_locked(void)
 {
-    register const char *   name = NULL;
+    register const char * name;
 
     name = getenv("TZ");
 
@@ -1235,7 +1239,7 @@
 
 #ifdef ALL_STATE
     if (lclptr == NULL) {
-        lclptr = calloc(1, sizeof *lclptr);
+        lclptr = malloc(sizeof *lclptr);
         if (lclptr == NULL) {
             settzname();    /* all we can do */
             return;
@@ -1279,27 +1283,25 @@
 /*ARGSUSED*/
 static struct tm *
 localsub(const time_t * const timep, const int_fast32_t offset,
-         struct tm * const tmp, const struct state * sp) // android-changed: added sp.
+         struct tm * const tmp, struct state * sp) // android-changed: added sp.
 {
-    register const struct ttinfo *  ttisp;
-    register int            i;
-    register struct tm *        result;
-    const time_t            t = *timep;
+    register const struct ttinfo * ttisp;
+    register int         i;
+    register struct tm * result;
+    const time_t         t = *timep;
 
     // BEGIN android-changed: support user-supplied sp.
     if (sp == NULL) {
         sp = lclptr;
     }
     // END android-changed
-#ifdef ALL_STATE
     if (sp == NULL)
         return gmtsub(timep, offset, tmp, sp); // android-changed: added sp.
-#endif /* defined ALL_STATE */
     if ((sp->goback && t < sp->ats[0]) ||
         (sp->goahead && t > sp->ats[sp->timecnt - 1])) {
             time_t          newt = t;
-            register time_t     seconds;
-            register time_t     years;
+            register time_t seconds;
+            register time_t years;
 
             if (t < sp->ats[0])
                 seconds = sp->ats[0] - t;
@@ -1330,8 +1332,8 @@
     if (sp->timecnt == 0 || t < sp->ats[0]) {
         i = sp->defaulttype;
     } else {
-        register int    lo = 1;
-        register int    hi = sp->timecnt;
+        register int lo = 1;
+        register int hi = sp->timecnt;
 
         while (lo < hi) {
             register int    mid = (lo + hi) >> 1;
@@ -1371,7 +1373,7 @@
 struct tm *
 localtime_r(const time_t * const timep, struct tm * tmp)
 {
-    struct tm*  result;
+    struct tm* result;
 
     _tzLock();
     tzset_locked();
@@ -1387,18 +1389,18 @@
 
 static struct tm *
 gmtsub(const time_t * const timep, const int_fast32_t offset,
-       struct tm *const tmp, const struct state * sp) // android-changed: added sp.
+       struct tm *const tmp, struct state * sp __unused) // android-changed: added sp.
 {
-    register struct tm *    result;
-
-    (void) sp; // android-added: unused.
+    register struct tm * result;
 
     if (!gmt_is_set) {
-        gmt_is_set = TRUE;
 #ifdef ALL_STATE
-        gmtptr = calloc(1, sizeof *gmtptr);
-        if (gmtptr != NULL)
+        gmtptr = malloc(sizeof *gmtptr);
+        gmt_is_set = gmtptr != NULL;
+#else
+        gmt_is_set = TRUE;
 #endif /* defined ALL_STATE */
+        if (gmt_is_set)
             gmtload(gmtptr);
     }
     result = timesub(timep, offset, gmtptr, tmp);
@@ -1408,18 +1410,7 @@
     ** "UT+xxxx" or "UT-xxxx" if offset is non-zero,
     ** but this is no time for a treasure hunt.
     */
-    if (offset != 0)
-        tmp->TM_ZONE = wildabbr;
-    else {
-#ifdef ALL_STATE
-        if (gmtptr == NULL)
-            tmp->TM_ZONE = gmt;
-        else    tmp->TM_ZONE = gmtptr->chars;
-#endif /* defined ALL_STATE */
-#ifndef ALL_STATE
-        tmp->TM_ZONE = gmtptr->chars;
-#endif /* State Farm */
-    }
+    tmp->TM_ZONE = offset ? wildabbr : gmtptr ? gmtptr->chars : gmt;
 #endif /* defined TM_ZONE */
     return result;
 }
@@ -1437,7 +1428,7 @@
 struct tm *
 gmtime_r(const time_t * const timep, struct tm * tmp)
 {
-    struct tm*  result;
+    struct tm* result;
 
     _tzLock();
     result = gmtsub(timep, 0L, tmp, NULL); // android-changed: extra parameter.
@@ -1446,6 +1437,16 @@
     return result;
 }
 
+#ifdef STD_INSPIRED
+
+struct tm *
+offtime(const time_t *const timep, const long offset)
+{
+    return gmtsub(timep, offset, &tmGlobal, NULL); // android-changed: extra parameter.
+}
+
+#endif /* defined STD_INSPIRED */
+
 /*
 ** Return the number of leap years through the end of the given year
 ** where, to make the math easy, the answer for year zero is defined as zero.
@@ -1463,24 +1464,19 @@
         register const struct state *const sp,
         register struct tm *const tmp)
 {
-    register const struct lsinfo *  lp;
-    register time_t         tdays;
-    register int            idays;  /* unsigned would be so 2003 */
-    register int_fast64_t           rem;
-    int             y;
-    register const int *        ip;
-    register int_fast64_t           corr;
-    register int            hit;
-    register int            i;
+    register const struct lsinfo * lp;
+    register time_t       tdays;
+    register int          idays;  /* unsigned would be so 2003 */
+    register int_fast64_t rem;
+    int                   y;
+    register const int *  ip;
+    register int_fast64_t corr;
+    register int          hit;
+    register int          i;
 
     corr = 0;
     hit = 0;
-#ifdef ALL_STATE
     i = (sp == NULL) ? 0 : sp->leapcnt;
-#endif /* defined ALL_STATE */
-#ifndef ALL_STATE
-    i = sp->leapcnt;
-#endif /* State Farm */
     while (--i >= 0) {
         lp = &sp->lsis[i];
         if (*timep >= lp->ls_trans) {
@@ -1631,61 +1627,77 @@
 static int
 increment_overflow(int *const ip, int j)
 {
-	register int const	i = *ip;
+    register int const i = *ip;
 
-	/*
-	** If i >= 0 there can only be overflow if i + j > INT_MAX
-	** or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow.
-	** If i < 0 there can only be overflow if i + j < INT_MIN
-	** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
-	*/
-	if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i))
-		return TRUE;
-	*ip += j;
-	return FALSE;
+    /*
+    ** If i >= 0 there can only be overflow if i + j > INT_MAX
+    ** or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow.
+    ** If i < 0 there can only be overflow if i + j < INT_MIN
+    ** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
+    */
+    if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i))
+        return TRUE;
+    *ip += j;
+    return FALSE;
 }
 
 static int
 increment_overflow32(int_fast32_t *const lp, int const m)
 {
-	register int_fast32_t const	l = *lp;
+    register int_fast32_t const l = *lp;
 
-	if ((l >= 0) ? (m > INT_FAST32_MAX - l) : (m < INT_FAST32_MIN - l))
-		return TRUE;
-	*lp += m;
-	return FALSE;
+    if ((l >= 0) ? (m > INT_FAST32_MAX - l) : (m < INT_FAST32_MIN - l))
+        return TRUE;
+    *lp += m;
+    return FALSE;
+}
+
+static int
+increment_overflow_time(time_t *tp, int_fast32_t j)
+{
+    /*
+    ** This is like
+    ** 'if (! (time_t_min <= *tp + j && *tp + j <= time_t_max)) ...',
+    ** except that it does the right thing even if *tp + j would overflow.
+    */
+    if (! (j < 0
+           ? (TYPE_SIGNED(time_t) ? time_t_min - j <= *tp : -1 - j < *tp)
+           : *tp <= time_t_max - j))
+        return TRUE;
+    *tp += j;
+    return FALSE;
 }
 
 static int
 normalize_overflow(int *const tensptr, int *const unitsptr, const int base)
 {
-	register int	tensdelta;
+    register int tensdelta;
 
-	tensdelta = (*unitsptr >= 0) ?
-		(*unitsptr / base) :
-		(-1 - (-1 - *unitsptr) / base);
-	*unitsptr -= tensdelta * base;
-	return increment_overflow(tensptr, tensdelta);
+    tensdelta = (*unitsptr >= 0) ?
+        (*unitsptr / base) :
+        (-1 - (-1 - *unitsptr) / base);
+    *unitsptr -= tensdelta * base;
+    return increment_overflow(tensptr, tensdelta);
 }
 
 static int
 normalize_overflow32(int_fast32_t *const tensptr, int *const unitsptr,
-		     const int base)
+             const int base)
 {
-	register int	tensdelta;
+    register int tensdelta;
 
-	tensdelta = (*unitsptr >= 0) ?
-		(*unitsptr / base) :
-		(-1 - (-1 - *unitsptr) / base);
-	*unitsptr -= tensdelta * base;
-	return increment_overflow32(tensptr, tensdelta);
+    tensdelta = (*unitsptr >= 0) ?
+        (*unitsptr / base) :
+        (-1 - (-1 - *unitsptr) / base);
+    *unitsptr -= tensdelta * base;
+    return increment_overflow32(tensptr, tensdelta);
 }
 
 static int
 tmcomp(register const struct tm * const atmp,
        register const struct tm * const btmp)
 {
-    register int    result;
+    register int result;
 
     if (atmp->tm_year != btmp->tm_year)
         return atmp->tm_year < btmp->tm_year ? -1 : 1;
@@ -1699,21 +1711,21 @@
 
 static time_t
 time2sub(struct tm * const tmp,
-         struct tm *(*const funcp)(const time_t*, int_fast32_t, struct tm*, const struct state*),
+         struct tm *(*const funcp)(const time_t*, int_fast32_t, struct tm*, struct state*),
          const int_fast32_t offset,
          int * const okayp,
-         const int do_norm_secs, const struct state * sp) // android-changed: added sp
+         const int do_norm_secs, struct state * sp) // android-changed: added sp
 {
-    register int            dir;
-    register int            i, j;
-    register int            saved_seconds;
-    register int_fast32_t           li;
-    register time_t         lo;
-    register time_t         hi;
-    int_fast32_t                y;
-    time_t              newt;
-    time_t              t;
-    struct tm           yourtm, mytm;
+    register int          dir;
+    register int          i, j;
+    register int          saved_seconds;
+    register int_fast32_t li;
+    register time_t       lo;
+    register time_t       hi;
+    int_fast32_t          y;
+    time_t                newt;
+    time_t                t;
+    struct tm             yourtm, mytm;
 
     *okayp = FALSE;
     yourtm = *tmp;
@@ -1837,14 +1849,12 @@
         */
         // BEGIN android-changed: support user-supplied sp
         if (sp == NULL) {
-            sp = (const struct state *)
+            sp = (struct state *)
                 ((funcp == localsub) ? lclptr : gmtptr);
         }
         // END android-changed
-#ifdef ALL_STATE
         if (sp == NULL)
             return WRONG;
-#endif /* defined ALL_STATE */
         for (i = sp->typecnt - 1; i >= 0; --i) {
             if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
                 continue;
@@ -1880,11 +1890,11 @@
 
 static time_t
 time2(struct tm * const tmp,
-      struct tm * (*const funcp)(const time_t *, int_fast32_t, struct tm *, const struct state *), // android-changed: added sp.
+      struct tm * (*const funcp)(const time_t *, int_fast32_t, struct tm *, struct state *), // android-changed: added sp.
       const int_fast32_t offset,
-      int *const okayp, const struct state* sp) // android-changed: added sp.
+      int *const okayp, struct state* sp) // android-changed: added sp.
 {
-    time_t  t;
+    time_t t;
 
     /*
     ** First try without normalization of seconds
@@ -1897,16 +1907,16 @@
 
 static time_t
 time1(struct tm * const tmp,
-      struct tm * (* const funcp) (const time_t *, int_fast32_t, struct tm *, const struct state *), // android-changed: added sp.
-      const int_fast32_t offset, const struct state * sp) // android-changed: added sp.
+      struct tm * (* const funcp) (const time_t *, int_fast32_t, struct tm *, struct state *), // android-changed: added sp.
+      const int_fast32_t offset, struct state * sp) // android-changed: added sp.
 {
-    register time_t         t;
-    register int            samei, otheri;
-    register int            sameind, otherind;
-    register int            i;
-    register int            nseen;
-    int             seen[TZ_MAX_TYPES];
-    int             types[TZ_MAX_TYPES];
+    register time_t t;
+    register int    samei, otheri;
+    register int    sameind, otherind;
+    register int    i;
+    register int    nseen;
+    char            seen[TZ_MAX_TYPES];
+    unsigned char   types[TZ_MAX_TYPES];
     int             okay;
 
     if (tmp == NULL) {
@@ -1916,17 +1926,15 @@
     if (tmp->tm_isdst > 1)
         tmp->tm_isdst = 1;
     t = time2(tmp, funcp, offset, &okay, sp); // android-changed: added sp.
-#ifdef PCTS
-    /*
-    ** PCTS code courtesy Grant Sullivan.
-    */
     if (okay)
         return t;
     if (tmp->tm_isdst < 0)
+#ifdef PCTS
+        /*
+        ** POSIX Conformance Test Suite code courtesy Grant Sullivan.
+        */
         tmp->tm_isdst = 0;  /* reset to std and try again */
-#endif /* defined PCTS */
-#ifndef PCTS
-    if (okay || tmp->tm_isdst < 0)
+#else
         return t;
 #endif /* !defined PCTS */
     /*
@@ -1937,13 +1945,11 @@
     */
     // BEGIN android-changed: support user-supplied sp.
     if (sp == NULL) {
-        sp = (const struct state *) ((funcp == localsub) ?  lclptr : gmtptr);
+        sp = (struct state *) ((funcp == localsub) ?  lclptr : gmtptr);
     }
     // BEGIN android-changed
-#ifdef ALL_STATE
     if (sp == NULL)
         return WRONG;
-#endif /* defined ALL_STATE */
     for (i = 0; i < sp->typecnt; ++i)
         seen[i] = FALSE;
     nseen = 0;
@@ -1997,7 +2003,7 @@
 time_t
 timegm(struct tm * const tmp)
 {
-    time_t  result;
+    time_t result;
 
     if (tmp != NULL)
         tmp->tm_isdst = 0;
@@ -2008,6 +2014,14 @@
     return result;
 }
 
+time_t
+timeoff(struct tm *const tmp, const long offset)
+{
+    if (tmp != NULL)
+        tmp->tm_isdst = 0;
+    return time1(tmp, gmtsub, offset, NULL); // android-changed: extra parameter.
+}
+
 #endif /* defined STD_INSPIRED */
 
 #ifdef CMUCS
@@ -2020,7 +2034,7 @@
 long
 gtime(struct tm * const tmp)
 {
-    const time_t    t = mktime(tmp);
+    const time_t t = mktime(tmp);
 
     if (t == WRONG)
         return -1;
@@ -2046,9 +2060,9 @@
 static int_fast64_t
 leapcorr(time_t * timep)
 {
-    register struct state *     sp;
-    register struct lsinfo *    lp;
-    register int            i;
+    register struct state *  sp;
+    register struct lsinfo * lp;
+    register int             i;
 
     sp = lclptr;
     i = sp->leapcnt;
@@ -2070,8 +2084,8 @@
 time_t
 posix2time(time_t t)
 {
-    time_t  x;
-    time_t  y;
+    time_t x;
+    time_t y;
 
     tzset();
     /*
@@ -2108,10 +2122,6 @@
 #include <stdint.h>
 #include <arpa/inet.h> // For ntohl(3).
 
-static int to_int(unsigned char* s) {
-  return (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
-}
-
 static int __bionic_open_tzdata_path(const char* path_prefix_variable, const char* path_suffix,
                                      const char* olson_id, int* data_size) {
   const char* path_prefix = getenv(path_prefix_variable);
@@ -2119,11 +2129,17 @@
     fprintf(stderr, "%s: %s not set!\n", __FUNCTION__, path_prefix_variable);
     return -1;
   }
-  char path[PATH_MAX];
-  snprintf(path, sizeof(path), "%s/%s", path_prefix, path_suffix);
+  size_t path_length = strlen(path_prefix) + 1 + strlen(path_suffix) + 1;
+  char* path = malloc(path_length);
+  if (path == NULL) {
+    fprintf(stderr, "%s: couldn't allocate %zu-byte path\n", __FUNCTION__, path_length);
+    return -1;
+  }
+  snprintf(path, path_length, "%s/%s", path_prefix, path_suffix);
   int fd = TEMP_FAILURE_RETRY(open(path, OPEN_MODE));
   if (fd == -1) {
     XLOG(("%s: could not open \"%s\": %s\n", __FUNCTION__, path, strerror(errno)));
+    free(path);
     return -2; // Distinguish failure to find any data from failure to find a specific id.
   }
 
@@ -2142,6 +2158,7 @@
   if (bytes_read != sizeof(header)) {
     fprintf(stderr, "%s: could not read header of \"%s\": %s\n",
             __FUNCTION__, path, (bytes_read == -1) ? strerror(errno) : "short read");
+    free(path);
     close(fd);
     return -1;
   }
@@ -2149,6 +2166,7 @@
   if (strncmp(header.tzdata_version, "tzdata", 6) != 0 || header.tzdata_version[11] != 0) {
     fprintf(stderr, "%s: bad magic in \"%s\": \"%.6s\"\n",
             __FUNCTION__, path, header.tzdata_version);
+    free(path);
     close(fd);
     return -1;
   }
@@ -2163,34 +2181,58 @@
   if (TEMP_FAILURE_RETRY(lseek(fd, ntohl(header.index_offset), SEEK_SET)) == -1) {
     fprintf(stderr, "%s: couldn't seek to index in \"%s\": %s\n",
             __FUNCTION__, path, strerror(errno));
+    free(path);
     close(fd);
     return -1;
   }
 
   off_t specific_zone_offset = -1;
+  ssize_t index_size = ntohl(header.data_offset) - ntohl(header.index_offset);
+  char* index = malloc(index_size);
+  if (index == NULL) {
+    fprintf(stderr, "%s: couldn't allocate %zd-byte index for \"%s\"\n",
+            __FUNCTION__, index_size, path);
+    free(path);
+    close(fd);
+    return -1;
+  }
+  if (TEMP_FAILURE_RETRY(read(fd, index, index_size)) != index_size) {
+    fprintf(stderr, "%s: could not read index of \"%s\": %s\n",
+            __FUNCTION__, path, (bytes_read == -1) ? strerror(errno) : "short read");
+    free(path);
+    free(index);
+    close(fd);
+    return -1;
+  }
 
   static const size_t NAME_LENGTH = 40;
-  unsigned char buf[NAME_LENGTH + 3 * sizeof(int32_t)];
+  struct index_entry_t {
+    char buf[NAME_LENGTH];
+    int32_t start;
+    int32_t length;
+    int32_t unused; // Was raw GMT offset; always 0 since tzdata2014f (L).
+  };
 
-  size_t id_count = (ntohl(header.data_offset) - ntohl(header.index_offset)) / sizeof(buf);
+  size_t id_count = (ntohl(header.data_offset) - ntohl(header.index_offset)) / sizeof(struct index_entry_t);
+  struct index_entry_t* entry = (struct index_entry_t*) index;
   for (size_t i = 0; i < id_count; ++i) {
-    if (TEMP_FAILURE_RETRY(read(fd, buf, sizeof(buf))) != (ssize_t) sizeof(buf)) {
-      break;
-    }
-
     char this_id[NAME_LENGTH + 1];
-    memcpy(this_id, buf, NAME_LENGTH);
+    memcpy(this_id, entry->buf, NAME_LENGTH);
     this_id[NAME_LENGTH] = '\0';
 
     if (strcmp(this_id, olson_id) == 0) {
-      specific_zone_offset = to_int(buf + NAME_LENGTH) + ntohl(header.data_offset);
-      *data_size = to_int(buf + NAME_LENGTH + sizeof(int32_t));
+      specific_zone_offset = ntohl(entry->start) + ntohl(header.data_offset);
+      *data_size = ntohl(entry->length);
       break;
     }
+
+    ++entry;
   }
+  free(index);
 
   if (specific_zone_offset == -1) {
     XLOG(("%s: couldn't find zone \"%s\"\n", __FUNCTION__, olson_id));
+    free(path);
     close(fd);
     return -1;
   }
@@ -2198,12 +2240,14 @@
   if (TEMP_FAILURE_RETRY(lseek(fd, specific_zone_offset, SEEK_SET)) == -1) {
     fprintf(stderr, "%s: could not seek to %ld in \"%s\": %s\n",
             __FUNCTION__, specific_zone_offset, path, strerror(errno));
+    free(path);
     close(fd);
     return -1;
   }
 
   // TODO: check that there's TZ_MAGIC at this offset, so we can fall back to the other file if not.
 
+  free(path);
   return fd;
 }
 
@@ -2225,12 +2269,12 @@
   _tzLock();
 
   // Our single-item cache.
-  static char* gCachedTimeZoneName;
-  static struct state gCachedTimeZone;
+  static char* g_cached_time_zone_name;
+  static struct state g_cached_time_zone;
 
   // Do we already have this timezone cached?
-  if (gCachedTimeZoneName != NULL && strcmp(name, gCachedTimeZoneName) == 0) {
-    *sp = gCachedTimeZone;
+  if (g_cached_time_zone_name != NULL && strcmp(name, g_cached_time_zone_name) == 0) {
+    *sp = g_cached_time_zone;
     _tzUnlock();
     return 0;
   }
@@ -2239,9 +2283,9 @@
   int rc = tzload(name, sp, doextend);
   if (rc == 0) {
     // Update the cache.
-    free(gCachedTimeZoneName);
-    gCachedTimeZoneName = strdup(name);
-    gCachedTimeZone = *sp;
+    free(g_cached_time_zone_name);
+    g_cached_time_zone_name = strdup(name);
+    g_cached_time_zone = *sp;
   }
 
   _tzUnlock();
@@ -2249,23 +2293,21 @@
 }
 
 // Non-standard API: mktime(3) but with an explicit timezone parameter.
-time_t mktime_tz(struct tm* const tmp, const char* tz) {
-  struct state st;
-  if (__bionic_tzload_cached(tz, &st, TRUE) != 0) {
-    // TODO: not sure what's best here, but for now, we fall back to gmt.
-    gmtload(&st);
-  }
-  return time1(tmp, localsub, 0L, &st);
-}
+// This can't actually be hidden/removed until we fix MtpUtils.cpp
+__attribute__((visibility("default"))) time_t mktime_tz(struct tm* const tmp, const char* tz) {
+  struct state* st = malloc(sizeof(*st));
+  time_t return_value;
 
-// Non-standard API: localtime(3) but with an explicit timezone parameter.
-void localtime_tz(const time_t* const timep, struct tm* tmp, const char* tz) {
-  struct state st;
-  if (__bionic_tzload_cached(tz, &st, TRUE) != 0) {
+  if (st == NULL)
+    return 0;
+  if (__bionic_tzload_cached(tz, st, TRUE) != 0) {
     // TODO: not sure what's best here, but for now, we fall back to gmt.
-    gmtload(&st);
+    gmtload(st);
   }
-  localsub(timep, 0L, tmp, &st);
+
+  return_value = time1(tmp, localsub, 0L, st);
+  free(st);
+  return return_value;
 }
 
 // END android-added
diff --git a/libc/tzcode/private.h b/libc/tzcode/private.h
index 3a19305..c30c711 100644
--- a/libc/tzcode/private.h
+++ b/libc/tzcode/private.h
@@ -19,7 +19,7 @@
 
 /*
 ** Defaults for preprocessor symbols.
-** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
+** You can override these in your C compiler options, e.g. '-DHAVE_ADJTIME=0'.
 */
 
 #ifndef HAVE_ADJTIME
@@ -34,6 +34,10 @@
 #define HAVE_INCOMPATIBLE_CTIME_R	0
 #endif /* !defined INCOMPATIBLE_CTIME_R */
 
+#ifndef HAVE_LINK
+#define HAVE_LINK		1
+#endif /* !defined HAVE_LINK */
+
 #ifndef HAVE_SETTIMEOFDAY
 #define HAVE_SETTIMEOFDAY	3
 #endif /* !defined HAVE_SETTIMEOFDAY */
@@ -58,9 +62,11 @@
 #define HAVE_UTMPX_H		0
 #endif /* !defined HAVE_UTMPX_H */
 
+#if !defined(__ANDROID__)
 #ifndef LOCALE_HOME
 #define LOCALE_HOME		"/usr/lib/locale"
 #endif /* !defined LOCALE_HOME */
+#endif // __ANDROID__
 
 #if HAVE_INCOMPATIBLE_CTIME_R
 #define asctime_r _incompatible_asctime_r
@@ -116,8 +122,9 @@
 */
 #ifndef HAVE_STDINT_H
 #define HAVE_STDINT_H \
-	(199901 <= __STDC_VERSION__ || \
-	2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
+   (199901 <= __STDC_VERSION__ \
+    || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__)	\
+    || __CYGWIN__)
 #endif /* !defined HAVE_STDINT_H */
 
 #if HAVE_STDINT_H
@@ -201,6 +208,10 @@
 #define INT32_MIN (-1 - INT32_MAX)
 #endif /* !defined INT32_MIN */
 
+#ifndef SIZE_MAX
+#define SIZE_MAX ((size_t) -1)
+#endif
+
 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
 # define ATTRIBUTE_CONST __attribute__ ((const))
 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
@@ -343,29 +354,15 @@
 ** INITIALIZE(x)
 */
 
-#ifndef GNUC_or_lint
 #ifdef lint
-#define GNUC_or_lint
-#endif /* defined lint */
-#ifndef lint
-#ifdef __GNUC__
-#define GNUC_or_lint
-#endif /* defined __GNUC__ */
-#endif /* !defined lint */
-#endif /* !defined GNUC_or_lint */
-
-#ifndef INITIALIZE
-#ifdef GNUC_or_lint
-#define INITIALIZE(x)	((x) = 0)
-#endif /* defined GNUC_or_lint */
-#ifndef GNUC_or_lint
-#define INITIALIZE(x)
-#endif /* !defined GNUC_or_lint */
-#endif /* !defined INITIALIZE */
+# define INITIALIZE(x)	((x) = 0)
+#else
+# define INITIALIZE(x)
+#endif
 
 /*
 ** For the benefit of GNU folk...
-** `_(MSGID)' uses the current locale's message library string for MSGID.
+** '_(MSGID)' uses the current locale's message library string for MSGID.
 ** The default is to use gettext if available, and use MSGID otherwise.
 */
 
@@ -377,9 +374,9 @@
 #endif /* !HAVE_GETTEXT */
 #endif /* !defined _ */
 
-#ifndef TZ_DOMAIN
-#define TZ_DOMAIN "tz"
-#endif /* !defined TZ_DOMAIN */
+#if !defined TZ_DOMAIN && defined TZ_DOMAINDIR
+# define TZ_DOMAIN "tz"
+#endif
 
 #if HAVE_INCOMPATIBLE_CTIME_R
 #undef asctime_r
diff --git a/libc/tzcode/strftime.c b/libc/tzcode/strftime.c
index 1164a13..4328b4c 100644
--- a/libc/tzcode/strftime.c
+++ b/libc/tzcode/strftime.c
@@ -1,12 +1,9 @@
-#ifndef lint
-#ifndef NOID
-static char elsieid[] = "@(#)strftime.c 8.1";
 /*
-** Based on the UCB version with the ID appearing below.
+** Based on the UCB version with the copyright notice and sccsid
+** appearing below.
+**
 ** This is ANSIish only when "multibyte character == plain character".
 */
-#endif /* !defined NOID */
-#endif /* !defined lint */
 
 #include "private.h"
 
@@ -22,30 +19,29 @@
 ** by the University of California, Berkeley. The name of the
 ** University may not be used to endorse or promote products derived
 ** from this software without specific prior written permission.
-** THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+** THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
 ** IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
 
-#ifndef LIBC_SCCS
-#ifndef lint
-static const char   sccsid[] = "@(#)strftime.c  5.4 (Berkeley) 3/14/89";
-#endif /* !defined lint */
-#endif /* !defined LIBC_SCCS */
-
 #include "tzfile.h"
 #include "fcntl.h"
 #include "locale.h"
-#include <ctype.h>
-#include <time64.h>
-#include "private/bionic_time.h"  /* for strftime_tz */
 
-/* struct lc_time_T is now defined as strftime_locale
- * in <time.h>
- */
-#if 1
-#define  lc_time_T    strftime_locale
+#if __ANDROID__
+
+/* LP32 had a 32-bit time_t, so we need to work around that here. */
+#if defined(__LP64__)
+#define time64_t time_t
+#define mktime64 mktime
 #else
+#include <time64.h>
+#endif
+
+#include <ctype.h>
+
+#endif
+
 struct lc_time_T {
     const char *    mon[MONSPERYEAR];
     const char *    month[MONSPERYEAR];
@@ -58,9 +54,16 @@
     const char *    pm;
     const char *    date_fmt;
 };
-#endif
 
+#ifdef LOCALE_HOME
+#include "sys/stat.h"
+static struct lc_time_T                localebuf;
+static struct lc_time_T *      _loc(void);
+#define Locale _loc()
+#endif /* defined LOCALE_HOME */
+#ifndef LOCALE_HOME
 #define Locale  (&C_time_locale)
+#endif /* !defined LOCALE_HOME */
 
 static const struct lc_time_T   C_time_locale = {
     {
@@ -70,9 +73,6 @@
         "January", "February", "March", "April", "May", "June",
         "July", "August", "September", "October", "November", "December"
     }, {
-        "January", "February", "March", "April", "May", "June",
-        "July", "August", "September", "October", "November", "December"
-    }, {
         "Sun", "Mon", "Tue", "Wed",
         "Thu", "Fri", "Sat"
     }, {
@@ -114,7 +114,7 @@
 static char *   _add(const char *, char *, const char *, int);
 static char *   _conv(int, const char *, char *, const char *);
 static char *   _fmt(const char *, const struct tm *, char *, const char *,
-            int *, const struct strftime_locale*);
+            int *);
 static char *   _yconv(int, int, int, int, char *, const char *, int);
 static char *   getformat(int, char *, char *, char *, char *);
 
@@ -132,30 +132,19 @@
 #define FORCE_LOWER_CASE 0x100
 
 size_t
-strftime(s, maxsize, format, t)
-char * const        s;
-const size_t        maxsize;
-const char * const  format;
-const struct tm * const t;
-{
-    return strftime_tz(s, maxsize, format, t, Locale);
-}
-
-size_t
-strftime_tz(s, maxsize, format, t, locale)
-char * const        s;
-const size_t        maxsize;
-const char * const  format;
-const struct tm * const t;
-const struct strftime_locale *locale;
+strftime(char * const s, const size_t maxsize, const char *const format,
+        const struct tm *const t)
 {
     char *  p;
     int warn;
 
     tzset();
+#ifdef LOCALE_HOME
+    localebuf.mon[0] = 0;
+#endif /* defined LOCALE_HOME */
     warn = IN_NONE;
-    p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn, locale);
-#if 0  /* ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
+    p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
+#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
     if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
         (void) fprintf(stderr, "\n");
         if (format == NULL)
@@ -194,13 +183,8 @@
 }
 
 static char *
-_fmt(format, t, pt, ptlim, warnp, locale)
-const char *        format;
-const struct tm * const t;
-char *          pt;
-const char * const  ptlim;
-int *           warnp;
-const struct strftime_locale* locale;
+_fmt(const char *format, const struct tm *const t, char * pt,
+        const char *const ptlim, int *warnp)
 {
     for ( ; *format; ++format) {
         if (*format == '%') {
@@ -213,33 +197,26 @@
             case 'A':
                 pt = _add((t->tm_wday < 0 ||
                     t->tm_wday >= DAYSPERWEEK) ?
-                    "?" : locale->weekday[t->tm_wday],
+                    "?" : Locale->weekday[t->tm_wday],
                     pt, ptlim, modifier);
                 continue;
             case 'a':
                 pt = _add((t->tm_wday < 0 ||
                     t->tm_wday >= DAYSPERWEEK) ?
-                    "?" : locale->wday[t->tm_wday],
+                    "?" : Locale->wday[t->tm_wday],
                     pt, ptlim, modifier);
                 continue;
             case 'B':
-                if (modifier == '-') {
-                    pt = _add((t->tm_mon < 0 ||
+                pt = _add((t->tm_mon < 0 ||
                                 t->tm_mon >= MONSPERYEAR) ?
-                                "?" : locale->standalone_month[t->tm_mon],
+                                "?" : Locale->month[t->tm_mon],
                                 pt, ptlim, modifier);
-                } else {
-                    pt = _add((t->tm_mon < 0 ||
-                                t->tm_mon >= MONSPERYEAR) ?
-                                "?" : locale->month[t->tm_mon],
-                                pt, ptlim, modifier);
-                }
                 continue;
             case 'b':
             case 'h':
                 pt = _add((t->tm_mon < 0 ||
                     t->tm_mon >= MONSPERYEAR) ?
-                    "?" : locale->mon[t->tm_mon],
+                    "?" : Locale->mon[t->tm_mon],
                     pt, ptlim, modifier);
                 continue;
             case 'C':
@@ -257,7 +234,7 @@
                 {
                 int warn2 = IN_SOME;
 
-                pt = _fmt(locale->c_fmt, t, pt, ptlim, warnp, locale);
+                pt = _fmt(Locale->c_fmt, t, pt, ptlim, &warn2);
                 if (warn2 == IN_ALL)
                     warn2 = IN_THIS;
                 if (warn2 > *warnp)
@@ -265,7 +242,7 @@
                 }
                 continue;
             case 'D':
-                                pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp, locale);
+                                pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
                 continue;
             case 'd':
                                 pt = _conv(t->tm_mday,
@@ -299,7 +276,7 @@
                                            pt, ptlim);
                 continue;
             case 'F':
-                pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp, locale);
+                pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
                 continue;
             case 'H':
                 pt = _conv(t->tm_hour,
@@ -340,7 +317,7 @@
                 /*
                 ** After all this time, still unclaimed!
                 */
-                pt = _add("kitchen sink", pt, ptlim, modifier);
+                pt = _add("kitchen sink", pt, ptlim);
                 continue;
 #endif /* defined KITCHEN_SINK */
             case 'l':
@@ -376,21 +353,21 @@
                 continue;
             case 'p':
                 pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
-                    locale->pm :
-                    locale->am,
+                    Locale->pm :
+                    Locale->am,
                     pt, ptlim, modifier);
                 continue;
             case 'P':
                 pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
-                    locale->pm :
-                    locale->am,
+                    Locale->pm :
+                    Locale->am,
                     pt, ptlim, FORCE_LOWER_CASE);
                 continue;
             case 'R':
-                pt = _fmt("%H:%M", t, pt, ptlim, warnp, locale);
+                pt = _fmt("%H:%M", t, pt, ptlim, warnp);
                 continue;
             case 'r':
-                pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp, locale);
+                pt = _fmt("%I:%M:%S %p", t, pt, ptlim, warnp);
                 continue;
             case 'S':
                 pt = _conv(t->tm_sec,
@@ -416,7 +393,7 @@
                 }
                 continue;
             case 'T':
-                pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp, locale);
+                pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
                 continue;
             case 't':
                 pt = _add("\t", pt, ptlim, modifier);
@@ -447,7 +424,7 @@
 ** (01-53)."
 ** (ado, 1993-05-24)
 **
-** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
+** From <http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html> by Markus Kuhn:
 ** "Week 01 of a year is per definition the first week which has the
 ** Thursday in this year, which is equivalent to the week which contains
 ** the fourth day of January. In other words, the first week of a new year
@@ -517,11 +494,7 @@
 #endif /* defined XPG4_1994_04_09 */
                     if (*format == 'V')
                         pt = _conv(w,
-                                                           getformat(modifier,
-                                                                     "%02d",
-                                                                     "%2d",
-                                                                     "%d",
-                                                                     "%02d"),
+                                getformat(modifier, "%02d", "%2d", "%d", "%02d"),
                                pt, ptlim);
                     else if (*format == 'g') {
                         *warnp = IN_ALL;
@@ -537,7 +510,7 @@
                 ** "date as dd-bbb-YYYY"
                 ** (ado, 1993-05-24)
                 */
-                pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp, locale);
+                pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
                 continue;
             case 'W':
                 pt = _conv((t->tm_yday + DAYSPERWEEK -
@@ -552,13 +525,13 @@
                 pt = _conv(t->tm_wday, "%d", pt, ptlim);
                 continue;
             case 'X':
-                pt = _fmt(locale->X_fmt, t, pt, ptlim, warnp, locale);
+                pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp);
                 continue;
             case 'x':
                 {
                 int warn2 = IN_SOME;
 
-                pt = _fmt(locale->x_fmt, t, pt, ptlim, &warn2, locale);
+                pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2);
                 if (warn2 == IN_ALL)
                     warn2 = IN_THIS;
                 if (warn2 > *warnp)
@@ -647,8 +620,8 @@
                 }
                 continue;
             case '+':
-                pt = _fmt(locale->date_fmt, t, pt, ptlim,
-                    warnp, locale);
+                pt = _fmt(Locale->date_fmt, t, pt, ptlim,
+                    warnp);
                 continue;
             case '%':
             /*
@@ -668,11 +641,8 @@
 }
 
 static char *
-_conv(n, format, pt, ptlim)
-const int       n;
-const char * const  format;
-char * const        pt;
-const char * const  ptlim;
+_conv(const int n, const char *const format, char *const pt,
+        const char *const ptlim)
 {
     char    buf[INT_STRLEN_MAXIMUM(int) + 1];
 
@@ -681,11 +651,7 @@
 }
 
 static char *
-_add(str, pt, ptlim, modifier)
-const char *        str;
-char *          pt;
-const char * const  ptlim;
-int                     modifier;
+_add(const char *str, char *pt, const char *const ptlim, int modifier)
 {
         int c;
 
@@ -733,14 +699,8 @@
 */
 
 static char *
-_yconv(a, b, convert_top, convert_yy, pt, ptlim, modifier)
-const int       a;
-const int       b;
-const int       convert_top;
-const int       convert_yy;
-char *          pt;
-const char * const  ptlim;
-int                     modifier;
+_yconv(const int a, const int b, const int convert_top, const int convert_yy,
+        char *pt, const char *const ptlim, int modifier)
 {
     register int    lead;
     register int    trail;
@@ -759,13 +719,9 @@
     if (convert_top) {
         if (lead == 0 && trail < 0)
             pt = _add("-0", pt, ptlim, modifier);
-        else    pt = _conv(lead, getformat(modifier, "%02d",
-                                                   "%2d", "%d", "%02d"),
-                                   pt, ptlim);
+        else    pt = _conv(lead, getformat(modifier, "%02d", "%2d", "%d", "%02d"), pt, ptlim);
     }
     if (convert_yy)
-        pt = _conv(((trail < 0) ? -trail : trail),
-                           getformat(modifier, "%02d", "%2d", "%d", "%02d"),
-                           pt, ptlim);
+        pt = _conv(((trail < 0) ? -trail : trail), getformat(modifier, "%02d", "%2d", "%d", "%02d"), pt, ptlim);
     return pt;
 }
diff --git a/libc/tzcode/tzfile.h b/libc/tzcode/tzfile.h
index a2955dd..529650d 100644
--- a/libc/tzcode/tzfile.h
+++ b/libc/tzcode/tzfile.h
@@ -101,16 +101,8 @@
 #endif /* !defined TZ_MAX_TIMES */
 
 #ifndef TZ_MAX_TYPES
-#ifndef NOSOLAR
+/* This must be at least 17 for Europe/Samara and Europe/Vilnius.  */
 #define TZ_MAX_TYPES	256 /* Limited by what (unsigned char)'s can hold */
-#endif /* !defined NOSOLAR */
-#ifdef NOSOLAR
-/*
-** Must be at least 14 for Europe/Riga as of Jan 12 1995,
-** as noted by Earl Chew.
-*/
-#define TZ_MAX_TYPES	20	/* Maximum number of local time types */
-#endif /* !defined NOSOLAR */
 #endif /* !defined TZ_MAX_TYPES */
 
 #ifndef TZ_MAX_CHARS
diff --git a/libc/unistd/alarm.c b/libc/unistd/alarm.c
deleted file mode 100644
index 53edea9..0000000
--- a/libc/unistd/alarm.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)alarm.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-//__FBSDID("$FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/alarm.c,v 1.3 2007/01/09 00:27:53 imp Exp $");
-
-/*
- * Backwards compatible alarm.
- */
-#include <sys/time.h>
-#include <unistd.h>
-
-unsigned int
-alarm(secs)
-	unsigned int secs;
-{
-	struct itimerval it, oitv;
-	struct itimerval *itp = &it;
-
-    itp->it_interval.tv_usec = 0;
-    itp->it_interval.tv_sec = 0;
-	itp->it_value.tv_sec = secs;
-	itp->it_value.tv_usec = 0;
-	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
-#if 1 /* BIONIC: Same behaviour than GLibc for errors */
-		return 0;
-#else
-		return (-1);
-#endif
-	if (oitv.it_value.tv_usec)
-		oitv.it_value.tv_sec++;
-	return (oitv.it_value.tv_sec);
-}
diff --git a/libc/unistd/exec.c b/libc/unistd/exec.c
deleted file mode 100644
index 2fe2a4e..0000000
--- a/libc/unistd/exec.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/*	$OpenBSD: exec.c,v 1.18 2005/08/08 08:05:34 espie Exp $ */
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <stdio.h>
-#include <paths.h>
-#include <stdarg.h>
-#include <alloca.h>
-
-extern char **environ;
-
-int
-execl(const char *name, const char *arg, ...)
-{
-	va_list ap;
-	char **argv;
-	int n;
-
-	va_start(ap, arg);
-	n = 1;
-	while (va_arg(ap, char *) != NULL)
-		n++;
-	va_end(ap);
-	argv = alloca((n + 1) * sizeof(*argv));
-	if (argv == NULL) {
-		errno = ENOMEM;
-		return (-1);
-	}
-	va_start(ap, arg);
-	n = 1;
-	argv[0] = (char *)arg;
-	while ((argv[n] = va_arg(ap, char *)) != NULL)
-		n++;
-	va_end(ap);
-	return (execve(name, argv, environ));
-}
-
-int
-execle(const char *name, const char *arg, ...)
-{
-	va_list ap;
-	char **argv, **envp;
-	int n;
-
-	va_start(ap, arg);
-	n = 1;
-	while (va_arg(ap, char *) != NULL)
-		n++;
-	va_end(ap);
-	argv = alloca((n + 1) * sizeof(*argv));
-	if (argv == NULL) {
-		errno = ENOMEM;
-		return (-1);
-	}
-	va_start(ap, arg);
-	n = 1;
-	argv[0] = (char *)arg;
-	while ((argv[n] = va_arg(ap, char *)) != NULL)
-		n++;
-	envp = va_arg(ap, char **);
-	va_end(ap);
-	return (execve(name, argv, envp));
-}
-
-int
-execlp(const char *name, const char *arg, ...)
-{
-	va_list ap;
-	char **argv;
-	int n;
-
-	va_start(ap, arg);
-	n = 1;
-	while (va_arg(ap, char *) != NULL)
-		n++;
-	va_end(ap);
-	argv = alloca((n + 1) * sizeof(*argv));
-	if (argv == NULL) {
-		errno = ENOMEM;
-		return (-1);
-	}
-	va_start(ap, arg);
-	n = 1;
-	argv[0] = (char *)arg;
-	while ((argv[n] = va_arg(ap, char *)) != NULL)
-		n++;
-	va_end(ap);
-	return (execvp(name, argv));
-}
-
-int
-execv(const char *name, char * const *argv)
-{
-	(void)execve(name, argv, environ);
-	return (-1);
-}
-
-int
-execvp(const char *name, char * const *argv)
-{
-	char **memp;
-	int cnt, lp, ln, len;
-	char *p;
-	int eacces = 0;
-	char *bp, *cur, *path, buf[MAXPATHLEN];
-
-	/*
-	 * Do not allow null name
-	 */
-	if (name == NULL || *name == '\0') {
-		errno = ENOENT;
-		return (-1);
- 	}
-
-	/* If it's an absolute or relative path name, it's easy. */
-	if (strchr(name, '/')) {
-		bp = (char *)name;
-		cur = path = NULL;
-		goto retry;
-	}
-	bp = buf;
-
-	/* Get the path we're searching. */
-	if (!(path = getenv("PATH")))
-		path = _PATH_DEFPATH;
-	len = strlen(path) + 1;
-	cur = alloca(len);
-	if (cur == NULL) {
-		errno = ENOMEM;
-		return (-1);
-	}
-	strlcpy(cur, path, len);
-	path = cur;
-	while ((p = strsep(&cur, ":"))) {
-		/*
-		 * It's a SHELL path -- double, leading and trailing colons
-		 * mean the current directory.
-		 */
-		if (!*p) {
-			p = ".";
-			lp = 1;
-		} else
-			lp = strlen(p);
-		ln = strlen(name);
-
-		/*
-		 * If the path is too long complain.  This is a possible
-		 * security issue; given a way to make the path too long
-		 * the user may execute the wrong program.
-		 */
-		if (lp + ln + 2 > (int)sizeof(buf)) {
-			struct iovec iov[3];
-
-			iov[0].iov_base = "execvp: ";
-			iov[0].iov_len = 8;
-			iov[1].iov_base = p;
-			iov[1].iov_len = lp;
-			iov[2].iov_base = ": path too long\n";
-			iov[2].iov_len = 16;
-			(void)writev(STDERR_FILENO, iov, 3);
-			continue;
-		}
-		memcpy(buf, p, lp);
-		buf[lp] = '/';
-		memcpy(buf + lp + 1, name, ln);
-		buf[lp + ln + 1] = '\0';
-
-retry:		(void)execve(bp, argv, environ);
-		switch(errno) {
-		case E2BIG:
-			goto done;
-		case EISDIR:
-		case ELOOP:
-		case ENAMETOOLONG:
-		case ENOENT:
-			break;
-		case ENOEXEC:
-			for (cnt = 0; argv[cnt]; ++cnt)
-				;
-			memp = alloca((cnt + 2) * sizeof(char *));
-			if (memp == NULL)
-				goto done;
-			memp[0] = "sh";
-			memp[1] = bp;
-			memcpy(memp + 2, argv + 1, cnt * sizeof(char *));
-			(void)execve(_PATH_BSHELL, memp, environ);
-			goto done;
-		case ENOMEM:
-			goto done;
-		case ENOTDIR:
-			break;
-		case ETXTBSY:
-			/*
-			 * We used to retry here, but sh(1) doesn't.
-			 */
-			goto done;
-		case EACCES:
-			eacces = 1;
-			break;
-		default:
-			goto done;
-		}
-	}
-	if (eacces)
-		errno = EACCES;
-	else if (!errno)
-		errno = ENOENT;
-done:
-	return (-1);
-}
diff --git a/libc/unistd/fnmatch.c b/libc/unistd/fnmatch.c
deleted file mode 100644
index c3d1a3c..0000000
--- a/libc/unistd/fnmatch.c
+++ /dev/null
@@ -1,480 +0,0 @@
-/*	$OpenBSD: fnmatch.c,v 1.16 2011/12/06 11:47:46 stsp Exp $	*/
-
-/* Copyright (c) 2011, VMware, Inc.
- * All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in the
- *       documentation and/or other materials provided with the distribution.
- *     * Neither the name of the VMware, Inc. nor the names of its contributors
- *       may be used to endorse or promote products derived from this software
- *       without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 2008 Todd C. Miller <millert@openbsd.org>
- *
- * Permission to use, copy, modify, and 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.
- */
-
-/* Authored by William A. Rowe Jr. <wrowe; apache.org, vmware.com>, April 2011
- *
- * Derived from The Open Group Base Specifications Issue 7, IEEE Std 1003.1-2008
- * as described in;
- *   http://pubs.opengroup.org/onlinepubs/9699919799/functions/fnmatch.html
- *
- * Filename pattern matches defined in section 2.13, "Pattern Matching Notation"
- * from chapter 2. "Shell Command Language"
- *   http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13
- * where; 1. A bracket expression starting with an unquoted <circumflex> '^' 
- * character CONTINUES to specify a non-matching list; 2. an explicit <period> '.' 
- * in a bracket expression matching list, e.g. "[.abc]" does NOT match a leading 
- * <period> in a filename; 3. a <left-square-bracket> '[' which does not introduce
- * a valid bracket expression is treated as an ordinary character; 4. a differing
- * number of consecutive slashes within pattern and string will NOT match;
- * 5. a trailing '\' in FNM_ESCAPE mode is treated as an ordinary '\' character.
- *
- * Bracket expansion defined in section 9.3.5, "RE Bracket Expression",
- * from chapter 9, "Regular Expressions"
- *   http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_05
- * with no support for collating symbols, equivalence class expressions or 
- * character class expressions.  A partial range expression with a leading 
- * hyphen following a valid range expression will match only the ordinary
- * <hyphen> and the ending character (e.g. "[a-m-z]" will match characters 
- * 'a' through 'm', a <hyphen> '-', or a 'z').
- *
- * Supports BSD extensions FNM_LEADING_DIR to match pattern to the end of one
- * path segment of string, and FNM_CASEFOLD to ignore alpha case.
- *
- * NOTE: Only POSIX/C single byte locales are correctly supported at this time.
- * Notably, non-POSIX locales with FNM_CASEFOLD produce undefined results,
- * particularly in ranges of mixed case (e.g. "[A-z]") or spanning alpha and
- * nonalpha characters within a range.
- *
- * XXX comments below indicate porting required for multi-byte character sets
- * and non-POSIX locale collation orders; requires mbr* APIs to track shift
- * state of pattern and string (rewinding pattern and string repeatedly).
- *
- * Certain parts of the code assume 0x00-0x3F are unique with any MBCS (e.g.
- * UTF-8, SHIFT-JIS, etc).  Any implementation allowing '\' as an alternate
- * path delimiter must be aware that 0x5C is NOT unique within SHIFT-JIS.
- */
-
-#include <fnmatch.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include "charclass.h"
-
-#define	RANGE_MATCH	1
-#define	RANGE_NOMATCH	0
-#define	RANGE_ERROR	(-1)
-
-static int
-classmatch(const char *pattern, char test, int foldcase, const char **ep)
-{
-	struct cclass *cc;
-	const char *colon;
-	size_t len;
-	int rval = RANGE_NOMATCH;
-	const char * const mismatch = pattern;
-
-	if (*pattern != '[' || pattern[1] != ':') {
-		*ep = mismatch;
-		return(RANGE_ERROR);
-	}
-
-	pattern += 2;
-
-	if ((colon = strchr(pattern, ':')) == NULL || colon[1] != ']') {
-		*ep = mismatch;
-		return(RANGE_ERROR);
-	}
-	*ep = colon + 2;
-	len = (size_t)(colon - pattern);
-
-	if (foldcase && strncmp(pattern, "upper:]", 7) == 0)
-		pattern = "lower:]";
-	for (cc = cclasses; cc->name != NULL; cc++) {
-		if (!strncmp(pattern, cc->name, len) && cc->name[len] == '\0') {
-			if (cc->isctype((unsigned char)test))
-				rval = RANGE_MATCH;
-			break;
-		}
-	}
-	if (cc->name == NULL) {
-		/* invalid character class, treat as normal text */
-		*ep = mismatch;
-		rval = RANGE_ERROR;
-	}
-	return(rval);
-}
-
-/* Most MBCS/collation/case issues handled here.  Wildcard '*' is not handled.
- * EOS '\0' and the FNM_PATHNAME '/' delimiters are not advanced over, 
- * however the "\/" sequence is advanced to '/'.
- *
- * Both pattern and string are **char to support pointer increment of arbitrary
- * multibyte characters for the given locale, in a later iteration of this code
- */
-static int fnmatch_ch(const char **pattern, const char **string, int flags)
-{
-    const char * const mismatch = *pattern;
-    const int nocase = !!(flags & FNM_CASEFOLD);
-    const int escape = !(flags & FNM_NOESCAPE);
-    const int slash = !!(flags & FNM_PATHNAME);
-    int result = FNM_NOMATCH;
-    const char *startch;
-    int negate;
-
-    if (**pattern == '[')
-    {
-        ++*pattern;
-
-        /* Handle negation, either leading ! or ^ operators (never both) */
-        negate = ((**pattern == '!') || (**pattern == '^'));
-        if (negate)
-            ++*pattern;
-
-        /* ']' is an ordinary character at the start of the range pattern */
-        if (**pattern == ']')
-            goto leadingclosebrace;
-
-        while (**pattern)
-        {
-            if (**pattern == ']') {
-                ++*pattern;
-                /* XXX: Fix for MBCS character width */
-                ++*string;
-                return (result ^ negate);
-            }
-
-            if (escape && (**pattern == '\\')) {
-                ++*pattern;
-
-                /* Patterns must be terminated with ']', not EOS */
-                if (!**pattern)
-                    break;
-            }
-
-            /* Patterns must be terminated with ']' not '/' */
-            if (slash && (**pattern == '/'))
-                break;
-
-            /* Match character classes. */
-            if (classmatch(*pattern, **string, nocase, pattern)
-                == RANGE_MATCH) {
-                result = 0;
-                continue;
-            }
-
-leadingclosebrace:
-            /* Look at only well-formed range patterns; 
-             * "x-]" is not allowed unless escaped ("x-\]")
-             * XXX: Fix for locale/MBCS character width
-             */
-            if (((*pattern)[1] == '-') && ((*pattern)[2] != ']'))
-            {
-                startch = *pattern;
-                *pattern += (escape && ((*pattern)[2] == '\\')) ? 3 : 2;
-
-                /* NOT a properly balanced [expr] pattern, EOS terminated 
-                 * or ranges containing a slash in FNM_PATHNAME mode pattern
-                 * fall out to to the rewind and test '[' literal code path
-                 */
-                if (!**pattern || (slash && (**pattern == '/')))
-                    break;
-
-                /* XXX: handle locale/MBCS comparison, advance by MBCS char width */
-                if ((**string >= *startch) && (**string <= **pattern))
-                    result = 0;
-                else if (nocase && (isupper(**string) || isupper(*startch)
-                                                      || isupper(**pattern))
-                            && (tolower(**string) >= tolower(*startch)) 
-                            && (tolower(**string) <= tolower(**pattern)))
-                    result = 0;
-
-                ++*pattern;
-                continue;
-            }
-
-            /* XXX: handle locale/MBCS comparison, advance by MBCS char width */
-            if ((**string == **pattern))
-                result = 0;
-            else if (nocase && (isupper(**string) || isupper(**pattern))
-                            && (tolower(**string) == tolower(**pattern)))
-                result = 0;
-
-            ++*pattern;
-        }
-
-        /* NOT a properly balanced [expr] pattern; Rewind
-         * and reset result to test '[' literal
-         */
-        *pattern = mismatch;
-        result = FNM_NOMATCH;
-    }
-    else if (**pattern == '?') {
-        /* Optimize '?' match before unescaping **pattern */
-        if (!**string || (slash && (**string == '/')))
-            return FNM_NOMATCH;
-        result = 0;
-        goto fnmatch_ch_success;
-    }
-    else if (escape && (**pattern == '\\') && (*pattern)[1]) {
-        ++*pattern;
-    }
-
-    /* XXX: handle locale/MBCS comparison, advance by the MBCS char width */
-    if (**string == **pattern)
-        result = 0;
-    else if (nocase && (isupper(**string) || isupper(**pattern))
-                    && (tolower(**string) == tolower(**pattern)))
-        result = 0;
-
-    /* Refuse to advance over trailing slash or nulls
-     */
-    if (!**string || !**pattern || (slash && ((**string == '/') || (**pattern == '/'))))
-        return result;
-
-fnmatch_ch_success:
-    ++*pattern;
-    ++*string;
-    return result;
-}
-
-
-int fnmatch(const char *pattern, const char *string, int flags)
-{
-    static const char dummystring[2] = {' ', 0};
-    const int escape = !(flags & FNM_NOESCAPE);
-    const int slash = !!(flags & FNM_PATHNAME);
-    const int leading_dir = !!(flags & FNM_LEADING_DIR);
-    const char *strendseg;
-    const char *dummyptr;
-    const char *matchptr;
-    int wild;
-    /* For '*' wild processing only; surpress 'used before initialization'
-     * warnings with dummy initialization values;
-     */
-    const char *strstartseg = NULL;
-    const char *mismatch = NULL;
-    int matchlen = 0;
-
-    if (strnlen(pattern, PATH_MAX) == PATH_MAX ||
-        strnlen(string, PATH_MAX) == PATH_MAX)
-            return (FNM_NOMATCH);
-
-    if (*pattern == '*')
-        goto firstsegment;
-
-    while (*pattern && *string)
-    {
-        /* Pre-decode "\/" which has no special significance, and
-         * match balanced slashes, starting a new segment pattern
-         */
-        if (slash && escape && (*pattern == '\\') && (pattern[1] == '/'))
-            ++pattern;
-        if (slash && (*pattern == '/') && (*string == '/')) {
-            ++pattern;
-            ++string;
-        }            
-
-firstsegment:
-        /* At the beginning of each segment, validate leading period behavior.
-         */
-        if ((flags & FNM_PERIOD) && (*string == '.'))
-        {
-            if (*pattern == '.')
-                ++pattern;
-            else if (escape && (*pattern == '\\') && (pattern[1] == '.'))
-                pattern += 2;
-            else
-                return FNM_NOMATCH;
-            ++string;
-        }
-
-        /* Determine the end of string segment
-         *
-         * Presumes '/' character is unique, not composite in any MBCS encoding
-         */
-        if (slash) {
-            strendseg = strchr(string, '/');
-            if (!strendseg)
-                strendseg = strchr(string, '\0');
-        }
-        else {
-            strendseg = strchr(string, '\0');
-        }
-
-        /* Allow pattern '*' to be consumed even with no remaining string to match
-         */
-        while (*pattern)
-        {
-            if ((string > strendseg)
-                || ((string == strendseg) && (*pattern != '*')))
-                break;
-
-            if (slash && ((*pattern == '/')
-                           || (escape && (*pattern == '\\')
-                                      && (pattern[1] == '/'))))
-                break;
-
-            /* Reduce groups of '*' and '?' to n '?' matches
-             * followed by one '*' test for simplicity
-             */
-            for (wild = 0; ((*pattern == '*') || (*pattern == '?')); ++pattern)
-            {
-                if (*pattern == '*') {
-                    wild = 1;
-                }
-                else if (string < strendseg) {  /* && (*pattern == '?') */
-                    /* XXX: Advance 1 char for MBCS locale */
-                    ++string;
-                }
-                else {  /* (string >= strendseg) && (*pattern == '?') */
-                    return FNM_NOMATCH;
-                }
-            }
-
-            if (wild)
-            {
-                strstartseg = string;
-                mismatch = pattern;
-
-                /* Count fixed (non '*') char matches remaining in pattern
-                 * excluding '/' (or "\/") and '*'
-                 */
-                for (matchptr = pattern, matchlen = 0; 1; ++matchlen)
-                {
-                    if ((*matchptr == '\0') 
-                        || (slash && ((*matchptr == '/')
-                                      || (escape && (*matchptr == '\\')
-                                                 && (matchptr[1] == '/')))))
-                    {
-                        /* Compare precisely this many trailing string chars,
-                         * the resulting match needs no wildcard loop
-                         */
-                        /* XXX: Adjust for MBCS */
-                        if (string + matchlen > strendseg)
-                            return FNM_NOMATCH;
-
-                        string = strendseg - matchlen;
-                        wild = 0;
-                        break;
-                    }
-
-                    if (*matchptr == '*')
-                    {
-                        /* Ensure at least this many trailing string chars remain
-                         * for the first comparison
-                         */
-                        /* XXX: Adjust for MBCS */
-                        if (string + matchlen > strendseg)
-                            return FNM_NOMATCH;
-
-                        /* Begin first wild comparison at the current position */
-                        break;
-                    }
-
-                    /* Skip forward in pattern by a single character match
-                     * Use a dummy fnmatch_ch() test to count one "[range]" escape
-                     */ 
-                    /* XXX: Adjust for MBCS */
-                    if (escape && (*matchptr == '\\') && matchptr[1]) {
-                        matchptr += 2;
-                    }
-                    else if (*matchptr == '[') {
-                        dummyptr = dummystring;
-                        fnmatch_ch(&matchptr, &dummyptr, flags);
-                    }
-                    else {
-                        ++matchptr;
-                    }
-                }
-            }
-
-            /* Incrementally match string against the pattern
-             */
-            while (*pattern && (string < strendseg))
-            {
-                /* Success; begin a new wild pattern search
-                 */
-                if (*pattern == '*')
-                    break;
-
-                if (slash && ((*string == '/')
-                              || (*pattern == '/')
-                              || (escape && (*pattern == '\\')
-                                         && (pattern[1] == '/'))))
-                    break;
-
-                /* Compare ch's (the pattern is advanced over "\/" to the '/',
-                 * but slashes will mismatch, and are not consumed)
-                 */
-                if (!fnmatch_ch(&pattern, &string, flags))
-                    continue;
-
-                /* Failed to match, loop against next char offset of string segment 
-                 * until not enough string chars remain to match the fixed pattern
-                 */
-                if (wild) {
-                    /* XXX: Advance 1 char for MBCS locale */
-                    string = ++strstartseg;
-                    if (string + matchlen > strendseg)
-                        return FNM_NOMATCH;
-
-                    pattern = mismatch;
-                    continue;
-                }
-                else
-                    return FNM_NOMATCH;
-            }
-        }
-
-        if (*string && !((slash || leading_dir) && (*string == '/')))
-            return FNM_NOMATCH;
-
-        if (*pattern && !(slash && ((*pattern == '/')
-                                    || (escape && (*pattern == '\\')
-                                               && (pattern[1] == '/')))))
-            return FNM_NOMATCH;
-
-        if (leading_dir && !*pattern && *string == '/')
-            return 0;
-    }
-
-    /* Where both pattern and string are at EOS, declare success
-     */
-    if (!*string && !*pattern)
-        return 0;
-
-    /* pattern didn't match to the end of string */
-    return FNM_NOMATCH;
-}
diff --git a/libc/unistd/syslog.c b/libc/unistd/syslog.c
deleted file mode 100644
index 7878475..0000000
--- a/libc/unistd/syslog.c
+++ /dev/null
@@ -1,368 +0,0 @@
-/*	$OpenBSD: syslog.c,v 1.28 2005/08/08 08:05:34 espie Exp $ */
-/*
- * Copyright (c) 1983, 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-#include <syslog.h>
-#include <sys/un.h>
-#include <netdb.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <stdarg.h>
-
-static struct syslog_data sdata = SYSLOG_DATA_INIT;
-
-extern const char	*__progname;		/* Program name, from crt0. */
-
-static void	disconnectlog_r(struct syslog_data *);	/* disconnect from syslogd */
-static void	connectlog_r(struct syslog_data *);	/* (re)connect to syslogd */
-
-/*
- * syslog, vsyslog --
- *	print message on log file; output is intended for syslogd(8).
- */
-void
-syslog(int pri, const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	vsyslog(pri, fmt, ap);
-	va_end(ap);
-}
-
-void
-vsyslog(int pri, const char *fmt, va_list ap)
-{
-	vsyslog_r(pri, &sdata, fmt, ap);
-}
-
-void
-openlog(const char *ident, int logstat, int logfac)
-{
-	openlog_r(ident, logstat, logfac, &sdata);
-}
-
-void
-closelog(void)
-{
-	closelog_r(&sdata);
-}
-
-/* setlogmask -- set the log mask level */
-int
-setlogmask(int pmask)
-{
-	return setlogmask_r(pmask, &sdata);
-}
-
-/* Reentrant version of syslog, i.e. syslog_r() */
-
-void
-syslog_r(int pri, struct syslog_data *data, const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	vsyslog_r(pri, data, fmt, ap);
-	va_end(ap);
-}
-
-void
-vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap)
-{
-	int cnt;
-	char ch, *p, *t;
-	time_t now;
-	int fd, saved_errno, error;
-#define	TBUF_LEN	2048
-#define	FMT_LEN		1024
-	char *stdp = NULL, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN];
-	int tbuf_left, fmt_left, prlen;
-
-#define	INTERNALLOG	LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
-	/* Check for invalid bits. */
-	if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
-		if (data == &sdata) {
-			syslog(INTERNALLOG,
-			    "syslog: unknown facility/priority: %x", pri);
-		} else {
-			syslog_r(INTERNALLOG, data,
-			    "syslog_r: unknown facility/priority: %x", pri);
-		}
-		pri &= LOG_PRIMASK|LOG_FACMASK;
-	}
-
-	/* Check priority against setlogmask values. */
-	if (!(LOG_MASK(LOG_PRI(pri)) & data->log_mask))
-		return;
-
-	saved_errno = errno;
-
-	/* Set default facility if none specified. */
-	if ((pri & LOG_FACMASK) == 0)
-		pri |= data->log_fac;
-
-	/* If we have been called through syslog(), no need for reentrancy. */
-	if (data == &sdata)
-		(void)time(&now);
-
-	p = tbuf;
-	tbuf_left = TBUF_LEN;
-
-#define	DEC()	\
-	do {					\
-		if (prlen < 0)			\
-			prlen = 0;		\
-		if (prlen >= tbuf_left)		\
-			prlen = tbuf_left - 1;	\
-		p += prlen;			\
-		tbuf_left -= prlen;		\
-	} while (0)
-
-	prlen = snprintf(p, tbuf_left, "<%d>", pri);
-	DEC();
-
-	/* 
-	 * syslogd will expand time automagically for reentrant case, and
-	 * for normal case, just do like before
-	 */
-	if (data == &sdata) {
-		prlen = strftime(p, tbuf_left, "%h %e %T ", localtime(&now));
-		DEC();
-	}
-
-	if (data->log_stat & LOG_PERROR)
-		stdp = p;
-	if (data->log_tag == NULL)
-		data->log_tag = __progname;
-	if (data->log_tag != NULL) {
-		prlen = snprintf(p, tbuf_left, "%s", data->log_tag);
-		DEC();
-	}
-	if (data->log_stat & LOG_PID) {
-		prlen = snprintf(p, tbuf_left, "[%ld]", (long)getpid());
-		DEC();
-	}
-	if (data->log_tag != NULL) {
-		if (tbuf_left > 1) {
-			*p++ = ':';
-			tbuf_left--;
-		}
-		if (tbuf_left > 1) {
-			*p++ = ' ';
-			tbuf_left--;
-		}
-	}
-
-	/* strerror() is not reentrant */
-
-	for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
-		if (ch == '%' && fmt[1] == 'm') {
-			++fmt;
-			if (data == &sdata) {
-				prlen = snprintf(t, fmt_left, "%s",
-				    strerror(saved_errno)); 
-			} else {
-				prlen = snprintf(t, fmt_left, "Error %d",
-				    saved_errno); 
-			}
-			if (prlen < 0)
-				prlen = 0;
-			if (prlen >= fmt_left)
-				prlen = fmt_left - 1;
-			t += prlen;
-			fmt_left -= prlen;
-		} else if (ch == '%' && fmt[1] == '%' && fmt_left > 2) {
-			*t++ = '%';
-			*t++ = '%';
-			fmt++;
-			fmt_left -= 2;
-		} else {
-			if (fmt_left > 1) {
-				*t++ = ch;
-				fmt_left--;
-			}
-		}
-	}
-	*t = '\0';
-
-	prlen = vsnprintf(p, tbuf_left, fmt_cpy, ap);
-	DEC();
-	cnt = p - tbuf;
-
-	/* Output to stderr if requested. */
-	if (data->log_stat & LOG_PERROR) {
-		struct iovec iov[2];
-
-		iov[0].iov_base = stdp;
-		iov[0].iov_len = cnt - (stdp - tbuf);
-		iov[1].iov_base = "\n";
-		iov[1].iov_len = 1;
-		(void)writev(STDERR_FILENO, iov, 2);
-	}
-
-	/* Get connected, output the message to the local logger. */
-	if (!data->opened)
-		openlog_r(data->log_tag, data->log_stat, 0, data);
-	connectlog_r(data);
-
-	/*
-	 * If the send() failed, there are two likely scenarios:
-	 *  1) syslogd was restarted
-	 *  2) /dev/log is out of socket buffer space
-	 * We attempt to reconnect to /dev/log to take care of
-	 * case #1 and keep send()ing data to cover case #2
-	 * to give syslogd a chance to empty its socket buffer.
-	 */
-	if ((error = send(data->log_file, tbuf, cnt, 0)) < 0) {
-		if (errno != ENOBUFS) {
-			disconnectlog_r(data);
-			connectlog_r(data);
-		}
-		do {
-			usleep(1);
-			if ((error = send(data->log_file, tbuf, cnt, 0)) >= 0)
-				break;
-		} while (errno == ENOBUFS);
-	}
-
-	/*
-	 * Output the message to the console; try not to block
-	 * as a blocking console should not stop other processes.
-	 * Make sure the error reported is the one from the syslogd failure.
-	 */
-	if (error == -1 && (data->log_stat & LOG_CONS) &&
-	    (fd = open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) {
-		struct iovec iov[2];
-		
-		p = strchr(tbuf, '>') + 1;
-		iov[0].iov_base = p;
-		iov[0].iov_len = cnt - (p - tbuf);
-		iov[1].iov_base = "\r\n";
-		iov[1].iov_len = 2;
-		(void)writev(fd, iov, 2);
-		(void)close(fd);
-	}
-
-	if (data != &sdata)
-		closelog_r(data);
-}
-
-static void
-disconnectlog_r(struct syslog_data *data)
-{
-	/*
-	 * If the user closed the FD and opened another in the same slot,
-	 * that's their problem.  They should close it before calling on
-	 * system services.
-	 */
-	if (data->log_file != -1) {
-		close(data->log_file);
-		data->log_file = -1;
-	}
-	data->connected = 0;		/* retry connect */
-}
-
-static void
-connectlog_r(struct syslog_data *data)
-{
-    union {
-        struct sockaddr     syslogAddr;
-        struct sockaddr_un  syslogAddrUn;
-    } u;
-
-#define SyslogAddr   u.syslogAddrUn
-
-	if (data->log_file == -1) {
-		if ((data->log_file = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
-			return;
-		(void)fcntl(data->log_file, F_SETFD, 1);
-	}
-	if (data->log_file != -1 && !data->connected) {
-		memset(&SyslogAddr, '\0', sizeof(SyslogAddr));
-#if 0
-                /* BIONIC: no sun_len field to fill on Linux */
-		SyslogAddr.sun_len = sizeof(SyslogAddr);
-#endif
-		SyslogAddr.sun_family = AF_UNIX;
-		strlcpy(SyslogAddr.sun_path, _PATH_LOG,
-		    sizeof(SyslogAddr.sun_path));
-		if (connect(data->log_file, &u.syslogAddr,
-		    sizeof(SyslogAddr)) == -1) {
-			(void)close(data->log_file);
-			data->log_file = -1;
-		} else
-			data->connected = 1;
-	}
-}
-
-void
-openlog_r(const char *ident, int logstat, int logfac, struct syslog_data *data)
-{
-	if (ident != NULL)
-		data->log_tag = ident;
-	data->log_stat = logstat;
-	if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
-		data->log_fac = logfac;
-
-	if (data->log_stat & LOG_NDELAY)	/* open immediately */
-		connectlog_r(data);
-
-	data->opened = 1;	/* ident and facility has been set */
-}
-
-void
-closelog_r(struct syslog_data *data)
-{
-	(void)close(data->log_file);
-	data->log_file = -1;
-	data->connected = 0;
-	data->log_tag = NULL;
-}
-
-/* setlogmask -- set the log mask level */
-int
-setlogmask_r(int pmask, struct syslog_data *data)
-{
-	int omask;
-
-	omask = data->log_mask;
-	if (pmask != 0)
-		data->log_mask = pmask;
-	return (omask);
-}
diff --git a/libc/unistd/system.c b/libc/unistd/system.c
deleted file mode 100644
index 72cc37e..0000000
--- a/libc/unistd/system.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*	$OpenBSD: system.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <paths.h>
-#include <sys/wait.h>
-
-extern char **environ;
-
-int
-system(const char *command)
-{
-  pid_t pid;
-	sig_t intsave, quitsave;
-	sigset_t mask, omask;
-	int pstat;
-	char *argp[] = {"sh", "-c", NULL, NULL};
-
-	if (!command)		/* just checking... */
-		return(1);
-
-	argp[2] = (char *)command;
-
-	sigemptyset(&mask);
-	sigaddset(&mask, SIGCHLD);
-	sigprocmask(SIG_BLOCK, &mask, &omask);
-	switch (pid = vfork()) {
-	case -1:			/* error */
-		sigprocmask(SIG_SETMASK, &omask, NULL);
-		return(-1);
-	case 0:				/* child */
-		sigprocmask(SIG_SETMASK, &omask, NULL);
-		execve(_PATH_BSHELL, argp, environ);
-    _exit(127);
-  }
-
-	intsave = (sig_t)  bsd_signal(SIGINT, SIG_IGN);
-	quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN);
-	pid = waitpid(pid, (int *)&pstat, 0);
-	sigprocmask(SIG_SETMASK, &omask, NULL);
-	(void)bsd_signal(SIGINT, intsave);
-	(void)bsd_signal(SIGQUIT, quitsave);
-	return (pid == -1 ? -1 : pstat);
-}
diff --git a/libc/unistd/time.c b/libc/unistd/time.c
deleted file mode 100644
index 18aa62c..0000000
--- a/libc/unistd/time.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*	$OpenBSD: time.c,v 1.5 2005/08/08 08:05:34 espie Exp $ */
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <time.h>
-
-time_t
-time(time_t *t)
-{
-	struct timeval tt;
-	time_t ret;
-
-	if (gettimeofday(&tt, (struct timezone *)0) < 0)
-		ret = -1;
-	else
-		ret = tt.tv_sec;
-	if (t != NULL)
-		*t = ret;
-	return ret;
-}
-
-// return monotonically increasing CPU time in ticks relative to unspecified epoch
-static inline clock_t clock_now(void)
-{
-	struct timespec tm;
-	clock_gettime( CLOCK_MONOTONIC, &tm);
-	return tm.tv_sec * CLOCKS_PER_SEC + (tm.tv_nsec * (CLOCKS_PER_SEC/1e9));
-}
-
-// initialized by the constructor below
-static clock_t clock_start;
-
-// called by dlopen when .so is loaded
-__attribute__((constructor)) static void clock_crt0(void)
-{
-	clock_start = clock_now();
-}
-
-// return elapsed CPU time in clock ticks, since start of program execution
-// (spec says epoch is undefined, but glibc uses crt0 as epoch)
-clock_t
-clock(void)
-{
-	// note that if we are executing in a different thread than crt0, then the
-	// pthread_create that made us had a memory barrier so clock_start is defined
-	return clock_now() - clock_start;
-}
diff --git a/libc/upstream-dlmalloc/malloc.c b/libc/upstream-dlmalloc/malloc.c
index 3ef9b61..4362f49 100644
--- a/libc/upstream-dlmalloc/malloc.c
+++ b/libc/upstream-dlmalloc/malloc.c
@@ -5317,12 +5317,19 @@
   return dlmemalign(pagesz, bytes);
 }
 
+/* BEGIN android-changed: added overflow check */
 void* dlpvalloc(size_t bytes) {
   size_t pagesz;
+  size_t size;
   ensure_initialization();
   pagesz = mparams.page_size;
-  return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
+  size = (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE);
+  if (size < bytes) {
+    return NULL;
+  }
+  return dlmemalign(pagesz, size);
 }
+/* END android-change */
 
 void** dlindependent_calloc(size_t n_elements, size_t elem_size,
                             void* chunks[]) {
diff --git a/libc/upstream-freebsd/android/include/freebsd-compat.h b/libc/upstream-freebsd/android/include/freebsd-compat.h
new file mode 100644
index 0000000..d5f1425
--- /dev/null
+++ b/libc/upstream-freebsd/android/include/freebsd-compat.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_FREEBSD_COMPAT_H_included
+#define _BIONIC_FREEBSD_COMPAT_H_included
+
+#define __USE_BSD
+#define REPLACE_GETOPT
+
+/*
+ * FreeBSD's libc has three symbols for every symbol:
+ *
+ *     __f will be the actual implementation.
+ *     _f will be a weak reference to __f (used for calls to f from within the library).
+ *     f will be a weak reference to __f (used for calls to f from outside the library).
+ *
+ * We collapse this into just the one symbol, f.
+ */
+
+/* Prevent weak reference generation. */
+#define __weak_reference(sym,alias)
+
+/* Ensure that the implementation itself gets the underscore-free name. */
+#define __sleep sleep
+#define __usleep usleep
+
+/* Redirect internal C library calls to the public function. */
+#define _close close
+#define _fcntl fcntl
+#define _fstat fstat
+#define _nanosleep nanosleep
+#define _open open
+
+/* This one is only needed as long as we have a mix of OpenBSD and FreeBSD stdio. */
+#define _sseek __sseek
+
+/* This is in BSD's <stdlib.h>. */
+#include <stdint.h>
+extern uint32_t arc4random_uniform(uint32_t upper_bound);
+
+#endif
diff --git a/libc/upstream-freebsd/android/include/libc_private.h b/libc/upstream-freebsd/android/include/libc_private.h
new file mode 100644
index 0000000..c6a6433
--- /dev/null
+++ b/libc/upstream-freebsd/android/include/libc_private.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_FREEBSD_LIBC_PRIVATE_H_included
+#define _BIONIC_FREEBSD_LIBC_PRIVATE_H_included
+
+#define STDIO_THREAD_LOCK()   /* TODO: until we have the FreeBSD findfp.c, this is useless. */
+#define STDIO_THREAD_UNLOCK() /* TODO: until we have the FreeBSD findfp.c, this is useless. */
+
+#define ORIENT(fp, o) /* Only needed for wide-character stream support. */
+
+#endif
diff --git a/libc/upstream-freebsd/un-namespace.h b/libc/upstream-freebsd/android/include/namespace.h
similarity index 100%
copy from libc/upstream-freebsd/un-namespace.h
copy to libc/upstream-freebsd/android/include/namespace.h
diff --git a/libc/upstream-freebsd/spinlock.h b/libc/upstream-freebsd/android/include/spinlock.h
similarity index 100%
rename from libc/upstream-freebsd/spinlock.h
rename to libc/upstream-freebsd/android/include/spinlock.h
diff --git a/libc/upstream-freebsd/un-namespace.h b/libc/upstream-freebsd/android/include/un-namespace.h
similarity index 100%
rename from libc/upstream-freebsd/un-namespace.h
rename to libc/upstream-freebsd/android/include/un-namespace.h
diff --git a/libc/upstream-freebsd/freebsd-compat.h b/libc/upstream-freebsd/freebsd-compat.h
deleted file mode 100644
index 74dc679..0000000
--- a/libc/upstream-freebsd/freebsd-compat.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _BIONIC_FREEBSD_COMPAT_H_included
-#define _BIONIC_FREEBSD_COMPAT_H_included
-
-#define __USE_BSD
-#define REPLACE_GETOPT
-
-/*
- * FreeBSD's libc has three symbols for every symbol:
- *
- *     __f will be the actual implementation.
- *     _f will be a weak reference to __f (used for calls to f from within the library).
- *     f will be a weak reference to __f (used for calls to f from outside the library).
- *
- * We collapse this into just the one symbol, f.
- */
-
-/* Prevent weak reference generation. */
-#define __weak_reference(sym,alias)
-
-/* Ensure that the implementation itself gets the underscore-free name. */
-#define __sleep sleep
-#define __usleep usleep
-
-/* Redirect internal C library calls to the public function. */
-#define _close close
-#define _fcntl fcntl
-#define _fstat fstat
-#define _nanosleep nanosleep
-#define _open open
-
-/* This one is only needed as long as we have a mix of OpenBSD and FreeBSD stdio. */
-#define _sseek __sseek
-
-#endif
diff --git a/libc/upstream-freebsd/lib/libc/gen/ldexp.c b/libc/upstream-freebsd/lib/libc/gen/ldexp.c
new file mode 100644
index 0000000..887f673
--- /dev/null
+++ b/libc/upstream-freebsd/lib/libc/gen/ldexp.c
@@ -0,0 +1,123 @@
+/* @(#)s_scalbn.c 5.1 93/09/24 */
+/* @(#)fdlibm.h 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <machine/endian.h>
+#include <math.h>
+
+/* Bit fiddling routines copied from msun/src/math_private.h,v 1.15 */
+
+#if BYTE_ORDER == BIG_ENDIAN
+
+typedef union
+{
+  double value;
+  struct
+  {
+    u_int32_t msw;
+    u_int32_t lsw;
+  } parts;
+} ieee_double_shape_type;
+
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+
+typedef union
+{
+  double value;
+  struct
+  {
+    u_int32_t lsw;
+    u_int32_t msw;
+  } parts;
+} ieee_double_shape_type;
+
+#endif
+
+/* Get two 32 bit ints from a double.  */
+
+#define EXTRACT_WORDS(ix0,ix1,d)				\
+do {								\
+  ieee_double_shape_type ew_u;					\
+  ew_u.value = (d);						\
+  (ix0) = ew_u.parts.msw;					\
+  (ix1) = ew_u.parts.lsw;					\
+} while (0)
+
+/* Get the more significant 32 bit int from a double.  */
+
+#define GET_HIGH_WORD(i,d)					\
+do {								\
+  ieee_double_shape_type gh_u;					\
+  gh_u.value = (d);						\
+  (i) = gh_u.parts.msw;						\
+} while (0)
+
+/* Set the more significant 32 bits of a double from an int.  */
+
+#define SET_HIGH_WORD(d,v)					\
+do {								\
+  ieee_double_shape_type sh_u;					\
+  sh_u.value = (d);						\
+  sh_u.parts.msw = (v);						\
+  (d) = sh_u.value;						\
+} while (0)
+
+
+static const double
+two54   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+twom54  =  5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
+huge   = 1.0e+300,
+tiny   = 1.0e-300;
+
+static double
+_copysign(double x, double y)
+{
+	u_int32_t hx,hy;
+	GET_HIGH_WORD(hx,x);
+	GET_HIGH_WORD(hy,y);
+	SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
+	return x;
+}
+
+double
+ldexp(double x, int n)
+{
+	int32_t k,hx,lx;
+	EXTRACT_WORDS(hx,lx,x);
+        k = (hx&0x7ff00000)>>20;		/* extract exponent */
+        if (k==0) {				/* 0 or subnormal x */
+            if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
+	    x *= two54;
+	    GET_HIGH_WORD(hx,x);
+	    k = ((hx&0x7ff00000)>>20) - 54;
+            if (n< -50000) return tiny*x; 	/*underflow*/
+	    }
+        if (k==0x7ff) return x+x;		/* NaN or Inf */
+        k = k+n;
+        if (k >  0x7fe) return huge*_copysign(huge,x); /* overflow  */
+        if (k > 0) 				/* normal result */
+	    {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
+        if (k <= -54) {
+            if (n > 50000) 	/* in case integer overflow in n+k */
+		return huge*_copysign(huge,x);	/*overflow*/
+	    else return tiny*_copysign(tiny,x); 	/*underflow*/
+	}
+        k += 54;				/* subnormal result */
+	SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
+        return x*twom54;
+}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/clrerr.c b/libc/upstream-freebsd/lib/libc/stdio/clrerr.c
deleted file mode 100644
index f161a6e..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/clrerr.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)clrerr.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef clearerr
-#undef clearerr_unlocked
-
-void
-clearerr(FILE *fp)
-{
-	FLOCKFILE(fp);
-	__sclearerr(fp);
-	FUNLOCKFILE(fp);
-}
-
-void
-clearerr_unlocked(FILE *fp)
-{
-
-	__sclearerr(fp);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fdopen.c b/libc/upstream-freebsd/lib/libc/stdio/fdopen.c
deleted file mode 100644
index 2e19b9f..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fdopen.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fdopen.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <limits.h>
-#include "un-namespace.h"
-#include "local.h"
-
-FILE *
-fdopen(int fd, const char *mode)
-{
-	FILE *fp;
-	int flags, oflags, fdflags, tmp;
-
-	/*
-	 * File descriptors are a full int, but _file is only a short.
-	 * If we get a valid file descriptor that is greater than
-	 * SHRT_MAX, then the fd will get sign-extended into an
-	 * invalid file descriptor.  Handle this case by failing the
-	 * open.
-	 */
-	if (fd > SHRT_MAX) {
-		errno = EMFILE;
-		return (NULL);
-	}
-
-	if ((flags = __sflags(mode, &oflags)) == 0)
-		return (NULL);
-
-	/* Make sure the mode the user wants is a subset of the actual mode. */
-	if ((fdflags = _fcntl(fd, F_GETFL, 0)) < 0)
-		return (NULL);
-	tmp = fdflags & O_ACCMODE;
-	if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) {
-		errno = EINVAL;
-		return (NULL);
-	}
-
-	if ((fp = __sfp()) == NULL)
-		return (NULL);
-
-	if ((oflags & O_CLOEXEC) && _fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
-		fp->_flags = 0;
-		return (NULL);
-	}
-
-	fp->_flags = flags;
-	/*
-	 * If opened for appending, but underlying descriptor does not have
-	 * O_APPEND bit set, assert __SAPP so that __swrite() caller
-	 * will _sseek() to the end before write.
-	 */
-	if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
-		fp->_flags |= __SAPP;
-	fp->_file = fd;
-	fp->_cookie = fp;
-	fp->_read = __sread;
-	fp->_write = __swrite;
-	fp->_seek = __sseek;
-	fp->_close = __sclose;
-	return (fp);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/feof.c b/libc/upstream-freebsd/lib/libc/stdio/feof.c
deleted file mode 100644
index b970248..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/feof.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)feof.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef feof
-#undef feof_unlocked
-
-int
-feof(FILE *fp)
-{
-	int	ret;
-
-	FLOCKFILE(fp);
-	ret= __sfeof(fp);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
-
-int
-feof_unlocked(FILE *fp)
-{
-
-	return (__sfeof(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/ferror.c b/libc/upstream-freebsd/lib/libc/stdio/ferror.c
deleted file mode 100644
index 7e0f8f9..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/ferror.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ferror.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef ferror
-#undef ferror_unlocked
-
-int
-ferror(FILE *fp)
-{
-	int	ret;
-
-	FLOCKFILE(fp);
-	ret = __sferror(fp);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
-
-int
-ferror_unlocked(FILE *fp)
-{
-
-	return (__sferror(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgetln.c b/libc/upstream-freebsd/lib/libc/stdio/fgetln.c
deleted file mode 100644
index 1779de2..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fgetln.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetln.c	8.2 (Berkeley) 1/2/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-#include "local.h"
-
-/*
- * Expand the line buffer.  Return -1 on error.
-#ifdef notdef
- * The `new size' does not account for a terminating '\0',
- * so we add 1 here.
-#endif
- */
-int
-__slbexpand(FILE *fp, size_t newsize)
-{
-	void *p;
-
-#ifdef notdef
-	++newsize;
-#endif
-	if (fp->_lb._size >= newsize)
-		return (0);
-	if ((p = realloc(fp->_lb._base, newsize)) == NULL)
-		return (-1);
-	fp->_lb._base = p;
-	fp->_lb._size = newsize;
-	return (0);
-}
-
-/*
- * Get an input line.  The returned pointer often (but not always)
- * points into a stdio buffer.  Fgetln does not alter the text of
- * the returned line (which is thus not a C string because it will
- * not necessarily end with '\0'), but does allow callers to modify
- * it if they wish.  Thus, we set __SMOD in case the caller does.
- */
-char *
-fgetln(FILE *fp, size_t *lenp)
-{
-	unsigned char *p;
-	size_t len;
-	size_t off;
-
-	FLOCKFILE(fp);
-	ORIENT(fp, -1);
-	/* make sure there is input */
-	if (fp->_r <= 0 && __srefill(fp)) {
-		*lenp = 0;
-		FUNLOCKFILE(fp);
-		return (NULL);
-	}
-
-	/* look for a newline in the input */
-	if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) {
-		char *ret;
-
-		/*
-		 * Found one.  Flag buffer as modified to keep fseek from
-		 * `optimising' a backward seek, in case the user stomps on
-		 * the text.
-		 */
-		p++;		/* advance over it */
-		ret = (char *)fp->_p;
-		*lenp = len = p - fp->_p;
-		fp->_flags |= __SMOD;
-		fp->_r -= len;
-		fp->_p = p;
-		FUNLOCKFILE(fp);
-		return (ret);
-	}
-
-	/*
-	 * We have to copy the current buffered data to the line buffer.
-	 * As a bonus, though, we can leave off the __SMOD.
-	 *
-	 * OPTIMISTIC is length that we (optimistically) expect will
-	 * accommodate the `rest' of the string, on each trip through the
-	 * loop below.
-	 */
-#define OPTIMISTIC 80
-
-	for (len = fp->_r, off = 0;; len += fp->_r) {
-		size_t diff;
-
-		/*
-		 * Make sure there is room for more bytes.  Copy data from
-		 * file buffer to line buffer, refill file and look for
-		 * newline.  The loop stops only when we find a newline.
-		 */
-		if (__slbexpand(fp, len + OPTIMISTIC))
-			goto error;
-		(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
-		    len - off);
-		off = len;
-		if (__srefill(fp))
-			break;	/* EOF or error: return partial line */
-		if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL)
-			continue;
-
-		/* got it: finish up the line (like code above) */
-		p++;
-		diff = p - fp->_p;
-		len += diff;
-		if (__slbexpand(fp, len))
-			goto error;
-		(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
-		    diff);
-		fp->_r -= diff;
-		fp->_p = p;
-		break;
-	}
-	*lenp = len;
-#ifdef notdef
-	fp->_lb._base[len] = 0;
-#endif
-	FUNLOCKFILE(fp);
-	return ((char *)fp->_lb._base);
-
-error:
-	*lenp = 0;		/* ??? */
-	FUNLOCKFILE(fp);
-	return (NULL);		/* ??? */
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c b/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c
deleted file mode 100644
index f161f43..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetpos.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-
-int
-fgetpos(FILE * __restrict fp, fpos_t * __restrict pos)
-{
-	/*
-	 * ftello is thread-safe; no need to lock fp.
-	 */
-	if ((*pos = ftello(fp)) == (fpos_t)-1)
-		return (-1);
-	else
-		return (0);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgets.c b/libc/upstream-freebsd/lib/libc/stdio/fgets.c
deleted file mode 100644
index 9abf559..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fgets.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgets.c	8.2 (Berkeley) 12/22/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include <string.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-/*
- * Read at most n-1 characters from the given file.
- * Stop when a newline has been read, or the count runs out.
- * Return first argument, or NULL if no characters were read.
- */
-char *
-fgets(char * __restrict buf, int n, FILE * __restrict fp)
-{
-	size_t len;
-	char *s;
-	unsigned char *p, *t;
-
-	if (n <= 0)		/* sanity check */
-		return (NULL);
-
-	FLOCKFILE(fp);
-	ORIENT(fp, -1);
-	s = buf;
-	n--;			/* leave space for NUL */
-	while (n != 0) {
-		/*
-		 * If the buffer is empty, refill it.
-		 */
-		if ((len = fp->_r) <= 0) {
-			if (__srefill(fp)) {
-				/* EOF/error: stop with partial or no line */
-				if (s == buf) {
-					FUNLOCKFILE(fp);
-					return (NULL);
-				}
-				break;
-			}
-			len = fp->_r;
-		}
-		p = fp->_p;
-
-		/*
-		 * Scan through at most n bytes of the current buffer,
-		 * looking for '\n'.  If found, copy up to and including
-		 * newline, and stop.  Otherwise, copy entire chunk
-		 * and loop.
-		 */
-		if (len > n)
-			len = n;
-		t = memchr((void *)p, '\n', len);
-		if (t != NULL) {
-			len = ++t - p;
-			fp->_r -= len;
-			fp->_p = t;
-			(void)memcpy((void *)s, (void *)p, len);
-			s[len] = 0;
-			FUNLOCKFILE(fp);
-			return (buf);
-		}
-		fp->_r -= len;
-		fp->_p += len;
-		(void)memcpy((void *)s, (void *)p, len);
-		s += len;
-		n -= len;
-	}
-	*s = 0;
-	FUNLOCKFILE(fp);
-	return (buf);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fileno.c b/libc/upstream-freebsd/lib/libc/stdio/fileno.c
deleted file mode 100644
index 3ac1830..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fileno.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fileno.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef fileno
-#undef fileno_unlocked
-
-int
-fileno(FILE *fp)
-{
-	int fd;
-
-	FLOCKFILE(fp);
-	fd = __sfileno(fp);
-	FUNLOCKFILE(fp);
-
-	return (fd);
-}
-
-int
-fileno_unlocked(FILE *fp)
-{
-
-	return (__sfileno(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fpurge.c b/libc/upstream-freebsd/lib/libc/stdio/fpurge.c
deleted file mode 100644
index f205bdf..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fpurge.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fpurge.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-/*
- * fpurge: like fflush, but without writing anything: leave the
- * given FILE's buffer empty.
- */
-int
-fpurge(FILE *fp)
-{
-	int retval;
-	FLOCKFILE(fp);
-	if (!fp->_flags) {
-		errno = EBADF;
-		retval = EOF;
-	} else {
-		if (HASUB(fp))
-			FREEUB(fp);
-		fp->_p = fp->_bf._base;
-		fp->_r = 0;
-		fp->_w = fp->_flags & (__SLBF|__SNBF|__SRD) ? 0 : fp->_bf._size;
-		retval = 0;
-	}
-	FUNLOCKFILE(fp);
-	return (retval);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fputs.c b/libc/upstream-freebsd/lib/libc/stdio/fputs.c
deleted file mode 100644
index 3b8f2c9..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fputs.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fputs.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include <string.h>
-#include "un-namespace.h"
-#include "fvwrite.h"
-#include "libc_private.h"
-#include "local.h"
-
-/*
- * Write the given string to the given file.
- */
-int
-fputs(const char * __restrict s, FILE * __restrict fp)
-{
-	int retval;
-	struct __suio uio;
-	struct __siov iov;
-
-	iov.iov_base = (void *)s;
-	iov.iov_len = uio.uio_resid = strlen(s);
-	uio.uio_iov = &iov;
-	uio.uio_iovcnt = 1;
-	FLOCKFILE(fp);
-	ORIENT(fp, -1);
-	retval = __sfvwrite(fp, &uio);
-	FUNLOCKFILE(fp);
-	return (retval);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fsetpos.c b/libc/upstream-freebsd/lib/libc/stdio/fsetpos.c
deleted file mode 100644
index c6b8b78..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fsetpos.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fsetpos.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <stdio.h>
-
-/*
- * fsetpos: like fseek.
- */
-int
-fsetpos(FILE *iop, const fpos_t *pos)
-{
-	return (fseeko(iop, (off_t)*pos, SEEK_SET));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/funopen.c b/libc/upstream-freebsd/lib/libc/stdio/funopen.c
deleted file mode 100644
index 983fe50..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/funopen.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)funopen.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <errno.h>
-
-#include "local.h"
-
-FILE *
-funopen(const void *cookie,
-	int (*readfn)(void *, char *, int),
-	int (*writefn)(void *, const char *, int),
-	fpos_t (*seekfn)(void *, fpos_t, int),
-	int (*closefn)(void *))
-{
-	FILE *fp;
-	int flags;
-
-	if (readfn == NULL) {
-		if (writefn == NULL) {		/* illegal */
-			errno = EINVAL;
-			return (NULL);
-		} else
-			flags = __SWR;		/* write only */
-	} else {
-		if (writefn == NULL)
-			flags = __SRD;		/* read only */
-		else
-			flags = __SRW;		/* read-write */
-	}
-	if ((fp = __sfp()) == NULL)
-		return (NULL);
-	fp->_flags = flags;
-	fp->_file = -1;
-	fp->_cookie = (void *)cookie;
-	fp->_read = readfn;
-	fp->_write = writefn;
-	fp->_seek = seekfn;
-	fp->_close = closefn;
-	return (fp);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fwalk.c b/libc/upstream-freebsd/lib/libc/stdio/fwalk.c
deleted file mode 100644
index 151837b..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fwalk.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fwalk.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <stdio.h>
-#include "local.h"
-#include "glue.h"
-
-int
-_fwalk(int (*function)(FILE *))
-{
-	FILE *fp;
-	int n, ret;
-	struct glue *g;
-
-	ret = 0;
-	/*
-	 * It should be safe to walk the list without locking it;
-	 * new nodes are only added to the end and none are ever
-	 * removed.
-	 *
-	 * Avoid locking this list while walking it or else you will
-	 * introduce a potential deadlock in [at least] refill.c.
-	 */
-	for (g = &__sglue; g != NULL; g = g->next)
-		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
-			if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0))
-				ret |= (*function)(fp);
-	return (ret);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fwrite.c b/libc/upstream-freebsd/lib/libc/stdio/fwrite.c
deleted file mode 100644
index 707d362..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fwrite.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fwrite.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <errno.h>
-#include <stdint.h>
-#include <stdio.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "fvwrite.h"
-#include "libc_private.h"
-
-/*
- * Write `count' objects (each size `size') from memory to the given file.
- * Return the number of whole objects written.
- */
-size_t
-fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __restrict fp)
-{
-	size_t n;
-	struct __suio uio;
-	struct __siov iov;
-
-	/*
-	 * ANSI and SUSv2 require a return value of 0 if size or count are 0.
-	 */
-	if ((count == 0) || (size == 0))
-		return (0);
-
-	/*
-	 * Check for integer overflow.  As an optimization, first check that
-	 * at least one of {count, size} is at least 2^16, since if both
-	 * values are less than that, their product can't possible overflow
-	 * (size_t is always at least 32 bits on FreeBSD).
-	 */
-	if (((count | size) > 0xFFFF) &&
-	    (count > SIZE_MAX / size)) {
-		errno = EINVAL;
-		fp->_flags |= __SERR;
-		return (0);
-	}
-
-	n = count * size;
-
-	iov.iov_base = (void *)buf;
-	uio.uio_resid = iov.iov_len = n;
-	uio.uio_iov = &iov;
-	uio.uio_iovcnt = 1;
-
-	FLOCKFILE(fp);
-	ORIENT(fp, -1);
-	/*
-	 * The usual case is success (__sfvwrite returns 0);
-	 * skip the divide if this happens, since divides are
-	 * generally slow and since this occurs whenever size==0.
-	 */
-	if (__sfvwrite(fp, &uio) != 0)
-	    count = (n - uio.uio_resid) / size;
-	FUNLOCKFILE(fp);
-	return (count);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/getc.c b/libc/upstream-freebsd/lib/libc/stdio/getc.c
deleted file mode 100644
index 4963c8c..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/getc.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getc.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-#include "local.h"
-
-#undef getc
-#undef getc_unlocked
-
-int
-getc(FILE *fp)
-{
-	int retval;
-	FLOCKFILE(fp);
-	/* Orientation set by __sgetc() when buffer is empty. */
-	/* ORIENT(fp, -1); */
-	retval = __sgetc(fp);
-	FUNLOCKFILE(fp);
-	return (retval);
-}
-
-int
-getc_unlocked(FILE *fp)
-{
-
-	return (__sgetc(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/getchar.c b/libc/upstream-freebsd/lib/libc/stdio/getchar.c
deleted file mode 100644
index 21040bc..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/getchar.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getchar.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * A subroutine version of the macro getchar.
- */
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-#undef getchar
-#undef getchar_unlocked
-
-int
-getchar()
-{
-	int retval;
-	FLOCKFILE(stdin);
-	/* Orientation set by __sgetc() when buffer is empty. */
-	/* ORIENT(stdin, -1); */
-	retval = __sgetc(stdin);
-	FUNLOCKFILE(stdin);
-	return (retval);
-}
-
-int
-getchar_unlocked(void)
-{
-
-	return (__sgetc(stdin));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/makebuf.c b/libc/upstream-freebsd/lib/libc/stdio/makebuf.c
deleted file mode 100644
index a92087e..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/makebuf.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)makebuf.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "un-namespace.h"
-
-#include "libc_private.h"
-#include "local.h"
-
-/*
- * Allocate a file buffer, or switch to unbuffered I/O.
- * Per the ANSI C standard, ALL tty devices default to line buffered.
- *
- * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
- * optimisation) right after the _fstat() that finds the buffer size.
- */
-void
-__smakebuf(FILE *fp)
-{
-	void *p;
-	int flags;
-	size_t size;
-	int couldbetty;
-
-	if (fp->_flags & __SNBF) {
-		fp->_bf._base = fp->_p = fp->_nbuf;
-		fp->_bf._size = 1;
-		return;
-	}
-	flags = __swhatbuf(fp, &size, &couldbetty);
-	if ((p = malloc(size)) == NULL) {
-		fp->_flags |= __SNBF;
-		fp->_bf._base = fp->_p = fp->_nbuf;
-		fp->_bf._size = 1;
-		return;
-	}
-	__cleanup = _cleanup;
-	flags |= __SMBF;
-	fp->_bf._base = fp->_p = p;
-	fp->_bf._size = size;
-	if (couldbetty && isatty(fp->_file))
-		flags |= __SLBF;
-	fp->_flags |= flags;
-}
-
-/*
- * Internal routine to determine `proper' buffering for a file.
- */
-int
-__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
-{
-	struct stat st;
-
-	if (fp->_file < 0 || _fstat(fp->_file, &st) < 0) {
-		*couldbetty = 0;
-		*bufsize = BUFSIZ;
-		return (__SNPT);
-	}
-
-	/* could be a tty iff it is a character device */
-	*couldbetty = (st.st_mode & S_IFMT) == S_IFCHR;
-	if (st.st_blksize <= 0) {
-		*bufsize = BUFSIZ;
-		return (__SNPT);
-	}
-
-	/*
-	 * Optimise fseek() only if it is a regular file.  (The test for
-	 * __sseek is mainly paranoia.)  It is safe to set _blksize
-	 * unconditionally; it will only be used if __SOPT is also set.
-	 */
-	*bufsize = st.st_blksize;
-	fp->_blksize = st.st_blksize;
-	return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ?
-	    __SOPT : __SNPT);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/mktemp.c b/libc/upstream-freebsd/lib/libc/stdio/mktemp.c
deleted file mode 100644
index 58783dd..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/mktemp.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright (c) 1987, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)mktemp.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-char *_mktemp(char *);
-
-static int _gettemp(char *, int *, int, int);
-
-static const unsigned char padchar[] =
-"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
-int
-mkstemps(char *path, int slen)
-{
-	int fd;
-
-	return (_gettemp(path, &fd, 0, slen) ? fd : -1);
-}
-
-int
-mkstemp(char *path)
-{
-	int fd;
-
-	return (_gettemp(path, &fd, 0, 0) ? fd : -1);
-}
-
-char *
-mkdtemp(char *path)
-{
-	return (_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL);
-}
-
-char *
-_mktemp(char *path)
-{
-	return (_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL);
-}
-
-__warn_references(mktemp,
-    "warning: mktemp() possibly used unsafely; consider using mkstemp()");
-
-char *
-mktemp(char *path)
-{
-	return (_mktemp(path));
-}
-
-static int
-_gettemp(char *path, int *doopen, int domkdir, int slen)
-{
-	char *start, *trv, *suffp, *carryp;
-	char *pad;
-	struct stat sbuf;
-	int rval;
-	uint32_t rand;
-	char carrybuf[MAXPATHLEN];
-
-	if ((doopen != NULL && domkdir) || slen < 0) {
-		errno = EINVAL;
-		return (0);
-	}
-
-	for (trv = path; *trv != '\0'; ++trv)
-		;
-	if (trv - path >= MAXPATHLEN) {
-		errno = ENAMETOOLONG;
-		return (0);
-	}
-	trv -= slen;
-	suffp = trv;
-	--trv;
-	if (trv < path || NULL != strchr(suffp, '/')) {
-		errno = EINVAL;
-		return (0);
-	}
-
-	/* Fill space with random characters */
-	while (trv >= path && *trv == 'X') {
-		rand = arc4random_uniform(sizeof(padchar) - 1);
-		*trv-- = padchar[rand];
-	}
-	start = trv + 1;
-
-	/* save first combination of random characters */
-	memcpy(carrybuf, start, suffp - start);
-
-	/*
-	 * check the target directory.
-	 */
-	if (doopen != NULL || domkdir) {
-		for (; trv > path; --trv) {
-			if (*trv == '/') {
-				*trv = '\0';
-				rval = stat(path, &sbuf);
-				*trv = '/';
-				if (rval != 0)
-					return (0);
-				if (!S_ISDIR(sbuf.st_mode)) {
-					errno = ENOTDIR;
-					return (0);
-				}
-				break;
-			}
-		}
-	}
-
-	for (;;) {
-		if (doopen) {
-			if ((*doopen =
-			    _open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0)
-				return (1);
-			if (errno != EEXIST)
-				return (0);
-		} else if (domkdir) {
-			if (mkdir(path, 0700) == 0)
-				return (1);
-			if (errno != EEXIST)
-				return (0);
-		} else if (lstat(path, &sbuf))
-			return (errno == ENOENT);
-
-		/* If we have a collision, cycle through the space of filenames */
-		for (trv = start, carryp = carrybuf;;) {
-			/* have we tried all possible permutations? */
-			if (trv == suffp)
-				return (0); /* yes - exit with EEXIST */
-			pad = strchr(padchar, *trv);
-			if (pad == NULL) {
-				/* this should never happen */
-				errno = EIO;
-				return (0);
-			}
-			/* increment character */
-			*trv = (*++pad == '\0') ? padchar[0] : *pad;
-			/* carry to next position? */
-			if (*trv == *carryp) {
-				/* increment position and loop */
-				++trv;
-				++carryp;
-			} else {
-				/* try with new name */
-				break;
-			}
-		}
-	}
-	/*NOTREACHED*/
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/putc.c b/libc/upstream-freebsd/lib/libc/stdio/putc.c
deleted file mode 100644
index aaffece..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/putc.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putc.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-#undef putc
-#undef putc_unlocked
-
-int
-putc(int c, FILE *fp)
-{
-	int retval;
-	FLOCKFILE(fp);
-	/* Orientation set by __sputc() when buffer is full. */
-	/* ORIENT(fp, -1); */
-	retval = __sputc(c, fp);
-	FUNLOCKFILE(fp);
-	return (retval);
-}
-
-int
-putc_unlocked(int ch, FILE *fp)
-{
-
-	return (__sputc(ch, fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/putchar.c b/libc/upstream-freebsd/lib/libc/stdio/putchar.c
deleted file mode 100644
index 7561559..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/putchar.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putchar.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-#undef putchar
-#undef putchar_unlocked
-
-/*
- * A subroutine version of the macro putchar
- */
-int
-putchar(int c)
-{
-	int retval;
-	FILE *so = stdout;
-
-	FLOCKFILE(so);
-	/* Orientation set by __sputc() when buffer is full. */
-	/* ORIENT(so, -1); */
-	retval = __sputc(c, so);
-	FUNLOCKFILE(so);
-	return (retval);
-}
-
-int
-putchar_unlocked(int ch)
-{
-
-	return (__sputc(ch, stdout));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/puts.c b/libc/upstream-freebsd/lib/libc/stdio/puts.c
deleted file mode 100644
index 5ee7fc1..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/puts.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)puts.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include <string.h>
-#include "un-namespace.h"
-#include "fvwrite.h"
-#include "libc_private.h"
-#include "local.h"
-
-/*
- * Write the given string to stdout, appending a newline.
- */
-int
-puts(char const *s)
-{
-	int retval;
-	size_t c = strlen(s);
-	struct __suio uio;
-	struct __siov iov[2];
-
-	iov[0].iov_base = (void *)s;
-	iov[0].iov_len = c;
-	iov[1].iov_base = "\n";
-	iov[1].iov_len = 1;
-	uio.uio_resid = c + 1;
-	uio.uio_iov = &iov[0];
-	uio.uio_iovcnt = 2;
-	FLOCKFILE(stdout);
-	ORIENT(stdout, -1);
-	retval = __sfvwrite(stdout, &uio) ? EOF : '\n';
-	FUNLOCKFILE(stdout);
-	return (retval);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/putw.c b/libc/upstream-freebsd/lib/libc/stdio/putw.c
deleted file mode 100644
index 0360caf..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/putw.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putw.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "fvwrite.h"
-#include "libc_private.h"
-
-int
-putw(int w, FILE *fp)
-{
-	int retval;
-	struct __suio uio;
-	struct __siov iov;
-
-	iov.iov_base = &w;
-	iov.iov_len = uio.uio_resid = sizeof(w);
-	uio.uio_iov = &iov;
-	uio.uio_iovcnt = 1;
-	FLOCKFILE(fp);
-	retval = __sfvwrite(fp, &uio);
-	FUNLOCKFILE(fp);
-	return (retval);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/remove.c b/libc/upstream-freebsd/lib/libc/stdio/remove.c
deleted file mode 100644
index 2e984ba..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/remove.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)remove.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdio.h>
-
-int
-remove(const char *file)
-{
-	struct stat sb;
-
-	if (lstat(file, &sb) < 0)
-		return (-1);
-	if (S_ISDIR(sb.st_mode))
-		return (rmdir(file));
-	return (unlink(file));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/rget.c b/libc/upstream-freebsd/lib/libc/stdio/rget.c
deleted file mode 100644
index bdc0311..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/rget.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rget.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include "local.h"
-
-/*
- * Handle getc() when the buffer ran out:
- * Refill, then return the first character
- * in the newly-filled buffer.
- */
-int
-__srget(FILE *fp)
-{
-	if (__srefill(fp) == 0) {
-		fp->_r--;
-		return (*fp->_p++);
-	}
-	return (EOF);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c b/libc/upstream-freebsd/lib/libc/stdio/setbuf.c
deleted file mode 100644
index 5c65f97..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setbuf.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include "local.h"
-
-void
-setbuf(FILE * __restrict fp, char * __restrict buf)
-{
-	(void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuffer.c b/libc/upstream-freebsd/lib/libc/stdio/setbuffer.c
deleted file mode 100644
index af5eb3c..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/setbuffer.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setbuffer.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-
-void
-setbuffer(FILE *fp, char *buf, int size)
-{
-
-	(void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size);
-}
-
-/*
- * set line buffering
- */
-int
-setlinebuf(FILE *fp)
-{
-
-	return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/setvbuf.c b/libc/upstream-freebsd/lib/libc/stdio/setvbuf.c
deleted file mode 100644
index d396960..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/setvbuf.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setvbuf.c	8.2 (Berkeley) 11/16/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-/*
- * Set one of the three kinds of buffering, optionally including
- * a buffer.
- */
-int
-setvbuf(FILE * __restrict fp, char * __restrict buf, int mode, size_t size)
-{
-	int ret, flags;
-	size_t iosize;
-	int ttyflag;
-
-	/*
-	 * Verify arguments.  The `int' limit on `size' is due to this
-	 * particular implementation.  Note, buf and size are ignored
-	 * when setting _IONBF.
-	 */
-	if (mode != _IONBF)
-		if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0)
-			return (EOF);
-
-	FLOCKFILE(fp);
-	/*
-	 * Write current buffer, if any.  Discard unread input (including
-	 * ungetc data), cancel line buffering, and free old buffer if
-	 * malloc()ed.  We also clear any eof condition, as if this were
-	 * a seek.
-	 */
-	ret = 0;
-	(void)__sflush(fp);
-	if (HASUB(fp))
-		FREEUB(fp);
-	fp->_r = fp->_lbfsize = 0;
-	flags = fp->_flags;
-	if (flags & __SMBF)
-		free((void *)fp->_bf._base);
-	flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SOFF | __SNPT | __SEOF);
-
-	/* If setting unbuffered mode, skip all the hard work. */
-	if (mode == _IONBF)
-		goto nbf;
-
-	/*
-	 * Find optimal I/O size for seek optimization.  This also returns
-	 * a `tty flag' to suggest that we check isatty(fd), but we do not
-	 * care since our caller told us how to buffer.
-	 */
-	flags |= __swhatbuf(fp, &iosize, &ttyflag);
-	if (size == 0) {
-		buf = NULL;	/* force local allocation */
-		size = iosize;
-	}
-
-	/* Allocate buffer if needed. */
-	if (buf == NULL) {
-		if ((buf = malloc(size)) == NULL) {
-			/*
-			 * Unable to honor user's request.  We will return
-			 * failure, but try again with file system size.
-			 */
-			ret = EOF;
-			if (size != iosize) {
-				size = iosize;
-				buf = malloc(size);
-			}
-		}
-		if (buf == NULL) {
-			/* No luck; switch to unbuffered I/O. */
-nbf:
-			fp->_flags = flags | __SNBF;
-			fp->_w = 0;
-			fp->_bf._base = fp->_p = fp->_nbuf;
-			fp->_bf._size = 1;
-			FUNLOCKFILE(fp);
-			return (ret);
-		}
-		flags |= __SMBF;
-	}
-
-	/*
-	 * Kill any seek optimization if the buffer is not the
-	 * right size.
-	 *
-	 * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)?
-	 */
-	if (size != iosize)
-		flags |= __SNPT;
-
-	/*
-	 * Fix up the FILE fields, and set __cleanup for output flush on
-	 * exit (since we are buffered in some way).
-	 */
-	if (mode == _IOLBF)
-		flags |= __SLBF;
-	fp->_flags = flags;
-	fp->_bf._base = fp->_p = (unsigned char *)buf;
-	fp->_bf._size = size;
-	/* fp->_lbfsize is still 0 */
-	if (flags & __SWR) {
-		/*
-		 * Begin or continue writing: see __swsetup().  Note
-		 * that __SNBF is impossible (it was handled earlier).
-		 */
-		if (flags & __SLBF) {
-			fp->_w = 0;
-			fp->_lbfsize = -fp->_bf._size;
-		} else
-			fp->_w = size;
-	} else {
-		/* begin/continue reading, or stay in intermediate state */
-		fp->_w = 0;
-	}
-	__cleanup = _cleanup;
-
-	FUNLOCKFILE(fp);
-	return (ret);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/tempnam.c b/libc/upstream-freebsd/lib/libc/stdio/tempnam.c
deleted file mode 100644
index e15746f..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/tempnam.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tempnam.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <paths.h>
-
-__warn_references(tempnam,
-    "warning: tempnam() possibly used unsafely; consider using mkstemp()");
-
-extern char *_mktemp(char *);
-
-char *
-tempnam(const char *dir, const char *pfx)
-{
-	int sverrno;
-	char *f, *name;
-
-	if (!(name = malloc(MAXPATHLEN)))
-		return(NULL);
-
-	if (!pfx)
-		pfx = "tmp.";
-
-	if (issetugid() == 0 && (f = getenv("TMPDIR"))) {
-		(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
-		    *(f + strlen(f) - 1) == '/'? "": "/", pfx);
-		if ((f = _mktemp(name)))
-			return(f);
-	}
-
-	if ((f = (char *)dir)) {
-		(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
-		    *(f + strlen(f) - 1) == '/'? "": "/", pfx);
-		if ((f = _mktemp(name)))
-			return(f);
-	}
-
-	f = P_tmpdir;
-	(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
-	if ((f = _mktemp(name)))
-		return(f);
-
-	f = _PATH_TMP;
-	(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
-	if ((f = _mktemp(name)))
-		return(f);
-
-	sverrno = errno;
-	free(name);
-	errno = sverrno;
-	return(NULL);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/tmpnam.c b/libc/upstream-freebsd/lib/libc/stdio/tmpnam.c
deleted file mode 100644
index ce32dcc..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/tmpnam.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tmpnam.c	8.3 (Berkeley) 3/28/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <unistd.h>
-
-__warn_references(tmpnam,
-    "warning: tmpnam() possibly used unsafely; consider using mkstemp()");
-
-extern char *_mktemp(char *);
-
-char *
-tmpnam(char *s)
-{
-	static u_long tmpcount;
-	static char buf[L_tmpnam];
-
-	if (s == NULL)
-		s = buf;
-	(void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount);
-	++tmpcount;
-	return (_mktemp(s));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/wsetup.c b/libc/upstream-freebsd/lib/libc/stdio/wsetup.c
deleted file mode 100644
index 70f8247..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/wsetup.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)wsetup.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "local.h"
-
-/*
- * Various output routines call wsetup to be sure it is safe to write,
- * because either _flags does not include __SWR, or _buf is NULL.
- * _wsetup returns 0 if OK to write; otherwise, it returns EOF and sets errno.
- */
-int
-__swsetup(FILE *fp)
-{
-	/* make sure stdio is set up */
-	if (!__sdidinit)
-		__sinit();
-
-	/*
-	 * If we are not writing, we had better be reading and writing.
-	 */
-	if ((fp->_flags & __SWR) == 0) {
-		if ((fp->_flags & __SRW) == 0) {
-			errno = EBADF;
-			fp->_flags |= __SERR;
-			return (EOF);
-		}
-		if (fp->_flags & __SRD) {
-			/* clobber any ungetc data */
-			if (HASUB(fp))
-				FREEUB(fp);
-			fp->_flags &= ~(__SRD|__SEOF);
-			fp->_r = 0;
-			fp->_p = fp->_bf._base;
-		}
-		fp->_flags |= __SWR;
-	}
-
-	/*
-	 * Make a buffer if necessary, then set _w.
-	 */
-	if (fp->_bf._base == NULL)
-		__smakebuf(fp);
-	if (fp->_flags & __SLBF) {
-		/*
-		 * It is line buffered, so make _lbfsize be -_bufsize
-		 * for the putc() macro.  We will change _lbfsize back
-		 * to 0 whenever we turn off __SWR.
-		 */
-		fp->_w = 0;
-		fp->_lbfsize = -fp->_bf._size;
-	} else
-		fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
-	return (0);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c b/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c
new file mode 100644
index 0000000..ef8cdb1
--- /dev/null
+++ b/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c
@@ -0,0 +1,80 @@
+/*-
+ * Copyright (c) 2011 David Chisnall
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <stdlib.h>
+#include <pthread.h>
+
+/**
+ * Linked list of quick exit handlers.  This is simpler than the atexit()
+ * version, because it is not required to support C++ destructors or
+ * DSO-specific cleanups.
+ */
+struct quick_exit_handler {
+	struct quick_exit_handler *next;
+	void (*cleanup)(void);
+};
+
+/**
+ * Lock protecting the handlers list.
+ */
+static pthread_mutex_t atexit_mutex = PTHREAD_MUTEX_INITIALIZER;
+/**
+ * Stack of cleanup handlers.  These will be invoked in reverse order when 
+ */
+static struct quick_exit_handler *handlers;
+
+int
+at_quick_exit(void (*func)(void))
+{
+	struct quick_exit_handler *h;
+	
+	h = malloc(sizeof(*h));
+
+	if (NULL == h)
+		return (1);
+	h->cleanup = func;
+	pthread_mutex_lock(&atexit_mutex);
+	h->next = handlers;
+	handlers = h;
+	pthread_mutex_unlock(&atexit_mutex);
+	return (0);
+}
+
+void
+quick_exit(int status)
+{
+	struct quick_exit_handler *h;
+
+	/*
+	 * XXX: The C++ spec requires us to call std::terminate if there is an
+	 * exception here.
+	 */
+	for (h = handlers; NULL != h; h = h->next)
+		h->cleanup();
+	_Exit(status);
+}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcslcpy.c b/libc/upstream-freebsd/lib/libc/string/wcslcpy.c
deleted file mode 100644
index b104a06..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcslcpy.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *	from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp
- */
-
-#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <wchar.h>
-
-/*
- * Copy src to string dst of size siz.  At most siz-1 characters
- * will be copied.  Always NUL terminates (unless siz == 0).
- * Returns wcslen(src); if retval >= siz, truncation occurred.
- */
-size_t
-wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
-{
-	wchar_t *d = dst;
-	const wchar_t *s = src;
-	size_t n = siz;
-
-	/* Copy as many bytes as will fit */
-	if (n != 0 && --n != 0) {
-		do {
-			if ((*d++ = *s++) == 0)
-				break;
-		} while (--n != 0);
-	}
-
-	/* Not enough room in dst, add NUL and traverse rest of src */
-	if (n == 0) {
-		if (siz != 0)
-			*d = '\0';		/* NUL-terminate dst */
-		while (*s++)
-			;
-	}
-
-	return(s - src - 1);	/* count does not include NUL */
-}
diff --git a/libc/upstream-freebsd/lib/libc/string/wcsstr.c b/libc/upstream-freebsd/lib/libc/string/wcsstr.c
deleted file mode 100644
index ce598a6..0000000
--- a/libc/upstream-freebsd/lib/libc/string/wcsstr.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strstr.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-/*
- * Find the first occurrence of find in s.
- */
-wchar_t *
-wcsstr(const wchar_t * __restrict s, const wchar_t * __restrict find)
-{
-	wchar_t c, sc;
-	size_t len;
-
-	if ((c = *find++) != L'\0') {
-		len = wcslen(find);
-		do {
-			do {
-				if ((sc = *s++) == L'\0')
-					return (NULL);
-			} while (sc != c);
-		} while (wcsncmp(s, find, len) != 0);
-		s--;
-	}
-	return ((wchar_t *)s);
-}
diff --git a/libc/upstream-freebsd/libc_private.h b/libc/upstream-freebsd/libc_private.h
deleted file mode 100644
index ecdbb7e..0000000
--- a/libc/upstream-freebsd/libc_private.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _BIONIC_FREEBSD_LIBC_PRIVATE_H_included
-#define _BIONIC_FREEBSD_LIBC_PRIVATE_H_included
-
-#define FLOCKFILE(fp)   do { if (__isthreaded) flockfile(fp); } while (0)
-#define FUNLOCKFILE(fp) do { if (__isthreaded) funlockfile(fp); } while (0)
-
-#define STDIO_THREAD_LOCK()   /* TODO: until we have the FreeBSD findfp.c, this is useless. */
-#define STDIO_THREAD_UNLOCK() /* TODO: until we have the FreeBSD findfp.c, this is useless. */
-
-#define ORIENT(fp, o) /* Only needed for wide-character stream support. */
-
-#endif
diff --git a/libc/upstream-freebsd/namespace.h b/libc/upstream-freebsd/namespace.h
deleted file mode 100644
index a980b57..0000000
--- a/libc/upstream-freebsd/namespace.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _BIONIC_FREEBSD_NAMESPACE_H_included
-#define _BIONIC_FREEBSD_NAMESPACE_H_included
-
-__attribute__((visibility("hidden"))) char* _mktemp(char*);
-
-#endif
diff --git a/libc/upstream-netbsd/README.txt b/libc/upstream-netbsd/README.txt
index 86af6eb..e2d146e 100644
--- a/libc/upstream-netbsd/README.txt
+++ b/libc/upstream-netbsd/README.txt
@@ -2,8 +2,4 @@
 files directly. Make fixes upstream and then pull down the new version of
 the file.
 
-Note that code in the other 'netbsd' directory contains Android modifications.
-We should work towards getting as many of those changes as possible upstream
-and then losing those files in favor of pure upstream copies here instead.
-
 TODO: write a script to make this process automated.
diff --git a/libc/upstream-netbsd/env.h b/libc/upstream-netbsd/android/include/env.h
similarity index 100%
rename from libc/upstream-netbsd/env.h
rename to libc/upstream-netbsd/android/include/env.h
diff --git a/libc/upstream-netbsd/extern.h b/libc/upstream-netbsd/android/include/extern.h
similarity index 100%
rename from libc/upstream-netbsd/extern.h
rename to libc/upstream-netbsd/android/include/extern.h
diff --git a/libc/upstream-netbsd/fd_setsize.h b/libc/upstream-netbsd/android/include/fd_setsize.h
similarity index 100%
rename from libc/upstream-netbsd/fd_setsize.h
rename to libc/upstream-netbsd/android/include/fd_setsize.h
diff --git a/libc/upstream-netbsd/android/include/namespace.h b/libc/upstream-netbsd/android/include/namespace.h
new file mode 100644
index 0000000..5df543c
--- /dev/null
+++ b/libc/upstream-netbsd/android/include/namespace.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_NETBSD_NAMESPACE_H_included
+#define _BIONIC_NETBSD_NAMESPACE_H_included
+
+// NetBSD uses __weak_alias on a lot of functions. We don't want that.
+#if defined(__weak_alias)
+#undef __weak_alias
+#endif
+
+__LIBC_HIDDEN__ int __res_enable_mt(void);
+__LIBC_HIDDEN__ int __res_disable_mt(void);
+
+#endif
diff --git a/libc/upstream-netbsd/android/include/netbsd-compat.h b/libc/upstream-netbsd/android/include/netbsd-compat.h
new file mode 100644
index 0000000..84be931
--- /dev/null
+++ b/libc/upstream-netbsd/android/include/netbsd-compat.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_NETBSD_COMPAT_H_included
+#define _BIONIC_NETBSD_COMPAT_H_included
+
+// NetBSD uses _DIAGASSERT to null-check arguments and the like.
+#include <assert.h>
+#define _DIAGASSERT(e) ((e) ? (void) 0 : __assert2(__FILE__, __LINE__, __func__, #e))
+
+// TODO: update our <sys/cdefs.h> to support this properly.
+#define __type_fit(t, a) (0 == 0)
+
+#define _GNU_SOURCE
+#define __USE_BSD
+
+// TODO: we don't yet have thread-safe environment variables.
+#define __readlockenv() 0
+#define __unlockenv() 0
+
+#endif
diff --git a/libc/upstream-netbsd/port_after.h b/libc/upstream-netbsd/android/include/port_after.h
similarity index 100%
rename from libc/upstream-netbsd/port_after.h
rename to libc/upstream-netbsd/android/include/port_after.h
diff --git a/libc/upstream-netbsd/android/include/port_before.h b/libc/upstream-netbsd/android/include/port_before.h
new file mode 100644
index 0000000..9fa9487
--- /dev/null
+++ b/libc/upstream-netbsd/android/include/port_before.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_NETBSD_PORT_BEFORE_H_included
+#define _BIONIC_NETBSD_PORT_BEFORE_H_included
+
+#include "namespace.h"
+#include <sys/cdefs.h>
+#include <time.h>
+#include <arpa/nameser.h>
+
+#define ISC_FORMAT_PRINTF(a,b) __printflike(a,b)
+#define ISC_SOCKLEN_T socklen_t
+
+#endif
diff --git a/libc/upstream-netbsd/android/include/rand48.h b/libc/upstream-netbsd/android/include/rand48.h
new file mode 100644
index 0000000..1279906
--- /dev/null
+++ b/libc/upstream-netbsd/android/include/rand48.h
@@ -0,0 +1,34 @@
+/*	$NetBSD: rand48.h,v 1.6 2011/05/18 19:36:36 dsl Exp $	*/
+
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#ifndef _RAND48_H_
+#define _RAND48_H_
+
+#include <stdlib.h>
+
+__LIBC_HIDDEN__ void		__dorand48(unsigned short[3]);
+__LIBC_HIDDEN__ unsigned short	__rand48_seed[3];
+__LIBC_HIDDEN__ unsigned short	__rand48_mult[3];
+__LIBC_HIDDEN__ unsigned short	__rand48_add;
+
+#define	RAND48_SEED_0	(0x330e)
+#define	RAND48_SEED_1	(0xabcd)
+#define	RAND48_SEED_2	(0x1234)
+#define	RAND48_MULT_0	(0xe66d)
+#define	RAND48_MULT_1	(0xdeec)
+#define	RAND48_MULT_2	(0x0005)
+#define	RAND48_ADD	(0x000b)
+
+#endif /* _RAND48_H_ */
diff --git a/libc/upstream-netbsd/android/include/reentrant.h b/libc/upstream-netbsd/android/include/reentrant.h
new file mode 100644
index 0000000..3ca8fd6
--- /dev/null
+++ b/libc/upstream-netbsd/android/include/reentrant.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_NETBSD_REENTRANT_H_included
+#define _BIONIC_NETBSD_REENTRANT_H_included
+
+#define _REENTRANT
+
+#include <pthread.h>
+#include <signal.h>
+
+//
+// Map NetBSD libc internal locking to pthread locking.
+//
+
+#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define mutex_t pthread_mutex_t
+#define mutex_lock(x) pthread_mutex_lock(x)
+#define mutex_unlock(x) pthread_mutex_unlock(x)
+
+#define RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
+#define rwlock_t pthread_rwlock_t
+#define rwlock_rdlock pthread_rwlock_rdlock
+#define rwlock_unlock pthread_rwlock_unlock
+#define rwlock_wrlock pthread_rwlock_wrlock
+
+#endif
diff --git a/libc/include/sys/sha1.h b/libc/upstream-netbsd/android/include/sys/sha1.h
similarity index 100%
rename from libc/include/sys/sha1.h
rename to libc/upstream-netbsd/android/include/sys/sha1.h
diff --git a/libc/upstream-netbsd/common/lib/libc/inet/inet_addr.c b/libc/upstream-netbsd/common/lib/libc/inet/inet_addr.c
deleted file mode 100644
index 1360ce9..0000000
--- a/libc/upstream-netbsd/common/lib/libc/inet/inet_addr.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/*	$NetBSD: inet_addr.c,v 1.3 2012/03/09 15:41:16 christos Exp $	*/
-
-/*
- * Copyright (c) 1983, 1990, 1993
- *    The Regents of the University of California.  All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static const char sccsid[] = "@(#)inet_addr.c	8.1 (Berkeley) 6/17/93";
-static const char rcsid[] = "Id: inet_addr.c,v 1.2.206.2 2004/03/17 00:29:45 marka Exp";
-#else
-__RCSID("$NetBSD: inet_addr.c,v 1.3 2012/03/09 15:41:16 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <ctype.h>
-
-#include "port_after.h"
-
-#ifdef __weak_alias
-__weak_alias(inet_aton,_inet_aton)
-#endif
-#else
-#include <lib/libkern/libkern.h>
-#include <netinet/in.h>
-#endif
-
-/*
- * Ascii internet address interpretation routine.
- * The value returned is in network order.
- */
-uint32_t
-inet_addr(const char *cp) {
-	struct in_addr val;
-
-	if (inet_aton(cp, &val))
-		return (val.s_addr);
-	return (INADDR_NONE);
-}
-
-/* 
- * Check whether "cp" is a valid ascii representation
- * of an Internet address and convert to a binary address.
- * Returns 1 if the address is valid, 0 if not.
- * This replaces inet_addr, the return value from which
- * cannot distinguish between failure and a local broadcast address.
- */
-int
-inet_aton(const char *cp, struct in_addr *addr) {
-	uint32_t val;
-	int base;
-	size_t n;
-	char c;
-	uint8_t parts[4];
-	uint8_t *pp = parts;
-	int digit;
-
-	c = *cp;
-	for (;;) {
-		/*
-		 * Collect number up to ``.''.
-		 * Values are specified as for C:
-		 * 0x=hex, 0=octal, isdigit=decimal.
-		 */
-		if (!isdigit((unsigned char)c))
-			return (0);
-		val = 0; base = 10; digit = 0;
-		if (c == '0') {
-			c = *++cp;
-			if (c == 'x' || c == 'X')
-				base = 16, c = *++cp;
-			else {
-				base = 8;
-				digit = 1 ;
-			}
-		}
-		for (;;) {
-			if (isascii(c) && isdigit((unsigned char)c)) {
-				if (base == 8 && (c == '8' || c == '9'))
-					return (0);
-				val = (val * base) + (c - '0');
-				c = *++cp;
-				digit = 1;
-			} else if (base == 16 && isascii(c) && 
-				   isxdigit((unsigned char)c)) {
-				val = (val << 4) |
-					(c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
-				c = *++cp;
-				digit = 1;
-			} else
-				break;
-		}
-		if (c == '.') {
-			/*
-			 * Internet format:
-			 *	a.b.c.d
-			 *	a.b.c	(with c treated as 16 bits)
-			 *	a.b	(with b treated as 24 bits)
-			 */
-			if (pp >= parts + 3 || val > 0xffU)
-				return (0);
-			*pp++ = val;
-			c = *++cp;
-		} else
-			break;
-	}
-	/*
-	 * Check for trailing characters.
-	 */
-	if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c)))
-		return (0);
-	/*
-	 * Did we get a valid digit?
-	 */
-	if (!digit)
-		return (0);
-	/*
-	 * Concoct the address according to
-	 * the number of parts specified.
-	 */
-	n = pp - parts + 1;
-	switch (n) {
-	case 1:				/* a -- 32 bits */
-		break;
-
-	case 2:				/* a.b -- 8.24 bits */
-		if (val > 0xffffffU)
-			return (0);
-		val |= parts[0] << 24;
-		break;
-
-	case 3:				/* a.b.c -- 8.8.16 bits */
-		if (val > 0xffffU)
-			return (0);
-		val |= (parts[0] << 24) | (parts[1] << 16);
-		break;
-
-	case 4:				/* a.b.c.d -- 8.8.8.8 bits */
-		if (val > 0xffU)
-			return (0);
-		val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
-		break;
-	}
-	if (addr != NULL)
-		addr->s_addr = htonl(val);
-	return (1);
-}
diff --git a/libc/upstream-netbsd/common/lib/libc/stdlib/random.c b/libc/upstream-netbsd/common/lib/libc/stdlib/random.c
new file mode 100644
index 0000000..e7503c7
--- /dev/null
+++ b/libc/upstream-netbsd/common/lib/libc/stdlib/random.c
@@ -0,0 +1,530 @@
+/*	$NetBSD: random.c,v 1.4 2014/06/12 20:59:46 christos Exp $	*/
+
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)random.c	8.2 (Berkeley) 5/19/95";
+#else
+__RCSID("$NetBSD: random.c,v 1.4 2014/06/12 20:59:46 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include "reentrant.h"
+
+#ifdef __weak_alias
+__weak_alias(initstate,_initstate)
+__weak_alias(random,_random)
+__weak_alias(setstate,_setstate)
+__weak_alias(srandom,_srandom)
+#endif
+
+
+#ifdef _REENTRANT
+static mutex_t random_mutex = MUTEX_INITIALIZER;
+#endif
+#else
+#include <lib/libkern/libkern.h>
+#define mutex_lock(a)	(void)0
+#define mutex_unlock(a) (void)0
+#endif
+
+#ifndef SMALL_RANDOM
+static void srandom_unlocked(unsigned int);
+static long random_unlocked(void);
+
+#define USE_BETTER_RANDOM
+
+/*
+ * random.c:
+ *
+ * An improved random number generation package.  In addition to the standard
+ * rand()/srand() like interface, this package also has a special state info
+ * interface.  The initstate() routine is called with a seed, an array of
+ * bytes, and a count of how many bytes are being passed in; this array is
+ * then initialized to contain information for random number generation with
+ * that much state information.  Good sizes for the amount of state
+ * information are 32, 64, 128, and 256 bytes.  The state can be switched by
+ * calling the setstate() routine with the same array as was initiallized
+ * with initstate().  By default, the package runs with 128 bytes of state
+ * information and generates far better random numbers than a linear
+ * congruential generator.  If the amount of state information is less than
+ * 32 bytes, a simple linear congruential R.N.G. is used.
+ *
+ * Internally, the state information is treated as an array of ints; the
+ * zeroeth element of the array is the type of R.N.G. being used (small
+ * integer); the remainder of the array is the state information for the
+ * R.N.G.  Thus, 32 bytes of state information will give 7 ints worth of
+ * state information, which will allow a degree seven polynomial.  (Note:
+ * the zeroeth word of state information also has some other information
+ * stored in it -- see setstate() for details).
+ * 
+ * The random number generation technique is a linear feedback shift register
+ * approach, employing trinomials (since there are fewer terms to sum up that
+ * way).  In this approach, the least significant bit of all the numbers in
+ * the state table will act as a linear feedback shift register, and will
+ * have period 2^deg - 1 (where deg is the degree of the polynomial being
+ * used, assuming that the polynomial is irreducible and primitive).  The
+ * higher order bits will have longer periods, since their values are also
+ * influenced by pseudo-random carries out of the lower bits.  The total
+ * period of the generator is approximately deg*(2**deg - 1); thus doubling
+ * the amount of state information has a vast influence on the period of the
+ * generator.  Note: the deg*(2**deg - 1) is an approximation only good for
+ * large deg, when the period of the shift register is the dominant factor.
+ * With deg equal to seven, the period is actually much longer than the
+ * 7*(2**7 - 1) predicted by this formula.
+ *
+ * Modified 28 December 1994 by Jacob S. Rosenberg.
+ * The following changes have been made:
+ * All references to the type u_int have been changed to unsigned long.
+ * All references to type int have been changed to type long.  Other
+ * cleanups have been made as well.  A warning for both initstate and
+ * setstate has been inserted to the effect that on Sparc platforms
+ * the 'arg_state' variable must be forced to begin on word boundaries.
+ * This can be easily done by casting a long integer array to char *.
+ * The overall logic has been left STRICTLY alone.  This software was
+ * tested on both a VAX and Sun SpacsStation with exactly the same
+ * results.  The new version and the original give IDENTICAL results.
+ * The new version is somewhat faster than the original.  As the
+ * documentation says:  "By default, the package runs with 128 bytes of
+ * state information and generates far better random numbers than a linear
+ * congruential generator.  If the amount of state information is less than
+ * 32 bytes, a simple linear congruential R.N.G. is used."  For a buffer of
+ * 128 bytes, this new version runs about 19 percent faster and for a 16
+ * byte buffer it is about 5 percent faster.
+ *
+ * Modified 07 January 2002 by Jason R. Thorpe.
+ * The following changes have been made:
+ * All the references to "long" have been changed back to "int".  This
+ * fixes memory corruption problems on LP64 platforms.
+ */
+
+/*
+ * For each of the currently supported random number generators, we have a
+ * break value on the amount of state information (you need at least this
+ * many bytes of state info to support this random number generator), a degree
+ * for the polynomial (actually a trinomial) that the R.N.G. is based on, and
+ * the separation between the two lower order coefficients of the trinomial.
+ */
+#define	TYPE_0		0		/* linear congruential */
+#define	BREAK_0		8
+#define	DEG_0		0
+#define	SEP_0		0
+
+#define	TYPE_1		1		/* x**7 + x**3 + 1 */
+#define	BREAK_1		32
+#define	DEG_1		7
+#define	SEP_1		3
+
+#define	TYPE_2		2		/* x**15 + x + 1 */
+#define	BREAK_2		64
+#define	DEG_2		15
+#define	SEP_2		1
+
+#define	TYPE_3		3		/* x**31 + x**3 + 1 */
+#define	BREAK_3		128
+#define	DEG_3		31
+#define	SEP_3		3
+
+#define	TYPE_4		4		/* x**63 + x + 1 */
+#define	BREAK_4		256
+#define	DEG_4		63
+#define	SEP_4		1
+
+/*
+ * Array versions of the above information to make code run faster --
+ * relies on fact that TYPE_i == i.
+ */
+#define	MAX_TYPES	5		/* max number of types above */
+
+static const int degrees[MAX_TYPES] =	{ DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
+static const int seps[MAX_TYPES] =	{ SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
+
+/*
+ * Initially, everything is set up as if from:
+ *
+ *	initstate(1, &randtbl, 128);
+ *
+ * Note that this initialization takes advantage of the fact that srandom()
+ * advances the front and rear pointers 10*rand_deg times, and hence the
+ * rear pointer which starts at 0 will also end up at zero; thus the zeroeth
+ * element of the state information, which contains info about the current
+ * position of the rear pointer is just
+ *
+ *	MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3.
+ */
+
+/* LINTED */
+static int randtbl[DEG_3 + 1] = {
+	TYPE_3,
+#ifdef USE_BETTER_RANDOM
+	0x991539b1, 0x16a5bce3, 0x6774a4cd,
+	0x3e01511e, 0x4e508aaa, 0x61048c05,
+	0xf5500617, 0x846b7115, 0x6a19892c,
+	0x896a97af, 0xdb48f936, 0x14898454,
+	0x37ffd106, 0xb58bff9c, 0x59e17104,
+	0xcf918a49, 0x09378c83, 0x52c7a471,
+	0x8d293ea9, 0x1f4fc301, 0xc3db71be,
+	0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1,
+	0x19edc328, 0x87bf4bdd, 0xc9b240e5,
+	0xe9ee4b1b, 0x4382aee7, 0x535b6b41,
+	0xf3bec5da,
+#else
+	0x9a319039, 0x32d9c024, 0x9b663182,
+	0x5da1f342, 0xde3b81e0, 0xdf0a6fb5,
+	0xf103bc02, 0x48f340fb, 0x7449e56b,
+	0xbeb1dbb0, 0xab5c5918, 0x946554fd,
+	0x8c2e680f, 0xeb3d799f, 0xb11ee0b7,
+	0x2d436b86, 0xda672e2a, 0x1588ca88,
+	0xe369735d, 0x904f35f7, 0xd7158fd6,
+	0x6fa6f051, 0x616e6b96, 0xac94efdc,
+	0x36413f93, 0xc622c298, 0xf5a42ab8,
+	0x8a88d77b, 0xf5ad9d0e, 0x8999220b,
+	0x27fb47b9,
+#endif /* USE_BETTER_RANDOM */
+};
+
+/*
+ * fptr and rptr are two pointers into the state info, a front and a rear
+ * pointer.  These two pointers are always rand_sep places aparts, as they
+ * cycle cyclically through the state information.  (Yes, this does mean we
+ * could get away with just one pointer, but the code for random() is more
+ * efficient this way).  The pointers are left positioned as they would be
+ * from the call
+ *
+ *	initstate(1, randtbl, 128);
+ *
+ * (The position of the rear pointer, rptr, is really 0 (as explained above
+ * in the initialization of randtbl) because the state table pointer is set
+ * to point to randtbl[1] (as explained below).
+ */
+static int *fptr = &randtbl[SEP_3 + 1];
+static int *rptr = &randtbl[1];
+
+/*
+ * The following things are the pointer to the state information table, the
+ * type of the current generator, the degree of the current polynomial being
+ * used, and the separation between the two pointers.  Note that for efficiency
+ * of random(), we remember the first location of the state information, not
+ * the zeroeth.  Hence it is valid to access state[-1], which is used to
+ * store the type of the R.N.G.  Also, we remember the last location, since
+ * this is more efficient than indexing every time to find the address of
+ * the last element to see if the front and rear pointers have wrapped.
+ */
+static int *state = &randtbl[1];
+static int rand_type = TYPE_3;
+static int rand_deg = DEG_3;
+static int rand_sep = SEP_3;
+static int *end_ptr = &randtbl[DEG_3 + 1];
+
+/*
+ * srandom:
+ *
+ * Initialize the random number generator based on the given seed.  If the
+ * type is the trivial no-state-information type, just remember the seed.
+ * Otherwise, initializes state[] based on the given "seed" via a linear
+ * congruential generator.  Then, the pointers are set to known locations
+ * that are exactly rand_sep places apart.  Lastly, it cycles the state
+ * information a given number of times to get rid of any initial dependencies
+ * introduced by the L.C.R.N.G.  Note that the initialization of randtbl[]
+ * for default usage relies on values produced by this routine.
+ */
+static void
+srandom_unlocked(unsigned int x)
+{
+	int i;
+
+	if (rand_type == TYPE_0)
+		state[0] = x;
+	else {
+		state[0] = x;
+		for (i = 1; i < rand_deg; i++) {
+#ifdef USE_BETTER_RANDOM
+			int x1, hi, lo, t;
+
+			/*
+			 * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
+			 * From "Random number generators: good ones are hard
+			 * to find", Park and Miller, Communications of the ACM,
+			 * vol. 31, no. 10,
+			 * October 1988, p. 1195.
+			 */
+			x1 = state[i - 1];
+			hi = x1 / 127773;
+			lo = x1 % 127773;
+			t = 16807 * lo - 2836 * hi;
+			if (t <= 0)
+				t += 0x7fffffff;
+			state[i] = t;
+#else
+			state[i] = 1103515245 * state[i - 1] + 12345;
+#endif /* USE_BETTER_RANDOM */
+		}
+		fptr = &state[rand_sep];
+		rptr = &state[0];
+		for (i = 0; i < 10 * rand_deg; i++)
+			(void)random_unlocked();
+	}
+}
+
+void
+srandom(unsigned int x)
+{
+
+	mutex_lock(&random_mutex);
+	srandom_unlocked(x);
+	mutex_unlock(&random_mutex);
+}
+
+/*
+ * initstate:
+ *
+ * Initialize the state information in the given array of n bytes for future
+ * random number generation.  Based on the number of bytes we are given, and
+ * the break values for the different R.N.G.'s, we choose the best (largest)
+ * one we can and set things up for it.  srandom() is then called to
+ * initialize the state information.
+ * 
+ * Note that on return from srandom(), we set state[-1] to be the type
+ * multiplexed with the current value of the rear pointer; this is so
+ * successive calls to initstate() won't lose this information and will be
+ * able to restart with setstate().
+ * 
+ * Note: the first thing we do is save the current state, if any, just like
+ * setstate() so that it doesn't matter when initstate is called.
+ *
+ * Returns a pointer to the old state.
+ *
+ * Note: The Sparc platform requires that arg_state begin on an int
+ * word boundary; otherwise a bus error will occur. Even so, lint will
+ * complain about mis-alignment, but you should disregard these messages.
+ */
+char *
+initstate(
+	unsigned int seed,		/* seed for R.N.G. */
+	char *arg_state,		/* pointer to state array */
+	size_t n)			/* # bytes of state info */
+{
+	void *ostate = (void *)(&state[-1]);
+	int *int_arg_state;
+
+	_DIAGASSERT(arg_state != NULL);
+
+	int_arg_state = (int *)(void *)arg_state;
+
+	mutex_lock(&random_mutex);
+	if (rand_type == TYPE_0)
+		state[-1] = rand_type;
+	else
+		state[-1] = MAX_TYPES * (int)(rptr - state) + rand_type;
+	if (n < BREAK_0) {
+		mutex_unlock(&random_mutex);
+		return (NULL);
+	} else if (n < BREAK_1) {
+		rand_type = TYPE_0;
+		rand_deg = DEG_0;
+		rand_sep = SEP_0;
+	} else if (n < BREAK_2) {
+		rand_type = TYPE_1;
+		rand_deg = DEG_1;
+		rand_sep = SEP_1;
+	} else if (n < BREAK_3) {
+		rand_type = TYPE_2;
+		rand_deg = DEG_2;
+		rand_sep = SEP_2;
+	} else if (n < BREAK_4) {
+		rand_type = TYPE_3;
+		rand_deg = DEG_3;
+		rand_sep = SEP_3;
+	} else {
+		rand_type = TYPE_4;
+		rand_deg = DEG_4;
+		rand_sep = SEP_4;
+	}
+	state = (int *) (int_arg_state + 1); /* first location */
+	end_ptr = &state[rand_deg];	/* must set end_ptr before srandom */
+	srandom_unlocked(seed);
+	if (rand_type == TYPE_0)
+		int_arg_state[0] = rand_type;
+	else
+		int_arg_state[0] = MAX_TYPES * (int)(rptr - state) + rand_type;
+	mutex_unlock(&random_mutex);
+	return((char *)ostate);
+}
+
+/*
+ * setstate:
+ *
+ * Restore the state from the given state array.
+ *
+ * Note: it is important that we also remember the locations of the pointers
+ * in the current state information, and restore the locations of the pointers
+ * from the old state information.  This is done by multiplexing the pointer
+ * location into the zeroeth word of the state information.
+ *
+ * Note that due to the order in which things are done, it is OK to call
+ * setstate() with the same state as the current state.
+ *
+ * Returns a pointer to the old state information.
+ *
+ * Note: The Sparc platform requires that arg_state begin on a long
+ * word boundary; otherwise a bus error will occur. Even so, lint will
+ * complain about mis-alignment, but you should disregard these messages.
+ */
+char *
+setstate(char *arg_state)		/* pointer to state array */
+{
+	int *new_state;
+	int type;
+	int rear;
+	void *ostate = (void *)(&state[-1]);
+
+	_DIAGASSERT(arg_state != NULL);
+
+	new_state = (int *)(void *)arg_state;
+	type = (int)(new_state[0] % MAX_TYPES);
+	rear = (int)(new_state[0] / MAX_TYPES);
+
+	mutex_lock(&random_mutex);
+	if (rand_type == TYPE_0)
+		state[-1] = rand_type;
+	else
+		state[-1] = MAX_TYPES * (int)(rptr - state) + rand_type;
+	switch(type) {
+	case TYPE_0:
+	case TYPE_1:
+	case TYPE_2:
+	case TYPE_3:
+	case TYPE_4:
+		rand_type = type;
+		rand_deg = degrees[type];
+		rand_sep = seps[type];
+		break;
+	default:
+		mutex_unlock(&random_mutex);
+		return (NULL);
+	}
+	state = (int *) (new_state + 1);
+	if (rand_type != TYPE_0) {
+		rptr = &state[rear];
+		fptr = &state[(rear + rand_sep) % rand_deg];
+	}
+	end_ptr = &state[rand_deg];		/* set end_ptr too */
+	mutex_unlock(&random_mutex);
+	return((char *)ostate);
+}
+
+/*
+ * random:
+ *
+ * If we are using the trivial TYPE_0 R.N.G., just do the old linear
+ * congruential bit.  Otherwise, we do our fancy trinomial stuff, which is
+ * the same in all the other cases due to all the global variables that have
+ * been set up.  The basic operation is to add the number at the rear pointer
+ * into the one at the front pointer.  Then both pointers are advanced to
+ * the next location cyclically in the table.  The value returned is the sum
+ * generated, reduced to 31 bits by throwing away the "least random" low bit.
+ *
+ * Note: the code takes advantage of the fact that both the front and
+ * rear pointers can't wrap on the same call by not testing the rear
+ * pointer if the front one has wrapped.
+ *
+ * Returns a 31-bit random number.
+ */
+static long
+random_unlocked(void)
+{
+	int i;
+	int *f, *r;
+
+	if (rand_type == TYPE_0) {
+		i = state[0];
+		state[0] = i = (i * 1103515245 + 12345) & 0x7fffffff;
+	} else {
+		/*
+		 * Use local variables rather than static variables for speed.
+		 */
+		f = fptr; r = rptr;
+		*f += *r;
+		/* chucking least random bit */
+		i = ((unsigned int)*f >> 1) & 0x7fffffff;
+		if (++f >= end_ptr) {
+			f = state;
+			++r;
+		}
+		else if (++r >= end_ptr) {
+			r = state;
+		}
+
+		fptr = f; rptr = r;
+	}
+	return(i);
+}
+
+long
+random(void)
+{
+	long r;
+
+	mutex_lock(&random_mutex);
+	r = random_unlocked();
+	mutex_unlock(&random_mutex);
+	return (r);
+}
+#else
+long
+random(void)
+{
+	static u_long randseed = 1;
+	long x, hi, lo, t;
+ 
+	/*
+	 * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
+	 * From "Random number generators: good ones are hard to find",
+	 * Park and Miller, Communications of the ACM, vol. 31, no. 10,
+	 * October 1988, p. 1195.
+	 */
+	x = randseed;
+	hi = x / 127773;
+	lo = x % 127773;
+	t = 16807 * lo - 2836 * hi;
+	if (t <= 0)
+		t += 0x7fffffff;
+	randseed = t;
+	return (t);
+}
+#endif /* SMALL_RANDOM */
diff --git a/libc/upstream-netbsd/libc/gen/ftw.c b/libc/upstream-netbsd/lib/libc/gen/ftw.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/ftw.c
rename to libc/upstream-netbsd/lib/libc/gen/ftw.c
diff --git a/libc/upstream-netbsd/libc/gen/nftw.c b/libc/upstream-netbsd/lib/libc/gen/nftw.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/nftw.c
rename to libc/upstream-netbsd/lib/libc/gen/nftw.c
diff --git a/libc/upstream-netbsd/libc/gen/nice.c b/libc/upstream-netbsd/lib/libc/gen/nice.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/nice.c
rename to libc/upstream-netbsd/lib/libc/gen/nice.c
diff --git a/libc/upstream-netbsd/libc/gen/popen.c b/libc/upstream-netbsd/lib/libc/gen/popen.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/popen.c
rename to libc/upstream-netbsd/lib/libc/gen/popen.c
diff --git a/libc/upstream-netbsd/libc/gen/psignal.c b/libc/upstream-netbsd/lib/libc/gen/psignal.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/psignal.c
rename to libc/upstream-netbsd/lib/libc/gen/psignal.c
diff --git a/libc/upstream-netbsd/libc/gen/utime.c b/libc/upstream-netbsd/lib/libc/gen/utime.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/utime.c
rename to libc/upstream-netbsd/lib/libc/gen/utime.c
diff --git a/libc/upstream-netbsd/lib/libc/gen/utmp.c b/libc/upstream-netbsd/lib/libc/gen/utmp.c
new file mode 100644
index 0000000..9fb0799
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/gen/utmp.c
@@ -0,0 +1,106 @@
+/*	$NetBSD: utmp.c,v 1.10 2011/10/15 23:00:02 christos Exp $	 */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: utmp.c,v 1.10 2011/10/15 23:00:02 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/param.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <utmp.h>
+#include <sys/stat.h>
+
+static struct utmp utmp;
+static FILE *ut;
+static char utfile[MAXPATHLEN] = _PATH_UTMP;
+
+void
+setutent(void)
+{
+	if (ut == NULL)
+		return;
+	(void)fseeko(ut, (off_t)0, SEEK_SET);
+}
+
+struct utmp *
+getutent(void)
+{
+	if (ut == NULL) {
+		struct stat st;
+		off_t numentries;
+		if ((ut = fopen(utfile, "re")) == NULL)
+			return NULL;
+		if (fstat(fileno(ut), &st) == -1)
+			goto out;
+		/*
+		 * If we have a an old version utmp file bail.
+		 */
+		numentries = st.st_size / sizeof(utmp);
+		if ((off_t)(numentries * sizeof(utmp)) != st.st_size)
+			goto out;
+	}
+	if (fread(&utmp, sizeof(utmp), 1, ut) == 1)
+		return &utmp;
+out:
+	(void)fclose(ut);
+	return NULL;
+}
+
+void
+endutent(void)
+{
+	if (ut != NULL) {
+		(void)fclose(ut);
+		ut = NULL;
+	}
+}
+
+int
+utmpname(const char *fname)
+{
+	size_t len = strlen(fname);
+
+	if (len >= sizeof(utfile))
+		return 0;
+
+	/* must not end in x! */
+	if (fname[len - 1] == 'x')
+		return 0;
+
+	(void)strlcpy(utfile, fname, sizeof(utfile));
+	endutent();
+	return 1;
+}
diff --git a/libc/upstream-netbsd/libc/include/isc/assertions.h b/libc/upstream-netbsd/lib/libc/include/isc/assertions.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/assertions.h
rename to libc/upstream-netbsd/lib/libc/include/isc/assertions.h
diff --git a/libc/upstream-netbsd/libc/include/isc/dst.h b/libc/upstream-netbsd/lib/libc/include/isc/dst.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/dst.h
rename to libc/upstream-netbsd/lib/libc/include/isc/dst.h
diff --git a/libc/upstream-netbsd/libc/include/isc/eventlib.h b/libc/upstream-netbsd/lib/libc/include/isc/eventlib.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/eventlib.h
rename to libc/upstream-netbsd/lib/libc/include/isc/eventlib.h
diff --git a/libc/upstream-netbsd/libc/include/isc/heap.h b/libc/upstream-netbsd/lib/libc/include/isc/heap.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/heap.h
rename to libc/upstream-netbsd/lib/libc/include/isc/heap.h
diff --git a/libc/upstream-netbsd/libc/include/isc/list.h b/libc/upstream-netbsd/lib/libc/include/isc/list.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/list.h
rename to libc/upstream-netbsd/lib/libc/include/isc/list.h
diff --git a/libc/upstream-netbsd/libc/include/isc/memcluster.h b/libc/upstream-netbsd/lib/libc/include/isc/memcluster.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/memcluster.h
rename to libc/upstream-netbsd/lib/libc/include/isc/memcluster.h
diff --git a/libc/upstream-netbsd/lib/libc/include/resolv_mt.h b/libc/upstream-netbsd/lib/libc/include/resolv_mt.h
new file mode 100644
index 0000000..73a8dcc
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/include/resolv_mt.h
@@ -0,0 +1,49 @@
+/*	$NetBSD: resolv_mt.h,v 1.1.1.3 2009/04/12 16:35:44 christos Exp $	*/
+
+#ifndef _RESOLV_MT_H
+#define _RESOLV_MT_H
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+
+/* Access functions for the libresolv private interface */
+
+int	__res_enable_mt(void);
+int	__res_disable_mt(void);
+
+/* Per-thread context */
+
+typedef struct {
+int	no_hosts_fallback_private;
+int	retry_save;
+int	retry_private;
+char	inet_nsap_ntoa_tmpbuf[255*3];
+char	sym_ntos_unname[20];
+char	sym_ntop_unname[20];
+char	p_option_nbuf[40];
+char	p_time_nbuf[40];
+char	precsize_ntoa_retbuf[sizeof "90000000.00"];
+char	loc_ntoa_tmpbuf[sizeof
+"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
+char	p_secstodate_output[15];
+} mtctxres_t;
+
+/* Thread-specific data (TSD) */
+
+mtctxres_t	*___mtctxres(void);
+#define mtctxres	(___mtctxres())
+
+/* Various static data that should be TSD */
+
+#define sym_ntos_unname		(mtctxres->sym_ntos_unname)
+#define sym_ntop_unname		(mtctxres->sym_ntop_unname)
+#define inet_nsap_ntoa_tmpbuf	(mtctxres->inet_nsap_ntoa_tmpbuf)
+#define p_option_nbuf		(mtctxres->p_option_nbuf)
+#define p_time_nbuf		(mtctxres->p_time_nbuf)
+#define precsize_ntoa_retbuf	(mtctxres->precsize_ntoa_retbuf)
+#define loc_ntoa_tmpbuf		(mtctxres->loc_ntoa_tmpbuf)
+#define p_secstodate_output	(mtctxres->p_secstodate_output)
+
+#endif /* _RESOLV_MT_H */
diff --git a/libc/upstream-netbsd/lib/libc/inet/nsap_addr.c b/libc/upstream-netbsd/lib/libc/inet/nsap_addr.c
new file mode 100644
index 0000000..8633205
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/inet/nsap_addr.c
@@ -0,0 +1,130 @@
+/*	$NetBSD: nsap_addr.c,v 1.6 2009/04/12 17:07:17 christos Exp $	*/
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static const char rcsid[] = "Id: nsap_addr.c,v 1.5 2005/07/28 06:51:48 marka Exp";
+#else
+__RCSID("$NetBSD: nsap_addr.c,v 1.6 2009/04/12 17:07:17 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "port_before.h"
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <resolv_mt.h>
+
+#include "port_after.h"
+
+#ifdef __weak_alias
+__weak_alias(inet_nsap_addr,_inet_nsap_addr)
+__weak_alias(inet_nsap_ntoa,_inet_nsap_ntoa)
+#endif
+
+static char
+xtob(int c) {
+	return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
+}
+
+u_int
+inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) {
+	u_char c, nib;
+	u_int len = 0;
+
+	_DIAGASSERT(ascii != NULL);
+	_DIAGASSERT(binary != NULL);
+
+	if (ascii[0] != '0' || (ascii[1] != 'x' && ascii[1] != 'X'))
+		return (0);
+	ascii += 2;
+
+	while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
+		if (c == '.' || c == '+' || c == '/')
+			continue;
+		if (!isascii(c))
+			return (0);
+		if (islower(c))
+			c = toupper(c);
+		if (isxdigit(c)) {
+			nib = xtob(c);
+			c = *ascii++;
+			if (c != '\0') {
+				c = toupper(c);
+				if (isxdigit(c)) {
+					*binary++ = (nib << 4) | xtob(c);
+					len++;
+				} else
+					return (0);
+			}
+			else
+				return (0);
+		}
+		else
+			return (0);
+	}
+	return (len);
+}
+
+char *
+inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) {
+	int nib;
+	int i;
+	char *tmpbuf = inet_nsap_ntoa_tmpbuf;
+	char *start;
+
+	_DIAGASSERT(binary != NULL);
+
+	if (ascii)
+		start = ascii;
+	else {
+		ascii = tmpbuf;
+		start = tmpbuf;
+	}
+
+	*ascii++ = '0';
+	*ascii++ = 'x';
+
+	if (binlen > 255)
+		binlen = 255;
+
+	for (i = 0; i < binlen; i++) {
+		nib = (u_int32_t)*binary >> 4;
+		*ascii++ = nib + (nib < 10 ? '0' : '7');
+		nib = *binary++ & 0x0f;
+		*ascii++ = nib + (nib < 10 ? '0' : '7');
+		if (((i % 2) == 0 && (i + 1) < binlen))
+			*ascii++ = '.';
+	}
+	*ascii = '\0';
+	return (start);
+}
+
+/*! \file */
diff --git a/libc/upstream-netbsd/libc/isc/ev_streams.c b/libc/upstream-netbsd/lib/libc/isc/ev_streams.c
similarity index 100%
rename from libc/upstream-netbsd/libc/isc/ev_streams.c
rename to libc/upstream-netbsd/lib/libc/isc/ev_streams.c
diff --git a/libc/upstream-netbsd/libc/isc/ev_timers.c b/libc/upstream-netbsd/lib/libc/isc/ev_timers.c
similarity index 100%
rename from libc/upstream-netbsd/libc/isc/ev_timers.c
rename to libc/upstream-netbsd/lib/libc/isc/ev_timers.c
diff --git a/libc/upstream-netbsd/libc/isc/eventlib_p.h b/libc/upstream-netbsd/lib/libc/isc/eventlib_p.h
similarity index 100%
rename from libc/upstream-netbsd/libc/isc/eventlib_p.h
rename to libc/upstream-netbsd/lib/libc/isc/eventlib_p.h
diff --git a/libc/upstream-netbsd/libc/regex/cclass.h b/libc/upstream-netbsd/lib/libc/regex/cclass.h
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/cclass.h
rename to libc/upstream-netbsd/lib/libc/regex/cclass.h
diff --git a/libc/upstream-netbsd/libc/regex/cname.h b/libc/upstream-netbsd/lib/libc/regex/cname.h
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/cname.h
rename to libc/upstream-netbsd/lib/libc/regex/cname.h
diff --git a/libc/upstream-netbsd/libc/regex/engine.c b/libc/upstream-netbsd/lib/libc/regex/engine.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/engine.c
rename to libc/upstream-netbsd/lib/libc/regex/engine.c
diff --git a/libc/upstream-netbsd/libc/regex/regcomp.c b/libc/upstream-netbsd/lib/libc/regex/regcomp.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regcomp.c
rename to libc/upstream-netbsd/lib/libc/regex/regcomp.c
diff --git a/libc/upstream-netbsd/libc/regex/regerror.c b/libc/upstream-netbsd/lib/libc/regex/regerror.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regerror.c
rename to libc/upstream-netbsd/lib/libc/regex/regerror.c
diff --git a/libc/upstream-netbsd/libc/regex/regex2.h b/libc/upstream-netbsd/lib/libc/regex/regex2.h
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regex2.h
rename to libc/upstream-netbsd/lib/libc/regex/regex2.h
diff --git a/libc/upstream-netbsd/libc/regex/regexec.c b/libc/upstream-netbsd/lib/libc/regex/regexec.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regexec.c
rename to libc/upstream-netbsd/lib/libc/regex/regexec.c
diff --git a/libc/upstream-netbsd/libc/regex/regfree.c b/libc/upstream-netbsd/lib/libc/regex/regfree.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regfree.c
rename to libc/upstream-netbsd/lib/libc/regex/regfree.c
diff --git a/libc/upstream-netbsd/libc/regex/utils.h b/libc/upstream-netbsd/lib/libc/regex/utils.h
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/utils.h
rename to libc/upstream-netbsd/lib/libc/regex/utils.h
diff --git a/libc/upstream-netbsd/lib/libc/resolv/mtctxres.c b/libc/upstream-netbsd/lib/libc/resolv/mtctxres.c
new file mode 100644
index 0000000..6e3281a
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/resolv/mtctxres.c
@@ -0,0 +1,130 @@
+/*	$NetBSD: mtctxres.c,v 1.4 2007/03/30 20:40:52 ghen Exp $	*/
+
+#include <port_before.h>
+#ifdef DO_PTHREADS
+#include <pthread.h>
+#endif
+#include <errno.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
+#include <resolv_mt.h>
+#include <port_after.h>
+
+#ifdef DO_PTHREADS
+static pthread_key_t	key;
+static int		mt_key_initialized = 0;
+
+static int		__res_init_ctx(void);
+static void		__res_destroy_ctx(void *);
+
+#if defined(sun) && !defined(__GNUC__)
+#pragma init	(_mtctxres_init)
+#endif
+#endif
+
+static mtctxres_t	sharedctx;
+
+#ifdef DO_PTHREADS
+/*
+ * Initialize the TSD key. By doing this at library load time, we're
+ * implicitly running without interference from other threads, so there's
+ * no need for locking.
+ */
+static void
+_mtctxres_init(void) {
+	int pthread_keycreate_ret;
+
+	pthread_keycreate_ret = pthread_key_create(&key, __res_destroy_ctx);
+	if (pthread_keycreate_ret == 0)
+		mt_key_initialized = 1;
+}
+#endif
+
+/*
+ * To support binaries that used the private MT-safe interface in
+ * Solaris 8, we still need to provide the __res_enable_mt()
+ * and __res_disable_mt() entry points. They're do-nothing routines.
+ */
+int
+__res_enable_mt(void) {
+	return (-1);
+}
+
+int
+__res_disable_mt(void) {
+	return (0);
+}
+
+#ifdef DO_PTHREADS
+static int
+__res_init_ctx(void) {
+
+	mtctxres_t	*mt;
+	int		ret;
+
+
+	if (pthread_getspecific(key) != 0) {
+		/* Already exists */
+		return (0);
+	}
+
+	if ((mt = malloc(sizeof (mtctxres_t))) == 0) {
+		errno = ENOMEM;
+		return (-1);
+	}
+
+	memset(mt, 0, sizeof (mtctxres_t));
+
+	if ((ret = pthread_setspecific(key, mt)) != 0) {
+		free(mt);
+		errno = ret;
+		return (-1);
+	}
+
+	return (0);
+}
+
+static void
+__res_destroy_ctx(void *value) {
+
+	mtctxres_t	*mt = (mtctxres_t *)value;
+
+	if (mt != 0)
+		free(mt);
+}
+#endif
+
+mtctxres_t *
+___mtctxres(void) {
+#ifdef DO_PTHREADS
+	mtctxres_t	*mt;
+
+	/*
+	 * This if clause should only be executed if we are linking
+	 * statically.  When linked dynamically _mtctxres_init() should
+	 * be called at binding time due the #pragma above.
+	 */
+	if (!mt_key_initialized) {
+		static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
+                if (pthread_mutex_lock(&keylock) == 0) {
+			_mtctxres_init();
+			(void) pthread_mutex_unlock(&keylock);
+		}
+	}
+
+	/*
+	 * If we have already been called in this thread return the existing
+	 * context.  Otherwise recreat a new context and return it.  If
+	 * that fails return a global context.
+	 */
+	if (mt_key_initialized) {
+		if (((mt = pthread_getspecific(key)) != 0) ||
+		    (__res_init_ctx() == 0 &&
+		     (mt = pthread_getspecific(key)) != 0)) {
+			return (mt);
+		}
+	}
+#endif
+	return (&sharedctx);
+}
diff --git a/libc/upstream-netbsd/libc/stdlib/_rand48.c b/libc/upstream-netbsd/lib/libc/stdlib/_rand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/_rand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/_rand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/bsearch.c b/libc/upstream-netbsd/lib/libc/stdlib/bsearch.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/bsearch.c
rename to libc/upstream-netbsd/lib/libc/stdlib/bsearch.c
diff --git a/libc/upstream-netbsd/libc/stdlib/div.c b/libc/upstream-netbsd/lib/libc/stdlib/div.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/div.c
rename to libc/upstream-netbsd/lib/libc/stdlib/div.c
diff --git a/libc/upstream-netbsd/libc/stdlib/drand48.c b/libc/upstream-netbsd/lib/libc/stdlib/drand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/drand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/drand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/erand48.c b/libc/upstream-netbsd/lib/libc/stdlib/erand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/erand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/erand48.c
diff --git a/libc/upstream-netbsd/lib/libc/stdlib/insque.c b/libc/upstream-netbsd/lib/libc/stdlib/insque.c
new file mode 100644
index 0000000..09020ae
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/stdlib/insque.c
@@ -0,0 +1,58 @@
+/*
+ *  Copyright (c) 1993 John Brezak
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *  3. The name of the author may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: insque.c,v 1.3 2012/06/25 22:32:45 abs Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <search.h>
+
+struct qelem {
+        struct qelem *q_forw;
+        struct qelem *q_back;
+};
+
+void
+insque(void *entry, void *pred)
+{
+	struct qelem *e = (struct qelem *) entry;
+	struct qelem *p = (struct qelem *) pred;
+
+	_DIAGASSERT(e != 0);
+
+	e->q_back = p;
+	if (p) {
+		e->q_forw = p->q_forw;
+		if (p->q_forw)
+			p->q_forw->q_back = e;
+		p->q_forw = e;
+	} else
+		e->q_forw = 0;
+}
diff --git a/libc/upstream-netbsd/libc/stdlib/jrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/jrand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/jrand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/jrand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/ldiv.c b/libc/upstream-netbsd/lib/libc/stdlib/ldiv.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/ldiv.c
rename to libc/upstream-netbsd/lib/libc/stdlib/ldiv.c
diff --git a/libc/upstream-netbsd/libc/stdlib/lldiv.c b/libc/upstream-netbsd/lib/libc/stdlib/lldiv.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/lldiv.c
rename to libc/upstream-netbsd/lib/libc/stdlib/lldiv.c
diff --git a/libc/upstream-netbsd/libc/stdlib/lrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/lrand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/lrand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/lrand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/mrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/mrand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/mrand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/mrand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/nrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/nrand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/nrand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/nrand48.c
diff --git a/libc/upstream-netbsd/lib/libc/stdlib/rand_r.c b/libc/upstream-netbsd/lib/libc/stdlib/rand_r.c
new file mode 100644
index 0000000..272b2bd
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/stdlib/rand_r.c
@@ -0,0 +1,51 @@
+/*	$NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char *sccsid = "from: @(#)rand.c	5.6 (Berkeley) 6/24/91";
+#else
+__RCSID("$NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+
+int
+rand_r(unsigned int *seed)
+{
+	_DIAGASSERT(seed != NULL);
+
+	return ((*seed = *seed * 1103515245 + 12345) & RAND_MAX);
+}
diff --git a/libc/upstream-netbsd/lib/libc/stdlib/remque.c b/libc/upstream-netbsd/lib/libc/stdlib/remque.c
new file mode 100644
index 0000000..6060ad8
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/stdlib/remque.c
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (c) 1993 John Brezak
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *  3. The name of the author may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: remque.c,v 1.3 2012/06/25 22:32:45 abs Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <search.h>
+
+struct qelem {
+        struct qelem *q_forw;
+        struct qelem *q_back;
+};
+
+void
+remque(void *element)
+{
+	struct qelem *e = (struct qelem *) element;
+
+	_DIAGASSERT(e != 0);
+
+	if (e->q_forw)
+		e->q_forw->q_back = e->q_back;
+	if (e->q_back)
+		e->q_back->q_forw = e->q_forw;
+}
diff --git a/libc/upstream-netbsd/libc/stdlib/seed48.c b/libc/upstream-netbsd/lib/libc/stdlib/seed48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/seed48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/seed48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/srand48.c b/libc/upstream-netbsd/lib/libc/stdlib/srand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/srand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/srand48.c
diff --git a/libc/upstream-netbsd/libc/string/memccpy.c b/libc/upstream-netbsd/lib/libc/string/memccpy.c
similarity index 100%
rename from libc/upstream-netbsd/libc/string/memccpy.c
rename to libc/upstream-netbsd/lib/libc/string/memccpy.c
diff --git a/libc/upstream-netbsd/libc/string/strcasestr.c b/libc/upstream-netbsd/lib/libc/string/strcasestr.c
similarity index 100%
rename from libc/upstream-netbsd/libc/string/strcasestr.c
rename to libc/upstream-netbsd/lib/libc/string/strcasestr.c
diff --git a/libc/upstream-netbsd/libc/string/strcoll.c b/libc/upstream-netbsd/lib/libc/string/strcoll.c
similarity index 100%
rename from libc/upstream-netbsd/libc/string/strcoll.c
rename to libc/upstream-netbsd/lib/libc/string/strcoll.c
diff --git a/libc/upstream-netbsd/libc/string/strxfrm.c b/libc/upstream-netbsd/lib/libc/string/strxfrm.c
similarity index 100%
rename from libc/upstream-netbsd/libc/string/strxfrm.c
rename to libc/upstream-netbsd/lib/libc/string/strxfrm.c
diff --git a/libc/upstream-netbsd/libc/unistd/killpg.c b/libc/upstream-netbsd/lib/libc/unistd/killpg.c
similarity index 100%
rename from libc/upstream-netbsd/libc/unistd/killpg.c
rename to libc/upstream-netbsd/lib/libc/unistd/killpg.c
diff --git a/libc/upstream-netbsd/libc/compat-43/creat.c b/libc/upstream-netbsd/libc/compat-43/creat.c
deleted file mode 100644
index 9560bea..0000000
--- a/libc/upstream-netbsd/libc/compat-43/creat.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*	$NetBSD: creat.c,v 1.10 2003/08/07 16:42:39 agc Exp $	*/
-
-/*
- * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)creat.c	8.1 (Berkeley) 6/2/93";
-#else
-__RCSID("$NetBSD: creat.c,v 1.10 2003/08/07 16:42:39 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-
-int
-creat(const char *path, mode_t mode)
-{
-
-	_DIAGASSERT(path != NULL);
-
-	return(open(path, O_WRONLY|O_CREAT|O_TRUNC, mode));
-}
diff --git a/libc/upstream-netbsd/libc/gen/setjmperr.c b/libc/upstream-netbsd/libc/gen/setjmperr.c
deleted file mode 100644
index 5b1432e..0000000
--- a/libc/upstream-netbsd/libc/gen/setjmperr.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*	$NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $	*/
-
-/*
- * Copyright (c) 1980, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)setjmperr.c	8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * This routine is called from longjmp() when an error occurs.
- * Programs that wish to exit gracefully from this error may
- * write their own versions.
- * If this routine returns, the program is aborted.
- */
-
-#include <setjmp.h>
-#include <unistd.h>
-
-void
-longjmperror(void)
-{
-#define	ERRMSG	"longjmp botch.\n"
-	(void)write(STDERR_FILENO, ERRMSG, sizeof(ERRMSG) - 1);
-}
diff --git a/libc/upstream-netbsd/libc/inet/inet_ntoa.c b/libc/upstream-netbsd/libc/inet/inet_ntoa.c
deleted file mode 100644
index 6ed023b..0000000
--- a/libc/upstream-netbsd/libc/inet/inet_ntoa.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*	$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $	*/
-
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)inet_ntoa.c	8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef __weak_alias
-__weak_alias(inet_ntoa,_inet_ntoa)
-#endif
-
-/*
- * Convert network-format internet address
- * to base 256 d.d.d.d representation.
- */
-/*const*/ char *
-inet_ntoa(struct in_addr in) {
-	static char ret[18];
-
-	strlcpy(ret, "[inet_ntoa error]", sizeof(ret));
-	(void) inet_ntop(AF_INET, &in, ret, (socklen_t)sizeof ret);
-	return ret;
-}
diff --git a/libc/upstream-netbsd/libc/inet/inet_ntop.c b/libc/upstream-netbsd/libc/inet/inet_ntop.c
deleted file mode 100644
index 00c55a8..0000000
--- a/libc/upstream-netbsd/libc/inet/inet_ntop.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*	$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp";
-#else
-__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include "namespace.h"
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "port_after.h"
-
-#ifdef __weak_alias
-__weak_alias(inet_ntop,_inet_ntop)
-#endif
-
-/*%
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size);
-static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);
-
-/* char *
- * inet_ntop(af, src, dst, size)
- *	convert a network format address to presentation format.
- * return:
- *	pointer to presentation format address (`dst'), or NULL (see errno).
- * author:
- *	Paul Vixie, 1996.
- */
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size)
-{
-
-	_DIAGASSERT(src != NULL);
-	_DIAGASSERT(dst != NULL);
-
-	switch (af) {
-	case AF_INET:
-		return (inet_ntop4(src, dst, size));
-	case AF_INET6:
-		return (inet_ntop6(src, dst, size));
-	default:
-		errno = EAFNOSUPPORT;
-		return (NULL);
-	}
-	/* NOTREACHED */
-}
-
-/* const char *
- * inet_ntop4(src, dst, size)
- *	format an IPv4 address, more or less like inet_ntoa()
- * return:
- *	`dst' (as a const)
- * notes:
- *	(1) uses no statics
- *	(2) takes a u_char* not an in_addr as input
- * author:
- *	Paul Vixie, 1996.
- */
-static const char *
-inet_ntop4(const u_char *src, char *dst, socklen_t size)
-{
-	char tmp[sizeof "255.255.255.255"];
-	int l;
-
-	_DIAGASSERT(src != NULL);
-	_DIAGASSERT(dst != NULL);
-
-	l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u",
-	    src[0], src[1], src[2], src[3]);
-	if (l <= 0 || (socklen_t) l >= size) {
-		errno = ENOSPC;
-		return (NULL);
-	}
-	strlcpy(dst, tmp, size);
-	return (dst);
-}
-
-/* const char *
- * inet_ntop6(src, dst, size)
- *	convert IPv6 binary address into presentation (printable) format
- * author:
- *	Paul Vixie, 1996.
- */
-static const char *
-inet_ntop6(const u_char *src, char *dst, socklen_t size)
-{
-	/*
-	 * Note that int32_t and int16_t need only be "at least" large enough
-	 * to contain a value of the specified size.  On some systems, like
-	 * Crays, there is no such thing as an integer variable with 16 bits.
-	 * Keep this in mind if you think this function should have been coded
-	 * to use pointer overlays.  All the world's not a VAX.
-	 */
-	char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
-	char *tp, *ep;
-	struct { int base, len; } best, cur;
-	u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
-	int i;
-	int advance;
-
-	_DIAGASSERT(src != NULL);
-	_DIAGASSERT(dst != NULL);
-
-	/*
-	 * Preprocess:
-	 *	Copy the input (bytewise) array into a wordwise array.
-	 *	Find the longest run of 0x00's in src[] for :: shorthanding.
-	 */
-	memset(words, '\0', sizeof words);
-	for (i = 0; i < NS_IN6ADDRSZ; i++)
-		words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
-	best.base = -1;
-	best.len = 0;
-	cur.base = -1;
-	cur.len = 0;
-	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
-		if (words[i] == 0) {
-			if (cur.base == -1)
-				cur.base = i, cur.len = 1;
-			else
-				cur.len++;
-		} else {
-			if (cur.base != -1) {
-				if (best.base == -1 || cur.len > best.len)
-					best = cur;
-				cur.base = -1;
-			}
-		}
-	}
-	if (cur.base != -1) {
-		if (best.base == -1 || cur.len > best.len)
-			best = cur;
-	}
-	if (best.base != -1 && best.len < 2)
-		best.base = -1;
-
-	/*
-	 * Format the result.
-	 */
-	tp = tmp;
-	ep = tmp + sizeof(tmp);
-	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
-		/* Are we inside the best run of 0x00's? */
-		if (best.base != -1 && i >= best.base &&
-		    i < (best.base + best.len)) {
-			if (i == best.base)
-				*tp++ = ':';
-			continue;
-		}
-		/* Are we following an initial run of 0x00s or any real hex? */
-		if (i != 0) {
-			if (tp + 1 >= ep)
-				return (NULL);
-			*tp++ = ':';
-		}
-		/* Is this address an encapsulated IPv4? */
-		if (i == 6 && best.base == 0 &&
-		    (best.len == 6 ||
-		    (best.len == 7 && words[7] != 0x0001) ||
-		    (best.len == 5 && words[5] == 0xffff))) {
-			if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
-				return (NULL);
-			tp += strlen(tp);
-			break;
-		}
-		advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
-		if (advance <= 0 || advance >= ep - tp)
-			return (NULL);
-		tp += advance;
-	}
-	/* Was it a trailing run of 0x00's? */
-	if (best.base != -1 && (best.base + best.len) == 
-	    (NS_IN6ADDRSZ / NS_INT16SZ)) {
-		if (tp + 1 >= ep)
-			return (NULL);
-		*tp++ = ':';
-	}
-	if (tp + 1 >= ep)
-		return (NULL);
-	*tp++ = '\0';
-
-	/*
-	 * Check for overflow, copy, and we're done.
-	 */
-	if ((size_t)(tp - tmp) > size) {
-		errno = ENOSPC;
-		return (NULL);
-	}
-	strlcpy(dst, tmp, size);
-	return (dst);
-}
-
-/*! \file */
diff --git a/libc/upstream-netbsd/libc/inet/inet_pton.c b/libc/upstream-netbsd/libc/inet/inet_pton.c
deleted file mode 100644
index c1e9a69..0000000
--- a/libc/upstream-netbsd/libc/inet/inet_pton.c
+++ /dev/null
@@ -1,310 +0,0 @@
-/*	$NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $	*/
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and 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 ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static const char rcsid[] = "Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp";
-#else
-__RCSID("$NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include "namespace.h"
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <stddef.h>
-#include <string.h>
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-
-#include "port_after.h"
-
-#ifdef __weak_alias
-__weak_alias(inet_pton,_inet_pton)
-#endif
-
-/*%
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static int	inet_pton4(const char *src, u_char *dst, int pton);
-static int	inet_pton6(const char *src, u_char *dst);
-
-/* int
- * inet_pton(af, src, dst)
- *	convert from presentation format (which usually means ASCII printable)
- *	to network format (which is usually some kind of binary format).
- * return:
- *	1 if the address was valid for the specified address family
- *	0 if the address wasn't valid (`dst' is untouched in this case)
- *	-1 if some other error occurred (`dst' is untouched in this case, too)
- * author:
- *	Paul Vixie, 1996.
- */
-int
-inet_pton(int af, const char *src, void *dst)
-{
-
-	_DIAGASSERT(src != NULL);
-	_DIAGASSERT(dst != NULL);
-
-	switch (af) {
-	case AF_INET:
-		return (inet_pton4(src, dst, 1));
-	case AF_INET6:
-		return (inet_pton6(src, dst));
-	default:
-		errno = EAFNOSUPPORT;
-		return (-1);
-	}
-	/* NOTREACHED */
-}
-
-/* int
- * inet_pton4(src, dst, pton)
- *	when last arg is 0: inet_aton(). with hexadecimal, octal and shorthand.
- *	when last arg is 1: inet_pton(). decimal dotted-quad only.
- * return:
- *	1 if `src' is a valid input, else 0.
- * notice:
- *	does not touch `dst' unless it's returning 1.
- * author:
- *	Paul Vixie, 1996.
- */
-static int
-inet_pton4(const char *src, u_char *dst, int pton)
-{
-	u_int32_t val;
-	u_int digit, base;
-	ptrdiff_t n;
-	unsigned char c;
-	u_int parts[4];
-	u_int *pp = parts;
-
-	_DIAGASSERT(src != NULL);
-	_DIAGASSERT(dst != NULL);
-
-	c = *src;
-	for (;;) {
-		/*
-		 * Collect number up to ``.''.
-		 * Values are specified as for C:
-		 * 0x=hex, 0=octal, isdigit=decimal.
-		 */
-		if (!isdigit(c))
-			return (0);
-		val = 0; base = 10;
-		if (c == '0') {
-			c = *++src;
-			if (c == 'x' || c == 'X')
-				base = 16, c = *++src;
-			else if (isdigit(c) && c != '9')
-				base = 8;
-		}
-		/* inet_pton() takes decimal only */
-		if (pton && base != 10)
-			return (0);
-		for (;;) {
-			if (isdigit(c)) {
-				digit = c - '0';
-				if (digit >= base)
-					break;
-				val = (val * base) + digit;
-				c = *++src;
-			} else if (base == 16 && isxdigit(c)) {
-				digit = c + 10 - (islower(c) ? 'a' : 'A');
-				if (digit >= 16)
-					break;
-				val = (val << 4) | digit;
-				c = *++src;
-			} else
-				break;
-		}
-		if (c == '.') {
-			/*
-			 * Internet format:
-			 *	a.b.c.d
-			 *	a.b.c	(with c treated as 16 bits)
-			 *	a.b	(with b treated as 24 bits)
-			 *	a	(with a treated as 32 bits)
-			 */
-			if (pp >= parts + 3)
-				return (0);
-			*pp++ = val;
-			c = *++src;
-		} else
-			break;
-	}
-	/*
-	 * Check for trailing characters.
-	 */
-	if (c != '\0' && !isspace(c))
-		return (0);
-	/*
-	 * Concoct the address according to
-	 * the number of parts specified.
-	 */
-	n = pp - parts + 1;
-	/* inet_pton() takes dotted-quad only.  it does not take shorthand. */
-	if (pton && n != 4)
-		return (0);
-	switch (n) {
-
-	case 0:
-		return (0);		/* initial nondigit */
-
-	case 1:				/* a -- 32 bits */
-		break;
-
-	case 2:				/* a.b -- 8.24 bits */
-		if (parts[0] > 0xff || val > 0xffffff)
-			return (0);
-		val |= parts[0] << 24;
-		break;
-
-	case 3:				/* a.b.c -- 8.8.16 bits */
-		if ((parts[0] | parts[1]) > 0xff || val > 0xffff)
-			return (0);
-		val |= (parts[0] << 24) | (parts[1] << 16);
-		break;
-
-	case 4:				/* a.b.c.d -- 8.8.8.8 bits */
-		if ((parts[0] | parts[1] | parts[2] | val) > 0xff)
-			return (0);
-		val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
-		break;
-	}
-	if (dst) {
-		val = htonl(val);
-		memcpy(dst, &val, NS_INADDRSZ);
-	}
-	return (1);
-}
-
-/* int
- * inet_pton6(src, dst)
- *	convert presentation level address to network order binary form.
- * return:
- *	1 if `src' is a valid [RFC1884 2.2] address, else 0.
- * notice:
- *	(1) does not touch `dst' unless it's returning 1.
- *	(2) :: in a full address is silently ignored.
- * credit:
- *	inspired by Mark Andrews.
- * author:
- *	Paul Vixie, 1996.
- */
-static int
-inet_pton6(const char *src, u_char *dst)
-{
-	static const char xdigits_l[] = "0123456789abcdef",
-			  xdigits_u[] = "0123456789ABCDEF";
-	u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
-	const char *xdigits, *curtok;
-	int ch, seen_xdigits;
-	u_int val;
-
-	_DIAGASSERT(src != NULL);
-	_DIAGASSERT(dst != NULL);
-
-	memset((tp = tmp), '\0', NS_IN6ADDRSZ);
-	endp = tp + NS_IN6ADDRSZ;
-	colonp = NULL;
-	/* Leading :: requires some special handling. */
-	if (*src == ':')
-		if (*++src != ':')
-			return (0);
-	curtok = src;
-	seen_xdigits = 0;
-	val = 0;
-	while ((ch = *src++) != '\0') {
-		const char *pch;
-
-		if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
-			pch = strchr((xdigits = xdigits_u), ch);
-		if (pch != NULL) {
-			val <<= 4;
-			val |= (int)(pch - xdigits);
-			if (++seen_xdigits > 4)
-				return (0);
-			continue;
-		}
-		if (ch == ':') {
-			curtok = src;
-			if (!seen_xdigits) {
-				if (colonp)
-					return (0);
-				colonp = tp;
-				continue;
-			} else if (*src == '\0')
-				return (0);
-			if (tp + NS_INT16SZ > endp)
-				return (0);
-			*tp++ = (u_char) (val >> 8) & 0xff;
-			*tp++ = (u_char) val & 0xff;
-			seen_xdigits = 0;
-			val = 0;
-			continue;
-		}
-		if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
-		    inet_pton4(curtok, tp, 1) > 0) {
-			tp += NS_INADDRSZ;
-			seen_xdigits = 0;
-			break;	/*%< '\\0' was seen by inet_pton4(). */
-		}
-		return (0);
-	}
-	if (seen_xdigits) {
-		if (tp + NS_INT16SZ > endp)
-			return (0);
-		*tp++ = (u_char) (val >> 8) & 0xff;
-		*tp++ = (u_char) val & 0xff;
-	}
-	if (colonp != NULL) {
-		/*
-		 * Since some memmove()'s erroneously fail to handle
-		 * overlapping regions, we'll do the shift by hand.
-		 */
-		const ptrdiff_t n = tp - colonp;
-		int i;
-
-		if (tp == endp)
-			return (0);
-		for (i = 1; i <= n; i++) {
-			endp[- i] = colonp[n - i];
-			colonp[n - i] = 0;
-		}
-		tp = endp;
-	}
-	if (tp != endp)
-		return (0);
-	memcpy(dst, tmp, NS_IN6ADDRSZ);
-	return (1);
-}
-
-/*! \file */
diff --git a/libc/upstream-netbsd/libc/stdio/getdelim.c b/libc/upstream-netbsd/libc/stdio/getdelim.c
deleted file mode 100644
index acce376..0000000
--- a/libc/upstream-netbsd/libc/stdio/getdelim.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */
-
-/*
- * Copyright (c) 2009 The NetBSD Foundation, Inc.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Roy Marples.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__RCSID("$NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $");
-
-#include "namespace.h"
-
-#include <sys/param.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "reentrant.h"
-#include "local.h"
-
-#ifdef __weak_alias
-__weak_alias(getdelim, _getdelim)
-#endif
-
-/* Minimum buffer size we create.
- * This should allow config files to fit into our power of 2 buffer growth
- * without the need for a realloc. */
-#define MINBUF	128
-
-ssize_t
-__getdelim(char **__restrict buf, size_t *__restrict buflen,
-    int sep, FILE *__restrict fp)
-{
-	unsigned char *p;
-	size_t len, newlen, off;
-	char *newb;
-
-	_DIAGASSERT(fp != NULL);
-
-	if (buf == NULL || buflen == NULL) {
-		errno = EINVAL;
-		goto error;
-	}
-
-	/* If buf is NULL, we have to assume a size of zero */
-	if (*buf == NULL)
-		*buflen = 0;
-
-	_SET_ORIENTATION(fp, -1);
-	off = 0;
-	do {
-		/* If the input buffer is empty, refill it */
-		if (fp->_r <= 0 && __srefill(fp)) {
-			if (__sferror(fp))
-				goto error;
-			/* No error, so EOF. */
-			break;
-		}
-
-		/* Scan through looking for the separator */
-		p = memchr(fp->_p, sep, (size_t)fp->_r);
-		if (p == NULL)
-			len = fp->_r;
-		else
-			len = (p - fp->_p) + 1;
-
-		newlen = off + len;
-		/* Ensure we can handle it */
-		if (newlen < off || newlen > SSIZE_MAX) {
-			errno = EOVERFLOW;
-			goto error;
-		}
-		newlen++; /* reserve space for the NULL terminator */
-		if (newlen > *buflen) {
-			if (newlen < MINBUF)
-				newlen = MINBUF;
-			if (!powerof2(newlen)) {
-				/* Grow the buffer to the next power of 2 */
-				newlen--;
-				newlen |= newlen >> 1;
-				newlen |= newlen >> 2;
-				newlen |= newlen >> 4;
-				newlen |= newlen >> 8;
-				newlen |= newlen >> 16;
-#if SIZE_T_MAX > 0xffffffffU
-				newlen |= newlen >> 32;
-#endif
-				newlen++;
-			}
-
-			newb = realloc(*buf, newlen);
-			if (newb == NULL)
-				goto error;
-			*buf = newb;
-			*buflen = newlen;
-		}
-
-		(void)memcpy((*buf + off), fp->_p, len);
-		/* Safe, len is never greater than what fp->_r can fit. */
-		fp->_r -= (int)len;
-		fp->_p += (int)len;
-		off += len;
-	} while (p == NULL);
-
-	/* POSIX demands we return -1 on EOF. */
-	if (off == 0) 
-		return -1;
-
-	if (*buf != NULL)
-		*(*buf + off) = '\0';
-	return off;
-
-error:
-	fp->_flags |= __SERR;
-	return -1;
-}
-
-ssize_t
-getdelim(char **__restrict buf, size_t *__restrict buflen,
-    int sep, FILE *__restrict fp)
-{
-	ssize_t n;
-
-	FLOCKFILE(fp);
-	n = __getdelim(buf, buflen, sep, fp);
-	FUNLOCKFILE(fp);
-	return n;
-}
diff --git a/libc/upstream-netbsd/libc/stdio/getline.c b/libc/upstream-netbsd/libc/stdio/getline.c
deleted file mode 100644
index e5d4bab..0000000
--- a/libc/upstream-netbsd/libc/stdio/getline.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* $NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $ */
-
-/*
- * Copyright (c) 2009 The NetBSD Foundation, Inc.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Roy Marples.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__RCSID("$NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $");
-
-#include "namespace.h"
-
-#include <stdio.h>
-
-#ifdef __weak_alias
-__weak_alias(getline, _getline)
-#endif
-
-ssize_t
-getline(char **__restrict buf, size_t *__restrict buflen, FILE *__restrict fp)
-{
-	return getdelim(buf, buflen, '\n', fp);
-}
diff --git a/libc/upstream-netbsd/libc/stdlib/exit.c b/libc/upstream-netbsd/libc/stdlib/exit.c
deleted file mode 100644
index 67e6adf..0000000
--- a/libc/upstream-netbsd/libc/stdlib/exit.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*	$NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)exit.c	8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include <stdlib.h>
-#include <unistd.h>
-#ifdef _LIBC
-#include "reentrant.h"
-#include "atexit.h"
-#endif
-
-void (*__cleanup)(void);
-
-/*
- * Exit, flushing stdio buffers if necessary.
- */
-void
-exit(int status)
-{
-
-#ifdef _LIBC
-	__cxa_finalize(NULL);
-#endif
-	if (__cleanup)
-		(*__cleanup)();
-	_exit(status);
-}
diff --git a/libc/upstream-netbsd/libc/stdlib/tdelete.c b/libc/upstream-netbsd/libc/stdlib/tdelete.c
deleted file mode 100644
index 84017dc..0000000
--- a/libc/upstream-netbsd/libc/stdlib/tdelete.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*	$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $	*/
-
-/*
- * Tree search generalized from Knuth (6.2.2) Algorithm T just like
- * the AT&T man page says.
- *
- * The node_t structure is for internal use only, lint doesn't grok it.
- *
- * Written by reading the System V Interface Definition, not the code.
- *
- * Totally public domain.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#include <assert.h>
-#define _SEARCH_PRIVATE
-#include <search.h>
-#include <stdlib.h>
-
-
-/* find a node with key "vkey" in tree "vrootp" */
-void *
-tdelete(const void *vkey, void **vrootp,
-    int (*compar)(const void *, const void *))
-{
-	node_t **rootp = (node_t **)vrootp;
-	node_t *p, *q, *r;
-	int  cmp;
-
-	_DIAGASSERT(vkey != NULL);
-	_DIAGASSERT(compar != NULL);
-
-	if (rootp == NULL || (p = *rootp) == NULL)
-		return NULL;
-
-	while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) {
-		p = *rootp;
-		rootp = (cmp < 0) ?
-		    &(*rootp)->llink :		/* follow llink branch */
-		    &(*rootp)->rlink;		/* follow rlink branch */
-		if (*rootp == NULL)
-			return NULL;		/* key not found */
-	}
-	r = (*rootp)->rlink;			/* D1: */
-	if ((q = (*rootp)->llink) == NULL)	/* Left NULL? */
-		q = r;
-	else if (r != NULL) {			/* Right link is NULL? */
-		if (r->llink == NULL) {		/* D2: Find successor */
-			r->llink = q;
-			q = r;
-		} else {			/* D3: Find NULL link */
-			for (q = r->llink; q->llink != NULL; q = r->llink)
-				r = q;
-			r->llink = q->rlink;
-			q->llink = (*rootp)->llink;
-			q->rlink = (*rootp)->rlink;
-		}
-	}
-	if (p != *rootp)
-		free(*rootp);			/* D4: Free node */
-	*rootp = q;				/* link parent to new node */
-	return p;
-}
diff --git a/libc/upstream-netbsd/libc/stdlib/tfind.c b/libc/upstream-netbsd/libc/stdlib/tfind.c
deleted file mode 100644
index fd3f362..0000000
--- a/libc/upstream-netbsd/libc/stdlib/tfind.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*	$NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $	*/
-
-/*
- * Tree search generalized from Knuth (6.2.2) Algorithm T just like
- * the AT&T man page says.
- *
- * The node_t structure is for internal use only, lint doesn't grok it.
- *
- * Written by reading the System V Interface Definition, not the code.
- *
- * Totally public domain.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#include <assert.h>
-#define _SEARCH_PRIVATE
-#include <stdlib.h>
-#include <search.h>
-
-/* find a node by key "vkey" in tree "vrootp", or return 0 */
-void *
-tfind(const void *vkey, void * const *vrootp,
-    int (*compar)(const void *, const void *))
-{
-	node_t * const *rootp = (node_t * const*)vrootp;
-
-	_DIAGASSERT(vkey != NULL);
-	_DIAGASSERT(compar != NULL);
-
-	if (rootp == NULL)
-		return NULL;
-
-	while (*rootp != NULL) {		/* T1: */
-		int r;
-
-		if ((r = (*compar)(vkey, (*rootp)->key)) == 0)	/* T2: */
-			return *rootp;		/* key found */
-		rootp = (r < 0) ?
-		    &(*rootp)->llink :		/* T3: follow left branch */
-		    &(*rootp)->rlink;		/* T4: follow right branch */
-	}
-	return NULL;
-}
diff --git a/libc/upstream-netbsd/libc/stdlib/tsearch.c b/libc/upstream-netbsd/libc/stdlib/tsearch.c
deleted file mode 100644
index af2fe9c..0000000
--- a/libc/upstream-netbsd/libc/stdlib/tsearch.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*	$NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $	*/
-
-/*
- * Tree search generalized from Knuth (6.2.2) Algorithm T just like
- * the AT&T man page says.
- *
- * The node_t structure is for internal use only, lint doesn't grok it.
- *
- * Written by reading the System V Interface Definition, not the code.
- *
- * Totally public domain.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#include <assert.h>
-#define _SEARCH_PRIVATE
-#include <search.h>
-#include <stdlib.h>
-
-/* find or insert datum into search tree */
-void *
-tsearch(const void *vkey, void **vrootp,
-    int (*compar)(const void *, const void *))
-{
-	node_t *q;
-	node_t **rootp = (node_t **)vrootp;
-
-	_DIAGASSERT(vkey != NULL);
-	_DIAGASSERT(compar != NULL);
-
-	if (rootp == NULL)
-		return NULL;
-
-	while (*rootp != NULL) {	/* Knuth's T1: */
-		int r;
-
-		if ((r = (*compar)(vkey, (*rootp)->key)) == 0)	/* T2: */
-			return *rootp;		/* we found it! */
-
-		rootp = (r < 0) ?
-		    &(*rootp)->llink :		/* T3: follow left branch */
-		    &(*rootp)->rlink;		/* T4: follow right branch */
-	}
-
-	q = malloc(sizeof(node_t));		/* T5: key not found */
-	if (q != 0) {				/* make new node */
-		*rootp = q;			/* link new node to old */
-		q->key = __UNCONST(vkey);	/* initialize new node */
-		q->llink = q->rlink = NULL;
-	}
-	return q;
-}
diff --git a/libc/upstream-netbsd/libc/thread-stub/__isthreaded.c b/libc/upstream-netbsd/libc/thread-stub/__isthreaded.c
deleted file mode 100644
index 50c1b6f..0000000
--- a/libc/upstream-netbsd/libc/thread-stub/__isthreaded.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*	$NetBSD: __isthreaded.c,v 1.3 2009/12/01 01:33:25 explorer Exp $	*/
-
-/*-
- * Copyright (c) 1999 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Michael Graff.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: __isthreaded.c,v 1.3 2009/12/01 01:33:25 explorer Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-int __isthreaded = 0;
diff --git a/libc/upstream-netbsd/namespace.h b/libc/upstream-netbsd/namespace.h
deleted file mode 100644
index a4d4151..0000000
--- a/libc/upstream-netbsd/namespace.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _BIONIC_NETBSD_NAMESPACE_H_included
-#define _BIONIC_NETBSD_NAMESPACE_H_included
-
-// NetBSD uses __weak_alias on a lot of functions. We don't want that.
-#if defined(__weak_alias)
-#undef __weak_alias
-#endif
-
-#endif
diff --git a/libc/upstream-netbsd/netbsd-compat.h b/libc/upstream-netbsd/netbsd-compat.h
deleted file mode 100644
index f830f38..0000000
--- a/libc/upstream-netbsd/netbsd-compat.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _BIONIC_NETBSD_COMPAT_H_included
-#define _BIONIC_NETBSD_COMPAT_H_included
-
-// NetBSD uses _DIAGASSERT to null-check arguments and the like.
-#include <assert.h>
-#define _DIAGASSERT(e) ((e) ? (void) 0 : __assert2(__FILE__, __LINE__, __func__, #e))
-
-// TODO: update our <sys/cdefs.h> to support this properly.
-#define __type_fit(t, a) (0 == 0)
-
-#define _GNU_SOURCE
-
-// TODO: we don't yet have thread-safe environment variables.
-#define __readlockenv() 0
-#define __unlockenv() 0
-
-#endif
diff --git a/libc/upstream-netbsd/port_before.h b/libc/upstream-netbsd/port_before.h
deleted file mode 100644
index 5e06e52..0000000
--- a/libc/upstream-netbsd/port_before.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _BIONIC_NETBSD_PORT_BEFORE_H_included
-#define _BIONIC_NETBSD_PORT_BEFORE_H_included
-
-#include "namespace.h"
-#include <sys/cdefs.h>
-#include "private/arpa_nameser.h"
-
-#define ISC_FORMAT_PRINTF(a,b) __printflike(a,b)
-#define ISC_SOCKLEN_T socklen_t
-
-#endif
diff --git a/libc/upstream-netbsd/rand48.h b/libc/upstream-netbsd/rand48.h
deleted file mode 100644
index 1ad8b0d..0000000
--- a/libc/upstream-netbsd/rand48.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*	$NetBSD: rand48.h,v 1.6 2011/05/18 19:36:36 dsl Exp $	*/
-
-/*
- * Copyright (c) 1993 Martin Birgmeier
- * All rights reserved.
- *
- * You may redistribute unmodified or modified versions of this source
- * code provided that the above copyright notice and this and the
- * following conditions are retained.
- *
- * This software is provided ``as is'', and comes with no warranties
- * of any kind. I shall in no event be liable for anything that happens
- * to anyone/anything when using this software.
- */
-
-#ifndef _RAND48_H_
-#define _RAND48_H_
-
-#include <stdlib.h>
-
-extern void		__dorand48(unsigned short[3]);
-extern unsigned short	__rand48_seed[3];
-extern unsigned short	__rand48_mult[3];
-extern unsigned short	__rand48_add;
-
-#define	RAND48_SEED_0	(0x330e)
-#define	RAND48_SEED_1	(0xabcd)
-#define	RAND48_SEED_2	(0x1234)
-#define	RAND48_MULT_0	(0xe66d)
-#define	RAND48_MULT_1	(0xdeec)
-#define	RAND48_MULT_2	(0x0005)
-#define	RAND48_ADD	(0x000b)
-
-#endif /* _RAND48_H_ */
diff --git a/libc/upstream-netbsd/reentrant.h b/libc/upstream-netbsd/reentrant.h
deleted file mode 100644
index e2945da..0000000
--- a/libc/upstream-netbsd/reentrant.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _BIONIC_NETBSD_REENTRANT_H_included
-#define _BIONIC_NETBSD_REENTRANT_H_included
-
-#define _REENTRANT
-
-#include <pthread.h>
-#include <signal.h>
-
-//
-// Map NetBSD libc internal locking to pthread locking.
-//
-
-#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-#define mutex_t pthread_mutex_t
-
-#define RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
-#define rwlock_t pthread_rwlock_t
-#define rwlock_rdlock pthread_rwlock_rdlock
-#define rwlock_unlock pthread_rwlock_unlock
-#define rwlock_wrlock pthread_rwlock_wrlock
-
-#endif
diff --git a/libc/upstream-openbsd/README.txt b/libc/upstream-openbsd/README.txt
new file mode 100644
index 0000000..9db64ea
--- /dev/null
+++ b/libc/upstream-openbsd/README.txt
@@ -0,0 +1,5 @@
+This directory contains upstream OpenBSD source. You should not edit these
+files directly. Make fixes upstream and then pull down the new version of
+the file.
+
+TODO: write a script to make this process automated.
diff --git a/libc/upstream-openbsd/android/gdtoa_support.cpp b/libc/upstream-openbsd/android/gdtoa_support.cpp
new file mode 100644
index 0000000..4e7bf3b
--- /dev/null
+++ b/libc/upstream-openbsd/android/gdtoa_support.cpp
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <pthread.h>
+
+__LIBC_HIDDEN__ pthread_mutex_t __dtoa_locks[] = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER };
diff --git a/libc/upstream-openbsd/android/include/arc4random.h b/libc/upstream-openbsd/android/include/arc4random.h
new file mode 100644
index 0000000..c07257d
--- /dev/null
+++ b/libc/upstream-openbsd/android/include/arc4random.h
@@ -0,0 +1,87 @@
+/*	$OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $	*/
+
+/*
+ * Copyright (c) 1996, David Mazieres <dm@uun.org>
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+ * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+/*
+ * Stub functions for portability.
+ */
+
+#include <sys/mman.h>
+
+#include <pthread.h>
+#include <signal.h>
+
+// Android gets these from "thread_private.h".
+#include "thread_private.h"
+//static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
+//#define _ARC4_LOCK()   pthread_mutex_lock(&arc4random_mtx)
+//#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
+
+#ifdef __GLIBC__
+extern void *__dso_handle;
+extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
+#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
+#else
+#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+#endif
+
+static inline void
+_getentropy_fail(void)
+{
+	raise(SIGKILL);
+}
+
+static volatile sig_atomic_t _rs_forked;
+
+static inline void
+_rs_forkhandler(void)
+{
+	_rs_forked = 1;
+}
+
+static inline void
+_rs_forkdetect(void)
+{
+	static pid_t _rs_pid = 0;
+	pid_t pid = getpid();
+
+	if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) {
+		_rs_pid = pid;
+		_rs_forked = 0;
+		if (rs)
+			memset(rs, 0, sizeof(*rs));
+	}
+}
+
+static inline int
+_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
+{
+	if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
+	    MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
+		return (-1);
+
+	if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
+	    MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
+		munmap(*rsxp, sizeof(**rsxp));
+		return (-1);
+	}
+
+	_ARC4_ATFORK(_rs_forkhandler);
+	return (0);
+}
diff --git a/libc/upstream-openbsd/android/include/arith.h b/libc/upstream-openbsd/android/include/arith.h
new file mode 100644
index 0000000..b262e4f
--- /dev/null
+++ b/libc/upstream-openbsd/android/include/arith.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define IEEE_8087
+
+#if __LP64__
+#define Long int
+#endif
+
+#define INFNAN_CHECK
+#define MULTIPLE_THREADS
diff --git a/libc/upstream-openbsd/android/include/gd_qnan.h b/libc/upstream-openbsd/android/include/gd_qnan.h
new file mode 100644
index 0000000..e8e907b
--- /dev/null
+++ b/libc/upstream-openbsd/android/include/gd_qnan.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if __arm__
+
+#define f_QNAN  0xffffffff
+
+#define d_QNAN0 0xffffffff
+#define d_QNAN1 0xffffffff
+
+#elif __mips__
+
+#define f_QNAN  0x7fbfffff
+
+#define d_QNAN0 0x7ff7ffff
+#define d_QNAN1 0xffffffff
+
+#else
+
+#define f_QNAN  0xffc00000
+
+#define d_QNAN0 0x00000000
+#define d_QNAN1 0xfff80000
+
+#endif
+
+/* long double. */
+#if __LP64__
+#define ld_QNAN0 0x7fff8000
+#define ld_QNAN1 0x00000000
+#define ld_QNAN2 0x00000000
+#define ld_QNAN3 0x00000000
+#else
+/* sizeof(long double) == sizeof(double), so we shouldn't be trying to use these constants. */
+#endif
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h
new file mode 100644
index 0000000..34ad2c5
--- /dev/null
+++ b/libc/upstream-openbsd/android/include/openbsd-compat.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BIONIC_OPENBSD_COMPAT_H_included
+#define _BIONIC_OPENBSD_COMPAT_H_included
+
+#include <sys/cdefs.h>
+#include <stddef.h> // For size_t.
+
+#define __USE_BSD
+
+/* OpenBSD's <ctype.h> uses these names, which conflicted with stlport.
+ * Additionally, we changed the numeric/digit type from N to D for libcxx.
+ */
+#define _U _CTYPE_U
+#define _L _CTYPE_L
+#define _N _CTYPE_D
+#define _S _CTYPE_S
+#define _P _CTYPE_P
+#define _C _CTYPE_C
+#define _X _CTYPE_X
+#define _B _CTYPE_B
+
+/* OpenBSD has this, but we can't really implement it correctly on Linux. */
+#define issetugid() 0
+
+#define explicit_bzero(p, s) memset(p, 0, s)
+
+/* We have OpenBSD's getentropy_linux.c, but we don't mention getentropy in any header. */
+__LIBC_HIDDEN__ extern int getentropy(void*, size_t);
+
+/* LP32 NDK ctype.h contained references to these. */
+__LIBC64_HIDDEN__ extern const short* _tolower_tab_;
+__LIBC64_HIDDEN__ extern const short* _toupper_tab_;
+
+__LIBC_HIDDEN__ extern struct atexit* __atexit;
+__LIBC_HIDDEN__ extern const char _C_ctype_[];
+__LIBC_HIDDEN__ extern const short _C_toupper_[];
+__LIBC_HIDDEN__ extern const short _C_tolower_[];
+__LIBC_HIDDEN__ extern char* __findenv(const char*, int, int*);
+__LIBC_HIDDEN__ extern char* _mktemp(char*);
+
+/* TODO: hide this when android_support.a is fixed (http://b/16298580).*/
+/*__LIBC_HIDDEN__*/ extern int __isthreaded;
+
+#endif
diff --git a/libc/upstream-openbsd/lib/libc/crypt/arc4random.c b/libc/upstream-openbsd/lib/libc/crypt/arc4random.c
new file mode 100644
index 0000000..64248b6
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/crypt/arc4random.c
@@ -0,0 +1,195 @@
+/*	$OpenBSD: arc4random.c,v 1.50 2014/07/21 18:13:12 deraadt Exp $	*/
+
+/*
+ * Copyright (c) 1996, David Mazieres <dm@uun.org>
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+ * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+/*
+ * ChaCha based random number generator for OpenBSD.
+ */
+
+#include <fcntl.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+
+#define KEYSTREAM_ONLY
+#include "chacha_private.h"
+
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#ifdef __GNUC__
+#define inline __inline
+#else				/* !__GNUC__ */
+#define inline
+#endif				/* !__GNUC__ */
+
+#define KEYSZ	32
+#define IVSZ	8
+#define BLOCKSZ	64
+#define RSBUFSZ	(16*BLOCKSZ)
+
+/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */
+static struct _rs {
+	size_t		rs_have;	/* valid bytes at end of rs_buf */
+	size_t		rs_count;	/* bytes till reseed */
+} *rs;
+
+/* Maybe be preserved in fork children, if _rs_allocate() decides. */
+static struct _rsx {
+	chacha_ctx	rs_chacha;	/* chacha context for random keystream */
+	u_char		rs_buf[RSBUFSZ];	/* keystream blocks */
+} *rsx;
+
+static inline int _rs_allocate(struct _rs **, struct _rsx **);
+static inline void _rs_forkdetect(void);
+#include "arc4random.h"
+
+static inline void _rs_rekey(u_char *dat, size_t datlen);
+
+static inline void
+_rs_init(u_char *buf, size_t n)
+{
+	if (n < KEYSZ + IVSZ)
+		return;
+
+	if (rs == NULL) {
+		if (_rs_allocate(&rs, &rsx) == -1)
+			abort();
+	}
+
+	chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8, 0);
+	chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ);
+}
+
+static void
+_rs_stir(void)
+{
+	u_char rnd[KEYSZ + IVSZ];
+
+	if (getentropy(rnd, sizeof rnd) == -1)
+		_getentropy_fail();
+
+	if (!rs)
+		_rs_init(rnd, sizeof(rnd));
+	else
+		_rs_rekey(rnd, sizeof(rnd));
+	explicit_bzero(rnd, sizeof(rnd));	/* discard source seed */
+
+	/* invalidate rs_buf */
+	rs->rs_have = 0;
+	memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
+
+	rs->rs_count = 1600000;
+}
+
+static inline void
+_rs_stir_if_needed(size_t len)
+{
+	_rs_forkdetect();
+	if (!rs || rs->rs_count <= len)
+		_rs_stir();
+	if (rs->rs_count <= len)
+		rs->rs_count = 0;
+	else
+		rs->rs_count -= len;
+}
+
+static inline void
+_rs_rekey(u_char *dat, size_t datlen)
+{
+#ifndef KEYSTREAM_ONLY
+	memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
+#endif
+	/* fill rs_buf with the keystream */
+	chacha_encrypt_bytes(&rsx->rs_chacha, rsx->rs_buf,
+	    rsx->rs_buf, sizeof(rsx->rs_buf));
+	/* mix in optional user provided data */
+	if (dat) {
+		size_t i, m;
+
+		m = min(datlen, KEYSZ + IVSZ);
+		for (i = 0; i < m; i++)
+			rsx->rs_buf[i] ^= dat[i];
+	}
+	/* immediately reinit for backtracking resistance */
+	_rs_init(rsx->rs_buf, KEYSZ + IVSZ);
+	memset(rsx->rs_buf, 0, KEYSZ + IVSZ);
+	rs->rs_have = sizeof(rsx->rs_buf) - KEYSZ - IVSZ;
+}
+
+static inline void
+_rs_random_buf(void *_buf, size_t n)
+{
+	u_char *buf = (u_char *)_buf;
+	u_char *keystream;
+	size_t m;
+
+	_rs_stir_if_needed(n);
+	while (n > 0) {
+		if (rs->rs_have > 0) {
+			m = min(n, rs->rs_have);
+			keystream = rsx->rs_buf + sizeof(rsx->rs_buf)
+			    - rs->rs_have;
+			memcpy(buf, keystream, m);
+			memset(keystream, 0, m);
+			buf += m;
+			n -= m;
+			rs->rs_have -= m;
+		}
+		if (rs->rs_have == 0)
+			_rs_rekey(NULL, 0);
+	}
+}
+
+static inline void
+_rs_random_u32(uint32_t *val)
+{
+	u_char *keystream;
+
+	_rs_stir_if_needed(sizeof(*val));
+	if (rs->rs_have < sizeof(*val))
+		_rs_rekey(NULL, 0);
+	keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have;
+	memcpy(val, keystream, sizeof(*val));
+	memset(keystream, 0, sizeof(*val));
+	rs->rs_have -= sizeof(*val);
+}
+
+uint32_t
+arc4random(void)
+{
+	uint32_t val;
+
+	_ARC4_LOCK();
+	_rs_random_u32(&val);
+	_ARC4_UNLOCK();
+	return val;
+}
+
+void
+arc4random_buf(void *buf, size_t n)
+{
+	_ARC4_LOCK();
+	_rs_random_buf(buf, n);
+	_ARC4_UNLOCK();
+}
diff --git a/libc/upstream-openbsd/lib/libc/crypt/arc4random_uniform.c b/libc/upstream-openbsd/lib/libc/crypt/arc4random_uniform.c
new file mode 100644
index 0000000..1aa9a62
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/crypt/arc4random_uniform.c
@@ -0,0 +1,56 @@
+/*	$OpenBSD: arc4random_uniform.c,v 1.1 2014/07/12 13:24:54 deraadt Exp $	*/
+
+/*
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+#include <sys/types.h>
+#include <stdlib.h>
+
+/*
+ * Calculate a uniformly distributed random number less than upper_bound
+ * avoiding "modulo bias".
+ *
+ * Uniformity is achieved by generating new random numbers until the one
+ * returned is outside the range [0, 2**32 % upper_bound).  This
+ * guarantees the selected random number will be inside
+ * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
+ * after reduction modulo upper_bound.
+ */
+uint32_t
+arc4random_uniform(uint32_t upper_bound)
+{
+	uint32_t r, min;
+
+	if (upper_bound < 2)
+		return 0;
+
+	/* 2**32 % x == (2**32 - x) % x */
+	min = -upper_bound % upper_bound;
+
+	/*
+	 * This could theoretically loop forever but each retry has
+	 * p > 0.5 (worst case, usually far better) of selecting a
+	 * number inside the range we need, so it should rarely need
+	 * to re-roll.
+	 */
+	for (;;) {
+		r = arc4random();
+		if (r >= min)
+			break;
+	}
+
+	return r % upper_bound;
+}
diff --git a/libc/upstream-openbsd/lib/libc/crypt/chacha_private.h b/libc/upstream-openbsd/lib/libc/crypt/chacha_private.h
new file mode 100644
index 0000000..7c3680f
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/crypt/chacha_private.h
@@ -0,0 +1,222 @@
+/*
+chacha-merged.c version 20080118
+D. J. Bernstein
+Public domain.
+*/
+
+/* $OpenBSD: chacha_private.h,v 1.2 2013/10/04 07:02:27 djm Exp $ */
+
+typedef unsigned char u8;
+typedef unsigned int u32;
+
+typedef struct
+{
+  u32 input[16]; /* could be compressed */
+} chacha_ctx;
+
+#define U8C(v) (v##U)
+#define U32C(v) (v##U)
+
+#define U8V(v) ((u8)(v) & U8C(0xFF))
+#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
+
+#define ROTL32(v, n) \
+  (U32V((v) << (n)) | ((v) >> (32 - (n))))
+
+#define U8TO32_LITTLE(p) \
+  (((u32)((p)[0])      ) | \
+   ((u32)((p)[1]) <<  8) | \
+   ((u32)((p)[2]) << 16) | \
+   ((u32)((p)[3]) << 24))
+
+#define U32TO8_LITTLE(p, v) \
+  do { \
+    (p)[0] = U8V((v)      ); \
+    (p)[1] = U8V((v) >>  8); \
+    (p)[2] = U8V((v) >> 16); \
+    (p)[3] = U8V((v) >> 24); \
+  } while (0)
+
+#define ROTATE(v,c) (ROTL32(v,c))
+#define XOR(v,w) ((v) ^ (w))
+#define PLUS(v,w) (U32V((v) + (w)))
+#define PLUSONE(v) (PLUS((v),1))
+
+#define QUARTERROUND(a,b,c,d) \
+  a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
+  c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
+  a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
+  c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
+
+static const char sigma[16] = "expand 32-byte k";
+static const char tau[16] = "expand 16-byte k";
+
+static void
+chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
+{
+  const char *constants;
+
+  x->input[4] = U8TO32_LITTLE(k + 0);
+  x->input[5] = U8TO32_LITTLE(k + 4);
+  x->input[6] = U8TO32_LITTLE(k + 8);
+  x->input[7] = U8TO32_LITTLE(k + 12);
+  if (kbits == 256) { /* recommended */
+    k += 16;
+    constants = sigma;
+  } else { /* kbits == 128 */
+    constants = tau;
+  }
+  x->input[8] = U8TO32_LITTLE(k + 0);
+  x->input[9] = U8TO32_LITTLE(k + 4);
+  x->input[10] = U8TO32_LITTLE(k + 8);
+  x->input[11] = U8TO32_LITTLE(k + 12);
+  x->input[0] = U8TO32_LITTLE(constants + 0);
+  x->input[1] = U8TO32_LITTLE(constants + 4);
+  x->input[2] = U8TO32_LITTLE(constants + 8);
+  x->input[3] = U8TO32_LITTLE(constants + 12);
+}
+
+static void
+chacha_ivsetup(chacha_ctx *x,const u8 *iv)
+{
+  x->input[12] = 0;
+  x->input[13] = 0;
+  x->input[14] = U8TO32_LITTLE(iv + 0);
+  x->input[15] = U8TO32_LITTLE(iv + 4);
+}
+
+static void
+chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
+{
+  u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
+  u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
+  u8 *ctarget = NULL;
+  u8 tmp[64];
+  u_int i;
+
+  if (!bytes) return;
+
+  j0 = x->input[0];
+  j1 = x->input[1];
+  j2 = x->input[2];
+  j3 = x->input[3];
+  j4 = x->input[4];
+  j5 = x->input[5];
+  j6 = x->input[6];
+  j7 = x->input[7];
+  j8 = x->input[8];
+  j9 = x->input[9];
+  j10 = x->input[10];
+  j11 = x->input[11];
+  j12 = x->input[12];
+  j13 = x->input[13];
+  j14 = x->input[14];
+  j15 = x->input[15];
+
+  for (;;) {
+    if (bytes < 64) {
+      for (i = 0;i < bytes;++i) tmp[i] = m[i];
+      m = tmp;
+      ctarget = c;
+      c = tmp;
+    }
+    x0 = j0;
+    x1 = j1;
+    x2 = j2;
+    x3 = j3;
+    x4 = j4;
+    x5 = j5;
+    x6 = j6;
+    x7 = j7;
+    x8 = j8;
+    x9 = j9;
+    x10 = j10;
+    x11 = j11;
+    x12 = j12;
+    x13 = j13;
+    x14 = j14;
+    x15 = j15;
+    for (i = 20;i > 0;i -= 2) {
+      QUARTERROUND( x0, x4, x8,x12)
+      QUARTERROUND( x1, x5, x9,x13)
+      QUARTERROUND( x2, x6,x10,x14)
+      QUARTERROUND( x3, x7,x11,x15)
+      QUARTERROUND( x0, x5,x10,x15)
+      QUARTERROUND( x1, x6,x11,x12)
+      QUARTERROUND( x2, x7, x8,x13)
+      QUARTERROUND( x3, x4, x9,x14)
+    }
+    x0 = PLUS(x0,j0);
+    x1 = PLUS(x1,j1);
+    x2 = PLUS(x2,j2);
+    x3 = PLUS(x3,j3);
+    x4 = PLUS(x4,j4);
+    x5 = PLUS(x5,j5);
+    x6 = PLUS(x6,j6);
+    x7 = PLUS(x7,j7);
+    x8 = PLUS(x8,j8);
+    x9 = PLUS(x9,j9);
+    x10 = PLUS(x10,j10);
+    x11 = PLUS(x11,j11);
+    x12 = PLUS(x12,j12);
+    x13 = PLUS(x13,j13);
+    x14 = PLUS(x14,j14);
+    x15 = PLUS(x15,j15);
+
+#ifndef KEYSTREAM_ONLY
+    x0 = XOR(x0,U8TO32_LITTLE(m + 0));
+    x1 = XOR(x1,U8TO32_LITTLE(m + 4));
+    x2 = XOR(x2,U8TO32_LITTLE(m + 8));
+    x3 = XOR(x3,U8TO32_LITTLE(m + 12));
+    x4 = XOR(x4,U8TO32_LITTLE(m + 16));
+    x5 = XOR(x5,U8TO32_LITTLE(m + 20));
+    x6 = XOR(x6,U8TO32_LITTLE(m + 24));
+    x7 = XOR(x7,U8TO32_LITTLE(m + 28));
+    x8 = XOR(x8,U8TO32_LITTLE(m + 32));
+    x9 = XOR(x9,U8TO32_LITTLE(m + 36));
+    x10 = XOR(x10,U8TO32_LITTLE(m + 40));
+    x11 = XOR(x11,U8TO32_LITTLE(m + 44));
+    x12 = XOR(x12,U8TO32_LITTLE(m + 48));
+    x13 = XOR(x13,U8TO32_LITTLE(m + 52));
+    x14 = XOR(x14,U8TO32_LITTLE(m + 56));
+    x15 = XOR(x15,U8TO32_LITTLE(m + 60));
+#endif
+
+    j12 = PLUSONE(j12);
+    if (!j12) {
+      j13 = PLUSONE(j13);
+      /* stopping at 2^70 bytes per nonce is user's responsibility */
+    }
+
+    U32TO8_LITTLE(c + 0,x0);
+    U32TO8_LITTLE(c + 4,x1);
+    U32TO8_LITTLE(c + 8,x2);
+    U32TO8_LITTLE(c + 12,x3);
+    U32TO8_LITTLE(c + 16,x4);
+    U32TO8_LITTLE(c + 20,x5);
+    U32TO8_LITTLE(c + 24,x6);
+    U32TO8_LITTLE(c + 28,x7);
+    U32TO8_LITTLE(c + 32,x8);
+    U32TO8_LITTLE(c + 36,x9);
+    U32TO8_LITTLE(c + 40,x10);
+    U32TO8_LITTLE(c + 44,x11);
+    U32TO8_LITTLE(c + 48,x12);
+    U32TO8_LITTLE(c + 52,x13);
+    U32TO8_LITTLE(c + 56,x14);
+    U32TO8_LITTLE(c + 60,x15);
+
+    if (bytes <= 64) {
+      if (bytes < 64) {
+        for (i = 0;i < bytes;++i) ctarget[i] = c[i];
+      }
+      x->input[12] = j12;
+      x->input[13] = j13;
+      return;
+    }
+    bytes -= 64;
+    c += 64;
+#ifndef KEYSTREAM_ONLY
+    m += 64;
+#endif
+  }
+}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/dmisc.c b/libc/upstream-openbsd/lib/libc/gdtoa/dmisc.c
new file mode 100644
index 0000000..a5795cf
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/dmisc.c
@@ -0,0 +1,224 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+#ifndef MULTIPLE_THREADS
+ char *dtoa_result;
+#endif
+
+ char *
+#ifdef KR_headers
+rv_alloc(i) int i;
+#else
+rv_alloc(int i)
+#endif
+{
+	int j, k, *r;
+
+	j = sizeof(ULong);
+	for(k = 0;
+		sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;
+		j <<= 1)
+			k++;
+	r = (int*)Balloc(k);
+	if (r == NULL)
+		return (
+#ifndef MULTIPLE_THREADS
+		dtoa_result =
+#endif
+			NULL);
+	*r = k;
+	return
+#ifndef MULTIPLE_THREADS
+	dtoa_result =
+#endif
+		(char *)(r+1);
+	}
+
+ char *
+#ifdef KR_headers
+nrv_alloc(s, rve, n) char *s, **rve; int n;
+#else
+nrv_alloc(char *s, char **rve, int n)
+#endif
+{
+	char *rv, *t;
+
+	t = rv = rv_alloc(n);
+	if (t == NULL)
+		return (NULL);
+	while((*t = *s++) !=0)
+		t++;
+	if (rve)
+		*rve = t;
+	return rv;
+	}
+
+/* freedtoa(s) must be used to free values s returned by dtoa
+ * when MULTIPLE_THREADS is #defined.  It should be used in all cases,
+ * but for consistency with earlier versions of dtoa, it is optional
+ * when MULTIPLE_THREADS is not defined.
+ */
+
+ void
+#ifdef KR_headers
+freedtoa(s) char *s;
+#else
+freedtoa(char *s)
+#endif
+{
+	Bigint *b = (Bigint *)((int *)s - 1);
+	b->maxwds = 1 << (b->k = *(int*)b);
+	Bfree(b);
+#ifndef MULTIPLE_THREADS
+	if (s == dtoa_result)
+		dtoa_result = 0;
+#endif
+	}
+
+ int
+quorem
+#ifdef KR_headers
+	(b, S) Bigint *b, *S;
+#else
+	(Bigint *b, Bigint *S)
+#endif
+{
+	int n;
+	ULong *bx, *bxe, q, *sx, *sxe;
+#ifdef ULLong
+	ULLong borrow, carry, y, ys;
+#else
+	ULong borrow, carry, y, ys;
+#ifdef Pack_32
+	ULong si, z, zs;
+#endif
+#endif
+
+	n = S->wds;
+#ifdef DEBUG
+	/*debug*/ if (b->wds > n)
+	/*debug*/	Bug("oversize b in quorem");
+#endif
+	if (b->wds < n)
+		return 0;
+	sx = S->x;
+	sxe = sx + --n;
+	bx = b->x;
+	bxe = bx + n;
+	q = *bxe / (*sxe + 1);	/* ensure q <= true quotient */
+#ifdef DEBUG
+	/*debug*/ if (q > 9)
+	/*debug*/	Bug("oversized quotient in quorem");
+#endif
+	if (q) {
+		borrow = 0;
+		carry = 0;
+		do {
+#ifdef ULLong
+			ys = *sx++ * (ULLong)q + carry;
+			carry = ys >> 32;
+			y = *bx - (ys & 0xffffffffUL) - borrow;
+			borrow = y >> 32 & 1UL;
+			*bx++ = y & 0xffffffffUL;
+#else
+#ifdef Pack_32
+			si = *sx++;
+			ys = (si & 0xffff) * q + carry;
+			zs = (si >> 16) * q + (ys >> 16);
+			carry = zs >> 16;
+			y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
+			borrow = (y & 0x10000) >> 16;
+			z = (*bx >> 16) - (zs & 0xffff) - borrow;
+			borrow = (z & 0x10000) >> 16;
+			Storeinc(bx, z, y);
+#else
+			ys = *sx++ * q + carry;
+			carry = ys >> 16;
+			y = *bx - (ys & 0xffff) - borrow;
+			borrow = (y & 0x10000) >> 16;
+			*bx++ = y & 0xffff;
+#endif
+#endif
+			}
+			while(sx <= sxe);
+		if (!*bxe) {
+			bx = b->x;
+			while(--bxe > bx && !*bxe)
+				--n;
+			b->wds = n;
+			}
+		}
+	if (cmp(b, S) >= 0) {
+		q++;
+		borrow = 0;
+		carry = 0;
+		bx = b->x;
+		sx = S->x;
+		do {
+#ifdef ULLong
+			ys = *sx++ + carry;
+			carry = ys >> 32;
+			y = *bx - (ys & 0xffffffffUL) - borrow;
+			borrow = y >> 32 & 1UL;
+			*bx++ = y & 0xffffffffUL;
+#else
+#ifdef Pack_32
+			si = *sx++;
+			ys = (si & 0xffff) + carry;
+			zs = (si >> 16) + (ys >> 16);
+			carry = zs >> 16;
+			y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
+			borrow = (y & 0x10000) >> 16;
+			z = (*bx >> 16) - (zs & 0xffff) - borrow;
+			borrow = (z & 0x10000) >> 16;
+			Storeinc(bx, z, y);
+#else
+			ys = *sx++ + carry;
+			carry = ys >> 16;
+			y = *bx - (ys & 0xffff) - borrow;
+			borrow = (y & 0x10000) >> 16;
+			*bx++ = y & 0xffff;
+#endif
+#endif
+			}
+			while(sx <= sxe);
+		bx = b->x;
+		bxe = bx + n;
+		if (!*bxe) {
+			while(--bxe > bx && !*bxe)
+				--n;
+			b->wds = n;
+			}
+		}
+	return q;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/dtoa.c b/libc/upstream-openbsd/lib/libc/gdtoa/dtoa.c
new file mode 100644
index 0000000..668f7b5
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/dtoa.c
@@ -0,0 +1,839 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
+ *
+ * Inspired by "How to Print Floating-Point Numbers Accurately" by
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
+ *
+ * Modifications:
+ *	1. Rather than iterating, we use a simple numeric overestimate
+ *	   to determine k = floor(log10(d)).  We scale relevant
+ *	   quantities using O(log2(k)) rather than O(k) multiplications.
+ *	2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
+ *	   try to generate digits strictly left to right.  Instead, we
+ *	   compute with fewer bits and propagate the carry if necessary
+ *	   when rounding the final digit up.  This is often faster.
+ *	3. Under the assumption that input will be rounded nearest,
+ *	   mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
+ *	   That is, we allow equality in stopping tests when the
+ *	   round-nearest rule will give the same floating-point value
+ *	   as would satisfaction of the stopping test with strict
+ *	   inequality.
+ *	4. We remove common factors of powers of 2 from relevant
+ *	   quantities.
+ *	5. When converting floating-point integers less than 1e16,
+ *	   we use floating-point arithmetic rather than resorting
+ *	   to multiple-precision integers.
+ *	6. When asked to produce fewer than 15 digits, we first try
+ *	   to get by with floating-point arithmetic; we resort to
+ *	   multiple-precision integer arithmetic only if we cannot
+ *	   guarantee that the floating-point calculation has given
+ *	   the correctly rounded result.  For k requested digits and
+ *	   "uniformly" distributed input, the probability is
+ *	   something like 10^(k-15) that we must resort to the Long
+ *	   calculation.
+ */
+
+#ifdef Honor_FLT_ROUNDS
+#undef Check_FLT_ROUNDS
+#define Check_FLT_ROUNDS
+#else
+#define Rounding Flt_Rounds
+#endif
+
+ char *
+dtoa
+#ifdef KR_headers
+	(d0, mode, ndigits, decpt, sign, rve)
+	double d0; int mode, ndigits, *decpt, *sign; char **rve;
+#else
+	(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
+#endif
+{
+ /*	Arguments ndigits, decpt, sign are similar to those
+	of ecvt and fcvt; trailing zeros are suppressed from
+	the returned string.  If not null, *rve is set to point
+	to the end of the return value.  If d is +-Infinity or NaN,
+	then *decpt is set to 9999.
+
+	mode:
+		0 ==> shortest string that yields d when read in
+			and rounded to nearest.
+		1 ==> like 0, but with Steele & White stopping rule;
+			e.g. with IEEE P754 arithmetic , mode 0 gives
+			1e23 whereas mode 1 gives 9.999999999999999e22.
+		2 ==> max(1,ndigits) significant digits.  This gives a
+			return value similar to that of ecvt, except
+			that trailing zeros are suppressed.
+		3 ==> through ndigits past the decimal point.  This
+			gives a return value similar to that from fcvt,
+			except that trailing zeros are suppressed, and
+			ndigits can be negative.
+		4,5 ==> similar to 2 and 3, respectively, but (in
+			round-nearest mode) with the tests of mode 0 to
+			possibly return a shorter string that rounds to d.
+			With IEEE arithmetic and compilation with
+			-DHonor_FLT_ROUNDS, modes 4 and 5 behave the same
+			as modes 2 and 3 when FLT_ROUNDS != 1.
+		6-9 ==> Debugging modes similar to mode - 4:  don't try
+			fast floating-point estimate (if applicable).
+
+		Values of mode other than 0-9 are treated as mode 0.
+
+		Sufficient space is allocated to the return value
+		to hold the suppressed trailing zeros.
+	*/
+
+	int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,
+		j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
+		spec_case, try_quick;
+	Long L;
+#ifndef Sudden_Underflow
+	int denorm;
+	ULong x;
+#endif
+	Bigint *b, *b1, *delta, *mlo, *mhi, *S;
+	U d, d2, eps;
+	double ds;
+	char *s, *s0;
+#ifdef SET_INEXACT
+	int inexact, oldinexact;
+#endif
+#ifdef Honor_FLT_ROUNDS /*{*/
+	int Rounding;
+#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
+	Rounding = Flt_Rounds;
+#else /*}{*/
+	Rounding = 1;
+	switch(fegetround()) {
+	  case FE_TOWARDZERO:	Rounding = 0; break;
+	  case FE_UPWARD:	Rounding = 2; break;
+	  case FE_DOWNWARD:	Rounding = 3;
+	  }
+#endif /*}}*/
+#endif /*}*/
+
+#ifndef MULTIPLE_THREADS
+	if (dtoa_result) {
+		freedtoa(dtoa_result);
+		dtoa_result = 0;
+		}
+#endif
+	d.d = d0;
+	if (word0(&d) & Sign_bit) {
+		/* set sign for everything, including 0's and NaNs */
+		*sign = 1;
+		word0(&d) &= ~Sign_bit;	/* clear sign bit */
+		}
+	else
+		*sign = 0;
+
+#if defined(IEEE_Arith) + defined(VAX)
+#ifdef IEEE_Arith
+	if ((word0(&d) & Exp_mask) == Exp_mask)
+#else
+	if (word0(&d)  == 0x8000)
+#endif
+		{
+		/* Infinity or NaN */
+		*decpt = 9999;
+#ifdef IEEE_Arith
+		if (!word1(&d) && !(word0(&d) & 0xfffff))
+			return nrv_alloc("Infinity", rve, 8);
+#endif
+		return nrv_alloc("NaN", rve, 3);
+		}
+#endif
+#ifdef IBM
+	dval(&d) += 0; /* normalize */
+#endif
+	if (!dval(&d)) {
+		*decpt = 1;
+		return nrv_alloc("0", rve, 1);
+		}
+
+#ifdef SET_INEXACT
+	try_quick = oldinexact = get_inexact();
+	inexact = 1;
+#endif
+#ifdef Honor_FLT_ROUNDS
+	if (Rounding >= 2) {
+		if (*sign)
+			Rounding = Rounding == 2 ? 0 : 2;
+		else
+			if (Rounding != 2)
+				Rounding = 0;
+		}
+#endif
+
+	b = d2b(dval(&d), &be, &bbits);
+	if (b == NULL)
+		return (NULL);
+#ifdef Sudden_Underflow
+	i = (int)(word0(&d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
+#else
+	if (( i = (int)(word0(&d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) {
+#endif
+		dval(&d2) = dval(&d);
+		word0(&d2) &= Frac_mask1;
+		word0(&d2) |= Exp_11;
+#ifdef IBM
+		if (( j = 11 - hi0bits(word0(&d2) & Frac_mask) )!=0)
+			dval(&d2) /= 1 << j;
+#endif
+
+		/* log(x)	~=~ log(1.5) + (x-1.5)/1.5
+		 * log10(x)	 =  log(x) / log(10)
+		 *		~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
+		 * log10(&d) = (i-Bias)*log(2)/log(10) + log10(&d2)
+		 *
+		 * This suggests computing an approximation k to log10(&d) by
+		 *
+		 * k = (i - Bias)*0.301029995663981
+		 *	+ ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
+		 *
+		 * We want k to be too large rather than too small.
+		 * The error in the first-order Taylor series approximation
+		 * is in our favor, so we just round up the constant enough
+		 * to compensate for any error in the multiplication of
+		 * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
+		 * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
+		 * adding 1e-13 to the constant term more than suffices.
+		 * Hence we adjust the constant term to 0.1760912590558.
+		 * (We could get a more accurate k by invoking log10,
+		 *  but this is probably not worthwhile.)
+		 */
+
+		i -= Bias;
+#ifdef IBM
+		i <<= 2;
+		i += j;
+#endif
+#ifndef Sudden_Underflow
+		denorm = 0;
+		}
+	else {
+		/* d is denormalized */
+
+		i = bbits + be + (Bias + (P-1) - 1);
+		x = i > 32  ? word0(&d) << (64 - i) | word1(&d) >> (i - 32)
+			    : word1(&d) << (32 - i);
+		dval(&d2) = x;
+		word0(&d2) -= 31*Exp_msk1; /* adjust exponent */
+		i -= (Bias + (P-1) - 1) + 1;
+		denorm = 1;
+		}
+#endif
+	ds = (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
+	k = (int)ds;
+	if (ds < 0. && ds != k)
+		k--;	/* want k = floor(ds) */
+	k_check = 1;
+	if (k >= 0 && k <= Ten_pmax) {
+		if (dval(&d) < tens[k])
+			k--;
+		k_check = 0;
+		}
+	j = bbits - i - 1;
+	if (j >= 0) {
+		b2 = 0;
+		s2 = j;
+		}
+	else {
+		b2 = -j;
+		s2 = 0;
+		}
+	if (k >= 0) {
+		b5 = 0;
+		s5 = k;
+		s2 += k;
+		}
+	else {
+		b2 -= k;
+		b5 = -k;
+		s5 = 0;
+		}
+	if (mode < 0 || mode > 9)
+		mode = 0;
+
+#ifndef SET_INEXACT
+#ifdef Check_FLT_ROUNDS
+	try_quick = Rounding == 1;
+#else
+	try_quick = 1;
+#endif
+#endif /*SET_INEXACT*/
+
+	if (mode > 5) {
+		mode -= 4;
+		try_quick = 0;
+		}
+	leftright = 1;
+	ilim = ilim1 = -1;	/* Values for cases 0 and 1; done here to */
+				/* silence erroneous "gcc -Wall" warning. */
+	switch(mode) {
+		case 0:
+		case 1:
+			i = 18;
+			ndigits = 0;
+			break;
+		case 2:
+			leftright = 0;
+			/* no break */
+		case 4:
+			if (ndigits <= 0)
+				ndigits = 1;
+			ilim = ilim1 = i = ndigits;
+			break;
+		case 3:
+			leftright = 0;
+			/* no break */
+		case 5:
+			i = ndigits + k + 1;
+			ilim = i;
+			ilim1 = i - 1;
+			if (i <= 0)
+				i = 1;
+		}
+	s = s0 = rv_alloc(i);
+	if (s == NULL)
+		return (NULL);
+
+#ifdef Honor_FLT_ROUNDS
+	if (mode > 1 && Rounding != 1)
+		leftright = 0;
+#endif
+
+	if (ilim >= 0 && ilim <= Quick_max && try_quick) {
+
+		/* Try to get by with floating-point arithmetic. */
+
+		i = 0;
+		dval(&d2) = dval(&d);
+		k0 = k;
+		ilim0 = ilim;
+		ieps = 2; /* conservative */
+		if (k > 0) {
+			ds = tens[k&0xf];
+			j = k >> 4;
+			if (j & Bletch) {
+				/* prevent overflows */
+				j &= Bletch - 1;
+				dval(&d) /= bigtens[n_bigtens-1];
+				ieps++;
+				}
+			for(; j; j >>= 1, i++)
+				if (j & 1) {
+					ieps++;
+					ds *= bigtens[i];
+					}
+			dval(&d) /= ds;
+			}
+		else if (( j1 = -k )!=0) {
+			dval(&d) *= tens[j1 & 0xf];
+			for(j = j1 >> 4; j; j >>= 1, i++)
+				if (j & 1) {
+					ieps++;
+					dval(&d) *= bigtens[i];
+					}
+			}
+		if (k_check && dval(&d) < 1. && ilim > 0) {
+			if (ilim1 <= 0)
+				goto fast_failed;
+			ilim = ilim1;
+			k--;
+			dval(&d) *= 10.;
+			ieps++;
+			}
+		dval(&eps) = ieps*dval(&d) + 7.;
+		word0(&eps) -= (P-1)*Exp_msk1;
+		if (ilim == 0) {
+			S = mhi = 0;
+			dval(&d) -= 5.;
+			if (dval(&d) > dval(&eps))
+				goto one_digit;
+			if (dval(&d) < -dval(&eps))
+				goto no_digits;
+			goto fast_failed;
+			}
+#ifndef No_leftright
+		if (leftright) {
+			/* Use Steele & White method of only
+			 * generating digits needed.
+			 */
+			dval(&eps) = 0.5/tens[ilim-1] - dval(&eps);
+			for(i = 0;;) {
+				L = dval(&d);
+				dval(&d) -= L;
+				*s++ = '0' + (int)L;
+				if (dval(&d) < dval(&eps))
+					goto ret1;
+				if (1. - dval(&d) < dval(&eps))
+					goto bump_up;
+				if (++i >= ilim)
+					break;
+				dval(&eps) *= 10.;
+				dval(&d) *= 10.;
+				}
+			}
+		else {
+#endif
+			/* Generate ilim digits, then fix them up. */
+			dval(&eps) *= tens[ilim-1];
+			for(i = 1;; i++, dval(&d) *= 10.) {
+				L = (Long)(dval(&d));
+				if (!(dval(&d) -= L))
+					ilim = i;
+				*s++ = '0' + (int)L;
+				if (i == ilim) {
+					if (dval(&d) > 0.5 + dval(&eps))
+						goto bump_up;
+					else if (dval(&d) < 0.5 - dval(&eps)) {
+						while(*--s == '0');
+						s++;
+						goto ret1;
+						}
+					break;
+					}
+				}
+#ifndef No_leftright
+			}
+#endif
+ fast_failed:
+		s = s0;
+		dval(&d) = dval(&d2);
+		k = k0;
+		ilim = ilim0;
+		}
+
+	/* Do we have a "small" integer? */
+
+	if (be >= 0 && k <= Int_max) {
+		/* Yes. */
+		ds = tens[k];
+		if (ndigits < 0 && ilim <= 0) {
+			S = mhi = 0;
+			if (ilim < 0 || dval(&d) <= 5*ds)
+				goto no_digits;
+			goto one_digit;
+			}
+		for(i = 1;; i++, dval(&d) *= 10.) {
+			L = (Long)(dval(&d) / ds);
+			dval(&d) -= L*ds;
+#ifdef Check_FLT_ROUNDS
+			/* If FLT_ROUNDS == 2, L will usually be high by 1 */
+			if (dval(&d) < 0) {
+				L--;
+				dval(&d) += ds;
+				}
+#endif
+			*s++ = '0' + (int)L;
+			if (!dval(&d)) {
+#ifdef SET_INEXACT
+				inexact = 0;
+#endif
+				break;
+				}
+			if (i == ilim) {
+#ifdef Honor_FLT_ROUNDS
+				if (mode > 1)
+				switch(Rounding) {
+				  case 0: goto ret1;
+				  case 2: goto bump_up;
+				  }
+#endif
+				dval(&d) += dval(&d);
+#ifdef ROUND_BIASED
+				if (dval(&d) >= ds)
+#else
+				if (dval(&d) > ds || (dval(&d) == ds && L & 1))
+#endif
+					{
+ bump_up:
+					while(*--s == '9')
+						if (s == s0) {
+							k++;
+							*s = '0';
+							break;
+							}
+					++*s++;
+					}
+				break;
+				}
+			}
+		goto ret1;
+		}
+
+	m2 = b2;
+	m5 = b5;
+	mhi = mlo = 0;
+	if (leftright) {
+		i =
+#ifndef Sudden_Underflow
+			denorm ? be + (Bias + (P-1) - 1 + 1) :
+#endif
+#ifdef IBM
+			1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);
+#else
+			1 + P - bbits;
+#endif
+		b2 += i;
+		s2 += i;
+		mhi = i2b(1);
+		if (mhi == NULL)
+			return (NULL);
+		}
+	if (m2 > 0 && s2 > 0) {
+		i = m2 < s2 ? m2 : s2;
+		b2 -= i;
+		m2 -= i;
+		s2 -= i;
+		}
+	if (b5 > 0) {
+		if (leftright) {
+			if (m5 > 0) {
+				mhi = pow5mult(mhi, m5);
+				if (mhi == NULL)
+					return (NULL);
+				b1 = mult(mhi, b);
+				if (b1 == NULL)
+					return (NULL);
+				Bfree(b);
+				b = b1;
+				}
+			if (( j = b5 - m5 )!=0) {
+				b = pow5mult(b, j);
+				if (b == NULL)
+					return (NULL);
+				}
+			}
+		else {
+			b = pow5mult(b, b5);
+			if (b == NULL)
+				return (NULL);
+			}
+		}
+	S = i2b(1);
+	if (S == NULL)
+		return (NULL);
+	if (s5 > 0) {
+		S = pow5mult(S, s5);
+		if (S == NULL)
+			return (NULL);
+		}
+
+	/* Check for special case that d is a normalized power of 2. */
+
+	spec_case = 0;
+	if ((mode < 2 || leftright)
+#ifdef Honor_FLT_ROUNDS
+			&& Rounding == 1
+#endif
+				) {
+		if (!word1(&d) && !(word0(&d) & Bndry_mask)
+#ifndef Sudden_Underflow
+		 && word0(&d) & (Exp_mask & ~Exp_msk1)
+#endif
+				) {
+			/* The special case */
+			b2 += Log2P;
+			s2 += Log2P;
+			spec_case = 1;
+			}
+		}
+
+	/* Arrange for convenient computation of quotients:
+	 * shift left if necessary so divisor has 4 leading 0 bits.
+	 *
+	 * Perhaps we should just compute leading 28 bits of S once
+	 * and for all and pass them and a shift to quorem, so it
+	 * can do shifts and ors to compute the numerator for q.
+	 */
+#ifdef Pack_32
+	if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f )!=0)
+		i = 32 - i;
+#else
+	if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf )!=0)
+		i = 16 - i;
+#endif
+	if (i > 4) {
+		i -= 4;
+		b2 += i;
+		m2 += i;
+		s2 += i;
+		}
+	else if (i < 4) {
+		i += 28;
+		b2 += i;
+		m2 += i;
+		s2 += i;
+		}
+	if (b2 > 0) {
+		b = lshift(b, b2);
+		if (b == NULL)
+			return (NULL);
+		}
+	if (s2 > 0) {
+		S = lshift(S, s2);
+		if (S == NULL)
+			return (NULL);
+		}
+	if (k_check) {
+		if (cmp(b,S) < 0) {
+			k--;
+			b = multadd(b, 10, 0);	/* we botched the k estimate */
+			if (b == NULL)
+				return (NULL);
+			if (leftright) {
+				mhi = multadd(mhi, 10, 0);
+				if (mhi == NULL)
+					return (NULL);
+				}
+			ilim = ilim1;
+			}
+		}
+	if (ilim <= 0 && (mode == 3 || mode == 5)) {
+		S = multadd(S,5,0);
+		if (S == NULL)
+			return (NULL);
+		if (ilim < 0 || cmp(b,S) <= 0) {
+			/* no digits, fcvt style */
+ no_digits:
+			k = -1 - ndigits;
+			goto ret;
+			}
+ one_digit:
+		*s++ = '1';
+		k++;
+		goto ret;
+		}
+	if (leftright) {
+		if (m2 > 0) {
+			mhi = lshift(mhi, m2);
+			if (mhi == NULL)
+				return (NULL);
+			}
+
+		/* Compute mlo -- check for special case
+		 * that d is a normalized power of 2.
+		 */
+
+		mlo = mhi;
+		if (spec_case) {
+			mhi = Balloc(mhi->k);
+			if (mhi == NULL)
+				return (NULL);
+			Bcopy(mhi, mlo);
+			mhi = lshift(mhi, Log2P);
+			if (mhi == NULL)
+				return (NULL);
+			}
+
+		for(i = 1;;i++) {
+			dig = quorem(b,S) + '0';
+			/* Do we yet have the shortest decimal string
+			 * that will round to d?
+			 */
+			j = cmp(b, mlo);
+			delta = diff(S, mhi);
+			if (delta == NULL)
+				return (NULL);
+			j1 = delta->sign ? 1 : cmp(b, delta);
+			Bfree(delta);
+#ifndef ROUND_BIASED
+			if (j1 == 0 && mode != 1 && !(word1(&d) & 1)
+#ifdef Honor_FLT_ROUNDS
+				&& Rounding >= 1
+#endif
+								   ) {
+				if (dig == '9')
+					goto round_9_up;
+				if (j > 0)
+					dig++;
+#ifdef SET_INEXACT
+				else if (!b->x[0] && b->wds <= 1)
+					inexact = 0;
+#endif
+				*s++ = dig;
+				goto ret;
+				}
+#endif
+			if (j < 0 || (j == 0 && mode != 1
+#ifndef ROUND_BIASED
+							&& !(word1(&d) & 1)
+#endif
+					)) {
+				if (!b->x[0] && b->wds <= 1) {
+#ifdef SET_INEXACT
+					inexact = 0;
+#endif
+					goto accept_dig;
+					}
+#ifdef Honor_FLT_ROUNDS
+				if (mode > 1)
+				 switch(Rounding) {
+				  case 0: goto accept_dig;
+				  case 2: goto keep_dig;
+				  }
+#endif /*Honor_FLT_ROUNDS*/
+				if (j1 > 0) {
+					b = lshift(b, 1);
+					if (b == NULL)
+						return (NULL);
+					j1 = cmp(b, S);
+#ifdef ROUND_BIASED
+					if (j1 >= 0 /*)*/
+#else
+					if ((j1 > 0 || (j1 == 0 && dig & 1))
+#endif
+					&& dig++ == '9')
+						goto round_9_up;
+					}
+ accept_dig:
+				*s++ = dig;
+				goto ret;
+				}
+			if (j1 > 0) {
+#ifdef Honor_FLT_ROUNDS
+				if (!Rounding)
+					goto accept_dig;
+#endif
+				if (dig == '9') { /* possible if i == 1 */
+ round_9_up:
+					*s++ = '9';
+					goto roundoff;
+					}
+				*s++ = dig + 1;
+				goto ret;
+				}
+#ifdef Honor_FLT_ROUNDS
+ keep_dig:
+#endif
+			*s++ = dig;
+			if (i == ilim)
+				break;
+			b = multadd(b, 10, 0);
+			if (b == NULL)
+				return (NULL);
+			if (mlo == mhi) {
+				mlo = mhi = multadd(mhi, 10, 0);
+				if (mlo == NULL)
+					return (NULL);
+				}
+			else {
+				mlo = multadd(mlo, 10, 0);
+				if (mlo == NULL)
+					return (NULL);
+				mhi = multadd(mhi, 10, 0);
+				if (mhi == NULL)
+					return (NULL);
+				}
+			}
+		}
+	else
+		for(i = 1;; i++) {
+			*s++ = dig = quorem(b,S) + '0';
+			if (!b->x[0] && b->wds <= 1) {
+#ifdef SET_INEXACT
+				inexact = 0;
+#endif
+				goto ret;
+				}
+			if (i >= ilim)
+				break;
+			b = multadd(b, 10, 0);
+			if (b == NULL)
+				return (NULL);
+			}
+
+	/* Round off last digit */
+
+#ifdef Honor_FLT_ROUNDS
+	switch(Rounding) {
+	  case 0: goto trimzeros;
+	  case 2: goto roundoff;
+	  }
+#endif
+	b = lshift(b, 1);
+	if (b == NULL)
+		return (NULL);
+	j = cmp(b, S);
+#ifdef ROUND_BIASED
+	if (j >= 0)
+#else
+	if (j > 0 || (j == 0 && dig & 1))
+#endif
+		{
+ roundoff:
+		while(*--s == '9')
+			if (s == s0) {
+				k++;
+				*s++ = '1';
+				goto ret;
+				}
+		++*s++;
+		}
+	else {
+#ifdef Honor_FLT_ROUNDS
+ trimzeros:
+#endif
+		while(*--s == '0');
+		s++;
+		}
+ ret:
+	Bfree(S);
+	if (mhi) {
+		if (mlo && mlo != mhi)
+			Bfree(mlo);
+		Bfree(mhi);
+		}
+ ret1:
+#ifdef SET_INEXACT
+	if (inexact) {
+		if (!oldinexact) {
+			word0(&d) = Exp_1 + (70 << Exp_shift);
+			word1(&d) = 0;
+			dval(&d) += 1.;
+			}
+		}
+	else if (!oldinexact)
+		clear_inexact();
+#endif
+	Bfree(b);
+	*s = 0;
+	*decpt = k + 1;
+	if (rve)
+		*rve = s;
+	return s0;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa.c b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa.c
new file mode 100644
index 0000000..fd11de5
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa.c
@@ -0,0 +1,829 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ static Bigint *
+#ifdef KR_headers
+bitstob(bits, nbits, bbits) ULong *bits; int nbits; int *bbits;
+#else
+bitstob(ULong *bits, int nbits, int *bbits)
+#endif
+{
+	int i, k;
+	Bigint *b;
+	ULong *be, *x, *x0;
+
+	i = ULbits;
+	k = 0;
+	while(i < nbits) {
+		i <<= 1;
+		k++;
+		}
+#ifndef Pack_32
+	if (!k)
+		k = 1;
+#endif
+	b = Balloc(k);
+	if (b == NULL)
+		return (NULL);
+	be = bits + ((nbits - 1) >> kshift);
+	x = x0 = b->x;
+	do {
+		*x++ = *bits & ALL_ON;
+#ifdef Pack_16
+		*x++ = (*bits >> 16) & ALL_ON;
+#endif
+		} while(++bits <= be);
+	i = x - x0;
+	while(!x0[--i])
+		if (!i) {
+			b->wds = 0;
+			*bbits = 0;
+			goto ret;
+			}
+	b->wds = i + 1;
+	*bbits = i*ULbits + 32 - hi0bits(b->x[i]);
+ ret:
+	return b;
+	}
+
+/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
+ *
+ * Inspired by "How to Print Floating-Point Numbers Accurately" by
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
+ *
+ * Modifications:
+ *	1. Rather than iterating, we use a simple numeric overestimate
+ *	   to determine k = floor(log10(d)).  We scale relevant
+ *	   quantities using O(log2(k)) rather than O(k) multiplications.
+ *	2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
+ *	   try to generate digits strictly left to right.  Instead, we
+ *	   compute with fewer bits and propagate the carry if necessary
+ *	   when rounding the final digit up.  This is often faster.
+ *	3. Under the assumption that input will be rounded nearest,
+ *	   mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
+ *	   That is, we allow equality in stopping tests when the
+ *	   round-nearest rule will give the same floating-point value
+ *	   as would satisfaction of the stopping test with strict
+ *	   inequality.
+ *	4. We remove common factors of powers of 2 from relevant
+ *	   quantities.
+ *	5. When converting floating-point integers less than 1e16,
+ *	   we use floating-point arithmetic rather than resorting
+ *	   to multiple-precision integers.
+ *	6. When asked to produce fewer than 15 digits, we first try
+ *	   to get by with floating-point arithmetic; we resort to
+ *	   multiple-precision integer arithmetic only if we cannot
+ *	   guarantee that the floating-point calculation has given
+ *	   the correctly rounded result.  For k requested digits and
+ *	   "uniformly" distributed input, the probability is
+ *	   something like 10^(k-15) that we must resort to the Long
+ *	   calculation.
+ */
+
+ char *
+gdtoa
+#ifdef KR_headers
+	(fpi, be, bits, kindp, mode, ndigits, decpt, rve)
+	FPI *fpi; int be; ULong *bits;
+	int *kindp, mode, ndigits, *decpt; char **rve;
+#else
+	(FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve)
+#endif
+{
+ /*	Arguments ndigits and decpt are similar to the second and third
+	arguments of ecvt and fcvt; trailing zeros are suppressed from
+	the returned string.  If not null, *rve is set to point
+	to the end of the return value.  If d is +-Infinity or NaN,
+	then *decpt is set to 9999.
+	be = exponent: value = (integer represented by bits) * (2 to the power of be).
+
+	mode:
+		0 ==> shortest string that yields d when read in
+			and rounded to nearest.
+		1 ==> like 0, but with Steele & White stopping rule;
+			e.g. with IEEE P754 arithmetic , mode 0 gives
+			1e23 whereas mode 1 gives 9.999999999999999e22.
+		2 ==> max(1,ndigits) significant digits.  This gives a
+			return value similar to that of ecvt, except
+			that trailing zeros are suppressed.
+		3 ==> through ndigits past the decimal point.  This
+			gives a return value similar to that from fcvt,
+			except that trailing zeros are suppressed, and
+			ndigits can be negative.
+		4-9 should give the same return values as 2-3, i.e.,
+			4 <= mode <= 9 ==> same return as mode
+			2 + (mode & 1).  These modes are mainly for
+			debugging; often they run slower but sometimes
+			faster than modes 2-3.
+		4,5,8,9 ==> left-to-right digit generation.
+		6-9 ==> don't try fast floating-point estimate
+			(if applicable).
+
+		Values of mode other than 0-9 are treated as mode 0.
+
+		Sufficient space is allocated to the return value
+		to hold the suppressed trailing zeros.
+	*/
+
+	int bbits, b2, b5, be0, dig, i, ieps, ilim, ilim0, ilim1, inex;
+	int j, j1, k, k0, k_check, kind, leftright, m2, m5, nbits;
+	int rdir, s2, s5, spec_case, try_quick;
+	Long L;
+	Bigint *b, *b1, *delta, *mlo, *mhi, *mhi1, *S;
+	double d2, ds;
+	char *s, *s0;
+	U d, eps;
+
+#ifndef MULTIPLE_THREADS
+	if (dtoa_result) {
+		freedtoa(dtoa_result);
+		dtoa_result = 0;
+		}
+#endif
+	inex = 0;
+	kind = *kindp &= ~STRTOG_Inexact;
+	switch(kind & STRTOG_Retmask) {
+	  case STRTOG_Zero:
+		goto ret_zero;
+	  case STRTOG_Normal:
+	  case STRTOG_Denormal:
+		break;
+	  case STRTOG_Infinite:
+		*decpt = -32768;
+		return nrv_alloc("Infinity", rve, 8);
+	  case STRTOG_NaN:
+		*decpt = -32768;
+		return nrv_alloc("NaN", rve, 3);
+	  default:
+		return 0;
+	  }
+	b = bitstob(bits, nbits = fpi->nbits, &bbits);
+	if (b == NULL)
+		return (NULL);
+	be0 = be;
+	if ( (i = trailz(b)) !=0) {
+		rshift(b, i);
+		be += i;
+		bbits -= i;
+		}
+	if (!b->wds) {
+		Bfree(b);
+ ret_zero:
+		*decpt = 1;
+		return nrv_alloc("0", rve, 1);
+		}
+
+	dval(&d) = b2d(b, &i);
+	i = be + bbits - 1;
+	word0(&d) &= Frac_mask1;
+	word0(&d) |= Exp_11;
+#ifdef IBM
+	if ( (j = 11 - hi0bits(word0(&d) & Frac_mask)) !=0)
+		dval(&d) /= 1 << j;
+#endif
+
+	/* log(x)	~=~ log(1.5) + (x-1.5)/1.5
+	 * log10(x)	 =  log(x) / log(10)
+	 *		~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
+	 * log10(&d) = (i-Bias)*log(2)/log(10) + log10(d2)
+	 *
+	 * This suggests computing an approximation k to log10(&d) by
+	 *
+	 * k = (i - Bias)*0.301029995663981
+	 *	+ ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
+	 *
+	 * We want k to be too large rather than too small.
+	 * The error in the first-order Taylor series approximation
+	 * is in our favor, so we just round up the constant enough
+	 * to compensate for any error in the multiplication of
+	 * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
+	 * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
+	 * adding 1e-13 to the constant term more than suffices.
+	 * Hence we adjust the constant term to 0.1760912590558.
+	 * (We could get a more accurate k by invoking log10,
+	 *  but this is probably not worthwhile.)
+	 */
+#ifdef IBM
+	i <<= 2;
+	i += j;
+#endif
+	ds = (dval(&d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
+
+	/* correct assumption about exponent range */
+	if ((j = i) < 0)
+		j = -j;
+	if ((j -= 1077) > 0)
+		ds += j * 7e-17;
+
+	k = (int)ds;
+	if (ds < 0. && ds != k)
+		k--;	/* want k = floor(ds) */
+	k_check = 1;
+#ifdef IBM
+	j = be + bbits - 1;
+	if ( (j1 = j & 3) !=0)
+		dval(&d) *= 1 << j1;
+	word0(&d) += j << Exp_shift - 2 & Exp_mask;
+#else
+	word0(&d) += (be + bbits - 1) << Exp_shift;
+#endif
+	if (k >= 0 && k <= Ten_pmax) {
+		if (dval(&d) < tens[k])
+			k--;
+		k_check = 0;
+		}
+	j = bbits - i - 1;
+	if (j >= 0) {
+		b2 = 0;
+		s2 = j;
+		}
+	else {
+		b2 = -j;
+		s2 = 0;
+		}
+	if (k >= 0) {
+		b5 = 0;
+		s5 = k;
+		s2 += k;
+		}
+	else {
+		b2 -= k;
+		b5 = -k;
+		s5 = 0;
+		}
+	if (mode < 0 || mode > 9)
+		mode = 0;
+	try_quick = 1;
+	if (mode > 5) {
+		mode -= 4;
+		try_quick = 0;
+		}
+	else if (i >= -4 - Emin || i < Emin)
+		try_quick = 0;
+	leftright = 1;
+	ilim = ilim1 = -1;	/* Values for cases 0 and 1; done here to */
+				/* silence erroneous "gcc -Wall" warning. */
+	switch(mode) {
+		case 0:
+		case 1:
+			i = (int)(nbits * .30103) + 3;
+			ndigits = 0;
+			break;
+		case 2:
+			leftright = 0;
+			/* no break */
+		case 4:
+			if (ndigits <= 0)
+				ndigits = 1;
+			ilim = ilim1 = i = ndigits;
+			break;
+		case 3:
+			leftright = 0;
+			/* no break */
+		case 5:
+			i = ndigits + k + 1;
+			ilim = i;
+			ilim1 = i - 1;
+			if (i <= 0)
+				i = 1;
+		}
+	s = s0 = rv_alloc(i);
+	if (s == NULL)
+		return (NULL);
+
+	if ( (rdir = fpi->rounding - 1) !=0) {
+		if (rdir < 0)
+			rdir = 2;
+		if (kind & STRTOG_Neg)
+			rdir = 3 - rdir;
+		}
+
+	/* Now rdir = 0 ==> round near, 1 ==> round up, 2 ==> round down. */
+
+	if (ilim >= 0 && ilim <= Quick_max && try_quick && !rdir
+#ifndef IMPRECISE_INEXACT
+		&& k == 0
+#endif
+								) {
+
+		/* Try to get by with floating-point arithmetic. */
+
+		i = 0;
+		d2 = dval(&d);
+#ifdef IBM
+		if ( (j = 11 - hi0bits(word0(&d) & Frac_mask)) !=0)
+			dval(&d) /= 1 << j;
+#endif
+		k0 = k;
+		ilim0 = ilim;
+		ieps = 2; /* conservative */
+		if (k > 0) {
+			ds = tens[k&0xf];
+			j = k >> 4;
+			if (j & Bletch) {
+				/* prevent overflows */
+				j &= Bletch - 1;
+				dval(&d) /= bigtens[n_bigtens-1];
+				ieps++;
+				}
+			for(; j; j >>= 1, i++)
+				if (j & 1) {
+					ieps++;
+					ds *= bigtens[i];
+					}
+			}
+		else  {
+			ds = 1.;
+			if ( (j1 = -k) !=0) {
+				dval(&d) *= tens[j1 & 0xf];
+				for(j = j1 >> 4; j; j >>= 1, i++)
+					if (j & 1) {
+						ieps++;
+						dval(&d) *= bigtens[i];
+						}
+				}
+			}
+		if (k_check && dval(&d) < 1. && ilim > 0) {
+			if (ilim1 <= 0)
+				goto fast_failed;
+			ilim = ilim1;
+			k--;
+			dval(&d) *= 10.;
+			ieps++;
+			}
+		dval(&eps) = ieps*dval(&d) + 7.;
+		word0(&eps) -= (P-1)*Exp_msk1;
+		if (ilim == 0) {
+			S = mhi = 0;
+			dval(&d) -= 5.;
+			if (dval(&d) > dval(&eps))
+				goto one_digit;
+			if (dval(&d) < -dval(&eps))
+				goto no_digits;
+			goto fast_failed;
+			}
+#ifndef No_leftright
+		if (leftright) {
+			/* Use Steele & White method of only
+			 * generating digits needed.
+			 */
+			dval(&eps) = ds*0.5/tens[ilim-1] - dval(&eps);
+			for(i = 0;;) {
+				L = (Long)(dval(&d)/ds);
+				dval(&d) -= L*ds;
+				*s++ = '0' + (int)L;
+				if (dval(&d) < dval(&eps)) {
+					if (dval(&d))
+						inex = STRTOG_Inexlo;
+					goto ret1;
+					}
+				if (ds - dval(&d) < dval(&eps))
+					goto bump_up;
+				if (++i >= ilim)
+					break;
+				dval(&eps) *= 10.;
+				dval(&d) *= 10.;
+				}
+			}
+		else {
+#endif
+			/* Generate ilim digits, then fix them up. */
+			dval(&eps) *= tens[ilim-1];
+			for(i = 1;; i++, dval(&d) *= 10.) {
+				if ( (L = (Long)(dval(&d)/ds)) !=0)
+					dval(&d) -= L*ds;
+				*s++ = '0' + (int)L;
+				if (i == ilim) {
+					ds *= 0.5;
+					if (dval(&d) > ds + dval(&eps))
+						goto bump_up;
+					else if (dval(&d) < ds - dval(&eps)) {
+						if (dval(&d))
+							inex = STRTOG_Inexlo;
+						goto clear_trailing0;
+						}
+					break;
+					}
+				}
+#ifndef No_leftright
+			}
+#endif
+ fast_failed:
+		s = s0;
+		dval(&d) = d2;
+		k = k0;
+		ilim = ilim0;
+		}
+
+	/* Do we have a "small" integer? */
+
+	if (be >= 0 && k <= Int_max) {
+		/* Yes. */
+		ds = tens[k];
+		if (ndigits < 0 && ilim <= 0) {
+			S = mhi = 0;
+			if (ilim < 0 || dval(&d) <= 5*ds)
+				goto no_digits;
+			goto one_digit;
+			}
+		for(i = 1;; i++, dval(&d) *= 10.) {
+			L = dval(&d) / ds;
+			dval(&d) -= L*ds;
+#ifdef Check_FLT_ROUNDS
+			/* If FLT_ROUNDS == 2, L will usually be high by 1 */
+			if (dval(&d) < 0) {
+				L--;
+				dval(&d) += ds;
+				}
+#endif
+			*s++ = '0' + (int)L;
+			if (dval(&d) == 0.)
+				break;
+			if (i == ilim) {
+				if (rdir) {
+					if (rdir == 1)
+						goto bump_up;
+					inex = STRTOG_Inexlo;
+					goto ret1;
+					}
+				dval(&d) += dval(&d);
+#ifdef ROUND_BIASED
+				if (dval(&d) >= ds)
+#else
+				if (dval(&d) > ds || (dval(&d) == ds && L & 1))
+#endif
+					{
+ bump_up:
+					inex = STRTOG_Inexhi;
+					while(*--s == '9')
+						if (s == s0) {
+							k++;
+							*s = '0';
+							break;
+							}
+					++*s++;
+					}
+				else {
+					inex = STRTOG_Inexlo;
+ clear_trailing0:
+					while(*--s == '0'){}
+					++s;
+					}
+				break;
+				}
+			}
+		goto ret1;
+		}
+
+	m2 = b2;
+	m5 = b5;
+	mhi = mlo = 0;
+	if (leftright) {
+		i = nbits - bbits;
+		if (be - i++ < fpi->emin && mode != 3 && mode != 5) {
+			/* denormal */
+			i = be - fpi->emin + 1;
+			if (mode >= 2 && ilim > 0 && ilim < i)
+				goto small_ilim;
+			}
+		else if (mode >= 2) {
+ small_ilim:
+			j = ilim - 1;
+			if (m5 >= j)
+				m5 -= j;
+			else {
+				s5 += j -= m5;
+				b5 += j;
+				m5 = 0;
+				}
+			if ((i = ilim) < 0) {
+				m2 -= i;
+				i = 0;
+				}
+			}
+		b2 += i;
+		s2 += i;
+		mhi = i2b(1);
+		if (mhi == NULL)
+			return (NULL);
+		}
+	if (m2 > 0 && s2 > 0) {
+		i = m2 < s2 ? m2 : s2;
+		b2 -= i;
+		m2 -= i;
+		s2 -= i;
+		}
+	if (b5 > 0) {
+		if (leftright) {
+			if (m5 > 0) {
+				mhi = pow5mult(mhi, m5);
+				if (mhi == NULL)
+					return (NULL);
+				b1 = mult(mhi, b);
+				if (b1 == NULL)
+					return (NULL);
+				Bfree(b);
+				b = b1;
+				}
+			if ( (j = b5 - m5) !=0) {
+				b = pow5mult(b, j);
+				if (b == NULL)
+					return (NULL);
+				}
+			}
+		else {
+			b = pow5mult(b, b5);
+			if (b == NULL)
+				return (NULL);
+			}
+		}
+	S = i2b(1);
+	if (S == NULL)
+		return (NULL);
+	if (s5 > 0) {
+		S = pow5mult(S, s5);
+		if (S == NULL)
+			return (NULL);
+		}
+
+	/* Check for special case that d is a normalized power of 2. */
+
+	spec_case = 0;
+	if (mode < 2) {
+		if (bbits == 1 && be0 > fpi->emin + 1) {
+			/* The special case */
+			b2++;
+			s2++;
+			spec_case = 1;
+			}
+		}
+
+	/* Arrange for convenient computation of quotients:
+	 * shift left if necessary so divisor has 4 leading 0 bits.
+	 *
+	 * Perhaps we should just compute leading 28 bits of S once
+	 * and for all and pass them and a shift to quorem, so it
+	 * can do shifts and ors to compute the numerator for q.
+	 */
+	i = ((s5 ? hi0bits(S->x[S->wds-1]) : ULbits - 1) - s2 - 4) & kmask;
+	m2 += i;
+	if ((b2 += i) > 0) {
+		b = lshift(b, b2);
+		if (b == NULL)
+			return (NULL);
+		}
+	if ((s2 += i) > 0) {
+		S = lshift(S, s2);
+		if (S == NULL)
+			return (NULL);
+		}
+	if (k_check) {
+		if (cmp(b,S) < 0) {
+			k--;
+			b = multadd(b, 10, 0);	/* we botched the k estimate */
+			if (b == NULL)
+				return (NULL);
+			if (leftright) {
+				mhi = multadd(mhi, 10, 0);
+				if (mhi == NULL)
+					return (NULL);
+				}
+			ilim = ilim1;
+			}
+		}
+	if (ilim <= 0 && mode > 2) {
+		S = multadd(S,5,0);
+		if (S == NULL)
+			return (NULL);
+		if (ilim < 0 || cmp(b,S) <= 0) {
+			/* no digits, fcvt style */
+ no_digits:
+			k = -1 - ndigits;
+			inex = STRTOG_Inexlo;
+			goto ret;
+			}
+ one_digit:
+		inex = STRTOG_Inexhi;
+		*s++ = '1';
+		k++;
+		goto ret;
+		}
+	if (leftright) {
+		if (m2 > 0) {
+			mhi = lshift(mhi, m2);
+			if (mhi == NULL)
+				return (NULL);
+			}
+
+		/* Compute mlo -- check for special case
+		 * that d is a normalized power of 2.
+		 */
+
+		mlo = mhi;
+		if (spec_case) {
+			mhi = Balloc(mhi->k);
+			if (mhi == NULL)
+				return (NULL);
+			Bcopy(mhi, mlo);
+			mhi = lshift(mhi, 1);
+			if (mhi == NULL)
+				return (NULL);
+			}
+
+		for(i = 1;;i++) {
+			dig = quorem(b,S) + '0';
+			/* Do we yet have the shortest decimal string
+			 * that will round to d?
+			 */
+			j = cmp(b, mlo);
+			delta = diff(S, mhi);
+			if (delta == NULL)
+				return (NULL);
+			j1 = delta->sign ? 1 : cmp(b, delta);
+			Bfree(delta);
+#ifndef ROUND_BIASED
+			if (j1 == 0 && !mode && !(bits[0] & 1) && !rdir) {
+				if (dig == '9')
+					goto round_9_up;
+				if (j <= 0) {
+					if (b->wds > 1 || b->x[0])
+						inex = STRTOG_Inexlo;
+					}
+				else {
+					dig++;
+					inex = STRTOG_Inexhi;
+					}
+				*s++ = dig;
+				goto ret;
+				}
+#endif
+			if (j < 0 || (j == 0 && !mode
+#ifndef ROUND_BIASED
+							&& !(bits[0] & 1)
+#endif
+					)) {
+				if (rdir && (b->wds > 1 || b->x[0])) {
+					if (rdir == 2) {
+						inex = STRTOG_Inexlo;
+						goto accept;
+						}
+					while (cmp(S,mhi) > 0) {
+						*s++ = dig;
+						mhi1 = multadd(mhi, 10, 0);
+						if (mhi1 == NULL)
+							return (NULL);
+						if (mlo == mhi)
+							mlo = mhi1;
+						mhi = mhi1;
+						b = multadd(b, 10, 0);
+						if (b == NULL)
+							return (NULL);
+						dig = quorem(b,S) + '0';
+						}
+					if (dig++ == '9')
+						goto round_9_up;
+					inex = STRTOG_Inexhi;
+					goto accept;
+					}
+				if (j1 > 0) {
+					b = lshift(b, 1);
+					if (b == NULL)
+						return (NULL);
+					j1 = cmp(b, S);
+#ifdef ROUND_BIASED
+					if (j1 >= 0 /*)*/
+#else
+					if ((j1 > 0 || (j1 == 0 && dig & 1))
+#endif
+					&& dig++ == '9')
+						goto round_9_up;
+					inex = STRTOG_Inexhi;
+					}
+				if (b->wds > 1 || b->x[0])
+					inex = STRTOG_Inexlo;
+ accept:
+				*s++ = dig;
+				goto ret;
+				}
+			if (j1 > 0 && rdir != 2) {
+				if (dig == '9') { /* possible if i == 1 */
+ round_9_up:
+					*s++ = '9';
+					inex = STRTOG_Inexhi;
+					goto roundoff;
+					}
+				inex = STRTOG_Inexhi;
+				*s++ = dig + 1;
+				goto ret;
+				}
+			*s++ = dig;
+			if (i == ilim)
+				break;
+			b = multadd(b, 10, 0);
+			if (b == NULL)
+				return (NULL);
+			if (mlo == mhi) {
+				mlo = mhi = multadd(mhi, 10, 0);
+				if (mlo == NULL)
+					return (NULL);
+				}
+			else {
+				mlo = multadd(mlo, 10, 0);
+				if (mlo == NULL)
+					return (NULL);
+				mhi = multadd(mhi, 10, 0);
+				if (mhi == NULL)
+					return (NULL);
+				}
+			}
+		}
+	else
+		for(i = 1;; i++) {
+			*s++ = dig = quorem(b,S) + '0';
+			if (i >= ilim)
+				break;
+			b = multadd(b, 10, 0);
+			if (b == NULL)
+				return (NULL);
+			}
+
+	/* Round off last digit */
+
+	if (rdir) {
+		if (rdir == 2 || (b->wds <= 1 && !b->x[0]))
+			goto chopzeros;
+		goto roundoff;
+		}
+	b = lshift(b, 1);
+	if (b == NULL)
+		return (NULL);
+	j = cmp(b, S);
+#ifdef ROUND_BIASED
+	if (j >= 0)
+#else
+	if (j > 0 || (j == 0 && dig & 1))
+#endif
+		{
+ roundoff:
+		inex = STRTOG_Inexhi;
+		while(*--s == '9')
+			if (s == s0) {
+				k++;
+				*s++ = '1';
+				goto ret;
+				}
+		++*s++;
+		}
+	else {
+ chopzeros:
+		if (b->wds > 1 || b->x[0])
+			inex = STRTOG_Inexlo;
+		while(*--s == '0'){}
+		++s;
+		}
+ ret:
+	Bfree(S);
+	if (mhi) {
+		if (mlo && mlo != mhi)
+			Bfree(mlo);
+		Bfree(mhi);
+		}
+ ret1:
+	Bfree(b);
+	*s = 0;
+	*decpt = k + 1;
+	if (rve)
+		*rve = s;
+	*kindp |= inex;
+	return s0;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa.h b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa.h
new file mode 100644
index 0000000..9e1cea0
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa.h
@@ -0,0 +1,155 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#ifndef GDTOA_H_INCLUDED
+#define GDTOA_H_INCLUDED
+
+#include "arith.h"
+#include <stddef.h> /* for size_t */
+
+#ifndef Long
+#define Long int
+#endif
+#ifndef ULong
+typedef unsigned Long ULong;
+#endif
+#ifndef UShort
+typedef unsigned short UShort;
+#endif
+
+#ifndef ANSI
+#ifdef KR_headers
+#define ANSI(x) ()
+#define Void /*nothing*/
+#else
+#define ANSI(x) x
+#define Void void
+#endif
+#endif /* ANSI */
+
+#ifndef CONST
+#ifdef KR_headers
+#define CONST /* blank */
+#else
+#define CONST const
+#endif
+#endif /* CONST */
+
+ enum {	/* return values from strtodg */
+	STRTOG_Zero	= 0x000,
+	STRTOG_Normal	= 0x001,
+	STRTOG_Denormal	= 0x002,
+	STRTOG_Infinite	= 0x003,
+	STRTOG_NaN	= 0x004,
+	STRTOG_NaNbits	= 0x005,
+	STRTOG_NoNumber	= 0x006,
+	STRTOG_NoMemory = 0x007,
+	STRTOG_Retmask	= 0x00f,
+
+	/* The following may be or-ed into one of the above values. */
+
+	STRTOG_Inexlo	= 0x010, /* returned result rounded toward zero */
+	STRTOG_Inexhi	= 0x020, /* returned result rounded away from zero */
+	STRTOG_Inexact	= 0x030,
+	STRTOG_Underflow= 0x040,
+	STRTOG_Overflow	= 0x080,
+	STRTOG_Neg	= 0x100 /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
+	};
+
+ typedef struct
+FPI {
+	int nbits;
+	int emin;
+	int emax;
+	int rounding;
+	int sudden_underflow;
+	} 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
+	};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char* __dtoa  ANSI((double d, int mode, int ndigits, int *decpt,
+			int *sign, char **rve));
+extern char* __gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,
+			int mode, int ndigits, int *decpt, char **rve));
+extern void __freedtoa ANSI((char*));
+extern float  strtof ANSI((CONST char *, char **));
+extern double strtod ANSI((CONST char *, char **));
+extern int __strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*));
+
+extern char*	__g_ddfmt  ANSI((char*, double*, int, size_t));
+extern char*	__g_dfmt   ANSI((char*, double*, int, size_t));
+extern char*	__g_ffmt   ANSI((char*, float*,  int, size_t));
+extern char*	__g_Qfmt   ANSI((char*, void*,   int, size_t));
+extern char*	__g_xfmt   ANSI((char*, void*,   int, size_t));
+extern char*	__g_xLfmt  ANSI((char*, void*,   int, size_t));
+
+extern int	__strtoId  ANSI((CONST char*, char**, double*, double*));
+extern int	__strtoIdd ANSI((CONST char*, char**, double*, double*));
+extern int	__strtoIf  ANSI((CONST char*, char**, float*, float*));
+extern int	__strtoIQ  ANSI((CONST char*, char**, void*, void*));
+extern int	__strtoIx  ANSI((CONST char*, char**, void*, void*));
+extern int	__strtoIxL ANSI((CONST char*, char**, void*, void*));
+extern int	__strtord  ANSI((CONST char*, char**, int, double*));
+extern int	__strtordd ANSI((CONST char*, char**, int, double*));
+extern int	__strtorf  ANSI((CONST char*, char**, int, float*));
+extern int	__strtorQ  ANSI((CONST char*, char**, int, void*));
+extern int	__strtorx  ANSI((CONST char*, char**, int, void*));
+extern int	__strtorxL ANSI((CONST char*, char**, int, void*));
+#if 1
+extern int	__strtodI  ANSI((CONST char*, char**, double*));
+extern int	__strtopd  ANSI((CONST char*, char**, double*));
+extern int	__strtopdd ANSI((CONST char*, char**, double*));
+extern int	__strtopf  ANSI((CONST char*, char**, float*));
+extern int	__strtopQ  ANSI((CONST char*, char**, void*));
+extern int	__strtopx  ANSI((CONST char*, char**, void*));
+extern int	__strtopxL ANSI((CONST char*, char**, void*));
+#else
+#define __strtopd(s,se,x) strtord(s,se,1,x)
+#define __strtopdd(s,se,x) strtordd(s,se,1,x)
+#define __strtopf(s,se,x) strtorf(s,se,1,x)
+#define __strtopQ(s,se,x) strtorQ(s,se,1,x)
+#define __strtopx(s,se,x) strtorx(s,se,1,x)
+#define __strtopxL(s,se,x) strtorxL(s,se,1,x)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* GDTOA_H_INCLUDED */
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa_fltrnds.h b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa_fltrnds.h
new file mode 100644
index 0000000..33e5f9e
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoa_fltrnds.h
@@ -0,0 +1,18 @@
+	FPI *fpi, fpi1;
+	int Rounding;
+#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
+	Rounding = Flt_Rounds;
+#else /*}{*/
+	Rounding = 1;
+	switch(fegetround()) {
+	  case FE_TOWARDZERO:	Rounding = 0; break;
+	  case FE_UPWARD:	Rounding = 2; break;
+	  case FE_DOWNWARD:	Rounding = 3;
+	  }
+#endif /*}}*/
+	fpi = &fpi0;
+	if (Rounding != 1) {
+		fpi1 = fpi0;
+		fpi = &fpi1;
+		fpi1.rounding = Rounding;
+		}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/gdtoaimp.h b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoaimp.h
new file mode 100644
index 0000000..7a36967
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoaimp.h
@@ -0,0 +1,665 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998-2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* This is a variation on dtoa.c that converts arbitary binary
+   floating-point formats to and from decimal notation.  It uses
+   double-precision arithmetic internally, so there are still
+   various #ifdefs that adapt the calculations to the native
+   double-precision arithmetic (any of IEEE, VAX D_floating,
+   or IBM mainframe arithmetic).
+
+   Please send bug reports to David M. Gay (dmg at acm dot org,
+   with " at " changed at "@" and " dot " changed to ".").
+ */
+
+/* On a machine with IEEE extended-precision registers, it is
+ * necessary to specify double-precision (53-bit) rounding precision
+ * before invoking strtod or dtoa.  If the machine uses (the equivalent
+ * of) Intel 80x87 arithmetic, the call
+ *	_control87(PC_53, MCW_PC);
+ * does this with many compilers.  Whether this or another call is
+ * appropriate depends on the compiler; for this to work, it may be
+ * necessary to #include "float.h" or another system-dependent header
+ * file.
+ */
+
+/* strtod for IEEE-, VAX-, and IBM-arithmetic machines.
+ *
+ * This strtod returns a nearest machine number to the input decimal
+ * string (or sets errno to ERANGE).  With IEEE arithmetic, ties are
+ * broken by the IEEE round-even rule.  Otherwise ties are broken by
+ * biased rounding (add half and chop).
+ *
+ * Inspired loosely by William D. Clinger's paper "How to Read Floating
+ * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 112-126].
+ *
+ * Modifications:
+ *
+ *	1. We only require IEEE, IBM, or VAX double-precision
+ *		arithmetic (not IEEE double-extended).
+ *	2. We get by with floating-point arithmetic in a case that
+ *		Clinger missed -- when we're computing d * 10^n
+ *		for a small integer d and the integer n is not too
+ *		much larger than 22 (the maximum integer k for which
+ *		we can represent 10^k exactly), we may be able to
+ *		compute (d*10^k) * 10^(e-k) with just one roundoff.
+ *	3. Rather than a bit-at-a-time adjustment of the binary
+ *		result in the hard case, we use floating-point
+ *		arithmetic to determine the adjustment to within
+ *		one bit; only in really hard cases do we need to
+ *		compute a second residual.
+ *	4. Because of 3., we don't need a large table of powers of 10
+ *		for ten-to-e (just some small tables, e.g. of 10^k
+ *		for 0 <= k <= 22).
+ */
+
+/*
+ * #define IEEE_8087 for IEEE-arithmetic machines where the least
+ *	significant byte has the lowest address.
+ * #define IEEE_MC68k for IEEE-arithmetic machines where the most
+ *	significant byte has the lowest address.
+ * #define Long int on machines with 32-bit ints and 64-bit longs.
+ * #define Sudden_Underflow for IEEE-format machines without gradual
+ *	underflow (i.e., that flush to zero on underflow).
+ * #define IBM for IBM mainframe-style floating-point arithmetic.
+ * #define VAX for VAX-style floating-point arithmetic (D_floating).
+ * #define No_leftright to omit left-right logic in fast floating-point
+ *	computation of dtoa and gdtoa.  This will cause modes 4 and 5 to be
+ *	treated the same as modes 2 and 3 for some inputs.
+ * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3.
+ * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
+ *	that use extended-precision instructions to compute rounded
+ *	products and quotients) with IBM.
+ * #define ROUND_BIASED for IEEE-format with biased rounding and arithmetic
+ *	that rounds toward +Infinity.
+ * #define ROUND_BIASED_without_Round_Up for IEEE-format with biased
+ *	rounding when the underlying floating-point arithmetic uses
+ *	unbiased rounding.  This prevent using ordinary floating-point
+ *	arithmetic when the result could be computed with one rounding error.
+ * #define Inaccurate_Divide for IEEE-format with correctly rounded
+ *	products but inaccurate quotients, e.g., for Intel i860.
+ * #define NO_LONG_LONG on machines that do not have a "long long"
+ *	integer type (of >= 64 bits).  On such machines, you can
+ *	#define Just_16 to store 16 bits per 32-bit Long when doing
+ *	high-precision integer arithmetic.  Whether this speeds things
+ *	up or slows things down depends on the machine and the number
+ *	being converted.  If long long is available and the name is
+ *	something other than "long long", #define Llong to be the name,
+ *	and if "unsigned Llong" does not work as an unsigned version of
+ *	Llong, #define #ULLong to be the corresponding unsigned type.
+ * #define KR_headers for old-style C function headers.
+ * #define Bad_float_h if your system lacks a float.h or if it does not
+ *	define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
+ *	FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
+ * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
+ *	if memory is available and otherwise does something you deem
+ *	appropriate.  If MALLOC is undefined, malloc will be invoked
+ *	directly -- and assumed always to succeed.  Similarly, if you
+ *	want something other than the system's free() to be called to
+ *	recycle memory acquired from MALLOC, #define FREE to be the
+ *	name of the alternate routine.  (FREE or free is only called in
+ *	pathological cases, e.g., in a gdtoa call after a gdtoa return in
+ *	mode 3 with thousands of digits requested.)
+ * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
+ *	memory allocations from a private pool of memory when possible.
+ *	When used, the private pool is PRIVATE_MEM bytes long:  2304 bytes,
+ *	unless #defined to be a different length.  This default length
+ *	suffices to get rid of MALLOC calls except for unusual cases,
+ *	such as decimal-to-binary conversion of a very long string of
+ *	digits.  When converting IEEE double precision values, the
+ *	longest string gdtoa can return is about 751 bytes long.  For
+ *	conversions by strtod of strings of 800 digits and all gdtoa
+ *	conversions of IEEE doubles in single-threaded executions with
+ *	8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with
+ *	4-byte pointers, PRIVATE_MEM >= 7112 appears adequate.
+ * #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK
+ *	#defined automatically on IEEE systems.  On such systems,
+ *	when INFNAN_CHECK is #defined, strtod checks
+ *	for Infinity and NaN (case insensitively).
+ *	When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
+ *	strtodg also accepts (case insensitively) strings of the form
+ *	NaN(x), where x is a string of hexadecimal digits (optionally
+ *	preceded by 0x or 0X) and spaces; if there is only one string
+ *	of hexadecimal digits, it is taken for the fraction bits of the
+ *	resulting NaN; if there are two or more strings of hexadecimal
+ *	digits, each string is assigned to the next available sequence
+ *	of 32-bit words of fractions bits (starting with the most
+ *	significant), right-aligned in each sequence.
+ *	Unless GDTOA_NON_PEDANTIC_NANCHECK is #defined, input "NaN(...)"
+ *	is consumed even when ... has the wrong form (in which case the
+ *	"(...)" is consumed but ignored).
+ * #define MULTIPLE_THREADS if the system offers preemptively scheduled
+ *	multiple threads.  In this case, you must provide (or suitably
+ *	#define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
+ *	by FREE_DTOA_LOCK(n) for n = 0 or 1.  (The second lock, accessed
+ *	in pow5mult, ensures lazy evaluation of only one copy of high
+ *	powers of 5; omitting this lock would introduce a small
+ *	probability of wasting memory, but would otherwise be harmless.)
+ *	You must also invoke freedtoa(s) to free the value s returned by
+ *	dtoa.  You may do so whether or not MULTIPLE_THREADS is #defined.
+ * #define IMPRECISE_INEXACT if you do not care about the setting of
+ *	the STRTOG_Inexact bits in the special case of doing IEEE double
+ *	precision conversions (which could also be done by the strtod in
+ *	dtoa.c).
+ * #define NO_HEX_FP to disable recognition of C9x's hexadecimal
+ *	floating-point constants.
+ * #define -DNO_ERRNO to suppress setting errno (in strtod.c and
+ *	strtodg.c).
+ * #define NO_STRING_H to use private versions of memcpy.
+ *	On some K&R systems, it may also be necessary to
+ *	#define DECLARE_SIZE_T in this case.
+ * #define USE_LOCALE to use the current locale's decimal_point value.
+ */
+
+#ifndef GDTOAIMP_H_INCLUDED
+#define GDTOAIMP_H_INCLUDED
+#include "gdtoa.h"
+#include "gd_qnan.h"
+#ifdef Honor_FLT_ROUNDS
+#include <fenv.h>
+#endif
+
+#ifdef DEBUG
+#include "stdio.h"
+#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
+#endif
+
+#include "stdlib.h"
+#include "string.h"
+
+#ifdef KR_headers
+#define Char char
+#else
+#define Char void
+#endif
+
+#ifdef MALLOC
+extern Char *MALLOC ANSI((size_t));
+#else
+#define MALLOC malloc
+#endif
+
+#undef IEEE_Arith
+#undef Avoid_Underflow
+#ifdef IEEE_MC68k
+#define IEEE_Arith
+#endif
+#ifdef IEEE_8087
+#define IEEE_Arith
+#endif
+
+#include "errno.h"
+#ifdef Bad_float_h
+
+#ifdef IEEE_Arith
+#define DBL_DIG 15
+#define DBL_MAX_10_EXP 308
+#define DBL_MAX_EXP 1024
+#define FLT_RADIX 2
+#define DBL_MAX 1.7976931348623157e+308
+#endif
+
+#ifdef IBM
+#define DBL_DIG 16
+#define DBL_MAX_10_EXP 75
+#define DBL_MAX_EXP 63
+#define FLT_RADIX 16
+#define DBL_MAX 7.2370055773322621e+75
+#endif
+
+#ifdef VAX
+#define DBL_DIG 16
+#define DBL_MAX_10_EXP 38
+#define DBL_MAX_EXP 127
+#define FLT_RADIX 2
+#define DBL_MAX 1.7014118346046923e+38
+#define n_bigtens 2
+#endif
+
+#ifndef LONG_MAX
+#define LONG_MAX 2147483647
+#endif
+
+#else /* ifndef Bad_float_h */
+#include "float.h"
+#endif /* Bad_float_h */
+
+#ifdef IEEE_Arith
+#define Scale_Bit 0x10
+#define n_bigtens 5
+#endif
+
+#ifdef IBM
+#define n_bigtens 3
+#endif
+
+#ifdef VAX
+#define n_bigtens 2
+#endif
+
+#ifndef __MATH_H__
+#include "math.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
+Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
+#endif
+
+typedef union { double d; ULong L[2]; } U;
+
+#ifdef IEEE_8087
+#define word0(x) (x)->L[1]
+#define word1(x) (x)->L[0]
+#else
+#define word0(x) (x)->L[0]
+#define word1(x) (x)->L[1]
+#endif
+#define dval(x) (x)->d
+
+/* The following definition of Storeinc is appropriate for MIPS processors.
+ * An alternative that might be better on some machines is
+ * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
+ */
+#if defined(IEEE_8087) + defined(VAX)
+#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
+((unsigned short *)a)[0] = (unsigned short)c, a++)
+#else
+#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
+((unsigned short *)a)[1] = (unsigned short)c, a++)
+#endif
+
+/* #define P DBL_MANT_DIG */
+/* Ten_pmax = floor(P*log(2)/log(5)) */
+/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
+/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
+/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
+
+#ifdef IEEE_Arith
+#define Exp_shift  20
+#define Exp_shift1 20
+#define Exp_msk1    0x100000
+#define Exp_msk11   0x100000
+#define Exp_mask  0x7ff00000
+#define P 53
+#define Bias 1023
+#define Emin (-1022)
+#define Exp_1  0x3ff00000
+#define Exp_11 0x3ff00000
+#define Ebits 11
+#define Frac_mask  0xfffff
+#define Frac_mask1 0xfffff
+#define Ten_pmax 22
+#define Bletch 0x10
+#define Bndry_mask  0xfffff
+#define Bndry_mask1 0xfffff
+#define LSB 1
+#define Sign_bit 0x80000000
+#define Log2P 1
+#define Tiny0 0
+#define Tiny1 1
+#define Quick_max 14
+#define Int_max 14
+
+#ifndef Flt_Rounds
+#ifdef FLT_ROUNDS
+#define Flt_Rounds FLT_ROUNDS
+#else
+#define Flt_Rounds 1
+#endif
+#endif /*Flt_Rounds*/
+
+#else /* ifndef IEEE_Arith */
+#undef  Sudden_Underflow
+#define Sudden_Underflow
+#ifdef IBM
+#undef Flt_Rounds
+#define Flt_Rounds 0
+#define Exp_shift  24
+#define Exp_shift1 24
+#define Exp_msk1   0x1000000
+#define Exp_msk11  0x1000000
+#define Exp_mask  0x7f000000
+#define P 14
+#define Bias 65
+#define Exp_1  0x41000000
+#define Exp_11 0x41000000
+#define Ebits 8	/* exponent has 7 bits, but 8 is the right value in b2d */
+#define Frac_mask  0xffffff
+#define Frac_mask1 0xffffff
+#define Bletch 4
+#define Ten_pmax 22
+#define Bndry_mask  0xefffff
+#define Bndry_mask1 0xffffff
+#define LSB 1
+#define Sign_bit 0x80000000
+#define Log2P 4
+#define Tiny0 0x100000
+#define Tiny1 0
+#define Quick_max 14
+#define Int_max 15
+#else /* VAX */
+#undef Flt_Rounds
+#define Flt_Rounds 1
+#define Exp_shift  23
+#define Exp_shift1 7
+#define Exp_msk1    0x80
+#define Exp_msk11   0x800000
+#define Exp_mask  0x7f80
+#define P 56
+#define Bias 129
+#define Emin (-127)
+#define Exp_1  0x40800000
+#define Exp_11 0x4080
+#define Ebits 8
+#define Frac_mask  0x7fffff
+#define Frac_mask1 0xffff007f
+#define Ten_pmax 24
+#define Bletch 2
+#define Bndry_mask  0xffff007f
+#define Bndry_mask1 0xffff007f
+#define LSB 0x10000
+#define Sign_bit 0x8000
+#define Log2P 1
+#define Tiny0 0x80
+#define Tiny1 0
+#define Quick_max 15
+#define Int_max 15
+#endif /* IBM, VAX */
+#endif /* IEEE_Arith */
+
+#ifndef IEEE_Arith
+#define ROUND_BIASED
+#else
+#ifdef ROUND_BIASED_without_Round_Up
+#undef  ROUND_BIASED
+#define ROUND_BIASED
+#endif
+#endif
+
+#ifdef RND_PRODQUOT
+#define rounded_product(a,b) a = rnd_prod(a, b)
+#define rounded_quotient(a,b) a = rnd_quot(a, b)
+#ifdef KR_headers
+extern double rnd_prod(), rnd_quot();
+#else
+extern double rnd_prod(double, double), rnd_quot(double, double);
+#endif
+#else
+#define rounded_product(a,b) a *= b
+#define rounded_quotient(a,b) a /= b
+#endif
+
+#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
+#define Big1 0xffffffff
+
+#undef  Pack_16
+#ifndef Pack_32
+#define Pack_32
+#endif
+
+#ifdef NO_LONG_LONG
+#undef ULLong
+#ifdef Just_16
+#undef Pack_32
+#define Pack_16
+/* When Pack_32 is not defined, we store 16 bits per 32-bit Long.
+ * This makes some inner loops simpler and sometimes saves work
+ * during multiplications, but it often seems to make things slightly
+ * slower.  Hence the default is now to store 32 bits per Long.
+ */
+#endif
+#else	/* long long available */
+#ifndef Llong
+#define Llong long long
+#endif
+#ifndef ULLong
+#define ULLong unsigned Llong
+#endif
+#endif /* NO_LONG_LONG */
+
+#ifdef Pack_32
+#define ULbits 32
+#define kshift 5
+#define kmask 31
+#define ALL_ON 0xffffffff
+#else
+#define ULbits 16
+#define kshift 4
+#define kmask 15
+#define ALL_ON 0xffff
+#endif
+
+#ifndef MULTIPLE_THREADS
+#define ACQUIRE_DTOA_LOCK(n)	/*nothing*/
+#define FREE_DTOA_LOCK(n)	/*nothing*/
+#else
+#include "thread_private.h"
+extern void *__dtoa_locks[];
+#define ACQUIRE_DTOA_LOCK(n)	_MUTEX_LOCK(&__dtoa_locks[n])
+#define FREE_DTOA_LOCK(n)	_MUTEX_UNLOCK(&__dtoa_locks[n])
+#endif
+
+#define Kmax 9
+
+ struct
+Bigint {
+	struct Bigint *next;
+	int k, maxwds, sign, wds;
+	ULong x[1];
+	};
+
+ typedef struct Bigint Bigint;
+
+#ifdef NO_STRING_H
+#ifdef DECLARE_SIZE_T
+typedef unsigned int size_t;
+#endif
+extern void memcpy_D2A ANSI((void*, const void*, size_t));
+#define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
+#else /* !NO_STRING_H */
+#define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
+#endif /* NO_STRING_H */
+
+#define dtoa __dtoa
+#define gdtoa __gdtoa
+#define freedtoa __freedtoa
+#define strtodg __strtodg
+#define g_ddfmt __g_ddfmt
+#define g_dfmt __g_dfmt
+#define g_ffmt __g_ffmt
+#define g_Qfmt __g_Qfmt
+#define g_xfmt __g_xfmt
+#define g_xLfmt __g_xLfmt
+#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
+
+#define Balloc __Balloc_D2A
+#define Bfree __Bfree_D2A
+#define ULtoQ __ULtoQ_D2A
+#define ULtof __ULtof_D2A
+#define ULtod __ULtod_D2A
+#define ULtodd __ULtodd_D2A
+#define ULtox __ULtox_D2A
+#define ULtoxL __ULtoxL_D2A
+#define any_on __any_on_D2A
+#define b2d __b2d_D2A
+#define bigtens __bigtens_D2A
+#define cmp __cmp_D2A
+#define copybits __copybits_D2A
+#define d2b __d2b_D2A
+#define decrement __decrement_D2A
+#define diff __diff_D2A
+#define dtoa_result __dtoa_result_D2A
+#define g__fmt __g__fmt_D2A
+#define gethex __gethex_D2A
+#define hexdig __hexdig_D2A
+#define hexnan __hexnan_D2A
+#define hi0bits(x) __hi0bits_D2A((ULong)(x))
+#define hi0bits_D2A __hi0bits_D2A
+#define i2b __i2b_D2A
+#define increment __increment_D2A
+#define lo0bits __lo0bits_D2A
+#define lshift __lshift_D2A
+#define match __match_D2A
+#define mult __mult_D2A
+#define multadd __multadd_D2A
+#define nrv_alloc __nrv_alloc_D2A
+#define pow5mult __pow5mult_D2A
+#define quorem __quorem_D2A
+#define ratio __ratio_D2A
+#define rshift __rshift_D2A
+#define rv_alloc __rv_alloc_D2A
+#define s2b __s2b_D2A
+#define set_ones __set_ones_D2A
+#define strcp __strcp_D2A
+#define strtoIg __strtoIg_D2A
+#define sulp __sulp_D2A
+#define sum __sum_D2A
+#define tens __tens_D2A
+#define tinytens __tinytens_D2A
+#define tinytens __tinytens_D2A
+#define trailz __trailz_D2A
+#define ulp __ulp_D2A
+
+ extern char *dtoa_result;
+ extern CONST double bigtens[], tens[], tinytens[];
+ extern unsigned char hexdig[];
+
+ extern Bigint *Balloc ANSI((int));
+ extern void Bfree ANSI((Bigint*));
+ extern void ULtof ANSI((ULong*, ULong*, Long, int));
+ extern void ULtod ANSI((ULong*, ULong*, Long, int));
+ extern void ULtodd ANSI((ULong*, ULong*, Long, int));
+ extern void ULtoQ ANSI((ULong*, ULong*, Long, int));
+ extern void ULtox ANSI((UShort*, ULong*, Long, int));
+ extern void ULtoxL ANSI((ULong*, ULong*, Long, int));
+ extern ULong any_on ANSI((Bigint*, int));
+ extern double b2d ANSI((Bigint*, int*));
+ extern int cmp ANSI((Bigint*, Bigint*));
+ extern void copybits ANSI((ULong*, int, Bigint*));
+ extern Bigint *d2b ANSI((double, int*, int*));
+ extern void decrement ANSI((Bigint*));
+ extern Bigint *diff ANSI((Bigint*, Bigint*));
+ extern char *dtoa ANSI((double d, int mode, int ndigits,
+			int *decpt, int *sign, char **rve));
+ extern char *g__fmt ANSI((char*, char*, char*, int, ULong, size_t));
+ extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int));
+ extern void hexdig_init_D2A(Void);
+ extern int hexnan ANSI((CONST char**, FPI*, ULong*));
+ extern int hi0bits_D2A ANSI((ULong));
+ extern Bigint *i2b ANSI((int));
+ extern Bigint *increment ANSI((Bigint*));
+ extern int lo0bits ANSI((ULong*));
+ extern Bigint *lshift ANSI((Bigint*, int));
+ extern int match ANSI((CONST char**, char*));
+ extern Bigint *mult ANSI((Bigint*, Bigint*));
+ extern Bigint *multadd ANSI((Bigint*, int, int));
+ extern char *nrv_alloc ANSI((char*, char **, int));
+ extern Bigint *pow5mult ANSI((Bigint*, int));
+ extern int quorem ANSI((Bigint*, Bigint*));
+ extern double ratio ANSI((Bigint*, Bigint*));
+ extern void rshift ANSI((Bigint*, int));
+ extern char *rv_alloc ANSI((int));
+ extern Bigint *s2b ANSI((CONST char*, int, int, ULong, int));
+ extern Bigint *set_ones ANSI((Bigint*, int));
+ extern char *strcp ANSI((char*, const char*));
+ extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*));
+ extern double strtod ANSI((const char *s00, char **se));
+ extern Bigint *sum ANSI((Bigint*, Bigint*));
+ extern int trailz ANSI((Bigint*));
+ extern double ulp ANSI((U*));
+
+#ifdef __cplusplus
+}
+#endif
+/*
+ * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c.  Prior to
+ * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0,
+ * respectively), but now are determined by compiling and running
+ * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1.
+ * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=...
+ * and -DNAN_WORD1=...  values if necessary.  This should still work.
+ * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
+ */
+#ifdef IEEE_Arith
+#ifndef NO_INFNAN_CHECK
+#undef INFNAN_CHECK
+#define INFNAN_CHECK
+#endif
+#ifdef IEEE_MC68k
+#define _0 0
+#define _1 1
+#ifndef NAN_WORD0
+#define NAN_WORD0 d_QNAN0
+#endif
+#ifndef NAN_WORD1
+#define NAN_WORD1 d_QNAN1
+#endif
+#else
+#define _0 1
+#define _1 0
+#ifndef NAN_WORD0
+#define NAN_WORD0 d_QNAN1
+#endif
+#ifndef NAN_WORD1
+#define NAN_WORD1 d_QNAN0
+#endif
+#endif
+#else
+#undef INFNAN_CHECK
+#endif
+
+#undef SI
+#ifdef Sudden_Underflow
+#define SI 1
+#else
+#define SI 0
+#endif
+
+#endif /* GDTOAIMP_H_INCLUDED */
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/gethex.c b/libc/upstream-openbsd/lib/libc/gdtoa/gethex.c
new file mode 100644
index 0000000..7ace0fa
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/gethex.c
@@ -0,0 +1,360 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+#ifdef USE_LOCALE
+#include "locale.h"
+#endif
+
+ int
+#ifdef KR_headers
+gethex(sp, fpi, exp, bp, sign)
+	CONST char **sp; FPI *fpi; Long *exp; Bigint **bp; int sign;
+#else
+gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
+#endif
+{
+	Bigint *b;
+	CONST unsigned char *decpt, *s0, *s, *s1;
+	int big, esign, havedig, irv, j, k, n, n0, nbits, up, zret;
+	ULong L, lostbits, *x;
+	Long e, e1;
+#ifdef USE_LOCALE
+	int i;
+#ifdef NO_LOCALE_CACHE
+	const unsigned char *decimalpoint = (unsigned char*)localeconv()->decimal_point;
+#else
+	const unsigned char *decimalpoint;
+	static unsigned char *decimalpoint_cache;
+	if (!(s0 = decimalpoint_cache)) {
+		s0 = (unsigned char*)localeconv()->decimal_point;
+		if ((decimalpoint_cache = (char*)MALLOC(strlen(s0) + 1))) {
+			strlcpy(decimalpoint_cache, s0, strlen(s0) + 1);
+			s0 = decimalpoint_cache;
+			}
+		}
+	decimalpoint = s0;
+#endif
+#endif
+
+	if (!hexdig['0'])
+		hexdig_init_D2A();
+	*bp = 0;
+	havedig = 0;
+	s0 = *(CONST unsigned char **)sp + 2;
+	while(s0[havedig] == '0')
+		havedig++;
+	s0 += havedig;
+	s = s0;
+	decpt = 0;
+	zret = 0;
+	e = 0;
+	if (hexdig[*s])
+		havedig++;
+	else {
+		zret = 1;
+#ifdef USE_LOCALE
+		for(i = 0; decimalpoint[i]; ++i) {
+			if (s[i] != decimalpoint[i])
+				goto pcheck;
+			}
+		decpt = s += i;
+#else
+		if (*s != '.')
+			goto pcheck;
+		decpt = ++s;
+#endif
+		if (!hexdig[*s])
+			goto pcheck;
+		while(*s == '0')
+			s++;
+		if (hexdig[*s])
+			zret = 0;
+		havedig = 1;
+		s0 = s;
+		}
+	while(hexdig[*s])
+		s++;
+#ifdef USE_LOCALE
+	if (*s == *decimalpoint && !decpt) {
+		for(i = 1; decimalpoint[i]; ++i) {
+			if (s[i] != decimalpoint[i])
+				goto pcheck;
+			}
+		decpt = s += i;
+#else
+	if (*s == '.' && !decpt) {
+		decpt = ++s;
+#endif
+		while(hexdig[*s])
+			s++;
+		}/*}*/
+	if (decpt)
+		e = -(((Long)(s-decpt)) << 2);
+ pcheck:
+	s1 = s;
+	big = esign = 0;
+	switch(*s) {
+	  case 'p':
+	  case 'P':
+		switch(*++s) {
+		  case '-':
+			esign = 1;
+			/* no break */
+		  case '+':
+			s++;
+		  }
+		if ((n = hexdig[*s]) == 0 || n > 0x19) {
+			s = s1;
+			break;
+			}
+		e1 = n - 0x10;
+		while((n = hexdig[*++s]) !=0 && n <= 0x19) {
+			if (e1 & 0xf8000000)
+				big = 1;
+			e1 = 10*e1 + n - 0x10;
+			}
+		if (esign)
+			e1 = -e1;
+		e += e1;
+	  }
+	*sp = (char*)s;
+	if (!havedig)
+		*sp = (char*)s0 - 1;
+	if (zret)
+		return STRTOG_Zero;
+	if (big) {
+		if (esign) {
+			switch(fpi->rounding) {
+			  case FPI_Round_up:
+				if (sign)
+					break;
+				goto ret_tiny;
+			  case FPI_Round_down:
+				if (!sign)
+					break;
+				goto ret_tiny;
+			  }
+			goto retz;
+ ret_tiny:
+			b = Balloc(0);
+			if (b == NULL)
+				return (STRTOG_NoMemory);
+			b->wds = 1;
+			b->x[0] = 1;
+			goto dret;
+			}
+		switch(fpi->rounding) {
+		  case FPI_Round_near:
+			goto ovfl1;
+		  case FPI_Round_up:
+			if (!sign)
+				goto ovfl1;
+			goto ret_big;
+		  case FPI_Round_down:
+			if (sign)
+				goto ovfl1;
+			goto ret_big;
+		  }
+ ret_big:
+		nbits = fpi->nbits;
+		n0 = n = nbits >> kshift;
+		if (nbits & kmask)
+			++n;
+		for(j = n, k = 0; j >>= 1; ++k);
+		*bp = b = Balloc(k);
+		if (*bp == NULL)
+			return (STRTOG_NoMemory);
+		b->wds = n;
+		for(j = 0; j < n0; ++j)
+			b->x[j] = ALL_ON;
+		if (n > n0)
+			b->x[j] = ULbits >> (ULbits - (nbits & kmask));
+		*exp = fpi->emin;
+		return STRTOG_Normal | STRTOG_Inexlo;
+		}
+	n = s1 - s0 - 1;
+	for(k = 0; n > (1 << (kshift-2)) - 1; n >>= 1)
+		k++;
+	b = Balloc(k);
+	if (b == NULL)
+		return (STRTOG_NoMemory);
+	x = b->x;
+	n = 0;
+	L = 0;
+#ifdef USE_LOCALE
+	for(i = 0; decimalpoint[i+1]; ++i);
+#endif
+	while(s1 > s0) {
+#ifdef USE_LOCALE
+		if (*--s1 == decimalpoint[i]) {
+			s1 -= i;
+			continue;
+			}
+#else
+		if (*--s1 == '.')
+			continue;
+#endif
+		if (n == ULbits) {
+			*x++ = L;
+			L = 0;
+			n = 0;
+			}
+		L |= (hexdig[*s1] & 0x0f) << n;
+		n += 4;
+		}
+	*x++ = L;
+	b->wds = n = x - b->x;
+	n = ULbits*n - hi0bits(L);
+	nbits = fpi->nbits;
+	lostbits = 0;
+	x = b->x;
+	if (n > nbits) {
+		n -= nbits;
+		if (any_on(b,n)) {
+			lostbits = 1;
+			k = n - 1;
+			if (x[k>>kshift] & 1 << (k & kmask)) {
+				lostbits = 2;
+				if (k > 0 && any_on(b,k))
+					lostbits = 3;
+				}
+			}
+		rshift(b, n);
+		e += n;
+		}
+	else if (n < nbits) {
+		n = nbits - n;
+		b = lshift(b, n);
+		if (b == NULL)
+			return (STRTOG_NoMemory);
+		e -= n;
+		x = b->x;
+		}
+	if (e > fpi->emax) {
+ ovfl:
+		Bfree(b);
+ ovfl1:
+#ifndef NO_ERRNO
+		errno = ERANGE;
+#endif
+		return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
+		}
+	irv = STRTOG_Normal;
+	if (e < fpi->emin) {
+		irv = STRTOG_Denormal;
+		n = fpi->emin - e;
+		if (n >= nbits) {
+			switch (fpi->rounding) {
+			  case FPI_Round_near:
+				if (n == nbits && (n < 2 || any_on(b,n-1)))
+					goto one_bit;
+				break;
+			  case FPI_Round_up:
+				if (!sign)
+					goto one_bit;
+				break;
+			  case FPI_Round_down:
+				if (sign) {
+ one_bit:
+					x[0] = b->wds = 1;
+ dret:
+					*bp = b;
+					*exp = fpi->emin;
+#ifndef NO_ERRNO
+					errno = ERANGE;
+#endif
+					return STRTOG_Denormal | STRTOG_Inexhi
+						| STRTOG_Underflow;
+					}
+			  }
+			Bfree(b);
+ retz:
+#ifndef NO_ERRNO
+			errno = ERANGE;
+#endif
+			return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow;
+			}
+		k = n - 1;
+		if (lostbits)
+			lostbits = 1;
+		else if (k > 0)
+			lostbits = any_on(b,k);
+		if (x[k>>kshift] & 1 << (k & kmask))
+			lostbits |= 2;
+		nbits -= n;
+		rshift(b,n);
+		e = fpi->emin;
+		}
+	if (lostbits) {
+		up = 0;
+		switch(fpi->rounding) {
+		  case FPI_Round_zero:
+			break;
+		  case FPI_Round_near:
+			if (lostbits & 2
+			 && (lostbits | x[0]) & 1)
+				up = 1;
+			break;
+		  case FPI_Round_up:
+			up = 1 - sign;
+			break;
+		  case FPI_Round_down:
+			up = sign;
+		  }
+		if (up) {
+			k = b->wds;
+			b = increment(b);
+			if (b == NULL)
+				return (STRTOG_NoMemory);
+			x = b->x;
+			if (irv == STRTOG_Denormal) {
+				if (nbits == fpi->nbits - 1
+				 && x[nbits >> kshift] & 1 << (nbits & kmask))
+					irv =  STRTOG_Normal;
+				}
+			else if (b->wds > k
+			 || ((n = nbits & kmask) !=0
+			      && hi0bits(x[k-1]) < 32-n)) {
+				rshift(b,1);
+				if (++e > fpi->emax)
+					goto ovfl;
+				}
+			irv |= STRTOG_Inexhi;
+			}
+		else
+			irv |= STRTOG_Inexlo;
+		}
+	*bp = b;
+	*exp = e;
+	return irv;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/gmisc.c b/libc/upstream-openbsd/lib/libc/gdtoa/gmisc.c
new file mode 100644
index 0000000..8270ef9
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/gmisc.c
@@ -0,0 +1,86 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ void
+#ifdef KR_headers
+rshift(b, k) Bigint *b; int k;
+#else
+rshift(Bigint *b, int k)
+#endif
+{
+	ULong *x, *x1, *xe, y;
+	int n;
+
+	x = x1 = b->x;
+	n = k >> kshift;
+	if (n < b->wds) {
+		xe = x + b->wds;
+		x += n;
+		if (k &= kmask) {
+			n = ULbits - k;
+			y = *x++ >> k;
+			while(x < xe) {
+				*x1++ = (y | (*x << n)) & ALL_ON;
+				y = *x++ >> k;
+				}
+			if ((*x1 = y) !=0)
+				x1++;
+			}
+		else
+			while(x < xe)
+				*x1++ = *x++;
+		}
+	if ((b->wds = x1 - b->x) == 0)
+		b->x[0] = 0;
+	}
+
+ int
+#ifdef KR_headers
+trailz(b) Bigint *b;
+#else
+trailz(Bigint *b)
+#endif
+{
+	ULong L, *x, *xe;
+	int n = 0;
+
+	x = b->x;
+	xe = x + b->wds;
+	for(n = 0; x < xe && !*x; x++)
+		n += ULbits;
+	if (x < xe) {
+		L = *x;
+		n += lo0bits(&L);
+		}
+	return n;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/hd_init.c b/libc/upstream-openbsd/lib/libc/gdtoa/hd_init.c
new file mode 100644
index 0000000..fa6e18d
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/hd_init.c
@@ -0,0 +1,55 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ unsigned char hexdig[256];
+
+ static void
+#ifdef KR_headers
+htinit(h, s, inc) unsigned char *h; unsigned char *s; int inc;
+#else
+htinit(unsigned char *h, unsigned char *s, int inc)
+#endif
+{
+	int i, j;
+	for(i = 0; (j = s[i]) !=0; i++)
+		h[j] = i + inc;
+	}
+
+ void
+hexdig_init_D2A(Void)
+{
+#define USC (unsigned char *)
+	htinit(hexdig, USC "0123456789", 0x10);
+	htinit(hexdig, USC "abcdef", 0x10 + 10);
+	htinit(hexdig, USC "ABCDEF", 0x10 + 10);
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/hdtoa.c b/libc/upstream-openbsd/lib/libc/gdtoa/hdtoa.c
new file mode 100644
index 0000000..c62f6d5
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/hdtoa.c
@@ -0,0 +1,332 @@
+/*	$OpenBSD: hdtoa.c,v 1.2 2009/10/16 12:15:03 martynas Exp $	*/
+/*-
+ * Copyright (c) 2004, 2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <machine/ieee.h>
+#include <float.h>
+#include <limits.h>
+#include <math.h>
+
+#include "gdtoaimp.h"
+
+/* Strings values used by dtoa() */
+#define	INFSTR	"Infinity"
+#define	NANSTR	"NaN"
+
+#define	DBL_ADJ		(DBL_MAX_EXP - 2 + ((DBL_MANT_DIG - 1) % 4))
+#define	LDBL_ADJ	(LDBL_MAX_EXP - 2 + ((LDBL_MANT_DIG - 1) % 4))
+
+/*
+ * Round up the given digit string.  If the digit string is fff...f,
+ * this procedure sets it to 100...0 and returns 1 to indicate that
+ * the exponent needs to be bumped.  Otherwise, 0 is returned.
+ */
+static int
+roundup(char *s0, int ndigits)
+{
+	char *s;
+
+	for (s = s0 + ndigits - 1; *s == 0xf; s--) {
+		if (s == s0) {
+			*s = 1;
+			return (1);
+		}
+		*s = 0;
+	}
+	++*s;
+	return (0);
+}
+
+/*
+ * Round the given digit string to ndigits digits according to the
+ * current rounding mode.  Note that this could produce a string whose
+ * value is not representable in the corresponding floating-point
+ * type.  The exponent pointed to by decpt is adjusted if necessary.
+ */
+static void
+dorounding(char *s0, int ndigits, int sign, int *decpt)
+{
+	int adjust = 0;	/* do we need to adjust the exponent? */
+
+	switch (FLT_ROUNDS) {
+	case 0:		/* toward zero */
+	default:	/* implementation-defined */
+		break;
+	case 1:		/* to nearest, halfway rounds to even */
+		if ((s0[ndigits] > 8) ||
+		    (s0[ndigits] == 8 && s0[ndigits + 1] & 1))
+			adjust = roundup(s0, ndigits);
+		break;
+	case 2:		/* toward +inf */
+		if (sign == 0)
+			adjust = roundup(s0, ndigits);
+		break;
+	case 3:		/* toward -inf */
+		if (sign != 0)
+			adjust = roundup(s0, ndigits);
+		break;
+	}
+
+	if (adjust)
+		*decpt += 4;
+}
+
+/*
+ * This procedure converts a double-precision number in IEEE format
+ * into a string of hexadecimal digits and an exponent of 2.  Its
+ * behavior is bug-for-bug compatible with dtoa() in mode 2, with the
+ * following exceptions:
+ *
+ * - An ndigits < 0 causes it to use as many digits as necessary to
+ *   represent the number exactly.
+ * - The additional xdigs argument should point to either the string
+ *   "0123456789ABCDEF" or the string "0123456789abcdef", depending on
+ *   which case is desired.
+ * - This routine does not repeat dtoa's mistake of setting decpt
+ *   to 9999 in the case of an infinity or NaN.  INT_MAX is used
+ *   for this purpose instead.
+ *
+ * Note that the C99 standard does not specify what the leading digit
+ * should be for non-zero numbers.  For instance, 0x1.3p3 is the same
+ * as 0x2.6p2 is the same as 0x4.cp3.  This implementation chooses the
+ * first digit so that subsequent digits are aligned on nibble
+ * boundaries (before rounding).
+ *
+ * Inputs:	d, xdigs, ndigits
+ * Outputs:	decpt, sign, rve
+ */
+char *
+__hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,
+    char **rve)
+{
+	static const int sigfigs = (DBL_MANT_DIG + 3) / 4;
+	struct ieee_double *p = (struct ieee_double *)&d;
+	char *s, *s0;
+	int bufsize;
+
+	*sign = p->dbl_sign;
+
+	switch (fpclassify(d)) {
+	case FP_NORMAL:
+		*decpt = p->dbl_exp - DBL_ADJ;
+		break;
+	case FP_ZERO:
+		*decpt = 1;
+		return (nrv_alloc("0", rve, 1));
+	case FP_SUBNORMAL:
+		d *= 0x1p514;
+		*decpt = p->dbl_exp - (514 + DBL_ADJ);
+		break;
+	case FP_INFINITE:
+		*decpt = INT_MAX;
+		return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1));
+	case FP_NAN:
+		*decpt = INT_MAX;
+		return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
+	default:
+		abort();
+	}
+
+	/* FP_NORMAL or FP_SUBNORMAL */
+
+	if (ndigits == 0)		/* dtoa() compatibility */
+		ndigits = 1;
+
+	/*
+	 * For simplicity, we generate all the digits even if the
+	 * caller has requested fewer.
+	 */
+	bufsize = (sigfigs > ndigits) ? sigfigs : ndigits;
+	s0 = rv_alloc(bufsize);
+	if (s0 == NULL)
+		return (NULL);
+
+	/*
+	 * We work from right to left, first adding any requested zero
+	 * padding, then the least significant portion of the
+	 * mantissa, followed by the most significant.  The buffer is
+	 * filled with the byte values 0x0 through 0xf, which are
+	 * converted to xdigs[0x0] through xdigs[0xf] after the
+	 * rounding phase.
+	 */
+	for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
+		*s = 0;
+	for (; s > s0 + sigfigs - (DBL_FRACLBITS / 4) - 1 && s > s0; s--) {
+		*s = p->dbl_fracl & 0xf;
+		p->dbl_fracl >>= 4;
+	}
+	for (; s > s0; s--) {
+		*s = p->dbl_frach & 0xf;
+		p->dbl_frach >>= 4;
+	}
+
+	/*
+	 * At this point, we have snarfed all the bits in the
+	 * mantissa, with the possible exception of the highest-order
+	 * (partial) nibble, which is dealt with by the next
+	 * statement.  We also tack on the implicit normalization bit.
+	 */
+	*s = p->dbl_frach | (1U << ((DBL_MANT_DIG - 1) % 4));
+
+	/* If ndigits < 0, we are expected to auto-size the precision. */
+	if (ndigits < 0) {
+		for (ndigits = sigfigs; s0[ndigits - 1] == 0; ndigits--)
+			;
+	}
+
+	if (sigfigs > ndigits && s0[ndigits] != 0)
+		dorounding(s0, ndigits, p->dbl_sign, decpt);
+
+	s = s0 + ndigits;
+	if (rve != NULL)
+		*rve = s;
+	*s-- = '\0';
+	for (; s >= s0; s--)
+		*s = xdigs[(unsigned int)*s];
+
+	return (s0);
+}
+
+#if (LDBL_MANT_DIG > DBL_MANT_DIG)
+
+/*
+ * This is the long double version of __hdtoa().
+ */
+char *
+__hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign,
+    char **rve)
+{
+	static const int sigfigs = (LDBL_MANT_DIG + 3) / 4;
+	struct ieee_ext *p = (struct ieee_ext *)&e;
+	char *s, *s0;
+	int bufsize;
+
+	*sign = p->ext_sign;
+
+	switch (fpclassify(e)) {
+	case FP_NORMAL:
+		*decpt = p->ext_exp - LDBL_ADJ;
+		break;
+	case FP_ZERO:
+		*decpt = 1;
+		return (nrv_alloc("0", rve, 1));
+	case FP_SUBNORMAL:
+		e *= 0x1p514L;
+		*decpt = p->ext_exp - (514 + LDBL_ADJ);
+		break;
+	case FP_INFINITE:
+		*decpt = INT_MAX;
+		return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1));
+	case FP_NAN:
+		*decpt = INT_MAX;
+		return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
+	default:
+		abort();
+	}
+
+	/* FP_NORMAL or FP_SUBNORMAL */
+
+	if (ndigits == 0)		/* dtoa() compatibility */
+		ndigits = 1;
+
+	/*
+	 * For simplicity, we generate all the digits even if the
+	 * caller has requested fewer.
+	 */
+	bufsize = (sigfigs > ndigits) ? sigfigs : ndigits;
+	s0 = rv_alloc(bufsize);
+	if (s0 == NULL)
+		return (NULL);
+
+	/*
+	 * We work from right to left, first adding any requested zero
+	 * padding, then the least significant portion of the
+	 * mantissa, followed by the most significant.  The buffer is
+	 * filled with the byte values 0x0 through 0xf, which are
+	 * converted to xdigs[0x0] through xdigs[0xf] after the
+	 * rounding phase.
+	 */
+	for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
+		*s = 0;
+	for (; s > s0 + sigfigs - (EXT_FRACLBITS / 4) - 1 && s > s0; s--) {
+		*s = p->ext_fracl & 0xf;
+		p->ext_fracl >>= 4;
+	}
+#ifdef EXT_FRACHMBITS
+	for (; s > s0; s--) {
+		*s = p->ext_frachm & 0xf;
+		p->ext_frachm >>= 4;
+	}
+#endif
+#ifdef EXT_FRACLMBITS
+	for (; s > s0; s--) {
+		*s = p->ext_fraclm & 0xf;
+		p->ext_fraclm >>= 4;
+	}
+#endif
+	for (; s > s0; s--) {
+		*s = p->ext_frach & 0xf;
+		p->ext_frach >>= 4;
+	}
+
+	/*
+	 * At this point, we have snarfed all the bits in the
+	 * mantissa, with the possible exception of the highest-order
+	 * (partial) nibble, which is dealt with by the next
+	 * statement.  We also tack on the implicit normalization bit.
+	 */
+	*s = p->ext_frach | (1U << ((LDBL_MANT_DIG - 1) % 4));
+
+	/* If ndigits < 0, we are expected to auto-size the precision. */
+	if (ndigits < 0) {
+		for (ndigits = sigfigs; s0[ndigits - 1] == 0; ndigits--)
+			;
+	}
+
+	if (sigfigs > ndigits && s0[ndigits] != 0)
+		dorounding(s0, ndigits, p->ext_sign, decpt);
+
+	s = s0 + ndigits;
+	if (rve != NULL)
+		*rve = s;
+	*s-- = '\0';
+	for (; s >= s0; s--)
+		*s = xdigs[(unsigned int)*s];
+
+	return (s0);
+}
+
+#else	/* (LDBL_MANT_DIG == DBL_MANT_DIG) */
+
+char *
+__hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign,
+    char **rve)
+{
+	return (__hdtoa((double)e, xdigs, ndigits, decpt, sign, rve));
+}
+
+#endif	/* (LDBL_MANT_DIG == DBL_MANT_DIG) */
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/hexnan.c b/libc/upstream-openbsd/lib/libc/gdtoa/hexnan.c
new file mode 100644
index 0000000..a443721
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/hexnan.c
@@ -0,0 +1,150 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ static void
+#ifdef KR_headers
+L_shift(x, x1, i) ULong *x; ULong *x1; int i;
+#else
+L_shift(ULong *x, ULong *x1, int i)
+#endif
+{
+	int j;
+
+	i = 8 - i;
+	i <<= 2;
+	j = ULbits - i;
+	do {
+		*x |= x[1] << j;
+		x[1] >>= i;
+		} while(++x < x1);
+	}
+
+ int
+#ifdef KR_headers
+hexnan(sp, fpi, x0)
+	CONST char **sp; FPI *fpi; ULong *x0;
+#else
+hexnan( CONST char **sp, FPI *fpi, ULong *x0)
+#endif
+{
+	ULong c, h, *x, *x1, *xe;
+	CONST char *s;
+	int havedig, hd0, i, nbits;
+
+	if (!hexdig['0'])
+		hexdig_init_D2A();
+	nbits = fpi->nbits;
+	x = x0 + (nbits >> kshift);
+	if (nbits & kmask)
+		x++;
+	*--x = 0;
+	x1 = xe = x;
+	havedig = hd0 = i = 0;
+	s = *sp;
+	/* allow optional initial 0x or 0X */
+	while((c = *(CONST unsigned char*)(s+1)) && c <= ' ')
+		++s;
+	if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')
+	 && *(CONST unsigned char*)(s+3) > ' ')
+		s += 2;
+	while((c = *(CONST unsigned char*)++s)) {
+		if (!(h = hexdig[c])) {
+			if (c <= ' ') {
+				if (hd0 < havedig) {
+					if (x < x1 && i < 8)
+						L_shift(x, x1, i);
+					if (x <= x0) {
+						i = 8;
+						continue;
+						}
+					hd0 = havedig;
+					*--x = 0;
+					x1 = x;
+					i = 0;
+					}
+				while(*(CONST unsigned char*)(s+1) <= ' ')
+					++s;
+				if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')
+				 && *(CONST unsigned char*)(s+3) > ' ')
+					s += 2;
+				continue;
+				}
+			if (/*(*/ c == ')' && havedig) {
+				*sp = s + 1;
+				break;
+				}
+#ifndef GDTOA_NON_PEDANTIC_NANCHECK
+			do {
+				if (/*(*/ c == ')') {
+					*sp = s + 1;
+					break;
+					}
+				} while((c = *++s));
+#endif
+			return STRTOG_NaN;
+			}
+		havedig++;
+		if (++i > 8) {
+			if (x <= x0)
+				continue;
+			i = 1;
+			*--x = 0;
+			}
+		*x = (*x << 4) | (h & 0xf);
+		}
+	if (!havedig)
+		return STRTOG_NaN;
+	if (x < x1 && i < 8)
+		L_shift(x, x1, i);
+	if (x > x0) {
+		x1 = x0;
+		do *x1++ = *x++;
+			while(x <= xe);
+		do *x1++ = 0;
+			while(x1 <= xe);
+		}
+	else {
+		/* truncate high-order word if necessary */
+		if ( (i = nbits & (ULbits-1)) !=0)
+			*xe &= ((ULong)0xffffffff) >> (ULbits - i);
+		}
+	for(x1 = xe;; --x1) {
+		if (*x1 != 0)
+			break;
+		if (x1 == x0) {
+			*x1 = 1;
+			break;
+			}
+		}
+	return STRTOG_NaNbits;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/ldtoa.c b/libc/upstream-openbsd/lib/libc/gdtoa/ldtoa.c
new file mode 100644
index 0000000..793d71c
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/ldtoa.c
@@ -0,0 +1,124 @@
+/*	$OpenBSD: ldtoa.c,v 1.1 2008/09/07 20:36:08 martynas Exp $	*/
+/*-
+ * Copyright (c) 2003 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#ifndef __vax__
+#include <machine/ieee.h>
+#endif /* !__vax__ */
+#include <float.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <math.h>
+#include <stdlib.h>
+#include "gdtoaimp.h"
+
+#if (LDBL_MANT_DIG > DBL_MANT_DIG)
+
+/*
+ * ldtoa() is a wrapper for gdtoa() that makes it smell like dtoa(),
+ * except that the floating point argument is passed by reference.
+ * When dtoa() is passed a NaN or infinity, it sets expt to 9999.
+ * However, a long double could have a valid exponent of 9999, so we
+ * use INT_MAX in ldtoa() instead.
+ */
+char *
+__ldtoa(long double *ld, int mode, int ndigits, int *decpt, int *sign,
+    char **rve)
+{
+	FPI fpi = {
+		LDBL_MANT_DIG,			/* nbits */
+		LDBL_MIN_EXP - LDBL_MANT_DIG,	/* emin */
+		LDBL_MAX_EXP - LDBL_MANT_DIG,	/* emax */
+		FLT_ROUNDS,	       		/* rounding */
+#ifdef Sudden_Underflow	/* unused, but correct anyway */
+		1
+#else
+		0
+#endif
+	};
+	int be, kind;
+	char *ret;
+	struct ieee_ext *p = (struct ieee_ext *)ld;
+	uint32_t bits[(LDBL_MANT_DIG + 31) / 32];
+	void *vbits = bits;
+
+	/*
+	 * gdtoa doesn't know anything about the sign of the number, so
+	 * if the number is negative, we need to swap rounding modes of
+	 * 2 (upwards) and 3 (downwards).
+	 */
+	*sign = p->ext_sign;
+	fpi.rounding ^= (fpi.rounding >> 1) & p->ext_sign;
+
+	be = p->ext_exp - (LDBL_MAX_EXP - 1) - (LDBL_MANT_DIG - 1);
+	EXT_TO_ARRAY32(p, bits);
+
+	switch (fpclassify(*ld)) {
+	case FP_NORMAL:
+		kind = STRTOG_Normal;
+#ifdef EXT_IMPLICIT_NBIT
+		bits[LDBL_MANT_DIG / 32] |= 1 << ((LDBL_MANT_DIG - 1) % 32);
+#endif /* EXT_IMPLICIT_NBIT */
+		break;
+	case FP_ZERO:
+		kind = STRTOG_Zero;
+		break;
+	case FP_SUBNORMAL:
+		kind = STRTOG_Denormal;
+		be++;
+		break;
+	case FP_INFINITE:
+		kind = STRTOG_Infinite;
+		break;
+	case FP_NAN:
+		kind = STRTOG_NaN;
+		break;
+	default:
+		abort();
+	}
+
+	ret = gdtoa(&fpi, be, vbits, &kind, mode, ndigits, decpt, rve);
+	if (*decpt == -32768)
+		*decpt = INT_MAX;
+	return ret;
+}
+
+#else   /* (LDBL_MANT_DIG == DBL_MANT_DIG) */
+
+char *
+__ldtoa(long double *ld, int mode, int ndigits, int *decpt, int *sign,
+    char **rve)
+{
+	char *ret;
+
+	ret = dtoa((double)*ld, mode, ndigits, decpt, sign, rve);
+	if (*decpt == 9999)
+		*decpt = INT_MAX;
+	return ret;
+}
+
+#endif  /* (LDBL_MANT_DIG == DBL_MANT_DIG) */
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/misc.c b/libc/upstream-openbsd/lib/libc/gdtoa/misc.c
new file mode 100644
index 0000000..6ad706b
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/misc.c
@@ -0,0 +1,907 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ static Bigint *freelist[Kmax+1];
+#ifndef Omit_Private_Memory
+#ifndef PRIVATE_MEM
+#define PRIVATE_MEM 2304
+#endif
+#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
+static double private_mem[PRIVATE_mem], *pmem_next = private_mem;
+#endif
+
+ Bigint *
+Balloc
+#ifdef KR_headers
+	(k) int k;
+#else
+	(int k)
+#endif
+{
+	int x;
+	Bigint *rv;
+#ifndef Omit_Private_Memory
+	unsigned int len;
+#endif
+
+	ACQUIRE_DTOA_LOCK(0);
+	/* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
+	/* but this case seems very unlikely. */
+	if (k <= Kmax && (rv = freelist[k]) !=0) {
+		freelist[k] = rv->next;
+		}
+	else {
+		x = 1 << k;
+#ifdef Omit_Private_Memory
+		rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
+		if (rv == NULL)
+			return (NULL);
+#else
+		len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
+			/sizeof(double);
+		if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
+			rv = (Bigint*)pmem_next;
+			pmem_next += len;
+			}
+		else {
+			rv = (Bigint*)MALLOC(len*sizeof(double));
+			if (rv == NULL)
+				return (NULL);
+		}
+#endif
+		rv->k = k;
+		rv->maxwds = x;
+		}
+	FREE_DTOA_LOCK(0);
+	rv->sign = rv->wds = 0;
+	return rv;
+	}
+
+ void
+Bfree
+#ifdef KR_headers
+	(v) Bigint *v;
+#else
+	(Bigint *v)
+#endif
+{
+	if (v) {
+		if (v->k > Kmax)
+#ifdef FREE
+			FREE((void*)v);
+#else
+			free((void*)v);
+#endif
+		else {
+			ACQUIRE_DTOA_LOCK(0);
+			v->next = freelist[v->k];
+			freelist[v->k] = v;
+			FREE_DTOA_LOCK(0);
+			}
+		}
+	}
+
+ int
+lo0bits
+#ifdef KR_headers
+	(y) ULong *y;
+#else
+	(ULong *y)
+#endif
+{
+	int k;
+	ULong x = *y;
+
+	if (x & 7) {
+		if (x & 1)
+			return 0;
+		if (x & 2) {
+			*y = x >> 1;
+			return 1;
+			}
+		*y = x >> 2;
+		return 2;
+		}
+	k = 0;
+	if (!(x & 0xffff)) {
+		k = 16;
+		x >>= 16;
+		}
+	if (!(x & 0xff)) {
+		k += 8;
+		x >>= 8;
+		}
+	if (!(x & 0xf)) {
+		k += 4;
+		x >>= 4;
+		}
+	if (!(x & 0x3)) {
+		k += 2;
+		x >>= 2;
+		}
+	if (!(x & 1)) {
+		k++;
+		x >>= 1;
+		if (!x)
+			return 32;
+		}
+	*y = x;
+	return k;
+	}
+
+ Bigint *
+multadd
+#ifdef KR_headers
+	(b, m, a) Bigint *b; int m, a;
+#else
+	(Bigint *b, int m, int a)	/* multiply by m and add a */
+#endif
+{
+	int i, wds;
+#ifdef ULLong
+	ULong *x;
+	ULLong carry, y;
+#else
+	ULong carry, *x, y;
+#ifdef Pack_32
+	ULong xi, z;
+#endif
+#endif
+	Bigint *b1;
+
+	wds = b->wds;
+	x = b->x;
+	i = 0;
+	carry = a;
+	do {
+#ifdef ULLong
+		y = *x * (ULLong)m + carry;
+		carry = y >> 32;
+		*x++ = y & 0xffffffffUL;
+#else
+#ifdef Pack_32
+		xi = *x;
+		y = (xi & 0xffff) * m + carry;
+		z = (xi >> 16) * m + (y >> 16);
+		carry = z >> 16;
+		*x++ = (z << 16) + (y & 0xffff);
+#else
+		y = *x * m + carry;
+		carry = y >> 16;
+		*x++ = y & 0xffff;
+#endif
+#endif
+		}
+		while(++i < wds);
+	if (carry) {
+		if (wds >= b->maxwds) {
+			b1 = Balloc(b->k+1);
+			if (b1 == NULL)
+				return (NULL);
+			Bcopy(b1, b);
+			Bfree(b);
+			b = b1;
+			}
+		b->x[wds++] = carry;
+		b->wds = wds;
+		}
+	return b;
+	}
+
+ int
+hi0bits_D2A
+#ifdef KR_headers
+	(x) ULong x;
+#else
+	(ULong x)
+#endif
+{
+	int k = 0;
+
+	if (!(x & 0xffff0000)) {
+		k = 16;
+		x <<= 16;
+		}
+	if (!(x & 0xff000000)) {
+		k += 8;
+		x <<= 8;
+		}
+	if (!(x & 0xf0000000)) {
+		k += 4;
+		x <<= 4;
+		}
+	if (!(x & 0xc0000000)) {
+		k += 2;
+		x <<= 2;
+		}
+	if (!(x & 0x80000000)) {
+		k++;
+		if (!(x & 0x40000000))
+			return 32;
+		}
+	return k;
+	}
+
+ Bigint *
+i2b
+#ifdef KR_headers
+	(i) int i;
+#else
+	(int i)
+#endif
+{
+	Bigint *b;
+
+	b = Balloc(1);
+	if (b == NULL)
+		return (NULL);
+	b->x[0] = i;
+	b->wds = 1;
+	return b;
+	}
+
+ Bigint *
+mult
+#ifdef KR_headers
+	(a, b) Bigint *a, *b;
+#else
+	(Bigint *a, Bigint *b)
+#endif
+{
+	Bigint *c;
+	int k, wa, wb, wc;
+	ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
+	ULong y;
+#ifdef ULLong
+	ULLong carry, z;
+#else
+	ULong carry, z;
+#ifdef Pack_32
+	ULong z2;
+#endif
+#endif
+
+	if (a->wds < b->wds) {
+		c = a;
+		a = b;
+		b = c;
+		}
+	k = a->k;
+	wa = a->wds;
+	wb = b->wds;
+	wc = wa + wb;
+	if (wc > a->maxwds)
+		k++;
+	c = Balloc(k);
+	if (c == NULL)
+		return (NULL);
+	for(x = c->x, xa = x + wc; x < xa; x++)
+		*x = 0;
+	xa = a->x;
+	xae = xa + wa;
+	xb = b->x;
+	xbe = xb + wb;
+	xc0 = c->x;
+#ifdef ULLong
+	for(; xb < xbe; xc0++) {
+		if ( (y = *xb++) !=0) {
+			x = xa;
+			xc = xc0;
+			carry = 0;
+			do {
+				z = *x++ * (ULLong)y + *xc + carry;
+				carry = z >> 32;
+				*xc++ = z & 0xffffffffUL;
+				}
+				while(x < xae);
+			*xc = carry;
+			}
+		}
+#else
+#ifdef Pack_32
+	for(; xb < xbe; xb++, xc0++) {
+		if ( (y = *xb & 0xffff) !=0) {
+			x = xa;
+			xc = xc0;
+			carry = 0;
+			do {
+				z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
+				carry = z >> 16;
+				z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
+				carry = z2 >> 16;
+				Storeinc(xc, z2, z);
+				}
+				while(x < xae);
+			*xc = carry;
+			}
+		if ( (y = *xb >> 16) !=0) {
+			x = xa;
+			xc = xc0;
+			carry = 0;
+			z2 = *xc;
+			do {
+				z = (*x & 0xffff) * y + (*xc >> 16) + carry;
+				carry = z >> 16;
+				Storeinc(xc, z, z2);
+				z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
+				carry = z2 >> 16;
+				}
+				while(x < xae);
+			*xc = z2;
+			}
+		}
+#else
+	for(; xb < xbe; xc0++) {
+		if ( (y = *xb++) !=0) {
+			x = xa;
+			xc = xc0;
+			carry = 0;
+			do {
+				z = *x++ * y + *xc + carry;
+				carry = z >> 16;
+				*xc++ = z & 0xffff;
+				}
+				while(x < xae);
+			*xc = carry;
+			}
+		}
+#endif
+#endif
+	for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
+	c->wds = wc;
+	return c;
+	}
+
+ static Bigint *p5s;
+
+ Bigint *
+pow5mult
+#ifdef KR_headers
+	(b, k) Bigint *b; int k;
+#else
+	(Bigint *b, int k)
+#endif
+{
+	Bigint *b1, *p5, *p51;
+	int i;
+	static int p05[3] = { 5, 25, 125 };
+
+	if ( (i = k & 3) !=0) {
+		b = multadd(b, p05[i-1], 0);
+		if (b == NULL)
+			return (NULL);
+		}
+
+	if (!(k >>= 2))
+		return b;
+	if ((p5 = p5s) == 0) {
+		/* first time */
+#ifdef MULTIPLE_THREADS
+		ACQUIRE_DTOA_LOCK(1);
+		if (!(p5 = p5s)) {
+			p5 = p5s = i2b(625);
+			if (p5 == NULL)
+				return (NULL);
+			p5->next = 0;
+			}
+		FREE_DTOA_LOCK(1);
+#else
+		p5 = p5s = i2b(625);
+		if (p5 == NULL)
+			return (NULL);
+		p5->next = 0;
+#endif
+		}
+	for(;;) {
+		if (k & 1) {
+			b1 = mult(b, p5);
+			if (b1 == NULL)
+				return (NULL);
+			Bfree(b);
+			b = b1;
+			}
+		if (!(k >>= 1))
+			break;
+		if ((p51 = p5->next) == 0) {
+#ifdef MULTIPLE_THREADS
+			ACQUIRE_DTOA_LOCK(1);
+			if (!(p51 = p5->next)) {
+				p51 = p5->next = mult(p5,p5);
+				if (p51 == NULL)
+					return (NULL);
+				p51->next = 0;
+				}
+			FREE_DTOA_LOCK(1);
+#else
+			p51 = p5->next = mult(p5,p5);
+			if (p51 == NULL)
+				return (NULL);
+			p51->next = 0;
+#endif
+			}
+		p5 = p51;
+		}
+	return b;
+	}
+
+ Bigint *
+lshift
+#ifdef KR_headers
+	(b, k) Bigint *b; int k;
+#else
+	(Bigint *b, int k)
+#endif
+{
+	int i, k1, n, n1;
+	Bigint *b1;
+	ULong *x, *x1, *xe, z;
+
+	n = k >> kshift;
+	k1 = b->k;
+	n1 = n + b->wds + 1;
+	for(i = b->maxwds; n1 > i; i <<= 1)
+		k1++;
+	b1 = Balloc(k1);
+	if (b1 == NULL)
+		return (NULL);
+	x1 = b1->x;
+	for(i = 0; i < n; i++)
+		*x1++ = 0;
+	x = b->x;
+	xe = x + b->wds;
+	if (k &= kmask) {
+#ifdef Pack_32
+		k1 = 32 - k;
+		z = 0;
+		do {
+			*x1++ = *x << k | z;
+			z = *x++ >> k1;
+			}
+			while(x < xe);
+		if ((*x1 = z) !=0)
+			++n1;
+#else
+		k1 = 16 - k;
+		z = 0;
+		do {
+			*x1++ = *x << k  & 0xffff | z;
+			z = *x++ >> k1;
+			}
+			while(x < xe);
+		if (*x1 = z)
+			++n1;
+#endif
+		}
+	else do
+		*x1++ = *x++;
+		while(x < xe);
+	b1->wds = n1 - 1;
+	Bfree(b);
+	return b1;
+	}
+
+ int
+cmp
+#ifdef KR_headers
+	(a, b) Bigint *a, *b;
+#else
+	(Bigint *a, Bigint *b)
+#endif
+{
+	ULong *xa, *xa0, *xb, *xb0;
+	int i, j;
+
+	i = a->wds;
+	j = b->wds;
+#ifdef DEBUG
+	if (i > 1 && !a->x[i-1])
+		Bug("cmp called with a->x[a->wds-1] == 0");
+	if (j > 1 && !b->x[j-1])
+		Bug("cmp called with b->x[b->wds-1] == 0");
+#endif
+	if (i -= j)
+		return i;
+	xa0 = a->x;
+	xa = xa0 + j;
+	xb0 = b->x;
+	xb = xb0 + j;
+	for(;;) {
+		if (*--xa != *--xb)
+			return *xa < *xb ? -1 : 1;
+		if (xa <= xa0)
+			break;
+		}
+	return 0;
+	}
+
+ Bigint *
+diff
+#ifdef KR_headers
+	(a, b) Bigint *a, *b;
+#else
+	(Bigint *a, Bigint *b)
+#endif
+{
+	Bigint *c;
+	int i, wa, wb;
+	ULong *xa, *xae, *xb, *xbe, *xc;
+#ifdef ULLong
+	ULLong borrow, y;
+#else
+	ULong borrow, y;
+#ifdef Pack_32
+	ULong z;
+#endif
+#endif
+
+	i = cmp(a,b);
+	if (!i) {
+		c = Balloc(0);
+		if (c == NULL)
+			return (NULL);
+		c->wds = 1;
+		c->x[0] = 0;
+		return c;
+		}
+	if (i < 0) {
+		c = a;
+		a = b;
+		b = c;
+		i = 1;
+		}
+	else
+		i = 0;
+	c = Balloc(a->k);
+	if (c == NULL)
+		return (NULL);
+	c->sign = i;
+	wa = a->wds;
+	xa = a->x;
+	xae = xa + wa;
+	wb = b->wds;
+	xb = b->x;
+	xbe = xb + wb;
+	xc = c->x;
+	borrow = 0;
+#ifdef ULLong
+	do {
+		y = (ULLong)*xa++ - *xb++ - borrow;
+		borrow = y >> 32 & 1UL;
+		*xc++ = y & 0xffffffffUL;
+		}
+		while(xb < xbe);
+	while(xa < xae) {
+		y = *xa++ - borrow;
+		borrow = y >> 32 & 1UL;
+		*xc++ = y & 0xffffffffUL;
+		}
+#else
+#ifdef Pack_32
+	do {
+		y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
+		borrow = (y & 0x10000) >> 16;
+		z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
+		borrow = (z & 0x10000) >> 16;
+		Storeinc(xc, z, y);
+		}
+		while(xb < xbe);
+	while(xa < xae) {
+		y = (*xa & 0xffff) - borrow;
+		borrow = (y & 0x10000) >> 16;
+		z = (*xa++ >> 16) - borrow;
+		borrow = (z & 0x10000) >> 16;
+		Storeinc(xc, z, y);
+		}
+#else
+	do {
+		y = *xa++ - *xb++ - borrow;
+		borrow = (y & 0x10000) >> 16;
+		*xc++ = y & 0xffff;
+		}
+		while(xb < xbe);
+	while(xa < xae) {
+		y = *xa++ - borrow;
+		borrow = (y & 0x10000) >> 16;
+		*xc++ = y & 0xffff;
+		}
+#endif
+#endif
+	while(!*--xc)
+		wa--;
+	c->wds = wa;
+	return c;
+	}
+
+ double
+b2d
+#ifdef KR_headers
+	(a, e) Bigint *a; int *e;
+#else
+	(Bigint *a, int *e)
+#endif
+{
+	ULong *xa, *xa0, w, y, z;
+	int k;
+	U d;
+#ifdef VAX
+	ULong d0, d1;
+#else
+#define d0 word0(&d)
+#define d1 word1(&d)
+#endif
+
+	xa0 = a->x;
+	xa = xa0 + a->wds;
+	y = *--xa;
+#ifdef DEBUG
+	if (!y) Bug("zero y in b2d");
+#endif
+	k = hi0bits(y);
+	*e = 32 - k;
+#ifdef Pack_32
+	if (k < Ebits) {
+		d0 = Exp_1 | y >> (Ebits - k);
+		w = xa > xa0 ? *--xa : 0;
+		d1 = y << ((32-Ebits) + k) | w >> (Ebits - k);
+		goto ret_d;
+		}
+	z = xa > xa0 ? *--xa : 0;
+	if (k -= Ebits) {
+		d0 = Exp_1 | y << k | z >> (32 - k);
+		y = xa > xa0 ? *--xa : 0;
+		d1 = z << k | y >> (32 - k);
+		}
+	else {
+		d0 = Exp_1 | y;
+		d1 = z;
+		}
+#else
+	if (k < Ebits + 16) {
+		z = xa > xa0 ? *--xa : 0;
+		d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k;
+		w = xa > xa0 ? *--xa : 0;
+		y = xa > xa0 ? *--xa : 0;
+		d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
+		goto ret_d;
+		}
+	z = xa > xa0 ? *--xa : 0;
+	w = xa > xa0 ? *--xa : 0;
+	k -= Ebits + 16;
+	d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k;
+	y = xa > xa0 ? *--xa : 0;
+	d1 = w << k + 16 | y << k;
+#endif
+ ret_d:
+#ifdef VAX
+	word0(&d) = d0 >> 16 | d0 << 16;
+	word1(&d) = d1 >> 16 | d1 << 16;
+#endif
+	return dval(&d);
+	}
+#undef d0
+#undef d1
+
+ Bigint *
+d2b
+#ifdef KR_headers
+	(dd, e, bits) double dd; int *e, *bits;
+#else
+	(double dd, int *e, int *bits)
+#endif
+{
+	Bigint *b;
+	U d;
+#ifndef Sudden_Underflow
+	int i;
+#endif
+	int de, k;
+	ULong *x, y, z;
+#ifdef VAX
+	ULong d0, d1;
+#else
+#define d0 word0(&d)
+#define d1 word1(&d)
+#endif
+	d.d = dd;
+#ifdef VAX
+	d0 = word0(&d) >> 16 | word0(&d) << 16;
+	d1 = word1(&d) >> 16 | word1(&d) << 16;
+#endif
+
+#ifdef Pack_32
+	b = Balloc(1);
+#else
+	b = Balloc(2);
+#endif
+	if (b == NULL)
+		return (NULL);
+	x = b->x;
+
+	z = d0 & Frac_mask;
+	d0 &= 0x7fffffff;	/* clear sign bit, which we ignore */
+#ifdef Sudden_Underflow
+	de = (int)(d0 >> Exp_shift);
+#ifndef IBM
+	z |= Exp_msk11;
+#endif
+#else
+	if ( (de = (int)(d0 >> Exp_shift)) !=0)
+		z |= Exp_msk1;
+#endif
+#ifdef Pack_32
+	if ( (y = d1) !=0) {
+		if ( (k = lo0bits(&y)) !=0) {
+			x[0] = y | z << (32 - k);
+			z >>= k;
+			}
+		else
+			x[0] = y;
+#ifndef Sudden_Underflow
+		i =
+#endif
+		     b->wds = (x[1] = z) !=0 ? 2 : 1;
+		}
+	else {
+		k = lo0bits(&z);
+		x[0] = z;
+#ifndef Sudden_Underflow
+		i =
+#endif
+		    b->wds = 1;
+		k += 32;
+		}
+#else
+	if ( (y = d1) !=0) {
+		if ( (k = lo0bits(&y)) !=0)
+			if (k >= 16) {
+				x[0] = y | z << 32 - k & 0xffff;
+				x[1] = z >> k - 16 & 0xffff;
+				x[2] = z >> k;
+				i = 2;
+				}
+			else {
+				x[0] = y & 0xffff;
+				x[1] = y >> 16 | z << 16 - k & 0xffff;
+				x[2] = z >> k & 0xffff;
+				x[3] = z >> k+16;
+				i = 3;
+				}
+		else {
+			x[0] = y & 0xffff;
+			x[1] = y >> 16;
+			x[2] = z & 0xffff;
+			x[3] = z >> 16;
+			i = 3;
+			}
+		}
+	else {
+#ifdef DEBUG
+		if (!z)
+			Bug("Zero passed to d2b");
+#endif
+		k = lo0bits(&z);
+		if (k >= 16) {
+			x[0] = z;
+			i = 0;
+			}
+		else {
+			x[0] = z & 0xffff;
+			x[1] = z >> 16;
+			i = 1;
+			}
+		k += 32;
+		}
+	while(!x[i])
+		--i;
+	b->wds = i + 1;
+#endif
+#ifndef Sudden_Underflow
+	if (de) {
+#endif
+#ifdef IBM
+		*e = (de - Bias - (P-1) << 2) + k;
+		*bits = 4*P + 8 - k - hi0bits(word0(&d) & Frac_mask);
+#else
+		*e = de - Bias - (P-1) + k;
+		*bits = P - k;
+#endif
+#ifndef Sudden_Underflow
+		}
+	else {
+		*e = de - Bias - (P-1) + 1 + k;
+#ifdef Pack_32
+		*bits = 32*i - hi0bits(x[i-1]);
+#else
+		*bits = (i+2)*16 - hi0bits(x[i]);
+#endif
+		}
+#endif
+	return b;
+	}
+#undef d0
+#undef d1
+
+ CONST double
+#ifdef IEEE_Arith
+bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
+CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256
+		};
+#else
+#ifdef IBM
+bigtens[] = { 1e16, 1e32, 1e64 };
+CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 };
+#else
+bigtens[] = { 1e16, 1e32 };
+CONST double tinytens[] = { 1e-16, 1e-32 };
+#endif
+#endif
+
+ CONST double
+tens[] = {
+		1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
+		1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
+		1e20, 1e21, 1e22
+#ifdef VAX
+		, 1e23, 1e24
+#endif
+		};
+
+ char *
+#ifdef KR_headers
+strcp_D2A(a, b) char *a; char *b;
+#else
+strcp_D2A(char *a, CONST char *b)
+#endif
+{
+	while((*a = *b++))
+		a++;
+	return a;
+	}
+
+#ifdef NO_STRING_H
+
+ Char *
+#ifdef KR_headers
+memcpy_D2A(a, b, len) Char *a; Char *b; size_t len;
+#else
+memcpy_D2A(void *a1, void *b1, size_t len)
+#endif
+{
+	char *a = (char*)a1, *ae = a + len;
+	char *b = (char*)b1, *a0 = a;
+	while(a < ae)
+		*a++ = *b++;
+	return a0;
+	}
+
+#endif /* NO_STRING_H */
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/smisc.c b/libc/upstream-openbsd/lib/libc/gdtoa/smisc.c
new file mode 100644
index 0000000..d063a38
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/smisc.c
@@ -0,0 +1,201 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ Bigint *
+s2b
+#ifdef KR_headers
+	(s, nd0, nd, y9, dplen) CONST char *s; int dplen, nd0, nd; ULong y9;
+#else
+	(CONST char *s, int nd0, int nd, ULong y9, int dplen)
+#endif
+{
+	Bigint *b;
+	int i, k;
+	Long x, y;
+
+	x = (nd + 8) / 9;
+	for(k = 0, y = 1; x > y; y <<= 1, k++) ;
+#ifdef Pack_32
+	b = Balloc(k);
+	if (b == NULL)
+		return (NULL);
+	b->x[0] = y9;
+	b->wds = 1;
+#else
+	b = Balloc(k+1);
+	if (b == NULL)
+		return (NULL);
+	b->x[0] = y9 & 0xffff;
+	b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
+#endif
+
+	i = 9;
+	if (9 < nd0) {
+		s += 9;
+		do {
+			b = multadd(b, 10, *s++ - '0');
+			if (b == NULL)
+				return (NULL);
+			} while(++i < nd0);
+		s += dplen;
+		}
+	else
+		s += dplen + 9;
+	for(; i < nd; i++) {
+		b = multadd(b, 10, *s++ - '0');
+		if (b == NULL)
+			return (NULL);
+		}
+	return b;
+	}
+
+ double
+ratio
+#ifdef KR_headers
+	(a, b) Bigint *a, *b;
+#else
+	(Bigint *a, Bigint *b)
+#endif
+{
+	U da, db;
+	int k, ka, kb;
+
+	dval(&da) = b2d(a, &ka);
+	dval(&db) = b2d(b, &kb);
+	k = ka - kb + ULbits*(a->wds - b->wds);
+#ifdef IBM
+	if (k > 0) {
+		word0(&da) += (k >> 2)*Exp_msk1;
+		if (k &= 3)
+			dval(&da) *= 1 << k;
+		}
+	else {
+		k = -k;
+		word0(&db) += (k >> 2)*Exp_msk1;
+		if (k &= 3)
+			dval(&db) *= 1 << k;
+		}
+#else
+	if (k > 0)
+		word0(&da) += k*Exp_msk1;
+	else {
+		k = -k;
+		word0(&db) += k*Exp_msk1;
+		}
+#endif
+	return dval(&da) / dval(&db);
+	}
+
+#ifdef INFNAN_CHECK
+
+ int
+match
+#ifdef KR_headers
+	(sp, t) char **sp, *t;
+#else
+	(CONST char **sp, char *t)
+#endif
+{
+	int c, d;
+	CONST char *s = *sp;
+
+	while( (d = *t++) !=0) {
+		if ((c = *++s) >= 'A' && c <= 'Z')
+			c += 'a' - 'A';
+		if (c != d)
+			return 0;
+		}
+	*sp = s + 1;
+	return 1;
+	}
+#endif /* INFNAN_CHECK */
+
+ void
+#ifdef KR_headers
+copybits(c, n, b) ULong *c; int n; Bigint *b;
+#else
+copybits(ULong *c, int n, Bigint *b)
+#endif
+{
+	ULong *ce, *x, *xe;
+#ifdef Pack_16
+	int nw, nw1;
+#endif
+
+	ce = c + ((n-1) >> kshift) + 1;
+	x = b->x;
+#ifdef Pack_32
+	xe = x + b->wds;
+	while(x < xe)
+		*c++ = *x++;
+#else
+	nw = b->wds;
+	nw1 = nw & 1;
+	for(xe = x + (nw - nw1); x < xe; x += 2)
+		Storeinc(c, x[1], x[0]);
+	if (nw1)
+		*c++ = *x;
+#endif
+	while(c < ce)
+		*c++ = 0;
+	}
+
+ ULong
+#ifdef KR_headers
+any_on(b, k) Bigint *b; int k;
+#else
+any_on(Bigint *b, int k)
+#endif
+{
+	int n, nwds;
+	ULong *x, *x0, x1, x2;
+
+	x = b->x;
+	nwds = b->wds;
+	n = k >> kshift;
+	if (n > nwds)
+		n = nwds;
+	else if (n < nwds && (k &= kmask)) {
+		x1 = x2 = x[n];
+		x1 >>= k;
+		x1 <<= k;
+		if (x1 != x2)
+			return 1;
+		}
+	x0 = x;
+	x += n;
+	while(x > x0)
+		if (*--x)
+			return 1;
+	return 0;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/strtod.c b/libc/upstream-openbsd/lib/libc/gdtoa/strtod.c
new file mode 100644
index 0000000..ded47d8
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/strtod.c
@@ -0,0 +1,1105 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998-2001 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+#ifndef NO_FENV_H
+#include <fenv.h>
+#endif
+
+#ifdef USE_LOCALE
+#include "locale.h"
+#endif
+
+#ifdef IEEE_Arith
+#ifndef NO_IEEE_Scale
+#define Avoid_Underflow
+#undef tinytens
+/* The factor of 2^106 in tinytens[4] helps us avoid setting the underflow */
+/* flag unnecessarily.  It leads to a song and dance at the end of strtod. */
+static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
+		9007199254740992.*9007199254740992.e-256
+		};
+#endif
+#endif
+
+#ifdef Honor_FLT_ROUNDS
+#undef Check_FLT_ROUNDS
+#define Check_FLT_ROUNDS
+#else
+#define Rounding Flt_Rounds
+#endif
+
+#ifdef Avoid_Underflow /*{*/
+ static double
+sulp
+#ifdef KR_headers
+	(x, scale) U *x; int scale;
+#else
+	(U *x, int scale)
+#endif
+{
+	U u;
+	double rv;
+	int i;
+
+	rv = ulp(x);
+	if (!scale || (i = 2*P + 1 - ((word0(x) & Exp_mask) >> Exp_shift)) <= 0)
+		return rv; /* Is there an example where i <= 0 ? */
+	word0(&u) = Exp_1 + (i << Exp_shift);
+	word1(&u) = 0;
+	return rv * u.d;
+	}
+#endif /*}*/
+
+ double
+strtod
+#ifdef KR_headers
+	(s00, se) CONST char *s00; char **se;
+#else
+	(CONST char *s00, char **se)
+#endif
+{
+#ifdef Avoid_Underflow
+	int scale;
+#endif
+	int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign,
+		 e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
+	CONST char *s, *s0, *s1;
+	double aadj;
+	Long L;
+	U adj, aadj1, rv, rv0;
+	ULong y, z;
+	Bigint *bb = NULL, *bb1, *bd = NULL, *bd0 = NULL, *bs = NULL, *delta = NULL;
+#ifdef Avoid_Underflow
+	ULong Lsb, Lsb1;
+#endif
+#ifdef SET_INEXACT
+	int inexact, oldinexact;
+#endif
+#ifdef USE_LOCALE /*{{*/
+#ifdef NO_LOCALE_CACHE
+	char *decimalpoint = localeconv()->decimal_point;
+	int dplen = strlen(decimalpoint);
+#else
+	char *decimalpoint;
+	static char *decimalpoint_cache;
+	static int dplen;
+	if (!(s0 = decimalpoint_cache)) {
+		s0 = localeconv()->decimal_point;
+		if ((decimalpoint_cache = (char*)MALLOC(strlen(s0) + 1))) {
+			strlcpy(decimalpoint_cache, s0, strlen(s0) + 1);
+			s0 = decimalpoint_cache;
+			}
+		dplen = strlen(s0);
+		}
+	decimalpoint = (char*)s0;
+#endif /*NO_LOCALE_CACHE*/
+#else  /*USE_LOCALE}{*/
+#define dplen 1
+#endif /*USE_LOCALE}}*/
+
+#ifdef Honor_FLT_ROUNDS /*{*/
+	int Rounding;
+#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
+	Rounding = Flt_Rounds;
+#else /*}{*/
+	Rounding = 1;
+	switch(fegetround()) {
+	  case FE_TOWARDZERO:	Rounding = 0; break;
+	  case FE_UPWARD:	Rounding = 2; break;
+	  case FE_DOWNWARD:	Rounding = 3;
+	  }
+#endif /*}}*/
+#endif /*}*/
+
+	sign = nz0 = nz = decpt = 0;
+	dval(&rv) = 0.;
+	for(s = s00;;s++) switch(*s) {
+		case '-':
+			sign = 1;
+			/* no break */
+		case '+':
+			if (*++s)
+				goto break2;
+			/* no break */
+		case 0:
+			goto ret0;
+		case '\t':
+		case '\n':
+		case '\v':
+		case '\f':
+		case '\r':
+		case ' ':
+			continue;
+		default:
+			goto break2;
+		}
+ break2:
+	if (*s == '0') {
+#ifndef NO_HEX_FP /*{*/
+		{
+		static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
+		Long exp;
+		ULong bits[2];
+		switch(s[1]) {
+		  case 'x':
+		  case 'X':
+			{
+#ifdef Honor_FLT_ROUNDS
+			FPI fpi1 = fpi;
+			fpi1.rounding = Rounding;
+#else
+#define fpi1 fpi
+#endif
+			switch((i = gethex(&s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) {
+			  case STRTOG_NoMemory:
+				goto ovfl;
+			  case STRTOG_NoNumber:
+				s = s00;
+				sign = 0;
+			  case STRTOG_Zero:
+				break;
+			  default:
+				if (bb) {
+					copybits(bits, fpi.nbits, bb);
+					Bfree(bb);
+					}
+				ULtod(((U*)&rv)->L, bits, exp, i);
+			  }}
+			goto ret;
+		  }
+		}
+#endif /*}*/
+		nz0 = 1;
+		while(*++s == '0') ;
+		if (!*s)
+			goto ret;
+		}
+	s0 = s;
+	y = z = 0;
+	for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
+		if (nd < 9)
+			y = 10*y + c - '0';
+		else if (nd < 16)
+			z = 10*z + c - '0';
+	nd0 = nd;
+#ifdef USE_LOCALE
+	if (c == *decimalpoint) {
+		for(i = 1; decimalpoint[i]; ++i)
+			if (s[i] != decimalpoint[i])
+				goto dig_done;
+		s += i;
+		c = *s;
+#else
+	if (c == '.') {
+		c = *++s;
+#endif
+		decpt = 1;
+		if (!nd) {
+			for(; c == '0'; c = *++s)
+				nz++;
+			if (c > '0' && c <= '9') {
+				s0 = s;
+				nf += nz;
+				nz = 0;
+				goto have_dig;
+				}
+			goto dig_done;
+			}
+		for(; c >= '0' && c <= '9'; c = *++s) {
+ have_dig:
+			nz++;
+			if (c -= '0') {
+				nf += nz;
+				for(i = 1; i < nz; i++)
+					if (nd++ < 9)
+						y *= 10;
+					else if (nd <= DBL_DIG + 1)
+						z *= 10;
+				if (nd++ < 9)
+					y = 10*y + c;
+				else if (nd <= DBL_DIG + 1)
+					z = 10*z + c;
+				nz = 0;
+				}
+			}
+		}/*}*/
+ dig_done:
+	e = 0;
+	if (c == 'e' || c == 'E') {
+		if (!nd && !nz && !nz0) {
+			goto ret0;
+			}
+		s00 = s;
+		esign = 0;
+		switch(c = *++s) {
+			case '-':
+				esign = 1;
+			case '+':
+				c = *++s;
+			}
+		if (c >= '0' && c <= '9') {
+			while(c == '0')
+				c = *++s;
+			if (c > '0' && c <= '9') {
+				L = c - '0';
+				s1 = s;
+				while((c = *++s) >= '0' && c <= '9')
+					L = 10*L + c - '0';
+				if (s - s1 > 8 || L > 19999)
+					/* Avoid confusion from exponents
+					 * so large that e might overflow.
+					 */
+					e = 19999; /* safe for 16 bit ints */
+				else
+					e = (int)L;
+				if (esign)
+					e = -e;
+				}
+			else
+				e = 0;
+			}
+		else
+			s = s00;
+		}
+	if (!nd) {
+		if (!nz && !nz0) {
+#ifdef INFNAN_CHECK
+			/* Check for Nan and Infinity */
+			ULong bits[2];
+			static FPI fpinan =	/* only 52 explicit bits */
+				{ 52, 1-1023-53+1, 2046-1023-53+1, 1, SI };
+			if (!decpt)
+			 switch(c) {
+			  case 'i':
+			  case 'I':
+				if (match(&s,"nf")) {
+					--s;
+					if (!match(&s,"inity"))
+						++s;
+					word0(&rv) = 0x7ff00000;
+					word1(&rv) = 0;
+					goto ret;
+					}
+				break;
+			  case 'n':
+			  case 'N':
+				if (match(&s, "an")) {
+#ifndef No_Hex_NaN
+					if (*s == '(' /*)*/
+					 && hexnan(&s, &fpinan, bits)
+							== STRTOG_NaNbits) {
+						word0(&rv) = 0x7ff00000 | bits[1];
+						word1(&rv) = bits[0];
+						}
+					else {
+#endif
+						word0(&rv) = NAN_WORD0;
+						word1(&rv) = NAN_WORD1;
+#ifndef No_Hex_NaN
+						}
+#endif
+					goto ret;
+					}
+			  }
+#endif /* INFNAN_CHECK */
+ ret0:
+			s = s00;
+			sign = 0;
+			}
+		goto ret;
+		}
+	e1 = e -= nf;
+
+	/* Now we have nd0 digits, starting at s0, followed by a
+	 * decimal point, followed by nd-nd0 digits.  The number we're
+	 * after is the integer represented by those digits times
+	 * 10**e */
+
+	if (!nd0)
+		nd0 = nd;
+	k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
+	dval(&rv) = y;
+	if (k > 9) {
+#ifdef SET_INEXACT
+		if (k > DBL_DIG)
+			oldinexact = get_inexact();
+#endif
+		dval(&rv) = tens[k - 9] * dval(&rv) + z;
+		}
+	if (nd <= DBL_DIG
+#ifndef RND_PRODQUOT
+#ifndef Honor_FLT_ROUNDS
+		&& Flt_Rounds == 1
+#endif
+#endif
+			) {
+		if (!e)
+			goto ret;
+#ifndef ROUND_BIASED_without_Round_Up
+		if (e > 0) {
+			if (e <= Ten_pmax) {
+#ifdef VAX
+				goto vax_ovfl_check;
+#else
+#ifdef Honor_FLT_ROUNDS
+				/* round correctly FLT_ROUNDS = 2 or 3 */
+				if (sign) {
+					rv.d = -rv.d;
+					sign = 0;
+					}
+#endif
+				/* rv = */ rounded_product(dval(&rv), tens[e]);
+				goto ret;
+#endif
+				}
+			i = DBL_DIG - nd;
+			if (e <= Ten_pmax + i) {
+				/* A fancier test would sometimes let us do
+				 * this for larger i values.
+				 */
+#ifdef Honor_FLT_ROUNDS
+				/* round correctly FLT_ROUNDS = 2 or 3 */
+				if (sign) {
+					rv.d = -rv.d;
+					sign = 0;
+					}
+#endif
+				e -= i;
+				dval(&rv) *= tens[i];
+#ifdef VAX
+				/* VAX exponent range is so narrow we must
+				 * worry about overflow here...
+				 */
+ vax_ovfl_check:
+				word0(&rv) -= P*Exp_msk1;
+				/* rv = */ rounded_product(dval(&rv), tens[e]);
+				if ((word0(&rv) & Exp_mask)
+				 > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
+					goto ovfl;
+				word0(&rv) += P*Exp_msk1;
+#else
+				/* rv = */ rounded_product(dval(&rv), tens[e]);
+#endif
+				goto ret;
+				}
+			}
+#ifndef Inaccurate_Divide
+		else if (e >= -Ten_pmax) {
+#ifdef Honor_FLT_ROUNDS
+			/* round correctly FLT_ROUNDS = 2 or 3 */
+			if (sign) {
+				rv.d = -rv.d;
+				sign = 0;
+				}
+#endif
+			/* rv = */ rounded_quotient(dval(&rv), tens[-e]);
+			goto ret;
+			}
+#endif
+#endif /* ROUND_BIASED_without_Round_Up */
+		}
+	e1 += nd - k;
+
+#ifdef IEEE_Arith
+#ifdef SET_INEXACT
+	inexact = 1;
+	if (k <= DBL_DIG)
+		oldinexact = get_inexact();
+#endif
+#ifdef Avoid_Underflow
+	scale = 0;
+#endif
+#ifdef Honor_FLT_ROUNDS
+	if (Rounding >= 2) {
+		if (sign)
+			Rounding = Rounding == 2 ? 0 : 2;
+		else
+			if (Rounding != 2)
+				Rounding = 0;
+		}
+#endif
+#endif /*IEEE_Arith*/
+
+	/* Get starting approximation = rv * 10**e1 */
+
+	if (e1 > 0) {
+		if ( (i = e1 & 15) !=0)
+			dval(&rv) *= tens[i];
+		if (e1 &= ~15) {
+			if (e1 > DBL_MAX_10_EXP) {
+ ovfl:
+				/* Can't trust HUGE_VAL */
+#ifdef IEEE_Arith
+#ifdef Honor_FLT_ROUNDS
+				switch(Rounding) {
+				  case 0: /* toward 0 */
+				  case 3: /* toward -infinity */
+					word0(&rv) = Big0;
+					word1(&rv) = Big1;
+					break;
+				  default:
+					word0(&rv) = Exp_mask;
+					word1(&rv) = 0;
+				  }
+#else /*Honor_FLT_ROUNDS*/
+				word0(&rv) = Exp_mask;
+				word1(&rv) = 0;
+#endif /*Honor_FLT_ROUNDS*/
+#ifdef SET_INEXACT
+				/* set overflow bit */
+				dval(&rv0) = 1e300;
+				dval(&rv0) *= dval(&rv0);
+#endif
+#else /*IEEE_Arith*/
+				word0(&rv) = Big0;
+				word1(&rv) = Big1;
+#endif /*IEEE_Arith*/
+ range_err:
+				if (bd0) {
+					Bfree(bb);
+					Bfree(bd);
+					Bfree(bs);
+					Bfree(bd0);
+					Bfree(delta);
+					}
+#ifndef NO_ERRNO
+				errno = ERANGE;
+#endif
+				goto ret;
+				}
+			e1 >>= 4;
+			for(j = 0; e1 > 1; j++, e1 >>= 1)
+				if (e1 & 1)
+					dval(&rv) *= bigtens[j];
+		/* The last multiplication could overflow. */
+			word0(&rv) -= P*Exp_msk1;
+			dval(&rv) *= bigtens[j];
+			if ((z = word0(&rv) & Exp_mask)
+			 > Exp_msk1*(DBL_MAX_EXP+Bias-P))
+				goto ovfl;
+			if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
+				/* set to largest number */
+				/* (Can't trust DBL_MAX) */
+				word0(&rv) = Big0;
+				word1(&rv) = Big1;
+				}
+			else
+				word0(&rv) += P*Exp_msk1;
+			}
+		}
+	else if (e1 < 0) {
+		e1 = -e1;
+		if ( (i = e1 & 15) !=0)
+			dval(&rv) /= tens[i];
+		if (e1 >>= 4) {
+			if (e1 >= 1 << n_bigtens)
+				goto undfl;
+#ifdef Avoid_Underflow
+			if (e1 & Scale_Bit)
+				scale = 2*P;
+			for(j = 0; e1 > 0; j++, e1 >>= 1)
+				if (e1 & 1)
+					dval(&rv) *= tinytens[j];
+			if (scale && (j = 2*P + 1 - ((word0(&rv) & Exp_mask)
+						>> Exp_shift)) > 0) {
+				/* scaled rv is denormal; zap j low bits */
+				if (j >= 32) {
+					word1(&rv) = 0;
+					if (j >= 53)
+					 word0(&rv) = (P+2)*Exp_msk1;
+					else
+					 word0(&rv) &= 0xffffffff << (j-32);
+					}
+				else
+					word1(&rv) &= 0xffffffff << j;
+				}
+#else
+			for(j = 0; e1 > 1; j++, e1 >>= 1)
+				if (e1 & 1)
+					dval(&rv) *= tinytens[j];
+			/* The last multiplication could underflow. */
+			dval(&rv0) = dval(&rv);
+			dval(&rv) *= tinytens[j];
+			if (!dval(&rv)) {
+				dval(&rv) = 2.*dval(&rv0);
+				dval(&rv) *= tinytens[j];
+#endif
+				if (!dval(&rv)) {
+ undfl:
+					dval(&rv) = 0.;
+					goto range_err;
+					}
+#ifndef Avoid_Underflow
+				word0(&rv) = Tiny0;
+				word1(&rv) = Tiny1;
+				/* The refinement below will clean
+				 * this approximation up.
+				 */
+				}
+#endif
+			}
+		}
+
+	/* Now the hard part -- adjusting rv to the correct value.*/
+
+	/* Put digits into bd: true value = bd * 10^e */
+
+	bd0 = s2b(s0, nd0, nd, y, dplen);
+	if (bd0 == NULL)
+		goto ovfl;
+
+	for(;;) {
+		bd = Balloc(bd0->k);
+		if (bd == NULL)
+			goto ovfl;
+		Bcopy(bd, bd0);
+		bb = d2b(dval(&rv), &bbe, &bbbits);	/* rv = bb * 2^bbe */
+		if (bb == NULL)
+			goto ovfl;
+		bs = i2b(1);
+		if (bs == NULL)
+			goto ovfl;
+
+		if (e >= 0) {
+			bb2 = bb5 = 0;
+			bd2 = bd5 = e;
+			}
+		else {
+			bb2 = bb5 = -e;
+			bd2 = bd5 = 0;
+			}
+		if (bbe >= 0)
+			bb2 += bbe;
+		else
+			bd2 -= bbe;
+		bs2 = bb2;
+#ifdef Honor_FLT_ROUNDS
+		if (Rounding != 1)
+			bs2++;
+#endif
+#ifdef Avoid_Underflow
+		Lsb = LSB;
+		Lsb1 = 0;
+		j = bbe - scale;
+		i = j + bbbits - 1;	/* logb(rv) */
+		j = P + 1 - bbbits;
+		if (i < Emin) {	/* denormal */
+			i = Emin - i;
+			j -= i;
+			if (i < 32)
+				Lsb <<= i;
+			else
+				Lsb1 = Lsb << (i-32);
+			}
+#else /*Avoid_Underflow*/
+#ifdef Sudden_Underflow
+#ifdef IBM
+		j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
+#else
+		j = P + 1 - bbbits;
+#endif
+#else /*Sudden_Underflow*/
+		j = bbe;
+		i = j + bbbits - 1;	/* logb(&rv) */
+		if (i < Emin)	/* denormal */
+			j += P - Emin;
+		else
+			j = P + 1 - bbbits;
+#endif /*Sudden_Underflow*/
+#endif /*Avoid_Underflow*/
+		bb2 += j;
+		bd2 += j;
+#ifdef Avoid_Underflow
+		bd2 += scale;
+#endif
+		i = bb2 < bd2 ? bb2 : bd2;
+		if (i > bs2)
+			i = bs2;
+		if (i > 0) {
+			bb2 -= i;
+			bd2 -= i;
+			bs2 -= i;
+			}
+		if (bb5 > 0) {
+			bs = pow5mult(bs, bb5);
+			if (bs == NULL)
+				goto ovfl;
+			bb1 = mult(bs, bb);
+			if (bb1 == NULL)
+				goto ovfl;
+			Bfree(bb);
+			bb = bb1;
+			}
+		if (bb2 > 0) {
+			bb = lshift(bb, bb2);
+			if (bb == NULL)
+				goto ovfl;
+			}
+		if (bd5 > 0) {
+			bd = pow5mult(bd, bd5);
+			if (bd == NULL)
+				goto ovfl;
+			}
+		if (bd2 > 0) {
+			bd = lshift(bd, bd2);
+			if (bd == NULL)
+				goto ovfl;
+			}
+		if (bs2 > 0) {
+			bs = lshift(bs, bs2);
+			if (bs == NULL)
+				goto ovfl;
+			}
+		delta = diff(bb, bd);
+		if (delta == NULL)
+			goto ovfl;
+		dsign = delta->sign;
+		delta->sign = 0;
+		i = cmp(delta, bs);
+#ifdef Honor_FLT_ROUNDS
+		if (Rounding != 1) {
+			if (i < 0) {
+				/* Error is less than an ulp */
+				if (!delta->x[0] && delta->wds <= 1) {
+					/* exact */
+#ifdef SET_INEXACT
+					inexact = 0;
+#endif
+					break;
+					}
+				if (Rounding) {
+					if (dsign) {
+						dval(&adj) = 1.;
+						goto apply_adj;
+						}
+					}
+				else if (!dsign) {
+					dval(&adj) = -1.;
+					if (!word1(&rv)
+					 && !(word0(&rv) & Frac_mask)) {
+						y = word0(&rv) & Exp_mask;
+#ifdef Avoid_Underflow
+						if (!scale || y > 2*P*Exp_msk1)
+#else
+						if (y)
+#endif
+						  {
+						  delta = lshift(delta,Log2P);
+						  if (delta == NULL)
+							goto ovfl;
+						  if (cmp(delta, bs) <= 0)
+							dval(&adj) = -0.5;
+						  }
+						}
+ apply_adj:
+#ifdef Avoid_Underflow
+					if (scale && (y = word0(&rv) & Exp_mask)
+						<= 2*P*Exp_msk1)
+					  word0(&adj) += (2*P+1)*Exp_msk1 - y;
+#else
+#ifdef Sudden_Underflow
+					if ((word0(&rv) & Exp_mask) <=
+							P*Exp_msk1) {
+						word0(&rv) += P*Exp_msk1;
+						dval(&rv) += adj*ulp(&rv);
+						word0(&rv) -= P*Exp_msk1;
+						}
+					else
+#endif /*Sudden_Underflow*/
+#endif /*Avoid_Underflow*/
+					dval(&rv) += adj.d*ulp(&rv);
+					}
+				break;
+				}
+			dval(&adj) = ratio(delta, bs);
+			if (adj.d < 1.)
+				dval(&adj) = 1.;
+			if (adj.d <= 0x7ffffffe) {
+				/* dval(&adj) = Rounding ? ceil(&adj) : floor(&adj); */
+				y = adj.d;
+				if (y != adj.d) {
+					if (!((Rounding>>1) ^ dsign))
+						y++;
+					dval(&adj) = y;
+					}
+				}
+#ifdef Avoid_Underflow
+			if (scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1)
+				word0(&adj) += (2*P+1)*Exp_msk1 - y;
+#else
+#ifdef Sudden_Underflow
+			if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) {
+				word0(&rv) += P*Exp_msk1;
+				dval(&adj) *= ulp(&rv);
+				if (dsign)
+					dval(&rv) += adj;
+				else
+					dval(&rv) -= adj;
+				word0(&rv) -= P*Exp_msk1;
+				goto cont;
+				}
+#endif /*Sudden_Underflow*/
+#endif /*Avoid_Underflow*/
+			dval(&adj) *= ulp(&rv);
+			if (dsign) {
+				if (word0(&rv) == Big0 && word1(&rv) == Big1)
+					goto ovfl;
+				dval(&rv) += adj.d;
+				}
+			else
+				dval(&rv) -= adj.d;
+			goto cont;
+			}
+#endif /*Honor_FLT_ROUNDS*/
+
+		if (i < 0) {
+			/* Error is less than half an ulp -- check for
+			 * special case of mantissa a power of two.
+			 */
+			if (dsign || word1(&rv) || word0(&rv) & Bndry_mask
+#ifdef IEEE_Arith
+#ifdef Avoid_Underflow
+			 || (word0(&rv) & Exp_mask) <= (2*P+1)*Exp_msk1
+#else
+			 || (word0(&rv) & Exp_mask) <= Exp_msk1
+#endif
+#endif
+				) {
+#ifdef SET_INEXACT
+				if (!delta->x[0] && delta->wds <= 1)
+					inexact = 0;
+#endif
+				break;
+				}
+			if (!delta->x[0] && delta->wds <= 1) {
+				/* exact result */
+#ifdef SET_INEXACT
+				inexact = 0;
+#endif
+				break;
+				}
+			delta = lshift(delta,Log2P);
+			if (delta == NULL)
+				goto ovfl;
+			if (cmp(delta, bs) > 0)
+				goto drop_down;
+			break;
+			}
+		if (i == 0) {
+			/* exactly half-way between */
+			if (dsign) {
+				if ((word0(&rv) & Bndry_mask1) == Bndry_mask1
+				 &&  word1(&rv) == (
+#ifdef Avoid_Underflow
+			(scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1)
+		? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
+#endif
+						   0xffffffff)) {
+					/*boundary case -- increment exponent*/
+					if (word0(&rv) == Big0 && word1(&rv) == Big1)
+						goto ovfl;
+					word0(&rv) = (word0(&rv) & Exp_mask)
+						+ Exp_msk1
+#ifdef IBM
+						| Exp_msk1 >> 4
+#endif
+						;
+					word1(&rv) = 0;
+#ifdef Avoid_Underflow
+					dsign = 0;
+#endif
+					break;
+					}
+				}
+			else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) {
+ drop_down:
+				/* boundary case -- decrement exponent */
+#ifdef Sudden_Underflow /*{{*/
+				L = word0(&rv) & Exp_mask;
+#ifdef IBM
+				if (L <  Exp_msk1)
+#else
+#ifdef Avoid_Underflow
+				if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1))
+#else
+				if (L <= Exp_msk1)
+#endif /*Avoid_Underflow*/
+#endif /*IBM*/
+					goto undfl;
+				L -= Exp_msk1;
+#else /*Sudden_Underflow}{*/
+#ifdef Avoid_Underflow
+				if (scale) {
+					L = word0(&rv) & Exp_mask;
+					if (L <= (2*P+1)*Exp_msk1) {
+						if (L > (P+2)*Exp_msk1)
+							/* round even ==> */
+							/* accept rv */
+							break;
+						/* rv = smallest denormal */
+						goto undfl;
+						}
+					}
+#endif /*Avoid_Underflow*/
+				L = (word0(&rv) & Exp_mask) - Exp_msk1;
+#endif /*Sudden_Underflow}}*/
+				word0(&rv) = L | Bndry_mask1;
+				word1(&rv) = 0xffffffff;
+#ifdef IBM
+				goto cont;
+#else
+				break;
+#endif
+				}
+#ifndef ROUND_BIASED
+#ifdef Avoid_Underflow
+			if (Lsb1) {
+				if (!(word0(&rv) & Lsb1))
+					break;
+				}
+			else if (!(word1(&rv) & Lsb))
+				break;
+#else
+			if (!(word1(&rv) & LSB))
+				break;
+#endif
+#endif
+			if (dsign)
+#ifdef Avoid_Underflow
+				dval(&rv) += sulp(&rv, scale);
+#else
+				dval(&rv) += ulp(&rv);
+#endif
+#ifndef ROUND_BIASED
+			else {
+#ifdef Avoid_Underflow
+				dval(&rv) -= sulp(&rv, scale);
+#else
+				dval(&rv) -= ulp(&rv);
+#endif
+#ifndef Sudden_Underflow
+				if (!dval(&rv))
+					goto undfl;
+#endif
+				}
+#ifdef Avoid_Underflow
+			dsign = 1 - dsign;
+#endif
+#endif
+			break;
+			}
+		if ((aadj = ratio(delta, bs)) <= 2.) {
+			if (dsign)
+				aadj = dval(&aadj1) = 1.;
+			else if (word1(&rv) || word0(&rv) & Bndry_mask) {
+#ifndef Sudden_Underflow
+				if (word1(&rv) == Tiny1 && !word0(&rv))
+					goto undfl;
+#endif
+				aadj = 1.;
+				dval(&aadj1) = -1.;
+				}
+			else {
+				/* special case -- power of FLT_RADIX to be */
+				/* rounded down... */
+
+				if (aadj < 2./FLT_RADIX)
+					aadj = 1./FLT_RADIX;
+				else
+					aadj *= 0.5;
+				dval(&aadj1) = -aadj;
+				}
+			}
+		else {
+			aadj *= 0.5;
+			dval(&aadj1) = dsign ? aadj : -aadj;
+#ifdef Check_FLT_ROUNDS
+			switch(Rounding) {
+				case 2: /* towards +infinity */
+					dval(&aadj1) -= 0.5;
+					break;
+				case 0: /* towards 0 */
+				case 3: /* towards -infinity */
+					dval(&aadj1) += 0.5;
+				}
+#else
+			if (Flt_Rounds == 0)
+				dval(&aadj1) += 0.5;
+#endif /*Check_FLT_ROUNDS*/
+			}
+		y = word0(&rv) & Exp_mask;
+
+		/* Check for overflow */
+
+		if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
+			dval(&rv0) = dval(&rv);
+			word0(&rv) -= P*Exp_msk1;
+			dval(&adj) = dval(&aadj1) * ulp(&rv);
+			dval(&rv) += dval(&adj);
+			if ((word0(&rv) & Exp_mask) >=
+					Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
+				if (word0(&rv0) == Big0 && word1(&rv0) == Big1)
+					goto ovfl;
+				word0(&rv) = Big0;
+				word1(&rv) = Big1;
+				goto cont;
+				}
+			else
+				word0(&rv) += P*Exp_msk1;
+			}
+		else {
+#ifdef Avoid_Underflow
+			if (scale && y <= 2*P*Exp_msk1) {
+				if (aadj <= 0x7fffffff) {
+					if ((z = aadj) <= 0)
+						z = 1;
+					aadj = z;
+					dval(&aadj1) = dsign ? aadj : -aadj;
+					}
+				word0(&aadj1) += (2*P+1)*Exp_msk1 - y;
+				}
+			dval(&adj) = dval(&aadj1) * ulp(&rv);
+			dval(&rv) += dval(&adj);
+#else
+#ifdef Sudden_Underflow
+			if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) {
+				dval(&rv0) = dval(&rv);
+				word0(&rv) += P*Exp_msk1;
+				dval(&adj) = dval(&aadj1) * ulp(&rv);
+				dval(&rv) += dval(&adj);
+#ifdef IBM
+				if ((word0(&rv) & Exp_mask) <  P*Exp_msk1)
+#else
+				if ((word0(&rv) & Exp_mask) <= P*Exp_msk1)
+#endif
+					{
+					if (word0(&rv0) == Tiny0
+					 && word1(&rv0) == Tiny1)
+						goto undfl;
+					word0(&rv) = Tiny0;
+					word1(&rv) = Tiny1;
+					goto cont;
+					}
+				else
+					word0(&rv) -= P*Exp_msk1;
+				}
+			else {
+				dval(&adj) = dval(&aadj1) * ulp(&rv);
+				dval(&rv) += dval(&adj);
+				}
+#else /*Sudden_Underflow*/
+			/* Compute dval(&adj) so that the IEEE rounding rules will
+			 * correctly round rv + dval(&adj) in some half-way cases.
+			 * If rv * ulp(&rv) is denormalized (i.e.,
+			 * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
+			 * trouble from bits lost to denormalization;
+			 * example: 1.2e-307 .
+			 */
+			if (y <= (P-1)*Exp_msk1 && aadj > 1.) {
+				dval(&aadj1) = (double)(int)(aadj + 0.5);
+				if (!dsign)
+					dval(&aadj1) = -dval(&aadj1);
+				}
+			dval(&adj) = dval(&aadj1) * ulp(&rv);
+			dval(&rv) += adj;
+#endif /*Sudden_Underflow*/
+#endif /*Avoid_Underflow*/
+			}
+		z = word0(&rv) & Exp_mask;
+#ifndef SET_INEXACT
+#ifdef Avoid_Underflow
+		if (!scale)
+#endif
+		if (y == z) {
+			/* Can we stop now? */
+			L = (Long)aadj;
+			aadj -= L;
+			/* The tolerances below are conservative. */
+			if (dsign || word1(&rv) || word0(&rv) & Bndry_mask) {
+				if (aadj < .4999999 || aadj > .5000001)
+					break;
+				}
+			else if (aadj < .4999999/FLT_RADIX)
+				break;
+			}
+#endif
+ cont:
+		Bfree(bb);
+		Bfree(bd);
+		Bfree(bs);
+		Bfree(delta);
+		}
+	Bfree(bb);
+	Bfree(bd);
+	Bfree(bs);
+	Bfree(bd0);
+	Bfree(delta);
+#ifdef SET_INEXACT
+	if (inexact) {
+		if (!oldinexact) {
+			word0(&rv0) = Exp_1 + (70 << Exp_shift);
+			word1(&rv0) = 0;
+			dval(&rv0) += 1.;
+			}
+		}
+	else if (!oldinexact)
+		clear_inexact();
+#endif
+#ifdef Avoid_Underflow
+	if (scale) {
+		word0(&rv0) = Exp_1 - 2*P*Exp_msk1;
+		word1(&rv0) = 0;
+		dval(&rv) *= dval(&rv0);
+#ifndef NO_ERRNO
+		/* try to avoid the bug of testing an 8087 register value */
+#ifdef IEEE_Arith
+		if (!(word0(&rv) & Exp_mask))
+#else
+		if (word0(&rv) == 0 && word1(&rv) == 0)
+#endif
+			errno = ERANGE;
+#endif
+		}
+#endif /* Avoid_Underflow */
+#ifdef SET_INEXACT
+	if (inexact && !(word0(&rv) & Exp_mask)) {
+		/* set underflow bit */
+		dval(&rv0) = 1e-300;
+		dval(&rv0) *= dval(&rv0);
+		}
+#endif
+ ret:
+	if (se)
+		*se = (char *)s;
+	return sign ? -dval(&rv) : dval(&rv);
+	}
+
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/strtodg.c b/libc/upstream-openbsd/lib/libc/gdtoa/strtodg.c
new file mode 100644
index 0000000..753f6bf
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/strtodg.c
@@ -0,0 +1,1154 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998-2001 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+#ifdef USE_LOCALE
+#include "locale.h"
+#endif
+
+ static CONST int
+fivesbits[] = {	 0,  3,  5,  7, 10, 12, 14, 17, 19, 21,
+		24, 26, 28, 31, 33, 35, 38, 40, 42, 45,
+		47, 49, 52
+#ifdef VAX
+		, 54, 56
+#endif
+		};
+
+ Bigint *
+#ifdef KR_headers
+increment(b) Bigint *b;
+#else
+increment(Bigint *b)
+#endif
+{
+	ULong *x, *xe;
+	Bigint *b1;
+#ifdef Pack_16
+	ULong carry = 1, y;
+#endif
+
+	x = b->x;
+	xe = x + b->wds;
+#ifdef Pack_32
+	do {
+		if (*x < (ULong)0xffffffffL) {
+			++*x;
+			return b;
+			}
+		*x++ = 0;
+		} while(x < xe);
+#else
+	do {
+		y = *x + carry;
+		carry = y >> 16;
+		*x++ = y & 0xffff;
+		if (!carry)
+			return b;
+		} while(x < xe);
+	if (carry)
+#endif
+	{
+		if (b->wds >= b->maxwds) {
+			b1 = Balloc(b->k+1);
+			if (b1 == NULL)
+				return (NULL);
+			Bcopy(b1,b);
+			Bfree(b);
+			b = b1;
+			}
+		b->x[b->wds++] = 1;
+		}
+	return b;
+	}
+
+ void
+#ifdef KR_headers
+decrement(b) Bigint *b;
+#else
+decrement(Bigint *b)
+#endif
+{
+	ULong *x, *xe;
+#ifdef Pack_16
+	ULong borrow = 1, y;
+#endif
+
+	x = b->x;
+	xe = x + b->wds;
+#ifdef Pack_32
+	do {
+		if (*x) {
+			--*x;
+			break;
+			}
+		*x++ = 0xffffffffL;
+		}
+		while(x < xe);
+#else
+	do {
+		y = *x - borrow;
+		borrow = (y & 0x10000) >> 16;
+		*x++ = y & 0xffff;
+		} while(borrow && x < xe);
+#endif
+	}
+
+ static int
+#ifdef KR_headers
+all_on(b, n) Bigint *b; int n;
+#else
+all_on(Bigint *b, int n)
+#endif
+{
+	ULong *x, *xe;
+
+	x = b->x;
+	xe = x + (n >> kshift);
+	while(x < xe)
+		if ((*x++ & ALL_ON) != ALL_ON)
+			return 0;
+	if (n &= kmask)
+		return ((*x | (ALL_ON << n)) & ALL_ON) == ALL_ON;
+	return 1;
+	}
+
+ Bigint *
+#ifdef KR_headers
+set_ones(b, n) Bigint *b; int n;
+#else
+set_ones(Bigint *b, int n)
+#endif
+{
+	int k;
+	ULong *x, *xe;
+
+	k = (n + ((1 << kshift) - 1)) >> kshift;
+	if (b->k < k) {
+		Bfree(b);
+		b = Balloc(k);
+		if (b == NULL)
+			return (NULL);
+		}
+	k = n >> kshift;
+	if (n &= kmask)
+		k++;
+	b->wds = k;
+	x = b->x;
+	xe = x + k;
+	while(x < xe)
+		*x++ = ALL_ON;
+	if (n)
+		x[-1] >>= ULbits - n;
+	return b;
+	}
+
+ static int
+rvOK
+#ifdef KR_headers
+ (d, fpi, exp, bits, exact, rd, irv)
+ U *d; FPI *fpi; Long *exp; ULong *bits; int exact, rd, *irv;
+#else
+ (U *d, FPI *fpi, Long *exp, ULong *bits, int exact, int rd, int *irv)
+#endif
+{
+	Bigint *b;
+	ULong carry, inex, lostbits;
+	int bdif, e, j, k, k1, nb, rv;
+
+	carry = rv = 0;
+	b = d2b(dval(d), &e, &bdif);
+	if (b == NULL) {
+		*irv = STRTOG_NoMemory;
+		return (1);
+	}
+	bdif -= nb = fpi->nbits;
+	e += bdif;
+	if (bdif <= 0) {
+		if (exact)
+			goto trunc;
+		goto ret;
+		}
+	if (P == nb) {
+		if (
+#ifndef IMPRECISE_INEXACT
+			exact &&
+#endif
+			fpi->rounding ==
+#ifdef RND_PRODQUOT
+					FPI_Round_near
+#else
+					Flt_Rounds
+#endif
+			) goto trunc;
+		goto ret;
+		}
+	switch(rd) {
+	  case 1: /* round down (toward -Infinity) */
+		goto trunc;
+	  case 2: /* round up (toward +Infinity) */
+		break;
+	  default: /* round near */
+		k = bdif - 1;
+		if (k < 0)
+			goto trunc;
+		if (!k) {
+			if (!exact)
+				goto ret;
+			if (b->x[0] & 2)
+				break;
+			goto trunc;
+			}
+		if (b->x[k>>kshift] & ((ULong)1 << (k & kmask)))
+			break;
+		goto trunc;
+	  }
+	/* "break" cases: round up 1 bit, then truncate; bdif > 0 */
+	carry = 1;
+ trunc:
+	inex = lostbits = 0;
+	if (bdif > 0) {
+		if ( (lostbits = any_on(b, bdif)) !=0)
+			inex = STRTOG_Inexlo;
+		rshift(b, bdif);
+		if (carry) {
+			inex = STRTOG_Inexhi;
+			b = increment(b);
+			if (b == NULL) {
+				*irv = STRTOG_NoMemory;
+				return (1);
+				}
+			if ( (j = nb & kmask) !=0)
+				j = ULbits - j;
+			if (hi0bits(b->x[b->wds - 1]) != j) {
+				if (!lostbits)
+					lostbits = b->x[0] & 1;
+				rshift(b, 1);
+				e++;
+				}
+			}
+		}
+	else if (bdif < 0) {
+		b = lshift(b, -bdif);
+		if (b == NULL) {
+			*irv = STRTOG_NoMemory;
+			return (1);
+			}
+		}
+	if (e < fpi->emin) {
+		k = fpi->emin - e;
+		e = fpi->emin;
+		if (k > nb || fpi->sudden_underflow) {
+			b->wds = inex = 0;
+			*irv = STRTOG_Underflow | STRTOG_Inexlo;
+			}
+		else {
+			k1 = k - 1;
+			if (k1 > 0 && !lostbits)
+				lostbits = any_on(b, k1);
+			if (!lostbits && !exact)
+				goto ret;
+			lostbits |=
+			  carry = b->x[k1>>kshift] & (1 << (k1 & kmask));
+			rshift(b, k);
+			*irv = STRTOG_Denormal;
+			if (carry) {
+				b = increment(b);
+				if (b == NULL) {
+					*irv = STRTOG_NoMemory;
+					return (1);
+					}
+				inex = STRTOG_Inexhi | STRTOG_Underflow;
+				}
+			else if (lostbits)
+				inex = STRTOG_Inexlo | STRTOG_Underflow;
+			}
+		}
+	else if (e > fpi->emax) {
+		e = fpi->emax + 1;
+		*irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
+#ifndef NO_ERRNO
+		errno = ERANGE;
+#endif
+		b->wds = inex = 0;
+		}
+	*exp = e;
+	copybits(bits, nb, b);
+	*irv |= inex;
+	rv = 1;
+ ret:
+	Bfree(b);
+	return rv;
+	}
+
+ static int
+#ifdef KR_headers
+mantbits(d) U *d;
+#else
+mantbits(U *d)
+#endif
+{
+	ULong L;
+#ifdef VAX
+	L = word1(d) << 16 | word1(d) >> 16;
+	if (L)
+#else
+	if ( (L = word1(d)) !=0)
+#endif
+		return P - lo0bits(&L);
+#ifdef VAX
+	L = word0(d) << 16 | word0(d) >> 16 | Exp_msk11;
+#else
+	L = word0(d) | Exp_msk1;
+#endif
+	return P - 32 - lo0bits(&L);
+	}
+
+ int
+strtodg
+#ifdef KR_headers
+	(s00, se, fpi, exp, bits)
+	CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits;
+#else
+	(CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits)
+#endif
+{
+	int abe, abits, asub;
+	int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm;
+	int dsign, e, e1, e2, emin, esign, finished, i, inex, irv;
+	int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;
+	int sudden_underflow;
+	CONST char *s, *s0, *s1;
+	double adj0, tol;
+	Long L;
+	U adj, rv;
+	ULong *b, *be, y, z;
+	Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;
+#ifdef USE_LOCALE /*{{*/
+#ifdef NO_LOCALE_CACHE
+	char *decimalpoint = localeconv()->decimal_point;
+	int dplen = strlen(decimalpoint);
+#else
+	char *decimalpoint;
+	static char *decimalpoint_cache;
+	static int dplen;
+	if (!(s0 = decimalpoint_cache)) {
+		s0 = localeconv()->decimal_point;
+		if ((decimalpoint_cache = (char*)MALLOC(strlen(s0) + 1))) {
+			strlcpy(decimalpoint_cache, s0, strlen(s0) + 1);
+			s0 = decimalpoint_cache;
+			}
+		dplen = strlen(s0);
+		}
+	decimalpoint = (char*)s0;
+#endif /*NO_LOCALE_CACHE*/
+#else  /*USE_LOCALE}{*/
+#define dplen 1
+#endif /*USE_LOCALE}}*/
+
+	irv = STRTOG_Zero;
+	denorm = sign = nz0 = nz = 0;
+	dval(&rv) = 0.;
+	rvb = 0;
+	nbits = fpi->nbits;
+	for(s = s00;;s++) switch(*s) {
+		case '-':
+			sign = 1;
+			/* no break */
+		case '+':
+			if (*++s)
+				goto break2;
+			/* no break */
+		case 0:
+			sign = 0;
+			irv = STRTOG_NoNumber;
+			s = s00;
+			goto ret;
+		case '\t':
+		case '\n':
+		case '\v':
+		case '\f':
+		case '\r':
+		case ' ':
+			continue;
+		default:
+			goto break2;
+		}
+ break2:
+	if (*s == '0') {
+#ifndef NO_HEX_FP
+		switch(s[1]) {
+		  case 'x':
+		  case 'X':
+			irv = gethex(&s, fpi, exp, &rvb, sign);
+			if (irv == STRTOG_NoMemory)
+				return (STRTOG_NoMemory);
+			if (irv == STRTOG_NoNumber) {
+				s = s00;
+				sign = 0;
+				}
+			goto ret;
+		  }
+#endif
+		nz0 = 1;
+		while(*++s == '0') ;
+		if (!*s)
+			goto ret;
+		}
+	sudden_underflow = fpi->sudden_underflow;
+	s0 = s;
+	y = z = 0;
+	for(decpt = nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
+		if (nd < 9)
+			y = 10*y + c - '0';
+		else if (nd < 16)
+			z = 10*z + c - '0';
+	nd0 = nd;
+#ifdef USE_LOCALE
+	if (c == *decimalpoint) {
+		for(i = 1; decimalpoint[i]; ++i)
+			if (s[i] != decimalpoint[i])
+				goto dig_done;
+		s += i;
+		c = *s;
+#else
+	if (c == '.') {
+		c = *++s;
+#endif
+		decpt = 1;
+		if (!nd) {
+			for(; c == '0'; c = *++s)
+				nz++;
+			if (c > '0' && c <= '9') {
+				s0 = s;
+				nf += nz;
+				nz = 0;
+				goto have_dig;
+				}
+			goto dig_done;
+			}
+		for(; c >= '0' && c <= '9'; c = *++s) {
+ have_dig:
+			nz++;
+			if (c -= '0') {
+				nf += nz;
+				for(i = 1; i < nz; i++)
+					if (nd++ < 9)
+						y *= 10;
+					else if (nd <= DBL_DIG + 1)
+						z *= 10;
+				if (nd++ < 9)
+					y = 10*y + c;
+				else if (nd <= DBL_DIG + 1)
+					z = 10*z + c;
+				nz = 0;
+				}
+			}
+		}/*}*/
+ dig_done:
+	e = 0;
+	if (c == 'e' || c == 'E') {
+		if (!nd && !nz && !nz0) {
+			irv = STRTOG_NoNumber;
+			s = s00;
+			goto ret;
+			}
+		s00 = s;
+		esign = 0;
+		switch(c = *++s) {
+			case '-':
+				esign = 1;
+			case '+':
+				c = *++s;
+			}
+		if (c >= '0' && c <= '9') {
+			while(c == '0')
+				c = *++s;
+			if (c > '0' && c <= '9') {
+				L = c - '0';
+				s1 = s;
+				while((c = *++s) >= '0' && c <= '9')
+					L = 10*L + c - '0';
+				if (s - s1 > 8 || L > 19999)
+					/* Avoid confusion from exponents
+					 * so large that e might overflow.
+					 */
+					e = 19999; /* safe for 16 bit ints */
+				else
+					e = (int)L;
+				if (esign)
+					e = -e;
+				}
+			else
+				e = 0;
+			}
+		else
+			s = s00;
+		}
+	if (!nd) {
+		if (!nz && !nz0) {
+#ifdef INFNAN_CHECK
+			/* Check for Nan and Infinity */
+			if (!decpt)
+			 switch(c) {
+			  case 'i':
+			  case 'I':
+				if (match(&s,"nf")) {
+					--s;
+					if (!match(&s,"inity"))
+						++s;
+					irv = STRTOG_Infinite;
+					goto infnanexp;
+					}
+				break;
+			  case 'n':
+			  case 'N':
+				if (match(&s, "an")) {
+					irv = STRTOG_NaN;
+					*exp = fpi->emax + 1;
+#ifndef No_Hex_NaN
+					if (*s == '(') /*)*/
+						irv = hexnan(&s, fpi, bits);
+#endif
+					goto infnanexp;
+					}
+			  }
+#endif /* INFNAN_CHECK */
+			irv = STRTOG_NoNumber;
+			s = s00;
+			}
+		goto ret;
+		}
+
+	irv = STRTOG_Normal;
+	e1 = e -= nf;
+	rd = 0;
+	switch(fpi->rounding & 3) {
+	  case FPI_Round_up:
+		rd = 2 - sign;
+		break;
+	  case FPI_Round_zero:
+		rd = 1;
+		break;
+	  case FPI_Round_down:
+		rd = 1 + sign;
+	  }
+
+	/* Now we have nd0 digits, starting at s0, followed by a
+	 * decimal point, followed by nd-nd0 digits.  The number we're
+	 * after is the integer represented by those digits times
+	 * 10**e */
+
+	if (!nd0)
+		nd0 = nd;
+	k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
+	dval(&rv) = y;
+	if (k > 9)
+		dval(&rv) = tens[k - 9] * dval(&rv) + z;
+	bd0 = 0;
+	if (nbits <= P && nd <= DBL_DIG) {
+		if (!e) {
+			if (rvOK(&rv, fpi, exp, bits, 1, rd, &irv)) {
+				if (irv == STRTOG_NoMemory)
+					return (STRTOG_NoMemory);
+				goto ret;
+				}
+			}
+		else if (e > 0) {
+			if (e <= Ten_pmax) {
+#ifdef VAX
+				goto vax_ovfl_check;
+#else
+				i = fivesbits[e] + mantbits(&rv) <= P;
+				/* rv = */ rounded_product(dval(&rv), tens[e]);
+				if (rvOK(&rv, fpi, exp, bits, i, rd, &irv)) {
+					if (irv == STRTOG_NoMemory)
+						return (STRTOG_NoMemory);
+					goto ret;
+					}
+				e1 -= e;
+				goto rv_notOK;
+#endif
+				}
+			i = DBL_DIG - nd;
+			if (e <= Ten_pmax + i) {
+				/* A fancier test would sometimes let us do
+				 * this for larger i values.
+				 */
+				e2 = e - i;
+				e1 -= i;
+				dval(&rv) *= tens[i];
+#ifdef VAX
+				/* VAX exponent range is so narrow we must
+				 * worry about overflow here...
+				 */
+ vax_ovfl_check:
+				dval(&adj) = dval(&rv);
+				word0(&adj) -= P*Exp_msk1;
+				/* adj = */ rounded_product(dval(&adj), tens[e2]);
+				if ((word0(&adj) & Exp_mask)
+				 > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
+					goto rv_notOK;
+				word0(&adj) += P*Exp_msk1;
+				dval(&rv) = dval(&adj);
+#else
+				/* rv = */ rounded_product(dval(&rv), tens[e2]);
+#endif
+				if (rvOK(&rv, fpi, exp, bits, 0, rd, &irv)) {
+					if (irv == STRTOG_NoMemory)
+						return (STRTOG_NoMemory);
+					goto ret;
+					}
+				e1 -= e2;
+				}
+			}
+#ifndef Inaccurate_Divide
+		else if (e >= -Ten_pmax) {
+			/* rv = */ rounded_quotient(dval(&rv), tens[-e]);
+			if (rvOK(&rv, fpi, exp, bits, 0, rd, &irv)) {
+				if (irv == STRTOG_NoMemory)
+					return (STRTOG_NoMemory);
+				goto ret;
+				}
+			e1 -= e;
+			}
+#endif
+		}
+ rv_notOK:
+	e1 += nd - k;
+
+	/* Get starting approximation = rv * 10**e1 */
+
+	e2 = 0;
+	if (e1 > 0) {
+		if ( (i = e1 & 15) !=0)
+			dval(&rv) *= tens[i];
+		if (e1 &= ~15) {
+			e1 >>= 4;
+			while(e1 >= (1 << (n_bigtens-1))) {
+				e2 += ((word0(&rv) & Exp_mask)
+					>> Exp_shift1) - Bias;
+				word0(&rv) &= ~Exp_mask;
+				word0(&rv) |= Bias << Exp_shift1;
+				dval(&rv) *= bigtens[n_bigtens-1];
+				e1 -= 1 << (n_bigtens-1);
+				}
+			e2 += ((word0(&rv) & Exp_mask) >> Exp_shift1) - Bias;
+			word0(&rv) &= ~Exp_mask;
+			word0(&rv) |= Bias << Exp_shift1;
+			for(j = 0; e1 > 0; j++, e1 >>= 1)
+				if (e1 & 1)
+					dval(&rv) *= bigtens[j];
+			}
+		}
+	else if (e1 < 0) {
+		e1 = -e1;
+		if ( (i = e1 & 15) !=0)
+			dval(&rv) /= tens[i];
+		if (e1 &= ~15) {
+			e1 >>= 4;
+			while(e1 >= (1 << (n_bigtens-1))) {
+				e2 += ((word0(&rv) & Exp_mask)
+					>> Exp_shift1) - Bias;
+				word0(&rv) &= ~Exp_mask;
+				word0(&rv) |= Bias << Exp_shift1;
+				dval(&rv) *= tinytens[n_bigtens-1];
+				e1 -= 1 << (n_bigtens-1);
+				}
+			e2 += ((word0(&rv) & Exp_mask) >> Exp_shift1) - Bias;
+			word0(&rv) &= ~Exp_mask;
+			word0(&rv) |= Bias << Exp_shift1;
+			for(j = 0; e1 > 0; j++, e1 >>= 1)
+				if (e1 & 1)
+					dval(&rv) *= tinytens[j];
+			}
+		}
+#ifdef IBM
+	/* e2 is a correction to the (base 2) exponent of the return
+	 * value, reflecting adjustments above to avoid overflow in the
+	 * native arithmetic.  For native IBM (base 16) arithmetic, we
+	 * must multiply e2 by 4 to change from base 16 to 2.
+	 */
+	e2 <<= 2;
+#endif
+	rvb = d2b(dval(&rv), &rve, &rvbits);	/* rv = rvb * 2^rve */
+	if (rvb == NULL)
+		return (STRTOG_NoMemory);
+	rve += e2;
+	if ((j = rvbits - nbits) > 0) {
+		rshift(rvb, j);
+		rvbits = nbits;
+		rve += j;
+		}
+	bb0 = 0;	/* trailing zero bits in rvb */
+	e2 = rve + rvbits - nbits;
+	if (e2 > fpi->emax + 1)
+		goto huge;
+	rve1 = rve + rvbits - nbits;
+	if (e2 < (emin = fpi->emin)) {
+		denorm = 1;
+		j = rve - emin;
+		if (j > 0) {
+			rvb = lshift(rvb, j);
+			if (rvb == NULL)
+				return (STRTOG_NoMemory);
+			rvbits += j;
+			}
+		else if (j < 0) {
+			rvbits += j;
+			if (rvbits <= 0) {
+				if (rvbits < -1) {
+ ufl:
+					rvb->wds = 0;
+					rvb->x[0] = 0;
+					*exp = emin;
+					irv = STRTOG_Underflow | STRTOG_Inexlo;
+					goto ret;
+					}
+				rvb->x[0] = rvb->wds = rvbits = 1;
+				}
+			else
+				rshift(rvb, -j);
+			}
+		rve = rve1 = emin;
+		if (sudden_underflow && e2 + 1 < emin)
+			goto ufl;
+		}
+
+	/* Now the hard part -- adjusting rv to the correct value.*/
+
+	/* Put digits into bd: true value = bd * 10^e */
+
+	bd0 = s2b(s0, nd0, nd, y, dplen);
+	if (bd0 == NULL)
+		return (STRTOG_NoMemory);
+
+	for(;;) {
+		bd = Balloc(bd0->k);
+		if (bd == NULL)
+			return (STRTOG_NoMemory);
+		Bcopy(bd, bd0);
+		bb = Balloc(rvb->k);
+		if (bb == NULL)
+			return (STRTOG_NoMemory);
+		Bcopy(bb, rvb);
+		bbbits = rvbits - bb0;
+		bbe = rve + bb0;
+		bs = i2b(1);
+		if (bs == NULL)
+			return (STRTOG_NoMemory);
+
+		if (e >= 0) {
+			bb2 = bb5 = 0;
+			bd2 = bd5 = e;
+			}
+		else {
+			bb2 = bb5 = -e;
+			bd2 = bd5 = 0;
+			}
+		if (bbe >= 0)
+			bb2 += bbe;
+		else
+			bd2 -= bbe;
+		bs2 = bb2;
+		j = nbits + 1 - bbbits;
+		i = bbe + bbbits - nbits;
+		if (i < emin)	/* denormal */
+			j += i - emin;
+		bb2 += j;
+		bd2 += j;
+		i = bb2 < bd2 ? bb2 : bd2;
+		if (i > bs2)
+			i = bs2;
+		if (i > 0) {
+			bb2 -= i;
+			bd2 -= i;
+			bs2 -= i;
+			}
+		if (bb5 > 0) {
+			bs = pow5mult(bs, bb5);
+			if (bs == NULL)
+				return (STRTOG_NoMemory);
+			bb1 = mult(bs, bb);
+			if (bb1 == NULL)
+				return (STRTOG_NoMemory);
+			Bfree(bb);
+			bb = bb1;
+			}
+		bb2 -= bb0;
+		if (bb2 > 0) {
+			bb = lshift(bb, bb2);
+			if (bb == NULL)
+				return (STRTOG_NoMemory);
+			}
+		else if (bb2 < 0)
+			rshift(bb, -bb2);
+		if (bd5 > 0) {
+			bd = pow5mult(bd, bd5);
+			if (bd == NULL)
+				return (STRTOG_NoMemory);
+			}
+		if (bd2 > 0) {
+			bd = lshift(bd, bd2);
+			if (bd == NULL)
+				return (STRTOG_NoMemory);
+			}
+		if (bs2 > 0) {
+			bs = lshift(bs, bs2);
+			if (bs == NULL)
+				return (STRTOG_NoMemory);
+			}
+		asub = 1;
+		inex = STRTOG_Inexhi;
+		delta = diff(bb, bd);
+		if (delta == NULL)
+			return (STRTOG_NoMemory);
+		if (delta->wds <= 1 && !delta->x[0])
+			break;
+		dsign = delta->sign;
+		delta->sign = finished = 0;
+		L = 0;
+		i = cmp(delta, bs);
+		if (rd && i <= 0) {
+			irv = STRTOG_Normal;
+			if ( (finished = dsign ^ (rd&1)) !=0) {
+				if (dsign != 0) {
+					irv |= STRTOG_Inexhi;
+					goto adj1;
+					}
+				irv |= STRTOG_Inexlo;
+				if (rve1 == emin)
+					goto adj1;
+				for(i = 0, j = nbits; j >= ULbits;
+						i++, j -= ULbits) {
+					if (rvb->x[i] & ALL_ON)
+						goto adj1;
+					}
+				if (j > 1 && lo0bits(rvb->x + i) < j - 1)
+					goto adj1;
+				rve = rve1 - 1;
+				rvb = set_ones(rvb, rvbits = nbits);
+				if (rvb == NULL)
+					return (STRTOG_NoMemory);
+				break;
+				}
+			irv |= dsign ? STRTOG_Inexlo : STRTOG_Inexhi;
+			break;
+			}
+		if (i < 0) {
+			/* Error is less than half an ulp -- check for
+			 * special case of mantissa a power of two.
+			 */
+			irv = dsign
+				? STRTOG_Normal | STRTOG_Inexlo
+				: STRTOG_Normal | STRTOG_Inexhi;
+			if (dsign || bbbits > 1 || denorm || rve1 == emin)
+				break;
+			delta = lshift(delta,1);
+			if (delta == NULL)
+				return (STRTOG_NoMemory);
+			if (cmp(delta, bs) > 0) {
+				irv = STRTOG_Normal | STRTOG_Inexlo;
+				goto drop_down;
+				}
+			break;
+			}
+		if (i == 0) {
+			/* exactly half-way between */
+			if (dsign) {
+				if (denorm && all_on(rvb, rvbits)) {
+					/*boundary case -- increment exponent*/
+					rvb->wds = 1;
+					rvb->x[0] = 1;
+					rve = emin + nbits - (rvbits = 1);
+					irv = STRTOG_Normal | STRTOG_Inexhi;
+					denorm = 0;
+					break;
+					}
+				irv = STRTOG_Normal | STRTOG_Inexlo;
+				}
+			else if (bbbits == 1) {
+				irv = STRTOG_Normal;
+ drop_down:
+				/* boundary case -- decrement exponent */
+				if (rve1 == emin) {
+					irv = STRTOG_Normal | STRTOG_Inexhi;
+					if (rvb->wds == 1 && rvb->x[0] == 1)
+						sudden_underflow = 1;
+					break;
+					}
+				rve -= nbits;
+				rvb = set_ones(rvb, rvbits = nbits);
+				if (rvb == NULL)
+					return (STRTOG_NoMemory);
+				break;
+				}
+			else
+				irv = STRTOG_Normal | STRTOG_Inexhi;
+			if ((bbbits < nbits && !denorm) || !(rvb->x[0] & 1))
+				break;
+			if (dsign) {
+				rvb = increment(rvb);
+				if (rvb == NULL)
+					return (STRTOG_NoMemory);
+				j = kmask & (ULbits - (rvbits & kmask));
+				if (hi0bits(rvb->x[rvb->wds - 1]) != j)
+					rvbits++;
+				irv = STRTOG_Normal | STRTOG_Inexhi;
+				}
+			else {
+				if (bbbits == 1)
+					goto undfl;
+				decrement(rvb);
+				irv = STRTOG_Normal | STRTOG_Inexlo;
+				}
+			break;
+			}
+		if ((dval(&adj) = ratio(delta, bs)) <= 2.) {
+ adj1:
+			inex = STRTOG_Inexlo;
+			if (dsign) {
+				asub = 0;
+				inex = STRTOG_Inexhi;
+				}
+			else if (denorm && bbbits <= 1) {
+ undfl:
+				rvb->wds = 0;
+				rve = emin;
+				irv = STRTOG_Underflow | STRTOG_Inexlo;
+				break;
+				}
+			adj0 = dval(&adj) = 1.;
+			}
+		else {
+			adj0 = dval(&adj) *= 0.5;
+			if (dsign) {
+				asub = 0;
+				inex = STRTOG_Inexlo;
+				}
+			if (dval(&adj) < 2147483647.) {
+				L = adj0;
+				adj0 -= L;
+				switch(rd) {
+				  case 0:
+					if (adj0 >= .5)
+						goto inc_L;
+					break;
+				  case 1:
+					if (asub && adj0 > 0.)
+						goto inc_L;
+					break;
+				  case 2:
+					if (!asub && adj0 > 0.) {
+ inc_L:
+						L++;
+						inex = STRTOG_Inexact - inex;
+						}
+				  }
+				dval(&adj) = L;
+				}
+			}
+		y = rve + rvbits;
+
+		/* adj *= ulp(dval(&rv)); */
+		/* if (asub) rv -= adj; else rv += adj; */
+
+		if (!denorm && rvbits < nbits) {
+			rvb = lshift(rvb, j = nbits - rvbits);
+			if (rvb == NULL)
+				return (STRTOG_NoMemory);
+			rve -= j;
+			rvbits = nbits;
+			}
+		ab = d2b(dval(&adj), &abe, &abits);
+		if (ab == NULL)
+			return (STRTOG_NoMemory);
+		if (abe < 0)
+			rshift(ab, -abe);
+		else if (abe > 0) {
+			ab = lshift(ab, abe);
+			if (ab == NULL)
+				return (STRTOG_NoMemory);
+			}
+		rvb0 = rvb;
+		if (asub) {
+			/* rv -= adj; */
+			j = hi0bits(rvb->x[rvb->wds-1]);
+			rvb = diff(rvb, ab);
+			if (rvb == NULL)
+				return (STRTOG_NoMemory);
+			k = rvb0->wds - 1;
+			if (denorm)
+				/* do nothing */;
+			else if (rvb->wds <= k
+				|| hi0bits( rvb->x[k]) >
+				   hi0bits(rvb0->x[k])) {
+				/* unlikely; can only have lost 1 high bit */
+				if (rve1 == emin) {
+					--rvbits;
+					denorm = 1;
+					}
+				else {
+					rvb = lshift(rvb, 1);
+					if (rvb == NULL)
+						return (STRTOG_NoMemory);
+					--rve;
+					--rve1;
+					L = finished = 0;
+					}
+				}
+			}
+		else {
+			rvb = sum(rvb, ab);
+			if (rvb == NULL)
+				return (STRTOG_NoMemory);
+			k = rvb->wds - 1;
+			if (k >= rvb0->wds
+			 || hi0bits(rvb->x[k]) < hi0bits(rvb0->x[k])) {
+				if (denorm) {
+					if (++rvbits == nbits)
+						denorm = 0;
+					}
+				else {
+					rshift(rvb, 1);
+					rve++;
+					rve1++;
+					L = 0;
+					}
+				}
+			}
+		Bfree(ab);
+		Bfree(rvb0);
+		if (finished)
+			break;
+
+		z = rve + rvbits;
+		if (y == z && L) {
+			/* Can we stop now? */
+			tol = dval(&adj) * 5e-16; /* > max rel error */
+			dval(&adj) = adj0 - .5;
+			if (dval(&adj) < -tol) {
+				if (adj0 > tol) {
+					irv |= inex;
+					break;
+					}
+				}
+			else if (dval(&adj) > tol && adj0 < 1. - tol) {
+				irv |= inex;
+				break;
+				}
+			}
+		bb0 = denorm ? 0 : trailz(rvb);
+		Bfree(bb);
+		Bfree(bd);
+		Bfree(bs);
+		Bfree(delta);
+		}
+	if (!denorm && (j = nbits - rvbits)) {
+		if (j > 0) {
+			rvb = lshift(rvb, j);
+			if (rvb == NULL)
+				return (STRTOG_NoMemory);
+			}
+		else
+			rshift(rvb, -j);
+		rve -= j;
+		}
+	*exp = rve;
+	Bfree(bb);
+	Bfree(bd);
+	Bfree(bs);
+	Bfree(bd0);
+	Bfree(delta);
+	if (rve > fpi->emax) {
+		switch(fpi->rounding & 3) {
+		  case FPI_Round_near:
+			goto huge;
+		  case FPI_Round_up:
+			if (!sign)
+				goto huge;
+			break;
+		  case FPI_Round_down:
+			if (sign)
+				goto huge;
+		  }
+		/* Round to largest representable magnitude */
+		Bfree(rvb);
+		rvb = 0;
+		irv = STRTOG_Normal | STRTOG_Inexlo;
+		*exp = fpi->emax;
+		b = bits;
+		be = b + ((fpi->nbits + 31) >> 5);
+		while(b < be)
+			*b++ = -1;
+		if ((j = fpi->nbits & 0x1f))
+			*--be >>= (32 - j);
+		goto ret;
+ huge:
+		rvb->wds = 0;
+		irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
+#ifndef NO_ERRNO
+		errno = ERANGE;
+#endif
+ infnanexp:
+		*exp = fpi->emax + 1;
+		}
+ ret:
+	if (denorm) {
+		if (sudden_underflow) {
+			rvb->wds = 0;
+			irv = STRTOG_Underflow | STRTOG_Inexlo;
+#ifndef NO_ERRNO
+			errno = ERANGE;
+#endif
+			}
+		else  {
+			irv = (irv & ~STRTOG_Retmask) |
+				(rvb->wds > 0 ? STRTOG_Denormal : STRTOG_Zero);
+			if (irv & STRTOG_Inexact) {
+				irv |= STRTOG_Underflow;
+#ifndef NO_ERRNO
+				errno = ERANGE;
+#endif
+				}
+			}
+		}
+	if (se)
+		*se = (char *)s;
+	if (sign)
+		irv |= STRTOG_Neg;
+	if (rvb) {
+		copybits(bits, nbits, rvb);
+		Bfree(rvb);
+		}
+	return irv;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/strtof.c b/libc/upstream-openbsd/lib/libc/gdtoa/strtof.c
new file mode 100644
index 0000000..224491b
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/strtof.c
@@ -0,0 +1,81 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ float
+#ifdef KR_headers
+strtof(s, sp) CONST char *s; char **sp;
+#else
+strtof(CONST char *s, char **sp)
+#endif
+{
+	static FPI fpi0 = { 24, 1-127-24+1,  254-127-24+1, 1, SI };
+	ULong bits[1];
+	Long exp;
+	int k;
+	union { ULong L[1]; float f; } u;
+#ifdef Honor_FLT_ROUNDS
+#include "gdtoa_fltrnds.h"
+#else
+#define fpi &fpi0
+#endif
+
+	k = strtodg(s, sp, fpi, &exp, bits);
+	switch(k & STRTOG_Retmask) {
+	  case STRTOG_NoNumber:
+	  case STRTOG_Zero:
+		u.L[0] = 0;
+		break;
+
+	  case STRTOG_Normal:
+	  case STRTOG_NaNbits:
+		u.L[0] = (bits[0] & 0x7fffff) | ((exp + 0x7f + 23) << 23);
+		break;
+
+	  case STRTOG_Denormal:
+		u.L[0] = bits[0];
+		break;
+
+	  case STRTOG_NoMemory:
+		errno = ERANGE;
+		/* FALLTHROUGH */
+	  case STRTOG_Infinite:
+		u.L[0] = 0x7f800000;
+		break;
+
+	  case STRTOG_NaN:
+		u.L[0] = f_QNAN;
+	  }
+	if (k & STRTOG_Neg)
+		u.L[0] |= 0x80000000L;
+	return u.f;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/strtorQ.c b/libc/upstream-openbsd/lib/libc/gdtoa/strtorQ.c
new file mode 100644
index 0000000..715cb08
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/strtorQ.c
@@ -0,0 +1,120 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+#undef _0
+#undef _1
+
+/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
+
+#ifdef IEEE_MC68k
+#define _0 0
+#define _1 1
+#define _2 2
+#define _3 3
+#endif
+#ifdef IEEE_8087
+#define _0 3
+#define _1 2
+#define _2 1
+#define _3 0
+#endif
+
+ void
+#ifdef KR_headers
+ULtoQ(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k;
+#else
+ULtoQ(ULong *L, ULong *bits, Long exp, int k)
+#endif
+{
+	switch(k & STRTOG_Retmask) {
+	  case STRTOG_NoNumber:
+	  case STRTOG_Zero:
+		L[0] = L[1] = L[2] = L[3] = 0;
+		break;
+
+	  case STRTOG_Normal:
+	  case STRTOG_NaNbits:
+		L[_3] = bits[0];
+		L[_2] = bits[1];
+		L[_1] = bits[2];
+		L[_0] = (bits[3] & ~0x10000) | ((exp + 0x3fff + 112) << 16);
+		break;
+
+	  case STRTOG_Denormal:
+		L[_3] = bits[0];
+		L[_2] = bits[1];
+		L[_1] = bits[2];
+		L[_0] = bits[3];
+		break;
+
+	  case STRTOG_NoMemory:
+		errno = ERANGE;
+		/* FALLTHROUGH */
+	  case STRTOG_Infinite:
+		L[_0] = 0x7fff0000;
+		L[_1] = L[_2] = L[_3] = 0;
+		break;
+
+	  case STRTOG_NaN:
+		L[0] = ld_QNAN0;
+		L[1] = ld_QNAN1;
+		L[2] = ld_QNAN2;
+		L[3] = ld_QNAN3;
+	  }
+	if (k & STRTOG_Neg)
+		L[_0] |= 0x80000000L;
+	}
+
+ int
+#ifdef KR_headers
+strtorQ(s, sp, rounding, L) CONST char *s; char **sp; int rounding; void *L;
+#else
+strtorQ(CONST char *s, char **sp, int rounding, void *L)
+#endif
+{
+	static FPI fpi0 = { 113, 1-16383-113+1, 32766-16383-113+1, 1, SI };
+	FPI *fpi, fpi1;
+	ULong bits[4];
+	Long exp;
+	int k;
+
+	fpi = &fpi0;
+	if (rounding != FPI_Round_near) {
+		fpi1 = fpi0;
+		fpi1.rounding = rounding;
+		fpi = &fpi1;
+		}
+	k = strtodg(s, sp, fpi, &exp, bits);
+	ULtoQ((ULong*)L, bits, exp, k);
+	return k;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/strtord.c b/libc/upstream-openbsd/lib/libc/gdtoa/strtord.c
new file mode 100644
index 0000000..966d264
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/strtord.c
@@ -0,0 +1,96 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ void
+#ifdef KR_headers
+ULtod(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k;
+#else
+ULtod(ULong *L, ULong *bits, Long exp, int k)
+#endif
+{
+	switch(k & STRTOG_Retmask) {
+	  case STRTOG_NoNumber:
+	  case STRTOG_Zero:
+		L[0] = L[1] = 0;
+		break;
+
+	  case STRTOG_Denormal:
+		L[_1] = bits[0];
+		L[_0] = bits[1];
+		break;
+
+	  case STRTOG_Normal:
+	  case STRTOG_NaNbits:
+		L[_1] = bits[0];
+		L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
+		break;
+
+	  case STRTOG_NoMemory:
+		errno = ERANGE;
+		/* FALLTHROUGH */
+	  case STRTOG_Infinite:
+		L[_0] = 0x7ff00000;
+		L[_1] = 0;
+		break;
+
+	  case STRTOG_NaN:
+		L[0] = d_QNAN0;
+		L[1] = d_QNAN1;
+	  }
+	if (k & STRTOG_Neg)
+		L[_0] |= 0x80000000L;
+	}
+
+ int
+#ifdef KR_headers
+strtord(s, sp, rounding, d) CONST char *s; char **sp; int rounding; double *d;
+#else
+strtord(CONST char *s, char **sp, int rounding, double *d)
+#endif
+{
+	static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
+	FPI *fpi, fpi1;
+	ULong bits[2];
+	Long exp;
+	int k;
+
+	fpi = &fpi0;
+	if (rounding != FPI_Round_near) {
+		fpi1 = fpi0;
+		fpi1.rounding = rounding;
+		fpi = &fpi1;
+		}
+	k = strtodg(s, sp, fpi, &exp, bits);
+	ULtod((ULong*)d, bits, exp, k);
+	return k;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/sum.c b/libc/upstream-openbsd/lib/libc/gdtoa/sum.c
new file mode 100644
index 0000000..c6eb954
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/sum.c
@@ -0,0 +1,102 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ Bigint *
+#ifdef KR_headers
+sum(a, b) Bigint *a; Bigint *b;
+#else
+sum(Bigint *a, Bigint *b)
+#endif
+{
+	Bigint *c;
+	ULong carry, *xc, *xa, *xb, *xe, y;
+#ifdef Pack_32
+	ULong z;
+#endif
+
+	if (a->wds < b->wds) {
+		c = b; b = a; a = c;
+		}
+	c = Balloc(a->k);
+	if (c == NULL)
+		return (NULL);
+	c->wds = a->wds;
+	carry = 0;
+	xa = a->x;
+	xb = b->x;
+	xc = c->x;
+	xe = xc + b->wds;
+#ifdef Pack_32
+	do {
+		y = (*xa & 0xffff) + (*xb & 0xffff) + carry;
+		carry = (y & 0x10000) >> 16;
+		z = (*xa++ >> 16) + (*xb++ >> 16) + carry;
+		carry = (z & 0x10000) >> 16;
+		Storeinc(xc, z, y);
+		}
+		while(xc < xe);
+	xe += a->wds - b->wds;
+	while(xc < xe) {
+		y = (*xa & 0xffff) + carry;
+		carry = (y & 0x10000) >> 16;
+		z = (*xa++ >> 16) + carry;
+		carry = (z & 0x10000) >> 16;
+		Storeinc(xc, z, y);
+		}
+#else
+	do {
+		y = *xa++ + *xb++ + carry;
+		carry = (y & 0x10000) >> 16;
+		*xc++ = y & 0xffff;
+		}
+		while(xc < xe);
+	xe += a->wds - b->wds;
+	while(xc < xe) {
+		y = *xa++ + carry;
+		carry = (y & 0x10000) >> 16;
+		*xc++ = y & 0xffff;
+		}
+#endif
+	if (carry) {
+		if (c->wds == c->maxwds) {
+			b = Balloc(c->k + 1);
+			if (b == NULL)
+				return (NULL);
+			Bcopy(b, c);
+			Bfree(c);
+			c = b;
+			}
+		c->x[c->wds++] = 1;
+		}
+	return c;
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/ulp.c b/libc/upstream-openbsd/lib/libc/gdtoa/ulp.c
new file mode 100644
index 0000000..17e9f86
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/ulp.c
@@ -0,0 +1,70 @@
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 1999 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, 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.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to ".").	*/
+
+#include "gdtoaimp.h"
+
+ double
+ulp
+#ifdef KR_headers
+	(x) U *x;
+#else
+	(U *x)
+#endif
+{
+	Long L;
+	U a;
+
+	L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
+#ifndef Sudden_Underflow
+	if (L > 0) {
+#endif
+#ifdef IBM
+		L |= Exp_msk1 >> 4;
+#endif
+		word0(&a) = L;
+		word1(&a) = 0;
+#ifndef Sudden_Underflow
+		}
+	else {
+		L = -L >> Exp_shift;
+		if (L < Exp_shift) {
+			word0(&a) = 0x80000 >> L;
+			word1(&a) = 0;
+			}
+		else {
+			word0(&a) = 0;
+			L -= Exp_shift;
+			word1(&a) = L >= 31 ? 1 : 1 << (31 - L);
+			}
+		}
+#endif
+	return dval(&a);
+	}
diff --git a/libc/upstream-openbsd/lib/libc/gen/alarm.c b/libc/upstream-openbsd/lib/libc/gen/alarm.c
new file mode 100644
index 0000000..2af847a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/alarm.c
@@ -0,0 +1,51 @@
+/*	$OpenBSD: alarm.c,v 1.7 2005/08/08 08:05:33 espie Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Backwards compatible alarm.
+ */
+#include <sys/time.h>
+#include <unistd.h>
+
+unsigned int
+alarm(unsigned int secs)
+{
+	struct itimerval it, oitv;
+	struct itimerval *itp = &it;
+
+	timerclear(&itp->it_interval);
+	itp->it_value.tv_sec = secs;
+	itp->it_value.tv_usec = 0;
+	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
+		return ((unsigned int) -1);
+	if (oitv.it_value.tv_usec)
+		oitv.it_value.tv_sec++;
+	return (oitv.it_value.tv_sec);
+}
diff --git a/libc/unistd/charclass.h b/libc/upstream-openbsd/lib/libc/gen/charclass.h
similarity index 100%
rename from libc/unistd/charclass.h
rename to libc/upstream-openbsd/lib/libc/gen/charclass.h
diff --git a/libc/upstream-openbsd/lib/libc/gen/ctype_.c b/libc/upstream-openbsd/lib/libc/gen/ctype_.c
new file mode 100644
index 0000000..89c8257
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/ctype_.c
@@ -0,0 +1,76 @@
+/*	$OpenBSD: ctype_.c,v 1.10 2011/09/22 09:06:10 stsp Exp $ */
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include "ctype_private.h"
+
+const char _C_ctype_[1 + CTYPE_NUM_CHARS] = {
+	0,
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
+	_C,	_C|_S,	_C|_S,	_C|_S,	_C|_S,	_C|_S,	_C,	_C,
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
+	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
+   _S|(char)_B,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
+	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
+	_N,	_N,	_N,	_N,	_N,	_N,	_N,	_N,
+	_N,	_N,	_P,	_P,	_P,	_P,	_P,	_P,
+	_P,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U,
+	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
+	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
+	_U,	_U,	_U,	_P,	_P,	_P,	_P,	_P,
+	_P,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L,
+	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
+	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
+	_L,	_L,	_L,	_P,	_P,	_P,	_P,	_C,
+
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* 80 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* 88 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* 90 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* 98 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* A0 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* A8 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* B0 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* B8 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* C0 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* C8 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* D0 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* D8 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* E0 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* E8 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0, /* F0 */
+	 0,	 0,	 0,	 0,	 0,	 0,	 0,	 0  /* F8 */
+};
+
+const char *_ctype_ = _C_ctype_;
diff --git a/libc/upstream-openbsd/lib/libc/gen/exec.c b/libc/upstream-openbsd/lib/libc/gen/exec.c
new file mode 100644
index 0000000..1e2f7d9
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/exec.c
@@ -0,0 +1,251 @@
+/*	$OpenBSD: exec.c,v 1.21 2013/09/30 12:02:33 millert Exp $ */
+/*-
+ * Copyright (c) 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/uio.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+extern char **environ;
+
+int
+execl(const char *name, const char *arg, ...)
+{
+	va_list ap;
+	char **argv;
+	int n;
+
+	va_start(ap, arg);
+	n = 1;
+	while (va_arg(ap, char *) != NULL)
+		n++;
+	va_end(ap);
+	argv = alloca((n + 1) * sizeof(*argv));
+	if (argv == NULL) {
+		errno = ENOMEM;
+		return (-1);
+	}
+	va_start(ap, arg);
+	n = 1;
+	argv[0] = (char *)arg;
+	while ((argv[n] = va_arg(ap, char *)) != NULL)
+		n++;
+	va_end(ap);
+	return (execve(name, argv, environ));
+}
+
+int
+execle(const char *name, const char *arg, ...)
+{
+	va_list ap;
+	char **argv, **envp;
+	int n;
+
+	va_start(ap, arg);
+	n = 1;
+	while (va_arg(ap, char *) != NULL)
+		n++;
+	va_end(ap);
+	argv = alloca((n + 1) * sizeof(*argv));
+	if (argv == NULL) {
+		errno = ENOMEM;
+		return (-1);
+	}
+	va_start(ap, arg);
+	n = 1;
+	argv[0] = (char *)arg;
+	while ((argv[n] = va_arg(ap, char *)) != NULL)
+		n++;
+	envp = va_arg(ap, char **);
+	va_end(ap);
+	return (execve(name, argv, envp));
+}
+
+int
+execlp(const char *name, const char *arg, ...)
+{
+	va_list ap;
+	char **argv;
+	int n;
+
+	va_start(ap, arg);
+	n = 1;
+	while (va_arg(ap, char *) != NULL)
+		n++;
+	va_end(ap);
+	argv = alloca((n + 1) * sizeof(*argv));
+	if (argv == NULL) {
+		errno = ENOMEM;
+		return (-1);
+	}
+	va_start(ap, arg);
+	n = 1;
+	argv[0] = (char *)arg;
+	while ((argv[n] = va_arg(ap, char *)) != NULL)
+		n++;
+	va_end(ap);
+	return (execvp(name, argv));
+}
+
+int
+execv(const char *name, char *const *argv)
+{
+	(void)execve(name, argv, environ);
+	return (-1);
+}
+
+int
+execvpe(const char *name, char *const *argv, char *const *envp)
+{
+	char **memp;
+	int cnt;
+	size_t lp, ln, len;
+	char *p;
+	int eacces = 0;
+	char *bp, *cur, *path, buf[PATH_MAX];
+
+	/*
+	 * Do not allow null name
+	 */
+	if (name == NULL || *name == '\0') {
+		errno = ENOENT;
+		return (-1);
+ 	}
+
+	/* If it's an absolute or relative path name, it's easy. */
+	if (strchr(name, '/')) {
+		bp = (char *)name;
+		cur = path = NULL;
+		goto retry;
+	}
+	bp = buf;
+
+	/* Get the path we're searching. */
+	if (!(path = getenv("PATH")))
+		path = _PATH_DEFPATH;
+	len = strlen(path) + 1;
+	cur = alloca(len);
+	if (cur == NULL) {
+		errno = ENOMEM;
+		return (-1);
+	}
+	strlcpy(cur, path, len);
+	path = cur;
+	while ((p = strsep(&cur, ":"))) {
+		/*
+		 * It's a SHELL path -- double, leading and trailing colons
+		 * mean the current directory.
+		 */
+		if (!*p) {
+			p = ".";
+			lp = 1;
+		} else
+			lp = strlen(p);
+		ln = strlen(name);
+
+		/*
+		 * If the path is too long complain.  This is a possible
+		 * security issue; given a way to make the path too long
+		 * the user may execute the wrong program.
+		 */
+		if (lp + ln + 2 > sizeof(buf)) {
+			struct iovec iov[3];
+
+			iov[0].iov_base = "execvp: ";
+			iov[0].iov_len = 8;
+			iov[1].iov_base = p;
+			iov[1].iov_len = lp;
+			iov[2].iov_base = ": path too long\n";
+			iov[2].iov_len = 16;
+			(void)writev(STDERR_FILENO, iov, 3);
+			continue;
+		}
+		bcopy(p, buf, lp);
+		buf[lp] = '/';
+		bcopy(name, buf + lp + 1, ln);
+		buf[lp + ln + 1] = '\0';
+
+retry:		(void)execve(bp, argv, envp);
+		switch(errno) {
+		case E2BIG:
+			goto done;
+		case EISDIR:
+		case ELOOP:
+		case ENAMETOOLONG:
+		case ENOENT:
+			break;
+		case ENOEXEC:
+			for (cnt = 0; argv[cnt]; ++cnt)
+				;
+			memp = alloca((cnt + 2) * sizeof(char *));
+			if (memp == NULL)
+				goto done;
+			memp[0] = "sh";
+			memp[1] = bp;
+			bcopy(argv + 1, memp + 2, cnt * sizeof(char *));
+			(void)execve(_PATH_BSHELL, memp, envp);
+			goto done;
+		case ENOMEM:
+			goto done;
+		case ENOTDIR:
+			break;
+		case ETXTBSY:
+			/*
+			 * We used to retry here, but sh(1) doesn't.
+			 */
+			goto done;
+		case EACCES:
+			eacces = 1;
+			break;
+		default:
+			goto done;
+		}
+	}
+	if (eacces)
+		errno = EACCES;
+	else if (!errno)
+		errno = ENOENT;
+done:
+	return (-1);
+}
+
+int
+execvp(const char *name, char *const *argv)
+{
+    return execvpe(name, argv, environ);
+}
+
diff --git a/libc/upstream-openbsd/lib/libc/gen/fnmatch.c b/libc/upstream-openbsd/lib/libc/gen/fnmatch.c
new file mode 100644
index 0000000..2c860f7
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/fnmatch.c
@@ -0,0 +1,487 @@
+/*	$OpenBSD: fnmatch.c,v 1.17 2013/11/24 23:51:29 deraadt Exp $	*/
+
+/* Copyright (c) 2011, VMware, Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the VMware, Inc. nor the names of its contributors
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 2008 Todd C. Miller <millert@openbsd.org>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+/* Authored by William A. Rowe Jr. <wrowe; apache.org, vmware.com>, April 2011
+ *
+ * Derived from The Open Group Base Specifications Issue 7, IEEE Std 1003.1-2008
+ * as described in;
+ *   http://pubs.opengroup.org/onlinepubs/9699919799/functions/fnmatch.html
+ *
+ * Filename pattern matches defined in section 2.13, "Pattern Matching Notation"
+ * from chapter 2. "Shell Command Language"
+ *   http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13
+ * where; 1. A bracket expression starting with an unquoted <circumflex> '^' 
+ * character CONTINUES to specify a non-matching list; 2. an explicit <period> '.' 
+ * in a bracket expression matching list, e.g. "[.abc]" does NOT match a leading 
+ * <period> in a filename; 3. a <left-square-bracket> '[' which does not introduce
+ * a valid bracket expression is treated as an ordinary character; 4. a differing
+ * number of consecutive slashes within pattern and string will NOT match;
+ * 5. a trailing '\' in FNM_ESCAPE mode is treated as an ordinary '\' character.
+ *
+ * Bracket expansion defined in section 9.3.5, "RE Bracket Expression",
+ * from chapter 9, "Regular Expressions"
+ *   http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_05
+ * with no support for collating symbols, equivalence class expressions or 
+ * character class expressions.  A partial range expression with a leading 
+ * hyphen following a valid range expression will match only the ordinary
+ * <hyphen> and the ending character (e.g. "[a-m-z]" will match characters 
+ * 'a' through 'm', a <hyphen> '-', or a 'z').
+ *
+ * Supports BSD extensions FNM_LEADING_DIR to match pattern to the end of one
+ * path segment of string, and FNM_CASEFOLD to ignore alpha case.
+ *
+ * NOTE: Only POSIX/C single byte locales are correctly supported at this time.
+ * Notably, non-POSIX locales with FNM_CASEFOLD produce undefined results,
+ * particularly in ranges of mixed case (e.g. "[A-z]") or spanning alpha and
+ * nonalpha characters within a range.
+ *
+ * XXX comments below indicate porting required for multi-byte character sets
+ * and non-POSIX locale collation orders; requires mbr* APIs to track shift
+ * state of pattern and string (rewinding pattern and string repeatedly).
+ *
+ * Certain parts of the code assume 0x00-0x3F are unique with any MBCS (e.g.
+ * UTF-8, SHIFT-JIS, etc).  Any implementation allowing '\' as an alternate
+ * path delimiter must be aware that 0x5C is NOT unique within SHIFT-JIS.
+ */
+
+#include <fnmatch.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+
+#include "charclass.h"
+
+#define	RANGE_MATCH	1
+#define	RANGE_NOMATCH	0
+#define	RANGE_ERROR	(-1)
+
+static int
+classmatch(const char *pattern, char test, int foldcase, const char **ep)
+{
+	struct cclass *cc;
+	const char *colon;
+	size_t len;
+	int rval = RANGE_NOMATCH;
+	const char * const mismatch = pattern;
+
+	if (*pattern != '[' || pattern[1] != ':') {
+		*ep = mismatch;
+		return(RANGE_ERROR);
+	}
+
+	pattern += 2;
+
+	if ((colon = strchr(pattern, ':')) == NULL || colon[1] != ']') {
+		*ep = mismatch;
+		return(RANGE_ERROR);
+	}
+	*ep = colon + 2;
+	len = (size_t)(colon - pattern);
+
+	if (foldcase && strncmp(pattern, "upper:]", 7) == 0)
+		pattern = "lower:]";
+	for (cc = cclasses; cc->name != NULL; cc++) {
+		if (!strncmp(pattern, cc->name, len) && cc->name[len] == '\0') {
+			if (cc->isctype((unsigned char)test))
+				rval = RANGE_MATCH;
+			break;
+		}
+	}
+	if (cc->name == NULL) {
+		/* invalid character class, treat as normal text */
+		*ep = mismatch;
+		rval = RANGE_ERROR;
+	}
+	return(rval);
+}
+
+/* Most MBCS/collation/case issues handled here.  Wildcard '*' is not handled.
+ * EOS '\0' and the FNM_PATHNAME '/' delimiters are not advanced over, 
+ * however the "\/" sequence is advanced to '/'.
+ *
+ * Both pattern and string are **char to support pointer increment of arbitrary
+ * multibyte characters for the given locale, in a later iteration of this code
+ */
+static int fnmatch_ch(const char **pattern, const char **string, int flags)
+{
+    const char * const mismatch = *pattern;
+    const int nocase = !!(flags & FNM_CASEFOLD);
+    const int escape = !(flags & FNM_NOESCAPE);
+    const int slash = !!(flags & FNM_PATHNAME);
+    int result = FNM_NOMATCH;
+    const char *startch;
+    int negate;
+
+    if (**pattern == '[')
+    {
+        ++*pattern;
+
+        /* Handle negation, either leading ! or ^ operators (never both) */
+        negate = ((**pattern == '!') || (**pattern == '^'));
+        if (negate)
+            ++*pattern;
+
+        /* ']' is an ordinary character at the start of the range pattern */
+        if (**pattern == ']')
+            goto leadingclosebrace;
+
+        while (**pattern)
+        {
+            if (**pattern == ']') {
+                ++*pattern;
+                /* XXX: Fix for MBCS character width */
+                ++*string;
+                return (result ^ negate);
+            }
+
+            if (escape && (**pattern == '\\')) {
+                ++*pattern;
+
+                /* Patterns must be terminated with ']', not EOS */
+                if (!**pattern)
+                    break;
+            }
+
+            /* Patterns must be terminated with ']' not '/' */
+            if (slash && (**pattern == '/'))
+                break;
+
+            /* Match character classes. */
+            if (classmatch(*pattern, **string, nocase, pattern)
+                == RANGE_MATCH) {
+                result = 0;
+                continue;
+            }
+
+leadingclosebrace:
+            /* Look at only well-formed range patterns; 
+             * "x-]" is not allowed unless escaped ("x-\]")
+             * XXX: Fix for locale/MBCS character width
+             */
+            if (((*pattern)[1] == '-') && ((*pattern)[2] != ']'))
+            {
+                startch = *pattern;
+                *pattern += (escape && ((*pattern)[2] == '\\')) ? 3 : 2;
+
+                /* NOT a properly balanced [expr] pattern, EOS terminated 
+                 * or ranges containing a slash in FNM_PATHNAME mode pattern
+                 * fall out to to the rewind and test '[' literal code path
+                 */
+                if (!**pattern || (slash && (**pattern == '/')))
+                    break;
+
+                /* XXX: handle locale/MBCS comparison, advance by MBCS char width */
+                if ((**string >= *startch) && (**string <= **pattern))
+                    result = 0;
+                else if (nocase && (isupper((unsigned char)**string) ||
+			    isupper((unsigned char)*startch) ||
+                            isupper((unsigned char)**pattern))
+                            && (tolower((unsigned char)**string) >=
+			        tolower((unsigned char)*startch)) 
+                            && (tolower((unsigned char)**string) <=
+				tolower((unsigned char)**pattern)))
+                    result = 0;
+
+                ++*pattern;
+                continue;
+            }
+
+            /* XXX: handle locale/MBCS comparison, advance by MBCS char width */
+            if ((**string == **pattern))
+                result = 0;
+            else if (nocase && (isupper((unsigned char)**string) ||
+			    isupper((unsigned char)**pattern))
+                            && (tolower((unsigned char)**string) ==
+				tolower((unsigned char)**pattern)))
+                result = 0;
+
+            ++*pattern;
+        }
+
+        /* NOT a properly balanced [expr] pattern; Rewind
+         * and reset result to test '[' literal
+         */
+        *pattern = mismatch;
+        result = FNM_NOMATCH;
+    }
+    else if (**pattern == '?') {
+        /* Optimize '?' match before unescaping **pattern */
+        if (!**string || (slash && (**string == '/')))
+            return FNM_NOMATCH;
+        result = 0;
+        goto fnmatch_ch_success;
+    }
+    else if (escape && (**pattern == '\\') && (*pattern)[1]) {
+        ++*pattern;
+    }
+
+    /* XXX: handle locale/MBCS comparison, advance by the MBCS char width */
+    if (**string == **pattern)
+        result = 0;
+    else if (nocase && (isupper((unsigned char)**string) ||
+		    isupper((unsigned char)**pattern))
+                    && (tolower((unsigned char)**string) ==
+			tolower((unsigned char)**pattern)))
+        result = 0;
+
+    /* Refuse to advance over trailing slash or nulls
+     */
+    if (!**string || !**pattern || (slash && ((**string == '/') || (**pattern == '/'))))
+        return result;
+
+fnmatch_ch_success:
+    ++*pattern;
+    ++*string;
+    return result;
+}
+
+
+int fnmatch(const char *pattern, const char *string, int flags)
+{
+    static const char dummystring[2] = {' ', 0};
+    const int escape = !(flags & FNM_NOESCAPE);
+    const int slash = !!(flags & FNM_PATHNAME);
+    const int leading_dir = !!(flags & FNM_LEADING_DIR);
+    const char *strendseg;
+    const char *dummyptr;
+    const char *matchptr;
+    int wild;
+    /* For '*' wild processing only; surpress 'used before initialization'
+     * warnings with dummy initialization values;
+     */
+    const char *strstartseg = NULL;
+    const char *mismatch = NULL;
+    int matchlen = 0;
+
+    if (strnlen(pattern, PATH_MAX) == PATH_MAX ||
+        strnlen(string, PATH_MAX) == PATH_MAX)
+            return (FNM_NOMATCH);
+
+    if (*pattern == '*')
+        goto firstsegment;
+
+    while (*pattern && *string)
+    {
+        /* Pre-decode "\/" which has no special significance, and
+         * match balanced slashes, starting a new segment pattern
+         */
+        if (slash && escape && (*pattern == '\\') && (pattern[1] == '/'))
+            ++pattern;
+        if (slash && (*pattern == '/') && (*string == '/')) {
+            ++pattern;
+            ++string;
+        }            
+
+firstsegment:
+        /* At the beginning of each segment, validate leading period behavior.
+         */
+        if ((flags & FNM_PERIOD) && (*string == '.'))
+        {
+            if (*pattern == '.')
+                ++pattern;
+            else if (escape && (*pattern == '\\') && (pattern[1] == '.'))
+                pattern += 2;
+            else
+                return FNM_NOMATCH;
+            ++string;
+        }
+
+        /* Determine the end of string segment
+         *
+         * Presumes '/' character is unique, not composite in any MBCS encoding
+         */
+        if (slash) {
+            strendseg = strchr(string, '/');
+            if (!strendseg)
+                strendseg = strchr(string, '\0');
+        }
+        else {
+            strendseg = strchr(string, '\0');
+        }
+
+        /* Allow pattern '*' to be consumed even with no remaining string to match
+         */
+        while (*pattern)
+        {
+            if ((string > strendseg)
+                || ((string == strendseg) && (*pattern != '*')))
+                break;
+
+            if (slash && ((*pattern == '/')
+                           || (escape && (*pattern == '\\')
+                                      && (pattern[1] == '/'))))
+                break;
+
+            /* Reduce groups of '*' and '?' to n '?' matches
+             * followed by one '*' test for simplicity
+             */
+            for (wild = 0; ((*pattern == '*') || (*pattern == '?')); ++pattern)
+            {
+                if (*pattern == '*') {
+                    wild = 1;
+                }
+                else if (string < strendseg) {  /* && (*pattern == '?') */
+                    /* XXX: Advance 1 char for MBCS locale */
+                    ++string;
+                }
+                else {  /* (string >= strendseg) && (*pattern == '?') */
+                    return FNM_NOMATCH;
+                }
+            }
+
+            if (wild)
+            {
+                strstartseg = string;
+                mismatch = pattern;
+
+                /* Count fixed (non '*') char matches remaining in pattern
+                 * excluding '/' (or "\/") and '*'
+                 */
+                for (matchptr = pattern, matchlen = 0; 1; ++matchlen)
+                {
+                    if ((*matchptr == '\0') 
+                        || (slash && ((*matchptr == '/')
+                                      || (escape && (*matchptr == '\\')
+                                                 && (matchptr[1] == '/')))))
+                    {
+                        /* Compare precisely this many trailing string chars,
+                         * the resulting match needs no wildcard loop
+                         */
+                        /* XXX: Adjust for MBCS */
+                        if (string + matchlen > strendseg)
+                            return FNM_NOMATCH;
+
+                        string = strendseg - matchlen;
+                        wild = 0;
+                        break;
+                    }
+
+                    if (*matchptr == '*')
+                    {
+                        /* Ensure at least this many trailing string chars remain
+                         * for the first comparison
+                         */
+                        /* XXX: Adjust for MBCS */
+                        if (string + matchlen > strendseg)
+                            return FNM_NOMATCH;
+
+                        /* Begin first wild comparison at the current position */
+                        break;
+                    }
+
+                    /* Skip forward in pattern by a single character match
+                     * Use a dummy fnmatch_ch() test to count one "[range]" escape
+                     */ 
+                    /* XXX: Adjust for MBCS */
+                    if (escape && (*matchptr == '\\') && matchptr[1]) {
+                        matchptr += 2;
+                    }
+                    else if (*matchptr == '[') {
+                        dummyptr = dummystring;
+                        fnmatch_ch(&matchptr, &dummyptr, flags);
+                    }
+                    else {
+                        ++matchptr;
+                    }
+                }
+            }
+
+            /* Incrementally match string against the pattern
+             */
+            while (*pattern && (string < strendseg))
+            {
+                /* Success; begin a new wild pattern search
+                 */
+                if (*pattern == '*')
+                    break;
+
+                if (slash && ((*string == '/')
+                              || (*pattern == '/')
+                              || (escape && (*pattern == '\\')
+                                         && (pattern[1] == '/'))))
+                    break;
+
+                /* Compare ch's (the pattern is advanced over "\/" to the '/',
+                 * but slashes will mismatch, and are not consumed)
+                 */
+                if (!fnmatch_ch(&pattern, &string, flags))
+                    continue;
+
+                /* Failed to match, loop against next char offset of string segment 
+                 * until not enough string chars remain to match the fixed pattern
+                 */
+                if (wild) {
+                    /* XXX: Advance 1 char for MBCS locale */
+                    string = ++strstartseg;
+                    if (string + matchlen > strendseg)
+                        return FNM_NOMATCH;
+
+                    pattern = mismatch;
+                    continue;
+                }
+                else
+                    return FNM_NOMATCH;
+            }
+        }
+
+        if (*string && !((slash || leading_dir) && (*string == '/')))
+            return FNM_NOMATCH;
+
+        if (*pattern && !(slash && ((*pattern == '/')
+                                    || (escape && (*pattern == '\\')
+                                               && (pattern[1] == '/')))))
+            return FNM_NOMATCH;
+
+        if (leading_dir && !*pattern && *string == '/')
+            return 0;
+    }
+
+    /* Where both pattern and string are at EOS, declare success
+     */
+    if (!*string && !*pattern)
+        return 0;
+
+    /* pattern didn't match to the end of string */
+    return FNM_NOMATCH;
+}
diff --git a/libc/upstream-openbsd/lib/libc/gen/ftok.c b/libc/upstream-openbsd/lib/libc/gen/ftok.c
new file mode 100644
index 0000000..f9d6621
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/ftok.c
@@ -0,0 +1,43 @@
+/*	$OpenBSD: ftok.c,v 1.7 2005/08/08 08:05:34 espie Exp $ */
+/*
+ * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ipc.h>
+
+key_t
+ftok(const char *path, int id)
+{
+	struct stat st;
+
+	if (stat(path, &st) < 0)
+		return (key_t)-1;
+
+	return (key_t)
+	    ((id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff));
+}
diff --git a/libc/upstream-openbsd/lib/libc/gen/getprogname.c b/libc/upstream-openbsd/lib/libc/gen/getprogname.c
new file mode 100644
index 0000000..17046ab
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/getprogname.c
@@ -0,0 +1,26 @@
+/* $OpenBSD: getprogname.c,v 1.3 2013/11/12 06:09:48 deraadt Exp $ */
+/*
+ * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+#include <stdlib.h>
+
+extern const char *__progname;
+
+const char *
+getprogname(void)
+{
+	return (__progname);
+}
diff --git a/libc/upstream-openbsd/lib/libc/gen/isctype.c b/libc/upstream-openbsd/lib/libc/gen/isctype.c
new file mode 100644
index 0000000..970b5e2
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/isctype.c
@@ -0,0 +1,150 @@
+/*	$OpenBSD: isctype.c,v 1.11 2005/08/08 08:05:34 espie Exp $ */
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#define _ANSI_LIBRARY
+#include <ctype.h>
+#include <stdio.h>
+
+#undef isalnum
+int
+isalnum(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N)));
+}
+
+#undef isalpha
+int
+isalpha(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L)));
+}
+
+#undef isblank
+int
+isblank(int c)
+{
+	return (c == ' ' || c == '\t');
+}
+
+#undef iscntrl
+int
+iscntrl(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _C));
+}
+
+#undef isdigit
+int
+isdigit(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
+}
+
+#undef isgraph
+int
+isgraph(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N)));
+}
+
+#undef islower
+int
+islower(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _L));
+}
+
+#undef isprint
+int
+isprint(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B)));
+}
+
+#undef ispunct
+int
+ispunct(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P));
+}
+
+#undef isspace
+int
+isspace(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
+}
+
+#undef isupper
+int
+isupper(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _U));
+}
+
+#undef isxdigit
+int
+isxdigit(int c)
+{
+	return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_N|_X)));
+}
+
+#undef isascii
+int
+isascii(int c)
+{
+	return ((unsigned int)c <= 0177);
+}
+
+#undef toascii
+int
+toascii(int c)
+{
+	return (c & 0177);
+}
+
+#undef _toupper
+int
+_toupper(int c)
+{
+	return (c - 'a' + 'A');
+}
+
+#undef _tolower
+int
+_tolower(int c)
+{
+	return (c - 'A' + 'a');
+}
diff --git a/libc/upstream-openbsd/lib/libc/gen/setprogname.c b/libc/upstream-openbsd/lib/libc/gen/setprogname.c
new file mode 100644
index 0000000..089a15a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/setprogname.c
@@ -0,0 +1,33 @@
+/* $OpenBSD: setprogname.c,v 1.4 2013/11/12 06:09:48 deraadt Exp $ */
+/*
+ * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+extern const char *__progname;
+
+void
+setprogname(const char *progname)
+{
+	const char *tmpn;
+
+	tmpn = strrchr(progname, '/');
+	if (tmpn == NULL)
+		__progname = progname;
+	else
+		__progname = tmpn + 1;
+}
diff --git a/libc/upstream-openbsd/lib/libc/gen/time.c b/libc/upstream-openbsd/lib/libc/gen/time.c
new file mode 100644
index 0000000..3a57500
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/time.c
@@ -0,0 +1,44 @@
+/*	$OpenBSD: time.c,v 1.5 2005/08/08 08:05:34 espie Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+time_t
+time(time_t *t)
+{
+	struct timeval tt;
+
+	if (gettimeofday(&tt, (struct timezone *)0) < 0)
+		return (-1);
+	if (t)
+		*t = (time_t)tt.tv_sec;
+	return (tt.tv_sec);
+}
diff --git a/libc/stdlib/tolower_.c b/libc/upstream-openbsd/lib/libc/gen/tolower_.c
similarity index 100%
rename from libc/stdlib/tolower_.c
rename to libc/upstream-openbsd/lib/libc/gen/tolower_.c
diff --git a/libc/stdlib/toupper_.c b/libc/upstream-openbsd/lib/libc/gen/toupper_.c
similarity index 100%
rename from libc/stdlib/toupper_.c
rename to libc/upstream-openbsd/lib/libc/gen/toupper_.c
diff --git a/libc/stdlib/ctype_private.h b/libc/upstream-openbsd/lib/libc/include/ctype_private.h
similarity index 100%
rename from libc/stdlib/ctype_private.h
rename to libc/upstream-openbsd/lib/libc/include/ctype_private.h
diff --git a/libc/upstream-openbsd/lib/libc/include/langinfo.h b/libc/upstream-openbsd/lib/libc/include/langinfo.h
new file mode 100644
index 0000000..a871ab8
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/include/langinfo.h
@@ -0,0 +1,3 @@
+/* Hack to build "vfprintf.c". */
+#define RADIXCHAR 1
+#define nl_langinfo(i) ((i == RADIXCHAR) ? (char*) "." : NULL)
diff --git a/libc/upstream-openbsd/lib/libc/locale/_wcstod.h b/libc/upstream-openbsd/lib/libc/locale/_wcstod.h
new file mode 100644
index 0000000..ae993ad
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/_wcstod.h
@@ -0,0 +1,153 @@
+/*	$OpenBSD: _wcstod.h,v 1.2 2013/06/02 15:22:20 matthew Exp $	*/
+/* $NetBSD: wcstod.c,v 1.4 2001/10/28 12:08:43 yamt Exp $ */
+
+/*-
+ * Copyright (c)1999, 2000, 2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	$Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstod.c,v 1.2 2001/09/27 16:23:57 yamt Exp $
+ */
+
+/*
+ * function template for wcstof, wcstod and wcstold.
+ *
+ * parameters:
+ *	FUNCNAME : function name
+ *      float_type : return type
+ *      STRTOD_FUNC : conversion function
+ */
+
+float_type
+FUNCNAME(const wchar_t *nptr, wchar_t **endptr)
+{
+	const wchar_t *src;
+	size_t size;
+	const wchar_t *start;
+	const wchar_t *aftersign;
+
+	/*
+	 * check length of string and call strtod
+	 */
+	src = nptr;
+
+	/* skip space first */
+	while (iswspace(*src)) {
+		src++;
+	}
+
+	/* get length of string */
+	start = src;
+	if (*src && wcschr(L"+-", *src))
+		src++;
+	aftersign = src;
+	if (wcsncasecmp(src, L"inf", 3) == 0) {
+		src += 3;
+		if (wcsncasecmp(src, L"inity", 5) == 0)
+			src += 5;
+		goto match;
+	}
+	if (wcsncasecmp(src, L"nan", 3) == 0) {
+		src += 3;
+		if (*src == L'(') {
+			size = 1;
+			while (src[size] != L'\0' && src[size] != L')')
+				size++;
+			if (src[size] == L')')
+				src += size + 1;
+		}
+		goto match;
+	}
+	size = wcsspn(src, L"0123456789");
+	src += size;
+	if (*src == L'.') {/* XXX use localeconv */
+		src++;
+		size = wcsspn(src, L"0123456789");
+		src += size;
+	}
+	if (*src && wcschr(L"Ee", *src)) {
+		src++;
+		if (*src && wcschr(L"+-", *src))
+			src++;
+		size = wcsspn(src, L"0123456789");
+		src += size;
+	}
+match:
+	size = src - start;
+
+	/*
+	 * convert to a char-string and pass it to strtod.
+	 */
+	if (src > aftersign) {
+		mbstate_t st;
+		char *buf;
+		char *end;
+		const wchar_t *s;
+		size_t size_converted;
+		float_type result;
+		size_t bufsize;
+
+		s = start;
+		memset(&st, 0, sizeof(st));
+		bufsize = wcsnrtombs(NULL, &s, size, 0, &st);
+
+		buf = malloc(bufsize + 1);
+		if (!buf) {
+			errno = ENOMEM; /* XXX */
+			goto fail;
+		}
+
+		s = start;
+		memset(&st, 0, sizeof(st));
+		size_converted = wcsnrtombs(buf, &s, size, bufsize, &st);
+		if (size_converted != bufsize) {
+			/* XXX should not happen */
+			free(buf);
+			errno = EILSEQ;
+			goto fail;
+		}
+
+		buf[bufsize] = 0;
+		result = STRTOD_FUNC(buf, &end);
+
+		if (endptr) {
+			const char *s = buf;
+			memset(&st, 0, sizeof(st));
+			size = mbsnrtowcs(NULL, &s, end - buf, 0, &st);
+
+			/* LINTED bad interface */
+			*endptr = (wchar_t*)start + size;
+		}
+
+		free(buf);
+
+		return result;
+	}
+
+fail:
+	if (endptr)
+		/* LINTED bad interface */
+		*endptr = (wchar_t*)nptr;
+
+	return 0;
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/_wcstol.h b/libc/upstream-openbsd/lib/libc/locale/_wcstol.h
new file mode 100644
index 0000000..7b49bbf
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/_wcstol.h
@@ -0,0 +1,136 @@
+/*	$OpenBSD: _wcstol.h,v 1.1 2005/07/01 08:59:27 espie Exp $	*/
+/* $NetBSD: _wcstol.h,v 1.2 2003/08/07 16:43:03 agc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * @(#)strtol.c	8.1 (Berkeley) 6/4/93
+ * NetBSD: wcstol.c,v 1.1 2001/09/27 16:30:36 yamt Exp
+ * Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstol.c,v 1.2 2001/09/21 16:11:41 yamt Exp
+ */
+
+/*
+ * function template for wcstol, wcstoll and wcstoimax.
+ *
+ * parameters:
+ *	FUNCNAME : function name
+ *      int_type : return type
+ *      MIN_VALUE : lower limit of the return type
+ *      MAX_VALUE : upper limit of the return type
+ */
+
+int_type
+FUNCNAME(const wchar_t *nptr, wchar_t **endptr, int base)
+{
+	const wchar_t *s;
+	int_type acc, cutoff;
+	wint_t wc;
+	int i;
+	int neg, any, cutlim;
+
+	/* check base value */
+	if (base && (base < 2 || base > 36)) {
+		errno = EINVAL;
+		return 0;
+	}
+
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	s = nptr;
+	do {
+		wc = (wchar_t) *s++;
+	} while (iswspace(wc));
+	if (wc == L'-') {
+		neg = 1;
+		wc = *s++;
+	} else {
+		neg = 0;
+		if (wc == L'+')
+			wc = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    wc == L'0' && (*s == L'x' || *s == L'X')) {
+		wc = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = wc == L'0' ? 8 : 10;
+
+	/*
+	 * See strtol for comments as to the logic used.
+	 */
+	cutoff = neg ? MIN_VALUE : MAX_VALUE;
+	cutlim = (int)(cutoff % base);
+	cutoff /= base;
+	if (neg) {
+		if (cutlim > 0) {
+			cutlim -= base;
+			cutoff += 1;
+		}
+		cutlim = -cutlim;
+	}
+	for (acc = 0, any = 0;; wc = (wchar_t) *s++) {
+		i = wctoint(wc);
+		if (i == -1)
+			break;
+		if (i >= base)
+			break;
+		if (any < 0)
+			continue;
+		if (neg) {
+			if (acc < cutoff || (acc == cutoff && i > cutlim)) {
+				any = -1;
+				acc = MIN_VALUE;
+				errno = ERANGE;
+			} else {
+				any = 1;
+				acc *= base;
+				acc -= i;
+			}
+		} else {
+			if (acc > cutoff || (acc == cutoff && i > cutlim)) {
+				any = -1;
+				acc = MAX_VALUE;
+				errno = ERANGE;
+			} else {
+				any = 1;
+				acc *= base;
+				acc += i;
+			}
+		}
+	}
+	if (endptr != 0)
+		/* LINTED interface specification */
+		*endptr = (wchar_t *)(any ? s - 1 : nptr);
+	return (acc);
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/_wcstoul.h b/libc/upstream-openbsd/lib/libc/locale/_wcstoul.h
new file mode 100644
index 0000000..736b38f
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/_wcstoul.h
@@ -0,0 +1,116 @@
+/*	$OpenBSD: _wcstoul.h,v 1.1 2005/07/01 08:59:27 espie Exp $	*/
+/* $NetBSD: _wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp $ */
+
+/*
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * @(#)strtoul.c	8.1 (Berkeley) 6/4/93
+ * Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstoul.c,v 1.2 2001/09/21 16:11:41 yamt Exp
+ * NetBSD: wcstoul.c,v 1.1 2001/09/27 16:30:37 yamt Exp
+ */
+
+/*
+ * function template for wcstoul, wcstoull and wcstoumax.
+ *
+ * parameters:
+ *	FUNCNAME  : function name
+ *      uint_type : return type
+ *      MAX_VALUE : upper limit of the return type
+ */
+
+uint_type
+FUNCNAME(const wchar_t *nptr, wchar_t **endptr, int base)
+{
+	const wchar_t *s;
+	uint_type acc, cutoff;
+	wint_t wc;
+	int i;
+	int neg, any, cutlim;
+
+	if (base && (base < 2 || base > 36)) {
+		errno = EINVAL;
+		return 0;
+	}
+
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	s = nptr;
+	do {
+		wc = (wchar_t) *s++;
+	} while (iswspace(wc));
+	if (wc == L'-') {
+		neg = 1;
+		wc = *s++;
+	} else {
+		neg = 0;
+		if (wc == L'+')
+			wc = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    wc == L'0' && (*s == L'x' || *s == L'X')) {
+		wc = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = wc == L'0' ? 8 : 10;
+
+	/*
+	 * See strtoul for comments as to the logic used.
+	 */
+	cutoff = MAX_VALUE / (uint_type)base;
+	cutlim = (int)(MAX_VALUE % (uint_type)base);
+	for (acc = 0, any = 0;; wc = (wchar_t) *s++) {
+		i = wctoint(wc);
+		if (i == (wint_t)-1)
+			break;
+		if (i >= base)
+			break;
+		if (any < 0)
+			continue;
+		if (acc > cutoff || (acc == cutoff && i > cutlim)) {
+			any = -1;
+			acc = MAX_VALUE;
+			errno = ERANGE;
+		} else {
+			any = 1;
+			acc *= (uint_type)base;
+			acc += i;
+		}
+	}
+	if (neg && any > 0)
+		acc = -acc;
+	if (endptr != 0)
+		/* LINTED interface specification */
+		*endptr = (wchar_t *)(any ? s - 1 : nptr);
+	return (acc);
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/btowc.c b/libc/upstream-openbsd/lib/libc/locale/btowc.c
new file mode 100644
index 0000000..9627340
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/btowc.c
@@ -0,0 +1,52 @@
+/*	$OpenBSD: btowc.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002, 2003 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+
+wint_t
+btowc(int c)
+{
+	mbstate_t mbs;
+	char cc;
+	wchar_t wc;
+
+	if (c == EOF)
+		return (WEOF);
+	/*
+	 * We expect mbrtowc() to return 0 or 1, hence the check for n > 1
+	 * which detects error return values as well as "impossible" byte
+	 * counts.
+	 */
+	memset(&mbs, 0, sizeof(mbs));
+	cc = (char)c;
+	if (mbrtowc(&wc, &cc, 1, &mbs) > 1)
+		return (WEOF);
+	return (wc);
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/mbrlen.c b/libc/upstream-openbsd/lib/libc/locale/mbrlen.c
new file mode 100644
index 0000000..0f05bd0
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/mbrlen.c
@@ -0,0 +1,39 @@
+/*	$OpenBSD: mbrlen.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <wchar.h>
+
+size_t
+mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps)
+{
+	static mbstate_t mbs;
+
+	if (ps == NULL)
+		ps = &mbs;
+	return (mbrtowc(NULL, s, n, ps));
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/mbstowcs.c b/libc/upstream-openbsd/lib/libc/locale/mbstowcs.c
new file mode 100644
index 0000000..c17a858
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/mbstowcs.c
@@ -0,0 +1,44 @@
+/*	$OpenBSD: mbstowcs.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+size_t
+mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n)
+{
+	mbstate_t mbs;
+	const char *sp;
+
+	memset(&mbs, 0, sizeof(mbs));
+	sp = s;
+	return (mbsrtowcs(pwcs, &sp, n, &mbs));
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/mbtowc.c b/libc/upstream-openbsd/lib/libc/locale/mbtowc.c
new file mode 100644
index 0000000..920f4bf
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/mbtowc.c
@@ -0,0 +1,50 @@
+/*	$OpenBSD: mbtowc.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <errno.h>
+
+int
+mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
+{
+	static mbstate_t mbs;
+	size_t rval;
+
+	if (s == NULL) {
+		/* No support for state dependent encodings. */
+		memset(&mbs, 0, sizeof(mbs));
+		return (0);
+	}
+	rval = mbrtowc(pwc, s, n, &mbs);
+	if (rval == (size_t)-1 || rval == (size_t)-2)
+		return (-1);
+	return ((int)rval);
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcscoll.c b/libc/upstream-openbsd/lib/libc/locale/wcscoll.c
new file mode 100644
index 0000000..8ec32ce
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcscoll.c
@@ -0,0 +1,41 @@
+/*	$OpenBSD: wcscoll.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+/*	$NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $	*/
+
+/*-
+ * Copyright (c)2003 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <wchar.h>
+
+/*
+ * Compare strings with using collating information.
+ */
+int
+wcscoll(const wchar_t *s1, const wchar_t *s2)
+{
+	/* XXX: LC_COLLATE should be implemented. */
+	return (wcscmp(s1, s2));
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstod.c b/libc/upstream-openbsd/lib/libc/locale/wcstod.c
new file mode 100644
index 0000000..957d0a1
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstod.c
@@ -0,0 +1,13 @@
+/*	$OpenBSD: wcstod.c,v 1.3 2009/01/13 18:18:31 kettenis Exp $	*/
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#define FUNCNAME	wcstod
+typedef double		float_type;
+#define STRTOD_FUNC	strtod
+
+#include "_wcstod.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstof.c b/libc/upstream-openbsd/lib/libc/locale/wcstof.c
new file mode 100644
index 0000000..40d76c7
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstof.c
@@ -0,0 +1,13 @@
+/*	$OpenBSD: wcstof.c,v 1.1 2009/01/13 18:18:31 kettenis Exp $	*/
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#define FUNCNAME	wcstof
+typedef float		float_type;
+#define STRTOD_FUNC	strtof
+
+#include "_wcstod.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstoimax.c b/libc/upstream-openbsd/lib/libc/locale/wcstoimax.c
new file mode 100644
index 0000000..d46a7c7
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstoimax.c
@@ -0,0 +1,19 @@
+/*	$OpenBSD: wcstoimax.c,v 1.1 2009/01/13 18:13:51 kettenis Exp $	*/
+/* $NetBSD: wcstol.c,v 1.2 2003/03/11 09:21:23 tshiozak Exp $ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "wctoint.h"
+
+#define	FUNCNAME	wcstoimax
+typedef intmax_t	int_type;
+#define	MIN_VALUE	INTMAX_MIN
+#define	MAX_VALUE	INTMAX_MAX
+
+#include "_wcstol.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstol.c b/libc/upstream-openbsd/lib/libc/locale/wcstol.c
new file mode 100644
index 0000000..03395a0
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstol.c
@@ -0,0 +1,18 @@
+/*	$OpenBSD: wcstol.c,v 1.2 2005/08/08 08:05:35 espie Exp $	*/
+/* $NetBSD: wcstol.c,v 1.2 2003/03/11 09:21:23 tshiozak Exp $ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "wctoint.h"
+
+#define	FUNCNAME	wcstol
+typedef long int_type;
+#define	MIN_VALUE	LONG_MIN
+#define	MAX_VALUE	LONG_MAX
+
+#include "_wcstol.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstold.c b/libc/upstream-openbsd/lib/libc/locale/wcstold.c
new file mode 100644
index 0000000..a642542
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstold.c
@@ -0,0 +1,13 @@
+/*	$OpenBSD: wcstold.c,v 1.1 2009/01/13 18:18:31 kettenis Exp $	*/
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#define FUNCNAME	wcstold
+typedef long double	float_type;
+#define STRTOD_FUNC	strtold
+
+#include "_wcstod.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstoll.c b/libc/upstream-openbsd/lib/libc/locale/wcstoll.c
new file mode 100644
index 0000000..926db70
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstoll.c
@@ -0,0 +1,18 @@
+/*	$OpenBSD: wcstoll.c,v 1.2 2005/08/08 08:05:35 espie Exp $	*/
+/* $NetBSD: wcstoll.c,v 1.1 2003/03/11 09:21:23 tshiozak Exp $ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "wctoint.h"
+
+#define	FUNCNAME	wcstoll
+typedef long long int int_type;
+#define	MIN_VALUE	LLONG_MIN
+#define	MAX_VALUE	LLONG_MAX
+
+#include "_wcstol.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstombs.c b/libc/upstream-openbsd/lib/libc/locale/wcstombs.c
new file mode 100644
index 0000000..e8054c4
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstombs.c
@@ -0,0 +1,43 @@
+/*	$OpenBSD: wcstombs.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+size_t
+wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n)
+{
+	mbstate_t mbs;
+	const wchar_t *pwcsp;
+
+	memset(&mbs, 0, sizeof(mbs));
+	pwcsp = pwcs;
+	return (wcsrtombs(s, &pwcsp, n, &mbs));
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstoul.c b/libc/upstream-openbsd/lib/libc/locale/wcstoul.c
new file mode 100644
index 0000000..e863862
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstoul.c
@@ -0,0 +1,17 @@
+/*	$OpenBSD: wcstoul.c,v 1.2 2005/08/08 08:05:35 espie Exp $	*/
+/*	$NetBSD: wcstoul.c,v 1.2 2003/03/11 09:21:24 tshiozak Exp $	*/
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "wctoint.h"
+
+#define	FUNCNAME	wcstoul
+typedef unsigned long uint_type;
+#define	MAX_VALUE	ULONG_MAX
+
+#include "_wcstoul.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstoull.c b/libc/upstream-openbsd/lib/libc/locale/wcstoull.c
new file mode 100644
index 0000000..6671c37
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstoull.c
@@ -0,0 +1,17 @@
+/*	$OpenBSD: wcstoull.c,v 1.2 2005/08/08 08:05:35 espie Exp $	*/
+/*	$NetBSD: wcstoull.c,v 1.1 2003/03/11 09:21:24 tshiozak Exp $	*/
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "wctoint.h"
+
+#define	FUNCNAME	wcstoull
+typedef unsigned long long int uint_type;
+#define	MAX_VALUE	ULLONG_MAX
+
+#include "_wcstoul.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcstoumax.c b/libc/upstream-openbsd/lib/libc/locale/wcstoumax.c
new file mode 100644
index 0000000..ccd4713
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcstoumax.c
@@ -0,0 +1,18 @@
+/*	$OpenBSD: wcstoumax.c,v 1.1 2009/01/13 18:13:51 kettenis Exp $	*/
+/*	$NetBSD: wcstoul.c,v 1.2 2003/03/11 09:21:24 tshiozak Exp $	*/
+
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "wctoint.h"
+
+#define	FUNCNAME	wcstoumax
+typedef uintmax_t	uint_type;
+#define	MAX_VALUE	UINTMAX_MAX
+
+#include "_wcstoul.h"
diff --git a/libc/upstream-openbsd/lib/libc/locale/wcsxfrm.c b/libc/upstream-openbsd/lib/libc/locale/wcsxfrm.c
new file mode 100644
index 0000000..98db4a9
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wcsxfrm.c
@@ -0,0 +1,42 @@
+/*	$OpenBSD: wcsxfrm.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+/*	$OpenBSD: wcsxfrm.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $	*/
+/*	$NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $	*/
+
+/*
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <wchar.h>
+
+size_t 
+wcsxfrm(wchar_t *dest, const wchar_t *src, size_t n)
+{
+	if (n == 0)
+		return wcslen(src);
+	return wcslcpy(dest, src, n);
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/wctob.c b/libc/upstream-openbsd/lib/libc/locale/wctob.c
new file mode 100644
index 0000000..ea1f40c
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wctob.c
@@ -0,0 +1,43 @@
+/*	$OpenBSD: wctob.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+
+int
+wctob(wint_t c)
+{
+	mbstate_t mbs;
+	char buf[MB_LEN_MAX];
+
+	memset(&mbs, 0, sizeof(mbs));
+	if (c == WEOF || wcrtomb(buf, c, &mbs) != 1)
+		return (EOF);
+	return ((unsigned char)*buf);
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/wctoint.h b/libc/upstream-openbsd/lib/libc/locale/wctoint.h
new file mode 100644
index 0000000..c9bf084
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wctoint.h
@@ -0,0 +1,79 @@
+/*	$OpenBSD: wctoint.h,v 1.1 2005/07/01 08:59:27 espie Exp $	*/
+/* $NetBSD: __wctoint.h,v 1.1 2001/09/28 11:25:37 yamt Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	$Citrus: xpg4dl/FreeBSD/lib/libc/locale/__wctoint.h,v 1.1 2001/09/21 13:52:32 yamt Exp $
+ */
+
+
+__inline static int
+wctoint(wchar_t wc)
+{
+	int n;
+
+	switch (wc) {
+	case L'0': n = 0; break;
+	case L'1': n = 1; break;
+	case L'2': n = 2; break;
+	case L'3': n = 3; break;
+	case L'4': n = 4; break;
+	case L'5': n = 5; break;
+	case L'6': n = 6; break;
+	case L'7': n = 7; break;
+	case L'8': n = 8; break;
+	case L'9': n = 9; break;
+	case L'A': case L'a': n = 10; break;
+	case L'B': case L'b': n = 11; break;
+	case L'C': case L'c': n = 12; break;
+	case L'D': case L'd': n = 13; break;
+	case L'E': case L'e': n = 14; break;
+	case L'F': case L'f': n = 15; break;
+	case L'G': case L'g': n = 16; break;
+	case L'H': case L'h': n = 17; break;
+	case L'I': case L'i': n = 18; break;
+	case L'J': case L'j': n = 19; break;
+	case L'K': case L'k': n = 20; break;
+	case L'L': case L'l': n = 21; break;
+	case L'M': case L'm': n = 22; break;
+	case L'N': case L'n': n = 23; break;
+	case L'O': case L'o': n = 24; break;
+	case L'P': case L'p': n = 25; break;
+	case L'Q': case L'q': n = 26; break;
+	case L'R': case L'r': n = 27; break;
+	case L'S': case L's': n = 28; break;
+	case L'T': case L't': n = 29; break;
+	case L'U': case L'u': n = 30; break;
+	case L'V': case L'v': n = 31; break;
+	case L'W': case L'w': n = 32; break;
+	case L'X': case L'x': n = 33; break;
+	case L'Y': case L'y': n = 34; break;
+	case L'Z': case L'z': n = 35; break;
+	default: n = -1; break; /* error */
+	}
+
+	return n;
+}
diff --git a/libc/upstream-openbsd/lib/libc/locale/wctomb.c b/libc/upstream-openbsd/lib/libc/locale/wctomb.c
new file mode 100644
index 0000000..39f7a7c
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/locale/wctomb.c
@@ -0,0 +1,47 @@
+/*	$OpenBSD: wctomb.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+int
+wctomb(char *s, wchar_t wchar)
+{
+	static mbstate_t mbs;
+	size_t rval;
+
+	if (s == NULL) {
+		/* No support for state dependent encodings. */
+		memset(&mbs, 0, sizeof(mbs));
+		return (0);
+	}
+	if ((rval = wcrtomb(s, wchar, &mbs)) == (size_t)-1)
+		return (-1);
+	return ((int)rval);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/htonl.c b/libc/upstream-openbsd/lib/libc/net/htonl.c
new file mode 100644
index 0000000..5ab4189
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/htonl.c
@@ -0,0 +1,21 @@
+/*	$OpenBSD: htonl.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <sys/types.h>
+#include <machine/endian.h>
+
+#undef htonl
+
+u_int32_t
+htonl(u_int32_t x)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+	u_char *s = (u_char *)&x;
+	return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
+#else
+	return x;
+#endif
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/htons.c b/libc/upstream-openbsd/lib/libc/net/htons.c
new file mode 100644
index 0000000..c8b73fd
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/htons.c
@@ -0,0 +1,21 @@
+/*	$OpenBSD: htons.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <sys/types.h>
+#include <machine/endian.h>
+
+#undef htons
+
+u_int16_t
+htons(u_int16_t x)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+	u_char *s = (u_char *) &x;
+	return (u_int16_t)(s[0] << 8 | s[1]);
+#else
+	return x;
+#endif
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_addr.c b/libc/upstream-openbsd/lib/libc/net/inet_addr.c
new file mode 100644
index 0000000..18762ab
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/inet_addr.c
@@ -0,0 +1,175 @@
+/*	$OpenBSD: inet_addr.c,v 1.10 2013/11/24 23:51:28 deraadt Exp $	*/
+
+/*
+ * ++Copyright++ 1983, 1990, 1993
+ * -
+ * Copyright (c) 1983, 1990, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ * -
+ * --Copyright--
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <ctype.h>
+
+/*
+ * Ascii internet address interpretation routine.
+ * The value returned is in network order.
+ */
+in_addr_t
+inet_addr(const char *cp)
+{
+	struct in_addr val;
+
+	if (inet_aton(cp, &val))
+		return (val.s_addr);
+	return (INADDR_NONE);
+}
+
+/* 
+ * Check whether "cp" is a valid ascii representation
+ * of an Internet address and convert to a binary address.
+ * Returns 1 if the address is valid, 0 if not.
+ * This replaces inet_addr, the return value from which
+ * cannot distinguish between failure and a local broadcast address.
+ */
+int
+inet_aton(const char *cp, struct in_addr *addr)
+{
+	in_addr_t val;
+	int base, n;
+	char c;
+	u_int parts[4];
+	u_int *pp = parts;
+
+	c = *cp;
+	for (;;) {
+		/*
+		 * Collect number up to ``.''.
+		 * Values are specified as for C:
+		 * 0x=hex, 0=octal, isdigit=decimal.
+		 */
+		if (!isdigit((unsigned char)c))
+			return (0);
+		val = 0; base = 10;
+		if (c == '0') {
+			c = *++cp;
+			if (c == 'x' || c == 'X')
+				base = 16, c = *++cp;
+			else
+				base = 8;
+		}
+		for (;;) {
+			if (isascii((unsigned char)c) &&
+			    isdigit((unsigned char)c)) {
+				val = (val * base) + (c - '0');
+				c = *++cp;
+			} else if (base == 16 &&
+			    isascii((unsigned char)c) &&
+			    isxdigit((unsigned char)c)) {
+				val = (val << 4) |
+				    (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
+				c = *++cp;
+			} else
+				break;
+		}
+		if (c == '.') {
+			/*
+			 * Internet format:
+			 *	a.b.c.d
+			 *	a.b.c	(with c treated as 16 bits)
+			 *	a.b	(with b treated as 24 bits)
+			 */
+			if (pp >= parts + 3)
+				return (0);
+			*pp++ = val;
+			c = *++cp;
+		} else
+			break;
+	}
+	/*
+	 * Check for trailing characters.
+	 */
+	if (c != '\0' &&
+	    (!isascii((unsigned char)c) || !isspace((unsigned char)c)))
+		return (0);
+	/*
+	 * Concoct the address according to
+	 * the number of parts specified.
+	 */
+	n = pp - parts + 1;
+	switch (n) {
+
+	case 0:
+		return (0);		/* initial nondigit */
+
+	case 1:				/* a -- 32 bits */
+		break;
+
+	case 2:				/* a.b -- 8.24 bits */
+		if ((val > 0xffffff) || (parts[0] > 0xff))
+			return (0);
+		val |= parts[0] << 24;
+		break;
+
+	case 3:				/* a.b.c -- 8.8.16 bits */
+		if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff))
+			return (0);
+		val |= (parts[0] << 24) | (parts[1] << 16);
+		break;
+
+	case 4:				/* a.b.c.d -- 8.8.8.8 bits */
+		if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff))
+			return (0);
+		val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+		break;
+	}
+	if (addr)
+		addr->s_addr = htonl(val);
+	return (1);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_lnaof.c b/libc/upstream-openbsd/lib/libc/net/inet_lnaof.c
new file mode 100644
index 0000000..b1a58cd
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/inet_lnaof.c
@@ -0,0 +1,51 @@
+/*	$OpenBSD: inet_lnaof.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * Return the local network address portion of an
+ * internet address; handles class a/b/c network
+ * number formats.
+ */
+in_addr_t
+inet_lnaof(struct in_addr in)
+{
+	in_addr_t i = ntohl(in.s_addr);
+
+	if (IN_CLASSA(i))
+		return ((i)&IN_CLASSA_HOST);
+	else if (IN_CLASSB(i))
+		return ((i)&IN_CLASSB_HOST);
+	else
+		return ((i)&IN_CLASSC_HOST);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_makeaddr.c b/libc/upstream-openbsd/lib/libc/net/inet_makeaddr.c
new file mode 100644
index 0000000..87d9325
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/inet_makeaddr.c
@@ -0,0 +1,54 @@
+/*	$OpenBSD: inet_makeaddr.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * Formulate an Internet address from network + host.  Used in
+ * building addresses stored in the ifnet structure.
+ */
+struct in_addr
+inet_makeaddr(in_addr_t net, in_addr_t host)
+{
+	in_addr_t addr;
+
+	if (net < 128)
+		addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
+	else if (net < 65536)
+		addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
+	else if (net < 16777216L)
+		addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
+	else
+		addr = net | host;
+	addr = htonl(addr);
+	return (*(struct in_addr *)&addr);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_netof.c b/libc/upstream-openbsd/lib/libc/net/inet_netof.c
new file mode 100644
index 0000000..2f468c3
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/inet_netof.c
@@ -0,0 +1,50 @@
+/*	$OpenBSD: inet_netof.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * Return the network number from an internet
+ * address; handles class a/b/c network #'s.
+ */
+in_addr_t
+inet_netof(struct in_addr in)
+{
+	in_addr_t i = ntohl(in.s_addr);
+
+	if (IN_CLASSA(i))
+		return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
+	else if (IN_CLASSB(i))
+		return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
+	else
+		return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_network.c b/libc/upstream-openbsd/lib/libc/net/inet_network.c
new file mode 100644
index 0000000..ecf554e
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/inet_network.c
@@ -0,0 +1,84 @@
+/*	$OpenBSD: inet_network.c,v 1.11 2013/11/25 17:29:19 deraadt Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <ctype.h>
+
+/*
+ * Internet network address interpretation routine.
+ * The library routines call this routine to interpret
+ * network numbers.
+ */
+in_addr_t
+inet_network(const char *cp)
+{
+	in_addr_t val, base, n;
+	u_char c;
+	in_addr_t parts[4], *pp = parts;
+	int i;
+
+again:
+	val = 0; base = 10;
+	if (*cp == '0')
+		base = 8, cp++;
+	if (*cp == 'x' || *cp == 'X')
+		base = 16, cp++;
+	while ((c = *cp)) {
+		if (isdigit(c)) {
+			val = (val * base) + (c - '0');
+			cp++;
+			continue;
+		}
+		if (base == 16 && isxdigit(c)) {
+			val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
+			cp++;
+			continue;
+		}
+		break;
+	}
+	if (*cp == '.') {
+		if (pp >= parts + 3)
+			return (INADDR_NONE);
+		*pp++ = val, cp++;
+		goto again;
+	}
+	if (*cp && !isspace(*cp))
+		return (INADDR_NONE);
+	*pp++ = val;
+	n = pp - parts;
+	for (val = 0, i = 0; i < 4; i++) {
+		val <<= 8;
+		if (i < n)
+			val |= parts[i] & 0xff;
+	}
+	return (val);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_ntoa.c b/libc/upstream-openbsd/lib/libc/net/inet_ntoa.c
new file mode 100644
index 0000000..ff5d93d
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/inet_ntoa.c
@@ -0,0 +1,51 @@
+/*	$OpenBSD: inet_ntoa.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Convert network-format internet address
+ * to base 256 d.d.d.d representation.
+ */
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+
+char *
+inet_ntoa(struct in_addr in)
+{
+	static char b[18];
+	char *p;
+
+	p = (char *)&in;
+#define	UC(b)	(((int)b)&0xff)
+	(void)snprintf(b, sizeof(b),
+	    "%u.%u.%u.%u", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
+	return (b);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_ntop.c b/libc/upstream-openbsd/lib/libc/net/inet_ntop.c
new file mode 100644
index 0000000..f991a07
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/inet_ntop.c
@@ -0,0 +1,205 @@
+/*	$OpenBSD: inet_ntop.c,v 1.10 2014/05/17 18:16:14 tedu Exp $	*/
+
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM 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.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static const char *inet_ntop4(const u_char *src, char *dst, size_t size);
+static const char *inet_ntop6(const u_char *src, char *dst, size_t size);
+
+/* const char *
+ * inet_ntop(af, src, dst, size)
+ *	convert a network format address to presentation format.
+ * return:
+ *	pointer to presentation format address (`dst'), or NULL (see errno).
+ * author:
+ *	Paul Vixie, 1996.
+ */
+const char *
+inet_ntop(int af, const void *src, char *dst, socklen_t size)
+{
+	switch (af) {
+	case AF_INET:
+		return (inet_ntop4(src, dst, (size_t)size));
+	case AF_INET6:
+		return (inet_ntop6(src, dst, (size_t)size));
+	default:
+		errno = EAFNOSUPPORT;
+		return (NULL);
+	}
+	/* NOTREACHED */
+}
+
+/* const char *
+ * inet_ntop4(src, dst, size)
+ *	format an IPv4 address, more or less like inet_ntoa()
+ * return:
+ *	`dst' (as a const)
+ * notes:
+ *	(1) uses no statics
+ *	(2) takes a u_char* not an in_addr as input
+ * author:
+ *	Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop4(const u_char *src, char *dst, size_t size)
+{
+	char tmp[sizeof "255.255.255.255"];
+	int l;
+
+	l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u",
+	    src[0], src[1], src[2], src[3]);
+	if (l <= 0 || l >= size) {
+		errno = ENOSPC;
+		return (NULL);
+	}
+	strlcpy(dst, tmp, size);
+	return (dst);
+}
+
+/* const char *
+ * inet_ntop6(src, dst, size)
+ *	convert IPv6 binary address into presentation (printable) format
+ * author:
+ *	Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop6(const u_char *src, char *dst, size_t size)
+{
+	/*
+	 * Note that int32_t and int16_t need only be "at least" large enough
+	 * to contain a value of the specified size.  On some systems, like
+	 * Crays, there is no such thing as an integer variable with 16 bits.
+	 * Keep this in mind if you think this function should have been coded
+	 * to use pointer overlays.  All the world's not a VAX.
+	 */
+	char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
+	char *tp, *ep;
+	struct { int base, len; } best, cur;
+	u_int words[IN6ADDRSZ / INT16SZ];
+	int i;
+	int advance;
+
+	/*
+	 * Preprocess:
+	 *	Copy the input (bytewise) array into a wordwise array.
+	 *	Find the longest run of 0x00's in src[] for :: shorthanding.
+	 */
+	memset(words, '\0', sizeof words);
+	for (i = 0; i < IN6ADDRSZ; i++)
+		words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
+	best.base = -1;
+	cur.base = -1;
+	for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
+		if (words[i] == 0) {
+			if (cur.base == -1)
+				cur.base = i, cur.len = 1;
+			else
+				cur.len++;
+		} else {
+			if (cur.base != -1) {
+				if (best.base == -1 || cur.len > best.len)
+					best = cur;
+				cur.base = -1;
+			}
+		}
+	}
+	if (cur.base != -1) {
+		if (best.base == -1 || cur.len > best.len)
+			best = cur;
+	}
+	if (best.base != -1 && best.len < 2)
+		best.base = -1;
+
+	/*
+	 * Format the result.
+	 */
+	tp = tmp;
+	ep = tmp + sizeof(tmp);
+	for (i = 0; i < (IN6ADDRSZ / INT16SZ) && tp < ep; i++) {
+		/* Are we inside the best run of 0x00's? */
+		if (best.base != -1 && i >= best.base &&
+		    i < (best.base + best.len)) {
+			if (i == best.base) {
+				if (tp + 1 >= ep) {
+					errno = ENOSPC;
+					return (NULL);
+				}
+				*tp++ = ':';
+			}
+			continue;
+		}
+		/* Are we following an initial run of 0x00s or any real hex? */
+		if (i != 0) {
+			if (tp + 1 >= ep) {
+				errno = ENOSPC;
+				return (NULL);
+			}
+			*tp++ = ':';
+		}
+		/* Is this address an encapsulated IPv4? */
+		if (i == 6 && best.base == 0 &&
+		    (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
+			if (!inet_ntop4(src+12, tp, (size_t)(ep - tp)))
+				return (NULL);
+			tp += strlen(tp);
+			break;
+		}
+		advance = snprintf(tp, ep - tp, "%x", words[i]);
+		if (advance <= 0 || advance >= ep - tp) {
+			errno = ENOSPC;
+			return (NULL);
+		}
+		tp += advance;
+	}
+	/* Was it a trailing run of 0x00's? */
+	if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) {
+		if (tp + 1 >= ep) {
+			errno = ENOSPC;
+			return (NULL);
+		}
+		*tp++ = ':';
+	}
+	if (tp + 1 >= ep) {
+		errno = ENOSPC;
+		return (NULL);
+	}
+	*tp++ = '\0';
+
+	/*
+	 * Check for overflow, copy, and we're done.
+	 */
+	if ((size_t)(tp - tmp) > size) {
+		errno = ENOSPC;
+		return (NULL);
+	}
+	strlcpy(dst, tmp, size);
+	return (dst);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/inet_pton.c b/libc/upstream-openbsd/lib/libc/net/inet_pton.c
new file mode 100644
index 0000000..7e521c3
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/inet_pton.c
@@ -0,0 +1,213 @@
+/*	$OpenBSD: inet_pton.c,v 1.8 2010/05/06 15:47:14 claudio Exp $	*/
+
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM 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.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <string.h>
+#include <errno.h>
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int	inet_pton4(const char *src, u_char *dst);
+static int	inet_pton6(const char *src, u_char *dst);
+
+/* int
+ * inet_pton(af, src, dst)
+ *	convert from presentation format (which usually means ASCII printable)
+ *	to network format (which is usually some kind of binary format).
+ * return:
+ *	1 if the address was valid for the specified address family
+ *	0 if the address wasn't valid (`dst' is untouched in this case)
+ *	-1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ *	Paul Vixie, 1996.
+ */
+int
+inet_pton(int af, const char *src, void *dst)
+{
+	switch (af) {
+	case AF_INET:
+		return (inet_pton4(src, dst));
+	case AF_INET6:
+		return (inet_pton6(src, dst));
+	default:
+		errno = EAFNOSUPPORT;
+		return (-1);
+	}
+	/* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ *	like inet_aton() but without all the hexadecimal and shorthand.
+ * return:
+ *	1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ *	does not touch `dst' unless it's returning 1.
+ * author:
+ *	Paul Vixie, 1996.
+ */
+static int
+inet_pton4(const char *src, u_char *dst)
+{
+	static const char digits[] = "0123456789";
+	int saw_digit, octets, ch;
+	u_char tmp[INADDRSZ], *tp;
+
+	saw_digit = 0;
+	octets = 0;
+	*(tp = tmp) = 0;
+	while ((ch = *src++) != '\0') {
+		const char *pch;
+
+		if ((pch = strchr(digits, ch)) != NULL) {
+			u_int new = *tp * 10 + (pch - digits);
+
+			if (new > 255)
+				return (0);
+			if (! saw_digit) {
+				if (++octets > 4)
+					return (0);
+				saw_digit = 1;
+			}
+			*tp = new;
+		} else if (ch == '.' && saw_digit) {
+			if (octets == 4)
+				return (0);
+			*++tp = 0;
+			saw_digit = 0;
+		} else
+			return (0);
+	}
+	if (octets < 4)
+		return (0);
+
+	memcpy(dst, tmp, INADDRSZ);
+	return (1);
+}
+
+/* int
+ * inet_pton6(src, dst)
+ *	convert presentation level address to network order binary form.
+ * return:
+ *	1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ *	does not touch `dst' unless it's returning 1.
+ * credit:
+ *	inspired by Mark Andrews.
+ * author:
+ *	Paul Vixie, 1996.
+ */
+static int
+inet_pton6(const char *src, u_char *dst)
+{
+	static const char xdigits_l[] = "0123456789abcdef",
+			  xdigits_u[] = "0123456789ABCDEF";
+	u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
+	const char *xdigits, *curtok;
+	int ch, saw_xdigit, count_xdigit;
+	u_int val;
+
+	memset((tp = tmp), '\0', IN6ADDRSZ);
+	endp = tp + IN6ADDRSZ;
+	colonp = NULL;
+	/* Leading :: requires some special handling. */
+	if (*src == ':')
+		if (*++src != ':')
+			return (0);
+	curtok = src;
+	saw_xdigit = count_xdigit = 0;
+	val = 0;
+	while ((ch = *src++) != '\0') {
+		const char *pch;
+
+		if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+			pch = strchr((xdigits = xdigits_u), ch);
+		if (pch != NULL) {
+			if (count_xdigit >= 4)
+				return (0);
+			val <<= 4;
+			val |= (pch - xdigits);
+			if (val > 0xffff)
+				return (0);
+			saw_xdigit = 1;
+			count_xdigit++;
+			continue;
+		}
+		if (ch == ':') {
+			curtok = src;
+			if (!saw_xdigit) {
+				if (colonp)
+					return (0);
+				colonp = tp;
+				continue;
+			} else if (*src == '\0') {
+				return (0);
+			}
+			if (tp + INT16SZ > endp)
+				return (0);
+			*tp++ = (u_char) (val >> 8) & 0xff;
+			*tp++ = (u_char) val & 0xff;
+			saw_xdigit = 0;
+			count_xdigit = 0;
+			val = 0;
+			continue;
+		}
+		if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
+		    inet_pton4(curtok, tp) > 0) {
+			tp += INADDRSZ;
+			saw_xdigit = 0;
+			count_xdigit = 0;
+			break;	/* '\0' was seen by inet_pton4(). */
+		}
+		return (0);
+	}
+	if (saw_xdigit) {
+		if (tp + INT16SZ > endp)
+			return (0);
+		*tp++ = (u_char) (val >> 8) & 0xff;
+		*tp++ = (u_char) val & 0xff;
+	}
+	if (colonp != NULL) {
+		/*
+		 * Since some memmove()'s erroneously fail to handle
+		 * overlapping regions, we'll do the shift by hand.
+		 */
+		const int n = tp - colonp;
+		int i;
+
+		if (tp == endp)
+			return (0);
+		for (i = 1; i <= n; i++) {
+			endp[- i] = colonp[n - i];
+			colonp[n - i] = 0;
+		}
+		tp = endp;
+	}
+	if (tp != endp)
+		return (0);
+	memcpy(dst, tmp, IN6ADDRSZ);
+	return (1);
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/ntohl.c b/libc/upstream-openbsd/lib/libc/net/ntohl.c
new file mode 100644
index 0000000..36414b7
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/ntohl.c
@@ -0,0 +1,21 @@
+/*	$OpenBSD: ntohl.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <sys/types.h>
+#include <machine/endian.h>
+
+#undef ntohl
+
+u_int32_t
+ntohl(u_int32_t x)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+	u_char *s = (u_char *)&x;
+	return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
+#else
+	return x;
+#endif
+}
diff --git a/libc/upstream-openbsd/lib/libc/net/ntohs.c b/libc/upstream-openbsd/lib/libc/net/ntohs.c
new file mode 100644
index 0000000..8f345e8
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/net/ntohs.c
@@ -0,0 +1,21 @@
+/*	$OpenBSD: ntohs.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <sys/types.h>
+#include <machine/endian.h>
+
+#undef ntohs
+
+u_int16_t
+ntohs(u_int16_t x)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+	u_char *s = (u_char *) &x;
+	return (u_int16_t)(s[0] << 8 | s[1]);
+#else
+	return x;
+#endif
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/asprintf.c b/libc/upstream-openbsd/lib/libc/stdio/asprintf.c
new file mode 100644
index 0000000..5424c90
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/asprintf.c
@@ -0,0 +1,63 @@
+/*	$OpenBSD: asprintf.c,v 1.19 2011/05/30 18:48:33 martynas Exp $	*/
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+#include "local.h"
+
+/* PRINTFLIKE2 */
+int
+asprintf(char **str, const char *fmt, ...)
+{
+	int ret;
+	va_list ap;
+	FILE f;
+	struct __sfileext fext;
+	unsigned char *_base;
+
+	_FILEEXT_SETUP(&f, &fext);
+	f._file = -1;
+	f._flags = __SWR | __SSTR | __SALC;
+	f._bf._base = f._p = (unsigned char *)malloc(128);
+	if (f._bf._base == NULL)
+		goto err;
+	f._bf._size = f._w = 127;		/* Leave room for the NUL */
+	va_start(ap, fmt);
+	ret = __vfprintf(&f, fmt, ap);
+	va_end(ap);
+	if (ret == -1)
+		goto err;
+	*f._p = '\0';
+	_base = realloc(f._bf._base, ret + 1);
+	if (_base == NULL)
+		goto err;
+	*str = (char *)_base;
+	return (ret);
+
+err:
+	if (f._bf._base) {
+		free(f._bf._base);
+		f._bf._base = NULL;
+	}
+	*str = NULL;
+	errno = ENOMEM;
+	return (-1);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/clrerr.c b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c
new file mode 100644
index 0000000..ac08c72
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c
@@ -0,0 +1,44 @@
+/*	$OpenBSD: clrerr.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+#undef	clearerr
+
+void
+clearerr(FILE *fp)
+{
+	FLOCKFILE(fp);
+	__sclearerr(fp);
+	FUNLOCKFILE(fp);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/dprintf.c b/libc/upstream-openbsd/lib/libc/stdio/dprintf.c
new file mode 100644
index 0000000..dbf7d34
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/dprintf.c
@@ -0,0 +1,48 @@
+/*	$OpenBSD: dprintf.c,v 1.1 2013/01/30 00:08:13 brad Exp $	*/
+/*	$FreeBSD: src/lib/libc/stdio/dprintf.c,v 1.2 2012/11/17 01:49:39 svnexp Exp $	*/
+
+/*-
+ * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Copyright (c) 2011 The FreeBSD Foundation
+ * All rights reserved.
+ * Portions of this software were developed by David Chisnall
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int
+dprintf(int fd, const char * __restrict fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vdprintf(fd, fmt, ap);
+	va_end(ap);
+	return ret;
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fdopen.c b/libc/upstream-openbsd/lib/libc/stdio/fdopen.c
new file mode 100644
index 0000000..3e47f2c
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fdopen.c
@@ -0,0 +1,83 @@
+/*	$OpenBSD: fdopen.c,v 1.6 2008/04/21 12:28:35 otto Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include "local.h"
+
+FILE *
+fdopen(int fd, const char *mode)
+{
+	FILE *fp;
+	int flags, oflags, fdflags, tmp;
+
+	/* _file is only a short */
+	if (fd > SHRT_MAX) {
+		errno = EMFILE;
+		return (NULL);
+	}
+
+	if ((flags = __sflags(mode, &oflags)) == 0)
+		return (NULL);
+
+	/* Make sure the mode the user wants is a subset of the actual mode. */
+	if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0)
+		return (NULL);
+	tmp = fdflags & O_ACCMODE;
+	if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) {
+		errno = EINVAL;
+		return (NULL);
+	}
+
+	if ((fp = __sfp()) == NULL)
+		return (NULL);
+	fp->_flags = flags;
+	/*
+	 * If opened for appending, but underlying descriptor does not have
+	 * O_APPEND bit set, assert __SAPP so that __swrite() will lseek to
+	 * end before each write.
+	 */
+	if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
+		fp->_flags |= __SAPP;
+	fp->_file = fd;
+	fp->_cookie = fp;
+	fp->_read = __sread;
+	fp->_write = __swrite;
+	fp->_seek = __sseek;
+	fp->_close = __sclose;
+	return (fp);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/feof.c b/libc/upstream-openbsd/lib/libc/stdio/feof.c
new file mode 100644
index 0000000..0036bab
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/feof.c
@@ -0,0 +1,51 @@
+/*	$OpenBSD: feof.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro feof.
+ */
+#undef feof
+
+int
+feof(FILE *fp)
+{
+	int	ret;
+
+	FLOCKFILE(fp);
+	ret = __sfeof(fp);
+	FUNLOCKFILE(fp);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/ferror.c b/libc/upstream-openbsd/lib/libc/stdio/ferror.c
new file mode 100644
index 0000000..00b9c8b
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/ferror.c
@@ -0,0 +1,51 @@
+/*	$OpenBSD: ferror.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro ferror.
+ */
+#undef ferror
+
+int
+ferror(FILE *fp)
+{
+	int     ret;
+
+	FLOCKFILE(fp);
+	ret = __sferror(fp);
+	FUNLOCKFILE(fp);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fflush.c b/libc/upstream-openbsd/lib/libc/stdio/fflush.c
new file mode 100644
index 0000000..3e30f10
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fflush.c
@@ -0,0 +1,97 @@
+/*	$OpenBSD: fflush.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include "local.h"
+
+/* Flush a single file, or (if fp is NULL) all files.  */
+int
+fflush(FILE *fp)
+{
+	int	r;
+
+	if (fp == NULL)
+		return (_fwalk(__sflush_locked));
+	FLOCKFILE(fp);
+	if ((fp->_flags & (__SWR | __SRW)) == 0) {
+		errno = EBADF;
+		r = EOF;
+	} else
+		r = __sflush(fp);
+	FUNLOCKFILE(fp);
+	return (r);
+}
+
+int
+__sflush(FILE *fp)
+{
+	unsigned char *p;
+	int n, t;
+
+	t = fp->_flags;
+	if ((t & __SWR) == 0)
+		return (0);
+
+	if ((p = fp->_bf._base) == NULL)
+		return (0);
+
+	n = fp->_p - p;		/* write this much */
+
+	/*
+	 * Set these immediately to avoid problems with longjmp and to allow
+	 * exchange buffering (via setvbuf) in user write function.
+	 */
+	fp->_p = p;
+	fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
+
+	for (; n > 0; n -= t, p += t) {
+		t = (*fp->_write)(fp->_cookie, (char *)p, n);
+		if (t <= 0) {
+			fp->_flags |= __SERR;
+			return (EOF);
+		}
+	}
+	return (0);
+}
+
+int
+__sflush_locked(FILE *fp)
+{
+	int	r;
+
+	FLOCKFILE(fp);
+	r = __sflush(fp);
+	FUNLOCKFILE(fp);
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/fgetc.c
new file mode 100644
index 0000000..c5d7dde
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetc.c
@@ -0,0 +1,40 @@
+/*	$OpenBSD: fgetc.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+int
+fgetc(FILE *fp)
+{
+	return (getc(fp));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetln.c b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
new file mode 100644
index 0000000..d0c0809
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
@@ -0,0 +1,154 @@
+/*	$OpenBSD: fgetln.c,v 1.12 2013/11/12 07:04:06 deraadt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "local.h"
+
+/*
+ * Expand the line buffer.  Return -1 on error.
+#ifdef notdef
+ * The `new size' does not account for a terminating '\0',
+ * so we add 1 here.
+#endif
+ */
+static int
+__slbexpand(FILE *fp, size_t newsize)
+{
+	void *p;
+
+#ifdef notdef
+	++newsize;
+#endif
+	if (fp->_lb._size >= newsize)
+		return (0);
+	if ((p = realloc(fp->_lb._base, newsize)) == NULL)
+		return (-1);
+	fp->_lb._base = p;
+	fp->_lb._size = newsize;
+	return (0);
+}
+
+/*
+ * Get an input line.  The returned pointer often (but not always)
+ * points into a stdio buffer.  Fgetline does not alter the text of
+ * the returned line (which is thus not a C string because it will
+ * not necessarily end with '\0'), but does allow callers to modify
+ * it if they wish.  Thus, we set __SMOD in case the caller does.
+ */
+char *
+fgetln(FILE *fp, size_t *lenp)
+{
+	unsigned char *p;
+	char *ret;
+	size_t len;
+	size_t off;
+
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, -1);
+
+	/* make sure there is input */
+	if (fp->_r <= 0 && __srefill(fp))
+		goto error;
+
+	/* look for a newline in the input */
+	if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) {
+		/*
+		 * Found one.  Flag buffer as modified to keep fseek from
+		 * `optimising' a backward seek, in case the user stomps on
+		 * the text.
+		 */
+		p++;		/* advance over it */
+		ret = (char *)fp->_p;
+		*lenp = len = p - fp->_p;
+		fp->_flags |= __SMOD;
+		fp->_r -= len;
+		fp->_p = p;
+		FUNLOCKFILE(fp);
+		return (ret);
+	}
+
+	/*
+	 * We have to copy the current buffered data to the line buffer.
+	 * As a bonus, though, we can leave off the __SMOD.
+	 *
+	 * OPTIMISTIC is length that we (optimistically) expect will
+	 * accommodate the `rest' of the string, on each trip through the
+	 * loop below.
+	 */
+#define OPTIMISTIC 80
+
+	for (len = fp->_r, off = 0;; len += fp->_r) {
+		size_t diff;
+
+		/*
+		 * Make sure there is room for more bytes.  Copy data from
+		 * file buffer to line buffer, refill file and look for
+		 * newline.  The loop stops only when we find a newline.
+		 */
+		if (__slbexpand(fp, len + OPTIMISTIC))
+			goto error;
+		(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
+		    len - off);
+		off = len;
+		if (__srefill(fp))
+			break;	/* EOF or error: return partial line */
+		if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL)
+			continue;
+
+		/* got it: finish up the line (like code above) */
+		p++;
+		diff = p - fp->_p;
+		len += diff;
+		if (__slbexpand(fp, len))
+			goto error;
+		(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
+		    diff);
+		fp->_r -= diff;
+		fp->_p = p;
+		break;
+	}
+	*lenp = len;
+	ret = (char *)fp->_lb._base;
+#ifdef notdef
+	ret[len] = '\0';
+#endif
+	FUNLOCKFILE(fp);
+	return (ret);
+
+error:
+	*lenp = 0;		/* ??? */
+	FUNLOCKFILE(fp);
+	return (NULL);		/* ??? */
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c b/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c
new file mode 100644
index 0000000..e6188e5
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c
@@ -0,0 +1,43 @@
+/*	$OpenBSD: fgetpos.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+/*
+ * fgetpos: like ftello.
+ */
+int
+fgetpos(FILE *fp, fpos_t *pos)
+{
+	return((*pos = ftello(fp)) == (fpos_t)-1);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgets.c b/libc/upstream-openbsd/lib/libc/stdio/fgets.c
new file mode 100644
index 0000000..0ba8770
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgets.c
@@ -0,0 +1,105 @@
+/*	$OpenBSD: fgets.c,v 1.14 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "local.h"
+
+/*
+ * Read at most n-1 characters from the given file.
+ * Stop when a newline has been read, or the count runs out.
+ * Return first argument, or NULL if no characters were read.
+ * Do not return NULL if n == 1.
+ */
+char *
+fgets(char *buf, int n, FILE *fp)
+{
+	size_t len;
+	char *s;
+	unsigned char *p, *t;
+
+	if (n <= 0) {		/* sanity check */
+		errno = EINVAL;
+		return (NULL);
+	}
+
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, -1);
+	s = buf;
+	n--;			/* leave space for NUL */
+	while (n != 0) {
+		/*
+		 * If the buffer is empty, refill it.
+		 */
+		if (fp->_r <= 0) {
+			if (__srefill(fp)) {
+				/* EOF/error: stop with partial or no line */
+				if (s == buf) {
+					FUNLOCKFILE(fp);
+					return (NULL);
+				}
+				break;
+			}
+		}
+		len = fp->_r;
+		p = fp->_p;
+
+		/*
+		 * Scan through at most n bytes of the current buffer,
+		 * looking for '\n'.  If found, copy up to and including
+		 * newline, and stop.  Otherwise, copy entire chunk
+		 * and loop.
+		 */
+		if (len > n)
+			len = n;
+		t = memchr((void *)p, '\n', len);
+		if (t != NULL) {
+			len = ++t - p;
+			fp->_r -= len;
+			fp->_p = t;
+			(void)memcpy((void *)s, (void *)p, len);
+			s[len] = '\0';
+			FUNLOCKFILE(fp);
+			return (buf);
+		}
+		fp->_r -= len;
+		fp->_p += len;
+		(void)memcpy((void *)s, (void *)p, len);
+		s += len;
+		n -= len;
+	}
+	*s = '\0';
+	FUNLOCKFILE(fp);
+	return (buf);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetwc.c b/libc/upstream-openbsd/lib/libc/stdio/fgetwc.c
new file mode 100644
index 0000000..c16ffaf
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetwc.c
@@ -0,0 +1,90 @@
+/*	$OpenBSD: fgetwc.c,v 1.4 2009/11/09 00:18:27 kurt Exp $	*/
+/* $NetBSD: fgetwc.c,v 1.3 2003/03/07 07:11:36 tshiozak Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "local.h"
+
+wint_t
+__fgetwc_unlock(FILE *fp)
+{
+	struct wchar_io_data *wcio;
+	mbstate_t *st;
+	wchar_t wc;
+	size_t size;
+
+	_SET_ORIENTATION(fp, 1);
+	wcio = WCIO_GET(fp);
+	if (wcio == 0) {
+		errno = ENOMEM;
+		return WEOF;
+	}
+
+	/* if there're ungetwc'ed wchars, use them */
+	if (wcio->wcio_ungetwc_inbuf) {
+		wc = wcio->wcio_ungetwc_buf[--wcio->wcio_ungetwc_inbuf];
+
+		return wc;
+	}
+
+	st = &wcio->wcio_mbstate_in;
+
+	do {
+		char c;
+		int ch = __sgetc(fp);
+
+		if (ch == EOF) {
+			return WEOF;
+		}
+
+		c = ch;
+		size = mbrtowc(&wc, &c, 1, st);
+		if (size == (size_t)-1) {
+			errno = EILSEQ;
+			return WEOF;
+		}
+	} while (size == (size_t)-2);
+
+	return wc;
+}
+
+wint_t
+fgetwc(FILE *fp)
+{
+	wint_t r;
+
+	FLOCKFILE(fp);
+	r = __fgetwc_unlock(fp);
+	FUNLOCKFILE(fp);
+
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetws.c b/libc/upstream-openbsd/lib/libc/stdio/fgetws.c
new file mode 100644
index 0000000..e8cd249
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetws.c
@@ -0,0 +1,79 @@
+/*	$OpenBSD: fgetws.c,v 1.6 2009/11/09 00:18:27 kurt Exp $	*/
+/* $NetBSD: fgetws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.4 2002/09/20 13:25:40 tjr Exp
+ *
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "local.h"
+
+wchar_t *
+fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
+{
+	wchar_t *wsp;
+	wint_t wc;
+
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, 1);
+
+	if (n <= 0) {
+		errno = EINVAL;
+		goto error;
+	}
+
+	wsp = ws;
+	while (n-- > 1) {
+		if ((wc = __fgetwc_unlock(fp)) == WEOF && errno == EILSEQ) {
+			goto error;
+		}
+		if (wc == WEOF) {
+			if (wsp == ws) {
+				/* EOF/error, no characters read yet. */
+				goto error;
+			}
+			break;
+		}
+		*wsp++ = (wchar_t)wc;
+		if (wc == L'\n') {
+			break;
+		}
+	}
+
+	*wsp++ = L'\0';
+	FUNLOCKFILE(fp);
+
+	return (ws);
+
+error:
+	FUNLOCKFILE(fp);
+	return (NULL);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fileno.c b/libc/upstream-openbsd/lib/libc/stdio/fileno.c
new file mode 100644
index 0000000..58628da
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fileno.c
@@ -0,0 +1,51 @@
+/*	$OpenBSD: fileno.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro fileno.
+ */
+#undef fileno
+
+int
+fileno(FILE *fp)
+{
+	int     ret;
+
+	FLOCKFILE(fp);
+	ret = __sfileno(fp);
+	FUNLOCKFILE(fp);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/findfp.c b/libc/upstream-openbsd/lib/libc/stdio/findfp.c
new file mode 100644
index 0000000..b8c7dc1
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/findfp.c
@@ -0,0 +1,181 @@
+/*	$OpenBSD: findfp.c,v 1.15 2013/12/17 16:33:27 deraadt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include "local.h"
+#include "glue.h"
+#include "private/thread_private.h"
+
+#define ALIGNBYTES (sizeof(uintptr_t) - 1)
+#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
+
+int	__sdidinit;
+
+#define	NDYNAMIC 10		/* add ten more whenever necessary */
+
+#define	std(flags, file) \
+	{0,0,0,flags,file,{0,0},0,__sF+file,__sclose,__sread,__sseek,__swrite, \
+	 {(unsigned char *)(__sFext+file), 0},NULL,0,{0,0,0},{0},{0,0},0,0}
+/*	 p r w flags file _bf z  cookie      close    read    seek    write
+	 ext */
+
+				/* the usual - (stdin + stdout + stderr) */
+static FILE usual[FOPEN_MAX - 3];
+static struct __sfileext usualext[FOPEN_MAX - 3];
+static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
+static struct glue *lastglue = &uglue;
+_THREAD_PRIVATE_MUTEX(__sfp_mutex);
+
+static struct __sfileext __sFext[3];
+FILE __sF[3] = {
+	std(__SRD, STDIN_FILENO),		/* stdin */
+	std(__SWR, STDOUT_FILENO),		/* stdout */
+	std(__SWR|__SNBF, STDERR_FILENO)	/* stderr */
+};
+struct glue __sglue = { &uglue, 3, __sF };
+
+static struct glue *
+moreglue(int n)
+{
+	struct glue *g;
+	FILE *p;
+	struct __sfileext *pext;
+	static FILE empty;
+	char *data;
+
+	data = malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)
+	    + n * sizeof(struct __sfileext));
+	if (data == NULL)
+		return (NULL);
+	g = (struct glue *)data;
+	p = (FILE *)ALIGN(data + sizeof(*g));
+	pext = (struct __sfileext *)
+	    (ALIGN(data + sizeof(*g)) + n * sizeof(FILE));
+	g->next = NULL;
+	g->niobs = n;
+	g->iobs = p;
+	while (--n >= 0) {
+		*p = empty;
+		_FILEEXT_SETUP(p, pext);
+		p++;
+		pext++;
+	}
+	return (g);
+}
+
+/*
+ * Find a free FILE for fopen et al.
+ */
+FILE *
+__sfp(void)
+{
+	FILE *fp;
+	int n;
+	struct glue *g;
+
+	if (!__sdidinit)
+		__sinit();
+
+	_THREAD_PRIVATE_MUTEX_LOCK(__sfp_mutex);
+	for (g = &__sglue; g != NULL; g = g->next) {
+		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
+			if (fp->_flags == 0)
+				goto found;
+	}
+
+	/* release lock while mallocing */
+	_THREAD_PRIVATE_MUTEX_UNLOCK(__sfp_mutex);
+	if ((g = moreglue(NDYNAMIC)) == NULL)
+		return (NULL);
+	_THREAD_PRIVATE_MUTEX_LOCK(__sfp_mutex);
+	lastglue->next = g;
+	lastglue = g;
+	fp = g->iobs;
+found:
+	fp->_flags = 1;		/* reserve this slot; caller sets real flags */
+	_THREAD_PRIVATE_MUTEX_UNLOCK(__sfp_mutex);
+	fp->_p = NULL;		/* no current pointer */
+	fp->_w = 0;		/* nothing to read or write */
+	fp->_r = 0;
+	fp->_bf._base = NULL;	/* no buffer */
+	fp->_bf._size = 0;
+	fp->_lbfsize = 0;	/* not line buffered */
+	fp->_file = -1;		/* no file */
+/*	fp->_cookie = <any>; */	/* caller sets cookie, _read/_write etc */
+	fp->_lb._base = NULL;	/* no line buffer */
+	fp->_lb._size = 0;
+	_FILEEXT_INIT(fp);
+	return (fp);
+}
+
+/*
+ * exit() and abort() call _cleanup() through the callback registered
+ * with __atexit_register_cleanup(), set whenever we open or buffer a
+ * file. This chicanery is done so that programs that do not use stdio
+ * need not link it all in.
+ *
+ * The name `_cleanup' is, alas, fairly well known outside stdio.
+ */
+void
+_cleanup(void)
+{
+	/* (void) _fwalk(fclose); */
+	(void) _fwalk(__sflush);		/* `cheating' */
+}
+
+/*
+ * __sinit() is called whenever stdio's internal variables must be set up.
+ */
+void
+__sinit(void)
+{
+	_THREAD_PRIVATE_MUTEX(__sinit_mutex);
+	int i;
+
+	_THREAD_PRIVATE_MUTEX_LOCK(__sinit_mutex);
+	if (__sdidinit)
+		goto out;	/* bail out if caller lost the race */
+	for (i = 0; i < FOPEN_MAX - 3; i++) {
+		_FILEEXT_SETUP(usual+i, usualext+i);
+	}
+	/* make sure we clean up on exit */
+	__atexit_register_cleanup(_cleanup); /* conservative */
+	__sdidinit = 1;
+out:
+	_THREAD_PRIVATE_MUTEX_UNLOCK(__sinit_mutex);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/floatio.h b/libc/upstream-openbsd/lib/libc/stdio/floatio.h
new file mode 100644
index 0000000..9769030
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/floatio.h
@@ -0,0 +1,58 @@
+/*	$OpenBSD: floatio.h,v 1.4 2008/09/07 20:36:08 martynas Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Floating point scanf/printf (input/output) definitions.
+ */
+
+/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
+#define	MAXEXP		308
+/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
+#define	MAXFRACT	39
+
+/*
+ * MAXEXPDIG is the maximum number of decimal digits needed to store a
+ * floating point exponent in the largest supported format.  It should
+ * be ceil(log10(LDBL_MAX_10_EXP)) or, if hexadecimal floating point
+ * conversions are supported, ceil(log10(LDBL_MAX_EXP)).  But since it
+ * is presently never greater than 5 in practice, we fudge it.
+ */
+#define	MAXEXPDIG	6
+#if LDBL_MAX_EXP > 999999
+#error "floating point buffers too small"
+#endif
+
+char *__hdtoa(double, const char *, int, int *, int *, char **);
+char *__hldtoa(long double, const char *, int, int *, int *, char **);
+char *__ldtoa(long double *, int, int, int *, int *, char **);
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fprintf.c b/libc/upstream-openbsd/lib/libc/stdio/fprintf.c
new file mode 100644
index 0000000..a391142
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fprintf.c
@@ -0,0 +1,48 @@
+/*	$OpenBSD: fprintf.c,v 1.7 2011/05/30 18:48:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+/* PRINTFLIKE2 */
+int
+fprintf(FILE *fp, const char *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfprintf(fp, fmt, ap);
+	va_end(ap);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fpurge.c b/libc/upstream-openbsd/lib/libc/stdio/fpurge.c
new file mode 100644
index 0000000..65bd749
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fpurge.c
@@ -0,0 +1,61 @@
+/*	$OpenBSD: fpurge.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "local.h"
+
+/*
+ * fpurge: like fflush, but without writing anything: leave the
+ * given FILE's buffer empty.
+ */
+int
+fpurge(FILE *fp)
+{
+	FLOCKFILE(fp);
+	if (!fp->_flags) {
+		FUNLOCKFILE(fp);
+		errno = EBADF;
+		return(EOF);
+	}
+
+	if (HASUB(fp))
+		FREEUB(fp);
+	WCIO_FREE(fp);
+	fp->_p = fp->_bf._base;
+	fp->_r = 0;
+	fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
+	FUNLOCKFILE(fp);
+	return (0);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fputc.c b/libc/upstream-openbsd/lib/libc/stdio/fputc.c
new file mode 100644
index 0000000..98e3960
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fputc.c
@@ -0,0 +1,41 @@
+/*	$OpenBSD: fputc.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+
+int
+fputc(int c, FILE *fp)
+{
+	return (putc(c, fp));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fputs.c b/libc/upstream-openbsd/lib/libc/stdio/fputs.c
new file mode 100644
index 0000000..ea8556a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fputs.c
@@ -0,0 +1,58 @@
+/*	$OpenBSD: fputs.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "local.h"
+#include "fvwrite.h"
+
+/*
+ * Write the given string to the given file.
+ */
+int
+fputs(const char *s, FILE *fp)
+{
+	struct __suio uio;
+	struct __siov iov;
+	int ret;
+
+	iov.iov_base = (void *)s;
+	iov.iov_len = uio.uio_resid = strlen(s);
+	uio.uio_iov = &iov;
+	uio.uio_iovcnt = 1;
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, -1);
+	ret = __sfvwrite(fp, &uio);
+	FUNLOCKFILE(fp);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fputwc.c b/libc/upstream-openbsd/lib/libc/stdio/fputwc.c
new file mode 100644
index 0000000..9db70d0
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fputwc.c
@@ -0,0 +1,88 @@
+/*	$OpenBSD: fputwc.c,v 1.4 2009/11/09 00:18:27 kurt Exp $	*/
+/* $NetBSD: fputwc.c,v 1.3 2003/03/07 07:11:37 tshiozak Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "local.h"
+#include "fvwrite.h"
+
+wint_t
+__fputwc_unlock(wchar_t wc, FILE *fp)
+{
+	struct wchar_io_data *wcio;
+	mbstate_t *st;
+	size_t size;
+	char buf[MB_LEN_MAX];
+	struct __suio uio;
+	struct __siov iov;
+
+	/* LINTED we don't play with buf */
+	iov.iov_base = (void *)buf;
+	uio.uio_iov = &iov;
+	uio.uio_iovcnt = 1;
+
+	_SET_ORIENTATION(fp, 1);
+	wcio = WCIO_GET(fp);
+	if (wcio == 0) {
+		errno = ENOMEM;
+		return WEOF;
+	}
+
+	wcio->wcio_ungetwc_inbuf = 0;
+	st = &wcio->wcio_mbstate_out;
+
+	size = wcrtomb(buf, wc, st);
+	if (size == (size_t)-1) {
+		errno = EILSEQ;
+		return WEOF;
+	}
+
+	uio.uio_resid = iov.iov_len = size;
+	if (__sfvwrite(fp, &uio)) {
+		return WEOF;
+	}
+
+	return (wint_t)wc;
+}
+
+wint_t
+fputwc(wchar_t wc, FILE *fp)
+{
+	wint_t r;
+
+	FLOCKFILE(fp);
+	r = __fputwc_unlock(wc, fp);
+	FUNLOCKFILE(fp);
+
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fputws.c b/libc/upstream-openbsd/lib/libc/stdio/fputws.c
new file mode 100644
index 0000000..108846e
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fputws.c
@@ -0,0 +1,57 @@
+/*	$OpenBSD: fputws.c,v 1.7 2013/11/12 07:04:35 deraadt Exp $	*/
+/* $NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * FreeBSD: src/lib/libc/stdio/fputws.c,v 1.4 2002/09/20 13:25:40 tjr Exp
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "local.h"
+#include "fvwrite.h"
+
+int
+fputws(ws, fp)
+	const wchar_t * __restrict ws;
+	FILE * __restrict fp;
+{
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, 1);
+
+	while (*ws != '\0') {
+		if (__fputwc_unlock(*ws++, fp) == WEOF) {
+			FUNLOCKFILE(fp);
+			return (-1);
+		}
+	}
+
+	FUNLOCKFILE(fp);
+
+	return (0);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fread.c b/libc/upstream-openbsd/lib/libc/stdio/fread.c
new file mode 100644
index 0000000..8a592f6
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fread.c
@@ -0,0 +1,88 @@
+/*	$OpenBSD: fread.c,v 1.12 2014/05/01 16:40:36 deraadt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <errno.h>
+#include "local.h"
+
+#define MUL_NO_OVERFLOW	(1UL << (sizeof(size_t) * 4))
+
+size_t
+fread(void *buf, size_t size, size_t count, FILE *fp)
+{
+	size_t resid;
+	char *p;
+	int r;
+	size_t total;
+
+	/*
+	 * Extension:  Catch integer overflow
+	 */
+	if ((size >= MUL_NO_OVERFLOW || count >= MUL_NO_OVERFLOW) &&
+	    size > 0 && SIZE_MAX / size < count) {
+		errno = EOVERFLOW;
+		fp->_flags |= __SERR;
+		return (0);
+	}
+
+	/*
+	 * ANSI and SUSv2 require a return value of 0 if size or count are 0.
+	 */
+	if ((resid = count * size) == 0)
+		return (0);
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, -1);
+	if (fp->_r < 0)
+		fp->_r = 0;
+	total = resid;
+	p = buf;
+	while (resid > (r = fp->_r)) {
+		(void)memcpy((void *)p, (void *)fp->_p, (size_t)r);
+		fp->_p += r;
+		/* fp->_r = 0 ... done in __srefill */
+		p += r;
+		resid -= r;
+		if (__srefill(fp)) {
+			/* no more input: return partial result */
+			FUNLOCKFILE(fp);
+			return ((total - resid) / size);
+		}
+	}
+	(void)memcpy((void *)p, (void *)fp->_p, resid);
+	fp->_r -= resid;
+	fp->_p += resid;
+	FUNLOCKFILE(fp);
+	return (count);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/freopen.c b/libc/upstream-openbsd/lib/libc/stdio/freopen.c
new file mode 100644
index 0000000..3158fb1
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/freopen.c
@@ -0,0 +1,171 @@
+/*	$OpenBSD: freopen.c,v 1.13 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <limits.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "local.h"
+
+/* 
+ * Re-direct an existing, open (probably) file to some other file. 
+ * ANSI is written such that the original file gets closed if at
+ * all possible, no matter what.
+ */
+FILE *
+freopen(const char *file, const char *mode, FILE *fp)
+{
+	int f;
+	int flags, isopen, oflags, sverrno, wantfd;
+
+	if ((flags = __sflags(mode, &oflags)) == 0) {
+		(void) fclose(fp);
+		return (NULL);
+	}
+
+	if (!__sdidinit)
+		__sinit();
+
+	FLOCKFILE(fp);
+
+	/*
+	 * There are actually programs that depend on being able to "freopen"
+	 * descriptors that weren't originally open.  Keep this from breaking.
+	 * Remember whether the stream was open to begin with, and which file
+	 * descriptor (if any) was associated with it.  If it was attached to
+	 * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin)
+	 * should work.  This is unnecessary if it was not a Unix file.
+	 */
+	if (fp->_flags == 0) {
+		fp->_flags = __SEOF;	/* hold on to it */
+		isopen = 0;
+		wantfd = -1;
+	} else {
+		/* flush the stream; ANSI doesn't require this. */
+		if (fp->_flags & __SWR)
+			(void) __sflush(fp);
+		/* if close is NULL, closing is a no-op, hence pointless */
+		isopen = fp->_close != NULL;
+		if ((wantfd = fp->_file) < 0 && isopen) {
+			(void) (*fp->_close)(fp->_cookie);
+			isopen = 0;
+		}
+	}
+
+	/* Get a new descriptor to refer to the new file. */
+	f = open(file, oflags, DEFFILEMODE);
+	if (f < 0 && isopen) {
+		/* If out of fd's close the old one and try again. */
+		if (errno == ENFILE || errno == EMFILE) {
+			(void) (*fp->_close)(fp->_cookie);
+			isopen = 0;
+			f = open(file, oflags, DEFFILEMODE);
+		}
+	}
+	sverrno = errno;
+
+	/*
+	 * Finish closing fp.  Even if the open succeeded above, we cannot
+	 * keep fp->_base: it may be the wrong size.  This loses the effect
+	 * of any setbuffer calls, but stdio has always done this before.
+	 */
+	if (isopen && f != wantfd)
+		(void) (*fp->_close)(fp->_cookie);
+	if (fp->_flags & __SMBF)
+		free((char *)fp->_bf._base);
+	fp->_w = 0;
+	fp->_r = 0;
+	fp->_p = NULL;
+	fp->_bf._base = NULL;
+	fp->_bf._size = 0;
+	fp->_lbfsize = 0;
+	if (HASUB(fp))
+		FREEUB(fp);
+	_UB(fp)._size = 0;
+	WCIO_FREE(fp);
+	if (HASLB(fp))
+		FREELB(fp);
+	fp->_lb._size = 0;
+
+	if (f < 0) {			/* did not get it after all */
+		fp->_flags = 0;		/* set it free */
+		FUNLOCKFILE(fp);
+		errno = sverrno;	/* restore in case _close clobbered */
+		return (NULL);
+	}
+
+	/*
+	 * If reopening something that was open before on a real file, try
+	 * to maintain the descriptor.  Various C library routines (perror)
+	 * assume stderr is always fd STDERR_FILENO, even if being freopen'd.
+	 */
+	if (wantfd >= 0 && f != wantfd) {
+		if (dup2(f, wantfd) >= 0) {
+			(void) close(f);
+			f = wantfd;
+		}
+	}
+
+	/* _file is only a short */
+	if (f > SHRT_MAX) {
+		fp->_flags = 0;		/* set it free */
+		FUNLOCKFILE(fp);
+		errno = EMFILE;
+		return (NULL);
+	}
+
+	fp->_flags = flags;
+	fp->_file = f;
+	fp->_cookie = fp;
+	fp->_read = __sread;
+	fp->_write = __swrite;
+	fp->_seek = __sseek;
+	fp->_close = __sclose;
+
+	/*
+	 * When opening in append mode, even though we use O_APPEND,
+	 * we need to seek to the end so that ftell() gets the right
+	 * answer.  If the user then alters the seek pointer, or
+	 * the file extends, this will fail, but there is not much
+	 * we can do about this.  (We could set __SAPP and check in
+	 * fseek and ftell.)
+	 */
+	if (oflags & O_APPEND)
+		(void) __sseek((void *)fp, (fpos_t)0, SEEK_END);
+	FUNLOCKFILE(fp);
+	return (fp);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fscanf.c b/libc/upstream-openbsd/lib/libc/stdio/fscanf.c
new file mode 100644
index 0000000..5fd10d4
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fscanf.c
@@ -0,0 +1,48 @@
+/*	$OpenBSD: fscanf.c,v 1.10 2011/05/30 18:48:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+/* SCANFLIKE2 */
+int
+fscanf(FILE *fp, const char *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfscanf(fp, fmt, ap);
+	va_end(ap);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fseek.c b/libc/upstream-openbsd/lib/libc/stdio/fseek.c
new file mode 100644
index 0000000..cdd40b6
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fseek.c
@@ -0,0 +1,251 @@
+/*	$OpenBSD: fseek.c,v 1.11 2012/05/21 22:24:19 matthew Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "local.h"
+
+#define	POS_ERR	(-(fpos_t)1)
+
+/*
+ * Seek the given file to the given offset.
+ * `Whence' must be one of the three SEEK_* macros.
+ */
+int
+fseeko(FILE *fp, off_t offset, int whence)
+{
+	fpos_t (*seekfn)(void *, fpos_t, int);
+	fpos_t target, curoff;
+	size_t n;
+	struct stat st;
+	int havepos;
+
+	/* make sure stdio is set up */
+	if (!__sdidinit)
+		__sinit();
+
+	/*
+	 * Have to be able to seek.
+	 */
+	if ((seekfn = fp->_seek) == NULL) {
+		errno = ESPIPE;			/* historic practice */
+		return (EOF);
+	}
+
+	/*
+	 * Change any SEEK_CUR to SEEK_SET, and check `whence' argument.
+	 * After this, whence is either SEEK_SET or SEEK_END.
+	 */
+	FLOCKFILE(fp);
+	switch (whence) {
+
+	case SEEK_CUR:
+		/*
+		 * In order to seek relative to the current stream offset,
+		 * we have to first find the current stream offset a la
+		 * ftell (see ftell for details).
+		 */
+		__sflush(fp);	/* may adjust seek offset on append stream */
+		if (fp->_flags & __SOFF)
+			curoff = fp->_offset;
+		else {
+			curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
+			if (curoff == (fpos_t)-1) {
+				FUNLOCKFILE(fp);
+				return (EOF);
+			}
+		}
+		if (fp->_flags & __SRD) {
+			curoff -= fp->_r;
+			if (HASUB(fp))
+				curoff -= fp->_ur;
+		} else if (fp->_flags & __SWR && fp->_p != NULL)
+			curoff += fp->_p - fp->_bf._base;
+
+		offset += curoff;
+		whence = SEEK_SET;
+		havepos = 1;
+		break;
+
+	case SEEK_SET:
+	case SEEK_END:
+		curoff = 0;		/* XXX just to keep gcc quiet */
+		havepos = 0;
+		break;
+
+	default:
+		FUNLOCKFILE(fp);
+		errno = EINVAL;
+		return (EOF);
+	}
+
+	/*
+	 * Can only optimise if:
+	 *	reading (and not reading-and-writing);
+	 *	not unbuffered; and
+	 *	this is a `regular' Unix file (and hence seekfn==__sseek).
+	 * We must check __NBF first, because it is possible to have __NBF
+	 * and __SOPT both set.
+	 */
+	if (fp->_bf._base == NULL)
+		__smakebuf(fp);
+	if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT))
+		goto dumb;
+	if ((fp->_flags & __SOPT) == 0) {
+		if (seekfn != __sseek ||
+		    fp->_file < 0 || fstat(fp->_file, &st) ||
+		    (st.st_mode & S_IFMT) != S_IFREG) {
+			fp->_flags |= __SNPT;
+			goto dumb;
+		}
+		fp->_blksize = st.st_blksize;
+		fp->_flags |= __SOPT;
+	}
+
+	/*
+	 * We are reading; we can try to optimise.
+	 * Figure out where we are going and where we are now.
+	 */
+	if (whence == SEEK_SET)
+		target = offset;
+	else {
+		if (fstat(fp->_file, &st))
+			goto dumb;
+		target = st.st_size + offset;
+	}
+
+	if (!havepos) {
+		if (fp->_flags & __SOFF)
+			curoff = fp->_offset;
+		else {
+			curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
+			if (curoff == POS_ERR)
+				goto dumb;
+		}
+		curoff -= fp->_r;
+		if (HASUB(fp))
+			curoff -= fp->_ur;
+	}
+
+	/*
+	 * Compute the number of bytes in the input buffer (pretending
+	 * that any ungetc() input has been discarded).  Adjust current
+	 * offset backwards by this count so that it represents the
+	 * file offset for the first byte in the current input buffer.
+	 */
+	if (HASUB(fp)) {
+		curoff += fp->_r;	/* kill off ungetc */
+		n = fp->_up - fp->_bf._base;
+		curoff -= n;
+		n += fp->_ur;
+	} else {
+		n = fp->_p - fp->_bf._base;
+		curoff -= n;
+		n += fp->_r;
+	}
+
+	/*
+	 * If the target offset is within the current buffer,
+	 * simply adjust the pointers, clear EOF, undo ungetc(),
+	 * and return.  (If the buffer was modified, we have to
+	 * skip this; see fgetln.c.)
+	 */
+	if ((fp->_flags & __SMOD) == 0 &&
+	    target >= curoff && target < curoff + n) {
+		int o = target - curoff;
+
+		fp->_p = fp->_bf._base + o;
+		fp->_r = n - o;
+		if (HASUB(fp))
+			FREEUB(fp);
+		fp->_flags &= ~__SEOF;
+		FUNLOCKFILE(fp);
+		return (0);
+	}
+
+	/*
+	 * The place we want to get to is not within the current buffer,
+	 * but we can still be kind to the kernel copyout mechanism.
+	 * By aligning the file offset to a block boundary, we can let
+	 * the kernel use the VM hardware to map pages instead of
+	 * copying bytes laboriously.  Using a block boundary also
+	 * ensures that we only read one block, rather than two.
+	 */
+	curoff = target & ~(fp->_blksize - 1);
+	if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)
+		goto dumb;
+	fp->_r = 0;
+ 	fp->_p = fp->_bf._base;
+	if (HASUB(fp))
+		FREEUB(fp);
+	fp->_flags &= ~__SEOF;
+	n = target - curoff;
+	if (n) {
+		if (__srefill(fp) || fp->_r < n)
+			goto dumb;
+		fp->_p += n;
+		fp->_r -= n;
+	}
+	FUNLOCKFILE(fp);
+	return (0);
+
+	/*
+	 * We get here if we cannot optimise the seek ... just
+	 * do it.  Allow the seek function to change fp->_bf._base.
+	 */
+dumb:
+	if (__sflush(fp) ||
+	    (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) {
+		FUNLOCKFILE(fp);
+		return (EOF);
+	}
+	/* success: clear EOF indicator and discard ungetc() data */
+	if (HASUB(fp))
+		FREEUB(fp);
+	fp->_p = fp->_bf._base;
+	fp->_r = 0;
+	/* fp->_w = 0; */	/* unnecessary (I think...) */
+	fp->_flags &= ~__SEOF;
+	FUNLOCKFILE(fp);
+	return (0);
+}
+
+int
+fseek(FILE *fp, long offset, int whence)
+{
+	return (fseeko(fp, offset, whence));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c b/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c
new file mode 100644
index 0000000..9624fe5
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c
@@ -0,0 +1,43 @@
+/*	$OpenBSD: fsetpos.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+/*
+ * fsetpos: like fseeko.
+ */
+int
+fsetpos(FILE *iop, const fpos_t *pos)
+{
+	return (fseeko(iop, (off_t)*pos, SEEK_SET));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/ftell.c b/libc/upstream-openbsd/lib/libc/stdio/ftell.c
new file mode 100644
index 0000000..0a2016c
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/ftell.c
@@ -0,0 +1,96 @@
+/*	$OpenBSD: ftell.c,v 1.10 2012/05/21 22:24:19 matthew Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <limits.h>
+#include "local.h"
+
+/*
+ * ftello: return current offset.
+ */
+off_t
+ftello(FILE *fp)
+{
+	fpos_t pos;
+
+	if (fp->_seek == NULL) {
+		errno = ESPIPE;			/* historic practice */
+		pos = -1;
+		goto out;
+	}
+
+	/*
+	 * Find offset of underlying I/O object, then
+	 * adjust for buffered bytes.
+	 */
+	FLOCKFILE(fp);
+	__sflush(fp);		/* may adjust seek offset on append stream */
+	if (fp->_flags & __SOFF)
+		pos = fp->_offset;
+	else {
+		pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
+		if (pos == -1)
+			goto out;
+	}
+	if (fp->_flags & __SRD) {
+		/*
+		 * Reading.  Any unread characters (including
+		 * those from ungetc) cause the position to be
+		 * smaller than that in the underlying object.
+		 */
+		pos -= fp->_r;
+		if (HASUB(fp))
+			pos -= fp->_ur;
+	} else if (fp->_flags & __SWR && fp->_p != NULL) {
+		/*
+		 * Writing.  Any buffered characters cause the
+		 * position to be greater than that in the
+		 * underlying object.
+		 */
+		pos += fp->_p - fp->_bf._base;
+	}
+out:	FUNLOCKFILE(fp);
+	return (pos);
+}
+
+long
+ftell(FILE *fp)
+{
+	off_t offset = ftello(fp);
+	if (offset > LONG_MAX) {
+		errno = EOVERFLOW;
+		return (-1);
+	}
+	return ((long)offset);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/funopen.c b/libc/upstream-openbsd/lib/libc/stdio/funopen.c
new file mode 100644
index 0000000..b85ee96
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/funopen.c
@@ -0,0 +1,68 @@
+/*	$OpenBSD: funopen.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include "local.h"
+
+FILE *
+funopen(const void *cookie, int (*readfn)(void *, char *, int),
+	int (*writefn)(void *, const char *, int),
+	fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *))
+{
+	FILE *fp;
+	int flags;
+
+	if (readfn == NULL) {
+		if (writefn == NULL) {		/* illegal */
+			errno = EINVAL;
+			return (NULL);
+		} else
+			flags = __SWR;		/* write only */
+	} else {
+		if (writefn == NULL)
+			flags = __SRD;		/* read only */
+		else
+			flags = __SRW;		/* read-write */
+	}
+	if ((fp = __sfp()) == NULL)
+		return (NULL);
+	fp->_flags = flags;
+	fp->_file = -1;
+	fp->_cookie = (void *)cookie;		/* SAFE: cookie not modified */
+	fp->_read = readfn;
+	fp->_write = writefn;
+	fp->_seek = seekfn;
+	fp->_close = closefn;
+	return (fp);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fvwrite.c b/libc/upstream-openbsd/lib/libc/stdio/fvwrite.c
new file mode 100644
index 0000000..1088991
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fvwrite.c
@@ -0,0 +1,204 @@
+/*	$OpenBSD: fvwrite.c,v 1.17 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "local.h"
+#include "fvwrite.h"
+
+/*
+ * Write some memory regions.  Return zero on success, EOF on error.
+ *
+ * This routine is large and unsightly, but most of the ugliness due
+ * to the three different kinds of output buffering is handled here.
+ */
+int
+__sfvwrite(FILE *fp, struct __suio *uio)
+{
+	size_t len;
+	char *p;
+	struct __siov *iov;
+	int w, s;
+	char *nl;
+	int nlknown, nldist;
+
+	if ((len = uio->uio_resid) == 0)
+		return (0);
+	/* make sure we can write */
+	if (cantwrite(fp)) {
+		errno = EBADF;
+		return (EOF);
+	}
+
+#define	MIN(a, b) ((a) < (b) ? (a) : (b))
+#define	COPY(n)	  (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n))
+
+	iov = uio->uio_iov;
+	p = iov->iov_base;
+	len = iov->iov_len;
+	iov++;
+#define GETIOV(extra_work) \
+	while (len == 0) { \
+		extra_work; \
+		p = iov->iov_base; \
+		len = iov->iov_len; \
+		iov++; \
+	}
+	if (fp->_flags & __SNBF) {
+		/*
+		 * Unbuffered: write up to BUFSIZ bytes at a time.
+		 */
+		do {
+			GETIOV(;);
+			w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ));
+			if (w <= 0)
+				goto err;
+			p += w;
+			len -= w;
+		} while ((uio->uio_resid -= w) != 0);
+	} else if ((fp->_flags & __SLBF) == 0) {
+		/*
+		 * Fully buffered: fill partially full buffer, if any,
+		 * and then flush.  If there is no partial buffer, write
+		 * one _bf._size byte chunk directly (without copying).
+		 *
+		 * String output is a special case: write as many bytes
+		 * as fit, but pretend we wrote everything.  This makes
+		 * snprintf() return the number of bytes needed, rather
+		 * than the number used, and avoids its write function
+		 * (so that the write function can be invalid).
+		 */
+		do {
+			GETIOV(;);
+			if ((fp->_flags & (__SALC | __SSTR)) ==
+			    (__SALC | __SSTR) && fp->_w < len) {
+				size_t blen = fp->_p - fp->_bf._base;
+				unsigned char *_base;
+				int _size;
+
+				/* Allocate space exponentially. */
+				_size = fp->_bf._size;
+				do {
+					_size = (_size << 1) + 1;
+				} while (_size < blen + len);
+				_base = realloc(fp->_bf._base, _size + 1);
+				if (_base == NULL)
+					goto err;
+				fp->_w += _size - fp->_bf._size;
+				fp->_bf._base = _base;
+				fp->_bf._size = _size;
+				fp->_p = _base + blen;
+			}
+			w = fp->_w;
+			if (fp->_flags & __SSTR) {
+				if (len < w)
+					w = len;
+				COPY(w);	/* copy MIN(fp->_w,len), */
+				fp->_w -= w;
+				fp->_p += w;
+				w = len;	/* but pretend copied all */
+			} else if (fp->_p > fp->_bf._base && len > w) {
+				/* fill and flush */
+				COPY(w);
+				/* fp->_w -= w; */ /* unneeded */
+				fp->_p += w;
+				if (__sflush(fp))
+					goto err;
+			} else if (len >= (w = fp->_bf._size)) {
+				/* write directly */
+				w = (*fp->_write)(fp->_cookie, p, w);
+				if (w <= 0)
+					goto err;
+			} else {
+				/* fill and done */
+				w = len;
+				COPY(w);
+				fp->_w -= w;
+				fp->_p += w;
+			}
+			p += w;
+			len -= w;
+		} while ((uio->uio_resid -= w) != 0);
+	} else {
+		/*
+		 * Line buffered: like fully buffered, but we
+		 * must check for newlines.  Compute the distance
+		 * to the first newline (including the newline),
+		 * or `infinity' if there is none, then pretend
+		 * that the amount to write is MIN(len,nldist).
+		 */
+		nlknown = 0;
+		nldist = 0;	/* XXX just to keep gcc happy */
+		do {
+			GETIOV(nlknown = 0);
+			if (!nlknown) {
+				nl = memchr((void *)p, '\n', len);
+				nldist = nl ? nl + 1 - p : len + 1;
+				nlknown = 1;
+			}
+			s = MIN(len, nldist);
+			w = fp->_w + fp->_bf._size;
+			if (fp->_p > fp->_bf._base && s > w) {
+				COPY(w);
+				/* fp->_w -= w; */
+				fp->_p += w;
+				if (__sflush(fp))
+					goto err;
+			} else if (s >= (w = fp->_bf._size)) {
+				w = (*fp->_write)(fp->_cookie, p, w);
+				if (w <= 0)
+				 	goto err;
+			} else {
+				w = s;
+				COPY(w);
+				fp->_w -= w;
+				fp->_p += w;
+			}
+			if ((nldist -= w) == 0) {
+				/* copied the newline: flush and forget */
+				if (__sflush(fp))
+					goto err;
+				nlknown = 0;
+			}
+			p += w;
+			len -= w;
+		} while ((uio->uio_resid -= w) != 0);
+	}
+	return (0);
+
+err:
+	fp->_flags |= __SERR;
+	return (EOF);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fvwrite.h b/libc/upstream-openbsd/lib/libc/stdio/fvwrite.h
new file mode 100644
index 0000000..d3a309b
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fvwrite.h
@@ -0,0 +1,49 @@
+/*	$OpenBSD: fvwrite.h,v 1.6 2013/11/12 07:04:35 deraadt Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * I/O descriptors for __sfvwrite().
+ */
+struct __siov {
+	void	*iov_base;
+	size_t	iov_len;
+};
+struct __suio {
+	struct	__siov *uio_iov;
+	int	uio_iovcnt;
+	int	uio_resid;
+};
+
+extern int __sfvwrite(FILE *, struct __suio *);
+wint_t __fputwc_unlock(wchar_t wc, FILE *fp);
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fwalk.c b/libc/upstream-openbsd/lib/libc/stdio/fwalk.c
new file mode 100644
index 0000000..8ac6628
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fwalk.c
@@ -0,0 +1,53 @@
+/*	$OpenBSD: fwalk.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include "local.h"
+#include "glue.h"
+
+int
+_fwalk(int (*function)(FILE *))
+{
+	FILE *fp;
+	int n, ret;
+	struct glue *g;
+
+	ret = 0;
+	for (g = &__sglue; g != NULL; g = g->next)
+		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) {
+			if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0))
+				ret |= (*function)(fp);
+		}
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fwide.c b/libc/upstream-openbsd/lib/libc/stdio/fwide.c
new file mode 100644
index 0000000..93cddc6
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fwide.c
@@ -0,0 +1,64 @@
+/*	$OpenBSD: fwide.c,v 1.4 2009/11/09 00:18:27 kurt Exp $	*/
+/* $NetBSD: fwide.c,v 1.2 2003/01/18 11:29:54 thorpej Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <stdio.h>
+#include <wchar.h>
+#include "local.h"
+
+int
+fwide(FILE *fp, int mode)
+{
+	struct wchar_io_data *wcio;
+
+	/*
+	 * this implementation use only -1, 0, 1
+	 * for mode value.
+	 * (we don't need to do this, but
+	 *  this can make things simpler.)
+	 */
+	if (mode > 0)
+		mode = 1;
+	else if (mode < 0)
+		mode = -1;
+
+	FLOCKFILE(fp);
+	wcio = WCIO_GET(fp);
+	if (!wcio)
+		return 0; /* XXX */
+
+	if (wcio->wcio_mode == 0 && mode != 0)
+		wcio->wcio_mode = mode;
+	else
+		mode = wcio->wcio_mode;
+	FUNLOCKFILE(fp);
+
+	return mode;
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fwprintf.c b/libc/upstream-openbsd/lib/libc/stdio/fwprintf.c
new file mode 100644
index 0000000..4474e8b
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fwprintf.c
@@ -0,0 +1,48 @@
+/*	$OpenBSD: fwprintf.c,v 1.3 2011/04/28 17:38:46 stsp Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+
+int
+fwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfwprintf(fp, fmt, ap);
+	va_end(ap);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fwrite.c b/libc/upstream-openbsd/lib/libc/stdio/fwrite.c
new file mode 100644
index 0000000..f0a17bf
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fwrite.c
@@ -0,0 +1,88 @@
+/*	$OpenBSD: fwrite.c,v 1.11 2014/05/01 16:40:36 deraadt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <errno.h>
+#include "local.h"
+#include "fvwrite.h"
+
+#define MUL_NO_OVERFLOW	(1UL << (sizeof(size_t) * 4))
+
+/*
+ * Write `count' objects (each size `size') from memory to the given file.
+ * Return the number of whole objects written.
+ */
+size_t
+fwrite(const void *buf, size_t size, size_t count, FILE *fp)
+{
+	size_t n;
+	struct __suio uio;
+	struct __siov iov;
+	int ret;
+
+	/*
+	 * Extension:  Catch integer overflow
+	 */
+	if ((size >= MUL_NO_OVERFLOW || count >= MUL_NO_OVERFLOW) &&
+	    size > 0 && SIZE_MAX / size < count) {
+		errno = EOVERFLOW;
+		fp->_flags |= __SERR;
+		return (0);
+	}
+
+	/*
+	 * ANSI and SUSv2 require a return value of 0 if size or count are 0.
+	 */
+	if ((n = count * size) == 0)
+		return (0);
+
+	iov.iov_base = (void *)buf;
+	uio.uio_resid = iov.iov_len = n;
+	uio.uio_iov = &iov;
+	uio.uio_iovcnt = 1;
+
+	/*
+	 * The usual case is success (__sfvwrite returns 0);
+	 * skip the divide if this happens, since divides are
+	 * generally slow and since this occurs whenever size==0.
+	 */
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, -1);
+	ret = __sfvwrite(fp, &uio);
+	FUNLOCKFILE(fp);
+	if (ret == 0)
+		return (count);
+	return ((n - uio.uio_resid) / size);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fwscanf.c b/libc/upstream-openbsd/lib/libc/stdio/fwscanf.c
new file mode 100644
index 0000000..b716cbf
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/fwscanf.c
@@ -0,0 +1,44 @@
+/* $OpenBSD: fwscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+fwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
+{
+	va_list ap;
+	int r;
+
+	va_start(ap, fmt);
+	r = vfwscanf(fp, fmt, ap);
+	va_end(ap);
+
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getc.c b/libc/upstream-openbsd/lib/libc/stdio/getc.c
new file mode 100644
index 0000000..6879cbb
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/getc.c
@@ -0,0 +1,62 @@
+/*	$OpenBSD: getc.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro getc_unlocked.
+ */
+#undef getc_unlocked
+
+int
+getc_unlocked(FILE *fp)
+{
+	return (__sgetc(fp));
+}
+
+/*
+ * A subroutine version of the macro getc.
+ */
+#undef getc
+
+int
+getc(FILE *fp)
+{
+	int c;
+
+	FLOCKFILE(fp);
+	c = __sgetc(fp);
+	FUNLOCKFILE(fp);
+	return (c);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getchar.c b/libc/upstream-openbsd/lib/libc/stdio/getchar.c
new file mode 100644
index 0000000..550817d
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/getchar.c
@@ -0,0 +1,58 @@
+/*	$OpenBSD: getchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+/*
+ * A subroutine version of the macro getchar_unlocked.
+ */
+#undef getchar_unlocked
+
+int
+getchar_unlocked(void)
+{
+	return (getc_unlocked(stdin));
+}
+
+
+/*
+ * A subroutine version of the macro getchar.
+ */
+
+#undef getchar
+
+int
+getchar(void)
+{
+	return (getc(stdin));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getdelim.c b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c
new file mode 100644
index 0000000..dcde0c3
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c
@@ -0,0 +1,134 @@
+/*	$OpenBSD: getdelim.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $	*/
+/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roy Marples.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "local.h"
+
+/* Minimum buffer size we create.
+ * This should allow config files to fit into our power of 2 buffer growth
+ * without the need for a realloc. */
+#define MINBUF	128
+
+ssize_t
+getdelim(char **__restrict buf, size_t *__restrict buflen,
+    int sep, FILE *__restrict fp)
+{
+	unsigned char *p;
+	size_t len, newlen, off;
+	char *newb;
+
+	FLOCKFILE(fp);
+
+	if (buf == NULL || buflen == NULL) {
+		errno = EINVAL;
+		goto error;
+	}
+
+	/* If buf is NULL, we have to assume a size of zero */
+	if (*buf == NULL)
+		*buflen = 0;
+
+	_SET_ORIENTATION(fp, -1);
+	off = 0;
+	do {
+		/* If the input buffer is empty, refill it */
+		if (fp->_r <= 0 && __srefill(fp)) {
+			if (__sferror(fp))
+				goto error;
+			/* No error, so EOF. */
+			break;
+		}
+
+		/* Scan through looking for the separator */
+		p = memchr(fp->_p, sep, (size_t)fp->_r);
+		if (p == NULL)
+			len = fp->_r;
+		else
+			len = (p - fp->_p) + 1;
+
+		newlen = off + len;
+		/* Ensure we can handle it */
+		if (newlen < off || newlen > SSIZE_MAX) {
+			errno = EOVERFLOW;
+			goto error;
+		}
+		newlen++; /* reserve space for the NULL terminator */
+		if (newlen > *buflen) {
+			if (newlen < MINBUF)
+				newlen = MINBUF;
+#define powerof2(x) ((((x)-1)&(x))==0)
+			if (!powerof2(newlen)) {
+				/* Grow the buffer to the next power of 2 */
+				newlen--;
+				newlen |= newlen >> 1;
+				newlen |= newlen >> 2;
+				newlen |= newlen >> 4;
+				newlen |= newlen >> 8;
+				newlen |= newlen >> 16;
+#if SIZE_T_MAX > 0xffffffffU
+				newlen |= newlen >> 32;
+#endif
+				newlen++;
+			}
+
+			newb = realloc(*buf, newlen);
+			if (newb == NULL)
+				goto error;
+			*buf = newb;
+			*buflen = newlen;
+		}
+
+		(void)memcpy((*buf + off), fp->_p, len);
+		/* Safe, len is never greater than what fp->_r can fit. */
+		fp->_r -= (int)len;
+		fp->_p += (int)len;
+		off += len;
+	} while (p == NULL);
+
+	FUNLOCKFILE(fp);
+
+	/* POSIX demands we return -1 on EOF. */
+	if (off == 0)
+		return -1;
+
+	if (*buf != NULL)
+		*(*buf + off) = '\0';
+	return off;
+
+error:
+	fp->_flags |= __SERR;
+	FUNLOCKFILE(fp);
+	return -1;
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getline.c b/libc/upstream-openbsd/lib/libc/stdio/getline.c
new file mode 100644
index 0000000..55ad396
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/getline.c
@@ -0,0 +1,37 @@
+/*	$OpenBSD: getline.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $	*/
+/* $NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roy Marples.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+ssize_t
+getline(char **__restrict buf, size_t *__restrict buflen, FILE *__restrict fp)
+{
+	return getdelim(buf, buflen, '\n', fp);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/gets.c b/libc/upstream-openbsd/lib/libc/stdio/gets.c
new file mode 100644
index 0000000..c2e1b50
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/gets.c
@@ -0,0 +1,59 @@
+/*	$OpenBSD: gets.c,v 1.12 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+
+__warn_references(gets,
+    "warning: gets() is very unsafe; consider using fgets()");
+
+char *
+gets(char *buf)
+{
+	int c;
+	char *s;
+
+	FLOCKFILE(stdin);
+	for (s = buf; (c = getchar_unlocked()) != '\n';)
+		if (c == EOF)
+			if (s == buf) {
+				FUNLOCKFILE(stdin);
+				return (NULL);
+			} else
+				break;
+		else
+			*s++ = c;
+	*s = '\0';
+	FUNLOCKFILE(stdin);
+	return (buf);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getwc.c b/libc/upstream-openbsd/lib/libc/stdio/getwc.c
new file mode 100644
index 0000000..e9bbb7c
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/getwc.c
@@ -0,0 +1,45 @@
+/*	$OpenBSD: getwc.c,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
+/* $NetBSD: getwc.c,v 1.2 2003/01/18 11:29:55 thorpej Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+ * A subroutine version of the macro getwc.
+ */
+#undef getwc
+
+wint_t
+getwc(FILE *fp)
+{
+
+	return fgetwc(fp);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getwchar.c b/libc/upstream-openbsd/lib/libc/stdio/getwchar.c
new file mode 100644
index 0000000..2a112ed
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/getwchar.c
@@ -0,0 +1,45 @@
+/*	$OpenBSD: getwchar.c,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
+/* $NetBSD: getwchar.c,v 1.2 2003/01/18 11:29:55 thorpej Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+ * A subroutine version of the macro getwchar.
+ */
+#undef getwchar
+
+wint_t
+getwchar()
+{
+
+	return fgetwc(stdin);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/makebuf.c b/libc/upstream-openbsd/lib/libc/stdio/makebuf.c
new file mode 100644
index 0000000..d47e27c
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/makebuf.c
@@ -0,0 +1,107 @@
+/*	$OpenBSD: makebuf.c,v 1.8 2005/12/28 18:50:22 millert Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "local.h"
+
+/*
+ * Allocate a file buffer, or switch to unbuffered I/O.
+ * Per the ANSI C standard, ALL tty devices default to line buffered.
+ *
+ * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
+ * optimisation) right after the fstat() that finds the buffer size.
+ */
+void
+__smakebuf(FILE *fp)
+{
+	void *p;
+	int flags;
+	size_t size;
+	int couldbetty;
+
+	if (fp->_flags & __SNBF) {
+		fp->_bf._base = fp->_p = fp->_nbuf;
+		fp->_bf._size = 1;
+		return;
+	}
+	flags = __swhatbuf(fp, &size, &couldbetty);
+	if ((p = malloc(size)) == NULL) {
+		fp->_flags |= __SNBF;
+		fp->_bf._base = fp->_p = fp->_nbuf;
+		fp->_bf._size = 1;
+		return;
+	}
+	__atexit_register_cleanup(_cleanup);
+	flags |= __SMBF;
+	fp->_bf._base = fp->_p = p;
+	fp->_bf._size = size;
+	if (couldbetty && isatty(fp->_file))
+		flags |= __SLBF;
+	fp->_flags |= flags;
+}
+
+/*
+ * Internal routine to determine `proper' buffering for a file.
+ */
+int
+__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
+{
+	struct stat st;
+
+	if (fp->_file < 0 || fstat(fp->_file, &st) < 0) {
+		*couldbetty = 0;
+		*bufsize = BUFSIZ;
+		return (__SNPT);
+	}
+
+	/* could be a tty iff it is a character device */
+	*couldbetty = S_ISCHR(st.st_mode);
+	if (st.st_blksize == 0) {
+		*bufsize = BUFSIZ;
+		return (__SNPT);
+	}
+
+	/*
+	 * Optimise fseek() only if it is a regular file.  (The test for
+	 * __sseek is mainly paranoia.)  It is safe to set _blksize
+	 * unconditionally; it will only be used if __SOPT is also set.
+	 */
+	*bufsize = st.st_blksize;
+	fp->_blksize = st.st_blksize;
+	return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ?
+	    __SOPT : __SNPT);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/mktemp.c b/libc/upstream-openbsd/lib/libc/stdio/mktemp.c
new file mode 100644
index 0000000..cb154c4
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/mktemp.c
@@ -0,0 +1,143 @@
+/*	$OpenBSD: mktemp.c,v 1.33 2014/05/06 22:55:27 millert Exp $ */
+/*
+ * Copyright (c) 1996-1998, 2008 Theo de Raadt
+ * Copyright (c) 1997, 2008-2009 Todd C. Miller
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#define MKTEMP_NAME	0
+#define MKTEMP_FILE	1
+#define MKTEMP_DIR	2
+
+#define TEMPCHARS	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
+#define NUM_CHARS	(sizeof(TEMPCHARS) - 1)
+#define MIN_X		6
+
+#ifndef nitems
+#define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
+#endif
+
+static int
+mktemp_internal(char *path, int slen, int mode)
+{
+	char *start, *cp, *ep;
+	const char *tempchars = TEMPCHARS;
+	unsigned int tries;
+	struct stat sb;
+	size_t len;
+	int fd;
+
+	len = strlen(path);
+	if (len < MIN_X || slen < 0 || (size_t)slen > len - MIN_X) {
+		errno = EINVAL;
+		return(-1);
+	}
+	ep = path + len - slen;
+
+	for (start = ep; start > path && start[-1] == 'X'; start--)
+		;
+	if (ep - start < MIN_X) {
+		errno = EINVAL;
+		return(-1);
+	}
+
+	tries = INT_MAX;
+	do {
+		cp = start;
+		do {
+			unsigned short rbuf[16];
+			unsigned int i;
+
+			/*
+			 * Avoid lots of arc4random() calls by using
+			 * a buffer sized for up to 16 Xs at a time.
+			 */
+			arc4random_buf(rbuf, sizeof(rbuf));
+			for (i = 0; i < nitems(rbuf) && cp != ep; i++)
+				*cp++ = tempchars[rbuf[i] % NUM_CHARS];
+		} while (cp != ep);
+
+		switch (mode) {
+		case MKTEMP_NAME:
+			if (lstat(path, &sb) != 0)
+				return(errno == ENOENT ? 0 : -1);
+			break;
+		case MKTEMP_FILE:
+			fd = open(path, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR);
+			if (fd != -1 || errno != EEXIST)
+				return(fd);
+			break;
+		case MKTEMP_DIR:
+			if (mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR) == 0)
+				return(0);
+			if (errno != EEXIST)
+				return(-1);
+			break;
+		}
+	} while (--tries);
+
+	errno = EEXIST;
+	return(-1);
+}
+
+char *_mktemp(char *);
+
+char *
+_mktemp(char *path)
+{
+	if (mktemp_internal(path, 0, MKTEMP_NAME) == -1)
+		return(NULL);
+	return(path);
+}
+
+__warn_references(mktemp,
+    "warning: mktemp() possibly used unsafely; consider using mkstemp()");
+
+char *
+mktemp(char *path)
+{
+	return(_mktemp(path));
+}
+
+int
+mkstemp(char *path)
+{
+	return(mktemp_internal(path, 0, MKTEMP_FILE));
+}
+
+int
+mkstemps(char *path, int slen)
+{
+	return(mktemp_internal(path, slen, MKTEMP_FILE));
+}
+
+char *
+mkdtemp(char *path)
+{
+	int error;
+
+	error = mktemp_internal(path, 0, MKTEMP_DIR);
+	return(error ? NULL : path);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/perror.c b/libc/upstream-openbsd/lib/libc/stdio/perror.c
new file mode 100644
index 0000000..8728718
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/perror.c
@@ -0,0 +1,62 @@
+/*	$OpenBSD: perror.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
+/*
+ * Copyright (c) 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+
+void
+perror(const char *s)
+{
+	struct iovec *v;
+	struct iovec iov[4];
+	char buf[NL_TEXTMAX];
+
+	v = iov;
+	if (s && *s) {
+		v->iov_base = (char *)s;
+		v->iov_len = strlen(s);
+		v++;
+		v->iov_base = ": ";
+		v->iov_len = 2;
+		v++;
+	}
+	(void)strerror_r(errno, buf, sizeof(buf));
+	v->iov_base = buf;
+	v->iov_len = strlen(v->iov_base);
+	v++;
+	v->iov_base = "\n";
+	v->iov_len = 1;
+	(void)writev(STDERR_FILENO, iov, (v - iov) + 1);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/printf.c b/libc/upstream-openbsd/lib/libc/stdio/printf.c
new file mode 100644
index 0000000..09bb3d7
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/printf.c
@@ -0,0 +1,48 @@
+/*	$OpenBSD: printf.c,v 1.8 2011/05/30 18:48:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+/* PRINTFLIKE1 */
+int
+printf(const char *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfprintf(stdout, fmt, ap);
+	va_end(ap);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putc.c b/libc/upstream-openbsd/lib/libc/stdio/putc.c
new file mode 100644
index 0000000..762fecb
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/putc.c
@@ -0,0 +1,68 @@
+/*	$OpenBSD: putc.c,v 1.12 2009/11/21 10:11:54 guenther Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro putc_unlocked.
+ */
+#undef putc_unlocked
+
+int
+putc_unlocked(int c, FILE *fp)
+{
+	if (cantwrite(fp)) {
+		errno = EBADF;
+		return (EOF);
+	}
+	_SET_ORIENTATION(fp, -1);
+	return (__sputc(c, fp));
+}
+
+/*
+ * A subroutine version of the macro putc.
+ */
+#undef putc
+
+int
+putc(int c, FILE *fp)
+{
+	int ret;
+
+	FLOCKFILE(fp);
+	ret = putc_unlocked(c, fp);
+	FUNLOCKFILE(fp);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putchar.c b/libc/upstream-openbsd/lib/libc/stdio/putchar.c
new file mode 100644
index 0000000..233cdfd
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/putchar.c
@@ -0,0 +1,59 @@
+/*	$OpenBSD: putchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#undef putchar_unlocked
+/*
+ * A subrouting version of the macro putchar_unlocked
+ */
+int
+putchar_unlocked(int c)
+{
+	FILE *so = stdout;
+
+	return (putc_unlocked(c,so));
+}
+
+#undef putchar
+
+/*
+ * A subroutine version of the macro putchar
+ */
+int
+putchar(int c)
+{
+	FILE *so = stdout;
+
+	return (putc(c, so));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/puts.c b/libc/upstream-openbsd/lib/libc/stdio/puts.c
new file mode 100644
index 0000000..655aed7
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/puts.c
@@ -0,0 +1,62 @@
+/*	$OpenBSD: puts.c,v 1.11 2009/11/21 09:53:44 guenther Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "local.h"
+#include "fvwrite.h"
+
+/*
+ * Write the given string to stdout, appending a newline.
+ */
+int
+puts(const char *s)
+{
+	size_t c = strlen(s);
+	struct __suio uio;
+	struct __siov iov[2];
+	int ret;
+
+	iov[0].iov_base = (void *)s;
+	iov[0].iov_len = c;
+	iov[1].iov_base = "\n";
+	iov[1].iov_len = 1;
+	uio.uio_resid = c + 1;
+	uio.uio_iov = &iov[0];
+	uio.uio_iovcnt = 2;
+	FLOCKFILE(stdout);
+	_SET_ORIENTATION(stdout, -1);
+	ret = __sfvwrite(stdout, &uio);
+	FUNLOCKFILE(stdout);
+	return (ret ? EOF : '\n');
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putw.c b/libc/upstream-openbsd/lib/libc/stdio/putw.c
new file mode 100644
index 0000000..47941a4
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/putw.c
@@ -0,0 +1,54 @@
+/*	$OpenBSD: putw.c,v 1.10 2009/11/21 09:53:44 guenther Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+#include "fvwrite.h"
+
+int
+putw(int w, FILE *fp)
+{
+	struct __suio uio;
+	struct __siov iov;
+	int ret;
+
+	iov.iov_base = &w;
+	iov.iov_len = uio.uio_resid = sizeof(w);
+	uio.uio_iov = &iov;
+	uio.uio_iovcnt = 1;
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, -1);
+	ret = __sfvwrite(fp, &uio);
+	FUNLOCKFILE(fp);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putwc.c b/libc/upstream-openbsd/lib/libc/stdio/putwc.c
new file mode 100644
index 0000000..8e2ff2d
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/putwc.c
@@ -0,0 +1,45 @@
+/*	$OpenBSD: putwc.c,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
+/* $NetBSD: putwc.c,v 1.3 2003/01/18 11:29:56 thorpej Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+ * A subroutine version of the macro putwc.
+ */
+#undef putwc
+
+wint_t
+putwc(wchar_t wc, FILE *fp)
+{
+
+	return fputwc(wc, fp);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putwchar.c b/libc/upstream-openbsd/lib/libc/stdio/putwchar.c
new file mode 100644
index 0000000..940ec05
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/putwchar.c
@@ -0,0 +1,45 @@
+/*	$OpenBSD: putwchar.c,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
+/* $NetBSD: putwchar.c,v 1.3 2003/01/18 11:29:56 thorpej Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+ * A subroutine version of the macro putwchar.
+ */
+#undef putwchar
+
+wint_t
+putwchar(wchar_t wc)
+{
+
+	return fputwc(wc, stdout);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/refill.c b/libc/upstream-openbsd/lib/libc/stdio/refill.c
new file mode 100644
index 0000000..165c72a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/refill.c
@@ -0,0 +1,128 @@
+/*	$OpenBSD: refill.c,v 1.11 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "local.h"
+
+static int
+lflush(FILE *fp)
+{
+	if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
+		return (__sflush_locked(fp));	/* ignored... */
+	return (0);
+}
+
+/*
+ * Refill a stdio buffer.
+ * Return EOF on eof or error, 0 otherwise.
+ */
+int
+__srefill(FILE *fp)
+{
+
+	/* make sure stdio is set up */
+	if (!__sdidinit)
+		__sinit();
+
+	fp->_r = 0;		/* largely a convenience for callers */
+
+	/* SysV does not make this test; take it out for compatibility */
+	if (fp->_flags & __SEOF)
+		return (EOF);
+
+	/* if not already reading, have to be reading and writing */
+	if ((fp->_flags & __SRD) == 0) {
+		if ((fp->_flags & __SRW) == 0) {
+			errno = EBADF;
+			fp->_flags |= __SERR;
+			return (EOF);
+		}
+		/* switch to reading */
+		if (fp->_flags & __SWR) {
+			if (__sflush(fp))
+				return (EOF);
+			fp->_flags &= ~__SWR;
+			fp->_w = 0;
+			fp->_lbfsize = 0;
+		}
+		fp->_flags |= __SRD;
+	} else {
+		/*
+		 * We were reading.  If there is an ungetc buffer,
+		 * we must have been reading from that.  Drop it,
+		 * restoring the previous buffer (if any).  If there
+		 * is anything in that buffer, return.
+		 */
+		if (HASUB(fp)) {
+			FREEUB(fp);
+			if ((fp->_r = fp->_ur) != 0) {
+				fp->_p = fp->_up;
+				return (0);
+			}
+		}
+	}
+
+	if (fp->_bf._base == NULL)
+		__smakebuf(fp);
+
+	/*
+	 * Before reading from a line buffered or unbuffered file,
+	 * flush all line buffered output files, per the ANSI C
+	 * standard.
+	 */
+	if (fp->_flags & (__SLBF|__SNBF)) {
+		/* Ignore this file in _fwalk to avoid potential deadlock. */
+		fp->_flags |= __SIGN;
+		(void) _fwalk(lflush);
+		fp->_flags &= ~__SIGN;
+
+		/* Now flush this file without locking it. */
+		if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
+			__sflush(fp);
+	}
+	fp->_p = fp->_bf._base;
+	fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size);
+	fp->_flags &= ~__SMOD;	/* buffer contents are again pristine */
+	if (fp->_r <= 0) {
+		if (fp->_r == 0)
+			fp->_flags |= __SEOF;
+		else {
+			fp->_r = 0;
+			fp->_flags |= __SERR;
+		}
+		return (EOF);
+	}
+	return (0);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/remove.c b/libc/upstream-openbsd/lib/libc/stdio/remove.c
new file mode 100644
index 0000000..d09d76f
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/remove.c
@@ -0,0 +1,49 @@
+/*	$OpenBSD: remove.c,v 1.7 2005/08/08 08:05:36 espie Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+int
+remove(const char *file)
+{
+	struct stat st;
+
+	if (lstat(file, &st) < 0)
+		return (-1);
+	if (S_ISDIR(st.st_mode))
+		return (rmdir(file));
+	return (unlink(file));
+}
diff --git a/libc/stdio/rewind.c b/libc/upstream-openbsd/lib/libc/stdio/rewind.c
similarity index 100%
rename from libc/stdio/rewind.c
rename to libc/upstream-openbsd/lib/libc/stdio/rewind.c
diff --git a/libc/upstream-openbsd/lib/libc/stdio/rget.c b/libc/upstream-openbsd/lib/libc/stdio/rget.c
new file mode 100644
index 0000000..4cd97cb
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/rget.c
@@ -0,0 +1,51 @@
+/*	$OpenBSD: rget.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+
+/*
+ * Handle getc() when the buffer ran out:
+ * Refill, then return the first character
+ * in the newly-filled buffer.
+ */
+int
+__srget(FILE *fp)
+{
+	_SET_ORIENTATION(fp, -1);
+	if (__srefill(fp) == 0) {
+		fp->_r--;
+		return (*fp->_p++);
+	}
+	return (EOF);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/scanf.c b/libc/upstream-openbsd/lib/libc/stdio/scanf.c
new file mode 100644
index 0000000..90cf12a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/scanf.c
@@ -0,0 +1,48 @@
+/*	$OpenBSD: scanf.c,v 1.10 2011/05/30 18:48:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+/* SCANFLIKE1 */
+int
+scanf(const char *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfscanf(stdin, fmt, ap);
+	va_end(ap);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/setbuf.c b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c
new file mode 100644
index 0000000..883b895
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c
@@ -0,0 +1,41 @@
+/*	$OpenBSD: setbuf.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "local.h"
+
+void
+setbuf(FILE *fp, char *buf)
+{
+	(void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c b/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c
new file mode 100644
index 0000000..8725ff7
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c
@@ -0,0 +1,51 @@
+/*	$OpenBSD: setbuffer.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+void
+setbuffer(FILE *fp, char *buf, int size)
+{
+
+	(void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size);
+}
+
+/*
+ * set line buffering
+ */
+int
+setlinebuf(FILE *fp)
+{
+
+	return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c b/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
new file mode 100644
index 0000000..6c49f7a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
@@ -0,0 +1,154 @@
+/*	$OpenBSD: setvbuf.c,v 1.11 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "local.h"
+
+/*
+ * Set one of the three kinds of buffering, optionally including
+ * a buffer.
+ */
+int
+setvbuf(FILE *fp, char *buf, int mode, size_t size)
+{
+	int ret, flags;
+	size_t iosize;
+	int ttyflag;
+
+	/*
+	 * Verify arguments.  The `int' limit on `size' is due to this
+	 * particular implementation.  Note, buf and size are ignored
+	 * when setting _IONBF.
+	 */
+	if (mode != _IONBF)
+		if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0)
+			return (EOF);
+
+	/*
+	 * Write current buffer, if any.  Discard unread input (including
+	 * ungetc data), cancel line buffering, and free old buffer if
+	 * malloc()ed.  We also clear any eof condition, as if this were
+	 * a seek.
+	 */
+	FLOCKFILE(fp);
+	ret = 0;
+	(void)__sflush(fp);
+	if (HASUB(fp))
+		FREEUB(fp);
+	WCIO_FREE(fp);
+	fp->_r = fp->_lbfsize = 0;
+	flags = fp->_flags;
+	if (flags & __SMBF)
+		free((void *)fp->_bf._base);
+	flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF);
+
+	/* If setting unbuffered mode, skip all the hard work. */
+	if (mode == _IONBF)
+		goto nbf;
+
+	/*
+	 * Find optimal I/O size for seek optimization.  This also returns
+	 * a `tty flag' to suggest that we check isatty(fd), but we do not
+	 * care since our caller told us how to buffer.
+	 */
+	flags |= __swhatbuf(fp, &iosize, &ttyflag);
+	if (size == 0) {
+		buf = NULL;	/* force local allocation */
+		size = iosize;
+	}
+
+	/* Allocate buffer if needed. */
+	if (buf == NULL) {
+		if ((buf = malloc(size)) == NULL) {
+			/*
+			 * Unable to honor user's request.  We will return
+			 * failure, but try again with file system size.
+			 */
+			ret = EOF;
+			if (size != iosize) {
+				size = iosize;
+				buf = malloc(size);
+			}
+		}
+		if (buf == NULL) {
+			/* No luck; switch to unbuffered I/O. */
+nbf:
+			fp->_flags = flags | __SNBF;
+			fp->_w = 0;
+			fp->_bf._base = fp->_p = fp->_nbuf;
+			fp->_bf._size = 1;
+			FUNLOCKFILE(fp);
+			return (ret);
+		}
+		flags |= __SMBF;
+	}
+
+	/*
+	 * Kill any seek optimization if the buffer is not the
+	 * right size.
+	 *
+	 * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)?
+	 */
+	if (size != iosize)
+		flags |= __SNPT;
+
+	/*
+	 * Fix up the FILE fields, and set __cleanup for output flush on
+	 * exit (since we are buffered in some way).
+	 */
+	if (mode == _IOLBF)
+		flags |= __SLBF;
+	fp->_flags = flags;
+	fp->_bf._base = fp->_p = (unsigned char *)buf;
+	fp->_bf._size = size;
+	/* fp->_lbfsize is still 0 */
+	if (flags & __SWR) {
+		/*
+		 * Begin or continue writing: see __swsetup().  Note
+		 * that __SNBF is impossible (it was handled earlier).
+		 */
+		if (flags & __SLBF) {
+			fp->_w = 0;
+			fp->_lbfsize = -fp->_bf._size;
+		} else
+			fp->_w = size;
+	} else {
+		/* begin/continue reading, or stay in intermediate state */
+		fp->_w = 0;
+	}
+	FUNLOCKFILE(fp);
+	__atexit_register_cleanup(_cleanup);
+
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/sscanf.c b/libc/upstream-openbsd/lib/libc/stdio/sscanf.c
new file mode 100644
index 0000000..e371ca6
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/sscanf.c
@@ -0,0 +1,66 @@
+/*	$OpenBSD: sscanf.c,v 1.14 2011/11/08 18:30:42 guenther Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include "local.h"
+
+/* ARGSUSED */
+static int
+eofread(void *cookie, char *buf, int len)
+{
+
+	return (0);
+}
+
+/* SCANFLIKE2 */
+int
+sscanf(const char *str, const char *fmt, ...)
+{
+	int ret;
+	va_list ap;
+	FILE f;
+	struct __sfileext fext;
+
+	_FILEEXT_SETUP(&f, &fext);
+	f._flags = __SRD;
+	f._bf._base = f._p = (unsigned char *)str;
+	f._bf._size = f._r = strlen(str);
+	f._read = eofread;
+	f._lb._base = NULL;
+	va_start(ap, fmt);
+	ret = __svfscanf(&f, fmt, ap);
+	va_end(ap);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/stdio.c b/libc/upstream-openbsd/lib/libc/stdio/stdio.c
new file mode 100644
index 0000000..a4a27b5
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/stdio.c
@@ -0,0 +1,89 @@
+/*	$OpenBSD: stdio.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "local.h"
+
+/*
+ * Small standard I/O/seek/close functions.
+ * These maintain the `known seek offset' for seek optimisation.
+ */
+int
+__sread(void *cookie, char *buf, int n)
+{
+	FILE *fp = cookie;
+	int ret;
+	
+	ret = read(fp->_file, buf, n);
+	/* if the read succeeded, update the current offset */
+	if (ret >= 0)
+		fp->_offset += ret;
+	else
+		fp->_flags &= ~__SOFF;	/* paranoia */
+	return (ret);
+}
+
+int
+__swrite(void *cookie, const char *buf, int n)
+{
+	FILE *fp = cookie;
+
+	if (fp->_flags & __SAPP)
+		(void) lseek(fp->_file, (off_t)0, SEEK_END);
+	fp->_flags &= ~__SOFF;	/* in case FAPPEND mode is set */
+	return (write(fp->_file, buf, n));
+}
+
+fpos_t
+__sseek(void *cookie, fpos_t offset, int whence)
+{
+	FILE *fp = cookie;
+	off_t ret;
+	
+	ret = lseek(fp->_file, (off_t)offset, whence);
+	if (ret == (off_t)-1)
+		fp->_flags &= ~__SOFF;
+	else {
+		fp->_flags |= __SOFF;
+		fp->_offset = ret;
+	}
+	return (ret);
+}
+
+int
+__sclose(void *cookie)
+{
+	return (close(((FILE *)cookie)->_file));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/swprintf.c b/libc/upstream-openbsd/lib/libc/stdio/swprintf.c
new file mode 100644
index 0000000..8928aea
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/swprintf.c
@@ -0,0 +1,45 @@
+/*	$OpenBSD: swprintf.c,v 1.5 2012/12/05 23:20:01 deraadt Exp $ */
+/*	$NetBSD: swprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vswprintf(s, n, fmt, ap);
+	va_end(ap);
+
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/swscanf.c b/libc/upstream-openbsd/lib/libc/stdio/swscanf.c
new file mode 100644
index 0000000..a85e9ee
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/swscanf.c
@@ -0,0 +1,44 @@
+/* $OpenBSD: swscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+swscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, ...)
+{
+	va_list ap;
+	int r;
+
+	va_start(ap, fmt);
+	r = vswscanf(str, fmt, ap);
+	va_end(ap);
+
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/tempnam.c b/libc/upstream-openbsd/lib/libc/stdio/tempnam.c
new file mode 100644
index 0000000..e3f2ab6
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/tempnam.c
@@ -0,0 +1,101 @@
+/*	$OpenBSD: tempnam.c,v 1.17 2013/09/30 12:02:35 millert Exp $ */
+/*
+ * Copyright (c) 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+__warn_references(tempnam,
+    "warning: tempnam() possibly used unsafely; consider using mkstemp()");
+
+extern char *_mktemp(char *);
+
+char *
+tempnam(const char *dir, const char *pfx)
+{
+	int sverrno, len;
+	char *f, *name;
+
+	if (!(name = malloc(PATH_MAX)))
+		return(NULL);
+
+	if (!pfx)
+		pfx = "tmp.";
+
+	if (issetugid() == 0 && (f = getenv("TMPDIR")) && *f != '\0') {
+		len = snprintf(name, PATH_MAX, "%s%s%sXXXXXXXXXX", f,
+		    f[strlen(f) - 1] == '/' ? "" : "/", pfx);
+		if (len < 0 || len >= PATH_MAX) {
+			errno = ENAMETOOLONG;
+			return(NULL);
+		}
+		if ((f = _mktemp(name)))
+			return(f);
+	}
+
+	if (dir != NULL) {
+		f = *dir ? (char *)dir : ".";
+		len = snprintf(name, PATH_MAX, "%s%s%sXXXXXXXXXX", f,
+		    f[strlen(f) - 1] == '/' ? "" : "/", pfx);
+		if (len < 0 || len >= PATH_MAX) {
+			errno = ENAMETOOLONG;
+			return(NULL);
+		}
+		if ((f = _mktemp(name)))
+			return(f);
+	}
+
+	f = P_tmpdir;
+	len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx);
+	if (len < 0 || len >= PATH_MAX) {
+		errno = ENAMETOOLONG;
+		return(NULL);
+	}
+	if ((f = _mktemp(name)))
+		return(f);
+
+	f = _PATH_TMP;
+	len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx);
+	if (len < 0 || len >= PATH_MAX) {
+		errno = ENAMETOOLONG;
+		return(NULL);
+	}
+	if ((f = _mktemp(name)))
+		return(f);
+
+	sverrno = errno;
+	free(name);
+	errno = sverrno;
+	return(NULL);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/tmpnam.c b/libc/upstream-openbsd/lib/libc/stdio/tmpnam.c
new file mode 100644
index 0000000..32e0a22
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/tmpnam.c
@@ -0,0 +1,55 @@
+/*	$OpenBSD: tmpnam.c,v 1.10 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <unistd.h>
+
+__warn_references(tmpnam,
+    "warning: tmpnam() possibly used unsafely; consider using mkstemp()");
+
+extern char *_mktemp(char *);
+
+char *
+tmpnam(char *s)
+{
+	static u_long tmpcount;
+	static char buf[L_tmpnam];
+
+	if (s == NULL)
+		s = buf;
+	(void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXXXXX", P_tmpdir, tmpcount);
+	++tmpcount;
+	return (_mktemp(s));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/ungetc.c b/libc/upstream-openbsd/lib/libc/stdio/ungetc.c
new file mode 100644
index 0000000..675733a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/ungetc.c
@@ -0,0 +1,145 @@
+/*	$OpenBSD: ungetc.c,v 1.12 2009/11/09 00:18:27 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "local.h"
+
+static int __submore(FILE *);
+/*
+ * Expand the ungetc buffer `in place'.  That is, adjust fp->_p when
+ * the buffer moves, so that it points the same distance from the end,
+ * and move the bytes in the buffer around as necessary so that they
+ * are all at the end (stack-style).
+ */
+static int
+__submore(FILE *fp)
+{
+	int i;
+	unsigned char *p;
+
+	if (_UB(fp)._base == fp->_ubuf) {
+		/*
+		 * Get a new buffer (rather than expanding the old one).
+		 */
+		if ((p = malloc((size_t)BUFSIZ)) == NULL)
+			return (EOF);
+		_UB(fp)._base = p;
+		_UB(fp)._size = BUFSIZ;
+		p += BUFSIZ - sizeof(fp->_ubuf);
+		for (i = sizeof(fp->_ubuf); --i >= 0;)
+			p[i] = fp->_ubuf[i];
+		fp->_p = p;
+		return (0);
+	}
+	i = _UB(fp)._size;
+	p = realloc(_UB(fp)._base, i << 1);
+	if (p == NULL)
+		return (EOF);
+	/* no overlap (hence can use memcpy) because we doubled the size */
+	(void)memcpy((void *)(p + i), (void *)p, (size_t)i);
+	fp->_p = p + i;
+	_UB(fp)._base = p;
+	_UB(fp)._size = i << 1;
+	return (0);
+}
+
+int
+ungetc(int c, FILE *fp)
+{
+	if (c == EOF)
+		return (EOF);
+	if (!__sdidinit)
+		__sinit();
+	FLOCKFILE(fp);
+	_SET_ORIENTATION(fp, -1);
+	if ((fp->_flags & __SRD) == 0) {
+		/*
+		 * Not already reading: no good unless reading-and-writing.
+		 * Otherwise, flush any current write stuff.
+		 */
+		if ((fp->_flags & __SRW) == 0) {
+error:			FUNLOCKFILE(fp);
+			return (EOF);
+		}
+		if (fp->_flags & __SWR) {
+			if (__sflush(fp))
+				goto error;
+			fp->_flags &= ~__SWR;
+			fp->_w = 0;
+			fp->_lbfsize = 0;
+		}
+		fp->_flags |= __SRD;
+	}
+	c = (unsigned char)c;
+
+	/*
+	 * If we are in the middle of ungetc'ing, just continue.
+	 * This may require expanding the current ungetc buffer.
+	 */
+	if (HASUB(fp)) {
+		if (fp->_r >= _UB(fp)._size && __submore(fp))
+			goto error;
+		*--fp->_p = c;
+inc_ret:	fp->_r++;
+		FUNLOCKFILE(fp);
+		return (c);
+	}
+	fp->_flags &= ~__SEOF;
+
+	/*
+	 * If we can handle this by simply backing up, do so,
+	 * but never replace the original character.
+	 * (This makes sscanf() work when scanning `const' data.)
+	 */
+	if (fp->_bf._base != NULL && fp->_p > fp->_bf._base &&
+	    fp->_p[-1] == c) {
+		fp->_p--;
+		goto inc_ret;
+	}
+
+	/*
+	 * Create an ungetc buffer.
+	 * Initially, we will use the `reserve' buffer.
+	 */
+	fp->_ur = fp->_r;
+	fp->_up = fp->_p;
+	_UB(fp)._base = fp->_ubuf;
+	_UB(fp)._size = sizeof(fp->_ubuf);
+	fp->_ubuf[sizeof(fp->_ubuf) - 1] = c;
+	fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1];
+	fp->_r = 1;
+	FUNLOCKFILE(fp);
+	return (c);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/ungetwc.c b/libc/upstream-openbsd/lib/libc/stdio/ungetwc.c
new file mode 100644
index 0000000..c0321e9
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/ungetwc.c
@@ -0,0 +1,77 @@
+/*	$OpenBSD: ungetwc.c,v 1.5 2011/10/16 13:20:51 stsp Exp $	*/
+/* $NetBSD: ungetwc.c,v 1.2 2003/01/18 11:29:59 thorpej Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "local.h"
+
+wint_t
+__ungetwc(wint_t wc, FILE *fp)
+{
+	struct wchar_io_data *wcio;
+
+	if (wc == WEOF)
+		return WEOF;
+
+	_SET_ORIENTATION(fp, 1);
+	/*
+	 * XXX since we have no way to transform a wchar string to
+	 * a char string in reverse order, we can't use ungetc.
+	 */
+	/* XXX should we flush ungetc buffer? */
+
+	wcio = WCIO_GET(fp);
+	if (wcio == 0) {
+		errno = ENOMEM; /* XXX */
+		return WEOF;
+	}
+
+	if (wcio->wcio_ungetwc_inbuf >= WCIO_UNGETWC_BUFSIZE) {
+		return WEOF;
+	}
+
+	wcio->wcio_ungetwc_buf[wcio->wcio_ungetwc_inbuf++] = wc;
+	__sclearerr(fp);
+
+	return wc;
+}
+
+wint_t
+ungetwc(wint_t wc, FILE *fp)
+{
+	wint_t r;
+
+	FLOCKFILE(fp);
+	r = __ungetwc(wc, fp);
+	FUNLOCKFILE(fp);
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c
new file mode 100644
index 0000000..8fe7c5b
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c
@@ -0,0 +1,58 @@
+/*	$OpenBSD: vasprintf.c,v 1.16 2009/11/09 00:18:27 kurt Exp $	*/
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "local.h"
+
+int
+vasprintf(char **str, const char *fmt, __va_list ap)
+{
+	int ret;
+	FILE f;
+	struct __sfileext fext;
+	unsigned char *_base;
+
+	_FILEEXT_SETUP(&f, &fext);
+	f._file = -1;
+	f._flags = __SWR | __SSTR | __SALC;
+	f._bf._base = f._p = (unsigned char *)malloc(128);
+	if (f._bf._base == NULL)
+		goto err;
+	f._bf._size = f._w = 127;		/* Leave room for the NUL */
+	ret = __vfprintf(&f, fmt, ap);
+	if (ret == -1)
+		goto err;
+	*f._p = '\0';
+	_base = realloc(f._bf._base, ret + 1);
+	if (_base == NULL)
+		goto err;
+	*str = (char *)_base;
+	return (ret);
+
+err:
+	if (f._bf._base) {
+		free(f._bf._base);
+		f._bf._base = NULL;
+	}
+	*str = NULL;
+	errno = ENOMEM;
+	return (-1);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vdprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vdprintf.c
new file mode 100644
index 0000000..49c1969
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vdprintf.c
@@ -0,0 +1,73 @@
+/*	$OpenBSD: vdprintf.c,v 1.1 2013/01/30 00:08:13 brad Exp $	*/
+/*	$FreeBSD: src/lib/libc/stdio/vdprintf.c,v 1.4 2012/11/17 01:49:40 svnexp Exp $ */
+
+/*-
+ * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Copyright (c) 2011 The FreeBSD Foundation
+ * All rights reserved.
+ * Portions of this software were developed by David Chisnall
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "local.h"
+
+static int
+__dwrite(void *cookie, const char *buf, int n)
+{
+	int *fdp = cookie;
+	return (write(*fdp, buf, n));
+}
+
+int
+vdprintf(int fd, const char * __restrict fmt, va_list ap)
+{
+	FILE f;
+	struct __sfileext fext;
+	unsigned char buf[BUFSIZ];
+	int ret;
+
+	_FILEEXT_SETUP(&f, &fext);
+
+	f._p = buf;
+	f._w = sizeof(buf);
+	f._flags = __SWR;
+	f._file = -1;
+	f._bf._base = buf;
+	f._bf._size = sizeof(buf);
+	f._cookie = &fd;
+	f._write = __dwrite;
+
+	if ((ret = __vfprintf(&f, fmt, ap)) < 0)
+		return ret;
+
+	return fflush(&f) ? EOF : ret;
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c
new file mode 100644
index 0000000..7f8ff31
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c
@@ -0,0 +1,1555 @@
+/*	$OpenBSD: vfprintf.c,v 1.66 2014/05/03 12:36:45 deraadt Exp $	*/
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Actual printf innards.
+ *
+ * This code is large and complicated...
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include <errno.h>
+#include <langinfo.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <wchar.h>
+
+#include "local.h"
+#include "fvwrite.h"
+
+union arg {
+	int			intarg;
+	unsigned int		uintarg;
+	long			longarg;
+	unsigned long		ulongarg;
+	long long		longlongarg;
+	unsigned long long	ulonglongarg;
+	ptrdiff_t		ptrdiffarg;
+	size_t			sizearg;
+	ssize_t			ssizearg;
+	intmax_t		intmaxarg;
+	uintmax_t		uintmaxarg;
+	void			*pvoidarg;
+	char			*pchararg;
+	signed char		*pschararg;
+	short			*pshortarg;
+	int			*pintarg;
+	long			*plongarg;
+	long long		*plonglongarg;
+	ptrdiff_t		*pptrdiffarg;
+	ssize_t			*pssizearg;
+	intmax_t		*pintmaxarg;
+#ifdef FLOATING_POINT
+	double			doublearg;
+	long double		longdoublearg;
+#endif
+#ifdef PRINTF_WIDE_CHAR
+	wint_t			wintarg;
+	wchar_t			*pwchararg;
+#endif
+};
+
+static int __find_arguments(const char *fmt0, va_list ap, union arg **argtable,
+    size_t *argtablesiz);
+static int __grow_type_table(unsigned char **typetable, int *tablesize);
+
+/*
+ * Flush out all the vectors defined by the given uio,
+ * then reset it so that it can be reused.
+ */
+static int
+__sprint(FILE *fp, struct __suio *uio)
+{
+	int err;
+
+	if (uio->uio_resid == 0) {
+		uio->uio_iovcnt = 0;
+		return (0);
+	}
+	err = __sfvwrite(fp, uio);
+	uio->uio_resid = 0;
+	uio->uio_iovcnt = 0;
+	return (err);
+}
+
+/*
+ * Helper function for `fprintf to unbuffered unix file': creates a
+ * temporary buffer.  We only work on write-only files; this avoids
+ * worries about ungetc buffers and so forth.
+ */
+static int
+__sbprintf(FILE *fp, const char *fmt, va_list ap)
+{
+	int ret;
+	FILE fake;
+	struct __sfileext fakeext;
+	unsigned char buf[BUFSIZ];
+
+	_FILEEXT_SETUP(&fake, &fakeext);
+	/* copy the important variables */
+	fake._flags = fp->_flags & ~__SNBF;
+	fake._file = fp->_file;
+	fake._cookie = fp->_cookie;
+	fake._write = fp->_write;
+
+	/* set up the buffer */
+	fake._bf._base = fake._p = buf;
+	fake._bf._size = fake._w = sizeof(buf);
+	fake._lbfsize = 0;	/* not actually used, but Just In Case */
+
+	/* do the work, then copy any error status */
+	ret = __vfprintf(&fake, fmt, ap);
+	if (ret >= 0 && __sflush(&fake))
+		ret = EOF;
+	if (fake._flags & __SERR)
+		fp->_flags |= __SERR;
+	return (ret);
+}
+
+#ifdef PRINTF_WIDE_CHAR
+/*
+ * Convert a wide character string argument for the %ls format to a multibyte
+ * string representation. If not -1, prec specifies the maximum number of
+ * bytes to output, and also means that we can't assume that the wide char
+ * string is null-terminated.
+ */
+static char *
+__wcsconv(wchar_t *wcsarg, int prec)
+{
+	mbstate_t mbs;
+	char buf[MB_LEN_MAX];
+	wchar_t *p;
+	char *convbuf;
+	size_t clen, nbytes;
+
+	/* Allocate space for the maximum number of bytes we could output. */
+	if (prec < 0) {
+		memset(&mbs, 0, sizeof(mbs));
+		p = wcsarg;
+		nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs);
+		if (nbytes == (size_t)-1) {
+			errno = EILSEQ;
+			return (NULL);
+		}
+	} else {
+		/*
+		 * Optimisation: if the output precision is small enough,
+		 * just allocate enough memory for the maximum instead of
+		 * scanning the string.
+		 */
+		if (prec < 128)
+			nbytes = prec;
+		else {
+			nbytes = 0;
+			p = wcsarg;
+			memset(&mbs, 0, sizeof(mbs));
+			for (;;) {
+				clen = wcrtomb(buf, *p++, &mbs);
+				if (clen == 0 || clen == (size_t)-1 ||
+				    nbytes + clen > (size_t)prec)
+					break;
+				nbytes += clen;
+			}
+			if (clen == (size_t)-1) {
+				errno = EILSEQ;
+				return (NULL);
+			}
+		}
+	}
+	if ((convbuf = malloc(nbytes + 1)) == NULL)
+		return (NULL);
+
+	/* Fill the output buffer. */
+	p = wcsarg;
+	memset(&mbs, 0, sizeof(mbs));
+	if ((nbytes = wcsrtombs(convbuf, (const wchar_t **)&p,
+	    nbytes, &mbs)) == (size_t)-1) {
+		free(convbuf);
+		errno = EILSEQ;
+		return (NULL);
+	}
+	convbuf[nbytes] = '\0';
+	return (convbuf);
+}
+#endif
+
+#ifdef FLOATING_POINT
+#include <float.h>
+#include <locale.h>
+#include <math.h>
+#include "floatio.h"
+#include "gdtoa.h"
+
+#define	DEFPREC		6
+
+static int exponent(char *, int, int);
+#endif /* FLOATING_POINT */
+
+/*
+ * The size of the buffer we use as scratch space for integer
+ * conversions, among other things.  Technically, we would need the
+ * most space for base 10 conversions with thousands' grouping
+ * characters between each pair of digits.  100 bytes is a
+ * conservative overestimate even for a 128-bit uintmax_t.
+ */
+#define BUF	100
+
+#define STATIC_ARG_TBL_SIZE 8	/* Size of static argument table. */
+
+
+/*
+ * Macros for converting digits to letters and vice versa
+ */
+#define	to_digit(c)	((c) - '0')
+#define is_digit(c)	((unsigned)to_digit(c) <= 9)
+#define	to_char(n)	((n) + '0')
+
+/*
+ * Flags used during conversion.
+ */
+#define	ALT		0x0001		/* alternate form */
+#define	LADJUST		0x0004		/* left adjustment */
+#define	LONGDBL		0x0008		/* long double */
+#define	LONGINT		0x0010		/* long integer */
+#define	LLONGINT	0x0020		/* long long integer */
+#define	SHORTINT	0x0040		/* short integer */
+#define	ZEROPAD		0x0080		/* zero (as opposed to blank) pad */
+#define FPT		0x0100		/* Floating point number */
+#define PTRINT		0x0200		/* (unsigned) ptrdiff_t */
+#define SIZEINT		0x0400		/* (signed) size_t */
+#define CHARINT		0x0800		/* 8 bit integer */
+#define MAXINT		0x1000		/* largest integer size (intmax_t) */
+
+int
+vfprintf(FILE *fp, const char *fmt0, __va_list ap)
+{
+	int ret;
+
+	FLOCKFILE(fp);
+	ret = __vfprintf(fp, fmt0, ap);
+	FUNLOCKFILE(fp);
+	return (ret);
+}
+
+int
+__vfprintf(FILE *fp, const char *fmt0, __va_list ap)
+{
+	char *fmt;		/* format string */
+	int ch;			/* character from fmt */
+	int n, n2;		/* handy integers (short term usage) */
+	char *cp;		/* handy char pointer (short term usage) */
+	struct __siov *iovp;	/* for PRINT macro */
+	int flags;		/* flags as above */
+	int ret;		/* return value accumulator */
+	int width;		/* width from format (%8d), or 0 */
+	int prec;		/* precision from format; <0 for N/A */
+	char sign;		/* sign prefix (' ', '+', '-', or \0) */
+	wchar_t wc;
+	mbstate_t ps;
+#ifdef FLOATING_POINT
+	/*
+	 * We can decompose the printed representation of floating
+	 * point numbers into several parts, some of which may be empty:
+	 *
+	 * [+|-| ] [0x|0X] MMM . NNN [e|E|p|P] [+|-] ZZ
+	 *    A       B     ---C---      D       E   F
+	 *
+	 * A:	'sign' holds this value if present; '\0' otherwise
+	 * B:	ox[1] holds the 'x' or 'X'; '\0' if not hexadecimal
+	 * C:	cp points to the string MMMNNN.  Leading and trailing
+	 *	zeros are not in the string and must be added.
+	 * D:	expchar holds this character; '\0' if no exponent, e.g. %f
+	 * F:	at least two digits for decimal, at least one digit for hex
+	 */
+	char *decimal_point = NULL;
+	int signflag;		/* true if float is negative */
+	union {			/* floating point arguments %[aAeEfFgG] */
+		double dbl;
+		long double ldbl;
+	} fparg;
+	int expt;		/* integer value of exponent */
+	char expchar;		/* exponent character: [eEpP\0] */
+	char *dtoaend;		/* pointer to end of converted digits */
+	int expsize;		/* character count for expstr */
+	int lead;		/* sig figs before decimal or group sep */
+	int ndig;		/* actual number of digits returned by dtoa */
+	char expstr[MAXEXPDIG+2];	/* buffer for exponent string: e+ZZZ */
+	char *dtoaresult = NULL;
+#endif
+
+	uintmax_t _umax;	/* integer arguments %[diouxX] */
+	enum { OCT, DEC, HEX } base;	/* base for %[diouxX] conversion */
+	int dprec;		/* a copy of prec if %[diouxX], 0 otherwise */
+	int realsz;		/* field size expanded by dprec */
+	int size;		/* size of converted field or string */
+	const char *xdigs;	/* digits for %[xX] conversion */
+#define NIOV 8
+	struct __suio uio;	/* output information: summary */
+	struct __siov iov[NIOV];/* ... and individual io vectors */
+	char buf[BUF];		/* buffer with space for digits of uintmax_t */
+	char ox[2];		/* space for 0x; ox[1] is either x, X, or \0 */
+	union arg *argtable;	/* args, built due to positional arg */
+	union arg statargtable[STATIC_ARG_TBL_SIZE];
+	size_t argtablesiz;
+	int nextarg;		/* 1-based argument index */
+	va_list orgap;		/* original argument pointer */
+#ifdef PRINTF_WIDE_CHAR
+	char *convbuf;		/* buffer for wide to multi-byte conversion */
+#endif
+
+	/*
+	 * Choose PADSIZE to trade efficiency vs. size.  If larger printf
+	 * fields occur frequently, increase PADSIZE and make the initialisers
+	 * below longer.
+	 */
+#define	PADSIZE	16		/* pad chunk size */
+	static char blanks[PADSIZE] =
+	 {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
+	static char zeroes[PADSIZE] =
+	 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
+
+	static const char xdigs_lower[16] = "0123456789abcdef";
+	static const char xdigs_upper[16] = "0123456789ABCDEF";
+
+	/*
+	 * BEWARE, these `goto error' on error, and PAD uses `n'.
+	 */
+#define	PRINT(ptr, len) do { \
+	iovp->iov_base = (ptr); \
+	iovp->iov_len = (len); \
+	uio.uio_resid += (len); \
+	iovp++; \
+	if (++uio.uio_iovcnt >= NIOV) { \
+		if (__sprint(fp, &uio)) \
+			goto error; \
+		iovp = iov; \
+	} \
+} while (0)
+#define	PAD(howmany, with) do { \
+	if ((n = (howmany)) > 0) { \
+		while (n > PADSIZE) { \
+			PRINT(with, PADSIZE); \
+			n -= PADSIZE; \
+		} \
+		PRINT(with, n); \
+	} \
+} while (0)
+#define	PRINTANDPAD(p, ep, len, with) do {	\
+	n2 = (ep) - (p);       			\
+	if (n2 > (len))				\
+		n2 = (len);			\
+	if (n2 > 0)				\
+		PRINT((p), n2);			\
+	PAD((len) - (n2 > 0 ? n2 : 0), (with));	\
+} while(0)
+#define	FLUSH() do { \
+	if (uio.uio_resid && __sprint(fp, &uio)) \
+		goto error; \
+	uio.uio_iovcnt = 0; \
+	iovp = iov; \
+} while (0)
+
+	/*
+	 * To extend shorts properly, we need both signed and unsigned
+	 * argument extraction methods.
+	 */
+#define	SARG() \
+	((intmax_t)(flags&MAXINT ? GETARG(intmax_t) : \
+	    flags&LLONGINT ? GETARG(long long) : \
+	    flags&LONGINT ? GETARG(long) : \
+	    flags&PTRINT ? GETARG(ptrdiff_t) : \
+	    flags&SIZEINT ? GETARG(ssize_t) : \
+	    flags&SHORTINT ? (short)GETARG(int) : \
+	    flags&CHARINT ? (signed char)GETARG(int) : \
+	    GETARG(int)))
+#define	UARG() \
+	((uintmax_t)(flags&MAXINT ? GETARG(uintmax_t) : \
+	    flags&LLONGINT ? GETARG(unsigned long long) : \
+	    flags&LONGINT ? GETARG(unsigned long) : \
+	    flags&PTRINT ? (uintptr_t)GETARG(ptrdiff_t) : /* XXX */ \
+	    flags&SIZEINT ? GETARG(size_t) : \
+	    flags&SHORTINT ? (unsigned short)GETARG(int) : \
+	    flags&CHARINT ? (unsigned char)GETARG(int) : \
+	    GETARG(unsigned int)))
+
+	/*
+	 * Append a digit to a value and check for overflow.
+	 */
+#define APPEND_DIGIT(val, dig) do { \
+	if ((val) > INT_MAX / 10) \
+		goto overflow; \
+	(val) *= 10; \
+	if ((val) > INT_MAX - to_digit((dig))) \
+		goto overflow; \
+	(val) += to_digit((dig)); \
+} while (0)
+
+	 /*
+	  * Get * arguments, including the form *nn$.  Preserve the nextarg
+	  * that the argument can be gotten once the type is determined.
+	  */
+#define GETASTER(val) \
+	n2 = 0; \
+	cp = fmt; \
+	while (is_digit(*cp)) { \
+		APPEND_DIGIT(n2, *cp); \
+		cp++; \
+	} \
+	if (*cp == '$') { \
+		int hold = nextarg; \
+		if (argtable == NULL) { \
+			argtable = statargtable; \
+			__find_arguments(fmt0, orgap, &argtable, &argtablesiz); \
+		} \
+		nextarg = n2; \
+		val = GETARG(int); \
+		nextarg = hold; \
+		fmt = ++cp; \
+	} else { \
+		val = GETARG(int); \
+	}
+
+/*
+* Get the argument indexed by nextarg.   If the argument table is
+* built, use it to get the argument.  If its not, get the next
+* argument (and arguments must be gotten sequentially).
+*/
+#define GETARG(type) \
+	((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \
+		(nextarg++, va_arg(ap, type)))
+
+	_SET_ORIENTATION(fp, -1);
+	/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
+	if (cantwrite(fp)) {
+		errno = EBADF;
+		return (EOF);
+	}
+
+	/* optimise fprintf(stderr) (and other unbuffered Unix files) */
+	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
+	    fp->_file >= 0)
+		return (__sbprintf(fp, fmt0, ap));
+
+	fmt = (char *)fmt0;
+	argtable = NULL;
+	nextarg = 1;
+	va_copy(orgap, ap);
+	uio.uio_iov = iovp = iov;
+	uio.uio_resid = 0;
+	uio.uio_iovcnt = 0;
+	ret = 0;
+#ifdef PRINTF_WIDE_CHAR
+	convbuf = NULL;
+#endif
+
+	memset(&ps, 0, sizeof(ps));
+	/*
+	 * Scan the format for conversions (`%' character).
+	 */
+	for (;;) {
+		cp = fmt;
+		while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) {
+			fmt += n;
+			if (wc == '%') {
+				fmt--;
+				break;
+			}
+		}
+		if (fmt != cp) {
+			ptrdiff_t m = fmt - cp;
+			if (m < 0 || m > INT_MAX - ret)
+				goto overflow;
+			PRINT(cp, m);
+			ret += m;
+		}
+		if (n <= 0)
+			goto done;
+		fmt++;		/* skip over '%' */
+
+		flags = 0;
+		dprec = 0;
+		width = 0;
+		prec = -1;
+		sign = '\0';
+		ox[1] = '\0';
+
+rflag:		ch = *fmt++;
+reswitch:	switch (ch) {
+		case ' ':
+			/*
+			 * ``If the space and + flags both appear, the space
+			 * flag will be ignored.''
+			 *	-- ANSI X3J11
+			 */
+			if (!sign)
+				sign = ' ';
+			goto rflag;
+		case '#':
+			flags |= ALT;
+			goto rflag;
+		case '\'':
+			/* grouping not implemented */
+			goto rflag;
+		case '*':
+			/*
+			 * ``A negative field width argument is taken as a
+			 * - flag followed by a positive field width.''
+			 *	-- ANSI X3J11
+			 * They don't exclude field widths read from args.
+			 */
+			GETASTER(width);
+			if (width >= 0)
+				goto rflag;
+			if (width == INT_MIN)
+				goto overflow;
+			width = -width;
+			/* FALLTHROUGH */
+		case '-':
+			flags |= LADJUST;
+			goto rflag;
+		case '+':
+			sign = '+';
+			goto rflag;
+		case '.':
+			if ((ch = *fmt++) == '*') {
+				GETASTER(n);
+				prec = n < 0 ? -1 : n;
+				goto rflag;
+			}
+			n = 0;
+			while (is_digit(ch)) {
+				APPEND_DIGIT(n, ch);
+				ch = *fmt++;
+			}
+			if (ch == '$') {
+				nextarg = n;
+				if (argtable == NULL) {
+					argtable = statargtable;
+					__find_arguments(fmt0, orgap,
+					    &argtable, &argtablesiz);
+				}
+				goto rflag;
+			}
+			prec = n;
+			goto reswitch;
+		case '0':
+			/*
+			 * ``Note that 0 is taken as a flag, not as the
+			 * beginning of a field width.''
+			 *	-- ANSI X3J11
+			 */
+			flags |= ZEROPAD;
+			goto rflag;
+		case '1': case '2': case '3': case '4':
+		case '5': case '6': case '7': case '8': case '9':
+			n = 0;
+			do {
+				APPEND_DIGIT(n, ch);
+				ch = *fmt++;
+			} while (is_digit(ch));
+			if (ch == '$') {
+				nextarg = n;
+				if (argtable == NULL) {
+					argtable = statargtable;
+					__find_arguments(fmt0, orgap,
+					    &argtable, &argtablesiz);
+				}
+				goto rflag;
+			}
+			width = n;
+			goto reswitch;
+#ifdef FLOATING_POINT
+		case 'L':
+			flags |= LONGDBL;
+			goto rflag;
+#endif
+		case 'h':
+			if (*fmt == 'h') {
+				fmt++;
+				flags |= CHARINT;
+			} else {
+				flags |= SHORTINT;
+			}
+			goto rflag;
+		case 'j':
+			flags |= MAXINT;
+			goto rflag;
+		case 'l':
+			if (*fmt == 'l') {
+				fmt++;
+				flags |= LLONGINT;
+			} else {
+				flags |= LONGINT;
+			}
+			goto rflag;
+		case 'q':
+			flags |= LLONGINT;
+			goto rflag;
+		case 't':
+			flags |= PTRINT;
+			goto rflag;
+		case 'z':
+			flags |= SIZEINT;
+			goto rflag;
+		case 'c':
+#ifdef PRINTF_WIDE_CHAR
+			if (flags & LONGINT) {
+				mbstate_t mbs;
+				size_t mbseqlen;
+
+				memset(&mbs, 0, sizeof(mbs));
+				mbseqlen = wcrtomb(buf,
+				    (wchar_t)GETARG(wint_t), &mbs);
+				if (mbseqlen == (size_t)-1) {
+					fp->_flags |= __SERR;
+					errno = EILSEQ;
+					goto error;
+				}
+				cp = buf;
+				size = (int)mbseqlen;
+			} else {
+#endif
+				*(cp = buf) = GETARG(int);
+				size = 1;
+#ifdef PRINTF_WIDE_CHAR
+			}
+#endif
+			sign = '\0';
+			break;
+		case 'D':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'd':
+		case 'i':
+			_umax = SARG();
+			if ((intmax_t)_umax < 0) {
+				_umax = -_umax;
+				sign = '-';
+			}
+			base = DEC;
+			goto number;
+#ifdef FLOATING_POINT
+		case 'a':
+		case 'A':
+			if (ch == 'a') {
+				ox[1] = 'x';
+				xdigs = xdigs_lower;
+				expchar = 'p';
+			} else {
+				ox[1] = 'X';
+				xdigs = xdigs_upper;
+				expchar = 'P';
+			}
+			if (prec >= 0)
+				prec++;
+			if (dtoaresult)
+				__freedtoa(dtoaresult);
+			if (flags & LONGDBL) {
+				fparg.ldbl = GETARG(long double);
+				dtoaresult = cp =
+				    __hldtoa(fparg.ldbl, xdigs, prec,
+				    &expt, &signflag, &dtoaend);
+				if (dtoaresult == NULL) {
+					errno = ENOMEM;
+					goto error;
+				}
+			} else {
+				fparg.dbl = GETARG(double);
+				dtoaresult = cp =
+				    __hdtoa(fparg.dbl, xdigs, prec,
+				    &expt, &signflag, &dtoaend);
+				if (dtoaresult == NULL) {
+					errno = ENOMEM;
+					goto error;
+				}
+			}
+			if (prec < 0)
+				prec = dtoaend - cp;
+			if (expt == INT_MAX)
+				ox[1] = '\0';
+			goto fp_common;
+		case 'e':
+		case 'E':
+			expchar = ch;
+			if (prec < 0)	/* account for digit before decpt */
+				prec = DEFPREC + 1;
+			else
+				prec++;
+			goto fp_begin;
+		case 'f':
+		case 'F':
+			expchar = '\0';
+			goto fp_begin;
+		case 'g':
+		case 'G':
+			expchar = ch - ('g' - 'e');
+ 			if (prec == 0)
+ 				prec = 1;
+fp_begin:
+			if (prec < 0)
+				prec = DEFPREC;
+			if (dtoaresult)
+				__freedtoa(dtoaresult);
+			if (flags & LONGDBL) {
+				fparg.ldbl = GETARG(long double);
+				dtoaresult = cp =
+				    __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec,
+				    &expt, &signflag, &dtoaend);
+				if (dtoaresult == NULL) {
+					errno = ENOMEM;
+					goto error;
+				}
+			} else {
+				fparg.dbl = GETARG(double);
+				dtoaresult = cp =
+				    __dtoa(fparg.dbl, expchar ? 2 : 3, prec,
+				    &expt, &signflag, &dtoaend);
+				if (dtoaresult == NULL) {
+					errno = ENOMEM;
+					goto error;
+				}
+				if (expt == 9999)
+					expt = INT_MAX;
+ 			}
+fp_common:
+			if (signflag)
+				sign = '-';
+			if (expt == INT_MAX) {	/* inf or nan */
+				if (*cp == 'N') {
+					cp = (ch >= 'a') ? "nan" : "NAN";
+					sign = '\0';
+				} else
+					cp = (ch >= 'a') ? "inf" : "INF";
+ 				size = 3;
+				flags &= ~ZEROPAD;
+ 				break;
+ 			}
+			flags |= FPT;
+			ndig = dtoaend - cp;
+ 			if (ch == 'g' || ch == 'G') {
+				if (expt > -4 && expt <= prec) {
+					/* Make %[gG] smell like %[fF] */
+					expchar = '\0';
+					if (flags & ALT)
+						prec -= expt;
+					else
+						prec = ndig - expt;
+					if (prec < 0)
+						prec = 0;
+				} else {
+					/*
+					 * Make %[gG] smell like %[eE], but
+					 * trim trailing zeroes if no # flag.
+					 */
+					if (!(flags & ALT))
+						prec = ndig;
+				}
+ 			}
+			if (expchar) {
+				expsize = exponent(expstr, expt - 1, expchar);
+				size = expsize + prec;
+				if (prec > 1 || flags & ALT)
+ 					++size;
+			} else {
+				/* space for digits before decimal point */
+				if (expt > 0)
+					size = expt;
+				else	/* "0" */
+					size = 1;
+				/* space for decimal pt and following digits */
+				if (prec || flags & ALT)
+					size += prec + 1;
+				lead = expt;
+			}
+			break;
+#endif /* FLOATING_POINT */
+#ifndef NO_PRINTF_PERCENT_N
+		case 'n':
+			if (flags & LLONGINT)
+				*GETARG(long long *) = ret;
+			else if (flags & LONGINT)
+				*GETARG(long *) = ret;
+			else if (flags & SHORTINT)
+				*GETARG(short *) = ret;
+			else if (flags & CHARINT)
+				*GETARG(signed char *) = ret;
+			else if (flags & PTRINT)
+				*GETARG(ptrdiff_t *) = ret;
+			else if (flags & SIZEINT)
+				*GETARG(ssize_t *) = ret;
+			else if (flags & MAXINT)
+				*GETARG(intmax_t *) = ret;
+			else
+				*GETARG(int *) = ret;
+			continue;	/* no output */
+#endif /* NO_PRINTF_PERCENT_N */
+		case 'O':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'o':
+			_umax = UARG();
+			base = OCT;
+			goto nosign;
+		case 'p':
+			/*
+			 * ``The argument shall be a pointer to void.  The
+			 * value of the pointer is converted to a sequence
+			 * of printable characters, in an implementation-
+			 * defined manner.''
+			 *	-- ANSI X3J11
+			 */
+			/* NOSTRICT */
+			_umax = (u_long)GETARG(void *);
+			base = HEX;
+			xdigs = xdigs_lower;
+			ox[1] = 'x';
+			goto nosign;
+		case 's':
+#ifdef PRINTF_WIDE_CHAR
+			if (flags & LONGINT) {
+				wchar_t *wcp;
+
+				if (convbuf != NULL) {
+					free(convbuf);
+					convbuf = NULL;
+				}
+				if ((wcp = GETARG(wchar_t *)) == NULL) {
+					cp = "(null)";
+				} else {
+					convbuf = __wcsconv(wcp, prec);
+					if (convbuf == NULL) {
+						fp->_flags = __SERR;
+						goto error;
+					}
+					cp = convbuf;
+				}
+			} else
+#endif /* PRINTF_WIDE_CHAR */
+			if ((cp = GETARG(char *)) == NULL)
+				cp = "(null)";
+			if (prec >= 0) {
+				/*
+				 * can't use strlen; can only look for the
+				 * NUL in the first `prec' characters, and
+				 * strlen() will go further.
+				 */
+				char *p = memchr(cp, 0, prec);
+
+				size = p ? (p - cp) : prec;
+			} else {
+				size_t len;
+
+				if ((len = strlen(cp)) > INT_MAX)
+					goto overflow;
+				size = (int)len;
+			}
+			sign = '\0';
+			break;
+		case 'U':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'u':
+			_umax = UARG();
+			base = DEC;
+			goto nosign;
+		case 'X':
+			xdigs = xdigs_upper;
+			goto hex;
+		case 'x':
+			xdigs = xdigs_lower;
+hex:			_umax = UARG();
+			base = HEX;
+			/* leading 0x/X only if non-zero */
+			if (flags & ALT && _umax != 0)
+				ox[1] = ch;
+
+			/* unsigned conversions */
+nosign:			sign = '\0';
+			/*
+			 * ``... diouXx conversions ... if a precision is
+			 * specified, the 0 flag will be ignored.''
+			 *	-- ANSI X3J11
+			 */
+number:			if ((dprec = prec) >= 0)
+				flags &= ~ZEROPAD;
+
+			/*
+			 * ``The result of converting a zero value with an
+			 * explicit precision of zero is no characters.''
+			 *	-- ANSI X3J11
+			 */
+			cp = buf + BUF;
+			if (_umax != 0 || prec != 0) {
+				/*
+				 * Unsigned mod is hard, and unsigned mod
+				 * by a constant is easier than that by
+				 * a variable; hence this switch.
+				 */
+				switch (base) {
+				case OCT:
+					do {
+						*--cp = to_char(_umax & 7);
+						_umax >>= 3;
+					} while (_umax);
+					/* handle octal leading 0 */
+					if (flags & ALT && *cp != '0')
+						*--cp = '0';
+					break;
+
+				case DEC:
+					/* many numbers are 1 digit */
+					while (_umax >= 10) {
+						*--cp = to_char(_umax % 10);
+						_umax /= 10;
+					}
+					*--cp = to_char(_umax);
+					break;
+
+				case HEX:
+					do {
+						*--cp = xdigs[_umax & 15];
+						_umax >>= 4;
+					} while (_umax);
+					break;
+
+				default:
+					cp = "bug in vfprintf: bad base";
+					size = strlen(cp);
+					goto skipsize;
+				}
+			}
+			size = buf + BUF - cp;
+			if (size > BUF)	/* should never happen */
+				abort();
+		skipsize:
+			break;
+		default:	/* "%?" prints ?, unless ? is NUL */
+			if (ch == '\0')
+				goto done;
+			/* pretend it was %c with argument ch */
+			cp = buf;
+			*cp = ch;
+			size = 1;
+			sign = '\0';
+			break;
+		}
+
+		/*
+		 * All reasonable formats wind up here.  At this point, `cp'
+		 * points to a string which (if not flags&LADJUST) should be
+		 * padded out to `width' places.  If flags&ZEROPAD, it should
+		 * first be prefixed by any sign or other prefix; otherwise,
+		 * it should be blank padded before the prefix is emitted.
+		 * After any left-hand padding and prefixing, emit zeroes
+		 * required by a decimal %[diouxX] precision, then print the
+		 * string proper, then emit zeroes required by any leftover
+		 * floating precision; finally, if LADJUST, pad with blanks.
+		 *
+		 * Compute actual size, so we know how much to pad.
+		 * size excludes decimal prec; realsz includes it.
+		 */
+		realsz = dprec > size ? dprec : size;
+		if (sign)
+			realsz++;
+		if (ox[1])
+			realsz+= 2;
+
+		/* right-adjusting blank padding */
+		if ((flags & (LADJUST|ZEROPAD)) == 0)
+			PAD(width - realsz, blanks);
+
+		/* prefix */
+		if (sign)
+			PRINT(&sign, 1);
+		if (ox[1]) {	/* ox[1] is either x, X, or \0 */
+			ox[0] = '0';
+			PRINT(ox, 2);
+		}
+
+		/* right-adjusting zero padding */
+		if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
+			PAD(width - realsz, zeroes);
+
+		/* leading zeroes from decimal precision */
+		PAD(dprec - size, zeroes);
+
+		/* the string or number proper */
+#ifdef FLOATING_POINT
+		if ((flags & FPT) == 0) {
+			PRINT(cp, size);
+		} else {	/* glue together f_p fragments */
+			if (decimal_point == NULL)
+				decimal_point = nl_langinfo(RADIXCHAR);
+			if (!expchar) {	/* %[fF] or sufficiently short %[gG] */
+				if (expt <= 0) {
+					PRINT(zeroes, 1);
+					if (prec || flags & ALT)
+						PRINT(decimal_point, 1);
+					PAD(-expt, zeroes);
+					/* already handled initial 0's */
+					prec += expt;
+ 				} else {
+					PRINTANDPAD(cp, dtoaend, lead, zeroes);
+					cp += lead;
+					if (prec || flags & ALT)
+						PRINT(decimal_point, 1);
+				}
+				PRINTANDPAD(cp, dtoaend, prec, zeroes);
+			} else {	/* %[eE] or sufficiently long %[gG] */
+				if (prec > 1 || flags & ALT) {
+					buf[0] = *cp++;
+					buf[1] = *decimal_point;
+					PRINT(buf, 2);
+					PRINT(cp, ndig-1);
+					PAD(prec - ndig, zeroes);
+				} else { /* XeYYY */
+					PRINT(cp, 1);
+				}
+				PRINT(expstr, expsize);
+			}
+		}
+#else
+		PRINT(cp, size);
+#endif
+		/* left-adjusting padding (always blank) */
+		if (flags & LADJUST)
+			PAD(width - realsz, blanks);
+
+		/* finally, adjust ret */
+		if (width < realsz)
+			width = realsz;
+		if (width > INT_MAX - ret)
+			goto overflow;
+		ret += width;
+
+		FLUSH();	/* copy out the I/O vectors */
+	}
+done:
+	FLUSH();
+error:
+	va_end(orgap);
+	if (__sferror(fp))
+		ret = -1;
+	goto finish;
+
+overflow:
+	errno = ENOMEM;
+	ret = -1;
+
+finish:
+#ifdef PRINTF_WIDE_CHAR
+	if (convbuf)
+		free(convbuf);
+#endif
+#ifdef FLOATING_POINT
+	if (dtoaresult)
+		__freedtoa(dtoaresult);
+#endif
+	if (argtable != NULL && argtable != statargtable) {
+		munmap(argtable, argtablesiz);
+		argtable = NULL;
+	}
+	return (ret);
+}
+
+/*
+ * Type ids for argument type table.
+ */
+#define T_UNUSED	0
+#define T_SHORT		1
+#define T_U_SHORT	2
+#define TP_SHORT	3
+#define T_INT		4
+#define T_U_INT		5
+#define TP_INT		6
+#define T_LONG		7
+#define T_U_LONG	8
+#define TP_LONG		9
+#define T_LLONG		10
+#define T_U_LLONG	11
+#define TP_LLONG	12
+#define T_DOUBLE	13
+#define T_LONG_DOUBLE	14
+#define TP_CHAR		15
+#define TP_VOID		16
+#define T_PTRINT	17
+#define TP_PTRINT	18
+#define T_SIZEINT	19
+#define T_SSIZEINT	20
+#define TP_SSIZEINT	21
+#define T_MAXINT	22
+#define T_MAXUINT	23
+#define TP_MAXINT	24
+#define T_CHAR		25
+#define T_U_CHAR	26
+#define T_WINT		27
+#define TP_WCHAR	28
+
+/*
+ * Find all arguments when a positional parameter is encountered.  Returns a
+ * table, indexed by argument number, of pointers to each arguments.  The
+ * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
+ * It will be replaced with a mmap-ed one if it overflows (malloc cannot be
+ * used since we are attempting to make snprintf thread safe, and alloca is
+ * problematic since we have nested functions..)
+ */
+static int
+__find_arguments(const char *fmt0, va_list ap, union arg **argtable,
+    size_t *argtablesiz)
+{
+	char *fmt;		/* format string */
+	int ch;			/* character from fmt */
+	int n, n2;		/* handy integer (short term usage) */
+	char *cp;		/* handy char pointer (short term usage) */
+	int flags;		/* flags as above */
+	unsigned char *typetable; /* table of types */
+	unsigned char stattypetable[STATIC_ARG_TBL_SIZE];
+	int tablesize;		/* current size of type table */
+	int tablemax;		/* largest used index in table */
+	int nextarg;		/* 1-based argument index */
+	int ret = 0;		/* return value */
+	wchar_t wc;
+	mbstate_t ps;
+
+	/*
+	 * Add an argument type to the table, expanding if necessary.
+	 */
+#define ADDTYPE(type) \
+	((nextarg >= tablesize) ? \
+		__grow_type_table(&typetable, &tablesize) : 0, \
+	(nextarg > tablemax) ? tablemax = nextarg : 0, \
+	typetable[nextarg++] = type)
+
+#define	ADDSARG() \
+        ((flags&MAXINT) ? ADDTYPE(T_MAXINT) : \
+	    ((flags&PTRINT) ? ADDTYPE(T_PTRINT) : \
+	    ((flags&SIZEINT) ? ADDTYPE(T_SSIZEINT) : \
+	    ((flags&LLONGINT) ? ADDTYPE(T_LLONG) : \
+	    ((flags&LONGINT) ? ADDTYPE(T_LONG) : \
+	    ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : \
+	    ((flags&CHARINT) ? ADDTYPE(T_CHAR) : ADDTYPE(T_INT))))))))
+
+#define	ADDUARG() \
+        ((flags&MAXINT) ? ADDTYPE(T_MAXUINT) : \
+	    ((flags&PTRINT) ? ADDTYPE(T_PTRINT) : \
+	    ((flags&SIZEINT) ? ADDTYPE(T_SIZEINT) : \
+	    ((flags&LLONGINT) ? ADDTYPE(T_U_LLONG) : \
+	    ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \
+	    ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : \
+	    ((flags&CHARINT) ? ADDTYPE(T_U_CHAR) : ADDTYPE(T_U_INT))))))))
+
+	/*
+	 * Add * arguments to the type array.
+	 */
+#define ADDASTER() \
+	n2 = 0; \
+	cp = fmt; \
+	while (is_digit(*cp)) { \
+		APPEND_DIGIT(n2, *cp); \
+		cp++; \
+	} \
+	if (*cp == '$') { \
+		int hold = nextarg; \
+		nextarg = n2; \
+		ADDTYPE(T_INT); \
+		nextarg = hold; \
+		fmt = ++cp; \
+	} else { \
+		ADDTYPE(T_INT); \
+	}
+	fmt = (char *)fmt0;
+	typetable = stattypetable;
+	tablesize = STATIC_ARG_TBL_SIZE;
+	tablemax = 0;
+	nextarg = 1;
+	memset(typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
+	memset(&ps, 0, sizeof(ps));
+
+	/*
+	 * Scan the format for conversions (`%' character).
+	 */
+	for (;;) {
+		cp = fmt;
+		while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) {
+			fmt += n;
+			if (wc == '%') {
+				fmt--;
+				break;
+			}
+		}
+		if (n <= 0)
+			goto done;
+		fmt++;		/* skip over '%' */
+
+		flags = 0;
+
+rflag:		ch = *fmt++;
+reswitch:	switch (ch) {
+		case ' ':
+		case '#':
+		case '\'':
+			goto rflag;
+		case '*':
+			ADDASTER();
+			goto rflag;
+		case '-':
+		case '+':
+			goto rflag;
+		case '.':
+			if ((ch = *fmt++) == '*') {
+				ADDASTER();
+				goto rflag;
+			}
+			while (is_digit(ch)) {
+				ch = *fmt++;
+			}
+			goto reswitch;
+		case '0':
+			goto rflag;
+		case '1': case '2': case '3': case '4':
+		case '5': case '6': case '7': case '8': case '9':
+			n = 0;
+			do {
+				APPEND_DIGIT(n ,ch);
+				ch = *fmt++;
+			} while (is_digit(ch));
+			if (ch == '$') {
+				nextarg = n;
+				goto rflag;
+			}
+			goto reswitch;
+#ifdef FLOATING_POINT
+		case 'L':
+			flags |= LONGDBL;
+			goto rflag;
+#endif
+		case 'h':
+			if (*fmt == 'h') {
+				fmt++;
+				flags |= CHARINT;
+			} else {
+				flags |= SHORTINT;
+			}
+			goto rflag;
+		case 'j':
+			flags |= MAXINT;
+			goto rflag;
+		case 'l':
+			if (*fmt == 'l') {
+				fmt++;
+				flags |= LLONGINT;
+			} else {
+				flags |= LONGINT;
+			}
+			goto rflag;
+		case 'q':
+			flags |= LLONGINT;
+			goto rflag;
+		case 't':
+			flags |= PTRINT;
+			goto rflag;
+		case 'z':
+			flags |= SIZEINT;
+			goto rflag;
+		case 'c':
+#ifdef PRINTF_WIDE_CHAR
+			if (flags & LONGINT)
+				ADDTYPE(T_WINT);
+			else
+#endif
+				ADDTYPE(T_INT);
+			break;
+		case 'D':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'd':
+		case 'i':
+			ADDSARG();
+			break;
+#ifdef FLOATING_POINT
+		case 'a':
+		case 'A':
+		case 'e':
+		case 'E':
+		case 'f':
+		case 'F':
+		case 'g':
+		case 'G':
+			if (flags & LONGDBL)
+				ADDTYPE(T_LONG_DOUBLE);
+			else
+				ADDTYPE(T_DOUBLE);
+			break;
+#endif /* FLOATING_POINT */
+#ifndef NO_PRINTF_PERCENT_N
+		case 'n':
+			if (flags & LLONGINT)
+				ADDTYPE(TP_LLONG);
+			else if (flags & LONGINT)
+				ADDTYPE(TP_LONG);
+			else if (flags & SHORTINT)
+				ADDTYPE(TP_SHORT);
+			else if (flags & PTRINT)
+				ADDTYPE(TP_PTRINT);
+			else if (flags & SIZEINT)
+				ADDTYPE(TP_SSIZEINT);
+			else if (flags & MAXINT)
+				ADDTYPE(TP_MAXINT);
+			else
+				ADDTYPE(TP_INT);
+			continue;	/* no output */
+#endif /* NO_PRINTF_PERCENT_N */
+		case 'O':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'o':
+			ADDUARG();
+			break;
+		case 'p':
+			ADDTYPE(TP_VOID);
+			break;
+		case 's':
+#ifdef PRINTF_WIDE_CHAR
+			if (flags & LONGINT)
+				ADDTYPE(TP_WCHAR);
+			else
+#endif
+				ADDTYPE(TP_CHAR);
+			break;
+		case 'U':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'u':
+		case 'X':
+		case 'x':
+			ADDUARG();
+			break;
+		default:	/* "%?" prints ?, unless ? is NUL */
+			if (ch == '\0')
+				goto done;
+			break;
+		}
+	}
+done:
+	/*
+	 * Build the argument table.
+	 */
+	if (tablemax >= STATIC_ARG_TBL_SIZE) {
+		*argtablesiz = sizeof(union arg) * (tablemax + 1);
+		*argtable = mmap(NULL, *argtablesiz,
+		    PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0);
+		if (*argtable == MAP_FAILED)
+			return (-1);
+	}
+
+#if 0
+	/* XXX is this required? */
+	(*argtable)[0].intarg = 0;
+#endif
+	for (n = 1; n <= tablemax; n++) {
+		switch (typetable[n]) {
+		case T_UNUSED:
+		case T_CHAR:
+		case T_U_CHAR:
+		case T_SHORT:
+		case T_U_SHORT:
+		case T_INT:
+			(*argtable)[n].intarg = va_arg(ap, int);
+			break;
+		case TP_SHORT:
+			(*argtable)[n].pshortarg = va_arg(ap, short *);
+			break;
+		case T_U_INT:
+			(*argtable)[n].uintarg = va_arg(ap, unsigned int);
+			break;
+		case TP_INT:
+			(*argtable)[n].pintarg = va_arg(ap, int *);
+			break;
+		case T_LONG:
+			(*argtable)[n].longarg = va_arg(ap, long);
+			break;
+		case T_U_LONG:
+			(*argtable)[n].ulongarg = va_arg(ap, unsigned long);
+			break;
+		case TP_LONG:
+			(*argtable)[n].plongarg = va_arg(ap, long *);
+			break;
+		case T_LLONG:
+			(*argtable)[n].longlongarg = va_arg(ap, long long);
+			break;
+		case T_U_LLONG:
+			(*argtable)[n].ulonglongarg = va_arg(ap, unsigned long long);
+			break;
+		case TP_LLONG:
+			(*argtable)[n].plonglongarg = va_arg(ap, long long *);
+			break;
+#ifdef FLOATING_POINT
+		case T_DOUBLE:
+			(*argtable)[n].doublearg = va_arg(ap, double);
+			break;
+		case T_LONG_DOUBLE:
+			(*argtable)[n].longdoublearg = va_arg(ap, long double);
+			break;
+#endif
+		case TP_CHAR:
+			(*argtable)[n].pchararg = va_arg(ap, char *);
+			break;
+		case TP_VOID:
+			(*argtable)[n].pvoidarg = va_arg(ap, void *);
+			break;
+		case T_PTRINT:
+			(*argtable)[n].ptrdiffarg = va_arg(ap, ptrdiff_t);
+			break;
+		case TP_PTRINT:
+			(*argtable)[n].pptrdiffarg = va_arg(ap, ptrdiff_t *);
+			break;
+		case T_SIZEINT:
+			(*argtable)[n].sizearg = va_arg(ap, size_t);
+			break;
+		case T_SSIZEINT:
+			(*argtable)[n].ssizearg = va_arg(ap, ssize_t);
+			break;
+		case TP_SSIZEINT:
+			(*argtable)[n].pssizearg = va_arg(ap, ssize_t *);
+			break;
+		case T_MAXINT:
+			(*argtable)[n].intmaxarg = va_arg(ap, intmax_t);
+			break;
+		case T_MAXUINT:
+			(*argtable)[n].uintmaxarg = va_arg(ap, uintmax_t);
+			break;
+		case TP_MAXINT:
+			(*argtable)[n].pintmaxarg = va_arg(ap, intmax_t *);
+			break;
+#ifdef PRINTF_WIDE_CHAR
+		case T_WINT:
+			(*argtable)[n].wintarg = va_arg(ap, wint_t);
+			break;
+		case TP_WCHAR:
+			(*argtable)[n].pwchararg = va_arg(ap, wchar_t *);
+			break;
+#endif
+		}
+	}
+	goto finish;
+
+overflow:
+	errno = ENOMEM;
+	ret = -1;
+
+finish:
+	if (typetable != NULL && typetable != stattypetable) {
+		munmap(typetable, *argtablesiz);
+		typetable = NULL;
+	}
+	return (ret);
+}
+
+/*
+ * Increase the size of the type table.
+ */
+static int
+__grow_type_table(unsigned char **typetable, int *tablesize)
+{
+	unsigned char *oldtable = *typetable;
+	int newsize = *tablesize * 2;
+
+	if (newsize < getpagesize())
+		newsize = getpagesize();
+
+	if (*tablesize == STATIC_ARG_TBL_SIZE) {
+		*typetable = mmap(NULL, newsize, PROT_WRITE|PROT_READ,
+		    MAP_ANON|MAP_PRIVATE, -1, 0);
+		if (*typetable == MAP_FAILED)
+			return (-1);
+		bcopy(oldtable, *typetable, *tablesize);
+	} else {
+		unsigned char *new = mmap(NULL, newsize, PROT_WRITE|PROT_READ,
+		    MAP_ANON|MAP_PRIVATE, -1, 0);
+		if (new == MAP_FAILED)
+			return (-1);
+		memmove(new, *typetable, *tablesize);
+		munmap(*typetable, *tablesize);
+		*typetable = new;
+	}
+	memset(*typetable + *tablesize, T_UNUSED, (newsize - *tablesize));
+
+	*tablesize = newsize;
+	return (0);
+}
+
+ 
+#ifdef FLOATING_POINT
+static int
+exponent(char *p0, int exp, int fmtch)
+{
+	char *p, *t;
+	char expbuf[MAXEXPDIG];
+
+	p = p0;
+	*p++ = fmtch;
+	if (exp < 0) {
+		exp = -exp;
+		*p++ = '-';
+	} else
+		*p++ = '+';
+	t = expbuf + MAXEXPDIG;
+	if (exp > 9) {
+		do {
+			*--t = to_char(exp % 10);
+		} while ((exp /= 10) > 9);
+		*--t = to_char(exp);
+		for (; t < expbuf + MAXEXPDIG; *p++ = *t++)
+			/* nothing */;
+	} else {
+		/*
+		 * Exponents for decimal floating point conversions
+		 * (%[eEgG]) must be at least two characters long,
+		 * whereas exponents for hexadecimal conversions can
+		 * be only one character long.
+		 */
+		if (fmtch == 'e' || fmtch == 'E')
+			*p++ = '0';
+		*p++ = to_char(exp);
+	}
+	return (p - p0);
+}
+#endif /* FLOATING_POINT */
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vfscanf.c
new file mode 100644
index 0000000..abefe32
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vfscanf.c
@@ -0,0 +1,969 @@
+/*	$OpenBSD: vfscanf.c,v 1.31 2014/03/19 05:17:01 guenther Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <wctype.h>
+#include <inttypes.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "local.h"
+
+#ifdef FLOATING_POINT
+#include "floatio.h"
+#endif
+
+#define	BUF		513	/* Maximum length of numeric string. */
+
+/*
+ * Flags used during conversion.
+ */
+#define	LONG		0x00001	/* l: long or double */
+#define	LONGDBL		0x00002	/* L: long double */
+#define	SHORT		0x00004	/* h: short */
+#define	SHORTSHORT	0x00008	/* hh: 8 bit integer */
+#define LLONG		0x00010	/* ll: long long (+ deprecated q: quad) */
+#define	POINTER		0x00020	/* p: void * (as hex) */
+#define	SIZEINT		0x00040	/* z: (signed) size_t */
+#define	MAXINT		0x00080	/* j: intmax_t */
+#define	PTRINT		0x00100	/* t: ptrdiff_t */
+#define	NOSKIP		0x00200	/* [ or c: do not skip blanks */
+#define	SUPPRESS	0x00400	/* *: suppress assignment */
+#define	UNSIGNED	0x00800	/* %[oupxX] conversions */
+
+/*
+ * The following are used in numeric conversions only:
+ * SIGNOK, HAVESIGN, NDIGITS, DPTOK, and EXPOK are for floating point;
+ * SIGNOK, HAVESIGN, NDIGITS, PFXOK, and NZDIGITS are for integral.
+ */
+#define	SIGNOK		0x01000	/* +/- is (still) legal */
+#define	HAVESIGN	0x02000	/* sign detected */
+#define	NDIGITS		0x04000	/* no digits detected */
+
+#define	DPTOK		0x08000	/* (float) decimal point is still legal */
+#define	EXPOK		0x10000	/* (float) exponent (e+3, etc) still legal */
+
+#define	PFXOK		0x08000	/* 0x prefix is (still) legal */
+#define	NZDIGITS	0x10000	/* no zero digits detected */
+
+/*
+ * Conversion types.
+ */
+#define	CT_CHAR		0	/* %c conversion */
+#define	CT_CCL		1	/* %[...] conversion */
+#define	CT_STRING	2	/* %s conversion */
+#define	CT_INT		3	/* integer, i.e., strtoimax or strtoumax */
+#define	CT_FLOAT	4	/* floating, i.e., strtod */
+
+#define u_char unsigned char
+#define u_long unsigned long
+
+static u_char *__sccl(char *, u_char *);
+
+/*
+ * Internal, unlocked version of vfscanf
+ */
+int
+__svfscanf(FILE *fp, const char *fmt0, __va_list ap)
+{
+	u_char *fmt = (u_char *)fmt0;
+	int c;		/* character from format, or conversion */
+	size_t width;	/* field width, or 0 */
+	char *p;	/* points into all kinds of strings */
+	int n;		/* handy integer */
+	int flags;	/* flags as defined above */
+	char *p0;	/* saves original value of p when necessary */
+	int nassigned;		/* number of fields assigned */
+	int nread;		/* number of characters consumed from fp */
+	int base;		/* base argument to strtoimax/strtouimax */
+	char ccltab[256];	/* character class table for %[...] */
+	char buf[BUF];		/* buffer for numeric conversions */
+#ifdef SCANF_WIDE_CHAR
+	wchar_t *wcp;		/* handy wide character pointer */
+	size_t nconv;		/* length of multibyte sequence converted */
+	mbstate_t mbs;
+#endif
+
+	/* `basefix' is used to avoid `if' tests in the integer scanner */
+	static short basefix[17] =
+		{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+	_SET_ORIENTATION(fp, -1);
+
+	nassigned = 0;
+	nread = 0;
+	base = 0;		/* XXX just to keep gcc happy */
+	for (;;) {
+		c = *fmt++;
+		if (c == 0)
+			return (nassigned);
+		if (isspace(c)) {
+			while ((fp->_r > 0 || __srefill(fp) == 0) &&
+			    isspace(*fp->_p))
+				nread++, fp->_r--, fp->_p++;
+			continue;
+		}
+		if (c != '%')
+			goto literal;
+		width = 0;
+		flags = 0;
+		/*
+		 * switch on the format.  continue if done;
+		 * break once format type is derived.
+		 */
+again:		c = *fmt++;
+		switch (c) {
+		case '%':
+literal:
+			if (fp->_r <= 0 && __srefill(fp))
+				goto input_failure;
+			if (*fp->_p != c)
+				goto match_failure;
+			fp->_r--, fp->_p++;
+			nread++;
+			continue;
+
+		case '*':
+			flags |= SUPPRESS;
+			goto again;
+		case 'j':
+			flags |= MAXINT;
+			goto again;
+		case 'L':
+			flags |= LONGDBL;
+			goto again;
+		case 'h':
+			if (*fmt == 'h') {
+				fmt++;
+				flags |= SHORTSHORT;
+			} else {
+				flags |= SHORT;
+			}
+			goto again;
+		case 'l':
+			if (*fmt == 'l') {
+				fmt++;
+				flags |= LLONG;
+			} else {
+				flags |= LONG;
+			}
+			goto again;
+		case 'q':
+			flags |= LLONG;		/* deprecated */
+			goto again;
+		case 't':
+			flags |= PTRINT;
+			goto again;
+		case 'z':
+			flags |= SIZEINT;
+			goto again;
+
+		case '0': case '1': case '2': case '3': case '4':
+		case '5': case '6': case '7': case '8': case '9':
+			width = width * 10 + c - '0';
+			goto again;
+
+		/*
+		 * Conversions.
+		 * Those marked `compat' are for 4.[123]BSD compatibility.
+		 *
+		 * (According to ANSI, E and X formats are supposed
+		 * to the same as e and x.  Sorry about that.)
+		 */
+		case 'D':	/* compat */
+			flags |= LONG;
+			/* FALLTHROUGH */
+		case 'd':
+			c = CT_INT;
+			base = 10;
+			break;
+
+		case 'i':
+			c = CT_INT;
+			base = 0;
+			break;
+
+		case 'O':	/* compat */
+			flags |= LONG;
+			/* FALLTHROUGH */
+		case 'o':
+			c = CT_INT;
+			flags |= UNSIGNED;
+			base = 8;
+			break;
+
+		case 'u':
+			c = CT_INT;
+			flags |= UNSIGNED;
+			base = 10;
+			break;
+
+		case 'X':
+		case 'x':
+			flags |= PFXOK;	/* enable 0x prefixing */
+			c = CT_INT;
+			flags |= UNSIGNED;
+			base = 16;
+			break;
+
+#ifdef FLOATING_POINT
+		case 'e': case 'E':
+		case 'f': case 'F':
+		case 'g': case 'G':
+		case 'a': case 'A':
+			c = CT_FLOAT;
+			break;
+#endif
+
+		case 's':
+			c = CT_STRING;
+			break;
+
+		case '[':
+			fmt = __sccl(ccltab, fmt);
+			flags |= NOSKIP;
+			c = CT_CCL;
+			break;
+
+		case 'c':
+			flags |= NOSKIP;
+			c = CT_CHAR;
+			break;
+
+		case 'p':	/* pointer format is like hex */
+			flags |= POINTER | PFXOK;
+			c = CT_INT;
+			flags |= UNSIGNED;
+			base = 16;
+			break;
+
+		case 'n':
+			if (flags & SUPPRESS)
+				continue;
+			if (flags & SHORTSHORT)
+				*va_arg(ap, signed char *) = nread;
+			else if (flags & SHORT)
+				*va_arg(ap, short *) = nread;
+			else if (flags & LONG)
+				*va_arg(ap, long *) = nread;
+			else if (flags & SIZEINT)
+				*va_arg(ap, ssize_t *) = nread;
+			else if (flags & PTRINT)
+				*va_arg(ap, ptrdiff_t *) = nread;
+			else if (flags & LLONG)
+				*va_arg(ap, long long *) = nread;
+			else if (flags & MAXINT)
+				*va_arg(ap, intmax_t *) = nread;
+			else
+				*va_arg(ap, int *) = nread;
+			continue;
+
+		/*
+		 * Disgusting backwards compatibility hacks.	XXX
+		 */
+		case '\0':	/* compat */
+			return (EOF);
+
+		default:	/* compat */
+			if (isupper(c))
+				flags |= LONG;
+			c = CT_INT;
+			base = 10;
+			break;
+		}
+
+		/*
+		 * We have a conversion that requires input.
+		 */
+		if (fp->_r <= 0 && __srefill(fp))
+			goto input_failure;
+
+		/*
+		 * Consume leading white space, except for formats
+		 * that suppress this.
+		 */
+		if ((flags & NOSKIP) == 0) {
+			while (isspace(*fp->_p)) {
+				nread++;
+				if (--fp->_r > 0)
+					fp->_p++;
+				else if (__srefill(fp))
+					goto input_failure;
+			}
+			/*
+			 * Note that there is at least one character in
+			 * the buffer, so conversions that do not set NOSKIP
+			 * ca no longer result in an input failure.
+			 */
+		}
+
+		/*
+		 * Do the conversion.
+		 */
+		switch (c) {
+
+		case CT_CHAR:
+			/* scan arbitrary characters (sets NOSKIP) */
+			if (width == 0)
+				width = 1;
+#ifdef SCANF_WIDE_CHAR
+			if (flags & LONG) {
+				if ((flags & SUPPRESS) == 0)
+					wcp = va_arg(ap, wchar_t *);
+				else
+					wcp = NULL;
+				n = 0;
+				while (width != 0) {
+					if (n == MB_CUR_MAX) {
+						fp->_flags |= __SERR;
+						goto input_failure;
+					}
+					buf[n++] = *fp->_p;
+					fp->_p++;
+					fp->_r--;
+					bzero(&mbs, sizeof(mbs));
+					nconv = mbrtowc(wcp, buf, n, &mbs);
+					if (nconv == (size_t)-1) {
+						fp->_flags |= __SERR;
+						goto input_failure;
+					}
+					if (nconv == 0 && !(flags & SUPPRESS))
+						*wcp = L'\0';
+					if (nconv != (size_t)-2) {
+						nread += n;
+						width--;
+						if (!(flags & SUPPRESS))
+							wcp++;
+						n = 0;
+					}
+					if (fp->_r <= 0 && __srefill(fp)) {
+						if (n != 0) {
+							fp->_flags |= __SERR;
+							goto input_failure;
+						}
+						break;
+					}
+				}
+				if (!(flags & SUPPRESS))
+					nassigned++;
+			} else
+#endif /* SCANF_WIDE_CHAR */
+			if (flags & SUPPRESS) {
+				size_t sum = 0;
+				for (;;) {
+					if ((n = fp->_r) < width) {
+						sum += n;
+						width -= n;
+						fp->_p += n;
+						if (__srefill(fp)) {
+							if (sum == 0)
+							    goto input_failure;
+							break;
+						}
+					} else {
+						sum += width;
+						fp->_r -= width;
+						fp->_p += width;
+						break;
+					}
+				}
+				nread += sum;
+			} else {
+				size_t r = fread((void *)va_arg(ap, char *), 1,
+				    width, fp);
+
+				if (r == 0)
+					goto input_failure;
+				nread += r;
+				nassigned++;
+			}
+			break;
+
+		case CT_CCL:
+			/* scan a (nonempty) character class (sets NOSKIP) */
+			if (width == 0)
+				width = (size_t)~0;	/* `infinity' */
+#ifdef SCANF_WIDE_CHAR
+			/* take only those things in the class */
+			if (flags & LONG) {
+				wchar_t twc;
+				int nchars;
+
+				if ((flags & SUPPRESS) == 0)
+					wcp = va_arg(ap, wchar_t *);
+				else
+					wcp = &twc;
+				n = 0;
+				nchars = 0;
+				while (width != 0) {
+					if (n == MB_CUR_MAX) {
+						fp->_flags |= __SERR;
+						goto input_failure;
+					}
+					buf[n++] = *fp->_p;
+					fp->_p++;
+					fp->_r--;
+					bzero(&mbs, sizeof(mbs));
+					nconv = mbrtowc(wcp, buf, n, &mbs);
+					if (nconv == (size_t)-1) {
+						fp->_flags |= __SERR;
+						goto input_failure;
+					}
+					if (nconv == 0)
+						*wcp = L'\0';
+					if (nconv != (size_t)-2) {
+						if (wctob(*wcp) != EOF &&
+						    !ccltab[wctob(*wcp)]) {
+							while (n != 0) {
+								n--;
+								ungetc(buf[n],
+								    fp);
+							}
+							break;
+						}
+						nread += n;
+						width--;
+						if (!(flags & SUPPRESS))
+							wcp++;
+						nchars++;
+						n = 0;
+					}
+					if (fp->_r <= 0 && __srefill(fp)) {
+						if (n != 0) {
+							fp->_flags |= __SERR;
+							goto input_failure;
+						}
+						break;
+					}
+				}
+				if (n != 0) {
+					fp->_flags |= __SERR;
+					goto input_failure;
+				}
+				n = nchars;
+				if (n == 0)
+					goto match_failure;
+				if (!(flags & SUPPRESS)) {
+					*wcp = L'\0';
+					nassigned++;
+				}
+			} else
+#endif /* SCANF_WIDE_CHAR */
+			/* take only those things in the class */
+			if (flags & SUPPRESS) {
+				n = 0;
+				while (ccltab[*fp->_p]) {
+					n++, fp->_r--, fp->_p++;
+					if (--width == 0)
+						break;
+					if (fp->_r <= 0 && __srefill(fp)) {
+						if (n == 0)
+							goto input_failure;
+						break;
+					}
+				}
+				if (n == 0)
+					goto match_failure;
+			} else {
+				p0 = p = va_arg(ap, char *);
+				while (ccltab[*fp->_p]) {
+					fp->_r--;
+					*p++ = *fp->_p++;
+					if (--width == 0)
+						break;
+					if (fp->_r <= 0 && __srefill(fp)) {
+						if (p == p0)
+							goto input_failure;
+						break;
+					}
+				}
+				n = p - p0;
+				if (n == 0)
+					goto match_failure;
+				*p = '\0';
+				nassigned++;
+			}
+			nread += n;
+			break;
+
+		case CT_STRING:
+			/* like CCL, but zero-length string OK, & no NOSKIP */
+			if (width == 0)
+				width = (size_t)~0;
+#ifdef SCANF_WIDE_CHAR
+			if (flags & LONG) {
+				wchar_t twc;
+
+				if ((flags & SUPPRESS) == 0)
+					wcp = va_arg(ap, wchar_t *);
+				else
+					wcp = &twc;
+				n = 0;
+				while (!isspace(*fp->_p) && width != 0) {
+					if (n == MB_CUR_MAX) {
+						fp->_flags |= __SERR;
+						goto input_failure;
+					}
+					buf[n++] = *fp->_p;
+					fp->_p++;
+					fp->_r--;
+					bzero(&mbs, sizeof(mbs));
+					nconv = mbrtowc(wcp, buf, n, &mbs);
+					if (nconv == (size_t)-1) {
+						fp->_flags |= __SERR;
+						goto input_failure;
+					}
+					if (nconv == 0)
+						*wcp = L'\0';
+					if (nconv != (size_t)-2) {
+						if (iswspace(*wcp)) {
+							while (n != 0) {
+								n--;
+								ungetc(buf[n],
+								    fp);
+							}
+							break;
+						}
+						nread += n;
+						width--;
+						if (!(flags & SUPPRESS))
+							wcp++;
+						n = 0;
+					}
+					if (fp->_r <= 0 && __srefill(fp)) {
+						if (n != 0) {
+							fp->_flags |= __SERR;
+							goto input_failure;
+						}
+						break;
+					}
+				}
+				if (!(flags & SUPPRESS)) {
+					*wcp = L'\0';
+					nassigned++;
+				}
+			} else
+#endif /* SCANF_WIDE_CHAR */
+			if (flags & SUPPRESS) {
+				n = 0;
+				while (!isspace(*fp->_p)) {
+					n++, fp->_r--, fp->_p++;
+					if (--width == 0)
+						break;
+					if (fp->_r <= 0 && __srefill(fp))
+						break;
+				}
+				nread += n;
+			} else {
+				p0 = p = va_arg(ap, char *);
+				while (!isspace(*fp->_p)) {
+					fp->_r--;
+					*p++ = *fp->_p++;
+					if (--width == 0)
+						break;
+					if (fp->_r <= 0 && __srefill(fp))
+						break;
+				}
+				*p = '\0';
+				nread += p - p0;
+				nassigned++;
+			}
+			continue;
+
+		case CT_INT:
+			/* scan an integer as if by strtoimax/strtoumax */
+#ifdef hardway
+			if (width == 0 || width > sizeof(buf) - 1)
+				width = sizeof(buf) - 1;
+#else
+			/* size_t is unsigned, hence this optimisation */
+			if (--width > sizeof(buf) - 2)
+				width = sizeof(buf) - 2;
+			width++;
+#endif
+			flags |= SIGNOK | NDIGITS | NZDIGITS;
+			for (p = buf; width; width--) {
+				c = *fp->_p;
+				/*
+				 * Switch on the character; `goto ok'
+				 * if we accept it as a part of number.
+				 */
+				switch (c) {
+
+				/*
+				 * The digit 0 is always legal, but is
+				 * special.  For %i conversions, if no
+				 * digits (zero or nonzero) have been
+				 * scanned (only signs), we will have
+				 * base==0.  In that case, we should set
+				 * it to 8 and enable 0x prefixing.
+				 * Also, if we have not scanned zero digits
+				 * before this, do not turn off prefixing
+				 * (someone else will turn it off if we
+				 * have scanned any nonzero digits).
+				 */
+				case '0':
+					if (base == 0) {
+						base = 8;
+						flags |= PFXOK;
+					}
+					if (flags & NZDIGITS)
+					    flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
+					else
+					    flags &= ~(SIGNOK|PFXOK|NDIGITS);
+					goto ok;
+
+				/* 1 through 7 always legal */
+				case '1': case '2': case '3':
+				case '4': case '5': case '6': case '7':
+					base = basefix[base];
+					flags &= ~(SIGNOK | PFXOK | NDIGITS);
+					goto ok;
+
+				/* digits 8 and 9 ok iff decimal or hex */
+				case '8': case '9':
+					base = basefix[base];
+					if (base <= 8)
+						break;	/* not legal here */
+					flags &= ~(SIGNOK | PFXOK | NDIGITS);
+					goto ok;
+
+				/* letters ok iff hex */
+				case 'A': case 'B': case 'C':
+				case 'D': case 'E': case 'F':
+				case 'a': case 'b': case 'c':
+				case 'd': case 'e': case 'f':
+					/* no need to fix base here */
+					if (base <= 10)
+						break;	/* not legal here */
+					flags &= ~(SIGNOK | PFXOK | NDIGITS);
+					goto ok;
+
+				/* sign ok only as first character */
+				case '+': case '-':
+					if (flags & SIGNOK) {
+						flags &= ~SIGNOK;
+						flags |= HAVESIGN;
+						goto ok;
+					}
+					break;
+
+				/*
+				 * x ok iff flag still set and 2nd char (or
+				 * 3rd char if we have a sign).
+				 */
+				case 'x': case 'X':
+					if ((flags & PFXOK) && p ==
+					    buf + 1 + !!(flags & HAVESIGN)) {
+						base = 16;	/* if %i */
+						flags &= ~PFXOK;
+						goto ok;
+					}
+					break;
+				}
+
+				/*
+				 * If we got here, c is not a legal character
+				 * for a number.  Stop accumulating digits.
+				 */
+				break;
+		ok:
+				/*
+				 * c is legal: store it and look at the next.
+				 */
+				*p++ = c;
+				if (--fp->_r > 0)
+					fp->_p++;
+				else if (__srefill(fp))
+					break;		/* EOF */
+			}
+			/*
+			 * If we had only a sign, it is no good; push
+			 * back the sign.  If the number ends in `x',
+			 * it was [sign] '0' 'x', so push back the x
+			 * and treat it as [sign] '0'.
+			 */
+			if (flags & NDIGITS) {
+				if (p > buf)
+					(void) ungetc(*(u_char *)--p, fp);
+				goto match_failure;
+			}
+			c = ((u_char *)p)[-1];
+			if (c == 'x' || c == 'X') {
+				--p;
+				(void) ungetc(c, fp);
+			}
+			if ((flags & SUPPRESS) == 0) {
+				uintmax_t res;
+
+				*p = '\0';
+				if (flags & UNSIGNED)
+					res = strtoumax(buf, NULL, base);
+				else
+					res = strtoimax(buf, NULL, base);
+				if (flags & POINTER)
+					*va_arg(ap, void **) =
+					    (void *)(uintptr_t)res;
+				else if (flags & MAXINT)
+					*va_arg(ap, intmax_t *) = res;
+				else if (flags & LLONG)
+					*va_arg(ap, long long *) = res;
+				else if (flags & SIZEINT)
+					*va_arg(ap, ssize_t *) = res;
+				else if (flags & PTRINT)
+					*va_arg(ap, ptrdiff_t *) = res;
+				else if (flags & LONG)
+					*va_arg(ap, long *) = res;
+				else if (flags & SHORT)
+					*va_arg(ap, short *) = res;
+				else if (flags & SHORTSHORT)
+					*va_arg(ap, signed char *) = res;
+				else
+					*va_arg(ap, int *) = res;
+				nassigned++;
+			}
+			nread += p - buf;
+			break;
+
+#ifdef FLOATING_POINT
+		case CT_FLOAT:
+			/* scan a floating point number as if by strtod */
+#ifdef hardway
+			if (width == 0 || width > sizeof(buf) - 1)
+				width = sizeof(buf) - 1;
+#else
+			/* size_t is unsigned, hence this optimisation */
+			if (--width > sizeof(buf) - 2)
+				width = sizeof(buf) - 2;
+			width++;
+#endif
+			flags |= SIGNOK | NDIGITS | DPTOK | EXPOK;
+			for (p = buf; width; width--) {
+				c = *fp->_p;
+				/*
+				 * This code mimicks the integer conversion
+				 * code, but is much simpler.
+				 */
+				switch (c) {
+
+				case '0': case '1': case '2': case '3':
+				case '4': case '5': case '6': case '7':
+				case '8': case '9':
+					flags &= ~(SIGNOK | NDIGITS);
+					goto fok;
+
+				case '+': case '-':
+					if (flags & SIGNOK) {
+						flags &= ~SIGNOK;
+						goto fok;
+					}
+					break;
+				case '.':
+					if (flags & DPTOK) {
+						flags &= ~(SIGNOK | DPTOK);
+						goto fok;
+					}
+					break;
+				case 'e': case 'E':
+					/* no exponent without some digits */
+					if ((flags&(NDIGITS|EXPOK)) == EXPOK) {
+						flags =
+						    (flags & ~(EXPOK|DPTOK)) |
+						    SIGNOK | NDIGITS;
+						goto fok;
+					}
+					break;
+				}
+				break;
+		fok:
+				*p++ = c;
+				if (--fp->_r > 0)
+					fp->_p++;
+				else if (__srefill(fp))
+					break;	/* EOF */
+			}
+			/*
+			 * If no digits, might be missing exponent digits
+			 * (just give back the exponent) or might be missing
+			 * regular digits, but had sign and/or decimal point.
+			 */
+			if (flags & NDIGITS) {
+				if (flags & EXPOK) {
+					/* no digits at all */
+					while (p > buf)
+						ungetc(*(u_char *)--p, fp);
+					goto match_failure;
+				}
+				/* just a bad exponent (e and maybe sign) */
+				c = *(u_char *)--p;
+				if (c != 'e' && c != 'E') {
+					(void) ungetc(c, fp);/* sign */
+					c = *(u_char *)--p;
+				}
+				(void) ungetc(c, fp);
+			}
+			if ((flags & SUPPRESS) == 0) {
+				*p = '\0';
+				if (flags & LONGDBL) {
+					long double res = strtold(buf,
+					    (char **)NULL);
+					*va_arg(ap, long double *) = res;
+				} else if (flags & LONG) {
+					double res = strtod(buf, (char **)NULL);
+					*va_arg(ap, double *) = res;
+				} else {
+					float res = strtof(buf, (char **)NULL);
+					*va_arg(ap, float *) = res;
+				}
+				nassigned++;
+			}
+			nread += p - buf;
+			break;
+#endif /* FLOATING_POINT */
+		}
+	}
+input_failure:
+	if (nassigned == 0)
+		nassigned = -1;
+match_failure:
+	return (nassigned);
+}
+
+/*
+ * Fill in the given table from the scanset at the given format
+ * (just after `[').  Return a pointer to the character past the
+ * closing `]'.  The table has a 1 wherever characters should be
+ * considered part of the scanset.
+ */
+static u_char *
+__sccl(char *tab, u_char *fmt)
+{
+	int c, n, v;
+
+	/* first `clear' the whole table */
+	c = *fmt++;		/* first char hat => negated scanset */
+	if (c == '^') {
+		v = 1;		/* default => accept */
+		c = *fmt++;	/* get new first char */
+	} else
+		v = 0;		/* default => reject */
+	/* should probably use memset here */
+	for (n = 0; n < 256; n++)
+		tab[n] = v;
+	if (c == 0)
+		return (fmt - 1);/* format ended before closing ] */
+
+	/*
+	 * Now set the entries corresponding to the actual scanset
+	 * to the opposite of the above.
+	 *
+	 * The first character may be ']' (or '-') without being special;
+	 * the last character may be '-'.
+	 */
+	v = 1 - v;
+	for (;;) {
+		tab[c] = v;		/* take character c */
+doswitch:
+		n = *fmt++;		/* and examine the next */
+		switch (n) {
+
+		case 0:			/* format ended too soon */
+			return (fmt - 1);
+
+		case '-':
+			/*
+			 * A scanset of the form
+			 *	[01+-]
+			 * is defined as `the digit 0, the digit 1,
+			 * the character +, the character -', but
+			 * the effect of a scanset such as
+			 *	[a-zA-Z0-9]
+			 * is implementation defined.  The V7 Unix
+			 * scanf treats `a-z' as `the letters a through
+			 * z', but treats `a-a' as `the letter a, the
+			 * character -, and the letter a'.
+			 *
+			 * For compatibility, the `-' is not considerd
+			 * to define a range if the character following
+			 * it is either a close bracket (required by ANSI)
+			 * or is not numerically greater than the character
+			 * we just stored in the table (c).
+			 */
+			n = *fmt;
+			if (n == ']' || n < c) {
+				c = '-';
+				break;	/* resume the for(;;) */
+			}
+			fmt++;
+			do {		/* fill in the range */
+				tab[++c] = v;
+			} while (c < n);
+#if 1	/* XXX another disgusting compatibility hack */
+			/*
+			 * Alas, the V7 Unix scanf also treats formats
+			 * such as [a-c-e] as `the letters a through e'.
+			 * This too is permitted by the standard....
+			 */
+			goto doswitch;
+#else
+			c = *fmt++;
+			if (c == 0)
+				return (fmt - 1);
+			if (c == ']')
+				return (fmt);
+#endif
+			break;
+
+		case ']':		/* end of scanset */
+			return (fmt);
+
+		default:		/* just another character */
+			c = n;
+			break;
+		}
+	}
+	/* NOTREACHED */
+}
+
+int
+vfscanf(FILE *fp, const char *fmt0, __va_list ap)
+{
+	int r;
+
+	FLOCKFILE(fp);
+	r = __svfscanf(fp, fmt0, ap);
+	FUNLOCKFILE(fp);
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c
new file mode 100644
index 0000000..ef0ca43
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c
@@ -0,0 +1,1521 @@
+/*	$OpenBSD: vfwprintf.c,v 1.11 2014/06/04 07:45:25 stsp Exp $ */
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Actual wprintf innards.
+ *
+ * This code is large and complicated...
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include <errno.h>
+#include <langinfo.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "local.h"
+#include "fvwrite.h"
+
+union arg {
+	int			intarg;
+	unsigned int		uintarg;
+	long			longarg;
+	unsigned long		ulongarg;
+	long long		longlongarg;
+	unsigned long long	ulonglongarg;
+	ptrdiff_t		ptrdiffarg;
+	size_t			sizearg;
+	ssize_t			ssizearg;
+	intmax_t		intmaxarg;
+	uintmax_t		uintmaxarg;
+	void			*pvoidarg;
+	char			*pchararg;
+	signed char		*pschararg;
+	short			*pshortarg;
+	int			*pintarg;
+	long			*plongarg;
+	long long		*plonglongarg;
+	ptrdiff_t		*pptrdiffarg;
+	ssize_t			*pssizearg;
+	intmax_t		*pintmaxarg;
+#ifdef FLOATING_POINT
+	double			doublearg;
+	long double		longdoublearg;
+#endif
+	wint_t			wintarg;
+	wchar_t			*pwchararg;
+};
+
+static int __find_arguments(const wchar_t *fmt0, va_list ap, union arg **argtable,
+    size_t *argtablesiz);
+static int __grow_type_table(unsigned char **typetable, int *tablesize);
+
+/*
+ * Helper function for `fprintf to unbuffered unix file': creates a
+ * temporary buffer.  We only work on write-only files; this avoids
+ * worries about ungetc buffers and so forth.
+ */
+static int
+__sbprintf(FILE *fp, const wchar_t *fmt, va_list ap)
+{
+	int ret;
+	FILE fake;
+	struct __sfileext fakeext;
+	unsigned char buf[BUFSIZ];
+
+	_FILEEXT_SETUP(&fake, &fakeext);
+	/* copy the important variables */
+	fake._flags = fp->_flags & ~__SNBF;
+	fake._file = fp->_file;
+	fake._cookie = fp->_cookie;
+	fake._write = fp->_write;
+
+	/* set up the buffer */
+	fake._bf._base = fake._p = buf;
+	fake._bf._size = fake._w = sizeof(buf);
+	fake._lbfsize = 0;	/* not actually used, but Just In Case */
+
+	/* do the work, then copy any error status */
+	ret = __vfwprintf(&fake, fmt, ap);
+	if (ret >= 0 && __sflush(&fake))
+		ret = EOF;
+	if (fake._flags & __SERR)
+		fp->_flags |= __SERR;
+	return (ret);
+}
+
+/*
+ * Like __fputwc_unlock, but handles fake string (__SSTR) files properly.
+ * File must already be locked.
+ */
+static wint_t
+__xfputwc(wchar_t wc, FILE *fp)
+{
+	mbstate_t mbs;
+	char buf[MB_LEN_MAX];
+	struct __suio uio;
+	struct __siov iov;
+	size_t len;
+
+	if ((fp->_flags & __SSTR) == 0)
+		return (__fputwc_unlock(wc, fp));
+
+	bzero(&mbs, sizeof(mbs));
+	len = wcrtomb(buf, wc, &mbs);
+	if (len == (size_t)-1) {
+		fp->_flags |= __SERR;
+		errno = EILSEQ;
+		return (WEOF);
+	}
+	uio.uio_iov = &iov;
+	uio.uio_resid = len;
+	uio.uio_iovcnt = 1;
+	iov.iov_base = buf;
+	iov.iov_len = len;
+	return (__sfvwrite(fp, &uio) != EOF ? (wint_t)wc : WEOF);
+}
+
+/*
+ * Convert a multibyte character string argument for the %s format to a wide
+ * string representation. ``prec'' specifies the maximum number of bytes
+ * to output. If ``prec'' is greater than or equal to zero, we can't assume
+ * that the multibyte character string ends in a null character.
+ * 
+ * Returns NULL on failure.
+ * To find out what happened check errno for ENOMEM, EILSEQ and EINVAL.
+ */
+static wchar_t *
+__mbsconv(char *mbsarg, int prec)
+{
+	mbstate_t mbs;
+	wchar_t *convbuf, *wcp;
+	const char *p;
+	size_t insize, nchars, nconv;
+
+	if (mbsarg == NULL)
+		return (NULL);
+
+	/*
+	 * Supplied argument is a multibyte string; convert it to wide
+	 * characters first.
+	 */
+	if (prec >= 0) {
+		/*
+		 * String is not guaranteed to be NUL-terminated. Find the
+		 * number of characters to print.
+		 */
+		p = mbsarg;
+		insize = nchars = nconv = 0;
+		bzero(&mbs, sizeof(mbs));
+		while (nchars != (size_t)prec) {
+			nconv = mbrlen(p, MB_CUR_MAX, &mbs);
+			if (nconv == (size_t)0 || nconv == (size_t)-1 ||
+			    nconv == (size_t)-2)
+				break;
+			p += nconv;
+			nchars++;
+			insize += nconv;
+		}
+		if (nconv == (size_t)-1 || nconv == (size_t)-2)
+			return (NULL);
+	} else
+		insize = strlen(mbsarg);
+
+	/*
+	 * Allocate buffer for the result and perform the conversion,
+	 * converting at most `size' bytes of the input multibyte string to
+	 * wide characters for printing.
+	 */
+	convbuf = calloc(insize + 1, sizeof(*convbuf));
+	if (convbuf == NULL)
+		return (NULL);
+	wcp = convbuf;
+	p = mbsarg;
+	bzero(&mbs, sizeof(mbs));
+	nconv = 0;
+	while (insize != 0) {
+		nconv = mbrtowc(wcp, p, insize, &mbs);
+		if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
+			break;
+		wcp++;
+		p += nconv;
+		insize -= nconv;
+	}
+	if (nconv == (size_t)-1 || nconv == (size_t)-2) {
+		free(convbuf);
+		return (NULL);
+	}
+	*wcp = '\0';
+
+	return (convbuf);
+}
+
+#ifdef FLOATING_POINT
+#include <float.h>
+#include <locale.h>
+#include <math.h>
+#include "floatio.h"
+#include "gdtoa.h"
+
+#define	DEFPREC		6
+
+static int exponent(wchar_t *, int, int);
+#endif /* FLOATING_POINT */
+
+/*
+ * The size of the buffer we use as scratch space for integer
+ * conversions, among other things.  Technically, we would need the
+ * most space for base 10 conversions with thousands' grouping
+ * characters between each pair of digits.  100 bytes is a
+ * conservative overestimate even for a 128-bit uintmax_t.
+ */
+#define BUF	100
+
+#define STATIC_ARG_TBL_SIZE 8	/* Size of static argument table. */
+
+
+/*
+ * Macros for converting digits to letters and vice versa
+ */
+#define	to_digit(c)	((c) - '0')
+#define is_digit(c)	((unsigned)to_digit(c) <= 9)
+#define	to_char(n)	((wchar_t)((n) + '0'))
+
+/*
+ * Flags used during conversion.
+ */
+#define	ALT		0x0001		/* alternate form */
+#define	LADJUST		0x0004		/* left adjustment */
+#define	LONGDBL		0x0008		/* long double */
+#define	LONGINT		0x0010		/* long integer */
+#define	LLONGINT	0x0020		/* long long integer */
+#define	SHORTINT	0x0040		/* short integer */
+#define	ZEROPAD		0x0080		/* zero (as opposed to blank) pad */
+#define FPT		0x0100		/* Floating point number */
+#define PTRINT		0x0200		/* (unsigned) ptrdiff_t */
+#define SIZEINT		0x0400		/* (signed) size_t */
+#define CHARINT		0x0800		/* 8 bit integer */
+#define MAXINT		0x1000		/* largest integer size (intmax_t) */
+
+int
+__vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, __va_list ap)
+{
+	wchar_t *fmt;		/* format string */
+	wchar_t ch;		/* character from fmt */
+	int n, n2, n3;		/* handy integers (short term usage) */
+	wchar_t *cp;		/* handy char pointer (short term usage) */
+	int flags;		/* flags as above */
+	int ret;		/* return value accumulator */
+	int width;		/* width from format (%8d), or 0 */
+	int prec;		/* precision from format; <0 for N/A */
+	wchar_t sign;		/* sign prefix (' ', '+', '-', or \0) */
+#ifdef FLOATING_POINT
+	/*
+	 * We can decompose the printed representation of floating
+	 * point numbers into several parts, some of which may be empty:
+	 *
+	 * [+|-| ] [0x|0X] MMM . NNN [e|E|p|P] [+|-] ZZ
+	 *    A       B     ---C---      D       E   F
+	 *
+	 * A:	'sign' holds this value if present; '\0' otherwise
+	 * B:	ox[1] holds the 'x' or 'X'; '\0' if not hexadecimal
+	 * C:	cp points to the string MMMNNN.  Leading and trailing
+	 *	zeros are not in the string and must be added.
+	 * D:	expchar holds this character; '\0' if no exponent, e.g. %f
+	 * F:	at least two digits for decimal, at least one digit for hex
+	 */
+	char *decimal_point = NULL;
+	int signflag;		/* true if float is negative */
+	union {			/* floating point arguments %[aAeEfFgG] */
+		double dbl;
+		long double ldbl;
+	} fparg;
+	int expt;		/* integer value of exponent */
+	char expchar;		/* exponent character: [eEpP\0] */
+	char *dtoaend;		/* pointer to end of converted digits */
+	int expsize;		/* character count for expstr */
+	int lead;		/* sig figs before decimal or group sep */
+	int ndig;		/* actual number of digits returned by dtoa */
+	wchar_t expstr[MAXEXPDIG+2];	/* buffer for exponent string: e+ZZZ */
+	char *dtoaresult = NULL;
+#endif
+
+	uintmax_t _umax;	/* integer arguments %[diouxX] */
+	enum { OCT, DEC, HEX } base;	/* base for %[diouxX] conversion */
+	int dprec;		/* a copy of prec if %[diouxX], 0 otherwise */
+	int realsz;		/* field size expanded by dprec */
+	int size;		/* size of converted field or string */
+	const char *xdigs;	/* digits for %[xX] conversion */
+	wchar_t buf[BUF];	/* buffer with space for digits of uintmax_t */
+	wchar_t ox[2];		/* space for 0x; ox[1] is either x, X, or \0 */
+	union arg *argtable;	/* args, built due to positional arg */
+	union arg statargtable[STATIC_ARG_TBL_SIZE];
+	size_t argtablesiz;
+	int nextarg;		/* 1-based argument index */
+	va_list orgap;		/* original argument pointer */
+	wchar_t *convbuf;	/* buffer for multibyte to wide conversion */
+
+	/*
+	 * Choose PADSIZE to trade efficiency vs. size.  If larger printf
+	 * fields occur frequently, increase PADSIZE and make the initialisers
+	 * below longer.
+	 */
+#define	PADSIZE	16		/* pad chunk size */
+	static wchar_t blanks[PADSIZE] =
+	 {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
+	static wchar_t zeroes[PADSIZE] =
+	 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
+
+	static const char xdigs_lower[16] = "0123456789abcdef";
+	static const char xdigs_upper[16] = "0123456789ABCDEF";
+
+	/*
+	 * BEWARE, these `goto error' on error, PRINT uses 'n3',
+	 * PAD uses `n' and 'n3', and PRINTANDPAD uses 'n', 'n2', and 'n3'.
+	 */
+#define	PRINT(ptr, len)	do {	\
+	for (n3 = 0; n3 < (len); n3++) {	\
+		if ((__xfputwc((ptr)[n3], fp)) == WEOF)	\
+			goto error; \
+	} \
+} while (0)
+#define	PAD(howmany, with) do { \
+	if ((n = (howmany)) > 0) { \
+		while (n > PADSIZE) { \
+			PRINT(with, PADSIZE); \
+			n -= PADSIZE; \
+		} \
+		PRINT(with, n); \
+	} \
+} while (0)
+#define	PRINTANDPAD(p, ep, len, with) do {	\
+	n2 = (ep) - (p);       			\
+	if (n2 > (len))				\
+		n2 = (len);			\
+	if (n2 > 0)				\
+		PRINT((p), n2);			\
+	PAD((len) - (n2 > 0 ? n2 : 0), (with));	\
+} while(0)
+
+	/*
+	 * To extend shorts properly, we need both signed and unsigned
+	 * argument extraction methods.
+	 */
+#define	SARG() \
+	((intmax_t)(flags&MAXINT ? GETARG(intmax_t) : \
+	    flags&LLONGINT ? GETARG(long long) : \
+	    flags&LONGINT ? GETARG(long) : \
+	    flags&PTRINT ? GETARG(ptrdiff_t) : \
+	    flags&SIZEINT ? GETARG(ssize_t) : \
+	    flags&SHORTINT ? (short)GETARG(int) : \
+	    flags&CHARINT ? (signed char)GETARG(int) : \
+	    GETARG(int)))
+#define	UARG() \
+	((uintmax_t)(flags&MAXINT ? GETARG(uintmax_t) : \
+	    flags&LLONGINT ? GETARG(unsigned long long) : \
+	    flags&LONGINT ? GETARG(unsigned long) : \
+	    flags&PTRINT ? (uintptr_t)GETARG(ptrdiff_t) : /* XXX */ \
+	    flags&SIZEINT ? GETARG(size_t) : \
+	    flags&SHORTINT ? (unsigned short)GETARG(int) : \
+	    flags&CHARINT ? (unsigned char)GETARG(int) : \
+	    GETARG(unsigned int)))
+
+	/*
+	 * Append a digit to a value and check for overflow.
+	 */
+#define APPEND_DIGIT(val, dig) do { \
+	if ((val) > INT_MAX / 10) \
+		goto overflow; \
+	(val) *= 10; \
+	if ((val) > INT_MAX - to_digit((dig))) \
+		goto overflow; \
+	(val) += to_digit((dig)); \
+} while (0)
+
+	 /*
+	  * Get * arguments, including the form *nn$.  Preserve the nextarg
+	  * that the argument can be gotten once the type is determined.
+	  */
+#define GETASTER(val) \
+	n2 = 0; \
+	cp = fmt; \
+	while (is_digit(*cp)) { \
+		APPEND_DIGIT(n2, *cp); \
+		cp++; \
+	} \
+	if (*cp == '$') { \
+		int hold = nextarg; \
+		if (argtable == NULL) { \
+			argtable = statargtable; \
+			__find_arguments(fmt0, orgap, &argtable, &argtablesiz); \
+		} \
+		nextarg = n2; \
+		val = GETARG(int); \
+		nextarg = hold; \
+		fmt = ++cp; \
+	} else { \
+		val = GETARG(int); \
+	}
+
+/*
+* Get the argument indexed by nextarg.   If the argument table is
+* built, use it to get the argument.  If its not, get the next
+* argument (and arguments must be gotten sequentially).
+*/
+#define GETARG(type) \
+	((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \
+		(nextarg++, va_arg(ap, type)))
+
+	_SET_ORIENTATION(fp, 1);
+	/* sorry, fwprintf(read_only_file, "") returns EOF, not 0 */
+	if (cantwrite(fp)) {
+		errno = EBADF;
+		return (EOF);
+	}
+
+	/* optimise fwprintf(stderr) (and other unbuffered Unix files) */
+	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
+	    fp->_file >= 0)
+		return (__sbprintf(fp, fmt0, ap));
+
+	fmt = (wchar_t *)fmt0;
+	argtable = NULL;
+	nextarg = 1;
+	va_copy(orgap, ap);
+	ret = 0;
+	convbuf = NULL;
+
+	/*
+	 * Scan the format for conversions (`%' character).
+	 */
+	for (;;) {
+		for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
+			continue;
+		if (fmt != cp) {
+			ptrdiff_t m = fmt - cp;
+			if (m < 0 || m > INT_MAX - ret)
+				goto overflow;
+			PRINT(cp, m);
+			ret += m;
+		}
+		if (ch == '\0')
+			goto done;
+		fmt++;		/* skip over '%' */
+
+		flags = 0;
+		dprec = 0;
+		width = 0;
+		prec = -1;
+		sign = '\0';
+		ox[1] = '\0';
+
+rflag:		ch = *fmt++;
+reswitch:	switch (ch) {
+		case ' ':
+			/*
+			 * ``If the space and + flags both appear, the space
+			 * flag will be ignored.''
+			 *	-- ANSI X3J11
+			 */
+			if (!sign)
+				sign = ' ';
+			goto rflag;
+		case '#':
+			flags |= ALT;
+			goto rflag;
+		case '\'':
+			/* grouping not implemented */
+			goto rflag;
+		case '*':
+			/*
+			 * ``A negative field width argument is taken as a
+			 * - flag followed by a positive field width.''
+			 *	-- ANSI X3J11
+			 * They don't exclude field widths read from args.
+			 */
+			GETASTER(width);
+			if (width >= 0)
+				goto rflag;
+			if (width == INT_MIN)
+				goto overflow;
+			width = -width;
+			/* FALLTHROUGH */
+		case '-':
+			flags |= LADJUST;
+			goto rflag;
+		case '+':
+			sign = '+';
+			goto rflag;
+		case '.':
+			if ((ch = *fmt++) == '*') {
+				GETASTER(n);
+				prec = n < 0 ? -1 : n;
+				goto rflag;
+			}
+			n = 0;
+			while (is_digit(ch)) {
+				APPEND_DIGIT(n, ch);
+				ch = *fmt++;
+			}
+			if (ch == '$') {
+				nextarg = n;
+				if (argtable == NULL) {
+					argtable = statargtable;
+					__find_arguments(fmt0, orgap,
+					    &argtable, &argtablesiz);
+				}
+				goto rflag;
+			}
+			prec = n;
+			goto reswitch;
+		case '0':
+			/*
+			 * ``Note that 0 is taken as a flag, not as the
+			 * beginning of a field width.''
+			 *	-- ANSI X3J11
+			 */
+			flags |= ZEROPAD;
+			goto rflag;
+		case '1': case '2': case '3': case '4':
+		case '5': case '6': case '7': case '8': case '9':
+			n = 0;
+			do {
+				APPEND_DIGIT(n, ch);
+				ch = *fmt++;
+			} while (is_digit(ch));
+			if (ch == '$') {
+				nextarg = n;
+				if (argtable == NULL) {
+					argtable = statargtable;
+					__find_arguments(fmt0, orgap,
+					    &argtable, &argtablesiz);
+				}
+				goto rflag;
+			}
+			width = n;
+			goto reswitch;
+#ifdef FLOATING_POINT
+		case 'L':
+			flags |= LONGDBL;
+			goto rflag;
+#endif
+		case 'h':
+			if (*fmt == 'h') {
+				fmt++;
+				flags |= CHARINT;
+			} else {
+				flags |= SHORTINT;
+			}
+			goto rflag;
+		case 'j':
+			flags |= MAXINT;
+			goto rflag;
+		case 'l':
+			if (*fmt == 'l') {
+				fmt++;
+				flags |= LLONGINT;
+			} else {
+				flags |= LONGINT;
+			}
+			goto rflag;
+		case 'q':
+			flags |= LLONGINT;
+			goto rflag;
+		case 't':
+			flags |= PTRINT;
+			goto rflag;
+		case 'z':
+			flags |= SIZEINT;
+			goto rflag;
+		case 'C':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'c':
+			if (flags & LONGINT)
+				*(cp = buf) = (wchar_t)GETARG(wint_t);
+			else
+				*(cp = buf) = (wchar_t)btowc(GETARG(int));
+			size = 1;
+			sign = '\0';
+			break;
+		case 'D':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'd':
+		case 'i':
+			_umax = SARG();
+			if ((intmax_t)_umax < 0) {
+				_umax = -_umax;
+				sign = '-';
+			}
+			base = DEC;
+			goto number;
+#ifdef FLOATING_POINT
+		case 'a':
+		case 'A':
+			if (ch == 'a') {
+				ox[1] = 'x';
+				xdigs = xdigs_lower;
+				expchar = 'p';
+			} else {
+				ox[1] = 'X';
+				xdigs = xdigs_upper;
+				expchar = 'P';
+			}
+			if (prec >= 0)
+				prec++;
+			if (dtoaresult)
+				__freedtoa(dtoaresult);
+			if (flags & LONGDBL) {
+				fparg.ldbl = GETARG(long double);
+				dtoaresult =
+				    __hldtoa(fparg.ldbl, xdigs, prec,
+				    &expt, &signflag, &dtoaend);
+				if (dtoaresult == NULL) {
+					errno = ENOMEM;
+					goto error;
+				}
+			} else {
+				fparg.dbl = GETARG(double);
+				dtoaresult =
+				    __hdtoa(fparg.dbl, xdigs, prec,
+				    &expt, &signflag, &dtoaend);
+				if (dtoaresult == NULL) {
+					errno = ENOMEM;
+					goto error;
+				}
+			}
+			if (prec < 0)
+				prec = dtoaend - dtoaresult;
+			if (expt == INT_MAX)
+				ox[1] = '\0';
+			if (convbuf) {
+				free(convbuf);
+				convbuf = NULL;
+			}
+			cp = convbuf = __mbsconv(dtoaresult, -1);
+			if (cp == NULL)
+				goto error;
+			ndig = dtoaend - dtoaresult;
+			goto fp_common;
+		case 'e':
+		case 'E':
+			expchar = ch;
+			if (prec < 0)	/* account for digit before decpt */
+				prec = DEFPREC + 1;
+			else
+				prec++;
+			goto fp_begin;
+		case 'f':
+		case 'F':
+			expchar = '\0';
+			goto fp_begin;
+		case 'g':
+		case 'G':
+			expchar = ch - ('g' - 'e');
+ 			if (prec == 0)
+ 				prec = 1;
+fp_begin:
+			if (prec < 0)
+				prec = DEFPREC;
+			if (dtoaresult)
+				__freedtoa(dtoaresult);
+			if (flags & LONGDBL) {
+				fparg.ldbl = GETARG(long double);
+				dtoaresult =
+				    __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec,
+				    &expt, &signflag, &dtoaend);
+				if (dtoaresult == NULL) {
+					errno = ENOMEM;
+					goto error;
+				}
+			} else {
+				fparg.dbl = GETARG(double);
+				dtoaresult =
+				    __dtoa(fparg.dbl, expchar ? 2 : 3, prec,
+				    &expt, &signflag, &dtoaend);
+				if (dtoaresult == NULL) {
+					errno = ENOMEM;
+					goto error;
+				}
+				if (expt == 9999)
+					expt = INT_MAX;
+ 			}
+			if (convbuf) {
+				free(convbuf);
+				convbuf = NULL;
+			}
+			cp = convbuf = __mbsconv(dtoaresult, -1);
+			if (cp == NULL)
+				goto error;
+			ndig = dtoaend - dtoaresult;
+fp_common:
+			if (signflag)
+				sign = '-';
+			if (expt == INT_MAX) {	/* inf or nan */
+				if (*cp == 'N') {
+					cp = (ch >= 'a') ? L"nan" : L"NAN";
+					sign = '\0';
+				} else
+					cp = (ch >= 'a') ? L"inf" : L"INF";
+ 				size = 3;
+				flags &= ~ZEROPAD;
+ 				break;
+ 			}
+			flags |= FPT;
+ 			if (ch == 'g' || ch == 'G') {
+				if (expt > -4 && expt <= prec) {
+					/* Make %[gG] smell like %[fF] */
+					expchar = '\0';
+					if (flags & ALT)
+						prec -= expt;
+					else
+						prec = ndig - expt;
+					if (prec < 0)
+						prec = 0;
+				} else {
+					/*
+					 * Make %[gG] smell like %[eE], but
+					 * trim trailing zeroes if no # flag.
+					 */
+					if (!(flags & ALT))
+						prec = ndig;
+				}
+ 			}
+			if (expchar) {
+				expsize = exponent(expstr, expt - 1, expchar);
+				size = expsize + prec;
+				if (prec > 1 || flags & ALT)
+ 					++size;
+			} else {
+				/* space for digits before decimal point */
+				if (expt > 0)
+					size = expt;
+				else	/* "0" */
+					size = 1;
+				/* space for decimal pt and following digits */
+				if (prec || flags & ALT)
+					size += prec + 1;
+				lead = expt;
+			}
+			break;
+#endif /* FLOATING_POINT */
+#ifndef NO_PRINTF_PERCENT_N
+		case 'n':
+			if (flags & LLONGINT)
+				*GETARG(long long *) = ret;
+			else if (flags & LONGINT)
+				*GETARG(long *) = ret;
+			else if (flags & SHORTINT)
+				*GETARG(short *) = ret;
+			else if (flags & CHARINT)
+				*GETARG(signed char *) = ret;
+			else if (flags & PTRINT)
+				*GETARG(ptrdiff_t *) = ret;
+			else if (flags & SIZEINT)
+				*GETARG(ssize_t *) = ret;
+			else if (flags & MAXINT)
+				*GETARG(intmax_t *) = ret;
+			else
+				*GETARG(int *) = ret;
+			continue;	/* no output */
+#endif /* NO_PRINTF_PERCENT_N */
+		case 'O':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'o':
+			_umax = UARG();
+			base = OCT;
+			goto nosign;
+		case 'p':
+			/*
+			 * ``The argument shall be a pointer to void.  The
+			 * value of the pointer is converted to a sequence
+			 * of printable characters, in an implementation-
+			 * defined manner.''
+			 *	-- ANSI X3J11
+			 */
+			/* NOSTRICT */
+			_umax = (u_long)GETARG(void *);
+			base = HEX;
+			xdigs = xdigs_lower;
+			ox[1] = 'x';
+			goto nosign;
+		case 'S':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 's':
+			if (flags & LONGINT) {
+				if ((cp = GETARG(wchar_t *)) == NULL)
+					cp = L"(null)";
+			} else {
+				char *mbsarg;
+				if ((mbsarg = GETARG(char *)) == NULL)
+					mbsarg = "(null)";
+				if (convbuf) {
+					free(convbuf);
+					convbuf = NULL;
+				}
+				convbuf = __mbsconv(mbsarg, prec);
+				if (convbuf == NULL) {
+					fp->_flags |= __SERR;
+					goto error;
+				} else
+					cp = convbuf;
+			}
+			if (prec >= 0) {
+				/*
+				 * can't use wcslen; can only look for the
+				 * NUL in the first `prec' characters, and
+				 * wcslen() will go further.
+				 */
+				wchar_t *p = wmemchr(cp, 0, prec);
+
+				size = p ? (p - cp) : prec;
+			} else {
+				size_t len;
+
+				if ((len = wcslen(cp)) > INT_MAX)
+					goto overflow;
+				size = (int)len;
+			}
+			sign = '\0';
+			break;
+		case 'U':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'u':
+			_umax = UARG();
+			base = DEC;
+			goto nosign;
+		case 'X':
+			xdigs = xdigs_upper;
+			goto hex;
+		case 'x':
+			xdigs = xdigs_lower;
+hex:			_umax = UARG();
+			base = HEX;
+			/* leading 0x/X only if non-zero */
+			if (flags & ALT && _umax != 0)
+				ox[1] = ch;
+
+			/* unsigned conversions */
+nosign:			sign = '\0';
+			/*
+			 * ``... diouXx conversions ... if a precision is
+			 * specified, the 0 flag will be ignored.''
+			 *	-- ANSI X3J11
+			 */
+number:			if ((dprec = prec) >= 0)
+				flags &= ~ZEROPAD;
+
+			/*
+			 * ``The result of converting a zero value with an
+			 * explicit precision of zero is no characters.''
+			 *	-- ANSI X3J11
+			 */
+			cp = buf + BUF;
+			if (_umax != 0 || prec != 0) {
+				/*
+				 * Unsigned mod is hard, and unsigned mod
+				 * by a constant is easier than that by
+				 * a variable; hence this switch.
+				 */
+				switch (base) {
+				case OCT:
+					do {
+						*--cp = to_char(_umax & 7);
+						_umax >>= 3;
+					} while (_umax);
+					/* handle octal leading 0 */
+					if (flags & ALT && *cp != '0')
+						*--cp = '0';
+					break;
+
+				case DEC:
+					/* many numbers are 1 digit */
+					while (_umax >= 10) {
+						*--cp = to_char(_umax % 10);
+						_umax /= 10;
+					}
+					*--cp = to_char(_umax);
+					break;
+
+				case HEX:
+					do {
+						*--cp = xdigs[_umax & 15];
+						_umax >>= 4;
+					} while (_umax);
+					break;
+
+				default:
+					cp = L"bug in vfwprintf: bad base";
+					size = wcslen(cp);
+					goto skipsize;
+				}
+			}
+			size = buf + BUF - cp;
+			if (size > BUF)	/* should never happen */
+				abort();
+		skipsize:
+			break;
+		default:	/* "%?" prints ?, unless ? is NUL */
+			if (ch == '\0')
+				goto done;
+			/* pretend it was %c with argument ch */
+			cp = buf;
+			*cp = ch;
+			size = 1;
+			sign = '\0';
+			break;
+		}
+
+		/*
+		 * All reasonable formats wind up here.  At this point, `cp'
+		 * points to a string which (if not flags&LADJUST) should be
+		 * padded out to `width' places.  If flags&ZEROPAD, it should
+		 * first be prefixed by any sign or other prefix; otherwise,
+		 * it should be blank padded before the prefix is emitted.
+		 * After any left-hand padding and prefixing, emit zeroes
+		 * required by a decimal %[diouxX] precision, then print the
+		 * string proper, then emit zeroes required by any leftover
+		 * floating precision; finally, if LADJUST, pad with blanks.
+		 *
+		 * Compute actual size, so we know how much to pad.
+		 * size excludes decimal prec; realsz includes it.
+		 */
+		realsz = dprec > size ? dprec : size;
+		if (sign)
+			realsz++;
+		if (ox[1])
+			realsz+= 2;
+
+		/* right-adjusting blank padding */
+		if ((flags & (LADJUST|ZEROPAD)) == 0)
+			PAD(width - realsz, blanks);
+
+		/* prefix */
+		if (sign)
+			PRINT(&sign, 1);
+		if (ox[1]) {	/* ox[1] is either x, X, or \0 */
+			ox[0] = '0';
+			PRINT(ox, 2);
+		}
+
+		/* right-adjusting zero padding */
+		if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
+			PAD(width - realsz, zeroes);
+
+		/* leading zeroes from decimal precision */
+		PAD(dprec - size, zeroes);
+
+		/* the string or number proper */
+#ifdef FLOATING_POINT
+		if ((flags & FPT) == 0) {
+			PRINT(cp, size);
+		} else {	/* glue together f_p fragments */
+			if (decimal_point == NULL)
+				decimal_point = nl_langinfo(RADIXCHAR);
+			if (!expchar) {	/* %[fF] or sufficiently short %[gG] */
+				if (expt <= 0) {
+					PRINT(zeroes, 1);
+					if (prec || flags & ALT)
+						PRINT(decimal_point, 1);
+					PAD(-expt, zeroes);
+					/* already handled initial 0's */
+					prec += expt;
+ 				} else {
+					PRINTANDPAD(cp, convbuf + ndig,
+					    lead, zeroes);
+					cp += lead;
+					if (prec || flags & ALT)
+						PRINT(decimal_point, 1);
+				}
+				PRINTANDPAD(cp, convbuf + ndig, prec, zeroes);
+			} else {	/* %[eE] or sufficiently long %[gG] */
+				if (prec > 1 || flags & ALT) {
+					buf[0] = *cp++;
+					buf[1] = *decimal_point;
+					PRINT(buf, 2);
+					PRINT(cp, ndig-1);
+					PAD(prec - ndig, zeroes);
+				} else { /* XeYYY */
+					PRINT(cp, 1);
+				}
+				PRINT(expstr, expsize);
+			}
+		}
+#else
+		PRINT(cp, size);
+#endif
+		/* left-adjusting padding (always blank) */
+		if (flags & LADJUST)
+			PAD(width - realsz, blanks);
+
+		/* finally, adjust ret */
+		if (width < realsz)
+			width = realsz;
+		if (width > INT_MAX - ret)
+			goto overflow;
+		ret += width;
+	}
+done:
+error:
+	va_end(orgap);
+	if (__sferror(fp))
+		ret = -1;
+	goto finish;
+
+overflow:
+	errno = ENOMEM;
+	ret = -1;
+
+finish:
+	if (convbuf)
+		free(convbuf);
+#ifdef FLOATING_POINT
+	if (dtoaresult)
+		__freedtoa(dtoaresult);
+#endif
+	if (argtable != NULL && argtable != statargtable) {
+		munmap(argtable, argtablesiz);
+		argtable = NULL;
+	}
+	return (ret);
+}
+
+int
+vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, __va_list ap)
+{
+	int r;
+
+	FLOCKFILE(fp);
+	r = __vfwprintf(fp, fmt0, ap);
+	FUNLOCKFILE(fp);
+
+	return (r);
+}
+
+/*
+ * Type ids for argument type table.
+ */
+#define T_UNUSED	0
+#define T_SHORT		1
+#define T_U_SHORT	2
+#define TP_SHORT	3
+#define T_INT		4
+#define T_U_INT		5
+#define TP_INT		6
+#define T_LONG		7
+#define T_U_LONG	8
+#define TP_LONG		9
+#define T_LLONG		10
+#define T_U_LLONG	11
+#define TP_LLONG	12
+#define T_DOUBLE	13
+#define T_LONG_DOUBLE	14
+#define TP_CHAR		15
+#define TP_VOID		16
+#define T_PTRINT	17
+#define TP_PTRINT	18
+#define T_SIZEINT	19
+#define T_SSIZEINT	20
+#define TP_SSIZEINT	21
+#define T_MAXINT	22
+#define T_MAXUINT	23
+#define TP_MAXINT	24
+#define T_CHAR		25
+#define T_U_CHAR	26
+#define T_WINT		27
+#define TP_WCHAR	28
+
+/*
+ * Find all arguments when a positional parameter is encountered.  Returns a
+ * table, indexed by argument number, of pointers to each arguments.  The
+ * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
+ * It will be replaced with a mmap-ed one if it overflows (malloc cannot be
+ * used since we are attempting to make snprintf thread safe, and alloca is
+ * problematic since we have nested functions..)
+ */
+static int
+__find_arguments(const wchar_t *fmt0, va_list ap, union arg **argtable,
+    size_t *argtablesiz)
+{
+	wchar_t *fmt;		/* format string */
+	int ch;			/* character from fmt */
+	int n, n2;		/* handy integer (short term usage) */
+	wchar_t *cp;		/* handy char pointer (short term usage) */
+	int flags;		/* flags as above */
+	unsigned char *typetable; /* table of types */
+	unsigned char stattypetable[STATIC_ARG_TBL_SIZE];
+	int tablesize;		/* current size of type table */
+	int tablemax;		/* largest used index in table */
+	int nextarg;		/* 1-based argument index */
+	int ret = 0;		/* return value */
+
+	/*
+	 * Add an argument type to the table, expanding if necessary.
+	 */
+#define ADDTYPE(type) \
+	((nextarg >= tablesize) ? \
+		__grow_type_table(&typetable, &tablesize) : 0, \
+	(nextarg > tablemax) ? tablemax = nextarg : 0, \
+	typetable[nextarg++] = type)
+
+#define	ADDSARG() \
+        ((flags&MAXINT) ? ADDTYPE(T_MAXINT) : \
+	    ((flags&PTRINT) ? ADDTYPE(T_PTRINT) : \
+	    ((flags&SIZEINT) ? ADDTYPE(T_SSIZEINT) : \
+	    ((flags&LLONGINT) ? ADDTYPE(T_LLONG) : \
+	    ((flags&LONGINT) ? ADDTYPE(T_LONG) : \
+	    ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : \
+	    ((flags&CHARINT) ? ADDTYPE(T_CHAR) : ADDTYPE(T_INT))))))))
+
+#define	ADDUARG() \
+        ((flags&MAXINT) ? ADDTYPE(T_MAXUINT) : \
+	    ((flags&PTRINT) ? ADDTYPE(T_PTRINT) : \
+	    ((flags&SIZEINT) ? ADDTYPE(T_SIZEINT) : \
+	    ((flags&LLONGINT) ? ADDTYPE(T_U_LLONG) : \
+	    ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \
+	    ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : \
+	    ((flags&CHARINT) ? ADDTYPE(T_U_CHAR) : ADDTYPE(T_U_INT))))))))
+
+	/*
+	 * Add * arguments to the type array.
+	 */
+#define ADDASTER() \
+	n2 = 0; \
+	cp = fmt; \
+	while (is_digit(*cp)) { \
+		APPEND_DIGIT(n2, *cp); \
+		cp++; \
+	} \
+	if (*cp == '$') { \
+		int hold = nextarg; \
+		nextarg = n2; \
+		ADDTYPE(T_INT); \
+		nextarg = hold; \
+		fmt = ++cp; \
+	} else { \
+		ADDTYPE(T_INT); \
+	}
+	fmt = (wchar_t *)fmt0;
+	typetable = stattypetable;
+	tablesize = STATIC_ARG_TBL_SIZE;
+	tablemax = 0;
+	nextarg = 1;
+	memset(typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
+
+	/*
+	 * Scan the format for conversions (`%' character).
+	 */
+	for (;;) {
+		for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
+			continue;
+		if (ch == '\0')
+			goto done;
+		fmt++;		/* skip over '%' */
+
+		flags = 0;
+
+rflag:		ch = *fmt++;
+reswitch:	switch (ch) {
+		case ' ':
+		case '#':
+		case '\'':
+			goto rflag;
+		case '*':
+			ADDASTER();
+			goto rflag;
+		case '-':
+		case '+':
+			goto rflag;
+		case '.':
+			if ((ch = *fmt++) == '*') {
+				ADDASTER();
+				goto rflag;
+			}
+			while (is_digit(ch)) {
+				ch = *fmt++;
+			}
+			goto reswitch;
+		case '0':
+			goto rflag;
+		case '1': case '2': case '3': case '4':
+		case '5': case '6': case '7': case '8': case '9':
+			n = 0;
+			do {
+				APPEND_DIGIT(n ,ch);
+				ch = *fmt++;
+			} while (is_digit(ch));
+			if (ch == '$') {
+				nextarg = n;
+				goto rflag;
+			}
+			goto reswitch;
+#ifdef FLOATING_POINT
+		case 'L':
+			flags |= LONGDBL;
+			goto rflag;
+#endif
+		case 'h':
+			if (*fmt == 'h') {
+				fmt++;
+				flags |= CHARINT;
+			} else {
+				flags |= SHORTINT;
+			}
+			goto rflag;
+		case 'l':
+			if (*fmt == 'l') {
+				fmt++;
+				flags |= LLONGINT;
+			} else {
+				flags |= LONGINT;
+			}
+			goto rflag;
+		case 'q':
+			flags |= LLONGINT;
+			goto rflag;
+		case 't':
+			flags |= PTRINT;
+			goto rflag;
+		case 'z':
+			flags |= SIZEINT;
+			goto rflag;
+		case 'C':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'c':
+			if (flags & LONGINT)
+				ADDTYPE(T_WINT);
+			else
+				ADDTYPE(T_INT);
+			break;
+		case 'D':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'd':
+		case 'i':
+			ADDSARG();
+			break;
+#ifdef FLOATING_POINT
+		case 'a':
+		case 'A':
+		case 'e':
+		case 'E':
+		case 'f':
+		case 'F':
+		case 'g':
+		case 'G':
+			if (flags & LONGDBL)
+				ADDTYPE(T_LONG_DOUBLE);
+			else
+				ADDTYPE(T_DOUBLE);
+			break;
+#endif /* FLOATING_POINT */
+#ifndef NO_PRINTF_PERCENT_N
+		case 'n':
+			if (flags & LLONGINT)
+				ADDTYPE(TP_LLONG);
+			else if (flags & LONGINT)
+				ADDTYPE(TP_LONG);
+			else if (flags & SHORTINT)
+				ADDTYPE(TP_SHORT);
+			else if (flags & PTRINT)
+				ADDTYPE(TP_PTRINT);
+			else if (flags & SIZEINT)
+				ADDTYPE(TP_SSIZEINT);
+			else if (flags & MAXINT)
+				ADDTYPE(TP_MAXINT);
+			else
+				ADDTYPE(TP_INT);
+			continue;	/* no output */
+#endif /* NO_PRINTF_PERCENT_N */
+		case 'O':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'o':
+			ADDUARG();
+			break;
+		case 'p':
+			ADDTYPE(TP_VOID);
+			break;
+		case 'S':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 's':
+			if (flags & LONGINT)
+				ADDTYPE(TP_CHAR);
+			else
+				ADDTYPE(TP_WCHAR);
+			break;
+		case 'U':
+			flags |= LONGINT;
+			/*FALLTHROUGH*/
+		case 'u':
+		case 'X':
+		case 'x':
+			ADDUARG();
+			break;
+		default:	/* "%?" prints ?, unless ? is NUL */
+			if (ch == '\0')
+				goto done;
+			break;
+		}
+	}
+done:
+	/*
+	 * Build the argument table.
+	 */
+	if (tablemax >= STATIC_ARG_TBL_SIZE) {
+		*argtablesiz = sizeof(union arg) * (tablemax + 1);
+		*argtable = mmap(NULL, *argtablesiz,
+		    PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0);
+		if (*argtable == MAP_FAILED)
+			return (-1);
+	}
+
+#if 0
+	/* XXX is this required? */
+	(*argtable)[0].intarg = 0;
+#endif
+	for (n = 1; n <= tablemax; n++) {
+		switch (typetable[n]) {
+		case T_UNUSED:
+		case T_CHAR:
+		case T_U_CHAR:
+		case T_SHORT:
+		case T_U_SHORT:
+		case T_INT:
+			(*argtable)[n].intarg = va_arg(ap, int);
+			break;
+		case TP_SHORT:
+			(*argtable)[n].pshortarg = va_arg(ap, short *);
+			break;
+		case T_U_INT:
+			(*argtable)[n].uintarg = va_arg(ap, unsigned int);
+			break;
+		case TP_INT:
+			(*argtable)[n].pintarg = va_arg(ap, int *);
+			break;
+		case T_LONG:
+			(*argtable)[n].longarg = va_arg(ap, long);
+			break;
+		case T_U_LONG:
+			(*argtable)[n].ulongarg = va_arg(ap, unsigned long);
+			break;
+		case TP_LONG:
+			(*argtable)[n].plongarg = va_arg(ap, long *);
+			break;
+		case T_LLONG:
+			(*argtable)[n].longlongarg = va_arg(ap, long long);
+			break;
+		case T_U_LLONG:
+			(*argtable)[n].ulonglongarg = va_arg(ap, unsigned long long);
+			break;
+		case TP_LLONG:
+			(*argtable)[n].plonglongarg = va_arg(ap, long long *);
+			break;
+#ifdef FLOATING_POINT
+		case T_DOUBLE:
+			(*argtable)[n].doublearg = va_arg(ap, double);
+			break;
+		case T_LONG_DOUBLE:
+			(*argtable)[n].longdoublearg = va_arg(ap, long double);
+			break;
+#endif
+		case TP_CHAR:
+			(*argtable)[n].pchararg = va_arg(ap, char *);
+			break;
+		case TP_VOID:
+			(*argtable)[n].pvoidarg = va_arg(ap, void *);
+			break;
+		case T_PTRINT:
+			(*argtable)[n].ptrdiffarg = va_arg(ap, ptrdiff_t);
+			break;
+		case TP_PTRINT:
+			(*argtable)[n].pptrdiffarg = va_arg(ap, ptrdiff_t *);
+			break;
+		case T_SIZEINT:
+			(*argtable)[n].sizearg = va_arg(ap, size_t);
+			break;
+		case T_SSIZEINT:
+			(*argtable)[n].ssizearg = va_arg(ap, ssize_t);
+			break;
+		case TP_SSIZEINT:
+			(*argtable)[n].pssizearg = va_arg(ap, ssize_t *);
+			break;
+		case TP_MAXINT:
+			(*argtable)[n].intmaxarg = va_arg(ap, intmax_t);
+			break;
+		case T_WINT:
+			(*argtable)[n].wintarg = va_arg(ap, wint_t);
+			break;
+		case TP_WCHAR:
+			(*argtable)[n].pwchararg = va_arg(ap, wchar_t *);
+			break;
+		}
+	}
+	goto finish;
+
+overflow:
+	errno = ENOMEM;
+	ret = -1;
+
+finish:
+	if (typetable != NULL && typetable != stattypetable) {
+		munmap(typetable, *argtablesiz);
+		typetable = NULL;
+	}
+	return (ret);
+}
+
+/*
+ * Increase the size of the type table.
+ */
+static int
+__grow_type_table(unsigned char **typetable, int *tablesize)
+{
+	unsigned char *oldtable = *typetable;
+	int newsize = *tablesize * 2;
+
+	if (newsize < getpagesize())
+		newsize = getpagesize();
+
+	if (*tablesize == STATIC_ARG_TBL_SIZE) {
+		*typetable = mmap(NULL, newsize, PROT_WRITE|PROT_READ,
+		    MAP_ANON|MAP_PRIVATE, -1, 0);
+		if (*typetable == MAP_FAILED)
+			return (-1);
+		bcopy(oldtable, *typetable, *tablesize);
+	} else {
+		unsigned char *new = mmap(NULL, newsize, PROT_WRITE|PROT_READ,
+		    MAP_ANON|MAP_PRIVATE, -1, 0);
+		if (new == MAP_FAILED)
+			return (-1);
+		memmove(new, *typetable, *tablesize);
+		munmap(*typetable, *tablesize);
+		*typetable = new;
+	}
+	memset(*typetable + *tablesize, T_UNUSED, (newsize - *tablesize));
+
+	*tablesize = newsize;
+	return (0);
+}
+
+ 
+#ifdef FLOATING_POINT
+static int
+exponent(wchar_t *p0, int exp, int fmtch)
+{
+	wchar_t *p, *t;
+	wchar_t expbuf[MAXEXPDIG];
+
+	p = p0;
+	*p++ = fmtch;
+	if (exp < 0) {
+		exp = -exp;
+		*p++ = '-';
+	} else
+		*p++ = '+';
+	t = expbuf + MAXEXPDIG;
+	if (exp > 9) {
+		do {
+			*--t = to_char(exp % 10);
+		} while ((exp /= 10) > 9);
+		*--t = to_char(exp);
+		for (; t < expbuf + MAXEXPDIG; *p++ = *t++)
+			/* nothing */;
+	} else {
+		/*
+		 * Exponents for decimal floating point conversions
+		 * (%[eEgG]) must be at least two characters long,
+		 * whereas exponents for hexadecimal conversions can
+		 * be only one character long.
+		 */
+		if (fmtch == 'e' || fmtch == 'E')
+			*p++ = '0';
+		*p++ = to_char(exp);
+	}
+	return (p - p0);
+}
+#endif /* FLOATING_POINT */
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfwscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vfwscanf.c
new file mode 100644
index 0000000..cbb36be
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vfwscanf.c
@@ -0,0 +1,798 @@
+/*	$OpenBSD: vfwscanf.c,v 1.4 2014/03/19 05:17:01 guenther Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wctype.h>
+#include "local.h"
+
+#ifdef FLOATING_POINT
+#include "floatio.h"
+#endif
+
+#define	BUF		513	/* Maximum length of numeric string. */
+
+/*
+ * Flags used during conversion.
+ */
+#define	LONG		0x00001	/* l: long or double */
+#define	LONGDBL		0x00002	/* L: long double */
+#define	SHORT		0x00004	/* h: short */
+#define	SHORTSHORT	0x00008	/* hh: 8 bit integer */
+#define LLONG		0x00010	/* ll: long long (+ deprecated q: quad) */
+#define	POINTER		0x00020	/* p: void * (as hex) */
+#define	SIZEINT		0x00040	/* z: (signed) size_t */
+#define	MAXINT		0x00080	/* j: intmax_t */
+#define	PTRINT		0x00100	/* t: ptrdiff_t */
+#define	NOSKIP		0x00200	/* [ or c: do not skip blanks */
+#define	SUPPRESS	0x00400	/* *: suppress assignment */
+#define	UNSIGNED	0x00800	/* %[oupxX] conversions */
+
+/*
+ * The following are used in numeric conversions only:
+ * SIGNOK, HAVESIGN, NDIGITS, DPTOK, and EXPOK are for floating point;
+ * SIGNOK, HAVESIGN, NDIGITS, PFXOK, and NZDIGITS are for integral.
+ */
+#define	SIGNOK		0x01000	/* +/- is (still) legal */
+#define	HAVESIGN	0x02000	/* sign detected */
+#define	NDIGITS		0x04000	/* no digits detected */
+
+#define	DPTOK		0x08000	/* (float) decimal point is still legal */
+#define	EXPOK		0x10000	/* (float) exponent (e+3, etc) still legal */
+
+#define	PFXOK		0x08000	/* 0x prefix is (still) legal */
+#define	NZDIGITS	0x10000	/* no zero digits detected */
+
+/*
+ * Conversion types.
+ */
+#define	CT_CHAR		0	/* %c conversion */
+#define	CT_CCL		1	/* %[...] conversion */
+#define	CT_STRING	2	/* %s conversion */
+#define	CT_INT		3	/* integer, i.e., strtoimax or strtoumax */
+#define	CT_FLOAT	4	/* floating, i.e., strtod */
+
+#define u_char unsigned char
+#define u_long unsigned long
+
+#define	INCCL(_c)	\
+	(cclcompl ? (wmemchr(ccls, (_c), ccle - ccls) == NULL) : \
+	(wmemchr(ccls, (_c), ccle - ccls) != NULL))
+
+/*
+ * vfwscanf
+ */
+int
+__vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, __va_list ap)
+{
+	wint_t c;	/* character from format, or conversion */
+	size_t width;	/* field width, or 0 */
+	wchar_t *p;	/* points into all kinds of strings */
+	int n;		/* handy integer */
+	int flags;	/* flags as defined above */
+	wchar_t *p0;	/* saves original value of p when necessary */
+	int nassigned;		/* number of fields assigned */
+	int nconversions;	/* number of conversions */
+	int nread;		/* number of characters consumed from fp */
+	int base;		/* base argument to strtoimax/strtouimax */
+	wchar_t buf[BUF];	/* buffer for numeric conversions */
+	const wchar_t *ccls;	/* character class start */
+	const wchar_t *ccle;	/* character class end */
+	int cclcompl;		/* ccl is complemented? */
+	wint_t wi;		/* handy wint_t */
+	char *mbp;		/* multibyte string pointer for %c %s %[ */
+	size_t nconv;		/* number of bytes in mb. conversion */
+	char mbbuf[MB_LEN_MAX];	/* temporary mb. character buffer */
+ 	mbstate_t mbs;
+#ifdef FLOATING_POINT
+	wchar_t decimal_point = 0;
+#endif
+
+	/* `basefix' is used to avoid `if' tests in the integer scanner */
+	static short basefix[17] =
+		{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+	_SET_ORIENTATION(fp, 1);
+
+	nassigned = 0;
+	nconversions = 0;
+	nread = 0;
+	base = 0;		/* XXX just to keep gcc happy */
+	ccls = ccle = NULL;
+	for (;;) {
+		c = *fmt++;
+		if (c == 0) {
+			return (nassigned);
+		}
+		if (iswspace(c)) {
+			while ((c = __fgetwc_unlock(fp)) != WEOF &&
+			    iswspace(c))
+				;
+			if (c != WEOF)
+				__ungetwc(c, fp);
+			continue;
+		}
+		if (c != '%')
+			goto literal;
+		width = 0;
+		flags = 0;
+		/*
+		 * switch on the format.  continue if done;
+		 * break once format type is derived.
+		 */
+again:		c = *fmt++;
+		switch (c) {
+		case '%':
+literal:
+			if ((wi = __fgetwc_unlock(fp)) == WEOF)
+				goto input_failure;
+			if (wi != c) {
+				__ungetwc(wi, fp);
+				goto input_failure;
+			}
+			nread++;
+			continue;
+
+		case '*':
+			flags |= SUPPRESS;
+			goto again;
+		case 'j':
+			flags |= MAXINT;
+			goto again;
+		case 'L':
+			flags |= LONGDBL;
+			goto again;
+		case 'h':
+			if (*fmt == 'h') {
+				fmt++;
+				flags |= SHORTSHORT;
+			} else {
+				flags |= SHORT;
+			}
+			goto again;
+		case 'l':
+			if (*fmt == 'l') {
+				fmt++;
+				flags |= LLONG;
+			} else {
+				flags |= LONG;
+			}
+			goto again;
+		case 'q':
+			flags |= LLONG;		/* deprecated */
+			goto again;
+		case 't':
+			flags |= PTRINT;
+			goto again;
+		case 'z':
+			flags |= SIZEINT;
+			goto again;
+
+		case '0': case '1': case '2': case '3': case '4':
+		case '5': case '6': case '7': case '8': case '9':
+			width = width * 10 + c - '0';
+			goto again;
+
+		/*
+		 * Conversions.
+		 * Those marked `compat' are for 4.[123]BSD compatibility.
+		 *
+		 * (According to ANSI, E and X formats are supposed
+		 * to the same as e and x.  Sorry about that.)
+		 */
+		case 'D':	/* compat */
+			flags |= LONG;
+			/* FALLTHROUGH */
+		case 'd':
+			c = CT_INT;
+			base = 10;
+			break;
+
+		case 'i':
+			c = CT_INT;
+			base = 0;
+			break;
+
+		case 'O':	/* compat */
+			flags |= LONG;
+			/* FALLTHROUGH */
+		case 'o':
+			c = CT_INT;
+			flags |= UNSIGNED;
+			base = 8;
+			break;
+
+		case 'u':
+			c = CT_INT;
+			flags |= UNSIGNED;
+			base = 10;
+			break;
+
+		case 'X':
+		case 'x':
+			flags |= PFXOK;	/* enable 0x prefixing */
+			c = CT_INT;
+			flags |= UNSIGNED;
+			base = 16;
+			break;
+
+#ifdef FLOATING_POINT
+		case 'e': case 'E':
+		case 'f': case 'F':
+		case 'g': case 'G':
+		case 'a': case 'A':
+			c = CT_FLOAT;
+			break;
+#endif
+
+		case 's':
+			c = CT_STRING;
+			break;
+
+		case '[':
+			ccls = fmt;
+			if (*fmt == '^') {
+				cclcompl = 1;
+				fmt++;
+			} else
+				cclcompl = 0;
+			if (*fmt == ']')
+				fmt++;
+			while (*fmt != '\0' && *fmt != ']')
+				fmt++;
+			ccle = fmt;
+			fmt++;
+			flags |= NOSKIP;
+			c = CT_CCL;
+			break;
+
+		case 'c':
+			flags |= NOSKIP;
+			c = CT_CHAR;
+			break;
+
+		case 'p':	/* pointer format is like hex */
+			flags |= POINTER | PFXOK;
+			c = CT_INT;
+			flags |= UNSIGNED;
+			base = 16;
+			break;
+
+		case 'n':
+			nconversions++;
+			if (flags & SUPPRESS)
+				continue;
+			if (flags & SHORTSHORT)
+				*va_arg(ap, signed char *) = nread;
+			else if (flags & SHORT)
+				*va_arg(ap, short *) = nread;
+			else if (flags & LONG)
+				*va_arg(ap, long *) = nread;
+			else if (flags & SIZEINT)
+				*va_arg(ap, ssize_t *) = nread;
+			else if (flags & PTRINT)
+				*va_arg(ap, ptrdiff_t *) = nread;
+			else if (flags & LLONG)
+				*va_arg(ap, long long *) = nread;
+			else if (flags & MAXINT)
+				*va_arg(ap, intmax_t *) = nread;
+			else
+				*va_arg(ap, int *) = nread;
+			continue;
+
+		/*
+		 * Disgusting backwards compatibility hacks.	XXX
+		 */
+		case '\0':	/* compat */
+			return (EOF);
+
+		default:	/* compat */
+			if (iswupper(c))
+				flags |= LONG;
+			c = CT_INT;
+			base = 10;
+			break;
+		}
+
+		/*
+		 * Consume leading white space, except for formats
+		 * that suppress this.
+		 */
+		if ((flags & NOSKIP) == 0) {
+			while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+			    iswspace(wi))
+				nread++;
+			if (wi == WEOF)
+				goto input_failure;
+			__ungetwc(wi, fp);
+		}
+
+		/*
+		 * Do the conversion.
+		 */
+		switch (c) {
+
+		case CT_CHAR:
+			/* scan arbitrary characters (sets NOSKIP) */
+			if (width == 0)
+				width = 1;
+ 			if (flags & LONG) {
+				if (!(flags & SUPPRESS))
+					p = va_arg(ap, wchar_t *);
+				n = 0;
+				while (width-- != 0 &&
+				    (wi = __fgetwc_unlock(fp)) != WEOF) {
+					if (!(flags & SUPPRESS))
+						*p++ = (wchar_t)wi;
+					n++;
+				}
+				if (n == 0)
+					goto input_failure;
+				nread += n;
+ 				if (!(flags & SUPPRESS))
+ 					nassigned++;
+			} else {
+				if (!(flags & SUPPRESS))
+					mbp = va_arg(ap, char *);
+				n = 0;
+				bzero(&mbs, sizeof(mbs));
+				while (width != 0 &&
+				    (wi = __fgetwc_unlock(fp)) != WEOF) {
+					if (width >= MB_CUR_MAX &&
+					    !(flags & SUPPRESS)) {
+						nconv = wcrtomb(mbp, wi, &mbs);
+						if (nconv == (size_t)-1)
+							goto input_failure;
+					} else {
+						nconv = wcrtomb(mbbuf, wi,
+						    &mbs);
+						if (nconv == (size_t)-1)
+							goto input_failure;
+						if (nconv > width) {
+							__ungetwc(wi, fp);
+ 							break;
+ 						}
+						if (!(flags & SUPPRESS))
+							memcpy(mbp, mbbuf,
+							    nconv);
+ 					}
+					if (!(flags & SUPPRESS))
+						mbp += nconv;
+					width -= nconv;
+					n++;
+ 				}
+				if (n == 0)
+ 					goto input_failure;
+				nread += n;
+				if (!(flags & SUPPRESS))
+					nassigned++;
+			}
+			nconversions++;
+			break;
+
+		case CT_CCL:
+			/* scan a (nonempty) character class (sets NOSKIP) */
+			if (width == 0)
+				width = (size_t)~0;	/* `infinity' */
+			/* take only those things in the class */
+			if ((flags & SUPPRESS) && (flags & LONG)) {
+				n = 0;
+				while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+				    width-- != 0 && INCCL(wi))
+					n++;
+				if (wi != WEOF)
+					__ungetwc(wi, fp);
+				if (n == 0)
+					goto match_failure;
+			} else if (flags & LONG) {
+				p0 = p = va_arg(ap, wchar_t *);
+				while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+				    width-- != 0 && INCCL(wi))
+					*p++ = (wchar_t)wi;
+				if (wi != WEOF)
+					__ungetwc(wi, fp);
+				n = p - p0;
+				if (n == 0)
+					goto match_failure;
+				*p = 0;
+				nassigned++;
+			} else {
+				if (!(flags & SUPPRESS))
+					mbp = va_arg(ap, char *);
+				n = 0;
+				bzero(&mbs, sizeof(mbs));
+				while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+				    width != 0 && INCCL(wi)) {
+					if (width >= MB_CUR_MAX &&
+					   !(flags & SUPPRESS)) {
+						nconv = wcrtomb(mbp, wi, &mbs);
+						if (nconv == (size_t)-1)
+							goto input_failure;
+					} else {
+						nconv = wcrtomb(mbbuf, wi,
+						    &mbs);
+						if (nconv == (size_t)-1)
+							goto input_failure;
+						if (nconv > width)
+							break;
+						if (!(flags & SUPPRESS))
+							memcpy(mbp, mbbuf,
+							    nconv);
+					}
+					if (!(flags & SUPPRESS))
+						mbp += nconv;
+					width -= nconv;
+					n++;
+				}
+				if (wi != WEOF)
+					__ungetwc(wi, fp);
+				if (!(flags & SUPPRESS)) {
+					*mbp = 0;
+					nassigned++;
+				}
+ 			}
+			nread += n;
+			nconversions++;
+			break;
+
+		case CT_STRING:
+			/* like CCL, but zero-length string OK, & no NOSKIP */
+			if (width == 0)
+				width = (size_t)~0;
+			if ((flags & SUPPRESS) && (flags & LONG)) {
+				while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+				    width-- != 0 &&
+				    !iswspace(wi))
+					nread++;
+				if (wi != WEOF)
+					__ungetwc(wi, fp);
+			} else if (flags & LONG) {
+				p0 = p = va_arg(ap, wchar_t *);
+				while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+				    width-- != 0 &&
+				    !iswspace(wi)) {
+					*p++ = (wchar_t)wi;
+					nread++;
+				}
+				if (wi != WEOF)
+					__ungetwc(wi, fp);
+				*p = 0;
+				nassigned++;
+			} else {
+				if (!(flags & SUPPRESS))
+					mbp = va_arg(ap, char *);
+				bzero(&mbs, sizeof(mbs));
+				while ((wi = __fgetwc_unlock(fp)) != WEOF &&
+				    width != 0 &&
+				    !iswspace(wi)) {
+					if (width >= MB_CUR_MAX &&
+					    !(flags & SUPPRESS)) {
+						nconv = wcrtomb(mbp, wi, &mbs);
+						if (nconv == (size_t)-1)
+							goto input_failure;
+					} else {
+						nconv = wcrtomb(mbbuf, wi,
+						    &mbs);
+						if (nconv == (size_t)-1)
+							goto input_failure;
+						if (nconv > width)
+							break;
+						if (!(flags & SUPPRESS))
+							memcpy(mbp, mbbuf,
+							    nconv);
+					}
+					if (!(flags & SUPPRESS))
+						mbp += nconv;
+					width -= nconv;
+					nread++;
+				}
+				if (wi != WEOF)
+					__ungetwc(wi, fp);
+				if (!(flags & SUPPRESS)) {
+					*mbp = 0;
+ 					nassigned++;
+ 				}
+			}
+			nconversions++;
+			continue;
+
+		case CT_INT:
+			/* scan an integer as if by strtoimax/strtoumax */
+			if (width == 0 || width > sizeof(buf) /
+			    sizeof(*buf) - 1)
+				width = sizeof(buf) / sizeof(*buf) - 1;
+			flags |= SIGNOK | NDIGITS | NZDIGITS;
+			for (p = buf; width; width--) {
+				c = __fgetwc_unlock(fp);
+				/*
+				 * Switch on the character; `goto ok'
+				 * if we accept it as a part of number.
+				 */
+				switch (c) {
+
+				/*
+				 * The digit 0 is always legal, but is
+				 * special.  For %i conversions, if no
+				 * digits (zero or nonzero) have been
+				 * scanned (only signs), we will have
+				 * base==0.  In that case, we should set
+				 * it to 8 and enable 0x prefixing.
+				 * Also, if we have not scanned zero digits
+				 * before this, do not turn off prefixing
+				 * (someone else will turn it off if we
+				 * have scanned any nonzero digits).
+				 */
+				case '0':
+					if (base == 0) {
+						base = 8;
+						flags |= PFXOK;
+					}
+					if (flags & NZDIGITS)
+					    flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
+					else
+					    flags &= ~(SIGNOK|PFXOK|NDIGITS);
+					goto ok;
+
+				/* 1 through 7 always legal */
+				case '1': case '2': case '3':
+				case '4': case '5': case '6': case '7':
+					base = basefix[base];
+					flags &= ~(SIGNOK | PFXOK | NDIGITS);
+					goto ok;
+
+				/* digits 8 and 9 ok iff decimal or hex */
+				case '8': case '9':
+					base = basefix[base];
+					if (base <= 8)
+						break;	/* not legal here */
+					flags &= ~(SIGNOK | PFXOK | NDIGITS);
+					goto ok;
+
+				/* letters ok iff hex */
+				case 'A': case 'B': case 'C':
+				case 'D': case 'E': case 'F':
+				case 'a': case 'b': case 'c':
+				case 'd': case 'e': case 'f':
+					/* no need to fix base here */
+					if (base <= 10)
+						break;	/* not legal here */
+					flags &= ~(SIGNOK | PFXOK | NDIGITS);
+					goto ok;
+
+				/* sign ok only as first character */
+				case '+': case '-':
+					if (flags & SIGNOK) {
+						flags &= ~SIGNOK;
+						flags |= HAVESIGN;
+						goto ok;
+					}
+					break;
+
+				/*
+				 * x ok iff flag still set and 2nd char (or
+				 * 3rd char if we have a sign).
+				 */
+				case 'x': case 'X':
+					if ((flags & PFXOK) && p ==
+					    buf + 1 + !!(flags & HAVESIGN)) {
+						base = 16;	/* if %i */
+						flags &= ~PFXOK;
+						goto ok;
+					}
+					break;
+				}
+
+				/*
+				 * If we got here, c is not a legal character
+				 * for a number.  Stop accumulating digits.
+				 */
+				if (c != WEOF)
+					__ungetwc(c, fp);
+				break;
+		ok:
+				/*
+				 * c is legal: store it and look at the next.
+				 */
+				*p++ = (wchar_t)c;
+			}
+			/*
+			 * If we had only a sign, it is no good; push
+			 * back the sign.  If the number ends in `x',
+			 * it was [sign] '0' 'x', so push back the x
+			 * and treat it as [sign] '0'.
+			 */
+			if (flags & NDIGITS) {
+				if (p > buf)
+					__ungetwc(*--p, fp);
+				goto match_failure;
+			}
+			c = p[-1];
+			if (c == 'x' || c == 'X') {
+				--p;
+				__ungetwc(c, fp);
+			}
+			if ((flags & SUPPRESS) == 0) {
+				uintmax_t res;
+
+				*p = '\0';
+				if (flags & UNSIGNED)
+					res = wcstoimax(buf, NULL, base);
+				else
+					res = wcstoumax(buf, NULL, base);
+				if (flags & POINTER)
+					*va_arg(ap, void **) =
+					    (void *)(uintptr_t)res;
+				else if (flags & MAXINT)
+					*va_arg(ap, intmax_t *) = res;
+				else if (flags & LLONG)
+					*va_arg(ap, long long *) = res;
+				else if (flags & SIZEINT)
+					*va_arg(ap, ssize_t *) = res;
+				else if (flags & PTRINT)
+					*va_arg(ap, ptrdiff_t *) = res;
+				else if (flags & LONG)
+					*va_arg(ap, long *) = res;
+				else if (flags & SHORT)
+					*va_arg(ap, short *) = res;
+				else if (flags & SHORTSHORT)
+					*va_arg(ap, signed char *) = res;
+				else
+					*va_arg(ap, int *) = res;
+				nassigned++;
+			}
+			nread += p - buf;
+			nconversions++;
+			break;
+
+#ifdef FLOATING_POINT
+		case CT_FLOAT:
+			/* scan a floating point number as if by strtod */
+			if (width == 0 || width > sizeof(buf) /
+			    sizeof(*buf) - 1)
+				width = sizeof(buf) / sizeof(*buf) - 1;
+			flags |= SIGNOK | NDIGITS | DPTOK | EXPOK;
+			for (p = buf; width; width--) {
+				c = __fgetwc_unlock(fp);
+				/*
+				 * This code mimicks the integer conversion
+				 * code, but is much simpler.
+				 */
+				switch (c) {
+
+				case '0': case '1': case '2': case '3':
+				case '4': case '5': case '6': case '7':
+				case '8': case '9':
+					flags &= ~(SIGNOK | NDIGITS);
+					goto fok;
+
+				case '+': case '-':
+					if (flags & SIGNOK) {
+						flags &= ~SIGNOK;
+						goto fok;
+					}
+					break;
+				case 'e': case 'E':
+					/* no exponent without some digits */
+					if ((flags&(NDIGITS|EXPOK)) == EXPOK) {
+						flags =
+						    (flags & ~(EXPOK|DPTOK)) |
+						    SIGNOK | NDIGITS;
+						goto fok;
+					}
+					break;
+				default:
+					if (decimal_point == 0) {
+						bzero(&mbs, sizeof(mbs));
+						nconv = mbrtowc(&decimal_point,
+						    localeconv()->decimal_point,
+					    	    MB_CUR_MAX, &mbs);
+						if (nconv == 0 ||
+						    nconv == (size_t)-1 ||
+						    nconv == (size_t)-2)
+							decimal_point = '.';
+					}
+					if (c == decimal_point &&
+					    (flags & DPTOK)) {
+						flags &= ~(SIGNOK | DPTOK);
+						goto fok;
+					}
+					break;
+				}
+				if (c != WEOF)
+					__ungetwc(c, fp);
+				break;
+		fok:
+				*p++ = c;
+			}
+			/*
+			 * If no digits, might be missing exponent digits
+			 * (just give back the exponent) or might be missing
+			 * regular digits, but had sign and/or decimal point.
+			 */
+			if (flags & NDIGITS) {
+				if (flags & EXPOK) {
+					/* no digits at all */
+					while (p > buf)
+						__ungetwc(*--p, fp);
+					goto match_failure;
+				}
+				/* just a bad exponent (e and maybe sign) */
+				c = *--p;
+				if (c != 'e' && c != 'E') {
+					__ungetwc(c, fp);/* sign */
+					c = *--p;
+				}
+				__ungetwc(c, fp);
+			}
+			if ((flags & SUPPRESS) == 0) {
+				*p = 0;
+				if (flags & LONGDBL) {
+					long double res = wcstold(buf, NULL);
+					*va_arg(ap, long double *) = res;
+				} else if (flags & LONG) {
+					double res = wcstod(buf, NULL);
+					*va_arg(ap, double *) = res;
+				} else {
+					float res = wcstof(buf, NULL);
+					*va_arg(ap, float *) = res;
+				}
+				nassigned++;
+			}
+			nread += p - buf;
+			nconversions++;
+			break;
+#endif /* FLOATING_POINT */
+		}
+	}
+input_failure:
+	return (nconversions != 0 ? nassigned : EOF);
+match_failure:
+	return (nassigned);
+}
+
+int
+vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, __va_list ap)
+{
+	int r;
+
+	FLOCKFILE(fp);
+	r = __vfwscanf(fp, fmt, ap);
+	FUNLOCKFILE(fp);
+	return (r);
+}
diff --git a/libc/stdio/vprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vprintf.c
similarity index 100%
rename from libc/stdio/vprintf.c
rename to libc/upstream-openbsd/lib/libc/stdio/vprintf.c
diff --git a/libc/stdio/vscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vscanf.c
similarity index 100%
rename from libc/stdio/vscanf.c
rename to libc/upstream-openbsd/lib/libc/stdio/vscanf.c
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c
new file mode 100644
index 0000000..8b1a088
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c
@@ -0,0 +1,64 @@
+/*	$OpenBSD: vsnprintf.c,v 1.15 2009/11/09 00:18:28 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include "local.h"
+
+int
+vsnprintf(char *str, size_t n, const char *fmt, __va_list ap)
+{
+	int ret;
+	char dummy;
+	FILE f;
+	struct __sfileext fext;
+
+	_FILEEXT_SETUP(&f, &fext);
+
+	/* While snprintf(3) specifies size_t stdio uses an int internally */
+	if (n > INT_MAX)
+		n = INT_MAX;
+	/* Stdio internals do not deal correctly with zero length buffer */
+	if (n == 0) {
+		str = &dummy;
+		n = 1;
+	}
+	f._file = -1;
+	f._flags = __SWR | __SSTR;
+	f._bf._base = f._p = (unsigned char *)str;
+	f._bf._size = f._w = n - 1;
+	ret = __vfprintf(&f, fmt, ap);
+	*f._p = '\0';
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c
new file mode 100644
index 0000000..308ff37
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c
@@ -0,0 +1,59 @@
+/*	$OpenBSD: vsprintf.c,v 1.16 2009/11/09 00:18:28 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+#include "local.h"
+
+#if defined(APIWARN)
+__warn_references(vsprintf,
+    "warning: vsprintf() is often misused, please use vsnprintf()");
+#endif
+
+int
+vsprintf(char *str, const char *fmt, __va_list ap)
+{
+	int ret;
+	FILE f;
+	struct __sfileext fext;
+
+	_FILEEXT_SETUP(&f, &fext);
+	f._file = -1;
+	f._flags = __SWR | __SSTR;
+	f._bf._base = f._p = (unsigned char *)str;
+	f._bf._size = f._w = INT_MAX;
+	ret = __vfprintf(&f, fmt, ap);
+	*f._p = '\0';
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vsscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vsscanf.c
new file mode 100644
index 0000000..71eb752
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vsscanf.c
@@ -0,0 +1,59 @@
+/*	$OpenBSD: vsscanf.c,v 1.12 2011/11/08 18:30:42 guenther Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Donn Seeley at UUNET Technologies, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "local.h"
+
+/* ARGSUSED */
+static int
+eofread(void *cookie, char *buf, int len)
+{
+
+	return (0);
+}
+
+int
+vsscanf(const char *str, const char *fmt, __va_list ap)
+{
+	FILE f;
+	struct __sfileext fext;
+
+	_FILEEXT_SETUP(&f, &fext);
+	f._flags = __SRD;
+	f._bf._base = f._p = (unsigned char *)str;
+	f._bf._size = f._r = strlen(str);
+	f._read = eofread;
+	f._lb._base = NULL;
+	return (__svfscanf(&f, fmt, ap));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vswprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vswprintf.c
new file mode 100644
index 0000000..da7c4de
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vswprintf.c
@@ -0,0 +1,96 @@
+/*	$OpenBSD: vswprintf.c,v 1.4 2012/12/05 23:20:01 deraadt Exp $	*/
+/*	$NetBSD: vswprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $	*/
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <stdarg.h>
+#include "local.h"
+
+int
+vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
+    __va_list ap)
+{
+	mbstate_t mbs;
+	FILE f;
+	char *mbp;
+	int ret, sverrno;
+	size_t nwc;
+	struct __sfileext fext;
+
+	if (n == 0) {
+		errno = EINVAL;
+		return (-1);
+	}
+
+	_FILEEXT_SETUP(&f, &fext);
+	f._file = -1;
+	f._flags = __SWR | __SSTR | __SALC;
+	f._bf._base = f._p = (unsigned char *)malloc(128);
+	if (f._bf._base == NULL) {
+		errno = ENOMEM;
+		return (-1);
+	}
+	f._bf._size = f._w = 127;		/* Leave room for the NUL */
+	ret = __vfwprintf(&f, fmt, ap);
+	if (ret < 0) {
+		sverrno = errno;
+		free(f._bf._base);
+		errno = sverrno;
+		return (-1);
+	}
+	if (ret == 0) {
+		s[0] = L'\0';
+		free(f._bf._base);
+		return (0);
+	}
+	*f._p = '\0';
+	mbp = (char *)f._bf._base;
+	/*
+	 * XXX Undo the conversion from wide characters to multibyte that
+	 * fputwc() did in __vfwprintf().
+	 */
+	bzero(&mbs, sizeof(mbs));
+	nwc = mbsrtowcs(s, (const char **)&mbp, n, &mbs);
+	free(f._bf._base);
+	if (nwc == (size_t)-1) {
+		errno = EILSEQ;
+		return (-1);
+	}
+	if (nwc == n) {
+		s[n - 1] = L'\0';
+		errno = EOVERFLOW;
+		return (-1);
+	}
+
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vswscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vswscanf.c
new file mode 100644
index 0000000..cbaa250
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vswscanf.c
@@ -0,0 +1,88 @@
+/* $OpenBSD: vswscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Donn Seeley at UUNET Technologies, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <limits.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "local.h"
+
+static int	eofread(void *, char *, int);
+
+static int
+eofread(void *cookie, char *buf, int len)
+{
+	return (0);
+}
+
+int
+vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
+    __va_list ap)
+{
+	mbstate_t mbs;
+	FILE f;
+	struct __sfileext fext;
+	char *mbstr;
+	size_t len, mlen;
+	int r;
+	const wchar_t *strp;
+
+	/*
+	 * XXX Convert the wide character string to multibyte, which
+	 * __vfwscanf() will convert back to wide characters.
+	 */
+	len = wcslen(str) * MB_CUR_MAX;
+	if ((mbstr = malloc(len + 1)) == NULL)
+		return (EOF);
+	bzero(&mbs, sizeof(mbs));
+	strp = str;
+	if ((mlen = wcsrtombs(mbstr, &strp, len, &mbs)) == (size_t)-1) {
+		free(mbstr);
+		return (EOF);
+	}
+	if (mlen == len)
+		mbstr[len] = '\0';
+	_FILEEXT_SETUP(&f, &fext);
+	f._flags = __SRD;
+	f._bf._base = f._p = (unsigned char *)mbstr;
+	f._bf._size = f._r = mlen;
+	f._read = eofread;
+	f._lb._base = NULL;
+	r = __vfwscanf(&f, fmt, ap);
+	free(mbstr);
+
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vwprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vwprintf.c
new file mode 100644
index 0000000..49569c1
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vwprintf.c
@@ -0,0 +1,42 @@
+/*	$OpenBSD: vwprintf.c,v 1.3 2011/04/28 17:38:46 stsp Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+vwprintf(const wchar_t * __restrict fmt, __va_list ap)
+{
+	return (vfwprintf(stdout, fmt, ap));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vwscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vwscanf.c
new file mode 100644
index 0000000..7039f02
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/vwscanf.c
@@ -0,0 +1,38 @@
+/* $OpenBSD: vwscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+vwscanf(const wchar_t * __restrict fmt, __va_list ap)
+{
+
+	return (vfwscanf(stdin, fmt, ap));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/wbuf.c b/libc/upstream-openbsd/lib/libc/stdio/wbuf.c
new file mode 100644
index 0000000..6aa00e1
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/wbuf.c
@@ -0,0 +1,84 @@
+/*	$OpenBSD: wbuf.c,v 1.12 2009/11/09 00:18:28 kurt Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include "local.h"
+
+/*
+ * Write the given character into the (probably full) buffer for
+ * the given file.  Flush the buffer out if it is or becomes full,
+ * or if c=='\n' and the file is line buffered.
+ */
+int
+__swbuf(int c, FILE *fp)
+{
+	int n;
+
+	_SET_ORIENTATION(fp, -1);
+	/*
+	 * In case we cannot write, or longjmp takes us out early,
+	 * make sure _w is 0 (if fully- or un-buffered) or -_bf._size
+	 * (if line buffered) so that we will get called again.
+	 * If we did not do this, a sufficient number of putc()
+	 * calls might wrap _w from negative to positive.
+	 */
+	fp->_w = fp->_lbfsize;
+	if (cantwrite(fp)) {
+		errno = EBADF;
+		return (EOF);
+	}
+	c = (unsigned char)c;
+
+	/*
+	 * If it is completely full, flush it out.  Then, in any case,
+	 * stuff c into the buffer.  If this causes the buffer to fill
+	 * completely, or if c is '\n' and the file is line buffered,
+	 * flush it (perhaps a second time).  The second flush will always
+	 * happen on unbuffered streams, where _bf._size==1; __sflush()
+	 * guarantees that putc() will always call wbuf() by setting _w
+	 * to 0, so we need not do anything else.
+	 */
+	n = fp->_p - fp->_bf._base;
+	if (n >= fp->_bf._size) {
+		if (__sflush(fp))
+			return (EOF);
+		n = 0;
+	}
+	fp->_w--;
+	*fp->_p++ = c;
+	if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
+		if (__sflush(fp))
+			return (EOF);
+	return (c);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/wprintf.c b/libc/upstream-openbsd/lib/libc/stdio/wprintf.c
new file mode 100644
index 0000000..9f7abb6
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/wprintf.c
@@ -0,0 +1,48 @@
+/*	$OpenBSD: wprintf.c,v 1.3 2011/04/28 17:38:46 stsp Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+
+int
+wprintf(const wchar_t * __restrict fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfwprintf(stdout, fmt, ap);
+	va_end(ap);
+	return (ret);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/wscanf.c b/libc/upstream-openbsd/lib/libc/stdio/wscanf.c
new file mode 100644
index 0000000..06c0829
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/wscanf.c
@@ -0,0 +1,44 @@
+/* $OpenBSD: wscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+int
+wscanf(const wchar_t * __restrict fmt, ...)
+{
+	va_list ap;
+	int r;
+
+	va_start(ap, fmt);
+	r = vfwscanf(stdin, fmt, ap);
+	va_end(ap);
+
+	return (r);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/wsetup.c b/libc/upstream-openbsd/lib/libc/stdio/wsetup.c
new file mode 100644
index 0000000..0834223
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdio/wsetup.c
@@ -0,0 +1,86 @@
+/*	$OpenBSD: wsetup.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "local.h"
+
+/*
+ * Various output routines call wsetup to be sure it is safe to write,
+ * because either _flags does not include __SWR, or _buf is NULL.
+ * _wsetup returns 0 if OK to write, nonzero otherwise.
+ */
+int
+__swsetup(FILE *fp)
+{
+	/* make sure stdio is set up */
+	if (!__sdidinit)
+		__sinit();
+
+	/*
+	 * If we are not writing, we had better be reading and writing.
+	 */
+	if ((fp->_flags & __SWR) == 0) {
+		if ((fp->_flags & __SRW) == 0)
+			return (EOF);
+		if (fp->_flags & __SRD) {
+			/* clobber any ungetc data */
+			if (HASUB(fp))
+				FREEUB(fp);
+			fp->_flags &= ~(__SRD|__SEOF);
+			fp->_r = 0;
+			fp->_p = fp->_bf._base;
+		}
+		fp->_flags |= __SWR;
+	}
+
+	/*
+	 * Make a buffer if necessary, then set _w.
+	 */
+	if (fp->_bf._base == NULL) {
+		if ((fp->_flags & (__SSTR | __SALC)) == __SSTR)
+			return (EOF);
+		__smakebuf(fp);
+	}
+	if (fp->_flags & __SLBF) {
+		/*
+		 * It is line buffered, so make _lbfsize be -_bufsize
+		 * for the putc() macro.  We will change _lbfsize back
+		 * to 0 whenever we turn off __SWR.
+		 */
+		fp->_w = 0;
+		fp->_lbfsize = -fp->_bf._size;
+	} else
+		fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
+	return (0);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/atexit.c b/libc/upstream-openbsd/lib/libc/stdlib/atexit.c
new file mode 100644
index 0000000..6532b38
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atexit.c
@@ -0,0 +1,202 @@
+/*	$OpenBSD: atexit.c,v 1.20 2014/07/11 09:51:37 kettenis Exp $ */
+/*
+ * Copyright (c) 2002 Daniel Hartmeier
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *    - Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "atexit.h"
+#include "thread_private.h"
+
+struct atexit *__atexit;
+static int restartloop;
+
+/*
+ * Function pointers are stored in a linked list of pages. The list
+ * is initially empty, and pages are allocated on demand. The first
+ * function pointer in the first allocated page (the last one in
+ * the linked list) is reserved for the cleanup function.
+ *
+ * Outside the following functions, all pages are mprotect()'ed
+ * to prevent unintentional/malicious corruption.
+ */
+
+/*
+ * Register a function to be performed at exit or when a shared object
+ * with the given dso handle is unloaded dynamically.  Also used as
+ * the backend for atexit().  For more info on this API, see:
+ *
+ *	http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor
+ */
+int
+__cxa_atexit(void (*func)(void *), void *arg, void *dso)
+{
+	struct atexit *p = __atexit;
+	struct atexit_fn *fnp;
+	int pgsize = getpagesize();
+	int ret = -1;
+
+	if (pgsize < sizeof(*p))
+		return (-1);
+	_ATEXIT_LOCK();
+	p = __atexit;
+	if (p != NULL) {
+		if (p->ind + 1 >= p->max)
+			p = NULL;
+		else if (mprotect(p, pgsize, PROT_READ | PROT_WRITE))
+			goto unlock;
+	}
+	if (p == NULL) {
+		p = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,
+		    MAP_ANON | MAP_PRIVATE, -1, 0);
+		if (p == MAP_FAILED)
+			goto unlock;
+		if (__atexit == NULL) {
+			memset(&p->fns[0], 0, sizeof(p->fns[0]));
+			p->ind = 1;
+		} else
+			p->ind = 0;
+		p->max = (pgsize - ((char *)&p->fns[0] - (char *)p)) /
+		    sizeof(p->fns[0]);
+		p->next = __atexit;
+		__atexit = p;
+	}
+	fnp = &p->fns[p->ind++];
+	fnp->fn_ptr = func;
+	fnp->fn_arg = arg;
+	fnp->fn_dso = dso;
+	if (mprotect(p, pgsize, PROT_READ))
+		goto unlock;
+	restartloop = 1;
+	ret = 0;
+unlock:
+	_ATEXIT_UNLOCK();
+	return (ret);
+}
+
+/*
+ * Call all handlers registered with __cxa_atexit() for the shared
+ * object owning 'dso'.
+ * Note: if 'dso' is NULL, then all remaining handlers are called.
+ */
+void
+__cxa_finalize(void *dso)
+{
+	struct atexit *p, *q;
+	struct atexit_fn fn;
+	int n, pgsize = getpagesize();
+	static int call_depth;
+
+	_ATEXIT_LOCK();
+	call_depth++;
+
+restart:
+	restartloop = 0;
+	for (p = __atexit; p != NULL; p = p->next) {
+		for (n = p->ind; --n >= 0;) {
+			if (p->fns[n].fn_ptr == NULL)
+				continue;	/* already called */
+			if (dso != NULL && dso != p->fns[n].fn_dso)
+				continue;	/* wrong DSO */
+
+			/*
+			 * Mark handler as having been already called to avoid
+			 * dupes and loops, then call the appropriate function.
+			 */
+			fn = p->fns[n];
+			if (mprotect(p, pgsize, PROT_READ | PROT_WRITE) == 0) {
+				p->fns[n].fn_ptr = NULL;
+				mprotect(p, pgsize, PROT_READ);
+			}
+			_ATEXIT_UNLOCK();
+			(*fn.fn_ptr)(fn.fn_arg);
+			_ATEXIT_LOCK();
+			if (restartloop)
+				goto restart;
+		}
+	}
+
+	call_depth--;
+
+	/*
+	 * If called via exit(), unmap the pages since we have now run
+	 * all the handlers.  We defer this until calldepth == 0 so that
+	 * we don't unmap things prematurely if called recursively.
+	 */
+	if (dso == NULL && call_depth == 0) {
+		for (p = __atexit; p != NULL; ) {
+			q = p;
+			p = p->next;
+			munmap(q, pgsize);
+		}
+		__atexit = NULL;
+	}
+	_ATEXIT_UNLOCK();
+}
+
+/*
+ * Register the cleanup function
+ */
+void
+__atexit_register_cleanup(void (*func)(void))
+{
+	struct atexit *p;
+	int pgsize = getpagesize();
+
+	if (pgsize < sizeof(*p))
+		return;
+	_ATEXIT_LOCK();
+	p = __atexit;
+	while (p != NULL && p->next != NULL)
+		p = p->next;
+	if (p == NULL) {
+		p = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,
+		    MAP_ANON | MAP_PRIVATE, -1, 0);
+		if (p == MAP_FAILED)
+			goto unlock;
+		p->ind = 1;
+		p->max = (pgsize - ((char *)&p->fns[0] - (char *)p)) /
+		    sizeof(p->fns[0]);
+		p->next = NULL;
+		__atexit = p;
+	} else {
+		if (mprotect(p, pgsize, PROT_READ | PROT_WRITE))
+			goto unlock;
+	}
+	p->fns[0].fn_ptr = (void (*)(void *))func;
+	p->fns[0].fn_arg = NULL;
+	p->fns[0].fn_dso = NULL;
+	mprotect(p, pgsize, PROT_READ);
+	restartloop = 1;
+unlock:
+	_ATEXIT_UNLOCK();
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/atexit.h b/libc/upstream-openbsd/lib/libc/stdlib/atexit.h
new file mode 100644
index 0000000..3de2aa3
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atexit.h
@@ -0,0 +1,47 @@
+/*	$OpenBSD: atexit.h,v 1.9 2014/06/18 19:01:10 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2002 Daniel Hartmeier
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *    - Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+struct atexit {
+	struct atexit *next;		/* next in list */
+	int ind;			/* next index in this table */
+	int max;			/* max entries >= ATEXIT_SIZE */
+	struct atexit_fn {
+		void (*fn_ptr)(void *);
+		void *fn_arg;		/* argument for CXA callback */
+		void *fn_dso;		/* shared module handle */
+	} fns[1];			/* the table itself */
+};
+
+extern struct atexit *__atexit;		/* points to head of LIFO stack */
+
+int	__cxa_atexit(void (*)(void *), void *, void *);
+void	__cxa_finalize(void *);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/atoi.c b/libc/upstream-openbsd/lib/libc/stdlib/atoi.c
new file mode 100644
index 0000000..b084267
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atoi.c
@@ -0,0 +1,37 @@
+/*	$OpenBSD: atoi.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+int
+atoi(const char *str)
+{
+	return((int)strtol(str, (char **)NULL, 10));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/atol.c b/libc/upstream-openbsd/lib/libc/stdlib/atol.c
new file mode 100644
index 0000000..1970804
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atol.c
@@ -0,0 +1,37 @@
+/*	$OpenBSD: atol.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+long
+atol(const char *str)
+{
+	return(strtol(str, (char **)NULL, 10));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/atoll.c b/libc/upstream-openbsd/lib/libc/stdlib/atoll.c
new file mode 100644
index 0000000..a65e682
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atoll.c
@@ -0,0 +1,38 @@
+/*	$OpenBSD: atoll.c,v 1.3 2005/08/08 08:05:36 espie Exp $ */
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+long long
+atoll(str)
+	const char *str;
+{
+	return(strtoll(str, (char **)NULL, 10));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/exit.c b/libc/upstream-openbsd/lib/libc/stdlib/exit.c
new file mode 100644
index 0000000..83fe3d2
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/exit.c
@@ -0,0 +1,59 @@
+/*	$OpenBSD: exit.c,v 1.12 2007/09/03 14:40:16 millert Exp $ */
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "atexit.h"
+#include "thread_private.h"
+
+/*
+ * This variable is zero until a process has created a thread.
+ * It is used to avoid calling locking functions in libc when they
+ * are not required. By default, libc is intended to be(come)
+ * thread-safe, but without a (significant) penalty to non-threaded
+ * processes.
+ */
+int     __isthreaded    = 0;
+
+/*
+ * Exit, flushing stdio buffers if necessary.
+ */
+void
+exit(int status)
+{
+	/*
+	 * Call functions registered by atexit() or _cxa_atexit()
+	 * (including the stdio cleanup routine) and then _exit().
+	 */
+	__cxa_finalize(NULL);
+	_exit(status);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/getenv.c b/libc/upstream-openbsd/lib/libc/stdlib/getenv.c
new file mode 100644
index 0000000..fd8482e
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/getenv.c
@@ -0,0 +1,81 @@
+/*	$OpenBSD: getenv.c,v 1.10 2010/08/23 22:31:50 millert Exp $ */
+/*
+ * Copyright (c) 1987, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+char *__findenv(const char *name, int len, int *offset);
+
+/*
+ * __findenv --
+ *	Returns pointer to value associated with name, if any, else NULL.
+ *	Starts searching within the environmental array at offset.
+ *	Sets offset to be the offset of the name/value combination in the
+ *	environmental array, for use by putenv(3), setenv(3) and unsetenv(3).
+ *	Explicitly removes '=' in argument name.
+ *
+ *	This routine *should* be a static; don't use it.
+ */
+char *
+__findenv(const char *name, int len, int *offset)
+{
+	extern char **environ;
+	int i;
+	const char *np;
+	char **p, *cp;
+
+	if (name == NULL || environ == NULL)
+		return (NULL);
+	for (p = environ + *offset; (cp = *p) != NULL; ++p) {
+		for (np = name, i = len; i && *cp; i--)
+			if (*cp++ != *np++)
+				break;
+		if (i == 0 && *cp++ == '=') {
+			*offset = p - environ;
+			return (cp);
+		}
+	}
+	return (NULL);
+}
+
+/*
+ * getenv --
+ *	Returns ptr to value associated with name, if any, else NULL.
+ */
+char *
+getenv(const char *name)
+{
+	int offset = 0;
+	const char *np;
+
+	for (np = name; *np && *np != '='; ++np)
+		;
+	return (__findenv(name, (int)(np - name), &offset));
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/lsearch.c b/libc/upstream-openbsd/lib/libc/stdlib/lsearch.c
new file mode 100644
index 0000000..8cad05f
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/lsearch.c
@@ -0,0 +1,84 @@
+/*	$OpenBSD: lsearch.c,v 1.5 2014/07/18 04:16:09 matthew Exp $	*/
+
+/*
+ * Copyright (c) 1989, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Roger L. Snyder.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include <search.h>
+
+typedef int (*cmp_fn_t)(const void *, const void *);
+static void *linear_base(const void *, const void *, size_t *, size_t,
+    cmp_fn_t, int);
+
+void *
+lsearch(const void *key, void *base, size_t *nelp, size_t width,
+    	cmp_fn_t compar)
+{
+
+	return(linear_base(key, base, nelp, width, compar, 1));
+}
+
+void *
+lfind(const void *key, const void *base, size_t *nelp, size_t width,
+	cmp_fn_t compar)
+{
+	return(linear_base(key, base, nelp, width, compar, 0));
+}
+
+static void *
+linear_base(const void *key, const void *base, size_t *nelp, size_t width,
+	cmp_fn_t compar, int add_flag)
+{
+	const char *element, *end;
+
+	end = (const char *)base + *nelp * width;
+	for (element = base; element < end; element += width)
+		if (!compar(key, element))		/* key found */
+			return((void *)element);
+
+	if (!add_flag)					/* key not found */
+		return(NULL);
+
+	/*
+	 * The UNIX System User's Manual, 1986 edition claims that
+	 * a NULL pointer is returned by lsearch with errno set
+	 * appropriately, if there is not enough room in the table
+	 * to add a new item.  This can't be done as none of these
+	 * routines have any method of determining the size of the
+	 * table.  This comment isn't in the 1986-87 System V
+	 * manual.
+	 */
+	++*nelp;
+	memcpy((void *)end, key, width);
+	return((void *)end);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/setenv.c b/libc/upstream-openbsd/lib/libc/stdlib/setenv.c
new file mode 100644
index 0000000..9060fdb
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/setenv.c
@@ -0,0 +1,180 @@
+/*	$OpenBSD: setenv.c,v 1.14 2012/09/23 16:08:04 jeremy Exp $ */
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *__findenv(const char *name, int len, int *offset);
+
+extern char **environ;
+static char **lastenv;				/* last value of environ */
+
+/*
+ * putenv --
+ *	Add a name=value string directly to the environmental, replacing
+ *	any current value.
+ */
+int
+putenv(char *str)
+{
+	char **P, *cp;
+	size_t cnt;
+	int offset = 0;
+
+	for (cp = str; *cp && *cp != '='; ++cp)
+		;
+	if (*cp != '=') {
+		errno = EINVAL;
+		return (-1);			/* missing `=' in string */
+	}
+
+	if (__findenv(str, (int)(cp - str), &offset) != NULL) {
+		environ[offset++] = str;
+		/* could be set multiple times */
+		while (__findenv(str, (int)(cp - str), &offset)) {
+			for (P = &environ[offset];; ++P)
+				if (!(*P = *(P + 1)))
+					break;
+		}
+		return (0);
+	}
+
+	/* create new slot for string */
+	for (P = environ; *P != NULL; P++)
+		;
+	cnt = P - environ;
+	P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
+	if (!P)
+		return (-1);
+	if (lastenv != environ)
+		memcpy(P, environ, cnt * sizeof(char *));
+	lastenv = environ = P;
+	environ[cnt] = str;
+	environ[cnt + 1] = NULL;
+	return (0);
+}
+
+/*
+ * setenv --
+ *	Set the value of the environmental variable "name" to be
+ *	"value".  If rewrite is set, replace any current value.
+ */
+int
+setenv(const char *name, const char *value, int rewrite)
+{
+	char *C, **P;
+	const char *np;
+	int l_value, offset = 0;
+
+	if (!name || !*name) {
+		errno = EINVAL;
+		return (-1);
+	}
+	for (np = name; *np && *np != '='; ++np)
+		;
+	if (*np) {
+		errno = EINVAL;
+		return (-1);			/* has `=' in name */
+	}
+
+	l_value = strlen(value);
+	if ((C = __findenv(name, (int)(np - name), &offset)) != NULL) {
+		int tmpoff = offset + 1;
+		if (!rewrite)
+			return (0);
+#if 0 /* XXX - existing entry may not be writable */
+		if (strlen(C) >= l_value) {	/* old larger; copy over */
+			while ((*C++ = *value++))
+				;
+			return (0);
+		}
+#endif
+		/* could be set multiple times */
+		while (__findenv(name, (int)(np - name), &tmpoff)) {
+			for (P = &environ[tmpoff];; ++P)
+				if (!(*P = *(P + 1)))
+					break;
+		}
+	} else {					/* create new slot */
+		size_t cnt;
+
+		for (P = environ; *P != NULL; P++)
+			;
+		cnt = P - environ;
+		P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
+		if (!P)
+			return (-1);
+		if (lastenv != environ)
+			memcpy(P, environ, cnt * sizeof(char *));
+		lastenv = environ = P;
+		offset = cnt;
+		environ[cnt + 1] = NULL;
+	}
+	if (!(environ[offset] =			/* name + `=' + value */
+	    malloc((size_t)((int)(np - name) + l_value + 2))))
+		return (-1);
+	for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
+		;
+	for (*C++ = '='; (*C++ = *value++); )
+		;
+	return (0);
+}
+
+/*
+ * unsetenv(name) --
+ *	Delete environmental variable "name".
+ */
+int
+unsetenv(const char *name)
+{
+	char **P;
+	const char *np;
+	int offset = 0;
+
+	if (!name || !*name) {
+		errno = EINVAL;
+		return (-1);
+	}
+	for (np = name; *np && *np != '='; ++np)
+		;
+	if (*np) {
+		errno = EINVAL;
+		return (-1);			/* has `=' in name */
+	}
+
+	/* could be set multiple times */
+	while (__findenv(name, (int)(np - name), &offset)) {
+		for (P = &environ[offset];; ++P)
+			if (!(*P = *(P + 1)))
+				break;
+	}
+	return (0);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
new file mode 100644
index 0000000..2c77f41
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
@@ -0,0 +1,140 @@
+/*	$OpenBSD: strtoimax.c,v 1.1 2006/01/13 17:58:09 millert Exp $	*/
+
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+
+/*
+ * Convert a string to an intmax_t
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+intmax_t
+strtoimax(const char *nptr, char **endptr, int base)
+{
+	const char *s;
+	intmax_t acc, cutoff;
+	int c;
+	int neg, any, cutlim;
+
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	s = nptr;
+	do {
+		c = (unsigned char) *s++;
+	} while (isspace(c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for intmax_t is
+	 * [-9223372036854775808..9223372036854775807] and the input base
+	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
+	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+	 * accumulated a value > 922337203685477580, or equal but the
+	 * next digit is > 7 (or 8), the number is too big, and we will
+	 * return a range error.
+	 *
+	 * Set any if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? INTMAX_MIN : INTMAX_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	if (neg) {
+		if (cutlim > 0) {
+			cutlim -= base;
+			cutoff += 1;
+		}
+		cutlim = -cutlim;
+	}
+	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
+		if (isdigit(c))
+			c -= '0';
+		else if (isalpha(c))
+			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0)
+			continue;
+		if (neg) {
+			if (acc < cutoff || (acc == cutoff && c > cutlim)) {
+				any = -1;
+				acc = INTMAX_MIN;
+				errno = ERANGE;
+			} else {
+				any = 1;
+				acc *= base;
+				acc -= c;
+			}
+		} else {
+			if (acc > cutoff || (acc == cutoff && c > cutlim)) {
+				any = -1;
+				acc = INTMAX_MAX;
+				errno = ERANGE;
+			} else {
+				any = 1;
+				acc *= base;
+				acc += c;
+			}
+		}
+	}
+	if (endptr != 0)
+		*endptr = (char *) (any ? s - 1 : nptr);
+	return (acc);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtol.c b/libc/upstream-openbsd/lib/libc/stdlib/strtol.c
new file mode 100644
index 0000000..dc2cf88
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtol.c
@@ -0,0 +1,151 @@
+/*	$OpenBSD: strtol.c,v 1.9 2013/04/17 17:40:35 tedu Exp $ */
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+
+/*
+ * Convert a string to a long integer.
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+long
+strtol(const char *nptr, char **endptr, int base)
+{
+	const char *s;
+	long acc, cutoff;
+	int c;
+	int neg, any, cutlim;
+
+	/*
+	 * Ensure that base is between 2 and 36 inclusive, or the special
+	 * value of 0.
+	 */
+	if (base != 0 && (base < 2 || base > 36)) {
+		if (endptr != 0)
+			*endptr = (char *)nptr;
+		errno = EINVAL;
+		return 0;
+	}
+
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	s = nptr;
+	do {
+		c = (unsigned char) *s++;
+	} while (isspace(c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for longs is
+	 * [-2147483648..2147483647] and the input base is 10,
+	 * cutoff will be set to 214748364 and cutlim to either
+	 * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
+	 * a value > 214748364, or equal but the next digit is > 7 (or 8),
+	 * the number is too big, and we will return a range error.
+	 *
+	 * Set any if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? LONG_MIN : LONG_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	if (neg) {
+		if (cutlim > 0) {
+			cutlim -= base;
+			cutoff += 1;
+		}
+		cutlim = -cutlim;
+	}
+	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
+		if (isdigit(c))
+			c -= '0';
+		else if (isalpha(c))
+			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0)
+			continue;
+		if (neg) {
+			if (acc < cutoff || (acc == cutoff && c > cutlim)) {
+				any = -1;
+				acc = LONG_MIN;
+				errno = ERANGE;
+			} else {
+				any = 1;
+				acc *= base;
+				acc -= c;
+			}
+		} else {
+			if (acc > cutoff || (acc == cutoff && c > cutlim)) {
+				any = -1;
+				acc = LONG_MAX;
+				errno = ERANGE;
+			} else {
+				any = 1;
+				acc *= base;
+				acc += c;
+			}
+		}
+	}
+	if (endptr != 0)
+		*endptr = (char *) (any ? s - 1 : nptr);
+	return (acc);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
new file mode 100644
index 0000000..4bcc556
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
@@ -0,0 +1,144 @@
+/* $OpenBSD: strtoll.c,v 1.7 2013/03/28 18:09:38 martynas Exp $ */
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+/*
+ * Convert a string to a long long.
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+long long
+strtoll(const char *nptr, char **endptr, int base)
+{
+	const char *s;
+	long long acc, cutoff;
+	int c;
+	int neg, any, cutlim;
+
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	s = nptr;
+	do {
+		c = (unsigned char) *s++;
+	} while (isspace(c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for long longs is
+	 * [-9223372036854775808..9223372036854775807] and the input base
+	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
+	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+	 * accumulated a value > 922337203685477580, or equal but the
+	 * next digit is > 7 (or 8), the number is too big, and we will
+	 * return a range error.
+	 *
+	 * Set any if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? LLONG_MIN : LLONG_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	if (neg) {
+		if (cutlim > 0) {
+			cutlim -= base;
+			cutoff += 1;
+		}
+		cutlim = -cutlim;
+	}
+	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
+		if (isdigit(c))
+			c -= '0';
+		else if (isalpha(c))
+			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0)
+			continue;
+		if (neg) {
+			if (acc < cutoff || (acc == cutoff && c > cutlim)) {
+				any = -1;
+				acc = LLONG_MIN;
+				errno = ERANGE;
+			} else {
+				any = 1;
+				acc *= base;
+				acc -= c;
+			}
+		} else {
+			if (acc > cutoff || (acc == cutoff && c > cutlim)) {
+				any = -1;
+				acc = LLONG_MAX;
+				errno = ERANGE;
+			} else {
+				any = 1;
+				acc *= base;
+				acc += c;
+			}
+		}
+	}
+	if (endptr != 0)
+		*endptr = (char *) (any ? s - 1 : nptr);
+	return (acc);
+}
+
+__strong_alias(strtoq, strtoll);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c
new file mode 100644
index 0000000..a236365
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c
@@ -0,0 +1,102 @@
+/*	$OpenBSD: strtoul.c,v 1.8 2013/04/17 17:40:35 tedu Exp $ */
+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+/*
+ * Convert a string to an unsigned long integer.
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long
+strtoul(const char *nptr, char **endptr, int base)
+{
+	const char *s;
+	unsigned long acc, cutoff;
+	int c;
+	int neg, any, cutlim;
+
+	/*
+	 * See strtol for comments as to the logic used.
+	 */
+	s = nptr;
+	do {
+		c = (unsigned char) *s++;
+	} while (isspace(c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+
+	cutoff = ULONG_MAX / (unsigned long)base;
+	cutlim = ULONG_MAX % (unsigned long)base;
+	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
+		if (isdigit(c))
+			c -= '0';
+		else if (isalpha(c))
+			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0)
+			continue;
+		if (acc > cutoff || (acc == cutoff && c > cutlim)) {
+			any = -1;
+			acc = ULONG_MAX;
+			errno = ERANGE;
+		} else {
+			any = 1;
+			acc *= (unsigned long)base;
+			acc += c;
+		}
+	}
+	if (neg && any > 0)
+		acc = -acc;
+	if (endptr != 0)
+		*endptr = (char *) (any ? s - 1 : nptr);
+	return (acc);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
new file mode 100644
index 0000000..28f613a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
@@ -0,0 +1,106 @@
+/*	$OpenBSD: strtoull.c,v 1.6 2013/03/28 18:09:38 martynas Exp $ */
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+/*
+ * Convert a string to an unsigned long long.
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long long
+strtoull(const char *nptr, char **endptr, int base)
+{
+	const char *s;
+	unsigned long long acc, cutoff;
+	int c;
+	int neg, any, cutlim;
+
+	/*
+	 * See strtoq for comments as to the logic used.
+	 */
+	s = nptr;
+	do {
+		c = (unsigned char) *s++;
+	} while (isspace(c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else { 
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+
+	cutoff = ULLONG_MAX / (unsigned long long)base;
+	cutlim = ULLONG_MAX % (unsigned long long)base;
+	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
+		if (isdigit(c))
+			c -= '0';
+		else if (isalpha(c))
+			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0)
+			continue;
+		if (acc > cutoff || (acc == cutoff && c > cutlim)) {
+			any = -1;
+			acc = ULLONG_MAX;
+			errno = ERANGE;
+		} else {
+			any = 1;
+			acc *= (unsigned long long)base;
+			acc += c;
+		}
+	}
+	if (neg && any > 0)
+		acc = -acc;
+	if (endptr != 0)
+		*endptr = (char *) (any ? s - 1 : nptr);
+	return (acc);
+}
+
+__strong_alias(strtouq, strtoull);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
new file mode 100644
index 0000000..ce6e2c0
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
@@ -0,0 +1,102 @@
+/*	$OpenBSD: strtoumax.c,v 1.1 2006/01/13 17:58:09 millert Exp $	*/
+
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+
+/*
+ * Convert a string to a uintmax_t.
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+uintmax_t
+strtoumax(const char *nptr, char **endptr, int base)
+{
+	const char *s;
+	uintmax_t acc, cutoff;
+	int c;
+	int neg, any, cutlim;
+
+	/*
+	 * See strtoq for comments as to the logic used.
+	 */
+	s = nptr;
+	do {
+		c = (unsigned char) *s++;
+	} while (isspace(c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else { 
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+
+	cutoff = UINTMAX_MAX / (uintmax_t)base;
+	cutlim = UINTMAX_MAX % (uintmax_t)base;
+	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
+		if (isdigit(c))
+			c -= '0';
+		else if (isalpha(c))
+			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0)
+			continue;
+		if (acc > cutoff || (acc == cutoff && c > cutlim)) {
+			any = -1;
+			acc = UINTMAX_MAX;
+			errno = ERANGE;
+		} else {
+			any = 1;
+			acc *= (uintmax_t)base;
+			acc += c;
+		}
+	}
+	if (neg && any > 0)
+		acc = -acc;
+	if (endptr != 0)
+		*endptr = (char *) (any ? s - 1 : nptr);
+	return (acc);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/system.c b/libc/upstream-openbsd/lib/libc/stdlib/system.c
new file mode 100644
index 0000000..14ddcae
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/system.c
@@ -0,0 +1,74 @@
+/*	$OpenBSD: system.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */
+/*
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <paths.h>
+
+extern char **environ;
+
+int
+system(const char *command)
+{
+	pid_t pid;
+	sig_t intsave, quitsave;
+	sigset_t mask, omask;
+	int pstat;
+	char *argp[] = {"sh", "-c", NULL, NULL};
+
+	if (!command)		/* just checking... */
+		return(1);
+
+	argp[2] = (char *)command;
+
+	sigemptyset(&mask);
+	sigaddset(&mask, SIGCHLD);
+	sigprocmask(SIG_BLOCK, &mask, &omask);
+	switch (pid = vfork()) {
+	case -1:			/* error */
+		sigprocmask(SIG_SETMASK, &omask, NULL);
+		return(-1);
+	case 0:				/* child */
+		sigprocmask(SIG_SETMASK, &omask, NULL);
+		execve(_PATH_BSHELL, argp, environ);
+		_exit(127);
+	}
+
+	intsave = signal(SIGINT, SIG_IGN);
+	quitsave = signal(SIGQUIT, SIG_IGN);
+	pid = waitpid(pid, (int *)&pstat, 0);
+	sigprocmask(SIG_SETMASK, &omask, NULL);
+	(void)signal(SIGINT, intsave);
+	(void)signal(SIGQUIT, quitsave);
+	return (pid == -1 ? -1 : pstat);
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/tfind.c b/libc/upstream-openbsd/lib/libc/stdlib/tfind.c
new file mode 100644
index 0000000..0d1d519
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/tfind.c
@@ -0,0 +1,41 @@
+/*	$OpenBSD: tfind.c,v 1.6 2014/03/16 18:38:30 guenther Exp $	*/
+
+/*
+ * Tree search generalized from Knuth (6.2.2) Algorithm T just like
+ * the AT&T man page says.
+ *
+ * The node_t structure is for internal use only
+ *
+ * Written by reading the System V Interface Definition, not the code.
+ *
+ * Totally public domain.
+ */
+/*LINTLIBRARY*/
+#include <search.h>
+
+typedef struct node_t
+{
+    char	  *key;
+    struct node_t *llink, *rlink;
+} node;
+
+/* find a node, or return 0 */
+void *
+tfind(const void *vkey, void * const *vrootp,
+    int (*compar)(const void *, const void *))
+{
+    char *key = (char *)vkey;
+    node **rootp = (node **)vrootp;
+
+    if (rootp == (struct node_t **)0)
+	return ((struct node_t *)0);
+    while (*rootp != (struct node_t *)0) {	/* T1: */
+	int r;
+	if ((r = (*compar)(key, (*rootp)->key)) == 0)	/* T2: */
+	    return (*rootp);		/* key found */
+	rootp = (r < 0) ?
+	    &(*rootp)->llink :		/* T3: follow left branch */
+	    &(*rootp)->rlink;		/* T4: follow right branch */
+    }
+    return (node *)0;
+}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/tsearch.c b/libc/upstream-openbsd/lib/libc/stdlib/tsearch.c
new file mode 100644
index 0000000..a141085
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/tsearch.c
@@ -0,0 +1,119 @@
+/*	$OpenBSD: tsearch.c,v 1.8 2014/03/16 18:38:30 guenther Exp $	*/
+
+/*
+ * Tree search generalized from Knuth (6.2.2) Algorithm T just like
+ * the AT&T man page says.
+ *
+ * The node_t structure is for internal use only
+ *
+ * Written by reading the System V Interface Definition, not the code.
+ *
+ * Totally public domain.
+ */
+/*LINTLIBRARY*/
+
+#include <search.h>
+#include <stdlib.h>
+
+typedef struct node_t {
+    char	  *key;
+    struct node_t *left, *right;
+} node;
+
+/* find or insert datum into search tree */
+void *
+tsearch(const void *vkey, void **vrootp,
+    int (*compar)(const void *, const void *))
+{
+    node *q;
+    char *key = (char *)vkey;
+    node **rootp = (node **)vrootp;
+
+    if (rootp == (struct node_t **)0)
+	return ((void *)0);
+    while (*rootp != (struct node_t *)0) {	/* Knuth's T1: */
+	int r;
+
+	if ((r = (*compar)(key, (*rootp)->key)) == 0)	/* T2: */
+	    return ((void *)*rootp);		/* we found it! */
+	rootp = (r < 0) ?
+	    &(*rootp)->left :		/* T3: follow left branch */
+	    &(*rootp)->right;		/* T4: follow right branch */
+    }
+    q = (node *) malloc(sizeof(node));	/* T5: key not found */
+    if (q != (struct node_t *)0) {	/* make new node */
+	*rootp = q;			/* link new node to old */
+	q->key = key;			/* initialize new node */
+	q->left = q->right = (struct node_t *)0;
+    }
+    return ((void *)q);
+}
+
+/* delete node with given key */
+void *
+tdelete(const void *vkey, void **vrootp,
+    int (*compar)(const void *, const void *))
+{
+    node **rootp = (node **)vrootp;
+    char *key = (char *)vkey;
+    node *p = (node *)1;
+    node *q;
+    node *r;
+    int cmp;
+
+    if (rootp == (struct node_t **)0 || *rootp == (struct node_t *)0)
+	return ((struct node_t *)0);
+    while ((cmp = (*compar)(key, (*rootp)->key)) != 0) {
+	p = *rootp;
+	rootp = (cmp < 0) ?
+	    &(*rootp)->left :		/* follow left branch */
+	    &(*rootp)->right;		/* follow right branch */
+	if (*rootp == (struct node_t *)0)
+	    return ((void *)0);		/* key not found */
+    }
+    r = (*rootp)->right;			/* D1: */
+    if ((q = (*rootp)->left) == (struct node_t *)0)	/* Left (struct node_t *)0? */
+	q = r;
+    else if (r != (struct node_t *)0) {		/* Right link is null? */
+	if (r->left == (struct node_t *)0) {	/* D2: Find successor */
+	    r->left = q;
+	    q = r;
+	} else {			/* D3: Find (struct node_t *)0 link */
+	    for (q = r->left; q->left != (struct node_t *)0; q = r->left)
+		r = q;
+	    r->left = q->right;
+	    q->left = (*rootp)->left;
+	    q->right = (*rootp)->right;
+	}
+    }
+    free((struct node_t *) *rootp);	/* D4: Free node */
+    *rootp = q;				/* link parent to new node */
+    return(p);
+}
+
+/* Walk the nodes of a tree */
+static void
+trecurse(node *root, void (*action)(const void *, VISIT, int), int level)
+{
+    if (root->left == (struct node_t *)0 && root->right == (struct node_t *)0)
+	(*action)(root, leaf, level);
+    else {
+	(*action)(root, preorder, level);
+	if (root->left != (struct node_t *)0)
+	    trecurse(root->left, action, level + 1);
+	(*action)(root, postorder, level);
+	if (root->right != (struct node_t *)0)
+	    trecurse(root->right, action, level + 1);
+	(*action)(root, endorder, level);
+    }
+}
+
+/* Walk the nodes of a tree */
+void
+twalk(const void *vroot, void (*action)(const void *, VISIT, int))
+{
+    node *root = (node *)vroot;
+
+    if (root != (node *)0 && action != (void (*)(const void *, VISIT, int))0)
+	trecurse(root, action, 0);
+}
diff --git a/libc/string/bcopy.c b/libc/upstream-openbsd/lib/libc/string/bcopy.c
similarity index 100%
rename from libc/string/bcopy.c
rename to libc/upstream-openbsd/lib/libc/string/bcopy.c
diff --git a/libc/upstream-openbsd/lib/libc/string/stpcpy.c b/libc/upstream-openbsd/lib/libc/string/stpcpy.c
new file mode 100644
index 0000000..d88afac
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/stpcpy.c
@@ -0,0 +1,44 @@
+/*	$OpenBSD: stpcpy.c,v 1.2 2014/07/09 17:08:21 naddy Exp $	*/
+
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+#if defined(APIWARN)
+__warn_references(stpcpy,
+    "warning: stpcpy() is dangerous; do not use it");
+#endif
+
+char *
+stpcpy(char *to, const char *from)
+{
+	for (; (*to = *from) != '\0'; ++from, ++to);
+	return(to);
+}
diff --git a/libc/upstream-openbsd/lib/libc/string/stpncpy.c b/libc/upstream-openbsd/lib/libc/string/stpncpy.c
new file mode 100644
index 0000000..c7c2a57
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/stpncpy.c
@@ -0,0 +1,56 @@
+/*	$OpenBSD: stpncpy.c,v 1.2 2012/07/11 10:44:59 naddy Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+char *
+stpncpy(char *dst, const char *src, size_t n)
+{
+	if (n != 0) {
+		char *d = dst;
+		const char *s = src;
+
+		dst = &dst[n];
+		do {
+			if ((*d++ = *s++) == 0) {
+				dst = d - 1;
+				/* NUL pad the remaining n-1 bytes */
+				while (--n != 0)
+					*d++ = 0;
+				break;
+			}
+		} while (--n != 0);
+	}
+	return (dst);
+}
diff --git a/libc/string/strcasecmp.c b/libc/upstream-openbsd/lib/libc/string/strcasecmp.c
similarity index 100%
rename from libc/string/strcasecmp.c
rename to libc/upstream-openbsd/lib/libc/string/strcasecmp.c
diff --git a/libc/upstream-openbsd/lib/libc/string/strcat.c b/libc/upstream-openbsd/lib/libc/string/strcat.c
new file mode 100644
index 0000000..646c9c2
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strcat.c
@@ -0,0 +1,47 @@
+/*	$OpenBSD: strcat.c,v 1.9 2014/06/10 04:17:37 deraadt Exp $	*/
+
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+#if defined(APIWARN)
+__warn_references(strcat,
+    "warning: strcat() is almost always misused, please use strlcat()");
+#endif
+
+char *
+strcat(char *s, const char *append)
+{
+	char *save = s;
+
+	for (; *s; ++s);
+	while ((*s++ = *append++) != '\0');
+	return(save);
+}
diff --git a/libc/upstream-openbsd/lib/libc/string/strcmp.c b/libc/upstream-openbsd/lib/libc/string/strcmp.c
new file mode 100644
index 0000000..d1b6c50
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strcmp.c
@@ -0,0 +1,47 @@
+/*	$OpenBSD: strcmp.c,v 1.8 2014/06/10 04:17:37 deraadt Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+/*
+ * Compare strings.
+ */
+int
+strcmp(const char *s1, const char *s2)
+{
+	while (*s1 == *s2++)
+		if (*s1++ == 0)
+			return (0);
+	return (*(unsigned char *)s1 - *(unsigned char *)--s2);
+}
diff --git a/libc/upstream-openbsd/lib/libc/string/strcpy.c b/libc/upstream-openbsd/lib/libc/string/strcpy.c
new file mode 100644
index 0000000..5a9001e
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strcpy.c
@@ -0,0 +1,46 @@
+/*	$OpenBSD: strcpy.c,v 1.9 2014/06/10 04:17:37 deraadt Exp $	*/
+
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+#if defined(APIWARN)
+__warn_references(strcpy,
+    "warning: strcpy() is almost always misused, please use strlcpy()");
+#endif
+
+char *
+strcpy(char *to, const char *from)
+{
+	char *save = to;
+
+	for (; (*to = *from) != '\0'; ++from, ++to);
+	return(save);
+}
diff --git a/libc/string/strcspn.c b/libc/upstream-openbsd/lib/libc/string/strcspn.c
similarity index 100%
rename from libc/string/strcspn.c
rename to libc/upstream-openbsd/lib/libc/string/strcspn.c
diff --git a/libc/string/strdup.c b/libc/upstream-openbsd/lib/libc/string/strdup.c
similarity index 100%
rename from libc/string/strdup.c
rename to libc/upstream-openbsd/lib/libc/string/strdup.c
diff --git a/libc/string/strlcat.c b/libc/upstream-openbsd/lib/libc/string/strlcat.c
similarity index 100%
rename from libc/string/strlcat.c
rename to libc/upstream-openbsd/lib/libc/string/strlcat.c
diff --git a/libc/string/strlcpy.c b/libc/upstream-openbsd/lib/libc/string/strlcpy.c
similarity index 100%
rename from libc/string/strlcpy.c
rename to libc/upstream-openbsd/lib/libc/string/strlcpy.c
diff --git a/libc/upstream-openbsd/lib/libc/string/strlen.c b/libc/upstream-openbsd/lib/libc/string/strlen.c
new file mode 100644
index 0000000..7e0e27b
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strlen.c
@@ -0,0 +1,43 @@
+/*	$OpenBSD: strlen.c,v 1.8 2014/06/10 04:17:37 deraadt Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+size_t
+strlen(const char *str)
+{
+	const char *s;
+
+	for (s = str; *s; ++s)
+		;
+	return (s - str);
+}
+
diff --git a/libc/string/strncat.c b/libc/upstream-openbsd/lib/libc/string/strncat.c
similarity index 100%
rename from libc/string/strncat.c
rename to libc/upstream-openbsd/lib/libc/string/strncat.c
diff --git a/libc/upstream-openbsd/lib/libc/string/strncmp.c b/libc/upstream-openbsd/lib/libc/string/strncmp.c
new file mode 100644
index 0000000..0a4ddc1
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strncmp.c
@@ -0,0 +1,47 @@
+/*	$OpenBSD: strncmp.c,v 1.8 2014/06/10 04:17:37 deraadt Exp $	*/
+
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+int
+strncmp(const char *s1, const char *s2, size_t n)
+{
+
+	if (n == 0)
+		return (0);
+	do {
+		if (*s1 != *s2++)
+			return (*(unsigned char *)s1 - *(unsigned char *)--s2);
+		if (*s1++ == 0)
+			break;
+	} while (--n != 0);
+	return (0);
+}
diff --git a/libc/upstream-openbsd/lib/libc/string/strncpy.c b/libc/upstream-openbsd/lib/libc/string/strncpy.c
new file mode 100644
index 0000000..5003a19
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strncpy.c
@@ -0,0 +1,58 @@
+/*	$OpenBSD: strncpy.c,v 1.7 2014/06/10 04:17:37 deraadt Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+/*
+ * Copy src to dst, truncating or null-padding to always copy n bytes.
+ * Return dst.
+ */
+char *
+strncpy(char *dst, const char *src, size_t n)
+{
+	if (n != 0) {
+		char *d = dst;
+		const char *s = src;
+
+		do {
+			if ((*d++ = *s++) == 0) {
+				/* NUL pad the remaining n-1 bytes */
+				while (--n != 0)
+					*d++ = 0;
+				break;
+			}
+		} while (--n != 0);
+	}
+	return (dst);
+}
diff --git a/libc/upstream-openbsd/lib/libc/string/strndup.c b/libc/upstream-openbsd/lib/libc/string/strndup.c
new file mode 100644
index 0000000..27701ac
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strndup.c
@@ -0,0 +1,39 @@
+/*	$OpenBSD: strndup.c,v 1.1 2010/05/18 22:24:55 tedu Exp $	*/
+
+/*
+ * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+#include <sys/types.h>
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+strndup(const char *str, size_t maxlen)
+{
+	char *copy;
+	size_t len;
+
+	len = strnlen(str, maxlen);
+	copy = malloc(len + 1);
+	if (copy != NULL) {
+		(void)memcpy(copy, str, len);
+		copy[len] = '\0';
+	}
+
+	return copy;
+}
diff --git a/libc/string/strpbrk.c b/libc/upstream-openbsd/lib/libc/string/strpbrk.c
similarity index 100%
rename from libc/string/strpbrk.c
rename to libc/upstream-openbsd/lib/libc/string/strpbrk.c
diff --git a/libc/upstream-openbsd/lib/libc/string/strsep.c b/libc/upstream-openbsd/lib/libc/string/strsep.c
new file mode 100644
index 0000000..2ffc4b4
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strsep.c
@@ -0,0 +1,70 @@
+/*	$OpenBSD: strsep.c,v 1.7 2014/02/05 20:42:32 stsp Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.  
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+strsep(char **stringp, const char *delim)
+{
+	char *s;
+	const char *spanp;
+	int c, sc;
+	char *tok;
+
+	if ((s = *stringp) == NULL)
+		return (NULL);
+	for (tok = s;;) {
+		c = *s++;
+		spanp = delim;
+		do {
+			if ((sc = *spanp++) == c) {
+				if (c == 0)
+					s = NULL;
+				else
+					s[-1] = 0;
+				*stringp = s;
+				return (tok);
+			}
+		} while (sc != 0);
+	}
+	/* NOTREACHED */
+}
diff --git a/libc/string/strspn.c b/libc/upstream-openbsd/lib/libc/string/strspn.c
similarity index 100%
rename from libc/string/strspn.c
rename to libc/upstream-openbsd/lib/libc/string/strspn.c
diff --git a/libc/string/strstr.c b/libc/upstream-openbsd/lib/libc/string/strstr.c
similarity index 100%
rename from libc/string/strstr.c
rename to libc/upstream-openbsd/lib/libc/string/strstr.c
diff --git a/libc/string/strtok.c b/libc/upstream-openbsd/lib/libc/string/strtok.c
similarity index 100%
rename from libc/string/strtok.c
rename to libc/upstream-openbsd/lib/libc/string/strtok.c
diff --git a/libc/upstream-openbsd/lib/libc/string/wcslcpy.c b/libc/upstream-openbsd/lib/libc/string/wcslcpy.c
new file mode 100644
index 0000000..f49936a
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/wcslcpy.c
@@ -0,0 +1,52 @@
+/*	$OpenBSD: wcslcpy.c,v 1.5 2011/07/24 15:21:28 millert Exp $	*/
+/*	$NetBSD: wcslcpy.c,v 1.2 2001/01/03 14:33:02 lukem Exp $	*/
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+
+#include <sys/types.h>
+#include <wchar.h>
+
+/*
+ * Copy src to string dst of size siz.  At most siz-1 characters
+ * will be copied.  Always NUL terminates (unless siz == 0).
+ * Returns wcslen(src); if retval >= siz, truncation occurred.
+ */
+size_t
+wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
+{
+	wchar_t *d = dst;
+	const wchar_t *s = src;
+	size_t n = siz;
+
+	/* Copy as many bytes as will fit */
+	if (n != 0) {
+		while (--n != 0) {
+			if ((*d++ = *s++) == '\0')
+				break;
+		}
+	}
+
+	/* Not enough room in dst, add NUL and traverse rest of src */
+	if (n == 0) {
+		if (siz != 0)
+			*d = '\0';		/* NUL-terminate dst */
+		while (*s++)
+			;
+	}
+
+	return(s - src - 1);	/* count does not include NUL */
+}
diff --git a/libc/upstream-openbsd/lib/libc/string/wcsstr.c b/libc/upstream-openbsd/lib/libc/string/wcsstr.c
new file mode 100644
index 0000000..669e340
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/wcsstr.c
@@ -0,0 +1,70 @@
+/*	$OpenBSD: wcsstr.c,v 1.3 2005/08/08 08:05:37 espie Exp $	*/
+/*	$NetBSD: wcsstr.c,v 1.3 2003/03/05 20:18:17 tshiozak Exp $	*/
+
+/*-
+ * Copyright (c)1999 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
+ */
+
+#include <wchar.h>
+
+wchar_t *
+#ifdef WCSWCS
+wcswcs(const wchar_t *big, const wchar_t *little)
+#else
+wcsstr(const wchar_t *big, const wchar_t *little)
+#endif
+{
+	const wchar_t *p;
+	const wchar_t *q;
+	const wchar_t *r;
+
+	if (!*little) {
+		/* LINTED interface specification */
+		return (wchar_t *)big;
+	}
+	if (wcslen(big) < wcslen(little))
+		return NULL;
+
+	p = big;
+	q = little;
+	while (*p) {
+		q = little;
+		r = p;
+		while (*q) {
+			if (*r != *q)
+				break;
+			q++;
+			r++;
+		}
+		if (!*q) {
+			/* LINTED interface specification */
+			return (wchar_t *)p;
+		}
+		p++;
+	}
+	return NULL;
+}
diff --git a/libc/upstream-openbsd/lib/libc/string/wcswidth.c b/libc/upstream-openbsd/lib/libc/string/wcswidth.c
new file mode 100644
index 0000000..8ea1bdf
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/wcswidth.c
@@ -0,0 +1,50 @@
+/*	$OpenBSD: wcswidth.c,v 1.4 2011/04/04 18:16:24 stsp Exp $	*/
+/*	$NetBSD: wcswidth.c,v 1.2 2001/01/03 14:29:37 lukem Exp $	*/
+
+/*-
+ * Copyright (c)1999 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	citrus Id: wcswidth.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
+ */
+
+#include <wchar.h>
+
+int
+wcswidth(const wchar_t *s, size_t n)
+{
+	int w, q;
+
+	w = 0;
+	while (n && *s) {
+		q = wcwidth(*s);
+		if (q == -1)
+			return (-1);
+		w += q;
+		s++;
+		n--;
+	}
+
+	return w;
+}
diff --git a/libc/upstream-openbsd/lib/libc/time/wcsftime.c b/libc/upstream-openbsd/lib/libc/time/wcsftime.c
new file mode 100644
index 0000000..21ccac7
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/time/wcsftime.c
@@ -0,0 +1,555 @@
+/*	$OpenBSD: wcsftime.c,v 1.3 2014/05/06 15:49:45 tedu Exp $ */
+#include "private.h"
+
+/*
+** Based on the UCB version with the ID appearing below.
+** This is ANSIish only when "multibyte character == plain character".
+**
+** Copyright (c) 1989, 1993
+**	The Regents of the University of California.  All rights reserved.
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions
+** are met:
+** 1. Redistributions of source code must retain the above copyright
+**    notice, this list of conditions and the following disclaimer.
+** 2. Redistributions in binary form must reproduce the above copyright
+**    notice, this list of conditions and the following disclaimer in the
+**    documentation and/or other materials provided with the distribution.
+** 3. Neither the name of the University nor the names of its contributors
+**    may be used to endorse or promote products derived from this software
+**    without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+** ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+** SUCH DAMAGE.
+*/
+
+#include "tzfile.h"
+#include "fcntl.h"
+#include <locale.h>
+#include <wchar.h>
+
+struct lc_time_T {
+	const wchar_t *	mon[MONSPERYEAR];
+	const wchar_t *	month[MONSPERYEAR];
+	const wchar_t *	wday[DAYSPERWEEK];
+	const wchar_t *	weekday[DAYSPERWEEK];
+	const wchar_t *	X_fmt;
+	const wchar_t *	x_fmt;
+	const wchar_t *	c_fmt;
+	const wchar_t *	am;
+	const wchar_t *	pm;
+	const wchar_t *	date_fmt;
+};
+
+#define Locale	(&C_time_locale)
+
+static const struct lc_time_T	C_time_locale = {
+	{
+		L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
+		L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
+	}, {
+		L"January", L"February", L"March", L"April", L"May", L"June",
+		L"July", L"August", L"September", L"October", L"November", 
+		L"December"
+	}, {
+		L"Sun", L"Mon", L"Tue", L"Wed",
+		L"Thu", L"Fri", L"Sat"
+	}, {
+		L"Sunday", L"Monday", L"Tuesday", L"Wednesday",
+		L"Thursday", L"Friday", L"Saturday"
+	},
+
+	/* X_fmt */
+	L"%H:%M:%S",
+
+	/*
+	** x_fmt
+	** C99 requires this format.
+	** Using just numbers (as here) makes Quakers happier;
+	** it's also compatible with SVR4.
+	*/
+	L"%m/%d/%y",
+
+	/*
+	** c_fmt
+	** C99 requires this format.
+	** Previously this code used "%D %X", but we now conform to C99.
+	** Note that
+	**	"%a %b %d %H:%M:%S %Y"
+	** is used by Solaris 2.3.
+	*/
+	L"%a %b %e %T %Y",
+
+	/* am */
+	L"AM",
+
+	/* pm */
+	L"PM",
+
+	/* date_fmt */
+	L"%a %b %e %H:%M:%S %Z %Y"
+};
+
+#define UNKNOWN L"?"
+static wchar_t *	_add(const wchar_t *, wchar_t *, const wchar_t *);
+static wchar_t *	_sadd(const char *, wchar_t *, const wchar_t *);
+static wchar_t *	_conv(int, const wchar_t *, wchar_t *, const wchar_t *);
+static wchar_t *	_fmt(const wchar_t *, const struct tm *, wchar_t *, const wchar_t *,
+			int *);
+static wchar_t *	_yconv(int, int, int, int, wchar_t *, const wchar_t *);
+
+extern char *	tzname[];
+
+#define IN_NONE	0
+#define IN_SOME	1
+#define IN_THIS	2
+#define IN_ALL	3
+
+size_t
+wcsftime(wchar_t *__restrict s, size_t maxsize, 
+    const wchar_t *__restrict format, const struct tm *__restrict t)
+{
+	wchar_t *p;
+	int	warn;
+
+	tzset();
+	warn = IN_NONE;
+	p = _fmt(((format == NULL) ? L"%c" : format), t, s, s + maxsize, &warn);
+	if (p == s + maxsize) {
+		if (maxsize > 0)
+			s[maxsize - 1] = '\0';
+		return 0;
+	}
+	*p = L'\0';
+	return p - s;
+}
+
+static wchar_t *
+_fmt(const wchar_t *format, const struct tm *t, wchar_t *pt, 
+    const wchar_t *ptlim, int *warnp)
+{
+	for ( ; *format; ++format) {
+		if (*format != L'%') {
+			if (pt == ptlim)
+				break;
+			*pt++ = *format;
+			continue;
+		}
+label:
+		switch (*++format) {
+		case '\0':
+			--format;
+			break;
+		case 'A':
+			pt = _add((t->tm_wday < 0 ||
+				t->tm_wday >= DAYSPERWEEK) ?
+				UNKNOWN : Locale->weekday[t->tm_wday],
+				pt, ptlim);
+			continue;
+		case 'a':
+			pt = _add((t->tm_wday < 0 ||
+				t->tm_wday >= DAYSPERWEEK) ?
+				UNKNOWN : Locale->wday[t->tm_wday],
+				pt, ptlim);
+			continue;
+		case 'B':
+			pt = _add((t->tm_mon < 0 ||
+				t->tm_mon >= MONSPERYEAR) ?
+				UNKNOWN : Locale->month[t->tm_mon],
+				pt, ptlim);
+			continue;
+		case 'b':
+		case 'h':
+			pt = _add((t->tm_mon < 0 ||
+				t->tm_mon >= MONSPERYEAR) ?
+				UNKNOWN : Locale->mon[t->tm_mon],
+				pt, ptlim);
+			continue;
+		case 'C':
+			/*
+			** %C used to do a...
+			**	_fmt("%a %b %e %X %Y", t);
+			** ...whereas now POSIX 1003.2 calls for
+			** something completely different.
+			** (ado, 1993-05-24)
+			*/
+			pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
+				pt, ptlim);
+			continue;
+		case 'c':
+			{
+			int warn2 = IN_SOME;
+
+			pt = _fmt(Locale->c_fmt, t, pt, ptlim, &warn2);
+			if (warn2 == IN_ALL)
+				warn2 = IN_THIS;
+			if (warn2 > *warnp)
+				*warnp = warn2;
+			}
+			continue;
+		case 'D':
+			pt = _fmt(L"%m/%d/%y", t, pt, ptlim, warnp);
+			continue;
+		case 'd':
+			pt = _conv(t->tm_mday, L"%02d", pt, ptlim);
+			continue;
+		case 'E':
+		case 'O':
+			/*
+			** C99 locale modifiers.
+			** The sequences
+			**	%Ec %EC %Ex %EX %Ey %EY
+			**	%Od %oe %OH %OI %Om %OM
+			**	%OS %Ou %OU %OV %Ow %OW %Oy
+			** are supposed to provide alternate
+			** representations.
+			*/
+			goto label;
+		case 'e':
+			pt = _conv(t->tm_mday, L"%2d", pt, ptlim);
+			continue;
+		case 'F':
+			pt = _fmt(L"%Y-%m-%d", t, pt, ptlim, warnp);
+			continue;
+		case 'H':
+			pt = _conv(t->tm_hour, L"%02d", pt, ptlim);
+			continue;
+		case 'I':
+			pt = _conv((t->tm_hour % 12) ?
+				(t->tm_hour % 12) : 12,
+				L"%02d", pt, ptlim);
+			continue;
+		case 'j':
+			pt = _conv(t->tm_yday + 1, L"%03d", pt, ptlim);
+			continue;
+		case 'k':
+			/*
+			** This used to be...
+			**	_conv(t->tm_hour % 12 ?
+			**		t->tm_hour % 12 : 12, 2, ' ');
+			** ...and has been changed to the below to
+			** match SunOS 4.1.1 and Arnold Robbins'
+			** strftime version 3.0. That is, "%k" and
+			** "%l" have been swapped.
+			** (ado, 1993-05-24)
+			*/
+			pt = _conv(t->tm_hour, L"%2d", pt, ptlim);
+			continue;
+		case 'l':
+			/*
+			** This used to be...
+			**	_conv(t->tm_hour, 2, ' ');
+			** ...and has been changed to the below to
+			** match SunOS 4.1.1 and Arnold Robbin's
+			** strftime version 3.0. That is, "%k" and
+			** "%l" have been swapped.
+			** (ado, 1993-05-24)
+			*/
+			pt = _conv((t->tm_hour % 12) ?
+				(t->tm_hour % 12) : 12,
+				L"%2d", pt, ptlim);
+			continue;
+		case 'M':
+			pt = _conv(t->tm_min, L"%02d", pt, ptlim);
+			continue;
+		case 'm':
+			pt = _conv(t->tm_mon + 1, L"%02d", pt, ptlim);
+			continue;
+		case 'n':
+			pt = _add(L"\n", pt, ptlim);
+			continue;
+		case 'p':
+			pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
+				Locale->pm :
+				Locale->am,
+				pt, ptlim);
+			continue;
+		case 'R':
+			pt = _fmt(L"%H:%M", t, pt, ptlim, warnp);
+			continue;
+		case 'r':
+			pt = _fmt(L"%I:%M:%S %p", t, pt, ptlim, warnp);
+			continue;
+		case 'S':
+			pt = _conv(t->tm_sec, L"%02d", pt, ptlim);
+			continue;
+		case 's':
+			{
+				struct tm	tm;
+				wchar_t		buf[INT_STRLEN_MAXIMUM(
+							time_t) + 1];
+				time_t		mkt;
+
+				tm = *t;
+				mkt = mktime(&tm);
+				if (TYPE_SIGNED(time_t))
+					(void) swprintf(buf, 
+					    sizeof buf/sizeof buf[0],
+					    L"%ld", (long) mkt);
+				else	
+					(void) swprintf(buf, 
+					    sizeof buf/sizeof buf[0],
+					    L"%lu", (unsigned long) mkt);
+				pt = _add(buf, pt, ptlim);
+			}
+			continue;
+		case 'T':
+			pt = _fmt(L"%H:%M:%S", t, pt, ptlim, warnp);
+			continue;
+		case 't':
+			pt = _add(L"\t", pt, ptlim);
+			continue;
+		case 'U':
+			pt = _conv((t->tm_yday + DAYSPERWEEK -
+				t->tm_wday) / DAYSPERWEEK,
+				L"%02d", pt, ptlim);
+			continue;
+		case 'u':
+			/*
+			** From Arnold Robbins' strftime version 3.0:
+			** "ISO 8601: Weekday as a decimal number
+			** [1 (Monday) - 7]"
+			** (ado, 1993-05-24)
+			*/
+			pt = _conv((t->tm_wday == 0) ?
+				DAYSPERWEEK : t->tm_wday,
+				L"%d", pt, ptlim);
+			continue;
+		case 'V':	/* ISO 8601 week number */
+		case 'G':	/* ISO 8601 year (four digits) */
+		case 'g':	/* ISO 8601 year (two digits) */
+/*
+** From Arnold Robbins' strftime version 3.0: "the week number of the
+** year (the first Monday as the first day of week 1) as a decimal number
+** (01-53)."
+** (ado, 1993-05-24)
+**
+** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
+** "Week 01 of a year is per definition the first week which has the
+** Thursday in this year, which is equivalent to the week which contains
+** the fourth day of January. In other words, the first week of a new year
+** is the week which has the majority of its days in the new year. Week 01
+** might also contain days from the previous year and the week before week
+** 01 of a year is the last week (52 or 53) of the previous year even if
+** it contains days from the new year. A week starts with Monday (day 1)
+** and ends with Sunday (day 7). For example, the first week of the year
+** 1997 lasts from 1996-12-30 to 1997-01-05..."
+** (ado, 1996-01-02)
+*/
+			{
+			int	year;
+			int	base;
+			int	yday;
+			int	wday;
+			int	w;
+
+			year = t->tm_year;
+			base = TM_YEAR_BASE;
+			yday = t->tm_yday;
+			wday = t->tm_wday;
+			for ( ; ; ) {
+				int	len;
+				int	bot;
+				int	top;
+
+				len = isleap_sum(year, base) ?
+					DAYSPERLYEAR :
+					DAYSPERNYEAR;
+				/*
+				** What yday (-3 ... 3) does the ISO year 
+				** begin on?
+				*/
+				bot = ((yday + 11 - wday) % DAYSPERWEEK) - 3;
+				/*
+				** What yday does the NEXT ISO year begin on?
+				*/
+				top = bot - (len % DAYSPERWEEK);
+				if (top < -3)
+					top += DAYSPERWEEK;
+				top += len;
+				if (yday >= top) {
+					++base;
+					w = 1;
+					break;
+				}
+				if (yday >= bot) {
+					w = 1 + ((yday - bot) / DAYSPERWEEK);
+					break;
+				}
+				--base;
+				yday += isleap_sum(year, base) ?
+					DAYSPERLYEAR :
+					DAYSPERNYEAR;
+			}
+			if ((w == 52 && t->tm_mon == TM_JANUARY) ||
+				(w == 1 && t->tm_mon == TM_DECEMBER))
+					w = 53;
+			if (*format == 'V')
+				pt = _conv(w, L"%02d", pt, ptlim);
+			else if (*format == 'g') {
+				*warnp = IN_ALL;
+				pt = _yconv(year, base, 0, 1, pt, ptlim);
+			} else	
+				pt = _yconv(year, base, 1, 1, pt, ptlim);
+			}
+			continue;
+		case 'v':
+			/*
+			** From Arnold Robbins' strftime version 3.0:
+			** "date as dd-bbb-YYYY"
+			** (ado, 1993-05-24)
+			*/
+			pt = _fmt(L"%e-%b-%Y", t, pt, ptlim, warnp);
+			continue;
+		case 'W':
+			pt = _conv((t->tm_yday + DAYSPERWEEK -
+				(t->tm_wday ?
+				(t->tm_wday - 1) :
+				(DAYSPERWEEK - 1))) / DAYSPERWEEK,
+				L"%02d", pt, ptlim);
+			continue;
+		case 'w':
+			pt = _conv(t->tm_wday, L"%d", pt, ptlim);
+			continue;
+		case 'X':
+			pt = _fmt(Locale->X_fmt, t, pt, ptlim, warnp);
+			continue;
+		case 'x':
+			{
+			int	warn2 = IN_SOME;
+
+			pt = _fmt(Locale->x_fmt, t, pt, ptlim, &warn2);
+			if (warn2 == IN_ALL)
+				warn2 = IN_THIS;
+			if (warn2 > *warnp)
+				*warnp = warn2;
+			}
+			continue;
+		case 'y':
+			*warnp = IN_ALL;
+			pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1, pt, ptlim);
+			continue;
+		case 'Y':
+			pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1, pt, ptlim);
+			continue;
+		case 'Z':
+			if (t->tm_zone != NULL)
+				pt = _sadd(t->TM_ZONE, pt, ptlim);
+			else
+				if (t->tm_isdst >= 0)
+					pt = _sadd(tzname[t->tm_isdst != 0], 
+					    pt, ptlim);
+			/*
+			** C99 says that %Z must be replaced by the
+			** empty string if the time zone is not
+			** determinable.
+			*/
+			continue;
+		case 'z':
+			{
+			int		diff;
+			wchar_t const *	sign;
+
+			if (t->tm_isdst < 0)
+				continue;
+			diff = t->tm_gmtoff;
+			if (diff < 0) {
+				sign = L"-";
+				diff = -diff;
+			} else	
+				sign = L"+";
+			pt = _add(sign, pt, ptlim);
+			diff /= SECSPERMIN;
+			diff = (diff / MINSPERHOUR) * 100 +
+				(diff % MINSPERHOUR);
+			pt = _conv(diff, L"%04d", pt, ptlim);
+			}
+			continue;
+		case '+':
+			pt = _fmt(Locale->date_fmt, t, pt, ptlim, warnp);
+			continue;
+		case '%':
+		/*
+		** X311J/88-090 (4.12.3.5): if conversion wchar_t is
+		** undefined, behavior is undefined. Print out the
+		** character itself as printf(3) also does.
+		*/
+		default:
+			if (pt != ptlim)
+				*pt++ = *format;
+			break;
+		}
+	}
+	return pt;
+}
+
+static wchar_t *
+_conv(int n, const wchar_t *format, wchar_t *pt, const wchar_t *ptlim)
+{
+	wchar_t	buf[INT_STRLEN_MAXIMUM(int) + 1];
+
+	(void) swprintf(buf, sizeof buf/sizeof buf[0], format, n);
+	return _add(buf, pt, ptlim);
+}
+
+static wchar_t *
+_add(const wchar_t *str, wchar_t *pt, const wchar_t *ptlim)
+{
+	while (pt < ptlim && (*pt = *str++) != L'\0')
+		++pt;
+	return pt;
+}
+
+static wchar_t *
+_sadd(const char *str, wchar_t *pt, const wchar_t *ptlim)
+{
+	while (pt < ptlim && (*pt = btowc(*str++)) != L'\0')
+		++pt;
+	return pt;
+}
+/*
+** POSIX and the C Standard are unclear or inconsistent about
+** what %C and %y do if the year is negative or exceeds 9999.
+** Use the convention that %C concatenated with %y yields the
+** same output as %Y, and that %Y contains at least 4 bytes,
+** with more only if necessary.
+*/
+
+static wchar_t *
+_yconv(int a, int b, int convert_top, int convert_yy, wchar_t *pt, 
+    const wchar_t *ptlim)
+{
+	register int	lead;
+	register int	trail;
+
+#define DIVISOR	100
+	trail = a % DIVISOR + b % DIVISOR;
+	lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR;
+	trail %= DIVISOR;
+	if (trail < 0 && lead > 0) {
+		trail += DIVISOR;
+		--lead;
+	} else if (lead < 0 && trail > 0) {
+		trail -= DIVISOR;
+		++lead;
+	}
+	if (convert_top) {
+		if (lead == 0 && trail < 0)
+			pt = _add(L"-0", pt, ptlim);
+		else	pt = _conv(lead, L"%02d", pt, ptlim);
+	}
+	if (convert_yy)
+		pt = _conv(((trail < 0) ? -trail : trail), L"%02d", pt, ptlim);
+	return pt;
+}
+
diff --git a/libc/wchar/wcswidth.c b/libc/wchar/wcswidth.c
deleted file mode 100644
index b142074..0000000
--- a/libc/wchar/wcswidth.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <wchar.h>
-
-int
-wcswidth(const wchar_t *pwcs, size_t n)
-{
-	wchar_t wc;
-	int len, l;
-
-	len = 0;
-	while (n-- > 0 && (wc = *pwcs++) != L'\0') {
-		if ((l = wcwidth(wc)) < 0)
-			return (-1);
-		len += l;
-	}
-	return (len);
-}
-
diff --git a/libc/wchar/wcsxfrm.c b/libc/wchar/wcsxfrm.c
deleted file mode 100644
index 042ea56..0000000
--- a/libc/wchar/wcsxfrm.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-
- * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
- *		at Electronni Visti IA, Kiev, Ukraine.
- *			All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <wchar.h>
-
-/*
- * Placeholder wcsxfrm() implementation. See wcscoll.c for a description of
- * the logic used.
- */
-size_t
-wcsxfrm(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len)
-{
-    int prim, sec, l;
-    size_t slen;
-    char *mbsrc, *s, *ss;
-
-    if (*src == L'\0') {
-        if (len != 0)
-            *dest = L'\0';
-        return (0);
-    }
-
-    slen = wcslen(src);
-    if (len > 0) {
-        if (slen < len)
-            wcscpy(dest, src);
-        else {
-            wcsncpy(dest, src, len - 1);
-            dest[len - 1] = L'\0';
-        }
-    }
-    return (slen);
-}
diff --git a/libc/zoneinfo/tzdata b/libc/zoneinfo/tzdata
index 8468e83..8d574f5 100644
--- a/libc/zoneinfo/tzdata
+++ b/libc/zoneinfo/tzdata
Binary files differ
diff --git a/libdl/Android.mk b/libdl/Android.mk
index 3d60474..cb1cb7d 100644
--- a/libdl/Android.mk
+++ b/libdl/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_LDFLAGS_x86_64 := $(LOCAL_LDFLAGS_x86)
 
 LOCAL_SRC_FILES:= libdl.c
-LOCAL_CFLAGS := -Wall -Wextra -Werror
+LOCAL_CFLAGS := -Wall -Wextra -Wunused -Werror
 
 LOCAL_MODULE := libdl
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
diff --git a/libdl/libdl.c b/libdl/libdl.c
index 310db54..dca51b0 100644
--- a/libdl/libdl.c
+++ b/libdl/libdl.c
@@ -17,6 +17,7 @@
 #include <dlfcn.h>
 #include <link.h>
 #include <stdlib.h>
+#include <android/dlext.h>
 
 // These are stubs for functions that are actually defined
 // in the dynamic linker and hijacked at runtime.
@@ -27,11 +28,13 @@
 int dladdr(const void* addr __unused, Dl_info* info __unused) { return 0; }
 int dlclose(void* handle __unused) { return 0; }
 
-void android_get_LD_LIBRARY_PATH(char* buffer __unused, size_t buffer_size __unused) { }
-void android_update_LD_LIBRARY_PATH(const char* ld_library_path __unused) { }
-
 #if defined(__arm__)
 _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc __unused, int* pcount __unused) { return 0; }
 #endif
 
 int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data) __unused, void* data __unused) { return 0; }
+
+void android_get_LD_LIBRARY_PATH(char* buffer __unused, size_t buffer_size __unused) { }
+void android_update_LD_LIBRARY_PATH(const char* ld_library_path __unused) { }
+
+void* android_dlopen_ext(const char* filename __unused, int flag __unused, const android_dlextinfo* extinfo __unused) { return 0; }
diff --git a/libm/Android.mk b/libm/Android.mk
index ce98236..994caa0 100644
--- a/libm/Android.mk
+++ b/libm/Android.mk
@@ -1,13 +1,15 @@
+ifneq ($(TARGET_USE_PRIVATE_LIBM),true)
 LOCAL_PATH:= $(call my-dir)
 
-# TODO: these come from from upstream's libc, not libm!
+# TODO: this comes from from upstream's libc, not libm, but it's an
+# implementation detail that should have hidden visibility, so it needs
+# to be in whatever library the math code is in.
 libm_common_src_files := \
     digittoint.c  \
-    fpclassify.c \
-    isinf.c  \
 
 # TODO: this is not in the BSDs.
 libm_common_src_files += \
+    significandl.c \
     sincos.c \
 
 libm_common_src_files += \
@@ -64,6 +66,7 @@
     upstream-freebsd/lib/msun/src/e_sinhf.c \
     upstream-freebsd/lib/msun/src/e_sqrt.c \
     upstream-freebsd/lib/msun/src/e_sqrtf.c \
+    upstream-freebsd/lib/msun/src/imprecise.c \
     upstream-freebsd/lib/msun/src/k_cos.c \
     upstream-freebsd/lib/msun/src/k_cosf.c \
     upstream-freebsd/lib/msun/src/k_exp.c \
@@ -128,9 +131,6 @@
     upstream-freebsd/lib/msun/src/s_frexpf.c \
     upstream-freebsd/lib/msun/src/s_ilogb.c \
     upstream-freebsd/lib/msun/src/s_ilogbf.c \
-    upstream-freebsd/lib/msun/src/s_isfinite.c \
-    upstream-freebsd/lib/msun/src/s_isnan.c \
-    upstream-freebsd/lib/msun/src/s_isnormal.c \
     upstream-freebsd/lib/msun/src/s_llrint.c \
     upstream-freebsd/lib/msun/src/s_llrintf.c \
     upstream-freebsd/lib/msun/src/s_llround.c \
@@ -149,7 +149,6 @@
     upstream-freebsd/lib/msun/src/s_nearbyint.c \
     upstream-freebsd/lib/msun/src/s_nextafter.c \
     upstream-freebsd/lib/msun/src/s_nextafterf.c \
-    upstream-freebsd/lib/msun/src/s_nexttowardf.c \
     upstream-freebsd/lib/msun/src/s_remquo.c \
     upstream-freebsd/lib/msun/src/s_remquof.c \
     upstream-freebsd/lib/msun/src/s_rint.c \
@@ -159,7 +158,6 @@
     upstream-freebsd/lib/msun/src/s_scalbln.c \
     upstream-freebsd/lib/msun/src/s_scalbn.c \
     upstream-freebsd/lib/msun/src/s_scalbnf.c \
-    upstream-freebsd/lib/msun/src/s_signbit.c \
     upstream-freebsd/lib/msun/src/s_signgam.c \
     upstream-freebsd/lib/msun/src/s_significand.c \
     upstream-freebsd/lib/msun/src/s_significandf.c \
@@ -179,42 +177,57 @@
 
 libm_common_src_files += \
     fake_long_double.c \
-    upstream-freebsd/lib/msun/src/s_modfl.c \
+    signbit.c \
 
-# TODO: on Android, "long double" is "double".
-#    upstream-freebsd/lib/msun/src/e_acosl.c \
-#    upstream-freebsd/lib/msun/src/e_asinl.c \
-#    upstream-freebsd/lib/msun/src/e_atan2l.c \
-#    upstream-freebsd/lib/msun/src/e_fmodl.c \
-#    upstream-freebsd/lib/msun/src/e_hypotl.c \
-#    upstream-freebsd/lib/msun/src/e_remainderl.c \
-#    upstream-freebsd/lib/msun/src/e_sqrtl.c \
-#    upstream-freebsd/lib/msun/src/s_atanl.c \
-#    upstream-freebsd/lib/msun/src/s_cbrtl.c \
-#    upstream-freebsd/lib/msun/src/s_ceill.c \
-#    upstream-freebsd/lib/msun/src/s_copysignl.c \
-#    upstream-freebsd/lib/msun/src/s_cosl.c \
-#    upstream-freebsd/lib/msun/src/s_fabsl.c \
-#    upstream-freebsd/lib/msun/src/s_floorl.c \
-#    upstream-freebsd/lib/msun/src/s_fmal.c \
-#    upstream-freebsd/lib/msun/src/s_fmaxl.c \
-#    upstream-freebsd/lib/msun/src/s_fminl.c \
-#    upstream-freebsd/lib/msun/src/s_frexpl.c \
-#    upstream-freebsd/lib/msun/src/s_ilogbl.c \
-#    upstream-freebsd/lib/msun/src/s_llrintl.c \
-#    upstream-freebsd/lib/msun/src/s_llroundl.c \
-#    upstream-freebsd/lib/msun/src/s_logbl.c \
-#    upstream-freebsd/lib/msun/src/s_lrintl.c \
-#    upstream-freebsd/lib/msun/src/s_lroundl.c \
-#    upstream-freebsd/lib/msun/src/s_nextafterl.c \
-#    upstream-freebsd/lib/msun/src/s_nexttoward.c \
-#    upstream-freebsd/lib/msun/src/s_remquol.c \
-#    upstream-freebsd/lib/msun/src/s_rintl.c \
-#    upstream-freebsd/lib/msun/src/s_roundl.c \
-#    upstream-freebsd/lib/msun/src/s_scalbnl.c \
-#    upstream-freebsd/lib/msun/src/s_sinl.c \
-#    upstream-freebsd/lib/msun/src/s_tanl.c \
-#    upstream-freebsd/lib/msun/src/s_truncl.c \
+libm_ld_src_files = \
+    upstream-freebsd/lib/msun/src/e_acosl.c \
+    upstream-freebsd/lib/msun/src/e_acoshl.c \
+    upstream-freebsd/lib/msun/src/e_asinl.c \
+    upstream-freebsd/lib/msun/src/e_atan2l.c \
+    upstream-freebsd/lib/msun/src/e_atanhl.c \
+    upstream-freebsd/lib/msun/src/e_fmodl.c \
+    upstream-freebsd/lib/msun/src/e_hypotl.c \
+    upstream-freebsd/lib/msun/src/e_remainderl.c \
+    upstream-freebsd/lib/msun/src/e_sqrtl.c \
+    upstream-freebsd/lib/msun/src/s_asinhl.c \
+    upstream-freebsd/lib/msun/src/s_atanl.c \
+    upstream-freebsd/lib/msun/src/s_cbrtl.c \
+    upstream-freebsd/lib/msun/src/s_ceill.c \
+    upstream-freebsd/lib/msun/src/s_copysignl.c \
+    upstream-freebsd/lib/msun/src/s_cosl.c \
+    upstream-freebsd/lib/msun/src/s_fabsl.c \
+    upstream-freebsd/lib/msun/src/s_floorl.c \
+    upstream-freebsd/lib/msun/src/s_fmal.c \
+    upstream-freebsd/lib/msun/src/s_fmaxl.c \
+    upstream-freebsd/lib/msun/src/s_fminl.c \
+    upstream-freebsd/lib/msun/src/s_modfl.c \
+    upstream-freebsd/lib/msun/src/s_frexpl.c \
+    upstream-freebsd/lib/msun/src/s_ilogbl.c \
+    upstream-freebsd/lib/msun/src/s_llrintl.c \
+    upstream-freebsd/lib/msun/src/s_llroundl.c \
+    upstream-freebsd/lib/msun/src/s_logbl.c \
+    upstream-freebsd/lib/msun/src/s_lrintl.c \
+    upstream-freebsd/lib/msun/src/s_lroundl.c \
+    upstream-freebsd/lib/msun/src/s_nextafterl.c \
+    upstream-freebsd/lib/msun/src/s_nexttoward.c \
+    upstream-freebsd/lib/msun/src/s_nexttowardf.c \
+    upstream-freebsd/lib/msun/src/s_remquol.c \
+    upstream-freebsd/lib/msun/src/s_rintl.c \
+    upstream-freebsd/lib/msun/src/s_roundl.c \
+    upstream-freebsd/lib/msun/src/s_scalbnl.c \
+    upstream-freebsd/lib/msun/src/s_sinl.c \
+    upstream-freebsd/lib/msun/src/s_tanl.c \
+    upstream-freebsd/lib/msun/src/s_truncl.c \
+
+libm_ld_src_files += \
+    upstream-freebsd/lib/msun/ld128/invtrig.c \
+    upstream-freebsd/lib/msun/ld128/k_cosl.c \
+    upstream-freebsd/lib/msun/ld128/k_sinl.c \
+    upstream-freebsd/lib/msun/ld128/k_tanl.c \
+    upstream-freebsd/lib/msun/ld128/s_exp2l.c \
+    upstream-freebsd/lib/msun/ld128/s_expl.c \
+    upstream-freebsd/lib/msun/ld128/s_logl.c \
+    upstream-freebsd/lib/msun/ld128/s_nanl.c \
 
 # TODO: re-enable i387/e_sqrtf.S for x86, and maybe others.
 
@@ -222,24 +235,21 @@
     -DFLT_EVAL_METHOD=0 \
     -std=c99 \
     -include $(LOCAL_PATH)/freebsd-compat.h \
+    -Wno-missing-braces \
+    -Wno-parentheses \
+    -Wno-sign-compare \
+    -Wno-uninitialized \
+    -Wno-unknown-pragmas \
+    -fvisibility=hidden \
+
+# Workaround the GCC "(long)fn -> lfn" optimization bug which will result in
+# self recursions for lrint, lrintf, and lrintl.
+# BUG: 14225968
+libm_common_cflags += -fno-builtin-rint -fno-builtin-rintf -fno-builtin-rintl
 
 libm_common_includes := $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/
 
-libm_arm_includes := $(LOCAL_PATH)/arm
-libm_arm_src_files := arm/fenv.c
-
-libm_arm64_includes := $(LOCAL_PATH)/arm64
-libm_arm64_src_files := arm64/fenv.c
-
-libm_x86_includes := $(LOCAL_PATH)/i386 $(LOCAL_PATH)/i387
-libm_x86_src_files := i387/fenv.c
-
-libm_x86_64_includes := $(LOCAL_PATH)/amd64
-libm_x86_64_src_files := amd64/fenv.c
-
-libm_mips_cflags := -fno-builtin-rintf -fno-builtin-rint
-libm_mips_includes := $(LOCAL_PATH)/mips
-libm_mips_src_files := mips/fenv.c
+libm_ld_includes := $(LOCAL_PATH)/upstream-freebsd/lib/msun/ld128/
 
 #
 # libm.a for target.
@@ -248,10 +258,29 @@
 LOCAL_MODULE:= libm
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_ARM_MODE := arm
-LOCAL_CFLAGS := $(libm_common_cflags) $(libm_$(TARGET_ARCH)_cflags)
-LOCAL_C_INCLUDES += $(libm_common_includes) $(libm_$(TARGET_ARCH)_includes)
-LOCAL_SRC_FILES := $(libm_common_src_files) $(libm_$(TARGET_ARCH)_src_files)
+LOCAL_CFLAGS := $(libm_common_cflags)
+LOCAL_C_INCLUDES += $(libm_common_includes)
+LOCAL_SRC_FILES := $(libm_common_src_files)
 LOCAL_SYSTEM_SHARED_LIBRARIES := libc
+
+# arch-specific settings
+LOCAL_C_INCLUDES_arm := $(LOCAL_PATH)/arm
+LOCAL_SRC_FILES_arm := arm/fenv.c
+
+LOCAL_C_INCLUDES_arm64 := $(libm_ld_includes)
+LOCAL_SRC_FILES_arm64 := arm64/fenv.c $(libm_ld_src_files)
+
+LOCAL_C_INCLUDES_x86 := $(LOCAL_PATH)/i387
+LOCAL_SRC_FILES_x86 := i387/fenv.c
+
+LOCAL_C_INCLUDES_x86_64 := $(libm_ld_includes)
+LOCAL_SRC_FILES_x86_64 := amd64/fenv.c $(libm_ld_src_files)
+
+LOCAL_SRC_FILES_mips := mips/fenv.c
+
+LOCAL_C_INCLUDES_mips64 := $(libm_ld_includes)
+LOCAL_SRC_FILES_mips64 := mips/fenv.c $(libm_ld_src_files)
+
 include $(BUILD_STATIC_LIBRARY)
 
 #
@@ -262,4 +291,12 @@
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_SYSTEM_SHARED_LIBRARIES := libc
 LOCAL_WHOLE_STATIC_LIBRARIES := libm
+
+# We'd really like to do this for all architectures, but since this wasn't done
+# before, these symbols must continue to be exported on LP32 for binary
+# compatibility.
+LOCAL_LDFLAGS_arm64 := -Wl,--exclude-libs,libgcc.a
+LOCAL_LDFLAGS_mips64 := -Wl,--exclude-libs,libgcc.a
+LOCAL_LDFLAGS_x86_64 := -Wl,--exclude-libs,libgcc.a
 include $(BUILD_SHARED_LIBRARY)
+endif
diff --git a/libm/NOTICE b/libm/NOTICE
index 709563c..5be60db 100644
--- a/libm/NOTICE
+++ b/libm/NOTICE
@@ -46,6 +46,31 @@
 
 ====================================================
 Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+
+Developed at SunSoft, a Sun Microsystems, Inc. business.
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+
+-------------------------------------------------------------------
+
+====================================================
+Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+
+Developed at SunSoft, a Sun Microsystems, Inc. business.
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+====================================================
+
+Optimized by Bruce D. Evans.
+
+-------------------------------------------------------------------
+
+====================================================
+Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 Copyright (c) 2009-2011, Bruce D. Evans, Steven G. Kargl, David Schultz.
 
 Developed at SunPro, a Sun Microsystems, Inc. business.
@@ -78,6 +103,16 @@
 
 -------------------------------------------------------------------
 
+====================================================
+Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
+Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+
+-------------------------------------------------------------------
+
 Copyright (C) 2010 The Android Open Source Project
 All rights reserved.
 
@@ -120,6 +155,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (C) 2014 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 1985, 1993
    The Regents of the University of California.  All rights reserved.
 
@@ -277,32 +338,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 2003 Dag-Erling Smørgrav
 All rights reserved.
 
@@ -384,33 +419,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
-Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
-
--------------------------------------------------------------------
-
 Copyright (c) 2003, Steven G. Kargl
 All rights reserved.
 
@@ -810,6 +818,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2007-2013 Bruce D. Evans
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice unmodified, this list of conditions, and the following
+   disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
 All rights reserved.
 
@@ -836,6 +870,60 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2009-2013 Steven G. Kargl
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice unmodified, this list of conditions, and the following
+   disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Optimized by Bruce D. Evans.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2010 The NetBSD Foundation, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2011 David Schultz
 All rights reserved.
 
@@ -888,6 +976,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2013 David Chisnall
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
 From: @(#)s_ilogb.c 5.1 93/09/24
 ====================================================
 Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
diff --git a/libm/amd64/_fpmath.h b/libm/amd64/_fpmath.h
deleted file mode 100755
index c2a7384..0000000
--- a/libm/amd64/_fpmath.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-union IEEEl2bits {
-	long double	e;
-	struct {
-		unsigned int	manl	:32;
-		unsigned int	manh	:32;
-		unsigned int	exp	:15;
-		unsigned int	sign	:1;
-		unsigned int	junkl	:16;
-		unsigned int	junkh	:32;
-	} bits;
-	struct {
-		unsigned long	man	:64;
-		unsigned int	expsign	:16;
-		unsigned long	junk	:48;
-	} xbits;
-};
-
-#define	LDBL_NBIT	0x80000000
-#define	mask_nbit_l(u)	((u).bits.manh &= ~LDBL_NBIT)
-
-#define	LDBL_MANH_SIZE	32
-#define	LDBL_MANL_SIZE	32
-
-#define	LDBL_TO_ARRAY32(u, a) do {			\
-	(a)[0] = (uint32_t)(u).bits.manl;		\
-	(a)[1] = (uint32_t)(u).bits.manh;		\
-} while (0)
diff --git a/libm/amd64/fenv.c b/libm/amd64/fenv.c
index 7ad3be7..4b24ff9 100755
--- a/libm/amd64/fenv.c
+++ b/libm/amd64/fenv.c
@@ -1,5 +1,5 @@
-/*	$OpenBSD: fenv.c,v 1.3 2012/12/05 23:20:02 deraadt Exp $	*/
-/*	$NetBSD: fenv.c,v 1.1 2010/07/31 21:47:53 joerg Exp $	*/
+/*  $OpenBSD: fenv.c,v 1.3 2012/12/05 23:20:02 deraadt Exp $  */
+/*  $NetBSD: fenv.c,v 1.1 2010/07/31 21:47:53 joerg Exp $ */
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
@@ -30,6 +30,15 @@
 #include <fenv.h>
 #include <machine/fpu.h>
 
+#define SSE_MASK_SHIFT 7
+
+/*
+ * The following symbol is simply the bitwise-inclusive OR of all floating-point
+ * rounding direction constants defined above.
+ */
+#define X87_ROUND_MASK  (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
+#define SSE_ROUND_SHIFT 3
+
 /*
  * The following constant represents the default floating-point environment
  * (that is, the one installed at program startup) and has type pointer to
@@ -42,19 +51,19 @@
  * x87 fpu registers are 16bit wide. The upper bits, 31-16, are marked as
  * RESERVED.
  */
-fenv_t __fe_dfl_env = {
-	{
-		0xffff0000 | __INITIAL_NPXCW__,	/* Control word register */
-		0xffff0000,			/* Status word register */
-		0xffffffff,			/* Tag word register */
-		{
-			0x00000000,
-			0x00000000,
-			0x00000000,
-			0xffff0000
-		}
-	},
-	__INITIAL_MXCSR__			/* MXCSR register */
+const fenv_t __fe_dfl_env = {
+  {
+    0xffff0000 | __INITIAL_NPXCW__, /* Control word register */
+    0xffff0000,                     /* Status word register */
+    0xffffffff,                     /* Tag word register */
+    {
+      0x00000000,
+      0x00000000,
+      0x00000000,
+      0xffff0000
+    }
+  },
+  __INITIAL_MXCSR__                 /* MXCSR register */
 };
 
 
@@ -65,26 +74,26 @@
 int
 feclearexcept(int excepts)
 {
-	fenv_t fenv;
-	unsigned int mxcsr;
+  fenv_t fenv;
+  unsigned int mxcsr;
 
-	excepts &= FE_ALL_EXCEPT;
+  excepts &= FE_ALL_EXCEPT;
 
-	/* Store the current x87 floating-point environment */
-	__asm__ __volatile__ ("fnstenv %0" : "=m" (fenv));
+  /* Store the current x87 floating-point environment */
+  __asm__ __volatile__ ("fnstenv %0" : "=m" (fenv));
 
-	/* Clear the requested floating-point exceptions */
-	fenv.__x87.__status &= ~excepts;
+  /* Clear the requested floating-point exceptions */
+  fenv.__x87.__status &= ~excepts;
 
-	/* Load the x87 floating-point environent */
-	__asm__ __volatile__ ("fldenv %0" : : "m" (fenv));
+  /* Load the x87 floating-point environent */
+  __asm__ __volatile__ ("fldenv %0" : : "m" (fenv));
 
-	/* Same for SSE environment */
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
-	mxcsr &= ~excepts;
-	__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
+  /* Same for SSE environment */
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
+  mxcsr &= ~excepts;
+  __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -95,21 +104,21 @@
 int
 fegetexceptflag(fexcept_t *flagp, int excepts)
 {
-	unsigned short status;
-	unsigned int mxcsr;
+  unsigned short status;
+  unsigned int mxcsr;
 
-	excepts &= FE_ALL_EXCEPT;
+  excepts &= FE_ALL_EXCEPT;
 
-	/* Store the current x87 status register */
-	__asm__ __volatile__ ("fnstsw %0" : "=am" (status));
+  /* Store the current x87 status register */
+  __asm__ __volatile__ ("fnstsw %0" : "=am" (status));
 
-	/* Store the MXCSR register */
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
+  /* Store the MXCSR register */
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
 
-	/* Store the results in flagp */
-	*flagp = (status | mxcsr) & excepts;
+  /* Store the results in flagp */
+  *flagp = (status | mxcsr) & excepts;
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -125,12 +134,12 @@
 int
 feraiseexcept(int excepts)
 {
-	excepts &= FE_ALL_EXCEPT;
+  excepts &= FE_ALL_EXCEPT;
 
-	fesetexceptflag((fexcept_t *)&excepts, excepts);
-	__asm__ __volatile__ ("fwait");
+  fesetexceptflag((fexcept_t *)&excepts, excepts);
+  __asm__ __volatile__ ("fwait");
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -141,28 +150,28 @@
 int
 fesetexceptflag(const fexcept_t *flagp, int excepts)
 {
-	fenv_t fenv;
-	unsigned int mxcsr;
+  fenv_t fenv;
+  unsigned int mxcsr;
 
-	excepts &= FE_ALL_EXCEPT;
+  excepts &= FE_ALL_EXCEPT;
 
-	/* Store the current x87 floating-point environment */
-	__asm__ __volatile__ ("fnstenv %0" : "=m" (fenv));
+  /* Store the current x87 floating-point environment */
+  __asm__ __volatile__ ("fnstenv %0" : "=m" (fenv));
 
-	/* Set the requested status flags */
-	fenv.__x87.__status &= ~excepts;
-	fenv.__x87.__status |= *flagp & excepts;
+  /* Set the requested status flags */
+  fenv.__x87.__status &= ~excepts;
+  fenv.__x87.__status |= *flagp & excepts;
 
-	/* Load the x87 floating-point environent */
-	__asm__ __volatile__ ("fldenv %0" : : "m" (fenv));
+  /* Load the x87 floating-point environent */
+  __asm__ __volatile__ ("fldenv %0" : : "m" (fenv));
 
-	/* Same for SSE environment */
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
-	mxcsr &= ~excepts;
-	mxcsr |= *flagp & excepts;
-	__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
+  /* Same for SSE environment */
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
+  mxcsr &= ~excepts;
+  mxcsr |= *flagp & excepts;
+  __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -173,18 +182,18 @@
 int
 fetestexcept(int excepts)
 {
-	unsigned short status;
-	unsigned int mxcsr;
+  unsigned short status;
+  unsigned int mxcsr;
 
-	excepts &= FE_ALL_EXCEPT;
+  excepts &= FE_ALL_EXCEPT;
 
-	/* Store the current x87 status register */
-	__asm__ __volatile__ ("fnstsw %0" : "=am" (status));
+  /* Store the current x87 status register */
+  __asm__ __volatile__ ("fnstsw %0" : "=am" (status));
 
-	/* Store the MXCSR register state */
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
+  /* Store the MXCSR register state */
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
 
-	return ((status | mxcsr) & excepts);
+  return ((status | mxcsr) & excepts);
 }
 
 /*
@@ -193,17 +202,17 @@
 int
 fegetround(void)
 {
-	unsigned short control;
+  unsigned short control;
 
-	/*
-	 * We assume that the x87 and the SSE unit agree on the
-	 * rounding mode.  Reading the control word on the x87 turns
-	 * out to be about 5 times faster than reading it on the SSE
-	 * unit on an Opteron 244.
-	 */
-	__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
+  /*
+   * We assume that the x87 and the SSE unit agree on the
+   * rounding mode.  Reading the control word on the x87 turns
+   * out to be about 5 times faster than reading it on the SSE
+   * unit on an Opteron 244.
+   */
+  __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
 
-	return (control & _X87_ROUND_MASK);
+  return (control & X87_ROUND_MASK);
 }
 
 /*
@@ -214,30 +223,30 @@
 int
 fesetround(int round)
 {
-	unsigned short control;
-	unsigned int mxcsr;
+  unsigned short control;
+  unsigned int mxcsr;
 
-	/* Check whether requested rounding direction is supported */
-	if (round & ~_X87_ROUND_MASK)
-		return (-1);
+  /* Check whether requested rounding direction is supported */
+  if (round & ~X87_ROUND_MASK)
+    return (-1);
 
-	/* Store the current x87 control word register */
-	__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
+  /* Store the current x87 control word register */
+  __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
 
-	/* Set the rounding direction */
-	control &= ~_X87_ROUND_MASK;
-	control |= round;
+  /* Set the rounding direction */
+  control &= ~X87_ROUND_MASK;
+  control |= round;
 
-	/* Load the x87 control word register */
-	__asm__ __volatile__ ("fldcw %0" : : "m" (control));
+  /* Load the x87 control word register */
+  __asm__ __volatile__ ("fldcw %0" : : "m" (control));
 
-	/* Same for the SSE environment */
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
-	mxcsr &= ~(_X87_ROUND_MASK << _SSE_ROUND_SHIFT);
-	mxcsr |= round << _SSE_ROUND_SHIFT;
-	__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
+  /* Same for the SSE environment */
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
+  mxcsr &= ~(X87_ROUND_MASK << SSE_ROUND_SHIFT);
+  mxcsr |= round << SSE_ROUND_SHIFT;
+  __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -247,23 +256,23 @@
 int
 fegetenv(fenv_t *envp)
 {
-	/* Store the current x87 floating-point environment */
-	__asm__ __volatile__ ("fnstenv %0" : "=m" (*envp));
+  /* Store the current x87 floating-point environment */
+  __asm__ __volatile__ ("fnstenv %0" : "=m" (*envp));
 
-	/* Store the MXCSR register state */
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (envp->__mxcsr));
+  /* Store the MXCSR register state */
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (envp->__mxcsr));
 
-	/*
-	 * When an FNSTENV instruction is executed, all pending exceptions are
-	 * essentially lost (either the x87 FPU status register is cleared or
-	 * all exceptions are masked).
-	 *
-	 * 8.6 X87 FPU EXCEPTION SYNCHRONIZATION -
-	 * Intel(R) 64 and IA-32 Architectures Softare Developer's Manual - Vol1
-	 */
-	__asm__ __volatile__ ("fldcw %0" : : "m" (envp->__x87.__control));
+  /*
+   * When an FNSTENV instruction is executed, all pending exceptions are
+   * essentially lost (either the x87 FPU status register is cleared or
+   * all exceptions are masked).
+   *
+   * 8.6 X87 FPU EXCEPTION SYNCHRONIZATION -
+   * Intel(R) 64 and IA-32 Architectures Softare Developer's Manual - Vol1
+   */
+  __asm__ __volatile__ ("fldcw %0" : : "m" (envp->__x87.__control));
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -275,28 +284,28 @@
 int
 feholdexcept(fenv_t *envp)
 {
-	unsigned int mxcsr;
+  unsigned int mxcsr;
 
-	/* Store the current x87 floating-point environment */
-	__asm__ __volatile__ ("fnstenv %0" : "=m" (*envp));
+  /* Store the current x87 floating-point environment */
+  __asm__ __volatile__ ("fnstenv %0" : "=m" (*envp));
 
-	/* Clear all exception flags in FPU */
-	__asm__ __volatile__ ("fnclex");
+  /* Clear all exception flags in FPU */
+  __asm__ __volatile__ ("fnclex");
 
-	/* Store the MXCSR register state */
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (envp->__mxcsr));
+  /* Store the MXCSR register state */
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (envp->__mxcsr));
 
-	/* Clear exception flags in MXCSR */
-	mxcsr = envp->__mxcsr;
-	mxcsr &= ~FE_ALL_EXCEPT;
+  /* Clear exception flags in MXCSR */
+  mxcsr = envp->__mxcsr;
+  mxcsr &= ~FE_ALL_EXCEPT;
 
-	/* Mask all exceptions */
-	mxcsr |= FE_ALL_EXCEPT << _SSE_MASK_SHIFT;
+  /* Mask all exceptions */
+  mxcsr |= FE_ALL_EXCEPT << SSE_MASK_SHIFT;
 
-	/* Store the MXCSR register */
-	__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
+  /* Store the MXCSR register */
+  __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -310,13 +319,13 @@
 int
 fesetenv(const fenv_t *envp)
 {
-	/* Load the x87 floating-point environent */
-	__asm__ __volatile__ ("fldenv %0" : : "m" (*envp));
+  /* Load the x87 floating-point environent */
+  __asm__ __volatile__ ("fldenv %0" : : "m" (*envp));
 
-	/* Store the MXCSR register */
-	__asm__ __volatile__ ("ldmxcsr %0" : : "m" (envp->__mxcsr));
+  /* Store the MXCSR register */
+  __asm__ __volatile__ ("ldmxcsr %0" : : "m" (envp->__mxcsr));
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -330,22 +339,22 @@
 int
 feupdateenv(const fenv_t *envp)
 {
-	unsigned short status;
-	unsigned int mxcsr;
+  unsigned short status;
+  unsigned int mxcsr;
 
-	/* Store the x87 status register */
-	__asm__ __volatile__ ("fnstsw %0" : "=am" (status));
+  /* Store the x87 status register */
+  __asm__ __volatile__ ("fnstsw %0" : "=am" (status));
 
-	/* Store the MXCSR register */
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
+  /* Store the MXCSR register */
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
 
-	/* Install new floating-point environment */
-	fesetenv(envp);
+  /* Install new floating-point environment */
+  fesetenv(envp);
 
-	/* Raise any previously accumulated exceptions */
-	feraiseexcept(status | mxcsr);
+  /* Raise any previously accumulated exceptions */
+  feraiseexcept(status | mxcsr);
 
-	return (0);
+  return (0);
 }
 
 /*
@@ -354,55 +363,55 @@
 int
 feenableexcept(int mask)
 {
-	unsigned int mxcsr, omask;
-	unsigned short control;
+  unsigned int mxcsr, omask;
+  unsigned short control;
 
-	mask &= FE_ALL_EXCEPT;
+  mask &= FE_ALL_EXCEPT;
 
-	__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
+  __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
 
-	omask = ~(control | (mxcsr >> _SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
-	control &= ~mask;
-	__asm__ __volatile__ ("fldcw %0" : : "m" (control));
+  omask = ~(control | (mxcsr >> SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
+  control &= ~mask;
+  __asm__ __volatile__ ("fldcw %0" : : "m" (control));
 
-	mxcsr &= ~(mask << _SSE_MASK_SHIFT);
-	__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
+  mxcsr &= ~(mask << SSE_MASK_SHIFT);
+  __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
-	return (omask);
+  return (omask);
 }
 
 int
 fedisableexcept(int mask)
 {
-	unsigned int mxcsr, omask;
-	unsigned short control;
+  unsigned int mxcsr, omask;
+  unsigned short control;
 
-	mask &= FE_ALL_EXCEPT;
+  mask &= FE_ALL_EXCEPT;
 
-	__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
-	__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
+  __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
+  __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
 
-	omask = ~(control | (mxcsr >> _SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
-	control |= mask;
-	__asm__ __volatile__ ("fldcw %0" : : "m" (control));
+  omask = ~(control | (mxcsr >> SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
+  control |= mask;
+  __asm__ __volatile__ ("fldcw %0" : : "m" (control));
 
-	mxcsr |= mask << _SSE_MASK_SHIFT;
-	__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
+  mxcsr |= mask << SSE_MASK_SHIFT;
+  __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
 
-	return (omask);
+  return (omask);
 }
 
 int
 fegetexcept(void)
 {
-	unsigned short control;
+  unsigned short control;
 
-	/*
-	 * We assume that the masks for the x87 and the SSE unit are
-	 * the same.
-	 */
-	__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
+  /*
+   * We assume that the masks for the x87 and the SSE unit are
+   * the same.
+   */
+  __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
 
-	return (~control & FE_ALL_EXCEPT);
+  return (~control & FE_ALL_EXCEPT);
 }
diff --git a/libm/arm/_fpmath.h b/libm/arm/_fpmath.h
deleted file mode 100644
index 4c18945..0000000
--- a/libm/arm/_fpmath.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#if defined(__VFP_FP__)
-#define	_IEEE_WORD_ORDER	_BYTE_ORDER
-#else
-#define	_IEEE_WORD_ORDER	_BIG_ENDIAN
-#endif
-
-union IEEEl2bits {
-	long double	e;
-	struct {
-#if _BYTE_ORDER == _LITTLE_ENDIAN
-#if _IEEE_WORD_ORDER == _LITTLE_ENDIAN
-		unsigned int	manl	:32;
-#endif
-		unsigned int	manh	:20;
-		unsigned int	exp	:11;
-		unsigned int	sign	:1;
-#if _IEEE_WORD_ORDER == _BIG_ENDIAN
-		unsigned int	manl	:32;
-#endif
-#else	/* _BYTE_ORDER == _LITTLE_ENDIAN */
-		unsigned int		sign	:1;
-		unsigned int		exp	:11;
-		unsigned int		manh	:20;
-		unsigned int		manl	:32;
-#endif
-	} bits;
-};
-
-#define	LDBL_NBIT	0
-#define	LDBL_IMPLICIT_NBIT
-#define	mask_nbit_l(u)	((void)0)
-
-#define	LDBL_MANH_SIZE	20
-#define	LDBL_MANL_SIZE	32
-
-#define	LDBL_TO_ARRAY32(u, a) do {			\
-	(a)[0] = (uint32_t)(u).bits.manl;		\
-	(a)[1] = (uint32_t)(u).bits.manh;		\
-} while(0)
diff --git a/libm/arm/fenv.c b/libm/arm/fenv.c
index 469f198..2124730 100644
--- a/libm/arm/fenv.c
+++ b/libm/arm/fenv.c
@@ -28,8 +28,112 @@
 
 #include <fenv.h>
 
-/*
- * Hopefully the system ID byte is immutable, so it's valid to use
- * this as a default environment.
- */
+#define FPSCR_ENABLE_SHIFT 8
+#define FPSCR_ENABLE_MASK  (FE_ALL_EXCEPT << FPSCR_ENABLE_SHIFT)
+
+#define FPSCR_RMODE_SHIFT 22
+
 const fenv_t __fe_dfl_env = 0;
+
+int fegetenv(fenv_t* __envp) {
+  fenv_t _fpscr;
+  __asm__ __volatile__("vmrs %0,fpscr" : "=r" (_fpscr));
+  *__envp = _fpscr;
+  return 0;
+}
+
+int fesetenv(const fenv_t* __envp) {
+  fenv_t _fpscr = *__envp;
+  __asm__ __volatile__("vmsr fpscr,%0" : :"ri" (_fpscr));
+  return 0;
+}
+
+int feclearexcept(int __excepts) {
+  fexcept_t __fpscr;
+  fegetenv(&__fpscr);
+  __fpscr &= ~__excepts;
+  fesetenv(&__fpscr);
+  return 0;
+}
+
+int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
+  fexcept_t __fpscr;
+  fegetenv(&__fpscr);
+  *__flagp = __fpscr & __excepts;
+  return 0;
+}
+
+int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
+  fexcept_t __fpscr;
+  fegetenv(&__fpscr);
+  __fpscr &= ~__excepts;
+  __fpscr |= *__flagp & __excepts;
+  fesetenv(&__fpscr);
+  return 0;
+}
+
+int feraiseexcept(int __excepts) {
+  fexcept_t __ex = __excepts;
+  fesetexceptflag(&__ex, __excepts);
+  return 0;
+}
+
+int fetestexcept(int __excepts) {
+  fexcept_t __fpscr;
+  fegetenv(&__fpscr);
+  return (__fpscr & __excepts);
+}
+
+int fegetround(void) {
+  fenv_t _fpscr;
+  fegetenv(&_fpscr);
+  return ((_fpscr >> FPSCR_RMODE_SHIFT) & 0x3);
+}
+
+int fesetround(int __round) {
+  fenv_t _fpscr;
+  fegetenv(&_fpscr);
+  _fpscr &= ~(0x3 << FPSCR_RMODE_SHIFT);
+  _fpscr |= (__round << FPSCR_RMODE_SHIFT);
+  fesetenv(&_fpscr);
+  return 0;
+}
+
+int feholdexcept(fenv_t* __envp) {
+  fenv_t __env;
+  fegetenv(&__env);
+  *__envp = __env;
+  __env &= ~(FE_ALL_EXCEPT | FPSCR_ENABLE_MASK);
+  fesetenv(&__env);
+  return 0;
+}
+
+int feupdateenv(const fenv_t* __envp) {
+  fexcept_t __fpscr;
+  fegetenv(&__fpscr);
+  fesetenv(__envp);
+  feraiseexcept(__fpscr & FE_ALL_EXCEPT);
+  return 0;
+}
+
+int feenableexcept(int __mask) {
+  fenv_t __old_fpscr, __new_fpscr;
+  fegetenv(&__old_fpscr);
+  __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << FPSCR_ENABLE_SHIFT;
+  fesetenv(&__new_fpscr);
+  return ((__old_fpscr >> FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
+}
+
+int fedisableexcept(int __mask) {
+  fenv_t __old_fpscr, __new_fpscr;
+  fegetenv(&__old_fpscr);
+  __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << FPSCR_ENABLE_SHIFT);
+  fesetenv(&__new_fpscr);
+  return ((__old_fpscr >> FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
+}
+
+int fegetexcept(void) {
+  fenv_t __fpscr;
+  fegetenv(&__fpscr);
+  return ((__fpscr & FPSCR_ENABLE_MASK) >> FPSCR_ENABLE_SHIFT);
+}
diff --git a/libm/arm64/_fpmath.h b/libm/arm64/_fpmath.h
deleted file mode 100644
index a24632a..0000000
--- a/libm/arm64/_fpmath.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/libc/aarch64/_fpmath.h $
- */
-
-union IEEEl2bits {
-	long double	e;
-	struct {
-#ifndef __AARCH64EB__
-		unsigned int	manl	:32;
-		unsigned int	manh	:20;
-		unsigned int	exp	:11;
-		unsigned int	sign	:1;
-#else
-		unsigned int		sign	:1;
-		unsigned int		exp	:11;
-		unsigned int		manh	:20;
-		unsigned int		manl	:32;
-#endif
-	} bits;
-};
-
-#define	LDBL_NBIT	0
-#define	LDBL_IMPLICIT_NBIT
-#define	mask_nbit_l(u)	((void)0)
-
-#define	LDBL_MANH_SIZE	32
-#define	LDBL_MANL_SIZE	32
-
-#define	LDBL_TO_ARRAY32(u, a) do {			\
-	(a)[0] = (uint32_t)(u).bits.manl;		\
-	(a)[1] = (uint32_t)(u).bits.manh;		\
-} while(0)
diff --git a/libm/arm64/fenv.c b/libm/arm64/fenv.c
index 27c405f..ce560a7 100644
--- a/libm/arm64/fenv.c
+++ b/libm/arm64/fenv.c
@@ -28,8 +28,168 @@
 
 #include <fenv.h>
 
-/*
- * Hopefully the system ID byte is immutable, so it's valid to use
- * this as a default environment.
- */
-const fenv_t __fe_dfl_env = 0;
+#define FPCR_EXCEPT_SHIFT 8
+#define FPCR_EXCEPT_MASK  (FE_ALL_EXCEPT << FPCR_EXCEPT_SHIFT)
+
+#define FPCR_RMODE_SHIFT 22
+
+const fenv_t __fe_dfl_env = { 0 /* control */, 0 /* status */};
+
+typedef __uint32_t fpu_control_t;   // FPCR, Floating-point Control Register.
+typedef __uint32_t fpu_status_t;    // FPSR, Floating-point Status Register.
+
+#define __get_fpcr(__fpcr) __asm__ __volatile__("mrs %0,fpcr" : "=r" (__fpcr))
+#define __get_fpsr(__fpsr) __asm__ __volatile__("mrs %0,fpsr" : "=r" (__fpsr))
+#define __set_fpcr(__fpcr) __asm__ __volatile__("msr fpcr,%0" : :"ri" (__fpcr))
+#define __set_fpsr(__fpsr) __asm__ __volatile__("msr fpsr,%0" : :"ri" (__fpsr))
+
+int fegetenv(fenv_t* envp) {
+  __get_fpcr(envp->__control);
+  __get_fpsr(envp->__status);
+  return 0;
+}
+
+int fesetenv(const fenv_t* envp) {
+  fpu_control_t fpcr;
+
+  __get_fpcr(fpcr);
+  if (envp->__control != fpcr) {
+    __set_fpcr(envp->__control);
+  }
+  __set_fpsr(envp->__status);
+  return 0;
+}
+
+int feclearexcept(int excepts) {
+  fpu_status_t fpsr;
+
+  excepts &= FE_ALL_EXCEPT;
+  __get_fpsr(fpsr);
+  fpsr &= ~excepts;
+  __set_fpsr(fpsr);
+  return 0;
+}
+
+int fegetexceptflag(fexcept_t* flagp, int excepts) {
+  fpu_status_t fpsr;
+
+  excepts &= FE_ALL_EXCEPT;
+  __get_fpsr(fpsr);
+  *flagp = fpsr & excepts;
+  return 0;
+}
+
+int fesetexceptflag(const fexcept_t* flagp, int excepts) {
+  fpu_status_t fpsr;
+
+  excepts &= FE_ALL_EXCEPT;
+  __get_fpsr(fpsr);
+  fpsr &= ~excepts;
+  fpsr |= *flagp & excepts;
+  __set_fpsr(fpsr);
+  return 0;
+}
+
+int feraiseexcept(int excepts) {
+  fexcept_t ex = excepts;
+
+  fesetexceptflag(&ex, excepts);
+  return 0;
+}
+
+int fetestexcept(int excepts) {
+  fpu_status_t fpsr;
+
+  excepts &= FE_ALL_EXCEPT;
+  __get_fpsr(fpsr);
+  return (fpsr & excepts);
+}
+
+int fegetround(void) {
+  fpu_control_t fpcr;
+
+  __get_fpcr(fpcr);
+  return ((fpcr >> FPCR_RMODE_SHIFT) & FE_TOWARDZERO);
+}
+
+int fesetround(int round) {
+  fpu_control_t fpcr, new_fpcr;
+
+  round &= FE_TOWARDZERO;
+  __get_fpcr(fpcr);
+  new_fpcr = fpcr & ~(FE_TOWARDZERO << FPCR_RMODE_SHIFT);
+  new_fpcr |= (round << FPCR_RMODE_SHIFT);
+  if (new_fpcr != fpcr) {
+    __set_fpcr(new_fpcr);
+  }
+  return 0;
+}
+
+int feholdexcept(fenv_t* envp) {
+  fenv_t env;
+  fpu_status_t fpsr;
+  fpu_control_t fpcr, new_fpcr;
+
+  __get_fpsr(fpsr);
+  __get_fpcr(fpcr);
+  env.__status = fpsr;
+  env.__control = fpcr;
+  *envp = env;
+
+  // Set exceptions to untrapped.
+  new_fpcr = fpcr & ~(FE_ALL_EXCEPT << FPCR_EXCEPT_SHIFT);
+  if (new_fpcr != fpcr) {
+    __set_fpcr(new_fpcr);
+  }
+
+  // Clear all exceptions.
+  fpsr &= ~FE_ALL_EXCEPT;
+  __set_fpsr(fpsr);
+  return 0;
+}
+
+int feupdateenv(const fenv_t* envp) {
+  fpu_status_t fpsr;
+  fpu_control_t fpcr;
+
+  // Set FPU Control register.
+  __get_fpcr(fpcr);
+  if (envp->__control != fpcr) {
+    __set_fpcr(envp->__control);
+  }
+
+  // Set FPU Status register to status | currently raised exceptions.
+  __get_fpsr(fpsr);
+  fpsr = envp->__status | (fpsr & FE_ALL_EXCEPT);
+  __set_fpsr(fpsr);
+  return 0;
+}
+
+int feenableexcept(int mask) {
+  fpu_control_t old_fpcr, new_fpcr;
+
+  __get_fpcr(old_fpcr);
+  new_fpcr = old_fpcr | ((mask & FE_ALL_EXCEPT) << FPCR_EXCEPT_SHIFT);
+  if (new_fpcr != old_fpcr) {
+    __set_fpcr(new_fpcr);
+  }
+  return ((old_fpcr >> FPCR_EXCEPT_SHIFT) & FE_ALL_EXCEPT);
+}
+
+int fedisableexcept(int mask) {
+  fpu_control_t old_fpcr, new_fpcr;
+
+  __get_fpcr(old_fpcr);
+  new_fpcr = old_fpcr & ~((mask & FE_ALL_EXCEPT) << FPCR_EXCEPT_SHIFT);
+  if (new_fpcr != old_fpcr) {
+    __set_fpcr(new_fpcr);
+  }
+  return ((old_fpcr >> FPCR_EXCEPT_SHIFT) & FE_ALL_EXCEPT);
+}
+
+int fegetexcept(void) {
+  fpu_control_t fpcr;
+
+  __get_fpcr(fpcr);
+  return ((fpcr & FPCR_EXCEPT_MASK) >> FPCR_EXCEPT_SHIFT);
+}
diff --git a/libm/fake_long_double.c b/libm/fake_long_double.c
index 756e35b..317a115 100644
--- a/libm/fake_long_double.c
+++ b/libm/fake_long_double.c
@@ -17,74 +17,25 @@
 #include <float.h>
 #include <math.h>
 
-extern int __isinf(double); /* isinf.c */
-int (isinf)(double a1) { return __isinf(a1); }
-
-int (isnanf)(float a1) { return __isnanf(a1); }
-
+#ifndef __LP64__
 /*
  * The BSD "long double" functions are broken when sizeof(long double) == sizeof(double).
  * Android works around those cases by replacing the broken functions with our own trivial stubs
  * that call the regular "double" function.
  */
 
-int __fpclassifyl(long double a1) { return __fpclassifyd(a1); }
-int __isfinitel(long double a1) { return __isfinite(a1); }
-int __isinfl(long double a1) { return __isinf(a1); }
-int __isnanl(long double a1) { return (isnan)(a1); }
-int __isnormall(long double a1) { return __isnormal(a1); }
-int __signbitl(long double a1) { return __signbit(a1); }
-
-long double acoshl(long double a1) { return acosh(a1); }
-long double acosl(long double a1) { return acos(a1); }
-long double asinhl(long double a1) { return asinh(a1); }
-long double asinl(long double a1) { return asin(a1); }
-long double atan2l(long double a1, long double a2) { return atan2(a1, a2); }
-long double atanhl(long double a1) { return atanh(a1); }
-long double atanl(long double a1) { return atan(a1); }
-long double cbrtl(long double a1) { return cbrt(a1); }
-long double ceill(long double a1) { return ceil(a1); }
 long double copysignl(long double a1, long double a2) { return copysign(a1, a2); }
-long double coshl(long double a1) { return cosh(a1); }
-long double cosl(long double a1) { return cos(a1); }
-long double erfcl(long double a1) { return erfc(a1); }
-long double erfl(long double a1) { return erf(a1); }
-long double exp2l(long double a1) { return exp2(a1); }
-long double expl(long double a1) { return exp(a1); }
-long double expm1l(long double a1) { return expm1(a1); }
 long double fabsl(long double a1) { return fabs(a1); }
-long double floorl(long double a1) { return floor(a1); }
-long double fmal(long double a1, long double a2, long double a3) { return fma(a1, a2, a3); }
 long double fmaxl(long double a1, long double a2) { return fmax(a1, a2); }
 long double fmodl(long double a1, long double a2) { return fmod(a1, a2); }
 long double fminl(long double a1, long double a2) { return fmin(a1, a2); }
-long double frexpl(long double a1, int* a2) { return frexp(a1, a2); }
-long double hypotl(long double a1, long double a2) { return hypot(a1, a2); }
 int ilogbl(long double a1) { return ilogb(a1); }
-long double ldexpl(long double a1, int a2) { return ldexp(a1, a2); }
-long double lgammal(long double a1) { return lgamma(a1); }
 long long llrintl(long double a1) { return llrint(a1); }
-long double log10l(long double a1) { return log10(a1); }
-long double log1pl(long double a1) { return log1p(a1); }
-long double log2l(long double a1) { return log2(a1); }
-long double logbl(long double a1) { return logb(a1); }
-long double logl(long double a1) { return log(a1); }
 long lrintl(long double a1) { return lrint(a1); }
 long long llroundl(long double a1) { return llround(a1); }
 long lroundl(long double a1) { return lround(a1); }
-long double nanl(const char* a1) { return nan(a1); }
-long double nextafterl(long double a1, long double a2) { return nextafter(a1, a2); }
-long double powl(long double a1, long double a2) { return pow(a1, a2); }
-long double remainderl(long double a1, long double a2) { return remainder(a1, a2); }
-long double remquol(long double a1, long double a2, int* a3) { return remquo(a1, a2, a3); }
-long double rintl(long double a1) { return rint(a1); }
+long double modfl(long double a1, long double* a2) { double i; double f = modf(a1, &i); *a2 = i; return f; }
+float nexttowardf(float a1, long double a2) { return nextafterf(a1, (float) a2); }
 long double roundl(long double a1) { return round(a1); }
-long double scalbnl(long double a1, int a2) { return scalbn(a1, a2); }
-long double significandl(long double a1) { return significand(a1); }
-long double sinhl(long double a1) { return sinh(a1); }
-long double sinl(long double a1) { return sin(a1); }
-long double sqrtl(long double a1) { return sqrt(a1); }
-long double tanhl(long double a1) { return tanh(a1); }
-long double tanl(long double a1) { return tan(a1); }
-long double tgammal(long double a1) { return tgamma(a1); }
-long double truncl(long double a1) { return trunc(a1); }
+
+#endif // __LP64__
diff --git a/libm/fpclassify.c b/libm/fpclassify.c
deleted file mode 100644
index a039138..0000000
--- a/libm/fpclassify.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*-
- * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
- * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/libc/gen/fpclassify.c,v 1.2 2005/02/06 03:23:31 das Exp $
- */
-
-#include <sys/endian.h>
-
-#include <math.h>
-#include <stdint.h>
-
-#include "fpmath.h"
-
-int
-__fpclassifyf(float f)
-{
-	union IEEEf2bits u;
-
-	u.f = f;
-	if (u.bits.exp == 0) {
-		if (u.bits.man == 0)
-			return (FP_ZERO);
-		return (FP_SUBNORMAL);
-	}
-	if (u.bits.exp == 255) {
-		if (u.bits.man == 0)
-			return (FP_INFINITE);
-		return (FP_NAN);
-	}
-	return (FP_NORMAL);
-}
-
-int
-__fpclassifyd(double d)
-{
-	union IEEEd2bits u;
-
-	u.d = d;
-	if (u.bits.exp == 0) {
-		if ((u.bits.manl | u.bits.manh) == 0)
-			return (FP_ZERO);
-		return (FP_SUBNORMAL);
-	}
-	if (u.bits.exp == 2047) {
-		if ((u.bits.manl | u.bits.manh) == 0)
-			return (FP_INFINITE);
-		return (FP_NAN);
-	}
-	return (FP_NORMAL);
-}
-
-int
-__fpclassifyl(long double e)
-{
-	union IEEEl2bits u;
-
-	u.e = e;
-	if (u.bits.exp == 0) {
-		if ((u.bits.manl | u.bits.manh) == 0)
-			return (FP_ZERO);
-		return (FP_SUBNORMAL);
-	}
-	mask_nbit_l(u);		/* Mask normalization bit if applicable. */
-	if (u.bits.exp == 32767) {
-		if ((u.bits.manl | u.bits.manh) == 0)
-			return (FP_INFINITE);
-		return (FP_NAN);
-	}
-	return (FP_NORMAL);
-}
-
diff --git a/libm/fpmath.h b/libm/fpmath.h
index f3753c1..80420e5 100644
--- a/libm/fpmath.h
+++ b/libm/fpmath.h
@@ -24,61 +24,73 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libc/include/fpmath.h,v 1.3 2005/02/06 03:23:31 das Exp $
+ * $FreeBSD$
  */
 
+// ANDROID changed:
+// - keep only little endian variants as they're the only one supported.
+// - add long double structures here instead of _fpmath.h.
+// - android uses 128 bits long doubles for LP64, so the structure and macros
+//   were reworked for the quad precision ieee representation.
+
+#ifndef _FPMATH_
+#define _FPMATH_
+
 #include <endian.h>
-#include "_fpmath.h"
 
 union IEEEf2bits {
-	float	f;
-	struct {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-		unsigned int	man	:23;
-		unsigned int	exp	:8;
-		unsigned int	sign	:1;
-#else /* _BIG_ENDIAN */
-		unsigned int	sign	:1;
-		unsigned int	exp	:8;
-		unsigned int	man	:23;
-#endif
-	} bits;
+  float f;
+  struct {
+    unsigned int man   :23;
+    unsigned int exp   :8;
+    unsigned int sign  :1;
+  } bits;
 };
 
-#define	DBL_MANH_SIZE	20
-#define	DBL_MANL_SIZE	32
+#define DBL_MANH_SIZE  20
+#define DBL_MANL_SIZE  32
 
 union IEEEd2bits {
-	double	d;
-	struct {
-/* #ifdef __ARMEB__ */
-#if (__BYTE_ORDER == __BIG_ENDIAN) || (defined(__arm__) && !defined(__VFP_FP__))
-		unsigned int	manh	:20;
-		unsigned int	exp	:11;
-		unsigned int	sign	:1;
-		unsigned int	manl	:32;
-#elif  __BYTE_ORDER == __LITTLE_ENDIAN
-		unsigned int	manl	:32;
-		unsigned int	manh	:20;
-		unsigned int	exp	:11;
-		unsigned int	sign	:1;
-#elif __BYTE_ORDER == __BIG_ENDIAN
-		unsigned int	sign	:1;
-		unsigned int	exp	:11;
-		unsigned int	manh	:20;
-		unsigned int	manl	:32;
-#endif
-	} bits;
+  double  d;
+  struct {
+    unsigned int manl  :32;
+    unsigned int manh  :20;
+    unsigned int exp   :11;
+    unsigned int sign  :1;
+  } bits;
 };
 
-/*
- * The BSD "long double" functions are broken when sizeof(long double) == sizeof(double).
- * Android works around those cases by replacing the broken functions with our own trivial stubs
- * that call the regular "double" function.
- */
-#define __fpclassifyl __broken__fpclassify
-#define __isfinitel __broken__isfinitel
-#define __isinfl __broken__isinfl
-#define __isnanl __broken__isnanl
-#define __isnormall __broken__isnormall
-#define __signbitl __broken_signbitl
+#ifdef __LP64__
+
+union IEEEl2bits {
+  long double e;
+  struct {
+    unsigned long manl  :64;
+    unsigned long manh  :48;
+    unsigned int  exp   :15;
+    unsigned int  sign  :1;
+  } bits;
+  struct {
+    unsigned long manl     :64;
+    unsigned long manh     :48;
+    unsigned int  expsign  :16;
+  } xbits;
+};
+
+#define LDBL_NBIT  0
+#define LDBL_IMPLICIT_NBIT
+#define mask_nbit_l(u)  ((void)0)
+
+#define LDBL_MANH_SIZE  48
+#define LDBL_MANL_SIZE  64
+
+#define LDBL_TO_ARRAY32(u, a) do {           \
+  (a)[0] = (uint32_t)(u).bits.manl;          \
+  (a)[1] = (uint32_t)((u).bits.manl >> 32);  \
+  (a)[2] = (uint32_t)(u).bits.manh;          \
+  (a)[3] = (uint32_t)((u).bits.manh >> 32);  \
+} while(0)
+
+#endif // __LP64__
+
+#endif // _FPMATH_
diff --git a/libm/freebsd-compat.h b/libm/freebsd-compat.h
index 4b14fae..1481cc2 100644
--- a/libm/freebsd-compat.h
+++ b/libm/freebsd-compat.h
@@ -17,10 +17,16 @@
 #ifndef _BIONIC_LIBM_FREEBSD_COMPAT_H_included
 #define _BIONIC_LIBM_FREEBSD_COMPAT_H_included
 
-#define __weak_reference(sym,alias) \
-    /* We don't use __weak_reference; see "fake_long_double.c". */
+#include <float.h>
+
+#define __weak_reference(sym,alias)     \
+    __asm__(".weak " #alias);           \
+    __asm__(".equ "  #alias ", " #sym)
 
 #define __strong_reference(sym,aliassym) \
     extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
 
+/* digittoint is in BSD's <ctype.h>. */
+int digittoint(char ch);
+
 #endif
diff --git a/libm/i386/_fpmath.h b/libm/i386/_fpmath.h
deleted file mode 100644
index 4f1f5f4..0000000
--- a/libm/i386/_fpmath.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-union IEEEl2bits {
-	long double	e;
-	struct {
-		unsigned int	manl	:32;
-		unsigned int	manh	:32;
-		unsigned int	exp	:15;
-		unsigned int	sign	:1;
-		unsigned int	junk	:16;
-	} bits;
-	struct {
-		unsigned long long man	:64;
-		unsigned int 	expsign	:16;
-		unsigned int	junk	:16;
-	} xbits;
-};
-
-#define	LDBL_NBIT	0x80000000
-#define	mask_nbit_l(u)	((u).bits.manh &= ~LDBL_NBIT)
-
-#define	LDBL_MANH_SIZE	32
-#define	LDBL_MANL_SIZE	32
-
-#define	LDBL_TO_ARRAY32(u, a) do {			\
-	(a)[0] = (uint32_t)(u).bits.manl;		\
-	(a)[1] = (uint32_t)(u).bits.manh;		\
-} while (0)
diff --git a/libm/i387/fenv.c b/libm/i387/fenv.c
index 89ddc55..f64f8dc 100644
--- a/libm/i387/fenv.c
+++ b/libm/i387/fenv.c
@@ -31,29 +31,31 @@
 #include "npx.h"
 #include "fenv.h"
 
+#define ROUND_MASK   (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
+
 /*
  * As compared to the x87 control word, the SSE unit's control word
  * has the rounding control bits offset by 3 and the exception mask
  * bits offset by 7.
  */
-#define	_SSE_ROUND_SHIFT	3
-#define	_SSE_EMASK_SHIFT	7
+#define _SSE_ROUND_SHIFT 3
+#define _SSE_EMASK_SHIFT 7
 
 const fenv_t __fe_dfl_env = {
-	__INITIAL_NPXCW__, /*__control*/
-	0x0000,            /*__mxcsr_hi*/
-	0x0000,            /*__status*/
-	0x1f80,            /*__mxcsr_lo*/
-	0xffffffff,        /*__tag*/
-	{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } /*__other*/
+  __INITIAL_NPXCW__, /*__control*/
+  0x0000,            /*__mxcsr_hi*/
+  0x0000,            /*__status*/
+  0x1f80,            /*__mxcsr_lo*/
+  0xffffffff,        /*__tag*/
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } /*__other*/
 };
 
 #define __fldcw(__cw)           __asm __volatile("fldcw %0" : : "m" (__cw))
 #define __fldenv(__env)         __asm __volatile("fldenv %0" : : "m" (__env))
-#define	__fldenvx(__env)	__asm __volatile("fldenv %0" : : "m" (__env)  \
-				: "st", "st(1)", "st(2)", "st(3)", "st(4)",   \
-				"st(5)", "st(6)", "st(7)")
+#define __fldenvx(__env)        __asm __volatile("fldenv %0" : : "m" (__env)  \
+                                : "st", "st(1)", "st(2)", "st(3)", "st(4)",   \
+                                "st(5)", "st(6)", "st(7)")
 #define __fnclex()              __asm __volatile("fnclex")
 #define __fnstenv(__env)        __asm __volatile("fnstenv %0" : "=m" (*(__env)))
 #define __fnstcw(__cw)          __asm __volatile("fnstcw %0" : "=m" (*(__cw)))
@@ -68,22 +70,22 @@
 #define __HAS_SSE()     1
 #else
 #define __HAS_SSE()     (__has_sse == __SSE_YES ||                      \
-                         (__has_sse == __SSE_UNK && __test_sse()))
+                        (__has_sse == __SSE_UNK && __test_sse()))
 #endif
 
 enum __sse_support __has_sse =
 #ifdef __SSE__
-	__SSE_YES;
+  __SSE_YES;
 #else
-	__SSE_UNK;
+  __SSE_UNK;
 #endif
 
 #ifndef __SSE__
-#define	getfl(x)	__asm __volatile("pushfl\n\tpopl %0" : "=mr" (*(x)))
-#define	setfl(x)	__asm __volatile("pushl %0\n\tpopfl" : : "g" (x))
-#define	cpuid_dx(x)	__asm __volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t"  \
-					 "cpuid\n\tpopl %%ebx"		      \
-					: "=d" (*(x)) : : "eax", "ecx")
+#define getfl(x)    __asm __volatile("pushfl\n\tpopl %0" : "=mr" (*(x)))
+#define setfl(x)    __asm __volatile("pushl %0\n\tpopfl" : : "g" (x))
+#define cpuid_dx(x) __asm __volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t"  \
+                    "cpuid\n\tpopl %%ebx"          \
+                    : "=d" (*(x)) : : "eax", "ecx")
 
 /*
  * Test for SSE support on this processor.  We need to do this because
@@ -94,298 +96,298 @@
 int
 __test_sse(void)
 {
-	int flag, nflag;
-	int dx_features;
+  int flag, nflag;
+  int dx_features;
 
-	/* Am I a 486? */
-	getfl(&flag);
-	nflag = flag ^ 0x200000;
-	setfl(nflag);
-	getfl(&nflag);
-	if (flag != nflag) {
-		/* Not a 486, so CPUID should work. */
-		cpuid_dx(&dx_features);
-		if (dx_features & 0x2000000) {
-			__has_sse = __SSE_YES;
-			return (1);
-		}
-	}
-	__has_sse = __SSE_NO;
-	return (0);
+  /* Am I a 486? */
+  getfl(&flag);
+  nflag = flag ^ 0x200000;
+  setfl(nflag);
+  getfl(&nflag);
+  if (flag != nflag) {
+    /* Not a 486, so CPUID should work. */
+    cpuid_dx(&dx_features);
+    if (dx_features & 0x2000000) {
+      __has_sse = __SSE_YES;
+      return (1);
+    }
+  }
+  __has_sse = __SSE_NO;
+  return (0);
 }
 #endif /* __SSE__ */
 
 int
 fesetexceptflag(const fexcept_t *flagp, int excepts)
 {
-	fenv_t env;
-	__uint32_t mxcsr;
+  fenv_t env;
+  __uint32_t mxcsr;
 
-	excepts &= FE_ALL_EXCEPT;
-	if (excepts) { /* Do nothing if excepts is 0 */
-		__fnstenv(&env);
-		env.__status &= ~excepts;
-		env.__status |= *flagp & excepts;
-		__fnclex();
-		__fldenv(env);
-		if (__HAS_SSE()) {
-			__stmxcsr(&mxcsr);
-			mxcsr &= ~excepts;
-			mxcsr |= *flagp & excepts;
-			__ldmxcsr(mxcsr);
-		}
-	}
+  excepts &= FE_ALL_EXCEPT;
+  if (excepts) { /* Do nothing if excepts is 0 */
+    __fnstenv(&env);
+    env.__status &= ~excepts;
+    env.__status |= *flagp & excepts;
+    __fnclex();
+    __fldenv(env);
+    if (__HAS_SSE()) {
+      __stmxcsr(&mxcsr);
+      mxcsr &= ~excepts;
+      mxcsr |= *flagp & excepts;
+      __ldmxcsr(mxcsr);
+    }
+  }
 
-	return (0);
+  return (0);
 }
 
 int
 feraiseexcept(int excepts)
 {
-	fexcept_t ex = excepts;
+  fexcept_t ex = excepts;
 
-	fesetexceptflag(&ex, excepts);
-	__fwait();
-	return (0);
+  fesetexceptflag(&ex, excepts);
+  __fwait();
+  return (0);
 }
 
 int
 fegetenv(fenv_t *envp)
 {
-	__uint32_t mxcsr;
+  __uint32_t mxcsr;
 
-	__fnstenv(envp);
-	/*
-	 * fnstenv masks all exceptions, so we need to restore
-	 * the old control word to avoid this side effect.
-	 */
-	__fldcw(envp->__control);
-	if (__HAS_SSE()) {
-		__stmxcsr(&mxcsr);
-		envp->__mxcsr_hi = mxcsr >> 16;
-		envp->__mxcsr_lo = mxcsr & 0xffff;
-	}
-	return (0);
+  __fnstenv(envp);
+  /*
+   * fnstenv masks all exceptions, so we need to restore
+   * the old control word to avoid this side effect.
+   */
+  __fldcw(envp->__control);
+  if (__HAS_SSE()) {
+    __stmxcsr(&mxcsr);
+    envp->__mxcsr_hi = mxcsr >> 16;
+    envp->__mxcsr_lo = mxcsr & 0xffff;
+  }
+  return (0);
 }
 
 int
 feholdexcept(fenv_t *envp)
 {
-	__uint32_t mxcsr;
-	fenv_t env;
+  __uint32_t mxcsr;
+  fenv_t env;
 
-	__fnstenv(&env);
-	*envp = env;
-	env.__status &= ~FE_ALL_EXCEPT;
-	env.__control |= FE_ALL_EXCEPT;
-	__fnclex();
-	__fldenv(env);
-	if (__HAS_SSE()) {
-		__stmxcsr(&mxcsr);
-		envp->__mxcsr_hi = mxcsr >> 16;
-		envp->__mxcsr_lo = mxcsr & 0xffff;
-		mxcsr &= ~FE_ALL_EXCEPT;
-		mxcsr |= FE_ALL_EXCEPT << _SSE_EMASK_SHIFT;
-		__ldmxcsr(mxcsr);
-	}
-	return (0);
+  __fnstenv(&env);
+  *envp = env;
+  env.__status &= ~FE_ALL_EXCEPT;
+  env.__control |= FE_ALL_EXCEPT;
+  __fnclex();
+  __fldenv(env);
+  if (__HAS_SSE()) {
+    __stmxcsr(&mxcsr);
+    envp->__mxcsr_hi = mxcsr >> 16;
+    envp->__mxcsr_lo = mxcsr & 0xffff;
+    mxcsr &= ~FE_ALL_EXCEPT;
+    mxcsr |= FE_ALL_EXCEPT << _SSE_EMASK_SHIFT;
+    __ldmxcsr(mxcsr);
+  }
+  return (0);
 }
 
 int
 feupdateenv(const fenv_t *envp)
 {
-	__uint32_t mxcsr;
-	__uint16_t status;
+  __uint32_t mxcsr;
+  __uint16_t status;
 
-	__fnstsw(&status);
-	if (__HAS_SSE()) {
-		__stmxcsr(&mxcsr);
-	} else {
-		mxcsr = 0;
-	}
-	fesetenv(envp);
-	feraiseexcept((mxcsr | status) & FE_ALL_EXCEPT);
-	return (0);
+  __fnstsw(&status);
+  if (__HAS_SSE()) {
+    __stmxcsr(&mxcsr);
+  } else {
+    mxcsr = 0;
+  }
+  fesetenv(envp);
+  feraiseexcept((mxcsr | status) & FE_ALL_EXCEPT);
+  return (0);
 }
 
 int
 feenableexcept(int mask)
 {
-	__uint32_t mxcsr;
-	__uint16_t control, omask;
+  __uint32_t mxcsr;
+  __uint16_t control, omask;
 
-	mask &= FE_ALL_EXCEPT;
-	__fnstcw(&control);
-	if (__HAS_SSE()) {
-		__stmxcsr(&mxcsr);
-	} else {
-		mxcsr = 0;
-	}
-	omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT;
-	if (mask) {
-		control &= ~mask;
-		__fldcw(control);
-		if (__HAS_SSE()) {
-			mxcsr &= ~(mask << _SSE_EMASK_SHIFT);
-			__ldmxcsr(mxcsr);
-		}
-	}
-	return (omask);
+  mask &= FE_ALL_EXCEPT;
+  __fnstcw(&control);
+  if (__HAS_SSE()) {
+    __stmxcsr(&mxcsr);
+  } else {
+    mxcsr = 0;
+  }
+  omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT;
+  if (mask) {
+    control &= ~mask;
+    __fldcw(control);
+    if (__HAS_SSE()) {
+      mxcsr &= ~(mask << _SSE_EMASK_SHIFT);
+      __ldmxcsr(mxcsr);
+    }
+  }
+  return (omask);
 }
 
 int
 fedisableexcept(int mask)
 {
-	__uint32_t mxcsr;
-	__uint16_t control, omask;
+  __uint32_t mxcsr;
+  __uint16_t control, omask;
 
-	mask &= FE_ALL_EXCEPT;
-	__fnstcw(&control);
-	if (__HAS_SSE()) {
-		__stmxcsr(&mxcsr);
-	} else {
-		mxcsr = 0;
-	}
-	omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT;
-	if (mask) {
-		control |= mask;
-		__fldcw(control);
-		if (__HAS_SSE()) {
-			mxcsr |= mask << _SSE_EMASK_SHIFT;
-			__ldmxcsr(mxcsr);
-		}
-	}
-	return (omask);
+  mask &= FE_ALL_EXCEPT;
+  __fnstcw(&control);
+  if (__HAS_SSE()) {
+    __stmxcsr(&mxcsr);
+  } else {
+    mxcsr = 0;
+  }
+  omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT;
+  if (mask) {
+    control |= mask;
+    __fldcw(control);
+    if (__HAS_SSE()) {
+      mxcsr |= mask << _SSE_EMASK_SHIFT;
+      __ldmxcsr(mxcsr);
+    }
+  }
+  return (omask);
 }
 
 int
 feclearexcept(int excepts)
 {
-	fenv_t env;
-	__uint32_t mxcsr;
+  fenv_t env;
+  __uint32_t mxcsr;
 
-	excepts &= FE_ALL_EXCEPT;
-	if (excepts) { /* Do nothing if excepts is 0 */
-		__fnstenv(&env);
-		env.__status &= ~excepts;
-		__fnclex();
-		__fldenv(env);
-		if (__HAS_SSE()) {
-			__stmxcsr(&mxcsr);
-			mxcsr &= ~excepts;
-			__ldmxcsr(mxcsr);
-		}
-	}
-	return (0);
+  excepts &= FE_ALL_EXCEPT;
+  if (excepts) { /* Do nothing if excepts is 0 */
+    __fnstenv(&env);
+    env.__status &= ~excepts;
+    __fnclex();
+    __fldenv(env);
+    if (__HAS_SSE()) {
+      __stmxcsr(&mxcsr);
+      mxcsr &= ~excepts;
+      __ldmxcsr(mxcsr);
+    }
+  }
+  return (0);
 }
 
 int
 fegetexceptflag(fexcept_t *flagp, int excepts)
 {
-	__uint32_t mxcsr;
-	__uint16_t status;
+  __uint32_t mxcsr;
+  __uint16_t status;
 
-	excepts &= FE_ALL_EXCEPT;
-	__fnstsw(&status);
-	if (__HAS_SSE()) {
-		__stmxcsr(&mxcsr);
-	} else {
-		mxcsr = 0;
-	}
-	*flagp = (status | mxcsr) & excepts;
-	return (0);
+  excepts &= FE_ALL_EXCEPT;
+  __fnstsw(&status);
+  if (__HAS_SSE()) {
+    __stmxcsr(&mxcsr);
+  } else {
+    mxcsr = 0;
+  }
+  *flagp = (status | mxcsr) & excepts;
+  return (0);
 }
 
 int
 fetestexcept(int excepts)
 {
-	__uint32_t mxcsr;
-	__uint16_t status;
+  __uint32_t mxcsr;
+  __uint16_t status;
 
-	excepts &= FE_ALL_EXCEPT;
-	if (excepts) { /* Do nothing if excepts is 0 */
-		__fnstsw(&status);
-		if (__HAS_SSE()) {
-			__stmxcsr(&mxcsr);
-		} else {
-			mxcsr = 0;
-		}
-		return ((status | mxcsr) & excepts);
-	}
-	return (0);
+  excepts &= FE_ALL_EXCEPT;
+  if (excepts) { /* Do nothing if excepts is 0 */
+    __fnstsw(&status);
+    if (__HAS_SSE()) {
+      __stmxcsr(&mxcsr);
+    } else {
+      mxcsr = 0;
+    }
+    return ((status | mxcsr) & excepts);
+  }
+  return (0);
 }
 
 int
 fegetround(void)
 {
-	__uint16_t control;
+  __uint16_t control;
 
-	/*
-	 * We assume that the x87 and the SSE unit agree on the
-	 * rounding mode.  Reading the control word on the x87 turns
-	 * out to be about 5 times faster than reading it on the SSE
-	 * unit on an Opteron 244.
-	 */
-	__fnstcw(&control);
-	return (control & _ROUND_MASK);
+  /*
+   * We assume that the x87 and the SSE unit agree on the
+   * rounding mode.  Reading the control word on the x87 turns
+   * out to be about 5 times faster than reading it on the SSE
+   * unit on an Opteron 244.
+   */
+  __fnstcw(&control);
+  return (control & ROUND_MASK);
 }
 
 int
 fesetround(int round)
 {
-	__uint32_t mxcsr;
-	__uint16_t control;
+  __uint32_t mxcsr;
+  __uint16_t control;
 
-	if (round & ~_ROUND_MASK) {
-		return (-1);
-	} else {
-		__fnstcw(&control);
-		control &= ~_ROUND_MASK;
-		control |= round;
-		__fldcw(control);
-		if (__HAS_SSE()) {
-			__stmxcsr(&mxcsr);
-			mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT);
-			mxcsr |= round << _SSE_ROUND_SHIFT;
-			__ldmxcsr(mxcsr);
-		}
-		return (0);
-	}
+  if (round & ~ROUND_MASK) {
+    return (-1);
+  } else {
+    __fnstcw(&control);
+    control &= ~ROUND_MASK;
+    control |= round;
+    __fldcw(control);
+    if (__HAS_SSE()) {
+      __stmxcsr(&mxcsr);
+      mxcsr &= ~(ROUND_MASK << _SSE_ROUND_SHIFT);
+      mxcsr |= round << _SSE_ROUND_SHIFT;
+      __ldmxcsr(mxcsr);
+    }
+    return (0);
+  }
 }
 
 int
 fesetenv(const fenv_t *envp)
 {
-	fenv_t env = *envp;
-	__uint32_t mxcsr;
+  fenv_t env = *envp;
+  __uint32_t mxcsr;
 
-	mxcsr = (env.__mxcsr_hi << 16) | (env.__mxcsr_lo);
-	env.__mxcsr_hi = 0xffff;
-	env.__mxcsr_lo = 0xffff;
-	/*
-	 * XXX Using fldenvx() instead of fldenv() tells the compiler that this
-	 * instruction clobbers the i387 register stack.  This happens because
-	 * we restore the tag word from the saved environment.  Normally, this
-	 * would happen anyway and we wouldn't care, because the ABI allows
-	 * function calls to clobber the i387 regs.  However, fesetenv() is
-	 * inlined, so we need to be more careful.
-	 */
-	__fldenvx(env);
-	if (__HAS_SSE()) {
-		__ldmxcsr(mxcsr);
-	}
-	return (0);
+  mxcsr = (env.__mxcsr_hi << 16) | (env.__mxcsr_lo);
+  env.__mxcsr_hi = 0xffff;
+  env.__mxcsr_lo = 0xffff;
+  /*
+   * XXX Using fldenvx() instead of fldenv() tells the compiler that this
+   * instruction clobbers the i387 register stack.  This happens because
+   * we restore the tag word from the saved environment.  Normally, this
+   * would happen anyway and we wouldn't care, because the ABI allows
+   * function calls to clobber the i387 regs.  However, fesetenv() is
+   * inlined, so we need to be more careful.
+   */
+  __fldenvx(env);
+  if (__HAS_SSE()) {
+    __ldmxcsr(mxcsr);
+  }
+  return (0);
 }
 
 int
 fegetexcept(void)
 {
-	__uint16_t control;
+  __uint16_t control;
 
-	/*
-	 * We assume that the masks for the x87 and the SSE unit are
-	 * the same.
-	 */
-	__fnstcw(&control);
-	return (~control & FE_ALL_EXCEPT);
+  /*
+   * We assume that the masks for the x87 and the SSE unit are
+   * the same.
+   */
+  __fnstcw(&control);
+  return (~control & FE_ALL_EXCEPT);
 }
diff --git a/libm/include/amd64/fenv.h b/libm/include/amd64/fenv.h
deleted file mode 100644
index 1dc4215..0000000
--- a/libm/include/amd64/fenv.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef	_AMD64_FENV_H_
-#define	_AMD64_FENV_H_
-
-#include <sys/types.h>
-
-/*
- * This file combines the OpenBSD include/fenv.h and machine/fenv.h to fit
- * the style of the other architectures (where we couldn't just take an
- * upstream fenv.h and had to write our own).
- */
-
-__BEGIN_DECLS
-
-/*
- * Each symbol representing a floating point exception expands to an integer
- * constant expression with values, such that bitwise-inclusive ORs of _all
- * combinations_ of the constants result in distinct values.
- *
- * We use such values that allow direct bitwise operations on FPU/SSE registers.
- */
-#define	FE_INVALID		0x01
-#define	FE_DENORMAL		0x02
-#define	FE_DIVBYZERO		0x04
-#define	FE_OVERFLOW		0x08
-#define	FE_UNDERFLOW		0x10
-#define	FE_INEXACT		0x20
-
-/*
- * The following symbol is simply the bitwise-inclusive OR of all floating-point
- * exception constants defined above.
- */
-#define	FE_ALL_EXCEPT		(FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \
-				 FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
-#define	_SSE_MASK_SHIFT		7
-
-/*
- * Each symbol representing the rounding direction, expands to an integer
- * constant expression whose value is distinct non-negative value.
- *
- * We use such values that allow direct bitwise operations on FPU/SSE registers.
- */
-#define	FE_TONEAREST		0x000
-#define	FE_DOWNWARD		0x400
-#define	FE_UPWARD		0x800
-#define	FE_TOWARDZERO		0xc00
-
-/*
- * The following symbol is simply the bitwise-inclusive OR of all floating-point
- * rounding direction constants defined above.
- */
-#define	_X87_ROUND_MASK		(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \
-				 FE_TOWARDZERO)
-#define	_SSE_ROUND_SHIFT	3
-
-/*
- * fenv_t represents the entire floating-point environment.
- */
-typedef	struct {
-	struct {
-		unsigned int __control;		/* Control word register */
-		unsigned int __status;		/* Status word register */
-		unsigned int __tag;		/* Tag word register */
-		unsigned int __others[4];	/* EIP, Pointer Selector, etc */
-	} __x87;
-	unsigned int __mxcsr;			/* Control, status register */
-} fenv_t;
-
-/*
- * The following constant represents the default floating-point environment
- * (that is, the one installed at program startup) and has type pointer to
- * const-qualified fenv_t.
- *
- * It can be used as an argument to the functions within the <fenv.h> header
- * that manage the floating-point environment, namely fesetenv() and
- * feupdateenv().
- */
-extern	fenv_t			__fe_dfl_env;
-#define	FE_DFL_ENV		((const fenv_t *)&__fe_dfl_env)
-
-/*
- * fexcept_t represents the floating-point status flags collectively, including
- * any status the implementation associates with the flags.
- *
- * A floating-point status flag is a system variable whose value is set (but
- * never cleared) when a floating-point exception is raised, which occurs as a
- * side effect of exceptional floating-point arithmetic to provide auxiliary
- * information.
- *
- * A floating-point control mode is a system variable whose value may be set by
- * the user to affect the subsequent behavior of floating-point arithmetic.
- */
-typedef	unsigned int		fexcept_t;
-
-/* C99 floating-point exception functions */
-int feclearexcept(int excepts);
-int fegetexceptflag(fexcept_t *flagp, int excepts);
-int fesetexceptflag(const fexcept_t *flagp, int excepts);
-/* feraiseexcept does not set the inexact flag on overflow/underflow */
-int feraiseexcept(int excepts);
-int fetestexcept(int excepts);
-
-/* C99 rounding control functions */
-int fegetround(void);
-int fesetround(int round);
-
-/* C99 floating-point environment functions */
-int fegetenv(fenv_t *__envp);
-int feholdexcept(fenv_t *__envp);
-int fesetenv(const fenv_t *envp);
-int feupdateenv(const fenv_t *__envp);
-
-#if __BSD_VISIBLE
-/* Additional support functions to set/query floating point traps */
-int feenableexcept(int __mask);
-int fedisableexcept(int __mask);
-int fegetexcept(void);
-#endif /* __BSD_VISIBLE */
-
-__END_DECLS
-
-#endif	/* !_AMD64_FENV_H_ */
diff --git a/libm/include/amd64/machine/fenv.h b/libm/include/amd64/machine/fenv.h
new file mode 100644
index 0000000..c2b25ed
--- /dev/null
+++ b/libm/include/amd64/machine/fenv.h
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _AMD64_FENV_H_
+#define _AMD64_FENV_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+/*
+ * Each symbol representing a floating point exception expands to an integer
+ * constant expression with values, such that bitwise-inclusive ORs of _all
+ * combinations_ of the constants result in distinct values.
+ *
+ * We use such values that allow direct bitwise operations on FPU/SSE registers.
+ */
+#define FE_INVALID    0x01
+#define FE_DENORMAL   0x02
+#define FE_DIVBYZERO  0x04
+#define FE_OVERFLOW   0x08
+#define FE_UNDERFLOW  0x10
+#define FE_INEXACT    0x20
+
+/*
+ * The following symbol is simply the bitwise-inclusive OR of all floating-point
+ * exception constants defined above.
+ */
+#define FE_ALL_EXCEPT   (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \
+                         FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
+
+/*
+ * Each symbol representing the rounding direction, expands to an integer
+ * constant expression whose value is distinct non-negative value.
+ *
+ * We use such values that allow direct bitwise operations on FPU/SSE registers.
+ */
+#define FE_TONEAREST  0x000
+#define FE_DOWNWARD   0x400
+#define FE_UPWARD     0x800
+#define FE_TOWARDZERO 0xc00
+
+/*
+ * fenv_t represents the entire floating-point environment.
+ */
+typedef struct {
+  struct {
+    __uint32_t __control;   /* Control word register */
+    __uint32_t __status;    /* Status word register */
+    __uint32_t __tag;       /* Tag word register */
+    __uint32_t __others[4]; /* EIP, Pointer Selector, etc */
+  } __x87;
+  __uint32_t __mxcsr;       /* Control, status register */
+} fenv_t;
+
+/*
+ * fexcept_t represents the floating-point status flags collectively, including
+ * any status the implementation associates with the flags.
+ *
+ * A floating-point status flag is a system variable whose value is set (but
+ * never cleared) when a floating-point exception is raised, which occurs as a
+ * side effect of exceptional floating-point arithmetic to provide auxiliary
+ * information.
+ *
+ * A floating-point control mode is a system variable whose value may be set by
+ * the user to affect the subsequent behavior of floating-point arithmetic.
+ */
+typedef __uint32_t fexcept_t;
+
+__END_DECLS
+
+#endif /* !_AMD64_FENV_H_ */
diff --git a/libm/include/arm/fenv.h b/libm/include/arm/fenv.h
deleted file mode 100644
index a96f99e..0000000
--- a/libm/include/arm/fenv.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
- */
-
-/*
- * Rewritten for Android.
- *
- * The ARM FPSCR is described here:
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Chdfafia.html
- */
-
-#ifndef _FENV_H_
-#define _FENV_H_
-
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-typedef __uint32_t fenv_t;
-typedef __uint32_t fexcept_t;
-
-/* Exception flags. */
-#define FE_INVALID    0x01
-#define FE_DIVBYZERO  0x02
-#define FE_OVERFLOW   0x04
-#define FE_UNDERFLOW  0x08
-#define FE_INEXACT    0x10
-#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
-#define _FPSCR_ENABLE_SHIFT 8
-#define _FPSCR_ENABLE_MASK (FE_ALL_EXCEPT << _FPSCR_ENABLE_SHIFT)
-
-/* Rounding modes. */
-#define FE_TONEAREST  0x0
-#define FE_UPWARD     0x1
-#define FE_DOWNWARD   0x2
-#define FE_TOWARDZERO 0x3
-#define _FPSCR_RMODE_SHIFT 22
-
-/* Default floating-point environment. */
-extern const fenv_t __fe_dfl_env;
-#define FE_DFL_ENV (&__fe_dfl_env)
-
-static __inline int fegetenv(fenv_t* __envp) {
-  fenv_t _fpscr;
-  __asm__ __volatile__("vmrs %0,fpscr" : "=r" (_fpscr));
-  *__envp = _fpscr;
-  return 0;
-}
-
-static __inline int fesetenv(const fenv_t* __envp) {
-  fenv_t _fpscr = *__envp;
-  __asm__ __volatile__("vmsr fpscr,%0" : :"ri" (_fpscr));
-  return 0;
-}
-
-static __inline int feclearexcept(int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  __fpscr &= ~__excepts;
-  fesetenv(&__fpscr);
-  return 0;
-}
-
-static __inline int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  *__flagp = __fpscr & __excepts;
-  return 0;
-}
-
-static __inline int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  __fpscr &= ~__excepts;
-  __fpscr |= *__flagp & __excepts;
-  fesetenv(&__fpscr);
-  return 0;
-}
-
-static __inline int feraiseexcept(int __excepts) {
-  fexcept_t __ex = __excepts;
-  fesetexceptflag(&__ex, __excepts);
-  return 0;
-}
-
-static __inline int fetestexcept(int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  return (__fpscr & __excepts);
-}
-
-static __inline int fegetround(void) {
-  fenv_t _fpscr;
-  fegetenv(&_fpscr);
-  return ((_fpscr >> _FPSCR_RMODE_SHIFT) & 0x3);
-}
-
-static __inline int fesetround(int __round) {
-  fenv_t _fpscr;
-  fegetenv(&_fpscr);
-  _fpscr &= ~(0x3 << _FPSCR_RMODE_SHIFT);
-  _fpscr |= (__round << _FPSCR_RMODE_SHIFT);
-  fesetenv(&_fpscr);
-  return 0;
-}
-
-static __inline int feholdexcept(fenv_t* __envp) {
-  fenv_t __env;
-  fegetenv(&__env);
-  *__envp = __env;
-  __env &= ~(FE_ALL_EXCEPT | _FPSCR_ENABLE_MASK);
-  fesetenv(&__env);
-  return 0;
-}
-
-static __inline int feupdateenv(const fenv_t* __envp) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  fesetenv(__envp);
-  feraiseexcept(__fpscr & FE_ALL_EXCEPT);
-  return 0;
-}
-
-#if __BSD_VISIBLE
-
-static __inline int feenableexcept(int __mask) {
-  fenv_t __old_fpscr, __new_fpscr;
-  fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT;
-  fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fedisableexcept(int __mask) {
-  fenv_t __old_fpscr, __new_fpscr;
-  fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT);
-  fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fegetexcept(void) {
-  fenv_t __fpscr;
-  fegetenv(&__fpscr);
-  return ((__fpscr & _FPSCR_ENABLE_MASK) >> _FPSCR_ENABLE_SHIFT);
-}
-
-#endif /* __BSD_VISIBLE */
-
-__END_DECLS
-
-#endif /* !_FENV_H_ */
diff --git a/libm/include/arm/machine/fenv.h b/libm/include/arm/machine/fenv.h
new file mode 100644
index 0000000..0e483e3
--- /dev/null
+++ b/libm/include/arm/machine/fenv.h
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
+ */
+
+/*
+ * Rewritten for Android.
+ *
+ * The ARM FPSCR is described here:
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Chdfafia.html
+ */
+
+#ifndef _ARM_FENV_H_
+#define _ARM_FENV_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+typedef __uint32_t fenv_t;
+typedef __uint32_t fexcept_t;
+
+/* Exception flags. */
+#define FE_INVALID    0x01
+#define FE_DIVBYZERO  0x02
+#define FE_OVERFLOW   0x04
+#define FE_UNDERFLOW  0x08
+#define FE_INEXACT    0x10
+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
+                       FE_OVERFLOW | FE_UNDERFLOW)
+
+/* Rounding modes. */
+#define FE_TONEAREST  0x0
+#define FE_UPWARD     0x1
+#define FE_DOWNWARD   0x2
+#define FE_TOWARDZERO 0x3
+
+__END_DECLS
+
+#endif /* !_ARM_FENV_H_ */
diff --git a/libm/include/arm64/fenv.h b/libm/include/arm64/fenv.h
deleted file mode 100644
index 32c3b1d..0000000
--- a/libm/include/arm64/fenv.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
- */
-
-/*
- * Rewritten for Android.
- *
- * The ARM FPSCR (Floating-point Status and Control Register) described here:
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Chdfafia.html
- * has been split into the FPCR (Floating-point Control Register) and FPSR
- * (Floating-point Status Register) on the ARMv8. These are described briefly in
- * "Procedure Call Standard for the ARM 64-bit Architecture"
- * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
- * section 5.1.2 SIMD and Floating-Point Registers
- */
-
-#ifndef _FENV_H_
-#define _FENV_H_
-
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-typedef __uint32_t fenv_t;
-typedef __uint32_t fexcept_t;
-
-/* Exception flags. */
-#define FE_INVALID    0x01
-#define FE_DIVBYZERO  0x02
-#define FE_OVERFLOW   0x04
-#define FE_UNDERFLOW  0x08
-#define FE_INEXACT    0x10
-#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
-#define _FPSCR_ENABLE_SHIFT 8
-#define _FPSCR_ENABLE_MASK (FE_ALL_EXCEPT << _FPSCR_ENABLE_SHIFT)
-
-/* Rounding modes. */
-#define FE_TONEAREST  0x0
-#define FE_UPWARD     0x1
-#define FE_DOWNWARD   0x2
-#define FE_TOWARDZERO 0x3
-#define _FPSCR_RMODE_SHIFT 22
-
-#define FPCR_IOE    (1 << 8)
-#define FPCR_DZE    (1 << 9)
-#define FPCR_OFE    (1 << 10)
-#define FPCR_UFE    (1 << 11)
-#define FPCR_IXE    (1 << 12)
-#define FPCR_IDE    (1 << 15)
-#define FPCR_LEN    (7 << 16)
-#define FPCR_STRIDE (3 << 20)
-#define FPCR_RMODE  (3 << 22)
-#define FPCR_FZ     (1 << 24)
-#define FPCR_DN     (1 << 25)
-#define FPCR_AHP    (1 << 26)
-#define FPCR_MASK   (FPCR_IOE | \
-                     FPCR_DZE | \
-                     FPCR_OFE | \
-                     FPCR_UFE | \
-                     FPCR_IXE | \
-                     FPCR_IDE | \
-                     FPCR_LEN | \
-                     FPCR_STRIDE | \
-                     FPCR_RMODE | \
-                     FPCR_FZ | \
-                     FPCR_DN | \
-                     FPCR_AHP )
-
-#define FPSR_IOC    (1 << 0)
-#define FPSR_DZC    (1 << 1)
-#define FPSR_OFC    (1 << 2)
-#define FPSR_UFC    (1 << 3)
-#define FPSR_IXC    (1 << 4)
-#define FPSR_IDC    (1 << 7)
-#define FPSR_QC     (1 << 27)
-#define FPSR_V      (1 << 28)
-#define FPSR_C      (1 << 29)
-#define FPSR_Z      (1 << 30)
-#define FPSR_N      (1 << 31)
-#define FPSR_MASK   (FPSR_IOC | \
-                     FPSR_DZC | \
-                     FPSR_OFC | \
-                     FPSR_UFC | \
-                     FPSR_IXC | \
-                     FPSR_IDC | \
-                     FPSR_QC | \
-                     FPSR_V | \
-                     FPSR_C | \
-                     FPSR_Z | \
-                     FPSR_N )
-
-/* Default floating-point environment. */
-extern const fenv_t __fe_dfl_env;
-#define FE_DFL_ENV (&__fe_dfl_env)
-
-static __inline int fegetenv(fenv_t* __envp) {
-    fenv_t _fpcr, _fpsr;
-    __asm__ __volatile__("mrs %0,fpcr" : "=r" (_fpcr));
-    __asm__ __volatile__("mrs %0,fpsr" : "=r" (_fpsr));
-  *__envp = (_fpcr | _fpsr);
-  return 0;
-}
-
-static __inline int fesetenv(const fenv_t* __envp) {
-    fenv_t _fpcr = (*__envp & FPCR_MASK);
-    fenv_t _fpsr = (*__envp & FPSR_MASK);
-    __asm__ __volatile__("msr fpcr,%0" : :"ri" (_fpcr));
-    __asm__ __volatile__("msr fpsr,%0" : :"ri" (_fpsr));
-  return 0;
-}
-
-static __inline int feclearexcept(int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  __fpscr &= ~__excepts;
-  fesetenv(&__fpscr);
-  return 0;
-}
-
-static __inline int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  *__flagp = __fpscr & __excepts;
-  return 0;
-}
-
-static __inline int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  __fpscr &= ~__excepts;
-  __fpscr |= *__flagp & __excepts;
-  fesetenv(&__fpscr);
-  return 0;
-}
-
-static __inline int feraiseexcept(int __excepts) {
-  fexcept_t __ex = __excepts;
-  fesetexceptflag(&__ex, __excepts);
-  return 0;
-}
-
-static __inline int fetestexcept(int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  return (__fpscr & __excepts);
-}
-
-static __inline int fegetround(void) {
-  fenv_t _fpscr;
-  fegetenv(&_fpscr);
-  return ((_fpscr >> _FPSCR_RMODE_SHIFT) & 0x3);
-}
-
-static __inline int fesetround(int __round) {
-  fenv_t _fpscr;
-  fegetenv(&_fpscr);
-  _fpscr &= ~(0x3 << _FPSCR_RMODE_SHIFT);
-  _fpscr |= (__round << _FPSCR_RMODE_SHIFT);
-  fesetenv(&_fpscr);
-  return 0;
-}
-
-static __inline int feholdexcept(fenv_t* __envp) {
-  fenv_t __env;
-  fegetenv(&__env);
-  *__envp = __env;
-  __env &= ~(FE_ALL_EXCEPT | _FPSCR_ENABLE_MASK);
-  fesetenv(&__env);
-  return 0;
-}
-
-static __inline int feupdateenv(const fenv_t* __envp) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  fesetenv(__envp);
-  feraiseexcept(__fpscr & FE_ALL_EXCEPT);
-  return 0;
-}
-
-#if __BSD_VISIBLE
-
-static __inline int feenableexcept(int __mask) {
-  fenv_t __old_fpscr, __new_fpscr;
-  fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT;
-  fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fedisableexcept(int __mask) {
-  fenv_t __old_fpscr, __new_fpscr;
-  fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT);
-  fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fegetexcept(void) {
-  fenv_t __fpscr;
-  fegetenv(&__fpscr);
-  return ((__fpscr & _FPSCR_ENABLE_MASK) >> _FPSCR_ENABLE_SHIFT);
-}
-
-#endif /* __BSD_VISIBLE */
-
-__END_DECLS
-
-#endif /* !_FENV_H_ */
diff --git a/libm/include/arm64/machine/fenv.h b/libm/include/arm64/machine/fenv.h
new file mode 100644
index 0000000..a8568b8
--- /dev/null
+++ b/libm/include/arm64/machine/fenv.h
@@ -0,0 +1,102 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
+ */
+
+/*
+ * In ARMv8, AArch64 state, floating-point operation is controlled by:
+ *
+ *  * FPCR - 32Bit Floating-Point Control Register:
+ *      * [31:27] - Reserved, Res0;
+ *      * [26]    - AHP, Alternative half-precision control bit;
+ *      * [25]    - DN, Default NaN mode control bit;
+ *      * [24]    - FZ, Flush-to-zero mode control bit;
+ *      * [23:22] - RMode, Rounding Mode control field:
+ *            * 00  - Round to Nearest (RN) mode;
+ *            * 01  - Round towards Plus Infinity (RP) mode;
+ *            * 10  - Round towards Minus Infinity (RM) mode;
+ *            * 11  - Round towards Zero (RZ) mode.
+ *      * [21:20] - Stride, ignored during AArch64 execution;
+ *      * [19]    - Reserved, Res0;
+ *      * [18:16] - Len, ignored during AArch64 execution;
+ *      * [15]    - IDE, Input Denormal exception trap;
+ *      * [14:13] - Reserved, Res0;
+ *      * [12]    - IXE, Inexact exception trap;
+ *      * [11]    - UFE, Underflow exception trap;
+ *      * [10]    - OFE, Overflow exception trap;
+ *      * [9]     - DZE, Division by Zero exception;
+ *      * [8]     - IOE, Invalid Operation exception;
+ *      * [7:0]   - Reserved, Res0.
+ *
+ *  * FPSR - 32Bit Floating-Point Status Register:
+ *      * [31]    - N, Negative condition flag for AArch32 (AArch64 sets PSTATE.N);
+ *      * [30]    - Z, Zero condition flag for AArch32 (AArch64 sets PSTATE.Z);
+ *      * [29]    - C, Carry conditon flag for AArch32 (AArch64 sets PSTATE.C);
+ *      * [28]    - V, Overflow conditon flag for AArch32 (AArch64 sets PSTATE.V);
+ *      * [27]    - QC, Cumulative saturation bit, Advanced SIMD only;
+ *      * [26:8]  - Reserved, Res0;
+ *      * [7]     - IDC, Input Denormal cumulative exception;
+ *      * [6:5]   - Reserved, Res0;
+ *      * [4]     - IXC, Inexact cumulative exception;
+ *      * [3]     - UFC, Underflow cumulative exception;
+ *      * [2]     - OFC, Overflow cumulative exception;
+ *      * [1]     - DZC, Division by Zero cumulative exception;
+ *      * [0]     - IOC, Invalid Operation cumulative exception.
+ */
+
+#ifndef _ARM64_FENV_H_
+#define _ARM64_FENV_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+typedef struct {
+  __uint32_t __control;     /* FPCR, Floating-point Control Register */
+  __uint32_t __status;      /* FPSR, Floating-point Status Register */
+} fenv_t;
+
+typedef __uint32_t fexcept_t;
+
+/* Exception flags. */
+#define FE_INVALID    0x01
+#define FE_DIVBYZERO  0x02
+#define FE_OVERFLOW   0x04
+#define FE_UNDERFLOW  0x08
+#define FE_INEXACT    0x10
+#define FE_DENORMAL   0x80
+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
+                       FE_OVERFLOW | FE_UNDERFLOW | FE_DENORMAL)
+
+/* Rounding modes. */
+#define FE_TONEAREST  0x0
+#define FE_UPWARD     0x1
+#define FE_DOWNWARD   0x2
+#define FE_TOWARDZERO 0x3
+
+__END_DECLS
+
+#endif /* !_ARM64_FENV_H_ */
diff --git a/libm/include/fenv.h b/libm/include/fenv.h
new file mode 100644
index 0000000..73ecc80
--- /dev/null
+++ b/libm/include/fenv.h
@@ -0,0 +1,71 @@
+/*  $OpenBSD: fenv.h,v 1.2 2011/05/25 21:46:49 martynas Exp $ */
+/*  $NetBSD: fenv.h,v 1.2.4.1 2011/02/08 16:18:55 bouyer Exp $  */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _FENV_H_
+#define _FENV_H_
+
+#include <sys/cdefs.h>
+#include <machine/fenv.h>
+
+__BEGIN_DECLS
+#pragma GCC visibility push(default)
+
+int feclearexcept(int);
+int fegetexceptflag(fexcept_t *, int);
+int feraiseexcept(int);
+int fesetexceptflag(const fexcept_t *, int);
+int fetestexcept(int);
+
+int fegetround(void);
+int fesetround(int);
+
+int fegetenv(fenv_t *);
+int feholdexcept(fenv_t *);
+int fesetenv(const fenv_t *);
+int feupdateenv(const fenv_t *);
+
+int feenableexcept(int);
+int fedisableexcept(int);
+int fegetexcept(void);
+
+/*
+ * The following constant represents the default floating-point environment
+ * (that is, the one installed at program startup) and has type pointer to
+ * const-qualified fenv_t.
+ *
+ * It can be used as an argument to the functions that manage the floating-point
+ * environment, namely fesetenv() and feupdateenv().
+ */
+extern const fenv_t __fe_dfl_env;
+#define FE_DFL_ENV  (&__fe_dfl_env)
+
+#pragma GCC visibility pop
+__END_DECLS
+
+#endif  /* ! _FENV_H_ */
diff --git a/libm/include/i387/fenv.h b/libm/include/i387/fenv.h
deleted file mode 100644
index c0421c0..0000000
--- a/libm/include/i387/fenv.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/msun/i387/fenv.h,v 1.4 2005/03/17 22:21:46 das Exp $
- */
-
-#ifndef	_FENV_H_
-#define	_FENV_H_
-
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-/*                   
- * To preserve binary compatibility with FreeBSD 5.3, we pack the
- * mxcsr into some reserved fields, rather than changing sizeof(fenv_t).
- */
-typedef struct {
-	__uint16_t	__control;
-	__uint16_t      __mxcsr_hi;
-	__uint16_t	__status;
-	__uint16_t      __mxcsr_lo;
-	__uint32_t	__tag;
-	char		__other[16];
-} fenv_t;
-
-typedef	__uint16_t	fexcept_t;
-
-/* Exception flags */
-#define	FE_INVALID	0x01
-#define	FE_DENORMAL	0x02
-#define	FE_DIVBYZERO	0x04
-#define	FE_OVERFLOW	0x08
-#define	FE_UNDERFLOW	0x10
-#define	FE_INEXACT	0x20
-#define	FE_ALL_EXCEPT	(FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \
-			 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
-
-/* Rounding modes */
-#define	FE_TONEAREST	0x0000
-#define	FE_DOWNWARD	0x0400
-#define	FE_UPWARD	0x0800
-#define	FE_TOWARDZERO	0x0c00
-#define	_ROUND_MASK	(FE_TONEAREST | FE_DOWNWARD | \
-			 FE_UPWARD | FE_TOWARDZERO)
-
-/* Default floating-point environment */
-extern const fenv_t	__fe_dfl_env;
-#define	FE_DFL_ENV	(&__fe_dfl_env)
-
-/* C99 floating-point exception functions */
-int feclearexcept(int excepts);
-int fegetexceptflag(fexcept_t *flagp, int excepts);
-int fesetexceptflag(const fexcept_t *flagp, int excepts);
-/* feraiseexcept does not set the inexact flag on overflow/underflow */
-int feraiseexcept(int excepts);
-int fetestexcept(int excepts);
-
-/* C99 rounding control functions */
-int fegetround(void);
-int fesetround(int round);
-
-/* C99 floating-point environment functions */
-int fegetenv(fenv_t *__envp);
-int feholdexcept(fenv_t *__envp);
-int fesetenv(const fenv_t *envp);
-int feupdateenv(const fenv_t *__envp);
-
-#if __BSD_VISIBLE
-/* Additional support functions to set/query floating point traps */
-int feenableexcept(int __mask);
-int fedisableexcept(int __mask);
-int fegetexcept(void);
-
-#endif /* __BSD_VISIBLE */
-
-__END_DECLS
-
-#endif	/* !_FENV_H_ */
diff --git a/libm/include/i387/machine/fenv.h b/libm/include/i387/machine/fenv.h
new file mode 100644
index 0000000..de45add
--- /dev/null
+++ b/libm/include/i387/machine/fenv.h
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/msun/i387/fenv.h,v 1.4 2005/03/17 22:21:46 das Exp $
+ */
+
+#ifndef _I387_FENV_H_
+#define _I387_FENV_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+/*
+ * To preserve binary compatibility with FreeBSD 5.3, we pack the
+ * mxcsr into some reserved fields, rather than changing sizeof(fenv_t).
+ */
+typedef struct {
+  __uint16_t __control;
+  __uint16_t __mxcsr_hi;
+  __uint16_t __status;
+  __uint16_t __mxcsr_lo;
+  __uint32_t __tag;
+  char       __other[16];
+} fenv_t;
+
+typedef __uint16_t fexcept_t;
+
+/* Exception flags */
+#define FE_INVALID    0x01
+#define FE_DENORMAL   0x02
+#define FE_DIVBYZERO  0x04
+#define FE_OVERFLOW   0x08
+#define FE_UNDERFLOW  0x10
+#define FE_INEXACT    0x20
+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \
+                       FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
+
+/* Rounding modes */
+#define FE_TONEAREST  0x0000
+#define FE_DOWNWARD   0x0400
+#define FE_UPWARD     0x0800
+#define FE_TOWARDZERO 0x0c00
+
+__END_DECLS
+
+#endif /* !I387_FENV_H_ */
diff --git a/libm/include/math.h b/libm/include/math.h
index b13eca9..3eca140 100644
--- a/libm/include/math.h
+++ b/libm/include/math.h
@@ -18,9 +18,11 @@
 #define	_MATH_H_
 
 #include <sys/cdefs.h>
-#include <sys/_types.h>
 #include <limits.h>
 
+__BEGIN_DECLS
+#pragma GCC visibility push(default)
+
 /*
  * ANSI/POSIX
  */
@@ -34,11 +36,11 @@
 	float		__uf;
 } __nan;
 
-#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
+#if __GNUC_PREREQ(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
 #define	__MATH_BUILTIN_CONSTANTS
 #endif
 
-#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
+#if __GNUC_PREREQ(3, 0) && !defined(__INTEL_COMPILER)
 #define	__MATH_BUILTIN_RELOPS
 #endif
 
@@ -124,8 +126,10 @@
     : (sizeof (x) == sizeof (double)) ? __signbit(x)	\
     : __signbitl(x))
 
-typedef	__double_t	double_t;
-typedef	__float_t	float_t;
+typedef double __double_t;
+typedef __double_t double_t;
+typedef float __float_t;
+typedef __float_t float_t;
 #endif /* __ISO_C_VISIBLE >= 1999 */
 
 /*
@@ -164,7 +168,7 @@
  * effect of raising floating-point exceptions, so they are not declared
  * as __pure2.  In C99, FENV_ACCESS affects the purity of these functions.
  */
-__BEGIN_DECLS
+
 /*
  * ANSI/POSIX
  */
@@ -281,6 +285,7 @@
 double	drem(double, double);
 int	finite(double) __pure2;
 int	isnanf(float) __pure2;
+long double significandl(long double);
 
 /*
  * Reentrant version of gamma & lgamma; passes signgam back by reference
@@ -395,16 +400,23 @@
  * long double versions of ISO/POSIX math functions
  */
 #if __ISO_C_VISIBLE >= 1999
+long double	acoshl(long double);
 long double	acosl(long double);
+long double	asinhl(long double);
 long double	asinl(long double);
 long double	atan2l(long double, long double);
+long double	atanhl(long double);
 long double	atanl(long double);
 long double	cbrtl(long double);
 long double	ceill(long double);
 long double	copysignl(long double, long double) __pure2;
+long double	coshl(long double);
 long double	cosl(long double);
+long double	erfcl(long double);
+long double	erfl(long double);
 long double	exp2l(long double);
 long double	expl(long double);
+long double	expm1l(long double);
 long double	fabsl(long double) __pure2;
 long double	fdiml(long double, long double);
 long double	floorl(long double);
@@ -416,9 +428,14 @@
 long double	hypotl(long double, long double);
 int		ilogbl(long double) __pure2;
 long double	ldexpl(long double, int);
+long double	lgammal(long double);
 long long	llrintl(long double);
 long long	llroundl(long double);
+long double	log10l(long double);
+long double	log1pl(long double);
+long double	log2l(long double);
 long double	logbl(long double);
+long double	logl(long double);
 long		lrintl(long double);
 long		lroundl(long double);
 long double	modfl(long double, long double *); /* fundamentally !__pure2 */
@@ -428,53 +445,30 @@
 double		nexttoward(double, long double);
 float		nexttowardf(float, long double);
 long double	nexttowardl(long double, long double);
+long double	powl(long double, long double);
 long double	remainderl(long double, long double);
 long double	remquol(long double, long double, int *);
 long double	rintl(long double);
 long double	roundl(long double);
 long double	scalblnl(long double, long);
 long double	scalbnl(long double, int);
+long double	sinhl(long double);
 long double	sinl(long double);
 long double	sqrtl(long double);
+long double	tanhl(long double);
 long double	tanl(long double);
+long double	tgammal(long double);
 long double	truncl(long double);
 
 #endif /* __ISO_C_VISIBLE >= 1999 */
+
+#if defined(_GNU_SOURCE)
+void sincos(double, double*, double*);
+void sincosf(float, float*, float*);
+void sincosl(long double, long double*, long double*);
+#endif /* _GNU_SOURCE */
+
+#pragma GCC visibility pop
 __END_DECLS
 
 #endif /* !_MATH_H_ */
-
-/* separate header for cmath */
-#ifndef _MATH_EXTRA_H_
-#if __ISO_C_VISIBLE >= 1999
-#if _DECLARE_C99_LDBL_MATH
-
-#define _MATH_EXTRA_H_
-
-/*
- * extra long double versions of math functions for C99 and cmath
- */
-__BEGIN_DECLS
-
-long double	acoshl(long double);
-long double	asinhl(long double);
-long double	atanhl(long double);
-long double	coshl(long double);
-long double	erfcl(long double);
-long double	erfl(long double);
-long double	expm1l(long double);
-long double	lgammal(long double);
-long double	log10l(long double);
-long double	log1pl(long double);
-long double	log2l(long double);
-long double	logl(long double);
-long double	powl(long double, long double);
-long double	sinhl(long double);
-long double	tanhl(long double);
-long double	tgammal(long double);
-
-__END_DECLS
-
-#endif /* !_DECLARE_C99_LDBL_MATH */
-#endif /* __ISO_C_VISIBLE >= 1999 */
-#endif /* !_MATH_EXTRA_H_ */
diff --git a/libm/include/mips/fenv.h b/libm/include/mips/fenv.h
deleted file mode 100644
index ed69cf8..0000000
--- a/libm/include/mips/fenv.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
- */
-
-/*
-   Rewritten for Android.
-*/
-
-/* MIPS FPU floating point control register bits.
- *
- * 31-25  -> floating point conditions code bits set by FP compare
- *           instructions
- * 24     -> flush denormalized results to zero instead of
- *           causing unimplemented operation exception.
- * 23     -> Condition bit
- * 22     -> In conjunction with FS detects denormalized
- *           operands and replaces them internally with 0.
- * 21     -> In conjunction with FS forces denormalized operands
- *           to the closest normalized value.
- * 20-18  -> reserved (read as 0, write with 0)
- * 17     -> cause bit for unimplemented operation
- * 16     -> cause bit for invalid exception
- * 15     -> cause bit for division by zero exception
- * 14     -> cause bit for overflow exception
- * 13     -> cause bit for underflow exception
- * 12     -> cause bit for inexact exception
- * 11     -> enable exception for invalid exception
- * 10     -> enable exception for division by zero exception
- *  9     -> enable exception for overflow exception
- *  8     -> enable exception for underflow exception
- *  7     -> enable exception for inexact exception
- *  6     -> flag invalid exception
- *  5     -> flag division by zero exception
- *  4     -> flag overflow exception
- *  3     -> flag underflow exception
- *  2     -> flag inexact exception
- *  1-0   -> rounding control
- *
- *
- * Rounding Control:
- * 00 - rounding to nearest (RN)
- * 01 - rounding toward zero (RZ)
- * 10 - rounding (up) toward plus infinity (RP)
- * 11 - rounding (down)toward minus infinity (RM)
- */
-
-#ifndef _FENV_H_
-#define _FENV_H_
-
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-typedef __uint32_t    fenv_t;
-typedef __uint32_t    fexcept_t;
-
-/* Exception flags */
-#define FE_INVALID      0x40
-#define FE_DIVBYZERO    0x20
-#define FE_OVERFLOW     0x10
-#define FE_UNDERFLOW    0x08
-#define FE_INEXACT      0x04
-#define FE_ALL_EXCEPT   (FE_DIVBYZERO | FE_INEXACT | \
-                         FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
-#define _FCSR_CAUSE_SHIFT  10
-#define _ENABLE_SHIFT 5
-#define _FCSR_ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT)
-
-/* Rounding modes */
-#define FE_TONEAREST    0x0000
-#define FE_TOWARDZERO   0x0001
-#define FE_UPWARD       0x0002
-#define FE_DOWNWARD     0x0003
-#define _FCSR_RMODE_SHIFT 0
-#define _FCSR_RMASK       0x3
-/* Default floating-point environment */
-extern const fenv_t    __fe_dfl_env;
-#define FE_DFL_ENV    (&__fe_dfl_env)
-
-static __inline int fegetenv(fenv_t* __envp) {
-   fenv_t _fcsr = 0;
-#ifdef  __mips_hard_float
-   __asm__ __volatile__("cfc1 %0,$31" : "=r" (_fcsr));
-#endif
-   *__envp = _fcsr;
-   return 0;
-}
-
-static __inline int fesetenv(const fenv_t* __envp) {
-  fenv_t _fcsr = *__envp;
-#ifdef  __mips_hard_float
-  __asm__ __volatile__("ctc1 %0,$31" : : "r" (_fcsr));
-#endif
-  return 0;
-}
-
-static __inline int feclearexcept(int __excepts) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  __excepts &= FE_ALL_EXCEPT;
-  __fcsr &= ~(__excepts | (__excepts << _FCSR_CAUSE_SHIFT));
-  fesetenv(&__fcsr);
-  return 0;
-}
-
-static __inline int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  *__flagp = __fcsr & __excepts & FE_ALL_EXCEPT;
-  return 0;
-}
-
-static __inline int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  /* Ensure that flags are all legal */
-  __excepts &= FE_ALL_EXCEPT;
-  __fcsr &= ~__excepts;
-  __fcsr |= *__flagp & __excepts;
-  fesetenv(&__fcsr);
-  return 0;
-}
-
-static __inline int feraiseexcept(int __excepts) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  /* Ensure that flags are all legal */
-  __excepts &= FE_ALL_EXCEPT;
-  /* Cause bit needs to be set as well for generating the exception*/
-  __fcsr |= __excepts | (__excepts << _FCSR_CAUSE_SHIFT);
-  fesetenv(&__fcsr);
-  return 0;
-}
-
-static __inline int fetestexcept(int __excepts) {
-  fexcept_t __FCSR;
-  fegetenv(&__FCSR);
-  return (__FCSR & __excepts & FE_ALL_EXCEPT);
-}
-
-static __inline int fegetround(void) {
-  fenv_t _fcsr;
-  fegetenv(&_fcsr);
-  return (_fcsr & _FCSR_RMASK);
-}
-
-static __inline int fesetround(int __round) {
-  fenv_t _fcsr;
-  fegetenv(&_fcsr);
-  _fcsr &= ~_FCSR_RMASK;
-  _fcsr |= (__round & _FCSR_RMASK ) ;
-  fesetenv(&_fcsr);
-  return 0;
-}
-
-static __inline int feholdexcept(fenv_t* __envp) {
-  fenv_t __env;
-  fegetenv(&__env);
-  *__envp = __env;
-  __env &= ~(FE_ALL_EXCEPT | _FCSR_ENABLE_MASK);
-  fesetenv(&__env);
-  return 0;
-}
-
-static __inline int feupdateenv(const fenv_t* __envp) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  fesetenv(__envp);
-  feraiseexcept(__fcsr & FE_ALL_EXCEPT);
-  return 0;
-}
-
-#if __BSD_VISIBLE
-
-static __inline int feenableexcept(int __mask) {
-  fenv_t __old_fcsr, __new_fcsr;
-  fegetenv(&__old_fcsr);
-  __new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT;
-  fesetenv(&__new_fcsr);
-  return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fedisableexcept(int __mask) {
-  fenv_t __old_fcsr, __new_fcsr;
-  fegetenv(&__old_fcsr);
-  __new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT);
-  fesetenv(&__new_fcsr);
-  return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fegetexcept(void) {
-  fenv_t __fcsr;
-  fegetenv(&__fcsr);
-  return ((__fcsr & _FCSR_ENABLE_MASK) >> _ENABLE_SHIFT);
-}
-
-#endif /* __BSD_VISIBLE */
-
-__END_DECLS
-
-#endif /* !_FENV_H_ */
diff --git a/libm/include/mips/machine/fenv.h b/libm/include/mips/machine/fenv.h
new file mode 100644
index 0000000..689e1cb
--- /dev/null
+++ b/libm/include/mips/machine/fenv.h
@@ -0,0 +1,98 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
+ */
+
+/*
+   Rewritten for Android.
+*/
+
+/* MIPS FPU floating point control register bits.
+ *
+ * 31-25  -> floating point conditions code bits set by FP compare
+ *           instructions
+ * 24     -> flush denormalized results to zero instead of
+ *           causing unimplemented operation exception.
+ * 23     -> Condition bit
+ * 22     -> In conjunction with FS detects denormalized
+ *           operands and replaces them internally with 0.
+ * 21     -> In conjunction with FS forces denormalized operands
+ *           to the closest normalized value.
+ * 20-18  -> reserved (read as 0, write with 0)
+ * 17     -> cause bit for unimplemented operation
+ * 16     -> cause bit for invalid exception
+ * 15     -> cause bit for division by zero exception
+ * 14     -> cause bit for overflow exception
+ * 13     -> cause bit for underflow exception
+ * 12     -> cause bit for inexact exception
+ * 11     -> enable exception for invalid exception
+ * 10     -> enable exception for division by zero exception
+ *  9     -> enable exception for overflow exception
+ *  8     -> enable exception for underflow exception
+ *  7     -> enable exception for inexact exception
+ *  6     -> flag invalid exception
+ *  5     -> flag division by zero exception
+ *  4     -> flag overflow exception
+ *  3     -> flag underflow exception
+ *  2     -> flag inexact exception
+ *  1-0   -> rounding control
+ *
+ *
+ * Rounding Control:
+ * 00 - rounding to nearest (RN)
+ * 01 - rounding toward zero (RZ)
+ * 10 - rounding (up) toward plus infinity (RP)
+ * 11 - rounding (down)toward minus infinity (RM)
+ */
+
+#ifndef _MIPS_FENV_H_
+#define _MIPS_FENV_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+typedef __uint32_t fenv_t;
+typedef __uint32_t fexcept_t;
+
+/* Exception flags */
+#define FE_INVALID    0x40
+#define FE_DIVBYZERO  0x20
+#define FE_OVERFLOW   0x10
+#define FE_UNDERFLOW  0x08
+#define FE_INEXACT    0x04
+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
+                       FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
+
+/* Rounding modes */
+#define FE_TONEAREST  0x0000
+#define FE_TOWARDZERO 0x0001
+#define FE_UPWARD     0x0002
+#define FE_DOWNWARD   0x0003
+
+__END_DECLS
+
+#endif /* !_MIPS_FENV_H_ */
diff --git a/libm/isinf.c b/libm/isinf.c
deleted file mode 100644
index c917f16..0000000
--- a/libm/isinf.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <math.h>
-#include <sys/cdefs.h>
-#include "fpmath.h"
-
-/*
- * XXX These routines belong in libm, but they must remain in libc for
- *     binary compat until we can bump libm's major version number.
- */
-
-int
-__isinf(double d)
-{
-	union IEEEd2bits u;
-
-	u.d = d;
-	return (u.bits.exp == 2047 && u.bits.manl == 0 && u.bits.manh == 0);
-}
-
-int
-__isinff(float f)
-{
-	union IEEEf2bits u;
-
-	u.f = f;
-	return (u.bits.exp == 255 && u.bits.man == 0);
-}
-
-int
-__isinfl(long double e)
-{
-	union IEEEl2bits u;
-
-	u.e = e;
-	mask_nbit_l(u);
-#ifndef __alpha__
-	return (u.bits.exp == 32767 && u.bits.manl == 0 && u.bits.manh == 0);
-#else
-	return (u.bits.exp == 2047 && u.bits.manl == 0 && u.bits.manh == 0);
-#endif
-}
diff --git a/libm/mips/_fpmath.h b/libm/mips/_fpmath.h
deleted file mode 100644
index f006a58..0000000
--- a/libm/mips/_fpmath.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-union IEEEl2bits {
-	long double	e;
-	struct {
-#ifndef __MIPSEB__
-		unsigned int	manl	:32;
-		unsigned int	manh	:20;
-		unsigned int	exp	:11;
-		unsigned int	sign	:1;
-#else
-		unsigned int		sign	:1;
-		unsigned int		exp	:11;
-		unsigned int		manh	:20;
-		unsigned int		manl	:32;
-#endif
-	} bits;
-};
-
-#define	LDBL_NBIT	0
-#define	mask_nbit_l(u)	((void)0)
-#define	LDBL_IMPLICIT_NBIT
-
-#define	LDBL_MANH_SIZE	20
-#define	LDBL_MANL_SIZE	32
-
-#define	LDBL_TO_ARRAY32(u, a) do {			\
-	(a)[0] = (uint32_t)(u).bits.manl;		\
-	(a)[1] = (uint32_t)(u).bits.manh;		\
-} while(0)
diff --git a/libm/mips/fenv.c b/libm/mips/fenv.c
index b5f52da..aacd526 100644
--- a/libm/mips/fenv.c
+++ b/libm/mips/fenv.c
@@ -28,8 +28,129 @@
 
 #include <fenv.h>
 
+#define FCSR_CAUSE_SHIFT 10
+#define FCSR_ENABLE_SHIFT 5
+#define FCSR_ENABLE_MASK (FE_ALL_EXCEPT << FCSR_ENABLE_SHIFT)
+
+#define FCSR_RMASK       0x3
+
 /*
  * Hopefully the system ID byte is immutable, so it's valid to use
  * this as a default environment.
  */
 const fenv_t __fe_dfl_env = 0;
+
+int fegetenv(fenv_t* __envp) {
+  fenv_t _fcsr = 0;
+#ifdef  __mips_hard_float
+  __asm__ __volatile__("cfc1 %0,$31" : "=r" (_fcsr));
+#endif
+  *__envp = _fcsr;
+  return 0;
+}
+
+int fesetenv(const fenv_t* __envp) {
+  fenv_t _fcsr = *__envp;
+#ifdef  __mips_hard_float
+  __asm__ __volatile__("ctc1 %0,$31" : : "r" (_fcsr));
+#endif
+  return 0;
+}
+
+int feclearexcept(int __excepts) {
+  fexcept_t __fcsr;
+  fegetenv(&__fcsr);
+  __excepts &= FE_ALL_EXCEPT;
+  __fcsr &= ~(__excepts | (__excepts << FCSR_CAUSE_SHIFT));
+  fesetenv(&__fcsr);
+  return 0;
+}
+
+int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
+  fexcept_t __fcsr;
+  fegetenv(&__fcsr);
+  *__flagp = __fcsr & __excepts & FE_ALL_EXCEPT;
+  return 0;
+}
+
+int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
+  fexcept_t __fcsr;
+  fegetenv(&__fcsr);
+  /* Ensure that flags are all legal */
+  __excepts &= FE_ALL_EXCEPT;
+  __fcsr &= ~__excepts;
+  __fcsr |= *__flagp & __excepts;
+  fesetenv(&__fcsr);
+  return 0;
+}
+
+int feraiseexcept(int __excepts) {
+  fexcept_t __fcsr;
+  fegetenv(&__fcsr);
+  /* Ensure that flags are all legal */
+  __excepts &= FE_ALL_EXCEPT;
+  /* Cause bit needs to be set as well for generating the exception*/
+  __fcsr |= __excepts | (__excepts << FCSR_CAUSE_SHIFT);
+  fesetenv(&__fcsr);
+  return 0;
+}
+
+int fetestexcept(int __excepts) {
+  fexcept_t __FCSR;
+  fegetenv(&__FCSR);
+  return (__FCSR & __excepts & FE_ALL_EXCEPT);
+}
+
+int fegetround(void) {
+  fenv_t _fcsr;
+  fegetenv(&_fcsr);
+  return (_fcsr & FCSR_RMASK);
+}
+
+int fesetround(int __round) {
+  fenv_t _fcsr;
+  fegetenv(&_fcsr);
+  _fcsr &= ~FCSR_RMASK;
+  _fcsr |= (__round & FCSR_RMASK);
+  fesetenv(&_fcsr);
+  return 0;
+}
+
+int feholdexcept(fenv_t* __envp) {
+  fenv_t __env;
+  fegetenv(&__env);
+  *__envp = __env;
+  __env &= ~(FE_ALL_EXCEPT | FCSR_ENABLE_MASK);
+  fesetenv(&__env);
+  return 0;
+}
+
+int feupdateenv(const fenv_t* __envp) {
+  fexcept_t __fcsr;
+  fegetenv(&__fcsr);
+  fesetenv(__envp);
+  feraiseexcept(__fcsr & FE_ALL_EXCEPT);
+  return 0;
+}
+
+int feenableexcept(int __mask) {
+  fenv_t __old_fcsr, __new_fcsr;
+  fegetenv(&__old_fcsr);
+  __new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << FCSR_ENABLE_SHIFT;
+  fesetenv(&__new_fcsr);
+  return ((__old_fcsr >> FCSR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
+}
+
+int fedisableexcept(int __mask) {
+  fenv_t __old_fcsr, __new_fcsr;
+  fegetenv(&__old_fcsr);
+  __new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << FCSR_ENABLE_SHIFT);
+  fesetenv(&__new_fcsr);
+  return ((__old_fcsr >> FCSR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
+}
+
+int fegetexcept(void) {
+  fenv_t __fcsr;
+  fegetenv(&__fcsr);
+  return ((__fcsr & FCSR_ENABLE_MASK) >> FCSR_ENABLE_SHIFT);
+}
diff --git a/libm/signbit.c b/libm/signbit.c
new file mode 100644
index 0000000..b98bf45
--- /dev/null
+++ b/libm/signbit.c
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <math.h>
+
+#include "fpmath.h"
+
+int __signbit(double d)
+{
+  union IEEEd2bits u;
+
+  u.d = d;
+  return (u.bits.sign);
+}
+
+int __signbitf(float f)
+{
+  union IEEEf2bits u;
+
+  u.f = f;
+  return (u.bits.sign);
+}
+
+#ifdef __LP64__
+int __signbitl(long double e)
+{
+  union IEEEl2bits u;
+
+  u.e = e;
+  return (u.bits.sign);
+}
+#else // __LP32__
+__weak_reference(__signbit, __signbitl);
+#endif // __LP64__
diff --git a/libm/significandl.c b/libm/significandl.c
new file mode 100644
index 0000000..c5d7dd4
--- /dev/null
+++ b/libm/significandl.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <math.h>
+
+long double significandl(long double x) {
+  return scalbnl(x, -ilogbl(x));
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/e_rem_pio2l.h b/libm/upstream-freebsd/lib/msun/ld128/e_rem_pio2l.h
new file mode 100644
index 0000000..078d0c3
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/e_rem_pio2l.h
@@ -0,0 +1,140 @@
+/* From: @(#)e_rem_pio2.c 1.4 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ * Optimized by Bruce D. Evans.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* ld128 version of __ieee754_rem_pio2l(x,y)
+ *
+ * return the remainder of x rem pi/2 in y[0]+y[1]
+ * use __kernel_rem_pio2()
+ */
+
+#include <float.h>
+
+#include "math.h"
+#include "math_private.h"
+#include "fpmath.h"
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+
+/*
+ * XXX need to verify that nonzero integer multiples of pi/2 within the
+ * range get no closer to a long double than 2**-140, or that
+ * ilogb(x) + ilogb(min_delta) < 45 - -140.
+ */
+/*
+ * invpio2:  113 bits of 2/pi
+ * pio2_1:   first  68 bits of pi/2
+ * pio2_1t:  pi/2 - pio2_1
+ * pio2_2:   second 68 bits of pi/2
+ * pio2_2t:  pi/2 - (pio2_1+pio2_2)
+ * pio2_3:   third  68 bits of pi/2
+ * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
+ */
+
+static const double
+zero =  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
+two24 =  1.67772160000000000000e+07; /* 0x41700000, 0x00000000 */
+
+static const long double
+invpio2 =  6.3661977236758134307553505349005747e-01L,	/*  0x145f306dc9c882a53f84eafa3ea6a.0p-113 */
+pio2_1  =  1.5707963267948966192292994253909555e+00L,	/*  0x1921fb54442d18469800000000000.0p-112 */
+pio2_1t =  2.0222662487959507323996846200947577e-21L,	/*  0x13198a2e03707344a4093822299f3.0p-181 */
+pio2_2  =  2.0222662487959507323994779168837751e-21L,	/*  0x13198a2e03707344a400000000000.0p-181 */
+pio2_2t =  2.0670321098263988236496903051604844e-43L,	/*  0x127044533e63a0105df531d89cd91.0p-254 */
+pio2_3  =  2.0670321098263988236499468110329591e-43L,	/*  0x127044533e63a0105e00000000000.0p-254 */
+pio2_3t = -2.5650587247459238361625433492959285e-65L;	/* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */
+
+static inline __always_inline int
+__ieee754_rem_pio2l(long double x, long double *y)
+{
+	union IEEEl2bits u,u1;
+	long double z,w,t,r,fn;
+	double tx[5],ty[3];
+	int64_t n;
+	int e0,ex,i,j,nx;
+	int16_t expsign;
+
+	u.e = x;
+	expsign = u.xbits.expsign;
+	ex = expsign & 0x7fff;
+	if (ex < BIAS + 45 || ex == BIAS + 45 &&
+	    u.bits.manh < 0x921fb54442d1LL) {
+	    /* |x| ~< 2^45*(pi/2), medium size */
+	    /* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+	    fn = x*invpio2+0x1.8p112;
+	    fn = fn-0x1.8p112;
+#ifdef HAVE_EFFICIENT_I64RINT
+	    n  = i64rint(fn);
+#else
+	    n  = fn;
+#endif
+	    r  = x-fn*pio2_1;
+	    w  = fn*pio2_1t;	/* 1st round good to 180 bit */
+	    {
+		union IEEEl2bits u2;
+	        int ex1;
+	        j  = ex;
+	        y[0] = r-w;
+		u2.e = y[0];
+		ex1 = u2.xbits.expsign & 0x7fff;
+	        i = j-ex1;
+	        if(i>51) {  /* 2nd iteration needed, good to 248 */
+		    t  = r;
+		    w  = fn*pio2_2;
+		    r  = t-w;
+		    w  = fn*pio2_2t-((t-r)-w);
+		    y[0] = r-w;
+		    u2.e = y[0];
+		    ex1 = u2.xbits.expsign & 0x7fff;
+		    i = j-ex1;
+		    if(i>119) {	/* 3rd iteration need, 316 bits acc */
+		    	t  = r;	/* will cover all possible cases */
+		    	w  = fn*pio2_3;
+		    	r  = t-w;
+		    	w  = fn*pio2_3t-((t-r)-w);
+		    	y[0] = r-w;
+		    }
+		}
+	    }
+	    y[1] = (r-y[0])-w;
+	    return n;
+	}
+    /*
+     * all other (large) arguments
+     */
+	if(ex==0x7fff) {		/* x is inf or NaN */
+	    y[0]=y[1]=x-x; return 0;
+	}
+    /* set z = scalbn(|x|,ilogb(x)-23) */
+	u1.e = x;
+	e0 = ex - BIAS - 23;		/* e0 = ilogb(|x|)-23; */
+	u1.xbits.expsign = ex - e0;
+	z = u1.e;
+	for(i=0;i<4;i++) {
+		tx[i] = (double)((int32_t)(z));
+		z     = (z-tx[i])*two24;
+	}
+	tx[4] = z;
+	nx = 5;
+	while(tx[nx-1]==zero) nx--;	/* skip zero term */
+	n  =  __kernel_rem_pio2(tx,ty,e0,nx,3);
+	t = (long double)ty[2] + ty[1];
+	r = t + ty[0];
+	w = ty[0] - (r - t);
+	if(expsign<0) {y[0] = -r; y[1] = -w; return -n;}
+	y[0] = r; y[1] = w; return n;
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/invtrig.c b/libm/upstream-freebsd/lib/msun/ld128/invtrig.c
new file mode 100644
index 0000000..df67d16
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/invtrig.c
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "invtrig.h"
+
+/*
+ * asinl() and acosl()
+ */
+const long double
+pS0 =  1.66666666666666666666666666666700314e-01L,
+pS1 = -7.32816946414566252574527475428622708e-01L,
+pS2 =  1.34215708714992334609030036562143589e+00L,
+pS3 = -1.32483151677116409805070261790752040e+00L,
+pS4 =  7.61206183613632558824485341162121989e-01L,
+pS5 = -2.56165783329023486777386833928147375e-01L,
+pS6 =  4.80718586374448793411019434585413855e-02L,
+pS7 = -4.42523267167024279410230886239774718e-03L,
+pS8 =  1.44551535183911458253205638280410064e-04L,
+pS9 = -2.10558957916600254061591040482706179e-07L,
+qS1 = -4.84690167848739751544716485245697428e+00L,
+qS2 =  9.96619113536172610135016921140206980e+00L,
+qS3 = -1.13177895428973036660836798461641458e+01L,
+qS4 =  7.74004374389488266169304117714658761e+00L,
+qS5 = -3.25871986053534084709023539900339905e+00L,
+qS6 =  8.27830318881232209752469022352928864e-01L,
+qS7 = -1.18768052702942805423330715206348004e-01L,
+qS8 =  8.32600764660522313269101537926539470e-03L,
+qS9 = -1.99407384882605586705979504567947007e-04L;
+
+/*
+ * atanl()
+ */
+const long double atanhi[] = {
+	 4.63647609000806116214256231461214397e-01L,
+	 7.85398163397448309615660845819875699e-01L,
+	 9.82793723247329067985710611014666038e-01L,
+	 1.57079632679489661923132169163975140e+00L,
+};
+
+const long double atanlo[] = {
+	 4.89509642257333492668618435220297706e-36L,
+	 2.16795253253094525619926100651083806e-35L,
+	-2.31288434538183565909319952098066272e-35L,
+	 4.33590506506189051239852201302167613e-35L,
+};
+
+const long double aT[] = {
+	 3.33333333333333333333333333333333125e-01L,
+	-1.99999999999999999999999999999180430e-01L,
+	 1.42857142857142857142857142125269827e-01L,
+	-1.11111111111111111111110834490810169e-01L,
+	 9.09090909090909090908522355708623681e-02L,
+	-7.69230769230769230696553844935357021e-02L,
+	 6.66666666666666660390096773046256096e-02L,
+	-5.88235294117646671706582985209643694e-02L,
+	 5.26315789473666478515847092020327506e-02L,
+	-4.76190476189855517021024424991436144e-02L,
+	 4.34782608678695085948531993458097026e-02L,
+	-3.99999999632663469330634215991142368e-02L,
+	 3.70370363987423702891250829918659723e-02L,
+	-3.44827496515048090726669907612335954e-02L,
+	 3.22579620681420149871973710852268528e-02L,
+	-3.03020767654269261041647570626778067e-02L,
+	 2.85641979882534783223403715930946138e-02L,
+	-2.69824879726738568189929461383741323e-02L,
+	 2.54194698498808542954187110873675769e-02L,
+	-2.35083879708189059926183138130183215e-02L,
+	 2.04832358998165364349957325067131428e-02L,
+	-1.54489555488544397858507248612362957e-02L,
+	 8.64492360989278761493037861575248038e-03L,
+	-2.58521121597609872727919154569765469e-03L,
+};
+
+const long double pi_lo = 8.67181013012378102479704402604335225e-35L;
diff --git a/libm/upstream-freebsd/lib/msun/ld128/invtrig.h b/libm/upstream-freebsd/lib/msun/ld128/invtrig.h
new file mode 100644
index 0000000..12f598b
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/invtrig.h
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <float.h>
+
+#include "fpmath.h"
+
+#define	BIAS		(LDBL_MAX_EXP - 1)
+#define	MANH_SIZE	(LDBL_MANH_SIZE + 1)
+
+/* Approximation thresholds. */
+#define	ASIN_LINEAR	(BIAS - 56)	/* 2**-56 */
+#define	ACOS_CONST	(BIAS - 113)	/* 2**-113 */
+#define	ATAN_CONST	(BIAS + 113)	/* 2**113 */
+#define	ATAN_LINEAR	(BIAS - 56)	/* 2**-56 */
+
+/* 0.95 */
+#define	THRESH	((0xe666666666666666ULL>>(64-(MANH_SIZE-1)))|LDBL_NBIT)
+
+/* Constants shared by the long double inverse trig functions. */
+#define	pS0	_ItL_pS0
+#define	pS1	_ItL_pS1
+#define	pS2	_ItL_pS2
+#define	pS3	_ItL_pS3
+#define	pS4	_ItL_pS4
+#define	pS5	_ItL_pS5
+#define	pS6	_ItL_pS6
+#define	pS7	_ItL_pS7
+#define	pS8	_ItL_pS8
+#define	pS9	_ItL_pS9
+#define	qS1	_ItL_qS1
+#define	qS2	_ItL_qS2
+#define	qS3	_ItL_qS3
+#define	qS4	_ItL_qS4
+#define	qS5	_ItL_qS5
+#define	qS6	_ItL_qS6
+#define	qS7	_ItL_qS7
+#define	qS8	_ItL_qS8
+#define	qS9	_ItL_qS9
+#define	atanhi	_ItL_atanhi
+#define	atanlo	_ItL_atanlo
+#define	aT	_ItL_aT
+#define	pi_lo	_ItL_pi_lo
+
+#define	pio2_hi	atanhi[3]
+#define	pio2_lo	atanlo[3]
+#define	pio4_hi	atanhi[1]
+
+/* Constants shared by the long double inverse trig functions. */
+extern const long double pS0, pS1, pS2, pS3, pS4, pS5, pS6, pS7, pS8, pS9;
+extern const long double qS1, qS2, qS3, qS4, qS5, qS6, qS7, qS8, qS9;
+extern const long double atanhi[], atanlo[], aT[];
+extern const long double pi_lo;
+
+static inline long double
+P(long double x)
+{
+
+	return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \
+		(pS4 + x * (pS5 + x * (pS6 + x * (pS7 + x * (pS8 + x * \
+		pS9))))))))));
+}
+
+static inline long double
+Q(long double x)
+{
+
+	return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * \
+		(qS5 + x * (qS6 + x * (qS7 + x * (qS8 + x * qS9)))))))));
+}
+
+static inline long double
+T_even(long double x)
+{
+
+	return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * \
+		(aT[8] + x * (aT[10] + x * (aT[12] + x * (aT[14] + x * \
+		(aT[16] + x * (aT[18] + x * (aT[20] + x * aT[22])))))))))));
+}
+
+static inline long double
+T_odd(long double x)
+{
+
+	return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * \
+		(aT[9] + x * (aT[11] + x * (aT[13] + x * (aT[15] + x * \
+		(aT[17] + x * (aT[19] + x * (aT[21] + x * aT[23])))))))))));
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/k_cosl.c b/libm/upstream-freebsd/lib/msun/ld128/k_cosl.c
new file mode 100644
index 0000000..5f4aa37
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/k_cosl.c
@@ -0,0 +1,61 @@
+/* From: @(#)k_cos.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * ld128 version of k_cos.c.  See ../src/k_cos.c for most comments.
+ */
+
+#include "math_private.h"
+
+/*
+ * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]:
+ * |cos(x) - c(x))| < 2**-122.0
+ *
+ * 113-bit precision requires more care than 64-bit precision, since
+ * simple methods give a minimax polynomial with coefficient for x^2
+ * that is 1 ulp below 0.5, but we want it to be precisely 0.5.  See
+ * ../ld80/k_cosl.c for more details.
+ */
+static const double
+one = 1.0;
+
+static const long double
+C1 =  0.04166666666666666666666666666666658424671L,
+C2 = -0.001388888888888888888888888888863490893732L,
+C3 =  0.00002480158730158730158730158600795304914210L,
+C4 = -0.2755731922398589065255474947078934284324e-6L,
+C5 =  0.2087675698786809897659225313136400793948e-8L,
+C6 = -0.1147074559772972315817149986812031204775e-10L,
+C7 =  0.4779477332386808976875457937252120293400e-13L;
+
+static const double
+C8 = -0.1561920696721507929516718307820958119868e-15,
+C9 =  0.4110317413744594971475941557607804508039e-18,
+C10 = -0.8896592467191938803288521958313920156409e-21,
+C11 =  0.1601061435794535138244346256065192782581e-23;
+
+long double
+__kernel_cosl(long double x, long double y)
+{
+	long double hz,z,r,w;
+
+	z  = x*x;
+	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+
+	    z*(C8+z*(C9+z*(C10+z*C11))))))))));
+	hz = 0.5*z;
+	w  = one-hz;
+	return w + (((one-w)-hz) + (z*r-x*y));
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/k_sinl.c b/libm/upstream-freebsd/lib/msun/ld128/k_sinl.c
new file mode 100644
index 0000000..bd415c0
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/k_sinl.c
@@ -0,0 +1,59 @@
+/* From: @(#)k_sin.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * ld128 version of k_sin.c.  See ../src/k_sin.c for most comments.
+ */
+
+#include "math_private.h"
+
+static const double
+half =  0.5;
+
+/*
+ * Domain [-0.7854, 0.7854], range ~[-1.53e-37, 1.659e-37]
+ * |sin(x)/x - s(x)| < 2**-122.1
+ *
+ * See ../ld80/k_cosl.c for more details about the polynomial.
+ */
+static const long double
+S1 = -0.16666666666666666666666666666666666606732416116558L,
+S2 =  0.0083333333333333333333333333333331135404851288270047L,
+S3 = -0.00019841269841269841269841269839935785325638310428717L,
+S4 =  0.27557319223985890652557316053039946268333231205686e-5L,
+S5 = -0.25052108385441718775048214826384312253862930064745e-7L,
+S6 =  0.16059043836821614596571832194524392581082444805729e-9L,
+S7 = -0.76471637318198151807063387954939213287488216303768e-12L,
+S8 =  0.28114572543451292625024967174638477283187397621303e-14L;
+
+static const double
+S9  = -0.82206352458348947812512122163446202498005154296863e-17,
+S10 =  0.19572940011906109418080609928334380560135358385256e-19,
+S11 = -0.38680813379701966970673724299207480965452616911420e-22,
+S12 =  0.64038150078671872796678569586315881020659912139412e-25;
+
+long double
+__kernel_sinl(long double x, long double y, int iy)
+{
+	long double z,r,v;
+
+	z	=  x*x;
+	v	=  z*x;
+	r	=  S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*(S8+
+	    z*(S9+z*(S10+z*(S11+z*S12)))))))));
+	if(iy==0) return x+v*(S1+z*r);
+	else      return x-((z*(half*y-v*r)-y)-v*S1);
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/k_tanl.c b/libm/upstream-freebsd/lib/msun/ld128/k_tanl.c
new file mode 100644
index 0000000..d7ec0b9
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/k_tanl.c
@@ -0,0 +1,119 @@
+/* From: @(#)k_tan.c 1.5 04/04/22 SMI */
+
+/*
+ * ====================================================
+ * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * ld128 version of k_tan.c.  See ../src/k_tan.c for most comments.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+/*
+ * Domain [-0.67434, 0.67434], range ~[-3.37e-36, 1.982e-37]
+ * |tan(x)/x - t(x)| < 2**-117.8 (XXX should be ~1e-37)
+ *
+ * See ../ld80/k_cosl.c for more details about the polynomial.
+ */
+static const long double
+T3 = 0x1.5555555555555555555555555553p-2L,
+T5 = 0x1.1111111111111111111111111eb5p-3L,
+T7 = 0x1.ba1ba1ba1ba1ba1ba1ba1b694cd6p-5L,
+T9 = 0x1.664f4882c10f9f32d6bbe09d8bcdp-6L,
+T11 = 0x1.226e355e6c23c8f5b4f5762322eep-7L,
+T13 = 0x1.d6d3d0e157ddfb5fed8e84e27b37p-9L,
+T15 = 0x1.7da36452b75e2b5fce9ee7c2c92ep-10L,
+T17 = 0x1.355824803674477dfcf726649efep-11L,
+T19 = 0x1.f57d7734d1656e0aceb716f614c2p-13L,
+T21 = 0x1.967e18afcb180ed942dfdc518d6cp-14L,
+T23 = 0x1.497d8eea21e95bc7e2aa79b9f2cdp-15L,
+T25 = 0x1.0b132d39f055c81be49eff7afd50p-16L,
+T27 = 0x1.b0f72d33eff7bfa2fbc1059d90b6p-18L,
+T29 = 0x1.5ef2daf21d1113df38d0fbc00267p-19L,
+T31 = 0x1.1c77d6eac0234988cdaa04c96626p-20L,
+T33 = 0x1.cd2a5a292b180e0bdd701057dfe3p-22L,
+T35 = 0x1.75c7357d0298c01a31d0a6f7d518p-23L,
+T37 = 0x1.2f3190f4718a9a520f98f50081fcp-24L,
+pio4 = 0x1.921fb54442d18469898cc51701b8p-1L,
+pio4lo = 0x1.cd129024e088a67cc74020bbea60p-116L;
+
+static const double
+T39 =  0.000000028443389121318352,	/*  0x1e8a7592977938.0p-78 */
+T41 =  0.000000011981013102001973,	/*  0x19baa1b1223219.0p-79 */
+T43 =  0.0000000038303578044958070,	/*  0x107385dfb24529.0p-80 */
+T45 =  0.0000000034664378216909893,	/*  0x1dc6c702a05262.0p-81 */
+T47 = -0.0000000015090641701997785,	/* -0x19ecef3569ebb6.0p-82 */
+T49 =  0.0000000029449552300483952,	/*  0x194c0668da786a.0p-81 */
+T51 = -0.0000000022006995706097711,	/* -0x12e763b8845268.0p-81 */
+T53 =  0.0000000015468200913196612,	/*  0x1a92fc98c29554.0p-82 */
+T55 = -0.00000000061311613386849674,	/* -0x151106cbc779a9.0p-83 */
+T57 =  1.4912469681508012e-10;		/*  0x147edbdba6f43a.0p-85 */
+
+long double
+__kernel_tanl(long double x, long double y, int iy) {
+	long double z, r, v, w, s;
+	long double osign;
+	int i;
+
+	iy = (iy == 1 ? -1 : 1);	/* XXX recover original interface */
+	osign = (x >= 0 ? 1.0 : -1.0);	/* XXX slow, probably wrong for -0 */
+	if (fabsl(x) >= 0.67434) {
+		if (x < 0) {
+			x = -x;
+			y = -y;
+		}
+		z = pio4 - x;
+		w = pio4lo - y;
+		x = z + w;
+		y = 0.0;
+		i = 1;
+	} else
+		i = 0;
+	z = x * x;
+	w = z * z;
+	r = T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 +
+	    w * (T25 + w * (T29 + w * (T33 +
+	    w * (T37 + w * (T41 + w * (T45 + w * (T49 + w * (T53 +
+	    w * T57))))))))))));
+	v = z * (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 +
+	    w * (T27 + w * (T31 + w * (T35 +
+	    w * (T39 + w * (T43 + w * (T47 + w * (T51 + w * T55))))))))))));
+	s = z * x;
+	r = y + z * (s * (r + v) + y);
+	r += T3 * s;
+	w = x + r;
+	if (i == 1) {
+		v = (long double) iy;
+		return osign *
+			(v - 2.0 * (x - (w * w / (w + v) - r)));
+	}
+	if (iy == 1)
+		return w;
+	else {
+		/*
+		 * if allow error up to 2 ulp, simply return
+		 * -1.0 / (x+r) here
+		 */
+		/* compute -1.0 / (x+r) accurately */
+		long double a, t;
+		z = w;
+		z = z + 0x1p32 - 0x1p32;
+		v = r - (z - x);	/* z+v = r+x */
+		t = a = -1.0 / w;	/* a = -1.0/w */
+		t = t + 0x1p32 - 0x1p32;
+		s = 1.0 + t * z;
+		return t + a * (s + t * v);
+	}
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c b/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c
new file mode 100644
index 0000000..5ed514c
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c
@@ -0,0 +1,427 @@
+/*-
+ * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+#include <stdint.h>
+
+#include "fpmath.h"
+#include "math.h"
+
+#define	TBLBITS	7
+#define	TBLSIZE	(1 << TBLBITS)
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+#define	EXPMASK	(BIAS + LDBL_MAX_EXP)
+
+static volatile long double
+    huge      = 0x1p10000L,
+    twom10000 = 0x1p-10000L;
+
+static const long double
+    P1        = 0x1.62e42fefa39ef35793c7673007e6p-1L,
+    P2	      = 0x1.ebfbdff82c58ea86f16b06ec9736p-3L,
+    P3        = 0x1.c6b08d704a0bf8b33a762bad3459p-5L,
+    P4        = 0x1.3b2ab6fba4e7729ccbbe0b4f3fc2p-7L,
+    P5        = 0x1.5d87fe78a67311071dee13fd11d9p-10L,
+    P6        = 0x1.430912f86c7876f4b663b23c5fe5p-13L;
+
+static const double
+    P7        = 0x1.ffcbfc588b041p-17,
+    P8        = 0x1.62c0223a5c7c7p-20,
+    P9        = 0x1.b52541ff59713p-24,
+    P10       = 0x1.e4cf56a391e22p-28,
+    redux     = 0x1.8p112 / TBLSIZE;
+
+static const long double tbl[TBLSIZE] = {
+	0x1.6a09e667f3bcc908b2fb1366dfeap-1L,
+	0x1.6c012750bdabeed76a99800f4edep-1L,
+	0x1.6dfb23c651a2ef220e2cbe1bc0d4p-1L,
+	0x1.6ff7df9519483cf87e1b4f3e1e98p-1L,
+	0x1.71f75e8ec5f73dd2370f2ef0b148p-1L,
+	0x1.73f9a48a58173bd5c9a4e68ab074p-1L,
+	0x1.75feb564267c8bf6e9aa33a489a8p-1L,
+	0x1.780694fde5d3f619ae02808592a4p-1L,
+	0x1.7a11473eb0186d7d51023f6ccb1ap-1L,
+	0x1.7c1ed0130c1327c49334459378dep-1L,
+	0x1.7e2f336cf4e62105d02ba1579756p-1L,
+	0x1.80427543e1a11b60de67649a3842p-1L,
+	0x1.82589994cce128acf88afab34928p-1L,
+	0x1.8471a4623c7acce52f6b97c6444cp-1L,
+	0x1.868d99b4492ec80e41d90ac2556ap-1L,
+	0x1.88ac7d98a669966530bcdf2d4cc0p-1L,
+	0x1.8ace5422aa0db5ba7c55a192c648p-1L,
+	0x1.8cf3216b5448bef2aa1cd161c57ap-1L,
+	0x1.8f1ae991577362b982745c72eddap-1L,
+	0x1.9145b0b91ffc588a61b469f6b6a0p-1L,
+	0x1.93737b0cdc5e4f4501c3f2540ae8p-1L,
+	0x1.95a44cbc8520ee9b483695a0e7fep-1L,
+	0x1.97d829fde4e4f8b9e920f91e8eb6p-1L,
+	0x1.9a0f170ca07b9ba3109b8c467844p-1L,
+	0x1.9c49182a3f0901c7c46b071f28dep-1L,
+	0x1.9e86319e323231824ca78e64c462p-1L,
+	0x1.a0c667b5de564b29ada8b8cabbacp-1L,
+	0x1.a309bec4a2d3358c171f770db1f4p-1L,
+	0x1.a5503b23e255c8b424491caf88ccp-1L,
+	0x1.a799e1330b3586f2dfb2b158f31ep-1L,
+	0x1.a9e6b5579fdbf43eb243bdff53a2p-1L,
+	0x1.ac36bbfd3f379c0db966a3126988p-1L,
+	0x1.ae89f995ad3ad5e8734d17731c80p-1L,
+	0x1.b0e07298db66590842acdfc6fb4ep-1L,
+	0x1.b33a2b84f15faf6bfd0e7bd941b0p-1L,
+	0x1.b59728de559398e3881111648738p-1L,
+	0x1.b7f76f2fb5e46eaa7b081ab53ff6p-1L,
+	0x1.ba5b030a10649840cb3c6af5b74cp-1L,
+	0x1.bcc1e904bc1d2247ba0f45b3d06cp-1L,
+	0x1.bf2c25bd71e088408d7025190cd0p-1L,
+	0x1.c199bdd85529c2220cb12a0916bap-1L,
+	0x1.c40ab5fffd07a6d14df820f17deap-1L,
+	0x1.c67f12e57d14b4a2137fd20f2a26p-1L,
+	0x1.c8f6d9406e7b511acbc48805c3f6p-1L,
+	0x1.cb720dcef90691503cbd1e949d0ap-1L,
+	0x1.cdf0b555dc3f9c44f8958fac4f12p-1L,
+	0x1.d072d4a07897b8d0f22f21a13792p-1L,
+	0x1.d2f87080d89f18ade123989ea50ep-1L,
+	0x1.d5818dcfba48725da05aeb66dff8p-1L,
+	0x1.d80e316c98397bb84f9d048807a0p-1L,
+	0x1.da9e603db3285708c01a5b6d480cp-1L,
+	0x1.dd321f301b4604b695de3c0630c0p-1L,
+	0x1.dfc97337b9b5eb968cac39ed284cp-1L,
+	0x1.e264614f5a128a12761fa17adc74p-1L,
+	0x1.e502ee78b3ff6273d130153992d0p-1L,
+	0x1.e7a51fbc74c834b548b2832378a4p-1L,
+	0x1.ea4afa2a490d9858f73a18f5dab4p-1L,
+	0x1.ecf482d8e67f08db0312fb949d50p-1L,
+	0x1.efa1bee615a27771fd21a92dabb6p-1L,
+	0x1.f252b376bba974e8696fc3638f24p-1L,
+	0x1.f50765b6e4540674f84b762861a6p-1L,
+	0x1.f7bfdad9cbe138913b4bfe72bd78p-1L,
+	0x1.fa7c1819e90d82e90a7e74b26360p-1L,
+	0x1.fd3c22b8f71f10975ba4b32bd006p-1L,
+	0x1.0000000000000000000000000000p+0L,
+	0x1.0163da9fb33356d84a66ae336e98p+0L,
+	0x1.02c9a3e778060ee6f7caca4f7a18p+0L,
+	0x1.04315e86e7f84bd738f9a20da442p+0L,
+	0x1.059b0d31585743ae7c548eb68c6ap+0L,
+	0x1.0706b29ddf6ddc6dc403a9d87b1ep+0L,
+	0x1.0874518759bc808c35f25d942856p+0L,
+	0x1.09e3ecac6f3834521e060c584d5cp+0L,
+	0x1.0b5586cf9890f6298b92b7184200p+0L,
+	0x1.0cc922b7247f7407b705b893dbdep+0L,
+	0x1.0e3ec32d3d1a2020742e4f8af794p+0L,
+	0x1.0fb66affed31af232091dd8a169ep+0L,
+	0x1.11301d0125b50a4ebbf1aed9321cp+0L,
+	0x1.12abdc06c31cbfb92bad324d6f84p+0L,
+	0x1.1429aaea92ddfb34101943b2588ep+0L,
+	0x1.15a98c8a58e512480d573dd562aep+0L,
+	0x1.172b83c7d517adcdf7c8c50eb162p+0L,
+	0x1.18af9388c8de9bbbf70b9a3c269cp+0L,
+	0x1.1a35beb6fcb753cb698f692d2038p+0L,
+	0x1.1bbe084045cd39ab1e72b442810ep+0L,
+	0x1.1d4873168b9aa7805b8028990be8p+0L,
+	0x1.1ed5022fcd91cb8819ff61121fbep+0L,
+	0x1.2063b88628cd63b8eeb0295093f6p+0L,
+	0x1.21f49917ddc962552fd29294bc20p+0L,
+	0x1.2387a6e75623866c1fadb1c159c0p+0L,
+	0x1.251ce4fb2a63f3582ab7de9e9562p+0L,
+	0x1.26b4565e27cdd257a673281d3068p+0L,
+	0x1.284dfe1f5638096cf15cf03c9fa0p+0L,
+	0x1.29e9df51fdee12c25d15f5a25022p+0L,
+	0x1.2b87fd0dad98ffddea46538fca24p+0L,
+	0x1.2d285a6e4030b40091d536d0733ep+0L,
+	0x1.2ecafa93e2f5611ca0f45d5239a4p+0L,
+	0x1.306fe0a31b7152de8d5a463063bep+0L,
+	0x1.32170fc4cd8313539cf1c3009330p+0L,
+	0x1.33c08b26416ff4c9c8610d96680ep+0L,
+	0x1.356c55f929ff0c94623476373be4p+0L,
+	0x1.371a7373aa9caa7145502f45452ap+0L,
+	0x1.38cae6d05d86585a9cb0d9bed530p+0L,
+	0x1.3a7db34e59ff6ea1bc9299e0a1fep+0L,
+	0x1.3c32dc313a8e484001f228b58cf0p+0L,
+	0x1.3dea64c12342235b41223e13d7eep+0L,
+	0x1.3fa4504ac801ba0bf701aa417b9cp+0L,
+	0x1.4160a21f72e29f84325b8f3dbacap+0L,
+	0x1.431f5d950a896dc704439410b628p+0L,
+	0x1.44e086061892d03136f409df0724p+0L,
+	0x1.46a41ed1d005772512f459229f0ap+0L,
+	0x1.486a2b5c13cd013c1a3b69062f26p+0L,
+	0x1.4a32af0d7d3de672d8bcf46f99b4p+0L,
+	0x1.4bfdad5362a271d4397afec42e36p+0L,
+	0x1.4dcb299fddd0d63b36ef1a9e19dep+0L,
+	0x1.4f9b2769d2ca6ad33d8b69aa0b8cp+0L,
+	0x1.516daa2cf6641c112f52c84d6066p+0L,
+	0x1.5342b569d4f81df0a83c49d86bf4p+0L,
+	0x1.551a4ca5d920ec52ec620243540cp+0L,
+	0x1.56f4736b527da66ecb004764e61ep+0L,
+	0x1.58d12d497c7fd252bc2b7343d554p+0L,
+	0x1.5ab07dd48542958c93015191e9a8p+0L,
+	0x1.5c9268a5946b701c4b1b81697ed4p+0L,
+	0x1.5e76f15ad21486e9be4c20399d12p+0L,
+	0x1.605e1b976dc08b076f592a487066p+0L,
+	0x1.6247eb03a5584b1f0fa06fd2d9eap+0L,
+	0x1.6434634ccc31fc76f8714c4ee122p+0L,
+	0x1.66238825522249127d9e29b92ea2p+0L,
+	0x1.68155d44ca973081c57227b9f69ep+0L,
+};
+
+static const float eps[TBLSIZE] = {
+	-0x1.5c50p-101,
+	-0x1.5d00p-106,
+	 0x1.8e90p-102,
+	-0x1.5340p-103,
+	 0x1.1bd0p-102,
+	-0x1.4600p-105,
+	-0x1.7a40p-104,
+	 0x1.d590p-102,
+	-0x1.d590p-101,
+	 0x1.b100p-103,
+	-0x1.0d80p-105,
+	 0x1.6b00p-103,
+	-0x1.9f00p-105,
+	 0x1.c400p-103,
+	 0x1.e120p-103,
+	-0x1.c100p-104,
+	-0x1.9d20p-103,
+	 0x1.a800p-108,
+	 0x1.4c00p-106,
+	-0x1.9500p-106,
+	 0x1.6900p-105,
+	-0x1.29d0p-100,
+	 0x1.4c60p-103,
+	 0x1.13a0p-102,
+	-0x1.5b60p-103,
+	-0x1.1c40p-103,
+	 0x1.db80p-102,
+	 0x1.91a0p-102,
+	 0x1.dc00p-105,
+	 0x1.44c0p-104,
+	 0x1.9710p-102,
+	 0x1.8760p-103,
+	-0x1.a720p-103,
+	 0x1.ed20p-103,
+	-0x1.49c0p-102,
+	-0x1.e000p-111,
+	 0x1.86a0p-103,
+	 0x1.2b40p-103,
+	-0x1.b400p-108,
+	 0x1.1280p-99,
+	-0x1.02d8p-102,
+	-0x1.e3d0p-103,
+	-0x1.b080p-105,
+	-0x1.f100p-107,
+	-0x1.16c0p-105,
+	-0x1.1190p-103,
+	-0x1.a7d2p-100,
+	 0x1.3450p-103,
+	-0x1.67c0p-105,
+	 0x1.4b80p-104,
+	-0x1.c4e0p-103,
+	 0x1.6000p-108,
+	-0x1.3f60p-105,
+	 0x1.93f0p-104,
+	 0x1.5fe0p-105,
+	 0x1.6f80p-107,
+	-0x1.7600p-106,
+	 0x1.21e0p-106,
+	-0x1.3a40p-106,
+	-0x1.40c0p-104,
+	-0x1.9860p-105,
+	-0x1.5d40p-108,
+	-0x1.1d70p-106,
+	 0x1.2760p-105,
+	 0x0.0000p+0,
+	 0x1.21e2p-104,
+	-0x1.9520p-108,
+	-0x1.5720p-106,
+	-0x1.4810p-106,
+	-0x1.be00p-109,
+	 0x1.0080p-105,
+	-0x1.5780p-108,
+	-0x1.d460p-105,
+	-0x1.6140p-105,
+	 0x1.4630p-104,
+	 0x1.ad50p-103,
+	 0x1.82e0p-105,
+	 0x1.1d3cp-101,
+	 0x1.6100p-107,
+	 0x1.ec30p-104,
+	 0x1.f200p-108,
+	 0x1.0b40p-103,
+	 0x1.3660p-102,
+	 0x1.d9d0p-103,
+	-0x1.02d0p-102,
+	 0x1.b070p-103,
+	 0x1.b9c0p-104,
+	-0x1.01c0p-103,
+	-0x1.dfe0p-103,
+	 0x1.1b60p-104,
+	-0x1.ae94p-101,
+	-0x1.3340p-104,
+	 0x1.b3d8p-102,
+	-0x1.6e40p-105,
+	-0x1.3670p-103,
+	 0x1.c140p-104,
+	 0x1.1840p-101,
+	 0x1.1ab0p-102,
+	-0x1.a400p-104,
+	 0x1.1f00p-104,
+	-0x1.7180p-103,
+	 0x1.4ce0p-102,
+	 0x1.9200p-107,
+	-0x1.54c0p-103,
+	 0x1.1b80p-105,
+	-0x1.1828p-101,
+	 0x1.5720p-102,
+	-0x1.a060p-100,
+	 0x1.9160p-102,
+	 0x1.a280p-104,
+	 0x1.3400p-107,
+	 0x1.2b20p-102,
+	 0x1.7800p-108,
+	 0x1.cfd0p-101,
+	 0x1.2ef0p-102,
+	-0x1.2760p-99,
+	 0x1.b380p-104,
+	 0x1.0048p-101,
+	-0x1.60b0p-102,
+	 0x1.a1ccp-100,
+	-0x1.a640p-104,
+	-0x1.08a0p-101,
+	 0x1.7e60p-102,
+	 0x1.22c0p-103,
+	-0x1.7200p-106,
+	 0x1.f0f0p-102,
+	 0x1.eb4ep-99,
+	 0x1.c6e0p-103,
+};
+
+/*
+ * exp2l(x): compute the base 2 exponential of x
+ *
+ * Accuracy: Peak error < 0.502 ulp.
+ *
+ * Method: (accurate tables)
+ *
+ *   Reduce x:
+ *     x = 2**k + y, for integer k and |y| <= 1/2.
+ *     Thus we have exp2(x) = 2**k * exp2(y).
+ *
+ *   Reduce y:
+ *     y = i/TBLSIZE + z - eps[i] for integer i near y * TBLSIZE.
+ *     Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z - eps[i]),
+ *     with |z - eps[i]| <= 2**-8 + 2**-98 for the table used.
+ *
+ *   We compute exp2(i/TBLSIZE) via table lookup and exp2(z - eps[i]) via
+ *   a degree-10 minimax polynomial with maximum error under 2**-120.
+ *   The values in exp2t[] and eps[] are chosen such that
+ *   exp2t[i] = exp2(i/TBLSIZE + eps[i]), and eps[i] is a small offset such
+ *   that exp2t[i] is accurate to 2**-122.
+ *
+ *   Note that the range of i is +-TBLSIZE/2, so we actually index the tables
+ *   by i0 = i + TBLSIZE/2.
+ *
+ *   This method is due to Gal, with many details due to Gal and Bachelis:
+ *
+ *	Gal, S. and Bachelis, B.  An Accurate Elementary Mathematical Library
+ *	for the IEEE Floating Point Standard.  TOMS 17(1), 26-46 (1991).
+ */
+long double
+exp2l(long double x)
+{
+	union IEEEl2bits u, v;
+	long double r, t, twopk, twopkp10000, z;
+	uint32_t hx, ix, i0;
+	int k;
+
+	u.e = x;
+
+	/* Filter out exceptional cases. */
+	hx = u.xbits.expsign;
+	ix = hx & EXPMASK;
+	if (ix >= BIAS + 14) {		/* |x| >= 16384 */
+		if (ix == BIAS + LDBL_MAX_EXP) {
+			if (u.xbits.manh != 0
+			    || u.xbits.manl != 0
+			    || (hx & 0x8000) == 0)
+				return (x + x);	/* x is NaN or +Inf */
+			else
+				return (0.0);	/* x is -Inf */
+		}
+		if (x >= 16384)
+			return (huge * huge); /* overflow */
+		if (x <= -16495)
+			return (twom10000 * twom10000); /* underflow */
+	} else if (ix <= BIAS - 115) {		/* |x| < 0x1p-115 */
+		return (1.0 + x);
+	}
+
+	/*
+	 * Reduce x, computing z, i0, and k. The low bits of x + redux
+	 * contain the 16-bit integer part of the exponent (k) followed by
+	 * TBLBITS fractional bits (i0). We use bit tricks to extract these
+	 * as integers, then set z to the remainder.
+	 *
+	 * Example: Suppose x is 0xabc.123456p0 and TBLBITS is 8.
+	 * Then the low-order word of x + redux is 0x000abc12,
+	 * We split this into k = 0xabc and i0 = 0x12 (adjusted to
+	 * index into the table), then we compute z = 0x0.003456p0.
+	 *
+	 * XXX If the exponent is negative, the computation of k depends on
+	 *     '>>' doing sign extension.
+	 */
+	u.e = x + redux;
+	i0 = (u.bits.manl & 0xffffffff) + TBLSIZE / 2;
+	k = (int)i0 >> TBLBITS;
+	i0 = i0 & (TBLSIZE - 1);
+	u.e -= redux;
+	z = x - u.e;
+	v.xbits.manh = 0;
+	v.xbits.manl = 0;
+	if (k >= LDBL_MIN_EXP) {
+		v.xbits.expsign = LDBL_MAX_EXP - 1 + k;
+		twopk = v.e;
+	} else {
+		v.xbits.expsign = LDBL_MAX_EXP - 1 + k + 10000;
+		twopkp10000 = v.e;
+	}
+
+	/* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */
+	t = tbl[i0];		/* exp2t[i0] */
+	z -= eps[i0];		/* eps[i0]   */
+	r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * (P5 + z * (P6
+	    + z * (P7 + z * (P8 + z * (P9 + z * P10)))))))));
+
+	/* Scale by 2**k. */
+	if(k >= LDBL_MIN_EXP) {
+		if (k == LDBL_MAX_EXP)
+			return (r * 2.0 * 0x1p16383L);
+		return (r * twopk);
+	} else {
+		return (r * twopkp10000 * twom10000);
+	}
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_expl.c b/libm/upstream-freebsd/lib/msun/ld128/s_expl.c
new file mode 100644
index 0000000..176c932
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/s_expl.c
@@ -0,0 +1,494 @@
+/*-
+ * Copyright (c) 2009-2013 Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Optimized by Bruce D. Evans.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * ld128 version of s_expl.c.  See ../ld80/s_expl.c for most comments.
+ */
+
+#include <float.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+#define	INTERVALS	128
+#define	LOG2_INTERVALS	7
+#define	BIAS	(LDBL_MAX_EXP - 1)
+
+static const long double
+huge = 0x1p10000L,
+twom10000 = 0x1p-10000L;
+/* XXX Prevent gcc from erroneously constant folding this: */
+static volatile const long double tiny = 0x1p-10000L;
+
+static const long double
+/* log(2**16384 - 0.5) rounded towards zero: */
+/* log(2**16384 - 0.5 + 1) rounded towards zero for expm1l() is the same: */
+o_threshold =  11356.523406294143949491931077970763428L,
+/* log(2**(-16381-64-1)) rounded towards zero: */
+u_threshold = -11433.462743336297878837243843452621503L;
+
+static const double
+/*
+ * ln2/INTERVALS = L1+L2 (hi+lo decomposition for multiplication).  L1 must
+ * have at least 22 (= log2(|LDBL_MIN_EXP-extras|) + log2(INTERVALS)) lowest
+ * bits zero so that multiplication of it by n is exact.
+ */
+INV_L = 1.8466496523378731e+2,		/*  0x171547652b82fe.0p-45 */
+L2 = -1.0253670638894731e-29;		/* -0x1.9ff0342542fc3p-97 */
+static const long double
+/* 0x1.62e42fefa39ef35793c768000000p-8 */
+L1 =  5.41521234812457272982212595914567508e-3L;
+
+static const long double
+/*
+ * Domain [-0.002708, 0.002708], range ~[-2.4021e-38, 2.4234e-38]:
+ * |exp(x) - p(x)| < 2**-124.9
+ * (0.002708 is ln2/(2*INTERVALS) rounded up a little).
+ */
+A2  =  0.5,
+A3  =  1.66666666666666666666666666651085500e-1L,
+A4  =  4.16666666666666666666666666425885320e-2L,
+A5  =  8.33333333333333333334522877160175842e-3L,
+A6  =  1.38888888888888888889971139751596836e-3L;
+
+static const double
+A7  =  1.9841269841269471e-4,
+A8  =  2.4801587301585284e-5,
+A9  =  2.7557324277411234e-6,
+A10 =  2.7557333722375072e-7;
+
+static const struct {
+	/*
+	 * hi must be rounded to at most 106 bits so that multiplication
+	 * by r1 in expm1l() is exact, but it is rounded to 88 bits due to
+	 * historical accidents.
+	 */
+	long double	hi;
+	long double	lo;
+} tbl[INTERVALS] = {
+	0x1p0L, 0x0p0L,
+	0x1.0163da9fb33356d84a66aep0L, 0x3.36dcdfa4003ec04c360be2404078p-92L,
+	0x1.02c9a3e778060ee6f7cacap0L, 0x4.f7a29bde93d70a2cabc5cb89ba10p-92L,
+	0x1.04315e86e7f84bd738f9a2p0L, 0xd.a47e6ed040bb4bfc05af6455e9b8p-96L,
+	0x1.059b0d31585743ae7c548ep0L, 0xb.68ca417fe53e3495f7df4baf84a0p-92L,
+	0x1.0706b29ddf6ddc6dc403a8p0L, 0x1.d87b27ed07cb8b092ac75e311753p-88L,
+	0x1.0874518759bc808c35f25cp0L, 0x1.9427fa2b041b2d6829d8993a0d01p-88L,
+	0x1.09e3ecac6f3834521e060cp0L, 0x5.84d6b74ba2e023da730e7fccb758p-92L,
+	0x1.0b5586cf9890f6298b92b6p0L, 0x1.1842a98364291408b3ceb0a2a2bbp-88L,
+	0x1.0cc922b7247f7407b705b8p0L, 0x9.3dc5e8aac564e6fe2ef1d431fd98p-92L,
+	0x1.0e3ec32d3d1a2020742e4ep0L, 0x1.8af6a552ac4b358b1129e9f966a4p-88L,
+	0x1.0fb66affed31af232091dcp0L, 0x1.8a1426514e0b627bda694a400a27p-88L,
+	0x1.11301d0125b50a4ebbf1aep0L, 0xd.9318ceac5cc47ab166ee57427178p-92L,
+	0x1.12abdc06c31cbfb92bad32p0L, 0x4.d68e2f7270bdf7cedf94eb1cb818p-92L,
+	0x1.1429aaea92ddfb34101942p0L, 0x1.b2586d01844b389bea7aedd221d4p-88L,
+	0x1.15a98c8a58e512480d573cp0L, 0x1.d5613bf92a2b618ee31b376c2689p-88L,
+	0x1.172b83c7d517adcdf7c8c4p0L, 0x1.0eb14a792035509ff7d758693f24p-88L,
+	0x1.18af9388c8de9bbbf70b9ap0L, 0x3.c2505c97c0102e5f1211941d2840p-92L,
+	0x1.1a35beb6fcb753cb698f68p0L, 0x1.2d1c835a6c30724d5cfae31b84e5p-88L,
+	0x1.1bbe084045cd39ab1e72b4p0L, 0x4.27e35f9acb57e473915519a1b448p-92L,
+	0x1.1d4873168b9aa7805b8028p0L, 0x9.90f07a98b42206e46166cf051d70p-92L,
+	0x1.1ed5022fcd91cb8819ff60p0L, 0x1.121d1e504d36c47474c9b7de6067p-88L,
+	0x1.2063b88628cd63b8eeb028p0L, 0x1.50929d0fc487d21c2b84004264dep-88L,
+	0x1.21f49917ddc962552fd292p0L, 0x9.4bdb4b61ea62477caa1dce823ba0p-92L,
+	0x1.2387a6e75623866c1fadb0p0L, 0x1.c15cb593b0328566902df69e4de2p-88L,
+	0x1.251ce4fb2a63f3582ab7dep0L, 0x9.e94811a9c8afdcf796934bc652d0p-92L,
+	0x1.26b4565e27cdd257a67328p0L, 0x1.d3b249dce4e9186ddd5ff44e6b08p-92L,
+	0x1.284dfe1f5638096cf15cf0p0L, 0x3.ca0967fdaa2e52d7c8106f2e262cp-92L,
+	0x1.29e9df51fdee12c25d15f4p0L, 0x1.a24aa3bca890ac08d203fed80a07p-88L,
+	0x1.2b87fd0dad98ffddea4652p0L, 0x1.8fcab88442fdc3cb6de4519165edp-88L,
+	0x1.2d285a6e4030b40091d536p0L, 0xd.075384589c1cd1b3e4018a6b1348p-92L,
+	0x1.2ecafa93e2f5611ca0f45cp0L, 0x1.523833af611bdcda253c554cf278p-88L,
+	0x1.306fe0a31b7152de8d5a46p0L, 0x3.05c85edecbc27343629f502f1af2p-92L,
+	0x1.32170fc4cd8313539cf1c2p0L, 0x1.008f86dde3220ae17a005b6412bep-88L,
+	0x1.33c08b26416ff4c9c8610cp0L, 0x1.96696bf95d1593039539d94d662bp-88L,
+	0x1.356c55f929ff0c94623476p0L, 0x3.73af38d6d8d6f9506c9bbc93cbc0p-92L,
+	0x1.371a7373aa9caa7145502ep0L, 0x1.4547987e3e12516bf9c699be432fp-88L,
+	0x1.38cae6d05d86585a9cb0d8p0L, 0x1.bed0c853bd30a02790931eb2e8f0p-88L,
+	0x1.3a7db34e59ff6ea1bc9298p0L, 0x1.e0a1d336163fe2f852ceeb134067p-88L,
+	0x1.3c32dc313a8e484001f228p0L, 0xb.58f3775e06ab66353001fae9fca0p-92L,
+	0x1.3dea64c12342235b41223ep0L, 0x1.3d773fba2cb82b8244267c54443fp-92L,
+	0x1.3fa4504ac801ba0bf701aap0L, 0x4.1832fb8c1c8dbdff2c49909e6c60p-92L,
+	0x1.4160a21f72e29f84325b8ep0L, 0x1.3db61fb352f0540e6ba05634413ep-88L,
+	0x1.431f5d950a896dc7044394p0L, 0x1.0ccec81e24b0caff7581ef4127f7p-92L,
+	0x1.44e086061892d03136f408p0L, 0x1.df019fbd4f3b48709b78591d5cb5p-88L,
+	0x1.46a41ed1d005772512f458p0L, 0x1.229d97df404ff21f39c1b594d3a8p-88L,
+	0x1.486a2b5c13cd013c1a3b68p0L, 0x1.062f03c3dd75ce8757f780e6ec99p-88L,
+	0x1.4a32af0d7d3de672d8bcf4p0L, 0x6.f9586461db1d878b1d148bd3ccb8p-92L,
+	0x1.4bfdad5362a271d4397afep0L, 0xc.42e20e0363ba2e159c579f82e4b0p-92L,
+	0x1.4dcb299fddd0d63b36ef1ap0L, 0x9.e0cc484b25a5566d0bd5f58ad238p-92L,
+	0x1.4f9b2769d2ca6ad33d8b68p0L, 0x1.aa073ee55e028497a329a7333dbap-88L,
+	0x1.516daa2cf6641c112f52c8p0L, 0x4.d822190e718226177d7608d20038p-92L,
+	0x1.5342b569d4f81df0a83c48p0L, 0x1.d86a63f4e672a3e429805b049465p-88L,
+	0x1.551a4ca5d920ec52ec6202p0L, 0x4.34ca672645dc6c124d6619a87574p-92L,
+	0x1.56f4736b527da66ecb0046p0L, 0x1.64eb3c00f2f5ab3d801d7cc7272dp-88L,
+	0x1.58d12d497c7fd252bc2b72p0L, 0x1.43bcf2ec936a970d9cc266f0072fp-88L,
+	0x1.5ab07dd48542958c930150p0L, 0x1.91eb345d88d7c81280e069fbdb63p-88L,
+	0x1.5c9268a5946b701c4b1b80p0L, 0x1.6986a203d84e6a4a92f179e71889p-88L,
+	0x1.5e76f15ad21486e9be4c20p0L, 0x3.99766a06548a05829e853bdb2b52p-92L,
+	0x1.605e1b976dc08b076f592ap0L, 0x4.86e3b34ead1b4769df867b9c89ccp-92L,
+	0x1.6247eb03a5584b1f0fa06ep0L, 0x1.d2da42bb1ceaf9f732275b8aef30p-88L,
+	0x1.6434634ccc31fc76f8714cp0L, 0x4.ed9a4e41000307103a18cf7a6e08p-92L,
+	0x1.66238825522249127d9e28p0L, 0x1.b8f314a337f4dc0a3adf1787ff74p-88L,
+	0x1.68155d44ca973081c57226p0L, 0x1.b9f32706bfe4e627d809a85dcc66p-88L,
+	0x1.6a09e667f3bcc908b2fb12p0L, 0x1.66ea957d3e3adec17512775099dap-88L,
+	0x1.6c012750bdabeed76a9980p0L, 0xf.4f33fdeb8b0ecd831106f57b3d00p-96L,
+	0x1.6dfb23c651a2ef220e2cbep0L, 0x1.bbaa834b3f11577ceefbe6c1c411p-92L,
+	0x1.6ff7df9519483cf87e1b4ep0L, 0x1.3e213bff9b702d5aa477c12523cep-88L,
+	0x1.71f75e8ec5f73dd2370f2ep0L, 0xf.0acd6cb434b562d9e8a20adda648p-92L,
+	0x1.73f9a48a58173bd5c9a4e6p0L, 0x8.ab1182ae217f3a7681759553e840p-92L,
+	0x1.75feb564267c8bf6e9aa32p0L, 0x1.a48b27071805e61a17b954a2dad8p-88L,
+	0x1.780694fde5d3f619ae0280p0L, 0x8.58b2bb2bdcf86cd08e35fb04c0f0p-92L,
+	0x1.7a11473eb0186d7d51023ep0L, 0x1.6cda1f5ef42b66977960531e821bp-88L,
+	0x1.7c1ed0130c1327c4933444p0L, 0x1.937562b2dc933d44fc828efd4c9cp-88L,
+	0x1.7e2f336cf4e62105d02ba0p0L, 0x1.5797e170a1427f8fcdf5f3906108p-88L,
+	0x1.80427543e1a11b60de6764p0L, 0x9.a354ea706b8e4d8b718a672bf7c8p-92L,
+	0x1.82589994cce128acf88afap0L, 0xb.34a010f6ad65cbbac0f532d39be0p-92L,
+	0x1.8471a4623c7acce52f6b96p0L, 0x1.c64095370f51f48817914dd78665p-88L,
+	0x1.868d99b4492ec80e41d90ap0L, 0xc.251707484d73f136fb5779656b70p-92L,
+	0x1.88ac7d98a669966530bcdep0L, 0x1.2d4e9d61283ef385de170ab20f96p-88L,
+	0x1.8ace5422aa0db5ba7c55a0p0L, 0x1.92c9bb3e6ed61f2733304a346d8fp-88L,
+	0x1.8cf3216b5448bef2aa1cd0p0L, 0x1.61c55d84a9848f8c453b3ca8c946p-88L,
+	0x1.8f1ae991577362b982745cp0L, 0x7.2ed804efc9b4ae1458ae946099d4p-92L,
+	0x1.9145b0b91ffc588a61b468p0L, 0x1.f6b70e01c2a90229a4c4309ea719p-88L,
+	0x1.93737b0cdc5e4f4501c3f2p0L, 0x5.40a22d2fc4af581b63e8326efe9cp-92L,
+	0x1.95a44cbc8520ee9b483694p0L, 0x1.a0fc6f7c7d61b2b3a22a0eab2cadp-88L,
+	0x1.97d829fde4e4f8b9e920f8p0L, 0x1.1e8bd7edb9d7144b6f6818084cc7p-88L,
+	0x1.9a0f170ca07b9ba3109b8cp0L, 0x4.6737beb19e1eada6825d3c557428p-92L,
+	0x1.9c49182a3f0901c7c46b06p0L, 0x1.1f2be58ddade50c217186c90b457p-88L,
+	0x1.9e86319e323231824ca78ep0L, 0x6.4c6e010f92c082bbadfaf605cfd4p-92L,
+	0x1.a0c667b5de564b29ada8b8p0L, 0xc.ab349aa0422a8da7d4512edac548p-92L,
+	0x1.a309bec4a2d3358c171f76p0L, 0x1.0daad547fa22c26d168ea762d854p-88L,
+	0x1.a5503b23e255c8b424491cp0L, 0xa.f87bc8050a405381703ef7caff50p-92L,
+	0x1.a799e1330b3586f2dfb2b0p0L, 0x1.58f1a98796ce8908ae852236ca94p-88L,
+	0x1.a9e6b5579fdbf43eb243bcp0L, 0x1.ff4c4c58b571cf465caf07b4b9f5p-88L,
+	0x1.ac36bbfd3f379c0db966a2p0L, 0x1.1265fc73e480712d20f8597a8e7bp-88L,
+	0x1.ae89f995ad3ad5e8734d16p0L, 0x1.73205a7fbc3ae675ea440b162d6cp-88L,
+	0x1.b0e07298db66590842acdep0L, 0x1.c6f6ca0e5dcae2aafffa7a0554cbp-88L,
+	0x1.b33a2b84f15faf6bfd0e7ap0L, 0x1.d947c2575781dbb49b1237c87b6ep-88L,
+	0x1.b59728de559398e3881110p0L, 0x1.64873c7171fefc410416be0a6525p-88L,
+	0x1.b7f76f2fb5e46eaa7b081ap0L, 0xb.53c5354c8903c356e4b625aacc28p-92L,
+	0x1.ba5b030a10649840cb3c6ap0L, 0xf.5b47f297203757e1cc6eadc8bad0p-92L,
+	0x1.bcc1e904bc1d2247ba0f44p0L, 0x1.b3d08cd0b20287092bd59be4ad98p-88L,
+	0x1.bf2c25bd71e088408d7024p0L, 0x1.18e3449fa073b356766dfb568ff4p-88L,
+	0x1.c199bdd85529c2220cb12ap0L, 0x9.1ba6679444964a36661240043970p-96L,
+	0x1.c40ab5fffd07a6d14df820p0L, 0xf.1828a5366fd387a7bdd54cdf7300p-92L,
+	0x1.c67f12e57d14b4a2137fd2p0L, 0xf.2b301dd9e6b151a6d1f9d5d5f520p-96L,
+	0x1.c8f6d9406e7b511acbc488p0L, 0x5.c442ddb55820171f319d9e5076a8p-96L,
+	0x1.cb720dcef90691503cbd1ep0L, 0x9.49db761d9559ac0cb6dd3ed599e0p-92L,
+	0x1.cdf0b555dc3f9c44f8958ep0L, 0x1.ac51be515f8c58bdfb6f5740a3a4p-88L,
+	0x1.d072d4a07897b8d0f22f20p0L, 0x1.a158e18fbbfc625f09f4cca40874p-88L,
+	0x1.d2f87080d89f18ade12398p0L, 0x9.ea2025b4c56553f5cdee4c924728p-92L,
+	0x1.d5818dcfba48725da05aeap0L, 0x1.66e0dca9f589f559c0876ff23830p-88L,
+	0x1.d80e316c98397bb84f9d04p0L, 0x8.805f84bec614de269900ddf98d28p-92L,
+	0x1.da9e603db3285708c01a5ap0L, 0x1.6d4c97f6246f0ec614ec95c99392p-88L,
+	0x1.dd321f301b4604b695de3cp0L, 0x6.30a393215299e30d4fb73503c348p-96L,
+	0x1.dfc97337b9b5eb968cac38p0L, 0x1.ed291b7225a944efd5bb5524b927p-88L,
+	0x1.e264614f5a128a12761fa0p0L, 0x1.7ada6467e77f73bf65e04c95e29dp-88L,
+	0x1.e502ee78b3ff6273d13014p0L, 0x1.3991e8f49659e1693be17ae1d2f9p-88L,
+	0x1.e7a51fbc74c834b548b282p0L, 0x1.23786758a84f4956354634a416cep-88L,
+	0x1.ea4afa2a490d9858f73a18p0L, 0xf.5db301f86dea20610ceee13eb7b8p-92L,
+	0x1.ecf482d8e67f08db0312fap0L, 0x1.949cef462010bb4bc4ce72a900dfp-88L,
+	0x1.efa1bee615a27771fd21a8p0L, 0x1.2dac1f6dd5d229ff68e46f27e3dfp-88L,
+	0x1.f252b376bba974e8696fc2p0L, 0x1.6390d4c6ad5476b5162f40e1d9a9p-88L,
+	0x1.f50765b6e4540674f84b76p0L, 0x2.862baff99000dfc4352ba29b8908p-92L,
+	0x1.f7bfdad9cbe138913b4bfep0L, 0x7.2bd95c5ce7280fa4d2344a3f5618p-92L,
+	0x1.fa7c1819e90d82e90a7e74p0L, 0xb.263c1dc060c36f7650b4c0f233a8p-92L,
+	0x1.fd3c22b8f71f10975ba4b2p0L, 0x1.2bcf3a5e12d269d8ad7c1a4a8875p-88L
+};
+
+long double
+expl(long double x)
+{
+	union IEEEl2bits u, v;
+	long double q, r, r1, t, twopk, twopkp10000;
+	double dr, fn, r2;
+	int k, n, n2;
+	uint16_t hx, ix;
+
+	/* Filter out exceptional cases. */
+	u.e = x;
+	hx = u.xbits.expsign;
+	ix = hx & 0x7fff;
+	if (ix >= BIAS + 13) {		/* |x| >= 8192 or x is NaN */
+		if (ix == BIAS + LDBL_MAX_EXP) {
+			if (hx & 0x8000)  /* x is -Inf or -NaN */
+				return (-1 / x);
+			return (x + x);	/* x is +Inf or +NaN */
+		}
+		if (x > o_threshold)
+			return (huge * huge);
+		if (x < u_threshold)
+			return (tiny * tiny);
+	} else if (ix < BIAS - 114) {	/* |x| < 0x1p-114 */
+		return (1 + x);		/* 1 with inexact iff x != 0 */
+	}
+
+	ENTERI();
+
+	/* Reduce x to (k*ln2 + endpoint[n2] + r1 + r2). */
+	/* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+	/* XXX assume no extra precision for the additions, as for trig fns. */
+	/* XXX this set of comments is now quadruplicated. */
+	fn = (double)x * INV_L + 0x1.8p52 - 0x1.8p52;
+#if defined(HAVE_EFFICIENT_IRINT)
+	n = irint(fn);
+#else
+	n = (int)fn;
+#endif
+	n2 = (unsigned)n % INTERVALS;
+	k = n >> LOG2_INTERVALS;
+	r1 = x - fn * L1;
+	r2 = fn * -L2;
+	r = r1 + r2;
+
+	/* Prepare scale factors. */
+	/* XXX sparc64 multiplication is so slow that scalbnl() is faster. */
+	v.e = 1;
+	if (k >= LDBL_MIN_EXP) {
+		v.xbits.expsign = BIAS + k;
+		twopk = v.e;
+	} else {
+		v.xbits.expsign = BIAS + k + 10000;
+		twopkp10000 = v.e;
+	}
+
+	/* Evaluate expl(endpoint[n2] + r1 + r2) = tbl[n2] * expl(r1 + r2). */
+	dr = r;
+	q = r2 + r * r * (A2 + r * (A3 + r * (A4 + r * (A5 + r * (A6 +
+	    dr * (A7 + dr * (A8 + dr * (A9 + dr * A10))))))));
+	t = tbl[n2].lo + tbl[n2].hi;
+	t = tbl[n2].lo + t * (q + r1) + tbl[n2].hi;
+
+	/* Scale by 2**k. */
+	if (k >= LDBL_MIN_EXP) {
+		if (k == LDBL_MAX_EXP)
+			RETURNI(t * 2 * 0x1p16383L);
+		RETURNI(t * twopk);
+	} else {
+		RETURNI(t * twopkp10000 * twom10000);
+	}
+}
+
+/*
+ * Our T1 and T2 are chosen to be approximately the points where method
+ * A and method B have the same accuracy.  Tang's T1 and T2 are the
+ * points where method A's accuracy changes by a full bit.  For Tang,
+ * this drop in accuracy makes method A immediately less accurate than
+ * method B, but our larger INTERVALS makes method A 2 bits more
+ * accurate so it remains the most accurate method significantly
+ * closer to the origin despite losing the full bit in our extended
+ * range for it.
+ *
+ * Split the interval [T1, T2] into two intervals [T1, T3] and [T3, T2].
+ * Setting T3 to 0 would require the |x| < 0x1p-113 condition to appear
+ * in both subintervals, so set T3 = 2**-5, which places the condition
+ * into the [T1, T3] interval.
+ */
+static const double
+T1 = -0.1659,				/* ~-30.625/128 * log(2) */
+T2 =  0.1659,				/* ~30.625/128 * log(2) */
+T3 =  0.03125;
+
+/*
+ * Domain [-0.1659, 0.03125], range ~[2.9134e-44, 1.8404e-37]:
+ * |(exp(x)-1-x-x**2/2)/x - p(x)| < 2**-122.03
+ */
+static const long double
+C3  =  1.66666666666666666666666666666666667e-1L,
+C4  =  4.16666666666666666666666666666666645e-2L,
+C5  =  8.33333333333333333333333333333371638e-3L,
+C6  =  1.38888888888888888888888888891188658e-3L,
+C7  =  1.98412698412698412698412697235950394e-4L,
+C8  =  2.48015873015873015873015112487849040e-5L,
+C9  =  2.75573192239858906525606685484412005e-6L,
+C10 =  2.75573192239858906612966093057020362e-7L,
+C11 =  2.50521083854417203619031960151253944e-8L,
+C12 =  2.08767569878679576457272282566520649e-9L,
+C13 =  1.60590438367252471783548748824255707e-10L;
+
+static const double
+C14 =  1.1470745580491932e-11,		/*  0x1.93974a81dae30p-37 */
+C15 =  7.6471620181090468e-13,		/*  0x1.ae7f3820adab1p-41 */
+C16 =  4.7793721460260450e-14,		/*  0x1.ae7cd18a18eacp-45 */
+C17 =  2.8074757356658877e-15,		/*  0x1.949992a1937d9p-49 */
+C18 =  1.4760610323699476e-16;		/*  0x1.545b43aabfbcdp-53 */
+
+/*
+ * Domain [0.03125, 0.1659], range ~[-2.7676e-37, -1.0367e-38]:
+ * |(exp(x)-1-x-x**2/2)/x - p(x)| < 2**-121.44
+ */
+static const long double
+D3  =  1.66666666666666666666666666666682245e-1L,
+D4  =  4.16666666666666666666666666634228324e-2L,
+D5  =  8.33333333333333333333333364022244481e-3L,
+D6  =  1.38888888888888888888887138722762072e-3L,
+D7  =  1.98412698412698412699085805424661471e-4L,
+D8  =  2.48015873015873015687993712101479612e-5L,
+D9  =  2.75573192239858944101036288338208042e-6L,
+D10 =  2.75573192239853161148064676533754048e-7L,
+D11 =  2.50521083855084570046480450935267433e-8L,
+D12 =  2.08767569819738524488686318024854942e-9L,
+D13 =  1.60590442297008495301927448122499313e-10L;
+
+static const double
+D14 =  1.1470726176204336e-11,		/*  0x1.93971dc395d9ep-37 */
+D15 =  7.6478532249581686e-13,		/*  0x1.ae892e3D16fcep-41 */
+D16 =  4.7628892832607741e-14,		/*  0x1.ad00Dfe41feccp-45 */
+D17 =  3.0524857220358650e-15;		/*  0x1.D7e8d886Df921p-49 */
+
+long double
+expm1l(long double x)
+{
+	union IEEEl2bits u, v;
+	long double hx2_hi, hx2_lo, q, r, r1, t, twomk, twopk, x_hi;
+	long double x_lo, x2;
+	double dr, dx, fn, r2;
+	int k, n, n2;
+	uint16_t hx, ix;
+
+	/* Filter out exceptional cases. */
+	u.e = x;
+	hx = u.xbits.expsign;
+	ix = hx & 0x7fff;
+	if (ix >= BIAS + 7) {		/* |x| >= 128 or x is NaN */
+		if (ix == BIAS + LDBL_MAX_EXP) {
+			if (hx & 0x8000)  /* x is -Inf or -NaN */
+				return (-1 / x - 1);
+			return (x + x);	/* x is +Inf or +NaN */
+		}
+		if (x > o_threshold)
+			return (huge * huge);
+		/*
+		 * expm1l() never underflows, but it must avoid
+		 * unrepresentable large negative exponents.  We used a
+		 * much smaller threshold for large |x| above than in
+		 * expl() so as to handle not so large negative exponents
+		 * in the same way as large ones here.
+		 */
+		if (hx & 0x8000)	/* x <= -128 */
+			return (tiny - 1);	/* good for x < -114ln2 - eps */
+	}
+
+	ENTERI();
+
+	if (T1 < x && x < T2) {
+		x2 = x * x;
+		dx = x;
+
+		if (x < T3) {
+			if (ix < BIAS - 113) {	/* |x| < 0x1p-113 */
+				/* x (rounded) with inexact if x != 0: */
+				RETURNI(x == 0 ? x :
+				    (0x1p200 * x + fabsl(x)) * 0x1p-200);
+			}
+			q = x * x2 * C3 + x2 * x2 * (C4 + x * (C5 + x * (C6 +
+			    x * (C7 + x * (C8 + x * (C9 + x * (C10 +
+			    x * (C11 + x * (C12 + x * (C13 +
+			    dx * (C14 + dx * (C15 + dx * (C16 +
+			    dx * (C17 + dx * C18))))))))))))));
+		} else {
+			q = x * x2 * D3 + x2 * x2 * (D4 + x * (D5 + x * (D6 +
+			    x * (D7 + x * (D8 + x * (D9 + x * (D10 +
+			    x * (D11 + x * (D12 + x * (D13 +
+			    dx * (D14 + dx * (D15 + dx * (D16 +
+			    dx * D17)))))))))))));
+		}
+
+		x_hi = (float)x;
+		x_lo = x - x_hi;
+		hx2_hi = x_hi * x_hi / 2;
+		hx2_lo = x_lo * (x + x_hi) / 2;
+		if (ix >= BIAS - 7)
+			RETURNI(hx2_lo + x_lo + q + (hx2_hi + x_hi));
+		else
+			RETURNI(hx2_lo + q + hx2_hi + x);
+	}
+
+	/* Reduce x to (k*ln2 + endpoint[n2] + r1 + r2). */
+	/* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+	fn = (double)x * INV_L + 0x1.8p52 - 0x1.8p52;
+#if defined(HAVE_EFFICIENT_IRINT)
+	n = irint(fn);
+#else
+	n = (int)fn;
+#endif
+	n2 = (unsigned)n % INTERVALS;
+	k = n >> LOG2_INTERVALS;
+	r1 = x - fn * L1;
+	r2 = fn * -L2;
+	r = r1 + r2;
+
+	/* Prepare scale factor. */
+	v.e = 1;
+	v.xbits.expsign = BIAS + k;
+	twopk = v.e;
+
+	/*
+	 * Evaluate lower terms of
+	 * expl(endpoint[n2] + r1 + r2) = tbl[n2] * expl(r1 + r2).
+	 */
+	dr = r;
+	q = r2 + r * r * (A2 + r * (A3 + r * (A4 + r * (A5 + r * (A6 +
+	    dr * (A7 + dr * (A8 + dr * (A9 + dr * A10))))))));
+
+	t = tbl[n2].lo + tbl[n2].hi;
+
+	if (k == 0) {
+		t = tbl[n2].lo * (r1 + 1) + t * q + tbl[n2].hi * r1 +
+		    (tbl[n2].hi - 1);
+		RETURNI(t);
+	}
+	if (k == -1) {
+		t = tbl[n2].lo * (r1 + 1) + t * q + tbl[n2].hi * r1 + 
+		    (tbl[n2].hi - 2);
+		RETURNI(t / 2);
+	}
+	if (k < -7) {
+		t = tbl[n2].lo + t * (q + r1) + tbl[n2].hi;
+		RETURNI(t * twopk - 1);
+	}
+	if (k > 2 * LDBL_MANT_DIG - 1) {
+		t = tbl[n2].lo + t * (q + r1) + tbl[n2].hi;
+		if (k == LDBL_MAX_EXP)
+			RETURNI(t * 2 * 0x1p16383L - 1);
+		RETURNI(t * twopk - 1);
+	}
+
+	v.xbits.expsign = BIAS - k;
+	twomk = v.e;
+
+	if (k > LDBL_MANT_DIG - 1)
+		t = tbl[n2].lo - twomk + t * (q + r1) + tbl[n2].hi;
+	else
+		t = tbl[n2].lo + t * (q + r1) + (tbl[n2].hi - twomk);
+	RETURNI(t * twopk);
+}
diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_logl.c b/libm/upstream-freebsd/lib/msun/ld128/s_logl.c
new file mode 100644
index 0000000..391d623
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/s_logl.c
@@ -0,0 +1,737 @@
+/*-
+ * Copyright (c) 2007-2013 Bruce D. Evans
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/**
+ * Implementation of the natural logarithm of x for 128-bit format.
+ *
+ * First decompose x into its base 2 representation:
+ *
+ *    log(x) = log(X * 2**k), where X is in [1, 2)
+ *           = log(X) + k * log(2).
+ *
+ * Let X = X_i + e, where X_i is the center of one of the intervals
+ * [-1.0/256, 1.0/256), [1.0/256, 3.0/256), .... [2.0-1.0/256, 2.0+1.0/256)
+ * and X is in this interval.  Then
+ *
+ *    log(X) = log(X_i + e)
+ *           = log(X_i * (1 + e / X_i))
+ *           = log(X_i) + log(1 + e / X_i).
+ *
+ * The values log(X_i) are tabulated below.  Let d = e / X_i and use
+ *
+ *    log(1 + d) = p(d)
+ *
+ * where p(d) = d - 0.5*d*d + ... is a special minimax polynomial of
+ * suitably high degree.
+ *
+ * To get sufficiently small roundoff errors, k * log(2), log(X_i), and
+ * sometimes (if |k| is not large) the first term in p(d) must be evaluated
+ * and added up in extra precision.  Extra precision is not needed for the
+ * rest of p(d).  In the worst case when k = 0 and log(X_i) is 0, the final
+ * error is controlled mainly by the error in the second term in p(d).  The
+ * error in this term itself is at most 0.5 ulps from the d*d operation in
+ * it.  The error in this term relative to the first term is thus at most
+ * 0.5 * |-0.5| * |d| < 1.0/1024 ulps.  We aim for an accumulated error of
+ * at most twice this at the point of the final rounding step.  Thus the
+ * final error should be at most 0.5 + 1.0/512 = 0.5020 ulps.  Exhaustive
+ * testing of a float variant of this function showed a maximum final error
+ * of 0.5008 ulps.  Non-exhaustive testing of a double variant of this
+ * function showed a maximum final error of 0.5078 ulps (near 1+1.0/256).
+ *
+ * We made the maximum of |d| (and thus the total relative error and the
+ * degree of p(d)) small by using a large number of intervals.  Using
+ * centers of intervals instead of endpoints reduces this maximum by a
+ * factor of 2 for a given number of intervals.  p(d) is special only
+ * in beginning with the Taylor coefficients 0 + 1*d, which tends to happen
+ * naturally.  The most accurate minimax polynomial of a given degree might
+ * be different, but then we wouldn't want it since we would have to do
+ * extra work to avoid roundoff error (especially for P0*d instead of d).
+ */
+
+#ifdef DEBUG
+#include <assert.h>
+#include <fenv.h>
+#endif
+
+#include "fpmath.h"
+#include "math.h"
+#ifndef NO_STRUCT_RETURN
+#define	STRUCT_RETURN
+#endif
+#include "math_private.h"
+
+#if !defined(NO_UTAB) && !defined(NO_UTABL)
+#define	USE_UTAB
+#endif
+
+/*
+ * Domain [-0.005280, 0.004838], range ~[-1.1577e-37, 1.1582e-37]:
+ * |log(1 + d)/d - p(d)| < 2**-122.7
+ */
+static const long double
+P2 = -0.5L,
+P3 =  3.33333333333333333333333333333233795e-1L,	/*  0x15555555555555555555555554d42.0p-114L */
+P4 = -2.49999999999999999999999999941139296e-1L,	/* -0x1ffffffffffffffffffffffdab14e.0p-115L */
+P5 =  2.00000000000000000000000085468039943e-1L,	/*  0x19999999999999999999a6d3567f4.0p-115L */
+P6 = -1.66666666666666666666696142372698408e-1L,	/* -0x15555555555555555567267a58e13.0p-115L */
+P7 =  1.42857142857142857119522943477166120e-1L,	/*  0x1249249249249248ed79a0ae434de.0p-115L */
+P8 = -1.24999999999999994863289015033581301e-1L;	/* -0x1fffffffffffffa13e91765e46140.0p-116L */
+/* Double precision gives ~ 53 + log2(P9 * max(|d|)**8) ~= 120 bits. */
+static const double
+P9 =  1.1111111111111401e-1,		/*  0x1c71c71c71c7ed.0p-56 */
+P10 = -1.0000000000040135e-1,		/* -0x199999999a0a92.0p-56 */
+P11 =  9.0909090728136258e-2,		/*  0x1745d173962111.0p-56 */
+P12 = -8.3333318851855284e-2,		/* -0x1555551722c7a3.0p-56 */
+P13 =  7.6928634666404178e-2,		/*  0x13b1985204a4ae.0p-56 */
+P14 = -7.1626810078462499e-2;		/* -0x12562276cdc5d0.0p-56 */
+
+static volatile const double zero = 0;
+
+#define	INTERVALS	128
+#define	LOG2_INTERVALS	7
+#define	TSIZE		(INTERVALS + 1)
+#define	G(i)		(T[(i)].G)
+#define	F_hi(i)		(T[(i)].F_hi)
+#define	F_lo(i)		(T[(i)].F_lo)
+#define	ln2_hi		F_hi(TSIZE - 1)
+#define	ln2_lo		F_lo(TSIZE - 1)
+#define	E(i)		(U[(i)].E)
+#define	H(i)		(U[(i)].H)
+
+static const struct {
+	float	G;			/* 1/(1 + i/128) rounded to 8/9 bits */
+	float	F_hi;			/* log(1 / G_i) rounded (see below) */
+	/* The compiler will insert 8 bytes of padding here. */
+	long double F_lo;		/* next 113 bits for log(1 / G_i) */
+} T[TSIZE] = {
+	/*
+	 * ln2_hi and each F_hi(i) are rounded to a number of bits that
+	 * makes F_hi(i) + dk*ln2_hi exact for all i and all dk.
+	 *
+	 * The last entry (for X just below 2) is used to define ln2_hi
+	 * and ln2_lo, to ensure that F_hi(i) and F_lo(i) cancel exactly
+	 * with dk*ln2_hi and dk*ln2_lo, respectively, when dk = -1.
+	 * This is needed for accuracy when x is just below 1.  (To avoid
+	 * special cases, such x are "reduced" strangely to X just below
+	 * 2 and dk = -1, and then the exact cancellation is needed
+	 * because any the error from any non-exactness would be too
+	 * large).
+	 *
+	 * The relevant range of dk is [-16445, 16383].  The maximum number
+	 * of bits in F_hi(i) that works is very dependent on i but has
+	 * a minimum of 93.  We only need about 12 bits in F_hi(i) for
+	 * it to provide enough extra precision.
+	 *
+	 * We round F_hi(i) to 24 bits so that it can have type float,
+	 * mainly to minimize the size of the table.  Using all 24 bits
+	 * in a float for it automatically satisfies the above constraints.
+	 */
+     0x800000.0p-23,  0,               0,
+     0xfe0000.0p-24,  0x8080ac.0p-30, -0x14ee431dae6674afa0c4bfe16e8fd.0p-144L,
+     0xfc0000.0p-24,  0x8102b3.0p-29, -0x1db29ee2d83717be918e1119642ab.0p-144L,
+     0xfa0000.0p-24,  0xc24929.0p-29,  0x1191957d173697cf302cc9476f561.0p-143L,
+     0xf80000.0p-24,  0x820aec.0p-28,  0x13ce8888e02e78eba9b1113bc1c18.0p-142L,
+     0xf60000.0p-24,  0xa33577.0p-28, -0x17a4382ce6eb7bfa509bec8da5f22.0p-142L,
+     0xf48000.0p-24,  0xbc42cb.0p-28, -0x172a21161a107674986dcdca6709c.0p-143L,
+     0xf30000.0p-24,  0xd57797.0p-28, -0x1e09de07cb958897a3ea46e84abb3.0p-142L,
+     0xf10000.0p-24,  0xf7518e.0p-28,  0x1ae1eec1b036c484993c549c4bf40.0p-151L,
+     0xef0000.0p-24,  0x8cb9df.0p-27, -0x1d7355325d560d9e9ab3d6ebab580.0p-141L,
+     0xed8000.0p-24,  0x999ec0.0p-27, -0x1f9f02d256d5037108f4ec21e48cd.0p-142L,
+     0xec0000.0p-24,  0xa6988b.0p-27, -0x16fc0a9d12c17a70f7a684c596b12.0p-143L,
+     0xea0000.0p-24,  0xb80698.0p-27,  0x15d581c1e8da99ded322fb08b8462.0p-141L,
+     0xe80000.0p-24,  0xc99af3.0p-27, -0x1535b3ba8f150ae09996d7bb4653e.0p-143L,
+     0xe70000.0p-24,  0xd273b2.0p-27,  0x163786f5251aefe0ded34c8318f52.0p-145L,
+     0xe50000.0p-24,  0xe442c0.0p-27,  0x1bc4b2368e32d56699c1799a244d4.0p-144L,
+     0xe38000.0p-24,  0xf1b83f.0p-27,  0x1c6090f684e6766abceccab1d7174.0p-141L,
+     0xe20000.0p-24,  0xff448a.0p-27, -0x1890aa69ac9f4215f93936b709efb.0p-142L,
+     0xe08000.0p-24,  0x8673f6.0p-26,  0x1b9985194b6affd511b534b72a28e.0p-140L,
+     0xdf0000.0p-24,  0x8d515c.0p-26, -0x1dc08d61c6ef1d9b2ef7e68680598.0p-143L,
+     0xdd8000.0p-24,  0x943a9e.0p-26, -0x1f72a2dac729b3f46662238a9425a.0p-142L,
+     0xdc0000.0p-24,  0x9b2fe6.0p-26, -0x1fd4dfd3a0afb9691aed4d5e3df94.0p-140L,
+     0xda8000.0p-24,  0xa2315d.0p-26, -0x11b26121629c46c186384993e1c93.0p-142L,
+     0xd90000.0p-24,  0xa93f2f.0p-26,  0x1286d633e8e5697dc6a402a56fce1.0p-141L,
+     0xd78000.0p-24,  0xb05988.0p-26,  0x16128eba9367707ebfa540e45350c.0p-144L,
+     0xd60000.0p-24,  0xb78094.0p-26,  0x16ead577390d31ef0f4c9d43f79b2.0p-140L,
+     0xd50000.0p-24,  0xbc4c6c.0p-26,  0x151131ccf7c7b75e7d900b521c48d.0p-141L,
+     0xd38000.0p-24,  0xc3890a.0p-26, -0x115e2cd714bd06508aeb00d2ae3e9.0p-140L,
+     0xd20000.0p-24,  0xcad2d7.0p-26, -0x1847f406ebd3af80485c2f409633c.0p-142L,
+     0xd10000.0p-24,  0xcfb620.0p-26,  0x1c2259904d686581799fbce0b5f19.0p-141L,
+     0xcf8000.0p-24,  0xd71653.0p-26,  0x1ece57a8d5ae54f550444ecf8b995.0p-140L,
+     0xce0000.0p-24,  0xde843a.0p-26, -0x1f109d4bc4595412b5d2517aaac13.0p-141L,
+     0xcd0000.0p-24,  0xe37fde.0p-26,  0x1bc03dc271a74d3a85b5b43c0e727.0p-141L,
+     0xcb8000.0p-24,  0xeb050c.0p-26, -0x1bf2badc0df841a71b79dd5645b46.0p-145L,
+     0xca0000.0p-24,  0xf29878.0p-26, -0x18efededd89fbe0bcfbe6d6db9f66.0p-147L,
+     0xc90000.0p-24,  0xf7ad6f.0p-26,  0x1373ff977baa6911c7bafcb4d84fb.0p-141L,
+     0xc80000.0p-24,  0xfcc8e3.0p-26,  0x196766f2fb328337cc050c6d83b22.0p-140L,
+     0xc68000.0p-24,  0x823f30.0p-25,  0x19bd076f7c434e5fcf1a212e2a91e.0p-139L,
+     0xc58000.0p-24,  0x84d52c.0p-25, -0x1a327257af0f465e5ecab5f2a6f81.0p-139L,
+     0xc40000.0p-24,  0x88bc74.0p-25,  0x113f23def19c5a0fe396f40f1dda9.0p-141L,
+     0xc30000.0p-24,  0x8b5ae6.0p-25,  0x1759f6e6b37de945a049a962e66c6.0p-139L,
+     0xc20000.0p-24,  0x8dfccb.0p-25,  0x1ad35ca6ed5147bdb6ddcaf59c425.0p-141L,
+     0xc10000.0p-24,  0x90a22b.0p-25,  0x1a1d71a87deba46bae9827221dc98.0p-139L,
+     0xbf8000.0p-24,  0x94a0d8.0p-25, -0x139e5210c2b730e28aba001a9b5e0.0p-140L,
+     0xbe8000.0p-24,  0x974f16.0p-25, -0x18f6ebcff3ed72e23e13431adc4a5.0p-141L,
+     0xbd8000.0p-24,  0x9a00f1.0p-25, -0x1aa268be39aab7148e8d80caa10b7.0p-139L,
+     0xbc8000.0p-24,  0x9cb672.0p-25, -0x14c8815839c5663663d15faed7771.0p-139L,
+     0xbb0000.0p-24,  0xa0cda1.0p-25,  0x1eaf46390dbb2438273918db7df5c.0p-141L,
+     0xba0000.0p-24,  0xa38c6e.0p-25,  0x138e20d831f698298adddd7f32686.0p-141L,
+     0xb90000.0p-24,  0xa64f05.0p-25, -0x1e8d3c41123615b147a5d47bc208f.0p-142L,
+     0xb80000.0p-24,  0xa91570.0p-25,  0x1ce28f5f3840b263acb4351104631.0p-140L,
+     0xb70000.0p-24,  0xabdfbb.0p-25, -0x186e5c0a42423457e22d8c650b355.0p-139L,
+     0xb60000.0p-24,  0xaeadef.0p-25, -0x14d41a0b2a08a465dc513b13f567d.0p-143L,
+     0xb50000.0p-24,  0xb18018.0p-25,  0x16755892770633947ffe651e7352f.0p-139L,
+     0xb40000.0p-24,  0xb45642.0p-25, -0x16395ebe59b15228bfe8798d10ff0.0p-142L,
+     0xb30000.0p-24,  0xb73077.0p-25,  0x1abc65c8595f088b61a335f5b688c.0p-140L,
+     0xb20000.0p-24,  0xba0ec4.0p-25, -0x1273089d3dad88e7d353e9967d548.0p-139L,
+     0xb10000.0p-24,  0xbcf133.0p-25,  0x10f9f67b1f4bbf45de06ecebfaf6d.0p-139L,
+     0xb00000.0p-24,  0xbfd7d2.0p-25, -0x109fab904864092b34edda19a831e.0p-140L,
+     0xaf0000.0p-24,  0xc2c2ac.0p-25, -0x1124680aa43333221d8a9b475a6ba.0p-139L,
+     0xae8000.0p-24,  0xc439b3.0p-25, -0x1f360cc4710fbfe24b633f4e8d84d.0p-140L,
+     0xad8000.0p-24,  0xc72afd.0p-25, -0x132d91f21d89c89c45003fc5d7807.0p-140L,
+     0xac8000.0p-24,  0xca20a2.0p-25, -0x16bf9b4d1f8da8002f2449e174504.0p-139L,
+     0xab8000.0p-24,  0xcd1aae.0p-25,  0x19deb5ce6a6a8717d5626e16acc7d.0p-141L,
+     0xaa8000.0p-24,  0xd0192f.0p-25,  0x1a29fb48f7d3ca87dabf351aa41f4.0p-139L,
+     0xaa0000.0p-24,  0xd19a20.0p-25,  0x1127d3c6457f9d79f51dcc73014c9.0p-141L,
+     0xa90000.0p-24,  0xd49f6a.0p-25, -0x1ba930e486a0ac42d1bf9199188e7.0p-141L,
+     0xa80000.0p-24,  0xd7a94b.0p-25, -0x1b6e645f31549dd1160bcc45c7e2c.0p-139L,
+     0xa70000.0p-24,  0xdab7d0.0p-25,  0x1118a425494b610665377f15625b6.0p-140L,
+     0xa68000.0p-24,  0xdc40d5.0p-25,  0x1966f24d29d3a2d1b2176010478be.0p-140L,
+     0xa58000.0p-24,  0xdf566d.0p-25, -0x1d8e52eb2248f0c95dd83626d7333.0p-142L,
+     0xa48000.0p-24,  0xe270ce.0p-25, -0x1ee370f96e6b67ccb006a5b9890ea.0p-140L,
+     0xa40000.0p-24,  0xe3ffce.0p-25,  0x1d155324911f56db28da4d629d00a.0p-140L,
+     0xa30000.0p-24,  0xe72179.0p-25, -0x1fe6e2f2f867d8f4d60c713346641.0p-140L,
+     0xa20000.0p-24,  0xea4812.0p-25,  0x1b7be9add7f4d3b3d406b6cbf3ce5.0p-140L,
+     0xa18000.0p-24,  0xebdd3d.0p-25,  0x1b3cfb3f7511dd73692609040ccc2.0p-139L,
+     0xa08000.0p-24,  0xef0b5b.0p-25, -0x1220de1f7301901b8ad85c25afd09.0p-139L,
+     0xa00000.0p-24,  0xf0a451.0p-25, -0x176364c9ac81cc8a4dfb804de6867.0p-140L,
+     0x9f0000.0p-24,  0xf3da16.0p-25,  0x1eed6b9aafac8d42f78d3e65d3727.0p-141L,
+     0x9e8000.0p-24,  0xf576e9.0p-25,  0x1d593218675af269647b783d88999.0p-139L,
+     0x9d8000.0p-24,  0xf8b47c.0p-25, -0x13e8eb7da053e063714615f7cc91d.0p-144L,
+     0x9d0000.0p-24,  0xfa553f.0p-25,  0x1c063259bcade02951686d5373aec.0p-139L,
+     0x9c0000.0p-24,  0xfd9ac5.0p-25,  0x1ef491085fa3c1649349630531502.0p-139L,
+     0x9b8000.0p-24,  0xff3f8c.0p-25,  0x1d607a7c2b8c5320619fb9433d841.0p-139L,
+     0x9a8000.0p-24,  0x814697.0p-24, -0x12ad3817004f3f0bdff99f932b273.0p-138L,
+     0x9a0000.0p-24,  0x821b06.0p-24, -0x189fc53117f9e54e78103a2bc1767.0p-141L,
+     0x990000.0p-24,  0x83c5f8.0p-24,  0x14cf15a048907b7d7f47ddb45c5a3.0p-139L,
+     0x988000.0p-24,  0x849c7d.0p-24,  0x1cbb1d35fb82873b04a9af1dd692c.0p-138L,
+     0x978000.0p-24,  0x864ba6.0p-24,  0x1128639b814f9b9770d8cb6573540.0p-138L,
+     0x970000.0p-24,  0x87244c.0p-24,  0x184733853300f002e836dfd47bd41.0p-139L,
+     0x968000.0p-24,  0x87fdaa.0p-24,  0x109d23aef77dd5cd7cc94306fb3ff.0p-140L,
+     0x958000.0p-24,  0x89b293.0p-24, -0x1a81ef367a59de2b41eeebd550702.0p-138L,
+     0x950000.0p-24,  0x8a8e20.0p-24, -0x121ad3dbb2f45275c917a30df4ac9.0p-138L,
+     0x948000.0p-24,  0x8b6a6a.0p-24, -0x1cfb981628af71a89df4e6df2e93b.0p-139L,
+     0x938000.0p-24,  0x8d253a.0p-24, -0x1d21730ea76cfdec367828734cae5.0p-139L,
+     0x930000.0p-24,  0x8e03c2.0p-24,  0x135cc00e566f76b87333891e0dec4.0p-138L,
+     0x928000.0p-24,  0x8ee30d.0p-24, -0x10fcb5df257a263e3bf446c6e3f69.0p-140L,
+     0x918000.0p-24,  0x90a3ee.0p-24, -0x16e171b15433d723a4c7380a448d8.0p-139L,
+     0x910000.0p-24,  0x918587.0p-24, -0x1d050da07f3236f330972da2a7a87.0p-139L,
+     0x908000.0p-24,  0x9267e7.0p-24,  0x1be03669a5268d21148c6002becd3.0p-139L,
+     0x8f8000.0p-24,  0x942f04.0p-24,  0x10b28e0e26c336af90e00533323ba.0p-139L,
+     0x8f0000.0p-24,  0x9513c3.0p-24,  0x1a1d820da57cf2f105a89060046aa.0p-138L,
+     0x8e8000.0p-24,  0x95f950.0p-24, -0x19ef8f13ae3cf162409d8ea99d4c0.0p-139L,
+     0x8e0000.0p-24,  0x96dfab.0p-24, -0x109e417a6e507b9dc10dac743ad7a.0p-138L,
+     0x8d0000.0p-24,  0x98aed2.0p-24,  0x10d01a2c5b0e97c4990b23d9ac1f5.0p-139L,
+     0x8c8000.0p-24,  0x9997a2.0p-24, -0x1d6a50d4b61ea74540bdd2aa99a42.0p-138L,
+     0x8c0000.0p-24,  0x9a8145.0p-24,  0x1b3b190b83f9527e6aba8f2d783c1.0p-138L,
+     0x8b8000.0p-24,  0x9b6bbf.0p-24,  0x13a69fad7e7abe7ba81c664c107e0.0p-138L,
+     0x8b0000.0p-24,  0x9c5711.0p-24, -0x11cd12316f576aad348ae79867223.0p-138L,
+     0x8a8000.0p-24,  0x9d433b.0p-24,  0x1c95c444b807a246726b304ccae56.0p-139L,
+     0x898000.0p-24,  0x9f1e22.0p-24, -0x1b9c224ea698c2f9b47466d6123fe.0p-139L,
+     0x890000.0p-24,  0xa00ce1.0p-24,  0x125ca93186cf0f38b4619a2483399.0p-141L,
+     0x888000.0p-24,  0xa0fc80.0p-24, -0x1ee38a7bc228b3597043be78eaf49.0p-139L,
+     0x880000.0p-24,  0xa1ed00.0p-24, -0x1a0db876613d204147dc69a07a649.0p-138L,
+     0x878000.0p-24,  0xa2de62.0p-24,  0x193224e8516c008d3602a7b41c6e8.0p-139L,
+     0x870000.0p-24,  0xa3d0a9.0p-24,  0x1fa28b4d2541aca7d5844606b2421.0p-139L,
+     0x868000.0p-24,  0xa4c3d6.0p-24,  0x1c1b5760fb4571acbcfb03f16daf4.0p-138L,
+     0x858000.0p-24,  0xa6acea.0p-24,  0x1fed5d0f65949c0a345ad743ae1ae.0p-140L,
+     0x850000.0p-24,  0xa7a2d4.0p-24,  0x1ad270c9d749362382a7688479e24.0p-140L,
+     0x848000.0p-24,  0xa899ab.0p-24,  0x199ff15ce532661ea9643a3a2d378.0p-139L,
+     0x840000.0p-24,  0xa99171.0p-24,  0x1a19e15ccc45d257530a682b80490.0p-139L,
+     0x838000.0p-24,  0xaa8a28.0p-24, -0x121a14ec532b35ba3e1f868fd0b5e.0p-140L,
+     0x830000.0p-24,  0xab83d1.0p-24,  0x1aee319980bff3303dd481779df69.0p-139L,
+     0x828000.0p-24,  0xac7e6f.0p-24, -0x18ffd9e3900345a85d2d86161742e.0p-140L,
+     0x820000.0p-24,  0xad7a03.0p-24, -0x1e4db102ce29f79b026b64b42caa1.0p-140L,
+     0x818000.0p-24,  0xae768f.0p-24,  0x17c35c55a04a82ab19f77652d977a.0p-141L,
+     0x810000.0p-24,  0xaf7415.0p-24,  0x1448324047019b48d7b98c1cf7234.0p-138L,
+     0x808000.0p-24,  0xb07298.0p-24, -0x1750ee3915a197e9c7359dd94152f.0p-138L,
+     0x800000.0p-24,  0xb17218.0p-24, -0x105c610ca86c3898cff81a12a17e2.0p-141L,
+};
+
+#ifdef USE_UTAB
+static const struct {
+	float	H;			/* 1 + i/INTERVALS (exact) */
+	float	E;			/* H(i) * G(i) - 1 (exact) */
+} U[TSIZE] = {
+	 0x800000.0p-23,  0,
+	 0x810000.0p-23, -0x800000.0p-37,
+	 0x820000.0p-23, -0x800000.0p-35,
+	 0x830000.0p-23, -0x900000.0p-34,
+	 0x840000.0p-23, -0x800000.0p-33,
+	 0x850000.0p-23, -0xc80000.0p-33,
+	 0x860000.0p-23, -0xa00000.0p-36,
+	 0x870000.0p-23,  0x940000.0p-33,
+	 0x880000.0p-23,  0x800000.0p-35,
+	 0x890000.0p-23, -0xc80000.0p-34,
+	 0x8a0000.0p-23,  0xe00000.0p-36,
+	 0x8b0000.0p-23,  0x900000.0p-33,
+	 0x8c0000.0p-23, -0x800000.0p-35,
+	 0x8d0000.0p-23, -0xe00000.0p-33,
+	 0x8e0000.0p-23,  0x880000.0p-33,
+	 0x8f0000.0p-23, -0xa80000.0p-34,
+	 0x900000.0p-23, -0x800000.0p-35,
+	 0x910000.0p-23,  0x800000.0p-37,
+	 0x920000.0p-23,  0x900000.0p-35,
+	 0x930000.0p-23,  0xd00000.0p-35,
+	 0x940000.0p-23,  0xe00000.0p-35,
+	 0x950000.0p-23,  0xc00000.0p-35,
+	 0x960000.0p-23,  0xe00000.0p-36,
+	 0x970000.0p-23, -0x800000.0p-38,
+	 0x980000.0p-23, -0xc00000.0p-35,
+	 0x990000.0p-23, -0xd00000.0p-34,
+	 0x9a0000.0p-23,  0x880000.0p-33,
+	 0x9b0000.0p-23,  0xe80000.0p-35,
+	 0x9c0000.0p-23, -0x800000.0p-35,
+	 0x9d0000.0p-23,  0xb40000.0p-33,
+	 0x9e0000.0p-23,  0x880000.0p-34,
+	 0x9f0000.0p-23, -0xe00000.0p-35,
+	 0xa00000.0p-23,  0x800000.0p-33,
+	 0xa10000.0p-23, -0x900000.0p-36,
+	 0xa20000.0p-23, -0xb00000.0p-33,
+	 0xa30000.0p-23, -0xa00000.0p-36,
+	 0xa40000.0p-23,  0x800000.0p-33,
+	 0xa50000.0p-23, -0xf80000.0p-35,
+	 0xa60000.0p-23,  0x880000.0p-34,
+	 0xa70000.0p-23, -0x900000.0p-33,
+	 0xa80000.0p-23, -0x800000.0p-35,
+	 0xa90000.0p-23,  0x900000.0p-34,
+	 0xaa0000.0p-23,  0xa80000.0p-33,
+	 0xab0000.0p-23, -0xac0000.0p-34,
+	 0xac0000.0p-23, -0x800000.0p-37,
+	 0xad0000.0p-23,  0xf80000.0p-35,
+	 0xae0000.0p-23,  0xf80000.0p-34,
+	 0xaf0000.0p-23, -0xac0000.0p-33,
+	 0xb00000.0p-23, -0x800000.0p-33,
+	 0xb10000.0p-23, -0xb80000.0p-34,
+	 0xb20000.0p-23, -0x800000.0p-34,
+	 0xb30000.0p-23, -0xb00000.0p-35,
+	 0xb40000.0p-23, -0x800000.0p-35,
+	 0xb50000.0p-23, -0xe00000.0p-36,
+	 0xb60000.0p-23, -0x800000.0p-35,
+	 0xb70000.0p-23, -0xb00000.0p-35,
+	 0xb80000.0p-23, -0x800000.0p-34,
+	 0xb90000.0p-23, -0xb80000.0p-34,
+	 0xba0000.0p-23, -0x800000.0p-33,
+	 0xbb0000.0p-23, -0xac0000.0p-33,
+	 0xbc0000.0p-23,  0x980000.0p-33,
+	 0xbd0000.0p-23,  0xbc0000.0p-34,
+	 0xbe0000.0p-23,  0xe00000.0p-36,
+	 0xbf0000.0p-23, -0xb80000.0p-35,
+	 0xc00000.0p-23, -0x800000.0p-33,
+	 0xc10000.0p-23,  0xa80000.0p-33,
+	 0xc20000.0p-23,  0x900000.0p-34,
+	 0xc30000.0p-23, -0x800000.0p-35,
+	 0xc40000.0p-23, -0x900000.0p-33,
+	 0xc50000.0p-23,  0x820000.0p-33,
+	 0xc60000.0p-23,  0x800000.0p-38,
+	 0xc70000.0p-23, -0x820000.0p-33,
+	 0xc80000.0p-23,  0x800000.0p-33,
+	 0xc90000.0p-23, -0xa00000.0p-36,
+	 0xca0000.0p-23, -0xb00000.0p-33,
+	 0xcb0000.0p-23,  0x840000.0p-34,
+	 0xcc0000.0p-23, -0xd00000.0p-34,
+	 0xcd0000.0p-23,  0x800000.0p-33,
+	 0xce0000.0p-23, -0xe00000.0p-35,
+	 0xcf0000.0p-23,  0xa60000.0p-33,
+	 0xd00000.0p-23, -0x800000.0p-35,
+	 0xd10000.0p-23,  0xb40000.0p-33,
+	 0xd20000.0p-23, -0x800000.0p-35,
+	 0xd30000.0p-23,  0xaa0000.0p-33,
+	 0xd40000.0p-23, -0xe00000.0p-35,
+	 0xd50000.0p-23,  0x880000.0p-33,
+	 0xd60000.0p-23, -0xd00000.0p-34,
+	 0xd70000.0p-23,  0x9c0000.0p-34,
+	 0xd80000.0p-23, -0xb00000.0p-33,
+	 0xd90000.0p-23, -0x800000.0p-38,
+	 0xda0000.0p-23,  0xa40000.0p-33,
+	 0xdb0000.0p-23, -0xdc0000.0p-34,
+	 0xdc0000.0p-23,  0xc00000.0p-35,
+	 0xdd0000.0p-23,  0xca0000.0p-33,
+	 0xde0000.0p-23, -0xb80000.0p-34,
+	 0xdf0000.0p-23,  0xd00000.0p-35,
+	 0xe00000.0p-23,  0xc00000.0p-33,
+	 0xe10000.0p-23, -0xf40000.0p-34,
+	 0xe20000.0p-23,  0x800000.0p-37,
+	 0xe30000.0p-23,  0x860000.0p-33,
+	 0xe40000.0p-23, -0xc80000.0p-33,
+	 0xe50000.0p-23, -0xa80000.0p-34,
+	 0xe60000.0p-23,  0xe00000.0p-36,
+	 0xe70000.0p-23,  0x880000.0p-33,
+	 0xe80000.0p-23, -0xe00000.0p-33,
+	 0xe90000.0p-23, -0xfc0000.0p-34,
+	 0xea0000.0p-23, -0x800000.0p-35,
+	 0xeb0000.0p-23,  0xe80000.0p-35,
+	 0xec0000.0p-23,  0x900000.0p-33,
+	 0xed0000.0p-23,  0xe20000.0p-33,
+	 0xee0000.0p-23, -0xac0000.0p-33,
+	 0xef0000.0p-23, -0xc80000.0p-34,
+	 0xf00000.0p-23, -0x800000.0p-35,
+	 0xf10000.0p-23,  0x800000.0p-35,
+	 0xf20000.0p-23,  0xb80000.0p-34,
+	 0xf30000.0p-23,  0x940000.0p-33,
+	 0xf40000.0p-23,  0xc80000.0p-33,
+	 0xf50000.0p-23, -0xf20000.0p-33,
+	 0xf60000.0p-23, -0xc80000.0p-33,
+	 0xf70000.0p-23, -0xa20000.0p-33,
+	 0xf80000.0p-23, -0x800000.0p-33,
+	 0xf90000.0p-23, -0xc40000.0p-34,
+	 0xfa0000.0p-23, -0x900000.0p-34,
+	 0xfb0000.0p-23, -0xc80000.0p-35,
+	 0xfc0000.0p-23, -0x800000.0p-35,
+	 0xfd0000.0p-23, -0x900000.0p-36,
+	 0xfe0000.0p-23, -0x800000.0p-37,
+	 0xff0000.0p-23, -0x800000.0p-39,
+	 0x800000.0p-22,  0,
+};
+#endif /* USE_UTAB */
+
+#ifdef STRUCT_RETURN
+#define	RETURN1(rp, v) do {	\
+	(rp)->hi = (v);		\
+	(rp)->lo_set = 0;	\
+	return;			\
+} while (0)
+
+#define	RETURN2(rp, h, l) do {	\
+	(rp)->hi = (h);		\
+	(rp)->lo = (l);		\
+	(rp)->lo_set = 1;	\
+	return;			\
+} while (0)
+
+struct ld {
+	long double hi;
+	long double lo;
+	int	lo_set;
+};
+#else
+#define	RETURN1(rp, v)	RETURNF(v)
+#define	RETURN2(rp, h, l)	RETURNI((h) + (l))
+#endif
+
+#ifdef STRUCT_RETURN
+static inline __always_inline void
+k_logl(long double x, struct ld *rp)
+#else
+long double
+logl(long double x)
+#endif
+{
+	long double d, val_hi, val_lo;
+	double dd, dk;
+	uint64_t lx, llx;
+	int i, k;
+	uint16_t hx;
+
+	EXTRACT_LDBL128_WORDS(hx, lx, llx, x);
+	k = -16383;
+#if 0 /* Hard to do efficiently.  Don't do it until we support all modes. */
+	if (x == 1)
+		RETURN1(rp, 0);		/* log(1) = +0 in all rounding modes */
+#endif
+	if (hx == 0 || hx >= 0x8000) {	/* zero, negative or subnormal? */
+		if (((hx & 0x7fff) | lx | llx) == 0)
+			RETURN1(rp, -1 / zero);	/* log(+-0) = -Inf */
+		if (hx != 0)
+			/* log(neg or NaN) = qNaN: */
+			RETURN1(rp, (x - x) / zero);
+		x *= 0x1.0p113;		/* subnormal; scale up x */
+		EXTRACT_LDBL128_WORDS(hx, lx, llx, x);
+		k = -16383 - 113;
+	} else if (hx >= 0x7fff)
+		RETURN1(rp, x + x);	/* log(Inf or NaN) = Inf or qNaN */
+#ifndef STRUCT_RETURN
+	ENTERI();
+#endif
+	k += hx;
+	dk = k;
+
+	/* Scale x to be in [1, 2). */
+	SET_LDBL_EXPSIGN(x, 0x3fff);
+
+	/* 0 <= i <= INTERVALS: */
+#define	L2I	(49 - LOG2_INTERVALS)
+	i = (lx + (1LL << (L2I - 2))) >> (L2I - 1);
+
+	/*
+	 * -0.005280 < d < 0.004838.  In particular, the infinite-
+	 * precision |d| is <= 2**-7.  Rounding of G(i) to 8 bits
+	 * ensures that d is representable without extra precision for
+	 * this bound on |d| (since when this calculation is expressed
+	 * as x*G(i)-1, the multiplication needs as many extra bits as
+	 * G(i) has and the subtraction cancels 8 bits).  But for
+	 * most i (107 cases out of 129), the infinite-precision |d|
+	 * is <= 2**-8.  G(i) is rounded to 9 bits for such i to give
+	 * better accuracy (this works by improving the bound on |d|,
+	 * which in turn allows rounding to 9 bits in more cases).
+	 * This is only important when the original x is near 1 -- it
+	 * lets us avoid using a special method to give the desired
+	 * accuracy for such x.
+	 */
+	if (0)
+		d = x * G(i) - 1;
+	else {
+#ifdef USE_UTAB
+		d = (x - H(i)) * G(i) + E(i);
+#else
+		long double x_hi;
+		double x_lo;
+
+		/*
+		 * Split x into x_hi + x_lo to calculate x*G(i)-1 exactly.
+		 * G(i) has at most 9 bits, so the splitting point is not
+		 * critical.
+		 */
+		INSERT_LDBL128_WORDS(x_hi, 0x3fff, lx,
+		    llx & 0xffffffffff000000ULL);
+		x_lo = x - x_hi;
+		d = x_hi * G(i) - 1 + x_lo * G(i);
+#endif
+	}
+
+	/*
+	 * Our algorithm depends on exact cancellation of F_lo(i) and
+	 * F_hi(i) with dk*ln_2_lo and dk*ln2_hi when k is -1 and i is
+	 * at the end of the table.  This and other technical complications
+	 * make it difficult to avoid the double scaling in (dk*ln2) *
+	 * log(base) for base != e without losing more accuracy and/or
+	 * efficiency than is gained.
+	 */
+	/*
+	 * Use double precision operations wherever possible, since long
+	 * double operations are emulated and are very slow on the only
+	 * known machines that support ld128 (sparc64).  Also, don't try
+	 * to improve parallelism by increasing the number of operations,
+	 * since any parallelism on such machines is needed for the
+	 * emulation.  Horner's method is good for this, and is also good
+	 * for accuracy.  Horner's method doesn't handle the `lo' term
+	 * well, either for efficiency or accuracy.  However, for accuracy
+	 * we evaluate d * d * P2 separately to take advantage of
+	 * by P2 being exact, and this gives a good place to sum the 'lo'
+	 * term too.
+	 */
+	dd = (double)d;
+	val_lo = d * d * d * (P3 +
+	    d * (P4 + d * (P5 + d * (P6 + d * (P7 + d * (P8 +
+	    dd * (P9 + dd * (P10 + dd * (P11 + dd * (P12 + dd * (P13 +
+	    dd * P14))))))))))) + (F_lo(i) + dk * ln2_lo) + d * d * P2;
+	val_hi = d;
+#ifdef DEBUG
+	if (fetestexcept(FE_UNDERFLOW))
+		breakpoint();
+#endif
+
+	_3sumF(val_hi, val_lo, F_hi(i) + dk * ln2_hi);
+	RETURN2(rp, val_hi, val_lo);
+}
+
+long double
+log1pl(long double x)
+{
+	long double d, d_hi, f_lo, val_hi, val_lo;
+	long double f_hi, twopminusk;
+	double d_lo, dd, dk;
+	uint64_t lx, llx;
+	int i, k;
+	int16_t ax, hx;
+
+	DOPRINT_START(&x);
+	EXTRACT_LDBL128_WORDS(hx, lx, llx, x);
+	if (hx < 0x3fff) {		/* x < 1, or x neg NaN */
+		ax = hx & 0x7fff;
+		if (ax >= 0x3fff) {	/* x <= -1, or x neg NaN */
+			if (ax == 0x3fff && (lx | llx) == 0)
+				RETURNP(-1 / zero);	/* log1p(-1) = -Inf */
+			/* log1p(x < 1, or x NaN) = qNaN: */
+			RETURNP((x - x) / (x - x));
+		}
+		if (ax <= 0x3f8d) {	/* |x| < 2**-113 */
+			if ((int)x == 0)
+				RETURNP(x);	/* x with inexact if x != 0 */
+		}
+		f_hi = 1;
+		f_lo = x;
+	} else if (hx >= 0x7fff) {	/* x +Inf or non-neg NaN */
+		RETURNP(x + x);		/* log1p(Inf or NaN) = Inf or qNaN */
+	} else if (hx < 0x40e1) {	/* 1 <= x < 2**226 */
+		f_hi = x;
+		f_lo = 1;
+	} else {			/* 2**226 <= x < +Inf */
+		f_hi = x;
+		f_lo = 0;		/* avoid underflow of the P3 term */
+	}
+	ENTERI();
+	x = f_hi + f_lo;
+	f_lo = (f_hi - x) + f_lo;
+
+	EXTRACT_LDBL128_WORDS(hx, lx, llx, x);
+	k = -16383;
+
+	k += hx;
+	dk = k;
+
+	SET_LDBL_EXPSIGN(x, 0x3fff);
+	twopminusk = 1;
+	SET_LDBL_EXPSIGN(twopminusk, 0x7ffe - (hx & 0x7fff));
+	f_lo *= twopminusk;
+
+	i = (lx + (1LL << (L2I - 2))) >> (L2I - 1);
+
+	/*
+	 * x*G(i)-1 (with a reduced x) can be represented exactly, as
+	 * above, but now we need to evaluate the polynomial on d =
+	 * (x+f_lo)*G(i)-1 and extra precision is needed for that.
+	 * Since x+x_lo is a hi+lo decomposition and subtracting 1
+	 * doesn't lose too many bits, an inexact calculation for
+	 * f_lo*G(i) is good enough.
+	 */
+	if (0)
+		d_hi = x * G(i) - 1;
+	else {
+#ifdef USE_UTAB
+		d_hi = (x - H(i)) * G(i) + E(i);
+#else
+		long double x_hi;
+		double x_lo;
+
+		INSERT_LDBL128_WORDS(x_hi, 0x3fff, lx,
+		    llx & 0xffffffffff000000ULL);
+		x_lo = x - x_hi;
+		d_hi = x_hi * G(i) - 1 + x_lo * G(i);
+#endif
+	}
+	d_lo = f_lo * G(i);
+
+	/*
+	 * This is _2sumF(d_hi, d_lo) inlined.  The condition
+	 * (d_hi == 0 || |d_hi| >= |d_lo|) for using _2sumF() is not
+	 * always satisifed, so it is not clear that this works, but
+	 * it works in practice.  It works even if it gives a wrong
+	 * normalized d_lo, since |d_lo| > |d_hi| implies that i is
+	 * nonzero and d is tiny, so the F(i) term dominates d_lo.
+	 * In float precision:
+	 * (By exhaustive testing, the worst case is d_hi = 0x1.bp-25.
+	 * And if d is only a little tinier than that, we would have
+	 * another underflow problem for the P3 term; this is also ruled
+	 * out by exhaustive testing.)
+	 */
+	d = d_hi + d_lo;
+	d_lo = d_hi - d + d_lo;
+	d_hi = d;
+
+	dd = (double)d;
+	val_lo = d * d * d * (P3 +
+	    d * (P4 + d * (P5 + d * (P6 + d * (P7 + d * (P8 +
+	    dd * (P9 + dd * (P10 + dd * (P11 + dd * (P12 + dd * (P13 +
+	    dd * P14))))))))))) + (F_lo(i) + dk * ln2_lo + d_lo) + d * d * P2;
+	val_hi = d_hi;
+#ifdef DEBUG
+	if (fetestexcept(FE_UNDERFLOW))
+		breakpoint();
+#endif
+
+	_3sumF(val_hi, val_lo, F_hi(i) + dk * ln2_hi);
+	RETURN2PI(val_hi, val_lo);
+}
+
+#ifdef STRUCT_RETURN
+
+long double
+logl(long double x)
+{
+	struct ld r;
+
+	ENTERI();
+	DOPRINT_START(&x);
+	k_logl(x, &r);
+	RETURNSPI(&r);
+}
+
+/*
+ * 29+113 bit decompositions.  The bits are distributed so that the products
+ * of the hi terms are exact in double precision.  The types are chosen so
+ * that the products of the hi terms are done in at least double precision,
+ * without any explicit conversions.  More natural choices would require a
+ * slow long double precision multiplication.
+ */
+static const double
+invln10_hi =  4.3429448176175356e-1,		/*  0x1bcb7b15000000.0p-54 */
+invln2_hi =  1.4426950402557850e0;		/*  0x17154765000000.0p-52 */
+static const long double
+invln10_lo =  1.41498268538580090791605082294397000e-10L,	/*  0x137287195355baaafad33dc323ee3.0p-145L */
+invln2_lo =  6.33178418956604368501892137426645911e-10L;	/*  0x15c17f0bbbe87fed0691d3e88eb57.0p-143L */
+
+long double
+log10l(long double x)
+{
+	struct ld r;
+	long double lo;
+	float hi;
+
+	ENTERI();
+	DOPRINT_START(&x);
+	k_logl(x, &r);
+	if (!r.lo_set)
+		RETURNPI(r.hi);
+	_2sumF(r.hi, r.lo);
+	hi = r.hi;
+	lo = r.lo + (r.hi - hi);
+	RETURN2PI(invln10_hi * hi,
+	    (invln10_lo + invln10_hi) * lo + invln10_lo * hi);
+}
+
+long double
+log2l(long double x)
+{
+	struct ld r;
+	long double lo;
+	float hi;
+
+	ENTERI();
+	DOPRINT_START(&x);
+	k_logl(x, &r);
+	if (!r.lo_set)
+		RETURNPI(r.hi);
+	_2sumF(r.hi, r.lo);
+	hi = r.hi;
+	lo = r.lo + (r.hi - hi);
+	RETURN2PI(invln2_hi * hi,
+	    (invln2_lo + invln2_hi) * lo + invln2_lo * hi);
+}
+
+#endif /* STRUCT_RETURN */
diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c b/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c
new file mode 100644
index 0000000..0f74a13
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2007 David Schultz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <math.h>
+
+#include "fpmath.h"
+#include "../src/math_private.h"
+
+long double
+nanl(const char *s)
+{
+	union {
+		union IEEEl2bits ieee;
+		uint32_t bits[4];
+	} u;
+
+	_scan_nan(u.bits, 4, s);
+	u.ieee.bits.exp = 0x7fff;
+	u.ieee.bits.manh |= 1ULL << 47;	/* make it a quiet NaN */
+	return (u.ieee.e);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/e_acoshl.c b/libm/upstream-freebsd/lib/msun/src/e_acoshl.c
new file mode 100644
index 0000000..59faeb0
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_acoshl.c
@@ -0,0 +1,89 @@
+/* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */
+
+/* @(#)e_acosh.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * See e_acosh.c for complete comments.
+ *
+ * Converted to long double by David Schultz <das@FreeBSD.ORG> and
+ * Bruce D. Evans.
+ */
+
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+/* EXP_LARGE is the threshold above which we use acosh(x) ~= log(2x). */
+#if LDBL_MANT_DIG == 64
+#define	EXP_LARGE	34
+#elif LDBL_MANT_DIG == 113
+#define	EXP_LARGE	58
+#else
+#error "Unsupported long double format"
+#endif
+
+#if LDBL_MAX_EXP != 0x4000
+/* We also require the usual expsign encoding. */
+#error "Unsupported long double format"
+#endif
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+
+static const double
+one	= 1.0;
+
+#if LDBL_MANT_DIG == 64
+static const union IEEEl2bits
+u_ln2 =  LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
+#define	ln2	u_ln2.e
+#elif LDBL_MANT_DIG == 113
+static const long double
+ln2 =  6.93147180559945309417232121458176568e-1L;	/* 0x162e42fefa39ef35793c7673007e6.0p-113 */
+#else
+#error "Unsupported long double format"
+#endif
+
+long double
+acoshl(long double x)
+{
+	long double t;
+	int16_t hx;
+
+	ENTERI();
+	GET_LDBL_EXPSIGN(hx, x);
+	if (hx < 0x3fff) {		/* x < 1, or misnormal */
+	    RETURNI((x-x)/(x-x));
+	} else if (hx >= BIAS + EXP_LARGE) { /* x >= LARGE */
+	    if (hx >= 0x7fff) {		/* x is inf, NaN or misnormal */
+	        RETURNI(x+x);
+	    } else
+		RETURNI(logl(x)+ln2);	/* acosh(huge)=log(2x), or misnormal */
+	} else if (hx == 0x3fff && x == 1) {
+	    RETURNI(0.0);		/* acosh(1) = 0 */
+	} else if (hx >= 0x4000) {	/* LARGE > x >= 2, or misnormal */
+	    t=x*x;
+	    RETURNI(logl(2.0*x-one/(x+sqrtl(t-one))));
+	} else {			/* 1<x<2 */
+	    t = x-one;
+	    RETURNI(log1pl(t+sqrtl(2.0*t+t*t)));
+	}
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/e_atanhl.c b/libm/upstream-freebsd/lib/msun/src/e_atanhl.c
new file mode 100644
index 0000000..a888426
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_atanhl.c
@@ -0,0 +1,74 @@
+/* from: FreeBSD: head/lib/msun/src/e_atanh.c 176451 2008-02-22 02:30:36Z das */
+
+/* @(#)e_atanh.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * See e_atanh.c for complete comments.
+ *
+ * Converted to long double by David Schultz <das@FreeBSD.ORG> and
+ * Bruce D. Evans.
+ */
+
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+/* EXP_TINY is the threshold below which we use atanh(x) ~= x. */
+#if LDBL_MANT_DIG == 64
+#define	EXP_TINY	-34
+#elif LDBL_MANT_DIG == 113
+#define	EXP_TINY	-58
+#else
+#error "Unsupported long double format"
+#endif
+
+#if LDBL_MAX_EXP != 0x4000
+/* We also require the usual expsign encoding. */
+#error "Unsupported long double format"
+#endif
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+
+static const double one = 1.0, huge = 1e300;
+static const double zero = 0.0;
+
+long double
+atanhl(long double x)
+{
+	long double t;
+	uint16_t hx, ix;
+
+	ENTERI();
+	GET_LDBL_EXPSIGN(hx, x);
+	ix = hx & 0x7fff;
+	if (ix >= 0x3fff)		/* |x| >= 1, or NaN or misnormal */
+	    RETURNI(fabsl(x) == 1 ? x / zero : (x - x) / (x - x));
+	if (ix < BIAS + EXP_TINY && (huge + x) > zero)
+	    RETURNI(x);			/* x is tiny */
+	SET_LDBL_EXPSIGN(x, ix);
+	if (ix < 0x3ffe) {		/* |x| < 0.5, or misnormal */
+	    t = x+x;
+	    t = 0.5*log1pl(t+t*x/(one-x));
+	} else
+	    t = 0.5*log1pl((x+x)/(one-x));
+	RETURNI((hx & 0x8000) == 0 ? t : -t);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/imprecise.c b/libm/upstream-freebsd/lib/msun/src/imprecise.c
new file mode 100644
index 0000000..a7503bf
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/imprecise.c
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2013 David Chisnall
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <float.h>
+#include <math.h>
+
+/*
+ * If long double is not the same size as double, then these will lose
+ * precision and we should emit a warning whenever something links against
+ * them.
+ */
+#if (LDBL_MANT_DIG > 53)
+#define WARN_IMPRECISE(x) \
+	__warn_references(x, # x " has lower than advertised precision");
+#else
+#define WARN_IMPRECISE(x)
+#endif
+/*
+ * Declare the functions as weak variants so that other libraries providing
+ * real versions can override them.
+ */
+#define	DECLARE_WEAK(x)\
+	__weak_reference(imprecise_## x, x);\
+	WARN_IMPRECISE(x)
+
+long double
+imprecise_powl(long double x, long double y)
+{
+
+	return pow(x, y);
+}
+DECLARE_WEAK(powl);
+
+#define DECLARE_IMPRECISE(f) \
+	long double imprecise_ ## f ## l(long double v) { return f(v); }\
+	DECLARE_WEAK(f ## l)
+
+DECLARE_IMPRECISE(cosh);
+DECLARE_IMPRECISE(erfc);
+DECLARE_IMPRECISE(erf);
+DECLARE_IMPRECISE(lgamma);
+DECLARE_IMPRECISE(sinh);
+DECLARE_IMPRECISE(tanh);
+DECLARE_IMPRECISE(tgamma);
diff --git a/libm/upstream-freebsd/lib/msun/src/math_private.h b/libm/upstream-freebsd/lib/msun/src/math_private.h
index 8ebc7fb..8af2c65 100644
--- a/libm/upstream-freebsd/lib/msun/src/math_private.h
+++ b/libm/upstream-freebsd/lib/msun/src/math_private.h
@@ -39,7 +39,7 @@
  */
 
 #ifdef __arm__
-#if defined(__VFP_FP__)
+#if defined(__VFP_FP__) || defined(__ARM_EABI__)
 #define	IEEE_WORD_ORDER	BYTE_ORDER
 #else
 #define	IEEE_WORD_ORDER	BIG_ENDIAN
diff --git a/libm/upstream-freebsd/lib/msun/src/s_asinhl.c b/libm/upstream-freebsd/lib/msun/src/s_asinhl.c
new file mode 100644
index 0000000..ba28f59
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_asinhl.c
@@ -0,0 +1,91 @@
+/* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */
+
+/* @(#)s_asinh.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * See s_asinh.c for complete comments.
+ *
+ * Converted to long double by David Schultz <das@FreeBSD.ORG> and
+ * Bruce D. Evans.
+ */
+
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+/* EXP_LARGE is the threshold above which we use asinh(x) ~= log(2x). */
+/* EXP_TINY is the threshold below which we use asinh(x) ~= x. */
+#if LDBL_MANT_DIG == 64
+#define	EXP_LARGE	34
+#define	EXP_TINY	-34
+#elif LDBL_MANT_DIG == 113
+#define	EXP_LARGE	58
+#define	EXP_TINY	-58
+#else
+#error "Unsupported long double format"
+#endif
+
+#if LDBL_MAX_EXP != 0x4000
+/* We also require the usual expsign encoding. */
+#error "Unsupported long double format"
+#endif
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+
+static const double
+one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
+huge=  1.00000000000000000000e+300;
+
+#if LDBL_MANT_DIG == 64
+static const union IEEEl2bits
+u_ln2 =  LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
+#define	ln2	u_ln2.e
+#elif LDBL_MANT_DIG == 113
+static const long double
+ln2 =  6.93147180559945309417232121458176568e-1L;	/* 0x162e42fefa39ef35793c7673007e6.0p-113 */
+#else
+#error "Unsupported long double format"
+#endif
+
+long double
+asinhl(long double x)
+{
+	long double t, w;
+	uint16_t hx, ix;
+
+	ENTERI();
+	GET_LDBL_EXPSIGN(hx, x);
+	ix = hx & 0x7fff;
+	if (ix >= 0x7fff) RETURNI(x+x);	/* x is inf, NaN or misnormal */
+	if (ix < BIAS + EXP_TINY) {	/* |x| < TINY, or misnormal */
+	    if (huge + x > one) RETURNI(x);	/* return x inexact except 0 */
+	}
+	if (ix >= BIAS + EXP_LARGE) {	/* |x| >= LARGE, or misnormal */
+	    w = logl(fabsl(x))+ln2;
+	} else if (ix >= 0x4000) {	/* LARGE > |x| >= 2.0, or misnormal */
+	    t = fabsl(x);
+	    w = logl(2.0*t+one/(sqrtl(x*x+one)+t));
+	} else {		/* 2.0 > |x| >= TINY, or misnormal */
+	    t = x*x;
+	    w =log1pl(fabsl(x)+t/(one+sqrtl(one+t)));
+	}
+	RETURNI((hx & 0x8000) == 0 ? w : -w);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_erff.c b/libm/upstream-freebsd/lib/msun/src/s_erff.c
index a44e135..a3579f1 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_erff.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_erff.c
@@ -24,75 +24,59 @@
 half=  5.0000000000e-01, /* 0x3F000000 */
 one =  1.0000000000e+00, /* 0x3F800000 */
 two =  2.0000000000e+00, /* 0x40000000 */
-	/* c = (subfloat)0.84506291151 */
-erx =  8.4506291151e-01, /* 0x3f58560b */
 /*
  * Coefficients for approximation to  erf on [0,0.84375]
  */
 efx =  1.2837916613e-01, /* 0x3e0375d4 */
 efx8=  1.0270333290e+00, /* 0x3f8375d4 */
-pp0  =  1.2837916613e-01, /* 0x3e0375d4 */
-pp1  = -3.2504209876e-01, /* 0xbea66beb */
-pp2  = -2.8481749818e-02, /* 0xbce9528f */
-pp3  = -5.7702702470e-03, /* 0xbbbd1489 */
-pp4  = -2.3763017452e-05, /* 0xb7c756b1 */
-qq1  =  3.9791721106e-01, /* 0x3ecbbbce */
-qq2  =  6.5022252500e-02, /* 0x3d852a63 */
-qq3  =  5.0813062117e-03, /* 0x3ba68116 */
-qq4  =  1.3249473704e-04, /* 0x390aee49 */
-qq5  = -3.9602282413e-06, /* 0xb684e21a */
 /*
- * Coefficients for approximation to  erf  in [0.84375,1.25]
+ *  Domain [0, 0.84375], range ~[-5.4446e-10,5.5197e-10]:
+ *  |(erf(x) - x)/x - p(x)/q(x)| < 2**-31.
  */
-pa0  = -2.3621185683e-03, /* 0xbb1acdc6 */
-pa1  =  4.1485610604e-01, /* 0x3ed46805 */
-pa2  = -3.7220788002e-01, /* 0xbebe9208 */
-pa3  =  3.1834661961e-01, /* 0x3ea2fe54 */
-pa4  = -1.1089469492e-01, /* 0xbde31cc2 */
-pa5  =  3.5478305072e-02, /* 0x3d1151b3 */
-pa6  = -2.1663755178e-03, /* 0xbb0df9c0 */
-qa1  =  1.0642088205e-01, /* 0x3dd9f331 */
-qa2  =  5.4039794207e-01, /* 0x3f0a5785 */
-qa3  =  7.1828655899e-02, /* 0x3d931ae7 */
-qa4  =  1.2617121637e-01, /* 0x3e013307 */
-qa5  =  1.3637083583e-02, /* 0x3c5f6e13 */
-qa6  =  1.1984500103e-02, /* 0x3c445aa3 */
+pp0  =  1.28379166e-01F, /*  0x1.06eba8p-3 */
+pp1  = -3.36030394e-01F, /* -0x1.58185ap-2 */
+pp2  = -1.86260219e-03F, /* -0x1.e8451ep-10 */
+qq1  =  3.12324286e-01F, /*  0x1.3fd1f0p-2 */
+qq2  =  2.16070302e-02F, /*  0x1.620274p-6 */
+qq3  = -1.98859419e-03F, /* -0x1.04a626p-9 */
 /*
- * Coefficients for approximation to  erfc in [1.25,1/0.35]
+ * Domain [0.84375, 1.25], range ~[-1.953e-11,1.940e-11]:
+ * |(erf(x) - erx) - p(x)/q(x)| < 2**-36.
  */
-ra0  = -9.8649440333e-03, /* 0xbc21a093 */
-ra1  = -6.9385856390e-01, /* 0xbf31a0b7 */
-ra2  = -1.0558626175e+01, /* 0xc128f022 */
-ra3  = -6.2375331879e+01, /* 0xc2798057 */
-ra4  = -1.6239666748e+02, /* 0xc322658c */
-ra5  = -1.8460508728e+02, /* 0xc3389ae7 */
-ra6  = -8.1287437439e+01, /* 0xc2a2932b */
-ra7  = -9.8143291473e+00, /* 0xc11d077e */
-sa1  =  1.9651271820e+01, /* 0x419d35ce */
-sa2  =  1.3765776062e+02, /* 0x4309a863 */
-sa3  =  4.3456588745e+02, /* 0x43d9486f */
-sa4  =  6.4538726807e+02, /* 0x442158c9 */
-sa5  =  4.2900814819e+02, /* 0x43d6810b */
-sa6  =  1.0863500214e+02, /* 0x42d9451f */
-sa7  =  6.5702495575e+00, /* 0x40d23f7c */
-sa8  = -6.0424413532e-02, /* 0xbd777f97 */
+erx  =  8.42697144e-01F, /*  0x1.af7600p-1.  erf(1) rounded to 16 bits. */
+pa0  =  3.64939137e-06F, /*  0x1.e9d022p-19 */
+pa1  =  4.15109694e-01F, /*  0x1.a91284p-2 */
+pa2  = -1.65179938e-01F, /* -0x1.5249dcp-3 */
+pa3  =  1.10914491e-01F, /*  0x1.c64e46p-4 */
+qa1  =  6.02074385e-01F, /*  0x1.344318p-1 */
+qa2  =  5.35934687e-01F, /*  0x1.126608p-1 */
+qa3  =  1.68576106e-01F, /*  0x1.593e6ep-3 */
+qa4  =  5.62181212e-02F, /*  0x1.cc89f2p-5 */
 /*
- * Coefficients for approximation to  erfc in [1/.35,28]
+ * Domain [1.25,1/0.35], range ~[-7.043e-10,7.457e-10]:
+ * |log(x*erfc(x)) + x**2 + 0.5625 - r(x)/s(x)| < 2**-30
  */
-rb0  = -9.8649431020e-03, /* 0xbc21a092 */
-rb1  = -7.9928326607e-01, /* 0xbf4c9dd4 */
-rb2  = -1.7757955551e+01, /* 0xc18e104b */
-rb3  = -1.6063638306e+02, /* 0xc320a2ea */
-rb4  = -6.3756646729e+02, /* 0xc41f6441 */
-rb5  = -1.0250950928e+03, /* 0xc480230b */
-rb6  = -4.8351919556e+02, /* 0xc3f1c275 */
-sb1  =  3.0338060379e+01, /* 0x41f2b459 */
-sb2  =  3.2579251099e+02, /* 0x43a2e571 */
-sb3  =  1.5367296143e+03, /* 0x44c01759 */
-sb4  =  3.1998581543e+03, /* 0x4547fdbb */
-sb5  =  2.5530502930e+03, /* 0x451f90ce */
-sb6  =  4.7452853394e+02, /* 0x43ed43a7 */
-sb7  = -2.2440952301e+01; /* 0xc1b38712 */
+ra0  = -9.87132732e-03F, /* -0x1.4376b2p-7 */
+ra1  = -5.53605914e-01F, /* -0x1.1b723cp-1 */
+ra2  = -2.17589188e+00F, /* -0x1.1683a0p+1 */
+ra3  = -1.43268085e+00F, /* -0x1.6ec42cp+0 */
+sa1  =  5.45995426e+00F, /*  0x1.5d6fe4p+2 */
+sa2  =  6.69798088e+00F, /*  0x1.acabb8p+2 */
+sa3  =  1.43113089e+00F, /*  0x1.6e5e98p+0 */
+sa4  = -5.77397496e-02F, /* -0x1.d90108p-5 */
+/*
+ * Domain [1/0.35, 11], range ~[-2.264e-13,2.336e-13]:
+ * |log(x*erfc(x)) + x**2 + 0.5625 - r(x)/s(x)| < 2**-42
+ */
+rb0  = -9.86494310e-03F, /* -0x1.434124p-7 */
+rb1  = -6.25171244e-01F, /* -0x1.401672p-1 */
+rb2  = -6.16498327e+00F, /* -0x1.8a8f16p+2 */
+rb3  = -1.66696873e+01F, /* -0x1.0ab70ap+4 */
+rb4  = -9.53764343e+00F, /* -0x1.313460p+3 */
+sb1  =  1.26884899e+01F, /*  0x1.96081cp+3 */
+sb2  =  4.51839523e+01F, /*  0x1.6978bcp+5 */
+sb3  =  4.72810211e+01F, /*  0x1.7a3f88p+5 */
+sb4  =  8.93033314e+00F; /*  0x1.1dc54ap+3 */
 
 float
 erff(float x)
@@ -107,43 +91,37 @@
 	}
 
 	if(ix < 0x3f580000) {		/* |x|<0.84375 */
-	    if(ix < 0x31800000) { 	/* |x|<2**-28 */
-	        if (ix < 0x04000000)
-		    /*avoid underflow */
-		    return (float)0.125*((float)8.0*x+efx8*x);
+	    if(ix < 0x38800000) { 	/* |x|<2**-14 */
+	        if (ix < 0x04000000)	/* |x|<0x1p-119 */
+		    return (8*x+efx8*x)/8;	/* avoid spurious underflow */
 		return x + efx*x;
 	    }
 	    z = x*x;
-	    r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
-	    s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
+	    r = pp0+z*(pp1+z*pp2);
+	    s = one+z*(qq1+z*(qq2+z*qq3));
 	    y = r/s;
 	    return x + x*y;
 	}
 	if(ix < 0x3fa00000) {		/* 0.84375 <= |x| < 1.25 */
 	    s = fabsf(x)-one;
-	    P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
-	    Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
+	    P = pa0+s*(pa1+s*(pa2+s*pa3));
+	    Q = one+s*(qa1+s*(qa2+s*(qa3+s*qa4)));
 	    if(hx>=0) return erx + P/Q; else return -erx - P/Q;
 	}
-	if (ix >= 0x40c00000) {		/* inf>|x|>=6 */
+	if (ix >= 0x40800000) {		/* inf>|x|>=4 */
 	    if(hx>=0) return one-tiny; else return tiny-one;
 	}
 	x = fabsf(x);
  	s = one/(x*x);
 	if(ix< 0x4036DB6E) {	/* |x| < 1/0.35 */
-	    R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
-				ra5+s*(ra6+s*ra7))))));
-	    S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
-				sa5+s*(sa6+s*(sa7+s*sa8)))))));
+	    R=ra0+s*(ra1+s*(ra2+s*ra3));
+	    S=one+s*(sa1+s*(sa2+s*(sa3+s*sa4)));
 	} else {	/* |x| >= 1/0.35 */
-	    R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
-				rb5+s*rb6)))));
-	    S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
-				sb5+s*(sb6+s*sb7))))));
+	    R=rb0+s*(rb1+s*(rb2+s*(rb3+s*rb4)));
+	    S=one+s*(sb1+s*(sb2+s*(sb3+s*sb4)));
 	}
-	GET_FLOAT_WORD(ix,x);
-	SET_FLOAT_WORD(z,ix&0xfffff000);
-	r  =  __ieee754_expf(-z*z-(float)0.5625)*__ieee754_expf((z-x)*(z+x)+R/S);
+	SET_FLOAT_WORD(z,hx&0xffffe000);
+	r  = expf(-z*z-0.5625F)*expf((z-x)*(z+x)+R/S);
 	if(hx>=0) return one-r/x; else return  r/x-one;
 }
 
@@ -160,11 +138,11 @@
 	}
 
 	if(ix < 0x3f580000) {		/* |x|<0.84375 */
-	    if(ix < 0x23800000)  	/* |x|<2**-56 */
+	    if(ix < 0x33800000)  	/* |x|<2**-24 */
 		return one-x;
 	    z = x*x;
-	    r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
-	    s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
+	    r = pp0+z*(pp1+z*pp2);
+	    s = one+z*(qq1+z*(qq2+z*qq3));
 	    y = r/s;
 	    if(hx < 0x3e800000) {  	/* x<1/4 */
 		return one-(x+x*y);
@@ -176,33 +154,27 @@
 	}
 	if(ix < 0x3fa00000) {		/* 0.84375 <= |x| < 1.25 */
 	    s = fabsf(x)-one;
-	    P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
-	    Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
+	    P = pa0+s*(pa1+s*(pa2+s*pa3));
+	    Q = one+s*(qa1+s*(qa2+s*(qa3+s*qa4)));
 	    if(hx>=0) {
 	        z  = one-erx; return z - P/Q;
 	    } else {
 		z = erx+P/Q; return one+z;
 	    }
 	}
-	if (ix < 0x41e00000) {		/* |x|<28 */
+	if (ix < 0x41300000) {		/* |x|<11 */
 	    x = fabsf(x);
  	    s = one/(x*x);
 	    if(ix< 0x4036DB6D) {	/* |x| < 1/.35 ~ 2.857143*/
-	        R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
-				ra5+s*(ra6+s*ra7))))));
-	        S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
-				sa5+s*(sa6+s*(sa7+s*sa8)))))));
+	        R=ra0+s*(ra1+s*(ra2+s*ra3));
+	        S=one+s*(sa1+s*(sa2+s*(sa3+s*sa4)));
 	    } else {			/* |x| >= 1/.35 ~ 2.857143 */
-		if(hx<0&&ix>=0x40c00000) return two-tiny;/* x < -6 */
-	        R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
-				rb5+s*rb6)))));
-	        S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
-				sb5+s*(sb6+s*sb7))))));
+		if(hx<0&&ix>=0x40a00000) return two-tiny;/* x < -5 */
+	        R=rb0+s*(rb1+s*(rb2+s*(rb3+s*rb4)));
+		S=one+s*(sb1+s*(sb2+s*(sb3+s*sb4)));
 	    }
-	    GET_FLOAT_WORD(ix,x);
-	    SET_FLOAT_WORD(z,ix&0xfffff000);
-	    r  =  __ieee754_expf(-z*z-(float)0.5625)*
-			__ieee754_expf((z-x)*(z+x)+R/S);
+	    SET_FLOAT_WORD(z,hx&0xffffe000);
+	    r  = expf(-z*z-0.5625F)*expf((z-x)*(z+x)+R/S);
 	    if(hx>0) return r/x; else return two-r/x;
 	} else {
 	    if(hx>0) return tiny*tiny; else return two-tiny;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_fma.c b/libm/upstream-freebsd/lib/msun/src/s_fma.c
index 452bece..b1066c2 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_fma.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fma.c
@@ -117,7 +117,7 @@
 	if (sum.lo != 0) {
 		EXTRACT_WORD64(hibits, sum.hi);
 		bits_lost = -((int)(hibits >> 52) & 0x7ff) - scale + 1;
-		if (bits_lost != 1 ^ (int)(hibits & 1)) {
+		if ((bits_lost != 1) ^ (int)(hibits & 1)) {
 			/* hibits += (int)copysign(1.0, sum.hi * sum.lo) */
 			EXTRACT_WORD64(lobits, sum.lo);
 			hibits += 1 - (((hibits ^ lobits) >> 62) & 2);
diff --git a/libm/upstream-freebsd/lib/msun/src/s_fmal.c b/libm/upstream-freebsd/lib/msun/src/s_fmal.c
index 9271901..d435f4f 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_fmal.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fmal.c
@@ -113,7 +113,7 @@
 	if (sum.lo != 0) {
 		u.e = sum.hi;
 		bits_lost = -u.bits.exp - scale + 1;
-		if (bits_lost != 1 ^ (int)(u.bits.manl & 1))
+		if ((bits_lost != 1) ^ (int)(u.bits.manl & 1))
 			sum.hi = nextafterl(sum.hi, INFINITY * sum.lo);
 	}
 	return (ldexp(sum.hi, scale));
diff --git a/libm/upstream-freebsd/lib/msun/src/s_isfinite.c b/libm/upstream-freebsd/lib/msun/src/s_isfinite.c
deleted file mode 100644
index c9d1bd7..0000000
--- a/libm/upstream-freebsd/lib/msun/src/s_isfinite.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <math.h>
-
-#include "fpmath.h"
-
-int
-__isfinite(double d)
-{
-	union IEEEd2bits u;
-
-	u.d = d;
-	return (u.bits.exp != 2047);
-}
-
-int
-__isfinitef(float f)
-{
-	union IEEEf2bits u;
-
-	u.f = f;
-	return (u.bits.exp != 255);
-}
-
-int
-__isfinitel(long double e)
-{
-	union IEEEl2bits u;
-
-	u.e = e;
-	return (u.bits.exp != 32767);
-}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_isnan.c b/libm/upstream-freebsd/lib/msun/src/s_isnan.c
deleted file mode 100644
index a54ded3..0000000
--- a/libm/upstream-freebsd/lib/msun/src/s_isnan.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <math.h>
-
-#include "fpmath.h"
-
-/* Provided by libc.so */
-#ifndef PIC
-#undef isnan
-int
-isnan(double d)
-{
-	union IEEEd2bits u;
-
-	u.d = d;
-	return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
-}
-#endif /* !PIC */
-
-int
-__isnanf(float f)
-{
-	union IEEEf2bits u;
-
-	u.f = f;
-	return (u.bits.exp == 255 && u.bits.man != 0);
-}
-
-int
-__isnanl(long double e)
-{
-	union IEEEl2bits u;
-
-	u.e = e;
-	mask_nbit_l(u);
-	return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0));
-}
-
-__weak_reference(__isnanf, isnanf);
diff --git a/libm/upstream-freebsd/lib/msun/src/s_isnormal.c b/libm/upstream-freebsd/lib/msun/src/s_isnormal.c
deleted file mode 100644
index 49f2a74..0000000
--- a/libm/upstream-freebsd/lib/msun/src/s_isnormal.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <math.h>
-
-#include "fpmath.h"
-
-int
-__isnormal(double d)
-{
-	union IEEEd2bits u;
-
-	u.d = d;
-	return (u.bits.exp != 0 && u.bits.exp != 2047);
-}
-
-int
-__isnormalf(float f)
-{
-	union IEEEf2bits u;
-
-	u.f = f;
-	return (u.bits.exp != 0 && u.bits.exp != 255);
-}
-
-int
-__isnormall(long double e)
-{
-	union IEEEl2bits u;
-
-	u.e = e;
-	return (u.bits.exp != 0 && u.bits.exp != 32767);
-}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_remquol.c b/libm/upstream-freebsd/lib/msun/src/s_remquol.c
index 712651c..8899293 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_remquol.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquol.c
@@ -5,7 +5,7 @@
  *
  * Developed at SunSoft, a Sun Microsystems, Inc. business.
  * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
+ * software is freely granted, provided that this notice
  * is preserved.
  * ====================================================
  */
diff --git a/libm/upstream-freebsd/lib/msun/src/s_rintl.c b/libm/upstream-freebsd/lib/msun/src/s_rintl.c
index b43df89..e55b40e 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_rintl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_rintl.c
@@ -29,6 +29,7 @@
 
 #include <float.h>
 #include <math.h>
+#include <stdint.h>
 
 #include "fpmath.h"
 
diff --git a/libm/upstream-freebsd/lib/msun/src/s_signbit.c b/libm/upstream-freebsd/lib/msun/src/s_signbit.c
deleted file mode 100644
index 01eb3ab..0000000
--- a/libm/upstream-freebsd/lib/msun/src/s_signbit.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <math.h>
-
-#include "fpmath.h"
-
-int
-__signbit(double d)
-{
-	union IEEEd2bits u;
-
-	u.d = d;
-	return (u.bits.sign);
-}
-
-int
-__signbitf(float f)
-{
-	union IEEEf2bits u;
-
-	u.f = f;
-	return (u.bits.sign);
-}
-
-int
-__signbitl(long double e)
-{
-	union IEEEl2bits u;
-
-	u.e = e;
-	return (u.bits.sign);
-}
diff --git a/libstdc++/Android.mk b/libstdc++/Android.mk
deleted file mode 100644
index 41e6c4d..0000000
--- a/libstdc++/Android.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-# Common C++ flags to build this library.
-# Note that we need to access private Bionic headers
-# and define ANDROID_SMP accordingly.
-libstdc++_cflags := -Ibionic/libc/
-ifeq ($(TARGET_CPU_SMP),true)
-    libstdc++_cflags += -DANDROID_SMP=1
-else
-    libstdc++_cflags += -DANDROID_SMP=0
-endif
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-	src/one_time_construction.cpp \
-	src/new.cpp \
-	src/pure_virtual.cpp \
-	src/typeinfo.cpp
-
-LOCAL_MODULE:= libstdc++
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_CFLAGS := $(libstdc++_cflags)
-
-LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-	src/one_time_construction.cpp \
-	src/new.cpp \
-	src/pure_virtual.cpp \
-	src/typeinfo.cpp
-
-LOCAL_CFLAGS := $(libstdc++_cflags)
-
-LOCAL_MODULE:= libstdc++
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/libstdc++/NOTICE b/libstdc++/NOTICE
index 6c263d1..492770d 100644
--- a/libstdc++/NOTICE
+++ b/libstdc++/NOTICE
@@ -4,9 +4,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -32,9 +32,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -79,7 +79,3 @@
 
 -------------------------------------------------------------------
 
-Copyright 2006 The Android Open Source Project
-
--------------------------------------------------------------------
-
diff --git a/libstdc++/include/cstdio b/libstdc++/include/cstdio
index 3c8b5c6..2948d85 100644
--- a/libstdc++/include/cstdio
+++ b/libstdc++/include/cstdio
@@ -63,7 +63,9 @@
 using ::fwrite;
 using ::getc;
 using ::getchar;
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
 using ::gets;
+#endif
 using ::perror;
 using ::printf;
 using ::putc;
diff --git a/libstdc++/include/cstdlib b/libstdc++/include/cstdlib
index bb6f5a5..bd1deae 100644
--- a/libstdc++/include/cstdlib
+++ b/libstdc++/include/cstdlib
@@ -42,9 +42,6 @@
 using ::exit;
 using ::abort;
 using ::atexit;
-#if 0 /* MISSING FROM BIONIC */
-using ::on_exit;
-#endif
 
 using ::getenv;
 using ::putenv;
diff --git a/libstdc++/src/new.cpp b/libstdc++/src/new.cpp
deleted file mode 100644
index ddd3dba..0000000
--- a/libstdc++/src/new.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include "new"
-#include <stdlib.h>
-
-const std::nothrow_t std::nothrow = {};
-
-void* operator new(std::size_t size)
-{
-    void* p = malloc(size);
-    if (p == NULL) {
-        abort();
-    }
-    return p;
-}
-
-void* operator new[](std::size_t size)
-{
-    void* p = malloc(size);
-    if (p == NULL) {
-        abort();
-    }
-    return p;
-}
-
-void  operator delete(void* ptr)
-{
-    free(ptr);
-}
-
-void  operator delete[](void* ptr)
-{
-    free(ptr);
-}
-
-void* operator new(std::size_t size, const std::nothrow_t&)
-{
-    return malloc(size);
-}
-
-void* operator new[](std::size_t size, const std::nothrow_t&)
-{
-    return malloc(size);
-}
-
-void  operator delete(void* ptr, const std::nothrow_t&)
-{
-    free(ptr);
-}
-
-void  operator delete[](void* ptr, const std::nothrow_t&)
-{
-    free(ptr);
-}
-
-
-
-
-
diff --git a/libstdc++/src/one_time_construction.cpp b/libstdc++/src/one_time_construction.cpp
deleted file mode 100644
index 5574311..0000000
--- a/libstdc++/src/one_time_construction.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2006 The Android Open Source Project
- */
-
-#include <stddef.h>
-#include <sys/atomics.h>
-#include <endian.h>
-
-#include "private/bionic_atomic_inline.h"
-#include "private/bionic_futex.h"
-
-// This file contains C++ ABI support functions for one time
-// constructors as defined in the "Run-time ABI for the ARM Architecture"
-// section 4.4.2
-//
-// ARM C++ ABI and Itanium/x86 C++ ABI has different definition for
-// one time construction:
-//
-//    ARM C++ ABI defines the LSB of guard variable should be tested
-//    by compiler-generated code before calling __cxa_guard_acquire et al.
-//
-//    The Itanium/x86 C++ ABI defines the low-order _byte_ should be
-//    tested instead.
-//
-//    Meanwhile, guard variable are 32bit aligned for ARM, and 64bit
-//    aligned for x86.
-//
-// Reference documentation:
-//
-//    section 3.2.3 of ARM IHI 0041C (for ARM)
-//    section 3.3.2 of the Itanium C++ ABI specification v1.83 (for x86).
-//
-// There is no C++ ABI available for other ARCH. But the gcc source
-// shows all other ARCH follow the definition of Itanium/x86 C++ ABI.
-
-
-#if defined(__arm__)
-// The ARM C++ ABI mandates that guard variable are
-// 32-bit aligned, 32-bit values. And only its LSB is tested by
-// the compiler-generated code before calling
-// __cxa_guard_acquire.
-//
-typedef union {
-    int volatile state;
-    int32_t aligner;
-} _guard_t;
-
-const static int ready = 0x1;
-const static int pending = 0x2;
-const static int waiting = 0x6;
-
-#else   // GCC sources indicates all none-arm follow the same ABI
-// The Itanium/x86 C++ ABI mandates that guard variables
-// are 64-bit aligned, 64-bit values. Also, the least-significant
-// byte is tested by the compiler-generated code before, we calling
-// __cxa_guard_acquire. We can access it through the first
-// 32-bit word in the union below.
-//
-typedef union {
-    int volatile state;
-    int64_t aligner;
-} _guard_t;
-
-const static int ready     = letoh32(0x1);
-const static int pending   = letoh32(0x100);
-const static int waiting   = letoh32(0x10000);
-#endif
-
-extern "C" int __cxa_guard_acquire(_guard_t* gv)
-{
-    // 0 -> pending, return 1
-    // pending -> waiting, wait and return 0
-    // waiting: untouched, wait and return 0
-    // ready: untouched, return 0
-
-retry:
-    if (__bionic_cmpxchg(0, pending, &gv->state) == 0) {
-        ANDROID_MEMBAR_FULL();
-        return 1;
-    }
-    __bionic_cmpxchg(pending, waiting, &gv->state); // Indicate there is a waiter
-    __futex_wait(&gv->state, waiting, NULL);
-
-    if (gv->state != ready) // __cxa_guard_abort was called, let every thread try since there is no return code for this condition
-        goto retry;
-
-    ANDROID_MEMBAR_FULL();
-    return 0;
-}
-
-extern "C" void __cxa_guard_release(_guard_t* gv)
-{
-    // pending -> ready
-    // waiting -> ready, and wake
-
-    ANDROID_MEMBAR_FULL();
-    if (__bionic_cmpxchg(pending, ready, &gv->state) == 0) {
-        return;
-    }
-
-    gv->state = ready;
-    __futex_wake(&gv->state, 0x7fffffff);
-}
-
-extern "C" void __cxa_guard_abort(_guard_t* gv)
-{
-    ANDROID_MEMBAR_FULL();
-    gv->state= 0;
-    __futex_wake(&gv->state, 0x7fffffff);
-}
diff --git a/libstdc++/src/pure_virtual.cpp b/libstdc++/src/pure_virtual.cpp
deleted file mode 100644
index 6b5e328..0000000
--- a/libstdc++/src/pure_virtual.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#undef NDEBUG
-#include <assert.h>
-
-extern "C" void __cxa_pure_virtual() {
-  // We can't call __libc_format_log from libstdc++ because it's hidden and in libc, so cheat.
-  assert(!"Pure virtual function called. Are you calling virtual methods from a destructor?");
-  /* NOTREACHED */
-}
diff --git a/libstdc++/src/typeinfo.cpp b/libstdc++/src/typeinfo.cpp
deleted file mode 100644
index b426f1a..0000000
--- a/libstdc++/src/typeinfo.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "typeinfo"
-#include <stdlib.h>
-
-type_info::type_info() {
-}
-
-type_info::~type_info() {
-}
-
-char const *
-type_info::name() const {
-    return "N/A";
-}
-
-bool 
-type_info::operator==(type_info const & right) const {
-    return false;
-}
-
-bool 
-type_info::operator!=(type_info const & right) const {
-    return false;
-}
-
-bool
-type_info::before(type_info const & right) const {
-    return false;
-}
-
-type_info::type_info(type_info const & right) {
-}
-
diff --git a/linker/Android.mk b/linker/Android.mk
index bdc54de..5853c90 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -1,21 +1,23 @@
-LOCAL_PATH:= $(call my-dir)
+LOCAL_PATH := $(call my-dir)
+
 include $(CLEAR_VARS)
 
-ifeq ($(TARGET_ARCH),x86)
-    linker_begin_extension := c
-else
-    linker_begin_extension := S
-endif
-
 LOCAL_SRC_FILES:= \
-    arch/$(TARGET_ARCH)/begin.$(linker_begin_extension) \
     debugger.cpp \
     dlfcn.cpp \
     linker.cpp \
+    linker_allocator.cpp \
     linker_environ.cpp \
     linker_phdr.cpp \
     rt.cpp \
 
+LOCAL_SRC_FILES_arm     := arch/arm/begin.S
+LOCAL_SRC_FILES_arm64   := arch/arm64/begin.S
+LOCAL_SRC_FILES_x86     := arch/x86/begin.c
+LOCAL_SRC_FILES_x86_64  := arch/x86_64/begin.S
+LOCAL_SRC_FILES_mips    := arch/mips/begin.S
+LOCAL_SRC_FILES_mips64  := arch/mips64/begin.S
+
 LOCAL_LDFLAGS := \
     -shared \
     -Wl,-Bsymbolic \
@@ -25,7 +27,7 @@
     -fno-stack-protector \
     -Wstrict-overflow=5 \
     -fvisibility=hidden \
-    -Wall -Wextra -Werror \
+    -Wall -Wextra -Wunused -Werror \
 
 LOCAL_CONLYFLAGS += \
     -std=gnu99 \
@@ -36,51 +38,40 @@
 # We need to access Bionic private headers in the linker.
 LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
 
-ifeq ($(TARGET_IS_64_BIT),true)
-    LOCAL_MODULE := linker64
-else
-    LOCAL_MODULE := linker
-endif
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_STATIC_LIBRARIES := libc_nomalloc
-
-#LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
-
-#
-# include $(BUILD_EXECUTABLE)
-#
-# Instead of including $(BUILD_EXECUTABLE), we execute the steps to create an executable by
-# hand, as we want to insert an extra step that is not supported by the build system, and
-# is probably specific the linker only, so there's no need to modify the build system for
-# the purpose.
-
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_MODULE_SUFFIX := $(TARGET_EXECUTABLE_SUFFIX)
-
 # we don't want crtbegin.o (because we have begin.o), so unset it
 # just for this module
 LOCAL_NO_CRT := true
-
 # TODO: split out the asflags.
 LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
 
-include $(BUILD_SYSTEM)/dynamic_binary.mk
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/linker_executable.mk
 
-# See build/core/executable.mk
-$(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $(TARGET_GLOBAL_LD_DIRS)
-$(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(TARGET_GLOBAL_LDFLAGS)
-$(linked_module): PRIVATE_TARGET_FDO_LIB := $(TARGET_FDO_LIB)
-$(linked_module): PRIVATE_TARGET_LIBGCC := $(TARGET_LIBGCC)
-$(linked_module): PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_CRTBEGIN_DYNAMIC_O)
-$(linked_module): PRIVATE_TARGET_CRTBEGIN_STATIC_O := $(TARGET_CRTBEGIN_STATIC_O)
-$(linked_module): PRIVATE_TARGET_CRTEND_O := $(TARGET_CRTEND_O)
-$(linked_module): $(TARGET_CRTBEGIN_STATIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
-	$(transform-o-to-static-executable)
-	@echo "target PrefixSymbols: $(PRIVATE_MODULE) ($@)"
-	$(hide) $(TARGET_OBJCOPY) --prefix-symbols=__dl_ $@
+LOCAL_STATIC_LIBRARIES := libc_nomalloc
 
-#
-# end of BUILD_EXECUTABLE hack
-#
+LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
+
+LOCAL_2ND_ARCH_VAR_PREFIX := $(linker_2nd_arch_var_prefix)
+
+LOCAL_MODULE := linker
+LOCAL_MODULE_STEM_32 := linker
+LOCAL_MODULE_STEM_64 := linker64
+LOCAL_MULTILIB := both
+
+# Leave the symbols in the shared library so that stack unwinders can produce
+# meaningful name resolution.
+LOCAL_STRIP_MODULE := keep_symbols
+
+include $(LOCAL_PATH)/linker_executable.mk
+ifdef TARGET_2ND_ARCH
+LOCAL_2ND_ARCH_VAR_PREFIX := $(TARGET_2ND_ARCH_VAR_PREFIX)
+OVERRIDE_BUILT_MODULE_PATH :=
+LOCAL_BUILT_MODULE :=
+LOCAL_INSTALLED_MODULE :=
+LOCAL_MODULE_STEM :=
+LOCAL_BUILT_MODULE_STEM :=
+LOCAL_INSTALLED_MODULE_STEM :=
+LOCAL_INTERMEDIATE_TARGETS :=
+include $(LOCAL_PATH)/linker_executable.mk
+endif
+
+include $(call first-makefiles-under,$(LOCAL_PATH))
diff --git a/linker/NOTICE b/linker/NOTICE
index c3d6cf6..cb3a1dd 100644
--- a/linker/NOTICE
+++ b/linker/NOTICE
@@ -20,9 +20,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -48,9 +48,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -76,9 +76,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -104,9 +104,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -132,9 +132,9 @@
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -155,14 +155,30 @@
 -------------------------------------------------------------------
 
 Copyright (C) 2013 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2013 The Android Open Source Project
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
-Redistributions of source code must retain the above copyright
+ * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright
+ * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.
@@ -182,3 +198,19 @@
 
 -------------------------------------------------------------------
 
+Copyright (C) 2014 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-------------------------------------------------------------------
+
diff --git a/linker/arch/arm/begin.S b/linker/arch/arm/begin.S
index e259902..8cb599b 100644
--- a/linker/arch/arm/begin.S
+++ b/linker/arch/arm/begin.S
@@ -26,20 +26,12 @@
  * SUCH DAMAGE.
  */
 
-	.text
-	.align 4
-	.type _start,#function
-	.globl _start
+#include <private/bionic_asm.h>
 
-_start:
-	mov	r0, sp
-	mov	r1, #0
-	bl	__linker_init
+ENTRY(_start)
+  mov r0, sp
+  bl __linker_init
 
-	/* linker init returns the _entry address in the main image */
-	mov	pc, r0
-
-	.section .ctors, "wa"
-	.globl __CTOR_LIST__
-__CTOR_LIST__:
-	.long -1
+  /* linker init returns the _entry address in the main image */
+  mov pc, r0
+END(_start)
diff --git a/linker/arch/arm64/begin.S b/linker/arch/arm64/begin.S
index 55618b7..a6ea583 100644
--- a/linker/arch/arm64/begin.S
+++ b/linker/arch/arm64/begin.S
@@ -26,12 +26,11 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(_start)
   mov x0, sp
-  mov x1, xzr
-  bl  __linker_init
+  bl __linker_init
 
   /* linker init returns the _entry address in the main image */
   br x0
diff --git a/linker/arch/mips/begin.S b/linker/arch/mips/begin.S
index b782947..cbe1e37 100644
--- a/linker/arch/mips/begin.S
+++ b/linker/arch/mips/begin.S
@@ -32,7 +32,9 @@
 
     .ent    __start
     .globl    __start
+    .globl    _start
 __start:
+_start:
     .set    noreorder
     bal    1f
     nop
@@ -100,8 +102,3 @@
     addu    $sp, 4*4        /* restore sp */
     j    $t9
     .end    __start
-
-    .section .ctors, "wa"
-    .globl __CTOR_LIST__
-__CTOR_LIST__:
-    .long -1
diff --git a/linker/arch/mips64/begin.S b/linker/arch/mips64/begin.S
new file mode 100644
index 0000000..8f6b94a
--- /dev/null
+++ b/linker/arch/mips64/begin.S
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+#define ELF_DYNSZ       8
+#define ELF_DYN_TAG     0
+#define ELF_DYN_VAL     4
+#define GOTENT_SZ       4
+#else
+#define ELF_DYNSZ       16
+#define ELF_DYN_TAG     0
+#define ELF_DYN_VAL     8
+#define GOTENT_SZ       8
+#endif
+
+    .text
+    .align	4
+    .type	__start,@function
+
+    .ent	__start
+    .globl	__start
+    .globl	_start
+__start:
+_start:
+    .set	noreorder
+    bal		1f
+     nop
+1:
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+    .cpload	ra
+#else
+    .cpsetup	ra, $0, 1b
+#endif
+    .set	reorder
+
+    /* Discover the load address */
+    LA		t0, 1b
+    PTR_SUBU	t0, ra, t0
+
+#define DT_PLTGOT 3
+#define DT_MIPS_LOCAL_GOTNO 0x7000000a
+
+    /* Search dynamic table for DT_MIPS_LOCAL_GOTNO and DT_PLTGOT values */
+    LA		t1, _DYNAMIC
+    PTR_ADDU	t1, t0
+    LI		t3, DT_PLTGOT
+    LI		ta0, DT_MIPS_LOCAL_GOTNO
+0:
+    REG_L	t2, ELF_DYN_TAG(t1)
+    beqz	t2, .Lrelocate_local_got
+
+    bne		t2, t3, 1f	/* DT_PLTGOT? */
+    REG_L	s0, ELF_DYN_VAL(t1)
+    PTR_ADDU	s0, t0
+    b		2f
+
+1:
+    bne		t2, ta0, 2f    /* DT_MIPS_LOCAL_GOTNO? */
+    REG_L	s1, ELF_DYN_VAL(t1)
+
+2:  PTR_ADDU    t1, ELF_DYNSZ
+    b		0b
+
+.Lrelocate_local_got:
+    /*
+     * Relocate the local GOT entries
+     * got[0] is address of lazy resolver function
+     * got[1] may be used for a GNU extension
+     */
+
+    PTR_ADDU	s0, GOTENT_SZ
+    SUBU	s1, 1
+    PTR_L	t1, (s0)
+    bgez	t1, 9f
+    PTR_ADDU	s0, GOTENT_SZ
+    SUBU	s1, 1
+    b		9f
+
+1:  PTR_L	t1, (s0)
+    PTR_ADDU	t1, t0
+    PTR_S	t1, (s0)
+    PTR_ADDU	s0, GOTENT_SZ
+9:  SUBU	s1, 1
+    bgez	s1, 1b
+
+    /* call linker_init */
+    move	a0, sp
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+    PTR_SUBU	sp, 4*REGSZ       /* space for arg saves in linker_init */
+#endif
+    jal		__linker_init
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+    PTR_ADDU	sp, 4*REGSZ        /* restore sp */
+#endif
+    move	t9, v0
+    j		t9
+    .end    __start
diff --git a/linker/arch/x86_64/begin.S b/linker/arch/x86_64/begin.S
index 9ecad1a..7945a31 100644
--- a/linker/arch/x86_64/begin.S
+++ b/linker/arch/x86_64/begin.S
@@ -26,10 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(_start)
-  /* Pass elfdata to __linker_init. */
   mov %rsp, %rdi
   call __linker_init
 
diff --git a/linker/debugger.cpp b/linker/debugger.cpp
index 92e9dac..c316151 100644
--- a/linker/debugger.cpp
+++ b/linker/debugger.cpp
@@ -29,6 +29,7 @@
 #include "linker.h"
 
 #include <errno.h>
+#include <inttypes.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -40,15 +41,19 @@
 
 extern "C" int tgkill(int tgid, int tid, int sig);
 
+#if __LP64__
+#define DEBUGGER_SOCKET_NAME "android:debuggerd64"
+#else
 #define DEBUGGER_SOCKET_NAME "android:debuggerd"
+#endif
 
 enum debugger_action_t {
-    // dump a crash
-    DEBUGGER_ACTION_CRASH,
-    // dump a tombstone file
-    DEBUGGER_ACTION_DUMP_TOMBSTONE,
-    // dump a backtrace only back to the socket
-    DEBUGGER_ACTION_DUMP_BACKTRACE,
+  // dump a crash
+  DEBUGGER_ACTION_CRASH,
+  // dump a tombstone file
+  DEBUGGER_ACTION_DUMP_TOMBSTONE,
+  // dump a backtrace only back to the socket
+  DEBUGGER_ACTION_DUMP_BACKTRACE,
 };
 
 /* message sent over the socket */
@@ -59,46 +64,48 @@
 
   // version 2 added:
   uintptr_t abort_msg_address;
+
+  // version 3 added:
+  int32_t original_si_code;
 };
 
 // see man(2) prctl, specifically the section about PR_GET_NAME
 #define MAX_TASK_NAME_LEN (16)
 
 static int socket_abstract_client(const char* name, int type) {
-    sockaddr_un addr;
+  sockaddr_un addr;
 
-    // Test with length +1 for the *initial* '\0'.
-    size_t namelen = strlen(name);
-    if ((namelen + 1) > sizeof(addr.sun_path)) {
-        errno = EINVAL;
-        return -1;
-    }
+  // Test with length +1 for the *initial* '\0'.
+  size_t namelen = strlen(name);
+  if ((namelen + 1) > sizeof(addr.sun_path)) {
+    errno = EINVAL;
+    return -1;
+  }
 
-    /* This is used for abstract socket namespace, we need
-     * an initial '\0' at the start of the Unix socket path.
-     *
-     * Note: The path in this case is *not* supposed to be
-     * '\0'-terminated. ("man 7 unix" for the gory details.)
-     */
-    memset(&addr, 0, sizeof(addr));
-    addr.sun_family = AF_LOCAL;
-    addr.sun_path[0] = 0;
-    memcpy(addr.sun_path + 1, name, namelen);
+  // This is used for abstract socket namespace, we need
+  // an initial '\0' at the start of the Unix socket path.
+  //
+  // Note: The path in this case is *not* supposed to be
+  // '\0'-terminated. ("man 7 unix" for the gory details.)
+  memset(&addr, 0, sizeof(addr));
+  addr.sun_family = AF_LOCAL;
+  addr.sun_path[0] = 0;
+  memcpy(addr.sun_path + 1, name, namelen);
 
-    socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
+  socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
 
-    int s = socket(AF_LOCAL, type, 0);
-    if (s == -1) {
-        return -1;
-    }
+  int s = socket(AF_LOCAL, type, 0);
+  if (s == -1) {
+    return -1;
+  }
 
-    int err = TEMP_FAILURE_RETRY(connect(s, reinterpret_cast<sockaddr*>(&addr), alen));
-    if (err == -1) {
-        close(s);
-        s = -1;
-    }
+  int rc = TEMP_FAILURE_RETRY(connect(s, reinterpret_cast<sockaddr*>(&addr), alen));
+  if (rc == -1) {
+    close(s);
+    return -1;
+  }
 
-    return s;
+  return s;
 }
 
 /*
@@ -111,158 +118,192 @@
  * could allocate memory or hold a lock.
  */
 static void log_signal_summary(int signum, const siginfo_t* info) {
-    const char* signal_name;
-    switch (signum) {
-        case SIGILL:    signal_name = "SIGILL";     break;
-        case SIGABRT:   signal_name = "SIGABRT";    break;
-        case SIGBUS:    signal_name = "SIGBUS";     break;
-        case SIGFPE:    signal_name = "SIGFPE";     break;
-        case SIGSEGV:   signal_name = "SIGSEGV";    break;
+  const char* signal_name = "???";
+  bool has_address = false;
+  switch (signum) {
+    case SIGABRT:
+      signal_name = "SIGABRT";
+      break;
+    case SIGBUS:
+      signal_name = "SIGBUS";
+      has_address = true;
+      break;
+    case SIGFPE:
+      signal_name = "SIGFPE";
+      has_address = true;
+      break;
+    case SIGILL:
+      signal_name = "SIGILL";
+      has_address = true;
+      break;
+    case SIGPIPE:
+      signal_name = "SIGPIPE";
+      break;
+    case SIGSEGV:
+      signal_name = "SIGSEGV";
+      has_address = true;
+      break;
 #if defined(SIGSTKFLT)
-        case SIGSTKFLT: signal_name = "SIGSTKFLT";  break;
+    case SIGSTKFLT:
+      signal_name = "SIGSTKFLT";
+      break;
 #endif
-        case SIGPIPE:   signal_name = "SIGPIPE";    break;
-        default:        signal_name = "???";        break;
-    }
+    case SIGTRAP:
+      signal_name = "SIGTRAP";
+      break;
+  }
 
-    char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination
-    if (prctl(PR_GET_NAME, (unsigned long)thread_name, 0, 0, 0) != 0) {
-        strcpy(thread_name, "<name unknown>");
-    } else {
-        // short names are null terminated by prctl, but the man page
-        // implies that 16 byte names are not.
-        thread_name[MAX_TASK_NAME_LEN] = 0;
-    }
+  char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination
+  if (prctl(PR_GET_NAME, (unsigned long)thread_name, 0, 0, 0) != 0) {
+    strcpy(thread_name, "<name unknown>");
+  } else {
+    // short names are null terminated by prctl, but the man page
+    // implies that 16 byte names are not.
+    thread_name[MAX_TASK_NAME_LEN] = 0;
+  }
 
-    // "info" will be NULL if the siginfo_t information was not available.
-    if (info != NULL) {
-        __libc_format_log(ANDROID_LOG_FATAL, "libc",
-                          "Fatal signal %d (%s) at %p (code=%d), thread %d (%s)",
-                          signum, signal_name, info->si_addr, info->si_code,
-                          gettid(), thread_name);
-    } else {
-        __libc_format_log(ANDROID_LOG_FATAL, "libc",
-                          "Fatal signal %d (%s), thread %d (%s)",
-                          signum, signal_name, gettid(), thread_name);
+  // "info" will be NULL if the siginfo_t information was not available.
+  // Many signals don't have an address or a code.
+  char code_desc[32]; // ", code -6"
+  char addr_desc[32]; // ", fault addr 0x1234"
+  addr_desc[0] = code_desc[0] = 0;
+  if (info != NULL) {
+    // For a rethrown signal, this si_code will be right and the one debuggerd shows will
+    // always be SI_TKILL.
+    __libc_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code);
+    if (has_address) {
+      __libc_format_buffer(addr_desc, sizeof(addr_desc), ", fault addr %p", info->si_addr);
     }
+  }
+  __libc_format_log(ANDROID_LOG_FATAL, "libc",
+                    "Fatal signal %d (%s)%s%s in tid %d (%s)",
+                    signum, signal_name, code_desc, addr_desc, gettid(), thread_name);
 }
 
 /*
  * Returns true if the handler for signal "signum" has SA_SIGINFO set.
  */
 static bool have_siginfo(int signum) {
-    struct sigaction old_action, new_action;
+  struct sigaction old_action, new_action;
 
-    memset(&new_action, 0, sizeof(new_action));
-    new_action.sa_handler = SIG_DFL;
-    new_action.sa_flags = SA_RESTART;
-    sigemptyset(&new_action.sa_mask);
+  memset(&new_action, 0, sizeof(new_action));
+  new_action.sa_handler = SIG_DFL;
+  new_action.sa_flags = SA_RESTART;
+  sigemptyset(&new_action.sa_mask);
 
-    if (sigaction(signum, &new_action, &old_action) < 0) {
-      __libc_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s",
-                        strerror(errno));
-      return false;
-    }
-    bool result = (old_action.sa_flags & SA_SIGINFO) != 0;
+  if (sigaction(signum, &new_action, &old_action) < 0) {
+    __libc_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s",
+                      strerror(errno));
+    return false;
+  }
+  bool result = (old_action.sa_flags & SA_SIGINFO) != 0;
 
-    if (sigaction(signum, &old_action, NULL) == -1) {
-      __libc_format_log(ANDROID_LOG_WARN, "libc", "Restore failed in test for SA_SIGINFO: %s",
-                        strerror(errno));
-    }
-    return result;
+  if (sigaction(signum, &old_action, NULL) == -1) {
+    __libc_format_log(ANDROID_LOG_WARN, "libc", "Restore failed in test for SA_SIGINFO: %s",
+                      strerror(errno));
+  }
+  return result;
+}
+
+static void send_debuggerd_packet(siginfo_t* info) {
+  if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0) {
+    // process has disabled core dumps and PTRACE_ATTACH, and does not want to be dumped.
+    // Honor that intention by not connecting to debuggerd and asking it
+    // to dump our internal state.
+    __libc_format_log(ANDROID_LOG_INFO, "libc",
+                      "Suppressing debuggerd output because prctl(PR_GET_DUMPABLE)==0");
+    return;
+  }
+
+  int s = socket_abstract_client(DEBUGGER_SOCKET_NAME, SOCK_STREAM);
+  if (s == -1) {
+    __libc_format_log(ANDROID_LOG_FATAL, "libc", "Unable to open connection to debuggerd: %s",
+                      strerror(errno));
+    return;
+  }
+
+  // debuggerd knows our pid from the credentials on the
+  // local socket but we need to tell it the tid of the crashing thread.
+  // debuggerd will be paranoid and verify that we sent a tid
+  // that's actually in our process.
+  debugger_msg_t msg;
+  msg.action = DEBUGGER_ACTION_CRASH;
+  msg.tid = gettid();
+  msg.abort_msg_address = reinterpret_cast<uintptr_t>(g_abort_message);
+  msg.original_si_code = (info != NULL) ? info->si_code : 0;
+  int ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg)));
+  if (ret == sizeof(msg)) {
+    char debuggerd_ack;
+    ret = TEMP_FAILURE_RETRY(read(s, &debuggerd_ack, 1));
+    int saved_errno = errno;
+    notify_gdb_of_libraries();
+    errno = saved_errno;
+  } else {
+    // read or write failed -- broken connection?
+    __libc_format_log(ANDROID_LOG_FATAL, "libc", "Failed while talking to debuggerd: %s",
+                      strerror(errno));
+  }
+
+  close(s);
 }
 
 /*
  * Catches fatal signals so we can ask debuggerd to ptrace us before
  * we crash.
  */
-void debuggerd_signal_handler(int n, siginfo_t* info, void*) {
-    /*
-     * It's possible somebody cleared the SA_SIGINFO flag, which would mean
-     * our "info" arg holds an undefined value.
-     */
-    if (!have_siginfo(n)) {
-        info = NULL;
-    }
+static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void*) {
+  // It's possible somebody cleared the SA_SIGINFO flag, which would mean
+  // our "info" arg holds an undefined value.
+  if (!have_siginfo(signal_number)) {
+    info = NULL;
+  }
 
-    log_signal_summary(n, info);
+  log_signal_summary(signal_number, info);
 
-    pid_t tid = gettid();
-    int s = socket_abstract_client(DEBUGGER_SOCKET_NAME, SOCK_STREAM);
+  send_debuggerd_packet(info);
 
-    if (s >= 0) {
-        // debuggerd knows our pid from the credentials on the
-        // local socket but we need to tell it the tid of the crashing thread.
-        // debuggerd will be paranoid and verify that we sent a tid
-        // that's actually in our process.
-        debugger_msg_t msg;
-        msg.action = DEBUGGER_ACTION_CRASH;
-        msg.tid = tid;
-        msg.abort_msg_address = reinterpret_cast<uintptr_t>(gAbortMessage);
-        int ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg)));
-        if (ret == sizeof(msg)) {
-            // if the write failed, there is no point trying to read a response.
-            ret = TEMP_FAILURE_RETRY(read(s, &tid, 1));
-            int saved_errno = errno;
-            notify_gdb_of_libraries();
-            errno = saved_errno;
-        }
+  // Remove our net so we fault for real when we return.
+  signal(signal_number, SIG_DFL);
 
-        if (ret < 0) {
-            /* read or write failed -- broken connection? */
-            __libc_format_log(ANDROID_LOG_FATAL, "libc", "Failed while talking to debuggerd: %s",
-                              strerror(errno));
-        }
-
-        close(s);
-    } else {
-        /* socket failed; maybe process ran out of fds */
-        __libc_format_log(ANDROID_LOG_FATAL, "libc", "Unable to open connection to debuggerd: %s",
-                          strerror(errno));
-    }
-
-    /* remove our net so we fault for real when we return */
-    signal(n, SIG_DFL);
-
-    /*
-     * These signals are not re-thrown when we resume.  This means that
-     * crashing due to (say) SIGPIPE doesn't work the way you'd expect it
-     * to.  We work around this by throwing them manually.  We don't want
-     * to do this for *all* signals because it'll screw up the address for
-     * faults like SIGSEGV.
-     */
-    switch (n) {
-        case SIGABRT:
-        case SIGFPE:
-        case SIGPIPE:
+  // These signals are not re-thrown when we resume.  This means that
+  // crashing due to (say) SIGPIPE doesn't work the way you'd expect it
+  // to.  We work around this by throwing them manually.  We don't want
+  // to do this for *all* signals because it'll screw up the si_addr for
+  // faults like SIGSEGV. It does screw up the si_code, which is why we
+  // passed that to debuggerd above.
+  switch (signal_number) {
+    case SIGABRT:
+    case SIGFPE:
+    case SIGPIPE:
 #if defined(SIGSTKFLT)
-        case SIGSTKFLT:
+    case SIGSTKFLT:
 #endif
-            (void) tgkill(getpid(), gettid(), n);
-            break;
-        default:    // SIGILL, SIGBUS, SIGSEGV
-            break;
-    }
+    case SIGTRAP:
+      tgkill(getpid(), gettid(), signal_number);
+      break;
+    default:    // SIGILL, SIGBUS, SIGSEGV
+      break;
+  }
 }
 
-void debuggerd_init() {
-    struct sigaction action;
-    memset(&action, 0, sizeof(action));
-    sigemptyset(&action.sa_mask);
-    action.sa_sigaction = debuggerd_signal_handler;
-    action.sa_flags = SA_RESTART | SA_SIGINFO;
+__LIBC_HIDDEN__ void debuggerd_init() {
+  struct sigaction action;
+  memset(&action, 0, sizeof(action));
+  sigemptyset(&action.sa_mask);
+  action.sa_sigaction = debuggerd_signal_handler;
+  action.sa_flags = SA_RESTART | SA_SIGINFO;
 
-    // Use the alternate signal stack if available so we can catch stack overflows.
-    action.sa_flags |= SA_ONSTACK;
+  // Use the alternate signal stack if available so we can catch stack overflows.
+  action.sa_flags |= SA_ONSTACK;
 
-    sigaction(SIGABRT, &action, NULL);
-    sigaction(SIGBUS, &action, NULL);
-    sigaction(SIGFPE, &action, NULL);
-    sigaction(SIGILL, &action, NULL);
-    sigaction(SIGPIPE, &action, NULL);
-    sigaction(SIGSEGV, &action, NULL);
+  sigaction(SIGABRT, &action, NULL);
+  sigaction(SIGBUS, &action, NULL);
+  sigaction(SIGFPE, &action, NULL);
+  sigaction(SIGILL, &action, NULL);
+  sigaction(SIGPIPE, &action, NULL);
+  sigaction(SIGSEGV, &action, NULL);
 #if defined(SIGSTKFLT)
-    sigaction(SIGSTKFLT, &action, NULL);
+  sigaction(SIGSTKFLT, &action, NULL);
 #endif
-    sigaction(SIGTRAP, &action, NULL);
+  sigaction(SIGTRAP, &action, NULL);
 }
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index 1e9d9bc..5d6db8e 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -20,6 +20,7 @@
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <android/dlext.h>
 
 #include <bionic/pthread_internal.h>
 #include "private/bionic_tls.h"
@@ -28,7 +29,7 @@
 
 /* This file hijacks the symbols stubbed out in libdl.so. */
 
-static pthread_mutex_t gDlMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+static pthread_mutex_t g_dl_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
 
 static const char* __bionic_set_dlerror(char* new_value) {
   char** dlerror_slot = &reinterpret_cast<char**>(__get_tls())[TLS_SLOT_DLERROR];
@@ -55,18 +56,18 @@
 }
 
 void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
-  ScopedPthreadMutexLocker locker(&gDlMutex);
+  ScopedPthreadMutexLocker locker(&g_dl_mutex);
   do_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
 }
 
 void android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
-  ScopedPthreadMutexLocker locker(&gDlMutex);
+  ScopedPthreadMutexLocker locker(&g_dl_mutex);
   do_android_update_LD_LIBRARY_PATH(ld_library_path);
 }
 
-void* dlopen(const char* filename, int flags) {
-  ScopedPthreadMutexLocker locker(&gDlMutex);
-  soinfo* result = do_dlopen(filename, flags);
+static void* dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
+  ScopedPthreadMutexLocker locker(&g_dl_mutex);
+  soinfo* result = do_dlopen(filename, flags, extinfo);
   if (result == NULL) {
     __bionic_format_dlerror("dlopen failed", linker_get_error_buffer());
     return NULL;
@@ -74,39 +75,49 @@
   return result;
 }
 
-void* dlsym(void* handle, const char* symbol) {
-  ScopedPthreadMutexLocker locker(&gDlMutex);
+void* android_dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
+  return dlopen_ext(filename, flags, extinfo);
+}
 
+void* dlopen(const char* filename, int flags) {
+  return dlopen_ext(filename, flags, NULL);
+}
+
+void* dlsym(void* handle, const char* symbol) {
+  ScopedPthreadMutexLocker locker(&g_dl_mutex);
+
+#if !defined(__LP64__)
   if (handle == NULL) {
     __bionic_format_dlerror("dlsym library handle is null", NULL);
     return NULL;
   }
+#endif
+
   if (symbol == NULL) {
     __bionic_format_dlerror("dlsym symbol name is null", NULL);
     return NULL;
   }
 
   soinfo* found = NULL;
-  Elf_Sym* sym = NULL;
+  ElfW(Sym)* sym = NULL;
   if (handle == RTLD_DEFAULT) {
     sym = dlsym_linear_lookup(symbol, &found, NULL);
   } else if (handle == RTLD_NEXT) {
-    void* ret_addr = __builtin_return_address(0);
-    soinfo* si = find_containing_library(ret_addr);
+    void* caller_addr = __builtin_return_address(0);
+    soinfo* si = find_containing_library(caller_addr);
 
     sym = NULL;
     if (si && si->next) {
       sym = dlsym_linear_lookup(symbol, &found, si->next);
     }
   } else {
-    found = reinterpret_cast<soinfo*>(handle);
-    sym = dlsym_handle_lookup(found, symbol);
+    sym = dlsym_handle_lookup(reinterpret_cast<soinfo*>(handle), &found, symbol);
   }
 
   if (sym != NULL) {
     unsigned bind = ELF_ST_BIND(sym->st_info);
 
-    if (bind == STB_GLOBAL && sym->st_shndx != 0) {
+    if ((bind == STB_GLOBAL || bind == STB_WEAK) && sym->st_shndx != 0) {
       return reinterpret_cast<void*>(sym->st_value + found->load_bias);
     }
 
@@ -119,7 +130,7 @@
 }
 
 int dladdr(const void* addr, Dl_info* info) {
-  ScopedPthreadMutexLocker locker(&gDlMutex);
+  ScopedPthreadMutexLocker locker(&g_dl_mutex);
 
   // Determine if this address can be found in any library currently mapped.
   soinfo* si = find_containing_library(addr);
@@ -131,21 +142,23 @@
 
   info->dli_fname = si->name;
   // Address at which the shared object is loaded.
-  info->dli_fbase = (void*) si->base;
+  info->dli_fbase = reinterpret_cast<void*>(si->base);
 
   // Determine if any symbol in the library contains the specified address.
-  Elf_Sym *sym = dladdr_find_symbol(si, addr);
+  ElfW(Sym)* sym = dladdr_find_symbol(si, addr);
   if (sym != NULL) {
     info->dli_sname = si->strtab + sym->st_name;
-    info->dli_saddr = (void*)(si->load_bias + sym->st_value);
+    info->dli_saddr = reinterpret_cast<void*>(si->load_bias + sym->st_value);
   }
 
   return 1;
 }
 
 int dlclose(void* handle) {
-  ScopedPthreadMutexLocker locker(&gDlMutex);
-  return do_dlclose(reinterpret_cast<soinfo*>(handle));
+  ScopedPthreadMutexLocker locker(&g_dl_mutex);
+  do_dlclose(reinterpret_cast<soinfo*>(handle));
+  // dlclose has no defined errors.
+  return 0;
 }
 
 // name_offset: starting index of the name in libdl_info.strtab
@@ -167,135 +180,77 @@
       /* st_size */ 0, \
     }
 
-#if defined(__LP64__)
-#  define ELF_SYM_INITIALIZER ELF64_SYM_INITIALIZER
-#else
-#  define ELF_SYM_INITIALIZER ELF32_SYM_INITIALIZER
-#endif
-
 #if defined(__arm__)
-  // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 9999900000000001 1
-  // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 5678901234567890 1
+  // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 9999900000000001 1111111112222222222 333333333344444444445
+  // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 5678901234567890 1234567890123456789 012345678901234567890
 #  define ANDROID_LIBDL_STRTAB \
-    "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_iterate_phdr\0dl_unwind_find_exidx\0"
+    "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_iterate_phdr\0android_dlopen_ext\0dl_unwind_find_exidx\0"
 #elif defined(__aarch64__) || defined(__i386__) || defined(__mips__) || defined(__x86_64__)
-  // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 9999900000000001 1
-  // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 5678901234567890 1
+  // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 9999900000000001 1111111112222222222
+  // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 5678901234567890 1234567890123456789
 #  define ANDROID_LIBDL_STRTAB \
-    "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_iterate_phdr\0"
+    "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_iterate_phdr\0android_dlopen_ext\0"
 #else
-#  error Unsupported architecture. Only arm, arm64, mips, x86, and x86_64 are presently supported.
+#  error Unsupported architecture. Only arm, arm64, mips, mips64, x86 and x86_64 are presently supported.
 #endif
 
-static Elf_Sym gLibDlSymtab[] = {
+static ElfW(Sym) g_libdl_symtab[] = {
   // Total length of libdl_info.strtab, including trailing 0.
   // This is actually the STH_UNDEF entry. Technically, it's
   // supposed to have st_name == 0, but instead, it points to an index
   // in the strtab with a \0 to make iterating through the symtab easier.
-  ELF_SYM_INITIALIZER(sizeof(ANDROID_LIBDL_STRTAB) - 1, NULL, 0),
-  ELF_SYM_INITIALIZER(  0, &dlopen, 1),
-  ELF_SYM_INITIALIZER(  7, &dlclose, 1),
-  ELF_SYM_INITIALIZER( 15, &dlsym, 1),
-  ELF_SYM_INITIALIZER( 21, &dlerror, 1),
-  ELF_SYM_INITIALIZER( 29, &dladdr, 1),
-  ELF_SYM_INITIALIZER( 36, &android_update_LD_LIBRARY_PATH, 1),
-  ELF_SYM_INITIALIZER( 67, &android_get_LD_LIBRARY_PATH, 1),
-  ELF_SYM_INITIALIZER( 95, &dl_iterate_phdr, 1),
+  ELFW(SYM_INITIALIZER)(sizeof(ANDROID_LIBDL_STRTAB) - 1, NULL, 0),
+  ELFW(SYM_INITIALIZER)(  0, &dlopen, 1),
+  ELFW(SYM_INITIALIZER)(  7, &dlclose, 1),
+  ELFW(SYM_INITIALIZER)( 15, &dlsym, 1),
+  ELFW(SYM_INITIALIZER)( 21, &dlerror, 1),
+  ELFW(SYM_INITIALIZER)( 29, &dladdr, 1),
+  ELFW(SYM_INITIALIZER)( 36, &android_update_LD_LIBRARY_PATH, 1),
+  ELFW(SYM_INITIALIZER)( 67, &android_get_LD_LIBRARY_PATH, 1),
+  ELFW(SYM_INITIALIZER)( 95, &dl_iterate_phdr, 1),
+  ELFW(SYM_INITIALIZER)(111, &android_dlopen_ext, 1),
 #if defined(__arm__)
-  ELF_SYM_INITIALIZER(111, &dl_unwind_find_exidx, 1),
+  ELFW(SYM_INITIALIZER)(130, &dl_unwind_find_exidx, 1),
 #endif
 };
 
 // Fake out a hash table with a single bucket.
 //
-// A search of the hash table will look through gLibDlSymtab starting with index 1, then
-// use gLibDlChains to find the next index to look at. gLibDlChains should be set up to
-// walk through every element in gLibDlSymtab, and then end with 0 (sentinel value).
+// A search of the hash table will look through g_libdl_symtab starting with index 1, then
+// use g_libdl_chains to find the next index to look at. g_libdl_chains should be set up to
+// walk through every element in g_libdl_symtab, and then end with 0 (sentinel value).
 //
-// That is, gLibDlChains should look like { 0, 2, 3, ... N, 0 } where N is the number
-// of actual symbols, or nelems(gLibDlSymtab)-1 (since the first element of gLibDlSymtab is not
+// That is, g_libdl_chains should look like { 0, 2, 3, ... N, 0 } where N is the number
+// of actual symbols, or nelems(g_libdl_symtab)-1 (since the first element of g_libdl_symtab is not
 // a real symbol). (See soinfo_elf_lookup().)
 //
 // Note that adding any new symbols here requires stubbing them out in libdl.
-static unsigned gLibDlBuckets[1] = { 1 };
+static unsigned g_libdl_buckets[1] = { 1 };
 #if defined(__arm__)
-static unsigned gLibDlChains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
 #else
-static unsigned gLibDlChains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 0 };
+static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
 #endif
 
+// Defined as global because we do not yet have access
+// to synchronization functions __cxa_guard_* needed
+// to define statics inside functions.
+static soinfo __libdl_info;
+
 // This is used by the dynamic linker. Every process gets these symbols for free.
-soinfo libdl_info = {
-    "libdl.so",
+soinfo* get_libdl_info() {
+  if (__libdl_info.name[0] == '\0') {
+    // initialize
+    strncpy(__libdl_info.name, "libdl.so", sizeof(__libdl_info.name));
+    __libdl_info.flags = FLAG_LINKED | FLAG_NEW_SOINFO;
+    __libdl_info.strtab = ANDROID_LIBDL_STRTAB;
+    __libdl_info.symtab = g_libdl_symtab;
+    __libdl_info.nbucket = sizeof(g_libdl_buckets)/sizeof(unsigned);
+    __libdl_info.nchain = sizeof(g_libdl_chains)/sizeof(unsigned);
+    __libdl_info.bucket = g_libdl_buckets;
+    __libdl_info.chain = g_libdl_chains;
+    __libdl_info.has_DT_SYMBOLIC = true;
+  }
 
-    .phdr = 0,
-    .phnum = 0,
-    .entry = 0,
-    .base = 0,
-    .size = 0,
-
-#if !defined(__LP64__)
-    .unused1 = 0,
-#endif
-
-    .dynamic = 0,
-
-#if !defined(__LP64__)
-    .unused2 = 0, .unused3 = 0,
-#endif
-
-    .next = 0,
-
-    .flags = FLAG_LINKED,
-
-    .strtab = ANDROID_LIBDL_STRTAB,
-    .symtab = gLibDlSymtab,
-
-    .nbucket = sizeof(gLibDlBuckets)/sizeof(unsigned),
-    .nchain = sizeof(gLibDlChains)/sizeof(unsigned),
-    .bucket = gLibDlBuckets,
-    .chain = gLibDlChains,
-
-#if defined(USE_RELA)
-    .plt_rela = 0,
-    .plt_rela_count = 0,
-    .rela = 0,
-    .rela_count = 0,
-#else
-    .plt_got = 0,
-    .plt_rel = 0,
-    .plt_rel_count = 0,
-    .rel = 0,
-    .rel_count = 0,
-#endif
-
-    .preinit_array = 0,
-    .preinit_array_count = 0,
-
-    .init_array = 0,
-    .init_array_count = 0,
-
-    .fini_array = 0,
-    .fini_array_count = 0,
-
-    .init_func = 0,
-    .fini_func = 0,
-
-#if defined(__arm__)
-    .ARM_exidx = 0,
-    .ARM_exidx_count = 0,
-#elif defined(__mips__)
-    .mips_symtabno = 0,
-    .mips_local_gotno = 0,
-    .mips_gotsym = 0,
-#endif
-
-    .ref_count = 0,
-    { .l_addr = 0, .l_name = 0, .l_ld = 0, .l_next = 0, .l_prev = 0, },
-    .constructors_called = false,
-    .load_bias = 0,
-#if !defined(__LP64__)
-    .has_text_relocations = false,
-#endif
-    .has_DT_SYMBOLIC = true,
-};
+  return &__libdl_info;
+}
diff --git a/linker/linked_list.h b/linker/linked_list.h
new file mode 100644
index 0000000..8096e62
--- /dev/null
+++ b/linker/linked_list.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LINKED_LIST_H
+#define __LINKED_LIST_H
+
+#include "private/bionic_macros.h"
+
+template<typename T>
+struct LinkedListEntry {
+  LinkedListEntry<T>* next;
+  T* element;
+};
+
+/*
+ * Represents linked list of objects of type T
+ */
+template<typename T, typename Allocator>
+class LinkedList {
+ public:
+  LinkedList() : head_(nullptr), tail_(nullptr) {}
+
+  void push_front(T* const element) {
+    LinkedListEntry<T>* new_entry = Allocator::alloc();
+    new_entry->next = head_;
+    new_entry->element = element;
+    head_ = new_entry;
+    if (tail_ == nullptr) {
+      tail_ = new_entry;
+    }
+  }
+
+  void push_back(T* const element) {
+    LinkedListEntry<T>* new_entry = Allocator::alloc();
+    new_entry->next = nullptr;
+    new_entry->element = element;
+    if (tail_ == nullptr) {
+      tail_ = head_ = new_entry;
+    } else {
+      tail_->next = new_entry;
+      tail_ = new_entry;
+    }
+  }
+
+  T* pop_front() {
+    if (head_ == nullptr) {
+      return nullptr;
+    }
+
+    LinkedListEntry<T>* entry = head_;
+    T* element = entry->element;
+    head_ = entry->next;
+    Allocator::free(entry);
+
+    if (head_ == nullptr) {
+      tail_ = nullptr;
+    }
+
+    return element;
+  }
+
+  void clear() {
+    while (head_ != nullptr) {
+      LinkedListEntry<T>* p = head_;
+      head_ = head_->next;
+      Allocator::free(p);
+    }
+
+    tail_ = nullptr;
+  }
+
+  template<typename F>
+  void for_each(F&& action) {
+    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
+      if (e->element != nullptr) {
+        action(e->element);
+      }
+    }
+  }
+
+  template<typename F>
+  void remove_if(F&& predicate) {
+    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
+      if (e->element != nullptr && predicate(e->element)) {
+        e->element = nullptr;
+      }
+    }
+  }
+
+  bool contains(const T* el) {
+    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
+      if (e->element != nullptr && e->element == el) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+ private:
+  LinkedListEntry<T>* head_;
+  LinkedListEntry<T>* tail_;
+  DISALLOW_COPY_AND_ASSIGN(LinkedList);
+};
+
+#endif // __LINKED_LIST_H
diff --git a/linker/linker.cpp b/linker/linker.cpp
old mode 100755
new mode 100644
index 9bc9afe..cf65705
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -29,13 +29,11 @@
 #include <dlfcn.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <linux/auxvec.h>
+#include <inttypes.h>
 #include <pthread.h>
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/atomics.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -44,11 +42,13 @@
 #include "private/bionic_tls.h"
 #include "private/KernelArgumentBlock.h"
 #include "private/ScopedPthreadMutexLocker.h"
+#include "private/ScopedFd.h"
 
 #include "linker.h"
 #include "linker_debug.h"
 #include "linker_environ.h"
 #include "linker_phdr.h"
+#include "linker_allocator.h"
 
 /* >>> IMPORTANT NOTE - READ ME BEFORE MODIFYING <<<
  *
@@ -60,31 +60,35 @@
  *
  * open issues / todo:
  *
- * - are we doing everything we should for ARM_COPY relocations?
  * - cleaner error reporting
  * - after linking, set as much stuff as possible to READONLY
  *   and NOEXEC
  */
 
-static bool soinfo_link_image(soinfo* si);
-static Elf_Addr get_elf_exec_load_bias(const Elf_Ehdr* elf);
+#if defined(__LP64__)
+#define SEARCH_NAME(x) x
+#else
+// Nvidia drivers are relying on the bug:
+// http://code.google.com/p/android/issues/detail?id=6670
+// so we continue to use base-name lookup for lp32
+static const char* get_base_name(const char* name) {
+  const char* bname = strrchr(name, '/');
+  return bname ? bname + 1 : name;
+}
+#define SEARCH_NAME(x) get_base_name(x)
+#endif
 
-// We can't use malloc(3) in the dynamic linker. We use a linked list of anonymous
-// maps, each a single page in size. The pages are broken up into as many struct soinfo
-// objects as will fit, and they're all threaded together on a free list.
-#define SOINFO_PER_POOL ((PAGE_SIZE - sizeof(soinfo_pool_t*)) / sizeof(soinfo))
-struct soinfo_pool_t {
-  soinfo_pool_t* next;
-  soinfo info[SOINFO_PER_POOL];
-};
-static struct soinfo_pool_t* gSoInfoPools = NULL;
-static soinfo* gSoInfoFreeList = NULL;
+static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo);
+static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf);
 
-static soinfo* solist = &libdl_info;
-static soinfo* sonext = &libdl_info;
+static LinkerAllocator<soinfo> g_soinfo_allocator;
+static LinkerAllocator<LinkedListEntry<soinfo>> g_soinfo_links_allocator;
+
+static soinfo* solist;
+static soinfo* sonext;
 static soinfo* somain; /* main process, always the one after libdl_info */
 
-static const char* const gDefaultLdPaths[] = {
+static const char* const kDefaultLdPaths[] = {
 #if defined(__LP64__)
   "/vendor/lib64",
   "/system/lib64",
@@ -101,17 +105,17 @@
 #define LDPRELOAD_BUFSIZE (LDPRELOAD_MAX*64)
 #define LDPRELOAD_MAX 8
 
-static char gLdPathsBuffer[LDPATH_BUFSIZE];
-static const char* gLdPaths[LDPATH_MAX + 1];
+static char g_ld_library_paths_buffer[LDPATH_BUFSIZE];
+static const char* g_ld_library_paths[LDPATH_MAX + 1];
 
-static char gLdPreloadsBuffer[LDPRELOAD_BUFSIZE];
-static const char* gLdPreloadNames[LDPRELOAD_MAX + 1];
+static char g_ld_preloads_buffer[LDPRELOAD_BUFSIZE];
+static const char* g_ld_preload_names[LDPRELOAD_MAX + 1];
 
-static soinfo* gLdPreloads[LDPRELOAD_MAX + 1];
+static soinfo* g_ld_preloads[LDPRELOAD_MAX + 1];
 
-__LIBC_HIDDEN__ int gLdDebugVerbosity;
+__LIBC_HIDDEN__ int g_ld_debug_verbosity;
 
-__LIBC_HIDDEN__ abort_msg_t* gAbortMessage = NULL; // For debuggerd.
+__LIBC_HIDDEN__ abort_msg_t* g_abort_message = NULL; // For debuggerd.
 
 enum RelocationKind {
     kRelocAbsolute = 0,
@@ -143,12 +147,12 @@
     do { \
         if ((((offset) >> 12) >> 5) < 4096) \
             bitmask[((offset) >> 12) >> 5] |= (1 << (((offset) >> 12) & 31)); \
-    } while(0)
+    } while (0)
 #else
 #define MARK(offset) \
     do { \
         bitmask[((offset) >> 12) >> 3] |= (1 << (((offset) >> 12) & 7)); \
-    } while(0)
+    } while (0)
 #endif
 #else
 #define MARK(x) do {} while (0)
@@ -159,16 +163,12 @@
 #define DISALLOW_ALLOCATION(return_type, name, ...) \
     return_type name __VA_ARGS__ \
     { \
-        const char* msg = "ERROR: " #name " called from the dynamic linker!\n"; \
-        __libc_format_log(ANDROID_LOG_FATAL, "linker", "%s", msg); \
-        write(2, msg, strlen(msg)); \
-        abort(); \
+        __libc_fatal("ERROR: " #name " called from the dynamic linker!\n"); \
     }
-#define UNUSED __attribute__((unused))
-DISALLOW_ALLOCATION(void*, malloc, (size_t u UNUSED));
-DISALLOW_ALLOCATION(void, free, (void* u UNUSED));
-DISALLOW_ALLOCATION(void*, realloc, (void* u1 UNUSED, size_t u2 UNUSED));
-DISALLOW_ALLOCATION(void*, calloc, (size_t u1 UNUSED, size_t u2 UNUSED));
+DISALLOW_ALLOCATION(void*, malloc, (size_t u __unused));
+DISALLOW_ALLOCATION(void, free, (void* u __unused));
+DISALLOW_ALLOCATION(void*, realloc, (void* u1 __unused, size_t u2 __unused));
+DISALLOW_ALLOCATION(void*, calloc, (size_t u1 __unused, size_t u2 __unused));
 
 static char tmp_err_buf[768];
 static char __linker_dl_err_buf[768];
@@ -187,17 +187,16 @@
  */
 extern "C" void __attribute__((noinline)) __attribute__((visibility("default"))) rtld_db_dlactivity();
 
-static r_debug _r_debug = {1, NULL, &rtld_db_dlactivity, RT_CONSISTENT, 0};
-static link_map_t* r_debug_tail = 0;
+static pthread_mutex_t g__r_debug_mutex = PTHREAD_MUTEX_INITIALIZER;
+static r_debug _r_debug = {1, NULL, reinterpret_cast<uintptr_t>(&rtld_db_dlactivity), r_debug::RT_CONSISTENT, 0};
+static link_map* r_debug_tail = 0;
 
-static pthread_mutex_t gDebugMutex = PTHREAD_MUTEX_INITIALIZER;
-
-static void insert_soinfo_into_debug_map(soinfo * info) {
+static void insert_soinfo_into_debug_map(soinfo* info) {
     // Copy the necessary fields into the debug structure.
-    link_map_t* map = &(info->link_map);
+    link_map* map = &(info->link_map_head);
     map->l_addr = info->load_bias;
-    map->l_name = (char*) info->name;
-    map->l_ld = (uintptr_t)info->dynamic;
+    map->l_name = reinterpret_cast<char*>(info->name);
+    map->l_ld = info->dynamic;
 
     /* Stick the new library at the end of the list.
      * gdb tends to care more about libc than it does
@@ -217,7 +216,7 @@
 }
 
 static void remove_soinfo_from_debug_map(soinfo* info) {
-    link_map_t* map = &(info->link_map);
+    link_map* map = &(info->link_map_head);
 
     if (r_debug_tail == map) {
         r_debug_tail = map->l_prev;
@@ -237,14 +236,14 @@
         return;
     }
 
-    ScopedPthreadMutexLocker locker(&gDebugMutex);
+    ScopedPthreadMutexLocker locker(&g__r_debug_mutex);
 
-    _r_debug.r_state = RT_ADD;
+    _r_debug.r_state = r_debug::RT_ADD;
     rtld_db_dlactivity();
 
     insert_soinfo_into_debug_map(info);
 
-    _r_debug.r_state = RT_CONSISTENT;
+    _r_debug.r_state = r_debug::RT_CONSISTENT;
     rtld_db_dlactivity();
 }
 
@@ -254,78 +253,55 @@
         return;
     }
 
-    ScopedPthreadMutexLocker locker(&gDebugMutex);
+    ScopedPthreadMutexLocker locker(&g__r_debug_mutex);
 
-    _r_debug.r_state = RT_DELETE;
+    _r_debug.r_state = r_debug::RT_DELETE;
     rtld_db_dlactivity();
 
     remove_soinfo_from_debug_map(info);
 
-    _r_debug.r_state = RT_CONSISTENT;
+    _r_debug.r_state = r_debug::RT_CONSISTENT;
     rtld_db_dlactivity();
 }
 
 void notify_gdb_of_libraries() {
-    _r_debug.r_state = RT_ADD;
-    rtld_db_dlactivity();
-    _r_debug.r_state = RT_CONSISTENT;
-    rtld_db_dlactivity();
+  _r_debug.r_state = r_debug::RT_ADD;
+  rtld_db_dlactivity();
+  _r_debug.r_state = r_debug::RT_CONSISTENT;
+  rtld_db_dlactivity();
 }
 
-static bool ensure_free_list_non_empty() {
-  if (gSoInfoFreeList != NULL) {
-    return true;
-  }
-
-  // Allocate a new pool.
-  soinfo_pool_t* pool = reinterpret_cast<soinfo_pool_t*>(mmap(NULL, sizeof(*pool),
-                                                              PROT_READ|PROT_WRITE,
-                                                              MAP_PRIVATE|MAP_ANONYMOUS, 0, 0));
-  if (pool == MAP_FAILED) {
-    return false;
-  }
-
-  // Add the pool to our list of pools.
-  pool->next = gSoInfoPools;
-  gSoInfoPools = pool;
-
-  // Chain the entries in the new pool onto the free list.
-  gSoInfoFreeList = &pool->info[0];
-  soinfo* next = NULL;
-  for (int i = SOINFO_PER_POOL - 1; i >= 0; --i) {
-    pool->info[i].next = next;
-    next = &pool->info[i];
-  }
-
-  return true;
+LinkedListEntry<soinfo>* SoinfoListAllocator::alloc() {
+  return g_soinfo_links_allocator.alloc();
 }
 
-static void set_soinfo_pool_protection(int protection) {
-  for (soinfo_pool_t* p = gSoInfoPools; p != NULL; p = p->next) {
-    if (mprotect(p, sizeof(*p), protection) == -1) {
-      abort(); // Can't happen.
-    }
-  }
+void SoinfoListAllocator::free(LinkedListEntry<soinfo>* entry) {
+  g_soinfo_links_allocator.free(entry);
 }
 
-static soinfo* soinfo_alloc(const char* name) {
+static void protect_data(int protection) {
+  g_soinfo_allocator.protect_all(protection);
+  g_soinfo_links_allocator.protect_all(protection);
+}
+
+static soinfo* soinfo_alloc(const char* name, struct stat* file_stat) {
   if (strlen(name) >= SOINFO_NAME_LEN) {
     DL_ERR("library name \"%s\" too long", name);
     return NULL;
   }
 
-  if (!ensure_free_list_non_empty()) {
-    DL_ERR("out of memory when loading \"%s\"", name);
-    return NULL;
-  }
-
-  // Take the head element off the free list.
-  soinfo* si = gSoInfoFreeList;
-  gSoInfoFreeList = gSoInfoFreeList->next;
+  soinfo* si = g_soinfo_allocator.alloc();
 
   // Initialize the new element.
   memset(si, 0, sizeof(soinfo));
   strlcpy(si->name, name, sizeof(si->name));
+  si->flags = FLAG_NEW_SOINFO;
+
+  if (file_stat != NULL) {
+    si->set_st_dev(file_stat->st_dev);
+    si->set_st_ino(file_stat->st_ino);
+  }
+
   sonext->next = si;
   sonext = si;
 
@@ -333,12 +309,15 @@
   return si;
 }
 
-static void soinfo_free(soinfo* si)
-{
+static void soinfo_free(soinfo* si) {
     if (si == NULL) {
         return;
     }
 
+    if (si->base != 0 && si->size != 0) {
+      munmap(reinterpret_cast<void*>(si->base), si->size);
+    }
+
     soinfo *prev = NULL, *trav;
 
     TRACE("name %s: freeing soinfo @ %p", si->name, si);
@@ -354,6 +333,9 @@
         return;
     }
 
+    // clear links to/from si
+    si->remove_all_links();
+
     /* prev will never be NULL, because the first entry in solist is
        always the static libdl_info.
     */
@@ -361,8 +343,8 @@
     if (si == sonext) {
         sonext = prev;
     }
-    si->next = gSoInfoFreeList;
-    gSoInfoFreeList = si;
+
+    g_soinfo_allocator.free(si);
 }
 
 
@@ -392,14 +374,14 @@
 }
 
 static void parse_LD_LIBRARY_PATH(const char* path) {
-  parse_path(path, ":", gLdPaths,
-             gLdPathsBuffer, sizeof(gLdPathsBuffer), LDPATH_MAX);
+  parse_path(path, ":", g_ld_library_paths,
+             g_ld_library_paths_buffer, sizeof(g_ld_library_paths_buffer), LDPATH_MAX);
 }
 
 static void parse_LD_PRELOAD(const char* path) {
   // We have historically supported ':' as well as ' ' in LD_PRELOAD.
-  parse_path(path, " :", gLdPreloadNames,
-             gLdPreloadsBuffer, sizeof(gLdPreloadsBuffer), LDPRELOAD_MAX);
+  parse_path(path, " :", g_ld_preload_names,
+             g_ld_preloads_buffer, sizeof(g_ld_preloads_buffer), LDPRELOAD_MAX);
 }
 
 #if defined(__arm__)
@@ -413,18 +395,16 @@
  *
  * This function is exposed via dlfcn.cpp and libdl.so.
  */
-_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount)
-{
-    soinfo *si;
+_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
     unsigned addr = (unsigned)pc;
 
-    for (si = solist; si != 0; si = si->next) {
+    for (soinfo* si = solist; si != 0; si = si->next) {
         if ((addr >= si->base) && (addr < (si->base + si->size))) {
             *pcount = si->ARM_exidx_count;
             return (_Unwind_Ptr)si->ARM_exidx;
         }
     }
-   *pcount = 0;
+    *pcount = 0;
     return NULL;
 }
 
@@ -432,15 +412,12 @@
 
 /* Here, we only have to provide a callback to iterate across all the
  * loaded libraries. gcc_eh does the rest. */
-int
-dl_iterate_phdr(int (*cb)(dl_phdr_info *info, size_t size, void *data),
-                void *data)
-{
+int dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data) {
     int rv = 0;
     for (soinfo* si = solist; si != NULL; si = si->next) {
         dl_phdr_info dl_info;
-        dl_info.dlpi_addr = si->link_map.l_addr;
-        dl_info.dlpi_name = si->link_map.l_name;
+        dl_info.dlpi_addr = si->link_map_head.l_addr;
+        dl_info.dlpi_name = si->link_map_head.l_name;
         dl_info.dlpi_phdr = si->phdr;
         dl_info.dlpi_phnum = si->phnum;
         rv = cb(&dl_info, sizeof(dl_phdr_info), data);
@@ -451,40 +428,49 @@
     return rv;
 }
 
-static Elf_Sym* soinfo_elf_lookup(soinfo* si, unsigned hash, const char* name) {
-    Elf_Sym* symtab = si->symtab;
-    const char* strtab = si->strtab;
+static ElfW(Sym)* soinfo_elf_lookup(soinfo* si, unsigned hash, const char* name) {
+  ElfW(Sym)* symtab = si->symtab;
+  const char* strtab = si->strtab;
 
-    TRACE_TYPE(LOOKUP, "SEARCH %s in %s@%p %x %zd",
-               name, si->name, reinterpret_cast<void*>(si->base), hash, hash % si->nbucket);
+  TRACE_TYPE(LOOKUP, "SEARCH %s in %s@%p %x %zd",
+             name, si->name, reinterpret_cast<void*>(si->base), hash, hash % si->nbucket);
 
-    for (unsigned n = si->bucket[hash % si->nbucket]; n != 0; n = si->chain[n]) {
-        Elf_Sym* s = symtab + n;
-        if (strcmp(strtab + s->st_name, name)) continue;
+  for (unsigned n = si->bucket[hash % si->nbucket]; n != 0; n = si->chain[n]) {
+    ElfW(Sym)* s = symtab + n;
+    if (strcmp(strtab + s->st_name, name)) continue;
 
-            /* only concern ourselves with global and weak symbol definitions */
-        switch (ELF_ST_BIND(s->st_info)) {
-        case STB_GLOBAL:
-        case STB_WEAK:
-            if (s->st_shndx == SHN_UNDEF) {
-                continue;
-            }
-
-            TRACE_TYPE(LOOKUP, "FOUND %s in %s (%p) %zd",
-                       name, si->name, reinterpret_cast<void*>(s->st_value),
-                       static_cast<size_t>(s->st_size));
-            return s;
+    /* only concern ourselves with global and weak symbol definitions */
+    switch (ELF_ST_BIND(s->st_info)) {
+      case STB_GLOBAL:
+      case STB_WEAK:
+        if (s->st_shndx == SHN_UNDEF) {
+          continue;
         }
-    }
 
-    return NULL;
+        TRACE_TYPE(LOOKUP, "FOUND %s in %s (%p) %zd",
+                 name, si->name, reinterpret_cast<void*>(s->st_value),
+                 static_cast<size_t>(s->st_size));
+        return s;
+      case STB_LOCAL:
+        continue;
+      default:
+        __libc_fatal("ERROR: Unexpected ST_BIND value: %d for '%s' in '%s'",
+            ELF_ST_BIND(s->st_info), name, si->name);
+    }
+  }
+
+  TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p %x %zd",
+             name, si->name, reinterpret_cast<void*>(si->base), hash, hash % si->nbucket);
+
+
+  return NULL;
 }
 
 static unsigned elfhash(const char* _name) {
-    const unsigned char* name = (const unsigned char*) _name;
+    const unsigned char* name = reinterpret_cast<const unsigned char*>(_name);
     unsigned h = 0, g;
 
-    while(*name) {
+    while (*name) {
         h = (h << 4) + *name++;
         g = h & 0xf0000000;
         h ^= g;
@@ -493,12 +479,11 @@
     return h;
 }
 
-static Elf_Sym* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, soinfo* needed[]) {
+static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, soinfo* needed[]) {
     unsigned elf_hash = elfhash(name);
-    Elf_Sym* s = NULL;
+    ElfW(Sym)* s = NULL;
 
     if (si != NULL && somain != NULL) {
-
         /*
          * Local scope is executable scope. Just start looking into it right away
          * for the shortcut.
@@ -510,6 +495,15 @@
                 *lsi = si;
                 goto done;
             }
+
+            /* Next, look for it in the preloads list */
+            for (int i = 0; g_ld_preloads[i] != NULL; i++) {
+                s = soinfo_elf_lookup(g_ld_preloads[i], elf_hash, name);
+                if (s != NULL) {
+                    *lsi = g_ld_preloads[i];
+                    goto done;
+                }
+            }
         } else {
             /* Order of symbol lookup is controlled by DT_SYMBOLIC flag */
 
@@ -527,6 +521,15 @@
                     *lsi = somain;
                     goto done;
                 }
+
+                /* Next, look for it in the preloads list */
+                for (int i = 0; g_ld_preloads[i] != NULL; i++) {
+                    s = soinfo_elf_lookup(g_ld_preloads[i], elf_hash, name);
+                    if (s != NULL) {
+                        *lsi = g_ld_preloads[i];
+                        goto done;
+                    }
+                }
             }
 
             /* Look for symbols in the local scope (the object who is
@@ -558,16 +561,16 @@
                     *lsi = somain;
                     goto done;
                 }
-            }
-        }
-    }
 
-    /* Next, look for it in the preloads list */
-    for (int i = 0; gLdPreloads[i] != NULL; i++) {
-        s = soinfo_elf_lookup(gLdPreloads[i], elf_hash, name);
-        if (s != NULL) {
-            *lsi = gLdPreloads[i];
-            goto done;
+                /* Next, look for it in the preloads list */
+                for (int i = 0; g_ld_preloads[i] != NULL; i++) {
+                    s = soinfo_elf_lookup(g_ld_preloads[i], elf_hash, name);
+                    if (s != NULL) {
+                        *lsi = g_ld_preloads[i];
+                        goto done;
+                    }
+                }
+            }
         }
     }
 
@@ -594,17 +597,50 @@
     return NULL;
 }
 
-/* This is used by dlsym(3).  It performs symbol lookup only within the
-   specified soinfo object and not in any of its dependencies.
+// Another soinfo list allocator to use in dlsym. We don't reuse
+// SoinfoListAllocator because it is write-protected most of the time.
+static LinkerAllocator<LinkedListEntry<soinfo>> g_soinfo_list_allocator_rw;
+class SoinfoListAllocatorRW {
+ public:
+  static LinkedListEntry<soinfo>* alloc() {
+    return g_soinfo_list_allocator_rw.alloc();
+  }
 
-   TODO: Only looking in the specified soinfo seems wrong. dlsym(3) says
-   that it should do a breadth first search through the dependency
-   tree. This agrees with the ELF spec (aka System V Application
-   Binary Interface) where in Chapter 5 it discuss resolving "Shared
-   Object Dependencies" in breadth first search order.
- */
-Elf_Sym* dlsym_handle_lookup(soinfo* si, const char* name) {
-    return soinfo_elf_lookup(si, elfhash(name), name);
+  static void free(LinkedListEntry<soinfo>* ptr) {
+    g_soinfo_list_allocator_rw.free(ptr);
+  }
+};
+
+// This is used by dlsym(3).  It performs symbol lookup only within the
+// specified soinfo object and its dependencies in breadth first order.
+ElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name) {
+  LinkedList<soinfo, SoinfoListAllocatorRW> visit_list;
+  LinkedList<soinfo, SoinfoListAllocatorRW> visited;
+  visit_list.push_back(si);
+  soinfo* current_soinfo;
+  while ((current_soinfo = visit_list.pop_front()) != nullptr) {
+    if (visited.contains(current_soinfo)) {
+      continue;
+    }
+
+    ElfW(Sym)* result = soinfo_elf_lookup(current_soinfo, elfhash(name), name);
+
+    if (result != nullptr) {
+      *found = current_soinfo;
+      visit_list.clear();
+      visited.clear();
+      return result;
+    }
+    visited.push_back(current_soinfo);
+
+    current_soinfo->get_children().for_each([&](soinfo* child) {
+      visit_list.push_back(child);
+    });
+  }
+
+  visit_list.clear();
+  visited.clear();
+  return nullptr;
 }
 
 /* This is used by dlsym(3) to performs a global symbol lookup. If the
@@ -612,14 +648,14 @@
    beginning of the global solist. Otherwise the search starts at the
    specified soinfo (for RTLD_NEXT).
  */
-Elf_Sym* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start) {
+ElfW(Sym)* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start) {
   unsigned elf_hash = elfhash(name);
 
   if (start == NULL) {
     start = solist;
   }
 
-  Elf_Sym* s = NULL;
+  ElfW(Sym)* s = NULL;
   for (soinfo* si = start; (s == NULL) && (si != NULL); si = si->next) {
     s = soinfo_elf_lookup(si, elf_hash, name);
     if (s != NULL) {
@@ -637,7 +673,7 @@
 }
 
 soinfo* find_containing_library(const void* p) {
-  Elf_Addr address = reinterpret_cast<Elf_Addr>(p);
+  ElfW(Addr) address = reinterpret_cast<ElfW(Addr)>(p);
   for (soinfo* si = solist; si != NULL; si = si->next) {
     if (address >= si->base && address - si->base < si->size) {
       return si;
@@ -646,13 +682,13 @@
   return NULL;
 }
 
-Elf_Sym* dladdr_find_symbol(soinfo* si, const void* addr) {
-  Elf_Addr soaddr = reinterpret_cast<Elf_Addr>(addr) - si->base;
+ElfW(Sym)* dladdr_find_symbol(soinfo* si, const void* addr) {
+  ElfW(Addr) soaddr = reinterpret_cast<ElfW(Addr)>(addr) - si->base;
 
   // Search the library's symbol table for any defined symbol which
   // contains this address.
   for (size_t i = 0; i < si->nchain; ++i) {
-    Elf_Sym* sym = &si->symtab[i];
+    ElfW(Sym)* sym = &si->symtab[i];
     if (sym->st_shndx != SHN_UNDEF &&
         soaddr >= sym->st_value &&
         soaddr < sym->st_value + sym->st_size) {
@@ -663,19 +699,6 @@
   return NULL;
 }
 
-#if 0
-static void dump(soinfo* si)
-{
-    Elf_Sym* s = si->symtab;
-    for (unsigned n = 0; n < si->nchain; n++) {
-        TRACE("%04d> %08x: %02x %04x %08x %08x %s", n, s,
-               s->st_info, s->st_shndx, s->st_value, s->st_size,
-               si->strtab + s->st_name);
-        s++;
-    }
-}
-#endif
-
 static int open_library_on_path(const char* name, const char* const paths[]) {
   char buf[512];
   for (size_t i = 0; paths[i] != NULL; ++i) {
@@ -702,133 +725,180 @@
       return fd;
     }
     // ...but nvidia binary blobs (at least) rely on this behavior, so fall through for now.
+#if defined(__LP64__)
+    return -1;
+#endif
   }
 
   // Otherwise we try LD_LIBRARY_PATH first, and fall back to the built-in well known paths.
-  int fd = open_library_on_path(name, gLdPaths);
+  int fd = open_library_on_path(name, g_ld_library_paths);
   if (fd == -1) {
-    fd = open_library_on_path(name, gDefaultLdPaths);
+    fd = open_library_on_path(name, kDefaultLdPaths);
   }
   return fd;
 }
 
-static soinfo* load_library(const char* name) {
-    // Open the file.
-    int fd = open_library(name);
-    if (fd == -1) {
+static soinfo* load_library(const char* name, int dlflags, const android_dlextinfo* extinfo) {
+    int fd = -1;
+    ScopedFd file_guard(-1);
+
+    if (extinfo != NULL && (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) != 0) {
+      fd = extinfo->library_fd;
+    } else {
+      // Open the file.
+      fd = open_library(name);
+      if (fd == -1) {
         DL_ERR("library \"%s\" not found", name);
         return NULL;
+      }
+
+      file_guard.reset(fd);
+    }
+
+    ElfReader elf_reader(name, fd);
+
+    struct stat file_stat;
+    if (TEMP_FAILURE_RETRY(fstat(fd, &file_stat)) != 0) {
+      DL_ERR("unable to stat file for the library %s: %s", name, strerror(errno));
+      return NULL;
+    }
+
+    // Check for symlink and other situations where
+    // file can have different names.
+    for (soinfo* si = solist; si != NULL; si = si->next) {
+      if (si->get_st_dev() != 0 &&
+          si->get_st_ino() != 0 &&
+          si->get_st_dev() == file_stat.st_dev &&
+          si->get_st_ino() == file_stat.st_ino) {
+        TRACE("library \"%s\" is already loaded under different name/path \"%s\" - will return existing soinfo", name, si->name);
+        return si;
+      }
+    }
+
+    if ((dlflags & RTLD_NOLOAD) != 0) {
+      return NULL;
     }
 
     // Read the ELF header and load the segments.
-    ElfReader elf_reader(name, fd);
-    if (!elf_reader.Load()) {
+    if (!elf_reader.Load(extinfo)) {
         return NULL;
     }
 
-    const char* bname = strrchr(name, '/');
-    soinfo* si = soinfo_alloc(bname ? bname + 1 : name);
+    soinfo* si = soinfo_alloc(SEARCH_NAME(name), &file_stat);
     if (si == NULL) {
         return NULL;
     }
     si->base = elf_reader.load_start();
     si->size = elf_reader.load_size();
     si->load_bias = elf_reader.load_bias();
-    si->flags = 0;
-    si->entry = 0;
-    si->dynamic = NULL;
     si->phnum = elf_reader.phdr_count();
     si->phdr = elf_reader.loaded_phdr();
+
+    // At this point we know that whatever is loaded @ base is a valid ELF
+    // shared library whose segments are properly mapped in.
+    TRACE("[ load_library base=%p size=%zu name='%s' ]",
+          reinterpret_cast<void*>(si->base), si->size, si->name);
+
+    if (!soinfo_link_image(si, extinfo)) {
+      soinfo_free(si);
+      return NULL;
+    }
+
     return si;
 }
 
-static soinfo *find_loaded_library(const char *name)
-{
-    soinfo *si;
-    const char *bname;
-
-    // TODO: don't use basename only for determining libraries
-    // http://code.google.com/p/android/issues/detail?id=6670
-
-    bname = strrchr(name, '/');
-    bname = bname ? bname + 1 : name;
-
-    for (si = solist; si != NULL; si = si->next) {
-        if (!strcmp(bname, si->name)) {
-            return si;
-        }
+static soinfo *find_loaded_library_by_name(const char* name) {
+  const char* search_name = SEARCH_NAME(name);
+  for (soinfo* si = solist; si != NULL; si = si->next) {
+    if (!strcmp(search_name, si->name)) {
+      return si;
     }
-    return NULL;
+  }
+  return NULL;
 }
 
-static soinfo* find_library_internal(const char* name) {
+static soinfo* find_library_internal(const char* name, int dlflags, const android_dlextinfo* extinfo) {
   if (name == NULL) {
     return somain;
   }
 
-  soinfo* si = find_loaded_library(name);
-  if (si != NULL) {
-    if (si->flags & FLAG_LINKED) {
-      return si;
-    }
-    DL_ERR("OOPS: recursive link to \"%s\"", si->name);
-    return NULL;
-  }
+  soinfo* si = find_loaded_library_by_name(name);
 
-  TRACE("[ '%s' has not been loaded yet.  Locating...]", name);
-  si = load_library(name);
+  // Library might still be loaded, the accurate detection
+  // of this fact is done by load_library
   if (si == NULL) {
-    return NULL;
+    TRACE("[ '%s' has not been found by name.  Trying harder...]", name);
+    si = load_library(name, dlflags, extinfo);
   }
 
-  // At this point we know that whatever is loaded @ base is a valid ELF
-  // shared library whose segments are properly mapped in.
-  TRACE("[ find_library_internal base=%p size=%zu name='%s' ]",
-        reinterpret_cast<void*>(si->base), si->size, si->name);
-
-  if (!soinfo_link_image(si)) {
-    munmap(reinterpret_cast<void*>(si->base), si->size);
-    soinfo_free(si);
+  if (si != NULL && (si->flags & FLAG_LINKED) == 0) {
+    DL_ERR("recursive link to \"%s\"", si->name);
     return NULL;
   }
 
   return si;
 }
 
-static soinfo* find_library(const char* name) {
-  soinfo* si = find_library_internal(name);
+static soinfo* find_library(const char* name, int dlflags, const android_dlextinfo* extinfo) {
+  soinfo* si = find_library_internal(name, dlflags, extinfo);
   if (si != NULL) {
     si->ref_count++;
   }
   return si;
 }
 
-static int soinfo_unload(soinfo* si) {
+static void soinfo_unload(soinfo* si) {
   if (si->ref_count == 1) {
     TRACE("unloading '%s'", si->name);
     si->CallDestructors();
 
-    for (Elf_Dyn* d = si->dynamic; d->d_tag != DT_NULL; ++d) {
-      if (d->d_tag == DT_NEEDED) {
-        const char* library_name = si->strtab + d->d_un.d_val;
-        TRACE("%s needs to unload %s", si->name, library_name);
-        soinfo_unload(find_loaded_library(library_name));
+    if ((si->flags | FLAG_NEW_SOINFO) != 0) {
+      si->get_children().for_each([&] (soinfo* child) {
+        TRACE("%s needs to unload %s", si->name, child->name);
+        soinfo_unload(child);
+      });
+    } else {
+      for (ElfW(Dyn)* d = si->dynamic; d->d_tag != DT_NULL; ++d) {
+        if (d->d_tag == DT_NEEDED) {
+          const char* library_name = si->strtab + d->d_un.d_val;
+          TRACE("%s needs to unload %s", si->name, library_name);
+          soinfo* needed = find_library(library_name, RTLD_NOLOAD, NULL);
+          if (needed != NULL) {
+            soinfo_unload(needed);
+          } else {
+            // Not found: for example if symlink was deleted between dlopen and dlclose
+            // Since we cannot really handle errors at this point - print and continue.
+            PRINT("warning: couldn't find %s needed by %s on unload.", library_name, si->name);
+          }
+        }
       }
     }
 
-    munmap(reinterpret_cast<void*>(si->base), si->size);
     notify_gdb_of_unload(si);
-    soinfo_free(si);
     si->ref_count = 0;
+    soinfo_free(si);
   } else {
     si->ref_count--;
     TRACE("not unloading '%s', decrementing ref_count to %zd", si->name, si->ref_count);
   }
-  return 0;
 }
 
 void do_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
-  snprintf(buffer, buffer_size, "%s:%s", gDefaultLdPaths[0], gDefaultLdPaths[1]);
+  // Use basic string manipulation calls to avoid snprintf.
+  // snprintf indirectly calls pthread_getspecific to get the size of a buffer.
+  // When debug malloc is enabled, this call returns 0. This in turn causes
+  // snprintf to do nothing, which causes libraries to fail to load.
+  // See b/17302493 for further details.
+  // Once the above bug is fixed, this code can be modified to use
+  // snprintf again.
+  size_t required_len = strlen(kDefaultLdPaths[0]) + strlen(kDefaultLdPaths[1]) + 2;
+  if (buffer_size < required_len) {
+    __libc_fatal("android_get_LD_LIBRARY_PATH failed, buffer too small: buffer len %zu, required len %zu",
+                 buffer_size, required_len);
+  }
+  char* end = stpcpy(buffer, kDefaultLdPaths[0]);
+  *end = ':';
+  strcpy(end + 1, kDefaultLdPaths[1]);
 }
 
 void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
@@ -837,52 +907,52 @@
   }
 }
 
-soinfo* do_dlopen(const char* name, int flags) {
-  if ((flags & ~(RTLD_NOW|RTLD_LAZY|RTLD_LOCAL|RTLD_GLOBAL)) != 0) {
+soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo) {
+  if ((flags & ~(RTLD_NOW|RTLD_LAZY|RTLD_LOCAL|RTLD_GLOBAL|RTLD_NOLOAD)) != 0) {
     DL_ERR("invalid flags to dlopen: %x", flags);
     return NULL;
   }
-  set_soinfo_pool_protection(PROT_READ | PROT_WRITE);
-  soinfo* si = find_library(name);
+  if (extinfo != NULL && ((extinfo->flags & ~(ANDROID_DLEXT_VALID_FLAG_BITS)) != 0)) {
+    DL_ERR("invalid extended flags to android_dlopen_ext: %" PRIx64, extinfo->flags);
+    return NULL;
+  }
+  protect_data(PROT_READ | PROT_WRITE);
+  soinfo* si = find_library(name, flags, extinfo);
   if (si != NULL) {
     si->CallConstructors();
   }
-  set_soinfo_pool_protection(PROT_READ);
+  protect_data(PROT_READ);
   return si;
 }
 
-int do_dlclose(soinfo* si) {
-  set_soinfo_pool_protection(PROT_READ | PROT_WRITE);
-  int result = soinfo_unload(si);
-  set_soinfo_pool_protection(PROT_READ);
-  return result;
+void do_dlclose(soinfo* si) {
+  protect_data(PROT_READ | PROT_WRITE);
+  soinfo_unload(si);
+  protect_data(PROT_READ);
 }
 
 #if defined(USE_RELA)
-static int soinfo_relocate_a(soinfo* si, Elf_Rela* rela, unsigned count, soinfo* needed[]) {
-  Elf_Sym* symtab = si->symtab;
-  const char* strtab = si->strtab;
-  Elf_Sym* s;
-  Elf_Rela* start = rela;
+static int soinfo_relocate(soinfo* si, ElfW(Rela)* rela, unsigned count, soinfo* needed[]) {
+  ElfW(Sym)* s;
   soinfo* lsi;
 
   for (size_t idx = 0; idx < count; ++idx, ++rela) {
-    unsigned type = ELF_R_TYPE(rela->r_info);
-    unsigned sym = ELF_R_SYM(rela->r_info);
-    Elf_Addr reloc = static_cast<Elf_Addr>(rela->r_offset + si->load_bias);
-    Elf_Addr sym_addr = 0;
-    char* sym_name = NULL;
+    unsigned type = ELFW(R_TYPE)(rela->r_info);
+    unsigned sym = ELFW(R_SYM)(rela->r_info);
+    ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rela->r_offset + si->load_bias);
+    ElfW(Addr) sym_addr = 0;
+    const char* sym_name = NULL;
 
     DEBUG("Processing '%s' relocation at index %zd", si->name, idx);
     if (type == 0) { // R_*_NONE
       continue;
     }
     if (sym != 0) {
-      sym_name = (char *)(strtab + symtab[sym].st_name);
+      sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
       s = soinfo_do_lookup(si, sym_name, &lsi, needed);
       if (s == NULL) {
         // We only allow an undefined symbol if this is a weak reference...
-        s = &symtab[sym];
+        s = &si->symtab[sym];
         if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
           DL_ERR("cannot locate symbol \"%s\" referenced by \"%s\"...", sym_name, si->name);
           return -1;
@@ -918,6 +988,7 @@
         case R_X86_64_JUMP_SLOT:
         case R_X86_64_GLOB_DAT:
         case R_X86_64_32:
+        case R_X86_64_64:
         case R_X86_64_RELATIVE:
           // No need to do anything.
           break;
@@ -926,12 +997,12 @@
           break;
 #endif
         default:
-          DL_ERR("unknown weak reloc type %d @ %p (%d)", type, rela, (int) (rela - start));
+          DL_ERR("unknown weak reloc type %d @ %p (%zu)", type, rela, idx);
           return -1;
         }
       } else {
         // We got a definition.
-        sym_addr = static_cast<Elf_Addr>(s->st_value + lsi->load_bias);
+        sym_addr = static_cast<ElfW(Addr)>(s->st_value + lsi->load_bias);
       }
       count_relocation(kRelocSymbol);
     } else {
@@ -943,117 +1014,92 @@
     case R_AARCH64_JUMP_SLOT:
         count_relocation(kRelocAbsolute);
         MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO JMP_SLOT %16lx <- %16lx %s\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    sym_name);
-        *reinterpret_cast<Elf_Addr*>(reloc) = (sym_addr + rela->r_addend);
+        TRACE_TYPE(RELO, "RELO JMP_SLOT %16llx <- %16llx %s\n",
+                   reloc, (sym_addr + rela->r_addend), sym_name);
+        *reinterpret_cast<ElfW(Addr)*>(reloc) = (sym_addr + rela->r_addend);
         break;
     case R_AARCH64_GLOB_DAT:
         count_relocation(kRelocAbsolute);
         MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO GLOB_DAT %16lx <- %16lx %s\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    sym_name);
-        *reinterpret_cast<Elf_Addr*>(reloc) = (sym_addr + rela->r_addend);
+        TRACE_TYPE(RELO, "RELO GLOB_DAT %16llx <- %16llx %s\n",
+                   reloc, (sym_addr + rela->r_addend), sym_name);
+        *reinterpret_cast<ElfW(Addr)*>(reloc) = (sym_addr + rela->r_addend);
         break;
     case R_AARCH64_ABS64:
         count_relocation(kRelocAbsolute);
         MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO ABS64 %16lx <- %16lx %s\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    sym_name);
-        *reinterpret_cast<Elf_Addr*>(reloc) += (sym_addr + rela->r_addend);
+        TRACE_TYPE(RELO, "RELO ABS64 %16llx <- %16llx %s\n",
+                   reloc, (sym_addr + rela->r_addend), sym_name);
+        *reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr + rela->r_addend);
         break;
     case R_AARCH64_ABS32:
         count_relocation(kRelocAbsolute);
         MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO ABS32 %16lx <- %16lx %s\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    sym_name);
-        if ((static_cast<Elf_Addr>(INT32_MIN) <=
-          (*reinterpret_cast<Elf_Addr*>(reloc) + (sym_addr + rela->r_addend))) &&
-          ((*reinterpret_cast<Elf_Addr*>(reloc) + (sym_addr + rela->r_addend)) <=
-          static_cast<Elf_Addr>(UINT32_MAX))) {
-            *reinterpret_cast<Elf_Addr*>(reloc) += (sym_addr + rela->r_addend);
+        TRACE_TYPE(RELO, "RELO ABS32 %16llx <- %16llx %s\n",
+                   reloc, (sym_addr + rela->r_addend), sym_name);
+        if ((static_cast<ElfW(Addr)>(INT32_MIN) <= (*reinterpret_cast<ElfW(Addr)*>(reloc) + (sym_addr + rela->r_addend))) &&
+            ((*reinterpret_cast<ElfW(Addr)*>(reloc) + (sym_addr + rela->r_addend)) <= static_cast<ElfW(Addr)>(UINT32_MAX))) {
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr + rela->r_addend);
         } else {
-            DL_ERR("0x%016lx out of range 0x%016lx to 0x%016lx",
-                    (*reinterpret_cast<Elf_Addr*>(reloc) + (sym_addr + rela->r_addend)),
-                    static_cast<Elf_Addr>(INT32_MIN),
-                    static_cast<Elf_Addr>(UINT32_MAX));
+            DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
+                   (*reinterpret_cast<ElfW(Addr)*>(reloc) + (sym_addr + rela->r_addend)),
+                   static_cast<ElfW(Addr)>(INT32_MIN),
+                   static_cast<ElfW(Addr)>(UINT32_MAX));
             return -1;
         }
         break;
     case R_AARCH64_ABS16:
         count_relocation(kRelocAbsolute);
         MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO ABS16 %16lx <- %16lx %s\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    sym_name);
-        if ((static_cast<Elf_Addr>(INT16_MIN) <=
-          (*reinterpret_cast<Elf_Addr*>(reloc) + (sym_addr + rela->r_addend))) &&
-          ((*reinterpret_cast<Elf_Addr*>(reloc) + (sym_addr + rela->r_addend)) <=
-          static_cast<Elf_Addr>(UINT16_MAX))) {
-            *reinterpret_cast<Elf_Addr*>(reloc) += (sym_addr + rela->r_addend);
+        TRACE_TYPE(RELO, "RELO ABS16 %16llx <- %16llx %s\n",
+                   reloc, (sym_addr + rela->r_addend), sym_name);
+        if ((static_cast<ElfW(Addr)>(INT16_MIN) <= (*reinterpret_cast<ElfW(Addr)*>(reloc) + (sym_addr + rela->r_addend))) &&
+            ((*reinterpret_cast<ElfW(Addr)*>(reloc) + (sym_addr + rela->r_addend)) <= static_cast<ElfW(Addr)>(UINT16_MAX))) {
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr + rela->r_addend);
         } else {
-            DL_ERR("0x%016lx out of range 0x%016lx to 0x%016lx",
-                    (*reinterpret_cast<Elf_Addr*>(reloc) + (sym_addr + rela->r_addend)),
-                    static_cast<Elf_Addr>(INT16_MIN),
-                    static_cast<Elf_Addr>(UINT16_MAX));
+            DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
+                   (*reinterpret_cast<ElfW(Addr)*>(reloc) + (sym_addr + rela->r_addend)),
+                   static_cast<ElfW(Addr)>(INT16_MIN),
+                   static_cast<ElfW(Addr)>(UINT16_MAX));
             return -1;
         }
         break;
     case R_AARCH64_PREL64:
         count_relocation(kRelocRelative);
         MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO REL64 %16lx <- %16lx - %16lx %s\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    rela->r_offset,
-                    sym_name);
-        *reinterpret_cast<Elf_Addr*>(reloc) += (sym_addr + rela->r_addend) - rela->r_offset;
+        TRACE_TYPE(RELO, "RELO REL64 %16llx <- %16llx - %16llx %s\n",
+                   reloc, (sym_addr + rela->r_addend), rela->r_offset, sym_name);
+        *reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr + rela->r_addend) - rela->r_offset;
         break;
     case R_AARCH64_PREL32:
         count_relocation(kRelocRelative);
         MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO REL32 %16lx <- %16lx - %16lx %s\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    rela->r_offset, sym_name);
-        if ((static_cast<Elf_Addr>(INT32_MIN) <=
-          (*reinterpret_cast<Elf_Addr*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset))) &&
-          ((*reinterpret_cast<Elf_Addr*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset)) <=
-          static_cast<Elf_Addr>(UINT32_MAX))) {
-            *reinterpret_cast<Elf_Addr*>(reloc) += ((sym_addr + rela->r_addend) - rela->r_offset);
+        TRACE_TYPE(RELO, "RELO REL32 %16llx <- %16llx - %16llx %s\n",
+                   reloc, (sym_addr + rela->r_addend), rela->r_offset, sym_name);
+        if ((static_cast<ElfW(Addr)>(INT32_MIN) <= (*reinterpret_cast<ElfW(Addr)*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset))) &&
+            ((*reinterpret_cast<ElfW(Addr)*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset)) <= static_cast<ElfW(Addr)>(UINT32_MAX))) {
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += ((sym_addr + rela->r_addend) - rela->r_offset);
         } else {
-            DL_ERR("0x%016lx out of range 0x%016lx to 0x%016lx",
-                    (*reinterpret_cast<Elf_Addr*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset)),
-                    static_cast<Elf_Addr>(INT32_MIN),
-                    static_cast<Elf_Addr>(UINT32_MAX));
+            DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
+                   (*reinterpret_cast<ElfW(Addr)*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset)),
+                   static_cast<ElfW(Addr)>(INT32_MIN),
+                   static_cast<ElfW(Addr)>(UINT32_MAX));
             return -1;
         }
         break;
     case R_AARCH64_PREL16:
         count_relocation(kRelocRelative);
         MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO REL16 %16lx <- %16lx - %16lx %s\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    rela->r_offset, sym_name);
-        if ((static_cast<Elf_Addr>(INT16_MIN) <=
-          (*reinterpret_cast<Elf_Addr*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset))) &&
-          ((*reinterpret_cast<Elf_Addr*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset)) <=
-          static_cast<Elf_Addr>(UINT16_MAX))) {
-            *reinterpret_cast<Elf_Addr*>(reloc) += ((sym_addr + rela->r_addend) - rela->r_offset);
+        TRACE_TYPE(RELO, "RELO REL16 %16llx <- %16llx - %16llx %s\n",
+                   reloc, (sym_addr + rela->r_addend), rela->r_offset, sym_name);
+        if ((static_cast<ElfW(Addr)>(INT16_MIN) <= (*reinterpret_cast<ElfW(Addr)*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset))) &&
+            ((*reinterpret_cast<ElfW(Addr)*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset)) <= static_cast<ElfW(Addr)>(UINT16_MAX))) {
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += ((sym_addr + rela->r_addend) - rela->r_offset);
         } else {
-            DL_ERR("0x%016lx out of range 0x%016lx to 0x%016lx",
-                    (*reinterpret_cast<Elf_Addr*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset)),
-                    static_cast<Elf_Addr>(INT16_MIN),
-                    static_cast<Elf_Addr>(UINT16_MAX));
+            DL_ERR("0x%016llx out of range 0x%016llx to 0x%016llx",
+                   (*reinterpret_cast<ElfW(Addr)*>(reloc) + ((sym_addr + rela->r_addend) - rela->r_offset)),
+                   static_cast<ElfW(Addr)>(INT16_MIN),
+                   static_cast<ElfW(Addr)>(UINT16_MAX));
             return -1;
         }
         break;
@@ -1065,69 +1111,30 @@
             DL_ERR("odd RELATIVE form...");
             return -1;
         }
-        TRACE_TYPE(RELO, "RELO RELATIVE %16lx <- %16lx\n",
-                    reloc,
-                    (si->base + rela->r_addend));
-        *reinterpret_cast<Elf_Addr*>(reloc) = (si->base + rela->r_addend);
+        TRACE_TYPE(RELO, "RELO RELATIVE %16llx <- %16llx\n",
+                   reloc, (si->base + rela->r_addend));
+        *reinterpret_cast<ElfW(Addr)*>(reloc) = (si->base + rela->r_addend);
         break;
 
     case R_AARCH64_COPY:
-        if ((si->flags & FLAG_EXE) == 0) {
-            /*
-              * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
-              *
-              * Section 4.7.1.10 "Dynamic relocations"
-              * R_AARCH64_COPY may only appear in executable objects where e_type is
-              * set to ET_EXEC.
-              *
-              * FLAG_EXE is set for both ET_DYN and ET_EXEC executables.
-              * We should explicitly disallow ET_DYN executables from having
-              * R_AARCH64_COPY relocations.
-              */
-            DL_ERR("%s R_AARCH64_COPY relocations only supported for ET_EXEC", si->name);
-            return -1;
-        }
-        count_relocation(kRelocCopy);
-        MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO COPY %16lx <- %ld @ %16lx %s\n",
-                    reloc,
-                    s->st_size,
-                    (sym_addr + rela->r_addend),
-                    sym_name);
-        if (reloc == (sym_addr + rela->r_addend)) {
-            Elf_Sym *src = soinfo_do_lookup(NULL, sym_name, &lsi, needed);
-
-            if (src == NULL) {
-                DL_ERR("%s R_AARCH64_COPY relocation source cannot be resolved", si->name);
-                return -1;
-            }
-            if (lsi->has_DT_SYMBOLIC) {
-                DL_ERR("%s invalid R_AARCH64_COPY relocation against DT_SYMBOLIC shared "
-                        "library %s (built with -Bsymbolic?)", si->name, lsi->name);
-                return -1;
-            }
-            if (s->st_size < src->st_size) {
-                DL_ERR("%s R_AARCH64_COPY relocation size mismatch (%ld < %ld)",
-                        si->name, s->st_size, src->st_size);
-                return -1;
-            }
-            memcpy((void*)reloc, (void*)(src->st_value + lsi->load_bias), src->st_size);
-        } else {
-            DL_ERR("%s R_AARCH64_COPY relocation target cannot be resolved", si->name);
-            return -1;
-        }
-        break;
+        /*
+         * ET_EXEC is not supported so this should not happen.
+         *
+         * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
+         *
+         * Section 4.7.1.10 "Dynamic relocations"
+         * R_AARCH64_COPY may only appear in executable objects where e_type is
+         * set to ET_EXEC.
+         */
+        DL_ERR("%s R_AARCH64_COPY relocations are not supported", si->name);
+        return -1;
     case R_AARCH64_TLS_TPREL64:
-        TRACE_TYPE(RELO, "RELO TLS_TPREL64 *** %16lx <- %16lx - %16lx\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    rela->r_offset);
+        TRACE_TYPE(RELO, "RELO TLS_TPREL64 *** %16llx <- %16llx - %16llx\n",
+                   reloc, (sym_addr + rela->r_addend), rela->r_offset);
         break;
     case R_AARCH64_TLS_DTPREL32:
-        TRACE_TYPE(RELO, "RELO TLS_DTPREL32 *** %16lx <- %16lx - %16lx\n",
-                    reloc,
-                    (sym_addr + rela->r_addend),
-                    rela->r_offset);
+        TRACE_TYPE(RELO, "RELO TLS_DTPREL32 *** %16llx <- %16llx - %16llx\n",
+                   reloc, (sym_addr + rela->r_addend), rela->r_offset);
         break;
 #elif defined(__x86_64__)
     case R_X86_64_JUMP_SLOT:
@@ -1135,14 +1142,14 @@
       MARK(rela->r_offset);
       TRACE_TYPE(RELO, "RELO JMP_SLOT %08zx <- %08zx %s", static_cast<size_t>(reloc),
                  static_cast<size_t>(sym_addr + rela->r_addend), sym_name);
-      *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr + rela->r_addend;
+      *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + rela->r_addend;
       break;
     case R_X86_64_GLOB_DAT:
       count_relocation(kRelocAbsolute);
       MARK(rela->r_offset);
       TRACE_TYPE(RELO, "RELO GLOB_DAT %08zx <- %08zx %s", static_cast<size_t>(reloc),
                  static_cast<size_t>(sym_addr + rela->r_addend), sym_name);
-      *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr + rela->r_addend;
+      *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + rela->r_addend;
       break;
     case R_X86_64_RELATIVE:
       count_relocation(kRelocRelative);
@@ -1153,21 +1160,21 @@
       }
       TRACE_TYPE(RELO, "RELO RELATIVE %08zx <- +%08zx", static_cast<size_t>(reloc),
                  static_cast<size_t>(si->base));
-      *reinterpret_cast<Elf_Addr*>(reloc) = si->base + rela->r_addend;
+      *reinterpret_cast<ElfW(Addr)*>(reloc) = si->base + rela->r_addend;
       break;
     case R_X86_64_32:
       count_relocation(kRelocRelative);
       MARK(rela->r_offset);
       TRACE_TYPE(RELO, "RELO R_X86_64_32 %08zx <- +%08zx %s", static_cast<size_t>(reloc),
                  static_cast<size_t>(sym_addr), sym_name);
-      *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr + rela->r_addend;
+      *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + rela->r_addend;
       break;
     case R_X86_64_64:
       count_relocation(kRelocRelative);
       MARK(rela->r_offset);
       TRACE_TYPE(RELO, "RELO R_X86_64_64 %08zx <- +%08zx %s", static_cast<size_t>(reloc),
                  static_cast<size_t>(sym_addr), sym_name);
-      *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr + rela->r_addend;
+      *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + rela->r_addend;
       break;
     case R_X86_64_PC32:
       count_relocation(kRelocRelative);
@@ -1175,45 +1182,42 @@
       TRACE_TYPE(RELO, "RELO R_X86_64_PC32 %08zx <- +%08zx (%08zx - %08zx) %s",
                  static_cast<size_t>(reloc), static_cast<size_t>(sym_addr - reloc),
                  static_cast<size_t>(sym_addr), static_cast<size_t>(reloc), sym_name);
-      *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr + rela->r_addend - reloc;
+      *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr + rela->r_addend - reloc;
       break;
 #endif
 
     default:
-      DL_ERR("unknown reloc type %d @ %p (%d)", type, rela, (int) (rela - start));
+      DL_ERR("unknown reloc type %d @ %p (%zu)", type, rela, idx);
       return -1;
     }
   }
   return 0;
 }
-#else
-static int soinfo_relocate(soinfo* si, Elf_Rel* rel, unsigned count,
-                           soinfo* needed[])
-{
-    Elf_Sym* symtab = si->symtab;
-    const char* strtab = si->strtab;
-    Elf_Sym* s;
-    Elf_Rel* start = rel;
+
+#else // REL, not RELA.
+
+static int soinfo_relocate(soinfo* si, ElfW(Rel)* rel, unsigned count, soinfo* needed[]) {
+    ElfW(Sym)* s;
     soinfo* lsi;
 
     for (size_t idx = 0; idx < count; ++idx, ++rel) {
-        unsigned type = ELF_R_TYPE(rel->r_info);
-        // TODO: don't use unsigned for 'sym'. Use uint32_t or Elf_Addr instead.
-        unsigned sym = ELF_R_SYM(rel->r_info);
-        Elf_Addr reloc = static_cast<Elf_Addr>(rel->r_offset + si->load_bias);
-        Elf_Addr sym_addr = 0;
-        char* sym_name = NULL;
+        unsigned type = ELFW(R_TYPE)(rel->r_info);
+        // TODO: don't use unsigned for 'sym'. Use uint32_t or ElfW(Addr) instead.
+        unsigned sym = ELFW(R_SYM)(rel->r_info);
+        ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rel->r_offset + si->load_bias);
+        ElfW(Addr) sym_addr = 0;
+        const char* sym_name = NULL;
 
         DEBUG("Processing '%s' relocation at index %zd", si->name, idx);
         if (type == 0) { // R_*_NONE
             continue;
         }
         if (sym != 0) {
-            sym_name = (char *)(strtab + symtab[sym].st_name);
+            sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
             s = soinfo_do_lookup(si, sym_name, &lsi, needed);
             if (s == NULL) {
                 // We only allow an undefined symbol if this is a weak reference...
-                s = &symtab[sym];
+                s = &si->symtab[sym];
                 if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
                     DL_ERR("cannot locate symbol \"%s\" referenced by \"%s\"...", sym_name, si->name);
                     return -1;
@@ -1261,12 +1265,12 @@
                     // Fall through. Can't really copy if weak symbol is not found at run-time.
 #endif
                 default:
-                    DL_ERR("unknown weak reloc type %d @ %p (%d)", type, rel, (int) (rel - start));
+                    DL_ERR("unknown weak reloc type %d @ %p (%zu)", type, rel, idx);
                     return -1;
                 }
             } else {
                 // We got a definition.
-                sym_addr = static_cast<Elf_Addr>(s->st_value + lsi->load_bias);
+                sym_addr = static_cast<ElfW(Addr)>(s->st_value + lsi->load_bias);
             }
             count_relocation(kRelocSymbol);
         } else {
@@ -1279,105 +1283,86 @@
             count_relocation(kRelocAbsolute);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "RELO JMP_SLOT %08x <- %08x %s", reloc, sym_addr, sym_name);
-            *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr;
+            *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr;
             break;
         case R_ARM_GLOB_DAT:
             count_relocation(kRelocAbsolute);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "RELO GLOB_DAT %08x <- %08x %s", reloc, sym_addr, sym_name);
-            *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr;
+            *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr;
             break;
         case R_ARM_ABS32:
             count_relocation(kRelocAbsolute);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "RELO ABS %08x <- %08x %s", reloc, sym_addr, sym_name);
-            *reinterpret_cast<Elf_Addr*>(reloc) += sym_addr;
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += sym_addr;
             break;
         case R_ARM_REL32:
             count_relocation(kRelocRelative);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "RELO REL32 %08x <- %08x - %08x %s",
                        reloc, sym_addr, rel->r_offset, sym_name);
-            *reinterpret_cast<Elf_Addr*>(reloc) += sym_addr - rel->r_offset;
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += sym_addr - rel->r_offset;
             break;
         case R_ARM_COPY:
-            if ((si->flags & FLAG_EXE) == 0) {
-                /*
-                 * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
-                 *
-                 * Section 4.7.1.10 "Dynamic relocations"
-                 * R_ARM_COPY may only appear in executable objects where e_type is
-                 * set to ET_EXEC.
-                 *
-                 * TODO: FLAG_EXE is set for both ET_DYN and ET_EXEC executables.
-                 * We should explicitly disallow ET_DYN executables from having
-                 * R_ARM_COPY relocations.
-                 */
-                DL_ERR("%s R_ARM_COPY relocations only supported for ET_EXEC", si->name);
-                return -1;
-            }
-            count_relocation(kRelocCopy);
-            MARK(rel->r_offset);
-            TRACE_TYPE(RELO, "RELO %08x <- %d @ %08x %s", reloc, s->st_size, sym_addr, sym_name);
-            if (reloc == sym_addr) {
-                Elf_Sym *src = soinfo_do_lookup(NULL, sym_name, &lsi, needed);
-
-                if (src == NULL) {
-                    DL_ERR("%s R_ARM_COPY relocation source cannot be resolved", si->name);
-                    return -1;
-                }
-                if (lsi->has_DT_SYMBOLIC) {
-                    DL_ERR("%s invalid R_ARM_COPY relocation against DT_SYMBOLIC shared "
-                           "library %s (built with -Bsymbolic?)", si->name, lsi->name);
-                    return -1;
-                }
-                if (s->st_size < src->st_size) {
-                    DL_ERR("%s R_ARM_COPY relocation size mismatch (%d < %d)",
-                           si->name, s->st_size, src->st_size);
-                    return -1;
-                }
-                memcpy((void*)reloc, (void*)(src->st_value + lsi->load_bias), src->st_size);
-            } else {
-                DL_ERR("%s R_ARM_COPY relocation target cannot be resolved", si->name);
-                return -1;
-            }
-            break;
+            /*
+             * ET_EXEC is not supported so this should not happen.
+             *
+             * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
+             *
+             * Section 4.7.1.10 "Dynamic relocations"
+             * R_ARM_COPY may only appear in executable objects where e_type is
+             * set to ET_EXEC.
+             */
+            DL_ERR("%s R_ARM_COPY relocations are not supported", si->name);
+            return -1;
 #elif defined(__i386__)
         case R_386_JMP_SLOT:
             count_relocation(kRelocAbsolute);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "RELO JMP_SLOT %08x <- %08x %s", reloc, sym_addr, sym_name);
-            *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr;
+            *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr;
             break;
         case R_386_GLOB_DAT:
             count_relocation(kRelocAbsolute);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "RELO GLOB_DAT %08x <- %08x %s", reloc, sym_addr, sym_name);
-            *reinterpret_cast<Elf_Addr*>(reloc) = sym_addr;
+            *reinterpret_cast<ElfW(Addr)*>(reloc) = sym_addr;
             break;
         case R_386_32:
             count_relocation(kRelocRelative);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "RELO R_386_32 %08x <- +%08x %s", reloc, sym_addr, sym_name);
-            *reinterpret_cast<Elf_Addr*>(reloc) += sym_addr;
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += sym_addr;
             break;
         case R_386_PC32:
             count_relocation(kRelocRelative);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "RELO R_386_PC32 %08x <- +%08x (%08x - %08x) %s",
                        reloc, (sym_addr - reloc), sym_addr, reloc, sym_name);
-            *reinterpret_cast<Elf_Addr*>(reloc) += (sym_addr - reloc);
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += (sym_addr - reloc);
             break;
 #elif defined(__mips__)
         case R_MIPS_REL32:
+#if defined(__LP64__)
+            // MIPS Elf64_Rel entries contain compound relocations
+            // We only handle the R_MIPS_NONE|R_MIPS_64|R_MIPS_REL32 case
+            if (ELF64_R_TYPE2(rel->r_info) != R_MIPS_64 ||
+                ELF64_R_TYPE3(rel->r_info) != R_MIPS_NONE) {
+                DL_ERR("Unexpected compound relocation type:%d type2:%d type3:%d @ %p (%zu)",
+                       type, (unsigned)ELF64_R_TYPE2(rel->r_info),
+                       (unsigned)ELF64_R_TYPE3(rel->r_info), rel, idx);
+                return -1;
+            }
+#endif
             count_relocation(kRelocAbsolute);
             MARK(rel->r_offset);
-            TRACE_TYPE(RELO, "RELO REL32 %08x <- %08x %s",
-                       reloc, sym_addr, (sym_name) ? sym_name : "*SECTIONHDR*");
+            TRACE_TYPE(RELO, "RELO REL32 %08zx <- %08zx %s", static_cast<size_t>(reloc),
+                       static_cast<size_t>(sym_addr), sym_name ? sym_name : "*SECTIONHDR*");
             if (s) {
-                *reinterpret_cast<Elf_Addr*>(reloc) += sym_addr;
+                *reinterpret_cast<ElfW(Addr)*>(reloc) += sym_addr;
             } else {
-                *reinterpret_cast<Elf_Addr*>(reloc) += si->base;
+                *reinterpret_cast<ElfW(Addr)*>(reloc) += si->base;
             }
             break;
 #endif
@@ -1395,11 +1380,11 @@
             }
             TRACE_TYPE(RELO, "RELO RELATIVE %p <- +%p",
                        reinterpret_cast<void*>(reloc), reinterpret_cast<void*>(si->base));
-            *reinterpret_cast<Elf_Addr*>(reloc) += si->base;
+            *reinterpret_cast<ElfW(Addr)*>(reloc) += si->base;
             break;
 
         default:
-            DL_ERR("unknown reloc type %d @ %p (%d)", type, rel, (int) (rel - start));
+            DL_ERR("unknown reloc type %d @ %p (%zu)", type, rel, idx);
             return -1;
         }
     }
@@ -1409,71 +1394,59 @@
 
 #if defined(__mips__)
 static bool mips_relocate_got(soinfo* si, soinfo* needed[]) {
-    unsigned* got = si->plt_got;
+    ElfW(Addr)** got = si->plt_got;
     if (got == NULL) {
         return true;
     }
     unsigned local_gotno = si->mips_local_gotno;
     unsigned gotsym = si->mips_gotsym;
     unsigned symtabno = si->mips_symtabno;
-    Elf_Sym* symtab = si->symtab;
+    ElfW(Sym)* symtab = si->symtab;
 
-    /*
-     * got[0] is address of lazy resolver function
-     * got[1] may be used for a GNU extension
-     * set it to a recognizable address in case someone calls it
-     * (should be _rtld_bind_start)
-     * FIXME: maybe this should be in a separate routine
-     */
-
+    // got[0] is the address of the lazy resolver function.
+    // got[1] may be used for a GNU extension.
+    // Set it to a recognizable address in case someone calls it (should be _rtld_bind_start).
+    // FIXME: maybe this should be in a separate routine?
     if ((si->flags & FLAG_LINKER) == 0) {
         size_t g = 0;
-        got[g++] = 0xdeadbeef;
-        if (got[g] & 0x80000000) {
-            got[g++] = 0xdeadfeed;
+        got[g++] = reinterpret_cast<ElfW(Addr)*>(0xdeadbeef);
+        if (reinterpret_cast<intptr_t>(got[g]) < 0) {
+            got[g++] = reinterpret_cast<ElfW(Addr)*>(0xdeadfeed);
         }
-        /*
-         * Relocate the local GOT entries need to be relocated
-         */
+        // Relocate the local GOT entries.
         for (; g < local_gotno; g++) {
-            got[g] += si->load_bias;
+            got[g] = reinterpret_cast<ElfW(Addr)*>(reinterpret_cast<uintptr_t>(got[g]) + si->load_bias);
         }
     }
 
-    /* Now for the global GOT entries */
-    Elf_Sym* sym = symtab + gotsym;
+    // Now for the global GOT entries...
+    ElfW(Sym)* sym = symtab + gotsym;
     got = si->plt_got + local_gotno;
     for (size_t g = gotsym; g < symtabno; g++, sym++, got++) {
-        const char* sym_name;
-        Elf_Sym* s;
+        // This is an undefined reference... try to locate it.
+        const char* sym_name = si->strtab + sym->st_name;
         soinfo* lsi;
-
-        /* This is an undefined reference... try to locate it */
-        sym_name = si->strtab + sym->st_name;
-        s = soinfo_do_lookup(si, sym_name, &lsi, needed);
+        ElfW(Sym)* s = soinfo_do_lookup(si, sym_name, &lsi, needed);
         if (s == NULL) {
-            /* We only allow an undefined symbol if this is a weak
-               reference..   */
+            // We only allow an undefined symbol if this is a weak reference.
             s = &symtab[g];
             if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
                 DL_ERR("cannot locate \"%s\"...", sym_name);
                 return false;
             }
             *got = 0;
-        }
-        else {
-            /* FIXME: is this sufficient?
-             * For reference see NetBSD link loader
-             * http://cvsweb.netbsd.org/bsdweb.cgi/src/libexec/ld.elf_so/arch/mips/mips_reloc.c?rev=1.53&content-type=text/x-cvsweb-markup
-             */
-             *got = lsi->load_bias + s->st_value;
+        } else {
+            // FIXME: is this sufficient?
+            // For reference see NetBSD link loader
+            // http://cvsweb.netbsd.org/bsdweb.cgi/src/libexec/ld.elf_so/arch/mips/mips_reloc.c?rev=1.53&content-type=text/x-cvsweb-markup
+            *got = reinterpret_cast<ElfW(Addr)*>(lsi->load_bias + s->st_value);
         }
     }
     return true;
 }
 #endif
 
-void soinfo::CallArray(const char* array_name UNUSED, linker_function_t* functions, size_t count, bool reverse) {
+void soinfo::CallArray(const char* array_name __unused, linker_function_t* functions, size_t count, bool reverse) {
   if (functions == NULL) {
     return;
   }
@@ -1492,7 +1465,7 @@
   TRACE("[ Done calling %s for '%s' ]", array_name, name);
 }
 
-void soinfo::CallFunction(const char* function_name UNUSED, linker_function_t function) {
+void soinfo::CallFunction(const char* function_name __unused, linker_function_t function) {
   if (function == NULL || reinterpret_cast<uintptr_t>(function) == static_cast<uintptr_t>(-1)) {
     return;
   }
@@ -1503,7 +1476,7 @@
 
   // The function may have called dlopen(3) or dlclose(3), so we need to ensure our data structures
   // are still writable. This happens with our debug malloc (see http://b/7941716).
-  set_soinfo_pool_protection(PROT_READ | PROT_WRITE);
+  protect_data(PROT_READ | PROT_WRITE);
 }
 
 void soinfo::CallPreInitConstructors() {
@@ -1535,15 +1508,9 @@
           name, preinit_array_count);
   }
 
-  if (dynamic != NULL) {
-    for (Elf_Dyn* d = dynamic; d->d_tag != DT_NULL; ++d) {
-      if (d->d_tag == DT_NEEDED) {
-        const char* library_name = strtab + d->d_un.d_val;
-        TRACE("\"%s\": calling constructors in DT_NEEDED \"%s\"", name, library_name);
-        find_loaded_library(library_name)->CallConstructors();
-      }
-    }
-  }
+  get_children().for_each([] (soinfo* si) {
+    si->CallConstructors();
+  });
 
   TRACE("\"%s\": calling constructors", name);
 
@@ -1560,6 +1527,86 @@
 
   // DT_FINI should be called after DT_FINI_ARRAY if both are present.
   CallFunction("DT_FINI", fini_func);
+
+  // This is needed on second call to dlopen
+  // after library has been unloaded with RTLD_NODELETE
+  constructors_called = false;
+}
+
+void soinfo::add_child(soinfo* child) {
+  if ((this->flags & FLAG_NEW_SOINFO) == 0) {
+    return;
+  }
+
+  this->children.push_front(child);
+  child->parents.push_front(this);
+}
+
+void soinfo::remove_all_links() {
+  if ((this->flags & FLAG_NEW_SOINFO) == 0) {
+    return;
+  }
+
+  // 1. Untie connected soinfos from 'this'.
+  children.for_each([&] (soinfo* child) {
+    child->parents.remove_if([&] (const soinfo* parent) {
+      return parent == this;
+    });
+  });
+
+  parents.for_each([&] (soinfo* parent) {
+    parent->children.for_each([&] (const soinfo* child) {
+      return child == this;
+    });
+  });
+
+  // 2. Once everything untied - clear local lists.
+  parents.clear();
+  children.clear();
+}
+
+void soinfo::set_st_dev(dev_t dev) {
+  if ((this->flags & FLAG_NEW_SOINFO) == 0) {
+    return;
+  }
+
+  st_dev = dev;
+}
+
+void soinfo::set_st_ino(ino_t ino) {
+  if ((this->flags & FLAG_NEW_SOINFO) == 0) {
+    return;
+  }
+
+  st_ino = ino;
+}
+
+dev_t soinfo::get_st_dev() {
+  if ((this->flags & FLAG_NEW_SOINFO) == 0) {
+    return 0;
+  }
+
+  return st_dev;
+};
+
+ino_t soinfo::get_st_ino() {
+  if ((this->flags & FLAG_NEW_SOINFO) == 0) {
+    return 0;
+  }
+
+  return st_ino;
+}
+
+// This is a return on get_children() in case
+// 'this->flags' does not have FLAG_NEW_SOINFO set.
+static soinfo::soinfo_list_t g_empty_list;
+
+soinfo::soinfo_list_t& soinfo::get_children() {
+  if ((this->flags & FLAG_NEW_SOINFO) == 0) {
+    return g_empty_list;
+  }
+
+  return this->children;
 }
 
 /* Force any of the closed stdin, stdout and stderr to be associated with
@@ -1623,10 +1670,10 @@
     return return_value;
 }
 
-static bool soinfo_link_image(soinfo* si) {
+static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo) {
     /* "base" might wrap around UINT32_MAX. */
-    Elf_Addr base = si->load_bias;
-    const Elf_Phdr *phdr = si->phdr;
+    ElfW(Addr) base = si->load_bias;
+    const ElfW(Phdr)* phdr = si->phdr;
     int phnum = si->phnum;
     bool relocating_linker = (si->flags & FLAG_LINKER) != 0;
 
@@ -1638,7 +1685,7 @@
 
     /* Extract dynamic section */
     size_t dynamic_count;
-    Elf_Word dynamic_flags;
+    ElfW(Word) dynamic_flags;
     phdr_table_get_dynamic_section(phdr, phnum, base, &si->dynamic,
                                    &dynamic_count, &dynamic_flags);
     if (si->dynamic == NULL) {
@@ -1659,21 +1706,21 @@
 
     // Extract useful information from dynamic section.
     uint32_t needed_count = 0;
-    for (Elf_Dyn* d = si->dynamic; d->d_tag != DT_NULL; ++d) {
+    for (ElfW(Dyn)* d = si->dynamic; d->d_tag != DT_NULL; ++d) {
         DEBUG("d = %p, d[0](tag) = %p d[1](val) = %p",
               d, reinterpret_cast<void*>(d->d_tag), reinterpret_cast<void*>(d->d_un.d_val));
         switch (d->d_tag) {
         case DT_HASH:
-            si->nbucket = ((unsigned *) (base + d->d_un.d_ptr))[0];
-            si->nchain = ((unsigned *) (base + d->d_un.d_ptr))[1];
-            si->bucket = (unsigned *) (base + d->d_un.d_ptr + 8);
-            si->chain = (unsigned *) (base + d->d_un.d_ptr + 8 + si->nbucket * 4);
+            si->nbucket = reinterpret_cast<uint32_t*>(base + d->d_un.d_ptr)[0];
+            si->nchain = reinterpret_cast<uint32_t*>(base + d->d_un.d_ptr)[1];
+            si->bucket = reinterpret_cast<uint32_t*>(base + d->d_un.d_ptr + 8);
+            si->chain = reinterpret_cast<uint32_t*>(base + d->d_un.d_ptr + 8 + si->nbucket * 4);
             break;
         case DT_STRTAB:
-            si->strtab = (const char *) (base + d->d_un.d_ptr);
+            si->strtab = reinterpret_cast<const char*>(base + d->d_un.d_ptr);
             break;
         case DT_SYMTAB:
-            si->symtab = (Elf_Sym *) (base + d->d_un.d_ptr);
+            si->symtab = reinterpret_cast<ElfW(Sym)*>(base + d->d_un.d_ptr);
             break;
 #if !defined(__LP64__)
         case DT_PLTREL:
@@ -1685,37 +1732,43 @@
 #endif
         case DT_JMPREL:
 #if defined(USE_RELA)
-            si->plt_rela = (Elf_Rela*) (base + d->d_un.d_ptr);
+            si->plt_rela = reinterpret_cast<ElfW(Rela)*>(base + d->d_un.d_ptr);
 #else
-            si->plt_rel = (Elf_Rel*) (base + d->d_un.d_ptr);
+            si->plt_rel = reinterpret_cast<ElfW(Rel)*>(base + d->d_un.d_ptr);
 #endif
             break;
         case DT_PLTRELSZ:
 #if defined(USE_RELA)
-            si->plt_rela_count = d->d_un.d_val / sizeof(Elf_Rela);
+            si->plt_rela_count = d->d_un.d_val / sizeof(ElfW(Rela));
 #else
-            si->plt_rel_count = d->d_un.d_val / sizeof(Elf_Rel);
+            si->plt_rel_count = d->d_un.d_val / sizeof(ElfW(Rel));
 #endif
             break;
-#if !defined(__LP64__)
+#if defined(__mips__)
         case DT_PLTGOT:
-            // Used by 32-bit MIPS.
-            si->plt_got = (unsigned *)(base + d->d_un.d_ptr);
+            // Used by mips and mips64.
+            si->plt_got = reinterpret_cast<ElfW(Addr)**>(base + d->d_un.d_ptr);
             break;
 #endif
         case DT_DEBUG:
             // Set the DT_DEBUG entry to the address of _r_debug for GDB
             // if the dynamic table is writable
+// FIXME: not working currently for N64
+// The flags for the LOAD and DYNAMIC program headers do not agree.
+// The LOAD section containng the dynamic table has been mapped as
+// read-only, but the DYNAMIC header claims it is writable.
+#if !(defined(__mips__) && defined(__LP64__))
             if ((dynamic_flags & PF_W) != 0) {
                 d->d_un.d_val = reinterpret_cast<uintptr_t>(&_r_debug);
             }
             break;
+#endif
 #if defined(USE_RELA)
          case DT_RELA:
-            si->rela = (Elf_Rela*) (base + d->d_un.d_ptr);
+            si->rela = reinterpret_cast<ElfW(Rela)*>(base + d->d_un.d_ptr);
             break;
          case DT_RELASZ:
-            si->rela_count = d->d_un.d_val / sizeof(Elf_Rela);
+            si->rela_count = d->d_un.d_val / sizeof(ElfW(Rela));
             break;
         case DT_REL:
             DL_ERR("unsupported DT_REL in \"%s\"", si->name);
@@ -1725,10 +1778,10 @@
             return false;
 #else
         case DT_REL:
-            si->rel = (Elf_Rel*) (base + d->d_un.d_ptr);
+            si->rel = reinterpret_cast<ElfW(Rel)*>(base + d->d_un.d_ptr);
             break;
         case DT_RELSZ:
-            si->rel_count = d->d_un.d_val / sizeof(Elf_Rel);
+            si->rel_count = d->d_un.d_val / sizeof(ElfW(Rel));
             break;
          case DT_RELA:
             DL_ERR("unsupported DT_RELA in \"%s\"", si->name);
@@ -1747,21 +1800,21 @@
             DEBUG("%s constructors (DT_INIT_ARRAY) found at %p", si->name, si->init_array);
             break;
         case DT_INIT_ARRAYSZ:
-            si->init_array_count = ((unsigned)d->d_un.d_val) / sizeof(Elf_Addr);
+            si->init_array_count = ((unsigned)d->d_un.d_val) / sizeof(ElfW(Addr));
             break;
         case DT_FINI_ARRAY:
             si->fini_array = reinterpret_cast<linker_function_t*>(base + d->d_un.d_ptr);
             DEBUG("%s destructors (DT_FINI_ARRAY) found at %p", si->name, si->fini_array);
             break;
         case DT_FINI_ARRAYSZ:
-            si->fini_array_count = ((unsigned)d->d_un.d_val) / sizeof(Elf_Addr);
+            si->fini_array_count = ((unsigned)d->d_un.d_val) / sizeof(ElfW(Addr));
             break;
         case DT_PREINIT_ARRAY:
             si->preinit_array = reinterpret_cast<linker_function_t*>(base + d->d_un.d_ptr);
             DEBUG("%s constructors (DT_PREINIT_ARRAY) found at %p", si->name, si->preinit_array);
             break;
         case DT_PREINIT_ARRAYSZ:
-            si->preinit_array_count = ((unsigned)d->d_un.d_val) / sizeof(Elf_Addr);
+            si->preinit_array_count = ((unsigned)d->d_un.d_val) / sizeof(ElfW(Addr));
             break;
         case DT_TEXTREL:
 #if defined(__LP64__)
@@ -1798,7 +1851,7 @@
         case DT_MIPS_RLD_MAP:
             // Set the DT_MIPS_RLD_MAP entry to the address of _r_debug for GDB.
             {
-              r_debug** dp = (r_debug**) d->d_un.d_ptr;
+              r_debug** dp = reinterpret_cast<r_debug**>(base + d->d_un.d_ptr);
               *dp = &_r_debug;
             }
             break;
@@ -1851,34 +1904,36 @@
 
     // If this is the main executable, then load all of the libraries from LD_PRELOAD now.
     if (si->flags & FLAG_EXE) {
-        memset(gLdPreloads, 0, sizeof(gLdPreloads));
+        memset(g_ld_preloads, 0, sizeof(g_ld_preloads));
         size_t preload_count = 0;
-        for (size_t i = 0; gLdPreloadNames[i] != NULL; i++) {
-            soinfo* lsi = find_library(gLdPreloadNames[i]);
+        for (size_t i = 0; g_ld_preload_names[i] != NULL; i++) {
+            soinfo* lsi = find_library(g_ld_preload_names[i], 0, NULL);
             if (lsi != NULL) {
-                gLdPreloads[preload_count++] = lsi;
+                g_ld_preloads[preload_count++] = lsi;
             } else {
                 // As with glibc, failure to load an LD_PRELOAD library is just a warning.
                 DL_WARN("could not load library \"%s\" from LD_PRELOAD for \"%s\"; caused by %s",
-                        gLdPreloadNames[i], si->name, linker_get_error_buffer());
+                        g_ld_preload_names[i], si->name, linker_get_error_buffer());
             }
         }
     }
 
-    soinfo** needed = (soinfo**) alloca((1 + needed_count) * sizeof(soinfo*));
+    soinfo** needed = reinterpret_cast<soinfo**>(alloca((1 + needed_count) * sizeof(soinfo*)));
     soinfo** pneeded = needed;
 
-    for (Elf_Dyn* d = si->dynamic; d->d_tag != DT_NULL; ++d) {
+    for (ElfW(Dyn)* d = si->dynamic; d->d_tag != DT_NULL; ++d) {
         if (d->d_tag == DT_NEEDED) {
             const char* library_name = si->strtab + d->d_un.d_val;
             DEBUG("%s needs %s", si->name, library_name);
-            soinfo* lsi = find_library(library_name);
+            soinfo* lsi = find_library(library_name, 0, NULL);
             if (lsi == NULL) {
                 strlcpy(tmp_err_buf, linker_get_error_buffer(), sizeof(tmp_err_buf));
                 DL_ERR("could not load library \"%s\" needed by \"%s\"; caused by %s",
                        library_name, si->name, tmp_err_buf);
                 return false;
             }
+
+            si->add_child(lsi);
             *pneeded++ = lsi;
         }
     }
@@ -1900,26 +1955,26 @@
 
 #if defined(USE_RELA)
     if (si->plt_rela != NULL) {
-        DEBUG("[ relocating %s plt ]\n", si->name );
-        if (soinfo_relocate_a(si, si->plt_rela, si->plt_rela_count, needed)) {
+        DEBUG("[ relocating %s plt ]\n", si->name);
+        if (soinfo_relocate(si, si->plt_rela, si->plt_rela_count, needed)) {
             return false;
         }
     }
     if (si->rela != NULL) {
-        DEBUG("[ relocating %s ]\n", si->name );
-        if (soinfo_relocate_a(si, si->rela, si->rela_count, needed)) {
+        DEBUG("[ relocating %s ]\n", si->name);
+        if (soinfo_relocate(si, si->rela, si->rela_count, needed)) {
             return false;
         }
     }
 #else
     if (si->plt_rel != NULL) {
-        DEBUG("[ relocating %s plt ]", si->name );
+        DEBUG("[ relocating %s plt ]", si->name);
         if (soinfo_relocate(si, si->plt_rel, si->plt_rel_count, needed)) {
             return false;
         }
     }
     if (si->rel != NULL) {
-        DEBUG("[ relocating %s ]", si->name );
+        DEBUG("[ relocating %s ]", si->name);
         if (soinfo_relocate(si, si->rel, si->rel_count, needed)) {
             return false;
         }
@@ -1953,6 +2008,23 @@
         return false;
     }
 
+    /* Handle serializing/sharing the RELRO segment */
+    if (extinfo && (extinfo->flags & ANDROID_DLEXT_WRITE_RELRO)) {
+      if (phdr_table_serialize_gnu_relro(si->phdr, si->phnum, si->load_bias,
+                                         extinfo->relro_fd) < 0) {
+        DL_ERR("failed serializing GNU RELRO section for \"%s\": %s",
+               si->name, strerror(errno));
+        return false;
+      }
+    } else if (extinfo && (extinfo->flags & ANDROID_DLEXT_USE_RELRO)) {
+      if (phdr_table_map_gnu_relro(si->phdr, si->phnum, si->load_bias,
+                                   extinfo->relro_fd) < 0) {
+        DL_ERR("failed mapping GNU RELRO section for \"%s\": %s",
+               si->name, strerror(errno));
+        return false;
+      }
+    }
+
     notify_gdb_of_load(si);
     return true;
 }
@@ -1962,32 +2034,65 @@
  * It helps to stack unwinding through signal handlers.
  * Also, it makes bionic more like glibc.
  */
-static void add_vdso(KernelArgumentBlock& args UNUSED) {
+static void add_vdso(KernelArgumentBlock& args __unused) {
 #if defined(AT_SYSINFO_EHDR)
-    Elf_Ehdr* ehdr_vdso = reinterpret_cast<Elf_Ehdr*>(args.getauxval(AT_SYSINFO_EHDR));
-    if (ehdr_vdso == NULL) {
-        return;
-    }
+  ElfW(Ehdr)* ehdr_vdso = reinterpret_cast<ElfW(Ehdr)*>(args.getauxval(AT_SYSINFO_EHDR));
+  if (ehdr_vdso == NULL) {
+    return;
+  }
 
-    soinfo* si = soinfo_alloc("[vdso]");
+  soinfo* si = soinfo_alloc("[vdso]", NULL);
 
-    si->phdr = reinterpret_cast<Elf_Phdr*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff);
-    si->phnum = ehdr_vdso->e_phnum;
-    si->base = reinterpret_cast<Elf_Addr>(ehdr_vdso);
-    si->size = phdr_table_get_load_size(si->phdr, si->phnum);
-    si->flags = 0;
-    si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
+  si->phdr = reinterpret_cast<ElfW(Phdr)*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff);
+  si->phnum = ehdr_vdso->e_phnum;
+  si->base = reinterpret_cast<ElfW(Addr)>(ehdr_vdso);
+  si->size = phdr_table_get_load_size(si->phdr, si->phnum);
+  si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
 
-    soinfo_link_image(si);
+  soinfo_link_image(si, NULL);
 #endif
 }
 
 /*
+ * This is linker soinfo for GDB. See details below.
+ */
+static soinfo linker_soinfo_for_gdb;
+
+/* gdb expects the linker to be in the debug shared object list.
+ * Without this, gdb has trouble locating the linker's ".text"
+ * and ".plt" sections. Gdb could also potentially use this to
+ * relocate the offset of our exported 'rtld_db_dlactivity' symbol.
+ * Don't use soinfo_alloc(), because the linker shouldn't
+ * be on the soinfo list.
+ */
+static void init_linker_info_for_gdb(ElfW(Addr) linker_base) {
+#if defined(__LP64__)
+  strlcpy(linker_soinfo_for_gdb.name, "/system/bin/linker64", sizeof(linker_soinfo_for_gdb.name));
+#else
+  strlcpy(linker_soinfo_for_gdb.name, "/system/bin/linker", sizeof(linker_soinfo_for_gdb.name));
+#endif
+  linker_soinfo_for_gdb.flags = FLAG_NEW_SOINFO;
+  linker_soinfo_for_gdb.base = linker_base;
+
+  /*
+   * Set the dynamic field in the link map otherwise gdb will complain with
+   * the following:
+   *   warning: .dynamic section for "/system/bin/linker" is not at the
+   *   expected address (wrong library or version mismatch?)
+   */
+  ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_base);
+  ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_base + elf_hdr->e_phoff);
+  phdr_table_get_dynamic_section(phdr, elf_hdr->e_phnum, linker_base,
+                                 &linker_soinfo_for_gdb.dynamic, NULL, NULL);
+  insert_soinfo_into_debug_map(&linker_soinfo_for_gdb);
+}
+
+/*
  * This code is called after the linker has linked itself and
  * fixed it's own GOT. It is safe to make references to externs
  * and other non-local data at this point.
  */
-static Elf_Addr __linker_init_post_relocation(KernelArgumentBlock& args, Elf_Addr linker_base) {
+static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(Addr) linker_base) {
     /* NOTE: we store the args pointer on a special location
      *       of the temporary TLS area in order to pass it to
      *       the C Library's runtime initializer.
@@ -2017,7 +2122,7 @@
     // Get a few environment variables.
     const char* LD_DEBUG = linker_env_get("LD_DEBUG");
     if (LD_DEBUG != NULL) {
-      gLdDebugVerbosity = atoi(LD_DEBUG);
+      g_ld_debug_verbosity = atoi(LD_DEBUG);
     }
 
     // Normally, these are cleaned by linker_env_init, but the test
@@ -2031,14 +2136,14 @@
 
     INFO("[ android linker & debugger ]");
 
-    soinfo* si = soinfo_alloc(args.argv[0]);
+    soinfo* si = soinfo_alloc(args.argv[0], NULL);
     if (si == NULL) {
         exit(EXIT_FAILURE);
     }
 
     /* bootstrap the link map, the main exe always needs to be first */
     si->flags |= FLAG_EXE;
-    link_map_t* map = &(si->link_map);
+    link_map* map = &(si->link_map_head);
 
     map->l_addr = 0;
     map->l_name = args.argv[0];
@@ -2048,38 +2153,10 @@
     _r_debug.r_map = map;
     r_debug_tail = map;
 
-    /* gdb expects the linker to be in the debug shared object list.
-     * Without this, gdb has trouble locating the linker's ".text"
-     * and ".plt" sections. Gdb could also potentially use this to
-     * relocate the offset of our exported 'rtld_db_dlactivity' symbol.
-     * Don't use soinfo_alloc(), because the linker shouldn't
-     * be on the soinfo list.
-     */
-    {
-        static soinfo linker_soinfo;
-#if defined(__LP64__)
-        strlcpy(linker_soinfo.name, "/system/bin/linker64", sizeof(linker_soinfo.name));
-#else
-        strlcpy(linker_soinfo.name, "/system/bin/linker", sizeof(linker_soinfo.name));
-#endif
-        linker_soinfo.flags = 0;
-        linker_soinfo.base = linker_base;
-
-        /*
-         * Set the dynamic field in the link map otherwise gdb will complain with
-         * the following:
-         *   warning: .dynamic section for "/system/bin/linker" is not at the
-         *   expected address (wrong library or version mismatch?)
-         */
-        Elf_Ehdr *elf_hdr = (Elf_Ehdr *) linker_base;
-        Elf_Phdr *phdr = (Elf_Phdr*)((unsigned char*) linker_base + elf_hdr->e_phoff);
-        phdr_table_get_dynamic_section(phdr, elf_hdr->e_phnum, linker_base,
-                                       &linker_soinfo.dynamic, NULL, NULL);
-        insert_soinfo_into_debug_map(&linker_soinfo);
-    }
+    init_linker_info_for_gdb(linker_base);
 
     // Extract information passed from the kernel.
-    si->phdr = reinterpret_cast<Elf_Phdr*>(args.getauxval(AT_PHDR));
+    si->phdr = reinterpret_cast<ElfW(Phdr)*>(args.getauxval(AT_PHDR));
     si->phnum = args.getauxval(AT_PHNUM);
     si->entry = args.getauxval(AT_ENTRY);
 
@@ -2092,21 +2169,27 @@
     si->load_bias = 0;
     for (size_t i = 0; i < si->phnum; ++i) {
       if (si->phdr[i].p_type == PT_PHDR) {
-        si->load_bias = reinterpret_cast<Elf_Addr>(si->phdr) - si->phdr[i].p_vaddr;
-        si->base = reinterpret_cast<Elf_Addr>(si->phdr) - si->phdr[i].p_offset;
+        si->load_bias = reinterpret_cast<ElfW(Addr)>(si->phdr) - si->phdr[i].p_vaddr;
+        si->base = reinterpret_cast<ElfW(Addr)>(si->phdr) - si->phdr[i].p_offset;
         break;
       }
     }
     si->dynamic = NULL;
     si->ref_count = 1;
 
+    ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
+    if (elf_hdr->e_type != ET_DYN) {
+        __libc_format_fd(2, "error: only position independent executables (PIE) are supported.\n");
+        exit(EXIT_FAILURE);
+    }
+
     // Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
     parse_LD_LIBRARY_PATH(ldpath_env);
     parse_LD_PRELOAD(ldpreload_env);
 
     somain = si;
 
-    if (!soinfo_link_image(si)) {
+    if (!soinfo_link_image(si, NULL)) {
         __libc_format_fd(2, "CANNOT LINK EXECUTABLE: %s\n", linker_get_error_buffer());
         exit(EXIT_FAILURE);
     }
@@ -2115,8 +2198,8 @@
 
     si->CallPreInitConstructors();
 
-    for (size_t i = 0; gLdPreloads[i] != NULL; ++i) {
-        gLdPreloads[i]->CallConstructors();
+    for (size_t i = 0; g_ld_preloads[i] != NULL; ++i) {
+        g_ld_preloads[i]->CallConstructors();
     }
 
     /* After the link_image, the si->load_bias is initialized.
@@ -2128,11 +2211,10 @@
     si->CallConstructors();
 
 #if TIMING
-    gettimeofday(&t1,NULL);
+    gettimeofday(&t1, NULL);
     PRINT("LINKER TIME: %s: %d microseconds", args.argv[0], (int) (
                (((long long)t1.tv_sec * 1000000LL) + (long long)t1.tv_usec) -
-               (((long long)t0.tv_sec * 1000000LL) + (long long)t0.tv_usec)
-               ));
+               (((long long)t0.tv_sec * 1000000LL) + (long long)t0.tv_usec)));
 #endif
 #if STATS
     PRINT("RELO STATS: %s: %d abs, %d rel, %d copy, %d symbol", args.argv[0],
@@ -2183,19 +2265,21 @@
  *    load bias, i.e. add the value of any p_vaddr in the file to get
  *    the corresponding address in memory.
  */
-static Elf_Addr get_elf_exec_load_bias(const Elf_Ehdr* elf) {
-  Elf_Addr offset = elf->e_phoff;
-  const Elf_Phdr* phdr_table = (const Elf_Phdr*)((char*)elf + offset);
-  const Elf_Phdr* phdr_end = phdr_table + elf->e_phnum;
+static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf) {
+  ElfW(Addr) offset = elf->e_phoff;
+  const ElfW(Phdr)* phdr_table = reinterpret_cast<const ElfW(Phdr)*>(reinterpret_cast<uintptr_t>(elf) + offset);
+  const ElfW(Phdr)* phdr_end = phdr_table + elf->e_phnum;
 
-  for (const Elf_Phdr* phdr = phdr_table; phdr < phdr_end; phdr++) {
+  for (const ElfW(Phdr)* phdr = phdr_table; phdr < phdr_end; phdr++) {
     if (phdr->p_type == PT_LOAD) {
-      return reinterpret_cast<Elf_Addr>(elf) + phdr->p_offset - phdr->p_vaddr;
+      return reinterpret_cast<ElfW(Addr)>(elf) + phdr->p_offset - phdr->p_vaddr;
     }
   }
   return 0;
 }
 
+extern "C" void _start();
+
 /*
  * This is the entry point for the linker, called from begin.S. This
  * method is responsible for fixing the linker's own relocations, and
@@ -2205,16 +2289,31 @@
  * relocations, any attempt to reference an extern variable, extern
  * function, or other GOT reference will generate a segfault.
  */
-extern "C" Elf_Addr __linker_init(void* raw_args) {
+extern "C" ElfW(Addr) __linker_init(void* raw_args) {
+  // Initialize static variables.
+  solist = get_libdl_info();
+  sonext = get_libdl_info();
+
   KernelArgumentBlock args(raw_args);
 
-  Elf_Addr linker_addr = args.getauxval(AT_BASE);
-  Elf_Ehdr* elf_hdr = reinterpret_cast<Elf_Ehdr*>(linker_addr);
-  Elf_Phdr* phdr = (Elf_Phdr*)((unsigned char*) linker_addr + elf_hdr->e_phoff);
+  ElfW(Addr) linker_addr = args.getauxval(AT_BASE);
+  ElfW(Addr) entry_point = args.getauxval(AT_ENTRY);
+  ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_addr);
+  ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_addr + elf_hdr->e_phoff);
 
   soinfo linker_so;
   memset(&linker_so, 0, sizeof(soinfo));
 
+  // If the linker is not acting as PT_INTERP entry_point is equal to
+  // _start. Which means that the linker is running as an executable and
+  // already linked by PT_INTERP.
+  //
+  // This happens when user tries to run 'adb shell /system/bin/linker'
+  // see also https://code.google.com/p/android/issues/detail?id=63174
+  if (reinterpret_cast<ElfW(Addr)>(&_start) == entry_point) {
+    __libc_fatal("This is %s, the helper program for shared library executables.\n", args.argv[0]);
+  }
+
   strcpy(linker_so.name, "[dynamic linker]");
   linker_so.base = linker_addr;
   linker_so.size = phdr_table_get_load_size(phdr, elf_hdr->e_phnum);
@@ -2224,7 +2323,7 @@
   linker_so.phnum = elf_hdr->e_phnum;
   linker_so.flags |= FLAG_LINKER;
 
-  if (!soinfo_link_image(&linker_so)) {
+  if (!soinfo_link_image(&linker_so, NULL)) {
     // It would be nice to print an error message, but if the linker
     // can't link itself, there's no guarantee that we'll be able to
     // call write() (because it involves a GOT reference). We may as
@@ -2236,12 +2335,15 @@
     _exit(EXIT_FAILURE);
   }
 
+  // Initialize the linker's own global variables
+  linker_so.CallConstructors();
+
   // We have successfully fixed our own relocations. It's safe to run
   // the main part of the linker now.
-  args.abort_message_ptr = &gAbortMessage;
-  Elf_Addr start_address = __linker_init_post_relocation(args, linker_addr);
+  args.abort_message_ptr = &g_abort_message;
+  ElfW(Addr) start_address = __linker_init_post_relocation(args, linker_addr);
 
-  set_soinfo_pool_protection(PROT_READ);
+  protect_data(PROT_READ);
 
   // Return the address that the calling assembly stub should jump to.
   return start_address;
diff --git a/linker/linker.h b/linker/linker.h
index 972050f..374652e 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -32,8 +32,11 @@
 #include <elf.h>
 #include <link.h>
 #include <unistd.h>
+#include <android/dlext.h>
+#include <sys/stat.h>
 
 #include "private/libc_logging.h"
+#include "linked_list.h"
 
 #define DL_ERR(fmt, x...) \
     do { \
@@ -50,6 +53,25 @@
       __libc_format_fd(2, "\n"); \
     } while (false)
 
+#if defined(__LP64__)
+#define ELFW(what) ELF64_ ## what
+#else
+#define ELFW(what) ELF32_ ## what
+#endif
+
+// mips64 interprets Elf64_Rel structures' r_info field differently.
+// bionic (like other C libraries) has macros that assume regular ELF files,
+// but the dynamic linker needs to be able to load mips64 ELF files.
+#if defined(__mips__) && defined(__LP64__)
+#undef ELF64_R_SYM
+#undef ELF64_R_TYPE
+#undef ELF64_R_INFO
+#define ELF64_R_SYM(info)   (((info) >> 0) & 0xffffffff)
+#define ELF64_R_SSYM(info)  (((info) >> 32) & 0xff)
+#define ELF64_R_TYPE3(info) (((info) >> 40) & 0xff)
+#define ELF64_R_TYPE2(info) (((info) >> 48) & 0xff)
+#define ELF64_R_TYPE(info)  (((info) >> 56) & 0xff)
+#endif
 
 // Returns the address of the page containing address 'x'.
 #define PAGE_START(x)  ((x) & PAGE_MASK)
@@ -61,58 +83,47 @@
 // itself at the start of a page.
 #define PAGE_END(x)    PAGE_START((x) + (PAGE_SIZE-1))
 
-// Magic shared structures that GDB knows about.
-
-struct link_map_t {
-  uintptr_t l_addr;
-  char*  l_name;
-  uintptr_t l_ld;
-  link_map_t* l_next;
-  link_map_t* l_prev;
-};
-
-// Values for r_debug->state
-enum {
-  RT_CONSISTENT,
-  RT_ADD,
-  RT_DELETE
-};
-
-struct r_debug {
-  int32_t r_version;
-  link_map_t* r_map;
-  void (*r_brk)(void);
-  int32_t r_state;
-  uintptr_t r_ldbase;
-};
-
 #define FLAG_LINKED     0x00000001
 #define FLAG_EXE        0x00000004 // The main executable
 #define FLAG_LINKER     0x00000010 // The linker itself
+#define FLAG_NEW_SOINFO 0x40000000 // new soinfo format
 
 #define SOINFO_NAME_LEN 128
 
 typedef void (*linker_function_t)();
 
-// Android uses REL for 32-bit but only uses RELA for 64-bit.
-#if defined(__LP64__)
+// Android uses RELA for aarch64 and x86_64. mips64 still uses REL.
+#if defined(__aarch64__) || defined(__x86_64__)
 #define USE_RELA 1
 #endif
 
+struct soinfo;
+
+class SoinfoListAllocator {
+public:
+  static LinkedListEntry<soinfo>* alloc();
+  static void free(LinkedListEntry<soinfo>* entry);
+private:
+  // unconstructable
+  DISALLOW_IMPLICIT_CONSTRUCTORS(SoinfoListAllocator);
+};
+
 struct soinfo {
  public:
+  typedef LinkedList<soinfo, SoinfoListAllocator> soinfo_list_t;
+ public:
   char name[SOINFO_NAME_LEN];
-  const Elf_Phdr* phdr;
+  const ElfW(Phdr)* phdr;
   size_t phnum;
-  Elf_Addr entry;
-  Elf_Addr base;
+  ElfW(Addr) entry;
+  ElfW(Addr) base;
   size_t size;
 
 #ifndef __LP64__
   uint32_t unused1;  // DO NOT USE, maintained for compatibility.
 #endif
 
-  Elf_Dyn* dynamic;
+  ElfW(Dyn)* dynamic;
 
 #ifndef __LP64__
   uint32_t unused2; // DO NOT USE, maintained for compatibility
@@ -123,30 +134,30 @@
   unsigned flags;
 
   const char* strtab;
-  Elf_Sym* symtab;
+  ElfW(Sym)* symtab;
 
   size_t nbucket;
   size_t nchain;
   unsigned* bucket;
   unsigned* chain;
 
-#if !defined(__LP64__)
-  // This is only used by 32-bit MIPS, but needs to be here for
+#if defined(__mips__) || !defined(__LP64__)
+  // This is only used by mips and mips64, but needs to be here for
   // all 32-bit architectures to preserve binary compatibility.
-  unsigned* plt_got;
+  ElfW(Addr)** plt_got;
 #endif
 
 #if defined(USE_RELA)
-  Elf_Rela* plt_rela;
+  ElfW(Rela)* plt_rela;
   size_t plt_rela_count;
 
-  Elf_Rela* rela;
+  ElfW(Rela)* rela;
   size_t rela_count;
 #else
-  Elf_Rel* plt_rel;
+  ElfW(Rel)* plt_rel;
   size_t plt_rel_count;
 
-  Elf_Rel* rel;
+  ElfW(Rel)* rel;
   size_t rel_count;
 #endif
 
@@ -172,43 +183,65 @@
 #endif
 
   size_t ref_count;
-  link_map_t link_map;
+  link_map link_map_head;
 
   bool constructors_called;
 
   // When you read a virtual address from the ELF file, add this
   // value to get the corresponding address in the process' address space.
-  Elf_Addr load_bias;
+  ElfW(Addr) load_bias;
 
 #if !defined(__LP64__)
   bool has_text_relocations;
 #endif
   bool has_DT_SYMBOLIC;
-
   void CallConstructors();
   void CallDestructors();
   void CallPreInitConstructors();
 
+  void add_child(soinfo* child);
+  void remove_all_links();
+
+  void set_st_dev(dev_t st_dev);
+  void set_st_ino(ino_t st_ino);
+  ino_t get_st_ino();
+  dev_t get_st_dev();
+
+  soinfo_list_t& get_children();
+
  private:
   void CallArray(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
   void CallFunction(const char* function_name, linker_function_t function);
+
+ private:
+  // This part of the structure is only available
+  // when FLAG_NEW_SOINFO is set in this->flags.
+  unsigned int version;
+
+  dev_t st_dev;
+  ino_t st_ino;
+
+  // dependency graph
+  soinfo_list_t children;
+  soinfo_list_t parents;
+
 };
 
-extern soinfo libdl_info;
+extern soinfo* get_libdl_info();
 
 void do_android_get_LD_LIBRARY_PATH(char*, size_t);
 void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
-soinfo* do_dlopen(const char* name, int flags);
-int do_dlclose(soinfo* si);
+soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo);
+void do_dlclose(soinfo* si);
 
-Elf_Sym* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start);
+ElfW(Sym)* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start);
 soinfo* find_containing_library(const void* addr);
 
-Elf_Sym* dladdr_find_symbol(soinfo* si, const void* addr);
-Elf_Sym* dlsym_handle_lookup(soinfo* si, const char* name);
+ElfW(Sym)* dladdr_find_symbol(soinfo* si, const void* addr);
+ElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name);
 
 void debuggerd_init();
-extern "C" abort_msg_t* gAbortMessage;
+extern "C" abort_msg_t* g_abort_message;
 extern "C" void notify_gdb_of_libraries();
 
 char* linker_get_error_buffer();
diff --git a/linker/linker_allocator.cpp b/linker/linker_allocator.cpp
new file mode 100644
index 0000000..92220e8
--- /dev/null
+++ b/linker/linker_allocator.cpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "linker_allocator.h"
+#include <inttypes.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#include "private/bionic_prctl.h"
+
+struct LinkerAllocatorPage {
+  LinkerAllocatorPage* next;
+  uint8_t bytes[PAGE_SIZE-sizeof(LinkerAllocatorPage*)];
+};
+
+struct FreeBlockInfo {
+  void* next_block;
+  size_t num_free_blocks;
+};
+
+LinkerBlockAllocator::LinkerBlockAllocator(size_t block_size)
+  : block_size_(block_size < sizeof(FreeBlockInfo) ? sizeof(FreeBlockInfo) : block_size),
+    page_list_(nullptr),
+    free_block_list_(nullptr)
+{}
+
+void* LinkerBlockAllocator::alloc() {
+  if (free_block_list_ == nullptr) {
+    create_new_page();
+  }
+
+  FreeBlockInfo* block_info = reinterpret_cast<FreeBlockInfo*>(free_block_list_);
+  if (block_info->num_free_blocks > 1) {
+    FreeBlockInfo* next_block_info = reinterpret_cast<FreeBlockInfo*>(
+      reinterpret_cast<char*>(free_block_list_) + block_size_);
+    next_block_info->next_block = block_info->next_block;
+    next_block_info->num_free_blocks = block_info->num_free_blocks - 1;
+    free_block_list_ = next_block_info;
+  } else {
+    free_block_list_ = block_info->next_block;
+  }
+
+  memset(block_info, 0, block_size_);
+
+  return block_info;
+}
+
+void LinkerBlockAllocator::free(void* block) {
+  if (block == nullptr) {
+    return;
+  }
+
+  LinkerAllocatorPage* page = find_page(block);
+
+  if (page == nullptr) {
+    abort();
+  }
+
+  ssize_t offset = reinterpret_cast<uint8_t*>(block) - page->bytes;
+
+  if (offset % block_size_ != 0) {
+    abort();
+  }
+
+  memset(block, 0, block_size_);
+
+  FreeBlockInfo* block_info = reinterpret_cast<FreeBlockInfo*>(block);
+
+  block_info->next_block = free_block_list_;
+  block_info->num_free_blocks = 1;
+
+  free_block_list_ = block_info;
+}
+
+void LinkerBlockAllocator::protect_all(int prot) {
+  for (LinkerAllocatorPage* page = page_list_; page != nullptr; page = page->next) {
+    if (mprotect(page, PAGE_SIZE, prot) == -1) {
+      abort();
+    }
+  }
+}
+
+void LinkerBlockAllocator::create_new_page() {
+  LinkerAllocatorPage* page = reinterpret_cast<LinkerAllocatorPage*>(mmap(nullptr, PAGE_SIZE,
+      PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0));
+  if (page == MAP_FAILED) {
+    abort(); // oom
+  }
+
+  prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, page, PAGE_SIZE, "linker_alloc");
+
+  memset(page, 0, PAGE_SIZE);
+
+  FreeBlockInfo* first_block = reinterpret_cast<FreeBlockInfo*>(page->bytes);
+  first_block->next_block = free_block_list_;
+  first_block->num_free_blocks = (PAGE_SIZE - sizeof(LinkerAllocatorPage*))/block_size_;
+
+  free_block_list_ = first_block;
+
+  page->next = page_list_;
+  page_list_ = page;
+}
+
+LinkerAllocatorPage* LinkerBlockAllocator::find_page(void* block) {
+  if (block == nullptr) {
+    abort();
+  }
+
+  LinkerAllocatorPage* page = page_list_;
+  while (page != nullptr) {
+    const uint8_t* page_ptr = reinterpret_cast<const uint8_t*>(page);
+    if (block >= (page_ptr + sizeof(page->next)) && block < (page_ptr + PAGE_SIZE)) {
+      return page;
+    }
+
+    page = page->next;
+  }
+
+  abort();
+}
diff --git a/linker/linker_allocator.h b/linker/linker_allocator.h
new file mode 100644
index 0000000..5d3563f
--- /dev/null
+++ b/linker/linker_allocator.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LINKER_ALLOCATOR_H
+#define __LINKER_ALLOCATOR_H
+
+#include <stdlib.h>
+#include <limits.h>
+#include "private/bionic_macros.h"
+
+struct LinkerAllocatorPage;
+
+/*
+ * This class is a non-template version of the LinkerAllocator
+ * It keeps code inside .cpp file by keeping the interface
+ * template-free.
+ *
+ * Please use LinkerAllocator<type> where possible (everywhere).
+ */
+class LinkerBlockAllocator {
+ public:
+  explicit LinkerBlockAllocator(size_t block_size);
+
+  void* alloc();
+  void free(void* block);
+  void protect_all(int prot);
+
+ private:
+  void create_new_page();
+  LinkerAllocatorPage* find_page(void* block);
+
+  size_t block_size_;
+  LinkerAllocatorPage* page_list_;
+  void* free_block_list_;
+
+  DISALLOW_COPY_AND_ASSIGN(LinkerBlockAllocator);
+};
+
+/*
+ * We can't use malloc(3) in the dynamic linker.
+ *
+ * A simple allocator for the dynamic linker. An allocator allocates instances
+ * of a single fixed-size type. Allocations are backed by page-sized private
+ * anonymous mmaps.
+ */
+template<typename T>
+class LinkerAllocator {
+ public:
+  LinkerAllocator() : block_allocator_(sizeof(T)) {}
+  T* alloc() { return reinterpret_cast<T*>(block_allocator_.alloc()); }
+  void free(T* t) { block_allocator_.free(t); }
+  void protect_all(int prot) { block_allocator_.protect_all(prot); }
+ private:
+  LinkerBlockAllocator block_allocator_;
+  DISALLOW_COPY_AND_ASSIGN(LinkerAllocator);
+};
+#endif // __LINKER_ALLOCATOR_H
diff --git a/linker/linker_debug.h b/linker/linker_debug.h
index 2bf6cec..3faa38e 100644
--- a/linker/linker_debug.h
+++ b/linker/linker_debug.h
@@ -55,17 +55,17 @@
 
 #include "private/libc_logging.h"
 
-__LIBC_HIDDEN__ extern int gLdDebugVerbosity;
+__LIBC_HIDDEN__ extern int g_ld_debug_verbosity;
 
 #if LINKER_DEBUG_TO_LOG
-#define _PRINTVF(v,x...) \
+#define _PRINTVF(v, x...) \
     do { \
-      if (gLdDebugVerbosity > (v)) __libc_format_log(5-(v),"linker",x); \
+      if (g_ld_debug_verbosity > (v)) __libc_format_log(5-(v), "linker", x); \
     } while (0)
 #else /* !LINKER_DEBUG_TO_LOG */
-#define _PRINTVF(v,x...) \
+#define _PRINTVF(v, x...) \
     do { \
-      if (gLdDebugVerbosity > (v)) { __libc_format_fd(1, x); write(1, "\n", 1); } \
+      if (g_ld_debug_verbosity > (v)) { __libc_format_fd(1, x); write(1, "\n", 1); } \
     } while (0)
 #endif /* !LINKER_DEBUG_TO_LOG */
 
@@ -79,6 +79,6 @@
 #define DEBUG(x...)          do {} while (0)
 #endif /* TRACE_DEBUG */
 
-#define TRACE_TYPE(t,x...)   do { if (DO_TRACE_##t) { TRACE(x); } } while (0)
+#define TRACE_TYPE(t, x...)   do { if (DO_TRACE_##t) { TRACE(x); } } while (0)
 
 #endif /* _LINKER_DEBUG_H_ */
diff --git a/linker/linker_executable.mk b/linker/linker_executable.mk
new file mode 100644
index 0000000..4902a0c
--- /dev/null
+++ b/linker/linker_executable.mk
@@ -0,0 +1,26 @@
+
+#
+# Instead of including $(BUILD_EXECUTABLE), we execute the steps to create an executable by
+# hand, as we want to insert an extra objcopy step that is not supported by the build
+# system, and is probably specific the linker only, so there's no need to modify the build
+# system for the purpose.
+#
+
+LOCAL_MODULE_CLASS := EXECUTABLES
+LOCAL_MODULE_SUFFIX := $(TARGET_EXECUTABLE_SUFFIX)
+
+include $(BUILD_SYSTEM)/dynamic_binary.mk
+
+# See build/core/executable_internal.mk
+$(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LD_DIRS)
+$(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS)
+$(linked_module): PRIVATE_TARGET_FDO_LIB := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_LIB)
+$(linked_module): PRIVATE_TARGET_LIBGCC := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCC)
+$(linked_module): PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTBEGIN_DYNAMIC_O)
+$(linked_module): PRIVATE_TARGET_CRTBEGIN_STATIC_O := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTBEGIN_STATIC_O)
+$(linked_module): PRIVATE_TARGET_CRTEND_O := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTEND_O)
+$(linked_module): PRIVATE_TARGET_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
+$(linked_module): $(TARGET_CRTBEGIN_STATIC_O) $(all_objects) $(all_libraries) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTEND_O)
+	$(transform-o-to-static-executable)
+	@echo "target PrefixSymbols: $(PRIVATE_MODULE) ($@)"
+	$(hide) $(PRIVATE_TARGET_OBJCOPY) --prefix-symbols=__dl_ $@
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 3101511..0b99d20 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -31,6 +31,9 @@
 #include <errno.h>
 #include <machine/exec.h>
 #include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include "linker.h"
 #include "linker_debug.h"
@@ -50,7 +53,7 @@
     p_vaddr   -> segment's virtual address
     p_flags   -> segment flags (e.g. readable, writable, executable)
 
-  We will ignore the p_paddr and p_align fields of Elf_Phdr for now.
+  We will ignore the p_paddr and p_align fields of ElfW(Phdr) for now.
 
   The loadable segments can be seen as a list of [p_vaddr ... p_vaddr+p_memsz)
   ranges of virtual addresses. A few rules apply:
@@ -111,7 +114,7 @@
 
  **/
 
-#define MAYBE_MAP_FLAG(x,from,to)    (((x) & (from)) ? (to) : 0)
+#define MAYBE_MAP_FLAG(x, from, to)  (((x) & (from)) ? (to) : 0)
 #define PFLAGS_TO_PROT(x)            (MAYBE_MAP_FLAG((x), PF_X, PROT_EXEC) | \
                                       MAYBE_MAP_FLAG((x), PF_R, PROT_READ) | \
                                       MAYBE_MAP_FLAG((x), PF_W, PROT_WRITE))
@@ -124,19 +127,16 @@
 }
 
 ElfReader::~ElfReader() {
-  if (fd_ != -1) {
-    close(fd_);
-  }
   if (phdr_mmap_ != NULL) {
     munmap(phdr_mmap_, phdr_size_);
   }
 }
 
-bool ElfReader::Load() {
+bool ElfReader::Load(const android_dlextinfo* extinfo) {
   return ReadElfHeader() &&
          VerifyElfHeader() &&
          ReadProgramHeader() &&
-         ReserveAddressSpace() &&
+         ReserveAddressSpace(extinfo) &&
          LoadSegments() &&
          FindPhdr();
 }
@@ -156,10 +156,7 @@
 }
 
 bool ElfReader::VerifyElfHeader() {
-  if (header_.e_ident[EI_MAG0] != ELFMAG0 ||
-      header_.e_ident[EI_MAG1] != ELFMAG1 ||
-      header_.e_ident[EI_MAG2] != ELFMAG2 ||
-      header_.e_ident[EI_MAG3] != ELFMAG3) {
+  if (memcmp(header_.e_ident, ELFMAG, SELFMAG) != 0) {
     DL_ERR("\"%s\" has bad ELF magic", name_);
     return false;
   }
@@ -217,14 +214,14 @@
 
   // Like the kernel, we only accept program header tables that
   // are smaller than 64KiB.
-  if (phdr_num_ < 1 || phdr_num_ > 65536/sizeof(Elf_Phdr)) {
+  if (phdr_num_ < 1 || phdr_num_ > 65536/sizeof(ElfW(Phdr))) {
     DL_ERR("\"%s\" has invalid e_phnum: %zd", name_, phdr_num_);
     return false;
   }
 
-  Elf_Addr page_min = PAGE_START(header_.e_phoff);
-  Elf_Addr page_max = PAGE_END(header_.e_phoff + (phdr_num_ * sizeof(Elf_Phdr)));
-  Elf_Addr page_offset = PAGE_OFFSET(header_.e_phoff);
+  ElfW(Addr) page_min = PAGE_START(header_.e_phoff);
+  ElfW(Addr) page_max = PAGE_END(header_.e_phoff + (phdr_num_ * sizeof(ElfW(Phdr))));
+  ElfW(Addr) page_offset = PAGE_OFFSET(header_.e_phoff);
 
   phdr_size_ = page_max - page_min;
 
@@ -235,7 +232,7 @@
   }
 
   phdr_mmap_ = mmap_result;
-  phdr_table_ = reinterpret_cast<Elf_Phdr*>(reinterpret_cast<char*>(mmap_result) + page_offset);
+  phdr_table_ = reinterpret_cast<ElfW(Phdr)*>(reinterpret_cast<char*>(mmap_result) + page_offset);
   return true;
 }
 
@@ -249,50 +246,50 @@
  * set to the minimum and maximum addresses of pages to be reserved,
  * or 0 if there is nothing to load.
  */
-size_t phdr_table_get_load_size(const Elf_Phdr* phdr_table, size_t phdr_count,
-                                Elf_Addr* out_min_vaddr,
-                                Elf_Addr* out_max_vaddr) {
-    Elf_Addr min_vaddr = UINTPTR_MAX;
-    Elf_Addr max_vaddr = 0;
+size_t phdr_table_get_load_size(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                                ElfW(Addr)* out_min_vaddr,
+                                ElfW(Addr)* out_max_vaddr) {
+  ElfW(Addr) min_vaddr = UINTPTR_MAX;
+  ElfW(Addr) max_vaddr = 0;
 
-    bool found_pt_load = false;
-    for (size_t i = 0; i < phdr_count; ++i) {
-        const Elf_Phdr* phdr = &phdr_table[i];
+  bool found_pt_load = false;
+  for (size_t i = 0; i < phdr_count; ++i) {
+    const ElfW(Phdr)* phdr = &phdr_table[i];
 
-        if (phdr->p_type != PT_LOAD) {
-            continue;
-        }
-        found_pt_load = true;
-
-        if (phdr->p_vaddr < min_vaddr) {
-            min_vaddr = phdr->p_vaddr;
-        }
-
-        if (phdr->p_vaddr + phdr->p_memsz > max_vaddr) {
-            max_vaddr = phdr->p_vaddr + phdr->p_memsz;
-        }
+    if (phdr->p_type != PT_LOAD) {
+      continue;
     }
-    if (!found_pt_load) {
-        min_vaddr = 0;
+    found_pt_load = true;
+
+    if (phdr->p_vaddr < min_vaddr) {
+      min_vaddr = phdr->p_vaddr;
     }
 
-    min_vaddr = PAGE_START(min_vaddr);
-    max_vaddr = PAGE_END(max_vaddr);
+    if (phdr->p_vaddr + phdr->p_memsz > max_vaddr) {
+      max_vaddr = phdr->p_vaddr + phdr->p_memsz;
+    }
+  }
+  if (!found_pt_load) {
+    min_vaddr = 0;
+  }
 
-    if (out_min_vaddr != NULL) {
-        *out_min_vaddr = min_vaddr;
-    }
-    if (out_max_vaddr != NULL) {
-        *out_max_vaddr = max_vaddr;
-    }
-    return max_vaddr - min_vaddr;
+  min_vaddr = PAGE_START(min_vaddr);
+  max_vaddr = PAGE_END(max_vaddr);
+
+  if (out_min_vaddr != NULL) {
+    *out_min_vaddr = min_vaddr;
+  }
+  if (out_max_vaddr != NULL) {
+    *out_max_vaddr = max_vaddr;
+  }
+  return max_vaddr - min_vaddr;
 }
 
 // Reserve a virtual address range big enough to hold all loadable
 // segments of a program header table. This is done by creating a
 // private anonymous mmap() with PROT_NONE.
-bool ElfReader::ReserveAddressSpace() {
-  Elf_Addr min_vaddr;
+bool ElfReader::ReserveAddressSpace(const android_dlextinfo* extinfo) {
+  ElfW(Addr) min_vaddr;
   load_size_ = phdr_table_get_load_size(phdr_table_, phdr_num_, &min_vaddr);
   if (load_size_ == 0) {
     DL_ERR("\"%s\" has no loadable segments", name_);
@@ -300,11 +297,33 @@
   }
 
   uint8_t* addr = reinterpret_cast<uint8_t*>(min_vaddr);
-  int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS;
-  void* start = mmap(addr, load_size_, PROT_NONE, mmap_flags, -1, 0);
-  if (start == MAP_FAILED) {
-    DL_ERR("couldn't reserve %zd bytes of address space for \"%s\"", load_size_, name_);
-    return false;
+  void* start;
+  size_t reserved_size = 0;
+  bool reserved_hint = true;
+
+  if (extinfo != NULL) {
+    if (extinfo->flags & ANDROID_DLEXT_RESERVED_ADDRESS) {
+      reserved_size = extinfo->reserved_size;
+      reserved_hint = false;
+    } else if (extinfo->flags & ANDROID_DLEXT_RESERVED_ADDRESS_HINT) {
+      reserved_size = extinfo->reserved_size;
+    }
+  }
+
+  if (load_size_ > reserved_size) {
+    if (!reserved_hint) {
+      DL_ERR("reserved address space %zd smaller than %zd bytes needed for \"%s\"",
+             reserved_size - load_size_, load_size_, name_);
+      return false;
+    }
+    int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS;
+    start = mmap(addr, load_size_, PROT_NONE, mmap_flags, -1, 0);
+    if (start == MAP_FAILED) {
+      DL_ERR("couldn't reserve %zd bytes of address space for \"%s\"", load_size_, name_);
+      return false;
+    }
+  } else {
+    start = extinfo->reserved_addr;
   }
 
   load_start_ = start;
@@ -314,30 +333,30 @@
 
 bool ElfReader::LoadSegments() {
   for (size_t i = 0; i < phdr_num_; ++i) {
-    const Elf_Phdr* phdr = &phdr_table_[i];
+    const ElfW(Phdr)* phdr = &phdr_table_[i];
 
     if (phdr->p_type != PT_LOAD) {
       continue;
     }
 
     // Segment addresses in memory.
-    Elf_Addr seg_start = phdr->p_vaddr + load_bias_;
-    Elf_Addr seg_end   = seg_start + phdr->p_memsz;
+    ElfW(Addr) seg_start = phdr->p_vaddr + load_bias_;
+    ElfW(Addr) seg_end   = seg_start + phdr->p_memsz;
 
-    Elf_Addr seg_page_start = PAGE_START(seg_start);
-    Elf_Addr seg_page_end   = PAGE_END(seg_end);
+    ElfW(Addr) seg_page_start = PAGE_START(seg_start);
+    ElfW(Addr) seg_page_end   = PAGE_END(seg_end);
 
-    Elf_Addr seg_file_end   = seg_start + phdr->p_filesz;
+    ElfW(Addr) seg_file_end   = seg_start + phdr->p_filesz;
 
     // File offsets.
-    Elf_Addr file_start = phdr->p_offset;
-    Elf_Addr file_end   = file_start + phdr->p_filesz;
+    ElfW(Addr) file_start = phdr->p_offset;
+    ElfW(Addr) file_end   = file_start + phdr->p_filesz;
 
-    Elf_Addr file_page_start = PAGE_START(file_start);
-    Elf_Addr file_length = file_end - file_page_start;
+    ElfW(Addr) file_page_start = PAGE_START(file_start);
+    ElfW(Addr) file_length = file_end - file_page_start;
 
     if (file_length != 0) {
-      void* seg_addr = mmap((void*)seg_page_start,
+      void* seg_addr = mmap(reinterpret_cast<void*>(seg_page_start),
                             file_length,
                             PFLAGS_TO_PROT(phdr->p_flags),
                             MAP_FIXED|MAP_PRIVATE,
@@ -352,7 +371,7 @@
     // if the segment is writable, and does not end on a page boundary,
     // zero-fill it until the page limit.
     if ((phdr->p_flags & PF_W) != 0 && PAGE_OFFSET(seg_file_end) > 0) {
-      memset((void*)seg_file_end, 0, PAGE_SIZE - PAGE_OFFSET(seg_file_end));
+      memset(reinterpret_cast<void*>(seg_file_end), 0, PAGE_SIZE - PAGE_OFFSET(seg_file_end));
     }
 
     seg_file_end = PAGE_END(seg_file_end);
@@ -362,7 +381,7 @@
     // between them. This is done by using a private anonymous
     // map for all extra pages.
     if (seg_page_end > seg_file_end) {
-      void* zeromap = mmap((void*)seg_file_end,
+      void* zeromap = mmap(reinterpret_cast<void*>(seg_file_end),
                            seg_page_end - seg_file_end,
                            PFLAGS_TO_PROT(phdr->p_flags),
                            MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE,
@@ -381,26 +400,27 @@
  * with optional extra flags (i.e. really PROT_WRITE). Used by
  * phdr_table_protect_segments and phdr_table_unprotect_segments.
  */
-static int _phdr_table_set_load_prot(const Elf_Phdr* phdr_table, size_t phdr_count,
-                                     Elf_Addr load_bias, int extra_prot_flags) {
-    const Elf_Phdr* phdr = phdr_table;
-    const Elf_Phdr* phdr_limit = phdr + phdr_count;
+static int _phdr_table_set_load_prot(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                                     ElfW(Addr) load_bias, int extra_prot_flags) {
+  const ElfW(Phdr)* phdr = phdr_table;
+  const ElfW(Phdr)* phdr_limit = phdr + phdr_count;
 
-    for (; phdr < phdr_limit; phdr++) {
-        if (phdr->p_type != PT_LOAD || (phdr->p_flags & PF_W) != 0)
-            continue;
-
-        Elf_Addr seg_page_start = PAGE_START(phdr->p_vaddr) + load_bias;
-        Elf_Addr seg_page_end   = PAGE_END(phdr->p_vaddr + phdr->p_memsz) + load_bias;
-
-        int ret = mprotect((void*)seg_page_start,
-                           seg_page_end - seg_page_start,
-                           PFLAGS_TO_PROT(phdr->p_flags) | extra_prot_flags);
-        if (ret < 0) {
-            return -1;
-        }
+  for (; phdr < phdr_limit; phdr++) {
+    if (phdr->p_type != PT_LOAD || (phdr->p_flags & PF_W) != 0) {
+      continue;
     }
-    return 0;
+
+    ElfW(Addr) seg_page_start = PAGE_START(phdr->p_vaddr) + load_bias;
+    ElfW(Addr) seg_page_end   = PAGE_END(phdr->p_vaddr + phdr->p_memsz) + load_bias;
+
+    int ret = mprotect(reinterpret_cast<void*>(seg_page_start),
+                       seg_page_end - seg_page_start,
+                       PFLAGS_TO_PROT(phdr->p_flags) | extra_prot_flags);
+    if (ret < 0) {
+      return -1;
+    }
+  }
+  return 0;
 }
 
 /* Restore the original protection modes for all loadable segments.
@@ -414,8 +434,8 @@
  * Return:
  *   0 on error, -1 on failure (error code in errno).
  */
-int phdr_table_protect_segments(const Elf_Phdr* phdr_table, size_t phdr_count, Elf_Addr load_bias) {
-    return _phdr_table_set_load_prot(phdr_table, phdr_count, load_bias, 0);
+int phdr_table_protect_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias) {
+  return _phdr_table_set_load_prot(phdr_table, phdr_count, load_bias, 0);
 }
 
 /* Change the protection of all loaded segments in memory to writable.
@@ -434,50 +454,50 @@
  * Return:
  *   0 on error, -1 on failure (error code in errno).
  */
-int phdr_table_unprotect_segments(const Elf_Phdr* phdr_table, size_t phdr_count, Elf_Addr load_bias) {
-    return _phdr_table_set_load_prot(phdr_table, phdr_count, load_bias, PROT_WRITE);
+int phdr_table_unprotect_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias) {
+  return _phdr_table_set_load_prot(phdr_table, phdr_count, load_bias, PROT_WRITE);
 }
 
 /* Used internally by phdr_table_protect_gnu_relro and
  * phdr_table_unprotect_gnu_relro.
  */
-static int _phdr_table_set_gnu_relro_prot(const Elf_Phdr* phdr_table, size_t phdr_count,
-                                          Elf_Addr load_bias, int prot_flags) {
-    const Elf_Phdr* phdr = phdr_table;
-    const Elf_Phdr* phdr_limit = phdr + phdr_count;
+static int _phdr_table_set_gnu_relro_prot(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                                          ElfW(Addr) load_bias, int prot_flags) {
+  const ElfW(Phdr)* phdr = phdr_table;
+  const ElfW(Phdr)* phdr_limit = phdr + phdr_count;
 
-    for (phdr = phdr_table; phdr < phdr_limit; phdr++) {
-        if (phdr->p_type != PT_GNU_RELRO)
-            continue;
-
-        /* Tricky: what happens when the relro segment does not start
-         * or end at page boundaries?. We're going to be over-protective
-         * here and put every page touched by the segment as read-only.
-         *
-         * This seems to match Ian Lance Taylor's description of the
-         * feature at http://www.airs.com/blog/archives/189.
-         *
-         * Extract:
-         *    Note that the current dynamic linker code will only work
-         *    correctly if the PT_GNU_RELRO segment starts on a page
-         *    boundary. This is because the dynamic linker rounds the
-         *    p_vaddr field down to the previous page boundary. If
-         *    there is anything on the page which should not be read-only,
-         *    the program is likely to fail at runtime. So in effect the
-         *    linker must only emit a PT_GNU_RELRO segment if it ensures
-         *    that it starts on a page boundary.
-         */
-        Elf_Addr seg_page_start = PAGE_START(phdr->p_vaddr) + load_bias;
-        Elf_Addr seg_page_end   = PAGE_END(phdr->p_vaddr + phdr->p_memsz) + load_bias;
-
-        int ret = mprotect((void*)seg_page_start,
-                           seg_page_end - seg_page_start,
-                           prot_flags);
-        if (ret < 0) {
-            return -1;
-        }
+  for (phdr = phdr_table; phdr < phdr_limit; phdr++) {
+    if (phdr->p_type != PT_GNU_RELRO) {
+      continue;
     }
-    return 0;
+
+    // Tricky: what happens when the relro segment does not start
+    // or end at page boundaries? We're going to be over-protective
+    // here and put every page touched by the segment as read-only.
+
+    // This seems to match Ian Lance Taylor's description of the
+    // feature at http://www.airs.com/blog/archives/189.
+
+    //    Extract:
+    //       Note that the current dynamic linker code will only work
+    //       correctly if the PT_GNU_RELRO segment starts on a page
+    //       boundary. This is because the dynamic linker rounds the
+    //       p_vaddr field down to the previous page boundary. If
+    //       there is anything on the page which should not be read-only,
+    //       the program is likely to fail at runtime. So in effect the
+    //       linker must only emit a PT_GNU_RELRO segment if it ensures
+    //       that it starts on a page boundary.
+    ElfW(Addr) seg_page_start = PAGE_START(phdr->p_vaddr) + load_bias;
+    ElfW(Addr) seg_page_end   = PAGE_END(phdr->p_vaddr + phdr->p_memsz) + load_bias;
+
+    int ret = mprotect(reinterpret_cast<void*>(seg_page_start),
+                       seg_page_end - seg_page_start,
+                       prot_flags);
+    if (ret < 0) {
+      return -1;
+    }
+  }
+  return 0;
 }
 
 /* Apply GNU relro protection if specified by the program header. This will
@@ -496,10 +516,143 @@
  * Return:
  *   0 on error, -1 on failure (error code in errno).
  */
-int phdr_table_protect_gnu_relro(const Elf_Phdr* phdr_table, size_t phdr_count, Elf_Addr load_bias) {
-    return _phdr_table_set_gnu_relro_prot(phdr_table, phdr_count, load_bias, PROT_READ);
+int phdr_table_protect_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias) {
+  return _phdr_table_set_gnu_relro_prot(phdr_table, phdr_count, load_bias, PROT_READ);
 }
 
+/* Serialize the GNU relro segments to the given file descriptor. This can be
+ * performed after relocations to allow another process to later share the
+ * relocated segment, if it was loaded at the same address.
+ *
+ * Input:
+ *   phdr_table  -> program header table
+ *   phdr_count  -> number of entries in tables
+ *   load_bias   -> load bias
+ *   fd          -> writable file descriptor to use
+ * Return:
+ *   0 on error, -1 on failure (error code in errno).
+ */
+int phdr_table_serialize_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias,
+                                   int fd) {
+  const ElfW(Phdr)* phdr = phdr_table;
+  const ElfW(Phdr)* phdr_limit = phdr + phdr_count;
+  ssize_t file_offset = 0;
+
+  for (phdr = phdr_table; phdr < phdr_limit; phdr++) {
+    if (phdr->p_type != PT_GNU_RELRO) {
+      continue;
+    }
+
+    ElfW(Addr) seg_page_start = PAGE_START(phdr->p_vaddr) + load_bias;
+    ElfW(Addr) seg_page_end   = PAGE_END(phdr->p_vaddr + phdr->p_memsz) + load_bias;
+    ssize_t size = seg_page_end - seg_page_start;
+
+    ssize_t written = TEMP_FAILURE_RETRY(write(fd, reinterpret_cast<void*>(seg_page_start), size));
+    if (written != size) {
+      return -1;
+    }
+    void* map = mmap(reinterpret_cast<void*>(seg_page_start), size, PROT_READ,
+                     MAP_PRIVATE|MAP_FIXED, fd, file_offset);
+    if (map == MAP_FAILED) {
+      return -1;
+    }
+    file_offset += size;
+  }
+  return 0;
+}
+
+/* Where possible, replace the GNU relro segments with mappings of the given
+ * file descriptor. This can be performed after relocations to allow a file
+ * previously created by phdr_table_serialize_gnu_relro in another process to
+ * replace the dirty relocated pages, saving memory, if it was loaded at the
+ * same address. We have to compare the data before we map over it, since some
+ * parts of the relro segment may not be identical due to other libraries in
+ * the process being loaded at different addresses.
+ *
+ * Input:
+ *   phdr_table  -> program header table
+ *   phdr_count  -> number of entries in tables
+ *   load_bias   -> load bias
+ *   fd          -> readable file descriptor to use
+ * Return:
+ *   0 on error, -1 on failure (error code in errno).
+ */
+int phdr_table_map_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias,
+                             int fd) {
+  // Map the file at a temporary location so we can compare its contents.
+  struct stat file_stat;
+  if (TEMP_FAILURE_RETRY(fstat(fd, &file_stat)) != 0) {
+    return -1;
+  }
+  off_t file_size = file_stat.st_size;
+  void* temp_mapping = NULL;
+  if (file_size > 0) {
+    temp_mapping = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
+    if (temp_mapping == MAP_FAILED) {
+      return -1;
+    }
+  }
+  size_t file_offset = 0;
+
+  // Iterate over the relro segments and compare/remap the pages.
+  const ElfW(Phdr)* phdr = phdr_table;
+  const ElfW(Phdr)* phdr_limit = phdr + phdr_count;
+
+  for (phdr = phdr_table; phdr < phdr_limit; phdr++) {
+    if (phdr->p_type != PT_GNU_RELRO) {
+      continue;
+    }
+
+    ElfW(Addr) seg_page_start = PAGE_START(phdr->p_vaddr) + load_bias;
+    ElfW(Addr) seg_page_end   = PAGE_END(phdr->p_vaddr + phdr->p_memsz) + load_bias;
+
+    char* file_base = static_cast<char*>(temp_mapping) + file_offset;
+    char* mem_base = reinterpret_cast<char*>(seg_page_start);
+    size_t match_offset = 0;
+    size_t size = seg_page_end - seg_page_start;
+
+    if (file_size - file_offset < size) {
+      // File is too short to compare to this segment. The contents are likely
+      // different as well (it's probably for a different library version) so
+      // just don't bother checking.
+      break;
+    }
+
+    while (match_offset < size) {
+      // Skip over dissimilar pages.
+      while (match_offset < size &&
+             memcmp(mem_base + match_offset, file_base + match_offset, PAGE_SIZE) != 0) {
+        match_offset += PAGE_SIZE;
+      }
+
+      // Count similar pages.
+      size_t mismatch_offset = match_offset;
+      while (mismatch_offset < size &&
+             memcmp(mem_base + mismatch_offset, file_base + mismatch_offset, PAGE_SIZE) == 0) {
+        mismatch_offset += PAGE_SIZE;
+      }
+
+      // Map over similar pages.
+      if (mismatch_offset > match_offset) {
+        void* map = mmap(mem_base + match_offset, mismatch_offset - match_offset,
+                         PROT_READ, MAP_PRIVATE|MAP_FIXED, fd, match_offset);
+        if (map == MAP_FAILED) {
+          munmap(temp_mapping, file_size);
+          return -1;
+        }
+      }
+
+      match_offset = mismatch_offset;
+    }
+
+    // Add to the base file offset in case there are multiple relro segments.
+    file_offset += size;
+  }
+  munmap(temp_mapping, file_size);
+  return 0;
+}
+
+
 #if defined(__arm__)
 
 #  ifndef PT_ARM_EXIDX
@@ -519,23 +672,24 @@
  * Return:
  *   0 on error, -1 on failure (_no_ error code in errno)
  */
-int phdr_table_get_arm_exidx(const Elf_Phdr* phdr_table, size_t phdr_count,
-                             Elf_Addr load_bias,
-                             Elf_Addr** arm_exidx, unsigned* arm_exidx_count) {
-    const Elf_Phdr* phdr = phdr_table;
-    const Elf_Phdr* phdr_limit = phdr + phdr_count;
+int phdr_table_get_arm_exidx(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                             ElfW(Addr) load_bias,
+                             ElfW(Addr)** arm_exidx, unsigned* arm_exidx_count) {
+  const ElfW(Phdr)* phdr = phdr_table;
+  const ElfW(Phdr)* phdr_limit = phdr + phdr_count;
 
-    for (phdr = phdr_table; phdr < phdr_limit; phdr++) {
-        if (phdr->p_type != PT_ARM_EXIDX)
-            continue;
-
-        *arm_exidx = (Elf_Addr*)(load_bias + phdr->p_vaddr);
-        *arm_exidx_count = (unsigned)(phdr->p_memsz / 8);
-        return 0;
+  for (phdr = phdr_table; phdr < phdr_limit; phdr++) {
+    if (phdr->p_type != PT_ARM_EXIDX) {
+      continue;
     }
-    *arm_exidx = NULL;
-    *arm_exidx_count = 0;
-    return -1;
+
+    *arm_exidx = reinterpret_cast<ElfW(Addr)*>(load_bias + phdr->p_vaddr);
+    *arm_exidx_count = (unsigned)(phdr->p_memsz / 8);
+    return 0;
+  }
+  *arm_exidx = NULL;
+  *arm_exidx_count = 0;
+  return -1;
 }
 #endif
 
@@ -553,40 +707,40 @@
  * Return:
  *   void
  */
-void phdr_table_get_dynamic_section(const Elf_Phdr* phdr_table, size_t phdr_count,
-                                    Elf_Addr load_bias,
-                                    Elf_Dyn** dynamic, size_t* dynamic_count, Elf_Word* dynamic_flags) {
-    const Elf_Phdr* phdr = phdr_table;
-    const Elf_Phdr* phdr_limit = phdr + phdr_count;
+void phdr_table_get_dynamic_section(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                                    ElfW(Addr) load_bias,
+                                    ElfW(Dyn)** dynamic, size_t* dynamic_count, ElfW(Word)* dynamic_flags) {
+  const ElfW(Phdr)* phdr = phdr_table;
+  const ElfW(Phdr)* phdr_limit = phdr + phdr_count;
 
-    for (phdr = phdr_table; phdr < phdr_limit; phdr++) {
-        if (phdr->p_type != PT_DYNAMIC) {
-            continue;
-        }
-
-        *dynamic = reinterpret_cast<Elf_Dyn*>(load_bias + phdr->p_vaddr);
-        if (dynamic_count) {
-            *dynamic_count = (unsigned)(phdr->p_memsz / 8);
-        }
-        if (dynamic_flags) {
-            *dynamic_flags = phdr->p_flags;
-        }
-        return;
+  for (phdr = phdr_table; phdr < phdr_limit; phdr++) {
+    if (phdr->p_type != PT_DYNAMIC) {
+      continue;
     }
-    *dynamic = NULL;
+
+    *dynamic = reinterpret_cast<ElfW(Dyn)*>(load_bias + phdr->p_vaddr);
     if (dynamic_count) {
-        *dynamic_count = 0;
+      *dynamic_count = (unsigned)(phdr->p_memsz / 8);
     }
+    if (dynamic_flags) {
+      *dynamic_flags = phdr->p_flags;
+    }
+    return;
+  }
+  *dynamic = NULL;
+  if (dynamic_count) {
+    *dynamic_count = 0;
+  }
 }
 
 // Returns the address of the program header table as it appears in the loaded
 // segments in memory. This is in contrast with 'phdr_table_' which
 // is temporary and will be released before the library is relocated.
 bool ElfReader::FindPhdr() {
-  const Elf_Phdr* phdr_limit = phdr_table_ + phdr_num_;
+  const ElfW(Phdr)* phdr_limit = phdr_table_ + phdr_num_;
 
   // If there is a PT_PHDR, use it directly.
-  for (const Elf_Phdr* phdr = phdr_table_; phdr < phdr_limit; ++phdr) {
+  for (const ElfW(Phdr)* phdr = phdr_table_; phdr < phdr_limit; ++phdr) {
     if (phdr->p_type == PT_PHDR) {
       return CheckPhdr(load_bias_ + phdr->p_vaddr);
     }
@@ -595,13 +749,13 @@
   // Otherwise, check the first loadable segment. If its file offset
   // is 0, it starts with the ELF header, and we can trivially find the
   // loaded program header from it.
-  for (const Elf_Phdr* phdr = phdr_table_; phdr < phdr_limit; ++phdr) {
+  for (const ElfW(Phdr)* phdr = phdr_table_; phdr < phdr_limit; ++phdr) {
     if (phdr->p_type == PT_LOAD) {
       if (phdr->p_offset == 0) {
-        Elf_Addr  elf_addr = load_bias_ + phdr->p_vaddr;
-        const Elf_Ehdr* ehdr = (const Elf_Ehdr*)(void*)elf_addr;
-        Elf_Addr  offset = ehdr->e_phoff;
-        return CheckPhdr((Elf_Addr)ehdr + offset);
+        ElfW(Addr)  elf_addr = load_bias_ + phdr->p_vaddr;
+        const ElfW(Ehdr)* ehdr = reinterpret_cast<const ElfW(Ehdr)*>(elf_addr);
+        ElfW(Addr)  offset = ehdr->e_phoff;
+        return CheckPhdr((ElfW(Addr))ehdr + offset);
       }
       break;
     }
@@ -614,17 +768,17 @@
 // Ensures that our program header is actually within a loadable
 // segment. This should help catch badly-formed ELF files that
 // would cause the linker to crash later when trying to access it.
-bool ElfReader::CheckPhdr(Elf_Addr loaded) {
-  const Elf_Phdr* phdr_limit = phdr_table_ + phdr_num_;
-  Elf_Addr loaded_end = loaded + (phdr_num_ * sizeof(Elf_Phdr));
-  for (Elf_Phdr* phdr = phdr_table_; phdr < phdr_limit; ++phdr) {
+bool ElfReader::CheckPhdr(ElfW(Addr) loaded) {
+  const ElfW(Phdr)* phdr_limit = phdr_table_ + phdr_num_;
+  ElfW(Addr) loaded_end = loaded + (phdr_num_ * sizeof(ElfW(Phdr)));
+  for (ElfW(Phdr)* phdr = phdr_table_; phdr < phdr_limit; ++phdr) {
     if (phdr->p_type != PT_LOAD) {
       continue;
     }
-    Elf_Addr seg_start = phdr->p_vaddr + load_bias_;
-    Elf_Addr seg_end = phdr->p_filesz + seg_start;
+    ElfW(Addr) seg_start = phdr->p_vaddr + load_bias_;
+    ElfW(Addr) seg_end = phdr->p_filesz + seg_start;
     if (seg_start <= loaded && loaded_end <= seg_end) {
-      loaded_phdr_ = reinterpret_cast<const Elf_Phdr*>(loaded);
+      loaded_phdr_ = reinterpret_cast<const ElfW(Phdr)*>(loaded);
       return true;
     }
   }
diff --git a/linker/linker_phdr.h b/linker/linker_phdr.h
index db15ac9..611f1a7 100644
--- a/linker/linker_phdr.h
+++ b/linker/linker_phdr.h
@@ -42,61 +42,66 @@
   ElfReader(const char* name, int fd);
   ~ElfReader();
 
-  bool Load();
+  bool Load(const android_dlextinfo* extinfo);
 
   size_t phdr_count() { return phdr_num_; }
-  Elf_Addr load_start() { return reinterpret_cast<Elf_Addr>(load_start_); }
+  ElfW(Addr) load_start() { return reinterpret_cast<ElfW(Addr)>(load_start_); }
   size_t load_size() { return load_size_; }
-  Elf_Addr load_bias() { return load_bias_; }
-  const Elf_Phdr* loaded_phdr() { return loaded_phdr_; }
+  ElfW(Addr) load_bias() { return load_bias_; }
+  const ElfW(Phdr)* loaded_phdr() { return loaded_phdr_; }
 
  private:
   bool ReadElfHeader();
   bool VerifyElfHeader();
   bool ReadProgramHeader();
-  bool ReserveAddressSpace();
+  bool ReserveAddressSpace(const android_dlextinfo* extinfo);
   bool LoadSegments();
   bool FindPhdr();
-  bool CheckPhdr(Elf_Addr);
+  bool CheckPhdr(ElfW(Addr));
 
   const char* name_;
   int fd_;
 
-  Elf_Ehdr header_;
+  ElfW(Ehdr) header_;
   size_t phdr_num_;
 
   void* phdr_mmap_;
-  Elf_Phdr* phdr_table_;
-  Elf_Addr phdr_size_;
+  ElfW(Phdr)* phdr_table_;
+  ElfW(Addr) phdr_size_;
 
   // First page of reserved address space.
   void* load_start_;
   // Size in bytes of reserved address space.
   size_t load_size_;
   // Load bias.
-  Elf_Addr load_bias_;
+  ElfW(Addr) load_bias_;
 
   // Loaded phdr.
-  const Elf_Phdr* loaded_phdr_;
+  const ElfW(Phdr)* loaded_phdr_;
 };
 
-size_t phdr_table_get_load_size(const Elf_Phdr* phdr_table, size_t phdr_count,
-                                Elf_Addr* min_vaddr = NULL, Elf_Addr* max_vaddr = NULL);
+size_t phdr_table_get_load_size(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                                ElfW(Addr)* min_vaddr = NULL, ElfW(Addr)* max_vaddr = NULL);
 
-int phdr_table_protect_segments(const Elf_Phdr* phdr_table, size_t phdr_count, Elf_Addr load_bias);
+int phdr_table_protect_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias);
 
-int phdr_table_unprotect_segments(const Elf_Phdr* phdr_table, size_t phdr_count, Elf_Addr load_bias);
+int phdr_table_unprotect_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias);
 
-int phdr_table_protect_gnu_relro(const Elf_Phdr* phdr_table, size_t phdr_count, Elf_Addr load_bias);
+int phdr_table_protect_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias);
 
+int phdr_table_serialize_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias,
+                                   int fd);
+
+int phdr_table_map_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias,
+                             int fd);
 
 #if defined(__arm__)
-int phdr_table_get_arm_exidx(const Elf_Phdr* phdr_table, size_t phdr_count, Elf_Addr load_bias,
-                             Elf_Addr** arm_exidx, unsigned* arm_exidix_count);
+int phdr_table_get_arm_exidx(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias,
+                             ElfW(Addr)** arm_exidx, unsigned* arm_exidix_count);
 #endif
 
-void phdr_table_get_dynamic_section(const Elf_Phdr* phdr_table, size_t phdr_count,
-                                    Elf_Addr load_bias,
-                                    Elf_Dyn** dynamic, size_t* dynamic_count, Elf_Word* dynamic_flags);
+void phdr_table_get_dynamic_section(const ElfW(Phdr)* phdr_table, size_t phdr_count,
+                                    ElfW(Addr) load_bias,
+                                    ElfW(Dyn)** dynamic, size_t* dynamic_count, ElfW(Word)* dynamic_flags);
 
 #endif /* LINKER_PHDR_H */
diff --git a/linker/tests/Android.mk b/linker/tests/Android.mk
new file mode 100644
index 0000000..fe64e77
--- /dev/null
+++ b/linker/tests/Android.mk
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+ifneq ($(BUILD_TINY_ANDROID),true)
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := linker-unit-tests
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
+
+LOCAL_CFLAGS += -g -Wall -Wextra -Wunused -Werror -std=gnu++11
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../libc/
+
+LOCAL_SRC_FILES := \
+  linked_list_test.cpp \
+  linker_allocator_test.cpp \
+  ../linker_allocator.cpp
+
+include $(BUILD_NATIVE_TEST)
+
+endif # !BUILD_TINY_ANDROID
diff --git a/linker/tests/linked_list_test.cpp b/linker/tests/linked_list_test.cpp
new file mode 100644
index 0000000..b9816fa
--- /dev/null
+++ b/linker/tests/linked_list_test.cpp
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <string>
+#include <sstream>
+
+#include <gtest/gtest.h>
+
+#include "../linked_list.h"
+
+namespace {
+
+bool alloc_called = false;
+bool free_called = false;
+
+class LinkedListTestAllocator {
+ public:
+  typedef LinkedListEntry<const char> entry_t;
+
+  static entry_t* alloc() {
+    alloc_called = true;
+    return reinterpret_cast<entry_t*>(::malloc(sizeof(entry_t)));
+  }
+
+  static void free(entry_t* p) {
+    free_called = true;
+    ::free(p);
+  }
+ private:
+  DISALLOW_IMPLICIT_CONSTRUCTORS(LinkedListTestAllocator);
+};
+
+typedef LinkedList<const char, LinkedListTestAllocator> test_list_t;
+
+std::string test_list_to_string(test_list_t& list) {
+  std::stringstream ss;
+  list.for_each([&] (const char* c) {
+    ss << c;
+  });
+
+  return ss.str();
+}
+
+};
+
+TEST(linked_list, simple) {
+  alloc_called = free_called = false;
+  test_list_t list;
+  ASSERT_EQ("", test_list_to_string(list));
+  ASSERT_TRUE(!alloc_called);
+  ASSERT_TRUE(!free_called);
+  list.push_front("a");
+  ASSERT_TRUE(alloc_called);
+  ASSERT_TRUE(!free_called);
+  ASSERT_EQ("a", test_list_to_string(list));
+  list.push_front("b");
+  ASSERT_EQ("ba", test_list_to_string(list));
+  list.push_front("c");
+  list.push_front("d");
+  ASSERT_EQ("dcba", test_list_to_string(list));
+  ASSERT_TRUE(alloc_called);
+  ASSERT_TRUE(!free_called);
+  alloc_called = free_called = false;
+  list.remove_if([] (const char* c) {
+    return *c == 'c';
+  });
+
+  ASSERT_TRUE(!alloc_called);
+  ASSERT_TRUE(!free_called);
+
+  ASSERT_EQ("dba", test_list_to_string(list));
+  alloc_called = free_called = false;
+  list.remove_if([] (const char* c) {
+    return *c == '2';
+  });
+  ASSERT_TRUE(!alloc_called);
+  ASSERT_TRUE(!free_called);
+  ASSERT_EQ("dba", test_list_to_string(list));
+  list.clear();
+  ASSERT_TRUE(!alloc_called);
+  ASSERT_TRUE(free_called);
+  ASSERT_EQ("", test_list_to_string(list));
+}
+
+TEST(linked_list, push_pop) {
+  test_list_t list;
+  list.push_front("b");
+  list.push_front("a");
+  ASSERT_EQ("ab", test_list_to_string(list));
+  list.push_back("c");
+  ASSERT_EQ("abc", test_list_to_string(list));
+  ASSERT_EQ("a", list.pop_front());
+  ASSERT_EQ("bc", test_list_to_string(list));
+  ASSERT_EQ("b", list.pop_front());
+  ASSERT_EQ("c", test_list_to_string(list));
+  ASSERT_EQ("c", list.pop_front());
+  ASSERT_EQ("", test_list_to_string(list));
+  ASSERT_TRUE(list.pop_front() == nullptr);
+  list.push_back("r");
+  ASSERT_EQ("r", test_list_to_string(list));
+  ASSERT_EQ("r", list.pop_front());
+  ASSERT_TRUE(list.pop_front() == nullptr);
+}
diff --git a/linker/tests/linker_allocator_test.cpp b/linker/tests/linker_allocator_test.cpp
new file mode 100644
index 0000000..9292a05
--- /dev/null
+++ b/linker/tests/linker_allocator_test.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+
+#include <gtest/gtest.h>
+
+#include "../linker_allocator.h"
+
+#include <unistd.h>
+
+namespace {
+
+struct test_struct_nominal {
+  void* pointer;
+  ssize_t value;
+};
+
+/*
+ * this one has size below allocator cap which is 2*sizeof(void*)
+ */
+struct test_struct_small {
+  char dummy_str[5];
+};
+
+/*
+ * 1009 byte struct (1009 is prime)
+ */
+struct test_struct_larger {
+  char dummy_str[1009];
+};
+
+static size_t kPageSize = sysconf(_SC_PAGE_SIZE);
+};
+
+TEST(linker_allocator, test_nominal) {
+  LinkerAllocator<test_struct_nominal> allocator;
+
+  test_struct_nominal* ptr1 = allocator.alloc();
+  ASSERT_TRUE(ptr1 != nullptr);
+  test_struct_nominal* ptr2 = allocator.alloc();
+  ASSERT_TRUE(ptr2 != nullptr);
+  // they should be next to each other.
+  ASSERT_EQ(ptr1+1, ptr2);
+
+  ptr1->value = 42;
+
+  allocator.free(ptr1);
+  allocator.free(ptr2);
+}
+
+TEST(linker_allocator, test_small) {
+  LinkerAllocator<test_struct_small> allocator;
+
+  char* ptr1 = reinterpret_cast<char*>(allocator.alloc());
+  char* ptr2 = reinterpret_cast<char*>(allocator.alloc());
+
+  ASSERT_TRUE(ptr1 != nullptr);
+  ASSERT_TRUE(ptr2 != nullptr);
+  ASSERT_EQ(ptr1+2*sizeof(void*), ptr2);
+}
+
+TEST(linker_allocator, test_larger) {
+  LinkerAllocator<test_struct_larger> allocator;
+
+  test_struct_larger* ptr1 = allocator.alloc();
+  test_struct_larger* ptr2 = allocator.alloc();
+
+  ASSERT_TRUE(ptr1 != nullptr);
+  ASSERT_TRUE(ptr2 != nullptr);
+
+  ASSERT_EQ(ptr1+1, ptr2);
+
+  // lets allocate until we reach next page.
+  size_t n = kPageSize/sizeof(test_struct_larger) + 1 - 2;
+
+  for (size_t i=0; i<n; ++i) {
+    ASSERT_TRUE(allocator.alloc() != nullptr);
+  }
+
+  test_struct_larger* ptr_to_free = allocator.alloc();
+  ASSERT_TRUE(ptr_to_free != nullptr);
+  allocator.free(ptr1);
+}
+
+static void protect_all() {
+  LinkerAllocator<test_struct_larger> allocator;
+
+  // number of allocs to reach the end of first page
+  size_t n = kPageSize/sizeof(test_struct_larger) - 1;
+  test_struct_larger* page1_ptr = allocator.alloc();
+
+  for (size_t i=0; i<n; ++i) {
+    allocator.alloc();
+  }
+
+  test_struct_larger* page2_ptr = allocator.alloc();
+  allocator.protect_all(PROT_READ);
+  allocator.protect_all(PROT_READ | PROT_WRITE);
+  // check access
+  page2_ptr->dummy_str[23] = 27;
+  page1_ptr->dummy_str[13] = 11;
+
+  allocator.protect_all(PROT_READ);
+  fprintf(stderr, "trying to access protected page");
+
+  // this should result in segmentation fault
+  page1_ptr->dummy_str[11] = 7;
+}
+
+TEST(linker_allocator, test_protect) {
+  testing::FLAGS_gtest_death_test_style = "threadsafe";
+  ASSERT_EXIT(protect_all(), testing::KilledBySignal(SIGSEGV), "trying to access protected page");
+}
+
diff --git a/tests/Android.build.mk b/tests/Android.build.mk
new file mode 100644
index 0000000..d4b0396
--- /dev/null
+++ b/tests/Android.build.mk
@@ -0,0 +1,95 @@
+#
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := $(module)
+LOCAL_MODULE_TAGS := $(module_tag)
+ifeq ($(build_type),host)
+# Always make host multilib
+LOCAL_MULTILIB := both
+endif
+
+ifneq ($(findstring LIBRARY, $(build_target)),LIBRARY)
+    LOCAL_MODULE_STEM_32 := $(module)32
+    LOCAL_MODULE_STEM_64 := $(module)64
+else
+ifeq ($($(module)_install_to_out_data),true)
+    LOCAL_MODULE_PATH_32 := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_NATIVE_TESTS)/$(module)
+    LOCAL_MODULE_PATH_64 := $(TARGET_OUT_DATA_NATIVE_TESTS)/$(module)
+endif
+endif
+
+LOCAL_CLANG := $($(module)_clang_$(build_type))
+
+LOCAL_FORCE_STATIC_EXECUTABLE := $($(module)_force_static_executable)
+
+LOCAL_CFLAGS := \
+    $(common_cflags) \
+    $($(module)_cflags) \
+    $($(module)_cflags_$(build_type)) \
+
+LOCAL_CONLYFLAGS += \
+    $(common_conlyflags) \
+    $($(module)_conlyflags) \
+    $($(module)_conlyflags_$(build_type)) \
+
+LOCAL_CPPFLAGS += \
+    $(common_cppflags) \
+    $($(module)_cppflags) \
+    $($(module)_cppflags_$(build_type)) \
+
+LOCAL_C_INCLUDES := \
+    $(common_c_includes) \
+    $($(module)_c_includes) \
+    $($(module)_c_includes_$(build_type)) \
+
+LOCAL_SRC_FILES := \
+    $($(module)_src_files) \
+    $($(module)_src_files_$(build_type)) \
+
+LOCAL_STATIC_LIBRARIES := \
+    $($(module)_static_libraries) \
+    $($(module)_static_libraries_$(build_type)) \
+
+LOCAL_SHARED_LIBRARIES := \
+    $($(module)_shared_libraries) \
+    $($(module)_shared_libraries_$(build_type)) \
+
+LOCAL_WHOLE_STATIC_LIBRARIES := \
+    $($(module)_whole_static_libraries) \
+    $($(module)_whole_static_libraries_$(build_type)) \
+
+LOCAL_LDFLAGS := \
+    $($(module)_ldflags) \
+    $($(module)_ldflags_$(build_type)) \
+
+LOCAL_LDLIBS := \
+    $($(module)_ldlibs) \
+    $($(module)_ldlibs_$(build_type)) \
+
+ifeq ($(build_type),target)
+  include external/stlport/libstlport.mk
+
+  include $(BUILD_$(build_target))
+endif
+
+ifeq ($(build_type),host)
+  # Only build if host builds are supported.
+  ifeq ($(build_host),true)
+    include $(BUILD_HOST_$(build_target))
+  endif
+endif
diff --git a/tests/Android.mk b/tests/Android.mk
index ee22c35..8184bf7 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -22,182 +22,326 @@
 # Unit tests.
 # -----------------------------------------------------------------------------
 
-test_c_flags = \
+ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
+build_host := true
+else
+build_host := false
+endif
+
+# -----------------------------------------------------------------------------
+# All standard tests.
+# -----------------------------------------------------------------------------
+test_cflags = \
     -fstack-protector-all \
     -g \
-    -Wall -Wextra \
+    -Wall -Wextra -Wunused \
     -Werror \
     -fno-builtin \
 
-ifeq ($(TARGET_ARCH),arm64)
-  $(info TODO: $(LOCAL_PATH)/Android.mk -fstack-protector not yet available for the AArch64 toolchain)
-  test_c_flags += -fno-stack-protector
-endif # arm64
+test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
 
-test_src_files = \
+ifeq ($(MALLOC_IMPL),dlmalloc)
+test_cflags += -DUSE_DLMALLOC
+else
+test_cflags += -DUSE_JEMALLOC
+endif
+
+test_cppflags = \
+    -std=gnu++11 \
+
+libBionicStandardTests_src_files := \
+    arpa_inet_test.cpp \
     buffer_tests.cpp \
+    ctype_test.cpp \
     dirent_test.cpp \
     eventfd_test.cpp \
     fcntl_test.cpp \
     fenv_test.cpp \
+    ftw_test.cpp \
     getauxval_test.cpp \
     getcwd_test.cpp \
     inttypes_test.cpp \
     libc_logging_test.cpp \
     libgen_test.cpp \
+    locale_test.cpp \
     malloc_test.cpp \
+    math_cos_test.cpp \
+    math_cosf_test.cpp \
+    math_exp_test.cpp \
+    math_expf_test.cpp \
+    math_log_test.cpp \
+    math_logf_test.cpp \
+    math_pow_test.cpp \
+    math_powf_test.cpp \
+    math_sin_test.cpp \
+    math_sinf_test.cpp \
+    math_sincos_test.cpp \
+    math_sincosf_test.cpp \
+    math_tan_test.cpp \
+    math_tanf_test.cpp \
     math_test.cpp \
+    mntent_test.cpp \
     netdb_test.cpp \
     pthread_test.cpp \
     regex_test.cpp \
     sched_test.cpp \
+    search_test.cpp \
     signal_test.cpp \
     stack_protector_test.cpp \
     stack_unwinding_test.cpp \
-    statvfs_test.cpp \
+    stdatomic_test.cpp \
+    stdint_test.cpp \
     stdio_test.cpp \
     stdlib_test.cpp \
     string_test.cpp \
     strings_test.cpp \
     stubs_test.cpp \
+    sstream_test.cpp \
     sys_epoll_test.cpp \
     sys_mman_test.cpp \
     sys_resource_test.cpp \
     sys_select_test.cpp \
     sys_sendfile_test.cpp \
+    sys_socket_test.cpp \
     sys_stat_test.cpp \
+    sys_statvfs_test.cpp \
     sys_syscall_test.cpp \
     sys_time_test.cpp \
     sys_types_test.cpp \
+    sys_vfs_test.cpp \
     system_properties_test.cpp \
     time_test.cpp \
+    uchar_test.cpp \
     unistd_test.cpp \
+    wchar_test.cpp \
 
-test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction
-test_dynamic_src_files = \
-    dlfcn_test.cpp \
+libBionicStandardTests_cflags := \
+    $(test_cflags) \
 
-test_fortify_static_libraries = \
-    fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := bionic-unit-tests-unwind-test-impl
-LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
-LOCAL_SRC_FILES := stack_unwinding_test_impl.c
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host
-LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
-LOCAL_SRC_FILES := stack_unwinding_test_impl.c
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-# Build tests for the device (with bionic's .so). Run with:
-#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
-include $(CLEAR_VARS)
-LOCAL_MODULE := bionic-unit-tests
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_CFLAGS += $(test_c_flags)
-LOCAL_LDFLAGS += $(test_dynamic_ldflags)
-LOCAL_SHARED_LIBRARIES += libdl
-LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
-LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries)
-LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl
-include $(BUILD_NATIVE_TEST)
-
-# Build tests for the device (with bionic's .a). Run with:
-#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
-include $(CLEAR_VARS)
-LOCAL_MODULE := bionic-unit-tests-static
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_FORCE_STATIC_EXECUTABLE := true
-LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests
-LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc
-include $(BUILD_NATIVE_TEST)
-
-# -----------------------------------------------------------------------------
-# We build the static unit tests as a library so they can be used both for
-# bionic-unit-tests-static and also as part of CTS.
-# -----------------------------------------------------------------------------
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libBionicTests
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_CFLAGS += $(test_c_flags)
-LOCAL_SRC_FILES := $(test_src_files)
-LOCAL_CFLAGS += \
-    -DGTEST_OS_LINUX_ANDROID \
-    -DGTEST_HAS_STD_STRING \
-
-LOCAL_C_INCLUDES += \
-    bionic bionic/libstdc++/include \
-    external/gtest/include \
-    external/stlport/stlport \
-
-LOCAL_WHOLE_STATIC_LIBRARIES := \
-    $(test_fortify_static_libraries) \
-    bionic-unit-tests-unwind-test-impl \
-
-include $(BUILD_STATIC_LIBRARY)
-
-# -----------------------------------------------------------------------------
-# Test library for the unit tests.
-# -----------------------------------------------------------------------------
-
-# Build no-elf-hash-table-library.so to test dlopen(3) on a library that
-# only has a GNU-style hash table. MIPS doesn't support GNU hash style.
-ifneq ($(TARGET_ARCH),mips)
-include $(CLEAR_VARS)
-LOCAL_MODULE := no-elf-hash-table-library
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_SRC_FILES := empty.cpp
-LOCAL_LDFLAGS := -Wl,--hash-style=gnu
-include $(BUILD_SHARED_LIBRARY)
+ifeq ($(MALLOC_IMPL),dlmalloc)
+  libBionicStandardTests_cflags += -DUSE_DLMALLOC
+else
+  libBionicStandardTests_cflags += -DUSE_JEMALLOC
 endif
 
+libBionicStandardTests_cppflags := \
+    $(test_cppflags) \
+
+libBionicStandardTests_c_includes := \
+    bionic/libc \
+
+libBionicStandardTests_ldlibs_host := \
+    -lrt \
+
+libBionicStandardTests_whole_static_libraries := \
+    libBionicUnwindTest \
+
+module := libBionicStandardTests
+module_tag := optional
+build_type := target
+build_target := STATIC_TEST_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
 # -----------------------------------------------------------------------------
-# Unit tests built against glibc.
+# Special stack unwinding test library compiled with special flags.
+# -----------------------------------------------------------------------------
+libBionicUnwindTest_cflags := \
+    $(test_cflags) \
+    -fexceptions \
+    -fnon-call-exceptions \
+
+libBionicUnwindTest_src_files := \
+    stack_unwinding_test_impl.c \
+
+module := libBionicUnwindTest
+module_tag := optional
+build_type := target
+build_target := STATIC_TEST_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Fortify tests.
+# -----------------------------------------------------------------------------
+$(foreach compiler,gcc clang, \
+  $(foreach test,1 2, \
+    $(eval fortify$(test)-tests-$(compiler)_cflags := \
+      $(test_cflags) \
+      -U_FORTIFY_SOURCE \
+      -D_FORTIFY_SOURCE=$(test) \
+      -DTEST_NAME=Fortify$(test)_$(compiler)); \
+    $(eval fortify$(test)-tests-$(compiler)_cflags_host := \
+      -Wno-error); \
+    $(eval fortify$(test)-tests-$(compiler)_src_files := \
+      fortify_test.cpp); \
+    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
+  ) \
+)
+
+module := fortify1-tests-gcc
+module_tag := optional
+build_type := target
+build_target := STATIC_TEST_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
+module := fortify2-tests-gcc
+module_tag := optional
+build_type := target
+build_target := STATIC_TEST_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
+fortify1-tests-clang_clang_target := true
+fortify1-tests-clang_cflags_host := -D__clang__
+
+module := fortify1-tests-clang
+module_tag := optional
+build_type := target
+build_target := STATIC_TEST_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
+fortify2-tests-clang_clang_target := true
+
+fortify2-tests-clang_cflags_host := -D__clang__
+
+module := fortify2-tests-clang
+module_tag := optional
+build_type := target
+build_target := STATIC_TEST_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library of all tests (excluding the dynamic linker tests).
+# -----------------------------------------------------------------------------
+libBionicTests_whole_static_libraries := \
+    libBionicStandardTests \
+    $(fortify_libs) \
+
+module := libBionicTests
+module_tag := optional
+build_type := target
+build_target := STATIC_TEST_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Tests for the device using bionic's .so. Run with:
+#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
+#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
+# -----------------------------------------------------------------------------
+bionic-unit-tests_whole_static_libraries := \
+    libBionicTests \
+
+bionic-unit-tests_src_files := \
+    atexit_test.cpp \
+    dlext_test.cpp \
+    dlfcn_test.cpp \
+
+bionic-unit-tests_cflags := $(test_cflags)
+bionic-unit-tests_cppflags := $(test_cppflags)
+
+bionic-unit-tests_ldflags := \
+    -Wl,--export-dynamic \
+    -Wl,-u,DlSymTestFunction \
+
+bionic-unit-tests_c_includes := \
+    $(call include-path-for, libpagemap) \
+
+bionic-unit-tests_shared_libraries_target := \
+    libdl \
+    libpagemap \
+
+module := bionic-unit-tests
+module_tag := optional
+build_type := target
+build_target := NATIVE_TEST
+include $(LOCAL_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Tests for the device linked against bionic's static library. Run with:
+#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
+#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
+# -----------------------------------------------------------------------------
+bionic-unit-tests-static_whole_static_libraries := \
+    libBionicTests \
+
+bionic-unit-tests-static_static_libraries := \
+    libstlport_static \
+    libm \
+    libc \
+    libstdc++ \
+
+bionic-unit-tests-static_force_static_executable := true
+
+module := bionic-unit-tests-static
+module_tag := optional
+build_type := target
+build_target := NATIVE_TEST
+include $(LOCAL_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Tests to run on the host and linked against glibc. Run with:
+#   cd bionic/tests; mm bionic-unit-tests-glibc-run
 # -----------------------------------------------------------------------------
 
-# Build tests for the host (with glibc).
-# Note that this will build against glibc, so it's not useful for testing
-# bionic's implementation, but it does let you use glibc as a reference
-# implementation for testing the tests themselves.
-ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
-include $(CLEAR_VARS)
-LOCAL_MODULE := bionic-unit-tests-glibc
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_CFLAGS += $(test_c_flags)
-LOCAL_LDFLAGS += -lpthread -ldl -lrt
-LOCAL_LDFLAGS += $(test_dynamic_ldflags)
-LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
-LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host
-include $(BUILD_HOST_NATIVE_TEST)
+ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
+
+bionic-unit-tests-glibc_src_files := \
+    atexit_test.cpp \
+
+bionic-unit-tests-glibc_whole_static_libraries := \
+    libBionicStandardTests \
+
+bionic-unit-tests-glibc_ldlibs := \
+    -lrt -ldl \
+
+bionic-unit-tests-glibc_cflags := $(test_cflags)
+bionic-unit-tests-glibc_cppflags := $(test_cppflags)
+
+module := bionic-unit-tests-glibc
+module_tag := optional
+build_type := host
+build_target := NATIVE_TEST
+include $(LOCAL_PATH)/Android.build.mk
+
+ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
+LINKER = linker64
+NATIVE_TEST_SUFFIX=64
+else
+LINKER = linker
+NATIVE_TEST_SUFFIX=32
+endif
 
 # gtest needs ANDROID_DATA/local/tmp for death test output.
 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
 # Use the current target out directory as ANDROID_DATA.
+# BIONIC_TEST_FLAGS is either empty or it comes from the user.
 bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
 	mkdir -p $(TARGET_OUT_DATA)/local/tmp
 	ANDROID_DATA=$(TARGET_OUT_DATA) \
 	ANDROID_ROOT=$(TARGET_OUT) \
-		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc
-endif
+		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
 
 # -----------------------------------------------------------------------------
 # Run the unit tests built against x86 bionic on an x86 host.
 # -----------------------------------------------------------------------------
 
-ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
-ifeq ($(TARGET_ARCH),x86)
-LINKER = linker
-else
-LINKER = linker64
-endif
 # gtest needs ANDROID_DATA/local/tmp for death test output.
 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
 # bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
+# BIONIC_TEST_FLAGS is either empty or it comes from the user.
 bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
 	if [ ! -d /system -o ! -d /system/bin ]; then \
 	  echo "Attempting to create /system/bin"; \
@@ -209,59 +353,10 @@
 	ANDROID_DATA=$(TARGET_OUT_DATA) \
 	ANDROID_ROOT=$(TARGET_OUT) \
 	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
-		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests
-endif
+		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
 endif
 
-# -----------------------------------------------------------------------------
-# FORTIFY_SOURCE tests
-# -----------------------------------------------------------------------------
+endif # linux-x86
 
-fortify_c_includes = \
-    bionic \
-    bionic/libstdc++/include \
-    external/stlport/stlport \
-    external/gtest/include
-fortify_test_files = fortify_test.cpp
-
-# -Wno-error=unused-parameter needed as
-# external/stlport/stlport/stl/_threads.c (included from
-# external/gtest/include/gtest/gtest.h) does not compile cleanly under
-# clang. TODO: fix this.
-fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(fortify_test_files)
-LOCAL_MODULE := fortify1-tests-gcc
-LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_C_INCLUDES += $(fortify_c_includes)
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(fortify_test_files)
-LOCAL_MODULE := fortify2-tests-gcc
-LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_C_INCLUDES += $(fortify_c_includes)
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(fortify_test_files)
-LOCAL_MODULE := fortify1-tests-clang
-LOCAL_CLANG := true
-LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_C_INCLUDES += $(fortify_c_includes)
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(fortify_test_files)
-LOCAL_MODULE := fortify2-tests-clang
-LOCAL_CLANG := true
-LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_C_INCLUDES += $(fortify_c_includes)
-include $(BUILD_STATIC_LIBRARY)
-
+include $(call first-makefiles-under,$(LOCAL_PATH))
 endif # !BUILD_TINY_ANDROID
diff --git a/tests/TemporaryFile.h b/tests/TemporaryFile.h
index b3f085f..c4ee2d5 100644
--- a/tests/TemporaryFile.h
+++ b/tests/TemporaryFile.h
@@ -14,32 +14,67 @@
  * limitations under the License.
  */
 
+#include <fcntl.h>
 #include <unistd.h>
 
-class TemporaryFile {
+template<int (*mk_fn)(char*)>
+class GenericTemporaryFile {
  public:
-  TemporaryFile() {
-    // Since we might be running on the host or the target, and if we're
-    // running on the host we might be running under bionic or glibc,
-    // let's just try both possible temporary directories and take the
-    // first one that works.
-    init("/data/local/tmp");
-    if (fd == -1) {
-      init("/tmp");
+  GenericTemporaryFile(const char* dirpath = NULL) {
+    if (dirpath != NULL) {
+      init(dirpath);
+    } else {
+      // Since we might be running on the host or the target, and if we're
+      // running on the host we might be running under bionic or glibc,
+      // let's just try both possible temporary directories and take the
+      // first one that works.
+      init("/data/local/tmp");
+      if (fd == -1) {
+        init("/tmp");
+      }
     }
   }
 
-  ~TemporaryFile() {
+  ~GenericTemporaryFile() {
     close(fd);
     unlink(filename);
   }
 
+  void reopen() {
+    close(fd);
+    fd = open(filename, O_RDWR);
+  }
+
   int fd;
   char filename[1024];
 
  private:
   void init(const char* tmp_dir) {
     snprintf(filename, sizeof(filename), "%s/TemporaryFile-XXXXXX", tmp_dir);
-    fd = mkstemp(filename);
+    fd = mk_fn(filename);
   }
 };
+
+typedef GenericTemporaryFile<mkstemp> TemporaryFile;
+
+class TemporaryDir {
+ public:
+  TemporaryDir() {
+    if (!init("/data/local/tmp")) {
+      init("/tmp");
+    }
+  }
+
+  ~TemporaryDir() {
+    rmdir(dirname);
+  }
+
+  char dirname[1024];
+
+ private:
+  bool init(const char* tmp_dir) {
+    snprintf(dirname, sizeof(dirname), "%s/TemporaryDir-XXXXXX", tmp_dir);
+    return (mkdtemp(dirname) != NULL);
+  }
+
+};
diff --git a/tests/arpa_inet_test.cpp b/tests/arpa_inet_test.cpp
new file mode 100644
index 0000000..5e53337
--- /dev/null
+++ b/tests/arpa_inet_test.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <arpa/inet.h>
+
+TEST(arpa_inet, inet_addr) {
+  ASSERT_EQ((htonl)(0x7f000001), inet_addr("127.0.0.1"));
+}
+
+TEST(arpa_inet, inet_aton) {
+  in_addr a;
+  ASSERT_EQ(1, inet_aton("127.0.0.1", &a));
+  ASSERT_EQ((htonl)(0x7f000001), a.s_addr);
+}
+
+TEST(arpa_inet, inet_lnaof) {
+  in_addr a = { htonl(0x12345678) };
+  ASSERT_EQ(0x00345678U, inet_lnaof(a));
+}
+
+TEST(arpa_inet, inet_makeaddr) {
+  in_addr a = inet_makeaddr(0x12U, 0x345678);
+  ASSERT_EQ((htonl)(0x12345678), a.s_addr);
+}
+
+TEST(arpa_inet, inet_netof) {
+  in_addr a = { htonl(0x12345678) };
+  ASSERT_EQ(0x12U, inet_netof(a));
+}
+
+TEST(arpa_inet, inet_network) {
+  ASSERT_EQ(0x7f000001U, inet_network("127.0.0.1"));
+}
+
+TEST(arpa_inet, inet_ntoa) {
+  in_addr a = { (htonl)(0x7f000001) };
+  ASSERT_STREQ("127.0.0.1", inet_ntoa(a));
+}
+
+TEST(arpa_inet, inet_pton__inet_ntop) {
+  sockaddr_storage ss;
+  ASSERT_EQ(1, inet_pton(AF_INET, "127.0.0.1", &ss));
+
+  char s[INET_ADDRSTRLEN];
+  ASSERT_STREQ("127.0.0.1", inet_ntop(AF_INET, &ss, s, INET_ADDRSTRLEN));
+}
+
+TEST(arpa_inet, inet_ntop_overflow) {
+  // OpenBSD's inet_ntop had a bug where passing a 'size' larger than INET_ADDRSTRLEN
+  // for AF_INET or INET6_ADDRSTRLEN for AF_INET6 would cause inet_ntop to overflow an
+  // internal buffer.
+
+  sockaddr_storage ss4;
+  ASSERT_EQ(1, inet_pton(AF_INET, "127.0.0.1", &ss4));
+
+  sockaddr_storage ss6;
+  ASSERT_EQ(1, inet_pton(AF_INET6, "::1", &ss6));
+
+  char s4[INET_ADDRSTRLEN];
+  char s6[INET6_ADDRSTRLEN];
+  ASSERT_STREQ("127.0.0.1", inet_ntop(AF_INET, &ss4, s4, INET_ADDRSTRLEN));
+  ASSERT_STREQ("127.0.0.1", inet_ntop(AF_INET, &ss4, s4, 2*INET_ADDRSTRLEN));
+  ASSERT_STREQ("::1", inet_ntop(AF_INET6, &ss6, s6, INET_ADDRSTRLEN));
+  ASSERT_STREQ("::1", inet_ntop(AF_INET6, &ss6, s6, INET6_ADDRSTRLEN));
+  ASSERT_STREQ("::1", inet_ntop(AF_INET6, &ss6, s6, 2*INET6_ADDRSTRLEN));
+}
diff --git a/tests/atexit_test.cpp b/tests/atexit_test.cpp
new file mode 100644
index 0000000..e01220e
--- /dev/null
+++ b/tests/atexit_test.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <dlfcn.h>
+#include <libgen.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#include <string>
+
+TEST(atexit, dlclose) {
+  std::string atexit_call_sequence;
+  bool valid_this_in_static_dtor = false;
+  void* handle = dlopen("libtest_atexit.so", RTLD_NOW);
+  ASSERT_TRUE(handle != NULL);
+
+  void* sym = dlsym(handle, "register_atexit");
+  ASSERT_TRUE(sym != NULL);
+  reinterpret_cast<void (*)(std::string*, bool*)>(sym)(&atexit_call_sequence, &valid_this_in_static_dtor);
+
+  ASSERT_EQ(0, dlclose(handle));
+  // this test verifies atexit call from atexit handler. as well as the order of calls
+  ASSERT_EQ("Humpty Dumpty sat on a wall", atexit_call_sequence);
+  ASSERT_TRUE(valid_this_in_static_dtor);
+}
+
+class TestMainStaticDtorClass {
+ public:
+  TestMainStaticDtorClass() {
+    expected_this = this;
+  }
+
+  ~TestMainStaticDtorClass() {
+    if (this != expected_this) {
+      fprintf(stderr, "\nerror: static d-tor called with incorrect this pointer: %p, expected: %p\n", this, expected_this);
+    } else {
+      fprintf(stderr, "6");
+    }
+  }
+ private:
+  static const TestMainStaticDtorClass* expected_this;
+};
+
+const TestMainStaticDtorClass* TestMainStaticDtorClass::expected_this = NULL;
+
+static void atexit_func5() {
+  fprintf(stderr, "5");
+}
+
+static void atexit_func4() {
+  fprintf(stderr, "4");
+}
+
+static void atexit_func3() {
+  fprintf(stderr, "3");
+  atexit(atexit_func4);
+}
+
+static void atexit_func2() {
+  fprintf(stderr, "2");
+}
+
+static void atexit_func1() {
+  fprintf(stderr, "1");
+}
+
+static void atexit_main() {
+  // This should result in "123456" output to stderr
+  static TestMainStaticDtorClass static_obj;
+  atexit(atexit_func5);
+  atexit(atexit_func3);
+  atexit(atexit_func2);
+  atexit(atexit_func1);
+  exit(0);
+}
+
+TEST(atexit, exit) {
+  ASSERT_EXIT(atexit_main(), testing::ExitedWithCode(0), "123456");
+}
+
diff --git a/tests/ctype_test.cpp b/tests/ctype_test.cpp
new file mode 100644
index 0000000..7b27d64
--- /dev/null
+++ b/tests/ctype_test.cpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <ctype.h>
+
+TEST(ctype, isalnum) {
+  EXPECT_TRUE(isalnum('1'));
+  EXPECT_TRUE(isalnum('a'));
+  EXPECT_TRUE(isalnum('A'));
+  EXPECT_FALSE(isalnum('!'));
+  EXPECT_FALSE(isalnum(' '));
+}
+
+TEST(ctype, isalpha) {
+  EXPECT_FALSE(isalpha('1'));
+  EXPECT_TRUE(isalpha('a'));
+  EXPECT_TRUE(isalpha('A'));
+  EXPECT_FALSE(isalpha('!'));
+  EXPECT_FALSE(isalpha(' '));
+}
+
+TEST(ctype, isascii) {
+  EXPECT_TRUE(isascii('\x7f'));
+  EXPECT_FALSE(isascii('\x80'));
+}
+
+TEST(ctype, isblank) {
+  EXPECT_FALSE(isblank('1'));
+  EXPECT_TRUE(isblank(' '));
+  EXPECT_TRUE(isblank('\t'));
+}
+
+TEST(ctype, iscntrl) {
+  EXPECT_FALSE(iscntrl('1'));
+  EXPECT_TRUE(iscntrl('\b'));
+}
+
+TEST(ctype, isdigit) {
+  EXPECT_TRUE(isdigit('1'));
+  EXPECT_FALSE(isdigit('a'));
+  EXPECT_FALSE(isdigit('x'));
+}
+
+TEST(ctype, isgraph) {
+  EXPECT_TRUE(isgraph('a'));
+  EXPECT_TRUE(isgraph('A'));
+  EXPECT_TRUE(isgraph('1'));
+  EXPECT_TRUE(isgraph('!'));
+  EXPECT_FALSE(isgraph(' '));
+}
+
+TEST(ctype, islower) {
+  EXPECT_TRUE(islower('a'));
+  EXPECT_FALSE(islower('A'));
+  EXPECT_FALSE(islower('!'));
+}
+
+TEST(ctype, isprint) {
+  EXPECT_TRUE(isprint('a'));
+  EXPECT_TRUE(isprint(' '));
+  EXPECT_FALSE(isprint('\b'));
+}
+
+TEST(ctype, ispunct) {
+  EXPECT_TRUE(ispunct('!'));
+  EXPECT_FALSE(ispunct('a'));
+  EXPECT_FALSE(ispunct(' '));
+  EXPECT_FALSE(ispunct('\b'));
+}
+
+TEST(ctype, isspace) {
+  EXPECT_TRUE(isspace(' '));
+  EXPECT_TRUE(isspace('\f'));
+  EXPECT_TRUE(isspace('\n'));
+  EXPECT_TRUE(isspace('\r'));
+  EXPECT_TRUE(isspace('\t'));
+  EXPECT_TRUE(isspace('\v'));
+  EXPECT_FALSE(isspace('a'));
+  EXPECT_FALSE(isspace('!'));
+}
+
+TEST(ctype, isupper) {
+  EXPECT_TRUE(isupper('A'));
+  EXPECT_FALSE(isupper('a'));
+  EXPECT_FALSE(isupper('!'));
+}
+
+TEST(ctype, isxdigit) {
+  EXPECT_TRUE(isxdigit('0'));
+  EXPECT_FALSE(isxdigit('x'));
+  EXPECT_TRUE(isxdigit('1'));
+  EXPECT_TRUE(isxdigit('a'));
+  EXPECT_TRUE(isxdigit('A'));
+  EXPECT_FALSE(isxdigit('g'));
+  EXPECT_FALSE(isxdigit(' '));
+}
+
+TEST(ctype, toascii) {
+  EXPECT_EQ('a', toascii('a'));
+  EXPECT_EQ('a', toascii(0x80 | 'a'));
+}
+
+TEST(ctype, tolower) {
+  EXPECT_EQ('!', tolower('!'));
+  EXPECT_EQ('a', tolower('a'));
+  EXPECT_EQ('a', tolower('A'));
+}
+
+TEST(ctype, _tolower) {
+  // _tolower may mangle characters for which isupper is false.
+  EXPECT_EQ('a', _tolower('A'));
+}
+
+TEST(ctype, toupper) {
+  EXPECT_EQ('!', toupper('!'));
+  EXPECT_EQ('A', toupper('a'));
+  EXPECT_EQ('A', toupper('A'));
+}
+
+TEST(ctype, _toupper) {
+  // _toupper may mangle characters for which islower is false.
+  EXPECT_EQ('A', _toupper('a'));
+}
diff --git a/tests/dirent_test.cpp b/tests/dirent_test.cpp
index 48ca819..6aadb37 100644
--- a/tests/dirent_test.cpp
+++ b/tests/dirent_test.cpp
@@ -37,21 +37,31 @@
   ASSERT_TRUE(names.find("stat") != names.end());
 }
 
-TEST(dirent, scandir) {
+template <typename DirEntT>
+void ScanEntries(DirEntT** entries, int entry_count,
+                 std::set<std::string>& name_set, std::vector<std::string>& name_list) {
+  for (size_t i = 0; i < static_cast<size_t>(entry_count); ++i) {
+    name_set.insert(entries[i]->d_name);
+    name_list.push_back(entries[i]->d_name);
+    free(entries[i]);
+  }
+  free(entries);
+}
+
+TEST(dirent, scandir_scandir64) {
   // Get everything from /proc/self...
   dirent** entries;
   int entry_count = scandir("/proc/self", &entries, NULL, alphasort);
   ASSERT_GE(entry_count, 0);
 
+  dirent64** entries64;
+  int entry_count64 = scandir64("/proc/self", &entries64, NULL, alphasort64);
+  ASSERT_EQ(entry_count, entry_count64);
+
   // Turn the directory entries into a set and vector of the names.
   std::set<std::string> name_set;
   std::vector<std::string> unsorted_name_list;
-  for (size_t i = 0; i < static_cast<size_t>(entry_count); ++i) {
-    name_set.insert(entries[i]->d_name);
-    unsorted_name_list.push_back(entries[i]->d_name);
-    free(entries[i]);
-  }
-  free(entries);
+  ScanEntries(entries, entry_count, name_set, unsorted_name_list);
 
   // No duplicates.
   ASSERT_EQ(name_set.size(), unsorted_name_list.size());
@@ -61,6 +71,13 @@
   std::sort(sorted_name_list.begin(), sorted_name_list.end());
   ASSERT_EQ(sorted_name_list, unsorted_name_list);
 
+  // scandir64 returned the same results as scandir.
+  std::set<std::string> name_set64;
+  std::vector<std::string> unsorted_name_list64;
+  ScanEntries(entries64, entry_count64, name_set64, unsorted_name_list64);
+  ASSERT_EQ(name_set, name_set64);
+  ASSERT_EQ(unsorted_name_list, unsorted_name_list64);
+
   CheckProcSelf(name_set);
 }
 
@@ -133,6 +150,23 @@
   CheckProcSelf(name_set);
 }
 
+TEST(dirent, readdir64) {
+  DIR* d = opendir("/proc/self");
+  ASSERT_TRUE(d != NULL);
+  std::set<std::string> name_set;
+  errno = 0;
+  dirent64* e;
+  while ((e = readdir64(d)) != NULL) {
+    name_set.insert(e->d_name);
+  }
+  // Reading to the end of the directory is not an error.
+  // readdir64(3) returns NULL, but leaves errno as 0.
+  ASSERT_EQ(0, errno);
+  ASSERT_EQ(closedir(d), 0);
+
+  CheckProcSelf(name_set);
+}
+
 TEST(dirent, readdir_r) {
   DIR* d = opendir("/proc/self");
   ASSERT_TRUE(d != NULL);
@@ -151,6 +185,24 @@
   CheckProcSelf(name_set);
 }
 
+TEST(dirent, readdir64_r) {
+  DIR* d = opendir("/proc/self");
+  ASSERT_TRUE(d != NULL);
+  std::set<std::string> name_set;
+  errno = 0;
+  dirent64 storage;
+  dirent64* e = NULL;
+  while (readdir64_r(d, &storage, &e) == 0 && e != NULL) {
+    name_set.insert(e->d_name);
+  }
+  // Reading to the end of the directory is not an error.
+  // readdir64_r(3) returns NULL, but leaves errno as 0.
+  ASSERT_EQ(0, errno);
+  ASSERT_EQ(closedir(d), 0);
+
+  CheckProcSelf(name_set);
+}
+
 TEST(dirent, rewinddir) {
   DIR* d = opendir("/proc/self");
   ASSERT_TRUE(d != NULL);
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
new file mode 100644
index 0000000..da63046
--- /dev/null
+++ b/tests/dlext_test.cpp
@@ -0,0 +1,377 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <dlfcn.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <android/dlext.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <pagemap/pagemap.h>
+
+
+#define ASSERT_DL_NOTNULL(ptr) \
+    ASSERT_TRUE(ptr != NULL) << "dlerror: " << dlerror()
+
+#define ASSERT_DL_ZERO(i) \
+    ASSERT_EQ(0, i) << "dlerror: " << dlerror()
+
+#define ASSERT_NOERROR(i) \
+    ASSERT_NE(-1, i) << "errno: " << strerror(errno)
+
+
+typedef int (*fn)(void);
+#define LIBNAME "libdlext_test.so"
+#define LIBNAME_NORELRO "libdlext_test_norelro.so"
+#define LIBSIZE 1024*1024 // how much address space to reserve for it
+
+#if defined(__LP64__)
+#define LIBPATH "%s/nativetest64/libdlext_test_fd/libdlext_test_fd.so"
+#else
+#define LIBPATH "%s/nativetest/libdlext_test_fd/libdlext_test_fd.so"
+#endif
+
+class DlExtTest : public ::testing::Test {
+protected:
+  virtual void SetUp() {
+    handle_ = NULL;
+    // verify that we don't have the library loaded already
+    ASSERT_EQ(NULL, dlsym(RTLD_DEFAULT, "getRandomNumber"));
+    // call dlerror() to swallow the error, and check it was the one we wanted
+    ASSERT_STREQ("undefined symbol: getRandomNumber", dlerror());
+  }
+
+  virtual void TearDown() {
+    if (handle_ != NULL) {
+      ASSERT_DL_ZERO(dlclose(handle_));
+    }
+  }
+
+  void* handle_;
+};
+
+TEST_F(DlExtTest, ExtInfoNull) {
+  handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, NULL);
+  ASSERT_DL_NOTNULL(handle_);
+  fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
+  ASSERT_DL_NOTNULL(f);
+  EXPECT_EQ(4, f());
+}
+
+TEST_F(DlExtTest, ExtInfoNoFlags) {
+  android_dlextinfo extinfo;
+  extinfo.flags = 0;
+  handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+  ASSERT_DL_NOTNULL(handle_);
+  fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
+  ASSERT_DL_NOTNULL(f);
+  EXPECT_EQ(4, f());
+}
+
+TEST_F(DlExtTest, ExtInfoUseFd) {
+  const char* android_data = getenv("ANDROID_DATA");
+  ASSERT_TRUE(android_data != NULL);
+  char lib_path[PATH_MAX];
+  snprintf(lib_path, sizeof(lib_path), LIBPATH, android_data);
+
+  android_dlextinfo extinfo;
+  extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD;
+  extinfo.library_fd = TEMP_FAILURE_RETRY(open(lib_path, O_RDONLY | O_CLOEXEC));
+  ASSERT_TRUE(extinfo.library_fd != -1);
+  handle_ = android_dlopen_ext(lib_path, RTLD_NOW, &extinfo);
+  ASSERT_DL_NOTNULL(handle_);
+  fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
+  ASSERT_DL_NOTNULL(f);
+  EXPECT_EQ(4, f());
+}
+
+TEST_F(DlExtTest, Reserved) {
+  void* start = mmap(NULL, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,
+                     -1, 0);
+  ASSERT_TRUE(start != MAP_FAILED);
+  android_dlextinfo extinfo;
+  extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
+  extinfo.reserved_addr = start;
+  extinfo.reserved_size = LIBSIZE;
+  handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+  ASSERT_DL_NOTNULL(handle_);
+  fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
+  ASSERT_DL_NOTNULL(f);
+  EXPECT_GE(f, start);
+  EXPECT_LT(reinterpret_cast<void*>(f),
+            reinterpret_cast<char*>(start) + LIBSIZE);
+  EXPECT_EQ(4, f());
+}
+
+TEST_F(DlExtTest, ReservedTooSmall) {
+  void* start = mmap(NULL, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,
+                     -1, 0);
+  ASSERT_TRUE(start != MAP_FAILED);
+  android_dlextinfo extinfo;
+  extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
+  extinfo.reserved_addr = start;
+  extinfo.reserved_size = PAGE_SIZE;
+  handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+  EXPECT_EQ(NULL, handle_);
+}
+
+TEST_F(DlExtTest, ReservedHint) {
+  void* start = mmap(NULL, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,
+                     -1, 0);
+  ASSERT_TRUE(start != MAP_FAILED);
+  android_dlextinfo extinfo;
+  extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS_HINT;
+  extinfo.reserved_addr = start;
+  extinfo.reserved_size = LIBSIZE;
+  handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+  ASSERT_DL_NOTNULL(handle_);
+  fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
+  ASSERT_DL_NOTNULL(f);
+  EXPECT_GE(f, start);
+  EXPECT_LT(reinterpret_cast<void*>(f),
+            reinterpret_cast<char*>(start) + LIBSIZE);
+  EXPECT_EQ(4, f());
+}
+
+TEST_F(DlExtTest, ReservedHintTooSmall) {
+  void* start = mmap(NULL, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,
+                     -1, 0);
+  ASSERT_TRUE(start != MAP_FAILED);
+  android_dlextinfo extinfo;
+  extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS_HINT;
+  extinfo.reserved_addr = start;
+  extinfo.reserved_size = PAGE_SIZE;
+  handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+  ASSERT_DL_NOTNULL(handle_);
+  fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
+  ASSERT_DL_NOTNULL(f);
+  EXPECT_TRUE(f < start || (reinterpret_cast<void*>(f) >=
+                            reinterpret_cast<char*>(start) + PAGE_SIZE));
+  EXPECT_EQ(4, f());
+}
+
+class DlExtRelroSharingTest : public DlExtTest {
+protected:
+  virtual void SetUp() {
+    DlExtTest::SetUp();
+    void* start = mmap(NULL, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,
+                       -1, 0);
+    ASSERT_TRUE(start != MAP_FAILED);
+    extinfo_.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
+    extinfo_.reserved_addr = start;
+    extinfo_.reserved_size = LIBSIZE;
+    extinfo_.relro_fd = -1;
+
+    const char* android_data = getenv("ANDROID_DATA");
+    ASSERT_TRUE(android_data != NULL);
+    snprintf(relro_file_, sizeof(relro_file_), "%s/local/tmp/libdlext_test.relro", android_data);
+  }
+
+  virtual void TearDown() {
+    DlExtTest::TearDown();
+    if (extinfo_.relro_fd != -1) {
+      ASSERT_NOERROR(close(extinfo_.relro_fd));
+    }
+  }
+
+  void CreateRelroFile(const char* lib) {
+    int relro_fd = open(relro_file_, O_CREAT | O_RDWR | O_TRUNC, 0644);
+    ASSERT_NOERROR(relro_fd);
+
+    pid_t pid = fork();
+    if (pid == 0) {
+      // child process
+      extinfo_.flags |= ANDROID_DLEXT_WRITE_RELRO;
+      extinfo_.relro_fd = relro_fd;
+      void* handle = android_dlopen_ext(lib, RTLD_NOW, &extinfo_);
+      if (handle == NULL) {
+        fprintf(stderr, "in child: %s\n", dlerror());
+        exit(1);
+      }
+      exit(0);
+    }
+
+    // continuing in parent
+    ASSERT_NOERROR(close(relro_fd));
+    ASSERT_NOERROR(pid);
+    int status;
+    ASSERT_EQ(pid, waitpid(pid, &status, 0));
+    ASSERT_TRUE(WIFEXITED(status));
+    ASSERT_EQ(0, WEXITSTATUS(status));
+
+    // reopen file for reading so it can be used
+    relro_fd = open(relro_file_, O_RDONLY);
+    ASSERT_NOERROR(relro_fd);
+    extinfo_.flags |= ANDROID_DLEXT_USE_RELRO;
+    extinfo_.relro_fd = relro_fd;
+  }
+
+  void TryUsingRelro(const char* lib) {
+    handle_ = android_dlopen_ext(lib, RTLD_NOW, &extinfo_);
+    ASSERT_DL_NOTNULL(handle_);
+    fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
+    ASSERT_DL_NOTNULL(f);
+    EXPECT_EQ(4, f());
+  }
+
+  void SpawnChildrenAndMeasurePss(const char* lib, bool share_relro, size_t* pss_out);
+
+  android_dlextinfo extinfo_;
+  char relro_file_[PATH_MAX];
+};
+
+TEST_F(DlExtRelroSharingTest, ChildWritesGoodData) {
+  ASSERT_NO_FATAL_FAILURE(CreateRelroFile(LIBNAME));
+  ASSERT_NO_FATAL_FAILURE(TryUsingRelro(LIBNAME));
+}
+
+TEST_F(DlExtRelroSharingTest, ChildWritesNoRelro) {
+  ASSERT_NO_FATAL_FAILURE(CreateRelroFile(LIBNAME_NORELRO));
+  ASSERT_NO_FATAL_FAILURE(TryUsingRelro(LIBNAME_NORELRO));
+}
+
+TEST_F(DlExtRelroSharingTest, RelroFileEmpty) {
+  int relro_fd = open(relro_file_, O_CREAT | O_RDWR | O_TRUNC, 0644);
+  ASSERT_NOERROR(relro_fd);
+  ASSERT_NOERROR(close(relro_fd));
+
+  ASSERT_NO_FATAL_FAILURE(TryUsingRelro(LIBNAME));
+}
+
+TEST_F(DlExtRelroSharingTest, VerifyMemorySaving) {
+  ASSERT_NO_FATAL_FAILURE(CreateRelroFile(LIBNAME));
+  int relro_fd = open(relro_file_, O_RDONLY);
+  ASSERT_NOERROR(relro_fd);
+  extinfo_.flags |= ANDROID_DLEXT_USE_RELRO;
+  extinfo_.relro_fd = relro_fd;
+  int pipefd[2];
+  ASSERT_NOERROR(pipe(pipefd));
+
+  size_t without_sharing, with_sharing;
+  ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(LIBNAME, false, &without_sharing));
+  ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(LIBNAME, true, &with_sharing));
+
+  // We expect the sharing to save at least 10% of the total PSS. In practice
+  // it saves 40%+ for this test.
+  size_t expected_size = without_sharing - (without_sharing/10);
+  EXPECT_LT(with_sharing, expected_size);
+}
+
+void getPss(pid_t pid, size_t* pss_out) {
+  pm_kernel_t* kernel;
+  ASSERT_EQ(0, pm_kernel_create(&kernel));
+
+  pm_process_t* process;
+  ASSERT_EQ(0, pm_process_create(kernel, pid, &process));
+
+  pm_map_t** maps;
+  size_t num_maps;
+  ASSERT_EQ(0, pm_process_maps(process, &maps, &num_maps));
+
+  size_t total_pss = 0;
+  for (size_t i = 0; i < num_maps; i++) {
+    pm_memusage_t usage;
+    ASSERT_EQ(0, pm_map_usage(maps[i], &usage));
+    total_pss += usage.pss;
+  }
+  *pss_out = total_pss;
+
+  free(maps);
+  pm_process_destroy(process);
+  pm_kernel_destroy(kernel);
+}
+
+void DlExtRelroSharingTest::SpawnChildrenAndMeasurePss(const char* lib, bool share_relro,
+                                                       size_t* pss_out) {
+  const int CHILDREN = 20;
+
+  // Create children
+  pid_t childpid[CHILDREN];
+  int childpipe[CHILDREN];
+  for (int i=0; i<CHILDREN; ++i) {
+    char read_buf;
+    int child_done_pipe[2], parent_done_pipe[2];
+    ASSERT_NOERROR(pipe(child_done_pipe));
+    ASSERT_NOERROR(pipe(parent_done_pipe));
+
+    pid_t child = fork();
+    if (child == 0) {
+      // close the 'wrong' ends of the pipes in the child
+      close(child_done_pipe[0]);
+      close(parent_done_pipe[1]);
+
+      // open the library
+      void* handle;
+      if (share_relro) {
+        handle = android_dlopen_ext(lib, RTLD_NOW, &extinfo_);
+      } else {
+        handle = dlopen(lib, RTLD_NOW);
+      }
+      if (handle == NULL) {
+        fprintf(stderr, "in child: %s\n", dlerror());
+        exit(1);
+      }
+
+      // close write end of child_done_pipe to signal the parent that we're done.
+      close(child_done_pipe[1]);
+
+      // wait for the parent to close parent_done_pipe, then exit
+      read(parent_done_pipe[0], &read_buf, 1);
+      exit(0);
+    }
+
+    ASSERT_NOERROR(child);
+
+    // close the 'wrong' ends of the pipes in the parent
+    close(child_done_pipe[1]);
+    close(parent_done_pipe[0]);
+
+    // wait for the child to be done
+    read(child_done_pipe[0], &read_buf, 1);
+    close(child_done_pipe[0]);
+
+    // save the child's pid and the parent_done_pipe
+    childpid[i] = child;
+    childpipe[i] = parent_done_pipe[1];
+  }
+
+  // Sum the PSS of all the children
+  size_t total_pss = 0;
+  for (int i=0; i<CHILDREN; ++i) {
+    size_t child_pss;
+    ASSERT_NO_FATAL_FAILURE(getPss(childpid[i], &child_pss));
+    total_pss += child_pss;
+  }
+  *pss_out = total_pss;
+
+  // Close pipes and wait for children to exit
+  for (int i=0; i<CHILDREN; ++i) {
+    ASSERT_NOERROR(close(childpipe[i]));
+  }
+  for (int i=0; i<CHILDREN; ++i) {
+    int status;
+    ASSERT_EQ(childpid[i], waitpid(childpid[i], &status, 0));
+    ASSERT_TRUE(WIFEXITED(status));
+    ASSERT_EQ(0, WEXITSTATUS(status));
+  }
+}
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index fc90dd9..457fcd5 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -27,9 +27,21 @@
 #define ASSERT_SUBSTR(needle, haystack) \
     ASSERT_PRED_FORMAT2(::testing::IsSubstring, needle, haystack)
 
-static bool gCalled = false;
+static bool g_called = false;
 extern "C" void DlSymTestFunction() {
-  gCalled = true;
+  g_called = true;
+}
+
+static int g_ctor_function_called = 0;
+
+extern "C" void ctor_function() __attribute__ ((constructor));
+
+extern "C" void ctor_function() {
+  g_ctor_function_called = 17;
+}
+
+TEST(dlfcn, ctor_function_call) {
+  ASSERT_EQ(17, g_ctor_function_called);
 }
 
 TEST(dlfcn, dlsym_in_self) {
@@ -43,17 +55,42 @@
 
   void (*function)() = reinterpret_cast<void(*)()>(sym);
 
-  gCalled = false;
+  g_called = false;
   function();
-  ASSERT_TRUE(gCalled);
+  ASSERT_TRUE(g_called);
 
   ASSERT_EQ(0, dlclose(self));
 }
 
+TEST(dlfcn, dlsym_with_dependencies) {
+  void* handle = dlopen("libtest_with_dependency.so", RTLD_NOW);
+  ASSERT_TRUE(handle != NULL);
+  dlerror();
+  // This symbol is in DT_NEEDED library.
+  void* sym = dlsym(handle, "getRandomNumber");
+  ASSERT_TRUE(sym != NULL);
+  int (*fn)(void);
+  fn = reinterpret_cast<int (*)(void)>(sym);
+  EXPECT_EQ(4, fn());
+  dlclose(handle);
+}
+
+TEST(dlfcn, dlopen_noload) {
+  void* handle = dlopen("libtest_simple.so", RTLD_NOW | RTLD_NOLOAD);
+  ASSERT_TRUE(handle == NULL);
+  handle = dlopen("libtest_simple.so", RTLD_NOW);
+  void* handle2 = dlopen("libtest_simple.so", RTLD_NOW | RTLD_NOLOAD);
+  ASSERT_TRUE(handle != NULL);
+  ASSERT_TRUE(handle2 != NULL);
+  ASSERT_TRUE(handle == handle2);
+  ASSERT_EQ(0, dlclose(handle));
+  ASSERT_EQ(0, dlclose(handle2));
+}
+
 TEST(dlfcn, dlopen_failure) {
   void* self = dlopen("/does/not/exist", RTLD_NOW);
   ASSERT_TRUE(self == NULL);
-#if __BIONIC__
+#if defined(__BIONIC__)
   ASSERT_STREQ("dlopen failed: library \"/does/not/exist\" not found", dlerror());
 #else
   ASSERT_STREQ("/does/not/exist: cannot open shared object file: No such file or directory", dlerror());
@@ -89,17 +126,16 @@
 
   void* sym;
 
-  // NULL handle.
+#if defined(__BIONIC__) && !defined(__LP64__)
+  // RTLD_DEFAULT in lp32 bionic is not (void*)0
+  // so it can be distinguished from the NULL handle.
   sym = dlsym(NULL, "test");
   ASSERT_TRUE(sym == NULL);
-#if __BIONIC__
   ASSERT_SUBSTR("dlsym library handle is null", dlerror());
-#else
-  ASSERT_SUBSTR("undefined symbol: test", dlerror()); // glibc isn't specific about the failure.
 #endif
 
   // NULL symbol name.
-#if __BIONIC__
+#if defined(__BIONIC__)
   // glibc marks this parameter non-null and SEGVs if you cheat.
   sym = dlsym(self, NULL);
   ASSERT_TRUE(sym == NULL);
@@ -152,10 +188,8 @@
   // Look in /proc/pid/maps to find out what address we were loaded at.
   // TODO: factor /proc/pid/maps parsing out into a class and reuse all over bionic.
   void* base_address = NULL;
-  char path[PATH_MAX];
-  snprintf(path, sizeof(path), "/proc/%d/maps", getpid());
   char line[BUFSIZ];
-  FILE* fp = fopen(path, "r");
+  FILE* fp = fopen("/proc/self/maps", "r");
   ASSERT_TRUE(fp != NULL);
   while (fgets(line, sizeof(line), fp) != NULL) {
     uintptr_t start = strtoul(line, 0, 16);
@@ -206,7 +240,7 @@
   dlerror(); // Clear any pending errors.
   void* handle;
 
-#ifdef __GLIBC__
+#if defined(__GLIBC__)
   // glibc was smart enough not to define RTLD_NOW as 0, so it can detect missing flags.
   handle = dlopen(NULL, 0);
   ASSERT_TRUE(handle == NULL);
@@ -242,3 +276,23 @@
   void* addr = dlsym(RTLD_NEXT, "fopen");
   ASSERT_TRUE(addr != NULL);
 }
+
+TEST(dlfcn, dlsym_weak_func) {
+  dlerror();
+  void* handle = dlopen("libtest_dlsym_weak_func.so",RTLD_NOW);
+  ASSERT_TRUE(handle != NULL);
+
+  int (*weak_func)();
+  weak_func = reinterpret_cast<int (*)()>(dlsym(handle, "weak_func"));
+  ASSERT_TRUE(weak_func != NULL) << "dlerror: " << dlerror();
+  EXPECT_EQ(42, weak_func());
+  dlclose(handle);
+}
+
+TEST(dlfcn, dlopen_symlink) {
+  void* handle1 = dlopen("libdlext_test.so", RTLD_NOW);
+  void* handle2 = dlopen("libdlext_test_v2.so", RTLD_NOW);
+  ASSERT_TRUE(handle1 != NULL);
+  ASSERT_TRUE(handle2 != NULL);
+  ASSERT_EQ(handle1, handle2);
+}
diff --git a/tests/eventfd_test.cpp b/tests/eventfd_test.cpp
index 2c2c5f0..aa88a3b 100644
--- a/tests/eventfd_test.cpp
+++ b/tests/eventfd_test.cpp
@@ -14,11 +14,25 @@
  * limitations under the License.
  */
 
+#include <errno.h>
+#include <fcntl.h>
+
 #include <gtest/gtest.h>
 
-#if !defined(__GLIBC__) // Android's prebuilt gcc's header files don't include <sys/eventfd.h>.
-
+#if defined(__BIONIC__) // Android's prebuilt gcc's header files don't include <sys/eventfd.h>.
 #include <sys/eventfd.h>
+#else
+// Include the necessary components of sys/eventfd.h right here.
+#include <stdint.h>
+
+typedef uint64_t eventfd_t;
+
+__BEGIN_DECLS
+extern int eventfd(int, int);
+extern int eventfd_read(int, eventfd_t*);
+extern int eventfd_write(int, eventfd_t);
+__END_DECLS
+#endif
 
 TEST(eventfd, smoke) {
   unsigned int initial_value = 2;
@@ -43,5 +57,3 @@
 
   close(fd);
 }
-
-#endif
diff --git a/tests/fcntl_test.cpp b/tests/fcntl_test.cpp
index a094fac..3fd0a8c 100644
--- a/tests/fcntl_test.cpp
+++ b/tests/fcntl_test.cpp
@@ -19,6 +19,8 @@
 #include <errno.h>
 #include <fcntl.h>
 
+#include "TemporaryFile.h"
+
 TEST(fcntl, fcntl_smoke) {
   int fd = open("/proc/version", O_RDONLY);
   ASSERT_TRUE(fd != -1);
@@ -33,4 +35,205 @@
   flags = fcntl(fd, F_GETFD);
   ASSERT_TRUE(flags != -1);
   ASSERT_EQ(FD_CLOEXEC, flags & FD_CLOEXEC);
+
+  close(fd);
+}
+
+TEST(fcntl, open_open64) {
+  int fd;
+
+  fd = open("/proc/version", O_RDONLY);
+  ASSERT_TRUE(fd != -1);
+  close(fd);
+
+  fd = open64("/proc/version", O_RDONLY);
+  ASSERT_TRUE(fd != -1);
+  close(fd);
+}
+
+TEST(fcntl, openat_openat64) {
+  int fd;
+
+  fd = openat(AT_FDCWD, "/proc/version", O_RDONLY);
+  ASSERT_TRUE(fd != -1);
+  close(fd);
+
+  fd = openat64(AT_FDCWD, "/proc/version", O_RDONLY);
+  ASSERT_TRUE(fd != -1);
+  close(fd);
+}
+
+TEST(fcntl, creat_creat64) {
+  ASSERT_EQ(-1, creat("", 0666));
+  ASSERT_EQ(ENOENT, errno);
+  ASSERT_EQ(-1, creat64("", 0666));
+  ASSERT_EQ(ENOENT, errno);
+}
+
+TEST(fcntl, posix_fadvise) {
+  TemporaryFile tf;
+  errno = 0;
+
+  EXPECT_EQ(EBADF, posix_fadvise(-1, 0, 0, POSIX_FADV_NORMAL));
+  EXPECT_EQ(0, errno);
+
+  EXPECT_EQ(EBADF, posix_fadvise64(-1, 0, 0, POSIX_FADV_NORMAL));
+  EXPECT_EQ(0, errno);
+
+  EXPECT_EQ(EINVAL, posix_fadvise(tf.fd, 0, 0, -1));
+  EXPECT_EQ(0, errno);
+
+  EXPECT_EQ(EINVAL, posix_fadvise64(tf.fd, 0, 0, -1));
+  EXPECT_EQ(0, errno);
+
+  EXPECT_EQ(0, posix_fadvise(tf.fd, 0, 0, POSIX_FADV_NORMAL));
+  EXPECT_EQ(0, posix_fadvise64(tf.fd, 0, 0, POSIX_FADV_NORMAL));
+}
+
+TEST(fcntl, fallocate_EINVAL) {
+  TemporaryFile tf;
+
+  // fallocate/fallocate64 set errno.
+  // posix_fallocate/posix_fallocate64 return an errno value.
+
+  errno = 0;
+  ASSERT_EQ(-1, fallocate(tf.fd, 0, 0, -1));
+  ASSERT_EQ(EINVAL, errno);
+
+  errno = 0;
+  ASSERT_EQ(-1, fallocate64(tf.fd, 0, 0, -1));
+  ASSERT_EQ(EINVAL, errno);
+
+  errno = 0;
+  ASSERT_EQ(EINVAL, posix_fallocate(tf.fd, 0, -1));
+  ASSERT_EQ(0, errno);
+
+  errno = 0;
+  ASSERT_EQ(EINVAL, posix_fallocate64(tf.fd, 0, -1));
+  ASSERT_EQ(0, errno);
+}
+
+TEST(fcntl, fallocate) {
+  TemporaryFile tf;
+  struct stat sb;
+  ASSERT_EQ(0, fstat(tf.fd, &sb));
+  ASSERT_EQ(0, sb.st_size);
+
+#if defined(__BIONIC__)
+  ASSERT_EQ(0, fallocate(tf.fd, 0, 0, 1));
+  ASSERT_EQ(0, fstat(tf.fd, &sb));
+  ASSERT_EQ(1, sb.st_size);
+
+  ASSERT_EQ(0, fallocate64(tf.fd, 0, 0, 2));
+  ASSERT_EQ(0, fstat(tf.fd, &sb));
+  ASSERT_EQ(2, sb.st_size);
+#endif
+
+  ASSERT_EQ(0, posix_fallocate(tf.fd, 0, 3));
+  ASSERT_EQ(0, fstat(tf.fd, &sb));
+  ASSERT_EQ(3, sb.st_size);
+
+  ASSERT_EQ(0, posix_fallocate64(tf.fd, 0, 4));
+  ASSERT_EQ(0, fstat(tf.fd, &sb));
+  ASSERT_EQ(4, sb.st_size);
+}
+
+TEST(fcntl, f_getlk64) {
+  int fd = open64("/proc/version", O_RDONLY);
+  ASSERT_TRUE(fd != -1);
+
+  struct flock64 check_lock;
+  check_lock.l_type = F_WRLCK;
+  check_lock.l_start = 0;
+  check_lock.l_whence = SEEK_SET;
+  check_lock.l_len = 0;
+
+  int rc = fcntl(fd, F_GETLK64, &check_lock);
+  ASSERT_EQ(0, rc);
+
+  close(fd);
+}
+
+TEST(fcntl, splice) {
+  int pipe_fds[2];
+  ASSERT_EQ(0, pipe(pipe_fds));
+
+  int in = open("/proc/cpuinfo", O_RDONLY);
+  ASSERT_NE(in, -1);
+
+  TemporaryFile tf;
+
+  ssize_t bytes_read = splice(in, 0, pipe_fds[1], NULL, 8*1024, SPLICE_F_MORE | SPLICE_F_MOVE);
+  ASSERT_NE(bytes_read, -1);
+
+  ssize_t bytes_written = splice(pipe_fds[0], NULL, tf.fd, 0, bytes_read, SPLICE_F_MORE | SPLICE_F_MOVE);
+  ASSERT_EQ(bytes_read, bytes_written);
+
+  close(pipe_fds[0]);
+  close(pipe_fds[1]);
+  close(in);
+}
+
+TEST(fcntl, vmsplice) {
+  int pipe_fds[2];
+  ASSERT_EQ(0, pipe(pipe_fds));
+
+  iovec v[2];
+  v[0].iov_base = const_cast<char*>("hello ");
+  v[0].iov_len = 6;
+  v[1].iov_base = const_cast<char*>("world\n");
+  v[1].iov_len = 6;
+  ssize_t bytes_written = vmsplice(pipe_fds[1], v, sizeof(v)/sizeof(iovec), 0);
+  ASSERT_EQ(v[0].iov_len + v[1].iov_len, static_cast<size_t>(bytes_written));
+  close(pipe_fds[1]);
+
+  char buf[BUFSIZ];
+  FILE* fp = fdopen(pipe_fds[0], "r");
+  ASSERT_TRUE(fp != NULL);
+  ASSERT_TRUE(fgets(buf, sizeof(buf), fp) != NULL);
+  fclose(fp);
+  ASSERT_STREQ("hello world\n", buf);
+}
+
+TEST(fcntl, tee) {
+  char expected[256];
+  FILE* expected_fp = fopen("/proc/version", "r");
+  ASSERT_TRUE(expected_fp != NULL);
+  ASSERT_TRUE(fgets(expected, sizeof(expected), expected_fp) != NULL);
+  fclose(expected_fp);
+
+  int pipe1[2];
+  ASSERT_EQ(0, pipe(pipe1));
+
+  int pipe2[2];
+  ASSERT_EQ(0, pipe(pipe2));
+
+  int in = open("/proc/version", O_RDONLY);
+  ASSERT_NE(in, -1);
+
+  // Write /proc/version into pipe1.
+  ssize_t bytes_read = splice(in, 0, pipe1[1], NULL, 8*1024, SPLICE_F_MORE | SPLICE_F_MOVE);
+  ASSERT_NE(bytes_read, -1);
+  close(pipe1[1]);
+
+  // Tee /proc/version from pipe1 into pipe2.
+  ssize_t bytes_teed = tee(pipe1[0], pipe2[1], SIZE_MAX, 0);
+  ASSERT_EQ(bytes_read, bytes_teed);
+  close(pipe2[1]);
+
+  // The out fds of both pipe1 and pipe2 should now contain /proc/version.
+  char buf1[BUFSIZ];
+  FILE* fp1 = fdopen(pipe1[0], "r");
+  ASSERT_TRUE(fp1 != NULL);
+  ASSERT_TRUE(fgets(buf1, sizeof(buf1), fp1) != NULL);
+  fclose(fp1);
+
+  char buf2[BUFSIZ];
+  FILE* fp2 = fdopen(pipe2[0], "r");
+  ASSERT_TRUE(fp2 != NULL);
+  ASSERT_TRUE(fgets(buf2, sizeof(buf2), fp2) != NULL);
+  fclose(fp2);
+
+  ASSERT_STREQ(expected, buf1);
+  ASSERT_STREQ(expected, buf2);
 }
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index 408991e..352cac6 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -15,6 +15,7 @@
  */
 
 #include <gtest/gtest.h>
+#include <signal.h>
 #include <string.h>
 #include <stdarg.h>
 #include <sys/types.h>
@@ -22,6 +23,7 @@
 #include <sys/socket.h>
 #include <malloc.h>
 #include <fcntl.h>
+#include <sys/prctl.h>
 
 // We have to say "DeathTest" here so gtest knows to run this test (which exits)
 // in its own process. Unfortunately, the C preprocessor doesn't give us an
@@ -31,6 +33,21 @@
 #define DEATHTEST_EVALUATOR(name) DEATHTEST_PASTER(name)
 #define DEATHTEST DEATHTEST_EVALUATOR(TEST_NAME)
 
+class DEATHTEST : public testing::Test {
+ protected:
+  virtual void SetUp() {
+    old_dumpable_ = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
+    // Suppress debuggerd stack traces. Too slow.
+    prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
+  }
+
+  virtual void TearDown() {
+    prctl(PR_SET_DUMPABLE, old_dumpable_, 0, 0, 0, 0);
+  }
+ private:
+  int old_dumpable_;
+};
+
 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE == 2
 struct foo {
   char empty[0];
@@ -42,7 +59,32 @@
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strncpy_fortified2) {
+TEST_F(DEATHTEST, stpncpy_fortified2) {
+  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+  foo myfoo;
+  int copy_amt = atoi("11");
+  ASSERT_EXIT(stpncpy(myfoo.a, "01234567890", copy_amt),
+              testing::KilledBySignal(SIGABRT), "");
+}
+#endif
+
+#ifndef __clang__
+// This test is disabled in clang because clang doesn't properly detect
+// this buffer overflow. TODO: Fix clang.
+TEST_F(DEATHTEST, stpncpy2_fortified2) {
+  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+  foo myfoo;
+  memset(&myfoo, 0, sizeof(myfoo));
+  myfoo.one[0] = 'A'; // not null terminated string
+  ASSERT_EXIT(stpncpy(myfoo.b, myfoo.one, sizeof(myfoo.b)),
+              testing::KilledBySignal(SIGABRT), "");
+}
+#endif
+
+#ifndef __clang__
+// This test is disabled in clang because clang doesn't properly detect
+// this buffer overflow. TODO: Fix clang.
+TEST_F(DEATHTEST, strncpy_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   int copy_amt = atoi("11");
@@ -54,7 +96,7 @@
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strncpy2_fortified2) {
+TEST_F(DEATHTEST, strncpy2_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   memset(&myfoo, 0, sizeof(myfoo));
@@ -67,7 +109,7 @@
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, sprintf_fortified2) {
+TEST_F(DEATHTEST, sprintf_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   char source_buf[15];
@@ -80,7 +122,7 @@
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, sprintf2_fortified2) {
+TEST_F(DEATHTEST, sprintf2_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   ASSERT_EXIT(sprintf(myfoo.a, "0123456789"),
@@ -102,12 +144,12 @@
   return result;
 }
 
-TEST(DEATHTEST, vsprintf_fortified2) {
+TEST_F(DEATHTEST, vsprintf_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(vsprintf_helper2("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, vsprintf2_fortified2) {
+TEST_F(DEATHTEST, vsprintf2_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(vsprintf_helper2("0123456789"), testing::KilledBySignal(SIGABRT), "");
 }
@@ -128,30 +170,50 @@
   return result;
 }
 
-TEST(DEATHTEST, vsnprintf_fortified2) {
+TEST_F(DEATHTEST, vsnprintf_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(vsnprintf_helper2("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, vsnprintf2_fortified2) {
+TEST_F(DEATHTEST, vsnprintf2_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(vsnprintf_helper2("0123456789"), testing::KilledBySignal(SIGABRT), "");
 }
 #endif
 
-#if __BIONIC__
+#ifndef __clang__
+// zero sized target with "\0" source (should fail)
+// This test is disabled in clang because clang doesn't properly detect
+// this buffer overflow. TODO: Fix clang.
+TEST_F(DEATHTEST, stpcpy_fortified2) {
+#if defined(__BIONIC__)
+  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+  foo myfoo;
+  char* src = strdup("");
+  ASSERT_EXIT(stpcpy(myfoo.empty, src),
+              testing::KilledBySignal(SIGABRT), "");
+  free(src);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
+}
+#endif
 
 #ifndef __clang__
 // zero sized target with "\0" source (should fail)
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strcpy_fortified2) {
+TEST_F(DEATHTEST, strcpy_fortified2) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   char* src = strdup("");
   ASSERT_EXIT(strcpy(myfoo.empty, src),
               testing::KilledBySignal(SIGABRT), "");
   free(src);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 #endif
 
@@ -159,13 +221,17 @@
 // zero sized target with longer source (should fail)
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strcpy2_fortified2) {
+TEST_F(DEATHTEST, strcpy2_fortified2) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   char* src = strdup("1");
   ASSERT_EXIT(strcpy(myfoo.empty, src),
               testing::KilledBySignal(SIGABRT), "");
   free(src);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 #endif
 
@@ -173,59 +239,76 @@
 // one byte target with longer source (should fail)
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strcpy3_fortified2) {
+TEST_F(DEATHTEST, strcpy3_fortified2) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   char* src = strdup("12");
   ASSERT_EXIT(strcpy(myfoo.one, src),
               testing::KilledBySignal(SIGABRT), "");
   free(src);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 #endif
 
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strchr_fortified2) {
+TEST_F(DEATHTEST, strchr_fortified2) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   memcpy(myfoo.a, "0123456789", sizeof(myfoo.a));
   myfoo.b[0] = '\0';
   ASSERT_EXIT(printf("%s", strchr(myfoo.a, 'a')),
               testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 #endif
 
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strrchr_fortified2) {
+TEST_F(DEATHTEST, strrchr_fortified2) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   memcpy(myfoo.a, "0123456789", 10);
   memcpy(myfoo.b, "01234", 6);
   ASSERT_EXIT(printf("%s", strrchr(myfoo.a, 'a')),
               testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 #endif
 
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strlcpy_fortified2) {
+TEST_F(DEATHTEST, strlcpy_fortified2) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   strcpy(myfoo.a, "01");
   size_t n = strlen(myfoo.a);
   ASSERT_EXIT(strlcpy(myfoo.one, myfoo.a, n),
               testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 #endif
 
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strlcat_fortified2) {
+TEST_F(DEATHTEST, strlcat_fortified2) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   strcpy(myfoo.a, "01");
@@ -233,15 +316,16 @@
   size_t n = strlen(myfoo.a);
   ASSERT_EXIT(strlcat(myfoo.one, myfoo.a, n),
               testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 #endif
 
-#endif /* __BIONIC__ */
-
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strncat_fortified2) {
+TEST_F(DEATHTEST, strncat_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   size_t n = atoi("10"); // avoid compiler optimizations
@@ -253,7 +337,7 @@
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strncat2_fortified2) {
+TEST_F(DEATHTEST, strncat2_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   myfoo.a[0] = '\0';
@@ -262,7 +346,7 @@
 }
 #endif
 
-TEST(DEATHTEST, strncat3_fortified2) {
+TEST_F(DEATHTEST, strncat3_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); // unterminated string
@@ -274,7 +358,7 @@
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, strcat_fortified2) {
+TEST_F(DEATHTEST, strcat_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char src[11];
   strcpy(src, "0123456789");
@@ -284,7 +368,7 @@
 }
 #endif
 
-TEST(DEATHTEST, strcat2_fortified2) {
+TEST_F(DEATHTEST, strcat2_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); // unterminated string
@@ -292,7 +376,7 @@
   ASSERT_EXIT(strcat(myfoo.b, myfoo.a), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, snprintf_fortified2) {
+TEST_F(DEATHTEST, snprintf_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   strcpy(myfoo.a, "012345678");
@@ -300,7 +384,7 @@
   ASSERT_EXIT(snprintf(myfoo.b, n, "a%s", myfoo.a), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, bzero_fortified2) {
+TEST_F(DEATHTEST, bzero_fortified2) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   foo myfoo;
   memcpy(myfoo.b, "0123456789", sizeof(myfoo.b));
@@ -310,74 +394,106 @@
 
 #endif /* defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE=2 */
 
-#if __BIONIC__
 // multibyte target where we over fill (should fail)
-TEST(DEATHTEST, strcpy_fortified) {
+TEST_F(DEATHTEST, strcpy_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[10];
   char *orig = strdup("0123456789");
   ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
   free(orig);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 // zero sized target with "\0" source (should fail)
-TEST(DEATHTEST, strcpy2_fortified) {
+TEST_F(DEATHTEST, strcpy2_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[0];
   char *orig = strdup("");
   ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
   free(orig);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 // zero sized target with longer source (should fail)
-TEST(DEATHTEST, strcpy3_fortified) {
+TEST_F(DEATHTEST, strcpy3_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[0];
   char *orig = strdup("1");
   ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
   free(orig);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 // one byte target with longer source (should fail)
-TEST(DEATHTEST, strcpy4_fortified) {
+TEST_F(DEATHTEST, strcpy4_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[1];
   char *orig = strdup("12");
   ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
   free(orig);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
-TEST(DEATHTEST, strlen_fortified) {
+TEST_F(DEATHTEST, strlen_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[10];
   memcpy(buf, "0123456789", sizeof(buf));
   ASSERT_EXIT(printf("%zd", strlen(buf)), testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
-TEST(DEATHTEST, strchr_fortified) {
+TEST_F(DEATHTEST, strchr_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[10];
   memcpy(buf, "0123456789", sizeof(buf));
   ASSERT_EXIT(printf("%s", strchr(buf, 'a')), testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
-TEST(DEATHTEST, strrchr_fortified) {
+TEST_F(DEATHTEST, strrchr_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[10];
   memcpy(buf, "0123456789", sizeof(buf));
   ASSERT_EXIT(printf("%s", strrchr(buf, 'a')), testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
-TEST(DEATHTEST, strlcpy_fortified) {
+TEST_F(DEATHTEST, strlcpy_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char bufa[15];
   char bufb[10];
   strcpy(bufa, "01234567890123");
   size_t n = strlen(bufa);
   ASSERT_EXIT(strlcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
-TEST(DEATHTEST, strlcat_fortified) {
+TEST_F(DEATHTEST, strlcat_fortified) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char bufa[15];
   char bufb[10];
@@ -385,11 +501,12 @@
   strcpy(bufa, "01234567890123");
   size_t n = strlen(bufa);
   ASSERT_EXIT(strlcat(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
-#endif
-
-TEST(DEATHTEST, sprintf_fortified) {
+TEST_F(DEATHTEST, sprintf_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[10];
   char source_buf[15];
@@ -400,7 +517,7 @@
 #ifndef __clang__
 // This test is disabled in clang because clang doesn't properly detect
 // this buffer overflow. TODO: Fix clang.
-TEST(DEATHTEST, sprintf_malloc_fortified) {
+TEST_F(DEATHTEST, sprintf_malloc_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char* buf = (char *) malloc(10);
   char source_buf[11];
@@ -410,7 +527,7 @@
 }
 #endif
 
-TEST(DEATHTEST, sprintf2_fortified) {
+TEST_F(DEATHTEST, sprintf2_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[5];
   ASSERT_EXIT(sprintf(buf, "aaaaa"), testing::KilledBySignal(SIGABRT), "");
@@ -427,12 +544,12 @@
   return result;
 }
 
-TEST(DEATHTEST, vsprintf_fortified) {
+TEST_F(DEATHTEST, vsprintf_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(vsprintf_helper("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, vsprintf2_fortified) {
+TEST_F(DEATHTEST, vsprintf2_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(vsprintf_helper("0123456789"), testing::KilledBySignal(SIGABRT), "");
 }
@@ -449,17 +566,17 @@
   return result;
 }
 
-TEST(DEATHTEST, vsnprintf_fortified) {
+TEST_F(DEATHTEST, vsnprintf_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(vsnprintf_helper("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, vsnprintf2_fortified) {
+TEST_F(DEATHTEST, vsnprintf2_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(vsnprintf_helper("0123456789"), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, strncat_fortified) {
+TEST_F(DEATHTEST, strncat_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[10];
   size_t n = atoi("10"); // avoid compiler optimizations
@@ -467,7 +584,7 @@
   ASSERT_EXIT(strncat(buf, "9", n), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, strncat2_fortified) {
+TEST_F(DEATHTEST, strncat2_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[10];
   buf[0] = '\0';
@@ -475,7 +592,7 @@
   ASSERT_EXIT(strncat(buf, "0123456789", n), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, strcat_fortified) {
+TEST_F(DEATHTEST, strcat_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char src[11];
   strcpy(src, "0123456789");
@@ -484,7 +601,7 @@
   ASSERT_EXIT(strcat(buf, src), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, memmove_fortified) {
+TEST_F(DEATHTEST, memmove_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[20];
   strcpy(buf, "0123456789");
@@ -492,7 +609,7 @@
   ASSERT_EXIT(memmove(buf + 11, buf, n), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, memcpy_fortified) {
+TEST_F(DEATHTEST, memcpy_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char bufa[10];
   char bufb[10];
@@ -501,7 +618,24 @@
   ASSERT_EXIT(memcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, strncpy_fortified) {
+TEST_F(DEATHTEST, stpncpy_fortified) {
+  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+  char bufa[15];
+  char bufb[10];
+  strcpy(bufa, "01234567890123");
+  size_t n = strlen(bufa);
+  ASSERT_EXIT(stpncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
+}
+
+TEST_F(DEATHTEST, stpncpy2_fortified) {
+  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+  char dest[11];
+  char src[10];
+  memcpy(src, "0123456789", sizeof(src)); // src is not null terminated
+  ASSERT_EXIT(stpncpy(dest, src, sizeof(dest)), testing::KilledBySignal(SIGABRT), "");
+}
+
+TEST_F(DEATHTEST, strncpy_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char bufa[15];
   char bufb[10];
@@ -510,7 +644,8 @@
   ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, strncpy2_fortified) {
+
+TEST_F(DEATHTEST, strncpy2_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char dest[11];
   char src[10];
@@ -518,7 +653,7 @@
   ASSERT_EXIT(strncpy(dest, src, sizeof(dest)), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, snprintf_fortified) {
+TEST_F(DEATHTEST, snprintf_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char bufa[15];
   char bufb[10];
@@ -527,7 +662,7 @@
   ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, bzero_fortified) {
+TEST_F(DEATHTEST, bzero_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[10];
   memcpy(buf, "0123456789", sizeof(buf));
@@ -535,41 +670,46 @@
   ASSERT_EXIT(bzero(buf, n), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, umask_fortified) {
+TEST_F(DEATHTEST, umask_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   mode_t mask = atoi("1023");  // 01777 in octal
   ASSERT_EXIT(umask(mask), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, recv_fortified) {
+TEST_F(DEATHTEST, recv_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   size_t data_len = atoi("11"); // suppress compiler optimizations
   char buf[10];
   ASSERT_EXIT(recv(0, buf, data_len, 0), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, FD_ISSET_fortified) {
+TEST_F(DEATHTEST, FD_ISSET_fortified) {
+#if defined(__BIONIC__) // glibc catches this at compile-time.
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   fd_set set;
   memset(&set, 0, sizeof(set));
   ASSERT_EXIT(FD_ISSET(-1, &set), testing::KilledBySignal(SIGABRT), "");
+#endif
 }
 
-TEST(DEATHTEST, FD_ISSET_2_fortified) {
+TEST_F(DEATHTEST, FD_ISSET_2_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[1];
   fd_set* set = (fd_set*) buf;
   ASSERT_EXIT(FD_ISSET(0, set), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, FD_ZERO_fortified) {
+// gtest's ASSERT_EXIT needs a valid expression, but glibc has a do-while macro.
+static void FD_ZERO_function(fd_set* s) { FD_ZERO(s); }
+
+TEST_F(DEATHTEST, FD_ZERO_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[1];
   fd_set* set = (fd_set*) buf;
-  ASSERT_EXIT(FD_ZERO(set), testing::KilledBySignal(SIGABRT), "");
+  ASSERT_EXIT(FD_ZERO_function(set), testing::KilledBySignal(SIGABRT), "");
 }
 
-TEST(DEATHTEST, read_fortified) {
+TEST_F(DEATHTEST, read_fortified) {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   char buf[1];
   size_t ct = atoi("2"); // prevent optimizations
@@ -732,6 +872,45 @@
   ASSERT_EQ('\0',  buf[9]);
 }
 
+TEST(TEST_NAME, stpncpy) {
+  char src[10];
+  char dst[10];
+  memcpy(src, "0123456789", sizeof(src)); // non null terminated string
+  stpncpy(dst, src, sizeof(dst));
+  ASSERT_EQ('0', dst[0]);
+  ASSERT_EQ('1', dst[1]);
+  ASSERT_EQ('2', dst[2]);
+  ASSERT_EQ('3', dst[3]);
+  ASSERT_EQ('4', dst[4]);
+  ASSERT_EQ('5', dst[5]);
+  ASSERT_EQ('6', dst[6]);
+  ASSERT_EQ('7', dst[7]);
+  ASSERT_EQ('8', dst[8]);
+  ASSERT_EQ('9', dst[9]);
+}
+
+TEST(TEST_NAME, stpncpy2) {
+  char src[10];
+  char dst[15];
+  memcpy(src, "012345678\0", sizeof(src));
+  stpncpy(dst, src, sizeof(dst));
+  ASSERT_EQ('0',  dst[0]);
+  ASSERT_EQ('1',  dst[1]);
+  ASSERT_EQ('2',  dst[2]);
+  ASSERT_EQ('3',  dst[3]);
+  ASSERT_EQ('4',  dst[4]);
+  ASSERT_EQ('5',  dst[5]);
+  ASSERT_EQ('6',  dst[6]);
+  ASSERT_EQ('7',  dst[7]);
+  ASSERT_EQ('8',  dst[8]);
+  ASSERT_EQ('\0', dst[9]);
+  ASSERT_EQ('\0', dst[10]);
+  ASSERT_EQ('\0', dst[11]);
+  ASSERT_EQ('\0', dst[12]);
+  ASSERT_EQ('\0', dst[13]);
+  ASSERT_EQ('\0', dst[14]);
+}
+
 TEST(TEST_NAME, strncpy) {
   char src[10];
   char dst[10];
@@ -790,22 +969,22 @@
   ASSERT_EQ('\0', buf[9]);
 }
 
+extern "C" char* __stpcpy_chk(char*, const char*, size_t);
+
+TEST(TEST_NAME, stpcpy_chk_max_int_size) {
+  char buf[10];
+  char* res = __stpcpy_chk(buf, "012345678", (size_t)-1);
+  ASSERT_EQ(buf + strlen("012345678"), res);
+  ASSERT_STREQ("012345678", buf);
+}
+
 extern "C" char* __strcpy_chk(char*, const char*, size_t);
 
 TEST(TEST_NAME, strcpy_chk_max_int_size) {
   char buf[10];
   char* res = __strcpy_chk(buf, "012345678", (size_t)-1);
   ASSERT_EQ(buf, res);
-  ASSERT_EQ('0',  buf[0]);
-  ASSERT_EQ('1',  buf[1]);
-  ASSERT_EQ('2',  buf[2]);
-  ASSERT_EQ('3',  buf[3]);
-  ASSERT_EQ('4',  buf[4]);
-  ASSERT_EQ('5',  buf[5]);
-  ASSERT_EQ('6',  buf[6]);
-  ASSERT_EQ('7',  buf[7]);
-  ASSERT_EQ('8',  buf[8]);
-  ASSERT_EQ('\0', buf[9]);
+  ASSERT_STREQ("012345678", buf);
 }
 
 extern "C" void* __memcpy_chk(void*, const void*, size_t, size_t);
diff --git a/tests/ftw_test.cpp b/tests/ftw_test.cpp
new file mode 100644
index 0000000..6d3a308
--- /dev/null
+++ b/tests/ftw_test.cpp
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include "TemporaryFile.h"
+
+#include <ftw.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+void sanity_check_ftw(const char* fpath, const struct stat* sb, int tflag) {
+  ASSERT_TRUE(fpath != NULL);
+  ASSERT_TRUE(sb != NULL);
+  bool is_dir = S_ISDIR(sb->st_mode);
+  ASSERT_TRUE((is_dir && tflag == FTW_D) || (!is_dir && tflag == FTW_F));
+}
+
+void sanity_check_nftw(
+    const char* fpath, const struct stat* sb, int tflag, struct FTW* ftwbuf) {
+  sanity_check_ftw(fpath, sb, tflag);
+  // either the parent dir or the file
+  bool is_dir = S_ISDIR(sb->st_mode);
+  ASSERT_TRUE(
+    (is_dir && ftwbuf->level == 0) || (!is_dir && ftwbuf->level == 1));
+}
+
+int check_ftw(const char* fpath, const struct stat* sb, int tflag) {
+  sanity_check_ftw(fpath, sb, tflag);
+  return 0;
+}
+
+int check_ftw64(const char* fpath, const struct stat64* sb, int tflag) {
+  sanity_check_ftw(fpath, reinterpret_cast<const struct stat*>(sb), tflag);
+  return 0;
+}
+
+int check_nftw(
+  const char* fpath, const struct stat* sb, int tflag, struct FTW* ftwbuf) {
+  sanity_check_nftw(fpath, sb, tflag, ftwbuf);
+  return 0;
+}
+
+int check_nftw64(
+  const char* fpath, const struct stat64* sb, int tflag, struct FTW* ftwbuf) {
+  sanity_check_nftw(fpath, reinterpret_cast<const struct stat*>(sb),
+    tflag, ftwbuf);
+  return 0;
+}
+
+TEST(ftw, ftw) {
+  TemporaryDir td;
+  TemporaryFile tf(td.dirname);
+  ftw(td.dirname, check_ftw, 1);
+}
+
+TEST(ftw, ftw64) {
+  TemporaryDir td;
+  GenericTemporaryFile<mkstemp64> tf(td.dirname);
+  ftw64(td.dirname, check_ftw64, 1);
+}
+
+TEST(ftw, nftw) {
+  TemporaryDir td;
+  TemporaryFile tf(td.dirname);
+  nftw(td.dirname, check_nftw, 1, 0);
+}
+
+TEST(ftw, nftw64) {
+  TemporaryDir td;
+  GenericTemporaryFile<mkstemp64> tf(td.dirname);
+  nftw64(td.dirname, check_nftw64, 1, 0);
+}
diff --git a/tests/getauxval_test.cpp b/tests/getauxval_test.cpp
index 01c11c3..51c9db8 100644
--- a/tests/getauxval_test.cpp
+++ b/tests/getauxval_test.cpp
@@ -31,10 +31,11 @@
 #endif
 
 #if defined(GETAUXVAL_CAN_COMPILE)
-
 #include <sys/auxv.h>
+#endif
 
 TEST(getauxval, expected_values) {
+#if defined(GETAUXVAL_CAN_COMPILE)
   ASSERT_EQ((unsigned long int) 0, getauxval(AT_SECURE));
   ASSERT_EQ(getuid(), getauxval(AT_UID));
   ASSERT_EQ(geteuid(), getauxval(AT_EUID));
@@ -46,10 +47,15 @@
   ASSERT_NE((unsigned long int) 0, getauxval(AT_PHNUM));
   ASSERT_NE((unsigned long int) 0, getauxval(AT_ENTRY));
   ASSERT_NE((unsigned long int) 0, getauxval(AT_PAGESZ));
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
 }
 
 TEST(getauxval, unexpected_values) {
+#if defined(GETAUXVAL_CAN_COMPILE)
   ASSERT_EQ((unsigned long int) 0, getauxval(0xdeadbeef));
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
 }
-
-#endif /* GETAUXVAL_CAN_COMPILE */
diff --git a/tests/inttypes_test.cpp b/tests/inttypes_test.cpp
index df02d1f..e588503 100644
--- a/tests/inttypes_test.cpp
+++ b/tests/inttypes_test.cpp
@@ -19,7 +19,6 @@
 #include <stdio.h>
 #include <inttypes.h>
 
-#if defined(__BIONIC__) // Doesn't work on glibc because we use -m32.
 TEST(inttypes, misc) {
   char buf[512];
 
@@ -39,4 +38,11 @@
   sscanf(buf, "%08" SCNuPTR, &u);
   sscanf(buf, "%08" SCNxPTR, &u);
 }
-#endif
+
+TEST(inttypes, wcstoimax) {
+  ASSERT_EQ(123, wcstoimax(L"123", NULL, 10));
+}
+
+TEST(inttypes, wcstoumax) {
+  ASSERT_EQ(123U, wcstoumax(L"123", NULL, 10));
+}
diff --git a/tests/libc_logging_test.cpp b/tests/libc_logging_test.cpp
index c44b85b..950161e 100644
--- a/tests/libc_logging_test.cpp
+++ b/tests/libc_logging_test.cpp
@@ -17,12 +17,12 @@
 #include <gtest/gtest.h>
 
 #if defined(__BIONIC__)
-
 #include "../libc/bionic/libc_logging.cpp"
-
 extern int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...);
+#endif // __BIONIC__
 
 TEST(libc_logging, smoke) {
+#if defined(__BIONIC__)
   char buf[BUFSIZ];
 
   __libc_format_buffer(buf, sizeof(buf), "a");
@@ -104,21 +104,33 @@
 
   __libc_format_buffer(buf, sizeof(buf), "a%lld,%d,%d,%dz", 0x1000000000LL, 6, 7, 8);
   EXPECT_STREQ("a68719476736,6,7,8z", buf);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(libc_logging, d_INT_MAX) {
+#if defined(__BIONIC__)
   char buf[BUFSIZ];
   __libc_format_buffer(buf, sizeof(buf), "%d", INT_MAX);
   EXPECT_STREQ("2147483647", buf);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(libc_logging, d_INT_MIN) {
+#if defined(__BIONIC__)
   char buf[BUFSIZ];
   __libc_format_buffer(buf, sizeof(buf), "%d", INT_MIN);
   EXPECT_STREQ("-2147483648", buf);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(libc_logging, ld_LONG_MAX) {
+#if defined(__BIONIC__)
   char buf[BUFSIZ];
   __libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MAX);
 #if __LP64__
@@ -126,9 +138,13 @@
 #else
   EXPECT_STREQ("2147483647", buf);
 #endif
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(libc_logging, ld_LONG_MIN) {
+#if defined(__BIONIC__)
   char buf[BUFSIZ];
   __libc_format_buffer(buf, sizeof(buf), "%ld", LONG_MIN);
 #if __LP64__
@@ -136,18 +152,27 @@
 #else
   EXPECT_STREQ("-2147483648", buf);
 #endif
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(libc_logging, lld_LLONG_MAX) {
+#if defined(__BIONIC__)
   char buf[BUFSIZ];
   __libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MAX);
   EXPECT_STREQ("9223372036854775807", buf);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(libc_logging, lld_LLONG_MIN) {
+#if defined(__BIONIC__)
   char buf[BUFSIZ];
   __libc_format_buffer(buf, sizeof(buf), "%lld", LLONG_MIN);
   EXPECT_STREQ("-9223372036854775808", buf);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-
-#endif
diff --git a/tests/libgen_test.cpp b/tests/libgen_test.cpp
index c2c01f6..3958f81 100644
--- a/tests/libgen_test.cpp
+++ b/tests/libgen_test.cpp
@@ -38,7 +38,9 @@
   free(writable_in);
 }
 
-TEST(libgen, basename) {
+// Do not use basename as the test name, it's defined to another value in glibc
+// so leads to a differently named test on host versus target architectures.
+TEST(libgen, basename_smoke) {
   TestBasename(NULL, ".");
   TestBasename("", ".");
   TestBasename("/usr/lib", "lib");
@@ -62,8 +64,7 @@
   TestDirname("/", "/");
 }
 
-#if __BIONIC__
-
+#if defined(__BIONIC__) && !defined(__LP64__)
 static void TestBasename(const char* in, const char* expected_out, int expected_rc,
                          char* buf, size_t buf_size, int expected_errno) {
   errno = 0;
@@ -85,8 +86,10 @@
   }
   ASSERT_EQ(expected_errno, errno) << in;
 }
+#endif // __BIONIC__
 
 TEST(libgen, basename_r) {
+#if defined(__BIONIC__) && !defined(__LP64__)
   char buf[256];
   TestBasename("", ".",  1, NULL, 0, 0);
   TestBasename("", ".", -1, buf, 0, ERANGE);
@@ -99,9 +102,13 @@
   TestBasename("/", "/", 1, buf, sizeof(buf), 0);
   TestBasename(".", ".", 1, buf, sizeof(buf), 0);
   TestBasename("..", "..", 2, buf, sizeof(buf), 0);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(libgen, dirname_r) {
+#if defined(__BIONIC__) && !defined(__LP64__)
   char buf[256];
   TestDirname("", ".",  1, NULL, 0, 0);
   TestDirname("", ".", -1, buf, 0, ERANGE);
@@ -112,6 +119,7 @@
   TestDirname("usr", ".", 1, buf, sizeof(buf), 0);
   TestDirname(".", ".", 1, buf, sizeof(buf), 0);
   TestDirname("..", ".", 1, buf, sizeof(buf), 0);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-
-#endif
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
new file mode 100644
index 0000000..75df539
--- /dev/null
+++ b/tests/libs/Android.mk
@@ -0,0 +1,142 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+TEST_PATH := $(LOCAL_PATH)/..
+
+# -----------------------------------------------------------------------------
+# Library used by dlfcn tests.
+# -----------------------------------------------------------------------------
+ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
+no-elf-hash-table-library_src_files := \
+    empty.cpp \
+
+no-elf-hash-table-library_ldflags := \
+    -Wl,--hash-style=gnu \
+
+module := no-elf-hash-table-library
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+endif
+
+# -----------------------------------------------------------------------------
+# Library used by dlext tests - with GNU RELRO program header
+# -----------------------------------------------------------------------------
+libdlext_test_src_files := \
+    dlext_test_library.cpp \
+
+libdlext_test_ldflags := \
+    -Wl,-z,relro \
+
+module := libdlext_test
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# create symlink to libdlext_test.so for symlink test
+# -----------------------------------------------------------------------------
+# Use = instead of := to defer the evaluation of $@
+$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD = \
+    $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
+
+ifneq ($(TARGET_2ND_ARCH),)
+# link 64 bit .so
+$(TARGET_OUT)/lib64/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \
+    $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
+endif
+
+# -----------------------------------------------------------------------------
+# Library used by dlext tests - without GNU RELRO program header
+# -----------------------------------------------------------------------------
+libdlext_test_norelro_src_files := \
+    dlext_test_library.cpp \
+
+libdlext_test_norelro_ldflags := \
+    -Wl,-z,norelro \
+
+module := libdlext_test_norelro
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library used by dlext tests - different name non-default location
+# -----------------------------------------------------------------------------
+libdlext_test_fd_src_files := \
+    dlext_test_library.cpp \
+
+libdlext_test_fd_install_to_out_data := true
+module := libdlext_test_fd
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library used by dlfcn tests
+# -----------------------------------------------------------------------------
+libtest_simple_src_files := \
+    dlopen_testlib_simple.cpp
+
+module := libtest_simple
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library with dependency used by dlfcn tests
+# -----------------------------------------------------------------------------
+libtest_with_dependency_src_files := \
+    dlopen_testlib_simple.cpp
+
+libtest_with_dependency_shared_libraries := libdlext_test
+
+module := libtest_with_dependency
+build_type := target
+build_target := SHARED_LIBRARY
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library used by atexit tests
+# -----------------------------------------------------------------------------
+
+libtest_atexit_src_files := \
+    atexit_testlib.cpp
+
+module := libtest_atexit
+build_target := SHARED_LIBRARY
+build_type := target
+include $(TEST_PATH)/Android.build.mk
+build_type := host
+include $(TEST_PATH)/Android.build.mk
+
+# -----------------------------------------------------------------------------
+# Library with weak function
+# -----------------------------------------------------------------------------
+libtest_dlsym_weak_func_src_files := \
+    dlsym_weak_function.cpp
+
+module := libtest_dlsym_weak_func
+build_target := SHARED_LIBRARY
+build_type := target
+include $(TEST_PATH)/Android.build.mk
+build_type := host
+include $(TEST_PATH)/Android.build.mk
diff --git a/tests/libs/atexit_testlib.cpp b/tests/libs/atexit_testlib.cpp
new file mode 100644
index 0000000..d35f57b
--- /dev/null
+++ b/tests/libs/atexit_testlib.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string>
+
+// use external control number from main test
+static std::string* atexit_sequence = NULL;
+static bool* atexit_valid_this_in_static_dtor = NULL;
+
+static class AtExitStaticClass {
+ public:
+  AtExitStaticClass() { expected_this = this; }
+  ~AtExitStaticClass() {
+    if (atexit_valid_this_in_static_dtor) {
+      *atexit_valid_this_in_static_dtor = (expected_this == this);
+    }
+  }
+ private:
+  static const AtExitStaticClass* expected_this;
+
+} static_obj;
+
+const AtExitStaticClass* AtExitStaticClass::expected_this = NULL;
+
+// 4
+static void atexit_handler_from_atexit_from_atexit2() {
+  *atexit_sequence += " on";
+}
+
+// 3
+static void atexit_handler_from_atexit_from_atexit1() {
+  *atexit_sequence += " sat";
+}
+
+// 2
+static void atexit_handler_from_atexit() {
+  *atexit_sequence += " Dumpty";
+  // register 2 others
+  atexit(atexit_handler_from_atexit_from_atexit2);
+  atexit(atexit_handler_from_atexit_from_atexit1);
+}
+
+// 1
+static void atexit_handler_with_atexit() {
+  *atexit_sequence += "Humpty";
+  atexit(atexit_handler_from_atexit);
+}
+
+// last
+static void atexit_handler_regular() {
+  *atexit_sequence += " a wall";
+}
+
+extern "C" void register_atexit(std::string* sequence, bool* valid_this_in_static_dtor) {
+  atexit_sequence = sequence;
+  atexit_valid_this_in_static_dtor = valid_this_in_static_dtor;
+  atexit(atexit_handler_regular);
+  atexit(atexit_handler_with_atexit);
+}
+
diff --git a/tests/libs/dlext_test_library.cpp b/tests/libs/dlext_test_library.cpp
new file mode 100644
index 0000000..5c04329
--- /dev/null
+++ b/tests/libs/dlext_test_library.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+class A {
+public:
+  virtual int getRandomNumber() {
+    return 4;  // chosen by fair dice roll.
+               // guaranteed to be random.
+  }
+
+  virtual ~A() {}
+};
+
+A a;
+
+// nested macros to make it easy to define a large amount of read-only data
+// which will require relocation.
+#define A_16 &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a,
+#define A_128 A_16 A_16 A_16 A_16 A_16 A_16 A_16 A_16
+#define A_1024 A_128 A_128 A_128 A_128 A_128 A_128 A_128 A_128
+
+extern "C" A* const lots_of_relro[] = {
+  A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 A_1024
+};
+
+extern "C" int getRandomNumber() {
+  // access the relro section (twice, in fact, once for the pointer, and once
+  // for the vtable of A) to check it's actually there.
+  return lots_of_relro[0]->getRandomNumber();
+}
diff --git a/tests/libs/dlopen_testlib_simple.cpp b/tests/libs/dlopen_testlib_simple.cpp
new file mode 100644
index 0000000..afe54b4
--- /dev/null
+++ b/tests/libs/dlopen_testlib_simple.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+
+uint32_t dlopen_testlib_taxicab_number = 1729;
+
+bool dlopen_testlib_simple_func() {
+  return true;
+}
diff --git a/tests/libs/dlsym_weak_function.cpp b/tests/libs/dlsym_weak_function.cpp
new file mode 100644
index 0000000..e38f2b8
--- /dev/null
+++ b/tests/libs/dlsym_weak_function.cpp
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern "C" int __attribute__((weak)) weak_func() {
+  return 42;
+}
+
diff --git a/tests/empty.cpp b/tests/libs/empty.cpp
similarity index 100%
rename from tests/empty.cpp
rename to tests/libs/empty.cpp
diff --git a/tests/locale_test.cpp b/tests/locale_test.cpp
new file mode 100644
index 0000000..7ec607a
--- /dev/null
+++ b/tests/locale_test.cpp
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+
+TEST(locale, localeconv) {
+  EXPECT_STREQ(".", localeconv()->decimal_point);
+  EXPECT_STREQ("", localeconv()->thousands_sep);
+  EXPECT_STREQ("", localeconv()->grouping);
+  EXPECT_STREQ("", localeconv()->int_curr_symbol);
+  EXPECT_STREQ("", localeconv()->currency_symbol);
+  EXPECT_STREQ("", localeconv()->mon_decimal_point);
+  EXPECT_STREQ("", localeconv()->mon_thousands_sep);
+  EXPECT_STREQ("", localeconv()->mon_grouping);
+  EXPECT_STREQ("", localeconv()->positive_sign);
+  EXPECT_STREQ("", localeconv()->negative_sign);
+  EXPECT_EQ(CHAR_MAX, localeconv()->int_frac_digits);
+  EXPECT_EQ(CHAR_MAX, localeconv()->frac_digits);
+  EXPECT_EQ(CHAR_MAX, localeconv()->p_cs_precedes);
+  EXPECT_EQ(CHAR_MAX, localeconv()->p_sep_by_space);
+  EXPECT_EQ(CHAR_MAX, localeconv()->n_cs_precedes);
+  EXPECT_EQ(CHAR_MAX, localeconv()->n_sep_by_space);
+  EXPECT_EQ(CHAR_MAX, localeconv()->p_sign_posn);
+  EXPECT_EQ(CHAR_MAX, localeconv()->n_sign_posn);
+  EXPECT_EQ(CHAR_MAX, localeconv()->int_p_cs_precedes);
+  EXPECT_EQ(CHAR_MAX, localeconv()->int_p_sep_by_space);
+  EXPECT_EQ(CHAR_MAX, localeconv()->int_n_cs_precedes);
+  EXPECT_EQ(CHAR_MAX, localeconv()->int_n_sep_by_space);
+  EXPECT_EQ(CHAR_MAX, localeconv()->int_p_sign_posn);
+  EXPECT_EQ(CHAR_MAX, localeconv()->int_n_sign_posn);
+}
+
+TEST(locale, setlocale) {
+  EXPECT_STREQ("C.UTF-8", setlocale(LC_ALL, NULL));
+  EXPECT_STREQ("C.UTF-8", setlocale(LC_CTYPE, NULL));
+
+  errno = 0;
+  EXPECT_EQ(NULL, setlocale(-1, NULL));
+  EXPECT_EQ(EINVAL, errno);
+  errno = 0;
+  EXPECT_EQ(NULL, setlocale(13, NULL));
+  EXPECT_EQ(EINVAL, errno);
+
+#if defined(__BIONIC__)
+  // The "" locale is implementation-defined. For bionic, it's the C locale.
+  // glibc will give us something like "en_US.UTF-8", depending on the user's configuration.
+  EXPECT_STREQ("C", setlocale(LC_ALL, ""));
+#endif
+  EXPECT_STREQ("C", setlocale(LC_ALL, "C"));
+  EXPECT_STREQ("C", setlocale(LC_ALL, "POSIX"));
+
+  errno = 0;
+  EXPECT_EQ(NULL, setlocale(LC_ALL, "this-is-not-a-locale"));
+  EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
+}
+
+TEST(locale, newlocale) {
+  errno = 0;
+  EXPECT_EQ(0, newlocale(1 << 20, "C", 0));
+  EXPECT_EQ(EINVAL, errno);
+
+  locale_t l = newlocale(LC_ALL, "C", 0);
+  ASSERT_TRUE(l != NULL);
+  freelocale(l);
+
+  errno = 0;
+  EXPECT_EQ(0, newlocale(LC_ALL, "this-is-not-a-locale", 0));
+  EXPECT_EQ(ENOENT, errno); // POSIX specified, not an implementation detail!
+}
+
+TEST(locale, duplocale) {
+  locale_t cloned_global = duplocale(LC_GLOBAL_LOCALE);
+  ASSERT_TRUE(cloned_global != NULL);
+  freelocale(cloned_global);
+}
+
+TEST(locale, uselocale) {
+  locale_t original = uselocale(NULL);
+  EXPECT_FALSE(original == 0);
+  EXPECT_EQ(LC_GLOBAL_LOCALE, original);
+
+  locale_t n = newlocale(LC_ALL, "C", 0);
+  EXPECT_FALSE(n == 0);
+  EXPECT_FALSE(n == original);
+
+  locale_t old = uselocale(n);
+  EXPECT_TRUE(old == original);
+
+  EXPECT_EQ(n, uselocale(NULL));
+}
+
+TEST(locale, mb_cur_max) {
+  // We can't reliably test the behavior with setlocale(3) or the behavior for
+  // initial program conditions because (unless we're the only test that was
+  // run), another test has almost certainly called uselocale(3) in this thread.
+  // See b/16685652.
+  locale_t cloc = newlocale(LC_ALL, "C", 0);
+  locale_t cloc_utf8 = newlocale(LC_ALL, "C.UTF-8", 0);
+
+  locale_t old_locale = uselocale(cloc);
+  ASSERT_EQ(1U, MB_CUR_MAX);
+  uselocale(cloc_utf8);
+  ASSERT_EQ(4U, MB_CUR_MAX);
+
+  uselocale(old_locale);
+  freelocale(cloc);
+  freelocale(cloc_utf8);
+}
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 259853d..6b7a28b 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -16,18 +16,28 @@
 
 #include <gtest/gtest.h>
 
+#include <limits.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <malloc.h>
+#include <unistd.h>
+
+#include "private/bionic_config.h"
 
 TEST(malloc, malloc_std) {
   // Simple malloc test.
   void *ptr = malloc(100);
   ASSERT_TRUE(ptr != NULL);
   ASSERT_LE(100U, malloc_usable_size(ptr));
-
   free(ptr);
 }
 
+TEST(malloc, malloc_overflow) {
+  errno = 0;
+  ASSERT_EQ(NULL, malloc(SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+}
+
 TEST(malloc, calloc_std) {
   // Simple calloc test.
   size_t alloc_len = 100;
@@ -37,24 +47,67 @@
   for (size_t i = 0; i < alloc_len; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
-
   free(ptr);
 }
 
+TEST(malloc, calloc_illegal) {
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(-1, 100));
+  ASSERT_EQ(ENOMEM, errno);
+}
+
+TEST(malloc, calloc_overflow) {
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(1, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(SIZE_MAX, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(2, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  errno = 0;
+  ASSERT_EQ(NULL, calloc(SIZE_MAX, 2));
+  ASSERT_EQ(ENOMEM, errno);
+}
+
 TEST(malloc, memalign_multiple) {
   // Memalign test where the alignment is any value.
   for (size_t i = 0; i <= 12; i++) {
     for (size_t alignment = 1 << i; alignment < (1U << (i+1)); alignment++) {
-      char *ptr = (char*)memalign(alignment, 100);
-      ASSERT_TRUE(ptr != NULL);
-      ASSERT_LE(100U, malloc_usable_size(ptr));
-      ASSERT_EQ(0, (intptr_t)ptr % (1 << i));
-
+      char *ptr = reinterpret_cast<char*>(memalign(alignment, 100));
+      ASSERT_TRUE(ptr != NULL) << "Failed at alignment " << alignment;
+      ASSERT_LE(100U, malloc_usable_size(ptr)) << "Failed at alignment " << alignment;
+      ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) % ((1U << i)))
+          << "Failed at alignment " << alignment;
       free(ptr);
     }
   }
 }
 
+TEST(malloc, memalign_overflow) {
+  ASSERT_EQ(NULL, memalign(4096, SIZE_MAX));
+}
+
+TEST(malloc, memalign_non_power2) {
+  void* ptr;
+  for (size_t align = 0; align <= 256; align++) {
+    ptr = memalign(align, 1024);
+    ASSERT_TRUE(ptr != NULL) << "Failed at align " << align;
+    free(ptr);
+  }
+}
+
+TEST(malloc, posix_memalign_non_power2) {
+  void* ptr;
+  ASSERT_EQ(EINVAL, posix_memalign(&ptr, 17, 1024));
+}
+
+TEST(malloc, posix_memalign_overflow) {
+  void* ptr;
+  ASSERT_NE(0, posix_memalign(&ptr, 16, SIZE_MAX));
+}
+
 TEST(malloc, memalign_realloc) {
   // Memalign and then realloc the pointer a couple of times.
   for (size_t alignment = 1; alignment <= 4096; alignment <<= 1) {
@@ -87,7 +140,6 @@
     for (size_t i = 0; i < 250; i++) {
       ASSERT_EQ(0x67, ptr[i]);
     }
-
     free(ptr);
   }
 }
@@ -105,7 +157,6 @@
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(67, ptr[i]);
   }
-
   free(ptr);
 }
 
@@ -122,7 +173,6 @@
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(67, ptr[i]);
   }
-
   free(ptr);
 }
 
@@ -161,9 +211,9 @@
   for (size_t i = 0; i < 150; i++) {
     ASSERT_EQ(0x23, ptr[i]);
   }
-
   free(ptr);
 }
+
 TEST(malloc, calloc_realloc_larger) {
   // Realloc to a larger size, calloc is used for the original allocation.
   char *ptr = (char *)calloc(1, 100);
@@ -176,7 +226,6 @@
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
-
   free(ptr);
 }
 
@@ -192,7 +241,6 @@
   for (size_t i = 0; i < 100; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
-
   free(ptr);
 }
 
@@ -230,6 +278,47 @@
   for (size_t i = 0; i < 150; i++) {
     ASSERT_EQ(0, ptr[i]);
   }
-
   free(ptr);
 }
+
+TEST(malloc, realloc_overflow) {
+  errno = 0;
+  ASSERT_EQ(NULL, realloc(NULL, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  void* ptr = malloc(100);
+  ASSERT_TRUE(ptr != NULL);
+  errno = 0;
+  ASSERT_EQ(NULL, realloc(ptr, SIZE_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+  free(ptr);
+}
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+extern "C" void* pvalloc(size_t);
+extern "C" void* valloc(size_t);
+
+TEST(malloc, pvalloc_std) {
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  void* ptr = pvalloc(100);
+  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE((reinterpret_cast<uintptr_t>(ptr) & (pagesize-1)) == 0);
+  ASSERT_LE(pagesize, malloc_usable_size(ptr));
+  free(ptr);
+}
+
+TEST(malloc, pvalloc_overflow) {
+  ASSERT_EQ(NULL, pvalloc(SIZE_MAX));
+}
+
+TEST(malloc, valloc_std) {
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+  void* ptr = pvalloc(100);
+  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE((reinterpret_cast<uintptr_t>(ptr) & (pagesize-1)) == 0);
+  free(ptr);
+}
+
+TEST(malloc, valloc_overflow) {
+  ASSERT_EQ(NULL, valloc(SIZE_MAX));
+}
+#endif
diff --git a/tests/math_cos_test.cpp b/tests/math_cos_test.cpp
new file mode 100644
index 0000000..c0a2d82
--- /dev/null
+++ b/tests/math_cos_test.cpp
@@ -0,0 +1,5643 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  double expected;
+  double call_data;
+} cos_intel_data_t;
+
+static cos_intel_data_t g_cos_intel_data[] = {
+  { // Entry 0
+    0x1.c1a27ae836f128000000000000504e9bp-1,
+    0x1.feb1f7920e248p-2
+  },
+  { // Entry 1
+    0x1.c1a27ae836f128000000000000504e9bp-1,
+    -0x1.feb1f7920e248p-2
+  },
+  { // Entry 2
+    0x1.78daf01036d0cfffffffffffff9890d6p-1,
+    0x1.7cb7648526f99p-1
+  },
+  { // Entry 3
+    0x1.78daf01036d0cfffffffffffff9890d6p-1,
+    -0x1.7cb7648526f99p-1
+  },
+  { // Entry 4
+    0x1.ff8eb6a91ecb000000000000001f8f56p-1,
+    0x1.549ec0c0c5afap-5
+  },
+  { // Entry 5
+    0x1.ff8eb6a91ecb000000000000001f8f56p-1,
+    -0x1.549ec0c0c5afap-5
+  },
+  { // Entry 6
+    0x1.fed0476fc75c9800000000000020b13ep-1,
+    0x1.16e534ee36580p-4
+  },
+  { // Entry 7
+    0x1.fed0476fc75c9800000000000020b13ep-1,
+    -0x1.16e534ee36580p-4
+  },
+  { // Entry 8
+    0x1.f10fc61e2c78efffffffffffff87666ap-1,
+    0x1.efeef61d39ac2p-3
+  },
+  { // Entry 9
+    0x1.f10fc61e2c78efffffffffffff87666ap-1,
+    -0x1.efeef61d39ac2p-3
+  },
+  { // Entry 10
+    0x1.434a3645be2087ffffffffffff72d0aep-1,
+    0x1.c65a170474549p-1
+  },
+  { // Entry 11
+    0x1.434a3645be2087ffffffffffff72d0aep-1,
+    -0x1.c65a170474549p-1
+  },
+  { // Entry 12
+    0x1.337fc5b072c52800000000000017fe77p-3,
+    0x1.6b8a6273d7c21p0
+  },
+  { // Entry 13
+    0x1.337fc5b072c52800000000000017fe77p-3,
+    -0x1.6b8a6273d7c21p0
+  },
+  { // Entry 14
+    0x1.efa7cddb128fb8004356877b74ee8abdp-1,
+    -0x1.036f4ba7e90aap-2
+  },
+  { // Entry 15
+    0x1.efa7cddb128fb8004356877b74ee8abdp-1,
+    0x1.036f4ba7e90aap-2
+  },
+  { // Entry 16
+    0x1.fffffffffffffffb5117fee2eda7f13ep-1,
+    -0x1.1500766c9df20p-31
+  },
+  { // Entry 17
+    0x1.fffffffffffffffb5117fee2eda7f13ep-1,
+    0x1.1500766c9df20p-31
+  },
+  { // Entry 18
+    0x1.ec231802917bdffa627ab6a59abe3f7dp-1,
+    -0x1.1e2a1563e068ep-2
+  },
+  { // Entry 19
+    0x1.ec231802917bdffa627ab6a59abe3f7dp-1,
+    0x1.1e2a1563e068ep-2
+  },
+  { // Entry 20
+    0x1.dc044ac92b7fb9007913c87db76fa49fp-8,
+    -0x1.2115aa73f8d05p5
+  },
+  { // Entry 21
+    0x1.dc044ac92b7fb9007913c87db76fa49fp-8,
+    0x1.2115aa73f8d05p5
+  },
+  { // Entry 22
+    0x1.d1fa67c50dd527f6e9abbb0bd0664ab9p-4,
+    -0x1.34e3bcdf8f69ap2
+  },
+  { // Entry 23
+    0x1.d1fa67c50dd527f6e9abbb0bd0664ab9p-4,
+    0x1.34e3bcdf8f69ap2
+  },
+  { // Entry 24
+    0x1.e2f8d19fb8db88056dcddd76f5a05c20p-2,
+    -0x1.380000000000bp7
+  },
+  { // Entry 25
+    0x1.e2f8d19fb8db88056dcddd76f5a05c20p-2,
+    0x1.380000000000bp7
+  },
+  { // Entry 26
+    0x1.8da9c90c3eda17f5bd708cfc414ff1b8p-1,
+    -0x1.440000004p6
+  },
+  { // Entry 27
+    0x1.8da9c90c3eda17f5bd708cfc414ff1b8p-1,
+    0x1.440000004p6
+  },
+  { // Entry 28
+    0x1.b59b320603f837ff015e2a961e75946ep-1,
+    -0x1.550c8ee67a4c4p29
+  },
+  { // Entry 29
+    0x1.b59b320603f837ff015e2a961e75946ep-1,
+    0x1.550c8ee67a4c4p29
+  },
+  { // Entry 30
+    0x1.ffffff7af6c887e5f3186371a17dd81fp-1,
+    -0x1.711789fdb2e8ap-13
+  },
+  { // Entry 31
+    0x1.ffffff7af6c887e5f3186371a17dd81fp-1,
+    0x1.711789fdb2e8ap-13
+  },
+  { // Entry 32
+    0x1.c1b68ebb0b4fe82e8e99f9d425ee901ap-2,
+    -0x1.77e000002p8
+  },
+  { // Entry 33
+    0x1.c1b68ebb0b4fe82e8e99f9d425ee901ap-2,
+    0x1.77e000002p8
+  },
+  { // Entry 34
+    0x1.1161e1dad76dbfd55f08c4a4a90bd547p-4,
+    -0x1.8106561931b43p0
+  },
+  { // Entry 35
+    0x1.1161e1dad76dbfd55f08c4a4a90bd547p-4,
+    0x1.8106561931b43p0
+  },
+  { // Entry 36
+    0x1.f828c3226b3d77c374e789d7216a85b3p-5,
+    -0x1.825be2461cad4p0
+  },
+  { // Entry 37
+    0x1.f828c3226b3d77c374e789d7216a85b3p-5,
+    0x1.825be2461cad4p0
+  },
+  { // Entry 38
+    0x1.f2990d742e9fa80dd19483a2c0de428bp-5,
+    -0x1.8288755803b08p0
+  },
+  { // Entry 39
+    0x1.f2990d742e9fa80dd19483a2c0de428bp-5,
+    0x1.8288755803b08p0
+  },
+  { // Entry 40
+    -0x1.ff150dda7524ce678ab97ee460e8e961p-1,
+    -0x1.8a75701f4ccd3p1
+  },
+  { // Entry 41
+    -0x1.ff150dda7524ce678ab97ee460e8e961p-1,
+    0x1.8a75701f4ccd3p1
+  },
+  { // Entry 42
+    0x1.015c47c32b574802eb81deb0db46c207p-1,
+    -0x1.b389316f37f37p3
+  },
+  { // Entry 43
+    0x1.015c47c32b574802eb81deb0db46c207p-1,
+    0x1.b389316f37f37p3
+  },
+  { // Entry 44
+    0x1.d681a366a05347fa56b75d845b33c7bbp-1,
+    -0x1.c602c465d7d27p6
+  },
+  { // Entry 45
+    0x1.d681a366a05347fa56b75d845b33c7bbp-1,
+    0x1.c602c465d7d27p6
+  },
+  { // Entry 46
+    -0x1.84e896c7543d54c16d7be346e0f40017p-1,
+    -0x1.cfb81fe69664cp4
+  },
+  { // Entry 47
+    -0x1.84e896c7543d54c16d7be346e0f40017p-1,
+    0x1.cfb81fe69664cp4
+  },
+  { // Entry 48
+    0x1.fc5dcfddd54c07f1574ce114c1e5effep-1,
+    -0x1.d08f2d86b12c6p13
+  },
+  { // Entry 49
+    0x1.fc5dcfddd54c07f1574ce114c1e5effep-1,
+    0x1.d08f2d86b12c6p13
+  },
+  { // Entry 50
+    0x1.fe83235fbe015d6c361556ee5a0e2294p-3,
+    -0x1.de13f0943c494p99
+  },
+  { // Entry 51
+    0x1.fe83235fbe015d6c361556ee5a0e2294p-3,
+    0x1.de13f0943c494p99
+  },
+  { // Entry 52
+    -0x1.720321239ec4f38d55b40d8445099c2ap-1,
+    -0x1.de3c1f1285e8bp3
+  },
+  { // Entry 53
+    -0x1.720321239ec4f38d55b40d8445099c2ap-1,
+    0x1.de3c1f1285e8bp3
+  },
+  { // Entry 54
+    0x1.f7143c8bba406d6f834a3bca5e9c6a58p-4,
+    -0x1.fffffffffff7fp1023
+  },
+  { // Entry 55
+    0x1.f7143c8bba406d6f834a3bca5e9c6a58p-4,
+    0x1.fffffffffff7fp1023
+  },
+  { // Entry 56
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 57
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 58
+    0x1.055e457ac122766a7a343ea4ac739b2ep-5,
+    0x1.0000000000001p51
+  },
+  { // Entry 59
+    0x1.055e457ac122766a7a343ea4ac739b2ep-5,
+    -0x1.0000000000001p51
+  },
+  { // Entry 60
+    0x1.c1528065b7d4e2d84d640301800ddd81p-1,
+    0x1.0000000000003p-1
+  },
+  { // Entry 61
+    0x1.c1528065b7d4e2d84d640301800ddd81p-1,
+    -0x1.0000000000003p-1
+  },
+  { // Entry 62
+    0x1.fffffffffffffffeffffffffffffa0p-1,
+    0x1.0000000000003p-32
+  },
+  { // Entry 63
+    0x1.fffffffffffffffeffffffffffffa0p-1,
+    -0x1.0000000000003p-32
+  },
+  { // Entry 64
+    0x1.fffea444bc05e0b2ec693f7226d056b8p-1,
+    0x1.0000000000020p150
+  },
+  { // Entry 65
+    0x1.fffea444bc05e0b2ec693f7226d056b8p-1,
+    -0x1.0000000000020p150
+  },
+  { // Entry 66
+    -0x1.ebddee876f4338cc885394d1039acfe1p-1,
+    0x1.0000000000038p380
+  },
+  { // Entry 67
+    -0x1.ebddee876f4338cc885394d1039acfe1p-1,
+    -0x1.0000000000038p380
+  },
+  { // Entry 68
+    -0x1.f2ffc51dc69681ded33362645b4e8513p-1,
+    0x1.0000000000118p380
+  },
+  { // Entry 69
+    -0x1.f2ffc51dc69681ded33362645b4e8513p-1,
+    -0x1.0000000000118p380
+  },
+  { // Entry 70
+    -0x1.f8fbb4d358b207f4f81c36cf21c4af97p-1,
+    0x1.00000000003ffp641
+  },
+  { // Entry 71
+    -0x1.f8fbb4d358b207f4f81c36cf21c4af97p-1,
+    -0x1.00000000003ffp641
+  },
+  { // Entry 72
+    -0x1.aa2265753e6687fde76269ee92a784b0p-2,
+    0x1.00000000010p1
+  },
+  { // Entry 73
+    -0x1.aa2265753e6687fde76269ee92a784b0p-2,
+    -0x1.00000000010p1
+  },
+  { // Entry 74
+    0x1.fd1242c25994d0cc5daf405fa510e539p-1,
+    0x1.000000008p452
+  },
+  { // Entry 75
+    0x1.fd1242c25994d0cc5daf405fa510e539p-1,
+    -0x1.000000008p452
+  },
+  { // Entry 76
+    0x1.fffc0001554da8000048828de97acccbp-1,
+    0x1.00000000effafp-7
+  },
+  { // Entry 77
+    0x1.fffc0001554da8000048828de97acccbp-1,
+    -0x1.00000000effafp-7
+  },
+  { // Entry 78
+    0x1.14a27f292552280000dd30fbf6b38481p-1,
+    0x1.00000114fefe2p0
+  },
+  { // Entry 79
+    0x1.14a27f292552280000dd30fbf6b38481p-1,
+    -0x1.00000114fefe2p0
+  },
+  { // Entry 80
+    0x1.bf81e0269c59c7ff753ca32147666c56p-3,
+    0x1.0000070p40
+  },
+  { // Entry 81
+    0x1.bf81e0269c59c7ff753ca32147666c56p-3,
+    -0x1.0000070p40
+  },
+  { // Entry 82
+    0x1.14a26ed1960d67ffffdf8d13b43fa2b4p-1,
+    0x1.00000acadb3d3p0
+  },
+  { // Entry 83
+    0x1.14a26ed1960d67ffffdf8d13b43fa2b4p-1,
+    -0x1.00000acadb3d3p0
+  },
+  { // Entry 84
+    0x1.ffffffffbfffe7ffff155655559a7d2dp-1,
+    0x1.00003p-17
+  },
+  { // Entry 85
+    0x1.ffffffffbfffe7ffff155655559a7d2dp-1,
+    -0x1.00003p-17
+  },
+  { // Entry 86
+    0x1.ffffffffeffff7ffff15f96ad3b29d94p-1,
+    0x1.00003ffffffaep-18
+  },
+  { // Entry 87
+    0x1.ffffffffeffff7ffff15f96ad3b29d94p-1,
+    -0x1.00003ffffffaep-18
+  },
+  { // Entry 88
+    0x1.ffffffffeffff7ffff15576aab329f45p-1,
+    0x1.00003ffffffffp-18
+  },
+  { // Entry 89
+    0x1.ffffffffeffff7ffff15576aab329f45p-1,
+    -0x1.00003ffffffffp-18
+  },
+  { // Entry 90
+    -0x1.dab7efeb35bad7fbdcb0efedb662097cp-2,
+    0x1.00007ffffdea0p41
+  },
+  { // Entry 91
+    -0x1.dab7efeb35bad7fbdcb0efedb662097cp-2,
+    -0x1.00007ffffdea0p41
+  },
+  { // Entry 92
+    0x1.fffffffffbfff8000001595aa9afffcfp-1,
+    0x1.0000ffff8p-19
+  },
+  { // Entry 93
+    0x1.fffffffffbfff8000001595aa9afffcfp-1,
+    -0x1.0000ffff8p-19
+  },
+  { // Entry 94
+    0x1.fffffffffefff80000004b36423050f6p-1,
+    0x1.0003fff800051p-20
+  },
+  { // Entry 95
+    0x1.fffffffffefff80000004b36423050f6p-1,
+    -0x1.0003fff800051p-20
+  },
+  { // Entry 96
+    0x1.fffffffffefff800000042961fb095f7p-1,
+    0x1.0003fff800096p-20
+  },
+  { // Entry 97
+    0x1.fffffffffefff800000042961fb095f7p-1,
+    -0x1.0003fff800096p-20
+  },
+  { // Entry 98
+    -0x1.fbf2b71a23a577fddd081d30bc24917fp-2,
+    0x1.000fd20p334
+  },
+  { // Entry 99
+    -0x1.fbf2b71a23a577fddd081d30bc24917fp-2,
+    -0x1.000fd20p334
+  },
+  { // Entry 100
+    0x1.fccc87eae7736d8d8a4776314f6b0ba7p-5,
+    0x1.003p514
+  },
+  { // Entry 101
+    0x1.fccc87eae7736d8d8a4776314f6b0ba7p-5,
+    -0x1.003p514
+  },
+  { // Entry 102
+    -0x1.a43f40d92b7ed7eef0fe6d1799442cfap-7,
+    0x1.00600000015f4p41
+  },
+  { // Entry 103
+    -0x1.a43f40d92b7ed7eef0fe6d1799442cfap-7,
+    -0x1.00600000015f4p41
+  },
+  { // Entry 104
+    0x1.c11cc38f40ab2827dd0ff8c6f3dd1dafp-1,
+    0x1.007p-1
+  },
+  { // Entry 105
+    0x1.c11cc38f40ab2827dd0ff8c6f3dd1dafp-1,
+    -0x1.007p-1
+  },
+  { // Entry 106
+    0x1.ffffffffffbfc7f3c0000157ac331d0cp-1,
+    0x1.007p-21
+  },
+  { // Entry 107
+    0x1.ffffffffffbfc7f3c0000157ac331d0cp-1,
+    -0x1.007p-21
+  },
+  { // Entry 108
+    0x1.e9ba98231f7346e0566694e1484a5b98p-8,
+    0x1.00cp40
+  },
+  { // Entry 109
+    0x1.e9ba98231f7346e0566694e1484a5b98p-8,
+    -0x1.00cp40
+  },
+  { // Entry 110
+    0x1.fefdf48ed649cd087e3e801219edf804p-1,
+    0x1.011p-4
+  },
+  { // Entry 111
+    0x1.fefdf48ed649cd087e3e801219edf804p-1,
+    -0x1.011p-4
+  },
+  { // Entry 112
+    -0x1.ffc16a0f12ff271ced72fc659ddcd382p-1,
+    0x1.011p996
+  },
+  { // Entry 113
+    -0x1.ffc16a0f12ff271ced72fc659ddcd382p-1,
+    -0x1.011p996
+  },
+  { // Entry 114
+    0x1.efd5b61a30a387fff1400519845fcb1ep-1,
+    0x1.020p-2
+  },
+  { // Entry 115
+    0x1.efd5b61a30a387fff1400519845fcb1ep-1,
+    -0x1.020p-2
+  },
+  { // Entry 116
+    0x1.c97b8161dc50a06cd4801deeb8e0715bp-2,
+    0x1.0204260c18307p59
+  },
+  { // Entry 117
+    0x1.c97b8161dc50a06cd4801deeb8e0715bp-2,
+    -0x1.0204260c18307p59
+  },
+  { // Entry 118
+    -0x1.bf26a3c9b9fbe83488449343f08b08d7p-2,
+    0x1.02e78a321155ep1
+  },
+  { // Entry 119
+    -0x1.bf26a3c9b9fbe83488449343f08b08d7p-2,
+    -0x1.02e78a321155ep1
+  },
+  { // Entry 120
+    0x1.fef806b1f84e4dfd5f71307a3c3eb602p-1,
+    0x1.040p-4
+  },
+  { // Entry 121
+    0x1.fef806b1f84e4dfd5f71307a3c3eb602p-1,
+    -0x1.040p-4
+  },
+  { // Entry 122
+    0x1.fe851fbf87d176fb4c69295c7f928402p-1,
+    0x1.04bde8bb80258p98
+  },
+  { // Entry 123
+    0x1.fe851fbf87d176fb4c69295c7f928402p-1,
+    -0x1.04bde8bb80258p98
+  },
+  { // Entry 124
+    0x1.70f6a51da8efec398e74169e771386eap-1,
+    0x1.077e749e37ceep236
+  },
+  { // Entry 125
+    0x1.70f6a51da8efec398e74169e771386eap-1,
+    -0x1.077e749e37ceep236
+  },
+  { // Entry 126
+    0x1.6b408c856bda57fe5829a58361fea112p-3,
+    0x1.07f80p300
+  },
+  { // Entry 127
+    0x1.6b408c856bda57fe5829a58361fea112p-3,
+    -0x1.07f80p300
+  },
+  { // Entry 128
+    0x1.2b2f965ae40fc7ffffbca0b7eaec5919p-1,
+    0x1.07f9bea1b3546p27
+  },
+  { // Entry 129
+    0x1.2b2f965ae40fc7ffffbca0b7eaec5919p-1,
+    -0x1.07f9bea1b3546p27
+  },
+  { // Entry 130
+    -0x1.4eed2f3fc76a77f803d8911eeddcc5e8p-1,
+    0x1.090d18372f2d5p4
+  },
+  { // Entry 131
+    -0x1.4eed2f3fc76a77f803d8911eeddcc5e8p-1,
+    -0x1.090d18372f2d5p4
+  },
+  { // Entry 132
+    0x1.fba59aecee5000315cee323079ed1427p-1,
+    0x1.0b4p-3
+  },
+  { // Entry 133
+    0x1.fba59aecee5000315cee323079ed1427p-1,
+    -0x1.0b4p-3
+  },
+  { // Entry 134
+    0x1.fffd1bcda7a7d5510aa3d0ed8addc785p-1,
+    0x1.0c0d5c2af3c2ep346
+  },
+  { // Entry 135
+    0x1.fffd1bcda7a7d5510aa3d0ed8addc785p-1,
+    -0x1.0c0d5c2af3c2ep346
+  },
+  { // Entry 136
+    -0x1.e4dfe831292867fdc1333c0a4c3f3f70p-1,
+    0x1.0d30596ee91fdp216
+  },
+  { // Entry 137
+    -0x1.e4dfe831292867fdc1333c0a4c3f3f70p-1,
+    -0x1.0d30596ee91fdp216
+  },
+  { // Entry 138
+    0x1.fb8432886a283b17acaa524e312ab1e3p-2,
+    0x1.0d6p0
+  },
+  { // Entry 139
+    0x1.fb8432886a283b17acaa524e312ab1e3p-2,
+    -0x1.0d6p0
+  },
+  { // Entry 140
+    0x1.ffffee202853ffbbc1684847019727a0p-1,
+    0x1.0e9474c68831cp-10
+  },
+  { // Entry 141
+    0x1.ffffee202853ffbbc1684847019727a0p-1,
+    -0x1.0e9474c68831cp-10
+  },
+  { // Entry 142
+    -0x1.b70d3d5584b1a83c68e254e523d37dfdp-2,
+    0x1.113bae4049849p2
+  },
+  { // Entry 143
+    -0x1.b70d3d5584b1a83c68e254e523d37dfdp-2,
+    -0x1.113bae4049849p2
+  },
+  { // Entry 144
+    0x1.fed8df58f625fdcbb1e40cf83caa2ca2p-1,
+    0x1.12eb870976540p-4
+  },
+  { // Entry 145
+    0x1.fed8df58f625fdcbb1e40cf83caa2ca2p-1,
+    -0x1.12eb870976540p-4
+  },
+  { // Entry 146
+    0x1.e536ae395dfce001457970c8aaac3b1fp-2,
+    0x1.13cp0
+  },
+  { // Entry 147
+    0x1.e536ae395dfce001457970c8aaac3b1fp-2,
+    -0x1.13cp0
+  },
+  { // Entry 148
+    0x1.fed0476fc75c9800000000000020b13ep-1,
+    0x1.16e534ee36580p-4
+  },
+  { // Entry 149
+    0x1.fed0476fc75c9800000000000020b13ep-1,
+    -0x1.16e534ee36580p-4
+  },
+  { // Entry 150
+    0x1.fb38e82e3193a7f19a17d231a2e8194ep-1,
+    0x1.17fffffffea98p-3
+  },
+  { // Entry 151
+    0x1.fb38e82e3193a7f19a17d231a2e8194ep-1,
+    -0x1.17fffffffea98p-3
+  },
+  { // Entry 152
+    0x1.fb38e82e3187fc65747ae443461eb434p-1,
+    0x1.180p-3
+  },
+  { // Entry 153
+    0x1.fb38e82e3187fc65747ae443461eb434p-1,
+    -0x1.180p-3
+  },
+  { // Entry 154
+    -0x1.e59647f1fe9c750059b9eafb88c2aceap-1,
+    0x1.1a191ebbb4d7fp7
+  },
+  { // Entry 155
+    -0x1.e59647f1fe9c750059b9eafb88c2aceap-1,
+    -0x1.1a191ebbb4d7fp7
+  },
+  { // Entry 156
+    -0x1.d0dca1f8715bd7f9ff373c763522db0ep-4,
+    0x1.1da84f2b7b1d8p7
+  },
+  { // Entry 157
+    -0x1.d0dca1f8715bd7f9ff373c763522db0ep-4,
+    -0x1.1da84f2b7b1d8p7
+  },
+  { // Entry 158
+    0x1.b917ebbc30e1d8364bc3c2c10ea13539p-2,
+    0x1.201e973251302p0
+  },
+  { // Entry 159
+    0x1.b917ebbc30e1d8364bc3c2c10ea13539p-2,
+    -0x1.201e973251302p0
+  },
+  { // Entry 160
+    0x1.fffadf12ff4147f6f6f35b44b0f6cb46p-1,
+    0x1.21e02p-7
+  },
+  { // Entry 161
+    0x1.fffadf12ff4147f6f6f35b44b0f6cb46p-1,
+    -0x1.21e02p-7
+  },
+  { // Entry 162
+    -0x1.598a4dab3de597d52faa736762a3f651p-1,
+    0x1.27e29a4b985bfp1
+  },
+  { // Entry 163
+    -0x1.598a4dab3de597d52faa736762a3f651p-1,
+    -0x1.27e29a4b985bfp1
+  },
+  { // Entry 164
+    0x1.fa95c1154abf56c4dbb77bfe5e4e8f42p-1,
+    0x1.2a1f28dbfb6c0p-3
+  },
+  { // Entry 165
+    0x1.fa95c1154abf56c4dbb77bfe5e4e8f42p-1,
+    -0x1.2a1f28dbfb6c0p-3
+  },
+  { // Entry 166
+    -0x1.6412293adb7bca97731e50a86312da2dp-1,
+    0x1.2b8p1
+  },
+  { // Entry 167
+    -0x1.6412293adb7bca97731e50a86312da2dp-1,
+    -0x1.2b8p1
+  },
+  { // Entry 168
+    0x1.fffa518a7d0e77f3b431fcd0ba353095p-1,
+    0x1.31199def72f4dp-7
+  },
+  { // Entry 169
+    0x1.fffa518a7d0e77f3b431fcd0ba353095p-1,
+    -0x1.31199def72f4dp-7
+  },
+  { // Entry 170
+    0x1.f36895fe177f77fe84798264ad4f33b1p-1,
+    0x1.31260e1485014p4
+  },
+  { // Entry 171
+    0x1.f36895fe177f77fe84798264ad4f33b1p-1,
+    -0x1.31260e1485014p4
+  },
+  { // Entry 172
+    0x1.d36207b4fee167f6b3185fdd9294a233p-4,
+    0x1.34e964cd103bdp2
+  },
+  { // Entry 173
+    0x1.d36207b4fee167f6b3185fdd9294a233p-4,
+    -0x1.34e964cd103bdp2
+  },
+  { // Entry 174
+    -0x1.84a37f4fa7616caad66b4d701ab53e94p-1,
+    0x1.37618a0ba7850p1
+  },
+  { // Entry 175
+    -0x1.84a37f4fa7616caad66b4d701ab53e94p-1,
+    -0x1.37618a0ba7850p1
+  },
+  { // Entry 176
+    -0x1.c830bbc99e2290f9d93aa62b2ddfec97p-39,
+    0x1.379704f5f1eb3p24
+  },
+  { // Entry 177
+    -0x1.c830bbc99e2290f9d93aa62b2ddfec97p-39,
+    -0x1.379704f5f1eb3p24
+  },
+  { // Entry 178
+    0x1.b5daaa233bd4f7fcf34b6d5d0280172fp-3,
+    0x1.3b61dd166d470p2
+  },
+  { // Entry 179
+    0x1.b5daaa233bd4f7fcf34b6d5d0280172fp-3,
+    -0x1.3b61dd166d470p2
+  },
+  { // Entry 180
+    -0x1.ffd00dc4db400d962e2d255a661e3ccbp-4,
+    0x1.3c011022acbd0p37
+  },
+  { // Entry 181
+    -0x1.ffd00dc4db400d962e2d255a661e3ccbp-4,
+    -0x1.3c011022acbd0p37
+  },
+  { // Entry 182
+    -0x1.14052b4016ff57fe5750ed3426bfd758p-1,
+    0x1.3e7788e900b70p727
+  },
+  { // Entry 183
+    -0x1.14052b4016ff57fe5750ed3426bfd758p-1,
+    -0x1.3e7788e900b70p727
+  },
+  { // Entry 184
+    0x1.ffffe6a5e4197f5fc50acb189eb85c94p-1,
+    0x1.423eafdcc2779p-10
+  },
+  { // Entry 185
+    0x1.ffffe6a5e4197f5fc50acb189eb85c94p-1,
+    -0x1.423eafdcc2779p-10
+  },
+  { // Entry 186
+    -0x1.fe09fc3d16fedd7508301df68857b756p-6,
+    0x1.4321828c1b538p119
+  },
+  { // Entry 187
+    -0x1.fe09fc3d16fedd7508301df68857b756p-6,
+    -0x1.4321828c1b538p119
+  },
+  { // Entry 188
+    0x1.b685d949a27a0143c4ac9b553541ebecp-14,
+    0x1.43506cb22975dp22
+  },
+  { // Entry 189
+    0x1.b685d949a27a0143c4ac9b553541ebecp-14,
+    -0x1.43506cb22975dp22
+  },
+  { // Entry 190
+    0x1.fe398090e203bc2f6fe6830d380facc4p-1,
+    0x1.439f63495786ap67
+  },
+  { // Entry 191
+    0x1.fe398090e203bc2f6fe6830d380facc4p-1,
+    -0x1.439f63495786ap67
+  },
+  { // Entry 192
+    0x1.fe6274e000973a26c1a0053e3fdeffc7p-1,
+    0x1.457538a6bd073p-4
+  },
+  { // Entry 193
+    0x1.fe6274e000973a26c1a0053e3fdeffc7p-1,
+    -0x1.457538a6bd073p-4
+  },
+  { // Entry 194
+    0x1.09fcb69359c09d5739f1f0255d4fce83p-1,
+    0x1.478fc08p43
+  },
+  { // Entry 195
+    0x1.09fcb69359c09d5739f1f0255d4fce83p-1,
+    -0x1.478fc08p43
+  },
+  { // Entry 196
+    -0x1.20c2158511e7899f1ec379e90c296780p-9,
+    0x1.48a45797cbe63p61
+  },
+  { // Entry 197
+    -0x1.20c2158511e7899f1ec379e90c296780p-9,
+    -0x1.48a45797cbe63p61
+  },
+  { // Entry 198
+    0x1.990d17aae25307fec4ae6d4e98f30093p-1,
+    0x1.4a62e0e12c173p-1
+  },
+  { // Entry 199
+    0x1.990d17aae25307fec4ae6d4e98f30093p-1,
+    -0x1.4a62e0e12c173p-1
+  },
+  { // Entry 200
+    0x1.fdd4f1e00b38700419f96d341905d045p-3,
+    0x1.4c596642a9488p9
+  },
+  { // Entry 201
+    0x1.fdd4f1e00b38700419f96d341905d045p-3,
+    -0x1.4c596642a9488p9
+  },
+  { // Entry 202
+    0x1.fe4f141032f377fe135b13e04436c5ffp-1,
+    0x1.4d0p-4
+  },
+  { // Entry 203
+    0x1.fe4f141032f377fe135b13e04436c5ffp-1,
+    -0x1.4d0p-4
+  },
+  { // Entry 204
+    0x1.94e9f45d43c137a3f345644240a2cef0p-2,
+    0x1.4f0f308p488
+  },
+  { // Entry 205
+    0x1.94e9f45d43c137a3f345644240a2cef0p-2,
+    -0x1.4f0f308p488
+  },
+  { // Entry 206
+    0x1.9355f69ad4326404827cd5ccff8a0c69p-2,
+    0x1.52f00e0p793
+  },
+  { // Entry 207
+    0x1.9355f69ad4326404827cd5ccff8a0c69p-2,
+    -0x1.52f00e0p793
+  },
+  { // Entry 208
+    0x1.1a19be8bea10a801d0b2d09d9509c2c4p-1,
+    0x1.52f06c730ec02p2
+  },
+  { // Entry 209
+    0x1.1a19be8bea10a801d0b2d09d9509c2c4p-1,
+    -0x1.52f06c730ec02p2
+  },
+  { // Entry 210
+    0x1.385d92ec0c7337fea39493f6f2674328p-1,
+    0x1.53e7d5845fe3dp220
+  },
+  { // Entry 211
+    0x1.385d92ec0c7337fea39493f6f2674328p-1,
+    -0x1.53e7d5845fe3dp220
+  },
+  { // Entry 212
+    0x1.fffffffffe2f0f000000465e3592bffbp-1,
+    0x1.590p-20
+  },
+  { // Entry 213
+    0x1.fffffffffe2f0f000000465e3592bffbp-1,
+    -0x1.590p-20
+  },
+  { // Entry 214
+    -0x1.ffd7bc28ded91ffa200d677109251801p-1,
+    0x1.592f1176f0980p86
+  },
+  { // Entry 215
+    -0x1.ffd7bc28ded91ffa200d677109251801p-1,
+    -0x1.592f1176f0980p86
+  },
+  { // Entry 216
+    -0x1.cee28b3d79799000009ea8081244116cp-1,
+    0x1.5999999dc09dcp1
+  },
+  { // Entry 217
+    -0x1.cee28b3d79799000009ea8081244116cp-1,
+    -0x1.5999999dc09dcp1
+  },
+  { // Entry 218
+    0x1.c1f1eb08c26040a32800f087952a383cp-1,
+    0x1.5bea010p468
+  },
+  { // Entry 219
+    0x1.c1f1eb08c26040a32800f087952a383cp-1,
+    -0x1.5bea010p468
+  },
+  { // Entry 220
+    0x1.fffe35ab09a653e266eada6f44055214p-1,
+    0x1.5cb80a6135e5ap1000
+  },
+  { // Entry 221
+    0x1.fffe35ab09a653e266eada6f44055214p-1,
+    -0x1.5cb80a6135e5ap1000
+  },
+  { // Entry 222
+    -0x1.07b85f606e75d765b1aa3bbccba6eaf8p-3,
+    0x1.5d5be48730d2dp13
+  },
+  { // Entry 223
+    -0x1.07b85f606e75d765b1aa3bbccba6eaf8p-3,
+    -0x1.5d5be48730d2dp13
+  },
+  { // Entry 224
+    0x1.ffffffffff86239c000004d581b055ebp-1,
+    0x1.614p-21
+  },
+  { // Entry 225
+    0x1.ffffffffff86239c000004d581b055ebp-1,
+    -0x1.614p-21
+  },
+  { // Entry 226
+    -0x1.dd3a806e89cf17fffff16ecd5397b486p-1,
+    0x1.62adc8a660364p1
+  },
+  { // Entry 227
+    -0x1.dd3a806e89cf17fffff16ecd5397b486p-1,
+    -0x1.62adc8a660364p1
+  },
+  { // Entry 228
+    -0x1.4308b14f4b6edc4c07ee6895f3188af3p-1,
+    0x1.64ef438p142
+  },
+  { // Entry 229
+    -0x1.4308b14f4b6edc4c07ee6895f3188af3p-1,
+    -0x1.64ef438p142
+  },
+  { // Entry 230
+    0x1.6623d2eb6add1ffc398a3c20447f9d06p-3,
+    0x1.652p0
+  },
+  { // Entry 231
+    0x1.6623d2eb6add1ffc398a3c20447f9d06p-3,
+    -0x1.652p0
+  },
+  { // Entry 232
+    0x1.fff832c50f471ff5599c23dc968eb8e4p-1,
+    0x1.65865b2cb08a2p-7
+  },
+  { // Entry 233
+    0x1.fff832c50f471ff5599c23dc968eb8e4p-1,
+    -0x1.65865b2cb08a2p-7
+  },
+  { // Entry 234
+    0x1.acc251be330228021bc31307bc81dc16p-1,
+    0x1.6a937daabc20ep375
+  },
+  { // Entry 235
+    0x1.acc251be330228021bc31307bc81dc16p-1,
+    -0x1.6a937daabc20ep375
+  },
+  { // Entry 236
+    -0x1.14ae72e6ba22ef4608875c41378eb052p-61,
+    0x1.6ac5b262ca1ffp849
+  },
+  { // Entry 237
+    -0x1.14ae72e6ba22ef4608875c41378eb052p-61,
+    -0x1.6ac5b262ca1ffp849
+  },
+  { // Entry 238
+    0x1.e0619960a11c6801e80ab0c9e25f89d0p-2,
+    0x1.6f7bdef7bdef4p3
+  },
+  { // Entry 239
+    0x1.e0619960a11c6801e80ab0c9e25f89d0p-2,
+    -0x1.6f7bdef7bdef4p3
+  },
+  { // Entry 240
+    0x1.8d23f97901a307fffd6c52adf83f0993p-1,
+    0x1.739ce759ce738p200
+  },
+  { // Entry 241
+    0x1.8d23f97901a307fffd6c52adf83f0993p-1,
+    -0x1.739ce759ce738p200
+  },
+  { // Entry 242
+    0x1.fffff78a14ba0f38a84b48dcdb63d44fp-1,
+    0x1.7450c3f49d0b2p-11
+  },
+  { // Entry 243
+    0x1.fffff78a14ba0f38a84b48dcdb63d44fp-1,
+    -0x1.7450c3f49d0b2p-11
+  },
+  { // Entry 244
+    0x1.d6f1c727fb2cb7f7e9cbee2e14246c08p-4,
+    0x1.749fe53f963fdp0
+  },
+  { // Entry 245
+    0x1.d6f1c727fb2cb7f7e9cbee2e14246c08p-4,
+    -0x1.749fe53f963fdp0
+  },
+  { // Entry 246
+    -0x1.f284b5028c1847fffffc9532fe892aadp-1,
+    0x1.74af6725c6206p1
+  },
+  { // Entry 247
+    -0x1.f284b5028c1847fffffc9532fe892aadp-1,
+    -0x1.74af6725c6206p1
+  },
+  { // Entry 248
+    -0x1.f3165a0b306b1ffcf8d11909fffba167p-1,
+    0x1.7550d28ffccc4p1
+  },
+  { // Entry 249
+    -0x1.f3165a0b306b1ffcf8d11909fffba167p-1,
+    -0x1.7550d28ffccc4p1
+  },
+  { // Entry 250
+    0x1.d66d2078ebdeb7ffedf8a48e25084c19p-1,
+    0x1.775e397cd6aa0p6
+  },
+  { // Entry 251
+    0x1.d66d2078ebdeb7ffedf8a48e25084c19p-1,
+    -0x1.775e397cd6aa0p6
+  },
+  { // Entry 252
+    0x1.7af9a13085f5382a87a541ae0b2e5965p-1,
+    0x1.799302bf7f290p-1
+  },
+  { // Entry 253
+    0x1.7af9a13085f5382a87a541ae0b2e5965p-1,
+    -0x1.799302bf7f290p-1
+  },
+  { // Entry 254
+    0x1.ffdd2fdac0c2483e7b116d6d488e7a4bp-1,
+    0x1.799fffffffffdp-6
+  },
+  { // Entry 255
+    0x1.ffdd2fdac0c2483e7b116d6d488e7a4bp-1,
+    -0x1.799fffffffffdp-6
+  },
+  { // Entry 256
+    0x1.fff744f185a737f256732ce87dbaf7a7p-1,
+    0x1.7a3692ca94490p-7
+  },
+  { // Entry 257
+    0x1.fff744f185a737f256732ce87dbaf7a7p-1,
+    -0x1.7a3692ca94490p-7
+  },
+  { // Entry 258
+    0x1.7a6b326b690fa831ee4d0dd72787fbc3p-1,
+    0x1.7a66a638ac5b5p-1
+  },
+  { // Entry 259
+    0x1.7a6b326b690fa831ee4d0dd72787fbc3p-1,
+    -0x1.7a66a638ac5b5p-1
+  },
+  { // Entry 260
+    0x1.671fdb64ffbed7e4952a9d967941e7dap-4,
+    0x1.7ba65462b49a0p0
+  },
+  { // Entry 261
+    0x1.671fdb64ffbed7e4952a9d967941e7dap-4,
+    -0x1.7ba65462b49a0p0
+  },
+  { // Entry 262
+    0x1.ffa55490f206e3b4323a02477b4149e8p-1,
+    0x1.7cdf37cdf37c9p239
+  },
+  { // Entry 263
+    0x1.ffa55490f206e3b4323a02477b4149e8p-1,
+    -0x1.7cdf37cdf37c9p239
+  },
+  { // Entry 264
+    0x1.4c5b5970a3a488233005742af5e6a95ep-4,
+    0x1.7d542565f472ep0
+  },
+  { // Entry 265
+    0x1.4c5b5970a3a488233005742af5e6a95ep-4,
+    -0x1.7d542565f472ep0
+  },
+  { // Entry 266
+    0x1.479a5667c63f57da26adf180a7eb2ffbp-4,
+    0x1.7da0751649058p0
+  },
+  { // Entry 267
+    0x1.479a5667c63f57da26adf180a7eb2ffbp-4,
+    -0x1.7da0751649058p0
+  },
+  { // Entry 268
+    0x1.fff717511dcb57f32d38f29c01379b98p-1,
+    0x1.7e0ddcda6cc0dp-7
+  },
+  { // Entry 269
+    0x1.fff717511dcb57f32d38f29c01379b98p-1,
+    -0x1.7e0ddcda6cc0dp-7
+  },
+  { // Entry 270
+    0x1.ffffffffff7077e7000006b4c7060c33p-1,
+    0x1.7f6p-21
+  },
+  { // Entry 271
+    0x1.ffffffffff7077e7000006b4c7060c33p-1,
+    -0x1.7f6p-21
+  },
+  { // Entry 272
+    -0x1.fff9e1554698017220917c3fb31188ddp-1,
+    0x1.7f90117d44c74p100
+  },
+  { // Entry 273
+    -0x1.fff9e1554698017220917c3fb31188ddp-1,
+    -0x1.7f90117d44c74p100
+  },
+  { // Entry 274
+    0x1.ffdc006bff7e984a8d5031a7152d36e5p-1,
+    0x1.7ffffffffef7ap-6
+  },
+  { // Entry 275
+    0x1.ffdc006bff7e984a8d5031a7152d36e5p-1,
+    -0x1.7ffffffffef7ap-6
+  },
+  { // Entry 276
+    0x1.ffdc006bff7e78474d66d7f25c3ac277p-1,
+    0x1.7fffffffffa26p-6
+  },
+  { // Entry 277
+    0x1.ffdc006bff7e78474d66d7f25c3ac277p-1,
+    -0x1.7fffffffffa26p-6
+  },
+  { // Entry 278
+    0x1.ffdc006bff7e6839adba2a91108d56afp-1,
+    0x1.7ffffffffff80p-6
+  },
+  { // Entry 279
+    0x1.ffdc006bff7e6839adba2a91108d56afp-1,
+    -0x1.7ffffffffff80p-6
+  },
+  { // Entry 280
+    0x1.760718ab443977fdd8f8f2221ca4db3cp-1,
+    0x1.80ep-1
+  },
+  { // Entry 281
+    0x1.760718ab443977fdd8f8f2221ca4db3cp-1,
+    -0x1.80ep-1
+  },
+  { // Entry 282
+    -0x1.fffffffffffffffffffffffffeb29d0bp-1,
+    0x1.81ae0dffa3b33p959
+  },
+  { // Entry 283
+    -0x1.fffffffffffffffffffffffffeb29d0bp-1,
+    -0x1.81ae0dffa3b33p959
+  },
+  { // Entry 284
+    -0x1.fbdc48125b34574cf1f91419e7edb75bp-1,
+    0x1.81d612289c5cfp1
+  },
+  { // Entry 285
+    -0x1.fbdc48125b34574cf1f91419e7edb75bp-1,
+    -0x1.81d612289c5cfp1
+  },
+  { // Entry 286
+    0x1.ff9e396651cc97e935b2e0ee73607d12p-5,
+    0x1.8220192270a0ep0
+  },
+  { // Entry 287
+    0x1.ff9e396651cc97e935b2e0ee73607d12p-5,
+    -0x1.8220192270a0ep0
+  },
+  { // Entry 288
+    0x1.fe2b26dddb5c882f30a885c1b291f945p-5,
+    0x1.822bb780e9104p0
+  },
+  { // Entry 289
+    0x1.fe2b26dddb5c882f30a885c1b291f945p-5,
+    -0x1.822bb780e9104p0
+  },
+  { // Entry 290
+    0x1.eb87cff7c91157a755818c01284b0e51p-5,
+    0x1.82c119c4b8e49p0
+  },
+  { // Entry 291
+    0x1.eb87cff7c91157a755818c01284b0e51p-5,
+    -0x1.82c119c4b8e49p0
+  },
+  { // Entry 292
+    0x1.eb87cff7a62b77b57a66ac275a3104c8p-5,
+    0x1.82c119c4b9fc4p0
+  },
+  { // Entry 293
+    0x1.eb87cff7a62b77b57a66ac275a3104c8p-5,
+    -0x1.82c119c4b9fc4p0
+  },
+  { // Entry 294
+    0x1.eb87cff795ab17a807864d8fb0ca43cap-5,
+    0x1.82c119c4ba808p0
+  },
+  { // Entry 295
+    0x1.eb87cff795ab17a807864d8fb0ca43cap-5,
+    -0x1.82c119c4ba808p0
+  },
+  { // Entry 296
+    0x1.de1d17ab0d6a48367523193d68568c1bp-5,
+    0x1.832c9fc765270p0
+  },
+  { // Entry 297
+    0x1.de1d17ab0d6a48367523193d68568c1bp-5,
+    -0x1.832c9fc765270p0
+  },
+  { // Entry 298
+    0x1.dc86e7bec0c44848cfc39b7f1b8204acp-5,
+    0x1.833956ce7d1f9p0
+  },
+  { // Entry 299
+    0x1.dc86e7bec0c44848cfc39b7f1b8204acp-5,
+    -0x1.833956ce7d1f9p0
+  },
+  { // Entry 300
+    0x1.db03cbb942a7a84974e904ecc896a5eep-5,
+    0x1.834574eb1c099p0
+  },
+  { // Entry 301
+    0x1.db03cbb942a7a84974e904ecc896a5eep-5,
+    -0x1.834574eb1c099p0
+  },
+  { // Entry 302
+    0x1.ce431710d15077b1e8170a532b68abdep-5,
+    0x1.83aba5688e13ep0
+  },
+  { // Entry 303
+    0x1.ce431710d15077b1e8170a532b68abdep-5,
+    -0x1.83aba5688e13ep0
+  },
+  { // Entry 304
+    0x1.cd46b3a77f6dd7ab0d312546aba7c0afp-5,
+    0x1.83b38bbafd75bp0
+  },
+  { // Entry 305
+    0x1.cd46b3a77f6dd7ab0d312546aba7c0afp-5,
+    -0x1.83b38bbafd75bp0
+  },
+  { // Entry 306
+    -0x1.ff29bc666bee6ea44d4db000e5f173bfp-1,
+    0x1.86a017cb1c31cp16
+  },
+  { // Entry 307
+    -0x1.ff29bc666bee6ea44d4db000e5f173bfp-1,
+    -0x1.86a017cb1c31cp16
+  },
+  { // Entry 308
+    -0x1.7968916e4c64630e8e3ae60276ba2d27p-2,
+    0x1.8720588p392
+  },
+  { // Entry 309
+    -0x1.7968916e4c64630e8e3ae60276ba2d27p-2,
+    -0x1.8720588p392
+  },
+  { // Entry 310
+    0x1.fb97c7e452917f59890dfb47e7c9b5e3p-1,
+    0x1.88a2288a22888p9
+  },
+  { // Entry 311
+    0x1.fb97c7e452917f59890dfb47e7c9b5e3p-1,
+    -0x1.88a2288a22888p9
+  },
+  { // Entry 312
+    -0x1.ae44a5f01bf633015e5aacccab4a7f3dp-1,
+    0x1.8cf013991c308p1000
+  },
+  { // Entry 313
+    -0x1.ae44a5f01bf633015e5aacccab4a7f3dp-1,
+    -0x1.8cf013991c308p1000
+  },
+  { // Entry 314
+    0x1.d96e82f71a9dc7fd86f57480e75491e3p-1,
+    0x1.9p-2
+  },
+  { // Entry 315
+    0x1.d96e82f71a9dc7fd86f57480e75491e3p-1,
+    -0x1.9p-2
+  },
+  { // Entry 316
+    0x1.0fd9d5c093df4f57fc49463e2f3f33e6p-7,
+    0x1.9p0
+  },
+  { // Entry 317
+    0x1.0fd9d5c093df4f57fc49463e2f3f33e6p-7,
+    -0x1.9p0
+  },
+  { // Entry 318
+    0x1.0fd9d5c05e5fc801a0f5cbfa33777ae4p-7,
+    0x1.90000000006b0p0
+  },
+  { // Entry 319
+    0x1.0fd9d5c05e5fc801a0f5cbfa33777ae4p-7,
+    -0x1.90000000006b0p0
+  },
+  { // Entry 320
+    0x1.bc8be725417d8800000cada42eeea04ep-1,
+    0x1.900c206d44162p6
+  },
+  { // Entry 321
+    0x1.bc8be725417d8800000cada42eeea04ep-1,
+    -0x1.900c206d44162p6
+  },
+  { // Entry 322
+    0x1.fffffffff63b67e4972d86a2f9d8209bp-1,
+    0x1.900c2af7baef3p-19
+  },
+  { // Entry 323
+    0x1.fffffffff63b67e4972d86a2f9d8209bp-1,
+    -0x1.900c2af7baef3p-19
+  },
+  { // Entry 324
+    0x1.bd464c9352d107ffffff8db9e0da71c0p-1,
+    0x1.900f11bd8955dp6
+  },
+  { // Entry 325
+    0x1.bd464c9352d107ffffff8db9e0da71c0p-1,
+    -0x1.900f11bd8955dp6
+  },
+  { // Entry 326
+    0x1.fffffda85cdd0d431e06f9aa74bc8ce0p-1,
+    0x1.910b35c3253d4p100
+  },
+  { // Entry 327
+    0x1.fffffda85cdd0d431e06f9aa74bc8ce0p-1,
+    -0x1.910b35c3253d4p100
+  },
+  { // Entry 328
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 329
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 330
+    -0x1.2aeef4b9ea1ae4e64c71fccf1fd06f40p-18,
+    0x1.922p0
+  },
+  { // Entry 331
+    -0x1.2aeef4b9ea1ae4e64c71fccf1fd06f40p-18,
+    -0x1.922p0
+  },
+  { // Entry 332
+    -0x1.ffffffffd904847798c7acd46ad183cap-18,
+    0x1.9220354442d18p0
+  },
+  { // Entry 333
+    -0x1.ffffffffd904847798c7acd46ad183cap-18,
+    -0x1.9220354442d18p0
+  },
+  { // Entry 334
+    -0x1.ffffffffffffffffffff2ac8c3da72cbp-1,
+    0x1.9251f93aeb59dp12
+  },
+  { // Entry 335
+    -0x1.ffffffffffffffffffff2ac8c3da72cbp-1,
+    -0x1.9251f93aeb59dp12
+  },
+  { // Entry 336
+    0x1.ffb8c4d1f78a87fffffb23d171bd54d0p-1,
+    0x1.943be221d909ap2
+  },
+  { // Entry 337
+    0x1.ffb8c4d1f78a87fffffb23d171bd54d0p-1,
+    -0x1.943be221d909ap2
+  },
+  { // Entry 338
+    0x1.fff6011fdddab7f25c82e5384d46cc69p-1,
+    0x1.94af699302875p-7
+  },
+  { // Entry 339
+    0x1.fff6011fdddab7f25c82e5384d46cc69p-1,
+    -0x1.94af699302875p-7
+  },
+  { // Entry 340
+    0x1.d7954e7a3ee998000099470604329b68p-1,
+    0x1.999999ab7b0edp-2
+  },
+  { // Entry 341
+    0x1.d7954e7a3ee998000099470604329b68p-1,
+    -0x1.999999ab7b0edp-2
+  },
+  { // Entry 342
+    0x1.d7954e76c8e30fffff5a9bf455a06410p-1,
+    0x1.999999bd4190bp-2
+  },
+  { // Entry 343
+    0x1.d7954e76c8e30fffff5a9bf455a06410p-1,
+    -0x1.999999bd4190bp-2
+  },
+  { // Entry 344
+    0x1.fa23cfb82022440eb972c7e083933d20p-1,
+    0x1.9bd0f19479a24p2
+  },
+  { // Entry 345
+    0x1.fa23cfb82022440eb972c7e083933d20p-1,
+    -0x1.9bd0f19479a24p2
+  },
+  { // Entry 346
+    -0x1.6a09e667f3af07f2f4676b5f6f268c81p-1,
+    0x1.9c55835e7e83ep8
+  },
+  { // Entry 347
+    -0x1.6a09e667f3af07f2f4676b5f6f268c81p-1,
+    -0x1.9c55835e7e83ep8
+  },
+  { // Entry 348
+    0x1.fff59c12558097f2858f4a1326f2ddf4p-1,
+    0x1.9c9942b14448dp-7
+  },
+  { // Entry 349
+    0x1.fff59c12558097f2858f4a1326f2ddf4p-1,
+    -0x1.9c9942b14448dp-7
+  },
+  { // Entry 350
+    0x1.ffece5cab4ca5652ea2fc7ccce883304p-1,
+    0x1.9d3d92485e2b5p523
+  },
+  { // Entry 351
+    0x1.ffece5cab4ca5652ea2fc7ccce883304p-1,
+    -0x1.9d3d92485e2b5p523
+  },
+  { // Entry 352
+    -0x1.ff55301d3a780d19c28c22c82c1f5383p-5,
+    0x1.a0d068341a080p1000
+  },
+  { // Entry 353
+    -0x1.ff55301d3a780d19c28c22c82c1f5383p-5,
+    -0x1.a0d068341a080p1000
+  },
+  { // Entry 354
+    0x1.5a5615acd0dc09bf32e903149634f999p-1,
+    0x1.a7ep-1
+  },
+  { // Entry 355
+    0x1.5a5615acd0dc09bf32e903149634f999p-1,
+    -0x1.a7ep-1
+  },
+  { // Entry 356
+    0x1.766ad27a1de4fb1a5b667216bbe6bf68p-14,
+    0x1.a858343863965p119
+  },
+  { // Entry 357
+    0x1.766ad27a1de4fb1a5b667216bbe6bf68p-14,
+    -0x1.a858343863965p119
+  },
+  { // Entry 358
+    0x1.6bd4d5be7249325d8680606e6b9ea625p-1,
+    0x1.ab190633d88eap3
+  },
+  { // Entry 359
+    0x1.6bd4d5be7249325d8680606e6b9ea625p-1,
+    -0x1.ab190633d88eap3
+  },
+  { // Entry 360
+    0x1.ffffffffff4a57e64da87a5af47cfa18p-1,
+    0x1.af4bd2f4bd2f0p-21
+  },
+  { // Entry 361
+    0x1.ffffffffff4a57e64da87a5af47cfa18p-1,
+    -0x1.af4bd2f4bd2f0p-21
+  },
+  { // Entry 362
+    0x1.7ff2934ad29a74288b886124fead5842p-1,
+    0x1.afa70300aee60p72
+  },
+  { // Entry 363
+    0x1.7ff2934ad29a74288b886124fead5842p-1,
+    -0x1.afa70300aee60p72
+  },
+  { // Entry 364
+    0x1.ff866aebdce0a7fffffb6074d5199896p-1,
+    0x1.b5ab427cffb4cp94
+  },
+  { // Entry 365
+    0x1.ff866aebdce0a7fffffb6074d5199896p-1,
+    -0x1.b5ab427cffb4cp94
+  },
+  { // Entry 366
+    -0x1.f54f5227a4e83fbf939b2e96178f121dp-60,
+    0x1.b951f1572eba5p23
+  },
+  { // Entry 367
+    -0x1.f54f5227a4e83fbf939b2e96178f121dp-60,
+    -0x1.b951f1572eba5p23
+  },
+  { // Entry 368
+    0x1.fffd06d35579c7fe295dad17efbbbe97p-1,
+    0x1.b96e5b96e5b91p-8
+  },
+  { // Entry 369
+    0x1.fffd06d35579c7fe295dad17efbbbe97p-1,
+    -0x1.b96e5b96e5b91p-8
+  },
+  { // Entry 370
+    -0x1.7c4128e2aff4b2b78e147601fa658af5p-1,
+    0x1.ba3b18395d17bp8
+  },
+  { // Entry 371
+    -0x1.7c4128e2aff4b2b78e147601fa658af5p-1,
+    -0x1.ba3b18395d17bp8
+  },
+  { // Entry 372
+    -0x1.fffffffffffffffffffffffffefaff9dp-1,
+    0x1.bab62ed655019p970
+  },
+  { // Entry 373
+    -0x1.fffffffffffffffffffffffffefaff9dp-1,
+    -0x1.bab62ed655019p970
+  },
+  { // Entry 374
+    0x1.ffffff3e534467fffff37e509b7b792ep-1,
+    0x1.bd55aa411ab46p-13
+  },
+  { // Entry 375
+    0x1.ffffff3e534467fffff37e509b7b792ep-1,
+    -0x1.bd55aa411ab46p-13
+  },
+  { // Entry 376
+    -0x1.7fdb07b9f77e07ffff7207c4628d3f68p-1,
+    0x1.bd616d4fe95cdp36
+  },
+  { // Entry 377
+    -0x1.7fdb07b9f77e07ffff7207c4628d3f68p-1,
+    -0x1.bd616d4fe95cdp36
+  },
+  { // Entry 378
+    0x1.ffcf4da76222c889718239523341f4b5p-1,
+    0x1.beap-6
+  },
+  { // Entry 379
+    0x1.ffcf4da76222c889718239523341f4b5p-1,
+    -0x1.beap-6
+  },
+  { // Entry 380
+    -0x1.ddee13357ec6f7fcc9502399fccdc2f0p-1,
+    0x1.c11516af585a4p1
+  },
+  { // Entry 381
+    -0x1.ddee13357ec6f7fcc9502399fccdc2f0p-1,
+    -0x1.c11516af585a4p1
+  },
+  { // Entry 382
+    0x1.58cccec059da17d3f448a8b2b6e7c0e8p-1,
+    0x1.c75e54de4c06ep2
+  },
+  { // Entry 383
+    0x1.58cccec059da17d3f448a8b2b6e7c0e8p-1,
+    -0x1.c75e54de4c06ep2
+  },
+  { // Entry 384
+    -0x1.ffffffffffffffffffffffffffc8663ep-1,
+    0x1.cb44e86bc192bp648
+  },
+  { // Entry 385
+    -0x1.ffffffffffffffffffffffffffc8663ep-1,
+    -0x1.cb44e86bc192bp648
+  },
+  { // Entry 386
+    0x1.ffffffffffffffffffffffffff2198f9p-1,
+    0x1.cb44e86bc192bp649
+  },
+  { // Entry 387
+    0x1.ffffffffffffffffffffffffff2198f9p-1,
+    -0x1.cb44e86bc192bp649
+  },
+  { // Entry 388
+    -0x1.ca281d7fe44b07ffffd2b7d46ab5d361p-1,
+    0x1.cd5a6f8762affp1
+  },
+  { // Entry 389
+    -0x1.ca281d7fe44b07ffffd2b7d46ab5d361p-1,
+    -0x1.cd5a6f8762affp1
+  },
+  { // Entry 390
+    0x1.e80ad4fe54c71d4e604ede474cca0b19p-5,
+    0x1.d0cb95f02ad77p464
+  },
+  { // Entry 391
+    0x1.e80ad4fe54c71d4e604ede474cca0b19p-5,
+    -0x1.d0cb95f02ad77p464
+  },
+  { // Entry 392
+    0x1.0df8eb409efe37fffff925b5de2c80b6p-1,
+    0x1.d31bd604903a0p2
+  },
+  { // Entry 393
+    0x1.0df8eb409efe37fffff925b5de2c80b6p-1,
+    -0x1.d31bd604903a0p2
+  },
+  { // Entry 394
+    0x1.ff2ae968efe70ea4126849c3832c9cbdp-1,
+    0x1.d32f4610180f6p-5
+  },
+  { // Entry 395
+    0x1.ff2ae968efe70ea4126849c3832c9cbdp-1,
+    -0x1.d32f4610180f6p-5
+  },
+  { // Entry 396
+    -0x1.cec307a674d3ed2f8df47cf394aa88eap-3,
+    0x1.d96e058p488
+  },
+  { // Entry 397
+    -0x1.cec307a674d3ed2f8df47cf394aa88eap-3,
+    -0x1.d96e058p488
+  },
+  { // Entry 398
+    -0x1.ac8dbf9cdc95483577560b1814ea8895p-5,
+    0x1.db0803c392b4cp15
+  },
+  { // Entry 399
+    -0x1.ac8dbf9cdc95483577560b1814ea8895p-5,
+    -0x1.db0803c392b4cp15
+  },
+  { // Entry 400
+    -0x1.ac94870ca631684bd10b658b80cfcd42p-5,
+    0x1.db0803c3ff51dp15
+  },
+  { // Entry 401
+    -0x1.ac94870ca631684bd10b658b80cfcd42p-5,
+    -0x1.db0803c3ff51dp15
+  },
+  { // Entry 402
+    0x1.ff229073fd8b5e91d60dd095cfde5967p-1,
+    0x1.dc4p-5
+  },
+  { // Entry 403
+    0x1.ff229073fd8b5e91d60dd095cfde5967p-1,
+    -0x1.dc4p-5
+  },
+  { // Entry 404
+    0x1.ff21e5f975fffe83c2ae1c55a885f12fp-1,
+    0x1.dcf73dcf73dccp-5
+  },
+  { // Entry 405
+    0x1.ff21e5f975fffe83c2ae1c55a885f12fp-1,
+    -0x1.dcf73dcf73dccp-5
+  },
+  { // Entry 406
+    0x1.2f011326420e5002172db245fd9063e2p-1,
+    0x1.dffffffffffffp-1
+  },
+  { // Entry 407
+    0x1.2f011326420e5002172db245fd9063e2p-1,
+    -0x1.dffffffffffffp-1
+  },
+  { // Entry 408
+    0x1.f72c8e16dbc78b26afbf346185dccb48p-1,
+    0x1.e123691a7c4bep26
+  },
+  { // Entry 409
+    0x1.f72c8e16dbc78b26afbf346185dccb48p-1,
+    -0x1.e123691a7c4bep26
+  },
+  { // Entry 410
+    -0x1.4b0c6bb623f57fffff5e458203deef33p-2,
+    0x1.e666666f9cf49p0
+  },
+  { // Entry 411
+    -0x1.4b0c6bb623f57fffff5e458203deef33p-2,
+    -0x1.e666666f9cf49p0
+  },
+  { // Entry 412
+    0x1.fd74b5587588481884a92e83747f5c4ep-1,
+    0x1.e83accfc50b70p995
+  },
+  { // Entry 413
+    0x1.fd74b5587588481884a92e83747f5c4ep-1,
+    -0x1.e83accfc50b70p995
+  },
+  { // Entry 414
+    0x1.fff169b6ab7d17f43d59f6cf085accb0p-1,
+    0x1.e8ep-7
+  },
+  { // Entry 415
+    0x1.fff169b6ab7d17f43d59f6cf085accb0p-1,
+    -0x1.e8ep-7
+  },
+  { // Entry 416
+    0x1.7d39c9f1b0b3c0027a5fc9a76faee83dp-1,
+    0x1.eaf5ea5317442p4
+  },
+  { // Entry 417
+    0x1.7d39c9f1b0b3c0027a5fc9a76faee83dp-1,
+    -0x1.eaf5ea5317442p4
+  },
+  { // Entry 418
+    0x1.7f13af7081a6741660469fd60255fe49p-1,
+    0x1.eb0c2b00b1b83p4
+  },
+  { // Entry 419
+    0x1.7f13af7081a6741660469fd60255fe49p-1,
+    -0x1.eb0c2b00b1b83p4
+  },
+  { // Entry 420
+    -0x1.7ad7b88a1fe0f82b6f249c7c56dd8b5ap-1,
+    0x1.ebc6b555311c4p15
+  },
+  { // Entry 421
+    -0x1.7ad7b88a1fe0f82b6f249c7c56dd8b5ap-1,
+    -0x1.ebc6b555311c4p15
+  },
+  { // Entry 422
+    0x1.b06b2b58a2a23c98b12853415b5c83a1p-5,
+    0x1.ef7bdef7bdef2p239
+  },
+  { // Entry 423
+    0x1.b06b2b58a2a23c98b12853415b5c83a1p-5,
+    -0x1.ef7bdef7bdef2p239
+  },
+  { // Entry 424
+    0x1.fe6ded53172a6876790d3aab83a656f4p-1,
+    0x1.efbbeefbbeef8p15
+  },
+  { // Entry 425
+    0x1.fe6ded53172a6876790d3aab83a656f4p-1,
+    -0x1.efbbeefbbeef8p15
+  },
+  { // Entry 426
+    -0x1.fe2bcb87a7e158cffa2fe8d306cc7555p-1,
+    0x1.f07c1f07c1ef7p239
+  },
+  { // Entry 427
+    -0x1.fe2bcb87a7e158cffa2fe8d306cc7555p-1,
+    -0x1.f07c1f07c1ef7p239
+  },
+  { // Entry 428
+    -0x1.79d08d6b3a88282e0a0da2350464d0abp-1,
+    0x1.f0f2b5e060b29p1
+  },
+  { // Entry 429
+    -0x1.79d08d6b3a88282e0a0da2350464d0abp-1,
+    -0x1.f0f2b5e060b29p1
+  },
+  { // Entry 430
+    0x1.f0d11d321178d7ff15da48990d5983c2p-1,
+    0x1.f40p-3
+  },
+  { // Entry 431
+    0x1.f0d11d321178d7ff15da48990d5983c2p-1,
+    -0x1.f40p-3
+  },
+  { // Entry 432
+    0x1.e3ff5b15f723d7f7f7f5bb0dbce54d01p-4,
+    0x1.f43d49f947e87p9
+  },
+  { // Entry 433
+    0x1.e3ff5b15f723d7f7f7f5bb0dbce54d01p-4,
+    -0x1.f43d49f947e87p9
+  },
+  { // Entry 434
+    -0x1.6636c9f6a87a97f1cbdf708a2f1ad9bap-1,
+    0x1.f7fffffffffffp1
+  },
+  { // Entry 435
+    -0x1.6636c9f6a87a97f1cbdf708a2f1ad9bap-1,
+    -0x1.f7fffffffffffp1
+  },
+  { // Entry 436
+    0x1.ffc1be33092857ff26220f9981635bc7p-1,
+    0x1.f8fffffffffffp-6
+  },
+  { // Entry 437
+    0x1.ffc1be33092857ff26220f9981635bc7p-1,
+    -0x1.f8fffffffffffp-6
+  },
+  { // Entry 438
+    0x1.ffc1be33092857fb344affdd93d043a7p-1,
+    0x1.f90p-6
+  },
+  { // Entry 439
+    0x1.ffc1be33092857fb344affdd93d043a7p-1,
+    -0x1.f90p-6
+  },
+  { // Entry 440
+    -0x1.fffffffcab0d58220669dcfa421ccfa6p-1,
+    0x1.fa0236523ce54p344
+  },
+  { // Entry 441
+    -0x1.fffffffcab0d58220669dcfa421ccfa6p-1,
+    -0x1.fa0236523ce54p344
+  },
+  { // Entry 442
+    0x1.fc0d98ace2308800000212788a794eacp-1,
+    0x1.fceab54d37da0p-4
+  },
+  { // Entry 443
+    0x1.fc0d98ace2308800000212788a794eacp-1,
+    -0x1.fceab54d37da0p-4
+  },
+  { // Entry 444
+    -0x1.9589bca128b917fe59692a738c3791c9p-4,
+    0x1.fd0072fffffffp2
+  },
+  { // Entry 445
+    -0x1.9589bca128b917fe59692a738c3791c9p-4,
+    -0x1.fd0072fffffffp2
+  },
+  { // Entry 446
+    -0x1.4d304b07fc897cf1ade54fe97db7c8bdp-2,
+    0x1.fe0f827673422p62
+  },
+  { // Entry 447
+    -0x1.4d304b07fc897cf1ade54fe97db7c8bdp-2,
+    -0x1.fe0f827673422p62
+  },
+  { // Entry 448
+    0x1.c1a27ae836f128000000000000504e9bp-1,
+    0x1.feb1f7920e248p-2
+  },
+  { // Entry 449
+    0x1.c1a27ae836f128000000000000504e9bp-1,
+    -0x1.feb1f7920e248p-2
+  },
+  { // Entry 450
+    -0x1.936b64e955978d15aacfddf5821c6281p-1,
+    0x1.feeffffffffc6p995
+  },
+  { // Entry 451
+    -0x1.936b64e955978d15aacfddf5821c6281p-1,
+    -0x1.feeffffffffc6p995
+  },
+  { // Entry 452
+    0x1.fff007147ea577fb02130c68b335ef45p-1,
+    0x1.ff8ffffffffffp-7
+  },
+  { // Entry 453
+    0x1.fff007147ea577fb02130c68b335ef45p-1,
+    -0x1.ff8ffffffffffp-7
+  },
+  { // Entry 454
+    0x1.ffffc01bfe442b09cbec19f68af8fbf8p-1,
+    0x1.ff8ffffffffffp-10
+  },
+  { // Entry 455
+    0x1.ffffc01bfe442b09cbec19f68af8fbf8p-1,
+    -0x1.ff8ffffffffffp-10
+  },
+  { // Entry 456
+    0x1.7cc9fb75317ae93bf5ddee0e8b9c83cep-1,
+    0x1.ff8ffffffffffp870
+  },
+  { // Entry 457
+    0x1.7cc9fb75317ae93bf5ddee0e8b9c83cep-1,
+    -0x1.ff8ffffffffffp870
+  },
+  { // Entry 458
+    0x1.d6aea48015588e71983142804227fd84p-1,
+    0x1.ffcfff8p19
+  },
+  { // Entry 459
+    0x1.d6aea48015588e71983142804227fd84p-1,
+    -0x1.ffcfff8p19
+  },
+  { // Entry 460
+    -0x1.6a9972eee19badf9e34d36b0d1202091p-2,
+    0x1.ffcfff8p365
+  },
+  { // Entry 461
+    -0x1.6a9972eee19badf9e34d36b0d1202091p-2,
+    -0x1.ffcfff8p365
+  },
+  { // Entry 462
+    -0x1.3aaa15f7544b691a43e1fa1a639bdfc2p-1,
+    0x1.ffcffffffff6cp720
+  },
+  { // Entry 463
+    -0x1.3aaa15f7544b691a43e1fa1a639bdfc2p-1,
+    -0x1.ffcffffffff6cp720
+  },
+  { // Entry 464
+    0x1.3f164bce055c4c61b74a61f73ca73d3fp-1,
+    0x1.ffcfffffffff9p320
+  },
+  { // Entry 465
+    0x1.3f164bce055c4c61b74a61f73ca73d3fp-1,
+    -0x1.ffcfffffffff9p320
+  },
+  { // Entry 466
+    0x1.fffff002fff14d566ae8ec9d1edc3e3fp-1,
+    0x1.ffcffffffffffp-11
+  },
+  { // Entry 467
+    0x1.fffff002fff14d566ae8ec9d1edc3e3fp-1,
+    -0x1.ffcffffffffffp-11
+  },
+  { // Entry 468
+    -0x1.ffffff987f985d67944b867bff4ab857p-1,
+    0x1.ffcffffffffffp405
+  },
+  { // Entry 469
+    -0x1.ffffff987f985d67944b867bff4ab857p-1,
+    -0x1.ffcffffffffffp405
+  },
+  { // Entry 470
+    -0x1.ffff6235a25edb8c975b485c5c6f41f7p-1,
+    0x1.ffcffffffffffp567
+  },
+  { // Entry 471
+    -0x1.ffff6235a25edb8c975b485c5c6f41f7p-1,
+    -0x1.ffcffffffffffp567
+  },
+  { // Entry 472
+    0x1.fdf11ae4608b0894bab8786949aa6333p-3,
+    0x1.ffefff8ffffffp16
+  },
+  { // Entry 473
+    0x1.fdf11ae4608b0894bab8786949aa6333p-3,
+    -0x1.ffefff8ffffffp16
+  },
+  { // Entry 474
+    0x1.8f5525ab4583c064353aaad12c6cce6cp-1,
+    0x1.ffeffffffffccp995
+  },
+  { // Entry 475
+    0x1.8f5525ab4583c064353aaad12c6cce6cp-1,
+    -0x1.ffeffffffffccp995
+  },
+  { // Entry 476
+    0x1.a0af44a45c0569b72058cc34efd0e32ep-8,
+    0x1.ffeffffffffffp77
+  },
+  { // Entry 477
+    0x1.a0af44a45c0569b72058cc34efd0e32ep-8,
+    -0x1.ffeffffffffffp77
+  },
+  { // Entry 478
+    -0x1.df7546c31bf8cffef69c4859da055f33p-1,
+    0x1.ffeffffffffffp122
+  },
+  { // Entry 479
+    -0x1.df7546c31bf8cffef69c4859da055f33p-1,
+    -0x1.ffeffffffffffp122
+  },
+  { // Entry 480
+    -0x1.825a7bea27d5b1a598af6b684eb18478p-1,
+    0x1.ffeffffffffffp179
+  },
+  { // Entry 481
+    -0x1.825a7bea27d5b1a598af6b684eb18478p-1,
+    -0x1.ffeffffffffffp179
+  },
+  { // Entry 482
+    -0x1.1be2ab2078d547fff09932011fe16456p-1,
+    0x1.ffeffffffffffp238
+  },
+  { // Entry 483
+    -0x1.1be2ab2078d547fff09932011fe16456p-1,
+    -0x1.ffeffffffffffp238
+  },
+  { // Entry 484
+    -0x1.a4cc5f838f5297e0a7e749cb087c2f14p-7,
+    0x1.fff0000002511p492
+  },
+  { // Entry 485
+    -0x1.a4cc5f838f5297e0a7e749cb087c2f14p-7,
+    -0x1.fff0000002511p492
+  },
+  { // Entry 486
+    0x1.f16437d6119f89bfa73a2f14f377fd3ep-10,
+    0x1.fff1fffffffffp41
+  },
+  { // Entry 487
+    0x1.f16437d6119f89bfa73a2f14f377fd3ep-10,
+    -0x1.fff1fffffffffp41
+  },
+  { // Entry 488
+    0x1.898324c2f1cfc596e590b4a80d2508fbp-11,
+    0x1.ffffc7fffffffp45
+  },
+  { // Entry 489
+    0x1.898324c2f1cfc596e590b4a80d2508fbp-11,
+    -0x1.ffffc7fffffffp45
+  },
+  { // Entry 490
+    0x1.f0154c00688f87fcc96f14c8efb5914fp-1,
+    0x1.ffffdf1ffffffp-3
+  },
+  { // Entry 491
+    0x1.f0154c00688f87fcc96f14c8efb5914fp-1,
+    -0x1.ffffdf1ffffffp-3
+  },
+  { // Entry 492
+    0x1.ffc00157126a7d98216491df73d97cd3p-1,
+    0x1.fffff8fffffffp-6
+  },
+  { // Entry 493
+    0x1.ffc00157126a7d98216491df73d97cd3p-1,
+    -0x1.fffff8fffffffp-6
+  },
+  { // Entry 494
+    -0x1.e0d9f0f38c73f0069739e9de65191416p-2,
+    0x1.fffffbfffffffp968
+  },
+  { // Entry 495
+    -0x1.e0d9f0f38c73f0069739e9de65191416p-2,
+    -0x1.fffffbfffffffp968
+  },
+  { // Entry 496
+    0x1.fff4699dd560b5dbb88a029337b9ab86p-1,
+    0x1.fffffcfffffffp40
+  },
+  { // Entry 497
+    0x1.fff4699dd560b5dbb88a029337b9ab86p-1,
+    -0x1.fffffcfffffffp40
+  },
+  { // Entry 498
+    0x1.ff0015559f228802433732ae11942945p-1,
+    0x1.ffffff0000040p-5
+  },
+  { // Entry 499
+    0x1.ff0015559f228802433732ae11942945p-1,
+    -0x1.ffffff0000040p-5
+  },
+  { // Entry 500
+    -0x1.9c6951cccd39bf60d47db80be6fce34fp-2,
+    0x1.ffffff8p119
+  },
+  { // Entry 501
+    -0x1.9c6951cccd39bf60d47db80be6fce34fp-2,
+    -0x1.ffffff8p119
+  },
+  { // Entry 502
+    -0x1.f2c2263590034ec62522d45d2eeca285p-1,
+    0x1.ffffff8p192
+  },
+  { // Entry 503
+    -0x1.f2c2263590034ec62522d45d2eeca285p-1,
+    -0x1.ffffff8p192
+  },
+  { // Entry 504
+    0x1.c7884d6cfb5511a6b5111077fd0b1b72p-1,
+    0x1.ffffff8p543
+  },
+  { // Entry 505
+    0x1.c7884d6cfb5511a6b5111077fd0b1b72p-1,
+    -0x1.ffffff8p543
+  },
+  { // Entry 506
+    0x1.e66c79e776a1eff6b68f2d01289e08e8p-2,
+    0x1.ffffffc3fffffp500
+  },
+  { // Entry 507
+    0x1.e66c79e776a1eff6b68f2d01289e08e8p-2,
+    -0x1.ffffffc3fffffp500
+  },
+  { // Entry 508
+    0x1.c7c9a9c57c0b2009f18a6c2c07b52ea2p-3,
+    0x1.ffffffe1fffffp700
+  },
+  { // Entry 509
+    0x1.c7c9a9c57c0b2009f18a6c2c07b52ea2p-3,
+    -0x1.ffffffe1fffffp700
+  },
+  { // Entry 510
+    0x1.7bb28daf5f9ad3608dda8a16ea235cb4p-1,
+    0x1.ffffffff0f0ffp400
+  },
+  { // Entry 511
+    0x1.7bb28daf5f9ad3608dda8a16ea235cb4p-1,
+    -0x1.ffffffff0f0ffp400
+  },
+  { // Entry 512
+    0x1.fc015527d8bb37806e4976dcf7a7c98cp-1,
+    0x1.ffffffff3ffffp-4
+  },
+  { // Entry 513
+    0x1.fc015527d8bb37806e4976dcf7a7c98cp-1,
+    -0x1.ffffffff3ffffp-4
+  },
+  { // Entry 514
+    -0x1.ea5257eb66e3bffee900cd4447404c16p-1,
+    0x1.ffffffff8ffffp3
+  },
+  { // Entry 515
+    -0x1.ea5257eb66e3bffee900cd4447404c16p-1,
+    -0x1.ffffffff8ffffp3
+  },
+  { // Entry 516
+    -0x1.4eaa606dbef968000267b0375ded6872p-1,
+    0x1.fffffffffbcffp1
+  },
+  { // Entry 517
+    -0x1.4eaa606dbef968000267b0375ded6872p-1,
+    -0x1.fffffffffbcffp1
+  },
+  { // Entry 518
+    -0x1.fc9cd6b5f009482b0d5582e1c6cdf738p-1,
+    0x1.fffffffffe0b5p720
+  },
+  { // Entry 519
+    -0x1.fc9cd6b5f009482b0d5582e1c6cdf738p-1,
+    -0x1.fffffffffe0b5p720
+  },
+  { // Entry 520
+    0x1.e96ac045dd138d25741cb879b92afa48p-3,
+    0x1.fffffffffe7ffp41
+  },
+  { // Entry 521
+    0x1.e96ac045dd138d25741cb879b92afa48p-3,
+    -0x1.fffffffffe7ffp41
+  },
+  { // Entry 522
+    -0x1.fcaf39cfb94d48195d2b26060b30f822p-1,
+    0x1.fffffffffee09p720
+  },
+  { // Entry 523
+    -0x1.fcaf39cfb94d48195d2b26060b30f822p-1,
+    -0x1.fffffffffee09p720
+  },
+  { // Entry 524
+    0x1.8432232a6d1daa6ac8a94c0021e60d50p-1,
+    0x1.ffffffffffdffp40
+  },
+  { // Entry 525
+    0x1.8432232a6d1daa6ac8a94c0021e60d50p-1,
+    -0x1.ffffffffffdffp40
+  },
+  { // Entry 526
+    0x1.9e375143139d9a37b354ea33dd625cd6p-6,
+    0x1.ffffffffffeffp41
+  },
+  { // Entry 527
+    0x1.9e375143139d9a37b354ea33dd625cd6p-6,
+    -0x1.ffffffffffeffp41
+  },
+  { // Entry 528
+    0x1.fffc0001555528000049b10c26a1f539p-1,
+    0x1.fffffffffff4ap-8
+  },
+  { // Entry 529
+    0x1.fffc0001555528000049b10c26a1f539p-1,
+    -0x1.fffffffffff4ap-8
+  },
+  { // Entry 530
+    0x1.463a895c4ea5ce4e56e8f578388eed3ap-1,
+    0x1.fffffffffff78p920
+  },
+  { // Entry 531
+    0x1.463a895c4ea5ce4e56e8f578388eed3ap-1,
+    -0x1.fffffffffff78p920
+  },
+  { // Entry 532
+    0x1.3c1a48635cf380c8158d934c4d0dd87cp-1,
+    0x1.fffffffffffd5p995
+  },
+  { // Entry 533
+    0x1.3c1a48635cf380c8158d934c4d0dd87cp-1,
+    -0x1.fffffffffffd5p995
+  },
+  { // Entry 534
+    0x1.91c4e0708bd486217f5fc230f0416220p-1,
+    0x1.fffffffffffe8p720
+  },
+  { // Entry 535
+    0x1.91c4e0708bd486217f5fc230f0416220p-1,
+    -0x1.fffffffffffe8p720
+  },
+  { // Entry 536
+    -0x1.3e15cb849b5ea87bcc583f6344cbcc40p-1,
+    0x1.fffffffffffebp920
+  },
+  { // Entry 537
+    -0x1.3e15cb849b5ea87bcc583f6344cbcc40p-1,
+    -0x1.fffffffffffebp920
+  },
+  { // Entry 538
+    -0x1.816808349b80dd3c22cbe80b4c171d1fp-1,
+    0x1.ffffffffffff1p245
+  },
+  { // Entry 539
+    -0x1.816808349b80dd3c22cbe80b4c171d1fp-1,
+    -0x1.ffffffffffff1p245
+  },
+  { // Entry 540
+    0x1.4699c814c5f075bb0ed9472dfecc50a9p-1,
+    0x1.ffffffffffff4p845
+  },
+  { // Entry 541
+    0x1.4699c814c5f075bb0ed9472dfecc50a9p-1,
+    -0x1.ffffffffffff4p845
+  },
+  { // Entry 542
+    -0x1.815e92b7a2a019e74650a859968e0f29p-1,
+    0x1.ffffffffffff4p1020
+  },
+  { // Entry 543
+    -0x1.815e92b7a2a019e74650a859968e0f29p-1,
+    -0x1.ffffffffffff4p1020
+  },
+  { // Entry 544
+    -0x1.3e8d028153201ed272fc9549725fcb3fp-10,
+    0x1.ffffffffffffcp45
+  },
+  { // Entry 545
+    -0x1.3e8d028153201ed272fc9549725fcb3fp-10,
+    -0x1.ffffffffffffcp45
+  },
+  { // Entry 546
+    0x1.7d6765714c78532d3eb0f2a73c5d6126p-1,
+    0x1.ffffffffffffep105
+  },
+  { // Entry 547
+    0x1.7d6765714c78532d3eb0f2a73c5d6126p-1,
+    -0x1.ffffffffffffep105
+  },
+  { // Entry 548
+    -0x1.f869fb14d2568d67c37c90b0a038b240p-3,
+    0x1.ffffffffffffep480
+  },
+  { // Entry 549
+    -0x1.f869fb14d2568d67c37c90b0a038b240p-3,
+    -0x1.ffffffffffffep480
+  },
+  { // Entry 550
+    -0x1.80a75b369d3c3fd15b6060c6fb98f2d6p-1,
+    0x1.ffffffffffffep970
+  },
+  { // Entry 551
+    -0x1.80a75b369d3c3fd15b6060c6fb98f2d6p-1,
+    -0x1.ffffffffffffep970
+  },
+  { // Entry 552
+    -0x1.9dba69e853bd77fd883be3bb1171df55p-4,
+    0x1.0000000000001p42
+  },
+  { // Entry 553
+    -0x1.9dba69e853bd77fd883be3bb1171df55p-4,
+    -0x1.0000000000001p42
+  },
+  { // Entry 554
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074
+  },
+  { // Entry 555
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074
+  },
+  { // Entry 556
+    0x1.p0,
+    -0.0
+  },
+  { // Entry 557
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074
+  },
+  { // Entry 558
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074
+  },
+  { // Entry 559
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 560
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 561
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1022
+  },
+  { // Entry 562
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1022
+  },
+  { // Entry 563
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 564
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 565
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 566
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 567
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1022
+  },
+  { // Entry 568
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1022
+  },
+  { // Entry 569
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 570
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 571
+    0x1.ffffff5c28f5cb4c5272061281211120p-1,
+    0x1.999999999999ap-13
+  },
+  { // Entry 572
+    0x1.ffffff5c28f5cb4c5272061281211120p-1,
+    -0x1.999999999999ap-13
+  },
+  { // Entry 573
+    0x1.fffffd70a3d7960cd5695a06fdb80e74p-1,
+    0x1.999999999999ap-12
+  },
+  { // Entry 574
+    0x1.fffffd70a3d7960cd5695a06fdb80e74p-1,
+    -0x1.999999999999ap-12
+  },
+  { // Entry 575
+    0x1.fffffa3d70a69ad42b39d8696632f856p-1,
+    0x1.3333333333334p-11
+  },
+  { // Entry 576
+    0x1.fffffa3d70a69ad42b39d8696632f856p-1,
+    -0x1.3333333333334p-11
+  },
+  { // Entry 577
+    0x1.fffff5c28f64e5ec0da0a4f7f4388052p-1,
+    0x1.999999999999ap-11
+  },
+  { // Entry 578
+    0x1.fffff5c28f64e5ec0da0a4f7f4388052p-1,
+    -0x1.999999999999ap-11
+  },
+  { // Entry 579
+    0x1.fffff0000015555549f49f4d34d34ca0p-1,
+    0x1.0p-10
+  },
+  { // Entry 580
+    0x1.fffff0000015555549f49f4d34d34ca0p-1,
+    -0x1.0p-10
+  },
+  { // Entry 581
+    0x1.ffffe8f5c2bb98c7c103d2ff79f15d6ap-1,
+    0x1.3333333333333p-10
+  },
+  { // Entry 582
+    0x1.ffffe8f5c2bb98c7c103d2ff79f15d6ap-1,
+    -0x1.3333333333333p-10
+  },
+  { // Entry 583
+    0x1.ffffe0a3d75c31b26451166d6f398abdp-1,
+    0x1.6666666666666p-10
+  },
+  { // Entry 584
+    0x1.ffffe0a3d75c31b26451166d6f398abdp-1,
+    -0x1.6666666666666p-10
+  },
+  { // Entry 585
+    0x1.ffffd70a3dfc733b3331d8382b1e9df5p-1,
+    0x1.9999999999999p-10
+  },
+  { // Entry 586
+    0x1.ffffd70a3dfc733b3331d8382b1e9df5p-1,
+    -0x1.9999999999999p-10
+  },
+  { // Entry 587
+    0x1.ffffcc28f6a2823f3765b50659ecb0e2p-1,
+    0x1.cccccccccccccp-10
+  },
+  { // Entry 588
+    0x1.ffffcc28f6a2823f3765b50659ecb0e2p-1,
+    -0x1.cccccccccccccp-10
+  },
+  { // Entry 589
+    0x1.fffbcc2a6e86fef7d2af1580bd8e6699p-1,
+    0x1.0666666666666p-7
+  },
+  { // Entry 590
+    0x1.fffbcc2a6e86fef7d2af1580bd8e6699p-1,
+    -0x1.0666666666666p-7
+  },
+  { // Entry 591
+    0x1.fff30a4b6fcc1405e18fbf7335d2f789p-1,
+    0x1.cccccccccccccp-7
+  },
+  { // Entry 592
+    0x1.fff30a4b6fcc1405e18fbf7335d2f789p-1,
+    -0x1.cccccccccccccp-7
+  },
+  { // Entry 593
+    0x1.ffe57a780f38c0db37051fa8c8d60fbcp-1,
+    0x1.4999999999999p-6
+  },
+  { // Entry 594
+    0x1.ffe57a780f38c0db37051fa8c8d60fbcp-1,
+    -0x1.4999999999999p-6
+  },
+  { // Entry 595
+    0x1.ffd31cd0e1d62c05d2cded21add8bd33p-1,
+    0x1.accccccccccccp-6
+  },
+  { // Entry 596
+    0x1.ffd31cd0e1d62c05d2cded21add8bd33p-1,
+    -0x1.accccccccccccp-6
+  },
+  { // Entry 597
+    0x1.ffbbf18207542ef81390d73c3ba89c1ap-1,
+    0x1.080p-5
+  },
+  { // Entry 598
+    0x1.ffbbf18207542ef81390d73c3ba89c1ap-1,
+    -0x1.080p-5
+  },
+  { // Entry 599
+    0x1.ff9ff8c3299f54457bbaf8c12173b46bp-1,
+    0x1.399999999999ap-5
+  },
+  { // Entry 600
+    0x1.ff9ff8c3299f54457bbaf8c12173b46bp-1,
+    -0x1.399999999999ap-5
+  },
+  { // Entry 601
+    0x1.ff7f32d77c5b1c42f1660c9b6f2ef64fp-1,
+    0x1.6b33333333334p-5
+  },
+  { // Entry 602
+    0x1.ff7f32d77c5b1c42f1660c9b6f2ef64fp-1,
+    -0x1.6b33333333334p-5
+  },
+  { // Entry 603
+    0x1.ff59a00dbc40896bb5e4ac8ad293afb4p-1,
+    0x1.9cccccccccccep-5
+  },
+  { // Entry 604
+    0x1.ff59a00dbc40896bb5e4ac8ad293afb4p-1,
+    -0x1.9cccccccccccep-5
+  },
+  { // Entry 605
+    0x1.ff2f40c02e60f61d6dcfc39b6c2be087p-1,
+    0x1.ce66666666666p-5
+  },
+  { // Entry 606
+    0x1.ff2f40c02e60f61d6dcfc39b6c2be087p-1,
+    -0x1.ce66666666666p-5
+  },
+  { // Entry 607
+    0x1.8ca46c7d8975e57a1484f05c3738d83bp-1,
+    0x1.5e7fc4369bdadp-1
+  },
+  { // Entry 608
+    0x1.8ca46c7d8975e57a1484f05c3738d83bp-1,
+    -0x1.5e7fc4369bdadp-1
+  },
+  { // Entry 609
+    0x1.0b5d3802fc7991140168f294eedd7904p-2,
+    0x1.4e7fc4369bdadp0
+  },
+  { // Entry 610
+    0x1.0b5d3802fc7991140168f294eedd7904p-2,
+    -0x1.4e7fc4369bdadp0
+  },
+  { // Entry 611
+    -0x1.66b96f53323af1d7e31a7162ab18a75bp-2,
+    0x1.edbfa651e9c84p0
+  },
+  { // Entry 612
+    -0x1.66b96f53323af1d7e31a7162ab18a75bp-2,
+    -0x1.edbfa651e9c84p0
+  },
+  { // Entry 613
+    -0x1.a93554888c32fa57f22a9529a320c1cbp-1,
+    0x1.467fc4369bdadp1
+  },
+  { // Entry 614
+    -0x1.a93554888c32fa57f22a9529a320c1cbp-1,
+    -0x1.467fc4369bdadp1
+  },
+  { // Entry 615
+    -0x1.ffc00155527d2b9fda2ae89396e09727p-1,
+    0x1.961fb54442d18p1
+  },
+  { // Entry 616
+    -0x1.ffc00155527d2b9fda2ae89396e09727p-1,
+    -0x1.961fb54442d18p1
+  },
+  { // Entry 617
+    -0x1.96907c5c7c25b88e34addff1fbef66e4p-1,
+    0x1.e5bfa651e9c83p1
+  },
+  { // Entry 618
+    -0x1.96907c5c7c25b88e34addff1fbef66e4p-1,
+    -0x1.e5bfa651e9c83p1
+  },
+  { // Entry 619
+    -0x1.2a1e5a50f948cd487c5309682b110a53p-2,
+    0x1.1aafcbafc85f7p2
+  },
+  { // Entry 620
+    -0x1.2a1e5a50f948cd487c5309682b110a53p-2,
+    -0x1.1aafcbafc85f7p2
+  },
+  { // Entry 621
+    0x1.4894f695dc56bce8b273e5524f181264p-2,
+    0x1.427fc4369bdadp2
+  },
+  { // Entry 622
+    0x1.4894f695dc56bce8b273e5524f181264p-2,
+    -0x1.427fc4369bdadp2
+  },
+  { // Entry 623
+    0x1.a016ea3a692ce0c321b77f168de39122p-1,
+    0x1.6a4fbcbd6f562p2
+  },
+  { // Entry 624
+    0x1.a016ea3a692ce0c321b77f168de39122p-1,
+    -0x1.6a4fbcbd6f562p2
+  },
+  { // Entry 625
+    0x1.a30a69f5537ebc22f0870c2bd26ef284p-1,
+    0x1.6af2eff0a2896p2
+  },
+  { // Entry 626
+    0x1.a30a69f5537ebc22f0870c2bd26ef284p-1,
+    -0x1.6af2eff0a2896p2
+  },
+  { // Entry 627
+    0x1.5bd62e8b04ad5915e66242349b756e11p-2,
+    0x1.43c62a9d02414p2
+  },
+  { // Entry 628
+    0x1.5bd62e8b04ad5915e66242349b756e11p-2,
+    -0x1.43c62a9d02414p2
+  },
+  { // Entry 629
+    -0x1.0cb71f671e63410966e78d2009c0616fp-2,
+    0x1.1c99654961f92p2
+  },
+  { // Entry 630
+    -0x1.0cb71f671e63410966e78d2009c0616fp-2,
+    -0x1.1c99654961f92p2
+  },
+  { // Entry 631
+    -0x1.89d86aa8521c11b74f8b1954c08f9b36p-1,
+    0x1.ead93feb8361fp1
+  },
+  { // Entry 632
+    -0x1.89d86aa8521c11b74f8b1954c08f9b36p-1,
+    -0x1.ead93feb8361fp1
+  },
+  { // Entry 633
+    -0x1.fe51ac554a16ad8194f181085f8a17f2p-1,
+    0x1.9c7fb54442d1ap1
+  },
+  { // Entry 634
+    -0x1.fe51ac554a16ad8194f181085f8a17f2p-1,
+    -0x1.9c7fb54442d1ap1
+  },
+  { // Entry 635
+    -0x1.b97c04d08bc5d765b341a22b2c720b6fp-1,
+    0x1.4e262a9d02415p1
+  },
+  { // Entry 636
+    -0x1.b97c04d08bc5d765b341a22b2c720b6fp-1,
+    -0x1.4e262a9d02415p1
+  },
+  { // Entry 637
+    -0x1.a8ac8a3e58f6ca952390299d2e8b187fp-2,
+    0x1.ff993feb83620p0
+  },
+  { // Entry 638
+    -0x1.a8ac8a3e58f6ca952390299d2e8b187fp-2,
+    -0x1.ff993feb83620p0
+  },
+  { // Entry 639
+    0x1.77a8b9b3d254a9e39d02b3eb3e2390e7p-3,
+    0x1.62e62a9d02416p0
+  },
+  { // Entry 640
+    0x1.77a8b9b3d254a9e39d02b3eb3e2390e7p-3,
+    -0x1.62e62a9d02416p0
+  },
+  { // Entry 641
+    0x1.6e1061205dd79051c112d30a05097c61p-1,
+    0x1.8c662a9d02419p-1
+  },
+  { // Entry 642
+    0x1.6e1061205dd79051c112d30a05097c61p-1,
+    -0x1.8c662a9d02419p-1
+  },
+  { // Entry 643
+    -0x1.682f3cc3c7a08da2ce02a41cdc7bed86p-4,
+    -0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 644
+    -0x1.682f3cc3c7a08da2ce02a41cdc7bed86p-4,
+    0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 645
+    -0x1.e6669a270c36d4879b428ddba96cd87bp-7,
+    -0x1.95ec8b9e03d54p0
+  },
+  { // Entry 646
+    -0x1.e6669a270c36d4879b428ddba96cd87bp-7,
+    0x1.95ec8b9e03d54p0
+  },
+  { // Entry 647
+    0x1.ddd1ec25e209f1bbf7e17ef6c8450cd7p-5,
+    -0x1.832efa2a435a9p0
+  },
+  { // Entry 648
+    0x1.ddd1ec25e209f1bbf7e17ef6c8450cd7p-5,
+    0x1.832efa2a435a9p0
+  },
+  { // Entry 649
+    0x1.0cab9115640d993082a7343bb5affea2p-3,
+    -0x1.707168b682dfep0
+  },
+  { // Entry 650
+    0x1.0cab9115640d993082a7343bb5affea2p-3,
+    0x1.707168b682dfep0
+  },
+  { // Entry 651
+    0x1.a0723a95492edee5dc98394e45f96d88p-3,
+    -0x1.5db3d742c2653p0
+  },
+  { // Entry 652
+    0x1.a0723a95492edee5dc98394e45f96d88p-3,
+    0x1.5db3d742c2653p0
+  },
+  { // Entry 653
+    0x1.18fee96a1a585928a94cda7e3d916fe1p-2,
+    -0x1.4af645cf01ea8p0
+  },
+  { // Entry 654
+    0x1.18fee96a1a585928a94cda7e3d916fe1p-2,
+    0x1.4af645cf01ea8p0
+  },
+  { // Entry 655
+    0x1.6043621b13be2ff07085f8278598e566p-2,
+    -0x1.3838b45b416fdp0
+  },
+  { // Entry 656
+    0x1.6043621b13be2ff07085f8278598e566p-2,
+    0x1.3838b45b416fdp0
+  },
+  { // Entry 657
+    0x1.a5a4ccf40d9d9ba97faa4e23ecce9e3ap-2,
+    -0x1.257b22e780f52p0
+  },
+  { // Entry 658
+    0x1.a5a4ccf40d9d9ba97faa4e23ecce9e3ap-2,
+    0x1.257b22e780f52p0
+  },
+  { // Entry 659
+    0x1.e8c405f36f85b7f5d6a38dfd4a692341p-2,
+    -0x1.12bd9173c07abp0
+  },
+  { // Entry 660
+    0x1.e8c405f36f85b7f5d6a38dfd4a692341p-2,
+    0x1.12bd9173c07abp0
+  },
+  { // Entry 661
+    0x1.26976a6c4e0f86633327f1ceecb508aep-1,
+    -0x1.ea5c3ed5b3850p-1
+  },
+  { // Entry 662
+    0x1.26976a6c4e0f86633327f1ceecb508aep-1,
+    0x1.ea5c3ed5b3850p-1
+  },
+  { // Entry 663
+    0x1.3805a1882009f2843da808e959f17861p-1,
+    -0x1.d4b87dab670a0p-1
+  },
+  { // Entry 664
+    0x1.3805a1882009f2843da808e959f17861p-1,
+    0x1.d4b87dab670a0p-1
+  },
+  { // Entry 665
+    0x1.48e52e0a65bcb3cd46455c4d2338bdf2p-1,
+    -0x1.bf14bc811a8f0p-1
+  },
+  { // Entry 666
+    0x1.48e52e0a65bcb3cd46455c4d2338bdf2p-1,
+    0x1.bf14bc811a8f0p-1
+  },
+  { // Entry 667
+    0x1.592e58ea0a9eec0b357eb4e9a83b0ea5p-1,
+    -0x1.a970fb56ce140p-1
+  },
+  { // Entry 668
+    0x1.592e58ea0a9eec0b357eb4e9a83b0ea5p-1,
+    0x1.a970fb56ce140p-1
+  },
+  { // Entry 669
+    0x1.68d9afe052d1f0e9324ae876961bcdb1p-1,
+    -0x1.93cd3a2c81990p-1
+  },
+  { // Entry 670
+    0x1.68d9afe052d1f0e9324ae876961bcdb1p-1,
+    0x1.93cd3a2c81990p-1
+  },
+  { // Entry 671
+    0x1.77e008d0775e744eb16a2c4ec7184c43p-1,
+    -0x1.7e297902351e0p-1
+  },
+  { // Entry 672
+    0x1.77e008d0775e744eb16a2c4ec7184c43p-1,
+    0x1.7e297902351e0p-1
+  },
+  { // Entry 673
+    0x1.863a850e438fe029302aba0f5f127616p-1,
+    -0x1.6885b7d7e8a30p-1
+  },
+  { // Entry 674
+    0x1.863a850e438fe029302aba0f5f127616p-1,
+    0x1.6885b7d7e8a30p-1
+  },
+  { // Entry 675
+    0x1.93e2948233fce814439ed51fd2548920p-1,
+    -0x1.52e1f6ad9c280p-1
+  },
+  { // Entry 676
+    0x1.93e2948233fce814439ed51fd2548920p-1,
+    0x1.52e1f6ad9c280p-1
+  },
+  { // Entry 677
+    0x1.a0d1f8a9a791d4b5694ca68a42fe6c9bp-1,
+    -0x1.3d3e35834fad0p-1
+  },
+  { // Entry 678
+    0x1.a0d1f8a9a791d4b5694ca68a42fe6c9bp-1,
+    0x1.3d3e35834fad0p-1
+  },
+  { // Entry 679
+    0x1.bc6bd861e13de309428e00f7bef6c3ecp-1,
+    -0x1.0a0b02501c799p-1
+  },
+  { // Entry 680
+    0x1.bc6bd861e13de309428e00f7bef6c3ecp-1,
+    0x1.0a0b02501c799p-1
+  },
+  { // Entry 681
+    0x1.ca59c6fa3d9ce238a227393b6b075bc5p-1,
+    -0x1.d8f7208e6b82cp-2
+  },
+  { // Entry 682
+    0x1.ca59c6fa3d9ce238a227393b6b075bc5p-1,
+    0x1.d8f7208e6b82cp-2
+  },
+  { // Entry 683
+    0x1.d6c0b125791cffce83e32564712b78c6p-1,
+    -0x1.9dd83c7c9e126p-2
+  },
+  { // Entry 684
+    0x1.d6c0b125791cffce83e32564712b78c6p-1,
+    0x1.9dd83c7c9e126p-2
+  },
+  { // Entry 685
+    0x1.e1960261829858391645bbe12019e58ap-1,
+    -0x1.62b9586ad0a20p-2
+  },
+  { // Entry 686
+    0x1.e1960261829858391645bbe12019e58ap-1,
+    0x1.62b9586ad0a20p-2
+  },
+  { // Entry 687
+    0x1.ead07cc6356964e27a1036d2f8b158f7p-1,
+    -0x1.279a74590331ap-2
+  },
+  { // Entry 688
+    0x1.ead07cc6356964e27a1036d2f8b158f7p-1,
+    0x1.279a74590331ap-2
+  },
+  { // Entry 689
+    0x1.f26840e7b2188f7a0cc661a0ede3728bp-1,
+    -0x1.d8f7208e6b829p-3
+  },
+  { // Entry 690
+    0x1.f26840e7b2188f7a0cc661a0ede3728bp-1,
+    0x1.d8f7208e6b829p-3
+  },
+  { // Entry 691
+    0x1.f856d48db797dec0b79e1353409dc3f2p-1,
+    -0x1.62b9586ad0a1ep-3
+  },
+  { // Entry 692
+    0x1.f856d48db797dec0b79e1353409dc3f2p-1,
+    0x1.62b9586ad0a1ep-3
+  },
+  { // Entry 693
+    0x1.fc97283a424797215f8a8d1967736c9bp-1,
+    -0x1.d8f7208e6b826p-4
+  },
+  { // Entry 694
+    0x1.fc97283a424797215f8a8d1967736c9bp-1,
+    0x1.d8f7208e6b826p-4
+  },
+  { // Entry 695
+    0x1.ff259b7ab9f4f9a8cb9f1c333272e409p-1,
+    -0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 696
+    0x1.ff259b7ab9f4f9a8cb9f1c333272e409p-1,
+    0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 697
+    0x1.ff259b7ab9f4f9a8cb9f1c333272e409p-1,
+    0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 698
+    0x1.ff259b7ab9f4f9a8cb9f1c333272e409p-1,
+    -0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 699
+    0x1.fc97283a424795847294654a1d8a08edp-1,
+    0x1.d8f7208e6b82dp-4
+  },
+  { // Entry 700
+    0x1.fc97283a424795847294654a1d8a08edp-1,
+    -0x1.d8f7208e6b82dp-4
+  },
+  { // Entry 701
+    0x1.f856d48db797dbfecfa8b4cd3be44027p-1,
+    0x1.62b9586ad0a22p-3
+  },
+  { // Entry 702
+    0x1.f856d48db797dbfecfa8b4cd3be44027p-1,
+    -0x1.62b9586ad0a22p-3
+  },
+  { // Entry 703
+    0x1.f26840e7b2188bd0814e3dfc7f6f3f87p-1,
+    0x1.d8f7208e6b82dp-3
+  },
+  { // Entry 704
+    0x1.f26840e7b2188bd0814e3dfc7f6f3f87p-1,
+    -0x1.d8f7208e6b82dp-3
+  },
+  { // Entry 705
+    0x1.ead07cc6356960546ae634ef62621fb2p-1,
+    0x1.279a74590331cp-2
+  },
+  { // Entry 706
+    0x1.ead07cc6356960546ae634ef62621fb2p-1,
+    -0x1.279a74590331cp-2
+  },
+  { // Entry 707
+    0x1.e1960261829852ca662ca27d518c2fa9p-1,
+    0x1.62b9586ad0a22p-2
+  },
+  { // Entry 708
+    0x1.e1960261829852ca662ca27d518c2fa9p-1,
+    -0x1.62b9586ad0a22p-2
+  },
+  { // Entry 709
+    0x1.d6c0b125791cf983d53efaa7d45e291ep-1,
+    0x1.9dd83c7c9e128p-2
+  },
+  { // Entry 710
+    0x1.d6c0b125791cf983d53efaa7d45e291ep-1,
+    -0x1.9dd83c7c9e128p-2
+  },
+  { // Entry 711
+    0x1.ca59c6fa3d9cdb17530927aff1b33abbp-1,
+    0x1.d8f7208e6b82ep-2
+  },
+  { // Entry 712
+    0x1.ca59c6fa3d9cdb17530927aff1b33abbp-1,
+    -0x1.d8f7208e6b82ep-2
+  },
+  { // Entry 713
+    0x1.bc6bd861e13de309428e00f7bef6c3ecp-1,
+    0x1.0a0b02501c799p-1
+  },
+  { // Entry 714
+    0x1.bc6bd861e13de309428e00f7bef6c3ecp-1,
+    -0x1.0a0b02501c799p-1
+  },
+  { // Entry 715
+    0x1.a0d1f8a9a791f9dff5c993af4908264dp-1,
+    0x1.3d3e35834faccp-1
+  },
+  { // Entry 716
+    0x1.a0d1f8a9a791f9dff5c993af4908264dp-1,
+    -0x1.3d3e35834faccp-1
+  },
+  { // Entry 717
+    0x1.93e2948233fd0f69e3918982148f8265p-1,
+    0x1.52e1f6ad9c27cp-1
+  },
+  { // Entry 718
+    0x1.93e2948233fd0f69e3918982148f8265p-1,
+    -0x1.52e1f6ad9c27cp-1
+  },
+  { // Entry 719
+    0x1.863a850e43900997e76be80405437377p-1,
+    0x1.6885b7d7e8a2cp-1
+  },
+  { // Entry 720
+    0x1.863a850e43900997e76be80405437377p-1,
+    -0x1.6885b7d7e8a2cp-1
+  },
+  { // Entry 721
+    0x1.77e008d0775e9fc38e3f492f8e93ff51p-1,
+    0x1.7e297902351dcp-1
+  },
+  { // Entry 722
+    0x1.77e008d0775e9fc38e3f492f8e93ff51p-1,
+    -0x1.7e297902351dcp-1
+  },
+  { // Entry 723
+    0x1.68d9afe052d21e50560f9ffb6cc1b945p-1,
+    0x1.93cd3a2c8198cp-1
+  },
+  { // Entry 724
+    0x1.68d9afe052d21e50560f9ffb6cc1b945p-1,
+    -0x1.93cd3a2c8198cp-1
+  },
+  { // Entry 725
+    0x1.592e58ea0a9f1b4fddbaaf868fe47911p-1,
+    0x1.a970fb56ce13cp-1
+  },
+  { // Entry 726
+    0x1.592e58ea0a9f1b4fddbaaf868fe47911p-1,
+    -0x1.a970fb56ce13cp-1
+  },
+  { // Entry 727
+    0x1.48e52e0a65bce4d9d62a31293f7d41c1p-1,
+    0x1.bf14bc811a8ecp-1
+  },
+  { // Entry 728
+    0x1.48e52e0a65bce4d9d62a31293f7d41c1p-1,
+    -0x1.bf14bc811a8ecp-1
+  },
+  { // Entry 729
+    0x1.3805a188200a254247f30462c36acf6ap-1,
+    0x1.d4b87dab6709cp-1
+  },
+  { // Entry 730
+    0x1.3805a188200a254247f30462c36acf6ap-1,
+    -0x1.d4b87dab6709cp-1
+  },
+  { // Entry 731
+    0x1.26976a6c4e0fbabb84632bd99feec9c6p-1,
+    0x1.ea5c3ed5b384cp-1
+  },
+  { // Entry 732
+    0x1.26976a6c4e0fbabb84632bd99feec9c6p-1,
+    -0x1.ea5c3ed5b384cp-1
+  },
+  { // Entry 733
+    0x1.e8c405f36f85b7f5d6a38dfd4a692341p-2,
+    0x1.12bd9173c07abp0
+  },
+  { // Entry 734
+    0x1.e8c405f36f85b7f5d6a38dfd4a692341p-2,
+    -0x1.12bd9173c07abp0
+  },
+  { // Entry 735
+    0x1.a5a4ccf40d9cb25f16ad97e480c4b483p-2,
+    0x1.257b22e780f56p0
+  },
+  { // Entry 736
+    0x1.a5a4ccf40d9cb25f16ad97e480c4b483p-2,
+    -0x1.257b22e780f56p0
+  },
+  { // Entry 737
+    0x1.6043621b13bd3f904b3b876df5b2c6f4p-2,
+    0x1.3838b45b41701p0
+  },
+  { // Entry 738
+    0x1.6043621b13bd3f904b3b876df5b2c6f4p-2,
+    -0x1.3838b45b41701p0
+  },
+  { // Entry 739
+    0x1.18fee96a1a5762fc6770ff168e06ab3ep-2,
+    0x1.4af645cf01eacp0
+  },
+  { // Entry 740
+    0x1.18fee96a1a5762fc6770ff168e06ab3ep-2,
+    -0x1.4af645cf01eacp0
+  },
+  { // Entry 741
+    0x1.a0723a95492ce998457fb7a0d09a6385p-3,
+    0x1.5db3d742c2657p0
+  },
+  { // Entry 742
+    0x1.a0723a95492ce998457fb7a0d09a6385p-3,
+    -0x1.5db3d742c2657p0
+  },
+  { // Entry 743
+    0x1.0cab9115640b9d9d466723bbd5d589bep-3,
+    0x1.707168b682e02p0
+  },
+  { // Entry 744
+    0x1.0cab9115640b9d9d466723bbd5d589bep-3,
+    -0x1.707168b682e02p0
+  },
+  { // Entry 745
+    0x1.ddd1ec25e201f538925bf5bcf7c7df6ep-5,
+    0x1.832efa2a435adp0
+  },
+  { // Entry 746
+    0x1.ddd1ec25e201f538925bf5bcf7c7df6ep-5,
+    -0x1.832efa2a435adp0
+  },
+  { // Entry 747
+    -0x1.e6669a270c56d3a08d91cc2721f92fe1p-7,
+    0x1.95ec8b9e03d58p0
+  },
+  { // Entry 748
+    -0x1.e6669a270c56d3a08d91cc2721f92fe1p-7,
+    -0x1.95ec8b9e03d58p0
+  },
+  { // Entry 749
+    -0x1.682f3cc3c7a08da2ce02a41cdc7bed86p-4,
+    0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 750
+    -0x1.682f3cc3c7a08da2ce02a41cdc7bed86p-4,
+    -0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 751
+    0x1.0cb3469a29ea66d4031be769702aad5cp-1,
+    0x1.04aff6d330942p0
+  },
+  { // Entry 752
+    0x1.0cb3469a29ea66d4031be769702aad5cp-1,
+    -0x1.04aff6d330942p0
+  },
+  { // Entry 753
+    0x1.0cb228fa7f8117c82e61cf5393341c64p-1,
+    0x1.04b09e98dcdb4p0
+  },
+  { // Entry 754
+    0x1.0cb228fa7f8117c82e61cf5393341c64p-1,
+    -0x1.04b09e98dcdb4p0
+  },
+  { // Entry 755
+    0x1.0cb10b5a61b05a73e78a3e4447baf514p-1,
+    0x1.04b1465e89226p0
+  },
+  { // Entry 756
+    0x1.0cb10b5a61b05a73e78a3e4447baf514p-1,
+    -0x1.04b1465e89226p0
+  },
+  { // Entry 757
+    0x1.0cafedb9d078a984086928aa40d2e4a5p-1,
+    0x1.04b1ee2435698p0
+  },
+  { // Entry 758
+    0x1.0cafedb9d078a984086928aa40d2e4a5p-1,
+    -0x1.04b1ee2435698p0
+  },
+  { // Entry 759
+    0x1.0caed018cbda7fa59c631cd55b31aa8dp-1,
+    0x1.04b295e9e1b0ap0
+  },
+  { // Entry 760
+    0x1.0caed018cbda7fa59c631cd55b31aa8dp-1,
+    -0x1.04b295e9e1b0ap0
+  },
+  { // Entry 761
+    0x1.0cadb27753d65785e06d0e464006149ep-1,
+    0x1.04b33daf8df7cp0
+  },
+  { // Entry 762
+    0x1.0cadb27753d65785e06d0e464006149ep-1,
+    -0x1.04b33daf8df7cp0
+  },
+  { // Entry 763
+    0x1.0cac94d5686cabd2430c20fdf2855b47p-1,
+    0x1.04b3e5753a3eep0
+  },
+  { // Entry 764
+    0x1.0cac94d5686cabd2430c20fdf2855b47p-1,
+    -0x1.04b3e5753a3eep0
+  },
+  { // Entry 765
+    0x1.0cab7733099df738645574cd482ef4b2p-1,
+    0x1.04b48d3ae6860p0
+  },
+  { // Entry 766
+    0x1.0cab7733099df738645574cd482ef4b2p-1,
+    -0x1.04b48d3ae6860p0
+  },
+  { // Entry 767
+    0x1.0caa5990376b061ec1cf3890f1b8e1e3p-1,
+    0x1.04b5350092ccfp0
+  },
+  { // Entry 768
+    0x1.0caa5990376b061ec1cf3890f1b8e1e3p-1,
+    -0x1.04b5350092ccfp0
+  },
+  { // Entry 769
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074
+  },
+  { // Entry 770
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074
+  },
+  { // Entry 771
+    0x1.p0,
+    -0.0
+  },
+  { // Entry 772
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074
+  },
+  { // Entry 773
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074
+  },
+  { // Entry 774
+    0x1.ad02c771c35ed5f01089a00c6a27e0cfp-1,
+    0x1.279a74590331bp-1
+  },
+  { // Entry 775
+    0x1.ad02c771c35ed5f01089a00c6a27e0cfp-1,
+    -0x1.279a74590331bp-1
+  },
+  { // Entry 776
+    0x1.ad02c771c35ecd3471de9021e6c3b92bp-1,
+    0x1.279a74590331cp-1
+  },
+  { // Entry 777
+    0x1.ad02c771c35ecd3471de9021e6c3b92bp-1,
+    -0x1.279a74590331cp-1
+  },
+  { // Entry 778
+    0x1.ad02c771c35ec478d333803762f450d5p-1,
+    0x1.279a74590331dp-1
+  },
+  { // Entry 779
+    0x1.ad02c771c35ec478d333803762f450d5p-1,
+    -0x1.279a74590331dp-1
+  },
+  { // Entry 780
+    -0x1.48d1ddd2b2b3f8c21b9421e65b380735p-3,
+    0x1.bb67ae8584ca9p0
+  },
+  { // Entry 781
+    -0x1.48d1ddd2b2b3f8c21b9421e65b380735p-3,
+    -0x1.bb67ae8584ca9p0
+  },
+  { // Entry 782
+    -0x1.48d1ddd2b2b47718ff3063b6bd981099p-3,
+    0x1.bb67ae8584caap0
+  },
+  { // Entry 783
+    -0x1.48d1ddd2b2b47718ff3063b6bd981099p-3,
+    -0x1.bb67ae8584caap0
+  },
+  { // Entry 784
+    -0x1.48d1ddd2b2b4f56fe2cca5871eaf4820p-3,
+    0x1.bb67ae8584cabp0
+  },
+  { // Entry 785
+    -0x1.48d1ddd2b2b4f56fe2cca5871eaf4820p-3,
+    -0x1.bb67ae8584cabp0
+  },
+  { // Entry 786
+    0x1.cfc6cfa52ad9f9911db4ca0d45fdb0b3p-1,
+    0x1.bffffffffffffp-2
+  },
+  { // Entry 787
+    0x1.cfc6cfa52ad9f9911db4ca0d45fdb0b3p-1,
+    -0x1.bffffffffffffp-2
+  },
+  { // Entry 788
+    0x1.cfc6cfa52ad9f62d6d5423ca8339a00ap-1,
+    0x1.cp-2
+  },
+  { // Entry 789
+    0x1.cfc6cfa52ad9f62d6d5423ca8339a00ap-1,
+    -0x1.cp-2
+  },
+  { // Entry 790
+    0x1.cfc6cfa52ad9f2c9bcf37d87c05892f5p-1,
+    0x1.c000000000001p-2
+  },
+  { // Entry 791
+    0x1.cfc6cfa52ad9f2c9bcf37d87c05892f5p-1,
+    -0x1.c000000000001p-2
+  },
+  { // Entry 792
+    0x1.8bb105a5dc90104051d08cb965631807p-1,
+    0x1.5ffffffffffffp-1
+  },
+  { // Entry 793
+    0x1.8bb105a5dc90104051d08cb965631807p-1,
+    -0x1.5ffffffffffffp-1
+  },
+  { // Entry 794
+    0x1.8bb105a5dc900618f80fa51d303c69p-1,
+    0x1.6p-1
+  },
+  { // Entry 795
+    0x1.8bb105a5dc900618f80fa51d303c69p-1,
+    -0x1.6p-1
+  },
+  { // Entry 796
+    0x1.8bb105a5dc8ffbf19e4ebd80fab2cdb8p-1,
+    0x1.6000000000001p-1
+  },
+  { // Entry 797
+    0x1.8bb105a5dc8ffbf19e4ebd80fab2cdb8p-1,
+    -0x1.6000000000001p-1
+  },
+  { // Entry 798
+    0x1.7ef4842f0bcd11686aaf6f21c9aa8354p-2,
+    0x1.2ffffffffffffp0
+  },
+  { // Entry 799
+    0x1.7ef4842f0bcd11686aaf6f21c9aa8354p-2,
+    -0x1.2ffffffffffffp0
+  },
+  { // Entry 800
+    0x1.7ef4842f0bccd60d4a501dc8bc4b57b3p-2,
+    0x1.3p0
+  },
+  { // Entry 801
+    0x1.7ef4842f0bccd60d4a501dc8bc4b57b3p-2,
+    -0x1.3p0
+  },
+  { // Entry 802
+    0x1.7ef4842f0bcc9ab229f0cc6fad6d378dp-2,
+    0x1.3000000000001p0
+  },
+  { // Entry 803
+    0x1.7ef4842f0bcc9ab229f0cc6fad6d378dp-2,
+    -0x1.3000000000001p0
+  },
+  { // Entry 804
+    -0x1.863efa361dc2294e929b9515fb34f9bap-1,
+    0x1.37fffffffffffp1
+  },
+  { // Entry 805
+    -0x1.863efa361dc2294e929b9515fb34f9bap-1,
+    -0x1.37fffffffffffp1
+  },
+  { // Entry 806
+    -0x1.863efa361dc252bca1eaeed39749bed7p-1,
+    0x1.380p1
+  },
+  { // Entry 807
+    -0x1.863efa361dc252bca1eaeed39749bed7p-1,
+    -0x1.380p1
+  },
+  { // Entry 808
+    -0x1.863efa361dc27c2ab13a48912d45880bp-1,
+    0x1.3800000000001p1
+  },
+  { // Entry 809
+    -0x1.863efa361dc27c2ab13a48912d45880bp-1,
+    -0x1.3800000000001p1
+  },
+  { // Entry 810
+    0x1.fef2b2d21cf6c106e86ff9395f8204a0p-1,
+    0x1.069c8b46b3792p-4
+  },
+  { // Entry 811
+    0x1.fef2b2d21cf6c106e86ff9395f8204a0p-1,
+    -0x1.069c8b46b3792p-4
+  },
+  { // Entry 812
+    0x1.fbcbe693bd8ec85723b6cb55e4f5e78fp-1,
+    0x1.069c8b46b3792p-3
+  },
+  { // Entry 813
+    0x1.fbcbe693bd8ec85723b6cb55e4f5e78fp-1,
+    -0x1.069c8b46b3792p-3
+  },
+  { // Entry 814
+    0x1.f68eebfcbb5e841900e2542f7c24bab0p-1,
+    0x1.89ead0ea0d35bp-3
+  },
+  { // Entry 815
+    0x1.f68eebfcbb5e841900e2542f7c24bab0p-1,
+    -0x1.89ead0ea0d35bp-3
+  },
+  { // Entry 816
+    0x1.ef4145b4aecffbdaaffb78ffb49ac9bdp-1,
+    0x1.069c8b46b3792p-2
+  },
+  { // Entry 817
+    0x1.ef4145b4aecffbdaaffb78ffb49ac9bdp-1,
+    -0x1.069c8b46b3792p-2
+  },
+  { // Entry 818
+    0x1.e5eaa286fbbc670dbf6392d7c98ab0a0p-1,
+    0x1.4843ae1860576p-2
+  },
+  { // Entry 819
+    0x1.e5eaa286fbbc670dbf6392d7c98ab0a0p-1,
+    -0x1.4843ae1860576p-2
+  },
+  { // Entry 820
+    0x1.da94d54dd4c0876e18ee97c70d1a4a94p-1,
+    0x1.89ead0ea0d35ap-2
+  },
+  { // Entry 821
+    0x1.da94d54dd4c0876e18ee97c70d1a4a94p-1,
+    -0x1.89ead0ea0d35ap-2
+  },
+  { // Entry 822
+    0x1.cd4bca9cb5c715302001e446cc93a7bcp-1,
+    0x1.cb91f3bbba13ep-2
+  },
+  { // Entry 823
+    0x1.cd4bca9cb5c715302001e446cc93a7bcp-1,
+    -0x1.cb91f3bbba13ep-2
+  },
+  { // Entry 824
+    0x1.be1d7c3534c40331fddf243d8a0a56b0p-1,
+    0x1.069c8b46b3791p-1
+  },
+  { // Entry 825
+    0x1.be1d7c3534c40331fddf243d8a0a56b0p-1,
+    -0x1.069c8b46b3791p-1
+  },
+  { // Entry 826
+    0x1.ad19e2535aa9678bd5fdafc68817700bp-1,
+    0x1.27701caf89e83p-1
+  },
+  { // Entry 827
+    0x1.ad19e2535aa9678bd5fdafc68817700bp-1,
+    -0x1.27701caf89e83p-1
+  },
+  { // Entry 828
+    0x1.9a52e2e0fbcb3a3f4bde6f6ec27767a9p-1,
+    0x1.4843ae1860575p-1
+  },
+  { // Entry 829
+    0x1.9a52e2e0fbcb3a3f4bde6f6ec27767a9p-1,
+    -0x1.4843ae1860575p-1
+  },
+  { // Entry 830
+    0x1.85dc3ea1bbce9a8085f66593a87b7e2ep-1,
+    0x1.69173f8136c67p-1
+  },
+  { // Entry 831
+    0x1.85dc3ea1bbce9a8085f66593a87b7e2ep-1,
+    -0x1.69173f8136c67p-1
+  },
+  { // Entry 832
+    0x1.6fcb7c6b8b919af3dda53094c9a27aabp-1,
+    0x1.89ead0ea0d359p-1
+  },
+  { // Entry 833
+    0x1.6fcb7c6b8b919af3dda53094c9a27aabp-1,
+    -0x1.89ead0ea0d359p-1
+  },
+  { // Entry 834
+    0x1.5837d2817cf303ef6dae69faeb0f015ep-1,
+    0x1.aabe6252e3a4bp-1
+  },
+  { // Entry 835
+    0x1.5837d2817cf303ef6dae69faeb0f015ep-1,
+    -0x1.aabe6252e3a4bp-1
+  },
+  { // Entry 836
+    0x1.3f3a0e28bedd40445858f823e150264bp-1,
+    0x1.cb91f3bbba13dp-1
+  },
+  { // Entry 837
+    0x1.3f3a0e28bedd40445858f823e150264bp-1,
+    -0x1.cb91f3bbba13dp-1
+  },
+  { // Entry 838
+    0x1.24ec799171642dbd24d259005822bd25p-1,
+    0x1.ec6585249082fp-1
+  },
+  { // Entry 839
+    0x1.24ec799171642dbd24d259005822bd25p-1,
+    -0x1.ec6585249082fp-1
+  },
+  { // Entry 840
+    0x1.096ac02ec42c85b7b10afed9202785b9p-1,
+    0x1.069c8b46b3791p0
+  },
+  { // Entry 841
+    0x1.096ac02ec42c85b7b10afed9202785b9p-1,
+    -0x1.069c8b46b3791p0
+  },
+  { // Entry 842
+    0x1.d9a3a336edb7613df062e86a32d09fe1p-2,
+    0x1.170653fb1eb0ap0
+  },
+  { // Entry 843
+    0x1.d9a3a336edb7613df062e86a32d09fe1p-2,
+    -0x1.170653fb1eb0ap0
+  },
+  { // Entry 844
+    0x1.9e7f8652b47582afd29744293170c07cp-2,
+    0x1.27701caf89e83p0
+  },
+  { // Entry 845
+    0x1.9e7f8652b47582afd29744293170c07cp-2,
+    -0x1.27701caf89e83p0
+  },
+  { // Entry 846
+    0x1.61a76077aee07bb349ca76cf700913d1p-2,
+    0x1.37d9e563f51fcp0
+  },
+  { // Entry 847
+    0x1.61a76077aee07bb349ca76cf700913d1p-2,
+    -0x1.37d9e563f51fcp0
+  },
+  { // Entry 848
+    0x1.235b331d8f748e20fb6ddb6a708dba10p-2,
+    0x1.4843ae1860575p0
+  },
+  { // Entry 849
+    0x1.235b331d8f748e20fb6ddb6a708dba10p-2,
+    -0x1.4843ae1860575p0
+  },
+  { // Entry 850
+    0x1.c7b90e3024593da8449963cfe08dde85p-3,
+    0x1.58ad76cccb8eep0
+  },
+  { // Entry 851
+    0x1.c7b90e3024593da8449963cfe08dde85p-3,
+    -0x1.58ad76cccb8eep0
+  },
+  { // Entry 852
+    0x1.46dc4f4ce83da727ea048cc7d2f276d1p-3,
+    0x1.69173f8136c67p0
+  },
+  { // Entry 853
+    0x1.46dc4f4ce83da727ea048cc7d2f276d1p-3,
+    -0x1.69173f8136c67p0
+  },
+  { // Entry 854
+    0x1.894f70befbb99ab7df9d1790a28f48adp-4,
+    0x1.79810835a1fe0p0
+  },
+  { // Entry 855
+    0x1.894f70befbb99ab7df9d1790a28f48adp-4,
+    -0x1.79810835a1fe0p0
+  },
+  { // Entry 856
+    0x1.069107ae9332f95fa2c5ceeadfb29f77p-5,
+    0x1.89ead0ea0d359p0
+  },
+  { // Entry 857
+    0x1.069107ae9332f95fa2c5ceeadfb29f77p-5,
+    -0x1.89ead0ea0d359p0
+  },
+  { // Entry 858
+    -0x1.069107ae9327e0731a748c21f03b5efcp-5,
+    0x1.9a54999e786d2p0
+  },
+  { // Entry 859
+    -0x1.069107ae9327e0731a748c21f03b5efcp-5,
+    -0x1.9a54999e786d2p0
+  },
+  { // Entry 860
+    -0x1.894f70befbb41417dff843e81fac388bp-4,
+    0x1.aabe6252e3a4bp0
+  },
+  { // Entry 861
+    -0x1.894f70befbb41417dff843e81fac388bp-4,
+    -0x1.aabe6252e3a4bp0
+  },
+  { // Entry 862
+    -0x1.46dc4f4ce83ae9ab1cc1b2367cb753ebp-3,
+    0x1.bb282b074edc4p0
+  },
+  { // Entry 863
+    -0x1.46dc4f4ce83ae9ab1cc1b2367cb753ebp-3,
+    -0x1.bb282b074edc4p0
+  },
+  { // Entry 864
+    -0x1.c7b90e30245688e099860e8d4fff601cp-3,
+    0x1.cb91f3bbba13dp0
+  },
+  { // Entry 865
+    -0x1.c7b90e30245688e099860e8d4fff601cp-3,
+    -0x1.cb91f3bbba13dp0
+  },
+  { // Entry 866
+    -0x1.235b331d8f7339841a517312d0d347fbp-2,
+    0x1.dbfbbc70254b6p0
+  },
+  { // Entry 867
+    -0x1.235b331d8f7339841a517312d0d347fbp-2,
+    -0x1.dbfbbc70254b6p0
+  },
+  { // Entry 868
+    -0x1.61a76077aedf2e43aca418f7a2e1324dp-2,
+    0x1.ec6585249082fp0
+  },
+  { // Entry 869
+    -0x1.61a76077aedf2e43aca418f7a2e1324dp-2,
+    -0x1.ec6585249082fp0
+  },
+  { // Entry 870
+    -0x1.9e7f8652b4743dcc3c3568baff8bf9ebp-2,
+    0x1.fccf4dd8fbba8p0
+  },
+  { // Entry 871
+    -0x1.9e7f8652b4743dcc3c3568baff8bf9ebp-2,
+    -0x1.fccf4dd8fbba8p0
+  },
+  { // Entry 872
+    -0x1.d9a3a336edb65efa30e1a6679aa064c2p-2,
+    0x1.069c8b46b3791p1
+  },
+  { // Entry 873
+    -0x1.d9a3a336edb65efa30e1a6679aa064c2p-2,
+    -0x1.069c8b46b3791p1
+  },
+  { // Entry 874
+    -0x1.096ac02ec42c24880a5951788cb383c8p-1,
+    0x1.0ed16fa0e914ep1
+  },
+  { // Entry 875
+    -0x1.096ac02ec42c24880a5951788cb383c8p-1,
+    -0x1.0ed16fa0e914ep1
+  },
+  { // Entry 876
+    -0x1.24ec79917163dda65afd8109f59cb465p-1,
+    0x1.170653fb1eb0bp1
+  },
+  { // Entry 877
+    -0x1.24ec79917163dda65afd8109f59cb465p-1,
+    -0x1.170653fb1eb0bp1
+  },
+  { // Entry 878
+    -0x1.3f3a0e28bedd0cf0c4bfbd8c82a3baafp-1,
+    0x1.1f3b3855544c8p1
+  },
+  { // Entry 879
+    -0x1.3f3a0e28bedd0cf0c4bfbd8c82a3baafp-1,
+    -0x1.1f3b3855544c8p1
+  },
+  { // Entry 880
+    -0x1.5837d2817cf2eb069035552dc3ae834cp-1,
+    0x1.27701caf89e85p1
+  },
+  { // Entry 881
+    -0x1.5837d2817cf2eb069035552dc3ae834cp-1,
+    -0x1.27701caf89e85p1
+  },
+  { // Entry 882
+    -0x1.6fcb7c6b8b9199ce2f17dd3ee86b3b9ap-1,
+    0x1.2fa50109bf842p1
+  },
+  { // Entry 883
+    -0x1.6fcb7c6b8b9199ce2f17dd3ee86b3b9ap-1,
+    -0x1.2fa50109bf842p1
+  },
+  { // Entry 884
+    -0x1.85dc3ea1bbceae2d294421e8c7350f8cp-1,
+    0x1.37d9e563f51ffp1
+  },
+  { // Entry 885
+    -0x1.85dc3ea1bbceae2d294421e8c7350f8cp-1,
+    -0x1.37d9e563f51ffp1
+  },
+  { // Entry 886
+    -0x1.9a52e2e0fbcb5f8a3f55c274f9ec754bp-1,
+    0x1.400ec9be2abbcp1
+  },
+  { // Entry 887
+    -0x1.9a52e2e0fbcb5f8a3f55c274f9ec754bp-1,
+    -0x1.400ec9be2abbcp1
+  },
+  { // Entry 888
+    -0x1.ad19e2535aa99b049ac0b5858c5d381fp-1,
+    0x1.4843ae1860579p1
+  },
+  { // Entry 889
+    -0x1.ad19e2535aa99b049ac0b5858c5d381fp-1,
+    -0x1.4843ae1860579p1
+  },
+  { // Entry 890
+    -0x1.be1d7c3534c44132ab1c4130cbe9dfa0p-1,
+    0x1.5078927295f36p1
+  },
+  { // Entry 891
+    -0x1.be1d7c3534c44132ab1c4130cbe9dfa0p-1,
+    -0x1.5078927295f36p1
+  },
+  { // Entry 892
+    -0x1.cd4bca9cb5c759e4d6dc8601ec3d84b6p-1,
+    0x1.58ad76cccb8f3p1
+  },
+  { // Entry 893
+    -0x1.cd4bca9cb5c759e4d6dc8601ec3d84b6p-1,
+    -0x1.58ad76cccb8f3p1
+  },
+  { // Entry 894
+    -0x1.da94d54dd4c0cedccd73684994422740p-1,
+    0x1.60e25b27012b0p1
+  },
+  { // Entry 895
+    -0x1.da94d54dd4c0cedccd73684994422740p-1,
+    -0x1.60e25b27012b0p1
+  },
+  { // Entry 896
+    -0x1.e5eaa286fbbcad1e4a6373392e679669p-1,
+    0x1.69173f8136c6dp1
+  },
+  { // Entry 897
+    -0x1.e5eaa286fbbcad1e4a6373392e679669p-1,
+    -0x1.69173f8136c6dp1
+  },
+  { // Entry 898
+    -0x1.ef4145b4aed03c5f1d39763b1eee6ed8p-1,
+    0x1.714c23db6c62ap1
+  },
+  { // Entry 899
+    -0x1.ef4145b4aed03c5f1d39763b1eee6ed8p-1,
+    -0x1.714c23db6c62ap1
+  },
+  { // Entry 900
+    -0x1.f68eebfcbb5eba124d8cc48fd1beb04dp-1,
+    0x1.79810835a1fe7p1
+  },
+  { // Entry 901
+    -0x1.f68eebfcbb5eba124d8cc48fd1beb04dp-1,
+    -0x1.79810835a1fe7p1
+  },
+  { // Entry 902
+    -0x1.fbcbe693bd8ef006f5ff02210dfe0619p-1,
+    0x1.81b5ec8fd79a4p1
+  },
+  { // Entry 903
+    -0x1.fbcbe693bd8ef006f5ff02210dfe0619p-1,
+    -0x1.81b5ec8fd79a4p1
+  },
+  { // Entry 904
+    -0x1.fef2b2d21cf6be1a2c7ea665ef1f874ep-1,
+    0x1.89ead0ea0d35bp1
+  },
+  { // Entry 905
+    -0x1.fef2b2d21cf6be1a2c7ea665ef1f874ep-1,
+    -0x1.89ead0ea0d35bp1
+  },
+  { // Entry 906
+    0x1.ef4145b4aecff6f58edecf24955428c1p-1,
+    -0x1.81b5ec8fd799fp2
+  },
+  { // Entry 907
+    0x1.ef4145b4aecff6f58edecf24955428c1p-1,
+    0x1.81b5ec8fd799fp2
+  },
+  { // Entry 908
+    0x1.be1d7c3534c3f9b9b35619280049de85p-1,
+    -0x1.714c23db6c626p2
+  },
+  { // Entry 909
+    0x1.be1d7c3534c3f9b9b35619280049de85p-1,
+    0x1.714c23db6c626p2
+  },
+  { // Entry 910
+    0x1.6fcb7c6b8b918d86fc83d612a6587eddp-1,
+    -0x1.60e25b27012adp2
+  },
+  { // Entry 911
+    0x1.6fcb7c6b8b918d86fc83d612a6587eddp-1,
+    0x1.60e25b27012adp2
+  },
+  { // Entry 912
+    0x1.096ac02ec42c82e5b225185bd6c757d5p-1,
+    -0x1.5078927295f34p2
+  },
+  { // Entry 913
+    0x1.096ac02ec42c82e5b225185bd6c757d5p-1,
+    0x1.5078927295f34p2
+  },
+  { // Entry 914
+    0x1.235b331d8f7487ce2db97819fae7777cp-2,
+    -0x1.400ec9be2abbbp2
+  },
+  { // Entry 915
+    0x1.235b331d8f7487ce2db97819fae7777cp-2,
+    0x1.400ec9be2abbbp2
+  },
+  { // Entry 916
+    0x1.069107ae9332c4a1cd2dc033b8d50598p-5,
+    -0x1.2fa50109bf842p2
+  },
+  { // Entry 917
+    0x1.069107ae9332c4a1cd2dc033b8d50598p-5,
+    0x1.2fa50109bf842p2
+  },
+  { // Entry 918
+    -0x1.c7b90e30245695bd1ec170f45feeb1ffp-3,
+    -0x1.1f3b3855544c9p2
+  },
+  { // Entry 919
+    -0x1.c7b90e30245695bd1ec170f45feeb1ffp-3,
+    0x1.1f3b3855544c9p2
+  },
+  { // Entry 920
+    -0x1.d9a3a336edb62c1541b8584cd6c00f87p-2,
+    -0x1.0ed16fa0e9150p2
+  },
+  { // Entry 921
+    -0x1.d9a3a336edb62c1541b8584cd6c00f87p-2,
+    0x1.0ed16fa0e9150p2
+  },
+  { // Entry 922
+    -0x1.5837d2817cf27705cac7881fb569ffc7p-1,
+    -0x1.fccf4dd8fbbaep1
+  },
+  { // Entry 923
+    -0x1.5837d2817cf27705cac7881fb569ffc7p-1,
+    0x1.fccf4dd8fbbaep1
+  },
+  { // Entry 924
+    -0x1.ad19e2535aa8ffb40066d78aef71fabdp-1,
+    -0x1.dbfbbc70254bcp1
+  },
+  { // Entry 925
+    -0x1.ad19e2535aa8ffb40066d78aef71fabdp-1,
+    0x1.dbfbbc70254bcp1
+  },
+  { // Entry 926
+    -0x1.e5eaa286fbbc2b129238160df30ce704p-1,
+    -0x1.bb282b074edcap1
+  },
+  { // Entry 927
+    -0x1.e5eaa286fbbc2b129238160df30ce704p-1,
+    0x1.bb282b074edcap1
+  },
+  { // Entry 928
+    -0x1.fef2b2d21cf6b40ff3b530ce8dc0d8a7p-1,
+    -0x1.9a54999e786d8p1
+  },
+  { // Entry 929
+    -0x1.fef2b2d21cf6b40ff3b530ce8dc0d8a7p-1,
+    0x1.9a54999e786d8p1
+  },
+  { // Entry 930
+    -0x1.f68eebfcbb5eadd65c261cd803990ae1p-1,
+    -0x1.79810835a1fe6p1
+  },
+  { // Entry 931
+    -0x1.f68eebfcbb5eadd65c261cd803990ae1p-1,
+    0x1.79810835a1fe6p1
+  },
+  { // Entry 932
+    -0x1.cd4bca9cb5c775a99729f7ad95b7dce3p-1,
+    -0x1.58ad76cccb8f4p1
+  },
+  { // Entry 933
+    -0x1.cd4bca9cb5c775a99729f7ad95b7dce3p-1,
+    0x1.58ad76cccb8f4p1
+  },
+  { // Entry 934
+    -0x1.85dc3ea1bbcf2aa2e21ec586d5497e35p-1,
+    -0x1.37d9e563f5202p1
+  },
+  { // Entry 935
+    -0x1.85dc3ea1bbcf2aa2e21ec586d5497e35p-1,
+    0x1.37d9e563f5202p1
+  },
+  { // Entry 936
+    -0x1.24ec79917164e41addd4bacd4420f9fbp-1,
+    -0x1.170653fb1eb10p1
+  },
+  { // Entry 937
+    -0x1.24ec79917164e41addd4bacd4420f9fbp-1,
+    0x1.170653fb1eb10p1
+  },
+  { // Entry 938
+    -0x1.61a76077aee23b11f0c673f638003b0ap-2,
+    -0x1.ec6585249083cp0
+  },
+  { // Entry 939
+    -0x1.61a76077aee23b11f0c673f638003b0ap-2,
+    0x1.ec6585249083cp0
+  },
+  { // Entry 940
+    -0x1.894f70befbc104b706e85cf4c1c96a52p-4,
+    -0x1.aabe6252e3a58p0
+  },
+  { // Entry 941
+    -0x1.894f70befbc104b706e85cf4c1c96a52p-4,
+    0x1.aabe6252e3a58p0
+  },
+  { // Entry 942
+    0x1.46dc4f4ce8373c7c44f13b57363edd3bp-3,
+    -0x1.69173f8136c74p0
+  },
+  { // Entry 943
+    0x1.46dc4f4ce8373c7c44f13b57363edd3bp-3,
+    0x1.69173f8136c74p0
+  },
+  { // Entry 944
+    0x1.9e7f8652b47289e53fccd54955db4552p-2,
+    -0x1.27701caf89e90p0
+  },
+  { // Entry 945
+    0x1.9e7f8652b47289e53fccd54955db4552p-2,
+    0x1.27701caf89e90p0
+  },
+  { // Entry 946
+    0x1.3f3a0e28bedbfb066b67abd9c338409ep-1,
+    -0x1.cb91f3bbba157p-1
+  },
+  { // Entry 947
+    0x1.3f3a0e28bedbfb066b67abd9c338409ep-1,
+    0x1.cb91f3bbba157p-1
+  },
+  { // Entry 948
+    0x1.9a52e2e0fbca4b00c72daa3cdaca257cp-1,
+    -0x1.4843ae186058ep-1
+  },
+  { // Entry 949
+    0x1.9a52e2e0fbca4b00c72daa3cdaca257cp-1,
+    0x1.4843ae186058ep-1
+  },
+  { // Entry 950
+    0x1.da94d54dd4bff753d988c1755e2ffc04p-1,
+    -0x1.89ead0ea0d38ap-2
+  },
+  { // Entry 951
+    0x1.da94d54dd4bff753d988c1755e2ffc04p-1,
+    0x1.89ead0ea0d38ap-2
+  },
+  { // Entry 952
+    0x1.fbcbe693bd8e98423207e36587d942b7p-1,
+    -0x1.069c8b46b37f0p-3
+  },
+  { // Entry 953
+    0x1.fbcbe693bd8e98423207e36587d942b7p-1,
+    0x1.069c8b46b37f0p-3
+  },
+  { // Entry 954
+    0x1.fbcbe693bd8ef86c1565b3453036e55ep-1,
+    0x1.069c8b46b3734p-3
+  },
+  { // Entry 955
+    0x1.fbcbe693bd8ef86c1565b3453036e55ep-1,
+    -0x1.069c8b46b3734p-3
+  },
+  { // Entry 956
+    0x1.da94d54dd4c11187405ada7f04e5b171p-1,
+    0x1.89ead0ea0d32cp-2
+  },
+  { // Entry 957
+    0x1.da94d54dd4c11187405ada7f04e5b171p-1,
+    -0x1.89ead0ea0d32cp-2
+  },
+  { // Entry 958
+    0x1.9a52e2e0fbcc0cc83b843bae58c6cdf8p-1,
+    0x1.4843ae186055fp-1
+  },
+  { // Entry 959
+    0x1.9a52e2e0fbcc0cc83b843bae58c6cdf8p-1,
+    -0x1.4843ae186055fp-1
+  },
+  { // Entry 960
+    0x1.3f3a0e28bede46f65ca5b5c19ad99dd7p-1,
+    0x1.cb91f3bbba128p-1
+  },
+  { // Entry 961
+    0x1.3f3a0e28bede46f65ca5b5c19ad99dd7p-1,
+    -0x1.cb91f3bbba128p-1
+  },
+  { // Entry 962
+    0x1.9e7f8652b478066eec563f835097f148p-2,
+    0x1.27701caf89e78p0
+  },
+  { // Entry 963
+    0x1.9e7f8652b478066eec563f835097f148p-2,
+    -0x1.27701caf89e78p0
+  },
+  { // Entry 964
+    0x1.46dc4f4ce843151b9d14e561879e5fe3p-3,
+    0x1.69173f8136c5cp0
+  },
+  { // Entry 965
+    0x1.46dc4f4ce843151b9d14e561879e5fe3p-3,
+    -0x1.69173f8136c5cp0
+  },
+  { // Entry 966
+    -0x1.894f70befba9211b0dcaa4dca450670fp-4,
+    0x1.aabe6252e3a40p0
+  },
+  { // Entry 967
+    -0x1.894f70befba9211b0dcaa4dca450670fp-4,
+    -0x1.aabe6252e3a40p0
+  },
+  { // Entry 968
+    -0x1.61a76077aedc99952438421f820a2befp-2,
+    0x1.ec65852490824p0
+  },
+  { // Entry 969
+    -0x1.61a76077aedc99952438421f820a2befp-2,
+    -0x1.ec65852490824p0
+  },
+  { // Entry 970
+    -0x1.24ec799171626e36709cfcf7c7752332p-1,
+    0x1.170653fb1eb04p1
+  },
+  { // Entry 971
+    -0x1.24ec799171626e36709cfcf7c7752332p-1,
+    -0x1.170653fb1eb04p1
+  },
+  { // Entry 972
+    -0x1.85dc3ea1bbcd38cbfeb4370d5405eebap-1,
+    0x1.37d9e563f51f6p1
+  },
+  { // Entry 973
+    -0x1.85dc3ea1bbcd38cbfeb4370d5405eebap-1,
+    -0x1.37d9e563f51f6p1
+  },
+  { // Entry 974
+    -0x1.cd4bca9cb5c628709388a39fc84591d1p-1,
+    0x1.58ad76cccb8e8p1
+  },
+  { // Entry 975
+    -0x1.cd4bca9cb5c628709388a39fc84591d1p-1,
+    -0x1.58ad76cccb8e8p1
+  },
+  { // Entry 976
+    -0x1.f68eebfcbb5e1b070b564037f5571a39p-1,
+    0x1.79810835a1fdap1
+  },
+  { // Entry 977
+    -0x1.f68eebfcbb5e1b070b564037f5571a39p-1,
+    -0x1.79810835a1fdap1
+  },
+  { // Entry 978
+    -0x1.fef2b2d21cf6e544ab7795aed10d9fa7p-1,
+    0x1.9a54999e786ccp1
+  },
+  { // Entry 979
+    -0x1.fef2b2d21cf6e544ab7795aed10d9fa7p-1,
+    -0x1.9a54999e786ccp1
+  },
+  { // Entry 980
+    -0x1.e5eaa286fbbd1d135e216c49a9f7e5dap-1,
+    0x1.bb282b074edbep1
+  },
+  { // Entry 981
+    -0x1.e5eaa286fbbd1d135e216c49a9f7e5dap-1,
+    -0x1.bb282b074edbep1
+  },
+  { // Entry 982
+    -0x1.ad19e2535aaaa2ac87056b6d7776e97ap-1,
+    0x1.dbfbbc70254b0p1
+  },
+  { // Entry 983
+    -0x1.ad19e2535aaaa2ac87056b6d7776e97ap-1,
+    -0x1.dbfbbc70254b0p1
+  },
+  { // Entry 984
+    -0x1.5837d2817cf4af8e5e59b13b4aa9b5e3p-1,
+    0x1.fccf4dd8fbba2p1
+  },
+  { // Entry 985
+    -0x1.5837d2817cf4af8e5e59b13b4aa9b5e3p-1,
+    -0x1.fccf4dd8fbba2p1
+  },
+  { // Entry 986
+    -0x1.d9a3a336edbb7de64a2183cb27be4b5bp-2,
+    0x1.0ed16fa0e914ap2
+  },
+  { // Entry 987
+    -0x1.d9a3a336edbb7de64a2183cb27be4b5bp-2,
+    -0x1.0ed16fa0e914ap2
+  },
+  { // Entry 988
+    -0x1.c7b90e30246248b7a0c2c87a3dd25224p-3,
+    0x1.1f3b3855544c3p2
+  },
+  { // Entry 989
+    -0x1.c7b90e30246248b7a0c2c87a3dd25224p-3,
+    -0x1.1f3b3855544c3p2
+  },
+  { // Entry 990
+    0x1.069107ae9302caf2068b48842afdf051p-5,
+    0x1.2fa50109bf83cp2
+  },
+  { // Entry 991
+    0x1.069107ae9302caf2068b48842afdf051p-5,
+    -0x1.2fa50109bf83cp2
+  },
+  { // Entry 992
+    0x1.235b331d8f6ec74aa3de5aed15fa3f68p-2,
+    0x1.400ec9be2abb5p2
+  },
+  { // Entry 993
+    0x1.235b331d8f6ec74aa3de5aed15fa3f68p-2,
+    -0x1.400ec9be2abb5p2
+  },
+  { // Entry 994
+    0x1.096ac02ec429f225c99b89bb4c9e5d3ep-1,
+    0x1.5078927295f2ep2
+  },
+  { // Entry 995
+    0x1.096ac02ec429f225c99b89bb4c9e5d3ep-1,
+    -0x1.5078927295f2ep2
+  },
+  { // Entry 996
+    0x1.6fcb7c6b8b8f773e3b421dded6fc1f26p-1,
+    0x1.60e25b27012a7p2
+  },
+  { // Entry 997
+    0x1.6fcb7c6b8b8f773e3b421dded6fc1f26p-1,
+    -0x1.60e25b27012a7p2
+  },
+  { // Entry 998
+    0x1.be1d7c3534c280dab43dced670330b63p-1,
+    0x1.714c23db6c620p2
+  },
+  { // Entry 999
+    0x1.be1d7c3534c280dab43dced670330b63p-1,
+    -0x1.714c23db6c620p2
+  },
+  { // Entry 1000
+    0x1.ef4145b4aecf342709a3b19320d1b194p-1,
+    0x1.81b5ec8fd7999p2
+  },
+  { // Entry 1001
+    0x1.ef4145b4aecf342709a3b19320d1b194p-1,
+    -0x1.81b5ec8fd7999p2
+  },
+  { // Entry 1002
+    0x1.ff0fd2c96adfbae576981ee4b34769dep-1,
+    0x1.effffffffffffp-5
+  },
+  { // Entry 1003
+    0x1.ff0fd2c96adfbae576981ee4b34769dep-1,
+    -0x1.effffffffffffp-5
+  },
+  { // Entry 1004
+    0x1.ff0fd2c96adfbad5f904a71b2d210a2ap-1,
+    0x1.fp-5
+  },
+  { // Entry 1005
+    0x1.ff0fd2c96adfbad5f904a71b2d210a2ap-1,
+    -0x1.fp-5
+  },
+  { // Entry 1006
+    0x1.ff0fd2c96adfbac67b712f51a6fa2ab3p-1,
+    0x1.f000000000001p-5
+  },
+  { // Entry 1007
+    0x1.ff0fd2c96adfbac67b712f51a6fa2ab3p-1,
+    -0x1.f000000000001p-5
+  },
+  { // Entry 1008
+    0x1.fc210055467fe5c8f76e75fd7083818cp-1,
+    0x1.f7fffffffffffp-4
+  },
+  { // Entry 1009
+    0x1.fc210055467fe5c8f76e75fd7083818cp-1,
+    -0x1.f7fffffffffffp-4
+  },
+  { // Entry 1010
+    0x1.fc210055467fe58a20193399b3bc0dd2p-1,
+    0x1.f80p-4
+  },
+  { // Entry 1011
+    0x1.fc210055467fe58a20193399b3bc0dd2p-1,
+    -0x1.f80p-4
+  },
+  { // Entry 1012
+    0x1.fc210055467fe54b48c3f135f6f29df7p-1,
+    0x1.f800000000001p-4
+  },
+  { // Entry 1013
+    0x1.fc210055467fe54b48c3f135f6f29df7p-1,
+    -0x1.f800000000001p-4
+  },
+  { // Entry 1014
+    0x1.f94984b2552e19e7329413b8c2e8dc51p-1,
+    0x1.4bfffffffffffp-3
+  },
+  { // Entry 1015
+    0x1.f94984b2552e19e7329413b8c2e8dc51p-1,
+    -0x1.4bfffffffffffp-3
+  },
+  { // Entry 1016
+    0x1.f94984b2552e1941ec766c6a82ece4a3p-1,
+    0x1.4c0p-3
+  },
+  { // Entry 1017
+    0x1.f94984b2552e1941ec766c6a82ece4a3p-1,
+    -0x1.4c0p-3
+  },
+  { // Entry 1018
+    0x1.f94984b2552e189ca658c51c42e907cep-1,
+    0x1.4c00000000001p-3
+  },
+  { // Entry 1019
+    0x1.f94984b2552e189ca658c51c42e907cep-1,
+    -0x1.4c00000000001p-3
+  },
+  { // Entry 1020
+    0x1.e921dd42f09ba868603ea376f6e2d012p-1,
+    0x1.3333333333332p-2
+  },
+  { // Entry 1021
+    0x1.e921dd42f09ba868603ea376f6e2d012p-1,
+    -0x1.3333333333332p-2
+  },
+  { // Entry 1022
+    0x1.e921dd42f09ba60b268bec1fb0878a42p-1,
+    0x1.3333333333333p-2
+  },
+  { // Entry 1023
+    0x1.e921dd42f09ba60b268bec1fb0878a42p-1,
+    -0x1.3333333333333p-2
+  },
+  { // Entry 1024
+    0x1.e921dd42f09ba3adecd934c86a0db254p-1,
+    0x1.3333333333334p-2
+  },
+  { // Entry 1025
+    0x1.e921dd42f09ba3adecd934c86a0db254p-1,
+    -0x1.3333333333334p-2
+  },
+  { // Entry 1026
+    0x1.8feedb86bf0ef3158f8a1dcbef49d123p-1,
+    0x1.594317acc4ef8p-1
+  },
+  { // Entry 1027
+    0x1.8feedb86bf0ef3158f8a1dcbef49d123p-1,
+    -0x1.594317acc4ef8p-1
+  },
+  { // Entry 1028
+    0x1.8feedb86bf0ee91817a64b28b79e5119p-1,
+    0x1.594317acc4ef9p-1
+  },
+  { // Entry 1029
+    0x1.8feedb86bf0ee91817a64b28b79e5119p-1,
+    -0x1.594317acc4ef9p-1
+  },
+  { // Entry 1030
+    0x1.8feedb86bf0edf1a9fc278857f8ed559p-1,
+    0x1.594317acc4efap-1
+  },
+  { // Entry 1031
+    0x1.8feedb86bf0edf1a9fc278857f8ed559p-1,
+    -0x1.594317acc4efap-1
+  },
+  { // Entry 1032
+    0x1.6b898fa9efb5dd6f9e17e3442d59b241p-1,
+    0x1.8ffffffffffffp-1
+  },
+  { // Entry 1033
+    0x1.6b898fa9efb5dd6f9e17e3442d59b241p-1,
+    -0x1.8ffffffffffffp-1
+  },
+  { // Entry 1034
+    0x1.6b898fa9efb5d22b58f0d99e9634931ap-1,
+    0x1.9p-1
+  },
+  { // Entry 1035
+    0x1.6b898fa9efb5d22b58f0d99e9634931ap-1,
+    -0x1.9p-1
+  },
+  { // Entry 1036
+    0x1.6b898fa9efb5c6e713c9cff8feb4918fp-1,
+    0x1.9000000000001p-1
+  },
+  { // Entry 1037
+    0x1.6b898fa9efb5c6e713c9cff8feb4918fp-1,
+    -0x1.9000000000001p-1
+  },
+  { // Entry 1038
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074
+  },
+  { // Entry 1039
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074
+  },
+  { // Entry 1040
+    0x1.p0,
+    -0.0
+  },
+  { // Entry 1041
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074
+  },
+  { // Entry 1042
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074
+  },
+  { // Entry 1043
+    0x1.ff621e3796d7de4a8ab7d7cd8488f499p-1,
+    0x1.921fb54442d17p-5
+  },
+  { // Entry 1044
+    0x1.ff621e3796d7de4a8ab7d7cd8488f499p-1,
+    -0x1.921fb54442d17p-5
+  },
+  { // Entry 1045
+    0x1.ff621e3796d7de3dfb04df46987f6450p-1,
+    0x1.921fb54442d18p-5
+  },
+  { // Entry 1046
+    0x1.ff621e3796d7de3dfb04df46987f6450p-1,
+    -0x1.921fb54442d18p-5
+  },
+  { // Entry 1047
+    0x1.ff621e3796d7de316b51e6bfac75542fp-1,
+    0x1.921fb54442d19p-5
+  },
+  { // Entry 1048
+    0x1.ff621e3796d7de316b51e6bfac75542fp-1,
+    -0x1.921fb54442d19p-5
+  },
+  { // Entry 1049
+    0x1.fd88da3d12525a208898cf58ded0eeb3p-1,
+    0x1.921fb54442d17p-4
+  },
+  { // Entry 1050
+    0x1.fd88da3d12525a208898cf58ded0eeb3p-1,
+    -0x1.921fb54442d17p-4
+  },
+  { // Entry 1051
+    0x1.fd88da3d125259ee594b5705767ab649p-1,
+    0x1.921fb54442d18p-4
+  },
+  { // Entry 1052
+    0x1.fd88da3d125259ee594b5705767ab649p-1,
+    -0x1.921fb54442d18p-4
+  },
+  { // Entry 1053
+    0x1.fd88da3d125259bc29fddeb20e228056p-1,
+    0x1.921fb54442d19p-4
+  },
+  { // Entry 1054
+    0x1.fd88da3d125259bc29fddeb20e228056p-1,
+    -0x1.921fb54442d19p-4
+  },
+  { // Entry 1055
+    0x1.f6297cff75cb03ab1fced6337e35a245p-1,
+    0x1.921fb54442d17p-3
+  },
+  { // Entry 1056
+    0x1.f6297cff75cb03ab1fced6337e35a245p-1,
+    -0x1.921fb54442d17p-3
+  },
+  { // Entry 1057
+    0x1.f6297cff75cb02e35a0cf2e64de60626p-1,
+    0x1.921fb54442d18p-3
+  },
+  { // Entry 1058
+    0x1.f6297cff75cb02e35a0cf2e64de60626p-1,
+    -0x1.921fb54442d18p-3
+  },
+  { // Entry 1059
+    0x1.f6297cff75cb021b944b0f991d8e9161p-1,
+    0x1.921fb54442d19p-3
+  },
+  { // Entry 1060
+    0x1.f6297cff75cb021b944b0f991d8e9161p-1,
+    -0x1.921fb54442d19p-3
+  },
+  { // Entry 1061
+    0x1.d906bcf328d46672d9c1a865898e5966p-1,
+    0x1.921fb54442d17p-2
+  },
+  { // Entry 1062
+    0x1.d906bcf328d46672d9c1a865898e5966p-1,
+    -0x1.921fb54442d17p-2
+  },
+  { // Entry 1063
+    0x1.d906bcf328d463631d6cd2905d4b13f5p-1,
+    0x1.921fb54442d18p-2
+  },
+  { // Entry 1064
+    0x1.d906bcf328d463631d6cd2905d4b13f5p-1,
+    -0x1.921fb54442d18p-2
+  },
+  { // Entry 1065
+    0x1.d906bcf328d460536117fcbb30ea3e17p-1,
+    0x1.921fb54442d19p-2
+  },
+  { // Entry 1066
+    0x1.d906bcf328d460536117fcbb30ea3e17p-1,
+    -0x1.921fb54442d19p-2
+  },
+  { // Entry 1067
+    0x1.6a09e667f3bcd777b6461376ab523242p-1,
+    0x1.921fb54442d17p-1
+  },
+  { // Entry 1068
+    0x1.6a09e667f3bcd777b6461376ab523242p-1,
+    -0x1.921fb54442d17p-1
+  },
+  { // Entry 1069
+    0x1.6a09e667f3bccc276712d3d8c5502387p-1,
+    0x1.921fb54442d18p-1
+  },
+  { // Entry 1070
+    0x1.6a09e667f3bccc276712d3d8c5502387p-1,
+    -0x1.921fb54442d18p-1
+  },
+  { // Entry 1071
+    0x1.6a09e667f3bcc0d717df943adef39253p-1,
+    0x1.921fb54442d19p-1
+  },
+  { // Entry 1072
+    0x1.6a09e667f3bcc0d717df943adef39253p-1,
+    -0x1.921fb54442d19p-1
+  },
+  { // Entry 1073
+    0x1.469898cc51701b839a252049c0b8b50bp-52,
+    0x1.921fb54442d17p0
+  },
+  { // Entry 1074
+    0x1.469898cc51701b839a252049c0b8b50bp-52,
+    -0x1.921fb54442d17p0
+  },
+  { // Entry 1075
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 1076
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 1077
+    -0x1.72cece675d1fc8f8cbb5bf6c7dbcfba0p-53,
+    0x1.921fb54442d19p0
+  },
+  { // Entry 1078
+    -0x1.72cece675d1fc8f8cbb5bf6c7dbcfba0p-53,
+    -0x1.921fb54442d19p0
+  },
+  { // Entry 1079
+    -0x1.fffffffffffffffffffffffff97d5bffp-1,
+    0x1.921fb54442d17p1
+  },
+  { // Entry 1080
+    -0x1.fffffffffffffffffffffffff97d5bffp-1,
+    -0x1.921fb54442d17p1
+  },
+  { // Entry 1081
+    -0x1.ffffffffffffffffffffffffffb220c5p-1,
+    0x1.921fb54442d18p1
+  },
+  { // Entry 1082
+    -0x1.ffffffffffffffffffffffffffb220c5p-1,
+    -0x1.921fb54442d18p1
+  },
+  { // Entry 1083
+    -0x1.fffffffffffffffffffffffffde6e58cp-1,
+    0x1.921fb54442d19p1
+  },
+  { // Entry 1084
+    -0x1.fffffffffffffffffffffffffde6e58cp-1,
+    -0x1.921fb54442d19p1
+  },
+  { // Entry 1085
+    0x1.ffffffffffffffffffffffffe5f56ffep-1,
+    0x1.921fb54442d17p2
+  },
+  { // Entry 1086
+    0x1.ffffffffffffffffffffffffe5f56ffep-1,
+    -0x1.921fb54442d17p2
+  },
+  { // Entry 1087
+    0x1.fffffffffffffffffffffffffec88317p-1,
+    0x1.921fb54442d18p2
+  },
+  { // Entry 1088
+    0x1.fffffffffffffffffffffffffec88317p-1,
+    -0x1.921fb54442d18p2
+  },
+  { // Entry 1089
+    0x1.fffffffffffffffffffffffff79b9631p-1,
+    0x1.921fb54442d19p2
+  },
+  { // Entry 1090
+    0x1.fffffffffffffffffffffffff79b9631p-1,
+    -0x1.921fb54442d19p2
+  },
+  { // Entry 1091
+    0x1.ffffffffffffffffffffffff97d5bff8p-1,
+    0x1.921fb54442d17p3
+  },
+  { // Entry 1092
+    0x1.ffffffffffffffffffffffff97d5bff8p-1,
+    -0x1.921fb54442d17p3
+  },
+  { // Entry 1093
+    0x1.fffffffffffffffffffffffffb220c5ep-1,
+    0x1.921fb54442d18p3
+  },
+  { // Entry 1094
+    0x1.fffffffffffffffffffffffffb220c5ep-1,
+    -0x1.921fb54442d18p3
+  },
+  { // Entry 1095
+    0x1.ffffffffffffffffffffffffde6e58c4p-1,
+    0x1.921fb54442d19p3
+  },
+  { // Entry 1096
+    0x1.ffffffffffffffffffffffffde6e58c4p-1,
+    -0x1.921fb54442d19p3
+  },
+  { // Entry 1097
+    0x1.fffffffffffffffffffffffe5f56ffe1p-1,
+    0x1.921fb54442d17p4
+  },
+  { // Entry 1098
+    0x1.fffffffffffffffffffffffe5f56ffe1p-1,
+    -0x1.921fb54442d17p4
+  },
+  { // Entry 1099
+    0x1.ffffffffffffffffffffffffec88317ap-1,
+    0x1.921fb54442d18p4
+  },
+  { // Entry 1100
+    0x1.ffffffffffffffffffffffffec88317ap-1,
+    -0x1.921fb54442d18p4
+  },
+  { // Entry 1101
+    0x1.ffffffffffffffffffffffff79b96313p-1,
+    0x1.921fb54442d19p4
+  },
+  { // Entry 1102
+    0x1.ffffffffffffffffffffffff79b96313p-1,
+    -0x1.921fb54442d19p4
+  },
+  { // Entry 1103
+    0x1.fffffffffffffffffffffff97d5bff87p-1,
+    0x1.921fb54442d17p5
+  },
+  { // Entry 1104
+    0x1.fffffffffffffffffffffff97d5bff87p-1,
+    -0x1.921fb54442d17p5
+  },
+  { // Entry 1105
+    0x1.ffffffffffffffffffffffffb220c5e9p-1,
+    0x1.921fb54442d18p5
+  },
+  { // Entry 1106
+    0x1.ffffffffffffffffffffffffb220c5e9p-1,
+    -0x1.921fb54442d18p5
+  },
+  { // Entry 1107
+    0x1.fffffffffffffffffffffffde6e58c4cp-1,
+    0x1.921fb54442d19p5
+  },
+  { // Entry 1108
+    0x1.fffffffffffffffffffffffde6e58c4cp-1,
+    -0x1.921fb54442d19p5
+  },
+  { // Entry 1109
+    0x1.ffffffffffffffffffffffe5f56ffe1dp-1,
+    0x1.921fb54442d17p6
+  },
+  { // Entry 1110
+    0x1.ffffffffffffffffffffffe5f56ffe1dp-1,
+    -0x1.921fb54442d17p6
+  },
+  { // Entry 1111
+    0x1.fffffffffffffffffffffffec88317a7p-1,
+    0x1.921fb54442d18p6
+  },
+  { // Entry 1112
+    0x1.fffffffffffffffffffffffec88317a7p-1,
+    -0x1.921fb54442d18p6
+  },
+  { // Entry 1113
+    0x1.fffffffffffffffffffffff79b963131p-1,
+    0x1.921fb54442d19p6
+  },
+  { // Entry 1114
+    0x1.fffffffffffffffffffffff79b963131p-1,
+    -0x1.921fb54442d19p6
+  },
+  { // Entry 1115
+    0x1.ffffffffffffffffffffff97d5bff874p-1,
+    0x1.921fb54442d17p7
+  },
+  { // Entry 1116
+    0x1.ffffffffffffffffffffff97d5bff874p-1,
+    -0x1.921fb54442d17p7
+  },
+  { // Entry 1117
+    0x1.fffffffffffffffffffffffb220c5e9dp-1,
+    0x1.921fb54442d18p7
+  },
+  { // Entry 1118
+    0x1.fffffffffffffffffffffffb220c5e9dp-1,
+    -0x1.921fb54442d18p7
+  },
+  { // Entry 1119
+    0x1.ffffffffffffffffffffffde6e58c4c6p-1,
+    0x1.921fb54442d19p7
+  },
+  { // Entry 1120
+    0x1.ffffffffffffffffffffffde6e58c4c6p-1,
+    -0x1.921fb54442d19p7
+  },
+  { // Entry 1121
+    -0x1.6a09e667f3bc926b59e6d399bd1b906cp-1,
+    0x1.2d97c7f3321d1p1
+  },
+  { // Entry 1122
+    -0x1.6a09e667f3bc926b59e6d399bd1b906cp-1,
+    -0x1.2d97c7f3321d1p1
+  },
+  { // Entry 1123
+    -0x1.6a09e667f3bcbfac96b3d2115a3c3e21p-1,
+    0x1.2d97c7f3321d2p1
+  },
+  { // Entry 1124
+    -0x1.6a09e667f3bcbfac96b3d2115a3c3e21p-1,
+    -0x1.2d97c7f3321d2p1
+  },
+  { // Entry 1125
+    -0x1.6a09e667f3bcecedd380d088f1b4c43cp-1,
+    0x1.2d97c7f3321d3p1
+  },
+  { // Entry 1126
+    -0x1.6a09e667f3bcecedd380d088f1b4c43cp-1,
+    -0x1.2d97c7f3321d3p1
+  },
+  { // Entry 1127
+    -0x1.6a09e667f3bd05e3743ed417c44fba46p-1,
+    0x1.f6a7a2955385dp1
+  },
+  { // Entry 1128
+    -0x1.6a09e667f3bd05e3743ed417c44fba46p-1,
+    -0x1.f6a7a2955385dp1
+  },
+  { // Entry 1129
+    -0x1.6a09e667f3bcd8a23771d5a02ff5e843p-1,
+    0x1.f6a7a2955385ep1
+  },
+  { // Entry 1130
+    -0x1.6a09e667f3bcd8a23771d5a02ff5e843p-1,
+    -0x1.f6a7a2955385ep1
+  },
+  { // Entry 1131
+    -0x1.6a09e667f3bcab60faa4d72895f3eea5p-1,
+    0x1.f6a7a2955385fp1
+  },
+  { // Entry 1132
+    -0x1.6a09e667f3bcab60faa4d72895f3eea5p-1,
+    -0x1.f6a7a2955385fp1
+  },
+  { // Entry 1133
+    -0x1.34f272993d1414a2b39bd8374c1d1631p-50,
+    0x1.2d97c7f3321d1p2
+  },
+  { // Entry 1134
+    -0x1.34f272993d1414a2b39bd8374c1d1631p-50,
+    -0x1.2d97c7f3321d1p2
+  },
+  { // Entry 1135
+    -0x1.a79394c9e8a0a5159cdec1ba86377c92p-53,
+    0x1.2d97c7f3321d2p2
+  },
+  { // Entry 1136
+    -0x1.a79394c9e8a0a5159cdec1ba86377c92p-53,
+    -0x1.2d97c7f3321d2p2
+  },
+  { // Entry 1137
+    0x1.961b1acd85d7d6ba98c84f915bbcbc6cp-51,
+    0x1.2d97c7f3321d3p2
+  },
+  { // Entry 1138
+    0x1.961b1acd85d7d6ba98c84f915bbcbc6cp-51,
+    -0x1.2d97c7f3321d3p2
+  },
+  { // Entry 1139
+    0x1.6a09e667f3bc58af4cbad35aabb200f4p-1,
+    0x1.5fdbbe9bba774p2
+  },
+  { // Entry 1140
+    0x1.6a09e667f3bc58af4cbad35aabb200f4p-1,
+    -0x1.5fdbbe9bba774p2
+  },
+  { // Entry 1141
+    0x1.6a09e667f3bcb331c654d049eeba380fp-1,
+    0x1.5fdbbe9bba775p2
+  },
+  { // Entry 1142
+    0x1.6a09e667f3bcb331c654d049eeba380fp-1,
+    -0x1.5fdbbe9bba775p2
+  },
+  { // Entry 1143
+    0x1.6a09e667f3bd0db43feecd391b21d0c4p-1,
+    0x1.5fdbbe9bba776p2
+  },
+  { // Entry 1144
+    0x1.6a09e667f3bd0db43feecd391b21d0c4p-1,
+    -0x1.5fdbbe9bba776p2
+  },
+  { // Entry 1145
+    0x1.6a09e667f3bd3f9f816ad456ba1a54a9p-1,
+    0x1.c463abeccb2bap2
+  },
+  { // Entry 1146
+    0x1.6a09e667f3bd3f9f816ad456ba1a54a9p-1,
+    -0x1.c463abeccb2bap2
+  },
+  { // Entry 1147
+    0x1.6a09e667f3bce51d07d0d7679a2d8c53p-1,
+    0x1.c463abeccb2bbp2
+  },
+  { // Entry 1148
+    0x1.6a09e667f3bce51d07d0d7679a2d8c53p-1,
+    -0x1.c463abeccb2bbp2
+  },
+  { // Entry 1149
+    0x1.6a09e667f3bc8a9a8e36da7863a02597p-1,
+    0x1.c463abeccb2bcp2
+  },
+  { // Entry 1150
+    0x1.6a09e667f3bc8a9a8e36da7863a02597p-1,
+    -0x1.c463abeccb2bcp2
+  },
+  { // Entry 1151
+    0x1.583ebeff65cc226480ae685c2ad9afdap-50,
+    0x1.f6a7a2955385dp2
+  },
+  { // Entry 1152
+    0x1.583ebeff65cc226480ae685c2ad9afdap-50,
+    -0x1.f6a7a2955385dp2
+  },
+  { // Entry 1153
+    0x1.60fafbfd9730899202b9a170c4e6a849p-52,
+    0x1.f6a7a2955385ep2
+  },
+  { // Entry 1154
+    0x1.60fafbfd9730899202b9a170c4e6a849p-52,
+    -0x1.f6a7a2955385ep2
+  },
+  { // Entry 1155
+    -0x1.4f8282013467bb36fea32f479bd48f4ap-51,
+    0x1.f6a7a2955385fp2
+  },
+  { // Entry 1156
+    -0x1.4f8282013467bb36fea32f479bd48f4ap-51,
+    -0x1.f6a7a2955385fp2
+  },
+  { // Entry 1157
+    -0x1.6a09e667f3bb972f8927d7b46c737485p-1,
+    0x1.1475cc9eedeffp3
+  },
+  { // Entry 1158
+    -0x1.6a09e667f3bb972f8927d7b46c737485p-1,
+    -0x1.1475cc9eedeffp3
+  },
+  { // Entry 1159
+    -0x1.6a09e667f3bc4c347c5bd1933ca3261fp-1,
+    0x1.1475cc9eedfp3
+  },
+  { // Entry 1160
+    -0x1.6a09e667f3bc4c347c5bd1933ca3261fp-1,
+    -0x1.1475cc9eedfp3
+  },
+  { // Entry 1161
+    -0x1.6a09e667f3bd01396f8fcb71b2505e1fp-1,
+    0x1.1475cc9eedf01p3
+  },
+  { // Entry 1162
+    -0x1.6a09e667f3bd01396f8fcb71b2505e1fp-1,
+    -0x1.1475cc9eedf01p3
+  },
+  { // Entry 1163
+    -0x1.ffffffffffffffffffffffffa2c9eda8p-1,
+    0x1.2d97c7f3321d1p3
+  },
+  { // Entry 1164
+    -0x1.ffffffffffffffffffffffffa2c9eda8p-1,
+    -0x1.2d97c7f3321d1p3
+  },
+  { // Entry 1165
+    -0x1.fffffffffffffffffffffffffd4326f5p-1,
+    0x1.2d97c7f3321d2p3
+  },
+  { // Entry 1166
+    -0x1.fffffffffffffffffffffffffd4326f5p-1,
+    -0x1.2d97c7f3321d2p3
+  },
+  { // Entry 1167
+    -0x1.ffffffffffffffffffffffffd7bc6041p-1,
+    0x1.2d97c7f3321d3p3
+  },
+  { // Entry 1168
+    -0x1.ffffffffffffffffffffffffd7bc6041p-1,
+    -0x1.2d97c7f3321d3p3
+  },
+  { // Entry 1169
+    -0x1.6a09e667f3be011f44fdcffc167f7140p-1,
+    0x1.46b9c347764a2p3
+  },
+  { // Entry 1170
+    -0x1.6a09e667f3be011f44fdcffc167f7140p-1,
+    -0x1.46b9c347764a2p3
+  },
+  { // Entry 1171
+    -0x1.6a09e667f3bd4c1a51c9d61e20c523f7p-1,
+    0x1.46b9c347764a3p3
+  },
+  { // Entry 1172
+    -0x1.6a09e667f3bd4c1a51c9d61e20c523f7p-1,
+    -0x1.46b9c347764a3p3
+  },
+  { // Entry 1173
+    -0x1.6a09e667f3bc97155e95dc3fd0885d14p-1,
+    0x1.46b9c347764a4p3
+  },
+  { // Entry 1174
+    -0x1.6a09e667f3bc97155e95dc3fd0885d14p-1,
+    -0x1.46b9c347764a4p3
+  },
+  { // Entry 1175
+    -0x1.3dc585b2c742181326e07c40748873bbp-49,
+    0x1.5fdbbe9bba774p3
+  },
+  { // Entry 1176
+    -0x1.3dc585b2c742181326e07c40748873bbp-49,
+    -0x1.5fdbbe9bba774p3
+  },
+  { // Entry 1177
+    -0x1.ee2c2d963a10c0993703e20446463301p-52,
+    0x1.5fdbbe9bba775p3
+  },
+  { // Entry 1178
+    -0x1.ee2c2d963a10c0993703e20446463301p-52,
+    -0x1.5fdbbe9bba775p3
+  },
+  { // Entry 1179
+    0x1.8474f49a717bcfd9b23f077ee4d090cfp-50,
+    0x1.5fdbbe9bba776p3
+  },
+  { // Entry 1180
+    0x1.8474f49a717bcfd9b23f077ee4d090cfp-50,
+    -0x1.5fdbbe9bba776p3
+  },
+  { // Entry 1181
+    0x1.6a09e667f3bb8ab4b8c8d5ecf6b910d6p-1,
+    0x1.78fdb9effea45p3
+  },
+  { // Entry 1182
+    0x1.6a09e667f3bb8ab4b8c8d5ecf6b910d6p-1,
+    -0x1.78fdb9effea45p3
+  },
+  { // Entry 1183
+    0x1.6a09e667f3bc3fb9abfccfcbcd262aa0p-1,
+    0x1.78fdb9effea46p3
+  },
+  { // Entry 1184
+    0x1.6a09e667f3bc3fb9abfccfcbcd262aa0p-1,
+    -0x1.78fdb9effea46p3
+  },
+  { // Entry 1185
+    0x1.6a09e667f3bcf4be9f30c9aa4910cacfp-1,
+    0x1.78fdb9effea47p3
+  },
+  { // Entry 1186
+    0x1.6a09e667f3bcf4be9f30c9aa4910cacfp-1,
+    -0x1.78fdb9effea47p3
+  },
+  { // Entry 1187
+    0x1.6a09e667f3be0d9a155cd1c3767eb7b3p-1,
+    0x1.ab41b09886fe8p3
+  },
+  { // Entry 1188
+    0x1.6a09e667f3be0d9a155cd1c3767eb7b3p-1,
+    -0x1.ab41b09886fe8p3
+  },
+  { // Entry 1189
+    0x1.6a09e667f3bd58952228d7e58701d299p-1,
+    0x1.ab41b09886fe9p3
+  },
+  { // Entry 1190
+    0x1.6a09e667f3bd58952228d7e58701d299p-1,
+    -0x1.ab41b09886fe9p3
+  },
+  { // Entry 1191
+    0x1.6a09e667f3bca3902ef4de073d0273e6p-1,
+    0x1.ab41b09886feap3
+  },
+  { // Entry 1192
+    0x1.6a09e667f3bca3902ef4de073d0273e6p-1,
+    -0x1.ab41b09886feap3
+  },
+  { // Entry 1193
+    0x1.4f6babe5db9e1ef40d69c452e135591dp-49,
+    0x1.c463abeccb2bap3
+  },
+  { // Entry 1194
+    0x1.4f6babe5db9e1ef40d69c452e135591dp-49,
+    -0x1.c463abeccb2bap3
+  },
+  { // Entry 1195
+    0x1.3daeaf976e787bd035a7114be387b5c3p-51,
+    0x1.c463abeccb2bbp3
+  },
+  { // Entry 1196
+    0x1.3daeaf976e787bd035a7114be387b5c3p-51,
+    -0x1.c463abeccb2bbp3
+  },
+  { // Entry 1197
+    -0x1.6128a83448c3c217e52c775a0698d26ap-50,
+    0x1.c463abeccb2bcp3
+  },
+  { // Entry 1198
+    -0x1.6128a83448c3c217e52c775a0698d26ap-50,
+    -0x1.c463abeccb2bcp3
+  },
+  { // Entry 1199
+    -0x1.6a09e667f3bb7e39e869d42580908c7cp-1,
+    0x1.dd85a7410f58bp3
+  },
+  { // Entry 1200
+    -0x1.6a09e667f3bb7e39e869d42580908c7cp-1,
+    -0x1.dd85a7410f58bp3
+  },
+  { // Entry 1201
+    -0x1.6a09e667f3bc333edb9dce045d3b0e75p-1,
+    0x1.dd85a7410f58cp3
+  },
+  { // Entry 1202
+    -0x1.6a09e667f3bc333edb9dce045d3b0e75p-1,
+    -0x1.dd85a7410f58cp3
+  },
+  { // Entry 1203
+    -0x1.6a09e667f3bce843ced1c7e2df6316d4p-1,
+    0x1.dd85a7410f58dp3
+  },
+  { // Entry 1204
+    -0x1.6a09e667f3bce843ced1c7e2df6316d4p-1,
+    -0x1.dd85a7410f58dp3
+  },
+  { // Entry 1205
+    -0x1.ffffffffffffffffffffffff8c45d3d4p-1,
+    0x1.f6a7a2955385dp3
+  },
+  { // Entry 1206
+    -0x1.ffffffffffffffffffffffff8c45d3d4p-1,
+    -0x1.f6a7a2955385dp3
+  },
+  { // Entry 1207
+    -0x1.fffffffffffffffffffffffff8653353p-1,
+    0x1.f6a7a2955385ep3
+  },
+  { // Entry 1208
+    -0x1.fffffffffffffffffffffffff8653353p-1,
+    -0x1.f6a7a2955385ep3
+  },
+  { // Entry 1209
+    -0x1.ffffffffffffffffffffffffe48492d3p-1,
+    0x1.f6a7a2955385fp3
+  },
+  { // Entry 1210
+    -0x1.ffffffffffffffffffffffffe48492d3p-1,
+    -0x1.f6a7a2955385fp3
+  },
+  { // Entry 1211
+    -0x1.6a09e667f3bf841ecc23c74599076a81p-1,
+    0x1.07e4cef4cbd96p4
+  },
+  { // Entry 1212
+    -0x1.6a09e667f3bf841ecc23c74599076a81p-1,
+    -0x1.07e4cef4cbd96p4
+  },
+  { // Entry 1213
+    -0x1.6a09e667f3be1a14e5bbd38ad60fdd7bp-1,
+    0x1.07e4cef4cbd97p4
+  },
+  { // Entry 1214
+    -0x1.6a09e667f3be1a14e5bbd38ad60fdd7bp-1,
+    -0x1.07e4cef4cbd97p4
+  },
+  { // Entry 1215
+    -0x1.6a09e667f3bcb00aff53dfcea90e6a0cp-1,
+    0x1.07e4cef4cbd98p4
+  },
+  { // Entry 1216
+    -0x1.6a09e667f3bcb00aff53dfcea90e6a0cp-1,
+    -0x1.07e4cef4cbd98p4
+  },
+  { // Entry 1217
+    -0x1.b088e90c77fd12ea79f98631e6f0b74bp-48,
+    0x1.1475cc9eedeffp4
+  },
+  { // Entry 1218
+    -0x1.b088e90c77fd12ea79f98631e6f0b74bp-48,
+    -0x1.1475cc9eedeffp4
+  },
+  { // Entry 1219
+    -0x1.6111d218effa25d4f3f30c654d7c36a1p-49,
+    0x1.1475cc9eedfp4
+  },
+  { // Entry 1220
+    -0x1.6111d218effa25d4f3f30c654d7c36a1p-49,
+    -0x1.1475cc9eedfp4
+  },
+  { // Entry 1221
+    0x1.3ddc5bce200bb4561819e73527f5a6d7p-50,
+    0x1.1475cc9eedf01p4
+  },
+  { // Entry 1222
+    0x1.3ddc5bce200bb4561819e73527f5a6d7p-50,
+    -0x1.1475cc9eedf01p4
+  },
+  { // Entry 1223
+    0x1.6a09e667f3babcba24d6d87ecc8f83b4p-1,
+    0x1.2106ca4910068p4
+  },
+  { // Entry 1224
+    0x1.6a09e667f3babcba24d6d87ecc8f83b4p-1,
+    -0x1.2106ca4910068p4
+  },
+  { // Entry 1225
+    0x1.6a09e667f3bc26c40b3ecc3cece1d1a0p-1,
+    0x1.2106ca4910069p4
+  },
+  { // Entry 1226
+    0x1.6a09e667f3bc26c40b3ecc3cece1d1a0p-1,
+    -0x1.2106ca4910069p4
+  },
+  { // Entry 1227
+    0x1.6a09e667f3bd90cdf1a6bff9a32a3923p-1,
+    0x1.2106ca491006ap4
+  },
+  { // Entry 1228
+    0x1.6a09e667f3bd90cdf1a6bff9a32a3923p-1,
+    -0x1.2106ca491006ap4
+  },
+  { // Entry 1229
+    0x1.fffffffffffffffffffffffe8b27b6a2p-1,
+    0x1.2d97c7f3321d1p4
+  },
+  { // Entry 1230
+    0x1.fffffffffffffffffffffffe8b27b6a2p-1,
+    -0x1.2d97c7f3321d1p4
+  },
+  { // Entry 1231
+    0x1.fffffffffffffffffffffffff50c9bd4p-1,
+    0x1.2d97c7f3321d2p4
+  },
+  { // Entry 1232
+    0x1.fffffffffffffffffffffffff50c9bd4p-1,
+    -0x1.2d97c7f3321d2p4
+  },
+  { // Entry 1233
+    0x1.ffffffffffffffffffffffff5ef18107p-1,
+    0x1.2d97c7f3321d3p4
+  },
+  { // Entry 1234
+    0x1.ffffffffffffffffffffffff5ef18107p-1,
+    -0x1.2d97c7f3321d3p4
+  },
+  { // Entry 1235
+    0x1.6a09e667f3bf90999c82c90cebaf9f3fp-1,
+    0x1.3a28c59d54339p4
+  },
+  { // Entry 1236
+    0x1.6a09e667f3bf90999c82c90cebaf9f3fp-1,
+    -0x1.3a28c59d54339p4
+  },
+  { // Entry 1237
+    0x1.6a09e667f3be268fb61ad5523532e298p-1,
+    0x1.3a28c59d5433ap4
+  },
+  { // Entry 1238
+    0x1.6a09e667f3be268fb61ad5523532e298p-1,
+    -0x1.3a28c59d5433ap4
+  },
+  { // Entry 1239
+    0x1.6a09e667f3bcbc85cfb2e19614ac3f88p-1,
+    0x1.3a28c59d5433bp4
+  },
+  { // Entry 1240
+    0x1.6a09e667f3bcbc85cfb2e19614ac3f88p-1,
+    -0x1.3a28c59d5433bp4
+  },
+  { // Entry 1241
+    0x1.b95bfc26022b165aed3e2a3b12382479p-48,
+    0x1.46b9c347764a2p4
+  },
+  { // Entry 1242
+    0x1.b95bfc26022b165aed3e2a3b12382479p-48,
+    -0x1.46b9c347764a2p4
+  },
+  { // Entry 1243
+    0x1.72b7f84c04562cb5da7c5477b957adebp-49,
+    0x1.46b9c347764a3p4
+  },
+  { // Entry 1244
+    0x1.72b7f84c04562cb5da7c5477b957adebp-49,
+    -0x1.46b9c347764a3p4
+  },
+  { // Entry 1245
+    -0x1.1a900f67f753a6944b07571048f1cad2p-50,
+    0x1.46b9c347764a4p4
+  },
+  { // Entry 1246
+    -0x1.1a900f67f753a6944b07571048f1cad2p-50,
+    -0x1.46b9c347764a4p4
+  },
+  { // Entry 1247
+    -0x1.6a09e667f3bab03f5477d6b74f4d55d5p-1,
+    0x1.534ac0f19860bp4
+  },
+  { // Entry 1248
+    -0x1.6a09e667f3bab03f5477d6b74f4d55d5p-1,
+    -0x1.534ac0f19860bp4
+  },
+  { // Entry 1249
+    -0x1.6a09e667f3bc1a493adfca757c1a741fp-1,
+    0x1.534ac0f19860cp4
+  },
+  { // Entry 1250
+    -0x1.6a09e667f3bc1a493adfca757c1a741fp-1,
+    -0x1.534ac0f19860cp4
+  },
+  { // Entry 1251
+    -0x1.6a09e667f3bd84532147be323eddac01p-1,
+    0x1.534ac0f19860dp4
+  },
+  { // Entry 1252
+    -0x1.6a09e667f3bd84532147be323eddac01p-1,
+    -0x1.534ac0f19860dp4
+  },
+  { // Entry 1253
+    -0x1.fffffffffffffffffffffffe758d3a7cp-1,
+    0x1.5fdbbe9bba774p4
+  },
+  { // Entry 1254
+    -0x1.fffffffffffffffffffffffe758d3a7cp-1,
+    -0x1.5fdbbe9bba774p4
+  },
+  { // Entry 1255
+    -0x1.fffffffffffffffffffffffff11845e1p-1,
+    0x1.5fdbbe9bba775p4
+  },
+  { // Entry 1256
+    -0x1.fffffffffffffffffffffffff11845e1p-1,
+    -0x1.5fdbbe9bba775p4
+  },
+  { // Entry 1257
+    -0x1.ffffffffffffffffffffffff6ca35147p-1,
+    0x1.5fdbbe9bba776p4
+  },
+  { // Entry 1258
+    -0x1.ffffffffffffffffffffffff6ca35147p-1,
+    -0x1.5fdbbe9bba776p4
+  },
+  { // Entry 1259
+    -0x1.6a09e667f3bf9d146ce1cad43de9b352p-1,
+    0x1.6c6cbc45dc8dcp4
+  },
+  { // Entry 1260
+    -0x1.6a09e667f3bf9d146ce1cad43de9b352p-1,
+    -0x1.6c6cbc45dc8dcp4
+  },
+  { // Entry 1261
+    -0x1.6a09e667f3be330a8679d71993e7c709p-1,
+    0x1.6c6cbc45dc8ddp4
+  },
+  { // Entry 1262
+    -0x1.6a09e667f3be330a8679d71993e7c709p-1,
+    -0x1.6c6cbc45dc8ddp4
+  },
+  { // Entry 1263
+    -0x1.6a09e667f3bcc900a011e35d7fdbf459p-1,
+    0x1.6c6cbc45dc8dep4
+  },
+  { // Entry 1264
+    -0x1.6a09e667f3bcc900a011e35d7fdbf459p-1,
+    -0x1.6c6cbc45dc8dep4
+  },
+  { // Entry 1265
+    -0x1.c22f0f3f8c5919cb6082ce443cf95022p-48,
+    0x1.78fdb9effea45p4
+  },
+  { // Entry 1266
+    -0x1.c22f0f3f8c5919cb6082ce443cf95022p-48,
+    -0x1.78fdb9effea45p4
+  },
+  { // Entry 1267
+    -0x1.845e1e7f18b23396c1059c8a24c2609cp-49,
+    0x1.78fdb9effea46p4
+  },
+  { // Entry 1268
+    -0x1.845e1e7f18b23396c1059c8a24c2609cp-49,
+    -0x1.78fdb9effea46p4
+  },
+  { // Entry 1269
+    0x1.ee8786039d3731a4fbe98dd6d32ff62ap-51,
+    0x1.78fdb9effea47p4
+  },
+  { // Entry 1270
+    0x1.ee8786039d3731a4fbe98dd6d32ff62ap-51,
+    -0x1.78fdb9effea47p4
+  },
+  { // Entry 1271
+    0x1.6a09e667f3baa3c48418d4efd19d074ap-1,
+    0x1.858eb79a20baep4
+  },
+  { // Entry 1272
+    0x1.6a09e667f3baa3c48418d4efd19d074ap-1,
+    -0x1.858eb79a20baep4
+  },
+  { // Entry 1273
+    0x1.6a09e667f3bc0dce6a80c8ae0ae4f5f3p-1,
+    0x1.858eb79a20bafp4
+  },
+  { // Entry 1274
+    0x1.6a09e667f3bc0dce6a80c8ae0ae4f5f3p-1,
+    -0x1.858eb79a20bafp4
+  },
+  { // Entry 1275
+    0x1.6a09e667f3bd77d850e8bc6ada22fe34p-1,
+    0x1.858eb79a20bb0p4
+  },
+  { // Entry 1276
+    0x1.6a09e667f3bd77d850e8bc6ada22fe34p-1,
+    -0x1.858eb79a20bb0p4
+  },
+  { // Entry 1277
+    -0x1.2ccaf641d4261ea3ccd8d2a102dc3066p-3,
+    0x1.fffffffffffffp62
+  },
+  { // Entry 1278
+    -0x1.2ccaf641d4261ea3ccd8d2a102dc3066p-3,
+    -0x1.fffffffffffffp62
+  },
+  { // Entry 1279
+    0x1.82aa375b3c33e70663731bab4beb6ed3p-7,
+    0x1.0p63
+  },
+  { // Entry 1280
+    0x1.82aa375b3c33e70663731bab4beb6ed3p-7,
+    -0x1.0p63
+  },
+  { // Entry 1281
+    0x1.4c0622a6e35ddefd5f2b7700716a581fp-2,
+    0x1.0000000000001p63
+  },
+  { // Entry 1282
+    0x1.4c0622a6e35ddefd5f2b7700716a581fp-2,
+    -0x1.0000000000001p63
+  },
+  { // Entry 1283
+    0x1.4ab650b8c60734385375e22603fcdb10p-1,
+    0x1.fffffffffffffp26
+  },
+  { // Entry 1284
+    0x1.4ab650b8c60734385375e22603fcdb10p-1,
+    -0x1.fffffffffffffp26
+  },
+  { // Entry 1285
+    0x1.4ab6511a7d39ad3cc88ded1e775ca147p-1,
+    0x1.0p27
+  },
+  { // Entry 1286
+    0x1.4ab6511a7d39ad3cc88ded1e775ca147p-1,
+    -0x1.0p27
+  },
+  { // Entry 1287
+    0x1.4ab651ddeb9e61438382f02167ade4afp-1,
+    0x1.0000000000001p27
+  },
+  { // Entry 1288
+    0x1.4ab651ddeb9e61438382f02167ade4afp-1,
+    -0x1.0000000000001p27
+  },
+  { // Entry 1289
+    0x1.40ad67e777b1df0195189f50a8c26345p-1,
+    0x1.fffffffffffffp23
+  },
+  { // Entry 1290
+    0x1.40ad67e777b1df0195189f50a8c26345p-1,
+    -0x1.fffffffffffffp23
+  },
+  { // Entry 1291
+    0x1.40ad67f3f0c9a143963c9c96dbce3f8ap-1,
+    0x1.0p24
+  },
+  { // Entry 1292
+    0x1.40ad67f3f0c9a143963c9c96dbce3f8ap-1,
+    -0x1.0p24
+  },
+  { // Entry 1293
+    0x1.40ad680ce2f924d716769d1064bc8defp-1,
+    0x1.0000000000001p24
+  },
+  { // Entry 1294
+    0x1.40ad680ce2f924d716769d1064bc8defp-1,
+    -0x1.0000000000001p24
+  },
+  { // Entry 1295
+    -0x1.4eaa606db24c3cb5e15d7b19d5ee73a1p-1,
+    0x1.fffffffffffffp1
+  },
+  { // Entry 1296
+    -0x1.4eaa606db24c3cb5e15d7b19d5ee73a1p-1,
+    -0x1.fffffffffffffp1
+  },
+  { // Entry 1297
+    -0x1.4eaa606db24c0c466da1c2dc7baa2b32p-1,
+    0x1.0p2
+  },
+  { // Entry 1298
+    -0x1.4eaa606db24c0c466da1c2dc7baa2b32p-1,
+    -0x1.0p2
+  },
+  { // Entry 1299
+    -0x1.4eaa606db24bab67862a5261b7719dcfp-1,
+    0x1.0000000000001p2
+  },
+  { // Entry 1300
+    -0x1.4eaa606db24bab67862a5261b7719dcfp-1,
+    -0x1.0000000000001p2
+  },
+  { // Entry 1301
+    -0x1.aa2265753720101145230952e61c6f2cp-2,
+    0x1.fffffffffffffp0
+  },
+  { // Entry 1302
+    -0x1.aa2265753720101145230952e61c6f2cp-2,
+    -0x1.fffffffffffffp0
+  },
+  { // Entry 1303
+    -0x1.aa22657537204a4332f8acbb72b0d768p-2,
+    0x1.0p1
+  },
+  { // Entry 1304
+    -0x1.aa22657537204a4332f8acbb72b0d768p-2,
+    -0x1.0p1
+  },
+  { // Entry 1305
+    -0x1.aa2265753720bea70ea3f38c86db40afp-2,
+    0x1.0000000000001p1
+  },
+  { // Entry 1306
+    -0x1.aa2265753720bea70ea3f38c86db40afp-2,
+    -0x1.0000000000001p1
+  },
+  { // Entry 1307
+    0x1.14a280fb5068c69a2ed45fb547c2f271p-1,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 1308
+    0x1.14a280fb5068c69a2ed45fb547c2f271p-1,
+    -0x1.fffffffffffffp-1
+  },
+  { // Entry 1309
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    0x1.0p0
+  },
+  { // Entry 1310
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    -0x1.0p0
+  },
+  { // Entry 1311
+    0x1.14a280fb50689e362ffdd221e2551035p-1,
+    0x1.0000000000001p0
+  },
+  { // Entry 1312
+    0x1.14a280fb50689e362ffdd221e2551035p-1,
+    -0x1.0000000000001p0
+  },
+  { // Entry 1313
+    0x1.c1528065b7d4fdb158c9c4a6b3e4b740p-1,
+    0x1.fffffffffffffp-2
+  },
+  { // Entry 1314
+    0x1.c1528065b7d4fdb158c9c4a6b3e4b740p-1,
+    -0x1.fffffffffffffp-2
+  },
+  { // Entry 1315
+    0x1.c1528065b7d4f9db7bbb3b45f5f5b30ap-1,
+    0x1.0p-1
+  },
+  { // Entry 1316
+    0x1.c1528065b7d4f9db7bbb3b45f5f5b30ap-1,
+    -0x1.0p-1
+  },
+  { // Entry 1317
+    0x1.c1528065b7d4f22fc19e288479c36b27p-1,
+    0x1.0000000000001p-1
+  },
+  { // Entry 1318
+    0x1.c1528065b7d4f22fc19e288479c36b27p-1,
+    -0x1.0000000000001p-1
+  },
+  { // Entry 1319
+    0x1.f01549f7deea184c5f1d210b6adbe56cp-1,
+    0x1.fffffffffffffp-3
+  },
+  { // Entry 1320
+    0x1.f01549f7deea184c5f1d210b6adbe56cp-1,
+    -0x1.fffffffffffffp-3
+  },
+  { // Entry 1321
+    0x1.f01549f7deea174f07a67972bf29f148p-1,
+    0x1.0p-2
+  },
+  { // Entry 1322
+    0x1.f01549f7deea174f07a67972bf29f148p-1,
+    -0x1.0p-2
+  },
+  { // Entry 1323
+    0x1.f01549f7deea155458b92a4167aec7ffp-1,
+    0x1.0000000000001p-2
+  },
+  { // Entry 1324
+    0x1.f01549f7deea155458b92a4167aec7ffp-1,
+    -0x1.0000000000001p-2
+  },
+  { // Entry 1325
+    0x1.fc015527d5bd371a12320249ca4dafd7p-1,
+    0x1.fffffffffffffp-4
+  },
+  { // Entry 1326
+    0x1.fc015527d5bd371a12320249ca4dafd7p-1,
+    -0x1.fffffffffffffp-4
+  },
+  { // Entry 1327
+    0x1.fc015527d5bd36da3cd4253bede319cap-1,
+    0x1.0p-3
+  },
+  { // Entry 1328
+    0x1.fc015527d5bd36da3cd4253bede319cap-1,
+    -0x1.0p-3
+  },
+  { // Entry 1329
+    0x1.fc015527d5bd365a92186b203507f9adp-1,
+    0x1.0000000000001p-3
+  },
+  { // Entry 1330
+    0x1.fc015527d5bd365a92186b203507f9adp-1,
+    -0x1.0000000000001p-3
+  },
+  { // Entry 1331
+    0x1.ff0015549f4d34da0b745dc7433145efp-1,
+    0x1.fffffffffffffp-5
+  },
+  { // Entry 1332
+    0x1.ff0015549f4d34da0b745dc7433145efp-1,
+    -0x1.fffffffffffffp-5
+  },
+  { // Entry 1333
+    0x1.ff0015549f4d34ca0e1ee6509bc42b71p-1,
+    0x1.0p-4
+  },
+  { // Entry 1334
+    0x1.ff0015549f4d34ca0e1ee6509bc42b71p-1,
+    -0x1.0p-4
+  },
+  { // Entry 1335
+    0x1.ff0015549f4d34aa1373f7634ce87737p-1,
+    0x1.0000000000001p-4
+  },
+  { // Entry 1336
+    0x1.ff0015549f4d34aa1373f7634ce87737p-1,
+    -0x1.0000000000001p-4
+  },
+  { // Entry 1337
+    0x1.ffc00155527d2b16aeb09fb70636a10ap-1,
+    0x1.fffffffffffffp-6
+  },
+  { // Entry 1338
+    0x1.ffc00155527d2b16aeb09fb70636a10ap-1,
+    -0x1.fffffffffffffp-6
+  },
+  { // Entry 1339
+    0x1.ffc00155527d2b12aedb49d92928df72p-1,
+    0x1.0p-5
+  },
+  { // Entry 1340
+    0x1.ffc00155527d2b12aedb49d92928df72p-1,
+    -0x1.0p-5
+  },
+  { // Entry 1341
+    0x1.ffc00155527d2b0aaf309e1d6f0cfc4ep-1,
+    0x1.0000000000001p-5
+  },
+  { // Entry 1342
+    0x1.ffc00155527d2b0aaf309e1d6f0cfc4ep-1,
+    -0x1.0000000000001p-5
+  },
+  { // Entry 1343
+    0x1.fff000155549f4a38a2563ef344c3ff4p-1,
+    0x1.fffffffffffffp-7
+  },
+  { // Entry 1344
+    0x1.fff000155549f4a38a2563ef344c3ff4p-1,
+    -0x1.fffffffffffffp-7
+  },
+  { // Entry 1345
+    0x1.fff000155549f4a28a280e97bcd59c8ap-1,
+    0x1.0p-6
+  },
+  { // Entry 1346
+    0x1.fff000155549f4a28a280e97bcd59c8ap-1,
+    -0x1.0p-6
+  },
+  { // Entry 1347
+    0x1.fff000155549f4a08a2d63e8cde83db5p-1,
+    0x1.0000000000001p-6
+  },
+  { // Entry 1348
+    0x1.fff000155549f4a08a2d63e8cde83db5p-1,
+    -0x1.0000000000001p-6
+  },
+  { // Entry 1349
+    0x1.fffffff00000001555565549f49c9f4dp-1,
+    0x1.fffffffffffffp-15
+  },
+  { // Entry 1350
+    0x1.fffffff00000001555565549f49c9f4dp-1,
+    -0x1.fffffffffffffp-15
+  },
+  { // Entry 1351
+    0x1.fffffff00000001555555549f49f49f7p-1,
+    0x1.0p-14
+  },
+  { // Entry 1352
+    0x1.fffffff00000001555555549f49f49f7p-1,
+    -0x1.0p-14
+  },
+  { // Entry 1353
+    0x1.fffffff00000001555535549f4a49f4dp-1,
+    0x1.0000000000001p-14
+  },
+  { // Entry 1354
+    0x1.fffffff00000001555535549f4a49f4dp-1,
+    -0x1.0000000000001p-14
+  },
+  { // Entry 1355
+    0x1.fffffffffffffc000000000000415555p-1,
+    0x1.fffffffffffffp-28
+  },
+  { // Entry 1356
+    0x1.fffffffffffffc000000000000415555p-1,
+    -0x1.fffffffffffffp-28
+  },
+  { // Entry 1357
+    0x1.fffffffffffffc000000000000015555p-1,
+    0x1.0p-27
+  },
+  { // Entry 1358
+    0x1.fffffffffffffc000000000000015555p-1,
+    -0x1.0p-27
+  },
+  { // Entry 1359
+    0x1.fffffffffffffbffffffffffff815555p-1,
+    0x1.0000000000001p-27
+  },
+  { // Entry 1360
+    0x1.fffffffffffffbffffffffffff815555p-1,
+    -0x1.0000000000001p-27
+  },
+  { // Entry 1361
+    0x1.fffffffffffffff00000000000010015p-1,
+    0x1.fffffffffffffp-31
+  },
+  { // Entry 1362
+    0x1.fffffffffffffff00000000000010015p-1,
+    -0x1.fffffffffffffp-31
+  },
+  { // Entry 1363
+    0x1.fffffffffffffff00000000000000015p-1,
+    0x1.0p-30
+  },
+  { // Entry 1364
+    0x1.fffffffffffffff00000000000000015p-1,
+    -0x1.0p-30
+  },
+  { // Entry 1365
+    0x1.ffffffffffffffeffffffffffffe0015p-1,
+    0x1.0000000000001p-30
+  },
+  { // Entry 1366
+    0x1.ffffffffffffffeffffffffffffe0015p-1,
+    -0x1.0000000000001p-30
+  },
+  { // Entry 1367
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1368
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1369
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1370
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1371
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1372
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1373
+    0x1.7ffdfb4c5308f777cf774c733b256695p-2,
+    0x1.ffffffffffffep1023
+  },
+  { // Entry 1374
+    0x1.7ffdfb4c5308f777cf774c733b256695p-2,
+    -0x1.ffffffffffffep1023
+  },
+  { // Entry 1375
+    -0x1.ffffffffffffffffffffffffffb220c5p-1,
+    0x1.921fb54442d18p1
+  },
+  { // Entry 1376
+    -0x1.ffffffffffffffffffffffffffb220c5p-1,
+    -0x1.921fb54442d18p1
+  },
+  { // Entry 1377
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 1378
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 1379
+    0x1.14a280fb50689e362ffdd221e2551035p-1,
+    0x1.0000000000001p0
+  },
+  { // Entry 1380
+    0x1.14a280fb50689e362ffdd221e2551035p-1,
+    -0x1.0000000000001p0
+  },
+  { // Entry 1381
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    0x1.0p0
+  },
+  { // Entry 1382
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    -0x1.0p0
+  },
+  { // Entry 1383
+    0x1.14a280fb5068c69a2ed45fb547c2f271p-1,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 1384
+    0x1.14a280fb5068c69a2ed45fb547c2f271p-1,
+    -0x1.fffffffffffffp-1
+  },
+  { // Entry 1385
+    0x1.6a09e667f3bccc276712d3d8c5502387p-1,
+    0x1.921fb54442d18p-1
+  },
+  { // Entry 1386
+    0x1.6a09e667f3bccc276712d3d8c5502387p-1,
+    -0x1.921fb54442d18p-1
+  },
+  { // Entry 1387
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 1388
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 1389
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1022
+  },
+  { // Entry 1390
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1022
+  },
+  { // Entry 1391
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 1392
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 1393
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.ffffffffffffcp-1023
+  },
+  { // Entry 1394
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffcp-1023
+  },
+  { // Entry 1395
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1073
+  },
+  { // Entry 1396
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1073
+  },
+  { // Entry 1397
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074
+  },
+  { // Entry 1398
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074
+  },
+  { // Entry 1399
+    0x1.p0,
+    0.0
+  },
+  { // Entry 1400
+    0x1.p0,
+    -0.0
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_cos, cos_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_cos_intel_data)/sizeof(cos_intel_data_t); i++) {
+    EXPECT_DOUBLE_EQ(g_cos_intel_data[i].expected, cos(g_cos_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_cosf_test.cpp b/tests/math_cosf_test.cpp
new file mode 100644
index 0000000..ea95ff3
--- /dev/null
+++ b/tests/math_cosf_test.cpp
@@ -0,0 +1,4355 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  float expected;
+  float call_data;
+} cosf_intel_data_t;
+
+static cosf_intel_data_t g_cosf_intel_data[] = {
+  { // Entry 0
+    0x1.bc7b66ffb7689d646dd1af83e9661d2dp-1,
+    -0x1.09ebacp-1
+  },
+  { // Entry 1
+    0x1.bc7b66ffb7689d646dd1af83e9661d2dp-1,
+    0x1.09ebacp-1
+  },
+  { // Entry 2
+    0x1.dee8d0fffcd997ce5cfbab0a5a336c14p-5,
+    -0x1.156564p4
+  },
+  { // Entry 3
+    0x1.dee8d0fffcd997ce5cfbab0a5a336c14p-5,
+    0x1.156564p4
+  },
+  { // Entry 4
+    -0x1.c11bb2f056552ca4cdb6c5a0cf71509dp-8,
+    -0x1.406a40p6
+  },
+  { // Entry 5
+    -0x1.c11bb2f056552ca4cdb6c5a0cf71509dp-8,
+    0x1.406a40p6
+  },
+  { // Entry 6
+    0x1.ff836cff97077bf489aadc5f349a9fb9p-1,
+    -0x1.653078p-5
+  },
+  { // Entry 7
+    0x1.ff836cff97077bf489aadc5f349a9fb9p-1,
+    0x1.653078p-5
+  },
+  { // Entry 8
+    0x1.b29cd4f9da2964e8c6bb5693387d3f3bp-5,
+    -0x1.6c0008p5
+  },
+  { // Entry 9
+    0x1.b29cd4f9da2964e8c6bb5693387d3f3bp-5,
+    0x1.6c0008p5
+  },
+  { // Entry 10
+    0x1.df40d3f650f6c94390a3ca5d8d9b48c1p-1,
+    -0x1.703824p-2
+  },
+  { // Entry 11
+    0x1.df40d3f650f6c94390a3ca5d8d9b48c1p-1,
+    0x1.703824p-2
+  },
+  { // Entry 12
+    0x1.f76316f541e10ef15d57c5a23775329cp-1,
+    -0x1.782e2ep-3
+  },
+  { // Entry 13
+    0x1.f76316f541e10ef15d57c5a23775329cp-1,
+    0x1.782e2ep-3
+  },
+  { // Entry 14
+    0x1.cfab0ec2fc95382986fa511648bd4e6fp-24,
+    -0x1.8e3266p9
+  },
+  { // Entry 15
+    0x1.cfab0ec2fc95382986fa511648bd4e6fp-24,
+    0x1.8e3266p9
+  },
+  { // Entry 16
+    0x1.92e66b5920a85d6083e9cc85568ceaa3p-21,
+    -0x1.c6ac02p14
+  },
+  { // Entry 17
+    0x1.92e66b5920a85d6083e9cc85568ceaa3p-21,
+    0x1.c6ac02p14
+  },
+  { // Entry 18
+    0x1.d1ceb4ffff6ed05b5ef5fc618231214ap-2,
+    -0x1.e513fcp4
+  },
+  { // Entry 19
+    0x1.d1ceb4ffff6ed05b5ef5fc618231214ap-2,
+    0x1.e513fcp4
+  },
+  { // Entry 20
+    0x1.c27e049dfeab38e1b8ea6a09631829fep-1,
+    -0x1.fb1904p-2
+  },
+  { // Entry 21
+    0x1.c27e049dfeab38e1b8ea6a09631829fep-1,
+    0x1.fb1904p-2
+  },
+  { // Entry 22
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 23
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    0x1.fffffep127
+  },
+  { // Entry 24
+    0x1.ffffff000000155555549f49f4a28a28p-1,
+    0x1.p-12
+  },
+  { // Entry 25
+    0x1.ffffff000000155555549f49f4a28a28p-1,
+    -0x1.p-12
+  },
+  { // Entry 26
+    0x1.ffffffffffc000000000015555555555p-1,
+    0x1.p-21
+  },
+  { // Entry 27
+    0x1.ffffffffffc000000000015555555555p-1,
+    -0x1.p-21
+  },
+  { // Entry 28
+    0x1.fffffffffff000000000001555555555p-1,
+    0x1.p-22
+  },
+  { // Entry 29
+    0x1.fffffffffff000000000001555555555p-1,
+    -0x1.p-22
+  },
+  { // Entry 30
+    0x1.fffffefffffc155551ff49f696c4aecap-1,
+    0x1.000002p-12
+  },
+  { // Entry 31
+    0x1.fffffefffffc155551ff49f696c4aecap-1,
+    -0x1.000002p-12
+  },
+  { // Entry 32
+    0x1.882d606ba07505a7a09ae74d713f9788p-1,
+    0x1.000002p51
+  },
+  { // Entry 33
+    0x1.882d606ba07505a7a09ae74d713f9788p-1,
+    -0x1.000002p51
+  },
+  { // Entry 34
+    0x1.fc0154f7f5b6422f7794bf156ee98b7ep-1,
+    0x1.000006p-3
+  },
+  { // Entry 35
+    0x1.fc0154f7f5b6422f7794bf156ee98b7ep-1,
+    -0x1.000006p-3
+  },
+  { // Entry 36
+    0x1.34e976ef67d60a3de814ad3d0203ba21p-10,
+    0x1.000006p121
+  },
+  { // Entry 37
+    0x1.34e976ef67d60a3de814ad3d0203ba21p-10,
+    -0x1.000006p121
+  },
+  { // Entry 38
+    -0x1.ffffa2cf59398dc6180801e9ea3120c8p-1,
+    0x1.000006p122
+  },
+  { // Entry 39
+    -0x1.ffffa2cf59398dc6180801e9ea3120c8p-1,
+    -0x1.000006p122
+  },
+  { // Entry 40
+    0x1.ffc0014453315d47e2a318bf63e4caa7p-1,
+    0x1.000022p-5
+  },
+  { // Entry 41
+    0x1.ffc0014453315d47e2a318bf63e4caa7p-1,
+    -0x1.000022p-5
+  },
+  { // Entry 42
+    0x1.c15215015f3d916a0019a39e3acc7364p-1,
+    0x1.0000e0p-1
+  },
+  { // Entry 43
+    0x1.c15215015f3d916a0019a39e3acc7364p-1,
+    -0x1.0000e0p-1
+  },
+  { // Entry 44
+    0x1.ff001394e93085c7cce53915893af765p-1,
+    0x1.0000e0p-4
+  },
+  { // Entry 45
+    0x1.ff001394e93085c7cce53915893af765p-1,
+    -0x1.0000e0p-4
+  },
+  { // Entry 46
+    0x1.90b0c97de2370587a68aeae2b6943953p-15,
+    0x1.000322p23
+  },
+  { // Entry 47
+    0x1.90b0c97de2370587a68aeae2b6943953p-15,
+    -0x1.000322p23
+  },
+  { // Entry 48
+    -0x1.8b90c67677565874f44d9314ca2ba634p-6,
+    0x1.000402p8
+  },
+  { // Entry 49
+    -0x1.8b90c67677565874f44d9314ca2ba634p-6,
+    -0x1.000402p8
+  },
+  { // Entry 50
+    0x1.14735fffd55120a4480b7c91a1d78d6ep-1,
+    0x1.001cp0
+  },
+  { // Entry 51
+    0x1.14735fffd55120a4480b7c91a1d78d6ep-1,
+    -0x1.001cp0
+  },
+  { // Entry 52
+    0x1.c0b6d10005468a3a3eb056eb59b58ce2p-1,
+    0x1.0144p-1
+  },
+  { // Entry 53
+    0x1.c0b6d10005468a3a3eb056eb59b58ce2p-1,
+    -0x1.0144p-1
+  },
+  { // Entry 54
+    -0x1.c403d90006509b0762642d0bea40e4b1p-2,
+    0x1.0394c8p1
+  },
+  { // Entry 55
+    -0x1.c403d90006509b0762642d0bea40e4b1p-2,
+    -0x1.0394c8p1
+  },
+  { // Entry 56
+    -0x1.270da18b198e6ebfc8782082902bf2d4p-25,
+    0x1.04ccbcp18
+  },
+  { // Entry 57
+    -0x1.270da18b198e6ebfc8782082902bf2d4p-25,
+    -0x1.04ccbcp18
+  },
+  { // Entry 58
+    0x1.ee0f67015b9fb39ba6eb91d47829c913p-1,
+    0x1.07b518p99
+  },
+  { // Entry 59
+    0x1.ee0f67015b9fb39ba6eb91d47829c913p-1,
+    -0x1.07b518p99
+  },
+  { // Entry 60
+    0x1.fef05d000666cb47f1632c478a6282a8p-1,
+    0x1.07bf80p-4
+  },
+  { // Entry 61
+    0x1.fef05d000666cb47f1632c478a6282a8p-1,
+    -0x1.07bf80p-4
+  },
+  { // Entry 62
+    0x1.16f4330000b44c8288679f8c79d36c4fp-6,
+    0x1.07c1f0p5
+  },
+  { // Entry 63
+    0x1.16f4330000b44c8288679f8c79d36c4fp-6,
+    -0x1.07c1f0p5
+  },
+  { // Entry 64
+    0x1.cfb404557277d85bf149496d46c2fa9fp-18,
+    0x1.0bd21ep9
+  },
+  { // Entry 65
+    0x1.cfb404557277d85bf149496d46c2fa9fp-18,
+    -0x1.0bd21ep9
+  },
+  { // Entry 66
+    0x1.bb543efffd6cacac12698b8a94ed2c3ep-1,
+    0x1.0c3cp-1
+  },
+  { // Entry 67
+    0x1.bb543efffd6cacac12698b8a94ed2c3ep-1,
+    -0x1.0c3cp-1
+  },
+  { // Entry 68
+    0x1.bb0a22c13b616cdcad32c7fca58e6643p-1,
+    0x1.0cd0p-1
+  },
+  { // Entry 69
+    0x1.bb0a22c13b616cdcad32c7fca58e6643p-1,
+    -0x1.0cd0p-1
+  },
+  { // Entry 70
+    0x1.f98f9b1d05e7c922ac5e5c6b6ac86876p-2,
+    0x1.0df0p0
+  },
+  { // Entry 71
+    0x1.f98f9b1d05e7c922ac5e5c6b6ac86876p-2,
+    -0x1.0df0p0
+  },
+  { // Entry 72
+    0x1.ee15181830c25b0b10ce671e8f7a3289p-1,
+    0x1.0fb4p-2
+  },
+  { // Entry 73
+    0x1.ee15181830c25b0b10ce671e8f7a3289p-1,
+    -0x1.0fb4p-2
+  },
+  { // Entry 74
+    0x1.edf6cc16defe6361f38ffa60ece3944cp-1,
+    0x1.109ab2p-2
+  },
+  { // Entry 75
+    0x1.edf6cc16defe6361f38ffa60ece3944cp-1,
+    -0x1.109ab2p-2
+  },
+  { // Entry 76
+    0x1.dee8d0fffcd997ce5cfbab0a5a336c14p-5,
+    0x1.156564p4
+  },
+  { // Entry 77
+    0x1.dee8d0fffcd997ce5cfbab0a5a336c14p-5,
+    -0x1.156564p4
+  },
+  { // Entry 78
+    0x1.b656d60000155bacb4aa874b28de2ff9p-1,
+    0x1.160cp-1
+  },
+  { // Entry 79
+    0x1.b656d60000155bacb4aa874b28de2ff9p-1,
+    -0x1.160cp-1
+  },
+  { // Entry 80
+    0x1.ffb275967c191ee95f862efb4f790cecp-1,
+    0x1.19ccp-5
+  },
+  { // Entry 81
+    0x1.ffb275967c191ee95f862efb4f790cecp-1,
+    -0x1.19ccp-5
+  },
+  { // Entry 82
+    0x1.c59c50ffe542233b7ea21100df87bb60p-2,
+    0x1.1ca4p0
+  },
+  { // Entry 83
+    0x1.c59c50ffe542233b7ea21100df87bb60p-2,
+    -0x1.1ca4p0
+  },
+  { // Entry 84
+    0x1.af630f86b77571b9de2f17fee2b6c5cep-5,
+    0x1.1ffffep79
+  },
+  { // Entry 85
+    0x1.af630f86b77571b9de2f17fee2b6c5cep-5,
+    -0x1.1ffffep79
+  },
+  { // Entry 86
+    0x1.b1493ef1fbc62673ec140c12adc5a134p-6,
+    0x1.2620p10
+  },
+  { // Entry 87
+    0x1.b1493ef1fbc62673ec140c12adc5a134p-6,
+    -0x1.2620p10
+  },
+  { // Entry 88
+    -0x1.ad00b6f15c6ac5c3e79ef55d2fec70bdp-5,
+    0x1.2a3d62p2
+  },
+  { // Entry 89
+    -0x1.ad00b6f15c6ac5c3e79ef55d2fec70bdp-5,
+    -0x1.2a3d62p2
+  },
+  { // Entry 90
+    -0x1.ab9984f283f114cf13cc6df38c67955fp-6,
+    0x1.2bec22p2
+  },
+  { // Entry 91
+    -0x1.ab9984f283f114cf13cc6df38c67955fp-6,
+    -0x1.2bec22p2
+  },
+  { // Entry 92
+    0x1.99bc5b961b1acaca18d971f68ae99da9p-27,
+    0x1.2d97c8p2
+  },
+  { // Entry 93
+    0x1.99bc5b961b1acaca18d971f68ae99da9p-27,
+    -0x1.2d97c8p2
+  },
+  { // Entry 94
+    -0x1.ffffffffffffd703498c3b8288563915p-1,
+    0x1.2d97c8p3
+  },
+  { // Entry 95
+    -0x1.ffffffffffffd703498c3b8288563915p-1,
+    -0x1.2d97c8p3
+  },
+  { // Entry 96
+    0x1.ffffffffffff5c0d2630ee0a27e8d6d1p-1,
+    0x1.2d97c8p4
+  },
+  { // Entry 97
+    0x1.ffffffffffff5c0d2630ee0a27e8d6d1p-1,
+    -0x1.2d97c8p4
+  },
+  { // Entry 98
+    -0x1.99b69cf0c4a2c8ddad3f4cf29453e509p-6,
+    0x1.2fefc4p9
+  },
+  { // Entry 99
+    -0x1.99b69cf0c4a2c8ddad3f4cf29453e509p-6,
+    -0x1.2fefc4p9
+  },
+  { // Entry 100
+    0x1.e92148328d620fc186df9d6ce1088fd9p-1,
+    0x1.333724p-2
+  },
+  { // Entry 101
+    0x1.e92148328d620fc186df9d6ce1088fd9p-1,
+    -0x1.333724p-2
+  },
+  { // Entry 102
+    0x1.a1caab00002d3189e0699f2aaf20d9fcp-1,
+    0x1.3b90f8p-1
+  },
+  { // Entry 103
+    0x1.a1caab00002d3189e0699f2aaf20d9fcp-1,
+    -0x1.3b90f8p-1
+  },
+  { // Entry 104
+    0x1.fc33baffffffbb055ce03690bd392531p-1,
+    0x1.41c470p16
+  },
+  { // Entry 105
+    0x1.fc33baffffffbb055ce03690bd392531p-1,
+    -0x1.41c470p16
+  },
+  { // Entry 106
+    0x1.4798b30672f21602a21aaf471e8259a0p-19,
+    0x1.442f74p15
+  },
+  { // Entry 107
+    0x1.4798b30672f21602a21aaf471e8259a0p-19,
+    -0x1.442f74p15
+  },
+  { // Entry 108
+    0x1.e2b5ecffffa49c8c68d743c47f624633p-1,
+    0x1.5c09dap-2
+  },
+  { // Entry 109
+    0x1.e2b5ecffffa49c8c68d743c47f624633p-1,
+    -0x1.5c09dap-2
+  },
+  { // Entry 110
+    0x1.10591094ac58a270d9ad91802df49fd0p-11,
+    0x1.5fe0p3
+  },
+  { // Entry 111
+    0x1.10591094ac58a270d9ad91802df49fd0p-11,
+    -0x1.5fe0p3
+  },
+  { // Entry 112
+    -0x1.fffe580ee141c0225b44281c1c6f7ff1p-1,
+    0x1.665982p119
+  },
+  { // Entry 113
+    -0x1.fffe580ee141c0225b44281c1c6f7ff1p-1,
+    -0x1.665982p119
+  },
+  { // Entry 114
+    -0x1.e2b8ecffed91ce3a4b9dc5a592fb0b14p-1,
+    0x1.66a0bap1
+  },
+  { // Entry 115
+    -0x1.e2b8ecffed91ce3a4b9dc5a592fb0b14p-1,
+    -0x1.66a0bap1
+  },
+  { // Entry 116
+    -0x1.a08c6cfdbe04b859c0e16d478ff81f7bp-5,
+    0x1.6bee42p12
+  },
+  { // Entry 117
+    -0x1.a08c6cfdbe04b859c0e16d478ff81f7bp-5,
+    -0x1.6bee42p12
+  },
+  { // Entry 118
+    0x1.ff7c719a18439c4267075e2df688343ap-1,
+    0x1.6f1070p-5
+  },
+  { // Entry 119
+    0x1.ff7c719a18439c4267075e2df688343ap-1,
+    -0x1.6f1070p-5
+  },
+  { // Entry 120
+    0x1.ff7c3b997d6bea661ef0d1e69e222bfep-1,
+    0x1.6f5bc2p-5
+  },
+  { // Entry 121
+    0x1.ff7c3b997d6bea661ef0d1e69e222bfep-1,
+    -0x1.6f5bc2p-5
+  },
+  { // Entry 122
+    -0x1.6a0a0ee68da131091e29e055226a1bd9p-1,
+    0x1.72b53cp5
+  },
+  { // Entry 123
+    -0x1.6a0a0ee68da131091e29e055226a1bd9p-1,
+    -0x1.72b53cp5
+  },
+  { // Entry 124
+    0x1.ff777b9a218985c1a191c92b2d11ffbap-1,
+    0x1.75ec1ap-5
+  },
+  { // Entry 125
+    0x1.ff777b9a218985c1a191c92b2d11ffbap-1,
+    -0x1.75ec1ap-5
+  },
+  { // Entry 126
+    0x1.6d487f92427920e81dc5ae34e0e8d7bap-2,
+    0x1.78b3fap100
+  },
+  { // Entry 127
+    0x1.6d487f92427920e81dc5ae34e0e8d7bap-2,
+    -0x1.78b3fap100
+  },
+  { // Entry 128
+    0x1.4949c2fffa0cd336dfda998216dae393p-4,
+    0x1.7d8568p0
+  },
+  { // Entry 129
+    0x1.4949c2fffa0cd336dfda998216dae393p-4,
+    -0x1.7d8568p0
+  },
+  { // Entry 130
+    -0x1.b9ed9eb33eacbfac8151cda113734c29p-1,
+    0x1.830688p57
+  },
+  { // Entry 131
+    -0x1.b9ed9eb33eacbfac8151cda113734c29p-1,
+    -0x1.830688p57
+  },
+  { // Entry 132
+    0x1.c7349af06d61394cae1912233f64a04ep-5,
+    0x1.83e430p0
+  },
+  { // Entry 133
+    0x1.c7349af06d61394cae1912233f64a04ep-5,
+    -0x1.83e430p0
+  },
+  { // Entry 134
+    0x1.ab73f0f0fe04403e6a7fdde141a38a8ep-5,
+    0x1.84c288p0
+  },
+  { // Entry 135
+    0x1.ab73f0f0fe04403e6a7fdde141a38a8ep-5,
+    -0x1.84c288p0
+  },
+  { // Entry 136
+    0x1.ff6c2799dcf0d6c8f7acaf5b0a46e6e2p-1,
+    0x1.852140p-5
+  },
+  { // Entry 137
+    0x1.ff6c2799dcf0d6c8f7acaf5b0a46e6e2p-1,
+    -0x1.852140p-5
+  },
+  { // Entry 138
+    0x1.ff69ed99de70e51f519f30bad247a4d9p-1,
+    0x1.880cb6p-5
+  },
+  { // Entry 139
+    0x1.ff69ed99de70e51f519f30bad247a4d9p-1,
+    -0x1.880cb6p-5
+  },
+  { // Entry 140
+    -0x1.fd76c57f872f85bc4b0e1bf591b3b5b0p-1,
+    0x1.9364eap119
+  },
+  { // Entry 141
+    -0x1.fd76c57f872f85bc4b0e1bf591b3b5b0p-1,
+    -0x1.9364eap119
+  },
+  { // Entry 142
+    -0x1.f87c1ceec5fd5811c9c089cdaeeff13cp-8,
+    0x1.979e28p9
+  },
+  { // Entry 143
+    -0x1.f87c1ceec5fd5811c9c089cdaeeff13cp-8,
+    -0x1.979e28p9
+  },
+  { // Entry 144
+    -0x1.16ae29144d3b1ea8d907b8776f704157p-26,
+    0x1.9a48dep15
+  },
+  { // Entry 145
+    -0x1.16ae29144d3b1ea8d907b8776f704157p-26,
+    -0x1.9a48dep15
+  },
+  { // Entry 146
+    -0x1.977552f8e6ab3c01cb29ec77803007cfp-13,
+    0x1.9cbc1ap50
+  },
+  { // Entry 147
+    -0x1.977552f8e6ab3c01cb29ec77803007cfp-13,
+    -0x1.9cbc1ap50
+  },
+  { // Entry 148
+    0x1.ff58c5ffffffc7266a9df4e921726771p-1,
+    0x1.9ddb06p-5
+  },
+  { // Entry 149
+    0x1.ff58c5ffffffc7266a9df4e921726771p-1,
+    -0x1.9ddb06p-5
+  },
+  { // Entry 150
+    0x1.fffffffffffff5700019fffff0094c15p-1,
+    0x1.9ffffep-27
+  },
+  { // Entry 151
+    0x1.fffffffffffff5700019fffff0094c15p-1,
+    -0x1.9ffffep-27
+  },
+  { // Entry 152
+    0x1.31bd63004b1ff4d722c745044706d517p-1,
+    0x1.ac129cp24
+  },
+  { // Entry 153
+    0x1.31bd63004b1ff4d722c745044706d517p-1,
+    -0x1.ac129cp24
+  },
+  { // Entry 154
+    -0x1.f1ad0f000009e06ce449f5bde03d5d1ap-1,
+    0x1.b078f8p1
+  },
+  { // Entry 155
+    -0x1.f1ad0f000009e06ce449f5bde03d5d1ap-1,
+    -0x1.b078f8p1
+  },
+  { // Entry 156
+    0x1.ff4776ffe324ba2958aca8d73cf8b839p-1,
+    0x1.b2c03cp-5
+  },
+  { // Entry 157
+    0x1.ff4776ffe324ba2958aca8d73cf8b839p-1,
+    -0x1.b2c03cp-5
+  },
+  { // Entry 158
+    0x1.ff437f00005e500d29bd8103a8e769e9p-1,
+    0x1.b766f6p-5
+  },
+  { // Entry 159
+    0x1.ff437f00005e500d29bd8103a8e769e9p-1,
+    -0x1.b766f6p-5
+  },
+  { // Entry 160
+    -0x1.99663da94db7348bcbb257ed16b7227cp-24,
+    0x1.beeeeep79
+  },
+  { // Entry 161
+    -0x1.99663da94db7348bcbb257ed16b7227cp-24,
+    -0x1.beeeeep79
+  },
+  { // Entry 162
+    0x1.f3d620ffffff860e49bbab8963dcc42ep-1,
+    0x1.bf4e1cp-3
+  },
+  { // Entry 163
+    0x1.f3d620ffffff860e49bbab8963dcc42ep-1,
+    -0x1.bf4e1cp-3
+  },
+  { // Entry 164
+    0x1.81ff79ed9201755f7ad18b533aa99d18p-1,
+    0x1.c0p2
+  },
+  { // Entry 165
+    0x1.81ff79ed9201755f7ad18b533aa99d18p-1,
+    -0x1.c0p2
+  },
+  { // Entry 166
+    -0x1.af3c6108887730fcecedf61d2d81ceabp-15,
+    0x1.c20ec8p23
+  },
+  { // Entry 167
+    -0x1.af3c6108887730fcecedf61d2d81ceabp-15,
+    -0x1.c20ec8p23
+  },
+  { // Entry 168
+    -0x1.b1656ef91447fa6a546cbd81034cafabp-14,
+    0x1.c79d20p17
+  },
+  { // Entry 169
+    -0x1.b1656ef91447fa6a546cbd81034cafabp-14,
+    -0x1.c79d20p17
+  },
+  { // Entry 170
+    0x1.2da1d3007a57461f6f67f2d3e983f798p-1,
+    0x1.ca7ce0p24
+  },
+  { // Entry 171
+    0x1.2da1d3007a57461f6f67f2d3e983f798p-1,
+    -0x1.ca7ce0p24
+  },
+  { // Entry 172
+    0x1.ffdd37888387ce3c9828144676f2ab0dp-1,
+    0x1.cc31b8p18
+  },
+  { // Entry 173
+    0x1.ffdd37888387ce3c9828144676f2ab0dp-1,
+    -0x1.cc31b8p18
+  },
+  { // Entry 174
+    0x1.395ba4ffffa061223f7304299be0aad8p-1,
+    0x1.d30892p-1
+  },
+  { // Entry 175
+    0x1.395ba4ffffa061223f7304299be0aad8p-1,
+    -0x1.d30892p-1
+  },
+  { // Entry 176
+    0x1.cb27c6ffd8e9d51a0605b57fd02ee483p-1,
+    0x1.d5574cp-2
+  },
+  { // Entry 177
+    0x1.cb27c6ffd8e9d51a0605b57fd02ee483p-1,
+    -0x1.d5574cp-2
+  },
+  { // Entry 178
+    0x1.a0a09cfd2b2b23476f09aa3eb631351cp-5,
+    0x1.d7557ap12
+  },
+  { // Entry 179
+    0x1.a0a09cfd2b2b23476f09aa3eb631351cp-5,
+    -0x1.d7557ap12
+  },
+  { // Entry 180
+    0x1.38ae6d000c49df5001baf701b1a2a564p-1,
+    0x1.dbe75cp24
+  },
+  { // Entry 181
+    0x1.38ae6d000c49df5001baf701b1a2a564p-1,
+    -0x1.dbe75cp24
+  },
+  { // Entry 182
+    0x1.ffff1f00125abf3d1765781b64e6fe07p-1,
+    0x1.dffffep-9
+  },
+  { // Entry 183
+    0x1.ffff1f00125abf3d1765781b64e6fe07p-1,
+    -0x1.dffffep-9
+  },
+  { // Entry 184
+    -0x1.9abc76f7eb1d15a727e0be7ab16400a7p-1,
+    0x1.e02a42p108
+  },
+  { // Entry 185
+    -0x1.9abc76f7eb1d15a727e0be7ab16400a7p-1,
+    -0x1.e02a42p108
+  },
+  { // Entry 186
+    0x1.5a1429044eb087032dbee719cdd30226p-1,
+    0x1.e701eap100
+  },
+  { // Entry 187
+    0x1.5a1429044eb087032dbee719cdd30226p-1,
+    -0x1.e701eap100
+  },
+  { // Entry 188
+    -0x1.94ffc0f8d888f6f46c6d55a2efa1083fp-1,
+    0x1.edf188p24
+  },
+  { // Entry 189
+    -0x1.94ffc0f8d888f6f46c6d55a2efa1083fp-1,
+    -0x1.edf188p24
+  },
+  { // Entry 190
+    -0x1.27c6d300d8756e78846b84a1fa3b12a2p-1,
+    0x1.f4c63ap24
+  },
+  { // Entry 191
+    -0x1.27c6d300d8756e78846b84a1fa3b12a2p-1,
+    -0x1.f4c63ap24
+  },
+  { // Entry 192
+    0x1.da54ecefb1cd39510555126a76cb20d4p-7,
+    0x1.f5ba76p2
+  },
+  { // Entry 193
+    0x1.da54ecefb1cd39510555126a76cb20d4p-7,
+    -0x1.f5ba76p2
+  },
+  { // Entry 194
+    0x1.fc28da000006bc4f0b0cd3c8ab10fc57p-1,
+    0x1.f5ff4ep-4
+  },
+  { // Entry 195
+    0x1.fc28da000006bc4f0b0cd3c8ab10fc57p-1,
+    -0x1.f5ff4ep-4
+  },
+  { // Entry 196
+    -0x1.ffffffffffea396ab8aee509392c755dp-1,
+    0x1.f6a7a2p3
+  },
+  { // Entry 197
+    -0x1.ffffffffffea396ab8aee509392c755dp-1,
+    -0x1.f6a7a2p3
+  },
+  { // Entry 198
+    0x1.a4f1d4fd0ea286f32f3cb3092b4ced14p-5,
+    0x1.f6bff2p12
+  },
+  { // Entry 199
+    0x1.a4f1d4fd0ea286f32f3cb3092b4ced14p-5,
+    -0x1.f6bff2p12
+  },
+  { // Entry 200
+    -0x1.fffffffffffffaf33de290ca99e2faf3p-1,
+    0x1.f9cbe2p8
+  },
+  { // Entry 201
+    -0x1.fffffffffffffaf33de290ca99e2faf3p-1,
+    -0x1.f9cbe2p8
+  },
+  { // Entry 202
+    0x1.fdd40d6d912ce2594f200104570ac1b3p-3,
+    0x1.fc767ep12
+  },
+  { // Entry 203
+    0x1.fdd40d6d912ce2594f200104570ac1b3p-3,
+    -0x1.fc767ep12
+  },
+  { // Entry 204
+    -0x1.752de2ffffb1a5e227bf2c12f4083203p-1,
+    0x1.ff5352p8
+  },
+  { // Entry 205
+    -0x1.752de2ffffb1a5e227bf2c12f4083203p-1,
+    -0x1.ff5352p8
+  },
+  { // Entry 206
+    -0x1.4ed4c5ffc8018741870949767ff8dafap-1,
+    0x1.fff1fep1
+  },
+  { // Entry 207
+    -0x1.4ed4c5ffc8018741870949767ff8dafap-1,
+    -0x1.fff1fep1
+  },
+  { // Entry 208
+    -0x1.28406a0025545c9a568dacd45518dd65p-3,
+    0x1.fff1fep2
+  },
+  { // Entry 209
+    -0x1.28406a0025545c9a568dacd45518dd65p-3,
+    -0x1.fff1fep2
+  },
+  { // Entry 210
+    0x1.f015c8c24ca5e99c7c65599c8d60976ep-1,
+    0x1.fff7fep-3
+  },
+  { // Entry 211
+    0x1.f015c8c24ca5e99c7c65599c8d60976ep-1,
+    -0x1.fff7fep-3
+  },
+  { // Entry 212
+    0x1.aff9b45e94d32d8e5bde25dec6f357d6p-9,
+    0x1.fffe3ep41
+  },
+  { // Entry 213
+    0x1.aff9b45e94d32d8e5bde25dec6f357d6p-9,
+    -0x1.fffe3ep41
+  },
+  { // Entry 214
+    -0x1.ea5464fff571f6ff335004eade301b56p-1,
+    0x1.ffff8ep3
+  },
+  { // Entry 215
+    -0x1.ea5464fff571f6ff335004eade301b56p-1,
+    -0x1.ffff8ep3
+  },
+  { // Entry 216
+    0x1.fffd4e735df6db6a7ca7cb0436e6ef48p-1,
+    0x1.ffff8ep40
+  },
+  { // Entry 217
+    0x1.fffd4e735df6db6a7ca7cb0436e6ef48p-1,
+    -0x1.ffff8ep40
+  },
+  { // Entry 218
+    -0x1.88e527ffedd85d2e2429166f795d9788p-7,
+    0x1.ffff9ep45
+  },
+  { // Entry 219
+    -0x1.88e527ffedd85d2e2429166f795d9788p-7,
+    -0x1.ffff9ep45
+  },
+  { // Entry 220
+    -0x1.db8fa0e071f98061f27ef67161511437p-3,
+    0x1.ffffbap23
+  },
+  { // Entry 221
+    -0x1.db8fa0e071f98061f27ef67161511437p-3,
+    -0x1.ffffbap23
+  },
+  { // Entry 222
+    -0x1.fe5b337f4cfe25d468defe65d5c524adp-1,
+    0x1.ffffdcp8
+  },
+  { // Entry 223
+    -0x1.fe5b337f4cfe25d468defe65d5c524adp-1,
+    -0x1.ffffdcp8
+  },
+  { // Entry 224
+    -0x1.f59038f4c2dd33d159171ee80bb64886p-5,
+    0x1.fffff8p118
+  },
+  { // Entry 225
+    -0x1.f59038f4c2dd33d159171ee80bb64886p-5,
+    -0x1.fffff8p118
+  },
+  { // Entry 226
+    0x1.fffffc00001155553a7d27f4a289f319p-1,
+    0x1.fffffcp-12
+  },
+  { // Entry 227
+    0x1.fffffc00001155553a7d27f4a289f319p-1,
+    -0x1.fffffcp-12
+  },
+  { // Entry 228
+    -0x1.f9d6bdd62473cd2b729fe3a67a4e9157p-4,
+    0x1.fffffcp22
+  },
+  { // Entry 229
+    -0x1.f9d6bdd62473cd2b729fe3a67a4e9157p-4,
+    -0x1.fffffcp22
+  },
+  { // Entry 230
+    0x1.eb408300005d91b9814cada88f5fc596p-1,
+    0x1.24836cp-2
+  },
+  { // Entry 231
+    0x1.eb408300005d91b9814cada88f5fc596p-1,
+    -0x1.24836cp-2
+  },
+  { // Entry 232
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149
+  },
+  { // Entry 233
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149
+  },
+  { // Entry 234
+    0x1.p0,
+    0.0
+  },
+  { // Entry 235
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149
+  },
+  { // Entry 236
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149
+  },
+  { // Entry 237
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.000002p-126
+  },
+  { // Entry 238
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.000002p-126
+  },
+  { // Entry 239
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-126
+  },
+  { // Entry 240
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-126
+  },
+  { // Entry 241
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.fffffcp-127
+  },
+  { // Entry 242
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.fffffcp-127
+  },
+  { // Entry 243
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.fffffcp-127
+  },
+  { // Entry 244
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.fffffcp-127
+  },
+  { // Entry 245
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-126
+  },
+  { // Entry 246
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-126
+  },
+  { // Entry 247
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.000002p-126
+  },
+  { // Entry 248
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.000002p-126
+  },
+  { // Entry 249
+    0x1.ffffff5c28f57960cd56ebfe9482a61fp-1,
+    0x1.99999ap-13
+  },
+  { // Entry 250
+    0x1.ffffff5c28f57960cd56ebfe9482a61fp-1,
+    -0x1.99999ap-13
+  },
+  { // Entry 251
+    0x1.fffffd70a3d64e5ec165cd4307ad1326p-1,
+    0x1.99999ap-12
+  },
+  { // Entry 252
+    0x1.fffffd70a3d64e5ec165cd4307ad1326p-1,
+    -0x1.99999ap-12
+  },
+  { // Entry 253
+    0x1.fffffa3d709eecbfb5a385b0f3e0cb8fp-1,
+    0x1.333334p-11
+  },
+  { // Entry 254
+    0x1.fffffa3d709eecbfb5a385b0f3e0cb8fp-1,
+    -0x1.333334p-11
+  },
+  { // Entry 255
+    0x1.fffff5c28f5fc733c4202aa0bda92f97p-1,
+    0x1.99999ap-11
+  },
+  { // Entry 256
+    0x1.fffff5c28f5fc733c4202aa0bda92f97p-1,
+    -0x1.99999ap-11
+  },
+  { // Entry 257
+    0x1.fffff0000015555549f49f4d34d34ca0p-1,
+    0x1.p-10
+  },
+  { // Entry 258
+    0x1.fffff0000015555549f49f4d34d34ca0p-1,
+    -0x1.p-10
+  },
+  { // Entry 259
+    0x1.ffffe8f5c29ce07640bd5f6d8bb1ea6bp-1,
+    0x1.333334p-10
+  },
+  { // Entry 260
+    0x1.ffffe8f5c29ce07640bd5f6d8bb1ea6bp-1,
+    -0x1.333334p-10
+  },
+  { // Entry 261
+    0x1.ffffe0a3d714839f3601147ada73f8d9p-1,
+    0x1.666668p-10
+  },
+  { // Entry 262
+    0x1.ffffe0a3d714839f3601147ada73f8d9p-1,
+    -0x1.666668p-10
+  },
+  { // Entry 263
+    0x1.ffffd70a3d8191f66de5408fb2b995a0p-1,
+    0x1.99999cp-10
+  },
+  { // Entry 264
+    0x1.ffffd70a3d8191f66de5408fb2b995a0p-1,
+    -0x1.99999cp-10
+  },
+  { // Entry 265
+    0x1.ffffcc28f6d096b87d6d19a06e96999bp-1,
+    0x1.ccccccp-10
+  },
+  { // Entry 266
+    0x1.ffffcc28f6d096b87d6d19a06e96999bp-1,
+    -0x1.ccccccp-10
+  },
+  { // Entry 267
+    0x1.fffbcc2a71ceaabf5582b6da1fc30531p-1,
+    0x1.066666p-7
+  },
+  { // Entry 268
+    0x1.fffbcc2a71ceaabf5582b6da1fc30531p-1,
+    -0x1.066666p-7
+  },
+  { // Entry 269
+    0x1.fff30a4b7b5119d8e299f717ec0ece16p-1,
+    0x1.ccccccp-7
+  },
+  { // Entry 270
+    0x1.fff30a4b7b5119d8e299f717ec0ece16p-1,
+    -0x1.ccccccp-7
+  },
+  { // Entry 271
+    0x1.ffe57a785123226c1e2efb411353edc9p-1,
+    0x1.499998p-6
+  },
+  { // Entry 272
+    0x1.ffe57a785123226c1e2efb411353edc9p-1,
+    -0x1.499998p-6
+  },
+  { // Entry 273
+    0x1.ffd31cd10cb632d9733ac5f5f327a5f9p-1,
+    0x1.acccccp-6
+  },
+  { // Entry 274
+    0x1.ffd31cd10cb632d9733ac5f5f327a5f9p-1,
+    -0x1.acccccp-6
+  },
+  { // Entry 275
+    0x1.ffbbf18207542ef81390d73c3ba89c1ap-1,
+    0x1.08p-5
+  },
+  { // Entry 276
+    0x1.ffbbf18207542ef81390d73c3ba89c1ap-1,
+    -0x1.08p-5
+  },
+  { // Entry 277
+    0x1.ff9ff8c2eaeaee30fb211765af835171p-1,
+    0x1.39999ap-5
+  },
+  { // Entry 278
+    0x1.ff9ff8c2eaeaee30fb211765af835171p-1,
+    -0x1.39999ap-5
+  },
+  { // Entry 279
+    0x1.ff7f32d6eb1f9cf90226ec291c9e0922p-1,
+    0x1.6b3334p-5
+  },
+  { // Entry 280
+    0x1.ff7f32d6eb1f9cf90226ec291c9e0922p-1,
+    -0x1.6b3334p-5
+  },
+  { // Entry 281
+    0x1.ff59a00cc4ad492ca2597495412998edp-1,
+    0x1.9ccccep-5
+  },
+  { // Entry 282
+    0x1.ff59a00cc4ad492ca2597495412998edp-1,
+    -0x1.9ccccep-5
+  },
+  { // Entry 283
+    0x1.ff2f40c08acf4580a8d13380d9073398p-1,
+    0x1.ce6666p-5
+  },
+  { // Entry 284
+    0x1.ff2f40c08acf4580a8d13380d9073398p-1,
+    -0x1.ce6666p-5
+  },
+  { // Entry 285
+    0x1.8ca46ca011771bfae0d9edbf1dacb402p-1,
+    0x1.5e7fc4p-1
+  },
+  { // Entry 286
+    0x1.8ca46ca011771bfae0d9edbf1dacb402p-1,
+    -0x1.5e7fc4p-1
+  },
+  { // Entry 287
+    0x1.0b5d38d5d82e4a7624dac4e10ce159c2p-2,
+    0x1.4e7fc4p0
+  },
+  { // Entry 288
+    0x1.0b5d38d5d82e4a7624dac4e10ce159c2p-2,
+    -0x1.4e7fc4p0
+  },
+  { // Entry 289
+    -0x1.66b96e204e69cda8e9cf50996432539ep-2,
+    0x1.edbfa6p0
+  },
+  { // Entry 290
+    -0x1.66b96e204e69cda8e9cf50996432539ep-2,
+    -0x1.edbfa6p0
+  },
+  { // Entry 291
+    -0x1.a935540edeca4c220ed91dc5481e4d9bp-1,
+    0x1.467fc4p1
+  },
+  { // Entry 292
+    -0x1.a935540edeca4c220ed91dc5481e4d9bp-1,
+    -0x1.467fc4p1
+  },
+  { // Entry 293
+    -0x1.ffc0017dd9209dd8891f17fe4c9eee46p-1,
+    0x1.961fb4p1
+  },
+  { // Entry 294
+    -0x1.ffc0017dd9209dd8891f17fe4c9eee46p-1,
+    -0x1.961fb4p1
+  },
+  { // Entry 295
+    -0x1.969082007733d787f4c36ba0f9425694p-1,
+    0x1.e5bfa4p1
+  },
+  { // Entry 296
+    -0x1.969082007733d787f4c36ba0f9425694p-1,
+    -0x1.e5bfa4p1
+  },
+  { // Entry 297
+    -0x1.2a1e74223d9bddb7db59f781f96b65ecp-2,
+    0x1.1aafcap2
+  },
+  { // Entry 298
+    -0x1.2a1e74223d9bddb7db59f781f96b65ecp-2,
+    -0x1.1aafcap2
+  },
+  { // Entry 299
+    0x1.4894d50b84dbc981134a591ac4165d9ep-2,
+    0x1.427fc2p2
+  },
+  { // Entry 300
+    0x1.4894d50b84dbc981134a591ac4165d9ep-2,
+    -0x1.427fc2p2
+  },
+  { // Entry 301
+    0x1.a016dd7480a1eea4d49efb585fa49c86p-1,
+    0x1.6a4fbap2
+  },
+  { // Entry 302
+    0x1.a016dd7480a1eea4d49efb585fa49c86p-1,
+    -0x1.6a4fbap2
+  },
+  { // Entry 303
+    0x1.a30a6a3bf4a3e2b7e27666d3a9c3b74bp-1,
+    0x1.6af2f0p2
+  },
+  { // Entry 304
+    0x1.a30a6a3bf4a3e2b7e27666d3a9c3b74bp-1,
+    -0x1.6af2f0p2
+  },
+  { // Entry 305
+    0x1.5bd625504015ccc101e4f4340d4b762bp-2,
+    0x1.43c62ap2
+  },
+  { // Entry 306
+    0x1.5bd625504015ccc101e4f4340d4b762bp-2,
+    -0x1.43c62ap2
+  },
+  { // Entry 307
+    -0x1.0cb733448c30ee3ddffb4da69f0b3842p-2,
+    0x1.1c9964p2
+  },
+  { // Entry 308
+    -0x1.0cb733448c30ee3ddffb4da69f0b3842p-2,
+    -0x1.1c9964p2
+  },
+  { // Entry 309
+    -0x1.89d874ad30e3fb46244daa24451690d7p-1,
+    0x1.ead93cp1
+  },
+  { // Entry 310
+    -0x1.89d874ad30e3fb46244daa24451690d7p-1,
+    -0x1.ead93cp1
+  },
+  { // Entry 311
+    -0x1.fe51ae09f0d39ed554e68bef3e2f8a03p-1,
+    0x1.9c7fb0p1
+  },
+  { // Entry 312
+    -0x1.fe51ae09f0d39ed554e68bef3e2f8a03p-1,
+    -0x1.9c7fb0p1
+  },
+  { // Entry 313
+    -0x1.b97bf76ae765eb69cf55e80aae977303p-1,
+    0x1.4e2624p1
+  },
+  { // Entry 314
+    -0x1.b97bf76ae765eb69cf55e80aae977303p-1,
+    -0x1.4e2624p1
+  },
+  { // Entry 315
+    -0x1.a8ac5793e32629b131984ecffd2d0f31p-2,
+    0x1.ff9932p0
+  },
+  { // Entry 316
+    -0x1.a8ac5793e32629b131984ecffd2d0f31p-2,
+    -0x1.ff9932p0
+  },
+  { // Entry 317
+    0x1.77a92ca01bc79c195dda33736807f986p-3,
+    0x1.62e61cp0
+  },
+  { // Entry 318
+    0x1.77a92ca01bc79c195dda33736807f986p-3,
+    -0x1.62e61cp0
+  },
+  { // Entry 319
+    0x1.6e1060282c1488d9abd83da1d68cd0f7p-1,
+    0x1.8c662cp-1
+  },
+  { // Entry 320
+    0x1.6e1060282c1488d9abd83da1d68cd0f7p-1,
+    -0x1.8c662cp-1
+  },
+  { // Entry 321
+    -0x1.682f2bb87a8f5011735094176c9b6dacp-4,
+    -0x1.a8aa1cp0
+  },
+  { // Entry 322
+    -0x1.682f2bb87a8f5011735094176c9b6dacp-4,
+    0x1.a8aa1cp0
+  },
+  { // Entry 323
+    -0x1.e665cb2af842be5ba5f65960599a97ecp-7,
+    -0x1.95ec8ap0
+  },
+  { // Entry 324
+    -0x1.e665cb2af842be5ba5f65960599a97ecp-7,
+    0x1.95ec8ap0
+  },
+  { // Entry 325
+    0x1.ddd231501b12fcf2bc20633be4d51e51p-5,
+    -0x1.832ef8p0
+  },
+  { // Entry 326
+    0x1.ddd231501b12fcf2bc20633be4d51e51p-5,
+    0x1.832ef8p0
+  },
+  { // Entry 327
+    0x1.0caba6997691ab1970d43c7419ed51e1p-3,
+    -0x1.707166p0
+  },
+  { // Entry 328
+    0x1.0caba6997691ab1970d43c7419ed51e1p-3,
+    0x1.707166p0
+  },
+  { // Entry 329
+    0x1.a072541fd6eaf8b65a874c58d6cc5739p-3,
+    -0x1.5db3d4p0
+  },
+  { // Entry 330
+    0x1.a072541fd6eaf8b65a874c58d6cc5739p-3,
+    0x1.5db3d4p0
+  },
+  { // Entry 331
+    0x1.18fef8106bea63b9e96a7adf538c6194p-2,
+    -0x1.4af642p0
+  },
+  { // Entry 332
+    0x1.18fef8106bea63b9e96a7adf538c6194p-2,
+    0x1.4af642p0
+  },
+  { // Entry 333
+    0x1.60437277d48067e85230bce1883eaabap-2,
+    -0x1.3838b0p0
+  },
+  { // Entry 334
+    0x1.60437277d48067e85230bce1883eaabap-2,
+    0x1.3838b0p0
+  },
+  { // Entry 335
+    0x1.a5a4ded492bedfe8cf5c34cadd78df75p-2,
+    -0x1.257b1ep0
+  },
+  { // Entry 336
+    0x1.a5a4ded492bedfe8cf5c34cadd78df75p-2,
+    0x1.257b1ep0
+  },
+  { // Entry 337
+    0x1.e8c4040678d2ef736333a4537a1113a1p-2,
+    -0x1.12bd92p0
+  },
+  { // Entry 338
+    0x1.e8c4040678d2ef736333a4537a1113a1p-2,
+    0x1.12bd92p0
+  },
+  { // Entry 339
+    0x1.26976b1b16d19091c09259765c4b3872p-1,
+    -0x1.ea5c3ep-1
+  },
+  { // Entry 340
+    0x1.26976b1b16d19091c09259765c4b3872p-1,
+    0x1.ea5c3ep-1
+  },
+  { // Entry 341
+    0x1.3805a2dafda7f8554aec65dab348a714p-1,
+    -0x1.d4b87cp-1
+  },
+  { // Entry 342
+    0x1.3805a2dafda7f8554aec65dab348a714p-1,
+    0x1.d4b87cp-1
+  },
+  { // Entry 343
+    0x1.48e52ff5bbe794618b85190b86411824p-1,
+    -0x1.bf14bap-1
+  },
+  { // Entry 344
+    0x1.48e52ff5bbe794618b85190b86411824p-1,
+    0x1.bf14bap-1
+  },
+  { // Entry 345
+    0x1.592e5b615ef5ae463976d31141dbacf0p-1,
+    -0x1.a970f8p-1
+  },
+  { // Entry 346
+    0x1.592e5b615ef5ae463976d31141dbacf0p-1,
+    0x1.a970f8p-1
+  },
+  { // Entry 347
+    0x1.68d9b2d657e4307d331eb7bd35ee1879p-1,
+    -0x1.93cd36p-1
+  },
+  { // Entry 348
+    0x1.68d9b2d657e4307d331eb7bd35ee1879p-1,
+    0x1.93cd36p-1
+  },
+  { // Entry 349
+    0x1.77e00c3718528c36f722e63096c2646bp-1,
+    -0x1.7e2974p-1
+  },
+  { // Entry 350
+    0x1.77e00c3718528c36f722e63096c2646bp-1,
+    0x1.7e2974p-1
+  },
+  { // Entry 351
+    0x1.863a88d6b064f36f34370722d361ce9fp-1,
+    -0x1.6885b2p-1
+  },
+  { // Entry 352
+    0x1.863a88d6b064f36f34370722d361ce9fp-1,
+    0x1.6885b2p-1
+  },
+  { // Entry 353
+    0x1.93e2989cee6084e34b533b1eb92746dap-1,
+    -0x1.52e1f0p-1
+  },
+  { // Entry 354
+    0x1.93e2989cee6084e34b533b1eb92746dap-1,
+    0x1.52e1f0p-1
+  },
+  { // Entry 355
+    0x1.a0d1f8613ebc60c7ee6502ee183c89e7p-1,
+    -0x1.3d3e36p-1
+  },
+  { // Entry 356
+    0x1.a0d1f8613ebc60c7ee6502ee183c89e7p-1,
+    0x1.3d3e36p-1
+  },
+  { // Entry 357
+    0x1.bc6bd889a8a59dbb56e546a37ae798f5p-1,
+    -0x1.0a0b02p-1
+  },
+  { // Entry 358
+    0x1.bc6bd889a8a59dbb56e546a37ae798f5p-1,
+    0x1.0a0b02p-1
+  },
+  { // Entry 359
+    0x1.ca59c719f96075dd6b7a0ff443ad59dcp-1,
+    -0x1.d8f720p-2
+  },
+  { // Entry 360
+    0x1.ca59c719f96075dd6b7a0ff443ad59dcp-1,
+    0x1.d8f720p-2
+  },
+  { // Entry 361
+    0x1.d6c0b13df99613a49306b4dc6c57aa03p-1,
+    -0x1.9dd83cp-2
+  },
+  { // Entry 362
+    0x1.d6c0b13df99613a49306b4dc6c57aa03p-1,
+    0x1.9dd83cp-2
+  },
+  { // Entry 363
+    0x1.e1960273a4aaa1bd19ef0ccaa8874183p-1,
+    -0x1.62b958p-2
+  },
+  { // Entry 364
+    0x1.e1960273a4aaa1bd19ef0ccaa8874183p-1,
+    0x1.62b958p-2
+  },
+  { // Entry 365
+    0x1.ead07cd2e0f7f19679646362bbc0eb80p-1,
+    -0x1.279a74p-2
+  },
+  { // Entry 366
+    0x1.ead07cd2e0f7f19679646362bbc0eb80p-1,
+    0x1.279a74p-2
+  },
+  { // Entry 367
+    0x1.f26840efd86ceea23f388b6a1102ea4dp-1,
+    -0x1.d8f720p-3
+  },
+  { // Entry 368
+    0x1.f26840efd86ceea23f388b6a1102ea4dp-1,
+    0x1.d8f720p-3
+  },
+  { // Entry 369
+    0x1.f856d49251bd37c54f0094270eecbd18p-1,
+    -0x1.62b958p-3
+  },
+  { // Entry 370
+    0x1.f856d49251bd37c54f0094270eecbd18p-1,
+    0x1.62b958p-3
+  },
+  { // Entry 371
+    0x1.fc97283c4f5bd1f793201972b8db551fp-1,
+    -0x1.d8f720p-4
+  },
+  { // Entry 372
+    0x1.fc97283c4f5bd1f793201972b8db551fp-1,
+    0x1.d8f720p-4
+  },
+  { // Entry 373
+    0x1.ff259b7b3d721edf063a5bf6e7a1f93cp-1,
+    -0x1.d8f720p-5
+  },
+  { // Entry 374
+    0x1.ff259b7b3d721edf063a5bf6e7a1f93cp-1,
+    0x1.d8f720p-5
+  },
+  { // Entry 375
+    0x1.ff259b7b3d721edf063a5bf6e7a1f93cp-1,
+    0x1.d8f720p-5
+  },
+  { // Entry 376
+    0x1.ff259b7b3d721edf063a5bf6e7a1f93cp-1,
+    -0x1.d8f720p-5
+  },
+  { // Entry 377
+    0x1.fc97283c4f5bd1f793201972b8db551fp-1,
+    0x1.d8f720p-4
+  },
+  { // Entry 378
+    0x1.fc97283c4f5bd1f793201972b8db551fp-1,
+    -0x1.d8f720p-4
+  },
+  { // Entry 379
+    0x1.f856d49251bd37c54f0094270eecbd18p-1,
+    0x1.62b958p-3
+  },
+  { // Entry 380
+    0x1.f856d49251bd37c54f0094270eecbd18p-1,
+    -0x1.62b958p-3
+  },
+  { // Entry 381
+    0x1.f26840efd86ceea23f388b6a1102ea4dp-1,
+    0x1.d8f720p-3
+  },
+  { // Entry 382
+    0x1.f26840efd86ceea23f388b6a1102ea4dp-1,
+    -0x1.d8f720p-3
+  },
+  { // Entry 383
+    0x1.ead07cd2e0f7f19679646362bbc0eb80p-1,
+    0x1.279a74p-2
+  },
+  { // Entry 384
+    0x1.ead07cd2e0f7f19679646362bbc0eb80p-1,
+    -0x1.279a74p-2
+  },
+  { // Entry 385
+    0x1.e1960273a4aaa1bd19ef0ccaa8874183p-1,
+    0x1.62b958p-2
+  },
+  { // Entry 386
+    0x1.e1960273a4aaa1bd19ef0ccaa8874183p-1,
+    -0x1.62b958p-2
+  },
+  { // Entry 387
+    0x1.d6c0b13df99613a49306b4dc6c57aa03p-1,
+    0x1.9dd83cp-2
+  },
+  { // Entry 388
+    0x1.d6c0b13df99613a49306b4dc6c57aa03p-1,
+    -0x1.9dd83cp-2
+  },
+  { // Entry 389
+    0x1.ca59c719f96075dd6b7a0ff443ad59dcp-1,
+    0x1.d8f720p-2
+  },
+  { // Entry 390
+    0x1.ca59c719f96075dd6b7a0ff443ad59dcp-1,
+    -0x1.d8f720p-2
+  },
+  { // Entry 391
+    0x1.bc6bd889a8a59dbb56e546a37ae798f5p-1,
+    0x1.0a0b02p-1
+  },
+  { // Entry 392
+    0x1.bc6bd889a8a59dbb56e546a37ae798f5p-1,
+    -0x1.0a0b02p-1
+  },
+  { // Entry 393
+    0x1.a0d1f8613ebc60c7ee6502ee183c89e7p-1,
+    0x1.3d3e36p-1
+  },
+  { // Entry 394
+    0x1.a0d1f8613ebc60c7ee6502ee183c89e7p-1,
+    -0x1.3d3e36p-1
+  },
+  { // Entry 395
+    0x1.93e293b23a6aa1ae5373214eb8fb9e96p-1,
+    0x1.52e1f8p-1
+  },
+  { // Entry 396
+    0x1.93e293b23a6aa1ae5373214eb8fb9e96p-1,
+    -0x1.52e1f8p-1
+  },
+  { // Entry 397
+    0x1.863a83a8d9826c6135509406ebe05c0fp-1,
+    0x1.6885bap-1
+  },
+  { // Entry 398
+    0x1.863a83a8d9826c6135509406ebe05c0fp-1,
+    -0x1.6885bap-1
+  },
+  { // Entry 399
+    0x1.77e006c87cbaded66ec5b960c93c568ap-1,
+    0x1.7e297cp-1
+  },
+  { // Entry 400
+    0x1.77e006c87cbaded66ec5b960c93c568ap-1,
+    -0x1.7e297cp-1
+  },
+  { // Entry 401
+    0x1.68d9ad29736c1704caea6a2db6e71223p-1,
+    0x1.93cd3ep-1
+  },
+  { // Entry 402
+    0x1.68d9ad29736c1704caea6a2db6e71223p-1,
+    -0x1.93cd3ep-1
+  },
+  { // Entry 403
+    0x1.592e5578c9ec66acceddd4dc6ce66b26p-1,
+    0x1.a971p-1
+  },
+  { // Entry 404
+    0x1.592e5578c9ec66acceddd4dc6ce66b26p-1,
+    -0x1.a971p-1
+  },
+  { // Entry 405
+    0x1.48e529d429e721ec8bb1e014f94d48f1p-1,
+    0x1.bf14c2p-1
+  },
+  { // Entry 406
+    0x1.48e529d429e721ec8bb1e014f94d48f1p-1,
+    -0x1.bf14c2p-1
+  },
+  { // Entry 407
+    0x1.38059c833c58ea970f7b96d6ada3d9c4p-1,
+    0x1.d4b884p-1
+  },
+  { // Entry 408
+    0x1.38059c833c58ea970f7b96d6ada3d9c4p-1,
+    -0x1.d4b884p-1
+  },
+  { // Entry 409
+    0x1.26976b1b16d19091c09259765c4b3872p-1,
+    0x1.ea5c3ep-1
+  },
+  { // Entry 410
+    0x1.26976b1b16d19091c09259765c4b3872p-1,
+    -0x1.ea5c3ep-1
+  },
+  { // Entry 411
+    0x1.e8c4040678d2ef736333a4537a1113a1p-2,
+    0x1.12bd92p0
+  },
+  { // Entry 412
+    0x1.e8c4040678d2ef736333a4537a1113a1p-2,
+    -0x1.12bd92p0
+  },
+  { // Entry 413
+    0x1.a5a4c8f598fa0078971316eb4907f97bp-2,
+    0x1.257b24p0
+  },
+  { // Entry 414
+    0x1.a5a4c8f598fa0078971316eb4907f97bp-2,
+    -0x1.257b24p0
+  },
+  { // Entry 415
+    0x1.60435beed10ca05769f0a3d86a5a20f3p-2,
+    0x1.3838b6p0
+  },
+  { // Entry 416
+    0x1.60435beed10ca05769f0a3d86a5a20f3p-2,
+    -0x1.3838b6p0
+  },
+  { // Entry 417
+    0x1.18fee0fc45c31a79b2b9478b1f72a9ebp-2,
+    0x1.4af648p0
+  },
+  { // Entry 418
+    0x1.18fee0fc45c31a79b2b9478b1f72a9ebp-2,
+    -0x1.4af648p0
+  },
+  { // Entry 419
+    0x1.a072252090c33828767aee3e040ccddfp-3,
+    0x1.5db3dap0
+  },
+  { // Entry 420
+    0x1.a072252090c33828767aee3e040ccddfp-3,
+    -0x1.5db3dap0
+  },
+  { // Entry 421
+    0x1.0cab7703a8e9dacc4ad01188b443cfeep-3,
+    0x1.70716cp0
+  },
+  { // Entry 422
+    0x1.0cab7703a8e9dacc4ad01188b443cfeep-3,
+    -0x1.70716cp0
+  },
+  { // Entry 423
+    0x1.ddd171a3c9851e7819b5e4f6f90e763dp-5,
+    0x1.832efep0
+  },
+  { // Entry 424
+    0x1.ddd171a3c9851e7819b5e4f6f90e763dp-5,
+    -0x1.832efep0
+  },
+  { // Entry 425
+    -0x1.e668cb154eea68bbc7f8154f46b2e536p-7,
+    0x1.95ec90p0
+  },
+  { // Entry 426
+    -0x1.e668cb154eea68bbc7f8154f46b2e536p-7,
+    -0x1.95ec90p0
+  },
+  { // Entry 427
+    -0x1.682f2bb87a8f5011735094176c9b6dacp-4,
+    0x1.a8aa1cp0
+  },
+  { // Entry 428
+    -0x1.682f2bb87a8f5011735094176c9b6dacp-4,
+    -0x1.a8aa1cp0
+  },
+  { // Entry 429
+    0x1.0cb3449a0d0a9e0643d41f4a5b0f7db7p-1,
+    0x1.04aff8p0
+  },
+  { // Entry 430
+    0x1.0cb3449a0d0a9e0643d41f4a5b0f7db7p-1,
+    -0x1.04aff8p0
+  },
+  { // Entry 431
+    0x1.0cb22697153bcf1f8a63acddd96c54cbp-1,
+    0x1.04b0a0p0
+  },
+  { // Entry 432
+    0x1.0cb22697153bcf1f8a63acddd96c54cbp-1,
+    -0x1.04b0a0p0
+  },
+  { // Entry 433
+    0x1.0cb10893a9b5471a44356072cb33b395p-1,
+    0x1.04b148p0
+  },
+  { // Entry 434
+    0x1.0cb10893a9b5471a44356072cb33b395p-1,
+    -0x1.04b148p0
+  },
+  { // Entry 435
+    0x1.0cafea8fca7781236a57e5b1c8aed39cp-1,
+    0x1.04b1f0p0
+  },
+  { // Entry 436
+    0x1.0cafea8fca7781236a57e5b1c8aed39cp-1,
+    -0x1.04b1f0p0
+  },
+  { // Entry 437
+    0x1.0caecc8b7782f86827af92b0b2374510p-1,
+    0x1.04b298p0
+  },
+  { // Entry 438
+    0x1.0caecc8b7782f86827af92b0b2374510p-1,
+    -0x1.04b298p0
+  },
+  { // Entry 439
+    0x1.0cadae86b0d82815d8f632e67c7e1a99p-1,
+    0x1.04b340p0
+  },
+  { // Entry 440
+    0x1.0cadae86b0d82815d8f632e67c7e1a99p-1,
+    -0x1.04b340p0
+  },
+  { // Entry 441
+    0x1.0cac908176778b5a0cbad21ee75ce765p-1,
+    0x1.04b3e8p0
+  },
+  { // Entry 442
+    0x1.0cac908176778b5a0cbad21ee75ce765p-1,
+    -0x1.04b3e8p0
+  },
+  { // Entry 443
+    0x1.0cab727bc8619d628361876e1f30a633p-1,
+    0x1.04b490p0
+  },
+  { // Entry 444
+    0x1.0cab727bc8619d628361876e1f30a633p-1,
+    -0x1.04b490p0
+  },
+  { // Entry 445
+    0x1.0caa5b450a4324f204a556b072da124ap-1,
+    0x1.04b534p0
+  },
+  { // Entry 446
+    0x1.0caa5b450a4324f204a556b072da124ap-1,
+    -0x1.04b534p0
+  },
+  { // Entry 447
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149
+  },
+  { // Entry 448
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149
+  },
+  { // Entry 449
+    0x1.p0,
+    0.0
+  },
+  { // Entry 450
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149
+  },
+  { // Entry 451
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149
+  },
+  { // Entry 452
+    0x1.ad02c8b9cc93f448ef4eb068a88922a3p-1,
+    0x1.279a72p-1
+  },
+  { // Entry 453
+    0x1.ad02c8b9cc93f448ef4eb068a88922a3p-1,
+    -0x1.279a72p-1
+  },
+  { // Entry 454
+    0x1.ad02c7a258bfb362abbe86fb48f4e98bp-1,
+    0x1.279a74p-1
+  },
+  { // Entry 455
+    0x1.ad02c7a258bfb362abbe86fb48f4e98bp-1,
+    -0x1.279a74p-1
+  },
+  { // Entry 456
+    0x1.ad02c68ae4e9c579a08c04ce59be4002p-1,
+    0x1.279a76p-1
+  },
+  { // Entry 457
+    0x1.ad02c68ae4e9c579a08c04ce59be4002p-1,
+    -0x1.279a76p-1
+  },
+  { // Entry 458
+    -0x1.48d1c9e98b6c08784f10040f47a12191p-3,
+    0x1.bb67acp0
+  },
+  { // Entry 459
+    -0x1.48d1c9e98b6c08784f10040f47a12191p-3,
+    -0x1.bb67acp0
+  },
+  { // Entry 460
+    -0x1.48d1d9b467e37955337311decd09fc74p-3,
+    0x1.bb67aep0
+  },
+  { // Entry 461
+    -0x1.48d1d9b467e37955337311decd09fc74p-3,
+    -0x1.bb67aep0
+  },
+  { // Entry 462
+    -0x1.48d1e97f4455c6eab1048022238b2bd0p-3,
+    0x1.bb67b0p0
+  },
+  { // Entry 463
+    -0x1.48d1e97f4455c6eab1048022238b2bd0p-3,
+    -0x1.bb67b0p0
+  },
+  { // Entry 464
+    0x1.cfc6d011a0e5d0fcebb54b5fed672940p-1,
+    0x1.bffffep-2
+  },
+  { // Entry 465
+    0x1.cfc6d011a0e5d0fcebb54b5fed672940p-1,
+    -0x1.bffffep-2
+  },
+  { // Entry 466
+    0x1.cfc6cfa52ad9f62d6d5423ca8339a00ap-1,
+    0x1.c0p-2
+  },
+  { // Entry 467
+    0x1.cfc6cfa52ad9f62d6d5423ca8339a00ap-1,
+    -0x1.c0p-2
+  },
+  { // Entry 468
+    0x1.cfc6cf38b4cda76c3b09b17e9deb19eap-1,
+    0x1.c00002p-2
+  },
+  { // Entry 469
+    0x1.cfc6cf38b4cda76c3b09b17e9deb19eap-1,
+    -0x1.c00002p-2
+  },
+  { // Entry 470
+    0x1.8bb106eac7c75d33fbb19446313ecc2fp-1,
+    0x1.5ffffep-1
+  },
+  { // Entry 471
+    0x1.8bb106eac7c75d33fbb19446313ecc2fp-1,
+    -0x1.5ffffep-1
+  },
+  { // Entry 472
+    0x1.8bb105a5dc900618f80fa51d303c69p-1,
+    0x1.60p-1
+  },
+  { // Entry 473
+    0x1.8bb105a5dc900618f80fa51d303c69p-1,
+    -0x1.60p-1
+  },
+  { // Entry 474
+    0x1.8bb10460f157234ceec7d9644a1a78e5p-1,
+    0x1.600002p-1
+  },
+  { // Entry 475
+    0x1.8bb10460f157234ceec7d9644a1a78e5p-1,
+    -0x1.600002p-1
+  },
+  { // Entry 476
+    0x1.7ef48b9a6fd5c24f5ec39839e1729b78p-2,
+    0x1.2ffffep0
+  },
+  { // Entry 477
+    0x1.7ef48b9a6fd5c24f5ec39839e1729b78p-2,
+    -0x1.2ffffep0
+  },
+  { // Entry 478
+    0x1.7ef4842f0bccd60d4a501dc8bc4b57b3p-2,
+    0x1.30p0
+  },
+  { // Entry 479
+    0x1.7ef4842f0bccd60d4a501dc8bc4b57b3p-2,
+    -0x1.30p0
+  },
+  { // Entry 480
+    0x1.7ef47cc3a7bdedf9252074263d8a4596p-2,
+    0x1.300002p0
+  },
+  { // Entry 481
+    0x1.7ef47cc3a7bdedf9252074263d8a4596p-2,
+    -0x1.300002p0
+  },
+  { // Entry 482
+    -0x1.863ef5085bcc358d2ae8525bf39f0c40p-1,
+    0x1.37fffep1
+  },
+  { // Entry 483
+    -0x1.863ef5085bcc358d2ae8525bf39f0c40p-1,
+    -0x1.37fffep1
+  },
+  { // Entry 484
+    -0x1.863efa361dc252bca1eaeed39749bed7p-1,
+    0x1.38p1
+  },
+  { // Entry 485
+    -0x1.863efa361dc252bca1eaeed39749bed7p-1,
+    -0x1.38p1
+  },
+  { // Entry 486
+    -0x1.863eff63dfa00bfc758baf469469d741p-1,
+    0x1.380002p1
+  },
+  { // Entry 487
+    -0x1.863eff63dfa00bfc758baf469469d741p-1,
+    -0x1.380002p1
+  },
+  { // Entry 488
+    0x1.fef2b2d0a10e2739c566936480a1479bp-1,
+    0x1.069c8cp-4
+  },
+  { // Entry 489
+    0x1.fef2b2d0a10e2739c566936480a1479bp-1,
+    -0x1.069c8cp-4
+  },
+  { // Entry 490
+    0x1.fbcbe68dd10bad0a229ccbb580cc5436p-1,
+    0x1.069c8cp-3
+  },
+  { // Entry 491
+    0x1.fbcbe68dd10bad0a229ccbb580cc5436p-1,
+    -0x1.069c8cp-3
+  },
+  { // Entry 492
+    0x1.f68eebef72e7f6126b3f3dde646a755cp-1,
+    0x1.89ead2p-3
+  },
+  { // Entry 493
+    0x1.f68eebef72e7f6126b3f3dde646a755cp-1,
+    -0x1.89ead2p-3
+  },
+  { // Entry 494
+    0x1.ef41459d2e90ea1b7faad7fabd1fd444p-1,
+    0x1.069c8cp-2
+  },
+  { // Entry 495
+    0x1.ef41459d2e90ea1b7faad7fabd1fd444p-1,
+    -0x1.069c8cp-2
+  },
+  { // Entry 496
+    0x1.e5eaa23a27fe8d6890a3edace1c61998p-1,
+    0x1.4843b0p-2
+  },
+  { // Entry 497
+    0x1.e5eaa23a27fe8d6890a3edace1c61998p-1,
+    -0x1.4843b0p-2
+  },
+  { // Entry 498
+    0x1.da94d4b99c3a9a5e0d1fc86d53369a84p-1,
+    0x1.89ead4p-2
+  },
+  { // Entry 499
+    0x1.da94d4b99c3a9a5e0d1fc86d53369a84p-1,
+    -0x1.89ead4p-2
+  },
+  { // Entry 500
+    0x1.cd4bc9afc01230b2f982f6968dab7f05p-1,
+    0x1.cb91f8p-2
+  },
+  { // Entry 501
+    0x1.cd4bc9afc01230b2f982f6968dab7f05p-1,
+    -0x1.cb91f8p-2
+  },
+  { // Entry 502
+    0x1.be1d7adf077def2a360fec23dbbcef09p-1,
+    0x1.069c8ep-1
+  },
+  { // Entry 503
+    0x1.be1d7adf077def2a360fec23dbbcef09p-1,
+    -0x1.069c8ep-1
+  },
+  { // Entry 504
+    0x1.ad19e0847d25f3aa142289dab557bf96p-1,
+    0x1.277020p-1
+  },
+  { // Entry 505
+    0x1.ad19e0847d25f3aa142289dab557bf96p-1,
+    -0x1.277020p-1
+  },
+  { // Entry 506
+    0x1.9a52e08b191bd55512c8365074f1987fp-1,
+    0x1.4843b2p-1
+  },
+  { // Entry 507
+    0x1.9a52e08b191bd55512c8365074f1987fp-1,
+    -0x1.4843b2p-1
+  },
+  { // Entry 508
+    0x1.85dc3bb7c2e9abb5cccb6d96d12d39c4p-1,
+    0x1.691744p-1
+  },
+  { // Entry 509
+    0x1.85dc3bb7c2e9abb5cccb6d96d12d39c4p-1,
+    -0x1.691744p-1
+  },
+  { // Entry 510
+    0x1.6fcb78e1cd65d2e4fde7118caac79d6dp-1,
+    0x1.89ead6p-1
+  },
+  { // Entry 511
+    0x1.6fcb78e1cd65d2e4fde7118caac79d6dp-1,
+    -0x1.89ead6p-1
+  },
+  { // Entry 512
+    0x1.5837ce4dc835d4a5454ec0a1bb394081p-1,
+    0x1.aabe68p-1
+  },
+  { // Entry 513
+    0x1.5837ce4dc835d4a5454ec0a1bb394081p-1,
+    -0x1.aabe68p-1
+  },
+  { // Entry 514
+    0x1.3f3a09427966e9518802dee3bf443a95p-1,
+    0x1.cb91fap-1
+  },
+  { // Entry 515
+    0x1.3f3a09427966e9518802dee3bf443a95p-1,
+    -0x1.cb91fap-1
+  },
+  { // Entry 516
+    0x1.24ec73f1aeef4940bb8da19a82bbc49fp-1,
+    0x1.ec658cp-1
+  },
+  { // Entry 517
+    0x1.24ec73f1aeef4940bb8da19a82bbc49fp-1,
+    -0x1.ec658cp-1
+  },
+  { // Entry 518
+    0x1.096abb862f9bd5515982c2818c332ff9p-1,
+    0x1.069c8ep0
+  },
+  { // Entry 519
+    0x1.096abb862f9bd5515982c2818c332ff9p-1,
+    -0x1.069c8ep0
+  },
+  { // Entry 520
+    0x1.d9a39c0dddc654c717e3036da5dd685cp-2,
+    0x1.170656p0
+  },
+  { // Entry 521
+    0x1.d9a39c0dddc654c717e3036da5dd685cp-2,
+    -0x1.170656p0
+  },
+  { // Entry 522
+    0x1.9e7f81840c0bbd0f1b13733061062d34p-2,
+    0x1.27701ep0
+  },
+  { // Entry 523
+    0x1.9e7f81840c0bbd0f1b13733061062d34p-2,
+    -0x1.27701ep0
+  },
+  { // Entry 524
+    0x1.61a75e2deb596731c8cd45e3d9794526p-2,
+    0x1.37d9e6p0
+  },
+  { // Entry 525
+    0x1.61a75e2deb596731c8cd45e3d9794526p-2,
+    -0x1.37d9e6p0
+  },
+  { // Entry 526
+    0x1.235b337b091cdd8ac06390abc6816b82p-2,
+    0x1.4843aep0
+  },
+  { // Entry 527
+    0x1.235b337b091cdd8ac06390abc6816b82p-2,
+    -0x1.4843aep0
+  },
+  { // Entry 528
+    0x1.c7b9146d6d10824ff652dc390ba2d7f9p-3,
+    0x1.58ad76p0
+  },
+  { // Entry 529
+    0x1.c7b9146d6d10824ff652dc390ba2d7f9p-3,
+    -0x1.58ad76p0
+  },
+  { // Entry 530
+    0x1.46dc5b2f1de977efff7c278b5adb2a75p-3,
+    0x1.69173ep0
+  },
+  { // Entry 531
+    0x1.46dc5b2f1de977efff7c278b5adb2a75p-3,
+    -0x1.69173ep0
+  },
+  { // Entry 532
+    0x1.894f93ef49c4575800bbd646a3a31d2ap-4,
+    0x1.798106p0
+  },
+  { // Entry 533
+    0x1.894f93ef49c4575800bbd646a3a31d2ap-4,
+    -0x1.798106p0
+  },
+  { // Entry 534
+    0x1.069164e3f5cee94d865fb52e316dff6bp-5,
+    0x1.89eacep0
+  },
+  { // Entry 535
+    0x1.069164e3f5cee94d865fb52e316dff6bp-5,
+    -0x1.89eacep0
+  },
+  { // Entry 536
+    -0x1.069093eec0ed066ec83dd034498ef8bfp-5,
+    0x1.9a5496p0
+  },
+  { // Entry 537
+    -0x1.069093eec0ed066ec83dd034498ef8bfp-5,
+    -0x1.9a5496p0
+  },
+  { // Entry 538
+    -0x1.894f2be2979dd9ced83ccc60cf49cd44p-4,
+    0x1.aabe5ep0
+  },
+  { // Entry 539
+    -0x1.894f2be2979dd9ced83ccc60cf49cd44p-4,
+    -0x1.aabe5ep0
+  },
+  { // Entry 540
+    -0x1.46dc2796735195a15c80e5b719e2fc42p-3,
+    0x1.bb2826p0
+  },
+  { // Entry 541
+    -0x1.46dc2796735195a15c80e5b719e2fc42p-3,
+    -0x1.bb2826p0
+  },
+  { // Entry 542
+    -0x1.c7b8e178b7e8c01d9f320466cc7a68d4p-3,
+    0x1.cb91eep0
+  },
+  { // Entry 543
+    -0x1.c7b8e178b7e8c01d9f320466cc7a68d4p-3,
+    -0x1.cb91eep0
+  },
+  { // Entry 544
+    -0x1.235b1a6d767e4b362c64571ac97b4a1cp-2,
+    0x1.dbfbb6p0
+  },
+  { // Entry 545
+    -0x1.235b1a6d767e4b362c64571ac97b4a1cp-2,
+    -0x1.dbfbb6p0
+  },
+  { // Entry 546
+    -0x1.61a745a77b7e83c2f8a2f9b091e89aaap-2,
+    0x1.ec657ep0
+  },
+  { // Entry 547
+    -0x1.61a745a77b7e83c2f8a2f9b091e89aaap-2,
+    -0x1.ec657ep0
+  },
+  { // Entry 548
+    -0x1.9e7f699e8b9aaf8ed51c71c8f73b0b74p-2,
+    0x1.fccf46p0
+  },
+  { // Entry 549
+    -0x1.9e7f699e8b9aaf8ed51c71c8f73b0b74p-2,
+    -0x1.fccf46p0
+  },
+  { // Entry 550
+    -0x1.d9a38bfa3195ba1caa7fb69bc1d04e42p-2,
+    0x1.069c88p1
+  },
+  { // Entry 551
+    -0x1.d9a38bfa3195ba1caa7fb69bc1d04e42p-2,
+    -0x1.069c88p1
+  },
+  { // Entry 552
+    -0x1.096ab3c55c91f36e2359ed1c5a8342dfp-1,
+    0x1.0ed16cp1
+  },
+  { // Entry 553
+    -0x1.096ab3c55c91f36e2359ed1c5a8342dfp-1,
+    -0x1.0ed16cp1
+  },
+  { // Entry 554
+    -0x1.24ec6c8206e744322d99f47e9e41becep-1,
+    0x1.170650p1
+  },
+  { // Entry 555
+    -0x1.24ec6c8206e744322d99f47e9e41becep-1,
+    -0x1.170650p1
+  },
+  { // Entry 556
+    -0x1.3f3a009b82b5b8234e1296dd73cff49dp-1,
+    0x1.1f3b34p1
+  },
+  { // Entry 557
+    -0x1.3f3a009b82b5b8234e1296dd73cff49dp-1,
+    -0x1.1f3b34p1
+  },
+  { // Entry 558
+    -0x1.5837c4a184ccf7ed57c189f2addf32c5p-1,
+    0x1.277018p1
+  },
+  { // Entry 559
+    -0x1.5837c4a184ccf7ed57c189f2addf32c5p-1,
+    -0x1.277018p1
+  },
+  { // Entry 560
+    -0x1.6fcb6e6685e72fb4074e70cd3162d3bap-1,
+    0x1.2fa4fcp1
+  },
+  { // Entry 561
+    -0x1.6fcb6e6685e72fb4074e70cd3162d3bap-1,
+    -0x1.2fa4fcp1
+  },
+  { // Entry 562
+    -0x1.85dc30a79f26754ab1370338ee7bfd11p-1,
+    0x1.37d9e0p1
+  },
+  { // Entry 563
+    -0x1.85dc30a79f26754ab1370338ee7bfd11p-1,
+    -0x1.37d9e0p1
+  },
+  { // Entry 564
+    -0x1.9a52d523b1532e4ed477e27dc6051c12p-1,
+    0x1.400ec4p1
+  },
+  { // Entry 565
+    -0x1.9a52d523b1532e4ed477e27dc6051c12p-1,
+    -0x1.400ec4p1
+  },
+  { // Entry 566
+    -0x1.ad19d50664abf0c0141137d2ca509f21p-1,
+    0x1.4843a8p1
+  },
+  { // Entry 567
+    -0x1.ad19d50664abf0c0141137d2ca509f21p-1,
+    -0x1.4843a8p1
+  },
+  { // Entry 568
+    -0x1.be1d6f8d517db5c2cf7de0faf0808d30p-1,
+    0x1.50788cp1
+  },
+  { // Entry 569
+    -0x1.be1d6f8d517db5c2cf7de0faf0808d30p-1,
+    -0x1.50788cp1
+  },
+  { // Entry 570
+    -0x1.cd4bbecf7f2705d4fd00dd463780f45ep-1,
+    0x1.58ad70p1
+  },
+  { // Entry 571
+    -0x1.cd4bbecf7f2705d4fd00dd463780f45ep-1,
+    -0x1.58ad70p1
+  },
+  { // Entry 572
+    -0x1.da94ca915da3cdd1fff839d85eec39e2p-1,
+    0x1.60e254p1
+  },
+  { // Entry 573
+    -0x1.da94ca915da3cdd1fff839d85eec39e2p-1,
+    -0x1.60e254p1
+  },
+  { // Entry 574
+    -0x1.e5ea99116b39361ac926dd9fdc2089d1p-1,
+    0x1.691738p1
+  },
+  { // Entry 575
+    -0x1.e5ea99116b39361ac926dd9fdc2089d1p-1,
+    -0x1.691738p1
+  },
+  { // Entry 576
+    -0x1.ef413dbbda2859ffb0d1ab84342fd235p-1,
+    0x1.714c1cp1
+  },
+  { // Entry 577
+    -0x1.ef413dbbda2859ffb0d1ab84342fd235p-1,
+    -0x1.714c1cp1
+  },
+  { // Entry 578
+    -0x1.f68ee5b5bf356b10230944a18e70925cp-1,
+    0x1.7981p1
+  },
+  { // Entry 579
+    -0x1.f68ee5b5bf356b10230944a18e70925cp-1,
+    -0x1.7981p1
+  },
+  { // Entry 580
+    -0x1.fbcbe23296fc61b96f382f35ea15c768p-1,
+    0x1.81b5e4p1
+  },
+  { // Entry 581
+    -0x1.fbcbe23296fc61b96f382f35ea15c768p-1,
+    -0x1.81b5e4p1
+  },
+  { // Entry 582
+    -0x1.fef2b08943197cd3a8ba861095227c48p-1,
+    0x1.89eac8p1
+  },
+  { // Entry 583
+    -0x1.fef2b08943197cd3a8ba861095227c48p-1,
+    -0x1.89eac8p1
+  },
+  { // Entry 584
+    0x1.ef41489fc2fe801a6fc8ae791438eb78p-1,
+    -0x1.81b5eep2
+  },
+  { // Entry 585
+    0x1.ef41489fc2fe801a6fc8ae791438eb78p-1,
+    0x1.81b5eep2
+  },
+  { // Entry 586
+    0x1.be1d849ec649b797320e985d0b82ae85p-1,
+    -0x1.714c26p2
+  },
+  { // Entry 587
+    0x1.be1d849ec649b797320e985d0b82ae85p-1,
+    0x1.714c26p2
+  },
+  { // Entry 588
+    0x1.6fcb8c44bd30dd668148605969b1c161p-1,
+    -0x1.60e25ep2
+  },
+  { // Entry 589
+    0x1.6fcb8c44bd30dd668148605969b1c161p-1,
+    0x1.60e25ep2
+  },
+  { // Entry 590
+    0x1.096ad87c326622c42de34f92814cfa84p-1,
+    -0x1.507896p2
+  },
+  { // Entry 591
+    0x1.096ad87c326622c42de34f92814cfa84p-1,
+    0x1.507896p2
+  },
+  { // Entry 592
+    0x1.235b746a2a2eff2bf640dd8c04d35a5bp-2,
+    -0x1.400ecep2
+  },
+  { // Entry 593
+    0x1.235b746a2a2eff2bf640dd8c04d35a5bp-2,
+    0x1.400ecep2
+  },
+  { // Entry 594
+    0x1.0693827b46cee3b661ac17114b5fe0fbp-5,
+    -0x1.2fa506p2
+  },
+  { // Entry 595
+    0x1.0693827b46cee3b661ac17114b5fe0fbp-5,
+    0x1.2fa506p2
+  },
+  { // Entry 596
+    -0x1.c7b85d668e2abcc46542ca8527f0b801p-3,
+    -0x1.1f3b3ep2
+  },
+  { // Entry 597
+    -0x1.c7b85d668e2abcc46542ca8527f0b801p-3,
+    0x1.1f3b3ep2
+  },
+  { // Entry 598
+    -0x1.d9a348d4f4363ba4562110db01ee84e8p-2,
+    -0x1.0ed176p2
+  },
+  { // Entry 599
+    -0x1.d9a348d4f4363ba4562110db01ee84e8p-2,
+    0x1.0ed176p2
+  },
+  { // Entry 600
+    -0x1.5837ae8569c95846e6164d9636546120p-1,
+    -0x1.fccf5ap1
+  },
+  { // Entry 601
+    -0x1.5837ae8569c95846e6164d9636546120p-1,
+    0x1.fccf5ap1
+  },
+  { // Entry 602
+    -0x1.ad19c918883000b0b702ec080cf0122ep-1,
+    -0x1.dbfbc8p1
+  },
+  { // Entry 603
+    -0x1.ad19c918883000b0b702ec080cf0122ep-1,
+    0x1.dbfbc8p1
+  },
+  { // Entry 604
+    -0x1.e5ea94b2cf07add3d0d95ab3a30ad4abp-1,
+    -0x1.bb2836p1
+  },
+  { // Entry 605
+    -0x1.e5ea94b2cf07add3d0d95ab3a30ad4abp-1,
+    0x1.bb2836p1
+  },
+  { // Entry 606
+    -0x1.fef2b02908559f92de892d240a2b0b49p-1,
+    -0x1.9a54a4p1
+  },
+  { // Entry 607
+    -0x1.fef2b02908559f92de892d240a2b0b49p-1,
+    0x1.9a54a4p1
+  },
+  { // Entry 608
+    -0x1.f68ef3792e592c3cefbce1d5ded64a92p-1,
+    -0x1.798112p1
+  },
+  { // Entry 609
+    -0x1.f68ef3792e592c3cefbce1d5ded64a92p-1,
+    0x1.798112p1
+  },
+  { // Entry 610
+    -0x1.cd4bda943eea13630f8e508f8744f2f2p-1,
+    -0x1.58ad80p1
+  },
+  { // Entry 611
+    -0x1.cd4bda943eea13630f8e508f8744f2f2p-1,
+    0x1.58ad80p1
+  },
+  { // Entry 612
+    -0x1.85dc54f49f324bdfc71d5749483b3318p-1,
+    -0x1.37d9eep1
+  },
+  { // Entry 613
+    -0x1.85dc54f49f324bdfc71d5749483b3318p-1,
+    0x1.37d9eep1
+  },
+  { // Entry 614
+    -0x1.24ec93e04d4bdb54e20beaf383519af8p-1,
+    -0x1.17065cp1
+  },
+  { // Entry 615
+    -0x1.24ec93e04d4bdb54e20beaf383519af8p-1,
+    0x1.17065cp1
+  },
+  { // Entry 616
+    -0x1.61a7983d4c16c451b68bf2f5b70f3b6ap-2,
+    -0x1.ec6594p0
+  },
+  { // Entry 617
+    -0x1.61a7983d4c16c451b68bf2f5b70f3b6ap-2,
+    0x1.ec6594p0
+  },
+  { // Entry 618
+    -0x1.89504a8de6c9ecac663e67583cab47e8p-4,
+    -0x1.aabe70p0
+  },
+  { // Entry 619
+    -0x1.89504a8de6c9ecac663e67583cab47e8p-4,
+    0x1.aabe70p0
+  },
+  { // Entry 620
+    0x1.46dbec9ea3a5f08ba73aa69e7e22de1cp-3,
+    -0x1.69174cp0
+  },
+  { // Entry 621
+    0x1.46dbec9ea3a5f08ba73aa69e7e22de1cp-3,
+    0x1.69174cp0
+  },
+  { // Entry 622
+    0x1.9e7f5cf075d1ec4ef69c9c67b62c27cbp-2,
+    -0x1.277028p0
+  },
+  { // Entry 623
+    0x1.9e7f5cf075d1ec4ef69c9c67b62c27cbp-2,
+    0x1.277028p0
+  },
+  { // Entry 624
+    0x1.3f39fcc017653d2636837a55fdf6d2d4p-1,
+    -0x1.cb920ap-1
+  },
+  { // Entry 625
+    0x1.3f39fcc017653d2636837a55fdf6d2d4p-1,
+    0x1.cb920ap-1
+  },
+  { // Entry 626
+    0x1.9a52d5c700daa3dc8cf8f5a71f2df289p-1,
+    -0x1.4843c4p-1
+  },
+  { // Entry 627
+    0x1.9a52d5c700daa3dc8cf8f5a71f2df289p-1,
+    0x1.4843c4p-1
+  },
+  { // Entry 628
+    0x1.da94cd383dd7a3b91a2fc88ff905a6a0p-1,
+    -0x1.89eafcp-2
+  },
+  { // Entry 629
+    0x1.da94cd383dd7a3b91a2fc88ff905a6a0p-1,
+    0x1.89eafcp-2
+  },
+  { // Entry 630
+    0x1.fbcbe3de58e66c3283bc810d16c45833p-1,
+    -0x1.069ce0p-3
+  },
+  { // Entry 631
+    0x1.fbcbe3de58e66c3283bc810d16c45833p-1,
+    0x1.069ce0p-3
+  },
+  { // Entry 632
+    0x1.fbcbe93d48563d51b6e9d6efdb62495cp-1,
+    0x1.069c38p-3
+  },
+  { // Entry 633
+    0x1.fbcbe93d48563d51b6e9d6efdb62495cp-1,
+    -0x1.069c38p-3
+  },
+  { // Entry 634
+    0x1.da94dcfb1cd15853ce848ffb0264ad08p-1,
+    0x1.89eaa8p-2
+  },
+  { // Entry 635
+    0x1.da94dcfb1cd15853ce848ffb0264ad08p-1,
+    -0x1.89eaa8p-2
+  },
+  { // Entry 636
+    0x1.9a52eee5e35377d554ace881bdc4725bp-1,
+    0x1.48439ap-1
+  },
+  { // Entry 637
+    0x1.9a52eee5e35377d554ace881bdc4725bp-1,
+    -0x1.48439ap-1
+  },
+  { // Entry 638
+    0x1.3f3a1d9657ff6aa498c46f6faaf03b90p-1,
+    0x1.cb91e0p-1
+  },
+  { // Entry 639
+    0x1.3f3a1d9657ff6aa498c46f6faaf03b90p-1,
+    -0x1.cb91e0p-1
+  },
+  { // Entry 640
+    0x1.9e7fa617a1a3a400a7f59aa879088e31p-2,
+    0x1.277014p0
+  },
+  { // Entry 641
+    0x1.9e7fa617a1a3a400a7f59aa879088e31p-2,
+    -0x1.277014p0
+  },
+  { // Entry 642
+    0x1.46dc8a919b27840cda6e18a079da459cp-3,
+    0x1.691738p0
+  },
+  { // Entry 643
+    0x1.46dc8a919b27840cda6e18a079da459cp-3,
+    -0x1.691738p0
+  },
+  { // Entry 644
+    -0x1.894f0c0872415663b7f9e4e4801deaf0p-4,
+    0x1.aabe5cp0
+  },
+  { // Entry 645
+    -0x1.894f0c0872415663b7f9e4e4801deaf0p-4,
+    -0x1.aabe5cp0
+  },
+  { // Entry 646
+    -0x1.61a74d29774ae4e3bc5533a2ea08a14ap-2,
+    0x1.ec6580p0
+  },
+  { // Entry 647
+    -0x1.61a74d29774ae4e3bc5533a2ea08a14ap-2,
+    -0x1.ec6580p0
+  },
+  { // Entry 648
+    -0x1.24ec7311bd7b2255f9b890b3ff5899f4p-1,
+    0x1.170652p1
+  },
+  { // Entry 649
+    -0x1.24ec7311bd7b2255f9b890b3ff5899f4p-1,
+    -0x1.170652p1
+  },
+  { // Entry 650
+    -0x1.85dc3b06c435f524c873d9b5eba3def8p-1,
+    0x1.37d9e4p1
+  },
+  { // Entry 651
+    -0x1.85dc3b06c435f524c873d9b5eba3def8p-1,
+    -0x1.37d9e4p1
+  },
+  { // Entry 652
+    -0x1.cd4bc93947e86671ac7f0eacd9521377p-1,
+    0x1.58ad76p1
+  },
+  { // Entry 653
+    -0x1.cd4bc93947e86671ac7f0eacd9521377p-1,
+    -0x1.58ad76p1
+  },
+  { // Entry 654
+    -0x1.f68eebd3b8f12f9433e6d7224989c10ep-1,
+    0x1.798108p1
+  },
+  { // Entry 655
+    -0x1.f68eebd3b8f12f9433e6d7224989c10ep-1,
+    -0x1.798108p1
+  },
+  { // Entry 656
+    -0x1.fef2b2b91e40021a2fee74fc61812157p-1,
+    0x1.9a549ap1
+  },
+  { // Entry 657
+    -0x1.fef2b2b91e40021a2fee74fc61812157p-1,
+    -0x1.9a549ap1
+  },
+  { // Entry 658
+    -0x1.e5eaa14d86168b69918c22f3716a67eap-1,
+    0x1.bb282cp1
+  },
+  { // Entry 659
+    -0x1.e5eaa14d86168b69918c22f3716a67eap-1,
+    -0x1.bb282cp1
+  },
+  { // Entry 660
+    -0x1.ad19deead0eae2f72d04165e09e4a43dp-1,
+    0x1.dbfbbep1
+  },
+  { // Entry 661
+    -0x1.ad19deead0eae2f72d04165e09e4a43dp-1,
+    -0x1.dbfbbep1
+  },
+  { // Entry 662
+    -0x1.5837cc21dda44f3ab7fd96f57c014e19p-1,
+    0x1.fccf50p1
+  },
+  { // Entry 663
+    -0x1.5837cc21dda44f3ab7fd96f57c014e19p-1,
+    -0x1.fccf50p1
+  },
+  { // Entry 664
+    -0x1.d9a39df207139f99ebe9b56dafb234b7p-2,
+    0x1.0ed170p2
+  },
+  { // Entry 665
+    -0x1.d9a39df207139f99ebe9b56dafb234b7p-2,
+    -0x1.0ed170p2
+  },
+  { // Entry 666
+    -0x1.c7b9189638128bc0ae33fdf2729cc987p-3,
+    0x1.1f3b38p2
+  },
+  { // Entry 667
+    -0x1.c7b9189638128bc0ae33fdf2729cc987p-3,
+    -0x1.1f3b38p2
+  },
+  { // Entry 668
+    0x1.069082e04b25e9d2ea9e263b50d08b34p-5,
+    0x1.2fa5p2
+  },
+  { // Entry 669
+    0x1.069082e04b25e9d2ea9e263b50d08b34p-5,
+    -0x1.2fa5p2
+  },
+  { // Entry 670
+    0x1.235b1861f21aa86dce259e4e5b4ef395p-2,
+    0x1.400ec8p2
+  },
+  { // Entry 671
+    0x1.235b1861f21aa86dce259e4e5b4ef395p-2,
+    -0x1.400ec8p2
+  },
+  { // Entry 672
+    0x1.096aaf70341485062f443c80a90a3be3p-1,
+    0x1.507890p2
+  },
+  { // Entry 673
+    0x1.096aaf70341485062f443c80a90a3be3p-1,
+    -0x1.507890p2
+  },
+  { // Entry 674
+    0x1.6fcb6ae03107be458d07361371efabb4p-1,
+    0x1.60e258p2
+  },
+  { // Entry 675
+    0x1.6fcb6ae03107be458d07361371efabb4p-1,
+    -0x1.60e258p2
+  },
+  { // Entry 676
+    0x1.be1d6d10d5c8ceeb8bf9aeb7a9f690b9p-1,
+    0x1.714c20p2
+  },
+  { // Entry 677
+    0x1.be1d6d10d5c8ceeb8bf9aeb7a9f690b9p-1,
+    -0x1.714c20p2
+  },
+  { // Entry 678
+    0x1.ef413c72d988bb53937975e4fd4fcc7ap-1,
+    0x1.81b5e8p2
+  },
+  { // Entry 679
+    0x1.ef413c72d988bb53937975e4fd4fcc7ap-1,
+    -0x1.81b5e8p2
+  },
+  { // Entry 680
+    0x1.ff0fd2cb5a9228cfa1e01605d0626c84p-1,
+    0x1.effffep-5
+  },
+  { // Entry 681
+    0x1.ff0fd2cb5a9228cfa1e01605d0626c84p-1,
+    -0x1.effffep-5
+  },
+  { // Entry 682
+    0x1.ff0fd2c96adfbad5f904a71b2d210a2ap-1,
+    0x1.f0p-5
+  },
+  { // Entry 683
+    0x1.ff0fd2c96adfbad5f904a71b2d210a2ap-1,
+    -0x1.f0p-5
+  },
+  { // Entry 684
+    0x1.ff0fd2c77b2d4add40566ec5aa24fc6ep-1,
+    0x1.f00002p-5
+  },
+  { // Entry 685
+    0x1.ff0fd2c77b2d4add40566ec5aa24fc6ep-1,
+    -0x1.f00002p-5
+  },
+  { // Entry 686
+    0x1.fc21005d216a89de55b192096fc6b7bap-1,
+    0x1.f7fffep-4
+  },
+  { // Entry 687
+    0x1.fc21005d216a89de55b192096fc6b7bap-1,
+    -0x1.f7fffep-4
+  },
+  { // Entry 688
+    0x1.fc210055467fe58a20193399b3bc0dd2p-1,
+    0x1.f8p-4
+  },
+  { // Entry 689
+    0x1.fc210055467fe58a20193399b3bc0dd2p-1,
+    -0x1.f8p-4
+  },
+  { // Entry 690
+    0x1.fc21004d6b953945667f800ff81de0ebp-1,
+    0x1.f80002p-4
+  },
+  { // Entry 691
+    0x1.fc21004d6b953945667f800ff81de0ebp-1,
+    -0x1.f80002p-4
+  },
+  { // Entry 692
+    0x1.f94984c6fdf1be6168509ff1e35f62dep-1,
+    0x1.4bfffep-3
+  },
+  { // Entry 693
+    0x1.f94984c6fdf1be6168509ff1e35f62dep-1,
+    -0x1.4bfffep-3
+  },
+  { // Entry 694
+    0x1.f94984b2552e1941ec766c6a82ece4a3p-1,
+    0x1.4cp-3
+  },
+  { // Entry 695
+    0x1.f94984b2552e1941ec766c6a82ece4a3p-1,
+    -0x1.4cp-3
+  },
+  { // Entry 696
+    0x1.f949849dac6a548dd851139041106316p-1,
+    0x1.4c0002p-3
+  },
+  { // Entry 697
+    0x1.f949849dac6a548dd851139041106316p-1,
+    -0x1.4c0002p-3
+  },
+  { // Entry 698
+    0x1.e921dd7054ef5d4f727d938ce10a053cp-1,
+    0x1.333332p-2
+  },
+  { // Entry 699
+    0x1.e921dd7054ef5d4f727d938ce10a053cp-1,
+    -0x1.333332p-2
+  },
+  { // Entry 700
+    0x1.e921dd24adb9129efc053f9acd4d2444p-1,
+    0x1.333334p-2
+  },
+  { // Entry 701
+    0x1.e921dd24adb9129efc053f9acd4d2444p-1,
+    -0x1.333334p-2
+  },
+  { // Entry 702
+    0x1.e921dcd906824da60e43c03a7774b171p-1,
+    0x1.333336p-2
+  },
+  { // Entry 703
+    0x1.e921dcd906824da60e43c03a7774b171p-1,
+    -0x1.333336p-2
+  },
+  { // Entry 704
+    0x1.8feedc92764bfbdcb41389e82063ed6ep-1,
+    0x1.594316p-1
+  },
+  { // Entry 705
+    0x1.8feedc92764bfbdcb41389e82063ed6ep-1,
+    -0x1.594316p-1
+  },
+  { // Entry 706
+    0x1.8feedb52c750087c5f8727e0279e5f66p-1,
+    0x1.594318p-1
+  },
+  { // Entry 707
+    0x1.8feedb52c750087c5f8727e0279e5f66p-1,
+    -0x1.594318p-1
+  },
+  { // Entry 708
+    0x1.8feeda131852852d2fa7fe8847b05973p-1,
+    0x1.59431ap-1
+  },
+  { // Entry 709
+    0x1.8feeda131852852d2fa7fe8847b05973p-1,
+    -0x1.59431ap-1
+  },
+  { // Entry 710
+    0x1.6b8991127859fd9b43ca1d08b92aa401p-1,
+    0x1.8ffffep-1
+  },
+  { // Entry 711
+    0x1.6b8991127859fd9b43ca1d08b92aa401p-1,
+    -0x1.8ffffep-1
+  },
+  { // Entry 712
+    0x1.6b898fa9efb5d22b58f0d99e9634931ap-1,
+    0x1.90p-1
+  },
+  { // Entry 713
+    0x1.6b898fa9efb5d22b58f0d99e9634931ap-1,
+    -0x1.90p-1
+  },
+  { // Entry 714
+    0x1.6b898e4167103b31de6da67ebf5e9fe6p-1,
+    0x1.900002p-1
+  },
+  { // Entry 715
+    0x1.6b898e4167103b31de6da67ebf5e9fe6p-1,
+    -0x1.900002p-1
+  },
+  { // Entry 716
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149
+  },
+  { // Entry 717
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149
+  },
+  { // Entry 718
+    0x1.p0,
+    0.0
+  },
+  { // Entry 719
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149
+  },
+  { // Entry 720
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149
+  },
+  { // Entry 721
+    0x1.ff621e38956a3b3be920256ddb6034cdp-1,
+    0x1.921fb4p-5
+  },
+  { // Entry 722
+    0x1.ff621e38956a3b3be920256ddb6034cdp-1,
+    -0x1.921fb4p-5
+  },
+  { // Entry 723
+    0x1.ff621e370373dc6f3963d42896ede078p-1,
+    0x1.921fb6p-5
+  },
+  { // Entry 724
+    0x1.ff621e370373dc6f3963d42896ede078p-1,
+    -0x1.921fb6p-5
+  },
+  { // Entry 725
+    0x1.ff621e35717d7ba327894bdfde9f4787p-1,
+    0x1.921fb8p-5
+  },
+  { // Entry 726
+    0x1.ff621e35717d7ba327894bdfde9f4787p-1,
+    -0x1.921fb8p-5
+  },
+  { // Entry 727
+    0x1.fd88da410b61cd55221d9beb996d4d99p-1,
+    0x1.921fb4p-4
+  },
+  { // Entry 728
+    0x1.fd88da410b61cd55221d9beb996d4d99p-1,
+    -0x1.921fb4p-4
+  },
+  { // Entry 729
+    0x1.fd88da3ac5781f5a6fc32e40ed5122b0p-1,
+    0x1.921fb6p-4
+  },
+  { // Entry 730
+    0x1.fd88da3ac5781f5a6fc32e40ed5122b0p-1,
+    -0x1.921fb6p-4
+  },
+  { // Entry 731
+    0x1.fd88da347f8e696999ffd58060ba3569p-1,
+    0x1.921fb8p-4
+  },
+  { // Entry 732
+    0x1.fd88da347f8e696999ffd58060ba3569p-1,
+    -0x1.921fb8p-4
+  },
+  { // Entry 733
+    0x1.f6297d0f4671da580dfecdd4db29f473p-1,
+    0x1.921fb4p-3
+  },
+  { // Entry 734
+    0x1.f6297d0f4671da580dfecdd4db29f473p-1,
+    -0x1.921fb4p-3
+  },
+  { // Entry 735
+    0x1.f6297cf64db9a21d98ab3940fc8a86f0p-1,
+    0x1.921fb6p-3
+  },
+  { // Entry 736
+    0x1.f6297cf64db9a21d98ab3940fc8a86f0p-1,
+    -0x1.921fb6p-3
+  },
+  { // Entry 737
+    0x1.f6297cdd55014a808b883fd183f318acp-1,
+    0x1.921fb8p-3
+  },
+  { // Entry 738
+    0x1.f6297cdd55014a808b883fd183f318acp-1,
+    -0x1.921fb8p-3
+  },
+  { // Entry 739
+    0x1.d906bd313443007dcb0bd4e3d63284c0p-1,
+    0x1.921fb4p-2
+  },
+  { // Entry 740
+    0x1.d906bd313443007dcb0bd4e3d63284c0p-1,
+    -0x1.921fb4p-2
+  },
+  { // Entry 741
+    0x1.d906bccf3cb875874da3da4c01104bafp-1,
+    0x1.921fb6p-2
+  },
+  { // Entry 742
+    0x1.d906bccf3cb875874da3da4c01104bafp-1,
+    -0x1.921fb6p-2
+  },
+  { // Entry 743
+    0x1.d906bc6d452d744f210810861102f2dap-1,
+    0x1.921fb8p-2
+  },
+  { // Entry 744
+    0x1.d906bc6d452d744f210810861102f2dap-1,
+    -0x1.921fb8p-2
+  },
+  { // Entry 745
+    0x1.6a09e74d3d3fbb94d94274f37769f6eap-1,
+    0x1.921fb4p-1
+  },
+  { // Entry 746
+    0x1.6a09e74d3d3fbb94d94274f37769f6eap-1,
+    -0x1.921fb4p-1
+  },
+  { // Entry 747
+    0x1.6a09e5e3335983e5ac92e733e3f24b42p-1,
+    0x1.921fb6p-1
+  },
+  { // Entry 748
+    0x1.6a09e5e3335983e5ac92e733e3f24b42p-1,
+    -0x1.921fb6p-1
+  },
+  { // Entry 749
+    0x1.6a09e4792971e22c9a00261aeac070dap-1,
+    0x1.921fb8p-1
+  },
+  { // Entry 750
+    0x1.6a09e4792971e22c9a00261aeac070dap-1,
+    -0x1.921fb8p-1
+  },
+  { // Entry 751
+    0x1.4442d18469893610281a0f9b0e8d0eefp-24,
+    0x1.921fb4p0
+  },
+  { // Entry 752
+    0x1.4442d18469893610281a0f9b0e8d0eefp-24,
+    -0x1.921fb4p0
+  },
+  { // Entry 753
+    -0x1.777a5cf72cecc4cde3a31e7d5a026142p-25,
+    0x1.921fb6p0
+  },
+  { // Entry 754
+    -0x1.777a5cf72cecc4cde3a31e7d5a026142p-25,
+    -0x1.921fb6p0
+  },
+  { // Entry 755
+    -0x1.5dde973dcb3985f4a8e76a1feca29e1dp-23,
+    0x1.921fb8p0
+  },
+  { // Entry 756
+    -0x1.5dde973dcb3985f4a8e76a1feca29e1dp-23,
+    -0x1.921fb8p0
+  },
+  { // Entry 757
+    -0x1.fffffffffff9951b30e084732e60bb85p-1,
+    0x1.921fb4p1
+  },
+  { // Entry 758
+    -0x1.fffffffffff9951b30e084732e60bb85p-1,
+    -0x1.921fb4p1
+  },
+  { // Entry 759
+    -0x1.fffffffffffdd94849271d08eecf54a1p-1,
+    0x1.921fb6p1
+  },
+  { // Entry 760
+    -0x1.fffffffffffdd94849271d08eecf54a1p-1,
+    -0x1.921fb6p1
+  },
+  { // Entry 761
+    -0x1.ffffffffffe21d75616db5ebc56405f5p-1,
+    0x1.921fb8p1
+  },
+  { // Entry 762
+    -0x1.ffffffffffe21d75616db5ebc56405f5p-1,
+    -0x1.921fb8p1
+  },
+  { // Entry 763
+    0x1.ffffffffffe6546cc38211f5e8deeb97p-1,
+    0x1.921fb4p2
+  },
+  { // Entry 764
+    0x1.ffffffffffe6546cc38211f5e8deeb97p-1,
+    -0x1.921fb4p2
+  },
+  { // Entry 765
+    0x1.fffffffffff76521249c74285bf73c07p-1,
+    0x1.921fb6p2
+  },
+  { // Entry 766
+    0x1.fffffffffff76521249c74285bf73c07p-1,
+    -0x1.921fb6p2
+  },
+  { // Entry 767
+    0x1.ffffffffff8875d585b6db2c31711004p-1,
+    0x1.921fb8p2
+  },
+  { // Entry 768
+    0x1.ffffffffff8875d585b6db2c31711004p-1,
+    -0x1.921fb8p2
+  },
+  { // Entry 769
+    0x1.ffffffffff9951b30e084a6a993b8675p-1,
+    0x1.921fb4p3
+  },
+  { // Entry 770
+    0x1.ffffffffff9951b30e084a6a993b8675p-1,
+    -0x1.921fb4p3
+  },
+  { // Entry 771
+    0x1.ffffffffffdd94849271d0eb7b7b884bp-1,
+    0x1.921fb6p3
+  },
+  { // Entry 772
+    0x1.ffffffffffdd94849271d0eb7b7b884bp-1,
+    -0x1.921fb6p3
+  },
+  { // Entry 773
+    0x1.fffffffffe21d75616dba48283d3c2f7p-1,
+    0x1.921fb8p3
+  },
+  { // Entry 774
+    0x1.fffffffffe21d75616dba48283d3c2f7p-1,
+    -0x1.921fb8p3
+  },
+  { // Entry 775
+    0x1.fffffffffe6546cc382152d9c0eb9b47p-1,
+    0x1.921fb4p4
+  },
+  { // Entry 776
+    0x1.fffffffffe6546cc382152d9c0eb9b47p-1,
+    -0x1.921fb4p4
+  },
+  { // Entry 777
+    0x1.ffffffffff76521249c7484ea7d7a409p-1,
+    0x1.921fb6p4
+  },
+  { // Entry 778
+    0x1.ffffffffff76521249c7484ea7d7a409p-1,
+    -0x1.921fb6p4
+  },
+  { // Entry 779
+    0x1.fffffffff8875d585b720f25f0473943p-1,
+    0x1.921fb8p4
+  },
+  { // Entry 780
+    0x1.fffffffff8875d585b720f25f0473943p-1,
+    -0x1.921fb8p4
+  },
+  { // Entry 781
+    0x1.fffffffff9951b30e087de5cc38683b8p-1,
+    0x1.921fb4p5
+  },
+  { // Entry 782
+    0x1.fffffffff9951b30e087de5cc38683b8p-1,
+    -0x1.921fb4p5
+  },
+  { // Entry 783
+    0x1.fffffffffdd94849271d6b463df6bddfp-1,
+    0x1.921fb6p5
+  },
+  { // Entry 784
+    0x1.fffffffffdd94849271d6b463df6bddfp-1,
+    -0x1.921fb6p5
+  },
+  { // Entry 785
+    0x1.ffffffffe21d75616e000e55d09f8757p-1,
+    0x1.921fb8p5
+  },
+  { // Entry 786
+    0x1.ffffffffe21d75616e000e55d09f8757p-1,
+    -0x1.921fb8p5
+  },
+  { // Entry 787
+    0x1.ffffffffe6546cc38248a8cf0b9b5795p-1,
+    0x1.921fb4p6
+  },
+  { // Entry 788
+    0x1.ffffffffe6546cc38248a8cf0b9b5795p-1,
+    -0x1.921fb4p6
+  },
+  { // Entry 789
+    0x1.fffffffff76521249c7a4dd2e15dd1c4p-1,
+    0x1.921fb6p6
+  },
+  { // Entry 790
+    0x1.fffffffff76521249c7a4dd2e15dd1c4p-1,
+    -0x1.921fb6p6
+  },
+  { // Entry 791
+    0x1.ffffffff8875d585bb7d55383a9b39a4p-1,
+    0x1.921fb8p6
+  },
+  { // Entry 792
+    0x1.ffffffff8875d585bb7d55383a9b39a4p-1,
+    -0x1.921fb8p6
+  },
+  { // Entry 793
+    0x1.ffffffff9951b30e0bb598fc0679a6f7p-1,
+    0x1.921fb4p7
+  },
+  { // Entry 794
+    0x1.ffffffff9951b30e0bb598fc0679a6f7p-1,
+    -0x1.921fb4p7
+  },
+  { // Entry 795
+    0x1.ffffffffdd948492723342ea1da49bacp-1,
+    0x1.921fb6p7
+  },
+  { // Entry 796
+    0x1.ffffffffdd948492723342ea1da49bacp-1,
+    -0x1.921fb6p7
+  },
+  { // Entry 797
+    0x1.fffffffe21d7561725c712f068fc9718p-1,
+    0x1.921fb8p7
+  },
+  { // Entry 798
+    0x1.fffffffe21d7561725c712f068fc9718p-1,
+    -0x1.921fb8p7
+  },
+  { // Entry 799
+    -0x1.6a09db3bdba0868a31e766359a8406cap-1,
+    0x1.2d97c4p1
+  },
+  { // Entry 800
+    -0x1.6a09db3bdba0868a31e766359a8406cap-1,
+    -0x1.2d97c4p1
+  },
+  { // Entry 801
+    -0x1.6a09e0e4035b86694c16534e42fbe111p-1,
+    0x1.2d97c6p1
+  },
+  { // Entry 802
+    -0x1.6a09e0e4035b86694c16534e42fbe111p-1,
+    -0x1.2d97c6p1
+  },
+  { // Entry 803
+    -0x1.6a09e68c2affe5aa58050accb05c6248p-1,
+    0x1.2d97c8p1
+  },
+  { // Entry 804
+    -0x1.6a09e68c2affe5aa58050accb05c6248p-1,
+    -0x1.2d97c8p1
+  },
+  { // Entry 805
+    -0x1.6a09edb67706e0997121d12a0c87bae8p-1,
+    0x1.f6a7a0p1
+  },
+  { // Entry 806
+    -0x1.6a09edb67706e0997121d12a0c87bae8p-1,
+    -0x1.f6a7a0p1
+  },
+  { // Entry 807
+    -0x1.6a09e80e4f7f2a88debed37faa93e8c8p-1,
+    0x1.f6a7a2p1
+  },
+  { // Entry 808
+    -0x1.6a09e80e4f7f2a88debed37faa93e8c8p-1,
+    -0x1.f6a7a2p1
+  },
+  { // Entry 809
+    -0x1.6a09e26627e0d3d9cb76de00cb902becp-1,
+    0x1.f6a7a4p1
+  },
+  { // Entry 810
+    -0x1.6a09e26627e0d3d9cb76de00cb902becp-1,
+    -0x1.f6a7a4p1
+  },
+  { // Entry 811
+    -0x1.f9990e91a74168b90bd68dfab775c9cap-21,
+    0x1.2d97c4p2
+  },
+  { // Entry 812
+    -0x1.f9990e91a74168b90bd68dfab775c9cap-21,
+    -0x1.2d97c4p2
+  },
+  { // Entry 813
+    -0x1.f3321d234f1363d187dd09528b67b215p-22,
+    0x1.2d97c6p2
+  },
+  { // Entry 814
+    -0x1.f3321d234f1363d187dd09528b67b215p-22,
+    -0x1.2d97c6p2
+  },
+  { // Entry 815
+    0x1.99bc5b961b1acaca18d971f68ae99da9p-27,
+    0x1.2d97c8p2
+  },
+  { // Entry 816
+    0x1.99bc5b961b1acaca18d971f68ae99da9p-27,
+    -0x1.2d97c8p2
+  },
+  { // Entry 817
+    0x1.6a09d7a6b572c2c824d137d0405d8188p-1,
+    0x1.5fdbbcp2
+  },
+  { // Entry 818
+    0x1.6a09d7a6b572c2c824d137d0405d8188p-1,
+    -0x1.5fdbbcp2
+  },
+  { // Entry 819
+    0x1.6a09e2f704eecb181e3f5ece9be0ca0fp-1,
+    0x1.5fdbbep2
+  },
+  { // Entry 820
+    0x1.6a09e2f704eecb181e3f5ece9be0ca0fp-1,
+    -0x1.5fdbbep2
+  },
+  { // Entry 821
+    0x1.6a09ee47541050ef59ec4bfce935cc1ap-1,
+    0x1.5fdbc0p2
+  },
+  { // Entry 822
+    0x1.6a09ee47541050ef59ec4bfce935cc1ap-1,
+    -0x1.5fdbc0p2
+  },
+  { // Entry 823
+    0x1.6a09fc9bebaba208c81ec0b1cd307589p-1,
+    0x1.c463a8p2
+  },
+  { // Entry 824
+    0x1.6a09fc9bebaba208c81ec0b1cd307589p-1,
+    -0x1.c463a8p2
+  },
+  { // Entry 825
+    0x1.6a09f14b9cfcc0f6227d386cc3704a05p-1,
+    0x1.c463aap2
+  },
+  { // Entry 826
+    0x1.6a09f14b9cfcc0f6227d386cc3704a05p-1,
+    -0x1.c463aap2
+  },
+  { // Entry 827
+    0x1.6a09e5fb4df35d6729f472da3413e404p-1,
+    0x1.c463acp2
+  },
+  { // Entry 828
+    0x1.6a09e5fb4df35d6729f472da3413e404p-1,
+    -0x1.c463acp2
+  },
+  { // Entry 829
+    0x1.4aa9c2f2c1defb8728f0d2da1217aae1p-21,
+    0x1.f6a7a0p2
+  },
+  { // Entry 830
+    0x1.4aa9c2f2c1defb8728f0d2da1217aae1p-21,
+    -0x1.f6a7a0p2
+  },
+  { // Entry 831
+    0x1.2aa70bcb07d6d0f36b777cb380a845d9p-23,
+    0x1.f6a7a2p2
+  },
+  { // Entry 832
+    0x1.2aa70bcb07d6d0f36b777cb380a845d9p-23,
+    -0x1.f6a7a2p2
+  },
+  { // Entry 833
+    -0x1.6aac7a1a7c0c7afc5fcb2313a7eca229p-22,
+    0x1.f6a7a4p2
+  },
+  { // Entry 834
+    -0x1.6aac7a1a7c0c7afc5fcb2313a7eca229p-22,
+    -0x1.f6a7a4p2
+  },
+  { // Entry 835
+    -0x1.6a09c8c13f48b7aad851f9d6474bcb31p-1,
+    0x1.1475cap3
+  },
+  { // Entry 836
+    -0x1.6a09c8c13f48b7aad851f9d6474bcb31p-1,
+    -0x1.1475cap3
+  },
+  { // Entry 837
+    -0x1.6a09df61ded49d1ee4fca4ba6140d179p-1,
+    0x1.1475ccp3
+  },
+  { // Entry 838
+    -0x1.6a09df61ded49d1ee4fca4ba6140d179p-1,
+    -0x1.1475ccp3
+  },
+  { // Entry 839
+    -0x1.6a09f6027cf678b38fc8992cd9990302p-1,
+    0x1.1475cep3
+  },
+  { // Entry 840
+    -0x1.6a09f6027cf678b38fc8992cd9990302p-1,
+    -0x1.1475cep3
+  },
+  { // Entry 841
+    -0x1.fffffffffc1972c902ef31c37cb54817p-1,
+    0x1.2d97c4p3
+  },
+  { // Entry 842
+    -0x1.fffffffffc1972c902ef31c37cb54817p-1,
+    -0x1.2d97c4p3
+  },
+  { // Entry 843
+    -0x1.ffffffffff0ca4e6263d27a0204389dfp-1,
+    0x1.2d97c6p3
+  },
+  { // Entry 844
+    -0x1.ffffffffff0ca4e6263d27a0204389dfp-1,
+    -0x1.2d97c6p3
+  },
+  { // Entry 845
+    -0x1.ffffffffffffd703498c3b8288563915p-1,
+    0x1.2d97c8p3
+  },
+  { // Entry 846
+    -0x1.ffffffffffffd703498c3b8288563915p-1,
+    -0x1.2d97c8p3
+  },
+  { // Entry 847
+    -0x1.6a0a0b815fb37b2d01551e07cb3009d1p-1,
+    0x1.46b9c0p3
+  },
+  { // Entry 848
+    -0x1.6a0a0b815fb37b2d01551e07cb3009d1p-1,
+    -0x1.46b9c0p3
+  },
+  { // Entry 849
+    -0x1.6a09f4e0c2e98deb78642b6032a73d46p-1,
+    0x1.46b9c2p3
+  },
+  { // Entry 850
+    -0x1.6a09f4e0c2e98deb78642b6032a73d46p-1,
+    -0x1.46b9c2p3
+  },
+  { // Entry 851
+    -0x1.6a09de4024b596b50eb06d562db8c777p-1,
+    0x1.46b9c4p3
+  },
+  { // Entry 852
+    -0x1.6a09de4024b596b50eb06d562db8c777p-1,
+    -0x1.46b9c4p3
+  },
+  { // Entry 853
+    -0x1.4ddd3ba9edcd898b9946fdd20af22a68p-20,
+    0x1.5fdbbcp3
+  },
+  { // Entry 854
+    -0x1.4ddd3ba9edcd898b9946fdd20af22a68p-20,
+    -0x1.5fdbbcp3
+  },
+  { // Entry 855
+    -0x1.3774eea7b8abe8fa8c380142b97af4b6p-22,
+    0x1.5fdbbep3
+  },
+  { // Entry 856
+    -0x1.3774eea7b8abe8fa8c380142b97af4b6p-22,
+    -0x1.5fdbbep3
+  },
+  { // Entry 857
+    0x1.644588ac238ae493fa32435ba51329bfp-21,
+    0x1.5fdbc0p3
+  },
+  { // Entry 858
+    0x1.644588ac238ae493fa32435ba51329bfp-21,
+    -0x1.5fdbc0p3
+  },
+  { // Entry 859
+    0x1.6a09b9dbc881c458e747908caf2aa5e1p-1,
+    0x1.78fdb6p3
+  },
+  { // Entry 860
+    0x1.6a09b9dbc881c458e747908caf2aa5e1p-1,
+    -0x1.78fdb6p3
+  },
+  { // Entry 861
+    0x1.6a09d07c68fc010ffcfd3b19f1ee4f44p-1,
+    0x1.78fdb8p3
+  },
+  { // Entry 862
+    0x1.6a09d07c68fc010ffcfd3b19f1ee4f44p-1,
+    -0x1.78fdb8p3
+  },
+  { // Entry 863
+    0x1.6a09e71d080c33f6964a07d1a0bf5980p-1,
+    0x1.78fdbap3
+  },
+  { // Entry 864
+    0x1.6a09e71d080c33f6964a07d1a0bf5980p-1,
+    -0x1.78fdbap3
+  },
+  { // Entry 865
+    0x1.6a0a03c63742d62802d163d5cfb3b7d5p-1,
+    0x1.ab41aep3
+  },
+  { // Entry 866
+    0x1.6a0a03c63742d62802d163d5cfb3b7d5p-1,
+    -0x1.ab41aep3
+  },
+  { // Entry 867
+    0x1.6a09ed2599fd364c97660cca6652c0a3p-1,
+    0x1.ab41b0p3
+  },
+  { // Entry 868
+    0x1.6a09ed2599fd364c97660cca6652c0a3p-1,
+    -0x1.ab41b0p3
+  },
+  { // Entry 869
+    0x1.6a09d684fb4d8c840660d6b42ec83039p-1,
+    0x1.ab41b2p3
+  },
+  { // Entry 870
+    0x1.6a09d684fb4d8c840660d6b42ec83039p-1,
+    -0x1.ab41b2p3
+  },
+  { // Entry 871
+    0x1.f66595da7a1ae308d26a18de4c2ed3a3p-20,
+    0x1.c463a8p3
+  },
+  { // Entry 872
+    0x1.f66595da7a1ae308d26a18de4c2ed3a3p-20,
+    -0x1.c463a8p3
+  },
+  { // Entry 873
+    0x1.eccb2bb4f66ea861241fa09ca9d8a034p-21,
+    0x1.c463aap3
+  },
+  { // Entry 874
+    0x1.eccb2bb4f66ea861241fa09ca9d8a034p-21,
+    -0x1.c463aap3
+  },
+  { // Entry 875
+    -0x1.334d44b0945407b118b361ab78171f67p-25,
+    0x1.c463acp3
+  },
+  { // Entry 876
+    -0x1.334d44b0945407b118b361ab78171f67p-25,
+    -0x1.c463acp3
+  },
+  { // Entry 877
+    -0x1.6a09c196f2867cc916ae2b7e6c9d99c1p-1,
+    0x1.dd85a4p3
+  },
+  { // Entry 878
+    -0x1.6a09c196f2867cc916ae2b7e6c9d99c1p-1,
+    -0x1.dd85a4p3
+  },
+  { // Entry 879
+    -0x1.6a09d837928506f7cff76f094b4e0377p-1,
+    0x1.dd85a6p3
+  },
+  { // Entry 880
+    -0x1.6a09d837928506f7cff76f094b4e0377p-1,
+    -0x1.dd85a6p3
+  },
+  { // Entry 881
+    -0x1.6a09eed83119874e51ae4bb8aeddc1f2p-1,
+    0x1.dd85a8p3
+  },
+  { // Entry 882
+    -0x1.6a09eed83119874e51ae4bb8aeddc1f2p-1,
+    -0x1.dd85a8p3
+  },
+  { // Entry 883
+    -0x1.fffffffffe54e5e4d32b3453166060b3p-1,
+    0x1.f6a7a0p3
+  },
+  { // Entry 884
+    -0x1.fffffffffe54e5e4d32b3453166060b3p-1,
+    -0x1.f6a7a0p3
+  },
+  { // Entry 885
+    -0x1.ffffffffffea396ab8aee509392c755dp-1,
+    0x1.f6a7a2p3
+  },
+  { // Entry 886
+    -0x1.ffffffffffea396ab8aee509392c755dp-1,
+    -0x1.f6a7a2p3
+  },
+  { // Entry 887
+    -0x1.ffffffffff7f8cf09e32d6309bea85cap-1,
+    0x1.f6a7a4p3
+  },
+  { // Entry 888
+    -0x1.ffffffffff7f8cf09e32d6309bea85cap-1,
+    -0x1.f6a7a4p3
+  },
+  { // Entry 889
+    -0x1.6a0a294c45ec747a47711a4994d2c5e4p-1,
+    0x1.07e4ccp4
+  },
+  { // Entry 890
+    -0x1.6a0a294c45ec747a47711a4994d2c5e4p-1,
+    -0x1.07e4ccp4
+  },
+  { // Entry 891
+    -0x1.6a09fc0b0ea7ed9fb5dd50a0c8af19cbp-1,
+    0x1.07e4cep4
+  },
+  { // Entry 892
+    -0x1.6a09fc0b0ea7ed9fb5dd50a0c8af19cbp-1,
+    -0x1.07e4cep4
+  },
+  { // Entry 893
+    -0x1.6a09cec9d1bb3ed4f810c9f9786d610ep-1,
+    0x1.07e4d0p4
+  },
+  { // Entry 894
+    -0x1.6a09cec9d1bb3ed4f810c9f9786d610ep-1,
+    -0x1.07e4d0p4
+  },
+  { // Entry 895
+    -0x1.4f76f80582c73fc0cc0903ed8ca7d6b3p-19,
+    0x1.1475cap4
+  },
+  { // Entry 896
+    -0x1.4f76f80582c73fc0cc0903ed8ca7d6b3p-19,
+    -0x1.1475cap4
+  },
+  { // Entry 897
+    -0x1.3ddbe0161108b690eed70a7f59de751cp-21,
+    0x1.1475ccp4
+  },
+  { // Entry 898
+    -0x1.3ddbe0161108b690eed70a7f59de751cp-21,
+    -0x1.1475ccp4
+  },
+  { // Entry 899
+    0x1.61120ff4f70180b0d55c3ae0f69585cap-20,
+    0x1.1475cep4
+  },
+  { // Entry 900
+    0x1.61120ff4f70180b0d55c3ae0f69585cap-20,
+    -0x1.1475cep4
+  },
+  { // Entry 901
+    0x1.6a09b2b17b741050a6cfd64b81c76485p-1,
+    0x1.2106c8p4
+  },
+  { // Entry 902
+    0x1.6a09b2b17b741050a6cfd64b81c76485p-1,
+    -0x1.2106c8p4
+  },
+  { // Entry 903
+    0x1.6a09dff2bbe3c9616a3576c55e773207p-1,
+    0x1.2106cap4
+  },
+  { // Entry 904
+    0x1.6a09dff2bbe3c9616a3576c55e773207p-1,
+    -0x1.2106cap4
+  },
+  { // Entry 905
+    0x1.6a0a0d33f6ab5af262ad6ad18ac1ce9fp-1,
+    0x1.2106ccp4
+  },
+  { // Entry 906
+    0x1.6a0a0d33f6ab5af262ad6ad18ac1ce9fp-1,
+    -0x1.2106ccp4
+  },
+  { // Entry 907
+    0x1.fffffffff065cb240bcbfdff4977ddf8p-1,
+    0x1.2d97c4p4
+  },
+  { // Entry 908
+    0x1.fffffffff065cb240bcbfdff4977ddf8p-1,
+    -0x1.2d97c4p4
+  },
+  { // Entry 909
+    0x1.fffffffffc32939898f585d6948cf2d1p-1,
+    0x1.2d97c6p4
+  },
+  { // Entry 910
+    0x1.fffffffffc32939898f585d6948cf2d1p-1,
+    -0x1.2d97c6p4
+  },
+  { // Entry 911
+    0x1.ffffffffffff5c0d2630ee0a27e8d6d1p-1,
+    0x1.2d97c8p4
+  },
+  { // Entry 912
+    0x1.ffffffffffff5c0d2630ee0a27e8d6d1p-1,
+    -0x1.2d97c8p4
+  },
+  { // Entry 913
+    0x1.6a0a3831b81d94966ad8df4d378824f9p-1,
+    0x1.3a28c2p4
+  },
+  { // Entry 914
+    0x1.6a0a3831b81d94966ad8df4d378824f9p-1,
+    -0x1.3a28c2p4
+  },
+  { // Entry 915
+    0x1.6a0a0af082b5bca7f5569f4da6883f64p-1,
+    0x1.3a28c4p4
+  },
+  { // Entry 916
+    0x1.6a0a0af082b5bca7f5569f4da6883f64p-1,
+    -0x1.3a28c4p4
+  },
+  { // Entry 917
+    0x1.6a09ddaf47a5bc8dbdcb6b13844902aep-1,
+    0x1.3a28c6p4
+  },
+  { // Entry 918
+    0x1.6a09ddaf47a5bc8dbdcb6b13844902aep-1,
+    -0x1.3a28c6p4
+  },
+  { // Entry 919
+    0x1.a3bb251dc7efaa1e2137bb37ed6654dbp-19,
+    0x1.46b9c0p4
+  },
+  { // Entry 920
+    0x1.a3bb251dc7efaa1e2137bb37ed6654dbp-19,
+    -0x1.46b9c0p4
+  },
+  { // Entry 921
+    0x1.47764a3b9566758e5baa2e3029f1abbap-20,
+    0x1.46b9c2p4
+  },
+  { // Entry 922
+    0x1.47764a3b9566758e5baa2e3029f1abbap-20,
+    -0x1.46b9c2p4
+  },
+  { // Entry 923
+    -0x1.71136b88d4608490f2ddfe90101112aep-21,
+    0x1.46b9c4p4
+  },
+  { // Entry 924
+    -0x1.71136b88d4608490f2ddfe90101112aep-21,
+    -0x1.46b9c4p4
+  },
+  { // Entry 925
+    -0x1.6a09a3cc03c4bbad2222dfe5be317565p-1,
+    0x1.534abep4
+  },
+  { // Entry 926
+    -0x1.6a09a3cc03c4bbad2222dfe5be317565p-1,
+    -0x1.534abep4
+  },
+  { // Entry 927
+    -0x1.6a09d10d46112335d0e43d738387de8cp-1,
+    0x1.534ac0p4
+  },
+  { // Entry 928
+    -0x1.6a09d10d46112335d0e43d738387de8cp-1,
+    -0x1.534ac0p4
+  },
+  { // Entry 929
+    -0x1.6a09fe4e82b5637a4a8f392c3301be94p-1,
+    0x1.534ac2p4
+  },
+  { // Entry 930
+    -0x1.6a09fe4e82b5637a4a8f392c3301be94p-1,
+    -0x1.534ac2p4
+  },
+  { // Entry 931
+    -0x1.fffffffff9325ace5f682bbb8b122a09p-1,
+    0x1.5fdbbcp4
+  },
+  { // Entry 932
+    -0x1.fffffffff9325ace5f682bbb8b122a09p-1,
+    -0x1.5fdbbcp4
+  },
+  { // Entry 933
+    -0x1.ffffffffffa144abaed5b4aab880635dp-1,
+    0x1.5fdbbep4
+  },
+  { // Entry 934
+    -0x1.ffffffffffa144abaed5b4aab880635dp-1,
+    -0x1.5fdbbep4
+  },
+  { // Entry 935
+    -0x1.fffffffffe102e88fe476331e1ddefafp-1,
+    0x1.5fdbc0p4
+  },
+  { // Entry 936
+    -0x1.fffffffffe102e88fe476331e1ddefafp-1,
+    -0x1.5fdbc0p4
+  },
+  { // Entry 937
+    -0x1.6a0a19d5f626a35ee112a34638e07808p-1,
+    0x1.6c6cbap4
+  },
+  { // Entry 938
+    -0x1.6a0a19d5f626a35ee112a34638e07808p-1,
+    -0x1.6c6cbap4
+  },
+  { // Entry 939
+    -0x1.6a09ec94bcf35208ccd030684d5ddd9cp-1,
+    0x1.6c6cbcp4
+  },
+  { // Entry 940
+    -0x1.6a09ec94bcf35208ccd030684d5ddd9cp-1,
+    -0x1.6c6cbcp4
+  },
+  { // Entry 941
+    -0x1.6a09bf537e17d900659bd2fa24c3a8c8p-1,
+    0x1.6c6cbep4
+  },
+  { // Entry 942
+    -0x1.6a09bf537e17d900659bd2fa24c3a8c8p-1,
+    -0x1.6c6cbep4
+  },
+  { // Entry 943
+    -0x1.f7ff52360c622b3f94d9c7250bfad8d4p-19,
+    0x1.78fdb6p4
+  },
+  { // Entry 944
+    -0x1.f7ff52360c622b3f94d9c7250bfad8d4p-19,
+    -0x1.78fdb6p4
+  },
+  { // Entry 945
+    -0x1.effea46c21baa3da7c266c953a013598p-20,
+    0x1.78fdb8p4
+  },
+  { // Entry 946
+    -0x1.effea46c21baa3da7c266c953a013598p-20,
+    -0x1.78fdb8p4
+  },
+  { // Entry 947
+    0x1.0015b93dd0f095be1eb0a5b87fe5e33ep-24,
+    0x1.78fdbap4
+  },
+  { // Entry 948
+    0x1.0015b93dd0f095be1eb0a5b87fe5e33ep-24,
+    -0x1.78fdbap4
+  },
+  { // Entry 949
+    0x1.6a0994e68b787ee4fd6830b288225745p-1,
+    0x1.858eb4p4
+  },
+  { // Entry 950
+    0x1.6a0994e68b787ee4fd6830b288225745p-1,
+    -0x1.858eb4p4
+  },
+  { // Entry 951
+    0x1.6a09c227cfa194d1fa7ab9909de5083cp-1,
+    0x1.858eb6p4
+  },
+  { // Entry 952
+    0x1.6a09c227cfa194d1fa7ab9909de5083cp-1,
+    -0x1.858eb6p4
+  },
+  { // Entry 953
+    0x1.6a09ef690e2283b658509ed319483839p-1,
+    0x1.858eb8p4
+  },
+  { // Entry 954
+    0x1.6a09ef690e2283b658509ed319483839p-1,
+    -0x1.858eb8p4
+  },
+  { // Entry 955
+    -0x1.f3957bad70e0741f1d3d6751246ce21ap-1,
+    0x1.fffffep62
+  },
+  { // Entry 956
+    -0x1.f3957bad70e0741f1d3d6751246ce21ap-1,
+    -0x1.fffffep62
+  },
+  { // Entry 957
+    0x1.82aa375b3c33e70663731bab4beb6ed3p-7,
+    0x1.p63
+  },
+  { // Entry 958
+    0x1.82aa375b3c33e70663731bab4beb6ed3p-7,
+    -0x1.p63
+  },
+  { // Entry 959
+    0x1.945e6c69a580fb7bb27d02c0fe0f8a71p-2,
+    0x1.000002p63
+  },
+  { // Entry 960
+    0x1.945e6c69a580fb7bb27d02c0fe0f8a71p-2,
+    -0x1.000002p63
+  },
+  { // Entry 961
+    -0x1.b2d255f2bd0423e29e2a548728f034abp-1,
+    0x1.fffffep26
+  },
+  { // Entry 962
+    -0x1.b2d255f2bd0423e29e2a548728f034abp-1,
+    -0x1.fffffep26
+  },
+  { // Entry 963
+    0x1.4ab6511a7d39ad3cc88ded1e775ca147p-1,
+    0x1.p27
+  },
+  { // Entry 964
+    0x1.4ab6511a7d39ad3cc88ded1e775ca147p-1,
+    -0x1.p27
+  },
+  { // Entry 965
+    -0x1.ad3d80c82f4452b076581de24648435bp-1,
+    0x1.000002p27
+  },
+  { // Entry 966
+    -0x1.ad3d80c82f4452b076581de24648435bp-1,
+    -0x1.000002p27
+  },
+  { // Entry 967
+    -0x1.4532c3721ed4343ad88eea8908a988cbp-2,
+    0x1.fffffep23
+  },
+  { // Entry 968
+    -0x1.4532c3721ed4343ad88eea8908a988cbp-2,
+    -0x1.fffffep23
+  },
+  { // Entry 969
+    0x1.40ad67f3f0c9a143963c9c96dbce3f8ap-1,
+    0x1.p24
+  },
+  { // Entry 970
+    0x1.40ad67f3f0c9a143963c9c96dbce3f8ap-1,
+    -0x1.p24
+  },
+  { // Entry 971
+    0x1.caf8537c3e442ca8aca86c156773853ap-2,
+    0x1.000002p24
+  },
+  { // Entry 972
+    0x1.caf8537c3e442ca8aca86c156773853ap-2,
+    -0x1.000002p24
+  },
+  { // Entry 973
+    -0x1.4eaa667ba0b90dfb05ab3d9c247cdee7p-1,
+    0x1.fffffep1
+  },
+  { // Entry 974
+    -0x1.4eaa667ba0b90dfb05ab3d9c247cdee7p-1,
+    -0x1.fffffep1
+  },
+  { // Entry 975
+    -0x1.4eaa606db24c0c466da1c2dc7baa2b32p-1,
+    0x1.p2
+  },
+  { // Entry 976
+    -0x1.4eaa606db24c0c466da1c2dc7baa2b32p-1,
+    -0x1.p2
+  },
+  { // Entry 977
+    -0x1.4eaa5451d53348eb89dc478d4d11be02p-1,
+    0x1.000002p2
+  },
+  { // Entry 978
+    -0x1.4eaa5451d53348eb89dc478d4d11be02p-1,
+    -0x1.000002p2
+  },
+  { // Entry 979
+    -0x1.aa225e2ef96241915b6fd217522814f5p-2,
+    0x1.fffffep0
+  },
+  { // Entry 980
+    -0x1.aa225e2ef96241915b6fd217522814f5p-2,
+    -0x1.fffffep0
+  },
+  { // Entry 981
+    -0x1.aa22657537204a4332f8acbb72b0d768p-2,
+    0x1.p1
+  },
+  { // Entry 982
+    -0x1.aa22657537204a4332f8acbb72b0d768p-2,
+    -0x1.p1
+  },
+  { // Entry 983
+    -0x1.aa227401b288620a0372d5a96084915dp-2,
+    0x1.000002p1
+  },
+  { // Entry 984
+    -0x1.aa227401b288620a0372d5a96084915dp-2,
+    -0x1.000002p1
+  },
+  { // Entry 985
+    0x1.14a282aa25b11f6312a7a65180e7c3d4p-1,
+    0x1.fffffep-1
+  },
+  { // Entry 986
+    0x1.14a282aa25b11f6312a7a65180e7c3d4p-1,
+    -0x1.fffffep-1
+  },
+  { // Entry 987
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    0x1.p0
+  },
+  { // Entry 988
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    -0x1.p0
+  },
+  { // Entry 989
+    0x1.14a27d9da5d4aebce71428f9057b08dap-1,
+    0x1.000002p0
+  },
+  { // Entry 990
+    0x1.14a27d9da5d4aebce71428f9057b08dap-1,
+    -0x1.000002p0
+  },
+  { // Entry 991
+    0x1.c15280e0737692dd436908fdc8e6e2e1p-1,
+    0x1.fffffep-2
+  },
+  { // Entry 992
+    0x1.c15280e0737692dd436908fdc8e6e2e1p-1,
+    -0x1.fffffep-2
+  },
+  { // Entry 993
+    0x1.c1528065b7d4f9db7bbb3b45f5f5b30ap-1,
+    0x1.p-1
+  },
+  { // Entry 994
+    0x1.c1528065b7d4f9db7bbb3b45f5f5b30ap-1,
+    -0x1.p-1
+  },
+  { // Entry 995
+    0x1.c1527f70409076da0c3204df1e099a83p-1,
+    0x1.000002p-1
+  },
+  { // Entry 996
+    0x1.c1527f70409076da0c3204df1e099a83p-1,
+    -0x1.000002p-1
+  },
+  { // Entry 997
+    0x1.f0154a1789d8dcc172cd2092d05f6394p-1,
+    0x1.fffffep-3
+  },
+  { // Entry 998
+    0x1.f0154a1789d8dcc172cd2092d05f6394p-1,
+    -0x1.fffffep-3
+  },
+  { // Entry 999
+    0x1.f01549f7deea174f07a67972bf29f148p-1,
+    0x1.p-2
+  },
+  { // Entry 1000
+    0x1.f01549f7deea174f07a67972bf29f148p-1,
+    -0x1.p-2
+  },
+  { // Entry 1001
+    0x1.f01549b8890c2f66337cac15a7237c8ep-1,
+    0x1.000002p-2
+  },
+  { // Entry 1002
+    0x1.f01549b8890c2f66337cac15a7237c8ep-1,
+    -0x1.000002p-2
+  },
+  { // Entry 1003
+    0x1.fc01552fd068ee83f5b742c05245e8b2p-1,
+    0x1.fffffep-4
+  },
+  { // Entry 1004
+    0x1.fc01552fd068ee83f5b742c05245e8b2p-1,
+    -0x1.fffffep-4
+  },
+  { // Entry 1005
+    0x1.fc015527d5bd36da3cd4253bede319cap-1,
+    0x1.p-3
+  },
+  { // Entry 1006
+    0x1.fc015527d5bd36da3cd4253bede319cap-1,
+    -0x1.p-3
+  },
+  { // Entry 1007
+    0x1.fc015517e065afb6bb102c18f5919820p-1,
+    0x1.000002p-3
+  },
+  { // Entry 1008
+    0x1.fc015517e065afb6bb102c18f5919820p-1,
+    -0x1.000002p-3
+  },
+  { // Entry 1009
+    0x1.ff0015569ef7e2b96301e6f752c019d4p-1,
+    0x1.fffffep-5
+  },
+  { // Entry 1010
+    0x1.ff0015569ef7e2b96301e6f752c019d4p-1,
+    -0x1.fffffep-5
+  },
+  { // Entry 1011
+    0x1.ff0015549f4d34ca0e1ee6509bc42b71p-1,
+    0x1.p-4
+  },
+  { // Entry 1012
+    0x1.ff0015549f4d34ca0e1ee6509bc42b71p-1,
+    -0x1.p-4
+  },
+  { // Entry 1013
+    0x1.ff0015509ff7d2ee6418e924f0de5e97p-1,
+    0x1.000002p-4
+  },
+  { // Entry 1014
+    0x1.ff0015509ff7d2ee6418e924f0de5e97p-1,
+    -0x1.000002p-4
+  },
+  { // Entry 1015
+    0x1.ffc00155d277d58e727cd95c43f759cfp-1,
+    0x1.fffffep-6
+  },
+  { // Entry 1016
+    0x1.ffc00155d277d58e727cd95c43f759cfp-1,
+    -0x1.fffffep-6
+  },
+  { // Entry 1017
+    0x1.ffc00155527d2b12aedb49d92928df72p-1,
+    0x1.p-5
+  },
+  { // Entry 1018
+    0x1.ffc00155527d2b12aedb49d92928df72p-1,
+    -0x1.p-5
+  },
+  { // Entry 1019
+    0x1.ffc001545287d49b57972af5145663a0p-1,
+    0x1.000002p-5
+  },
+  { // Entry 1020
+    0x1.ffc001545287d49b57972af5145663a0p-1,
+    -0x1.000002p-5
+  },
+  { // Entry 1021
+    0x1.fff0001575499f3d7996e2da11cdeb24p-1,
+    0x1.fffffep-7
+  },
+  { // Entry 1022
+    0x1.fff0001575499f3d7996e2da11cdeb24p-1,
+    -0x1.fffffep-7
+  },
+  { // Entry 1023
+    0x1.fff000155549f4a28a280e97bcd59c8ap-1,
+    0x1.p-6
+  },
+  { // Entry 1024
+    0x1.fff000155549f4a28a280e97bcd59c8ap-1,
+    -0x1.p-6
+  },
+  { // Entry 1025
+    0x1.fff00015154a9f0cae4a62151501cd0ap-1,
+    0x1.000002p-6
+  },
+  { // Entry 1026
+    0x1.fff00015154a9f0cae4a62151501cd0ap-1,
+    -0x1.000002p-6
+  },
+  { // Entry 1027
+    0x1.fffffff0000020155544fff49fca38e6p-1,
+    0x1.fffffep-15
+  },
+  { // Entry 1028
+    0x1.fffffff0000020155544fff49fca38e6p-1,
+    -0x1.fffffep-15
+  },
+  { // Entry 1029
+    0x1.fffffff00000001555555549f49f49f7p-1,
+    0x1.p-14
+  },
+  { // Entry 1030
+    0x1.fffffff00000001555555549f49f49f7p-1,
+    -0x1.p-14
+  },
+  { // Entry 1031
+    0x1.ffffffefffffc0155515fff4a1496c1cp-1,
+    0x1.000002p-14
+  },
+  { // Entry 1032
+    0x1.ffffffefffffc0155515fff4a1496c1cp-1,
+    -0x1.000002p-14
+  },
+  { // Entry 1033
+    0x1.fffffffffffffc000007fffffc015555p-1,
+    0x1.fffffep-28
+  },
+  { // Entry 1034
+    0x1.fffffffffffffc000007fffffc015555p-1,
+    -0x1.fffffep-28
+  },
+  { // Entry 1035
+    0x1.fffffffffffffc000000000000015555p-1,
+    0x1.p-27
+  },
+  { // Entry 1036
+    0x1.fffffffffffffc000000000000015555p-1,
+    -0x1.p-27
+  },
+  { // Entry 1037
+    0x1.fffffffffffffbffffeffffff0015555p-1,
+    0x1.000002p-27
+  },
+  { // Entry 1038
+    0x1.fffffffffffffbffffeffffff0015555p-1,
+    -0x1.000002p-27
+  },
+  { // Entry 1039
+    0x1.fffffffffffffff000001ffffff00015p-1,
+    0x1.fffffep-31
+  },
+  { // Entry 1040
+    0x1.fffffffffffffff000001ffffff00015p-1,
+    -0x1.fffffep-31
+  },
+  { // Entry 1041
+    0x1.fffffffffffffff00000000000000015p-1,
+    0x1.p-30
+  },
+  { // Entry 1042
+    0x1.fffffffffffffff00000000000000015p-1,
+    -0x1.p-30
+  },
+  { // Entry 1043
+    0x1.ffffffffffffffefffffbfffffc00015p-1,
+    0x1.000002p-30
+  },
+  { // Entry 1044
+    0x1.ffffffffffffffefffffbfffffc00015p-1,
+    -0x1.000002p-30
+  },
+  { // Entry 1045
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1046
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1047
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1048
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1049
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1050
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1051
+    -0x1.8877a29e3d7b6defcb528e86f4c3e09ap-1,
+    0x1.fffffcp127
+  },
+  { // Entry 1052
+    -0x1.8877a29e3d7b6defcb528e86f4c3e09ap-1,
+    -0x1.fffffcp127
+  },
+  { // Entry 1053
+    -0x1.fffffffffffdd94849271d08eecf54a1p-1,
+    0x1.921fb6p1
+  },
+  { // Entry 1054
+    -0x1.fffffffffffdd94849271d08eecf54a1p-1,
+    -0x1.921fb6p1
+  },
+  { // Entry 1055
+    -0x1.777a5cf72cecc4cde3a31e7d5a026142p-25,
+    0x1.921fb6p0
+  },
+  { // Entry 1056
+    -0x1.777a5cf72cecc4cde3a31e7d5a026142p-25,
+    -0x1.921fb6p0
+  },
+  { // Entry 1057
+    0x1.14a27d9da5d4aebce71428f9057b08dap-1,
+    0x1.000002p0
+  },
+  { // Entry 1058
+    0x1.14a27d9da5d4aebce71428f9057b08dap-1,
+    -0x1.000002p0
+  },
+  { // Entry 1059
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    0x1.p0
+  },
+  { // Entry 1060
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    -0x1.p0
+  },
+  { // Entry 1061
+    0x1.14a282aa25b11f6312a7a65180e7c3d4p-1,
+    0x1.fffffep-1
+  },
+  { // Entry 1062
+    0x1.14a282aa25b11f6312a7a65180e7c3d4p-1,
+    -0x1.fffffep-1
+  },
+  { // Entry 1063
+    0x1.6a09e5e3335983e5ac92e733e3f24b42p-1,
+    0x1.921fb6p-1
+  },
+  { // Entry 1064
+    0x1.6a09e5e3335983e5ac92e733e3f24b42p-1,
+    -0x1.921fb6p-1
+  },
+  { // Entry 1065
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.000002p-126
+  },
+  { // Entry 1066
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.000002p-126
+  },
+  { // Entry 1067
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-126
+  },
+  { // Entry 1068
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-126
+  },
+  { // Entry 1069
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.fffffcp-127
+  },
+  { // Entry 1070
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.fffffcp-127
+  },
+  { // Entry 1071
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.fffff8p-127
+  },
+  { // Entry 1072
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.fffff8p-127
+  },
+  { // Entry 1073
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-148
+  },
+  { // Entry 1074
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-148
+  },
+  { // Entry 1075
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149
+  },
+  { // Entry 1076
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149
+  },
+  { // Entry 1077
+    0x1.p0,
+    0.0f
+  },
+  { // Entry 1078
+    0x1.p0,
+    -0.0f
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_cosf, cosf_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_cosf_intel_data)/sizeof(cosf_intel_data_t); i++) {
+    EXPECT_FLOAT_EQ(g_cosf_intel_data[i].expected, cosf(g_cosf_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_exp_test.cpp b/tests/math_exp_test.cpp
new file mode 100644
index 0000000..beb2584
--- /dev/null
+++ b/tests/math_exp_test.cpp
@@ -0,0 +1,1975 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  double expected;
+  double call_data;
+} exp_intel_data_t;
+
+static exp_intel_data_t g_exp_intel_data[] = {
+  { // Entry 0
+    0x1.0000000000001fffffffffffffffffffp0,
+    0x1.ffffffffffffep-52
+  },
+  { // Entry 1
+    0x1.000000000011ffffffffffffffffffffp0,
+    0x1.1ffffffffff5ep-44
+  },
+  { // Entry 2
+    0x1.000000000207fffffffffffffffffd34p0,
+    0x1.03fffffffef7fp-39
+  },
+  { // Entry 3
+    0x1.00000000c1b59800000000000027a7d5p0,
+    0x1.836b2fff6d6cbp-33
+  },
+  { // Entry 4
+    0x1.000000033d397800000000000002a51dp0,
+    0x1.9e9cbbfd6080bp-31
+  },
+  { // Entry 5
+    0x1.003af6c37c1d3000000000000009446ep0,
+    0x1.d77fd13d27fffp-11
+  },
+  { // Entry 6
+    0x1.016b4df3299d77ffffffffffffe83e10p0,
+    0x1.6a4d1af9cc989p-8
+  },
+  { // Entry 7
+    0x1.0ca4a41663fe07ffffffffffffdab235p0,
+    0x1.8ae823850230bp-5
+  },
+  { // Entry 8
+    0x1.1538ea18a4585000000000000039e054p0,
+    0x1.46370d915991bp-4
+  },
+  { // Entry 9
+    0x1.47408cb9583ce00000000000002c896fp0,
+    0x1.f6e4c3ced7c72p-3
+  },
+  { // Entry 10
+    0x1.27c2e4bc1ee707ffffffffffffeb0c2dp1,
+    0x1.accfbe46b4ef0p-1
+  },
+  { // Entry 11
+    0x1.557d4acd7e5568000000000000202c86p2,
+    0x1.aca7ae8da5a7bp0
+  },
+  { // Entry 12
+    0x1.91a8dff540ff700000000000002f1e33p2,
+    0x1.d6336a88077aap0
+  },
+  { // Entry 13
+    0x1.8ede492d96071fffffffffffff0aecd2p3,
+    0x1.42ee3c7dc4946p1
+  },
+  { // Entry 14
+    0x1.ac50b409c8aee0000000000000022ce3p8,
+    0x1.83d4bcdebb3f4p2
+  },
+  { // Entry 15
+    0x1.f3e558cf4de5400000000000001f5808p-23,
+    -0x1.e8bdbfcd9144ep3
+  },
+  { // Entry 16
+    0x1.951c6dc5d24e27ffffffffffffb6e0c3p-9,
+    -0x1.71e0b869b5e79p2
+  },
+  { // Entry 17
+    0x1.1064b2c103dda80000000000003eb5d7p-3,
+    -0x1.02393d5976769p1
+  },
+  { // Entry 18
+    0x1.3ef1e9b3a81c7fffffffffffffc315p-2,
+    -0x1.2a9cad9998262p0
+  },
+  { // Entry 19
+    0x1.534d4de87071300000000000003c6fb7p-3,
+    -0x1.cc37ef7de7501p0
+  },
+  { // Entry 20
+    0x1.2217147b85ea980000000000007745a3p-1,
+    -0x1.22e24fa3d5cf9p-1
+  },
+  { // Entry 21
+    0x1.9403fd0ee51c800000000000007720f1p-2,
+    -0x1.dc2b5df1f7d3dp-1
+  },
+  { // Entry 22
+    0x1.baded30cbf1c3ffffffffffffffbd904p-1,
+    -0x1.290ea09e36479p-3
+  },
+  { // Entry 23
+    0x1.ffe5d0bb7eabf0000000000000030320p-1,
+    -0x1.a2fefefd580dfp-13
+  },
+  { // Entry 24
+    0x1.ffffff84b39c4fffffffffffffff17f4p-1,
+    -0x1.ed318efb627eap-27
+  },
+  { // Entry 25
+    0x1.fffffffad0ae6800000000000009f1a8p-1,
+    -0x1.4bd46601ae1efp-31
+  },
+  { // Entry 26
+    0x1.ffffffffff7000000000000000000003p-1,
+    -0x1.2000000000288p-42
+  },
+  { // Entry 27
+    0x1.fffffffffffdp-1,
+    -0x1.8000000000012p-48
+  },
+  { // Entry 28
+    0x1.ffffffffffffc0p-1,
+    -0x1.0000000000001p-51
+  },
+  { // Entry 29
+    0x1.0000000000000fffffffffffffffffffp0,
+    0x1.fffffffffffffp-53
+  },
+  { // Entry 30
+    0x1.000000000001ffffffffffffffffffffp0,
+    0x1.fffffffffffe0p-48
+  },
+  { // Entry 31
+    0x1.000000017ffe80000000000000035ffdp0,
+    0x1.7ffe7ffee0024p-32
+  },
+  { // Entry 32
+    0x1.0000000180017ffffffffffffffc9ffdp0,
+    0x1.80017ffedffdcp-32
+  },
+  { // Entry 33
+    0x1.00000075e9f6400000000000000b1e80p0,
+    0x1.d7a7d893609e5p-26
+  },
+  { // Entry 34
+    0x1.0006e83736f8c80000000000000aa0afp0,
+    0x1.ba07d73250de7p-14
+  },
+  { // Entry 35
+    0x1.de7cd6751029a0000000000000e8bb2fp16,
+    0x1.76e7e5d7b6eacp3
+  },
+  { // Entry 36
+    0x1.1d71965f516ad80000000000009f7e97p19,
+    0x1.a8ead058bc6b8p3
+  },
+  { // Entry 37
+    0x1.a8c02e974c314fffffffffffffe21f03p25,
+    0x1.1d5c2daebe367p4
+  },
+  { // Entry 38
+    0x1.b890ca8637ae1fffffffffffffe42161p40,
+    0x1.c44ce0d716a1ap4
+  },
+  { // Entry 39
+    0x1.f03f56a88b5d781c905f6b51c76ae981p-1,
+    -0x1.0000000000001p-5
+  },
+  { // Entry 40
+    0x1.ff003ff556aa87ebb06e0eb57287567fp-1,
+    -0x1.000000000000ap-9
+  },
+  { // Entry 41
+    0x1.8ebef9eac81fc8001a3dbd88248efe13p-1,
+    -0x1.0000000000025p-2
+  },
+  { // Entry 42
+    0x1.fc03fd56a469b800008bcdfe018dbc74p-1,
+    -0x1.0000000171051p-7
+  },
+  { // Entry 43
+    0x1.78b5612dbee010008d3bc0735c80f7a8p-2,
+    -0x1.0000018p0
+  },
+  { // Entry 44
+    0x1.969c870ea9f5a801ddc1ff08a008db09p-93,
+    -0x1.000001e3ep6
+  },
+  { // Entry 45
+    0x1.78af867bc511d321cd454dbddaf806bcp-2,
+    -0x1.0003fc0p0
+  },
+  { // Entry 46
+    0x1.fffffffffefff8000000000400100015p-1,
+    -0x1.00080000004p-41
+  },
+  { // Entry 47
+    0x1.789214093c81d3b65fac659fb3fc8249p-2,
+    -0x1.00180p0
+  },
+  { // Entry 48
+    0x1.8e298e52fcce88014ad95c4f3bd88765p-1,
+    -0x1.018p-2
+  },
+  { // Entry 49
+    0x1.aa6ffb0ba519f801f9c3e146a15dc02cp-24,
+    -0x1.02010p4
+  },
+  { // Entry 50
+    0x1.dd7a46b8d85d67d67359337109c25168p-376,
+    -0x1.040p8
+  },
+  { // Entry 51
+    0x1.33e96ca3bcf3e801f9b3f6126fc60699p-1,
+    -0x1.045b948724130p-1
+  },
+  { // Entry 52
+    0x1.ef2f652dc26057fffc98aa54d4c33c16p-1,
+    -0x1.118e05cfa3e80p-5
+  },
+  { // Entry 53
+    0x1.a5d2ce977bbe28048b316927f970c201p-7,
+    -0x1.169156e17b9b9p2
+  },
+  { // Entry 54
+    0x1.a0207cf4190f700452282b04fa390407p-7,
+    -0x1.17701b3bf0502p2
+  },
+  { // Entry 55
+    0x1.fb97e1ff8cbba7adf16f3fbd6878f560p-1,
+    -0x1.1b4p-7
+  },
+  { // Entry 56
+    0x1.bcff09ae30c46804a6fafd550766eed2p-1,
+    -0x1.1f4p-3
+  },
+  { // Entry 57
+    0x1.fee70cf5e86ef4e54d0b1fa2701a346fp-833,
+    -0x1.2059ad42c3cf7p9
+  },
+  { // Entry 58
+    0x1.7ccd3f33407458011470b3f67197a9c8p-1,
+    -0x1.2f269d2ca38d2p-2
+  },
+  { // Entry 59
+    0x1.09cdb36e977bc7ffffe6d4ddbb18d553p-14,
+    -0x1.3553cf1828b0bp3
+  },
+  { // Entry 60
+    0x1.f9dc5cd546d9b800dc3d95519dc67ee8p-449,
+    -0x1.368ac083128fcp8
+  },
+  { // Entry 61
+    0x1.f1c53c907f6f576e62e401315bafc69ep-15,
+    -0x1.376e8f679ae16p3
+  },
+  { // Entry 62
+    0x1.f24595954e6618028965a9d67edeaf7bp-8,
+    -0x1.3844f67495f7dp2
+  },
+  { // Entry 63
+    0x1.fb56521290a222527d1d3c3638265f46p-905,
+    -0x1.394e9e1b089d7p9
+  },
+  { // Entry 64
+    0x1.dc1658ff6e0707fafd2fd8306c4b1897p-114,
+    -0x1.3997ea51e5271p6
+  },
+  { // Entry 65
+    0x1.ec8b3c090f8b97716a3d38de46d68a1ep-1,
+    -0x1.3d5de560e1906p-5
+  },
+  { // Entry 66
+    0x1.af411bf985220b562909c652c087fef4p-951,
+    -0x1.4954aa552a960p9
+  },
+  { // Entry 67
+    0x1.e1b71d238d5077fe3bea222fcba15608p-957,
+    -0x1.4b5ad6a9ad6adp9
+  },
+  { // Entry 68
+    0x1.cc666a3519ca080f1daef57f92b41d29p-973,
+    -0x1.50ec32686a834p9
+  },
+  { // Entry 69
+    0x1.22462bd5f72b0fffa6085b04427fdf5dp-976,
+    -0x1.52316872b0222p9
+  },
+  { // Entry 70
+    0x1.c1ebc18610301fff2424bc3936260dd2p-981,
+    -0x1.53b4ed3b4ec77p9
+  },
+  { // Entry 71
+    0x1.8d015bcaf9e18b57fdf057239d94f586p-981,
+    -0x1.53c4f13c4f079p9
+  },
+  { // Entry 72
+    0x1.fd5835460ed48c4e14207309a1237f90p-989,
+    -0x1.566ad4a41bec0p9
+  },
+  { // Entry 73
+    0x1.58733fbc088ef7ff38e15f94166c022cp-994,
+    -0x1.585883e7b3b38p9
+  },
+  { // Entry 74
+    0x1.b052090690481802acf0169f62bf32c9p-32,
+    -0x1.5a81ecf68beccp4
+  },
+  { // Entry 75
+    0x1.df6154bc644dac0f9e3a56646948b7c5p-1015,
+    -0x1.5f75629af4eb7p9
+  },
+  { // Entry 76
+    0x1.ff4b0da37083502c114a7ac56ac0498fp-1023,
+    -0x1.6232eb1c432f2p9
+  },
+  { // Entry 77
+    0x1.625edd4c7513e842f27a931c2bbe007cp-1023,
+    -0x1.6261d7dbf48ccp9
+  },
+  { // Entry 78
+    0x1.d572d24973be20006bad92e29bcba984p-1,
+    -0x1.6364b8f747e32p-4
+  },
+  { // Entry 79
+    0x1.ee4dd792245778020250f8981d1a0ad1p-9,
+    -0x1.6524796b40895p2
+  },
+  { // Entry 80
+    0x1.f660c59b294505d8989f85f8ed2a1878p-5,
+    -0x1.6551daae369cep1
+  },
+  { // Entry 81
+    0x1.aa070449efffe9b910657898cdc0ccddp-1037,
+    -0x1.672463f141607p9
+  },
+  { // Entry 82
+    0x1.d4e7fc331b7327ffccf4ee0c59aa7b22p-1,
+    -0x1.6820c99c1dc16p-4
+  },
+  { // Entry 83
+    0x1.fcc448acf476575c66ee396912dbaacdp-528,
+    -0x1.6d4b7e82c3f02p8
+  },
+  { // Entry 84
+    0x1.7fff5a1bffcb2062c9aaa5b07d097255p-529,
+    -0x1.6e44f765fda76p8
+  },
+  { // Entry 85
+    0x1.fa4ecd8ae57187fffffff9910c476c64p-1,
+    -0x1.6e56e725b8304p-7
+  },
+  { // Entry 86
+    0x1.e8d2dafd017ce8032bcb89459464fe7dp-3,
+    -0x1.6ecp0
+  },
+  { // Entry 87
+    0x1.214e34caac9e67139688ad1632dd2055p-1062,
+    -0x1.7p9
+  },
+  { // Entry 88
+    0x1.c87f21775a482a09a44af59c3c3ae44bp-1071,
+    -0x1.72e42p9
+  },
+  { // Entry 89
+    0x1.a349b2329c6777ffce65934b3b6203a7p-273,
+    -0x1.7978bac71121cp7
+  },
+  { // Entry 90
+    0x1.d2a6d5ea995c17ab448132e1e0453805p-1,
+    -0x1.7bde79e0f970cp-4
+  },
+  { // Entry 91
+    0x1.b776dc64c76d197e8c644dc8cb509c4ap-3,
+    -0x1.8a0p0
+  },
+  { // Entry 92
+    0x1.4446fcf7da689802d8c725db8c1145afp-72,
+    -0x1.8d5c84f0bac8cp5
+  },
+  { // Entry 93
+    0x1.e72a0b68bb82b78ce0524d1abb6f7abep-73,
+    -0x1.8fa68b4447230p5
+  },
+  { // Entry 94
+    0x1.fc33d5e1ca6df7d5069b03dc5a683e4fp-75,
+    -0x1.9a671693b946bp5
+  },
+  { // Entry 95
+    0x1.e6981fd6ef79c7fffffcc7201f82fd49p-1,
+    -0x1.a0ec89f897a75p-5
+  },
+  { // Entry 96
+    0x1.f2b9d3b6cf2277a1283f8e00743a0669p-1,
+    -0x1.ae6p-6
+  },
+  { // Entry 97
+    0x1.e5034c8d191bbfff719f2098e33c0577p-1,
+    -0x1.bb9706e2f1bb4p-5
+  },
+  { // Entry 98
+    0x1.f24dc90f9fbeb8028fbcaeebabc7e9fcp-1,
+    -0x1.bc3edad2e1efbp-6
+  },
+  { // Entry 99
+    0x1.71f237d64a6eb46aa154476fd0fc3886p-11,
+    -0x1.d0697edbe0052p2
+  },
+  { // Entry 100
+    0x1.f12c0d3addaa48004b23516d2a113804p-1,
+    -0x1.e18p-6
+  },
+  { // Entry 101
+    0x1.f110dd9073d71800bb4056830b517b08p-1,
+    -0x1.e50p-6
+  },
+  { // Entry 102
+    0x1.f3aa7a860574c2b0783061fe1fd1df2ep-705,
+    -0x1.e7fffffffffffp8
+  },
+  { // Entry 103
+    0x1.f0f898d55117081fc3b8792205e4e130p-1,
+    -0x1.e82p-6
+  },
+  { // Entry 104
+    0x1.ff814fff18dac854185d019b0f8ead36p-1,
+    -0x1.fafebfafebfb0p-11
+  },
+  { // Entry 105
+    0x1.ffffffff01c0701c46208c5416d943adp-1,
+    -0x1.fc7f1fc7f20p-34
+  },
+  { // Entry 106
+    0x1.7907d4148bd91687a1b50f26e8830775p-2,
+    -0x1.ff8ffffffffffp-1
+  },
+  { // Entry 107
+    0x1.ffffffffffff801c0000000013f900c3p-1,
+    -0x1.ff8ffffffffffp-51
+  },
+  { // Entry 108
+    0x1.e0fbb03a0c27d7e84804cadec377bdf9p-1,
+    -0x1.ffeffffffffffp-5
+  },
+  { // Entry 109
+    0x1.ffffffffff00080000004004000ffff5p-1,
+    -0x1.ffeffffffffffp-42
+  },
+  { // Entry 110
+    0x1.ffffffffff0007fffffffffc00100015p-1,
+    -0x1.fff00000008p-42
+  },
+  { // Entry 111
+    0x1.ffffffffffffffffffffffffe000719ep-1,
+    -0x1.fff8e61eadd48p-101
+  },
+  { // Entry 112
+    0x1.fffffffffc00080000040010000ffd55p-1,
+    -0x1.fffbfffffffffp-40
+  },
+  { // Entry 113
+    0x1.fffffffffc00001c0004001fc7fffe19p-1,
+    -0x1.fffff1fffffffp-40
+  },
+  { // Entry 114
+    0x1.ff800ffeaac008589f9a96af73eaff67p-1,
+    -0x1.ffffffffffda5p-11
+  },
+  { // Entry 115
+    0x1.e355bbaee8d85815e4b476b704d0f4f1p-24,
+    -0x1.fffffffffff7dp3
+  },
+  { // Entry 116
+    0x1.78b56362cef3da984453d1c72c344a31p-2,
+    -0x1.ffffffffffff8p-1
+  },
+  { // Entry 117
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffcp-1023
+  },
+  { // Entry 118
+    0x1.42eb9f39afbac7e5e73c32a21e853f26p-185,
+    -0x1.ffffffffffffep6
+  },
+  { // Entry 119
+    0x1.0000000000000800000000000020p0,
+    0x1.0p-53
+  },
+  { // Entry 120
+    0x1.95e54c5dd42177f53f4d5219df11ca3bp184,
+    0x1.0p7
+  },
+  { // Entry 121
+    0x1.9476504ba885758aa5fa7545e10e8e46p738,
+    0x1.0000000000001p9
+  },
+  { // Entry 122
+    0x1.0100802ab5577802ba424ad46b106a66p0,
+    0x1.0000000000003p-8
+  },
+  { // Entry 123
+    0x1.0000004000000800001caaaab1b55556p0,
+    0x1.0000000000007p-26
+  },
+  { // Entry 124
+    0x1.d8e64b8f26c128517489a490e684d8a8p2,
+    0x1.000000008p1
+  },
+  { // Entry 125
+    0x1.749ea7e015bc1dddfa19fbb3cf8bded4p11,
+    0x1.000000010p3
+  },
+  { // Entry 126
+    0x1.0f2ebd2c65d9a80081ac2e65e8025ab1p23,
+    0x1.000000020p4
+  },
+  { // Entry 127
+    0x1.0f2ec1473afea8081fa4566927a4cfd3p23,
+    0x1.0000004p4
+  },
+  { // Entry 128
+    0x1.0000000001000800000080080020002ap0,
+    0x1.00080p-40
+  },
+  { // Entry 129
+    0x1.00000000008008000000200400200005p0,
+    0x1.001p-41
+  },
+  { // Entry 130
+    0x1.000000000000080080000000002004p0,
+    0x1.001p-53
+  },
+  { // Entry 131
+    0x1.a8bf81a597edd223f2db6ebfe2eb1cc1p184,
+    0x1.00173eab3623ap7
+  },
+  { // Entry 132
+    0x1.75e54175aabb37fff5e5b44ba0f101b7p11,
+    0x1.001c0p3
+  },
+  { // Entry 133
+    0x1.60008fbed6c5280206e79909321d09c8p1,
+    0x1.02f8af8af8affp0
+  },
+  { // Entry 134
+    0x1.04184bb80ff43fffc89c53f1ee04ce04p0,
+    0x1.040p-6
+  },
+  { // Entry 135
+    0x1.00000840002208005d9600c105613e7cp0,
+    0x1.080p-21
+  },
+  { // Entry 136
+    0x1.2338ab9b7432080000000973938bacb0p0,
+    0x1.08000001d0fc8p-3
+  },
+  { // Entry 137
+    0x1.acc91bfa7c54c8036548c968b36e5750p0,
+    0x1.0814419d6a65ap-1
+  },
+  { // Entry 138
+    0x1.a4e4693413b9970755c15633af25f96bp400,
+    0x1.15c18de877563p8
+  },
+  { // Entry 139
+    0x1.000000000000480000000000061fffffp0,
+    0x1.1ffffffffffffp-50
+  },
+  { // Entry 140
+    0x1.eaa521edf1bc28014602191ce618c05fp846,
+    0x1.2586ca9cf411bp9
+  },
+  { // Entry 141
+    0x1.fca9c47016cb17617b275b298cf9f894p26,
+    0x1.2b55c037ebb9dp4
+  },
+  { // Entry 142
+    0x1.fcbb1e5c8d53575abc78726f5cea6f51p26,
+    0x1.2b564bee0a6cap4
+  },
+  { // Entry 143
+    0x1.cc0f9d911f1d1002cf0af382fdf62f02p0,
+    0x1.2c2p-1
+  },
+  { // Entry 144
+    0x1.b68a28b09fe947fdf00104f6d8c24801p6,
+    0x1.2c9e33f794769p2
+  },
+  { // Entry 145
+    0x1.d2e035b1892d6802a9c9e288d8e97c98p0,
+    0x1.33a74ff06fb66p-1
+  },
+  { // Entry 146
+    0x1.6acde844356c921fa99313aa18670593p3,
+    0x1.36cce3c3925p1
+  },
+  { // Entry 147
+    0x1.06dadee28c11c800fb9094435c1de727p7,
+    0x1.38389c48b0fcep2
+  },
+  { // Entry 148
+    0x1.c78f37f07cea6426ed5548b4a31d4ac2p904,
+    0x1.3997381d7d94fp9
+  },
+  { // Entry 149
+    0x1.bfe0c519166c47fe3a4b34e6c34b5ae4p1,
+    0x1.40a339c81cecbp0
+  },
+  { // Entry 150
+    0x1.fbc9c30603087488a3d92265b53c2a65p927,
+    0x1.419dbcc486770p9
+  },
+  { // Entry 151
+    0x1.f1ef9c8a4fdae801b19f8e42eff2c4a8p930,
+    0x1.42a565e456e04p9
+  },
+  { // Entry 152
+    0x1.da134d5a4d1e1800c436544994058ce6p934,
+    0x1.44020100804p9
+  },
+  { // Entry 153
+    0x1.f4ec44194b642801a4afd4c50633e8aap938,
+    0x1.456bf23e02428p9
+  },
+  { // Entry 154
+    0x1.ea91d9533b394801bf3d3ec8f88de568p939,
+    0x1.45c1feef8086cp9
+  },
+  { // Entry 155
+    0x1.cb419b9279b35763d113e6c5db79dc54p943,
+    0x1.471c71c71c71cp9
+  },
+  { // Entry 156
+    0x1.6d14308828321de6fe67a4136f17d1f8p29,
+    0x1.474c9cc44cc25p4
+  },
+  { // Entry 157
+    0x1.c0194b4186e2780120b873d72456ecddp956,
+    0x1.4b9ab17812030p9
+  },
+  { // Entry 158
+    0x1.15c605853476b80008cabc4b207ffd1fp0,
+    0x1.4e59dc7e2b053p-4
+  },
+  { // Entry 159
+    0x1.6dee38735a6d3800d8ec117683275f3ap972,
+    0x1.510c5465d984bp9
+  },
+  { // Entry 160
+    0x1.f1e96be2a52cd777e8cf54184ed7ae48p0,
+    0x1.549b0f5742382p-1
+  },
+  { // Entry 161
+    0x1.f253c5990aad2800004db615b1148476p0,
+    0x1.55085fb86501ap-1
+  },
+  { // Entry 162
+    0x1.279b1c43a26617ff4c7508c35e562b22p993,
+    0x1.58383126e94bfp9
+  },
+  { // Entry 163
+    0x1.6fd5ab59153f32a4a383710a3419f57dp996,
+    0x1.595e5795e592bp9
+  },
+  { // Entry 164
+    0x1.5ecf1876539547ffd612e5c4b715c8adp1004,
+    0x1.5c1e0f0783c10p9
+  },
+  { // Entry 165
+    0x1.f2a3c29fc6d723a63e349bbcd7894a8ap1008,
+    0x1.5dadf5d1e452cp9
+  },
+  { // Entry 166
+    0x1.edcb14879613e80176087c1a76dec97cp1009,
+    0x1.5e056ed40e56ep9
+  },
+  { // Entry 167
+    0x1.fcc7e5ca80b1f75c14d762f846bc1669p0,
+    0x1.5fa97bb4e9060p-1
+  },
+  { // Entry 168
+    0x1.f8b5c987a3d877e18bfcada50f1c54b0p3,
+    0x1.610e47e1325dcp1
+  },
+  { // Entry 169
+    0x1.f1e9d8cf24fcd8025127877a738eb2d1p7,
+    0x1.611b19dcc53e4p2
+  },
+  { // Entry 170
+    0x1.ffc045692e8a039c5622b8219f19c619p1023,
+    0x1.62e41fffffffap9
+  },
+  { // Entry 171
+    0x1.ffc045693009d3d065062f9267dff55ep1023,
+    0x1.62e42p9
+  },
+  { // Entry 172
+    0x1.ffc04569a2fb83679239091df068997ep1023,
+    0x1.62e42000001ccp9
+  },
+  { // Entry 173
+    0x1.fffffffffeb2a1b0e263ac68076ed4e0p1023,
+    0x1.62e42fefa39eap9
+  },
+  { // Entry 174
+    0x1.00000b40003f4800ed4e029b6b65ddb1p0,
+    0x1.680p-21
+  },
+  { // Entry 175
+    0x1.17e62f70bec99801a2936e89b54c5256p8,
+    0x1.689a7dc5921b8p2
+  },
+  { // Entry 176
+    0x1.6daaa1336a31500174ca0be569806fdep264,
+    0x1.6eb1de69ace32p7
+  },
+  { // Entry 177
+    0x1.72a9dadea7498c95a514c01d5403e5d0p0,
+    0x1.7b0p-2
+  },
+  { // Entry 178
+    0x1.1ed3fe64fc539800f9cd34ec4c83d9d1p2,
+    0x1.7fffffffffff9p0
+  },
+  { // Entry 179
+    0x1.000000000000180000000000001fffffp0,
+    0x1.7ffffffffffffp-52
+  },
+  { // Entry 180
+    0x1.fe31152b7ef6b1e0a8b9fec7ecdd85a4p553,
+    0x1.8p8
+  },
+  { // Entry 181
+    0x1.74d77b76d95163226caf84760a346abbp0,
+    0x1.810p-2
+  },
+  { // Entry 182
+    0x1.f0e3e5b6c17c02a799c306dbc1b1a8ecp556,
+    0x1.820d92fc4b42ap8
+  },
+  { // Entry 183
+    0x1.00000000c1b59800000000000027a7d5p0,
+    0x1.836b2fff6d6cbp-33
+  },
+  { // Entry 184
+    0x1.78b69d690db792b574f904d2bb1e9ebep570,
+    0x1.8b7aee631f489p8
+  },
+  { // Entry 185
+    0x1.4dad95877ae078000012827fac891535p144,
+    0x1.905011e0df629p6
+  },
+  { // Entry 186
+    0x1.fcbb8778f61217665a6e6f2119880b29p144,
+    0x1.91fffp6
+  },
+  { // Entry 187
+    0x1.7a5b2771e0a16ce6ecd6de8573c11192p4,
+    0x1.94e54738fb4b7p1
+  },
+  { // Entry 188
+    0x1.7d676a26fe5caccea59b023540bec80fp0,
+    0x1.984p-2
+  },
+  { // Entry 189
+    0x1.698764128a4448010e251b55f37a7b6ep147,
+    0x1.98f381d7db44fp6
+  },
+  { // Entry 190
+    0x1.44e5a752f9e1efffb31481484aa7692ap9,
+    0x1.9e8186b267a28p2
+  },
+  { // Entry 191
+    0x1.8023d298e372f8020ec8cf4a70affa87p0,
+    0x1.9f91c1449c421p-2
+  },
+  { // Entry 192
+    0x1.df9bd06daf8ce7b123df43bb50109938p299,
+    0x1.9fc1f212d70f6p7
+  },
+  { // Entry 193
+    0x1.81a4fbca9dcdb800000ae068bc21c4f5p0,
+    0x1.a392789eafce9p-2
+  },
+  { // Entry 194
+    0x1.825f354ccf6f2fffab7e9eb828fbc67dp0,
+    0x1.a5807ca1392b2p-2
+  },
+  { // Entry 195
+    0x1.3c1e2876834aa7fa46011e98abeadf76p0,
+    0x1.bp-3
+  },
+  { // Entry 196
+    0x1.1c7e1aca53795fff54a5fdf5529261cap0,
+    0x1.b04p-4
+  },
+  { // Entry 197
+    0x1.a2d50b8b2880e801a27a34d1954dab50p331,
+    0x1.cbd917ccad096p7
+  },
+  { // Entry 198
+    0x1.419c8a8da1b79802e20296e5f9279626p1,
+    0x1.d7b677e333d38p-1
+  },
+  { // Entry 199
+    0x1.41d1b8b4649eb8000023f9776da9d645p1,
+    0x1.d80b1a6330bebp-1
+  },
+  { // Entry 200
+    0x1.bf3447921fd397fd6db462cd2fbb39fep10,
+    0x1.df50d9af9e410p2
+  },
+  { // Entry 201
+    0x1.9919794bc86298020a19588552ceae5cp0,
+    0x1.e0081ebc3264ep-2
+  },
+  { // Entry 202
+    0x1.76a62bad715b4800daadb6fc2b6e6166p5,
+    0x1.ec5bb209e5707p1
+  },
+  { // Entry 203
+    0x1.c701554c761aa80eedf2a49ef60e562cp2,
+    0x1.f62p0
+  },
+  { // Entry 204
+    0x1.c3dda3c952b918012fd79fbb8ea38f69p727,
+    0x1.f87c7820d8446p8
+  },
+  { // Entry 205
+    0x1.d28c6097b9d5578835e6cff1b19464cdp2,
+    0x1.fc89dc1aa909cp0
+  },
+  { // Entry 206
+    0x1.4231178c2348f5f77eedb27dc404f616p734,
+    0x1.fcfffffffffffp8
+  },
+  { // Entry 207
+    0x1.04034591911e77ff1834fd70d0bbb4b0p0,
+    0x1.fda6dfe27ffffp-7
+  },
+  { // Entry 208
+    0x1.a5b5691c4b0ef803cab2bad4a2013f14p0,
+    0x1.ff1dd1fffffffp-2
+  },
+  { // Entry 209
+    0x1.0000000000003ff20000000005fc8062p0,
+    0x1.ff8ffffffffffp-51
+  },
+  { // Entry 210
+    0x1.6d4fd9ab47c9200073aa8127a2419ac8p738,
+    0x1.ffe5effffffffp8
+  },
+  { // Entry 211
+    0x1.0000000000fff80000000000001fffaap0,
+    0x1.ffefffffff001p-41
+  },
+  { // Entry 212
+    0x1.74418bce788eb46746b38b578759ecc0p11,
+    0x1.ffeffffffffffp2
+  },
+  { // Entry 213
+    0x1.0000000000fff80000007ff80020002ap0,
+    0x1.fffp-41
+  },
+  { // Entry 214
+    0x1.0000000000fffff200007ff7f200008cp0,
+    0x1.ffffe3fffffffp-41
+  },
+  { // Entry 215
+    0x1.d8e64b8d2185281f984a4e51148dadecp2,
+    0x1.ffffffffe7fffp0
+  },
+  { // Entry 216
+    0x1.p0,
+    0x1.ffffffffffffcp-1023
+  },
+  { // Entry 217
+    0x1.00000000000007ffffffffffff9fffffp0,
+    0x1.ffffffffffffep-54
+  },
+  { // Entry 218
+    0x1.00000000000007ffffffffffffdfffffp0,
+    0x1.fffffffffffffp-54
+  },
+  { // Entry 219
+    0x1.304d6aeca252531475ec9182369ba415p69,
+    0x1.7ffffffffffffp5
+  },
+  { // Entry 220
+    0x1.304d6aeca254b3af4bc5d6293d5f65c7p69,
+    0x1.8p5
+  },
+  { // Entry 221
+    0x1.304d6aeca257144a219f1ad50558d32cp69,
+    0x1.8000000000001p5
+  },
+  { // Entry 222
+    0x1.f8e6c24b558ef174995bcfad495149f5p-76,
+    -0x1.a000000000001p5
+  },
+  { // Entry 223
+    0x1.f8e6c24b5592e3421df27acf1e080144p-76,
+    -0x1.ap5
+  },
+  { // Entry 224
+    0x1.f8e6c24b5596d50fa28925f8d659c1bfp-76,
+    -0x1.9ffffffffffffp5
+  },
+  { // Entry 225
+    0x1.55779b984f395dea36a277b8bee2e64cp115,
+    0x1.3ffffffffffffp6
+  },
+  { // Entry 226
+    0x1.55779b984f3eb3c8a503b4a8e2489d98p115,
+    0x1.4p6
+  },
+  { // Entry 227
+    0x1.55779b984f4409a71364f1ae5d280e69p115,
+    0x1.4000000000001p6
+  },
+  { // Entry 228
+    0x1.07b7112bc1fbc2c0f9c1365330930310p-127,
+    -0x1.6000000000001p6
+  },
+  { // Entry 229
+    0x1.07b7112bc1ffe19d3e703e4a794f7372p-127,
+    -0x1.6p6
+  },
+  { // Entry 230
+    0x1.07b7112bc2040079831f46523d7cf692p-127,
+    -0x1.5ffffffffffffp6
+  },
+  { // Entry 231
+    0x1.40a4b9c27150866176d22f2139d1d40fp923,
+    0x1.3ffffffffffffp9
+  },
+  { // Entry 232
+    0x1.40a4b9c271789af8af205bb34f743337p923,
+    0x1.4p9
+  },
+  { // Entry 233
+    0x1.40a4b9c271a0af8fe76e8d47f7fd9c26p923,
+    0x1.4000000000001p9
+  },
+  { // Entry 234
+    0x1.44a3824e525d56fc3f02f886375ec876p-1016,
+    -0x1.6000000000001p9
+  },
+  { // Entry 235
+    0x1.44a3824e5285eb6c88cd46ba5deb457ap-1016,
+    -0x1.6p9
+  },
+  { // Entry 236
+    0x1.44a3824e52ae7fdcd2979a011280fbc8p-1016,
+    -0x1.5ffffffffffffp9
+  },
+  { // Entry 237
+    0x1.03996528e072b78a332480884c79baf7p75,
+    0x1.9ffffffffffffp5
+  },
+  { // Entry 238
+    0x1.03996528e074bebcfd76416fc2c0eb92p75,
+    0x1.ap5
+  },
+  { // Entry 239
+    0x1.03996528e076c5efc7c8025b476db0d0p75,
+    0x1.a000000000001p5
+  },
+  { // Entry 240
+    0x1.aebabae3a417ee6e7faf9ecfc951040cp-70,
+    -0x1.8000000000001p5
+  },
+  { // Entry 241
+    0x1.aebabae3a41b4be3f576e70303a37932p-70,
+    -0x1.8p5
+  },
+  { // Entry 242
+    0x1.aebabae3a41ea9596b3e2f3cf8e0d9e7p-70,
+    -0x1.7ffffffffffffp5
+  },
+  { // Entry 243
+    0x1.f1056dc7bf1b0fc857b67999f5035273p126,
+    0x1.5ffffffffffffp6
+  },
+  { // Entry 244
+    0x1.f1056dc7bf22d3de0ed57615bc501f8bp126,
+    0x1.6p6
+  },
+  { // Entry 245
+    0x1.f1056dc7bf2a97f3c5f472b093f3c91fp126,
+    0x1.6000000000001p6
+  },
+  { // Entry 246
+    0x1.7fd974d372de49099ee7bf48ae346eaap-116,
+    -0x1.4000000000001p6
+  },
+  { // Entry 247
+    0x1.7fd974d372e4486f72358acdd12690e5p-116,
+    -0x1.4p6
+  },
+  { // Entry 248
+    0x1.7fd974d372ea47d54583566af1b00056p-116,
+    -0x1.3ffffffffffffp6
+  },
+  { // Entry 249
+    0x1.93bf4ec282bd3b36cd2f4011488a8364p1015,
+    0x1.5ffffffffffffp9
+  },
+  { // Entry 250
+    0x1.93bf4ec282efb320a57f9ae02e01ae51p1015,
+    0x1.6p9
+  },
+  { // Entry 251
+    0x1.93bf4ec283222b0a7dcffbfe10b3e34ap1015,
+    0x1.6000000000001p9
+  },
+  { // Entry 252
+    0x1.98c72ca0cab14eda5aca97bee0fdd48fp-924,
+    -0x1.4000000000001p9
+  },
+  { // Entry 253
+    0x1.98c72ca0cae467bfeee3f11a4aa26f77p-924,
+    -0x1.4p9
+  },
+  { // Entry 254
+    0x1.98c72ca0cb1780a582fd50d8d0f98d8bp-924,
+    -0x1.3ffffffffffffp9
+  },
+  { // Entry 255
+    0x1.61013a44a981c910f20f80756007120ap-822,
+    -0x1.1cb90bfbe8e7cp9
+  },
+  { // Entry 256
+    0x1.8087717a7f08a7251210e71d47acc5e3p-905,
+    -0x1.397217f7d1cf8p9
+  },
+  { // Entry 257
+    0x1.a2de59d85452109f34165fa55f9e4e7bp-988,
+    -0x1.562b23f3bab73p9
+  },
+  { // Entry 258
+    0x1.fffffffffffff35793c76730080dfb9bp-2,
+    -0x1.62e42fefa39f0p-1
+  },
+  { // Entry 259
+    0x1.00000000000001abc9e3b39803f45c1cp-1,
+    -0x1.62e42fefa39efp-1
+  },
+  { // Entry 260
+    0x1.00000000000009abc9e3b3980421ba6bp-1,
+    -0x1.62e42fefa39eep-1
+  },
+  { // Entry 261
+    0x1.6a09e667f3bcc48f0965009f2778df91p-1,
+    -0x1.62e42fefa39f0p-2
+  },
+  { // Entry 262
+    0x1.6a09e667f3bcca3730fea06e1a966c06p-1,
+    -0x1.62e42fefa39efp-2
+  },
+  { // Entry 263
+    0x1.6a09e667f3bccfdf5898403d0dca9919p-1,
+    -0x1.62e42fefa39eep-2
+  },
+  { // Entry 264
+    0x1.ae89f995ad3ad33f3c451118e4ad74c5p-1,
+    -0x1.62e42fefa39f0p-3
+  },
+  { // Entry 265
+    0x1.ae89f995ad3ad69c50383c735a575052p-1,
+    -0x1.62e42fefa39efp-3
+  },
+  { // Entry 266
+    0x1.ae89f995ad3ad9f9642b67cdd007e606p-1,
+    -0x1.62e42fefa39eep-3
+  },
+  { // Entry 267
+    0x1.d5818dcfba4870ea30f8974f369eab8cp-1,
+    -0x1.62e42fefa39f0p-4
+  },
+  { // Entry 268
+    0x1.d5818dcfba4872bfb28667097f10807ep-1,
+    -0x1.62e42fefa39efp-4
+  },
+  { // Entry 269
+    0x1.d5818dcfba487495341436c3c7842af1p-1,
+    -0x1.62e42fefa39eep-4
+  },
+  { // Entry 270
+    0x1.ea4afa2a490d9797069887879b7c974ep-1,
+    -0x1.62e42fefa39f0p-5
+  },
+  { // Entry 271
+    0x1.ea4afa2a490d988c2c159cac2248a01bp-1,
+    -0x1.62e42fefa39efp-5
+  },
+  { // Entry 272
+    0x1.ea4afa2a490d99815192b1d0a915237bp-1,
+    -0x1.62e42fefa39eep-5
+  },
+  { // Entry 273
+    0x1.f50765b6e4540611e065c14f105024cep-1,
+    -0x1.62e42fefa39f0p-6
+  },
+  { // Entry 274
+    0x1.f50765b6e454068f223f2f082551b8efp-1,
+    -0x1.62e42fefa39efp-6
+  },
+  { // Entry 275
+    0x1.f50765b6e454070c64189cc13a536c5fp-1,
+    -0x1.62e42fefa39eep-6
+  },
+  { // Entry 276
+    0x1.059b0d315857435f6c51ceeb0a6b46e6p0,
+    0x1.62e42fefa39eep-6
+  },
+  { // Entry 277
+    0x1.059b0d31585743a0d3151b41203c26eep0,
+    0x1.62e42fefa39efp-6
+  },
+  { // Entry 278
+    0x1.059b0d31585743e239d86797360d174fp0,
+    0x1.62e42fefa39f0p-6
+  },
+  { // Entry 279
+    0x1.0b5586cf9890f587f5279294114165a2p0,
+    0x1.62e42fefa39eep-5
+  },
+  { // Entry 280
+    0x1.0b5586cf9890f60d9feafa6059bc4b08p0,
+    0x1.62e42fefa39efp-5
+  },
+  { // Entry 281
+    0x1.0b5586cf9890f6934aae622ca2377342p0,
+    0x1.62e42fefa39f0p-5
+  },
+  { // Entry 282
+    0x1.172b83c7d517ac7c7c0d3432ad543afap0,
+    0x1.62e42fefa39eep-4
+  },
+  { // Entry 283
+    0x1.172b83c7d517ad93a790fc07c501430cp0,
+    0x1.62e42fefa39efp-4
+  },
+  { // Entry 284
+    0x1.172b83c7d517aeaad314c3dcdcaf6249p0,
+    0x1.62e42fefa39f0p-4
+  },
+  { // Entry 285
+    0x1.306fe0a31b714ffe7eec6bebf7ca9d7dp0,
+    0x1.62e42fefa39eep-3
+  },
+  { // Entry 286
+    0x1.306fe0a31b71525f5eadb222da6cfb5ap0,
+    0x1.62e42fefa39efp-3
+  },
+  { // Entry 287
+    0x1.306fe0a31b7154c03e6ef859bd141af7p0,
+    0x1.62e42fefa39f0p-3
+  },
+  { // Entry 288
+    0x1.6a09e667f3bcc2320d5de690c78172aep0,
+    0x1.62e42fefa39eep-2
+  },
+  { // Entry 289
+    0x1.6a09e667f3bcc7da34f7865fba958b33p0,
+    0x1.62e42fefa39efp-2
+  },
+  { // Entry 290
+    0x1.6a09e667f3bccd825c91262eadc04456p0,
+    0x1.62e42fefa39f0p-2
+  },
+  { // Entry 291
+    0x1.ffffffffffffeca86c3898cff8779a1ap0,
+    0x1.62e42fefa39eep-1
+  },
+  { // Entry 292
+    0x1.fffffffffffffca86c3898cff81cdd7cp0,
+    0x1.62e42fefa39efp-1
+  },
+  { // Entry 293
+    0x1.0000000000000654361c4c67fc21106fp1,
+    0x1.62e42fefa39f0p-1
+  },
+  { // Entry 294
+    0x1.ffffffffffffd950d871319ff1aa4328p1,
+    0x1.62e42fefa39eep0
+  },
+  { // Entry 295
+    0x1.fffffffffffff950d871319ff03f50afp1,
+    0x1.62e42fefa39efp0
+  },
+  { // Entry 296
+    0x1.0000000000000ca86c3898cff86a2f1bp2,
+    0x1.62e42fefa39f0p0
+  },
+  { // Entry 297
+    0x1.ffffffffffffb2a1b0e2633fe640c21bp3,
+    0x1.62e42fefa39eep1
+  },
+  { // Entry 298
+    0x1.fffffffffffff2a1b0e2633fe094f837p3,
+    0x1.62e42fefa39efp1
+  },
+  { // Entry 299
+    0x1.0000000000001950d871319ff174972ap4,
+    0x1.62e42fefa39f0p1
+  },
+  { // Entry 300
+    0x1.ffffffffffff654361c4c67fd8327361p7,
+    0x1.62e42fefa39eep2
+  },
+  { // Entry 301
+    0x1.ffffffffffffe54361c4c67fc1834bd3p7,
+    0x1.62e42fefa39efp2
+  },
+  { // Entry 302
+    0x1.00000000000032a1b0e2633fe56a1222p8,
+    0x1.62e42fefa39f0p2
+  },
+  { // Entry 303
+    0x1.fffffffffffeca86c3898cffdf28a36fp15,
+    0x1.62e42fefa39eep3
+  },
+  { // Entry 304
+    0x1.ffffffffffffca86c3898cff846c0534p15,
+    0x1.62e42fefa39efp3
+  },
+  { // Entry 305
+    0x1.000000000000654361c4c67fd4d7b37cp16,
+    0x1.62e42fefa39f0p3
+  },
+  { // Entry 306
+    0x1.fffffffffffd950d87131a007960398fp31,
+    0x1.62e42fefa39eep4
+  },
+  { // Entry 307
+    0x1.ffffffffffff950d871319ff0e6dc0a3p31,
+    0x1.62e42fefa39efp4
+  },
+  { // Entry 308
+    0x1.000000000000ca86c3898cffd1bda3dbp32,
+    0x1.62e42fefa39f0p4
+  },
+  { // Entry 309
+    0x1.ffffffffffb2a1b0e26345b8dfe00697p1023,
+    0x1.62e42fefa39eep9
+  },
+  { // Entry 310
+    0x1.fffffffffff2a1b0e263400d15fc52ffp1023,
+    0x1.62e42fefa39efp9
+  },
+  { // Entry 311
+    HUGE_VAL,
+    0x1.62e42fefa39f0p9
+  },
+  { // Entry 312
+    0x1.c8464f76161962ed1930796c0794254ap-1071,
+    -0x1.72e42fefa39f0p9
+  },
+  { // Entry 313
+    0x1.c8464f7616526bb707f34028f1d63786p-1071,
+    -0x1.72e42fefa39efp9
+  },
+  { // Entry 314
+    0x1.c8464f76168b7480f6b60e06f556221bp-1071,
+    -0x1.72e42fefa39eep9
+  },
+  { // Entry 315
+    0x1.8ebef9eac820a84b86d1ce1a4424435fp-1,
+    -0x1.0000000000001p-2
+  },
+  { // Entry 316
+    0x1.8ebef9eac820ae8682b9793ac6d1e772p-1,
+    -0x1.0p-2
+  },
+  { // Entry 317
+    0x1.8ebef9eac820b1a400ad4ecb083211f6p-1,
+    -0x1.fffffffffffffp-3
+  },
+  { // Entry 318
+    0x1.c3d6a24ed82214f0d01daf8e1a8d2ca7p-1,
+    -0x1.0000000000001p-3
+  },
+  { // Entry 319
+    0x1.c3d6a24ed82218787d624d3e5eba95f5p-1,
+    -0x1.0p-3
+  },
+  { // Entry 320
+    0x1.c3d6a24ed8221a3c54049c1680d3f05ep-1,
+    -0x1.fffffffffffffp-4
+  },
+  { // Entry 321
+    0x1.e0fabfbc702a3b04e86023f0691cc597p-1,
+    -0x1.0000000000001p-4
+  },
+  { // Entry 322
+    0x1.e0fabfbc702a3ce5e31fe0609358bafdp-1,
+    -0x1.0p-4
+  },
+  { // Entry 323
+    0x1.e0fabfbc702a3dd6607fbe98a8776a0ep-1,
+    -0x1.fffffffffffffp-5
+  },
+  { // Entry 324
+    0x1.f03f56a88b5d781c905f6b51c76ae981p-1,
+    -0x1.0000000000001p-5
+  },
+  { // Entry 325
+    0x1.f03f56a88b5d7914b00abf97762735d1p-1,
+    -0x1.0p-5
+  },
+  { // Entry 326
+    0x1.f03f56a88b5d7990bfe069ba4d858a7fp-1,
+    -0x1.fffffffffffffp-6
+  },
+  { // Entry 327
+    0x1.f80feabfeefa48a9cd112d592c437012p-1,
+    -0x1.0000000000001p-6
+  },
+  { // Entry 328
+    0x1.f80feabfeefa4927d10bdd54ead5aa46p-1,
+    -0x1.0p-6
+  },
+  { // Entry 329
+    0x1.f80feabfeefa4966d3093552ca1ed330p-1,
+    -0x1.fffffffffffffp-7
+  },
+  { // Entry 330
+    0x1.fc03fd56aa224f587c3f685d543e53d7p-1,
+    -0x1.0000000000001p-7
+  },
+  { // Entry 331
+    0x1.fc03fd56aa224f97fcbf1332988842dep-1,
+    -0x1.0p-7
+  },
+  { // Entry 332
+    0x1.fc03fd56aa224fb7bcfee89d3aad3d5cp-1,
+    -0x1.fffffffffffffp-8
+  },
+  { // Entry 333
+    0x1.fe00ffaabffbbc51cd0e16d8b005d662p-1,
+    -0x1.0000000000001p-8
+  },
+  { // Entry 334
+    0x1.fe00ffaabffbbc71ad1e1184afc19c7ep-1,
+    -0x1.0p-8
+  },
+  { // Entry 335
+    0x1.fe00ffaabffbbc819d260edaaf9f804bp-1,
+    -0x1.fffffffffffffp-9
+  },
+  { // Entry 336
+    0x1.ff003ff556aa887b68800bb5d27da4ffp-1,
+    -0x1.0000000000001p-9
+  },
+  { // Entry 337
+    0x1.ff003ff556aa888b60820b6087d1e91ap-1,
+    -0x1.0p-9
+  },
+  { // Entry 338
+    0x1.ff003ff556aa88935c830b35e27c0b57p-1,
+    -0x1.fffffffffffffp-10
+  },
+  { // Entry 339
+    0x1.ff800ffeaabffee6fc4efcfc6459de13p-1,
+    -0x1.0000000000001p-10
+  },
+  { // Entry 340
+    0x1.ff800ffeaabffeeefa4f3cf70f59d9bfp-1,
+    -0x1.0p-10
+  },
+  { // Entry 341
+    0x1.ff800ffeaabffef2f94f5cf464d9d7a1p-1,
+    -0x1.fffffffffffffp-11
+  },
+  { // Entry 342
+    0x1.fff0003fff5556a9a8908b40b320849dp-1,
+    -0x1.0000000000001p-13
+  },
+  { // Entry 343
+    0x1.fff0003fff5556aaa8888b60b2cb2ff2p-1,
+    -0x1.0p-13
+  },
+  { // Entry 344
+    0x1.fff0003fff5556ab28848b70b2a0859dp-1,
+    -0x1.fffffffffffffp-14
+  },
+  { // Entry 345
+    0x1.48b5e3c3e81863e50ffc2ecb79f3f7c3p0,
+    0x1.fffffffffffffp-3
+  },
+  { // Entry 346
+    0x1.48b5e3c3e81866767bc3b69baabe534ep0,
+    0x1.0p-2
+  },
+  { // Entry 347
+    0x1.48b5e3c3e8186b995352c63c0c6272ecp0,
+    0x1.0000000000001p-2
+  },
+  { // Entry 348
+    0x1.2216045b6f5cce7ad7642815839c8160p0,
+    0x1.fffffffffffffp-4
+  },
+  { // Entry 349
+    0x1.2216045b6f5ccf9ced688384e06b8d42p0,
+    0x1.0p-3
+  },
+  { // Entry 350
+    0x1.2216045b6f5cd1e119713a639a0d0b49p0,
+    0x1.0000000000001p-3
+  },
+  { // Entry 351
+    0x1.1082b577d34ed74d70455df87e5de089p0,
+    0x1.fffffffffffffp-5
+  },
+  { // Entry 352
+    0x1.1082b577d34ed7d5b1a019e225c9a951p0,
+    0x1.0p-4
+  },
+  { // Entry 353
+    0x1.1082b577d34ed8e6345591b574a20744p0,
+    0x1.0000000000001p-4
+  },
+  { // Entry 354
+    0x1.08205601127ec94c03bb0367085a3c64p0,
+    0x1.fffffffffffffp-6
+  },
+  { // Entry 355
+    0x1.08205601127ec98e0bd083aba80c97a6p0,
+    0x1.0p-5
+  },
+  { // Entry 356
+    0x1.08205601127eca121bfb8434e7717fb0p0,
+    0x1.0000000000001p-5
+  },
+  { // Entry 357
+    0x1.04080ab55de3915a37635d3d47dc3df6p0,
+    0x1.fffffffffffffp-7
+  },
+  { // Entry 358
+    0x1.04080ab55de3917ab864b3e9044e6b45p0,
+    0x1.0p-6
+  },
+  { // Entry 359
+    0x1.04080ab55de391bbba6761407d32d213p0,
+    0x1.0000000000001p-6
+  },
+  { // Entry 360
+    0x1.0202015600445afc12436d5c6f22ecf0p0,
+    0x1.fffffffffffffp-8
+  },
+  { // Entry 361
+    0x1.0202015600445b0c326382bc73689d32p0,
+    0x1.0p-7
+  },
+  { // Entry 362
+    0x1.0202015600445b2c72a3ad7c7bf400bcp0,
+    0x1.0000000000001p-7
+  },
+  { // Entry 363
+    0x1.0100802ab55777ca8226417cbfee2ff3p0,
+    0x1.fffffffffffffp-9
+  },
+  { // Entry 364
+    0x1.0100802ab55777d28a2a42d26aa9ee67p0,
+    0x1.0p-8
+  },
+  { // Entry 365
+    0x1.0100802ab55777e29a32457dc0216c10p0,
+    0x1.0000000000001p-8
+  },
+  { // Entry 366
+    0x1.008020055600110e7b4155a81af484b1p0,
+    0x1.fffffffffffffp-10
+  },
+  { // Entry 367
+    0x1.00802005560011127d41d5bd72f4c8f3p0,
+    0x1.0p-9
+  },
+  { // Entry 368
+    0x1.008020055600111a8142d5e822f551a7p0,
+    0x1.0000000000001p-9
+  },
+  { // Entry 369
+    0x1.00400800aab555dbe30e5ce71927cbf0p0,
+    0x1.fffffffffffffp-11
+  },
+  { // Entry 370
+    0x1.00400800aab555dde38e6ce86e9277aap0,
+    0x1.0p-10
+  },
+  { // Entry 371
+    0x1.00400800aab555e1e48e8ceb1967cf29p0,
+    0x1.0000000000001p-10
+  },
+  { // Entry 372
+    0x1.00080020005555ffc10f1275295d4349p0,
+    0x1.fffffffffffffp-14
+  },
+  { // Entry 373
+    0x1.00080020005556000111127d297298c9p0,
+    0x1.0p-13
+  },
+  { // Entry 374
+    0x1.00080020005556008115128d299d43c9p0,
+    0x1.0000000000001p-13
+  },
+  { // Entry 375
+    0x1.44109edb206a938fad670b68ab99b768p-739,
+    -0x1.0000000000001p9
+  },
+  { // Entry 376
+    0x1.44109edb209315a388cb1b433ecd1a8ap-739,
+    -0x1.0p9
+  },
+  { // Entry 377
+    0x1.44109edb20a756ad767d2516a15514ccp-739,
+    -0x1.fffffffffffffp8
+  },
+  { // Entry 378
+    0x1.9755956ad4d04a606a8cd9ddfb368effp-370,
+    -0x1.0000000000001p8
+  },
+  { // Entry 379
+    0x1.9755956ad4e9bfb9c13a27ae4c07ed37p-370,
+    -0x1.0p8
+  },
+  { // Entry 380
+    0x1.9755956ad4f67a666c90cf2f3488a463p-370,
+    -0x1.fffffffffffffp7
+  },
+  { // Entry 381
+    0x1.42eb9f39afa6992bf3a1379715f6683bp-185,
+    -0x1.0000000000001p7
+  },
+  { // Entry 382
+    0x1.42eb9f39afb0b088ed6eb4f43cc9ec7bp-185,
+    -0x1.0p7
+  },
+  { // Entry 383
+    0x1.42eb9f39afb5bc376a5573c1164a9c03p-185,
+    -0x1.fffffffffffffp6
+  },
+  { // Entry 384
+    0x1.969d47321e46604a105f8de32d9dc685p-93,
+    -0x1.0000000000001p6
+  },
+  { // Entry 385
+    0x1.969d47321e4cbabf2d28070963b04194p-93,
+    -0x1.0p6
+  },
+  { // Entry 386
+    0x1.969d47321e4fe7f9bb8c43a606692a48p-93,
+    -0x1.fffffffffffffp5
+  },
+  { // Entry 387
+    0x1.c8464f761642f155fab3e5bb144fb910p-47,
+    -0x1.0000000000001p5
+  },
+  { // Entry 388
+    0x1.c8464f76164681e299a0124487884d64p-47,
+    -0x1.0p5
+  },
+  { // Entry 389
+    0x1.c8464f7616484a28e916288bed8e0ebfp-47,
+    -0x1.fffffffffffffp4
+  },
+  { // Entry 390
+    0x1.e355bbaee85aca50a3c50ad2ccffbb29p-24,
+    -0x1.0000000000001p4
+  },
+  { // Entry 391
+    0x1.e355bbaee85cada65f73f32e88fb3cc6p-24,
+    -0x1.0p4
+  },
+  { // Entry 392
+    0x1.e355bbaee85d9f513d4b675d1c3923f6p-24,
+    -0x1.fffffffffffffp3
+  },
+  { // Entry 393
+    0x1.5fc21041027a1bdec525f6d2b48a4637p-12,
+    -0x1.0000000000001p3
+  },
+  { // Entry 394
+    0x1.5fc21041027acbbfcd46780fee71ead2p-12,
+    -0x1.0p3
+  },
+  { // Entry 395
+    0x1.5fc21041027b23b05156b8aeac5feea5p-12,
+    -0x1.fffffffffffffp2
+  },
+  { // Entry 396
+    0x1.2c155b8213cefc79340f8e386263456ap-6,
+    -0x1.0000000000001p2
+  },
+  { // Entry 397
+    0x1.2c155b8213cf477e8af0132c2ae23d4ap-6,
+    -0x1.0p2
+  },
+  { // Entry 398
+    0x1.2c155b8213cf6d01366055a6162a395fp-6,
+    -0x1.fffffffffffffp1
+  },
+  { // Entry 399
+    0x1.152aaa3bf81c975862272f0f3b13f586p-3,
+    -0x1.0000000000001p1
+  },
+  { // Entry 400
+    0x1.152aaa3bf81cb9fdb76eae12d029571fp-3,
+    -0x1.0p1
+  },
+  { // Entry 401
+    0x1.152aaa3bf81ccb5062126d949c53c7ebp-3,
+    -0x1.fffffffffffffp0
+  },
+  { // Entry 402
+    0x1.78b56362cef364df9544f11b0a499031p-2,
+    -0x1.0000000000001p0
+  },
+  { // Entry 403
+    0x1.78b56362cef37c6aeb7b1e0a4153e437p-2,
+    -0x1.0p0
+  },
+  { // Entry 404
+    0x1.78b56362cef3883096963481dd66523fp-2,
+    -0x1.fffffffffffffp-1
+  },
+  { // Entry 405
+    0x1.9476504ba8399f5b97cae35beb78c3c5p738,
+    0x1.fffffffffffffp8
+  },
+  { // Entry 406
+    0x1.9476504ba852e6c09c8567c01c5a6648p738,
+    0x1.0p9
+  },
+  { // Entry 407
+    0x1.9476504ba885758aa5fa7545e10e8e46p738,
+    0x1.0000000000001p9
+  },
+  { // Entry 408
+    0x1.41c7a8814be192a5df25b042af824efdp369,
+    0x1.fffffffffffffp7
+  },
+  { // Entry 409
+    0x1.41c7a8814beba0e323300f777da65854p369,
+    0x1.0p8
+  },
+  { // Entry 410
+    0x1.41c7a8814bffbd5dab44ced26faccbfbp369,
+    0x1.0000000000001p8
+  },
+  { // Entry 411
+    0x1.95e54c5dd41b20600dd601a0ae672ff4p184,
+    0x1.fffffffffffffp6
+  },
+  { // Entry 412
+    0x1.95e54c5dd42177f53f4d5219df11ca3bp184,
+    0x1.0p7
+  },
+  { // Entry 413
+    0x1.95e54c5dd42e271fa23bf3585b655060p184,
+    0x1.0000000000001p7
+  },
+  { // Entry 414
+    0x1.425982cf597a4d52c89ea857bbaa807ap92,
+    0x1.fffffffffffffp5
+  },
+  { // Entry 415
+    0x1.425982cf597cd205ce3d5b4edb031756p92,
+    0x1.0p6
+  },
+  { // Entry 416
+    0x1.425982cf5981db6bd97ac14c35e666c6p92,
+    0x1.0000000000001p6
+  },
+  { // Entry 417
+    0x1.1f43fcc4b661a8944ac389b609e0f74ep46,
+    0x1.fffffffffffffp4
+  },
+  { // Entry 418
+    0x1.1f43fcc4b662c7d84788401842174074p46,
+    0x1.0p5
+  },
+  { // Entry 419
+    0x1.1f43fcc4b66506604111ace0104fc90ep46,
+    0x1.0000000000001p5
+  },
+  { // Entry 420
+    0x1.0f2ebd0a80017cfac56c30874afbab98p23,
+    0x1.fffffffffffffp3
+  },
+  { // Entry 421
+    0x1.0f2ebd0a8002049223f170882b5ee5efp23,
+    0x1.0p4
+  },
+  { // Entry 422
+    0x1.0f2ebd0a800313c0e0fbf08ab7886866p23,
+    0x1.0000000000001p4
+  },
+  { // Entry 423
+    0x1.749ea7d470c681e43618ec18d53f1b21p11,
+    0x1.fffffffffffffp2
+  },
+  { // Entry 424
+    0x1.749ea7d470c6df0be00e084a815d1de6p11,
+    0x1.0p3
+  },
+  { // Entry 425
+    0x1.749ea7d470c7995b33f840ae1f76e2e7p11,
+    0x1.0000000000001p3
+  },
+  { // Entry 426
+    0x1.b4c902e273a54fdfb6777166e6760dfbp5,
+    0x1.fffffffffffffp1
+  },
+  { // Entry 427
+    0x1.b4c902e273a58678d6d3bfdb93db96d0p5,
+    0x1.0p2
+  },
+  { // Entry 428
+    0x1.b4c902e273a5f3ab178c5cc50320149cp5,
+    0x1.0000000000001p2
+  },
+  { // Entry 429
+    0x1.d8e64b8d4ddabf34d582cd2909aafb2ap2,
+    0x1.fffffffffffffp0
+  },
+  { // Entry 430
+    0x1.d8e64b8d4ddadcc33a3ba206b68abba8p2,
+    0x1.0p1
+  },
+  { // Entry 431
+    0x1.d8e64b8d4ddb17e003ad4bc215d4ef86p2,
+    0x1.0000000000001p1
+  },
+  { // Entry 432
+    0x1.5bf0a8b145768a55da73221499fc4cfbp1,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 433
+    0x1.5bf0a8b1457695355fb8ac404e7a79e3p1,
+    0x1.0p0
+  },
+  { // Entry 434
+    0x1.5bf0a8b14576aaf46a43c097b87bc833p1,
+    0x1.0000000000001p0
+  },
+  { // Entry 435
+    0x1.ffc045692fc9dbc7b7e032576e5e26f8p1023,
+    0x1.62e41ffffffffp9
+  },
+  { // Entry 436
+    0x1.ffc045693009d3d065062f9267dff55ep1023,
+    0x1.62e42p9
+  },
+  { // Entry 437
+    0x1.ffc045693049cbd9122c34cc62776884p1023,
+    0x1.62e4200000001p9
+  },
+  { // Entry 438
+    0x1.c87f21775a0f1a25755fb027f94949a1p-1071,
+    -0x1.72e4200000001p9
+  },
+  { // Entry 439
+    0x1.c87f21775a482a09a44af59c3c3ae44bp-1071,
+    -0x1.72e42p9
+  },
+  { // Entry 440
+    0x1.c87f21775a8139edd33642327bb25c5fp-1071,
+    -0x1.72e41ffffffffp9
+  },
+  { // Entry 441
+    HUGE_VAL,
+    0x1.0p1020
+  },
+  { // Entry 442
+    HUGE_VAL,
+    0x1.999999999999ap1020
+  },
+  { // Entry 443
+    HUGE_VAL,
+    0x1.199999999999ap1021
+  },
+  { // Entry 444
+    HUGE_VAL,
+    0x1.6666666666667p1021
+  },
+  { // Entry 445
+    HUGE_VAL,
+    0x1.b333333333334p1021
+  },
+  { // Entry 446
+    HUGE_VAL,
+    0x1.0p1022
+  },
+  { // Entry 447
+    HUGE_VAL,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 448
+    HUGE_VAL,
+    HUGE_VAL
+  },
+  { // Entry 449
+    HUGE_VAL,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 450
+    HUGE_VAL,
+    0x1.ffffffffffffep1023
+  },
+  { // Entry 451
+    0x1.724046eb09338d2991a30893e7f4108dp4,
+    0x1.921fb54442d18p1
+  },
+  { // Entry 452
+    0x1.33dedc855935efaaaf578ced3f821f96p2,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 453
+    0x1.5bf0a8b14576aaf46a43c097b87bc833p1,
+    0x1.0000000000001p0
+  },
+  { // Entry 454
+    0x1.5bf0a8b1457695355fb8ac404e7a79e3p1,
+    0x1.0p0
+  },
+  { // Entry 455
+    0x1.5bf0a8b145768a55da73221499fc4cfbp1,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 456
+    0x1.18bd669471caa5585c71cc32a792ac85p1,
+    0x1.921fb54442d18p-1
+  },
+  { // Entry 457
+    0x1.p0,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 458
+    0x1.p0,
+    0x1.0p-1022
+  },
+  { // Entry 459
+    0x1.p0,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 460
+    0x1.p0,
+    0x1.ffffffffffffcp-1023
+  },
+  { // Entry 461
+    0x1.p0,
+    0x1.0p-1073
+  },
+  { // Entry 462
+    0x1.p0,
+    0x1.0p-1074
+  },
+  { // Entry 463
+    0x1.p0,
+    0.0
+  },
+  { // Entry 464
+    0x1.p0,
+    -0.0
+  },
+  { // Entry 465
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074
+  },
+  { // Entry 466
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1073
+  },
+  { // Entry 467
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffcp-1023
+  },
+  { // Entry 468
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 469
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1022
+  },
+  { // Entry 470
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 471
+    0x1.d2e171cf048793e16a7f9406e00c2dd9p-2,
+    -0x1.921fb54442d18p-1
+  },
+  { // Entry 472
+    0x1.78b56362cef3883096963481dd66523fp-2,
+    -0x1.fffffffffffffp-1
+  },
+  { // Entry 473
+    0x1.78b56362cef37c6aeb7b1e0a4153e437p-2,
+    -0x1.0p0
+  },
+  { // Entry 474
+    0x1.78b56362cef364df9544f11b0a499031p-2,
+    -0x1.0000000000001p0
+  },
+  { // Entry 475
+    0x1.a9bcc46f767dfb0d4eec2b1337a04b9ap-3,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 476
+    0x1.620227b598ef9949e60e44dc45d14d0cp-5,
+    -0x1.921fb54442d18p1
+  },
+  { // Entry 477
+    0.0,
+    -0x1.ffffffffffffep1023
+  },
+  { // Entry 478
+    0.0,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 479
+    0.0,
+    -HUGE_VAL
+  },
+  { // Entry 480
+    0x1.fffffffffff2a1b0e263400d15fc52ffp1023,
+    0x1.62e42fefa39efp9
+  },
+  { // Entry 481
+    HUGE_VAL,
+    0x1.62e42fefa39f0p9
+  },
+  { // Entry 482
+    0x1.000000000007bbcffb06f8fdab896db0p-1022,
+    -0x1.6232bdd7abcd2p9
+  },
+  { // Entry 483
+    0x1.ffffffffffcf779ff60df40c631419a2p-1023,
+    -0x1.6232bdd7abcd3p9
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_exp, exp_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_exp_intel_data)/sizeof(exp_intel_data_t); i++) {
+    EXPECT_DOUBLE_EQ(g_exp_intel_data[i].expected, exp(g_exp_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_expf_test.cpp b/tests/math_expf_test.cpp
new file mode 100644
index 0000000..257aa26
--- /dev/null
+++ b/tests/math_expf_test.cpp
@@ -0,0 +1,1439 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  float expected;
+  float call_data;
+} expf_intel_data_t;
+
+static expf_intel_data_t g_expf_intel_data[] = {
+  { // Entry 0
+    0x1.e0fabf081222780d74c00fda30aa3943p-1,
+    -0x1.000006p-4
+  },
+  { // Entry 1
+    0x1.e0fabecbf2ca9acd25eef63af858ed60p-1,
+    -0x1.000008p-4
+  },
+  { // Entry 2
+    0x1.fc03fccfb913167ecfa84f48f5b7205bp-1,
+    -0x1.000022p-7
+  },
+  { // Entry 3
+    0x1.c3d642ff9bf2d294c0ce088e8bad27b3p-1,
+    -0x1.0001b0p-3
+  },
+  { // Entry 4
+    0x1.ff800efaebb8218fc5d491b9868689aap-1,
+    -0x1.000208p-10
+  },
+  { // Entry 5
+    0x1.8ebd9d0446182e9056f60489fcd002cdp-1,
+    -0x1.000380p-2
+  },
+  { // Entry 6
+    0x1.e0f995010fd96d3f294c3ffe0e512426p-1,
+    -0x1.0009f0p-4
+  },
+  { // Entry 7
+    0x1.78a3bb4c17adf5b2d40e6ee3dbd4866fp-2,
+    -0x1.000cp0
+  },
+  { // Entry 8
+    0x1.ffdffd003aacbfca6591e7a38368b94cp-1,
+    -0x1.0020p-12
+  },
+  { // Entry 9
+    0x1.fdff416aa3827d6335a1ffa43d440562p-1,
+    -0x1.00e0p-8
+  },
+  { // Entry 10
+    0x1.99007ffbdffac31dff90da5ee46a16fap-47,
+    -0x1.00e0p5
+  },
+  { // Entry 11
+    0x1.35c0dcfffb4419dc29555c232f3cdca7p-1,
+    -0x1.014ep-1
+  },
+  { // Entry 12
+    0x1.fbed9ac7ed032abfc76306a3e1dc816bp-1,
+    -0x1.05a4p-7
+  },
+  { // Entry 13
+    0x1.efddb9cccd73f71a4b2b8c01a57ae75fp-1,
+    -0x1.064cp-5
+  },
+  { // Entry 14
+    0x1.fffdf1010f37e2f1f5fca8b9c13aff70p-1,
+    -0x1.0780p-16
+  },
+  { // Entry 15
+    0x1.efc35653912fade6a17a8f8ef4109679p-1,
+    -0x1.08p-5
+  },
+  { // Entry 16
+    0x1.8b3096fffcbe737961f8c61cdf9d7137p-1,
+    -0x1.092c68p-2
+  },
+  { // Entry 17
+    0x1.fbdd1ce561f9d0a689812e5bea089f9cp-1,
+    -0x1.09ccp-7
+  },
+  { // Entry 18
+    0x1.efa1ef8a19d40bb22c5d3c315991e15fp-1,
+    -0x1.0a28p-5
+  },
+  { // Entry 19
+    0x1.ffffef09ce47ecc03d1d11f9491e6519p-1,
+    -0x1.0f6320p-21
+  },
+  { // Entry 20
+    0x1.ffffef09c047ed36f8aa1a7e67e26528p-1,
+    -0x1.0f64p-21
+  },
+  { // Entry 21
+    0x1.8890636e31f543b3853b1b305daeb933p-1,
+    -0x1.10p-2
+  },
+  { // Entry 22
+    0x1.ffffef0000483fff334aac5dabfd1c7dp-1,
+    -0x1.10p-21
+  },
+  { // Entry 23
+    0x1.ef1c2d002f7639d4d82edc01eaad1dedp-1,
+    -0x1.12ccp-5
+  },
+  { // Entry 24
+    0x1.de7f010d1c6494139b0531bd5b8f108bp-1,
+    -0x1.1534p-4
+  },
+  { // Entry 25
+    0x1.02057d1245ceaf62a21099d4441a36dbp-101,
+    -0x1.18p6
+  },
+  { // Entry 26
+    0x1.e9040734a16333567cf6f31bc90d4355p-27,
+    -0x1.211588p4
+  },
+  { // Entry 27
+    0x1.8d03f8ffffb1a2622bba81d6ab4a92ffp-14,
+    -0x1.287d08p3
+  },
+  { // Entry 28
+    0x1.e97e430257e75f497f6a3efe51ff5054p-112,
+    -0x1.33efeap6
+  },
+  { // Entry 29
+    0x1.c69c518ea7c58842c178fbd9e8cf536ep-117,
+    -0x1.421888p6
+  },
+  { // Entry 30
+    0x1.df2a0f92c17e9ff0bfb77b7abbe637a6p-126,
+    -0x1.5ad6b6p6
+  },
+  { // Entry 31
+    0x1.782f23068c10b1c5513dc3b0192d30d4p-127,
+    -0x1.5e9444p6
+  },
+  { // Entry 32
+    0x1.710602f9f4288348cc8348472a24f93dp-127,
+    -0x1.5ea7f2p6
+  },
+  { // Entry 33
+    0x1.65ab7994ff3440dcd3ee7f9b9a02423ap-127,
+    -0x1.5ec7f2p6
+  },
+  { // Entry 34
+    0x1.6031cc454f1c3e0126b71bf21e903d20p-127,
+    -0x1.5ed7bep6
+  },
+  { // Entry 35
+    0x1.b78f6800030fb7ec7984a3e7419d6fc2p-129,
+    -0x1.638066p6
+  },
+  { // Entry 36
+    0x1.f9363f3583279ac24e757eeb7654910cp-3,
+    -0x1.664ee0p0
+  },
+  { // Entry 37
+    0x1.d617f10e63adfcd67414c08dc6f9d010p-9,
+    -0x1.685b44p2
+  },
+  { // Entry 38
+    0x1.cf8c4503bf17d8c7647e93a153af37b6p-9,
+    -0x1.6941p2
+  },
+  { // Entry 39
+    0x1.d470b70e90d5097e87b925c5f63fee7dp-1,
+    -0x1.6c3328p-4
+  },
+  { // Entry 40
+    0x1.a9c0a5010de85f9a60c8104f37fc597fp-1,
+    -0x1.79c984p-3
+  },
+  { // Entry 41
+    0x1.dff126fffcdde3436322ba09db4556e1p-2,
+    -0x1.83ff38p-1
+  },
+  { // Entry 42
+    0x1.da1b8301af81384b8e495c9a4f97497fp-72,
+    -0x1.8a529ep5
+  },
+  { // Entry 43
+    0x1.babaf4ffffe29025ce751094aecf9b03p-19,
+    -0x1.93e788p3
+  },
+  { // Entry 44
+    0x1.6e953afffec7fc3b5dda17c820678821p-43,
+    -0x1.d723f8p4
+  },
+  { // Entry 45
+    0x1.ff0ff6f3d9f493ed610364861a995664p-1,
+    -0x1.e082c4p-10
+  },
+  { // Entry 46
+    0x1.ff38a40a3bc33f65f4bed5de0bdfc397p-45,
+    -0x1.e7fffep4
+  },
+  { // Entry 47
+    0x1.8028990034fcc8f33443321db08c6de8p-2,
+    -0x1.f5f922p-1
+  },
+  { // Entry 48
+    0x1.ff0248f1a17418e63d4711f3e66b7c25p-1,
+    -0x1.fbecp-10
+  },
+  { // Entry 49
+    0x1.ff0246f29f2c26c5ed51d16498d1d68ep-1,
+    -0x1.fbf0p-10
+  },
+  { // Entry 50
+    0x1.fa87f66f812849292290a9f6268ef2f9p-24,
+    -0x1.fe7ffep3
+  },
+  { // Entry 51
+    0x1.ff0046f2d716c095770d849e182a3bb2p-1,
+    -0x1.fff1fep-10
+  },
+  { // Entry 52
+    0x1.e0fb2911655006422a15c3c03f8ce847p-1,
+    -0x1.fff8fep-5
+  },
+  { // Entry 53
+    0x1.ff0040f4d6cac316bdcfa13cc5af7e7cp-1,
+    -0x1.fffep-10
+  },
+  { // Entry 54
+    0x1.ffe001081a28c420260a161b12fbb97dp-1,
+    -0x1.ffff7ep-13
+  },
+  { // Entry 55
+    0x1.0000010000008000002aaaaab5555557p0,
+    0x1.p-24
+  },
+  { // Entry 56
+    0x1.426436f5aec1c313a6d2bbcd58a388dep92,
+    0x1.000022p6
+  },
+  { // Entry 57
+    0x1.a615e50a5e54e1f2f7e57c3f0ff90c61p0,
+    0x1.0004p-1
+  },
+  { // Entry 58
+    0x1.d95d63014ce5cdcd113fee0a4be67902p2,
+    0x1.002038p1
+  },
+  { // Entry 59
+    0x1.762b6304e19f3518e90348b5d9dc544ep11,
+    0x1.0022p3
+  },
+  { // Entry 60
+    0x1.a636e00a0cd5b85262756d50b95ccc88p0,
+    0x1.002cp-1
+  },
+  { // Entry 61
+    0x1.8ca6d30587af504a6f69d3a57bf3e6a8p11,
+    0x1.02p3
+  },
+  { // Entry 62
+    0x1.dfa2d701da98a148063c3ca6d13f1bcep93,
+    0x1.045cb6p6
+  },
+  { // Entry 63
+    0x1.6340e70000e296e79073670ef9c0915dp1,
+    0x1.05533ep0
+  },
+  { // Entry 64
+    0x1.ef595b018549442ec73e3d5161768d16p5,
+    0x1.080d74p2
+  },
+  { // Entry 65
+    0x1.89acdf26f99012ec527c5e9e7c47117fp47,
+    0x1.0810eep5
+  },
+  { // Entry 66
+    0x1.f33bef00003ab93a467c94fc95deed30p5,
+    0x1.088d74p2
+  },
+  { // Entry 67
+    0x1.b0f34affff9dc2430b31c2ea04f9df90p95,
+    0x1.097f6ap6
+  },
+  { // Entry 68
+    0x1.6b4ae5522604e10273283efbf9f626c9p1,
+    0x1.0b0dbap0
+  },
+  { // Entry 69
+    0x1.000011000090800332d562ed602e3824p0,
+    0x1.10p-20
+  },
+  { // Entry 70
+    0x1.b380b0f6a12fa19df391f5034b8ae31bp0,
+    0x1.1009a4p-1
+  },
+  { // Entry 71
+    0x1.b5d293f5bfa20416721999c6be03a195p0,
+    0x1.12c1fep-1
+  },
+  { // Entry 72
+    0x1.b6609ff785a04630531354d1924f8d11p0,
+    0x1.1368p-1
+  },
+  { // Entry 73
+    0x1.78241affffd1cf967a9eec663f45677ep1,
+    0x1.13f37ap0
+  },
+  { // Entry 74
+    0x1.b77660f58bcb1ee2d757a97f82c8223dp0,
+    0x1.14acp-1
+  },
+  { // Entry 75
+    0x1.7b4d6f06cf0fbd1fbc05d50908352075p1,
+    0x1.1618p0
+  },
+  { // Entry 76
+    0x1.2765810002c2eb4265308ac8b12afa3bp0,
+    0x1.252726p-3
+  },
+  { // Entry 77
+    0x1.92b0acffff1c8646d4075976f62dfbc2p1,
+    0x1.25693ep0
+  },
+  { // Entry 78
+    0x1.fbd224c7e1970bed868fadc8012c85aep13,
+    0x1.364486p3
+  },
+  { // Entry 79
+    0x1.06007d00084349f9491104f20c89f2f9p28,
+    0x1.36e696p4
+  },
+  { // Entry 80
+    0x1.5ec18400003419ad3815b41c45384dccp0,
+    0x1.427898p-2
+  },
+  { // Entry 81
+    0x1.b23fdacfa3e0d9d21b342983e159fedcp118,
+    0x1.49477cp6
+  },
+  { // Entry 82
+    0x1.fea000e2438214ca9155d4c91bd29e9ap119,
+    0x1.4cb32cp6
+  },
+  { // Entry 83
+    0x1.f67176c19fee0c9a8d1c9cbb2d73b617p120,
+    0x1.4f686ap6
+  },
+  { // Entry 84
+    0x1.d1c241024d841bd52972be6182633733p121,
+    0x1.51e090p6
+  },
+  { // Entry 85
+    0x1.cde2dd070c7de9cb58c0caed927145d8p3,
+    0x1.55b4e2p1
+  },
+  { // Entry 86
+    0x1.f7109009cd3494af526c18af019055eep0,
+    0x1.59e08ep-1
+  },
+  { // Entry 87
+    0x1.fa7c26c12afb87b5b2b151e654f6eb90p0,
+    0x1.5d58aep-1
+  },
+  { // Entry 88
+    0x1.cf3d46cb98a571871f6dee1a80581a52p126,
+    0x1.5fb7ecp6
+  },
+  { // Entry 89
+    0x1.fd8718f3d3ed8f4a5d8dec6ae7327159p7,
+    0x1.6294e2p2
+  },
+  { // Entry 90
+    0x1.feaffef3e736b71569a474042054e8b7p7,
+    0x1.62ba22p2
+  },
+  { // Entry 91
+    0x1.f76ba46733f4146a0f94b3d1311494bcp127,
+    0x1.62d2e2p6
+  },
+  { // Entry 92
+    0x1.fd7b9f01b4df08855feb29023232fd99p127,
+    0x1.62df24p6
+  },
+  { // Entry 93
+    0x1.ff691e6dd71bc8cb1f1fcffcc32cb982p127,
+    0x1.62e302p6
+  },
+  { // Entry 94
+    0x1.ffce0a9e4fc6762c91f1a0ce358a8487p127,
+    0x1.62e3ccp6
+  },
+  { // Entry 95
+    0x1.fffc0109c402d8b23bfea3a14835831bp15,
+    0x1.62e3f0p3
+  },
+  { // Entry 96
+    0x1.fff1086632b0e9b93bc5be44d9c1dea7p127,
+    0x1.62e412p6
+  },
+  { // Entry 97
+    0x1.fff608470786d7e47ef11662f1790c2ap127,
+    0x1.62e41cp6
+  },
+  { // Entry 98
+    0x1.232b96ffec147bb31695595878ba4f9dp4,
+    0x1.735e70p1
+  },
+  { // Entry 99
+    0x1.8d2c990317660e21a64ba7723f5e0ed3p8,
+    0x1.7fp2
+  },
+  { // Entry 100
+    0x1.ed379f025781ddca240c83375ee496abp70,
+    0x1.89689ap5
+  },
+  { // Entry 101
+    0x1.3687410000e2c9f8732208c97919fb0ep0,
+    0x1.8b76d0p-3
+  },
+  { // Entry 102
+    0x1.312e79ff522af71b9e2e837bf8872972p2,
+    0x1.8fe0cap0
+  },
+  { // Entry 103
+    0x1.7008f10020226e4f59b5afd8c117c096p4,
+    0x1.915afcp1
+  },
+  { // Entry 104
+    0x1.de75e90225ec6da2cfb39dca6440b688p75,
+    0x1.a4e438p5
+  },
+  { // Entry 105
+    0x1.79f0650095fd426dce8aa803e9a4fc98p9,
+    0x1.a82f30p2
+  },
+  { // Entry 106
+    0x1.2e02d6fffffed97f27dcc3742472ffa4p1,
+    0x1.b78498p-1
+  },
+  { // Entry 107
+    0x1.fa2b60fffffeea1c7bd1c78bb5c46b17p9,
+    0x1.bae196p2
+  },
+  { // Entry 108
+    0x1.000734ffffffbaba4820a2b79d296d63p0,
+    0x1.cd3982p-14
+  },
+  { // Entry 109
+    0x1.d54158f5434edb2a234359befb2209bcp10,
+    0x1.e26570p2
+  },
+  { // Entry 110
+    0x1.99fb290176ec010d068c5f888a18d847p87,
+    0x1.e632aap5
+  },
+  { // Entry 111
+    0x1.bc8e5300003e12eaf0ea04b8c5076474p2,
+    0x1.f02d68p0
+  },
+  { // Entry 112
+    0x1.565672ffffe78168cea9ed1deed2c472p1,
+    0x1.f7b05cp-1
+  },
+  { // Entry 113
+    0x1.a664dced7cc33ede965392722b0d87bfp22,
+    0x1.f7fffep3
+  },
+  { // Entry 114
+    0x1.fe8bfd38762490c7f68e80a4bdf3a17dp90,
+    0x1.f896a2p5
+  },
+  { // Entry 115
+    0x1.cc24d50c16500084754fbddc60e7276cp2,
+    0x1.f8fffep0
+  },
+  { // Entry 116
+    0x1.72151c69ff0e9850b88cbd9a600fea50p11,
+    0x1.ff900ep2
+  },
+  { // Entry 117
+    0x1.3d59d2d8b22b41c2bb6334c9be7be902p92,
+    0x1.ffdffep5
+  },
+  { // Entry 118
+    0x1.74875300042b943ba368994eec8dcb0ep11,
+    0x1.fffbfep2
+  },
+  { // Entry 119
+    0x1.d8e6090cefe80487948c01efe3cf4c5ap2,
+    0x1.ffffdcp0
+  },
+  { // Entry 120
+    0x1.000000fffffe7ffffe2aaaabb5555702p0,
+    0x1.fffffcp-25
+  },
+  { // Entry 121
+    0x1.304d1ed9511bf5a6a5b20e4cdbf6d8ffp69,
+    0x1.7ffffep5
+  },
+  { // Entry 122
+    0x1.304d6aeca254b3af4bc5d6293d5f65c7p69,
+    0x1.80p5
+  },
+  { // Entry 123
+    0x1.304db70006924866bc1845097c91e488p69,
+    0x1.800002p5
+  },
+  { // Entry 124
+    0x1.f8e64411b4c7429f260cb72539880919p-76,
+    -0x1.a00002p5
+  },
+  { // Entry 125
+    0x1.f8e6c24b5592e3421df27acf1e080144p-76,
+    -0x1.a0p5
+  },
+  { // Entry 126
+    0x1.f8e7408515ecf009cb5b7fe80003ae74p-76,
+    -0x1.9ffffep5
+  },
+  { // Entry 127
+    0x1.5576f0dcac21787f2d57b14a700224e3p115,
+    0x1.3ffffep6
+  },
+  { // Entry 128
+    0x1.55779b984f3eb3c8a503b4a8e2489d98p115,
+    0x1.40p6
+  },
+  { // Entry 129
+    0x1.5578465447b9d5f83246af1e48e8225bp115,
+    0x1.400002p6
+  },
+  { // Entry 130
+    0x1.07b68d505a60dd444b8b2bdfe06038cfp-127,
+    -0x1.600002p6
+  },
+  { // Entry 131
+    0x1.07b7112bc1ffe19d3e703e4a794f7372p-127,
+    -0x1.60p6
+  },
+  { // Entry 132
+    0x1.07b795076b8caa412334e7ddf18b00f5p-127,
+    -0x1.5ffffep6
+  },
+  { // Entry 133
+    0x1.039924428f47511c03e75dd623bc47e1p75,
+    0x1.9ffffep5
+  },
+  { // Entry 134
+    0x1.03996528e074bebcfd76416fc2c0eb92p75,
+    0x1.a0p5
+  },
+  { // Entry 135
+    0x1.0399a60f41dbc2b085221312f505089dp75,
+    0x1.a00002p5
+  },
+  { // Entry 136
+    0x1.aeba4f3502d837951889740890747609p-70,
+    -0x1.800002p5
+  },
+  { // Entry 137
+    0x1.aebabae3a41b4be3f576e70303a37932p-70,
+    -0x1.80p5
+  },
+  { // Entry 138
+    0x1.aebb2692604a0be10cc9f3a09e77aae1p-70,
+    -0x1.7ffffep5
+  },
+  { // Entry 139
+    0x1.f1047545465f97aad6774dfe16b960e2p126,
+    0x1.5ffffep6
+  },
+  { // Entry 140
+    0x1.f1056dc7bf22d3de0ed57615bc501f8bp126,
+    0x1.60p6
+  },
+  { // Entry 141
+    0x1.f106664ab4276b833993050c9aa09a95p126,
+    0x1.600002p6
+  },
+  { // Entry 142
+    0x1.7fd8b4e6e875b5988aeb2e9083caf791p-116,
+    -0x1.400002p6
+  },
+  { // Entry 143
+    0x1.7fd974d372e4486f72358acdd12690e5p-116,
+    -0x1.40p6
+  },
+  { // Entry 144
+    0x1.7fda34c05d49387b3838c5c2bfad0123p-116,
+    -0x1.3ffffep6
+  },
+  { // Entry 145
+    0x1.6a32e160645dc5364da93c123215c591p-107,
+    -0x1.274768p6
+  },
+  { // Entry 146
+    0x1.42a280b47f1e50e7307c9599e94975dap-121,
+    -0x1.4e8ed0p6
+  },
+  { // Entry 147
+    0x1.1f6479d6e79d924759c7f44160ad30e3p-135,
+    -0x1.75d638p6
+  },
+  { // Entry 148
+    0x1.ffffffefa39ef39a7f254535d935142bp-2,
+    -0x1.62e430p-1
+  },
+  { // Entry 149
+    0x1.000000f7d1cff19f0f33036cf01c120cp-1,
+    -0x1.62e42ep-1
+  },
+  { // Entry 150
+    0x1.000001f7d1d16970dfcb360efa91fea0p-1,
+    -0x1.62e42cp-1
+  },
+  { // Entry 151
+    0x1.6a09e6622aebfbd7a4a03777223c604fp-1,
+    -0x1.62e430p-2
+  },
+  { // Entry 152
+    0x1.6a09e7172fdf5a2e5771f3866a25514ep-1,
+    -0x1.62e42ep-2
+  },
+  { // Entry 153
+    0x1.6a09e7cc34d3130784097b8d8a7c9008p-1,
+    -0x1.62e42cp-2
+  },
+  { // Entry 154
+    0x1.ae89f9923cbb49183aabb33b9de1bc82p-1,
+    -0x1.62e430p-3
+  },
+  { // Entry 155
+    0x1.ae89f9fddf39bb1bb94baa36c98abb7bp-1,
+    -0x1.62e42ep-3
+  },
+  { // Entry 156
+    0x1.ae89fa6981b84807d78b7f25910956dep-1,
+    -0x1.62e42cp-3
+  },
+  { // Entry 157
+    0x1.d5818dcdda301bca95fbcc530ab9b938p-1,
+    -0x1.62e430p-4
+  },
+  { // Entry 158
+    0x1.d5818e088a61d930df1b087a4b928ea0p-1,
+    -0x1.62e42ep-4
+  },
+  { // Entry 159
+    0x1.d5818e433a939ded2e7266cb13d29986p-1,
+    -0x1.62e42cp-4
+  },
+  { // Entry 160
+    0x1.ea4afa294e60b4bfa24494610e75261cp-1,
+    -0x1.62e430p-5
+  },
+  { // Entry 161
+    0x1.ea4afa47f3105849adccfa1dd5b3f93dp-1,
+    -0x1.62e42ep-5
+  },
+  { // Entry 162
+    0x1.ea4afa6697bffdbe044fa7cdad4b3ee7p-1,
+    -0x1.62e42cp-5
+  },
+  { // Entry 163
+    0x1.f50765b6643efaa2ca9e6690933e5c37p-1,
+    -0x1.62e430p-6
+  },
+  { // Entry 164
+    0x1.f50765c60c7a28948d82f31a7288232fp-1,
+    -0x1.62e42ep-6
+  },
+  { // Entry 165
+    0x1.f50765d5b4b557039240f127705c11e7p-1,
+    -0x1.62e42cp-6
+  },
+  { // Entry 166
+    0x1.059b0d214186cff9a974bcb883cf68dep0,
+    0x1.62e42cp-6
+  },
+  { // Entry 167
+    0x1.059b0d296e5f3924690ce10533fe599bp0,
+    0x1.62e42ep-6
+  },
+  { // Entry 168
+    0x1.059b0d319b37a2908f684fad7bfb94d0p0,
+    0x1.62e430p-6
+  },
+  { // Entry 169
+    0x1.0b5586aeb68ea24c9281f25b79d84f83p0,
+    0x1.62e42cp-5
+  },
+  { // Entry 170
+    0x1.0b5586bf6be70dbda62f7148cd5a788fp0,
+    0x1.62e42ep-5
+  },
+  { // Entry 171
+    0x1.0b5586d0213f7a3a0f63afa207ea7587p0,
+    0x1.62e430p-5
+  },
+  { // Entry 172
+    0x1.172b838327ae1f9d7e70418a476da480p0,
+    0x1.62e42cp-4
+  },
+  { // Entry 173
+    0x1.172b83a60d1e9230cb3b52cd1200b8dcp0,
+    0x1.62e42ep-4
+  },
+  { // Entry 174
+    0x1.172b83c8f28f0920c614fc4456de049fp0,
+    0x1.62e430p-4
+  },
+  { // Entry 175
+    0x1.306fe00d521c5b35bf373738b0a12e1ap0,
+    0x1.62e42cp-3
+  },
+  { // Entry 176
+    0x1.306fe0596e14680dc54f3a2ea15e3afcp0,
+    0x1.62e42ep-3
+  },
+  { // Entry 177
+    0x1.306fe0a58a0c87ecc96cd405d8b582dbp0,
+    0x1.62e430p-3
+  },
+  { // Entry 178
+    0x1.6a09e503b2a7dd99cf9474b115a73ecep0,
+    0x1.62e42cp-2
+  },
+  { // Entry 179
+    0x1.6a09e5b8b79a8cb4602b42cd4c99e60ep0,
+    0x1.62e42ep-2
+  },
+  { // Entry 180
+    0x1.6a09e66dbc8d96516a303ed0289c5d36p0,
+    0x1.62e430p-2
+  },
+  { // Entry 181
+    0x1.fffffc105c64ec3292f2afac3f1a430dp0,
+    0x1.62e42cp-1
+  },
+  { // Entry 182
+    0x1.fffffe105c61fc8ef63c65c66a9d4971p0,
+    0x1.62e42ep-1
+  },
+  { // Entry 183
+    0x1.000000082e308675abcb3c215eacf84ap1,
+    0x1.62e430p-1
+  },
+  { // Entry 184
+    0x1.fffff820b8d19779692fb0fcc0281246p1,
+    0x1.62e42cp0
+  },
+  { // Entry 185
+    0x1.fffffc20b8c5d8eaff4ac013cf734639p1,
+    0x1.62e42ep0
+  },
+  { // Entry 186
+    0x1.000000105c610d2e42f45922768a8e6cp2,
+    0x1.62e430p0
+  },
+  { // Entry 187
+    0x1.fffff04171c22b43a28d8088c347bf1fp3,
+    0x1.62e42cp1
+  },
+  { // Entry 188
+    0x1.fffff8417193310a429b71e70d792186p3,
+    0x1.62e42ep1
+  },
+  { // Entry 189
+    0x1.00000020b8c21b6833603e51897c598cp4,
+    0x1.62e430p1
+  },
+  { // Entry 190
+    0x1.ffffe082e40047c89dfa41d09c1e1ef8p7,
+    0x1.62e42cp2
+  },
+  { // Entry 191
+    0x1.fffff082e3445ee55b3fa84a5dd849c9p7,
+    0x1.62e42ep2
+  },
+  { // Entry 192
+    0x1.0000004171843aff1c9ef14341bfa42ep8,
+    0x1.62e430p2
+  },
+  { // Entry 193
+    0x1.ffffc105c9f0548760a823b0dfdaeb66p15,
+    0x1.62e42cp3
+  },
+  { // Entry 194
+    0x1.ffffe105c700b10c3e2a549fbdebb0dap15,
+    0x1.62e42ep3
+  },
+  { // Entry 195
+    0x1.00000082e30886b910b9d8752828389dp16,
+    0x1.62e430p3
+  },
+  { // Entry 196
+    0x1.ffff820b9b9fbc6d5dda406ad9f93354p31,
+    0x1.62e42cp4
+  },
+  { // Entry 197
+    0x1.ffffc20b8fe12f101740ac9653f78fe3p31,
+    0x1.62e42ep4
+  },
+  { // Entry 198
+    0x1.00000105c611505d7f74a41433312dp32,
+    0x1.62e430p4
+  },
+  { // Entry 199
+    0x1.fffe082f28688d3872ab8aa69f3dc358p127,
+    0x1.62e42cp6
+  },
+  { // Entry 200
+    0x1.ffff082e6c7fed1d3fd5cff7e1f60591p127,
+    0x1.62e42ep6
+  },
+  { // Entry 201
+    HUGE_VALF,
+    0x1.62e430p6
+  },
+  { // Entry 202
+    0.0f,
+    -0x1.9d1da2p6
+  },
+  { // Entry 203
+    0.0f,
+    -0x1.9d1da0p6
+  },
+  { // Entry 204
+    0x1.0000733d37b1d08a80d7f5b45a57b888p-149,
+    -0x1.9d1d9ep6
+  },
+  { // Entry 205
+    0x1.8ebef92368a3eafa519740584c0bc3b4p-1,
+    -0x1.000002p-2
+  },
+  { // Entry 206
+    0x1.8ebef9eac820ae8682b9793ac6d1e772p-1,
+    -0x1.p-2
+  },
+  { // Entry 207
+    0x1.8ebefa4e77df35ae82b57af121518cefp-1,
+    -0x1.fffffep-3
+  },
+  { // Entry 208
+    0x1.c3d6a1dde27992e129ed78a65573f878p-1,
+    -0x1.000002p-3
+  },
+  { // Entry 209
+    0x1.c3d6a24ed82218787d624d3e5eba95f5p-1,
+    -0x1.p-3
+  },
+  { // Entry 210
+    0x1.c3d6a28752f665db2eea1fa5876798a3p-1,
+    -0x1.fffffep-4
+  },
+  { // Entry 211
+    0x1.e0fabf8050d24919d357946f9e880754p-1,
+    -0x1.000002p-4
+  },
+  { // Entry 212
+    0x1.e0fabfbc702a3ce5e31fe0609358bafdp-1,
+    -0x1.p-4
+  },
+  { // Entry 213
+    0x1.e0fabfda7fd6399d632391f9771f3e82p-1,
+    -0x1.fffffep-5
+  },
+  { // Entry 214
+    0x1.f03f568987680f8419de7d66d0a619ecp-1,
+    -0x1.000002p-5
+  },
+  { // Entry 215
+    0x1.f03f56a88b5d7914b00abf97762735d1p-1,
+    -0x1.p-5
+  },
+  { // Entry 216
+    0x1.f03f56b80d582e9712e15df3cc9e8e9cp-1,
+    -0x1.fffffep-6
+  },
+  { // Entry 217
+    0x1.f80feab02e7af3675b36eb6c3c71a5eep-1,
+    -0x1.000002p-6
+  },
+  { // Entry 218
+    0x1.f80feabfeefa4927d10bdd54ead5aa46p-1,
+    -0x1.p-6
+  },
+  { // Entry 219
+    0x1.f80feac7cf39f4374d745808a78130ecp-1,
+    -0x1.fffffep-7
+  },
+  { // Entry 220
+    0x1.fc03fd4eba125a4d3455bf72cbc939f7p-1,
+    -0x1.000002p-7
+  },
+  { // Entry 221
+    0x1.fc03fd56aa224f97fcbf1332988842dep-1,
+    -0x1.p-7
+  },
+  { // Entry 222
+    0x1.fc03fd5aa22a4a49490bad128ba5af93p-1,
+    -0x1.fffffep-8
+  },
+  { // Entry 223
+    0x1.fe00ffa6c3f9bd20292897f42d7b9d76p-1,
+    -0x1.000002p-8
+  },
+  { // Entry 224
+    0x1.fe00ffaabffbbc71ad1e1184afc19c7ep-1,
+    -0x1.p-8
+  },
+  { // Entry 225
+    0x1.fe00ffacbdfcbc1d6c1a4dcc11ddb6d8p-1,
+    -0x1.fffffep-9
+  },
+  { // Entry 226
+    0x1.ff003ff357aa48970957a2cf7d7a6cacp-1,
+    -0x1.000002p-9
+  },
+  { // Entry 227
+    0x1.ff003ff556aa888b60820b6087d1e91ap-1,
+    -0x1.p-9
+  },
+  { // Entry 228
+    0x1.ff003ff6562aa8864bb757a4ed8d9686p-1,
+    -0x1.fffffep-10
+  },
+  { // Entry 229
+    0x1.ff800ffdaafff6efe4df3f7f5ce23accp-1,
+    -0x1.000002p-10
+  },
+  { // Entry 230
+    0x1.ff800ffeaabffeeefa4f3cf70f59d9bfp-1,
+    -0x1.p-10
+  },
+  { // Entry 231
+    0x1.ff800fff2aa002eeb4fb3d32c498a8ffp-1,
+    -0x1.fffffep-11
+  },
+  { // Entry 232
+    0x1.fff0003fdf5656a6a9932df6283cfcbdp-1,
+    -0x1.000002p-13
+  },
+  { // Entry 233
+    0x1.fff0003fff5556aaa8888b60b2cb2ff2p-1,
+    -0x1.p-13
+  },
+  { // Entry 234
+    0x1.fff000400f54d6aca8c334161010099ep-1,
+    -0x1.fffffep-14
+  },
+  { // Entry 235
+    0x1.48b5e371ba9f7fc224c75d198fe4cd1bp0,
+    0x1.fffffep-3
+  },
+  { // Entry 236
+    0x1.48b5e3c3e81866767bc3b69baabe534ep0,
+    0x1.p-2
+  },
+  { // Entry 237
+    0x1.48b5e468430a7181447647fc03adbfb6p0,
+    0x1.000002p-2
+  },
+  { // Entry 238
+    0x1.221604372c9c46732dd72e996c9e23f2p0,
+    0x1.fffffep-4
+  },
+  { // Entry 239
+    0x1.2216045b6f5ccf9ced688384e06b8d42p0,
+    0x1.p-3
+  },
+  { // Entry 240
+    0x1.221604a3f4ddef8974c0079f23fd0bb9p0,
+    0x1.000002p-3
+  },
+  { // Entry 241
+    0x1.1082b566cb2380e0be0d559a0150172fp0,
+    0x1.fffffep-5
+  },
+  { // Entry 242
+    0x1.1082b577d34ed7d5b1a019e225c9a951p0,
+    0x1.p-4
+  },
+  { // Entry 243
+    0x1.1082b599e3a588f120e61af4869c9842p0,
+    0x1.000002p-4
+  },
+  { // Entry 244
+    0x1.082055f8d17c19a67be4f7058e9a570ap0,
+    0x1.fffffep-6
+  },
+  { // Entry 245
+    0x1.08205601127ec98e0bd083aba80c97a6p0,
+    0x1.p-5
+  },
+  { // Entry 246
+    0x1.0820561194842a2343e81fd5fab451efp0,
+    0x1.000002p-5
+  },
+  { // Entry 247
+    0x1.04080ab14dc366ad6116c39e3c2d0a9ep0,
+    0x1.fffffep-7
+  },
+  { // Entry 248
+    0x1.04080ab55de3917ab864b3e9044e6b45p0,
+    0x1.p-6
+  },
+  { // Entry 249
+    0x1.04080abd7e23e746288296c1313f21b1p0,
+    0x1.000002p-6
+  },
+  { // Entry 250
+    0x1.02020153fc40586235decf4eb727a15fp0,
+    0x1.fffffep-8
+  },
+  { // Entry 251
+    0x1.0202015600445b0c326382bc73689d32p0,
+    0x1.p-7
+  },
+  { // Entry 252
+    0x1.0202015a084c606c4384f9a7ff2ee425p0,
+    0x1.000002p-7
+  },
+  { // Entry 253
+    0x1.01008029b456f7a855530b151055fcccp0,
+    0x1.fffffep-9
+  },
+  { // Entry 254
+    0x1.0100802ab55777d28a2a42d26aa9ee67p0,
+    0x1.p-8
+  },
+  { // Entry 255
+    0x1.0100802cb7587829f6da32ce4058b940p0,
+    0x1.000002p-8
+  },
+  { // Entry 256
+    0x1.00802004d5c0010ff251d134d9bbdf8cp0,
+    0x1.fffffep-10
+  },
+  { // Entry 257
+    0x1.00802005560011127d41d5bd72f4c8f3p0,
+    0x1.p-9
+  },
+  { // Entry 258
+    0x1.00802006568031185381f6d2c5f6ac90p0,
+    0x1.000002p-9
+  },
+  { // Entry 259
+    0x1.004008006aa553ddc0e317b0fa59b1c4p0,
+    0x1.fffffep-11
+  },
+  { // Entry 260
+    0x1.00400800aab555dde38e6ce86e9277aap0,
+    0x1.p-10
+  },
+  { // Entry 261
+    0x1.004008012ad559de58f118d77b0703afp0,
+    0x1.000002p-10
+  },
+  { // Entry 262
+    0x1.0008001ff85515ff012e68cd2d69c588p0,
+    0x1.fffffep-14
+  },
+  { // Entry 263
+    0x1.00080020005556000111127d297298c9p0,
+    0x1.p-13
+  },
+  { // Entry 264
+    0x1.000800201055d60201966bdd39867f5cp0,
+    0x1.000002p-13
+  },
+  { // Entry 265
+    0x1.969c7be3ad874c06787aba955d206d83p-93,
+    -0x1.000002p6
+  },
+  { // Entry 266
+    0x1.969d47321e4cbabf2d28070963b04194p-93,
+    -0x1.p6
+  },
+  { // Entry 267
+    0x1.969dacd97cce2d9b005ff576b7a0bb4fp-93,
+    -0x1.fffffep5
+  },
+  { // Entry 268
+    0x1.c845dd6490ab2d9c7b0cfec9c5008483p-47,
+    -0x1.000002p5
+  },
+  { // Entry 269
+    0x1.c8464f76164681e299a0124487884d64p-47,
+    -0x1.p5
+  },
+  { // Entry 270
+    0x1.c846887ee3c5d1705be6172d117870a0p-47,
+    -0x1.fffffep4
+  },
+  { // Entry 271
+    0x1.e3557f4434ad7be9e06c29966f56e62bp-24,
+    -0x1.000002p4
+  },
+  { // Entry 272
+    0x1.e355bbaee85cada65f73f32e88fb3cc6p-24,
+    -0x1.p4
+  },
+  { // Entry 273
+    0x1.e355d9e44509470f0aa73ac7ef12148fp-24,
+    -0x1.fffffep3
+  },
+  { // Entry 274
+    0x1.5fc1fa44e2269c9c9706469c20b93e95p-12,
+    -0x1.000002p3
+  },
+  { // Entry 275
+    0x1.5fc21041027acbbfcd46780fee71ead2p-12,
+    -0x1.p3
+  },
+  { // Entry 276
+    0x1.5fc21b3f1328cc16210576d3c70bf98bp-12,
+    -0x1.fffffep2
+  },
+  { // Entry 277
+    0x1.2c1552216918b98b1cef7b04f710e36cp-6,
+    -0x1.000002p2
+  },
+  { // Entry 278
+    0x1.2c155b8213cf477e8af0132c2ae23d4ap-6,
+    -0x1.p2
+  },
+  { // Entry 279
+    0x1.2c1560326946b078b09f8faebe2fc287p-6,
+    -0x1.fffffep1
+  },
+  { // Entry 280
+    0x1.152aa5e74d7c73728ada0663f224a381p-3,
+    -0x1.000002p1
+  },
+  { // Entry 281
+    0x1.152aaa3bf81cb9fdb76eae12d029571fp-3,
+    -0x1.p1
+  },
+  { // Entry 282
+    0x1.152aac664d735c4346cc27f42a3d83b1p-3,
+    -0x1.fffffep0
+  },
+  { // Entry 283
+    0x1.78b56071642fa837c9519eec10a7f937p-2,
+    -0x1.000002p0
+  },
+  { // Entry 284
+    0x1.78b56362cef37c6aeb7b1e0a4153e437p-2,
+    -0x1.p0
+  },
+  { // Entry 285
+    0x1.78b564db84579b9490e7b9557026c647p-2,
+    -0x1.fffffep-1
+  },
+  { // Entry 286
+    0x1.4259323902dbc6e62e3e07ce26cd904cp92,
+    0x1.fffffep5
+  },
+  { // Entry 287
+    0x1.425982cf597cd205ce3d5b4edb031756p92,
+    0x1.p6
+  },
+  { // Entry 288
+    0x1.425a23fc432fb5d556006a4d8e7ee11bp92,
+    0x1.000002p6
+  },
+  { // Entry 289
+    0x1.1f43d8dc3908b8ed87a5abd50621706ap46,
+    0x1.fffffep4
+  },
+  { // Entry 290
+    0x1.1f43fcc4b662c7d84788401842174074p46,
+    0x1.p5
+  },
+  { // Entry 291
+    0x1.1f444495be8e1616a1e5e388779bc146p46,
+    0x1.000002p5
+  },
+  { // Entry 292
+    0x1.0f2eac1794b8f3edb5c10d26a51f420fp23,
+    0x1.fffffep3
+  },
+  { // Entry 293
+    0x1.0f2ebd0a8002049223f170882b5ee5efp23,
+    0x1.p4
+  },
+  { // Entry 294
+    0x1.0f2edef059c1b22312bed964006ee633p23,
+    0x1.000002p4
+  },
+  { // Entry 295
+    0x1.749e9c2f7bb6cf5a276ee08236c2d6c3p11,
+    0x1.fffffep2
+  },
+  { // Entry 296
+    0x1.749ea7d470c6df0be00e084a815d1de6p11,
+    0x1.p3
+  },
+  { // Entry 297
+    0x1.749ebf1e5bfe757019de4e22b113fde9p11,
+    0x1.000002p3
+  },
+  { // Entry 298
+    0x1.b4c8fc0f4fa7a2f2459a6ef53c315f0fp5,
+    0x1.fffffep1
+  },
+  { // Entry 299
+    0x1.b4c902e273a58678d6d3bfdb93db96d0p5,
+    0x1.p2
+  },
+  { // Entry 300
+    0x1.b4c91088bbf33336f0ee52b1ad858e43p5,
+    0x1.000002p2
+  },
+  { // Entry 301
+    0x1.d8e647db814773f419262ee477a98616p2,
+    0x1.fffffep0
+  },
+  { // Entry 302
+    0x1.d8e64b8d4ddadcc33a3ba206b68abba8p2,
+    0x1.p1
+  },
+  { // Entry 303
+    0x1.d8e652f0e717d92d15cd610022ae51e3p2,
+    0x1.000002p1
+  },
+  { // Entry 304
+    0x1.5bf0a75554ce91e83d421c2a7c075cb2p1,
+    0x1.fffffep-1
+  },
+  { // Entry 305
+    0x1.5bf0a8b1457695355fb8ac404e7a79e3p1,
+    0x1.p0
+  },
+  { // Entry 306
+    0x1.5bf0ab6926caafa1a0158d79693ac8e1p1,
+    0x1.000002p0
+  },
+  { // Entry 307
+    HUGE_VALF,
+    0x1.p124
+  },
+  { // Entry 308
+    HUGE_VALF,
+    0x1.99999ap124
+  },
+  { // Entry 309
+    HUGE_VALF,
+    0x1.19999ap125
+  },
+  { // Entry 310
+    HUGE_VALF,
+    0x1.666668p125
+  },
+  { // Entry 311
+    HUGE_VALF,
+    0x1.b33334p125
+  },
+  { // Entry 312
+    HUGE_VALF,
+    0x1.p126
+  },
+  { // Entry 313
+    HUGE_VALF,
+    0x1.fffffep127
+  },
+  { // Entry 314
+    HUGE_VALF,
+    HUGE_VALF
+  },
+  { // Entry 315
+    HUGE_VALF,
+    0x1.fffffep127
+  },
+  { // Entry 316
+    HUGE_VALF,
+    0x1.fffffcp127
+  },
+  { // Entry 317
+    0x1.7240490a165620d9b922aaa22a8e4c09p4,
+    0x1.921fb6p1
+  },
+  { // Entry 318
+    0x1.33dedd672084cca612aab2b9a3e817bbp2,
+    0x1.921fb6p0
+  },
+  { // Entry 319
+    0x1.5bf0ab6926caafa1a0158d79693ac8e1p1,
+    0x1.000002p0
+  },
+  { // Entry 320
+    0x1.5bf0a8b1457695355fb8ac404e7a79e3p1,
+    0x1.p0
+  },
+  { // Entry 321
+    0x1.5bf0a75554ce91e83d421c2a7c075cb2p1,
+    0x1.fffffep-1
+  },
+  { // Entry 322
+    0x1.18bd66fb62b31900cc07634deba43456p1,
+    0x1.921fb6p-1
+  },
+  { // Entry 323
+    0x1.00000000000000000000000000000004p0,
+    0x1.000002p-126
+  },
+  { // Entry 324
+    0x1.00000000000000000000000000000004p0,
+    0x1.p-126
+  },
+  { // Entry 325
+    0x1.00000000000000000000000000000003p0,
+    0x1.fffffcp-127
+  },
+  { // Entry 326
+    0x1.00000000000000000000000000000003p0,
+    0x1.fffff8p-127
+  },
+  { // Entry 327
+    0x1.p0,
+    0x1.p-148
+  },
+  { // Entry 328
+    0x1.p0,
+    0x1.p-149
+  },
+  { // Entry 329
+    0x1.p0,
+    0.0f
+  },
+  { // Entry 330
+    0x1.p0,
+    -0.0f
+  },
+  { // Entry 331
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149
+  },
+  { // Entry 332
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-148
+  },
+  { // Entry 333
+    0x1.fffffffffffffffffffffffffffffff8p-1,
+    -0x1.fffff8p-127
+  },
+  { // Entry 334
+    0x1.fffffffffffffffffffffffffffffff8p-1,
+    -0x1.fffffcp-127
+  },
+  { // Entry 335
+    0x1.fffffffffffffffffffffffffffffff8p-1,
+    -0x1.p-126
+  },
+  { // Entry 336
+    0x1.fffffffffffffffffffffffffffffff7p-1,
+    -0x1.000002p-126
+  },
+  { // Entry 337
+    0x1.d2e17123d2ae02abbcf896f2025e3463p-2,
+    -0x1.921fb6p-1
+  },
+  { // Entry 338
+    0x1.78b564db84579b9490e7b9557026c647p-2,
+    -0x1.fffffep-1
+  },
+  { // Entry 339
+    0x1.78b56362cef37c6aeb7b1e0a4153e437p-2,
+    -0x1.p0
+  },
+  { // Entry 340
+    0x1.78b56071642fa837c9519eec10a7f937p-2,
+    -0x1.000002p0
+  },
+  { // Entry 341
+    0x1.a9bcc3373efd3e4d6a96be7a7562f428p-3,
+    -0x1.921fb6p0
+  },
+  { // Entry 342
+    0x1.620225ae5e9349593d6bb618c231545ep-5,
+    -0x1.921fb6p1
+  },
+  { // Entry 343
+    0.0f,
+    -0x1.fffffcp127
+  },
+  { // Entry 344
+    0.0f,
+    -0x1.fffffep127
+  },
+  { // Entry 345
+    0.0,
+    -HUGE_VALF
+  },
+  { // Entry 346
+    0x1.ffff082e6c7fed1d3fd5cff7e1f60591p127,
+    0x1.62e42ep6
+  },
+  { // Entry 347
+    HUGE_VALF,
+    0x1.62e430p6
+  },
+  { // Entry 348
+    0x1.00004bf94f63e3fa686222148f1293c4p-126,
+    -0x1.5d589ep6
+  },
+  { // Entry 349
+    0x1.ffff97f292ce80e494231c6496e9cbf5p-127,
+    -0x1.5d58a0p6
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_expf, expf_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_expf_intel_data)/sizeof(expf_intel_data_t); i++) {
+    EXPECT_FLOAT_EQ(g_expf_intel_data[i].expected, expf(g_expf_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_log_test.cpp b/tests/math_log_test.cpp
new file mode 100644
index 0000000..da2a848
--- /dev/null
+++ b/tests/math_log_test.cpp
@@ -0,0 +1,1675 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  double expected;
+  double call_data;
+} log_intel_data_t;
+
+static log_intel_data_t g_log_intel_data[] = {
+  { // Entry 0
+    0x1.d77fd13d27ffefffffffffffb5ed9843p-11,
+    0x1.003af6c37c1d3p0
+  },
+  { // Entry 1
+    0x1.411efd297c7808000000000016d615b2p-6,
+    0x1.05112792934b3p0
+  },
+  { // Entry 2
+    0x1.d4840664446fb800000000001f574ffcp-6,
+    0x1.076d1d8c75ea6p0
+  },
+  { // Entry 3
+    0x1.f6e4c3ced7c71ffffffffffffee947dap-3,
+    0x1.47408cb9583cep0
+  },
+  { // Entry 4
+    0x1.1a0408712e009ffffffffffffee46012p-2,
+    0x1.512b3126454f3p0
+  },
+  { // Entry 5
+    0x1.8b52c15ea9c237fffffffffffe61395cp-2,
+    0x1.789e95b11578cp0
+  },
+  { // Entry 6
+    0x1.d707029bb59d8ffffffffffffecf6ef6p-2,
+    0x1.958497f7b353fp0
+  },
+  { // Entry 7
+    0x1.0727af5fee8f5ffffffffffffec7021fp-1,
+    0x1.ac032a8d2ec23p0
+  },
+  { // Entry 8
+    0x1.12fcce02efb320000000000001435b90p-1,
+    0x1.b604e1942098dp0
+  },
+  { // Entry 9
+    0x1.178e6d3ecace98000000000001300accp-1,
+    0x1.b9f1fa4587967p0
+  },
+  { // Entry 10
+    0x1.62f71c4656b60fffffffffffff7f168ep-1,
+    0x1.000976581ce4ep1
+  },
+  { // Entry 11
+    0x1.d6336a88077a9fffffffffffffe1f817p0,
+    0x1.91a8dff540ff7p2
+  },
+  { // Entry 12
+    0x1.016e82ceda358fffffffffffffacbf62p1,
+    0x1.de37fb31fd5fcp2
+  },
+  { // Entry 13
+    0x1.1e126f5d95f3880000000000005d3761p1,
+    0x1.2b1199e497739p3
+  },
+  { // Entry 14
+    0x1.2f3832cad3d5f000000000000078801cp1,
+    0x1.55f0eaa1b2fc8p3
+  },
+  { // Entry 15
+    0x1.42ee3c7dc494600000000000004ea57fp1,
+    0x1.8ede492d96072p3
+  },
+  { // Entry 16
+    0x1.6b5df7e3cd421800000000000044613bp1,
+    0x1.11867637cbd03p4
+  },
+  { // Entry 17
+    0x1.7e7f095703eee7ffffffffffffacdc06p1,
+    0x1.3d9d7d597a9ddp4
+  },
+  { // Entry 18
+    0x1.9687c83faf0067ffffffffffffb9cf3fp1,
+    0x1.7f3825778aaafp4
+  },
+  { // Entry 19
+    0x1.83d4bcdebb3f3fffffffffffffffacc9p2,
+    0x1.ac50b409c8aeep8
+  },
+  { // Entry 20
+    0x1.fffffffffffff0000000000000aaaaaap-53,
+    0x1.0000000000001p0
+  },
+  { // Entry 21
+    0x1.76e7e5d7b6eabffffffffffffff06f80p3,
+    0x1.de7cd6751029ap16
+  },
+  { // Entry 22
+    0x1.fffffffffffff0000000000000aaaaaap-53,
+    0x1.0000000000001p0
+  },
+  { // Entry 23
+    -0x1.91550c357f883fff899dff30d0f303eep8,
+    0x1.0000000000003p-579
+  },
+  { // Entry 24
+    0x1.7fffffffffffb8000000000011ffffffp-50,
+    0x1.0000000000006p0
+  },
+  { // Entry 25
+    0x1.bffffffffffe780000000001c9555555p-48,
+    0x1.000000000001cp0
+  },
+  { // Entry 26
+    0x1.7fdfffffff7017ff000047ee017ff52cp-41,
+    0x1.0000000000bffp0
+  },
+  { // Entry 27
+    0x1.0fffffffedf0000001996aaaaa81e28ap-35,
+    0x1.00000000220p0
+  },
+  { // Entry 28
+    0x1.ffffffff00000000aaaaaaaa2aaaaaabp-33,
+    0x1.000000010p0
+  },
+  { // Entry 29
+    0x1.7fffff70000047ffffd78000184cccbdp-25,
+    0x1.000000cp0
+  },
+  { // Entry 30
+    0x1.0a2ea3e77af060004010c4f6b437fb45p1,
+    0x1.00070p3
+  },
+  { // Entry 31
+    0x1.90412094d367f99f3c615231ad98bf3dp-13,
+    0x1.000c82573f5f9p0
+  },
+  { // Entry 32
+    0x1.ffe002aa6ab1106678ad8b318cb38545p-12,
+    0x1.002p0
+  },
+  { // Entry 33
+    0x1.bfcf07242969d15db4d2b3efe1c037e0p-11,
+    0x1.00380p0
+  },
+  { // Entry 34
+    0x1.d77fd13d27ffefffffffffffb5ed9843p-11,
+    0x1.003af6c37c1d3p0
+  },
+  { // Entry 35
+    0x1.ea054ce8508e4874442e95e41718b0dep-10,
+    0x1.007a9ea7a9e80p0
+  },
+  { // Entry 36
+    0x1.ff004a7ab9083f9e1717d3a4aaec8657p-10,
+    0x1.007fdff7fdfe0p0
+  },
+  { // Entry 37
+    0x1.ffda65d44dccc889115a4a4ff75c5a77p-10,
+    0x1.0080169a16cd5p0
+  },
+  { // Entry 38
+    0x1.b956989d2589d7fd6838e57a702f38acp-9,
+    0x1.00dd0a8317176p0
+  },
+  { // Entry 39
+    0x1.fd0816d97152c7fead7b849f7614fb48p-9,
+    0x1.00ff02ba8a543p0
+  },
+  { // Entry 40
+    -0x1.37915555785b07fc19dd2632088a1e7fp9,
+    0x1.00fffffffffffp-899
+  },
+  { // Entry 41
+    0x1.64a2a9b6a40588010102807138dff50cp0,
+    0x1.01c00000000dcp2
+  },
+  { // Entry 42
+    0x1.d465957106bd286bae67c08297163ea3p-8,
+    0x1.01d6131d09dc5p0
+  },
+  { // Entry 43
+    0x1.fdf639bea5ad3762df24a208e2a1cbe8p-8,
+    0x1.01fff37a34084p0
+  },
+  { // Entry 44
+    0x1.fdf6e4fcf456977205228530acd57155p-8,
+    0x1.01fff426c8cb6p0
+  },
+  { // Entry 45
+    0x1.fdf6e4fd0426f76d6d7b839b5f6c8bafp-8,
+    0x1.01fff426c8db5p0
+  },
+  { // Entry 46
+    0x1.fdfe9c57debe1760fe4ff0899bf9e6dcp-8,
+    0x1.01fffbed922e3p0
+  },
+  { // Entry 47
+    -0x1.d17be2451229ffff11e851804e97cdd7p3,
+    0x1.028p-21
+  },
+  { // Entry 48
+    0x1.6dcb2fed7f25d3f286707230be190760p-7,
+    0x1.02dfafa07df6dp0
+  },
+  { // Entry 49
+    0x1.ff092a85ee02f7fe7fc5dc1d417184c0p-7,
+    0x1.040615461f6cap0
+  },
+  { // Entry 50
+    0x1.0aa53cea3f1abfff1ddfb5af4ac49aaep-6,
+    0x1.04334eec5a65dp0
+  },
+  { // Entry 51
+    0x1.6ea07021c133480174835d142a4b831ep-6,
+    0x1.05cb09bb9fed7p0
+  },
+  { // Entry 52
+    0x1.7199f984f560800135ff3aec3a0796a8p-6,
+    0x1.05d735184261cp0
+  },
+  { // Entry 53
+    0x1.7788bc9c08318801546c035cbd9a269ap-6,
+    0x1.05ef7bdee7be0p0
+  },
+  { // Entry 54
+    0x1.c2688e952a7237fdd8563297de625acfp-6,
+    0x1.0722a05711778p0
+  },
+  { // Entry 55
+    0x1.e02151352512f7c230cc4b895dc68dd1p-6,
+    0x1.079cf00fe24f9p0
+  },
+  { // Entry 56
+    -0x1.3e1fee699c6bc7fc001a359e0efe2db7p8,
+    0x1.07cp-459
+  },
+  { // Entry 57
+    0x1.f31b56b8b6f1a2862582f528b33c4de2p-6,
+    0x1.07eb259ee01b5p0
+  },
+  { // Entry 58
+    -0x1.d0819095fcd6c800924ecd0308ebe218p3,
+    0x1.0a8551f8fc7f8p-21
+  },
+  { // Entry 59
+    -0x1.0268d40000c718005da0249ebb0a3024p1,
+    0x1.0fff8p-3
+  },
+  { // Entry 60
+    0x1.6b5df7e3cd421800000000000044613bp1,
+    0x1.11867637cbd03p4
+  },
+  { // Entry 61
+    0x1.6b96cb66f55c2800172d81c1cef357b1p1,
+    0x1.11ffffffffff8p4
+  },
+  { // Entry 62
+    -0x1.f7a213a7cd380fffde498c453f12553dp0,
+    0x1.1e6p-3
+  },
+  { // Entry 63
+    -0x1.a0765853dec06ffedf49002b5d3008bep8,
+    0x1.206658d9b0f05p-601
+  },
+  { // Entry 64
+    0x1.0d7b6ff6e3a247fffffefb9449faf8e6p6,
+    0x1.2514738e6dcadp97
+  },
+  { // Entry 65
+    0x1.1ee3899f6818e7ffffd09e6eb4879725p1,
+    0x1.2cfbb9e4a1599p3
+  },
+  { // Entry 66
+    -0x1.33153336792897fd38f4af7ab5c00769p6,
+    0x1.2f0617037e590p-111
+  },
+  { // Entry 67
+    -0x1.04c1e6cec96377febe1183e3bd373c3ep3,
+    0x1.2f29fd4b42515p-12
+  },
+  { // Entry 68
+    -0x1.0578bc4a143d699806f945d1356d06a2p-1,
+    0x1.333e1f03af55ep-1
+  },
+  { // Entry 69
+    -0x1.fd2a1d4dcf23d7fe75f7eef9498fdaa2p-2,
+    0x1.3767a0aaf1452p-1
+  },
+  { // Entry 70
+    -0x1.fb0ce0ec79bc97fe95141ce227ed47d2p-2,
+    0x1.380c640e6246cp-1
+  },
+  { // Entry 71
+    -0x1.ee693caa501a93f30062e2a3c445ac9cp-2,
+    0x1.3bec837d601c1p-1
+  },
+  { // Entry 72
+    -0x1.ed67b9b0f2f8d420adcdf51f432817fap-2,
+    0x1.3c3c0p-1
+  },
+  { // Entry 73
+    0x1.25397dc9f85bd800000a3d55bd6d8e50p1,
+    0x1.3c419b9db662ap3
+  },
+  { // Entry 74
+    0x1.9c041f7ed8d329e312aad8493a3a79a2p0,
+    0x1.3ffffffffffffp2
+  },
+  { // Entry 75
+    0x1.c8ff7c79a9a21ac25d81ef2ffb9a24aep-3,
+    0x1.4p0
+  },
+  { // Entry 76
+    0x1.d42adfec35d147fe04ff7b1b027c5fdap-3,
+    0x1.41cp0
+  },
+  { // Entry 77
+    0x1.d7577477b9ead7fe9b2bc6960a766303p-3,
+    0x1.423fc24d04fc6p0
+  },
+  { // Entry 78
+    -0x1.d360e90c3850b36d61103f575b991880p-2,
+    0x1.446p-1
+  },
+  { // Entry 79
+    -0x1.cdeabe01a86b2d50c8ea3bb030c66bbcp-2,
+    0x1.461c159a76d4bp-1
+  },
+  { // Entry 80
+    0x1.fb9186d5e3e244ee4e28531563b69a2cp-3,
+    0x1.47fffffffffffp0
+  },
+  { // Entry 81
+    0x1.fb9186d5e3e2a8d55466c3794d2ca092p-3,
+    0x1.480p0
+  },
+  { // Entry 82
+    0x1.fb920464f5fc777f3cb0d8448c30e701p-3,
+    0x1.4800141bea83fp0
+  },
+  { // Entry 83
+    0x1.fb9c2792045e9e82eff43ef1ce0bee02p-3,
+    0x1.4801b3bf42a4ap0
+  },
+  { // Entry 84
+    0x1.fc46718a2dc22ddbfabb2598a137baa7p-3,
+    0x1.481cfade8a64dp0
+  },
+  { // Entry 85
+    0x1.ff9bd7855aaeab815fd85d2cb0694231p-3,
+    0x1.48a5d0c7ac5b5p0
+  },
+  { // Entry 86
+    0x1.ffd65f29bfd4edf98ec849c90032f302p-3,
+    0x1.48af356081ca1p0
+  },
+  { // Entry 87
+    0x1.e737cb23865c6b921552ad81d572b729p-1,
+    0x1.4b8p1
+  },
+  { // Entry 88
+    0x1.90ed52d1a23c4ffed8ee7725c53035d6p8,
+    0x1.556ee611fa309p578
+  },
+  { // Entry 89
+    -0x1.b25b8d863b3b4800fcec4eb5c14a7c2ep3,
+    0x1.55ep-20
+  },
+  { // Entry 90
+    0x1.16758a93d29af7ff100a0c107fb0c9e7p6,
+    0x1.5996659966598p100
+  },
+  { // Entry 91
+    -0x1.7e3a93bf3540d81e3dbbb57585ec1674p-2,
+    0x1.608054de74582p-1
+  },
+  { // Entry 92
+    0x1.583a417be2216cb936610ca9843511dbp-2,
+    0x1.6649bb515354fp0
+  },
+  { // Entry 93
+    -0x1.4f7dac3f1d7f3fffffdf521ccfc9dbcdp5,
+    0x1.69b109377f7p-61
+  },
+  { // Entry 94
+    0x1.62e42fefa383734a769bb41258319c1ap-2,
+    0x1.6a09e667f3b31p0
+  },
+  { // Entry 95
+    -0x1.e7a2dd016daa87ffa79528e89b610c0ap1,
+    0x1.6b0p-6
+  },
+  { // Entry 96
+    0x1.739d7f6bbd0069ce24c53fad3ef796abp-2,
+    0x1.7p0
+  },
+  { // Entry 97
+    -0x1.4c3af4797206280013c4d45af696d7cbp-2,
+    0x1.7223cef78e25dp-1
+  },
+  { // Entry 98
+    -0x1.48e65fe2c23057fdeb25c7f7c4859e9cp-2,
+    0x1.73587ce753680p-1
+  },
+  { // Entry 99
+    -0x1.4057b02bfdd097fe57379888740d8103p-2,
+    0x1.76764087395fcp-1
+  },
+  { // Entry 100
+    0x1.4a5f12ed407a400083645efcc658eda6p8,
+    0x1.8ad934b838bdap476
+  },
+  { // Entry 101
+    -0x1.83d0f90690d0f7ff207b1f007f7a3917p1,
+    0x1.8bep-5
+  },
+  { // Entry 102
+    -0x1.e387545735931400edb47ee4265d728ep-1,
+    0x1.8e4p-2
+  },
+  { // Entry 103
+    -0x1.fcc59e01369768243eca599e59e6a909p-3,
+    0x1.8f6p-1
+  },
+  { // Entry 104
+    -0x1.edd6149b33156828750bb3a608c4ddc1p-3,
+    0x1.924c57d629082p-1
+  },
+  { // Entry 105
+    0x1.cfbe6164a73f1361604926a0a90f519fp-2,
+    0x1.92a4cb798664bp0
+  },
+  { // Entry 106
+    -0x1.b428216a5c1587fdbf2f97d4c27148ccp4,
+    0x1.980p-40
+  },
+  { // Entry 107
+    -0x1.d081f0f25d66380027d59b6ebdb9bac9p-3,
+    0x1.9819d0255be60p-1
+  },
+  { // Entry 108
+    -0x1.cc0d6a92b79157fe82bfad0addd085a5p-1,
+    0x1.a0ef883be2177p-2
+  },
+  { // Entry 109
+    -0x1.8f62e2cb658638000030eb1a289f78e3p-3,
+    0x1.a549336310e6fp-1
+  },
+  { // Entry 110
+    -0x1.3651d0de2368d7fee3d1d6ee2b227744p-3,
+    0x1.b80300c030118p-1
+  },
+  { // Entry 111
+    0x1.20f25e686e7f97feceff9a7299fcd1edp-1,
+    0x1.c22024dc8289cp0
+  },
+  { // Entry 112
+    -0x1.9e327eb6ac2c37f7a39af2c988abe2b6p-1,
+    0x1.c80p-2
+  },
+  { // Entry 113
+    -0x1.b76f3d0aaf0c97fadefb4f5332d365a9p-4,
+    0x1.cbea22c8a9a16p-1
+  },
+  { // Entry 114
+    -0x1.9335e5d59499181fa0f312a9854d3042p-4,
+    0x1.cffffffffffffp-1
+  },
+  { // Entry 115
+    0x1.b6cc2b05c90a77fe9a0bb3019d8a9aedp2,
+    0x1.dae1894a2dbedp9
+  },
+  { // Entry 116
+    -0x1.fc702b8d96d0d7d4794fd56c9bec2ce2p-5,
+    0x1.e1304c1304c13p-1
+  },
+  { // Entry 117
+    -0x1.f6c7f7d0b03557d1c2690fc214b3ef43p-5,
+    0x1.e185646bc7856p-1
+  },
+  { // Entry 118
+    -0x1.eb8dcb764e07e7d4f0ef36c6ee88eacap-5,
+    0x1.e22e7349f6e97p-1
+  },
+  { // Entry 119
+    -0x1.d94a9c323e77c7fd43e2e13f541141cbp-5,
+    0x1.e341f0592c2abp-1
+  },
+  { // Entry 120
+    -0x1.ccb106085394f7a05e03df8ac23eae5dp-5,
+    0x1.e4005dfd66c32p-1
+  },
+  { // Entry 121
+    -0x1.a9bd8afc6d84b7ec7bbc80cc6f2983f8p-5,
+    0x1.e61222241ca7fp-1
+  },
+  { // Entry 122
+    -0x1.787392a45888d8006bb538c724c45f7ep-5,
+    0x1.e901133e161e4p-1
+  },
+  { // Entry 123
+    -0x1.79a634cdfb255800008607b0c2c01570p4,
+    0x1.eddc0821c76c1p-35
+  },
+  { // Entry 124
+    0x1.5172153d5fe9b7ff0f26a87c085b87d7p-1,
+    0x1.eed9208a6a349p0
+  },
+  { // Entry 125
+    -0x1.12b227244ff977d878e1166c29f76aa5p-5,
+    0x1.ef1dbcea195cdp-1
+  },
+  { // Entry 126
+    -0x1.f8a34d2505f817d848f4e8959713fb76p-6,
+    0x1.f0786fa48bd9cp-1
+  },
+  { // Entry 127
+    0x1.06885d03c19c38000002f99205a60b54p1,
+    0x1.f1a945a457d96p2
+  },
+  { // Entry 128
+    0x1.a28cccb9c6f0d7fedd89e9c4d4b9f68bp6,
+    0x1.f1fffffffffffp150
+  },
+  { // Entry 129
+    -0x1.b032da095671e7c8d427eb42292764d2p-6,
+    0x1.f2ab9dee841b5p-1
+  },
+  { // Entry 130
+    -0x1.9d66ada69056485326194e3f1c7b170cp-6,
+    0x1.f33e2a944ac96p-1
+  },
+  { // Entry 131
+    -0x1.88e7a6bf1b5b97fdbf4dd5e05467c25dp-6,
+    0x1.f3de268394e8dp-1
+  },
+  { // Entry 132
+    -0x1.84e362ad217017fe7ee6c5e9580aa1ddp-6,
+    0x1.f3fd86b392884p-1
+  },
+  { // Entry 133
+    -0x1.744eff6d77dde7d2a179669e225699e3p-6,
+    0x1.f47f1e1f53f24p-1
+  },
+  { // Entry 134
+    -0x1.68b4f86497a0a7fe24c5fba78bf17a88p0,
+    0x1.f48p-3
+  },
+  { // Entry 135
+    -0x1.6f51e68fcd7cd7fa1e6acd9f4b979341p-6,
+    0x1.f4a622df760c9p-1
+  },
+  { // Entry 136
+    -0x1.6bab4f93a37207d2376593e12e890d80p-6,
+    0x1.f4c2b2a5a5c1dp-1
+  },
+  { // Entry 137
+    -0x1.65ae4deeda7b77fe9c5dac2c0c0dedf4p-6,
+    0x1.f4f18fab5c3b8p-1
+  },
+  { // Entry 138
+    -0x1.4c2a64cb22441fe74e2f868934e9e491p-6,
+    0x1.f5b96e5b96eb7p-1
+  },
+  { // Entry 139
+    -0x1.43ae6c44b9f767f34ebf8a2cc3744c94p-6,
+    0x1.f5fbf5cedc480p-1
+  },
+  { // Entry 140
+    -0x1.41f7812310c9b0015ca3978caea2af49p-6,
+    0x1.f60968a5952d9p-1
+  },
+  { // Entry 141
+    -0x1.3b0cb0b1469db800b20aa116988cb6f2p-6,
+    0x1.f63fae6bae321p-1
+  },
+  { // Entry 142
+    -0x1.311e67575b4f5006994df3158c7316ccp-6,
+    0x1.f68da368da368p-1
+  },
+  { // Entry 143
+    -0x1.020da703f2f9d7d88c2361f9312c8382p-6,
+    0x1.f7ffbefc5d9d8p-1
+  },
+  { // Entry 144
+    -0x1.0205658935b947ec5874530468145ae7p-6,
+    0x1.f7fffffffffe6p-1
+  },
+  { // Entry 145
+    -0x1.ae825fe2eb6707f96a6e4c1dd535f9ccp-7,
+    0x1.f95139c561139p-1
+  },
+  { // Entry 146
+    -0x1.23851c80dddf27fb847cdd237db32e86p-7,
+    0x1.fb77177fb5d35p-1
+  },
+  { // Entry 147
+    -0x1.7c498eb87ed687f5ab6d00e39946d3bfp-8,
+    0x1.fd09a0b5b17f0p-1
+  },
+  { // Entry 148
+    -0x1.50dd41aeb4865700c68f5df4a8438e0dp-8,
+    0x1.fd6p-1
+  },
+  { // Entry 149
+    -0x1.08b8bba5db3a85b4e252ed1003e3481fp-8,
+    0x1.fdef9fe7f9fe3p-1
+  },
+  { // Entry 150
+    -0x1.07c989add9f585e65c78fe912c1a8cp-8,
+    0x1.fdf17c5f17cp-1
+  },
+  { // Entry 151
+    -0x1.008055958e10b542f640a94ed45f9bc0p-8,
+    0x1.fdfffffffff55p-1
+  },
+  { // Entry 152
+    -0x1.1f3e47178f97c75334a62a2f7aa66bc5p-9,
+    0x1.fee1123d05c1bp-1
+  },
+  { // Entry 153
+    -0x1.ff7faa9ab136778a743baa4f52803c4ep-10,
+    0x1.ff007ffffffffp-1
+  },
+  { // Entry 154
+    -0x1.ff39ecbe26759778f8bbf67f1e4a7e0ap-10,
+    0x1.ff00a2cd88b55p-1
+  },
+  { // Entry 155
+    -0x1.6363477698d257fc17522b50ff55553cp0,
+    0x1.ff020ffffffffp-3
+  },
+  { // Entry 156
+    -0x1.f7a248bf22fa97facadb946630e3967cp-10,
+    0x1.ff046cbe6cbddp-1
+  },
+  { // Entry 157
+    -0x1.dae60fee9fa9f7e341fe9059ccf60974p-10,
+    0x1.ff12c3ff12c30p-1
+  },
+  { // Entry 158
+    -0x1.d208bc8587776791c38a76a675c1ea45p-10,
+    0x1.ff17309fefcd2p-1
+  },
+  { // Entry 159
+    -0x1.babff263eabf87ac216ead65574acf01p-12,
+    0x1.ffc8aaff534d4p-1
+  },
+  { // Entry 160
+    -0x1.c00c40725b0617de17d7b74e49091d74p-13,
+    0x1.ffe3fffffffffp-1
+  },
+  { // Entry 161
+    -0x1.78bfa5004153173f2f5226cd23948518p-13,
+    0x1.ffe874904abd0p-1
+  },
+  { // Entry 162
+    -0x1.1148dff957e7c74564229e9cb9c4b83cp-13,
+    0x1.ffeeebbaeebb8p-1
+  },
+  { // Entry 163
+    -0x1.4aa196aae1ef97ff1730897799ee4f02p8,
+    0x1.fffffbbffffffp-478
+  },
+  { // Entry 164
+    0x1.8e8f43d38040fffeda732c8d164c1eb5p8,
+    0x1.fffffbbffffffp574
+  },
+  { // Entry 165
+    -0x1.00000401000008015565655755957558p-31,
+    0x1.fffffffbfffffp-1
+  },
+  { // Entry 166
+    -0x1.ff8040007fc027f82c8ac2a212ef8e0ep-34,
+    0x1.ffffffff003fep-1
+  },
+  { // Entry 167
+    0x1.86ef5ccdfa1b17fe78c886a9d8b2faaep7,
+    0x1.ffffffffddfffp281
+  },
+  { // Entry 168
+    -0x1.00080000008008002000555d55955640p-40,
+    0x1.fffffffffdfffp-1
+  },
+  { // Entry 169
+    -0x1.00200000002008008000055755955801p-42,
+    0x1.ffffffffff7ffp-1
+  },
+  { // Entry 170
+    -0x1.00400000001008010000015655955aaap-43,
+    0x1.ffffffffffbffp-1
+  },
+  { // Entry 171
+    0x1.30fc1931f09c97ff42ff5cad467897fdp7,
+    0x1.fffffffffffeep219
+  },
+  { // Entry 172
+    -0x1.00000000000010000000000001555555p-51,
+    0x1.ffffffffffffcp-1
+  },
+  { // Entry 173
+    -0x1.00000000000008000000000000555555p-52,
+    0x1.ffffffffffffep-1
+  },
+  { // Entry 174
+    -0x1.03fe55a061c757fed6a1da317da50b1ap-1,
+    0x1.342185798f6d6p-1
+  },
+  { // Entry 175
+    -0x1.62e42fefa39f0ce4e0d5078578892721p-2,
+    0x1.6a09e667f3bccp-1
+  },
+  { // Entry 176
+    -0x1.da391c9043a0f16abe056e384bf07f29p-3,
+    0x1.962b5f9438d25p-1
+  },
+  { // Entry 177
+    -0x1.06fbec52082bd253e20210b58868e521p-3,
+    0x1.c24cd8c07de7ep-1
+  },
+  { // Entry 178
+    -0x1.1e0a8f670c50ad172b2608e4a78b5e60p-5,
+    0x1.ee6e51ecc2fd7p-1
+  },
+  { // Entry 179
+    0x1.9e548e7e3dde7b0f34385f075e850106p-5,
+    0x1.0d47e58c84098p0
+  },
+  { // Entry 180
+    0x1.08e0bae73ac238d5d0d1fd9a04579630p-3,
+    0x1.2358a222a6944p0
+  },
+  { // Entry 181
+    0x1.9e6462187c36a8ddeed899c4e3596896p-3,
+    0x1.39695eb8c91f0p0
+  },
+  { // Entry 182
+    0x1.14dd6b0af939ac9fd1cf8d8a3a630a07p-2,
+    0x1.4f7a1b4eeba9cp0
+  },
+  { // Entry 183
+    0x1.56181f19d7198035cf7c5df02d166026p-2,
+    0x1.658ad7e50e348p0
+  },
+  { // Entry 184
+    0x1.936a82fadcd85a768a1655a807a5c5fdp-2,
+    0x1.7b9b947b30bf4p0
+  },
+  { // Entry 185
+    0x1.cd45b0a9f25021e4c6ab876e541defc9p-2,
+    0x1.91ac5111534a0p0
+  },
+  { // Entry 186
+    0x1.02044c9b70627350f5c613ba3eff7f14p-1,
+    0x1.a7bd0da775d4cp0
+  },
+  { // Entry 187
+    0x1.1c01dad59e72fa047b61ac26c51f4c17p-1,
+    0x1.bdcdca3d985f8p0
+  },
+  { // Entry 188
+    0x1.34bde9b821fe31136e67453dfecf9e34p-1,
+    0x1.d3de86d3baea4p0
+  },
+  { // Entry 189
+    0x1.4c561dbbb21d9a8faab44f6777f929f7p-1,
+    0x1.e9ef4369dd750p0
+  },
+  { // Entry 190
+    0x1.62e42fefa39eb35793c7673003e5ed5ep-1,
+    0x1.ffffffffffffcp0
+  },
+  { // Entry 191
+    -0x1.62e42fefa39f0ce4e0d5078578892721p-2,
+    0x1.6a09e667f3bccp-1
+  },
+  { // Entry 192
+    -0x1.24cfce6f80d9b57bf711e8c7ba21def9p-2,
+    0x1.80aa84ce72f89p-1
+  },
+  { // Entry 193
+    -0x1.d490246defa6c24070421157c8bdbac4p-3,
+    0x1.974b2334f2346p-1
+  },
+  { // Entry 194
+    -0x1.65d558d4ce00a4188793f7452a41c9d3p-3,
+    0x1.adebc19b71703p-1
+  },
+  { // Entry 195
+    -0x1.f991c6cb3b376d3e05c0449d9978b9bbp-4,
+    0x1.c48c6001f0ac0p-1
+  },
+  { // Entry 196
+    -0x1.31b994d3a4f80646146a3561e1668213p-4,
+    0x1.db2cfe686fe7dp-1
+  },
+  { // Entry 197
+    -0x1.ccb73cdddb2b3b5b841eb150a3d5e34dp-6,
+    0x1.f1cd9cceef23ap-1
+  },
+  { // Entry 198
+    0x1.0b94f7c19617485bcb4375b0b82ed7aap-6,
+    0x1.04371d9ab72fbp0
+  },
+  { // Entry 199
+    0x1.e27076e2af2d92344012fb7464c787c6p-5,
+    0x1.0f876ccdf6cd9p0
+  },
+  { // Entry 200
+    0x1.986d3228180be0924ac3a19b72870e79p-4,
+    0x1.1ad7bc01366b7p0
+  },
+  { // Entry 201
+    0x1.1c898c16999f2915ad51a005b68ddcc4p-3,
+    0x1.26280b3476095p0
+  },
+  { // Entry 202
+    0x1.69d4592a03621b2e6cccc2036f3931ffp-3,
+    0x1.31785a67b5a73p0
+  },
+  { // Entry 203
+    0x1.b44f77bcc8f55a888449bc53e9d9bf3ep-3,
+    0x1.3cc8a99af5451p0
+  },
+  { // Entry 204
+    0x1.fc2d6cf47cf0b2e0b88f48832402408cp-3,
+    0x1.4818f8ce34e2fp0
+  },
+  { // Entry 205
+    0x1.20cdcd192ab6530b24d75ab4459e3bc3p-2,
+    0x1.536948017480dp0
+  },
+  { // Entry 206
+    0x1.426174dbd515d649d69984816e68940dp-2,
+    0x1.5eb99734b41ebp0
+  },
+  { // Entry 207
+    0x1.62e42fefa39e52069052cb73bf7c2d5fp-2,
+    0x1.6a09e667f3bc9p0
+  },
+  { // Entry 208
+    -0x1.269621134db92783beb7676c0aa9c2a3p-2,
+    0x1.8p-1
+  },
+  { // Entry 209
+    -0x1.89fa465cb93c39302d7a43bf8a8345c8p-3,
+    0x1.a666666666666p-1
+  },
+  { // Entry 210
+    -0x1.af8e8210a41648ad2ef5a75c80ae9b02p-4,
+    0x1.cccccccccccccp-1
+  },
+  { // Entry 211
+    -0x1.9ece955321b91119b64b048613dbc07dp-6,
+    0x1.f333333333332p-1
+  },
+  { // Entry 212
+    0x1.8fb063ef2c7d10ac8c5ce361f3a59a73p-5,
+    0x1.0ccccccccccccp0
+  },
+  { // Entry 213
+    0x1.e27076e2af2d7b106f9c6fe70000f0b8p-4,
+    0x1.1ffffffffffffp0
+  },
+  { // Entry 214
+    0x1.7565011e4966e394742cdeb80aaa0b85p-3,
+    0x1.3333333333332p0
+  },
+  { // Entry 215
+    0x1.f18dc41e8ef1708ddac617e72a16a351p-3,
+    0x1.4666666666665p0
+  },
+  { // Entry 216
+    0x1.334e9e47d07efd97d13fea265dcec2d1p-2,
+    0x1.5999999999998p0
+  },
+  { // Entry 217
+    0x1.6aac04146151ff3644f0da8793fe911fp-2,
+    0x1.6cccccccccccbp0
+  },
+  { // Entry 218
+    0x1.9f323ecbf98469d61382119eac3e89e1p-2,
+    0x1.7fffffffffffep0
+  },
+  { // Entry 219
+    0.0,
+    0x1.0p0
+  },
+  { // Entry 220
+    0x1.8663f793c46cc6d5699b82cc3bd3be38p-4,
+    0x1.199999999999ap0
+  },
+  { // Entry 221
+    0x1.7565011e4967b8e9c982340d62384469p-3,
+    0x1.3333333333334p0
+  },
+  { // Entry 222
+    0x1.0ca937be1b9df8e84ab52d4b0aefd012p-2,
+    0x1.4cccccccccccep0
+  },
+  { // Entry 223
+    0x1.588c2d9133494380eebceb76c1928f7cp-2,
+    0x1.6666666666668p0
+  },
+  { // Entry 224
+    0x1.9f323ecbf9851480be2cbc4956e9348bp-2,
+    0x1.8000000000002p0
+  },
+  { // Entry 225
+    0x1.e148a1a2726d394df8cdd6c80d7ec865p-2,
+    0x1.999999999999cp0
+  },
+  { // Entry 226
+    0x1.0fae81914a9947bd2de51187a6308fdbp-1,
+    0x1.b333333333336p0
+  },
+  { // Entry 227
+    0x1.2cf25fad8f1c715e5fafceb63bf60707p-1,
+    0x1.cccccccccccd0p0
+  },
+  { // Entry 228
+    0x1.48a11293d785f86a7b177f4aa4e9cadbp-1,
+    0x1.e66666666666ap0
+  },
+  { // Entry 229
+    0x1.62e42fefa39ef35793c7673007e5ed5ep-1,
+    0x1.0p1
+  },
+  { // Entry 230
+    0x1.1542457337d42e1c6b73c89d862ba171p6,
+    0x1.0p100
+  },
+  { // Entry 231
+    0x1.15a3de711cc5494e20ce2f7e393a9661p6,
+    0x1.199999999999ap100
+  },
+  { // Entry 232
+    0x1.15fcf7f3c6f8e1f8e05889b78cdcbd94p6,
+    0x1.3333333333334p100
+  },
+  { // Entry 233
+    0x1.164eeeaaf5efcc1553be7dcad1369141p6,
+    0x1.4cccccccccccep100
+  },
+  { // Entry 234
+    0x1.169ad1a0c907775fec628588fced3401p6,
+    0x1.6666666666668p100
+  },
+  { // Entry 235
+    0x1.16e177b203cdb330ec31f559cf828aa6p6,
+    0x1.8000000000002p100
+  },
+  { // Entry 236
+    0x1.17238e14da469b55b96c96744e39203ap6,
+    0x1.999999999999cp100
+  },
+  { // Entry 237
+    0x1.1761a2765a6960abe5cf92c095780291p6,
+    0x1.b333333333336p100
+  },
+  { // Entry 238
+    0x1.179c2a3292f266ff2833283af2a38d7fp6,
+    0x1.cccccccccccd0p100
+  },
+  { // Entry 239
+    0x1.17d387985f833a0d4069f79c1b757507p6,
+    0x1.e66666666666ap100
+  },
+  { // Entry 240
+    0x1.18080dd3171b6c031a9b576be63b6d4cp6,
+    0x1.0p101
+  },
+  { // Entry 241
+    0x1.1542457337d42e1c6b73c89d862ba171p7,
+    0x1.0p200
+  },
+  { // Entry 242
+    0x1.157311f22a4cbbb54620fc0ddfb31be9p7,
+    0x1.199999999999ap200
+  },
+  { // Entry 243
+    0x1.159f9eb37f66880aa5e6292a89842f82p7,
+    0x1.3333333333334p200
+  },
+  { // Entry 244
+    0x1.15c89a0f16e1fd18df9923342bb11959p7,
+    0x1.4cccccccccccep200
+  },
+  { // Entry 245
+    0x1.15ee8b8a006dd2be2beb2713418c6ab9p7,
+    0x1.6666666666668p200
+  },
+  { // Entry 246
+    0x1.1611de929dd0f0a6abd2defbaad7160cp7,
+    0x1.8000000000002p200
+  },
+  { // Entry 247
+    0x1.1632e9c4090d64b912702f88ea3260d6p7,
+    0x1.999999999999cp200
+  },
+  { // Entry 248
+    0x1.1651f3f4c91ec76428a1adaf0dd1d201p7,
+    0x1.b333333333336p200
+  },
+  { // Entry 249
+    0x1.166f37d2e5634a8dc9d3786c3c679778p7,
+    0x1.cccccccccccd0p200
+  },
+  { // Entry 250
+    0x1.168ae685cbabb414d5eee01cd0d08b3cp7,
+    0x1.e66666666666ap200
+  },
+  { // Entry 251
+    0x1.16a529a32777cd0fc3079004b633875fp7,
+    0x1.0p201
+  },
+  { // Entry 252
+    0x1.5a92d6d005c939a38650bac4e7b689cep9,
+    0x1.0p1000
+  },
+  { // Entry 253
+    -0x1.0000080000555559555588888b333357p-20,
+    0x1.ffffep-1
+  },
+  { // Entry 254
+    -0x1.0000040000155555d5555888889ddddep-21,
+    0x1.fffffp-1
+  },
+  { // Entry 255
+    0.0,
+    0x1.0p0
+  },
+  { // Entry 256
+    0x1.fffff800002aaaa9aaaab11110e66667p-22,
+    0x1.0000080p0
+  },
+  { // Entry 257
+    0x1.fffff00000aaaaa2aaab11110bbbbc04p-21,
+    0x1.00001p0
+  },
+  { // Entry 258
+    -0x1.00000002000000055555556555555588p-30,
+    0x1.fffffff80p-1
+  },
+  { // Entry 259
+    -0x1.00000001000000015555555755555558p-31,
+    0x1.fffffffc0p-1
+  },
+  { // Entry 260
+    0.0,
+    0x1.0p0
+  },
+  { // Entry 261
+    0x1.fffffffe00000002aaaaaaa6aaaaaab1p-32,
+    0x1.000000020p0
+  },
+  { // Entry 262
+    0x1.fffffffc0000000aaaaaaa8aaaaaab11p-31,
+    0x1.000000040p0
+  },
+  { // Entry 263
+    -0x1.00000000008000000000555555555595p-40,
+    0x1.fffffffffe0p-1
+  },
+  { // Entry 264
+    -0x1.0000000000400000000015555555555dp-41,
+    0x1.ffffffffff0p-1
+  },
+  { // Entry 265
+    0.0,
+    0x1.0p0
+  },
+  { // Entry 266
+    0x1.ffffffffff80000000002aaaaaaaaa9ap-42,
+    0x1.00000000008p0
+  },
+  { // Entry 267
+    0x1.ffffffffff0000000000aaaaaaaaaa2ap-41,
+    0x1.00000000010p0
+  },
+  { // Entry 268
+    -0x1.00000000000020000000000005555555p-50,
+    0x1.ffffffffffff8p-1
+  },
+  { // Entry 269
+    -0x1.00000000000010000000000001555555p-51,
+    0x1.ffffffffffffcp-1
+  },
+  { // Entry 270
+    0.0,
+    0x1.0p0
+  },
+  { // Entry 271
+    0x1.ffffffffffffe0000000000002aaaaaap-52,
+    0x1.0000000000002p0
+  },
+  { // Entry 272
+    0x1.ffffffffffffc000000000000aaaaaaap-51,
+    0x1.0000000000004p0
+  },
+  { // Entry 273
+    0x1.62e42fefa39ef35393c7673007e5dd5ep9,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 274
+    -0x1.74385446d71c36395a7ea3b9e048a775p9,
+    0x1.0p-1074
+  },
+  { // Entry 275
+    -0x1.62e42fefa39f3a261da205fd13cb53dfp-2,
+    0x1.6a09e667f3bcbp-1
+  },
+  { // Entry 276
+    -0x1.62e42fefa39f0ce4e0d5078578892721p-2,
+    0x1.6a09e667f3bccp-1
+  },
+  { // Entry 277
+    -0x1.62e42fefa39edfa3a408090ddf46fa62p-2,
+    0x1.6a09e667f3bcdp-1
+  },
+  { // Entry 278
+    0x1.62e42fefa39eac8909ecc862fc0086ddp-2,
+    0x1.6a09e667f3bcbp0
+  },
+  { // Entry 279
+    0x1.62e42fefa39ed9ca46b9c6da9742b39bp-2,
+    0x1.6a09e667f3bccp0
+  },
+  { // Entry 280
+    0x1.62e42fefa39f070b8386c5523084e05ap-2,
+    0x1.6a09e667f3bcdp0
+  },
+  { // Entry 281
+    -0x1.62e42fefa39f035793c767300825ed5ep-1,
+    0x1.fffffffffffffp-2
+  },
+  { // Entry 282
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep-1,
+    0x1.0p-1
+  },
+  { // Entry 283
+    -0x1.62e42fefa39ed35793c7673008e5ed5ep-1,
+    0x1.0000000000001p-1
+  },
+  { // Entry 284
+    -0x1.269621134db9522e69621216b637fb86p-2,
+    0x1.7ffffffffffffp-1
+  },
+  { // Entry 285
+    -0x1.269621134db92783beb7676c0aa9c2a3p-2,
+    0x1.8p-1
+  },
+  { // Entry 286
+    -0x1.269621134db8fcd9140cbcc160e2a631p-2,
+    0x1.8000000000001p-1
+  },
+  { // Entry 287
+    0x1.9f323ecbf9849480be2cbc495993df36p-2,
+    0x1.7ffffffffffffp0
+  },
+  { // Entry 288
+    0x1.9f323ecbf984bf2b68d766f405221819p-2,
+    0x1.8p0
+  },
+  { // Entry 289
+    0x1.9f323ecbf984e9d61382119eaee9348bp-2,
+    0x1.8000000000001p0
+  },
+  { // Entry 290
+    0x1.54e3c0b10a36434abac277160311ccb4p-9,
+    0x1.00aaaaaaaaaaap0
+  },
+  { // Entry 291
+    0x1.54e3c0b10a562e0394dbbb9359f477ddp-9,
+    0x1.00aaaaaaaaaabp0
+  },
+  { // Entry 292
+    0x1.54e3c0b10a7618bc6ef5000eb37f2563p-9,
+    0x1.00aaaaaaaaaacp0
+  },
+  { // Entry 293
+    0x1.62e42fefa39eeb5793c7673007c5ed5ep0,
+    0x1.fffffffffffffp1
+  },
+  { // Entry 294
+    0x1.62e42fefa39ef35793c7673007e5ed5ep0,
+    0x1.0p2
+  },
+  { // Entry 295
+    0x1.62e42fefa39f035793c767300765ed5ep0,
+    0x1.0000000000001p2
+  },
+  { // Entry 296
+    0x1.62e42fefa39ee35793c7673007a5ed5ep-1,
+    0x1.fffffffffffffp0
+  },
+  { // Entry 297
+    0x1.62e42fefa39ef35793c7673007e5ed5ep-1,
+    0x1.0p1
+  },
+  { // Entry 298
+    0x1.62e42fefa39f135793c7673006e5ed5ep-1,
+    0x1.0000000000001p1
+  },
+  { // Entry 299
+    -0x1.00000000000004000000000000155555p-53,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 300
+    0.0,
+    0x1.0p0
+  },
+  { // Entry 301
+    0x1.fffffffffffff0000000000000aaaaaap-53,
+    0x1.0000000000001p0
+  },
+  { // Entry 302
+    -0x1.62e42fefa39f035793c767300825ed5ep-1,
+    0x1.fffffffffffffp-2
+  },
+  { // Entry 303
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep-1,
+    0x1.0p-1
+  },
+  { // Entry 304
+    -0x1.62e42fefa39ed35793c7673008e5ed5ep-1,
+    0x1.0000000000001p-1
+  },
+  { // Entry 305
+    -0x1.62e42fefa39efb5793c767300805ed5ep0,
+    0x1.fffffffffffffp-3
+  },
+  { // Entry 306
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep0,
+    0x1.0p-2
+  },
+  { // Entry 307
+    -0x1.62e42fefa39ee35793c767300865ed5ep0,
+    0x1.0000000000001p-2
+  },
+  { // Entry 308
+    -0x1.0a2b23f3bab73a81aed58d6405fc7206p1,
+    0x1.fffffffffffffp-4
+  },
+  { // Entry 309
+    -0x1.0a2b23f3bab73681aed58d6405ec7206p1,
+    0x1.0p-3
+  },
+  { // Entry 310
+    -0x1.0a2b23f3bab72e81aed58d64062c7206p1,
+    0x1.0000000000001p-3
+  },
+  { // Entry 311
+    -0x1.62e42fefa39ef75793c7673007f5ed5ep1,
+    0x1.fffffffffffffp-5
+  },
+  { // Entry 312
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep1,
+    0x1.0p-4
+  },
+  { // Entry 313
+    -0x1.62e42fefa39eeb5793c767300825ed5ep1,
+    0x1.0000000000001p-4
+  },
+  { // Entry 314
+    -0x1.bb9d3beb8c86b42d78b940fc09ef68b6p1,
+    0x1.fffffffffffffp-6
+  },
+  { // Entry 315
+    -0x1.bb9d3beb8c86b02d78b940fc09df68b6p1,
+    0x1.0p-5
+  },
+  { // Entry 316
+    -0x1.bb9d3beb8c86a82d78b940fc0a1f68b6p1,
+    0x1.0000000000001p-5
+  },
+  { // Entry 317
+    -0x1.0a2b23f3bab73881aed58d6405f47206p2,
+    0x1.fffffffffffffp-7
+  },
+  { // Entry 318
+    -0x1.0a2b23f3bab73681aed58d6405ec7206p2,
+    0x1.0p-6
+  },
+  { // Entry 319
+    -0x1.0a2b23f3bab73281aed58d64060c7206p2,
+    0x1.0000000000001p-6
+  },
+  { // Entry 320
+    -0x1.3687a9f1af2b16eca14e7a4a06f12fb2p2,
+    0x1.fffffffffffffp-8
+  },
+  { // Entry 321
+    -0x1.3687a9f1af2b14eca14e7a4a06e92fb2p2,
+    0x1.0p-7
+  },
+  { // Entry 322
+    -0x1.3687a9f1af2b10eca14e7a4a07092fb2p2,
+    0x1.0000000000001p-7
+  },
+  { // Entry 323
+    -0x1.62e42fefa39ef55793c7673007eded5ep2,
+    0x1.fffffffffffffp-9
+  },
+  { // Entry 324
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep2,
+    0x1.0p-8
+  },
+  { // Entry 325
+    -0x1.62e42fefa39eef5793c767300805ed5ep2,
+    0x1.0000000000001p-8
+  },
+  { // Entry 326
+    -0x1.8f40b5ed9812d3c28640541608eaab0ap2,
+    0x1.fffffffffffffp-10
+  },
+  { // Entry 327
+    -0x1.8f40b5ed9812d1c28640541608e2ab0ap2,
+    0x1.0p-9
+  },
+  { // Entry 328
+    -0x1.8f40b5ed9812cdc2864054160902ab0ap2,
+    0x1.0000000000001p-9
+  },
+  { // Entry 329
+    -0x1.bb9d3beb8c86b22d78b940fc09e768b6p2,
+    0x1.fffffffffffffp-11
+  },
+  { // Entry 330
+    -0x1.bb9d3beb8c86b02d78b940fc09df68b6p2,
+    0x1.0p-10
+  },
+  { // Entry 331
+    -0x1.bb9d3beb8c86ac2d78b940fc09ff68b6p2,
+    0x1.0000000000001p-10
+  },
+  { // Entry 332
+    -0x1.205966f2b4f126b7281203d7066ed0dcp3,
+    0x1.fffffffffffffp-14
+  },
+  { // Entry 333
+    -0x1.205966f2b4f125b7281203d7066ad0dcp3,
+    0x1.0p-13
+  },
+  { // Entry 334
+    -0x1.205966f2b4f123b7281203d7067ad0dcp3,
+    0x1.0000000000001p-13
+  },
+  { // Entry 335
+    -0x1.205966f2b4f126b7281203d7066ed0dcp3,
+    0x1.fffffffffffffp-14
+  },
+  { // Entry 336
+    -0x1.205966f2b4f125b7281203d7066ad0dcp3,
+    0x1.0p-13
+  },
+  { // Entry 337
+    -0x1.205966f2b4f123b7281203d7067ad0dcp3,
+    0x1.0000000000001p-13
+  },
+  { // Entry 338
+    -0x1.0a2b23f3bab73a81aed58d6405fc7206p1,
+    0x1.fffffffffffffp-4
+  },
+  { // Entry 339
+    -0x1.0a2b23f3bab73681aed58d6405ec7206p1,
+    0x1.0p-3
+  },
+  { // Entry 340
+    -0x1.0a2b23f3bab72e81aed58d64062c7206p1,
+    0x1.0000000000001p-3
+  },
+  { // Entry 341
+    -0x1.1178e8227e480707cafd4459785b0e8fp-3,
+    0x1.bffffffffffffp-1
+  },
+  { // Entry 342
+    -0x1.1178e8227e47bde338b41fc72de81e3bp-3,
+    0x1.cp-1
+  },
+  { // Entry 343
+    -0x1.1178e8227e4774bea66afb34e611e9fdp-3,
+    0x1.c000000000001p-1
+  },
+  { // Entry 344
+    -0x1.62e42fefa39ef75793c7673007f5ed5ep1,
+    0x1.fffffffffffffp-5
+  },
+  { // Entry 345
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep1,
+    0x1.0p-4
+  },
+  { // Entry 346
+    -0x1.62e42fefa39eeb5793c767300825ed5ep1,
+    0x1.0000000000001p-4
+  },
+  { // Entry 347
+    -0x1.08598b59e3a0f112c86247d8be41d487p-4,
+    0x1.dffffffffffffp-1
+  },
+  { // Entry 348
+    -0x1.08598b59e3a0688a3fd9bf503372c12fp-4,
+    0x1.ep-1
+  },
+  { // Entry 349
+    -0x1.08598b59e39fe001b75136c7ad30c376p-4,
+    0x1.e000000000001p-1
+  },
+  { // Entry 350
+    -0x1.bb9d3beb8c86b42d78b940fc09ef68b6p1,
+    0x1.fffffffffffffp-6
+  },
+  { // Entry 351
+    -0x1.bb9d3beb8c86b02d78b940fc09df68b6p1,
+    0x1.0p-5
+  },
+  { // Entry 352
+    -0x1.bb9d3beb8c86a82d78b940fc0a1f68b6p1,
+    0x1.0000000000001p-5
+  },
+  { // Entry 353
+    -0x1.0415d89e74454f43844b7e55cedd837bp-5,
+    0x1.effffffffffffp-1
+  },
+  { // Entry 354
+    -0x1.0415d89e7444470173c75d4d8889de0ep-5,
+    0x1.fp-1
+  },
+  { // Entry 355
+    -0x1.0415d89e74433ebf63433c454abc7b39p-5,
+    0x1.f000000000001p-1
+  },
+  { // Entry 356
+    -0x1.0a2b23f3bab73881aed58d6405f47206p2,
+    0x1.fffffffffffffp-7
+  },
+  { // Entry 357
+    -0x1.0a2b23f3bab73681aed58d6405ec7206p2,
+    0x1.0p-6
+  },
+  { // Entry 358
+    -0x1.0a2b23f3bab73281aed58d64060c7206p2,
+    0x1.0000000000001p-6
+  },
+  { // Entry 359
+    -0x1.0205658935867cbfa5a9263bd81da4a0p-6,
+    0x1.f7fffffffffffp-1
+  },
+  { // Entry 360
+    -0x1.020565893584749f23a105b9c7bb9a6fp-6,
+    0x1.f80p-1
+  },
+  { // Entry 361
+    -0x1.0205658935826c7ea198e537c7dca08fp-6,
+    0x1.f800000000001p-1
+  },
+  { // Entry 362
+    -0x1.3687a9f1af2b16eca14e7a4a06f12fb2p2,
+    0x1.fffffffffffffp-8
+  },
+  { // Entry 363
+    -0x1.3687a9f1af2b14eca14e7a4a06e92fb2p2,
+    0x1.0p-7
+  },
+  { // Entry 364
+    -0x1.3687a9f1af2b10eca14e7a4a07092fb2p2,
+    0x1.0000000000001p-7
+  },
+  { // Entry 365
+    -0x1.010157588deb1a9cec9b03fbee49c6b0p-7,
+    0x1.fbfffffffffffp-1
+  },
+  { // Entry 366
+    -0x1.010157588de7128ccc5a82f9da00f48bp-7,
+    0x1.fc0p-1
+  },
+  { // Entry 367
+    -0x1.010157588de30a7cac1a01f7e639a670p-7,
+    0x1.fc00000000001p-1
+  },
+  { // Entry 368
+    -0x1.62e42fefa39ef55793c7673007eded5ep2,
+    0x1.fffffffffffffp-9
+  },
+  { // Entry 369
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep2,
+    0x1.0p-8
+  },
+  { // Entry 370
+    -0x1.62e42fefa39eef5793c767300805ed5ep2,
+    0x1.0000000000001p-8
+  },
+  { // Entry 371
+    -0x1.0080559588bb5feda0eb4595c5fbe2b1p-8,
+    0x1.fdfffffffffffp-1
+  },
+  { // Entry 372
+    -0x1.0080559588b357e598e33d8d9db37a29p-8,
+    0x1.fe0p-1
+  },
+  { // Entry 373
+    -0x1.0080559588ab4fdd90db3585b5ebd2a1p-8,
+    0x1.fe00000000001p-1
+  },
+  { // Entry 374
+    -0x1.8f40b5ed9812d3c28640541608eaab0ap2,
+    0x1.fffffffffffffp-10
+  },
+  { // Entry 375
+    -0x1.8f40b5ed9812d1c28640541608e2ab0ap2,
+    0x1.0p-9
+  },
+  { // Entry 376
+    -0x1.8f40b5ed9812cdc2864054160902ab0ap2,
+    0x1.0000000000001p-9
+  },
+  { // Entry 377
+    -0x1.0040155d5899e674691fef41402f3e7bp-9,
+    0x1.fefffffffffffp-1
+  },
+  { // Entry 378
+    -0x1.0040155d5889de70671eeec0bfcefe53p-9,
+    0x1.ff0p-1
+  },
+  { // Entry 379
+    -0x1.0040155d5879d66c651dee40bfef1e6bp-9,
+    0x1.ff00000000001p-1
+  },
+  { // Entry 380
+    -0x1.bb9d3beb8c86b22d78b940fc09e768b6p2,
+    0x1.fffffffffffffp-11
+  },
+  { // Entry 381
+    -0x1.bb9d3beb8c86b02d78b940fc09df68b6p2,
+    0x1.0p-10
+  },
+  { // Entry 382
+    -0x1.bb9d3beb8c86ac2d78b940fc09ff68b6p2,
+    0x1.0000000000001p-10
+  },
+  { // Entry 383
+    -0x1.0020055655a89b377d5801fd08fd9f2dp-10,
+    0x1.ff7ffffffffffp-1
+  },
+  { // Entry 384
+    -0x1.00200556558893357cd7e1f486bd0705p-10,
+    0x1.ff8p-1
+  },
+  { // Entry 385
+    -0x1.0020055655688b337c57c1ed04fc9eedp-10,
+    0x1.ff80000000001p-1
+  },
+  { // Entry 386
+    -0x1.205966f2b4f126b7281203d7066ed0dcp3,
+    0x1.fffffffffffffp-14
+  },
+  { // Entry 387
+    -0x1.205966f2b4f125b7281203d7066ad0dcp3,
+    0x1.0p-13
+  },
+  { // Entry 388
+    -0x1.205966f2b4f123b7281203d7067ad0dcp3,
+    0x1.0000000000001p-13
+  },
+  { // Entry 389
+    -0x1.0004001556d56088dde0703f034ca096p-13,
+    0x1.ffeffffffffffp-1
+  },
+  { // Entry 390
+    -0x1.0004001555d558889dde702b028c9996p-13,
+    0x1.fffp-1
+  },
+  { // Entry 391
+    -0x1.0004001554d550885ddc701f024c9896p-13,
+    0x1.fff0000000001p-1
+  },
+  { // Entry 392
+    HUGE_VAL,
+    HUGE_VAL
+  },
+  { // Entry 393
+    0x1.62e42fefa39ef35393c7673007e5dd5ep9,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 394
+    0x1.62e42fefa39ef34f93c7673007e5ad5ep9,
+    0x1.ffffffffffffep1023
+  },
+  { // Entry 395
+    0x1.250d048e7a1bcdee499fa5b0ca1dd243p0,
+    0x1.921fb54442d18p1
+  },
+  { // Entry 396
+    0x1.ce6bb25aa1315109feefc86318ab6e52p-2,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 397
+    0x1.fffffffffffff0000000000000aaaaaap-53,
+    0x1.0000000000001p0
+  },
+  { // Entry 398
+    0.0,
+    0x1.0p0
+  },
+  { // Entry 399
+    -0x1.00000000000004000000000000155555p-53,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 400
+    -0x1.eeb95b094c192b4a513e0bf9ee40d8d4p-3,
+    0x1.921fb54442d18p-1
+  },
+  { // Entry 401
+    -0x1.6232bdd7abcd23d5e7fd837c6fe23a67p9,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 402
+    -0x1.6232bdd7abcd23dde7fd837c6fe1fa67p9,
+    0x1.0p-1022
+  },
+  { // Entry 403
+    -0x1.6232bdd7abcd23e5e7fd837c6fe23a67p9,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 404
+    -0x1.6232bdd7abcd23ede7fd837c6fe2fa67p9,
+    0x1.ffffffffffffcp-1023
+  },
+  { // Entry 405
+    -0x1.73df9b3adb334e7c8499b1e01446adfap9,
+    0x1.0p-1073
+  },
+  { // Entry 406
+    -0x1.74385446d71c36395a7ea3b9e048a775p9,
+    0x1.0p-1074
+  },
+  { // Entry 407
+    -HUGE_VAL,
+    0.0
+  },
+  { // Entry 408
+    -HUGE_VAL,
+    -0.0
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_log, log_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_log_intel_data)/sizeof(log_intel_data_t); i++) {
+    EXPECT_DOUBLE_EQ(g_log_intel_data[i].expected, log(g_log_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_logf_test.cpp b/tests/math_logf_test.cpp
new file mode 100644
index 0000000..e5d0921
--- /dev/null
+++ b/tests/math_logf_test.cpp
@@ -0,0 +1,1327 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  float expected;
+  float call_data;
+} logf_intel_data_t;
+
+static logf_intel_data_t g_logf_intel_data[] = {
+  { // Entry 0
+    -0x1.bb9d3aeb8c87b02d7763eba8b48a102dp1,
+    0x1.000002p-5
+  },
+  { // Entry 1
+    0x1.fffffe000002aaaaa6aaaab111110666p-24,
+    0x1.000002p0
+  },
+  { // Entry 2
+    -0x1.c6b45ceb09a5a7c82aacd1cadf7253dcp4,
+    0x1.000008p-41
+  },
+  { // Entry 3
+    -0x1.d1cb7cea86d09f62474b14c45f4cb680p3,
+    0x1.000010p-21
+  },
+  { // Entry 4
+    -0x1.fe2800e87c347d788f394ef2e93db868p5,
+    0x1.000080p-92
+  },
+  { // Entry 5
+    0x1.1fffaf001e5ff32f85c436e59fe73b1ep-17,
+    0x1.000090p0
+  },
+  { // Entry 6
+    -0x1.0a27a3fffa7e0d031d9a55d157a0e8c8p1,
+    0x1.0007p-3
+  },
+  { // Entry 7
+    0x1.54de6ee78989a9acfc875c1d45e16490p-9,
+    0x1.00aaa8p0
+  },
+  { // Entry 8
+    0x1.8f4826fff787c58fab520e505952bb55p-9,
+    0x1.00c7f2p0
+  },
+  { // Entry 9
+    -0x1.6150cefffc83ba2da43d8d7455ef2fdep-1,
+    0x1.00cap-1
+  },
+  { // Entry 10
+    0x1.cf2e3eb0928bdf5cbf064a27c6422c85p-9,
+    0x1.00e8p0
+  },
+  { // Entry 11
+    0x1.f0ee8a9a67ab36597ffd3c93304d0cc5p-9,
+    0x1.00f8f0p0
+  },
+  { // Entry 12
+    0x1.fbdfc897d239fb49dc1c31afeaea1ea5p-9,
+    0x1.00fe6ep0
+  },
+  { // Entry 13
+    0x1.fdc5e48f893e8f48967ee4ff1e895dd5p-9,
+    0x1.00ff62p0
+  },
+  { // Entry 14
+    0x1.be79c70058ec8f9a6c04043f52763c30p-8,
+    0x1.01c0p0
+  },
+  { // Entry 15
+    0x1.e3afef036c442bea46d105f6864ea6f3p-8,
+    0x1.01e57ap0
+  },
+  { // Entry 16
+    0x1.eb92db03d89f25719af908ebb6e7e510p-8,
+    0x1.01ed6cp0
+  },
+  { // Entry 17
+    0x1.f873b502f9427cb1a14872267ffae2f8p-8,
+    0x1.01fa66p0
+  },
+  { // Entry 18
+    0x1.fc108903fcd4cd445800cb06c164d0b0p-8,
+    0x1.01fe0ap0
+  },
+  { // Entry 19
+    0x1.fea168fad6274232ad3998c3e39e43d9p-8,
+    0x1.0200a0p0
+  },
+  { // Entry 20
+    0x1.0ce4c9fe3edd7f45dc38d30f76305931p-7,
+    0x1.021cp0
+  },
+  { // Entry 21
+    0x1.0ee096e2764f9f1e64840607436cc093p-7,
+    0x1.0220p0
+  },
+  { // Entry 22
+    0x1.fc098efffe49fe32c3576def6f303335p-7,
+    0x1.03fffep0
+  },
+  { // Entry 23
+    -0x1.58fed400015fff94ac3bb9ebbc81c8aep-1,
+    0x1.04ffp-1
+  },
+  { // Entry 24
+    -0x1.58b1f1ffffa56b55b6a722e0ab2c5ae6p-1,
+    0x1.052634p-1
+  },
+  { // Entry 25
+    0x1.e720a3003d099731c85ce6d689546a76p-6,
+    0x1.07b9c4p0
+  },
+  { // Entry 26
+    0x1.f5a4cb00353937ad8b1e07a6a469189fp-6,
+    0x1.07f59cp0
+  },
+  { // Entry 27
+    -0x1.b0080fffd588ec91883715736aae0f50p4,
+    0x1.08p-39
+  },
+  { // Entry 28
+    0x1.7f64a700002b54d6fb5d69bc35c5e2cap-1,
+    0x1.0ea7b0p1
+  },
+  { // Entry 29
+    0x1.cf2825078d8bd21f5b5543342e66b54dp-5,
+    0x1.0ee4p0
+  },
+  { // Entry 30
+    0x1.845657000391f340da745d9e5d283165p-1,
+    0x1.1148p1
+  },
+  { // Entry 31
+    -0x1.b959420004b51fb80d8329172d8922f6p3,
+    0x1.12c8p-20
+  },
+  { // Entry 32
+    -0x1.3cb226cef9a610cf77dc0067902b4099p-1,
+    0x1.13d4p-1
+  },
+  { // Entry 33
+    0x1.5e1a22fccd87d40b6e7ebc0226374d61p-4,
+    0x1.16d8p0
+  },
+  { // Entry 34
+    -0x1.35fb76dd8c7a211f33842af42c599114p-1,
+    0x1.1778p-1
+  },
+  { // Entry 35
+    -0x1.35028ad9d8c85c1fca93f355d4796bc1p-1,
+    0x1.18p-1
+  },
+  { // Entry 36
+    0x1.a3f71cff14b8111aded976c26d18960ep-4,
+    0x1.1ba4p0
+  },
+  { // Entry 37
+    -0x1.55a061fff90fa6df755f7aef5ab9f978p1,
+    0x1.1bf4p-4
+  },
+  { // Entry 38
+    -0x1.ce5ffde66a9af783b86443209ecec164p3,
+    0x1.1ce0p-21
+  },
+  { // Entry 39
+    -0x1.ce3a55ea5d47322bdbbe0fff5479ca1ep3,
+    0x1.1e30p-21
+  },
+  { // Entry 40
+    0x1.e23792ef52971fd6c72a99f598a0fbacp-4,
+    0x1.1ffcp0
+  },
+  { // Entry 41
+    0x1.8fe0c85314ba5e09e115528c02ef6e31p0,
+    0x1.312e78p2
+  },
+  { // Entry 42
+    -0x1.fdedfade465d57336a9b8a3562d3b176p-2,
+    0x1.372c16p-1
+  },
+  { // Entry 43
+    -0x1.fd9c98de7d89b9e29546a9b7692cacddp-2,
+    0x1.3744d2p-1
+  },
+  { // Entry 44
+    -0x1.fd5656de0c66d47b7b9cf4fa68b356e4p-2,
+    0x1.375a2ep-1
+  },
+  { // Entry 45
+    -0x1.fca98cde0ceb18d6d7bab7705d14de17p-2,
+    0x1.378ebcp-1
+  },
+  { // Entry 46
+    -0x1.fc0a58de4ea7c9432ac00ff0adb6db7ep-2,
+    0x1.37bf30p-1
+  },
+  { // Entry 47
+    -0x1.ebdede51de7d7b359acc23ec312af2d4p-2,
+    0x1.3cb56ap-1
+  },
+  { // Entry 48
+    -0x1.dae0dedfdda2569379630abffcaffff2p-2,
+    0x1.420208p-1
+  },
+  { // Entry 49
+    -0x1.d930ca53ae8e0695d14e48376b584668p-2,
+    0x1.428a04p-1
+  },
+  { // Entry 50
+    0x1.ec3649c72c05a069c2d000090851c639p-3,
+    0x1.458cbep0
+  },
+  { // Entry 51
+    0x1.f3e63257ecd12b0d9ccc9ff34c3f3d6ep-3,
+    0x1.46c626p0
+  },
+  { // Entry 52
+    -0x1.693cfa30b633b1d03f4ecd88a750ac79p-2,
+    0x1.67cd3ap-1
+  },
+  { // Entry 53
+    -0x1.692b5e42108b73d7599518074ce8670ap-2,
+    0x1.67d36ap-1
+  },
+  { // Entry 54
+    -0x1.63bbba1771b8208d851ab36cd6d93f38p-2,
+    0x1.69bdbap-1
+  },
+  { // Entry 55
+    0x1.62e25eec85781e60cb49b4f21becabdfp-2,
+    0x1.6a0942p0
+  },
+  { // Entry 56
+    0x1.62e3ce9ef86f6524351edd87310e8743p-2,
+    0x1.6a09c4p0
+  },
+  { // Entry 57
+    -0x1.3c607adedb168d9d89c6b2265b4dd0a4p-2,
+    0x1.77ea38p-1
+  },
+  { // Entry 58
+    -0x1.194432fffcb092d891670b7f8f628fc4p6,
+    0x1.77fffep-102
+  },
+  { // Entry 59
+    0x1.193ea500258270930f8e7d7af244dcffp0,
+    0x1.7ffffcp1
+  },
+  { // Entry 60
+    -0x1.dac08de1d26b0f69e1ed58bd3d9fd82bp3,
+    0x1.82fe92p-22
+  },
+  { // Entry 61
+    0x1.c8d70de117cb2fe459ed64cc67e5abc9p3,
+    0x1.830608p20
+  },
+  { // Entry 62
+    0x1.f2272ae325a57546f69496cf261be046p1,
+    0x1.88p5
+  },
+  { // Entry 63
+    0x1.c9c5ade34763c0b9a180d863bfc7f106p3,
+    0x1.8e7686p20
+  },
+  { // Entry 64
+    -0x1.f991d108abe1fc9c91e91ae7f707bd4fp-3,
+    0x1.8ffffep-1
+  },
+  { // Entry 65
+    -0x1.827d4d002e5d13215ce5f8de87566933p1,
+    0x1.8ffffep-5
+  },
+  { // Entry 66
+    -0x1.f305bd058b3c9e64101476e5de911d83p-3,
+    0x1.9147e0p-1
+  },
+  { // Entry 67
+    -0x1.ee7ee50650878a84e97f4cec96736bc5p-3,
+    0x1.922b30p-1
+  },
+  { // Entry 68
+    0x1.dc0391005bf0fccb92c262eeb6a300e4p0,
+    0x1.9ae278p2
+  },
+  { // Entry 69
+    -0x1.2650b600000be0c5902c7a15495161c5p1,
+    0x1.9aeea0p-4
+  },
+  { // Entry 70
+    -0x1.7ba9b7ffff3d189f5a17149697c12ce2p1,
+    0x1.a5e970p-5
+  },
+  { // Entry 71
+    -0x1.206170fffc9e8a93c1986e21787bed5ap1,
+    0x1.ae6ef0p-4
+  },
+  { // Entry 72
+    -0x1.d73d7ffc1e7abc4225e39878828f8666p3,
+    0x1.afe26cp-22
+  },
+  { // Entry 73
+    -0x1.25174700000008ddbe755739d626364fp3,
+    0x1.b97c70p-14
+  },
+  { // Entry 74
+    -0x1.1ca5b500035fc07c389a9e5cbfd78edbp1,
+    0x1.bb2c2cp-4
+  },
+  { // Entry 75
+    -0x1.24b0ebfffcc32ee1b9b739e2a4c7d059p3,
+    0x1.bf0970p-14
+  },
+  { // Entry 76
+    -0x1.669915000230d74fa2da2f40bbdf4469p3,
+    0x1.c7fffep-17
+  },
+  { // Entry 77
+    -0x1.954aeedf4d5f5fb7c474a35723b4e707p-1,
+    0x1.cffffep-2
+  },
+  { // Entry 78
+    -0x1.92e76afffcd449b3ac5d412b622f78a8p-4,
+    0x1.d008e4p-1
+  },
+  { // Entry 79
+    -0x1.ffa24f1c1233a9f8e8ae684edf89313fp-5,
+    0x1.e10040p-1
+  },
+  { // Entry 80
+    -0x1.117889fffffbdf8a5cd7c34f7246f3cfp1,
+    0x1.e39bb4p-4
+  },
+  { // Entry 81
+    -0x1.894ac2dcdde549d0d0922b5b4f54e028p-5,
+    0x1.e7fffep-1
+  },
+  { // Entry 82
+    -0x1.381d36ffe60eb1dfb0686574074223e7p-5,
+    0x1.ecdc1cp-1
+  },
+  { // Entry 83
+    0x1.d14973edb3656c771e18eca84bc94c76p4,
+    0x1.effffep41
+  },
+  { // Entry 84
+    -0x1.efea18fff1115e81636f53b65665e16ep-6,
+    0x1.f0bc20p-1
+  },
+  { // Entry 85
+    -0x1.a5b584ffdad31147d1140b1694740ad7p-6,
+    0x1.f2fd60p-1
+  },
+  { // Entry 86
+    -0x1.62b35affdf0a2429284b006b680bd1bep-6,
+    0x1.f508e4p-1
+  },
+  { // Entry 87
+    -0x1.0cb140ffff9f8f1e06e7f9af0a531a5bp1,
+    0x1.f600dcp-4
+  },
+  { // Entry 88
+    -0x1.0bfe70eb451ad09a7cb75c1eedfa6150p1,
+    0x1.f8c010p-4
+  },
+  { // Entry 89
+    -0x1.70c8c50dce246dd6bcb0461e7dc4937ep-7,
+    0x1.fa4522p-1
+  },
+  { // Entry 90
+    -0x1.416a71b773a2c3e3980b11efd1a197b5p-8,
+    0x1.fd7ebep-1
+  },
+  { // Entry 91
+    -0x1.c0c674621c5b474a430e13570c580388p-9,
+    0x1.fe3ffep-1
+  },
+  { // Entry 92
+    -0x1.04863cfffbbf7edb167cb60df3f3d599p-9,
+    0x1.fefbbcp-1
+  },
+  { // Entry 93
+    -0x1.0a5ddf00004ebf2a6feee99d5bddde34p1,
+    0x1.ff353cp-4
+  },
+  { // Entry 94
+    -0x1.d80366485b747247a45bb9a470179df1p-15,
+    0x1.fff8a0p-1
+  },
+  { // Entry 95
+    -0x1.d1cb7fea86c49f63074b0d445fb65014p3,
+    0x1.fffff0p-22
+  },
+  { // Entry 96
+    0x1.d1cb7dea86bc9f62dca06199b5053f03p3,
+    0x1.fffff0p20
+  },
+  { // Entry 97
+    -0x1.00000200000555556555558888893333p-22,
+    0x1.fffff8p-1
+  },
+  { // Entry 98
+    -0x1.00000100000155555755555888888dddp-23,
+    0x1.fffffcp-1
+  },
+  { // Entry 99
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 100
+    -0x1.62e43115a8fb47c3a7c2e76a80cca9a5p-2,
+    0x1.6a09e6p-1
+  },
+  { // Entry 101
+    -0x1.da391a70d28a24641626f5e9155324b5p-3,
+    0x1.962b60p-1
+  },
+  { // Entry 102
+    -0x1.06fbe6a4e25295f80fb2274afe6d3bacp-3,
+    0x1.c24cdap-1
+  },
+  { // Entry 103
+    -0x1.1e0a6d053425d3d6528aa717ecc9a578p-5,
+    0x1.ee6e54p-1
+  },
+  { // Entry 104
+    0x1.9e549c3779f093451892a1fe4e67b50ep-5,
+    0x1.0d47e6p0
+  },
+  { // Entry 105
+    0x1.08e0b9f3a7944bab3ecb56d6a7ff03b5p-3,
+    0x1.2358a2p0
+  },
+  { // Entry 106
+    0x1.9e645d60ff198986479346d164ecad7ep-3,
+    0x1.39695ep0
+  },
+  { // Entry 107
+    0x1.14dd670cac0212506bf72fb762d8a7dbp-2,
+    0x1.4f7a1ap0
+  },
+  { // Entry 108
+    0x1.561819aca49de6b1d1ccda1095c74502p-2,
+    0x1.658ad6p0
+  },
+  { // Entry 109
+    0x1.936a7c496c3e21406af9f4ac9beac6a5p-2,
+    0x1.7b9b92p0
+  },
+  { // Entry 110
+    0x1.cd45a8d7e3403f5278d5e3d566349f75p-2,
+    0x1.91ac4ep0
+  },
+  { // Entry 111
+    0x1.02044831211ed0068efa4c2a8b9870bfp-1,
+    0x1.a7bd0ap0
+  },
+  { // Entry 112
+    0x1.1c01d5f6d3a50d31c45cbfddd0272765p-1,
+    0x1.bdcdc6p0
+  },
+  { // Entry 113
+    0x1.34bde46fd84fca43ba3f4799acab10ffp-1,
+    0x1.d3de82p0
+  },
+  { // Entry 114
+    0x1.4c5618136a3221d84476b78353fabc80p-1,
+    0x1.e9ef3ep0
+  },
+  { // Entry 115
+    0x1.62e429efa395f35781c7670787e58c2bp-1,
+    0x1.fffffap0
+  },
+  { // Entry 116
+    -0x1.62e43115a8fb47c3a7c2e76a80cca9a5p-2,
+    0x1.6a09e6p-1
+  },
+  { // Entry 117
+    -0x1.24cfd09514bae9e21501d1a28c37d51ep-2,
+    0x1.80aa84p-1
+  },
+  { // Entry 118
+    -0x1.d4902a7f6a1d18da241dffb42a0818edp-3,
+    0x1.974b22p-1
+  },
+  { // Entry 119
+    -0x1.65d5607cc85baba26e2faf78865dc991p-3,
+    0x1.adebc0p-1
+  },
+  { // Entry 120
+    -0x1.f991d8f6e2f011943d5a6a60cd646002p-4,
+    0x1.c48c5ep-1
+  },
+  { // Entry 121
+    -0x1.31b9a995502d59241500cd1ce955f5c4p-4,
+    0x1.db2cfcp-1
+  },
+  { // Entry 122
+    -0x1.ccb7994bda818c26cc15fca660f364ecp-6,
+    0x1.f1cd9ap-1
+  },
+  { // Entry 123
+    0x1.0b9492bd99570e8a2a2f5a7f59644b42p-6,
+    0x1.04371cp0
+  },
+  { // Entry 124
+    0x1.e2705e9cc554d8b565433c8fad2db164p-5,
+    0x1.0f876cp0
+  },
+  { // Entry 125
+    0x1.986d321688b074a21eb26b41679ee309p-4,
+    0x1.1ad7bcp0
+  },
+  { // Entry 126
+    0x1.1c89919fb208ebda275d6fee75577a43p-3,
+    0x1.26280cp0
+  },
+  { // Entry 127
+    0x1.69d463db5d0d8cbc5da8bd2c1f5d2953p-3,
+    0x1.31785cp0
+  },
+  { // Entry 128
+    0x1.b44f87381611ab2806d6f00d213de2cfp-3,
+    0x1.3cc8acp0
+  },
+  { // Entry 129
+    0x1.fc2d80e5311b3f7e05f26b963044ea08p-3,
+    0x1.4818fcp0
+  },
+  { // Entry 130
+    0x1.20cdd9262c59a7726689f4fe5ffa58fep-2,
+    0x1.53694cp0
+  },
+  { // Entry 131
+    0x1.426182db20e23d0b473ae1c2d1975c3fp-2,
+    0x1.5eb99cp0
+  },
+  { // Entry 132
+    0x1.62e42ec99e429eeb7fcbe6f58eff3117p-2,
+    0x1.6a09e6p0
+  },
+  { // Entry 133
+    -0x1.269621134db92783beb7676c0aa9c2a3p-2,
+    0x1.80p-1
+  },
+  { // Entry 134
+    -0x1.89fa484d355b5e186f5662b3da3e745bp-3,
+    0x1.a66666p-1
+  },
+  { // Entry 135
+    -0x1.af8e892d15de87e2e9e59dff5c0633bep-4,
+    0x1.ccccccp-1
+  },
+  { // Entry 136
+    -0x1.9ecebcb597ea1bb43d896f584759744ap-6,
+    0x1.f33332p-1
+  },
+  { // Entry 137
+    0x1.8fb04b8da65ceb85a2edb7d0ff0ad2d3p-5,
+    0x1.0cccccp0
+  },
+  { // Entry 138
+    0x1.e27076e2af2e5e9ea87ffe1fe9e155dbp-4,
+    0x1.20p0
+  },
+  { // Entry 139
+    0x1.756506739ebaf1cd58855d231e777a59p-3,
+    0x1.333334p0
+  },
+  { // Entry 140
+    0x1.f18dce2898f5ba919d825d9696c6c774p-3,
+    0x1.466668p0
+  },
+  { // Entry 141
+    0x1.334ea564424013b7739afbc9478741b5p-2,
+    0x1.59999cp0
+  },
+  { // Entry 142
+    0x1.6aac0d0fe3871ab60d70d41e954c2bd3p-2,
+    0x1.6cccd0p0
+  },
+  { // Entry 143
+    0x1.9f323ecbf984bf2b68d766f405221819p-2,
+    0x1.80p0
+  },
+  { // Entry 144
+    0.0,
+    0x1.p0
+  },
+  { // Entry 145
+    0x1.8663fd6538c872349ec1a85e05ec5fb5p-4,
+    0x1.19999ap0
+  },
+  { // Entry 146
+    0x1.756506739ebaf1cd58855d231e777a59p-3,
+    0x1.333334p0
+  },
+  { // Entry 147
+    0x1.0ca93b6f56afbacd07973b0a3c67fc47p-2,
+    0x1.4ccccep0
+  },
+  { // Entry 148
+    0x1.588c32237c6aefe96e1db27c46710d39p-2,
+    0x1.666668p0
+  },
+  { // Entry 149
+    0x1.9f3244214ed68647ddc799823e05a9b1p-2,
+    0x1.800002p0
+  },
+  { // Entry 150
+    0x1.e148a7a27268594dfd4dd6c301fece79p-2,
+    0x1.99999cp0
+  },
+  { // Entry 151
+    0x1.0fae84dc95e1a7d9897472d55a7563e8p-1,
+    0x1.b33336p0
+  },
+  { // Entry 152
+    0x1.2cf2633bc7fc9d9d9929319aa918822cp-1,
+    0x1.ccccd0p0
+  },
+  { // Entry 153
+    0x1.48a1165df274ab7963f8550dcbfb6aebp-1,
+    0x1.e6666ap0
+  },
+  { // Entry 154
+    0x1.62e42fefa39ef35793c7673007e5ed5ep-1,
+    0x1.p1
+  },
+  { // Entry 155
+    0x1.1542457337d42e1c6b73c89d862ba171p6,
+    0x1.p100
+  },
+  { // Entry 156
+    0x1.15a3de7291226038f89b79079dad1c89p6,
+    0x1.19999ap100
+  },
+  { // Entry 157
+    0x1.15fcf7f671a38b9552200b4c17badd2fp6,
+    0x1.333334p100
+  },
+  { // Entry 158
+    0x1.164eeeaea72addd7387b5fd89068096ep6,
+    0x1.4ccccep100
+  },
+  { // Entry 159
+    0x1.169ad1a55b50990c54e1e6500272127fp6,
+    0x1.666668p100
+  },
+  { // Entry 160
+    0x1.16e177b7592304a2b35190370869a71bp6,
+    0x1.800002p100
+  },
+  { // Entry 161
+    0x1.17238e1ada469675b9711674492da040p6,
+    0x1.99999cp100
+  },
+  { // Entry 162
+    0x1.1761a27cf0fff16c1e86b18330e08c39p6,
+    0x1.b33336p100
+  },
+  { // Entry 163
+    0x1.179c2a39af642757a6a61b00bb7dd276p6,
+    0x1.ccccd0p100
+  },
+  { // Entry 164
+    0x1.17d3879ff3b917735e3bb947a1c39847p6,
+    0x1.e6666ap100
+  },
+  { // Entry 165
+    0x1.18080dd3171b6c031a9b576be63b6d4cp6,
+    0x1.p101
+  },
+  { // Entry 166
+    -0x1.0000080000555559555588888b333357p-20,
+    0x1.ffffe0p-1
+  },
+  { // Entry 167
+    -0x1.0000040000155555d5555888889ddddep-21,
+    0x1.fffff0p-1
+  },
+  { // Entry 168
+    0.0,
+    0x1.p0
+  },
+  { // Entry 169
+    0x1.fffff800002aaaa9aaaab11110e66667p-22,
+    0x1.000008p0
+  },
+  { // Entry 170
+    0x1.fffff00000aaaaa2aaab11110bbbbc04p-21,
+    0x1.000010p0
+  },
+  { // Entry 171
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 172
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 173
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 174
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 175
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 176
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 177
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 178
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 179
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 180
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 181
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 182
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 183
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 184
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 185
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 186
+    0x1.62e42feba39ef15793c611dab1909808p6,
+    0x1.fffffep127
+  },
+  { // Entry 187
+    -0x1.9d1d9fccf4770743f2061e1de931a650p6,
+    0x1.p-149
+  },
+  { // Entry 188
+    -0x1.62e436bdd09a876194940b96cb28fd7fp-2,
+    0x1.6a09e4p-1
+  },
+  { // Entry 189
+    -0x1.62e43115a8fb47c3a7c2e76a80cca9a5p-2,
+    0x1.6a09e6p-1
+  },
+  { // Entry 190
+    -0x1.62e42b6d81640825bf89d8b8d9d0ff58p-2,
+    0x1.6a09e8p-1
+  },
+  { // Entry 191
+    0x1.62e4292176a35f4d92fac2c944a2dd3dp-2,
+    0x1.6a09e4p0
+  },
+  { // Entry 192
+    0x1.62e42ec99e429eeb7fcbe6f58eff3117p-2,
+    0x1.6a09e6p0
+  },
+  { // Entry 193
+    0x1.62e43471c5d9de896804f5a735fadb65p-2,
+    0x1.6a09e8p0
+  },
+  { // Entry 194
+    -0x1.62e431efa39ff357947211db3290986fp-1,
+    0x1.fffffep-2
+  },
+  { // Entry 195
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep-1,
+    0x1.p-1
+  },
+  { // Entry 196
+    -0x1.62e42befa3a2f3578e7211e2b2908b3cp-1,
+    0x1.000002p-1
+  },
+  { // Entry 197
+    -0x1.26962668a3120b11fac40bc7b22b5a8dp-2,
+    0x1.7ffffep-1
+  },
+  { // Entry 198
+    -0x1.269621134db92783beb7676c0aa9c2a3p-2,
+    0x1.80p-1
+  },
+  { // Entry 199
+    -0x1.26961bbdf867606749c734ddd1c6310bp-2,
+    0x1.800002p-1
+  },
+  { // Entry 200
+    0x1.9f323976a42bdb9d2ccac2985da0802fp-2,
+    0x1.7ffffep0
+  },
+  { // Entry 201
+    0x1.9f323ecbf984bf2b68d766f405221819p-2,
+    0x1.80p0
+  },
+  { // Entry 202
+    0x1.9f3244214ed68647ddc799823e05a9b1p-2,
+    0x1.800002p0
+  },
+  { // Entry 203
+    0x1.54de6ee78989a9acfc875c1d45e16490p-9,
+    0x1.00aaa8p0
+  },
+  { // Entry 204
+    0x1.54e26c3eab6ea24115a4ecbc6c21c3dep-9,
+    0x1.00aaaap0
+  },
+  { // Entry 205
+    0x1.54e66995c55e3ad40cb2b01d77b8b63fp-9,
+    0x1.00aaacp0
+  },
+  { // Entry 206
+    0x1.62e42eefa39e7357937211da729097d5p0,
+    0x1.fffffep1
+  },
+  { // Entry 207
+    0x1.62e42fefa39ef35793c7673007e5ed5ep0,
+    0x1.p2
+  },
+  { // Entry 208
+    0x1.62e431efa39cf357967211d6b2909e6fp0,
+    0x1.000002p2
+  },
+  { // Entry 209
+    0x1.62e42defa39df357931cbc84dd3b424dp-1,
+    0x1.fffffep0
+  },
+  { // Entry 210
+    0x1.62e42fefa39ef35793c7673007e5ed5ep-1,
+    0x1.p1
+  },
+  { // Entry 211
+    0x1.62e433efa39af357991cbc7d5d3b4f80p-1,
+    0x1.000002p1
+  },
+  { // Entry 212
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 213
+    0.0,
+    0x1.p0
+  },
+  { // Entry 214
+    0x1.fffffe000002aaaaa6aaaab111110666p-24,
+    0x1.000002p0
+  },
+  { // Entry 215
+    -0x1.62e431efa39ff357947211db3290986fp-1,
+    0x1.fffffep-2
+  },
+  { // Entry 216
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep-1,
+    0x1.p-1
+  },
+  { // Entry 217
+    -0x1.62e42befa3a2f3578e7211e2b2908b3cp-1,
+    0x1.000002p-1
+  },
+  { // Entry 218
+    -0x1.62e430efa39f7357941cbc859d3b42e7p0,
+    0x1.fffffep-3
+  },
+  { // Entry 219
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep0,
+    0x1.p-2
+  },
+  { // Entry 220
+    -0x1.62e42defa3a0f357911cbc895d3b3c4dp0,
+    0x1.000002p-2
+  },
+  { // Entry 221
+    -0x1.0a2b2473bab77681af00380ed0971ccbp1,
+    0x1.fffffep-4
+  },
+  { // Entry 222
+    -0x1.0a2b23f3bab73681aed58d6405ec7206p1,
+    0x1.p-3
+  },
+  { // Entry 223
+    -0x1.0a2b22f3bab83681ad803810b097197ep1,
+    0x1.000002p-3
+  },
+  { // Entry 224
+    -0x1.62e4306fa39f335793f211dad2909822p1,
+    0x1.fffffep-5
+  },
+  { // Entry 225
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep1,
+    0x1.p-4
+  },
+  { // Entry 226
+    -0x1.62e42eefa39ff357927211dcb29094d5p1,
+    0x1.000002p-4
+  },
+  { // Entry 227
+    -0x1.bb9d3c6b8c86f02d78e3eba6d48a137ap1,
+    0x1.fffffep-6
+  },
+  { // Entry 228
+    -0x1.bb9d3beb8c86b02d78b940fc09df68b6p1,
+    0x1.p-5
+  },
+  { // Entry 229
+    -0x1.bb9d3aeb8c87b02d7763eba8b48a102dp1,
+    0x1.000002p-5
+  },
+  { // Entry 230
+    -0x1.0a2b2433bab75681aeeae2b96b41c769p2,
+    0x1.fffffep-7
+  },
+  { // Entry 231
+    -0x1.0a2b23f3bab73681aed58d6405ec7206p2,
+    0x1.p-6
+  },
+  { // Entry 232
+    -0x1.0a2b2373bab7b681ae2ae2ba5b41c5c2p2,
+    0x1.000002p-6
+  },
+  { // Entry 233
+    -0x1.3687aa31af2b34eca163cf9f6c3e8514p2,
+    0x1.fffffep-8
+  },
+  { // Entry 234
+    -0x1.3687a9f1af2b14eca14e7a4a06e92fb2p2,
+    0x1.p-7
+  },
+  { // Entry 235
+    -0x1.3687a971af2b94eca0a3cfa05c3e836ep2,
+    0x1.000002p-7
+  },
+  { // Entry 236
+    -0x1.62e4302fa39f135793dcbc856d3b42c0p2,
+    0x1.fffffep-9
+  },
+  { // Entry 237
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep2,
+    0x1.p-8
+  },
+  { // Entry 238
+    -0x1.62e42f6fa39f7357931cbc865d3b411ap2,
+    0x1.000002p-8
+  },
+  { // Entry 239
+    -0x1.8f40b62d9812f1c28655a96b6e38006cp2,
+    0x1.fffffep-10
+  },
+  { // Entry 240
+    -0x1.8f40b5ed9812d1c28640541608e2ab0ap2,
+    0x1.p-9
+  },
+  { // Entry 241
+    -0x1.8f40b56d981351c28595a96c5e37fec6p2,
+    0x1.000002p-9
+  },
+  { // Entry 242
+    -0x1.bb9d3c2b8c86d02d78ce96516f34be18p2,
+    0x1.fffffep-11
+  },
+  { // Entry 243
+    -0x1.bb9d3beb8c86b02d78b940fc09df68b6p2,
+    0x1.p-10
+  },
+  { // Entry 244
+    -0x1.bb9d3b6b8c87302d780e96525f34bc71p2,
+    0x1.000002p-10
+  },
+  { // Entry 245
+    -0x1.20596712b4f135b7281cae81b9157b8dp3,
+    0x1.fffffep-14
+  },
+  { // Entry 246
+    -0x1.205966f2b4f125b7281203d7066ad0dcp3,
+    0x1.p-13
+  },
+  { // Entry 247
+    -0x1.205966b2b4f165b727bcae8231157abap3,
+    0x1.000002p-13
+  },
+  { // Entry 248
+    -0x1.20596712b4f135b7281cae81b9157b8dp3,
+    0x1.fffffep-14
+  },
+  { // Entry 249
+    -0x1.205966f2b4f125b7281203d7066ad0dcp3,
+    0x1.p-13
+  },
+  { // Entry 250
+    -0x1.205966b2b4f165b727bcae8231157abap3,
+    0x1.000002p-13
+  },
+  { // Entry 251
+    -0x1.0a2b2473bab77681af00380ed0971ccbp1,
+    0x1.fffffep-4
+  },
+  { // Entry 252
+    -0x1.0a2b23f3bab73681aed58d6405ec7206p1,
+    0x1.p-3
+  },
+  { // Entry 253
+    -0x1.0a2b22f3bab83681ad803810b097197ep1,
+    0x1.000002p-3
+  },
+  { // Entry 254
+    -0x1.1178f14710961bedaf9f799a53afc33dp-3,
+    0x1.bffffep-1
+  },
+  { // Entry 255
+    -0x1.1178e8227e47bde338b41fc72de81e3bp-3,
+    0x1.c0p-1
+  },
+  { // Entry 256
+    -0x1.1178defdec03d2c915604897971b7658p-3,
+    0x1.c00002p-1
+  },
+  { // Entry 257
+    -0x1.62e4306fa39f335793f211dad2909822p1,
+    0x1.fffffep-5
+  },
+  { // Entry 258
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep1,
+    0x1.p-4
+  },
+  { // Entry 259
+    -0x1.62e42eefa39ff357927211dcb29094d5p1,
+    0x1.000002p-4
+  },
+  { // Entry 260
+    -0x1.08599c6af4ba93c693b13122f6824a8bp-4,
+    0x1.dffffep-1
+  },
+  { // Entry 261
+    -0x1.08598b59e3a0688a3fd9bf503372c12fp-4,
+    0x1.e0p-1
+  },
+  { // Entry 262
+    -0x1.08597a48d29871a4649d0a66ccbd5edbp-4,
+    0x1.e00002p-1
+  },
+  { // Entry 263
+    -0x1.bb9d3c6b8c86f02d78e3eba6d48a137ap1,
+    0x1.fffffep-6
+  },
+  { // Entry 264
+    -0x1.bb9d3beb8c86b02d78b940fc09df68b6p1,
+    0x1.p-5
+  },
+  { // Entry 265
+    -0x1.bb9d3aeb8c87b02d7763eba8b48a102dp1,
+    0x1.000002p-5
+  },
+  { // Entry 266
+    -0x1.0415f9a6b665d7a7b9958d7d28f62a74p-5,
+    0x1.effffep-1
+  },
+  { // Entry 267
+    -0x1.0415d89e7444470173c75d4d8889de0ep-5,
+    0x1.f0p-1
+  },
+  { // Entry 268
+    -0x1.0415b7963244cf65919a578b2daa29d5p-5,
+    0x1.f00002p-1
+  },
+  { // Entry 269
+    -0x1.0a2b2433bab75681aeeae2b96b41c769p2,
+    0x1.fffffep-7
+  },
+  { // Entry 270
+    -0x1.0a2b23f3bab73681aed58d6405ec7206p2,
+    0x1.p-6
+  },
+  { // Entry 271
+    -0x1.0a2b2373bab7b681ae2ae2ba5b41c5c2p2,
+    0x1.000002p-6
+  },
+  { // Entry 272
+    -0x1.0205a68d45e67ed01e10e322bd43a170p-6,
+    0x1.f7fffep-1
+  },
+  { // Entry 273
+    -0x1.020565893584749f23a105b9c7bb9a6fp-6,
+    0x1.f8p-1
+  },
+  { // Entry 274
+    -0x1.02052485256476af6f4daabd139b5e57p-6,
+    0x1.f80002p-1
+  },
+  { // Entry 275
+    -0x1.3687aa31af2b34eca163cf9f6c3e8514p2,
+    0x1.fffffep-8
+  },
+  { // Entry 276
+    -0x1.3687a9f1af2b14eca14e7a4a06e92fb2p2,
+    0x1.p-7
+  },
+  { // Entry 277
+    -0x1.3687a971af2b94eca0a3cfa05c3e836ep2,
+    0x1.000002p-7
+  },
+  { // Entry 278
+    -0x1.0101d85a923025b54cbaae499d5e40bfp-7,
+    0x1.fbfffep-1
+  },
+  { // Entry 279
+    -0x1.010157588de7128ccc5a82f9da00f48bp-7,
+    0x1.fcp-1
+  },
+  { // Entry 280
+    -0x1.0100d6568a200574745b39f0aae26685p-7,
+    0x1.fc0002p-1
+  },
+  { // Entry 281
+    -0x1.62e4302fa39f135793dcbc856d3b42c0p2,
+    0x1.fffffep-9
+  },
+  { // Entry 282
+    -0x1.62e42fefa39ef35793c7673007e5ed5ep2,
+    0x1.p-8
+  },
+  { // Entry 283
+    -0x1.62e42f6fa39f7357931cbc865d3b411ap2,
+    0x1.000002p-8
+  },
+  { // Entry 284
+    -0x1.008156968a355a68f2be9b035772c9c3p-8,
+    0x1.fdfffep-1
+  },
+  { // Entry 285
+    -0x1.0080559588b357e598e33d8d9db37a29p-8,
+    0x1.fep-1
+  },
+  { // Entry 286
+    -0x1.007f549488335866440de7a1f2084736p-8,
+    0x1.fe0002p-1
+  },
+  { // Entry 287
+    -0x1.8f40b62d9812f1c28655a96b6e38006cp2,
+    0x1.fffffep-10
+  },
+  { // Entry 288
+    -0x1.8f40b5ed9812d1c28640541608e2ab0ap2,
+    0x1.p-9
+  },
+  { // Entry 289
+    -0x1.8f40b56d981351c28595a96c5e37fec6p2,
+    0x1.000002p-9
+  },
+  { // Entry 290
+    -0x1.0042165dd9caff419b1eccdf720a36d2p-9,
+    0x1.fefffep-1
+  },
+  { // Entry 291
+    -0x1.0040155d5889de70671eeec0bfcefe53p-9,
+    0x1.ffp-1
+  },
+  { // Entry 292
+    -0x1.003e145cd94abf2033bf71dc3028520cp-9,
+    0x1.ff0002p-1
+  },
+  { // Entry 293
+    -0x1.bb9d3c2b8c86d02d78ce96516f34be18p2,
+    0x1.fffffep-11
+  },
+  { // Entry 294
+    -0x1.bb9d3beb8c86b02d78b940fc09df68b6p2,
+    0x1.p-10
+  },
+  { // Entry 295
+    -0x1.bb9d3b6b8c87302d780e96525f34bc71p2,
+    0x1.000002p-10
+  },
+  { // Entry 296
+    -0x1.0024065697999797f377cb852750240bp-10,
+    0x1.ff7ffep-1
+  },
+  { // Entry 297
+    -0x1.00200556558893357cd7e1f486bd0705p-10,
+    0x1.ff80p-1
+  },
+  { // Entry 298
+    -0x1.001c045617798f93464c0067a7eaae4fp-10,
+    0x1.ff8002p-1
+  },
+  { // Entry 299
+    -0x1.20596712b4f135b7281cae81b9157b8dp3,
+    0x1.fffffep-14
+  },
+  { // Entry 300
+    -0x1.205966f2b4f125b7281203d7066ad0dcp3,
+    0x1.p-13
+  },
+  { // Entry 301
+    -0x1.205966b2b4f165b727bcae8231157abap3,
+    0x1.000002p-13
+  },
+  { // Entry 302
+    -0x1.002401156dd698a14a193857b6b2e2bdp-13,
+    0x1.ffeffep-1
+  },
+  { // Entry 303
+    -0x1.0004001555d558889dde702b028c9996p-13,
+    0x1.fff0p-1
+  },
+  { // Entry 304
+    -0x1.ffc7fe2abbac310fe54784015d23a61dp-14,
+    0x1.fff002p-1
+  },
+  { // Entry 305
+    HUGE_VALF,
+    HUGE_VALF
+  },
+  { // Entry 306
+    0x1.62e42feba39ef15793c611dab1909808p6,
+    0x1.fffffep127
+  },
+  { // Entry 307
+    0x1.62e42fe7a39eeb5793bcbc854d3b429ap6,
+    0x1.fffffcp127
+  },
+  { // Entry 308
+    0x1.250d0505fece83f5f3328cc322f65153p0,
+    0x1.921fb6p1
+  },
+  { // Entry 309
+    0x1.ce6bb438b3fc2928a53b64ac7c0d6a91p-2,
+    0x1.921fb6p0
+  },
+  { // Entry 310
+    0x1.fffffe000002aaaaa6aaaab111110666p-24,
+    0x1.000002p0
+  },
+  { // Entry 311
+    0.0,
+    0x1.p0
+  },
+  { // Entry 312
+    -0x1.000000800000555555955555888888b3p-24,
+    0x1.fffffep-1
+  },
+  { // Entry 313
+    -0x1.eeb9574d26837b0d04a6d367277ce056p-3,
+    0x1.921fb6p-1
+  },
+  { // Entry 314
+    -0x1.5d589f27e5107f8a356d9ee8ad1baae4p6,
+    0x1.000002p-126
+  },
+  { // Entry 315
+    -0x1.5d589f2fe510778a3578499347c655a9p6,
+    0x1.p-126
+  },
+  { // Entry 316
+    -0x1.5d589f37e5107f8a3582f43e0271006dp6,
+    0x1.fffffcp-127
+  },
+  { // Entry 317
+    -0x1.5d589f3fe510978a35cd9ee99d1bae31p6,
+    0x1.fffff8p-127
+  },
+  { // Entry 318
+    -0x1.9a57d76d152fc95d42de8f4f8921da75p6,
+    0x1.p-148
+  },
+  { // Entry 319
+    -0x1.9d1d9fccf4770743f2061e1de931a650p6,
+    0x1.p-149
+  },
+  { // Entry 320
+    -HUGE_VALF,
+    0.0f
+  },
+  { // Entry 321
+    -HUGE_VALF,
+    -0.0f
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_logf, logf_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_logf_intel_data)/sizeof(logf_intel_data_t); i++) {
+    EXPECT_FLOAT_EQ(g_logf_intel_data[i].expected, logf(g_logf_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_pow_test.cpp b/tests/math_pow_test.cpp
new file mode 100644
index 0000000..c185424
--- /dev/null
+++ b/tests/math_pow_test.cpp
@@ -0,0 +1,3300 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  double expected;
+  double x_call_data;
+  double y_call_data;
+} pow_intel_data_t;
+
+static pow_intel_data_t g_pow_intel_data[] = {
+  { // Entry 0
+    0x1.p0,
+    -0x1.0p-10, 0.0
+  },
+  { // Entry 1
+    0x1.p0,
+    -0x1.0p-20, 0.0
+  },
+  { // Entry 2
+    -HUGE_VAL,
+    -HUGE_VAL, 0x1.0000000000001p52
+  },
+  { // Entry 3
+    -0x1.ffffffffffffe0000000000001ffffffp20,
+    -0x1.0000000000001p-21, -0x1.0p0
+  },
+  { // Entry 4
+    0x1.p0,
+    -0x1.0000000000001p-41, 0.0
+  },
+  { // Entry 5
+    0x1.000000000000a000000000002dp-410,
+    -0x1.0000000000001p-41, 0x1.4p3
+  },
+  { // Entry 6
+    0x1.9241b707f6dadff955fd89193b67d331p-76,
+    -0x1.0000000000009p0, -0x1.7364d9364d93ep54
+  },
+  { // Entry 7
+    0x1.ffffe00000fffffabaaabeffffc3b111p-1,
+    -0x1.0000000000010p0, -0x1.0p28
+  },
+  { // Entry 8
+    -0x1.fffffeffac00403b0c6d424acd900953p964,
+    -0x1.00000000220p-1, -0x1.e28p9
+  },
+  { // Entry 9
+    0x1.ffe88f898fad6805ef5425ca3572f1e8p705,
+    -0x1.0000044p-1, -0x1.610p9
+  },
+  { // Entry 10
+    -0x1.fff0007ffc001fff0007ffc001fff0p40,
+    -0x1.00080p-41, -0x1.0p0
+  },
+  { // Entry 11
+    0x1.ff601b7c9059582e9c5cd4bde021f462p409,
+    -0x1.00080p-41, -0x1.4p3
+  },
+  { // Entry 12
+    -0x1.002802801400500080p200,
+    -0x1.00080p40, 0x1.4p2
+  },
+  { // Entry 13
+    0x1.ffa00a7f14c337fcecffc107244f96dfp245,
+    -0x1.0008000000f14p-41, -0x1.8p2
+  },
+  { // Entry 14
+    0x1.ff8011fd3be577fec85ffc5d60b0334ep-321,
+    -0x1.000800000e484p40, -0x1.0p3
+  },
+  { // Entry 15
+    0x1.6b3c46415430c004e9fd0b35f8ec6fd5p-1,
+    -0x1.046e8bfffffc2p0, -0x1.4p4
+  },
+  { // Entry 16
+    0.0,
+    -0x1.518p-1065, 0x1.0p1023
+  },
+  { // Entry 17
+    0x1.20000060000008p-81,
+    -0x1.8000004p-41, 0x1.0p1
+  },
+  { // Entry 18
+    0x1.c3d6a2157b623407e8c821289ebac2b6p-1,
+    -0x1.fffffbfffffffp-1, 0x1.0p20
+  },
+  { // Entry 19
+    -0x1.00000060000030000011000006300002p0,
+    -0x1.ffffffbffffffp-1, -0x1.8p1
+  },
+  { // Entry 20
+    -0x1.000000e00000a8000062000033a00018p35,
+    -0x1.ffffffbffffffp-6, -0x1.cp2
+  },
+  { // Entry 21
+    -0x1.000000e00000a8000062000033a00018p280,
+    -0x1.ffffffbffffffp-41, -0x1.cp2
+  },
+  { // Entry 22
+    -0x1.000000e00000a8000062000033a00018p-287,
+    -0x1.ffffffbffffffp40, -0x1.cp2
+  },
+  { // Entry 23
+    -0x1.fffffe40000038000030fffff49ffffdp286,
+    -0x1.ffffffbffffffp40, 0x1.cp2
+  },
+  { // Entry 24
+    0x1.ffffff80000008p-21,
+    -0x1.ffffffcp-11, 0x1.0p1
+  },
+  { // Entry 25
+    -0x1.000000000100080000010010004001p40,
+    -0x1.fffffffffdfffp-41, -0x1.0p0
+  },
+  { // Entry 26
+    -0x1.00000000000c98000000009e9a40p40,
+    -0x1.ffffffffffe6dp-41, -0x1.0p0
+  },
+  { // Entry 27
+    -0x1.fffffffdffffe00100000fffaaaaaaaap-1,
+    -0x1.ffffffffffffep-1, 0x1.00001p20
+  },
+  { // Entry 28
+    -0x1.0000000000000800000000000040p0,
+    -0x1.fffffffffffffp-1, -0x1.0p0
+  },
+  { // Entry 29
+    -HUGE_VAL,
+    -0x1.fffffffffffffp1023, 0x1.0000000000001p52
+  },
+  { // Entry 30
+    0x1.fda6a1be3e9d47fc84293281e77aa21ap-1,
+    0x1.0p-2, 0x1.b2cb2cb2cb2d0p-9
+  },
+  { // Entry 31
+    0.0,
+    0x1.0p-512, 0x1.0ccp1
+  },
+  { // Entry 32
+    0x1.f9b3a3820980938687e8bf7ff06bc42cp-914,
+    0x1.0p-1035, 0x1.c3a83a83a83a5p-1
+  },
+  { // Entry 33
+    0.0,
+    0x1.0p-1074, 0x1.0p1023
+  },
+  { // Entry 34
+    0.0,
+    0x1.0p-1074, 0x1.0000000000001p0
+  },
+  { // Entry 35
+    0x1.51cb453b954f5305fd8d61e650e8d0d5p-967,
+    0x1.0p-1074, 0x1.cccccccccccccp-1
+  },
+  { // Entry 36
+    0x1.fffffffd3a37a022a4bdf9482171d56fp1023,
+    0x1.0p1, 0x1.ffffffffff0p9
+  },
+  { // Entry 37
+    0x1.00000000000007ffffffffffffe0p-5,
+    0x1.0000000000001p-10, 0x1.0p-1
+  },
+  { // Entry 38
+    0x1.ae89f995ad5887ff46dd2362be6a8f23p-204,
+    0x1.0000000000001p-271, 0x1.7fffffffffffdp-1
+  },
+  { // Entry 39
+    0x1.2611186bae6a380002e6202c31b04d13p-38,
+    0x1.0000000000001p-462, 0x1.4f2094f2094f0p-4
+  },
+  { // Entry 40
+    0x1.6a09e667f3ecd2adb67223f9564b3422p-392,
+    0x1.0000000000001p-522, 0x1.7fffffffffffdp-1
+  },
+  { // Entry 41
+    0x1.9fdf8bcce543547d611ef13904022b8bp-493,
+    0x1.0000000000001p-547, 0x1.cccccccccccccp-1
+  },
+  { // Entry 42
+    0x1.91b501c2db5c8ffe81cc3effffe282e8p-290,
+    0x1.0000000000001p-643, 0x1.ccccccccccccap-2
+  },
+  { // Entry 43
+    0x1.a830fd0547202479c70c80b72a325d2fp-408,
+    0x1.0000000000001p-731, 0x1.1d41d41d41d44p-1
+  },
+  { // Entry 44
+    0x1.a9335df38e6e64cbdaa57750a0cfd5eep-291,
+    0x1.0000000000001p-733, 0x1.95810624dd2f7p-2
+  },
+  { // Entry 45
+    0x1.6a09e667f3d192a27b73577484a86dcdp-761,
+    0x1.0000000000001p-845, 0x1.cccccccccccccp-1
+  },
+  { // Entry 46
+    0x1.bdb8cdadbe60a56dd61c4e04350cfa9ap-569,
+    0x1.0000000000001p-947, 0x1.3333333333331p-1
+  },
+  { // Entry 47
+    0x1.6a09e66d72c9c801840532577e605e07p904,
+    0x1.0000000000001p-1005, -0x1.cccccccccfa81p-1
+  },
+  { // Entry 48
+    0x1.fffffffffffaea6e0622a45b3589d771p1023,
+    0x1.0000000000001p1, 0x1.ffffffffffffdp9
+  },
+  { // Entry 49
+    0x1.e6102ba465044814b28a0a49216ef667p-349,
+    0x1.0000000000001p663, -0x1.0cccccccccccfp-1
+  },
+  { // Entry 50
+    0x1.ffffffffffd75b6d85de8fb3a7e2e826p-703,
+    0x1.0000000000001p936, -0x1.8000000000001p-1
+  },
+  { // Entry 51
+    0x1.ffffffffffffe0000000000001ffffffp-1024,
+    0x1.0000000000001p1023, -0x1.0p0
+  },
+  { // Entry 52
+    0x1.fffffffffffaea6e0622a4573589d771p1023,
+    0x1.0000000000002p2, 0x1.ffffffffffffdp8
+  },
+  { // Entry 53
+    0x1.000000000000080000000000029fffffp0,
+    0x1.0000000000004p0, 0x1.0000000000007p-3
+  },
+  { // Entry 54
+    0x1.00000000000007ffffffffff3920p0,
+    0x1.0000000000004p0, 0x1.ffffffffffce8p-4
+  },
+  { // Entry 55
+    0x1.fffffffffffaea6e0622a44f3589d771p1023,
+    0x1.0000000000004p4, 0x1.ffffffffffffdp7
+  },
+  { // Entry 56
+    0x1.fb9540d99258a80f86b71925aaf4421ep80,
+    0x1.0000000000007p1023, 0x1.4444444444430p-4
+  },
+  { // Entry 57
+    0x1.df905ef8e2507fd852712ed6cea98963p833,
+    0x1.0000000000011p1, 0x1.a0f3ea0697a0bp9
+  },
+  { // Entry 58
+    0x1.00000000000097ffffffffffd2e0p3,
+    0x1.0000000000013p6, 0x1.0p-1
+  },
+  { // Entry 59
+    0x1.000000000000d7ffffffffff77e0p0,
+    0x1.0000000000021p0, 0x1.a2e8ba2e8ba2ep-2
+  },
+  { // Entry 60
+    0x1.9476504b9baf343e3f75a2bd2e4caddbp738,
+    0x1.0000000000080p0, 0x1.0p54
+  },
+  { // Entry 61
+    0x1.fffff4e95e1f3fdcdd5e3d928f3a47f5p1023,
+    0x1.00000000000ffp1, 0x1.fffffffc0p9
+  },
+  { // Entry 62
+    0x1.ffffffff8e4de8083ac63f95bcb525fcp1023,
+    0x1.00000000000ffp2, 0x1.ffffffffffcp8
+  },
+  { // Entry 63
+    0x1.9476504b433552adbf253ad5a9e61e68p738,
+    0x1.00000000004p0, 0x1.0p51
+  },
+  { // Entry 64
+    0x1.6247eb03578637ff2cb93c93fe2f2473p-129,
+    0x1.00000000007p1, -0x1.011p7
+  },
+  { // Entry 65
+    0x1.87cea2e506d2ea9b21823d7557663fbap427,
+    0x1.00000000020p1023, 0x1.ac083126e978cp-2
+  },
+  { // Entry 66
+    0x1.ffffff2b0338080b257df31bb02ff70ap767,
+    0x1.000000000ffffp-1, -0x1.7fffffffd5ce2p9
+  },
+  { // Entry 67
+    0x1.ffd931035b394087164501473df23095p1023,
+    0x1.000000001p1, 0x1.fffff1fffffffp9
+  },
+  { // Entry 68
+    0x1.912b6dd6652df7fa0fbaffbc7b32d62ap953,
+    0x1.000000001b1efp-1, -0x1.dcd2f3ea06995p9
+  },
+  { // Entry 69
+    0x1.fffffff800000020c0003f7b7ffe8216p-1,
+    0x1.000000040p0, -0x1.ffffffffcffffp-1
+  },
+  { // Entry 70
+    0x1.ffffffc0000027fffff70000039ffffep-1024,
+    0x1.0000001ffffffp1023, -0x1.0p0
+  },
+  { // Entry 71
+    0x1.705df34f84e31387148153c7cf783a53p-1,
+    0x1.0000004p1, -0x1.e66666666666bp-2
+  },
+  { // Entry 72
+    0x1.1a16744c2ec0d8042410bf3e3a9014acp1,
+    0x1.0000004p2, 0x1.23d70a3d70a3bp-1
+  },
+  { // Entry 73
+    0x1.fff8001002b417ef588e21c5092e20c7p1023,
+    0x1.0000010p-1, -0x1.ffffffffffff9p9
+  },
+  { // Entry 74
+    0x1.a12f806c39105800d5ac38f6cb88d374p-2,
+    0x1.000001cp3, -0x1.ba2e8ba2e8ba2p-2
+  },
+  { // Entry 75
+    0x1.d72f7f354d86d0206ad7c9be9b478c7cp-885,
+    0x1.0000044p-1, 0x1.ba0f61c9107c9p9
+  },
+  { // Entry 76
+    0x1.915d1955b15fc08191e000bc8a9c8262p738,
+    0x1.00020p0, 0x1.0000040p24
+  },
+  { // Entry 77
+    0x1.ffc0043cbc5db7fed905ea267724cd86p47,
+    0x1.000200000c0e4p-3, -0x1.fffffffff3fffp3
+  },
+  { // Entry 78
+    0x1.03861c0f25f0b7fdd7db988fc50e8ac5p896,
+    0x1.00070p7, 0x1.00000000880p7
+  },
+  { // Entry 79
+    0x1.735f4cae6fd5e7ec9ec93923f339e951p-242,
+    0x1.0007fdep0, -0x1.4f1b77c278dc0p20
+  },
+  { // Entry 80
+    0x1.b6bdcdafd5582823b4d361cb7bf02f0bp0,
+    0x1.0007ffffff18cp-3, -0x1.094f2094f2094p-2
+  },
+  { // Entry 81
+    0x1.ee9de3815589f8020429c850502a73cep0,
+    0x1.00080p1, 0x1.e666666666666p-1
+  },
+  { // Entry 82
+    0x1.fc4e957ad3cff80df14d5383bd09a83ap1023,
+    0x1.001febebccd42p0, 0x1.63d8aa986a9eap20
+  },
+  { // Entry 83
+    0x1.fbddf46d6b62882b4c4e659bf0212df4p1023,
+    0x1.001fef1cc4193p0, 0x1.63b500c83689dp20
+  },
+  { // Entry 84
+    0x1.fba7f9318c5dc81b1e178865147202f3p1023,
+    0x1.001ff069d2a6bp0, 0x1.63a676c8493e8p20
+  },
+  { // Entry 85
+    0x1.f61661b7000d32d1f698e0fa2f889d35p69,
+    0x1.00804025213dep-7, -0x1.4p3
+  },
+  { // Entry 86
+    0x1.e109bdcca01fb7ffbbe4f50c82d0ec62p15,
+    0x1.010p-1, -0x1.ffffffff9ffffp3
+  },
+  { // Entry 87
+    0x1.1e49c51473ff37dc1ad27264312c37b5p-1011,
+    0x1.021eeaa6d270dp1, -0x1.f37971758e257p9
+  },
+  { // Entry 88
+    0x1.eb41321e136b37fffbb99027ffc8514bp-21,
+    0x1.02f178bc5e2c1p3, -0x1.a99999999999ap2
+  },
+  { // Entry 89
+    0x1.080ffffff79cb800d4fa4351d8e63171p-2,
+    0x1.040p-1, 0x1.00000000060p1
+  },
+  { // Entry 90
+    0x1.cf2b19acfd538820cd62b9762fbd07d8p-1018,
+    0x1.0493cda7be452p1, -0x1.efe4b242071abp9
+  },
+  { // Entry 91
+    0x1.6692c05b09baba2ea48d785ad4a4575dp135,
+    0x1.05ebf8248a734p99, 0x1.5e3b32a2a9fb0p0
+  },
+  { // Entry 92
+    0x1.810f2f53980577f6663abfa1f774291bp70,
+    0x1.0aaaaaaaaaaabp7, 0x1.4p3
+  },
+  { // Entry 93
+    0x1.fffee335368ea0008aa6b3b006354625p-1,
+    0x1.0e4f938c0e0bbp-482, 0x1.b4838aa70d025p-26
+  },
+  { // Entry 94
+    0x1.cfc470cc939227fa970b58b91572f724p-40,
+    0x1.13bd11bcfaa50p-5, 0x1.0p3
+  },
+  { // Entry 95
+    0x1.ec33ea55afd33ad219aa2aec083397dfp-1,
+    0x1.1501f44659e54p0, -0x1.0p-1
+  },
+  { // Entry 96
+    0x1.f648a0ead82f6001daf0d46abd018b77p-1,
+    0x1.1555555555555p-1, 0x1.0000000000007p-5
+  },
+  { // Entry 97
+    0x1.fe7eb68734b5e825e94d6de454cde18ep6,
+    0x1.1745d1745da71p-1, -0x1.0000000000007p3
+  },
+  { // Entry 98
+    0x1.a5a00c77c65bf5b0592a61407b2bc79fp-39,
+    0x1.1973b102ffddbp-6, 0x1.a1d84f6a3b934p2
+  },
+  { // Entry 99
+    0x1.e7e26745f50fe800d14145ff80133761p-2,
+    0x1.19eedeb102d84p2, -0x1.0p-1
+  },
+  { // Entry 100
+    0x1.a73f9acbf4125a89020110a29c39bbd2p103,
+    0x1.24765a0cdd454p7, 0x1.cd81edfd6d5b8p3
+  },
+  { // Entry 101
+    0x1.445ae390f4b5369c1426f9fe8b8a1751p615,
+    0x1.2492492492492p-5, -0x1.ffffffffffff8p6
+  },
+  { // Entry 102
+    0x1.e4e045205527f33f0c9768dcb7f13fabp-616,
+    0x1.2492492492492p-5, 0x1.ffc7fffffffffp6
+  },
+  { // Entry 103
+    0x1.2dd17dc7293dc8001e1986a14875be95p122,
+    0x1.3150a12f25c8dp-41, -0x1.8p1
+  },
+  { // Entry 104
+    0x1.52c58cdbac4cb7feb761e24bbde99b85p-534,
+    0x1.3333333333333p-2, 0x1.333333333ce97p8
+  },
+  { // Entry 105
+    0x1.bc7f056ec71ff0000104808c9990ae9fp-2,
+    0x1.33333346cf8bap-2, 0x1.62e42fefa39efp-1
+  },
+  { // Entry 106
+    0x1.a2c9dc7bb2e724ae746c7a0a076b129bp-291,
+    0x1.38abf82ee6986p-1, 0x1.980p8
+  },
+  { // Entry 107
+    0x1.b4f60e5795b5e8088c1865ab9e0e2694p0,
+    0x1.3ec984cb36701p0, 0x1.38018879b2ba8p1
+  },
+  { // Entry 108
+    0x1.8fcf301c2b46532fffb6a06cc43dec91p-667,
+    0x1.4p-1070, 0x1.3ef368eb04327p-1
+  },
+  { // Entry 109
+    0x1.00003f65cce8080000ffef6e02bfe509p0,
+    0x1.4p4, 0x1.529a1574c0c72p-20
+  },
+  { // Entry 110
+    0x1.90000000000028000000000001p4,
+    0x1.4000000000001p2, 0x1.0p1
+  },
+  { // Entry 111
+    0x1.43015cf74d6e07ff3666305ddffb5f4ep1,
+    0x1.43e743ba79c41p-1, -0x1.02c30b80eb514p1
+  },
+  { // Entry 112
+    0x1.a36e1c3c700b7a416fad641bfc031adbp-10,
+    0x1.47ae147ae147bp-5, 0x1.000001cp1
+  },
+  { // Entry 113
+    0x1.e5eccf1b3a05dcf7adca8d47f937dac7p-985,
+    0x1.4e91b0e91b0f1p-1, 0x1.90c9714fbcd9bp10
+  },
+  { // Entry 114
+    0x1.95335bfb76c6c7fe38526cde1c16edbdp-3,
+    0x1.5152b7c373368p-22, 0x1.bb38288a0a6p-4
+  },
+  { // Entry 115
+    0x1.ffffffffffffb01e21a404429e88cfd6p-1,
+    0x1.51758790b4181p-4, 0x1.0p-52
+  },
+  { // Entry 116
+    0x1.702ebfa1ff2013f2438cfd1935b73099p101,
+    0x1.5555555555555p-2, -0x1.00380p6
+  },
+  { // Entry 117
+    0x1.ba30a127f6dd5fd9c60a7f010d9ca125p202,
+    0x1.5555555555555p-2, -0x1.ffc7fffffffffp6
+  },
+  { // Entry 118
+    0x1.7ffffe8eddc49a0bb74c9b3942e5eb0bp1,
+    0x1.5555555555555p-2, -0x1.fffffe3ffffffp-1
+  },
+  { // Entry 119
+    0x1.8aa8808647d07b8819b686a448174076p586,
+    0x1.5555555555555p-5, -0x1.ffc7fffffffffp6
+  },
+  { // Entry 120
+    0x1.7a0a9108e1d1884c584a9ab81fc3f3d1p-294,
+    0x1.5555555555555p-5, 0x1.000000000e0p6
+  },
+  { // Entry 121
+    0x1.ad3d5033217a047c2602ed9b3c0a9644p-461,
+    0x1.58a26121f46f6p-2, 0x1.24f45f5fd4f79p8
+  },
+  { // Entry 122
+    0x1.1104fb8cf786c800ffc735889a531fa3p0,
+    0x1.6130984c02017p0, 0x1.999999999999ap-3
+  },
+  { // Entry 123
+    0x1.1e952b19cc33672f1cdd3ec50e0b3df2p-1023,
+    0x1.622e8ba2e8b9dp-1, 0x1.e0f83e0f83e0cp10
+  },
+  { // Entry 124
+    0x1.ceafd8c0385bd8abbd5744704bf13d4ep-1023,
+    0x1.671111111110cp-1, 0x1.f333333333324p10
+  },
+  { // Entry 125
+    0x1.6a09e667f3ba12f93247a76d74374418p-1,
+    0x1.6a09e667f3b9ep-1, 0x1.ffffffffffff3p-1
+  },
+  { // Entry 126
+    0x1.a887293fd6f30a11e9f3aab161b0d41fp0,
+    0x1.745d1745d1746p-2, -0x1.ffffffffffff8p-2
+  },
+  { // Entry 127
+    0x1.917499900fda07fed49796d8256cbeadp-40,
+    0x1.745d1745d1746p-3, 0x1.fffffe3ffffffp3
+  },
+  { // Entry 128
+    0x1.f46e967980e048c59fd0fbea1e57781cp967,
+    0x1.7a0p7, 0x1.fffffffefffffp6
+  },
+  { // Entry 129
+    0x1.99ce45b7e28fc7ff2d3cfb4617742d7ap-1,
+    0x1.7bf0b2348b0a8p2, -0x1.0p-3
+  },
+  { // Entry 130
+    0x1.fe9d3facecdb482e52a2026f0d0fcbabp0,
+    0x1.8p-1, -0x1.33333333333c0p1
+  },
+  { // Entry 131
+    0x1.96c3a864d92cc8242fa6a056bb08b3cfp-1,
+    0x1.85e85e85e85eap-1, 0x1.b073ecade3053p-1
+  },
+  { // Entry 132
+    0x1.f2d80cf8cc08b7ffffeea79f95c3a9bap-1,
+    0x1.87d872441eabbp9, -0x1.fffffffffffeep-9
+  },
+  { // Entry 133
+    0x1.ffffffffffff701f8afb9aa06bad33c1p-1,
+    0x1.89e36ef84f19dp1, -0x1.0000000000011p-50
+  },
+  { // Entry 134
+    0x1.0000000000000fffb750f07593ac0fefp0,
+    0x1.8d600b7696862p-96, -0x1.efae61f60f6e8p-59
+  },
+  { // Entry 135
+    0x1.e8f15565ed43a82e052236ac3f8a1f09p77,
+    0x1.98d2fe5c53f34p-39, -0x1.044a002d50ad8p1
+  },
+  { // Entry 136
+    0x1.0f4b118a10e49fffff00ae7357d87c94p-1,
+    0x1.999999a637f10p-2, 0x1.62e42fefa39efp-1
+  },
+  { // Entry 137
+    0x1.d2515c49d64157fef62efe37aa7d4e57p-44,
+    0x1.9c0133cdb0856p-5, 0x1.4p3
+  },
+  { // Entry 138
+    0x1.fb85e9f13f076753450e315695d239e9p-1023,
+    0x1.9f0ed4f930522p-1, 0x1.a5db8a1755e9cp11
+  },
+  { // Entry 139
+    0x1.01ab8f2671b6e8000096349ab8974ec5p0,
+    0x1.9fcfe7f3fa181p-1, -0x1.0p-5
+  },
+  { // Entry 140
+    0x1.69c73824fbabf8066c0f38487c600c72p9,
+    0x1.a043274b705cep3, 0x1.487e31cce6468p1
+  },
+  { // Entry 141
+    0x1.d20088f4eeb8a52ff029ff7e476e3b67p-582,
+    0x1.a5d1745d1746ep-1, 0x1.03e0f83e0f83cp11
+  },
+  { // Entry 142
+    0x1.c4beedf3151e2803e049bb5161d1272dp-272,
+    0x1.aa4ce8ed526b1p-1, 0x1.00880p10
+  },
+  { // Entry 143
+    0x1.7173062b74c217fea6b41e6a7fb48dd6p-711,
+    0x1.ab99d36091bc0p97, -0x1.d136ee8e59573p2
+  },
+  { // Entry 144
+    0x1.86c1b49a551097fe78399c00d0157d92p-2,
+    0x1.b782218c3fdb4p2, -0x1.0p-1
+  },
+  { // Entry 145
+    0x1.5b6a74499d637804b9aa28f9b766c3ccp-1,
+    0x1.bceb771a02bdep2, -0x1.999999999999ap-3
+  },
+  { // Entry 146
+    0x1.fdde6d7d992d4ffcd0a2446a9572b791p-1,
+    0x1.bfffffffffffdp-1, 0x1.ffc7fffffffffp-6
+  },
+  { // Entry 147
+    0x1.2492492492492f05397829cbc1ade69fp-1023,
+    0x1.bffffffffffffp1022, -0x1.0p0
+  },
+  { // Entry 148
+    0x1.cca34d8d609542352dfeaace528cb7a1p-818,
+    0x1.cp-1033, 0x1.9555555555552p-1
+  },
+  { // Entry 149
+    0x1.55cb805d3b6ab5c7675ce288db179f2bp-981,
+    0x1.cp-1033, 0x1.e666666666662p-1
+  },
+  { // Entry 150
+    0x1.97a3fcbacebe5d86d4f9675d3b8208f8p861,
+    0x1.cp-1059, -0x1.a0ea0ea0ea0eap-1
+  },
+  { // Entry 151
+    0x1.e926f3342729d100beab22b5029fa692p-956,
+    0x1.cp-1071, 0x1.c8ebd48ebd498p-1
+  },
+  { // Entry 152
+    0x1.f1668a877c3020c8505c45ae994bd358p-1002,
+    0x1.cp-1071, 0x1.deeabb7884549p-1
+  },
+  { // Entry 153
+    0x1.24924924924597829cbc14f0e93c746ep-1023,
+    0x1.c000000000057p1022, -0x1.0p0
+  },
+  { // Entry 154
+    0x1.c65c2cf3962da8013d40ee8c3b46bf1dp96,
+    0x1.c25c268491610p-44, -0x1.1efeff5a273ecp1
+  },
+  { // Entry 155
+    0x1.970c10d6b0a59a7fadf1e21e5ab677bep77,
+    0x1.c25c268497682p-44, -0x1.cc6b93abbb074p0
+  },
+  { // Entry 156
+    0x1.8583c2489a50380006c9c7205b5a54fep-1,
+    0x1.c2e170b85c994p-2, 0x1.5555555555555p-2
+  },
+  { // Entry 157
+    0x1.7e4573015bc63bd267679aab2cd89f66p-1,
+    0x1.cb3c9484e2ad0p0, -0x1.0p-1
+  },
+  { // Entry 158
+    0x1.7e3e719ce5b797fe885815bc3b2457f2p-1,
+    0x1.cb4d69eb4f4b9p0, -0x1.0p-1
+  },
+  { // Entry 159
+    0x1.fd4250a871c7fe00d5f51039c57dde6fp-624,
+    0x1.ccc4c0fd63cb6p-1, 0x1.0p12
+  },
+  { // Entry 160
+    0x1.5dc285d5b5f16800f6d7dc5ffdcf8d16p-1,
+    0x1.d1745d1749883p-1, 0x1.ffc7fffffffffp1
+  },
+  { // Entry 161
+    0x1.fea595d5c04f881438f7f5f10dbb0297p-2,
+    0x1.d555555555552p-1, 0x1.ffc7fffffffffp2
+  },
+  { // Entry 162
+    0x1.0000000000007ff04a26678b633a133ep0,
+    0x1.d872441ec3905p2, 0x1.0000000000011p-50
+  },
+  { // Entry 163
+    0x1.a63f4bd797f82805919b09d2b62da1e1p-1,
+    0x1.da60a1f2ec608p-2, 0x1.007cd9524d3f4p-2
+  },
+  { // Entry 164
+    0x1.a82e1469025c850c1448a19c2af67fe4p-500,
+    0x1.db6db6db6db72p-2, 0x1.c30c30c30c3p8
+  },
+  { // Entry 165
+    0x1.779a06bc3880e2c39dfc679749e470a5p-2,
+    0x1.dbb0e0aa2dd0ep2, -0x1.0p-1
+  },
+  { // Entry 166
+    0x1.f55b41ab4a675405b542703d9b037ae7p-408,
+    0x1.dda95a95a95b1p-1, 0x1.fc0p11
+  },
+  { // Entry 167
+    0x1.767fbad219a208018d6b81f7f3a2051bp2,
+    0x1.de7f154838537p-6, -0x1.0p-1
+  },
+  { // Entry 168
+    0x1.711d602ffb27f80209043d6d8f283cf8p-10,
+    0x1.e66666666666bp-1, 0x1.ffffffffffff8p6
+  },
+  { // Entry 169
+    0x1.ff5697396af157ffead748859ae3c9cbp1,
+    0x1.eeeeeeeeeeeeep2, 0x1.5aaaaaaaaaaabp-1
+  },
+  { // Entry 170
+    0x1.fe961a3ccd3c281ad0333d6806927b2bp-1,
+    0x1.f07c1f07c1f07p-14, 0x1.40a57eb50296dp-12
+  },
+  { // Entry 171
+    0x1.dac0c7cfbef05bd65a0e6ea2477f47fap778,
+    0x1.f1a17d079e24fp-3, -0x1.7d9c0b5f3a960p8
+  },
+  { // Entry 172
+    0x1.6ea69bd85b67cc85be83fa977dc123cap-1,
+    0x1.f333333333324p0, -0x1.0p-1
+  },
+  { // Entry 173
+    0x1.715bf92f43f00b403049e0c3e51153f8p-16,
+    0x1.f664984b8a152p-21, 0x1.8b852ce2219f0p-1
+  },
+  { // Entry 174
+    0x1.74368094efbfb380bb2df2e20e2a7a17p-85,
+    0x1.f6ded8bc3fa43p-7, 0x1.c083595c2b1bcp3
+  },
+  { // Entry 175
+    0x1.b0ef556006207718d3da08a90136726dp721,
+    0x1.f83e0f83e0b8ap-1, -0x1.00000002b658ep15
+  },
+  { // Entry 176
+    0x1.b0ef4cd94f8f8a8e603ff658f61fefb1p721,
+    0x1.f83e0f83e0ba5p-1, -0x1.00000000221efp15
+  },
+  { // Entry 177
+    0x1.b0ef4cd82f1387d76580a9eeaba656f6p721,
+    0x1.f83e0f83e0bcfp-1, -0x1.00000000221efp15
+  },
+  { // Entry 178
+    0x1.b0ef4cfb1cec37d64f37ea375597b740p721,
+    0x1.f83e0f83e0bcfp-1, -0x1.000000002cb09p15
+  },
+  { // Entry 179
+    0x1.b0ef555e269c6774a18b56af36947d82p721,
+    0x1.f83e0f83e0bcfp-1, -0x1.00000002b6573p15
+  },
+  { // Entry 180
+    0x1.b1c3042fe76ec74eb631776ea90c3cc6p721,
+    0x1.f83e0f83e0bcfp-1, -0x1.00004000221efp15
+  },
+  { // Entry 181
+    0x1.f2e92477d64c86fa54f6215ec8de5896p827,
+    0x1.f83e0f83e0bcfp-1, -0x1.25ab6f7bced93p15
+  },
+  { // Entry 182
+    0x1.b0ef4c04ab6f97a529350915504c0074p721,
+    0x1.f83e0f83e0bcfp-1, -0x1.ffffffffc43dep14
+  },
+  { // Entry 183
+    0x1.b0ef555b1dbe97d276d196306ba00051p721,
+    0x1.f83e0f83e0c26p-1, -0x1.00000002b620fp15
+  },
+  { // Entry 184
+    0x1.b0ef4cbe6dee68f697fc5885e43a3545p721,
+    0x1.f83e0f83e0f80p-1, -0x1.00000000220p15
+  },
+  { // Entry 185
+    0x1.661db242e13f78760f3385c48de6e14dp-716,
+    0x1.f84f1b77aa61ep-1, 0x1.0000044p15
+  },
+  { // Entry 186
+    0x1.6cc056593b1897fe7294556e85a7fccap-1,
+    0x1.f869b10e1646ep0, -0x1.0p-1
+  },
+  { // Entry 187
+    0x1.96ec199c8283280dcde1bf0a6bdf18ddp-33,
+    0x1.f86d6f63aa049p-1, 0x1.780p10
+  },
+  { // Entry 188
+    0x1.8d3575c5a08217e96d2baccd92102101p612,
+    0x1.f96860afcb452p-1, -0x1.0000043fffeedp15
+  },
+  { // Entry 189
+    0x1.8d3575c52ea31fea3d0799f8cf8523e3p612,
+    0x1.f96860afcb468p-1, -0x1.0000043ffff85p15
+  },
+  { // Entry 190
+    0x1.8d3575c472f0c863c06a976e22a25c6dp612,
+    0x1.f96860afcb489p-1, -0x1.0000044p15
+  },
+  { // Entry 191
+    0x1.8d3575c35aacefea95c885439d49bd99p612,
+    0x1.f96860afcb4bbp-1, -0x1.00000440000d4p15
+  },
+  { // Entry 192
+    0x1.8d3575c0cfc461bbe5ee3644cc6d77c2p612,
+    0x1.f96860afcb506p-1, -0x1.0000043fffc79p15
+  },
+  { // Entry 193
+    0x1.8d3575c1667df1163979824d863cc571p612,
+    0x1.f96860afcb506p-1, -0x1.0000044000022p15
+  },
+  { // Entry 194
+    0x1.8d3575b4fec588e56f1ba4bb2cde3d37p612,
+    0x1.f96860afcb714p-1, -0x1.0000044000353p15
+  },
+  { // Entry 195
+    0x1.8d3575ac3ff49ee0044041951d20706bp612,
+    0x1.f96860afcb858p-1, -0x1.0000043fffe6dp15
+  },
+  { // Entry 196
+    0x1.671986dbe53f56acd36ddaeec97277aap-46,
+    0x1.f985f7cbf0059p-7, 0x1.e3fa3018bde08p2
+  },
+  { // Entry 197
+    0x1.eec73eb3ed9247940e87750e7fc49479p1019,
+    0x1.fa81a5e7d412cp-1, -0x1.000007ffef0p16
+  },
+  { // Entry 198
+    0x1.6afc2b3669cafd8b04be07637cb8ce5ep-1,
+    0x1.fd557019f1cd0p0, -0x1.0p-1
+  },
+  { // Entry 199
+    0x1.c4f91d24e5c3e86f73ea68132bda4b8ap1002,
+    0x1.fdfffffffffffp-3, -0x1.f3fffffffffffp8
+  },
+  { // Entry 200
+    0x1.6a93b7f04694ad66b9aa64f76ba1fa38p-2,
+    0x1.fe7b0ee6afa3cp2, -0x1.0p-1
+  },
+  { // Entry 201
+    0x1.e1776bde16643808a38caf050f5cb630p-966,
+    0x1.ff3e9ae3033aep-1, 0x1.ba6c13bf005ecp18
+  },
+  { // Entry 202
+    0x1.d4ef5ecd754cd7f6e7016453994c21d5p-943,
+    0x1.ff433a02ec964p-1, 0x1.ba7a347cdffebp18
+  },
+  { // Entry 203
+    0x1.fe9bbdc161abd7fd9b32dbbc2d748438p-915,
+    0x1.ff48e2b4a5d7ep-1, 0x1.ba8b810f5507fp18
+  },
+  { // Entry 204
+    0x1.de52aa6a5ecaf8067797c9e2a281b23ep-905,
+    0x1.ff4ae0e440fb6p-1, 0x1.ba9198ab03cd4p18
+  },
+  { // Entry 205
+    0x1.76bc52dc7431f800000536a94bc3d305p133,
+    0x1.ff77fffffffffp15, 0x1.0b1fdcd7590abp3
+  },
+  { // Entry 206
+    0x1.5c1c2ded7213d991836fd2aa8dff4df7p-1023,
+    0x1.ff7ffffffffffp0, -0x1.00000000cp10
+  },
+  { // Entry 207
+    0x1.7a2b4d72ccfab7febb68ab3ac422cda7p-613,
+    0x1.ff85796e4f063p-1, 0x1.bb44b86ca0928p18
+  },
+  { // Entry 208
+    0x1.18a2faf8b5f6e8032837e7d87abcfa58p-410,
+    0x1.ffae13ebf1872p-1, 0x1.bbc0d7c3a882cp18
+  },
+  { // Entry 209
+    0x1.39e7d84a8958282053666d8c41938466p-739,
+    0x1.fff0000006071p-1, 0x1.0000140p22
+  },
+  { // Entry 210
+    0x1.e6ce6f49ea6028016050f5f38aefc204p795,
+    0x1.fff800000e483p1023, 0x1.8df6b0df6b0e0p-1
+  },
+  { // Entry 211
+    0x1.9aaa3cdd12dc05e246b234654b8dc76fp-442,
+    0x1.fffffe7fffffep-1023, 0x1.ba2e8ba2e8ba4p-2
+  },
+  { // Entry 212
+    0x1.f663278f73044832a2c1c5820c51cde7p-1,
+    0x1.ffffff3ffffffp-8, 0x1.000000ep-8
+  },
+  { // Entry 213
+    0x1.ffffffcd55554801c722bf7f371564d7p-1,
+    0x1.ffffffbffffffp-1, 0x1.9555555555552p-1
+  },
+  { // Entry 214
+    0x1.61c50ac8e0257000ca0d8b938dfe79abp567,
+    0x1.ffffffbffffffp1023, 0x1.1bbbbbbbbbbb9p-1
+  },
+  { // Entry 215
+    0x1.ffffff80000008p-199,
+    0x1.ffffffcp-100, 0x1.0p1
+  },
+  { // Entry 216
+    0x1.ffffff85291c6803b8547332d01f63b1p1023,
+    0x1.ffffffff8ffffp7, 0x1.ffffffffe7e49p6
+  },
+  { // Entry 217
+    0x1.ffffffc7fff45f951f3a78dcb59a7fa5p-897,
+    0x1.ffffffffeffffp-2, 0x1.bffffffffffffp9
+  },
+  { // Entry 218
+    0x1.7b29358d45f41a2f23ee22f80bb6fd08p508,
+    0x1.fffffffff3ffep-1023, -0x1.fd8fd8fd8fd8ep-2
+  },
+  { // Entry 219
+    0x1.e3437e70fec24558c1079cade561e276p-810,
+    0x1.fffffffffbffep-1023, 0x1.9555555555552p-1
+  },
+  { // Entry 220
+    0x1.fffffffffdfff7fffffeff97fe6ffeffp-1,
+    0x1.fffffffffbfffp-1, 0x1.0000000000003p-1
+  },
+  { // Entry 221
+    0x1.f6697c7afa0ac827d45b428b9c13ea46p77,
+    0x1.ffffffffff0d6p952, 0x1.4f2094f2094f0p-4
+  },
+  { // Entry 222
+    0x1.ffffffffffbc37ffffffff82436fffffp-1,
+    0x1.ffffffffffb4bp-1, 0x1.cccccccccccccp-1
+  },
+  { // Entry 223
+    0x1.ffffffffffcfe7ffffffffe232cfffffp-1,
+    0x1.ffffffffffcd6p-1, 0x1.e666666666666p-1
+  },
+  { // Entry 224
+    0x1.fffffffffff377ffffffffdbdfefffffp-1,
+    0x1.ffffffffffe6fp-1, 0x1.ffffffffffff8p-2
+  },
+  { // Entry 225
+    0x1.000000000003c7ffffffffeb431fffffp0,
+    0x1.fffffffffff0ep-1, -0x1.ffffffffffe9bp-2
+  },
+  { // Entry 226
+    0x1.000000000012d800000000ecb980p-3,
+    0x1.fffffffffff37p0, -0x1.8p1
+  },
+  { // Entry 227
+    0x1.ae89f995aaa93b8abea2c7b7cbcdc5e2p378,
+    0x1.fffffffffff9fp2, 0x1.f8fffffffffffp6
+  },
+  { // Entry 228
+    0x1.000000000193480000013fd6b24000aap-1015,
+    0x1.fffffffffffa7p6, -0x1.220p7
+  },
+  { // Entry 229
+    0x1.fffffffffffd07ffffffffffec4fffffp-1,
+    0x1.fffffffffffcep-1, 0x1.e666666666666p-1
+  },
+  { // Entry 230
+    0x1.ffffffffff1ce485fdf4a5fd3e671ea9p-1023,
+    0x1.fffffffffffefp-5, 0x1.fefffffffffffp7
+  },
+  { // Entry 231
+    0x1.00000000000047ffffffffffffffffffp0,
+    0x1.ffffffffffff7p-1, -0x1.ffffffffffff7p-1
+  },
+  { // Entry 232
+    0x1.0000000000002800000000000640p-1023,
+    0x1.ffffffffffffbp1022, -0x1.0p0
+  },
+  { // Entry 233
+    0x1.fffffffffffff8000006ffffffd0p-1,
+    0x1.ffffffffffffcp-1, 0x1.fffffe3ffffffp-4
+  },
+  { // Entry 234
+    0x1.fffffffffff17217f7d1cf8da0cc77cbp1023,
+    0x1.ffffffffffffdp0, 0x1.0000000000002p10
+  },
+  { // Entry 235
+    0x1.fffffffffff8b90bfbe8e7bf932596dfp1023,
+    0x1.ffffffffffffdp1, 0x1.0000000000001p9
+  },
+  { // Entry 236
+    0x1.00000000000007ffffffffffffdfffffp0,
+    0x1.ffffffffffffep-1, -0x1.ffffffffffffep-2
+  },
+  { // Entry 237
+    0x1.9fdf8bcce5346004c5f8fe1fe52b1115p56,
+    0x1.ffffffffffffep-64, -0x1.ccccccccccccdp-1
+  },
+  { // Entry 238
+    0x1.3354053613975801e1f18c607d9f7c96p-55,
+    0x1.ffffffffffffep-224, 0x1.f6b0df6b0df6ap-3
+  },
+  { // Entry 239
+    0x1.4337cd6b11bd77ff1dfb16e77447ef8ep157,
+    0x1.ffffffffffffep-642, -0x1.f6b0df6b0df6cp-3
+  },
+  { // Entry 240
+    0x1.9fdf8bcce571fb3c9561f337c9c427d4p278,
+    0x1.ffffffffffffep-930, -0x1.3333333333337p-2
+  },
+  { // Entry 241
+    0x1.ddb680117ab968057796e81914e78595p909,
+    0x1.ffffffffffffep-1012, -0x1.ccccccccccccdp-1
+  },
+  { // Entry 242
+    0x1.2387a6e756233000b49c3b0bf9c54982p1,
+    0x1.ffffffffffffep4, 0x1.e66666666665cp-3
+  },
+  { // Entry 243
+    0x1.a5adb8c8e32c1807a7da92b43f7cc90cp54,
+    0x1.ffffffffffffep75, 0x1.70a3d70a3d70fp-1
+  },
+  { // Entry 244
+    0x1.ec1deabbe3a9eae29bde56f88e8ef4eep627,
+    0x1.ffffffffffffep813, 0x1.8af8af8af8af8p-1
+  },
+  { // Entry 245
+    0x1.ffffffffff8f9dccd52d470a882669c3p647,
+    0x1.ffffffffffffep863, 0x1.7fffffffffffdp-1
+  },
+  { // Entry 246
+    0x1.00000004da20a7d2821cdfd4f6347dd0p128,
+    0x1.fffffffffffffp-3, -0x1.000000000e0p6
+  },
+  { // Entry 247
+    0x1.44ce541b60346c98094443b9faa84abdp10,
+    0x1.fffffffffffffp1023, 0x1.4afd6a052c0e2p-7
+  },
+  { // Entry 248
+    0x1.cb720dcef90691503cbd1e949db761d9p-1,
+    0x1.0p-5, 0x1.0p-5
+  },
+  { // Entry 249
+    0x1.p-5,
+    0x1.0p-5, 0x1.0p0
+  },
+  { // Entry 250
+    0x1.p0,
+    0x1.0p0, 0x1.0p-5
+  },
+  { // Entry 251
+    0x1.p0,
+    0x1.0p0, 0x1.0p0
+  },
+  { // Entry 252
+    0x1.p-40,
+    0x1.0p-5, 0x1.0p3
+  },
+  { // Entry 253
+    0x1.p-160,
+    0x1.0p-5, 0x1.0p5
+  },
+  { // Entry 254
+    0x1.p0,
+    0x1.0p0, 0x1.0p3
+  },
+  { // Entry 255
+    0x1.p0,
+    0x1.0p0, 0x1.0p5
+  },
+  { // Entry 256
+    0.0,
+    0x1.0p-5, 0x1.0p10
+  },
+  { // Entry 257
+    0.0,
+    0x1.0p-5, 0x1.0p12
+  },
+  { // Entry 258
+    0x1.p0,
+    0x1.0p0, 0x1.0p10
+  },
+  { // Entry 259
+    0x1.p0,
+    0x1.0p0, 0x1.0p12
+  },
+  { // Entry 260
+    0x1.11301d0125b50a4ebbf1aed9318ceac5p0,
+    0x1.0p3, 0x1.0p-5
+  },
+  { // Entry 261
+    0x1.p3,
+    0x1.0p3, 0x1.0p0
+  },
+  { // Entry 262
+    0x1.1d4873168b9aa7805b8028990f07a98bp0,
+    0x1.0p5, 0x1.0p-5
+  },
+  { // Entry 263
+    0x1.p5,
+    0x1.0p5, 0x1.0p0
+  },
+  { // Entry 264
+    0x1.p24,
+    0x1.0p3, 0x1.0p3
+  },
+  { // Entry 265
+    0x1.p96,
+    0x1.0p3, 0x1.0p5
+  },
+  { // Entry 266
+    0x1.p40,
+    0x1.0p5, 0x1.0p3
+  },
+  { // Entry 267
+    0x1.p160,
+    0x1.0p5, 0x1.0p5
+  },
+  { // Entry 268
+    HUGE_VAL,
+    0x1.0p3, 0x1.0p10
+  },
+  { // Entry 269
+    HUGE_VAL,
+    0x1.0p3, 0x1.0p12
+  },
+  { // Entry 270
+    HUGE_VAL,
+    0x1.0p5, 0x1.0p10
+  },
+  { // Entry 271
+    HUGE_VAL,
+    0x1.0p5, 0x1.0p12
+  },
+  { // Entry 272
+    0x1.3dea64c12342235b41223e13d773fba2p0,
+    0x1.0p10, 0x1.0p-5
+  },
+  { // Entry 273
+    0x1.p10,
+    0x1.0p10, 0x1.0p0
+  },
+  { // Entry 274
+    0x1.4bfdad5362a271d4397afec42e20e036p0,
+    0x1.0p12, 0x1.0p-5
+  },
+  { // Entry 275
+    0x1.p12,
+    0x1.0p12, 0x1.0p0
+  },
+  { // Entry 276
+    0x1.p80,
+    0x1.0p10, 0x1.0p3
+  },
+  { // Entry 277
+    0x1.p320,
+    0x1.0p10, 0x1.0p5
+  },
+  { // Entry 278
+    0x1.p96,
+    0x1.0p12, 0x1.0p3
+  },
+  { // Entry 279
+    0x1.p384,
+    0x1.0p12, 0x1.0p5
+  },
+  { // Entry 280
+    0x1.000000000000198d4d0da05571e9ad47p2,
+    0x1.6a09e667f3bccp-1, -0x1.0p2
+  },
+  { // Entry 281
+    0x1.ffffffffffffcce565e4bf5521467385p-3,
+    0x1.6a09e667f3bccp-1, 0x1.0p2
+  },
+  { // Entry 282
+    0x1.000000000000198d4d0da05571e9ad47p-2,
+    0x1.6a09e667f3bccp0, -0x1.0p2
+  },
+  { // Entry 283
+    0x1.ffffffffffffcce565e4bf5521467385p1,
+    0x1.6a09e667f3bccp0, 0x1.0p2
+  },
+  { // Entry 284
+    0x1.000000000000198d4d0da05571e9ad47p2,
+    0x1.6a09e667f3bccp-1, -0x1.0p2
+  },
+  { // Entry 285
+    0x1.ffffffffffffcce565e4bf5521467385p-3,
+    0x1.6a09e667f3bccp-1, 0x1.0p2
+  },
+  { // Entry 286
+    0x1.000000000000198d4d0da05571e9ad47p-2,
+    0x1.6a09e667f3bccp0, -0x1.0p2
+  },
+  { // Entry 287
+    0x1.ffffffffffffcce565e4bf5521467385p1,
+    0x1.6a09e667f3bccp0, 0x1.0p2
+  },
+  { // Entry 288
+    0x1.00162f3904051fa2c1b4e853746b6f04p0,
+    0x1.6a09e667f3bccp-1, -0x1.0p-10
+  },
+  { // Entry 289
+    0x1.ffd3a565efb64ea88a80d8a52554a3a0p-1,
+    0x1.6a09e667f3bccp-1, 0x1.0p-10
+  },
+  { // Entry 290
+    0x1.ffd3a565efb64eaeed467183b8d46a96p-1,
+    0x1.6a09e667f3bccp0, -0x1.0p-10
+  },
+  { // Entry 291
+    0x1.00162f3904051f9f8fc46b3743f85cbep0,
+    0x1.6a09e667f3bccp0, 0x1.0p-10
+  },
+  { // Entry 292
+    0x1.948b0fcd6e9e06522c3f35ba781948b0p1,
+    0x1.8p-1, -0x1.0p2
+  },
+  { // Entry 293
+    0x1.44p-2,
+    0x1.8p-1, 0x1.0p2
+  },
+  { // Entry 294
+    0x1.948b0fcd6e9e06522c3f35ba781948b0p-3,
+    0x1.8p0, -0x1.0p2
+  },
+  { // Entry 295
+    0x1.44p2,
+    0x1.8p0, 0x1.0p2
+  },
+  { // Entry 296
+    0x1.279a74590331c4d218f81e4afb257d06p0,
+    0x1.8p-1, -0x1.0p-1
+  },
+  { // Entry 297
+    0x1.bb67ae8584caa73b25742d7078b83b89p-1,
+    0x1.8p-1, 0x1.0p-1
+  },
+  { // Entry 298
+    0x1.a20bd700c2c3dfc042cc1aed7871db45p-1,
+    0x1.8p0, -0x1.0p-1
+  },
+  { // Entry 299
+    0x1.3988e1409212e7d0321914321a556473p0,
+    0x1.8p0, 0x1.0p-1
+  },
+  { // Entry 300
+    0x1.00126a0b93db294cabe33da735437f51p0,
+    0x1.8p-1, -0x1.0p-10
+  },
+  { // Entry 301
+    0x1.ffdb2e8ed2a1fe71bd59fdd610313046p-1,
+    0x1.8p-1, 0x1.0p-10
+  },
+  { // Entry 302
+    0x1.ffcc1c5973b2129a5b1424e0c88786b8p-1,
+    0x1.8p0, -0x1.0p-10
+  },
+  { // Entry 303
+    0x1.0019f474aa190038c6af775d92f1d725p0,
+    0x1.8p0, 0x1.0p-10
+  },
+  { // Entry 304
+    0x1.p0,
+    0x1.0p0, -0x1.0p2
+  },
+  { // Entry 305
+    0x1.p0,
+    0x1.0p0, 0x1.0p2
+  },
+  { // Entry 306
+    0x1.p-4,
+    0x1.0p1, -0x1.0p2
+  },
+  { // Entry 307
+    0x1.p4,
+    0x1.0p1, 0x1.0p2
+  },
+  { // Entry 308
+    0x1.p0,
+    0x1.0p0, -0x1.0p-1
+  },
+  { // Entry 309
+    0x1.p0,
+    0x1.0p0, 0x1.0p-1
+  },
+  { // Entry 310
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep-1,
+    0x1.0p1, -0x1.0p-1
+  },
+  { // Entry 311
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.0p1, 0x1.0p-1
+  },
+  { // Entry 312
+    0x1.p0,
+    0x1.0p0, -0x1.0p-10
+  },
+  { // Entry 313
+    0x1.p0,
+    0x1.0p0, 0x1.0p-10
+  },
+  { // Entry 314
+    0x1.ffa74ea381efc217a773f15c025f7c0dp-1,
+    0x1.0p1, -0x1.0p-10
+  },
+  { // Entry 315
+    0x1.002c605e2e8cec506d21bfc89a23a010p0,
+    0x1.0p1, 0x1.0p-10
+  },
+  { // Entry 316
+    0x1.p40,
+    0x1.0p-10, -0x1.0p2
+  },
+  { // Entry 317
+    0x1.p-40,
+    0x1.0p-10, 0x1.0p2
+  },
+  { // Entry 318
+    0x1.fe013f6045e40a7c41499223b4a38ce8p-1,
+    0x1.004p0, -0x1.0p2
+  },
+  { // Entry 319
+    0x1.0100601001p0,
+    0x1.004p0, 0x1.0p2
+  },
+  { // Entry 320
+    0x1.p5,
+    0x1.0p-10, -0x1.0p-1
+  },
+  { // Entry 321
+    0x1.p-5,
+    0x1.0p-10, 0x1.0p-1
+  },
+  { // Entry 322
+    0x1.ffc00bfd808be0873653647448220fdfp-1,
+    0x1.004p0, -0x1.0p-1
+  },
+  { // Entry 323
+    0x1.001ffe003ff601bfac107ca6b29a0c31p0,
+    0x1.004p0, 0x1.0p-1
+  },
+  { // Entry 324
+    0x1.01bd1e77170b415e7626621eb5aaff61p0,
+    0x1.0p-10, -0x1.0p-10
+  },
+  { // Entry 325
+    0x1.fc8bc4866e8ad2b963e1828b0761cbc6p-1,
+    0x1.0p-10, 0x1.0p-10
+  },
+  { // Entry 326
+    0x1.ffffe0040055355844443df8680a8e05p-1,
+    0x1.004p0, -0x1.0p-10
+  },
+  { // Entry 327
+    0x1.00000ffe00d5256285340e4f3ad36287p0,
+    0x1.004p0, 0x1.0p-10
+  },
+  { // Entry 328
+    0x1.0000000000000800000000000040p-1024,
+    0x1.fffffffffffffp1023, -0x1.0p0
+  },
+  { // Entry 329
+    0x1.fffffffffffff0p1023,
+    0x1.fffffffffffffp1023, 0x1.0p0
+  },
+  { // Entry 330
+    0x1.3b2c47bff827194425605a92311acceep1020,
+    0x1.0p-1074, -0x1.e666666666666p-1
+  },
+  { // Entry 331
+    0x1.9fdf8bcce542f50814057837677baf82p-1021,
+    0x1.0p-1074, 0x1.e666666666666p-1
+  },
+  { // Entry 332
+    0x1.00000000000651591f9dd5cdb110f6e3p-384,
+    0x1.fffffffffffffp-7, 0x1.fffffffffffffp5
+  },
+  { // Entry 333
+    0x1.fffffffffffc000000000003efffffffp-385,
+    0x1.fffffffffffffp-7, 0x1.0p6
+  },
+  { // Entry 334
+    0x1.ffffffffffdaba9b8188aa7428411dd5p-385,
+    0x1.fffffffffffffp-7, 0x1.0000000000001p6
+  },
+  { // Entry 335
+    0x1.00000000000851591f9dd5dc4bc3361fp-384,
+    0x1.0p-6, 0x1.fffffffffffffp5
+  },
+  { // Entry 336
+    0x1.p-384,
+    0x1.0p-6, 0x1.0p6
+  },
+  { // Entry 337
+    0x1.ffffffffffdeba9b8188aa2ded7820e7p-385,
+    0x1.0p-6, 0x1.0000000000001p6
+  },
+  { // Entry 338
+    0x1.00000000000c51591f9dd6055127b496p-384,
+    0x1.0000000000001p-6, 0x1.fffffffffffffp5
+  },
+  { // Entry 339
+    0x1.000000000004000000000007e0p-384,
+    0x1.0000000000001p-6, 0x1.0p6
+  },
+  { // Entry 340
+    0x1.ffffffffffe6ba9b8188a9b917e62709p-385,
+    0x1.0000000000001p-6, 0x1.0000000000001p6
+  },
+  { // Entry 341
+    0x1.000000000002773a77d719106e939582p-160,
+    0x1.fffffffffffffp-6, 0x1.fffffffffffffp4
+  },
+  { // Entry 342
+    0x1.fffffffffffe000000000000f7ffffffp-161,
+    0x1.fffffffffffffp-6, 0x1.0p5
+  },
+  { // Entry 343
+    0x1.fffffffffff0231620a39c093f16f8cep-161,
+    0x1.fffffffffffffp-6, 0x1.0000000000001p5
+  },
+  { // Entry 344
+    0x1.000000000003773a77d7191361ce0d5ap-160,
+    0x1.0p-5, 0x1.fffffffffffffp4
+  },
+  { // Entry 345
+    0x1.p-160,
+    0x1.0p-5, 0x1.0p5
+  },
+  { // Entry 346
+    0x1.fffffffffff2231620a39bfa8a2d1972p-161,
+    0x1.0p-5, 0x1.0000000000001p5
+  },
+  { // Entry 347
+    0x1.000000000005773a77d7191c3042fd08p-160,
+    0x1.0000000000001p-5, 0x1.fffffffffffffp4
+  },
+  { // Entry 348
+    0x1.000000000002000000000001f0p-160,
+    0x1.0000000000001p-5, 0x1.0p5
+  },
+  { // Entry 349
+    0x1.fffffffffff6231620a39be2f0595ab9p-161,
+    0x1.0000000000001p-5, 0x1.0000000000001p5
+  },
+  { // Entry 350
+    0x1.000000000000e2e42fefa39f59e36bcbp-64,
+    0x1.fffffffffffffp-5, 0x1.fffffffffffffp3
+  },
+  { // Entry 351
+    0x1.ffffffffffff0000000000003bffffffp-65,
+    0x1.fffffffffffffp-5, 0x1.0p4
+  },
+  { // Entry 352
+    0x1.fffffffffff9746f4041718ed45990a2p-65,
+    0x1.fffffffffffffp-5, 0x1.0000000000001p4
+  },
+  { // Entry 353
+    0x1.00000000000162e42fefa39fe95583c3p-64,
+    0x1.0p-4, 0x1.fffffffffffffp3
+  },
+  { // Entry 354
+    0x1.p-64,
+    0x1.0p-4, 0x1.0p4
+  },
+  { // Entry 355
+    0x1.fffffffffffa746f4041718be29130c3p-65,
+    0x1.0p-4, 0x1.0000000000001p4
+  },
+  { // Entry 356
+    0x1.00000000000262e42fefa3a1bc39b3b3p-64,
+    0x1.0000000000001p-4, 0x1.fffffffffffffp3
+  },
+  { // Entry 357
+    0x1.00000000000100000000000078p-64,
+    0x1.0000000000001p-4, 0x1.0p4
+  },
+  { // Entry 358
+    0x1.fffffffffffc746f4041718767007104p-65,
+    0x1.0000000000001p-4, 0x1.0000000000001p4
+  },
+  { // Entry 359
+    0x1.000000000000451591f9dd5ba59328abp-24,
+    0x1.fffffffffffffp-4, 0x1.fffffffffffffp2
+  },
+  { // Entry 360
+    0x1.ffffffffffff8000000000000dffffffp-25,
+    0x1.fffffffffffffp-4, 0x1.0p3
+  },
+  { // Entry 361
+    0x1.fffffffffffd6ba9b8188a9332cfe24ap-25,
+    0x1.fffffffffffffp-4, 0x1.0000000000001p3
+  },
+  { // Entry 362
+    0x1.000000000000851591f9dd5bbdd88d2ap-24,
+    0x1.0p-3, 0x1.fffffffffffffp2
+  },
+  { // Entry 363
+    0x1.p-24,
+    0x1.0p-3, 0x1.0p3
+  },
+  { // Entry 364
+    0x1.fffffffffffdeba9b8188a92a7ba5050p-25,
+    0x1.0p-3, 0x1.0000000000001p3
+  },
+  { // Entry 365
+    0x1.000000000001051591f9dd5c18635627p-24,
+    0x1.0000000000001p-3, 0x1.fffffffffffffp2
+  },
+  { // Entry 366
+    0x1.0000000000008000000000001cp-24,
+    0x1.0000000000001p-3, 0x1.0p3
+  },
+  { // Entry 367
+    0x1.fffffffffffeeba9b8188a91e58f2c5cp-25,
+    0x1.0000000000001p-3, 0x1.0000000000001p3
+  },
+  { // Entry 368
+    0x1.0000000000000c5c85fdf473df375979p-8,
+    0x1.fffffffffffffp-3, 0x1.fffffffffffffp1
+  },
+  { // Entry 369
+    0x1.ffffffffffffc0000000000002ffffffp-9,
+    0x1.fffffffffffffp-3, 0x1.0p2
+  },
+  { // Entry 370
+    0x1.ffffffffffff0e8de8082e30ba42371ap-9,
+    0x1.fffffffffffffp-3, 0x1.0000000000001p2
+  },
+  { // Entry 371
+    0x1.0000000000002c5c85fdf473e242ea38p-8,
+    0x1.0p-2, 0x1.fffffffffffffp1
+  },
+  { // Entry 372
+    0x1.p-8,
+    0x1.0p-2, 0x1.0p2
+  },
+  { // Entry 373
+    0x1.ffffffffffff4e8de8082e30a513f41bp-9,
+    0x1.0p-2, 0x1.0000000000001p2
+  },
+  { // Entry 374
+    0x1.0000000000006c5c85fdf473f15a0bb8p-8,
+    0x1.0000000000001p-2, 0x1.fffffffffffffp1
+  },
+  { // Entry 375
+    0x1.00000000000040000000000006p-8,
+    0x1.0000000000001p-2, 0x1.0p2
+  },
+  { // Entry 376
+    0x1.ffffffffffffce8de8082e308cb76e1dp-9,
+    0x1.0000000000001p-2, 0x1.0000000000001p2
+  },
+  { // Entry 377
+    0x1.fffffffffffff62e42fefa39efcd9404p-3,
+    0x1.fffffffffffffp-2, 0x1.fffffffffffffp0
+  },
+  { // Entry 378
+    0x1.ffffffffffffe000000000000080p-3,
+    0x1.fffffffffffffp-2, 0x1.0p1
+  },
+  { // Entry 379
+    0x1.ffffffffffffb3a37a020b8c24c6d1c6p-3,
+    0x1.fffffffffffffp-2, 0x1.0000000000001p1
+  },
+  { // Entry 380
+    0x1.0000000000000b17217f7d1cf7d83c1ap-2,
+    0x1.0p-1, 0x1.fffffffffffffp0
+  },
+  { // Entry 381
+    0x1.p-2,
+    0x1.0p-1, 0x1.0p1
+  },
+  { // Entry 382
+    0x1.ffffffffffffd3a37a020b8c23810967p-3,
+    0x1.0p-1, 0x1.0000000000001p1
+  },
+  { // Entry 383
+    0x1.0000000000002b17217f7d1cf93b204ap-2,
+    0x1.0000000000001p-1, 0x1.fffffffffffffp0
+  },
+  { // Entry 384
+    0x1.00000000000020000000000001p-2,
+    0x1.0000000000001p-1, 0x1.0p1
+  },
+  { // Entry 385
+    0x1.00000000000009d1bd0105c611fabc53p-2,
+    0x1.0000000000001p-1, 0x1.0000000000001p1
+  },
+  { // Entry 386
+    0x1.fffffffffffff00000000000007fffffp-1,
+    0x1.fffffffffffffp-1, 0x1.fffffffffffffp-1
+  },
+  { // Entry 387
+    0x1.fffffffffffff0p-1,
+    0x1.fffffffffffffp-1, 0x1.0p0
+  },
+  { // Entry 388
+    0x1.ffffffffffffefffffffffffffp-1,
+    0x1.fffffffffffffp-1, 0x1.0000000000001p0
+  },
+  { // Entry 389
+    0x1.p0,
+    0x1.0p0, 0x1.fffffffffffffp-1
+  },
+  { // Entry 390
+    0x1.p0,
+    0x1.0p0, 0x1.0p0
+  },
+  { // Entry 391
+    0x1.p0,
+    0x1.0p0, 0x1.0000000000001p0
+  },
+  { // Entry 392
+    0x1.0000000000000fffffffffffff7fffffp0,
+    0x1.0000000000001p0, 0x1.fffffffffffffp-1
+  },
+  { // Entry 393
+    0x1.00000000000010p0,
+    0x1.0000000000001p0, 0x1.0p0
+  },
+  { // Entry 394
+    0x1.00000000000010000000000001p0,
+    0x1.0000000000001p0, 0x1.0000000000001p0
+  },
+  { // Entry 395
+    0x1.6a09e667f3bcbf74c2970440d6d2a831p0,
+    0x1.fffffffffffffp0, 0x1.fffffffffffffp-2
+  },
+  { // Entry 396
+    0x1.6a09e667f3bcc3608b617397f7660a23p0,
+    0x1.fffffffffffffp0, 0x1.0p-1
+  },
+  { // Entry 397
+    0x1.6a09e667f3bccb381cf6524638ad6b43p0,
+    0x1.fffffffffffffp0, 0x1.0000000000001p-1
+  },
+  { // Entry 398
+    0x1.6a09e667f3bcc51cea30a40fc9c52aecp0,
+    0x1.0p1, 0x1.fffffffffffffp-2
+  },
+  { // Entry 399
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.0p1, 0x1.0p-1
+  },
+  { // Entry 400
+    0x1.6a09e667f3bcd0e0448ff2152c56bf1fp0,
+    0x1.0p1, 0x1.0000000000001p-1
+  },
+  { // Entry 401
+    0x1.6a09e667f3bcd06d3963e3adaf664e88p0,
+    0x1.0000000000001p1, 0x1.fffffffffffffp-2
+  },
+  { // Entry 402
+    0x1.6a09e667f3bcd459022e5304d0b08199p0,
+    0x1.0000000000001p1, 0x1.0p-1
+  },
+  { // Entry 403
+    0x1.6a09e667f3bcdc3093c331b3136584f9p0,
+    0x1.0000000000001p1, 0x1.0000000000001p-1
+  },
+  { // Entry 404
+    0x1.6a09e667f3bcc248d663d4285049157bp0,
+    0x1.fffffffffffffp1, 0x1.fffffffffffffp-3
+  },
+  { // Entry 405
+    0x1.6a09e667f3bcc6349f2e437f70faef9cp0,
+    0x1.fffffffffffffp1, 0x1.0p-2
+  },
+  { // Entry 406
+    0x1.6a09e667f3bcce0c30c3222db27f411dp0,
+    0x1.fffffffffffffp1, 0x1.0000000000001p-2
+  },
+  { // Entry 407
+    0x1.6a09e667f3bcc51cea30a40fc9c52aecp0,
+    0x1.0p2, 0x1.fffffffffffffp-3
+  },
+  { // Entry 408
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.0p2, 0x1.0p-2
+  },
+  { // Entry 409
+    0x1.6a09e667f3bcd0e0448ff2152c56bf1fp0,
+    0x1.0p2, 0x1.0000000000001p-2
+  },
+  { // Entry 410
+    0x1.6a09e667f3bccac511ca43debc8a6c6bp0,
+    0x1.0000000000001p2, 0x1.fffffffffffffp-3
+  },
+  { // Entry 411
+    0x1.6a09e667f3bcceb0da94b335dd97af1cp0,
+    0x1.0000000000001p2, 0x1.0p-2
+  },
+  { // Entry 412
+    0x1.6a09e667f3bcd6886c2991e41fd2d1bdp0,
+    0x1.0000000000001p2, 0x1.0000000000001p-2
+  },
+  { // Entry 413
+    0x1.4bfdad5362a26dd5e0bd02594b5812cbp0,
+    0x1.fffffffffffffp2, 0x1.fffffffffffffp-4
+  },
+  { // Entry 414
+    0x1.4bfdad5362a270883bcdab618baa8204p0,
+    0x1.fffffffffffffp2, 0x1.0p-3
+  },
+  { // Entry 415
+    0x1.4bfdad5362a275ecf1eefd720c603321p0,
+    0x1.fffffffffffffp2, 0x1.0000000000001p-3
+  },
+  { // Entry 416
+    0x1.4bfdad5362a26f21de6a55bbedc15eb4p0,
+    0x1.0p3, 0x1.fffffffffffffp-4
+  },
+  { // Entry 417
+    0x1.4bfdad5362a271d4397afec42e20e036p0,
+    0x1.0p3, 0x1.0p-3
+  },
+  { // Entry 418
+    0x1.4bfdad5362a27738ef9c50d4aef0b5e4p0,
+    0x1.0p3, 0x1.0000000000001p-3
+  },
+  { // Entry 419
+    0x1.4bfdad5362a271b9d9c4fc813278bab6p0,
+    0x1.0000000000001p3, 0x1.fffffffffffffp-4
+  },
+  { // Entry 420
+    0x1.4bfdad5362a2746c34d5a58972f260c9p0,
+    0x1.0000000000001p3, 0x1.0p-3
+  },
+  { // Entry 421
+    0x1.4bfdad5362a279d0eaf6f799f3f67f99p0,
+    0x1.0000000000001p3, 0x1.0000000000001p-3
+  },
+  { // Entry 422
+    0x1.306fe0a31b7150a04b58ad8027ceb050p0,
+    0x1.fffffffffffffp3, 0x1.fffffffffffffp-5
+  },
+  { // Entry 423
+    0x1.306fe0a31b7152465569f4a2a3da43d4p0,
+    0x1.fffffffffffffp3, 0x1.0p-4
+  },
+  { // Entry 424
+    0x1.306fe0a31b715592698c82e79bf84613p0,
+    0x1.fffffffffffffp3, 0x1.0000000000001p-4
+  },
+  { // Entry 425
+    0x1.306fe0a31b7151388348ff0de074c5a3p0,
+    0x1.0p4, 0x1.fffffffffffffp-5
+  },
+  { // Entry 426
+    0x1.306fe0a31b7152de8d5a46305c85edecp0,
+    0x1.0p4, 0x1.0p-4
+  },
+  { // Entry 427
+    0x1.306fe0a31b71562aa17cd47554af19b4p0,
+    0x1.0p4, 0x1.0000000000001p-4
+  },
+  { // Entry 428
+    0x1.306fe0a31b715268f329a22951b38f61p0,
+    0x1.0000000000001p4, 0x1.fffffffffffffp-5
+  },
+  { // Entry 429
+    0x1.306fe0a31b71540efd3ae94bcdcfe133p0,
+    0x1.0000000000001p4, 0x1.0p-4
+  },
+  { // Entry 430
+    0x1.306fe0a31b71575b115d7790c60f600dp0,
+    0x1.0000000000001p4, 0x1.0000000000001p-4
+  },
+  { // Entry 431
+    0x1.1d4873168b9aa641db97b491a37936aep0,
+    0x1.fffffffffffffp4, 0x1.fffffffffffffp-6
+  },
+  { // Entry 432
+    0x1.1d4873168b9aa739096362f6285cb516p0,
+    0x1.fffffffffffffp4, 0x1.0p-5
+  },
+  { // Entry 433
+    0x1.1d4873168b9aa92764fabfbf32263462p0,
+    0x1.fffffffffffffp4, 0x1.0000000000001p-5
+  },
+  { // Entry 434
+    0x1.1d4873168b9aa6892db47a348a21b2c7p0,
+    0x1.0p5, 0x1.fffffffffffffp-6
+  },
+  { // Entry 435
+    0x1.1d4873168b9aa7805b8028990f07a98bp0,
+    0x1.0p5, 0x1.0p-5
+  },
+  { // Entry 436
+    0x1.1d4873168b9aa96eb717856218d61990p0,
+    0x1.0p5, 0x1.0000000000001p-5
+  },
+  { // Entry 437
+    0x1.1d4873168b9aa717d1ee057a576c30c4p0,
+    0x1.0000000000001p5, 0x1.fffffffffffffp-6
+  },
+  { // Entry 438
+    0x1.1d4873168b9aa80effb9b3dedc571840p0,
+    0x1.0000000000001p5, 0x1.0p-5
+  },
+  { // Entry 439
+    0x1.1d4873168b9aa9fd5b5110a7e62f69b6p0,
+    0x1.0000000000001p5, 0x1.0000000000001p-5
+  },
+  { // Entry 440
+    0x1.11301d0125b5099e90ea43d6599ee2bbp0,
+    0x1.fffffffffffffp5, 0x1.fffffffffffffp-7
+  },
+  { // Entry 441
+    0x1.11301d0125b50a2c95ee0eb47aeb1a78p0,
+    0x1.fffffffffffffp5, 0x1.0p-6
+  },
+  { // Entry 442
+    0x1.11301d0125b50b489ff5a470bd846771p0,
+    0x1.fffffffffffffp5, 0x1.0000000000001p-6
+  },
+  { // Entry 443
+    0x1.11301d0125b509c0b6ede3fb103f9017p0,
+    0x1.0p6, 0x1.fffffffffffffp-7
+  },
+  { // Entry 444
+    0x1.11301d0125b50a4ebbf1aed9318ceac5p0,
+    0x1.0p6, 0x1.0p-6
+  },
+  { // Entry 445
+    0x1.11301d0125b50b6ac5f9449574287d9fp0,
+    0x1.0p6, 0x1.0000000000001p-6
+  },
+  { // Entry 446
+    0x1.11301d0125b50a0502f524447d7dc40ep0,
+    0x1.0000000000001p6, 0x1.fffffffffffffp-7
+  },
+  { // Entry 447
+    0x1.11301d0125b50a9307f8ef229ecd649ep0,
+    0x1.0000000000001p6, 0x1.0p-6
+  },
+  { // Entry 448
+    0x1.11301d0125b50baf120084dee16d833bp0,
+    0x1.0000000000001p6, 0x1.0000000000001p-6
+  },
+  { // Entry 449
+    0x1.ffffffffff2746f4041746255c99e90bp1023,
+    0x1.ffffffffffffep0, 0x1.ffffffffffffep9
+  },
+  { // Entry 450
+    0x1.ffffffffff53a37a020ba924b26cfc59p1023,
+    0x1.ffffffffffffep0, 0x1.fffffffffffffp9
+  },
+  { // Entry 451
+    0x1.ffffffffff80000000000ffbfffffffep1023,
+    0x1.ffffffffffffep0, 0x1.0p10
+  },
+  { // Entry 452
+    0x1.ffffffffffd8b90bfbe8e9328265d851p1023,
+    0x1.ffffffffffffep0, 0x1.0000000000001p10
+  },
+  { // Entry 453
+    HUGE_VAL,
+    0x1.ffffffffffffep0, 0x1.0000000000002p10
+  },
+  { // Entry 454
+    0x1.ffffffffff6746f404172f0d3b1a6bf2p1023,
+    0x1.fffffffffffffp0, 0x1.ffffffffffffep9
+  },
+  { // Entry 455
+    0x1.ffffffffff93a37a020b979a21ad3dcdp1023,
+    0x1.fffffffffffffp0, 0x1.fffffffffffffp9
+  },
+  { // Entry 456
+    0x1.ffffffffffc00000000003feffffffffp1023,
+    0x1.fffffffffffffp0, 0x1.0p10
+  },
+  { // Entry 457
+    HUGE_VAL,
+    0x1.fffffffffffffp0, 0x1.0000000000001p10
+  },
+  { // Entry 458
+    HUGE_VAL,
+    0x1.fffffffffffffp0, 0x1.0000000000002p10
+  },
+  { // Entry 459
+    0x1.ffffffffffa746f404171ff3199aeed7p1023,
+    0x1.0p1, 0x1.ffffffffffffep9
+  },
+  { // Entry 460
+    0x1.ffffffffffd3a37a020b8e0d90ed7f3fp1023,
+    0x1.0p1, 0x1.fffffffffffffp9
+  },
+  { // Entry 461
+    HUGE_VAL,
+    0x1.0p1, 0x1.0p10
+  },
+  { // Entry 462
+    HUGE_VAL,
+    0x1.0p1, 0x1.0000000000001p10
+  },
+  { // Entry 463
+    HUGE_VAL,
+    0x1.0p1, 0x1.0000000000002p10
+  },
+  { // Entry 464
+    HUGE_VAL,
+    0x1.0000000000001p1, 0x1.ffffffffffffep9
+  },
+  { // Entry 465
+    HUGE_VAL,
+    0x1.0000000000001p1, 0x1.fffffffffffffp9
+  },
+  { // Entry 466
+    HUGE_VAL,
+    0x1.0000000000001p1, 0x1.0p10
+  },
+  { // Entry 467
+    HUGE_VAL,
+    0x1.0000000000001p1, 0x1.0000000000001p10
+  },
+  { // Entry 468
+    HUGE_VAL,
+    0x1.0000000000001p1, 0x1.0000000000002p10
+  },
+  { // Entry 469
+    HUGE_VAL,
+    0x1.0000000000002p1, 0x1.ffffffffffffep9
+  },
+  { // Entry 470
+    HUGE_VAL,
+    0x1.0000000000002p1, 0x1.fffffffffffffp9
+  },
+  { // Entry 471
+    HUGE_VAL,
+    0x1.0000000000002p1, 0x1.0p10
+  },
+  { // Entry 472
+    HUGE_VAL,
+    0x1.0000000000002p1, 0x1.0000000000001p10
+  },
+  { // Entry 473
+    HUGE_VAL,
+    0x1.0000000000002p1, 0x1.0000000000002p10
+  },
+  { // Entry 474
+    0.0,
+    0x1.ffffffffffffep0, -0x1.0cc0000000002p10
+  },
+  { // Entry 475
+    0.0,
+    0x1.ffffffffffffep0, -0x1.0cc0000000001p10
+  },
+  { // Entry 476
+    0.0,
+    0x1.ffffffffffffep0, -0x1.0ccp10
+  },
+  { // Entry 477
+    0.0,
+    0x1.ffffffffffffep0, -0x1.0cbffffffffffp10
+  },
+  { // Entry 478
+    0.0,
+    0x1.ffffffffffffep0, -0x1.0cbfffffffffep10
+  },
+  { // Entry 479
+    0.0,
+    0x1.fffffffffffffp0, -0x1.0cc0000000002p10
+  },
+  { // Entry 480
+    0.0,
+    0x1.fffffffffffffp0, -0x1.0cc0000000001p10
+  },
+  { // Entry 481
+    0.0,
+    0x1.fffffffffffffp0, -0x1.0ccp10
+  },
+  { // Entry 482
+    0.0,
+    0x1.fffffffffffffp0, -0x1.0cbffffffffffp10
+  },
+  { // Entry 483
+    0.0,
+    0x1.fffffffffffffp0, -0x1.0cbfffffffffep10
+  },
+  { // Entry 484
+    0.0,
+    0x1.0p1, -0x1.0cc0000000002p10
+  },
+  { // Entry 485
+    0.0,
+    0x1.0p1, -0x1.0cc0000000001p10
+  },
+  { // Entry 486
+    0.0,
+    0x1.0p1, -0x1.0ccp10
+  },
+  { // Entry 487
+    0.0,
+    0x1.0p1, -0x1.0cbffffffffffp10
+  },
+  { // Entry 488
+    0.0,
+    0x1.0p1, -0x1.0cbfffffffffep10
+  },
+  { // Entry 489
+    0.0,
+    0x1.0000000000001p1, -0x1.0cc0000000002p10
+  },
+  { // Entry 490
+    0.0,
+    0x1.0000000000001p1, -0x1.0cc0000000001p10
+  },
+  { // Entry 491
+    0.0,
+    0x1.0000000000001p1, -0x1.0ccp10
+  },
+  { // Entry 492
+    0.0,
+    0x1.0000000000001p1, -0x1.0cbffffffffffp10
+  },
+  { // Entry 493
+    0.0,
+    0x1.0000000000001p1, -0x1.0cbfffffffffep10
+  },
+  { // Entry 494
+    0.0,
+    0x1.0000000000002p1, -0x1.0cc0000000002p10
+  },
+  { // Entry 495
+    0.0,
+    0x1.0000000000002p1, -0x1.0cc0000000001p10
+  },
+  { // Entry 496
+    0.0,
+    0x1.0000000000002p1, -0x1.0ccp10
+  },
+  { // Entry 497
+    0.0,
+    0x1.0000000000002p1, -0x1.0cbffffffffffp10
+  },
+  { // Entry 498
+    0.0,
+    0x1.0000000000002p1, -0x1.0cbfffffffffep10
+  },
+  { // Entry 499
+    0x1.a82e14690252e5ea2cfa30b25e947cedp-500,
+    0x1.db6db6db6db70p-2, 0x1.c30c30c30c2fep8
+  },
+  { // Entry 500
+    0x1.a82e1469023e8ea567883fcd2742e4b7p-500,
+    0x1.db6db6db6db70p-2, 0x1.c30c30c30c2ffp8
+  },
+  { // Entry 501
+    0x1.a82e1469022a3760a2164fe1a4cd3aa2p-500,
+    0x1.db6db6db6db70p-2, 0x1.c30c30c30c3p8
+  },
+  { // Entry 502
+    0x1.a82e14690215e01bdca460efd7337eaep-500,
+    0x1.db6db6db6db70p-2, 0x1.c30c30c30c301p8
+  },
+  { // Entry 503
+    0x1.a82e1469020188d7173272f7be75b0dcp-500,
+    0x1.db6db6db6db70p-2, 0x1.c30c30c30c302p8
+  },
+  { // Entry 504
+    0x1.a82e1469026c0cbfe6135b38e76d3a47p-500,
+    0x1.db6db6db6db71p-2, 0x1.c30c30c30c2fep8
+  },
+  { // Entry 505
+    0x1.a82e14690257b57b20a1691fd0d853d6p-500,
+    0x1.db6db6db6db71p-2, 0x1.c30c30c30c2ffp8
+  },
+  { // Entry 506
+    0x1.a82e146902435e365b2f78006f1f5b87p-500,
+    0x1.db6db6db6db71p-2, 0x1.c30c30c30c3p8
+  },
+  { // Entry 507
+    0x1.a82e1469022f06f195bd87dac2425159p-500,
+    0x1.db6db6db6db71p-2, 0x1.c30c30c30c301p8
+  },
+  { // Entry 508
+    0x1.a82e1469021aafacd04b98aeca41354dp-500,
+    0x1.db6db6db6db71p-2, 0x1.c30c30c30c302p8
+  },
+  { // Entry 509
+    0x1.a82e1469028533959f2c873c61cafb18p-500,
+    0x1.db6db6db6db72p-2, 0x1.c30c30c30c2fep8
+  },
+  { // Entry 510
+    0x1.a82e14690270dc50d9ba93ef6bf2c66dp-500,
+    0x1.db6db6db6db72p-2, 0x1.c30c30c30c2ffp8
+  },
+  { // Entry 511
+    0x1.a82e1469025c850c1448a19c2af67fe4p-500,
+    0x1.db6db6db6db72p-2, 0x1.c30c30c30c3p8
+  },
+  { // Entry 512
+    0x1.a82e146902482dc74ed6b0429ed6277cp-500,
+    0x1.db6db6db6db72p-2, 0x1.c30c30c30c301p8
+  },
+  { // Entry 513
+    0x1.a82e14690233d6828964bfe2c791bd35p-500,
+    0x1.db6db6db6db72p-2, 0x1.c30c30c30c302p8
+  },
+  { // Entry 514
+    0x1.a82e1469029e5a6b5845b4bccdadbf62p-500,
+    0x1.db6db6db6db73p-2, 0x1.c30c30c30c2fep8
+  },
+  { // Entry 515
+    0x1.a82e1469028a032692d3c03bf8923c7cp-500,
+    0x1.db6db6db6db73p-2, 0x1.c30c30c30c2ffp8
+  },
+  { // Entry 516
+    0x1.a82e14690275abe1cd61ccb4d852a7b9p-500,
+    0x1.db6db6db6db73p-2, 0x1.c30c30c30c3p8
+  },
+  { // Entry 517
+    0x1.a82e14690261549d07efda276cef0116p-500,
+    0x1.db6db6db6db73p-2, 0x1.c30c30c30c301p8
+  },
+  { // Entry 518
+    0x1.a82e1469024cfd58427de893b6674895p-500,
+    0x1.db6db6db6db73p-2, 0x1.c30c30c30c302p8
+  },
+  { // Entry 519
+    0x1.a82e146902b78141115ee3ba2b158723p-500,
+    0x1.db6db6db6db74p-2, 0x1.c30c30c30c2fep8
+  },
+  { // Entry 520
+    0x1.a82e146902a329fc4becee0576b6b603p-500,
+    0x1.db6db6db6db74p-2, 0x1.c30c30c30c2ffp8
+  },
+  { // Entry 521
+    0x1.a82e1469028ed2b7867af94a7733d305p-500,
+    0x1.db6db6db6db74p-2, 0x1.c30c30c30c3p8
+  },
+  { // Entry 522
+    0x1.a82e1469027a7b72c10905892c8cde29p-500,
+    0x1.db6db6db6db74p-2, 0x1.c30c30c30c301p8
+  },
+  { // Entry 523
+    0x1.a82e14690266242dfb9712c196c1d76dp-500,
+    0x1.db6db6db6db74p-2, 0x1.c30c30c30c302p8
+  },
+  { // Entry 524
+    -0x1.ffffffffffffe0000000000001ffffffp-1,
+    -0x1.0000000000001p0, -0x1.0p0
+  },
+  { // Entry 525
+    -0x1.p0,
+    -0x1.0p0, -0x1.0p0
+  },
+  { // Entry 526
+    -0x1.0000000000000800000000000040p0,
+    -0x1.fffffffffffffp-1, -0x1.0p0
+  },
+  { // Entry 527
+    HUGE_VAL,
+    0x1.0p1, 0x1.0p10
+  },
+  { // Entry 528
+    HUGE_VAL,
+    0x1.0p2, 0x1.0p9
+  },
+  { // Entry 529
+    0x1.ffffffffffec5c85fdf4743fd612b28ap-1025,
+    0x1.fffffffffffffp-2, 0x1.fffffffffffffp9
+  },
+  { // Entry 530
+    0x1.ffffffffffc00000000003feffffffffp-1025,
+    0x1.fffffffffffffp-2, 0x1.0p10
+  },
+  { // Entry 531
+    0x1.ffffffffff6746f404172f053b1a6bf2p-1025,
+    0x1.fffffffffffffp-2, 0x1.0000000000001p10
+  },
+  { // Entry 532
+    0x1.0000000000162e42fefa3ae53369388cp-1024,
+    0x1.0p-1, 0x1.fffffffffffffp9
+  },
+  { // Entry 533
+    0x1.p-1024,
+    0x1.0p-1, 0x1.0p10
+  },
+  { // Entry 534
+    0x1.ffffffffffa746f404171ff3199aeed7p-1025,
+    0x1.0p-1, 0x1.0000000000001p10
+  },
+  { // Entry 535
+    0x1.0000000000562e42fefa486cc428f71cp-1024,
+    0x1.0000000000001p-1, 0x1.fffffffffffffp9
+  },
+  { // Entry 536
+    0x1.0000000000400000000007fep-1024,
+    0x1.0000000000001p-1, 0x1.0p10
+  },
+  { // Entry 537
+    0x1.000000000013a37a020b8ce46b4dfa4ep-1024,
+    0x1.0000000000001p-1, 0x1.0000000000001p10
+  },
+  { // Entry 538
+    0x1.000000000074519a5623533df8dcd353p-1074,
+    0x1.0p-1074, 0x1.ffffffffffffbp-1
+  },
+  { // Entry 539
+    0x1.00000000005d0e1511b5d7f72c61368ap-1074,
+    0x1.0p-1074, 0x1.ffffffffffffcp-1
+  },
+  { // Entry 540
+    0x1.000000000045ca8fcd485ecd93a6ec9dp-1074,
+    0x1.0p-1074, 0x1.ffffffffffffdp-1
+  },
+  { // Entry 541
+    0x1.00000000002e870a88dae7c12eadf58cp-1074,
+    0x1.0p-1074, 0x1.ffffffffffffep-1
+  },
+  { // Entry 542
+    0x1.0000000000174385446d72d1fd765158p-1074,
+    0x1.0p-1074, 0x1.fffffffffffffp-1
+  },
+  { // Entry 543
+    0x1.p-1074,
+    0x1.0p-1074, 0x1.0p0
+  },
+  { // Entry 544
+    0.0,
+    0x1.0p-1074, 0x1.0000000000001p0
+  },
+  { // Entry 545
+    0.0,
+    0x1.0p-1074, 0x1.0000000000002p0
+  },
+  { // Entry 546
+    0.0,
+    0x1.0p-1074, 0x1.0000000000003p0
+  },
+  { // Entry 547
+    0.0,
+    0x1.0p-1074, 0x1.0000000000004p0
+  },
+  { // Entry 548
+    0.0,
+    0x1.0p-1074, 0x1.0000000000005p0
+  },
+  { // Entry 549
+    0x1.00000000007435e082649a68f64fe306p-1073,
+    0x1.0p-1073, 0x1.ffffffffffffbp-1
+  },
+  { // Entry 550
+    0x1.00000000005cf7e6ceb6ddb52e1b099ep-1073,
+    0x1.0p-1073, 0x1.ffffffffffffcp-1
+  },
+  { // Entry 551
+    0x1.000000000045b9ed1b09231d97c56c9dp-1073,
+    0x1.0p-1073, 0x1.ffffffffffffdp-1
+  },
+  { // Entry 552
+    0x1.00000000002e7bf3675b6aa2334f0c02p-1073,
+    0x1.0p-1073, 0x1.ffffffffffffep-1
+  },
+  { // Entry 553
+    0x1.0000000000173df9b3adb44300b7e7cep-1073,
+    0x1.0p-1073, 0x1.fffffffffffffp-1
+  },
+  { // Entry 554
+    0x1.p-1073,
+    0x1.0p-1073, 0x1.0p0
+  },
+  { // Entry 555
+    0x1.ffffffffffa3081931493b9d285bcb2bp-1074,
+    0x1.0p-1073, 0x1.0000000000001p0
+  },
+  { // Entry 556
+    0x1.ffffffffff4610326292881bdfb17983p-1074,
+    0x1.0p-1073, 0x1.0000000000002p0
+  },
+  { // Entry 557
+    0x1.fffffffffee9184b93dbe57c26010b04p-1074,
+    0x1.0p-1073, 0x1.0000000000003p0
+  },
+  { // Entry 558
+    0x1.fffffffffe8c2064c52553bdfb4a7fadp-1074,
+    0x1.0p-1073, 0x1.0000000000004p0
+  },
+  { // Entry 559
+    0x1.fffffffffe2f287df66ed2e15f8dd77ap-1074,
+    0x1.0p-1073, 0x1.0000000000005p0
+  },
+  { // Entry 560
+    0x1.8000000000ae387cd1e8f3f39fe157f9p-1073,
+    0x1.8p-1073, 0x1.ffffffffffffbp-1
+  },
+  { // Entry 561
+    0x1.80000000008b6063db20bcd67b4f5ba5p-1073,
+    0x1.8p-1073, 0x1.ffffffffffffcp-1
+  },
+  { // Entry 562
+    0x1.800000000068884ae45888e2bf6fd4afp-1073,
+    0x1.8p-1073, 0x1.ffffffffffffdp-1
+  },
+  { // Entry 563
+    0x1.800000000045b031ed9058186c42c317p-1073,
+    0x1.8p-1073, 0x1.ffffffffffffep-1
+  },
+  { // Entry 564
+    0x1.800000000022d818f6c82a7781c826dcp-1073,
+    0x1.8p-1073, 0x1.fffffffffffffp-1
+  },
+  { // Entry 565
+    0x1.80p-1073,
+    0x1.8p-1073, 0x1.0p0
+  },
+  { // Entry 566
+    0x1.7fffffffffba4fce126fb48d3687125dp-1073,
+    0x1.8p-1073, 0x1.0000000000001p0
+  },
+  { // Entry 567
+    0x1.7fffffffff749f9c24df75c00fd7fa2ep-1073,
+    0x1.8p-1073, 0x1.0000000000002p0
+  },
+  { // Entry 568
+    0x1.7fffffffff2eef6a374f43988bf2b76ep-1073,
+    0x1.8p-1073, 0x1.0000000000003p0
+  },
+  { // Entry 569
+    0x1.7ffffffffee93f3849bf1e16aad74a1dp-1073,
+    0x1.8p-1073, 0x1.0000000000004p0
+  },
+  { // Entry 570
+    0x1.7ffffffffea38f065c2f053a6c85b237p-1073,
+    0x1.8p-1073, 0x1.0000000000005p0
+  },
+  { // Entry 571
+    0x1.000000a0cf65eb1817a7095d9a0443a7p0,
+    0x1.0p-29, -0x1.0p-29
+  },
+  { // Entry 572
+    0x1.ffffff5f309a60aad5c2309f81f90defp-1,
+    0x1.0p-29, 0x1.0p-30
+  },
+  { // Entry 573
+    0x1.fffffd9e07cf07767a55afbe9acae93ep-1,
+    0x1.0p55, -0x1.0p-29
+  },
+  { // Entry 574
+    0x1.000000987e0cc66344d89b494e1f43b3p0,
+    0x1.0p55, 0x1.0p-30
+  },
+  { // Entry 575
+    0x1.fffffd669427cf159515873887c17cf2p-1,
+    0x1.0p60, -0x1.0p-29
+  },
+  { // Entry 576
+    0x1.000000a65af6ae61be88ea2558790cd7p0,
+    0x1.0p60, 0x1.0p-30
+  },
+  { // Entry 577
+    0x1.fffffffffe0000000000fff7ffffffaap-1,
+    0x1.fffffffffffffp-1, 0x1.0p13
+  },
+  { // Entry 578
+    0x1.fffffffff0000000003fffbfffff5557p-1,
+    0x1.fffffffffffffp-1, 0x1.0p16
+  },
+  { // Entry 579
+    0x1.p0,
+    0x1.0p0, 0x1.0p13
+  },
+  { // Entry 580
+    0x1.p0,
+    0x1.0p0, 0x1.0p16
+  },
+  { // Entry 581
+    0x1.00000000020000000001fff000000155p0,
+    0x1.0000000000001p0, 0x1.0p13
+  },
+  { // Entry 582
+    0x1.0000000010000000007fff800002aaa2p0,
+    0x1.0000000000001p0, 0x1.0p16
+  },
+  { // Entry 583
+    0x1.ffffffc0000004000001d5555516aaaap-1,
+    -0x1.0000000000001p0, -0x1.0p25
+  },
+  { // Entry 584
+    0x1.fffffe000000ffffffbaaaaab0000003p-1,
+    -0x1.0000000000001p0, -0x1.0p28
+  },
+  { // Entry 585
+    0x1.p0,
+    -0x1.0p0, -0x1.0p25
+  },
+  { // Entry 586
+    0x1.p0,
+    -0x1.0p0, -0x1.0p28
+  },
+  { // Entry 587
+    0x1.0000001000000080000042aaaaaeb555p0,
+    -0x1.fffffffffffffp-1, -0x1.0p25
+  },
+  { // Entry 588
+    0x1.00000080000020000007555557p0,
+    -0x1.fffffffffffffp-1, -0x1.0p28
+  },
+  { // Entry 589
+    0x1.368b2fc6f960a4c1d9aa628fe3f13fffp-1,
+    -0x1.0000000000001p0, -0x1.0p51
+  },
+  { // Entry 590
+    0x1.5fc21041027b23b05156b8aea8b5e925p-12,
+    -0x1.0000000000001p0, -0x1.0p55
+  },
+  { // Entry 591
+    0x1.p0,
+    -0x1.0p0, -0x1.0p51
+  },
+  { // Entry 592
+    0x1.p0,
+    -0x1.0p0, -0x1.0p55
+  },
+  { // Entry 593
+    0x1.48b5e3c3e81867bf31a77a83c32c4744p0,
+    -0x1.fffffffffffffp-1, -0x1.0p51
+  },
+  { // Entry 594
+    0x1.b4c902e273a5a1c56701e715edaf2115p5,
+    -0x1.fffffffffffffp-1, -0x1.0p55
+  },
+  { // Entry 595
+    0x1.5fc21041027b23b05156b8aea8b5e925p-12,
+    -0x1.0000000000001p0, -0x1.0p55
+  },
+  { // Entry 596
+    0x1.969d47321e4fe7f9bb8c43a5e486b9aep-93,
+    -0x1.0000000000001p0, -0x1.0p58
+  },
+  { // Entry 597
+    0x1.p0,
+    -0x1.0p0, -0x1.0p55
+  },
+  { // Entry 598
+    0x1.p0,
+    -0x1.0p0, -0x1.0p58
+  },
+  { // Entry 599
+    0x1.b4c902e273a5a1c56701e715edaf2115p5,
+    -0x1.fffffffffffffp-1, -0x1.0p55
+  },
+  { // Entry 600
+    0x1.1f43fcc4b663577a45ea9b49cce9ee73p46,
+    -0x1.fffffffffffffp-1, -0x1.0p58
+  },
+  { // Entry 601
+    0x1.44109edb20a756ad767d2515c94a003ap-739,
+    -0x1.0000000000001p0, -0x1.0p61
+  },
+  { // Entry 602
+    0.0,
+    -0x1.0000000000001p0, -0x1.0p64
+  },
+  { // Entry 603
+    0x1.p0,
+    -0x1.0p0, -0x1.0p61
+  },
+  { // Entry 604
+    0x1.p0,
+    -0x1.0p0, -0x1.0p64
+  },
+  { // Entry 605
+    0x1.41c7a8814bf0a801c5353f302a40cc7fp369,
+    -0x1.fffffffffffffp-1, -0x1.0p61
+  },
+  { // Entry 606
+    HUGE_VAL,
+    -0x1.fffffffffffffp-1, -0x1.0p64
+  },
+  { // Entry 607
+    0x1.0000001000000080000042aaaaaeb555p0,
+    0x1.fffffffffffffp-1, -0x1.0p25
+  },
+  { // Entry 608
+    0x1.00000080000020000007555557p0,
+    0x1.fffffffffffffp-1, -0x1.0p28
+  },
+  { // Entry 609
+    0x1.p0,
+    0x1.0p0, -0x1.0p25
+  },
+  { // Entry 610
+    0x1.p0,
+    0x1.0p0, -0x1.0p28
+  },
+  { // Entry 611
+    0x1.ffffffc0000004000001d5555516aaaap-1,
+    0x1.0000000000001p0, -0x1.0p25
+  },
+  { // Entry 612
+    0x1.fffffe000000ffffffbaaaaab0000003p-1,
+    0x1.0000000000001p0, -0x1.0p28
+  },
+  { // Entry 613
+    0x1.48b5e3c3e81867bf31a77a83c32c4744p0,
+    0x1.fffffffffffffp-1, -0x1.0p51
+  },
+  { // Entry 614
+    0x1.b4c902e273a5a1c56701e715edaf2115p5,
+    0x1.fffffffffffffp-1, -0x1.0p55
+  },
+  { // Entry 615
+    0x1.p0,
+    0x1.0p0, -0x1.0p51
+  },
+  { // Entry 616
+    0x1.p0,
+    0x1.0p0, -0x1.0p55
+  },
+  { // Entry 617
+    0x1.368b2fc6f960a4c1d9aa628fe3f13fffp-1,
+    0x1.0000000000001p0, -0x1.0p51
+  },
+  { // Entry 618
+    0x1.5fc21041027b23b05156b8aea8b5e925p-12,
+    0x1.0000000000001p0, -0x1.0p55
+  },
+  { // Entry 619
+    0x1.b4c902e273a5a1c56701e715edaf2115p5,
+    0x1.fffffffffffffp-1, -0x1.0p55
+  },
+  { // Entry 620
+    0x1.1f43fcc4b663577a45ea9b49cce9ee73p46,
+    0x1.fffffffffffffp-1, -0x1.0p58
+  },
+  { // Entry 621
+    0x1.p0,
+    0x1.0p0, -0x1.0p55
+  },
+  { // Entry 622
+    0x1.p0,
+    0x1.0p0, -0x1.0p58
+  },
+  { // Entry 623
+    0x1.5fc21041027b23b05156b8aea8b5e925p-12,
+    0x1.0000000000001p0, -0x1.0p55
+  },
+  { // Entry 624
+    0x1.969d47321e4fe7f9bb8c43a5e486b9aep-93,
+    0x1.0000000000001p0, -0x1.0p58
+  },
+  { // Entry 625
+    0x1.41c7a8814bf0a801c5353f302a40cc7fp369,
+    0x1.fffffffffffffp-1, -0x1.0p61
+  },
+  { // Entry 626
+    HUGE_VAL,
+    0x1.fffffffffffffp-1, -0x1.0p64
+  },
+  { // Entry 627
+    0x1.p0,
+    0x1.0p0, -0x1.0p61
+  },
+  { // Entry 628
+    0x1.p0,
+    0x1.0p0, -0x1.0p64
+  },
+  { // Entry 629
+    0x1.44109edb20a756ad767d2515c94a003ap-739,
+    0x1.0000000000001p0, -0x1.0p61
+  },
+  { // Entry 630
+    0.0,
+    0x1.0000000000001p0, -0x1.0p64
+  },
+  { // Entry 631
+    HUGE_VAL,
+    -0x1.0p15, 0x1.0p63
+  },
+  { // Entry 632
+    HUGE_VAL,
+    0.0, -0x1.8p1
+  },
+  { // Entry 633
+    -HUGE_VAL,
+    -0.0, -0x1.8p1
+  },
+  { // Entry 634
+    HUGE_VAL,
+    0.0, -0x1.0p0
+  },
+  { // Entry 635
+    -HUGE_VAL,
+    -0.0, -0x1.0p0
+  },
+  { // Entry 636
+    HUGE_VAL,
+    0.0, -0x1.fffffffffffffp1023
+  },
+  { // Entry 637
+    HUGE_VAL,
+    0.0, -0x1.8p2
+  },
+  { // Entry 638
+    HUGE_VAL,
+    0.0, -0x1.0p1
+  },
+  { // Entry 639
+    HUGE_VAL,
+    0.0, -0x1.0000000000001p0
+  },
+  { // Entry 640
+    HUGE_VAL,
+    0.0, -0x1.fffffffffffffp-1
+  },
+  { // Entry 641
+    HUGE_VAL,
+    0.0, -0x1.0p-1022
+  },
+  { // Entry 642
+    HUGE_VAL,
+    0.0, -0x1.0p-1074
+  },
+  { // Entry 643
+    HUGE_VAL,
+    -0.0, -0x1.fffffffffffffp1023
+  },
+  { // Entry 644
+    HUGE_VAL,
+    -0.0, -0x1.8p2
+  },
+  { // Entry 645
+    HUGE_VAL,
+    -0.0, -0x1.0p1
+  },
+  { // Entry 646
+    HUGE_VAL,
+    -0.0, -0x1.0000000000001p0
+  },
+  { // Entry 647
+    HUGE_VAL,
+    -0.0, -0x1.fffffffffffffp-1
+  },
+  { // Entry 648
+    HUGE_VAL,
+    -0.0, -0x1.0p-1022
+  },
+  { // Entry 649
+    HUGE_VAL,
+    -0.0, -0x1.0p-1074
+  },
+  { // Entry 650
+    HUGE_VAL,
+    0.0, -HUGE_VAL
+  },
+  { // Entry 651
+    HUGE_VAL,
+    -0.0, -HUGE_VAL
+  },
+  { // Entry 652
+    0.0,
+    0.0, 0x1.8p1
+  },
+  { // Entry 653
+    -0.0,
+    -0.0, 0x1.8p1
+  },
+  { // Entry 654
+    0.0,
+    0.0, 0x1.0p0
+  },
+  { // Entry 655
+    -0.0,
+    -0.0, 0x1.0p0
+  },
+  { // Entry 656
+    0.0,
+    0.0, HUGE_VAL
+  },
+  { // Entry 657
+    0.0,
+    0.0, 0x1.fffffffffffffp1023
+  },
+  { // Entry 658
+    0.0,
+    0.0, 0x1.8p2
+  },
+  { // Entry 659
+    0.0,
+    0.0, 0x1.0p1
+  },
+  { // Entry 660
+    0.0,
+    0.0, 0x1.0000000000001p0
+  },
+  { // Entry 661
+    0.0,
+    0.0, 0x1.fffffffffffffp-1
+  },
+  { // Entry 662
+    0.0,
+    0.0, 0x1.0p-1022
+  },
+  { // Entry 663
+    0.0,
+    0.0, 0x1.0p-1074
+  },
+  { // Entry 664
+    0.0,
+    -0.0, HUGE_VAL
+  },
+  { // Entry 665
+    0.0,
+    -0.0, 0x1.fffffffffffffp1023
+  },
+  { // Entry 666
+    0.0,
+    -0.0, 0x1.8p2
+  },
+  { // Entry 667
+    0.0,
+    -0.0, 0x1.0p1
+  },
+  { // Entry 668
+    0.0,
+    -0.0, 0x1.0000000000001p0
+  },
+  { // Entry 669
+    0.0,
+    -0.0, 0x1.fffffffffffffp-1
+  },
+  { // Entry 670
+    0.0,
+    -0.0, 0x1.0p-1022
+  },
+  { // Entry 671
+    0.0,
+    -0.0, 0x1.0p-1074
+  },
+  { // Entry 672
+    0x1.p0,
+    -0x1.0p0, HUGE_VAL
+  },
+  { // Entry 673
+    0x1.p0,
+    -0x1.0p0, -HUGE_VAL
+  },
+  { // Entry 674
+    0x1.p0,
+    0x1.0p0, HUGE_VAL
+  },
+  { // Entry 675
+    0x1.p0,
+    0x1.0p0, -HUGE_VAL
+  },
+  { // Entry 676
+    0x1.p0,
+    0x1.0p0, 0x1.fffffffffffffp1023
+  },
+  { // Entry 677
+    0x1.p0,
+    0x1.0p0, -0x1.fffffffffffffp1023
+  },
+  { // Entry 678
+    0x1.p0,
+    -0x1.0p0, 0x1.fffffffffffffp1023
+  },
+  { // Entry 679
+    0x1.p0,
+    -0x1.0p0, -0x1.fffffffffffffp1023
+  },
+  { // Entry 680
+    0x1.p0,
+    0x1.0p0, 0x1.0p-1
+  },
+  { // Entry 681
+    0x1.p0,
+    0x1.0p0, -0x1.0p-1
+  },
+  { // Entry 682
+    0x1.p0,
+    0x1.0p0, 0x1.0p-1022
+  },
+  { // Entry 683
+    0x1.p0,
+    0x1.0p0, -0x1.0p-1022
+  },
+  { // Entry 684
+    0x1.p0,
+    0x1.0p0, 0x1.ffffffffffffep-1023
+  },
+  { // Entry 685
+    0x1.p0,
+    0x1.0p0, -0x1.ffffffffffffep-1023
+  },
+  { // Entry 686
+    0x1.p0,
+    0x1.0p0, 0x1.0p-1074
+  },
+  { // Entry 687
+    0x1.p0,
+    0x1.0p0, -0x1.0p-1074
+  },
+  { // Entry 688
+    0x1.p0,
+    0x1.0p0, 0.0
+  },
+  { // Entry 689
+    0x1.p0,
+    0x1.0p0, -0.0
+  },
+  { // Entry 690
+    0x1.p0,
+    HUGE_VAL, 0.0
+  },
+  { // Entry 691
+    0x1.p0,
+    HUGE_VAL, -0.0
+  },
+  { // Entry 692
+    0x1.p0,
+    0x1.fffffffffffffp1023, 0.0
+  },
+  { // Entry 693
+    0x1.p0,
+    0x1.fffffffffffffp1023, -0.0
+  },
+  { // Entry 694
+    0x1.p0,
+    0x1.0p-1022, 0.0
+  },
+  { // Entry 695
+    0x1.p0,
+    0x1.0p-1022, -0.0
+  },
+  { // Entry 696
+    0x1.p0,
+    0x1.0p-1074, 0.0
+  },
+  { // Entry 697
+    0x1.p0,
+    0x1.0p-1074, -0.0
+  },
+  { // Entry 698
+    0x1.p0,
+    0.0, 0.0
+  },
+  { // Entry 699
+    0x1.p0,
+    0.0, -0.0
+  },
+  { // Entry 700
+    0x1.p0,
+    -0.0, 0.0
+  },
+  { // Entry 701
+    0x1.p0,
+    -0.0, -0.0
+  },
+  { // Entry 702
+    0x1.p0,
+    -0x1.0p-1074, 0.0
+  },
+  { // Entry 703
+    0x1.p0,
+    -0x1.0p-1074, -0.0
+  },
+  { // Entry 704
+    0x1.p0,
+    -0x1.0p-1022, 0.0
+  },
+  { // Entry 705
+    0x1.p0,
+    -0x1.0p-1022, -0.0
+  },
+  { // Entry 706
+    0x1.p0,
+    -0x1.fffffffffffffp1023, 0.0
+  },
+  { // Entry 707
+    0x1.p0,
+    -0x1.fffffffffffffp1023, -0.0
+  },
+  { // Entry 708
+    0x1.p0,
+    -HUGE_VAL, 0.0
+  },
+  { // Entry 709
+    0x1.p0,
+    -HUGE_VAL, -0.0
+  },
+  { // Entry 710
+    HUGE_VAL,
+    0x1.0p-1022, -HUGE_VAL
+  },
+  { // Entry 711
+    HUGE_VAL,
+    0x1.0p-1074, -HUGE_VAL
+  },
+  { // Entry 712
+    HUGE_VAL,
+    -0x1.0p-1074, -HUGE_VAL
+  },
+  { // Entry 713
+    HUGE_VAL,
+    -0x1.0p-1022, -HUGE_VAL
+  },
+  { // Entry 714
+    0.0,
+    HUGE_VAL, -HUGE_VAL
+  },
+  { // Entry 715
+    0.0,
+    0x1.fffffffffffffp1023, -HUGE_VAL
+  },
+  { // Entry 716
+    0.0,
+    0x1.8p0, -HUGE_VAL
+  },
+  { // Entry 717
+    0.0,
+    -0x1.8p0, -HUGE_VAL
+  },
+  { // Entry 718
+    0.0,
+    -0x1.fffffffffffffp1023, -HUGE_VAL
+  },
+  { // Entry 719
+    0.0,
+    -HUGE_VAL, -HUGE_VAL
+  },
+  { // Entry 720
+    0.0,
+    0x1.0p-1022, HUGE_VAL
+  },
+  { // Entry 721
+    0.0,
+    0x1.0p-1074, HUGE_VAL
+  },
+  { // Entry 722
+    0.0,
+    0.0, HUGE_VAL
+  },
+  { // Entry 723
+    0.0,
+    -0.0, HUGE_VAL
+  },
+  { // Entry 724
+    0.0,
+    -0x1.0p-1074, HUGE_VAL
+  },
+  { // Entry 725
+    0.0,
+    -0x1.0p-1022, HUGE_VAL
+  },
+  { // Entry 726
+    HUGE_VAL,
+    HUGE_VAL, HUGE_VAL
+  },
+  { // Entry 727
+    HUGE_VAL,
+    0x1.fffffffffffffp1023, HUGE_VAL
+  },
+  { // Entry 728
+    HUGE_VAL,
+    0x1.8p0, HUGE_VAL
+  },
+  { // Entry 729
+    HUGE_VAL,
+    -0x1.8p0, HUGE_VAL
+  },
+  { // Entry 730
+    HUGE_VAL,
+    -0x1.fffffffffffffp1023, HUGE_VAL
+  },
+  { // Entry 731
+    HUGE_VAL,
+    -HUGE_VAL, HUGE_VAL
+  },
+  { // Entry 732
+    -0.0,
+    -HUGE_VAL, -0x1.8p1
+  },
+  { // Entry 733
+    -0.0,
+    -HUGE_VAL, -0x1.0p0
+  },
+  { // Entry 734
+    0.0,
+    -HUGE_VAL, -HUGE_VAL
+  },
+  { // Entry 735
+    0.0,
+    -HUGE_VAL, -0x1.921fb54442d18p1
+  },
+  { // Entry 736
+    0.0,
+    -HUGE_VAL, -0x1.921fb54442d18p0
+  },
+  { // Entry 737
+    0.0,
+    -HUGE_VAL, -0x1.fffffffffffffp1023
+  },
+  { // Entry 738
+    0.0,
+    -HUGE_VAL, -0x1.8p2
+  },
+  { // Entry 739
+    0.0,
+    -HUGE_VAL, -0x1.0p1
+  },
+  { // Entry 740
+    0.0,
+    -HUGE_VAL, -0x1.0p-1022
+  },
+  { // Entry 741
+    0.0,
+    -HUGE_VAL, -0x1.0p-1074
+  },
+  { // Entry 742
+    -HUGE_VAL,
+    -HUGE_VAL, 0x1.8p1
+  },
+  { // Entry 743
+    -HUGE_VAL,
+    -HUGE_VAL, 0x1.4p2
+  },
+  { // Entry 744
+    HUGE_VAL,
+    -HUGE_VAL, HUGE_VAL
+  },
+  { // Entry 745
+    HUGE_VAL,
+    -HUGE_VAL, 0x1.921fb54442d18p1
+  },
+  { // Entry 746
+    HUGE_VAL,
+    -HUGE_VAL, 0x1.921fb54442d18p0
+  },
+  { // Entry 747
+    HUGE_VAL,
+    -HUGE_VAL, 0x1.fffffffffffffp1023
+  },
+  { // Entry 748
+    HUGE_VAL,
+    -HUGE_VAL, 0x1.8p2
+  },
+  { // Entry 749
+    HUGE_VAL,
+    -HUGE_VAL, 0x1.0p1
+  },
+  { // Entry 750
+    HUGE_VAL,
+    -HUGE_VAL, 0x1.0p-1022
+  },
+  { // Entry 751
+    HUGE_VAL,
+    -HUGE_VAL, 0x1.0p-1074
+  },
+  { // Entry 752
+    0.0,
+    HUGE_VAL, -0x1.0p-1074
+  },
+  { // Entry 753
+    0.0,
+    HUGE_VAL, -0x1.0p-1022
+  },
+  { // Entry 754
+    0.0,
+    HUGE_VAL, -0x1.fffffffffffffp1023
+  },
+  { // Entry 755
+    0.0,
+    HUGE_VAL, -HUGE_VAL
+  },
+  { // Entry 756
+    HUGE_VAL,
+    HUGE_VAL, HUGE_VAL
+  },
+  { // Entry 757
+    HUGE_VAL,
+    HUGE_VAL, 0x1.fffffffffffffp1023
+  },
+  { // Entry 758
+    HUGE_VAL,
+    HUGE_VAL, 0x1.0p-1022
+  },
+  { // Entry 759
+    HUGE_VAL,
+    HUGE_VAL, 0x1.0p-1074
+  },
+  { // Entry 760
+    HUGE_VAL,
+    0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023
+  },
+  { // Entry 761
+    0.0,
+    0x1.0p-1022, 0x1.0p1
+  },
+  { // Entry 762
+    0.0,
+    -0x1.0p-1022, 0x1.0p1
+  },
+  { // Entry 763
+    0.0,
+    0x1.0p-1074, 0x1.0p1
+  },
+  { // Entry 764
+    0.0,
+    -0x1.0p-1074, 0x1.0p1
+  },
+  { // Entry 765
+    HUGE_VAL,
+    HUGE_VAL, 0x1.0p-1
+  },
+  { // Entry 766
+    0x1.fffffffffffff7ffffffffffffefffffp511,
+    0x1.fffffffffffffp1023, 0x1.0p-1
+  },
+  { // Entry 767
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep-1,
+    0x1.0p-1, 0x1.0p-1
+  },
+  { // Entry 768
+    0x1.p-511,
+    0x1.0p-1022, 0x1.0p-1
+  },
+  { // Entry 769
+    0x1.p-537,
+    0x1.0p-1074, 0x1.0p-1
+  },
+  { // Entry 770
+    0.0,
+    0.0, 0x1.0p-1
+  },
+  { // Entry 771
+    0.0,
+    -0.0, 0x1.0p-1
+  },
+  { // Entry 772
+    HUGE_VAL,
+    -HUGE_VAL, 0x1.0p-1
+  },
+  { // Entry 773
+    0.0,
+    HUGE_VAL, -0x1.0p-1
+  },
+  { // Entry 774
+    0x1.0000000000000400000000000018p-512,
+    0x1.fffffffffffffp1023, -0x1.0p-1
+  },
+  { // Entry 775
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.0p-1, -0x1.0p-1
+  },
+  { // Entry 776
+    0x1.p511,
+    0x1.0p-1022, -0x1.0p-1
+  },
+  { // Entry 777
+    0x1.p537,
+    0x1.0p-1074, -0x1.0p-1
+  },
+  { // Entry 778
+    HUGE_VAL,
+    0.0, -0x1.0p-1
+  },
+  { // Entry 779
+    HUGE_VAL,
+    -0.0, -0x1.0p-1
+  },
+  { // Entry 780
+    0.0,
+    -HUGE_VAL, -0x1.0p-1
+  },
+  { // Entry 781
+    0.0,
+    0x1.0p-1, HUGE_VAL
+  },
+  { // Entry 782
+    0.0,
+    0x1.0p-1, 0x1.fffffffffffffp1023
+  },
+  { // Entry 783
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep-1,
+    0x1.0p-1, 0x1.0p-1
+  },
+  { // Entry 784
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1, 0x1.0p-1022
+  },
+  { // Entry 785
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1, 0x1.0p-1074
+  },
+  { // Entry 786
+    0x1.p0,
+    0x1.0p-1, 0.0
+  },
+  { // Entry 787
+    0x1.p0,
+    0x1.0p-1, -0.0
+  },
+  { // Entry 788
+    0x1.p0,
+    0x1.0p-1, -0x1.0p-1074
+  },
+  { // Entry 789
+    0x1.p0,
+    0x1.0p-1, -0x1.0p-1022
+  },
+  { // Entry 790
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.0p-1, -0x1.0p-1
+  },
+  { // Entry 791
+    HUGE_VAL,
+    0x1.0p-1, -0x1.fffffffffffffp1023
+  },
+  { // Entry 792
+    HUGE_VAL,
+    0x1.0p-1, -HUGE_VAL
+  },
+  { // Entry 793
+    0.0,
+    -0x1.0p-1, HUGE_VAL
+  },
+  { // Entry 794
+    0.0,
+    -0x1.0p-1, 0x1.fffffffffffffp1023
+  },
+  { // Entry 795
+    0x1.p0,
+    -0x1.0p-1, 0.0
+  },
+  { // Entry 796
+    0x1.p0,
+    -0x1.0p-1, -0.0
+  },
+  { // Entry 797
+    HUGE_VAL,
+    -0x1.0p-1, -0x1.fffffffffffffp1023
+  },
+  { // Entry 798
+    HUGE_VAL,
+    -0x1.0p-1, -HUGE_VAL
+  },
+  { // Entry 799
+    0x1.p1,
+    0x1.0p2, 0x1.0p-1
+  },
+  { // Entry 800
+    0x1.80p1,
+    0x1.2p3, 0x1.0p-1
+  },
+  { // Entry 801
+    0x1.p2,
+    0x1.0p4, 0x1.0p-1
+  },
+  { // Entry 802
+    0x1.p-1,
+    0x1.0p2, -0x1.0p-1
+  },
+  { // Entry 803
+    0x1.p-2,
+    0x1.0p4, -0x1.0p-1
+  },
+  { // Entry 804
+    0x1.p-3,
+    0x1.0p6, -0x1.0p-1
+  },
+  { // Entry 805
+    HUGE_VAL,
+    0x1.fffffffffffffp-1, -0x1.74910d52d3052p62
+  },
+  { // Entry 806
+    0.0,
+    0x1.fffffffffffffp-1, 0x1.74910d52d3052p62
+  },
+  { // Entry 807
+    0x1.p2,
+    0x1.0p1, 0x1.0p1
+  },
+  { // Entry 808
+    0x1.p-2,
+    0x1.0p1, -0x1.0p1
+  },
+  { // Entry 809
+    0x1.p2,
+    -0x1.0p1, 0x1.0p1
+  },
+  { // Entry 810
+    0x1.p-2,
+    -0x1.0p1, -0x1.0p1
+  },
+  { // Entry 811
+    0x1.b0p4,
+    0x1.8p1, 0x1.8p1
+  },
+  { // Entry 812
+    0x1.86a0p11,
+    0x1.4p2, 0x1.4p2
+  },
+  { // Entry 813
+    0x1.921ee0p19,
+    0x1.cp2, 0x1.cp2
+  },
+  { // Entry 814
+    0x1.2a05f2p33,
+    0x1.4p3, 0x1.4p3
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_pow, pow_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_pow_intel_data)/sizeof(pow_intel_data_t); i++) {
+    EXPECT_DOUBLE_EQ(g_pow_intel_data[i].expected, pow(g_pow_intel_data[i].x_call_data, g_pow_intel_data[i].y_call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_powf_test.cpp b/tests/math_powf_test.cpp
new file mode 100644
index 0000000..f77b23a
--- /dev/null
+++ b/tests/math_powf_test.cpp
@@ -0,0 +1,2788 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  float expected;
+  float x_call_data;
+  float y_call_data;
+} powf_intel_data_t;
+
+static powf_intel_data_t g_powf_intel_data[] = {
+  { // Entry 0
+    HUGE_VALF,
+    -0.0, -0x1.000002p-1
+  },
+  { // Entry 1
+    0.0f,
+    -0x1.p-5, 0x1.e0p4
+  },
+  { // Entry 2
+    -0.0f,
+    -0x1.p-30, 0x1.40p2
+  },
+  { // Entry 3
+    0x1.p0,
+    -0x1.p0, 0x1.000002p32
+  },
+  { // Entry 4
+    0x1.p0,
+    -0x1.000002p-41, 0.0
+  },
+  { // Entry 5
+    0x1.d1a029128778fca3f9a261be1cb86be7p-121,
+    -0x1.000006p0, -0x1.bc1ee2p27
+  },
+  { // Entry 6
+    0x1.da6e3ff202da752de523f9846303c0b5p-124,
+    -0x1.00000ap0, -0x1.111112p27
+  },
+  { // Entry 7
+    0x1.eb70a2fbb8b2489b8d838eb65ed676acp-91,
+    -0x1.00000ap0, -0x1.8f83e4p26
+  },
+  { // Entry 8
+    HUGE_VALF,
+    -0x1.000028p0, 0x1.20p44
+  },
+  { // Entry 9
+    0x1.002001p-4,
+    -0x1.0010p-2, 0x1.p1
+  },
+  { // Entry 10
+    0x1.002001p-82,
+    -0x1.0010p-41, 0x1.p1
+  },
+  { // Entry 11
+    0x1.004004p-82,
+    -0x1.0020p-41, 0x1.p1
+  },
+  { // Entry 12
+    0x1.006009p-12,
+    -0x1.0030p-6, 0x1.p1
+  },
+  { // Entry 13
+    -0x1.fb859adbdb7df6974c5c9a5489e6972ap53,
+    -0x1.0040p-6, -0x1.20p3
+  },
+  { // Entry 14
+    0x1.008010p-82,
+    -0x1.0040p-41, 0x1.p1
+  },
+  { // Entry 15
+    0x1.00e031p-40,
+    -0x1.0070p-20, 0x1.p1
+  },
+  { // Entry 16
+    0x1.31e452ffffec96a3d5a882fe244f8c63p-1,
+    -0x1.046ef4p0, -0x1.e0p4
+  },
+  { // Entry 17
+    0x1.33e8f304p-36,
+    -0x1.08p-6, 0x1.80p2
+  },
+  { // Entry 18
+    0x1.d82001fe9d6bdbba98638def8d37e50bp-124,
+    -0x1.1ec38cp0, -0x1.78p9
+  },
+  { // Entry 19
+    -0x1.45f3bdeaa5f60d121c3fa751dbd758adp36,
+    -0x1.bffffep-6, -0x1.c0p2
+  },
+  { // Entry 20
+    0x1.df41ae7ef4e15e8ad45c7293ddc3fe7dp61,
+    -0x1.fffffap-1, -0x1.c9b244p27
+  },
+  { // Entry 21
+    0x1.df46f26f1f129a54922022f9b653a99fp61,
+    -0x1.fffffap-1, -0x1.c9b262p27
+  },
+  { // Entry 22
+    -0x1.00000300000900001b0000510000f3p21,
+    -0x1.fffffap-22, -0x1.p0
+  },
+  { // Entry 23
+    -0x1.00000300000900001b0000510000f3p-99,
+    -0x1.fffffap98, -0x1.p0
+  },
+  { // Entry 24
+    -0x1.78b55ef8aecb0b7c5b8865e27157d824p-2,
+    -0x1.fffffcp-1, 0x1.000002p23
+  },
+  { // Entry 25
+    -0x1.fffffep-41,
+    -0x1.fffffep-41, 0x1.p0
+  },
+  { // Entry 26
+    0x1.p71,
+    0x1.p-2, -0x1.1cp5
+  },
+  { // Entry 27
+    0x1.d580710e38463c3dd62fce98f203b471p-1,
+    0x1.p-2, 0x1.0007p-4
+  },
+  { // Entry 28
+    0x1.p-15,
+    0x1.p-2, 0x1.e0p2
+  },
+  { // Entry 29
+    0.0f,
+    0x1.p-3, 0x1.8ffffep5
+  },
+  { // Entry 30
+    0x1.p-40,
+    0x1.p-5, 0x1.p3
+  },
+  { // Entry 31
+    0x1.p40,
+    0x1.p-10, -0x1.p2
+  },
+  { // Entry 32
+    0x1.ecfff0b449d7c9a5d494c884c717f9cdp-88,
+    0x1.p-144, 0x1.3586fep-1
+  },
+  { // Entry 33
+    0x1.ecfff0b449d7c9a5d494c884c717f9cdp-106,
+    0x1.p-144, 0x1.7586fep-1
+  },
+  { // Entry 34
+    HUGE_VALF,
+    0x1.p-149, -0x1.ccacccp-1
+  },
+  { // Entry 35
+    HUGE_VALF,
+    0x1.p-149, -0x1.e6e666p-1
+  },
+  { // Entry 36
+    0x1.e8e101355bd975bfec3fb5ed3757777dp-1,
+    0x1.000002p-2, 0x1.1111p-5
+  },
+  { // Entry 37
+    0x1.ddb64347a55e452ed04d6a173ca5b56cp99,
+    0x1.000002p-111, -0x1.ccccccp-1
+  },
+  { // Entry 38
+    0x1.558e990004a8ebb3e8176275ba9f1052p52,
+    0x1.000002p-112, -0x1.df3b5ap-2
+  },
+  { // Entry 39
+    0x1.fffffd0000053ffff66000120bffddb6p92,
+    0x1.000002p-124, -0x1.80p-1
+  },
+  { // Entry 40
+    0x1.fffffffffff800000800000555554555p-1,
+    0x1.000002p0, -0x1.p-23
+  },
+  { // Entry 41
+    0x1.fffffffffff9000007000002eaaaa02ap-1,
+    0x1.000002p0, -0x1.c0p-24
+  },
+  { // Entry 42
+    0x1.ddb6530d485b7badb441a4460ca54c62p9,
+    0x1.000002p11, 0x1.ccccc6p-1
+  },
+  { // Entry 43
+    0x1.d901790cd9d1b9d8cdf616296479022fp-14,
+    0x1.000002p17, -0x1.8af8b0p-1
+  },
+  { // Entry 44
+    0x1.e6d3f90d414447b2f2467d4c214496bdp30,
+    0x1.000002p42, 0x1.7904a4p-1
+  },
+  { // Entry 45
+    0x1.000012ffffd68004fa7fb159108ec97dp0,
+    0x1.00001cp0, 0x1.5b6dbap-1
+  },
+  { // Entry 46
+    0x1.d174810e1e4527f011547dfc4dc6b48cp-3,
+    0x1.00001cp3, -0x1.6ccccep-1
+  },
+  { // Entry 47
+    0x1.d581970e8b4ccc9dbc28899bd1848e24p-1,
+    0x1.00002ep-2, 0x1.ffffcep-5
+  },
+  { // Entry 48
+    0x1.000455000312cc6e79ced653c38d7e2ap0,
+    0x1.000038p-50, -0x1.fff77ep-20
+  },
+  { // Entry 49
+    0x1.00480900a807e03f01500480090008p-81,
+    0x1.0008p-9, 0x1.20p3
+  },
+  { // Entry 50
+    0x1.ffc004ffb0045fc8029fe20149f2408ep39,
+    0x1.0008p-10, -0x1.p2
+  },
+  { // Entry 51
+    0x1.fec1bb35b5a826526101adab0695d1d3p-1,
+    0x1.00e0p0, -0x1.6ccccep-1
+  },
+  { // Entry 52
+    0x1.fadbde187acba5b3a6c4cde78e1bbb4ap45,
+    0x1.01fffcp0, 0x1.p12
+  },
+  { // Entry 53
+    0x1.ff1fb6ff79a5e0391b1d7dfb14de7de6p22,
+    0x1.01fffep0, 0x1.000cb6p11
+  },
+  { // Entry 54
+    0x1.6cbbc2fff64c73aab0033df757f3808dp11,
+    0x1.0220p0, 0x1.e295f2p9
+  },
+  { // Entry 55
+    0x1.f81f5312ba449421bd9393ad8df53aaep-1,
+    0x1.04p0, -0x1.0006p0
+  },
+  { // Entry 56
+    0x1.ffe88affffff33e933cfaad5f0ee2678p-1,
+    0x1.08c7eep-16, 0x1.0f94b2p-16
+  },
+  { // Entry 57
+    0x1.0000dcffffc6fee7e4aac09a3d9fb9a1p0,
+    0x1.0ep-20, -0x1.000cdcp-20
+  },
+  { // Entry 58
+    0x1.70ce05e629803c0ca47482392a882debp-3,
+    0x1.0ep3, -0x1.9b91bap-1
+  },
+  { // Entry 59
+    0x1.5a8926e473f6148a5a383bfa1ed0b335p-90,
+    0x1.0ffffep0, -0x1.0000fep10
+  },
+  { // Entry 60
+    0x1.8ec5b2e1606728f21cf2c90c2e4d2a9bp-93,
+    0x1.0ffffep0, -0x1.07fffep10
+  },
+  { // Entry 61
+    0x1.a47dd4ffffe25486314351413837b2fdp4,
+    0x1.1624p-4, -0x1.3720c0p0
+  },
+  { // Entry 62
+    0x1.442401p0,
+    0x1.2010p0, 0x1.p1
+  },
+  { // Entry 63
+    0x1.e7aaf2ffffbce86a4fd2cf9cb53d7e55p-1,
+    0x1.253264p0, -0x1.6f826ep-2
+  },
+  { // Entry 64
+    0x1.4d63290052d4d2d894b4635cb9b98130p-39,
+    0x1.2711c8p-6, 0x1.aa804ep2
+  },
+  { // Entry 65
+    0x1.b20168da0fc1fca6d3c1b8c23fdcaf39p49,
+    0x1.2aaaaap-1, -0x1.fff1fep5
+  },
+  { // Entry 66
+    0x1.ee26c12ebf5b649bef95484ece113007p2,
+    0x1.2f7dc0p-23, -0x1.0967c0p-3
+  },
+  { // Entry 67
+    0x1.bc90590000002ee11763c6fe2418730cp-2,
+    0x1.334478p-2, 0x1.62e42ep-1
+  },
+  { // Entry 68
+    0x1.8c8c8300308cee7c1a41b09294323cfbp-82,
+    0x1.3ffffep-1, 0x1.e0p6
+  },
+  { // Entry 69
+    0x1.643d4efffe606e056e4035b0becc20fdp-5,
+    0x1.3ffffep-40, 0x1.d2f190p-4
+  },
+  { // Entry 70
+    0x1.f8148914d4ea3af94ee724572f2ee8ffp-1,
+    0x1.41d420p20, -0x1.22p-10
+  },
+  { // Entry 71
+    0x1.cd6e9100038c93a7dce72a113ca56c70p-2,
+    0x1.443a42p-2, 0x1.62e42ep-1
+  },
+  { // Entry 72
+    0x1.f895910f392f3b8fcc641ae87164d684p-1,
+    0x1.45a2a8p1, -0x1.p-6
+  },
+  { // Entry 73
+    0x1.e3dff8fff6e9efd4f167a7b91eb882afp-1,
+    0x1.45d174p-1, 0x1.00001cp-3
+  },
+  { // Entry 74
+    0x1.d332f0fffc83128a7fc7bd56be27e755p-2,
+    0x1.4a1704p-2, 0x1.62e42ep-1
+  },
+  { // Entry 75
+    0x1.d5ae790003cb17cf83deb5e2cc0ea01cp-2,
+    0x1.4c9f94p-2, 0x1.62e42ep-1
+  },
+  { // Entry 76
+    0x1.ca8ec6ed5df39f991f808d94dd5c8834p88,
+    0x1.4e9cc2p-30, -0x1.80p1
+  },
+  { // Entry 77
+    0x1.d9b648fffc167ed8b917b64f747e6270p-2,
+    0x1.50bfc8p-2, 0x1.62e42ep-1
+  },
+  { // Entry 78
+    0x1.da95070001a3799fee02ea034357a8c2p-2,
+    0x1.51a450p-2, 0x1.62e42ep-1
+  },
+  { // Entry 79
+    0x1.fe957b38c5b6959bb0ea80e43c709ecap-1,
+    0x1.679286p-11, 0x1.8ea824p-12
+  },
+  { // Entry 80
+    0x1.aca91b5f3882f36dcdab2a8d641c0ab5p-56,
+    0x1.745d18p-4, 0x1.ff1ffep3
+  },
+  { // Entry 81
+    0x1.f82eb711ff0066ee591658258b692331p-1,
+    0x1.77fffep-120, 0x1.85bc7ap-13
+  },
+  { // Entry 82
+    0x1.d98c8300003e83fd25b95381f702161cp-1,
+    0x1.7a3d0ep0, -0x1.99999ap-3
+  },
+  { // Entry 83
+    0x1.f82cef13a11a5f5a0562fe52c88207bdp-1,
+    0x1.7c9a16p-2, 0x1.fddffep-7
+  },
+  { // Entry 84
+    0x1.d0d014fffe715e2732b6d1ced96adb76p19,
+    0x1.7e9bb0p-8, -0x1.569828p1
+  },
+  { // Entry 85
+    0x1.8518e2fffdea301062ac6a29c6e53df6p-1,
+    0x1.851ebap-1, 0x1.000ep0
+  },
+  { // Entry 86
+    0x1.2da1e8fffe1350e4daf5553e75dca020p-4,
+    0x1.861862p-4, 0x1.1cp0
+  },
+  { // Entry 87
+    0x1.dd037a2c561bfe1824p-11,
+    0x1.8ce632p-4, 0x1.80p1
+  },
+  { // Entry 88
+    0x1.f81fa713d2b23eac52a36f4b3a33023ep-1,
+    0x1.8f86aap-1, 0x1.0000e0p-4
+  },
+  { // Entry 89
+    0x1.03f14b095ae687525a7e377e3505e587p0,
+    0x1.90p5, 0x1.0008p-8
+  },
+  { // Entry 90
+    0x1.36395100005cc4113b220d6ce672e165p0,
+    0x1.95578ep1, 0x1.555556p-3
+  },
+  { // Entry 91
+    0x1.f83249134e77a21bf811350c6a931beep-1,
+    0x1.98p5, -0x1.000002p-8
+  },
+  { // Entry 92
+    0x1.9f628b3cfd06f417f86e1ca8edc1469ep117,
+    0x1.99999cp3, 0x1.p5
+  },
+  { // Entry 93
+    0x1.d4851ccedafdd1cbc79a6a6b3dbb1cbep119,
+    0x1.9a66d0p-14, -0x1.20p3
+  },
+  { // Entry 94
+    0x1.2536270001fab70a29d68e60feb11211p-11,
+    0x1.9ffffep41, -0x1.094f1cp-2
+  },
+  { // Entry 95
+    0x1.d08ae8fffdc7029e0bd02c871606a01cp0,
+    0x1.a57becp1, 0x1.p-1
+  },
+  { // Entry 96
+    0x1.b83638ffb21561a23ec9b8a7b0ba7b52p15,
+    0x1.aaaaaep-1, -0x1.e0p5
+  },
+  { // Entry 97
+    0x1.c198860000001c1cee146e451365eae1p-10,
+    0x1.ad1d1cp-14, 0x1.62e42ep-1
+  },
+  { // Entry 98
+    0x1.cd0c6eefc33dfc2ef3d2beb81ad568cap30,
+    0x1.b13b1cp-1, -0x1.ffff1ep6
+  },
+  { // Entry 99
+    0x1.6228e4fef882769ba040164fc4bca0cbp-81,
+    0x1.b7ffd8p-1, 0x1.705394p8
+  },
+  { // Entry 100
+    0x1.ae9d756c84b4063f238dd151bec30e0bp-99,
+    0x1.be0d7cp-1, 0x1.ede448p8
+  },
+  { // Entry 101
+    0x1.913f68f101ebe490d29d873d1e0fd828p-85,
+    0x1.be0f70p-1, 0x1.a8147ap8
+  },
+  { // Entry 102
+    0x1.b1e7215c128082aab49edab1641919a8p-99,
+    0x1.be0f70p-1, 0x1.ede5d8p8
+  },
+  { // Entry 103
+    0x1.dc574183f03d7a333c18fc6916daa859p-96,
+    0x1.bff0d0p-1, 0x1.ed2fb4p8
+  },
+  { // Entry 104
+    0x1.da6fcd00020da659e4a50ba993a71d92p6,
+    0x1.bffffep1, 0x1.e7f782p1
+  },
+  { // Entry 105
+    HUGE_VALF,
+    0x1.c25c26p-44, -0x1.40p3
+  },
+  { // Entry 106
+    0x1.951dfaf0d0341097e50f8d51fb5b0b2ap-72,
+    0x1.c4ec74p-1, 0x1.935234p8
+  },
+  { // Entry 107
+    0x1.fb1c6cfffef199884e78c26fef057fc3p4,
+    0x1.c76380p0, 0x1.80087cp2
+  },
+  { // Entry 108
+    0x1.d82d7dffffefc26e1f09e6d73a276d81p-10,
+    0x1.cc8d06p-14, 0x1.62e42ep-1
+  },
+  { // Entry 109
+    0x1.997e0eef7bb3d4eda40dc43c72a53167p-70,
+    0x1.d1cdccp-1, 0x1.fc2640p8
+  },
+  { // Entry 110
+    0x1.fe82dd381a8d3056a4c554f1e1764f9dp-1,
+    0x1.d40a66p-3, 0x1.02964cp-9
+  },
+  { // Entry 111
+    0x1.f3ab1937169c9ab7aac67b94894ede10p-1,
+    0x1.d55552p-2, 0x1.000038p-5
+  },
+  { // Entry 112
+    0x1.fe805f37b89bc0c8b0163db7c11f48f2p-1,
+    0x1.da12f0p-1, 0x1.38p-5
+  },
+  { // Entry 113
+    0x1.c27937000f6c15a86f8eb042a0895566p-73,
+    0x1.df0a82p-1, 0x1.77fbc0p9
+  },
+  { // Entry 114
+    0x1.c64b0d000027dbefa1e3233ef53619b7p105,
+    0x1.dffffep52, 0x1.00087cp1
+  },
+  { // Entry 115
+    0x1.0847b080e10a3f33ba599a218b630ffbp0,
+    0x1.e06b8cp-1, -0x1.p-1
+  },
+  { // Entry 116
+    0x1.eff5716fa057c0db02972e5b51a95899p-1,
+    0x1.e06b8cp-1, 0x1.p-1
+  },
+  { // Entry 117
+    0x1.083f7f587cdb6cc005ee70abb128067cp0,
+    0x1.e08956p-1, -0x1.p-1
+  },
+  { // Entry 118
+    0x1.f004d186653df746f46ac1da51e68817p-1,
+    0x1.e08956p-1, 0x1.p-1
+  },
+  { // Entry 119
+    0x1.2e78986ce71690689a17b09e2fd01256p0,
+    0x1.e0ee8ap-1, -0x1.5515p1
+  },
+  { // Entry 120
+    0x1.34e306ebdacb3fb249efb92c5df50a30p0,
+    0x1.e0ee8ap-1, -0x1.80p1
+  },
+  { // Entry 121
+    0x1.1a22a2b284843cef729aa7923200616bp0,
+    0x1.e0ee8ap-1, -0x1.8d89d8p0
+  },
+  { // Entry 122
+    0x1.1d8befed03f9ed8d628e72acfd5846f2p0,
+    0x1.e0ee8ap-1, -0x1.beb050p0
+  },
+  { // Entry 123
+    0x1.e9e518fb1617eceb976b420930a3ce51p-1,
+    0x1.e0ee8ap-1, 0x1.68f880p-1
+  },
+  { // Entry 124
+    0x1.a0bdbae7d1b95d1adb05939aefcd35f2p-93,
+    0x1.e13d0ep-1, 0x1.0220p10
+  },
+  { // Entry 125
+    0x1.8789269c3d7361f6464f369baecd358fp-90,
+    0x1.e1f07ep-1, 0x1.p10
+  },
+  { // Entry 126
+    0x1.f67dcb0d034ec28a4309c4415565f9ecp1,
+    0x1.e4000ep5, 0x1.55555ap-2
+  },
+  { // Entry 127
+    0x1.e65785986fb7af1219234980dca4ef34p-93,
+    0x1.e6f314p-1, 0x1.3e0f80p10
+  },
+  { // Entry 128
+    0x1.e9a57691f06acbd3893901e376830537p-125,
+    0x1.e97470p-1, 0x1.dd67c0p10
+  },
+  { // Entry 129
+    0x1.866ec900017d689ca5deb18c4769effbp-2,
+    0x1.f040c8p-1, 0x1.eddbacp4
+  },
+  { // Entry 130
+    0x1.f839d5101bcf305e04c187afb53a6c53p-1,
+    0x1.f091e2p-1, 0x1.p-1
+  },
+  { // Entry 131
+    0x1.a374c2b00b62172cd4678df5e503b6f1p-13,
+    0x1.f60c04p-14, 0x1.e2e42ep-1
+  },
+  { // Entry 132
+    0x1.f8479b115561f17028b236fb8f2c173fp-1,
+    0x1.ff174ap-1, 0x1.119996p3
+  },
+  { // Entry 133
+    0x1.f947cf0debb3f5149df66e08396f65c5p3,
+    0x1.ff1ffep3, 0x1.fddffep-1
+  },
+  { // Entry 134
+    0x1.f3ae6b36c3163cd2d42f1eddf4e95886p-1,
+    0x1.ff7ffep0, -0x1.203c88p-5
+  },
+  { // Entry 135
+    0x1.f842b5127e562bf4cc2fb2aa30312393p-1,
+    0x1.ffbffep-10, 0x1.3ffffep-9
+  },
+  { // Entry 136
+    0x1.fc042cfcabd3d00c3fd7e9d168a20182p-1,
+    0x1.ffc0p-1, 0x1.ffc7fep3
+  },
+  { // Entry 137
+    0x1.f836cd12927fe3ea2eb9810462c208dcp-1,
+    0x1.fff77ep100, -0x1.cb0968p-13
+  },
+  { // Entry 138
+    0x1.fff3fd0c0608c60d8c3c9f07648607d5p14,
+    0x1.fff7fep9, 0x1.80p0
+  },
+  { // Entry 139
+    0x1.f811d3140d17296dc633cd00bfd96387p-1,
+    0x1.fff8p-1, 0x1.ff80p7
+  },
+  { // Entry 140
+    0x1.fe9d9738d0ca9f11f97a71b1a366145ap-1,
+    0x1.fffefep1, -0x1.fffff8p-10
+  },
+  { // Entry 141
+    0x1.f202b300003069a7a886e44fbf6073c2p72,
+    0x1.ffff3ep127, 0x1.23d714p-1
+  },
+  { // Entry 142
+    0x1.b834a192875d72ac81b7915cf8979690p-96,
+    0x1.ffffbep-1, 0x1.p25
+  },
+  { // Entry 143
+    0x1.ffffed000029bffddef5495e5603ce3bp-1,
+    0x1.ffffe2p-1, 0x1.44443ep-1
+  },
+  { // Entry 144
+    0x1.d6ab5d0e7ae03433ad824616d0db8b03p15,
+    0x1.ffffeep-40, -0x1.a0ea0cp-2
+  },
+  { // Entry 145
+    0x1.000002fffffffffff27fffe4ffffebc0p0,
+    0x1.fffffap-1, -0x1.fffffap-1
+  },
+  { // Entry 146
+    0x1.00000000000400000400000d55556d55p0,
+    0x1.fffffcp-1, -0x1.p-23
+  },
+  { // Entry 147
+    0x1.00000000000380000380000acaaabdeap0,
+    0x1.fffffcp-1, -0x1.c0p-24
+  },
+  { // Entry 148
+    0x1.ee8fc930954d29b3e28c5c1eafb9f7fdp4,
+    0x1.fffffcp-67, -0x1.33334ep-4
+  },
+  { // Entry 149
+    0x1.6a0a0cfff3ffa00e753af84c0100fbf0p13,
+    0x1.fffffcp-106, -0x1.075078p-3
+  },
+  { // Entry 150
+    0x1.9aaabcfff2ae3e7c84e87085640355e4p48,
+    0x1.fffffcp-120, -0x1.a2e8bep-2
+  },
+  { // Entry 151
+    0x1.f5777afffe2b46a4da98759043de4862p-52,
+    0x1.fffffcp80, -0x1.428f58p-1
+  },
+  { // Entry 152
+    0x1.73d3321e7f247def1ed4c816c824c77dp-67,
+    0x1.fffffcp119, -0x1.1b91b4p-1
+  },
+  { // Entry 153
+    0x1.000001000001000001000001000001p10,
+    0x1.fffffep-11, -0x1.p0
+  },
+  { // Entry 154
+    0x1.fffffeffffffbfffffdfffffebfffff1p0,
+    0x1.fffffep1, 0x1.p-1
+  },
+  { // Entry 155
+    0x1.cb5a0d0002f5169a13de39863bb5f91dp-2,
+    0x1.421efap-2, 0x1.62e42ep-1
+  },
+  { // Entry 156
+    0x1.cb720dcef90691503cbd1e949db761d9p-1,
+    0x1.p-5, 0x1.p-5
+  },
+  { // Entry 157
+    0x1.p-5,
+    0x1.p-5, 0x1.p0
+  },
+  { // Entry 158
+    0x1.p0,
+    0x1.p0, 0x1.p-5
+  },
+  { // Entry 159
+    0x1.p0,
+    0x1.p0, 0x1.p0
+  },
+  { // Entry 160
+    0x1.p-40,
+    0x1.p-5, 0x1.p3
+  },
+  { // Entry 161
+    0.0f,
+    0x1.p-5, 0x1.p5
+  },
+  { // Entry 162
+    0x1.p0,
+    0x1.p0, 0x1.p3
+  },
+  { // Entry 163
+    0x1.p0,
+    0x1.p0, 0x1.p5
+  },
+  { // Entry 164
+    0.0f,
+    0x1.p-5, 0x1.p10
+  },
+  { // Entry 165
+    0.0f,
+    0x1.p-5, 0x1.p12
+  },
+  { // Entry 166
+    0x1.p0,
+    0x1.p0, 0x1.p10
+  },
+  { // Entry 167
+    0x1.p0,
+    0x1.p0, 0x1.p12
+  },
+  { // Entry 168
+    0x1.11301d0125b50a4ebbf1aed9318ceac5p0,
+    0x1.p3, 0x1.p-5
+  },
+  { // Entry 169
+    0x1.p3,
+    0x1.p3, 0x1.p0
+  },
+  { // Entry 170
+    0x1.1d4873168b9aa7805b8028990f07a98bp0,
+    0x1.p5, 0x1.p-5
+  },
+  { // Entry 171
+    0x1.p5,
+    0x1.p5, 0x1.p0
+  },
+  { // Entry 172
+    0x1.p24,
+    0x1.p3, 0x1.p3
+  },
+  { // Entry 173
+    0x1.p96,
+    0x1.p3, 0x1.p5
+  },
+  { // Entry 174
+    0x1.p40,
+    0x1.p5, 0x1.p3
+  },
+  { // Entry 175
+    HUGE_VALF,
+    0x1.p5, 0x1.p5
+  },
+  { // Entry 176
+    HUGE_VALF,
+    0x1.p3, 0x1.p10
+  },
+  { // Entry 177
+    HUGE_VALF,
+    0x1.p3, 0x1.p12
+  },
+  { // Entry 178
+    HUGE_VALF,
+    0x1.p5, 0x1.p10
+  },
+  { // Entry 179
+    HUGE_VALF,
+    0x1.p5, 0x1.p12
+  },
+  { // Entry 180
+    0x1.3dea64c12342235b41223e13d773fba2p0,
+    0x1.p10, 0x1.p-5
+  },
+  { // Entry 181
+    0x1.p10,
+    0x1.p10, 0x1.p0
+  },
+  { // Entry 182
+    0x1.4bfdad5362a271d4397afec42e20e036p0,
+    0x1.p12, 0x1.p-5
+  },
+  { // Entry 183
+    0x1.p12,
+    0x1.p12, 0x1.p0
+  },
+  { // Entry 184
+    0x1.p80,
+    0x1.p10, 0x1.p3
+  },
+  { // Entry 185
+    HUGE_VALF,
+    0x1.p10, 0x1.p5
+  },
+  { // Entry 186
+    0x1.p96,
+    0x1.p12, 0x1.p3
+  },
+  { // Entry 187
+    HUGE_VALF,
+    0x1.p12, 0x1.p5
+  },
+  { // Entry 188
+    0x1.00000126055cfd443c5376930d169f32p2,
+    0x1.6a09e6p-1, -0x1.p2
+  },
+  { // Entry 189
+    0x1.fffffdb3f548a8d827b65c88p-3,
+    0x1.6a09e6p-1, 0x1.p2
+  },
+  { // Entry 190
+    0x1.00000126055cfd443c5376930d169f32p-2,
+    0x1.6a09e6p0, -0x1.p2
+  },
+  { // Entry 191
+    0x1.fffffdb3f548a8d827b65c88p1,
+    0x1.6a09e6p0, 0x1.p2
+  },
+  { // Entry 192
+    0x1.00000126055cfd443c5376930d169f32p2,
+    0x1.6a09e6p-1, -0x1.p2
+  },
+  { // Entry 193
+    0x1.fffffdb3f548a8d827b65c88p-3,
+    0x1.6a09e6p-1, 0x1.p2
+  },
+  { // Entry 194
+    0x1.00000126055cfd443c5376930d169f32p-2,
+    0x1.6a09e6p0, -0x1.p2
+  },
+  { // Entry 195
+    0x1.fffffdb3f548a8d827b65c88p1,
+    0x1.6a09e6p0, 0x1.p2
+  },
+  { // Entry 196
+    0x1.00162f3916670d119697154ae3512c2dp0,
+    0x1.6a09e6p-1, -0x1.p-10
+  },
+  { // Entry 197
+    0x1.ffd3a565caf8d230dae1250693a55f23p-1,
+    0x1.6a09e6p-1, 0x1.p-10
+  },
+  { // Entry 198
+    0x1.ffd3a5661473cb269f894b40d6cf9bacp-1,
+    0x1.6a09e6p0, -0x1.p-10
+  },
+  { // Entry 199
+    0x1.00162f38f1a33230bc340bd3752fc094p0,
+    0x1.6a09e6p0, 0x1.p-10
+  },
+  { // Entry 200
+    0x1.948b0fcd6e9e06522c3f35ba781948b0p1,
+    0x1.80p-1, -0x1.p2
+  },
+  { // Entry 201
+    0x1.44p-2,
+    0x1.80p-1, 0x1.p2
+  },
+  { // Entry 202
+    0x1.948b0fcd6e9e06522c3f35ba781948b0p-3,
+    0x1.80p0, -0x1.p2
+  },
+  { // Entry 203
+    0x1.44p2,
+    0x1.80p0, 0x1.p2
+  },
+  { // Entry 204
+    0x1.279a74590331c4d218f81e4afb257d06p0,
+    0x1.80p-1, -0x1.p-1
+  },
+  { // Entry 205
+    0x1.bb67ae8584caa73b25742d7078b83b89p-1,
+    0x1.80p-1, 0x1.p-1
+  },
+  { // Entry 206
+    0x1.a20bd700c2c3dfc042cc1aed7871db45p-1,
+    0x1.80p0, -0x1.p-1
+  },
+  { // Entry 207
+    0x1.3988e1409212e7d0321914321a556473p0,
+    0x1.80p0, 0x1.p-1
+  },
+  { // Entry 208
+    0x1.00126a0b93db294cabe33da735437f51p0,
+    0x1.80p-1, -0x1.p-10
+  },
+  { // Entry 209
+    0x1.ffdb2e8ed2a1fe71bd59fdd610313046p-1,
+    0x1.80p-1, 0x1.p-10
+  },
+  { // Entry 210
+    0x1.ffcc1c5973b2129a5b1424e0c88786b8p-1,
+    0x1.80p0, -0x1.p-10
+  },
+  { // Entry 211
+    0x1.0019f474aa190038c6af775d92f1d725p0,
+    0x1.80p0, 0x1.p-10
+  },
+  { // Entry 212
+    0x1.p0,
+    0x1.p0, -0x1.p2
+  },
+  { // Entry 213
+    0x1.p0,
+    0x1.p0, 0x1.p2
+  },
+  { // Entry 214
+    0x1.p-4,
+    0x1.p1, -0x1.p2
+  },
+  { // Entry 215
+    0x1.p4,
+    0x1.p1, 0x1.p2
+  },
+  { // Entry 216
+    0x1.p0,
+    0x1.p0, -0x1.p-1
+  },
+  { // Entry 217
+    0x1.p0,
+    0x1.p0, 0x1.p-1
+  },
+  { // Entry 218
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep-1,
+    0x1.p1, -0x1.p-1
+  },
+  { // Entry 219
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.p1, 0x1.p-1
+  },
+  { // Entry 220
+    0x1.p0,
+    0x1.p0, -0x1.p-10
+  },
+  { // Entry 221
+    0x1.p0,
+    0x1.p0, 0x1.p-10
+  },
+  { // Entry 222
+    0x1.ffa74ea381efc217a773f15c025f7c0dp-1,
+    0x1.p1, -0x1.p-10
+  },
+  { // Entry 223
+    0x1.002c605e2e8cec506d21bfc89a23a010p0,
+    0x1.p1, 0x1.p-10
+  },
+  { // Entry 224
+    0x1.p40,
+    0x1.p-10, -0x1.p2
+  },
+  { // Entry 225
+    0x1.p-40,
+    0x1.p-10, 0x1.p2
+  },
+  { // Entry 226
+    0x1.fe013f6045e40a7c41499223b4a38ce8p-1,
+    0x1.0040p0, -0x1.p2
+  },
+  { // Entry 227
+    0x1.0100601001p0,
+    0x1.0040p0, 0x1.p2
+  },
+  { // Entry 228
+    0x1.p5,
+    0x1.p-10, -0x1.p-1
+  },
+  { // Entry 229
+    0x1.p-5,
+    0x1.p-10, 0x1.p-1
+  },
+  { // Entry 230
+    0x1.ffc00bfd808be0873653647448220fdfp-1,
+    0x1.0040p0, -0x1.p-1
+  },
+  { // Entry 231
+    0x1.001ffe003ff601bfac107ca6b29a0c31p0,
+    0x1.0040p0, 0x1.p-1
+  },
+  { // Entry 232
+    0x1.01bd1e77170b415e7626621eb5aaff61p0,
+    0x1.p-10, -0x1.p-10
+  },
+  { // Entry 233
+    0x1.fc8bc4866e8ad2b963e1828b0761cbc6p-1,
+    0x1.p-10, 0x1.p-10
+  },
+  { // Entry 234
+    0x1.ffffe0040055355844443df8680a8e05p-1,
+    0x1.0040p0, -0x1.p-10
+  },
+  { // Entry 235
+    0x1.00000ffe00d5256285340e4f3ad36287p0,
+    0x1.0040p0, 0x1.p-10
+  },
+  { // Entry 236
+    0x1.000001000001000001000001000001p-128,
+    0x1.fffffep127, -0x1.p0
+  },
+  { // Entry 237
+    0x1.fffffep127,
+    0x1.fffffep127, 0x1.p0
+  },
+  { // Entry 238
+    HUGE_VALF,
+    0x1.p-149, -0x1.e66666p-1
+  },
+  { // Entry 239
+    0x1.5db4ecab3e1cb942fc90a003e77da282p-142,
+    0x1.p-149, 0x1.e66666p-1
+  },
+  { // Entry 240
+    0.0f,
+    0x1.fffffep-7, 0x1.fffffep5
+  },
+  { // Entry 241
+    0.0f,
+    0x1.fffffep-7, 0x1.p6
+  },
+  { // Entry 242
+    0.0f,
+    0x1.fffffep-7, 0x1.000002p6
+  },
+  { // Entry 243
+    0.0f,
+    0x1.p-6, 0x1.fffffep5
+  },
+  { // Entry 244
+    0.0f,
+    0x1.p-6, 0x1.p6
+  },
+  { // Entry 245
+    0.0f,
+    0x1.p-6, 0x1.000002p6
+  },
+  { // Entry 246
+    0.0f,
+    0x1.000002p-6, 0x1.fffffep5
+  },
+  { // Entry 247
+    0.0f,
+    0x1.000002p-6, 0x1.p6
+  },
+  { // Entry 248
+    0.0f,
+    0x1.000002p-6, 0x1.000002p6
+  },
+  { // Entry 249
+    0.0f,
+    0x1.fffffep-6, 0x1.fffffep4
+  },
+  { // Entry 250
+    0.0f,
+    0x1.fffffep-6, 0x1.p5
+  },
+  { // Entry 251
+    0.0f,
+    0x1.fffffep-6, 0x1.000002p5
+  },
+  { // Entry 252
+    0.0f,
+    0x1.p-5, 0x1.fffffep4
+  },
+  { // Entry 253
+    0.0f,
+    0x1.p-5, 0x1.p5
+  },
+  { // Entry 254
+    0.0f,
+    0x1.p-5, 0x1.000002p5
+  },
+  { // Entry 255
+    0.0f,
+    0x1.000002p-5, 0x1.fffffep4
+  },
+  { // Entry 256
+    0.0f,
+    0x1.000002p-5, 0x1.p5
+  },
+  { // Entry 257
+    0.0f,
+    0x1.000002p-5, 0x1.000002p5
+  },
+  { // Entry 258
+    0x1.00001c5c879823e3af39baa221df84b0p-64,
+    0x1.fffffep-5, 0x1.fffffep3
+  },
+  { // Entry 259
+    0x1.ffffe00000effffba0000e37ffdde0p-65,
+    0x1.fffffep-5, 0x1.p4
+  },
+  { // Entry 260
+    0x1.ffff2e8e128f07f8aa95fb8b35d72ea4p-65,
+    0x1.fffffep-5, 0x1.000002p4
+  },
+  { // Entry 261
+    0x1.00002c5c89d5ec6ca4d7c8acc017b7c9p-64,
+    0x1.p-4, 0x1.fffffep3
+  },
+  { // Entry 262
+    0x1.p-64,
+    0x1.p-4, 0x1.p4
+  },
+  { // Entry 263
+    0x1.ffff4e8e06c7e8a2a84daed8ec56d6c3p-65,
+    0x1.p-4, 0x1.000002p4
+  },
+  { // Entry 264
+    0x1.00004c5c91217e02a4592ba7ad5df32ep-64,
+    0x1.000002p-4, 0x1.fffffep3
+  },
+  { // Entry 265
+    0x1.0000200001e00011800071c002220007p-64,
+    0x1.000002p-4, 0x1.p4
+  },
+  { // Entry 266
+    0x1.ffff8e8df4d9a8351320c05d3d814f9fp-65,
+    0x1.000002p-4, 0x1.000002p4
+  },
+  { // Entry 267
+    0x1.000008a2b26884f1068b81889467d67fp-24,
+    0x1.fffffep-4, 0x1.fffffep2
+  },
+  { // Entry 268
+    0x1.fffff0000037ffff9000008bffff90p-25,
+    0x1.fffffep-4, 0x1.p3
+  },
+  { // Entry 269
+    0x1.ffffad753d825dfcdd65e4ea54ccceb5p-25,
+    0x1.fffffep-4, 0x1.000002p3
+  },
+  { // Entry 270
+    0x1.000010a2b2c99a85707e8f13dc648710p-24,
+    0x1.p-3, 0x1.fffffep2
+  },
+  { // Entry 271
+    0x1.p-24,
+    0x1.p-3, 0x1.p3
+  },
+  { // Entry 272
+    0x1.ffffbd753b5607da2c260064823b30a7p-25,
+    0x1.p-3, 0x1.000002p3
+  },
+  { // Entry 273
+    0x1.000020a2b433c5b91729fe0493321d3fp-24,
+    0x1.000002p-3, 0x1.fffffep2
+  },
+  { // Entry 274
+    0x1.0000100000700001c00004600007p-24,
+    0x1.000002p-3, 0x1.p3
+  },
+  { // Entry 275
+    0x1.ffffdd75384d5b715e9437699534883bp-25,
+    0x1.000002p-3, 0x1.000002p3
+  },
+  { // Entry 276
+    0x1.0000018b90c2f02a80f3bb82aa12e95dp-8,
+    0x1.fffffep-3, 0x1.fffffep1
+  },
+  { // Entry 277
+    0x1.fffff800000bfffff8000002p-9,
+    0x1.fffffep-3, 0x1.p2
+  },
+  { // Entry 278
+    0x1.ffffe1d1bdd0bdc6b46ea64a42b1bad2p-9,
+    0x1.fffffep-3, 0x1.000002p2
+  },
+  { // Entry 279
+    0x1.0000058b90cf1e6d97f9ca14dbcc1628p-8,
+    0x1.p-2, 0x1.fffffep1
+  },
+  { // Entry 280
+    0x1.p-8,
+    0x1.p-2, 0x1.p2
+  },
+  { // Entry 281
+    0x1.ffffe9d1bd7c04bc4825147a8c0e63e3p-9,
+    0x1.p-2, 0x1.000002p2
+  },
+  { // Entry 282
+    0x1.00000d8b910b7af451a642e6d0b66b06p-8,
+    0x1.000002p-2, 0x1.fffffep1
+  },
+  { // Entry 283
+    0x1.000008000018000020000010p-8,
+    0x1.000002p-2, 0x1.p2
+  },
+  { // Entry 284
+    0x1.fffff9d1bd1a92a5d11088ed17417f41p-9,
+    0x1.000002p-2, 0x1.000002p2
+  },
+  { // Entry 285
+    0x1.fffffec5c8623fb25d7d06ac61a3063fp-3,
+    0x1.fffffep-2, 0x1.fffffep0
+  },
+  { // Entry 286
+    0x1.fffffc000002p-3,
+    0x1.fffffep-2, 0x1.p1
+  },
+  { // Entry 287
+    0x1.fffff6746f4d088289b880fe02adbfdep-3,
+    0x1.fffffep-2, 0x1.000002p1
+  },
+  { // Entry 288
+    0x1.00000162e430e5a18f6119e3c02282a5p-2,
+    0x1.p-1, 0x1.fffffep0
+  },
+  { // Entry 289
+    0x1.p-2,
+    0x1.p-1, 0x1.p1
+  },
+  { // Entry 290
+    0x1.fffffa746f47f160fcf890e3b801aeddp-3,
+    0x1.p-1, 0x1.000002p1
+  },
+  { // Entry 291
+    0x1.00000562e436713246f7a0134c8287eap-2,
+    0x1.000002p-1, 0x1.fffffep0
+  },
+  { // Entry 292
+    0x1.000004000004p-2,
+    0x1.000002p-1, 0x1.p1
+  },
+  { // Entry 293
+    0x1.0000013a37a4e18f0519a603954a5b0bp-2,
+    0x1.000002p-1, 0x1.000002p1
+  },
+  { // Entry 294
+    0x1.fffffe000001ffffff000000aaaaaa80p-1,
+    0x1.fffffep-1, 0x1.fffffep-1
+  },
+  { // Entry 295
+    0x1.fffffep-1,
+    0x1.fffffep-1, 0x1.p0
+  },
+  { // Entry 296
+    0x1.fffffdfffffc000002000004aaaaaaffp-1,
+    0x1.fffffep-1, 0x1.000002p0
+  },
+  { // Entry 297
+    0x1.p0,
+    0x1.p0, 0x1.fffffep-1
+  },
+  { // Entry 298
+    0x1.p0,
+    0x1.p0, 0x1.p0
+  },
+  { // Entry 299
+    0x1.p0,
+    0x1.p0, 0x1.000002p0
+  },
+  { // Entry 300
+    0x1.000001fffffdfffffe000003555553ffp0,
+    0x1.000002p0, 0x1.fffffep-1
+  },
+  { // Entry 301
+    0x1.000002p0,
+    0x1.000002p0, 0x1.p0
+  },
+  { // Entry 302
+    0x1.000002000004000004000005555558p0,
+    0x1.000002p0, 0x1.000002p0
+  },
+  { // Entry 303
+    0x1.6a09e53575b123625cc1968a665581a4p0,
+    0x1.fffffep0, 0x1.fffffep-2
+  },
+  { // Entry 304
+    0x1.6a09e5b2eec967cd97b2eff75f471493p0,
+    0x1.fffffep0, 0x1.p-1
+  },
+  { // Entry 305
+    0x1.6a09e6ade0fa7319052c4948dea48a76p0,
+    0x1.fffffep0, 0x1.000002p-1
+  },
+  { // Entry 306
+    0x1.6a09e5ea7aa390dbf868b7278b744829p0,
+    0x1.p1, 0x1.fffffep-2
+  },
+  { // Entry 307
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.p1, 0x1.p-1
+  },
+  { // Entry 308
+    0x1.6a09e762e5efbbd7217018250a3ab194p0,
+    0x1.p1, 0x1.000002p-1
+  },
+  { // Entry 309
+    0x1.6a09e75484875c47c3cee01d9f348bd8p0,
+    0x1.000002p1, 0x1.fffffep-2
+  },
+  { // Entry 310
+    0x1.6a09e7d1fda27bf77d45272dd2d83a4bp0,
+    0x1.000002p1, 0x1.p-1
+  },
+  { // Entry 311
+    0x1.6a09e8ccefd93dcbecf54d233ea8265bp0,
+    0x1.000002p1, 0x1.000002p-1
+  },
+  { // Entry 312
+    0x1.6a09e58ff82a4ecedb73f766d3d0758dp0,
+    0x1.fffffep1, 0x1.fffffep-3
+  },
+  { // Entry 313
+    0x1.6a09e60d71430d1ad61b45d5d1abdf15p0,
+    0x1.fffffep1, 0x1.p-2
+  },
+  { // Entry 314
+    0x1.6a09e70863750c27c3dd5c0ecdce5271p0,
+    0x1.fffffep1, 0x1.000002p-2
+  },
+  { // Entry 315
+    0x1.6a09e5ea7aa390dbf868b7278b744829p0,
+    0x1.p2, 0x1.fffffep-3
+  },
+  { // Entry 316
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.p2, 0x1.p-2
+  },
+  { // Entry 317
+    0x1.6a09e762e5efbbd7217018250a3ab194p0,
+    0x1.p2, 0x1.000002p-2
+  },
+  { // Entry 318
+    0x1.6a09e69f7f954950a1fce0a1b2c362d0p0,
+    0x1.000002p2, 0x1.fffffep-3
+  },
+  { // Entry 319
+    0x1.6a09e71cf8af753edb9700ad906c9cd9p0,
+    0x1.000002p2, 0x1.p-2
+  },
+  { // Entry 320
+    0x1.6a09e817eae44f9049d532cda2a90cb6p0,
+    0x1.000002p2, 0x1.000002p-2
+  },
+  { // Entry 321
+    0x1.4bfdacd3978adf9f3b64fe01f40593aep0,
+    0x1.fffffep2, 0x1.fffffep-4
+  },
+  { // Entry 322
+    0x1.4bfdad29e2ecb54005a6dbec67c5e413p0,
+    0x1.fffffep2, 0x1.p-3
+  },
+  { // Entry 323
+    0x1.4bfdadd679b0a3cc40ecb60afdc4a552p0,
+    0x1.fffffep2, 0x1.000002p-3
+  },
+  { // Entry 324
+    0x1.4bfdacfd174067ea4d43f8b09f974d86p0,
+    0x1.p3, 0x1.fffffep-4
+  },
+  { // Entry 325
+    0x1.4bfdad5362a271d4397afec42e20e036p0,
+    0x1.p3, 0x1.p-3
+  },
+  { // Entry 326
+    0x1.4bfdadfff966c8f2b8f44b137fbfaa96p0,
+    0x1.p3, 0x1.000002p-3
+  },
+  { // Entry 327
+    0x1.4bfdad5016ab0b9134e0574abca78b7ap0,
+    0x1.000002p3, 0x1.fffffep-4
+  },
+  { // Entry 328
+    0x1.4bfdada6620d7e0d6487fd9be64887a3p0,
+    0x1.000002p3, 0x1.p-3
+  },
+  { // Entry 329
+    0x1.4bfdae52f8d2a6506b74ce232fdcd291p0,
+    0x1.000002p3, 0x1.000002p-3
+  },
+  { // Entry 330
+    0x1.306fe05b533131c27612cfff7a0ffdb0p0,
+    0x1.fffffep3, 0x1.fffffep-5
+  },
+  { // Entry 331
+    0x1.306fe09014733fc18f2a8e5bc8a30cdcp0,
+    0x1.fffffep3, 0x1.p-4
+  },
+  { // Entry 332
+    0x1.306fe0f996f7772c9a94c16083446262p0,
+    0x1.fffffep3, 0x1.000002p-4
+  },
+  { // Entry 333
+    0x1.306fe06e5a2f2e8c620f7e55cc803dbap0,
+    0x1.p4, 0x1.fffffep-5
+  },
+  { // Entry 334
+    0x1.306fe0a31b7152de8d5a46305c85edecp0,
+    0x1.p4, 0x1.p-4
+  },
+  { // Entry 335
+    0x1.306fe10c9df5b6efbd400b7806005fa9p0,
+    0x1.p4, 0x1.000002p-4
+  },
+  { // Entry 336
+    0x1.306fe094682af29c8fe9f735fb1c4081p0,
+    0x1.000002p4, 0x1.fffffep-5
+  },
+  { // Entry 337
+    0x1.306fe0c9296d4394df5f99b9bd1a47d2p0,
+    0x1.000002p4, 0x1.p-4
+  },
+  { // Entry 338
+    0x1.306fe132abf200f257c612e07f149aa3p0,
+    0x1.000002p4, 0x1.000002p-4
+  },
+  { // Entry 339
+    0x1.1d4872eebb9da03bbac5af79b0cf9409p0,
+    0x1.fffffep4, 0x1.fffffep-6
+  },
+  { // Entry 340
+    0x1.1d48730da1570a7a85ea1fc1fcf88fddp0,
+    0x1.fffffep4, 0x1.p-5
+  },
+  { // Entry 341
+    0x1.1d48734b6cc9e902148fafcefa9eaa06p0,
+    0x1.fffffep4, 0x1.000002p-5
+  },
+  { // Entry 342
+    0x1.1d4872f7a5e133601ef3b495f3f89a12p0,
+    0x1.p5, 0x1.fffffep-6
+  },
+  { // Entry 343
+    0x1.1d4873168b9aa7805b8028990f07a98bp0,
+    0x1.p5, 0x1.p-5
+  },
+  { // Entry 344
+    0x1.1d487354570d99caccfbdb7e35ff0df1p0,
+    0x1.p5, 0x1.000002p-5
+  },
+  { // Entry 345
+    0x1.1d4873097a683fc01308d4a71615b820p0,
+    0x1.000002p5, 0x1.fffffep-6
+  },
+  { // Entry 346
+    0x1.1d4873286021c7a332496ee4ad91ade9p0,
+    0x1.000002p5, 0x1.p-5
+  },
+  { // Entry 347
+    0x1.1d4873662b94e1736939a503d83c5e42p0,
+    0x1.000002p5, 0x1.000002p-5
+  },
+  { // Entry 348
+    0x1.11301ceb20541ff3f655e3bd12271b3ep0,
+    0x1.fffffep5, 0x1.fffffep-7
+  },
+  { // Entry 349
+    0x1.11301cfce0f494304e630799fc8b181fp0,
+    0x1.fffffep5, 0x1.p-6
+  },
+  { // Entry 350
+    0x1.11301d206235801ef5580894354f900cp0,
+    0x1.fffffep5, 0x1.000002p-6
+  },
+  { // Entry 351
+    0x1.11301cef65149186a0ecb60713565b45p0,
+    0x1.p6, 0x1.fffffep-7
+  },
+  { // Entry 352
+    0x1.11301d0125b50a4ebbf1aed9318ceac5p0,
+    0x1.p6, 0x1.p-6
+  },
+  { // Entry 353
+    0x1.11301d24a6f5ff54e8d811a4b978b54fp0,
+    0x1.p6, 0x1.000002p-6
+  },
+  { // Entry 354
+    0x1.11301cf7ee956810edd94d1c7697f34bp0,
+    0x1.000002p6, 0x1.fffffep-7
+  },
+  { // Entry 355
+    0x1.11301d09af35e9f08ec0b6564cfd4d3ap0,
+    0x1.000002p6, 0x1.p-6
+  },
+  { // Entry 356
+    0x1.11301d2d3076f125c76f69bf107f4052p0,
+    0x1.000002p6, 0x1.000002p-6
+  },
+  { // Entry 357
+    0x1.fffc9d1eaff1e2bc708fbb9fc141d186p127,
+    0x1.fffffcp0, 0x1.fffffcp6
+  },
+  { // Entry 358
+    0x1.fffd4e8fb83933cbf5f827e2581f20dcp127,
+    0x1.fffffcp0, 0x1.fffffep6
+  },
+  { // Entry 359
+    0x1.fffe0000fdffaca81458f80ec301a2c8p127,
+    0x1.fffffcp0, 0x1.p7
+  },
+  { // Entry 360
+    0x1.ffff62e4420a6b06d702f4e2aaffa4e5p127,
+    0x1.fffffcp0, 0x1.000002p7
+  },
+  { // Entry 361
+    HUGE_VALF,
+    0x1.fffffcp0, 0x1.000004p7
+  },
+  { // Entry 362
+    0x1.fffd9d1d3e00d99bdfe3619f05f2ecc1p127,
+    0x1.fffffep0, 0x1.fffffcp6
+  },
+  { // Entry 363
+    0x1.fffe4e8ea000c3f99d84d886c03811fap127,
+    0x1.fffffep0, 0x1.fffffep6
+  },
+  { // Entry 364
+    0x1.ffff00003f7ff59501458fa07615868bp127,
+    0x1.fffffep0, 0x1.p7
+  },
+  { // Entry 365
+    HUGE_VALF,
+    0x1.fffffep0, 0x1.000002p7
+  },
+  { // Entry 366
+    HUGE_VALF,
+    0x1.fffffep0, 0x1.000004p7
+  },
+  { // Entry 367
+    0x1.fffe9d1c4b0f37f413d44c66c0481834p127,
+    0x1.p1, 0x1.fffffcp6
+  },
+  { // Entry 368
+    0x1.ffff4e8e06c7e8a2a84daed8ec56d6c3p127,
+    0x1.p1, 0x1.fffffep6
+  },
+  { // Entry 369
+    HUGE_VALF,
+    0x1.p1, 0x1.p7
+  },
+  { // Entry 370
+    HUGE_VALF,
+    0x1.p1, 0x1.000002p7
+  },
+  { // Entry 371
+    HUGE_VALF,
+    0x1.p1, 0x1.000004p7
+  },
+  { // Entry 372
+    HUGE_VALF,
+    0x1.000002p1, 0x1.fffffcp6
+  },
+  { // Entry 373
+    HUGE_VALF,
+    0x1.000002p1, 0x1.fffffep6
+  },
+  { // Entry 374
+    HUGE_VALF,
+    0x1.000002p1, 0x1.p7
+  },
+  { // Entry 375
+    HUGE_VALF,
+    0x1.000002p1, 0x1.000002p7
+  },
+  { // Entry 376
+    HUGE_VALF,
+    0x1.000002p1, 0x1.000004p7
+  },
+  { // Entry 377
+    HUGE_VALF,
+    0x1.000004p1, 0x1.fffffcp6
+  },
+  { // Entry 378
+    HUGE_VALF,
+    0x1.000004p1, 0x1.fffffep6
+  },
+  { // Entry 379
+    HUGE_VALF,
+    0x1.000004p1, 0x1.p7
+  },
+  { // Entry 380
+    HUGE_VALF,
+    0x1.000004p1, 0x1.000002p7
+  },
+  { // Entry 381
+    HUGE_VALF,
+    0x1.000004p1, 0x1.000004p7
+  },
+  { // Entry 382
+    0.0f,
+    0x1.fffffcp0, -0x1.2c0004p7
+  },
+  { // Entry 383
+    0.0f,
+    0x1.fffffcp0, -0x1.2c0002p7
+  },
+  { // Entry 384
+    0.0f,
+    0x1.fffffcp0, -0x1.2cp7
+  },
+  { // Entry 385
+    0.0f,
+    0x1.fffffcp0, -0x1.2bfffep7
+  },
+  { // Entry 386
+    0.0f,
+    0x1.fffffcp0, -0x1.2bfffcp7
+  },
+  { // Entry 387
+    0.0f,
+    0x1.fffffep0, -0x1.2c0004p7
+  },
+  { // Entry 388
+    0.0f,
+    0x1.fffffep0, -0x1.2c0002p7
+  },
+  { // Entry 389
+    0.0f,
+    0x1.fffffep0, -0x1.2cp7
+  },
+  { // Entry 390
+    0.0f,
+    0x1.fffffep0, -0x1.2bfffep7
+  },
+  { // Entry 391
+    0.0f,
+    0x1.fffffep0, -0x1.2bfffcp7
+  },
+  { // Entry 392
+    0.0f,
+    0x1.p1, -0x1.2c0004p7
+  },
+  { // Entry 393
+    0.0f,
+    0x1.p1, -0x1.2c0002p7
+  },
+  { // Entry 394
+    0.0f,
+    0x1.p1, -0x1.2cp7
+  },
+  { // Entry 395
+    0.0f,
+    0x1.p1, -0x1.2bfffep7
+  },
+  { // Entry 396
+    0.0f,
+    0x1.p1, -0x1.2bfffcp7
+  },
+  { // Entry 397
+    0.0f,
+    0x1.000002p1, -0x1.2c0004p7
+  },
+  { // Entry 398
+    0.0f,
+    0x1.000002p1, -0x1.2c0002p7
+  },
+  { // Entry 399
+    0.0f,
+    0x1.000002p1, -0x1.2cp7
+  },
+  { // Entry 400
+    0.0f,
+    0x1.000002p1, -0x1.2bfffep7
+  },
+  { // Entry 401
+    0.0f,
+    0x1.000002p1, -0x1.2bfffcp7
+  },
+  { // Entry 402
+    0.0f,
+    0x1.000004p1, -0x1.2c0004p7
+  },
+  { // Entry 403
+    0.0f,
+    0x1.000004p1, -0x1.2c0002p7
+  },
+  { // Entry 404
+    0.0f,
+    0x1.000004p1, -0x1.2cp7
+  },
+  { // Entry 405
+    0.0f,
+    0x1.000004p1, -0x1.2bfffep7
+  },
+  { // Entry 406
+    0.0f,
+    0x1.000004p1, -0x1.2bfffcp7
+  },
+  { // Entry 407
+    0.0f,
+    0x1.db6db2p-2, 0x1.c30c2cp8
+  },
+  { // Entry 408
+    0.0f,
+    0x1.db6db2p-2, 0x1.c30c2ep8
+  },
+  { // Entry 409
+    0.0f,
+    0x1.db6db2p-2, 0x1.c30c30p8
+  },
+  { // Entry 410
+    0.0f,
+    0x1.db6db2p-2, 0x1.c30c32p8
+  },
+  { // Entry 411
+    0.0f,
+    0x1.db6db2p-2, 0x1.c30c34p8
+  },
+  { // Entry 412
+    0.0f,
+    0x1.db6db4p-2, 0x1.c30c2cp8
+  },
+  { // Entry 413
+    0.0f,
+    0x1.db6db4p-2, 0x1.c30c2ep8
+  },
+  { // Entry 414
+    0.0f,
+    0x1.db6db4p-2, 0x1.c30c30p8
+  },
+  { // Entry 415
+    0.0f,
+    0x1.db6db4p-2, 0x1.c30c32p8
+  },
+  { // Entry 416
+    0.0f,
+    0x1.db6db4p-2, 0x1.c30c34p8
+  },
+  { // Entry 417
+    0.0f,
+    0x1.db6db6p-2, 0x1.c30c2cp8
+  },
+  { // Entry 418
+    0.0f,
+    0x1.db6db6p-2, 0x1.c30c2ep8
+  },
+  { // Entry 419
+    0.0f,
+    0x1.db6db6p-2, 0x1.c30c30p8
+  },
+  { // Entry 420
+    0.0f,
+    0x1.db6db6p-2, 0x1.c30c32p8
+  },
+  { // Entry 421
+    0.0f,
+    0x1.db6db6p-2, 0x1.c30c34p8
+  },
+  { // Entry 422
+    0.0f,
+    0x1.db6db8p-2, 0x1.c30c2cp8
+  },
+  { // Entry 423
+    0.0f,
+    0x1.db6db8p-2, 0x1.c30c2ep8
+  },
+  { // Entry 424
+    0.0f,
+    0x1.db6db8p-2, 0x1.c30c30p8
+  },
+  { // Entry 425
+    0.0f,
+    0x1.db6db8p-2, 0x1.c30c32p8
+  },
+  { // Entry 426
+    0.0f,
+    0x1.db6db8p-2, 0x1.c30c34p8
+  },
+  { // Entry 427
+    0.0f,
+    0x1.db6dbap-2, 0x1.c30c2cp8
+  },
+  { // Entry 428
+    0.0f,
+    0x1.db6dbap-2, 0x1.c30c2ep8
+  },
+  { // Entry 429
+    0.0f,
+    0x1.db6dbap-2, 0x1.c30c30p8
+  },
+  { // Entry 430
+    0.0f,
+    0x1.db6dbap-2, 0x1.c30c32p8
+  },
+  { // Entry 431
+    0.0f,
+    0x1.db6dbap-2, 0x1.c30c34p8
+  },
+  { // Entry 432
+    -0x1.fffffc000007fffff000001fffffc0p-1,
+    -0x1.000002p0, -0x1.p0
+  },
+  { // Entry 433
+    -0x1.p0,
+    -0x1.p0, -0x1.p0
+  },
+  { // Entry 434
+    -0x1.000001000001000001000001000001p0,
+    -0x1.fffffep-1, -0x1.p0
+  },
+  { // Entry 435
+    HUGE_VALF,
+    0x1.p1, 0x1.p10
+  },
+  { // Entry 436
+    HUGE_VALF,
+    0x1.p2, 0x1.p9
+  },
+  { // Entry 437
+    0.0f,
+    0x1.fffffep-2, 0x1.fffffep9
+  },
+  { // Entry 438
+    0.0f,
+    0x1.fffffep-2, 0x1.p10
+  },
+  { // Entry 439
+    0.0f,
+    0x1.fffffep-2, 0x1.000002p10
+  },
+  { // Entry 440
+    0.0f,
+    0x1.p-1, 0x1.fffffep9
+  },
+  { // Entry 441
+    0.0f,
+    0x1.p-1, 0x1.p10
+  },
+  { // Entry 442
+    0.0f,
+    0x1.p-1, 0x1.000002p10
+  },
+  { // Entry 443
+    0.0f,
+    0x1.000002p-1, 0x1.fffffep9
+  },
+  { // Entry 444
+    0.0f,
+    0x1.000002p-1, 0x1.p10
+  },
+  { // Entry 445
+    0.0f,
+    0x1.000002p-1, 0x1.000002p10
+  },
+  { // Entry 446
+    0x1.00020467109547572fa8f3f653eda548p-149,
+    0x1.p-149, 0x1.fffff6p-1
+  },
+  { // Entry 447
+    0x1.00019d1eed21f448f2c6217eab3d9c55p-149,
+    0x1.p-149, 0x1.fffff8p-1
+  },
+  { // Entry 448
+    0x1.000135d6f3596e086d463376a9dbd1e2p-149,
+    0x1.p-149, 0x1.fffffap-1
+  },
+  { // Entry 449
+    0x1.0000ce8f233ba3c64adc5667a7b0b245p-149,
+    0x1.p-149, 0x1.fffffcp-1
+  },
+  { // Entry 450
+    0x1.000067477cc884b33e03d0bb77571150p-149,
+    0x1.p-149, 0x1.fffffep-1
+  },
+  { // Entry 451
+    0x1.p-149,
+    0x1.p-149, 0x1.p0
+  },
+  { // Entry 452
+    0.0f,
+    0x1.p-149, 0x1.000002p0
+  },
+  { // Entry 453
+    0.0f,
+    0x1.p-149, 0x1.000004p0
+  },
+  { // Entry 454
+    0.0f,
+    0x1.p-149, 0x1.000006p0
+  },
+  { // Entry 455
+    0.0f,
+    0x1.p-149, 0x1.000008p0
+  },
+  { // Entry 456
+    0.0f,
+    0x1.p-149, 0x1.00000ap0
+  },
+  { // Entry 457
+    0x1.000200efcf25bab1c7cd22827341ab63p-148,
+    0x1.p-148, 0x1.fffff6p-1
+  },
+  { // Entry 458
+    0x1.00019a59204c82fe060cf6d320f15433p-148,
+    0x1.p-148, 0x1.fffff8p-1
+  },
+  { // Entry 459
+    0x1.000133c29a8f64f204da13b72ebc56edp-148,
+    0x1.p-148, 0x1.fffffap-1
+  },
+  { // Entry 460
+    0x1.0000cd2c3dee501480729506593fd68bp-148,
+    0x1.p-148, 0x1.fffffcp-1
+  },
+  { // Entry 461
+    0x1.000066960a6933ec3bae8cab9ccfd543p-148,
+    0x1.p-148, 0x1.fffffep-1
+  },
+  { // Entry 462
+    0x1.p-148,
+    0x1.p-148, 0x1.p0
+  },
+  { // Entry 463
+    0x1.fffe65a8cd021dedd55a40c272dc8acap-149,
+    0x1.p-148, 0x1.000002p0
+  },
+  { // Entry 464
+    0x1.fffccb52e2e1f2602021820ab47036fep-149,
+    0x1.p-148, 0x1.000004p0
+  },
+  { // Entry 465
+    0x1.fffb30fe419e75c552c074b75e9e132dp-149,
+    0x1.p-148, 0x1.000006p0
+  },
+  { // Entry 466
+    0x1.fff996aae936a08cb2de3b831326836cp-149,
+    0x1.p-148, 0x1.000008p0
+  },
+  { // Entry 467
+    0x1.fff7fc58d9a96b26595dc1b91aab1065p-149,
+    0x1.p-148, 0x1.00000ap0
+  },
+  { // Entry 468
+    0x1.8002fe5d326e1910dcf5adadc4fb80bap-148,
+    0x1.80p-148, 0x1.fffff6p-1
+  },
+  { // Entry 469
+    0x1.80026516e130410cbc34d6be1f314af3p-148,
+    0x1.80p-148, 0x1.fffff8p-1
+  },
+  { // Entry 470
+    0x1.8001cbd0cd20048dc0041aae6853f414p-148,
+    0x1.80p-148, 0x1.fffffap-1
+  },
+  { // Entry 471
+    0x1.8001328af63d4b28b93bac168d323776p-148,
+    0x1.80p-148, 0x1.fffffcp-1
+  },
+  { // Entry 472
+    0x1.800099455c87fc728272d7993c3c0ed2p-148,
+    0x1.80p-148, 0x1.fffffep-1
+  },
+  { // Entry 473
+    0x1.80p-148,
+    0x1.80p-148, 0x1.p0
+  },
+  { // Entry 474
+    0x1.7ffecd75fe779c39da312a0ae6575aaep-148,
+    0x1.80p-148, 0x1.000002p0
+  },
+  { // Entry 475
+    0x1.7ffd9aecf1a35c7e2d6f67b9177b8bc8p-148,
+    0x1.80p-148, 0x1.000004p0
+  },
+  { // Entry 476
+    0x1.7ffc6864d9827d757b4b6001d0c80a9bp-148,
+    0x1.80p-148, 0x1.000006p0
+  },
+  { // Entry 477
+    0x1.7ffb35ddb6143bc8e145a6d616a1b551p-148,
+    0x1.80p-148, 0x1.000008p0
+  },
+  { // Entry 478
+    0x1.7ffa03578757d42218ce40a578c74476p-148,
+    0x1.80p-148, 0x1.00000ap0
+  },
+  { // Entry 479
+    0x1.000000a0cf65eb1817a7095d9a0443a7p0,
+    0x1.p-29, -0x1.p-29
+  },
+  { // Entry 480
+    0x1.ffffff5f309a60aad5c2309f81f90defp-1,
+    0x1.p-29, 0x1.p-30
+  },
+  { // Entry 481
+    0x1.fffffd9e07cf07767a55afbe9acae93ep-1,
+    0x1.p55, -0x1.p-29
+  },
+  { // Entry 482
+    0x1.000000987e0cc66344d89b494e1f43b3p0,
+    0x1.p55, 0x1.p-30
+  },
+  { // Entry 483
+    0x1.fffffd669427cf159515873887c17cf2p-1,
+    0x1.p60, -0x1.p-29
+  },
+  { // Entry 484
+    0x1.000000a65af6ae61be88ea2558790cd7p0,
+    0x1.p60, 0x1.p-30
+  },
+  { // Entry 485
+    0x1.ffc003ffb55aaa4cd34f3431ea5b77f1p-1,
+    0x1.fffffep-1, 0x1.p13
+  },
+  { // Entry 486
+    0x1.fe00ffa9c0fb3bf28c8a9b2b3d2d7daap-1,
+    0x1.fffffep-1, 0x1.p16
+  },
+  { // Entry 487
+    0x1.p0,
+    0x1.p0, 0x1.p13
+  },
+  { // Entry 488
+    0x1.p0,
+    0x1.p0, 0x1.p16
+  },
+  { // Entry 489
+    0x1.004008006aa554332b8fed09d8ed29f3p0,
+    0x1.000002p0, 0x1.p13
+  },
+  { // Entry 490
+    0x1.02020153fc405b123b33a73cb93a3648p0,
+    0x1.000002p0, 0x1.p16
+  },
+  { // Entry 491
+    0x1.2c15603269407006b8f35e8e4f1497bap-6,
+    -0x1.000002p0, -0x1.p25
+  },
+  { // Entry 492
+    0x1.c846887ee379c5af637c7349afc9f699p-47,
+    -0x1.000002p0, -0x1.p28
+  },
+  { // Entry 493
+    0x1.p0,
+    -0x1.p0, -0x1.p25
+  },
+  { // Entry 494
+    0x1.p0,
+    -0x1.p0, -0x1.p28
+  },
+  { // Entry 495
+    0x1.d8e64d66342891c86fb3c87d1ed6d5c5p2,
+    -0x1.fffffep-1, -0x1.p25
+  },
+  { // Entry 496
+    0x1.0f2ec583f611e4b8fc1cc7b50efbb738p23,
+    -0x1.fffffep-1, -0x1.p28
+  },
+  { // Entry 497
+    0x1.d8e64d66342891c86fb3c87d1ed6d5c5p2,
+    0x1.fffffep-1, -0x1.p25
+  },
+  { // Entry 498
+    0x1.0f2ec583f611e4b8fc1cc7b50efbb738p23,
+    0x1.fffffep-1, -0x1.p28
+  },
+  { // Entry 499
+    0x1.p0,
+    0x1.p0, -0x1.p25
+  },
+  { // Entry 500
+    0x1.p0,
+    0x1.p0, -0x1.p28
+  },
+  { // Entry 501
+    0x1.2c15603269407006b8f35e8e4f1497bap-6,
+    0x1.000002p0, -0x1.p25
+  },
+  { // Entry 502
+    0x1.c846887ee379c5af637c7349afc9f699p-47,
+    0x1.000002p0, -0x1.p28
+  },
+  { // Entry 503
+    HUGE_VALF,
+    -0x1.p15, 0x1.p63
+  },
+  { // Entry 504
+    HUGE_VALF,
+    0.0f, -0x1.80p1
+  },
+  { // Entry 505
+    -HUGE_VALF,
+    -0.0f, -0x1.80p1
+  },
+  { // Entry 506
+    HUGE_VALF,
+    0.0f, -0x1.p0
+  },
+  { // Entry 507
+    -HUGE_VALF,
+    -0.0f, -0x1.p0
+  },
+  { // Entry 508
+    HUGE_VALF,
+    0.0f, -0x1.fffffep127
+  },
+  { // Entry 509
+    HUGE_VALF,
+    0.0f, -0x1.80p2
+  },
+  { // Entry 510
+    HUGE_VALF,
+    0.0f, -0x1.p1
+  },
+  { // Entry 511
+    HUGE_VALF,
+    0.0f, -0x1.000002p0
+  },
+  { // Entry 512
+    HUGE_VALF,
+    0.0f, -0x1.fffffep-1
+  },
+  { // Entry 513
+    HUGE_VALF,
+    0.0f, -0x1.p-126
+  },
+  { // Entry 514
+    HUGE_VALF,
+    0.0f, -0x1.p-149
+  },
+  { // Entry 515
+    HUGE_VALF,
+    -0.0f, -0x1.fffffep127
+  },
+  { // Entry 516
+    HUGE_VALF,
+    -0.0f, -0x1.80p2
+  },
+  { // Entry 517
+    HUGE_VALF,
+    -0.0f, -0x1.p1
+  },
+  { // Entry 518
+    HUGE_VALF,
+    -0.0f, -0x1.000002p0
+  },
+  { // Entry 519
+    HUGE_VALF,
+    -0.0f, -0x1.fffffep-1
+  },
+  { // Entry 520
+    HUGE_VALF,
+    -0.0f, -0x1.p-126
+  },
+  { // Entry 521
+    HUGE_VALF,
+    -0.0f, -0x1.p-149
+  },
+  { // Entry 522
+    HUGE_VALF,
+    0.0f, -HUGE_VALF
+  },
+  { // Entry 523
+    HUGE_VALF,
+    -0.0f, -HUGE_VALF
+  },
+  { // Entry 524
+    0.0,
+    0.0f, 0x1.80p1
+  },
+  { // Entry 525
+    -0.0,
+    -0.0f, 0x1.80p1
+  },
+  { // Entry 526
+    0.0,
+    0.0f, 0x1.p0
+  },
+  { // Entry 527
+    -0.0,
+    -0.0f, 0x1.p0
+  },
+  { // Entry 528
+    0.0,
+    0.0f, HUGE_VALF
+  },
+  { // Entry 529
+    0.0,
+    0.0f, 0x1.fffffep127
+  },
+  { // Entry 530
+    0.0,
+    0.0f, 0x1.80p2
+  },
+  { // Entry 531
+    0.0,
+    0.0f, 0x1.p1
+  },
+  { // Entry 532
+    0.0,
+    0.0f, 0x1.000002p0
+  },
+  { // Entry 533
+    0.0,
+    0.0f, 0x1.fffffep-1
+  },
+  { // Entry 534
+    0.0,
+    0.0f, 0x1.p-126
+  },
+  { // Entry 535
+    0.0,
+    0.0f, 0x1.p-149
+  },
+  { // Entry 536
+    0.0,
+    -0.0f, HUGE_VALF
+  },
+  { // Entry 537
+    0.0,
+    -0.0f, 0x1.fffffep127
+  },
+  { // Entry 538
+    0.0,
+    -0.0f, 0x1.80p2
+  },
+  { // Entry 539
+    0.0,
+    -0.0f, 0x1.p1
+  },
+  { // Entry 540
+    0.0,
+    -0.0f, 0x1.000002p0
+  },
+  { // Entry 541
+    0.0,
+    -0.0f, 0x1.fffffep-1
+  },
+  { // Entry 542
+    0.0,
+    -0.0f, 0x1.p-126
+  },
+  { // Entry 543
+    0.0,
+    -0.0f, 0x1.p-149
+  },
+  { // Entry 544
+    0x1.p0,
+    -0x1.p0, HUGE_VALF
+  },
+  { // Entry 545
+    0x1.p0,
+    -0x1.p0, -HUGE_VALF
+  },
+  { // Entry 546
+    0x1.p0,
+    0x1.p0, HUGE_VALF
+  },
+  { // Entry 547
+    0x1.p0,
+    0x1.p0, -HUGE_VALF
+  },
+  { // Entry 548
+    0x1.p0,
+    0x1.p0, 0x1.fffffep127
+  },
+  { // Entry 549
+    0x1.p0,
+    0x1.p0, -0x1.fffffep127
+  },
+  { // Entry 550
+    0x1.p0,
+    -0x1.p0, 0x1.fffffep127
+  },
+  { // Entry 551
+    0x1.p0,
+    -0x1.p0, -0x1.fffffep127
+  },
+  { // Entry 552
+    0x1.p0,
+    0x1.p0, 0x1.p-1
+  },
+  { // Entry 553
+    0x1.p0,
+    0x1.p0, -0x1.p-1
+  },
+  { // Entry 554
+    0x1.p0,
+    0x1.p0, 0x1.p-126
+  },
+  { // Entry 555
+    0x1.p0,
+    0x1.p0, -0x1.p-126
+  },
+  { // Entry 556
+    0x1.p0,
+    0x1.p0, 0x1.fffffcp-127
+  },
+  { // Entry 557
+    0x1.p0,
+    0x1.p0, -0x1.fffffcp-127
+  },
+  { // Entry 558
+    0x1.p0,
+    0x1.p0, 0x1.p-149
+  },
+  { // Entry 559
+    0x1.p0,
+    0x1.p0, -0x1.p-149
+  },
+  { // Entry 560
+    0x1.p0,
+    0x1.p0, 0.0f
+  },
+  { // Entry 561
+    0x1.p0,
+    0x1.p0, -0.0f
+  },
+  { // Entry 562
+    0x1.p0,
+    HUGE_VALF, 0.0f
+  },
+  { // Entry 563
+    0x1.p0,
+    HUGE_VALF, -0.0f
+  },
+  { // Entry 564
+    0x1.p0,
+    0x1.fffffep127, 0.0f
+  },
+  { // Entry 565
+    0x1.p0,
+    0x1.fffffep127, -0.0f
+  },
+  { // Entry 566
+    0x1.p0,
+    0x1.p-126, 0.0f
+  },
+  { // Entry 567
+    0x1.p0,
+    0x1.p-126, -0.0f
+  },
+  { // Entry 568
+    0x1.p0,
+    0x1.p-149, 0.0f
+  },
+  { // Entry 569
+    0x1.p0,
+    0x1.p-149, -0.0f
+  },
+  { // Entry 570
+    0x1.p0,
+    0.0f, 0.0f
+  },
+  { // Entry 571
+    0x1.p0,
+    0.0f, -0.0f
+  },
+  { // Entry 572
+    0x1.p0,
+    -0.0f, 0.0f
+  },
+  { // Entry 573
+    0x1.p0,
+    -0.0f, -0.0f
+  },
+  { // Entry 574
+    0x1.p0,
+    -0x1.p-149, 0.0f
+  },
+  { // Entry 575
+    0x1.p0,
+    -0x1.p-149, -0.0f
+  },
+  { // Entry 576
+    0x1.p0,
+    -0x1.p-126, 0.0f
+  },
+  { // Entry 577
+    0x1.p0,
+    -0x1.p-126, -0.0f
+  },
+  { // Entry 578
+    0x1.p0,
+    -0x1.fffffep127, 0.0f
+  },
+  { // Entry 579
+    0x1.p0,
+    -0x1.fffffep127, -0.0f
+  },
+  { // Entry 580
+    0x1.p0,
+    -HUGE_VALF, 0.0f
+  },
+  { // Entry 581
+    0x1.p0,
+    -HUGE_VALF, -0.0f
+  },
+  { // Entry 582
+    HUGE_VALF,
+    0x1.p-126, -HUGE_VALF
+  },
+  { // Entry 583
+    HUGE_VALF,
+    0x1.p-149, -HUGE_VALF
+  },
+  { // Entry 584
+    HUGE_VALF,
+    -0x1.p-149, -HUGE_VALF
+  },
+  { // Entry 585
+    HUGE_VALF,
+    -0x1.p-126, -HUGE_VALF
+  },
+  { // Entry 586
+    0.0,
+    HUGE_VALF, -HUGE_VALF
+  },
+  { // Entry 587
+    0.0,
+    0x1.fffffep127, -HUGE_VALF
+  },
+  { // Entry 588
+    0.0,
+    0x1.80p0, -HUGE_VALF
+  },
+  { // Entry 589
+    0.0,
+    -0x1.80p0, -HUGE_VALF
+  },
+  { // Entry 590
+    0.0,
+    -0x1.fffffep127, -HUGE_VALF
+  },
+  { // Entry 591
+    0.0,
+    -HUGE_VALF, -HUGE_VALF
+  },
+  { // Entry 592
+    0.0,
+    0x1.p-126, HUGE_VALF
+  },
+  { // Entry 593
+    0.0,
+    0x1.p-149, HUGE_VALF
+  },
+  { // Entry 594
+    0.0,
+    0.0f, HUGE_VALF
+  },
+  { // Entry 595
+    0.0,
+    -0.0f, HUGE_VALF
+  },
+  { // Entry 596
+    0.0,
+    -0x1.p-149, HUGE_VALF
+  },
+  { // Entry 597
+    0.0,
+    -0x1.p-126, HUGE_VALF
+  },
+  { // Entry 598
+    HUGE_VALF,
+    HUGE_VALF, HUGE_VALF
+  },
+  { // Entry 599
+    HUGE_VALF,
+    0x1.fffffep127, HUGE_VALF
+  },
+  { // Entry 600
+    HUGE_VALF,
+    0x1.80p0, HUGE_VALF
+  },
+  { // Entry 601
+    HUGE_VALF,
+    -0x1.80p0, HUGE_VALF
+  },
+  { // Entry 602
+    HUGE_VALF,
+    -0x1.fffffep127, HUGE_VALF
+  },
+  { // Entry 603
+    HUGE_VALF,
+    -HUGE_VALF, HUGE_VALF
+  },
+  { // Entry 604
+    -0.0,
+    -HUGE_VALF, -0x1.80p1
+  },
+  { // Entry 605
+    -0.0,
+    -HUGE_VALF, -0x1.p0
+  },
+  { // Entry 606
+    0.0,
+    -HUGE_VALF, -HUGE_VALF
+  },
+  { // Entry 607
+    0.0,
+    -HUGE_VALF, -0x1.921fb6p1
+  },
+  { // Entry 608
+    0.0,
+    -HUGE_VALF, -0x1.921fb6p0
+  },
+  { // Entry 609
+    0.0,
+    -HUGE_VALF, -0x1.fffffep127
+  },
+  { // Entry 610
+    0.0,
+    -HUGE_VALF, -0x1.80p2
+  },
+  { // Entry 611
+    0.0,
+    -HUGE_VALF, -0x1.p1
+  },
+  { // Entry 612
+    0.0,
+    -HUGE_VALF, -0x1.p-126
+  },
+  { // Entry 613
+    0.0,
+    -HUGE_VALF, -0x1.p-149
+  },
+  { // Entry 614
+    -HUGE_VALF,
+    -HUGE_VALF, 0x1.80p1
+  },
+  { // Entry 615
+    -HUGE_VALF,
+    -HUGE_VALF, 0x1.40p2
+  },
+  { // Entry 616
+    HUGE_VALF,
+    -HUGE_VALF, HUGE_VALF
+  },
+  { // Entry 617
+    HUGE_VALF,
+    -HUGE_VALF, 0x1.921fb6p1
+  },
+  { // Entry 618
+    HUGE_VALF,
+    -HUGE_VALF, 0x1.921fb6p0
+  },
+  { // Entry 619
+    HUGE_VALF,
+    -HUGE_VALF, 0x1.fffffep127
+  },
+  { // Entry 620
+    HUGE_VALF,
+    -HUGE_VALF, 0x1.80p2
+  },
+  { // Entry 621
+    HUGE_VALF,
+    -HUGE_VALF, 0x1.p1
+  },
+  { // Entry 622
+    HUGE_VALF,
+    -HUGE_VALF, 0x1.p-126
+  },
+  { // Entry 623
+    HUGE_VALF,
+    -HUGE_VALF, 0x1.p-149
+  },
+  { // Entry 624
+    0.0,
+    HUGE_VALF, -0x1.p-149
+  },
+  { // Entry 625
+    0.0,
+    HUGE_VALF, -0x1.p-126
+  },
+  { // Entry 626
+    0.0,
+    HUGE_VALF, -0x1.fffffep127
+  },
+  { // Entry 627
+    0.0,
+    HUGE_VALF, -HUGE_VALF
+  },
+  { // Entry 628
+    HUGE_VALF,
+    HUGE_VALF, HUGE_VALF
+  },
+  { // Entry 629
+    HUGE_VALF,
+    HUGE_VALF, 0x1.fffffep127
+  },
+  { // Entry 630
+    HUGE_VALF,
+    HUGE_VALF, 0x1.p-126
+  },
+  { // Entry 631
+    HUGE_VALF,
+    HUGE_VALF, 0x1.p-149
+  },
+  { // Entry 632
+    HUGE_VALF,
+    0x1.fffffep127, 0x1.fffffep127
+  },
+  { // Entry 633
+    0.0f,
+    0x1.p-126, 0x1.p1
+  },
+  { // Entry 634
+    0.0f,
+    -0x1.p-126, 0x1.p1
+  },
+  { // Entry 635
+    0.0f,
+    0x1.p-149, 0x1.p1
+  },
+  { // Entry 636
+    0.0f,
+    -0x1.p-149, 0x1.p1
+  },
+  { // Entry 637
+    HUGE_VALF,
+    HUGE_VALF, 0x1.p-1
+  },
+  { // Entry 638
+    0x1.fffffeffffffbfffffdfffffebfffff1p63,
+    0x1.fffffep127, 0x1.p-1
+  },
+  { // Entry 639
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep-1,
+    0x1.p-1, 0x1.p-1
+  },
+  { // Entry 640
+    0x1.p-63,
+    0x1.p-126, 0x1.p-1
+  },
+  { // Entry 641
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep-75,
+    0x1.p-149, 0x1.p-1
+  },
+  { // Entry 642
+    0.0,
+    0.0f, 0x1.p-1
+  },
+  { // Entry 643
+    0.0,
+    -0.0f, 0x1.p-1
+  },
+  { // Entry 644
+    HUGE_VALF,
+    -HUGE_VALF, 0x1.p-1
+  },
+  { // Entry 645
+    0.0,
+    HUGE_VALF, -0x1.p-1
+  },
+  { // Entry 646
+    0x1.0000008000006000005000004600003fp-64,
+    0x1.fffffep127, -0x1.p-1
+  },
+  { // Entry 647
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.p-1, -0x1.p-1
+  },
+  { // Entry 648
+    0x1.p63,
+    0x1.p-126, -0x1.p-1
+  },
+  { // Entry 649
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep74,
+    0x1.p-149, -0x1.p-1
+  },
+  { // Entry 650
+    HUGE_VALF,
+    0.0f, -0x1.p-1
+  },
+  { // Entry 651
+    HUGE_VALF,
+    -0.0f, -0x1.p-1
+  },
+  { // Entry 652
+    0.0,
+    -HUGE_VALF, -0x1.p-1
+  },
+  { // Entry 653
+    0.0,
+    0x1.p-1, HUGE_VALF
+  },
+  { // Entry 654
+    0.0f,
+    0x1.p-1, 0x1.fffffep127
+  },
+  { // Entry 655
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep-1,
+    0x1.p-1, 0x1.p-1
+  },
+  { // Entry 656
+    0x1.fffffffffffffffffffffffffffffffap-1,
+    0x1.p-1, 0x1.p-126
+  },
+  { // Entry 657
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-1, 0x1.p-149
+  },
+  { // Entry 658
+    0x1.p0,
+    0x1.p-1, 0.0f
+  },
+  { // Entry 659
+    0x1.p0,
+    0x1.p-1, -0.0f
+  },
+  { // Entry 660
+    0x1.p0,
+    0x1.p-1, -0x1.p-149
+  },
+  { // Entry 661
+    0x1.00000000000000000000000000000002p0,
+    0x1.p-1, -0x1.p-126
+  },
+  { // Entry 662
+    0x1.6a09e667f3bcc908b2fb1366ea957d3ep0,
+    0x1.p-1, -0x1.p-1
+  },
+  { // Entry 663
+    HUGE_VALF,
+    0x1.p-1, -0x1.fffffep127
+  },
+  { // Entry 664
+    HUGE_VALF,
+    0x1.p-1, -HUGE_VALF
+  },
+  { // Entry 665
+    0.0,
+    -0x1.p-1, HUGE_VALF
+  },
+  { // Entry 666
+    0.0f,
+    -0x1.p-1, 0x1.fffffep127
+  },
+  { // Entry 667
+    0x1.p0,
+    -0x1.p-1, 0.0f
+  },
+  { // Entry 668
+    0x1.p0,
+    -0x1.p-1, -0.0f
+  },
+  { // Entry 669
+    HUGE_VALF,
+    -0x1.p-1, -0x1.fffffep127
+  },
+  { // Entry 670
+    HUGE_VALF,
+    -0x1.p-1, -HUGE_VALF
+  },
+  { // Entry 671
+    0x1.p1,
+    0x1.p2, 0x1.p-1
+  },
+  { // Entry 672
+    0x1.80p1,
+    0x1.20p3, 0x1.p-1
+  },
+  { // Entry 673
+    0x1.p2,
+    0x1.p4, 0x1.p-1
+  },
+  { // Entry 674
+    0x1.p-1,
+    0x1.p2, -0x1.p-1
+  },
+  { // Entry 675
+    0x1.p-2,
+    0x1.p4, -0x1.p-1
+  },
+  { // Entry 676
+    0x1.p-3,
+    0x1.p6, -0x1.p-1
+  },
+  { // Entry 677
+    HUGE_VALF,
+    0x1.fffffep-1, -0x1.74910cp62
+  },
+  { // Entry 678
+    0.0f,
+    0x1.fffffep-1, 0x1.74910cp62
+  },
+  { // Entry 679
+    0x1.p2,
+    0x1.p1, 0x1.p1
+  },
+  { // Entry 680
+    0x1.p-2,
+    0x1.p1, -0x1.p1
+  },
+  { // Entry 681
+    0x1.p2,
+    -0x1.p1, 0x1.p1
+  },
+  { // Entry 682
+    0x1.p-2,
+    -0x1.p1, -0x1.p1
+  },
+  { // Entry 683
+    0x1.b0p4,
+    0x1.80p1, 0x1.80p1
+  },
+  { // Entry 684
+    0x1.86a0p11,
+    0x1.40p2, 0x1.40p2
+  },
+  { // Entry 685
+    0x1.921ee0p19,
+    0x1.c0p2, 0x1.c0p2
+  },
+  { // Entry 686
+    0x1.2a05f2p33,
+    0x1.40p3, 0x1.40p3
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_powf, powf_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_powf_intel_data)/sizeof(powf_intel_data_t); i++) {
+    EXPECT_FLOAT_EQ(g_powf_intel_data[i].expected, powf(g_powf_intel_data[i].x_call_data, g_powf_intel_data[i].y_call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_sin_test.cpp b/tests/math_sin_test.cpp
new file mode 100644
index 0000000..ffa4340
--- /dev/null
+++ b/tests/math_sin_test.cpp
@@ -0,0 +1,5795 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  double expected;
+  double call_data;
+} sin_intel_data_t;
+
+static sin_intel_data_t g_sin_intel_data[] = {
+  { // Entry 0
+    0x1.9259e3708bd39ffffffffffffff1bdbep-5,
+    0x1.9283586503fe0p-5
+  },
+  { // Entry 1
+    -0x1.9259e3708bd39ffffffffffffff1bdbep-5,
+    -0x1.9283586503fe0p-5
+  },
+  { // Entry 2
+    0x1.d77b117f230d5ffffffffffffff2adc7p-5,
+    0x1.d7bdcd778049fp-5
+  },
+  { // Entry 3
+    -0x1.d77b117f230d5ffffffffffffff2adc7p-5,
+    -0x1.d7bdcd778049fp-5
+  },
+  { // Entry 4
+    0x1.a1490c8c06ba6fffffffffffffa98611p-4,
+    0x1.a202b3fb84788p-4
+  },
+  { // Entry 5
+    -0x1.a1490c8c06ba6fffffffffffffa98611p-4,
+    -0x1.a202b3fb84788p-4
+  },
+  { // Entry 6
+    0x1.cc40c3805229a7ffffffffffff83e76bp-3,
+    0x1.d037cb27ee6dfp-3
+  },
+  { // Entry 7
+    -0x1.cc40c3805229a7ffffffffffff83e76bp-3,
+    -0x1.d037cb27ee6dfp-3
+  },
+  { // Entry 8
+    0x1.d0ef799001ba900000000000005ea4e9p-3,
+    0x1.d5064e6fe82c5p-3
+  },
+  { // Entry 9
+    -0x1.d0ef799001ba900000000000005ea4e9p-3,
+    -0x1.d5064e6fe82c5p-3
+  },
+  { // Entry 10
+    0x1.e9950730c4695ffffffffffffffffc2ep-2,
+    0x1.fe767739d0f6dp-2
+  },
+  { // Entry 11
+    -0x1.e9950730c4695ffffffffffffffffc2ep-2,
+    -0x1.fe767739d0f6dp-2
+  },
+  { // Entry 12
+    0x1.98dcd093377928000000000000167dc7p-1,
+    0x1.d98c4c612718dp-1
+  },
+  { // Entry 13
+    -0x1.98dcd093377928000000000000167dc7p-1,
+    -0x1.d98c4c612718dp-1
+  },
+  { // Entry 14
+    0x1.ffffffffffffffffffffffffffec8831p-1,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 15
+    -0x1.ffffffffffffffffffffffffffec8831p-1,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 16
+    0x1.70a9d825b506400422155aecd519d54cp-1,
+    -0x1.0000001f8p500
+  },
+  { // Entry 17
+    -0x1.70a9d825b506400422155aecd519d54cp-1,
+    0x1.0000001f8p500
+  },
+  { // Entry 18
+    0x1.bf3980c6c1e9f4496795f4ce535016b6p-1,
+    -0x1.00c0bf8p700
+  },
+  { // Entry 19
+    -0x1.bf3980c6c1e9f4496795f4ce535016b6p-1,
+    0x1.00c0bf8p700
+  },
+  { // Entry 20
+    0x1.d62899d48b4397fb275ba44095971364p-4,
+    -0x1.13fffffffff80p6
+  },
+  { // Entry 21
+    -0x1.d62899d48b4397fb275ba44095971364p-4,
+    0x1.13fffffffff80p6
+  },
+  { // Entry 22
+    -0x1.17b7a60ce1f1485824711523ab0fd6d1p-5,
+    -0x1.17c5920767dfcp-5
+  },
+  { // Entry 23
+    0x1.17b7a60ce1f1485824711523ab0fd6d1p-5,
+    0x1.17c5920767dfcp-5
+  },
+  { // Entry 24
+    0x1.f0192b794fbbe030fe25edf65a5db9bfp-1,
+    -0x1.1d99be08713ccp2
+  },
+  { // Entry 25
+    -0x1.f0192b794fbbe030fe25edf65a5db9bfp-1,
+    0x1.1d99be08713ccp2
+  },
+  { // Entry 26
+    -0x1.5e61328c0034ec3a05d053b72e2d5945p-3,
+    -0x1.1ddbfd64fc0d3p81
+  },
+  { // Entry 27
+    0x1.5e61328c0034ec3a05d053b72e2d5945p-3,
+    0x1.1ddbfd64fc0d3p81
+  },
+  { // Entry 28
+    0x1.fb028c5df1db3eb32b0062c6cd4dea0bp-1,
+    -0x1.1e2a1563e068ep7
+  },
+  { // Entry 29
+    -0x1.fb028c5df1db3eb32b0062c6cd4dea0bp-1,
+    0x1.1e2a1563e068ep7
+  },
+  { // Entry 30
+    -0x1.2cefb196ba2077fffffd4bd650722bfbp-3,
+    -0x1.2e07a91314dp-3
+  },
+  { // Entry 31
+    0x1.2cefb196ba2077fffffd4bd650722bfbp-3,
+    0x1.2e07a91314dp-3
+  },
+  { // Entry 32
+    0x1.b80f489d3edf4835de7deeeb5bb38ad9p-2,
+    -0x1.3bcec270444e2p3
+  },
+  { // Entry 33
+    -0x1.b80f489d3edf4835de7deeeb5bb38ad9p-2,
+    0x1.3bcec270444e2p3
+  },
+  { // Entry 34
+    -0x1.4fffffffffa38800000004dd22ccccccp-20,
+    -0x1.5000000000040p-20
+  },
+  { // Entry 35
+    0x1.4fffffffffa38800000004dd22ccccccp-20,
+    0x1.5000000000040p-20
+  },
+  { // Entry 36
+    -0x1.d29da5b44f51b7fc019f183e1d3bd511p-2,
+    -0x1.559001a42d90cp1
+  },
+  { // Entry 37
+    0x1.d29da5b44f51b7fc019f183e1d3bd511p-2,
+    0x1.559001a42d90cp1
+  },
+  { // Entry 38
+    -0x1.f85f526147f787fffff15241e719734bp-1,
+    -0x1.597bf3e9776b7p99
+  },
+  { // Entry 39
+    0x1.f85f526147f787fffff15241e719734bp-1,
+    0x1.597bf3e9776b7p99
+  },
+  { // Entry 40
+    -0x1.6d61b58c99c42f1396af4a42148f73c6p-59,
+    -0x1.6c6cbc45dc8dep7
+  },
+  { // Entry 41
+    0x1.6d61b58c99c42f1396af4a42148f73c6p-59,
+    0x1.6c6cbc45dc8dep7
+  },
+  { // Entry 42
+    0x1.e5c3c08a258a77f1d12efa8c30166709p-1,
+    -0x1.73d8d173f90d0p4
+  },
+  { // Entry 43
+    -0x1.e5c3c08a258a77f1d12efa8c30166709p-1,
+    0x1.73d8d173f90d0p4
+  },
+  { // Entry 44
+    0x1.feb36806ca5fb7ea442119af41be0f4fp-1,
+    -0x1.8c202d3a31802p6
+  },
+  { // Entry 45
+    -0x1.feb36806ca5fb7ea442119af41be0f4fp-1,
+    0x1.8c202d3a31802p6
+  },
+  { // Entry 46
+    -0x1.7c6c7b01b98d947cd8add5e5d1ae11cap-1,
+    -0x1.acd538b1a6d5dp-1
+  },
+  { // Entry 47
+    0x1.7c6c7b01b98d947cd8add5e5d1ae11cap-1,
+    0x1.acd538b1a6d5dp-1
+  },
+  { // Entry 48
+    -0x1.191be2059dcb57fed86dd2cc62eb1a9fp-1,
+    -0x1.b7525ac97e0d2p2
+  },
+  { // Entry 49
+    0x1.191be2059dcb57fed86dd2cc62eb1a9fp-1,
+    0x1.b7525ac97e0d2p2
+  },
+  { // Entry 50
+    -0x1.f8305993a212c7fffffc15c2afa5e57ep-1,
+    -0x1.bee5fa8a84b02p0
+  },
+  { // Entry 51
+    0x1.f8305993a212c7fffffc15c2afa5e57ep-1,
+    0x1.bee5fa8a84b02p0
+  },
+  { // Entry 52
+    0x1.ff3b13530fd70e72b77f7c6721da1131p-1,
+    -0x1.c393979fe5921p9
+  },
+  { // Entry 53
+    -0x1.ff3b13530fd70e72b77f7c6721da1131p-1,
+    0x1.c393979fe5921p9
+  },
+  { // Entry 54
+    -0x1.f119da81a4da57ffd8bcc5a1247f5590p-1,
+    -0x1.c48ffc72563c8p18
+  },
+  { // Entry 55
+    0x1.f119da81a4da57ffd8bcc5a1247f5590p-1,
+    0x1.c48ffc72563c8p18
+  },
+  { // Entry 56
+    -0x1.fd73b81e04ccc7e9d764eca8bb085109p-1,
+    -0x1.c79548bc31856p3
+  },
+  { // Entry 57
+    0x1.fd73b81e04ccc7e9d764eca8bb085109p-1,
+    0x1.c79548bc31856p3
+  },
+  { // Entry 58
+    -0x1.c7885aef33a94ffc5ae06be9444efad5p-3,
+    -0x1.cb6p-3
+  },
+  { // Entry 59
+    0x1.c7885aef33a94ffc5ae06be9444efad5p-3,
+    0x1.cb6p-3
+  },
+  { // Entry 60
+    -0x1.e6494911eedd08d1650a4b5136c3e6d6p-7,
+    -0x1.e64ddaf7bd72fp-7
+  },
+  { // Entry 61
+    0x1.e6494911eedd08d1650a4b5136c3e6d6p-7,
+    0x1.e64ddaf7bd72fp-7
+  },
+  { // Entry 62
+    0x1.e180eef5b1c887fff585594949b46e6cp-1,
+    -0x1.ecdd0fbf07942p5
+  },
+  { // Entry 63
+    -0x1.e180eef5b1c887fff585594949b46e6cp-1,
+    0x1.ecdd0fbf07942p5
+  },
+  { // Entry 64
+    -0x1.fd98d20c1be4380000001ee51562d7a8p-1,
+    -0x1.f073a23292337p2
+  },
+  { // Entry 65
+    0x1.fd98d20c1be4380000001ee51562d7a8p-1,
+    0x1.f073a23292337p2
+  },
+  { // Entry 66
+    -0x1.7268c112297c87d17633bab722f31a3fp-5,
+    -0x1.f5e4c410f4ef8p15
+  },
+  { // Entry 67
+    0x1.7268c112297c87d17633bab722f31a3fp-5,
+    0x1.f5e4c410f4ef8p15
+  },
+  { // Entry 68
+    0x1.420796146070e628c19d38d1e90df228p-18,
+    -0x1.f8000000002p95
+  },
+  { // Entry 69
+    -0x1.420796146070e628c19d38d1e90df228p-18,
+    0x1.f8000000002p95
+  },
+  { // Entry 70
+    -0x1.e4f6dc499d9cc8035607fa3d76f9f4c5p-2,
+    -0x1.f9365d79546e1p-2
+  },
+  { // Entry 71
+    0x1.e4f6dc499d9cc8035607fa3d76f9f4c5p-2,
+    0x1.f9365d79546e1p-2
+  },
+  { // Entry 72
+    0x1.b2ef99b140d650468aed82fe0d442adap-14,
+    -0x1.ffffffffffe7ep1023
+  },
+  { // Entry 73
+    -0x1.b2ef99b140d650468aed82fe0d442adap-14,
+    0x1.ffffffffffe7ep1023
+  },
+  { // Entry 74
+    0x1.db0ffc3ecc6e3b8e37357ca002d5625bp-1,
+    0x1.0p15
+  },
+  { // Entry 75
+    -0x1.db0ffc3ecc6e3b8e37357ca002d5625bp-1,
+    -0x1.0p15
+  },
+  { // Entry 76
+    -0x1.e98f87098b62699ad16e0259b0e85b24p-1,
+    0x1.0000000000001p13
+  },
+  { // Entry 77
+    0x1.e98f87098b62699ad16e0259b0e85b24p-1,
+    -0x1.0000000000001p13
+  },
+  { // Entry 78
+    0x1.053c35068e10d45ee50f2d1ddcabcf3dp-4,
+    0x1.0000000000001p52
+  },
+  { // Entry 79
+    -0x1.053c35068e10d45ee50f2d1ddcabcf3dp-4,
+    -0x1.0000000000001p52
+  },
+  { // Entry 80
+    0x1.72d421b6884e500bbd3a9efc0f0ced92p-1,
+    0x1.0000000000001p228
+  },
+  { // Entry 81
+    -0x1.72d421b6884e500bbd3a9efc0f0ced92p-1,
+    -0x1.0000000000001p228
+  },
+  { // Entry 82
+    0x1.77fba987c56533a665e88e5a592ca10cp-1,
+    0x1.0000000000001p491
+  },
+  { // Entry 83
+    -0x1.77fba987c56533a665e88e5a592ca10cp-1,
+    -0x1.0000000000001p491
+  },
+  { // Entry 84
+    -0x1.723b2625331af2e79a9f07145a1e5731p-1,
+    0x1.0000000000003p215
+  },
+  { // Entry 85
+    0x1.723b2625331af2e79a9f07145a1e5731p-1,
+    -0x1.0000000000003p215
+  },
+  { // Entry 86
+    0x1.aed548f090cf47fe7e32103ab140caf8p-1,
+    0x1.0000000000006p0
+  },
+  { // Entry 87
+    -0x1.aed548f090cf47fe7e32103ab140caf8p-1,
+    -0x1.0000000000006p0
+  },
+  { // Entry 88
+    -0x1.ff983208c7dc978079174b461b3809f0p-1,
+    0x1.0000000000007p8
+  },
+  { // Entry 89
+    0x1.ff983208c7dc978079174b461b3809f0p-1,
+    -0x1.0000000000007p8
+  },
+  { // Entry 90
+    0x1.ffef29dc38452ffef4a779a1f86707dap-1,
+    0x1.0000000000007p275
+  },
+  { // Entry 91
+    -0x1.ffef29dc38452ffef4a779a1f86707dap-1,
+    -0x1.0000000000007p275
+  },
+  { // Entry 92
+    -0x1.fa88c375723c0d7ea1f2d08ebb2f9407p-8,
+    0x1.0000000000007p449
+  },
+  { // Entry 93
+    0x1.fa88c375723c0d7ea1f2d08ebb2f9407p-8,
+    -0x1.0000000000007p449
+  },
+  { // Entry 94
+    0x1.fff5322c94eae1b0b51086c08faa585cp-1,
+    0x1.0000000000011p644
+  },
+  { // Entry 95
+    -0x1.fff5322c94eae1b0b51086c08faa585cp-1,
+    -0x1.0000000000011p644
+  },
+  { // Entry 96
+    -0x1.a73630af8f15b8000054ddd950bba107p-1,
+    0x1.000000000001fp164
+  },
+  { // Entry 97
+    0x1.a73630af8f15b8000054ddd950bba107p-1,
+    -0x1.000000000001fp164
+  },
+  { // Entry 98
+    0x1.1c548f9249e4474988646b86894e9581p-2,
+    0x1.0000000000038p380
+  },
+  { // Entry 99
+    -0x1.1c548f9249e4474988646b86894e9581p-2,
+    -0x1.0000000000038p380
+  },
+  { // Entry 100
+    0x1.ca965bd2c4dfee4779ca8c797806292dp-3,
+    0x1.0000000000118p380
+  },
+  { // Entry 101
+    -0x1.ca965bd2c4dfee4779ca8c797806292dp-3,
+    -0x1.0000000000118p380
+  },
+  { // Entry 102
+    -0x1.837b9dddc24cf2f729a38147795b18d2p-1,
+    0x1.000000000012cp2
+  },
+  { // Entry 103
+    0x1.837b9dddc24cf2f729a38147795b18d2p-1,
+    -0x1.000000000012cp2
+  },
+  { // Entry 104
+    0x1.d82c1784c3ecbfefb02d7d6b585f73c4p-2,
+    0x1.00000000001f8p700
+  },
+  { // Entry 105
+    -0x1.d82c1784c3ecbfefb02d7d6b585f73c4p-2,
+    -0x1.00000000001f8p700
+  },
+  { // Entry 106
+    0x1.fffeaaaaef2ee7ee876f90b70b512475p-8,
+    0x1.00000000002p-7
+  },
+  { // Entry 107
+    -0x1.fffeaaaaef2ee7ee876f90b70b512475p-8,
+    -0x1.00000000002p-7
+  },
+  { // Entry 108
+    -0x1.0871bddd90fc5834034ee3f6f86b43a3p-1,
+    0x1.00000000002p40
+  },
+  { // Entry 109
+    0x1.0871bddd90fc5834034ee3f6f86b43a3p-1,
+    -0x1.00000000002p40
+  },
+  { // Entry 110
+    0x1.fffeaaaaef2f07ee476fa60c5dbe4886p-8,
+    0x1.0000000000201p-7
+  },
+  { // Entry 111
+    -0x1.fffeaaaaef2f07ee476fa60c5dbe4886p-8,
+    -0x1.0000000000201p-7
+  },
+  { // Entry 112
+    0x1.fffeaaaaef3307e6477250b6ab524ab7p-8,
+    0x1.0000000000221p-7
+  },
+  { // Entry 113
+    -0x1.fffeaaaaef3307e6477250b6ab524ab7p-8,
+    -0x1.0000000000221p-7
+  },
+  { // Entry 114
+    0x1.fffeaaaaef3627e00774660bb7d7a87cp-8,
+    0x1.000000000023ap-7
+  },
+  { // Entry 115
+    -0x1.fffeaaaaef3627e00774660bb7d7a87cp-8,
+    -0x1.000000000023ap-7
+  },
+  { // Entry 116
+    0x1.e0c6edfa9360159534def713925f126fp-9,
+    0x1.00000000040p45
+  },
+  { // Entry 117
+    -0x1.e0c6edfa9360159534def713925f126fp-9,
+    -0x1.00000000040p45
+  },
+  { // Entry 118
+    0x1.ea1f618356db0d3ab66d0ef6493bc93dp-5,
+    0x1.0000000c0p40
+  },
+  { // Entry 119
+    -0x1.ea1f618356db0d3ab66d0ef6493bc93dp-5,
+    -0x1.0000000c0p40
+  },
+  { // Entry 120
+    0x1.faaeed7587541fffff9922ba6690b8bap-3,
+    0x1.00000013c86f4p-2
+  },
+  { // Entry 121
+    -0x1.faaeed7587541fffff9922ba6690b8bap-3,
+    -0x1.00000013c86f4p-2
+  },
+  { // Entry 122
+    0x1.540bc7785680ac2ca169ff9e3cc4b152p-1,
+    0x1.001p13
+  },
+  { // Entry 123
+    -0x1.540bc7785680ac2ca169ff9e3cc4b152p-1,
+    -0x1.001p13
+  },
+  { // Entry 124
+    -0x1.37a7cb907a2e500106b04d9e3f0b1b8cp-1,
+    0x1.003p699
+  },
+  { // Entry 125
+    0x1.37a7cb907a2e500106b04d9e3f0b1b8cp-1,
+    -0x1.003p699
+  },
+  { // Entry 126
+    -0x1.29e5845fc54b580145273f2cafe73ab5p-1,
+    0x1.00380p40
+  },
+  { // Entry 127
+    0x1.29e5845fc54b580145273f2cafe73ab5p-1,
+    -0x1.00380p40
+  },
+  { // Entry 128
+    0x1.ffe5ca46564917a1e812aedd48fe107cp-1,
+    0x1.007p10
+  },
+  { // Entry 129
+    -0x1.ffe5ca46564917a1e812aedd48fe107cp-1,
+    -0x1.007p10
+  },
+  { // Entry 130
+    0x1.ea4df82db014ac0c913465da57b6a643p-1,
+    0x1.007p25
+  },
+  { // Entry 131
+    -0x1.ea4df82db014ac0c913465da57b6a643p-1,
+    -0x1.007p25
+  },
+  { // Entry 132
+    0x1.fe757aef1c80c7ec16003d3ae5f0ce15p-1,
+    0x1.007p41
+  },
+  { // Entry 133
+    -0x1.fe757aef1c80c7ec16003d3ae5f0ce15p-1,
+    -0x1.007p41
+  },
+  { // Entry 134
+    0x1.e9b71805ec0685d484f6270f6411dc36p-7,
+    0x1.00cp41
+  },
+  { // Entry 135
+    -0x1.e9b71805ec0685d484f6270f6411dc36p-7,
+    -0x1.00cp41
+  },
+  { // Entry 136
+    0x1.b0b6d0a54058280008e80488f8ab1bb7p-1,
+    0x1.01c00000001p0
+  },
+  { // Entry 137
+    -0x1.b0b6d0a54058280008e80488f8ab1bb7p-1,
+    -0x1.01c00000001p0
+  },
+  { // Entry 138
+    0x1.fef009262701280b92aaf925dda63bbap-3,
+    0x1.02322e46da919p-2
+  },
+  { // Entry 139
+    -0x1.fef009262701280b92aaf925dda63bbap-3,
+    -0x1.02322e46da919p-2
+  },
+  { // Entry 140
+    0x1.ffc90059804a082d9b3f46b77ee81932p-3,
+    0x1.02a236478p-2
+  },
+  { // Entry 141
+    -0x1.ffc90059804a082d9b3f46b77ee81932p-3,
+    -0x1.02a236478p-2
+  },
+  { // Entry 142
+    0x1.ffd10a6b5429e828bef4d9413eb9f6c0p-3,
+    0x1.02a65d08ca5e5p-2
+  },
+  { // Entry 143
+    -0x1.ffd10a6b5429e828bef4d9413eb9f6c0p-3,
+    -0x1.02a65d08ca5e5p-2
+  },
+  { // Entry 144
+    0x1.ffd10ab302a3f7e0a048db5861e7b20bp-3,
+    0x1.02a65d2dce49ap-2
+  },
+  { // Entry 145
+    -0x1.ffd10ab302a3f7e0a048db5861e7b20bp-3,
+    -0x1.02a65d2dce49ap-2
+  },
+  { // Entry 146
+    0x1.ffe0b1764ca4c7d2329433828cdc901cp-3,
+    0x1.02ae7238ap-2
+  },
+  { // Entry 147
+    -0x1.ffe0b1764ca4c7d2329433828cdc901cp-3,
+    -0x1.02ae7238ap-2
+  },
+  { // Entry 148
+    -0x1.f68f0e26c0f6ad44f7184d56be95e1aep-3,
+    0x1.0501d22221dacp621
+  },
+  { // Entry 149
+    0x1.f68f0e26c0f6ad44f7184d56be95e1aep-3,
+    -0x1.0501d22221dacp621
+  },
+  { // Entry 150
+    0x1.b63c41f09eb747f30c1af5f254340a4cp-1,
+    0x1.06ffffffffff8p0
+  },
+  { // Entry 151
+    -0x1.b63c41f09eb747f30c1af5f254340a4cp-1,
+    -0x1.06ffffffffff8p0
+  },
+  { // Entry 152
+    -0x1.ffdc173adabb1afd58fcb5643cd86562p-1,
+    0x1.07023d3d44215p12
+  },
+  { // Entry 153
+    0x1.ffdc173adabb1afd58fcb5643cd86562p-1,
+    -0x1.07023d3d44215p12
+  },
+  { // Entry 154
+    0x1.0889e11bef1357a88742ab3a7f180786p-5,
+    0x1.0895a7a3e8ae6p-5
+  },
+  { // Entry 155
+    -0x1.0889e11bef1357a88742ab3a7f180786p-5,
+    -0x1.0895a7a3e8ae6p-5
+  },
+  { // Entry 156
+    0x1.08ca077c764457aa6d968afc1d1b17b3p-5,
+    0x1.08d5d69840601p-5
+  },
+  { // Entry 157
+    -0x1.08ca077c764457aa6d968afc1d1b17b3p-5,
+    -0x1.08d5d69840601p-5
+  },
+  { // Entry 158
+    -0x1.ff7fbe518023e90b3f28f81ab93e872fp-1,
+    0x1.0e0p6
+  },
+  { // Entry 159
+    0x1.ff7fbe518023e90b3f28f81ab93e872fp-1,
+    -0x1.0e0p6
+  },
+  { // Entry 160
+    -0x1.fd6c68b877afe803aaab2bd30124ecdfp-1,
+    0x1.107ba49c346e4p9
+  },
+  { // Entry 161
+    0x1.fd6c68b877afe803aaab2bd30124ecdfp-1,
+    -0x1.107ba49c346e4p9
+  },
+  { // Entry 162
+    -0x1.a2ba6bc70bce4801ea4d1c85f116193dp-1,
+    0x1.1491544774440p745
+  },
+  { // Entry 163
+    0x1.a2ba6bc70bce4801ea4d1c85f116193dp-1,
+    -0x1.1491544774440p745
+  },
+  { // Entry 164
+    0x1.165609790f23484a4701b4439d4fe51fp-5,
+    0x1.1663c0e518180p-5
+  },
+  { // Entry 165
+    -0x1.165609790f23484a4701b4439d4fe51fp-5,
+    -0x1.1663c0e518180p-5
+  },
+  { // Entry 166
+    -0x1.fc0523ff94e44c01731e45963034cba8p-1,
+    0x1.1745d1745d176p238
+  },
+  { // Entry 167
+    0x1.fc0523ff94e44c01731e45963034cba8p-1,
+    -0x1.1745d1745d176p238
+  },
+  { // Entry 168
+    0x1.f34a729c584bcc9666402cfdb48839ffp-1,
+    0x1.17472a408a3e0p97
+  },
+  { // Entry 169
+    -0x1.f34a729c584bcc9666402cfdb48839ffp-1,
+    -0x1.17472a408a3e0p97
+  },
+  { // Entry 170
+    0x1.177fae169fdf0858b1d4e7bad69981dcp-5,
+    0x1.178d91b6b992dp-5
+  },
+  { // Entry 171
+    -0x1.177fae169fdf0858b1d4e7bad69981dcp-5,
+    -0x1.178d91b6b992dp-5
+  },
+  { // Entry 172
+    0x1.177fae16a120e85843d1dfef36726cecp-5,
+    0x1.178d91b6bad4ep-5
+  },
+  { // Entry 173
+    -0x1.177fae16a120e85843d1dfef36726cecp-5,
+    -0x1.178d91b6bad4ep-5
+  },
+  { // Entry 174
+    0x1.177fae16a1f78856637cc9da8aaf6439p-5,
+    0x1.178d91b6bbabap-5
+  },
+  { // Entry 175
+    -0x1.177fae16a1f78856637cc9da8aaf6439p-5,
+    -0x1.178d91b6bbabap-5
+  },
+  { // Entry 176
+    0x1.177fae16a40fe858da1ddcb583bb9f3bp-5,
+    0x1.178d91b6bdc45p-5
+  },
+  { // Entry 177
+    -0x1.177fae16a40fe858da1ddcb583bb9f3bp-5,
+    -0x1.178d91b6bdc45p-5
+  },
+  { // Entry 178
+    0x1.297c768f2413080002edcb9a905946afp-1,
+    0x1.19752dbee5f6ap933
+  },
+  { // Entry 179
+    -0x1.297c768f2413080002edcb9a905946afp-1,
+    -0x1.19752dbee5f6ap933
+  },
+  { // Entry 180
+    0x1.b826df5cafafa824779bb808d64de6fbp-2,
+    0x1.1b3009cfe4dbcp8
+  },
+  { // Entry 181
+    -0x1.b826df5cafafa824779bb808d64de6fbp-2,
+    -0x1.1b3009cfe4dbcp8
+  },
+  { // Entry 182
+    0x1.b7a5956250b6a83882133bbe14c847ccp-2,
+    0x1.1f6475d95bf18p3
+  },
+  { // Entry 183
+    -0x1.b7a5956250b6a83882133bbe14c847ccp-2,
+    -0x1.1f6475d95bf18p3
+  },
+  { // Entry 184
+    0x1.4db6566b645477ffea9faaf8bf463a1ep-1,
+    0x1.229148a452291p118
+  },
+  { // Entry 185
+    -0x1.4db6566b645477ffea9faaf8bf463a1ep-1,
+    -0x1.229148a452291p118
+  },
+  { // Entry 186
+    0x1.1686fee2c49a7fffb68df681b2da7e49p-1,
+    0x1.268p-1
+  },
+  { // Entry 187
+    -0x1.1686fee2c49a7fffb68df681b2da7e49p-1,
+    -0x1.268p-1
+  },
+  { // Entry 188
+    0x1.22eb21a44d62780000031ae43c448511p-2,
+    0x1.26fb3844dd190p-2
+  },
+  { // Entry 189
+    -0x1.22eb21a44d62780000031ae43c448511p-2,
+    -0x1.26fb3844dd190p-2
+  },
+  { // Entry 190
+    0x1.d4a216d89b2b37f40ff08753ed600e74p-1,
+    0x1.27fffffffe6b0p0
+  },
+  { // Entry 191
+    -0x1.d4a216d89b2b37f40ff08753ed600e74p-1,
+    -0x1.27fffffffe6b0p0
+  },
+  { // Entry 192
+    -0x1.76c9b0f3a22f73cfd4453fcf7b21e358p-1,
+    0x1.284b84048d481p204
+  },
+  { // Entry 193
+    0x1.76c9b0f3a22f73cfd4453fcf7b21e358p-1,
+    -0x1.284b84048d481p204
+  },
+  { // Entry 194
+    -0x1.ff01226f97d32d6b5c0d5e4a3a2f53c3p-1,
+    0x1.2999e3109cad4p2
+  },
+  { // Entry 195
+    0x1.ff01226f97d32d6b5c0d5e4a3a2f53c3p-1,
+    -0x1.2999e3109cad4p2
+  },
+  { // Entry 196
+    0x1.2a8f11e7ae82c0a374855b53b3605d3bp-5,
+    0x1.2aap-5
+  },
+  { // Entry 197
+    -0x1.2a8f11e7ae82c0a374855b53b3605d3bp-5,
+    -0x1.2aap-5
+  },
+  { // Entry 198
+    0x1.2b03d1bf773df7b697d8a97eccefec50p-5,
+    0x1.2b14d3be0c230p-5
+  },
+  { // Entry 199
+    -0x1.2b03d1bf773df7b697d8a97eccefec50p-5,
+    -0x1.2b14d3be0c230p-5
+  },
+  { // Entry 200
+    -0x1.ffb90ee641791e699aa7fc7139bf58b4p-1,
+    0x1.2b7cb44849981p2
+  },
+  { // Entry 201
+    0x1.ffb90ee641791e699aa7fc7139bf58b4p-1,
+    -0x1.2b7cb44849981p2
+  },
+  { // Entry 202
+    -0x1.ffffff79e71a3db22109c6bb87f9c237p-1,
+    0x1.2becc86852580p200
+  },
+  { // Entry 203
+    0x1.ffffff79e71a3db22109c6bb87f9c237p-1,
+    -0x1.2becc86852580p200
+  },
+  { // Entry 204
+    -0x1.fff9edaf85b76f6cbb2f5b7e384cbbc9p-1,
+    0x1.2cfa14ce27cd5p2
+  },
+  { // Entry 205
+    0x1.fff9edaf85b76f6cbb2f5b7e384cbbc9p-1,
+    -0x1.2cfa14ce27cd5p2
+  },
+  { // Entry 206
+    0x1.2cbaaa4cebb517fe7bd14f062afec390p-4,
+    0x1.2d0p-4
+  },
+  { // Entry 207
+    -0x1.2cbaaa4cebb517fe7bd14f062afec390p-4,
+    -0x1.2d0p-4
+  },
+  { // Entry 208
+    -0x1.ffffbc177e00ff89cbb4f49a0643da78p-1,
+    0x1.2d76d18721be8p2
+  },
+  { // Entry 209
+    0x1.ffffbc177e00ff89cbb4f49a0643da78p-1,
+    -0x1.2d76d18721be8p2
+  },
+  { // Entry 210
+    0x1.745843dfafefd1bf9656896a8fb5b0e3p-18,
+    0x1.302a494e09090p97
+  },
+  { // Entry 211
+    -0x1.745843dfafefd1bf9656896a8fb5b0e3p-18,
+    -0x1.302a494e09090p97
+  },
+  { // Entry 212
+    0x1.ffcc568d423766c92e9c175f9210f1f4p-1,
+    0x1.31cc731cc731cp1000
+  },
+  { // Entry 213
+    -0x1.ffcc568d423766c92e9c175f9210f1f4p-1,
+    -0x1.31cc731cc731cp1000
+  },
+  { // Entry 214
+    0x1.b676077d4faf7927da1f858539fad1ffp-1,
+    0x1.328463d4f8ca6p441
+  },
+  { // Entry 215
+    -0x1.b676077d4faf7927da1f858539fad1ffp-1,
+    -0x1.328463d4f8ca6p441
+  },
+  { // Entry 216
+    -0x1.fffffffffffffffff3471d8dc070d5e6p-1,
+    0x1.32ce90b32171ep18
+  },
+  { // Entry 217
+    0x1.fffffffffffffffff3471d8dc070d5e6p-1,
+    -0x1.32ce90b32171ep18
+  },
+  { // Entry 218
+    0x1.35cbd3240d148845d39ebd54b1556779p-5,
+    0x1.35debd7f020ecp-5
+  },
+  { // Entry 219
+    -0x1.35cbd3240d148845d39ebd54b1556779p-5,
+    -0x1.35debd7f020ecp-5
+  },
+  { // Entry 220
+    0x1.3bb2086559fa982e5c6da10d8d9ac931p-7,
+    0x1.3bb3487893405p-7
+  },
+  { // Entry 221
+    -0x1.3bb2086559fa982e5c6da10d8d9ac931p-7,
+    -0x1.3bb3487893405p-7
+  },
+  { // Entry 222
+    0x1.3bb2086559fab82dfb1925eac2ab8bc1p-7,
+    0x1.3bb3487893407p-7
+  },
+  { // Entry 223
+    -0x1.3bb2086559fab82dfb1925eac2ab8bc1p-7,
+    -0x1.3bb3487893407p-7
+  },
+  { // Entry 224
+    0x1.dff197edc51d235e4a4cc6e34bd1fd10p-16,
+    0x1.3bb681d65aa60p100
+  },
+  { // Entry 225
+    -0x1.dff197edc51d235e4a4cc6e34bd1fd10p-16,
+    -0x1.3bb681d65aa60p100
+  },
+  { // Entry 226
+    -0x1.5d08d3dbb41af80000053ba30e95e709p-3,
+    0x1.3f9aa8626042fp83
+  },
+  { // Entry 227
+    0x1.5d08d3dbb41af80000053ba30e95e709p-3,
+    -0x1.3f9aa8626042fp83
+  },
+  { // Entry 228
+    0x1.fb503983f94bb749fce9ccca56a35ec6p-3,
+    0x1.3fep19
+  },
+  { // Entry 229
+    -0x1.fb503983f94bb749fce9ccca56a35ec6p-3,
+    -0x1.3fep19
+  },
+  { // Entry 230
+    -0x1.d3876eacc9ee6ec5a93ea14e032f9b02p-1,
+    0x1.4285478f1e3c8p58
+  },
+  { // Entry 231
+    0x1.d3876eacc9ee6ec5a93ea14e032f9b02p-1,
+    -0x1.4285478f1e3c8p58
+  },
+  { // Entry 232
+    0x1.42b66d54f69c0fabe371d703a1d7d7c9p-5,
+    0x1.42cbcf45a169ep-5
+  },
+  { // Entry 233
+    -0x1.42b66d54f69c0fabe371d703a1d7d7c9p-5,
+    -0x1.42cbcf45a169ep-5
+  },
+  { // Entry 234
+    0x1.b45e9e942755380000015e1db0ce188dp-1,
+    0x1.43fffffffff6ap557
+  },
+  { // Entry 235
+    -0x1.b45e9e942755380000015e1db0ce188dp-1,
+    -0x1.43fffffffff6ap557
+  },
+  { // Entry 236
+    0x1.43ffffffea602800006ed7862b3224a6p-17,
+    0x1.440p-17
+  },
+  { // Entry 237
+    -0x1.43ffffffea602800006ed7862b3224a6p-17,
+    -0x1.440p-17
+  },
+  { // Entry 238
+    -0x1.6a4e98d2d8b1b7fb43fef1bc4e3245bbp-1,
+    0x1.4748c08dc0976p200
+  },
+  { // Entry 239
+    0x1.6a4e98d2d8b1b7fb43fef1bc4e3245bbp-1,
+    -0x1.4748c08dc0976p200
+  },
+  { // Entry 240
+    -0x1.b57ca8aacf2a937a269ccdfa8b38c8c1p-1,
+    0x1.478fc08p43
+  },
+  { // Entry 241
+    0x1.b57ca8aacf2a937a269ccdfa8b38c8c1p-1,
+    -0x1.478fc08p43
+  },
+  { // Entry 242
+    0x1.ffe38008ef6b4956b290202d414d59c3p-1,
+    0x1.4cf36d17c596ep200
+  },
+  { // Entry 243
+    -0x1.ffe38008ef6b4956b290202d414d59c3p-1,
+    -0x1.4cf36d17c596ep200
+  },
+  { // Entry 244
+    0x1.d6457a3f12e6c527a853470401d35d2dp-1,
+    0x1.4f0f308p488
+  },
+  { // Entry 245
+    -0x1.d6457a3f12e6c527a853470401d35d2dp-1,
+    -0x1.4f0f308p488
+  },
+  { // Entry 246
+    0x1.4fffffffff9f88000000084f22ccccccp-20,
+    0x1.5p-20
+  },
+  { // Entry 247
+    -0x1.4fffffffff9f88000000084f22ccccccp-20,
+    -0x1.5p-20
+  },
+  { // Entry 248
+    -0x1.cbad095f503a18019a7b27170f6a4acfp-1,
+    0x1.5143e25a488f1p3
+  },
+  { // Entry 249
+    0x1.cbad095f503a18019a7b27170f6a4acfp-1,
+    -0x1.5143e25a488f1p3
+  },
+  { // Entry 250
+    -0x1.f942d6262e82dd6834ded8c90d0f8212p-5,
+    0x1.51f0f44da4df4p200
+  },
+  { // Entry 251
+    0x1.f942d6262e82dd6834ded8c90d0f8212p-5,
+    -0x1.51f0f44da4df4p200
+  },
+  { // Entry 252
+    -0x1.fc466ccaece804aac14e79aaba4b5c1ep-3,
+    0x1.52ad6c5a3602fp16
+  },
+  { // Entry 253
+    0x1.fc466ccaece804aac14e79aaba4b5c1ep-3,
+    -0x1.52ad6c5a3602fp16
+  },
+  { // Entry 254
+    0x1.d69c3cf4eecdd9b43726a2a7fa405c31p-1,
+    0x1.52f00e0p793
+  },
+  { // Entry 255
+    -0x1.d69c3cf4eecdd9b43726a2a7fa405c31p-1,
+    -0x1.52f00e0p793
+  },
+  { // Entry 256
+    0x1.e120292f3d4956579f9c3164cd94bad6p-1,
+    0x1.5555555555556p239
+  },
+  { // Entry 257
+    -0x1.e120292f3d4956579f9c3164cd94bad6p-1,
+    -0x1.5555555555556p239
+  },
+  { // Entry 258
+    -0x1.fd1d85b7ef0037fc4b1d1763882085f1p-1,
+    0x1.5a0000008p6
+  },
+  { // Entry 259
+    0x1.fd1d85b7ef0037fc4b1d1763882085f1p-1,
+    -0x1.5a0000008p6
+  },
+  { // Entry 260
+    0x1.5aff9664b07e1a2e0f24b2572ddbff64p-6,
+    0x1.5b063ad2dd08fp-6
+  },
+  { // Entry 261
+    -0x1.5aff9664b07e1a2e0f24b2572ddbff64p-6,
+    -0x1.5b063ad2dd08fp-6
+  },
+  { // Entry 262
+    -0x1.83f8bbb59f2f8cd8ebbd44c459e4c493p-1,
+    0x1.5b179d75fa285p2
+  },
+  { // Entry 263
+    0x1.83f8bbb59f2f8cd8ebbd44c459e4c493p-1,
+    -0x1.5b179d75fa285p2
+  },
+  { // Entry 264
+    0x1.fa865b0d994968390f9480c9caf49cb1p-1,
+    0x1.5bb5967402f9cp79
+  },
+  { // Entry 265
+    -0x1.fa865b0d994968390f9480c9caf49cb1p-1,
+    -0x1.5bb5967402f9cp79
+  },
+  { // Entry 266
+    0x1.e8a523fce884d189bdb87c20ed615944p-2,
+    0x1.5bea010p468
+  },
+  { // Entry 267
+    -0x1.e8a523fce884d189bdb87c20ed615944p-2,
+    -0x1.5bea010p468
+  },
+  { // Entry 268
+    -0x1.ff2ad941f0a40ea3bc29e6dd9c339b63p-1,
+    0x1.5f19fbc507af6p9
+  },
+  { // Entry 269
+    0x1.ff2ad941f0a40ea3bc29e6dd9c339b63p-1,
+    -0x1.5f19fbc507af6p9
+  },
+  { // Entry 270
+    -0x1.75ce4a0d0bd037fd53042cab82404953p-1,
+    0x1.60a610a658da9p889
+  },
+  { // Entry 271
+    0x1.75ce4a0d0bd037fd53042cab82404953p-1,
+    -0x1.60a610a658da9p889
+  },
+  { // Entry 272
+    -0x1.721586594ab4818acd4cb41fafc99484p-1,
+    0x1.62ad7ce17143dp62
+  },
+  { // Entry 273
+    0x1.721586594ab4818acd4cb41fafc99484p-1,
+    -0x1.62ad7ce17143dp62
+  },
+  { // Entry 274
+    0x1.b8d27019d1b9e836b953613c87acf3a9p-2,
+    0x1.645926cc1132cp9
+  },
+  { // Entry 275
+    -0x1.b8d27019d1b9e836b953613c87acf3a9p-2,
+    -0x1.645926cc1132cp9
+  },
+  { // Entry 276
+    0x1.647e09059c1e98000013714cd0c6a43dp-9,
+    0x1.647e25d391f17p-9
+  },
+  { // Entry 277
+    -0x1.647e09059c1e98000013714cd0c6a43dp-9,
+    -0x1.647e25d391f17p-9
+  },
+  { // Entry 278
+    -0x1.8d3b53ff85a823d06537413901229e45p-1,
+    0x1.64ef438p142
+  },
+  { // Entry 279
+    0x1.8d3b53ff85a823d06537413901229e45p-1,
+    -0x1.64ef438p142
+  },
+  { // Entry 280
+    -0x1.f7c8630e62a01ffd4e02577956e5523ep-1,
+    0x1.6599665996658p3
+  },
+  { // Entry 281
+    0x1.f7c8630e62a01ffd4e02577956e5523ep-1,
+    -0x1.6599665996658p3
+  },
+  { // Entry 282
+    0x1.67028e3602034800f45a9158d20a340cp-5,
+    0x1.672p-5
+  },
+  { // Entry 283
+    -0x1.67028e3602034800f45a9158d20a340cp-5,
+    -0x1.672p-5
+  },
+  { // Entry 284
+    0x1.bc60c8c33cb5ebf693d71650cbf166f9p-2,
+    0x1.688ae6c138ea8p299
+  },
+  { // Entry 285
+    -0x1.bc60c8c33cb5ebf693d71650cbf166f9p-2,
+    -0x1.688ae6c138ea8p299
+  },
+  { // Entry 286
+    -0x1.fc3b4bb8b012e8042d3ebced12def0c9p-1,
+    0x1.6aa78p17
+  },
+  { // Entry 287
+    0x1.fc3b4bb8b012e8042d3ebced12def0c9p-1,
+    -0x1.6aa78p17
+  },
+  { // Entry 288
+    0x1.ffffffffffffffffffffffffffffffb5p-1,
+    0x1.6ac5b262ca1ffp849
+  },
+  { // Entry 289
+    -0x1.ffffffffffffffffffffffffffffffb5p-1,
+    -0x1.6ac5b262ca1ffp849
+  },
+  { // Entry 290
+    -0x1.82317836a97c8cea1cd2e3a4d0d48f29p-1,
+    0x1.6d88083749412p4
+  },
+  { // Entry 291
+    0x1.82317836a97c8cea1cd2e3a4d0d48f29p-1,
+    -0x1.6d88083749412p4
+  },
+  { // Entry 292
+    0x1.6f781c78cc82a7ffcd20ba801e6691b1p-6,
+    0x1.6f8p-6
+  },
+  { // Entry 293
+    -0x1.6f781c78cc82a7ffcd20ba801e6691b1p-6,
+    -0x1.6f8p-6
+  },
+  { // Entry 294
+    -0x1.fdbe5085494ae7fe47fa067aaea7fdf9p-1,
+    0x1.729aa6859d1f4p396
+  },
+  { // Entry 295
+    0x1.fdbe5085494ae7fe47fa067aaea7fdf9p-1,
+    -0x1.729aa6859d1f4p396
+  },
+  { // Entry 296
+    -0x1.fffffae862b4fec1c2f1712aa165807cp-1,
+    0x1.73e2dbe9a2f80p10
+  },
+  { // Entry 297
+    0x1.fffffae862b4fec1c2f1712aa165807cp-1,
+    -0x1.73e2dbe9a2f80p10
+  },
+  { // Entry 298
+    0x1.769ac74459b058456b333238833f1d1ap-7,
+    0x1.769cde0b90b80p-7
+  },
+  { // Entry 299
+    -0x1.769ac74459b058456b333238833f1d1ap-7,
+    -0x1.769cde0b90b80p-7
+  },
+  { // Entry 300
+    0x1.769e8afb6a4ebf99ade465d19be86ac0p-5,
+    0x1.76cp-5
+  },
+  { // Entry 301
+    -0x1.769e8afb6a4ebf99ade465d19be86ac0p-5,
+    -0x1.76cp-5
+  },
+  { // Entry 302
+    0x1.fd562611f5bd4800de503e4210cc7df4p-1,
+    0x1.78001p0
+  },
+  { // Entry 303
+    -0x1.fd562611f5bd4800de503e4210cc7df4p-1,
+    -0x1.78001p0
+  },
+  { // Entry 304
+    0x1.fdba784ca00f17ebcc2b5b1098e83bffp-1,
+    0x1.7a0p0
+  },
+  { // Entry 305
+    -0x1.fdba784ca00f17ebcc2b5b1098e83bffp-1,
+    -0x1.7a0p0
+  },
+  { // Entry 306
+    0x1.f930c222a8682d7d1920a12b68870c36p-5,
+    0x1.7abd870381c2dp38
+  },
+  { // Entry 307
+    -0x1.f930c222a8682d7d1920a12b68870c36p-5,
+    -0x1.7abd870381c2dp38
+  },
+  { // Entry 308
+    0x1.ffeb2ff2b692367bc5660dab6960b57dp-1,
+    0x1.7dc945c212480p95
+  },
+  { // Entry 309
+    -0x1.ffeb2ff2b692367bc5660dab6960b57dp-1,
+    -0x1.7dc945c212480p95
+  },
+  { // Entry 310
+    0x1.b279153c23fb180000ce3a0d47d8c476p-2,
+    0x1.7f73e1594b70cp98
+  },
+  { // Entry 311
+    -0x1.b279153c23fb180000ce3a0d47d8c476p-2,
+    -0x1.7f73e1594b70cp98
+  },
+  { // Entry 312
+    -0x1.599fad35cf60ad43760cf3a9da3d9c30p-41,
+    0x1.7f7ef77e83f1ap21
+  },
+  { // Entry 313
+    0x1.599fad35cf60ad43760cf3a9da3d9c30p-41,
+    -0x1.7f7ef77e83f1ap21
+  },
+  { // Entry 314
+    0x1.feb7a9b2c6d8ade6e17fdacaef4fd96cp-1,
+    0x1.8p0
+  },
+  { // Entry 315
+    -0x1.feb7a9b2c6d8ade6e17fdacaef4fd96cp-1,
+    -0x1.8p0
+  },
+  { // Entry 316
+    0x1.f798d01ec615b8ededa474e3c6cd0c92p-1,
+    0x1.8p6
+  },
+  { // Entry 317
+    -0x1.f798d01ec615b8ededa474e3c6cd0c92p-1,
+    -0x1.8p6
+  },
+  { // Entry 318
+    0x1.fee1a2a977bced179f8ab8455ada525fp-1,
+    0x1.8132ceb1c4f39p0
+  },
+  { // Entry 319
+    -0x1.fee1a2a977bced179f8ab8455ada525fp-1,
+    -0x1.8132ceb1c4f39p0
+  },
+  { // Entry 320
+    -0x1.24245af4cd994e9b3bba992d0f57fc3fp-52,
+    0x1.81ae0dffa3b33p959
+  },
+  { // Entry 321
+    0x1.24245af4cd994e9b3bba992d0f57fc3fp-52,
+    -0x1.81ae0dffa3b33p959
+  },
+  { // Entry 322
+    0x1.85d41b0bf30907fffff1913a5ced7645p-4,
+    0x1.85ec5a399a2e6p1
+  },
+  { // Entry 323
+    -0x1.85d41b0bf30907fffff1913a5ced7645p-4,
+    -0x1.85ec5a399a2e6p1
+  },
+  { // Entry 324
+    0x1.1e42ae3cfbdc60976884087f97a0fda9p-24,
+    0x1.86a0092754022p16
+  },
+  { // Entry 325
+    -0x1.1e42ae3cfbdc60976884087f97a0fda9p-24,
+    -0x1.86a0092754022p16
+  },
+  { // Entry 326
+    -0x1.dbf4e594cefe1548efc24098d631e950p-1,
+    0x1.8720588p392
+  },
+  { // Entry 327
+    0x1.dbf4e594cefe1548efc24098d631e950p-1,
+    -0x1.8720588p392
+  },
+  { // Entry 328
+    0x1.44302d6a82d403badf1f9b71420ccdcap-9,
+    0x1.8929354ebc6aap43
+  },
+  { // Entry 329
+    -0x1.44302d6a82d403badf1f9b71420ccdcap-9,
+    -0x1.8929354ebc6aap43
+  },
+  { // Entry 330
+    0x1.8a52189ec34877bb5944413e00ad52edp-5,
+    0x1.8a791e4791e75p-5
+  },
+  { // Entry 331
+    -0x1.8a52189ec34877bb5944413e00ad52edp-5,
+    -0x1.8a791e4791e75p-5
+  },
+  { // Entry 332
+    -0x1.fe8566e538122db33c17f13b83474a04p-1,
+    0x1.8ba761438f5edp11
+  },
+  { // Entry 333
+    0x1.fe8566e538122db33c17f13b83474a04p-1,
+    -0x1.8ba761438f5edp11
+  },
+  { // Entry 334
+    0x1.fff42aca4cb5a80000057f1a48af65dep-1,
+    0x1.8eaf16de63920p0
+  },
+  { // Entry 335
+    -0x1.fff42aca4cb5a80000057f1a48af65dep-1,
+    -0x1.8eaf16de63920p0
+  },
+  { // Entry 336
+    0x1.fffb7d3f3a252da56d96327c18627f57p-1,
+    0x1.9p0
+  },
+  { // Entry 337
+    -0x1.fffb7d3f3a252da56d96327c18627f57p-1,
+    -0x1.9p0
+  },
+  { // Entry 338
+    -0x1.e815770667fd87f9525154edc867605fp-4,
+    0x1.91a5657fb6a9ap6
+  },
+  { // Entry 339
+    0x1.e815770667fd87f9525154edc867605fp-4,
+    -0x1.91a5657fb6a9ap6
+  },
+  { // Entry 340
+    -0x1.fffffffd311dc7ec5d0ae5728a7960fdp-1,
+    0x1.921fb54468847p37
+  },
+  { // Entry 341
+    0x1.fffffffd311dc7ec5d0ae5728a7960fdp-1,
+    -0x1.921fb54468847p37
+  },
+  { // Entry 342
+    0x1.ffffffff875e5e4497dd0760336e63f3p-17,
+    0x1.921ff54442d18p2
+  },
+  { // Entry 343
+    -0x1.ffffffff875e5e4497dd0760336e63f3p-17,
+    -0x1.921ff54442d18p2
+  },
+  { // Entry 344
+    0x1.812a5da3777cd7f6e17288638b40aa09p-8,
+    0x1.928p2
+  },
+  { // Entry 345
+    -0x1.812a5da3777cd7f6e17288638b40aa09p-8,
+    -0x1.928p2
+  },
+  { // Entry 346
+    0x1.fff9be8d82572c746f944934bbf1b697p-1,
+    0x1.94ap0
+  },
+  { // Entry 347
+    -0x1.fff9be8d82572c746f944934bbf1b697p-1,
+    -0x1.94ap0
+  },
+  { // Entry 348
+    0x1.947b0ace235f2850b27b164c49102a49p-5,
+    0x1.94a5294a51bdep-5
+  },
+  { // Entry 349
+    -0x1.947b0ace235f2850b27b164c49102a49p-5,
+    -0x1.94a5294a51bdep-5
+  },
+  { // Entry 350
+    0x1.c34f70e55a707bbd053a70e749105174p-2,
+    0x1.94a5294a52948p100
+  },
+  { // Entry 351
+    -0x1.c34f70e55a707bbd053a70e749105174p-2,
+    -0x1.94a5294a52948p100
+  },
+  { // Entry 352
+    0x1.950bcfc0f3d50850941a41d66cfa3721p-5,
+    0x1.95361b8f7697dp-5
+  },
+  { // Entry 353
+    -0x1.950bcfc0f3d50850941a41d66cfa3721p-5,
+    -0x1.95361b8f7697dp-5
+  },
+  { // Entry 354
+    0x1.6c548bfcce6953f19a8d2dd480d9320cp-1,
+    0x1.956p-1
+  },
+  { // Entry 355
+    -0x1.6c548bfcce6953f19a8d2dd480d9320cp-1,
+    -0x1.956p-1
+  },
+  { // Entry 356
+    0x1.ffeffdbf67ca6711a57b7d82140093c6p-1,
+    0x1.962p0
+  },
+  { // Entry 357
+    -0x1.ffeffdbf67ca6711a57b7d82140093c6p-1,
+    -0x1.962p0
+  },
+  { // Entry 358
+    0x1.9708213bf67f4857135077d50826f588p-5,
+    0x1.97330d2ea16d9p-5
+  },
+  { // Entry 359
+    -0x1.9708213bf67f4857135077d50826f588p-5,
+    -0x1.97330d2ea16d9p-5
+  },
+  { // Entry 360
+    0x1.972bf92713d50858e64c1b9b26aeecd0p-5,
+    0x1.9756f073b6b61p-5
+  },
+  { // Entry 361
+    -0x1.972bf92713d50858e64c1b9b26aeecd0p-5,
+    -0x1.9756f073b6b61p-5
+  },
+  { // Entry 362
+    0x1.976845ebe71188580e468bad00ce23ecp-5,
+    0x1.97935055cec1bp-5
+  },
+  { // Entry 363
+    -0x1.976845ebe71188580e468bad00ce23ecp-5,
+    -0x1.97935055cec1bp-5
+  },
+  { // Entry 364
+    0x1.97535cee51a42806e15f6f878524e5b7p-4,
+    0x1.980p-4
+  },
+  { // Entry 365
+    -0x1.97535cee51a42806e15f6f878524e5b7p-4,
+    -0x1.980p-4
+  },
+  { // Entry 366
+    0x1.6f494c3356177000006502cdff975b08p-1,
+    0x1.999999a42160cp-1
+  },
+  { // Entry 367
+    -0x1.6f494c3356177000006502cdff975b08p-1,
+    -0x1.999999a42160cp-1
+  },
+  { // Entry 368
+    0x1.6f494c37edd6d800006dc76aee4cc8e4p-1,
+    0x1.999999aab8f50p-1
+  },
+  { // Entry 369
+    -0x1.6f494c37edd6d800006dc76aee4cc8e4p-1,
+    -0x1.999999aab8f50p-1
+  },
+  { // Entry 370
+    0x1.6fa912bdeaab280000164f16dd649356p-1,
+    0x1.9a2324b9c6326p-1
+  },
+  { // Entry 371
+    -0x1.6fa912bdeaab280000164f16dd649356p-1,
+    -0x1.9a2324b9c6326p-1
+  },
+  { // Entry 372
+    0x1.70c7ef4ef9b347ed234ca6131be1b786p-1,
+    0x1.9bcp-1
+  },
+  { // Entry 373
+    -0x1.70c7ef4ef9b347ed234ca6131be1b786p-1,
+    -0x1.9bcp-1
+  },
+  { // Entry 374
+    0x1.ff28176ad3163ea168c9991f155f875bp-1,
+    0x1.a0d1d817d6c4ap0
+  },
+  { // Entry 375
+    -0x1.ff28176ad3163ea168c9991f155f875bp-1,
+    -0x1.a0d1d817d6c4ap0
+  },
+  { // Entry 376
+    0x1.749468a7248dd26161e93d78928c66dep-1,
+    0x1.a141c9de12fdfp-1
+  },
+  { // Entry 377
+    -0x1.749468a7248dd26161e93d78928c66dep-1,
+    -0x1.a141c9de12fdfp-1
+  },
+  { // Entry 378
+    0x1.754ebb7e73f452ab49c615f0e8300d5cp-1,
+    0x1.a251bc6766f20p-1
+  },
+  { // Entry 379
+    -0x1.754ebb7e73f452ab49c615f0e8300d5cp-1,
+    -0x1.a251bc6766f20p-1
+  },
+  { // Entry 380
+    -0x1.7c3bfefa74bd07fe21336caac372a73ep-1,
+    0x1.a2689ae1b86ddp62
+  },
+  { // Entry 381
+    0x1.7c3bfefa74bd07fe21336caac372a73ep-1,
+    -0x1.a2689ae1b86ddp62
+  },
+  { // Entry 382
+    -0x1.ffff4f3648e02f9f494f42eb822f262bp-1,
+    0x1.a3f66180c4550p100
+  },
+  { // Entry 383
+    0x1.ffff4f3648e02f9f494f42eb822f262bp-1,
+    -0x1.a3f66180c4550p100
+  },
+  { // Entry 384
+    -0x1.1cf463983c0e28023161b7d0d2938e37p-3,
+    0x1.a3fdd2a5286c3p1
+  },
+  { // Entry 385
+    0x1.1cf463983c0e28023161b7d0d2938e37p-3,
+    -0x1.a3fdd2a5286c3p1
+  },
+  { // Entry 386
+    0x1.feb7948d224d7e759a7c9dd768ded727p-1,
+    0x1.a44p0
+  },
+  { // Entry 387
+    -0x1.feb7948d224d7e759a7c9dd768ded727p-1,
+    -0x1.a44p0
+  },
+  { // Entry 388
+    0x1.78801e3e1166482dce6208e98d3cc142p-1,
+    0x1.a701ef3c7d54bp-1
+  },
+  { // Entry 389
+    -0x1.78801e3e1166482dce6208e98d3cc142p-1,
+    -0x1.a701ef3c7d54bp-1
+  },
+  { // Entry 390
+    -0x1.fff11e871d59c3e1333db5475bb57e27p-1,
+    0x1.a8c01fd43c0p537
+  },
+  { // Entry 391
+    0x1.fff11e871d59c3e1333db5475bb57e27p-1,
+    -0x1.a8c01fd43c0p537
+  },
+  { // Entry 392
+    0x1.fdfa4366eb7337e6d973c4cb8f1a244ap-1,
+    0x1.a8e29b7602f3bp0
+  },
+  { // Entry 393
+    -0x1.fdfa4366eb7337e6d973c4cb8f1a244ap-1,
+    -0x1.a8e29b7602f3bp0
+  },
+  { // Entry 394
+    0x1.fde98b94e7947a04229d26eeb2bb4280p-1,
+    0x1.a94p0
+  },
+  { // Entry 395
+    -0x1.fde98b94e7947a04229d26eeb2bb4280p-1,
+    -0x1.a94p0
+  },
+  { // Entry 396
+    0x1.7931cba10000880000068f94098018a7p-2,
+    0x1.aa445fce93b82p2
+  },
+  { // Entry 397
+    -0x1.7931cba10000880000068f94098018a7p-2,
+    -0x1.aa445fce93b82p2
+  },
+  { // Entry 398
+    0x1.7af3f76c7a708834b4072f59ac71a0bap-1,
+    0x1.aaa3fbc359fbep-1
+  },
+  { // Entry 399
+    -0x1.7af3f76c7a708834b4072f59ac71a0bap-1,
+    -0x1.aaa3fbc359fbep-1
+  },
+  { // Entry 400
+    0x1.fd74e53ae32fcd8467bcf50da1d0f563p-6,
+    0x1.abdd3dbd4d860p119
+  },
+  { // Entry 401
+    -0x1.fd74e53ae32fcd8467bcf50da1d0f563p-6,
+    -0x1.abdd3dbd4d860p119
+  },
+  { // Entry 402
+    0x1.7d4a7bf183a3329ed434c0c4dd78b1d9p-1,
+    0x1.ae2165a0c9f8ep-1
+  },
+  { // Entry 403
+    -0x1.7d4a7bf183a3329ed434c0c4dd78b1d9p-1,
+    -0x1.ae2165a0c9f8ep-1
+  },
+  { // Entry 404
+    0x1.b81410edc79e0837507a3eef8d553bd6p-2,
+    0x1.ae8dfefcfe13bp2
+  },
+  { // Entry 405
+    -0x1.b81410edc79e0837507a3eef8d553bd6p-2,
+    -0x1.ae8dfefcfe13bp2
+  },
+  { // Entry 406
+    -0x1.ff751561dc5097fefe499301d034a0edp-2,
+    0x1.b5597f950ee8cp29
+  },
+  { // Entry 407
+    0x1.ff751561dc5097fefe499301d034a0edp-2,
+    -0x1.b5597f950ee8cp29
+  },
+  { // Entry 408
+    0x1.027d184afb1984ca1d21b1ac928d5391p-52,
+    0x1.bab62ed655019p970
+  },
+  { // Entry 409
+    -0x1.027d184afb1984ca1d21b1ac928d5391p-52,
+    -0x1.bab62ed655019p970
+  },
+  { // Entry 410
+    0x1.bc572e5e413e17fcb2246d40249a005fp-10,
+    0x1.bc573c4ffffffp-10
+  },
+  { // Entry 411
+    -0x1.bc572e5e413e17fcb2246d40249a005fp-10,
+    -0x1.bc573c4ffffffp-10
+  },
+  { // Entry 412
+    0x1.fb300f1e39afe80471f993abb8cfa428p-1,
+    0x1.bef5cd25ab1adp9
+  },
+  { // Entry 413
+    -0x1.fb300f1e39afe80471f993abb8cfa428p-1,
+    -0x1.bef5cd25ab1adp9
+  },
+  { // Entry 414
+    0x1.b1baaf622d3a27fd27d0716f7d08d992p-2,
+    0x1.bfdf6df2a24c1p-2
+  },
+  { // Entry 415
+    -0x1.b1baaf622d3a27fd27d0716f7d08d992p-2,
+    -0x1.bfdf6df2a24c1p-2
+  },
+  { // Entry 416
+    0x1.88fb762c35ce37fecbb4748d01feffcep-1,
+    0x1.bfffffdffffffp-1
+  },
+  { // Entry 417
+    -0x1.88fb762c35ce37fecbb4748d01feffcep-1,
+    -0x1.bfffffdffffffp-1
+  },
+  { // Entry 418
+    0x1.fe0ebff99ab8c80ce5939f1f072c2e91p-1,
+    0x1.c2b489520e376p920
+  },
+  { // Entry 419
+    -0x1.fe0ebff99ab8c80ce5939f1f072c2e91p-1,
+    -0x1.c2b489520e376p920
+  },
+  { // Entry 420
+    0x1.cf7f749f2a8357f7feab685ff6f8b624p-4,
+    0x1.c54beb0085470p5
+  },
+  { // Entry 421
+    -0x1.cf7f749f2a8357f7feab685ff6f8b624p-4,
+    -0x1.c54beb0085470p5
+  },
+  { // Entry 422
+    0x1.b6facf665891482ea8c61f5ca32f280dp-2,
+    0x1.c5ad34f5f472ap-2
+  },
+  { // Entry 423
+    -0x1.b6facf665891482ea8c61f5ca32f280dp-2,
+    -0x1.c5ad34f5f472ap-2
+  },
+  { // Entry 424
+    0x1.b851cd9b84ee683dc6bd3899ea81dbf9p-2,
+    0x1.c728fc2f34bd6p-2
+  },
+  { // Entry 425
+    -0x1.b851cd9b84ee683dc6bd3899ea81dbf9p-2,
+    -0x1.c728fc2f34bd6p-2
+  },
+  { // Entry 426
+    0x1.ba21b53cf2ff2832606f65eeeb4e3aafp-2,
+    0x1.c92b0f6105089p-2
+  },
+  { // Entry 427
+    -0x1.ba21b53cf2ff2832606f65eeeb4e3aafp-2,
+    -0x1.c92b0f6105089p-2
+  },
+  { // Entry 428
+    0x1.c9a2b68e30ec77c4e76c889704394a50p-5,
+    0x1.c9dfbbe9ec704p-5
+  },
+  { // Entry 429
+    -0x1.c9a2b68e30ec77c4e76c889704394a50p-5,
+    -0x1.c9dfbbe9ec704p-5
+  },
+  { // Entry 430
+    0x1.f370115c9ab35743e12217c6122e1a28p-1,
+    0x1.caf31bd7ee217p0
+  },
+  { // Entry 431
+    -0x1.f370115c9ab35743e12217c6122e1a28p-1,
+    -0x1.caf31bd7ee217p0
+  },
+  { // Entry 432
+    -0x1.dd38a1f1d289b6173115721bc58e298dp-54,
+    0x1.cb44e86bc192bp648
+  },
+  { // Entry 433
+    0x1.dd38a1f1d289b6173115721bc58e298dp-54,
+    -0x1.cb44e86bc192bp648
+  },
+  { // Entry 434
+    0x1.dd38a1f1d289b6173115721bc55a56a8p-53,
+    0x1.cb44e86bc192bp649
+  },
+  { // Entry 435
+    -0x1.dd38a1f1d289b6173115721bc55a56a8p-53,
+    -0x1.cb44e86bc192bp649
+  },
+  { // Entry 436
+    0x1.c7885aef33a94ffc5ae06be9444efad5p-3,
+    0x1.cb6p-3
+  },
+  { // Entry 437
+    -0x1.c7885aef33a94ffc5ae06be9444efad5p-3,
+    -0x1.cb6p-3
+  },
+  { // Entry 438
+    0x1.cd279aa6196b57f9be71cdffdd9f1919p-4,
+    0x1.ce2271d2f662fp-4
+  },
+  { // Entry 439
+    -0x1.cd279aa6196b57f9be71cdffdd9f1919p-4,
+    -0x1.ce2271d2f662fp-4
+  },
+  { // Entry 440
+    0x1.930b705f9fad17fb56813a45973a8d72p-1,
+    0x1.d0000000004p-1
+  },
+  { // Entry 441
+    -0x1.930b705f9fad17fb56813a45973a8d72p-1,
+    -0x1.d0000000004p-1
+  },
+  { // Entry 442
+    0x1.7ef24c8e67d9a8017a031f38e24cce06p-1,
+    0x1.d01p199
+  },
+  { // Entry 443
+    -0x1.7ef24c8e67d9a8017a031f38e24cce06p-1,
+    -0x1.d01p199
+  },
+  { // Entry 444
+    0x1.ffff124c001aafb1f175ccb531c053b0p-1,
+    0x1.d024ba6f953cfp1000
+  },
+  { // Entry 445
+    -0x1.ffff124c001aafb1f175ccb531c053b0p-1,
+    -0x1.d024ba6f953cfp1000
+  },
+  { // Entry 446
+    -0x1.f83a0983dd15d00301e2df21e3bee635p-2,
+    0x1.d4067c60f471ep1
+  },
+  { // Entry 447
+    0x1.f83a0983dd15d00301e2df21e3bee635p-2,
+    -0x1.d4067c60f471ep1
+  },
+  { // Entry 448
+    0x1.d79b9896ff55484d2591b677d54ea46fp-5,
+    0x1.d7de6263bcaabp-5
+  },
+  { // Entry 449
+    -0x1.d79b9896ff55484d2591b677d54ea46fp-5,
+    -0x1.d7de6263bcaabp-5
+  },
+  { // Entry 450
+    0x1.ed0b908a2982f7fd9c80bc1051dd4080p-1,
+    0x1.d800000002274p0
+  },
+  { // Entry 451
+    -0x1.ed0b908a2982f7fd9c80bc1051dd4080p-1,
+    -0x1.d800000002274p0
+  },
+  { // Entry 452
+    -0x1.f2c217cbc7dcc919243a7c434a209f9ap-1,
+    0x1.d96e058p488
+  },
+  { // Entry 453
+    0x1.f2c217cbc7dcc919243a7c434a209f9ap-1,
+    -0x1.d96e058p488
+  },
+  { // Entry 454
+    0x1.98dcd093377928000000000000167dc7p-1,
+    0x1.d98c4c612718dp-1
+  },
+  { // Entry 455
+    -0x1.98dcd093377928000000000000167dc7p-1,
+    -0x1.d98c4c612718dp-1
+  },
+  { // Entry 456
+    0x1.db3ba8775ca257da3bd5449d396a66e2p-5,
+    0x1.db8p-5
+  },
+  { // Entry 457
+    -0x1.db3ba8775ca257da3bd5449d396a66e2p-5,
+    -0x1.db8p-5
+  },
+  { // Entry 458
+    -0x1.9fee37697d5828031a6a2679c1433457p-2,
+    0x1.de386d6090303p200
+  },
+  { // Entry 459
+    0x1.9fee37697d5828031a6a2679c1433457p-2,
+    -0x1.de386d6090303p200
+  },
+  { // Entry 460
+    -0x1.5361ee6553188036e9dfcab428deb4e1p-53,
+    0x1.de5e5054e921bp35
+  },
+  { // Entry 461
+    0x1.5361ee6553188036e9dfcab428deb4e1p-53,
+    -0x1.de5e5054e921bp35
+  },
+  { // Entry 462
+    0x1.fec48d5e769ebe37448c10e0a7a0ecb1p-1,
+    0x1.df77ddf77ddf4p10
+  },
+  { // Entry 463
+    -0x1.fec48d5e769ebe37448c10e0a7a0ecb1p-1,
+    -0x1.df77ddf77ddf4p10
+  },
+  { // Entry 464
+    -0x1.2902a83d72632800003d1149b7e6c0fbp-1,
+    0x1.e1562b0448a86p1
+  },
+  { // Entry 465
+    0x1.2902a83d72632800003d1149b7e6c0fbp-1,
+    -0x1.e1562b0448a86p1
+  },
+  { // Entry 466
+    0x1.9e26c7bc96b68800000d4736ff132035p-1,
+    0x1.e2700cdc86635p-1
+  },
+  { // Entry 467
+    -0x1.9e26c7bc96b68800000d4736ff132035p-1,
+    -0x1.e2700cdc86635p-1
+  },
+  { // Entry 468
+    0x1.e6494911eedd18d0f1915fd4f6495469p-7,
+    0x1.e64ddaf7bd730p-7
+  },
+  { // Entry 469
+    -0x1.e6494911eedd18d0f1915fd4f6495469p-7,
+    -0x1.e64ddaf7bd730p-7
+  },
+  { // Entry 470
+    0x1.eb26c690bda2484a6c020a9c052ea846p-5,
+    0x1.eb7239bca8afap-5
+  },
+  { // Entry 471
+    -0x1.eb26c690bda2484a6c020a9c052ea846p-5,
+    -0x1.eb7239bca8afap-5
+  },
+  { // Entry 472
+    0x1.c73238790a4ce801e04107b2546b4ae3p-3,
+    0x1.ef7b83f7bdef4p3
+  },
+  { // Entry 473
+    -0x1.c73238790a4ce801e04107b2546b4ae3p-3,
+    -0x1.ef7b83f7bdef4p3
+  },
+  { // Entry 474
+    0x1.ed1b575acb8c881082ce315074a8a42ap-3,
+    0x1.f20000000109bp-3
+  },
+  { // Entry 475
+    -0x1.ed1b575acb8c881082ce315074a8a42ap-3,
+    -0x1.f20000000109bp-3
+  },
+  { // Entry 476
+    0x1.c1b50a56c8809800000282a516c13e25p-1,
+    0x1.f40ca67a9e8d7p9
+  },
+  { // Entry 477
+    -0x1.c1b50a56c8809800000282a516c13e25p-1,
+    -0x1.f40ca67a9e8d7p9
+  },
+  { // Entry 478
+    0x1.e321fea643a968083208768e9e2cd28ep-2,
+    0x1.f7224d2c77540p-2
+  },
+  { // Entry 479
+    -0x1.e321fea643a968083208768e9e2cd28ep-2,
+    -0x1.f7224d2c77540p-2
+  },
+  { // Entry 480
+    0x1.c1269b020a107ffc00612a563a919686p-3,
+    0x1.f78a0d05e60e2p6
+  },
+  { // Entry 481
+    -0x1.c1269b020a107ffc00612a563a919686p-3,
+    -0x1.f78a0d05e60e2p6
+  },
+  { // Entry 482
+    0x1.f76cae28a07747fffcd453a0142c2ec1p-5,
+    0x1.f7bdef7bdf073p-5
+  },
+  { // Entry 483
+    -0x1.f76cae28a07747fffcd453a0142c2ec1p-5,
+    -0x1.f7bdef7bdf073p-5
+  },
+  { // Entry 484
+    0x1.e42c139dc2053807b9440f1a28f7c9b9p-2,
+    0x1.f8502d5955443p-2
+  },
+  { // Entry 485
+    -0x1.e42c139dc2053807b9440f1a28f7c9b9p-2,
+    -0x1.f8502d5955443p-2
+  },
+  { // Entry 486
+    0x1.0fa749e07f63fc9d01c834de47654acbp-9,
+    0x1.f8fc824d2693bp61
+  },
+  { // Entry 487
+    -0x1.0fa749e07f63fc9d01c834de47654acbp-9,
+    -0x1.f8fc824d2693bp61
+  },
+  { // Entry 488
+    0x1.ffa80324e2d8ebc02f323ed49eb97a6cp-1,
+    0x1.f8fffffffffffp2
+  },
+  { // Entry 489
+    -0x1.ffa80324e2d8ebc02f323ed49eb97a6cp-1,
+    -0x1.f8fffffffffffp2
+  },
+  { // Entry 490
+    -0x1.7cdf79d5e37b8b212eff86d2ffe2044bp-1,
+    0x1.fd8p1
+  },
+  { // Entry 491
+    0x1.7cdf79d5e37b8b212eff86d2ffe2044bp-1,
+    -0x1.fd8p1
+  },
+  { // Entry 492
+    0x1.fd3f48847a1d10a8e5ff1d4db84ed26dp-5,
+    0x1.fd9364d936596p-5
+  },
+  { // Entry 493
+    -0x1.fd3f48847a1d10a8e5ff1d4db84ed26dp-5,
+    -0x1.fd9364d936596p-5
+  },
+  { // Entry 494
+    0x1.f93ad471d262f8032e92d596797f9d41p-3,
+    0x1.fe8p-3
+  },
+  { // Entry 495
+    -0x1.f93ad471d262f8032e92d596797f9d41p-3,
+    -0x1.fe8p-3
+  },
+  { // Entry 496
+    0x1.83b3062414973d92c4278507f0474d67p-1,
+    0x1.febb646e2ee57p13
+  },
+  { // Entry 497
+    -0x1.83b3062414973d92c4278507f0474d67p-1,
+    -0x1.febb646e2ee57p13
+  },
+  { // Entry 498
+    0x1.3b45bd744977547fa4673e42dfc99402p-1,
+    0x1.feeffffffffc6p995
+  },
+  { // Entry 499
+    -0x1.3b45bd744977547fa4673e42dfc99402p-1,
+    -0x1.feeffffffffc6p995
+  },
+  { // Entry 500
+    -0x1.eefb59d143645a40041bf726dc6f2fa0p-1,
+    0x1.ff8ffffffffffp7
+  },
+  { // Entry 501
+    0x1.eefb59d143645a40041bf726dc6f2fa0p-1,
+    -0x1.ff8ffffffffffp7
+  },
+  { // Entry 502
+    -0x1.56433f0c6bcee9848751611c6f5ade1fp-1,
+    0x1.ff8ffffffffffp870
+  },
+  { // Entry 503
+    0x1.56433f0c6bcee9848751611c6f5ade1fp-1,
+    -0x1.ff8ffffffffffp870
+  },
+  { // Entry 504
+    -0x1.930006246a6c05dab72ea697daaba69dp-2,
+    0x1.ffcfff8p19
+  },
+  { // Entry 505
+    0x1.930006246a6c05dab72ea697daaba69dp-2,
+    -0x1.ffcfff8p19
+  },
+  { // Entry 506
+    0x1.ded37a1f0aa6d05d782d6aab40cb8670p-1,
+    0x1.ffcfff8p365
+  },
+  { // Entry 507
+    -0x1.ded37a1f0aa6d05d782d6aab40cb8670p-1,
+    -0x1.ffcfff8p365
+  },
+  { // Entry 508
+    -0x1.93e4d96b621e07bca866c1a2e771881cp-1,
+    0x1.ffcffffffff6cp720
+  },
+  { // Entry 509
+    0x1.93e4d96b621e07bca866c1a2e771881cp-1,
+    -0x1.ffcffffffff6cp720
+  },
+  { // Entry 510
+    0x1.9068b90e42605e05010e147110688e52p-1,
+    0x1.ffcfffffffff9p320
+  },
+  { // Entry 511
+    -0x1.9068b90e42605e05010e147110688e52p-1,
+    -0x1.ffcfffffffff9p320
+  },
+  { // Entry 512
+    0x1.cf81642e7421c56507eb8187611c84dbp-1,
+    0x1.ffcffffffffffp12
+  },
+  { // Entry 513
+    -0x1.cf81642e7421c56507eb8187611c84dbp-1,
+    -0x1.ffcffffffffffp12
+  },
+  { // Entry 514
+    0x1.ffffffe61fe616b282c3a69ca225c2d2p-1,
+    0x1.ffcffffffffffp404
+  },
+  { // Entry 515
+    -0x1.ffffffe61fe616b282c3a69ca225c2d2p-1,
+    -0x1.ffcffffffffffp404
+  },
+  { // Entry 516
+    -0x1.406ee9ae91e16f1d58c96eb7165f595bp-1,
+    0x1.ffeffffffffccp995
+  },
+  { // Entry 517
+    0x1.406ee9ae91e16f1d58c96eb7165f595bp-1,
+    -0x1.ffeffffffffccp995
+  },
+  { // Entry 518
+    0x1.fa9f6ca0ec44e0010026f385c0ab8690p-3,
+    0x1.ffeffffffffffp-3
+  },
+  { // Entry 519
+    -0x1.fa9f6ca0ec44e0010026f385c0ab8690p-3,
+    -0x1.ffeffffffffffp-3
+  },
+  { // Entry 520
+    0x1.6b491db8b66d880121f830d8c755ae54p-4,
+    0x1.ffeffffffffffp55
+  },
+  { // Entry 521
+    -0x1.6b491db8b66d880121f830d8c755ae54p-4,
+    -0x1.ffeffffffffffp55
+  },
+  { // Entry 522
+    0x1.fb0ab102cb12fef9a4e4a869a299ed46p-1,
+    0x1.ffeffffffffffp180
+  },
+  { // Entry 523
+    -0x1.fb0ab102cb12fef9a4e4a869a299ed46p-1,
+    -0x1.ffeffffffffffp180
+  },
+  { // Entry 524
+    0x1.e4315ec04635cd34b3ef60370511281fp-3,
+    0x1.ffeffffffffffp706
+  },
+  { // Entry 525
+    -0x1.e4315ec04635cd34b3ef60370511281fp-3,
+    -0x1.ffeffffffffffp706
+  },
+  { // Entry 526
+    0x1.ffffc39997ef67d2b9c7e4efa8b77e50p-1,
+    0x1.fff1fffffffffp41
+  },
+  { // Entry 527
+    -0x1.ffffc39997ef67d2b9c7e4efa8b77e50p-1,
+    -0x1.fff1fffffffffp41
+  },
+  { // Entry 528
+    0x1.fff163992831e8c68b0234b42efa1d0ap-7,
+    0x1.fff6b89ffffffp-7
+  },
+  { // Entry 529
+    -0x1.fff163992831e8c68b0234b42efa1d0ap-7,
+    -0x1.fff6b89ffffffp-7
+  },
+  { // Entry 530
+    -0x1.d9757a05fcc42c664f3a66b5576a98e4p-1,
+    0x1.fffdffff0001fp105
+  },
+  { // Entry 531
+    0x1.d9757a05fcc42c664f3a66b5576a98e4p-1,
+    -0x1.fffdffff0001fp105
+  },
+  { // Entry 532
+    -0x1.83791fe63a17a80258f2c479c7e1d339p-1,
+    0x1.ffff0c0000002p1
+  },
+  { // Entry 533
+    0x1.83791fe63a17a80258f2c479c7e1d339p-1,
+    -0x1.ffff0c0000002p1
+  },
+  { // Entry 534
+    -0x1.d9d3a85acc50c8000005d13dd82f61b5p-1,
+    0x1.ffffc00000055p150
+  },
+  { // Entry 535
+    0x1.d9d3a85acc50c8000005d13dd82f61b5p-1,
+    -0x1.ffffc00000055p150
+  },
+  { // Entry 536
+    -0x1.f25d858dcdee7412cf0760e955cb8390p-3,
+    0x1.ffffe3fffffffp40
+  },
+  { // Entry 537
+    0x1.f25d858dcdee7412cf0760e955cb8390p-3,
+    -0x1.ffffe3fffffffp40
+  },
+  { // Entry 538
+    0x1.d18f7bfe557eb80001557142bda18baep-1,
+    0x1.ffffefffcffaep0
+  },
+  { // Entry 539
+    -0x1.d18f7bfe557eb80001557142bda18baep-1,
+    -0x1.ffffefffcffaep0
+  },
+  { // Entry 540
+    -0x1.bc14ebf6bfb51ffa5e6f5b0b0bf9e899p-4,
+    0x1.fffffbfffffffp228
+  },
+  { // Entry 541
+    0x1.bc14ebf6bfb51ffa5e6f5b0b0bf9e899p-4,
+    -0x1.fffffbfffffffp228
+  },
+  { // Entry 542
+    0x1.bb887a06f6c50fef0654d303c82f1a78p-3,
+    0x1.fffffbfffffffp735
+  },
+  { // Entry 543
+    -0x1.bb887a06f6c50fef0654d303c82f1a78p-3,
+    -0x1.fffffbfffffffp735
+  },
+  { // Entry 544
+    0x1.ffaaadef54e2f0c4081880b7b9e794dfp-5,
+    0x1.fffffefffffffp-5
+  },
+  { // Entry 545
+    -0x1.ffaaadef54e2f0c4081880b7b9e794dfp-5,
+    -0x1.fffffefffffffp-5
+  },
+  { // Entry 546
+    0x1.d4a3c62c5be08b123868e8a467eff0cep-1,
+    0x1.ffffff8p119
+  },
+  { // Entry 547
+    -0x1.d4a3c62c5be08b123868e8a467eff0cep-1,
+    -0x1.ffffff8p119
+  },
+  { // Entry 548
+    0x1.cec20f197703f4fd42048ddf889fe84ap-3,
+    0x1.ffffff8p192
+  },
+  { // Entry 549
+    -0x1.cec20f197703f4fd42048ddf889fe84ap-3,
+    -0x1.ffffff8p192
+  },
+  { // Entry 550
+    0x1.d37aadc7c8662501751dbf4e9e5701abp-2,
+    0x1.ffffff8p543
+  },
+  { // Entry 551
+    -0x1.d37aadc7c8662501751dbf4e9e5701abp-2,
+    -0x1.ffffff8p543
+  },
+  { // Entry 552
+    0x1.fa8d2a4d0a2027f0f74df3136cb78f72p-1,
+    0x1.ffffffc0018ffp2
+  },
+  { // Entry 553
+    -0x1.fa8d2a4d0a2027f0f74df3136cb78f72p-1,
+    -0x1.ffffffc0018ffp2
+  },
+  { // Entry 554
+    0x1.fa8d2a029f977ffe74cb14cb09df176dp-1,
+    0x1.ffffffffeffffp2
+  },
+  { // Entry 555
+    -0x1.fa8d2a029f977ffe74cb14cb09df176dp-1,
+    -0x1.ffffffffeffffp2
+  },
+  { // Entry 556
+    -0x1.2763f02a2d1e980000015dbf95d89ab2p-4,
+    0x1.fffffffff8250p943
+  },
+  { // Entry 557
+    0x1.2763f02a2d1e980000015dbf95d89ab2p-4,
+    -0x1.fffffffff8250p943
+  },
+  { // Entry 558
+    0x1.fcff128f77dda81c2a0ec03e4ed80422p-1,
+    0x1.fffffffffe09dp320
+  },
+  { // Entry 559
+    -0x1.fcff128f77dda81c2a0ec03e4ed80422p-1,
+    -0x1.fffffffffe09dp320
+  },
+  { // Entry 560
+    -0x1.fcc0bfedd84a5816d9596b8f9fbb9b41p-1,
+    0x1.fffffffffe6e3p720
+  },
+  { // Entry 561
+    0x1.fcc0bfedd84a5816d9596b8f9fbb9b41p-1,
+    -0x1.fffffffffe6e3p720
+  },
+  { // Entry 562
+    0x1.aed548f090c1dffe6e04322dc8e8cbfap-1,
+    0x1.ffffffffffe7fp-1
+  },
+  { // Entry 563
+    -0x1.aed548f090c1dffe6e04322dc8e8cbfap-1,
+    -0x1.ffffffffffe7fp-1
+  },
+  { // Entry 564
+    -0x1.f5e11def99d2b22098242ac9fb756adbp-1,
+    0x1.ffffffffffeffp250
+  },
+  { // Entry 565
+    0x1.f5e11def99d2b22098242ac9fb756adbp-1,
+    -0x1.ffffffffffeffp250
+  },
+  { // Entry 566
+    0x1.8a9cbf48fec9f2a0fde951f313b918ccp-1,
+    0x1.fffffffffff78p920
+  },
+  { // Entry 567
+    -0x1.8a9cbf48fec9f2a0fde951f313b918ccp-1,
+    -0x1.fffffffffff78p920
+  },
+  { // Entry 568
+    -0x1.7eba5894844cc00c88f39bd3d4197d14p-3,
+    0x1.fffffffffff83p150
+  },
+  { // Entry 569
+    0x1.7eba5894844cc00c88f39bd3d4197d14p-3,
+    -0x1.fffffffffff83p150
+  },
+  { // Entry 570
+    0x1.92c4f06d2cdd15d302609caa87882afap-1,
+    0x1.fffffffffffd5p995
+  },
+  { // Entry 571
+    -0x1.92c4f06d2cdd15d302609caa87882afap-1,
+    -0x1.fffffffffffd5p995
+  },
+  { // Entry 572
+    -0x1.3d5f7deb1d3bad63eb173b73e84110a0p-1,
+    0x1.fffffffffffe8p720
+  },
+  { // Entry 573
+    0x1.3d5f7deb1d3bad63eb173b73e84110a0p-1,
+    -0x1.fffffffffffe8p720
+  },
+  { // Entry 574
+    -0x1.91349b0ae90e5316539c07eea9b4e6b0p-1,
+    0x1.fffffffffffebp920
+  },
+  { // Entry 575
+    0x1.91349b0ae90e5316539c07eea9b4e6b0p-1,
+    -0x1.fffffffffffebp920
+  },
+  { // Entry 576
+    -0x1.837b9dddc1e8738d74b2a74fa42d802dp-1,
+    0x1.ffffffffffff1p1
+  },
+  { // Entry 577
+    0x1.837b9dddc1e8738d74b2a74fa42d802dp-1,
+    -0x1.ffffffffffff1p1
+  },
+  { // Entry 578
+    0x1.510e062e7fa2037d3842de993c9c5090p-1,
+    0x1.ffffffffffff1p245
+  },
+  { // Entry 579
+    -0x1.510e062e7fa2037d3842de993c9c5090p-1,
+    -0x1.ffffffffffff1p245
+  },
+  { // Entry 580
+    0x1.eaee8744b05e47fde092e3a14895d067p-2,
+    0x1.ffffffffffff3p-2
+  },
+  { // Entry 581
+    -0x1.eaee8744b05e47fde092e3a14895d067p-2,
+    -0x1.ffffffffffff3p-2
+  },
+  { // Entry 582
+    0x1.8a4dee8f4062791078766b0a01de360dp-1,
+    0x1.ffffffffffff4p845
+  },
+  { // Entry 583
+    -0x1.8a4dee8f4062791078766b0a01de360dp-1,
+    -0x1.ffffffffffff4p845
+  },
+  { // Entry 584
+    0x1.5118d6bbde07e4eebf2a11df4dc74d54p-1,
+    0x1.ffffffffffff4p1020
+  },
+  { // Entry 585
+    -0x1.5118d6bbde07e4eebf2a11df4dc74d54p-1,
+    -0x1.ffffffffffff4p1020
+  },
+  { // Entry 586
+    -0x1.5cd5c53cf30a97ff0e471d149c40955dp-1,
+    0x1.ffffffffffff8p616
+  },
+  { // Entry 587
+    0x1.5cd5c53cf30a97ff0e471d149c40955dp-1,
+    -0x1.ffffffffffff8p616
+  },
+  { // Entry 588
+    0x1.ffffa1f0d7daf693a80a2b817b16f277p-1,
+    0x1.ffffffffffffcp475
+  },
+  { // Entry 589
+    -0x1.ffffa1f0d7daf693a80a2b817b16f277p-1,
+    -0x1.ffffffffffffcp475
+  },
+  { // Entry 590
+    0x1.51e9d840106d73484d44a86f74c3d41dp-1,
+    0x1.ffffffffffffep970
+  },
+  { // Entry 591
+    -0x1.51e9d840106d73484d44a86f74c3d41dp-1,
+    -0x1.ffffffffffffep970
+  },
+  { // Entry 592
+    -0.0,
+    -0x1.0p-1074
+  },
+  { // Entry 593
+    0.0,
+    0x1.0p-1074
+  },
+  { // Entry 594
+    -0.0,
+    -0.0
+  },
+  { // Entry 595
+    0.0,
+    0x1.0p-1074
+  },
+  { // Entry 596
+    -0.0,
+    -0x1.0p-1074
+  },
+  { // Entry 597
+    -0x1.0000000000000fffffffffffffffffffp-1022,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 598
+    0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 599
+    -0x1.ffffffffffffffffffffffffffffffffp-1023,
+    -0x1.0p-1022
+  },
+  { // Entry 600
+    0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.0p-1022
+  },
+  { // Entry 601
+    -0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 602
+    0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 603
+    0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 604
+    -0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 605
+    0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.0p-1022
+  },
+  { // Entry 606
+    -0x1.ffffffffffffffffffffffffffffffffp-1023,
+    -0x1.0p-1022
+  },
+  { // Entry 607
+    0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 608
+    -0x1.0000000000000fffffffffffffffffffp-1022,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 609
+    0x1.9999996de8ca198c24ab9449beee16d5p-13,
+    0x1.999999999999ap-13
+  },
+  { // Entry 610
+    -0x1.9999996de8ca198c24ab9449beee16d5p-13,
+    -0x1.999999999999ap-13
+  },
+  { // Entry 611
+    0x1.999998ead65b96f78a4dbfd839c7ef2ep-12,
+    0x1.999999999999ap-12
+  },
+  { // Entry 612
+    -0x1.999998ead65b96f78a4dbfd839c7ef2ep-12,
+    -0x1.999999999999ap-12
+  },
+  { // Entry 613
+    0x1.3333320c49babff151b6d04290e2c3a2p-11,
+    0x1.3333333333334p-11
+  },
+  { // Entry 614
+    -0x1.3333320c49babff151b6d04290e2c3a2p-11,
+    -0x1.3333333333334p-11
+  },
+  { // Entry 615
+    0x1.999996de8ca2884da2f08f25bb024d08p-11,
+    0x1.999999999999ap-11
+  },
+  { // Entry 616
+    -0x1.999996de8ca2884da2f08f25bb024d08p-11,
+    -0x1.999999999999ap-11
+  },
+  { // Entry 617
+    0x1.fffffaaaaaaeeeeeed4ed4edab4c7bd6p-11,
+    0x1.0p-10
+  },
+  { // Entry 618
+    -0x1.fffffaaaaaaeeeeeed4ed4edab4c7bd6p-11,
+    -0x1.0p-10
+  },
+  { // Entry 619
+    0x1.33332e978d552afc883bdb04751e3835p-10,
+    0x1.3333333333333p-10
+  },
+  { // Entry 620
+    -0x1.33332e978d552afc883bdb04751e3835p-10,
+    -0x1.3333333333333p-10
+  },
+  { // Entry 621
+    0x1.66665f1529aff8a3809246670a436c3cp-10,
+    0x1.6666666666666p-10
+  },
+  { // Entry 622
+    -0x1.66665f1529aff8a3809246670a436c3cp-10,
+    -0x1.6666666666666p-10
+  },
+  { // Entry 623
+    0x1.99998ead65cdf82e194c133997f2fb68p-10,
+    0x1.9999999999999p-10
+  },
+  { // Entry 624
+    -0x1.99998ead65cdf82e194c133997f2fb68p-10,
+    -0x1.9999999999999p-10
+  },
+  { // Entry 625
+    0x1.ccccbd3f7d15d42affb9f02bf1dc257bp-10,
+    0x1.cccccccccccccp-10
+  },
+  { // Entry 626
+    -0x1.ccccbd3f7d15d42affb9f02bf1dc257bp-10,
+    -0x1.cccccccccccccp-10
+  },
+  { // Entry 627
+    0x1.0665ae9c7b44ed280216be2104f28f02p-7,
+    0x1.0666666666666p-7
+  },
+  { // Entry 628
+    -0x1.0665ae9c7b44ed280216be2104f28f02p-7,
+    -0x1.0666666666666p-7
+  },
+  { // Entry 629
+    0x1.ccc8e97b59f618898c4ac3a0aeddf709p-7,
+    0x1.cccccccccccccp-7
+  },
+  { // Entry 630
+    -0x1.ccc8e97b59f618898c4ac3a0aeddf709p-7,
+    -0x1.cccccccccccccp-7
+  },
+  { // Entry 631
+    0x1.4993e8a8ff79b132046efa7856a97538p-6,
+    0x1.4999999999999p-6
+  },
+  { // Entry 632
+    -0x1.4993e8a8ff79b132046efa7856a97538p-6,
+    -0x1.4999999999999p-6
+  },
+  { // Entry 633
+    0x1.acc044c56db0e19f82c9c3cff246e201p-6,
+    0x1.accccccccccccp-6
+  },
+  { // Entry 634
+    -0x1.acc044c56db0e19f82c9c3cff246e201p-6,
+    -0x1.accccccccccccp-6
+  },
+  { // Entry 635
+    0x1.07f44d67cf41afbc0c95108b99f91b01p-5,
+    0x1.080p-5
+  },
+  { // Entry 636
+    -0x1.07f44d67cf41afbc0c95108b99f91b01p-5,
+    -0x1.080p-5
+  },
+  { // Entry 637
+    0x1.3985fe46f1c8714eaa1418561963e89bp-5,
+    0x1.399999999999ap-5
+  },
+  { // Entry 638
+    -0x1.3985fe46f1c8714eaa1418561963e89bp-5,
+    -0x1.399999999999ap-5
+  },
+  { // Entry 639
+    0x1.6b14bde93ac5f7d24544d0ecf8be7aeep-5,
+    0x1.6b33333333334p-5
+  },
+  { // Entry 640
+    -0x1.6b14bde93ac5f7d24544d0ecf8be7aeep-5,
+    -0x1.6b33333333334p-5
+  },
+  { // Entry 641
+    0x1.9ca0153ed8396b02f8605219a5fe5917p-5,
+    0x1.9cccccccccccep-5
+  },
+  { // Entry 642
+    -0x1.9ca0153ed8396b02f8605219a5fe5917p-5,
+    -0x1.9cccccccccccep-5
+  },
+  { // Entry 643
+    0x1.ce278d4027d34387f184d4ab2aaf545fp-5,
+    0x1.ce66666666666p-5
+  },
+  { // Entry 644
+    -0x1.ce278d4027d34387f184d4ab2aaf545fp-5,
+    -0x1.ce66666666666p-5
+  },
+  { // Entry 645
+    0x1.43c1e9c171a667a0b92519a04fa5a91cp-1,
+    0x1.5e7fc4369bdadp-1
+  },
+  { // Entry 646
+    -0x1.43c1e9c171a667a0b92519a04fa5a91cp-1,
+    -0x1.5e7fc4369bdadp-1
+  },
+  { // Entry 647
+    0x1.ee3d6bcea09ca18b1d1ce7ee04fd886fp-1,
+    0x1.4e7fc4369bdadp0
+  },
+  { // Entry 648
+    -0x1.ee3d6bcea09ca18b1d1ce7ee04fd886fp-1,
+    -0x1.4e7fc4369bdadp0
+  },
+  { // Entry 649
+    0x1.df8e22ea809d65c6a69b96aca60be432p-1,
+    0x1.edbfa651e9c84p0
+  },
+  { // Entry 650
+    -0x1.df8e22ea809d65c6a69b96aca60be432p-1,
+    -0x1.edbfa651e9c84p0
+  },
+  { // Entry 651
+    0x1.1d3479eac7ae35e2fbea0ae696434692p-1,
+    0x1.467fc4369bdadp1
+  },
+  { // Entry 652
+    -0x1.1d3479eac7ae35e2fbea0ae696434692p-1,
+    -0x1.467fc4369bdadp1
+  },
+  { // Entry 653
+    -0x1.ffeaaaeeee84b44ccefef832254d28c0p-6,
+    0x1.961fb54442d18p1
+  },
+  { // Entry 654
+    0x1.ffeaaaeeee84b44ccefef832254d28c0p-6,
+    -0x1.961fb54442d18p1
+  },
+  { // Entry 655
+    -0x1.3734d32d49bd0b942772a7567d514140p-1,
+    0x1.e5bfa651e9c83p1
+  },
+  { // Entry 656
+    0x1.3734d32d49bd0b942772a7567d514140p-1,
+    -0x1.e5bfa651e9c83p1
+  },
+  { // Entry 657
+    -0x1.e9d25d19911e205b653521f42b9b864fp-1,
+    0x1.1aafcbafc85f7p2
+  },
+  { // Entry 658
+    0x1.e9d25d19911e205b653521f42b9b864fp-1,
+    -0x1.1aafcbafc85f7p2
+  },
+  { // Entry 659
+    -0x1.e4ecdc5a4e465899928eb9fc95829d48p-1,
+    0x1.427fc4369bdadp2
+  },
+  { // Entry 660
+    0x1.e4ecdc5a4e465899928eb9fc95829d48p-1,
+    -0x1.427fc4369bdadp2
+  },
+  { // Entry 661
+    -0x1.2a59f1034426197fa6eee22762967f25p-1,
+    0x1.6a4fbcbd6f562p2
+  },
+  { // Entry 662
+    0x1.2a59f1034426197fa6eee22762967f25p-1,
+    -0x1.6a4fbcbd6f562p2
+  },
+  { // Entry 663
+    -0x1.26312443bd35f19312eac0a1a6b5659ep-1,
+    0x1.6af2eff0a2896p2
+  },
+  { // Entry 664
+    0x1.26312443bd35f19312eac0a1a6b5659ep-1,
+    -0x1.6af2eff0a2896p2
+  },
+  { // Entry 665
+    -0x1.e18e660a5e2fb316ecbb9ed70122eff5p-1,
+    0x1.43c62a9d02414p2
+  },
+  { // Entry 666
+    0x1.e18e660a5e2fb316ecbb9ed70122eff5p-1,
+    -0x1.43c62a9d02414p2
+  },
+  { // Entry 667
+    -0x1.ee0e83a0198b6e2ef7c48e6625291a0ap-1,
+    0x1.1c99654961f92p2
+  },
+  { // Entry 668
+    0x1.ee0e83a0198b6e2ef7c48e6625291a0ap-1,
+    -0x1.1c99654961f92p2
+  },
+  { // Entry 669
+    -0x1.4727747338e4653616eadbd7ec3d02d3p-1,
+    0x1.ead93feb8361fp1
+  },
+  { // Entry 670
+    0x1.4727747338e4653616eadbd7ec3d02d3p-1,
+    -0x1.ead93feb8361fp1
+  },
+  { // Entry 671
+    -0x1.4ba2f75dda5fe434320905a7184ff1afp-4,
+    0x1.9c7fb54442d1ap1
+  },
+  { // Entry 672
+    0x1.4ba2f75dda5fe434320905a7184ff1afp-4,
+    -0x1.9c7fb54442d1ap1
+  },
+  { // Entry 673
+    0x1.034c4d633b4ef0a9089b43892a462a26p-1,
+    0x1.4e262a9d02415p1
+  },
+  { // Entry 674
+    -0x1.034c4d633b4ef0a9089b43892a462a26p-1,
+    -0x1.4e262a9d02415p1
+  },
+  { // Entry 675
+    0x1.d1e4cde2f3944f4c134c05cc4e5339a3p-1,
+    0x1.ff993feb83620p0
+  },
+  { // Entry 676
+    -0x1.d1e4cde2f3944f4c134c05cc4e5339a3p-1,
+    -0x1.ff993feb83620p0
+  },
+  { // Entry 677
+    0x1.f750235c949926c48c90e41a91474c06p-1,
+    0x1.62e62a9d02416p0
+  },
+  { // Entry 678
+    -0x1.f750235c949926c48c90e41a91474c06p-1,
+    -0x1.62e62a9d02416p0
+  },
+  { // Entry 679
+    0x1.65f7d571279b0b8005552fd47a2e77aep-1,
+    0x1.8c662a9d02419p-1
+  },
+  { // Entry 680
+    -0x1.65f7d571279b0b8005552fd47a2e77aep-1,
+    -0x1.8c662a9d02419p-1
+  },
+  { // Entry 681
+    -0x1.fe043f57369d6a52fa33f0119ec4da19p-1,
+    -0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 682
+    0x1.fe043f57369d6a52fa33f0119ec4da19p-1,
+    0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 683
+    -0x1.fff18f24f3e4b87bf8c3762cb44f46d6p-1,
+    -0x1.95ec8b9e03d54p0
+  },
+  { // Entry 684
+    0x1.fff18f24f3e4b87bf8c3762cb44f46d6p-1,
+    0x1.95ec8b9e03d54p0
+  },
+  { // Entry 685
+    -0x1.ff20d961624e7063a78203b811f579cap-1,
+    -0x1.832efa2a435a9p0
+  },
+  { // Entry 686
+    0x1.ff20d961624e7063a78203b811f579cap-1,
+    0x1.832efa2a435a9p0
+  },
+  { // Entry 687
+    -0x1.fb933c40107fd775185ac14918c8fbafp-1,
+    -0x1.707168b682dfep0
+  },
+  { // Entry 688
+    0x1.fb933c40107fd775185ac14918c8fbafp-1,
+    0x1.707168b682dfep0
+  },
+  { // Entry 689
+    -0x1.f54d971881ad685b782ef88e6350f7cdp-1,
+    -0x1.5db3d742c2653p0
+  },
+  { // Entry 690
+    0x1.f54d971881ad685b782ef88e6350f7cdp-1,
+    0x1.5db3d742c2653p0
+  },
+  { // Entry 691
+    -0x1.ec5883b7b6cf4d859ab04e15d53698c9p-1,
+    -0x1.4af645cf01ea8p0
+  },
+  { // Entry 692
+    0x1.ec5883b7b6cf4d859ab04e15d53698c9p-1,
+    0x1.4af645cf01ea8p0
+  },
+  { // Entry 693
+    -0x1.e0c04a94e17309c806c1c78bddc1d607p-1,
+    -0x1.3838b45b416fdp0
+  },
+  { // Entry 694
+    0x1.e0c04a94e17309c806c1c78bddc1d607p-1,
+    0x1.3838b45b416fdp0
+  },
+  { // Entry 695
+    -0x1.d294d1f96c7ebdb9869dd97cf574ddb9p-1,
+    -0x1.257b22e780f52p0
+  },
+  { // Entry 696
+    0x1.d294d1f96c7ebdb9869dd97cf574ddb9p-1,
+    0x1.257b22e780f52p0
+  },
+  { // Entry 697
+    -0x1.c1e9883373d7ecc48c92dc8875505f7ep-1,
+    -0x1.12bd9173c07abp0
+  },
+  { // Entry 698
+    0x1.c1e9883373d7ecc48c92dc8875505f7ep-1,
+    0x1.12bd9173c07abp0
+  },
+  { // Entry 699
+    -0x1.a2c289d9d055ac377f67d7a54a0b3005p-1,
+    -0x1.ea5c3ed5b3850p-1
+  },
+  { // Entry 700
+    0x1.a2c289d9d055ac377f67d7a54a0b3005p-1,
+    0x1.ea5c3ed5b3850p-1
+  },
+  { // Entry 701
+    -0x1.95f05257dbcb5f4b12636c5878ea405ap-1,
+    -0x1.d4b87dab670a0p-1
+  },
+  { // Entry 702
+    0x1.95f05257dbcb5f4b12636c5878ea405ap-1,
+    0x1.d4b87dab670a0p-1
+  },
+  { // Entry 703
+    -0x1.88647f26a6e0f6b2715a6c3797ec11f5p-1,
+    -0x1.bf14bc811a8f0p-1
+  },
+  { // Entry 704
+    0x1.88647f26a6e0f6b2715a6c3797ec11f5p-1,
+    0x1.bf14bc811a8f0p-1
+  },
+  { // Entry 705
+    -0x1.7a2541dfd4e752de38f04aba21fc9d9fp-1,
+    -0x1.a970fb56ce140p-1
+  },
+  { // Entry 706
+    0x1.7a2541dfd4e752de38f04aba21fc9d9fp-1,
+    0x1.a970fb56ce140p-1
+  },
+  { // Entry 707
+    -0x1.6b391e25bc26cbbcf7a0184070af9c39p-1,
+    -0x1.93cd3a2c81990p-1
+  },
+  { // Entry 708
+    0x1.6b391e25bc26cbbcf7a0184070af9c39p-1,
+    0x1.93cd3a2c81990p-1
+  },
+  { // Entry 709
+    -0x1.5ba6e6a8e706535b98fc99dfaef824f1p-1,
+    -0x1.7e297902351e0p-1
+  },
+  { // Entry 710
+    0x1.5ba6e6a8e706535b98fc99dfaef824f1p-1,
+    0x1.7e297902351e0p-1
+  },
+  { // Entry 711
+    -0x1.4b75ba096fa549eb93595d8194ab917fp-1,
+    -0x1.6885b7d7e8a30p-1
+  },
+  { // Entry 712
+    0x1.4b75ba096fa549eb93595d8194ab917fp-1,
+    0x1.6885b7d7e8a30p-1
+  },
+  { // Entry 713
+    -0x1.3aacff95a3122b15f372bfd2fdf9a75fp-1,
+    -0x1.52e1f6ad9c280p-1
+  },
+  { // Entry 714
+    0x1.3aacff95a3122b15f372bfd2fdf9a75fp-1,
+    0x1.52e1f6ad9c280p-1
+  },
+  { // Entry 715
+    -0x1.295463e769284a5aed17a443392f38f3p-1,
+    -0x1.3d3e35834fad0p-1
+  },
+  { // Entry 716
+    0x1.295463e769284a5aed17a443392f38f3p-1,
+    0x1.3d3e35834fad0p-1
+  },
+  { // Entry 717
+    -0x1.fc769b77e588495a6f642ca24e4ed3fcp-2,
+    -0x1.0a0b02501c799p-1
+  },
+  { // Entry 718
+    0x1.fc769b77e588495a6f642ca24e4ed3fcp-2,
+    0x1.0a0b02501c799p-1
+  },
+  { // Entry 719
+    -0x1.c853c78462de46b5743315612f8b5a7cp-2,
+    -0x1.d8f7208e6b82cp-2
+  },
+  { // Entry 720
+    0x1.c853c78462de46b5743315612f8b5a7cp-2,
+    0x1.d8f7208e6b82cp-2
+  },
+  { // Entry 721
+    -0x1.92aba90aaf27249de49c78fc643c8b72p-2,
+    -0x1.9dd83c7c9e126p-2
+  },
+  { // Entry 722
+    0x1.92aba90aaf27249de49c78fc643c8b72p-2,
+    0x1.9dd83c7c9e126p-2
+  },
+  { // Entry 723
+    -0x1.5bac064658f39460c83113c0a0097a0cp-2,
+    -0x1.62b9586ad0a20p-2
+  },
+  { // Entry 724
+    0x1.5bac064658f39460c83113c0a0097a0cp-2,
+    0x1.62b9586ad0a20p-2
+  },
+  { // Entry 725
+    -0x1.2383ca8078e58477cd5fb1d9de031dcep-2,
+    -0x1.279a74590331ap-2
+  },
+  { // Entry 726
+    0x1.2383ca8078e58477cd5fb1d9de031dcep-2,
+    0x1.279a74590331ap-2
+  },
+  { // Entry 727
+    -0x1.d4c5bc11d2371af2fe25ef5ede2766a3p-3,
+    -0x1.d8f7208e6b829p-3
+  },
+  { // Entry 728
+    0x1.d4c5bc11d2371af2fe25ef5ede2766a3p-3,
+    0x1.d8f7208e6b829p-3
+  },
+  { // Entry 729
+    -0x1.60f3faaf43023d3c7863ae06d4d59774p-3,
+    -0x1.62b9586ad0a1ep-3
+  },
+  { // Entry 730
+    0x1.60f3faaf43023d3c7863ae06d4d59774p-3,
+    0x1.62b9586ad0a1ep-3
+  },
+  { // Entry 731
+    -0x1.d7ea3de45a9d6563ac005c0c5bad8c50p-4,
+    -0x1.d8f7208e6b826p-4
+  },
+  { // Entry 732
+    0x1.d7ea3de45a9d6563ac005c0c5bad8c50p-4,
+    0x1.d8f7208e6b826p-4
+  },
+  { // Entry 733
+    -0x1.d8b3df489987a6fe0eead008e720aa22p-5,
+    -0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 734
+    0x1.d8b3df489987a6fe0eead008e720aa22p-5,
+    0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 735
+    0x1.d8b3df489987a6fe0eead008e720aa22p-5,
+    0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 736
+    -0x1.d8b3df489987a6fe0eead008e720aa22p-5,
+    -0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 737
+    0x1.d7ea3de45a9dd4a4bccd1a8c048faf4cp-4,
+    0x1.d8f7208e6b82dp-4
+  },
+  { // Entry 738
+    -0x1.d7ea3de45a9dd4a4bccd1a8c048faf4cp-4,
+    -0x1.d8f7208e6b82dp-4
+  },
+  { // Entry 739
+    0x1.60f3faaf43027c4752f564f9d0818fe8p-3,
+    0x1.62b9586ad0a22p-3
+  },
+  { // Entry 740
+    -0x1.60f3faaf43027c4752f564f9d0818fe8p-3,
+    -0x1.62b9586ad0a22p-3
+  },
+  { // Entry 741
+    0x1.d4c5bc11d23759400642e5a1efdc0f85p-3,
+    0x1.d8f7208e6b82dp-3
+  },
+  { // Entry 742
+    -0x1.d4c5bc11d23759400642e5a1efdc0f85p-3,
+    -0x1.d8f7208e6b82dp-3
+  },
+  { // Entry 743
+    0x1.2383ca8078e5a324d52c1530742cd4f5p-2,
+    0x1.279a74590331cp-2
+  },
+  { // Entry 744
+    -0x1.2383ca8078e5a324d52c1530742cd4f5p-2,
+    -0x1.279a74590331cp-2
+  },
+  { // Entry 745
+    0x1.5bac064658f3b27a28572bea256195efp-2,
+    0x1.62b9586ad0a22p-2
+  },
+  { // Entry 746
+    -0x1.5bac064658f3b27a28572bea256195efp-2,
+    -0x1.62b9586ad0a22p-2
+  },
+  { // Entry 747
+    0x1.92aba90aaf274209efaed08e34071e3bp-2,
+    0x1.9dd83c7c9e128p-2
+  },
+  { // Entry 748
+    -0x1.92aba90aaf274209efaed08e34071e3bp-2,
+    -0x1.9dd83c7c9e128p-2
+  },
+  { // Entry 749
+    0x1.c853c78462de635b10a2b93afd75da26p-2,
+    0x1.d8f7208e6b82ep-2
+  },
+  { // Entry 750
+    -0x1.c853c78462de635b10a2b93afd75da26p-2,
+    -0x1.d8f7208e6b82ep-2
+  },
+  { // Entry 751
+    0x1.fc769b77e588495a6f642ca24e4ed3fcp-2,
+    0x1.0a0b02501c799p-1
+  },
+  { // Entry 752
+    -0x1.fc769b77e588495a6f642ca24e4ed3fcp-2,
+    -0x1.0a0b02501c799p-1
+  },
+  { // Entry 753
+    0x1.295463e769281640ae026f50fc45e301p-1,
+    0x1.3d3e35834faccp-1
+  },
+  { // Entry 754
+    -0x1.295463e769281640ae026f50fc45e301p-1,
+    -0x1.3d3e35834faccp-1
+  },
+  { // Entry 755
+    0x1.3aacff95a311f899a0e279535e81c4ecp-1,
+    0x1.52e1f6ad9c27cp-1
+  },
+  { // Entry 756
+    -0x1.3aacff95a311f899a0e279535e81c4ecp-1,
+    -0x1.52e1f6ad9c27cp-1
+  },
+  { // Entry 757
+    0x1.4b75ba096fa5192442b7950f960f8006p-1,
+    0x1.6885b7d7e8a2cp-1
+  },
+  { // Entry 758
+    -0x1.4b75ba096fa5192442b7950f960f8006p-1,
+    -0x1.6885b7d7e8a2cp-1
+  },
+  { // Entry 759
+    0x1.5ba6e6a8e706245f97e28af3ddb700f6p-1,
+    0x1.7e297902351dcp-1
+  },
+  { // Entry 760
+    -0x1.5ba6e6a8e706245f97e28af3ddb700f6p-1,
+    -0x1.7e297902351dcp-1
+  },
+  { // Entry 761
+    0x1.6b391e25bc269ea1c1a40de62fbc03b4p-1,
+    0x1.93cd3a2c8198cp-1
+  },
+  { // Entry 762
+    -0x1.6b391e25bc269ea1c1a40de62fbc03b4p-1,
+    -0x1.93cd3a2c8198cp-1
+  },
+  { // Entry 763
+    0x1.7a2541dfd4e727b86dd309664186ec6bp-1,
+    0x1.a970fb56ce13cp-1
+  },
+  { // Entry 764
+    -0x1.7a2541dfd4e727b86dd309664186ec6bp-1,
+    -0x1.a970fb56ce13cp-1
+  },
+  { // Entry 765
+    0x1.88647f26a6e0cd95cb991f7ffe61a02ep-1,
+    0x1.bf14bc811a8ecp-1
+  },
+  { // Entry 766
+    -0x1.88647f26a6e0cd95cb991f7ffe61a02ep-1,
+    -0x1.bf14bc811a8ecp-1
+  },
+  { // Entry 767
+    0x1.95f05257dbcb384a5e326857376dd801p-1,
+    0x1.d4b87dab6709cp-1
+  },
+  { // Entry 768
+    -0x1.95f05257dbcb384a5e326857376dd801p-1,
+    -0x1.d4b87dab6709cp-1
+  },
+  { // Entry 769
+    0x1.a2c289d9d0558764921a4de355f9448cp-1,
+    0x1.ea5c3ed5b384cp-1
+  },
+  { // Entry 770
+    -0x1.a2c289d9d0558764921a4de355f9448cp-1,
+    -0x1.ea5c3ed5b384cp-1
+  },
+  { // Entry 771
+    0x1.c1e9883373d7ecc48c92dc8875505f7ep-1,
+    0x1.12bd9173c07abp0
+  },
+  { // Entry 772
+    -0x1.c1e9883373d7ecc48c92dc8875505f7ep-1,
+    -0x1.12bd9173c07abp0
+  },
+  { // Entry 773
+    0x1.d294d1f96c7ef26e203c5b309a55671fp-1,
+    0x1.257b22e780f56p0
+  },
+  { // Entry 774
+    -0x1.d294d1f96c7ef26e203c5b309a55671fp-1,
+    -0x1.257b22e780f56p0
+  },
+  { // Entry 775
+    0x1.e0c04a94e17335d073052a0394b9e1c3p-1,
+    0x1.3838b45b41701p0
+  },
+  { // Entry 776
+    -0x1.e0c04a94e17335d073052a0394b9e1c3p-1,
+    -0x1.3838b45b41701p0
+  },
+  { // Entry 777
+    0x1.ec5883b7b6cf70a577dd9160d0f8e9d5p-1,
+    0x1.4af645cf01eacp0
+  },
+  { // Entry 778
+    -0x1.ec5883b7b6cf70a577dd9160d0f8e9d5p-1,
+    -0x1.4af645cf01eacp0
+  },
+  { // Entry 779
+    0x1.f54d971881ad82629bd84d214194e8ddp-1,
+    0x1.5db3d742c2657p0
+  },
+  { // Entry 780
+    -0x1.f54d971881ad82629bd84d214194e8ddp-1,
+    -0x1.5db3d742c2657p0
+  },
+  { // Entry 781
+    0x1.fb933c40107fe83fd16c1789e27f69f7p-1,
+    0x1.707168b682e02p0
+  },
+  { // Entry 782
+    -0x1.fb933c40107fe83fd16c1789e27f69f7p-1,
+    -0x1.707168b682e02p0
+  },
+  { // Entry 783
+    0x1.ff20d961624e77daef329b4029c362dep-1,
+    0x1.832efa2a435adp0
+  },
+  { // Entry 784
+    -0x1.ff20d961624e77daef329b4029c362dep-1,
+    -0x1.832efa2a435adp0
+  },
+  { // Entry 785
+    0x1.fff18f24f3e4b69592294f206d7b32c2p-1,
+    0x1.95ec8b9e03d58p0
+  },
+  { // Entry 786
+    -0x1.fff18f24f3e4b69592294f206d7b32c2p-1,
+    -0x1.95ec8b9e03d58p0
+  },
+  { // Entry 787
+    0x1.fe043f57369d6a52fa33f0119ec4da19p-1,
+    0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 788
+    -0x1.fe043f57369d6a52fa33f0119ec4da19p-1,
+    -0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 789
+    0x1.b3d3695acc4136b2d44714f9b38419b4p-1,
+    0x1.04aff6d330942p0
+  },
+  { // Entry 790
+    -0x1.b3d3695acc4136b2d44714f9b38419b4p-1,
+    -0x1.04aff6d330942p0
+  },
+  { // Entry 791
+    0x1.b3d41972dc8063994f63413d5e4d8e4bp-1,
+    0x1.04b09e98dcdb4p0
+  },
+  { // Entry 792
+    -0x1.b3d41972dc8063994f63413d5e4d8e4bp-1,
+    -0x1.04b09e98dcdb4p0
+  },
+  { // Entry 793
+    0x1.b3d4c98a318fb66f821d7286ae7dce7bp-1,
+    0x1.04b1465e89226p0
+  },
+  { // Entry 794
+    -0x1.b3d4c98a318fb66f821d7286ae7dce7bp-1,
+    -0x1.04b1465e89226p0
+  },
+  { // Entry 795
+    0x1.b3d579a0cb6ee393ff75b58ffe16d13fp-1,
+    0x1.04b1ee2435698p0
+  },
+  { // Entry 796
+    -0x1.b3d579a0cb6ee393ff75b58ffe16d13fp-1,
+    -0x1.04b1ee2435698p0
+  },
+  { // Entry 797
+    0x1.b3d629b6aa1d9f65aad1a2fc932c8bcbp-1,
+    0x1.04b295e9e1b0ap0
+  },
+  { // Entry 798
+    -0x1.b3d629b6aa1d9f65aad1a2fc932c8bcbp-1,
+    -0x1.04b295e9e1b0ap0
+  },
+  { // Entry 799
+    0x1.b3d6d9cbcd9b9e43b7fc7fd428a44dd8p-1,
+    0x1.04b33daf8df7cp0
+  },
+  { // Entry 800
+    -0x1.b3d6d9cbcd9b9e43b7fc7fd428a44dd8p-1,
+    -0x1.04b33daf8df7cp0
+  },
+  { // Entry 801
+    0x1.b3d789e035e8948dab275dfe546c5b08p-1,
+    0x1.04b3e5753a3eep0
+  },
+  { // Entry 802
+    -0x1.b3d789e035e8948dab275dfe546c5b08p-1,
+    -0x1.04b3e5753a3eep0
+  },
+  { // Entry 803
+    0x1.b3d839f3e30436a358e93cbdcb2bb367p-1,
+    0x1.04b48d3ae6860p0
+  },
+  { // Entry 804
+    -0x1.b3d839f3e30436a358e93cbdcb2bb367p-1,
+    -0x1.04b48d3ae6860p0
+  },
+  { // Entry 805
+    0x1.b3d8ea06d4ee0684f5741ec777ed88e0p-1,
+    0x1.04b5350092ccfp0
+  },
+  { // Entry 806
+    -0x1.b3d8ea06d4ee0684f5741ec777ed88e0p-1,
+    -0x1.04b5350092ccfp0
+  },
+  { // Entry 807
+    -0.0,
+    -0x1.0p-1074
+  },
+  { // Entry 808
+    0.0,
+    0x1.0p-1074
+  },
+  { // Entry 809
+    -0.0,
+    -0.0
+  },
+  { // Entry 810
+    0.0,
+    0x1.0p-1074
+  },
+  { // Entry 811
+    -0.0,
+    -0x1.0p-1074
+  },
+  { // Entry 812
+    0x1.1773d561fd5065d0e9607a728a39eed2p-1,
+    0x1.279a74590331bp-1
+  },
+  { // Entry 813
+    -0x1.1773d561fd5065d0e9607a728a39eed2p-1,
+    -0x1.279a74590331bp-1
+  },
+  { // Entry 814
+    0x1.1773d561fd507338ff9c088d80c680dbp-1,
+    0x1.279a74590331cp-1
+  },
+  { // Entry 815
+    -0x1.1773d561fd507338ff9c088d80c680dbp-1,
+    -0x1.279a74590331cp-1
+  },
+  { // Entry 816
+    0x1.1773d561fd5080a115d796a8770d35efp-1,
+    0x1.279a74590331dp-1
+  },
+  { // Entry 817
+    -0x1.1773d561fd5080a115d796a8770d35efp-1,
+    -0x1.279a74590331dp-1
+  },
+  { // Entry 818
+    0x1.f95b8e7107418c11c94d4a54a9da9b7ap-1,
+    0x1.bb67ae8584ca9p0
+  },
+  { // Entry 819
+    -0x1.f95b8e7107418c11c94d4a54a9da9b7ap-1,
+    -0x1.bb67ae8584ca9p0
+  },
+  { // Entry 820
+    0x1.f95b8e71074186ee81d5ff89d8fae545p-1,
+    0x1.bb67ae8584caap0
+  },
+  { // Entry 821
+    -0x1.f95b8e71074186ee81d5ff89d8fae545p-1,
+    -0x1.bb67ae8584caap0
+  },
+  { // Entry 822
+    0x1.f95b8e71074181cb3a5eb4bf0621d381p-1,
+    0x1.bb67ae8584cabp0
+  },
+  { // Entry 823
+    -0x1.f95b8e71074181cb3a5eb4bf0621d381p-1,
+    -0x1.bb67ae8584cabp0
+  },
+  { // Entry 824
+    0x1.b1d8305321615ac938cff02be9f25085p-2,
+    0x1.bffffffffffffp-2
+  },
+  { // Entry 825
+    -0x1.b1d8305321615ac938cff02be9f25085p-2,
+    -0x1.bffffffffffffp-2
+  },
+  { // Entry 826
+    0x1.b1d83053216169476f4d1982b9b14ab1p-2,
+    0x1.cp-2
+  },
+  { // Entry 827
+    -0x1.b1d83053216169476f4d1982b9b14ab1p-2,
+    -0x1.cp-2
+  },
+  { // Entry 828
+    0x1.b1d83053216177c5a5ca42d98955275ap-2,
+    0x1.c000000000001p-2
+  },
+  { // Entry 829
+    -0x1.b1d83053216177c5a5ca42d98955275ap-2,
+    -0x1.c000000000001p-2
+  },
+  { // Entry 830
+    0x1.44eb381cf3869ea71ccb36863e4ea65bp-1,
+    0x1.5ffffffffffffp-1
+  },
+  { // Entry 831
+    -0x1.44eb381cf3869ea71ccb36863e4ea65bp-1,
+    -0x1.5ffffffffffffp-1
+  },
+  { // Entry 832
+    0x1.44eb381cf386ab04a4f8656abea80b83p-1,
+    0x1.6p-1
+  },
+  { // Entry 833
+    -0x1.44eb381cf386ab04a4f8656abea80b83p-1,
+    -0x1.6p-1
+  },
+  { // Entry 834
+    0x1.44eb381cf386b7622d25944f3eb035dcp-1,
+    0x1.6000000000001p-1
+  },
+  { // Entry 835
+    -0x1.44eb381cf386b7622d25944f3eb035dcp-1,
+    -0x1.6000000000001p-1
+  },
+  { // Entry 836
+    0x1.dad902fa8ac864fd8afa0bdc609ded19p-1,
+    0x1.2ffffffffffffp0
+  },
+  { // Entry 837
+    -0x1.dad902fa8ac864fd8afa0bdc609ded19p-1,
+    -0x1.2ffffffffffffp0
+  },
+  { // Entry 838
+    0x1.dad902fa8ac870f52f1b843ac83bc3edp-1,
+    0x1.3p0
+  },
+  { // Entry 839
+    -0x1.dad902fa8ac870f52f1b843ac83bc3edp-1,
+    -0x1.3p0
+  },
+  { // Entry 840
+    0x1.dad902fa8ac87cecd33cfc992dfec1bep-1,
+    0x1.3000000000001p0
+  },
+  { // Entry 841
+    -0x1.dad902fa8ac87cecd33cfc992dfec1bep-1,
+    -0x1.3000000000001p0
+  },
+  { // Entry 842
+    0x1.4b707a7acdecf90a188d0230fad3ad58p-1,
+    0x1.37fffffffffffp1
+  },
+  { // Entry 843
+    -0x1.4b707a7acdecf90a188d0230fad3ad58p-1,
+    -0x1.37fffffffffffp1
+  },
+  { // Entry 844
+    0x1.4b707a7acdecc84239463e78b312fa10p-1,
+    0x1.380p1
+  },
+  { // Entry 845
+    -0x1.4b707a7acdecc84239463e78b312fa10p-1,
+    -0x1.380p1
+  },
+  { // Entry 846
+    0x1.4b707a7acdec977a59ff7ac0662484ddp-1,
+    0x1.3800000000001p1
+  },
+  { // Entry 847
+    -0x1.4b707a7acdec977a59ff7ac0662484ddp-1,
+    -0x1.3800000000001p1
+  },
+  { // Entry 848
+    0x1.066e7eb76f5c6678fd8325a81f1925c6p-4,
+    0x1.069c8b46b3792p-4
+  },
+  { // Entry 849
+    -0x1.066e7eb76f5c6678fd8325a81f1925c6p-4,
+    -0x1.069c8b46b3792p-4
+  },
+  { // Entry 850
+    0x1.05e4761ab8d8f0a7dba834000f236650p-3,
+    0x1.069c8b46b3792p-3
+  },
+  { // Entry 851
+    -0x1.05e4761ab8d8f0a7dba834000f236650p-3,
+    -0x1.069c8b46b3792p-3
+  },
+  { // Entry 852
+    0x1.877e2cd4f6fd9ba498e327053032734fp-3,
+    0x1.89ead0ea0d35bp-3
+  },
+  { // Entry 853
+    -0x1.877e2cd4f6fd9ba498e327053032734fp-3,
+    -0x1.89ead0ea0d35bp-3
+  },
+  { // Entry 854
+    0x1.03be06f97cbee47698539f977cadbe7ep-2,
+    0x1.069c8b46b3792p-2
+  },
+  { // Entry 855
+    -0x1.03be06f97cbee47698539f977cadbe7ep-2,
+    -0x1.069c8b46b3792p-2
+  },
+  { // Entry 856
+    0x1.42abba8c72fbb8ca96f79aa4bb03584ep-2,
+    0x1.4843ae1860576p-2
+  },
+  { // Entry 857
+    -0x1.42abba8c72fbb8ca96f79aa4bb03584ep-2,
+    -0x1.4843ae1860576p-2
+  },
+  { // Entry 858
+    0x1.8045fe64e62dc3d686d976d7d5a7c689p-2,
+    0x1.89ead0ea0d35ap-2
+  },
+  { // Entry 859
+    -0x1.8045fe64e62dc3d686d976d7d5a7c689p-2,
+    -0x1.89ead0ea0d35ap-2
+  },
+  { // Entry 860
+    0x1.bc4c04d71abbeea5ab064ecfbf54c613p-2,
+    0x1.cb91f3bbba13ep-2
+  },
+  { // Entry 861
+    -0x1.bc4c04d71abbeea5ab064ecfbf54c613p-2,
+    -0x1.cb91f3bbba13ep-2
+  },
+  { // Entry 862
+    0x1.f67ea975b86a01510e6bde3778138934p-2,
+    0x1.069c8b46b3791p-1
+  },
+  { // Entry 863
+    -0x1.f67ea975b86a01510e6bde3778138934p-2,
+    -0x1.069c8b46b3791p-1
+  },
+  { // Entry 864
+    0x1.175059bf0d42524ecb0bf4243b55973dp-1,
+    0x1.27701caf89e83p-1
+  },
+  { // Entry 865
+    -0x1.175059bf0d42524ecb0bf4243b55973dp-1,
+    -0x1.27701caf89e83p-1
+  },
+  { // Entry 866
+    0x1.323b8b1fb4ba21dd12cce820e156a4fcp-1,
+    0x1.4843ae1860575p-1
+  },
+  { // Entry 867
+    -0x1.323b8b1fb4ba21dd12cce820e156a4fcp-1,
+    -0x1.4843ae1860575p-1
+  },
+  { // Entry 868
+    0x1.4be4979c5efb306c1a77024032849b52p-1,
+    0x1.69173f8136c67p-1
+  },
+  { // Entry 869
+    -0x1.4be4979c5efb306c1a77024032849b52p-1,
+    -0x1.69173f8136c67p-1
+  },
+  { // Entry 870
+    0x1.643080d67acc1332c64a85612cacafb9p-1,
+    0x1.89ead0ea0d359p-1
+  },
+  { // Entry 871
+    -0x1.643080d67acc1332c64a85612cacafb9p-1,
+    -0x1.89ead0ea0d359p-1
+  },
+  { // Entry 872
+    0x1.7b05b7b6c612e5b08d5efe49a46e21a1p-1,
+    0x1.aabe6252e3a4bp-1
+  },
+  { // Entry 873
+    -0x1.7b05b7b6c612e5b08d5efe49a46e21a1p-1,
+    -0x1.aabe6252e3a4bp-1
+  },
+  { // Entry 874
+    0x1.904c37505de48fa8e76287960fd44594p-1,
+    0x1.cb91f3bbba13dp-1
+  },
+  { // Entry 875
+    -0x1.904c37505de48fa8e76287960fd44594p-1,
+    -0x1.cb91f3bbba13dp-1
+  },
+  { // Entry 876
+    0x1.a3ed9e252938a14c79c575639c15a91dp-1,
+    0x1.ec6585249082fp-1
+  },
+  { // Entry 877
+    -0x1.a3ed9e252938a14c79c575639c15a91dp-1,
+    -0x1.ec6585249082fp-1
+  },
+  { // Entry 878
+    0x1.b5d545b109bf935594036798cf40c9b0p-1,
+    0x1.069c8b46b3791p0
+  },
+  { // Entry 879
+    -0x1.b5d545b109bf935594036798cf40c9b0p-1,
+    -0x1.069c8b46b3791p0
+  },
+  { // Entry 880
+    0x1.c5f058230e7fd14d3e5e315349f699efp-1,
+    0x1.170653fb1eb0ap0
+  },
+  { // Entry 881
+    -0x1.c5f058230e7fd14d3e5e315349f699efp-1,
+    -0x1.170653fb1eb0ap0
+  },
+  { // Entry 882
+    0x1.d42de42dce1346a03d1f6abf0eba9022p-1,
+    0x1.27701caf89e83p0
+  },
+  { // Entry 883
+    -0x1.d42de42dce1346a03d1f6abf0eba9022p-1,
+    -0x1.27701caf89e83p0
+  },
+  { // Entry 884
+    0x1.e07eeeda109cb504afcca860d4b5dd32p-1,
+    0x1.37d9e563f51fcp0
+  },
+  { // Entry 885
+    -0x1.e07eeeda109cb504afcca860d4b5dd32p-1,
+    -0x1.37d9e563f51fcp0
+  },
+  { // Entry 886
+    0x1.ead6834909b93371faf3beaddbd60eddp-1,
+    0x1.4843ae1860575p0
+  },
+  { // Entry 887
+    -0x1.ead6834909b93371faf3beaddbd60eddp-1,
+    -0x1.4843ae1860575p0
+  },
+  { // Entry 888
+    0x1.f329c0558e967e4cab58d0fa572d62d2p-1,
+    0x1.58ad76cccb8eep0
+  },
+  { // Entry 889
+    -0x1.f329c0558e967e4cab58d0fa572d62d2p-1,
+    -0x1.58ad76cccb8eep0
+  },
+  { // Entry 890
+    0x1.f96fe405f1ac5dc9cf343508067bfcaep-1,
+    0x1.69173f8136c67p0
+  },
+  { // Entry 891
+    -0x1.f96fe405f1ac5dc9cf343508067bfcaep-1,
+    -0x1.69173f8136c67p0
+  },
+  { // Entry 892
+    0x1.fda254c27a01f4786c149d6a7779cc3ap-1,
+    0x1.79810835a1fe0p0
+  },
+  { // Entry 893
+    -0x1.fda254c27a01f4786c149d6a7779cc3ap-1,
+    -0x1.79810835a1fe0p0
+  },
+  { // Entry 894
+    0x1.ffbca846c4fc997f1a381420208884e0p-1,
+    0x1.89ead0ea0d359p0
+  },
+  { // Entry 895
+    -0x1.ffbca846c4fc997f1a381420208884e0p-1,
+    -0x1.89ead0ea0d359p0
+  },
+  { // Entry 896
+    0x1.ffbca846c4fc9f30bfb458ef2091c8eep-1,
+    0x1.9a54999e786d2p0
+  },
+  { // Entry 897
+    -0x1.ffbca846c4fc9f30bfb458ef2091c8eep-1,
+    -0x1.9a54999e786d2p0
+  },
+  { // Entry 898
+    0x1.fda254c27a0205875f271435f827160cp-1,
+    0x1.aabe6252e3a4bp0
+  },
+  { // Entry 899
+    -0x1.fda254c27a0205875f271435f827160cp-1,
+    -0x1.aabe6252e3a4bp0
+  },
+  { // Entry 900
+    0x1.f96fe405f1ac7a241e02e58b0cbf3ae7p-1,
+    0x1.bb282b074edc4p0
+  },
+  { // Entry 901
+    -0x1.f96fe405f1ac7a241e02e58b0cbf3ae7p-1,
+    -0x1.bb282b074edc4p0
+  },
+  { // Entry 902
+    0x1.f329c0558e96a5d48272ad4c49ec53b8p-1,
+    0x1.cb91f3bbba13dp0
+  },
+  { // Entry 903
+    -0x1.f329c0558e96a5d48272ad4c49ec53b8p-1,
+    -0x1.cb91f3bbba13dp0
+  },
+  { // Entry 904
+    0x1.ead6834909b965fdc4b0ceffc0f285c6p-1,
+    0x1.dbfbbc70254b6p0
+  },
+  { // Entry 905
+    -0x1.ead6834909b965fdc4b0ceffc0f285c6p-1,
+    -0x1.dbfbbc70254b6p0
+  },
+  { // Entry 906
+    0x1.e07eeeda109cf25f400cd5f46acec887p-1,
+    0x1.ec6585249082fp0
+  },
+  { // Entry 907
+    -0x1.e07eeeda109cf25f400cd5f46acec887p-1,
+    -0x1.ec6585249082fp0
+  },
+  { // Entry 908
+    0x1.d42de42dce138e890939e56c439ded90p-1,
+    0x1.fccf4dd8fbba8p0
+  },
+  { // Entry 909
+    -0x1.d42de42dce138e890939e56c439ded90p-1,
+    -0x1.fccf4dd8fbba8p0
+  },
+  { // Entry 910
+    0x1.c5f058230e8014ab83ece0c3a638c079p-1,
+    0x1.069c8b46b3791p1
+  },
+  { // Entry 911
+    -0x1.c5f058230e8014ab83ece0c3a638c079p-1,
+    -0x1.069c8b46b3791p1
+  },
+  { // Entry 912
+    0x1.b5d545b109bfce3fc4d77001afe2f2b6p-1,
+    0x1.0ed16fa0e914ep1
+  },
+  { // Entry 913
+    -0x1.b5d545b109bfce3fc4d77001afe2f2b6p-1,
+    -0x1.0ed16fa0e914ep1
+  },
+  { // Entry 914
+    0x1.a3ed9e252938d92a5553b3c09d2bddd3p-1,
+    0x1.170653fb1eb0bp1
+  },
+  { // Entry 915
+    -0x1.a3ed9e252938d92a5553b3c09d2bddd3p-1,
+    -0x1.170653fb1eb0bp1
+  },
+  { // Entry 916
+    0x1.904c37505de4b8975dd2730e196ddfc3p-1,
+    0x1.1f3b3855544c8p1
+  },
+  { // Entry 917
+    -0x1.904c37505de4b8975dd2730e196ddfc3p-1,
+    -0x1.1f3b3855544c8p1
+  },
+  { // Entry 918
+    0x1.7b05b7b6c612fc4fda3812b1f1348389p-1,
+    0x1.27701caf89e85p1
+  },
+  { // Entry 919
+    -0x1.7b05b7b6c612fc4fda3812b1f1348389p-1,
+    -0x1.27701caf89e85p1
+  },
+  { // Entry 920
+    0x1.643080d67acc14620672dda6241ea305p-1,
+    0x1.2fa50109bf842p1
+  },
+  { // Entry 921
+    -0x1.643080d67acc14620672dda6241ea305p-1,
+    -0x1.2fa50109bf842p1
+  },
+  { // Entry 922
+    0x1.4be4979c5efb194fc82ac367fedf93bcp-1,
+    0x1.37d9e563f51ffp1
+  },
+  { // Entry 923
+    -0x1.4be4979c5efb194fc82ac367fedf93bcp-1,
+    -0x1.37d9e563f51ffp1
+  },
+  { // Entry 924
+    0x1.323b8b1fb4b9efe5075ede8049a85c3dp-1,
+    0x1.400ec9be2abbcp1
+  },
+  { // Entry 925
+    -0x1.323b8b1fb4b9efe5075ede8049a85c3dp-1,
+    -0x1.400ec9be2abbcp1
+  },
+  { // Entry 926
+    0x1.175059bf0d42033bbcf598c88b176e61p-1,
+    0x1.4843ae1860579p1
+  },
+  { // Entry 927
+    -0x1.175059bf0d42033bbcf598c88b176e61p-1,
+    -0x1.4843ae1860579p1
+  },
+  { // Entry 928
+    0x1.f67ea975b8692521f77d6754b302c5c4p-2,
+    0x1.5078927295f36p1
+  },
+  { // Entry 929
+    -0x1.f67ea975b8692521f77d6754b302c5c4p-2,
+    -0x1.5078927295f36p1
+  },
+  { // Entry 930
+    0x1.bc4c04d71abad14efc29a66342ada723p-2,
+    0x1.58ad76cccb8f3p1
+  },
+  { // Entry 931
+    -0x1.bc4c04d71abad14efc29a66342ada723p-2,
+    -0x1.58ad76cccb8f3p1
+  },
+  { // Entry 932
+    0x1.8045fe64e62c62f57f077ea251e2f2dcp-2,
+    0x1.60e25b27012b0p1
+  },
+  { // Entry 933
+    -0x1.8045fe64e62c62f57f077ea251e2f2dcp-2,
+    -0x1.60e25b27012b0p1
+  },
+  { // Entry 934
+    0x1.42abba8c72fa12be920b316627512e41p-2,
+    0x1.69173f8136c6dp1
+  },
+  { // Entry 935
+    -0x1.42abba8c72fa12be920b316627512e41p-2,
+    -0x1.69173f8136c6dp1
+  },
+  { // Entry 936
+    0x1.03be06f97cbcf866021e5a5c62c6b07ep-2,
+    0x1.714c23db6c62ap1
+  },
+  { // Entry 937
+    -0x1.03be06f97cbcf866021e5a5c62c6b07ep-2,
+    -0x1.714c23db6c62ap1
+  },
+  { // Entry 938
+    0x1.877e2cd4f6f94710f2776775b01c73dbp-3,
+    0x1.79810835a1fe7p1
+  },
+  { // Entry 939
+    -0x1.877e2cd4f6f94710f2776775b01c73dbp-3,
+    -0x1.79810835a1fe7p1
+  },
+  { // Entry 940
+    0x1.05e4761ab8d421719567717f76712867p-3,
+    0x1.81b5ec8fd79a4p1
+  },
+  { // Entry 941
+    -0x1.05e4761ab8d421719567717f76712867p-3,
+    -0x1.81b5ec8fd79a4p1
+  },
+  { // Entry 942
+    0x1.066e7eb76f5dd2ea19b6991e8a1a3634p-4,
+    0x1.89ead0ea0d35bp1
+  },
+  { // Entry 943
+    -0x1.066e7eb76f5dd2ea19b6991e8a1a3634p-4,
+    -0x1.89ead0ea0d35bp1
+  },
+  { // Entry 944
+    0x1.03be06f97cbf09cc0badbdae803d7b4ep-2,
+    -0x1.81b5ec8fd799fp2
+  },
+  { // Entry 945
+    -0x1.03be06f97cbf09cc0badbdae803d7b4ep-2,
+    0x1.81b5ec8fd799fp2
+  },
+  { // Entry 946
+    0x1.f67ea975b86a22f2348778824f95d84ap-2,
+    -0x1.714c23db6c626p2
+  },
+  { // Entry 947
+    -0x1.f67ea975b86a22f2348778824f95d84ap-2,
+    0x1.714c23db6c626p2
+  },
+  { // Entry 948
+    0x1.643080d67acc210fa27e9247a8286220p-1,
+    -0x1.60e25b27012adp2
+  },
+  { // Entry 949
+    -0x1.643080d67acc210fa27e9247a8286220p-1,
+    0x1.60e25b27012adp2
+  },
+  { // Entry 950
+    0x1.b5d545b109bf950b419702972b94f8fap-1,
+    -0x1.5078927295f34p2
+  },
+  { // Entry 951
+    -0x1.b5d545b109bf950b419702972b94f8fap-1,
+    0x1.5078927295f34p2
+  },
+  { // Entry 952
+    0x1.ead6834909b9346234dbb601d0486cf2p-1,
+    -0x1.400ec9be2abbbp2
+  },
+  { // Entry 953
+    -0x1.ead6834909b9346234dbb601d0486cf2p-1,
+    0x1.400ec9be2abbbp2
+  },
+  { // Entry 954
+    0x1.ffbca846c4fc999a29dc1d6b2d7cb413p-1,
+    -0x1.2fa50109bf842p2
+  },
+  { // Entry 955
+    -0x1.ffbca846c4fc999a29dc1d6b2d7cb413p-1,
+    0x1.2fa50109bf842p2
+  },
+  { // Entry 956
+    0x1.f329c0558e96a518a2af3ae7800a5b65p-1,
+    -0x1.1f3b3855544c9p2
+  },
+  { // Entry 957
+    -0x1.f329c0558e96a518a2af3ae7800a5b65p-1,
+    0x1.1f3b3855544c9p2
+  },
+  { // Entry 958
+    0x1.c5f058230e8021f21bd0ac2c0f6809a9p-1,
+    -0x1.0ed16fa0e9150p2
+  },
+  { // Entry 959
+    -0x1.c5f058230e8021f21bd0ac2c0f6809a9p-1,
+    0x1.0ed16fa0e9150p2
+  },
+  { // Entry 960
+    0x1.7b05b7b6c61365a9ac9e908b8e5d3ce4p-1,
+    -0x1.fccf4dd8fbbaep1
+  },
+  { // Entry 961
+    -0x1.7b05b7b6c61365a9ac9e908b8e5d3ce4p-1,
+    0x1.fccf4dd8fbbaep1
+  },
+  { // Entry 962
+    0x1.175059bf0d42f1d6b391f07f96f2353dp-1,
+    -0x1.dbfbbc70254bcp1
+  },
+  { // Entry 963
+    -0x1.175059bf0d42f1d6b391f07f96f2353dp-1,
+    0x1.dbfbbc70254bcp1
+  },
+  { // Entry 964
+    0x1.42abba8c72fd22194793246b8d19960ap-2,
+    -0x1.bb282b074edcap1
+  },
+  { // Entry 965
+    -0x1.42abba8c72fd22194793246b8d19960ap-2,
+    0x1.bb282b074edcap1
+  },
+  { // Entry 966
+    0x1.066e7eb76f62b5f4563de26dca890017p-4,
+    -0x1.9a54999e786d8p1
+  },
+  { // Entry 967
+    -0x1.066e7eb76f62b5f4563de26dca890017p-4,
+    0x1.9a54999e786d8p1
+  },
+  { // Entry 968
+    -0x1.877e2cd4f6fa42586875c5250a169e48p-3,
+    -0x1.79810835a1fe6p1
+  },
+  { // Entry 969
+    0x1.877e2cd4f6fa42586875c5250a169e48p-3,
+    0x1.79810835a1fe6p1
+  },
+  { // Entry 970
+    -0x1.bc4c04d71aba5dfc098278f168bbd962p-2,
+    -0x1.58ad76cccb8f4p1
+  },
+  { // Entry 971
+    0x1.bc4c04d71aba5dfc098278f168bbd962p-2,
+    0x1.58ad76cccb8f4p1
+  },
+  { // Entry 972
+    -0x1.4be4979c5efa871d30ae1cfa66389199p-1,
+    -0x1.37d9e563f5202p1
+  },
+  { // Entry 973
+    0x1.4be4979c5efa871d30ae1cfa66389199p-1,
+    0x1.37d9e563f5202p1
+  },
+  { // Entry 974
+    -0x1.a3ed9e25293822168958cce1e09f7c11p-1,
+    -0x1.170653fb1eb10p1
+  },
+  { // Entry 975
+    0x1.a3ed9e25293822168958cce1e09f7c11p-1,
+    0x1.170653fb1eb10p1
+  },
+  { // Entry 976
+    -0x1.e07eeeda109c62b340dc36e92169648dp-1,
+    -0x1.ec6585249083cp0
+  },
+  { // Entry 977
+    0x1.e07eeeda109c62b340dc36e92169648dp-1,
+    0x1.ec6585249083cp0
+  },
+  { // Entry 978
+    -0x1.fda254c27a01dd954db3aea505e49453p-1,
+    -0x1.aabe6252e3a58p0
+  },
+  { // Entry 979
+    0x1.fda254c27a01dd954db3aea505e49453p-1,
+    0x1.aabe6252e3a58p0
+  },
+  { // Entry 980
+    -0x1.f96fe405f1aca02e8f4fd433e59aa973p-1,
+    -0x1.69173f8136c74p0
+  },
+  { // Entry 981
+    0x1.f96fe405f1aca02e8f4fd433e59aa973p-1,
+    0x1.69173f8136c74p0
+  },
+  { // Entry 982
+    -0x1.d42de42dce13ef040bb1040e3148d7dep-1,
+    -0x1.27701caf89e90p0
+  },
+  { // Entry 983
+    0x1.d42de42dce13ef040bb1040e3148d7dep-1,
+    0x1.27701caf89e90p0
+  },
+  { // Entry 984
+    -0x1.904c37505de5930812e3a2a94feaa51bp-1,
+    -0x1.cb91f3bbba157p-1
+  },
+  { // Entry 985
+    0x1.904c37505de5930812e3a2a94feaa51bp-1,
+    0x1.cb91f3bbba157p-1
+  },
+  { // Entry 986
+    -0x1.323b8b1fb4bb626dd40cacd74963ac6cp-1,
+    -0x1.4843ae186058ep-1
+  },
+  { // Entry 987
+    0x1.323b8b1fb4bb626dd40cacd74963ac6cp-1,
+    0x1.4843ae186058ep-1
+  },
+  { // Entry 988
+    -0x1.8045fe64e6308bb5c6ce35f834b93c63p-2,
+    -0x1.89ead0ea0d38ap-2
+  },
+  { // Entry 989
+    0x1.8045fe64e6308bb5c6ce35f834b93c63p-2,
+    0x1.89ead0ea0d38ap-2
+  },
+  { // Entry 990
+    -0x1.05e4761ab8dec44ed0fa30d335049c40p-3,
+    -0x1.069c8b46b37f0p-3
+  },
+  { // Entry 991
+    0x1.05e4761ab8dec44ed0fa30d335049c40p-3,
+    0x1.069c8b46b37f0p-3
+  },
+  { // Entry 992
+    0x1.05e4761ab8d31d00e656372c5c04aa6ep-3,
+    0x1.069c8b46b3734p-3
+  },
+  { // Entry 993
+    -0x1.05e4761ab8d31d00e656372c5c04aa6ep-3,
+    -0x1.069c8b46b3734p-3
+  },
+  { // Entry 994
+    0x1.8045fe64e62b19a094399502afb76e5cp-2,
+    0x1.89ead0ea0d32cp-2
+  },
+  { // Entry 995
+    -0x1.8045fe64e62b19a094399502afb76e5cp-2,
+    -0x1.89ead0ea0d32cp-2
+  },
+  { // Entry 996
+    0x1.323b8b1fb4b907c416d23b04e0ec0e72p-1,
+    0x1.4843ae186055fp-1
+  },
+  { // Entry 997
+    -0x1.323b8b1fb4b907c416d23b04e0ec0e72p-1,
+    -0x1.4843ae186055fp-1
+  },
+  { // Entry 998
+    0x1.904c37505de3be2ace17ca5487750231p-1,
+    0x1.cb91f3bbba128p-1
+  },
+  { // Entry 999
+    -0x1.904c37505de3be2ace17ca5487750231p-1,
+    -0x1.cb91f3bbba128p-1
+  },
+  { // Entry 1000
+    0x1.d42de42dce12b82466f2fcb63b294751p-1,
+    0x1.27701caf89e78p0
+  },
+  { // Entry 1001
+    -0x1.d42de42dce12b82466f2fcb63b294751p-1,
+    -0x1.27701caf89e78p0
+  },
+  { // Entry 1002
+    0x1.f96fe405f1ac259bf192fd1cf64e2f12p-1,
+    0x1.69173f8136c5cp0
+  },
+  { // Entry 1003
+    -0x1.f96fe405f1ac259bf192fd1cf64e2f12p-1,
+    -0x1.69173f8136c5cp0
+  },
+  { // Entry 1004
+    0x1.fda254c27a02275432d77dd6f9704644p-1,
+    0x1.aabe6252e3a40p0
+  },
+  { // Entry 1005
+    -0x1.fda254c27a02275432d77dd6f9704644p-1,
+    -0x1.aabe6252e3a40p0
+  },
+  { // Entry 1006
+    0x1.e07eeeda109d6bf0c935fa10b1280c6dp-1,
+    0x1.ec65852490824p0
+  },
+  { // Entry 1007
+    -0x1.e07eeeda109d6bf0c935fa10b1280c6dp-1,
+    -0x1.ec65852490824p0
+  },
+  { // Entry 1008
+    0x1.a3ed9e252939d9793fb2f6f75e5c76e7p-1,
+    0x1.170653fb1eb04p1
+  },
+  { // Entry 1009
+    -0x1.a3ed9e252939d9793fb2f6f75e5c76e7p-1,
+    -0x1.170653fb1eb04p1
+  },
+  { // Entry 1010
+    0x1.4be4979c5efccfe78ea0b6afb0cbba37p-1,
+    0x1.37d9e563f51f6p1
+  },
+  { // Entry 1011
+    -0x1.4be4979c5efccfe78ea0b6afb0cbba37p-1,
+    -0x1.37d9e563f51f6p1
+  },
+  { // Entry 1012
+    0x1.bc4c04d71abfc5df69589a45d5e3196ep-2,
+    0x1.58ad76cccb8e8p1
+  },
+  { // Entry 1013
+    -0x1.bc4c04d71abfc5df69589a45d5e3196ep-2,
+    -0x1.58ad76cccb8e8p1
+  },
+  { // Entry 1014
+    0x1.877e2cd4f70609b1f062295b64aed4bdp-3,
+    0x1.79810835a1fdap1
+  },
+  { // Entry 1015
+    -0x1.877e2cd4f70609b1f062295b64aed4bdp-3,
+    -0x1.79810835a1fdap1
+  },
+  { // Entry 1016
+    -0x1.066e7eb76f4ac293f46486dc328d450bp-4,
+    0x1.9a54999e786ccp1
+  },
+  { // Entry 1017
+    0x1.066e7eb76f4ac293f46486dc328d450bp-4,
+    -0x1.9a54999e786ccp1
+  },
+  { // Entry 1018
+    -0x1.42abba8c72f770595ffe3135a0e0ad83p-2,
+    0x1.bb282b074edbep1
+  },
+  { // Entry 1019
+    0x1.42abba8c72f770595ffe3135a0e0ad83p-2,
+    -0x1.bb282b074edbep1
+  },
+  { // Entry 1020
+    -0x1.175059bf0d406e2fe014e880dd29cfacp-1,
+    0x1.dbfbbc70254b0p1
+  },
+  { // Entry 1021
+    0x1.175059bf0d406e2fe014e880dd29cfacp-1,
+    -0x1.dbfbbc70254b0p1
+  },
+  { // Entry 1022
+    -0x1.7b05b7b6c6116155f0dc551e316e1e0bp-1,
+    0x1.fccf4dd8fbba2p1
+  },
+  { // Entry 1023
+    0x1.7b05b7b6c6116155f0dc551e316e1e0bp-1,
+    -0x1.fccf4dd8fbba2p1
+  },
+  { // Entry 1024
+    -0x1.c5f058230e7ebeb7616779e16fa9b537p-1,
+    0x1.0ed16fa0e914ap2
+  },
+  { // Entry 1025
+    0x1.c5f058230e7ebeb7616779e16fa9b537p-1,
+    -0x1.0ed16fa0e914ap2
+  },
+  { // Entry 1026
+    -0x1.f329c0558e95fa333d5d2d44d654777cp-1,
+    0x1.1f3b3855544c3p2
+  },
+  { // Entry 1027
+    0x1.f329c0558e95fa333d5d2d44d654777cp-1,
+    -0x1.1f3b3855544c3p2
+  },
+  { // Entry 1028
+    -0x1.ffbca846c4fcb237c2947b35b037a2p-1,
+    0x1.2fa50109bf83cp2
+  },
+  { // Entry 1029
+    0x1.ffbca846c4fcb237c2947b35b037a2p-1,
+    -0x1.2fa50109bf83cp2
+  },
+  { // Entry 1030
+    -0x1.ead6834909ba0ee69b31e1970df1bb8bp-1,
+    0x1.400ec9be2abb5p2
+  },
+  { // Entry 1031
+    0x1.ead6834909ba0ee69b31e1970df1bb8bp-1,
+    -0x1.400ec9be2abb5p2
+  },
+  { // Entry 1032
+    -0x1.b5d545b109c1232b61dd28d8035d95cbp-1,
+    0x1.5078927295f2ep2
+  },
+  { // Entry 1033
+    0x1.b5d545b109c1232b61dd28d8035d95cbp-1,
+    -0x1.5078927295f2ep2
+  },
+  { // Entry 1034
+    -0x1.643080d67ace48c0dd1fe3a06bbc4bf5p-1,
+    0x1.60e25b27012a7p2
+  },
+  { // Entry 1035
+    0x1.643080d67ace48c0dd1fe3a06bbc4bf5p-1,
+    -0x1.60e25b27012a7p2
+  },
+  { // Entry 1036
+    -0x1.f67ea975b86f5d4aa92716cc077473a7p-2,
+    0x1.714c23db6c620p2
+  },
+  { // Entry 1037
+    0x1.f67ea975b86f5d4aa92716cc077473a7p-2,
+    -0x1.714c23db6c620p2
+  },
+  { // Entry 1038
+    -0x1.03be06f97cc4d78fdccbca1d40e86011p-2,
+    0x1.81b5ec8fd7999p2
+  },
+  { // Entry 1039
+    0x1.03be06f97cc4d78fdccbca1d40e86011p-2,
+    -0x1.81b5ec8fd7999p2
+  },
+  { // Entry 1040
+    0x1.efb26ef930c4c3fa3245963c1dcec0a6p-5,
+    0x1.effffffffffffp-5
+  },
+  { // Entry 1041
+    -0x1.efb26ef930c4c3fa3245963c1dcec0a6p-5,
+    -0x1.effffffffffffp-5
+  },
+  { // Entry 1042
+    0x1.efb26ef930c4d3f2b0dbe1931ba5ae64p-5,
+    0x1.fp-5
+  },
+  { // Entry 1043
+    -0x1.efb26ef930c4d3f2b0dbe1931ba5ae64p-5,
+    -0x1.fp-5
+  },
+  { // Entry 1044
+    0x1.efb26ef930c4e3eb2f722cea197c2036p-5,
+    0x1.f000000000001p-5
+  },
+  { // Entry 1045
+    -0x1.efb26ef930c4e3eb2f722cea197c2036p-5,
+    -0x1.f000000000001p-5
+  },
+  { // Entry 1046
+    0x1.f6baaa131de633ad4e0e7d6465d12a05p-4,
+    0x1.f7fffffffffffp-4
+  },
+  { // Entry 1047
+    -0x1.f6baaa131de633ad4e0e7d6465d12a05p-4,
+    -0x1.f7fffffffffffp-4
+  },
+  { // Entry 1048
+    0x1.f6baaa131de6438e5611279864fe7663p-4,
+    0x1.f80p-4
+  },
+  { // Entry 1049
+    -0x1.f6baaa131de6438e5611279864fe7663p-4,
+    -0x1.f80p-4
+  },
+  { // Entry 1050
+    0x1.f6baaa131de6536f5e13d1cc6429cc07p-4,
+    0x1.f800000000001p-4
+  },
+  { // Entry 1051
+    -0x1.f6baaa131de6536f5e13d1cc6429cc07p-4,
+    -0x1.f800000000001p-4
+  },
+  { // Entry 1052
+    0x1.4a8c3b4e9c7ff00a36e061a0d2295093p-3,
+    0x1.4bfffffffffffp-3
+  },
+  { // Entry 1053
+    -0x1.4a8c3b4e9c7ff00a36e061a0d2295093p-3,
+    -0x1.4bfffffffffffp-3
+  },
+  { // Entry 1054
+    0x1.4a8c3b4e9c7fffd48305f44a42f5f50fp-3,
+    0x1.4c0p-3
+  },
+  { // Entry 1055
+    -0x1.4a8c3b4e9c7fffd48305f44a42f5f50fp-3,
+    -0x1.4c0p-3
+  },
+  { // Entry 1056
+    0x1.4a8c3b4e9c800f9ecf2b86f3b3bd6f5ap-3,
+    0x1.4c00000000001p-3
+  },
+  { // Entry 1057
+    -0x1.4a8c3b4e9c800f9ecf2b86f3b3bd6f5ap-3,
+    -0x1.4c00000000001p-3
+  },
+  { // Entry 1058
+    0x1.2e9cd95baba325fe6067233d4496aaacp-2,
+    0x1.3333333333332p-2
+  },
+  { // Entry 1059
+    -0x1.2e9cd95baba325fe6067233d4496aaacp-2,
+    -0x1.3333333333332p-2
+  },
+  { // Entry 1060
+    0x1.2e9cd95baba335476f513ac221d078c7p-2,
+    0x1.3333333333333p-2
+  },
+  { // Entry 1061
+    -0x1.2e9cd95baba335476f513ac221d078c7p-2,
+    -0x1.3333333333333p-2
+  },
+  { // Entry 1062
+    0x1.2e9cd95baba344907e3b5246fef75d15p-2,
+    0x1.3333333333334p-2
+  },
+  { // Entry 1063
+    -0x1.2e9cd95baba344907e3b5246fef75d15p-2,
+    -0x1.3333333333334p-2
+  },
+  { // Entry 1064
+    0x1.3faefc7a5466ef3045c3f1be716ad568p-1,
+    0x1.594317acc4ef8p-1
+  },
+  { // Entry 1065
+    -0x1.3faefc7a5466ef3045c3f1be716ad568p-1,
+    -0x1.594317acc4ef8p-1
+  },
+  { // Entry 1066
+    0x1.3faefc7a5466fbafbca027b6e8db8c04p-1,
+    0x1.594317acc4ef9p-1
+  },
+  { // Entry 1067
+    -0x1.3faefc7a5466fbafbca027b6e8db8c04p-1,
+    -0x1.594317acc4ef9p-1
+  },
+  { // Entry 1068
+    0x1.3faefc7a5467082f337c5daf5ffc56e2p-1,
+    0x1.594317acc4efap-1
+  },
+  { // Entry 1069
+    -0x1.3faefc7a5467082f337c5daf5ffc56e2p-1,
+    -0x1.594317acc4efap-1
+  },
+  { // Entry 1070
+    0x1.6888a4e134b2def5bea51f4cd7d647c6p-1,
+    0x1.8ffffffffffffp-1
+  },
+  { // Entry 1071
+    -0x1.6888a4e134b2def5bea51f4cd7d647c6p-1,
+    -0x1.8ffffffffffffp-1
+  },
+  { // Entry 1072
+    0x1.6888a4e134b2ea520b226eca8694b3a2p-1,
+    0x1.9p-1
+  },
+  { // Entry 1073
+    -0x1.6888a4e134b2ea520b226eca8694b3a2p-1,
+    -0x1.9p-1
+  },
+  { // Entry 1074
+    0x1.6888a4e134b2f5ae579fbe4834f8fd55p-1,
+    0x1.9000000000001p-1
+  },
+  { // Entry 1075
+    -0x1.6888a4e134b2f5ae579fbe4834f8fd55p-1,
+    -0x1.9000000000001p-1
+  },
+  { // Entry 1076
+    -0.0,
+    -0x1.0p-1074
+  },
+  { // Entry 1077
+    0.0,
+    0x1.0p-1074
+  },
+  { // Entry 1078
+    -0.0,
+    -0.0
+  },
+  { // Entry 1079
+    0.0,
+    0x1.0p-1074
+  },
+  { // Entry 1080
+    -0.0,
+    -0x1.0p-1074
+  },
+  { // Entry 1081
+    0x1.91f65f10dd812a0b95ff71871ab48207p-5,
+    0x1.921fb54442d17p-5
+  },
+  { // Entry 1082
+    -0x1.91f65f10dd812a0b95ff71871ab48207p-5,
+    -0x1.921fb54442d17p-5
+  },
+  { // Entry 1083
+    0x1.91f65f10dd813a06a6f12e3dd9a6a41ep-5,
+    0x1.921fb54442d18p-5
+  },
+  { // Entry 1084
+    -0x1.91f65f10dd813a06a6f12e3dd9a6a41ep-5,
+    -0x1.921fb54442d18p-5
+  },
+  { // Entry 1085
+    0x1.91f65f10dd814a01b7e2eaf4989861b7p-5,
+    0x1.921fb54442d19p-5
+  },
+  { // Entry 1086
+    -0x1.91f65f10dd814a01b7e2eaf4989861b7p-5,
+    -0x1.921fb54442d19p-5
+  },
+  { // Entry 1087
+    0x1.917a6bc29b42a9cd2e787ee00ca8f8e3p-4,
+    0x1.921fb54442d17p-4
+  },
+  { // Entry 1088
+    -0x1.917a6bc29b42a9cd2e787ee00ca8f8e3p-4,
+    -0x1.921fb54442d17p-4
+  },
+  { // Entry 1089
+    0x1.917a6bc29b42b9b9754a67729f79346bp-4,
+    0x1.921fb54442d18p-4
+  },
+  { // Entry 1090
+    -0x1.917a6bc29b42b9b9754a67729f79346bp-4,
+    -0x1.921fb54442d18p-4
+  },
+  { // Entry 1091
+    0x1.917a6bc29b42c9a5bc1c50053247de78p-4,
+    0x1.921fb54442d19p-4
+  },
+  { // Entry 1092
+    -0x1.917a6bc29b42c9a5bc1c50053247de78p-4,
+    -0x1.921fb54442d19p-4
+  },
+  { // Entry 1093
+    0x1.8f8b83c69a60975f98453886f953a0e5p-3,
+    0x1.921fb54442d17p-3
+  },
+  { // Entry 1094
+    -0x1.8f8b83c69a60975f98453886f953a0e5p-3,
+    -0x1.921fb54442d17p-3
+  },
+  { // Entry 1095
+    0x1.8f8b83c69a60a710e42d3435516ddaccp-3,
+    0x1.921fb54442d18p-3
+  },
+  { // Entry 1096
+    -0x1.8f8b83c69a60a710e42d3435516ddaccp-3,
+    -0x1.921fb54442d18p-3
+  },
+  { // Entry 1097
+    0x1.8f8b83c69a60b6c230152fe3a981d686p-3,
+    0x1.921fb54442d19p-3
+  },
+  { // Entry 1098
+    -0x1.8f8b83c69a60b6c230152fe3a981d686p-3,
+    -0x1.921fb54442d19p-3
+  },
+  { // Entry 1099
+    0x1.87de2a6aea961a3e9dedea57fe7e6514p-2,
+    0x1.921fb54442d17p-2
+  },
+  { // Entry 1100
+    -0x1.87de2a6aea961a3e9dedea57fe7e6514p-2,
+    -0x1.921fb54442d17p-2
+  },
+  { // Entry 1101
+    0x1.87de2a6aea962906d3d5839ea1a5bcf0p-2,
+    0x1.921fb54442d18p-2
+  },
+  { // Entry 1102
+    -0x1.87de2a6aea962906d3d5839ea1a5bcf0p-2,
+    -0x1.921fb54442d18p-2
+  },
+  { // Entry 1103
+    0x1.87de2a6aea9637cf09bd1ce544b496eap-2,
+    0x1.921fb54442d19p-2
+  },
+  { // Entry 1104
+    -0x1.87de2a6aea9637cf09bd1ce544b496eap-2,
+    -0x1.921fb54442d19p-2
+  },
+  { // Entry 1105
+    0x1.6a09e667f3bcba99afb0135729457874p-1,
+    0x1.921fb54442d17p-1
+  },
+  { // Entry 1106
+    -0x1.6a09e667f3bcba99afb0135729457874p-1,
+    -0x1.921fb54442d17p-1
+  },
+  { // Entry 1107
+    0x1.6a09e667f3bcc5e9fee352f50fd3f4e9p-1,
+    0x1.921fb54442d18p-1
+  },
+  { // Entry 1108
+    -0x1.6a09e667f3bcc5e9fee352f50fd3f4e9p-1,
+    -0x1.921fb54442d18p-1
+  },
+  { // Entry 1109
+    0x1.6a09e667f3bcd13a4e169292f607eee5p-1,
+    0x1.921fb54442d19p-1
+  },
+  { // Entry 1110
+    -0x1.6a09e667f3bcd13a4e169292f607eee5p-1,
+    -0x1.921fb54442d19p-1
+  },
+  { // Entry 1111
+    0x1.fffffffffffffffffffffffffe5f56ffp-1,
+    0x1.921fb54442d17p0
+  },
+  { // Entry 1112
+    -0x1.fffffffffffffffffffffffffe5f56ffp-1,
+    -0x1.921fb54442d17p0
+  },
+  { // Entry 1113
+    0x1.ffffffffffffffffffffffffffec8831p-1,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 1114
+    -0x1.ffffffffffffffffffffffffffec8831p-1,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 1115
+    0x1.ffffffffffffffffffffffffff79b963p-1,
+    0x1.921fb54442d19p0
+  },
+  { // Entry 1116
+    -0x1.ffffffffffffffffffffffffff79b963p-1,
+    -0x1.921fb54442d19p0
+  },
+  { // Entry 1117
+    0x1.469898cc51701b839a252049bfaeed42p-51,
+    0x1.921fb54442d17p1
+  },
+  { // Entry 1118
+    -0x1.469898cc51701b839a252049bfaeed42p-51,
+    -0x1.921fb54442d17p1
+  },
+  { // Entry 1119
+    0x1.1a62633145c06e0e689481270436e2edp-53,
+    0x1.921fb54442d18p1
+  },
+  { // Entry 1120
+    -0x1.1a62633145c06e0e689481270436e2edp-53,
+    -0x1.921fb54442d18p1
+  },
+  { // Entry 1121
+    -0x1.72cece675d1fc8f8cbb5bf6c7d5bbc5cp-52,
+    0x1.921fb54442d19p1
+  },
+  { // Entry 1122
+    0x1.72cece675d1fc8f8cbb5bf6c7d5bbc5cp-52,
+    -0x1.921fb54442d19p1
+  },
+  { // Entry 1123
+    -0x1.469898cc51701b839a252049bb87ce1bp-50,
+    0x1.921fb54442d17p2
+  },
+  { // Entry 1124
+    0x1.469898cc51701b839a252049bb87ce1bp-50,
+    -0x1.921fb54442d17p2
+  },
+  { // Entry 1125
+    -0x1.1a62633145c06e0e68948127040bf003p-52,
+    0x1.921fb54442d18p2
+  },
+  { // Entry 1126
+    0x1.1a62633145c06e0e68948127040bf003p-52,
+    -0x1.921fb54442d18p2
+  },
+  { // Entry 1127
+    0x1.72cece675d1fc8f8cbb5bf6c7bd6bf4dp-51,
+    0x1.921fb54442d19p2
+  },
+  { // Entry 1128
+    -0x1.72cece675d1fc8f8cbb5bf6c7bd6bf4dp-51,
+    -0x1.921fb54442d19p2
+  },
+  { // Entry 1129
+    -0x1.469898cc51701b839a252049aaeb5182p-49,
+    0x1.921fb54442d17p3
+  },
+  { // Entry 1130
+    0x1.469898cc51701b839a252049aaeb5182p-49,
+    -0x1.921fb54442d17p3
+  },
+  { // Entry 1131
+    -0x1.1a62633145c06e0e689481270360245cp-51,
+    0x1.921fb54442d18p3
+  },
+  { // Entry 1132
+    0x1.1a62633145c06e0e689481270360245cp-51,
+    -0x1.921fb54442d18p3
+  },
+  { // Entry 1133
+    0x1.72cece675d1fc8f8cbb5bf6c75c2cb0ep-50,
+    0x1.921fb54442d19p3
+  },
+  { // Entry 1134
+    -0x1.72cece675d1fc8f8cbb5bf6c75c2cb0ep-50,
+    -0x1.921fb54442d19p3
+  },
+  { // Entry 1135
+    -0x1.469898cc51701b839a25204968795f1cp-48,
+    0x1.921fb54442d17p4
+  },
+  { // Entry 1136
+    0x1.469898cc51701b839a25204968795f1cp-48,
+    -0x1.921fb54442d17p4
+  },
+  { // Entry 1137
+    -0x1.1a62633145c06e0e6894812700b0f5bfp-50,
+    0x1.921fb54442d18p4
+  },
+  { // Entry 1138
+    0x1.1a62633145c06e0e6894812700b0f5bfp-50,
+    -0x1.921fb54442d18p4
+  },
+  { // Entry 1139
+    0x1.72cece675d1fc8f8cbb5bf6c5d72fa11p-49,
+    0x1.921fb54442d19p4
+  },
+  { // Entry 1140
+    -0x1.72cece675d1fc8f8cbb5bf6c5d72fa11p-49,
+    -0x1.921fb54442d19p4
+  },
+  { // Entry 1141
+    -0x1.469898cc51701b839a2520485eb19584p-47,
+    0x1.921fb54442d17p5
+  },
+  { // Entry 1142
+    0x1.469898cc51701b839a2520485eb19584p-47,
+    -0x1.921fb54442d17p5
+  },
+  { // Entry 1143
+    -0x1.1a62633145c06e0e68948126f5f43b4cp-49,
+    0x1.921fb54442d18p5
+  },
+  { // Entry 1144
+    0x1.1a62633145c06e0e68948126f5f43b4cp-49,
+    -0x1.921fb54442d18p5
+  },
+  { // Entry 1145
+    0x1.72cece675d1fc8f8cbb5bf6bfc33b61fp-48,
+    0x1.921fb54442d19p5
+  },
+  { // Entry 1146
+    -0x1.72cece675d1fc8f8cbb5bf6bfc33b61fp-48,
+    -0x1.921fb54442d19p5
+  },
+  { // Entry 1147
+    -0x1.469898cc51701b839a25204437926f25p-46,
+    0x1.921fb54442d17p6
+  },
+  { // Entry 1148
+    0x1.469898cc51701b839a25204437926f25p-46,
+    -0x1.921fb54442d17p6
+  },
+  { // Entry 1149
+    -0x1.1a62633145c06e0e68948126cb01517dp-48,
+    0x1.921fb54442d18p6
+  },
+  { // Entry 1150
+    0x1.1a62633145c06e0e68948126cb01517dp-48,
+    -0x1.921fb54442d18p6
+  },
+  { // Entry 1151
+    0x1.72cece675d1fc8f8cbb5bf6a7736a658p-47,
+    0x1.921fb54442d19p6
+  },
+  { // Entry 1152
+    -0x1.72cece675d1fc8f8cbb5bf6a7736a658p-47,
+    -0x1.921fb54442d19p6
+  },
+  { // Entry 1153
+    -0x1.469898cc51701b839a2520339b15d5aap-45,
+    0x1.921fb54442d17p7
+  },
+  { // Entry 1154
+    0x1.469898cc51701b839a2520339b15d5aap-45,
+    -0x1.921fb54442d17p7
+  },
+  { // Entry 1155
+    -0x1.1a62633145c06e0e689481261f35aa43p-47,
+    0x1.921fb54442d18p7
+  },
+  { // Entry 1156
+    0x1.1a62633145c06e0e689481261f35aa43p-47,
+    -0x1.921fb54442d18p7
+  },
+  { // Entry 1157
+    0x1.72cece675d1fc8f8cbb5bf646342673ap-46,
+    0x1.921fb54442d19p7
+  },
+  { // Entry 1158
+    -0x1.72cece675d1fc8f8cbb5bf646342673ap-46,
+    -0x1.921fb54442d19p7
+  },
+  { // Entry 1159
+    0x1.6a09e667f3bcffa60c0f53340fd24904p-1,
+    0x1.2d97c7f3321d1p1
+  },
+  { // Entry 1160
+    -0x1.6a09e667f3bcffa60c0f53340fd24904p-1,
+    -0x1.2d97c7f3321d1p1
+  },
+  { // Entry 1161
+    0x1.6a09e667f3bcd264cf4254bc7ab0c9fap-1,
+    0x1.2d97c7f3321d2p1
+  },
+  { // Entry 1162
+    -0x1.6a09e667f3bcd264cf4254bc7ab0c9fap-1,
+    -0x1.2d97c7f3321d2p1
+  },
+  { // Entry 1163
+    0x1.6a09e667f3bca52392755644dfe72357p-1,
+    0x1.2d97c7f3321d3p1
+  },
+  { // Entry 1164
+    -0x1.6a09e667f3bca52392755644dfe72357p-1,
+    -0x1.2d97c7f3321d3p1
+  },
+  { // Entry 1165
+    -0x1.6a09e667f3bc8c2df1b752b606a0a472p-1,
+    0x1.f6a7a2955385dp1
+  },
+  { // Entry 1166
+    0x1.6a09e667f3bc8c2df1b752b606a0a472p-1,
+    -0x1.f6a7a2955385dp1
+  },
+  { // Entry 1167
+    -0x1.6a09e667f3bcb96f2e84512da488ff2dp-1,
+    0x1.f6a7a2955385ep1
+  },
+  { // Entry 1168
+    0x1.6a09e667f3bcb96f2e84512da488ff2dp-1,
+    -0x1.f6a7a2955385ep1
+  },
+  { // Entry 1169
+    -0x1.6a09e667f3bce6b06b514fa53cc9324fp-1,
+    0x1.f6a7a2955385fp1
+  },
+  { // Entry 1170
+    0x1.6a09e667f3bce6b06b514fa53cc9324fp-1,
+    -0x1.f6a7a2955385fp1
+  },
+  { // Entry 1171
+    -0x1.ffffffffffffffffffffffffe8b27b6ap-1,
+    0x1.2d97c7f3321d1p2
+  },
+  { // Entry 1172
+    0x1.ffffffffffffffffffffffffe8b27b6ap-1,
+    -0x1.2d97c7f3321d1p2
+  },
+  { // Entry 1173
+    -0x1.ffffffffffffffffffffffffff50c9bdp-1,
+    0x1.2d97c7f3321d2p2
+  },
+  { // Entry 1174
+    0x1.ffffffffffffffffffffffffff50c9bdp-1,
+    -0x1.2d97c7f3321d2p2
+  },
+  { // Entry 1175
+    -0x1.fffffffffffffffffffffffff5ef1810p-1,
+    0x1.2d97c7f3321d3p2
+  },
+  { // Entry 1176
+    0x1.fffffffffffffffffffffffff5ef1810p-1,
+    -0x1.2d97c7f3321d3p2
+  },
+  { // Entry 1177
+    -0x1.6a09e667f3bd3962193b5373069ba0c2p-1,
+    0x1.5fdbbe9bba774p2
+  },
+  { // Entry 1178
+    0x1.6a09e667f3bd3962193b5373069ba0c2p-1,
+    -0x1.5fdbbe9bba774p2
+  },
+  { // Entry 1179
+    -0x1.6a09e667f3bcdedf9fa15683e51f7e60p-1,
+    0x1.5fdbbe9bba775p2
+  },
+  { // Entry 1180
+    0x1.6a09e667f3bcdedf9fa15683e51f7e60p-1,
+    -0x1.5fdbbe9bba775p2
+  },
+  { // Entry 1181
+    -0x1.6a09e667f3bc845d26075994ad02bd98p-1,
+    0x1.5fdbbe9bba776p2
+  },
+  { // Entry 1182
+    0x1.6a09e667f3bc845d26075994ad02bd98p-1,
+    -0x1.5fdbbe9bba776p2
+  },
+  { // Entry 1183
+    0x1.6a09e667f3bc5271e48b5276f438579fp-1,
+    0x1.c463abeccb2bap2
+  },
+  { // Entry 1184
+    -0x1.6a09e667f3bc5271e48b5276f438579fp-1,
+    -0x1.c463abeccb2bap2
+  },
+  { // Entry 1185
+    0x1.6a09e667f3bcacf45e254f6638cfe8c6p-1,
+    0x1.c463abeccb2bbp2
+  },
+  { // Entry 1186
+    -0x1.6a09e667f3bcacf45e254f6638cfe8c6p-1,
+    -0x1.c463abeccb2bbp2
+  },
+  { // Entry 1187
+    0x1.6a09e667f3bd0776d7bf4c5566c6db87p-1,
+    0x1.c463abeccb2bcp2
+  },
+  { // Entry 1188
+    -0x1.6a09e667f3bd0776d7bf4c5566c6db87p-1,
+    -0x1.c463abeccb2bcp2
+  },
+  { // Entry 1189
+    0x1.ffffffffffffffffffffffffe31174f5p-1,
+    0x1.f6a7a2955385dp2
+  },
+  { // Entry 1190
+    -0x1.ffffffffffffffffffffffffe31174f5p-1,
+    -0x1.f6a7a2955385dp2
+  },
+  { // Entry 1191
+    0x1.fffffffffffffffffffffffffe194cd4p-1,
+    0x1.f6a7a2955385ep2
+  },
+  { // Entry 1192
+    -0x1.fffffffffffffffffffffffffe194cd4p-1,
+    -0x1.f6a7a2955385ep2
+  },
+  { // Entry 1193
+    0x1.fffffffffffffffffffffffff92124b4p-1,
+    0x1.f6a7a2955385fp2
+  },
+  { // Entry 1194
+    -0x1.fffffffffffffffffffffffff92124b4p-1,
+    -0x1.f6a7a2955385fp2
+  },
+  { // Entry 1195
+    0x1.6a09e667f3bdfae1dcce4f18665681c6p-1,
+    0x1.1475cc9eedeffp3
+  },
+  { // Entry 1196
+    -0x1.6a09e667f3bdfae1dcce4f18665681c6p-1,
+    -0x1.1475cc9eedeffp3
+  },
+  { // Entry 1197
+    0x1.6a09e667f3bd45dce99a553a6d7d8065p-1,
+    0x1.1475cc9eedfp3
+  },
+  { // Entry 1198
+    -0x1.6a09e667f3bd45dce99a553a6d7d8065p-1,
+    -0x1.1475cc9eedfp3
+  },
+  { // Entry 1199
+    0x1.6a09e667f3bc90d7f6665b5c1a22056ap-1,
+    0x1.1475cc9eedf01p3
+  },
+  { // Entry 1200
+    -0x1.6a09e667f3bc90d7f6665b5c1a22056ap-1,
+    -0x1.1475cc9eedf01p3
+  },
+  { // Entry 1201
+    0x1.34f272993d1414a2b39bd8373e0d6b94p-49,
+    0x1.2d97c7f3321d1p3
+  },
+  { // Entry 1202
+    -0x1.34f272993d1414a2b39bd8373e0d6b94p-49,
+    -0x1.2d97c7f3321d1p3
+  },
+  { // Entry 1203
+    0x1.a79394c9e8a0a5159cdec1ba85a688bdp-52,
+    0x1.2d97c7f3321d2p3
+  },
+  { // Entry 1204
+    -0x1.a79394c9e8a0a5159cdec1ba85a688bdp-52,
+    -0x1.2d97c7f3321d2p3
+  },
+  { // Entry 1205
+    -0x1.961b1acd85d7d6ba98c84f9153c0cc16p-50,
+    0x1.2d97c7f3321d3p3
+  },
+  { // Entry 1206
+    0x1.961b1acd85d7d6ba98c84f9153c0cc16p-50,
+    -0x1.2d97c7f3321d3p3
+  },
+  { // Entry 1207
+    -0x1.6a09e667f3bb90f220f856d0b1a406c3p-1,
+    0x1.46b9c347764a2p3
+  },
+  { // Entry 1208
+    0x1.6a09e667f3bb90f220f856d0b1a406c3p-1,
+    -0x1.46b9c347764a2p3
+  },
+  { // Entry 1209
+    -0x1.6a09e667f3bc45f7142c50af84f26c75p-1,
+    0x1.46b9c347764a3p3
+  },
+  { // Entry 1210
+    0x1.6a09e667f3bc45f7142c50af84f26c75p-1,
+    -0x1.46b9c347764a3p3
+  },
+  { // Entry 1211
+    -0x1.6a09e667f3bcfafc07604a8dfdbe588dp-1,
+    0x1.46b9c347764a4p3
+  },
+  { // Entry 1212
+    0x1.6a09e667f3bcfafc07604a8dfdbe588dp-1,
+    -0x1.46b9c347764a4p3
+  },
+  { // Entry 1213
+    -0x1.ffffffffffffffffffffffff9d634e9fp-1,
+    0x1.5fdbbe9bba774p3
+  },
+  { // Entry 1214
+    0x1.ffffffffffffffffffffffff9d634e9fp-1,
+    -0x1.5fdbbe9bba774p3
+  },
+  { // Entry 1215
+    -0x1.fffffffffffffffffffffffffc461178p-1,
+    0x1.5fdbbe9bba775p3
+  },
+  { // Entry 1216
+    0x1.fffffffffffffffffffffffffc461178p-1,
+    -0x1.5fdbbe9bba775p3
+  },
+  { // Entry 1217
+    -0x1.ffffffffffffffffffffffffdb28d451p-1,
+    0x1.5fdbbe9bba776p3
+  },
+  { // Entry 1218
+    0x1.ffffffffffffffffffffffffdb28d451p-1,
+    -0x1.5fdbbe9bba776p3
+  },
+  { // Entry 1219
+    -0x1.6a09e667f3be075cad2d50dfc68cd88fp-1,
+    0x1.78fdb9effea45p3
+  },
+  { // Entry 1220
+    0x1.6a09e667f3be075cad2d50dfc68cd88fp-1,
+    -0x1.78fdb9effea45p3
+  },
+  { // Entry 1221
+    -0x1.6a09e667f3bd5257b9f95701d3f13f5dp-1,
+    0x1.78fdb9effea46p3
+  },
+  { // Entry 1222
+    0x1.6a09e667f3bd5257b9f95701d3f13f5dp-1,
+    -0x1.78fdb9effea46p3
+  },
+  { // Entry 1223
+    -0x1.6a09e667f3bc9d52c6c55d2386d32c92p-1,
+    0x1.78fdb9effea47p3
+  },
+  { // Entry 1224
+    0x1.6a09e667f3bc9d52c6c55d2386d32c92p-1,
+    -0x1.78fdb9effea47p3
+  },
+  { // Entry 1225
+    0x1.6a09e667f3bb8477509955093bb292bep-1,
+    0x1.ab41b09886fe8p3
+  },
+  { // Entry 1226
+    -0x1.6a09e667f3bb8477509955093bb292bep-1,
+    -0x1.ab41b09886fe8p3
+  },
+  { // Entry 1227
+    0x1.6a09e667f3bc397c43cd4ee8153e60a0p-1,
+    0x1.ab41b09886fe9p3
+  },
+  { // Entry 1228
+    -0x1.6a09e667f3bc397c43cd4ee8153e60a0p-1,
+    -0x1.ab41b09886fe9p3
+  },
+  { // Entry 1229
+    0x1.6a09e667f3bcee81370148c69447b4e7p-1,
+    0x1.ab41b09886feap3
+  },
+  { // Entry 1230
+    -0x1.6a09e667f3bcee81370148c69447b4e7p-1,
+    -0x1.ab41b09886feap3
+  },
+  { // Entry 1231
+    0x1.ffffffffffffffffffffffff922141b4p-1,
+    0x1.c463abeccb2bap3
+  },
+  { // Entry 1232
+    -0x1.ffffffffffffffffffffffff922141b4p-1,
+    -0x1.c463abeccb2bap3
+  },
+  { // Entry 1233
+    0x1.fffffffffffffffffffffffff9d717a7p-1,
+    0x1.c463abeccb2bbp3
+  },
+  { // Entry 1234
+    -0x1.fffffffffffffffffffffffff9d717a7p-1,
+    -0x1.c463abeccb2bbp3
+  },
+  { // Entry 1235
+    0x1.ffffffffffffffffffffffffe18ced9ap-1,
+    0x1.c463abeccb2bcp3
+  },
+  { // Entry 1236
+    -0x1.ffffffffffffffffffffffffe18ced9ap-1,
+    -0x1.c463abeccb2bcp3
+  },
+  { // Entry 1237
+    0x1.6a09e667f3be13d77d8c52a726550eacp-1,
+    0x1.dd85a7410f58bp3
+  },
+  { // Entry 1238
+    -0x1.6a09e667f3be13d77d8c52a726550eacp-1,
+    -0x1.dd85a7410f58bp3
+  },
+  { // Entry 1239
+    0x1.6a09e667f3bd5ed28a5858c939f6ddaap-1,
+    0x1.dd85a7410f58cp3
+  },
+  { // Entry 1240
+    -0x1.6a09e667f3bd5ed28a5858c939f6ddaap-1,
+    -0x1.dd85a7410f58cp3
+  },
+  { // Entry 1241
+    0x1.6a09e667f3bca9cd97245eeaf316330ep-1,
+    0x1.dd85a7410f58dp3
+  },
+  { // Entry 1242
+    -0x1.6a09e667f3bca9cd97245eeaf316330ep-1,
+    -0x1.dd85a7410f58dp3
+  },
+  { // Entry 1243
+    0x1.583ebeff65cc226480ae685c1765dec1p-49,
+    0x1.f6a7a2955385dp3
+  },
+  { // Entry 1244
+    -0x1.583ebeff65cc226480ae685c1765dec1p-49,
+    -0x1.f6a7a2955385dp3
+  },
+  { // Entry 1245
+    0x1.60fafbfd9730899202b9a170c3971e86p-51,
+    0x1.f6a7a2955385ep3
+  },
+  { // Entry 1246
+    -0x1.60fafbfd9730899202b9a170c3971e86p-51,
+    -0x1.f6a7a2955385ep3
+  },
+  { // Entry 1247
+    -0x1.4f8282013467bb36fea32f479753fe7ap-50,
+    0x1.f6a7a2955385fp3
+  },
+  { // Entry 1248
+    0x1.4f8282013467bb36fea32f479753fe7ap-50,
+    -0x1.f6a7a2955385fp3
+  },
+  { // Entry 1249
+    -0x1.6a09e667f3ba0df299d25f82f639251fp-1,
+    0x1.07e4cef4cbd96p4
+  },
+  { // Entry 1250
+    0x1.6a09e667f3ba0df299d25f82f639251fp-1,
+    -0x1.07e4cef4cbd96p4
+  },
+  { // Entry 1251
+    -0x1.6a09e667f3bb77fc803a5341c552fe0fp-1,
+    0x1.07e4cef4cbd97p4
+  },
+  { // Entry 1252
+    0x1.6a09e667f3bb77fc803a5341c552fe0fp-1,
+    -0x1.07e4cef4cbd97p4
+  },
+  { // Entry 1253
+    -0x1.6a09e667f3bce20666a246ff2a62f097p-1,
+    0x1.07e4cef4cbd98p4
+  },
+  { // Entry 1254
+    0x1.6a09e667f3bce20666a246ff2a62f097p-1,
+    -0x1.07e4cef4cbd98p4
+  },
+  { // Entry 1255
+    -0x1.fffffffffffffffffffffffd2531a43dp-1,
+    0x1.1475cc9eedeffp4
+  },
+  { // Entry 1256
+    0x1.fffffffffffffffffffffffd2531a43dp-1,
+    -0x1.1475cc9eedeffp4
+  },
+  { // Entry 1257
+    -0x1.ffffffffffffffffffffffff86437656p-1,
+    0x1.1475cc9eedfp4
+  },
+  { // Entry 1258
+    0x1.ffffffffffffffffffffffff86437656p-1,
+    -0x1.1475cc9eedfp4
+  },
+  { // Entry 1259
+    -0x1.ffffffffffffffffffffffffe755486fp-1,
+    0x1.1475cc9eedf01p4
+  },
+  { // Entry 1260
+    0x1.ffffffffffffffffffffffffe755486fp-1,
+    -0x1.1475cc9eedf01p4
+  },
+  { // Entry 1261
+    -0x1.6a09e667f3bed557411f4e4c114d7357p-1,
+    0x1.2106ca4910068p4
+  },
+  { // Entry 1262
+    0x1.6a09e667f3bed557411f4e4c114d7357p-1,
+    -0x1.2106ca4910068p4
+  },
+  { // Entry 1263
+    -0x1.6a09e667f3bd6b4d5ab75a909f8e5b4cp-1,
+    0x1.2106ca4910069p4
+  },
+  { // Entry 1264
+    0x1.6a09e667f3bd6b4d5ab75a909f8e5b4cp-1,
+    -0x1.2106ca4910069p4
+  },
+  { // Entry 1265
+    -0x1.6a09e667f3bc0143744f66d3c3c55cd9p-1,
+    0x1.2106ca491006ap4
+  },
+  { // Entry 1266
+    0x1.6a09e667f3bc0143744f66d3c3c55cd9p-1,
+    -0x1.2106ca491006ap4
+  },
+  { // Entry 1267
+    -0x1.34f272993d1414a2b39bd83705cec120p-48,
+    0x1.2d97c7f3321d1p4
+  },
+  { // Entry 1268
+    0x1.34f272993d1414a2b39bd83705cec120p-48,
+    -0x1.2d97c7f3321d1p4
+  },
+  { // Entry 1269
+    -0x1.a79394c9e8a0a5159cdec1ba8362b968p-51,
+    0x1.2d97c7f3321d2p4
+  },
+  { // Entry 1270
+    0x1.a79394c9e8a0a5159cdec1ba8362b968p-51,
+    -0x1.2d97c7f3321d2p4
+  },
+  { // Entry 1271
+    0x1.961b1acd85d7d6ba98c84f9133d10abep-49,
+    0x1.2d97c7f3321d3p4
+  },
+  { // Entry 1272
+    -0x1.961b1acd85d7d6ba98c84f9133d10abep-49,
+    -0x1.2d97c7f3321d3p4
+  },
+  { // Entry 1273
+    0x1.6a09e667f3ba0177c9735dbb72f09f65p-1,
+    0x1.3a28c59d54339p4
+  },
+  { // Entry 1274
+    -0x1.6a09e667f3ba0177c9735dbb72f09f65p-1,
+    -0x1.3a28c59d54339p4
+  },
+  { // Entry 1275
+    0x1.6a09e667f3bb6b81afdb517a4e8548b4p-1,
+    0x1.3a28c59d5433ap4
+  },
+  { // Entry 1276
+    -0x1.6a09e667f3bb6b81afdb517a4e8548b4p-1,
+    -0x1.3a28c59d5433ap4
+  },
+  { // Entry 1277
+    0x1.6a09e667f3bcd58b96434537c0100b9bp-1,
+    0x1.3a28c59d5433bp4
+  },
+  { // Entry 1278
+    -0x1.6a09e667f3bcd58b96434537c0100b9bp-1,
+    -0x1.3a28c59d5433bp4
+  },
+  { // Entry 1279
+    0x1.fffffffffffffffffffffffd0711f437p-1,
+    0x1.46b9c347764a2p4
+  },
+  { // Entry 1280
+    -0x1.fffffffffffffffffffffffd0711f437p-1,
+    -0x1.46b9c347764a2p4
+  },
+  { // Entry 1281
+    0x1.ffffffffffffffffffffffff79c9ec83p-1,
+    0x1.46b9c347764a3p4
+  },
+  { // Entry 1282
+    -0x1.ffffffffffffffffffffffff79c9ec83p-1,
+    -0x1.46b9c347764a3p4
+  },
+  { // Entry 1283
+    0x1.ffffffffffffffffffffffffec81e4cfp-1,
+    0x1.46b9c347764a4p4
+  },
+  { // Entry 1284
+    -0x1.ffffffffffffffffffffffffec81e4cfp-1,
+    -0x1.46b9c347764a4p4
+  },
+  { // Entry 1285
+    0x1.6a09e667f3bee1d2117e501369fbffefp-1,
+    0x1.534ac0f19860bp4
+  },
+  { // Entry 1286
+    -0x1.6a09e667f3bee1d2117e501369fbffefp-1,
+    -0x1.534ac0f19860bp4
+  },
+  { // Entry 1287
+    0x1.6a09e667f3bd77c82b165c5804b7b843p-1,
+    0x1.534ac0f19860cp4
+  },
+  { // Entry 1288
+    -0x1.6a09e667f3bd77c82b165c5804b7b843p-1,
+    -0x1.534ac0f19860cp4
+  },
+  { // Entry 1289
+    0x1.6a09e667f3bc0dbe44ae689b35698a2fp-1,
+    0x1.534ac0f19860dp4
+  },
+  { // Entry 1290
+    -0x1.6a09e667f3bc0dbe44ae689b35698a2fp-1,
+    -0x1.534ac0f19860dp4
+  },
+  { // Entry 1291
+    0x1.3dc585b2c742181326e07c40375464dep-48,
+    0x1.5fdbbe9bba774p4
+  },
+  { // Entry 1292
+    -0x1.3dc585b2c742181326e07c40375464dep-48,
+    -0x1.5fdbbe9bba774p4
+  },
+  { // Entry 1293
+    0x1.ee2c2d963a10c0993703e20442ad7b8dp-51,
+    0x1.5fdbbe9bba775p4
+  },
+  { // Entry 1294
+    -0x1.ee2c2d963a10c0993703e20442ad7b8dp-51,
+    -0x1.5fdbbe9bba775p4
+  },
+  { // Entry 1295
+    -0x1.8474f49a717bcfd9b23f077ec8dd175bp-49,
+    0x1.5fdbbe9bba776p4
+  },
+  { // Entry 1296
+    0x1.8474f49a717bcfd9b23f077ec8dd175bp-49,
+    -0x1.5fdbbe9bba776p4
+  },
+  { // Entry 1297
+    -0x1.6a09e667f3b9f4fcf9145bf3ef39f901p-1,
+    0x1.6c6cbc45dc8dcp4
+  },
+  { // Entry 1298
+    0x1.6a09e667f3b9f4fcf9145bf3ef39f901p-1,
+    -0x1.6c6cbc45dc8dcp4
+  },
+  { // Entry 1299
+    -0x1.6a09e667f3bb5f06df7c4fb2d74972aep-1,
+    0x1.6c6cbc45dc8ddp4
+  },
+  { // Entry 1300
+    0x1.6a09e667f3bb5f06df7c4fb2d74972aep-1,
+    -0x1.6c6cbc45dc8ddp4
+  },
+  { // Entry 1301
+    -0x1.6a09e667f3bcc910c5e44370554f05f4p-1,
+    0x1.6c6cbc45dc8dep4
+  },
+  { // Entry 1302
+    0x1.6a09e667f3bcc910c5e44370554f05f4p-1,
+    -0x1.6c6cbc45dc8dep4
+  },
+  { // Entry 1303
+    -0x1.fffffffffffffffffffffffce85685bdp-1,
+    0x1.78fdb9effea45p4
+  },
+  { // Entry 1304
+    0x1.fffffffffffffffffffffffce85685bdp-1,
+    -0x1.78fdb9effea45p4
+  },
+  { // Entry 1305
+    -0x1.ffffffffffffffffffffffff6cb4a43dp-1,
+    0x1.78fdb9effea46p4
+  },
+  { // Entry 1306
+    0x1.ffffffffffffffffffffffff6cb4a43dp-1,
+    -0x1.78fdb9effea46p4
+  },
+  { // Entry 1307
+    -0x1.fffffffffffffffffffffffff112c2bcp-1,
+    0x1.78fdb9effea47p4
+  },
+  { // Entry 1308
+    0x1.fffffffffffffffffffffffff112c2bcp-1,
+    -0x1.78fdb9effea47p4
+  },
+  { // Entry 1309
+    -0x1.6a09e667f3beee4ce1dd51dac23c6bdcp-1,
+    0x1.858eb79a20baep4
+  },
+  { // Entry 1310
+    0x1.6a09e667f3beee4ce1dd51dac23c6bdcp-1,
+    -0x1.858eb79a20baep4
+  },
+  { // Entry 1311
+    -0x1.6a09e667f3bd8442fb755e1f6972f48fp-1,
+    0x1.858eb79a20bafp4
+  },
+  { // Entry 1312
+    0x1.6a09e667f3bd8442fb755e1f6972f48fp-1,
+    -0x1.858eb79a20bafp4
+  },
+  { // Entry 1313
+    -0x1.6a09e667f3bc1a39150d6a62a69f96dap-1,
+    0x1.858eb79a20bb0p4
+  },
+  { // Entry 1314
+    0x1.6a09e667f3bc1a39150d6a62a69f96dap-1,
+    -0x1.858eb79a20bb0p4
+  },
+  { // Entry 1315
+    0x1.fa7299b17573d373c615096572a0de04p-1,
+    0x1.fffffffffffffp62
+  },
+  { // Entry 1316
+    -0x1.fa7299b17573d373c615096572a0de04p-1,
+    -0x1.fffffffffffffp62
+  },
+  { // Entry 1317
+    0x1.fff6dfd42dc54430bc0576b00a88bd94p-1,
+    0x1.0p63
+  },
+  { // Entry 1318
+    -0x1.fff6dfd42dc54430bc0576b00a88bd94p-1,
+    -0x1.0p63
+  },
+  { // Entry 1319
+    0x1.e456b818e7396b45989978d4b7ebf7b3p-1,
+    0x1.0000000000001p63
+  },
+  { // Entry 1320
+    -0x1.e456b818e7396b45989978d4b7ebf7b3p-1,
+    -0x1.0000000000001p63
+  },
+  { // Entry 1321
+    -0x1.86dcca0d689e7b56ef79481be4a645c6p-1,
+    0x1.fffffffffffffp26
+  },
+  { // Entry 1322
+    0x1.86dcca0d689e7b56ef79481be4a645c6p-1,
+    -0x1.fffffffffffffp26
+  },
+  { // Entry 1323
+    -0x1.86dcc9babb0a40ee875cab3b9e892757p-1,
+    0x1.0p27
+  },
+  { // Entry 1324
+    0x1.86dcc9babb0a40ee875cab3b9e892757p-1,
+    -0x1.0p27
+  },
+  { // Entry 1325
+    -0x1.86dcc9155fe182d4515599426bb14b94p-1,
+    0x1.0000000000001p27
+  },
+  { // Entry 1326
+    0x1.86dcc9155fe182d4515599426bb14b94p-1,
+    -0x1.0000000000001p27
+  },
+  { // Entry 1327
+    -0x1.8f22f84d42da1f57469dfaac44a8b73ap-1,
+    0x1.fffffffffffffp23
+  },
+  { // Entry 1328
+    0x1.8f22f84d42da1f57469dfaac44a8b73ap-1,
+    -0x1.fffffffffffffp23
+  },
+  { // Entry 1329
+    -0x1.8f22f8433d6edfe9a4aff9622517caa9p-1,
+    0x1.0p24
+  },
+  { // Entry 1330
+    0x1.8f22f8433d6edfe9a4aff9622517caa9p-1,
+    -0x1.0p24
+  },
+  { // Entry 1331
+    -0x1.8f22f82f32985fe30699c6e12d9dfce2p-1,
+    0x1.0000000000001p24
+  },
+  { // Entry 1332
+    0x1.8f22f82f32985fe30699c6e12d9dfce2p-1,
+    -0x1.0000000000001p24
+  },
+  { // Entry 1333
+    -0x1.837b9dddc1eabd379d729f575fc1144cp-1,
+    0x1.fffffffffffffp1
+  },
+  { // Entry 1334
+    0x1.837b9dddc1eabd379d729f575fc1144cp-1,
+    -0x1.fffffffffffffp1
+  },
+  { // Entry 1335
+    -0x1.837b9dddc1eae70ce98055a0e450d93cp-1,
+    0x1.0p2
+  },
+  { // Entry 1336
+    0x1.837b9dddc1eae70ce98055a0e450d93cp-1,
+    -0x1.0p2
+  },
+  { // Entry 1337
+    -0x1.837b9dddc1eb3ab7819bc233db4697b5p-1,
+    0x1.0000000000001p2
+  },
+  { // Entry 1338
+    0x1.837b9dddc1eb3ab7819bc233db4697b5p-1,
+    -0x1.0000000000001p2
+  },
+  { // Entry 1339
+    0x1.d18f6ead1b446b4bcb73c2390b330d75p-1,
+    0x1.fffffffffffffp0
+  },
+  { // Entry 1340
+    -0x1.d18f6ead1b446b4bcb73c2390b330d75p-1,
+    -0x1.fffffffffffffp0
+  },
+  { // Entry 1341
+    0x1.d18f6ead1b445dfab848188009c9bb95p-1,
+    0x1.0p1
+  },
+  { // Entry 1342
+    -0x1.d18f6ead1b445dfab848188009c9bb95p-1,
+    -0x1.0p1
+  },
+  { // Entry 1343
+    0x1.d18f6ead1b44435891f0c50e01826988p-1,
+    0x1.0000000000001p1
+  },
+  { // Entry 1344
+    -0x1.d18f6ead1b44435891f0c50e01826988p-1,
+    -0x1.0000000000001p1
+  },
+  { // Entry 1345
+    0x1.aed548f090ced79c79cbf790441f8197p-1,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 1346
+    -0x1.aed548f090ced79c79cbf790441f8197p-1,
+    -0x1.fffffffffffffp-1
+  },
+  { // Entry 1347
+    0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.0p0
+  },
+  { // Entry 1348
+    -0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    -0x1.0p0
+  },
+  { // Entry 1349
+    0x1.aed548f090cef18bb5e3871a14d94609p-1,
+    0x1.0000000000001p0
+  },
+  { // Entry 1350
+    -0x1.aed548f090cef18bb5e3871a14d94609p-1,
+    -0x1.0000000000001p0
+  },
+  { // Entry 1351
+    0x1.eaee8744b05ef07cd0b9089130598314p-2,
+    0x1.fffffffffffffp-2
+  },
+  { // Entry 1352
+    -0x1.eaee8744b05ef07cd0b9089130598314p-2,
+    -0x1.fffffffffffffp-2
+  },
+  { // Entry 1353
+    0x1.eaee8744b05efe8764bc364fd837b666p-2,
+    0x1.0p-1
+  },
+  { // Entry 1354
+    -0x1.eaee8744b05efe8764bc364fd837b666p-2,
+    -0x1.0p-1
+  },
+  { // Entry 1355
+    0x1.eaee8744b05f1a9c8cc291cd27981051p-2,
+    0x1.0000000000001p-1
+  },
+  { // Entry 1356
+    -0x1.eaee8744b05f1a9c8cc291cd27981051p-2,
+    -0x1.0000000000001p-1
+  },
+  { // Entry 1357
+    0x1.faaeed4f31575c27f39c1d7c012a4413p-3,
+    0x1.fffffffffffffp-3
+  },
+  { // Entry 1358
+    -0x1.faaeed4f31575c27f39c1d7c012a4413p-3,
+    -0x1.fffffffffffffp-3
+  },
+  { // Entry 1359
+    0x1.faaeed4f31576ba89debdc7351e8b1aep-3,
+    0x1.0p-2
+  },
+  { // Entry 1360
+    -0x1.faaeed4f31576ba89debdc7351e8b1aep-3,
+    -0x1.0p-2
+  },
+  { // Entry 1361
+    0x1.faaeed4f31578aa9f28b5a61f34dccb1p-3,
+    0x1.0000000000001p-2
+  },
+  { // Entry 1362
+    -0x1.faaeed4f31578aa9f28b5a61f34dccb1p-3,
+    -0x1.0000000000001p-2
+  },
+  { // Entry 1363
+    0x1.feaaeee86ee34cc05eff28740ee7b469p-4,
+    0x1.fffffffffffffp-4
+  },
+  { // Entry 1364
+    -0x1.feaaeee86ee34cc05eff28740ee7b469p-4,
+    -0x1.fffffffffffffp-4
+  },
+  { // Entry 1365
+    0x1.feaaeee86ee35ca069a86721f89f85a5p-4,
+    0x1.0p-3
+  },
+  { // Entry 1366
+    -0x1.feaaeee86ee35ca069a86721f89f85a5p-4,
+    -0x1.0p-3
+  },
+  { // Entry 1367
+    0x1.feaaeee86ee37c607efae47dcc092c1cp-4,
+    0x1.0000000000001p-3
+  },
+  { // Entry 1368
+    -0x1.feaaeee86ee37c607efae47dcc092c1cp-4,
+    -0x1.0000000000001p-3
+  },
+  { // Entry 1369
+    0x1.ffaaaeeed4ed9b53a408c0f2bc02c8f9p-5,
+    0x1.fffffffffffffp-5
+  },
+  { // Entry 1370
+    -0x1.ffaaaeeed4ed9b53a408c0f2bc02c8f9p-5,
+    -0x1.fffffffffffffp-5
+  },
+  { // Entry 1371
+    0x1.ffaaaeeed4edab4ba4b365ed25a9595fp-5,
+    0x1.0p-4
+  },
+  { // Entry 1372
+    -0x1.ffaaaeeed4edab4ba4b365ed25a9595fp-5,
+    -0x1.0p-4
+  },
+  { // Entry 1373
+    0x1.ffaaaeeed4edcb3ba608afe1f8f4fa6bp-5,
+    0x1.0000000000001p-4
+  },
+  { // Entry 1374
+    -0x1.ffaaaeeed4edcb3ba608afe1f8f4fa6bp-5,
+    -0x1.0000000000001p-4
+  },
+  { // Entry 1375
+    0x1.ffeaaaeeee86d8ccfe368cd95e38f003p-6,
+    0x1.fffffffffffffp-6
+  },
+  { // Entry 1376
+    -0x1.ffeaaaeeee86d8ccfe368cd95e38f003p-6,
+    -0x1.fffffffffffffp-6
+  },
+  { // Entry 1377
+    0x1.ffeaaaeeee86e8cafe41376d47919579p-6,
+    0x1.0p-5
+  },
+  { // Entry 1378
+    -0x1.ffeaaaeeee86e8cafe41376d47919579p-6,
+    -0x1.0p-5
+  },
+  { // Entry 1379
+    0x1.ffeaaaeeee8708c6fe568c951a428069p-6,
+    0x1.0000000000001p-5
+  },
+  { // Entry 1380
+    -0x1.ffeaaaeeee8708c6fe568c951a428069p-6,
+    -0x1.0000000000001p-5
+  },
+  { // Entry 1381
+    0x1.fffaaaaeeeed3ed5c9c5ab6538f9cce0p-7,
+    0x1.fffffffffffffp-7
+  },
+  { // Entry 1382
+    -0x1.fffaaaaeeeed3ed5c9c5ab6538f9cce0p-7,
+    -0x1.fffffffffffffp-7
+  },
+  { // Entry 1383
+    0x1.fffaaaaeeeed4ed549c6560f889ee531p-7,
+    0x1.0p-6
+  },
+  { // Entry 1384
+    -0x1.fffaaaaeeeed4ed549c6560f889ee531p-7,
+    -0x1.0p-6
+  },
+  { // Entry 1385
+    0x1.fffaaaaeeeed6ed449c7ab6427e8fdd4p-7,
+    0x1.0000000000001p-6
+  },
+  { // Entry 1386
+    -0x1.fffaaaaeeeed6ed449c7ab6427e8fdd4p-7,
+    -0x1.0000000000001p-6
+  },
+  { // Entry 1387
+    0x1.fffffffaaaaa9aaeeeef6eed4ed442a4p-15,
+    0x1.fffffffffffffp-15
+  },
+  { // Entry 1388
+    -0x1.fffffffaaaaa9aaeeeef6eed4ed442a4p-15,
+    -0x1.fffffffffffffp-15
+  },
+  { // Entry 1389
+    0x1.fffffffaaaaaaaaeeeeeeeed4ed4ed4fp-15,
+    0x1.0p-14
+  },
+  { // Entry 1390
+    -0x1.fffffffaaaaaaaaeeeeeeeed4ed4ed4fp-15,
+    -0x1.0p-14
+  },
+  { // Entry 1391
+    0x1.fffffffaaaaacaaeeeedeeed4ed642a4p-15,
+    0x1.0000000000001p-14
+  },
+  { // Entry 1392
+    -0x1.fffffffaaaaacaaeeeedeeed4ed642a4p-15,
+    -0x1.0000000000001p-14
+  },
+  { // Entry 1393
+    0x1.ffffffffffffeeaaaaaaaaaaaacaeeeep-28,
+    0x1.fffffffffffffp-28
+  },
+  { // Entry 1394
+    -0x1.ffffffffffffeeaaaaaaaaaaaacaeeeep-28,
+    -0x1.fffffffffffffp-28
+  },
+  { // Entry 1395
+    0x1.fffffffffffffeaaaaaaaaaaaaaaeeeep-28,
+    0x1.0p-27
+  },
+  { // Entry 1396
+    -0x1.fffffffffffffeaaaaaaaaaaaaaaeeeep-28,
+    -0x1.0p-27
+  },
+  { // Entry 1397
+    0x1.0000000000000f555555555555357777p-27,
+    0x1.0000000000001p-27
+  },
+  { // Entry 1398
+    -0x1.0000000000000f555555555555357777p-27,
+    -0x1.0000000000001p-27
+  },
+  { // Entry 1399
+    0x1.ffffffffffffeffaaaaaaaaaaaab2aaep-31,
+    0x1.fffffffffffffp-31
+  },
+  { // Entry 1400
+    -0x1.ffffffffffffeffaaaaaaaaaaaab2aaep-31,
+    -0x1.fffffffffffffp-31
+  },
+  { // Entry 1401
+    0x1.fffffffffffffffaaaaaaaaaaaaaaaaep-31,
+    0x1.0p-30
+  },
+  { // Entry 1402
+    -0x1.fffffffffffffffaaaaaaaaaaaaaaaaep-31,
+    -0x1.0p-30
+  },
+  { // Entry 1403
+    0x1.0000000000000ffd555555555554d557p-30,
+    0x1.0000000000001p-30
+  },
+  { // Entry 1404
+    -0x1.0000000000000ffd555555555554d557p-30,
+    -0x1.0000000000001p-30
+  },
+  { // Entry 1405
+    -0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1406
+    0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1407
+    0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1408
+    -0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1409
+    0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1410
+    -0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1411
+    0x1.daa3677c6ee8a22eb6c4b12ca10ce021p-1,
+    0x1.ffffffffffffep1023
+  },
+  { // Entry 1412
+    -0x1.daa3677c6ee8a22eb6c4b12ca10ce021p-1,
+    -0x1.ffffffffffffep1023
+  },
+  { // Entry 1413
+    0x1.1a62633145c06e0e689481270436e2edp-53,
+    0x1.921fb54442d18p1
+  },
+  { // Entry 1414
+    -0x1.1a62633145c06e0e689481270436e2edp-53,
+    -0x1.921fb54442d18p1
+  },
+  { // Entry 1415
+    0x1.ffffffffffffffffffffffffffec8831p-1,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 1416
+    -0x1.ffffffffffffffffffffffffffec8831p-1,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 1417
+    0x1.aed548f090cef18bb5e3871a14d94609p-1,
+    0x1.0000000000001p0
+  },
+  { // Entry 1418
+    -0x1.aed548f090cef18bb5e3871a14d94609p-1,
+    -0x1.0000000000001p0
+  },
+  { // Entry 1419
+    0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.0p0
+  },
+  { // Entry 1420
+    -0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    -0x1.0p0
+  },
+  { // Entry 1421
+    0x1.aed548f090ced79c79cbf790441f8197p-1,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 1422
+    -0x1.aed548f090ced79c79cbf790441f8197p-1,
+    -0x1.fffffffffffffp-1
+  },
+  { // Entry 1423
+    0x1.6a09e667f3bcc5e9fee352f50fd3f4e9p-1,
+    0x1.921fb54442d18p-1
+  },
+  { // Entry 1424
+    -0x1.6a09e667f3bcc5e9fee352f50fd3f4e9p-1,
+    -0x1.921fb54442d18p-1
+  },
+  { // Entry 1425
+    0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 1426
+    -0x1.0000000000000fffffffffffffffffffp-1022,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 1427
+    0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.0p-1022
+  },
+  { // Entry 1428
+    -0x1.ffffffffffffffffffffffffffffffffp-1023,
+    -0x1.0p-1022
+  },
+  { // Entry 1429
+    0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 1430
+    -0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 1431
+    0x1.ffffffffffffbfffffffffffffffffffp-1023,
+    0x1.ffffffffffffcp-1023
+  },
+  { // Entry 1432
+    -0x1.ffffffffffffbfffffffffffffffffffp-1023,
+    -0x1.ffffffffffffcp-1023
+  },
+  { // Entry 1433
+    0x1.ffffffffffffffffffffffffffffffffp-1074,
+    0x1.0p-1073
+  },
+  { // Entry 1434
+    -0x1.ffffffffffffffffffffffffffffffffp-1074,
+    -0x1.0p-1073
+  },
+  { // Entry 1435
+    0.0,
+    0x1.0p-1074
+  },
+  { // Entry 1436
+    -0.0,
+    -0x1.0p-1074
+  },
+  { // Entry 1437
+    0.0,
+    0.0
+  },
+  { // Entry 1438
+    -0.0,
+    -0.0
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_sin, sin_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_sin_intel_data)/sizeof(sin_intel_data_t); i++) {
+    EXPECT_DOUBLE_EQ(g_sin_intel_data[i].expected, sin(g_sin_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_sincos_test.cpp b/tests/math_sincos_test.cpp
new file mode 100644
index 0000000..0fab2c2
--- /dev/null
+++ b/tests/math_sincos_test.cpp
@@ -0,0 +1,4788 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  double sin_expected;
+  double cos_expected;
+  double call_data;
+} sincos_intel_data_t;
+
+static sincos_intel_data_t g_sincos_intel_data[] = {
+  { // Entry 0
+    -0x1.ce9a94ea9c2ad95597b1193b2300d19ap-1,
+    -0x1.b6d3057776dc38335b16745f2d756ab6p-2,
+    -0x1.01c000003p1,
+  },
+  { // Entry 1
+    0x1.ce9a94ea9c2ad95597b1193b2300d19ap-1,
+    -0x1.b6d3057776dc38335b16745f2d756ab6p-2,
+    0x1.01c000003p1,
+  },
+  { // Entry 2
+    -0x1.ce2cad2f92157153b4a9e012e3461d0ap-1,
+    -0x1.b8a14c745bd4c832bae9785655c91b60p-2,
+    -0x1.01fffc080p1,
+  },
+  { // Entry 3
+    0x1.ce2cad2f92157153b4a9e012e3461d0ap-1,
+    -0x1.b8a14c745bd4c832bae9785655c91b60p-2,
+    0x1.01fffc080p1,
+  },
+  { // Entry 4
+    -0x1.1a7444726f5e9dc2ee069dc3e500ab4fp-2,
+    0x1.ec231802917bdffa627ab6a59abe3f7dp-1,
+    -0x1.1e2a1563e068ep-2,
+  },
+  { // Entry 5
+    0x1.1a7444726f5e9dc2ee069dc3e500ab4fp-2,
+    0x1.ec231802917bdffa627ab6a59abe3f7dp-1,
+    0x1.1e2a1563e068ep-2,
+  },
+  { // Entry 6
+    -0x1.efdab5e65c8fd550d4688b62791fe694p-1,
+    0x1.fe4123d266ca37faeee822138eb331d3p-3,
+    -0x1.83ef2196f92f0p87,
+  },
+  { // Entry 7
+    0x1.efdab5e65c8fd550d4688b62791fe694p-1,
+    0x1.fe4123d266ca37faeee822138eb331d3p-3,
+    0x1.83ef2196f92f0p87,
+  },
+  { // Entry 8
+    -0x1.eff5edb1ad416cb6ca3109f1c0dfc34ap-1,
+    0x1.fc9935a7481717fa8aeca7a9c5833084p-3,
+    -0x1.a486d79764fb8p86,
+  },
+  { // Entry 9
+    0x1.eff5edb1ad416cb6ca3109f1c0dfc34ap-1,
+    0x1.fc9935a7481717fa8aeca7a9c5833084p-3,
+    0x1.a486d79764fb8p86,
+  },
+  { // Entry 10
+    -0x1.b78f2c97c88028396ec94ba9ea58dd68p-2,
+    0x1.ce6dea6788fde425f68fe33b0ffcc244p-1,
+    -0x1.c65173556ccfbp-2,
+  },
+  { // Entry 11
+    0x1.b78f2c97c88028396ec94ba9ea58dd68p-2,
+    0x1.ce6dea6788fde425f68fe33b0ffcc244p-1,
+    0x1.c65173556ccfbp-2,
+  },
+  { // Entry 12
+    -0x1.c7885aef33a94ffc5ae06be9444efad5p-3,
+    0x1.f32c8792006349b33b09fe57f80d9ed1p-1,
+    -0x1.cb6p-3,
+  },
+  { // Entry 13
+    0x1.c7885aef33a94ffc5ae06be9444efad5p-3,
+    0x1.f32c8792006349b33b09fe57f80d9ed1p-1,
+    0x1.cb6p-3,
+  },
+  { // Entry 14
+    -0x1.f74a97abb47bc823e92eb9d66f1d8b54p-3,
+    0x1.f04c859e062b9202aa2b9bf0486b5afdp-1,
+    -0x1.fc7fffffffffep-3,
+  },
+  { // Entry 15
+    0x1.f74a97abb47bc823e92eb9d66f1d8b54p-3,
+    0x1.f04c859e062b9202aa2b9bf0486b5afdp-1,
+    0x1.fc7fffffffffep-3,
+  },
+  { // Entry 16
+    0x1.0000000000002fffd555555555553d55p-32,
+    0x1.fffffffffffffffeffffffffffffa0p-1,
+    0x1.0000000000003p-32,
+  },
+  { // Entry 17
+    -0x1.0000000000002fffd555555555553d55p-32,
+    0x1.fffffffffffffffeffffffffffffa0p-1,
+    -0x1.0000000000003p-32,
+  },
+  { // Entry 18
+    0x1.d18f6ead199a3b95430d5516e93c8d7bp-1,
+    -0x1.aa2265753e6687fde76269ee92a784b0p-2,
+    0x1.00000000010p1,
+  },
+  { // Entry 19
+    -0x1.d18f6ead199a3b95430d5516e93c8d7bp-1,
+    -0x1.aa2265753e6687fde76269ee92a784b0p-2,
+    -0x1.00000000010p1,
+  },
+  { // Entry 20
+    0x1.b64d59dd8a5249e01113f4cb37d13c40p-1,
+    -0x1.08a445ad4737e80060cf3a5ff94d3067p-1,
+    0x1.001p557,
+  },
+  { // Entry 21
+    -0x1.b64d59dd8a5249e01113f4cb37d13c40p-1,
+    -0x1.08a445ad4737e80060cf3a5ff94d3067p-1,
+    -0x1.001p557,
+  },
+  { // Entry 22
+    0x1.ce77f24fd4d9a790125ff5290a62b7f1p-1,
+    -0x1.b764f40c9716b834bb72589348cfa4b8p-2,
+    0x1.01d4313757482p1,
+  },
+  { // Entry 23
+    -0x1.ce77f24fd4d9a790125ff5290a62b7f1p-1,
+    -0x1.b764f40c9716b834bb72589348cfa4b8p-2,
+    -0x1.01d4313757482p1,
+  },
+  { // Entry 24
+    0x1.ce39b7df7f4acb81e37c532638f9bf49p-1,
+    -0x1.b86a908f05c0a839e19d4aa63156d32bp-2,
+    0x1.01f867d44bc82p1,
+  },
+  { // Entry 25
+    -0x1.ce39b7df7f4acb81e37c532638f9bf49p-1,
+    -0x1.b86a908f05c0a839e19d4aa63156d32bp-2,
+    -0x1.01f867d44bc82p1,
+  },
+  { // Entry 26
+    0x1.ce70046acb80de75e903468cea8ab427p-1,
+    -0x1.b78654766c76483ce90a0bc2ac957b59p-2,
+    0x1.09860e8ed1e90p3,
+  },
+  { // Entry 27
+    -0x1.ce70046acb80de75e903468cea8ab427p-1,
+    -0x1.b78654766c76483ce90a0bc2ac957b59p-2,
+    -0x1.09860e8ed1e90p3,
+  },
+  { // Entry 28
+    0x1.ce68564e251f16285d604e04657f30e6p-1,
+    -0x1.b7a6a56f5796683c58e01b5b7061c16cp-2,
+    0x1.09872cce51fbdp3,
+  },
+  { // Entry 29
+    -0x1.ce68564e251f16285d604e04657f30e6p-1,
+    -0x1.b7a6a56f5796683c58e01b5b7061c16cp-2,
+    -0x1.09872cce51fbdp3,
+  },
+  { // Entry 30
+    -0x1.ce8ab32f3b002065f2d99e57a1072705p-1,
+    -0x1.b715f769cf1e582e23a15e8b80a70486p-2,
+    0x1.113b13b13b224p2,
+  },
+  { // Entry 31
+    0x1.ce8ab32f3b002065f2d99e57a1072705p-1,
+    -0x1.b715f769cf1e582e23a15e8b80a70486p-2,
+    -0x1.113b13b13b224p2,
+  },
+  { // Entry 32
+    0x1.c2df57188d3099e1baf7f721d7318bd9p-1,
+    0x1.e536ae395dfce001457970c8aaac3b1fp-2,
+    0x1.13cp0,
+  },
+  { // Entry 33
+    -0x1.c2df57188d3099e1baf7f721d7318bd9p-1,
+    0x1.e536ae395dfce001457970c8aaac3b1fp-2,
+    -0x1.13cp0,
+  },
+  { // Entry 34
+    0x1.b7dcd7c85c820838eecfa53e52078b2bp-2,
+    -0x1.ce5b7372046eaa467f49e1debe3662dfp-1,
+    0x1.1f628c5610717p3,
+  },
+  { // Entry 35
+    -0x1.b7dcd7c85c820838eecfa53e52078b2bp-2,
+    -0x1.ce5b7372046eaa467f49e1debe3662dfp-1,
+    -0x1.1f628c5610717p3,
+  },
+  { // Entry 36
+    0x1.ff3466b1ec8bed978f7c27018bc09678p-1,
+    0x1.c86caa04929857c2816d30693fceab36p-5,
+    0x1.1f699d708d497p16,
+  },
+  { // Entry 37
+    -0x1.ff3466b1ec8bed978f7c27018bc09678p-1,
+    0x1.c86caa04929857c2816d30693fceab36p-5,
+    -0x1.1f699d708d497p16,
+  },
+  { // Entry 38
+    0x1.b61d6aff754c2835697b5aa5339b635cp-2,
+    -0x1.cec59b2d230a83a86804730afdf1becfp-1,
+    0x1.1f72064620ef4p3,
+  },
+  { // Entry 39
+    -0x1.b61d6aff754c2835697b5aa5339b635cp-2,
+    -0x1.cec59b2d230a83a86804730afdf1becfp-1,
+    -0x1.1f72064620ef4p3,
+  },
+  { // Entry 40
+    0x1.cdf604838e499bd5d9d2712397b23c07p-1,
+    0x1.b98656b85bc2683216a947335ea689fbp-2,
+    0x1.1fffffdcefe40p0,
+  },
+  { // Entry 41
+    -0x1.cdf604838e499bd5d9d2712397b23c07p-1,
+    0x1.b98656b85bc2683216a947335ea689fbp-2,
+    -0x1.1fffffdcefe40p0,
+  },
+  { // Entry 42
+    0x1.ce913329696cd3fa471c7b00891075d4p-1,
+    0x1.b6fa92e5f576c834fc15d8998fccc728p-2,
+    0x1.20b478c4aa9edp0,
+  },
+  { // Entry 43
+    -0x1.ce913329696cd3fa471c7b00891075d4p-1,
+    0x1.b6fa92e5f576c834fc15d8998fccc728p-2,
+    -0x1.20b478c4aa9edp0,
+  },
+  { // Entry 44
+    0x1.ceabc025ed3d57323fca51626d2bf28cp-1,
+    0x1.b68a988604a7e83cd382fdf329d0d76ep-2,
+    0x1.20d37456e7453p0,
+  },
+  { // Entry 45
+    -0x1.ceabc025ed3d57323fca51626d2bf28cp-1,
+    0x1.b68a988604a7e83cd382fdf329d0d76ep-2,
+    -0x1.20d37456e7453p0,
+  },
+  { // Entry 46
+    0x1.ceb022b6b5ae07a267f0e7dc6a14a214p-1,
+    0x1.b67816b80ed0a82d11aee7aaa8008fedp-2,
+    0x1.20d8930cdf602p0,
+  },
+  { // Entry 47
+    -0x1.ceb022b6b5ae07a267f0e7dc6a14a214p-1,
+    0x1.b67816b80ed0a82d11aee7aaa8008fedp-2,
+    -0x1.20d8930cdf602p0,
+  },
+  { // Entry 48
+    -0x1.9e62aca53c660801b62604018a9d19ddp-4,
+    -0x1.fd5f830f860f333de490a42c2f045012p-1,
+    0x1.30d5f8e54b6d8p3,
+  },
+  { // Entry 49
+    0x1.9e62aca53c660801b62604018a9d19ddp-4,
+    -0x1.fd5f830f860f333de490a42c2f045012p-1,
+    -0x1.30d5f8e54b6d8p3,
+  },
+  { // Entry 50
+    0x1.3ed2aeefeafc97f0ee0fb3fa4fb46052p-3,
+    0x1.f9c201e4eb65fd5e5dbd97662505ff6fp-1,
+    0x1.402p-3,
+  },
+  { // Entry 51
+    -0x1.3ed2aeefeafc97f0ee0fb3fa4fb46052p-3,
+    0x1.f9c201e4eb65fd5e5dbd97662505ff6fp-1,
+    -0x1.402p-3,
+  },
+  { // Entry 52
+    -0x1.ff65d2ff4a8cc41cb8bb6df306e07be7p-1,
+    -0x1.8d3822ef260a57b385611f08577b75d9p-5,
+    0x1.4a40ec149a66fp16,
+  },
+  { // Entry 53
+    0x1.ff65d2ff4a8cc41cb8bb6df306e07be7p-1,
+    -0x1.8d3822ef260a57b385611f08577b75d9p-5,
+    -0x1.4a40ec149a66fp16,
+  },
+  { // Entry 54
+    0x1.4fffffffff9f88000000084f22ccccccp-20,
+    0x1.fffffffffe47000000003f4ebffffffcp-1,
+    0x1.5p-20,
+  },
+  { // Entry 55
+    -0x1.4fffffffff9f88000000084f22ccccccp-20,
+    0x1.fffffffffe47000000003f4ebffffffcp-1,
+    -0x1.5p-20,
+  },
+  { // Entry 56
+    0x1.79c599e1e91af809f9e69771796cd507p-1,
+    -0x1.5997065cb9653702d4c9d9b6bc58f768p-1,
+    0x1.5294a5294a528p4,
+  },
+  { // Entry 57
+    -0x1.79c599e1e91af809f9e69771796cd507p-1,
+    -0x1.5997065cb9653702d4c9d9b6bc58f768p-1,
+    -0x1.5294a5294a528p4,
+  },
+  { // Entry 58
+    -0x1.ff7996073bba6c6ede46f52d445623c9p-1,
+    0x1.72e7437910cc083fac4f6f62a2eb38afp-5,
+    0x1.57431aacf5c58p16,
+  },
+  { // Entry 59
+    0x1.ff7996073bba6c6ede46f52d445623c9p-1,
+    0x1.72e7437910cc083fac4f6f62a2eb38afp-5,
+    -0x1.57431aacf5c58p16,
+  },
+  { // Entry 60
+    0x1.f81c4f9a5181462ae735e21222d498c4p-1,
+    0x1.6623d2eb6add1ffc398a3c20447f9d06p-3,
+    0x1.652p0,
+  },
+  { // Entry 61
+    -0x1.f81c4f9a5181462ae735e21222d498c4p-1,
+    0x1.6623d2eb6add1ffc398a3c20447f9d06p-3,
+    -0x1.652p0,
+  },
+  { // Entry 62
+    -0x1.c42a091026f45286d061085c5c9fddb7p-1,
+    0x1.e0619960a11c6801e80ab0c9e25f89d0p-2,
+    0x1.6f7bdef7bdef4p3,
+  },
+  { // Entry 63
+    0x1.c42a091026f45286d061085c5c9fddb7p-1,
+    0x1.e0619960a11c6801e80ab0c9e25f89d0p-2,
+    -0x1.6f7bdef7bdef4p3,
+  },
+  { // Entry 64
+    -0x1.f9c4364ba198f7e32b672366c34b8b7dp-2,
+    0x1.bd309f3dfcd489128e5ecbc31680c4a5p-1,
+    0x1.711p2,
+  },
+  { // Entry 65
+    0x1.f9c4364ba198f7e32b672366c34b8b7dp-2,
+    0x1.bd309f3dfcd489128e5ecbc31680c4a5p-1,
+    -0x1.711p2,
+  },
+  { // Entry 66
+    -0x1.be6e5bea1a4d88331fd8e460cd677245p-2,
+    0x1.ccc7d99b57ab54f04ed918ec14a2507dp-1,
+    0x1.7540aa5882dc2p2,
+  },
+  { // Entry 67
+    0x1.be6e5bea1a4d88331fd8e460cd677245p-2,
+    0x1.ccc7d99b57ab54f04ed918ec14a2507dp-1,
+    -0x1.7540aa5882dc2p2,
+  },
+  { // Entry 68
+    0x1.c90c841d1494c0757e8ebb16725d8718p-3,
+    -0x1.f3165a0b306b1ffcf8d11909fffba167p-1,
+    0x1.7550d28ffccc4p1,
+  },
+  { // Entry 69
+    -0x1.c90c841d1494c0757e8ebb16725d8718p-3,
+    -0x1.f3165a0b306b1ffcf8d11909fffba167p-1,
+    -0x1.7550d28ffccc4p1,
+  },
+  { // Entry 70
+    -0x1.b649d577e1b2a839d25d19807eb2c564p-2,
+    0x1.cebb175d36b934bc0995a0be35cde1eep-1,
+    0x1.75d11fa0d6242p2,
+  },
+  { // Entry 71
+    0x1.b649d577e1b2a839d25d19807eb2c564p-2,
+    0x1.cebb175d36b934bc0995a0be35cde1eep-1,
+    -0x1.75d11fa0d6242p2,
+  },
+  { // Entry 72
+    0x1.b78730d11d8408320d21ca6ad2be3368p-2,
+    -0x1.ce6fd00ed16501cb13b908477e102811p-1,
+    0x1.bc50444ee6286p9,
+  },
+  { // Entry 73
+    -0x1.b78730d11d8408320d21ca6ad2be3368p-2,
+    -0x1.ce6fd00ed16501cb13b908477e102811p-1,
+    -0x1.bc50444ee6286p9,
+  },
+  { // Entry 74
+    0x1.b6b0b0996e7e6835acdb36e55a08bf15p-2,
+    0x1.cea2b8cc552181d0b0aead27e94a9168p-1,
+    0x1.c55b2bf19ce54p-2,
+  },
+  { // Entry 75
+    -0x1.b6b0b0996e7e6835acdb36e55a08bf15p-2,
+    0x1.cea2b8cc552181d0b0aead27e94a9168p-1,
+    -0x1.c55b2bf19ce54p-2,
+  },
+  { // Entry 76
+    0x1.b6facf665891482ea8c61f5ca32f280dp-2,
+    0x1.ce9124cec4150559d947a526ad98f2f4p-1,
+    0x1.c5ad34f5f472ap-2,
+  },
+  { // Entry 77
+    -0x1.b6facf665891482ea8c61f5ca32f280dp-2,
+    0x1.ce9124cec4150559d947a526ad98f2f4p-1,
+    -0x1.c5ad34f5f472ap-2,
+  },
+  { // Entry 78
+    -0x1.f83a0983dd15d00301e2df21e3bee635p-2,
+    -0x1.bda0596df060004d579563ad8c67d151p-1,
+    0x1.d4067c60f471ep1,
+  },
+  { // Entry 79
+    0x1.f83a0983dd15d00301e2df21e3bee635p-2,
+    -0x1.bda0596df060004d579563ad8c67d151p-1,
+    -0x1.d4067c60f471ep1,
+  },
+  { // Entry 80
+    0x1.9cb6a9bbce64a3e97a7267fdec25c83bp-1,
+    0x1.2f011326420e5002172db245fd9063e2p-1,
+    0x1.dffffffffffffp-1,
+  },
+  { // Entry 81
+    -0x1.9cb6a9bbce64a3e97a7267fdec25c83bp-1,
+    0x1.2f011326420e5002172db245fd9063e2p-1,
+    -0x1.dffffffffffffp-1,
+  },
+  { // Entry 82
+    0x1.f5f0be28565c5ad763c103d981fc5c4ep-5,
+    0x1.ff09babb076e4803e57e68204570fd5bp-1,
+    0x1.f64147d8add84p-5,
+  },
+  { // Entry 83
+    -0x1.f5f0be28565c5ad763c103d981fc5c4ep-5,
+    0x1.ff09babb076e4803e57e68204570fd5bp-1,
+    -0x1.f64147d8add84p-5,
+  },
+  { // Entry 84
+    -0x1.d4da5f56888e200fda4ebac7db1cdbefp-1,
+    0x1.9b70cd3284e157fb84491d581cb86bd3p-2,
+    0x1.fe6183efa397cp83,
+  },
+  { // Entry 85
+    0x1.d4da5f56888e200fda4ebac7db1cdbefp-1,
+    0x1.9b70cd3284e157fb84491d581cb86bd3p-2,
+    -0x1.fe6183efa397cp83,
+  },
+  { // Entry 86
+    0x1.fa9f6ca0ec44e0010026f385c0ab8690p-3,
+    0x1.f016474b75667424a050d79014fd2385p-1,
+    0x1.ffeffffffffffp-3,
+  },
+  { // Entry 87
+    -0x1.fa9f6ca0ec44e0010026f385c0ab8690p-3,
+    0x1.f016474b75667424a050d79014fd2385p-1,
+    -0x1.ffeffffffffffp-3,
+  },
+  { // Entry 88
+    -0x1.ff4868ddaba6ba32c6b714aef99ff2f7p-1,
+    -0x1.b16f0eb25ae467c2a185e516f1188b20p-5,
+    0x1.fff7ff800001fp15,
+  },
+  { // Entry 89
+    0x1.ff4868ddaba6ba32c6b714aef99ff2f7p-1,
+    -0x1.b16f0eb25ae467c2a185e516f1188b20p-5,
+    -0x1.fff7ff800001fp15,
+  },
+  { // Entry 90
+    -0x1.ff4f1e9c248912648701818d075b3953p-1,
+    -0x1.a971e3b64d08d7c3f37d299b43616eb4p-5,
+    0x1.fff7ffffffcp15,
+  },
+  { // Entry 91
+    0x1.ff4f1e9c248912648701818d075b3953p-1,
+    -0x1.a971e3b64d08d7c3f37d299b43616eb4p-5,
+    -0x1.fff7ffffffcp15,
+  },
+  { // Entry 92
+    0x1.d19616fc7ee4605345c25606cfc93235p-1,
+    -0x1.aa054c4909384811a063273112604c31p-2,
+    0x1.fff80p0,
+  },
+  { // Entry 93
+    -0x1.d19616fc7ee4605345c25606cfc93235p-1,
+    -0x1.aa054c4909384811a063273112604c31p-2,
+    -0x1.fff80p0,
+  },
+  { // Entry 94
+    0x1.ce3509751c4614837fa4b34963c6f5d8p-1,
+    0x1.b87e37101654482144d71d04972267d8p-2,
+    0x1.ffffbffe3ffffp14,
+  },
+  { // Entry 95
+    -0x1.ce3509751c4614837fa4b34963c6f5d8p-1,
+    0x1.b87e37101654482144d71d04972267d8p-2,
+    -0x1.ffffbffe3ffffp14,
+  },
+  { // Entry 96
+    0x1.d18f76ffc6e4ba0a3134e5be21b5bc8fp-1,
+    -0x1.aa2241160227896c68ef17839f17dce5p-2,
+    0x1.fffff60p0,
+  },
+  { // Entry 97
+    -0x1.d18f76ffc6e4ba0a3134e5be21b5bc8fp-1,
+    -0x1.aa2241160227896c68ef17839f17dce5p-2,
+    -0x1.fffff60p0,
+  },
+  { // Entry 98
+    -0x1.837b994a6d8ff7f2750755df5843e84dp-1,
+    -0x1.4eaa65b9e2ecc308fd82f65e09d06be4p-1,
+    0x1.fffffe3ffffffp1,
+  },
+  { // Entry 99
+    0x1.837b994a6d8ff7f2750755df5843e84dp-1,
+    -0x1.4eaa65b9e2ecc308fd82f65e09d06be4p-1,
+    -0x1.fffffe3ffffffp1,
+  },
+  { // Entry 100
+    0x1.aed548f090c1dffe6e04322dc8e8cbfap-1,
+    0x1.14a280fb507cf8999a1b291995646152p-1,
+    0x1.ffffffffffe7fp-1,
+  },
+  { // Entry 101
+    -0x1.aed548f090c1dffe6e04322dc8e8cbfap-1,
+    0x1.14a280fb507cf8999a1b291995646152p-1,
+    -0x1.ffffffffffe7fp-1,
+  },
+  { // Entry 102
+    -0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074,
+  },
+  { // Entry 103
+    0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074,
+  },
+  { // Entry 104
+    -0.0,
+    0x1.p0,
+    -0.0,
+  },
+  { // Entry 105
+    0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074,
+  },
+  { // Entry 106
+    -0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074,
+  },
+  { // Entry 107
+    -0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0000000000001p-1022,
+  },
+  { // Entry 108
+    0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0000000000001p-1022,
+  },
+  { // Entry 109
+    -0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1022,
+  },
+  { // Entry 110
+    0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1022,
+  },
+  { // Entry 111
+    -0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffep-1023,
+  },
+  { // Entry 112
+    0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.ffffffffffffep-1023,
+  },
+  { // Entry 113
+    0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.ffffffffffffep-1023,
+  },
+  { // Entry 114
+    -0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffep-1023,
+  },
+  { // Entry 115
+    0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1022,
+  },
+  { // Entry 116
+    -0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1022,
+  },
+  { // Entry 117
+    0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0000000000001p-1022,
+  },
+  { // Entry 118
+    -0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0000000000001p-1022,
+  },
+  { // Entry 119
+    0x1.9999996de8ca198c24ab9449beee16d5p-13,
+    0x1.ffffff5c28f5cb4c5272061281211120p-1,
+    0x1.999999999999ap-13,
+  },
+  { // Entry 120
+    -0x1.9999996de8ca198c24ab9449beee16d5p-13,
+    0x1.ffffff5c28f5cb4c5272061281211120p-1,
+    -0x1.999999999999ap-13,
+  },
+  { // Entry 121
+    0x1.999998ead65b96f78a4dbfd839c7ef2ep-12,
+    0x1.fffffd70a3d7960cd5695a06fdb80e74p-1,
+    0x1.999999999999ap-12,
+  },
+  { // Entry 122
+    -0x1.999998ead65b96f78a4dbfd839c7ef2ep-12,
+    0x1.fffffd70a3d7960cd5695a06fdb80e74p-1,
+    -0x1.999999999999ap-12,
+  },
+  { // Entry 123
+    0x1.3333320c49babff151b6d04290e2c3a2p-11,
+    0x1.fffffa3d70a69ad42b39d8696632f856p-1,
+    0x1.3333333333334p-11,
+  },
+  { // Entry 124
+    -0x1.3333320c49babff151b6d04290e2c3a2p-11,
+    0x1.fffffa3d70a69ad42b39d8696632f856p-1,
+    -0x1.3333333333334p-11,
+  },
+  { // Entry 125
+    0x1.999996de8ca2884da2f08f25bb024d08p-11,
+    0x1.fffff5c28f64e5ec0da0a4f7f4388052p-1,
+    0x1.999999999999ap-11,
+  },
+  { // Entry 126
+    -0x1.999996de8ca2884da2f08f25bb024d08p-11,
+    0x1.fffff5c28f64e5ec0da0a4f7f4388052p-1,
+    -0x1.999999999999ap-11,
+  },
+  { // Entry 127
+    0x1.fffffaaaaaaeeeeeed4ed4edab4c7bd6p-11,
+    0x1.fffff0000015555549f49f4d34d34ca0p-1,
+    0x1.0p-10,
+  },
+  { // Entry 128
+    -0x1.fffffaaaaaaeeeeeed4ed4edab4c7bd6p-11,
+    0x1.fffff0000015555549f49f4d34d34ca0p-1,
+    -0x1.0p-10,
+  },
+  { // Entry 129
+    0x1.33332e978d552afc883bdb04751e3835p-10,
+    0x1.ffffe8f5c2bb98c7c103d2ff79f15d6ap-1,
+    0x1.3333333333333p-10,
+  },
+  { // Entry 130
+    -0x1.33332e978d552afc883bdb04751e3835p-10,
+    0x1.ffffe8f5c2bb98c7c103d2ff79f15d6ap-1,
+    -0x1.3333333333333p-10,
+  },
+  { // Entry 131
+    0x1.66665f1529aff8a3809246670a436c3cp-10,
+    0x1.ffffe0a3d75c31b26451166d6f398abdp-1,
+    0x1.6666666666666p-10,
+  },
+  { // Entry 132
+    -0x1.66665f1529aff8a3809246670a436c3cp-10,
+    0x1.ffffe0a3d75c31b26451166d6f398abdp-1,
+    -0x1.6666666666666p-10,
+  },
+  { // Entry 133
+    0x1.99998ead65cdf82e194c133997f2fb68p-10,
+    0x1.ffffd70a3dfc733b3331d8382b1e9df5p-1,
+    0x1.9999999999999p-10,
+  },
+  { // Entry 134
+    -0x1.99998ead65cdf82e194c133997f2fb68p-10,
+    0x1.ffffd70a3dfc733b3331d8382b1e9df5p-1,
+    -0x1.9999999999999p-10,
+  },
+  { // Entry 135
+    0x1.ccccbd3f7d15d42affb9f02bf1dc257bp-10,
+    0x1.ffffcc28f6a2823f3765b50659ecb0e2p-1,
+    0x1.cccccccccccccp-10,
+  },
+  { // Entry 136
+    -0x1.ccccbd3f7d15d42affb9f02bf1dc257bp-10,
+    0x1.ffffcc28f6a2823f3765b50659ecb0e2p-1,
+    -0x1.cccccccccccccp-10,
+  },
+  { // Entry 137
+    0x1.0665ae9c7b44ed280216be2104f28f02p-7,
+    0x1.fffbcc2a6e86fef7d2af1580bd8e6699p-1,
+    0x1.0666666666666p-7,
+  },
+  { // Entry 138
+    -0x1.0665ae9c7b44ed280216be2104f28f02p-7,
+    0x1.fffbcc2a6e86fef7d2af1580bd8e6699p-1,
+    -0x1.0666666666666p-7,
+  },
+  { // Entry 139
+    0x1.ccc8e97b59f618898c4ac3a0aeddf709p-7,
+    0x1.fff30a4b6fcc1405e18fbf7335d2f789p-1,
+    0x1.cccccccccccccp-7,
+  },
+  { // Entry 140
+    -0x1.ccc8e97b59f618898c4ac3a0aeddf709p-7,
+    0x1.fff30a4b6fcc1405e18fbf7335d2f789p-1,
+    -0x1.cccccccccccccp-7,
+  },
+  { // Entry 141
+    0x1.4993e8a8ff79b132046efa7856a97538p-6,
+    0x1.ffe57a780f38c0db37051fa8c8d60fbcp-1,
+    0x1.4999999999999p-6,
+  },
+  { // Entry 142
+    -0x1.4993e8a8ff79b132046efa7856a97538p-6,
+    0x1.ffe57a780f38c0db37051fa8c8d60fbcp-1,
+    -0x1.4999999999999p-6,
+  },
+  { // Entry 143
+    0x1.acc044c56db0e19f82c9c3cff246e201p-6,
+    0x1.ffd31cd0e1d62c05d2cded21add8bd33p-1,
+    0x1.accccccccccccp-6,
+  },
+  { // Entry 144
+    -0x1.acc044c56db0e19f82c9c3cff246e201p-6,
+    0x1.ffd31cd0e1d62c05d2cded21add8bd33p-1,
+    -0x1.accccccccccccp-6,
+  },
+  { // Entry 145
+    0x1.07f44d67cf41afbc0c95108b99f91b01p-5,
+    0x1.ffbbf18207542ef81390d73c3ba89c1ap-1,
+    0x1.080p-5,
+  },
+  { // Entry 146
+    -0x1.07f44d67cf41afbc0c95108b99f91b01p-5,
+    0x1.ffbbf18207542ef81390d73c3ba89c1ap-1,
+    -0x1.080p-5,
+  },
+  { // Entry 147
+    0x1.3985fe46f1c8714eaa1418561963e89bp-5,
+    0x1.ff9ff8c3299f54457bbaf8c12173b46bp-1,
+    0x1.399999999999ap-5,
+  },
+  { // Entry 148
+    -0x1.3985fe46f1c8714eaa1418561963e89bp-5,
+    0x1.ff9ff8c3299f54457bbaf8c12173b46bp-1,
+    -0x1.399999999999ap-5,
+  },
+  { // Entry 149
+    0x1.6b14bde93ac5f7d24544d0ecf8be7aeep-5,
+    0x1.ff7f32d77c5b1c42f1660c9b6f2ef64fp-1,
+    0x1.6b33333333334p-5,
+  },
+  { // Entry 150
+    -0x1.6b14bde93ac5f7d24544d0ecf8be7aeep-5,
+    0x1.ff7f32d77c5b1c42f1660c9b6f2ef64fp-1,
+    -0x1.6b33333333334p-5,
+  },
+  { // Entry 151
+    0x1.9ca0153ed8396b02f8605219a5fe5917p-5,
+    0x1.ff59a00dbc40896bb5e4ac8ad293afb4p-1,
+    0x1.9cccccccccccep-5,
+  },
+  { // Entry 152
+    -0x1.9ca0153ed8396b02f8605219a5fe5917p-5,
+    0x1.ff59a00dbc40896bb5e4ac8ad293afb4p-1,
+    -0x1.9cccccccccccep-5,
+  },
+  { // Entry 153
+    0x1.ce278d4027d34387f184d4ab2aaf545fp-5,
+    0x1.ff2f40c02e60f61d6dcfc39b6c2be087p-1,
+    0x1.ce66666666666p-5,
+  },
+  { // Entry 154
+    -0x1.ce278d4027d34387f184d4ab2aaf545fp-5,
+    0x1.ff2f40c02e60f61d6dcfc39b6c2be087p-1,
+    -0x1.ce66666666666p-5,
+  },
+  { // Entry 155
+    0x1.43c1e9c171a667a0b92519a04fa5a91cp-1,
+    0x1.8ca46c7d8975e57a1484f05c3738d83bp-1,
+    0x1.5e7fc4369bdadp-1,
+  },
+  { // Entry 156
+    -0x1.43c1e9c171a667a0b92519a04fa5a91cp-1,
+    0x1.8ca46c7d8975e57a1484f05c3738d83bp-1,
+    -0x1.5e7fc4369bdadp-1,
+  },
+  { // Entry 157
+    0x1.ee3d6bcea09ca18b1d1ce7ee04fd886fp-1,
+    0x1.0b5d3802fc7991140168f294eedd7904p-2,
+    0x1.4e7fc4369bdadp0,
+  },
+  { // Entry 158
+    -0x1.ee3d6bcea09ca18b1d1ce7ee04fd886fp-1,
+    0x1.0b5d3802fc7991140168f294eedd7904p-2,
+    -0x1.4e7fc4369bdadp0,
+  },
+  { // Entry 159
+    0x1.df8e22ea809d65c6a69b96aca60be432p-1,
+    -0x1.66b96f53323af1d7e31a7162ab18a75bp-2,
+    0x1.edbfa651e9c84p0,
+  },
+  { // Entry 160
+    -0x1.df8e22ea809d65c6a69b96aca60be432p-1,
+    -0x1.66b96f53323af1d7e31a7162ab18a75bp-2,
+    -0x1.edbfa651e9c84p0,
+  },
+  { // Entry 161
+    0x1.1d3479eac7ae35e2fbea0ae696434692p-1,
+    -0x1.a93554888c32fa57f22a9529a320c1cbp-1,
+    0x1.467fc4369bdadp1,
+  },
+  { // Entry 162
+    -0x1.1d3479eac7ae35e2fbea0ae696434692p-1,
+    -0x1.a93554888c32fa57f22a9529a320c1cbp-1,
+    -0x1.467fc4369bdadp1,
+  },
+  { // Entry 163
+    -0x1.ffeaaaeeee84b44ccefef832254d28c0p-6,
+    -0x1.ffc00155527d2b9fda2ae89396e09727p-1,
+    0x1.961fb54442d18p1,
+  },
+  { // Entry 164
+    0x1.ffeaaaeeee84b44ccefef832254d28c0p-6,
+    -0x1.ffc00155527d2b9fda2ae89396e09727p-1,
+    -0x1.961fb54442d18p1,
+  },
+  { // Entry 165
+    -0x1.3734d32d49bd0b942772a7567d514140p-1,
+    -0x1.96907c5c7c25b88e34addff1fbef66e4p-1,
+    0x1.e5bfa651e9c83p1,
+  },
+  { // Entry 166
+    0x1.3734d32d49bd0b942772a7567d514140p-1,
+    -0x1.96907c5c7c25b88e34addff1fbef66e4p-1,
+    -0x1.e5bfa651e9c83p1,
+  },
+  { // Entry 167
+    -0x1.e9d25d19911e205b653521f42b9b864fp-1,
+    -0x1.2a1e5a50f948cd487c5309682b110a53p-2,
+    0x1.1aafcbafc85f7p2,
+  },
+  { // Entry 168
+    0x1.e9d25d19911e205b653521f42b9b864fp-1,
+    -0x1.2a1e5a50f948cd487c5309682b110a53p-2,
+    -0x1.1aafcbafc85f7p2,
+  },
+  { // Entry 169
+    -0x1.e4ecdc5a4e465899928eb9fc95829d48p-1,
+    0x1.4894f695dc56bce8b273e5524f181264p-2,
+    0x1.427fc4369bdadp2,
+  },
+  { // Entry 170
+    0x1.e4ecdc5a4e465899928eb9fc95829d48p-1,
+    0x1.4894f695dc56bce8b273e5524f181264p-2,
+    -0x1.427fc4369bdadp2,
+  },
+  { // Entry 171
+    -0x1.2a59f1034426197fa6eee22762967f25p-1,
+    0x1.a016ea3a692ce0c321b77f168de39122p-1,
+    0x1.6a4fbcbd6f562p2,
+  },
+  { // Entry 172
+    0x1.2a59f1034426197fa6eee22762967f25p-1,
+    0x1.a016ea3a692ce0c321b77f168de39122p-1,
+    -0x1.6a4fbcbd6f562p2,
+  },
+  { // Entry 173
+    -0x1.26312443bd35f19312eac0a1a6b5659ep-1,
+    0x1.a30a69f5537ebc22f0870c2bd26ef284p-1,
+    0x1.6af2eff0a2896p2,
+  },
+  { // Entry 174
+    0x1.26312443bd35f19312eac0a1a6b5659ep-1,
+    0x1.a30a69f5537ebc22f0870c2bd26ef284p-1,
+    -0x1.6af2eff0a2896p2,
+  },
+  { // Entry 175
+    -0x1.e18e660a5e2fb316ecbb9ed70122eff5p-1,
+    0x1.5bd62e8b04ad5915e66242349b756e11p-2,
+    0x1.43c62a9d02414p2,
+  },
+  { // Entry 176
+    0x1.e18e660a5e2fb316ecbb9ed70122eff5p-1,
+    0x1.5bd62e8b04ad5915e66242349b756e11p-2,
+    -0x1.43c62a9d02414p2,
+  },
+  { // Entry 177
+    -0x1.ee0e83a0198b6e2ef7c48e6625291a0ap-1,
+    -0x1.0cb71f671e63410966e78d2009c0616fp-2,
+    0x1.1c99654961f92p2,
+  },
+  { // Entry 178
+    0x1.ee0e83a0198b6e2ef7c48e6625291a0ap-1,
+    -0x1.0cb71f671e63410966e78d2009c0616fp-2,
+    -0x1.1c99654961f92p2,
+  },
+  { // Entry 179
+    -0x1.4727747338e4653616eadbd7ec3d02d3p-1,
+    -0x1.89d86aa8521c11b74f8b1954c08f9b36p-1,
+    0x1.ead93feb8361fp1,
+  },
+  { // Entry 180
+    0x1.4727747338e4653616eadbd7ec3d02d3p-1,
+    -0x1.89d86aa8521c11b74f8b1954c08f9b36p-1,
+    -0x1.ead93feb8361fp1,
+  },
+  { // Entry 181
+    -0x1.4ba2f75dda5fe434320905a7184ff1afp-4,
+    -0x1.fe51ac554a16ad8194f181085f8a17f2p-1,
+    0x1.9c7fb54442d1ap1,
+  },
+  { // Entry 182
+    0x1.4ba2f75dda5fe434320905a7184ff1afp-4,
+    -0x1.fe51ac554a16ad8194f181085f8a17f2p-1,
+    -0x1.9c7fb54442d1ap1,
+  },
+  { // Entry 183
+    0x1.034c4d633b4ef0a9089b43892a462a26p-1,
+    -0x1.b97c04d08bc5d765b341a22b2c720b6fp-1,
+    0x1.4e262a9d02415p1,
+  },
+  { // Entry 184
+    -0x1.034c4d633b4ef0a9089b43892a462a26p-1,
+    -0x1.b97c04d08bc5d765b341a22b2c720b6fp-1,
+    -0x1.4e262a9d02415p1,
+  },
+  { // Entry 185
+    0x1.d1e4cde2f3944f4c134c05cc4e5339a3p-1,
+    -0x1.a8ac8a3e58f6ca952390299d2e8b187fp-2,
+    0x1.ff993feb83620p0,
+  },
+  { // Entry 186
+    -0x1.d1e4cde2f3944f4c134c05cc4e5339a3p-1,
+    -0x1.a8ac8a3e58f6ca952390299d2e8b187fp-2,
+    -0x1.ff993feb83620p0,
+  },
+  { // Entry 187
+    0x1.f750235c949926c48c90e41a91474c06p-1,
+    0x1.77a8b9b3d254a9e39d02b3eb3e2390e7p-3,
+    0x1.62e62a9d02416p0,
+  },
+  { // Entry 188
+    -0x1.f750235c949926c48c90e41a91474c06p-1,
+    0x1.77a8b9b3d254a9e39d02b3eb3e2390e7p-3,
+    -0x1.62e62a9d02416p0,
+  },
+  { // Entry 189
+    0x1.65f7d571279b0b8005552fd47a2e77aep-1,
+    0x1.6e1061205dd79051c112d30a05097c61p-1,
+    0x1.8c662a9d02419p-1,
+  },
+  { // Entry 190
+    -0x1.65f7d571279b0b8005552fd47a2e77aep-1,
+    0x1.6e1061205dd79051c112d30a05097c61p-1,
+    -0x1.8c662a9d02419p-1,
+  },
+  { // Entry 191
+    -0x1.fe043f57369d6a52fa33f0119ec4da19p-1,
+    -0x1.682f3cc3c7a08da2ce02a41cdc7bed86p-4,
+    -0x1.a8aa1d11c44ffp0,
+  },
+  { // Entry 192
+    0x1.fe043f57369d6a52fa33f0119ec4da19p-1,
+    -0x1.682f3cc3c7a08da2ce02a41cdc7bed86p-4,
+    0x1.a8aa1d11c44ffp0,
+  },
+  { // Entry 193
+    -0x1.fff18f24f3e4b87bf8c3762cb44f46d6p-1,
+    -0x1.e6669a270c36d4879b428ddba96cd87bp-7,
+    -0x1.95ec8b9e03d54p0,
+  },
+  { // Entry 194
+    0x1.fff18f24f3e4b87bf8c3762cb44f46d6p-1,
+    -0x1.e6669a270c36d4879b428ddba96cd87bp-7,
+    0x1.95ec8b9e03d54p0,
+  },
+  { // Entry 195
+    -0x1.ff20d961624e7063a78203b811f579cap-1,
+    0x1.ddd1ec25e209f1bbf7e17ef6c8450cd7p-5,
+    -0x1.832efa2a435a9p0,
+  },
+  { // Entry 196
+    0x1.ff20d961624e7063a78203b811f579cap-1,
+    0x1.ddd1ec25e209f1bbf7e17ef6c8450cd7p-5,
+    0x1.832efa2a435a9p0,
+  },
+  { // Entry 197
+    -0x1.fb933c40107fd775185ac14918c8fbafp-1,
+    0x1.0cab9115640d993082a7343bb5affea2p-3,
+    -0x1.707168b682dfep0,
+  },
+  { // Entry 198
+    0x1.fb933c40107fd775185ac14918c8fbafp-1,
+    0x1.0cab9115640d993082a7343bb5affea2p-3,
+    0x1.707168b682dfep0,
+  },
+  { // Entry 199
+    -0x1.f54d971881ad685b782ef88e6350f7cdp-1,
+    0x1.a0723a95492edee5dc98394e45f96d88p-3,
+    -0x1.5db3d742c2653p0,
+  },
+  { // Entry 200
+    0x1.f54d971881ad685b782ef88e6350f7cdp-1,
+    0x1.a0723a95492edee5dc98394e45f96d88p-3,
+    0x1.5db3d742c2653p0,
+  },
+  { // Entry 201
+    -0x1.ec5883b7b6cf4d859ab04e15d53698c9p-1,
+    0x1.18fee96a1a585928a94cda7e3d916fe1p-2,
+    -0x1.4af645cf01ea8p0,
+  },
+  { // Entry 202
+    0x1.ec5883b7b6cf4d859ab04e15d53698c9p-1,
+    0x1.18fee96a1a585928a94cda7e3d916fe1p-2,
+    0x1.4af645cf01ea8p0,
+  },
+  { // Entry 203
+    -0x1.e0c04a94e17309c806c1c78bddc1d607p-1,
+    0x1.6043621b13be2ff07085f8278598e566p-2,
+    -0x1.3838b45b416fdp0,
+  },
+  { // Entry 204
+    0x1.e0c04a94e17309c806c1c78bddc1d607p-1,
+    0x1.6043621b13be2ff07085f8278598e566p-2,
+    0x1.3838b45b416fdp0,
+  },
+  { // Entry 205
+    -0x1.d294d1f96c7ebdb9869dd97cf574ddb9p-1,
+    0x1.a5a4ccf40d9d9ba97faa4e23ecce9e3ap-2,
+    -0x1.257b22e780f52p0,
+  },
+  { // Entry 206
+    0x1.d294d1f96c7ebdb9869dd97cf574ddb9p-1,
+    0x1.a5a4ccf40d9d9ba97faa4e23ecce9e3ap-2,
+    0x1.257b22e780f52p0,
+  },
+  { // Entry 207
+    -0x1.c1e9883373d7ecc48c92dc8875505f7ep-1,
+    0x1.e8c405f36f85b7f5d6a38dfd4a692341p-2,
+    -0x1.12bd9173c07abp0,
+  },
+  { // Entry 208
+    0x1.c1e9883373d7ecc48c92dc8875505f7ep-1,
+    0x1.e8c405f36f85b7f5d6a38dfd4a692341p-2,
+    0x1.12bd9173c07abp0,
+  },
+  { // Entry 209
+    -0x1.a2c289d9d055ac377f67d7a54a0b3005p-1,
+    0x1.26976a6c4e0f86633327f1ceecb508aep-1,
+    -0x1.ea5c3ed5b3850p-1,
+  },
+  { // Entry 210
+    0x1.a2c289d9d055ac377f67d7a54a0b3005p-1,
+    0x1.26976a6c4e0f86633327f1ceecb508aep-1,
+    0x1.ea5c3ed5b3850p-1,
+  },
+  { // Entry 211
+    -0x1.95f05257dbcb5f4b12636c5878ea405ap-1,
+    0x1.3805a1882009f2843da808e959f17861p-1,
+    -0x1.d4b87dab670a0p-1,
+  },
+  { // Entry 212
+    0x1.95f05257dbcb5f4b12636c5878ea405ap-1,
+    0x1.3805a1882009f2843da808e959f17861p-1,
+    0x1.d4b87dab670a0p-1,
+  },
+  { // Entry 213
+    -0x1.88647f26a6e0f6b2715a6c3797ec11f5p-1,
+    0x1.48e52e0a65bcb3cd46455c4d2338bdf2p-1,
+    -0x1.bf14bc811a8f0p-1,
+  },
+  { // Entry 214
+    0x1.88647f26a6e0f6b2715a6c3797ec11f5p-1,
+    0x1.48e52e0a65bcb3cd46455c4d2338bdf2p-1,
+    0x1.bf14bc811a8f0p-1,
+  },
+  { // Entry 215
+    -0x1.7a2541dfd4e752de38f04aba21fc9d9fp-1,
+    0x1.592e58ea0a9eec0b357eb4e9a83b0ea5p-1,
+    -0x1.a970fb56ce140p-1,
+  },
+  { // Entry 216
+    0x1.7a2541dfd4e752de38f04aba21fc9d9fp-1,
+    0x1.592e58ea0a9eec0b357eb4e9a83b0ea5p-1,
+    0x1.a970fb56ce140p-1,
+  },
+  { // Entry 217
+    -0x1.6b391e25bc26cbbcf7a0184070af9c39p-1,
+    0x1.68d9afe052d1f0e9324ae876961bcdb1p-1,
+    -0x1.93cd3a2c81990p-1,
+  },
+  { // Entry 218
+    0x1.6b391e25bc26cbbcf7a0184070af9c39p-1,
+    0x1.68d9afe052d1f0e9324ae876961bcdb1p-1,
+    0x1.93cd3a2c81990p-1,
+  },
+  { // Entry 219
+    -0x1.5ba6e6a8e706535b98fc99dfaef824f1p-1,
+    0x1.77e008d0775e744eb16a2c4ec7184c43p-1,
+    -0x1.7e297902351e0p-1,
+  },
+  { // Entry 220
+    0x1.5ba6e6a8e706535b98fc99dfaef824f1p-1,
+    0x1.77e008d0775e744eb16a2c4ec7184c43p-1,
+    0x1.7e297902351e0p-1,
+  },
+  { // Entry 221
+    -0x1.4b75ba096fa549eb93595d8194ab917fp-1,
+    0x1.863a850e438fe029302aba0f5f127616p-1,
+    -0x1.6885b7d7e8a30p-1,
+  },
+  { // Entry 222
+    0x1.4b75ba096fa549eb93595d8194ab917fp-1,
+    0x1.863a850e438fe029302aba0f5f127616p-1,
+    0x1.6885b7d7e8a30p-1,
+  },
+  { // Entry 223
+    -0x1.3aacff95a3122b15f372bfd2fdf9a75fp-1,
+    0x1.93e2948233fce814439ed51fd2548920p-1,
+    -0x1.52e1f6ad9c280p-1,
+  },
+  { // Entry 224
+    0x1.3aacff95a3122b15f372bfd2fdf9a75fp-1,
+    0x1.93e2948233fce814439ed51fd2548920p-1,
+    0x1.52e1f6ad9c280p-1,
+  },
+  { // Entry 225
+    -0x1.295463e769284a5aed17a443392f38f3p-1,
+    0x1.a0d1f8a9a791d4b5694ca68a42fe6c9bp-1,
+    -0x1.3d3e35834fad0p-1,
+  },
+  { // Entry 226
+    0x1.295463e769284a5aed17a443392f38f3p-1,
+    0x1.a0d1f8a9a791d4b5694ca68a42fe6c9bp-1,
+    0x1.3d3e35834fad0p-1,
+  },
+  { // Entry 227
+    -0x1.fc769b77e588495a6f642ca24e4ed3fcp-2,
+    0x1.bc6bd861e13de309428e00f7bef6c3ecp-1,
+    -0x1.0a0b02501c799p-1,
+  },
+  { // Entry 228
+    0x1.fc769b77e588495a6f642ca24e4ed3fcp-2,
+    0x1.bc6bd861e13de309428e00f7bef6c3ecp-1,
+    0x1.0a0b02501c799p-1,
+  },
+  { // Entry 229
+    -0x1.c853c78462de46b5743315612f8b5a7cp-2,
+    0x1.ca59c6fa3d9ce238a227393b6b075bc5p-1,
+    -0x1.d8f7208e6b82cp-2,
+  },
+  { // Entry 230
+    0x1.c853c78462de46b5743315612f8b5a7cp-2,
+    0x1.ca59c6fa3d9ce238a227393b6b075bc5p-1,
+    0x1.d8f7208e6b82cp-2,
+  },
+  { // Entry 231
+    -0x1.92aba90aaf27249de49c78fc643c8b72p-2,
+    0x1.d6c0b125791cffce83e32564712b78c6p-1,
+    -0x1.9dd83c7c9e126p-2,
+  },
+  { // Entry 232
+    0x1.92aba90aaf27249de49c78fc643c8b72p-2,
+    0x1.d6c0b125791cffce83e32564712b78c6p-1,
+    0x1.9dd83c7c9e126p-2,
+  },
+  { // Entry 233
+    -0x1.5bac064658f39460c83113c0a0097a0cp-2,
+    0x1.e1960261829858391645bbe12019e58ap-1,
+    -0x1.62b9586ad0a20p-2,
+  },
+  { // Entry 234
+    0x1.5bac064658f39460c83113c0a0097a0cp-2,
+    0x1.e1960261829858391645bbe12019e58ap-1,
+    0x1.62b9586ad0a20p-2,
+  },
+  { // Entry 235
+    -0x1.2383ca8078e58477cd5fb1d9de031dcep-2,
+    0x1.ead07cc6356964e27a1036d2f8b158f7p-1,
+    -0x1.279a74590331ap-2,
+  },
+  { // Entry 236
+    0x1.2383ca8078e58477cd5fb1d9de031dcep-2,
+    0x1.ead07cc6356964e27a1036d2f8b158f7p-1,
+    0x1.279a74590331ap-2,
+  },
+  { // Entry 237
+    -0x1.d4c5bc11d2371af2fe25ef5ede2766a3p-3,
+    0x1.f26840e7b2188f7a0cc661a0ede3728bp-1,
+    -0x1.d8f7208e6b829p-3,
+  },
+  { // Entry 238
+    0x1.d4c5bc11d2371af2fe25ef5ede2766a3p-3,
+    0x1.f26840e7b2188f7a0cc661a0ede3728bp-1,
+    0x1.d8f7208e6b829p-3,
+  },
+  { // Entry 239
+    -0x1.60f3faaf43023d3c7863ae06d4d59774p-3,
+    0x1.f856d48db797dec0b79e1353409dc3f2p-1,
+    -0x1.62b9586ad0a1ep-3,
+  },
+  { // Entry 240
+    0x1.60f3faaf43023d3c7863ae06d4d59774p-3,
+    0x1.f856d48db797dec0b79e1353409dc3f2p-1,
+    0x1.62b9586ad0a1ep-3,
+  },
+  { // Entry 241
+    -0x1.d7ea3de45a9d6563ac005c0c5bad8c50p-4,
+    0x1.fc97283a424797215f8a8d1967736c9bp-1,
+    -0x1.d8f7208e6b826p-4,
+  },
+  { // Entry 242
+    0x1.d7ea3de45a9d6563ac005c0c5bad8c50p-4,
+    0x1.fc97283a424797215f8a8d1967736c9bp-1,
+    0x1.d8f7208e6b826p-4,
+  },
+  { // Entry 243
+    -0x1.d8b3df489987a6fe0eead008e720aa22p-5,
+    0x1.ff259b7ab9f4f9a8cb9f1c333272e409p-1,
+    -0x1.d8f7208e6b82dp-5,
+  },
+  { // Entry 244
+    0x1.d8b3df489987a6fe0eead008e720aa22p-5,
+    0x1.ff259b7ab9f4f9a8cb9f1c333272e409p-1,
+    0x1.d8f7208e6b82dp-5,
+  },
+  { // Entry 245
+    0x1.d8b3df489987a6fe0eead008e720aa22p-5,
+    0x1.ff259b7ab9f4f9a8cb9f1c333272e409p-1,
+    0x1.d8f7208e6b82dp-5,
+  },
+  { // Entry 246
+    -0x1.d8b3df489987a6fe0eead008e720aa22p-5,
+    0x1.ff259b7ab9f4f9a8cb9f1c333272e409p-1,
+    -0x1.d8f7208e6b82dp-5,
+  },
+  { // Entry 247
+    0x1.d7ea3de45a9dd4a4bccd1a8c048faf4cp-4,
+    0x1.fc97283a424795847294654a1d8a08edp-1,
+    0x1.d8f7208e6b82dp-4,
+  },
+  { // Entry 248
+    -0x1.d7ea3de45a9dd4a4bccd1a8c048faf4cp-4,
+    0x1.fc97283a424795847294654a1d8a08edp-1,
+    -0x1.d8f7208e6b82dp-4,
+  },
+  { // Entry 249
+    0x1.60f3faaf43027c4752f564f9d0818fe8p-3,
+    0x1.f856d48db797dbfecfa8b4cd3be44027p-1,
+    0x1.62b9586ad0a22p-3,
+  },
+  { // Entry 250
+    -0x1.60f3faaf43027c4752f564f9d0818fe8p-3,
+    0x1.f856d48db797dbfecfa8b4cd3be44027p-1,
+    -0x1.62b9586ad0a22p-3,
+  },
+  { // Entry 251
+    0x1.d4c5bc11d23759400642e5a1efdc0f85p-3,
+    0x1.f26840e7b2188bd0814e3dfc7f6f3f87p-1,
+    0x1.d8f7208e6b82dp-3,
+  },
+  { // Entry 252
+    -0x1.d4c5bc11d23759400642e5a1efdc0f85p-3,
+    0x1.f26840e7b2188bd0814e3dfc7f6f3f87p-1,
+    -0x1.d8f7208e6b82dp-3,
+  },
+  { // Entry 253
+    0x1.2383ca8078e5a324d52c1530742cd4f5p-2,
+    0x1.ead07cc6356960546ae634ef62621fb2p-1,
+    0x1.279a74590331cp-2,
+  },
+  { // Entry 254
+    -0x1.2383ca8078e5a324d52c1530742cd4f5p-2,
+    0x1.ead07cc6356960546ae634ef62621fb2p-1,
+    -0x1.279a74590331cp-2,
+  },
+  { // Entry 255
+    0x1.5bac064658f3b27a28572bea256195efp-2,
+    0x1.e1960261829852ca662ca27d518c2fa9p-1,
+    0x1.62b9586ad0a22p-2,
+  },
+  { // Entry 256
+    -0x1.5bac064658f3b27a28572bea256195efp-2,
+    0x1.e1960261829852ca662ca27d518c2fa9p-1,
+    -0x1.62b9586ad0a22p-2,
+  },
+  { // Entry 257
+    0x1.92aba90aaf274209efaed08e34071e3bp-2,
+    0x1.d6c0b125791cf983d53efaa7d45e291ep-1,
+    0x1.9dd83c7c9e128p-2,
+  },
+  { // Entry 258
+    -0x1.92aba90aaf274209efaed08e34071e3bp-2,
+    0x1.d6c0b125791cf983d53efaa7d45e291ep-1,
+    -0x1.9dd83c7c9e128p-2,
+  },
+  { // Entry 259
+    0x1.c853c78462de635b10a2b93afd75da26p-2,
+    0x1.ca59c6fa3d9cdb17530927aff1b33abbp-1,
+    0x1.d8f7208e6b82ep-2,
+  },
+  { // Entry 260
+    -0x1.c853c78462de635b10a2b93afd75da26p-2,
+    0x1.ca59c6fa3d9cdb17530927aff1b33abbp-1,
+    -0x1.d8f7208e6b82ep-2,
+  },
+  { // Entry 261
+    0x1.fc769b77e588495a6f642ca24e4ed3fcp-2,
+    0x1.bc6bd861e13de309428e00f7bef6c3ecp-1,
+    0x1.0a0b02501c799p-1,
+  },
+  { // Entry 262
+    -0x1.fc769b77e588495a6f642ca24e4ed3fcp-2,
+    0x1.bc6bd861e13de309428e00f7bef6c3ecp-1,
+    -0x1.0a0b02501c799p-1,
+  },
+  { // Entry 263
+    0x1.295463e769281640ae026f50fc45e301p-1,
+    0x1.a0d1f8a9a791f9dff5c993af4908264dp-1,
+    0x1.3d3e35834faccp-1,
+  },
+  { // Entry 264
+    -0x1.295463e769281640ae026f50fc45e301p-1,
+    0x1.a0d1f8a9a791f9dff5c993af4908264dp-1,
+    -0x1.3d3e35834faccp-1,
+  },
+  { // Entry 265
+    0x1.3aacff95a311f899a0e279535e81c4ecp-1,
+    0x1.93e2948233fd0f69e3918982148f8265p-1,
+    0x1.52e1f6ad9c27cp-1,
+  },
+  { // Entry 266
+    -0x1.3aacff95a311f899a0e279535e81c4ecp-1,
+    0x1.93e2948233fd0f69e3918982148f8265p-1,
+    -0x1.52e1f6ad9c27cp-1,
+  },
+  { // Entry 267
+    0x1.4b75ba096fa5192442b7950f960f8006p-1,
+    0x1.863a850e43900997e76be80405437377p-1,
+    0x1.6885b7d7e8a2cp-1,
+  },
+  { // Entry 268
+    -0x1.4b75ba096fa5192442b7950f960f8006p-1,
+    0x1.863a850e43900997e76be80405437377p-1,
+    -0x1.6885b7d7e8a2cp-1,
+  },
+  { // Entry 269
+    0x1.5ba6e6a8e706245f97e28af3ddb700f6p-1,
+    0x1.77e008d0775e9fc38e3f492f8e93ff51p-1,
+    0x1.7e297902351dcp-1,
+  },
+  { // Entry 270
+    -0x1.5ba6e6a8e706245f97e28af3ddb700f6p-1,
+    0x1.77e008d0775e9fc38e3f492f8e93ff51p-1,
+    -0x1.7e297902351dcp-1,
+  },
+  { // Entry 271
+    0x1.6b391e25bc269ea1c1a40de62fbc03b4p-1,
+    0x1.68d9afe052d21e50560f9ffb6cc1b945p-1,
+    0x1.93cd3a2c8198cp-1,
+  },
+  { // Entry 272
+    -0x1.6b391e25bc269ea1c1a40de62fbc03b4p-1,
+    0x1.68d9afe052d21e50560f9ffb6cc1b945p-1,
+    -0x1.93cd3a2c8198cp-1,
+  },
+  { // Entry 273
+    0x1.7a2541dfd4e727b86dd309664186ec6bp-1,
+    0x1.592e58ea0a9f1b4fddbaaf868fe47911p-1,
+    0x1.a970fb56ce13cp-1,
+  },
+  { // Entry 274
+    -0x1.7a2541dfd4e727b86dd309664186ec6bp-1,
+    0x1.592e58ea0a9f1b4fddbaaf868fe47911p-1,
+    -0x1.a970fb56ce13cp-1,
+  },
+  { // Entry 275
+    0x1.88647f26a6e0cd95cb991f7ffe61a02ep-1,
+    0x1.48e52e0a65bce4d9d62a31293f7d41c1p-1,
+    0x1.bf14bc811a8ecp-1,
+  },
+  { // Entry 276
+    -0x1.88647f26a6e0cd95cb991f7ffe61a02ep-1,
+    0x1.48e52e0a65bce4d9d62a31293f7d41c1p-1,
+    -0x1.bf14bc811a8ecp-1,
+  },
+  { // Entry 277
+    0x1.95f05257dbcb384a5e326857376dd801p-1,
+    0x1.3805a188200a254247f30462c36acf6ap-1,
+    0x1.d4b87dab6709cp-1,
+  },
+  { // Entry 278
+    -0x1.95f05257dbcb384a5e326857376dd801p-1,
+    0x1.3805a188200a254247f30462c36acf6ap-1,
+    -0x1.d4b87dab6709cp-1,
+  },
+  { // Entry 279
+    0x1.a2c289d9d0558764921a4de355f9448cp-1,
+    0x1.26976a6c4e0fbabb84632bd99feec9c6p-1,
+    0x1.ea5c3ed5b384cp-1,
+  },
+  { // Entry 280
+    -0x1.a2c289d9d0558764921a4de355f9448cp-1,
+    0x1.26976a6c4e0fbabb84632bd99feec9c6p-1,
+    -0x1.ea5c3ed5b384cp-1,
+  },
+  { // Entry 281
+    0x1.c1e9883373d7ecc48c92dc8875505f7ep-1,
+    0x1.e8c405f36f85b7f5d6a38dfd4a692341p-2,
+    0x1.12bd9173c07abp0,
+  },
+  { // Entry 282
+    -0x1.c1e9883373d7ecc48c92dc8875505f7ep-1,
+    0x1.e8c405f36f85b7f5d6a38dfd4a692341p-2,
+    -0x1.12bd9173c07abp0,
+  },
+  { // Entry 283
+    0x1.d294d1f96c7ef26e203c5b309a55671fp-1,
+    0x1.a5a4ccf40d9cb25f16ad97e480c4b483p-2,
+    0x1.257b22e780f56p0,
+  },
+  { // Entry 284
+    -0x1.d294d1f96c7ef26e203c5b309a55671fp-1,
+    0x1.a5a4ccf40d9cb25f16ad97e480c4b483p-2,
+    -0x1.257b22e780f56p0,
+  },
+  { // Entry 285
+    0x1.e0c04a94e17335d073052a0394b9e1c3p-1,
+    0x1.6043621b13bd3f904b3b876df5b2c6f4p-2,
+    0x1.3838b45b41701p0,
+  },
+  { // Entry 286
+    -0x1.e0c04a94e17335d073052a0394b9e1c3p-1,
+    0x1.6043621b13bd3f904b3b876df5b2c6f4p-2,
+    -0x1.3838b45b41701p0,
+  },
+  { // Entry 287
+    0x1.ec5883b7b6cf70a577dd9160d0f8e9d5p-1,
+    0x1.18fee96a1a5762fc6770ff168e06ab3ep-2,
+    0x1.4af645cf01eacp0,
+  },
+  { // Entry 288
+    -0x1.ec5883b7b6cf70a577dd9160d0f8e9d5p-1,
+    0x1.18fee96a1a5762fc6770ff168e06ab3ep-2,
+    -0x1.4af645cf01eacp0,
+  },
+  { // Entry 289
+    0x1.f54d971881ad82629bd84d214194e8ddp-1,
+    0x1.a0723a95492ce998457fb7a0d09a6385p-3,
+    0x1.5db3d742c2657p0,
+  },
+  { // Entry 290
+    -0x1.f54d971881ad82629bd84d214194e8ddp-1,
+    0x1.a0723a95492ce998457fb7a0d09a6385p-3,
+    -0x1.5db3d742c2657p0,
+  },
+  { // Entry 291
+    0x1.fb933c40107fe83fd16c1789e27f69f7p-1,
+    0x1.0cab9115640b9d9d466723bbd5d589bep-3,
+    0x1.707168b682e02p0,
+  },
+  { // Entry 292
+    -0x1.fb933c40107fe83fd16c1789e27f69f7p-1,
+    0x1.0cab9115640b9d9d466723bbd5d589bep-3,
+    -0x1.707168b682e02p0,
+  },
+  { // Entry 293
+    0x1.ff20d961624e77daef329b4029c362dep-1,
+    0x1.ddd1ec25e201f538925bf5bcf7c7df6ep-5,
+    0x1.832efa2a435adp0,
+  },
+  { // Entry 294
+    -0x1.ff20d961624e77daef329b4029c362dep-1,
+    0x1.ddd1ec25e201f538925bf5bcf7c7df6ep-5,
+    -0x1.832efa2a435adp0,
+  },
+  { // Entry 295
+    0x1.fff18f24f3e4b69592294f206d7b32c2p-1,
+    -0x1.e6669a270c56d3a08d91cc2721f92fe1p-7,
+    0x1.95ec8b9e03d58p0,
+  },
+  { // Entry 296
+    -0x1.fff18f24f3e4b69592294f206d7b32c2p-1,
+    -0x1.e6669a270c56d3a08d91cc2721f92fe1p-7,
+    -0x1.95ec8b9e03d58p0,
+  },
+  { // Entry 297
+    0x1.fe043f57369d6a52fa33f0119ec4da19p-1,
+    -0x1.682f3cc3c7a08da2ce02a41cdc7bed86p-4,
+    0x1.a8aa1d11c44ffp0,
+  },
+  { // Entry 298
+    -0x1.fe043f57369d6a52fa33f0119ec4da19p-1,
+    -0x1.682f3cc3c7a08da2ce02a41cdc7bed86p-4,
+    -0x1.a8aa1d11c44ffp0,
+  },
+  { // Entry 299
+    0x1.b3d3695acc4136b2d44714f9b38419b4p-1,
+    0x1.0cb3469a29ea66d4031be769702aad5cp-1,
+    0x1.04aff6d330942p0,
+  },
+  { // Entry 300
+    -0x1.b3d3695acc4136b2d44714f9b38419b4p-1,
+    0x1.0cb3469a29ea66d4031be769702aad5cp-1,
+    -0x1.04aff6d330942p0,
+  },
+  { // Entry 301
+    0x1.b3d41972dc8063994f63413d5e4d8e4bp-1,
+    0x1.0cb228fa7f8117c82e61cf5393341c64p-1,
+    0x1.04b09e98dcdb4p0,
+  },
+  { // Entry 302
+    -0x1.b3d41972dc8063994f63413d5e4d8e4bp-1,
+    0x1.0cb228fa7f8117c82e61cf5393341c64p-1,
+    -0x1.04b09e98dcdb4p0,
+  },
+  { // Entry 303
+    0x1.b3d4c98a318fb66f821d7286ae7dce7bp-1,
+    0x1.0cb10b5a61b05a73e78a3e4447baf514p-1,
+    0x1.04b1465e89226p0,
+  },
+  { // Entry 304
+    -0x1.b3d4c98a318fb66f821d7286ae7dce7bp-1,
+    0x1.0cb10b5a61b05a73e78a3e4447baf514p-1,
+    -0x1.04b1465e89226p0,
+  },
+  { // Entry 305
+    0x1.b3d579a0cb6ee393ff75b58ffe16d13fp-1,
+    0x1.0cafedb9d078a984086928aa40d2e4a5p-1,
+    0x1.04b1ee2435698p0,
+  },
+  { // Entry 306
+    -0x1.b3d579a0cb6ee393ff75b58ffe16d13fp-1,
+    0x1.0cafedb9d078a984086928aa40d2e4a5p-1,
+    -0x1.04b1ee2435698p0,
+  },
+  { // Entry 307
+    0x1.b3d629b6aa1d9f65aad1a2fc932c8bcbp-1,
+    0x1.0caed018cbda7fa59c631cd55b31aa8dp-1,
+    0x1.04b295e9e1b0ap0,
+  },
+  { // Entry 308
+    -0x1.b3d629b6aa1d9f65aad1a2fc932c8bcbp-1,
+    0x1.0caed018cbda7fa59c631cd55b31aa8dp-1,
+    -0x1.04b295e9e1b0ap0,
+  },
+  { // Entry 309
+    0x1.b3d6d9cbcd9b9e43b7fc7fd428a44dd8p-1,
+    0x1.0cadb27753d65785e06d0e464006149ep-1,
+    0x1.04b33daf8df7cp0,
+  },
+  { // Entry 310
+    -0x1.b3d6d9cbcd9b9e43b7fc7fd428a44dd8p-1,
+    0x1.0cadb27753d65785e06d0e464006149ep-1,
+    -0x1.04b33daf8df7cp0,
+  },
+  { // Entry 311
+    0x1.b3d789e035e8948dab275dfe546c5b08p-1,
+    0x1.0cac94d5686cabd2430c20fdf2855b47p-1,
+    0x1.04b3e5753a3eep0,
+  },
+  { // Entry 312
+    -0x1.b3d789e035e8948dab275dfe546c5b08p-1,
+    0x1.0cac94d5686cabd2430c20fdf2855b47p-1,
+    -0x1.04b3e5753a3eep0,
+  },
+  { // Entry 313
+    0x1.b3d839f3e30436a358e93cbdcb2bb367p-1,
+    0x1.0cab7733099df738645574cd482ef4b2p-1,
+    0x1.04b48d3ae6860p0,
+  },
+  { // Entry 314
+    -0x1.b3d839f3e30436a358e93cbdcb2bb367p-1,
+    0x1.0cab7733099df738645574cd482ef4b2p-1,
+    -0x1.04b48d3ae6860p0,
+  },
+  { // Entry 315
+    0x1.b3d8ea06d4ee0684f5741ec777ed88e0p-1,
+    0x1.0caa5990376b061ec1cf3890f1b8e1e3p-1,
+    0x1.04b5350092ccfp0,
+  },
+  { // Entry 316
+    -0x1.b3d8ea06d4ee0684f5741ec777ed88e0p-1,
+    0x1.0caa5990376b061ec1cf3890f1b8e1e3p-1,
+    -0x1.04b5350092ccfp0,
+  },
+  { // Entry 317
+    -0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074,
+  },
+  { // Entry 318
+    0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074,
+  },
+  { // Entry 319
+    -0.0,
+    0x1.p0,
+    -0.0,
+  },
+  { // Entry 320
+    0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074,
+  },
+  { // Entry 321
+    -0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074,
+  },
+  { // Entry 322
+    0x1.1773d561fd5065d0e9607a728a39eed2p-1,
+    0x1.ad02c771c35ed5f01089a00c6a27e0cfp-1,
+    0x1.279a74590331bp-1,
+  },
+  { // Entry 323
+    -0x1.1773d561fd5065d0e9607a728a39eed2p-1,
+    0x1.ad02c771c35ed5f01089a00c6a27e0cfp-1,
+    -0x1.279a74590331bp-1,
+  },
+  { // Entry 324
+    0x1.1773d561fd507338ff9c088d80c680dbp-1,
+    0x1.ad02c771c35ecd3471de9021e6c3b92bp-1,
+    0x1.279a74590331cp-1,
+  },
+  { // Entry 325
+    -0x1.1773d561fd507338ff9c088d80c680dbp-1,
+    0x1.ad02c771c35ecd3471de9021e6c3b92bp-1,
+    -0x1.279a74590331cp-1,
+  },
+  { // Entry 326
+    0x1.1773d561fd5080a115d796a8770d35efp-1,
+    0x1.ad02c771c35ec478d333803762f450d5p-1,
+    0x1.279a74590331dp-1,
+  },
+  { // Entry 327
+    -0x1.1773d561fd5080a115d796a8770d35efp-1,
+    0x1.ad02c771c35ec478d333803762f450d5p-1,
+    -0x1.279a74590331dp-1,
+  },
+  { // Entry 328
+    0x1.f95b8e7107418c11c94d4a54a9da9b7ap-1,
+    -0x1.48d1ddd2b2b3f8c21b9421e65b380735p-3,
+    0x1.bb67ae8584ca9p0,
+  },
+  { // Entry 329
+    -0x1.f95b8e7107418c11c94d4a54a9da9b7ap-1,
+    -0x1.48d1ddd2b2b3f8c21b9421e65b380735p-3,
+    -0x1.bb67ae8584ca9p0,
+  },
+  { // Entry 330
+    0x1.f95b8e71074186ee81d5ff89d8fae545p-1,
+    -0x1.48d1ddd2b2b47718ff3063b6bd981099p-3,
+    0x1.bb67ae8584caap0,
+  },
+  { // Entry 331
+    -0x1.f95b8e71074186ee81d5ff89d8fae545p-1,
+    -0x1.48d1ddd2b2b47718ff3063b6bd981099p-3,
+    -0x1.bb67ae8584caap0,
+  },
+  { // Entry 332
+    0x1.f95b8e71074181cb3a5eb4bf0621d381p-1,
+    -0x1.48d1ddd2b2b4f56fe2cca5871eaf4820p-3,
+    0x1.bb67ae8584cabp0,
+  },
+  { // Entry 333
+    -0x1.f95b8e71074181cb3a5eb4bf0621d381p-1,
+    -0x1.48d1ddd2b2b4f56fe2cca5871eaf4820p-3,
+    -0x1.bb67ae8584cabp0,
+  },
+  { // Entry 334
+    0x1.b1d8305321615ac938cff02be9f25085p-2,
+    0x1.cfc6cfa52ad9f9911db4ca0d45fdb0b3p-1,
+    0x1.bffffffffffffp-2,
+  },
+  { // Entry 335
+    -0x1.b1d8305321615ac938cff02be9f25085p-2,
+    0x1.cfc6cfa52ad9f9911db4ca0d45fdb0b3p-1,
+    -0x1.bffffffffffffp-2,
+  },
+  { // Entry 336
+    0x1.b1d83053216169476f4d1982b9b14ab1p-2,
+    0x1.cfc6cfa52ad9f62d6d5423ca8339a00ap-1,
+    0x1.cp-2,
+  },
+  { // Entry 337
+    -0x1.b1d83053216169476f4d1982b9b14ab1p-2,
+    0x1.cfc6cfa52ad9f62d6d5423ca8339a00ap-1,
+    -0x1.cp-2,
+  },
+  { // Entry 338
+    0x1.b1d83053216177c5a5ca42d98955275ap-2,
+    0x1.cfc6cfa52ad9f2c9bcf37d87c05892f5p-1,
+    0x1.c000000000001p-2,
+  },
+  { // Entry 339
+    -0x1.b1d83053216177c5a5ca42d98955275ap-2,
+    0x1.cfc6cfa52ad9f2c9bcf37d87c05892f5p-1,
+    -0x1.c000000000001p-2,
+  },
+  { // Entry 340
+    0x1.44eb381cf3869ea71ccb36863e4ea65bp-1,
+    0x1.8bb105a5dc90104051d08cb965631807p-1,
+    0x1.5ffffffffffffp-1,
+  },
+  { // Entry 341
+    -0x1.44eb381cf3869ea71ccb36863e4ea65bp-1,
+    0x1.8bb105a5dc90104051d08cb965631807p-1,
+    -0x1.5ffffffffffffp-1,
+  },
+  { // Entry 342
+    0x1.44eb381cf386ab04a4f8656abea80b83p-1,
+    0x1.8bb105a5dc900618f80fa51d303c69p-1,
+    0x1.6p-1,
+  },
+  { // Entry 343
+    -0x1.44eb381cf386ab04a4f8656abea80b83p-1,
+    0x1.8bb105a5dc900618f80fa51d303c69p-1,
+    -0x1.6p-1,
+  },
+  { // Entry 344
+    0x1.44eb381cf386b7622d25944f3eb035dcp-1,
+    0x1.8bb105a5dc8ffbf19e4ebd80fab2cdb8p-1,
+    0x1.6000000000001p-1,
+  },
+  { // Entry 345
+    -0x1.44eb381cf386b7622d25944f3eb035dcp-1,
+    0x1.8bb105a5dc8ffbf19e4ebd80fab2cdb8p-1,
+    -0x1.6000000000001p-1,
+  },
+  { // Entry 346
+    0x1.dad902fa8ac864fd8afa0bdc609ded19p-1,
+    0x1.7ef4842f0bcd11686aaf6f21c9aa8354p-2,
+    0x1.2ffffffffffffp0,
+  },
+  { // Entry 347
+    -0x1.dad902fa8ac864fd8afa0bdc609ded19p-1,
+    0x1.7ef4842f0bcd11686aaf6f21c9aa8354p-2,
+    -0x1.2ffffffffffffp0,
+  },
+  { // Entry 348
+    0x1.dad902fa8ac870f52f1b843ac83bc3edp-1,
+    0x1.7ef4842f0bccd60d4a501dc8bc4b57b3p-2,
+    0x1.3p0,
+  },
+  { // Entry 349
+    -0x1.dad902fa8ac870f52f1b843ac83bc3edp-1,
+    0x1.7ef4842f0bccd60d4a501dc8bc4b57b3p-2,
+    -0x1.3p0,
+  },
+  { // Entry 350
+    0x1.dad902fa8ac87cecd33cfc992dfec1bep-1,
+    0x1.7ef4842f0bcc9ab229f0cc6fad6d378dp-2,
+    0x1.3000000000001p0,
+  },
+  { // Entry 351
+    -0x1.dad902fa8ac87cecd33cfc992dfec1bep-1,
+    0x1.7ef4842f0bcc9ab229f0cc6fad6d378dp-2,
+    -0x1.3000000000001p0,
+  },
+  { // Entry 352
+    0x1.4b707a7acdecf90a188d0230fad3ad58p-1,
+    -0x1.863efa361dc2294e929b9515fb34f9bap-1,
+    0x1.37fffffffffffp1,
+  },
+  { // Entry 353
+    -0x1.4b707a7acdecf90a188d0230fad3ad58p-1,
+    -0x1.863efa361dc2294e929b9515fb34f9bap-1,
+    -0x1.37fffffffffffp1,
+  },
+  { // Entry 354
+    0x1.4b707a7acdecc84239463e78b312fa10p-1,
+    -0x1.863efa361dc252bca1eaeed39749bed7p-1,
+    0x1.380p1,
+  },
+  { // Entry 355
+    -0x1.4b707a7acdecc84239463e78b312fa10p-1,
+    -0x1.863efa361dc252bca1eaeed39749bed7p-1,
+    -0x1.380p1,
+  },
+  { // Entry 356
+    0x1.4b707a7acdec977a59ff7ac0662484ddp-1,
+    -0x1.863efa361dc27c2ab13a48912d45880bp-1,
+    0x1.3800000000001p1,
+  },
+  { // Entry 357
+    -0x1.4b707a7acdec977a59ff7ac0662484ddp-1,
+    -0x1.863efa361dc27c2ab13a48912d45880bp-1,
+    -0x1.3800000000001p1,
+  },
+  { // Entry 358
+    0x1.066e7eb76f5c6678fd8325a81f1925c6p-4,
+    0x1.fef2b2d21cf6c106e86ff9395f8204a0p-1,
+    0x1.069c8b46b3792p-4,
+  },
+  { // Entry 359
+    -0x1.066e7eb76f5c6678fd8325a81f1925c6p-4,
+    0x1.fef2b2d21cf6c106e86ff9395f8204a0p-1,
+    -0x1.069c8b46b3792p-4,
+  },
+  { // Entry 360
+    0x1.05e4761ab8d8f0a7dba834000f236650p-3,
+    0x1.fbcbe693bd8ec85723b6cb55e4f5e78fp-1,
+    0x1.069c8b46b3792p-3,
+  },
+  { // Entry 361
+    -0x1.05e4761ab8d8f0a7dba834000f236650p-3,
+    0x1.fbcbe693bd8ec85723b6cb55e4f5e78fp-1,
+    -0x1.069c8b46b3792p-3,
+  },
+  { // Entry 362
+    0x1.877e2cd4f6fd9ba498e327053032734fp-3,
+    0x1.f68eebfcbb5e841900e2542f7c24bab0p-1,
+    0x1.89ead0ea0d35bp-3,
+  },
+  { // Entry 363
+    -0x1.877e2cd4f6fd9ba498e327053032734fp-3,
+    0x1.f68eebfcbb5e841900e2542f7c24bab0p-1,
+    -0x1.89ead0ea0d35bp-3,
+  },
+  { // Entry 364
+    0x1.03be06f97cbee47698539f977cadbe7ep-2,
+    0x1.ef4145b4aecffbdaaffb78ffb49ac9bdp-1,
+    0x1.069c8b46b3792p-2,
+  },
+  { // Entry 365
+    -0x1.03be06f97cbee47698539f977cadbe7ep-2,
+    0x1.ef4145b4aecffbdaaffb78ffb49ac9bdp-1,
+    -0x1.069c8b46b3792p-2,
+  },
+  { // Entry 366
+    0x1.42abba8c72fbb8ca96f79aa4bb03584ep-2,
+    0x1.e5eaa286fbbc670dbf6392d7c98ab0a0p-1,
+    0x1.4843ae1860576p-2,
+  },
+  { // Entry 367
+    -0x1.42abba8c72fbb8ca96f79aa4bb03584ep-2,
+    0x1.e5eaa286fbbc670dbf6392d7c98ab0a0p-1,
+    -0x1.4843ae1860576p-2,
+  },
+  { // Entry 368
+    0x1.8045fe64e62dc3d686d976d7d5a7c689p-2,
+    0x1.da94d54dd4c0876e18ee97c70d1a4a94p-1,
+    0x1.89ead0ea0d35ap-2,
+  },
+  { // Entry 369
+    -0x1.8045fe64e62dc3d686d976d7d5a7c689p-2,
+    0x1.da94d54dd4c0876e18ee97c70d1a4a94p-1,
+    -0x1.89ead0ea0d35ap-2,
+  },
+  { // Entry 370
+    0x1.bc4c04d71abbeea5ab064ecfbf54c613p-2,
+    0x1.cd4bca9cb5c715302001e446cc93a7bcp-1,
+    0x1.cb91f3bbba13ep-2,
+  },
+  { // Entry 371
+    -0x1.bc4c04d71abbeea5ab064ecfbf54c613p-2,
+    0x1.cd4bca9cb5c715302001e446cc93a7bcp-1,
+    -0x1.cb91f3bbba13ep-2,
+  },
+  { // Entry 372
+    0x1.f67ea975b86a01510e6bde3778138934p-2,
+    0x1.be1d7c3534c40331fddf243d8a0a56b0p-1,
+    0x1.069c8b46b3791p-1,
+  },
+  { // Entry 373
+    -0x1.f67ea975b86a01510e6bde3778138934p-2,
+    0x1.be1d7c3534c40331fddf243d8a0a56b0p-1,
+    -0x1.069c8b46b3791p-1,
+  },
+  { // Entry 374
+    0x1.175059bf0d42524ecb0bf4243b55973dp-1,
+    0x1.ad19e2535aa9678bd5fdafc68817700bp-1,
+    0x1.27701caf89e83p-1,
+  },
+  { // Entry 375
+    -0x1.175059bf0d42524ecb0bf4243b55973dp-1,
+    0x1.ad19e2535aa9678bd5fdafc68817700bp-1,
+    -0x1.27701caf89e83p-1,
+  },
+  { // Entry 376
+    0x1.323b8b1fb4ba21dd12cce820e156a4fcp-1,
+    0x1.9a52e2e0fbcb3a3f4bde6f6ec27767a9p-1,
+    0x1.4843ae1860575p-1,
+  },
+  { // Entry 377
+    -0x1.323b8b1fb4ba21dd12cce820e156a4fcp-1,
+    0x1.9a52e2e0fbcb3a3f4bde6f6ec27767a9p-1,
+    -0x1.4843ae1860575p-1,
+  },
+  { // Entry 378
+    0x1.4be4979c5efb306c1a77024032849b52p-1,
+    0x1.85dc3ea1bbce9a8085f66593a87b7e2ep-1,
+    0x1.69173f8136c67p-1,
+  },
+  { // Entry 379
+    -0x1.4be4979c5efb306c1a77024032849b52p-1,
+    0x1.85dc3ea1bbce9a8085f66593a87b7e2ep-1,
+    -0x1.69173f8136c67p-1,
+  },
+  { // Entry 380
+    0x1.643080d67acc1332c64a85612cacafb9p-1,
+    0x1.6fcb7c6b8b919af3dda53094c9a27aabp-1,
+    0x1.89ead0ea0d359p-1,
+  },
+  { // Entry 381
+    -0x1.643080d67acc1332c64a85612cacafb9p-1,
+    0x1.6fcb7c6b8b919af3dda53094c9a27aabp-1,
+    -0x1.89ead0ea0d359p-1,
+  },
+  { // Entry 382
+    0x1.7b05b7b6c612e5b08d5efe49a46e21a1p-1,
+    0x1.5837d2817cf303ef6dae69faeb0f015ep-1,
+    0x1.aabe6252e3a4bp-1,
+  },
+  { // Entry 383
+    -0x1.7b05b7b6c612e5b08d5efe49a46e21a1p-1,
+    0x1.5837d2817cf303ef6dae69faeb0f015ep-1,
+    -0x1.aabe6252e3a4bp-1,
+  },
+  { // Entry 384
+    0x1.904c37505de48fa8e76287960fd44594p-1,
+    0x1.3f3a0e28bedd40445858f823e150264bp-1,
+    0x1.cb91f3bbba13dp-1,
+  },
+  { // Entry 385
+    -0x1.904c37505de48fa8e76287960fd44594p-1,
+    0x1.3f3a0e28bedd40445858f823e150264bp-1,
+    -0x1.cb91f3bbba13dp-1,
+  },
+  { // Entry 386
+    0x1.a3ed9e252938a14c79c575639c15a91dp-1,
+    0x1.24ec799171642dbd24d259005822bd25p-1,
+    0x1.ec6585249082fp-1,
+  },
+  { // Entry 387
+    -0x1.a3ed9e252938a14c79c575639c15a91dp-1,
+    0x1.24ec799171642dbd24d259005822bd25p-1,
+    -0x1.ec6585249082fp-1,
+  },
+  { // Entry 388
+    0x1.b5d545b109bf935594036798cf40c9b0p-1,
+    0x1.096ac02ec42c85b7b10afed9202785b9p-1,
+    0x1.069c8b46b3791p0,
+  },
+  { // Entry 389
+    -0x1.b5d545b109bf935594036798cf40c9b0p-1,
+    0x1.096ac02ec42c85b7b10afed9202785b9p-1,
+    -0x1.069c8b46b3791p0,
+  },
+  { // Entry 390
+    0x1.c5f058230e7fd14d3e5e315349f699efp-1,
+    0x1.d9a3a336edb7613df062e86a32d09fe1p-2,
+    0x1.170653fb1eb0ap0,
+  },
+  { // Entry 391
+    -0x1.c5f058230e7fd14d3e5e315349f699efp-1,
+    0x1.d9a3a336edb7613df062e86a32d09fe1p-2,
+    -0x1.170653fb1eb0ap0,
+  },
+  { // Entry 392
+    0x1.d42de42dce1346a03d1f6abf0eba9022p-1,
+    0x1.9e7f8652b47582afd29744293170c07cp-2,
+    0x1.27701caf89e83p0,
+  },
+  { // Entry 393
+    -0x1.d42de42dce1346a03d1f6abf0eba9022p-1,
+    0x1.9e7f8652b47582afd29744293170c07cp-2,
+    -0x1.27701caf89e83p0,
+  },
+  { // Entry 394
+    0x1.e07eeeda109cb504afcca860d4b5dd32p-1,
+    0x1.61a76077aee07bb349ca76cf700913d1p-2,
+    0x1.37d9e563f51fcp0,
+  },
+  { // Entry 395
+    -0x1.e07eeeda109cb504afcca860d4b5dd32p-1,
+    0x1.61a76077aee07bb349ca76cf700913d1p-2,
+    -0x1.37d9e563f51fcp0,
+  },
+  { // Entry 396
+    0x1.ead6834909b93371faf3beaddbd60eddp-1,
+    0x1.235b331d8f748e20fb6ddb6a708dba10p-2,
+    0x1.4843ae1860575p0,
+  },
+  { // Entry 397
+    -0x1.ead6834909b93371faf3beaddbd60eddp-1,
+    0x1.235b331d8f748e20fb6ddb6a708dba10p-2,
+    -0x1.4843ae1860575p0,
+  },
+  { // Entry 398
+    0x1.f329c0558e967e4cab58d0fa572d62d2p-1,
+    0x1.c7b90e3024593da8449963cfe08dde85p-3,
+    0x1.58ad76cccb8eep0,
+  },
+  { // Entry 399
+    -0x1.f329c0558e967e4cab58d0fa572d62d2p-1,
+    0x1.c7b90e3024593da8449963cfe08dde85p-3,
+    -0x1.58ad76cccb8eep0,
+  },
+  { // Entry 400
+    0x1.f96fe405f1ac5dc9cf343508067bfcaep-1,
+    0x1.46dc4f4ce83da727ea048cc7d2f276d1p-3,
+    0x1.69173f8136c67p0,
+  },
+  { // Entry 401
+    -0x1.f96fe405f1ac5dc9cf343508067bfcaep-1,
+    0x1.46dc4f4ce83da727ea048cc7d2f276d1p-3,
+    -0x1.69173f8136c67p0,
+  },
+  { // Entry 402
+    0x1.fda254c27a01f4786c149d6a7779cc3ap-1,
+    0x1.894f70befbb99ab7df9d1790a28f48adp-4,
+    0x1.79810835a1fe0p0,
+  },
+  { // Entry 403
+    -0x1.fda254c27a01f4786c149d6a7779cc3ap-1,
+    0x1.894f70befbb99ab7df9d1790a28f48adp-4,
+    -0x1.79810835a1fe0p0,
+  },
+  { // Entry 404
+    0x1.ffbca846c4fc997f1a381420208884e0p-1,
+    0x1.069107ae9332f95fa2c5ceeadfb29f77p-5,
+    0x1.89ead0ea0d359p0,
+  },
+  { // Entry 405
+    -0x1.ffbca846c4fc997f1a381420208884e0p-1,
+    0x1.069107ae9332f95fa2c5ceeadfb29f77p-5,
+    -0x1.89ead0ea0d359p0,
+  },
+  { // Entry 406
+    0x1.ffbca846c4fc9f30bfb458ef2091c8eep-1,
+    -0x1.069107ae9327e0731a748c21f03b5efcp-5,
+    0x1.9a54999e786d2p0,
+  },
+  { // Entry 407
+    -0x1.ffbca846c4fc9f30bfb458ef2091c8eep-1,
+    -0x1.069107ae9327e0731a748c21f03b5efcp-5,
+    -0x1.9a54999e786d2p0,
+  },
+  { // Entry 408
+    0x1.fda254c27a0205875f271435f827160cp-1,
+    -0x1.894f70befbb41417dff843e81fac388bp-4,
+    0x1.aabe6252e3a4bp0,
+  },
+  { // Entry 409
+    -0x1.fda254c27a0205875f271435f827160cp-1,
+    -0x1.894f70befbb41417dff843e81fac388bp-4,
+    -0x1.aabe6252e3a4bp0,
+  },
+  { // Entry 410
+    0x1.f96fe405f1ac7a241e02e58b0cbf3ae7p-1,
+    -0x1.46dc4f4ce83ae9ab1cc1b2367cb753ebp-3,
+    0x1.bb282b074edc4p0,
+  },
+  { // Entry 411
+    -0x1.f96fe405f1ac7a241e02e58b0cbf3ae7p-1,
+    -0x1.46dc4f4ce83ae9ab1cc1b2367cb753ebp-3,
+    -0x1.bb282b074edc4p0,
+  },
+  { // Entry 412
+    0x1.f329c0558e96a5d48272ad4c49ec53b8p-1,
+    -0x1.c7b90e30245688e099860e8d4fff601cp-3,
+    0x1.cb91f3bbba13dp0,
+  },
+  { // Entry 413
+    -0x1.f329c0558e96a5d48272ad4c49ec53b8p-1,
+    -0x1.c7b90e30245688e099860e8d4fff601cp-3,
+    -0x1.cb91f3bbba13dp0,
+  },
+  { // Entry 414
+    0x1.ead6834909b965fdc4b0ceffc0f285c6p-1,
+    -0x1.235b331d8f7339841a517312d0d347fbp-2,
+    0x1.dbfbbc70254b6p0,
+  },
+  { // Entry 415
+    -0x1.ead6834909b965fdc4b0ceffc0f285c6p-1,
+    -0x1.235b331d8f7339841a517312d0d347fbp-2,
+    -0x1.dbfbbc70254b6p0,
+  },
+  { // Entry 416
+    0x1.e07eeeda109cf25f400cd5f46acec887p-1,
+    -0x1.61a76077aedf2e43aca418f7a2e1324dp-2,
+    0x1.ec6585249082fp0,
+  },
+  { // Entry 417
+    -0x1.e07eeeda109cf25f400cd5f46acec887p-1,
+    -0x1.61a76077aedf2e43aca418f7a2e1324dp-2,
+    -0x1.ec6585249082fp0,
+  },
+  { // Entry 418
+    0x1.d42de42dce138e890939e56c439ded90p-1,
+    -0x1.9e7f8652b4743dcc3c3568baff8bf9ebp-2,
+    0x1.fccf4dd8fbba8p0,
+  },
+  { // Entry 419
+    -0x1.d42de42dce138e890939e56c439ded90p-1,
+    -0x1.9e7f8652b4743dcc3c3568baff8bf9ebp-2,
+    -0x1.fccf4dd8fbba8p0,
+  },
+  { // Entry 420
+    0x1.c5f058230e8014ab83ece0c3a638c079p-1,
+    -0x1.d9a3a336edb65efa30e1a6679aa064c2p-2,
+    0x1.069c8b46b3791p1,
+  },
+  { // Entry 421
+    -0x1.c5f058230e8014ab83ece0c3a638c079p-1,
+    -0x1.d9a3a336edb65efa30e1a6679aa064c2p-2,
+    -0x1.069c8b46b3791p1,
+  },
+  { // Entry 422
+    0x1.b5d545b109bfce3fc4d77001afe2f2b6p-1,
+    -0x1.096ac02ec42c24880a5951788cb383c8p-1,
+    0x1.0ed16fa0e914ep1,
+  },
+  { // Entry 423
+    -0x1.b5d545b109bfce3fc4d77001afe2f2b6p-1,
+    -0x1.096ac02ec42c24880a5951788cb383c8p-1,
+    -0x1.0ed16fa0e914ep1,
+  },
+  { // Entry 424
+    0x1.a3ed9e252938d92a5553b3c09d2bddd3p-1,
+    -0x1.24ec79917163dda65afd8109f59cb465p-1,
+    0x1.170653fb1eb0bp1,
+  },
+  { // Entry 425
+    -0x1.a3ed9e252938d92a5553b3c09d2bddd3p-1,
+    -0x1.24ec79917163dda65afd8109f59cb465p-1,
+    -0x1.170653fb1eb0bp1,
+  },
+  { // Entry 426
+    0x1.904c37505de4b8975dd2730e196ddfc3p-1,
+    -0x1.3f3a0e28bedd0cf0c4bfbd8c82a3baafp-1,
+    0x1.1f3b3855544c8p1,
+  },
+  { // Entry 427
+    -0x1.904c37505de4b8975dd2730e196ddfc3p-1,
+    -0x1.3f3a0e28bedd0cf0c4bfbd8c82a3baafp-1,
+    -0x1.1f3b3855544c8p1,
+  },
+  { // Entry 428
+    0x1.7b05b7b6c612fc4fda3812b1f1348389p-1,
+    -0x1.5837d2817cf2eb069035552dc3ae834cp-1,
+    0x1.27701caf89e85p1,
+  },
+  { // Entry 429
+    -0x1.7b05b7b6c612fc4fda3812b1f1348389p-1,
+    -0x1.5837d2817cf2eb069035552dc3ae834cp-1,
+    -0x1.27701caf89e85p1,
+  },
+  { // Entry 430
+    0x1.643080d67acc14620672dda6241ea305p-1,
+    -0x1.6fcb7c6b8b9199ce2f17dd3ee86b3b9ap-1,
+    0x1.2fa50109bf842p1,
+  },
+  { // Entry 431
+    -0x1.643080d67acc14620672dda6241ea305p-1,
+    -0x1.6fcb7c6b8b9199ce2f17dd3ee86b3b9ap-1,
+    -0x1.2fa50109bf842p1,
+  },
+  { // Entry 432
+    0x1.4be4979c5efb194fc82ac367fedf93bcp-1,
+    -0x1.85dc3ea1bbceae2d294421e8c7350f8cp-1,
+    0x1.37d9e563f51ffp1,
+  },
+  { // Entry 433
+    -0x1.4be4979c5efb194fc82ac367fedf93bcp-1,
+    -0x1.85dc3ea1bbceae2d294421e8c7350f8cp-1,
+    -0x1.37d9e563f51ffp1,
+  },
+  { // Entry 434
+    0x1.323b8b1fb4b9efe5075ede8049a85c3dp-1,
+    -0x1.9a52e2e0fbcb5f8a3f55c274f9ec754bp-1,
+    0x1.400ec9be2abbcp1,
+  },
+  { // Entry 435
+    -0x1.323b8b1fb4b9efe5075ede8049a85c3dp-1,
+    -0x1.9a52e2e0fbcb5f8a3f55c274f9ec754bp-1,
+    -0x1.400ec9be2abbcp1,
+  },
+  { // Entry 436
+    0x1.175059bf0d42033bbcf598c88b176e61p-1,
+    -0x1.ad19e2535aa99b049ac0b5858c5d381fp-1,
+    0x1.4843ae1860579p1,
+  },
+  { // Entry 437
+    -0x1.175059bf0d42033bbcf598c88b176e61p-1,
+    -0x1.ad19e2535aa99b049ac0b5858c5d381fp-1,
+    -0x1.4843ae1860579p1,
+  },
+  { // Entry 438
+    0x1.f67ea975b8692521f77d6754b302c5c4p-2,
+    -0x1.be1d7c3534c44132ab1c4130cbe9dfa0p-1,
+    0x1.5078927295f36p1,
+  },
+  { // Entry 439
+    -0x1.f67ea975b8692521f77d6754b302c5c4p-2,
+    -0x1.be1d7c3534c44132ab1c4130cbe9dfa0p-1,
+    -0x1.5078927295f36p1,
+  },
+  { // Entry 440
+    0x1.bc4c04d71abad14efc29a66342ada723p-2,
+    -0x1.cd4bca9cb5c759e4d6dc8601ec3d84b6p-1,
+    0x1.58ad76cccb8f3p1,
+  },
+  { // Entry 441
+    -0x1.bc4c04d71abad14efc29a66342ada723p-2,
+    -0x1.cd4bca9cb5c759e4d6dc8601ec3d84b6p-1,
+    -0x1.58ad76cccb8f3p1,
+  },
+  { // Entry 442
+    0x1.8045fe64e62c62f57f077ea251e2f2dcp-2,
+    -0x1.da94d54dd4c0cedccd73684994422740p-1,
+    0x1.60e25b27012b0p1,
+  },
+  { // Entry 443
+    -0x1.8045fe64e62c62f57f077ea251e2f2dcp-2,
+    -0x1.da94d54dd4c0cedccd73684994422740p-1,
+    -0x1.60e25b27012b0p1,
+  },
+  { // Entry 444
+    0x1.42abba8c72fa12be920b316627512e41p-2,
+    -0x1.e5eaa286fbbcad1e4a6373392e679669p-1,
+    0x1.69173f8136c6dp1,
+  },
+  { // Entry 445
+    -0x1.42abba8c72fa12be920b316627512e41p-2,
+    -0x1.e5eaa286fbbcad1e4a6373392e679669p-1,
+    -0x1.69173f8136c6dp1,
+  },
+  { // Entry 446
+    0x1.03be06f97cbcf866021e5a5c62c6b07ep-2,
+    -0x1.ef4145b4aed03c5f1d39763b1eee6ed8p-1,
+    0x1.714c23db6c62ap1,
+  },
+  { // Entry 447
+    -0x1.03be06f97cbcf866021e5a5c62c6b07ep-2,
+    -0x1.ef4145b4aed03c5f1d39763b1eee6ed8p-1,
+    -0x1.714c23db6c62ap1,
+  },
+  { // Entry 448
+    0x1.877e2cd4f6f94710f2776775b01c73dbp-3,
+    -0x1.f68eebfcbb5eba124d8cc48fd1beb04dp-1,
+    0x1.79810835a1fe7p1,
+  },
+  { // Entry 449
+    -0x1.877e2cd4f6f94710f2776775b01c73dbp-3,
+    -0x1.f68eebfcbb5eba124d8cc48fd1beb04dp-1,
+    -0x1.79810835a1fe7p1,
+  },
+  { // Entry 450
+    0x1.05e4761ab8d421719567717f76712867p-3,
+    -0x1.fbcbe693bd8ef006f5ff02210dfe0619p-1,
+    0x1.81b5ec8fd79a4p1,
+  },
+  { // Entry 451
+    -0x1.05e4761ab8d421719567717f76712867p-3,
+    -0x1.fbcbe693bd8ef006f5ff02210dfe0619p-1,
+    -0x1.81b5ec8fd79a4p1,
+  },
+  { // Entry 452
+    0x1.066e7eb76f5dd2ea19b6991e8a1a3634p-4,
+    -0x1.fef2b2d21cf6be1a2c7ea665ef1f874ep-1,
+    0x1.89ead0ea0d35bp1,
+  },
+  { // Entry 453
+    -0x1.066e7eb76f5dd2ea19b6991e8a1a3634p-4,
+    -0x1.fef2b2d21cf6be1a2c7ea665ef1f874ep-1,
+    -0x1.89ead0ea0d35bp1,
+  },
+  { // Entry 454
+    0x1.03be06f97cbf09cc0badbdae803d7b4ep-2,
+    0x1.ef4145b4aecff6f58edecf24955428c1p-1,
+    -0x1.81b5ec8fd799fp2,
+  },
+  { // Entry 455
+    -0x1.03be06f97cbf09cc0badbdae803d7b4ep-2,
+    0x1.ef4145b4aecff6f58edecf24955428c1p-1,
+    0x1.81b5ec8fd799fp2,
+  },
+  { // Entry 456
+    0x1.f67ea975b86a22f2348778824f95d84ap-2,
+    0x1.be1d7c3534c3f9b9b35619280049de85p-1,
+    -0x1.714c23db6c626p2,
+  },
+  { // Entry 457
+    -0x1.f67ea975b86a22f2348778824f95d84ap-2,
+    0x1.be1d7c3534c3f9b9b35619280049de85p-1,
+    0x1.714c23db6c626p2,
+  },
+  { // Entry 458
+    0x1.643080d67acc210fa27e9247a8286220p-1,
+    0x1.6fcb7c6b8b918d86fc83d612a6587eddp-1,
+    -0x1.60e25b27012adp2,
+  },
+  { // Entry 459
+    -0x1.643080d67acc210fa27e9247a8286220p-1,
+    0x1.6fcb7c6b8b918d86fc83d612a6587eddp-1,
+    0x1.60e25b27012adp2,
+  },
+  { // Entry 460
+    0x1.b5d545b109bf950b419702972b94f8fap-1,
+    0x1.096ac02ec42c82e5b225185bd6c757d5p-1,
+    -0x1.5078927295f34p2,
+  },
+  { // Entry 461
+    -0x1.b5d545b109bf950b419702972b94f8fap-1,
+    0x1.096ac02ec42c82e5b225185bd6c757d5p-1,
+    0x1.5078927295f34p2,
+  },
+  { // Entry 462
+    0x1.ead6834909b9346234dbb601d0486cf2p-1,
+    0x1.235b331d8f7487ce2db97819fae7777cp-2,
+    -0x1.400ec9be2abbbp2,
+  },
+  { // Entry 463
+    -0x1.ead6834909b9346234dbb601d0486cf2p-1,
+    0x1.235b331d8f7487ce2db97819fae7777cp-2,
+    0x1.400ec9be2abbbp2,
+  },
+  { // Entry 464
+    0x1.ffbca846c4fc999a29dc1d6b2d7cb413p-1,
+    0x1.069107ae9332c4a1cd2dc033b8d50598p-5,
+    -0x1.2fa50109bf842p2,
+  },
+  { // Entry 465
+    -0x1.ffbca846c4fc999a29dc1d6b2d7cb413p-1,
+    0x1.069107ae9332c4a1cd2dc033b8d50598p-5,
+    0x1.2fa50109bf842p2,
+  },
+  { // Entry 466
+    0x1.f329c0558e96a518a2af3ae7800a5b65p-1,
+    -0x1.c7b90e30245695bd1ec170f45feeb1ffp-3,
+    -0x1.1f3b3855544c9p2,
+  },
+  { // Entry 467
+    -0x1.f329c0558e96a518a2af3ae7800a5b65p-1,
+    -0x1.c7b90e30245695bd1ec170f45feeb1ffp-3,
+    0x1.1f3b3855544c9p2,
+  },
+  { // Entry 468
+    0x1.c5f058230e8021f21bd0ac2c0f6809a9p-1,
+    -0x1.d9a3a336edb62c1541b8584cd6c00f87p-2,
+    -0x1.0ed16fa0e9150p2,
+  },
+  { // Entry 469
+    -0x1.c5f058230e8021f21bd0ac2c0f6809a9p-1,
+    -0x1.d9a3a336edb62c1541b8584cd6c00f87p-2,
+    0x1.0ed16fa0e9150p2,
+  },
+  { // Entry 470
+    0x1.7b05b7b6c61365a9ac9e908b8e5d3ce4p-1,
+    -0x1.5837d2817cf27705cac7881fb569ffc7p-1,
+    -0x1.fccf4dd8fbbaep1,
+  },
+  { // Entry 471
+    -0x1.7b05b7b6c61365a9ac9e908b8e5d3ce4p-1,
+    -0x1.5837d2817cf27705cac7881fb569ffc7p-1,
+    0x1.fccf4dd8fbbaep1,
+  },
+  { // Entry 472
+    0x1.175059bf0d42f1d6b391f07f96f2353dp-1,
+    -0x1.ad19e2535aa8ffb40066d78aef71fabdp-1,
+    -0x1.dbfbbc70254bcp1,
+  },
+  { // Entry 473
+    -0x1.175059bf0d42f1d6b391f07f96f2353dp-1,
+    -0x1.ad19e2535aa8ffb40066d78aef71fabdp-1,
+    0x1.dbfbbc70254bcp1,
+  },
+  { // Entry 474
+    0x1.42abba8c72fd22194793246b8d19960ap-2,
+    -0x1.e5eaa286fbbc2b129238160df30ce704p-1,
+    -0x1.bb282b074edcap1,
+  },
+  { // Entry 475
+    -0x1.42abba8c72fd22194793246b8d19960ap-2,
+    -0x1.e5eaa286fbbc2b129238160df30ce704p-1,
+    0x1.bb282b074edcap1,
+  },
+  { // Entry 476
+    0x1.066e7eb76f62b5f4563de26dca890017p-4,
+    -0x1.fef2b2d21cf6b40ff3b530ce8dc0d8a7p-1,
+    -0x1.9a54999e786d8p1,
+  },
+  { // Entry 477
+    -0x1.066e7eb76f62b5f4563de26dca890017p-4,
+    -0x1.fef2b2d21cf6b40ff3b530ce8dc0d8a7p-1,
+    0x1.9a54999e786d8p1,
+  },
+  { // Entry 478
+    -0x1.877e2cd4f6fa42586875c5250a169e48p-3,
+    -0x1.f68eebfcbb5eadd65c261cd803990ae1p-1,
+    -0x1.79810835a1fe6p1,
+  },
+  { // Entry 479
+    0x1.877e2cd4f6fa42586875c5250a169e48p-3,
+    -0x1.f68eebfcbb5eadd65c261cd803990ae1p-1,
+    0x1.79810835a1fe6p1,
+  },
+  { // Entry 480
+    -0x1.bc4c04d71aba5dfc098278f168bbd962p-2,
+    -0x1.cd4bca9cb5c775a99729f7ad95b7dce3p-1,
+    -0x1.58ad76cccb8f4p1,
+  },
+  { // Entry 481
+    0x1.bc4c04d71aba5dfc098278f168bbd962p-2,
+    -0x1.cd4bca9cb5c775a99729f7ad95b7dce3p-1,
+    0x1.58ad76cccb8f4p1,
+  },
+  { // Entry 482
+    -0x1.4be4979c5efa871d30ae1cfa66389199p-1,
+    -0x1.85dc3ea1bbcf2aa2e21ec586d5497e35p-1,
+    -0x1.37d9e563f5202p1,
+  },
+  { // Entry 483
+    0x1.4be4979c5efa871d30ae1cfa66389199p-1,
+    -0x1.85dc3ea1bbcf2aa2e21ec586d5497e35p-1,
+    0x1.37d9e563f5202p1,
+  },
+  { // Entry 484
+    -0x1.a3ed9e25293822168958cce1e09f7c11p-1,
+    -0x1.24ec79917164e41addd4bacd4420f9fbp-1,
+    -0x1.170653fb1eb10p1,
+  },
+  { // Entry 485
+    0x1.a3ed9e25293822168958cce1e09f7c11p-1,
+    -0x1.24ec79917164e41addd4bacd4420f9fbp-1,
+    0x1.170653fb1eb10p1,
+  },
+  { // Entry 486
+    -0x1.e07eeeda109c62b340dc36e92169648dp-1,
+    -0x1.61a76077aee23b11f0c673f638003b0ap-2,
+    -0x1.ec6585249083cp0,
+  },
+  { // Entry 487
+    0x1.e07eeeda109c62b340dc36e92169648dp-1,
+    -0x1.61a76077aee23b11f0c673f638003b0ap-2,
+    0x1.ec6585249083cp0,
+  },
+  { // Entry 488
+    -0x1.fda254c27a01dd954db3aea505e49453p-1,
+    -0x1.894f70befbc104b706e85cf4c1c96a52p-4,
+    -0x1.aabe6252e3a58p0,
+  },
+  { // Entry 489
+    0x1.fda254c27a01dd954db3aea505e49453p-1,
+    -0x1.894f70befbc104b706e85cf4c1c96a52p-4,
+    0x1.aabe6252e3a58p0,
+  },
+  { // Entry 490
+    -0x1.f96fe405f1aca02e8f4fd433e59aa973p-1,
+    0x1.46dc4f4ce8373c7c44f13b57363edd3bp-3,
+    -0x1.69173f8136c74p0,
+  },
+  { // Entry 491
+    0x1.f96fe405f1aca02e8f4fd433e59aa973p-1,
+    0x1.46dc4f4ce8373c7c44f13b57363edd3bp-3,
+    0x1.69173f8136c74p0,
+  },
+  { // Entry 492
+    -0x1.d42de42dce13ef040bb1040e3148d7dep-1,
+    0x1.9e7f8652b47289e53fccd54955db4552p-2,
+    -0x1.27701caf89e90p0,
+  },
+  { // Entry 493
+    0x1.d42de42dce13ef040bb1040e3148d7dep-1,
+    0x1.9e7f8652b47289e53fccd54955db4552p-2,
+    0x1.27701caf89e90p0,
+  },
+  { // Entry 494
+    -0x1.904c37505de5930812e3a2a94feaa51bp-1,
+    0x1.3f3a0e28bedbfb066b67abd9c338409ep-1,
+    -0x1.cb91f3bbba157p-1,
+  },
+  { // Entry 495
+    0x1.904c37505de5930812e3a2a94feaa51bp-1,
+    0x1.3f3a0e28bedbfb066b67abd9c338409ep-1,
+    0x1.cb91f3bbba157p-1,
+  },
+  { // Entry 496
+    -0x1.323b8b1fb4bb626dd40cacd74963ac6cp-1,
+    0x1.9a52e2e0fbca4b00c72daa3cdaca257cp-1,
+    -0x1.4843ae186058ep-1,
+  },
+  { // Entry 497
+    0x1.323b8b1fb4bb626dd40cacd74963ac6cp-1,
+    0x1.9a52e2e0fbca4b00c72daa3cdaca257cp-1,
+    0x1.4843ae186058ep-1,
+  },
+  { // Entry 498
+    -0x1.8045fe64e6308bb5c6ce35f834b93c63p-2,
+    0x1.da94d54dd4bff753d988c1755e2ffc04p-1,
+    -0x1.89ead0ea0d38ap-2,
+  },
+  { // Entry 499
+    0x1.8045fe64e6308bb5c6ce35f834b93c63p-2,
+    0x1.da94d54dd4bff753d988c1755e2ffc04p-1,
+    0x1.89ead0ea0d38ap-2,
+  },
+  { // Entry 500
+    -0x1.05e4761ab8dec44ed0fa30d335049c40p-3,
+    0x1.fbcbe693bd8e98423207e36587d942b7p-1,
+    -0x1.069c8b46b37f0p-3,
+  },
+  { // Entry 501
+    0x1.05e4761ab8dec44ed0fa30d335049c40p-3,
+    0x1.fbcbe693bd8e98423207e36587d942b7p-1,
+    0x1.069c8b46b37f0p-3,
+  },
+  { // Entry 502
+    0x1.05e4761ab8d31d00e656372c5c04aa6ep-3,
+    0x1.fbcbe693bd8ef86c1565b3453036e55ep-1,
+    0x1.069c8b46b3734p-3,
+  },
+  { // Entry 503
+    -0x1.05e4761ab8d31d00e656372c5c04aa6ep-3,
+    0x1.fbcbe693bd8ef86c1565b3453036e55ep-1,
+    -0x1.069c8b46b3734p-3,
+  },
+  { // Entry 504
+    0x1.8045fe64e62b19a094399502afb76e5cp-2,
+    0x1.da94d54dd4c11187405ada7f04e5b171p-1,
+    0x1.89ead0ea0d32cp-2,
+  },
+  { // Entry 505
+    -0x1.8045fe64e62b19a094399502afb76e5cp-2,
+    0x1.da94d54dd4c11187405ada7f04e5b171p-1,
+    -0x1.89ead0ea0d32cp-2,
+  },
+  { // Entry 506
+    0x1.323b8b1fb4b907c416d23b04e0ec0e72p-1,
+    0x1.9a52e2e0fbcc0cc83b843bae58c6cdf8p-1,
+    0x1.4843ae186055fp-1,
+  },
+  { // Entry 507
+    -0x1.323b8b1fb4b907c416d23b04e0ec0e72p-1,
+    0x1.9a52e2e0fbcc0cc83b843bae58c6cdf8p-1,
+    -0x1.4843ae186055fp-1,
+  },
+  { // Entry 508
+    0x1.904c37505de3be2ace17ca5487750231p-1,
+    0x1.3f3a0e28bede46f65ca5b5c19ad99dd7p-1,
+    0x1.cb91f3bbba128p-1,
+  },
+  { // Entry 509
+    -0x1.904c37505de3be2ace17ca5487750231p-1,
+    0x1.3f3a0e28bede46f65ca5b5c19ad99dd7p-1,
+    -0x1.cb91f3bbba128p-1,
+  },
+  { // Entry 510
+    0x1.d42de42dce12b82466f2fcb63b294751p-1,
+    0x1.9e7f8652b478066eec563f835097f148p-2,
+    0x1.27701caf89e78p0,
+  },
+  { // Entry 511
+    -0x1.d42de42dce12b82466f2fcb63b294751p-1,
+    0x1.9e7f8652b478066eec563f835097f148p-2,
+    -0x1.27701caf89e78p0,
+  },
+  { // Entry 512
+    0x1.f96fe405f1ac259bf192fd1cf64e2f12p-1,
+    0x1.46dc4f4ce843151b9d14e561879e5fe3p-3,
+    0x1.69173f8136c5cp0,
+  },
+  { // Entry 513
+    -0x1.f96fe405f1ac259bf192fd1cf64e2f12p-1,
+    0x1.46dc4f4ce843151b9d14e561879e5fe3p-3,
+    -0x1.69173f8136c5cp0,
+  },
+  { // Entry 514
+    0x1.fda254c27a02275432d77dd6f9704644p-1,
+    -0x1.894f70befba9211b0dcaa4dca450670fp-4,
+    0x1.aabe6252e3a40p0,
+  },
+  { // Entry 515
+    -0x1.fda254c27a02275432d77dd6f9704644p-1,
+    -0x1.894f70befba9211b0dcaa4dca450670fp-4,
+    -0x1.aabe6252e3a40p0,
+  },
+  { // Entry 516
+    0x1.e07eeeda109d6bf0c935fa10b1280c6dp-1,
+    -0x1.61a76077aedc99952438421f820a2befp-2,
+    0x1.ec65852490824p0,
+  },
+  { // Entry 517
+    -0x1.e07eeeda109d6bf0c935fa10b1280c6dp-1,
+    -0x1.61a76077aedc99952438421f820a2befp-2,
+    -0x1.ec65852490824p0,
+  },
+  { // Entry 518
+    0x1.a3ed9e252939d9793fb2f6f75e5c76e7p-1,
+    -0x1.24ec799171626e36709cfcf7c7752332p-1,
+    0x1.170653fb1eb04p1,
+  },
+  { // Entry 519
+    -0x1.a3ed9e252939d9793fb2f6f75e5c76e7p-1,
+    -0x1.24ec799171626e36709cfcf7c7752332p-1,
+    -0x1.170653fb1eb04p1,
+  },
+  { // Entry 520
+    0x1.4be4979c5efccfe78ea0b6afb0cbba37p-1,
+    -0x1.85dc3ea1bbcd38cbfeb4370d5405eebap-1,
+    0x1.37d9e563f51f6p1,
+  },
+  { // Entry 521
+    -0x1.4be4979c5efccfe78ea0b6afb0cbba37p-1,
+    -0x1.85dc3ea1bbcd38cbfeb4370d5405eebap-1,
+    -0x1.37d9e563f51f6p1,
+  },
+  { // Entry 522
+    0x1.bc4c04d71abfc5df69589a45d5e3196ep-2,
+    -0x1.cd4bca9cb5c628709388a39fc84591d1p-1,
+    0x1.58ad76cccb8e8p1,
+  },
+  { // Entry 523
+    -0x1.bc4c04d71abfc5df69589a45d5e3196ep-2,
+    -0x1.cd4bca9cb5c628709388a39fc84591d1p-1,
+    -0x1.58ad76cccb8e8p1,
+  },
+  { // Entry 524
+    0x1.877e2cd4f70609b1f062295b64aed4bdp-3,
+    -0x1.f68eebfcbb5e1b070b564037f5571a39p-1,
+    0x1.79810835a1fdap1,
+  },
+  { // Entry 525
+    -0x1.877e2cd4f70609b1f062295b64aed4bdp-3,
+    -0x1.f68eebfcbb5e1b070b564037f5571a39p-1,
+    -0x1.79810835a1fdap1,
+  },
+  { // Entry 526
+    -0x1.066e7eb76f4ac293f46486dc328d450bp-4,
+    -0x1.fef2b2d21cf6e544ab7795aed10d9fa7p-1,
+    0x1.9a54999e786ccp1,
+  },
+  { // Entry 527
+    0x1.066e7eb76f4ac293f46486dc328d450bp-4,
+    -0x1.fef2b2d21cf6e544ab7795aed10d9fa7p-1,
+    -0x1.9a54999e786ccp1,
+  },
+  { // Entry 528
+    -0x1.42abba8c72f770595ffe3135a0e0ad83p-2,
+    -0x1.e5eaa286fbbd1d135e216c49a9f7e5dap-1,
+    0x1.bb282b074edbep1,
+  },
+  { // Entry 529
+    0x1.42abba8c72f770595ffe3135a0e0ad83p-2,
+    -0x1.e5eaa286fbbd1d135e216c49a9f7e5dap-1,
+    -0x1.bb282b074edbep1,
+  },
+  { // Entry 530
+    -0x1.175059bf0d406e2fe014e880dd29cfacp-1,
+    -0x1.ad19e2535aaaa2ac87056b6d7776e97ap-1,
+    0x1.dbfbbc70254b0p1,
+  },
+  { // Entry 531
+    0x1.175059bf0d406e2fe014e880dd29cfacp-1,
+    -0x1.ad19e2535aaaa2ac87056b6d7776e97ap-1,
+    -0x1.dbfbbc70254b0p1,
+  },
+  { // Entry 532
+    -0x1.7b05b7b6c6116155f0dc551e316e1e0bp-1,
+    -0x1.5837d2817cf4af8e5e59b13b4aa9b5e3p-1,
+    0x1.fccf4dd8fbba2p1,
+  },
+  { // Entry 533
+    0x1.7b05b7b6c6116155f0dc551e316e1e0bp-1,
+    -0x1.5837d2817cf4af8e5e59b13b4aa9b5e3p-1,
+    -0x1.fccf4dd8fbba2p1,
+  },
+  { // Entry 534
+    -0x1.c5f058230e7ebeb7616779e16fa9b537p-1,
+    -0x1.d9a3a336edbb7de64a2183cb27be4b5bp-2,
+    0x1.0ed16fa0e914ap2,
+  },
+  { // Entry 535
+    0x1.c5f058230e7ebeb7616779e16fa9b537p-1,
+    -0x1.d9a3a336edbb7de64a2183cb27be4b5bp-2,
+    -0x1.0ed16fa0e914ap2,
+  },
+  { // Entry 536
+    -0x1.f329c0558e95fa333d5d2d44d654777cp-1,
+    -0x1.c7b90e30246248b7a0c2c87a3dd25224p-3,
+    0x1.1f3b3855544c3p2,
+  },
+  { // Entry 537
+    0x1.f329c0558e95fa333d5d2d44d654777cp-1,
+    -0x1.c7b90e30246248b7a0c2c87a3dd25224p-3,
+    -0x1.1f3b3855544c3p2,
+  },
+  { // Entry 538
+    -0x1.ffbca846c4fcb237c2947b35b037a2p-1,
+    0x1.069107ae9302caf2068b48842afdf051p-5,
+    0x1.2fa50109bf83cp2,
+  },
+  { // Entry 539
+    0x1.ffbca846c4fcb237c2947b35b037a2p-1,
+    0x1.069107ae9302caf2068b48842afdf051p-5,
+    -0x1.2fa50109bf83cp2,
+  },
+  { // Entry 540
+    -0x1.ead6834909ba0ee69b31e1970df1bb8bp-1,
+    0x1.235b331d8f6ec74aa3de5aed15fa3f68p-2,
+    0x1.400ec9be2abb5p2,
+  },
+  { // Entry 541
+    0x1.ead6834909ba0ee69b31e1970df1bb8bp-1,
+    0x1.235b331d8f6ec74aa3de5aed15fa3f68p-2,
+    -0x1.400ec9be2abb5p2,
+  },
+  { // Entry 542
+    -0x1.b5d545b109c1232b61dd28d8035d95cbp-1,
+    0x1.096ac02ec429f225c99b89bb4c9e5d3ep-1,
+    0x1.5078927295f2ep2,
+  },
+  { // Entry 543
+    0x1.b5d545b109c1232b61dd28d8035d95cbp-1,
+    0x1.096ac02ec429f225c99b89bb4c9e5d3ep-1,
+    -0x1.5078927295f2ep2,
+  },
+  { // Entry 544
+    -0x1.643080d67ace48c0dd1fe3a06bbc4bf5p-1,
+    0x1.6fcb7c6b8b8f773e3b421dded6fc1f26p-1,
+    0x1.60e25b27012a7p2,
+  },
+  { // Entry 545
+    0x1.643080d67ace48c0dd1fe3a06bbc4bf5p-1,
+    0x1.6fcb7c6b8b8f773e3b421dded6fc1f26p-1,
+    -0x1.60e25b27012a7p2,
+  },
+  { // Entry 546
+    -0x1.f67ea975b86f5d4aa92716cc077473a7p-2,
+    0x1.be1d7c3534c280dab43dced670330b63p-1,
+    0x1.714c23db6c620p2,
+  },
+  { // Entry 547
+    0x1.f67ea975b86f5d4aa92716cc077473a7p-2,
+    0x1.be1d7c3534c280dab43dced670330b63p-1,
+    -0x1.714c23db6c620p2,
+  },
+  { // Entry 548
+    -0x1.03be06f97cc4d78fdccbca1d40e86011p-2,
+    0x1.ef4145b4aecf342709a3b19320d1b194p-1,
+    0x1.81b5ec8fd7999p2,
+  },
+  { // Entry 549
+    0x1.03be06f97cc4d78fdccbca1d40e86011p-2,
+    0x1.ef4145b4aecf342709a3b19320d1b194p-1,
+    -0x1.81b5ec8fd7999p2,
+  },
+  { // Entry 550
+    0x1.efb26ef930c4c3fa3245963c1dcec0a6p-5,
+    0x1.ff0fd2c96adfbae576981ee4b34769dep-1,
+    0x1.effffffffffffp-5,
+  },
+  { // Entry 551
+    -0x1.efb26ef930c4c3fa3245963c1dcec0a6p-5,
+    0x1.ff0fd2c96adfbae576981ee4b34769dep-1,
+    -0x1.effffffffffffp-5,
+  },
+  { // Entry 552
+    0x1.efb26ef930c4d3f2b0dbe1931ba5ae64p-5,
+    0x1.ff0fd2c96adfbad5f904a71b2d210a2ap-1,
+    0x1.fp-5,
+  },
+  { // Entry 553
+    -0x1.efb26ef930c4d3f2b0dbe1931ba5ae64p-5,
+    0x1.ff0fd2c96adfbad5f904a71b2d210a2ap-1,
+    -0x1.fp-5,
+  },
+  { // Entry 554
+    0x1.efb26ef930c4e3eb2f722cea197c2036p-5,
+    0x1.ff0fd2c96adfbac67b712f51a6fa2ab3p-1,
+    0x1.f000000000001p-5,
+  },
+  { // Entry 555
+    -0x1.efb26ef930c4e3eb2f722cea197c2036p-5,
+    0x1.ff0fd2c96adfbac67b712f51a6fa2ab3p-1,
+    -0x1.f000000000001p-5,
+  },
+  { // Entry 556
+    0x1.f6baaa131de633ad4e0e7d6465d12a05p-4,
+    0x1.fc210055467fe5c8f76e75fd7083818cp-1,
+    0x1.f7fffffffffffp-4,
+  },
+  { // Entry 557
+    -0x1.f6baaa131de633ad4e0e7d6465d12a05p-4,
+    0x1.fc210055467fe5c8f76e75fd7083818cp-1,
+    -0x1.f7fffffffffffp-4,
+  },
+  { // Entry 558
+    0x1.f6baaa131de6438e5611279864fe7663p-4,
+    0x1.fc210055467fe58a20193399b3bc0dd2p-1,
+    0x1.f80p-4,
+  },
+  { // Entry 559
+    -0x1.f6baaa131de6438e5611279864fe7663p-4,
+    0x1.fc210055467fe58a20193399b3bc0dd2p-1,
+    -0x1.f80p-4,
+  },
+  { // Entry 560
+    0x1.f6baaa131de6536f5e13d1cc6429cc07p-4,
+    0x1.fc210055467fe54b48c3f135f6f29df7p-1,
+    0x1.f800000000001p-4,
+  },
+  { // Entry 561
+    -0x1.f6baaa131de6536f5e13d1cc6429cc07p-4,
+    0x1.fc210055467fe54b48c3f135f6f29df7p-1,
+    -0x1.f800000000001p-4,
+  },
+  { // Entry 562
+    0x1.4a8c3b4e9c7ff00a36e061a0d2295093p-3,
+    0x1.f94984b2552e19e7329413b8c2e8dc51p-1,
+    0x1.4bfffffffffffp-3,
+  },
+  { // Entry 563
+    -0x1.4a8c3b4e9c7ff00a36e061a0d2295093p-3,
+    0x1.f94984b2552e19e7329413b8c2e8dc51p-1,
+    -0x1.4bfffffffffffp-3,
+  },
+  { // Entry 564
+    0x1.4a8c3b4e9c7fffd48305f44a42f5f50fp-3,
+    0x1.f94984b2552e1941ec766c6a82ece4a3p-1,
+    0x1.4c0p-3,
+  },
+  { // Entry 565
+    -0x1.4a8c3b4e9c7fffd48305f44a42f5f50fp-3,
+    0x1.f94984b2552e1941ec766c6a82ece4a3p-1,
+    -0x1.4c0p-3,
+  },
+  { // Entry 566
+    0x1.4a8c3b4e9c800f9ecf2b86f3b3bd6f5ap-3,
+    0x1.f94984b2552e189ca658c51c42e907cep-1,
+    0x1.4c00000000001p-3,
+  },
+  { // Entry 567
+    -0x1.4a8c3b4e9c800f9ecf2b86f3b3bd6f5ap-3,
+    0x1.f94984b2552e189ca658c51c42e907cep-1,
+    -0x1.4c00000000001p-3,
+  },
+  { // Entry 568
+    0x1.2e9cd95baba325fe6067233d4496aaacp-2,
+    0x1.e921dd42f09ba868603ea376f6e2d012p-1,
+    0x1.3333333333332p-2,
+  },
+  { // Entry 569
+    -0x1.2e9cd95baba325fe6067233d4496aaacp-2,
+    0x1.e921dd42f09ba868603ea376f6e2d012p-1,
+    -0x1.3333333333332p-2,
+  },
+  { // Entry 570
+    0x1.2e9cd95baba335476f513ac221d078c7p-2,
+    0x1.e921dd42f09ba60b268bec1fb0878a42p-1,
+    0x1.3333333333333p-2,
+  },
+  { // Entry 571
+    -0x1.2e9cd95baba335476f513ac221d078c7p-2,
+    0x1.e921dd42f09ba60b268bec1fb0878a42p-1,
+    -0x1.3333333333333p-2,
+  },
+  { // Entry 572
+    0x1.2e9cd95baba344907e3b5246fef75d15p-2,
+    0x1.e921dd42f09ba3adecd934c86a0db254p-1,
+    0x1.3333333333334p-2,
+  },
+  { // Entry 573
+    -0x1.2e9cd95baba344907e3b5246fef75d15p-2,
+    0x1.e921dd42f09ba3adecd934c86a0db254p-1,
+    -0x1.3333333333334p-2,
+  },
+  { // Entry 574
+    0x1.3faefc7a5466ef3045c3f1be716ad568p-1,
+    0x1.8feedb86bf0ef3158f8a1dcbef49d123p-1,
+    0x1.594317acc4ef8p-1,
+  },
+  { // Entry 575
+    -0x1.3faefc7a5466ef3045c3f1be716ad568p-1,
+    0x1.8feedb86bf0ef3158f8a1dcbef49d123p-1,
+    -0x1.594317acc4ef8p-1,
+  },
+  { // Entry 576
+    0x1.3faefc7a5466fbafbca027b6e8db8c04p-1,
+    0x1.8feedb86bf0ee91817a64b28b79e5119p-1,
+    0x1.594317acc4ef9p-1,
+  },
+  { // Entry 577
+    -0x1.3faefc7a5466fbafbca027b6e8db8c04p-1,
+    0x1.8feedb86bf0ee91817a64b28b79e5119p-1,
+    -0x1.594317acc4ef9p-1,
+  },
+  { // Entry 578
+    0x1.3faefc7a5467082f337c5daf5ffc56e2p-1,
+    0x1.8feedb86bf0edf1a9fc278857f8ed559p-1,
+    0x1.594317acc4efap-1,
+  },
+  { // Entry 579
+    -0x1.3faefc7a5467082f337c5daf5ffc56e2p-1,
+    0x1.8feedb86bf0edf1a9fc278857f8ed559p-1,
+    -0x1.594317acc4efap-1,
+  },
+  { // Entry 580
+    0x1.6888a4e134b2def5bea51f4cd7d647c6p-1,
+    0x1.6b898fa9efb5dd6f9e17e3442d59b241p-1,
+    0x1.8ffffffffffffp-1,
+  },
+  { // Entry 581
+    -0x1.6888a4e134b2def5bea51f4cd7d647c6p-1,
+    0x1.6b898fa9efb5dd6f9e17e3442d59b241p-1,
+    -0x1.8ffffffffffffp-1,
+  },
+  { // Entry 582
+    0x1.6888a4e134b2ea520b226eca8694b3a2p-1,
+    0x1.6b898fa9efb5d22b58f0d99e9634931ap-1,
+    0x1.9p-1,
+  },
+  { // Entry 583
+    -0x1.6888a4e134b2ea520b226eca8694b3a2p-1,
+    0x1.6b898fa9efb5d22b58f0d99e9634931ap-1,
+    -0x1.9p-1,
+  },
+  { // Entry 584
+    0x1.6888a4e134b2f5ae579fbe4834f8fd55p-1,
+    0x1.6b898fa9efb5c6e713c9cff8feb4918fp-1,
+    0x1.9000000000001p-1,
+  },
+  { // Entry 585
+    -0x1.6888a4e134b2f5ae579fbe4834f8fd55p-1,
+    0x1.6b898fa9efb5c6e713c9cff8feb4918fp-1,
+    -0x1.9000000000001p-1,
+  },
+  { // Entry 586
+    -0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074,
+  },
+  { // Entry 587
+    0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074,
+  },
+  { // Entry 588
+    -0.0,
+    0x1.p0,
+    -0.0,
+  },
+  { // Entry 589
+    0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074,
+  },
+  { // Entry 590
+    -0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074,
+  },
+  { // Entry 591
+    0x1.91f65f10dd812a0b95ff71871ab48207p-5,
+    0x1.ff621e3796d7de4a8ab7d7cd8488f499p-1,
+    0x1.921fb54442d17p-5,
+  },
+  { // Entry 592
+    -0x1.91f65f10dd812a0b95ff71871ab48207p-5,
+    0x1.ff621e3796d7de4a8ab7d7cd8488f499p-1,
+    -0x1.921fb54442d17p-5,
+  },
+  { // Entry 593
+    0x1.91f65f10dd813a06a6f12e3dd9a6a41ep-5,
+    0x1.ff621e3796d7de3dfb04df46987f6450p-1,
+    0x1.921fb54442d18p-5,
+  },
+  { // Entry 594
+    -0x1.91f65f10dd813a06a6f12e3dd9a6a41ep-5,
+    0x1.ff621e3796d7de3dfb04df46987f6450p-1,
+    -0x1.921fb54442d18p-5,
+  },
+  { // Entry 595
+    0x1.91f65f10dd814a01b7e2eaf4989861b7p-5,
+    0x1.ff621e3796d7de316b51e6bfac75542fp-1,
+    0x1.921fb54442d19p-5,
+  },
+  { // Entry 596
+    -0x1.91f65f10dd814a01b7e2eaf4989861b7p-5,
+    0x1.ff621e3796d7de316b51e6bfac75542fp-1,
+    -0x1.921fb54442d19p-5,
+  },
+  { // Entry 597
+    0x1.917a6bc29b42a9cd2e787ee00ca8f8e3p-4,
+    0x1.fd88da3d12525a208898cf58ded0eeb3p-1,
+    0x1.921fb54442d17p-4,
+  },
+  { // Entry 598
+    -0x1.917a6bc29b42a9cd2e787ee00ca8f8e3p-4,
+    0x1.fd88da3d12525a208898cf58ded0eeb3p-1,
+    -0x1.921fb54442d17p-4,
+  },
+  { // Entry 599
+    0x1.917a6bc29b42b9b9754a67729f79346bp-4,
+    0x1.fd88da3d125259ee594b5705767ab649p-1,
+    0x1.921fb54442d18p-4,
+  },
+  { // Entry 600
+    -0x1.917a6bc29b42b9b9754a67729f79346bp-4,
+    0x1.fd88da3d125259ee594b5705767ab649p-1,
+    -0x1.921fb54442d18p-4,
+  },
+  { // Entry 601
+    0x1.917a6bc29b42c9a5bc1c50053247de78p-4,
+    0x1.fd88da3d125259bc29fddeb20e228056p-1,
+    0x1.921fb54442d19p-4,
+  },
+  { // Entry 602
+    -0x1.917a6bc29b42c9a5bc1c50053247de78p-4,
+    0x1.fd88da3d125259bc29fddeb20e228056p-1,
+    -0x1.921fb54442d19p-4,
+  },
+  { // Entry 603
+    0x1.8f8b83c69a60975f98453886f953a0e5p-3,
+    0x1.f6297cff75cb03ab1fced6337e35a245p-1,
+    0x1.921fb54442d17p-3,
+  },
+  { // Entry 604
+    -0x1.8f8b83c69a60975f98453886f953a0e5p-3,
+    0x1.f6297cff75cb03ab1fced6337e35a245p-1,
+    -0x1.921fb54442d17p-3,
+  },
+  { // Entry 605
+    0x1.8f8b83c69a60a710e42d3435516ddaccp-3,
+    0x1.f6297cff75cb02e35a0cf2e64de60626p-1,
+    0x1.921fb54442d18p-3,
+  },
+  { // Entry 606
+    -0x1.8f8b83c69a60a710e42d3435516ddaccp-3,
+    0x1.f6297cff75cb02e35a0cf2e64de60626p-1,
+    -0x1.921fb54442d18p-3,
+  },
+  { // Entry 607
+    0x1.8f8b83c69a60b6c230152fe3a981d686p-3,
+    0x1.f6297cff75cb021b944b0f991d8e9161p-1,
+    0x1.921fb54442d19p-3,
+  },
+  { // Entry 608
+    -0x1.8f8b83c69a60b6c230152fe3a981d686p-3,
+    0x1.f6297cff75cb021b944b0f991d8e9161p-1,
+    -0x1.921fb54442d19p-3,
+  },
+  { // Entry 609
+    0x1.87de2a6aea961a3e9dedea57fe7e6514p-2,
+    0x1.d906bcf328d46672d9c1a865898e5966p-1,
+    0x1.921fb54442d17p-2,
+  },
+  { // Entry 610
+    -0x1.87de2a6aea961a3e9dedea57fe7e6514p-2,
+    0x1.d906bcf328d46672d9c1a865898e5966p-1,
+    -0x1.921fb54442d17p-2,
+  },
+  { // Entry 611
+    0x1.87de2a6aea962906d3d5839ea1a5bcf0p-2,
+    0x1.d906bcf328d463631d6cd2905d4b13f5p-1,
+    0x1.921fb54442d18p-2,
+  },
+  { // Entry 612
+    -0x1.87de2a6aea962906d3d5839ea1a5bcf0p-2,
+    0x1.d906bcf328d463631d6cd2905d4b13f5p-1,
+    -0x1.921fb54442d18p-2,
+  },
+  { // Entry 613
+    0x1.87de2a6aea9637cf09bd1ce544b496eap-2,
+    0x1.d906bcf328d460536117fcbb30ea3e17p-1,
+    0x1.921fb54442d19p-2,
+  },
+  { // Entry 614
+    -0x1.87de2a6aea9637cf09bd1ce544b496eap-2,
+    0x1.d906bcf328d460536117fcbb30ea3e17p-1,
+    -0x1.921fb54442d19p-2,
+  },
+  { // Entry 615
+    0x1.6a09e667f3bcba99afb0135729457874p-1,
+    0x1.6a09e667f3bcd777b6461376ab523242p-1,
+    0x1.921fb54442d17p-1,
+  },
+  { // Entry 616
+    -0x1.6a09e667f3bcba99afb0135729457874p-1,
+    0x1.6a09e667f3bcd777b6461376ab523242p-1,
+    -0x1.921fb54442d17p-1,
+  },
+  { // Entry 617
+    0x1.6a09e667f3bcc5e9fee352f50fd3f4e9p-1,
+    0x1.6a09e667f3bccc276712d3d8c5502387p-1,
+    0x1.921fb54442d18p-1,
+  },
+  { // Entry 618
+    -0x1.6a09e667f3bcc5e9fee352f50fd3f4e9p-1,
+    0x1.6a09e667f3bccc276712d3d8c5502387p-1,
+    -0x1.921fb54442d18p-1,
+  },
+  { // Entry 619
+    0x1.6a09e667f3bcd13a4e169292f607eee5p-1,
+    0x1.6a09e667f3bcc0d717df943adef39253p-1,
+    0x1.921fb54442d19p-1,
+  },
+  { // Entry 620
+    -0x1.6a09e667f3bcd13a4e169292f607eee5p-1,
+    0x1.6a09e667f3bcc0d717df943adef39253p-1,
+    -0x1.921fb54442d19p-1,
+  },
+  { // Entry 621
+    0x1.fffffffffffffffffffffffffe5f56ffp-1,
+    0x1.469898cc51701b839a252049c0b8b50bp-52,
+    0x1.921fb54442d17p0,
+  },
+  { // Entry 622
+    -0x1.fffffffffffffffffffffffffe5f56ffp-1,
+    0x1.469898cc51701b839a252049c0b8b50bp-52,
+    -0x1.921fb54442d17p0,
+  },
+  { // Entry 623
+    0x1.ffffffffffffffffffffffffffec8831p-1,
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    0x1.921fb54442d18p0,
+  },
+  { // Entry 624
+    -0x1.ffffffffffffffffffffffffffec8831p-1,
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    -0x1.921fb54442d18p0,
+  },
+  { // Entry 625
+    0x1.ffffffffffffffffffffffffff79b963p-1,
+    -0x1.72cece675d1fc8f8cbb5bf6c7dbcfba0p-53,
+    0x1.921fb54442d19p0,
+  },
+  { // Entry 626
+    -0x1.ffffffffffffffffffffffffff79b963p-1,
+    -0x1.72cece675d1fc8f8cbb5bf6c7dbcfba0p-53,
+    -0x1.921fb54442d19p0,
+  },
+  { // Entry 627
+    0x1.469898cc51701b839a252049bfaeed42p-51,
+    -0x1.fffffffffffffffffffffffff97d5bffp-1,
+    0x1.921fb54442d17p1,
+  },
+  { // Entry 628
+    -0x1.469898cc51701b839a252049bfaeed42p-51,
+    -0x1.fffffffffffffffffffffffff97d5bffp-1,
+    -0x1.921fb54442d17p1,
+  },
+  { // Entry 629
+    0x1.1a62633145c06e0e689481270436e2edp-53,
+    -0x1.ffffffffffffffffffffffffffb220c5p-1,
+    0x1.921fb54442d18p1,
+  },
+  { // Entry 630
+    -0x1.1a62633145c06e0e689481270436e2edp-53,
+    -0x1.ffffffffffffffffffffffffffb220c5p-1,
+    -0x1.921fb54442d18p1,
+  },
+  { // Entry 631
+    -0x1.72cece675d1fc8f8cbb5bf6c7d5bbc5cp-52,
+    -0x1.fffffffffffffffffffffffffde6e58cp-1,
+    0x1.921fb54442d19p1,
+  },
+  { // Entry 632
+    0x1.72cece675d1fc8f8cbb5bf6c7d5bbc5cp-52,
+    -0x1.fffffffffffffffffffffffffde6e58cp-1,
+    -0x1.921fb54442d19p1,
+  },
+  { // Entry 633
+    -0x1.469898cc51701b839a252049bb87ce1bp-50,
+    0x1.ffffffffffffffffffffffffe5f56ffep-1,
+    0x1.921fb54442d17p2,
+  },
+  { // Entry 634
+    0x1.469898cc51701b839a252049bb87ce1bp-50,
+    0x1.ffffffffffffffffffffffffe5f56ffep-1,
+    -0x1.921fb54442d17p2,
+  },
+  { // Entry 635
+    -0x1.1a62633145c06e0e68948127040bf003p-52,
+    0x1.fffffffffffffffffffffffffec88317p-1,
+    0x1.921fb54442d18p2,
+  },
+  { // Entry 636
+    0x1.1a62633145c06e0e68948127040bf003p-52,
+    0x1.fffffffffffffffffffffffffec88317p-1,
+    -0x1.921fb54442d18p2,
+  },
+  { // Entry 637
+    0x1.72cece675d1fc8f8cbb5bf6c7bd6bf4dp-51,
+    0x1.fffffffffffffffffffffffff79b9631p-1,
+    0x1.921fb54442d19p2,
+  },
+  { // Entry 638
+    -0x1.72cece675d1fc8f8cbb5bf6c7bd6bf4dp-51,
+    0x1.fffffffffffffffffffffffff79b9631p-1,
+    -0x1.921fb54442d19p2,
+  },
+  { // Entry 639
+    -0x1.469898cc51701b839a252049aaeb5182p-49,
+    0x1.ffffffffffffffffffffffff97d5bff8p-1,
+    0x1.921fb54442d17p3,
+  },
+  { // Entry 640
+    0x1.469898cc51701b839a252049aaeb5182p-49,
+    0x1.ffffffffffffffffffffffff97d5bff8p-1,
+    -0x1.921fb54442d17p3,
+  },
+  { // Entry 641
+    -0x1.1a62633145c06e0e689481270360245cp-51,
+    0x1.fffffffffffffffffffffffffb220c5ep-1,
+    0x1.921fb54442d18p3,
+  },
+  { // Entry 642
+    0x1.1a62633145c06e0e689481270360245cp-51,
+    0x1.fffffffffffffffffffffffffb220c5ep-1,
+    -0x1.921fb54442d18p3,
+  },
+  { // Entry 643
+    0x1.72cece675d1fc8f8cbb5bf6c75c2cb0ep-50,
+    0x1.ffffffffffffffffffffffffde6e58c4p-1,
+    0x1.921fb54442d19p3,
+  },
+  { // Entry 644
+    -0x1.72cece675d1fc8f8cbb5bf6c75c2cb0ep-50,
+    0x1.ffffffffffffffffffffffffde6e58c4p-1,
+    -0x1.921fb54442d19p3,
+  },
+  { // Entry 645
+    -0x1.469898cc51701b839a25204968795f1cp-48,
+    0x1.fffffffffffffffffffffffe5f56ffe1p-1,
+    0x1.921fb54442d17p4,
+  },
+  { // Entry 646
+    0x1.469898cc51701b839a25204968795f1cp-48,
+    0x1.fffffffffffffffffffffffe5f56ffe1p-1,
+    -0x1.921fb54442d17p4,
+  },
+  { // Entry 647
+    -0x1.1a62633145c06e0e6894812700b0f5bfp-50,
+    0x1.ffffffffffffffffffffffffec88317ap-1,
+    0x1.921fb54442d18p4,
+  },
+  { // Entry 648
+    0x1.1a62633145c06e0e6894812700b0f5bfp-50,
+    0x1.ffffffffffffffffffffffffec88317ap-1,
+    -0x1.921fb54442d18p4,
+  },
+  { // Entry 649
+    0x1.72cece675d1fc8f8cbb5bf6c5d72fa11p-49,
+    0x1.ffffffffffffffffffffffff79b96313p-1,
+    0x1.921fb54442d19p4,
+  },
+  { // Entry 650
+    -0x1.72cece675d1fc8f8cbb5bf6c5d72fa11p-49,
+    0x1.ffffffffffffffffffffffff79b96313p-1,
+    -0x1.921fb54442d19p4,
+  },
+  { // Entry 651
+    -0x1.469898cc51701b839a2520485eb19584p-47,
+    0x1.fffffffffffffffffffffff97d5bff87p-1,
+    0x1.921fb54442d17p5,
+  },
+  { // Entry 652
+    0x1.469898cc51701b839a2520485eb19584p-47,
+    0x1.fffffffffffffffffffffff97d5bff87p-1,
+    -0x1.921fb54442d17p5,
+  },
+  { // Entry 653
+    -0x1.1a62633145c06e0e68948126f5f43b4cp-49,
+    0x1.ffffffffffffffffffffffffb220c5e9p-1,
+    0x1.921fb54442d18p5,
+  },
+  { // Entry 654
+    0x1.1a62633145c06e0e68948126f5f43b4cp-49,
+    0x1.ffffffffffffffffffffffffb220c5e9p-1,
+    -0x1.921fb54442d18p5,
+  },
+  { // Entry 655
+    0x1.72cece675d1fc8f8cbb5bf6bfc33b61fp-48,
+    0x1.fffffffffffffffffffffffde6e58c4cp-1,
+    0x1.921fb54442d19p5,
+  },
+  { // Entry 656
+    -0x1.72cece675d1fc8f8cbb5bf6bfc33b61fp-48,
+    0x1.fffffffffffffffffffffffde6e58c4cp-1,
+    -0x1.921fb54442d19p5,
+  },
+  { // Entry 657
+    -0x1.469898cc51701b839a25204437926f25p-46,
+    0x1.ffffffffffffffffffffffe5f56ffe1dp-1,
+    0x1.921fb54442d17p6,
+  },
+  { // Entry 658
+    0x1.469898cc51701b839a25204437926f25p-46,
+    0x1.ffffffffffffffffffffffe5f56ffe1dp-1,
+    -0x1.921fb54442d17p6,
+  },
+  { // Entry 659
+    -0x1.1a62633145c06e0e68948126cb01517dp-48,
+    0x1.fffffffffffffffffffffffec88317a7p-1,
+    0x1.921fb54442d18p6,
+  },
+  { // Entry 660
+    0x1.1a62633145c06e0e68948126cb01517dp-48,
+    0x1.fffffffffffffffffffffffec88317a7p-1,
+    -0x1.921fb54442d18p6,
+  },
+  { // Entry 661
+    0x1.72cece675d1fc8f8cbb5bf6a7736a658p-47,
+    0x1.fffffffffffffffffffffff79b963131p-1,
+    0x1.921fb54442d19p6,
+  },
+  { // Entry 662
+    -0x1.72cece675d1fc8f8cbb5bf6a7736a658p-47,
+    0x1.fffffffffffffffffffffff79b963131p-1,
+    -0x1.921fb54442d19p6,
+  },
+  { // Entry 663
+    -0x1.469898cc51701b839a2520339b15d5aap-45,
+    0x1.ffffffffffffffffffffff97d5bff874p-1,
+    0x1.921fb54442d17p7,
+  },
+  { // Entry 664
+    0x1.469898cc51701b839a2520339b15d5aap-45,
+    0x1.ffffffffffffffffffffff97d5bff874p-1,
+    -0x1.921fb54442d17p7,
+  },
+  { // Entry 665
+    -0x1.1a62633145c06e0e689481261f35aa43p-47,
+    0x1.fffffffffffffffffffffffb220c5e9dp-1,
+    0x1.921fb54442d18p7,
+  },
+  { // Entry 666
+    0x1.1a62633145c06e0e689481261f35aa43p-47,
+    0x1.fffffffffffffffffffffffb220c5e9dp-1,
+    -0x1.921fb54442d18p7,
+  },
+  { // Entry 667
+    0x1.72cece675d1fc8f8cbb5bf646342673ap-46,
+    0x1.ffffffffffffffffffffffde6e58c4c6p-1,
+    0x1.921fb54442d19p7,
+  },
+  { // Entry 668
+    -0x1.72cece675d1fc8f8cbb5bf646342673ap-46,
+    0x1.ffffffffffffffffffffffde6e58c4c6p-1,
+    -0x1.921fb54442d19p7,
+  },
+  { // Entry 669
+    0x1.6a09e667f3bcffa60c0f53340fd24904p-1,
+    -0x1.6a09e667f3bc926b59e6d399bd1b906cp-1,
+    0x1.2d97c7f3321d1p1,
+  },
+  { // Entry 670
+    -0x1.6a09e667f3bcffa60c0f53340fd24904p-1,
+    -0x1.6a09e667f3bc926b59e6d399bd1b906cp-1,
+    -0x1.2d97c7f3321d1p1,
+  },
+  { // Entry 671
+    0x1.6a09e667f3bcd264cf4254bc7ab0c9fap-1,
+    -0x1.6a09e667f3bcbfac96b3d2115a3c3e21p-1,
+    0x1.2d97c7f3321d2p1,
+  },
+  { // Entry 672
+    -0x1.6a09e667f3bcd264cf4254bc7ab0c9fap-1,
+    -0x1.6a09e667f3bcbfac96b3d2115a3c3e21p-1,
+    -0x1.2d97c7f3321d2p1,
+  },
+  { // Entry 673
+    0x1.6a09e667f3bca52392755644dfe72357p-1,
+    -0x1.6a09e667f3bcecedd380d088f1b4c43cp-1,
+    0x1.2d97c7f3321d3p1,
+  },
+  { // Entry 674
+    -0x1.6a09e667f3bca52392755644dfe72357p-1,
+    -0x1.6a09e667f3bcecedd380d088f1b4c43cp-1,
+    -0x1.2d97c7f3321d3p1,
+  },
+  { // Entry 675
+    -0x1.6a09e667f3bc8c2df1b752b606a0a472p-1,
+    -0x1.6a09e667f3bd05e3743ed417c44fba46p-1,
+    0x1.f6a7a2955385dp1,
+  },
+  { // Entry 676
+    0x1.6a09e667f3bc8c2df1b752b606a0a472p-1,
+    -0x1.6a09e667f3bd05e3743ed417c44fba46p-1,
+    -0x1.f6a7a2955385dp1,
+  },
+  { // Entry 677
+    -0x1.6a09e667f3bcb96f2e84512da488ff2dp-1,
+    -0x1.6a09e667f3bcd8a23771d5a02ff5e843p-1,
+    0x1.f6a7a2955385ep1,
+  },
+  { // Entry 678
+    0x1.6a09e667f3bcb96f2e84512da488ff2dp-1,
+    -0x1.6a09e667f3bcd8a23771d5a02ff5e843p-1,
+    -0x1.f6a7a2955385ep1,
+  },
+  { // Entry 679
+    -0x1.6a09e667f3bce6b06b514fa53cc9324fp-1,
+    -0x1.6a09e667f3bcab60faa4d72895f3eea5p-1,
+    0x1.f6a7a2955385fp1,
+  },
+  { // Entry 680
+    0x1.6a09e667f3bce6b06b514fa53cc9324fp-1,
+    -0x1.6a09e667f3bcab60faa4d72895f3eea5p-1,
+    -0x1.f6a7a2955385fp1,
+  },
+  { // Entry 681
+    -0x1.ffffffffffffffffffffffffe8b27b6ap-1,
+    -0x1.34f272993d1414a2b39bd8374c1d1631p-50,
+    0x1.2d97c7f3321d1p2,
+  },
+  { // Entry 682
+    0x1.ffffffffffffffffffffffffe8b27b6ap-1,
+    -0x1.34f272993d1414a2b39bd8374c1d1631p-50,
+    -0x1.2d97c7f3321d1p2,
+  },
+  { // Entry 683
+    -0x1.ffffffffffffffffffffffffff50c9bdp-1,
+    -0x1.a79394c9e8a0a5159cdec1ba86377c92p-53,
+    0x1.2d97c7f3321d2p2,
+  },
+  { // Entry 684
+    0x1.ffffffffffffffffffffffffff50c9bdp-1,
+    -0x1.a79394c9e8a0a5159cdec1ba86377c92p-53,
+    -0x1.2d97c7f3321d2p2,
+  },
+  { // Entry 685
+    -0x1.fffffffffffffffffffffffff5ef1810p-1,
+    0x1.961b1acd85d7d6ba98c84f915bbcbc6cp-51,
+    0x1.2d97c7f3321d3p2,
+  },
+  { // Entry 686
+    0x1.fffffffffffffffffffffffff5ef1810p-1,
+    0x1.961b1acd85d7d6ba98c84f915bbcbc6cp-51,
+    -0x1.2d97c7f3321d3p2,
+  },
+  { // Entry 687
+    -0x1.6a09e667f3bd3962193b5373069ba0c2p-1,
+    0x1.6a09e667f3bc58af4cbad35aabb200f4p-1,
+    0x1.5fdbbe9bba774p2,
+  },
+  { // Entry 688
+    0x1.6a09e667f3bd3962193b5373069ba0c2p-1,
+    0x1.6a09e667f3bc58af4cbad35aabb200f4p-1,
+    -0x1.5fdbbe9bba774p2,
+  },
+  { // Entry 689
+    -0x1.6a09e667f3bcdedf9fa15683e51f7e60p-1,
+    0x1.6a09e667f3bcb331c654d049eeba380fp-1,
+    0x1.5fdbbe9bba775p2,
+  },
+  { // Entry 690
+    0x1.6a09e667f3bcdedf9fa15683e51f7e60p-1,
+    0x1.6a09e667f3bcb331c654d049eeba380fp-1,
+    -0x1.5fdbbe9bba775p2,
+  },
+  { // Entry 691
+    -0x1.6a09e667f3bc845d26075994ad02bd98p-1,
+    0x1.6a09e667f3bd0db43feecd391b21d0c4p-1,
+    0x1.5fdbbe9bba776p2,
+  },
+  { // Entry 692
+    0x1.6a09e667f3bc845d26075994ad02bd98p-1,
+    0x1.6a09e667f3bd0db43feecd391b21d0c4p-1,
+    -0x1.5fdbbe9bba776p2,
+  },
+  { // Entry 693
+    0x1.6a09e667f3bc5271e48b5276f438579fp-1,
+    0x1.6a09e667f3bd3f9f816ad456ba1a54a9p-1,
+    0x1.c463abeccb2bap2,
+  },
+  { // Entry 694
+    -0x1.6a09e667f3bc5271e48b5276f438579fp-1,
+    0x1.6a09e667f3bd3f9f816ad456ba1a54a9p-1,
+    -0x1.c463abeccb2bap2,
+  },
+  { // Entry 695
+    0x1.6a09e667f3bcacf45e254f6638cfe8c6p-1,
+    0x1.6a09e667f3bce51d07d0d7679a2d8c53p-1,
+    0x1.c463abeccb2bbp2,
+  },
+  { // Entry 696
+    -0x1.6a09e667f3bcacf45e254f6638cfe8c6p-1,
+    0x1.6a09e667f3bce51d07d0d7679a2d8c53p-1,
+    -0x1.c463abeccb2bbp2,
+  },
+  { // Entry 697
+    0x1.6a09e667f3bd0776d7bf4c5566c6db87p-1,
+    0x1.6a09e667f3bc8a9a8e36da7863a02597p-1,
+    0x1.c463abeccb2bcp2,
+  },
+  { // Entry 698
+    -0x1.6a09e667f3bd0776d7bf4c5566c6db87p-1,
+    0x1.6a09e667f3bc8a9a8e36da7863a02597p-1,
+    -0x1.c463abeccb2bcp2,
+  },
+  { // Entry 699
+    0x1.ffffffffffffffffffffffffe31174f5p-1,
+    0x1.583ebeff65cc226480ae685c2ad9afdap-50,
+    0x1.f6a7a2955385dp2,
+  },
+  { // Entry 700
+    -0x1.ffffffffffffffffffffffffe31174f5p-1,
+    0x1.583ebeff65cc226480ae685c2ad9afdap-50,
+    -0x1.f6a7a2955385dp2,
+  },
+  { // Entry 701
+    0x1.fffffffffffffffffffffffffe194cd4p-1,
+    0x1.60fafbfd9730899202b9a170c4e6a849p-52,
+    0x1.f6a7a2955385ep2,
+  },
+  { // Entry 702
+    -0x1.fffffffffffffffffffffffffe194cd4p-1,
+    0x1.60fafbfd9730899202b9a170c4e6a849p-52,
+    -0x1.f6a7a2955385ep2,
+  },
+  { // Entry 703
+    0x1.fffffffffffffffffffffffff92124b4p-1,
+    -0x1.4f8282013467bb36fea32f479bd48f4ap-51,
+    0x1.f6a7a2955385fp2,
+  },
+  { // Entry 704
+    -0x1.fffffffffffffffffffffffff92124b4p-1,
+    -0x1.4f8282013467bb36fea32f479bd48f4ap-51,
+    -0x1.f6a7a2955385fp2,
+  },
+  { // Entry 705
+    0x1.6a09e667f3bdfae1dcce4f18665681c6p-1,
+    -0x1.6a09e667f3bb972f8927d7b46c737485p-1,
+    0x1.1475cc9eedeffp3,
+  },
+  { // Entry 706
+    -0x1.6a09e667f3bdfae1dcce4f18665681c6p-1,
+    -0x1.6a09e667f3bb972f8927d7b46c737485p-1,
+    -0x1.1475cc9eedeffp3,
+  },
+  { // Entry 707
+    0x1.6a09e667f3bd45dce99a553a6d7d8065p-1,
+    -0x1.6a09e667f3bc4c347c5bd1933ca3261fp-1,
+    0x1.1475cc9eedfp3,
+  },
+  { // Entry 708
+    -0x1.6a09e667f3bd45dce99a553a6d7d8065p-1,
+    -0x1.6a09e667f3bc4c347c5bd1933ca3261fp-1,
+    -0x1.1475cc9eedfp3,
+  },
+  { // Entry 709
+    0x1.6a09e667f3bc90d7f6665b5c1a22056ap-1,
+    -0x1.6a09e667f3bd01396f8fcb71b2505e1fp-1,
+    0x1.1475cc9eedf01p3,
+  },
+  { // Entry 710
+    -0x1.6a09e667f3bc90d7f6665b5c1a22056ap-1,
+    -0x1.6a09e667f3bd01396f8fcb71b2505e1fp-1,
+    -0x1.1475cc9eedf01p3,
+  },
+  { // Entry 711
+    0x1.34f272993d1414a2b39bd8373e0d6b94p-49,
+    -0x1.ffffffffffffffffffffffffa2c9eda8p-1,
+    0x1.2d97c7f3321d1p3,
+  },
+  { // Entry 712
+    -0x1.34f272993d1414a2b39bd8373e0d6b94p-49,
+    -0x1.ffffffffffffffffffffffffa2c9eda8p-1,
+    -0x1.2d97c7f3321d1p3,
+  },
+  { // Entry 713
+    0x1.a79394c9e8a0a5159cdec1ba85a688bdp-52,
+    -0x1.fffffffffffffffffffffffffd4326f5p-1,
+    0x1.2d97c7f3321d2p3,
+  },
+  { // Entry 714
+    -0x1.a79394c9e8a0a5159cdec1ba85a688bdp-52,
+    -0x1.fffffffffffffffffffffffffd4326f5p-1,
+    -0x1.2d97c7f3321d2p3,
+  },
+  { // Entry 715
+    -0x1.961b1acd85d7d6ba98c84f9153c0cc16p-50,
+    -0x1.ffffffffffffffffffffffffd7bc6041p-1,
+    0x1.2d97c7f3321d3p3,
+  },
+  { // Entry 716
+    0x1.961b1acd85d7d6ba98c84f9153c0cc16p-50,
+    -0x1.ffffffffffffffffffffffffd7bc6041p-1,
+    -0x1.2d97c7f3321d3p3,
+  },
+  { // Entry 717
+    -0x1.6a09e667f3bb90f220f856d0b1a406c3p-1,
+    -0x1.6a09e667f3be011f44fdcffc167f7140p-1,
+    0x1.46b9c347764a2p3,
+  },
+  { // Entry 718
+    0x1.6a09e667f3bb90f220f856d0b1a406c3p-1,
+    -0x1.6a09e667f3be011f44fdcffc167f7140p-1,
+    -0x1.46b9c347764a2p3,
+  },
+  { // Entry 719
+    -0x1.6a09e667f3bc45f7142c50af84f26c75p-1,
+    -0x1.6a09e667f3bd4c1a51c9d61e20c523f7p-1,
+    0x1.46b9c347764a3p3,
+  },
+  { // Entry 720
+    0x1.6a09e667f3bc45f7142c50af84f26c75p-1,
+    -0x1.6a09e667f3bd4c1a51c9d61e20c523f7p-1,
+    -0x1.46b9c347764a3p3,
+  },
+  { // Entry 721
+    -0x1.6a09e667f3bcfafc07604a8dfdbe588dp-1,
+    -0x1.6a09e667f3bc97155e95dc3fd0885d14p-1,
+    0x1.46b9c347764a4p3,
+  },
+  { // Entry 722
+    0x1.6a09e667f3bcfafc07604a8dfdbe588dp-1,
+    -0x1.6a09e667f3bc97155e95dc3fd0885d14p-1,
+    -0x1.46b9c347764a4p3,
+  },
+  { // Entry 723
+    -0x1.ffffffffffffffffffffffff9d634e9fp-1,
+    -0x1.3dc585b2c742181326e07c40748873bbp-49,
+    0x1.5fdbbe9bba774p3,
+  },
+  { // Entry 724
+    0x1.ffffffffffffffffffffffff9d634e9fp-1,
+    -0x1.3dc585b2c742181326e07c40748873bbp-49,
+    -0x1.5fdbbe9bba774p3,
+  },
+  { // Entry 725
+    -0x1.fffffffffffffffffffffffffc461178p-1,
+    -0x1.ee2c2d963a10c0993703e20446463301p-52,
+    0x1.5fdbbe9bba775p3,
+  },
+  { // Entry 726
+    0x1.fffffffffffffffffffffffffc461178p-1,
+    -0x1.ee2c2d963a10c0993703e20446463301p-52,
+    -0x1.5fdbbe9bba775p3,
+  },
+  { // Entry 727
+    -0x1.ffffffffffffffffffffffffdb28d451p-1,
+    0x1.8474f49a717bcfd9b23f077ee4d090cfp-50,
+    0x1.5fdbbe9bba776p3,
+  },
+  { // Entry 728
+    0x1.ffffffffffffffffffffffffdb28d451p-1,
+    0x1.8474f49a717bcfd9b23f077ee4d090cfp-50,
+    -0x1.5fdbbe9bba776p3,
+  },
+  { // Entry 729
+    -0x1.6a09e667f3be075cad2d50dfc68cd88fp-1,
+    0x1.6a09e667f3bb8ab4b8c8d5ecf6b910d6p-1,
+    0x1.78fdb9effea45p3,
+  },
+  { // Entry 730
+    0x1.6a09e667f3be075cad2d50dfc68cd88fp-1,
+    0x1.6a09e667f3bb8ab4b8c8d5ecf6b910d6p-1,
+    -0x1.78fdb9effea45p3,
+  },
+  { // Entry 731
+    -0x1.6a09e667f3bd5257b9f95701d3f13f5dp-1,
+    0x1.6a09e667f3bc3fb9abfccfcbcd262aa0p-1,
+    0x1.78fdb9effea46p3,
+  },
+  { // Entry 732
+    0x1.6a09e667f3bd5257b9f95701d3f13f5dp-1,
+    0x1.6a09e667f3bc3fb9abfccfcbcd262aa0p-1,
+    -0x1.78fdb9effea46p3,
+  },
+  { // Entry 733
+    -0x1.6a09e667f3bc9d52c6c55d2386d32c92p-1,
+    0x1.6a09e667f3bcf4be9f30c9aa4910cacfp-1,
+    0x1.78fdb9effea47p3,
+  },
+  { // Entry 734
+    0x1.6a09e667f3bc9d52c6c55d2386d32c92p-1,
+    0x1.6a09e667f3bcf4be9f30c9aa4910cacfp-1,
+    -0x1.78fdb9effea47p3,
+  },
+  { // Entry 735
+    0x1.6a09e667f3bb8477509955093bb292bep-1,
+    0x1.6a09e667f3be0d9a155cd1c3767eb7b3p-1,
+    0x1.ab41b09886fe8p3,
+  },
+  { // Entry 736
+    -0x1.6a09e667f3bb8477509955093bb292bep-1,
+    0x1.6a09e667f3be0d9a155cd1c3767eb7b3p-1,
+    -0x1.ab41b09886fe8p3,
+  },
+  { // Entry 737
+    0x1.6a09e667f3bc397c43cd4ee8153e60a0p-1,
+    0x1.6a09e667f3bd58952228d7e58701d299p-1,
+    0x1.ab41b09886fe9p3,
+  },
+  { // Entry 738
+    -0x1.6a09e667f3bc397c43cd4ee8153e60a0p-1,
+    0x1.6a09e667f3bd58952228d7e58701d299p-1,
+    -0x1.ab41b09886fe9p3,
+  },
+  { // Entry 739
+    0x1.6a09e667f3bcee81370148c69447b4e7p-1,
+    0x1.6a09e667f3bca3902ef4de073d0273e6p-1,
+    0x1.ab41b09886feap3,
+  },
+  { // Entry 740
+    -0x1.6a09e667f3bcee81370148c69447b4e7p-1,
+    0x1.6a09e667f3bca3902ef4de073d0273e6p-1,
+    -0x1.ab41b09886feap3,
+  },
+  { // Entry 741
+    0x1.ffffffffffffffffffffffff922141b4p-1,
+    0x1.4f6babe5db9e1ef40d69c452e135591dp-49,
+    0x1.c463abeccb2bap3,
+  },
+  { // Entry 742
+    -0x1.ffffffffffffffffffffffff922141b4p-1,
+    0x1.4f6babe5db9e1ef40d69c452e135591dp-49,
+    -0x1.c463abeccb2bap3,
+  },
+  { // Entry 743
+    0x1.fffffffffffffffffffffffff9d717a7p-1,
+    0x1.3daeaf976e787bd035a7114be387b5c3p-51,
+    0x1.c463abeccb2bbp3,
+  },
+  { // Entry 744
+    -0x1.fffffffffffffffffffffffff9d717a7p-1,
+    0x1.3daeaf976e787bd035a7114be387b5c3p-51,
+    -0x1.c463abeccb2bbp3,
+  },
+  { // Entry 745
+    0x1.ffffffffffffffffffffffffe18ced9ap-1,
+    -0x1.6128a83448c3c217e52c775a0698d26ap-50,
+    0x1.c463abeccb2bcp3,
+  },
+  { // Entry 746
+    -0x1.ffffffffffffffffffffffffe18ced9ap-1,
+    -0x1.6128a83448c3c217e52c775a0698d26ap-50,
+    -0x1.c463abeccb2bcp3,
+  },
+  { // Entry 747
+    0x1.6a09e667f3be13d77d8c52a726550eacp-1,
+    -0x1.6a09e667f3bb7e39e869d42580908c7cp-1,
+    0x1.dd85a7410f58bp3,
+  },
+  { // Entry 748
+    -0x1.6a09e667f3be13d77d8c52a726550eacp-1,
+    -0x1.6a09e667f3bb7e39e869d42580908c7cp-1,
+    -0x1.dd85a7410f58bp3,
+  },
+  { // Entry 749
+    0x1.6a09e667f3bd5ed28a5858c939f6ddaap-1,
+    -0x1.6a09e667f3bc333edb9dce045d3b0e75p-1,
+    0x1.dd85a7410f58cp3,
+  },
+  { // Entry 750
+    -0x1.6a09e667f3bd5ed28a5858c939f6ddaap-1,
+    -0x1.6a09e667f3bc333edb9dce045d3b0e75p-1,
+    -0x1.dd85a7410f58cp3,
+  },
+  { // Entry 751
+    0x1.6a09e667f3bca9cd97245eeaf316330ep-1,
+    -0x1.6a09e667f3bce843ced1c7e2df6316d4p-1,
+    0x1.dd85a7410f58dp3,
+  },
+  { // Entry 752
+    -0x1.6a09e667f3bca9cd97245eeaf316330ep-1,
+    -0x1.6a09e667f3bce843ced1c7e2df6316d4p-1,
+    -0x1.dd85a7410f58dp3,
+  },
+  { // Entry 753
+    0x1.583ebeff65cc226480ae685c1765dec1p-49,
+    -0x1.ffffffffffffffffffffffff8c45d3d4p-1,
+    0x1.f6a7a2955385dp3,
+  },
+  { // Entry 754
+    -0x1.583ebeff65cc226480ae685c1765dec1p-49,
+    -0x1.ffffffffffffffffffffffff8c45d3d4p-1,
+    -0x1.f6a7a2955385dp3,
+  },
+  { // Entry 755
+    0x1.60fafbfd9730899202b9a170c3971e86p-51,
+    -0x1.fffffffffffffffffffffffff8653353p-1,
+    0x1.f6a7a2955385ep3,
+  },
+  { // Entry 756
+    -0x1.60fafbfd9730899202b9a170c3971e86p-51,
+    -0x1.fffffffffffffffffffffffff8653353p-1,
+    -0x1.f6a7a2955385ep3,
+  },
+  { // Entry 757
+    -0x1.4f8282013467bb36fea32f479753fe7ap-50,
+    -0x1.ffffffffffffffffffffffffe48492d3p-1,
+    0x1.f6a7a2955385fp3,
+  },
+  { // Entry 758
+    0x1.4f8282013467bb36fea32f479753fe7ap-50,
+    -0x1.ffffffffffffffffffffffffe48492d3p-1,
+    -0x1.f6a7a2955385fp3,
+  },
+  { // Entry 759
+    -0x1.6a09e667f3ba0df299d25f82f639251fp-1,
+    -0x1.6a09e667f3bf841ecc23c74599076a81p-1,
+    0x1.07e4cef4cbd96p4,
+  },
+  { // Entry 760
+    0x1.6a09e667f3ba0df299d25f82f639251fp-1,
+    -0x1.6a09e667f3bf841ecc23c74599076a81p-1,
+    -0x1.07e4cef4cbd96p4,
+  },
+  { // Entry 761
+    -0x1.6a09e667f3bb77fc803a5341c552fe0fp-1,
+    -0x1.6a09e667f3be1a14e5bbd38ad60fdd7bp-1,
+    0x1.07e4cef4cbd97p4,
+  },
+  { // Entry 762
+    0x1.6a09e667f3bb77fc803a5341c552fe0fp-1,
+    -0x1.6a09e667f3be1a14e5bbd38ad60fdd7bp-1,
+    -0x1.07e4cef4cbd97p4,
+  },
+  { // Entry 763
+    -0x1.6a09e667f3bce20666a246ff2a62f097p-1,
+    -0x1.6a09e667f3bcb00aff53dfcea90e6a0cp-1,
+    0x1.07e4cef4cbd98p4,
+  },
+  { // Entry 764
+    0x1.6a09e667f3bce20666a246ff2a62f097p-1,
+    -0x1.6a09e667f3bcb00aff53dfcea90e6a0cp-1,
+    -0x1.07e4cef4cbd98p4,
+  },
+  { // Entry 765
+    -0x1.fffffffffffffffffffffffd2531a43dp-1,
+    -0x1.b088e90c77fd12ea79f98631e6f0b74bp-48,
+    0x1.1475cc9eedeffp4,
+  },
+  { // Entry 766
+    0x1.fffffffffffffffffffffffd2531a43dp-1,
+    -0x1.b088e90c77fd12ea79f98631e6f0b74bp-48,
+    -0x1.1475cc9eedeffp4,
+  },
+  { // Entry 767
+    -0x1.ffffffffffffffffffffffff86437656p-1,
+    -0x1.6111d218effa25d4f3f30c654d7c36a1p-49,
+    0x1.1475cc9eedfp4,
+  },
+  { // Entry 768
+    0x1.ffffffffffffffffffffffff86437656p-1,
+    -0x1.6111d218effa25d4f3f30c654d7c36a1p-49,
+    -0x1.1475cc9eedfp4,
+  },
+  { // Entry 769
+    -0x1.ffffffffffffffffffffffffe755486fp-1,
+    0x1.3ddc5bce200bb4561819e73527f5a6d7p-50,
+    0x1.1475cc9eedf01p4,
+  },
+  { // Entry 770
+    0x1.ffffffffffffffffffffffffe755486fp-1,
+    0x1.3ddc5bce200bb4561819e73527f5a6d7p-50,
+    -0x1.1475cc9eedf01p4,
+  },
+  { // Entry 771
+    -0x1.6a09e667f3bed557411f4e4c114d7357p-1,
+    0x1.6a09e667f3babcba24d6d87ecc8f83b4p-1,
+    0x1.2106ca4910068p4,
+  },
+  { // Entry 772
+    0x1.6a09e667f3bed557411f4e4c114d7357p-1,
+    0x1.6a09e667f3babcba24d6d87ecc8f83b4p-1,
+    -0x1.2106ca4910068p4,
+  },
+  { // Entry 773
+    -0x1.6a09e667f3bd6b4d5ab75a909f8e5b4cp-1,
+    0x1.6a09e667f3bc26c40b3ecc3cece1d1a0p-1,
+    0x1.2106ca4910069p4,
+  },
+  { // Entry 774
+    0x1.6a09e667f3bd6b4d5ab75a909f8e5b4cp-1,
+    0x1.6a09e667f3bc26c40b3ecc3cece1d1a0p-1,
+    -0x1.2106ca4910069p4,
+  },
+  { // Entry 775
+    -0x1.6a09e667f3bc0143744f66d3c3c55cd9p-1,
+    0x1.6a09e667f3bd90cdf1a6bff9a32a3923p-1,
+    0x1.2106ca491006ap4,
+  },
+  { // Entry 776
+    0x1.6a09e667f3bc0143744f66d3c3c55cd9p-1,
+    0x1.6a09e667f3bd90cdf1a6bff9a32a3923p-1,
+    -0x1.2106ca491006ap4,
+  },
+  { // Entry 777
+    -0x1.34f272993d1414a2b39bd83705cec120p-48,
+    0x1.fffffffffffffffffffffffe8b27b6a2p-1,
+    0x1.2d97c7f3321d1p4,
+  },
+  { // Entry 778
+    0x1.34f272993d1414a2b39bd83705cec120p-48,
+    0x1.fffffffffffffffffffffffe8b27b6a2p-1,
+    -0x1.2d97c7f3321d1p4,
+  },
+  { // Entry 779
+    -0x1.a79394c9e8a0a5159cdec1ba8362b968p-51,
+    0x1.fffffffffffffffffffffffff50c9bd4p-1,
+    0x1.2d97c7f3321d2p4,
+  },
+  { // Entry 780
+    0x1.a79394c9e8a0a5159cdec1ba8362b968p-51,
+    0x1.fffffffffffffffffffffffff50c9bd4p-1,
+    -0x1.2d97c7f3321d2p4,
+  },
+  { // Entry 781
+    0x1.961b1acd85d7d6ba98c84f9133d10abep-49,
+    0x1.ffffffffffffffffffffffff5ef18107p-1,
+    0x1.2d97c7f3321d3p4,
+  },
+  { // Entry 782
+    -0x1.961b1acd85d7d6ba98c84f9133d10abep-49,
+    0x1.ffffffffffffffffffffffff5ef18107p-1,
+    -0x1.2d97c7f3321d3p4,
+  },
+  { // Entry 783
+    0x1.6a09e667f3ba0177c9735dbb72f09f65p-1,
+    0x1.6a09e667f3bf90999c82c90cebaf9f3fp-1,
+    0x1.3a28c59d54339p4,
+  },
+  { // Entry 784
+    -0x1.6a09e667f3ba0177c9735dbb72f09f65p-1,
+    0x1.6a09e667f3bf90999c82c90cebaf9f3fp-1,
+    -0x1.3a28c59d54339p4,
+  },
+  { // Entry 785
+    0x1.6a09e667f3bb6b81afdb517a4e8548b4p-1,
+    0x1.6a09e667f3be268fb61ad5523532e298p-1,
+    0x1.3a28c59d5433ap4,
+  },
+  { // Entry 786
+    -0x1.6a09e667f3bb6b81afdb517a4e8548b4p-1,
+    0x1.6a09e667f3be268fb61ad5523532e298p-1,
+    -0x1.3a28c59d5433ap4,
+  },
+  { // Entry 787
+    0x1.6a09e667f3bcd58b96434537c0100b9bp-1,
+    0x1.6a09e667f3bcbc85cfb2e19614ac3f88p-1,
+    0x1.3a28c59d5433bp4,
+  },
+  { // Entry 788
+    -0x1.6a09e667f3bcd58b96434537c0100b9bp-1,
+    0x1.6a09e667f3bcbc85cfb2e19614ac3f88p-1,
+    -0x1.3a28c59d5433bp4,
+  },
+  { // Entry 789
+    0x1.fffffffffffffffffffffffd0711f437p-1,
+    0x1.b95bfc26022b165aed3e2a3b12382479p-48,
+    0x1.46b9c347764a2p4,
+  },
+  { // Entry 790
+    -0x1.fffffffffffffffffffffffd0711f437p-1,
+    0x1.b95bfc26022b165aed3e2a3b12382479p-48,
+    -0x1.46b9c347764a2p4,
+  },
+  { // Entry 791
+    0x1.ffffffffffffffffffffffff79c9ec83p-1,
+    0x1.72b7f84c04562cb5da7c5477b957adebp-49,
+    0x1.46b9c347764a3p4,
+  },
+  { // Entry 792
+    -0x1.ffffffffffffffffffffffff79c9ec83p-1,
+    0x1.72b7f84c04562cb5da7c5477b957adebp-49,
+    -0x1.46b9c347764a3p4,
+  },
+  { // Entry 793
+    0x1.ffffffffffffffffffffffffec81e4cfp-1,
+    -0x1.1a900f67f753a6944b07571048f1cad2p-50,
+    0x1.46b9c347764a4p4,
+  },
+  { // Entry 794
+    -0x1.ffffffffffffffffffffffffec81e4cfp-1,
+    -0x1.1a900f67f753a6944b07571048f1cad2p-50,
+    -0x1.46b9c347764a4p4,
+  },
+  { // Entry 795
+    0x1.6a09e667f3bee1d2117e501369fbffefp-1,
+    -0x1.6a09e667f3bab03f5477d6b74f4d55d5p-1,
+    0x1.534ac0f19860bp4,
+  },
+  { // Entry 796
+    -0x1.6a09e667f3bee1d2117e501369fbffefp-1,
+    -0x1.6a09e667f3bab03f5477d6b74f4d55d5p-1,
+    -0x1.534ac0f19860bp4,
+  },
+  { // Entry 797
+    0x1.6a09e667f3bd77c82b165c5804b7b843p-1,
+    -0x1.6a09e667f3bc1a493adfca757c1a741fp-1,
+    0x1.534ac0f19860cp4,
+  },
+  { // Entry 798
+    -0x1.6a09e667f3bd77c82b165c5804b7b843p-1,
+    -0x1.6a09e667f3bc1a493adfca757c1a741fp-1,
+    -0x1.534ac0f19860cp4,
+  },
+  { // Entry 799
+    0x1.6a09e667f3bc0dbe44ae689b35698a2fp-1,
+    -0x1.6a09e667f3bd84532147be323eddac01p-1,
+    0x1.534ac0f19860dp4,
+  },
+  { // Entry 800
+    -0x1.6a09e667f3bc0dbe44ae689b35698a2fp-1,
+    -0x1.6a09e667f3bd84532147be323eddac01p-1,
+    -0x1.534ac0f19860dp4,
+  },
+  { // Entry 801
+    0x1.3dc585b2c742181326e07c40375464dep-48,
+    -0x1.fffffffffffffffffffffffe758d3a7cp-1,
+    0x1.5fdbbe9bba774p4,
+  },
+  { // Entry 802
+    -0x1.3dc585b2c742181326e07c40375464dep-48,
+    -0x1.fffffffffffffffffffffffe758d3a7cp-1,
+    -0x1.5fdbbe9bba774p4,
+  },
+  { // Entry 803
+    0x1.ee2c2d963a10c0993703e20442ad7b8dp-51,
+    -0x1.fffffffffffffffffffffffff11845e1p-1,
+    0x1.5fdbbe9bba775p4,
+  },
+  { // Entry 804
+    -0x1.ee2c2d963a10c0993703e20442ad7b8dp-51,
+    -0x1.fffffffffffffffffffffffff11845e1p-1,
+    -0x1.5fdbbe9bba775p4,
+  },
+  { // Entry 805
+    -0x1.8474f49a717bcfd9b23f077ec8dd175bp-49,
+    -0x1.ffffffffffffffffffffffff6ca35147p-1,
+    0x1.5fdbbe9bba776p4,
+  },
+  { // Entry 806
+    0x1.8474f49a717bcfd9b23f077ec8dd175bp-49,
+    -0x1.ffffffffffffffffffffffff6ca35147p-1,
+    -0x1.5fdbbe9bba776p4,
+  },
+  { // Entry 807
+    -0x1.6a09e667f3b9f4fcf9145bf3ef39f901p-1,
+    -0x1.6a09e667f3bf9d146ce1cad43de9b352p-1,
+    0x1.6c6cbc45dc8dcp4,
+  },
+  { // Entry 808
+    0x1.6a09e667f3b9f4fcf9145bf3ef39f901p-1,
+    -0x1.6a09e667f3bf9d146ce1cad43de9b352p-1,
+    -0x1.6c6cbc45dc8dcp4,
+  },
+  { // Entry 809
+    -0x1.6a09e667f3bb5f06df7c4fb2d74972aep-1,
+    -0x1.6a09e667f3be330a8679d71993e7c709p-1,
+    0x1.6c6cbc45dc8ddp4,
+  },
+  { // Entry 810
+    0x1.6a09e667f3bb5f06df7c4fb2d74972aep-1,
+    -0x1.6a09e667f3be330a8679d71993e7c709p-1,
+    -0x1.6c6cbc45dc8ddp4,
+  },
+  { // Entry 811
+    -0x1.6a09e667f3bcc910c5e44370554f05f4p-1,
+    -0x1.6a09e667f3bcc900a011e35d7fdbf459p-1,
+    0x1.6c6cbc45dc8dep4,
+  },
+  { // Entry 812
+    0x1.6a09e667f3bcc910c5e44370554f05f4p-1,
+    -0x1.6a09e667f3bcc900a011e35d7fdbf459p-1,
+    -0x1.6c6cbc45dc8dep4,
+  },
+  { // Entry 813
+    -0x1.fffffffffffffffffffffffce85685bdp-1,
+    -0x1.c22f0f3f8c5919cb6082ce443cf95022p-48,
+    0x1.78fdb9effea45p4,
+  },
+  { // Entry 814
+    0x1.fffffffffffffffffffffffce85685bdp-1,
+    -0x1.c22f0f3f8c5919cb6082ce443cf95022p-48,
+    -0x1.78fdb9effea45p4,
+  },
+  { // Entry 815
+    -0x1.ffffffffffffffffffffffff6cb4a43dp-1,
+    -0x1.845e1e7f18b23396c1059c8a24c2609cp-49,
+    0x1.78fdb9effea46p4,
+  },
+  { // Entry 816
+    0x1.ffffffffffffffffffffffff6cb4a43dp-1,
+    -0x1.845e1e7f18b23396c1059c8a24c2609cp-49,
+    -0x1.78fdb9effea46p4,
+  },
+  { // Entry 817
+    -0x1.fffffffffffffffffffffffff112c2bcp-1,
+    0x1.ee8786039d3731a4fbe98dd6d32ff62ap-51,
+    0x1.78fdb9effea47p4,
+  },
+  { // Entry 818
+    0x1.fffffffffffffffffffffffff112c2bcp-1,
+    0x1.ee8786039d3731a4fbe98dd6d32ff62ap-51,
+    -0x1.78fdb9effea47p4,
+  },
+  { // Entry 819
+    -0x1.6a09e667f3beee4ce1dd51dac23c6bdcp-1,
+    0x1.6a09e667f3baa3c48418d4efd19d074ap-1,
+    0x1.858eb79a20baep4,
+  },
+  { // Entry 820
+    0x1.6a09e667f3beee4ce1dd51dac23c6bdcp-1,
+    0x1.6a09e667f3baa3c48418d4efd19d074ap-1,
+    -0x1.858eb79a20baep4,
+  },
+  { // Entry 821
+    -0x1.6a09e667f3bd8442fb755e1f6972f48fp-1,
+    0x1.6a09e667f3bc0dce6a80c8ae0ae4f5f3p-1,
+    0x1.858eb79a20bafp4,
+  },
+  { // Entry 822
+    0x1.6a09e667f3bd8442fb755e1f6972f48fp-1,
+    0x1.6a09e667f3bc0dce6a80c8ae0ae4f5f3p-1,
+    -0x1.858eb79a20bafp4,
+  },
+  { // Entry 823
+    -0x1.6a09e667f3bc1a39150d6a62a69f96dap-1,
+    0x1.6a09e667f3bd77d850e8bc6ada22fe34p-1,
+    0x1.858eb79a20bb0p4,
+  },
+  { // Entry 824
+    0x1.6a09e667f3bc1a39150d6a62a69f96dap-1,
+    0x1.6a09e667f3bd77d850e8bc6ada22fe34p-1,
+    -0x1.858eb79a20bb0p4,
+  },
+  { // Entry 825
+    0x1.fa7299b17573d373c615096572a0de04p-1,
+    -0x1.2ccaf641d4261ea3ccd8d2a102dc3066p-3,
+    0x1.fffffffffffffp62,
+  },
+  { // Entry 826
+    -0x1.fa7299b17573d373c615096572a0de04p-1,
+    -0x1.2ccaf641d4261ea3ccd8d2a102dc3066p-3,
+    -0x1.fffffffffffffp62,
+  },
+  { // Entry 827
+    0x1.fff6dfd42dc54430bc0576b00a88bd94p-1,
+    0x1.82aa375b3c33e70663731bab4beb6ed3p-7,
+    0x1.0p63,
+  },
+  { // Entry 828
+    -0x1.fff6dfd42dc54430bc0576b00a88bd94p-1,
+    0x1.82aa375b3c33e70663731bab4beb6ed3p-7,
+    -0x1.0p63,
+  },
+  { // Entry 829
+    0x1.e456b818e7396b45989978d4b7ebf7b3p-1,
+    0x1.4c0622a6e35ddefd5f2b7700716a581fp-2,
+    0x1.0000000000001p63,
+  },
+  { // Entry 830
+    -0x1.e456b818e7396b45989978d4b7ebf7b3p-1,
+    0x1.4c0622a6e35ddefd5f2b7700716a581fp-2,
+    -0x1.0000000000001p63,
+  },
+  { // Entry 831
+    -0x1.86dcca0d689e7b56ef79481be4a645c6p-1,
+    0x1.4ab650b8c60734385375e22603fcdb10p-1,
+    0x1.fffffffffffffp26,
+  },
+  { // Entry 832
+    0x1.86dcca0d689e7b56ef79481be4a645c6p-1,
+    0x1.4ab650b8c60734385375e22603fcdb10p-1,
+    -0x1.fffffffffffffp26,
+  },
+  { // Entry 833
+    -0x1.86dcc9babb0a40ee875cab3b9e892757p-1,
+    0x1.4ab6511a7d39ad3cc88ded1e775ca147p-1,
+    0x1.0p27,
+  },
+  { // Entry 834
+    0x1.86dcc9babb0a40ee875cab3b9e892757p-1,
+    0x1.4ab6511a7d39ad3cc88ded1e775ca147p-1,
+    -0x1.0p27,
+  },
+  { // Entry 835
+    -0x1.86dcc9155fe182d4515599426bb14b94p-1,
+    0x1.4ab651ddeb9e61438382f02167ade4afp-1,
+    0x1.0000000000001p27,
+  },
+  { // Entry 836
+    0x1.86dcc9155fe182d4515599426bb14b94p-1,
+    0x1.4ab651ddeb9e61438382f02167ade4afp-1,
+    -0x1.0000000000001p27,
+  },
+  { // Entry 837
+    -0x1.8f22f84d42da1f57469dfaac44a8b73ap-1,
+    0x1.40ad67e777b1df0195189f50a8c26345p-1,
+    0x1.fffffffffffffp23,
+  },
+  { // Entry 838
+    0x1.8f22f84d42da1f57469dfaac44a8b73ap-1,
+    0x1.40ad67e777b1df0195189f50a8c26345p-1,
+    -0x1.fffffffffffffp23,
+  },
+  { // Entry 839
+    -0x1.8f22f8433d6edfe9a4aff9622517caa9p-1,
+    0x1.40ad67f3f0c9a143963c9c96dbce3f8ap-1,
+    0x1.0p24,
+  },
+  { // Entry 840
+    0x1.8f22f8433d6edfe9a4aff9622517caa9p-1,
+    0x1.40ad67f3f0c9a143963c9c96dbce3f8ap-1,
+    -0x1.0p24,
+  },
+  { // Entry 841
+    -0x1.8f22f82f32985fe30699c6e12d9dfce2p-1,
+    0x1.40ad680ce2f924d716769d1064bc8defp-1,
+    0x1.0000000000001p24,
+  },
+  { // Entry 842
+    0x1.8f22f82f32985fe30699c6e12d9dfce2p-1,
+    0x1.40ad680ce2f924d716769d1064bc8defp-1,
+    -0x1.0000000000001p24,
+  },
+  { // Entry 843
+    -0x1.837b9dddc1eabd379d729f575fc1144cp-1,
+    -0x1.4eaa606db24c3cb5e15d7b19d5ee73a1p-1,
+    0x1.fffffffffffffp1,
+  },
+  { // Entry 844
+    0x1.837b9dddc1eabd379d729f575fc1144cp-1,
+    -0x1.4eaa606db24c3cb5e15d7b19d5ee73a1p-1,
+    -0x1.fffffffffffffp1,
+  },
+  { // Entry 845
+    -0x1.837b9dddc1eae70ce98055a0e450d93cp-1,
+    -0x1.4eaa606db24c0c466da1c2dc7baa2b32p-1,
+    0x1.0p2,
+  },
+  { // Entry 846
+    0x1.837b9dddc1eae70ce98055a0e450d93cp-1,
+    -0x1.4eaa606db24c0c466da1c2dc7baa2b32p-1,
+    -0x1.0p2,
+  },
+  { // Entry 847
+    -0x1.837b9dddc1eb3ab7819bc233db4697b5p-1,
+    -0x1.4eaa606db24bab67862a5261b7719dcfp-1,
+    0x1.0000000000001p2,
+  },
+  { // Entry 848
+    0x1.837b9dddc1eb3ab7819bc233db4697b5p-1,
+    -0x1.4eaa606db24bab67862a5261b7719dcfp-1,
+    -0x1.0000000000001p2,
+  },
+  { // Entry 849
+    0x1.d18f6ead1b446b4bcb73c2390b330d75p-1,
+    -0x1.aa2265753720101145230952e61c6f2cp-2,
+    0x1.fffffffffffffp0,
+  },
+  { // Entry 850
+    -0x1.d18f6ead1b446b4bcb73c2390b330d75p-1,
+    -0x1.aa2265753720101145230952e61c6f2cp-2,
+    -0x1.fffffffffffffp0,
+  },
+  { // Entry 851
+    0x1.d18f6ead1b445dfab848188009c9bb95p-1,
+    -0x1.aa22657537204a4332f8acbb72b0d768p-2,
+    0x1.0p1,
+  },
+  { // Entry 852
+    -0x1.d18f6ead1b445dfab848188009c9bb95p-1,
+    -0x1.aa22657537204a4332f8acbb72b0d768p-2,
+    -0x1.0p1,
+  },
+  { // Entry 853
+    0x1.d18f6ead1b44435891f0c50e01826988p-1,
+    -0x1.aa2265753720bea70ea3f38c86db40afp-2,
+    0x1.0000000000001p1,
+  },
+  { // Entry 854
+    -0x1.d18f6ead1b44435891f0c50e01826988p-1,
+    -0x1.aa2265753720bea70ea3f38c86db40afp-2,
+    -0x1.0000000000001p1,
+  },
+  { // Entry 855
+    0x1.aed548f090ced79c79cbf790441f8197p-1,
+    0x1.14a280fb5068c69a2ed45fb547c2f271p-1,
+    0x1.fffffffffffffp-1,
+  },
+  { // Entry 856
+    -0x1.aed548f090ced79c79cbf790441f8197p-1,
+    0x1.14a280fb5068c69a2ed45fb547c2f271p-1,
+    -0x1.fffffffffffffp-1,
+  },
+  { // Entry 857
+    0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    0x1.0p0,
+  },
+  { // Entry 858
+    -0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    -0x1.0p0,
+  },
+  { // Entry 859
+    0x1.aed548f090cef18bb5e3871a14d94609p-1,
+    0x1.14a280fb50689e362ffdd221e2551035p-1,
+    0x1.0000000000001p0,
+  },
+  { // Entry 860
+    -0x1.aed548f090cef18bb5e3871a14d94609p-1,
+    0x1.14a280fb50689e362ffdd221e2551035p-1,
+    -0x1.0000000000001p0,
+  },
+  { // Entry 861
+    0x1.eaee8744b05ef07cd0b9089130598314p-2,
+    0x1.c1528065b7d4fdb158c9c4a6b3e4b740p-1,
+    0x1.fffffffffffffp-2,
+  },
+  { // Entry 862
+    -0x1.eaee8744b05ef07cd0b9089130598314p-2,
+    0x1.c1528065b7d4fdb158c9c4a6b3e4b740p-1,
+    -0x1.fffffffffffffp-2,
+  },
+  { // Entry 863
+    0x1.eaee8744b05efe8764bc364fd837b666p-2,
+    0x1.c1528065b7d4f9db7bbb3b45f5f5b30ap-1,
+    0x1.0p-1,
+  },
+  { // Entry 864
+    -0x1.eaee8744b05efe8764bc364fd837b666p-2,
+    0x1.c1528065b7d4f9db7bbb3b45f5f5b30ap-1,
+    -0x1.0p-1,
+  },
+  { // Entry 865
+    0x1.eaee8744b05f1a9c8cc291cd27981051p-2,
+    0x1.c1528065b7d4f22fc19e288479c36b27p-1,
+    0x1.0000000000001p-1,
+  },
+  { // Entry 866
+    -0x1.eaee8744b05f1a9c8cc291cd27981051p-2,
+    0x1.c1528065b7d4f22fc19e288479c36b27p-1,
+    -0x1.0000000000001p-1,
+  },
+  { // Entry 867
+    0x1.faaeed4f31575c27f39c1d7c012a4413p-3,
+    0x1.f01549f7deea184c5f1d210b6adbe56cp-1,
+    0x1.fffffffffffffp-3,
+  },
+  { // Entry 868
+    -0x1.faaeed4f31575c27f39c1d7c012a4413p-3,
+    0x1.f01549f7deea184c5f1d210b6adbe56cp-1,
+    -0x1.fffffffffffffp-3,
+  },
+  { // Entry 869
+    0x1.faaeed4f31576ba89debdc7351e8b1aep-3,
+    0x1.f01549f7deea174f07a67972bf29f148p-1,
+    0x1.0p-2,
+  },
+  { // Entry 870
+    -0x1.faaeed4f31576ba89debdc7351e8b1aep-3,
+    0x1.f01549f7deea174f07a67972bf29f148p-1,
+    -0x1.0p-2,
+  },
+  { // Entry 871
+    0x1.faaeed4f31578aa9f28b5a61f34dccb1p-3,
+    0x1.f01549f7deea155458b92a4167aec7ffp-1,
+    0x1.0000000000001p-2,
+  },
+  { // Entry 872
+    -0x1.faaeed4f31578aa9f28b5a61f34dccb1p-3,
+    0x1.f01549f7deea155458b92a4167aec7ffp-1,
+    -0x1.0000000000001p-2,
+  },
+  { // Entry 873
+    0x1.feaaeee86ee34cc05eff28740ee7b469p-4,
+    0x1.fc015527d5bd371a12320249ca4dafd7p-1,
+    0x1.fffffffffffffp-4,
+  },
+  { // Entry 874
+    -0x1.feaaeee86ee34cc05eff28740ee7b469p-4,
+    0x1.fc015527d5bd371a12320249ca4dafd7p-1,
+    -0x1.fffffffffffffp-4,
+  },
+  { // Entry 875
+    0x1.feaaeee86ee35ca069a86721f89f85a5p-4,
+    0x1.fc015527d5bd36da3cd4253bede319cap-1,
+    0x1.0p-3,
+  },
+  { // Entry 876
+    -0x1.feaaeee86ee35ca069a86721f89f85a5p-4,
+    0x1.fc015527d5bd36da3cd4253bede319cap-1,
+    -0x1.0p-3,
+  },
+  { // Entry 877
+    0x1.feaaeee86ee37c607efae47dcc092c1cp-4,
+    0x1.fc015527d5bd365a92186b203507f9adp-1,
+    0x1.0000000000001p-3,
+  },
+  { // Entry 878
+    -0x1.feaaeee86ee37c607efae47dcc092c1cp-4,
+    0x1.fc015527d5bd365a92186b203507f9adp-1,
+    -0x1.0000000000001p-3,
+  },
+  { // Entry 879
+    0x1.ffaaaeeed4ed9b53a408c0f2bc02c8f9p-5,
+    0x1.ff0015549f4d34da0b745dc7433145efp-1,
+    0x1.fffffffffffffp-5,
+  },
+  { // Entry 880
+    -0x1.ffaaaeeed4ed9b53a408c0f2bc02c8f9p-5,
+    0x1.ff0015549f4d34da0b745dc7433145efp-1,
+    -0x1.fffffffffffffp-5,
+  },
+  { // Entry 881
+    0x1.ffaaaeeed4edab4ba4b365ed25a9595fp-5,
+    0x1.ff0015549f4d34ca0e1ee6509bc42b71p-1,
+    0x1.0p-4,
+  },
+  { // Entry 882
+    -0x1.ffaaaeeed4edab4ba4b365ed25a9595fp-5,
+    0x1.ff0015549f4d34ca0e1ee6509bc42b71p-1,
+    -0x1.0p-4,
+  },
+  { // Entry 883
+    0x1.ffaaaeeed4edcb3ba608afe1f8f4fa6bp-5,
+    0x1.ff0015549f4d34aa1373f7634ce87737p-1,
+    0x1.0000000000001p-4,
+  },
+  { // Entry 884
+    -0x1.ffaaaeeed4edcb3ba608afe1f8f4fa6bp-5,
+    0x1.ff0015549f4d34aa1373f7634ce87737p-1,
+    -0x1.0000000000001p-4,
+  },
+  { // Entry 885
+    0x1.ffeaaaeeee86d8ccfe368cd95e38f003p-6,
+    0x1.ffc00155527d2b16aeb09fb70636a10ap-1,
+    0x1.fffffffffffffp-6,
+  },
+  { // Entry 886
+    -0x1.ffeaaaeeee86d8ccfe368cd95e38f003p-6,
+    0x1.ffc00155527d2b16aeb09fb70636a10ap-1,
+    -0x1.fffffffffffffp-6,
+  },
+  { // Entry 887
+    0x1.ffeaaaeeee86e8cafe41376d47919579p-6,
+    0x1.ffc00155527d2b12aedb49d92928df72p-1,
+    0x1.0p-5,
+  },
+  { // Entry 888
+    -0x1.ffeaaaeeee86e8cafe41376d47919579p-6,
+    0x1.ffc00155527d2b12aedb49d92928df72p-1,
+    -0x1.0p-5,
+  },
+  { // Entry 889
+    0x1.ffeaaaeeee8708c6fe568c951a428069p-6,
+    0x1.ffc00155527d2b0aaf309e1d6f0cfc4ep-1,
+    0x1.0000000000001p-5,
+  },
+  { // Entry 890
+    -0x1.ffeaaaeeee8708c6fe568c951a428069p-6,
+    0x1.ffc00155527d2b0aaf309e1d6f0cfc4ep-1,
+    -0x1.0000000000001p-5,
+  },
+  { // Entry 891
+    0x1.fffaaaaeeeed3ed5c9c5ab6538f9cce0p-7,
+    0x1.fff000155549f4a38a2563ef344c3ff4p-1,
+    0x1.fffffffffffffp-7,
+  },
+  { // Entry 892
+    -0x1.fffaaaaeeeed3ed5c9c5ab6538f9cce0p-7,
+    0x1.fff000155549f4a38a2563ef344c3ff4p-1,
+    -0x1.fffffffffffffp-7,
+  },
+  { // Entry 893
+    0x1.fffaaaaeeeed4ed549c6560f889ee531p-7,
+    0x1.fff000155549f4a28a280e97bcd59c8ap-1,
+    0x1.0p-6,
+  },
+  { // Entry 894
+    -0x1.fffaaaaeeeed4ed549c6560f889ee531p-7,
+    0x1.fff000155549f4a28a280e97bcd59c8ap-1,
+    -0x1.0p-6,
+  },
+  { // Entry 895
+    0x1.fffaaaaeeeed6ed449c7ab6427e8fdd4p-7,
+    0x1.fff000155549f4a08a2d63e8cde83db5p-1,
+    0x1.0000000000001p-6,
+  },
+  { // Entry 896
+    -0x1.fffaaaaeeeed6ed449c7ab6427e8fdd4p-7,
+    0x1.fff000155549f4a08a2d63e8cde83db5p-1,
+    -0x1.0000000000001p-6,
+  },
+  { // Entry 897
+    0x1.fffffffaaaaa9aaeeeef6eed4ed442a4p-15,
+    0x1.fffffff00000001555565549f49c9f4dp-1,
+    0x1.fffffffffffffp-15,
+  },
+  { // Entry 898
+    -0x1.fffffffaaaaa9aaeeeef6eed4ed442a4p-15,
+    0x1.fffffff00000001555565549f49c9f4dp-1,
+    -0x1.fffffffffffffp-15,
+  },
+  { // Entry 899
+    0x1.fffffffaaaaaaaaeeeeeeeed4ed4ed4fp-15,
+    0x1.fffffff00000001555555549f49f49f7p-1,
+    0x1.0p-14,
+  },
+  { // Entry 900
+    -0x1.fffffffaaaaaaaaeeeeeeeed4ed4ed4fp-15,
+    0x1.fffffff00000001555555549f49f49f7p-1,
+    -0x1.0p-14,
+  },
+  { // Entry 901
+    0x1.fffffffaaaaacaaeeeedeeed4ed642a4p-15,
+    0x1.fffffff00000001555535549f4a49f4dp-1,
+    0x1.0000000000001p-14,
+  },
+  { // Entry 902
+    -0x1.fffffffaaaaacaaeeeedeeed4ed642a4p-15,
+    0x1.fffffff00000001555535549f4a49f4dp-1,
+    -0x1.0000000000001p-14,
+  },
+  { // Entry 903
+    0x1.ffffffffffffeeaaaaaaaaaaaacaeeeep-28,
+    0x1.fffffffffffffc000000000000415555p-1,
+    0x1.fffffffffffffp-28,
+  },
+  { // Entry 904
+    -0x1.ffffffffffffeeaaaaaaaaaaaacaeeeep-28,
+    0x1.fffffffffffffc000000000000415555p-1,
+    -0x1.fffffffffffffp-28,
+  },
+  { // Entry 905
+    0x1.fffffffffffffeaaaaaaaaaaaaaaeeeep-28,
+    0x1.fffffffffffffc000000000000015555p-1,
+    0x1.0p-27,
+  },
+  { // Entry 906
+    -0x1.fffffffffffffeaaaaaaaaaaaaaaeeeep-28,
+    0x1.fffffffffffffc000000000000015555p-1,
+    -0x1.0p-27,
+  },
+  { // Entry 907
+    0x1.0000000000000f555555555555357777p-27,
+    0x1.fffffffffffffbffffffffffff815555p-1,
+    0x1.0000000000001p-27,
+  },
+  { // Entry 908
+    -0x1.0000000000000f555555555555357777p-27,
+    0x1.fffffffffffffbffffffffffff815555p-1,
+    -0x1.0000000000001p-27,
+  },
+  { // Entry 909
+    0x1.ffffffffffffeffaaaaaaaaaaaab2aaep-31,
+    0x1.fffffffffffffff00000000000010015p-1,
+    0x1.fffffffffffffp-31,
+  },
+  { // Entry 910
+    -0x1.ffffffffffffeffaaaaaaaaaaaab2aaep-31,
+    0x1.fffffffffffffff00000000000010015p-1,
+    -0x1.fffffffffffffp-31,
+  },
+  { // Entry 911
+    0x1.fffffffffffffffaaaaaaaaaaaaaaaaep-31,
+    0x1.fffffffffffffff00000000000000015p-1,
+    0x1.0p-30,
+  },
+  { // Entry 912
+    -0x1.fffffffffffffffaaaaaaaaaaaaaaaaep-31,
+    0x1.fffffffffffffff00000000000000015p-1,
+    -0x1.0p-30,
+  },
+  { // Entry 913
+    0x1.0000000000000ffd555555555554d557p-30,
+    0x1.ffffffffffffffeffffffffffffe0015p-1,
+    0x1.0000000000001p-30,
+  },
+  { // Entry 914
+    -0x1.0000000000000ffd555555555554d557p-30,
+    0x1.ffffffffffffffeffffffffffffe0015p-1,
+    -0x1.0000000000001p-30,
+  },
+  { // Entry 915
+    -0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    -0x1.fffffffffffffp1023,
+  },
+  { // Entry 916
+    0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    0x1.fffffffffffffp1023,
+  },
+  { // Entry 917
+    0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    0x1.fffffffffffffp1023,
+  },
+  { // Entry 918
+    -0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    -0x1.fffffffffffffp1023,
+  },
+  { // Entry 919
+    0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    0x1.fffffffffffffp1023,
+  },
+  { // Entry 920
+    -0x1.452fc98b34e96b61139b09a7c84a44bdp-8,
+    -0x1.fffe62ecfab753c071b2680e1e26bbcep-1,
+    -0x1.fffffffffffffp1023,
+  },
+  { // Entry 921
+    0x1.daa3677c6ee8a22eb6c4b12ca10ce021p-1,
+    0x1.7ffdfb4c5308f777cf774c733b256695p-2,
+    0x1.ffffffffffffep1023,
+  },
+  { // Entry 922
+    -0x1.daa3677c6ee8a22eb6c4b12ca10ce021p-1,
+    0x1.7ffdfb4c5308f777cf774c733b256695p-2,
+    -0x1.ffffffffffffep1023,
+  },
+  { // Entry 923
+    0x1.1a62633145c06e0e689481270436e2edp-53,
+    -0x1.ffffffffffffffffffffffffffb220c5p-1,
+    0x1.921fb54442d18p1,
+  },
+  { // Entry 924
+    -0x1.1a62633145c06e0e689481270436e2edp-53,
+    -0x1.ffffffffffffffffffffffffffb220c5p-1,
+    -0x1.921fb54442d18p1,
+  },
+  { // Entry 925
+    0x1.ffffffffffffffffffffffffffec8831p-1,
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    0x1.921fb54442d18p0,
+  },
+  { // Entry 926
+    -0x1.ffffffffffffffffffffffffffec8831p-1,
+    0x1.1a62633145c06e0e6894812704419fa8p-54,
+    -0x1.921fb54442d18p0,
+  },
+  { // Entry 927
+    0x1.aed548f090cef18bb5e3871a14d94609p-1,
+    0x1.14a280fb50689e362ffdd221e2551035p-1,
+    0x1.0000000000001p0,
+  },
+  { // Entry 928
+    -0x1.aed548f090cef18bb5e3871a14d94609p-1,
+    0x1.14a280fb50689e362ffdd221e2551035p-1,
+    -0x1.0000000000001p0,
+  },
+  { // Entry 929
+    0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    0x1.0p0,
+  },
+  { // Entry 930
+    -0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    -0x1.0p0,
+  },
+  { // Entry 931
+    0x1.aed548f090ced79c79cbf790441f8197p-1,
+    0x1.14a280fb5068c69a2ed45fb547c2f271p-1,
+    0x1.fffffffffffffp-1,
+  },
+  { // Entry 932
+    -0x1.aed548f090ced79c79cbf790441f8197p-1,
+    0x1.14a280fb5068c69a2ed45fb547c2f271p-1,
+    -0x1.fffffffffffffp-1,
+  },
+  { // Entry 933
+    0x1.6a09e667f3bcc5e9fee352f50fd3f4e9p-1,
+    0x1.6a09e667f3bccc276712d3d8c5502387p-1,
+    0x1.921fb54442d18p-1,
+  },
+  { // Entry 934
+    -0x1.6a09e667f3bcc5e9fee352f50fd3f4e9p-1,
+    0x1.6a09e667f3bccc276712d3d8c5502387p-1,
+    -0x1.921fb54442d18p-1,
+  },
+  { // Entry 935
+    0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0000000000001p-1022,
+  },
+  { // Entry 936
+    -0x1.0000000000000fffffffffffffffffffp-1022,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0000000000001p-1022,
+  },
+  { // Entry 937
+    0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1022,
+  },
+  { // Entry 938
+    -0x1.ffffffffffffffffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1022,
+  },
+  { // Entry 939
+    0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.ffffffffffffep-1023,
+  },
+  { // Entry 940
+    -0x1.ffffffffffffdfffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffep-1023,
+  },
+  { // Entry 941
+    0x1.ffffffffffffbfffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.ffffffffffffcp-1023,
+  },
+  { // Entry 942
+    -0x1.ffffffffffffbfffffffffffffffffffp-1023,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.ffffffffffffcp-1023,
+  },
+  { // Entry 943
+    0x1.ffffffffffffffffffffffffffffffffp-1074,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1073,
+  },
+  { // Entry 944
+    -0x1.ffffffffffffffffffffffffffffffffp-1074,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1073,
+  },
+  { // Entry 945
+    0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.0p-1074,
+  },
+  { // Entry 946
+    -0.0,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.0p-1074,
+  },
+  { // Entry 947
+    0.0,
+    0x1.p0,
+    0.0,
+  },
+  { // Entry 948
+    -0.0,
+    0x1.p0,
+    -0.0,
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_sincos, sincos_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_sincos_intel_data)/sizeof(sincos_intel_data_t); i++) {
+   double dsin, dcos;
+   sincos(g_sincos_intel_data[i].call_data, &dsin, &dcos);
+   EXPECT_DOUBLE_EQ(g_sincos_intel_data[i].sin_expected, dsin) << "Failed on element " << i;
+   EXPECT_DOUBLE_EQ(g_sincos_intel_data[i].cos_expected, dcos) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_sincosf_test.cpp b/tests/math_sincosf_test.cpp
new file mode 100644
index 0000000..c1a32c9
--- /dev/null
+++ b/tests/math_sincosf_test.cpp
@@ -0,0 +1,4658 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  float sin_expected;
+  float cos_expected;
+  float call_data;
+} sincosf_intel_data_t;
+
+static sincosf_intel_data_t g_sincosf_intel_data[] = {
+  { // Entry 0
+    -0x1.b6a7abffaf59a5ac181e3e1abf961698p-1,
+    0x1.080e74c116863cfab82a0fd59c71b363p-1,
+    -0x1.0768p0,
+  },
+  { // Entry 1
+    0x1.b6a7abffaf59a5ac181e3e1abf961698p-1,
+    0x1.080e74c116863cfab82a0fd59c71b363p-1,
+    0x1.0768p0,
+  },
+  { // Entry 2
+    0x1.762da6648fde00e398462e7163094d52p-2,
+    0x1.dc9802ffffffe0cbfc57ef287d3c83afp-1,
+    -0x1.8f219cp5,
+  },
+  { // Entry 3
+    -0x1.762da6648fde00e398462e7163094d52p-2,
+    0x1.dc9802ffffffe0cbfc57ef287d3c83afp-1,
+    0x1.8f219cp5,
+  },
+  { // Entry 4
+    -0x1.493b6a7d3f5b7bf66fa32a01515d6c43p-1,
+    -0x1.881c26fd25d0bf6d6ea38708a0976b35p-1,
+    -0x1.d3a51ap80,
+  },
+  { // Entry 5
+    0x1.493b6a7d3f5b7bf66fa32a01515d6c43p-1,
+    -0x1.881c26fd25d0bf6d6ea38708a0976b35p-1,
+    0x1.d3a51ap80,
+  },
+  { // Entry 6
+    -0x1.e0d1dc006e85835b0394abe97de77fbcp-4,
+    0x1.fc75ca6313ef766012db3ca99a1a52d1p-1,
+    -0x1.e1ee52p-4,
+  },
+  { // Entry 7
+    0x1.e0d1dc006e85835b0394abe97de77fbcp-4,
+    0x1.fc75ca6313ef766012db3ca99a1a52d1p-1,
+    0x1.e1ee52p-4,
+  },
+  { // Entry 8
+    -0x1.2b6a9ca3df622efe2aa3154a6352bc70p-1,
+    -0x1.9f52def55d89e92e7df20ec21161deb8p-1,
+    -0x1.f3ffe2p24,
+  },
+  { // Entry 9
+    0x1.2b6a9ca3df622efe2aa3154a6352bc70p-1,
+    -0x1.9f52def55d89e92e7df20ec21161deb8p-1,
+    0x1.f3ffe2p24,
+  },
+  { // Entry 10
+    0x1.a3422af13b2cfb78d0cc458d9ac6bde9p-1,
+    -0x1.25e1aa1d9383c1f27027cf69b69477fdp-1,
+    -0x1.ff211ep24,
+  },
+  { // Entry 11
+    -0x1.a3422af13b2cfb78d0cc458d9ac6bde9p-1,
+    -0x1.25e1aa1d9383c1f27027cf69b69477fdp-1,
+    0x1.ff211ep24,
+  },
+  { // Entry 12
+    0x1.ffffffaaaaaaaeeeeeeed4ed4ed549c6p-13,
+    0x1.ffffff000000155555549f49f4a28a28p-1,
+    0x1.p-12,
+  },
+  { // Entry 13
+    -0x1.ffffffaaaaaaaeeeeeeed4ed4ed549c6p-13,
+    0x1.ffffff000000155555549f49f4a28a28p-1,
+    -0x1.p-12,
+  },
+  { // Entry 14
+    0x1.000001d555545777758cbfcafc09ef7ep-12,
+    0x1.fffffefffffc155551ff49f696c4aecap-1,
+    0x1.000002p-12,
+  },
+  { // Entry 15
+    -0x1.000001d555545777758cbfcafc09ef7ep-12,
+    0x1.fffffefffffc155551ff49f696c4aecap-1,
+    -0x1.000002p-12,
+  },
+  { // Entry 16
+    0x1.000001ffffffffffd555545555535555p-32,
+    0x1.fffffffffffffffefffffbfffffcp-1,
+    0x1.000002p-32,
+  },
+  { // Entry 17
+    -0x1.000001ffffffffffd555545555535555p-32,
+    0x1.fffffffffffffffefffffbfffffcp-1,
+    -0x1.000002p-32,
+  },
+  { // Entry 18
+    0x1.eaf0d5008f2db899e2487da9d3b9cde7p-2,
+    0x1.c151df4f12b197a665a2907e4933a1efp-1,
+    0x1.000150p-1,
+  },
+  { // Entry 19
+    -0x1.eaf0d5008f2db899e2487da9d3b9cde7p-2,
+    0x1.c151df4f12b197a665a2907e4933a1efp-1,
+    -0x1.000150p-1,
+  },
+  { // Entry 20
+    0x1.eaf77efff659021bc827bbd5696ad19ep-2,
+    0x1.c1500d494ed2cc5002c27cc5ca3d96f8p-1,
+    0x1.00051cp-1,
+  },
+  { // Entry 21
+    -0x1.eaf77efff659021bc827bbd5696ad19ep-2,
+    0x1.c1500d494ed2cc5002c27cc5ca3d96f8p-1,
+    -0x1.00051cp-1,
+  },
+  { // Entry 22
+    -0x1.5aa53c1c1317f30b4c108722e2b64612p-1,
+    0x1.78cdb6ffa6bff899e1723ed0139c48cbp-1,
+    0x1.000fdep80,
+  },
+  { // Entry 23
+    0x1.5aa53c1c1317f30b4c108722e2b64612p-1,
+    0x1.78cdb6ffa6bff899e1723ed0139c48cbp-1,
+    -0x1.000fdep80,
+  },
+  { // Entry 24
+    0x1.aef38822e64311445545980fbc5b56fap-1,
+    0x1.14735fffd55120a4480b7c91a1d78d6ep-1,
+    0x1.001cp0,
+  },
+  { // Entry 25
+    -0x1.aef38822e64311445545980fbc5b56fap-1,
+    0x1.14735fffd55120a4480b7c91a1d78d6ep-1,
+    -0x1.001cp0,
+  },
+  { // Entry 26
+    -0x1.7e12aee0c862b1709bd50205bba32167p-1,
+    -0x1.54d4290010a68826a882e7c87d6694d2p-1,
+    0x1.0027b8p40,
+  },
+  { // Entry 27
+    0x1.7e12aee0c862b1709bd50205bba32167p-1,
+    -0x1.54d4290010a68826a882e7c87d6694d2p-1,
+    -0x1.0027b8p40,
+  },
+  { // Entry 28
+    -0x1.bd6944ef4dd1b43962e2d3480410fd87p-1,
+    0x1.f8fc8efff67d834f6878ab4e44fa89b5p-2,
+    0x1.004840p68,
+  },
+  { // Entry 29
+    0x1.bd6944ef4dd1b43962e2d3480410fd87p-1,
+    0x1.f8fc8efff67d834f6878ab4e44fa89b5p-2,
+    -0x1.004840p68,
+  },
+  { // Entry 30
+    0x1.f4e23e00165a4907a656a7cf532bbde4p-2,
+    0x1.be91601e47bed6d45e8372687b373c0cp-1,
+    0x1.05b0p-1,
+  },
+  { // Entry 31
+    -0x1.f4e23e00165a4907a656a7cf532bbde4p-2,
+    0x1.be91601e47bed6d45e8372687b373c0cp-1,
+    -0x1.05b0p-1,
+  },
+  { // Entry 32
+    0x1.b6a7abffaf59a5ac181e3e1abf961698p-1,
+    0x1.080e74c116863cfab82a0fd59c71b363p-1,
+    0x1.0768p0,
+  },
+  { // Entry 33
+    -0x1.b6a7abffaf59a5ac181e3e1abf961698p-1,
+    0x1.080e74c116863cfab82a0fd59c71b363p-1,
+    -0x1.0768p0,
+  },
+  { // Entry 34
+    0x1.bcb8aafffffd69d2865aaf3f4c5074e8p-1,
+    0x1.fb69a6dc513bcba59d5dc68d3d59a05cp-2,
+    0x1.0d67a4p0,
+  },
+  { // Entry 35
+    -0x1.bcb8aafffffd69d2865aaf3f4c5074e8p-1,
+    0x1.fb69a6dc513bcba59d5dc68d3d59a05cp-2,
+    -0x1.0d67a4p0,
+  },
+  { // Entry 36
+    0x1.bf683cffffec6e8672a49f08aae49c46p-1,
+    0x1.f1e0f653d695977ccd240ff6b9297393p-2,
+    0x1.1024p0,
+  },
+  { // Entry 37
+    -0x1.bf683cffffec6e8672a49f08aae49c46p-1,
+    0x1.f1e0f653d695977ccd240ff6b9297393p-2,
+    -0x1.1024p0,
+  },
+  { // Entry 38
+    0x1.8b1e8e1c16a8d970a78a2391eea6575cp-1,
+    -0x1.459d4500000092b4b8307c652ee639a7p-1,
+    0x1.21497ep1,
+  },
+  { // Entry 39
+    -0x1.8b1e8e1c16a8d970a78a2391eea6575cp-1,
+    -0x1.459d4500000092b4b8307c652ee639a7p-1,
+    -0x1.21497ep1,
+  },
+  { // Entry 40
+    0x1.6991e0ffe7f9c9b3ef7b3017d23639fap-1,
+    -0x1.6a81c4133db73e276c89e724c6fe975bp-1,
+    0x1.2dc230p1,
+  },
+  { // Entry 41
+    -0x1.6991e0ffe7f9c9b3ef7b3017d23639fap-1,
+    -0x1.6a81c4133db73e276c89e724c6fe975bp-1,
+    -0x1.2dc230p1,
+  },
+  { // Entry 42
+    0x1.41f6bd0000d13ba2bd7a63bf6d950865p-1,
+    -0x1.8e197fe4fac9901dc07a2878baf15c7ap-1,
+    0x1.344248p18,
+  },
+  { // Entry 43
+    -0x1.41f6bd0000d13ba2bd7a63bf6d950865p-1,
+    -0x1.8e197fe4fac9901dc07a2878baf15c7ap-1,
+    -0x1.344248p18,
+  },
+  { // Entry 44
+    0x1.37f8deffffff61ca15c366b3add8f373p-1,
+    -0x1.95fa20d230fdf9e8cccc5921e61f03adp-1,
+    0x1.3e42p1,
+  },
+  { // Entry 45
+    -0x1.37f8deffffff61ca15c366b3add8f373p-1,
+    -0x1.95fa20d230fdf9e8cccc5921e61f03adp-1,
+    -0x1.3e42p1,
+  },
+  { // Entry 46
+    0x1.2ed7ce518f4660cce49556856784970cp-1,
+    0x1.9cd4f3000002264af2b32ebe5d8243c0p-1,
+    0x1.440c3ap-1,
+  },
+  { // Entry 47
+    -0x1.2ed7ce518f4660cce49556856784970cp-1,
+    0x1.9cd4f3000002264af2b32ebe5d8243c0p-1,
+    -0x1.440c3ap-1,
+  },
+  { // Entry 48
+    0x1.475fc937750bdf2f704177612d31dc1fp-1,
+    0x1.89a999000012c047e4b24181d6158640p-1,
+    0x1.632f6ap-1,
+  },
+  { // Entry 49
+    -0x1.475fc937750bdf2f704177612d31dc1fp-1,
+    0x1.89a999000012c047e4b24181d6158640p-1,
+    -0x1.632f6ap-1,
+  },
+  { // Entry 50
+    -0x1.8ace1cfcc0a766b35d0e8f48f3169e8ap-1,
+    -0x1.45fec95a40619819e3307aebe0cb5e89p-1,
+    0x1.6e8f18p24,
+  },
+  { // Entry 51
+    0x1.8ace1cfcc0a766b35d0e8f48f3169e8ap-1,
+    -0x1.45fec95a40619819e3307aebe0cb5e89p-1,
+    -0x1.6e8f18p24,
+  },
+  { // Entry 52
+    0x1.7c6b92ff24ff028ea35c459e5ebeb2cdp-1,
+    0x1.56ac2ae54cc9a5210ae673ea1ce31d47p-1,
+    0x1.795840p23,
+  },
+  { // Entry 53
+    -0x1.7c6b92ff24ff028ea35c459e5ebeb2cdp-1,
+    0x1.56ac2ae54cc9a5210ae673ea1ce31d47p-1,
+    -0x1.795840p23,
+  },
+  { // Entry 54
+    0x1.697cf4ffea9244e85cea640d13c6fbb5p-1,
+    -0x1.6a96a106ace21610ab529c9047c7e6e2p-1,
+    0x1.7fe7fep35,
+  },
+  { // Entry 55
+    -0x1.697cf4ffea9244e85cea640d13c6fbb5p-1,
+    -0x1.6a96a106ace21610ab529c9047c7e6e2p-1,
+    -0x1.7fe7fep35,
+  },
+  { // Entry 56
+    0x1.9c6cf2fffffe8588512ea3c808b0fa9fp-1,
+    0x1.2f6560e0f14cd5d68920bec0e0c25354p-1,
+    0x1.ce1026p2,
+  },
+  { // Entry 57
+    -0x1.9c6cf2fffffe8588512ea3c808b0fa9fp-1,
+    0x1.2f6560e0f14cd5d68920bec0e0c25354p-1,
+    -0x1.ce1026p2,
+  },
+  { // Entry 58
+    -0x1.07fac04c6e73f485096bdaa3e65044d9p-1,
+    -0x1.b6b387ffceb67a18c15e868550b96462p-1,
+    0x1.d775d0p1,
+  },
+  { // Entry 59
+    0x1.07fac04c6e73f485096bdaa3e65044d9p-1,
+    -0x1.b6b387ffceb67a18c15e868550b96462p-1,
+    -0x1.d775d0p1,
+  },
+  { // Entry 60
+    0x1.9a8c62f4b2a949b06924662d9436bf17p-1,
+    0x1.31ee7074e3ebc5a30f0092ec6c5d8b80p-1,
+    0x1.dfeaaap108,
+  },
+  { // Entry 61
+    -0x1.9a8c62f4b2a949b06924662d9436bf17p-1,
+    0x1.31ee7074e3ebc5a30f0092ec6c5d8b80p-1,
+    -0x1.dfeaaap108,
+  },
+  { // Entry 62
+    0x1.d4de8affffffd96f83ba442fdf2f7101p-2,
+    0x1.c72cd4e1d6c78547d31707be80b4b0aep-1,
+    0x1.e7061ep-2,
+  },
+  { // Entry 63
+    -0x1.d4de8affffffd96f83ba442fdf2f7101p-2,
+    0x1.c72cd4e1d6c78547d31707be80b4b0aep-1,
+    -0x1.e7061ep-2,
+  },
+  { // Entry 64
+    -0x1.483445d4194813168a1ac63eee1943f9p-1,
+    0x1.88f882fcbc81ffdf720a4bb1b2fca71dp-1,
+    0x1.e89b2ap80,
+  },
+  { // Entry 65
+    0x1.483445d4194813168a1ac63eee1943f9p-1,
+    0x1.88f882fcbc81ffdf720a4bb1b2fca71dp-1,
+    -0x1.e89b2ap80,
+  },
+  { // Entry 66
+    0x1.565e410014916fa6550e606ed588c6b8p-1,
+    0x1.7cb1b34af85589bdaf7c0793af30b682p-1,
+    0x1.fe8270p18,
+  },
+  { // Entry 67
+    -0x1.565e410014916fa6550e606ed588c6b8p-1,
+    0x1.7cb1b34af85589bdaf7c0793af30b682p-1,
+    -0x1.fe8270p18,
+  },
+  { // Entry 68
+    -0x1.8356fbaea0454bce3983d9a0e0250c55p-1,
+    -0x1.4ed4c5ffc8018741870949767ff8dafap-1,
+    0x1.fff1fep1,
+  },
+  { // Entry 69
+    0x1.8356fbaea0454bce3983d9a0e0250c55p-1,
+    -0x1.4ed4c5ffc8018741870949767ff8dafap-1,
+    -0x1.fff1fep1,
+  },
+  { // Entry 70
+    0x1.fa9d6bfb33a77b2e3b3289168ced6dcap-1,
+    -0x1.28406a0025545c9a568dacd45518dd65p-3,
+    0x1.fff1fep2,
+  },
+  { // Entry 71
+    -0x1.fa9d6bfb33a77b2e3b3289168ced6dcap-1,
+    -0x1.28406a0025545c9a568dacd45518dd65p-3,
+    -0x1.fff1fep2,
+  },
+  { // Entry 72
+    0x1.d18f76ffc6e4ba0a3134e5be21b5bc8fp-1,
+    -0x1.aa2241160227896c68ef17839f17dce5p-2,
+    0x1.fffff6p0,
+  },
+  { // Entry 73
+    -0x1.d18f76ffc6e4ba0a3134e5be21b5bc8fp-1,
+    -0x1.aa2241160227896c68ef17839f17dce5p-2,
+    -0x1.fffff6p0,
+  },
+  { // Entry 74
+    0x1.fffffaaaaab2eeeedc3dc3f1ee7b41fep-12,
+    0x1.fffffc00001155553a7d27f4a289f319p-1,
+    0x1.fffffcp-12,
+  },
+  { // Entry 75
+    -0x1.fffffaaaaab2eeeedc3dc3f1ee7b41fep-12,
+    0x1.fffffc00001155553a7d27f4a289f319p-1,
+    -0x1.fffffcp-12,
+  },
+  { // Entry 76
+    -0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149,
+  },
+  { // Entry 77
+    0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149,
+  },
+  { // Entry 78
+    0.0,
+    0x1.p0,
+    0.0,
+  },
+  { // Entry 79
+    0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149,
+  },
+  { // Entry 80
+    -0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149,
+  },
+  { // Entry 81
+    -0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.000002p-126,
+  },
+  { // Entry 82
+    0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.000002p-126,
+  },
+  { // Entry 83
+    -0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-126,
+  },
+  { // Entry 84
+    0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-126,
+  },
+  { // Entry 85
+    -0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.fffffcp-127,
+  },
+  { // Entry 86
+    0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.fffffcp-127,
+  },
+  { // Entry 87
+    0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.fffffcp-127,
+  },
+  { // Entry 88
+    -0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.fffffcp-127,
+  },
+  { // Entry 89
+    0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-126,
+  },
+  { // Entry 90
+    -0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-126,
+  },
+  { // Entry 91
+    0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.000002p-126,
+  },
+  { // Entry 92
+    -0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.000002p-126,
+  },
+  { // Entry 93
+    0x1.999999d44f3058c789014b7d0e22fec3p-13,
+    0x1.ffffff5c28f57960cd56ebfe9482a61fp-1,
+    0x1.99999ap-13,
+  },
+  { // Entry 94
+    -0x1.999999d44f3058c789014b7d0e22fec3p-13,
+    0x1.ffffff5c28f57960cd56ebfe9482a61fp-1,
+    -0x1.99999ap-13,
+  },
+  { // Entry 95
+    0x1.999999513cc173e51bb9955b066f1db8p-12,
+    0x1.fffffd70a3d64e5ec165cd4307ad1326p-1,
+    0x1.99999ap-12,
+  },
+  { // Entry 96
+    -0x1.999999513cc173e51bb9955b066f1db8p-12,
+    0x1.fffffd70a3d64e5ec165cd4307ad1326p-1,
+    -0x1.99999ap-12,
+  },
+  { // Entry 97
+    0x1.333332d91685321e5fc397d20a5af1e6p-11,
+    0x1.fffffa3d709eecbfb5a385b0f3e0cb8fp-1,
+    0x1.333334p-11,
+  },
+  { // Entry 98
+    -0x1.333332d91685321e5fc397d20a5af1e6p-11,
+    0x1.fffffa3d709eecbfb5a385b0f3e0cb8fp-1,
+    -0x1.333334p-11,
+  },
+  { // Entry 99
+    0x1.99999744f306dc03e9ef70897f78299ep-11,
+    0x1.fffff5c28f5fc733c4202aa0bda92f97p-1,
+    0x1.99999ap-11,
+  },
+  { // Entry 100
+    -0x1.99999744f306dc03e9ef70897f78299ep-11,
+    0x1.fffff5c28f5fc733c4202aa0bda92f97p-1,
+    -0x1.99999ap-11,
+  },
+  { // Entry 101
+    0x1.fffffaaaaaaeeeeeed4ed4edab4c7bd6p-11,
+    0x1.fffff0000015555549f49f4d34d34ca0p-1,
+    0x1.p-10,
+  },
+  { // Entry 102
+    -0x1.fffffaaaaaaeeeeeed4ed4edab4c7bd6p-11,
+    0x1.fffff0000015555549f49f4d34d34ca0p-1,
+    -0x1.p-10,
+  },
+  { // Entry 103
+    0x1.33332f645a18c3b0ccfc0a3cf7b2e91bp-10,
+    0x1.ffffe8f5c29ce07640bd5f6d8bb1ea6bp-1,
+    0x1.333334p-10,
+  },
+  { // Entry 104
+    -0x1.33332f645a18c3b0ccfc0a3cf7b2e91bp-10,
+    0x1.ffffe8f5c29ce07640bd5f6d8bb1ea6bp-1,
+    -0x1.333334p-10,
+  },
+  { // Entry 105
+    0x1.666660aec330821c7a100cf488c380ebp-10,
+    0x1.ffffe0a3d714839f3601147ada73f8d9p-1,
+    0x1.666668p-10,
+  },
+  { // Entry 106
+    -0x1.666660aec330821c7a100cf488c380ebp-10,
+    0x1.ffffe0a3d714839f3601147ada73f8d9p-1,
+    -0x1.666668p-10,
+  },
+  { // Entry 107
+    0x1.99999113cc034144fdbdc8a1dc713253p-10,
+    0x1.ffffd70a3d8191f66de5408fb2b995a0p-1,
+    0x1.99999cp-10,
+  },
+  { // Entry 108
+    -0x1.99999113cc034144fdbdc8a1dc713253p-10,
+    0x1.ffffd70a3d8191f66de5408fb2b995a0p-1,
+    -0x1.99999cp-10,
+  },
+  { // Entry 109
+    0x1.ccccbc72b05dd0951a9c5e65560c56e3p-10,
+    0x1.ffffcc28f6d096b87d6d19a06e96999bp-1,
+    0x1.ccccccp-10,
+  },
+  { // Entry 110
+    -0x1.ccccbc72b05dd0951a9c5e65560c56e3p-10,
+    0x1.ffffcc28f6d096b87d6d19a06e96999bp-1,
+    -0x1.ccccccp-10,
+  },
+  { // Entry 111
+    0x1.0665ae3615b5b7de52798064dfc59b29p-7,
+    0x1.fffbcc2a71ceaabf5582b6da1fc30531p-1,
+    0x1.066666p-7,
+  },
+  { // Entry 112
+    -0x1.0665ae3615b5b7de52798064dfc59b29p-7,
+    0x1.fffbcc2a71ceaabf5582b6da1fc30531p-1,
+    -0x1.066666p-7,
+  },
+  { // Entry 113
+    0x1.ccc8e8ae92586d8d66b6ad0aedcb0d94p-7,
+    0x1.fff30a4b7b5119d8e299f717ec0ece16p-1,
+    0x1.ccccccp-7,
+  },
+  { // Entry 114
+    -0x1.ccc8e8ae92586d8d66b6ad0aedcb0d94p-7,
+    0x1.fff30a4b7b5119d8e299f717ec0ece16p-1,
+    -0x1.ccccccp-7,
+  },
+  { // Entry 115
+    0x1.4993e70f7b17c10af9f97fc7b33b822bp-6,
+    0x1.ffe57a785123226c1e2efb411353edc9p-1,
+    0x1.499998p-6,
+  },
+  { // Entry 116
+    -0x1.4993e70f7b17c10af9f97fc7b33b822bp-6,
+    0x1.ffe57a785123226c1e2efb411353edc9p-1,
+    -0x1.499998p-6,
+  },
+  { // Entry 117
+    0x1.acc043f8b2d89ad5143c030e9766fc11p-6,
+    0x1.ffd31cd10cb632d9733ac5f5f327a5f9p-1,
+    0x1.acccccp-6,
+  },
+  { // Entry 118
+    -0x1.acc043f8b2d89ad5143c030e9766fc11p-6,
+    0x1.ffd31cd10cb632d9733ac5f5f327a5f9p-1,
+    -0x1.acccccp-6,
+  },
+  { // Entry 119
+    0x1.07f44d67cf41afbc0c95108b99f91b01p-5,
+    0x1.ffbbf18207542ef81390d73c3ba89c1ap-1,
+    0x1.08p-5,
+  },
+  { // Entry 120
+    -0x1.07f44d67cf41afbc0c95108b99f91b01p-5,
+    0x1.ffbbf18207542ef81390d73c3ba89c1ap-1,
+    -0x1.08p-5,
+  },
+  { // Entry 121
+    0x1.3985fead44fa2b851e651acba369d769p-5,
+    0x1.ff9ff8c2eaeaee30fb211765af835171p-1,
+    0x1.39999ap-5,
+  },
+  { // Entry 122
+    -0x1.3985fead44fa2b851e651acba369d769p-5,
+    0x1.ff9ff8c2eaeaee30fb211765af835171p-1,
+    -0x1.39999ap-5,
+  },
+  { // Entry 123
+    0x1.6b14beb5d40d745096247e59b622828bp-5,
+    0x1.ff7f32d6eb1f9cf90226ec291c9e0922p-1,
+    0x1.6b3334p-5,
+  },
+  { // Entry 124
+    -0x1.6b14beb5d40d745096247e59b622828bp-5,
+    0x1.ff7f32d6eb1f9cf90226ec291c9e0922p-1,
+    -0x1.6b3334p-5,
+  },
+  { // Entry 125
+    0x1.9ca01671a7995fc97cebd69729cc4309p-5,
+    0x1.ff59a00cc4ad492ca2597495412998edp-1,
+    0x1.9ccccep-5,
+  },
+  { // Entry 126
+    -0x1.9ca01671a7995fc97cebd69729cc4309p-5,
+    0x1.ff59a00cc4ad492ca2597495412998edp-1,
+    -0x1.9ccccep-5,
+  },
+  { // Entry 127
+    0x1.ce278cd9eb2cbd0c6a4e1279f690e856p-5,
+    0x1.ff2f40c08acf4580a8d13380d9073398p-1,
+    0x1.ce6666p-5,
+  },
+  { // Entry 128
+    -0x1.ce278cd9eb2cbd0c6a4e1279f690e856p-5,
+    0x1.ff2f40c08acf4580a8d13380d9073398p-1,
+    -0x1.ce6666p-5,
+  },
+  { // Entry 129
+    0x1.43c1e9972391aa8ecd8a9ccba907920ap-1,
+    0x1.8ca46ca011771bfae0d9edbf1dacb402p-1,
+    0x1.5e7fc4p-1,
+  },
+  { // Entry 130
+    -0x1.43c1e9972391aa8ecd8a9ccba907920ap-1,
+    0x1.8ca46ca011771bfae0d9edbf1dacb402p-1,
+    -0x1.5e7fc4p-1,
+  },
+  { // Entry 131
+    0x1.ee3d6bb21c64b2382efcff0cdf30ce0bp-1,
+    0x1.0b5d38d5d82e4a7624dac4e10ce159c2p-2,
+    0x1.4e7fc4p0,
+  },
+  { // Entry 132
+    -0x1.ee3d6bb21c64b2382efcff0cdf30ce0bp-1,
+    0x1.0b5d38d5d82e4a7624dac4e10ce159c2p-2,
+    -0x1.4e7fc4p0,
+  },
+  { // Entry 133
+    0x1.df8e2323e4bf1a538a100ec1bf3494a9p-1,
+    -0x1.66b96e204e69cda8e9cf50996432539ep-2,
+    0x1.edbfa6p0,
+  },
+  { // Entry 134
+    -0x1.df8e2323e4bf1a538a100ec1bf3494a9p-1,
+    -0x1.66b96e204e69cda8e9cf50996432539ep-2,
+    -0x1.edbfa6p0,
+  },
+  { // Entry 135
+    0x1.1d347aa02feb3bb1750d25509435da88p-1,
+    -0x1.a935540edeca4c220ed91dc5481e4d9bp-1,
+    0x1.467fc4p1,
+  },
+  { // Entry 136
+    -0x1.1d347aa02feb3bb1750d25509435da88p-1,
+    -0x1.a935540edeca4c220ed91dc5481e4d9bp-1,
+    -0x1.467fc4p1,
+  },
+  { // Entry 137
+    -0x1.ffea08e1c97f4c4de01961cc3e7b04dcp-6,
+    -0x1.ffc0017dd9209dd8891f17fe4c9eee46p-1,
+    0x1.961fb4p1,
+  },
+  { // Entry 138
+    0x1.ffea08e1c97f4c4de01961cc3e7b04dcp-6,
+    -0x1.ffc0017dd9209dd8891f17fe4c9eee46p-1,
+    -0x1.961fb4p1,
+  },
+  { // Entry 139
+    -0x1.3734cbced9c0f484e5f762e00216e620p-1,
+    -0x1.969082007733d787f4c36ba0f9425694p-1,
+    0x1.e5bfa4p1,
+  },
+  { // Entry 140
+    0x1.3734cbced9c0f484e5f762e00216e620p-1,
+    -0x1.969082007733d787f4c36ba0f9425694p-1,
+    -0x1.e5bfa4p1,
+  },
+  { // Entry 141
+    -0x1.e9d2592bec10c3acb15c5852239a2aa8p-1,
+    -0x1.2a1e74223d9bddb7db59f781f96b65ecp-2,
+    0x1.1aafcap2,
+  },
+  { // Entry 142
+    0x1.e9d2592bec10c3acb15c5852239a2aa8p-1,
+    -0x1.2a1e74223d9bddb7db59f781f96b65ecp-2,
+    -0x1.1aafcap2,
+  },
+  { // Entry 143
+    -0x1.e4ece208d0c4913ab019cab0ce9c785ep-1,
+    0x1.4894d50b84dbc981134a591ac4165d9ep-2,
+    0x1.427fc2p2,
+  },
+  { // Entry 144
+    0x1.e4ece208d0c4913ab019cab0ce9c785ep-1,
+    0x1.4894d50b84dbc981134a591ac4165d9ep-2,
+    -0x1.427fc2p2,
+  },
+  { // Entry 145
+    -0x1.2a5a02d392b54f641a0d88bd4ac6c2e1p-1,
+    0x1.a016dd7480a1eea4d49efb585fa49c86p-1,
+    0x1.6a4fbap2,
+  },
+  { // Entry 146
+    0x1.2a5a02d392b54f641a0d88bd4ac6c2e1p-1,
+    0x1.a016dd7480a1eea4d49efb585fa49c86p-1,
+    -0x1.6a4fbap2,
+  },
+  { // Entry 147
+    -0x1.263123df22d13ed329c665c83c0e71e8p-1,
+    0x1.a30a6a3bf4a3e2b7e27666d3a9c3b74bp-1,
+    0x1.6af2f0p2,
+  },
+  { // Entry 148
+    0x1.263123df22d13ed329c665c83c0e71e8p-1,
+    0x1.a30a6a3bf4a3e2b7e27666d3a9c3b74bp-1,
+    -0x1.6af2f0p2,
+  },
+  { // Entry 149
+    -0x1.e18e67b508ffc9e42f6c9e72f8e545f3p-1,
+    0x1.5bd625504015ccc101e4f4340d4b762bp-2,
+    0x1.43c62ap2,
+  },
+  { // Entry 150
+    0x1.e18e67b508ffc9e42f6c9e72f8e545f3p-1,
+    0x1.5bd625504015ccc101e4f4340d4b762bp-2,
+    -0x1.43c62ap2,
+  },
+  { // Entry 151
+    -0x1.ee0e80ec9d1562c17a6cf608af9b0ed4p-1,
+    -0x1.0cb733448c30ee3ddffb4da69f0b3842p-2,
+    0x1.1c9964p2,
+  },
+  { // Entry 152
+    0x1.ee0e80ec9d1562c17a6cf608af9b0ed4p-1,
+    -0x1.0cb733448c30ee3ddffb4da69f0b3842p-2,
+    -0x1.1c9964p2,
+  },
+  { // Entry 153
+    -0x1.472768637ea8866a652098a43aa688a6p-1,
+    -0x1.89d874ad30e3fb46244daa24451690d7p-1,
+    0x1.ead93cp1,
+  },
+  { // Entry 154
+    0x1.472768637ea8866a652098a43aa688a6p-1,
+    -0x1.89d874ad30e3fb46244daa24451690d7p-1,
+    -0x1.ead93cp1,
+  },
+  { // Entry 155
+    -0x1.4ba24f6325f21420e7c48d4f91e28064p-4,
+    -0x1.fe51ae09f0d39ed554e68bef3e2f8a03p-1,
+    0x1.9c7fb0p1,
+  },
+  { // Entry 156
+    0x1.4ba24f6325f21420e7c48d4f91e28064p-4,
+    -0x1.fe51ae09f0d39ed554e68bef3e2f8a03p-1,
+    -0x1.9c7fb0p1,
+  },
+  { // Entry 157
+    0x1.034c643295153aaffe5d9a0f29e92844p-1,
+    -0x1.b97bf76ae765eb69cf55e80aae977303p-1,
+    0x1.4e2624p1,
+  },
+  { // Entry 158
+    -0x1.034c643295153aaffe5d9a0f29e92844p-1,
+    -0x1.b97bf76ae765eb69cf55e80aae977303p-1,
+    -0x1.4e2624p1,
+  },
+  { // Entry 159
+    0x1.d1e4d96eac917574b948e4ea9e37b36dp-1,
+    -0x1.a8ac5793e32629b131984ecffd2d0f31p-2,
+    0x1.ff9932p0,
+  },
+  { // Entry 160
+    -0x1.d1e4d96eac917574b948e4ea9e37b36dp-1,
+    -0x1.a8ac5793e32629b131984ecffd2d0f31p-2,
+    -0x1.ff9932p0,
+  },
+  { // Entry 161
+    0x1.f7501e002bcafb897f931931d3a57afdp-1,
+    0x1.77a92ca01bc79c195dda33736807f986p-3,
+    0x1.62e61cp0,
+  },
+  { // Entry 162
+    -0x1.f7501e002bcafb897f931931d3a57afdp-1,
+    0x1.77a92ca01bc79c195dda33736807f986p-3,
+    -0x1.62e61cp0,
+  },
+  { // Entry 163
+    0x1.65f7d66ef6591cfc51ab29dc2086d3e7p-1,
+    0x1.6e1060282c1488d9abd83da1d68cd0f7p-1,
+    0x1.8c662cp-1,
+  },
+  { // Entry 164
+    -0x1.65f7d66ef6591cfc51ab29dc2086d3e7p-1,
+    0x1.6e1060282c1488d9abd83da1d68cd0f7p-1,
+    -0x1.8c662cp-1,
+  },
+  { // Entry 165
+    -0x1.fe043f875c6ed4a2c1b8d69a09fcf578p-1,
+    -0x1.682f2bb87a8f5011735094176c9b6dacp-4,
+    -0x1.a8aa1cp0,
+  },
+  { // Entry 166
+    0x1.fe043f875c6ed4a2c1b8d69a09fcf578p-1,
+    -0x1.682f2bb87a8f5011735094176c9b6dacp-4,
+    0x1.a8aa1cp0,
+  },
+  { // Entry 167
+    -0x1.fff18f313e66f1ae25f89a5f7a1f84c4p-1,
+    -0x1.e665cb2af842be5ba5f65960599a97ecp-7,
+    -0x1.95ec8ap0,
+  },
+  { // Entry 168
+    0x1.fff18f313e66f1ae25f89a5f7a1f84c4p-1,
+    -0x1.e665cb2af842be5ba5f65960599a97ecp-7,
+    0x1.95ec8ap0,
+  },
+  { // Entry 169
+    -0x1.ff20d920b9e9c23154f97e2f342a2884p-1,
+    0x1.ddd231501b12fcf2bc20633be4d51e51p-5,
+    -0x1.832ef8p0,
+  },
+  { // Entry 170
+    0x1.ff20d920b9e9c23154f97e2f342a2884p-1,
+    0x1.ddd231501b12fcf2bc20633be4d51e51p-5,
+    0x1.832ef8p0,
+  },
+  { // Entry 171
+    -0x1.fb933b89d7db3286eed0cfeabee98875p-1,
+    0x1.0caba6997691ab1970d43c7419ed51e1p-3,
+    -0x1.707166p0,
+  },
+  { // Entry 172
+    0x1.fb933b89d7db3286eed0cfeabee98875p-1,
+    0x1.0caba6997691ab1970d43c7419ed51e1p-3,
+    0x1.707166p0,
+  },
+  { // Entry 173
+    -0x1.f54d95c5058b7dc9972ab6f9928ca043p-1,
+    0x1.a072541fd6eaf8b65a874c58d6cc5739p-3,
+    -0x1.5db3d4p0,
+  },
+  { // Entry 174
+    0x1.f54d95c5058b7dc9972ab6f9928ca043p-1,
+    0x1.a072541fd6eaf8b65a874c58d6cc5739p-3,
+    0x1.5db3d4p0,
+  },
+  { // Entry 175
+    -0x1.ec5881a09c46aae020cd9036098a196ep-1,
+    0x1.18fef8106bea63b9e96a7adf538c6194p-2,
+    -0x1.4af642p0,
+  },
+  { // Entry 176
+    0x1.ec5881a09c46aae020cd9036098a196ep-1,
+    0x1.18fef8106bea63b9e96a7adf538c6194p-2,
+    0x1.4af642p0,
+  },
+  { // Entry 177
+    -0x1.e0c04795919d961a5e83e505df31c624p-1,
+    0x1.60437277d48067e85230bce1883eaabap-2,
+    -0x1.3838b0p0,
+  },
+  { // Entry 178
+    0x1.e0c04795919d961a5e83e505df31c624p-1,
+    0x1.60437277d48067e85230bce1883eaabap-2,
+    0x1.3838b0p0,
+  },
+  { // Entry 179
+    -0x1.d294cdef7cc161633a02d3e62058be0ep-1,
+    0x1.a5a4ded492bedfe8cf5c34cadd78df75p-2,
+    -0x1.257b1ep0,
+  },
+  { // Entry 180
+    0x1.d294cdef7cc161633a02d3e62058be0ep-1,
+    0x1.a5a4ded492bedfe8cf5c34cadd78df75p-2,
+    0x1.257b1ep0,
+  },
+  { // Entry 181
+    -0x1.c1e988b95614abd65d3d811f5c88039bp-1,
+    0x1.e8c4040678d2ef736333a4537a1113a1p-2,
+    -0x1.12bd92p0,
+  },
+  { // Entry 182
+    0x1.c1e988b95614abd65d3d811f5c88039bp-1,
+    0x1.e8c4040678d2ef736333a4537a1113a1p-2,
+    0x1.12bd92p0,
+  },
+  { // Entry 183
+    -0x1.a2c2895edb0d4ba51cdbd5390cac468fp-1,
+    0x1.26976b1b16d19091c09259765c4b3872p-1,
+    -0x1.ea5c3ep-1,
+  },
+  { // Entry 184
+    0x1.a2c2895edb0d4ba51cdbd5390cac468fp-1,
+    0x1.26976b1b16d19091c09259765c4b3872p-1,
+    0x1.ea5c3ep-1,
+  },
+  { // Entry 185
+    -0x1.95f05153644d60b94d2f2e700dfd3a37p-1,
+    0x1.3805a2dafda7f8554aec65dab348a714p-1,
+    -0x1.d4b87cp-1,
+  },
+  { // Entry 186
+    0x1.95f05153644d60b94d2f2e700dfd3a37p-1,
+    0x1.3805a2dafda7f8554aec65dab348a714p-1,
+    0x1.d4b87cp-1,
+  },
+  { // Entry 187
+    -0x1.88647d8ad2e41fb7c0af0f64614c9993p-1,
+    0x1.48e52ff5bbe794618b85190b86411824p-1,
+    -0x1.bf14bap-1,
+  },
+  { // Entry 188
+    0x1.88647d8ad2e41fb7c0af0f64614c9993p-1,
+    0x1.48e52ff5bbe794618b85190b86411824p-1,
+    0x1.bf14bap-1,
+  },
+  { // Entry 189
+    -0x1.7a253f9f89a7d3e4f9c54638418e97f6p-1,
+    0x1.592e5b615ef5ae463976d31141dbacf0p-1,
+    -0x1.a970f8p-1,
+  },
+  { // Entry 190
+    0x1.7a253f9f89a7d3e4f9c54638418e97f6p-1,
+    0x1.592e5b615ef5ae463976d31141dbacf0p-1,
+    0x1.a970f8p-1,
+  },
+  { // Entry 191
+    -0x1.6b391b34aab828fbe7cd7dcaf9ef3bd6p-1,
+    0x1.68d9b2d657e4307d331eb7bd35ee1879p-1,
+    -0x1.93cd36p-1,
+  },
+  { // Entry 192
+    0x1.6b391b34aab828fbe7cd7dcaf9ef3bd6p-1,
+    0x1.68d9b2d657e4307d331eb7bd35ee1879p-1,
+    0x1.93cd36p-1,
+  },
+  { // Entry 193
+    -0x1.5ba6e2fb980d482cf00ede80f5597fb2p-1,
+    0x1.77e00c3718528c36f722e63096c2646bp-1,
+    -0x1.7e2974p-1,
+  },
+  { // Entry 194
+    0x1.5ba6e2fb980d482cf00ede80f5597fb2p-1,
+    0x1.77e00c3718528c36f722e63096c2646bp-1,
+    0x1.7e2974p-1,
+  },
+  { // Entry 195
+    -0x1.4b75b5954e718020900719e25a7ea93bp-1,
+    0x1.863a88d6b064f36f34370722d361ce9fp-1,
+    -0x1.6885b2p-1,
+  },
+  { // Entry 196
+    0x1.4b75b5954e718020900719e25a7ea93bp-1,
+    0x1.863a88d6b064f36f34370722d361ce9fp-1,
+    0x1.6885b2p-1,
+  },
+  { // Entry 197
+    -0x1.3aacfa510810054c52ae0b67d116eb40p-1,
+    0x1.93e2989cee6084e34b533b1eb92746dap-1,
+    -0x1.52e1f0p-1,
+  },
+  { // Entry 198
+    0x1.3aacfa510810054c52ae0b67d116eb40p-1,
+    0x1.93e2989cee6084e34b533b1eb92746dap-1,
+    0x1.52e1f0p-1,
+  },
+  { // Entry 199
+    -0x1.2954644ceb8e3a2479c83ae84af57d3ep-1,
+    0x1.a0d1f8613ebc60c7ee6502ee183c89e7p-1,
+    -0x1.3d3e36p-1,
+  },
+  { // Entry 200
+    0x1.2954644ceb8e3a2479c83ae84af57d3ep-1,
+    0x1.a0d1f8613ebc60c7ee6502ee183c89e7p-1,
+    0x1.3d3e36p-1,
+  },
+  { // Entry 201
+    -0x1.fc769aecd265cfea08e0ff30c2fbcacdp-2,
+    0x1.bc6bd889a8a59dbb56e546a37ae798f5p-1,
+    -0x1.0a0b02p-1,
+  },
+  { // Entry 202
+    0x1.fc769aecd265cfea08e0ff30c2fbcacdp-2,
+    0x1.bc6bd889a8a59dbb56e546a37ae798f5p-1,
+    0x1.0a0b02p-1,
+  },
+  { // Entry 203
+    -0x1.c853c704e3b94322031d6b47aef853c9p-2,
+    0x1.ca59c719f96075dd6b7a0ff443ad59dcp-1,
+    -0x1.d8f720p-2,
+  },
+  { // Entry 204
+    0x1.c853c704e3b94322031d6b47aef853c9p-2,
+    0x1.ca59c719f96075dd6b7a0ff443ad59dcp-1,
+    0x1.d8f720p-2,
+  },
+  { // Entry 205
+    -0x1.92aba8981b25deda4cc1817251723a1bp-2,
+    0x1.d6c0b13df99613a49306b4dc6c57aa03p-1,
+    -0x1.9dd83cp-2,
+  },
+  { // Entry 206
+    0x1.92aba8981b25deda4cc1817251723a1bp-2,
+    0x1.d6c0b13df99613a49306b4dc6c57aa03p-1,
+    0x1.9dd83cp-2,
+  },
+  { // Entry 207
+    -0x1.5bac05e1e0a7c2de280fcb93be67a4dap-2,
+    0x1.e1960273a4aaa1bd19ef0ccaa8874183p-1,
+    -0x1.62b958p-2,
+  },
+  { // Entry 208
+    0x1.5bac05e1e0a7c2de280fcb93be67a4dap-2,
+    0x1.e1960273a4aaa1bd19ef0ccaa8874183p-1,
+    0x1.62b958p-2,
+  },
+  { // Entry 209
+    -0x1.2383ca2b249807d95005d96cfdaecd6cp-2,
+    0x1.ead07cd2e0f7f19679646362bbc0eb80p-1,
+    -0x1.279a74p-2,
+  },
+  { // Entry 210
+    0x1.2383ca2b249807d95005d96cfdaecd6cp-2,
+    0x1.ead07cd2e0f7f19679646362bbc0eb80p-1,
+    0x1.279a74p-2,
+  },
+  { // Entry 211
+    -0x1.d4c5bb872ea5375834ca0bca088d1d75p-3,
+    0x1.f26840efd86ceea23f388b6a1102ea4dp-1,
+    -0x1.d8f720p-3,
+  },
+  { // Entry 212
+    0x1.d4c5bb872ea5375834ca0bca088d1d75p-3,
+    0x1.f26840efd86ceea23f388b6a1102ea4dp-1,
+    0x1.d8f720p-3,
+  },
+  { // Entry 213
+    -0x1.60f3fa460b85811d2ae710cd69ec3690p-3,
+    0x1.f856d49251bd37c54f0094270eecbd18p-1,
+    -0x1.62b958p-3,
+  },
+  { // Entry 214
+    0x1.60f3fa460b85811d2ae710cd69ec3690p-3,
+    0x1.f856d49251bd37c54f0094270eecbd18p-1,
+    0x1.62b958p-3,
+  },
+  { // Entry 215
+    -0x1.d7ea3d56e1e6244c8786d74f189d98acp-4,
+    0x1.fc97283c4f5bd1f793201972b8db551fp-1,
+    -0x1.d8f720p-4,
+  },
+  { // Entry 216
+    0x1.d7ea3d56e1e6244c8786d74f189d98acp-4,
+    0x1.fc97283c4f5bd1f793201972b8db551fp-1,
+    0x1.d8f720p-4,
+  },
+  { // Entry 217
+    -0x1.d8b3deba6ac493b04b2103a0dbaef02fp-5,
+    0x1.ff259b7b3d721edf063a5bf6e7a1f93cp-1,
+    -0x1.d8f720p-5,
+  },
+  { // Entry 218
+    0x1.d8b3deba6ac493b04b2103a0dbaef02fp-5,
+    0x1.ff259b7b3d721edf063a5bf6e7a1f93cp-1,
+    0x1.d8f720p-5,
+  },
+  { // Entry 219
+    0x1.d8b3deba6ac493b04b2103a0dbaef02fp-5,
+    0x1.ff259b7b3d721edf063a5bf6e7a1f93cp-1,
+    0x1.d8f720p-5,
+  },
+  { // Entry 220
+    -0x1.d8b3deba6ac493b04b2103a0dbaef02fp-5,
+    0x1.ff259b7b3d721edf063a5bf6e7a1f93cp-1,
+    -0x1.d8f720p-5,
+  },
+  { // Entry 221
+    0x1.d7ea3d56e1e6244c8786d74f189d98acp-4,
+    0x1.fc97283c4f5bd1f793201972b8db551fp-1,
+    0x1.d8f720p-4,
+  },
+  { // Entry 222
+    -0x1.d7ea3d56e1e6244c8786d74f189d98acp-4,
+    0x1.fc97283c4f5bd1f793201972b8db551fp-1,
+    -0x1.d8f720p-4,
+  },
+  { // Entry 223
+    0x1.60f3fa460b85811d2ae710cd69ec3690p-3,
+    0x1.f856d49251bd37c54f0094270eecbd18p-1,
+    0x1.62b958p-3,
+  },
+  { // Entry 224
+    -0x1.60f3fa460b85811d2ae710cd69ec3690p-3,
+    0x1.f856d49251bd37c54f0094270eecbd18p-1,
+    -0x1.62b958p-3,
+  },
+  { // Entry 225
+    0x1.d4c5bb872ea5375834ca0bca088d1d75p-3,
+    0x1.f26840efd86ceea23f388b6a1102ea4dp-1,
+    0x1.d8f720p-3,
+  },
+  { // Entry 226
+    -0x1.d4c5bb872ea5375834ca0bca088d1d75p-3,
+    0x1.f26840efd86ceea23f388b6a1102ea4dp-1,
+    -0x1.d8f720p-3,
+  },
+  { // Entry 227
+    0x1.2383ca2b249807d95005d96cfdaecd6cp-2,
+    0x1.ead07cd2e0f7f19679646362bbc0eb80p-1,
+    0x1.279a74p-2,
+  },
+  { // Entry 228
+    -0x1.2383ca2b249807d95005d96cfdaecd6cp-2,
+    0x1.ead07cd2e0f7f19679646362bbc0eb80p-1,
+    -0x1.279a74p-2,
+  },
+  { // Entry 229
+    0x1.5bac05e1e0a7c2de280fcb93be67a4dap-2,
+    0x1.e1960273a4aaa1bd19ef0ccaa8874183p-1,
+    0x1.62b958p-2,
+  },
+  { // Entry 230
+    -0x1.5bac05e1e0a7c2de280fcb93be67a4dap-2,
+    0x1.e1960273a4aaa1bd19ef0ccaa8874183p-1,
+    -0x1.62b958p-2,
+  },
+  { // Entry 231
+    0x1.92aba8981b25deda4cc1817251723a1bp-2,
+    0x1.d6c0b13df99613a49306b4dc6c57aa03p-1,
+    0x1.9dd83cp-2,
+  },
+  { // Entry 232
+    -0x1.92aba8981b25deda4cc1817251723a1bp-2,
+    0x1.d6c0b13df99613a49306b4dc6c57aa03p-1,
+    -0x1.9dd83cp-2,
+  },
+  { // Entry 233
+    0x1.c853c704e3b94322031d6b47aef853c9p-2,
+    0x1.ca59c719f96075dd6b7a0ff443ad59dcp-1,
+    0x1.d8f720p-2,
+  },
+  { // Entry 234
+    -0x1.c853c704e3b94322031d6b47aef853c9p-2,
+    0x1.ca59c719f96075dd6b7a0ff443ad59dcp-1,
+    -0x1.d8f720p-2,
+  },
+  { // Entry 235
+    0x1.fc769aecd265cfea08e0ff30c2fbcacdp-2,
+    0x1.bc6bd889a8a59dbb56e546a37ae798f5p-1,
+    0x1.0a0b02p-1,
+  },
+  { // Entry 236
+    -0x1.fc769aecd265cfea08e0ff30c2fbcacdp-2,
+    0x1.bc6bd889a8a59dbb56e546a37ae798f5p-1,
+    -0x1.0a0b02p-1,
+  },
+  { // Entry 237
+    0x1.2954644ceb8e3a2479c83ae84af57d3ep-1,
+    0x1.a0d1f8613ebc60c7ee6502ee183c89e7p-1,
+    0x1.3d3e36p-1,
+  },
+  { // Entry 238
+    -0x1.2954644ceb8e3a2479c83ae84af57d3ep-1,
+    0x1.a0d1f8613ebc60c7ee6502ee183c89e7p-1,
+    -0x1.3d3e36p-1,
+  },
+  { // Entry 239
+    0x1.3aad00a09268a39df1653c70db91f157p-1,
+    0x1.93e293b23a6aa1ae5373214eb8fb9e96p-1,
+    0x1.52e1f8p-1,
+  },
+  { // Entry 240
+    -0x1.3aad00a09268a39df1653c70db91f157p-1,
+    0x1.93e293b23a6aa1ae5373214eb8fb9e96p-1,
+    -0x1.52e1f8p-1,
+  },
+  { // Entry 241
+    0x1.4b75bbae388a7f3466e7f2d6bdcf72bbp-1,
+    0x1.863a83a8d9826c6135509406ebe05c0fp-1,
+    0x1.6885bap-1,
+  },
+  { // Entry 242
+    -0x1.4b75bbae388a7f3466e7f2d6bdcf72bbp-1,
+    0x1.863a83a8d9826c6135509406ebe05c0fp-1,
+    -0x1.6885bap-1,
+  },
+  { // Entry 243
+    0x1.5ba6e8db1833475712b9a42a1ad0d2c2p-1,
+    0x1.77e006c87cbaded66ec5b960c93c568ap-1,
+    0x1.7e297cp-1,
+  },
+  { // Entry 244
+    -0x1.5ba6e8db1833475712b9a42a1ad0d2c2p-1,
+    0x1.77e006c87cbaded66ec5b960c93c568ap-1,
+    -0x1.7e297cp-1,
+  },
+  { // Entry 245
+    0x1.6b3920d8117828928fe10ac70ba69e76p-1,
+    0x1.68d9ad29736c1704caea6a2db6e71223p-1,
+    0x1.93cd3ep-1,
+  },
+  { // Entry 246
+    -0x1.6b3920d8117828928fe10ac70ba69e76p-1,
+    0x1.68d9ad29736c1704caea6a2db6e71223p-1,
+    -0x1.93cd3ep-1,
+  },
+  { // Entry 247
+    0x1.7a25450443098836c5202375db4b8462p-1,
+    0x1.592e5578c9ec66acceddd4dc6ce66b26p-1,
+    0x1.a971p-1,
+  },
+  { // Entry 248
+    -0x1.7a25450443098836c5202375db4b8462p-1,
+    0x1.592e5578c9ec66acceddd4dc6ce66b26p-1,
+    -0x1.a971p-1,
+  },
+  { // Entry 249
+    0x1.886482ae6797b38364f5c72ce9a3b76fp-1,
+    0x1.48e529d429e721ec8bb1e014f94d48f1p-1,
+    0x1.bf14c2p-1,
+  },
+  { // Entry 250
+    -0x1.886482ae6797b38364f5c72ce9a3b76fp-1,
+    0x1.48e529d429e721ec8bb1e014f94d48f1p-1,
+    -0x1.bf14c2p-1,
+  },
+  { // Entry 251
+    0x1.95f056337acc1d2d557525232e915467p-1,
+    0x1.38059c833c58ea970f7b96d6ada3d9c4p-1,
+    0x1.d4b884p-1,
+  },
+  { // Entry 252
+    -0x1.95f056337acc1d2d557525232e915467p-1,
+    0x1.38059c833c58ea970f7b96d6ada3d9c4p-1,
+    -0x1.d4b884p-1,
+  },
+  { // Entry 253
+    0x1.a2c2895edb0d4ba51cdbd5390cac468fp-1,
+    0x1.26976b1b16d19091c09259765c4b3872p-1,
+    0x1.ea5c3ep-1,
+  },
+  { // Entry 254
+    -0x1.a2c2895edb0d4ba51cdbd5390cac468fp-1,
+    0x1.26976b1b16d19091c09259765c4b3872p-1,
+    -0x1.ea5c3ep-1,
+  },
+  { // Entry 255
+    0x1.c1e988b95614abd65d3d811f5c88039bp-1,
+    0x1.e8c4040678d2ef736333a4537a1113a1p-2,
+    0x1.12bd92p0,
+  },
+  { // Entry 256
+    -0x1.c1e988b95614abd65d3d811f5c88039bp-1,
+    0x1.e8c4040678d2ef736333a4537a1113a1p-2,
+    -0x1.12bd92p0,
+  },
+  { // Entry 257
+    0x1.d294d2e06b3d10a4de263172d50f4497p-1,
+    0x1.a5a4c8f598fa0078971316eb4907f97bp-2,
+    0x1.257b24p0,
+  },
+  { // Entry 258
+    -0x1.d294d2e06b3d10a4de263172d50f4497p-1,
+    0x1.a5a4c8f598fa0078971316eb4907f97bp-2,
+    -0x1.257b24p0,
+  },
+  { // Entry 259
+    0x1.e0c04bb65bd33012be72a340df2c044bp-1,
+    0x1.60435beed10ca05769f0a3d86a5a20f3p-2,
+    0x1.3838b6p0,
+  },
+  { // Entry 260
+    -0x1.e0c04bb65bd33012be72a340df2c044bp-1,
+    0x1.60435beed10ca05769f0a3d86a5a20f3p-2,
+    -0x1.3838b6p0,
+  },
+  { // Entry 261
+    0x1.ec5884eb990c3deaaeebd3f0f84d6962p-1,
+    0x1.18fee0fc45c31a79b2b9478b1f72a9ebp-2,
+    0x1.4af648p0,
+  },
+  { // Entry 262
+    -0x1.ec5884eb990c3deaaeebd3f0f84d6962p-1,
+    0x1.18fee0fc45c31a79b2b9478b1f72a9ebp-2,
+    -0x1.4af648p0,
+  },
+  { // Entry 263
+    0x1.f54d9835b0e66e17612160272521f3b0p-1,
+    0x1.a072252090c33828767aee3e040ccddfp-3,
+    0x1.5db3dap0,
+  },
+  { // Entry 264
+    -0x1.f54d9835b0e66e17612160272521f3b0p-1,
+    0x1.a072252090c33828767aee3e040ccddfp-3,
+    -0x1.5db3dap0,
+  },
+  { // Entry 265
+    0x1.fb933d1cd931685e902e403a1baaecfdp-1,
+    0x1.0cab7703a8e9dacc4ad01188b443cfeep-3,
+    0x1.70716cp0,
+  },
+  { // Entry 266
+    -0x1.fb933d1cd931685e902e403a1baaecfdp-1,
+    0x1.0cab7703a8e9dacc4ad01188b443cfeep-3,
+    -0x1.70716cp0,
+  },
+  { // Entry 267
+    0x1.ff20d9d3e8984fec33982e42f5884f2cp-1,
+    0x1.ddd171a3c9851e7819b5e4f6f90e763dp-5,
+    0x1.832efep0,
+  },
+  { // Entry 268
+    -0x1.ff20d9d3e8984fec33982e42f5884f2cp-1,
+    0x1.ddd171a3c9851e7819b5e4f6f90e763dp-5,
+    -0x1.832efep0,
+  },
+  { // Entry 269
+    0x1.fff18f03a4b7e6aacf51f83931e85042p-1,
+    -0x1.e668cb154eea68bbc7f8154f46b2e536p-7,
+    0x1.95ec90p0,
+  },
+  { // Entry 270
+    -0x1.fff18f03a4b7e6aacf51f83931e85042p-1,
+    -0x1.e668cb154eea68bbc7f8154f46b2e536p-7,
+    -0x1.95ec90p0,
+  },
+  { // Entry 271
+    0x1.fe043f875c6ed4a2c1b8d69a09fcf578p-1,
+    -0x1.682f2bb87a8f5011735094176c9b6dacp-4,
+    0x1.a8aa1cp0,
+  },
+  { // Entry 272
+    -0x1.fe043f875c6ed4a2c1b8d69a09fcf578p-1,
+    -0x1.682f2bb87a8f5011735094176c9b6dacp-4,
+    -0x1.a8aa1cp0,
+  },
+  { // Entry 273
+    0x1.b3d36a96880cf69d9884a49f5381e917p-1,
+    0x1.0cb3449a0d0a9e0643d41f4a5b0f7db7p-1,
+    0x1.04aff8p0,
+  },
+  { // Entry 274
+    -0x1.b3d36a96880cf69d9884a49f5381e917p-1,
+    0x1.0cb3449a0d0a9e0643d41f4a5b0f7db7p-1,
+    -0x1.04aff8p0,
+  },
+  { // Entry 275
+    0x1.b3d41aebcf391c30c3d2f1ee7b79710cp-1,
+    0x1.0cb22697153bcf1f8a63acddd96c54cbp-1,
+    0x1.04b0a0p0,
+  },
+  { // Entry 276
+    -0x1.b3d41aebcf391c30c3d2f1ee7b79710cp-1,
+    0x1.0cb22697153bcf1f8a63acddd96c54cbp-1,
+    -0x1.04b0a0p0,
+  },
+  { // Entry 277
+    0x1.b3d4cb405ab3292be7df5b1b98032fbep-1,
+    0x1.0cb10893a9b5471a44356072cb33b395p-1,
+    0x1.04b148p0,
+  },
+  { // Entry 278
+    -0x1.b3d4cb405ab3292be7df5b1b98032fbep-1,
+    0x1.0cb10893a9b5471a44356072cb33b395p-1,
+    -0x1.04b148p0,
+  },
+  { // Entry 279
+    0x1.b3d57b942a7ad19e9b9892c9319e1be6p-1,
+    0x1.0cafea8fca7781236a57e5b1c8aed39cp-1,
+    0x1.04b1f0p0,
+  },
+  { // Entry 280
+    -0x1.b3d57b942a7ad19e9b9892c9319e1be6p-1,
+    0x1.0cafea8fca7781236a57e5b1c8aed39cp-1,
+    -0x1.04b1f0p0,
+  },
+  { // Entry 281
+    0x1.b3d62be73e8fc998c6c2df6590425613p-1,
+    0x1.0caecc8b7782f86827af92b0b2374510p-1,
+    0x1.04b298p0,
+  },
+  { // Entry 282
+    -0x1.b3d62be73e8fc998c6c2df6590425613p-1,
+    0x1.0caecc8b7782f86827af92b0b2374510p-1,
+    -0x1.04b298p0,
+  },
+  { // Entry 283
+    0x1.b3d6dc3996f1c52aa1f83bdee1d0e023p-1,
+    0x1.0cadae86b0d82815d8f632e67c7e1a99p-1,
+    0x1.04b340p0,
+  },
+  { // Entry 284
+    -0x1.b3d6dc3996f1c52aa1f83bdee1d0e023p-1,
+    0x1.0cadae86b0d82815d8f632e67c7e1a99p-1,
+    -0x1.04b340p0,
+  },
+  { // Entry 285
+    0x1.b3d78c8b33a07864b6a878573db34bcap-1,
+    0x1.0cac908176778b5a0cbad21ee75ce765p-1,
+    0x1.04b3e8p0,
+  },
+  { // Entry 286
+    -0x1.b3d78c8b33a07864b6a878573db34bcap-1,
+    0x1.0cac908176778b5a0cbad21ee75ce765p-1,
+    -0x1.04b3e8p0,
+  },
+  { // Entry 287
+    0x1.b3d83cdc149b9757df195ad885ab5201p-1,
+    0x1.0cab727bc8619d628361876e1f30a633p-1,
+    0x1.04b490p0,
+  },
+  { // Entry 288
+    -0x1.b3d83cdc149b9757df195ad885ab5201p-1,
+    0x1.0cab727bc8619d628361876e1f30a633p-1,
+    -0x1.04b490p0,
+  },
+  { // Entry 289
+    0x1.b3d8e8f9908360b38cd13fcbf6224d93p-1,
+    0x1.0caa5b450a4324f204a556b072da124ap-1,
+    0x1.04b534p0,
+  },
+  { // Entry 290
+    -0x1.b3d8e8f9908360b38cd13fcbf6224d93p-1,
+    0x1.0caa5b450a4324f204a556b072da124ap-1,
+    -0x1.04b534p0,
+  },
+  { // Entry 291
+    -0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149,
+  },
+  { // Entry 292
+    0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149,
+  },
+  { // Entry 293
+    0.0,
+    0x1.p0,
+    0.0,
+  },
+  { // Entry 294
+    0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149,
+  },
+  { // Entry 295
+    -0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149,
+  },
+  { // Entry 296
+    0x1.1773d36a64df61d6715e60af063559f4p-1,
+    0x1.ad02c8b9cc93f448ef4eb068a88922a3p-1,
+    0x1.279a72p-1,
+  },
+  { // Entry 297
+    -0x1.1773d36a64df61d6715e60af063559f4p-1,
+    0x1.ad02c8b9cc93f448ef4eb068a88922a3p-1,
+    -0x1.279a72p-1,
+  },
+  { // Entry 298
+    0x1.1773d51767a78fe91b55f6b7e5fd44c2p-1,
+    0x1.ad02c7a258bfb362abbe86fb48f4e98bp-1,
+    0x1.279a74p-1,
+  },
+  { // Entry 299
+    -0x1.1773d51767a78fe91b55f6b7e5fd44c2p-1,
+    0x1.ad02c7a258bfb362abbe86fb48f4e98bp-1,
+    -0x1.279a74p-1,
+  },
+  { // Entry 300
+    0x1.1773d6c46a6ea687f03625194d25bb52p-1,
+    0x1.ad02c68ae4e9c579a08c04ce59be4002p-1,
+    0x1.279a76p-1,
+  },
+  { // Entry 301
+    -0x1.1773d6c46a6ea687f03625194d25bb52p-1,
+    0x1.ad02c68ae4e9c579a08c04ce59be4002p-1,
+    -0x1.279a76p-1,
+  },
+  { // Entry 302
+    0x1.f95b8f40501057ac49acef13993b0c55p-1,
+    -0x1.48d1c9e98b6c08784f10040f47a12191p-3,
+    0x1.bb67acp0,
+  },
+  { // Entry 303
+    -0x1.f95b8f40501057ac49acef13993b0c55p-1,
+    -0x1.48d1c9e98b6c08784f10040f47a12191p-3,
+    -0x1.bb67acp0,
+  },
+  { // Entry 304
+    0x1.f95b8e9be727702f7595ae1000a14a1ap-1,
+    -0x1.48d1d9b467e37955337311decd09fc74p-3,
+    0x1.bb67aep0,
+  },
+  { // Entry 305
+    -0x1.f95b8e9be727702f7595ae1000a14a1ap-1,
+    -0x1.48d1d9b467e37955337311decd09fc74p-3,
+    -0x1.bb67aep0,
+  },
+  { // Entry 306
+    0x1.f95b8df77e36a344670ed07149191a58p-1,
+    -0x1.48d1e97f4455c6eab1048022238b2bd0p-3,
+    0x1.bb67b0p0,
+  },
+  { // Entry 307
+    -0x1.f95b8df77e36a344670ed07149191a58p-1,
+    -0x1.48d1e97f4455c6eab1048022238b2bd0p-3,
+    -0x1.bb67b0p0,
+  },
+  { // Entry 308
+    0x1.b1d82e835a918de18f5fdadc8b1240cfp-2,
+    0x1.cfc6d011a0e5d0fcebb54b5fed672940p-1,
+    0x1.bffffep-2,
+  },
+  { // Entry 309
+    -0x1.b1d82e835a918de18f5fdadc8b1240cfp-2,
+    0x1.cfc6d011a0e5d0fcebb54b5fed672940p-1,
+    -0x1.bffffep-2,
+  },
+  { // Entry 310
+    0x1.b1d83053216169476f4d1982b9b14ab1p-2,
+    0x1.cfc6cfa52ad9f62d6d5423ca8339a00ap-1,
+    0x1.c0p-2,
+  },
+  { // Entry 311
+    -0x1.b1d83053216169476f4d1982b9b14ab1p-2,
+    0x1.cfc6cfa52ad9f62d6d5423ca8339a00ap-1,
+    -0x1.c0p-2,
+  },
+  { // Entry 312
+    0x1.b1d83222e830d83743258fd09040ee56p-2,
+    0x1.cfc6cf38b4cda76c3b09b17e9deb19eap-1,
+    0x1.c00002p-2,
+  },
+  { // Entry 313
+    -0x1.b1d83222e830d83743258fd09040ee56p-2,
+    0x1.cfc6cf38b4cda76c3b09b17e9deb19eap-1,
+    -0x1.c00002p-2,
+  },
+  { // Entry 314
+    0x1.44eb3691428062b27925c585ad59d62ap-1,
+    0x1.8bb106eac7c75d33fbb19446313ecc2fp-1,
+    0x1.5ffffep-1,
+  },
+  { // Entry 315
+    -0x1.44eb3691428062b27925c585ad59d62ap-1,
+    0x1.8bb106eac7c75d33fbb19446313ecc2fp-1,
+    -0x1.5ffffep-1,
+  },
+  { // Entry 316
+    0x1.44eb381cf386ab04a4f8656abea80b83p-1,
+    0x1.8bb105a5dc900618f80fa51d303c69p-1,
+    0x1.60p-1,
+  },
+  { // Entry 317
+    -0x1.44eb381cf386ab04a4f8656abea80b83p-1,
+    0x1.8bb105a5dc900618f80fa51d303c69p-1,
+    -0x1.60p-1,
+  },
+  { // Entry 318
+    0x1.44eb39a8a48bae6b98ae11c9400535e5p-1,
+    0x1.8bb10460f157234ceec7d9644a1a78e5p-1,
+    0x1.600002p-1,
+  },
+  { // Entry 319
+    -0x1.44eb39a8a48bae6b98ae11c9400535e5p-1,
+    0x1.8bb10460f157234ceec7d9644a1a78e5p-1,
+    -0x1.600002p-1,
+  },
+  { // Entry 320
+    0x1.dad9017b96408c375d4faf0e4776d1fcp-1,
+    0x1.7ef48b9a6fd5c24f5ec39839e1729b78p-2,
+    0x1.2ffffep0,
+  },
+  { // Entry 321
+    -0x1.dad9017b96408c375d4faf0e4776d1fcp-1,
+    0x1.7ef48b9a6fd5c24f5ec39839e1729b78p-2,
+    -0x1.2ffffep0,
+  },
+  { // Entry 322
+    0x1.dad902fa8ac870f52f1b843ac83bc3edp-1,
+    0x1.7ef4842f0bccd60d4a501dc8bc4b57b3p-2,
+    0x1.30p0,
+  },
+  { // Entry 323
+    -0x1.dad902fa8ac870f52f1b843ac83bc3edp-1,
+    0x1.7ef4842f0bccd60d4a501dc8bc4b57b3p-2,
+    -0x1.30p0,
+  },
+  { // Entry 324
+    0x1.dad904797f48ea4ef4fd2e47fe4d52bdp-1,
+    0x1.7ef47cc3a7bdedf9252074263d8a4596p-2,
+    0x1.300002p0,
+  },
+  { // Entry 325
+    -0x1.dad904797f48ea4ef4fd2e47fe4d52bdp-1,
+    0x1.7ef47cc3a7bdedf9252074263d8a4596p-2,
+    -0x1.300002p0,
+  },
+  { // Entry 326
+    0x1.4b708093c9cb45355e7821e5aad98ce8p-1,
+    -0x1.863ef5085bcc358d2ae8525bf39f0c40p-1,
+    0x1.37fffep1,
+  },
+  { // Entry 327
+    -0x1.4b708093c9cb45355e7821e5aad98ce8p-1,
+    -0x1.863ef5085bcc358d2ae8525bf39f0c40p-1,
+    -0x1.37fffep1,
+  },
+  { // Entry 328
+    0x1.4b707a7acdecc84239463e78b312fa10p-1,
+    -0x1.863efa361dc252bca1eaeed39749bed7p-1,
+    0x1.38p1,
+  },
+  { // Entry 329
+    -0x1.4b707a7acdecc84239463e78b312fa10p-1,
+    -0x1.863efa361dc252bca1eaeed39749bed7p-1,
+    -0x1.38p1,
+  },
+  { // Entry 330
+    0x1.4b707461d1f994476c677c5ad5ddb264p-1,
+    -0x1.863eff63dfa00bfc758baf469469d741p-1,
+    0x1.380002p1,
+  },
+  { // Entry 331
+    -0x1.4b707461d1f994476c677c5ad5ddb264p-1,
+    -0x1.863eff63dfa00bfc758baf469469d741p-1,
+    -0x1.380002p1,
+  },
+  { // Entry 332
+    0x1.066e7f705a6ca2b9e107f7dc9f3b26e6p-4,
+    0x1.fef2b2d0a10e2739c566936480a1479bp-1,
+    0x1.069c8cp-4,
+  },
+  { // Entry 333
+    -0x1.066e7f705a6ca2b9e107f7dc9f3b26e6p-4,
+    0x1.fef2b2d0a10e2739c566936480a1479bp-1,
+    -0x1.069c8cp-4,
+  },
+  { // Entry 334
+    0x1.05e476d27febc8b7e9690009b367c327p-3,
+    0x1.fbcbe68dd10bad0a229ccbb580cc5436p-1,
+    0x1.069c8cp-3,
+  },
+  { // Entry 335
+    -0x1.05e476d27febc8b7e9690009b367c327p-3,
+    0x1.fbcbe68dd10bad0a229ccbb580cc5436p-1,
+    -0x1.069c8cp-3,
+  },
+  { // Entry 336
+    0x1.877e2de5c9a066b8db595adc149af0c0p-3,
+    0x1.f68eebef72e7f6126b3f3dde646a755cp-1,
+    0x1.89ead2p-3,
+  },
+  { // Entry 337
+    -0x1.877e2de5c9a066b8db595adc149af0c0p-3,
+    0x1.f68eebef72e7f6126b3f3dde646a755cp-1,
+    -0x1.89ead2p-3,
+  },
+  { // Entry 338
+    0x1.03be07acb9dab719b4343a33b9fa6afep-2,
+    0x1.ef41459d2e90ea1b7faad7fabd1fd444p-1,
+    0x1.069c8cp-2,
+  },
+  { // Entry 339
+    -0x1.03be07acb9dab719b4343a33b9fa6afep-2,
+    0x1.ef41459d2e90ea1b7faad7fabd1fd444p-1,
+    -0x1.069c8cp-2,
+  },
+  { // Entry 340
+    0x1.42abbc5b3b2f91e8ece46e5effd28369p-2,
+    0x1.e5eaa23a27fe8d6890a3edace1c61998p-1,
+    0x1.4843b0p-2,
+  },
+  { // Entry 341
+    -0x1.42abbc5b3b2f91e8ece46e5effd28369p-2,
+    0x1.e5eaa23a27fe8d6890a3edace1c61998p-1,
+    -0x1.4843b0p-2,
+  },
+  { // Entry 342
+    0x1.804601411d93f4750919670061de07d9p-2,
+    0x1.da94d4b99c3a9a5e0d1fc86d53369a84p-1,
+    0x1.89ead4p-2,
+  },
+  { // Entry 343
+    -0x1.804601411d93f4750919670061de07d9p-2,
+    0x1.da94d4b99c3a9a5e0d1fc86d53369a84p-1,
+    -0x1.89ead4p-2,
+  },
+  { // Entry 344
+    0x1.bc4c08af356088b1694995bfaf8a297bp-2,
+    0x1.cd4bc9afc01230b2f982f6968dab7f05p-1,
+    0x1.cb91f8p-2,
+  },
+  { // Entry 345
+    -0x1.bc4c08af356088b1694995bfaf8a297bp-2,
+    0x1.cd4bc9afc01230b2f982f6968dab7f05p-1,
+    -0x1.cb91f8p-2,
+  },
+  { // Entry 346
+    0x1.f67eae34dc0b42b465fd2a3fb07564a4p-2,
+    0x1.be1d7adf077def2a360fec23dbbcef09p-1,
+    0x1.069c8ep-1,
+  },
+  { // Entry 347
+    -0x1.f67eae34dc0b42b465fd2a3fb07564a4p-2,
+    0x1.be1d7adf077def2a360fec23dbbcef09p-1,
+    -0x1.069c8ep-1,
+  },
+  { // Entry 348
+    0x1.17505c86231898fd86b18d2282d93eedp-1,
+    0x1.ad19e0847d25f3aa142289dab557bf96p-1,
+    0x1.277020p-1,
+  },
+  { // Entry 349
+    -0x1.17505c86231898fd86b18d2282d93eedp-1,
+    0x1.ad19e0847d25f3aa142289dab557bf96p-1,
+    -0x1.277020p-1,
+  },
+  { // Entry 350
+    0x1.323b8e40d16575e50dc7b6e567bb5084p-1,
+    0x1.9a52e08b191bd55512c8365074f1987fp-1,
+    0x1.4843b2p-1,
+  },
+  { // Entry 351
+    -0x1.323b8e40d16575e50dc7b6e567bb5084p-1,
+    0x1.9a52e08b191bd55512c8365074f1987fp-1,
+    -0x1.4843b2p-1,
+  },
+  { // Entry 352
+    0x1.4be49b08a1e1629cbdaa507e18255cd8p-1,
+    0x1.85dc3bb7c2e9abb5cccb6d96d12d39c4p-1,
+    0x1.691744p-1,
+  },
+  { // Entry 353
+    -0x1.4be49b08a1e1629cbdaa507e18255cd8p-1,
+    0x1.85dc3bb7c2e9abb5cccb6d96d12d39c4p-1,
+    -0x1.691744p-1,
+  },
+  { // Entry 354
+    0x1.6430847dbbbfd46cbebbc6d5f51c7c49p-1,
+    0x1.6fcb78e1cd65d2e4fde7118caac79d6dp-1,
+    0x1.89ead6p-1,
+  },
+  { // Entry 355
+    -0x1.6430847dbbbfd46cbebbc6d5f51c7c49p-1,
+    0x1.6fcb78e1cd65d2e4fde7118caac79d6dp-1,
+    -0x1.89ead6p-1,
+  },
+  { // Entry 356
+    0x1.7b05bb87b38844e56003c41ef804b273p-1,
+    0x1.5837ce4dc835d4a5454ec0a1bb394081p-1,
+    0x1.aabe68p-1,
+  },
+  { // Entry 357
+    -0x1.7b05bb87b38844e56003c41ef804b273p-1,
+    0x1.5837ce4dc835d4a5454ec0a1bb394081p-1,
+    -0x1.aabe68p-1,
+  },
+  { // Entry 358
+    0x1.904c3b389d55d3deddb39d05eb366571p-1,
+    0x1.3f3a09427966e9518802dee3bf443a95p-1,
+    0x1.cb91fap-1,
+  },
+  { // Entry 359
+    -0x1.904c3b389d55d3deddb39d05eb366571p-1,
+    0x1.3f3a09427966e9518802dee3bf443a95p-1,
+    -0x1.cb91fap-1,
+  },
+  { // Entry 360
+    0x1.a3eda211798a82697d62431f9ae46cc4p-1,
+    0x1.24ec73f1aeef4940bb8da19a82bbc49fp-1,
+    0x1.ec658cp-1,
+  },
+  { // Entry 361
+    -0x1.a3eda211798a82697d62431f9ae46cc4p-1,
+    0x1.24ec73f1aeef4940bb8da19a82bbc49fp-1,
+    -0x1.ec658cp-1,
+  },
+  { // Entry 362
+    0x1.b5d54883fcb6123bc28aac91f085e4eep-1,
+    0x1.096abb862f9bd5515982c2818c332ff9p-1,
+    0x1.069c8ep0,
+  },
+  { // Entry 363
+    -0x1.b5d54883fcb6123bc28aac91f085e4eep-1,
+    0x1.096abb862f9bd5515982c2818c332ff9p-1,
+    -0x1.069c8ep0,
+  },
+  { // Entry 364
+    0x1.c5f05a0135d4882c768cdf18e2e1112cp-1,
+    0x1.d9a39c0dddc654c717e3036da5dd685cp-2,
+    0x1.170656p0,
+  },
+  { // Entry 365
+    -0x1.c5f05a0135d4882c768cdf18e2e1112cp-1,
+    0x1.d9a39c0dddc654c717e3036da5dd685cp-2,
+    -0x1.170656p0,
+  },
+  { // Entry 366
+    0x1.d42de53e315c839ce188e201205e99dep-1,
+    0x1.9e7f81840c0bbd0f1b13733061062d34p-2,
+    0x1.27701ep0,
+  },
+  { // Entry 367
+    -0x1.d42de53e315c839ce188e201205e99dep-1,
+    0x1.9e7f81840c0bbd0f1b13733061062d34p-2,
+    -0x1.27701ep0,
+  },
+  { // Entry 368
+    0x1.e07eef45d91eea8a6cc7369aa0e55388p-1,
+    0x1.61a75e2deb596731c8cd45e3d9794526p-2,
+    0x1.37d9e6p0,
+  },
+  { // Entry 369
+    -0x1.e07eef45d91eea8a6cc7369aa0e55388p-1,
+    0x1.61a75e2deb596731c8cd45e3d9794526p-2,
+    -0x1.37d9e6p0,
+  },
+  { // Entry 370
+    0x1.ead6833b2aa002baa1c2b19a38dc9b79p-1,
+    0x1.235b337b091cdd8ac06390abc6816b82p-2,
+    0x1.4843aep0,
+  },
+  { // Entry 371
+    -0x1.ead6833b2aa002baa1c2b19a38dc9b79p-1,
+    0x1.235b337b091cdd8ac06390abc6816b82p-2,
+    -0x1.4843aep0,
+  },
+  { // Entry 372
+    0x1.f329bffa6a208591eecb6905d7594e3bp-1,
+    0x1.c7b9146d6d10824ff652dc390ba2d7f9p-3,
+    0x1.58ad76p0,
+  },
+  { // Entry 373
+    -0x1.f329bffa6a208591eecb6905d7594e3bp-1,
+    0x1.c7b9146d6d10824ff652dc390ba2d7f9p-3,
+    -0x1.58ad76p0,
+  },
+  { // Entry 374
+    0x1.f96fe38afbd95b5fcd08608110e9381fp-1,
+    0x1.46dc5b2f1de977efff7c278b5adb2a75p-3,
+    0x1.69173ep0,
+  },
+  { // Entry 375
+    -0x1.f96fe38afbd95b5fcd08608110e9381fp-1,
+    0x1.46dc5b2f1de977efff7c278b5adb2a75p-3,
+    -0x1.69173ep0,
+  },
+  { // Entry 376
+    0x1.fda25455d9567772f20f25d15efc6775p-1,
+    0x1.894f93ef49c4575800bbd646a3a31d2ap-4,
+    0x1.798106p0,
+  },
+  { // Entry 377
+    -0x1.fda25455d9567772f20f25d15efc6775p-1,
+    0x1.894f93ef49c4575800bbd646a3a31d2ap-4,
+    -0x1.798106p0,
+  },
+  { // Entry 378
+    0x1.ffbca816f1f1516ec5d757b0db54ae34p-1,
+    0x1.069164e3f5cee94d865fb52e316dff6bp-5,
+    0x1.89eacep0,
+  },
+  { // Entry 379
+    -0x1.ffbca816f1f1516ec5d757b0db54ae34p-1,
+    0x1.069164e3f5cee94d865fb52e316dff6bp-5,
+    -0x1.89eacep0,
+  },
+  { // Entry 380
+    0x1.ffbca88228b163189ab8d637db99bd2dp-1,
+    -0x1.069093eec0ed066ec83dd034498ef8bfp-5,
+    0x1.9a5496p0,
+  },
+  { // Entry 381
+    -0x1.ffbca88228b163189ab8d637db99bd2dp-1,
+    -0x1.069093eec0ed066ec83dd034498ef8bfp-5,
+    -0x1.9a5496p0,
+  },
+  { // Entry 382
+    0x1.fda255970ccddb9d127ecf63403c2bf7p-1,
+    -0x1.894f2be2979dd9ced83ccc60cf49cd44p-4,
+    0x1.aabe5ep0,
+  },
+  { // Entry 383
+    -0x1.fda255970ccddb9d127ecf63403c2bf7p-1,
+    -0x1.894f2be2979dd9ced83ccc60cf49cd44p-4,
+    -0x1.aabe5ep0,
+  },
+  { // Entry 384
+    0x1.f96fe5a0da244489fb2f4b97b3e48757p-1,
+    -0x1.46dc2796735195a15c80e5b719e2fc42p-3,
+    0x1.bb2826p0,
+  },
+  { // Entry 385
+    -0x1.f96fe5a0da244489fb2f4b97b3e48757p-1,
+    -0x1.46dc2796735195a15c80e5b719e2fc42p-3,
+    -0x1.bb2826p0,
+  },
+  { // Entry 386
+    0x1.f329c2e2c1a39bad8ecdcb87961ba44ap-1,
+    -0x1.c7b8e178b7e8c01d9f320466cc7a68d4p-3,
+    0x1.cb91eep0,
+  },
+  { // Entry 387
+    -0x1.f329c2e2c1a39bad8ecdcb87961ba44ap-1,
+    -0x1.c7b8e178b7e8c01d9f320466cc7a68d4p-3,
+    -0x1.cb91eep0,
+  },
+  { // Entry 388
+    0x1.ead686f2ec572c83ed34a01f764d193ep-1,
+    -0x1.235b1a6d767e4b362c64571ac97b4a1cp-2,
+    0x1.dbfbb6p0,
+  },
+  { // Entry 389
+    -0x1.ead686f2ec572c83ed34a01f764d193ep-1,
+    -0x1.235b1a6d767e4b362c64571ac97b4a1cp-2,
+    -0x1.dbfbb6p0,
+  },
+  { // Entry 390
+    0x1.e07ef3c91bd500a0de230ad573163163p-1,
+    -0x1.61a745a77b7e83c2f8a2f9b091e89aaap-2,
+    0x1.ec657ep0,
+  },
+  { // Entry 391
+    -0x1.e07ef3c91bd500a0de230ad573163163p-1,
+    -0x1.61a745a77b7e83c2f8a2f9b091e89aaap-2,
+    -0x1.ec657ep0,
+  },
+  { // Entry 392
+    0x1.d42dea8835c88adb9cde17347f934e25p-1,
+    -0x1.9e7f699e8b9aaf8ed51c71c8f73b0b74p-2,
+    0x1.fccf46p0,
+  },
+  { // Entry 393
+    -0x1.d42dea8835c88adb9cde17347f934e25p-1,
+    -0x1.9e7f699e8b9aaf8ed51c71c8f73b0b74p-2,
+    -0x1.fccf46p0,
+  },
+  { // Entry 394
+    0x1.c5f05e32c80fb0fe603033ec028a4c32p-1,
+    -0x1.d9a38bfa3195ba1caa7fb69bc1d04e42p-2,
+    0x1.069c88p1,
+  },
+  { // Entry 395
+    -0x1.c5f05e32c80fb0fe603033ec028a4c32p-1,
+    -0x1.d9a38bfa3195ba1caa7fb69bc1d04e42p-2,
+    -0x1.069c88p1,
+  },
+  { // Entry 396
+    0x1.b5d54d3732d3b2e79d4907e115401ddap-1,
+    -0x1.096ab3c55c91f36e2359ed1c5a8342dfp-1,
+    0x1.0ed16cp1,
+  },
+  { // Entry 397
+    -0x1.b5d54d3732d3b2e79d4907e115401ddap-1,
+    -0x1.096ab3c55c91f36e2359ed1c5a8342dfp-1,
+    -0x1.0ed16cp1,
+  },
+  { // Entry 398
+    0x1.a3eda74161d06b83ec2c8dc396d813b9p-1,
+    -0x1.24ec6c8206e744322d99f47e9e41becep-1,
+    0x1.170650p1,
+  },
+  { // Entry 399
+    -0x1.a3eda74161d06b83ec2c8dc396d813b9p-1,
+    -0x1.24ec6c8206e744322d99f47e9e41becep-1,
+    -0x1.170650p1,
+  },
+  { // Entry 400
+    0x1.904c421efce58f4e8170d36dcda8e02cp-1,
+    -0x1.3f3a009b82b5b8234e1296dd73cff49dp-1,
+    0x1.1f3b34p1,
+  },
+  { // Entry 401
+    -0x1.904c421efce58f4e8170d36dcda8e02cp-1,
+    -0x1.3f3a009b82b5b8234e1296dd73cff49dp-1,
+    -0x1.1f3b34p1,
+  },
+  { // Entry 402
+    0x1.7b05c45093944d6afb0c90d2f9cb217fp-1,
+    -0x1.5837c4a184ccf7ed57c189f2addf32c5p-1,
+    0x1.277018p1,
+  },
+  { // Entry 403
+    -0x1.7b05c45093944d6afb0c90d2f9cb217fp-1,
+    -0x1.5837c4a184ccf7ed57c189f2addf32c5p-1,
+    -0x1.277018p1,
+  },
+  { // Entry 404
+    0x1.64308f506ffdaf1326d10b3380278e98p-1,
+    -0x1.6fcb6e6685e72fb4074e70cd3162d3bap-1,
+    0x1.2fa4fcp1,
+  },
+  { // Entry 405
+    -0x1.64308f506ffdaf1326d10b3380278e98p-1,
+    -0x1.6fcb6e6685e72fb4074e70cd3162d3bap-1,
+    -0x1.2fa4fcp1,
+  },
+  { // Entry 406
+    0x1.4be4a8076c135a48f3f1a1aaa362475fp-1,
+    -0x1.85dc30a79f26754ab1370338ee7bfd11p-1,
+    0x1.37d9e0p1,
+  },
+  { // Entry 407
+    -0x1.4be4a8076c135a48f3f1a1aaa362475fp-1,
+    -0x1.85dc30a79f26754ab1370338ee7bfd11p-1,
+    -0x1.37d9e0p1,
+  },
+  { // Entry 408
+    0x1.323b9d888d4da77a610893735eeed1cbp-1,
+    -0x1.9a52d523b1532e4ed477e27dc6051c12p-1,
+    0x1.400ec4p1,
+  },
+  { // Entry 409
+    -0x1.323b9d888d4da77a610893735eeed1cbp-1,
+    -0x1.9a52d523b1532e4ed477e27dc6051c12p-1,
+    -0x1.400ec4p1,
+  },
+  { // Entry 410
+    0x1.17506e2dfb603d34b9af39b12c1db735p-1,
+    -0x1.ad19d50664abf0c0141137d2ca509f21p-1,
+    0x1.4843a8p1,
+  },
+  { // Entry 411
+    -0x1.17506e2dfb603d34b9af39b12c1db735p-1,
+    -0x1.ad19d50664abf0c0141137d2ca509f21p-1,
+    -0x1.4843a8p1,
+  },
+  { // Entry 412
+    0x1.f67ed667352d4827450013f15e321bfbp-2,
+    -0x1.be1d6f8d517db5c2cf7de0faf0808d30p-1,
+    0x1.50788cp1,
+  },
+  { // Entry 413
+    -0x1.f67ed667352d4827450013f15e321bfbp-2,
+    -0x1.be1d6f8d517db5c2cf7de0faf0808d30p-1,
+    -0x1.50788cp1,
+  },
+  { // Entry 414
+    0x1.bc4c35da51e34b776e5e04da58f23441p-2,
+    -0x1.cd4bbecf7f2705d4fd00dd463780f45ep-1,
+    0x1.58ad70p1,
+  },
+  { // Entry 415
+    -0x1.bc4c35da51e34b776e5e04da58f23441p-2,
+    -0x1.cd4bbecf7f2705d4fd00dd463780f45ep-1,
+    -0x1.58ad70p1,
+  },
+  { // Entry 416
+    0x1.8046336e68427cf756056d3f4edbb662p-2,
+    -0x1.da94ca915da3cdd1fff839d85eec39e2p-1,
+    0x1.60e254p1,
+  },
+  { // Entry 417
+    -0x1.8046336e68427cf756056d3f4edbb662p-2,
+    -0x1.da94ca915da3cdd1fff839d85eec39e2p-1,
+    -0x1.60e254p1,
+  },
+  { // Entry 418
+    0x1.42abf3872905e632f204c41b24af90b6p-2,
+    -0x1.e5ea99116b39361ac926dd9fdc2089d1p-1,
+    0x1.691738p1,
+  },
+  { // Entry 419
+    -0x1.42abf3872905e632f204c41b24af90b6p-2,
+    -0x1.e5ea99116b39361ac926dd9fdc2089d1p-1,
+    -0x1.691738p1,
+  },
+  { // Entry 420
+    0x1.03be43c699f3536990dcf5a6665ac239p-2,
+    -0x1.ef413dbbda2859ffb0d1ab84342fd235p-1,
+    0x1.714c1cp1,
+  },
+  { // Entry 421
+    -0x1.03be43c699f3536990dcf5a6665ac239p-2,
+    -0x1.ef413dbbda2859ffb0d1ab84342fd235p-1,
+    -0x1.714c1cp1,
+  },
+  { // Entry 422
+    0x1.877eadc2fdfc2f0db1e8b78cd3fbfbd2p-3,
+    -0x1.f68ee5b5bf356b10230944a18e70925cp-1,
+    0x1.7981p1,
+  },
+  { // Entry 423
+    -0x1.877eadc2fdfc2f0db1e8b78cd3fbfbd2p-3,
+    -0x1.f68ee5b5bf356b10230944a18e70925cp-1,
+    -0x1.7981p1,
+  },
+  { // Entry 424
+    0x1.05e4fdf846632a8208d90de72d3a6da8p-3,
+    -0x1.fbcbe23296fc61b96f382f35ea15c768p-1,
+    0x1.81b5e4p1,
+  },
+  { // Entry 425
+    -0x1.05e4fdf846632a8208d90de72d3a6da8p-3,
+    -0x1.fbcbe23296fc61b96f382f35ea15c768p-1,
+    -0x1.81b5e4p1,
+  },
+  { // Entry 426
+    0x1.066f9b630b72dff16450e89afdf7e048p-4,
+    -0x1.fef2b08943197cd3a8ba861095227c48p-1,
+    0x1.89eac8p1,
+  },
+  { // Entry 427
+    -0x1.066f9b630b72dff16450e89afdf7e048p-4,
+    -0x1.fef2b08943197cd3a8ba861095227c48p-1,
+    -0x1.89eac8p1,
+  },
+  { // Entry 428
+    0x1.03bdf0b79ccf739529d54d422861046cp-2,
+    0x1.ef41489fc2fe801a6fc8ae791438eb78p-1,
+    -0x1.81b5eep2,
+  },
+  { // Entry 429
+    -0x1.03bdf0b79ccf739529d54d422861046cp-2,
+    0x1.ef41489fc2fe801a6fc8ae791438eb78p-1,
+    0x1.81b5eep2,
+  },
+  { // Entry 430
+    0x1.f67e8b95f5460ea369a803837b721abdp-2,
+    0x1.be1d849ec649b797320e985d0b82ae85p-1,
+    -0x1.714c26p2,
+  },
+  { // Entry 431
+    -0x1.f67e8b95f5460ea369a803837b721abdp-2,
+    0x1.be1d849ec649b797320e985d0b82ae85p-1,
+    0x1.714c26p2,
+  },
+  { // Entry 432
+    0x1.643070791751dc0636d1854d2bdbc5d4p-1,
+    0x1.6fcb8c44bd30dd668148605969b1c161p-1,
+    -0x1.60e25ep2,
+  },
+  { // Entry 433
+    -0x1.643070791751dc0636d1854d2bdbc5d4p-1,
+    0x1.6fcb8c44bd30dd668148605969b1c161p-1,
+    0x1.60e25ep2,
+  },
+  { // Entry 434
+    0x1.b5d536f59113a43af30e8c9db8a951a5p-1,
+    0x1.096ad87c326622c42de34f92814cfa84p-1,
+    -0x1.507896p2,
+  },
+  { // Entry 435
+    -0x1.b5d536f59113a43af30e8c9db8a951a5p-1,
+    0x1.096ad87c326622c42de34f92814cfa84p-1,
+    0x1.507896p2,
+  },
+  { // Entry 436
+    0x1.ead679985549140318349f512dca7a6bp-1,
+    0x1.235b746a2a2eff2bf640dd8c04d35a5bp-2,
+    -0x1.400ecep2,
+  },
+  { // Entry 437
+    -0x1.ead679985549140318349f512dca7a6bp-1,
+    0x1.235b746a2a2eff2bf640dd8c04d35a5bp-2,
+    0x1.400ecep2,
+  },
+  { // Entry 438
+    0x1.ffbca7010e0b0452f56075cfd5982880p-1,
+    0x1.0693827b46cee3b661ac17114b5fe0fbp-5,
+    -0x1.2fa506p2,
+  },
+  { // Entry 439
+    -0x1.ffbca7010e0b0452f56075cfd5982880p-1,
+    0x1.0693827b46cee3b661ac17114b5fe0fbp-5,
+    0x1.2fa506p2,
+  },
+  { // Entry 440
+    0x1.f329ca6bfc7425d89c2b4b9ad73ab108p-1,
+    -0x1.c7b85d668e2abcc46542ca8527f0b801p-3,
+    -0x1.1f3b3ep2,
+  },
+  { // Entry 441
+    -0x1.f329ca6bfc7425d89c2b4b9ad73ab108p-1,
+    -0x1.c7b85d668e2abcc46542ca8527f0b801p-3,
+    0x1.1f3b3ep2,
+  },
+  { // Entry 442
+    0x1.c5f06fb69427ac0f2d69428d82b5e669p-1,
+    -0x1.d9a348d4f4363ba4562110db01ee84e8p-2,
+    -0x1.0ed176p2,
+  },
+  { // Entry 443
+    -0x1.c5f06fb69427ac0f2d69428d82b5e669p-1,
+    -0x1.d9a348d4f4363ba4562110db01ee84e8p-2,
+    0x1.0ed176p2,
+  },
+  { // Entry 444
+    0x1.7b05d864ec9802adbc4b5577c233836ap-1,
+    -0x1.5837ae8569c95846e6164d9636546120p-1,
+    -0x1.fccf5ap1,
+  },
+  { // Entry 445
+    -0x1.7b05d864ec9802adbc4b5577c233836ap-1,
+    -0x1.5837ae8569c95846e6164d9636546120p-1,
+    0x1.fccf5ap1,
+  },
+  { // Entry 446
+    0x1.1750808185a998bbcecc3a6ac0cb2907p-1,
+    -0x1.ad19c918883000b0b702ec080cf0122ep-1,
+    -0x1.dbfbc8p1,
+  },
+  { // Entry 447
+    -0x1.1750808185a998bbcecc3a6ac0cb2907p-1,
+    -0x1.ad19c918883000b0b702ec080cf0122ep-1,
+    0x1.dbfbc8p1,
+  },
+  { // Entry 448
+    0x1.42ac0dd9495211816bf04ca53bce4beap-2,
+    -0x1.e5ea94b2cf07add3d0d95ab3a30ad4abp-1,
+    -0x1.bb2836p1,
+  },
+  { // Entry 449
+    -0x1.42ac0dd9495211816bf04ca53bce4beap-2,
+    -0x1.e5ea94b2cf07add3d0d95ab3a30ad4abp-1,
+    0x1.bb2836p1,
+  },
+  { // Entry 450
+    0x1.066fca39a70b52d06f2cd7eab69c31f2p-4,
+    -0x1.fef2b02908559f92de892d240a2b0b49p-1,
+    -0x1.9a54a4p1,
+  },
+  { // Entry 451
+    -0x1.066fca39a70b52d06f2cd7eab69c31f2p-4,
+    -0x1.fef2b02908559f92de892d240a2b0b49p-1,
+    0x1.9a54a4p1,
+  },
+  { // Entry 452
+    -0x1.877d931298e6fbc654f065536cff2b54p-3,
+    -0x1.f68ef3792e592c3cefbce1d5ded64a92p-1,
+    -0x1.798112p1,
+  },
+  { // Entry 453
+    0x1.877d931298e6fbc654f065536cff2b54p-3,
+    -0x1.f68ef3792e592c3cefbce1d5ded64a92p-1,
+    0x1.798112p1,
+  },
+  { // Entry 454
+    -0x1.bc4bc2875eb6d38eda3b49cb2320b561p-2,
+    -0x1.cd4bda943eea13630f8e508f8744f2f2p-1,
+    -0x1.58ad80p1,
+  },
+  { // Entry 455
+    0x1.bc4bc2875eb6d38eda3b49cb2320b561p-2,
+    -0x1.cd4bda943eea13630f8e508f8744f2f2p-1,
+    0x1.58ad80p1,
+  },
+  { // Entry 456
+    -0x1.4be47d6354c4ced53780b1b519acdec2p-1,
+    -0x1.85dc54f49f324bdfc71d5749483b3318p-1,
+    -0x1.37d9eep1,
+  },
+  { // Entry 457
+    0x1.4be47d6354c4ced53780b1b519acdec2p-1,
+    -0x1.85dc54f49f324bdfc71d5749483b3318p-1,
+    0x1.37d9eep1,
+  },
+  { // Entry 458
+    -0x1.a3ed8bcb35cbcf8c6089f82a91c31d5bp-1,
+    -0x1.24ec93e04d4bdb54e20beaf383519af8p-1,
+    -0x1.17065cp1,
+  },
+  { // Entry 459
+    0x1.a3ed8bcb35cbcf8c6089f82a91c31d5bp-1,
+    -0x1.24ec93e04d4bdb54e20beaf383519af8p-1,
+    0x1.17065cp1,
+  },
+  { // Entry 460
+    -0x1.e07ee496ea109654c42e171fdc4537c4p-1,
+    -0x1.61a7983d4c16c451b68bf2f5b70f3b6ap-2,
+    -0x1.ec6594p0,
+  },
+  { // Entry 461
+    0x1.e07ee496ea109654c42e171fdc4537c4p-1,
+    -0x1.61a7983d4c16c451b68bf2f5b70f3b6ap-2,
+    0x1.ec6594p0,
+  },
+  { // Entry 462
+    -0x1.fda2522219689d0e8069d90f5c969b92p-1,
+    -0x1.89504a8de6c9ecac663e67583cab47e8p-4,
+    -0x1.aabe70p0,
+  },
+  { // Entry 463
+    0x1.fda2522219689d0e8069d90f5c969b92p-1,
+    -0x1.89504a8de6c9ecac663e67583cab47e8p-4,
+    0x1.aabe70p0,
+  },
+  { // Entry 464
+    -0x1.f96fe802fe570372d0fcb6e934b43061p-1,
+    0x1.46dbec9ea3a5f08ba73aa69e7e22de1cp-3,
+    -0x1.69174cp0,
+  },
+  { // Entry 465
+    0x1.f96fe802fe570372d0fcb6e934b43061p-1,
+    0x1.46dbec9ea3a5f08ba73aa69e7e22de1cp-3,
+    0x1.69174cp0,
+  },
+  { // Entry 466
+    -0x1.d42ded56ae88a6e1cf270af27e6f1804p-1,
+    0x1.9e7f5cf075d1ec4ef69c9c67b62c27cbp-2,
+    -0x1.277028p0,
+  },
+  { // Entry 467
+    0x1.d42ded56ae88a6e1cf270af27e6f1804p-1,
+    0x1.9e7f5cf075d1ec4ef69c9c67b62c27cbp-2,
+    0x1.277028p0,
+  },
+  { // Entry 468
+    -0x1.904c45326d6dde224381d1d590ada41cp-1,
+    0x1.3f39fcc017653d2636837a55fdf6d2d4p-1,
+    -0x1.cb920ap-1,
+  },
+  { // Entry 469
+    0x1.904c45326d6dde224381d1d590ada41cp-1,
+    0x1.3f39fcc017653d2636837a55fdf6d2d4p-1,
+    0x1.cb920ap-1,
+  },
+  { // Entry 470
+    -0x1.323b9cadbb19e75a44483fb64ad8ddf6p-1,
+    0x1.9a52d5c700daa3dc8cf8f5a71f2df289p-1,
+    -0x1.4843c4p-1,
+  },
+  { // Entry 471
+    0x1.323b9cadbb19e75a44483fb64ad8ddf6p-1,
+    0x1.9a52d5c700daa3dc8cf8f5a71f2df289p-1,
+    0x1.4843c4p-1,
+  },
+  { // Entry 472
+    -0x1.80462654bde766faf47f3140e290996dp-2,
+    0x1.da94cd383dd7a3b91a2fc88ff905a6a0p-1,
+    -0x1.89eafcp-2,
+  },
+  { // Entry 473
+    0x1.80462654bde766faf47f3140e290996dp-2,
+    0x1.da94cd383dd7a3b91a2fc88ff905a6a0p-1,
+    0x1.89eafcp-2,
+  },
+  { // Entry 474
+    -0x1.05e4ca21f386a82bc2e4efcdebb1962bp-3,
+    0x1.fbcbe3de58e66c3283bc810d16c45833p-1,
+    -0x1.069ce0p-3,
+  },
+  { // Entry 475
+    0x1.05e4ca21f386a82bc2e4efcdebb1962bp-3,
+    0x1.fbcbe3de58e66c3283bc810d16c45833p-1,
+    0x1.069ce0p-3,
+  },
+  { // Entry 476
+    0x1.05e423830be01f9fe3c57d06867e0056p-3,
+    0x1.fbcbe93d48563d51b6e9d6efdb62495cp-1,
+    0x1.069c38p-3,
+  },
+  { // Entry 477
+    -0x1.05e423830be01f9fe3c57d06867e0056p-3,
+    0x1.fbcbe93d48563d51b6e9d6efdb62495cp-1,
+    -0x1.069c38p-3,
+  },
+  { // Entry 478
+    0x1.8045d87852f1307fea6dc751c4d15992p-2,
+    0x1.da94dcfb1cd15853ce848ffb0264ad08p-1,
+    0x1.89eaa8p-2,
+  },
+  { // Entry 479
+    -0x1.8045d87852f1307fea6dc751c4d15992p-2,
+    0x1.da94dcfb1cd15853ce848ffb0264ad08p-1,
+    -0x1.89eaa8p-2,
+  },
+  { // Entry 480
+    0x1.323b7b04ee88cff98b2a1620e1f61a01p-1,
+    0x1.9a52eee5e35377d554ace881bdc4725bp-1,
+    0x1.48439ap-1,
+  },
+  { // Entry 481
+    -0x1.323b7b04ee88cff98b2a1620e1f61a01p-1,
+    0x1.9a52eee5e35377d554ace881bdc4725bp-1,
+    -0x1.48439ap-1,
+  },
+  { // Entry 482
+    0x1.904c2b02aa59528ce044bf2213c96859p-1,
+    0x1.3f3a1d9657ff6aa498c46f6faaf03b90p-1,
+    0x1.cb91e0p-1,
+  },
+  { // Entry 483
+    -0x1.904c2b02aa59528ce044bf2213c96859p-1,
+    0x1.3f3a1d9657ff6aa498c46f6faaf03b90p-1,
+    -0x1.cb91e0p-1,
+  },
+  { // Entry 484
+    0x1.d42ddd25b3797e6a679f76e05e6c3e08p-1,
+    0x1.9e7fa617a1a3a400a7f59aa879088e31p-2,
+    0x1.277014p0,
+  },
+  { // Entry 485
+    -0x1.d42ddd25b3797e6a679f76e05e6c3e08p-1,
+    0x1.9e7fa617a1a3a400a7f59aa879088e31p-2,
+    -0x1.277014p0,
+  },
+  { // Entry 486
+    0x1.f96fe1a0b12d0ad4fa8c82d8af989c5ap-1,
+    0x1.46dc8a919b27840cda6e18a079da459cp-3,
+    0x1.691738p0,
+  },
+  { // Entry 487
+    -0x1.f96fe1a0b12d0ad4fa8c82d8af989c5ap-1,
+    0x1.46dc8a919b27840cda6e18a079da459cp-3,
+    -0x1.691738p0,
+  },
+  { // Entry 488
+    0x1.fda255f96094d8fe4e859c4cf0dd68a5p-1,
+    -0x1.894f0c0872415663b7f9e4e4801deaf0p-4,
+    0x1.aabe5cp0,
+  },
+  { // Entry 489
+    -0x1.fda255f96094d8fe4e859c4cf0dd68a5p-1,
+    -0x1.894f0c0872415663b7f9e4e4801deaf0p-4,
+    -0x1.aabe5cp0,
+  },
+  { // Entry 490
+    0x1.e07ef267748b982778f8d50d2981bb3ap-1,
+    -0x1.61a74d29774ae4e3bc5533a2ea08a14ap-2,
+    0x1.ec6580p0,
+  },
+  { // Entry 491
+    -0x1.e07ef267748b982778f8d50d2981bb3ap-1,
+    -0x1.61a74d29774ae4e3bc5533a2ea08a14ap-2,
+    -0x1.ec6580p0,
+  },
+  { // Entry 492
+    0x1.a3eda2adb01143fb21453b20bd1748fep-1,
+    -0x1.24ec7311bd7b2255f9b890b3ff5899f4p-1,
+    0x1.170652p1,
+  },
+  { // Entry 493
+    -0x1.a3eda2adb01143fb21453b20bd1748fep-1,
+    -0x1.24ec7311bd7b2255f9b890b3ff5899f4p-1,
+    -0x1.170652p1,
+  },
+  { // Entry 494
+    0x1.4be49bd88a64a0bb414ddacac4fa8de9p-1,
+    -0x1.85dc3b06c435f524c873d9b5eba3def8p-1,
+    0x1.37d9e4p1,
+  },
+  { // Entry 495
+    -0x1.4be49bd88a64a0bb414ddacac4fa8de9p-1,
+    -0x1.85dc3b06c435f524c873d9b5eba3def8p-1,
+    -0x1.37d9e4p1,
+  },
+  { // Entry 496
+    0x1.bc4c0a9b3782e220ae55786369ccf190p-2,
+    -0x1.cd4bc93947e86671ac7f0eacd9521377p-1,
+    0x1.58ad76p1,
+  },
+  { // Entry 497
+    -0x1.bc4c0a9b3782e220ae55786369ccf190p-2,
+    -0x1.cd4bc93947e86671ac7f0eacd9521377p-1,
+    -0x1.58ad76p1,
+  },
+  { // Entry 498
+    0x1.877e301f43cafffe6644a8958f108729p-3,
+    -0x1.f68eebd3b8f12f9433e6d7224989c10ep-1,
+    0x1.798108p1,
+  },
+  { // Entry 499
+    -0x1.877e301f43cafffe6644a8958f108729p-3,
+    -0x1.f68eebd3b8f12f9433e6d7224989c10ep-1,
+    -0x1.798108p1,
+  },
+  { // Entry 500
+    -0x1.066e8ae1f824a69817e6a806e6317e28p-4,
+    -0x1.fef2b2b91e40021a2fee74fc61812157p-1,
+    0x1.9a549ap1,
+  },
+  { // Entry 501
+    0x1.066e8ae1f824a69817e6a806e6317e28p-4,
+    -0x1.fef2b2b91e40021a2fee74fc61812157p-1,
+    -0x1.9a549ap1,
+  },
+  { // Entry 502
+    -0x1.42abc1eca11a0ad12ca6eeff197318aap-2,
+    -0x1.e5eaa14d86168b69918c22f3716a67eap-1,
+    0x1.bb282cp1,
+  },
+  { // Entry 503
+    0x1.42abc1eca11a0ad12ca6eeff197318aap-2,
+    -0x1.e5eaa14d86168b69918c22f3716a67eap-1,
+    -0x1.bb282cp1,
+  },
+  { // Entry 504
+    -0x1.17505efb8119773c647468be1dfee45ep-1,
+    -0x1.ad19deead0eae2f72d04165e09e4a43dp-1,
+    0x1.dbfbbep1,
+  },
+  { // Entry 505
+    0x1.17505efb8119773c647468be1dfee45ep-1,
+    -0x1.ad19deead0eae2f72d04165e09e4a43dp-1,
+    -0x1.dbfbbep1,
+  },
+  { // Entry 506
+    -0x1.7b05bd8091cd79dff359c8412b0de1a9p-1,
+    -0x1.5837cc21dda44f3ab7fd96f57c014e19p-1,
+    0x1.fccf50p1,
+  },
+  { // Entry 507
+    0x1.7b05bd8091cd79dff359c8412b0de1a9p-1,
+    -0x1.5837cc21dda44f3ab7fd96f57c014e19p-1,
+    -0x1.fccf50p1,
+  },
+  { // Entry 508
+    -0x1.c5f05982eabf022748960961666d540dp-1,
+    -0x1.d9a39df207139f99ebe9b56dafb234b7p-2,
+    0x1.0ed170p2,
+  },
+  { // Entry 509
+    0x1.c5f05982eabf022748960961666d540dp-1,
+    -0x1.d9a39df207139f99ebe9b56dafb234b7p-2,
+    -0x1.0ed170p2,
+  },
+  { // Entry 510
+    -0x1.f329bfbda8122f83e3a1ea0242eb76aap-1,
+    -0x1.c7b9189638128bc0ae33fdf2729cc987p-3,
+    0x1.1f3b38p2,
+  },
+  { // Entry 511
+    0x1.f329bfbda8122f83e3a1ea0242eb76aap-1,
+    -0x1.c7b9189638128bc0ae33fdf2729cc987p-3,
+    -0x1.1f3b38p2,
+  },
+  { // Entry 512
+    -0x1.ffbca88ae90f0900b6d3ad89eddd2c80p-1,
+    0x1.069082e04b25e9d2ea9e263b50d08b34p-5,
+    0x1.2fa5p2,
+  },
+  { // Entry 513
+    0x1.ffbca88ae90f0900b6d3ad89eddd2c80p-1,
+    0x1.069082e04b25e9d2ea9e263b50d08b34p-5,
+    -0x1.2fa5p2,
+  },
+  { // Entry 514
+    -0x1.ead687409c95dcaf61af98513517f507p-1,
+    0x1.235b1861f21aa86dce259e4e5b4ef395p-2,
+    0x1.400ec8p2,
+  },
+  { // Entry 515
+    0x1.ead687409c95dcaf61af98513517f507p-1,
+    0x1.235b1861f21aa86dce259e4e5b4ef395p-2,
+    -0x1.400ec8p2,
+  },
+  { // Entry 516
+    -0x1.b5d54fd79372b90d5d4c7acf7adaed42p-1,
+    0x1.096aaf70341485062f443c80a90a3be3p-1,
+    0x1.507890p2,
+  },
+  { // Entry 517
+    0x1.b5d54fd79372b90d5d4c7acf7adaed42p-1,
+    0x1.096aaf70341485062f443c80a90a3be3p-1,
+    -0x1.507890p2,
+  },
+  { // Entry 518
+    -0x1.643092f42ae797375531420c005ca2cfp-1,
+    0x1.6fcb6ae03107be458d07361371efabb4p-1,
+    0x1.60e258p2,
+  },
+  { // Entry 519
+    0x1.643092f42ae797375531420c005ca2cfp-1,
+    0x1.6fcb6ae03107be458d07361371efabb4p-1,
+    -0x1.60e258p2,
+  },
+  { // Entry 520
+    -0x1.f67edf3b7bee8554d54d84ea83f6cb21p-2,
+    0x1.be1d6d10d5c8ceeb8bf9aeb7a9f690b9p-1,
+    0x1.714c20p2,
+  },
+  { // Entry 521
+    0x1.f67edf3b7bee8554d54d84ea83f6cb21p-2,
+    0x1.be1d6d10d5c8ceeb8bf9aeb7a9f690b9p-1,
+    -0x1.714c20p2,
+  },
+  { // Entry 522
+    -0x1.03be4d93d949325340b2f464201545a7p-2,
+    0x1.ef413c72d988bb53937975e4fd4fcc7ap-1,
+    0x1.81b5e8p2,
+  },
+  { // Entry 523
+    0x1.03be4d93d949325340b2f464201545a7p-2,
+    0x1.ef413c72d988bb53937975e4fd4fcc7ap-1,
+    -0x1.81b5e8p2,
+  },
+  { // Entry 524
+    0x1.efb26cfa20f2098ff7e9e42f0260eb01p-5,
+    0x1.ff0fd2cb5a9228cfa1e01605d0626c84p-1,
+    0x1.effffep-5,
+  },
+  { // Entry 525
+    -0x1.efb26cfa20f2098ff7e9e42f0260eb01p-5,
+    0x1.ff0fd2cb5a9228cfa1e01605d0626c84p-1,
+    -0x1.effffep-5,
+  },
+  { // Entry 526
+    0x1.efb26ef930c4d3f2b0dbe1931ba5ae64p-5,
+    0x1.ff0fd2c96adfbad5f904a71b2d210a2ap-1,
+    0x1.f0p-5,
+  },
+  { // Entry 527
+    -0x1.efb26ef930c4d3f2b0dbe1931ba5ae64p-5,
+    0x1.ff0fd2c96adfbad5f904a71b2d210a2ap-1,
+    -0x1.f0p-5,
+  },
+  { // Entry 528
+    0x1.efb270f840979c65b75ee5c67016a866p-5,
+    0x1.ff0fd2c77b2d4add40566ec5aa24fc6ep-1,
+    0x1.f00002p-5,
+  },
+  { // Entry 529
+    -0x1.efb270f840979c65b75ee5c67016a866p-5,
+    0x1.ff0fd2c77b2d4add40566ec5aa24fc6ep-1,
+    -0x1.f00002p-5,
+  },
+  { // Entry 530
+    0x1.f6baa816fce5ea5a60d8c9fd2a289380p-4,
+    0x1.fc21005d216a89de55b192096fc6b7bap-1,
+    0x1.f7fffep-4,
+  },
+  { // Entry 531
+    -0x1.f6baa816fce5ea5a60d8c9fd2a289380p-4,
+    0x1.fc21005d216a89de55b192096fc6b7bap-1,
+    -0x1.f7fffep-4,
+  },
+  { // Entry 532
+    0x1.f6baaa131de6438e5611279864fe7663p-4,
+    0x1.fc210055467fe58a20193399b3bc0dd2p-1,
+    0x1.f8p-4,
+  },
+  { // Entry 533
+    -0x1.f6baaa131de6438e5611279864fe7663p-4,
+    0x1.fc210055467fe58a20193399b3bc0dd2p-1,
+    -0x1.f8p-4,
+  },
+  { // Entry 534
+    0x1.f6baac0f3ee694e760a138bc06c8be3dp-4,
+    0x1.fc21004d6b953945667f800ff81de0ebp-1,
+    0x1.f80002p-4,
+  },
+  { // Entry 535
+    -0x1.f6baac0f3ee694e760a138bc06c8be3dp-4,
+    0x1.fc21004d6b953945667f800ff81de0ebp-1,
+    -0x1.f80002p-4,
+  },
+  { // Entry 536
+    0x1.4a8c395552fb432af31780e883c98f71p-3,
+    0x1.f94984c6fdf1be6168509ff1e35f62dep-1,
+    0x1.4bfffep-3,
+  },
+  { // Entry 537
+    -0x1.4a8c395552fb432af31780e883c98f71p-3,
+    0x1.f94984c6fdf1be6168509ff1e35f62dep-1,
+    -0x1.4bfffep-3,
+  },
+  { // Entry 538
+    0x1.4a8c3b4e9c7fffd48305f44a42f5f50fp-3,
+    0x1.f94984b2552e1941ec766c6a82ece4a3p-1,
+    0x1.4cp-3,
+  },
+  { // Entry 539
+    -0x1.4a8c3b4e9c7fffd48305f44a42f5f50fp-3,
+    0x1.f94984b2552e1941ec766c6a82ece4a3p-1,
+    -0x1.4cp-3,
+  },
+  { // Entry 540
+    0x1.4a8c3d47e604a7d54f3f7de402409e2cp-3,
+    0x1.f949849dac6a548dd851139041106316p-1,
+    0x1.4c0002p-3,
+  },
+  { // Entry 541
+    -0x1.4a8c3d47e604a7d54f3f7de402409e2cp-3,
+    0x1.f949849dac6a548dd851139041106316p-1,
+    -0x1.4c0002p-3,
+  },
+  { // Entry 542
+    0x1.2e9cd83630eb35c12efcfb8413583998p-2,
+    0x1.e921dd7054ef5d4f727d938ce10a053cp-1,
+    0x1.333332p-2,
+  },
+  { // Entry 543
+    -0x1.2e9cd83630eb35c12efcfb8413583998p-2,
+    0x1.e921dd7054ef5d4f727d938ce10a053cp-1,
+    -0x1.333332p-2,
+  },
+  { // Entry 544
+    0x1.2e9cda1f52c88042833f236ff0f9d486p-2,
+    0x1.e921dd24adb9129efc053f9acd4d2444p-1,
+    0x1.333334p-2,
+  },
+  { // Entry 545
+    -0x1.2e9cda1f52c88042833f236ff0f9d486p-2,
+    0x1.e921dd24adb9129efc053f9acd4d2444p-1,
+    -0x1.333334p-2,
+  },
+  { // Entry 546
+    0x1.2e9cdc0874a57f1ca0f976a9b01e4a71p-2,
+    0x1.e921dcd906824da60e43c03a7774b171p-1,
+    0x1.333336p-2,
+  },
+  { // Entry 547
+    -0x1.2e9cdc0874a57f1ca0f976a9b01e4a71p-2,
+    0x1.e921dcd906824da60e43c03a7774b171p-1,
+    -0x1.333336p-2,
+  },
+  { // Entry 548
+    0x1.3faefb2b68e6786eb692bd4e4045213ep-1,
+    0x1.8feedc92764bfbdcb41389e82063ed6ep-1,
+    0x1.594316p-1,
+  },
+  { // Entry 549
+    -0x1.3faefb2b68e6786eb692bd4e4045213ep-1,
+    0x1.8feedc92764bfbdcb41389e82063ed6ep-1,
+    -0x1.594316p-1,
+  },
+  { // Entry 550
+    0x1.3faefcbb57c26b0d84b63dbfb72b413bp-1,
+    0x1.8feedb52c750087c5f8727e0279e5f66p-1,
+    0x1.594318p-1,
+  },
+  { // Entry 551
+    -0x1.3faefcbb57c26b0d84b63dbfb72b413bp-1,
+    0x1.8feedb52c750087c5f8727e0279e5f66p-1,
+    -0x1.594318p-1,
+  },
+  { // Entry 552
+    0x1.3faefe4b469d1dfd561e666edda7c6e6p-1,
+    0x1.8feeda131852852d2fa7fe8847b05973p-1,
+    0x1.59431ap-1,
+  },
+  { // Entry 553
+    -0x1.3faefe4b469d1dfd561e666edda7c6e6p-1,
+    0x1.8feeda131852852d2fa7fe8847b05973p-1,
+    -0x1.59431ap-1,
+  },
+  { // Entry 554
+    0x1.6888a375ab228c1e031c4005769509f9p-1,
+    0x1.6b8991127859fd9b43ca1d08b92aa401p-1,
+    0x1.8ffffep-1,
+  },
+  { // Entry 555
+    -0x1.6888a375ab228c1e031c4005769509f9p-1,
+    0x1.6b8991127859fd9b43ca1d08b92aa401p-1,
+    -0x1.8ffffep-1,
+  },
+  { // Entry 556
+    0x1.6888a4e134b2ea520b226eca8694b3a2p-1,
+    0x1.6b898fa9efb5d22b58f0d99e9634931ap-1,
+    0x1.90p-1,
+  },
+  { // Entry 557
+    -0x1.6888a4e134b2ea520b226eca8694b3a2p-1,
+    0x1.6b898fa9efb5d22b58f0d99e9634931ap-1,
+    -0x1.90p-1,
+  },
+  { // Entry 558
+    0x1.6888a64cbe41dffd6e4768dcca4db53bp-1,
+    0x1.6b898e4167103b31de6da67ebf5e9fe6p-1,
+    0x1.900002p-1,
+  },
+  { // Entry 559
+    -0x1.6888a64cbe41dffd6e4768dcca4db53bp-1,
+    0x1.6b898e4167103b31de6da67ebf5e9fe6p-1,
+    -0x1.900002p-1,
+  },
+  { // Entry 560
+    -0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149,
+  },
+  { // Entry 561
+    0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149,
+  },
+  { // Entry 562
+    0.0,
+    0x1.p0,
+    0.0,
+  },
+  { // Entry 563
+    0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149,
+  },
+  { // Entry 564
+    -0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149,
+  },
+  { // Entry 565
+    0x1.91f65dccfead353d8db9c32f12262730p-5,
+    0x1.ff621e38956a3b3be920256ddb6034cdp-1,
+    0x1.921fb4p-5,
+  },
+  { // Entry 566
+    -0x1.91f65dccfead353d8db9c32f12262730p-5,
+    0x1.ff621e38956a3b3be920256ddb6034cdp-1,
+    -0x1.921fb4p-5,
+  },
+  { // Entry 567
+    0x1.91f65fcc60cb6d09fcc5c35dd6a798c8p-5,
+    0x1.ff621e370373dc6f3963d42896ede078p-1,
+    0x1.921fb6p-5,
+  },
+  { // Entry 568
+    -0x1.91f65fcc60cb6d09fcc5c35dd6a798c8p-5,
+    0x1.ff621e370373dc6f3963d42896ede078p-1,
+    -0x1.921fb6p-5,
+  },
+  { // Entry 569
+    0x1.91f661cbc2e9a3447571f72bcfbc21e2p-5,
+    0x1.ff621e35717d7ba327894bdfde9f4787p-1,
+    0x1.921fb8p-5,
+  },
+  { // Entry 570
+    -0x1.91f661cbc2e9a3447571f72bcfbc21e2p-5,
+    0x1.ff621e35717d7ba327894bdfde9f4787p-1,
+    -0x1.921fb8p-5,
+  },
+  { // Entry 571
+    0x1.917a6a7fe8297bf0a1125fb02b2038aep-4,
+    0x1.fd88da410b61cd55221d9beb996d4d99p-1,
+    0x1.921fb4p-4,
+  },
+  { // Entry 572
+    -0x1.917a6a7fe8297bf0a1125fb02b2038aep-4,
+    0x1.fd88da410b61cd55221d9beb996d4d99p-1,
+    -0x1.921fb4p-4,
+  },
+  { // Entry 573
+    0x1.917a6c7d7103b9d90e09615164449c6bp-4,
+    0x1.fd88da3ac5781f5a6fc32e40ed5122b0p-1,
+    0x1.921fb6p-4,
+  },
+  { // Entry 574
+    -0x1.917a6c7d7103b9d90e09615164449c6bp-4,
+    0x1.fd88da3ac5781f5a6fc32e40ed5122b0p-1,
+    -0x1.921fb6p-4,
+  },
+  { // Entry 575
+    0x1.917a6e7af9ddf17b914e6d2e8e83b33ep-4,
+    0x1.fd88da347f8e696999ffd58060ba3569p-1,
+    0x1.921fb8p-4,
+  },
+  { // Entry 576
+    -0x1.917a6e7af9ddf17b914e6d2e8e83b33ep-4,
+    0x1.fd88da347f8e696999ffd58060ba3569p-1,
+    -0x1.921fb8p-4,
+  },
+  { // Entry 577
+    0x1.8f8b82889296b5cf7904db1e74b3466bp-3,
+    0x1.f6297d0f4671da580dfecdd4db29f473p-1,
+    0x1.921fb4p-3,
+  },
+  { // Entry 578
+    -0x1.8f8b82889296b5cf7904db1e74b3466bp-3,
+    0x1.f6297d0f4671da580dfecdd4db29f473p-1,
+    -0x1.921fb4p-3,
+  },
+  { // Entry 579
+    0x1.8f8b847ebc13b8998ec5b37e7065341ep-3,
+    0x1.f6297cf64db9a21d98ab3940fc8a86f0p-1,
+    0x1.921fb6p-3,
+  },
+  { // Entry 580
+    -0x1.8f8b847ebc13b8998ec5b37e7065341ep-3,
+    0x1.f6297cf64db9a21d98ab3940fc8a86f0p-1,
+    -0x1.921fb6p-3,
+  },
+  { // Entry 581
+    0x1.8f8b8674e590a26aec3ea01d30aed486p-3,
+    0x1.f6297cdd55014a808b883fd183f318acp-1,
+    0x1.921fb8p-3,
+  },
+  { // Entry 582
+    -0x1.8f8b8674e590a26aec3ea01d30aed486p-3,
+    0x1.f6297cdd55014a808b883fd183f318acp-1,
+    -0x1.921fb8p-3,
+  },
+  { // Entry 583
+    0x1.87de293f569717a42a3bdb01aeae2063p-2,
+    0x1.d906bd313443007dcb0bd4e3d63284c0p-1,
+    0x1.921fb4p-2,
+  },
+  { // Entry 584
+    -0x1.87de293f569717a42a3bdb01aeae2063p-2,
+    0x1.d906bd313443007dcb0bd4e3d63284c0p-1,
+    -0x1.921fb4p-2,
+  },
+  { // Entry 585
+    0x1.87de2b185d5417dca800b85ca1319043p-2,
+    0x1.d906bccf3cb875874da3da4c01104bafp-1,
+    0x1.921fb6p-2,
+  },
+  { // Entry 586
+    -0x1.87de2b185d5417dca800b85ca1319043p-2,
+    0x1.d906bccf3cb875874da3da4c01104bafp-1,
+    -0x1.921fb6p-2,
+  },
+  { // Entry 587
+    0x1.87de2cf16410b61d9aff7e628fc853b2p-2,
+    0x1.d906bc6d452d744f210810861102f2dap-1,
+    0x1.921fb8p-2,
+  },
+  { // Entry 588
+    -0x1.87de2cf16410b61d9aff7e628fc853b2p-2,
+    0x1.d906bc6d452d744f210810861102f2dap-1,
+    -0x1.921fb8p-2,
+  },
+  { // Entry 589
+    0x1.6a09e582aa3945461b5a8a0787d5ab5bp-1,
+    0x1.6a09e74d3d3fbb94d94274f37769f6eap-1,
+    0x1.921fb4p-1,
+  },
+  { // Entry 590
+    -0x1.6a09e582aa3945461b5a8a0787d5ab5bp-1,
+    0x1.6a09e74d3d3fbb94d94274f37769f6eap-1,
+    -0x1.921fb4p-1,
+  },
+  { // Entry 591
+    0x1.6a09e6ecb41fdd7e681872c854887019p-1,
+    0x1.6a09e5e3335983e5ac92e733e3f24b42p-1,
+    0x1.921fb6p-1,
+  },
+  { // Entry 592
+    -0x1.6a09e6ecb41fdd7e681872c854887019p-1,
+    0x1.6a09e5e3335983e5ac92e733e3f24b42p-1,
+    -0x1.921fb6p-1,
+  },
+  { // Entry 593
+    0x1.6a09e856be050baccde9a76961e84aa7p-1,
+    0x1.6a09e4792971e22c9a00261aeac070dap-1,
+    0x1.921fb8p-1,
+  },
+  { // Entry 594
+    -0x1.6a09e856be050baccde9a76961e84aa7p-1,
+    0x1.6a09e4792971e22c9a00261aeac070dap-1,
+    -0x1.921fb8p-1,
+  },
+  { // Entry 595
+    0x1.fffffffffffe6546cc38211c26dabeebp-1,
+    0x1.4442d18469893610281a0f9b0e8d0eefp-24,
+    0x1.921fb4p0,
+  },
+  { // Entry 596
+    -0x1.fffffffffffe6546cc38211c26dabeebp-1,
+    0x1.4442d18469893610281a0f9b0e8d0eefp-24,
+    -0x1.921fb4p0,
+  },
+  { // Entry 597
+    0x1.ffffffffffff76521249c7422930ed82p-1,
+    -0x1.777a5cf72cecc4cde3a31e7d5a026142p-25,
+    0x1.921fb6p0,
+  },
+  { // Entry 598
+    -0x1.ffffffffffff76521249c7422930ed82p-1,
+    -0x1.777a5cf72cecc4cde3a31e7d5a026142p-25,
+    -0x1.921fb6p0,
+  },
+  { // Entry 599
+    0x1.fffffffffff8875d585b6d6cfce97d9cp-1,
+    -0x1.5dde973dcb3985f4a8e76a1feca29e1dp-23,
+    0x1.921fb8p0,
+  },
+  { // Entry 600
+    -0x1.fffffffffff8875d585b6d6cfce97d9cp-1,
+    -0x1.5dde973dcb3985f4a8e76a1feca29e1dp-23,
+    -0x1.921fb8p0,
+  },
+  { // Entry 601
+    0x1.4442d184698831f15b6315bfa6b5ae75p-23,
+    -0x1.fffffffffff9951b30e084732e60bb85p-1,
+    0x1.921fb4p1,
+  },
+  { // Entry 602
+    -0x1.4442d184698831f15b6315bfa6b5ae75p-23,
+    -0x1.fffffffffff9951b30e084732e60bb85p-1,
+    -0x1.921fb4p1,
+  },
+  { // Entry 603
+    -0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    -0x1.fffffffffffdd94849271d08eecf54a1p-1,
+    0x1.921fb6p1,
+  },
+  { // Entry 604
+    0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    -0x1.fffffffffffdd94849271d08eecf54a1p-1,
+    -0x1.921fb6p1,
+  },
+  { // Entry 605
+    -0x1.5dde973dcb346afa46203cddc6f7fe97p-22,
+    -0x1.ffffffffffe21d75616db5ebc56405f5p-1,
+    0x1.921fb8p1,
+  },
+  { // Entry 606
+    0x1.5dde973dcb346afa46203cddc6f7fe97p-22,
+    -0x1.ffffffffffe21d75616db5ebc56405f5p-1,
+    -0x1.921fb8p1,
+  },
+  { // Entry 607
+    -0x1.4442d1846984217628872e56eb58b4c1p-22,
+    0x1.ffffffffffe6546cc38211f5e8deeb97p-1,
+    0x1.921fb4p2,
+  },
+  { // Entry 608
+    0x1.4442d1846984217628872e56eb58b4c1p-22,
+    0x1.ffffffffffe6546cc38211f5e8deeb97p-1,
+    -0x1.921fb4p2,
+  },
+  { // Entry 609
+    0x1.777a5cf72ceacbf6ec657e977ef771f1p-23,
+    0x1.fffffffffff76521249c74285bf73c07p-1,
+    0x1.921fb6p2,
+  },
+  { // Entry 610
+    -0x1.777a5cf72ceacbf6ec657e977ef771f1p-23,
+    0x1.fffffffffff76521249c74285bf73c07p-1,
+    -0x1.921fb6p2,
+  },
+  { // Entry 611
+    0x1.5dde973dcb1fff10bb0388479e82f4bbp-21,
+    0x1.ffffffffff8875d585b6db2c31711004p-1,
+    0x1.921fb8p2,
+  },
+  { // Entry 612
+    -0x1.5dde973dcb1fff10bb0388479e82f4bbp-21,
+    0x1.ffffffffff8875d585b6db2c31711004p-1,
+    -0x1.921fb8p2,
+  },
+  { // Entry 613
+    -0x1.4442d1846973df895d1791023ded513cp-21,
+    0x1.ffffffffff9951b30e084a6a993b8675p-1,
+    0x1.921fb4p3,
+  },
+  { // Entry 614
+    0x1.4442d1846973df895d1791023ded513cp-21,
+    0x1.ffffffffff9951b30e084a6a993b8675p-1,
+    -0x1.921fb4p3,
+  },
+  { // Entry 615
+    0x1.777a5cf72ce47c7a3ba04bc2a607a9a7p-22,
+    0x1.ffffffffffdd94849271d0eb7b7b884bp-1,
+    0x1.921fb6p3,
+  },
+  { // Entry 616
+    -0x1.777a5cf72ce47c7a3ba04bc2a607a9a7p-22,
+    0x1.ffffffffffdd94849271d0eb7b7b884bp-1,
+    -0x1.921fb6p3,
+  },
+  { // Entry 617
+    0x1.5dde973dcace4f6a8e90bd15e00610f8p-20,
+    0x1.fffffffffe21d75616dba48283d3c2f7p-1,
+    0x1.921fb8p3,
+  },
+  { // Entry 618
+    -0x1.5dde973dcace4f6a8e90bd15e00610f8p-20,
+    0x1.fffffffffe21d75616dba48283d3c2f7p-1,
+    -0x1.921fb8p3,
+  },
+  { // Entry 619
+    -0x1.4442d1846932d7d62f59209388c7f7cap-20,
+    0x1.fffffffffe6546cc382152d9c0eb9b47p-1,
+    0x1.921fb4p4,
+  },
+  { // Entry 620
+    0x1.4442d1846932d7d62f59209388c7f7cap-20,
+    0x1.fffffffffe6546cc382152d9c0eb9b47p-1,
+    -0x1.921fb4p4,
+  },
+  { // Entry 621
+    0x1.777a5cf72ccb3e87788b811229e725bcp-21,
+    0x1.ffffffffff76521249c7484ea7d7a409p-1,
+    0x1.921fb6p4,
+  },
+  { // Entry 622
+    -0x1.777a5cf72ccb3e87788b811229e725bcp-21,
+    0x1.ffffffffff76521249c7484ea7d7a409p-1,
+    -0x1.921fb6p4,
+  },
+  { // Entry 623
+    0x1.5dde973dc98790d1dcc602bd1b86bccap-19,
+    0x1.fffffffff8875d585b720f25f0473943p-1,
+    0x1.921fb8p4,
+  },
+  { // Entry 624
+    -0x1.5dde973dc98790d1dcc602bd1b86bccap-19,
+    0x1.fffffffff8875d585b720f25f0473943p-1,
+    -0x1.921fb8p4,
+  },
+  { // Entry 625
+    -0x1.4442d184682eb909785fad18bcb5dbfcp-19,
+    0x1.fffffffff9951b30e087de5cc38683b8p-1,
+    0x1.921fb4p5,
+  },
+  { // Entry 626
+    0x1.4442d184682eb909785fad18bcb5dbfcp-19,
+    0x1.fffffffff9951b30e087de5cc38683b8p-1,
+    -0x1.921fb4p5,
+  },
+  { // Entry 627
+    0x1.777a5cf72c6646bc6c38607eb34eea13p-20,
+    0x1.fffffffffdd94849271d6b463df6bddfp-1,
+    0x1.921fb6p5,
+  },
+  { // Entry 628
+    -0x1.777a5cf72c6646bc6c38607eb34eea13p-20,
+    0x1.fffffffffdd94849271d6b463df6bddfp-1,
+    -0x1.921fb6p5,
+  },
+  { // Entry 629
+    0x1.5dde973dc46c966f15a2403d60cd14d0p-18,
+    0x1.ffffffffe21d75616e000e55d09f8757p-1,
+    0x1.921fb8p5,
+  },
+  { // Entry 630
+    -0x1.5dde973dc46c966f15a2403d60cd14d0p-18,
+    0x1.ffffffffe21d75616e000e55d09f8757p-1,
+    -0x1.921fb8p5,
+  },
+  { // Entry 631
+    -0x1.4442d184641e3dd69c7ec32e14a209a5p-18,
+    0x1.ffffffffe6546cc38248a8cf0b9b5795p-1,
+    0x1.921fb4p6,
+  },
+  { // Entry 632
+    0x1.4442d184641e3dd69c7ec32e14a209a5p-18,
+    0x1.ffffffffe6546cc38248a8cf0b9b5795p-1,
+    -0x1.921fb4p6,
+  },
+  { // Entry 633
+    0x1.777a5cf72ad267903aec8118778b3b5ap-19,
+    0x1.fffffffff76521249c7a4dd2e15dd1c4p-1,
+    0x1.921fb6p6,
+  },
+  { // Entry 634
+    -0x1.777a5cf72ad267903aec8118778b3b5ap-19,
+    0x1.fffffffff76521249c7a4dd2e15dd1c4p-1,
+    -0x1.921fb6p6,
+  },
+  { // Entry 635
+    0x1.5dde973db000ace3f985a473ea1fc039p-17,
+    0x1.ffffffff8875d585bb7d55383a9b39a4p-1,
+    0x1.921fb8p6,
+  },
+  { // Entry 636
+    -0x1.5dde973db000ace3f985a473ea1fc039p-17,
+    0x1.ffffffff8875d585bb7d55383a9b39a4p-1,
+    -0x1.921fb8p6,
+  },
+  { // Entry 637
+    -0x1.4442d18453dc510b2d495b8bf79bd1cep-17,
+    0x1.ffffffff9951b30e0bb598fc0679a6f7p-1,
+    0x1.921fb4p7,
+  },
+  { // Entry 638
+    0x1.4442d18453dc510b2d495b8bf79bd1cep-17,
+    0x1.ffffffff9951b30e0bb598fc0679a6f7p-1,
+    -0x1.921fb4p7,
+  },
+  { // Entry 639
+    0x1.777a5cf72482eadf75c731f972507718p-18,
+    0x1.ffffffffdd948492723342ea1da49bacp-1,
+    0x1.921fb6p7,
+  },
+  { // Entry 640
+    -0x1.777a5cf72482eadf75c731f972507718p-18,
+    0x1.ffffffffdd948492723342ea1da49bacp-1,
+    -0x1.921fb6p7,
+  },
+  { // Entry 641
+    0x1.5dde973d5e5106b7903a18a552aefc6ep-16,
+    0x1.fffffffe21d7561725c712f068fc9718p-1,
+    0x1.921fb8p7,
+  },
+  { // Entry 642
+    -0x1.5dde973d5e5106b7903a18a552aefc6ep-16,
+    0x1.fffffffe21d7561725c712f068fc9718p-1,
+    -0x1.921fb8p7,
+  },
+  { // Entry 643
+    0x1.6a09f1940b80c8e25cfc8c10d42576c6p-1,
+    -0x1.6a09db3bdba0868a31e766359a8406cap-1,
+    0x1.2d97c4p1,
+  },
+  { // Entry 644
+    -0x1.6a09f1940b80c8e25cfc8c10d42576c6p-1,
+    -0x1.6a09db3bdba0868a31e766359a8406cap-1,
+    -0x1.2d97c4p1,
+  },
+  { // Entry 645
+    0x1.6a09ebebe40889245d57c5c9d90a6d82p-1,
+    -0x1.6a09e0e4035b86694c16534e42fbe111p-1,
+    0x1.2d97c6p1,
+  },
+  { // Entry 646
+    -0x1.6a09ebebe40889245d57c5c9d90a6d82p-1,
+    -0x1.6a09e0e4035b86694c16534e42fbe111p-1,
+    -0x1.2d97c6p1,
+  },
+  { // Entry 647
+    0x1.6a09e643bc79a8c79ef4bf187727e269p-1,
+    -0x1.6a09e68c2affe5aa58050accb05c6248p-1,
+    0x1.2d97c8p1,
+  },
+  { // Entry 648
+    -0x1.6a09e643bc79a8c79ef4bf187727e269p-1,
+    -0x1.6a09e68c2affe5aa58050accb05c6248p-1,
+    -0x1.2d97c8p1,
+  },
+  { // Entry 649
+    -0x1.6a09df19704cf14108e09000ff6374bfp-1,
+    -0x1.6a09edb67706e0997121d12a0c87bae8p-1,
+    0x1.f6a7a0p1,
+  },
+  { // Entry 650
+    0x1.6a09df19704cf14108e09000ff6374bfp-1,
+    -0x1.6a09edb67706e0997121d12a0c87bae8p-1,
+    -0x1.f6a7a0p1,
+  },
+  { // Entry 651
+    -0x1.6a09e4c197f87ace1c81b43022be39b1p-1,
+    -0x1.6a09e80e4f7f2a88debed37faa93e8c8p-1,
+    0x1.f6a7a2p1,
+  },
+  { // Entry 652
+    0x1.6a09e4c197f87ace1c81b43022be39b1p-1,
+    -0x1.6a09e80e4f7f2a88debed37faa93e8c8p-1,
+    -0x1.f6a7a2p1,
+  },
+  { // Entry 653
+    -0x1.6a09ea69bf8d63bce40958f5c4b4f155p-1,
+    -0x1.6a09e26627e0d3d9cb76de00cb902becp-1,
+    0x1.f6a7a4p1,
+  },
+  { // Entry 654
+    0x1.6a09ea69bf8d63bce40958f5c4b4f155p-1,
+    -0x1.6a09e26627e0d3d9cb76de00cb902becp-1,
+    -0x1.f6a7a4p1,
+  },
+  { // Entry 655
+    -0x1.ffffffffff065cb240bb8f9519d2c6f1p-1,
+    -0x1.f9990e91a74168b90bd68dfab775c9cap-21,
+    0x1.2d97c4p2,
+  },
+  { // Entry 656
+    0x1.ffffffffff065cb240bb8f9519d2c6f1p-1,
+    -0x1.f9990e91a74168b90bd68dfab775c9cap-21,
+    -0x1.2d97c4p2,
+  },
+  { // Entry 657
+    -0x1.ffffffffffc32939898f464aafc2e74ap-1,
+    -0x1.f3321d234f1363d187dd09528b67b215p-22,
+    0x1.2d97c6p2,
+  },
+  { // Entry 658
+    0x1.ffffffffffc32939898f464aafc2e74ap-1,
+    -0x1.f3321d234f1363d187dd09528b67b215p-22,
+    -0x1.2d97c6p2,
+  },
+  { // Entry 659
+    -0x1.fffffffffffff5c0d2630ee0a1fb4e7bp-1,
+    0x1.99bc5b961b1acaca18d971f68ae99da9p-27,
+    0x1.2d97c8p2,
+  },
+  { // Entry 660
+    0x1.fffffffffffff5c0d2630ee0a1fb4e7bp-1,
+    0x1.99bc5b961b1acaca18d971f68ae99da9p-27,
+    -0x1.2d97c8p2,
+  },
+  { // Entry 661
+    -0x1.6a09f529316cde5a190d235cc4ccb825p-1,
+    0x1.6a09d7a6b572c2c824d137d0405d8188p-1,
+    0x1.5fdbbcp2,
+  },
+  { // Entry 662
+    0x1.6a09f529316cde5a190d235cc4ccb825p-1,
+    0x1.6a09d7a6b572c2c824d137d0405d8188p-1,
+    -0x1.5fdbbcp2,
+  },
+  { // Entry 663
+    -0x1.6a09e9d8e2826770567ea818b2e89960p-1,
+    0x1.6a09e2f704eecb181e3f5ece9be0ca0fp-1,
+    0x1.5fdbbep2,
+  },
+  { // Entry 664
+    0x1.6a09e9d8e2826770567ea818b2e89960p-1,
+    0x1.6a09e2f704eecb181e3f5ece9be0ca0fp-1,
+    -0x1.5fdbbep2,
+  },
+  { // Entry 665
+    -0x1.6a09de88933d6e0c1db78e1d7cd15173p-1,
+    0x1.6a09ee47541050ef59ec4bfce935cc1ap-1,
+    0x1.5fdbc0p2,
+  },
+  { // Entry 666
+    0x1.6a09de88933d6e0c1db78e1d7cd15173p-1,
+    0x1.6a09ee47541050ef59ec4bfce935cc1ap-1,
+    -0x1.5fdbc0p2,
+  },
+  { // Entry 667
+    0x1.6a09d033fa715a407a6f03d01b91113fp-1,
+    0x1.6a09fc9bebaba208c81ec0b1cd307589p-1,
+    0x1.c463a8p2,
+  },
+  { // Entry 668
+    -0x1.6a09d033fa715a407a6f03d01b91113fp-1,
+    0x1.6a09fc9bebaba208c81ec0b1cd307589p-1,
+    -0x1.c463a8p2,
+  },
+  { // Entry 669
+    0x1.6a09db844a28f8635851fdf8818515efp-1,
+    0x1.6a09f14b9cfcc0f6227d386cc3704a05p-1,
+    0x1.c463aap2,
+  },
+  { // Entry 670
+    -0x1.6a09db844a28f8635851fdf8818515efp-1,
+    0x1.6a09f14b9cfcc0f6227d386cc3704a05p-1,
+    -0x1.c463aap2,
+  },
+  { // Entry 671
+    0x1.6a09e6d49986140f55226fc58672612cp-1,
+    0x1.6a09e5fb4df35d6729f472da3413e404p-1,
+    0x1.c463acp2,
+  },
+  { // Entry 672
+    -0x1.6a09e6d49986140f55226fc58672612cp-1,
+    0x1.6a09e5fb4df35d6729f472da3413e404p-1,
+    -0x1.c463acp2,
+  },
+  { // Entry 673
+    0x1.ffffffffff95397934cac1f28532d3d3p-1,
+    0x1.4aa9c2f2c1defb8728f0d2da1217aae1p-21,
+    0x1.f6a7a0p2,
+  },
+  { // Entry 674
+    -0x1.ffffffffff95397934cac1f28532d3d3p-1,
+    0x1.4aa9c2f2c1defb8728f0d2da1217aae1p-21,
+    -0x1.f6a7a0p2,
+  },
+  { // Entry 675
+    0x1.fffffffffffa8e5aae2bb93ae590f984p-1,
+    0x1.2aa70bcb07d6d0f36b777cb380a845d9p-23,
+    0x1.f6a7a2p2,
+  },
+  { // Entry 676
+    -0x1.fffffffffffa8e5aae2bb93ae590f984p-1,
+    0x1.2aa70bcb07d6d0f36b777cb380a845d9p-23,
+    -0x1.f6a7a2p2,
+  },
+  { // Entry 677
+    0x1.ffffffffffdfe33c278cb48a59ee3ef2p-1,
+    -0x1.6aac7a1a7c0c7afc5fcb2313a7eca229p-22,
+    0x1.f6a7a4p2,
+  },
+  { // Entry 678
+    -0x1.ffffffffffdfe33c278cb48a59ee3ef2p-1,
+    -0x1.6aac7a1a7c0c7afc5fcb2313a7eca229p-22,
+    -0x1.f6a7a4p2,
+  },
+  { // Entry 679
+    0x1.6a0a040ea5c32ba4afbeb86a614c5d16p-1,
+    -0x1.6a09c8c13f48b7aad851f9d6474bcb31p-1,
+    0x1.1475cap3,
+  },
+  { // Entry 680
+    -0x1.6a0a040ea5c32ba4afbeb86a614c5d16p-1,
+    -0x1.6a09c8c13f48b7aad851f9d6474bcb31p-1,
+    -0x1.1475cap3,
+  },
+  { // Entry 681
+    0x1.6a09ed6e088212b1e260a5132d6959b7p-1,
+    -0x1.6a09df61ded49d1ee4fca4ba6140d179p-1,
+    0x1.1475ccp3,
+  },
+  { // Entry 682
+    -0x1.6a09ed6e088212b1e260a5132d6959b7p-1,
+    -0x1.6a09df61ded49d1ee4fca4ba6140d179p-1,
+    -0x1.1475ccp3,
+  },
+  { // Entry 683
+    0x1.6a09d6cd69d6efd1a6fa2dd4c617cbbep-1,
+    -0x1.6a09f6027cf678b38fc8992cd9990302p-1,
+    0x1.1475cep3,
+  },
+  { // Entry 684
+    -0x1.6a09d6cd69d6efd1a6fa2dd4c617cbbep-1,
+    -0x1.6a09f6027cf678b38fc8992cd9990302p-1,
+    -0x1.1475cep3,
+  },
+  { // Entry 685
+    0x1.f9990e91a64ae486757878bdfee0f703p-20,
+    -0x1.fffffffffc1972c902ef31c37cb54817p-1,
+    0x1.2d97c4p3,
+  },
+  { // Entry 686
+    -0x1.f9990e91a64ae486757878bdfee0f703p-20,
+    -0x1.fffffffffc1972c902ef31c37cb54817p-1,
+    -0x1.2d97c4p3,
+  },
+  { // Entry 687
+    0x1.f3321d234ed8128aabb0499a43b4def2p-21,
+    -0x1.ffffffffff0ca4e6263d27a0204389dfp-1,
+    0x1.2d97c6p3,
+  },
+  { // Entry 688
+    -0x1.f3321d234ed8128aabb0499a43b4def2p-21,
+    -0x1.ffffffffff0ca4e6263d27a0204389dfp-1,
+    -0x1.2d97c6p3,
+  },
+  { // Entry 689
+    -0x1.99bc5b961b1ac296dbe1980fd2c890a0p-26,
+    -0x1.ffffffffffffd703498c3b8288563915p-1,
+    0x1.2d97c8p3,
+  },
+  { // Entry 690
+    0x1.99bc5b961b1ac296dbe1980fd2c890a0p-26,
+    -0x1.ffffffffffffd703498c3b8288563915p-1,
+    -0x1.2d97c8p3,
+  },
+  { // Entry 691
+    -0x1.6a09c14e83f8db080d1223f887cc12ecp-1,
+    -0x1.6a0a0b815fb37b2d01551e07cb3009d1p-1,
+    0x1.46b9c0p3,
+  },
+  { // Entry 692
+    0x1.6a09c14e83f8db080d1223f887cc12ecp-1,
+    -0x1.6a0a0b815fb37b2d01551e07cb3009d1p-1,
+    -0x1.46b9c0p3,
+  },
+  { // Entry 693
+    -0x1.6a09d7ef23fbec1ed812e807beb0492fp-1,
+    -0x1.6a09f4e0c2e98deb78642b6032a73d46p-1,
+    0x1.46b9c2p3,
+  },
+  { // Entry 694
+    0x1.6a09d7ef23fbec1ed812e807beb0492fp-1,
+    -0x1.6a09f4e0c2e98deb78642b6032a73d46p-1,
+    -0x1.46b9c2p3,
+  },
+  { // Entry 695
+    -0x1.6a09ee8fc294f35db3efce565365af89p-1,
+    -0x1.6a09de4024b596b50eb06d562db8c777p-1,
+    0x1.46b9c4p3,
+  },
+  { // Entry 696
+    0x1.6a09ee8fc294f35db3efce565365af89p-1,
+    -0x1.6a09de4024b596b50eb06d562db8c777p-1,
+    -0x1.46b9c4p3,
+  },
+  { // Entry 697
+    -0x1.fffffffffe4c96b397d951cb21861c95p-1,
+    -0x1.4ddd3ba9edcd898b9946fdd20af22a68p-20,
+    0x1.5fdbbcp3,
+  },
+  { // Entry 698
+    0x1.fffffffffe4c96b397d951cb21861c95p-1,
+    -0x1.4ddd3ba9edcd898b9946fdd20af22a68p-20,
+    -0x1.5fdbbcp3,
+  },
+  { // Entry 699
+    -0x1.ffffffffffe8512aebb56c9e75b41941p-1,
+    -0x1.3774eea7b8abe8fa8c380142b97af4b6p-22,
+    0x1.5fdbbep3,
+  },
+  { // Entry 700
+    0x1.ffffffffffe8512aebb56c9e75b41941p-1,
+    -0x1.3774eea7b8abe8fa8c380142b97af4b6p-22,
+    -0x1.5fdbbep3,
+  },
+  { // Entry 701
+    -0x1.ffffffffff840ba23f91c9cb49a10b27p-1,
+    0x1.644588ac238ae493fa32435ba51329bfp-21,
+    0x1.5fdbc0p3,
+  },
+  { // Entry 702
+    0x1.ffffffffff840ba23f91c9cb49a10b27p-1,
+    0x1.644588ac238ae493fa32435ba51329bfp-21,
+    -0x1.5fdbc0p3,
+  },
+  { // Entry 703
+    -0x1.6a0a12f4197c90a0ee4a094b6377aa23p-1,
+    0x1.6a09b9dbc881c458e747908caf2aa5e1p-1,
+    0x1.78fdb6p3,
+  },
+  { // Entry 704
+    0x1.6a0a12f4197c90a0ee4a094b6377aa23p-1,
+    0x1.6a09b9dbc881c458e747908caf2aa5e1p-1,
+    -0x1.78fdb6p3,
+  },
+  { // Entry 705
+    -0x1.6a09fc537d29cf131d6710991bebabedp-1,
+    0x1.6a09d07c68fc010ffcfd3b19f1ee4f44p-1,
+    0x1.78fdb8p3,
+  },
+  { // Entry 706
+    0x1.6a09fc537d29cf131d6710991bebabedp-1,
+    0x1.6a09d07c68fc010ffcfd3b19f1ee4f44p-1,
+    -0x1.78fdb8p3,
+  },
+  { // Entry 707
+    -0x1.6a09e5b2df6d0388f9070c4340f3e669p-1,
+    0x1.6a09e71d080c33f6964a07d1a0bf5980p-1,
+    0x1.78fdbap3,
+  },
+  { // Entry 708
+    0x1.6a09e5b2df6d0388f9070c4340f3e669p-1,
+    0x1.6a09e71d080c33f6964a07d1a0bf5980p-1,
+    -0x1.78fdbap3,
+  },
+  { // Entry 709
+    0x1.6a09c909add4dbf32253a39d5c306308p-1,
+    0x1.6a0a03c63742d62802d163d5cfb3b7d5p-1,
+    0x1.ab41aep3,
+  },
+  { // Entry 710
+    -0x1.6a09c909add4dbf32253a39d5c306308p-1,
+    0x1.6a0a03c63742d62802d163d5cfb3b7d5p-1,
+    -0x1.ab41aep3,
+  },
+  { // Entry 711
+    0x1.6a09dfaa4d5c3a7f056f3e61a365b29ep-1,
+    0x1.6a09ed2599fd364c97660cca6652c0a3p-1,
+    0x1.ab41b0p3,
+  },
+  { // Entry 712
+    -0x1.6a09dfaa4d5c3a7f056f3e61a365b29ep-1,
+    0x1.6a09ed2599fd364c97660cca6652c0a3p-1,
+    -0x1.ab41b0p3,
+  },
+  { // Entry 713
+    0x1.6a09f64aeb798f2b3e3d9b16e8e3c412p-1,
+    0x1.6a09d684fb4d8c840660d6b42ec83039p-1,
+    0x1.ab41b2p3,
+  },
+  { // Entry 714
+    -0x1.6a09f64aeb798f2b3e3d9b16e8e3c412p-1,
+    0x1.6a09d684fb4d8c840660d6b42ec83039p-1,
+    -0x1.ab41b2p3,
+  },
+  { // Entry 715
+    0x1.fffffffffc260d6ffb8f4cd8ab3fd020p-1,
+    0x1.f66595da7a1ae308d26a18de4c2ed3a3p-20,
+    0x1.c463a8p3,
+  },
+  { // Entry 716
+    -0x1.fffffffffc260d6ffb8f4cd8ab3fd020p-1,
+    0x1.f66595da7a1ae308d26a18de4c2ed3a3p-20,
+    -0x1.c463a8p3,
+  },
+  { // Entry 717
+    0x1.ffffffffff12d89bb084dd762848b3d6p-1,
+    0x1.eccb2bb4f66ea861241fa09ca9d8a034p-21,
+    0x1.c463aap3,
+  },
+  { // Entry 718
+    -0x1.ffffffffff12d89bb084dd762848b3d6p-1,
+    0x1.eccb2bb4f66ea861241fa09ca9d8a034p-21,
+    -0x1.c463aap3,
+  },
+  { // Entry 719
+    0x1.ffffffffffffa3c7657b85e5b44bbd44p-1,
+    -0x1.334d44b0945407b118b361ab78171f67p-25,
+    0x1.c463acp3,
+  },
+  { // Entry 720
+    -0x1.ffffffffffffa3c7657b85e5b44bbd44p-1,
+    -0x1.334d44b0945407b118b361ab78171f67p-25,
+    -0x1.c463acp3,
+  },
+  { // Entry 721
+    0x1.6a0a0b38f134a3295a0b386e42f1ca7ap-1,
+    -0x1.6a09c196f2867cc916ae2b7e6c9d99c1p-1,
+    0x1.dd85a4p3,
+  },
+  { // Entry 722
+    -0x1.6a0a0b38f134a3295a0b386e42f1ca7ap-1,
+    -0x1.6a09c196f2867cc916ae2b7e6c9d99c1p-1,
+    -0x1.dd85a4p3,
+  },
+  { // Entry 723
+    0x1.6a09f49854662eff1b35755a129044a7p-1,
+    -0x1.6a09d837928506f7cff76f094b4e0377p-1,
+    0x1.dd85a6p3,
+  },
+  { // Entry 724
+    -0x1.6a09f49854662eff1b35755a129044a7p-1,
+    -0x1.6a09d837928506f7cff76f094b4e0377p-1,
+    -0x1.dd85a6p3,
+  },
+  { // Entry 725
+    0x1.6a09ddf7b62db0e0440b6a4262203b11p-1,
+    -0x1.6a09eed83119874e51ae4bb8aeddc1f2p-1,
+    0x1.dd85a8p3,
+  },
+  { // Entry 726
+    -0x1.6a09ddf7b62db0e0440b6a4262203b11p-1,
+    -0x1.6a09eed83119874e51ae4bb8aeddc1f2p-1,
+    -0x1.dd85a8p3,
+  },
+  { // Entry 727
+    0x1.4aa9c2f2c19a062b18a017bcd5424feap-20,
+    -0x1.fffffffffe54e5e4d32b3453166060b3p-1,
+    0x1.f6a7a0p3,
+  },
+  { // Entry 728
+    -0x1.4aa9c2f2c19a062b18a017bcd5424feap-20,
+    -0x1.fffffffffe54e5e4d32b3453166060b3p-1,
+    -0x1.f6a7a0p3,
+  },
+  { // Entry 729
+    0x1.2aa70bcb07d3a40781510d213652e43ap-22,
+    -0x1.ffffffffffea396ab8aee509392c755dp-1,
+    0x1.f6a7a2p3,
+  },
+  { // Entry 730
+    -0x1.2aa70bcb07d3a40781510d213652e43ap-22,
+    -0x1.ffffffffffea396ab8aee509392c755dp-1,
+    -0x1.f6a7a2p3,
+  },
+  { // Entry 731
+    -0x1.6aac7a1a7bf5bbd49572ffb8d7749922p-21,
+    -0x1.ffffffffff7f8cf09e32d6309bea85cap-1,
+    0x1.f6a7a4p3,
+  },
+  { // Entry 732
+    0x1.6aac7a1a7bf5bbd49572ffb8d7749922p-21,
+    -0x1.ffffffffff7f8cf09e32d6309bea85cap-1,
+    -0x1.f6a7a4p3,
+  },
+  { // Entry 733
+    -0x1.6a09a383953124096898340f9168b9d5p-1,
+    -0x1.6a0a294c45ec747a47711a4994d2c5e4p-1,
+    0x1.07e4ccp4,
+  },
+  { // Entry 734
+    0x1.6a09a383953124096898340f9168b9d5p-1,
+    -0x1.6a0a294c45ec747a47711a4994d2c5e4p-1,
+    -0x1.07e4ccp4,
+  },
+  { // Entry 735
+    -0x1.6a09d0c4d7869961c47a9b0b968cc910p-1,
+    -0x1.6a09fc0b0ea7ed9fb5dd50a0c8af19cbp-1,
+    0x1.07e4cep4,
+  },
+  { // Entry 736
+    0x1.6a09d0c4d7869961c47a9b0b968cc910p-1,
+    -0x1.6a09fc0b0ea7ed9fb5dd50a0c8af19cbp-1,
+    -0x1.07e4cep4,
+  },
+  { // Entry 737
+    -0x1.6a09fe061433e7770d00ca59d5a56251p-1,
+    -0x1.6a09cec9d1bb3ed4f810c9f9786d610ep-1,
+    0x1.07e4d0p4,
+  },
+  { // Entry 738
+    0x1.6a09fe061433e7770d00ca59d5a56251p-1,
+    -0x1.6a09cec9d1bb3ed4f810c9f9786d610ep-1,
+    -0x1.07e4d0p4,
+  },
+  { // Entry 739
+    -0x1.fffffffff9219dae5feda1b539335803p-1,
+    -0x1.4f76f80582c73fc0cc0903ed8ca7d6b3p-19,
+    0x1.1475cap4,
+  },
+  { // Entry 740
+    0x1.fffffffff9219dae5feda1b539335803p-1,
+    -0x1.4f76f80582c73fc0cc0903ed8ca7d6b3p-19,
+    -0x1.1475cap4,
+  },
+  { // Entry 741
+    -0x1.ffffffffff9d556e8c0bf0a80d610808p-1,
+    -0x1.3ddbe0161108b690eed70a7f59de751cp-21,
+    0x1.1475ccp4,
+  },
+  { // Entry 742
+    0x1.ffffffffff9d556e8c0bf0a80d610808p-1,
+    -0x1.3ddbe0161108b690eed70a7f59de751cp-21,
+    -0x1.1475ccp4,
+  },
+  { // Entry 743
+    -0x1.fffffffffe190d2eb82e74efd2093215p-1,
+    0x1.61120ff4f70180b0d55c3ae0f69585cap-20,
+    0x1.1475cep4,
+  },
+  { // Entry 744
+    0x1.fffffffffe190d2eb82e74efd2093215p-1,
+    0x1.61120ff4f70180b0d55c3ae0f69585cap-20,
+    -0x1.1475cep4,
+  },
+  { // Entry 745
+    -0x1.6a0a1a1e64a28eee238dc852846aacd5p-1,
+    0x1.6a09b2b17b741050a6cfd64b81c76485p-1,
+    0x1.2106c8p4,
+  },
+  { // Entry 746
+    0x1.6a0a1a1e64a28eee238dc852846aacd5p-1,
+    0x1.6a09b2b17b741050a6cfd64b81c76485p-1,
+    -0x1.2106c8p4,
+  },
+  { // Entry 747
+    -0x1.6a09ecdd2b784b699034ee8102670e27p-1,
+    0x1.6a09dff2bbe3c9616a3576c55e773207p-1,
+    0x1.2106cap4,
+  },
+  { // Entry 748
+    0x1.6a09ecdd2b784b699034ee8102670e27p-1,
+    0x1.6a09dff2bbe3c9616a3576c55e773207p-1,
+    -0x1.2106cap4,
+  },
+  { // Entry 749
+    -0x1.6a09bf9beca5e03188301639c09ed574p-1,
+    0x1.6a0a0d33f6ab5af262ad6ad18ac1ce9fp-1,
+    0x1.2106ccp4,
+  },
+  { // Entry 750
+    0x1.6a09bf9beca5e03188301639c09ed574p-1,
+    0x1.6a0a0d33f6ab5af262ad6ad18ac1ce9fp-1,
+    -0x1.2106ccp4,
+  },
+  { // Entry 751
+    -0x1.f9990e91a270d3bc1c02f4f69f48e675p-19,
+    0x1.fffffffff065cb240bcbfdff4977ddf8p-1,
+    0x1.2d97c4p4,
+  },
+  { // Entry 752
+    0x1.f9990e91a270d3bc1c02f4f69f48e675p-19,
+    0x1.fffffffff065cb240bcbfdff4977ddf8p-1,
+    -0x1.2d97c4p4,
+  },
+  { // Entry 753
+    -0x1.f3321d234deacd6f3afd75039685012fp-20,
+    0x1.fffffffffc32939898f585d6948cf2d1p-1,
+    0x1.2d97c6p4,
+  },
+  { // Entry 754
+    0x1.f3321d234deacd6f3afd75039685012fp-20,
+    0x1.fffffffffc32939898f585d6948cf2d1p-1,
+    -0x1.2d97c6p4,
+  },
+  { // Entry 755
+    0x1.99bc5b961b1aa1c9e8023074f3406fd9p-25,
+    0x1.ffffffffffff5c0d2630ee0a27e8d6d1p-1,
+    0x1.2d97c8p4,
+  },
+  { // Entry 756
+    -0x1.99bc5b961b1aa1c9e8023074f3406fd9p-25,
+    0x1.ffffffffffff5c0d2630ee0a27e8d6d1p-1,
+    -0x1.2d97c8p4,
+  },
+  { // Entry 757
+    0x1.6a09949e1ce1ec501afcb35d731bf62cp-1,
+    0x1.6a0a3831b81d94966ad8df4d378824f9p-1,
+    0x1.3a28c2p4,
+  },
+  { // Entry 758
+    -0x1.6a09949e1ce1ec501afcb35d731bf62cp-1,
+    0x1.6a0a3831b81d94966ad8df4d378824f9p-1,
+    -0x1.3a28c2p4,
+  },
+  { // Entry 759
+    0x1.6a09c1df6114100c65d1ff6c55755e72p-1,
+    0x1.6a0a0af082b5bca7f5569f4da6883f64p-1,
+    0x1.3a28c4p4,
+  },
+  { // Entry 760
+    -0x1.6a09c1df6114100c65d1ff6c55755e72p-1,
+    0x1.6a0a0af082b5bca7f5569f4da6883f64p-1,
+    -0x1.3a28c4p4,
+  },
+  { // Entry 761
+    0x1.6a09ef209f9e0cc13324ddf2b361553fp-1,
+    0x1.6a09ddaf47a5bc8dbdcb6b13844902aep-1,
+    0x1.3a28c6p4,
+  },
+  { // Entry 762
+    -0x1.6a09ef209f9e0cc13324ddf2b361553fp-1,
+    0x1.6a09ddaf47a5bc8dbdcb6b13844902aep-1,
+    -0x1.3a28c6p4,
+  },
+  { // Entry 763
+    0x1.fffffffff53f476ec4f59f26c4bcdfa0p-1,
+    0x1.a3bb251dc7efaa1e2137bb37ed6654dbp-19,
+    0x1.46b9c0p4,
+  },
+  { // Entry 764
+    -0x1.fffffffff53f476ec4f59f26c4bcdfa0p-1,
+    0x1.a3bb251dc7efaa1e2137bb37ed6654dbp-19,
+    -0x1.46b9c0p4,
+  },
+  { // Entry 765
+    0x1.fffffffffe5d2097b34334ad679dd7a4p-1,
+    0x1.47764a3b9566758e5baa2e3029f1abbap-20,
+    0x1.46b9c2p4,
+  },
+  { // Entry 766
+    -0x1.fffffffffe5d2097b34334ad679dd7a4p-1,
+    0x1.47764a3b9566758e5baa2e3029f1abbap-20,
+    -0x1.46b9c2p4,
+  },
+  { // Entry 767
+    0x1.ffffffffff7af9c0a19a005c565c6af7p-1,
+    -0x1.71136b88d4608490f2ddfe90101112aep-21,
+    0x1.46b9c4p4,
+  },
+  { // Entry 768
+    -0x1.ffffffffff7af9c0a19a005c565c6af7p-1,
+    -0x1.71136b88d4608490f2ddfe90101112aep-21,
+    -0x1.46b9c4p4,
+  },
+  { // Entry 769
+    0x1.6a0a2903d773925b052fb006ac670c23p-1,
+    -0x1.6a09a3cc03c4bbad2222dfe5be317565p-1,
+    0x1.534abep4,
+  },
+  { // Entry 770
+    -0x1.6a0a2903d773925b052fb006ac670c23p-1,
+    -0x1.6a09a3cc03c4bbad2222dfe5be317565p-1,
+    -0x1.534abep4,
+  },
+  { // Entry 771
+    0x1.6a09fbc2a025fdae918466fa00142143p-1,
+    -0x1.6a09d10d46112335d0e43d738387de8cp-1,
+    0x1.534ac0p4,
+  },
+  { // Entry 772
+    -0x1.6a09fbc2a025fdae918466fa00142143p-1,
+    -0x1.6a09d10d46112335d0e43d738387de8cp-1,
+    -0x1.534ac0p4,
+  },
+  { // Entry 773
+    0x1.6a09ce8163304113135a68ae93d3fa0ep-1,
+    -0x1.6a09fe4e82b5637a4a8f392c3301be94p-1,
+    0x1.534ac2p4,
+  },
+  { // Entry 774
+    -0x1.6a09ce8163304113135a68ae93d3fa0ep-1,
+    -0x1.6a09fe4e82b5637a4a8f392c3301be94p-1,
+    -0x1.534ac2p4,
+  },
+  { // Entry 775
+    0x1.4ddd3ba9ecb19d6bb6ea161120e447b9p-19,
+    -0x1.fffffffff9325ace5f682bbb8b122a09p-1,
+    0x1.5fdbbcp4,
+  },
+  { // Entry 776
+    -0x1.4ddd3ba9ecb19d6bb6ea161120e447b9p-19,
+    -0x1.fffffffff9325ace5f682bbb8b122a09p-1,
+    -0x1.5fdbbcp4,
+  },
+  { // Entry 777
+    0x1.3774eea7b89d80df7816fe208ec69fc0p-21,
+    -0x1.ffffffffffa144abaed5b4aab880635dp-1,
+    0x1.5fdbbep4,
+  },
+  { // Entry 778
+    -0x1.3774eea7b89d80df7816fe208ec69fc0p-21,
+    -0x1.ffffffffffa144abaed5b4aab880635dp-1,
+    -0x1.5fdbbep4,
+  },
+  { // Entry 779
+    -0x1.644588ac2334a3d5452d9960282cf80dp-20,
+    -0x1.fffffffffe102e88fe476331e1ddefafp-1,
+    0x1.5fdbc0p4,
+  },
+  { // Entry 780
+    0x1.644588ac2334a3d5452d9960282cf80dp-20,
+    -0x1.fffffffffe102e88fe476331e1ddefafp-1,
+    -0x1.5fdbc0p4,
+  },
+  { // Entry 781
+    -0x1.6a09b2f9ea049e855e35ca9ce7e0d89ap-1,
+    -0x1.6a0a19d5f626a35ee112a34638e07808p-1,
+    0x1.6c6cbap4,
+  },
+  { // Entry 782
+    0x1.6a09b2f9ea049e855e35ca9ce7e0d89ap-1,
+    -0x1.6a0a19d5f626a35ee112a34638e07808p-1,
+    -0x1.6c6cbap4,
+  },
+  { // Entry 783
+    -0x1.6a09e03b2a6b49c6134c67b42baee668p-1,
+    -0x1.6a09ec94bcf35208ccd030684d5ddd9cp-1,
+    0x1.6c6cbcp4,
+  },
+  { // Entry 784
+    0x1.6a09e03b2a6b49c6134c67b42baee668p-1,
+    -0x1.6a09ec94bcf35208ccd030684d5ddd9cp-1,
+    -0x1.6c6cbcp4,
+  },
+  { // Entry 785
+    -0x1.6a0a0d7c6529cd85dbbb3a5c2cd3fae5p-1,
+    -0x1.6a09bf537e17d900659bd2fa24c3a8c8p-1,
+    0x1.6c6cbep4,
+  },
+  { // Entry 786
+    0x1.6a0a0d7c6529cd85dbbb3a5c2cd3fae5p-1,
+    -0x1.6a09bf537e17d900659bd2fa24c3a8c8p-1,
+    -0x1.6c6cbep4,
+  },
+  { // Entry 787
+    -0x1.fffffffff07f0ab12aa8f41f29c15392p-1,
+    -0x1.f7ff52360c622b3f94d9c7250bfad8d4p-19,
+    0x1.78fdb6p4,
+  },
+  { // Entry 788
+    0x1.fffffffff07f0ab12aa8f41f29c15392p-1,
+    -0x1.f7ff52360c622b3f94d9c7250bfad8d4p-19,
+    -0x1.78fdb6p4,
+  },
+  { // Entry 789
+    -0x1.fffffffffc3f0542db21dcbcb847dac3p-1,
+    -0x1.effea46c21baa3da7c266c953a013598p-20,
+    0x1.78fdb8p4,
+  },
+  { // Entry 790
+    0x1.fffffffffc3f0542db21dcbcb847dac3p-1,
+    -0x1.effea46c21baa3da7c266c953a013598p-20,
+    -0x1.78fdb8p4,
+  },
+  { // Entry 791
+    -0x1.fffffffffffeffd48bac73efe60c7fcfp-1,
+    0x1.0015b93dd0f095be1eb0a5b87fe5e33ep-24,
+    0x1.78fdbap4,
+  },
+  { // Entry 792
+    0x1.fffffffffffeffd48bac73efe60c7fcfp-1,
+    0x1.0015b93dd0f095be1eb0a5b87fe5e33ep-24,
+    -0x1.78fdbap4,
+  },
+  { // Entry 793
+    -0x1.6a0a37e949a7ad698a32234c73e5afbap-1,
+    0x1.6a0994e68b787ee4fd6830b288225745p-1,
+    0x1.858eb4p4,
+  },
+  { // Entry 794
+    0x1.6a0a37e949a7ad698a32234c73e5afbap-1,
+    0x1.6a0994e68b787ee4fd6830b288225745p-1,
+    -0x1.858eb4p4,
+  },
+  { // Entry 795
+    -0x1.6a0a0aa81436c7a8d33a38d704030d14p-1,
+    0x1.6a09c227cfa194d1fa7ab9909de5083cp-1,
+    0x1.858eb6p4,
+  },
+  { // Entry 796
+    0x1.6a0a0aa81436c7a8d33a38d704030d14p-1,
+    0x1.6a09c227cfa194d1fa7ab9909de5083cp-1,
+    -0x1.858eb6p4,
+  },
+  { // Entry 797
+    -0x1.6a09dd66d91db9bd7bf355faff08f194p-1,
+    0x1.6a09ef690e2283b658509ed319483839p-1,
+    0x1.858eb8p4,
+  },
+  { // Entry 798
+    0x1.6a09dd66d91db9bd7bf355faff08f194p-1,
+    0x1.6a09ef690e2283b658509ed319483839p-1,
+    -0x1.858eb8p4,
+  },
+  { // Entry 799
+    0x1.c048b38a8bbf59f414fec7079209926ep-3,
+    -0x1.f3957bad70e0741f1d3d6751246ce21ap-1,
+    0x1.fffffep62,
+  },
+  { // Entry 800
+    -0x1.c048b38a8bbf59f414fec7079209926ep-3,
+    -0x1.f3957bad70e0741f1d3d6751246ce21ap-1,
+    -0x1.fffffep62,
+  },
+  { // Entry 801
+    0x1.fff6dfd42dc54430bc0576b00a88bd94p-1,
+    0x1.82aa375b3c33e70663731bab4beb6ed3p-7,
+    0x1.p63,
+  },
+  { // Entry 802
+    -0x1.fff6dfd42dc54430bc0576b00a88bd94p-1,
+    0x1.82aa375b3c33e70663731bab4beb6ed3p-7,
+    -0x1.p63,
+  },
+  { // Entry 803
+    -0x1.d6637d070347ee94e830445e76486727p-1,
+    0x1.945e6c69a580fb7bb27d02c0fe0f8a71p-2,
+    0x1.000002p63,
+  },
+  { // Entry 804
+    0x1.d6637d070347ee94e830445e76486727p-1,
+    0x1.945e6c69a580fb7bb27d02c0fe0f8a71p-2,
+    -0x1.000002p63,
+  },
+  { // Entry 805
+    -0x1.0e5283661df0ca0f55ab6167e14514a1p-1,
+    -0x1.b2d255f2bd0423e29e2a548728f034abp-1,
+    0x1.fffffep26,
+  },
+  { // Entry 806
+    0x1.0e5283661df0ca0f55ab6167e14514a1p-1,
+    -0x1.b2d255f2bd0423e29e2a548728f034abp-1,
+    -0x1.fffffep26,
+  },
+  { // Entry 807
+    -0x1.86dcc9babb0a40ee875cab3b9e892757p-1,
+    0x1.4ab6511a7d39ad3cc88ded1e775ca147p-1,
+    0x1.p27,
+  },
+  { // Entry 808
+    0x1.86dcc9babb0a40ee875cab3b9e892757p-1,
+    0x1.4ab6511a7d39ad3cc88ded1e775ca147p-1,
+    -0x1.p27,
+  },
+  { // Entry 809
+    0x1.171999b629fd5b6357c6dff4d7827d95p-1,
+    -0x1.ad3d80c82f4452b076581de24648435bp-1,
+    0x1.000002p27,
+  },
+  { // Entry 810
+    -0x1.171999b629fd5b6357c6dff4d7827d95p-1,
+    -0x1.ad3d80c82f4452b076581de24648435bp-1,
+    -0x1.000002p27,
+  },
+  { // Entry 811
+    -0x1.e57ec09221973550d1e5798dcf0cd25dp-1,
+    -0x1.4532c3721ed4343ad88eea8908a988cbp-2,
+    0x1.fffffep23,
+  },
+  { // Entry 812
+    0x1.e57ec09221973550d1e5798dcf0cd25dp-1,
+    -0x1.4532c3721ed4343ad88eea8908a988cbp-2,
+    -0x1.fffffep23,
+  },
+  { // Entry 813
+    -0x1.8f22f8433d6edfe9a4aff9622517caa9p-1,
+    0x1.40ad67f3f0c9a143963c9c96dbce3f8ap-1,
+    0x1.p24,
+  },
+  { // Entry 814
+    0x1.8f22f8433d6edfe9a4aff9622517caa9p-1,
+    0x1.40ad67f3f0c9a143963c9c96dbce3f8ap-1,
+    -0x1.p24,
+  },
+  { // Entry 815
+    0x1.c9b0c7265c543f80faf01741c6458560p-1,
+    0x1.caf8537c3e442ca8aca86c156773853ap-2,
+    0x1.000002p24,
+  },
+  { // Entry 816
+    -0x1.c9b0c7265c543f80faf01741c6458560p-1,
+    0x1.caf8537c3e442ca8aca86c156773853ap-2,
+    -0x1.000002p24,
+  },
+  { // Entry 817
+    -0x1.837b98a3185d1466d852f0a7dc1d248ep-1,
+    -0x1.4eaa667ba0b90dfb05ab3d9c247cdee7p-1,
+    0x1.fffffep1,
+  },
+  { // Entry 818
+    0x1.837b98a3185d1466d852f0a7dc1d248ep-1,
+    -0x1.4eaa667ba0b90dfb05ab3d9c247cdee7p-1,
+    -0x1.fffffep1,
+  },
+  { // Entry 819
+    -0x1.837b9dddc1eae70ce98055a0e450d93cp-1,
+    -0x1.4eaa606db24c0c466da1c2dc7baa2b32p-1,
+    0x1.p2,
+  },
+  { // Entry 820
+    0x1.837b9dddc1eae70ce98055a0e450d93cp-1,
+    -0x1.4eaa606db24c0c466da1c2dc7baa2b32p-1,
+    -0x1.p2,
+  },
+  { // Entry 821
+    -0x1.837ba85314bde52b1e9c2c8ed2712c72p-1,
+    -0x1.4eaa5451d53348eb89dc478d4d11be02p-1,
+    0x1.000002p2,
+  },
+  { // Entry 822
+    0x1.837ba85314bde52b1e9c2c8ed2712c72p-1,
+    -0x1.4eaa5451d53348eb89dc478d4d11be02p-1,
+    -0x1.000002p2,
+  },
+  { // Entry 823
+    0x1.d18f70573da63012fa1c0e3d2ebbe59cp-1,
+    -0x1.aa225e2ef96241915b6fd217522814f5p-2,
+    0x1.fffffep0,
+  },
+  { // Entry 824
+    -0x1.d18f70573da63012fa1c0e3d2ebbe59cp-1,
+    -0x1.aa225e2ef96241915b6fd217522814f5p-2,
+    -0x1.fffffep0,
+  },
+  { // Entry 825
+    0x1.d18f6ead1b445dfab848188009c9bb95p-1,
+    -0x1.aa22657537204a4332f8acbb72b0d768p-2,
+    0x1.p1,
+  },
+  { // Entry 826
+    -0x1.d18f6ead1b445dfab848188009c9bb95p-1,
+    -0x1.aa22657537204a4332f8acbb72b0d768p-2,
+    -0x1.p1,
+  },
+  { // Entry 827
+    0x1.d18f6b58d66ae7110b2b6f7cffba6ec1p-1,
+    -0x1.aa227401b288620a0372d5a96084915dp-2,
+    0x1.000002p1,
+  },
+  { // Entry 828
+    -0x1.d18f6b58d66ae7110b2b6f7cffba6ec1p-1,
+    -0x1.aa227401b288620a0372d5a96084915dp-2,
+    -0x1.000002p1,
+  },
+  { // Entry 829
+    0x1.aed547dbee4d0d8680d0813d1e4e21d0p-1,
+    0x1.14a282aa25b11f6312a7a65180e7c3d4p-1,
+    0x1.fffffep-1,
+  },
+  { // Entry 830
+    -0x1.aed547dbee4d0d8680d0813d1e4e21d0p-1,
+    0x1.14a282aa25b11f6312a7a65180e7c3d4p-1,
+    -0x1.fffffep-1,
+  },
+  { // Entry 831
+    0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    0x1.p0,
+  },
+  { // Entry 832
+    -0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    -0x1.p0,
+  },
+  { // Entry 833
+    0x1.aed54b19d5cd7937cbf41ed408ca0a52p-1,
+    0x1.14a27d9da5d4aebce71428f9057b08dap-1,
+    0x1.000002p0,
+  },
+  { // Entry 834
+    -0x1.aed54b19d5cd7937cbf41ed408ca0a52p-1,
+    0x1.14a27d9da5d4aebce71428f9057b08dap-1,
+    -0x1.000002p0,
+  },
+  { // Entry 835
+    0x1.eaee85835dde5b71beec7d8d98052112p-2,
+    0x1.c15280e0737692dd436908fdc8e6e2e1p-1,
+    0x1.fffffep-2,
+  },
+  { // Entry 836
+    -0x1.eaee85835dde5b71beec7d8d98052112p-2,
+    0x1.c15280e0737692dd436908fdc8e6e2e1p-1,
+    -0x1.fffffep-2,
+  },
+  { // Entry 837
+    0x1.eaee8744b05efe8764bc364fd837b666p-2,
+    0x1.c1528065b7d4f9db7bbb3b45f5f5b30ap-1,
+    0x1.p-1,
+  },
+  { // Entry 838
+    -0x1.eaee8744b05efe8764bc364fd837b666p-2,
+    0x1.c1528065b7d4f9db7bbb3b45f5f5b30ap-1,
+    -0x1.p-1,
+  },
+  { // Entry 839
+    0x1.eaee8ac7555ed47fca77ceed174c8ea0p-2,
+    0x1.c1527f70409076da0c3204df1e099a83p-1,
+    0x1.000002p-1,
+  },
+  { // Entry 840
+    -0x1.eaee8ac7555ed47fca77ceed174c8ea0p-2,
+    0x1.c1527f70409076da0c3204df1e099a83p-1,
+    -0x1.000002p-1,
+  },
+  { // Entry 841
+    0x1.faaeeb5f1c0d63f43c6f3ec46011690fp-3,
+    0x1.f0154a1789d8dcc172cd2092d05f6394p-1,
+    0x1.fffffep-3,
+  },
+  { // Entry 842
+    -0x1.faaeeb5f1c0d63f43c6f3ec46011690fp-3,
+    0x1.f0154a1789d8dcc172cd2092d05f6394p-1,
+    -0x1.fffffep-3,
+  },
+  { // Entry 843
+    0x1.faaeed4f31576ba89debdc7351e8b1aep-3,
+    0x1.f01549f7deea174f07a67972bf29f148p-1,
+    0x1.p-2,
+  },
+  { // Entry 844
+    -0x1.faaeed4f31576ba89debdc7351e8b1aep-3,
+    0x1.f01549f7deea174f07a67972bf29f148p-1,
+    -0x1.p-2,
+  },
+  { // Entry 845
+    0x1.faaef12f5beb1c1094473d3c3365b9e1p-3,
+    0x1.f01549b8890c2f66337cac15a7237c8ep-1,
+    0x1.000002p-2,
+  },
+  { // Entry 846
+    -0x1.faaef12f5beb1c1094473d3c3365b9e1p-3,
+    0x1.f01549b8890c2f66337cac15a7237c8ep-1,
+    -0x1.000002p-2,
+  },
+  { // Entry 847
+    0x1.feaaecec6d8e30cd56950eb2ebdcebd4p-4,
+    0x1.fc01552fd068ee83f5b742c05245e8b2p-1,
+    0x1.fffffep-4,
+  },
+  { // Entry 848
+    -0x1.feaaecec6d8e30cd56950eb2ebdcebd4p-4,
+    0x1.fc01552fd068ee83f5b742c05245e8b2p-1,
+    -0x1.fffffep-4,
+  },
+  { // Entry 849
+    0x1.feaaeee86ee35ca069a86721f89f85a5p-4,
+    0x1.fc015527d5bd36da3cd4253bede319cap-1,
+    0x1.p-3,
+  },
+  { // Entry 850
+    -0x1.feaaeee86ee35ca069a86721f89f85a5p-4,
+    0x1.fc015527d5bd36da3cd4253bede319cap-1,
+    -0x1.p-3,
+  },
+  { // Entry 851
+    0x1.feaaf2e0718d9c568c9442c81545cd62p-4,
+    0x1.fc015517e065afb6bb102c18f5919820p-1,
+    0x1.000002p-3,
+  },
+  { // Entry 852
+    -0x1.feaaf2e0718d9c568c9442c81545cd62p-4,
+    0x1.fc015517e065afb6bb102c18f5919820p-1,
+    -0x1.000002p-3,
+  },
+  { // Entry 853
+    0x1.ffaaacefd4d855ac8227799f3e263d7ap-5,
+    0x1.ff0015569ef7e2b96301e6f752c019d4p-1,
+    0x1.fffffep-5,
+  },
+  { // Entry 854
+    -0x1.ffaaacefd4d855ac8227799f3e263d7ap-5,
+    0x1.ff0015569ef7e2b96301e6f752c019d4p-1,
+    -0x1.fffffep-5,
+  },
+  { // Entry 855
+    0x1.ffaaaeeed4edab4ba4b365ed25a9595fp-5,
+    0x1.ff0015549f4d34ca0e1ee6509bc42b71p-1,
+    0x1.p-4,
+  },
+  { // Entry 856
+    -0x1.ffaaaeeed4edab4ba4b365ed25a9595fp-5,
+    0x1.ff0015549f4d34ca0e1ee6509bc42b71p-1,
+    -0x1.p-4,
+  },
+  { // Entry 857
+    0x1.ffaab2ecd518508ae9bc730a165a8eadp-5,
+    0x1.ff0015509ff7d2ee6418e924f0de5e97p-1,
+    0x1.000002p-4,
+  },
+  { // Entry 858
+    -0x1.ffaab2ecd518508ae9bc730a165a8eadp-5,
+    0x1.ff0015509ff7d2ee6418e924f0de5e97p-1,
+    -0x1.000002p-4,
+  },
+  { // Entry 859
+    0x1.ffeaa8ef2e85933883c0dc33462387b5p-6,
+    0x1.ffc00155d277d58e727cd95c43f759cfp-1,
+    0x1.fffffep-6,
+  },
+  { // Entry 860
+    -0x1.ffeaa8ef2e85933883c0dc33462387b5p-6,
+    0x1.ffc00155d277d58e727cd95c43f759cfp-1,
+    -0x1.fffffep-6,
+  },
+  { // Entry 861
+    0x1.ffeaaaeeee86e8cafe41376d47919579p-6,
+    0x1.ffc00155527d2b12aedb49d92928df72p-1,
+    0x1.p-5,
+  },
+  { // Entry 862
+    -0x1.ffeaaaeeee86e8cafe41376d47919579p-6,
+    0x1.ffc00155527d2b12aedb49d92928df72p-1,
+    -0x1.p-5,
+  },
+  { // Entry 863
+    0x1.ffeaaeee6e89927003413abe64e9dc21p-6,
+    0x1.ffc001545287d49b57972af5145663a0p-1,
+    0x1.000002p-5,
+  },
+  { // Entry 864
+    -0x1.ffeaaeee6e89927003413abe64e9dc21p-6,
+    0x1.ffc001545287d49b57972af5145663a0p-1,
+    -0x1.000002p-5,
+  },
+  { // Entry 865
+    0x1.fffaa8aefeed396ffffc636313d0ba6dp-7,
+    0x1.fff0001575499f3d7996e2da11cdeb24p-1,
+    0x1.fffffep-7,
+  },
+  { // Entry 866
+    -0x1.fffaa8aefeed396ffffc636313d0ba6dp-7,
+    0x1.fff0001575499f3d7996e2da11cdeb24p-1,
+    -0x1.fffffep-7,
+  },
+  { // Entry 867
+    0x1.fffaaaaeeeed4ed549c6560f889ee531p-7,
+    0x1.fff000155549f4a28a280e97bcd59c8ap-1,
+    0x1.p-6,
+  },
+  { // Entry 868
+    -0x1.fffaaaaeeeed4ed549c6560f889ee531p-7,
+    0x1.fff000155549f4a28a280e97bcd59c8ap-1,
+    -0x1.p-6,
+  },
+  { // Entry 869
+    0x1.fffaaeaeceed793fde5a1a9ca5bb1ee6p-7,
+    0x1.fff00015154a9f0cae4a62151501cd0ap-1,
+    0x1.000002p-6,
+  },
+  { // Entry 870
+    -0x1.fffaaeaeceed793fde5a1a9ca5bb1ee6p-7,
+    0x1.fff00015154a9f0cae4a62151501cd0ap-1,
+    -0x1.000002p-6,
+  },
+  { // Entry 871
+    0x1.fffffdfaaaaabaaeeeded997feffa35ap-15,
+    0x1.fffffff0000020155544fff49fca38e6p-1,
+    0x1.fffffep-15,
+  },
+  { // Entry 872
+    -0x1.fffffdfaaaaabaaeeeded997feffa35ap-15,
+    0x1.fffffff0000020155544fff49fca38e6p-1,
+    -0x1.fffffep-15,
+  },
+  { // Entry 873
+    0x1.fffffffaaaaaaaaeeeeeeeed4ed4ed4fp-15,
+    0x1.fffffff00000001555555549f49f49f7p-1,
+    0x1.p-14,
+  },
+  { // Entry 874
+    -0x1.fffffffaaaaaaaaeeeeeeeed4ed4ed4fp-15,
+    0x1.fffffff00000001555555549f49f49f7p-1,
+    -0x1.p-14,
+  },
+  { // Entry 875
+    0x1.000001fd5555455777578ccbe7bfc09cp-14,
+    0x1.ffffffefffffc0155515fff4a1496c1cp-1,
+    0x1.000002p-14,
+  },
+  { // Entry 876
+    -0x1.000001fd5555455777578ccbe7bfc09cp-14,
+    0x1.ffffffefffffc0155515fff4a1496c1cp-1,
+    -0x1.000002p-14,
+  },
+  { // Entry 877
+    0x1.fffffdfffffffeaaaaaeaaaaa6aaeef0p-28,
+    0x1.fffffffffffffc000007fffffc015555p-1,
+    0x1.fffffep-28,
+  },
+  { // Entry 878
+    -0x1.fffffdfffffffeaaaaaeaaaaa6aaeef0p-28,
+    0x1.fffffffffffffc000007fffffc015555p-1,
+    -0x1.fffffep-28,
+  },
+  { // Entry 879
+    0x1.fffffffffffffeaaaaaaaaaaaaaaeeeep-28,
+    0x1.fffffffffffffc000000000000015555p-1,
+    0x1.p-27,
+  },
+  { // Entry 880
+    -0x1.fffffffffffffeaaaaaaaaaaaaaaeeeep-28,
+    0x1.fffffffffffffc000000000000015555p-1,
+    -0x1.p-27,
+  },
+  { // Entry 881
+    0x1.000001ffffffff55555155554d557772p-27,
+    0x1.fffffffffffffbffffeffffff0015555p-1,
+    0x1.000002p-27,
+  },
+  { // Entry 882
+    -0x1.000001ffffffff55555155554d557772p-27,
+    0x1.fffffffffffffbffffeffffff0015555p-1,
+    -0x1.000002p-27,
+  },
+  { // Entry 883
+    0x1.fffffdfffffffffaaaaabaaaaa9aaaaep-31,
+    0x1.fffffffffffffff000001ffffff00015p-1,
+    0x1.fffffep-31,
+  },
+  { // Entry 884
+    -0x1.fffffdfffffffffaaaaabaaaaa9aaaaep-31,
+    0x1.fffffffffffffff000001ffffff00015p-1,
+    -0x1.fffffep-31,
+  },
+  { // Entry 885
+    0x1.fffffffffffffffaaaaaaaaaaaaaaaaep-31,
+    0x1.fffffffffffffff00000000000000015p-1,
+    0x1.p-30,
+  },
+  { // Entry 886
+    -0x1.fffffffffffffffaaaaaaaaaaaaaaaaep-31,
+    0x1.fffffffffffffff00000000000000015p-1,
+    -0x1.p-30,
+  },
+  { // Entry 887
+    0x1.000001fffffffffd5555455555355557p-30,
+    0x1.ffffffffffffffefffffbfffffc00015p-1,
+    0x1.000002p-30,
+  },
+  { // Entry 888
+    -0x1.000001fffffffffd5555455555355557p-30,
+    0x1.ffffffffffffffefffffbfffffc00015p-1,
+    -0x1.000002p-30,
+  },
+  { // Entry 889
+    0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    -0x1.fffffep127,
+  },
+  { // Entry 890
+    -0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    0x1.fffffep127,
+  },
+  { // Entry 891
+    -0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    0x1.fffffep127,
+  },
+  { // Entry 892
+    0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    -0x1.fffffep127,
+  },
+  { // Entry 893
+    -0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    0x1.fffffep127,
+  },
+  { // Entry 894
+    0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.b4bf2c79bdfcdaa53ed6c013f65e0963p-1,
+    -0x1.fffffep127,
+  },
+  { // Entry 895
+    -0x1.48ce575202efd93c62f7b88106ea1d4dp-1,
+    -0x1.8877a29e3d7b6defcb528e86f4c3e09ap-1,
+    0x1.fffffcp127,
+  },
+  { // Entry 896
+    0x1.48ce575202efd93c62f7b88106ea1d4dp-1,
+    -0x1.8877a29e3d7b6defcb528e86f4c3e09ap-1,
+    -0x1.fffffcp127,
+  },
+  { // Entry 897
+    -0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    -0x1.fffffffffffdd94849271d08eecf54a1p-1,
+    0x1.921fb6p1,
+  },
+  { // Entry 898
+    0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    -0x1.fffffffffffdd94849271d08eecf54a1p-1,
+    -0x1.921fb6p1,
+  },
+  { // Entry 899
+    0x1.ffffffffffff76521249c7422930ed82p-1,
+    -0x1.777a5cf72cecc4cde3a31e7d5a026142p-25,
+    0x1.921fb6p0,
+  },
+  { // Entry 900
+    -0x1.ffffffffffff76521249c7422930ed82p-1,
+    -0x1.777a5cf72cecc4cde3a31e7d5a026142p-25,
+    -0x1.921fb6p0,
+  },
+  { // Entry 901
+    0x1.aed54b19d5cd7937cbf41ed408ca0a52p-1,
+    0x1.14a27d9da5d4aebce71428f9057b08dap-1,
+    0x1.000002p0,
+  },
+  { // Entry 902
+    -0x1.aed54b19d5cd7937cbf41ed408ca0a52p-1,
+    0x1.14a27d9da5d4aebce71428f9057b08dap-1,
+    -0x1.000002p0,
+  },
+  { // Entry 903
+    0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    0x1.p0,
+  },
+  { // Entry 904
+    -0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.14a280fb5068b923848cdb2ed0e37a53p-1,
+    -0x1.p0,
+  },
+  { // Entry 905
+    0x1.aed547dbee4d0d8680d0813d1e4e21d0p-1,
+    0x1.14a282aa25b11f6312a7a65180e7c3d4p-1,
+    0x1.fffffep-1,
+  },
+  { // Entry 906
+    -0x1.aed547dbee4d0d8680d0813d1e4e21d0p-1,
+    0x1.14a282aa25b11f6312a7a65180e7c3d4p-1,
+    -0x1.fffffep-1,
+  },
+  { // Entry 907
+    0x1.6a09e6ecb41fdd7e681872c854887019p-1,
+    0x1.6a09e5e3335983e5ac92e733e3f24b42p-1,
+    0x1.921fb6p-1,
+  },
+  { // Entry 908
+    -0x1.6a09e6ecb41fdd7e681872c854887019p-1,
+    0x1.6a09e5e3335983e5ac92e733e3f24b42p-1,
+    -0x1.921fb6p-1,
+  },
+  { // Entry 909
+    0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.000002p-126,
+  },
+  { // Entry 910
+    -0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.000002p-126,
+  },
+  { // Entry 911
+    0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-126,
+  },
+  { // Entry 912
+    -0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-126,
+  },
+  { // Entry 913
+    0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.fffffcp-127,
+  },
+  { // Entry 914
+    -0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.fffffcp-127,
+  },
+  { // Entry 915
+    0x1.fffff7ffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.fffff8p-127,
+  },
+  { // Entry 916
+    -0x1.fffff7ffffffffffffffffffffffffffp-127,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.fffff8p-127,
+  },
+  { // Entry 917
+    0x1.ffffffffffffffffffffffffffffffffp-149,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-148,
+  },
+  { // Entry 918
+    -0x1.ffffffffffffffffffffffffffffffffp-149,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-148,
+  },
+  { // Entry 919
+    0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    0x1.p-149,
+  },
+  { // Entry 920
+    -0.0f,
+    0x1.ffffffffffffffffffffffffffffffffp-1,
+    -0x1.p-149,
+  },
+  { // Entry 921
+    0.0,
+    0x1.p0,
+    0.0f,
+  },
+  { // Entry 922
+    -0.0,
+    0x1.p0,
+    -0.0f,
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_sincosf, sincosf_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_sincosf_intel_data)/sizeof(sincosf_intel_data_t); i++) {
+   float fsin, fcos;
+   sincosf(g_sincosf_intel_data[i].call_data, &fsin, &fcos);
+   EXPECT_FLOAT_EQ(g_sincosf_intel_data[i].sin_expected, fsin) << "Failed on element " << i;
+   EXPECT_FLOAT_EQ(g_sincosf_intel_data[i].cos_expected, fcos) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_sinf_test.cpp b/tests/math_sinf_test.cpp
new file mode 100644
index 0000000..bb1e2c9
--- /dev/null
+++ b/tests/math_sinf_test.cpp
@@ -0,0 +1,4395 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  float expected;
+  float call_data;
+} sinf_intel_data_t;
+
+static sinf_intel_data_t g_sinf_intel_data[] = {
+  { // Entry 0
+    -0x1.0003fffffff554d5535552cccf778ccdp-21,
+    -0x1.0004p-21
+  },
+  { // Entry 1
+    0x1.0003fffffff554d5535552cccf778ccdp-21,
+    0x1.0004p-21
+  },
+  { // Entry 2
+    -0x1.d30ca7008af24ef048a7a05eecde2120p-4,
+    -0x1.00cbf0p10
+  },
+  { // Entry 3
+    0x1.d30ca7008af24ef048a7a05eecde2120p-4,
+    0x1.00cbf0p10
+  },
+  { // Entry 4
+    0x1.8d665d0000200efc4478008658c617c7p-1,
+    -0x1.01ee34p2
+  },
+  { // Entry 5
+    -0x1.8d665d0000200efc4478008658c617c7p-1,
+    0x1.01ee34p2
+  },
+  { // Entry 6
+    0x1.ec042ff972e42c23f28f2da4fb75f851p-1,
+    -0x1.18f1f4p4
+  },
+  { // Entry 7
+    -0x1.ec042ff972e42c23f28f2da4fb75f851p-1,
+    0x1.18f1f4p4
+  },
+  { // Entry 8
+    0x1.f0d384240ad9f2dba47b96b08271b41fp-1,
+    -0x1.1df906p2
+  },
+  { // Entry 9
+    -0x1.f0d384240ad9f2dba47b96b08271b41fp-1,
+    0x1.1df906p2
+  },
+  { // Entry 10
+    -0x1.4616daf9cd3ce4e92186e7d8ec3d3ef0p-5,
+    -0x1.3ap6
+  },
+  { // Entry 11
+    0x1.4616daf9cd3ce4e92186e7d8ec3d3ef0p-5,
+    0x1.3ap6
+  },
+  { // Entry 12
+    0x1.df04c5f9de343235f4f8b1797286872bp-1,
+    -0x1.44b096p2
+  },
+  { // Entry 13
+    -0x1.df04c5f9de343235f4f8b1797286872bp-1,
+    0x1.44b096p2
+  },
+  { // Entry 14
+    -0x1.feffbd7334c7043b90a6bc2d76dda7c8p-1,
+    -0x1.821cf6p0
+  },
+  { // Entry 15
+    0x1.feffbd7334c7043b90a6bc2d76dda7c8p-1,
+    0x1.821cf6p0
+  },
+  { // Entry 16
+    0x1.ebac56ffe6f27893c69f68d1d7b4a448p-3,
+    -0x1.829b86p2
+  },
+  { // Entry 17
+    -0x1.ebac56ffe6f27893c69f68d1d7b4a448p-3,
+    0x1.829b86p2
+  },
+  { // Entry 18
+    0x1.b725ccef65b1390912a0f5eaab0e7202p-6,
+    -0x1.8580fep7
+  },
+  { // Entry 19
+    -0x1.b725ccef65b1390912a0f5eaab0e7202p-6,
+    0x1.8580fep7
+  },
+  { // Entry 20
+    0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 21
+    -0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.fffffep127
+  },
+  { // Entry 22
+    0.0f,
+    0x1.p-149
+  },
+  { // Entry 23
+    -0.0f,
+    -0x1.p-149
+  },
+  { // Entry 24
+    -0x1.f83de7c0683d3bd90a769f62a41ac1c3p-1,
+    0x1.000002p52
+  },
+  { // Entry 25
+    0x1.f83de7c0683d3bd90a769f62a41ac1c3p-1,
+    -0x1.000002p52
+  },
+  { // Entry 26
+    -0x1.7dbd11ffde4c20dbb376019f1c654bb0p-2,
+    0x1.000022p62
+  },
+  { // Entry 27
+    0x1.7dbd11ffde4c20dbb376019f1c654bb0p-2,
+    -0x1.000022p62
+  },
+  { // Entry 28
+    0x1.eaf0d5008f2db899e2487da9d3b9cde7p-2,
+    0x1.000150p-1
+  },
+  { // Entry 29
+    -0x1.eaf0d5008f2db899e2487da9d3b9cde7p-2,
+    -0x1.000150p-1
+  },
+  { // Entry 30
+    0x1.ffae8cfefa813da87498df988c3d8f5ep-5,
+    0x1.0001f0p-4
+  },
+  { // Entry 31
+    -0x1.ffae8cfefa813da87498df988c3d8f5ep-5,
+    -0x1.0001f0p-4
+  },
+  { // Entry 32
+    0x1.89c7d6087a861bb6fe794148c3425348p-1,
+    0x1.0003p40
+  },
+  { // Entry 33
+    -0x1.89c7d6087a861bb6fe794148c3425348p-1,
+    -0x1.0003p40
+  },
+  { // Entry 34
+    -0x1.59e1f519ef8b722eae12a404cad937ebp-1,
+    0x1.000380p126
+  },
+  { // Entry 35
+    0x1.59e1f519ef8b722eae12a404cad937ebp-1,
+    -0x1.000380p126
+  },
+  { // Entry 36
+    0x1.0003fffffff554d5535552cccf778ccdp-21,
+    0x1.0004p-21
+  },
+  { // Entry 37
+    -0x1.0003fffffff554d5535552cccf778ccdp-21,
+    -0x1.0004p-21
+  },
+  { // Entry 38
+    0x1.383065027ec4f20ab1c0027d991b805ap-6,
+    0x1.0007c0p9
+  },
+  { // Entry 39
+    -0x1.383065027ec4f20ab1c0027d991b805ap-6,
+    -0x1.0007c0p9
+  },
+  { // Entry 40
+    0x1.eb0397002fdfbae226f069d6cd53c40fp-2,
+    0x1.000cp-1
+  },
+  { // Entry 41
+    -0x1.eb0397002fdfbae226f069d6cd53c40fp-2,
+    -0x1.000cp-1
+  },
+  { // Entry 42
+    0x1.fedc8b0001f7dacee090c5edc3bfa547p-4,
+    0x1.0019p-3
+  },
+  { // Entry 43
+    -0x1.fedc8b0001f7dacee090c5edc3bfa547p-4,
+    -0x1.0019p-3
+  },
+  { // Entry 44
+    0x1.ab471af26ffea23d7643cf614c860b18p-10,
+    0x1.003820p68
+  },
+  { // Entry 45
+    -0x1.ab471af26ffea23d7643cf614c860b18p-10,
+    -0x1.003820p68
+  },
+  { // Entry 46
+    0x1.ff29eefdde3041fc5c75a1f822a5421dp-4,
+    0x1.0040p-3
+  },
+  { // Entry 47
+    -0x1.ff29eefdde3041fc5c75a1f822a5421dp-4,
+    -0x1.0040p-3
+  },
+  { // Entry 48
+    0x1.29070175206b3f198c893e19b4bd6cb8p-13,
+    0x1.01f0p103
+  },
+  { // Entry 49
+    -0x1.29070175206b3f198c893e19b4bd6cb8p-13,
+    -0x1.01f0p103
+  },
+  { // Entry 50
+    -0x1.ffffffffffffaafbe53de74231954709p-1,
+    0x1.04ccbcp18
+  },
+  { // Entry 51
+    0x1.ffffffffffffaafbe53de74231954709p-1,
+    -0x1.04ccbcp18
+  },
+  { // Entry 52
+    0x1.f4f72cad5f5fb17ec608ec7ac1cbca8bp-2,
+    0x1.05bcp-1
+  },
+  { // Entry 53
+    -0x1.f4f72cad5f5fb17ec608ec7ac1cbca8bp-2,
+    -0x1.05bcp-1
+  },
+  { // Entry 54
+    0x1.f896c6689d7e75e351ecc85731254cd3p-1,
+    0x1.07c1f8p119
+  },
+  { // Entry 55
+    -0x1.f896c6689d7e75e351ecc85731254cd3p-1,
+    -0x1.07c1f8p119
+  },
+  { // Entry 56
+    -0x1.267593f4d59c7de6170090a6a084cdcap-14,
+    0x1.080180p23
+  },
+  { // Entry 57
+    0x1.267593f4d59c7de6170090a6a084cdcap-14,
+    -0x1.080180p23
+  },
+  { // Entry 58
+    0x1.fc86372a841549410c12dbec6fe80dc5p-2,
+    0x1.0a14p-1
+  },
+  { // Entry 59
+    -0x1.fc86372a841549410c12dbec6fe80dc5p-2,
+    -0x1.0a14p-1
+  },
+  { // Entry 60
+    0x1.bca28f0004316bae8df6a2352cca1382p-1,
+    0x1.0b770ap1
+  },
+  { // Entry 61
+    -0x1.bca28f0004316bae8df6a2352cca1382p-1,
+    -0x1.0b770ap1
+  },
+  { // Entry 62
+    -0x1.fade9abd67526d37189df004b51d9d5ap-1,
+    0x1.0ddcp96
+  },
+  { // Entry 63
+    0x1.fade9abd67526d37189df004b51d9d5ap-1,
+    -0x1.0ddcp96
+  },
+  { // Entry 64
+    0x1.bf683cffffec6e8672a49f08aae49c46p-1,
+    0x1.1024p0
+  },
+  { // Entry 65
+    -0x1.bf683cffffec6e8672a49f08aae49c46p-1,
+    -0x1.1024p0
+  },
+  { // Entry 66
+    -0x1.f14407f6441e92f480d2e22859d67a39p-1,
+    0x1.109cc4p4
+  },
+  { // Entry 67
+    0x1.f14407f6441e92f480d2e22859d67a39p-1,
+    -0x1.109cc4p4
+  },
+  { // Entry 68
+    -0x1.ff7e7b9983a7c2ebecfab1a0b0af3c4dp-1,
+    0x1.13bfb2p4
+  },
+  { // Entry 69
+    0x1.ff7e7b9983a7c2ebecfab1a0b0af3c4dp-1,
+    -0x1.13bfb2p4
+  },
+  { // Entry 70
+    0x1.c4942b1e9ec175aa7d3fd75f2e37e566p-1,
+    0x1.1590p0
+  },
+  { // Entry 71
+    -0x1.c4942b1e9ec175aa7d3fd75f2e37e566p-1,
+    -0x1.1590p0
+  },
+  { // Entry 72
+    0x1.fff8d36866faaac8c17e1267498bd132p-1,
+    0x1.18p85
+  },
+  { // Entry 73
+    -0x1.fff8d36866faaac8c17e1267498bd132p-1,
+    -0x1.18p85
+  },
+  { // Entry 74
+    0x1.c78d962546ce51b882c9054eccd829b1p-1,
+    0x1.18c8p0
+  },
+  { // Entry 75
+    -0x1.c78d962546ce51b882c9054eccd829b1p-1,
+    -0x1.18c8p0
+  },
+  { // Entry 76
+    0x1.c7cb99a111f26527b805734962fb12a0p-1,
+    0x1.190cp0
+  },
+  { // Entry 77
+    -0x1.c7cb99a111f26527b805734962fb12a0p-1,
+    -0x1.190cp0
+  },
+  { // Entry 78
+    -0x1.70898100055943898aa7053017ecba69p-1,
+    0x1.1e8f14p62
+  },
+  { // Entry 79
+    0x1.70898100055943898aa7053017ecba69p-1,
+    -0x1.1e8f14p62
+  },
+  { // Entry 80
+    0x1.cdef1e4eb37e9f2249656c27d62b1895p-1,
+    0x1.1ff8p0
+  },
+  { // Entry 81
+    -0x1.cdef1e4eb37e9f2249656c27d62b1895p-1,
+    -0x1.1ff8p0
+  },
+  { // Entry 82
+    -0x1.5df0dd60f122bf79d1ddcf295c34cb0ep-1,
+    0x1.2244a6p59
+  },
+  { // Entry 83
+    0x1.5df0dd60f122bf79d1ddcf295c34cb0ep-1,
+    -0x1.2244a6p59
+  },
+  { // Entry 84
+    -0x1.fb8dd74f1b091a7b0f9f9d44db84661cp-3,
+    0x1.287ae0p13
+  },
+  { // Entry 85
+    0x1.fb8dd74f1b091a7b0f9f9d44db84661cp-3,
+    -0x1.287ae0p13
+  },
+  { // Entry 86
+    -0x1.fffffffffffff5c0d2630ee0a1fb4e7bp-1,
+    0x1.2d97c8p2
+  },
+  { // Entry 87
+    0x1.fffffffffffff5c0d2630ee0a1fb4e7bp-1,
+    -0x1.2d97c8p2
+  },
+  { // Entry 88
+    -0x1.99bc5b961b1ac296dbe1980fd2c890a0p-26,
+    0x1.2d97c8p3
+  },
+  { // Entry 89
+    0x1.99bc5b961b1ac296dbe1980fd2c890a0p-26,
+    -0x1.2d97c8p3
+  },
+  { // Entry 90
+    0x1.ffd5158b81944ff6b4833fdf1faa9281p-1,
+    0x1.32cdc6p18
+  },
+  { // Entry 91
+    -0x1.ffd5158b81944ff6b4833fdf1faa9281p-1,
+    -0x1.32cdc6p18
+  },
+  { // Entry 92
+    0x1.e191e77f58f479b564ec538b671f98afp-14,
+    0x1.37efd8p100
+  },
+  { // Entry 93
+    -0x1.e191e77f58f479b564ec538b671f98afp-14,
+    -0x1.37efd8p100
+  },
+  { // Entry 94
+    0x1.fffe974dceb10d4877a75bc77870ffebp-1,
+    0x1.38p11
+  },
+  { // Entry 95
+    -0x1.fffe974dceb10d4877a75bc77870ffebp-1,
+    -0x1.38p11
+  },
+  { // Entry 96
+    -0x1.b63f2c3f537b10eec2fbf340e4898644p-18,
+    0x1.3d72b8p15
+  },
+  { // Entry 97
+    0x1.b63f2c3f537b10eec2fbf340e4898644p-18,
+    -0x1.3d72b8p15
+  },
+  { // Entry 98
+    -0x1.e0208cff17f9186218945af9256d736cp-1,
+    0x1.444b20p7
+  },
+  { // Entry 99
+    0x1.e0208cff17f9186218945af9256d736cp-1,
+    -0x1.444b20p7
+  },
+  { // Entry 100
+    0x1.fffff9002cf87dade6f62eb709dc2aa7p-1,
+    0x1.46b71ep4
+  },
+  { // Entry 101
+    -0x1.fffff9002cf87dade6f62eb709dc2aa7p-1,
+    -0x1.46b71ep4
+  },
+  { // Entry 102
+    0x1.c875581a762211dd5caaf9abde5cf656p-21,
+    0x1.4d0242p7
+  },
+  { // Entry 103
+    -0x1.c875581a762211dd5caaf9abde5cf656p-21,
+    -0x1.4d0242p7
+  },
+  { // Entry 104
+    -0x1.6a6f79000053a3842566f1e018d6359fp-1,
+    0x1.511e8ep28
+  },
+  { // Entry 105
+    0x1.6a6f79000053a3842566f1e018d6359fp-1,
+    -0x1.511e8ep28
+  },
+  { // Entry 106
+    0x1.fffe9ffa6b569dd8c720d68e80bd9a63p-1,
+    0x1.5354d0p100
+  },
+  { // Entry 107
+    -0x1.fffe9ffa6b569dd8c720d68e80bd9a63p-1,
+    -0x1.5354d0p100
+  },
+  { // Entry 108
+    0x1.3b4d58fffff29126460f258ec4423e9ap-1,
+    0x1.53ad5cp-1
+  },
+  { // Entry 109
+    -0x1.3b4d58fffff29126460f258ec4423e9ap-1,
+    -0x1.53ad5cp-1
+  },
+  { // Entry 110
+    -0x1.fffeb762e93ead5ac70f85064fc79cffp-1,
+    0x1.60p3
+  },
+  { // Entry 111
+    0x1.fffeb762e93ead5ac70f85064fc79cffp-1,
+    -0x1.60p3
+  },
+  { // Entry 112
+    0x1.1772377ffe5b1f436c0149e328446f74p-20,
+    0x1.6c6cbcp6
+  },
+  { // Entry 113
+    -0x1.1772377ffe5b1f436c0149e328446f74p-20,
+    -0x1.6c6cbcp6
+  },
+  { // Entry 114
+    0x1.77fffdfffffff78d0577d9552663ea3ep-26,
+    0x1.77fffep-26
+  },
+  { // Entry 115
+    -0x1.77fffdfffffff78d0577d9552663ea3ep-26,
+    -0x1.77fffep-26
+  },
+  { // Entry 116
+    -0x1.ff04979385946d0568c153bf9e125fccp-1,
+    0x1.77fffep4
+  },
+  { // Entry 117
+    0x1.ff04979385946d0568c153bf9e125fccp-1,
+    -0x1.77fffep4
+  },
+  { // Entry 118
+    0x1.feb7a96a577f715fa7ad8788294c045bp-1,
+    0x1.7ffffep0
+  },
+  { // Entry 119
+    -0x1.feb7a96a577f715fa7ad8788294c045bp-1,
+    -0x1.7ffffep0
+  },
+  { // Entry 120
+    0x1.feb7eb54653509617faf3268344437fcp-1,
+    0x1.8001d0p0
+  },
+  { // Entry 121
+    -0x1.feb7eb54653509617faf3268344437fcp-1,
+    -0x1.8001d0p0
+  },
+  { // Entry 122
+    0x1.ff6535998ea004d48763597b6df9cd65p-1,
+    0x1.807ffep13
+  },
+  { // Entry 123
+    -0x1.ff6535998ea004d48763597b6df9cd65p-1,
+    -0x1.807ffep13
+  },
+  { // Entry 124
+    0x1.ff76ed9a192e9a2126bcfc0f306240d4p-1,
+    0x1.866a42p0
+  },
+  { // Entry 125
+    -0x1.ff76ed9a192e9a2126bcfc0f306240d4p-1,
+    -0x1.866a42p0
+  },
+  { // Entry 126
+    0x1.ace844f1eb6c3077277929ff4ade3f41p-5,
+    0x1.8864p35
+  },
+  { // Entry 127
+    -0x1.ace844f1eb6c3077277929ff4ade3f41p-5,
+    -0x1.8864p35
+  },
+  { // Entry 128
+    0x1.e0d108f196fd3cbcb7c2c76aee738205p-5,
+    0x1.8a9b56p1
+  },
+  { // Entry 129
+    -0x1.e0d108f196fd3cbcb7c2c76aee738205p-5,
+    -0x1.8a9b56p1
+  },
+  { // Entry 130
+    -0x1.6a09af0006fe0b47c81d8695c017a8dfp-1,
+    0x1.8e96eep9
+  },
+  { // Entry 131
+    0x1.6a09af0006fe0b47c81d8695c017a8dfp-1,
+    -0x1.8e96eep9
+  },
+  { // Entry 132
+    -0x1.dd59dceecf3fbd015e9e29b37aaf511ap-9,
+    0x1.91e40ap2
+  },
+  { // Entry 133
+    0x1.dd59dceecf3fbd015e9e29b37aaf511ap-9,
+    -0x1.91e40ap2
+  },
+  { // Entry 134
+    -0x1.fb73f1187e5053bacb752b89c6a3de57p-9,
+    0x1.91fffep3
+  },
+  { // Entry 135
+    0x1.fb73f1187e5053bacb752b89c6a3de57p-9,
+    -0x1.91fffep3
+  },
+  { // Entry 136
+    -0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    0x1.921fb6p1
+  },
+  { // Entry 137
+    0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    -0x1.921fb6p1
+  },
+  { // Entry 138
+    -0x1.ffffff79db917265e675574b8d83fa6ep-1,
+    0x1.94fd7cp100
+  },
+  { // Entry 139
+    0x1.ffffff79db917265e675574b8d83fa6ep-1,
+    -0x1.94fd7cp100
+  },
+  { // Entry 140
+    0x1.ffffffffffd7e83678a38329c1e093b5p-1,
+    0x1.986834p6
+  },
+  { // Entry 141
+    -0x1.ffffffffffd7e83678a38329c1e093b5p-1,
+    -0x1.986834p6
+  },
+  { // Entry 142
+    0x1.16ae29144d3aeb0ef741c3e2aba34078p-24,
+    0x1.9a48dep17
+  },
+  { // Entry 143
+    -0x1.16ae29144d3aeb0ef741c3e2aba34078p-24,
+    -0x1.9a48dep17
+  },
+  { // Entry 144
+    0x1.ff7ad398fd589528bb07db1e0bdd40f5p-1,
+    0x1.9daa38p0
+  },
+  { // Entry 145
+    -0x1.ff7ad398fd589528bb07db1e0bdd40f5p-1,
+    -0x1.9daa38p0
+  },
+  { // Entry 146
+    0x1.9df5f10000002f4b7421dfe9e955b60dp-4,
+    0x1.9eab2ep-4
+  },
+  { // Entry 147
+    -0x1.9df5f10000002f4b7421dfe9e955b60dp-4,
+    -0x1.9eab2ep-4
+  },
+  { // Entry 148
+    0x1.76dcf7000053c428e30ef99d9cf91accp-1,
+    0x1.a499p-1
+  },
+  { // Entry 149
+    -0x1.76dcf7000053c428e30ef99d9cf91accp-1,
+    -0x1.a499p-1
+  },
+  { // Entry 150
+    0x1.a9d4510000a2a82c391a9b36186ead65p-5,
+    0x1.aa0578p-5
+  },
+  { // Entry 151
+    -0x1.a9d4510000a2a82c391a9b36186ead65p-5,
+    -0x1.aa0578p-5
+  },
+  { // Entry 152
+    0x1.6a097dcc8b1356712fc20f82c4f87e4dp-1,
+    0x1.b4ae70p6
+  },
+  { // Entry 153
+    -0x1.6a097dcc8b1356712fc20f82c4f87e4dp-1,
+    -0x1.b4ae70p6
+  },
+  { // Entry 154
+    0x1.849926ffffeb95860262a99770a8c9c3p-1,
+    0x1.b936dap-1
+  },
+  { // Entry 155
+    -0x1.849926ffffeb95860262a99770a8c9c3p-1,
+    -0x1.b936dap-1
+  },
+  { // Entry 156
+    -0x1.dac40ef1e040315f07519a99c2034fffp-5,
+    0x1.ba2784p82
+  },
+  { // Entry 157
+    0x1.dac40ef1e040315f07519a99c2034fffp-5,
+    -0x1.ba2784p82
+  },
+  { // Entry 158
+    0x1.81074b0346f07390395b4ee2b50b3f94p-14,
+    0x1.bdb44ap107
+  },
+  { // Entry 159
+    -0x1.81074b0346f07390395b4ee2b50b3f94p-14,
+    -0x1.bdb44ap107
+  },
+  { // Entry 160
+    0x1.235debb727b95daaec183bfa4e728be1p-9,
+    0x1.bdbefep119
+  },
+  { // Entry 161
+    -0x1.235debb727b95daaec183bfa4e728be1p-9,
+    -0x1.bdbefep119
+  },
+  { // Entry 162
+    -0x1.99663da94db5290730b029513370e863p-23,
+    0x1.beeeeep80
+  },
+  { // Entry 163
+    0x1.99663da94db5290730b029513370e863p-23,
+    -0x1.beeeeep80
+  },
+  { // Entry 164
+    -0x1.62faa0ffdc55a4c54f1229fc0302bd5fp-2,
+    0x1.bf6fd0p1
+  },
+  { // Entry 165
+    0x1.62faa0ffdc55a4c54f1229fc0302bd5fp-2,
+    -0x1.bf6fd0p1
+  },
+  { // Entry 166
+    -0x1.c6d444de6b90c7b8b43402ef749a4c3dp-5,
+    0x1.bffffep45
+  },
+  { // Entry 167
+    0x1.c6d444de6b90c7b8b43402ef749a4c3dp-5,
+    -0x1.bffffep45
+  },
+  { // Entry 168
+    0x1.ffffffffffffa3c7657b85e5b44bbd44p-1,
+    0x1.c463acp3
+  },
+  { // Entry 169
+    -0x1.ffffffffffffa3c7657b85e5b44bbd44p-1,
+    -0x1.c463acp3
+  },
+  { // Entry 170
+    0x1.913648ffff9e23787f5ddb75dc55eec8p-1,
+    0x1.cd0a0cp-1
+  },
+  { // Entry 171
+    -0x1.913648ffff9e23787f5ddb75dc55eec8p-1,
+    -0x1.cd0a0cp-1
+  },
+  { // Entry 172
+    -0x1.a1d47cfd2825f1c3e2835e943b9669efp-5,
+    0x1.d41818p12
+  },
+  { // Entry 173
+    0x1.a1d47cfd2825f1c3e2835e943b9669efp-5,
+    -0x1.d41818p12
+  },
+  { // Entry 174
+    0x1.6a22db000036a9592db722e2d9be4869p-1,
+    0x1.e62944p8
+  },
+  { // Entry 175
+    -0x1.6a22db000036a9592db722e2d9be4869p-1,
+    -0x1.e62944p8
+  },
+  { // Entry 176
+    0x1.d4de8affffffd96f83ba442fdf2f7101p-2,
+    0x1.e7061ep-2
+  },
+  { // Entry 177
+    -0x1.d4de8affffffd96f83ba442fdf2f7101p-2,
+    -0x1.e7061ep-2
+  },
+  { // Entry 178
+    -0x1.e3ce04f1b94e1d82f0001cb99fed9275p-5,
+    0x1.e7fffep95
+  },
+  { // Entry 179
+    0x1.e3ce04f1b94e1d82f0001cb99fed9275p-5,
+    -0x1.e7fffep95
+  },
+  { // Entry 180
+    0x1.e97362ffff5d46e1e98c8a8c94478a44p-5,
+    0x1.e9be0ep-5
+  },
+  { // Entry 181
+    -0x1.e97362ffff5d46e1e98c8a8c94478a44p-5,
+    -0x1.e9be0ep-5
+  },
+  { // Entry 182
+    -0x1.57975cfefd7e705f3eb03a9e8e48a18cp-1,
+    0x1.eb1dbep12
+  },
+  { // Entry 183
+    0x1.57975cfefd7e705f3eb03a9e8e48a18cp-1,
+    -0x1.eb1dbep12
+  },
+  { // Entry 184
+    -0x1.6a1012e4b69b086c3dc0427aba80bc96p-1,
+    0x1.eb1e8ap12
+  },
+  { // Entry 185
+    0x1.6a1012e4b69b086c3dc0427aba80bc96p-1,
+    -0x1.eb1e8ap12
+  },
+  { // Entry 186
+    -0x1.9f42e4f467696ad36a70ac8b70e0cd32p-1,
+    0x1.effc8ap24
+  },
+  { // Entry 187
+    0x1.9f42e4f467696ad36a70ac8b70e0cd32p-1,
+    -0x1.effc8ap24
+  },
+  { // Entry 188
+    0x1.cbadb8ef8f3e358d2b8be493c11b57b1p-6,
+    0x1.f5c1c4p3
+  },
+  { // Entry 189
+    -0x1.cbadb8ef8f3e358d2b8be493c11b57b1p-6,
+    -0x1.f5c1c4p3
+  },
+  { // Entry 190
+    0x1.5aee2cfff087e59dfcd856cbfe4544dcp-2,
+    0x1.f7fffep111
+  },
+  { // Entry 191
+    -0x1.5aee2cfff087e59dfcd856cbfe4544dcp-2,
+    -0x1.f7fffep111
+  },
+  { // Entry 192
+    0x1.26db7d00bb06743fee581a888e2378f8p-1,
+    0x1.f92518p24
+  },
+  { // Entry 193
+    -0x1.26db7d00bb06743fee581a888e2378f8p-1,
+    -0x1.f92518p24
+  },
+  { // Entry 194
+    0x1.fffffffffffffebccf78a432a67858bbp-1,
+    0x1.f9cbe2p7
+  },
+  { // Entry 195
+    -0x1.fffffffffffffebccf78a432a67858bbp-1,
+    -0x1.f9cbe2p7
+  },
+  { // Entry 196
+    -0x1.1fa3bb9a07e77fd667f493622c9029ffp-27,
+    0x1.f9cbe2p8
+  },
+  { // Entry 197
+    0x1.1fa3bb9a07e77fd667f493622c9029ffp-27,
+    -0x1.f9cbe2p8
+  },
+  { // Entry 198
+    0x1.9ec29af1e15dd67f17e32047d9ff8db7p-1,
+    0x1.fad160p24
+  },
+  { // Entry 199
+    -0x1.9ec29af1e15dd67f17e32047d9ff8db7p-1,
+    -0x1.fad160p24
+  },
+  { // Entry 200
+    0x1.fbc2780f4bf8bc24d3fccc17f9e77f32p-1,
+    0x1.fee5bap2
+  },
+  { // Entry 201
+    -0x1.fbc2780f4bf8bc24d3fccc17f9e77f32p-1,
+    -0x1.fee5bap2
+  },
+  { // Entry 202
+    0x1.a8d7c10005ada8f7d4912bf603a315fep-1,
+    0x1.ff0caep10
+  },
+  { // Entry 203
+    -0x1.a8d7c10005ada8f7d4912bf603a315fep-1,
+    -0x1.ff0caep10
+  },
+  { // Entry 204
+    -0x1.56b02d00045da146e855d3770c9646fap-1,
+    0x1.ff8406p80
+  },
+  { // Entry 205
+    0x1.56b02d00045da146e855d3770c9646fap-1,
+    -0x1.ff8406p80
+  },
+  { // Entry 206
+    0x1.c02749ff4c4c8fcbb471610884d8e0bdp-3,
+    0x1.ff9ffep40
+  },
+  { // Entry 207
+    -0x1.c02749ff4c4c8fcbb471610884d8e0bdp-3,
+    -0x1.ff9ffep40
+  },
+  { // Entry 208
+    -0x1.388e710058342aa5b69afe3e2090a457p-1,
+    0x1.ffbd58p24
+  },
+  { // Entry 209
+    0x1.388e710058342aa5b69afe3e2090a457p-1,
+    -0x1.ffbd58p24
+  },
+  { // Entry 210
+    0x1.9e805aef3282d4ced40272702f174f53p-6,
+    0x1.ffdd7ep72
+  },
+  { // Entry 211
+    -0x1.9e805aef3282d4ced40272702f174f53p-6,
+    -0x1.ffdd7ep72
+  },
+  { // Entry 212
+    -0x1.fb3aef016b8ce66370ab61974e8ee0b2p-6,
+    0x1.ffdffep91
+  },
+  { // Entry 213
+    0x1.fb3aef016b8ce66370ab61974e8ee0b2p-6,
+    -0x1.ffdffep91
+  },
+  { // Entry 214
+    -0x1.e43148da53f422356edd3bdbaef3b2fap-3,
+    0x1.fff77ep23
+  },
+  { // Entry 215
+    0x1.e43148da53f422356edd3bdbaef3b2fap-3,
+    -0x1.fff77ep23
+  },
+  { // Entry 216
+    0x1.d6e1864764d24b4de18cb4c1903a7957p-1,
+    0x1.fffe3ep5
+  },
+  { // Entry 217
+    -0x1.d6e1864764d24b4de18cb4c1903a7957p-1,
+    -0x1.fffe3ep5
+  },
+  { // Entry 218
+    -0x1.ffff49c52f585e672d7185448d46e977p-1,
+    0x1.fffe3ep41
+  },
+  { // Entry 219
+    0x1.ffff49c52f585e672d7185448d46e977p-1,
+    -0x1.fffe3ep41
+  },
+  { // Entry 220
+    0x1.afc6a99cbade83b6be92b2ca45167988p-5,
+    0x1.fffe3ep45
+  },
+  { // Entry 221
+    -0x1.afc6a99cbade83b6be92b2ca45167988p-5,
+    -0x1.fffe3ep45
+  },
+  { // Entry 222
+    -0x1.53a29e54b4b142830dc796c9ed5fc59bp-9,
+    0x1.fffe7ep103
+  },
+  { // Entry 223
+    0x1.53a29e54b4b142830dc796c9ed5fc59bp-9,
+    -0x1.fffe7ep103
+  },
+  { // Entry 224
+    -0x1.47e89fd5047c4c94b5c0f61e375f2849p-11,
+    0x1.fffe7ep126
+  },
+  { // Entry 225
+    0x1.47e89fd5047c4c94b5c0f61e375f2849p-11,
+    -0x1.fffe7ep126
+  },
+  { // Entry 226
+    0x1.a4256c90c37410ce957c0b2501937618p-8,
+    0x1.ffff8ep40
+  },
+  { // Entry 227
+    -0x1.a4256c90c37410ce957c0b2501937618p-8,
+    -0x1.ffff8ep40
+  },
+  { // Entry 228
+    -0x1.d2bd84f5018f40c94c7f6e4552ef8e91p-3,
+    0x1.ffffa4p23
+  },
+  { // Entry 229
+    0x1.d2bd84f5018f40c94c7f6e4552ef8e91p-3,
+    -0x1.ffffa4p23
+  },
+  { // Entry 230
+    0x1.ffaa8cffd381ebe7b2d6a3e69bda3887p-5,
+    0x1.ffffdep-5
+  },
+  { // Entry 231
+    -0x1.ffaa8cffd381ebe7b2d6a3e69bda3887p-5,
+    -0x1.ffffdep-5
+  },
+  { // Entry 232
+    0x1.fa8d3ca23be2a84d37f0c04e97bab5e5p-1,
+    0x1.fffff0p2
+  },
+  { // Entry 233
+    -0x1.fa8d3ca23be2a84d37f0c04e97bab5e5p-1,
+    -0x1.fffff0p2
+  },
+  { // Entry 234
+    -0x1.ff978ecd320ad2d70c200824e4010843p-1,
+    0x1.fffff0p7
+  },
+  { // Entry 235
+    0x1.ff978ecd320ad2d70c200824e4010843p-1,
+    -0x1.fffff0p7
+  },
+  { // Entry 236
+    0x1.d18f76ffc6e4ba0a3134e5be21b5bc8fp-1,
+    0x1.fffff6p0
+  },
+  { // Entry 237
+    -0x1.d18f76ffc6e4ba0a3134e5be21b5bc8fp-1,
+    -0x1.fffff6p0
+  },
+  { // Entry 238
+    0x1.eaee8200b8dba5138f9ada42a22ab319p-2,
+    0x1.fffffap-2
+  },
+  { // Entry 239
+    -0x1.eaee8200b8dba5138f9ada42a22ab319p-2,
+    -0x1.fffffap-2
+  },
+  { // Entry 240
+    -0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.fffffep127
+  },
+  { // Entry 241
+    0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 242
+    -0.0f,
+    -0x1.p-149
+  },
+  { // Entry 243
+    0.0f,
+    0x1.p-149
+  },
+  { // Entry 244
+    0.0,
+    0.0
+  },
+  { // Entry 245
+    0.0f,
+    0x1.p-149
+  },
+  { // Entry 246
+    -0.0f,
+    -0x1.p-149
+  },
+  { // Entry 247
+    -0x1.000001ffffffffffffffffffffffffffp-126,
+    -0x1.000002p-126
+  },
+  { // Entry 248
+    0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.000002p-126
+  },
+  { // Entry 249
+    -0x1.ffffffffffffffffffffffffffffffffp-127,
+    -0x1.p-126
+  },
+  { // Entry 250
+    0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.p-126
+  },
+  { // Entry 251
+    -0x1.fffffbffffffffffffffffffffffffffp-127,
+    -0x1.fffffcp-127
+  },
+  { // Entry 252
+    0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.fffffcp-127
+  },
+  { // Entry 253
+    0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.fffffcp-127
+  },
+  { // Entry 254
+    -0x1.fffffbffffffffffffffffffffffffffp-127,
+    -0x1.fffffcp-127
+  },
+  { // Entry 255
+    0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.p-126
+  },
+  { // Entry 256
+    -0x1.ffffffffffffffffffffffffffffffffp-127,
+    -0x1.p-126
+  },
+  { // Entry 257
+    0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.000002p-126
+  },
+  { // Entry 258
+    -0x1.000001ffffffffffffffffffffffffffp-126,
+    -0x1.000002p-126
+  },
+  { // Entry 259
+    0x1.999999d44f3058c789014b7d0e22fec3p-13,
+    0x1.99999ap-13
+  },
+  { // Entry 260
+    -0x1.999999d44f3058c789014b7d0e22fec3p-13,
+    -0x1.99999ap-13
+  },
+  { // Entry 261
+    0x1.999999513cc173e51bb9955b066f1db8p-12,
+    0x1.99999ap-12
+  },
+  { // Entry 262
+    -0x1.999999513cc173e51bb9955b066f1db8p-12,
+    -0x1.99999ap-12
+  },
+  { // Entry 263
+    0x1.333332d91685321e5fc397d20a5af1e6p-11,
+    0x1.333334p-11
+  },
+  { // Entry 264
+    -0x1.333332d91685321e5fc397d20a5af1e6p-11,
+    -0x1.333334p-11
+  },
+  { // Entry 265
+    0x1.99999744f306dc03e9ef70897f78299ep-11,
+    0x1.99999ap-11
+  },
+  { // Entry 266
+    -0x1.99999744f306dc03e9ef70897f78299ep-11,
+    -0x1.99999ap-11
+  },
+  { // Entry 267
+    0x1.fffffaaaaaaeeeeeed4ed4edab4c7bd6p-11,
+    0x1.p-10
+  },
+  { // Entry 268
+    -0x1.fffffaaaaaaeeeeeed4ed4edab4c7bd6p-11,
+    -0x1.p-10
+  },
+  { // Entry 269
+    0x1.33332f645a18c3b0ccfc0a3cf7b2e91bp-10,
+    0x1.333334p-10
+  },
+  { // Entry 270
+    -0x1.33332f645a18c3b0ccfc0a3cf7b2e91bp-10,
+    -0x1.333334p-10
+  },
+  { // Entry 271
+    0x1.666660aec330821c7a100cf488c380ebp-10,
+    0x1.666668p-10
+  },
+  { // Entry 272
+    -0x1.666660aec330821c7a100cf488c380ebp-10,
+    -0x1.666668p-10
+  },
+  { // Entry 273
+    0x1.99999113cc034144fdbdc8a1dc713253p-10,
+    0x1.99999cp-10
+  },
+  { // Entry 274
+    -0x1.99999113cc034144fdbdc8a1dc713253p-10,
+    -0x1.99999cp-10
+  },
+  { // Entry 275
+    0x1.ccccbc72b05dd0951a9c5e65560c56e3p-10,
+    0x1.ccccccp-10
+  },
+  { // Entry 276
+    -0x1.ccccbc72b05dd0951a9c5e65560c56e3p-10,
+    -0x1.ccccccp-10
+  },
+  { // Entry 277
+    0x1.0665ae3615b5b7de52798064dfc59b29p-7,
+    0x1.066666p-7
+  },
+  { // Entry 278
+    -0x1.0665ae3615b5b7de52798064dfc59b29p-7,
+    -0x1.066666p-7
+  },
+  { // Entry 279
+    0x1.ccc8e8ae92586d8d66b6ad0aedcb0d94p-7,
+    0x1.ccccccp-7
+  },
+  { // Entry 280
+    -0x1.ccc8e8ae92586d8d66b6ad0aedcb0d94p-7,
+    -0x1.ccccccp-7
+  },
+  { // Entry 281
+    0x1.4993e70f7b17c10af9f97fc7b33b822bp-6,
+    0x1.499998p-6
+  },
+  { // Entry 282
+    -0x1.4993e70f7b17c10af9f97fc7b33b822bp-6,
+    -0x1.499998p-6
+  },
+  { // Entry 283
+    0x1.acc043f8b2d89ad5143c030e9766fc11p-6,
+    0x1.acccccp-6
+  },
+  { // Entry 284
+    -0x1.acc043f8b2d89ad5143c030e9766fc11p-6,
+    -0x1.acccccp-6
+  },
+  { // Entry 285
+    0x1.07f44d67cf41afbc0c95108b99f91b01p-5,
+    0x1.08p-5
+  },
+  { // Entry 286
+    -0x1.07f44d67cf41afbc0c95108b99f91b01p-5,
+    -0x1.08p-5
+  },
+  { // Entry 287
+    0x1.3985fead44fa2b851e651acba369d769p-5,
+    0x1.39999ap-5
+  },
+  { // Entry 288
+    -0x1.3985fead44fa2b851e651acba369d769p-5,
+    -0x1.39999ap-5
+  },
+  { // Entry 289
+    0x1.6b14beb5d40d745096247e59b622828bp-5,
+    0x1.6b3334p-5
+  },
+  { // Entry 290
+    -0x1.6b14beb5d40d745096247e59b622828bp-5,
+    -0x1.6b3334p-5
+  },
+  { // Entry 291
+    0x1.9ca01671a7995fc97cebd69729cc4309p-5,
+    0x1.9ccccep-5
+  },
+  { // Entry 292
+    -0x1.9ca01671a7995fc97cebd69729cc4309p-5,
+    -0x1.9ccccep-5
+  },
+  { // Entry 293
+    0x1.ce278cd9eb2cbd0c6a4e1279f690e856p-5,
+    0x1.ce6666p-5
+  },
+  { // Entry 294
+    -0x1.ce278cd9eb2cbd0c6a4e1279f690e856p-5,
+    -0x1.ce6666p-5
+  },
+  { // Entry 295
+    0x1.43c1e9972391aa8ecd8a9ccba907920ap-1,
+    0x1.5e7fc4p-1
+  },
+  { // Entry 296
+    -0x1.43c1e9972391aa8ecd8a9ccba907920ap-1,
+    -0x1.5e7fc4p-1
+  },
+  { // Entry 297
+    0x1.ee3d6bb21c64b2382efcff0cdf30ce0bp-1,
+    0x1.4e7fc4p0
+  },
+  { // Entry 298
+    -0x1.ee3d6bb21c64b2382efcff0cdf30ce0bp-1,
+    -0x1.4e7fc4p0
+  },
+  { // Entry 299
+    0x1.df8e2323e4bf1a538a100ec1bf3494a9p-1,
+    0x1.edbfa6p0
+  },
+  { // Entry 300
+    -0x1.df8e2323e4bf1a538a100ec1bf3494a9p-1,
+    -0x1.edbfa6p0
+  },
+  { // Entry 301
+    0x1.1d347aa02feb3bb1750d25509435da88p-1,
+    0x1.467fc4p1
+  },
+  { // Entry 302
+    -0x1.1d347aa02feb3bb1750d25509435da88p-1,
+    -0x1.467fc4p1
+  },
+  { // Entry 303
+    -0x1.ffea08e1c97f4c4de01961cc3e7b04dcp-6,
+    0x1.961fb4p1
+  },
+  { // Entry 304
+    0x1.ffea08e1c97f4c4de01961cc3e7b04dcp-6,
+    -0x1.961fb4p1
+  },
+  { // Entry 305
+    -0x1.3734cbced9c0f484e5f762e00216e620p-1,
+    0x1.e5bfa4p1
+  },
+  { // Entry 306
+    0x1.3734cbced9c0f484e5f762e00216e620p-1,
+    -0x1.e5bfa4p1
+  },
+  { // Entry 307
+    -0x1.e9d2592bec10c3acb15c5852239a2aa8p-1,
+    0x1.1aafcap2
+  },
+  { // Entry 308
+    0x1.e9d2592bec10c3acb15c5852239a2aa8p-1,
+    -0x1.1aafcap2
+  },
+  { // Entry 309
+    -0x1.e4ece208d0c4913ab019cab0ce9c785ep-1,
+    0x1.427fc2p2
+  },
+  { // Entry 310
+    0x1.e4ece208d0c4913ab019cab0ce9c785ep-1,
+    -0x1.427fc2p2
+  },
+  { // Entry 311
+    -0x1.2a5a02d392b54f641a0d88bd4ac6c2e1p-1,
+    0x1.6a4fbap2
+  },
+  { // Entry 312
+    0x1.2a5a02d392b54f641a0d88bd4ac6c2e1p-1,
+    -0x1.6a4fbap2
+  },
+  { // Entry 313
+    -0x1.263123df22d13ed329c665c83c0e71e8p-1,
+    0x1.6af2f0p2
+  },
+  { // Entry 314
+    0x1.263123df22d13ed329c665c83c0e71e8p-1,
+    -0x1.6af2f0p2
+  },
+  { // Entry 315
+    -0x1.e18e67b508ffc9e42f6c9e72f8e545f3p-1,
+    0x1.43c62ap2
+  },
+  { // Entry 316
+    0x1.e18e67b508ffc9e42f6c9e72f8e545f3p-1,
+    -0x1.43c62ap2
+  },
+  { // Entry 317
+    -0x1.ee0e80ec9d1562c17a6cf608af9b0ed4p-1,
+    0x1.1c9964p2
+  },
+  { // Entry 318
+    0x1.ee0e80ec9d1562c17a6cf608af9b0ed4p-1,
+    -0x1.1c9964p2
+  },
+  { // Entry 319
+    -0x1.472768637ea8866a652098a43aa688a6p-1,
+    0x1.ead93cp1
+  },
+  { // Entry 320
+    0x1.472768637ea8866a652098a43aa688a6p-1,
+    -0x1.ead93cp1
+  },
+  { // Entry 321
+    -0x1.4ba24f6325f21420e7c48d4f91e28064p-4,
+    0x1.9c7fb0p1
+  },
+  { // Entry 322
+    0x1.4ba24f6325f21420e7c48d4f91e28064p-4,
+    -0x1.9c7fb0p1
+  },
+  { // Entry 323
+    0x1.034c643295153aaffe5d9a0f29e92844p-1,
+    0x1.4e2624p1
+  },
+  { // Entry 324
+    -0x1.034c643295153aaffe5d9a0f29e92844p-1,
+    -0x1.4e2624p1
+  },
+  { // Entry 325
+    0x1.d1e4d96eac917574b948e4ea9e37b36dp-1,
+    0x1.ff9932p0
+  },
+  { // Entry 326
+    -0x1.d1e4d96eac917574b948e4ea9e37b36dp-1,
+    -0x1.ff9932p0
+  },
+  { // Entry 327
+    0x1.f7501e002bcafb897f931931d3a57afdp-1,
+    0x1.62e61cp0
+  },
+  { // Entry 328
+    -0x1.f7501e002bcafb897f931931d3a57afdp-1,
+    -0x1.62e61cp0
+  },
+  { // Entry 329
+    0x1.65f7d66ef6591cfc51ab29dc2086d3e7p-1,
+    0x1.8c662cp-1
+  },
+  { // Entry 330
+    -0x1.65f7d66ef6591cfc51ab29dc2086d3e7p-1,
+    -0x1.8c662cp-1
+  },
+  { // Entry 331
+    -0x1.fe043f875c6ed4a2c1b8d69a09fcf578p-1,
+    -0x1.a8aa1cp0
+  },
+  { // Entry 332
+    0x1.fe043f875c6ed4a2c1b8d69a09fcf578p-1,
+    0x1.a8aa1cp0
+  },
+  { // Entry 333
+    -0x1.fff18f313e66f1ae25f89a5f7a1f84c4p-1,
+    -0x1.95ec8ap0
+  },
+  { // Entry 334
+    0x1.fff18f313e66f1ae25f89a5f7a1f84c4p-1,
+    0x1.95ec8ap0
+  },
+  { // Entry 335
+    -0x1.ff20d920b9e9c23154f97e2f342a2884p-1,
+    -0x1.832ef8p0
+  },
+  { // Entry 336
+    0x1.ff20d920b9e9c23154f97e2f342a2884p-1,
+    0x1.832ef8p0
+  },
+  { // Entry 337
+    -0x1.fb933b89d7db3286eed0cfeabee98875p-1,
+    -0x1.707166p0
+  },
+  { // Entry 338
+    0x1.fb933b89d7db3286eed0cfeabee98875p-1,
+    0x1.707166p0
+  },
+  { // Entry 339
+    -0x1.f54d95c5058b7dc9972ab6f9928ca043p-1,
+    -0x1.5db3d4p0
+  },
+  { // Entry 340
+    0x1.f54d95c5058b7dc9972ab6f9928ca043p-1,
+    0x1.5db3d4p0
+  },
+  { // Entry 341
+    -0x1.ec5881a09c46aae020cd9036098a196ep-1,
+    -0x1.4af642p0
+  },
+  { // Entry 342
+    0x1.ec5881a09c46aae020cd9036098a196ep-1,
+    0x1.4af642p0
+  },
+  { // Entry 343
+    -0x1.e0c04795919d961a5e83e505df31c624p-1,
+    -0x1.3838b0p0
+  },
+  { // Entry 344
+    0x1.e0c04795919d961a5e83e505df31c624p-1,
+    0x1.3838b0p0
+  },
+  { // Entry 345
+    -0x1.d294cdef7cc161633a02d3e62058be0ep-1,
+    -0x1.257b1ep0
+  },
+  { // Entry 346
+    0x1.d294cdef7cc161633a02d3e62058be0ep-1,
+    0x1.257b1ep0
+  },
+  { // Entry 347
+    -0x1.c1e988b95614abd65d3d811f5c88039bp-1,
+    -0x1.12bd92p0
+  },
+  { // Entry 348
+    0x1.c1e988b95614abd65d3d811f5c88039bp-1,
+    0x1.12bd92p0
+  },
+  { // Entry 349
+    -0x1.a2c2895edb0d4ba51cdbd5390cac468fp-1,
+    -0x1.ea5c3ep-1
+  },
+  { // Entry 350
+    0x1.a2c2895edb0d4ba51cdbd5390cac468fp-1,
+    0x1.ea5c3ep-1
+  },
+  { // Entry 351
+    -0x1.95f05153644d60b94d2f2e700dfd3a37p-1,
+    -0x1.d4b87cp-1
+  },
+  { // Entry 352
+    0x1.95f05153644d60b94d2f2e700dfd3a37p-1,
+    0x1.d4b87cp-1
+  },
+  { // Entry 353
+    -0x1.88647d8ad2e41fb7c0af0f64614c9993p-1,
+    -0x1.bf14bap-1
+  },
+  { // Entry 354
+    0x1.88647d8ad2e41fb7c0af0f64614c9993p-1,
+    0x1.bf14bap-1
+  },
+  { // Entry 355
+    -0x1.7a253f9f89a7d3e4f9c54638418e97f6p-1,
+    -0x1.a970f8p-1
+  },
+  { // Entry 356
+    0x1.7a253f9f89a7d3e4f9c54638418e97f6p-1,
+    0x1.a970f8p-1
+  },
+  { // Entry 357
+    -0x1.6b391b34aab828fbe7cd7dcaf9ef3bd6p-1,
+    -0x1.93cd36p-1
+  },
+  { // Entry 358
+    0x1.6b391b34aab828fbe7cd7dcaf9ef3bd6p-1,
+    0x1.93cd36p-1
+  },
+  { // Entry 359
+    -0x1.5ba6e2fb980d482cf00ede80f5597fb2p-1,
+    -0x1.7e2974p-1
+  },
+  { // Entry 360
+    0x1.5ba6e2fb980d482cf00ede80f5597fb2p-1,
+    0x1.7e2974p-1
+  },
+  { // Entry 361
+    -0x1.4b75b5954e718020900719e25a7ea93bp-1,
+    -0x1.6885b2p-1
+  },
+  { // Entry 362
+    0x1.4b75b5954e718020900719e25a7ea93bp-1,
+    0x1.6885b2p-1
+  },
+  { // Entry 363
+    -0x1.3aacfa510810054c52ae0b67d116eb40p-1,
+    -0x1.52e1f0p-1
+  },
+  { // Entry 364
+    0x1.3aacfa510810054c52ae0b67d116eb40p-1,
+    0x1.52e1f0p-1
+  },
+  { // Entry 365
+    -0x1.2954644ceb8e3a2479c83ae84af57d3ep-1,
+    -0x1.3d3e36p-1
+  },
+  { // Entry 366
+    0x1.2954644ceb8e3a2479c83ae84af57d3ep-1,
+    0x1.3d3e36p-1
+  },
+  { // Entry 367
+    -0x1.fc769aecd265cfea08e0ff30c2fbcacdp-2,
+    -0x1.0a0b02p-1
+  },
+  { // Entry 368
+    0x1.fc769aecd265cfea08e0ff30c2fbcacdp-2,
+    0x1.0a0b02p-1
+  },
+  { // Entry 369
+    -0x1.c853c704e3b94322031d6b47aef853c9p-2,
+    -0x1.d8f720p-2
+  },
+  { // Entry 370
+    0x1.c853c704e3b94322031d6b47aef853c9p-2,
+    0x1.d8f720p-2
+  },
+  { // Entry 371
+    -0x1.92aba8981b25deda4cc1817251723a1bp-2,
+    -0x1.9dd83cp-2
+  },
+  { // Entry 372
+    0x1.92aba8981b25deda4cc1817251723a1bp-2,
+    0x1.9dd83cp-2
+  },
+  { // Entry 373
+    -0x1.5bac05e1e0a7c2de280fcb93be67a4dap-2,
+    -0x1.62b958p-2
+  },
+  { // Entry 374
+    0x1.5bac05e1e0a7c2de280fcb93be67a4dap-2,
+    0x1.62b958p-2
+  },
+  { // Entry 375
+    -0x1.2383ca2b249807d95005d96cfdaecd6cp-2,
+    -0x1.279a74p-2
+  },
+  { // Entry 376
+    0x1.2383ca2b249807d95005d96cfdaecd6cp-2,
+    0x1.279a74p-2
+  },
+  { // Entry 377
+    -0x1.d4c5bb872ea5375834ca0bca088d1d75p-3,
+    -0x1.d8f720p-3
+  },
+  { // Entry 378
+    0x1.d4c5bb872ea5375834ca0bca088d1d75p-3,
+    0x1.d8f720p-3
+  },
+  { // Entry 379
+    -0x1.60f3fa460b85811d2ae710cd69ec3690p-3,
+    -0x1.62b958p-3
+  },
+  { // Entry 380
+    0x1.60f3fa460b85811d2ae710cd69ec3690p-3,
+    0x1.62b958p-3
+  },
+  { // Entry 381
+    -0x1.d7ea3d56e1e6244c8786d74f189d98acp-4,
+    -0x1.d8f720p-4
+  },
+  { // Entry 382
+    0x1.d7ea3d56e1e6244c8786d74f189d98acp-4,
+    0x1.d8f720p-4
+  },
+  { // Entry 383
+    -0x1.d8b3deba6ac493b04b2103a0dbaef02fp-5,
+    -0x1.d8f720p-5
+  },
+  { // Entry 384
+    0x1.d8b3deba6ac493b04b2103a0dbaef02fp-5,
+    0x1.d8f720p-5
+  },
+  { // Entry 385
+    0x1.d8b3deba6ac493b04b2103a0dbaef02fp-5,
+    0x1.d8f720p-5
+  },
+  { // Entry 386
+    -0x1.d8b3deba6ac493b04b2103a0dbaef02fp-5,
+    -0x1.d8f720p-5
+  },
+  { // Entry 387
+    0x1.d7ea3d56e1e6244c8786d74f189d98acp-4,
+    0x1.d8f720p-4
+  },
+  { // Entry 388
+    -0x1.d7ea3d56e1e6244c8786d74f189d98acp-4,
+    -0x1.d8f720p-4
+  },
+  { // Entry 389
+    0x1.60f3fa460b85811d2ae710cd69ec3690p-3,
+    0x1.62b958p-3
+  },
+  { // Entry 390
+    -0x1.60f3fa460b85811d2ae710cd69ec3690p-3,
+    -0x1.62b958p-3
+  },
+  { // Entry 391
+    0x1.d4c5bb872ea5375834ca0bca088d1d75p-3,
+    0x1.d8f720p-3
+  },
+  { // Entry 392
+    -0x1.d4c5bb872ea5375834ca0bca088d1d75p-3,
+    -0x1.d8f720p-3
+  },
+  { // Entry 393
+    0x1.2383ca2b249807d95005d96cfdaecd6cp-2,
+    0x1.279a74p-2
+  },
+  { // Entry 394
+    -0x1.2383ca2b249807d95005d96cfdaecd6cp-2,
+    -0x1.279a74p-2
+  },
+  { // Entry 395
+    0x1.5bac05e1e0a7c2de280fcb93be67a4dap-2,
+    0x1.62b958p-2
+  },
+  { // Entry 396
+    -0x1.5bac05e1e0a7c2de280fcb93be67a4dap-2,
+    -0x1.62b958p-2
+  },
+  { // Entry 397
+    0x1.92aba8981b25deda4cc1817251723a1bp-2,
+    0x1.9dd83cp-2
+  },
+  { // Entry 398
+    -0x1.92aba8981b25deda4cc1817251723a1bp-2,
+    -0x1.9dd83cp-2
+  },
+  { // Entry 399
+    0x1.c853c704e3b94322031d6b47aef853c9p-2,
+    0x1.d8f720p-2
+  },
+  { // Entry 400
+    -0x1.c853c704e3b94322031d6b47aef853c9p-2,
+    -0x1.d8f720p-2
+  },
+  { // Entry 401
+    0x1.fc769aecd265cfea08e0ff30c2fbcacdp-2,
+    0x1.0a0b02p-1
+  },
+  { // Entry 402
+    -0x1.fc769aecd265cfea08e0ff30c2fbcacdp-2,
+    -0x1.0a0b02p-1
+  },
+  { // Entry 403
+    0x1.2954644ceb8e3a2479c83ae84af57d3ep-1,
+    0x1.3d3e36p-1
+  },
+  { // Entry 404
+    -0x1.2954644ceb8e3a2479c83ae84af57d3ep-1,
+    -0x1.3d3e36p-1
+  },
+  { // Entry 405
+    0x1.3aad00a09268a39df1653c70db91f157p-1,
+    0x1.52e1f8p-1
+  },
+  { // Entry 406
+    -0x1.3aad00a09268a39df1653c70db91f157p-1,
+    -0x1.52e1f8p-1
+  },
+  { // Entry 407
+    0x1.4b75bbae388a7f3466e7f2d6bdcf72bbp-1,
+    0x1.6885bap-1
+  },
+  { // Entry 408
+    -0x1.4b75bbae388a7f3466e7f2d6bdcf72bbp-1,
+    -0x1.6885bap-1
+  },
+  { // Entry 409
+    0x1.5ba6e8db1833475712b9a42a1ad0d2c2p-1,
+    0x1.7e297cp-1
+  },
+  { // Entry 410
+    -0x1.5ba6e8db1833475712b9a42a1ad0d2c2p-1,
+    -0x1.7e297cp-1
+  },
+  { // Entry 411
+    0x1.6b3920d8117828928fe10ac70ba69e76p-1,
+    0x1.93cd3ep-1
+  },
+  { // Entry 412
+    -0x1.6b3920d8117828928fe10ac70ba69e76p-1,
+    -0x1.93cd3ep-1
+  },
+  { // Entry 413
+    0x1.7a25450443098836c5202375db4b8462p-1,
+    0x1.a971p-1
+  },
+  { // Entry 414
+    -0x1.7a25450443098836c5202375db4b8462p-1,
+    -0x1.a971p-1
+  },
+  { // Entry 415
+    0x1.886482ae6797b38364f5c72ce9a3b76fp-1,
+    0x1.bf14c2p-1
+  },
+  { // Entry 416
+    -0x1.886482ae6797b38364f5c72ce9a3b76fp-1,
+    -0x1.bf14c2p-1
+  },
+  { // Entry 417
+    0x1.95f056337acc1d2d557525232e915467p-1,
+    0x1.d4b884p-1
+  },
+  { // Entry 418
+    -0x1.95f056337acc1d2d557525232e915467p-1,
+    -0x1.d4b884p-1
+  },
+  { // Entry 419
+    0x1.a2c2895edb0d4ba51cdbd5390cac468fp-1,
+    0x1.ea5c3ep-1
+  },
+  { // Entry 420
+    -0x1.a2c2895edb0d4ba51cdbd5390cac468fp-1,
+    -0x1.ea5c3ep-1
+  },
+  { // Entry 421
+    0x1.c1e988b95614abd65d3d811f5c88039bp-1,
+    0x1.12bd92p0
+  },
+  { // Entry 422
+    -0x1.c1e988b95614abd65d3d811f5c88039bp-1,
+    -0x1.12bd92p0
+  },
+  { // Entry 423
+    0x1.d294d2e06b3d10a4de263172d50f4497p-1,
+    0x1.257b24p0
+  },
+  { // Entry 424
+    -0x1.d294d2e06b3d10a4de263172d50f4497p-1,
+    -0x1.257b24p0
+  },
+  { // Entry 425
+    0x1.e0c04bb65bd33012be72a340df2c044bp-1,
+    0x1.3838b6p0
+  },
+  { // Entry 426
+    -0x1.e0c04bb65bd33012be72a340df2c044bp-1,
+    -0x1.3838b6p0
+  },
+  { // Entry 427
+    0x1.ec5884eb990c3deaaeebd3f0f84d6962p-1,
+    0x1.4af648p0
+  },
+  { // Entry 428
+    -0x1.ec5884eb990c3deaaeebd3f0f84d6962p-1,
+    -0x1.4af648p0
+  },
+  { // Entry 429
+    0x1.f54d9835b0e66e17612160272521f3b0p-1,
+    0x1.5db3dap0
+  },
+  { // Entry 430
+    -0x1.f54d9835b0e66e17612160272521f3b0p-1,
+    -0x1.5db3dap0
+  },
+  { // Entry 431
+    0x1.fb933d1cd931685e902e403a1baaecfdp-1,
+    0x1.70716cp0
+  },
+  { // Entry 432
+    -0x1.fb933d1cd931685e902e403a1baaecfdp-1,
+    -0x1.70716cp0
+  },
+  { // Entry 433
+    0x1.ff20d9d3e8984fec33982e42f5884f2cp-1,
+    0x1.832efep0
+  },
+  { // Entry 434
+    -0x1.ff20d9d3e8984fec33982e42f5884f2cp-1,
+    -0x1.832efep0
+  },
+  { // Entry 435
+    0x1.fff18f03a4b7e6aacf51f83931e85042p-1,
+    0x1.95ec90p0
+  },
+  { // Entry 436
+    -0x1.fff18f03a4b7e6aacf51f83931e85042p-1,
+    -0x1.95ec90p0
+  },
+  { // Entry 437
+    0x1.fe043f875c6ed4a2c1b8d69a09fcf578p-1,
+    0x1.a8aa1cp0
+  },
+  { // Entry 438
+    -0x1.fe043f875c6ed4a2c1b8d69a09fcf578p-1,
+    -0x1.a8aa1cp0
+  },
+  { // Entry 439
+    0x1.b3d36a96880cf69d9884a49f5381e917p-1,
+    0x1.04aff8p0
+  },
+  { // Entry 440
+    -0x1.b3d36a96880cf69d9884a49f5381e917p-1,
+    -0x1.04aff8p0
+  },
+  { // Entry 441
+    0x1.b3d41aebcf391c30c3d2f1ee7b79710cp-1,
+    0x1.04b0a0p0
+  },
+  { // Entry 442
+    -0x1.b3d41aebcf391c30c3d2f1ee7b79710cp-1,
+    -0x1.04b0a0p0
+  },
+  { // Entry 443
+    0x1.b3d4cb405ab3292be7df5b1b98032fbep-1,
+    0x1.04b148p0
+  },
+  { // Entry 444
+    -0x1.b3d4cb405ab3292be7df5b1b98032fbep-1,
+    -0x1.04b148p0
+  },
+  { // Entry 445
+    0x1.b3d57b942a7ad19e9b9892c9319e1be6p-1,
+    0x1.04b1f0p0
+  },
+  { // Entry 446
+    -0x1.b3d57b942a7ad19e9b9892c9319e1be6p-1,
+    -0x1.04b1f0p0
+  },
+  { // Entry 447
+    0x1.b3d62be73e8fc998c6c2df6590425613p-1,
+    0x1.04b298p0
+  },
+  { // Entry 448
+    -0x1.b3d62be73e8fc998c6c2df6590425613p-1,
+    -0x1.04b298p0
+  },
+  { // Entry 449
+    0x1.b3d6dc3996f1c52aa1f83bdee1d0e023p-1,
+    0x1.04b340p0
+  },
+  { // Entry 450
+    -0x1.b3d6dc3996f1c52aa1f83bdee1d0e023p-1,
+    -0x1.04b340p0
+  },
+  { // Entry 451
+    0x1.b3d78c8b33a07864b6a878573db34bcap-1,
+    0x1.04b3e8p0
+  },
+  { // Entry 452
+    -0x1.b3d78c8b33a07864b6a878573db34bcap-1,
+    -0x1.04b3e8p0
+  },
+  { // Entry 453
+    0x1.b3d83cdc149b9757df195ad885ab5201p-1,
+    0x1.04b490p0
+  },
+  { // Entry 454
+    -0x1.b3d83cdc149b9757df195ad885ab5201p-1,
+    -0x1.04b490p0
+  },
+  { // Entry 455
+    0x1.b3d8e8f9908360b38cd13fcbf6224d93p-1,
+    0x1.04b534p0
+  },
+  { // Entry 456
+    -0x1.b3d8e8f9908360b38cd13fcbf6224d93p-1,
+    -0x1.04b534p0
+  },
+  { // Entry 457
+    -0.0f,
+    -0x1.p-149
+  },
+  { // Entry 458
+    0.0f,
+    0x1.p-149
+  },
+  { // Entry 459
+    0.0,
+    0.0
+  },
+  { // Entry 460
+    0.0f,
+    0x1.p-149
+  },
+  { // Entry 461
+    -0.0f,
+    -0x1.p-149
+  },
+  { // Entry 462
+    0x1.1773d36a64df61d6715e60af063559f4p-1,
+    0x1.279a72p-1
+  },
+  { // Entry 463
+    -0x1.1773d36a64df61d6715e60af063559f4p-1,
+    -0x1.279a72p-1
+  },
+  { // Entry 464
+    0x1.1773d51767a78fe91b55f6b7e5fd44c2p-1,
+    0x1.279a74p-1
+  },
+  { // Entry 465
+    -0x1.1773d51767a78fe91b55f6b7e5fd44c2p-1,
+    -0x1.279a74p-1
+  },
+  { // Entry 466
+    0x1.1773d6c46a6ea687f03625194d25bb52p-1,
+    0x1.279a76p-1
+  },
+  { // Entry 467
+    -0x1.1773d6c46a6ea687f03625194d25bb52p-1,
+    -0x1.279a76p-1
+  },
+  { // Entry 468
+    0x1.f95b8f40501057ac49acef13993b0c55p-1,
+    0x1.bb67acp0
+  },
+  { // Entry 469
+    -0x1.f95b8f40501057ac49acef13993b0c55p-1,
+    -0x1.bb67acp0
+  },
+  { // Entry 470
+    0x1.f95b8e9be727702f7595ae1000a14a1ap-1,
+    0x1.bb67aep0
+  },
+  { // Entry 471
+    -0x1.f95b8e9be727702f7595ae1000a14a1ap-1,
+    -0x1.bb67aep0
+  },
+  { // Entry 472
+    0x1.f95b8df77e36a344670ed07149191a58p-1,
+    0x1.bb67b0p0
+  },
+  { // Entry 473
+    -0x1.f95b8df77e36a344670ed07149191a58p-1,
+    -0x1.bb67b0p0
+  },
+  { // Entry 474
+    0x1.b1d82e835a918de18f5fdadc8b1240cfp-2,
+    0x1.bffffep-2
+  },
+  { // Entry 475
+    -0x1.b1d82e835a918de18f5fdadc8b1240cfp-2,
+    -0x1.bffffep-2
+  },
+  { // Entry 476
+    0x1.b1d83053216169476f4d1982b9b14ab1p-2,
+    0x1.c0p-2
+  },
+  { // Entry 477
+    -0x1.b1d83053216169476f4d1982b9b14ab1p-2,
+    -0x1.c0p-2
+  },
+  { // Entry 478
+    0x1.b1d83222e830d83743258fd09040ee56p-2,
+    0x1.c00002p-2
+  },
+  { // Entry 479
+    -0x1.b1d83222e830d83743258fd09040ee56p-2,
+    -0x1.c00002p-2
+  },
+  { // Entry 480
+    0x1.44eb3691428062b27925c585ad59d62ap-1,
+    0x1.5ffffep-1
+  },
+  { // Entry 481
+    -0x1.44eb3691428062b27925c585ad59d62ap-1,
+    -0x1.5ffffep-1
+  },
+  { // Entry 482
+    0x1.44eb381cf386ab04a4f8656abea80b83p-1,
+    0x1.60p-1
+  },
+  { // Entry 483
+    -0x1.44eb381cf386ab04a4f8656abea80b83p-1,
+    -0x1.60p-1
+  },
+  { // Entry 484
+    0x1.44eb39a8a48bae6b98ae11c9400535e5p-1,
+    0x1.600002p-1
+  },
+  { // Entry 485
+    -0x1.44eb39a8a48bae6b98ae11c9400535e5p-1,
+    -0x1.600002p-1
+  },
+  { // Entry 486
+    0x1.dad9017b96408c375d4faf0e4776d1fcp-1,
+    0x1.2ffffep0
+  },
+  { // Entry 487
+    -0x1.dad9017b96408c375d4faf0e4776d1fcp-1,
+    -0x1.2ffffep0
+  },
+  { // Entry 488
+    0x1.dad902fa8ac870f52f1b843ac83bc3edp-1,
+    0x1.30p0
+  },
+  { // Entry 489
+    -0x1.dad902fa8ac870f52f1b843ac83bc3edp-1,
+    -0x1.30p0
+  },
+  { // Entry 490
+    0x1.dad904797f48ea4ef4fd2e47fe4d52bdp-1,
+    0x1.300002p0
+  },
+  { // Entry 491
+    -0x1.dad904797f48ea4ef4fd2e47fe4d52bdp-1,
+    -0x1.300002p0
+  },
+  { // Entry 492
+    0x1.4b708093c9cb45355e7821e5aad98ce8p-1,
+    0x1.37fffep1
+  },
+  { // Entry 493
+    -0x1.4b708093c9cb45355e7821e5aad98ce8p-1,
+    -0x1.37fffep1
+  },
+  { // Entry 494
+    0x1.4b707a7acdecc84239463e78b312fa10p-1,
+    0x1.38p1
+  },
+  { // Entry 495
+    -0x1.4b707a7acdecc84239463e78b312fa10p-1,
+    -0x1.38p1
+  },
+  { // Entry 496
+    0x1.4b707461d1f994476c677c5ad5ddb264p-1,
+    0x1.380002p1
+  },
+  { // Entry 497
+    -0x1.4b707461d1f994476c677c5ad5ddb264p-1,
+    -0x1.380002p1
+  },
+  { // Entry 498
+    0x1.066e7f705a6ca2b9e107f7dc9f3b26e6p-4,
+    0x1.069c8cp-4
+  },
+  { // Entry 499
+    -0x1.066e7f705a6ca2b9e107f7dc9f3b26e6p-4,
+    -0x1.069c8cp-4
+  },
+  { // Entry 500
+    0x1.05e476d27febc8b7e9690009b367c327p-3,
+    0x1.069c8cp-3
+  },
+  { // Entry 501
+    -0x1.05e476d27febc8b7e9690009b367c327p-3,
+    -0x1.069c8cp-3
+  },
+  { // Entry 502
+    0x1.877e2de5c9a066b8db595adc149af0c0p-3,
+    0x1.89ead2p-3
+  },
+  { // Entry 503
+    -0x1.877e2de5c9a066b8db595adc149af0c0p-3,
+    -0x1.89ead2p-3
+  },
+  { // Entry 504
+    0x1.03be07acb9dab719b4343a33b9fa6afep-2,
+    0x1.069c8cp-2
+  },
+  { // Entry 505
+    -0x1.03be07acb9dab719b4343a33b9fa6afep-2,
+    -0x1.069c8cp-2
+  },
+  { // Entry 506
+    0x1.42abbc5b3b2f91e8ece46e5effd28369p-2,
+    0x1.4843b0p-2
+  },
+  { // Entry 507
+    -0x1.42abbc5b3b2f91e8ece46e5effd28369p-2,
+    -0x1.4843b0p-2
+  },
+  { // Entry 508
+    0x1.804601411d93f4750919670061de07d9p-2,
+    0x1.89ead4p-2
+  },
+  { // Entry 509
+    -0x1.804601411d93f4750919670061de07d9p-2,
+    -0x1.89ead4p-2
+  },
+  { // Entry 510
+    0x1.bc4c08af356088b1694995bfaf8a297bp-2,
+    0x1.cb91f8p-2
+  },
+  { // Entry 511
+    -0x1.bc4c08af356088b1694995bfaf8a297bp-2,
+    -0x1.cb91f8p-2
+  },
+  { // Entry 512
+    0x1.f67eae34dc0b42b465fd2a3fb07564a4p-2,
+    0x1.069c8ep-1
+  },
+  { // Entry 513
+    -0x1.f67eae34dc0b42b465fd2a3fb07564a4p-2,
+    -0x1.069c8ep-1
+  },
+  { // Entry 514
+    0x1.17505c86231898fd86b18d2282d93eedp-1,
+    0x1.277020p-1
+  },
+  { // Entry 515
+    -0x1.17505c86231898fd86b18d2282d93eedp-1,
+    -0x1.277020p-1
+  },
+  { // Entry 516
+    0x1.323b8e40d16575e50dc7b6e567bb5084p-1,
+    0x1.4843b2p-1
+  },
+  { // Entry 517
+    -0x1.323b8e40d16575e50dc7b6e567bb5084p-1,
+    -0x1.4843b2p-1
+  },
+  { // Entry 518
+    0x1.4be49b08a1e1629cbdaa507e18255cd8p-1,
+    0x1.691744p-1
+  },
+  { // Entry 519
+    -0x1.4be49b08a1e1629cbdaa507e18255cd8p-1,
+    -0x1.691744p-1
+  },
+  { // Entry 520
+    0x1.6430847dbbbfd46cbebbc6d5f51c7c49p-1,
+    0x1.89ead6p-1
+  },
+  { // Entry 521
+    -0x1.6430847dbbbfd46cbebbc6d5f51c7c49p-1,
+    -0x1.89ead6p-1
+  },
+  { // Entry 522
+    0x1.7b05bb87b38844e56003c41ef804b273p-1,
+    0x1.aabe68p-1
+  },
+  { // Entry 523
+    -0x1.7b05bb87b38844e56003c41ef804b273p-1,
+    -0x1.aabe68p-1
+  },
+  { // Entry 524
+    0x1.904c3b389d55d3deddb39d05eb366571p-1,
+    0x1.cb91fap-1
+  },
+  { // Entry 525
+    -0x1.904c3b389d55d3deddb39d05eb366571p-1,
+    -0x1.cb91fap-1
+  },
+  { // Entry 526
+    0x1.a3eda211798a82697d62431f9ae46cc4p-1,
+    0x1.ec658cp-1
+  },
+  { // Entry 527
+    -0x1.a3eda211798a82697d62431f9ae46cc4p-1,
+    -0x1.ec658cp-1
+  },
+  { // Entry 528
+    0x1.b5d54883fcb6123bc28aac91f085e4eep-1,
+    0x1.069c8ep0
+  },
+  { // Entry 529
+    -0x1.b5d54883fcb6123bc28aac91f085e4eep-1,
+    -0x1.069c8ep0
+  },
+  { // Entry 530
+    0x1.c5f05a0135d4882c768cdf18e2e1112cp-1,
+    0x1.170656p0
+  },
+  { // Entry 531
+    -0x1.c5f05a0135d4882c768cdf18e2e1112cp-1,
+    -0x1.170656p0
+  },
+  { // Entry 532
+    0x1.d42de53e315c839ce188e201205e99dep-1,
+    0x1.27701ep0
+  },
+  { // Entry 533
+    -0x1.d42de53e315c839ce188e201205e99dep-1,
+    -0x1.27701ep0
+  },
+  { // Entry 534
+    0x1.e07eef45d91eea8a6cc7369aa0e55388p-1,
+    0x1.37d9e6p0
+  },
+  { // Entry 535
+    -0x1.e07eef45d91eea8a6cc7369aa0e55388p-1,
+    -0x1.37d9e6p0
+  },
+  { // Entry 536
+    0x1.ead6833b2aa002baa1c2b19a38dc9b79p-1,
+    0x1.4843aep0
+  },
+  { // Entry 537
+    -0x1.ead6833b2aa002baa1c2b19a38dc9b79p-1,
+    -0x1.4843aep0
+  },
+  { // Entry 538
+    0x1.f329bffa6a208591eecb6905d7594e3bp-1,
+    0x1.58ad76p0
+  },
+  { // Entry 539
+    -0x1.f329bffa6a208591eecb6905d7594e3bp-1,
+    -0x1.58ad76p0
+  },
+  { // Entry 540
+    0x1.f96fe38afbd95b5fcd08608110e9381fp-1,
+    0x1.69173ep0
+  },
+  { // Entry 541
+    -0x1.f96fe38afbd95b5fcd08608110e9381fp-1,
+    -0x1.69173ep0
+  },
+  { // Entry 542
+    0x1.fda25455d9567772f20f25d15efc6775p-1,
+    0x1.798106p0
+  },
+  { // Entry 543
+    -0x1.fda25455d9567772f20f25d15efc6775p-1,
+    -0x1.798106p0
+  },
+  { // Entry 544
+    0x1.ffbca816f1f1516ec5d757b0db54ae34p-1,
+    0x1.89eacep0
+  },
+  { // Entry 545
+    -0x1.ffbca816f1f1516ec5d757b0db54ae34p-1,
+    -0x1.89eacep0
+  },
+  { // Entry 546
+    0x1.ffbca88228b163189ab8d637db99bd2dp-1,
+    0x1.9a5496p0
+  },
+  { // Entry 547
+    -0x1.ffbca88228b163189ab8d637db99bd2dp-1,
+    -0x1.9a5496p0
+  },
+  { // Entry 548
+    0x1.fda255970ccddb9d127ecf63403c2bf7p-1,
+    0x1.aabe5ep0
+  },
+  { // Entry 549
+    -0x1.fda255970ccddb9d127ecf63403c2bf7p-1,
+    -0x1.aabe5ep0
+  },
+  { // Entry 550
+    0x1.f96fe5a0da244489fb2f4b97b3e48757p-1,
+    0x1.bb2826p0
+  },
+  { // Entry 551
+    -0x1.f96fe5a0da244489fb2f4b97b3e48757p-1,
+    -0x1.bb2826p0
+  },
+  { // Entry 552
+    0x1.f329c2e2c1a39bad8ecdcb87961ba44ap-1,
+    0x1.cb91eep0
+  },
+  { // Entry 553
+    -0x1.f329c2e2c1a39bad8ecdcb87961ba44ap-1,
+    -0x1.cb91eep0
+  },
+  { // Entry 554
+    0x1.ead686f2ec572c83ed34a01f764d193ep-1,
+    0x1.dbfbb6p0
+  },
+  { // Entry 555
+    -0x1.ead686f2ec572c83ed34a01f764d193ep-1,
+    -0x1.dbfbb6p0
+  },
+  { // Entry 556
+    0x1.e07ef3c91bd500a0de230ad573163163p-1,
+    0x1.ec657ep0
+  },
+  { // Entry 557
+    -0x1.e07ef3c91bd500a0de230ad573163163p-1,
+    -0x1.ec657ep0
+  },
+  { // Entry 558
+    0x1.d42dea8835c88adb9cde17347f934e25p-1,
+    0x1.fccf46p0
+  },
+  { // Entry 559
+    -0x1.d42dea8835c88adb9cde17347f934e25p-1,
+    -0x1.fccf46p0
+  },
+  { // Entry 560
+    0x1.c5f05e32c80fb0fe603033ec028a4c32p-1,
+    0x1.069c88p1
+  },
+  { // Entry 561
+    -0x1.c5f05e32c80fb0fe603033ec028a4c32p-1,
+    -0x1.069c88p1
+  },
+  { // Entry 562
+    0x1.b5d54d3732d3b2e79d4907e115401ddap-1,
+    0x1.0ed16cp1
+  },
+  { // Entry 563
+    -0x1.b5d54d3732d3b2e79d4907e115401ddap-1,
+    -0x1.0ed16cp1
+  },
+  { // Entry 564
+    0x1.a3eda74161d06b83ec2c8dc396d813b9p-1,
+    0x1.170650p1
+  },
+  { // Entry 565
+    -0x1.a3eda74161d06b83ec2c8dc396d813b9p-1,
+    -0x1.170650p1
+  },
+  { // Entry 566
+    0x1.904c421efce58f4e8170d36dcda8e02cp-1,
+    0x1.1f3b34p1
+  },
+  { // Entry 567
+    -0x1.904c421efce58f4e8170d36dcda8e02cp-1,
+    -0x1.1f3b34p1
+  },
+  { // Entry 568
+    0x1.7b05c45093944d6afb0c90d2f9cb217fp-1,
+    0x1.277018p1
+  },
+  { // Entry 569
+    -0x1.7b05c45093944d6afb0c90d2f9cb217fp-1,
+    -0x1.277018p1
+  },
+  { // Entry 570
+    0x1.64308f506ffdaf1326d10b3380278e98p-1,
+    0x1.2fa4fcp1
+  },
+  { // Entry 571
+    -0x1.64308f506ffdaf1326d10b3380278e98p-1,
+    -0x1.2fa4fcp1
+  },
+  { // Entry 572
+    0x1.4be4a8076c135a48f3f1a1aaa362475fp-1,
+    0x1.37d9e0p1
+  },
+  { // Entry 573
+    -0x1.4be4a8076c135a48f3f1a1aaa362475fp-1,
+    -0x1.37d9e0p1
+  },
+  { // Entry 574
+    0x1.323b9d888d4da77a610893735eeed1cbp-1,
+    0x1.400ec4p1
+  },
+  { // Entry 575
+    -0x1.323b9d888d4da77a610893735eeed1cbp-1,
+    -0x1.400ec4p1
+  },
+  { // Entry 576
+    0x1.17506e2dfb603d34b9af39b12c1db735p-1,
+    0x1.4843a8p1
+  },
+  { // Entry 577
+    -0x1.17506e2dfb603d34b9af39b12c1db735p-1,
+    -0x1.4843a8p1
+  },
+  { // Entry 578
+    0x1.f67ed667352d4827450013f15e321bfbp-2,
+    0x1.50788cp1
+  },
+  { // Entry 579
+    -0x1.f67ed667352d4827450013f15e321bfbp-2,
+    -0x1.50788cp1
+  },
+  { // Entry 580
+    0x1.bc4c35da51e34b776e5e04da58f23441p-2,
+    0x1.58ad70p1
+  },
+  { // Entry 581
+    -0x1.bc4c35da51e34b776e5e04da58f23441p-2,
+    -0x1.58ad70p1
+  },
+  { // Entry 582
+    0x1.8046336e68427cf756056d3f4edbb662p-2,
+    0x1.60e254p1
+  },
+  { // Entry 583
+    -0x1.8046336e68427cf756056d3f4edbb662p-2,
+    -0x1.60e254p1
+  },
+  { // Entry 584
+    0x1.42abf3872905e632f204c41b24af90b6p-2,
+    0x1.691738p1
+  },
+  { // Entry 585
+    -0x1.42abf3872905e632f204c41b24af90b6p-2,
+    -0x1.691738p1
+  },
+  { // Entry 586
+    0x1.03be43c699f3536990dcf5a6665ac239p-2,
+    0x1.714c1cp1
+  },
+  { // Entry 587
+    -0x1.03be43c699f3536990dcf5a6665ac239p-2,
+    -0x1.714c1cp1
+  },
+  { // Entry 588
+    0x1.877eadc2fdfc2f0db1e8b78cd3fbfbd2p-3,
+    0x1.7981p1
+  },
+  { // Entry 589
+    -0x1.877eadc2fdfc2f0db1e8b78cd3fbfbd2p-3,
+    -0x1.7981p1
+  },
+  { // Entry 590
+    0x1.05e4fdf846632a8208d90de72d3a6da8p-3,
+    0x1.81b5e4p1
+  },
+  { // Entry 591
+    -0x1.05e4fdf846632a8208d90de72d3a6da8p-3,
+    -0x1.81b5e4p1
+  },
+  { // Entry 592
+    0x1.066f9b630b72dff16450e89afdf7e048p-4,
+    0x1.89eac8p1
+  },
+  { // Entry 593
+    -0x1.066f9b630b72dff16450e89afdf7e048p-4,
+    -0x1.89eac8p1
+  },
+  { // Entry 594
+    0x1.03bdf0b79ccf739529d54d422861046cp-2,
+    -0x1.81b5eep2
+  },
+  { // Entry 595
+    -0x1.03bdf0b79ccf739529d54d422861046cp-2,
+    0x1.81b5eep2
+  },
+  { // Entry 596
+    0x1.f67e8b95f5460ea369a803837b721abdp-2,
+    -0x1.714c26p2
+  },
+  { // Entry 597
+    -0x1.f67e8b95f5460ea369a803837b721abdp-2,
+    0x1.714c26p2
+  },
+  { // Entry 598
+    0x1.643070791751dc0636d1854d2bdbc5d4p-1,
+    -0x1.60e25ep2
+  },
+  { // Entry 599
+    -0x1.643070791751dc0636d1854d2bdbc5d4p-1,
+    0x1.60e25ep2
+  },
+  { // Entry 600
+    0x1.b5d536f59113a43af30e8c9db8a951a5p-1,
+    -0x1.507896p2
+  },
+  { // Entry 601
+    -0x1.b5d536f59113a43af30e8c9db8a951a5p-1,
+    0x1.507896p2
+  },
+  { // Entry 602
+    0x1.ead679985549140318349f512dca7a6bp-1,
+    -0x1.400ecep2
+  },
+  { // Entry 603
+    -0x1.ead679985549140318349f512dca7a6bp-1,
+    0x1.400ecep2
+  },
+  { // Entry 604
+    0x1.ffbca7010e0b0452f56075cfd5982880p-1,
+    -0x1.2fa506p2
+  },
+  { // Entry 605
+    -0x1.ffbca7010e0b0452f56075cfd5982880p-1,
+    0x1.2fa506p2
+  },
+  { // Entry 606
+    0x1.f329ca6bfc7425d89c2b4b9ad73ab108p-1,
+    -0x1.1f3b3ep2
+  },
+  { // Entry 607
+    -0x1.f329ca6bfc7425d89c2b4b9ad73ab108p-1,
+    0x1.1f3b3ep2
+  },
+  { // Entry 608
+    0x1.c5f06fb69427ac0f2d69428d82b5e669p-1,
+    -0x1.0ed176p2
+  },
+  { // Entry 609
+    -0x1.c5f06fb69427ac0f2d69428d82b5e669p-1,
+    0x1.0ed176p2
+  },
+  { // Entry 610
+    0x1.7b05d864ec9802adbc4b5577c233836ap-1,
+    -0x1.fccf5ap1
+  },
+  { // Entry 611
+    -0x1.7b05d864ec9802adbc4b5577c233836ap-1,
+    0x1.fccf5ap1
+  },
+  { // Entry 612
+    0x1.1750808185a998bbcecc3a6ac0cb2907p-1,
+    -0x1.dbfbc8p1
+  },
+  { // Entry 613
+    -0x1.1750808185a998bbcecc3a6ac0cb2907p-1,
+    0x1.dbfbc8p1
+  },
+  { // Entry 614
+    0x1.42ac0dd9495211816bf04ca53bce4beap-2,
+    -0x1.bb2836p1
+  },
+  { // Entry 615
+    -0x1.42ac0dd9495211816bf04ca53bce4beap-2,
+    0x1.bb2836p1
+  },
+  { // Entry 616
+    0x1.066fca39a70b52d06f2cd7eab69c31f2p-4,
+    -0x1.9a54a4p1
+  },
+  { // Entry 617
+    -0x1.066fca39a70b52d06f2cd7eab69c31f2p-4,
+    0x1.9a54a4p1
+  },
+  { // Entry 618
+    -0x1.877d931298e6fbc654f065536cff2b54p-3,
+    -0x1.798112p1
+  },
+  { // Entry 619
+    0x1.877d931298e6fbc654f065536cff2b54p-3,
+    0x1.798112p1
+  },
+  { // Entry 620
+    -0x1.bc4bc2875eb6d38eda3b49cb2320b561p-2,
+    -0x1.58ad80p1
+  },
+  { // Entry 621
+    0x1.bc4bc2875eb6d38eda3b49cb2320b561p-2,
+    0x1.58ad80p1
+  },
+  { // Entry 622
+    -0x1.4be47d6354c4ced53780b1b519acdec2p-1,
+    -0x1.37d9eep1
+  },
+  { // Entry 623
+    0x1.4be47d6354c4ced53780b1b519acdec2p-1,
+    0x1.37d9eep1
+  },
+  { // Entry 624
+    -0x1.a3ed8bcb35cbcf8c6089f82a91c31d5bp-1,
+    -0x1.17065cp1
+  },
+  { // Entry 625
+    0x1.a3ed8bcb35cbcf8c6089f82a91c31d5bp-1,
+    0x1.17065cp1
+  },
+  { // Entry 626
+    -0x1.e07ee496ea109654c42e171fdc4537c4p-1,
+    -0x1.ec6594p0
+  },
+  { // Entry 627
+    0x1.e07ee496ea109654c42e171fdc4537c4p-1,
+    0x1.ec6594p0
+  },
+  { // Entry 628
+    -0x1.fda2522219689d0e8069d90f5c969b92p-1,
+    -0x1.aabe70p0
+  },
+  { // Entry 629
+    0x1.fda2522219689d0e8069d90f5c969b92p-1,
+    0x1.aabe70p0
+  },
+  { // Entry 630
+    -0x1.f96fe802fe570372d0fcb6e934b43061p-1,
+    -0x1.69174cp0
+  },
+  { // Entry 631
+    0x1.f96fe802fe570372d0fcb6e934b43061p-1,
+    0x1.69174cp0
+  },
+  { // Entry 632
+    -0x1.d42ded56ae88a6e1cf270af27e6f1804p-1,
+    -0x1.277028p0
+  },
+  { // Entry 633
+    0x1.d42ded56ae88a6e1cf270af27e6f1804p-1,
+    0x1.277028p0
+  },
+  { // Entry 634
+    -0x1.904c45326d6dde224381d1d590ada41cp-1,
+    -0x1.cb920ap-1
+  },
+  { // Entry 635
+    0x1.904c45326d6dde224381d1d590ada41cp-1,
+    0x1.cb920ap-1
+  },
+  { // Entry 636
+    -0x1.323b9cadbb19e75a44483fb64ad8ddf6p-1,
+    -0x1.4843c4p-1
+  },
+  { // Entry 637
+    0x1.323b9cadbb19e75a44483fb64ad8ddf6p-1,
+    0x1.4843c4p-1
+  },
+  { // Entry 638
+    -0x1.80462654bde766faf47f3140e290996dp-2,
+    -0x1.89eafcp-2
+  },
+  { // Entry 639
+    0x1.80462654bde766faf47f3140e290996dp-2,
+    0x1.89eafcp-2
+  },
+  { // Entry 640
+    -0x1.05e4ca21f386a82bc2e4efcdebb1962bp-3,
+    -0x1.069ce0p-3
+  },
+  { // Entry 641
+    0x1.05e4ca21f386a82bc2e4efcdebb1962bp-3,
+    0x1.069ce0p-3
+  },
+  { // Entry 642
+    0x1.05e423830be01f9fe3c57d06867e0056p-3,
+    0x1.069c38p-3
+  },
+  { // Entry 643
+    -0x1.05e423830be01f9fe3c57d06867e0056p-3,
+    -0x1.069c38p-3
+  },
+  { // Entry 644
+    0x1.8045d87852f1307fea6dc751c4d15992p-2,
+    0x1.89eaa8p-2
+  },
+  { // Entry 645
+    -0x1.8045d87852f1307fea6dc751c4d15992p-2,
+    -0x1.89eaa8p-2
+  },
+  { // Entry 646
+    0x1.323b7b04ee88cff98b2a1620e1f61a01p-1,
+    0x1.48439ap-1
+  },
+  { // Entry 647
+    -0x1.323b7b04ee88cff98b2a1620e1f61a01p-1,
+    -0x1.48439ap-1
+  },
+  { // Entry 648
+    0x1.904c2b02aa59528ce044bf2213c96859p-1,
+    0x1.cb91e0p-1
+  },
+  { // Entry 649
+    -0x1.904c2b02aa59528ce044bf2213c96859p-1,
+    -0x1.cb91e0p-1
+  },
+  { // Entry 650
+    0x1.d42ddd25b3797e6a679f76e05e6c3e08p-1,
+    0x1.277014p0
+  },
+  { // Entry 651
+    -0x1.d42ddd25b3797e6a679f76e05e6c3e08p-1,
+    -0x1.277014p0
+  },
+  { // Entry 652
+    0x1.f96fe1a0b12d0ad4fa8c82d8af989c5ap-1,
+    0x1.691738p0
+  },
+  { // Entry 653
+    -0x1.f96fe1a0b12d0ad4fa8c82d8af989c5ap-1,
+    -0x1.691738p0
+  },
+  { // Entry 654
+    0x1.fda255f96094d8fe4e859c4cf0dd68a5p-1,
+    0x1.aabe5cp0
+  },
+  { // Entry 655
+    -0x1.fda255f96094d8fe4e859c4cf0dd68a5p-1,
+    -0x1.aabe5cp0
+  },
+  { // Entry 656
+    0x1.e07ef267748b982778f8d50d2981bb3ap-1,
+    0x1.ec6580p0
+  },
+  { // Entry 657
+    -0x1.e07ef267748b982778f8d50d2981bb3ap-1,
+    -0x1.ec6580p0
+  },
+  { // Entry 658
+    0x1.a3eda2adb01143fb21453b20bd1748fep-1,
+    0x1.170652p1
+  },
+  { // Entry 659
+    -0x1.a3eda2adb01143fb21453b20bd1748fep-1,
+    -0x1.170652p1
+  },
+  { // Entry 660
+    0x1.4be49bd88a64a0bb414ddacac4fa8de9p-1,
+    0x1.37d9e4p1
+  },
+  { // Entry 661
+    -0x1.4be49bd88a64a0bb414ddacac4fa8de9p-1,
+    -0x1.37d9e4p1
+  },
+  { // Entry 662
+    0x1.bc4c0a9b3782e220ae55786369ccf190p-2,
+    0x1.58ad76p1
+  },
+  { // Entry 663
+    -0x1.bc4c0a9b3782e220ae55786369ccf190p-2,
+    -0x1.58ad76p1
+  },
+  { // Entry 664
+    0x1.877e301f43cafffe6644a8958f108729p-3,
+    0x1.798108p1
+  },
+  { // Entry 665
+    -0x1.877e301f43cafffe6644a8958f108729p-3,
+    -0x1.798108p1
+  },
+  { // Entry 666
+    -0x1.066e8ae1f824a69817e6a806e6317e28p-4,
+    0x1.9a549ap1
+  },
+  { // Entry 667
+    0x1.066e8ae1f824a69817e6a806e6317e28p-4,
+    -0x1.9a549ap1
+  },
+  { // Entry 668
+    -0x1.42abc1eca11a0ad12ca6eeff197318aap-2,
+    0x1.bb282cp1
+  },
+  { // Entry 669
+    0x1.42abc1eca11a0ad12ca6eeff197318aap-2,
+    -0x1.bb282cp1
+  },
+  { // Entry 670
+    -0x1.17505efb8119773c647468be1dfee45ep-1,
+    0x1.dbfbbep1
+  },
+  { // Entry 671
+    0x1.17505efb8119773c647468be1dfee45ep-1,
+    -0x1.dbfbbep1
+  },
+  { // Entry 672
+    -0x1.7b05bd8091cd79dff359c8412b0de1a9p-1,
+    0x1.fccf50p1
+  },
+  { // Entry 673
+    0x1.7b05bd8091cd79dff359c8412b0de1a9p-1,
+    -0x1.fccf50p1
+  },
+  { // Entry 674
+    -0x1.c5f05982eabf022748960961666d540dp-1,
+    0x1.0ed170p2
+  },
+  { // Entry 675
+    0x1.c5f05982eabf022748960961666d540dp-1,
+    -0x1.0ed170p2
+  },
+  { // Entry 676
+    -0x1.f329bfbda8122f83e3a1ea0242eb76aap-1,
+    0x1.1f3b38p2
+  },
+  { // Entry 677
+    0x1.f329bfbda8122f83e3a1ea0242eb76aap-1,
+    -0x1.1f3b38p2
+  },
+  { // Entry 678
+    -0x1.ffbca88ae90f0900b6d3ad89eddd2c80p-1,
+    0x1.2fa5p2
+  },
+  { // Entry 679
+    0x1.ffbca88ae90f0900b6d3ad89eddd2c80p-1,
+    -0x1.2fa5p2
+  },
+  { // Entry 680
+    -0x1.ead687409c95dcaf61af98513517f507p-1,
+    0x1.400ec8p2
+  },
+  { // Entry 681
+    0x1.ead687409c95dcaf61af98513517f507p-1,
+    -0x1.400ec8p2
+  },
+  { // Entry 682
+    -0x1.b5d54fd79372b90d5d4c7acf7adaed42p-1,
+    0x1.507890p2
+  },
+  { // Entry 683
+    0x1.b5d54fd79372b90d5d4c7acf7adaed42p-1,
+    -0x1.507890p2
+  },
+  { // Entry 684
+    -0x1.643092f42ae797375531420c005ca2cfp-1,
+    0x1.60e258p2
+  },
+  { // Entry 685
+    0x1.643092f42ae797375531420c005ca2cfp-1,
+    -0x1.60e258p2
+  },
+  { // Entry 686
+    -0x1.f67edf3b7bee8554d54d84ea83f6cb21p-2,
+    0x1.714c20p2
+  },
+  { // Entry 687
+    0x1.f67edf3b7bee8554d54d84ea83f6cb21p-2,
+    -0x1.714c20p2
+  },
+  { // Entry 688
+    -0x1.03be4d93d949325340b2f464201545a7p-2,
+    0x1.81b5e8p2
+  },
+  { // Entry 689
+    0x1.03be4d93d949325340b2f464201545a7p-2,
+    -0x1.81b5e8p2
+  },
+  { // Entry 690
+    0x1.efb26cfa20f2098ff7e9e42f0260eb01p-5,
+    0x1.effffep-5
+  },
+  { // Entry 691
+    -0x1.efb26cfa20f2098ff7e9e42f0260eb01p-5,
+    -0x1.effffep-5
+  },
+  { // Entry 692
+    0x1.efb26ef930c4d3f2b0dbe1931ba5ae64p-5,
+    0x1.f0p-5
+  },
+  { // Entry 693
+    -0x1.efb26ef930c4d3f2b0dbe1931ba5ae64p-5,
+    -0x1.f0p-5
+  },
+  { // Entry 694
+    0x1.efb270f840979c65b75ee5c67016a866p-5,
+    0x1.f00002p-5
+  },
+  { // Entry 695
+    -0x1.efb270f840979c65b75ee5c67016a866p-5,
+    -0x1.f00002p-5
+  },
+  { // Entry 696
+    0x1.f6baa816fce5ea5a60d8c9fd2a289380p-4,
+    0x1.f7fffep-4
+  },
+  { // Entry 697
+    -0x1.f6baa816fce5ea5a60d8c9fd2a289380p-4,
+    -0x1.f7fffep-4
+  },
+  { // Entry 698
+    0x1.f6baaa131de6438e5611279864fe7663p-4,
+    0x1.f8p-4
+  },
+  { // Entry 699
+    -0x1.f6baaa131de6438e5611279864fe7663p-4,
+    -0x1.f8p-4
+  },
+  { // Entry 700
+    0x1.f6baac0f3ee694e760a138bc06c8be3dp-4,
+    0x1.f80002p-4
+  },
+  { // Entry 701
+    -0x1.f6baac0f3ee694e760a138bc06c8be3dp-4,
+    -0x1.f80002p-4
+  },
+  { // Entry 702
+    0x1.4a8c395552fb432af31780e883c98f71p-3,
+    0x1.4bfffep-3
+  },
+  { // Entry 703
+    -0x1.4a8c395552fb432af31780e883c98f71p-3,
+    -0x1.4bfffep-3
+  },
+  { // Entry 704
+    0x1.4a8c3b4e9c7fffd48305f44a42f5f50fp-3,
+    0x1.4cp-3
+  },
+  { // Entry 705
+    -0x1.4a8c3b4e9c7fffd48305f44a42f5f50fp-3,
+    -0x1.4cp-3
+  },
+  { // Entry 706
+    0x1.4a8c3d47e604a7d54f3f7de402409e2cp-3,
+    0x1.4c0002p-3
+  },
+  { // Entry 707
+    -0x1.4a8c3d47e604a7d54f3f7de402409e2cp-3,
+    -0x1.4c0002p-3
+  },
+  { // Entry 708
+    0x1.2e9cd83630eb35c12efcfb8413583998p-2,
+    0x1.333332p-2
+  },
+  { // Entry 709
+    -0x1.2e9cd83630eb35c12efcfb8413583998p-2,
+    -0x1.333332p-2
+  },
+  { // Entry 710
+    0x1.2e9cda1f52c88042833f236ff0f9d486p-2,
+    0x1.333334p-2
+  },
+  { // Entry 711
+    -0x1.2e9cda1f52c88042833f236ff0f9d486p-2,
+    -0x1.333334p-2
+  },
+  { // Entry 712
+    0x1.2e9cdc0874a57f1ca0f976a9b01e4a71p-2,
+    0x1.333336p-2
+  },
+  { // Entry 713
+    -0x1.2e9cdc0874a57f1ca0f976a9b01e4a71p-2,
+    -0x1.333336p-2
+  },
+  { // Entry 714
+    0x1.3faefb2b68e6786eb692bd4e4045213ep-1,
+    0x1.594316p-1
+  },
+  { // Entry 715
+    -0x1.3faefb2b68e6786eb692bd4e4045213ep-1,
+    -0x1.594316p-1
+  },
+  { // Entry 716
+    0x1.3faefcbb57c26b0d84b63dbfb72b413bp-1,
+    0x1.594318p-1
+  },
+  { // Entry 717
+    -0x1.3faefcbb57c26b0d84b63dbfb72b413bp-1,
+    -0x1.594318p-1
+  },
+  { // Entry 718
+    0x1.3faefe4b469d1dfd561e666edda7c6e6p-1,
+    0x1.59431ap-1
+  },
+  { // Entry 719
+    -0x1.3faefe4b469d1dfd561e666edda7c6e6p-1,
+    -0x1.59431ap-1
+  },
+  { // Entry 720
+    0x1.6888a375ab228c1e031c4005769509f9p-1,
+    0x1.8ffffep-1
+  },
+  { // Entry 721
+    -0x1.6888a375ab228c1e031c4005769509f9p-1,
+    -0x1.8ffffep-1
+  },
+  { // Entry 722
+    0x1.6888a4e134b2ea520b226eca8694b3a2p-1,
+    0x1.90p-1
+  },
+  { // Entry 723
+    -0x1.6888a4e134b2ea520b226eca8694b3a2p-1,
+    -0x1.90p-1
+  },
+  { // Entry 724
+    0x1.6888a64cbe41dffd6e4768dcca4db53bp-1,
+    0x1.900002p-1
+  },
+  { // Entry 725
+    -0x1.6888a64cbe41dffd6e4768dcca4db53bp-1,
+    -0x1.900002p-1
+  },
+  { // Entry 726
+    -0.0f,
+    -0x1.p-149
+  },
+  { // Entry 727
+    0.0f,
+    0x1.p-149
+  },
+  { // Entry 728
+    0.0,
+    0.0
+  },
+  { // Entry 729
+    0.0f,
+    0x1.p-149
+  },
+  { // Entry 730
+    -0.0f,
+    -0x1.p-149
+  },
+  { // Entry 731
+    0x1.91f65dccfead353d8db9c32f12262730p-5,
+    0x1.921fb4p-5
+  },
+  { // Entry 732
+    -0x1.91f65dccfead353d8db9c32f12262730p-5,
+    -0x1.921fb4p-5
+  },
+  { // Entry 733
+    0x1.91f65fcc60cb6d09fcc5c35dd6a798c8p-5,
+    0x1.921fb6p-5
+  },
+  { // Entry 734
+    -0x1.91f65fcc60cb6d09fcc5c35dd6a798c8p-5,
+    -0x1.921fb6p-5
+  },
+  { // Entry 735
+    0x1.91f661cbc2e9a3447571f72bcfbc21e2p-5,
+    0x1.921fb8p-5
+  },
+  { // Entry 736
+    -0x1.91f661cbc2e9a3447571f72bcfbc21e2p-5,
+    -0x1.921fb8p-5
+  },
+  { // Entry 737
+    0x1.917a6a7fe8297bf0a1125fb02b2038aep-4,
+    0x1.921fb4p-4
+  },
+  { // Entry 738
+    -0x1.917a6a7fe8297bf0a1125fb02b2038aep-4,
+    -0x1.921fb4p-4
+  },
+  { // Entry 739
+    0x1.917a6c7d7103b9d90e09615164449c6bp-4,
+    0x1.921fb6p-4
+  },
+  { // Entry 740
+    -0x1.917a6c7d7103b9d90e09615164449c6bp-4,
+    -0x1.921fb6p-4
+  },
+  { // Entry 741
+    0x1.917a6e7af9ddf17b914e6d2e8e83b33ep-4,
+    0x1.921fb8p-4
+  },
+  { // Entry 742
+    -0x1.917a6e7af9ddf17b914e6d2e8e83b33ep-4,
+    -0x1.921fb8p-4
+  },
+  { // Entry 743
+    0x1.8f8b82889296b5cf7904db1e74b3466bp-3,
+    0x1.921fb4p-3
+  },
+  { // Entry 744
+    -0x1.8f8b82889296b5cf7904db1e74b3466bp-3,
+    -0x1.921fb4p-3
+  },
+  { // Entry 745
+    0x1.8f8b847ebc13b8998ec5b37e7065341ep-3,
+    0x1.921fb6p-3
+  },
+  { // Entry 746
+    -0x1.8f8b847ebc13b8998ec5b37e7065341ep-3,
+    -0x1.921fb6p-3
+  },
+  { // Entry 747
+    0x1.8f8b8674e590a26aec3ea01d30aed486p-3,
+    0x1.921fb8p-3
+  },
+  { // Entry 748
+    -0x1.8f8b8674e590a26aec3ea01d30aed486p-3,
+    -0x1.921fb8p-3
+  },
+  { // Entry 749
+    0x1.87de293f569717a42a3bdb01aeae2063p-2,
+    0x1.921fb4p-2
+  },
+  { // Entry 750
+    -0x1.87de293f569717a42a3bdb01aeae2063p-2,
+    -0x1.921fb4p-2
+  },
+  { // Entry 751
+    0x1.87de2b185d5417dca800b85ca1319043p-2,
+    0x1.921fb6p-2
+  },
+  { // Entry 752
+    -0x1.87de2b185d5417dca800b85ca1319043p-2,
+    -0x1.921fb6p-2
+  },
+  { // Entry 753
+    0x1.87de2cf16410b61d9aff7e628fc853b2p-2,
+    0x1.921fb8p-2
+  },
+  { // Entry 754
+    -0x1.87de2cf16410b61d9aff7e628fc853b2p-2,
+    -0x1.921fb8p-2
+  },
+  { // Entry 755
+    0x1.6a09e582aa3945461b5a8a0787d5ab5bp-1,
+    0x1.921fb4p-1
+  },
+  { // Entry 756
+    -0x1.6a09e582aa3945461b5a8a0787d5ab5bp-1,
+    -0x1.921fb4p-1
+  },
+  { // Entry 757
+    0x1.6a09e6ecb41fdd7e681872c854887019p-1,
+    0x1.921fb6p-1
+  },
+  { // Entry 758
+    -0x1.6a09e6ecb41fdd7e681872c854887019p-1,
+    -0x1.921fb6p-1
+  },
+  { // Entry 759
+    0x1.6a09e856be050baccde9a76961e84aa7p-1,
+    0x1.921fb8p-1
+  },
+  { // Entry 760
+    -0x1.6a09e856be050baccde9a76961e84aa7p-1,
+    -0x1.921fb8p-1
+  },
+  { // Entry 761
+    0x1.fffffffffffe6546cc38211c26dabeebp-1,
+    0x1.921fb4p0
+  },
+  { // Entry 762
+    -0x1.fffffffffffe6546cc38211c26dabeebp-1,
+    -0x1.921fb4p0
+  },
+  { // Entry 763
+    0x1.ffffffffffff76521249c7422930ed82p-1,
+    0x1.921fb6p0
+  },
+  { // Entry 764
+    -0x1.ffffffffffff76521249c7422930ed82p-1,
+    -0x1.921fb6p0
+  },
+  { // Entry 765
+    0x1.fffffffffff8875d585b6d6cfce97d9cp-1,
+    0x1.921fb8p0
+  },
+  { // Entry 766
+    -0x1.fffffffffff8875d585b6d6cfce97d9cp-1,
+    -0x1.921fb8p0
+  },
+  { // Entry 767
+    0x1.4442d184698831f15b6315bfa6b5ae75p-23,
+    0x1.921fb4p1
+  },
+  { // Entry 768
+    -0x1.4442d184698831f15b6315bfa6b5ae75p-23,
+    -0x1.921fb4p1
+  },
+  { // Entry 769
+    -0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    0x1.921fb6p1
+  },
+  { // Entry 770
+    0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    -0x1.921fb6p1
+  },
+  { // Entry 771
+    -0x1.5dde973dcb346afa46203cddc6f7fe97p-22,
+    0x1.921fb8p1
+  },
+  { // Entry 772
+    0x1.5dde973dcb346afa46203cddc6f7fe97p-22,
+    -0x1.921fb8p1
+  },
+  { // Entry 773
+    -0x1.4442d1846984217628872e56eb58b4c1p-22,
+    0x1.921fb4p2
+  },
+  { // Entry 774
+    0x1.4442d1846984217628872e56eb58b4c1p-22,
+    -0x1.921fb4p2
+  },
+  { // Entry 775
+    0x1.777a5cf72ceacbf6ec657e977ef771f1p-23,
+    0x1.921fb6p2
+  },
+  { // Entry 776
+    -0x1.777a5cf72ceacbf6ec657e977ef771f1p-23,
+    -0x1.921fb6p2
+  },
+  { // Entry 777
+    0x1.5dde973dcb1fff10bb0388479e82f4bbp-21,
+    0x1.921fb8p2
+  },
+  { // Entry 778
+    -0x1.5dde973dcb1fff10bb0388479e82f4bbp-21,
+    -0x1.921fb8p2
+  },
+  { // Entry 779
+    -0x1.4442d1846973df895d1791023ded513cp-21,
+    0x1.921fb4p3
+  },
+  { // Entry 780
+    0x1.4442d1846973df895d1791023ded513cp-21,
+    -0x1.921fb4p3
+  },
+  { // Entry 781
+    0x1.777a5cf72ce47c7a3ba04bc2a607a9a7p-22,
+    0x1.921fb6p3
+  },
+  { // Entry 782
+    -0x1.777a5cf72ce47c7a3ba04bc2a607a9a7p-22,
+    -0x1.921fb6p3
+  },
+  { // Entry 783
+    0x1.5dde973dcace4f6a8e90bd15e00610f8p-20,
+    0x1.921fb8p3
+  },
+  { // Entry 784
+    -0x1.5dde973dcace4f6a8e90bd15e00610f8p-20,
+    -0x1.921fb8p3
+  },
+  { // Entry 785
+    -0x1.4442d1846932d7d62f59209388c7f7cap-20,
+    0x1.921fb4p4
+  },
+  { // Entry 786
+    0x1.4442d1846932d7d62f59209388c7f7cap-20,
+    -0x1.921fb4p4
+  },
+  { // Entry 787
+    0x1.777a5cf72ccb3e87788b811229e725bcp-21,
+    0x1.921fb6p4
+  },
+  { // Entry 788
+    -0x1.777a5cf72ccb3e87788b811229e725bcp-21,
+    -0x1.921fb6p4
+  },
+  { // Entry 789
+    0x1.5dde973dc98790d1dcc602bd1b86bccap-19,
+    0x1.921fb8p4
+  },
+  { // Entry 790
+    -0x1.5dde973dc98790d1dcc602bd1b86bccap-19,
+    -0x1.921fb8p4
+  },
+  { // Entry 791
+    -0x1.4442d184682eb909785fad18bcb5dbfcp-19,
+    0x1.921fb4p5
+  },
+  { // Entry 792
+    0x1.4442d184682eb909785fad18bcb5dbfcp-19,
+    -0x1.921fb4p5
+  },
+  { // Entry 793
+    0x1.777a5cf72c6646bc6c38607eb34eea13p-20,
+    0x1.921fb6p5
+  },
+  { // Entry 794
+    -0x1.777a5cf72c6646bc6c38607eb34eea13p-20,
+    -0x1.921fb6p5
+  },
+  { // Entry 795
+    0x1.5dde973dc46c966f15a2403d60cd14d0p-18,
+    0x1.921fb8p5
+  },
+  { // Entry 796
+    -0x1.5dde973dc46c966f15a2403d60cd14d0p-18,
+    -0x1.921fb8p5
+  },
+  { // Entry 797
+    -0x1.4442d184641e3dd69c7ec32e14a209a5p-18,
+    0x1.921fb4p6
+  },
+  { // Entry 798
+    0x1.4442d184641e3dd69c7ec32e14a209a5p-18,
+    -0x1.921fb4p6
+  },
+  { // Entry 799
+    0x1.777a5cf72ad267903aec8118778b3b5ap-19,
+    0x1.921fb6p6
+  },
+  { // Entry 800
+    -0x1.777a5cf72ad267903aec8118778b3b5ap-19,
+    -0x1.921fb6p6
+  },
+  { // Entry 801
+    0x1.5dde973db000ace3f985a473ea1fc039p-17,
+    0x1.921fb8p6
+  },
+  { // Entry 802
+    -0x1.5dde973db000ace3f985a473ea1fc039p-17,
+    -0x1.921fb8p6
+  },
+  { // Entry 803
+    -0x1.4442d18453dc510b2d495b8bf79bd1cep-17,
+    0x1.921fb4p7
+  },
+  { // Entry 804
+    0x1.4442d18453dc510b2d495b8bf79bd1cep-17,
+    -0x1.921fb4p7
+  },
+  { // Entry 805
+    0x1.777a5cf72482eadf75c731f972507718p-18,
+    0x1.921fb6p7
+  },
+  { // Entry 806
+    -0x1.777a5cf72482eadf75c731f972507718p-18,
+    -0x1.921fb6p7
+  },
+  { // Entry 807
+    0x1.5dde973d5e5106b7903a18a552aefc6ep-16,
+    0x1.921fb8p7
+  },
+  { // Entry 808
+    -0x1.5dde973d5e5106b7903a18a552aefc6ep-16,
+    -0x1.921fb8p7
+  },
+  { // Entry 809
+    0x1.6a09f1940b80c8e25cfc8c10d42576c6p-1,
+    0x1.2d97c4p1
+  },
+  { // Entry 810
+    -0x1.6a09f1940b80c8e25cfc8c10d42576c6p-1,
+    -0x1.2d97c4p1
+  },
+  { // Entry 811
+    0x1.6a09ebebe40889245d57c5c9d90a6d82p-1,
+    0x1.2d97c6p1
+  },
+  { // Entry 812
+    -0x1.6a09ebebe40889245d57c5c9d90a6d82p-1,
+    -0x1.2d97c6p1
+  },
+  { // Entry 813
+    0x1.6a09e643bc79a8c79ef4bf187727e269p-1,
+    0x1.2d97c8p1
+  },
+  { // Entry 814
+    -0x1.6a09e643bc79a8c79ef4bf187727e269p-1,
+    -0x1.2d97c8p1
+  },
+  { // Entry 815
+    -0x1.6a09df19704cf14108e09000ff6374bfp-1,
+    0x1.f6a7a0p1
+  },
+  { // Entry 816
+    0x1.6a09df19704cf14108e09000ff6374bfp-1,
+    -0x1.f6a7a0p1
+  },
+  { // Entry 817
+    -0x1.6a09e4c197f87ace1c81b43022be39b1p-1,
+    0x1.f6a7a2p1
+  },
+  { // Entry 818
+    0x1.6a09e4c197f87ace1c81b43022be39b1p-1,
+    -0x1.f6a7a2p1
+  },
+  { // Entry 819
+    -0x1.6a09ea69bf8d63bce40958f5c4b4f155p-1,
+    0x1.f6a7a4p1
+  },
+  { // Entry 820
+    0x1.6a09ea69bf8d63bce40958f5c4b4f155p-1,
+    -0x1.f6a7a4p1
+  },
+  { // Entry 821
+    -0x1.ffffffffff065cb240bb8f9519d2c6f1p-1,
+    0x1.2d97c4p2
+  },
+  { // Entry 822
+    0x1.ffffffffff065cb240bb8f9519d2c6f1p-1,
+    -0x1.2d97c4p2
+  },
+  { // Entry 823
+    -0x1.ffffffffffc32939898f464aafc2e74ap-1,
+    0x1.2d97c6p2
+  },
+  { // Entry 824
+    0x1.ffffffffffc32939898f464aafc2e74ap-1,
+    -0x1.2d97c6p2
+  },
+  { // Entry 825
+    -0x1.fffffffffffff5c0d2630ee0a1fb4e7bp-1,
+    0x1.2d97c8p2
+  },
+  { // Entry 826
+    0x1.fffffffffffff5c0d2630ee0a1fb4e7bp-1,
+    -0x1.2d97c8p2
+  },
+  { // Entry 827
+    -0x1.6a09f529316cde5a190d235cc4ccb825p-1,
+    0x1.5fdbbcp2
+  },
+  { // Entry 828
+    0x1.6a09f529316cde5a190d235cc4ccb825p-1,
+    -0x1.5fdbbcp2
+  },
+  { // Entry 829
+    -0x1.6a09e9d8e2826770567ea818b2e89960p-1,
+    0x1.5fdbbep2
+  },
+  { // Entry 830
+    0x1.6a09e9d8e2826770567ea818b2e89960p-1,
+    -0x1.5fdbbep2
+  },
+  { // Entry 831
+    -0x1.6a09de88933d6e0c1db78e1d7cd15173p-1,
+    0x1.5fdbc0p2
+  },
+  { // Entry 832
+    0x1.6a09de88933d6e0c1db78e1d7cd15173p-1,
+    -0x1.5fdbc0p2
+  },
+  { // Entry 833
+    0x1.6a09d033fa715a407a6f03d01b91113fp-1,
+    0x1.c463a8p2
+  },
+  { // Entry 834
+    -0x1.6a09d033fa715a407a6f03d01b91113fp-1,
+    -0x1.c463a8p2
+  },
+  { // Entry 835
+    0x1.6a09db844a28f8635851fdf8818515efp-1,
+    0x1.c463aap2
+  },
+  { // Entry 836
+    -0x1.6a09db844a28f8635851fdf8818515efp-1,
+    -0x1.c463aap2
+  },
+  { // Entry 837
+    0x1.6a09e6d49986140f55226fc58672612cp-1,
+    0x1.c463acp2
+  },
+  { // Entry 838
+    -0x1.6a09e6d49986140f55226fc58672612cp-1,
+    -0x1.c463acp2
+  },
+  { // Entry 839
+    0x1.ffffffffff95397934cac1f28532d3d3p-1,
+    0x1.f6a7a0p2
+  },
+  { // Entry 840
+    -0x1.ffffffffff95397934cac1f28532d3d3p-1,
+    -0x1.f6a7a0p2
+  },
+  { // Entry 841
+    0x1.fffffffffffa8e5aae2bb93ae590f984p-1,
+    0x1.f6a7a2p2
+  },
+  { // Entry 842
+    -0x1.fffffffffffa8e5aae2bb93ae590f984p-1,
+    -0x1.f6a7a2p2
+  },
+  { // Entry 843
+    0x1.ffffffffffdfe33c278cb48a59ee3ef2p-1,
+    0x1.f6a7a4p2
+  },
+  { // Entry 844
+    -0x1.ffffffffffdfe33c278cb48a59ee3ef2p-1,
+    -0x1.f6a7a4p2
+  },
+  { // Entry 845
+    0x1.6a0a040ea5c32ba4afbeb86a614c5d16p-1,
+    0x1.1475cap3
+  },
+  { // Entry 846
+    -0x1.6a0a040ea5c32ba4afbeb86a614c5d16p-1,
+    -0x1.1475cap3
+  },
+  { // Entry 847
+    0x1.6a09ed6e088212b1e260a5132d6959b7p-1,
+    0x1.1475ccp3
+  },
+  { // Entry 848
+    -0x1.6a09ed6e088212b1e260a5132d6959b7p-1,
+    -0x1.1475ccp3
+  },
+  { // Entry 849
+    0x1.6a09d6cd69d6efd1a6fa2dd4c617cbbep-1,
+    0x1.1475cep3
+  },
+  { // Entry 850
+    -0x1.6a09d6cd69d6efd1a6fa2dd4c617cbbep-1,
+    -0x1.1475cep3
+  },
+  { // Entry 851
+    0x1.f9990e91a64ae486757878bdfee0f703p-20,
+    0x1.2d97c4p3
+  },
+  { // Entry 852
+    -0x1.f9990e91a64ae486757878bdfee0f703p-20,
+    -0x1.2d97c4p3
+  },
+  { // Entry 853
+    0x1.f3321d234ed8128aabb0499a43b4def2p-21,
+    0x1.2d97c6p3
+  },
+  { // Entry 854
+    -0x1.f3321d234ed8128aabb0499a43b4def2p-21,
+    -0x1.2d97c6p3
+  },
+  { // Entry 855
+    -0x1.99bc5b961b1ac296dbe1980fd2c890a0p-26,
+    0x1.2d97c8p3
+  },
+  { // Entry 856
+    0x1.99bc5b961b1ac296dbe1980fd2c890a0p-26,
+    -0x1.2d97c8p3
+  },
+  { // Entry 857
+    -0x1.6a09c14e83f8db080d1223f887cc12ecp-1,
+    0x1.46b9c0p3
+  },
+  { // Entry 858
+    0x1.6a09c14e83f8db080d1223f887cc12ecp-1,
+    -0x1.46b9c0p3
+  },
+  { // Entry 859
+    -0x1.6a09d7ef23fbec1ed812e807beb0492fp-1,
+    0x1.46b9c2p3
+  },
+  { // Entry 860
+    0x1.6a09d7ef23fbec1ed812e807beb0492fp-1,
+    -0x1.46b9c2p3
+  },
+  { // Entry 861
+    -0x1.6a09ee8fc294f35db3efce565365af89p-1,
+    0x1.46b9c4p3
+  },
+  { // Entry 862
+    0x1.6a09ee8fc294f35db3efce565365af89p-1,
+    -0x1.46b9c4p3
+  },
+  { // Entry 863
+    -0x1.fffffffffe4c96b397d951cb21861c95p-1,
+    0x1.5fdbbcp3
+  },
+  { // Entry 864
+    0x1.fffffffffe4c96b397d951cb21861c95p-1,
+    -0x1.5fdbbcp3
+  },
+  { // Entry 865
+    -0x1.ffffffffffe8512aebb56c9e75b41941p-1,
+    0x1.5fdbbep3
+  },
+  { // Entry 866
+    0x1.ffffffffffe8512aebb56c9e75b41941p-1,
+    -0x1.5fdbbep3
+  },
+  { // Entry 867
+    -0x1.ffffffffff840ba23f91c9cb49a10b27p-1,
+    0x1.5fdbc0p3
+  },
+  { // Entry 868
+    0x1.ffffffffff840ba23f91c9cb49a10b27p-1,
+    -0x1.5fdbc0p3
+  },
+  { // Entry 869
+    -0x1.6a0a12f4197c90a0ee4a094b6377aa23p-1,
+    0x1.78fdb6p3
+  },
+  { // Entry 870
+    0x1.6a0a12f4197c90a0ee4a094b6377aa23p-1,
+    -0x1.78fdb6p3
+  },
+  { // Entry 871
+    -0x1.6a09fc537d29cf131d6710991bebabedp-1,
+    0x1.78fdb8p3
+  },
+  { // Entry 872
+    0x1.6a09fc537d29cf131d6710991bebabedp-1,
+    -0x1.78fdb8p3
+  },
+  { // Entry 873
+    -0x1.6a09e5b2df6d0388f9070c4340f3e669p-1,
+    0x1.78fdbap3
+  },
+  { // Entry 874
+    0x1.6a09e5b2df6d0388f9070c4340f3e669p-1,
+    -0x1.78fdbap3
+  },
+  { // Entry 875
+    0x1.6a09c909add4dbf32253a39d5c306308p-1,
+    0x1.ab41aep3
+  },
+  { // Entry 876
+    -0x1.6a09c909add4dbf32253a39d5c306308p-1,
+    -0x1.ab41aep3
+  },
+  { // Entry 877
+    0x1.6a09dfaa4d5c3a7f056f3e61a365b29ep-1,
+    0x1.ab41b0p3
+  },
+  { // Entry 878
+    -0x1.6a09dfaa4d5c3a7f056f3e61a365b29ep-1,
+    -0x1.ab41b0p3
+  },
+  { // Entry 879
+    0x1.6a09f64aeb798f2b3e3d9b16e8e3c412p-1,
+    0x1.ab41b2p3
+  },
+  { // Entry 880
+    -0x1.6a09f64aeb798f2b3e3d9b16e8e3c412p-1,
+    -0x1.ab41b2p3
+  },
+  { // Entry 881
+    0x1.fffffffffc260d6ffb8f4cd8ab3fd020p-1,
+    0x1.c463a8p3
+  },
+  { // Entry 882
+    -0x1.fffffffffc260d6ffb8f4cd8ab3fd020p-1,
+    -0x1.c463a8p3
+  },
+  { // Entry 883
+    0x1.ffffffffff12d89bb084dd762848b3d6p-1,
+    0x1.c463aap3
+  },
+  { // Entry 884
+    -0x1.ffffffffff12d89bb084dd762848b3d6p-1,
+    -0x1.c463aap3
+  },
+  { // Entry 885
+    0x1.ffffffffffffa3c7657b85e5b44bbd44p-1,
+    0x1.c463acp3
+  },
+  { // Entry 886
+    -0x1.ffffffffffffa3c7657b85e5b44bbd44p-1,
+    -0x1.c463acp3
+  },
+  { // Entry 887
+    0x1.6a0a0b38f134a3295a0b386e42f1ca7ap-1,
+    0x1.dd85a4p3
+  },
+  { // Entry 888
+    -0x1.6a0a0b38f134a3295a0b386e42f1ca7ap-1,
+    -0x1.dd85a4p3
+  },
+  { // Entry 889
+    0x1.6a09f49854662eff1b35755a129044a7p-1,
+    0x1.dd85a6p3
+  },
+  { // Entry 890
+    -0x1.6a09f49854662eff1b35755a129044a7p-1,
+    -0x1.dd85a6p3
+  },
+  { // Entry 891
+    0x1.6a09ddf7b62db0e0440b6a4262203b11p-1,
+    0x1.dd85a8p3
+  },
+  { // Entry 892
+    -0x1.6a09ddf7b62db0e0440b6a4262203b11p-1,
+    -0x1.dd85a8p3
+  },
+  { // Entry 893
+    0x1.4aa9c2f2c19a062b18a017bcd5424feap-20,
+    0x1.f6a7a0p3
+  },
+  { // Entry 894
+    -0x1.4aa9c2f2c19a062b18a017bcd5424feap-20,
+    -0x1.f6a7a0p3
+  },
+  { // Entry 895
+    0x1.2aa70bcb07d3a40781510d213652e43ap-22,
+    0x1.f6a7a2p3
+  },
+  { // Entry 896
+    -0x1.2aa70bcb07d3a40781510d213652e43ap-22,
+    -0x1.f6a7a2p3
+  },
+  { // Entry 897
+    -0x1.6aac7a1a7bf5bbd49572ffb8d7749922p-21,
+    0x1.f6a7a4p3
+  },
+  { // Entry 898
+    0x1.6aac7a1a7bf5bbd49572ffb8d7749922p-21,
+    -0x1.f6a7a4p3
+  },
+  { // Entry 899
+    -0x1.6a09a383953124096898340f9168b9d5p-1,
+    0x1.07e4ccp4
+  },
+  { // Entry 900
+    0x1.6a09a383953124096898340f9168b9d5p-1,
+    -0x1.07e4ccp4
+  },
+  { // Entry 901
+    -0x1.6a09d0c4d7869961c47a9b0b968cc910p-1,
+    0x1.07e4cep4
+  },
+  { // Entry 902
+    0x1.6a09d0c4d7869961c47a9b0b968cc910p-1,
+    -0x1.07e4cep4
+  },
+  { // Entry 903
+    -0x1.6a09fe061433e7770d00ca59d5a56251p-1,
+    0x1.07e4d0p4
+  },
+  { // Entry 904
+    0x1.6a09fe061433e7770d00ca59d5a56251p-1,
+    -0x1.07e4d0p4
+  },
+  { // Entry 905
+    -0x1.fffffffff9219dae5feda1b539335803p-1,
+    0x1.1475cap4
+  },
+  { // Entry 906
+    0x1.fffffffff9219dae5feda1b539335803p-1,
+    -0x1.1475cap4
+  },
+  { // Entry 907
+    -0x1.ffffffffff9d556e8c0bf0a80d610808p-1,
+    0x1.1475ccp4
+  },
+  { // Entry 908
+    0x1.ffffffffff9d556e8c0bf0a80d610808p-1,
+    -0x1.1475ccp4
+  },
+  { // Entry 909
+    -0x1.fffffffffe190d2eb82e74efd2093215p-1,
+    0x1.1475cep4
+  },
+  { // Entry 910
+    0x1.fffffffffe190d2eb82e74efd2093215p-1,
+    -0x1.1475cep4
+  },
+  { // Entry 911
+    -0x1.6a0a1a1e64a28eee238dc852846aacd5p-1,
+    0x1.2106c8p4
+  },
+  { // Entry 912
+    0x1.6a0a1a1e64a28eee238dc852846aacd5p-1,
+    -0x1.2106c8p4
+  },
+  { // Entry 913
+    -0x1.6a09ecdd2b784b699034ee8102670e27p-1,
+    0x1.2106cap4
+  },
+  { // Entry 914
+    0x1.6a09ecdd2b784b699034ee8102670e27p-1,
+    -0x1.2106cap4
+  },
+  { // Entry 915
+    -0x1.6a09bf9beca5e03188301639c09ed574p-1,
+    0x1.2106ccp4
+  },
+  { // Entry 916
+    0x1.6a09bf9beca5e03188301639c09ed574p-1,
+    -0x1.2106ccp4
+  },
+  { // Entry 917
+    -0x1.f9990e91a270d3bc1c02f4f69f48e675p-19,
+    0x1.2d97c4p4
+  },
+  { // Entry 918
+    0x1.f9990e91a270d3bc1c02f4f69f48e675p-19,
+    -0x1.2d97c4p4
+  },
+  { // Entry 919
+    -0x1.f3321d234deacd6f3afd75039685012fp-20,
+    0x1.2d97c6p4
+  },
+  { // Entry 920
+    0x1.f3321d234deacd6f3afd75039685012fp-20,
+    -0x1.2d97c6p4
+  },
+  { // Entry 921
+    0x1.99bc5b961b1aa1c9e8023074f3406fd9p-25,
+    0x1.2d97c8p4
+  },
+  { // Entry 922
+    -0x1.99bc5b961b1aa1c9e8023074f3406fd9p-25,
+    -0x1.2d97c8p4
+  },
+  { // Entry 923
+    0x1.6a09949e1ce1ec501afcb35d731bf62cp-1,
+    0x1.3a28c2p4
+  },
+  { // Entry 924
+    -0x1.6a09949e1ce1ec501afcb35d731bf62cp-1,
+    -0x1.3a28c2p4
+  },
+  { // Entry 925
+    0x1.6a09c1df6114100c65d1ff6c55755e72p-1,
+    0x1.3a28c4p4
+  },
+  { // Entry 926
+    -0x1.6a09c1df6114100c65d1ff6c55755e72p-1,
+    -0x1.3a28c4p4
+  },
+  { // Entry 927
+    0x1.6a09ef209f9e0cc13324ddf2b361553fp-1,
+    0x1.3a28c6p4
+  },
+  { // Entry 928
+    -0x1.6a09ef209f9e0cc13324ddf2b361553fp-1,
+    -0x1.3a28c6p4
+  },
+  { // Entry 929
+    0x1.fffffffff53f476ec4f59f26c4bcdfa0p-1,
+    0x1.46b9c0p4
+  },
+  { // Entry 930
+    -0x1.fffffffff53f476ec4f59f26c4bcdfa0p-1,
+    -0x1.46b9c0p4
+  },
+  { // Entry 931
+    0x1.fffffffffe5d2097b34334ad679dd7a4p-1,
+    0x1.46b9c2p4
+  },
+  { // Entry 932
+    -0x1.fffffffffe5d2097b34334ad679dd7a4p-1,
+    -0x1.46b9c2p4
+  },
+  { // Entry 933
+    0x1.ffffffffff7af9c0a19a005c565c6af7p-1,
+    0x1.46b9c4p4
+  },
+  { // Entry 934
+    -0x1.ffffffffff7af9c0a19a005c565c6af7p-1,
+    -0x1.46b9c4p4
+  },
+  { // Entry 935
+    0x1.6a0a2903d773925b052fb006ac670c23p-1,
+    0x1.534abep4
+  },
+  { // Entry 936
+    -0x1.6a0a2903d773925b052fb006ac670c23p-1,
+    -0x1.534abep4
+  },
+  { // Entry 937
+    0x1.6a09fbc2a025fdae918466fa00142143p-1,
+    0x1.534ac0p4
+  },
+  { // Entry 938
+    -0x1.6a09fbc2a025fdae918466fa00142143p-1,
+    -0x1.534ac0p4
+  },
+  { // Entry 939
+    0x1.6a09ce8163304113135a68ae93d3fa0ep-1,
+    0x1.534ac2p4
+  },
+  { // Entry 940
+    -0x1.6a09ce8163304113135a68ae93d3fa0ep-1,
+    -0x1.534ac2p4
+  },
+  { // Entry 941
+    0x1.4ddd3ba9ecb19d6bb6ea161120e447b9p-19,
+    0x1.5fdbbcp4
+  },
+  { // Entry 942
+    -0x1.4ddd3ba9ecb19d6bb6ea161120e447b9p-19,
+    -0x1.5fdbbcp4
+  },
+  { // Entry 943
+    0x1.3774eea7b89d80df7816fe208ec69fc0p-21,
+    0x1.5fdbbep4
+  },
+  { // Entry 944
+    -0x1.3774eea7b89d80df7816fe208ec69fc0p-21,
+    -0x1.5fdbbep4
+  },
+  { // Entry 945
+    -0x1.644588ac2334a3d5452d9960282cf80dp-20,
+    0x1.5fdbc0p4
+  },
+  { // Entry 946
+    0x1.644588ac2334a3d5452d9960282cf80dp-20,
+    -0x1.5fdbc0p4
+  },
+  { // Entry 947
+    -0x1.6a09b2f9ea049e855e35ca9ce7e0d89ap-1,
+    0x1.6c6cbap4
+  },
+  { // Entry 948
+    0x1.6a09b2f9ea049e855e35ca9ce7e0d89ap-1,
+    -0x1.6c6cbap4
+  },
+  { // Entry 949
+    -0x1.6a09e03b2a6b49c6134c67b42baee668p-1,
+    0x1.6c6cbcp4
+  },
+  { // Entry 950
+    0x1.6a09e03b2a6b49c6134c67b42baee668p-1,
+    -0x1.6c6cbcp4
+  },
+  { // Entry 951
+    -0x1.6a0a0d7c6529cd85dbbb3a5c2cd3fae5p-1,
+    0x1.6c6cbep4
+  },
+  { // Entry 952
+    0x1.6a0a0d7c6529cd85dbbb3a5c2cd3fae5p-1,
+    -0x1.6c6cbep4
+  },
+  { // Entry 953
+    -0x1.fffffffff07f0ab12aa8f41f29c15392p-1,
+    0x1.78fdb6p4
+  },
+  { // Entry 954
+    0x1.fffffffff07f0ab12aa8f41f29c15392p-1,
+    -0x1.78fdb6p4
+  },
+  { // Entry 955
+    -0x1.fffffffffc3f0542db21dcbcb847dac3p-1,
+    0x1.78fdb8p4
+  },
+  { // Entry 956
+    0x1.fffffffffc3f0542db21dcbcb847dac3p-1,
+    -0x1.78fdb8p4
+  },
+  { // Entry 957
+    -0x1.fffffffffffeffd48bac73efe60c7fcfp-1,
+    0x1.78fdbap4
+  },
+  { // Entry 958
+    0x1.fffffffffffeffd48bac73efe60c7fcfp-1,
+    -0x1.78fdbap4
+  },
+  { // Entry 959
+    -0x1.6a0a37e949a7ad698a32234c73e5afbap-1,
+    0x1.858eb4p4
+  },
+  { // Entry 960
+    0x1.6a0a37e949a7ad698a32234c73e5afbap-1,
+    -0x1.858eb4p4
+  },
+  { // Entry 961
+    -0x1.6a0a0aa81436c7a8d33a38d704030d14p-1,
+    0x1.858eb6p4
+  },
+  { // Entry 962
+    0x1.6a0a0aa81436c7a8d33a38d704030d14p-1,
+    -0x1.858eb6p4
+  },
+  { // Entry 963
+    -0x1.6a09dd66d91db9bd7bf355faff08f194p-1,
+    0x1.858eb8p4
+  },
+  { // Entry 964
+    0x1.6a09dd66d91db9bd7bf355faff08f194p-1,
+    -0x1.858eb8p4
+  },
+  { // Entry 965
+    0x1.c048b38a8bbf59f414fec7079209926ep-3,
+    0x1.fffffep62
+  },
+  { // Entry 966
+    -0x1.c048b38a8bbf59f414fec7079209926ep-3,
+    -0x1.fffffep62
+  },
+  { // Entry 967
+    0x1.fff6dfd42dc54430bc0576b00a88bd94p-1,
+    0x1.p63
+  },
+  { // Entry 968
+    -0x1.fff6dfd42dc54430bc0576b00a88bd94p-1,
+    -0x1.p63
+  },
+  { // Entry 969
+    -0x1.d6637d070347ee94e830445e76486727p-1,
+    0x1.000002p63
+  },
+  { // Entry 970
+    0x1.d6637d070347ee94e830445e76486727p-1,
+    -0x1.000002p63
+  },
+  { // Entry 971
+    -0x1.0e5283661df0ca0f55ab6167e14514a1p-1,
+    0x1.fffffep26
+  },
+  { // Entry 972
+    0x1.0e5283661df0ca0f55ab6167e14514a1p-1,
+    -0x1.fffffep26
+  },
+  { // Entry 973
+    -0x1.86dcc9babb0a40ee875cab3b9e892757p-1,
+    0x1.p27
+  },
+  { // Entry 974
+    0x1.86dcc9babb0a40ee875cab3b9e892757p-1,
+    -0x1.p27
+  },
+  { // Entry 975
+    0x1.171999b629fd5b6357c6dff4d7827d95p-1,
+    0x1.000002p27
+  },
+  { // Entry 976
+    -0x1.171999b629fd5b6357c6dff4d7827d95p-1,
+    -0x1.000002p27
+  },
+  { // Entry 977
+    -0x1.e57ec09221973550d1e5798dcf0cd25dp-1,
+    0x1.fffffep23
+  },
+  { // Entry 978
+    0x1.e57ec09221973550d1e5798dcf0cd25dp-1,
+    -0x1.fffffep23
+  },
+  { // Entry 979
+    -0x1.8f22f8433d6edfe9a4aff9622517caa9p-1,
+    0x1.p24
+  },
+  { // Entry 980
+    0x1.8f22f8433d6edfe9a4aff9622517caa9p-1,
+    -0x1.p24
+  },
+  { // Entry 981
+    0x1.c9b0c7265c543f80faf01741c6458560p-1,
+    0x1.000002p24
+  },
+  { // Entry 982
+    -0x1.c9b0c7265c543f80faf01741c6458560p-1,
+    -0x1.000002p24
+  },
+  { // Entry 983
+    -0x1.837b98a3185d1466d852f0a7dc1d248ep-1,
+    0x1.fffffep1
+  },
+  { // Entry 984
+    0x1.837b98a3185d1466d852f0a7dc1d248ep-1,
+    -0x1.fffffep1
+  },
+  { // Entry 985
+    -0x1.837b9dddc1eae70ce98055a0e450d93cp-1,
+    0x1.p2
+  },
+  { // Entry 986
+    0x1.837b9dddc1eae70ce98055a0e450d93cp-1,
+    -0x1.p2
+  },
+  { // Entry 987
+    -0x1.837ba85314bde52b1e9c2c8ed2712c72p-1,
+    0x1.000002p2
+  },
+  { // Entry 988
+    0x1.837ba85314bde52b1e9c2c8ed2712c72p-1,
+    -0x1.000002p2
+  },
+  { // Entry 989
+    0x1.d18f70573da63012fa1c0e3d2ebbe59cp-1,
+    0x1.fffffep0
+  },
+  { // Entry 990
+    -0x1.d18f70573da63012fa1c0e3d2ebbe59cp-1,
+    -0x1.fffffep0
+  },
+  { // Entry 991
+    0x1.d18f6ead1b445dfab848188009c9bb95p-1,
+    0x1.p1
+  },
+  { // Entry 992
+    -0x1.d18f6ead1b445dfab848188009c9bb95p-1,
+    -0x1.p1
+  },
+  { // Entry 993
+    0x1.d18f6b58d66ae7110b2b6f7cffba6ec1p-1,
+    0x1.000002p1
+  },
+  { // Entry 994
+    -0x1.d18f6b58d66ae7110b2b6f7cffba6ec1p-1,
+    -0x1.000002p1
+  },
+  { // Entry 995
+    0x1.aed547dbee4d0d8680d0813d1e4e21d0p-1,
+    0x1.fffffep-1
+  },
+  { // Entry 996
+    -0x1.aed547dbee4d0d8680d0813d1e4e21d0p-1,
+    -0x1.fffffep-1
+  },
+  { // Entry 997
+    0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.p0
+  },
+  { // Entry 998
+    -0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    -0x1.p0
+  },
+  { // Entry 999
+    0x1.aed54b19d5cd7937cbf41ed408ca0a52p-1,
+    0x1.000002p0
+  },
+  { // Entry 1000
+    -0x1.aed54b19d5cd7937cbf41ed408ca0a52p-1,
+    -0x1.000002p0
+  },
+  { // Entry 1001
+    0x1.eaee85835dde5b71beec7d8d98052112p-2,
+    0x1.fffffep-2
+  },
+  { // Entry 1002
+    -0x1.eaee85835dde5b71beec7d8d98052112p-2,
+    -0x1.fffffep-2
+  },
+  { // Entry 1003
+    0x1.eaee8744b05efe8764bc364fd837b666p-2,
+    0x1.p-1
+  },
+  { // Entry 1004
+    -0x1.eaee8744b05efe8764bc364fd837b666p-2,
+    -0x1.p-1
+  },
+  { // Entry 1005
+    0x1.eaee8ac7555ed47fca77ceed174c8ea0p-2,
+    0x1.000002p-1
+  },
+  { // Entry 1006
+    -0x1.eaee8ac7555ed47fca77ceed174c8ea0p-2,
+    -0x1.000002p-1
+  },
+  { // Entry 1007
+    0x1.faaeeb5f1c0d63f43c6f3ec46011690fp-3,
+    0x1.fffffep-3
+  },
+  { // Entry 1008
+    -0x1.faaeeb5f1c0d63f43c6f3ec46011690fp-3,
+    -0x1.fffffep-3
+  },
+  { // Entry 1009
+    0x1.faaeed4f31576ba89debdc7351e8b1aep-3,
+    0x1.p-2
+  },
+  { // Entry 1010
+    -0x1.faaeed4f31576ba89debdc7351e8b1aep-3,
+    -0x1.p-2
+  },
+  { // Entry 1011
+    0x1.faaef12f5beb1c1094473d3c3365b9e1p-3,
+    0x1.000002p-2
+  },
+  { // Entry 1012
+    -0x1.faaef12f5beb1c1094473d3c3365b9e1p-3,
+    -0x1.000002p-2
+  },
+  { // Entry 1013
+    0x1.feaaecec6d8e30cd56950eb2ebdcebd4p-4,
+    0x1.fffffep-4
+  },
+  { // Entry 1014
+    -0x1.feaaecec6d8e30cd56950eb2ebdcebd4p-4,
+    -0x1.fffffep-4
+  },
+  { // Entry 1015
+    0x1.feaaeee86ee35ca069a86721f89f85a5p-4,
+    0x1.p-3
+  },
+  { // Entry 1016
+    -0x1.feaaeee86ee35ca069a86721f89f85a5p-4,
+    -0x1.p-3
+  },
+  { // Entry 1017
+    0x1.feaaf2e0718d9c568c9442c81545cd62p-4,
+    0x1.000002p-3
+  },
+  { // Entry 1018
+    -0x1.feaaf2e0718d9c568c9442c81545cd62p-4,
+    -0x1.000002p-3
+  },
+  { // Entry 1019
+    0x1.ffaaacefd4d855ac8227799f3e263d7ap-5,
+    0x1.fffffep-5
+  },
+  { // Entry 1020
+    -0x1.ffaaacefd4d855ac8227799f3e263d7ap-5,
+    -0x1.fffffep-5
+  },
+  { // Entry 1021
+    0x1.ffaaaeeed4edab4ba4b365ed25a9595fp-5,
+    0x1.p-4
+  },
+  { // Entry 1022
+    -0x1.ffaaaeeed4edab4ba4b365ed25a9595fp-5,
+    -0x1.p-4
+  },
+  { // Entry 1023
+    0x1.ffaab2ecd518508ae9bc730a165a8eadp-5,
+    0x1.000002p-4
+  },
+  { // Entry 1024
+    -0x1.ffaab2ecd518508ae9bc730a165a8eadp-5,
+    -0x1.000002p-4
+  },
+  { // Entry 1025
+    0x1.ffeaa8ef2e85933883c0dc33462387b5p-6,
+    0x1.fffffep-6
+  },
+  { // Entry 1026
+    -0x1.ffeaa8ef2e85933883c0dc33462387b5p-6,
+    -0x1.fffffep-6
+  },
+  { // Entry 1027
+    0x1.ffeaaaeeee86e8cafe41376d47919579p-6,
+    0x1.p-5
+  },
+  { // Entry 1028
+    -0x1.ffeaaaeeee86e8cafe41376d47919579p-6,
+    -0x1.p-5
+  },
+  { // Entry 1029
+    0x1.ffeaaeee6e89927003413abe64e9dc21p-6,
+    0x1.000002p-5
+  },
+  { // Entry 1030
+    -0x1.ffeaaeee6e89927003413abe64e9dc21p-6,
+    -0x1.000002p-5
+  },
+  { // Entry 1031
+    0x1.fffaa8aefeed396ffffc636313d0ba6dp-7,
+    0x1.fffffep-7
+  },
+  { // Entry 1032
+    -0x1.fffaa8aefeed396ffffc636313d0ba6dp-7,
+    -0x1.fffffep-7
+  },
+  { // Entry 1033
+    0x1.fffaaaaeeeed4ed549c6560f889ee531p-7,
+    0x1.p-6
+  },
+  { // Entry 1034
+    -0x1.fffaaaaeeeed4ed549c6560f889ee531p-7,
+    -0x1.p-6
+  },
+  { // Entry 1035
+    0x1.fffaaeaeceed793fde5a1a9ca5bb1ee6p-7,
+    0x1.000002p-6
+  },
+  { // Entry 1036
+    -0x1.fffaaeaeceed793fde5a1a9ca5bb1ee6p-7,
+    -0x1.000002p-6
+  },
+  { // Entry 1037
+    0x1.fffffdfaaaaabaaeeeded997feffa35ap-15,
+    0x1.fffffep-15
+  },
+  { // Entry 1038
+    -0x1.fffffdfaaaaabaaeeeded997feffa35ap-15,
+    -0x1.fffffep-15
+  },
+  { // Entry 1039
+    0x1.fffffffaaaaaaaaeeeeeeeed4ed4ed4fp-15,
+    0x1.p-14
+  },
+  { // Entry 1040
+    -0x1.fffffffaaaaaaaaeeeeeeeed4ed4ed4fp-15,
+    -0x1.p-14
+  },
+  { // Entry 1041
+    0x1.000001fd5555455777578ccbe7bfc09cp-14,
+    0x1.000002p-14
+  },
+  { // Entry 1042
+    -0x1.000001fd5555455777578ccbe7bfc09cp-14,
+    -0x1.000002p-14
+  },
+  { // Entry 1043
+    0x1.fffffdfffffffeaaaaaeaaaaa6aaeef0p-28,
+    0x1.fffffep-28
+  },
+  { // Entry 1044
+    -0x1.fffffdfffffffeaaaaaeaaaaa6aaeef0p-28,
+    -0x1.fffffep-28
+  },
+  { // Entry 1045
+    0x1.fffffffffffffeaaaaaaaaaaaaaaeeeep-28,
+    0x1.p-27
+  },
+  { // Entry 1046
+    -0x1.fffffffffffffeaaaaaaaaaaaaaaeeeep-28,
+    -0x1.p-27
+  },
+  { // Entry 1047
+    0x1.000001ffffffff55555155554d557772p-27,
+    0x1.000002p-27
+  },
+  { // Entry 1048
+    -0x1.000001ffffffff55555155554d557772p-27,
+    -0x1.000002p-27
+  },
+  { // Entry 1049
+    0x1.fffffdfffffffffaaaaabaaaaa9aaaaep-31,
+    0x1.fffffep-31
+  },
+  { // Entry 1050
+    -0x1.fffffdfffffffffaaaaabaaaaa9aaaaep-31,
+    -0x1.fffffep-31
+  },
+  { // Entry 1051
+    0x1.fffffffffffffffaaaaaaaaaaaaaaaaep-31,
+    0x1.p-30
+  },
+  { // Entry 1052
+    -0x1.fffffffffffffffaaaaaaaaaaaaaaaaep-31,
+    -0x1.p-30
+  },
+  { // Entry 1053
+    0x1.000001fffffffffd5555455555355557p-30,
+    0x1.000002p-30
+  },
+  { // Entry 1054
+    -0x1.000001fffffffffd5555455555355557p-30,
+    -0x1.000002p-30
+  },
+  { // Entry 1055
+    0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1056
+    -0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1057
+    -0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1058
+    0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1059
+    -0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1060
+    0x1.0b3366508957520d9dc88d7c09337e24p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1061
+    -0x1.48ce575202efd93c62f7b88106ea1d4dp-1,
+    0x1.fffffcp127
+  },
+  { // Entry 1062
+    0x1.48ce575202efd93c62f7b88106ea1d4dp-1,
+    -0x1.fffffcp127
+  },
+  { // Entry 1063
+    -0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    0x1.921fb6p1
+  },
+  { // Entry 1064
+    0x1.777a5cf72cec5fd61896cb4f40d1de79p-24,
+    -0x1.921fb6p1
+  },
+  { // Entry 1065
+    0x1.ffffffffffff76521249c7422930ed82p-1,
+    0x1.921fb6p0
+  },
+  { // Entry 1066
+    -0x1.ffffffffffff76521249c7422930ed82p-1,
+    -0x1.921fb6p0
+  },
+  { // Entry 1067
+    0x1.aed54b19d5cd7937cbf41ed408ca0a52p-1,
+    0x1.000002p0
+  },
+  { // Entry 1068
+    -0x1.aed54b19d5cd7937cbf41ed408ca0a52p-1,
+    -0x1.000002p0
+  },
+  { // Entry 1069
+    0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    0x1.p0
+  },
+  { // Entry 1070
+    -0x1.aed548f090cee0418dd3d2138a1e7865p-1,
+    -0x1.p0
+  },
+  { // Entry 1071
+    0x1.aed547dbee4d0d8680d0813d1e4e21d0p-1,
+    0x1.fffffep-1
+  },
+  { // Entry 1072
+    -0x1.aed547dbee4d0d8680d0813d1e4e21d0p-1,
+    -0x1.fffffep-1
+  },
+  { // Entry 1073
+    0x1.6a09e6ecb41fdd7e681872c854887019p-1,
+    0x1.921fb6p-1
+  },
+  { // Entry 1074
+    -0x1.6a09e6ecb41fdd7e681872c854887019p-1,
+    -0x1.921fb6p-1
+  },
+  { // Entry 1075
+    0x1.000001ffffffffffffffffffffffffffp-126,
+    0x1.000002p-126
+  },
+  { // Entry 1076
+    -0x1.000001ffffffffffffffffffffffffffp-126,
+    -0x1.000002p-126
+  },
+  { // Entry 1077
+    0x1.ffffffffffffffffffffffffffffffffp-127,
+    0x1.p-126
+  },
+  { // Entry 1078
+    -0x1.ffffffffffffffffffffffffffffffffp-127,
+    -0x1.p-126
+  },
+  { // Entry 1079
+    0x1.fffffbffffffffffffffffffffffffffp-127,
+    0x1.fffffcp-127
+  },
+  { // Entry 1080
+    -0x1.fffffbffffffffffffffffffffffffffp-127,
+    -0x1.fffffcp-127
+  },
+  { // Entry 1081
+    0x1.fffff7ffffffffffffffffffffffffffp-127,
+    0x1.fffff8p-127
+  },
+  { // Entry 1082
+    -0x1.fffff7ffffffffffffffffffffffffffp-127,
+    -0x1.fffff8p-127
+  },
+  { // Entry 1083
+    0x1.ffffffffffffffffffffffffffffffffp-149,
+    0x1.p-148
+  },
+  { // Entry 1084
+    -0x1.ffffffffffffffffffffffffffffffffp-149,
+    -0x1.p-148
+  },
+  { // Entry 1085
+    0.0f,
+    0x1.p-149
+  },
+  { // Entry 1086
+    -0.0f,
+    -0x1.p-149
+  },
+  { // Entry 1087
+    0.0,
+    0.0f
+  },
+  { // Entry 1088
+    -0.0,
+    -0.0f
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_sinf, sinf_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_sinf_intel_data)/sizeof(sinf_intel_data_t); i++) {
+    EXPECT_FLOAT_EQ(g_sinf_intel_data[i].expected, sinf(g_sinf_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_tan_test.cpp b/tests/math_tan_test.cpp
new file mode 100644
index 0000000..6862019
--- /dev/null
+++ b/tests/math_tan_test.cpp
@@ -0,0 +1,5203 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  double expected;
+  double call_data;
+} tan_intel_data_t;
+
+static tan_intel_data_t g_tan_intel_data[] = {
+  { // Entry 0
+    0x1.5078cebff9c728000000000000024df8p-5,
+    0x1.50486b2f87014p-5
+  },
+  { // Entry 1
+    -0x1.5078cebff9c728000000000000024df8p-5,
+    -0x1.50486b2f87014p-5
+  },
+  { // Entry 2
+    0x1.5389e6df41978fffffffffffffc61f54p-4,
+    0x1.52c39ef070cadp-4
+  },
+  { // Entry 3
+    -0x1.5389e6df41978fffffffffffffc61f54p-4,
+    -0x1.52c39ef070cadp-4
+  },
+  { // Entry 4
+    0x1.a933fe176b37500000000000000a4065p-3,
+    0x1.a33f32ac5ceb5p-3
+  },
+  { // Entry 5
+    -0x1.a933fe176b37500000000000000a4065p-3,
+    -0x1.a33f32ac5ceb5p-3
+  },
+  { // Entry 6
+    0x1.fac71cd34eea680000000000009a0c10p-2,
+    0x1.d696bfa988db9p-2
+  },
+  { // Entry 7
+    -0x1.fac71cd34eea680000000000009a0c10p-2,
+    -0x1.d696bfa988db9p-2
+  },
+  { // Entry 8
+    0x1.7ba49f739829efffffffffffffe7e9bep-1,
+    0x1.46ac372243536p-1
+  },
+  { // Entry 9
+    -0x1.7ba49f739829efffffffffffffe7e9bep-1,
+    -0x1.46ac372243536p-1
+  },
+  { // Entry 10
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 11
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 12
+    -0x1.8f048832144b70021ccd7a5246cb0b20p0,
+    -0x1.00180p0
+  },
+  { // Entry 13
+    0x1.8f048832144b70021ccd7a5246cb0b20p0,
+    0x1.00180p0
+  },
+  { // Entry 14
+    -0x1.8e884b24313ae802db47899fad15a6c6p0,
+    -0x1.090cca18a5565p2
+  },
+  { // Entry 15
+    0x1.8e884b24313ae802db47899fad15a6c6p0,
+    0x1.090cca18a5565p2
+  },
+  { // Entry 16
+    -0x1.ca18654b356972967a4f1e8404b9f972p0,
+    -0x1.0faa7650df144p0
+  },
+  { // Entry 17
+    0x1.ca18654b356972967a4f1e8404b9f972p0,
+    0x1.0faa7650df144p0
+  },
+  { // Entry 18
+    -0x1.e52fafa22ef1481d437e7ed32cba03b1p-2,
+    -0x1.1800000000040p5
+  },
+  { // Entry 19
+    0x1.e52fafa22ef1481d437e7ed32cba03b1p-2,
+    0x1.1800000000040p5
+  },
+  { // Entry 20
+    -0x1.a3ca421dc30f1c5760a1ae07396fec33p-3,
+    -0x1.4000527aca388p99
+  },
+  { // Entry 21
+    0x1.a3ca421dc30f1c5760a1ae07396fec33p-3,
+    0x1.4000527aca388p99
+  },
+  { // Entry 22
+    0x1.1f3b7d1978609800a1628e1df9558df6p1,
+    -0x1.486c3634751ecp2
+  },
+  { // Entry 23
+    -0x1.1f3b7d1978609800a1628e1df9558df6p1,
+    0x1.486c3634751ecp2
+  },
+  { // Entry 24
+    -0x1.7eb873343fa7ab5d9ef9a78afd33d501p-1,
+    -0x1.48a71800b5713p-1
+  },
+  { // Entry 25
+    0x1.7eb873343fa7ab5d9ef9a78afd33d501p-1,
+    0x1.48a71800b5713p-1
+  },
+  { // Entry 26
+    0x1.be071572f64e88047c3939ba46626a25p-1,
+    -0x1.49af0314eea3cp299
+  },
+  { // Entry 27
+    -0x1.be071572f64e88047c3939ba46626a25p-1,
+    0x1.49af0314eea3cp299
+  },
+  { // Entry 28
+    0x1.ffbb2647f57a181bd1296faf33c04e3ep-1,
+    -0x1.5fe00c814ffd6p2
+  },
+  { // Entry 29
+    -0x1.ffbb2647f57a181bd1296faf33c04e3ep-1,
+    0x1.5fe00c814ffd6p2
+  },
+  { // Entry 30
+    -0x1.a8eb142b2f42756e6dedff09267a62c6p-1,
+    -0x1.62ac241f79439p-1
+  },
+  { // Entry 31
+    0x1.a8eb142b2f42756e6dedff09267a62c6p-1,
+    0x1.62ac241f79439p-1
+  },
+  { // Entry 32
+    -0x1.7d1d3559ddac885ee30632c760998c8ep-4,
+    -0x1.7c051b476ca8dp-4
+  },
+  { // Entry 33
+    0x1.7d1d3559ddac885ee30632c760998c8ep-4,
+    0x1.7c051b476ca8dp-4
+  },
+  { // Entry 34
+    -0x1.0e1d0305b7b727ff193d9d0b8eaff181p2,
+    -0x1.7e43c880074c6p996
+  },
+  { // Entry 35
+    0x1.0e1d0305b7b727ff193d9d0b8eaff181p2,
+    0x1.7e43c880074c6p996
+  },
+  { // Entry 36
+    -0x1.812bdfe0246bbf2a7ab6477a5cbb352bp-4,
+    -0x1.800ac363398c4p-4
+  },
+  { // Entry 37
+    0x1.812bdfe0246bbf2a7ab6477a5cbb352bp-4,
+    0x1.800ac363398c4p-4
+  },
+  { // Entry 38
+    -0x1.850e5544b0c797b36034c98e16f3fafbp-4,
+    -0x1.83e46aedbff36p-4
+  },
+  { // Entry 39
+    0x1.850e5544b0c797b36034c98e16f3fafbp-4,
+    0x1.83e46aedbff36p-4
+  },
+  { // Entry 40
+    0x1.e6b5d91bba9337fc0ceb686c60cd29bdp-2,
+    -0x1.83ecf42e9265ap3
+  },
+  { // Entry 41
+    -0x1.e6b5d91bba9337fc0ceb686c60cd29bdp-2,
+    0x1.83ecf42e9265ap3
+  },
+  { // Entry 42
+    -0x1.f3688bc2594e20102573cff48190ac28p-1,
+    -0x1.8bcp-1
+  },
+  { // Entry 43
+    0x1.f3688bc2594e20102573cff48190ac28p-1,
+    0x1.8bcp-1
+  },
+  { // Entry 44
+    0x1.ec0d0facdd08b773a1d93484e2d66c45p-2,
+    -0x1.8d2ffffffffd1p9
+  },
+  { // Entry 45
+    -0x1.ec0d0facdd08b773a1d93484e2d66c45p-2,
+    0x1.8d2ffffffffd1p9
+  },
+  { // Entry 46
+    0x1.ec0336d5392597689b640bf049227338p-2,
+    -0x1.8d3000fffffd1p9
+  },
+  { // Entry 47
+    -0x1.ec0336d5392597689b640bf049227338p-2,
+    0x1.8d3000fffffd1p9
+  },
+  { // Entry 48
+    -0x1.f8093a017021f81c01c131475e50e49bp-1,
+    -0x1.baeee6f6fa538p6
+  },
+  { // Entry 49
+    0x1.f8093a017021f81c01c131475e50e49bp-1,
+    0x1.baeee6f6fa538p6
+  },
+  { // Entry 50
+    0x1.deaf34994b7e77fd52a408f0c677eae1p3,
+    -0x1.c6867e07455eap3
+  },
+  { // Entry 51
+    -0x1.deaf34994b7e77fd52a408f0c677eae1p3,
+    0x1.c6867e07455eap3
+  },
+  { // Entry 52
+    -0x1.f29aa87d4e1dd81b7b69abe9790ee0abp-1,
+    -0x1.d27ffffffe0p7
+  },
+  { // Entry 53
+    0x1.f29aa87d4e1dd81b7b69abe9790ee0abp-1,
+    0x1.d27ffffffe0p7
+  },
+  { // Entry 54
+    0x1.762fb47a192597ffffffeeedb26fb978p-3,
+    -0x1.f0df38029c9efp3
+  },
+  { // Entry 55
+    -0x1.762fb47a192597ffffffeeedb26fb978p-3,
+    0x1.f0df38029c9efp3
+  },
+  { // Entry 56
+    -0x1.8eb23ef2126bb7fffd153c7ff90e9f6cp0,
+    -0x1.fffffc0000fffp-1
+  },
+  { // Entry 57
+    0x1.8eb23ef2126bb7fffd153c7ff90e9f6cp0,
+    0x1.fffffc0000fffp-1
+  },
+  { // Entry 58
+    -0x1.d299d285bf018423fbc14efc00ed5799p-2,
+    -0x1.ffffffffffffcp1023
+  },
+  { // Entry 59
+    0x1.d299d285bf018423fbc14efc00ed5799p-2,
+    0x1.ffffffffffffcp1023
+  },
+  { // Entry 60
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 61
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 62
+    -0x1.82bee572e2ac8c76d6909c66b282e962p-6,
+    0x1.0p64
+  },
+  { // Entry 63
+    0x1.82bee572e2ac8c76d6909c66b282e962p-6,
+    -0x1.0p64
+  },
+  { // Entry 64
+    0x1.f53a8d05afcf6c4bf2e1e5208b34d5c6p4,
+    0x1.0000000000001p51
+  },
+  { // Entry 65
+    -0x1.f53a8d05afcf6c4bf2e1e5208b34d5c6p4,
+    -0x1.0000000000001p51
+  },
+  { // Entry 66
+    -0x1.6b371df5980cd3db36768e36046a4a81p-1,
+    0x1.0000000000001p1017
+  },
+  { // Entry 67
+    0x1.6b371df5980cd3db36768e36046a4a81p-1,
+    -0x1.0000000000001p1017
+  },
+  { // Entry 68
+    -0x1.b32e78f49a0c83c7f60a3dc3ef8ecf1fp2,
+    0x1.0000000000003p3
+  },
+  { // Entry 69
+    0x1.b32e78f49a0c83c7f60a3dc3ef8ecf1fp2,
+    -0x1.0000000000003p3
+  },
+  { // Entry 70
+    0x1.98afbd24264bc3a9d1838074a3daa5e5p-1,
+    0x1.0000000000003p21
+  },
+  { // Entry 71
+    -0x1.98afbd24264bc3a9d1838074a3daa5e5p-1,
+    -0x1.0000000000003p21
+  },
+  { // Entry 72
+    0x1.b667a2abe36c280315c62a1f974e7611p0,
+    0x1.0000000000003p511
+  },
+  { // Entry 73
+    -0x1.b667a2abe36c280315c62a1f974e7611p0,
+    -0x1.0000000000003p511
+  },
+  { // Entry 74
+    0x1.204c26a427861ffefb73796bcf1fd724p-2,
+    0x1.0000000000003p716
+  },
+  { // Entry 75
+    -0x1.204c26a427861ffefb73796bcf1fd724p-2,
+    -0x1.0000000000003p716
+  },
+  { // Entry 76
+    0x1.91c8f2938262ce2e9ad99ab17e46abd6p4,
+    0x1.0000000000007p8
+  },
+  { // Entry 77
+    -0x1.91c8f2938262ce2e9ad99ab17e46abd6p4,
+    -0x1.0000000000007p8
+  },
+  { // Entry 78
+    -0x1.27f7f0880031fe42ed1d5fedc496d14ep-2,
+    0x1.0000000000038p380
+  },
+  { // Entry 79
+    0x1.27f7f0880031fe42ed1d5fedc496d14ep-2,
+    -0x1.0000000000038p380
+  },
+  { // Entry 80
+    -0x1.d6890cc32711d4b046903ad8851a41bbp-3,
+    0x1.0000000000118p380
+  },
+  { // Entry 81
+    0x1.d6890cc32711d4b046903ad8851a41bbp-3,
+    -0x1.0000000000118p380
+  },
+  { // Entry 82
+    0x1.9af0e6f72f9127ffffc0200ea7f406f4p-3,
+    0x1.0000000000908p500
+  },
+  { // Entry 83
+    -0x1.9af0e6f72f9127ffffc0200ea7f406f4p-3,
+    -0x1.0000000000908p500
+  },
+  { // Entry 84
+    0x1.17b4f5bf440978002d66f1bd37032532p-1,
+    0x1.000000000c0p-1
+  },
+  { // Entry 85
+    -0x1.17b4f5bf440978002d66f1bd37032532p-1,
+    -0x1.000000000c0p-1
+  },
+  { // Entry 86
+    -0x1.17eb22e4dba72800d2a000698263d582p0,
+    0x1.00000001cp40
+  },
+  { // Entry 87
+    0x1.17eb22e4dba72800d2a000698263d582p0,
+    -0x1.00000001cp40
+  },
+  { // Entry 88
+    0x1.f6f03ce5690a6e3880b95fd8b2c8363ep-1,
+    0x1.0000001p250
+  },
+  { // Entry 89
+    -0x1.f6f03ce5690a6e3880b95fd8b2c8363ep-1,
+    -0x1.0000001p250
+  },
+  { // Entry 90
+    0x1.e23b78282a75d0dd6da35692d142bc63p-1,
+    0x1.000000988p27
+  },
+  { // Entry 91
+    -0x1.e23b78282a75d0dd6da35692d142bc63p-1,
+    -0x1.000000988p27
+  },
+  { // Entry 92
+    -0x1.981b657e1ca27009d82d8e18314240b5p-3,
+    0x1.00000c0p429
+  },
+  { // Entry 93
+    0x1.981b657e1ca27009d82d8e18314240b5p-3,
+    -0x1.00000c0p429
+  },
+  { // Entry 94
+    -0x1.455a2184f4c3dffb0986919cece683a4p-1,
+    0x1.00000fcp1000
+  },
+  { // Entry 95
+    0x1.455a2184f4c3dffb0986919cece683a4p-1,
+    -0x1.00000fcp1000
+  },
+  { // Entry 96
+    0x1.8ee66962f210c800000568c7daad3a28p0,
+    0x1.000f371b7a006p0
+  },
+  { // Entry 97
+    -0x1.8ee66962f210c800000568c7daad3a28p0,
+    -0x1.000f371b7a006p0
+  },
+  { // Entry 98
+    -0x1.ecd75cf6d4663bee1c96f03184fae086p-3,
+    0x1.001p15
+  },
+  { // Entry 99
+    0x1.ecd75cf6d4663bee1c96f03184fae086p-3,
+    -0x1.001p15
+  },
+  { // Entry 100
+    0x1.17d42033277cc8244ccb6e5154482105p-1,
+    0x1.0017ffffffffdp-1
+  },
+  { // Entry 101
+    -0x1.17d42033277cc8244ccb6e5154482105p-1,
+    -0x1.0017ffffffffdp-1
+  },
+  { // Entry 102
+    0x1.8f048832144b70021ccd7a5246cb0b20p0,
+    0x1.00180p0
+  },
+  { // Entry 103
+    -0x1.8f048832144b70021ccd7a5246cb0b20p0,
+    -0x1.00180p0
+  },
+  { // Entry 104
+    -0x1.18273cc3e763900743704028cfb114a5p-2,
+    0x1.001fffep500
+  },
+  { // Entry 105
+    0x1.18273cc3e763900743704028cfb114a5p-2,
+    -0x1.001fffep500
+  },
+  { // Entry 106
+    -0x1.d8f90cad30546ce5b8268b330ce50a6fp-2,
+    0x1.018p40
+  },
+  { // Entry 107
+    0x1.d8f90cad30546ce5b8268b330ce50a6fp-2,
+    -0x1.018p40
+  },
+  { // Entry 108
+    0x1.b079ea0d14a4a7ffc04bd6fbf451bb34p-2,
+    0x1.01b8a484ac0b6p4
+  },
+  { // Entry 109
+    -0x1.b079ea0d14a4a7ffc04bd6fbf451bb34p-2,
+    -0x1.01b8a484ac0b6p4
+  },
+  { // Entry 110
+    -0x1.a40c262f6ab997fef43bf54af3c5a765p-1,
+    0x1.026ac0ef32d40p28
+  },
+  { // Entry 111
+    0x1.a40c262f6ab997fef43bf54af3c5a765p-1,
+    -0x1.026ac0ef32d40p28
+  },
+  { // Entry 112
+    0x1.03b8c1f3296657c651a13eb5b100fc78p-4,
+    0x1.035fdcd08a596p-4
+  },
+  { // Entry 113
+    -0x1.03b8c1f3296657c651a13eb5b100fc78p-4,
+    -0x1.035fdcd08a596p-4
+  },
+  { // Entry 114
+    0x1.044979d134ed97c78bfe58a9003bfac5p-4,
+    0x1.03fp-4
+  },
+  { // Entry 115
+    -0x1.044979d134ed97c78bfe58a9003bfac5p-4,
+    -0x1.03fp-4
+  },
+  { // Entry 116
+    -0x1.e717de7da2ce831066bad1df5e88a030p0,
+    0x1.070p1
+  },
+  { // Entry 117
+    0x1.e717de7da2ce831066bad1df5e88a030p0,
+    -0x1.070p1
+  },
+  { // Entry 118
+    -0x1.8c896f607ff52bbae86f63e19a988d2bp-1,
+    0x1.070p30
+  },
+  { // Entry 119
+    0x1.8c896f607ff52bbae86f63e19a988d2bp-1,
+    -0x1.070p30
+  },
+  { // Entry 120
+    0x1.fffffffff5d846af6f017262c9c81de4p-1,
+    0x1.07e4cef4cbb0ep4
+  },
+  { // Entry 121
+    -0x1.fffffffff5d846af6f017262c9c81de4p-1,
+    -0x1.07e4cef4cbb0ep4
+  },
+  { // Entry 122
+    0x1.b476d32c1b7457ffff66edb3f78a7003p0,
+    0x1.0a53a78b13ab2p0
+  },
+  { // Entry 123
+    -0x1.b476d32c1b7457ffff66edb3f78a7003p0,
+    -0x1.0a53a78b13ab2p0
+  },
+  { // Entry 124
+    0x1.f2df7c02d20cd81b33117c00545f7a6bp-1,
+    0x1.0afbc268b9848p6
+  },
+  { // Entry 125
+    -0x1.f2df7c02d20cd81b33117c00545f7a6bp-1,
+    -0x1.0afbc268b9848p6
+  },
+  { // Entry 126
+    -0x1.b571af562f08a5a03dd8493990b29db1p0,
+    0x1.0cd5d435bea6dp1
+  },
+  { // Entry 127
+    0x1.b571af562f08a5a03dd8493990b29db1p0,
+    -0x1.0cd5d435bea6dp1
+  },
+  { // Entry 128
+    -0x1.ac73d2920a7955336ab2a3436c77c276p0,
+    0x1.0e0p1
+  },
+  { // Entry 129
+    0x1.ac73d2920a7955336ab2a3436c77c276p0,
+    -0x1.0e0p1
+  },
+  { // Entry 130
+    -0x1.126dce8ac7c818000cfcf3df066a4a2dp-1,
+    0x1.1086210842108p5
+  },
+  { // Entry 131
+    0x1.126dce8ac7c818000cfcf3df066a4a2dp-1,
+    -0x1.1086210842108p5
+  },
+  { // Entry 132
+    -0x1.9680c02601046ca506c0e3f744db1d0ap0,
+    0x1.110p1
+  },
+  { // Entry 133
+    0x1.9680c02601046ca506c0e3f744db1d0ap0,
+    -0x1.110p1
+  },
+  { // Entry 134
+    0x1.d1e716934469b2bc02fa835ae0149f58p0,
+    0x1.118p0
+  },
+  { // Entry 135
+    -0x1.d1e716934469b2bc02fa835ae0149f58p0,
+    -0x1.118p0
+  },
+  { // Entry 136
+    -0x1.6aa73101430837fffffebaafd45f7efap-1,
+    0x1.19df389f39e0ap3
+  },
+  { // Entry 137
+    0x1.6aa73101430837fffffebaafd45f7efap-1,
+    -0x1.19df389f39e0ap3
+  },
+  { // Entry 138
+    0x1.cb9a99227bdc972cd4145969c3dc38c1p1,
+    0x1.1c3598211013ap2
+  },
+  { // Entry 139
+    -0x1.cb9a99227bdc972cd4145969c3dc38c1p1,
+    -0x1.1c3598211013ap2
+  },
+  { // Entry 140
+    -0x1.bc109c3e6172450a5308b4c6eb2898cap7,
+    0x1.1d65aa4224c30p118
+  },
+  { // Entry 141
+    0x1.bc109c3e6172450a5308b4c6eb2898cap7,
+    -0x1.1d65aa4224c30p118
+  },
+  { // Entry 142
+    -0x1.09b393f48b2c67ffff3bd559c6326e60p-1,
+    0x1.1e4658272dc6fp3
+  },
+  { // Entry 143
+    0x1.09b393f48b2c67ffff3bd559c6326e60p-1,
+    -0x1.1e4658272dc6fp3
+  },
+  { // Entry 144
+    0x1.20000000000798000000003d82666666p-22,
+    0x1.2p-22
+  },
+  { // Entry 145
+    -0x1.20000000000798000000003d82666666p-22,
+    -0x1.2p-22
+  },
+  { // Entry 146
+    -0x1.02a335b00707a7ffffbe455adab7e814p0,
+    0x1.2127409620cacp95
+  },
+  { // Entry 147
+    0x1.02a335b00707a7ffffbe455adab7e814p0,
+    -0x1.2127409620cacp95
+  },
+  { // Entry 148
+    0x1.2508b9c1273ac034c3c79c4088e2acfdp-4,
+    0x1.2489224892248p-4
+  },
+  { // Entry 149
+    -0x1.2508b9c1273ac034c3c79c4088e2acfdp-4,
+    -0x1.2489224892248p-4
+  },
+  { // Entry 150
+    0x1.fded5f53d132d26a8244a63f9bcdf153p2,
+    0x1.2a52d119da061p237
+  },
+  { // Entry 151
+    -0x1.fded5f53d132d26a8244a63f9bcdf153p2,
+    -0x1.2a52d119da061p237
+  },
+  { // Entry 152
+    0x1.2de56a6ef9c5d7e9c71030407530f1d7p-4,
+    0x1.2d59ebab8dae4p-4
+  },
+  { // Entry 153
+    -0x1.2de56a6ef9c5d7e9c71030407530f1d7p-4,
+    -0x1.2d59ebab8dae4p-4
+  },
+  { // Entry 154
+    0x1.31665eb191fba800b7e715fd11716c8cp-4,
+    0x1.30d5f8e54b6d8p-4
+  },
+  { // Entry 155
+    -0x1.31665eb191fba800b7e715fd11716c8cp-4,
+    -0x1.30d5f8e54b6d8p-4
+  },
+  { // Entry 156
+    0x1.3cc1d4d28bfd17fded9ae50407590f3fp-2,
+    0x1.333275d63ec50p-2
+  },
+  { // Entry 157
+    -0x1.3cc1d4d28bfd17fded9ae50407590f3fp-2,
+    -0x1.333275d63ec50p-2
+  },
+  { // Entry 158
+    0x1.3cc237c0c7dcbfff1046ad9a068af510p-2,
+    0x1.3332d020b6da9p-2
+  },
+  { // Entry 159
+    -0x1.3cc237c0c7dcbfff1046ad9a068af510p-2,
+    -0x1.3332d020b6da9p-2
+  },
+  { // Entry 160
+    0x1.5e472e16999df00000fc06ee474fbfc9p-1,
+    0x1.333333401e66bp-1
+  },
+  { // Entry 161
+    -0x1.5e472e16999df00000fc06ee474fbfc9p-1,
+    -0x1.333333401e66bp-1
+  },
+  { // Entry 162
+    0x1.b5ed1c2080a987fc84f26ec958b2ac47p-1,
+    0x1.38f137cb9dbfcp9
+  },
+  { // Entry 163
+    -0x1.b5ed1c2080a987fc84f26ec958b2ac47p-1,
+    -0x1.38f137cb9dbfcp9
+  },
+  { // Entry 164
+    0x1.01aa22e2133d37fffff2a0c08093358ep1,
+    0x1.39a383f3fa003p85
+  },
+  { // Entry 165
+    -0x1.01aa22e2133d37fffff2a0c08093358ep1,
+    -0x1.39a383f3fa003p85
+  },
+  { // Entry 166
+    0x1.ffffffffff58236322819d060eb67c3cp-1,
+    0x1.3a28c59d54311p4
+  },
+  { // Entry 167
+    -0x1.ffffffffff58236322819d060eb67c3cp-1,
+    -0x1.3a28c59d54311p4
+  },
+  { // Entry 168
+    0x1.7166689d4803e83d2b6b1d15f5aca26ep-1,
+    0x1.4000000003fffp-1
+  },
+  { // Entry 169
+    -0x1.7166689d4803e83d2b6b1d15f5aca26ep-1,
+    -0x1.4000000003fffp-1
+  },
+  { // Entry 170
+    -0x1.ff7d27b37eba0819199e533cc5016f0dp-1,
+    0x1.40724a44714cfp5
+  },
+  { // Entry 171
+    0x1.ff7d27b37eba0819199e533cc5016f0dp-1,
+    -0x1.40724a44714cfp5
+  },
+  { // Entry 172
+    0x1.453a7d29dadad7c0dda78a7398be0873p-4,
+    0x1.448c2d6e1e1afp-4
+  },
+  { // Entry 173
+    -0x1.453a7d29dadad7c0dda78a7398be0873p-4,
+    -0x1.448c2d6e1e1afp-4
+  },
+  { // Entry 174
+    -0x1.a50f7601413e53ab1c5a2f0d676c397cp0,
+    0x1.478fc08p43
+  },
+  { // Entry 175
+    0x1.a50f7601413e53ab1c5a2f0d676c397cp0,
+    -0x1.478fc08p43
+  },
+  { // Entry 176
+    -0x1.a9991acb7636beee5b1a5d35a8a89917p-4,
+    0x1.4e93bee72b565p62
+  },
+  { // Entry 177
+    0x1.a9991acb7636beee5b1a5d35a8a89917p-4,
+    -0x1.4e93bee72b565p62
+  },
+  { // Entry 178
+    0x1.2952396945947b726ebf025a8ba07093p1,
+    0x1.4f0f308p488
+  },
+  { // Entry 179
+    -0x1.2952396945947b726ebf025a8ba07093p1,
+    -0x1.4f0f308p488
+  },
+  { // Entry 180
+    0x1.5078cebff9c728000000000000024df8p-5,
+    0x1.50486b2f87014p-5
+  },
+  { // Entry 181
+    -0x1.5078cebff9c728000000000000024df8p-5,
+    -0x1.50486b2f87014p-5
+  },
+  { // Entry 182
+    -0x1.1c929b6ede9ee8000040a3d1ca90a9f4p-1,
+    0x1.5130d552f1036p1
+  },
+  { // Entry 183
+    0x1.1c929b6ede9ee8000040a3d1ca90a9f4p-1,
+    -0x1.5130d552f1036p1
+  },
+  { // Entry 184
+    0x1.2ab3189e2d4ae41c1aff3cc30cfedd30p1,
+    0x1.52f00e0p793
+  },
+  { // Entry 185
+    -0x1.2ab3189e2d4ae41c1aff3cc30cfedd30p1,
+    -0x1.52f00e0p793
+  },
+  { // Entry 186
+    -0x1.7d2e63fb988907a109091d130f9f20d1p0,
+    0x1.5371684e5fb34p2
+  },
+  { // Entry 187
+    0x1.7d2e63fb988907a109091d130f9f20d1p0,
+    -0x1.5371684e5fb34p2
+  },
+  { // Entry 188
+    -0x1.f9f4f0da4de54499283a8ac2f55f7258p-1,
+    0x1.54ef2208956p239
+  },
+  { // Entry 189
+    0x1.f9f4f0da4de54499283a8ac2f55f7258p-1,
+    -0x1.54ef2208956p239
+  },
+  { // Entry 190
+    0x1.1483073142e608008f8849daf5f8c58dp2,
+    0x1.57e590af09014p0
+  },
+  { // Entry 191
+    -0x1.1483073142e608008f8849daf5f8c58dp2,
+    -0x1.57e590af09014p0
+  },
+  { // Entry 192
+    0x1.9972d4021c971563936055d8c1eaae0ap-1,
+    0x1.596p-1
+  },
+  { // Entry 193
+    -0x1.9972d4021c971563936055d8c1eaae0ap-1,
+    -0x1.596p-1
+  },
+  { // Entry 194
+    -0x1.e501ffd3a68c38336d977f634326a342p-2,
+    0x1.5981293783e1fp1
+  },
+  { // Entry 195
+    0x1.e501ffd3a68c38336d977f634326a342p-2,
+    -0x1.5981293783e1fp1
+  },
+  { // Entry 196
+    0x1.1604cc3dfc4181c3e9481558467a85fep-1,
+    0x1.5bea010p468
+  },
+  { // Entry 197
+    -0x1.1604cc3dfc4181c3e9481558467a85fep-1,
+    -0x1.5bea010p468
+  },
+  { // Entry 198
+    -0x1.f76ca50bbbaeb012beade2a328e5fc03p-1,
+    0x1.60661c1969666p2
+  },
+  { // Entry 199
+    0x1.f76ca50bbbaeb012beade2a328e5fc03p-1,
+    -0x1.60661c1969666p2
+  },
+  { // Entry 200
+    0x1.cd8b73c9430fef75dc710ffdfe091b42p0,
+    0x1.62c5a850a142ap59
+  },
+  { // Entry 201
+    -0x1.cd8b73c9430fef75dc710ffdfe091b42p0,
+    -0x1.62c5a850a142ap59
+  },
+  { // Entry 202
+    0x1.3accfd453ee67296088378f582eacb02p0,
+    0x1.64ef438p142
+  },
+  { // Entry 203
+    -0x1.3accfd453ee67296088378f582eacb02p0,
+    -0x1.64ef438p142
+  },
+  { // Entry 204
+    -0x1.acd9302d72de4bd8dda8f5650b77e732p-1,
+    0x1.658p2
+  },
+  { // Entry 205
+    0x1.acd9302d72de4bd8dda8f5650b77e732p-1,
+    -0x1.658p2
+  },
+  { // Entry 206
+    0x1.f004f875c2e738159c7d75a3980cafd7p-1,
+    0x1.6603c65d348d2p5
+  },
+  { // Entry 207
+    -0x1.f004f875c2e738159c7d75a3980cafd7p-1,
+    -0x1.6603c65d348d2p5
+  },
+  { // Entry 208
+    0x1.f53496e6d7f7181a62fec4c8a710900ep-1,
+    0x1.660e6bf2e092ap5
+  },
+  { // Entry 209
+    -0x1.f53496e6d7f7181a62fec4c8a710900ep-1,
+    -0x1.660e6bf2e092ap5
+  },
+  { // Entry 210
+    0x1.b64ee24f0119c800d5d0bb10a39aca4ep-1,
+    0x1.6a8p-1
+  },
+  { // Entry 211
+    -0x1.b64ee24f0119c800d5d0bb10a39aca4ep-1,
+    -0x1.6a8p-1
+  },
+  { // Entry 212
+    -0x1.d9ba9a7975635a3acc324e6aeda45133p60,
+    0x1.6ac5b262ca1ffp849
+  },
+  { // Entry 213
+    0x1.d9ba9a7975635a3acc324e6aeda45133p60,
+    -0x1.6ac5b262ca1ffp849
+  },
+  { // Entry 214
+    0x1.b6f557b999e22e0db10a92b908e877f6p-1,
+    0x1.6aep-1
+  },
+  { // Entry 215
+    -0x1.b6f557b999e22e0db10a92b908e877f6p-1,
+    -0x1.6aep-1
+  },
+  { // Entry 216
+    0x1.c1e1d5c4c0f077fc871d4bd0a03c6431p-1,
+    0x1.6cdb36cdb36c9p239
+  },
+  { // Entry 217
+    -0x1.c1e1d5c4c0f077fc871d4bd0a03c6431p-1,
+    -0x1.6cdb36cdb36c9p239
+  },
+  { // Entry 218
+    0x1.95bce4f5786978078c310210dced6f3fp-1,
+    0x1.6f1af1612270ap6
+  },
+  { // Entry 219
+    -0x1.95bce4f5786978078c310210dced6f3fp-1,
+    -0x1.6f1af1612270ap6
+  },
+  { // Entry 220
+    0x1.711e8f5fffba1f599595fbaac5b70e0bp-4,
+    0x1.702p-4
+  },
+  { // Entry 221
+    -0x1.711e8f5fffba1f599595fbaac5b70e0bp-4,
+    -0x1.702p-4
+  },
+  { // Entry 222
+    0x1.fb5898f29bb257fda6f2bedfc491abaep2,
+    0x1.720p0
+  },
+  { // Entry 223
+    -0x1.fb5898f29bb257fda6f2bedfc491abaep2,
+    -0x1.720p0
+  },
+  { // Entry 224
+    -0x1.ff9b771284d23290cdd83717cc905773p1,
+    0x1.7348c347ddc20p239
+  },
+  { // Entry 225
+    0x1.ff9b771284d23290cdd83717cc905773p1,
+    -0x1.7348c347ddc20p239
+  },
+  { // Entry 226
+    0x1.f72d47a0080e2d3d040863d56dbb567ep-2,
+    0x1.739ce739ce738p100
+  },
+  { // Entry 227
+    -0x1.f72d47a0080e2d3d040863d56dbb567ep-2,
+    -0x1.739ce739ce738p100
+  },
+  { // Entry 228
+    0x1.76441e7f8ea5f8000001d1c5c84f104ep-4,
+    0x1.753acc3d3ff35p-4
+  },
+  { // Entry 229
+    -0x1.76441e7f8ea5f8000001d1c5c84f104ep-4,
+    -0x1.753acc3d3ff35p-4
+  },
+  { // Entry 230
+    0x1.ce3f642e15af3c921dd7129db5e39342p-1,
+    0x1.77fffffffffffp-1
+  },
+  { // Entry 231
+    -0x1.ce3f642e15af3c921dd7129db5e39342p-1,
+    -0x1.77fffffffffffp-1
+  },
+  { // Entry 232
+    0x1.f425002a548eb405450970a353d307f7p42,
+    0x1.78fdb9effea26p4
+  },
+  { // Entry 233
+    -0x1.f425002a548eb405450970a353d307f7p42,
+    -0x1.78fdb9effea26p4
+  },
+  { // Entry 234
+    -0x1.dbc80de7dd042a9371e1b45718e51babp-1,
+    0x1.7a5f74607e851p19
+  },
+  { // Entry 235
+    0x1.dbc80de7dd042a9371e1b45718e51babp-1,
+    -0x1.7a5f74607e851p19
+  },
+  { // Entry 236
+    0x1.7b3bb3d0b3ca42f13207842899e0ba71p42,
+    0x1.7f7ef77e83f1ap19
+  },
+  { // Entry 237
+    -0x1.7b3bb3d0b3ca42f13207842899e0ba71p42,
+    -0x1.7f7ef77e83f1ap19
+  },
+  { // Entry 238
+    0x1.e7f05b71cd2d0fb4df6a43375cd8f670p33,
+    0x1.7f7f10a07f45ep20
+  },
+  { // Entry 239
+    -0x1.e7f05b71cd2d0fb4df6a43375cd8f670p33,
+    -0x1.7f7f10a07f45ep20
+  },
+  { // Entry 240
+    0x1.80000000000038000000000007333333p-25,
+    0x1.7ffffffffffffp-25
+  },
+  { // Entry 241
+    -0x1.80000000000038000000000007333333p-25,
+    -0x1.7ffffffffffffp-25
+  },
+  { // Entry 242
+    0x1.80000000000068000000000022333333p-25,
+    0x1.8000000000002p-25
+  },
+  { // Entry 243
+    -0x1.80000000000068000000000022333333p-25,
+    -0x1.8000000000002p-25
+  },
+  { // Entry 244
+    0x1.24245af4cd994e9b3bba992d1016365bp-52,
+    0x1.81ae0dffa3b33p959
+  },
+  { // Entry 245
+    -0x1.24245af4cd994e9b3bba992d1016365bp-52,
+    -0x1.81ae0dffa3b33p959
+  },
+  { // Entry 246
+    0x1.d72261d98e26b7ffa300d89fd46fb775p-1,
+    0x1.846bd7a4dce55p698
+  },
+  { // Entry 247
+    -0x1.d72261d98e26b7ffa300d89fd46fb775p-1,
+    -0x1.846bd7a4dce55p698
+  },
+  { // Entry 248
+    0x1.42d8a1ba441ad4028ac7f1a6a5ee0c54p1,
+    0x1.8720588p392
+  },
+  { // Entry 249
+    -0x1.42d8a1ba441ad4028ac7f1a6a5ee0c54p1,
+    -0x1.8720588p392
+  },
+  { // Entry 250
+    0x1.ea7b444cd798d7faeeff093f1d9971adp-1,
+    0x1.8722a67ea14acp-1
+  },
+  { // Entry 251
+    -0x1.ea7b444cd798d7faeeff093f1d9971adp-1,
+    -0x1.8722a67ea14acp-1
+  },
+  { // Entry 252
+    -0x1.c7dc7f08dbba089f2d7e890021bedcb7p-1,
+    0x1.89936c8828d38p299
+  },
+  { // Entry 253
+    0x1.c7dc7f08dbba089f2d7e890021bedcb7p-1,
+    -0x1.89936c8828d38p299
+  },
+  { // Entry 254
+    0x1.569653e319bba800000c83632e43abdep1,
+    0x1.8a69106fb9798p6
+  },
+  { // Entry 255
+    -0x1.569653e319bba800000c83632e43abdep1,
+    -0x1.8a69106fb9798p6
+  },
+  { // Entry 256
+    0x1.f2db21469f3d5819fa9ba8dccbff914ap-1,
+    0x1.8b777e1d2308cp-1
+  },
+  { // Entry 257
+    -0x1.f2db21469f3d5819fa9ba8dccbff914ap-1,
+    -0x1.8b777e1d2308cp-1
+  },
+  { // Entry 258
+    0x1.f3688bc2594e20102573cff48190ac28p-1,
+    0x1.8bcp-1
+  },
+  { // Entry 259
+    -0x1.f3688bc2594e20102573cff48190ac28p-1,
+    -0x1.8bcp-1
+  },
+  { // Entry 260
+    0x1.8d3a2544566df7b559b4ac48e12eac71p-4,
+    0x1.8bfd2274d851ap-4
+  },
+  { // Entry 261
+    -0x1.8d3a2544566df7b559b4ac48e12eac71p-4,
+    -0x1.8bfd2274d851ap-4
+  },
+  { // Entry 262
+    0x1.f4575cc4e477f019dab5d0103aaf91cfp-1,
+    0x1.8c3a450071dd9p-1
+  },
+  { // Entry 263
+    -0x1.f4575cc4e477f019dab5d0103aaf91cfp-1,
+    -0x1.8c3a450071dd9p-1
+  },
+  { // Entry 264
+    -0x1.1e09f66c4250b94e9030cadd00851158p11,
+    0x1.8cc0dd2b0f4b8p200
+  },
+  { // Entry 265
+    0x1.1e09f66c4250b94e9030cadd00851158p11,
+    -0x1.8cc0dd2b0f4b8p200
+  },
+  { // Entry 266
+    0x1.f71496cb921e5a4d2f39046a628b6509p-1,
+    0x1.8dap-1
+  },
+  { // Entry 267
+    -0x1.f71496cb921e5a4d2f39046a628b6509p-1,
+    -0x1.8dap-1
+  },
+  { // Entry 268
+    0x1.f71b4a6591169819476e6b759c7aae52p-1,
+    0x1.8da368da368d8p-1
+  },
+  { // Entry 269
+    -0x1.f71b4a6591169819476e6b759c7aae52p-1,
+    -0x1.8da368da368d8p-1
+  },
+  { // Entry 270
+    0x1.ff9b68ccadb2ff62c26864288ed6a4dfp-1,
+    0x1.91ed64b977a9ap-1
+  },
+  { // Entry 271
+    -0x1.ff9b68ccadb2ff62c26864288ed6a4dfp-1,
+    -0x1.91ed64b977a9ap-1
+  },
+  { // Entry 272
+    0x1.00000000290484779fa491c728aef945p18,
+    0x1.921f754442d19p0
+  },
+  { // Entry 273
+    -0x1.00000000290484779fa491c728aef945p18,
+    -0x1.921f754442d19p0
+  },
+  { // Entry 274
+    0x1.eef067afd328f311ce2c7a1f420a5983p48,
+    0x1.921fb54442d10p0
+  },
+  { // Entry 275
+    -0x1.eef067afd328f311ce2c7a1f420a5983p48,
+    -0x1.921fb54442d10p0
+  },
+  { // Entry 276
+    0x1.0000000003af2f223eb1e709cba00ec3p-17,
+    0x1.921ff54442d18p1
+  },
+  { // Entry 277
+    -0x1.0000000003af2f223eb1e709cba00ec3p-17,
+    -0x1.921ff54442d18p1
+  },
+  { // Entry 278
+    -0x1.b6772cb667dc187b7d019d1d7232c9e7p17,
+    0x1.922p0
+  },
+  { // Entry 279
+    0x1.b6772cb667dc187b7d019d1d7232c9e7p17,
+    -0x1.922p0
+  },
+  { // Entry 280
+    -0x1.fffffffceeefe791be2074779fd1dd9ep-1,
+    0x1.922071c31fc99p20
+  },
+  { // Entry 281
+    0x1.fffffffceeefe791be2074779fd1dd9ep-1,
+    -0x1.922071c31fc99p20
+  },
+  { // Entry 282
+    0x1.9d7c1354ba6f781c8b04408094f45284p-3,
+    0x1.97fffffffffffp-3
+  },
+  { // Entry 283
+    -0x1.9d7c1354ba6f781c8b04408094f45284p-3,
+    -0x1.97fffffffffffp-3
+  },
+  { // Entry 284
+    0x1.9af8877bb45e47ffffe961084b2c0beap-4,
+    0x1.999999a10a13cp-4
+  },
+  { // Entry 285
+    -0x1.9af8877bb45e47ffffe961084b2c0beap-4,
+    -0x1.999999a10a13cp-4
+  },
+  { // Entry 286
+    -0x1.b6ce128587cd07ffff757abda294c151p4,
+    0x1.9b74446ed05dcp0
+  },
+  { // Entry 287
+    0x1.b6ce128587cd07ffff757abda294c151p4,
+    -0x1.9b74446ed05dcp0
+  },
+  { // Entry 288
+    0x1.ff65aef54c8fc8042841071b45b6d7d9p-1,
+    0x1.9eae494d2b275p4
+  },
+  { // Entry 289
+    -0x1.ff65aef54c8fc8042841071b45b6d7d9p-1,
+    -0x1.9eae494d2b275p4
+  },
+  { // Entry 290
+    0x1.61776aa407a437f617fcadb15c7f61c2p-3,
+    0x1.a80p1
+  },
+  { // Entry 291
+    -0x1.61776aa407a437f617fcadb15c7f61c2p-3,
+    -0x1.a80p1
+  },
+  { // Entry 292
+    0x1.b6001de13ad9580073acba4aa423e2d9p-3,
+    0x1.af8p-3
+  },
+  { // Entry 293
+    -0x1.b6001de13ad9580073acba4aa423e2d9p-3,
+    -0x1.af8p-3
+  },
+  { // Entry 294
+    0x1.b5a0503ae354b7a16f7c50f8b3bef2cap-4,
+    0x1.b3f8ea7b1f91bp-4
+  },
+  { // Entry 295
+    -0x1.b5a0503ae354b7a16f7c50f8b3bef2cap-4,
+    -0x1.b3f8ea7b1f91bp-4
+  },
+  { // Entry 296
+    0x1.b5a0503ae4c7b792537327f4245ac6fbp-4,
+    0x1.b3f8ea7b21008p-4
+  },
+  { // Entry 297
+    -0x1.b5a0503ae4c7b792537327f4245ac6fbp-4,
+    -0x1.b3f8ea7b21008p-4
+  },
+  { // Entry 298
+    0x1.057584c429b3a6ea0a65caff98634490p59,
+    0x1.b951f1572eba5p23
+  },
+  { // Entry 299
+    -0x1.057584c429b3a6ea0a65caff98634490p59,
+    -0x1.b951f1572eba5p23
+  },
+  { // Entry 300
+    -0x1.9a282fa1ff7d98039be3bf5b39cc6d89p2,
+    0x1.b9cp0
+  },
+  { // Entry 301
+    0x1.9a282fa1ff7d98039be3bf5b39cc6d89p2,
+    -0x1.b9cp0
+  },
+  { // Entry 302
+    -0x1.027d184afb1984ca1d21b1ac93111887p-52,
+    0x1.bab62ed655019p970
+  },
+  { // Entry 303
+    0x1.027d184afb1984ca1d21b1ac93111887p-52,
+    -0x1.bab62ed655019p970
+  },
+  { // Entry 304
+    0x1.ca6efdf845d6c7fffebaea1afbf7e961p2,
+    0x1.bea1b35f3cb6dp84
+  },
+  { // Entry 305
+    -0x1.ca6efdf845d6c7fffebaea1afbf7e961p2,
+    -0x1.bea1b35f3cb6dp84
+  },
+  { // Entry 306
+    0x1.fd87b34747b746b8b657cac797c0870dp42,
+    0x1.c463abeccb27bp3
+  },
+  { // Entry 307
+    -0x1.fd87b34747b746b8b657cac797c0870dp42,
+    -0x1.c463abeccb27bp3
+  },
+  { // Entry 308
+    0x1.ffffffffffffb094541a2461e734daeep-1,
+    0x1.c463abeccb2bbp2
+  },
+  { // Entry 309
+    -0x1.ffffffffffffb094541a2461e734daeep-1,
+    -0x1.c463abeccb2bbp2
+  },
+  { // Entry 310
+    0x1.fb057029acfd17fffffa5ac8204f0803p-1,
+    0x1.c6cbe26b7b45fp86
+  },
+  { // Entry 311
+    -0x1.fb057029acfd17fffffa5ac8204f0803p-1,
+    -0x1.c6cbe26b7b45fp86
+  },
+  { // Entry 312
+    0x1.c8d5a08be40c20p-117,
+    0x1.c8d5a08be40c2p-117
+  },
+  { // Entry 313
+    -0x1.c8d5a08be40c20p-117,
+    -0x1.c8d5a08be40c2p-117
+  },
+  { // Entry 314
+    0x1.e5dffd7f06cb3754933cea578deaad36p-2,
+    0x1.cad4e9827a2bep1
+  },
+  { // Entry 315
+    -0x1.e5dffd7f06cb3754933cea578deaad36p-2,
+    -0x1.cad4e9827a2bep1
+  },
+  { // Entry 316
+    0x1.e6be378b1b4eb7658e85ad0af33836a9p-2,
+    0x1.caeb940e4b997p1
+  },
+  { // Entry 317
+    -0x1.e6be378b1b4eb7658e85ad0af33836a9p-2,
+    -0x1.caeb940e4b997p1
+  },
+  { // Entry 318
+    0x1.e72bd025a1fd5765f853469a85ae7b7dp-2,
+    0x1.caf6c04ecd034p1
+  },
+  { // Entry 319
+    -0x1.e72bd025a1fd5765f853469a85ae7b7dp-2,
+    -0x1.caf6c04ecd034p1
+  },
+  { // Entry 320
+    0x1.e844b3d7cbe4375c28e322da6ba5d7d8p-2,
+    0x1.cb135ec1c956ep1
+  },
+  { // Entry 321
+    -0x1.e844b3d7cbe4375c28e322da6ba5d7d8p-2,
+    -0x1.cb135ec1c956ep1
+  },
+  { // Entry 322
+    0x1.dd38a1f1d289b6173115721bc5c1fc72p-54,
+    0x1.cb44e86bc192bp648
+  },
+  { // Entry 323
+    -0x1.dd38a1f1d289b6173115721bc5c1fc72p-54,
+    -0x1.cb44e86bc192bp648
+  },
+  { // Entry 324
+    0x1.dd38a1f1d289b6173115721bc629a23dp-53,
+    0x1.cb44e86bc192bp649
+  },
+  { // Entry 325
+    -0x1.dd38a1f1d289b6173115721bc629a23dp-53,
+    -0x1.cb44e86bc192bp649
+  },
+  { // Entry 326
+    -0x1.fff6e755320ed78db4d6eff4bf6a6b10p1,
+    0x1.cb61afedb2b3cp119
+  },
+  { // Entry 327
+    0x1.fff6e755320ed78db4d6eff4bf6a6b10p1,
+    -0x1.cb61afedb2b3cp119
+  },
+  { // Entry 328
+    0x1.ccdf4aa6c228f8041be91a142e0e271bp-7,
+    0x1.ccd7834ba3804p-7
+  },
+  { // Entry 329
+    -0x1.ccdf4aa6c228f8041be91a142e0e271bp-7,
+    -0x1.ccd7834ba3804p-7
+  },
+  { // Entry 330
+    0x1.cee50016fc2d8837286bf6fd431a7b3bp-4,
+    0x1.ccf0599da478ep-4
+  },
+  { // Entry 331
+    -0x1.cee50016fc2d8837286bf6fd431a7b3bp-4,
+    -0x1.ccf0599da478ep-4
+  },
+  { // Entry 332
+    0x1.44cf3ee8a75a87cc6657e62f94a93e6fp0,
+    0x1.ce8p-1
+  },
+  { // Entry 333
+    -0x1.44cf3ee8a75a87cc6657e62f94a93e6fp0,
+    -0x1.ce8p-1
+  },
+  { // Entry 334
+    0x1.45aa12ff98152800001fbd8799a96a2cp0,
+    0x1.cf276c9cb9af0p-1
+  },
+  { // Entry 335
+    -0x1.45aa12ff98152800001fbd8799a96a2cp0,
+    -0x1.cf276c9cb9af0p-1
+  },
+  { // Entry 336
+    0x1.f9bc744f61e0ed853829e2f765b8a12cp-4,
+    0x1.d2e979148a458p61
+  },
+  { // Entry 337
+    -0x1.f9bc744f61e0ed853829e2f765b8a12cp-4,
+    -0x1.d2e979148a458p61
+  },
+  { // Entry 338
+    0x1.6e70f9edbd1a082ae6f90c62ef4f31ddp-2,
+    0x1.d6b5ad6b5ab68p100
+  },
+  { // Entry 339
+    -0x1.6e70f9edbd1a082ae6f90c62ef4f31ddp-2,
+    -0x1.d6b5ad6b5ab68p100
+  },
+  { // Entry 340
+    0x1.13e9c6a348e4a7bede82724505269f68p2,
+    0x1.d96e058p488
+  },
+  { // Entry 341
+    -0x1.13e9c6a348e4a7bede82724505269f68p2,
+    -0x1.d96e058p488
+  },
+  { // Entry 342
+    -0x1.d355463c2303582fa31a3238dcbe560ep-5,
+    0x1.dd10f25171bc9p5
+  },
+  { // Entry 343
+    0x1.d355463c2303582fa31a3238dcbe560ep-5,
+    -0x1.dd10f25171bc9p5
+  },
+  { // Entry 344
+    0x1.ddf21ebf6fc927fffffbb3ecc0cff66ep-6,
+    0x1.ddcf6e56696a4p-6
+  },
+  { // Entry 345
+    -0x1.ddf21ebf6fc927fffffbb3ecc0cff66ep-6,
+    -0x1.ddcf6e56696a4p-6
+  },
+  { // Entry 346
+    0x1.5cb0bfc1558007e0c5d095f729e3427bp0,
+    0x1.ep-1
+  },
+  { // Entry 347
+    -0x1.5cb0bfc1558007e0c5d095f729e3427bp0,
+    -0x1.ep-1
+  },
+  { // Entry 348
+    -0x1.97b5e8ae9a21c7f4821922bc5b3782ccp1,
+    0x1.ep0
+  },
+  { // Entry 349
+    0x1.97b5e8ae9a21c7f4821922bc5b3782ccp1,
+    -0x1.ep0
+  },
+  { // Entry 350
+    -0x1.f8bf68d0c23f3741efb8bd99853bae8ap0,
+    0x1.e779de779de71p118
+  },
+  { // Entry 351
+    0x1.f8bf68d0c23f3741efb8bd99853bae8ap0,
+    -0x1.e779de779de71p118
+  },
+  { // Entry 352
+    -0x1.fffffffffd71cf934ef3e5df4008665fp-1,
+    0x1.eb0567bed1f71p12
+  },
+  { // Entry 353
+    0x1.fffffffffd71cf934ef3e5df4008665fp-1,
+    -0x1.eb0567bed1f71p12
+  },
+  { // Entry 354
+    0x1.ee788d1cc7954841878473aa5d2615a5p-4,
+    0x1.ec16f30a34fbcp-4
+  },
+  { // Entry 355
+    -0x1.ee788d1cc7954841878473aa5d2615a5p-4,
+    -0x1.ec16f30a34fbcp-4
+  },
+  { // Entry 356
+    0x1.efdad938b4b0e834014bf56a7084675dp-4,
+    0x1.ed7424ba2aa4ep-4
+  },
+  { // Entry 357
+    -0x1.efdad938b4b0e834014bf56a7084675dp-4,
+    -0x1.ed7424ba2aa4ep-4
+  },
+  { // Entry 358
+    0x1.da347607948f47ffef21697161fd3cddp-1,
+    0x1.ee9eda5890390p499
+  },
+  { // Entry 359
+    -0x1.da347607948f47ffef21697161fd3cddp-1,
+    -0x1.ee9eda5890390p499
+  },
+  { // Entry 360
+    0x1.f682d27a8be87f783d494857b6f30e05p0,
+    0x1.f4ff0d7b3ac10p100
+  },
+  { // Entry 361
+    -0x1.f682d27a8be87f783d494857b6f30e05p0,
+    -0x1.f4ff0d7b3ac10p100
+  },
+  { // Entry 362
+    -0x1.ffd36a753ced9027c93845adde046246p-1,
+    0x1.f5a814afd69f5p119
+  },
+  { // Entry 363
+    0x1.ffd36a753ced9027c93845adde046246p-1,
+    -0x1.f5a814afd69f5p119
+  },
+  { // Entry 364
+    -0x1.0fa7701d059b51de05df58ade26bec5cp-9,
+    0x1.f8fc824d2693bp61
+  },
+  { // Entry 365
+    0x1.0fa7701d059b51de05df58ade26bec5cp-9,
+    -0x1.f8fc824d2693bp61
+  },
+  { // Entry 366
+    -0x1.afe3875bd3afe801f149d0a9ad36f453p-4,
+    0x1.f9be6f9be6f98p9
+  },
+  { // Entry 367
+    0x1.afe3875bd3afe801f149d0a9ad36f453p-4,
+    -0x1.f9be6f9be6f98p9
+  },
+  { // Entry 368
+    0x1.fd1032e82deab7baba99c913dee10b9ap-4,
+    0x1.fa775cd264f43p-4
+  },
+  { // Entry 369
+    -0x1.fd1032e82deab7baba99c913dee10b9ap-4,
+    -0x1.fa775cd264f43p-4
+  },
+  { // Entry 370
+    0x1.fea8c67dd46ca83ca49ab9ecd0360739p-4,
+    0x1.fc09b47402d82p-4
+  },
+  { // Entry 371
+    -0x1.fea8c67dd46ca83ca49ab9ecd0360739p-4,
+    -0x1.fc09b47402d82p-4
+  },
+  { // Entry 372
+    -0x1.9020caf18a87438127a85d1f0a3d4205p-1,
+    0x1.feeffffffffc6p995
+  },
+  { // Entry 373
+    0x1.9020caf18a87438127a85d1f0a3d4205p-1,
+    -0x1.feeffffffffc6p995
+  },
+  { // Entry 374
+    0x1.af135beb0f2817fba77204a5b1b6766bp0,
+    0x1.ff01fffffffffp7
+  },
+  { // Entry 375
+    -0x1.af135beb0f2817fba77204a5b1b6766bp0,
+    -0x1.ff01fffffffffp7
+  },
+  { // Entry 376
+    -0x1.fd97532efd89b26bc294b27e0a1956b9p3,
+    0x1.ff8ffffffffffp540
+  },
+  { // Entry 377
+    0x1.fd97532efd89b26bc294b27e0a1956b9p3,
+    -0x1.ff8ffffffffffp540
+  },
+  { // Entry 378
+    -0x1.cc32cb933818111e6ddf00c5c79cbc88p-1,
+    0x1.ff8ffffffffffp870
+  },
+  { // Entry 379
+    0x1.cc32cb933818111e6ddf00c5c79cbc88p-1,
+    -0x1.ff8ffffffffffp870
+  },
+  { // Entry 380
+    -0x1.8659d3e2b52b880668ac8b4b9fae9538p-1,
+    0x1.ffc10p9
+  },
+  { // Entry 381
+    0x1.8659d3e2b52b880668ac8b4b9fae9538p-1,
+    -0x1.ffc10p9
+  },
+  { // Entry 382
+    -0x1.b66066fb812ee27dbb623a1a1353e062p-2,
+    0x1.ffcfff8p19
+  },
+  { // Entry 383
+    0x1.b66066fb812ee27dbb623a1a1353e062p-2,
+    -0x1.ffcfff8p19
+  },
+  { // Entry 384
+    -0x1.520ebd32e1d8ecd38bfcd6a57e1a377fp1,
+    0x1.ffcfff8p365
+  },
+  { // Entry 385
+    0x1.520ebd32e1d8ecd38bfcd6a57e1a377fp1,
+    -0x1.ffcfff8p365
+  },
+  { // Entry 386
+    0x1.489813c24d13b00ab69627d858bb63b5p0,
+    0x1.ffcffffffff6cp720
+  },
+  { // Entry 387
+    -0x1.489813c24d13b00ab69627d858bb63b5p0,
+    -0x1.ffcffffffff6cp720
+  },
+  { // Entry 388
+    0x1.413e63f7dd607ef3c8422a490af2dc30p0,
+    0x1.ffcfffffffff9p320
+  },
+  { // Entry 389
+    -0x1.413e63f7dd607ef3c8422a490af2dc30p0,
+    -0x1.ffcfffffffff9p320
+  },
+  { // Entry 390
+    -0x1.fc3928a39b65284d4c7ef3b6a2edc8f1p-2,
+    0x1.ffcffffffffffp990
+  },
+  { // Entry 391
+    0x1.fc3928a39b65284d4c7ef3b6a2edc8f1p-2,
+    -0x1.ffcffffffffffp990
+  },
+  { // Entry 392
+    -0x1.9ad70d284f16d59dcaa0ab9fb77d7490p-1,
+    0x1.ffeffffffffccp995
+  },
+  { // Entry 393
+    0x1.9ad70d284f16d59dcaa0ab9fb77d7490p-1,
+    -0x1.ffeffffffffccp995
+  },
+  { // Entry 394
+    0x1.aad6effcb6783826de7b24dba501c11cp-3,
+    0x1.ffefffffffffdp366
+  },
+  { // Entry 395
+    -0x1.aad6effcb6783826de7b24dba501c11cp-3,
+    -0x1.ffefffffffffdp366
+  },
+  { // Entry 396
+    0x1.c88645f9d119ec2030724a4ce4e6ebbap2,
+    0x1.ffeffffffffffp180
+  },
+  { // Entry 397
+    -0x1.c88645f9d119ec2030724a4ce4e6ebbap2,
+    -0x1.ffeffffffffffp180
+  },
+  { // Entry 398
+    0x1.131aa7b9d4aa07ff5840ac1e8fb42360p2,
+    0x1.ffeffffffffffp231
+  },
+  { // Entry 399
+    -0x1.131aa7b9d4aa07ff5840ac1e8fb42360p2,
+    -0x1.ffeffffffffffp231
+  },
+  { // Entry 400
+    0x1.f671719be50d1d4debe85c922e1e2913p-3,
+    0x1.ffeffffffffffp1019
+  },
+  { // Entry 401
+    -0x1.f671719be50d1d4debe85c922e1e2913p-3,
+    -0x1.ffeffffffffffp1019
+  },
+  { // Entry 402
+    0x1.ff078a2d2d871ac1f32765e9db644eb1p-1,
+    0x1.fff1fffffffffp40
+  },
+  { // Entry 403
+    -0x1.ff078a2d2d871ac1f32765e9db644eb1p-1,
+    -0x1.fff1fffffffffp40
+  },
+  { // Entry 404
+    0x1.0784b04fc42a59e77f85d9967da6775dp9,
+    0x1.fff1fffffffffp41
+  },
+  { // Entry 405
+    -0x1.0784b04fc42a59e77f85d9967da6775dp9,
+    -0x1.fff1fffffffffp41
+  },
+  { // Entry 406
+    0x1.8eb22dd167a37ad21ddf1e69734e9ce2p0,
+    0x1.fffff1fffffffp-1
+  },
+  { // Entry 407
+    -0x1.8eb22dd167a37ad21ddf1e69734e9ce2p0,
+    -0x1.fffff1fffffffp-1
+  },
+  { // Entry 408
+    -0x1.22e7346fd3dda553b146c37f61127a4cp1,
+    0x1.ffffff8p119
+  },
+  { // Entry 409
+    0x1.22e7346fd3dda553b146c37f61127a4cp1,
+    -0x1.ffffff8p119
+  },
+  { // Entry 410
+    -0x1.db0b3b019f175bed5bcf1a5602db00afp-3,
+    0x1.ffffff8p192
+  },
+  { // Entry 411
+    0x1.db0b3b019f175bed5bcf1a5602db00afp-3,
+    -0x1.ffffff8p192
+  },
+  { // Entry 412
+    0x1.06b6bede910257f315a5083a9ab2b650p-1,
+    0x1.ffffff8p543
+  },
+  { // Entry 413
+    -0x1.06b6bede910257f315a5083a9ab2b650p-1,
+    -0x1.ffffff8p543
+  },
+  { // Entry 414
+    -0x1.40f02a15dfa3d7ff3e2a4553f19cb2d0p1,
+    0x1.ffffffffbbfffp40
+  },
+  { // Entry 415
+    0x1.40f02a15dfa3d7ff3e2a4553f19cb2d0p1,
+    -0x1.ffffffffbbfffp40
+  },
+  { // Entry 416
+    0x1.ab60112ef4fddff3f5a2690c7d3ea6efp-2,
+    0x1.fffffffff7fffp231
+  },
+  { // Entry 417
+    -0x1.ab60112ef4fddff3f5a2690c7d3ea6efp-2,
+    -0x1.fffffffff7fffp231
+  },
+  { // Entry 418
+    0x1.35a9929eeafd70f0712abe2a511854a1p0,
+    0x1.fffffffffff78p920
+  },
+  { // Entry 419
+    -0x1.35a9929eeafd70f0712abe2a511854a1p0,
+    -0x1.fffffffffff78p920
+  },
+  { // Entry 420
+    0x1.4630298f3b993287205dc0b89b0601e0p0,
+    0x1.fffffffffffd5p995
+  },
+  { // Entry 421
+    -0x1.4630298f3b993287205dc0b89b0601e0p0,
+    -0x1.fffffffffffd5p995
+  },
+  { // Entry 422
+    -0x1.9472e045129fdba63791712416ec9613p-1,
+    0x1.fffffffffffe8p720
+  },
+  { // Entry 423
+    0x1.9472e045129fdba63791712416ec9613p-1,
+    -0x1.fffffffffffe8p720
+  },
+  { // Entry 424
+    0x1.42e586daa1b428fc0580888f2fc46893p0,
+    0x1.fffffffffffebp920
+  },
+  { // Entry 425
+    -0x1.42e586daa1b428fc0580888f2fc46893p0,
+    -0x1.fffffffffffebp920
+  },
+  { // Entry 426
+    -0x1.bfc436b94374b5f16b60ea69cd883992p-1,
+    0x1.ffffffffffff1p245
+  },
+  { // Entry 427
+    0x1.bfc436b94374b5f16b60ea69cd883992p-1,
+    -0x1.ffffffffffff1p245
+  },
+  { // Entry 428
+    0x1.35117d4a4f1e4bb22fdd03164a364ccfp0,
+    0x1.ffffffffffff4p845
+  },
+  { // Entry 429
+    -0x1.35117d4a4f1e4bb22fdd03164a364ccfp0,
+    -0x1.ffffffffffff4p845
+  },
+  { // Entry 430
+    -0x1.bfdd9292798aaa789c3df0df7729835ap-1,
+    0x1.ffffffffffff4p1020
+  },
+  { // Entry 431
+    0x1.bfdd9292798aaa789c3df0df7729835ap-1,
+    -0x1.ffffffffffff4p1020
+  },
+  { // Entry 432
+    -0x1.9b768ccdae6ebb70b45ac14e92b3d5c8p9,
+    0x1.ffffffffffffcp45
+  },
+  { // Entry 433
+    0x1.9b768ccdae6ebb70b45ac14e92b3d5c8p9,
+    -0x1.ffffffffffffcp45
+  },
+  { // Entry 434
+    0x1.feca047f2730f7395d95f469ccb5a5d3p-1,
+    0x1.ffffffffffffcp474
+  },
+  { // Entry 435
+    -0x1.feca047f2730f7395d95f469ccb5a5d3p-1,
+    -0x1.ffffffffffffcp474
+  },
+  { // Entry 436
+    -0x1.449f15cc945597ff58f2426acbff9c62p-2,
+    0x1.ffffffffffffcp976
+  },
+  { // Entry 437
+    0x1.449f15cc945597ff58f2426acbff9c62p-2,
+    -0x1.ffffffffffffcp976
+  },
+  { // Entry 438
+    0x1.fffc58da07951cbe22c96d73b1289e1ep-2,
+    0x1.ffffffffffffep881
+  },
+  { // Entry 439
+    -0x1.fffc58da07951cbe22c96d73b1289e1ep-2,
+    -0x1.ffffffffffffep881
+  },
+  { // Entry 440
+    -0x1.c1c9195ec23aa64df145dd269cd895e8p-1,
+    0x1.ffffffffffffep970
+  },
+  { // Entry 441
+    0x1.c1c9195ec23aa64df145dd269cd895e8p-1,
+    -0x1.ffffffffffffep970
+  },
+  { // Entry 442
+    0x1.3cc1ed3906d2f7fdd633cf4eb06f3f19p-2,
+    0x1.33328c1b37321p-2
+  },
+  { // Entry 443
+    -0x1.3cc1ed3906d2f7fdd633cf4eb06f3f19p-2,
+    -0x1.33328c1b37321p-2
+  },
+  { // Entry 444
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 445
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 446
+    -0.0,
+    -0.0
+  },
+  { // Entry 447
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 448
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 449
+    -0x1.00000000000010p-1022,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 450
+    0x1.00000000000010p-1022,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 451
+    -0x1.p-1022,
+    -0x1.0p-1022
+  },
+  { // Entry 452
+    0x1.p-1022,
+    0x1.0p-1022
+  },
+  { // Entry 453
+    -0x1.ffffffffffffe0p-1023,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 454
+    0x1.ffffffffffffe0p-1023,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 455
+    0x1.ffffffffffffe0p-1023,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 456
+    -0x1.ffffffffffffe0p-1023,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 457
+    0x1.p-1022,
+    0x1.0p-1022
+  },
+  { // Entry 458
+    -0x1.p-1022,
+    -0x1.0p-1022
+  },
+  { // Entry 459
+    0x1.00000000000010p-1022,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 460
+    -0x1.00000000000010p-1022,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 461
+    0x1.999999f0fb38c6122a1fa8e043bb07c2p-13,
+    0x1.999999999999ap-13
+  },
+  { // Entry 462
+    -0x1.999999f0fb38c6122a1fa8e043bb07c2p-13,
+    -0x1.999999999999ap-13
+  },
+  { // Entry 463
+    0x1.99999af7201744b823e5b270fd1aa39dp-12,
+    0x1.999999999999ap-12
+  },
+  { // Entry 464
+    -0x1.99999af7201744b823e5b270fd1aa39dp-12,
+    -0x1.999999999999ap-12
+  },
+  { // Entry 465
+    0x1.33333581062a38f04df024142ddaa05dp-11,
+    0x1.3333333333334p-11
+  },
+  { // Entry 466
+    -0x1.33333581062a38f04df024142ddaa05dp-11,
+    -0x1.3333333333334p-11
+  },
+  { // Entry 467
+    0x1.99999f0fb3a0f9d88738be2ff7af9aaap-11,
+    0x1.999999999999ap-11
+  },
+  { // Entry 468
+    -0x1.99999f0fb3a0f9d88738be2ff7af9aaap-11,
+    -0x1.999999999999ap-11
+  },
+  { // Entry 469
+    0x1.000005555577777854854dedc28ead51p-10,
+    0x1.0p-10
+  },
+  { // Entry 470
+    -0x1.000005555577777854854dedc28ead51p-10,
+    -0x1.0p-10
+  },
+  { // Entry 471
+    0x1.33333c6a7f4ec73853151cd76b79e135p-10,
+    0x1.3333333333333p-10
+  },
+  { // Entry 472
+    -0x1.33333c6a7f4ec73853151cd76b79e135p-10,
+    -0x1.3333333333333p-10
+  },
+  { // Entry 473
+    0x1.66667508e0a1b502287034d36bf4e3d5p-10,
+    0x1.6666666666666p-10
+  },
+  { // Entry 474
+    -0x1.66667508e0a1b502287034d36bf4e3d5p-10,
+    -0x1.6666666666666p-10
+  },
+  { // Entry 475
+    0x1.9999af7202c366f1e0b548a31c41d210p-10,
+    0x1.9999999999999p-10
+  },
+  { // Entry 476
+    -0x1.9999af7202c366f1e0b548a31c41d210p-10,
+    -0x1.9999999999999p-10
+  },
+  { // Entry 477
+    0x1.ccccebe76f102ff633c5f02a34076687p-10,
+    0x1.cccccccccccccp-10
+  },
+  { // Entry 478
+    -0x1.ccccebe76f102ff633c5f02a34076687p-10,
+    -0x1.cccccccccccccp-10
+  },
+  { // Entry 479
+    0x1.0667d5fcf3d078f940687eb974310fb9p-7,
+    0x1.0666666666666p-7
+  },
+  { // Entry 480
+    -0x1.0667d5fcf3d078f940687eb974310fb9p-7,
+    -0x1.0666666666666p-7
+  },
+  { // Entry 481
+    0x1.ccd4939d0ccd7646b3f81b7553675c23p-7,
+    0x1.cccccccccccccp-7
+  },
+  { // Entry 482
+    -0x1.ccd4939d0ccd7646b3f81b7553675c23p-7,
+    -0x1.cccccccccccccp-7
+  },
+  { // Entry 483
+    0x1.49a4fc02ad193e8e94c4b2429190b5b2p-6,
+    0x1.4999999999999p-6
+  },
+  { // Entry 484
+    -0x1.49a4fc02ad193e8e94c4b2429190b5b2p-6,
+    -0x1.4999999999999p-6
+  },
+  { // Entry 485
+    0x1.ace5ded5f6be698f56697ac761f3dc69p-6,
+    0x1.accccccccccccp-6
+  },
+  { // Entry 486
+    -0x1.ace5ded5f6be698f56697ac761f3dc69p-6,
+    -0x1.accccccccccccp-6
+  },
+  { // Entry 487
+    0x1.081767fd3cb685f7b069146ce3333851p-5,
+    0x1.080p-5
+  },
+  { // Entry 488
+    -0x1.081767fd3cb685f7b069146ce3333851p-5,
+    -0x1.080p-5
+  },
+  { // Entry 489
+    0x1.39c0d6dea66fb6d286d403c292527356p-5,
+    0x1.399999999999ap-5
+  },
+  { // Entry 490
+    -0x1.39c0d6dea66fb6d286d403c292527356p-5,
+    -0x1.399999999999ap-5
+  },
+  { // Entry 491
+    0x1.6b702b954bc1d583c4a46773c2c2a15dp-5,
+    0x1.6b33333333334p-5
+  },
+  { // Entry 492
+    -0x1.6b702b954bc1d583c4a46773c2c2a15dp-5,
+    -0x1.6b33333333334p-5
+  },
+  { // Entry 493
+    0x1.9d265618dd0c688e049c61090d3e3fe2p-5,
+    0x1.9cccccccccccep-5
+  },
+  { // Entry 494
+    -0x1.9d265618dd0c688e049c61090d3e3fe2p-5,
+    -0x1.9cccccccccccep-5
+  },
+  { // Entry 495
+    0x1.cee446e4cfd4be6900f4b906ca9725b1p-5,
+    0x1.ce66666666666p-5
+  },
+  { // Entry 496
+    -0x1.cee446e4cfd4be6900f4b906ca9725b1p-5,
+    -0x1.ce66666666666p-5
+  },
+  { // Entry 497
+    0x1.a1eaedd5a4313e9d08bc7bb17a22531fp-1,
+    0x1.5e7fc4369bdadp-1
+  },
+  { // Entry 498
+    -0x1.a1eaedd5a4313e9d08bc7bb17a22531fp-1,
+    -0x1.5e7fc4369bdadp-1
+  },
+  { // Entry 499
+    0x1.d93b8aad424de0e43fb04d6781be81a3p1,
+    0x1.4e7fc4369bdadp0
+  },
+  { // Entry 500
+    -0x1.d93b8aad424de0e43fb04d6781be81a3p1,
+    -0x1.4e7fc4369bdadp0
+  },
+  { // Entry 501
+    -0x1.563acf158c2eb678d71be31e0f34754dp1,
+    0x1.edbfa651e9c84p0
+  },
+  { // Entry 502
+    0x1.563acf158c2eb678d71be31e0f34754dp1,
+    -0x1.edbfa651e9c84p0
+  },
+  { // Entry 503
+    -0x1.576b77609f0890313c371a0a2c582145p-1,
+    0x1.467fc4369bdadp1
+  },
+  { // Entry 504
+    0x1.576b77609f0890313c371a0a2c582145p-1,
+    -0x1.467fc4369bdadp1
+  },
+  { // Entry 505
+    0x1.00155777aebf6ad41b39a808ed5c3384p-5,
+    0x1.961fb54442d18p1
+  },
+  { // Entry 506
+    -0x1.00155777aebf6ad41b39a808ed5c3384p-5,
+    -0x1.961fb54442d18p1
+  },
+  { // Entry 507
+    0x1.87e9966e7d22d348fec6c95f851775f4p-1,
+    0x1.e5bfa651e9c83p1
+  },
+  { // Entry 508
+    -0x1.87e9966e7d22d348fec6c95f851775f4p-1,
+    -0x1.e5bfa651e9c83p1
+  },
+  { // Entry 509
+    0x1.a49e7d8987850f9ca5b9332e39dcd88fp1,
+    0x1.1aafcbafc85f7p2
+  },
+  { // Entry 510
+    -0x1.a49e7d8987850f9ca5b9332e39dcd88fp1,
+    -0x1.1aafcbafc85f7p2
+  },
+  { // Entry 511
+    -0x1.79ced8156d040edde5a6ab62255e2261p1,
+    0x1.427fc4369bdadp2
+  },
+  { // Entry 512
+    0x1.79ced8156d040edde5a6ab62255e2261p1,
+    -0x1.427fc4369bdadp2
+  },
+  { // Entry 513
+    -0x1.6f1f65cd1e91b5e5ec1e120e9e0ddc0ap-1,
+    0x1.6a4fbcbd6f562p2
+  },
+  { // Entry 514
+    0x1.6f1f65cd1e91b5e5ec1e120e9e0ddc0ap-1,
+    -0x1.6a4fbcbd6f562p2
+  },
+  { // Entry 515
+    -0x1.67747d5f844e1b0c503d51e7ba032ffcp-1,
+    0x1.6af2eff0a2896p2
+  },
+  { // Entry 516
+    0x1.67747d5f844e1b0c503d51e7ba032ffcp-1,
+    -0x1.6af2eff0a2896p2
+  },
+  { // Entry 517
+    -0x1.626a258815d1823506d17069130eb9fbp1,
+    0x1.43c62a9d02414p2
+  },
+  { // Entry 518
+    0x1.626a258815d1823506d17069130eb9fbp1,
+    -0x1.43c62a9d02414p2
+  },
+  { // Entry 519
+    0x1.d6adaf80f8b051fbc7ab9f2e09e8e608p1,
+    0x1.1c99654961f92p2
+  },
+  { // Entry 520
+    -0x1.d6adaf80f8b051fbc7ab9f2e09e8e608p1,
+    -0x1.1c99654961f92p2
+  },
+  { // Entry 521
+    0x1.a94d1b21370d52bfcd9ec417e41d6e5bp-1,
+    0x1.ead93feb8361fp1
+  },
+  { // Entry 522
+    -0x1.a94d1b21370d52bfcd9ec417e41d6e5bp-1,
+    -0x1.ead93feb8361fp1
+  },
+  { // Entry 523
+    0x1.4cba9e78222340ca493f803bbc947659p-4,
+    0x1.9c7fb54442d1ap1
+  },
+  { // Entry 524
+    -0x1.4cba9e78222340ca493f803bbc947659p-4,
+    -0x1.9c7fb54442d1ap1
+  },
+  { // Entry 525
+    -0x1.2cb6d02634531a6839bf898cc1f918dep-1,
+    0x1.4e262a9d02415p1
+  },
+  { // Entry 526
+    0x1.2cb6d02634531a6839bf898cc1f918dep-1,
+    -0x1.4e262a9d02415p1
+  },
+  { // Entry 527
+    -0x1.18d9112308d5b897ba44cfc5c4437317p1,
+    0x1.ff993feb83620p0
+  },
+  { // Entry 528
+    0x1.18d9112308d5b897ba44cfc5c4437317p1,
+    -0x1.ff993feb83620p0
+  },
+  { // Entry 529
+    0x1.56fe0145cf2901975829ddc3fc786df0p2,
+    0x1.62e62a9d02416p0
+  },
+  { // Entry 530
+    -0x1.56fe0145cf2901975829ddc3fc786df0p2,
+    -0x1.62e62a9d02416p0
+  },
+  { // Entry 531
+    0x1.f4ad353aca453f62beae01cd5b13d50dp-1,
+    0x1.8c662a9d02419p-1
+  },
+  { // Entry 532
+    -0x1.f4ad353aca453f62beae01cd5b13d50dp-1,
+    -0x1.8c662a9d02419p-1
+  },
+  { // Entry 533
+    0x1.6a7e1f6407ee61397d016d691bb61d17p3,
+    -0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 534
+    -0x1.6a7e1f6407ee61397d016d691bb61d17p3,
+    0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 535
+    0x1.0d718cfc82464536bfd621be419f007cp6,
+    -0x1.95ec8b9e03d54p0
+  },
+  { // Entry 536
+    -0x1.0d718cfc82464536bfd621be419f007cp6,
+    0x1.95ec8b9e03d54p0
+  },
+  { // Entry 537
+    -0x1.11d87146c2d5a1832c24f3d87052d7ebp4,
+    -0x1.832efa2a435a9p0
+  },
+  { // Entry 538
+    0x1.11d87146c2d5a1832c24f3d87052d7ebp4,
+    0x1.832efa2a435a9p0
+  },
+  { // Entry 539
+    -0x1.e3a3729b3e86e2221fa5f04abf699e6ep2,
+    -0x1.707168b682dfep0
+  },
+  { // Entry 540
+    0x1.e3a3729b3e86e2221fa5f04abf699e6ep2,
+    0x1.707168b682dfep0
+  },
+  { // Entry 541
+    -0x1.3429e61a5d1f2e80fbd1370d4a7c2b10p2,
+    -0x1.5db3d742c2653p0
+  },
+  { // Entry 542
+    0x1.3429e61a5d1f2e80fbd1370d4a7c2b10p2,
+    0x1.5db3d742c2653p0
+  },
+  { // Entry 543
+    -0x1.c08caec5cf99725e57c32766fb084c5fp1,
+    -0x1.4af645cf01ea8p0
+  },
+  { // Entry 544
+    0x1.c08caec5cf99725e57c32766fb084c5fp1,
+    0x1.4af645cf01ea8p0
+  },
+  { // Entry 545
+    -0x1.5d603d751767ee70e9a2ff54959fa4a7p1,
+    -0x1.3838b45b416fdp0
+  },
+  { // Entry 546
+    0x1.5d603d751767ee70e9a2ff54959fa4a7p1,
+    0x1.3838b45b416fdp0
+  },
+  { // Entry 547
+    -0x1.1b48a35b1b277effabd7278b525708edp1,
+    -0x1.257b22e780f52p0
+  },
+  { // Entry 548
+    0x1.1b48a35b1b277effabd7278b525708edp1,
+    0x1.257b22e780f52p0
+  },
+  { // Entry 549
+    -0x1.d74caf9912dc7d9669b00926aa1ade11p0,
+    -0x1.12bd9173c07abp0
+  },
+  { // Entry 550
+    0x1.d74caf9912dc7d9669b00926aa1ade11p0,
+    0x1.12bd9173c07abp0
+  },
+  { // Entry 551
+    -0x1.6be702e1f6cd60bfd86ad86180d18490p0,
+    -0x1.ea5c3ed5b3850p-1
+  },
+  { // Entry 552
+    0x1.6be702e1f6cd60bfd86ad86180d18490p0,
+    0x1.ea5c3ed5b3850p-1
+  },
+  { // Entry 553
+    -0x1.4d0df1fc1d3484b027537d8117a395f4p0,
+    -0x1.d4b87dab670a0p-1
+  },
+  { // Entry 554
+    0x1.4d0df1fc1d3484b027537d8117a395f4p0,
+    0x1.d4b87dab670a0p-1
+  },
+  { // Entry 555
+    -0x1.316c8b068a7af257f1e5a51943834f3ep0,
+    -0x1.bf14bc811a8f0p-1
+  },
+  { // Entry 556
+    0x1.316c8b068a7af257f1e5a51943834f3ep0,
+    0x1.bf14bc811a8f0p-1
+  },
+  { // Entry 557
+    -0x1.1872a1aaa7e26cf417e6331617ea7dd0p0,
+    -0x1.a970fb56ce140p-1
+  },
+  { // Entry 558
+    0x1.1872a1aaa7e26cf417e6331617ea7dd0p0,
+    0x1.a970fb56ce140p-1
+  },
+  { // Entry 559
+    -0x1.01aeeed04cbb0dfacd1d00c657d08b19p0,
+    -0x1.93cd3a2c81990p-1
+  },
+  { // Entry 560
+    0x1.01aeeed04cbb0dfacd1d00c657d08b19p0,
+    0x1.93cd3a2c81990p-1
+  },
+  { // Entry 561
+    -0x1.d98e408ac2085c4e0588df10ba7fb023p-1,
+    -0x1.7e297902351e0p-1
+  },
+  { // Entry 562
+    0x1.d98e408ac2085c4e0588df10ba7fb023p-1,
+    0x1.7e297902351e0p-1
+  },
+  { // Entry 563
+    -0x1.b2e4750631c53c54f5830fd41753d427p-1,
+    -0x1.6885b7d7e8a30p-1
+  },
+  { // Entry 564
+    0x1.b2e4750631c53c54f5830fd41753d427p-1,
+    0x1.6885b7d7e8a30p-1
+  },
+  { // Entry 565
+    -0x1.8ee916392e04590ce988d82cc3959021p-1,
+    -0x1.52e1f6ad9c280p-1
+  },
+  { // Entry 566
+    0x1.8ee916392e04590ce988d82cc3959021p-1,
+    0x1.52e1f6ad9c280p-1
+  },
+  { // Entry 567
+    -0x1.6d395e495f77e709842592e226607b53p-1,
+    -0x1.3d3e35834fad0p-1
+  },
+  { // Entry 568
+    0x1.6d395e495f77e709842592e226607b53p-1,
+    0x1.3d3e35834fad0p-1
+  },
+  { // Entry 569
+    -0x1.24e3e017a098ecf4de48bceeb026743ap-1,
+    -0x1.0a0b02501c799p-1
+  },
+  { // Entry 570
+    0x1.24e3e017a098ecf4de48bceeb026743ap-1,
+    0x1.0a0b02501c799p-1
+  },
+  { // Entry 571
+    -0x1.fdbd5f0596bdc6ef8da53ee652b57cf7p-2,
+    -0x1.d8f7208e6b82cp-2
+  },
+  { // Entry 572
+    0x1.fdbd5f0596bdc6ef8da53ee652b57cf7p-2,
+    0x1.d8f7208e6b82cp-2
+  },
+  { // Entry 573
+    -0x1.b5f3d6afbe6f259af37c4e633ab5fdfap-2,
+    -0x1.9dd83c7c9e126p-2
+  },
+  { // Entry 574
+    0x1.b5f3d6afbe6f259af37c4e633ab5fdfap-2,
+    0x1.9dd83c7c9e126p-2
+  },
+  { // Entry 575
+    -0x1.71a0f98081ea98b5f30a1593e3fc6373p-2,
+    -0x1.62b9586ad0a20p-2
+  },
+  { // Entry 576
+    0x1.71a0f98081ea98b5f30a1593e3fc6373p-2,
+    0x1.62b9586ad0a20p-2
+  },
+  { // Entry 577
+    -0x1.301909a2c36e89a67528a38c77ac9e43p-2,
+    -0x1.279a74590331ap-2
+  },
+  { // Entry 578
+    0x1.301909a2c36e89a67528a38c77ac9e43p-2,
+    0x1.279a74590331ap-2
+  },
+  { // Entry 579
+    -0x1.e18e941cc7fd519ecc40548a86d2a3edp-3,
+    -0x1.d8f7208e6b829p-3
+  },
+  { // Entry 580
+    0x1.e18e941cc7fd519ecc40548a86d2a3edp-3,
+    0x1.d8f7208e6b829p-3
+  },
+  { // Entry 581
+    -0x1.6650784bbdcc02f3390262cf68bad3c6p-3,
+    -0x1.62b9586ad0a1ep-3
+  },
+  { // Entry 582
+    0x1.6650784bbdcc02f3390262cf68bad3c6p-3,
+    0x1.62b9586ad0a1ep-3
+  },
+  { // Entry 583
+    -0x1.db142468cdafc56ecfdf8b1052b09e63p-4,
+    -0x1.d8f7208e6b826p-4
+  },
+  { // Entry 584
+    0x1.db142468cdafc56ecfdf8b1052b09e63p-4,
+    0x1.d8f7208e6b826p-4
+  },
+  { // Entry 585
+    -0x1.d97dd6d2e53f27e0fe1f3bd2b035662ap-5,
+    -0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 586
+    0x1.d97dd6d2e53f27e0fe1f3bd2b035662ap-5,
+    0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 587
+    0x1.d97dd6d2e53f27e0fe1f3bd2b035662ap-5,
+    0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 588
+    -0x1.d97dd6d2e53f27e0fe1f3bd2b035662ap-5,
+    -0x1.d8f7208e6b82dp-5
+  },
+  { // Entry 589
+    0x1.db142468cdb036f08783d936b19348f6p-4,
+    0x1.d8f7208e6b82dp-4
+  },
+  { // Entry 590
+    -0x1.db142468cdb036f08783d936b19348f6p-4,
+    -0x1.d8f7208e6b82dp-4
+  },
+  { // Entry 591
+    0x1.6650784bbdcc44e8be2c220e1d673ffbp-3,
+    0x1.62b9586ad0a22p-3
+  },
+  { // Entry 592
+    -0x1.6650784bbdcc44e8be2c220e1d673ffbp-3,
+    -0x1.62b9586ad0a22p-3
+  },
+  { // Entry 593
+    0x1.e18e941cc7fd9528a5585157ac65e615p-3,
+    0x1.d8f7208e6b82dp-3
+  },
+  { // Entry 594
+    -0x1.e18e941cc7fd9528a5585157ac65e615p-3,
+    -0x1.d8f7208e6b82dp-3
+  },
+  { // Entry 595
+    0x1.301909a2c36eac78ec1b4e711316d0c4p-2,
+    0x1.279a74590331cp-2
+  },
+  { // Entry 596
+    -0x1.301909a2c36eac78ec1b4e711316d0c4p-2,
+    -0x1.279a74590331cp-2
+  },
+  { // Entry 597
+    0x1.71a0f98081eabce155f310288c4245eap-2,
+    0x1.62b9586ad0a22p-2
+  },
+  { // Entry 598
+    -0x1.71a0f98081eabce155f310288c4245eap-2,
+    -0x1.62b9586ad0a22p-2
+  },
+  { // Entry 599
+    0x1.b5f3d6afbe6f4b756842b8eee5c85a31p-2,
+    0x1.9dd83c7c9e128p-2
+  },
+  { // Entry 600
+    -0x1.b5f3d6afbe6f4b756842b8eee5c85a31p-2,
+    -0x1.9dd83c7c9e128p-2
+  },
+  { // Entry 601
+    0x1.fdbd5f0596bdeedd82d5223c3c1b1925p-2,
+    0x1.d8f7208e6b82ep-2
+  },
+  { // Entry 602
+    -0x1.fdbd5f0596bdeedd82d5223c3c1b1925p-2,
+    -0x1.d8f7208e6b82ep-2
+  },
+  { // Entry 603
+    0x1.24e3e017a098ecf4de48bceeb026743ap-1,
+    0x1.0a0b02501c799p-1
+  },
+  { // Entry 604
+    -0x1.24e3e017a098ecf4de48bceeb026743ap-1,
+    -0x1.0a0b02501c799p-1
+  },
+  { // Entry 605
+    0x1.6d395e495f778678b9ea0d4808c7220ap-1,
+    0x1.3d3e35834faccp-1
+  },
+  { // Entry 606
+    -0x1.6d395e495f778678b9ea0d4808c7220ap-1,
+    -0x1.3d3e35834faccp-1
+  },
+  { // Entry 607
+    0x1.8ee916392e03f2335033a41b3b0206e4p-1,
+    0x1.52e1f6ad9c27cp-1
+  },
+  { // Entry 608
+    -0x1.8ee916392e03f2335033a41b3b0206e4p-1,
+    -0x1.52e1f6ad9c27cp-1
+  },
+  { // Entry 609
+    0x1.b2e4750631c4ce283ef8753fa1edf324p-1,
+    0x1.6885b7d7e8a2cp-1
+  },
+  { // Entry 610
+    -0x1.b2e4750631c4ce283ef8753fa1edf324p-1,
+    -0x1.6885b7d7e8a2cp-1
+  },
+  { // Entry 611
+    0x1.d98e408ac207e58e15f0185d4b10cf71p-1,
+    0x1.7e297902351dcp-1
+  },
+  { // Entry 612
+    -0x1.d98e408ac207e58e15f0185d4b10cf71p-1,
+    -0x1.7e297902351dcp-1
+  },
+  { // Entry 613
+    0x1.01aeeed04cbacd8eb6bc094664db7763p0,
+    0x1.93cd3a2c8198cp-1
+  },
+  { // Entry 614
+    -0x1.01aeeed04cbacd8eb6bc094664db7763p0,
+    -0x1.93cd3a2c8198cp-1
+  },
+  { // Entry 615
+    0x1.1872a1aaa7e2268cb946fceb83f0ea5ep0,
+    0x1.a970fb56ce13cp-1
+  },
+  { // Entry 616
+    -0x1.1872a1aaa7e2268cb946fceb83f0ea5ep0,
+    -0x1.a970fb56ce13cp-1
+  },
+  { // Entry 617
+    0x1.316c8b068a7aa4cb77bc3f39921c2c8dp0,
+    0x1.bf14bc811a8ecp-1
+  },
+  { // Entry 618
+    -0x1.316c8b068a7aa4cb77bc3f39921c2c8dp0,
+    -0x1.bf14bc811a8ecp-1
+  },
+  { // Entry 619
+    0x1.4d0df1fc1d342e867e49f1f6ddacedaap0,
+    0x1.d4b87dab6709cp-1
+  },
+  { // Entry 620
+    -0x1.4d0df1fc1d342e867e49f1f6ddacedaap0,
+    -0x1.d4b87dab6709cp-1
+  },
+  { // Entry 621
+    0x1.6be702e1f6cd0016ba1677a9cd33f139p0,
+    0x1.ea5c3ed5b384cp-1
+  },
+  { // Entry 622
+    -0x1.6be702e1f6cd0016ba1677a9cd33f139p0,
+    -0x1.ea5c3ed5b384cp-1
+  },
+  { // Entry 623
+    0x1.d74caf9912dc7d9669b00926aa1ade11p0,
+    0x1.12bd9173c07abp0
+  },
+  { // Entry 624
+    -0x1.d74caf9912dc7d9669b00926aa1ade11p0,
+    -0x1.12bd9173c07abp0
+  },
+  { // Entry 625
+    0x1.1b48a35b1b283bbc82bb044e99c4d9b1p1,
+    0x1.257b22e780f56p0
+  },
+  { // Entry 626
+    -0x1.1b48a35b1b283bbc82bb044e99c4d9b1p1,
+    -0x1.257b22e780f56p0
+  },
+  { // Entry 627
+    0x1.5d603d751768fcd8af82b38746888530p1,
+    0x1.3838b45b41701p0
+  },
+  { // Entry 628
+    -0x1.5d603d751768fcd8af82b38746888530p1,
+    -0x1.3838b45b41701p0
+  },
+  { // Entry 629
+    0x1.c08caec5cf9b1b54b045228b3eeb2469p1,
+    0x1.4af645cf01eacp0
+  },
+  { // Entry 630
+    -0x1.c08caec5cf9b1b54b045228b3eeb2469p1,
+    -0x1.4af645cf01eacp0
+  },
+  { // Entry 631
+    0x1.3429e61a5d20b175d45c2a675a386ba3p2,
+    0x1.5db3d742c2657p0
+  },
+  { // Entry 632
+    -0x1.3429e61a5d20b175d45c2a675a386ba3p2,
+    -0x1.5db3d742c2657p0
+  },
+  { // Entry 633
+    0x1.e3a3729b3e8a83d44a76e342d6b3fcbfp2,
+    0x1.707168b682e02p0
+  },
+  { // Entry 634
+    -0x1.e3a3729b3e8a83d44a76e342d6b3fcbfp2,
+    -0x1.707168b682e02p0
+  },
+  { // Entry 635
+    0x1.11d87146c2da39408e86083bf1471c8bp4,
+    0x1.832efa2a435adp0
+  },
+  { // Entry 636
+    -0x1.11d87146c2da39408e86083bf1471c8bp4,
+    -0x1.832efa2a435adp0
+  },
+  { // Entry 637
+    -0x1.0d718cfc82348ab9754f3d6b5e0ea499p6,
+    0x1.95ec8b9e03d58p0
+  },
+  { // Entry 638
+    0x1.0d718cfc82348ab9754f3d6b5e0ea499p6,
+    -0x1.95ec8b9e03d58p0
+  },
+  { // Entry 639
+    -0x1.6a7e1f6407ee61397d016d691bb61d17p3,
+    0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 640
+    0x1.6a7e1f6407ee61397d016d691bb61d17p3,
+    -0x1.a8aa1d11c44ffp0
+  },
+  { // Entry 641
+    0x1.9f39ea5bbe4749e962a807c2dc11c825p0,
+    0x1.04aff6d330942p0
+  },
+  { // Entry 642
+    -0x1.9f39ea5bbe4749e962a807c2dc11c825p0,
+    -0x1.04aff6d330942p0
+  },
+  { // Entry 643
+    0x1.9f3c4b8469f853b8507455717327c311p0,
+    0x1.04b09e98dcdb4p0
+  },
+  { // Entry 644
+    -0x1.9f3c4b8469f853b8507455717327c311p0,
+    -0x1.04b09e98dcdb4p0
+  },
+  { // Entry 645
+    0x1.9f3eacb224c2086ef391b0dfad2f1010p0,
+    0x1.04b1465e89226p0
+  },
+  { // Entry 646
+    -0x1.9f3eacb224c2086ef391b0dfad2f1010p0,
+    -0x1.04b1465e89226p0
+  },
+  { // Entry 647
+    0x1.9f410de4eeb69590caee85e886f478a8p0,
+    0x1.04b1ee2435698p0
+  },
+  { // Entry 648
+    -0x1.9f410de4eeb69590caee85e886f478a8p0,
+    -0x1.04b1ee2435698p0
+  },
+  { // Entry 649
+    0x1.9f436f1cc7e828f752819af1e2f4b6a2p0,
+    0x1.04b295e9e1b0ap0
+  },
+  { // Entry 650
+    -0x1.9f436f1cc7e828f752819af1e2f4b6a2p0,
+    -0x1.04b295e9e1b0ap0
+  },
+  { // Entry 651
+    0x1.9f45d059b068f0d205485ad648223e6dp0,
+    0x1.04b33daf8df7cp0
+  },
+  { // Entry 652
+    -0x1.9f45d059b068f0d205485ad648223e6dp0,
+    -0x1.04b33daf8df7cp0
+  },
+  { // Entry 653
+    0x1.9f48319ba84b1ba65f452cfe65e02d0ep0,
+    0x1.04b3e5753a3eep0
+  },
+  { // Entry 654
+    -0x1.9f48319ba84b1ba65f452cfe65e02d0ep0,
+    -0x1.04b3e5753a3eep0
+  },
+  { // Entry 655
+    0x1.9f4a92e2afa0d84fdf7ddbaad302f150p0,
+    0x1.04b48d3ae6860p0
+  },
+  { // Entry 656
+    -0x1.9f4a92e2afa0d84fdf7ddbaad302f150p0,
+    -0x1.04b48d3ae6860p0
+  },
+  { // Entry 657
+    0x1.9f4cf42ec67ba7ad0db2be248a870bfep0,
+    0x1.04b5350092ccfp0
+  },
+  { // Entry 658
+    -0x1.9f4cf42ec67ba7ad0db2be248a870bfep0,
+    -0x1.04b5350092ccfp0
+  },
+  { // Entry 659
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 660
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 661
+    -0.0,
+    -0.0
+  },
+  { // Entry 662
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 663
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 664
+    0x1.4d82b68cac19e6d065c5f1aa7621c08cp-1,
+    0x1.279a74590331bp-1
+  },
+  { // Entry 665
+    -0x1.4d82b68cac19e6d065c5f1aa7621c08cp-1,
+    -0x1.279a74590331bp-1
+  },
+  { // Entry 666
+    0x1.4d82b68cac19fd9a5b0c912d9093aa4ap-1,
+    0x1.279a74590331cp-1
+  },
+  { // Entry 667
+    -0x1.4d82b68cac19fd9a5b0c912d9093aa4ap-1,
+    -0x1.279a74590331cp-1
+  },
+  { // Entry 668
+    0x1.4d82b68cac1a1464505330b0abf316bfp-1,
+    0x1.279a74590331dp-1
+  },
+  { // Entry 669
+    -0x1.4d82b68cac1a1464505330b0abf316bfp-1,
+    -0x1.279a74590331dp-1
+  },
+  { // Entry 670
+    -0x1.89712eeca32be97dba2ca3f9b8379154p2,
+    0x1.bb67ae8584ca9p0
+  },
+  { // Entry 671
+    0x1.89712eeca32be97dba2ca3f9b8379154p2,
+    -0x1.bb67ae8584ca9p0
+  },
+  { // Entry 672
+    -0x1.89712eeca32b4e528d25635a4293be1dp2,
+    0x1.bb67ae8584caap0
+  },
+  { // Entry 673
+    0x1.89712eeca32b4e528d25635a4293be1dp2,
+    -0x1.bb67ae8584caap0
+  },
+  { // Entry 674
+    -0x1.89712eeca32ab327601e22bb442cdc37p2,
+    0x1.bb67ae8584cabp0
+  },
+  { // Entry 675
+    0x1.89712eeca32ab327601e22bb442cdc37p2,
+    -0x1.bb67ae8584cabp0
+  },
+  { // Entry 676
+    0x1.def49eaab37a00f90cb4454710e4e545p-2,
+    0x1.bffffffffffffp-2
+  },
+  { // Entry 677
+    -0x1.def49eaab37a00f90cb4454710e4e545p-2,
+    -0x1.bffffffffffffp-2
+  },
+  { // Entry 678
+    0x1.def49eaab37a1479231e899509ecf26cp-2,
+    0x1.cp-2
+  },
+  { // Entry 679
+    -0x1.def49eaab37a1479231e899509ecf26cp-2,
+    -0x1.cp-2
+  },
+  { // Entry 680
+    0x1.def49eaab37a27f93988cde3033df72cp-2,
+    0x1.c000000000001p-2
+  },
+  { // Entry 681
+    -0x1.def49eaab37a27f93988cde3033df72cp-2,
+    -0x1.c000000000001p-2
+  },
+  { // Entry 682
+    0x1.a46cb2be6a0b02e2dfffc95e6dcb2842p-1,
+    0x1.5ffffffffffffp-1
+  },
+  { // Entry 683
+    -0x1.a46cb2be6a0b02e2dfffc95e6dcb2842p-1,
+    -0x1.5ffffffffffffp-1
+  },
+  { // Entry 684
+    0x1.a46cb2be6a0b1dacb36269c41a4a9147p-1,
+    0x1.6p-1
+  },
+  { // Entry 685
+    -0x1.a46cb2be6a0b1dacb36269c41a4a9147p-1,
+    -0x1.6p-1
+  },
+  { // Entry 686
+    0x1.a46cb2be6a0b387686c50a29c829ee42p-1,
+    0x1.6000000000001p-1
+  },
+  { // Entry 687
+    -0x1.a46cb2be6a0b387686c50a29c829ee42p-1,
+    -0x1.6000000000001p-1
+  },
+  { // Entry 688
+    0x1.3d6dc956eac79a85b47456fa0c946b13p1,
+    0x1.2ffffffffffffp0
+  },
+  { // Entry 689
+    -0x1.3d6dc956eac79a85b47456fa0c946b13p1,
+    -0x1.2ffffffffffffp0
+  },
+  { // Entry 690
+    0x1.3d6dc956eac7d3b8d6eb2174110d1ddcp1,
+    0x1.3p0
+  },
+  { // Entry 691
+    -0x1.3d6dc956eac7d3b8d6eb2174110d1ddcp1,
+    -0x1.3p0
+  },
+  { // Entry 692
+    0x1.3d6dc956eac80cebf961ebee274107p1,
+    0x1.3000000000001p0
+  },
+  { // Entry 693
+    -0x1.3d6dc956eac80cebf961ebee274107p1,
+    -0x1.3000000000001p0
+  },
+  { // Entry 694
+    -0x1.b2d89a93829536cc9283cfc7e01fe2a3p-1,
+    0x1.37fffffffffffp1
+  },
+  { // Entry 695
+    0x1.b2d89a93829536cc9283cfc7e01fe2a3p-1,
+    -0x1.37fffffffffffp1
+  },
+  { // Entry 696
+    -0x1.b2d89a938294c8a2604db9f7aa56a0f8p-1,
+    0x1.380p1
+  },
+  { // Entry 697
+    0x1.b2d89a938294c8a2604db9f7aa56a0f8p-1,
+    -0x1.380p1
+  },
+  { // Entry 698
+    -0x1.b2d89a9382945a782e17a4278bf17736p-1,
+    0x1.3800000000001p1
+  },
+  { // Entry 699
+    0x1.b2d89a9382945a782e17a4278bf17736p-1,
+    -0x1.3800000000001p1
+  },
+  { // Entry 700
+    0x1.06f8d014bf083cd36650e9466dc086dcp-4,
+    0x1.069c8b46b3792p-4
+  },
+  { // Entry 701
+    -0x1.06f8d014bf083cd36650e9466dc086dcp-4,
+    -0x1.069c8b46b3792p-4
+  },
+  { // Entry 702
+    0x1.080f73b07051e37b23da3337c0aed353p-3,
+    0x1.069c8b46b3792p-3
+  },
+  { // Entry 703
+    -0x1.080f73b07051e37b23da3337c0aed353p-3,
+    -0x1.069c8b46b3792p-3
+  },
+  { // Entry 704
+    0x1.8ed9142fc918888e294d3ff5d0149415p-3,
+    0x1.89ead0ea0d35bp-3
+  },
+  { // Entry 705
+    -0x1.8ed9142fc918888e294d3ff5d0149415p-3,
+    -0x1.89ead0ea0d35bp-3
+  },
+  { // Entry 706
+    0x1.0c864083d1e7ca5551bce24972878127p-2,
+    0x1.069c8b46b3792p-2
+  },
+  { // Entry 707
+    -0x1.0c864083d1e7ca5551bce24972878127p-2,
+    -0x1.069c8b46b3792p-2
+  },
+  { // Entry 708
+    0x1.53fdcdfd37f04375d9ffb6aebafe7df8p-2,
+    0x1.4843ae1860576p-2
+  },
+  { // Entry 709
+    -0x1.53fdcdfd37f04375d9ffb6aebafe7df8p-2,
+    -0x1.4843ae1860576p-2
+  },
+  { // Entry 710
+    0x1.9e9257e6b62a0a8de5650c837f7f6227p-2,
+    0x1.89ead0ea0d35ap-2
+  },
+  { // Entry 711
+    -0x1.9e9257e6b62a0a8de5650c837f7f6227p-2,
+    -0x1.89ead0ea0d35ap-2
+  },
+  { // Entry 712
+    0x1.ed21e59972b07c7053f4f35dd5502493p-2,
+    0x1.cb91f3bbba13ep-2
+  },
+  { // Entry 713
+    -0x1.ed21e59972b07c7053f4f35dd5502493p-2,
+    -0x1.cb91f3bbba13ep-2
+  },
+  { // Entry 714
+    0x1.205a6009d5e3dde25d6deb7d521ff140p-1,
+    0x1.069c8b46b3791p-1
+  },
+  { // Entry 715
+    -0x1.205a6009d5e3dde25d6deb7d521ff140p-1,
+    -0x1.069c8b46b3791p-1
+  },
+  { // Entry 716
+    0x1.4d466accad48dd958ab168f5cfc6c99cp-1,
+    0x1.27701caf89e83p-1
+  },
+  { // Entry 717
+    -0x1.4d466accad48dd958ab168f5cfc6c99cp-1,
+    -0x1.27701caf89e83p-1
+  },
+  { // Entry 718
+    0x1.7e1d936f4d6152fb74809595717fa06dp-1,
+    0x1.4843ae1860575p-1
+  },
+  { // Entry 719
+    -0x1.7e1d936f4d6152fb74809595717fa06dp-1,
+    -0x1.4843ae1860575p-1
+  },
+  { // Entry 720
+    0x1.b3df386f18227ebcee905fdc51cdcbe2p-1,
+    0x1.69173f8136c67p-1
+  },
+  { // Entry 721
+    -0x1.b3df386f18227ebcee905fdc51cdcbe2p-1,
+    -0x1.69173f8136c67p-1
+  },
+  { // Entry 722
+    0x1.efd82742d778c18a8c969be0cf0902b3p-1,
+    0x1.89ead0ea0d359p-1
+  },
+  { // Entry 723
+    -0x1.efd82742d778c18a8c969be0cf0902b3p-1,
+    -0x1.89ead0ea0d359p-1
+  },
+  { // Entry 724
+    0x1.19e26b5ecd5c040a1d80c1583f78f7d7p0,
+    0x1.aabe6252e3a4bp-1
+  },
+  { // Entry 725
+    -0x1.19e26b5ecd5c040a1d80c1583f78f7d7p0,
+    -0x1.aabe6252e3a4bp-1
+  },
+  { // Entry 726
+    0x1.41038b70be0fa1478f98a2e9f266550ap0,
+    0x1.cb91f3bbba13dp-1
+  },
+  { // Entry 727
+    -0x1.41038b70be0fa1478f98a2e9f266550ap0,
+    -0x1.cb91f3bbba13dp-1
+  },
+  { // Entry 728
+    0x1.6efec8c1e493b517efe5eb92464fdf42p0,
+    0x1.ec6585249082fp-1
+  },
+  { // Entry 729
+    -0x1.6efec8c1e493b517efe5eb92464fdf42p0,
+    -0x1.ec6585249082fp-1
+  },
+  { // Entry 730
+    0x1.a64c7c9d653462d8ded3e658fe4efbcbp0,
+    0x1.069c8b46b3791p0
+  },
+  { // Entry 731
+    -0x1.a64c7c9d653462d8ded3e658fe4efbcbp0,
+    -0x1.069c8b46b3791p0
+  },
+  { // Entry 732
+    0x1.eab43e0e5e87c26fd432e06301e19e15p0,
+    0x1.170653fb1eb0ap0
+  },
+  { // Entry 733
+    -0x1.eab43e0e5e87c26fd432e06301e19e15p0,
+    -0x1.170653fb1eb0ap0
+  },
+  { // Entry 734
+    0x1.21277b97c01376e361988250b56364cfp1,
+    0x1.27701caf89e83p0
+  },
+  { // Entry 735
+    -0x1.21277b97c01376e361988250b56364cfp1,
+    -0x1.27701caf89e83p0
+  },
+  { // Entry 736
+    0x1.5bd13dda077cce249db2794d69407504p1,
+    0x1.37d9e563f51fcp0
+  },
+  { // Entry 737
+    -0x1.5bd13dda077cce249db2794d69407504p1,
+    -0x1.37d9e563f51fcp0
+  },
+  { // Entry 738
+    0x1.af4643e9371f88e78c24d83bd6b8e23ep1,
+    0x1.4843ae1860575p0
+  },
+  { // Entry 739
+    -0x1.af4643e9371f88e78c24d83bd6b8e23ep1,
+    -0x1.4843ae1860575p0
+  },
+  { // Entry 740
+    0x1.1866fe845e759d14da478c6cf6f2be65p2,
+    0x1.58ad76cccb8eep0
+  },
+  { // Entry 741
+    -0x1.1866fe845e759d14da478c6cf6f2be65p2,
+    -0x1.58ad76cccb8eep0
+  },
+  { // Entry 742
+    0x1.8bdcd54bd5980b3a80cefc914c481475p2,
+    0x1.69173f8136c67p0
+  },
+  { // Entry 743
+    -0x1.8bdcd54bd5980b3a80cefc914c481475p2,
+    -0x1.69173f8136c67p0
+  },
+  { // Entry 744
+    0x1.4bb6a64e0625b974cded615056ffd61cp3,
+    0x1.79810835a1fe0p0
+  },
+  { // Entry 745
+    -0x1.4bb6a64e0625b974cded615056ffd61cp3,
+    -0x1.79810835a1fe0p0
+  },
+  { // Entry 746
+    0x1.f2f05cfb656a39f6f2a90f7911b24051p4,
+    0x1.89ead0ea0d359p0
+  },
+  { // Entry 747
+    -0x1.f2f05cfb656a39f6f2a90f7911b24051p4,
+    -0x1.89ead0ea0d359p0
+  },
+  { // Entry 748
+    -0x1.f2f05cfb657f55f2bc6d204377a68543p4,
+    0x1.9a54999e786d2p0
+  },
+  { // Entry 749
+    0x1.f2f05cfb657f55f2bc6d204377a68543p4,
+    -0x1.9a54999e786d2p0
+  },
+  { // Entry 750
+    -0x1.4bb6a64e062a6da35870cfb33595fbe6p3,
+    0x1.aabe6252e3a4bp0
+  },
+  { // Entry 751
+    0x1.4bb6a64e062a6da35870cfb33595fbe6p3,
+    -0x1.aabe6252e3a4bp0
+  },
+  { // Entry 752
+    -0x1.8bdcd54bd59b73028e5f27649ca67cbap2,
+    0x1.bb282b074edc4p0
+  },
+  { // Entry 753
+    0x1.8bdcd54bd59b73028e5f27649ca67cbap2,
+    -0x1.bb282b074edc4p0
+  },
+  { // Entry 754
+    -0x1.1866fe845e775d8c8f8bf9165647f6cbp2,
+    0x1.cb91f3bbba13dp0
+  },
+  { // Entry 755
+    0x1.1866fe845e775d8c8f8bf9165647f6cbp2,
+    -0x1.cb91f3bbba13dp0
+  },
+  { // Entry 756
+    -0x1.af4643e93721ad8095dd27f0827e13e0p1,
+    0x1.dbfbbc70254b6p0
+  },
+  { // Entry 757
+    0x1.af4643e93721ad8095dd27f0827e13e0p1,
+    -0x1.dbfbbc70254b6p0
+  },
+  { // Entry 758
+    -0x1.5bd13dda077e427d0c9dc6c0e5d3b1b5p1,
+    0x1.ec6585249082fp0
+  },
+  { // Entry 759
+    0x1.5bd13dda077e427d0c9dc6c0e5d3b1b5p1,
+    -0x1.ec6585249082fp0
+  },
+  { // Entry 760
+    -0x1.21277b97c01485f17bacdb804375ebcdp1,
+    0x1.fccf4dd8fbba8p0
+  },
+  { // Entry 761
+    0x1.21277b97c01485f17bacdb804375ebcdp1,
+    -0x1.fccf4dd8fbba8p0
+  },
+  { // Entry 762
+    -0x1.eab43e0e5e8916d4c08349abe9e2abd3p0,
+    0x1.069c8b46b3791p1
+  },
+  { // Entry 763
+    0x1.eab43e0e5e8916d4c08349abe9e2abd3p0,
+    -0x1.069c8b46b3791p1
+  },
+  { // Entry 764
+    -0x1.a64c7c9d6535364d605bb9e5315072ffp0,
+    0x1.0ed16fa0e914ep1
+  },
+  { // Entry 765
+    0x1.a64c7c9d6535364d605bb9e5315072ffp0,
+    -0x1.0ed16fa0e914ep1
+  },
+  { // Entry 766
+    -0x1.6efec8c1e4944a425541219364a15078p0,
+    0x1.170653fb1eb0bp1
+  },
+  { // Entry 767
+    0x1.6efec8c1e4944a425541219364a15078p0,
+    -0x1.170653fb1eb0bp1
+  },
+  { // Entry 768
+    -0x1.41038b70be0ff5b7c4d8f06b0d4cf525p0,
+    0x1.1f3b3855544c8p1
+  },
+  { // Entry 769
+    0x1.41038b70be0ff5b7c4d8f06b0d4cf525p0,
+    -0x1.1f3b3855544c8p1
+  },
+  { // Entry 770
+    -0x1.19e26b5ecd5c294348ba17fec5454792p0,
+    0x1.27701caf89e85p1
+  },
+  { // Entry 771
+    0x1.19e26b5ecd5c294348ba17fec5454792p0,
+    -0x1.27701caf89e85p1
+  },
+  { // Entry 772
+    -0x1.efd82742d778c4bca07e1e86cbc604b0p-1,
+    0x1.2fa50109bf842p1
+  },
+  { // Entry 773
+    0x1.efd82742d778c4bca07e1e86cbc604b0p-1,
+    -0x1.2fa50109bf842p1
+  },
+  { // Entry 774
+    -0x1.b3df386f18224a6403e55c16b36ef17fp-1,
+    0x1.37d9e563f51ffp1
+  },
+  { // Entry 775
+    0x1.b3df386f18224a6403e55c16b36ef17fp-1,
+    -0x1.37d9e563f51ffp1
+  },
+  { // Entry 776
+    -0x1.7e1d936f4d60f1e6f88b4a24df9c65f4p-1,
+    0x1.400ec9be2abbcp1
+  },
+  { // Entry 777
+    0x1.7e1d936f4d60f1e6f88b4a24df9c65f4p-1,
+    -0x1.400ec9be2abbcp1
+  },
+  { // Entry 778
+    -0x1.4d466accad48574188835130e68e9badp-1,
+    0x1.4843ae1860579p1
+  },
+  { // Entry 779
+    0x1.4d466accad48574188835130e68e9badp-1,
+    -0x1.4843ae1860579p1
+  },
+  { // Entry 780
+    -0x1.205a6009d5e33774fa98f9f616acc80fp-1,
+    0x1.5078927295f36p1
+  },
+  { // Entry 781
+    0x1.205a6009d5e33774fa98f9f616acc80fp-1,
+    -0x1.5078927295f36p1
+  },
+  { // Entry 782
+    -0x1.ed21e59972aef64a06e553f18d646093p-2,
+    0x1.58ad76cccb8f3p1
+  },
+  { // Entry 783
+    0x1.ed21e59972aef64a06e553f18d646093p-2,
+    -0x1.58ad76cccb8f3p1
+  },
+  { // Entry 784
+    -0x1.9e9257e6b6284f73cd1e2eae3220f313p-2,
+    0x1.60e25b27012b0p1
+  },
+  { // Entry 785
+    0x1.9e9257e6b6284f73cd1e2eae3220f313p-2,
+    -0x1.60e25b27012b0p1
+  },
+  { // Entry 786
+    -0x1.53fdcdfd37ee55bc1cd1604b6ab13b5fp-2,
+    0x1.69173f8136c6dp1
+  },
+  { // Entry 787
+    0x1.53fdcdfd37ee55bc1cd1604b6ab13b5fp-2,
+    -0x1.69173f8136c6dp1
+  },
+  { // Entry 788
+    -0x1.0c864083d1e5aaa6815a85e25c662e97p-2,
+    0x1.714c23db6c62ap1
+  },
+  { // Entry 789
+    0x1.0c864083d1e5aaa6815a85e25c662e97p-2,
+    -0x1.714c23db6c62ap1
+  },
+  { // Entry 790
+    -0x1.8ed9142fc913f450dccdbdd27ed11a40p-3,
+    0x1.79810835a1fe7p1
+  },
+  { // Entry 791
+    0x1.8ed9142fc913f450dccdbdd27ed11a40p-3,
+    -0x1.79810835a1fe7p1
+  },
+  { // Entry 792
+    -0x1.080f73b0704cf570818a65d1a12d5be1p-3,
+    0x1.81b5ec8fd79a4p1
+  },
+  { // Entry 793
+    0x1.080f73b0704cf570818a65d1a12d5be1p-3,
+    -0x1.81b5ec8fd79a4p1
+  },
+  { // Entry 794
+    -0x1.06f8d014bf09ab85f2a19d80da5a2c0bp-4,
+    0x1.89ead0ea0d35bp1
+  },
+  { // Entry 795
+    0x1.06f8d014bf09ab85f2a19d80da5a2c0bp-4,
+    -0x1.89ead0ea0d35bp1
+  },
+  { // Entry 796
+    0x1.0c864083d1e7f3955b12071e0644418bp-2,
+    -0x1.81b5ec8fd799fp2
+  },
+  { // Entry 797
+    -0x1.0c864083d1e7f3955b12071e0644418bp-2,
+    0x1.81b5ec8fd799fp2
+  },
+  { // Entry 798
+    0x1.205a6009d5e3f74da3a372ac15721ef6p-1,
+    -0x1.714c23db6c626p2
+  },
+  { // Entry 799
+    -0x1.205a6009d5e3f74da3a372ac15721ef6p-1,
+    0x1.714c23db6c626p2
+  },
+  { // Entry 800
+    0x1.efd82742d778e6f04adefc3d21f8be96p-1,
+    -0x1.60e25b27012adp2
+  },
+  { // Entry 801
+    -0x1.efd82742d778e6f04adefc3d21f8be96p-1,
+    0x1.60e25b27012adp2
+  },
+  { // Entry 802
+    0x1.a64c7c9d653468fbc5260dca501ddb81p0,
+    -0x1.5078927295f34p2
+  },
+  { // Entry 803
+    -0x1.a64c7c9d653468fbc5260dca501ddb81p0,
+    0x1.5078927295f34p2
+  },
+  { // Entry 804
+    0x1.af4643e9371f9316d3254b8619eda484p1,
+    -0x1.400ec9be2abbbp2
+  },
+  { // Entry 805
+    -0x1.af4643e9371f9316d3254b8619eda484p1,
+    0x1.400ec9be2abbbp2
+  },
+  { // Entry 806
+    0x1.f2f05cfb656a9e4a085b027d18603230p4,
+    -0x1.2fa50109bf842p2
+  },
+  { // Entry 807
+    -0x1.f2f05cfb656a9e4a085b027d18603230p4,
+    0x1.2fa50109bf842p2
+  },
+  { // Entry 808
+    -0x1.1866fe845e7755392a0adff56a688eaap2,
+    -0x1.1f3b3855544c9p2
+  },
+  { // Entry 809
+    0x1.1866fe845e7755392a0adff56a688eaap2,
+    0x1.1f3b3855544c9p2
+  },
+  { // Entry 810
+    -0x1.eab43e0e5e8959e8f5ac6c4f9d9a833bp0,
+    -0x1.0ed16fa0e9150p2
+  },
+  { // Entry 811
+    0x1.eab43e0e5e8959e8f5ac6c4f9d9a833bp0,
+    0x1.0ed16fa0e9150p2
+  },
+  { // Entry 812
+    -0x1.19e26b5ecd5cd69c30c3dc5d9ffde986p0,
+    -0x1.fccf4dd8fbbaep1
+  },
+  { // Entry 813
+    0x1.19e26b5ecd5cd69c30c3dc5d9ffde986p0,
+    0x1.fccf4dd8fbbaep1
+  },
+  { // Entry 814
+    -0x1.4d466accad49ec96935caa2a35e439f0p-1,
+    -0x1.dbfbbc70254bcp1
+  },
+  { // Entry 815
+    0x1.4d466accad49ec96935caa2a35e439f0p-1,
+    0x1.dbfbbc70254bcp1
+  },
+  { // Entry 816
+    -0x1.53fdcdfd37f1ea216e815758ed02a557p-2,
+    -0x1.bb282b074edcap1
+  },
+  { // Entry 817
+    0x1.53fdcdfd37f1ea216e815758ed02a557p-2,
+    0x1.bb282b074edcap1
+  },
+  { // Entry 818
+    -0x1.06f8d014bf0e964e634f37bcdbf64491p-4,
+    -0x1.9a54999e786d8p1
+  },
+  { // Entry 819
+    0x1.06f8d014bf0e964e634f37bcdbf64491p-4,
+    0x1.9a54999e786d8p1
+  },
+  { // Entry 820
+    0x1.8ed9142fc914fe067b991d11d70859b8p-3,
+    -0x1.79810835a1fe6p1
+  },
+  { // Entry 821
+    -0x1.8ed9142fc914fe067b991d11d70859b8p-3,
+    0x1.79810835a1fe6p1
+  },
+  { // Entry 822
+    0x1.ed21e59972ae589aaa4ee3d80c3b7defp-2,
+    -0x1.58ad76cccb8f4p1
+  },
+  { // Entry 823
+    -0x1.ed21e59972ae589aaa4ee3d80c3b7defp-2,
+    0x1.58ad76cccb8f4p1
+  },
+  { // Entry 824
+    0x1.b3df386f1820ff3df290f036db46f13bp-1,
+    -0x1.37d9e563f5202p1
+  },
+  { // Entry 825
+    -0x1.b3df386f1820ff3df290f036db46f13bp-1,
+    0x1.37d9e563f5202p1
+  },
+  { // Entry 826
+    0x1.6efec8c1e492616fe2fec0b764fa6eb4p0,
+    -0x1.170653fb1eb10p1
+  },
+  { // Entry 827
+    -0x1.6efec8c1e492616fe2fec0b764fa6eb4p0,
+    0x1.170653fb1eb10p1
+  },
+  { // Entry 828
+    0x1.5bd13dda077ada91927ab73cedaa828dp1,
+    -0x1.ec6585249083cp0
+  },
+  { // Entry 829
+    -0x1.5bd13dda077ada91927ab73cedaa828dp1,
+    0x1.ec6585249083cp0
+  },
+  { // Entry 830
+    0x1.4bb6a64e061f69cf7409931383cc80a1p3,
+    -0x1.aabe6252e3a58p0
+  },
+  { // Entry 831
+    -0x1.4bb6a64e061f69cf7409931383cc80a1p3,
+    0x1.aabe6252e3a58p0
+  },
+  { // Entry 832
+    -0x1.8bdcd54bd5a004acf922c49a8d5e28a2p2,
+    -0x1.69173f8136c74p0
+  },
+  { // Entry 833
+    0x1.8bdcd54bd5a004acf922c49a8d5e28a2p2,
+    0x1.69173f8136c74p0
+  },
+  { // Entry 834
+    -0x1.21277b97c015f19de7b238252e56e63fp1,
+    -0x1.27701caf89e90p0
+  },
+  { // Entry 835
+    0x1.21277b97c015f19de7b238252e56e63fp1,
+    0x1.27701caf89e90p0
+  },
+  { // Entry 836
+    -0x1.41038b70be11b85798a271ac3d209ea7p0,
+    -0x1.cb91f3bbba157p-1
+  },
+  { // Entry 837
+    0x1.41038b70be11b85798a271ac3d209ea7p0,
+    0x1.cb91f3bbba157p-1
+  },
+  { // Entry 838
+    -0x1.7e1d936f4d63c1c7806657d8b838836ep-1,
+    -0x1.4843ae186058ep-1
+  },
+  { // Entry 839
+    0x1.7e1d936f4d63c1c7806657d8b838836ep-1,
+    0x1.4843ae186058ep-1
+  },
+  { // Entry 840
+    -0x1.9e9257e6b62d886f74e348bdc142599cp-2,
+    -0x1.89ead0ea0d38ap-2
+  },
+  { // Entry 841
+    0x1.9e9257e6b62d886f74e348bdc142599cp-2,
+    0x1.89ead0ea0d38ap-2
+  },
+  { // Entry 842
+    -0x1.080f73b07057dc7bf0df6de1d3ae1a3bp-3,
+    -0x1.069c8b46b37f0p-3
+  },
+  { // Entry 843
+    0x1.080f73b07057dc7bf0df6de1d3ae1a3bp-3,
+    0x1.069c8b46b37f0p-3
+  },
+  { // Entry 844
+    0x1.080f73b0704bea7a56d4f88ecf3d5cd3p-3,
+    0x1.069c8b46b3734p-3
+  },
+  { // Entry 845
+    -0x1.080f73b0704bea7a56d4f88ecf3d5cd3p-3,
+    -0x1.069c8b46b3734p-3
+  },
+  { // Entry 846
+    0x1.9e9257e6b626b1eb1136bd7853311543p-2,
+    0x1.89ead0ea0d32cp-2
+  },
+  { // Entry 847
+    -0x1.9e9257e6b626b1eb1136bd7853311543p-2,
+    -0x1.89ead0ea0d32cp-2
+  },
+  { // Entry 848
+    0x1.7e1d936f4d5f2eebbbf3d62963106afap-1,
+    0x1.4843ae186055fp-1
+  },
+  { // Entry 849
+    -0x1.7e1d936f4d5f2eebbbf3d62963106afap-1,
+    -0x1.4843ae186055fp-1
+  },
+  { // Entry 850
+    0x1.41038b70be0df11d1224683c6f865584p0,
+    0x1.cb91f3bbba128p-1
+  },
+  { // Entry 851
+    -0x1.41038b70be0df11d1224683c6f865584p0,
+    -0x1.cb91f3bbba128p-1
+  },
+  { // Entry 852
+    0x1.21277b97c0115dcf6647ad68f4cb4ad0p1,
+    0x1.27701caf89e78p0
+  },
+  { // Entry 853
+    -0x1.21277b97c0115dcf6647ad68f4cb4ad0p1,
+    -0x1.27701caf89e78p0
+  },
+  { // Entry 854
+    0x1.8bdcd54bd5914bd9a4d6dd659c2f6606p2,
+    0x1.69173f8136c5cp0
+  },
+  { // Entry 855
+    -0x1.8bdcd54bd5914bd9a4d6dd659c2f6606p2,
+    -0x1.69173f8136c5cp0
+  },
+  { // Entry 856
+    -0x1.4bb6a64e0633bfa56879660655c38767p3,
+    0x1.aabe6252e3a40p0
+  },
+  { // Entry 857
+    0x1.4bb6a64e0633bfa56879660655c38767p3,
+    -0x1.aabe6252e3a40p0
+  },
+  { // Entry 858
+    -0x1.5bd13dda078124444c940f013be7c402p1,
+    0x1.ec65852490824p0
+  },
+  { // Entry 859
+    0x1.5bd13dda078124444c940f013be7c402p1,
+    -0x1.ec65852490824p0
+  },
+  { // Entry 860
+    -0x1.6efec8c1e496f69c286adc66bd586eafp0,
+    0x1.170653fb1eb04p1
+  },
+  { // Entry 861
+    0x1.6efec8c1e496f69c286adc66bd586eafp0,
+    -0x1.170653fb1eb04p1
+  },
+  { // Entry 862
+    -0x1.b3df386f18262bd637e29fbb30806b2cp-1,
+    0x1.37d9e563f51f6p1
+  },
+  { // Entry 863
+    0x1.b3df386f18262bd637e29fbb30806b2cp-1,
+    -0x1.37d9e563f51f6p1
+  },
+  { // Entry 864
+    -0x1.ed21e59972b5bcd3015c250eff1c69b9p-2,
+    0x1.58ad76cccb8e8p1
+  },
+  { // Entry 865
+    0x1.ed21e59972b5bcd3015c250eff1c69b9p-2,
+    -0x1.58ad76cccb8e8p1
+  },
+  { // Entry 866
+    -0x1.8ed9142fc9217289ed21940deaafe878p-3,
+    0x1.79810835a1fdap1
+  },
+  { // Entry 867
+    0x1.8ed9142fc9217289ed21940deaafe878p-3,
+    -0x1.79810835a1fdap1
+  },
+  { // Entry 868
+    0x1.06f8d014bef67cfb2db560f5a414c88bp-4,
+    0x1.9a54999e786ccp1
+  },
+  { // Entry 869
+    -0x1.06f8d014bef67cfb2db560f5a414c88bp-4,
+    -0x1.9a54999e786ccp1
+  },
+  { // Entry 870
+    0x1.53fdcdfd37eb40cd9e504df431b502d0p-2,
+    0x1.bb282b074edbep1
+  },
+  { // Entry 871
+    -0x1.53fdcdfd37eb40cd9e504df431b502d0p-2,
+    -0x1.bb282b074edbep1
+  },
+  { // Entry 872
+    0x1.4d466accad45a72e5f735eb2f6adf9ffp-1,
+    0x1.dbfbbc70254b0p1
+  },
+  { // Entry 873
+    -0x1.4d466accad45a72e5f735eb2f6adf9ffp-1,
+    -0x1.dbfbbc70254b0p1
+  },
+  { // Entry 874
+    0x1.19e26b5ecd598507ecd00d81ec775683p0,
+    0x1.fccf4dd8fbba2p1
+  },
+  { // Entry 875
+    -0x1.19e26b5ecd598507ecd00d81ec775683p0,
+    -0x1.fccf4dd8fbba2p1
+  },
+  { // Entry 876
+    0x1.eab43e0e5e8257073afaecab386154a1p0,
+    0x1.0ed16fa0e914ap2
+  },
+  { // Entry 877
+    -0x1.eab43e0e5e8257073afaecab386154a1p0,
+    -0x1.0ed16fa0e914ap2
+  },
+  { // Entry 878
+    0x1.1866fe845e6fc27064e2b123a7724e75p2,
+    0x1.1f3b3855544c3p2
+  },
+  { // Entry 879
+    -0x1.1866fe845e6fc27064e2b123a7724e75p2,
+    -0x1.1f3b3855544c3p2
+  },
+  { // Entry 880
+    -0x1.f2f05cfb65c5e06b1ae88c48b4b755cep4,
+    0x1.2fa50109bf83cp2
+  },
+  { // Entry 881
+    0x1.f2f05cfb65c5e06b1ae88c48b4b755cep4,
+    -0x1.2fa50109bf83cp2
+  },
+  { // Entry 882
+    -0x1.af4643e93728d6bfd702c33405dcce7dp1,
+    0x1.400ec9be2abb5p2
+  },
+  { // Entry 883
+    0x1.af4643e93728d6bfd702c33405dcce7dp1,
+    -0x1.400ec9be2abb5p2
+  },
+  { // Entry 884
+    -0x1.a64c7c9d6539fdec27afc380b9f752c0p0,
+    0x1.5078927295f2ep2
+  },
+  { // Entry 885
+    0x1.a64c7c9d6539fdec27afc380b9f752c0p0,
+    -0x1.5078927295f2ep2
+  },
+  { // Entry 886
+    -0x1.efd82742d77eb73c81a00f568621f63cp-1,
+    0x1.60e25b27012a7p2
+  },
+  { // Entry 887
+    0x1.efd82742d77eb73c81a00f568621f63cp-1,
+    -0x1.60e25b27012a7p2
+  },
+  { // Entry 888
+    -0x1.205a6009d5e7eae63da1cbd57129eeffp-1,
+    0x1.714c23db6c620p2
+  },
+  { // Entry 889
+    0x1.205a6009d5e7eae63da1cbd57129eeffp-1,
+    -0x1.714c23db6c620p2
+  },
+  { // Entry 890
+    -0x1.0c864083d1ee5d34de2060c8629d4951p-2,
+    0x1.81b5ec8fd7999p2
+  },
+  { // Entry 891
+    0x1.0c864083d1ee5d34de2060c8629d4951p-2,
+    -0x1.81b5ec8fd7999p2
+  },
+  { // Entry 892
+    0x1.f09b63aa81fc36da509c3e410607ffe7p-5,
+    0x1.effffffffffffp-5
+  },
+  { // Entry 893
+    -0x1.f09b63aa81fc36da509c3e410607ffe7p-5,
+    -0x1.effffffffffffp-5
+  },
+  { // Entry 894
+    0x1.f09b63aa81fc46e95e06405b41e8b4ccp-5,
+    0x1.fp-5
+  },
+  { // Entry 895
+    -0x1.f09b63aa81fc46e95e06405b41e8b4ccp-5,
+    -0x1.fp-5
+  },
+  { // Entry 896
+    0x1.f09b63aa81fc56f86b7042757dca62e8p-5,
+    0x1.f000000000001p-5
+  },
+  { // Entry 897
+    -0x1.f09b63aa81fc56f86b7042757dca62e8p-5,
+    -0x1.f000000000001p-5
+  },
+  { // Entry 898
+    0x1.fa8f21c8a33aecf4af77754ef90a67b8p-4,
+    0x1.f7fffffffffffp-4
+  },
+  { // Entry 899
+    -0x1.fa8f21c8a33aecf4af77754ef90a67b8p-4,
+    -0x1.f7fffffffffffp-4
+  },
+  { // Entry 900
+    0x1.fa8f21c8a33afd3355198e8d7716a811p-4,
+    0x1.f80p-4
+  },
+  { // Entry 901
+    -0x1.fa8f21c8a33afd3355198e8d7716a811p-4,
+    -0x1.f80p-4
+  },
+  { // Entry 902
+    0x1.fa8f21c8a33b0d71fabba7cbf526ed07p-4,
+    0x1.f800000000001p-4
+  },
+  { // Entry 903
+    -0x1.fa8f21c8a33b0d71fabba7cbf526ed07p-4,
+    -0x1.f800000000001p-4
+  },
+  { // Entry 904
+    0x1.4ef06cb4f0a869ef00df8ec5582dfa31p-3,
+    0x1.4bfffffffffffp-3
+  },
+  { // Entry 905
+    -0x1.4ef06cb4f0a869ef00df8ec5582dfa31p-3,
+    -0x1.4bfffffffffffp-3
+  },
+  { // Entry 906
+    0x1.4ef06cb4f0a87a5c8eeeebceb12a22b4p-3,
+    0x1.4c0p-3
+  },
+  { // Entry 907
+    -0x1.4ef06cb4f0a87a5c8eeeebceb12a22b4p-3,
+    -0x1.4c0p-3
+  },
+  { // Entry 908
+    0x1.4ef06cb4f0a88aca1cfe48d80a310a65p-3,
+    0x1.4c00000000001p-3
+  },
+  { // Entry 909
+    -0x1.4ef06cb4f0a88aca1cfe48d80a310a65p-3,
+    -0x1.4c00000000001p-3
+  },
+  { // Entry 910
+    0x1.3cc2a44e2999668cb092a09b73b2de50p-2,
+    0x1.3333333333332p-2
+  },
+  { // Entry 911
+    -0x1.3cc2a44e2999668cb092a09b73b2de50p-2,
+    -0x1.3333333333332p-2
+  },
+  { // Entry 912
+    0x1.3cc2a44e29997814a1ac3f0211c7641fp-2,
+    0x1.3333333333333p-2
+  },
+  { // Entry 913
+    -0x1.3cc2a44e29997814a1ac3f0211c7641fp-2,
+    -0x1.3333333333333p-2
+  },
+  { // Entry 914
+    0x1.3cc2a44e2999899c92c5dd68b0074c31p-2,
+    0x1.3333333333334p-2
+  },
+  { // Entry 915
+    -0x1.3cc2a44e2999899c92c5dd68b0074c31p-2,
+    -0x1.3333333333334p-2
+  },
+  { // Entry 916
+    0x1.9943711dc2ce83d21cdb285aced817adp-1,
+    0x1.594317acc4ef8p-1
+  },
+  { // Entry 917
+    -0x1.9943711dc2ce83d21cdb285aced817adp-1,
+    -0x1.594317acc4ef8p-1
+  },
+  { // Entry 918
+    0x1.9943711dc2ce9e0b3f1ffe5aec0ac20dp-1,
+    0x1.594317acc4ef9p-1
+  },
+  { // Entry 919
+    -0x1.9943711dc2ce9e0b3f1ffe5aec0ac20dp-1,
+    -0x1.594317acc4ef9p-1
+  },
+  { // Entry 920
+    0x1.9943711dc2ceb8446164d45b0a8ccdeep-1,
+    0x1.594317acc4efap-1
+  },
+  { // Entry 921
+    -0x1.9943711dc2ceb8446164d45b0a8ccdeep-1,
+    -0x1.594317acc4efap-1
+  },
+  { // Entry 922
+    0x1.fbc511df5917d57d231d7ad434da5f94p-1,
+    0x1.8ffffffffffffp-1
+  },
+  { // Entry 923
+    -0x1.fbc511df5917d57d231d7ad434da5f94p-1,
+    -0x1.8ffffffffffffp-1
+  },
+  { // Entry 924
+    0x1.fbc511df5917f539bbcf778bc1a22249p-1,
+    0x1.9p-1
+  },
+  { // Entry 925
+    -0x1.fbc511df5917f539bbcf778bc1a22249p-1,
+    -0x1.9p-1
+  },
+  { // Entry 926
+    0x1.fbc511df591814f65481744350617c85p-1,
+    0x1.9000000000001p-1
+  },
+  { // Entry 927
+    -0x1.fbc511df591814f65481744350617c85p-1,
+    -0x1.9000000000001p-1
+  },
+  { // Entry 928
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 929
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 930
+    -0.0,
+    -0.0
+  },
+  { // Entry 931
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 932
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 933
+    0x1.927278a3b1160bbf8e0bb309da4247c5p-5,
+    0x1.921fb54442d17p-5
+  },
+  { // Entry 934
+    -0x1.927278a3b1160bbf8e0bb309da4247c5p-5,
+    -0x1.921fb54442d17p-5
+  },
+  { // Entry 935
+    0x1.927278a3b1161bc970ba8b50e575f97fp-5,
+    0x1.921fb54442d18p-5
+  },
+  { // Entry 936
+    -0x1.927278a3b1161bc970ba8b50e575f97fp-5,
+    -0x1.921fb54442d18p-5
+  },
+  { // Entry 937
+    0x1.927278a3b1162bd353696397f0aa74eep-5,
+    0x1.921fb54442d19p-5
+  },
+  { // Entry 938
+    -0x1.927278a3b1162bd353696397f0aa74eep-5,
+    -0x1.921fb54442d19p-5
+  },
+  { // Entry 939
+    0x1.936bb8c5b2da118306fa9b5d6d8ed2c1p-4,
+    0x1.921fb54442d17p-4
+  },
+  { // Entry 940
+    -0x1.936bb8c5b2da118306fa9b5d6d8ed2c1p-4,
+    -0x1.921fb54442d17p-4
+  },
+  { // Entry 941
+    0x1.936bb8c5b2da21aac2bfec84293e5d4dp-4,
+    0x1.921fb54442d18p-4
+  },
+  { // Entry 942
+    -0x1.936bb8c5b2da21aac2bfec84293e5d4dp-4,
+    -0x1.921fb54442d18p-4
+  },
+  { // Entry 943
+    0x1.936bb8c5b2da31d27e853daae4f11684p-4,
+    0x1.921fb54442d19p-4
+  },
+  { // Entry 944
+    -0x1.936bb8c5b2da31d27e853daae4f11684p-4,
+    -0x1.921fb54442d19p-4
+  },
+  { // Entry 945
+    0x1.975f5e0553156b438ca7d752d37d0873p-3,
+    0x1.921fb54442d17p-3
+  },
+  { // Entry 946
+    -0x1.975f5e0553156b438ca7d752d37d0873p-3,
+    -0x1.921fb54442d17p-3
+  },
+  { // Entry 947
+    0x1.975f5e0553157be59cbff648fdef2c08p-3,
+    0x1.921fb54442d18p-3
+  },
+  { // Entry 948
+    -0x1.975f5e0553157be59cbff648fdef2c08p-3,
+    -0x1.921fb54442d18p-3
+  },
+  { // Entry 949
+    0x1.975f5e0553158c87acd8153f286e8b8ap-3,
+    0x1.921fb54442d19p-3
+  },
+  { // Entry 950
+    -0x1.975f5e0553158c87acd8153f286e8b8ap-3,
+    -0x1.921fb54442d19p-3
+  },
+  { // Entry 951
+    0x1.a827999fcef30c38b2e5397ea7c10eadp-2,
+    0x1.921fb54442d17p-2
+  },
+  { // Entry 952
+    -0x1.a827999fcef30c38b2e5397ea7c10eadp-2,
+    -0x1.921fb54442d17p-2
+  },
+  { // Entry 953
+    0x1.a827999fcef31ef776183b070e6fc84ep-2,
+    0x1.921fb54442d18p-2
+  },
+  { // Entry 954
+    -0x1.a827999fcef31ef776183b070e6fc84ep-2,
+    -0x1.921fb54442d18p-2
+  },
+  { // Entry 955
+    0x1.a827999fcef331b6394b3c8f755c9fa3p-2,
+    0x1.921fb54442d19p-2
+  },
+  { // Entry 956
+    -0x1.a827999fcef331b6394b3c8f755c9fa3p-2,
+    -0x1.921fb54442d19p-2
+  },
+  { // Entry 957
+    0x1.ffffffffffffd72cece675d1fe3035bbp-1,
+    0x1.921fb54442d17p-1
+  },
+  { // Entry 958
+    -0x1.ffffffffffffd72cece675d1fe3035bbp-1,
+    -0x1.921fb54442d17p-1
+  },
+  { // Entry 959
+    0x1.fffffffffffff72cece675d1fca30489p-1,
+    0x1.921fb54442d18p-1
+  },
+  { // Entry 960
+    -0x1.fffffffffffff72cece675d1fca30489p-1,
+    -0x1.921fb54442d18p-1
+  },
+  { // Entry 961
+    0x1.0000000000000b9676733ae8fe8ae9acp0,
+    0x1.921fb54442d19p-1
+  },
+  { // Entry 962
+    -0x1.0000000000000b9676733ae8fe8ae9acp0,
+    -0x1.921fb54442d19p-1
+  },
+  { // Entry 963
+    0x1.9153d9443ed0b3b43ddab6ae573aa23dp51,
+    0x1.921fb54442d17p0
+  },
+  { // Entry 964
+    -0x1.9153d9443ed0b3b43ddab6ae573aa23dp51,
+    -0x1.921fb54442d17p0
+  },
+  { // Entry 965
+    0x1.d02967c31cdb4e0c38d01b655d5e0aafp53,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 966
+    -0x1.d02967c31cdb4e0c38d01b655d5e0aafp53,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 967
+    -0x1.617a15494767a04882c320317f3e4cecp52,
+    0x1.921fb54442d19p0
+  },
+  { // Entry 968
+    0x1.617a15494767a04882c320317f3e4cecp52,
+    -0x1.921fb54442d19p0
+  },
+  { // Entry 969
+    -0x1.469898cc51701b839a252049c3d60c68p-51,
+    0x1.921fb54442d17p1
+  },
+  { // Entry 970
+    0x1.469898cc51701b839a252049c3d60c68p-51,
+    -0x1.921fb54442d17p1
+  },
+  { // Entry 971
+    -0x1.1a62633145c06e0e689481270461d5d7p-53,
+    0x1.921fb54442d18p1
+  },
+  { // Entry 972
+    0x1.1a62633145c06e0e689481270461d5d7p-53,
+    -0x1.921fb54442d18p1
+  },
+  { // Entry 973
+    0x1.72cece675d1fc8f8cbb5bf6c7ee0b96cp-52,
+    0x1.921fb54442d19p1
+  },
+  { // Entry 974
+    -0x1.72cece675d1fc8f8cbb5bf6c7ee0b96cp-52,
+    -0x1.921fb54442d19p1
+  },
+  { // Entry 975
+    -0x1.469898cc51701b839a252049cc244ab5p-50,
+    0x1.921fb54442d17p2
+  },
+  { // Entry 976
+    0x1.469898cc51701b839a252049cc244ab5p-50,
+    -0x1.921fb54442d17p2
+  },
+  { // Entry 977
+    -0x1.1a62633145c06e0e6894812704b7bbabp-52,
+    0x1.921fb54442d18p2
+  },
+  { // Entry 978
+    0x1.1a62633145c06e0e6894812704b7bbabp-52,
+    -0x1.921fb54442d18p2
+  },
+  { // Entry 979
+    0x1.72cece675d1fc8f8cbb5bf6c81eab38cp-51,
+    0x1.921fb54442d19p2
+  },
+  { // Entry 980
+    -0x1.72cece675d1fc8f8cbb5bf6c81eab38cp-51,
+    -0x1.921fb54442d19p2
+  },
+  { // Entry 981
+    -0x1.469898cc51701b839a252049ed5d43e8p-49,
+    0x1.921fb54442d17p3
+  },
+  { // Entry 982
+    0x1.469898cc51701b839a252049ed5d43e8p-49,
+    -0x1.921fb54442d17p3
+  },
+  { // Entry 983
+    -0x1.1a62633145c06e0e68948127060f52f9p-51,
+    0x1.921fb54442d18p3
+  },
+  { // Entry 984
+    0x1.1a62633145c06e0e68948127060f52f9p-51,
+    -0x1.921fb54442d18p3
+  },
+  { // Entry 985
+    0x1.72cece675d1fc8f8cbb5bf6c8e129c0ap-50,
+    0x1.921fb54442d19p3
+  },
+  { // Entry 986
+    -0x1.72cece675d1fc8f8cbb5bf6c8e129c0ap-50,
+    -0x1.921fb54442d19p3
+  },
+  { // Entry 987
+    -0x1.469898cc51701b839a25204a724128b4p-48,
+    0x1.921fb54442d17p4
+  },
+  { // Entry 988
+    0x1.469898cc51701b839a25204a724128b4p-48,
+    -0x1.921fb54442d17p4
+  },
+  { // Entry 989
+    -0x1.1a62633145c06e0e689481270b6db033p-50,
+    0x1.921fb54442d18p4
+  },
+  { // Entry 990
+    0x1.1a62633145c06e0e689481270b6db033p-50,
+    -0x1.921fb54442d18p4
+  },
+  { // Entry 991
+    0x1.72cece675d1fc8f8cbb5bf6cbeb23e03p-49,
+    0x1.921fb54442d19p4
+  },
+  { // Entry 992
+    -0x1.72cece675d1fc8f8cbb5bf6cbeb23e03p-49,
+    -0x1.921fb54442d19p4
+  },
+  { // Entry 993
+    -0x1.469898cc51701b839a25204c85d0bbe3p-47,
+    0x1.921fb54442d17p5
+  },
+  { // Entry 994
+    0x1.469898cc51701b839a25204c85d0bbe3p-47,
+    -0x1.921fb54442d17p5
+  },
+  { // Entry 995
+    -0x1.1a62633145c06e0e6894812720e7251ap-49,
+    0x1.921fb54442d18p5
+  },
+  { // Entry 996
+    0x1.1a62633145c06e0e6894812720e7251ap-49,
+    -0x1.921fb54442d18p5
+  },
+  { // Entry 997
+    0x1.72cece675d1fc8f8cbb5bf6d8130c5e7p-48,
+    0x1.921fb54442d19p5
+  },
+  { // Entry 998
+    -0x1.72cece675d1fc8f8cbb5bf6d8130c5e7p-48,
+    -0x1.921fb54442d19p5
+  },
+  { // Entry 999
+    -0x1.469898cc51701b839a252054d40f08a0p-46,
+    0x1.921fb54442d17p6
+  },
+  { // Entry 1000
+    0x1.469898cc51701b839a252054d40f08a0p-46,
+    -0x1.921fb54442d17p6
+  },
+  { // Entry 1001
+    -0x1.1a62633145c06e0e6894812776ccf8b7p-48,
+    0x1.921fb54442d18p6
+  },
+  { // Entry 1002
+    0x1.1a62633145c06e0e6894812776ccf8b7p-48,
+    -0x1.921fb54442d18p6
+  },
+  { // Entry 1003
+    0x1.72cece675d1fc8f8cbb5bf708b2ae576p-47,
+    0x1.921fb54442d19p6
+  },
+  { // Entry 1004
+    -0x1.72cece675d1fc8f8cbb5bf708b2ae576p-47,
+    -0x1.921fb54442d19p6
+  },
+  { // Entry 1005
+    -0x1.469898cc51701b839a2520760d083b97p-45,
+    0x1.921fb54442d17p7
+  },
+  { // Entry 1006
+    0x1.469898cc51701b839a2520760d083b97p-45,
+    -0x1.921fb54442d17p7
+  },
+  { // Entry 1007
+    -0x1.1a62633145c06e0e68948128ce64472bp-47,
+    0x1.921fb54442d18p7
+  },
+  { // Entry 1008
+    0x1.1a62633145c06e0e68948128ce64472bp-47,
+    -0x1.921fb54442d18p7
+  },
+  { // Entry 1009
+    0x1.72cece675d1fc8f8cbb5bf7cb31363b1p-46,
+    0x1.921fb54442d19p7
+  },
+  { // Entry 1010
+    -0x1.72cece675d1fc8f8cbb5bf7cb31363b1p-46,
+    -0x1.921fb54442d19p7
+  },
+  { // Entry 1011
+    -0x1.0000000000004d3c9ca64f4510cf6f31p0,
+    0x1.2d97c7f3321d1p1
+  },
+  { // Entry 1012
+    0x1.0000000000004d3c9ca64f4510cf6f31p0,
+    -0x1.2d97c7f3321d1p1
+  },
+  { // Entry 1013
+    -0x1.0000000000000d3c9ca64f4505804808p0,
+    0x1.2d97c7f3321d2p1
+  },
+  { // Entry 1014
+    0x1.0000000000000d3c9ca64f4505804808p0,
+    -0x1.2d97c7f3321d2p1
+  },
+  { // Entry 1015
+    -0x1.ffffffffffff9a79394c9e8a146241bdp-1,
+    0x1.2d97c7f3321d3p1
+  },
+  { // Entry 1016
+    0x1.ffffffffffff9a79394c9e8a146241bdp-1,
+    -0x1.2d97c7f3321d3p1
+  },
+  { // Entry 1017
+    0x1.ffffffffffff53e0a0804d1a0bbc4ab3p-1,
+    0x1.f6a7a2955385dp1
+  },
+  { // Entry 1018
+    -0x1.ffffffffffff53e0a0804d1a0bbc4ab3p-1,
+    -0x1.f6a7a2955385dp1
+  },
+  { // Entry 1019
+    0x1.ffffffffffffd3e0a0804d19f0b472d3p-1,
+    0x1.f6a7a2955385ep1
+  },
+  { // Entry 1020
+    -0x1.ffffffffffffd3e0a0804d19f0b472d3p-1,
+    -0x1.f6a7a2955385ep1
+  },
+  { // Entry 1021
+    0x1.00000000000029f05040268cfad64d79p0,
+    0x1.f6a7a2955385fp1
+  },
+  { // Entry 1022
+    -0x1.00000000000029f05040268cfad64d79p0,
+    -0x1.f6a7a2955385fp1
+  },
+  { // Entry 1023
+    0x1.a8410087262e3f41859fa73567f9244dp49,
+    0x1.2d97c7f3321d1p2
+  },
+  { // Entry 1024
+    -0x1.a8410087262e3f41859fa73567f9244dp49,
+    -0x1.2d97c7f3321d1p2
+  },
+  { // Entry 1025
+    0x1.3570efd76892340825e0124393554697p52,
+    0x1.2d97c7f3321d2p2
+  },
+  { // Entry 1026
+    -0x1.3570efd76892340825e0124393554697p52,
+    -0x1.2d97c7f3321d2p2
+  },
+  { // Entry 1027
+    -0x1.42c0d64d5de5178afe06452a1a1b8667p50,
+    0x1.2d97c7f3321d3p2
+  },
+  { // Entry 1028
+    0x1.42c0d64d5de5178afe06452a1a1b8667p50,
+    -0x1.2d97c7f3321d3p2
+  },
+  { // Entry 1029
+    -0x1.0000000000009ee2c2d963a13d57ec20p0,
+    0x1.5fdbbe9bba774p2
+  },
+  { // Entry 1030
+    0x1.0000000000009ee2c2d963a13d57ec20p0,
+    -0x1.5fdbbe9bba774p2
+  },
+  { // Entry 1031
+    -0x1.0000000000001ee2c2d963a10de68ab4p0,
+    0x1.5fdbbe9bba775p2
+  },
+  { // Entry 1032
+    0x1.0000000000001ee2c2d963a10de68ab4p0,
+    -0x1.5fdbbe9bba775p2
+  },
+  { // Entry 1033
+    -0x1.ffffffffffff3dc585b2c7423cea528ep-1,
+    0x1.5fdbbe9bba776p2
+  },
+  { // Entry 1034
+    0x1.ffffffffffff3dc585b2c7423cea528ep-1,
+    -0x1.5fdbbe9bba776p2
+  },
+  { // Entry 1035
+    0x1.fffffffffffeb094541a24624eeab0e1p-1,
+    0x1.c463abeccb2bap2
+  },
+  { // Entry 1036
+    -0x1.fffffffffffeb094541a24624eeab0e1p-1,
+    -0x1.c463abeccb2bap2
+  },
+  { // Entry 1037
+    0x1.ffffffffffffb094541a2461e734daeep-1,
+    0x1.c463abeccb2bbp2
+  },
+  { // Entry 1038
+    -0x1.ffffffffffffb094541a2461e734daeep-1,
+    -0x1.c463abeccb2bbp2
+  },
+  { // Entry 1039
+    0x1.000000000000584a2a0d1230ffbf827dp0,
+    0x1.c463abeccb2bcp2
+  },
+  { // Entry 1040
+    -0x1.000000000000584a2a0d1230ffbf827dp0,
+    -0x1.c463abeccb2bcp2
+  },
+  { // Entry 1041
+    0x1.7cc080f8958567f05c40ac5f6d310de8p49,
+    0x1.f6a7a2955385dp2
+  },
+  { // Entry 1042
+    -0x1.7cc080f8958567f05c40ac5f6d310de8p49,
+    -0x1.f6a7a2955385dp2
+  },
+  { // Entry 1043
+    0x1.735453027d7c3e702d73491de369536fp51,
+    0x1.f6a7a2955385ep2
+  },
+  { // Entry 1044
+    -0x1.735453027d7c3e702d73491de369536fp51,
+    -0x1.f6a7a2955385ep2
+  },
+  { // Entry 1045
+    -0x1.86aa4a3a127a3add9a8e76993733b4a7p50,
+    0x1.f6a7a2955385fp2
+  },
+  { // Entry 1046
+    0x1.86aa4a3a127a3add9a8e76993733b4a7p50,
+    -0x1.f6a7a2955385fp2
+  },
+  { // Entry 1047
+    -0x1.000000000001b088e90c77fe8051a7dap0,
+    0x1.1475cc9eedeffp3
+  },
+  { // Entry 1048
+    0x1.000000000001b088e90c77fe8051a7dap0,
+    -0x1.1475cc9eedeffp3
+  },
+  { // Entry 1049
+    -0x1.000000000000b088e90c77fd4fc8becep0,
+    0x1.1475cc9eedfp3
+  },
+  { // Entry 1050
+    0x1.000000000000b088e90c77fd4fc8becep0,
+    -0x1.1475cc9eedfp3
+  },
+  { // Entry 1051
+    -0x1.ffffffffffff6111d218effa3e7fab83p-1,
+    0x1.1475cc9eedf01p3
+  },
+  { // Entry 1052
+    0x1.ffffffffffff6111d218effa3e7fab83p-1,
+    -0x1.1475cc9eedf01p3
+  },
+  { // Entry 1053
+    -0x1.34f272993d1414a2b39bd837764c1608p-49,
+    0x1.2d97c7f3321d1p3
+  },
+  { // Entry 1054
+    0x1.34f272993d1414a2b39bd837764c1608p-49,
+    -0x1.2d97c7f3321d1p3
+  },
+  { // Entry 1055
+    -0x1.a79394c9e8a0a5159cdec1ba87ea5811p-52,
+    0x1.2d97c7f3321d2p3
+  },
+  { // Entry 1056
+    0x1.a79394c9e8a0a5159cdec1ba87ea5811p-52,
+    -0x1.2d97c7f3321d2p3
+  },
+  { // Entry 1057
+    0x1.961b1acd85d7d6ba98c84f9173b08d6fp-50,
+    0x1.2d97c7f3321d3p3
+  },
+  { // Entry 1058
+    -0x1.961b1acd85d7d6ba98c84f9173b08d6fp-50,
+    -0x1.2d97c7f3321d3p3
+  },
+  { // Entry 1059
+    0x1.fffffffffffc8d4807b3fbaccc38314bp-1,
+    0x1.46b9c347764a2p3
+  },
+  { // Entry 1060
+    -0x1.fffffffffffc8d4807b3fbaccc38314bp-1,
+    -0x1.46b9c347764a2p3
+  },
+  { // Entry 1061
+    0x1.fffffffffffe8d4807b3fbaa598038ffp-1,
+    0x1.46b9c347764a3p3
+  },
+  { // Entry 1062
+    -0x1.fffffffffffe8d4807b3fbaa598038ffp-1,
+    -0x1.46b9c347764a3p3
+  },
+  { // Entry 1063
+    0x1.00000000000046a403d9fdd4f3642059p0,
+    0x1.46b9c347764a4p3
+  },
+  { // Entry 1064
+    -0x1.00000000000046a403d9fdd4f3642059p0,
+    -0x1.46b9c347764a4p3
+  },
+  { // Entry 1065
+    0x1.9c78eea78baa6e13eccc94c421c4f5acp48,
+    0x1.5fdbbe9bba774p3
+  },
+  { // Entry 1066
+    -0x1.9c78eea78baa6e13eccc94c421c4f5acp48,
+    -0x1.5fdbbe9bba774p3
+  },
+  { // Entry 1067
+    0x1.093c3b4aebeb0806fbe4a1f0c660ba3bp51,
+    0x1.5fdbbe9bba775p3
+  },
+  { // Entry 1068
+    -0x1.093c3b4aebeb0806fbe4a1f0c660ba3bp51,
+    -0x1.5fdbbe9bba775p3
+  },
+  { // Entry 1069
+    -0x1.516ac961421855fb759fc2facb4e9f5bp49,
+    0x1.5fdbbe9bba776p3
+  },
+  { // Entry 1070
+    0x1.516ac961421855fb759fc2facb4e9f5bp49,
+    -0x1.5fdbbe9bba776p3
+  },
+  { // Entry 1071
+    -0x1.000000000001c22f0f3f8c5aa5a01da3p0,
+    0x1.78fdb9effea45p3
+  },
+  { // Entry 1072
+    0x1.000000000001c22f0f3f8c5aa5a01da3p0,
+    -0x1.78fdb9effea45p3
+  },
+  { // Entry 1073
+    -0x1.000000000000c22f0f3f8c5963710e64p0,
+    0x1.78fdb9effea46p3
+  },
+  { // Entry 1074
+    0x1.000000000000c22f0f3f8c5963710e64p0,
+    -0x1.78fdb9effea46p3
+  },
+  { // Entry 1075
+    -0x1.ffffffffffff845e1e7f18b24283fe49p-1,
+    0x1.78fdb9effea47p3
+  },
+  { // Entry 1076
+    0x1.ffffffffffff845e1e7f18b24283fe49p-1,
+    -0x1.78fdb9effea47p3
+  },
+  { // Entry 1077
+    0x1.fffffffffffc69fbbb4dd2f4fc88ffa1p-1,
+    0x1.ab41b09886fe8p3
+  },
+  { // Entry 1078
+    -0x1.fffffffffffc69fbbb4dd2f4fc88ffa1p-1,
+    -0x1.ab41b09886fe8p3
+  },
+  { // Entry 1079
+    0x1.fffffffffffe69fbbb4dd2f26684baeep-1,
+    0x1.ab41b09886fe9p3
+  },
+  { // Entry 1080
+    -0x1.fffffffffffe69fbbb4dd2f26684baeep-1,
+    -0x1.ab41b09886fe9p3
+  },
+  { // Entry 1081
+    0x1.00000000000034fddda6e978e8403b1ep0,
+    0x1.ab41b09886feap3
+  },
+  { // Entry 1082
+    -0x1.00000000000034fddda6e978e8403b1ep0,
+    -0x1.ab41b09886feap3
+  },
+  { // Entry 1083
+    0x1.86c4e333b3c9f6273896aba201767912p48,
+    0x1.c463abeccb2bap3
+  },
+  { // Entry 1084
+    -0x1.86c4e333b3c9f6273896aba201767912p48,
+    -0x1.c463abeccb2bap3
+  },
+  { // Entry 1085
+    0x1.9c96951f361845603280185a16d6026cp50,
+    0x1.c463abeccb2bbp3
+  },
+  { // Entry 1086
+    -0x1.9c96951f361845603280185a16d6026cp50,
+    -0x1.c463abeccb2bbp3
+  },
+  { // Entry 1087
+    -0x1.73244d369e0b6eb2f5d73cca7344e87ap49,
+    0x1.c463abeccb2bcp3
+  },
+  { // Entry 1088
+    0x1.73244d369e0b6eb2f5d73cca7344e87ap49,
+    -0x1.c463abeccb2bcp3
+  },
+  { // Entry 1089
+    -0x1.000000000001d3d53572a0b6cc261055p0,
+    0x1.dd85a7410f58bp3
+  },
+  { // Entry 1090
+    0x1.000000000001d3d53572a0b6cc261055p0,
+    -0x1.dd85a7410f58bp3
+  },
+  { // Entry 1091
+    -0x1.000000000000d3d53572a0b57850dae2p0,
+    0x1.dd85a7410f58cp3
+  },
+  { // Entry 1092
+    0x1.000000000000d3d53572a0b57850dae2p0,
+    -0x1.dd85a7410f58cp3
+  },
+  { // Entry 1093
+    -0x1.ffffffffffffa7aa6ae5416a48f74adfp-1,
+    0x1.dd85a7410f58dp3
+  },
+  { // Entry 1094
+    0x1.ffffffffffffa7aa6ae5416a48f74adfp-1,
+    -0x1.dd85a7410f58dp3
+  },
+  { // Entry 1095
+    -0x1.583ebeff65cc226480ae685c65352325p-49,
+    0x1.f6a7a2955385dp3
+  },
+  { // Entry 1096
+    0x1.583ebeff65cc226480ae685c65352325p-49,
+    -0x1.f6a7a2955385dp3
+  },
+  { // Entry 1097
+    -0x1.60fafbfd9730899202b9a170c8d54591p-51,
+    0x1.f6a7a2955385ep3
+  },
+  { // Entry 1098
+    0x1.60fafbfd9730899202b9a170c8d54591p-51,
+    -0x1.f6a7a2955385ep3
+  },
+  { // Entry 1099
+    0x1.4f8282013467bb36fea32f47a95641bap-50,
+    0x1.f6a7a2955385fp3
+  },
+  { // Entry 1100
+    -0x1.4f8282013467bb36fea32f47a95641bap-50,
+    -0x1.f6a7a2955385fp3
+  },
+  { // Entry 1101
+    0x1.fffffffffff846af6ee7aa48a1e9e9f7p-1,
+    0x1.07e4cef4cbd96p4
+  },
+  { // Entry 1102
+    -0x1.fffffffffff846af6ee7aa48a1e9e9f7p-1,
+    -0x1.07e4cef4cbd96p4
+  },
+  { // Entry 1103
+    0x1.fffffffffffc46af6ee7aa3d2f48c7c7p-1,
+    0x1.07e4cef4cbd97p4
+  },
+  { // Entry 1104
+    -0x1.fffffffffffc46af6ee7aa3d2f48c7c7p-1,
+    -0x1.07e4cef4cbd97p4
+  },
+  { // Entry 1105
+    0x1.0000000000002357b773d51cde53d2cbp0,
+    0x1.07e4cef4cbd98p4
+  },
+  { // Entry 1106
+    -0x1.0000000000002357b773d51cde53d2cbp0,
+    -0x1.07e4cef4cbd98p4
+  },
+  { // Entry 1107
+    0x1.2f0842389e5bc014d0fbe843cca6ddf3p47,
+    0x1.1475cc9eedeffp4
+  },
+  { // Entry 1108
+    -0x1.2f0842389e5bc014d0fbe843cca6ddf3p47,
+    -0x1.1475cc9eedeffp4
+  },
+  { // Entry 1109
+    0x1.733c4e8ef9c50cb5929f6bb674bec67fp48,
+    0x1.1475cc9eedfp4
+  },
+  { // Entry 1110
+    -0x1.733c4e8ef9c50cb5929f6bb674bec67fp48,
+    -0x1.1475cc9eedfp4
+  },
+  { // Entry 1111
+    -0x1.9c5b4c728989891dfb8710adf387843cp49,
+    0x1.1475cc9eedf01p4
+  },
+  { // Entry 1112
+    0x1.9c5b4c728989891dfb8710adf387843cp49,
+    -0x1.1475cc9eedf01p4
+  },
+  { // Entry 1113
+    -0x1.000000000002e57b5ba5b515595edb94p0,
+    0x1.2106ca4910068p4
+  },
+  { // Entry 1114
+    0x1.000000000002e57b5ba5b515595edb94p0,
+    -0x1.2106ca4910068p4
+  },
+  { // Entry 1115
+    -0x1.000000000000e57b5ba5b5118e682449p0,
+    0x1.2106ca4910069p4
+  },
+  { // Entry 1116
+    0x1.000000000000e57b5ba5b5118e682449p0,
+    -0x1.2106ca4910069p4
+  },
+  { // Entry 1117
+    -0x1.fffffffffffdcaf6b74b6a2386e2d9fbp-1,
+    0x1.2106ca491006ap4
+  },
+  { // Entry 1118
+    0x1.fffffffffffdcaf6b74b6a2386e2d9fbp-1,
+    -0x1.2106ca491006ap4
+  },
+  { // Entry 1119
+    -0x1.34f272993d1414a2b39bd837e6c96af0p-48,
+    0x1.2d97c7f3321d1p4
+  },
+  { // Entry 1120
+    0x1.34f272993d1414a2b39bd837e6c96af0p-48,
+    -0x1.2d97c7f3321d1p4
+  },
+  { // Entry 1121
+    -0x1.a79394c9e8a0a5159cdec1ba8c71f6bap-51,
+    0x1.2d97c7f3321d2p4
+  },
+  { // Entry 1122
+    0x1.a79394c9e8a0a5159cdec1ba8c71f6bap-51,
+    -0x1.2d97c7f3321d2p4
+  },
+  { // Entry 1123
+    0x1.961b1acd85d7d6ba98c84f91b390101fp-49,
+    0x1.2d97c7f3321d3p4
+  },
+  { // Entry 1124
+    -0x1.961b1acd85d7d6ba98c84f91b390101fp-49,
+    -0x1.2d97c7f3321d3p4
+  },
+  { // Entry 1125
+    0x1.fffffffffff82363228181911db144bap-1,
+    0x1.3a28c59d54339p4
+  },
+  { // Entry 1126
+    -0x1.fffffffffff82363228181911db144bap-1,
+    -0x1.3a28c59d54339p4
+  },
+  { // Entry 1127
+    0x1.fffffffffffc236322818185647789bdp-1,
+    0x1.3a28c59d5433ap4
+  },
+  { // Entry 1128
+    -0x1.fffffffffffc236322818185647789bdp-1,
+    -0x1.3a28c59d5433ap4
+  },
+  { // Entry 1129
+    0x1.00000000000011b19140c0c0d59ee760p0,
+    0x1.3a28c59d5433bp4
+  },
+  { // Entry 1130
+    -0x1.00000000000011b19140c0c0d59ee760p0,
+    -0x1.3a28c59d5433bp4
+  },
+  { // Entry 1131
+    0x1.28f934315e5eb9b45a603a5f788de131p47,
+    0x1.46b9c347764a2p4
+  },
+  { // Entry 1132
+    -0x1.28f934315e5eb9b45a603a5f788de131p47,
+    -0x1.46b9c347764a2p4
+  },
+  { // Entry 1133
+    0x1.618fdb7f21c13c236a4c4551ff139f5dp48,
+    0x1.46b9c347764a3p4
+  },
+  { // Entry 1134
+    -0x1.618fdb7f21c13c236a4c4551ff139f5dp48,
+    -0x1.46b9c347764a3p4
+  },
+  { // Entry 1135
+    -0x1.cfde61218ab9e79ffe8f046afdf00de3p49,
+    0x1.46b9c347764a4p4
+  },
+  { // Entry 1136
+    0x1.cfde61218ab9e79ffe8f046afdf00de3p49,
+    -0x1.46b9c347764a4p4
+  },
+  { // Entry 1137
+    -0x1.000000000002f72181d8c97193f9ee49p0,
+    0x1.534ac0f19860bp4
+  },
+  { // Entry 1138
+    0x1.000000000002f72181d8c97193f9ee49p0,
+    -0x1.534ac0f19860bp4
+  },
+  { // Entry 1139
+    -0x1.000000000000f72181d8c96da5b6ea98p0,
+    0x1.534ac0f19860cp4
+  },
+  { // Entry 1140
+    0x1.000000000000f72181d8c96da5b6ea98p0,
+    -0x1.534ac0f19860cp4
+  },
+  { // Entry 1141
+    -0x1.fffffffffffdee4303b192db6ee7cdcdp-1,
+    0x1.534ac0f19860dp4
+  },
+  { // Entry 1142
+    0x1.fffffffffffdee4303b192db6ee7cdcdp-1,
+    -0x1.534ac0f19860dp4
+  },
+  { // Entry 1143
+    -0x1.3dc585b2c742181326e07c412c24a052p-48,
+    0x1.5fdbbe9bba774p4
+  },
+  { // Entry 1144
+    0x1.3dc585b2c742181326e07c412c24a052p-48,
+    -0x1.5fdbbe9bba774p4
+  },
+  { // Entry 1145
+    -0x1.ee2c2d963a10c0993703e2045110595ep-51,
+    0x1.5fdbbe9bba775p4
+  },
+  { // Entry 1146
+    0x1.ee2c2d963a10c0993703e2045110595ep-51,
+    -0x1.5fdbbe9bba775p4
+  },
+  { // Entry 1147
+    0x1.8474f49a717bcfd9b23f077f38aafd2ap-49,
+    0x1.5fdbbe9bba776p4
+  },
+  { // Entry 1148
+    -0x1.8474f49a717bcfd9b23f077f38aafd2ap-49,
+    -0x1.5fdbbe9bba776p4
+  },
+  { // Entry 1149
+    0x1.fffffffffff80016d61b58d99be7994ep-1,
+    0x1.6c6cbc45dc8dcp4
+  },
+  { // Entry 1150
+    -0x1.fffffffffff80016d61b58d99be7994ep-1,
+    -0x1.6c6cbc45dc8dcp4
+  },
+  { // Entry 1151
+    0x1.fffffffffffc0016d61b58cd9c154585p-1,
+    0x1.6c6cbc45dc8ddp4
+  },
+  { // Entry 1152
+    -0x1.fffffffffffc0016d61b58cd9c154585p-1,
+    -0x1.6c6cbc45dc8ddp4
+  },
+  { // Entry 1153
+    0x1.000000000000000b6b0dac64ce2178ddp0,
+    0x1.6c6cbc45dc8dep4
+  },
+  { // Entry 1154
+    -0x1.000000000000000b6b0dac64ce2178ddp0,
+    -0x1.6c6cbc45dc8dep4
+  },
+  { // Entry 1155
+    0x1.2326f4e8f2bb180e5bf0417d75ea5d9ep47,
+    0x1.78fdb9effea45p4
+  },
+  { // Entry 1156
+    -0x1.2326f4e8f2bb180e5bf0417d75ea5d9ep47,
+    -0x1.78fdb9effea45p4
+  },
+  { // Entry 1157
+    0x1.517ea08708ba69da333a8c85f3bc6609p48,
+    0x1.78fdb9effea46p4
+  },
+  { // Entry 1158
+    -0x1.517ea08708ba69da333a8c85f3bc6609p48,
+    -0x1.78fdb9effea46p4
+  },
+  { // Entry 1159
+    -0x1.090b3d5161785ac2d31663f7e5d6bed4p50,
+    0x1.78fdb9effea47p4
+  },
+  { // Entry 1160
+    0x1.090b3d5161785ac2d31663f7e5d6bed4p50,
+    -0x1.78fdb9effea47p4
+  },
+  { // Entry 1161
+    -0x1.00000000000308c7a80bddcdcfcc7de7p0,
+    0x1.858eb79a20baep4
+  },
+  { // Entry 1162
+    0x1.00000000000308c7a80bddcdcfcc7de7p0,
+    -0x1.858eb79a20baep4
+  },
+  { // Entry 1163
+    -0x1.00000000000108c7a80bddc9be3d2dcfp0,
+    0x1.858eb79a20bafp4
+  },
+  { // Entry 1164
+    0x1.00000000000108c7a80bddc9be3d2dcfp0,
+    -0x1.858eb79a20bafp4
+  },
+  { // Entry 1165
+    -0x1.fffffffffffe118f5017bb93595bbb6fp-1,
+    0x1.858eb79a20bb0p4
+  },
+  { // Entry 1166
+    0x1.fffffffffffe118f5017bb93595bbb6fp-1,
+    -0x1.858eb79a20bb0p4
+  },
+  { // Entry 1167
+    -0x1.af0792001f856335a38010a6a6832e6bp2,
+    0x1.fffffffffffffp62
+  },
+  { // Entry 1168
+    0x1.af0792001f856335a38010a6a6832e6bp2,
+    -0x1.fffffffffffffp62
+  },
+  { // Entry 1169
+    0x1.52f50e757941cbff5b7c2e06a1ab7e9dp6,
+    0x1.0p63
+  },
+  { // Entry 1170
+    -0x1.52f50e757941cbff5b7c2e06a1ab7e9dp6,
+    -0x1.0p63
+  },
+  { // Entry 1171
+    0x1.7570667d032eca8ef780ad59d3e27e4bp1,
+    0x1.0000000000001p63
+  },
+  { // Entry 1172
+    -0x1.7570667d032eca8ef780ad59d3e27e4bp1,
+    -0x1.0000000000001p63
+  },
+  { // Entry 1173
+    -0x1.2e8fc248e7b854fe5c2dc9d287de0cd3p0,
+    0x1.fffffffffffffp26
+  },
+  { // Entry 1174
+    0x1.2e8fc248e7b854fe5c2dc9d287de0cd3p0,
+    -0x1.fffffffffffffp26
+  },
+  { // Entry 1175
+    -0x1.2e8fc1af81d8baa8899a3325200c0dcbp0,
+    0x1.0p27
+  },
+  { // Entry 1176
+    0x1.2e8fc1af81d8baa8899a3325200c0dcbp0,
+    -0x1.0p27
+  },
+  { // Entry 1177
+    -0x1.2e8fc07cb61a95ef5e5d8d6416652c7ap0,
+    0x1.0000000000001p27
+  },
+  { // Entry 1178
+    0x1.2e8fc07cb61a95ef5e5d8d6416652c7ap0,
+    -0x1.0000000000001p27
+  },
+  { // Entry 1179
+    -0x1.3ea282860e7fbe1765607c2fdb32481fp0,
+    0x1.fffffffffffffp23
+  },
+  { // Entry 1180
+    0x1.3ea282860e7fbe1765607c2fdb32481fp0,
+    -0x1.fffffffffffffp23
+  },
+  { // Entry 1181
+    -0x1.3ea28271a9bea36e744f9ce537ba4b59p0,
+    0x1.0p24
+  },
+  { // Entry 1182
+    0x1.3ea28271a9bea36e744f9ce537ba4b59p0,
+    -0x1.0p24
+  },
+  { // Entry 1183
+    -0x1.3ea28248e03c72def70e7efb4c43f03ep0,
+    0x1.0000000000001p24
+  },
+  { // Entry 1184
+    0x1.3ea28248e03c72def70e7efb4c43f03ep0,
+    -0x1.0000000000001p24
+  },
+  { // Entry 1185
+    0x1.2866f9be4de0ec27efa9049ab80bbd6cp0,
+    0x1.fffffffffffffp1
+  },
+  { // Entry 1186
+    -0x1.2866f9be4de0ec27efa9049ab80bbd6cp0,
+    -0x1.fffffffffffffp1
+  },
+  { // Entry 1187
+    0x1.2866f9be4de1370db9078607012cb07bp0,
+    0x1.0p2
+  },
+  { // Entry 1188
+    -0x1.2866f9be4de1370db9078607012cb07bp0,
+    -0x1.0p2
+  },
+  { // Entry 1189
+    0x1.2866f9be4de1ccd94bc488dfd47873afp0,
+    0x1.0000000000001p2
+  },
+  { // Entry 1190
+    -0x1.2866f9be4de1ccd94bc488dfd47873afp0,
+    -0x1.0000000000001p2
+  },
+  { // Entry 1191
+    -0x1.17af62e0950fb1e701c642ef8737f516p1,
+    0x1.fffffffffffffp0
+  },
+  { // Entry 1192
+    0x1.17af62e0950fb1e701c642ef8737f516p1,
+    -0x1.fffffffffffffp0
+  },
+  { // Entry 1193
+    -0x1.17af62e0950f83b5099087aaf67af9c1p1,
+    0x1.0p1
+  },
+  { // Entry 1194
+    0x1.17af62e0950f83b5099087aaf67af9c1p1,
+    -0x1.0p1
+  },
+  { // Entry 1195
+    -0x1.17af62e0950f275119251121fadb17bap1,
+    0x1.0000000000001p1
+  },
+  { // Entry 1196
+    0x1.17af62e0950f275119251121fadb17bap1,
+    -0x1.0000000000001p1
+  },
+  { // Entry 1197
+    0x1.8eb245cbee3a40235613e7575020d30dp0,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 1198
+    -0x1.8eb245cbee3a40235613e7575020d30dp0,
+    -0x1.fffffffffffffp-1
+  },
+  { // Entry 1199
+    0x1.8eb245cbee3a5b8acc7d41323140b3b5p0,
+    0x1.0p0
+  },
+  { // Entry 1200
+    -0x1.8eb245cbee3a5b8acc7d41323140b3b5p0,
+    -0x1.0p0
+  },
+  { // Entry 1201
+    0x1.8eb245cbee3a9259b94ff4e7fb8111ecp0,
+    0x1.0000000000001p0
+  },
+  { // Entry 1202
+    -0x1.8eb245cbee3a9259b94ff4e7fb8111ecp0,
+    -0x1.0000000000001p0
+  },
+  { // Entry 1203
+    0x1.17b4f5bf347499ce41855dee4344bd1dp-1,
+    0x1.fffffffffffffp-2
+  },
+  { // Entry 1204
+    -0x1.17b4f5bf347499ce41855dee4344bd1dp-1,
+    -0x1.fffffffffffffp-2
+  },
+  { // Entry 1205
+    0x1.17b4f5bf3474a4317964807882444cc8p-1,
+    0x1.0p-1
+  },
+  { // Entry 1206
+    -0x1.17b4f5bf3474a4317964807882444cc8p-1,
+    -0x1.0p-1
+  },
+  { // Entry 1207
+    0x1.17b4f5bf3474b8f7e922c58d00cb9dd2p-1,
+    0x1.0000000000001p-1
+  },
+  { // Entry 1208
+    -0x1.17b4f5bf3474b8f7e922c58d00cb9dd2p-1,
+    -0x1.0000000000001p-1
+  },
+  { // Entry 1209
+    0x1.05785a43c4c555de0cb1371f10db31afp-2,
+    0x1.fffffffffffffp-3
+  },
+  { // Entry 1210
+    -0x1.05785a43c4c555de0cb1371f10db31afp-2,
+    -0x1.fffffffffffffp-3
+  },
+  { // Entry 1211
+    0x1.05785a43c4c55e63940188965c28bd0fp-2,
+    0x1.0p-2
+  },
+  { // Entry 1212
+    -0x1.05785a43c4c55e63940188965c28bd0fp-2,
+    -0x1.0p-2
+  },
+  { // Entry 1213
+    0x1.05785a43c4c56f6ea2a22b84f2ddf03fp-2,
+    0x1.0000000000001p-2
+  },
+  { // Entry 1214
+    -0x1.05785a43c4c56f6ea2a22b84f2ddf03fp-2,
+    -0x1.0000000000001p-2
+  },
+  { // Entry 1215
+    0x1.01577af1511a45e403dd60c8d82590d0p-3,
+    0x1.fffffffffffffp-4
+  },
+  { // Entry 1216
+    -0x1.01577af1511a45e403dd60c8d82590d0p-3,
+    -0x1.fffffffffffffp-4
+  },
+  { // Entry 1217
+    0x1.01577af1511a4e0459f5b872d4ff34fdp-3,
+    0x1.0p-3
+  },
+  { // Entry 1218
+    -0x1.01577af1511a4e0459f5b872d4ff34fdp-3,
+    -0x1.0p-3
+  },
+  { // Entry 1219
+    0x1.01577af1511a5e45062667c6ceb89dc4p-3,
+    0x1.0000000000001p-3
+  },
+  { // Entry 1220
+    -0x1.01577af1511a5e45062667c6ceb89dc4p-3,
+    -0x1.0000000000001p-3
+  },
+  { // Entry 1221
+    0x1.005577854df0002a8e6606f6c618d988p-4,
+    0x1.fffffffffffffp-5
+  },
+  { // Entry 1222
+    -0x1.005577854df0002a8e6606f6c618d988p-4,
+    -0x1.fffffffffffffp-5
+  },
+  { // Entry 1223
+    0x1.005577854df0083293be639057b0c681p-4,
+    0x1.0p-4
+  },
+  { // Entry 1224
+    -0x1.005577854df0083293be639057b0c681p-4,
+    -0x1.0p-4
+  },
+  { // Entry 1225
+    0x1.005577854df018429e6f1cc37ae22274p-4,
+    0x1.0000000000001p-4
+  },
+  { // Entry 1226
+    -0x1.005577854df018429e6f1cc37ae22274p-4,
+    -0x1.0000000000001p-4
+  },
+  { // Entry 1227
+    0x1.00155777aec07d7b22741d12ee53a9fcp-5,
+    0x1.fffffffffffffp-6
+  },
+  { // Entry 1228
+    -0x1.00155777aec07d7b22741d12ee53a9fcp-5,
+    -0x1.fffffffffffffp-6
+  },
+  { // Entry 1229
+    0x1.00155777aec0857d22c97e809860288dp-5,
+    0x1.0p-5
+  },
+  { // Entry 1230
+    -0x1.00155777aec0857d22c97e809860288dp-5,
+    -0x1.0p-5
+  },
+  { // Entry 1231
+    0x1.00155777aec095812374415bec7985cep-5,
+    0x1.0000000000001p-5
+  },
+  { // Entry 1232
+    -0x1.00155777aec095812374415bec7985cep-5,
+    -0x1.0000000000001p-5
+  },
+  { // Entry 1233
+    0x1.00055577785482e135f0afeebe805adbp-6,
+    0x1.fffffffffffffp-7
+  },
+  { // Entry 1234
+    -0x1.00055577785482e135f0afeebe805adbp-6,
+    -0x1.fffffffffffffp-7
+  },
+  { // Entry 1235
+    0x1.0005557778548ae1b5f60574706e8238p-6,
+    0x1.0p-6
+  },
+  { // Entry 1236
+    -0x1.0005557778548ae1b5f60574706e8238p-6,
+    -0x1.0p-6
+  },
+  { // Entry 1237
+    0x1.0005557778549ae2b600b07fd44ae8f3p-6,
+    0x1.0000000000001p-6
+  },
+  { // Entry 1238
+    -0x1.0005557778549ae2b600b07fd44ae8f3p-6,
+    -0x1.0000000000001p-6
+  },
+  { // Entry 1239
+    0x1.0000000555554d777776f854854304c9p-14,
+    0x1.fffffffffffffp-15
+  },
+  { // Entry 1240
+    -0x1.0000000555554d777776f854854304c9p-14,
+    -0x1.fffffffffffffp-15
+  },
+  { // Entry 1241
+    0x1.00000005555555777777785485485a1ep-14,
+    0x1.0p-14
+  },
+  { // Entry 1242
+    -0x1.00000005555555777777785485485a1ep-14,
+    -0x1.0p-14
+  },
+  { // Entry 1243
+    0x1.000000055555657777787854855304c9p-14,
+    0x1.0000000000001p-14
+  },
+  { // Entry 1244
+    -0x1.000000055555657777787854855304c9p-14,
+    -0x1.0000000000001p-14
+  },
+  { // Entry 1245
+    0x1.fffffffffffff2aaaaaaaaaaaa6eeeeep-28,
+    0x1.fffffffffffffp-28
+  },
+  { // Entry 1246
+    -0x1.fffffffffffff2aaaaaaaaaaaa6eeeeep-28,
+    -0x1.fffffffffffffp-28
+  },
+  { // Entry 1247
+    0x1.00000000000001555555555555577777p-27,
+    0x1.0p-27
+  },
+  { // Entry 1248
+    -0x1.00000000000001555555555555577777p-27,
+    -0x1.0p-27
+  },
+  { // Entry 1249
+    0x1.00000000000011555555555555977777p-27,
+    0x1.0000000000001p-27
+  },
+  { // Entry 1250
+    -0x1.00000000000011555555555555977777p-27,
+    -0x1.0000000000001p-27
+  },
+  { // Entry 1251
+    0x1.fffffffffffff00aaaaaaaaaaaa9aaeep-31,
+    0x1.fffffffffffffp-31
+  },
+  { // Entry 1252
+    -0x1.fffffffffffff00aaaaaaaaaaaa9aaeep-31,
+    -0x1.fffffffffffffp-31
+  },
+  { // Entry 1253
+    0x1.00000000000000055555555555555577p-30,
+    0x1.0p-30
+  },
+  { // Entry 1254
+    -0x1.00000000000000055555555555555577p-30,
+    -0x1.0p-30
+  },
+  { // Entry 1255
+    0x1.00000000000010055555555555565577p-30,
+    0x1.0000000000001p-30
+  },
+  { // Entry 1256
+    -0x1.00000000000010055555555555565577p-30,
+    -0x1.0000000000001p-30
+  },
+  { // Entry 1257
+    0x1.4530cfe729483b8da1f7101e16cd74b7p-8,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1258
+    -0x1.4530cfe729483b8da1f7101e16cd74b7p-8,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1259
+    -0x1.4530cfe729483b8da1f7101e16cd74b7p-8,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1260
+    0x1.4530cfe729483b8da1f7101e16cd74b7p-8,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1261
+    -0x1.4530cfe729483b8da1f7101e16cd74b7p-8,
+    0x1.fffffffffffffp1023
+  },
+  { // Entry 1262
+    0x1.4530cfe729483b8da1f7101e16cd74b7p-8,
+    -0x1.fffffffffffffp1023
+  },
+  { // Entry 1263
+    0x1.3c6e9970f78b84fc8227517fd521017bp1,
+    0x1.ffffffffffffep1023
+  },
+  { // Entry 1264
+    -0x1.3c6e9970f78b84fc8227517fd521017bp1,
+    -0x1.ffffffffffffep1023
+  },
+  { // Entry 1265
+    -0x1.1a62633145c06e0e689481270461d5d7p-53,
+    0x1.921fb54442d18p1
+  },
+  { // Entry 1266
+    0x1.1a62633145c06e0e689481270461d5d7p-53,
+    -0x1.921fb54442d18p1
+  },
+  { // Entry 1267
+    0x1.d02967c31cdb4e0c38d01b655d5e0aafp53,
+    0x1.921fb54442d18p0
+  },
+  { // Entry 1268
+    -0x1.d02967c31cdb4e0c38d01b655d5e0aafp53,
+    -0x1.921fb54442d18p0
+  },
+  { // Entry 1269
+    0x1.8eb245cbee3a9259b94ff4e7fb8111ecp0,
+    0x1.0000000000001p0
+  },
+  { // Entry 1270
+    -0x1.8eb245cbee3a9259b94ff4e7fb8111ecp0,
+    -0x1.0000000000001p0
+  },
+  { // Entry 1271
+    0x1.8eb245cbee3a5b8acc7d41323140b3b5p0,
+    0x1.0p0
+  },
+  { // Entry 1272
+    -0x1.8eb245cbee3a5b8acc7d41323140b3b5p0,
+    -0x1.0p0
+  },
+  { // Entry 1273
+    0x1.8eb245cbee3a40235613e7575020d30dp0,
+    0x1.fffffffffffffp-1
+  },
+  { // Entry 1274
+    -0x1.8eb245cbee3a40235613e7575020d30dp0,
+    -0x1.fffffffffffffp-1
+  },
+  { // Entry 1275
+    0x1.fffffffffffff72cece675d1fca30489p-1,
+    0x1.921fb54442d18p-1
+  },
+  { // Entry 1276
+    -0x1.fffffffffffff72cece675d1fca30489p-1,
+    -0x1.921fb54442d18p-1
+  },
+  { // Entry 1277
+    0x1.00000000000010p-1022,
+    0x1.0000000000001p-1022
+  },
+  { // Entry 1278
+    -0x1.00000000000010p-1022,
+    -0x1.0000000000001p-1022
+  },
+  { // Entry 1279
+    0x1.p-1022,
+    0x1.0p-1022
+  },
+  { // Entry 1280
+    -0x1.p-1022,
+    -0x1.0p-1022
+  },
+  { // Entry 1281
+    0x1.ffffffffffffe0p-1023,
+    0x1.ffffffffffffep-1023
+  },
+  { // Entry 1282
+    -0x1.ffffffffffffe0p-1023,
+    -0x1.ffffffffffffep-1023
+  },
+  { // Entry 1283
+    0x1.ffffffffffffc0p-1023,
+    0x1.ffffffffffffcp-1023
+  },
+  { // Entry 1284
+    -0x1.ffffffffffffc0p-1023,
+    -0x1.ffffffffffffcp-1023
+  },
+  { // Entry 1285
+    0x1.p-1073,
+    0x1.0p-1073
+  },
+  { // Entry 1286
+    -0x1.p-1073,
+    -0x1.0p-1073
+  },
+  { // Entry 1287
+    0x1.p-1074,
+    0x1.0p-1074
+  },
+  { // Entry 1288
+    -0x1.p-1074,
+    -0x1.0p-1074
+  },
+  { // Entry 1289
+    0.0,
+    0.0
+  },
+  { // Entry 1290
+    -0.0,
+    -0.0
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_tan, tan_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_tan_intel_data)/sizeof(tan_intel_data_t); i++) {
+    EXPECT_DOUBLE_EQ(g_tan_intel_data[i].expected, tan(g_tan_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_tanf_test.cpp b/tests/math_tanf_test.cpp
new file mode 100644
index 0000000..9319046
--- /dev/null
+++ b/tests/math_tanf_test.cpp
@@ -0,0 +1,4459 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <math.h>
+
+#include <gtest/gtest.h>
+
+#if defined(__BIONIC__)
+typedef struct {
+  float expected;
+  float call_data;
+} tanf_intel_data_t;
+
+static tanf_intel_data_t g_tanf_intel_data[] = {
+  { // Entry 0
+    -0x1.00000000001555555555577777777777p-21,
+    -0x1.p-21
+  },
+  { // Entry 1
+    0x1.00000000001555555555577777777777p-21,
+    0x1.p-21
+  },
+  { // Entry 2
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 3
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 4
+    -0x1.00000200000000000000155555d55556p-41,
+    -0x1.000002p-41
+  },
+  { // Entry 5
+    0x1.00000200000000000000155555d55556p-41,
+    0x1.000002p-41
+  },
+  { // Entry 6
+    -0x1.ffb7eb004b7e12b369388faaa0342f6cp-3,
+    -0x1.27cca6p7
+  },
+  { // Entry 7
+    0x1.ffb7eb004b7e12b369388faaa0342f6cp-3,
+    0x1.27cca6p7
+  },
+  { // Entry 8
+    -0x1.3b7ddaffdc9a2fad39f329743fbf49e5p4,
+    -0x1.2a5996p2
+  },
+  { // Entry 9
+    0x1.3b7ddaffdc9a2fad39f329743fbf49e5p4,
+    0x1.2a5996p2
+  },
+  { // Entry 10
+    0x1.819f32ffd97b1ed667bc143387037ddep-1,
+    -0x1.3f7f22p1
+  },
+  { // Entry 11
+    -0x1.819f32ffd97b1ed667bc143387037ddep-1,
+    0x1.3f7f22p1
+  },
+  { // Entry 12
+    -0x1.405f900000000000000a7402846583d0p-38,
+    -0x1.405f90p-38
+  },
+  { // Entry 13
+    0x1.405f900000000000000a7402846583d0p-38,
+    0x1.405f90p-38
+  },
+  { // Entry 14
+    -0x1.8cd79995344c7943c7b3e021607da3cbp-2,
+    -0x1.496e80p96
+  },
+  { // Entry 15
+    0x1.8cd79995344c7943c7b3e021607da3cbp-2,
+    0x1.496e80p96
+  },
+  { // Entry 16
+    0x1.e144471ea2b49b6c1fdceff8ccceea7bp10,
+    -0x1.5fe0p3
+  },
+  { // Entry 17
+    -0x1.e144471ea2b49b6c1fdceff8ccceea7bp10,
+    0x1.5fe0p3
+  },
+  { // Entry 18
+    -0x1.ca0f4c2315ab5a9729e6afa857677b3fp-1,
+    -0x1.75aef0p-1
+  },
+  { // Entry 19
+    0x1.ca0f4c2315ab5a9729e6afa857677b3fp-1,
+    0x1.75aef0p-1
+  },
+  { // Entry 20
+    -0x1.c33ed50b887775a5d613c08c488fbb9cp3,
+    -0x1.80p0
+  },
+  { // Entry 21
+    0x1.c33ed50b887775a5d613c08c488fbb9cp3,
+    0x1.80p0
+  },
+  { // Entry 22
+    -0x1.c34513ee7140fdb8217e83dc2d6d6f53p3,
+    -0x1.800040p0
+  },
+  { // Entry 23
+    0x1.c34513ee7140fdb8217e83dc2d6d6f53p3,
+    0x1.800040p0
+  },
+  { // Entry 24
+    0x1.4e6b8a48164b9e1d8175e4512ab22ff1p0,
+    -0x1.8e3560p98
+  },
+  { // Entry 25
+    -0x1.4e6b8a48164b9e1d8175e4512ab22ff1p0,
+    0x1.8e3560p98
+  },
+  { // Entry 26
+    -0x1.d017e0214a953265d8dd5c0a11ea61d1p-1,
+    -0x1.9de7d4p4
+  },
+  { // Entry 27
+    0x1.d017e0214a953265d8dd5c0a11ea61d1p-1,
+    0x1.9de7d4p4
+  },
+  { // Entry 28
+    -0x1.d0473f02270c0eec883e753e50800670p-1,
+    -0x1.9de8a4p4
+  },
+  { // Entry 29
+    0x1.d0473f02270c0eec883e753e50800670p-1,
+    0x1.9de8a4p4
+  },
+  { // Entry 30
+    0x1.d0aada22aa5e3dc35b5063c639047df5p-1,
+    -0x1.be7e5ap5
+  },
+  { // Entry 31
+    -0x1.d0aada22aa5e3dc35b5063c639047df5p-1,
+    0x1.be7e5ap5
+  },
+  { // Entry 32
+    -0x1.ee9495000a190cdb6db3e83d2c05ef38p-2,
+    -0x1.ccbeb0p-2
+  },
+  { // Entry 33
+    0x1.ee9495000a190cdb6db3e83d2c05ef38p-2,
+    0x1.ccbeb0p-2
+  },
+  { // Entry 34
+    0x1.dc32eba638d13458c7b29d96abffe1cap-7,
+    -0x1.fffep127
+  },
+  { // Entry 35
+    -0x1.dc32eba638d13458c7b29d96abffe1cap-7,
+    0x1.fffep127
+  },
+  { // Entry 36
+    0x1.00000000001555555555577777777777p-21,
+    0x1.p-21
+  },
+  { // Entry 37
+    -0x1.00000000001555555555577777777777p-21,
+    -0x1.p-21
+  },
+  { // Entry 38
+    0x1.p-131,
+    0x1.p-131
+  },
+  { // Entry 39
+    -0x1.p-131,
+    -0x1.p-131
+  },
+  { // Entry 40
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 41
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 42
+    0x1.52f50e757941cbff5b7c2e06a1ab7e9dp6,
+    0x1.p63
+  },
+  { // Entry 43
+    -0x1.52f50e757941cbff5b7c2e06a1ab7e9dp6,
+    -0x1.p63
+  },
+  { // Entry 44
+    0x1.00000200000000000000155555d55556p-41,
+    0x1.000002p-41
+  },
+  { // Entry 45
+    -0x1.00000200000000000000155555d55556p-41,
+    -0x1.000002p-41
+  },
+  { // Entry 46
+    -0x1.adb7eb6d8cebbe362f197dbeda5c113cp-1,
+    0x1.000002p51
+  },
+  { // Entry 47
+    0x1.adb7eb6d8cebbe362f197dbeda5c113cp-1,
+    -0x1.000002p51
+  },
+  { // Entry 48
+    0x1.f7762b752b006715d90c389a11826d6bp1,
+    0x1.000004p127
+  },
+  { // Entry 49
+    -0x1.f7762b752b006715d90c389a11826d6bp1,
+    -0x1.000004p127
+  },
+  { // Entry 50
+    -0x1.09cff10000671912c84762f18c285470p0,
+    0x1.000090p7
+  },
+  { // Entry 51
+    0x1.09cff10000671912c84762f18c285470p0,
+    -0x1.000090p7
+  },
+  { // Entry 52
+    0x1.015901017edb67aa7e52ae694e990a19p-3,
+    0x1.000180p-3
+  },
+  { // Entry 53
+    -0x1.015901017edb67aa7e52ae694e990a19p-3,
+    -0x1.000180p-3
+  },
+  { // Entry 54
+    0x1.0002200000000000000055577559d958p-40,
+    0x1.000220p-40
+  },
+  { // Entry 55
+    -0x1.0002200000000000000055577559d958p-40,
+    -0x1.000220p-40
+  },
+  { // Entry 56
+    0x1.6d53796cdd401e3ddc09e835b8ea660ap3,
+    0x1.000380p127
+  },
+  { // Entry 57
+    -0x1.6d53796cdd401e3ddc09e835b8ea660ap3,
+    -0x1.000380p127
+  },
+  { // Entry 58
+    -0x1.b070e3a6968463af6e9db922e7845524p-7,
+    0x1.000880p9
+  },
+  { // Entry 59
+    0x1.b070e3a6968463af6e9db922e7845524p-7,
+    -0x1.000880p9
+  },
+  { // Entry 60
+    -0x1.fa61dcffa3efe325b32704fc412462cfp1,
+    0x1.0020p62
+  },
+  { // Entry 61
+    0x1.fa61dcffa3efe325b32704fc412462cfp1,
+    -0x1.0020p62
+  },
+  { // Entry 62
+    0x1.fffd825a3f377f012209982a00c346f0p-2,
+    0x1.0060p90
+  },
+  { // Entry 63
+    -0x1.fffd825a3f377f012209982a00c346f0p-2,
+    -0x1.0060p90
+  },
+  { // Entry 64
+    0x1.013c68fff04b698165dfdf9d48444a95p-6,
+    0x1.0137p-6
+  },
+  { // Entry 65
+    -0x1.013c68fff04b698165dfdf9d48444a95p-6,
+    -0x1.0137p-6
+  },
+  { // Entry 66
+    0x1.932c994f61d804a084f20d975a617c50p0,
+    0x1.014cp0
+  },
+  { // Entry 67
+    -0x1.932c994f61d804a084f20d975a617c50p0,
+    -0x1.014cp0
+  },
+  { // Entry 68
+    -0x1.c34ec20533e760565cb762b15c18d6fcp1,
+    0x1.020446p58
+  },
+  { // Entry 69
+    0x1.c34ec20533e760565cb762b15c18d6fcp1,
+    -0x1.020446p58
+  },
+  { // Entry 70
+    0x1.9ff71767ea051e4e9cc0008922b11129p0,
+    0x1.04e4p0
+  },
+  { // Entry 71
+    -0x1.9ff71767ea051e4e9cc0008922b11129p0,
+    -0x1.04e4p0
+  },
+  { // Entry 72
+    0x1.07c9c5001659079722f8e9190ffe6ec6p-3,
+    0x1.0658p-3
+  },
+  { // Entry 73
+    -0x1.07c9c5001659079722f8e9190ffe6ec6p-3,
+    -0x1.0658p-3
+  },
+  { // Entry 74
+    0x1.fd611072a50357e6266768b2cdf0194cp-3,
+    0x1.0ac710p100
+  },
+  { // Entry 75
+    -0x1.fd611072a50357e6266768b2cdf0194cp-3,
+    -0x1.0ac710p100
+  },
+  { // Entry 76
+    0x1.0ddbb5000244c4fb972eb72de00896c0p-3,
+    0x1.0c50p-3
+  },
+  { // Entry 77
+    -0x1.0ddbb5000244c4fb972eb72de00896c0p-3,
+    -0x1.0c50p-3
+  },
+  { // Entry 78
+    -0x1.c0aeb5f84be95da5ab0716dfba205e28p2,
+    0x1.0ddcp96
+  },
+  { // Entry 79
+    0x1.c0aeb5f84be95da5ab0716dfba205e28p2,
+    -0x1.0ddcp96
+  },
+  { // Entry 80
+    0x1.340754fffffeb780761e86337f0c55efp1,
+    0x1.0e28a6p4
+  },
+  { // Entry 81
+    -0x1.340754fffffeb780761e86337f0c55efp1,
+    -0x1.0e28a6p4
+  },
+  { // Entry 82
+    0x1.349d95ffee472ec7c10934570d3ba486p-1,
+    0x1.15bcp-1
+  },
+  { // Entry 83
+    -0x1.349d95ffee472ec7c10934570d3ba486p-1,
+    -0x1.15bcp-1
+  },
+  { // Entry 84
+    0x1.eec72403a4fd24d0c9e2af088a05fb85p0,
+    0x1.17e4p0
+  },
+  { // Entry 85
+    -0x1.eec72403a4fd24d0c9e2af088a05fb85p0,
+    -0x1.17e4p0
+  },
+  { // Entry 86
+    0x1.ef4bd7a215237b3065d569fd4c5f5a47p0,
+    0x1.18p0
+  },
+  { // Entry 87
+    -0x1.ef4bd7a215237b3065d569fd4c5f5a47p0,
+    -0x1.18p0
+  },
+  { // Entry 88
+    -0x1.fe793900138c9941836b4fcbc9b2260dp-4,
+    0x1.18p64
+  },
+  { // Entry 89
+    0x1.fe793900138c9941836b4fcbc9b2260dp-4,
+    -0x1.18p64
+  },
+  { // Entry 90
+    0x1.f08f0873c5819a9f7cc6bbf3c5291cc0p0,
+    0x1.1844p0
+  },
+  { // Entry 91
+    -0x1.f08f0873c5819a9f7cc6bbf3c5291cc0p0,
+    -0x1.1844p0
+  },
+  { // Entry 92
+    0x1.5c51cc18f091bc4b54ee83623438c9a7p11,
+    0x1.18fffep19
+  },
+  { // Entry 93
+    -0x1.5c51cc18f091bc4b54ee83623438c9a7p11,
+    -0x1.18fffep19
+  },
+  { // Entry 94
+    0x1.2633567898e691eeb87ad026bd16a7e4p-2,
+    0x1.1e7cp-2
+  },
+  { // Entry 95
+    -0x1.2633567898e691eeb87ad026bd16a7e4p-2,
+    -0x1.1e7cp-2
+  },
+  { // Entry 96
+    0x1.ffffedf558bfb3100f61125f296b8badp1,
+    0x1.1ebep18
+  },
+  { // Entry 97
+    -0x1.ffffedf558bfb3100f61125f296b8badp1,
+    -0x1.1ebep18
+  },
+  { // Entry 98
+    0x1.0e551b00007fae17236421a76e861c75p1,
+    0x1.20ea9cp0
+  },
+  { // Entry 99
+    -0x1.0e551b00007fae17236421a76e861c75p1,
+    -0x1.20ea9cp0
+  },
+  { // Entry 100
+    0x1.c07dfb0552ba60b71c7df6bd7ca409d6p20,
+    0x1.2106cap5
+  },
+  { // Entry 101
+    -0x1.c07dfb0552ba60b71c7df6bd7ca409d6p20,
+    -0x1.2106cap5
+  },
+  { // Entry 102
+    -0x1.fd23fd64a4bfcfb597c46933649f5ae2p-2,
+    0x1.219dc6p119
+  },
+  { // Entry 103
+    0x1.fd23fd64a4bfcfb597c46933649f5ae2p-2,
+    -0x1.219dc6p119
+  },
+  { // Entry 104
+    -0x1.b93c13000d016d14e756c25e42302d9fp-3,
+    0x1.26cd6ap3
+  },
+  { // Entry 105
+    0x1.b93c13000d016d14e756c25e42302d9fp-3,
+    -0x1.26cd6ap3
+  },
+  { // Entry 106
+    -0x1.ebcbcb138b274cbcbe61af5113da83ecp-4,
+    0x1.29c4e0p3
+  },
+  { // Entry 107
+    0x1.ebcbcb138b274cbcbe61af5113da83ecp-4,
+    -0x1.29c4e0p3
+  },
+  { // Entry 108
+    0x1.99bc5b961b1b24fdb77fcee08ba2f720p-25,
+    0x1.2d97c8p4
+  },
+  { // Entry 109
+    -0x1.99bc5b961b1b24fdb77fcee08ba2f720p-25,
+    -0x1.2d97c8p4
+  },
+  { // Entry 110
+    -0x1.ed18af0b0ba80dfa6e8ee1b3b31dfc60p-1,
+    0x1.30p1
+  },
+  { // Entry 111
+    0x1.ed18af0b0ba80dfa6e8ee1b3b31dfc60p-1,
+    -0x1.30p1
+  },
+  { // Entry 112
+    0x1.9ab24111cfc62df4dbca320216b94651p-4,
+    0x1.30ca70p3
+  },
+  { // Entry 113
+    -0x1.9ab24111cfc62df4dbca320216b94651p-4,
+    -0x1.30ca70p3
+  },
+  { // Entry 114
+    0x1.337d8ffffffede62f050e98b3b9596e1p-3,
+    0x1.3135f0p-3
+  },
+  { // Entry 115
+    -0x1.337d8ffffffede62f050e98b3b9596e1p-3,
+    -0x1.3135f0p-3
+  },
+  { // Entry 116
+    0x1.348e650000002ef3a765b9416d12cf7ep-3,
+    0x1.3240bcp-3
+  },
+  { // Entry 117
+    -0x1.348e650000002ef3a765b9416d12cf7ep-3,
+    -0x1.3240bcp-3
+  },
+  { // Entry 118
+    -0x1.b9e58aec61a44ab533c2b83726367e17p-8,
+    0x1.32d53cp16
+  },
+  { // Entry 119
+    0x1.b9e58aec61a44ab533c2b83726367e17p-8,
+    -0x1.32d53cp16
+  },
+  { // Entry 120
+    -0x1.e1fd68edea44fb78780ed62e73c6e017p-6,
+    0x1.3a0aa8p6
+  },
+  { // Entry 121
+    0x1.e1fd68edea44fb78780ed62e73c6e017p-6,
+    -0x1.3a0aa8p6
+  },
+  { // Entry 122
+    -0x1.62a28100001393080f6733dfaf9c76fcp-1,
+    0x1.4495bap1
+  },
+  { // Entry 123
+    0x1.62a28100001393080f6733dfaf9c76fcp-1,
+    -0x1.4495bap1
+  },
+  { // Entry 124
+    0x1.b923c3ba0bc0c500ba4c245301bad207p1,
+    0x1.49d42ap0
+  },
+  { // Entry 125
+    -0x1.b923c3ba0bc0c500ba4c245301bad207p1,
+    -0x1.49d42ap0
+  },
+  { // Entry 126
+    0x1.541f3f00022ac25cc8a90855ab6bb808p-3,
+    0x1.510bbcp-3
+  },
+  { // Entry 127
+    -0x1.541f3f00022ac25cc8a90855ab6bb808p-3,
+    -0x1.510bbcp-3
+  },
+  { // Entry 128
+    0x1.76f3efffff3057122e6e7ce50d12cbcep-3,
+    0x1.549520p100
+  },
+  { // Entry 129
+    -0x1.76f3efffff3057122e6e7ce50d12cbcep-3,
+    -0x1.549520p100
+  },
+  { // Entry 130
+    0x1.4cac0300643e12c46203b47d3eeed4ffp-9,
+    0x1.54c4bap24
+  },
+  { // Entry 131
+    -0x1.4cac0300643e12c46203b47d3eeed4ffp-9,
+    -0x1.54c4bap24
+  },
+  { // Entry 132
+    -0x1.70d5450000058974c20b97ba96fdae03p-3,
+    0x1.5a757ep24
+  },
+  { // Entry 133
+    0x1.70d5450000058974c20b97ba96fdae03p-3,
+    -0x1.5a757ep24
+  },
+  { // Entry 134
+    -0x1.ffffe9bba7f1321fae192943a3e848c0p-1,
+    0x1.5fdbc0p2
+  },
+  { // Entry 135
+    0x1.ffffe9bba7f1321fae192943a3e848c0p-1,
+    -0x1.5fdbc0p2
+  },
+  { // Entry 136
+    -0x1.ffb68f0050dabe5ce719202610fcac2ep-1,
+    0x1.5fe056p2
+  },
+  { // Entry 137
+    0x1.ffb68f0050dabe5ce719202610fcac2ep-1,
+    -0x1.5fe056p2
+  },
+  { // Entry 138
+    -0x1.dabb46e3937e6c505ab2062232339a16p-7,
+    0x1.6493d4p95
+  },
+  { // Entry 139
+    0x1.dabb46e3937e6c505ab2062232339a16p-7,
+    -0x1.6493d4p95
+  },
+  { // Entry 140
+    0x1.c832162481e1ce4f01736bb97a3019b9p-1,
+    0x1.74a566p-1
+  },
+  { // Entry 141
+    -0x1.c832162481e1ce4f01736bb97a3019b9p-1,
+    -0x1.74a566p-1
+  },
+  { // Entry 142
+    0x1.7b2fa40000038d569226512c77976ff5p-3,
+    0x1.76f0b2p-3
+  },
+  { // Entry 143
+    -0x1.7b2fa40000038d569226512c77976ff5p-3,
+    -0x1.76f0b2p-3
+  },
+  { // Entry 144
+    -0x1.4f375ad9dee5fd604fb29435f32efe57p1,
+    0x1.78b3fap100
+  },
+  { // Entry 145
+    0x1.4f375ad9dee5fd604fb29435f32efe57p1,
+    -0x1.78b3fap100
+  },
+  { // Entry 146
+    -0x1.00005efffbe73e7bafeab7f76c8a93efp0,
+    0x1.78fdb4p3
+  },
+  { // Entry 147
+    0x1.00005efffbe73e7bafeab7f76c8a93efp0,
+    -0x1.78fdb4p3
+  },
+  { // Entry 148
+    -0x1.fc3ace000029c331692aa9fe4e42f004p-1,
+    0x1.791cp3
+  },
+  { // Entry 149
+    0x1.fc3ace000029c331692aa9fe4e42f004p-1,
+    -0x1.791cp3
+  },
+  { // Entry 150
+    0x1.dcfa3254b53b6a70cec4473abe850102p-1,
+    0x1.7ffffep-1
+  },
+  { // Entry 151
+    -0x1.dcfa3254b53b6a70cec4473abe850102p-1,
+    -0x1.7ffffep-1
+  },
+  { // Entry 152
+    0x1.c33ed50b887775a5d613c08c488fbb9cp3,
+    0x1.80p0
+  },
+  { // Entry 153
+    -0x1.c33ed50b887775a5d613c08c488fbb9cp3,
+    -0x1.80p0
+  },
+  { // Entry 154
+    0x1.8008p-130,
+    0x1.8008p-130
+  },
+  { // Entry 155
+    -0x1.8008p-130,
+    -0x1.8008p-130
+  },
+  { // Entry 156
+    -0x1.f96370ec482d2bb0eb8ea7a530139fcfp-5,
+    0x1.8180p83
+  },
+  { // Entry 157
+    0x1.f96370ec482d2bb0eb8ea7a530139fcfp-5,
+    -0x1.8180p83
+  },
+  { // Entry 158
+    -0x1.fff664faa6f86fa8b4e5e2719d2195cfp-1,
+    0x1.89e090p9
+  },
+  { // Entry 159
+    0x1.fff664faa6f86fa8b4e5e2719d2195cfp-1,
+    -0x1.89e090p9
+  },
+  { // Entry 160
+    0x1.1c051101643be740782fe0dfc9dcd1ccp0,
+    0x1.8c631ep15
+  },
+  { // Entry 161
+    -0x1.1c051101643be740782fe0dfc9dcd1ccp0,
+    -0x1.8c631ep15
+  },
+  { // Entry 162
+    0x1.bb2e88f26b9363f9a852665f3413d994p13,
+    0x1.8c67fep127
+  },
+  { // Entry 163
+    -0x1.bb2e88f26b9363f9a852665f3413d994p13,
+    -0x1.8c67fep127
+  },
+  { // Entry 164
+    -0x1.f0e4ec133585cb30e67cfcbb36faad8ep1,
+    0x1.91d858p12
+  },
+  { // Entry 165
+    0x1.f0e4ec133585cb30e67cfcbb36faad8ep1,
+    -0x1.91d858p12
+  },
+  { // Entry 166
+    -0x1.5d14946dc98975d6421a55284fe020a1p24,
+    0x1.921fb6p0
+  },
+  { // Entry 167
+    0x1.5d14946dc98975d6421a55284fe020a1p24,
+    -0x1.921fb6p0
+  },
+  { // Entry 168
+    0x1.980ee0cfbf0f1ebc9d4fd24cce3cdfe7p15,
+    0x1.922922p15
+  },
+  { // Entry 169
+    -0x1.980ee0cfbf0f1ebc9d4fd24cce3cdfe7p15,
+    -0x1.922922p15
+  },
+  { // Entry 170
+    -0x1.fd43f8e891e227ddad2fb2e5520d4ff2p-1,
+    0x1.9230fep15
+  },
+  { // Entry 171
+    0x1.fd43f8e891e227ddad2fb2e5520d4ff2p-1,
+    -0x1.9230fep15
+  },
+  { // Entry 172
+    0x1.cf38f6212e7e6276f4add54878f1a7dbp-1,
+    0x1.9510c8p6
+  },
+  { // Entry 173
+    -0x1.cf38f6212e7e6276f4add54878f1a7dbp-1,
+    -0x1.9510c8p6
+  },
+  { // Entry 174
+    0x1.d03d45024c3ca4a2c4e1a91856135046p-1,
+    0x1.9511e6p6
+  },
+  { // Entry 175
+    -0x1.d03d45024c3ca4a2c4e1a91856135046p-1,
+    -0x1.9511e6p6
+  },
+  { // Entry 176
+    0x1.0554eb5cbd393e4f0770c86528f39ee1p17,
+    0x1.979f24p9
+  },
+  { // Entry 177
+    -0x1.0554eb5cbd393e4f0770c86528f39ee1p17,
+    -0x1.979f24p9
+  },
+  { // Entry 178
+    0x1.fad5df93de3051cf018ab32c0b323571p-1,
+    0x1.a1e862p119
+  },
+  { // Entry 179
+    -0x1.fad5df93de3051cf018ab32c0b323571p-1,
+    -0x1.a1e862p119
+  },
+  { // Entry 180
+    0x1.ff981b1534f78016bea4d9588254e996p3,
+    0x1.ad1fp63
+  },
+  { // Entry 181
+    -0x1.ff981b1534f78016bea4d9588254e996p3,
+    -0x1.ad1fp63
+  },
+  { // Entry 182
+    -0x1.fff4a1db1e1e38c438ddd38bb94f6d31p1,
+    0x1.ada3dap39
+  },
+  { // Entry 183
+    0x1.fff4a1db1e1e38c438ddd38bb94f6d31p1,
+    -0x1.ada3dap39
+  },
+  { // Entry 184
+    0x1.d01529023d951390200a4252f038b4afp-1,
+    0x1.b125bap5
+  },
+  { // Entry 185
+    -0x1.d01529023d951390200a4252f038b4afp-1,
+    -0x1.b125bap5
+  },
+  { // Entry 186
+    0x1.d67fa105f76868612c84f74a1f38f0acp-2,
+    0x1.b90a02p-2
+  },
+  { // Entry 187
+    -0x1.d67fa105f76868612c84f74a1f38f0acp-2,
+    -0x1.b90a02p-2
+  },
+  { // Entry 188
+    0x1.99663da94dbd57199cb8e3dae7018358p-23,
+    0x1.beeeeep80
+  },
+  { // Entry 189
+    -0x1.99663da94dbd57199cb8e3dae7018358p-23,
+    -0x1.beeeeep80
+  },
+  { // Entry 190
+    0x1.eb96571eb9da1337e703cc20e41e9719p-13,
+    0x1.c3abf0p24
+  },
+  { // Entry 191
+    -0x1.eb96571eb9da1337e703cc20e41e9719p-13,
+    -0x1.c3abf0p24
+  },
+  { // Entry 192
+    0x1.e198c48bef954151ee075815d85c5363p0,
+    0x1.c71c74p116
+  },
+  { // Entry 193
+    -0x1.e198c48bef954151ee075815d85c5363p0,
+    -0x1.c71c74p116
+  },
+  { // Entry 194
+    -0x1.e50e524610728cfb239cc6305b212fd6p-1,
+    0x1.cc3252p18
+  },
+  { // Entry 195
+    0x1.e50e524610728cfb239cc6305b212fd6p-1,
+    -0x1.cc3252p18
+  },
+  { // Entry 196
+    -0x1.6a69e7bb21b52030964bc21ced077c71p19,
+    0x1.d38a2ap19
+  },
+  { // Entry 197
+    0x1.6a69e7bb21b52030964bc21ced077c71p19,
+    -0x1.d38a2ap19
+  },
+  { // Entry 198
+    0x1.6529bf81b958ca781cdaac7cec6e636ep0,
+    0x1.df0648p24
+  },
+  { // Entry 199
+    -0x1.6529bf81b958ca781cdaac7cec6e636ep0,
+    -0x1.df0648p24
+  },
+  { // Entry 200
+    0x1.659e43b4315f21ba5e7048b1d8d7815cp0,
+    0x1.df2204p24
+  },
+  { // Entry 201
+    -0x1.659e43b4315f21ba5e7048b1d8d7815cp0,
+    -0x1.df2204p24
+  },
+  { // Entry 202
+    -0x1.71a580ffc4e167ae0ef8b02d5d27c99dp-1,
+    0x1.df34p24
+  },
+  { // Entry 203
+    0x1.71a580ffc4e167ae0ef8b02d5d27c99dp-1,
+    -0x1.df34p24
+  },
+  { // Entry 204
+    0x1.ecf119000017a2caef4290b4d6c63785p-4,
+    0x1.ea951ap-4
+  },
+  { // Entry 205
+    -0x1.ecf119000017a2caef4290b4d6c63785p-4,
+    -0x1.ea951ap-4
+  },
+  { // Entry 206
+    0x1.ccd55821fad69755c2d824be2bfd4c64p-1,
+    0x1.efedc6p1
+  },
+  { // Entry 207
+    -0x1.ccd55821fad69755c2d824be2bfd4c64p-1,
+    -0x1.efedc6p1
+  },
+  { // Entry 208
+    0x1.d6981efffff2549634686a24dfda77cep-1,
+    0x1.f143a2p1
+  },
+  { // Entry 209
+    -0x1.d6981efffff2549634686a24dfda77cep-1,
+    -0x1.f143a2p1
+  },
+  { // Entry 210
+    0x1.dba4d1124a78a6803a0965af0ab79f88p3,
+    0x1.f25b06p2
+  },
+  { // Entry 211
+    -0x1.dba4d1124a78a6803a0965af0ab79f88p3,
+    -0x1.f25b06p2
+  },
+  { // Entry 212
+    -0x1.6dfcbaffd78023ecfabbf7ccf0a0e4b4p-1,
+    0x1.f32218p24
+  },
+  { // Entry 213
+    0x1.6dfcbaffd78023ecfabbf7ccf0a0e4b4p-1,
+    -0x1.f32218p24
+  },
+  { // Entry 214
+    -0x1.ec35cf000061079295ead714892db1cap1,
+    0x1.f44dbcp58
+  },
+  { // Entry 215
+    0x1.ec35cf000061079295ead714892db1cap1,
+    -0x1.f44dbcp58
+  },
+  { // Entry 216
+    0x1.db06c10d2a959715bc0a2e75e6da093bp4,
+    0x1.f47ffep2
+  },
+  { // Entry 217
+    -0x1.db06c10d2a959715bc0a2e75e6da093bp4,
+    -0x1.f47ffep2
+  },
+  { // Entry 218
+    0x1.ffffeb55643b9a648c2720bde1d22764p-1,
+    0x1.f6a7a0p1
+  },
+  { // Entry 219
+    -0x1.ffffeb55643b9a648c2720bde1d22764p-1,
+    -0x1.f6a7a0p1
+  },
+  { // Entry 220
+    0x1.c0a570ffffd379d0972ea78cd040c304p-3,
+    0x1.f6ded8p8
+  },
+  { // Entry 221
+    -0x1.c0a570ffffd379d0972ea78cd040c304p-3,
+    -0x1.f6ded8p8
+  },
+  { // Entry 222
+    -0x1.cdf18d01234809a6895315e9de59d864p-1,
+    0x1.f7ffbep15
+  },
+  { // Entry 223
+    0x1.cdf18d01234809a6895315e9de59d864p-1,
+    -0x1.f7ffbep15
+  },
+  { // Entry 224
+    -0x1.82f196fb60a81dc3b4dcbbc831ab8f85p-1,
+    0x1.f7fffep47
+  },
+  { // Entry 225
+    0x1.82f196fb60a81dc3b4dcbbc831ab8f85p-1,
+    -0x1.f7fffep47
+  },
+  { // Entry 226
+    0x1.6c03590f3fe3b7d29e89ee0e65fc9b1ep0,
+    0x1.f87d58p24
+  },
+  { // Entry 227
+    -0x1.6c03590f3fe3b7d29e89ee0e65fc9b1ep0,
+    -0x1.f87d58p24
+  },
+  { // Entry 228
+    -0x1.c7ae6e9c145b8d54f7719893fa03849fp27,
+    0x1.f9cbe2p7
+  },
+  { // Entry 229
+    0x1.c7ae6e9c145b8d54f7719893fa03849fp27,
+    -0x1.f9cbe2p7
+  },
+  { // Entry 230
+    0x1.6d2910005161b2bfa61134d0fbc9e9c0p0,
+    0x1.fd86bcp24
+  },
+  { // Entry 231
+    -0x1.6d2910005161b2bfa61134d0fbc9e9c0p0,
+    -0x1.fd86bcp24
+  },
+  { // Entry 232
+    0x1.6c8f8d0c3ad4bbb639a3f3a94237f69fp0,
+    0x1.fefa4ap24
+  },
+  { // Entry 233
+    -0x1.6c8f8d0c3ad4bbb639a3f3a94237f69fp0,
+    -0x1.fefa4ap24
+  },
+  { // Entry 234
+    0x1.00e5b5fffa13f7d9c4b0b52fe11a339bp-3,
+    0x1.ff1ffep-4
+  },
+  { // Entry 235
+    -0x1.00e5b5fffa13f7d9c4b0b52fe11a339bp-3,
+    -0x1.ff1ffep-4
+  },
+  { // Entry 236
+    0x1.ff3f41f01c5b360cce75b67877ffd677p0,
+    0x1.ff7ffep41
+  },
+  { // Entry 237
+    -0x1.ff3f41f01c5b360cce75b67877ffd677p0,
+    -0x1.ff7ffep41
+  },
+  { // Entry 238
+    -0x1.86dd5e00d7edc7266969bf5198438babp0,
+    0x1.ff9ffep12
+  },
+  { // Entry 239
+    0x1.86dd5e00d7edc7266969bf5198438babp0,
+    -0x1.ff9ffep12
+  },
+  { // Entry 240
+    -0x1.f8fe4579fdee2491c7d8572ea512fe93p5,
+    0x1.fffbfep45
+  },
+  { // Entry 241
+    0x1.f8fe4579fdee2491c7d8572ea512fe93p5,
+    -0x1.fffbfep45
+  },
+  { // Entry 242
+    -0x1.85ff462f0f86ff44641305da18ea8fc8p-13,
+    0x1.fffdf2p23
+  },
+  { // Entry 243
+    0x1.85ff462f0f86ff44641305da18ea8fc8p-13,
+    -0x1.fffdf2p23
+  },
+  { // Entry 244
+    0x1.3392e2ffbcb25fc1b016b9136e69c00bp-2,
+    0x1.fffdfep3
+  },
+  { // Entry 245
+    -0x1.3392e2ffbcb25fc1b016b9136e69c00bp-2,
+    -0x1.fffdfep3
+  },
+  { // Entry 246
+    -0x1.2f6c4bd2605f037f8609819f865a8dcbp8,
+    0x1.fffe3ep41
+  },
+  { // Entry 247
+    0x1.2f6c4bd2605f037f8609819f865a8dcbp8,
+    -0x1.fffe3ep41
+  },
+  { // Entry 248
+    -0x1.53a2e90e817727255e6ddf64e28c019cp-9,
+    0x1.fffe7ep103
+  },
+  { // Entry 249
+    0x1.53a2e90e817727255e6ddf64e28c019cp-9,
+    -0x1.fffe7ep103
+  },
+  { // Entry 250
+    -0x1.b34676f095b5b1a325426cdf42c04799p2,
+    0x1.ffff7ep2
+  },
+  { // Entry 251
+    0x1.b34676f095b5b1a325426cdf42c04799p2,
+    -0x1.ffff7ep2
+  },
+  { // Entry 252
+    0x1.f640d94e6241db4349e33bed67cbd3dbp-1,
+    0x1.ffff7ep119
+  },
+  { // Entry 253
+    -0x1.f640d94e6241db4349e33bed67cbd3dbp-1,
+    -0x1.ffff7ep119
+  },
+  { // Entry 254
+    0x1.526c269bdda8a89d90706870f3801eafp-1,
+    0x1.ffffeep4
+  },
+  { // Entry 255
+    -0x1.526c269bdda8a89d90706870f3801eafp-1,
+    -0x1.ffffeep4
+  },
+  { // Entry 256
+    -0x1.a37593c105e1462c2a37260603483da6p1,
+    0x1.fffffcp12
+  },
+  { // Entry 257
+    0x1.a37593c105e1462c2a37260603483da6p1,
+    -0x1.fffffcp12
+  },
+  { // Entry 258
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 259
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 260
+    0.0,
+    0.0
+  },
+  { // Entry 261
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 262
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 263
+    -0x1.000002p-126,
+    -0x1.000002p-126
+  },
+  { // Entry 264
+    0x1.000002p-126,
+    0x1.000002p-126
+  },
+  { // Entry 265
+    -0x1.p-126,
+    -0x1.p-126
+  },
+  { // Entry 266
+    0x1.p-126,
+    0x1.p-126
+  },
+  { // Entry 267
+    -0x1.fffffcp-127,
+    -0x1.fffffcp-127
+  },
+  { // Entry 268
+    0x1.fffffcp-127,
+    0x1.fffffcp-127
+  },
+  { // Entry 269
+    0x1.fffffcp-127,
+    0x1.fffffcp-127
+  },
+  { // Entry 270
+    -0x1.fffffcp-127,
+    -0x1.fffffcp-127
+  },
+  { // Entry 271
+    0x1.p-126,
+    0x1.p-126
+  },
+  { // Entry 272
+    -0x1.p-126,
+    -0x1.p-126
+  },
+  { // Entry 273
+    0x1.000002p-126,
+    0x1.000002p-126
+  },
+  { // Entry 274
+    -0x1.000002p-126,
+    -0x1.000002p-126
+  },
+  { // Entry 275
+    0x1.99999a57619f679b6193af8a0a7a8778p-13,
+    0x1.99999ap-13
+  },
+  { // Entry 276
+    -0x1.99999a57619f679b6193af8a0a7a8778p-13,
+    -0x1.99999ap-13
+  },
+  { // Entry 277
+    0x1.99999b5d867eaadd0305587399905311p-12,
+    0x1.99999ap-12
+  },
+  { // Entry 278
+    -0x1.99999b5d867eaadd0305587399905311p-12,
+    -0x1.99999ap-12
+  },
+  { // Entry 279
+    0x1.3333364dd2fb949645bea998cbc1ee72p-11,
+    0x1.333334p-11
+  },
+  { // Entry 280
+    -0x1.3333364dd2fb949645bea998cbc1ee72p-11,
+    -0x1.333334p-11
+  },
+  { // Entry 281
+    0x1.99999f761a0b726c18b00c6496cbe10dp-11,
+    0x1.99999ap-11
+  },
+  { // Entry 282
+    -0x1.99999f761a0b726c18b00c6496cbe10dp-11,
+    -0x1.99999ap-11
+  },
+  { // Entry 283
+    0x1.000005555577777854854dedc28ead51p-10,
+    0x1.p-10
+  },
+  { // Entry 284
+    -0x1.000005555577777854854dedc28ead51p-10,
+    -0x1.p-10
+  },
+  { // Entry 285
+    0x1.33333d374c2e05d108161378389fc84fp-10,
+    0x1.333334p-10
+  },
+  { // Entry 286
+    -0x1.33333d374c2e05d108161378389fc84fp-10,
+    -0x1.333334p-10
+  },
+  { // Entry 287
+    0x1.666676a27a6d8214d198b2321ef9a9dcp-10,
+    0x1.666668p-10
+  },
+  { // Entry 288
+    -0x1.666676a27a6d8214d198b2321ef9a9dcp-10,
+    -0x1.666668p-10
+  },
+  { // Entry 289
+    0x1.9999b1d8698c24cfe3b90ffd006ffdcap-10,
+    0x1.99999cp-10
+  },
+  { // Entry 290
+    -0x1.9999b1d8698c24cfe3b90ffd006ffdcap-10,
+    -0x1.99999cp-10
+  },
+  { // Entry 291
+    0x1.cccceb1aa219f71bb19208d74a739bb1p-10,
+    0x1.ccccccp-10
+  },
+  { // Entry 292
+    -0x1.cccceb1aa219f71bb19208d74a739bb1p-10,
+    -0x1.ccccccp-10
+  },
+  { // Entry 293
+    0x1.0667d5968bbbbe4037024b9c93f7b049p-7,
+    0x1.066666p-7
+  },
+  { // Entry 294
+    -0x1.0667d5968bbbbe4037024b9c93f7b049p-7,
+    -0x1.066666p-7
+  },
+  { // Entry 295
+    0x1.ccd492d035a227758b8c30d79b168826p-7,
+    0x1.ccccccp-7
+  },
+  { // Entry 296
+    -0x1.ccd492d035a227758b8c30d79b168826p-7,
+    -0x1.ccccccp-7
+  },
+  { // Entry 297
+    0x1.49a4fa68e90d228f445026eb29adcefdp-6,
+    0x1.499998p-6
+  },
+  { // Entry 298
+    -0x1.49a4fa68e90d228f445026eb29adcefdp-6,
+    -0x1.499998p-6
+  },
+  { // Entry 299
+    0x1.ace5de090603fda8f519afece05c17eap-6,
+    0x1.acccccp-6
+  },
+  { // Entry 300
+    -0x1.ace5de090603fda8f519afece05c17eap-6,
+    -0x1.acccccp-6
+  },
+  { // Entry 301
+    0x1.081767fd3cb685f7b069146ce3333851p-5,
+    0x1.08p-5
+  },
+  { // Entry 302
+    -0x1.081767fd3cb685f7b069146ce3333851p-5,
+    -0x1.08p-5
+  },
+  { // Entry 303
+    0x1.39c0d745334a3387d672e4a05624bca5p-5,
+    0x1.39999ap-5
+  },
+  { // Entry 304
+    -0x1.39c0d745334a3387d672e4a05624bca5p-5,
+    -0x1.39999ap-5
+  },
+  { // Entry 305
+    0x1.6b702c627fc00b777ea8661cce36061cp-5,
+    0x1.6b3334p-5
+  },
+  { // Entry 306
+    -0x1.6b702c627fc00b777ea8661cce36061cp-5,
+    -0x1.6b3334p-5
+  },
+  { // Entry 307
+    0x1.9d26574cd84759bfff51d8bb18538a0dp-5,
+    0x1.9ccccep-5
+  },
+  { // Entry 308
+    -0x1.9d26574cd84759bfff51d8bb18538a0dp-5,
+    -0x1.9ccccep-5
+  },
+  { // Entry 309
+    0x1.cee4467e15bb7ef59658a8eddc195167p-5,
+    0x1.ce6666p-5
+  },
+  { // Entry 310
+    -0x1.cee4467e15bb7ef59658a8eddc195167p-5,
+    -0x1.ce6666p-5
+  },
+  { // Entry 311
+    0x1.a1eaed7aa62a740c0b2e09bcd0f735b5p-1,
+    0x1.5e7fc4p-1
+  },
+  { // Entry 312
+    -0x1.a1eaed7aa62a740c0b2e09bcd0f735b5p-1,
+    -0x1.5e7fc4p-1
+  },
+  { // Entry 313
+    0x1.d93b891cbcb15aac8b5796a0a16bf29ep1,
+    0x1.4e7fc4p0
+  },
+  { // Entry 314
+    -0x1.d93b891cbcb15aac8b5796a0a16bf29ep1,
+    -0x1.4e7fc4p0
+  },
+  { // Entry 315
+    -0x1.563ad063486c797653a68955c0bb1c0bp1,
+    0x1.edbfa6p0
+  },
+  { // Entry 316
+    0x1.563ad063486c797653a68955c0bb1c0bp1,
+    -0x1.edbfa6p0
+  },
+  { // Entry 317
+    -0x1.576b789d544b6d037c3b7119fd6dd6p-1,
+    0x1.467fc4p1
+  },
+  { // Entry 318
+    0x1.576b789d544b6d037c3b7119fd6dd6p-1,
+    -0x1.467fc4p1
+  },
+  { // Entry 319
+    0x1.00150652b2d7931e0c878875b9f4ba82p-5,
+    0x1.961fb4p1
+  },
+  { // Entry 320
+    -0x1.00150652b2d7931e0c878875b9f4ba82p-5,
+    -0x1.961fb4p1
+  },
+  { // Entry 321
+    0x1.87e987b6e5071dbd3f755a76a27d8fc8p-1,
+    0x1.e5bfa4p1
+  },
+  { // Entry 322
+    -0x1.87e987b6e5071dbd3f755a76a27d8fc8p-1,
+    -0x1.e5bfa4p1
+  },
+  { // Entry 323
+    0x1.a49e55bce1c8991232387ecd1124698ap1,
+    0x1.1aafcap2
+  },
+  { // Entry 324
+    -0x1.a49e55bce1c8991232387ecd1124698ap1,
+    -0x1.1aafcap2
+  },
+  { // Entry 325
+    -0x1.79cf03135a93679d5aa2e1dcc5adedafp1,
+    0x1.427fc2p2
+  },
+  { // Entry 326
+    0x1.79cf03135a93679d5aa2e1dcc5adedafp1,
+    -0x1.427fc2p2
+  },
+  { // Entry 327
+    -0x1.6f1f86fdb20bc9923627b94d771f5388p-1,
+    0x1.6a4fbap2
+  },
+  { // Entry 328
+    0x1.6f1f86fdb20bc9923627b94d771f5388p-1,
+    -0x1.6a4fbap2
+  },
+  { // Entry 329
+    -0x1.67747ca802821c66c87a086638f28d36p-1,
+    0x1.6af2f0p2
+  },
+  { // Entry 330
+    0x1.67747ca802821c66c87a086638f28d36p-1,
+    -0x1.6af2f0p2
+  },
+  { // Entry 331
+    -0x1.626a30298df0c42c2cf7a8f9c166d55dp1,
+    0x1.43c62ap2
+  },
+  { // Entry 332
+    0x1.626a30298df0c42c2cf7a8f9c166d55dp1,
+    -0x1.43c62ap2
+  },
+  { // Entry 333
+    0x1.d6ad8a22a4407cc68df20cda1ea1c6aap1,
+    0x1.1c9964p2
+  },
+  { // Entry 334
+    -0x1.d6ad8a22a4407cc68df20cda1ea1c6aap1,
+    -0x1.1c9964p2
+  },
+  { // Entry 335
+    0x1.a94d00a1710d9bcc7b80481f42857d05p-1,
+    0x1.ead93cp1
+  },
+  { // Entry 336
+    -0x1.a94d00a1710d9bcc7b80481f42857d05p-1,
+    -0x1.ead93cp1
+  },
+  { // Entry 337
+    0x1.4cb9f4d315a995b28bfbd6e6a0905738p-4,
+    0x1.9c7fb0p1
+  },
+  { // Entry 338
+    -0x1.4cb9f4d315a995b28bfbd6e6a0905738p-4,
+    -0x1.9c7fb0p1
+  },
+  { // Entry 339
+    -0x1.2cb6f3ba51cd4ca385d7f4a7567c3a0bp-1,
+    0x1.4e2624p1
+  },
+  { // Entry 340
+    0x1.2cb6f3ba51cd4ca385d7f4a7567c3a0bp-1,
+    -0x1.4e2624p1
+  },
+  { // Entry 341
+    -0x1.18d9399a8290b3f8b42a4afc1f4b21dep1,
+    0x1.ff9932p0
+  },
+  { // Entry 342
+    0x1.18d9399a8290b3f8b42a4afc1f4b21dep1,
+    -0x1.ff9932p0
+  },
+  { // Entry 343
+    0x1.56fd94b0c0681613d3831608457f5bf6p2,
+    0x1.62e61cp0
+  },
+  { // Entry 344
+    -0x1.56fd94b0c0681613d3831608457f5bf6p2,
+    -0x1.62e61cp0
+  },
+  { // Entry 345
+    0x1.f4ad37f13e818641fc1555bf78e0e942p-1,
+    0x1.8c662cp-1
+  },
+  { // Entry 346
+    -0x1.f4ad37f13e818641fc1555bf78e0e942p-1,
+    -0x1.8c662cp-1
+  },
+  { // Entry 347
+    0x1.6a7e30ad8460f1a710479e2db9495c9cp3,
+    -0x1.a8aa1cp0
+  },
+  { // Entry 348
+    -0x1.6a7e30ad8460f1a710479e2db9495c9cp3,
+    0x1.a8aa1cp0
+  },
+  { // Entry 349
+    0x1.0d71ffac1d5e6aa753cf804a2a8c1f5bp6,
+    -0x1.95ec8ap0
+  },
+  { // Entry 350
+    -0x1.0d71ffac1d5e6aa753cf804a2a8c1f5bp6,
+    0x1.95ec8ap0
+  },
+  { // Entry 351
+    -0x1.11d8498073e1f4b776fe5672abb1f54ap4,
+    -0x1.832ef8p0
+  },
+  { // Entry 352
+    0x1.11d8498073e1f4b776fe5672abb1f54ap4,
+    0x1.832ef8p0
+  },
+  { // Entry 353
+    -0x1.e3a34b32708883a8578805f84ea03c6ap2,
+    -0x1.707166p0
+  },
+  { // Entry 354
+    0x1.e3a34b32708883a8578805f84ea03c6ap2,
+    0x1.707166p0
+  },
+  { // Entry 355
+    -0x1.3429d2634054eaae3bdbee94a6cec17fp2,
+    -0x1.5db3d4p0
+  },
+  { // Entry 356
+    0x1.3429d2634054eaae3bdbee94a6cec17fp2,
+    0x1.5db3d4p0
+  },
+  { // Entry 357
+    -0x1.c08c957bbb45acafa856bfd792cbf663p1,
+    -0x1.4af642p0
+  },
+  { // Entry 358
+    0x1.c08c957bbb45acafa856bfd792cbf663p1,
+    0x1.4af642p0
+  },
+  { // Entry 359
+    -0x1.5d602b0d0bdda825221a53369c5338d7p1,
+    -0x1.3838b0p0
+  },
+  { // Entry 360
+    0x1.5d602b0d0bdda825221a53369c5338d7p1,
+    0x1.3838b0p0
+  },
+  { // Entry 361
+    -0x1.1b4894e498720ec01735a02e55eefad8p1,
+    -0x1.257b1ep0
+  },
+  { // Entry 362
+    0x1.1b4894e498720ec01735a02e55eefad8p1,
+    0x1.257b1ep0
+  },
+  { // Entry 363
+    -0x1.d74cb200ab59040290627a9b2ffe29cfp0,
+    -0x1.12bd92p0
+  },
+  { // Entry 364
+    0x1.d74cb200ab59040290627a9b2ffe29cfp0,
+    0x1.12bd92p0
+  },
+  { // Entry 365
+    -0x1.6be7019f34d34f25cb0c14d0c7bc7b32p0,
+    -0x1.ea5c3ep-1
+  },
+  { // Entry 366
+    0x1.6be7019f34d34f25cb0c14d0c7bc7b32p0,
+    0x1.ea5c3ep-1
+  },
+  { // Entry 367
+    -0x1.4d0defbcb48aa75ce13e1b82f1fcb049p0,
+    -0x1.d4b87cp-1
+  },
+  { // Entry 368
+    0x1.4d0defbcb48aa75ce13e1b82f1fcb049p0,
+    0x1.d4b87cp-1
+  },
+  { // Entry 369
+    -0x1.316c87fdb7599cb57354e4b99f38d7ffp0,
+    -0x1.bf14bap-1
+  },
+  { // Entry 370
+    0x1.316c87fdb7599cb57354e4b99f38d7ffp0,
+    0x1.bf14bap-1
+  },
+  { // Entry 371
+    -0x1.18729dfe51dfcf767f79f39b689ae95ep0,
+    -0x1.a970f8p-1
+  },
+  { // Entry 372
+    0x1.18729dfe51dfcf767f79f39b689ae95ep0,
+    0x1.a970f8p-1
+  },
+  { // Entry 373
+    -0x1.01aeea9cbe9a8fb4ccef99ad961b6ad8p0,
+    -0x1.93cd36p-1
+  },
+  { // Entry 374
+    0x1.01aeea9cbe9a8fb4ccef99ad961b6ad8p0,
+    0x1.93cd36p-1
+  },
+  { // Entry 375
+    -0x1.d98e373faad7da3d6c8865a7ff9ba7f3p-1,
+    -0x1.7e2974p-1
+  },
+  { // Entry 376
+    0x1.d98e373faad7da3d6c8865a7ff9ba7f3p-1,
+    0x1.7e2974p-1
+  },
+  { // Entry 377
+    -0x1.b2e46af704eb75d1fab0766afc74703fp-1,
+    -0x1.6885b2p-1
+  },
+  { // Entry 378
+    0x1.b2e46af704eb75d1fab0766afc74703fp-1,
+    0x1.6885b2p-1
+  },
+  { // Entry 379
+    -0x1.8ee90b7dc89b1f999ae6dbb41baceb0dp-1,
+    -0x1.52e1f0p-1
+  },
+  { // Entry 380
+    0x1.8ee90b7dc89b1f999ae6dbb41baceb0dp-1,
+    0x1.52e1f0p-1
+  },
+  { // Entry 381
+    -0x1.6d395f05820b42f51223dab884367e71p-1,
+    -0x1.3d3e36p-1
+  },
+  { // Entry 382
+    0x1.6d395f05820b42f51223dab884367e71p-1,
+    0x1.3d3e36p-1
+  },
+  { // Entry 383
+    -0x1.24e3dfad4ce1493caa123864cb4f45d3p-1,
+    -0x1.0a0b02p-1
+  },
+  { // Entry 384
+    0x1.24e3dfad4ce1493caa123864cb4f45d3p-1,
+    0x1.0a0b02p-1
+  },
+  { // Entry 385
+    -0x1.fdbd5e53e0a6fc9c8b803289f1c3dbb7p-2,
+    -0x1.d8f720p-2
+  },
+  { // Entry 386
+    0x1.fdbd5e53e0a6fc9c8b803289f1c3dbb7p-2,
+    0x1.d8f720p-2
+  },
+  { // Entry 387
+    -0x1.b5f3d61c54ee4f6585e9bff489c00182p-2,
+    -0x1.9dd83cp-2
+  },
+  { // Entry 388
+    0x1.b5f3d61c54ee4f6585e9bff489c00182p-2,
+    0x1.9dd83cp-2
+  },
+  { // Entry 389
+    -0x1.71a0f907c661daf4903b7bbc015c5c14p-2,
+    -0x1.62b958p-2
+  },
+  { // Entry 390
+    0x1.71a0f907c661daf4903b7bbc015c5c14p-2,
+    0x1.62b958p-2
+  },
+  { // Entry 391
+    -0x1.30190941e699fdb2115a9ef6bf82d455p-2,
+    -0x1.279a74p-2
+  },
+  { // Entry 392
+    0x1.30190941e699fdb2115a9ef6bf82d455p-2,
+    0x1.279a74p-2
+  },
+  { // Entry 393
+    -0x1.e18e93867caf67efcaa19821898d50cap-3,
+    -0x1.d8f720p-3
+  },
+  { // Entry 394
+    0x1.e18e93867caf67efcaa19821898d50cap-3,
+    0x1.d8f720p-3
+  },
+  { // Entry 395
+    -0x1.665077dda822b189a56a02e15c04d5d4p-3,
+    -0x1.62b958p-3
+  },
+  { // Entry 396
+    0x1.665077dda822b189a56a02e15c04d5d4p-3,
+    0x1.62b958p-3
+  },
+  { // Entry 397
+    -0x1.db1423d877b250af6ea5546960743d72p-4,
+    -0x1.d8f720p-4
+  },
+  { // Entry 398
+    0x1.db1423d877b250af6ea5546960743d72p-4,
+    0x1.d8f720p-4
+  },
+  { // Entry 399
+    -0x1.d97dd643ffeef57d0a225051978ec8adp-5,
+    -0x1.d8f720p-5
+  },
+  { // Entry 400
+    0x1.d97dd643ffeef57d0a225051978ec8adp-5,
+    0x1.d8f720p-5
+  },
+  { // Entry 401
+    0x1.d97dd643ffeef57d0a225051978ec8adp-5,
+    0x1.d8f720p-5
+  },
+  { // Entry 402
+    -0x1.d97dd643ffeef57d0a225051978ec8adp-5,
+    -0x1.d8f720p-5
+  },
+  { // Entry 403
+    0x1.db1423d877b250af6ea5546960743d72p-4,
+    0x1.d8f720p-4
+  },
+  { // Entry 404
+    -0x1.db1423d877b250af6ea5546960743d72p-4,
+    -0x1.d8f720p-4
+  },
+  { // Entry 405
+    0x1.665077dda822b189a56a02e15c04d5d4p-3,
+    0x1.62b958p-3
+  },
+  { // Entry 406
+    -0x1.665077dda822b189a56a02e15c04d5d4p-3,
+    -0x1.62b958p-3
+  },
+  { // Entry 407
+    0x1.e18e93867caf67efcaa19821898d50cap-3,
+    0x1.d8f720p-3
+  },
+  { // Entry 408
+    -0x1.e18e93867caf67efcaa19821898d50cap-3,
+    -0x1.d8f720p-3
+  },
+  { // Entry 409
+    0x1.30190941e699fdb2115a9ef6bf82d455p-2,
+    0x1.279a74p-2
+  },
+  { // Entry 410
+    -0x1.30190941e699fdb2115a9ef6bf82d455p-2,
+    -0x1.279a74p-2
+  },
+  { // Entry 411
+    0x1.71a0f907c661daf4903b7bbc015c5c14p-2,
+    0x1.62b958p-2
+  },
+  { // Entry 412
+    -0x1.71a0f907c661daf4903b7bbc015c5c14p-2,
+    -0x1.62b958p-2
+  },
+  { // Entry 413
+    0x1.b5f3d61c54ee4f6585e9bff489c00182p-2,
+    0x1.9dd83cp-2
+  },
+  { // Entry 414
+    -0x1.b5f3d61c54ee4f6585e9bff489c00182p-2,
+    -0x1.9dd83cp-2
+  },
+  { // Entry 415
+    0x1.fdbd5e53e0a6fc9c8b803289f1c3dbb7p-2,
+    0x1.d8f720p-2
+  },
+  { // Entry 416
+    -0x1.fdbd5e53e0a6fc9c8b803289f1c3dbb7p-2,
+    -0x1.d8f720p-2
+  },
+  { // Entry 417
+    0x1.24e3dfad4ce1493caa123864cb4f45d3p-1,
+    0x1.0a0b02p-1
+  },
+  { // Entry 418
+    -0x1.24e3dfad4ce1493caa123864cb4f45d3p-1,
+    -0x1.0a0b02p-1
+  },
+  { // Entry 419
+    0x1.6d395f05820b42f51223dab884367e71p-1,
+    0x1.3d3e36p-1
+  },
+  { // Entry 420
+    -0x1.6d395f05820b42f51223dab884367e71p-1,
+    -0x1.3d3e36p-1
+  },
+  { // Entry 421
+    0x1.8ee91858fbaaf2a34a32dd947fd7e076p-1,
+    0x1.52e1f8p-1
+  },
+  { // Entry 422
+    -0x1.8ee91858fbaaf2a34a32dd947fd7e076p-1,
+    -0x1.52e1f8p-1
+  },
+  { // Entry 423
+    0x1.b2e478bc9ba738db90b2a4bc294ecf4fp-1,
+    0x1.6885bap-1
+  },
+  { // Entry 424
+    -0x1.b2e478bc9ba738db90b2a4bc294ecf4fp-1,
+    -0x1.6885bap-1
+  },
+  { // Entry 425
+    0x1.d98e4617a8bd1a1bb9e2e989d8ad35ccp-1,
+    0x1.7e297cp-1
+  },
+  { // Entry 426
+    -0x1.d98e4617a8bd1a1bb9e2e989d8ad35ccp-1,
+    -0x1.7e297cp-1
+  },
+  { // Entry 427
+    0x1.01aef2aa416545e3900864f2b35d86a6p0,
+    0x1.93cd3ep-1
+  },
+  { // Entry 428
+    -0x1.01aef2aa416545e3900864f2b35d86a6p0,
+    -0x1.93cd3ep-1
+  },
+  { // Entry 429
+    0x1.1872a6cb3dba156db8dc784e95d96a46p0,
+    0x1.a971p-1
+  },
+  { // Entry 430
+    -0x1.1872a6cb3dba156db8dc784e95d96a46p0,
+    -0x1.a971p-1
+  },
+  { // Entry 431
+    0x1.316c91af46b015a9c931a816fed89092p0,
+    0x1.bf14c2p-1
+  },
+  { // Entry 432
+    -0x1.316c91af46b015a9c931a816fed89092p0,
+    -0x1.bf14c2p-1
+  },
+  { // Entry 433
+    0x1.4d0dfa81e9cc806c10194fba6b767761p0,
+    0x1.d4b884p-1
+  },
+  { // Entry 434
+    -0x1.4d0dfa81e9cc806c10194fba6b767761p0,
+    -0x1.d4b884p-1
+  },
+  { // Entry 435
+    0x1.6be7019f34d34f25cb0c14d0c7bc7b32p0,
+    0x1.ea5c3ep-1
+  },
+  { // Entry 436
+    -0x1.6be7019f34d34f25cb0c14d0c7bc7b32p0,
+    -0x1.ea5c3ep-1
+  },
+  { // Entry 437
+    0x1.d74cb200ab59040290627a9b2ffe29cfp0,
+    0x1.12bd92p0
+  },
+  { // Entry 438
+    -0x1.d74cb200ab59040290627a9b2ffe29cfp0,
+    -0x1.12bd92p0
+  },
+  { // Entry 439
+    0x1.1b48a6964c024648f186bb6b1ebdeec2p1,
+    0x1.257b24p0
+  },
+  { // Entry 440
+    -0x1.1b48a6964c024648f186bb6b1ebdeec2p1,
+    -0x1.257b24p0
+  },
+  { // Entry 441
+    0x1.5d604466c5aee8f1a1d8470f7ff579cfp1,
+    0x1.3838b6p0
+  },
+  { // Entry 442
+    -0x1.5d604466c5aee8f1a1d8470f7ff579cfp1,
+    -0x1.3838b6p0
+  },
+  { // Entry 443
+    0x1.c08cbd52d2b012f0cb47bcb3ff513c6dp1,
+    0x1.4af648p0
+  },
+  { // Entry 444
+    -0x1.c08cbd52d2b012f0cb47bcb3ff513c6dp1,
+    -0x1.4af648p0
+  },
+  { // Entry 445
+    0x1.3429f6aa3446d703e6ef96e0b564fc0cp2,
+    0x1.5db3dap0
+  },
+  { // Entry 446
+    -0x1.3429f6aa3446d703e6ef96e0b564fc0cp2,
+    -0x1.5db3dap0
+  },
+  { // Entry 447
+    0x1.e3a3a25b2606418a13970971beef41d6p2,
+    0x1.70716cp0
+  },
+  { // Entry 448
+    -0x1.e3a3a25b2606418a13970971beef41d6p2,
+    -0x1.70716cp0
+  },
+  { // Entry 449
+    0x1.11d8b7ba41694658111af48925bbad68p4,
+    0x1.832efep0
+  },
+  { // Entry 450
+    -0x1.11d8b7ba41694658111af48925bbad68p4,
+    -0x1.832efep0
+  },
+  { // Entry 451
+    -0x1.0d70563193fe219f3fd31a285f4d6638p6,
+    0x1.95ec90p0
+  },
+  { // Entry 452
+    0x1.0d70563193fe219f3fd31a285f4d6638p6,
+    -0x1.95ec90p0
+  },
+  { // Entry 453
+    -0x1.6a7e30ad8460f1a710479e2db9495c9cp3,
+    0x1.a8aa1cp0
+  },
+  { // Entry 454
+    0x1.6a7e30ad8460f1a710479e2db9495c9cp3,
+    -0x1.a8aa1cp0
+  },
+  { // Entry 455
+    0x1.9f39ee9fedb2375ec05d6da7a288c6bdp0,
+    0x1.04aff8p0
+  },
+  { // Entry 456
+    -0x1.9f39ee9fedb2375ec05d6da7a288c6bdp0,
+    -0x1.04aff8p0
+  },
+  { // Entry 457
+    0x1.9f3c509c6a7d75e451088359c88def88p0,
+    0x1.04b0a0p0
+  },
+  { // Entry 458
+    -0x1.9f3c509c6a7d75e451088359c88def88p0,
+    -0x1.04b0a0p0
+  },
+  { // Entry 459
+    0x1.9f3eb29df9e6a20467474e24d8bf35bap0,
+    0x1.04b148p0
+  },
+  { // Entry 460
+    -0x1.9f3eb29df9e6a20467474e24d8bf35bap0,
+    -0x1.04b148p0
+  },
+  { // Entry 461
+    0x1.9f4114a49bfffc3f5a183d36000aa785p0,
+    0x1.04b1f0p0
+  },
+  { // Entry 462
+    -0x1.9f4114a49bfffc3f5a183d36000aa785p0,
+    -0x1.04b1f0p0
+  },
+  { // Entry 463
+    0x1.9f4376b050dbc56bf5596083192077b5p0,
+    0x1.04b298p0
+  },
+  { // Entry 464
+    -0x1.9f4376b050dbc56bf5596083192077b5p0,
+    -0x1.04b298p0
+  },
+  { // Entry 465
+    0x1.9f45d8c1188c3eb77bca2c4a84c7eaddp0,
+    0x1.04b340p0
+  },
+  { // Entry 466
+    -0x1.9f45d8c1188c3eb77bca2c4a84c7eaddp0,
+    -0x1.04b340p0
+  },
+  { // Entry 467
+    0x1.9f483ad6f323a9a5a90d4ae07a23d266p0,
+    0x1.04b3e8p0
+  },
+  { // Entry 468
+    -0x1.9f483ad6f323a9a5a90d4ae07a23d266p0,
+    -0x1.04b3e8p0
+  },
+  { // Entry 469
+    0x1.9f4a9cf1e0b44810b3aa7cca45d71cc9p0,
+    0x1.04b490p0
+  },
+  { // Entry 470
+    -0x1.9f4a9cf1e0b44810b3aa7cca45d71cc9p0,
+    -0x1.04b490p0
+  },
+  { // Entry 471
+    0x1.9f4cf08af6c60ed6e2badd5a7b5c1e87p0,
+    0x1.04b534p0
+  },
+  { // Entry 472
+    -0x1.9f4cf08af6c60ed6e2badd5a7b5c1e87p0,
+    -0x1.04b534p0
+  },
+  { // Entry 473
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 474
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 475
+    0.0,
+    0.0
+  },
+  { // Entry 476
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 477
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 478
+    0x1.4d82b334a582a56a802f96b3b96feb81p-1,
+    0x1.279a72p-1
+  },
+  { // Entry 479
+    -0x1.4d82b334a582a56a802f96b3b96feb81p-1,
+    -0x1.279a72p-1
+  },
+  { // Entry 480
+    0x1.4d82b60de428f92aa8c96a4a7fe88945p-1,
+    0x1.279a74p-1
+  },
+  { // Entry 481
+    -0x1.4d82b60de428f92aa8c96a4a7fe88945p-1,
+    -0x1.279a74p-1
+  },
+  { // Entry 482
+    0x1.4d82b8e722d302f5aa939a563b12b1a1p-1,
+    0x1.279a76p-1
+  },
+  { // Entry 483
+    -0x1.4d82b8e722d302f5aa939a563b12b1a1p-1,
+    -0x1.279a76p-1
+  },
+  { // Entry 484
+    -0x1.89714760e8fed9af03a91cf1527ceaadp2,
+    0x1.bb67acp0
+  },
+  { // Entry 485
+    0x1.89714760e8fed9af03a91cf1527ceaadp2,
+    -0x1.bb67acp0
+  },
+  { // Entry 486
+    -0x1.897133fb81f3169b3161d50b50ccc1a7p2,
+    0x1.bb67aep0
+  },
+  { // Entry 487
+    0x1.897133fb81f3169b3161d50b50ccc1a7p2,
+    -0x1.bb67aep0
+  },
+  { // Entry 488
+    -0x1.897120961cc4475eb3b8061df0409430p2,
+    0x1.bb67b0p0
+  },
+  { // Entry 489
+    0x1.897120961cc4475eb3b8061df0409430p2,
+    -0x1.bb67b0p0
+  },
+  { // Entry 490
+    0x1.def49c3ab0ad5dde93ba34c54db714c7p-2,
+    0x1.bffffep-2
+  },
+  { // Entry 491
+    -0x1.def49c3ab0ad5dde93ba34c54db714c7p-2,
+    -0x1.bffffep-2
+  },
+  { // Entry 492
+    0x1.def49eaab37a1479231e899509ecf26cp-2,
+    0x1.c0p-2
+  },
+  { // Entry 493
+    -0x1.def49eaab37a1479231e899509ecf26cp-2,
+    -0x1.c0p-2
+  },
+  { // Entry 494
+    0x1.def4a11ab647eef212b1997d3b51405ap-2,
+    0x1.c00002p-2
+  },
+  { // Entry 495
+    -0x1.def4a11ab647eef212b1997d3b51405ap-2,
+    -0x1.c00002p-2
+  },
+  { // Entry 496
+    0x1.a46caf652fa18987e4d0a79f8145dd5bp-1,
+    0x1.5ffffep-1
+  },
+  { // Entry 497
+    -0x1.a46caf652fa18987e4d0a79f8145dd5bp-1,
+    -0x1.5ffffep-1
+  },
+  { // Entry 498
+    0x1.a46cb2be6a0b1dacb36269c41a4a9147p-1,
+    0x1.60p-1
+  },
+  { // Entry 499
+    -0x1.a46cb2be6a0b1dacb36269c41a4a9147p-1,
+    -0x1.60p-1
+  },
+  { // Entry 500
+    0x1.a46cb617a47a31a156dc0005b4e6ebp-1,
+    0x1.600002p-1
+  },
+  { // Entry 501
+    -0x1.a46cb617a47a31a156dc0005b4e6ebp-1,
+    -0x1.600002p-1
+  },
+  { // Entry 502
+    0x1.3d6dc230869c70d5937fedc92d424df2p1,
+    0x1.2ffffep0
+  },
+  { // Entry 503
+    -0x1.3d6dc230869c70d5937fedc92d424df2p1,
+    -0x1.2ffffep0
+  },
+  { // Entry 504
+    0x1.3d6dc956eac7d3b8d6eb2174110d1ddcp1,
+    0x1.30p0
+  },
+  { // Entry 505
+    -0x1.3d6dc956eac7d3b8d6eb2174110d1ddcp1,
+    -0x1.30p0
+  },
+  { // Entry 506
+    0x1.3d6dd07d4f3a237589ad5c41c3801cb4p1,
+    0x1.300002p0
+  },
+  { // Entry 507
+    -0x1.3d6dd07d4f3a237589ad5c41c3801cb4p1,
+    -0x1.300002p0
+  },
+  { // Entry 508
+    -0x1.b2d8a858c90a538d1daad78040e69b98p-1,
+    0x1.37fffep1
+  },
+  { // Entry 509
+    0x1.b2d8a858c90a538d1daad78040e69b98p-1,
+    -0x1.37fffep1
+  },
+  { // Entry 510
+    -0x1.b2d89a938294c8a2604db9f7aa56a0f8p-1,
+    0x1.38p1
+  },
+  { // Entry 511
+    0x1.b2d89a938294c8a2604db9f7aa56a0f8p-1,
+    -0x1.38p1
+  },
+  { // Entry 512
+    -0x1.b2d88cce3c7cce174266439da309cf60p-1,
+    0x1.380002p1
+  },
+  { // Entry 513
+    0x1.b2d88cce3c7cce174266439da309cf60p-1,
+    -0x1.380002p1
+  },
+  { // Entry 514
+    0x1.06f8d0cecf169b06467e4aa036cf8279p-4,
+    0x1.069c8cp-4
+  },
+  { // Entry 515
+    -0x1.06f8d0cecf169b06467e4aa036cf8279p-4,
+    -0x1.069c8cp-4
+  },
+  { // Entry 516
+    0x1.080f746cd17397b60f908e2be01f7ba7p-3,
+    0x1.069c8cp-3
+  },
+  { // Entry 517
+    -0x1.080f746cd17397b60f908e2be01f7ba7p-3,
+    -0x1.069c8cp-3
+  },
+  { // Entry 518
+    0x1.8ed91550469d0eb08aae20658958043bp-3,
+    0x1.89ead2p-3
+  },
+  { // Entry 519
+    -0x1.8ed91550469d0eb08aae20658958043bp-3,
+    -0x1.89ead2p-3
+  },
+  { // Entry 520
+    0x1.0c864149dc68276df299282d04f69af6p-2,
+    0x1.069c8cp-2
+  },
+  { // Entry 521
+    -0x1.0c864149dc68276df299282d04f69af6p-2,
+    -0x1.069c8cp-2
+  },
+  { // Entry 522
+    0x1.53fdd01a98f07f208555cc644276ef2cp-2,
+    0x1.4843b0p-2
+  },
+  { // Entry 523
+    -0x1.53fdd01a98f07f208555cc644276ef2cp-2,
+    -0x1.4843b0p-2
+  },
+  { // Entry 524
+    0x1.9e925b7e237b88ac6098b513c371757cp-2,
+    0x1.89ead4p-2
+  },
+  { // Entry 525
+    -0x1.9e925b7e237b88ac6098b513c371757cp-2,
+    -0x1.89ead4p-2
+  },
+  { // Entry 526
+    0x1.ed21eadb08e47db8b2f11880fbb52879p-2,
+    0x1.cb91f8p-2
+  },
+  { // Entry 527
+    -0x1.ed21eadb08e47db8b2f11880fbb52879p-2,
+    -0x1.cb91f8p-2
+  },
+  { // Entry 528
+    0x1.205a63a04e31e1852af3da22e9f69a19p-1,
+    0x1.069c8ep-1
+  },
+  { // Entry 529
+    -0x1.205a63a04e31e1852af3da22e9f69a19p-1,
+    -0x1.069c8ep-1
+  },
+  { // Entry 530
+    0x1.4d466f84a3288515ab699dd1cec345d3p-1,
+    0x1.277020p-1
+  },
+  { // Entry 531
+    -0x1.4d466f84a3288515ab699dd1cec345d3p-1,
+    -0x1.277020p-1
+  },
+  { // Entry 532
+    0x1.7e1d9983b58754a29012e17a26f277d7p-1,
+    0x1.4843b2p-1
+  },
+  { // Entry 533
+    -0x1.7e1d9983b58754a29012e17a26f277d7p-1,
+    -0x1.4843b2p-1
+  },
+  { // Entry 534
+    0x1.b3df402fe49842a4164cf380ffa5dcp-1,
+    0x1.691744p-1
+  },
+  { // Entry 535
+    -0x1.b3df402fe49842a4164cf380ffa5dcp-1,
+    -0x1.691744p-1
+  },
+  { // Entry 536
+    0x1.efd8311ddf2cc393f20ea767c7b2264ap-1,
+    0x1.89ead6p-1
+  },
+  { // Entry 537
+    -0x1.efd8311ddf2cc393f20ea767c7b2264ap-1,
+    -0x1.89ead6p-1
+  },
+  { // Entry 538
+    0x1.19e271a6444ff34aa2f73c85014971c9p0,
+    0x1.aabe68p-1
+  },
+  { // Entry 539
+    -0x1.19e271a6444ff34aa2f73c85014971c9p0,
+    -0x1.aabe68p-1
+  },
+  { // Entry 540
+    0x1.410393802c1a22382914abf096afbee9p0,
+    0x1.cb91fap-1
+  },
+  { // Entry 541
+    -0x1.410393802c1a22382914abf096afbee9p0,
+    -0x1.cb91fap-1
+  },
+  { // Entry 542
+    0x1.6efed33b714045fe99cfa59471e1e9fdp0,
+    0x1.ec658cp-1
+  },
+  { // Entry 543
+    -0x1.6efed33b714045fe99cfa59471e1e9fdp0,
+    -0x1.ec658cp-1
+  },
+  { // Entry 544
+    0x1.a64c86c02e7a7d96e91f96a5584129f4p0,
+    0x1.069c8ep0
+  },
+  { // Entry 545
+    -0x1.a64c86c02e7a7d96e91f96a5584129f4p0,
+    -0x1.069c8ep0
+  },
+  { // Entry 546
+    0x1.eab4477e5b226dc5270bae9720ea13e3p0,
+    0x1.170656p0
+  },
+  { // Entry 547
+    -0x1.eab4477e5b226dc5270bae9720ea13e3p0,
+    -0x1.170656p0
+  },
+  { // Entry 548
+    0x1.21277f9a7d2f66bb131cff32f26629cdp1,
+    0x1.27701ep0
+  },
+  { // Entry 549
+    -0x1.21277f9a7d2f66bb131cff32f26629cdp1,
+    -0x1.27701ep0
+  },
+  { // Entry 550
+    0x1.5bd1406825b3ffeba48221ad6a8f5414p1,
+    0x1.37d9e6p0
+  },
+  { // Entry 551
+    -0x1.5bd1406825b3ffeba48221ad6a8f5414p1,
+    -0x1.37d9e6p0
+  },
+  { // Entry 552
+    0x1.af464352a989f802824152cad0afe8b7p1,
+    0x1.4843aep0
+  },
+  { // Entry 553
+    -0x1.af464352a989f802824152cad0afe8b7p1,
+    -0x1.4843aep0
+  },
+  { // Entry 554
+    0x1.1866fa7a601b87bb6f378b3438e3fc26p2,
+    0x1.58ad76p0
+  },
+  { // Entry 555
+    -0x1.1866fa7a601b87bb6f378b3438e3fc26p2,
+    -0x1.58ad76p0
+  },
+  { // Entry 556
+    0x1.8bdcc68718a70118860a1b945437fd90p2,
+    0x1.69173ep0
+  },
+  { // Entry 557
+    -0x1.8bdcc68718a70118860a1b945437fd90p2,
+    -0x1.69173ep0
+  },
+  { // Entry 558
+    0x1.4bb68859d3eafb2a130b73ba07e48e8ap3,
+    0x1.798106p0
+  },
+  { // Entry 559
+    -0x1.4bb68859d3eafb2a130b73ba07e48e8ap3,
+    -0x1.798106p0
+  },
+  { // Entry 560
+    0x1.f2efabaeb322ec5ca9d33869295c6063p4,
+    0x1.89eacep0
+  },
+  { // Entry 561
+    -0x1.f2efabaeb322ec5ca9d33869295c6063p4,
+    -0x1.89eacep0
+  },
+  { // Entry 562
+    -0x1.f2f13929323ef8f58db152143e65bcb7p4,
+    0x1.9a5496p0
+  },
+  { // Entry 563
+    0x1.f2f13929323ef8f58db152143e65bcb7p4,
+    -0x1.9a5496p0
+  },
+  { // Entry 564
+    -0x1.4bb6e0ec02cad5c110a4d70039db4d1cp3,
+    0x1.aabe5ep0
+  },
+  { // Entry 565
+    0x1.4bb6e0ec02cad5c110a4d70039db4d1cp3,
+    -0x1.aabe5ep0
+  },
+  { // Entry 566
+    -0x1.8bdd06a655dfa2f3195aca48798e5c86p2,
+    0x1.bb2826p0
+  },
+  { // Entry 567
+    0x1.8bdd06a655dfa2f3195aca48798e5c86p2,
+    -0x1.bb2826p0
+  },
+  { // Entry 568
+    -0x1.18671b76cfccf98a6edbc1fd5b8647b7p2,
+    0x1.cb91eep0
+  },
+  { // Entry 569
+    0x1.18671b76cfccf98a6edbc1fd5b8647b7p2,
+    -0x1.cb91eep0
+  },
+  { // Entry 570
+    -0x1.af466bac80dc9df668d1e0e9b442bf0ep1,
+    0x1.dbfbb6p0
+  },
+  { // Entry 571
+    0x1.af466bac80dc9df668d1e0e9b442bf0ep1,
+    -0x1.dbfbb6p0
+  },
+  { // Entry 572
+    -0x1.5bd15bcb3d06906cef5f3b2ec3ab4ab9p1,
+    0x1.ec657ep0
+  },
+  { // Entry 573
+    0x1.5bd15bcb3d06906cef5f3b2ec3ab4ab9p1,
+    -0x1.ec657ep0
+  },
+  { // Entry 574
+    -0x1.2127938a546d3c428292ba53ee6f67ccp1,
+    0x1.fccf46p0
+  },
+  { // Entry 575
+    0x1.2127938a546d3c428292ba53ee6f67ccp1,
+    -0x1.fccf46p0
+  },
+  { // Entry 576
+    -0x1.eab45caed706c4db622c90fe3e8d16c2p0,
+    0x1.069c88p1
+  },
+  { // Entry 577
+    0x1.eab45caed706c4db622c90fe3e8d16c2p0,
+    -0x1.069c88p1
+  },
+  { // Entry 578
+    -0x1.a64c979eb703d82cb4808044e8abf93fp0,
+    0x1.0ed16cp1
+  },
+  { // Entry 579
+    0x1.a64c979eb703d82cb4808044e8abf93fp0,
+    -0x1.0ed16cp1
+  },
+  { // Entry 580
+    -0x1.6efee11500263c10c1d1bb5904244de6p0,
+    0x1.170650p1
+  },
+  { // Entry 581
+    0x1.6efee11500263c10c1d1bb5904244de6p0,
+    -0x1.170650p1
+  },
+  { // Entry 582
+    -0x1.4103a1bc0f6576a760d49da3bfe55874p0,
+    0x1.1f3b34p1
+  },
+  { // Entry 583
+    0x1.4103a1bc0f6576a760d49da3bfe55874p0,
+    -0x1.1f3b34p1
+  },
+  { // Entry 584
+    -0x1.19e2801aa24ee0adcd9491e4d7af256fp0,
+    0x1.277018p1
+  },
+  { // Entry 585
+    0x1.19e2801aa24ee0adcd9491e4d7af256fp0,
+    -0x1.277018p1
+  },
+  { // Entry 586
+    -0x1.efd84e50652c1b7c71972ad8ee7c018ap-1,
+    0x1.2fa4fcp1
+  },
+  { // Entry 587
+    0x1.efd84e50652c1b7c71972ad8ee7c018ap-1,
+    -0x1.2fa4fcp1
+  },
+  { // Entry 588
+    -0x1.b3df5d9f54e2c748cf0227ee0974ea2ep-1,
+    0x1.37d9e0p1
+  },
+  { // Entry 589
+    0x1.b3df5d9f54e2c748cf0227ee0974ea2ep-1,
+    -0x1.37d9e0p1
+  },
+  { // Entry 590
+    -0x1.7e1db733769a1126a2b0ac7fa14a402cp-1,
+    0x1.400ec4p1
+  },
+  { // Entry 591
+    0x1.7e1db733769a1126a2b0ac7fa14a402cp-1,
+    -0x1.400ec4p1
+  },
+  { // Entry 592
+    -0x1.4d468d82c1a84fef7279fc5fb24419b2p-1,
+    0x1.4843a8p1
+  },
+  { // Entry 593
+    0x1.4d468d82c1a84fef7279fc5fb24419b2p-1,
+    -0x1.4843a8p1
+  },
+  { // Entry 594
+    -0x1.205a8202545202d891ce89bfa6cd1476p-1,
+    0x1.50788cp1
+  },
+  { // Entry 595
+    0x1.205a8202545202d891ce89bfa6cd1476p-1,
+    -0x1.50788cp1
+  },
+  { // Entry 596
+    -0x1.ed22289d891ed78cdc818a4cde6de918p-2,
+    0x1.58ad70p1
+  },
+  { // Entry 597
+    0x1.ed22289d891ed78cdc818a4cde6de918p-2,
+    -0x1.58ad70p1
+  },
+  { // Entry 598
+    -0x1.9e929a7fadf83b6f9e8fb851f512b44bp-2,
+    0x1.60e254p1
+  },
+  { // Entry 599
+    0x1.9e929a7fadf83b6f9e8fb851f512b44bp-2,
+    -0x1.60e254p1
+  },
+  { // Entry 600
+    -0x1.53fe10a547a6ecce5caddc2005db822bp-2,
+    0x1.691738p1
+  },
+  { // Entry 601
+    0x1.53fe10a547a6ecce5caddc2005db822bp-2,
+    -0x1.691738p1
+  },
+  { // Entry 602
+    -0x1.0c8683b1bc682759e28441ef97c8854bp-2,
+    0x1.714c1cp1
+  },
+  { // Entry 603
+    0x1.0c8683b1bc682759e28441ef97c8854bp-2,
+    -0x1.714c1cp1
+  },
+  { // Entry 604
+    -0x1.8ed99c8546008be46614ea66c7ddd7e6p-3,
+    0x1.7981p1
+  },
+  { // Entry 605
+    0x1.8ed99c8546008be46614ea66c7ddd7e6p-3,
+    -0x1.7981p1
+  },
+  { // Entry 606
+    -0x1.080ffef4eda0271d81658d58ae280792p-3,
+    0x1.81b5e4p1
+  },
+  { // Entry 607
+    0x1.080ffef4eda0271d81658d58ae280792p-3,
+    -0x1.81b5e4p1
+  },
+  { // Entry 608
+    -0x1.06f9ee83686aa6194c03de71a6b52f75p-4,
+    0x1.89eac8p1
+  },
+  { // Entry 609
+    0x1.06f9ee83686aa6194c03de71a6b52f75p-4,
+    -0x1.89eac8p1
+  },
+  { // Entry 610
+    0x1.0c8627ec3bc2e8f0e6df44f809f370fdp-2,
+    -0x1.81b5eep2
+  },
+  { // Entry 611
+    -0x1.0c8627ec3bc2e8f0e6df44f809f370fdp-2,
+    0x1.81b5eep2
+  },
+  { // Entry 612
+    0x1.205a49753bb89e8c971c6cd2842edaf0p-1,
+    -0x1.714c26p2
+  },
+  { // Entry 613
+    -0x1.205a49753bb89e8c971c6cd2842edaf0p-1,
+    0x1.714c26p2
+  },
+  { // Entry 614
+    0x1.efd7fb1d28b8a0602b25fadfe9e0277ap-1,
+    -0x1.60e25ep2
+  },
+  { // Entry 615
+    -0x1.efd7fb1d28b8a0602b25fadfe9e0277ap-1,
+    0x1.60e25ep2
+  },
+  { // Entry 616
+    0x1.a64c47bcfb5f9cbdb49360a65548fd6dp0,
+    -0x1.507896p2
+  },
+  { // Entry 617
+    -0x1.a64c47bcfb5f9cbdb49360a65548fd6dp0,
+    0x1.507896p2
+  },
+  { // Entry 618
+    0x1.af45dabd34b75597ff70079b3de986fdp1,
+    -0x1.400ecep2
+  },
+  { // Entry 619
+    -0x1.af45dabd34b75597ff70079b3de986fdp1,
+    0x1.400ecep2
+  },
+  { // Entry 620
+    0x1.f2eba583fff9f8df3693ffd969395de7p4,
+    -0x1.2fa506p2
+  },
+  { // Entry 621
+    -0x1.f2eba583fff9f8df3693ffd969395de7p4,
+    0x1.2fa506p2
+  },
+  { // Entry 622
+    -0x1.186770f5cef152a4ec75fe9a7031a56ap2,
+    -0x1.1f3b3ep2
+  },
+  { // Entry 623
+    0x1.186770f5cef152a4ec75fe9a7031a56ap2,
+    0x1.1f3b3ep2
+  },
+  { // Entry 624
+    -0x1.eab4b52e6cce160a5b9a23a4b929d01dp0,
+    -0x1.0ed176p2
+  },
+  { // Entry 625
+    0x1.eab4b52e6cce160a5b9a23a4b929d01dp0,
+    0x1.0ed176p2
+  },
+  { // Entry 626
+    -0x1.19e2a124bc3deef648338274627cc371p0,
+    -0x1.fccf5ap1
+  },
+  { // Entry 627
+    0x1.19e2a124bc3deef648338274627cc371p0,
+    0x1.fccf5ap1
+  },
+  { // Entry 628
+    -0x1.4d46aca48de47f5fd90c9000c15425d8p-1,
+    -0x1.dbfbc8p1
+  },
+  { // Entry 629
+    0x1.4d46aca48de47f5fd90c9000c15425d8p-1,
+    0x1.dbfbc8p1
+  },
+  { // Entry 630
+    -0x1.53fe2f6fc9d023774a2105c8213e4d5ep-2,
+    -0x1.bb2836p1
+  },
+  { // Entry 631
+    0x1.53fe2f6fc9d023774a2105c8213e4d5ep-2,
+    0x1.bb2836p1
+  },
+  { // Entry 632
+    -0x1.06fa1da43b26cd580ce5a5b89cf2eff3p-4,
+    -0x1.9a54a4p1
+  },
+  { // Entry 633
+    0x1.06fa1da43b26cd580ce5a5b89cf2eff3p-4,
+    0x1.9a54a4p1
+  },
+  { // Entry 634
+    0x1.8ed87198f413d3a122658287aa7fc33ep-3,
+    -0x1.798112p1
+  },
+  { // Entry 635
+    -0x1.8ed87198f413d3a122658287aa7fc33ep-3,
+    0x1.798112p1
+  },
+  { // Entry 636
+    0x1.ed218aee2df4e80e39340b0c4ec3b1d5p-2,
+    -0x1.58ad80p1
+  },
+  { // Entry 637
+    -0x1.ed218aee2df4e80e39340b0c4ec3b1d5p-2,
+    0x1.58ad80p1
+  },
+  { // Entry 638
+    0x1.b3defd0991e6315369dbd5e2de2d14fep-1,
+    -0x1.37d9eep1
+  },
+  { // Entry 639
+    -0x1.b3defd0991e6315369dbd5e2de2d14fep-1,
+    0x1.37d9eep1
+  },
+  { // Entry 640
+    0x1.6efe97c23f206826b4f0019f275d3a44p0,
+    -0x1.17065cp1
+  },
+  { // Entry 641
+    -0x1.6efe97c23f206826b4f0019f275d3a44p0,
+    0x1.17065cp1
+  },
+  { // Entry 642
+    0x1.5bd0ff925c94f7d608b88484f9081f2cp1,
+    -0x1.ec6594p0
+  },
+  { // Entry 643
+    -0x1.5bd0ff925c94f7d608b88484f9081f2cp1,
+    0x1.ec6594p0
+  },
+  { // Entry 644
+    0x1.4bb5ece657bee292a82a3fda6b812aadp3,
+    -0x1.aabe70p0
+  },
+  { // Entry 645
+    -0x1.4bb5ece657bee292a82a3fda6b812aadp3,
+    0x1.aabe70p0
+  },
+  { // Entry 646
+    -0x1.8bdd4feef18bfa8a6c23de6a721f2436p2,
+    -0x1.69174cp0
+  },
+  { // Entry 647
+    0x1.8bdd4feef18bfa8a6c23de6a721f2436p2,
+    0x1.69174cp0
+  },
+  { // Entry 648
+    -0x1.21279e1e8bf4bd3983a3677267e55809p1,
+    -0x1.277028p0
+  },
+  { // Entry 649
+    0x1.21279e1e8bf4bd3983a3677267e55809p1,
+    0x1.277028p0
+  },
+  { // Entry 650
+    -0x1.4103a8147ca836136cc98db9bc6ddf30p0,
+    -0x1.cb920ap-1
+  },
+  { // Entry 651
+    0x1.4103a8147ca836136cc98db9bc6ddf30p0,
+    0x1.cb920ap-1
+  },
+  { // Entry 652
+    -0x1.7e1db58a55d6a12a6457e3c5929ac2c7p-1,
+    -0x1.4843c4p-1
+  },
+  { // Entry 653
+    0x1.7e1db58a55d6a12a6457e3c5929ac2c7p-1,
+    0x1.4843c4p-1
+  },
+  { // Entry 654
+    -0x1.9e928a0c8e79023200164ed240caad05p-2,
+    -0x1.89eafcp-2
+  },
+  { // Entry 655
+    0x1.9e928a0c8e79023200164ed240caad05p-2,
+    0x1.89eafcp-2
+  },
+  { // Entry 656
+    -0x1.080fc9d24fbe9876b31b0aa29dd238eap-3,
+    -0x1.069ce0p-3
+  },
+  { // Entry 657
+    0x1.080fc9d24fbe9876b31b0aa29dd238eap-3,
+    0x1.069ce0p-3
+  },
+  { // Entry 658
+    0x1.080f1f07540fd03b82d4b370d237fa3dp-3,
+    0x1.069c38p-3
+  },
+  { // Entry 659
+    -0x1.080f1f07540fd03b82d4b370d237fa3dp-3,
+    -0x1.069c38p-3
+  },
+  { // Entry 660
+    0x1.9e922847e2b1b6a72d486700e18c05f2p-2,
+    0x1.89eaa8p-2
+  },
+  { // Entry 661
+    -0x1.9e922847e2b1b6a72d486700e18c05f2p-2,
+    -0x1.89eaa8p-2
+  },
+  { // Entry 662
+    0x1.7e1d74258cbc964b561d99c9a66f8c7ep-1,
+    0x1.48439ap-1
+  },
+  { // Entry 663
+    -0x1.7e1d74258cbc964b561d99c9a66f8c7ep-1,
+    -0x1.48439ap-1
+  },
+  { // Entry 664
+    0x1.4103720f2ca3e0580fba15849398a4e9p0,
+    0x1.cb91e0p-1
+  },
+  { // Entry 665
+    -0x1.4103720f2ca3e0580fba15849398a4e9p0,
+    -0x1.cb91e0p-1
+  },
+  { // Entry 666
+    0x1.2127611673ccc7531f5af5aeda3412c5p1,
+    0x1.277014p0
+  },
+  { // Entry 667
+    -0x1.2127611673ccc7531f5af5aeda3412c5p1,
+    -0x1.277014p0
+  },
+  { // Entry 668
+    0x1.8bdc8ba3d8277213c5b74ef806ef466bp2,
+    0x1.691738p0
+  },
+  { // Entry 669
+    -0x1.8bdc8ba3d8277213c5b74ef806ef466bp2,
+    -0x1.691738p0
+  },
+  { // Entry 670
+    -0x1.4bb6fc092bc16530216209a912aada37p3,
+    0x1.aabe5cp0
+  },
+  { // Entry 671
+    0x1.4bb6fc092bc16530216209a912aada37p3,
+    -0x1.aabe5cp0
+  },
+  { // Entry 672
+    -0x1.5bd15368f84be0bda8f135a5f79aeacbp1,
+    0x1.ec6580p0
+  },
+  { // Entry 673
+    0x1.5bd15368f84be0bda8f135a5f79aeacbp1,
+    -0x1.ec6580p0
+  },
+  { // Entry 674
+    -0x1.6efed4dc8946e1c3620d79bb0d654338p0,
+    0x1.170652p1
+  },
+  { // Entry 675
+    0x1.6efed4dc8946e1c3620d79bb0d654338p0,
+    -0x1.170652p1
+  },
+  { // Entry 676
+    -0x1.b3df4206d232794d5761992d88c5a394p-1,
+    0x1.37d9e4p1
+  },
+  { // Entry 677
+    0x1.b3df4206d232794d5761992d88c5a394p-1,
+    -0x1.37d9e4p1
+  },
+  { // Entry 678
+    -0x1.ed21ed7bc4b5968bdb0cd6da269cd55fp-2,
+    0x1.58ad76p1
+  },
+  { // Entry 679
+    0x1.ed21ed7bc4b5968bdb0cd6da269cd55fp-2,
+    -0x1.58ad76p1
+  },
+  { // Entry 680
+    -0x1.8ed917aa74e733b9194d537c8df33c64p-3,
+    0x1.798108p1
+  },
+  { // Entry 681
+    0x1.8ed917aa74e733b9194d537c8df33c64p-3,
+    -0x1.798108p1
+  },
+  { // Entry 682
+    0x1.06f8dc528ea01882064ee242f58a2b88p-4,
+    0x1.9a549ap1
+  },
+  { // Entry 683
+    -0x1.06f8dc528ea01882064ee242f58a2b88p-4,
+    -0x1.9a549ap1
+  },
+  { // Entry 684
+    0x1.53fdd69e1437db957c62e8cc55742beep-2,
+    0x1.bb282cp1
+  },
+  { // Entry 685
+    -0x1.53fdd69e1437db957c62e8cc55742beep-2,
+    -0x1.bb282cp1
+  },
+  { // Entry 686
+    0x1.4d4673b1c7635cc893e1c8d2ca57b3e9p-1,
+    0x1.dbfbbep1
+  },
+  { // Entry 687
+    -0x1.4d4673b1c7635cc893e1c8d2ca57b3e9p-1,
+    -0x1.dbfbbep1
+  },
+  { // Entry 688
+    0x1.19e274e4fdec9e78ef6872081b5572cfp0,
+    0x1.fccf50p1
+  },
+  { // Entry 689
+    -0x1.19e274e4fdec9e78ef6872081b5572cfp0,
+    -0x1.fccf50p1
+  },
+  { // Entry 690
+    0x1.eab445003a7b542a2d4d87a88793bb67p0,
+    0x1.0ed170p2
+  },
+  { // Entry 691
+    -0x1.eab445003a7b542a2d4d87a88793bb67p0,
+    -0x1.0ed170p2
+  },
+  { // Entry 692
+    0x1.1866f7c91660d9c9f4b2d14e91375732p2,
+    0x1.1f3b38p2
+  },
+  { // Entry 693
+    -0x1.1866f7c91660d9c9f4b2d14e91375732p2,
+    -0x1.1f3b38p2
+  },
+  { // Entry 694
+    -0x1.f2f1599b29a7de952b8ba1877d9f5e61p4,
+    0x1.2fa5p2
+  },
+  { // Entry 695
+    0x1.f2f1599b29a7de952b8ba1877d9f5e61p4,
+    -0x1.2fa5p2
+  },
+  { // Entry 696
+    -0x1.af466ef7b15645455e15fbbae6bb4bc6p1,
+    0x1.400ec8p2
+  },
+  { // Entry 697
+    0x1.af466ef7b15645455e15fbbae6bb4bc6p1,
+    -0x1.400ec8p2
+  },
+  { // Entry 698
+    -0x1.a64ca10bfefd2b04bb6a1bb708c28967p0,
+    0x1.507890p2
+  },
+  { // Entry 699
+    0x1.a64ca10bfefd2b04bb6a1bb708c28967p0,
+    -0x1.507890p2
+  },
+  { // Entry 700
+    -0x1.efd85821ec927f2a89ec41acee587230p-1,
+    0x1.60e258p2
+  },
+  { // Entry 701
+    0x1.efd85821ec927f2a89ec41acee587230p-1,
+    -0x1.60e258p2
+  },
+  { // Entry 702
+    -0x1.205a88aec64cad35d7752c73620c2139p-1,
+    0x1.714c20p2
+  },
+  { // Entry 703
+    0x1.205a88aec64cad35d7752c73620c2139p-1,
+    -0x1.714c20p2
+  },
+  { // Entry 704
+    -0x1.0c868e863543fd989476c8cdeffa93eap-2,
+    0x1.81b5e8p2
+  },
+  { // Entry 705
+    0x1.0c868e863543fd989476c8cdeffa93eap-2,
+    -0x1.81b5e8p2
+  },
+  { // Entry 706
+    0x1.f09b61a8a04f0898851f1d7604fa13c8p-5,
+    0x1.effffep-5
+  },
+  { // Entry 707
+    -0x1.f09b61a8a04f0898851f1d7604fa13c8p-5,
+    -0x1.effffep-5
+  },
+  { // Entry 708
+    0x1.f09b63aa81fc46e95e06405b41e8b4ccp-5,
+    0x1.f0p-5
+  },
+  { // Entry 709
+    -0x1.f09b63aa81fc46e95e06405b41e8b4ccp-5,
+    -0x1.f0p-5
+  },
+  { // Entry 710
+    0x1.f09b65ac63a9891f1418c4338c1e419ep-5,
+    0x1.f00002p-5
+  },
+  { // Entry 711
+    -0x1.f09b65ac63a9891f1418c4338c1e419ep-5,
+    -0x1.f00002p-5
+  },
+  { // Entry 712
+    0x1.fa8f1fc0ce86c214bf765fd59e8798a5p-4,
+    0x1.f7fffep-4
+  },
+  { // Entry 713
+    -0x1.fa8f1fc0ce86c214bf765fd59e8798a5p-4,
+    -0x1.f7fffep-4
+  },
+  { // Entry 714
+    0x1.fa8f21c8a33afd3355198e8d7716a811p-4,
+    0x1.f8p-4
+  },
+  { // Entry 715
+    -0x1.fa8f21c8a33afd3355198e8d7716a811p-4,
+    -0x1.f8p-4
+  },
+  { // Entry 716
+    0x1.fa8f23d077ef48645eff9a519628b3a9p-4,
+    0x1.f80002p-4
+  },
+  { // Entry 717
+    -0x1.fa8f23d077ef48645eff9a519628b3a9p-4,
+    -0x1.f80002p-4
+  },
+  { // Entry 718
+    0x1.4ef06aa73ee6a439c0c9f45046b25978p-3,
+    0x1.4bfffep-3
+  },
+  { // Entry 719
+    -0x1.4ef06aa73ee6a439c0c9f45046b25978p-3,
+    -0x1.4bfffep-3
+  },
+  { // Entry 720
+    0x1.4ef06cb4f0a87a5c8eeeebceb12a22b4p-3,
+    0x1.4cp-3
+  },
+  { // Entry 721
+    -0x1.4ef06cb4f0a87a5c8eeeebceb12a22b4p-3,
+    -0x1.4cp-3
+  },
+  { // Entry 722
+    0x1.4ef06ec2a26a7b7c1721ffafb93c0281p-3,
+    0x1.4c0002p-3
+  },
+  { // Entry 723
+    -0x1.4ef06ec2a26a7b7c1721ffafb93c0281p-3,
+    -0x1.4c0002p-3
+  },
+  { // Entry 724
+    0x1.3cc2a2fd911e1557d57b44abf28c4ccap-2,
+    0x1.333332p-2
+  },
+  { // Entry 725
+    -0x1.3cc2a2fd911e1557d57b44abf28c4ccap-2,
+    -0x1.333332p-2
+  },
+  { // Entry 726
+    0x1.3cc2a52e8f4137ca27d1dc0567195443p-2,
+    0x1.333334p-2
+  },
+  { // Entry 727
+    -0x1.3cc2a52e8f4137ca27d1dc0567195443p-2,
+    -0x1.333334p-2
+  },
+  { // Entry 728
+    0x1.3cc2a75f8d6507c589bf08e0371394bcp-2,
+    0x1.333336p-2
+  },
+  { // Entry 729
+    -0x1.3cc2a75f8d6507c589bf08e0371394bcp-2,
+    -0x1.333336p-2
+  },
+  { // Entry 730
+    0x1.99436e5f07b73dda1ef61a800aadfdd3p-1,
+    0x1.594316p-1
+  },
+  { // Entry 731
+    -0x1.99436e5f07b73dda1ef61a800aadfdd3p-1,
+    -0x1.594316p-1
+  },
+  { // Entry 732
+    0x1.994371a62bfe13eb1c755cb5be46f853p-1,
+    0x1.594318p-1
+  },
+  { // Entry 733
+    -0x1.994371a62bfe13eb1c755cb5be46f853p-1,
+    -0x1.594318p-1
+  },
+  { // Entry 734
+    0x1.994374ed504a278226573562b60eca9ap-1,
+    0x1.59431ap-1
+  },
+  { // Entry 735
+    -0x1.994374ed504a278226573562b60eca9ap-1,
+    -0x1.59431ap-1
+  },
+  { // Entry 736
+    0x1.fbc50de7c605a4d1d0f1119b1294b6f0p-1,
+    0x1.8ffffep-1
+  },
+  { // Entry 737
+    -0x1.fbc50de7c605a4d1d0f1119b1294b6f0p-1,
+    -0x1.8ffffep-1
+  },
+  { // Entry 738
+    0x1.fbc511df5917f539bbcf778bc1a22249p-1,
+    0x1.90p-1
+  },
+  { // Entry 739
+    -0x1.fbc511df5917f539bbcf778bc1a22249p-1,
+    -0x1.90p-1
+  },
+  { // Entry 740
+    0x1.fbc515d6ec3223ffbed4bb75154fda0fp-1,
+    0x1.900002p-1
+  },
+  { // Entry 741
+    -0x1.fbc515d6ec3223ffbed4bb75154fda0fp-1,
+    -0x1.900002p-1
+  },
+  { // Entry 742
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 743
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 744
+    0.0,
+    0.0
+  },
+  { // Entry 745
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 746
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 747
+    0x1.9272775ea5ecff4e43ecdef3d85ec226p-5,
+    0x1.921fb4p-5
+  },
+  { // Entry 748
+    -0x1.9272775ea5ecff4e43ecdef3d85ec226p-5,
+    -0x1.921fb4p-5
+  },
+  { // Entry 749
+    0x1.9272795fe242d9eb9393a7446620c394p-5,
+    0x1.921fb6p-5
+  },
+  { // Entry 750
+    -0x1.9272795fe242d9eb9393a7446620c394p-5,
+    -0x1.921fb6p-5
+  },
+  { // Entry 751
+    0x1.92727b611e98b7afb97977551d1c5f38p-5,
+    0x1.921fb8p-5
+  },
+  { // Entry 752
+    -0x1.92727b611e98b7afb97977551d1c5f38p-5,
+    -0x1.921fb8p-5
+  },
+  { // Entry 753
+    0x1.936bb77e4ac859bc69bc4abc9e91f025p-4,
+    0x1.921fb4p-4
+  },
+  { // Entry 754
+    -0x1.936bb77e4ac859bc69bc4abc9e91f025p-4,
+    -0x1.921fb4p-4
+  },
+  { // Entry 755
+    0x1.936bb9834241022ecd070b9064632721p-4,
+    0x1.921fb6p-4
+  },
+  { // Entry 756
+    -0x1.936bb9834241022ecd070b9064632721p-4,
+    -0x1.921fb6p-4
+  },
+  { // Entry 757
+    0x1.936bbb8839b9b75bdcc5f6870267a609p-4,
+    0x1.921fb8p-4
+  },
+  { // Entry 758
+    -0x1.936bbb8839b9b75bdcc5f6870267a609p-4,
+    -0x1.921fb8p-4
+  },
+  { // Entry 759
+    0x1.975f5cb43bd951aa2e89a05cbf5e70ffp-3,
+    0x1.921fb4p-3
+  },
+  { // Entry 760
+    -0x1.975f5cb43bd951aa2e89a05cbf5e70ffp-3,
+    -0x1.921fb4p-3
+  },
+  { // Entry 761
+    0x1.975f5ec87ddc4e7a357059f71a9f05b2p-3,
+    0x1.921fb6p-3
+  },
+  { // Entry 762
+    -0x1.975f5ec87ddc4e7a357059f71a9f05b2p-3,
+    -0x1.921fb6p-3
+  },
+  { // Entry 763
+    0x1.975f60dcbfdf8039f01eb7864bc09e13p-3,
+    0x1.921fb8p-3
+  },
+  { // Entry 764
+    -0x1.975f60dcbfdf8039f01eb7864bc09e13p-3,
+    -0x1.921fb8p-3
+  },
+  { // Entry 765
+    0x1.a8279823e9ba30ee623a5402a48590fcp-2,
+    0x1.921fb4p-2
+  },
+  { // Entry 766
+    -0x1.a8279823e9ba30ee623a5402a48590fcp-2,
+    -0x1.921fb4p-2
+  },
+  { // Entry 767
+    0x1.a8279a7bc2206fff3afa52f168c5f8f2p-2,
+    0x1.921fb6p-2
+  },
+  { // Entry 768
+    -0x1.a8279a7bc2206fff3afa52f168c5f8f2p-2,
+    -0x1.921fb6p-2
+  },
+  { // Entry 769
+    0x1.a8279cd39a87a786e140537db72ff334p-2,
+    0x1.921fb8p-2
+  },
+  { // Entry 770
+    -0x1.a8279cd39a87a786e140537db72ff334p-2,
+    -0x1.921fb8p-2
+  },
+  { // Entry 771
+    0x1.fffffd777a5e91e61f5380fb808d3272p-1,
+    0x1.921fb4p-1
+  },
+  { // Entry 772
+    -0x1.fffffd777a5e91e61f5380fb808d3272p-1,
+    -0x1.921fb4p-1
+  },
+  { // Entry 773
+    0x1.000000bbbd2ec06d6d6fff3655a346acp0,
+    0x1.921fb6p-1
+  },
+  { // Entry 774
+    -0x1.000000bbbd2ec06d6d6fff3655a346acp0,
+    -0x1.921fb6p-1
+  },
+  { // Entry 775
+    0x1.000002bbbd3237e7d114276ed329af5bp0,
+    0x1.921fb8p-1
+  },
+  { // Entry 776
+    -0x1.000002bbbd3237e7d114276ed329af5bp0,
+    -0x1.921fb8p-1
+  },
+  { // Entry 777
+    0x1.9437b336b6b0c479b2280999b19575c7p23,
+    0x1.921fb4p0
+  },
+  { // Entry 778
+    -0x1.9437b336b6b0c479b2280999b19575c7p23,
+    -0x1.921fb4p0
+  },
+  { // Entry 779
+    -0x1.5d14946dc98975d6421a55284fe020a1p24,
+    0x1.921fb6p0
+  },
+  { // Entry 780
+    0x1.5d14946dc98975d6421a55284fe020a1p24,
+    -0x1.921fb6p0
+  },
+  { // Entry 781
+    -0x1.76a190eb2b0718d8db55f7d2abeb07d2p22,
+    0x1.921fb8p0
+  },
+  { // Entry 782
+    0x1.76a190eb2b0718d8db55f7d2abeb07d2p22,
+    -0x1.921fb8p0
+  },
+  { // Entry 783
+    -0x1.4442d184698c426c8e3efd356cbebe0ap-23,
+    0x1.921fb4p1
+  },
+  { // Entry 784
+    0x1.4442d184698c426c8e3efd356cbebe0ap-23,
+    -0x1.921fb4p1
+  },
+  { // Entry 785
+    0x1.777a5cf72cedf3b544c81808b515f1f9p-24,
+    0x1.921fb6p1
+  },
+  { // Entry 786
+    -0x1.777a5cf72cedf3b544c81808b515f1f9p-24,
+    -0x1.921fb6p1
+  },
+  { // Entry 787
+    0x1.5dde973dcb48d6e3d13cf2a51550e911p-22,
+    0x1.921fb8p1
+  },
+  { // Entry 788
+    -0x1.5dde973dcb48d6e3d13cf2a51550e911p-22,
+    -0x1.921fb8p1
+  },
+  { // Entry 789
+    -0x1.4442d18469946362f3f6cc7c43857661p-22,
+    0x1.921fb4p2
+  },
+  { // Entry 790
+    0x1.4442d18469946362f3f6cc7c43857661p-22,
+    -0x1.921fb4p2
+  },
+  { // Entry 791
+    0x1.777a5cf72cf11b739d2ab1877e81a9c7p-23,
+    0x1.921fb6p2
+  },
+  { // Entry 792
+    -0x1.777a5cf72cf11b739d2ab1877e81a9c7p-23,
+    -0x1.921fb6p2
+  },
+  { // Entry 793
+    0x1.5dde973dcb71aeb6e776668bbb3de253p-21,
+    0x1.921fb8p2
+  },
+  { // Entry 794
+    -0x1.5dde973dcb71aeb6e776668bbb3de253p-21,
+    -0x1.921fb8p2
+  },
+  { // Entry 795
+    -0x1.4442d18469b4e73c8ad60e7b9f288c5cp-21,
+    0x1.921fb4p3
+  },
+  { // Entry 796
+    0x1.4442d18469b4e73c8ad60e7b9f288c5cp-21,
+    -0x1.921fb4p3
+  },
+  { // Entry 797
+    0x1.777a5cf72cfdba6cfeb518258bcf263cp-22,
+    0x1.921fb6p3
+  },
+  { // Entry 798
+    -0x1.777a5cf72cfdba6cfeb518258bcf263cp-22,
+    -0x1.921fb6p3
+  },
+  { // Entry 799
+    0x1.5dde973dcc150e03405ca894886602c2p-20,
+    0x1.921fb8p3
+  },
+  { // Entry 800
+    -0x1.5dde973dcc150e03405ca894886602c2p-20,
+    -0x1.921fb8p3
+  },
+  { // Entry 801
+    -0x1.4442d1846a36f6a2e65364b916382e9bp-20,
+    0x1.921fb4p4
+  },
+  { // Entry 802
+    0x1.4442d1846a36f6a2e65364b916382e9bp-20,
+    -0x1.921fb4p4
+  },
+  { // Entry 803
+    0x1.777a5cf72d30365284debccc3aeeec17p-21,
+    0x1.921fb6p4
+  },
+  { // Entry 804
+    -0x1.777a5cf72d30365284debccc3aeeec17p-21,
+    -0x1.921fb6p4
+  },
+  { // Entry 805
+    0x1.5dde973dcea28b34a3fcd79b144a5050p-19,
+    0x1.921fb8p4
+  },
+  { // Entry 806
+    -0x1.5dde973dcea28b34a3fcd79b144a5050p-19,
+    -0x1.921fb8p4
+  },
+  { // Entry 807
+    -0x1.4442d1846c3f343c544da1af7aab690cp-19,
+    0x1.921fb4p5
+  },
+  { // Entry 808
+    0x1.4442d1846c3f343c544da1af7aab690cp-19,
+    -0x1.921fb4p5
+  },
+  { // Entry 809
+    0x1.777a5cf72dfa25e89d85f24e960b4455p-20,
+    0x1.921fb6p5
+  },
+  { // Entry 810
+    -0x1.777a5cf72dfa25e89d85f24e960b4455p-20,
+    -0x1.921fb6p5
+  },
+  { // Entry 811
+    0x1.5dde973dd8d87ffa32f001eab81d960cp-18,
+    0x1.921fb8p5
+  },
+  { // Entry 812
+    -0x1.5dde973dd8d87ffa32f001eab81d960cp-18,
+    -0x1.921fb8p5
+  },
+  { // Entry 813
+    -0x1.4442d18474602aa20c84d5918fc68a8ep-18,
+    0x1.921fb4p6
+  },
+  { // Entry 814
+    0x1.4442d18474602aa20c84d5918fc68a8ep-18,
+    -0x1.921fb4p6
+  },
+  { // Entry 815
+    0x1.777a5cf73121e441002cf6d1ec50d56dp-19,
+    0x1.921fb6p6
+  },
+  { // Entry 816
+    -0x1.777a5cf73121e441002cf6d1ec50d56dp-19,
+    -0x1.921fb6p6
+  },
+  { // Entry 817
+    0x1.5dde973e01b0531075e38e808ce048f2p-17,
+    0x1.921fb8p6
+  },
+  { // Entry 818
+    -0x1.5dde973e01b0531075e38e808ce048f2p-17,
+    -0x1.921fb8p6
+  },
+  { // Entry 819
+    -0x1.4442d18494e40438f245a5a219dea235p-17,
+    0x1.921fb4p7
+  },
+  { // Entry 820
+    0x1.4442d18494e40438f245a5a219dea235p-17,
+    -0x1.921fb4p7
+  },
+  { // Entry 821
+    0x1.777a5cf73dc0dda28b6bf07de2b2d5e6p-18,
+    0x1.921fb6p7
+  },
+  { // Entry 822
+    -0x1.777a5cf73dc0dda28b6bf07de2b2d5e6p-18,
+    -0x1.921fb6p7
+  },
+  { // Entry 823
+    0x1.5dde973ea50f9f69f41ff64c8c6db761p-16,
+    0x1.921fb8p7
+  },
+  { // Entry 824
+    -0x1.5dde973ea50f9f69f41ff64c8c6db761p-16,
+    -0x1.921fb8p7
+  },
+  { // Entry 825
+    -0x1.00000fccc8f15ee89f09d222e14c7292p0,
+    0x1.2d97c4p1
+  },
+  { // Entry 826
+    0x1.00000fccc8f15ee89f09d222e14c7292p0,
+    -0x1.2d97c4p1
+  },
+  { // Entry 827
+    -0x1.000007ccc892f8a0760cc20827ace476p0,
+    0x1.2d97c6p1
+  },
+  { // Entry 828
+    0x1.000007ccc892f8a0760cc20827ace476p0,
+    -0x1.2d97c6p1
+  },
+  { // Entry 829
+    -0x1.ffffff9990e924b866e831c9e9e639c7p-1,
+    0x1.2d97c8p1
+  },
+  { // Entry 830
+    0x1.ffffff9990e924b866e831c9e9e639c7p-1,
+    -0x1.2d97c8p1
+  },
+  { // Entry 831
+    0x1.ffffeb55643b9a648c2720bde1d22764p-1,
+    0x1.f6a7a0p1
+  },
+  { // Entry 832
+    -0x1.ffffeb55643b9a648c2720bde1d22764p-1,
+    -0x1.f6a7a0p1
+  },
+  { // Entry 833
+    0x1.fffffb5563d64585e9dcc97d74321461p-1,
+    0x1.f6a7a2p1
+  },
+  { // Entry 834
+    -0x1.fffffb5563d64585e9dcc97d74321461p-1,
+    -0x1.f6a7a2p1
+  },
+  { // Entry 835
+    0x1.000005aab1f87852792237652d34b1cep0,
+    0x1.f6a7a4p1
+  },
+  { // Entry 836
+    -0x1.000005aab1f87852792237652d34b1cep0,
+    -0x1.f6a7a4p1
+  },
+  { // Entry 837
+    0x1.033dd91c1035861ae455e0f8dc274b0dp20,
+    0x1.2d97c4p2
+  },
+  { // Entry 838
+    -0x1.033dd91c1035861ae455e0f8dc274b0dp20,
+    -0x1.2d97c4p2
+  },
+  { // Entry 839
+    0x1.0690fb4774ab80ccddc9ef5ad0fcc237p21,
+    0x1.2d97c6p2
+  },
+  { // Entry 840
+    -0x1.0690fb4774ab80ccddc9ef5ad0fcc237p21,
+    -0x1.2d97c6p2
+  },
+  { // Entry 841
+    -0x1.3fe4dac06d830837f6c584af6f8d9399p26,
+    0x1.2d97c8p2
+  },
+  { // Entry 842
+    0x1.3fe4dac06d830837f6c584af6f8d9399p26,
+    -0x1.2d97c8p2
+  },
+  { // Entry 843
+    -0x1.000014ddd4945394cb6ec7f87debc7a5p0,
+    0x1.5fdbbcp2
+  },
+  { // Entry 844
+    0x1.000014ddd4945394cb6ec7f87debc7a5p0,
+    -0x1.5fdbbcp2
+  },
+  { // Entry 845
+    -0x1.000004ddd3c6764d7369a0be61a630e7p0,
+    0x1.5fdbbep2
+  },
+  { // Entry 846
+    0x1.000004ddd3c6764d7369a0be61a630e7p0,
+    -0x1.5fdbbep2
+  },
+  { // Entry 847
+    -0x1.ffffe9bba7f1321fae192943a3e848c0p-1,
+    0x1.5fdbc0p2
+  },
+  { // Entry 848
+    0x1.ffffe9bba7f1321fae192943a3e848c0p-1,
+    -0x1.5fdbc0p2
+  },
+  { // Entry 849
+    0x1.ffffc133511ea2d3b988bf85316d4e05p-1,
+    0x1.c463a8p2
+  },
+  { // Entry 850
+    -0x1.ffffc133511ea2d3b988bf85316d4e05p-1,
+    -0x1.c463a8p2
+  },
+  { // Entry 851
+    0x1.ffffe1334e31d7ef20d6220c65dd2f9bp-1,
+    0x1.c463aap2
+  },
+  { // Entry 852
+    -0x1.ffffe1334e31d7ef20d6220c65dd2f9bp-1,
+    -0x1.c463aap2
+  },
+  { // Entry 853
+    0x1.00000099a6a286667761c2874c5890aep0,
+    0x1.c463acp2
+  },
+  { // Entry 854
+    -0x1.00000099a6a286667761c2874c5890aep0,
+    -0x1.c463acp2
+  },
+  { // Entry 855
+    0x1.8c642e8cc56a9b233450d6b635a6266dp20,
+    0x1.f6a7a0p2
+  },
+  { // Entry 856
+    -0x1.8c642e8cc56a9b233450d6b635a6266dp20,
+    -0x1.f6a7a0p2
+  },
+  { // Entry 857
+    0x1.b6e0bfb728e42363cd5fb26b31c366c2p22,
+    0x1.f6a7a2p2
+  },
+  { // Entry 858
+    -0x1.b6e0bfb728e42363cd5fb26b31c366c2p22,
+    -0x1.f6a7a2p2
+  },
+  { // Entry 859
+    -0x1.69679b966acc43dfdb28383aa976f5c1p21,
+    0x1.f6a7a4p2
+  },
+  { // Entry 860
+    0x1.69679b966acc43dfdb28383aa976f5c1p21,
+    -0x1.f6a7a4p2
+  },
+  { // Entry 861
+    -0x1.000029eee26fe211bb4a2f8e23a0a9e9p0,
+    0x1.1475cap3
+  },
+  { // Entry 862
+    0x1.000029eee26fe211bb4a2f8e23a0a9e9p0,
+    -0x1.1475cap3
+  },
+  { // Entry 863
+    -0x1.000009eedf3205d2e9b66a3783e02f05p0,
+    0x1.1475ccp3
+  },
+  { // Entry 864
+    0x1.000009eedf3205d2e9b66a3783e02f05p0,
+    -0x1.1475ccp3
+  },
+  { // Entry 865
+    -0x1.ffffd3ddbfe853c71e4a5f7502b09c4ep-1,
+    0x1.1475cep3
+  },
+  { // Entry 866
+    0x1.ffffd3ddbfe853c71e4a5f7502b09c4ep-1,
+    -0x1.1475cep3
+  },
+  { // Entry 867
+    -0x1.f9990e91aa24f550cef57fa4106c56ebp-20,
+    0x1.2d97c4p3
+  },
+  { // Entry 868
+    0x1.f9990e91aa24f550cef57fa4106c56ebp-20,
+    -0x1.2d97c4p3
+  },
+  { // Entry 869
+    -0x1.f3321d234fc557a61c638ef7752de43fp-21,
+    0x1.2d97c6p3
+  },
+  { // Entry 870
+    0x1.f3321d234fc557a61c638ef7752de43fp-21,
+    -0x1.2d97c6p3
+  },
+  { // Entry 871
+    0x1.99bc5b961b1ae363cfc0ffaab4f0e505p-26,
+    0x1.2d97c8p3
+  },
+  { // Entry 872
+    -0x1.99bc5b961b1ae363cfc0ffaab4f0e505p-26,
+    -0x1.2d97c8p3
+  },
+  { // Entry 873
+    0x1.ffff971141794461276f342bd29c5a1fp-1,
+    0x1.46b9c0p3
+  },
+  { // Entry 874
+    -0x1.ffff971141794461276f342bd29c5a1fp-1,
+    -0x1.46b9c0p3
+  },
+  { // Entry 875
+    0x1.ffffd711385b6c9a013dabe9b7254665p-1,
+    0x1.46b9c2p3
+  },
+  { // Entry 876
+    -0x1.ffffd711385b6c9a013dabe9b7254665p-1,
+    -0x1.46b9c2p3
+  },
+  { // Entry 877
+    0x1.00000b889b9ec9c5b277fb6a91cf5f49p0,
+    0x1.46b9c4p3
+  },
+  { // Entry 878
+    -0x1.00000b889b9ec9c5b277fb6a91cf5f49p0,
+    -0x1.46b9c4p3
+  },
+  { // Entry 879
+    0x1.88973cb02a0eea2cfe1a281ca7f04663p19,
+    0x1.5fdbbcp3
+  },
+  { // Entry 880
+    -0x1.88973cb02a0eea2cfe1a281ca7f04663p19,
+    -0x1.5fdbbcp3
+  },
+  { // Entry 881
+    0x1.a4d5d5d753841c89cfe71c25abc8d645p21,
+    0x1.5fdbbep3
+  },
+  { // Entry 882
+    -0x1.a4d5d5d753841c89cfe71c25abc8d645p21,
+    -0x1.5fdbbep3
+  },
+  { // Entry 883
+    -0x1.6fe62a1a9a12b70b1fbb952801f99801p20,
+    0x1.5fdbc0p3
+  },
+  { // Entry 884
+    0x1.6fe62a1a9a12b70b1fbb952801f99801p20,
+    -0x1.5fdbc0p3
+  },
+  { // Entry 885
+    -0x1.00003efff2073e1c0dd65d3b83e5e589p0,
+    0x1.78fdb6p3
+  },
+  { // Entry 886
+    0x1.00003efff2073e1c0dd65d3b83e5e589p0,
+    -0x1.78fdb6p3
+  },
+  { // Entry 887
+    -0x1.00001effec273fb46bb5ecfec53c3105p0,
+    0x1.78fdb8p3
+  },
+  { // Entry 888
+    0x1.00001effec273fb46bb5ecfec53c3105p0,
+    -0x1.78fdb8p3
+  },
+  { // Entry 889
+    -0x1.fffffdffd48e84899227cea1f77a1cf7p-1,
+    0x1.78fdbap3
+  },
+  { // Entry 890
+    0x1.fffffdffd48e84899227cea1f77a1cf7p-1,
+    -0x1.78fdbap3
+  },
+  { // Entry 891
+    0x1.ffffacef26e965d1253424fbbc9ff354p-1,
+    0x1.ab41aep3
+  },
+  { // Entry 892
+    -0x1.ffffacef26e965d1253424fbbc9ff354p-1,
+    -0x1.ab41aep3
+  },
+  { // Entry 893
+    0x1.ffffecef20874a8f035ac4dc1a6029f8p-1,
+    0x1.ab41b0p3
+  },
+  { // Entry 894
+    -0x1.ffffecef20874a8f035ac4dc1a6029f8p-1,
+    -0x1.ab41b0p3
+  },
+  { // Entry 895
+    0x1.000016779112975a2d4b9b75bd90b3c1p0,
+    0x1.ab41b2p3
+  },
+  { // Entry 896
+    -0x1.000016779112975a2d4b9b75bd90b3c1p0,
+    -0x1.ab41b2p3
+  },
+  { // Entry 897
+    0x1.04e4b40acdf9439feccd49bbeb37da0fp19,
+    0x1.c463a8p3
+  },
+  { // Entry 898
+    -0x1.04e4b40acdf9439feccd49bbeb37da0fp19,
+    -0x1.c463a8p3
+  },
+  { // Entry 899
+    0x1.09fa3ae1f4913d1b3764ff9a9678ef68p20,
+    0x1.c463aap3
+  },
+  { // Entry 900
+    -0x1.09fa3ae1f4913d1b3764ff9a9678ef68p20,
+    -0x1.c463aap3
+  },
+  { // Entry 901
+    -0x1.aa8679009203dd6e942f9175275a7461p24,
+    0x1.c463acp3
+  },
+  { // Entry 902
+    0x1.aa8679009203dd6e942f9175275a7461p24,
+    -0x1.c463acp3
+  },
+  { // Entry 903
+    -0x1.00003410fad846fd67d35e0c0d983628p0,
+    0x1.dd85a4p3
+  },
+  { // Entry 904
+    0x1.00003410fad846fd67d35e0c0d983628p0,
+    -0x1.dd85a4p3
+  },
+  { // Entry 905
+    -0x1.00001410f656279e89d14cf4054f6c56p0,
+    0x1.dd85a6p3
+  },
+  { // Entry 906
+    0x1.00001410f656279e89d14cf4054f6c56p0,
+    -0x1.dd85a6p3
+  },
+  { // Entry 907
+    -0x1.ffffe821eba811c067240f666c904371p-1,
+    0x1.dd85a8p3
+  },
+  { // Entry 908
+    0x1.ffffe821eba811c067240f666c904371p-1,
+    -0x1.dd85a8p3
+  },
+  { // Entry 909
+    -0x1.4aa9c2f2c2addb9b59e39401239761e2p-20,
+    0x1.f6a7a0p3
+  },
+  { // Entry 910
+    0x1.4aa9c2f2c2addb9b59e39401239761e2p-20,
+    -0x1.f6a7a0p3
+  },
+  { // Entry 911
+    -0x1.2aa70bcb07e057b729eacbc0cf17cbbfp-22,
+    0x1.f6a7a2p3
+  },
+  { // Entry 912
+    0x1.2aa70bcb07e057b729eacbc0cf17cbbfp-22,
+    -0x1.f6a7a2p3
+  },
+  { // Entry 913
+    0x1.6aac7a1a7c50b873bed39b6859bf2934p-21,
+    0x1.f6a7a4p3
+  },
+  { // Entry 914
+    -0x1.6aac7a1a7c50b873bed39b6859bf2934p-21,
+    -0x1.f6a7a4p3
+  },
+  { // Entry 915
+    0x1.ffff42cd2c95508e700ab76956dd04cfp-1,
+    0x1.07e4ccp4
+  },
+  { // Entry 916
+    -0x1.ffff42cd2c95508e700ab76956dd04cfp-1,
+    -0x1.07e4ccp4
+  },
+  { // Entry 917
+    0x1.ffffc2cd0d489b48844179c594356e0dp-1,
+    0x1.07e4cep4
+  },
+  { // Entry 918
+    -0x1.ffffc2cd0d489b48844179c594356e0dp-1,
+    -0x1.07e4cep4
+  },
+  { // Entry 919
+    0x1.0000216686fdef2e1dd31a2eaa6a1cd4p0,
+    0x1.07e4d0p4
+  },
+  { // Entry 920
+    -0x1.0000216686fdef2e1dd31a2eaa6a1cd4p0,
+    -0x1.07e4d0p4
+  },
+  { // Entry 921
+    0x1.86b7ba4923bcf157dcc33291871e88d4p18,
+    0x1.1475cap4
+  },
+  { // Entry 922
+    -0x1.86b7ba4923bcf157dcc33291871e88d4p18,
+    -0x1.1475cap4
+  },
+  { // Entry 923
+    0x1.9c5becf2873eed369afdc3159a7f797cp20,
+    0x1.1475ccp4
+  },
+  { // Entry 924
+    -0x1.9c5becf2873eed369afdc3159a7f797cp20,
+    -0x1.1475ccp4
+  },
+  { // Entry 925
+    -0x1.733c0d84332fa606d1bd207a491e4371p19,
+    0x1.1475cep4
+  },
+  { // Entry 926
+    0x1.733c0d84332fa606d1bd207a491e4371p19,
+    -0x1.1475cep4
+  },
+  { // Entry 927
+    -0x1.000049220b451bf6e8e605550c88602fp0,
+    0x1.2106c8p4
+  },
+  { // Entry 928
+    0x1.000049220b451bf6e8e605550c88602fp0,
+    -0x1.2106c8p4
+  },
+  { // Entry 929
+    -0x1.0000092200fc99c5dfa4fe18085cf7cdp0,
+    0x1.2106cap4
+  },
+  { // Entry 930
+    0x1.0000092200fc99c5dfa4fe18085cf7cdp0,
+    -0x1.2106cap4
+  },
+  { // Entry 931
+    -0x1.ffff92440d6831722dec0d31810d8fc7p-1,
+    0x1.2106ccp4
+  },
+  { // Entry 932
+    0x1.ffff92440d6831722dec0d31810d8fc7p-1,
+    -0x1.2106ccp4
+  },
+  { // Entry 933
+    -0x1.f9990e91b1d916e582242347112ba1d6p-19,
+    0x1.2d97c4p4
+  },
+  { // Entry 934
+    0x1.f9990e91b1d916e582242347112ba1d6p-19,
+    -0x1.2d97c4p4
+  },
+  { // Entry 935
+    -0x1.f3321d23519fe1dcfdcd2f1f762008a4p-20,
+    0x1.2d97c6p4
+  },
+  { // Entry 936
+    0x1.f3321d23519fe1dcfdcd2f1f762008a4p-20,
+    -0x1.2d97c6p4
+  },
+  { // Entry 937
+    0x1.99bc5b961b1b24fdb77fcee08ba2f720p-25,
+    0x1.2d97c8p4
+  },
+  { // Entry 938
+    -0x1.99bc5b961b1b24fdb77fcee08ba2f720p-25,
+    -0x1.2d97c8p4
+  },
+  { // Entry 939
+    0x1.ffff18ab2756ba0a20aaf4392b0a8019p-1,
+    0x1.3a28c2p4
+  },
+  { // Entry 940
+    -0x1.ffff18ab2756ba0a20aaf4392b0a8019p-1,
+    -0x1.3a28c2p4
+  },
+  { // Entry 941
+    0x1.ffff98aafd818525d24d664ef962ef14p-1,
+    0x1.3a28c4p4
+  },
+  { // Entry 942
+    -0x1.ffff98aafd818525d24d664ef962ef14p-1,
+    -0x1.3a28c4p4
+  },
+  { // Entry 943
+    0x1.00000c5579d621ab7334eff31d23cf2cp0,
+    0x1.3a28c6p4
+  },
+  { // Entry 944
+    -0x1.00000c5579d621ab7334eff31d23cf2cp0,
+    -0x1.3a28c6p4
+  },
+  { // Entry 945
+    0x1.3846b310de7c796adb3ea2ea22b108e2p18,
+    0x1.46b9c0p4
+  },
+  { // Entry 946
+    -0x1.3846b310de7c796adb3ea2ea22b108e2p18,
+    -0x1.46b9c0p4
+  },
+  { // Entry 947
+    0x1.904425fc92eab0abfe96aeeb6ffb2dc8p19,
+    0x1.46b9c2p4
+  },
+  { // Entry 948
+    -0x1.904425fc92eab0abfe96aeeb6ffb2dc8p19,
+    -0x1.46b9c2p4
+  },
+  { // Entry 949
+    -0x1.6322bacb22de6af00228d2ea4d6d2799p20,
+    0x1.46b9c4p4
+  },
+  { // Entry 950
+    0x1.6322bacb22de6af00228d2ea4d6d2799p20,
+    -0x1.46b9c4p4
+  },
+  { // Entry 951
+    -0x1.00005e331d6dbee9f9d431b49ea7b723p0,
+    0x1.534abep4
+  },
+  { // Entry 952
+    0x1.00005e331d6dbee9f9d431b49ea7b723p0,
+    -0x1.534abep4
+  },
+  { // Entry 953
+    -0x1.00001e330de0f7c734bc57a4c6650327p0,
+    0x1.534ac0p4
+  },
+  { // Entry 954
+    0x1.00001e330de0f7c734bc57a4c6650327p0,
+    -0x1.534ac0p4
+  },
+  { // Entry 955
+    -0x1.ffffbc661ca868d5a4418f0d1cd7c22fp-1,
+    0x1.534ac2p4
+  },
+  { // Entry 956
+    0x1.ffffbc661ca868d5a4418f0d1cd7c22fp-1,
+    -0x1.534ac2p4
+  },
+  { // Entry 957
+    -0x1.4ddd3ba9f1214deb40672397d6f191bcp-19,
+    0x1.5fdbbcp4
+  },
+  { // Entry 958
+    0x1.4ddd3ba9f1214deb40672397d6f191bcp-19,
+    -0x1.5fdbbcp4
+  },
+  { // Entry 959
+    -0x1.3774eea7b8d7214bc89b11532f82d323p-21,
+    0x1.5fdbbep4
+  },
+  { // Entry 960
+    0x1.3774eea7b8d7214bc89b11532f82d323p-21,
+    -0x1.5fdbbep4
+  },
+  { // Entry 961
+    0x1.644588ac248da6d01941121f50673b3fp-20,
+    0x1.5fdbc0p4
+  },
+  { // Entry 962
+    -0x1.644588ac248da6d01941121f50673b3fp-20,
+    -0x1.5fdbc0p4
+  },
+  { // Entry 963
+    0x1.ffff6e88f1320794d845e8e0fe1fd8bdp-1,
+    0x1.6c6cbap4
+  },
+  { // Entry 964
+    -0x1.ffff6e88f1320794d845e8e0fe1fd8bdp-1,
+    -0x1.6c6cbap4
+  },
+  { // Entry 965
+    0x1.ffffee88dcd4429f15c0e4a95b9ba0e6p-1,
+    0x1.6c6cbcp4
+  },
+  { // Entry 966
+    -0x1.ffffee88dcd4429f15c0e4a95b9ba0e6p-1,
+    -0x1.6c6cbcp4
+  },
+  { // Entry 967
+    0x1.00003744743b3dbd37dd053e702bd754p0,
+    0x1.6c6cbep4
+  },
+  { // Entry 968
+    -0x1.00003744743b3dbd37dd053e702bd754p0,
+    -0x1.6c6cbep4
+  },
+  { // Entry 969
+    0x1.04109ab0ec78f827ee95cea746b38c20p18,
+    0x1.78fdb6p4
+  },
+  { // Entry 970
+    -0x1.04109ab0ec78f827ee95cea746b38c20p18,
+    -0x1.78fdb6p4
+  },
+  { // Entry 971
+    0x1.0842c9b32d2125dbf5c20d70c46b17a5p19,
+    0x1.78fdb8p4
+  },
+  { // Entry 972
+    -0x1.0842c9b32d2125dbf5c20d70c46b17a5p19,
+    -0x1.78fdb8p4
+  },
+  { // Entry 973
+    -0x1.ffd49133e26a9c749966630dee813ddep23,
+    0x1.78fdbap4
+  },
+  { // Entry 974
+    0x1.ffd49133e26a9c749966630dee813ddep23,
+    -0x1.78fdbap4
+  },
+  { // Entry 975
+    -0x1.000073443152301fa59338eec29c3778p0,
+    0x1.858eb4p4
+  },
+  { // Entry 976
+    0x1.000073443152301fa59338eec29c3778p0,
+    -0x1.858eb4p4
+  },
+  { // Entry 977
+    -0x1.000033441c81232d3d9fc34bea81fb7cp0,
+    0x1.858eb6p4
+  },
+  { // Entry 978
+    0x1.000033441c81232d3d9fc34bea81fb7cp0,
+    -0x1.858eb6p4
+  },
+  { // Entry 979
+    -0x1.ffffe6882f603946b53b042361aec82cp-1,
+    0x1.858eb8p4
+  },
+  { // Entry 980
+    0x1.ffffe6882f603946b53b042361aec82cp-1,
+    -0x1.858eb8p4
+  },
+  { // Entry 981
+    -0x1.cb6cd4cb82a91dfc4af9a499a575e4a4p-3,
+    0x1.fffffep62
+  },
+  { // Entry 982
+    0x1.cb6cd4cb82a91dfc4af9a499a575e4a4p-3,
+    -0x1.fffffep62
+  },
+  { // Entry 983
+    0x1.52f50e757941cbff5b7c2e06a1ab7e9dp6,
+    0x1.p63
+  },
+  { // Entry 984
+    -0x1.52f50e757941cbff5b7c2e06a1ab7e9dp6,
+    -0x1.p63
+  },
+  { // Entry 985
+    -0x1.29cbd12821b399c9ee4f265da51881a8p1,
+    0x1.000002p63
+  },
+  { // Entry 986
+    0x1.29cbd12821b399c9ee4f265da51881a8p1,
+    -0x1.000002p63
+  },
+  { // Entry 987
+    0x1.3e4d9148d7086727da944e1c052b68afp-1,
+    0x1.fffffep26
+  },
+  { // Entry 988
+    -0x1.3e4d9148d7086727da944e1c052b68afp-1,
+    -0x1.fffffep26
+  },
+  { // Entry 989
+    -0x1.2e8fc1af81d8baa8899a3325200c0dcbp0,
+    0x1.p27
+  },
+  { // Entry 990
+    0x1.2e8fc1af81d8baa8899a3325200c0dcbp0,
+    -0x1.p27
+  },
+  { // Entry 991
+    -0x1.4ce9748e524f77ad85735c7f7d668cf1p-1,
+    0x1.000002p27
+  },
+  { // Entry 992
+    0x1.4ce9748e524f77ad85735c7f7d668cf1p-1,
+    -0x1.000002p27
+  },
+  { // Entry 993
+    0x1.7e3005d57ed93ae45b1bea3e3615bb67p1,
+    0x1.fffffep23
+  },
+  { // Entry 994
+    -0x1.7e3005d57ed93ae45b1bea3e3615bb67p1,
+    -0x1.fffffep23
+  },
+  { // Entry 995
+    -0x1.3ea28271a9bea36e744f9ce537ba4b59p0,
+    0x1.p24
+  },
+  { // Entry 996
+    0x1.3ea28271a9bea36e744f9ce537ba4b59p0,
+    -0x1.p24
+  },
+  { // Entry 997
+    0x1.fe929b4282105a160a9be2731df20a6cp0,
+    0x1.000002p24
+  },
+  { // Entry 998
+    -0x1.fe929b4282105a160a9be2731df20a6cp0,
+    -0x1.000002p24
+  },
+  { // Entry 999
+    0x1.2866f06194e0c2c7ee22ee9f8f9dcaeep0,
+    0x1.fffffep1
+  },
+  { // Entry 1000
+    -0x1.2866f06194e0c2c7ee22ee9f8f9dcaeep0,
+    -0x1.fffffep1
+  },
+  { // Entry 1001
+    0x1.2866f9be4de1370db9078607012cb07bp0,
+    0x1.p2
+  },
+  { // Entry 1002
+    -0x1.2866f9be4de1370db9078607012cb07bp0,
+    -0x1.p2
+  },
+  { // Entry 1003
+    0x1.28670c77c0e647138d4fc7181ef9b61fp0,
+    0x1.000002p2
+  },
+  { // Entry 1004
+    -0x1.28670c77c0e647138d4fc7181ef9b61fp0,
+    -0x1.000002p2
+  },
+  { // Entry 1005
+    -0x1.17af68a6d42f772bd249f5d692afa4e7p1,
+    0x1.fffffep0
+  },
+  { // Entry 1006
+    0x1.17af68a6d42f772bd249f5d692afa4e7p1,
+    -0x1.fffffep0
+  },
+  { // Entry 1007
+    -0x1.17af62e0950f83b5099087aaf67af9c1p1,
+    0x1.p1
+  },
+  { // Entry 1008
+    0x1.17af62e0950f83b5099087aaf67af9c1p1,
+    -0x1.p1
+  },
+  { // Entry 1009
+    -0x1.17af5754176705173cec89d01381f553p1,
+    0x1.000002p1
+  },
+  { // Entry 1010
+    0x1.17af5754176705173cec89d01381f553p1,
+    -0x1.000002p1
+  },
+  { // Entry 1011
+    0x1.8eb2425eff72860d56d61056db54ef67p0,
+    0x1.fffffep-1
+  },
+  { // Entry 1012
+    -0x1.8eb2425eff72860d56d61056db54ef67p0,
+    -0x1.fffffep-1
+  },
+  { // Entry 1013
+    0x1.8eb245cbee3a5b8acc7d41323140b3b5p0,
+    0x1.p0
+  },
+  { // Entry 1014
+    -0x1.8eb245cbee3a5b8acc7d41323140b3b5p0,
+    -0x1.p0
+  },
+  { // Entry 1015
+    0x1.8eb24ca5cbea08f991206a3eaf93ab98p0,
+    0x1.000002p0
+  },
+  { // Entry 1016
+    -0x1.8eb24ca5cbea08f991206a3eaf93ab98p0,
+    -0x1.000002p0
+  },
+  { // Entry 1017
+    0x1.17b4f472cd791aabfe4ea91afb5e79e7p-1,
+    0x1.fffffep-2
+  },
+  { // Entry 1018
+    -0x1.17b4f472cd791aabfe4ea91afb5e79e7p-1,
+    -0x1.fffffep-2
+  },
+  { // Entry 1019
+    0x1.17b4f5bf3474a4317964807882444cc8p-1,
+    0x1.p-1
+  },
+  { // Entry 1020
+    -0x1.17b4f5bf3474a4317964807882444cc8p-1,
+    -0x1.p-1
+  },
+  { // Entry 1021
+    0x1.17b4f858026dd8033ed3d8d6d5350ca9p-1,
+    0x1.000002p-1
+  },
+  { // Entry 1022
+    -0x1.17b4f858026dd8033ed3d8d6d5350ca9p-1,
+    -0x1.000002p-1
+  },
+  { // Entry 1023
+    0x1.0578593313db659cf3ab88a235218456p-2,
+    0x1.fffffep-3
+  },
+  { // Entry 1024
+    -0x1.0578593313db659cf3ab88a235218456p-2,
+    -0x1.fffffep-3
+  },
+  { // Entry 1025
+    0x1.05785a43c4c55e63940188965c28bd0fp-2,
+    0x1.p-2
+  },
+  { // Entry 1026
+    -0x1.05785a43c4c55e63940188965c28bd0fp-2,
+    -0x1.p-2
+  },
+  { // Entry 1027
+    0x1.05785c652699b8628b7876b7bd83c0ccp-2,
+    0x1.000002p-2
+  },
+  { // Entry 1028
+    -0x1.05785c652699b8628b7876b7bd83c0ccp-2,
+    -0x1.000002p-2
+  },
+  { // Entry 1029
+    0x1.015779ed46574724b9025a4472a1ae0ap-3,
+    0x1.fffffep-4
+  },
+  { // Entry 1030
+    -0x1.015779ed46574724b9025a4472a1ae0ap-3,
+    -0x1.fffffep-4
+  },
+  { // Entry 1031
+    0x1.01577af1511a4e0459f5b872d4ff34fdp-3,
+    0x1.p-3
+  },
+  { // Entry 1032
+    -0x1.01577af1511a4e0459f5b872d4ff34fdp-3,
+    -0x1.p-3
+  },
+  { // Entry 1033
+    0x1.01577cf966a0744553dd44a994f0bbd1p-3,
+    0x1.000002p-3
+  },
+  { // Entry 1034
+    -0x1.01577cf966a0744553dd44a994f0bbd1p-3,
+    -0x1.000002p-3
+  },
+  { // Entry 1035
+    0x1.005576844d44fda0b80348bb17498aa1p-4,
+    0x1.fffffep-5
+  },
+  { // Entry 1036
+    -0x1.005576844d44fda0b80348bb17498aa1p-4,
+    -0x1.fffffep-5
+  },
+  { // Entry 1037
+    0x1.005577854df0083293be639057b0c681p-4,
+    0x1.p-4
+  },
+  { // Entry 1038
+    -0x1.005577854df0083293be639057b0c681p-4,
+    -0x1.p-4
+  },
+  { // Entry 1039
+    0x1.005579874f46235e52082a4d0ddfc6e1p-4,
+    0x1.000002p-4
+  },
+  { // Entry 1040
+    -0x1.005579874f46235e52082a4d0ddfc6e1p-4,
+    -0x1.000002p-4
+  },
+  { // Entry 1041
+    0x1.001556776eb5d98f82e1b5eab28c6b5fp-5,
+    0x1.fffffep-6
+  },
+  { // Entry 1042
+    -0x1.001556776eb5d98f82e1b5eab28c6b5fp-5,
+    -0x1.fffffep-6
+  },
+  { // Entry 1043
+    0x1.00155777aec0857d22c97e809860288dp-5,
+    0x1.p-5
+  },
+  { // Entry 1044
+    -0x1.00155777aec0857d22c97e809860288dp-5,
+    -0x1.p-5
+  },
+  { // Entry 1045
+    0x1.001559782ed5ded8e2b4c819cb7c9f11p-5,
+    0x1.000002p-5
+  },
+  { // Entry 1046
+    -0x1.001559782ed5ded8e2b4c819cb7c9f11p-5,
+    -0x1.000002p-5
+  },
+  { // Entry 1047
+    0x1.000554776853e041010da22a656f8267p-6,
+    0x1.fffffep-7
+  },
+  { // Entry 1048
+    -0x1.000554776853e041010da22a656f8267p-6,
+    -0x1.fffffep-7
+  },
+  { // Entry 1049
+    0x1.0005557778548ae1b5f60574706e8238p-6,
+    0x1.p-6
+  },
+  { // Entry 1050
+    -0x1.0005557778548ae1b5f60574706e8238p-6,
+    -0x1.p-6
+  },
+  { // Entry 1051
+    0x1.000557779855e08327c758e20d691dadp-6,
+    0x1.000002p-6
+  },
+  { // Entry 1052
+    -0x1.000557779855e08327c758e20d691dadp-6,
+    -0x1.000002p-6
+  },
+  { // Entry 1053
+    0x1.fffffe0aaaaa8aeeef0d9b53ad2f4823p-15,
+    0x1.fffffep-15
+  },
+  { // Entry 1054
+    -0x1.fffffe0aaaaa8aeeef0d9b53ad2f4823p-15,
+    -0x1.fffffep-15
+  },
+  { // Entry 1055
+    0x1.00000005555555777777785485485a1ep-14,
+    0x1.p-14
+  },
+  { // Entry 1056
+    -0x1.00000005555555777777785485485a1ep-14,
+    -0x1.p-14
+  },
+  { // Entry 1057
+    0x1.000002055555757777b8cdaa0aa9c640p-14,
+    0x1.000002p-14
+  },
+  { // Entry 1058
+    -0x1.000002055555757777b8cdaa0aa9c640p-14,
+    -0x1.000002p-14
+  },
+  { // Entry 1059
+    0x1.fffffe00000002aaaaa2aaaab2aeeeecp-28,
+    0x1.fffffep-28
+  },
+  { // Entry 1060
+    -0x1.fffffe00000002aaaaa2aaaab2aeeeecp-28,
+    -0x1.fffffep-28
+  },
+  { // Entry 1061
+    0x1.00000000000001555555555555577777p-27,
+    0x1.p-27
+  },
+  { // Entry 1062
+    -0x1.00000000000001555555555555577777p-27,
+    -0x1.p-27
+  },
+  { // Entry 1063
+    0x1.0000020000000155555d555565577782p-27,
+    0x1.000002p-27
+  },
+  { // Entry 1064
+    -0x1.0000020000000155555d555565577782p-27,
+    -0x1.000002p-27
+  },
+  { // Entry 1065
+    0x1.fffffe000000000aaaaa8aaaaacaaaeep-31,
+    0x1.fffffep-31
+  },
+  { // Entry 1066
+    -0x1.fffffe000000000aaaaa8aaaaacaaaeep-31,
+    -0x1.fffffep-31
+  },
+  { // Entry 1067
+    0x1.00000000000000055555555555555577p-30,
+    0x1.p-30
+  },
+  { // Entry 1068
+    -0x1.00000000000000055555555555555577p-30,
+    -0x1.p-30
+  },
+  { // Entry 1069
+    0x1.00000200000000055555755555955577p-30,
+    0x1.000002p-30
+  },
+  { // Entry 1070
+    -0x1.00000200000000055555755555955577p-30,
+    -0x1.000002p-30
+  },
+  { // Entry 1071
+    0x1.393d94b4988c1f254345c9f7d9ea0c03p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1072
+    -0x1.393d94b4988c1f254345c9f7d9ea0c03p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1073
+    -0x1.393d94b4988c1f254345c9f7d9ea0c03p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1074
+    0x1.393d94b4988c1f254345c9f7d9ea0c03p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1075
+    -0x1.393d94b4988c1f254345c9f7d9ea0c03p-1,
+    0x1.fffffep127
+  },
+  { // Entry 1076
+    0x1.393d94b4988c1f254345c9f7d9ea0c03p-1,
+    -0x1.fffffep127
+  },
+  { // Entry 1077
+    0x1.acf315a87aa5da8654c844b917d14745p-1,
+    0x1.fffffcp127
+  },
+  { // Entry 1078
+    -0x1.acf315a87aa5da8654c844b917d14745p-1,
+    -0x1.fffffcp127
+  },
+  { // Entry 1079
+    0x1.777a5cf72cedf3b544c81808b515f1f9p-24,
+    0x1.921fb6p1
+  },
+  { // Entry 1080
+    -0x1.777a5cf72cedf3b544c81808b515f1f9p-24,
+    -0x1.921fb6p1
+  },
+  { // Entry 1081
+    -0x1.5d14946dc98975d6421a55284fe020a1p24,
+    0x1.921fb6p0
+  },
+  { // Entry 1082
+    0x1.5d14946dc98975d6421a55284fe020a1p24,
+    -0x1.921fb6p0
+  },
+  { // Entry 1083
+    0x1.8eb24ca5cbea08f991206a3eaf93ab98p0,
+    0x1.000002p0
+  },
+  { // Entry 1084
+    -0x1.8eb24ca5cbea08f991206a3eaf93ab98p0,
+    -0x1.000002p0
+  },
+  { // Entry 1085
+    0x1.8eb245cbee3a5b8acc7d41323140b3b5p0,
+    0x1.p0
+  },
+  { // Entry 1086
+    -0x1.8eb245cbee3a5b8acc7d41323140b3b5p0,
+    -0x1.p0
+  },
+  { // Entry 1087
+    0x1.8eb2425eff72860d56d61056db54ef67p0,
+    0x1.fffffep-1
+  },
+  { // Entry 1088
+    -0x1.8eb2425eff72860d56d61056db54ef67p0,
+    -0x1.fffffep-1
+  },
+  { // Entry 1089
+    0x1.000000bbbd2ec06d6d6fff3655a346acp0,
+    0x1.921fb6p-1
+  },
+  { // Entry 1090
+    -0x1.000000bbbd2ec06d6d6fff3655a346acp0,
+    -0x1.921fb6p-1
+  },
+  { // Entry 1091
+    0x1.000002p-126,
+    0x1.000002p-126
+  },
+  { // Entry 1092
+    -0x1.000002p-126,
+    -0x1.000002p-126
+  },
+  { // Entry 1093
+    0x1.p-126,
+    0x1.p-126
+  },
+  { // Entry 1094
+    -0x1.p-126,
+    -0x1.p-126
+  },
+  { // Entry 1095
+    0x1.fffffcp-127,
+    0x1.fffffcp-127
+  },
+  { // Entry 1096
+    -0x1.fffffcp-127,
+    -0x1.fffffcp-127
+  },
+  { // Entry 1097
+    0x1.fffff8p-127,
+    0x1.fffff8p-127
+  },
+  { // Entry 1098
+    -0x1.fffff8p-127,
+    -0x1.fffff8p-127
+  },
+  { // Entry 1099
+    0x1.p-148,
+    0x1.p-148
+  },
+  { // Entry 1100
+    -0x1.p-148,
+    -0x1.p-148
+  },
+  { // Entry 1101
+    0x1.p-149,
+    0x1.p-149
+  },
+  { // Entry 1102
+    -0x1.p-149,
+    -0x1.p-149
+  },
+  { // Entry 1103
+    0.0,
+    0.0f
+  },
+  { // Entry 1104
+    -0.0,
+    -0.0f
+  },
+};
+#endif // __BIONIC__
+
+TEST(math_tanf, tanf_intel) {
+#if defined(__BIONIC__)
+  for (size_t i = 0; i < sizeof(g_tanf_intel_data)/sizeof(tanf_intel_data_t); i++) {
+    EXPECT_FLOAT_EQ(g_tanf_intel_data[i].expected, tanf(g_tanf_intel_data[i].call_data)) << "Failed on element " << i;
+  }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.";
+#endif // __BIONIC__
+}
diff --git a/tests/math_test.cpp b/tests/math_test.cpp
index 454646d..b4f5b14 100644
--- a/tests/math_test.cpp
+++ b/tests/math_test.cpp
@@ -14,13 +14,43 @@
  * limitations under the License.
  */
 
-#define _DECLARE_C99_LDBL_MATH 1
+// This include (and the associated definition of __test_capture_signbit)
+// must be placed before any files that include <cmath> (gtest.h in this case).
+//
+// <math.h> is required to define generic macros signbit, isfinite and
+// several other such functions.
+//
+// <cmath> is required to undef declarations of these macros in the global
+// namespace and make equivalent functions available in namespace std. Our
+// stlport implementation does this only for signbit, isfinite, isinf and
+// isnan.
+//
+// NOTE: We don't write our test using std::signbit because we want to be
+// sure that we're testing the bionic version of signbit. The C++ libraries
+// are free to reimplement signbit or delegate to compiler builtins if they
+// please.
+#include <math.h>
+
+namespace {
+template<typename T> inline int test_capture_signbit(const T in) {
+  return signbit(in);
+}
+template<typename T> inline int test_capture_isfinite(const T in) {
+  return isfinite(in);
+}
+template<typename T> inline int test_capture_isnan(const T in) {
+  return isnan(in);
+}
+template<typename T> inline int test_capture_isinf(const T in) {
+  return isinf(in);
+}
+}
 
 #include <gtest/gtest.h>
 
 #include <fenv.h>
+#include <float.h>
 #include <limits.h>
-#include <math.h>
 #include <stdint.h>
 
 float float_subnormal() {
@@ -41,147 +71,201 @@
   return u.d;
 }
 
+long double ldouble_subnormal() {
+  union {
+    long double e;
+    unsigned char c[sizeof(long double)];
+  } u;
+
+  // Subnormals must have a zero exponent and non zero significand.
+  // On all supported representation the 17 bit (counting from either sides)
+  // is part of the significand so it should be enough to set that.
+  // It also applies for the case sizeof(double) = sizeof(long double)
+  for (unsigned int i = 0; i < sizeof(long double); i++) {
+    u.c[i] = 0x00;
+  }
+  u.c[sizeof(long double) - 3] = 0x80;
+  u.c[2] = 0x80;
+
+  return u.e;
+}
+
 TEST(math, fpclassify) {
   ASSERT_EQ(FP_INFINITE, fpclassify(INFINITY));
   ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VALF));
   ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VAL));
+  ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VALL));
 
   ASSERT_EQ(FP_NAN, fpclassify(nanf("")));
   ASSERT_EQ(FP_NAN, fpclassify(nan("")));
+  ASSERT_EQ(FP_NAN, fpclassify(nanl("")));
 
   ASSERT_EQ(FP_NORMAL, fpclassify(1.0f));
   ASSERT_EQ(FP_NORMAL, fpclassify(1.0));
+  ASSERT_EQ(FP_NORMAL, fpclassify(1.0L));
 
   ASSERT_EQ(FP_SUBNORMAL, fpclassify(float_subnormal()));
   ASSERT_EQ(FP_SUBNORMAL, fpclassify(double_subnormal()));
+  ASSERT_EQ(FP_SUBNORMAL, fpclassify(ldouble_subnormal()));
 
   ASSERT_EQ(FP_ZERO, fpclassify(0.0f));
   ASSERT_EQ(FP_ZERO, fpclassify(0.0));
+  ASSERT_EQ(FP_ZERO, fpclassify(0.0L));
 }
 
-/* TODO: stlport breaks the isfinite macro
 TEST(math, isfinite) {
-  ASSERT_TRUE(isfinite(123.0f));
-  ASSERT_TRUE(isfinite(123.0));
-  ASSERT_FALSE(isfinite(HUGE_VALF));
-  ASSERT_FALSE(isfinite(HUGE_VAL));
+  ASSERT_TRUE(test_capture_isfinite(123.0f));
+  ASSERT_TRUE(test_capture_isfinite(123.0));
+  ASSERT_TRUE(test_capture_isfinite(123.0L));
+  ASSERT_FALSE(test_capture_isfinite(HUGE_VALF));
+  ASSERT_FALSE(test_capture_isfinite(HUGE_VAL));
+  ASSERT_FALSE(test_capture_isfinite(HUGE_VALL));
 }
-*/
 
 TEST(math, isinf) {
-  ASSERT_FALSE(isinf(123.0f));
-  ASSERT_FALSE(isinf(123.0));
-  ASSERT_TRUE(isinf(HUGE_VALF));
-  ASSERT_TRUE(isinf(HUGE_VAL));
+  ASSERT_FALSE(test_capture_isinf(123.0f));
+  ASSERT_FALSE(test_capture_isinf(123.0));
+  ASSERT_FALSE(test_capture_isinf(123.0L));
+  ASSERT_TRUE(test_capture_isinf(HUGE_VALF));
+  ASSERT_TRUE(test_capture_isinf(HUGE_VAL));
+  ASSERT_TRUE(test_capture_isinf(HUGE_VALL));
 }
 
 TEST(math, isnan) {
-  ASSERT_FALSE(isnan(123.0f));
-  ASSERT_FALSE(isnan(123.0));
-  ASSERT_TRUE(isnan(nanf("")));
-  ASSERT_TRUE(isnan(nan("")));
+  ASSERT_FALSE(test_capture_isnan(123.0f));
+  ASSERT_FALSE(test_capture_isnan(123.0));
+  ASSERT_FALSE(test_capture_isnan(123.0L));
+  ASSERT_TRUE(test_capture_isnan(nanf("")));
+  ASSERT_TRUE(test_capture_isnan(nan("")));
+  ASSERT_TRUE(test_capture_isnan(nanl("")));
 }
 
 TEST(math, isnormal) {
   ASSERT_TRUE(isnormal(123.0f));
   ASSERT_TRUE(isnormal(123.0));
+  ASSERT_TRUE(isnormal(123.0L));
   ASSERT_FALSE(isnormal(float_subnormal()));
   ASSERT_FALSE(isnormal(double_subnormal()));
+  ASSERT_FALSE(isnormal(ldouble_subnormal()));
 }
 
 // TODO: isgreater, isgreaterequals, isless, islessequal, islessgreater, isunordered
-
-/* TODO: stlport breaks the signbit macro
 TEST(math, signbit) {
-  ASSERT_EQ(0, signbit(0.0f));
-  ASSERT_EQ(0, signbit(0.0));
+  ASSERT_EQ(0, test_capture_signbit(0.0f));
+  ASSERT_EQ(0, test_capture_signbit(0.0));
+  ASSERT_EQ(0, test_capture_signbit(0.0L));
 
-  ASSERT_EQ(0, signbit(1.0f));
-  ASSERT_EQ(0, signbit(1.0));
+  ASSERT_EQ(0, test_capture_signbit(1.0f));
+  ASSERT_EQ(0, test_capture_signbit(1.0));
+  ASSERT_EQ(0, test_capture_signbit(1.0L));
 
-  ASSERT_NE(0, signbit(-1.0f));
-  ASSERT_NE(0, signbit(-1.0));
+  ASSERT_NE(0, test_capture_signbit(-1.0f));
+  ASSERT_NE(0, test_capture_signbit(-1.0));
+  ASSERT_NE(0, test_capture_signbit(-1.0L));
 }
-*/
 
-#if defined(__BIONIC__)
 TEST(math, __fpclassifyd) {
+#if defined(__BIONIC__)
   ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL));
   ASSERT_EQ(FP_NAN, __fpclassifyd(nan("")));
   ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0));
   ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal()));
   ASSERT_EQ(FP_ZERO, __fpclassifyd(0.0));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if defined(__BIONIC__)
 TEST(math, __fpclassifyf) {
+#if defined(__BIONIC__)
   ASSERT_EQ(FP_INFINITE, __fpclassifyf(HUGE_VALF));
   ASSERT_EQ(FP_NAN, __fpclassifyf(nanf("")));
   ASSERT_EQ(FP_NORMAL, __fpclassifyf(1.0f));
   ASSERT_EQ(FP_SUBNORMAL, __fpclassifyf(float_subnormal()));
   ASSERT_EQ(FP_ZERO, __fpclassifyf(0.0f));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if defined(__BIONIC__)
 TEST(math, __fpclassifyl) {
+#if defined(__BIONIC__)
   EXPECT_EQ(FP_INFINITE, __fpclassifyl(HUGE_VALL));
   EXPECT_EQ(FP_NAN, __fpclassifyl(nanl("")));
-  EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0));
-  EXPECT_EQ(FP_SUBNORMAL, __fpclassifyl(double_subnormal()));
-  EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0));
+  EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0L));
+  EXPECT_EQ(FP_SUBNORMAL, __fpclassifyl(ldouble_subnormal()));
+  EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0L));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
 TEST(math, finitef) {
   ASSERT_TRUE(finitef(123.0f));
   ASSERT_FALSE(finitef(HUGE_VALF));
 }
 
-#if defined(__BIONIC__)
 TEST(math, __isfinite) {
+#if defined(__BIONIC__)
   ASSERT_TRUE(__isfinite(123.0));
   ASSERT_FALSE(__isfinite(HUGE_VAL));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if defined(__BIONIC__)
 TEST(math, __isfinitef) {
+#if defined(__BIONIC__)
   ASSERT_TRUE(__isfinitef(123.0f));
   ASSERT_FALSE(__isfinitef(HUGE_VALF));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if defined(__BIONIC__)
 TEST(math, __isfinitel) {
-  ASSERT_TRUE(__isfinitel(123.0f));
+#if defined(__BIONIC__)
+  ASSERT_TRUE(__isfinitel(123.0L));
   ASSERT_FALSE(__isfinitel(HUGE_VALL));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
 TEST(math, finite) {
   ASSERT_TRUE(finite(123.0));
   ASSERT_FALSE(finite(HUGE_VAL));
 }
 
+TEST(math, isinf_function) {
+  // The isinf macro deals with all three types; the isinf function is for doubles.
+  ASSERT_FALSE((isinf)(123.0));
+  ASSERT_TRUE((isinf)(HUGE_VAL));
+}
+
 TEST(math, __isinff) {
   ASSERT_FALSE(__isinff(123.0f));
   ASSERT_TRUE(__isinff(HUGE_VALF));
 }
 
 TEST(math, __isinfl) {
-  ASSERT_FALSE(__isinfl(123.0));
+  ASSERT_FALSE(__isinfl(123.0L));
   ASSERT_TRUE(__isinfl(HUGE_VALL));
 }
 
+TEST(math, isnan_function) {
+  // The isnan macro deals with all three types; the isnan function is for doubles.
+  ASSERT_FALSE((isnan)(123.0));
+  ASSERT_TRUE((isnan)(nan("")));
+}
+
 TEST(math, __isnanf) {
   ASSERT_FALSE(__isnanf(123.0f));
   ASSERT_TRUE(__isnanf(nanf("")));
 }
 
 TEST(math, __isnanl) {
-  ASSERT_FALSE(__isnanl(123.0));
+  ASSERT_FALSE(__isnanl(123.0L));
   ASSERT_TRUE(__isnanl(nanl("")));
 }
 
@@ -190,26 +274,32 @@
   ASSERT_TRUE(isnanf(nanf("")));
 }
 
-#if defined(__BIONIC__)
 TEST(math, __isnormal) {
+#if defined(__BIONIC__)
   ASSERT_TRUE(__isnormal(123.0));
   ASSERT_FALSE(__isnormal(double_subnormal()));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if defined(__BIONIC__)
 TEST(math, __isnormalf) {
+#if defined(__BIONIC__)
   ASSERT_TRUE(__isnormalf(123.0f));
   ASSERT_FALSE(__isnormalf(float_subnormal()));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if defined(__BIONIC__)
 TEST(math, __isnormall) {
-  ASSERT_TRUE(__isnormall(123.0));
-  ASSERT_FALSE(__isnormall(double_subnormal()));
+#if defined(__BIONIC__)
+  ASSERT_TRUE(__isnormall(123.0L));
+  ASSERT_FALSE(__isnormall(ldouble_subnormal()));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
 TEST(math, __signbit) {
   ASSERT_EQ(0, __signbit(0.0));
@@ -224,13 +314,13 @@
 }
 
 TEST(math, __signbitl) {
-  ASSERT_EQ(0, __signbitl(0.0));
-  ASSERT_EQ(0, __signbitl(1.0));
-  ASSERT_NE(0, __signbitl(-1.0));
+  ASSERT_EQ(0L, __signbitl(0.0L));
+  ASSERT_EQ(0L, __signbitl(1.0L));
+  ASSERT_NE(0L, __signbitl(-1.0L));
 }
 
 TEST(math, acos) {
-  ASSERT_FLOAT_EQ(M_PI/2.0, acos(0.0));
+  ASSERT_DOUBLE_EQ(M_PI/2.0, acos(0.0));
 }
 
 TEST(math, acosf) {
@@ -238,11 +328,11 @@
 }
 
 TEST(math, acosl) {
-  ASSERT_FLOAT_EQ(M_PI/2.0, acosl(0.0));
+  ASSERT_DOUBLE_EQ(M_PI/2.0L, acosl(0.0L));
 }
 
 TEST(math, asin) {
-  ASSERT_FLOAT_EQ(0.0, asin(0.0));
+  ASSERT_DOUBLE_EQ(0.0, asin(0.0));
 }
 
 TEST(math, asinf) {
@@ -250,11 +340,11 @@
 }
 
 TEST(math, asinl) {
-  ASSERT_FLOAT_EQ(0.0, asinl(0.0));
+  ASSERT_DOUBLE_EQ(0.0L, asinl(0.0L));
 }
 
 TEST(math, atan) {
-  ASSERT_FLOAT_EQ(0.0, atan(0.0));
+  ASSERT_DOUBLE_EQ(0.0, atan(0.0));
 }
 
 TEST(math, atanf) {
@@ -262,11 +352,11 @@
 }
 
 TEST(math, atanl) {
-  ASSERT_FLOAT_EQ(0.0, atanl(0.0));
+  ASSERT_DOUBLE_EQ(0.0L, atanl(0.0L));
 }
 
 TEST(math, atan2) {
-  ASSERT_FLOAT_EQ(0.0, atan2(0.0, 0.0));
+  ASSERT_DOUBLE_EQ(0.0, atan2(0.0, 0.0));
 }
 
 TEST(math, atan2f) {
@@ -274,11 +364,11 @@
 }
 
 TEST(math, atan2l) {
-  ASSERT_FLOAT_EQ(0.0, atan2l(0.0, 0.0));
+  ASSERT_DOUBLE_EQ(0.0L, atan2l(0.0L, 0.0L));
 }
 
 TEST(math, cos) {
-  ASSERT_FLOAT_EQ(1.0, cos(0.0));
+  ASSERT_DOUBLE_EQ(1.0, cos(0.0));
 }
 
 TEST(math, cosf) {
@@ -286,11 +376,11 @@
 }
 
 TEST(math, cosl) {
-  ASSERT_FLOAT_EQ(1.0, cosl(0.0));
+  ASSERT_DOUBLE_EQ(1.0L, cosl(0.0L));
 }
 
 TEST(math, sin) {
-  ASSERT_FLOAT_EQ(0.0, sin(0.0));
+  ASSERT_DOUBLE_EQ(0.0, sin(0.0));
 }
 
 TEST(math, sinf) {
@@ -298,11 +388,11 @@
 }
 
 TEST(math, sinl) {
-  ASSERT_FLOAT_EQ(0.0, sinl(0.0));
+  ASSERT_DOUBLE_EQ(0.0L, sinl(0.0L));
 }
 
 TEST(math, tan) {
-  ASSERT_FLOAT_EQ(0.0, tan(0.0));
+  ASSERT_DOUBLE_EQ(0.0, tan(0.0));
 }
 
 TEST(math, tanf) {
@@ -310,11 +400,11 @@
 }
 
 TEST(math, tanl) {
-  ASSERT_FLOAT_EQ(0.0, tanl(0.0));
+  ASSERT_DOUBLE_EQ(0.0L, tanl(0.0L));
 }
 
 TEST(math, acosh) {
-  ASSERT_FLOAT_EQ(0.0, acosh(1.0));
+  ASSERT_DOUBLE_EQ(0.0, acosh(1.0));
 }
 
 TEST(math, acoshf) {
@@ -322,11 +412,11 @@
 }
 
 TEST(math, acoshl) {
-  ASSERT_FLOAT_EQ(0.0, acoshl(1.0));
+  ASSERT_DOUBLE_EQ(0.0L, acoshl(1.0L));
 }
 
 TEST(math, asinh) {
-  ASSERT_FLOAT_EQ(0.0, asinh(0.0));
+  ASSERT_DOUBLE_EQ(0.0, asinh(0.0));
 }
 
 TEST(math, asinhf) {
@@ -334,11 +424,11 @@
 }
 
 TEST(math, asinhl) {
-  ASSERT_FLOAT_EQ(0.0, asinhl(0.0));
+  ASSERT_DOUBLE_EQ(0.0L, asinhl(0.0L));
 }
 
 TEST(math, atanh) {
-  ASSERT_FLOAT_EQ(0.0, atanh(0.0));
+  ASSERT_DOUBLE_EQ(0.0, atanh(0.0));
 }
 
 TEST(math, atanhf) {
@@ -346,11 +436,11 @@
 }
 
 TEST(math, atanhl) {
-  ASSERT_FLOAT_EQ(0.0, atanhl(0.0));
+  ASSERT_DOUBLE_EQ(0.0L, atanhl(0.0L));
 }
 
 TEST(math, cosh) {
-  ASSERT_FLOAT_EQ(1.0, cosh(0.0));
+  ASSERT_DOUBLE_EQ(1.0, cosh(0.0));
 }
 
 TEST(math, coshf) {
@@ -358,11 +448,11 @@
 }
 
 TEST(math, coshl) {
-  ASSERT_FLOAT_EQ(1.0, coshl(0.0));
+  ASSERT_DOUBLE_EQ(1.0L, coshl(0.0L));
 }
 
 TEST(math, sinh) {
-  ASSERT_FLOAT_EQ(0.0, sinh(0.0));
+  ASSERT_DOUBLE_EQ(0.0, sinh(0.0));
 }
 
 TEST(math, sinhf) {
@@ -370,11 +460,11 @@
 }
 
 TEST(math, sinhl) {
-  ASSERT_FLOAT_EQ(0.0, sinhl(0.0));
+  ASSERT_DOUBLE_EQ(0.0L, sinhl(0.0L));
 }
 
 TEST(math, tanh) {
-  ASSERT_FLOAT_EQ(0.0, tanh(0.0));
+  ASSERT_DOUBLE_EQ(0.0, tanh(0.0));
 }
 
 TEST(math, tanhf) {
@@ -382,11 +472,11 @@
 }
 
 TEST(math, tanhl) {
-  ASSERT_FLOAT_EQ(0.0, tanhl(0.0));
+  ASSERT_DOUBLE_EQ(0.0L, tanhl(0.0L));
 }
 
 TEST(math, log) {
-  ASSERT_FLOAT_EQ(1.0, log(M_E));
+  ASSERT_DOUBLE_EQ(1.0, log(M_E));
 }
 
 TEST(math, logf) {
@@ -394,11 +484,11 @@
 }
 
 TEST(math, logl) {
-  ASSERT_FLOAT_EQ(1.0, logl(M_E));
+  ASSERT_DOUBLE_EQ(1.0L, logl(M_E));
 }
 
 TEST(math, log2) {
-  ASSERT_FLOAT_EQ(12.0, log2(4096.0));
+  ASSERT_DOUBLE_EQ(12.0, log2(4096.0));
 }
 
 TEST(math, log2f) {
@@ -406,11 +496,11 @@
 }
 
 TEST(math, log2l) {
-  ASSERT_FLOAT_EQ(12.0, log2l(4096.0));
+  ASSERT_DOUBLE_EQ(12.0L, log2l(4096.0L));
 }
 
 TEST(math, log10) {
-  ASSERT_FLOAT_EQ(3.0, log10(1000.0));
+  ASSERT_DOUBLE_EQ(3.0, log10(1000.0));
 }
 
 TEST(math, log10f) {
@@ -418,11 +508,11 @@
 }
 
 TEST(math, log10l) {
-  ASSERT_FLOAT_EQ(3.0, log10l(1000.0));
+  ASSERT_DOUBLE_EQ(3.0L, log10l(1000.0L));
 }
 
 TEST(math, cbrt) {
-  ASSERT_FLOAT_EQ(3.0, cbrt(27.0));
+  ASSERT_DOUBLE_EQ(3.0, cbrt(27.0));
 }
 
 TEST(math, cbrtf) {
@@ -430,11 +520,11 @@
 }
 
 TEST(math, cbrtl) {
-  ASSERT_FLOAT_EQ(3.0, cbrtl(27.0));
+  ASSERT_DOUBLE_EQ(3.0L, cbrtl(27.0L));
 }
 
 TEST(math, sqrt) {
-  ASSERT_FLOAT_EQ(2.0, sqrt(4.0));
+  ASSERT_DOUBLE_EQ(2.0, sqrt(4.0));
 }
 
 TEST(math, sqrtf) {
@@ -442,12 +532,12 @@
 }
 
 TEST(math, sqrtl) {
-  ASSERT_FLOAT_EQ(2.0, sqrtl(4.0));
+  ASSERT_DOUBLE_EQ(2.0L, sqrtl(4.0L));
 }
 
 TEST(math, exp) {
-  ASSERT_FLOAT_EQ(1.0, exp(0.0));
-  ASSERT_FLOAT_EQ(M_E, exp(1.0));
+  ASSERT_DOUBLE_EQ(1.0, exp(0.0));
+  ASSERT_DOUBLE_EQ(M_E, exp(1.0));
 }
 
 TEST(math, expf) {
@@ -456,12 +546,12 @@
 }
 
 TEST(math, expl) {
-  ASSERT_FLOAT_EQ(1.0, expl(0.0));
-  ASSERT_FLOAT_EQ(M_E, expl(1.0));
+  ASSERT_DOUBLE_EQ(1.0L, expl(0.0L));
+  ASSERT_DOUBLE_EQ(M_E, expl(1.0L));
 }
 
 TEST(math, exp2) {
-  ASSERT_FLOAT_EQ(8.0, exp2(3.0));
+  ASSERT_DOUBLE_EQ(8.0, exp2(3.0));
 }
 
 TEST(math, exp2f) {
@@ -469,11 +559,11 @@
 }
 
 TEST(math, exp2l) {
-  ASSERT_FLOAT_EQ(8.0, exp2l(3.0));
+  ASSERT_DOUBLE_EQ(8.0L, exp2l(3.0L));
 }
 
 TEST(math, expm1) {
-  ASSERT_FLOAT_EQ(M_E - 1.0, expm1(1.0));
+  ASSERT_DOUBLE_EQ(M_E - 1.0, expm1(1.0));
 }
 
 TEST(math, expm1f) {
@@ -481,14 +571,14 @@
 }
 
 TEST(math, expm1l) {
-  ASSERT_FLOAT_EQ(M_E - 1.0, expm1l(1.0));
+  ASSERT_DOUBLE_EQ(M_E - 1.0L, expm1l(1.0L));
 }
 
 TEST(math, pow) {
   ASSERT_TRUE(isnan(pow(nan(""), 3.0)));
-  ASSERT_FLOAT_EQ(1.0, (pow(1.0, nan(""))));
+  ASSERT_DOUBLE_EQ(1.0, (pow(1.0, nan(""))));
   ASSERT_TRUE(isnan(pow(2.0, nan(""))));
-  ASSERT_FLOAT_EQ(8.0, pow(2.0, 3.0));
+  ASSERT_DOUBLE_EQ(8.0, pow(2.0, 3.0));
 }
 
 TEST(math, powf) {
@@ -499,14 +589,14 @@
 }
 
 TEST(math, powl) {
-  ASSERT_TRUE(__isnanl(powl(nanl(""), 3.0)));
-  ASSERT_FLOAT_EQ(1.0, (powl(1.0, nanl(""))));
-  ASSERT_TRUE(__isnanl(powl(2.0, nanl(""))));
-  ASSERT_FLOAT_EQ(8.0, powl(2.0, 3.0));
+  ASSERT_TRUE(__isnanl(powl(nanl(""), 3.0L)));
+  ASSERT_DOUBLE_EQ(1.0L, (powl(1.0L, nanl(""))));
+  ASSERT_TRUE(__isnanl(powl(2.0L, nanl(""))));
+  ASSERT_DOUBLE_EQ(8.0L, powl(2.0L, 3.0L));
 }
 
 TEST(math, ceil) {
-  ASSERT_FLOAT_EQ(1.0, ceil(0.9));
+  ASSERT_DOUBLE_EQ(1.0, ceil(0.9));
 }
 
 TEST(math, ceilf) {
@@ -514,11 +604,11 @@
 }
 
 TEST(math, ceill) {
-  ASSERT_FLOAT_EQ(1.0, ceill(0.9));
+  ASSERT_DOUBLE_EQ(1.0L, ceill(0.9L));
 }
 
 TEST(math, floor) {
-  ASSERT_FLOAT_EQ(1.0, floor(1.1));
+  ASSERT_DOUBLE_EQ(1.0, floor(1.1));
 }
 
 TEST(math, floorf) {
@@ -526,11 +616,11 @@
 }
 
 TEST(math, floorl) {
-  ASSERT_FLOAT_EQ(1.0, floorl(1.1));
+  ASSERT_DOUBLE_EQ(1.0L, floorl(1.1L));
 }
 
 TEST(math, fabs) {
-  ASSERT_FLOAT_EQ(1.0, fabs(-1.0));
+  ASSERT_DOUBLE_EQ(1.0, fabs(-1.0));
 }
 
 TEST(math, fabsf) {
@@ -538,11 +628,11 @@
 }
 
 TEST(math, fabsl) {
-  ASSERT_FLOAT_EQ(1.0, fabsl(-1.0));
+  ASSERT_DOUBLE_EQ(1.0L, fabsl(-1.0L));
 }
 
 TEST(math, ldexp) {
-  ASSERT_FLOAT_EQ(16.0, ldexp(2.0, 3.0));
+  ASSERT_DOUBLE_EQ(16.0, ldexp(2.0, 3.0));
 }
 
 TEST(math, ldexpf) {
@@ -550,11 +640,11 @@
 }
 
 TEST(math, ldexpl) {
-  ASSERT_FLOAT_EQ(16.0, ldexpl(2.0, 3.0));
+  ASSERT_DOUBLE_EQ(16.0L, ldexpl(2.0L, 3.0));
 }
 
 TEST(math, fmod) {
-  ASSERT_FLOAT_EQ(2.0, fmod(12.0, 10.0));
+  ASSERT_DOUBLE_EQ(2.0, fmod(12.0, 10.0));
 }
 
 TEST(math, fmodf) {
@@ -562,11 +652,11 @@
 }
 
 TEST(math, fmodl) {
-  ASSERT_FLOAT_EQ(2.0, fmodl(12.0, 10.0));
+  ASSERT_DOUBLE_EQ(2.0L, fmodl(12.0L, 10.0L));
 }
 
 TEST(math, remainder) {
-  ASSERT_FLOAT_EQ(2.0, remainder(12.0, 10.0));
+  ASSERT_DOUBLE_EQ(2.0, remainder(12.0, 10.0));
 }
 
 TEST(math, remainderf) {
@@ -574,11 +664,11 @@
 }
 
 TEST(math, remainderl) {
-  ASSERT_FLOAT_EQ(2.0, remainderl(12.0, 10.0));
+  ASSERT_DOUBLE_EQ(2.0L, remainderl(12.0L, 10.0L));
 }
 
 TEST(math, drem) {
-  ASSERT_FLOAT_EQ(2.0, drem(12.0, 10.0));
+  ASSERT_DOUBLE_EQ(2.0, drem(12.0, 10.0));
 }
 
 TEST(math, dremf) {
@@ -586,9 +676,9 @@
 }
 
 TEST(math, fmax) {
-  ASSERT_FLOAT_EQ(12.0, fmax(12.0, 10.0));
-  ASSERT_FLOAT_EQ(12.0, fmax(12.0, nan("")));
-  ASSERT_FLOAT_EQ(12.0, fmax(nan(""), 12.0));
+  ASSERT_DOUBLE_EQ(12.0, fmax(12.0, 10.0));
+  ASSERT_DOUBLE_EQ(12.0, fmax(12.0, nan("")));
+  ASSERT_DOUBLE_EQ(12.0, fmax(nan(""), 12.0));
 }
 
 TEST(math, fmaxf) {
@@ -598,15 +688,15 @@
 }
 
 TEST(math, fmaxl) {
-  ASSERT_FLOAT_EQ(12.0, fmaxl(12.0, 10.0));
-  ASSERT_FLOAT_EQ(12.0, fmaxl(12.0, nanl("")));
-  ASSERT_FLOAT_EQ(12.0, fmaxl(nanl(""), 12.0));
+  ASSERT_DOUBLE_EQ(12.0L, fmaxl(12.0L, 10.0L));
+  ASSERT_DOUBLE_EQ(12.0L, fmaxl(12.0L, nanl("")));
+  ASSERT_DOUBLE_EQ(12.0L, fmaxl(nanl(""), 12.0L));
 }
 
 TEST(math, fmin) {
-  ASSERT_FLOAT_EQ(10.0, fmin(12.0, 10.0));
-  ASSERT_FLOAT_EQ(12.0, fmin(12.0, nan("")));
-  ASSERT_FLOAT_EQ(12.0, fmin(nan(""), 12.0));
+  ASSERT_DOUBLE_EQ(10.0, fmin(12.0, 10.0));
+  ASSERT_DOUBLE_EQ(12.0, fmin(12.0, nan("")));
+  ASSERT_DOUBLE_EQ(12.0, fmin(nan(""), 12.0));
 }
 
 TEST(math, fminf) {
@@ -616,13 +706,13 @@
 }
 
 TEST(math, fminl) {
-  ASSERT_FLOAT_EQ(10.0, fminl(12.0, 10.0));
-  ASSERT_FLOAT_EQ(12.0, fminl(12.0, nan("")));
-  ASSERT_FLOAT_EQ(12.0, fminl(nan(""), 12.0));
+  ASSERT_DOUBLE_EQ(10.0L, fminl(12.0L, 10.0L));
+  ASSERT_DOUBLE_EQ(12.0L, fminl(12.0L, nanl("")));
+  ASSERT_DOUBLE_EQ(12.0L, fminl(nanl(""), 12.0L));
 }
 
 TEST(math, fma) {
-  ASSERT_FLOAT_EQ(10.0, fma(2.0, 3.0, 4.0));
+  ASSERT_DOUBLE_EQ(10.0, fma(2.0, 3.0, 4.0));
 }
 
 TEST(math, fmaf) {
@@ -630,11 +720,11 @@
 }
 
 TEST(math, fmal) {
-  ASSERT_FLOAT_EQ(10.0, fmal(2.0, 3.0, 4.0));
+  ASSERT_DOUBLE_EQ(10.0L, fmal(2.0L, 3.0L, 4.0L));
 }
 
 TEST(math, hypot) {
-  ASSERT_FLOAT_EQ(5.0, hypot(3.0, 4.0));
+  ASSERT_DOUBLE_EQ(5.0, hypot(3.0, 4.0));
 }
 
 TEST(math, hypotf) {
@@ -642,11 +732,11 @@
 }
 
 TEST(math, hypotl) {
-  ASSERT_FLOAT_EQ(5.0, hypotl(3.0, 4.0));
+  ASSERT_DOUBLE_EQ(5.0L, hypotl(3.0L, 4.0L));
 }
 
 TEST(math, erf) {
-  ASSERT_FLOAT_EQ(0.84270078, erf(1.0));
+  ASSERT_DOUBLE_EQ(0.84270079294971489, erf(1.0));
 }
 
 TEST(math, erff) {
@@ -654,11 +744,11 @@
 }
 
 TEST(math, erfl) {
-  ASSERT_FLOAT_EQ(0.84270078, erfl(1.0));
+  ASSERT_DOUBLE_EQ(0.84270079294971489L, erfl(1.0L));
 }
 
 TEST(math, erfc) {
-  ASSERT_FLOAT_EQ(0.15729921, erfc(1.0));
+  ASSERT_DOUBLE_EQ(0.15729920705028513, erfc(1.0));
 }
 
 TEST(math, erfcf) {
@@ -666,27 +756,27 @@
 }
 
 TEST(math, erfcl) {
-  ASSERT_FLOAT_EQ(0.15729921, erfcl(1.0));
+  ASSERT_DOUBLE_EQ(0.15729920705028513l, erfcl(1.0L));
 }
 
 TEST(math, lrint) {
   fesetround(FE_UPWARD); // lrint/lrintf/lrintl obey the rounding mode.
   ASSERT_EQ(1235, lrint(1234.01));
   ASSERT_EQ(1235, lrintf(1234.01f));
-  ASSERT_EQ(1235, lrintl(1234.01));
+  ASSERT_EQ(1235, lrintl(1234.01L));
   fesetround(FE_TOWARDZERO); // lrint/lrintf/lrintl obey the rounding mode.
   ASSERT_EQ(1234, lrint(1234.01));
   ASSERT_EQ(1234, lrintf(1234.01f));
-  ASSERT_EQ(1234, lrintl(1234.01));
+  ASSERT_EQ(1234, lrintl(1234.01L));
 
   fesetround(FE_UPWARD); // llrint/llrintf/llrintl obey the rounding mode.
   ASSERT_EQ(1235L, llrint(1234.01));
   ASSERT_EQ(1235L, llrintf(1234.01f));
-  ASSERT_EQ(1235L, llrintl(1234.01));
+  ASSERT_EQ(1235L, llrintl(1234.01L));
   fesetround(FE_TOWARDZERO); // llrint/llrintf/llrintl obey the rounding mode.
   ASSERT_EQ(1234L, llrint(1234.01));
   ASSERT_EQ(1234L, llrintf(1234.01f));
-  ASSERT_EQ(1234L, llrintl(1234.01));
+  ASSERT_EQ(1234L, llrintl(1234.01L));
 }
 
 TEST(math, rint) {
@@ -704,15 +794,15 @@
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
 
   feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
-  ASSERT_EQ(1234.0, rintl(1234.0));
+  ASSERT_EQ(1234.0, rintl(1234.0L));
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
-  ASSERT_EQ(1235.0, rintl(1234.01));
+  ASSERT_EQ(1235.0, rintl(1234.01L));
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
 
   fesetround(FE_TOWARDZERO); // rint/rintf obey the rounding mode.
   ASSERT_EQ(1234.0, rint(1234.01));
   ASSERT_EQ(1234.0f, rintf(1234.01f));
-  ASSERT_EQ(1234.0, rintl(1234.01));
+  ASSERT_EQ(1234.0, rintl(1234.01L));
 }
 
 TEST(math, nearbyint) {
@@ -730,29 +820,29 @@
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
 
   feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
-  ASSERT_EQ(1234.0, nearbyintl(1234.0));
+  ASSERT_EQ(1234.0, nearbyintl(1234.0L));
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
-  ASSERT_EQ(1235.0, nearbyintl(1234.01));
+  ASSERT_EQ(1235.0, nearbyintl(1234.01L));
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
 
   fesetround(FE_TOWARDZERO); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
   ASSERT_EQ(1234.0, nearbyint(1234.01));
   ASSERT_EQ(1234.0f, nearbyintf(1234.01f));
-  ASSERT_EQ(1234.0, nearbyintl(1234.01));
+  ASSERT_EQ(1234.0, nearbyintl(1234.01L));
 }
 
 TEST(math, lround) {
   fesetround(FE_UPWARD); // lround ignores the rounding mode.
   ASSERT_EQ(1234, lround(1234.01));
   ASSERT_EQ(1234, lroundf(1234.01f));
-  ASSERT_EQ(1234, lroundl(1234.01));
+  ASSERT_EQ(1234, lroundl(1234.01L));
 }
 
 TEST(math, llround) {
   fesetround(FE_UPWARD); // llround ignores the rounding mode.
   ASSERT_EQ(1234L, llround(1234.01));
   ASSERT_EQ(1234L, llroundf(1234.01f));
-  ASSERT_EQ(1234L, llroundl(1234.01));
+  ASSERT_EQ(1234L, llroundl(1234.01L));
 }
 
 TEST(math, ilogb) {
@@ -772,11 +862,11 @@
 }
 
 TEST(math, ilogbl) {
-  ASSERT_EQ(FP_ILOGB0, ilogbl(0.0));
+  ASSERT_EQ(FP_ILOGB0, ilogbl(0.0L));
   ASSERT_EQ(FP_ILOGBNAN, ilogbl(nanl("")));
   ASSERT_EQ(INT_MAX, ilogbl(HUGE_VALL));
-  ASSERT_EQ(0, ilogbl(1.0));
-  ASSERT_EQ(3, ilogbl(10.0));
+  ASSERT_EQ(0L, ilogbl(1.0L));
+  ASSERT_EQ(3L, ilogbl(10.0L));
 }
 
 TEST(math, logb) {
@@ -796,18 +886,18 @@
 }
 
 TEST(math, logbl) {
-  ASSERT_EQ(-HUGE_VAL, logbl(0.0));
+  ASSERT_EQ(-HUGE_VAL, logbl(0.0L));
   ASSERT_TRUE(isnan(logbl(nanl(""))));
   ASSERT_TRUE(isinf(logbl(HUGE_VALL)));
-  ASSERT_EQ(0.0, logbl(1.0));
-  ASSERT_EQ(3.0, logbl(10.0));
+  ASSERT_EQ(0.0L, logbl(1.0L));
+  ASSERT_EQ(3.0L, logbl(10.0L));
 }
 
 TEST(math, log1p) {
   ASSERT_EQ(-HUGE_VAL, log1p(-1.0));
   ASSERT_TRUE(isnan(log1p(nan(""))));
   ASSERT_TRUE(isinf(log1p(HUGE_VAL)));
-  ASSERT_FLOAT_EQ(1.0, log1p(M_E - 1.0));
+  ASSERT_DOUBLE_EQ(1.0, log1p(M_E - 1.0));
 }
 
 TEST(math, log1pf) {
@@ -818,16 +908,16 @@
 }
 
 TEST(math, log1pl) {
-  ASSERT_EQ(-HUGE_VALL, log1pl(-1.0));
+  ASSERT_EQ(-HUGE_VALL, log1pl(-1.0L));
   ASSERT_TRUE(isnan(log1pl(nanl(""))));
   ASSERT_TRUE(isinf(log1pl(HUGE_VALL)));
-  ASSERT_FLOAT_EQ(1.0, log1pl(M_E - 1.0));
+  ASSERT_DOUBLE_EQ(1.0L, log1pl(M_E - 1.0L));
 }
 
 TEST(math, fdim) {
-  ASSERT_FLOAT_EQ(0.0, fdim(1.0, 1.0));
-  ASSERT_FLOAT_EQ(1.0, fdim(2.0, 1.0));
-  ASSERT_FLOAT_EQ(0.0, fdim(1.0, 2.0));
+  ASSERT_DOUBLE_EQ(0.0, fdim(1.0, 1.0));
+  ASSERT_DOUBLE_EQ(1.0, fdim(2.0, 1.0));
+  ASSERT_DOUBLE_EQ(0.0, fdim(1.0, 2.0));
 }
 
 TEST(math, fdimf) {
@@ -837,19 +927,19 @@
 }
 
 TEST(math, fdiml) {
-  ASSERT_FLOAT_EQ(0.0, fdiml(1.0, 1.0));
-  ASSERT_FLOAT_EQ(1.0, fdiml(2.0, 1.0));
-  ASSERT_FLOAT_EQ(0.0, fdiml(1.0, 2.0));
+  ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(1.0L, fdiml(2.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 2.0L));
 }
 
 TEST(math, round) {
   fesetround(FE_TOWARDZERO); // round ignores the rounding mode and always rounds away from zero.
-  ASSERT_FLOAT_EQ(1.0, round(0.5));
-  ASSERT_FLOAT_EQ(-1.0, round(-0.5));
-  ASSERT_FLOAT_EQ(0.0, round(0.0));
-  ASSERT_FLOAT_EQ(-0.0, round(-0.0));
+  ASSERT_DOUBLE_EQ(1.0, round(0.5));
+  ASSERT_DOUBLE_EQ(-1.0, round(-0.5));
+  ASSERT_DOUBLE_EQ(0.0, round(0.0));
+  ASSERT_DOUBLE_EQ(-0.0, round(-0.0));
   ASSERT_TRUE(isnan(round(nan(""))));
-  ASSERT_FLOAT_EQ(HUGE_VAL, round(HUGE_VAL));
+  ASSERT_DOUBLE_EQ(HUGE_VAL, round(HUGE_VAL));
 }
 
 TEST(math, roundf) {
@@ -864,22 +954,22 @@
 
 TEST(math, roundl) {
   fesetround(FE_TOWARDZERO); // roundl ignores the rounding mode and always rounds away from zero.
-  ASSERT_FLOAT_EQ(1.0, roundl(0.5));
-  ASSERT_FLOAT_EQ(-1.0, roundl(-0.5));
-  ASSERT_FLOAT_EQ(0.0, roundl(0.0));
-  ASSERT_FLOAT_EQ(-0.0, roundl(-0.0));
+  ASSERT_DOUBLE_EQ(1.0L, roundl(0.5L));
+  ASSERT_DOUBLE_EQ(-1.0L, roundl(-0.5L));
+  ASSERT_DOUBLE_EQ(0.0L, roundl(0.0L));
+  ASSERT_DOUBLE_EQ(-0.0L, roundl(-0.0L));
   ASSERT_TRUE(isnan(roundl(nanl(""))));
-  ASSERT_FLOAT_EQ(HUGE_VALL, roundl(HUGE_VALL));
+  ASSERT_DOUBLE_EQ(HUGE_VALL, roundl(HUGE_VALL));
 }
 
 TEST(math, trunc) {
   fesetround(FE_UPWARD); // trunc ignores the rounding mode and always rounds toward zero.
-  ASSERT_FLOAT_EQ(1.0, trunc(1.5));
-  ASSERT_FLOAT_EQ(-1.0, trunc(-1.5));
-  ASSERT_FLOAT_EQ(0.0, trunc(0.0));
-  ASSERT_FLOAT_EQ(-0.0, trunc(-0.0));
+  ASSERT_DOUBLE_EQ(1.0, trunc(1.5));
+  ASSERT_DOUBLE_EQ(-1.0, trunc(-1.5));
+  ASSERT_DOUBLE_EQ(0.0, trunc(0.0));
+  ASSERT_DOUBLE_EQ(-0.0, trunc(-0.0));
   ASSERT_TRUE(isnan(trunc(nan(""))));
-  ASSERT_FLOAT_EQ(HUGE_VAL, trunc(HUGE_VAL));
+  ASSERT_DOUBLE_EQ(HUGE_VAL, trunc(HUGE_VAL));
 }
 
 TEST(math, truncf) {
@@ -894,18 +984,18 @@
 
 TEST(math, truncl) {
   fesetround(FE_UPWARD); // truncl ignores the rounding mode and always rounds toward zero.
-  ASSERT_FLOAT_EQ(1.0, truncl(1.5));
-  ASSERT_FLOAT_EQ(-1.0, truncl(-1.5));
-  ASSERT_FLOAT_EQ(0.0, truncl(0.0));
-  ASSERT_FLOAT_EQ(-0.0, truncl(-0.0));
+  ASSERT_DOUBLE_EQ(1.0L, truncl(1.5L));
+  ASSERT_DOUBLE_EQ(-1.0L, truncl(-1.5L));
+  ASSERT_DOUBLE_EQ(0.0L, truncl(0.0L));
+  ASSERT_DOUBLE_EQ(-0.0L, truncl(-0.0L));
   ASSERT_TRUE(isnan(truncl(nan(""))));
-  ASSERT_FLOAT_EQ(HUGE_VALL, truncl(HUGE_VALL));
+  ASSERT_DOUBLE_EQ(HUGE_VALL, truncl(HUGE_VALL));
 }
 
 TEST(math, nextafter) {
-  ASSERT_FLOAT_EQ(0.0, nextafter(0.0, 0.0));
-  ASSERT_FLOAT_EQ(1.4012985e-45, nextafter(0.0, 1.0));
-  ASSERT_FLOAT_EQ(0.0, nextafter(0.0, -1.0));
+  ASSERT_DOUBLE_EQ(0.0, nextafter(0.0, 0.0));
+  ASSERT_DOUBLE_EQ(4.9406564584124654e-324, nextafter(0.0, 1.0));
+  ASSERT_DOUBLE_EQ(0.0, nextafter(0.0, -1.0));
 }
 
 TEST(math, nextafterf) {
@@ -915,20 +1005,40 @@
 }
 
 TEST(math, nextafterl) {
-  ASSERT_FLOAT_EQ(0.0, nextafterl(0.0, 0.0));
-  ASSERT_FLOAT_EQ(1.4012985e-45, nextafterl(0.0, 1.0));
-  ASSERT_FLOAT_EQ(0.0, nextafterl(0.0, -1.0));
+  ASSERT_DOUBLE_EQ(0.0L, nextafterl(0.0L, 0.0L));
+  // Use a runtime value to accomodate the case when
+  // sizeof(double) == sizeof(long double)
+  long double smallest_positive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG);
+  ASSERT_DOUBLE_EQ(smallest_positive, nextafterl(0.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(0.0L, nextafterl(0.0L, -1.0L));
 }
 
-// TODO: nexttoward
-// TODO: nexttowardf
-// TODO: nexttowardl
+TEST(math, nexttoward) {
+  ASSERT_DOUBLE_EQ(0.0, nexttoward(0.0, 0.0L));
+  ASSERT_DOUBLE_EQ(4.9406564584124654e-324, nexttoward(0.0, 1.0L));
+  ASSERT_DOUBLE_EQ(0.0, nexttoward(0.0, -1.0L));
+}
+
+TEST(math, nexttowardf) {
+  ASSERT_FLOAT_EQ(0.0f, nexttowardf(0.0f, 0.0L));
+  ASSERT_FLOAT_EQ(1.4012985e-45f, nexttowardf(0.0f, 1.0L));
+  ASSERT_FLOAT_EQ(0.0f, nexttowardf(0.0f, -1.0L));
+}
+
+TEST(math, nexttowardl) {
+  ASSERT_DOUBLE_EQ(0.0L, nexttowardl(0.0L, 0.0L));
+  // Use a runtime value to accomodate the case when
+  // sizeof(double) == sizeof(long double)
+  long double smallest_positive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG);
+  ASSERT_DOUBLE_EQ(smallest_positive, nexttowardl(0.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(0.0L, nexttowardl(0.0L, -1.0L));
+}
 
 TEST(math, copysign) {
-  ASSERT_FLOAT_EQ(0.0, copysign(0.0, 1.0));
-  ASSERT_FLOAT_EQ(-0.0, copysign(0.0, -1.0));
-  ASSERT_FLOAT_EQ(2.0, copysign(2.0, 1.0));
-  ASSERT_FLOAT_EQ(-2.0, copysign(2.0, -1.0));
+  ASSERT_DOUBLE_EQ(0.0, copysign(0.0, 1.0));
+  ASSERT_DOUBLE_EQ(-0.0, copysign(0.0, -1.0));
+  ASSERT_DOUBLE_EQ(2.0, copysign(2.0, 1.0));
+  ASSERT_DOUBLE_EQ(-2.0, copysign(2.0, -1.0));
 }
 
 TEST(math, copysignf) {
@@ -939,16 +1049,16 @@
 }
 
 TEST(math, copysignl) {
-  ASSERT_FLOAT_EQ(0.0f, copysignl(0.0, 1.0));
-  ASSERT_FLOAT_EQ(-0.0f, copysignl(0.0, -1.0));
-  ASSERT_FLOAT_EQ(2.0f, copysignl(2.0, 1.0));
-  ASSERT_FLOAT_EQ(-2.0f, copysignl(2.0, -1.0));
+  ASSERT_DOUBLE_EQ(0.0L, copysignl(0.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(-0.0L, copysignl(0.0L, -1.0L));
+  ASSERT_DOUBLE_EQ(2.0L, copysignl(2.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(-2.0L, copysignl(2.0L, -1.0L));
 }
 
 TEST(math, significand) {
-  ASSERT_FLOAT_EQ(0.0, significand(0.0));
-  ASSERT_FLOAT_EQ(1.2, significand(1.2));
-  ASSERT_FLOAT_EQ(1.5375, significand(12.3));
+  ASSERT_DOUBLE_EQ(0.0, significand(0.0));
+  ASSERT_DOUBLE_EQ(1.2, significand(1.2));
+  ASSERT_DOUBLE_EQ(1.5375, significand(12.3));
 }
 
 TEST(math, significandf) {
@@ -957,16 +1067,14 @@
   ASSERT_FLOAT_EQ(1.5375f, significandf(12.3f));
 }
 
-extern "C" long double significandl(long double); // BSD's <math.h> doesn't declare this.
-
 TEST(math, significandl) {
-  ASSERT_FLOAT_EQ(0.0, significandl(0.0));
-  ASSERT_FLOAT_EQ(1.2, significandl(1.2));
-  ASSERT_FLOAT_EQ(1.5375, significandl(12.3));
+  ASSERT_DOUBLE_EQ(0.0L, significandl(0.0L));
+  ASSERT_DOUBLE_EQ(1.2L, significandl(1.2L));
+  ASSERT_DOUBLE_EQ(1.5375L, significandl(12.3L));
 }
 
 TEST(math, scalb) {
-  ASSERT_FLOAT_EQ(12.0, scalb(3.0, 2.0));
+  ASSERT_DOUBLE_EQ(12.0, scalb(3.0, 2.0));
 }
 
 TEST(math, scalbf) {
@@ -974,7 +1082,7 @@
 }
 
 TEST(math, scalbln) {
-  ASSERT_FLOAT_EQ(12.0, scalbln(3.0, 2L));
+  ASSERT_DOUBLE_EQ(12.0, scalbln(3.0, 2L));
 }
 
 TEST(math, scalblnf) {
@@ -982,11 +1090,11 @@
 }
 
 TEST(math, scalblnl) {
-  ASSERT_FLOAT_EQ(12.0, scalblnl(3.0, 2L));
+  ASSERT_DOUBLE_EQ(12.0L, scalblnl(3.0L, 2L));
 }
 
 TEST(math, scalbn) {
-  ASSERT_FLOAT_EQ(12.0, scalbn(3.0, 2));
+  ASSERT_DOUBLE_EQ(12.0, scalbn(3.0, 2));
 }
 
 TEST(math, scalbnf) {
@@ -994,35 +1102,39 @@
 }
 
 TEST(math, scalbnl) {
-  ASSERT_FLOAT_EQ(12.0, scalbnl(3.0, 2));
+  ASSERT_DOUBLE_EQ(12.0L, scalbnl(3.0L, 2));
 }
 
 TEST(math, gamma) {
-  ASSERT_FLOAT_EQ(log(24.0), gamma(5.0));
+  ASSERT_DOUBLE_EQ(log(24.0), gamma(5.0));
 }
 
 TEST(math, gammaf) {
   ASSERT_FLOAT_EQ(logf(24.0f), gammaf(5.0f));
 }
 
-#if defined(__BIONIC__)
 TEST(math, gamma_r) {
-  int sign;
-  ASSERT_FLOAT_EQ(log(24.0), gamma_r(5.0, &sign));
-  ASSERT_EQ(1, sign);
-}
-#endif
-
 #if defined(__BIONIC__)
+  int sign;
+  ASSERT_DOUBLE_EQ(log(24.0), gamma_r(5.0, &sign));
+  ASSERT_EQ(1, sign);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
+}
+
 TEST(math, gammaf_r) {
+#if defined(__BIONIC__)
   int sign;
   ASSERT_FLOAT_EQ(logf(24.0f), gammaf_r(5.0f, &sign));
   ASSERT_EQ(1, sign);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
 TEST(math, lgamma) {
-  ASSERT_FLOAT_EQ(log(24.0), lgamma(5.0));
+  ASSERT_DOUBLE_EQ(log(24.0), lgamma(5.0));
 }
 
 TEST(math, lgammaf) {
@@ -1030,12 +1142,12 @@
 }
 
 TEST(math, lgammal) {
-  ASSERT_FLOAT_EQ(logl(24.0), lgammal(5.0));
+  ASSERT_DOUBLE_EQ(logl(24.0L), lgammal(5.0L));
 }
 
 TEST(math, lgamma_r) {
   int sign;
-  ASSERT_FLOAT_EQ(log(24.0), lgamma_r(5.0, &sign));
+  ASSERT_DOUBLE_EQ(log(24.0), lgamma_r(5.0, &sign));
   ASSERT_EQ(1, sign);
 }
 
@@ -1046,7 +1158,7 @@
 }
 
 TEST(math, tgamma) {
-  ASSERT_FLOAT_EQ(24.0, tgamma(5.0));
+  ASSERT_DOUBLE_EQ(24.0, tgamma(5.0));
 }
 
 TEST(math, tgammaf) {
@@ -1054,12 +1166,12 @@
 }
 
 TEST(math, tgammal) {
-  ASSERT_FLOAT_EQ(24.0, tgammal(5.0));
+  ASSERT_DOUBLE_EQ(24.0L, tgammal(5.0L));
 }
 
 TEST(math, j0) {
-  ASSERT_FLOAT_EQ(1.0, j0(0.0));
-  ASSERT_FLOAT_EQ(0.76519769, j0(1.0));
+  ASSERT_DOUBLE_EQ(1.0, j0(0.0));
+  ASSERT_DOUBLE_EQ(0.76519768655796661, j0(1.0));
 }
 
 TEST(math, j0f) {
@@ -1068,8 +1180,8 @@
 }
 
 TEST(math, j1) {
-  ASSERT_FLOAT_EQ(0.0, j1(0.0));
-  ASSERT_FLOAT_EQ(0.44005057, j1(1.0));
+  ASSERT_DOUBLE_EQ(0.0, j1(0.0));
+  ASSERT_DOUBLE_EQ(0.44005058574493355, j1(1.0));
 }
 
 TEST(math, j1f) {
@@ -1078,8 +1190,8 @@
 }
 
 TEST(math, jn) {
-  ASSERT_FLOAT_EQ(0.0, jn(4, 0.0));
-  ASSERT_FLOAT_EQ(0.0024766389, jn(4, 1.0));
+  ASSERT_DOUBLE_EQ(0.0, jn(4, 0.0));
+  ASSERT_DOUBLE_EQ(0.0024766389641099553, jn(4, 1.0));
 }
 
 TEST(math, jnf) {
@@ -1088,8 +1200,8 @@
 }
 
 TEST(math, y0) {
-  ASSERT_FLOAT_EQ(-HUGE_VAL, y0(0.0));
-  ASSERT_FLOAT_EQ(0.088256963, y0(1.0));
+  ASSERT_DOUBLE_EQ(-HUGE_VAL, y0(0.0));
+  ASSERT_DOUBLE_EQ(0.08825696421567697, y0(1.0));
 }
 
 TEST(math, y0f) {
@@ -1098,8 +1210,8 @@
 }
 
 TEST(math, y1) {
-  ASSERT_FLOAT_EQ(-HUGE_VAL, y1(0.0));
-  ASSERT_FLOAT_EQ(-0.78121281, y1(1.0));
+  ASSERT_DOUBLE_EQ(-HUGE_VAL, y1(0.0));
+  ASSERT_DOUBLE_EQ(-0.78121282130028868, y1(1.0));
 }
 
 TEST(math, y1f) {
@@ -1108,8 +1220,8 @@
 }
 
 TEST(math, yn) {
-  ASSERT_FLOAT_EQ(-HUGE_VAL, yn(4, 0.0));
-  ASSERT_FLOAT_EQ(-33.278423, yn(4, 1.0));
+  ASSERT_DOUBLE_EQ(-HUGE_VAL, yn(4, 0.0));
+  ASSERT_DOUBLE_EQ(-33.278423028972114, yn(4, 1.0));
 }
 
 TEST(math, ynf) {
@@ -1120,7 +1232,7 @@
 TEST(math, frexp) {
   int exp;
   double dr = frexp(1024.0, &exp);
-  ASSERT_FLOAT_EQ(1024.0, scalbn(dr, exp));
+  ASSERT_DOUBLE_EQ(1024.0, scalbn(dr, exp));
 }
 
 TEST(math, frexpf) {
@@ -1131,36 +1243,36 @@
 
 TEST(math, frexpl) {
   int exp;
-  long double ldr = frexpl(1024.0, &exp);
-  ASSERT_FLOAT_EQ(1024.0, scalbnl(ldr, exp));
+  long double ldr = frexpl(1024.0L, &exp);
+  ASSERT_DOUBLE_EQ(1024.0L, scalbnl(ldr, exp));
 }
 
 TEST(math, modf) {
   double di;
-  double df = modf(123.456, &di);
-  ASSERT_FLOAT_EQ(123.0, di);
-  ASSERT_FLOAT_EQ(0.456, df);
+  double df = modf(123.75, &di);
+  ASSERT_DOUBLE_EQ(123.0, di);
+  ASSERT_DOUBLE_EQ(0.75, df);
 }
 
 TEST(math, modff) {
   float fi;
-  float ff = modff(123.456f, &fi);
+  float ff = modff(123.75f, &fi);
   ASSERT_FLOAT_EQ(123.0f, fi);
-  ASSERT_FLOAT_EQ(0.45600128f, ff);
+  ASSERT_FLOAT_EQ(0.75f, ff);
 }
 
 TEST(math, modfl) {
   long double ldi;
-  long double ldf = modfl(123.456, &ldi);
-  ASSERT_FLOAT_EQ(123.0, ldi);
-  ASSERT_FLOAT_EQ(0.456, ldf);
+  long double ldf = modfl(123.75L, &ldi);
+  ASSERT_DOUBLE_EQ(123.0L, ldi);
+  ASSERT_DOUBLE_EQ(0.75L, ldf);
 }
 
 TEST(math, remquo) {
   int q;
   double d = remquo(13.0, 4.0, &q);
   ASSERT_EQ(3, q);
-  ASSERT_FLOAT_EQ(1.0, d);
+  ASSERT_DOUBLE_EQ(1.0, d);
 }
 
 TEST(math, remquof) {
@@ -1172,9 +1284,9 @@
 
 TEST(math, remquol) {
   int q;
-  long double ld = remquol(13.0, 4.0, &q);
-  ASSERT_EQ(3, q);
-  ASSERT_FLOAT_EQ(1.0, ld);
+  long double ld = remquol(13.0L, 4.0L, &q);
+  ASSERT_DOUBLE_EQ(3L, q);
+  ASSERT_DOUBLE_EQ(1.0L, ld);
 }
 
 // https://code.google.com/p/android/issues/detail?id=6697
@@ -1183,3 +1295,18 @@
   float fr = frexpf(14.1f, &exp);
   ASSERT_FLOAT_EQ(14.1f, scalbnf(fr, exp));
 }
+
+TEST(math, exp2_STRICT_ALIGN_OpenBSD_bug) {
+  // OpenBSD/x86's libm had a bug here, but it was already fixed in FreeBSD:
+  // http://svnweb.FreeBSD.org/base/head/lib/msun/src/math_private.h?revision=240827&view=markup
+  ASSERT_DOUBLE_EQ(5.0, exp2(log2(5)));
+  ASSERT_FLOAT_EQ(5.0f, exp2f(log2f(5)));
+  ASSERT_DOUBLE_EQ(5.0L, exp2l(log2l(5)));
+}
+
+TEST(math, nextafterl_OpenBSD_bug) {
+  // OpenBSD/x86's libm had a bug here.
+  ASSERT_TRUE(nextafter(1.0, 0.0) - 1.0 < 0.0);
+  ASSERT_TRUE(nextafterf(1.0f, 0.0f) - 1.0f < 0.0f);
+  ASSERT_TRUE(nextafterl(1.0L, 0.0L) - 1.0L < 0.0L);
+}
diff --git a/tests/mntent_test.cpp b/tests/mntent_test.cpp
new file mode 100644
index 0000000..637cb52
--- /dev/null
+++ b/tests/mntent_test.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <mntent.h>
+
+TEST(mntent, mntent_smoke) {
+  FILE* fp = setmntent("/no/mnt/tab/on/android", "r");
+  ASSERT_TRUE(fp == NULL);
+
+#if __BIONIC__ // glibc doesn't let you call getmntent/getmntent_r with a NULL FILE*.
+  ASSERT_TRUE(getmntent(fp) == NULL);
+
+  struct mntent mbuf;
+  char cbuf[32];
+  ASSERT_TRUE(getmntent_r(fp, &mbuf, cbuf, sizeof(cbuf)) == NULL);
+#endif
+
+  ASSERT_EQ(1, endmntent(fp));
+}
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 33317d9..4a7c6bd 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -19,10 +19,17 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <limits.h>
+#include <malloc.h>
 #include <pthread.h>
+#include <signal.h>
 #include <sys/mman.h>
+#include <sys/syscall.h>
+#include <time.h>
 #include <unistd.h>
 
+#include "private/ScopeGuard.h"
+#include "ScopedSignalHandler.h"
+
 TEST(pthread, pthread_key_create) {
   pthread_key_t key;
   ASSERT_EQ(0, pthread_key_create(&key, NULL));
@@ -31,8 +38,8 @@
   ASSERT_EQ(EINVAL, pthread_key_delete(key));
 }
 
-#if !defined(__GLIBC__) // glibc uses keys internally that its sysconf value doesn't account for.
 TEST(pthread, pthread_key_create_lots) {
+#if defined(__BIONIC__) // glibc uses keys internally that its sysconf value doesn't account for.
   // POSIX says PTHREAD_KEYS_MAX should be at least 128.
   ASSERT_GE(PTHREAD_KEYS_MAX, 128);
 
@@ -59,8 +66,74 @@
   for (size_t i = 0; i < keys.size(); ++i) {
     ASSERT_EQ(0, pthread_key_delete(keys[i]));
   }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
+
+TEST(pthread, pthread_key_delete) {
+  void* expected = reinterpret_cast<void*>(1234);
+  pthread_key_t key;
+  ASSERT_EQ(0, pthread_key_create(&key, NULL));
+  ASSERT_EQ(0, pthread_setspecific(key, expected));
+  ASSERT_EQ(expected, pthread_getspecific(key));
+  ASSERT_EQ(0, pthread_key_delete(key));
+  // After deletion, pthread_getspecific returns NULL.
+  ASSERT_EQ(NULL, pthread_getspecific(key));
+  // And you can't use pthread_setspecific with the deleted key.
+  ASSERT_EQ(EINVAL, pthread_setspecific(key, expected));
+}
+
+TEST(pthread, pthread_key_fork) {
+  void* expected = reinterpret_cast<void*>(1234);
+  pthread_key_t key;
+  ASSERT_EQ(0, pthread_key_create(&key, NULL));
+  ASSERT_EQ(0, pthread_setspecific(key, expected));
+  ASSERT_EQ(expected, pthread_getspecific(key));
+
+  pid_t pid = fork();
+  ASSERT_NE(-1, pid) << strerror(errno);
+
+  if (pid == 0) {
+    // The surviving thread inherits all the forking thread's TLS values...
+    ASSERT_EQ(expected, pthread_getspecific(key));
+    _exit(99);
+  }
+
+  int status;
+  ASSERT_EQ(pid, waitpid(pid, &status, 0));
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(99, WEXITSTATUS(status));
+
+  ASSERT_EQ(expected, pthread_getspecific(key));
+}
+
+static void* DirtyKeyFn(void* key) {
+  return pthread_getspecific(*reinterpret_cast<pthread_key_t*>(key));
+}
+
+TEST(pthread, pthread_key_dirty) {
+  pthread_key_t key;
+  ASSERT_EQ(0, pthread_key_create(&key, NULL));
+
+  size_t stack_size = 128 * 1024;
+  void* stack = mmap(NULL, stack_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  ASSERT_NE(MAP_FAILED, stack);
+  memset(stack, 0xff, stack_size);
+
+  pthread_attr_t attr;
+  ASSERT_EQ(0, pthread_attr_init(&attr));
+  ASSERT_EQ(0, pthread_attr_setstack(&attr, stack, stack_size));
+
+  pthread_t t;
+  ASSERT_EQ(0, pthread_create(&t, &attr, DirtyKeyFn, &key));
+
+  void* result;
+  ASSERT_EQ(0, pthread_join(t, &result));
+  ASSERT_EQ(nullptr, result); // Not ~0!
+
+  ASSERT_EQ(0, munmap(stack, stack_size));
+}
 
 static void* IdFn(void* arg) {
   return arg;
@@ -249,31 +322,24 @@
   ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, NULL));
 }
 
-#if __BIONIC__
-extern "C" pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
-TEST(pthread, __bionic_clone) {
-  // Check that our hand-written clone assembler sets errno correctly on failure.
-  uintptr_t fake_child_stack[16];
-  errno = 0;
-  ASSERT_EQ(-1, __bionic_clone(CLONE_THREAD, &fake_child_stack[16], NULL, NULL, NULL, NULL, NULL));
-  ASSERT_EQ(EINVAL, errno);
-}
-#endif
-
-#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
 TEST(pthread, pthread_setname_np__too_long) {
+#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
   ASSERT_EQ(ERANGE, pthread_setname_np(pthread_self(), "this name is far too long for linux"));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
 TEST(pthread, pthread_setname_np__self) {
+#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
   ASSERT_EQ(0, pthread_setname_np(pthread_self(), "short 1"));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
 TEST(pthread, pthread_setname_np__other) {
+#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
   // Emulator kernels don't currently support setting the name of other threads.
   char* filename = NULL;
   asprintf(&filename, "/proc/self/task/%d/comm", gettid());
@@ -288,18 +354,22 @@
   } else {
     fprintf(stderr, "skipping test: this kernel doesn't have /proc/self/task/tid/comm files!\n");
   }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
 TEST(pthread, pthread_setname_np__no_such_thread) {
+#if defined(__BIONIC__) // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
   pthread_t dead_thread;
   MakeDeadThread(dead_thread);
 
   // Call pthread_setname_np after thread has already exited.
   ASSERT_EQ(ESRCH, pthread_setname_np(dead_thread, "short 3"));
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
 TEST(pthread, pthread_kill__0) {
   // Signal 0 just tests that the thread exists, so it's safe to call on ourselves.
@@ -320,14 +390,8 @@
 }
 
 TEST(pthread, pthread_kill__in_signal_handler) {
-  struct sigaction action;
-  struct sigaction original_action;
-  sigemptyset(&action.sa_mask);
-  action.sa_flags = 0;
-  action.sa_handler = pthread_kill__in_signal_handler_helper;
-  ASSERT_EQ(0, sigaction(SIGALRM, &action, &original_action));
+  ScopedSignalHandler ssh(SIGALRM, pthread_kill__in_signal_handler_helper);
   ASSERT_EQ(0, pthread_kill(pthread_self(), SIGALRM));
-  ASSERT_EQ(0, sigaction(SIGALRM, &original_action, NULL));
 }
 
 TEST(pthread, pthread_detach__no_such_thread) {
@@ -337,6 +401,44 @@
   ASSERT_EQ(ESRCH, pthread_detach(dead_thread));
 }
 
+TEST(pthread, pthread_detach__leak) {
+  size_t initial_bytes = 0;
+  // Run this loop more than once since the first loop causes some memory
+  // to be allocated permenantly. Run an extra loop to help catch any subtle
+  // memory leaks.
+  for (size_t loop = 0; loop < 3; loop++) {
+    // Set the initial bytes on the second loop since the memory in use
+    // should have stabilized.
+    if (loop == 1) {
+      initial_bytes = mallinfo().uordblks;
+    }
+
+    pthread_attr_t attr;
+    ASSERT_EQ(0, pthread_attr_init(&attr));
+    ASSERT_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
+
+    std::vector<pthread_t> threads;
+    for (size_t i = 0; i < 32; ++i) {
+      pthread_t t;
+      ASSERT_EQ(0, pthread_create(&t, &attr, IdFn, NULL));
+      threads.push_back(t);
+    }
+
+    sleep(1);
+
+    for (size_t i = 0; i < 32; ++i) {
+      ASSERT_EQ(0, pthread_detach(threads[i])) << i;
+    }
+  }
+
+  size_t final_bytes = mallinfo().uordblks;
+  int leaked_bytes = (final_bytes - initial_bytes);
+
+  // User code (like this test) doesn't know how large pthread_internal_t is.
+  // We can be pretty sure it's more than 128 bytes.
+  ASSERT_LT(leaked_bytes, 32 /*threads*/ * 128 /*bytes*/);
+}
+
 TEST(pthread, pthread_getcpuclockid__clock_gettime) {
   pthread_t t;
   ASSERT_EQ(0, pthread_create(&t, NULL, SleepFn, reinterpret_cast<void*>(5)));
@@ -511,49 +613,106 @@
   ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, 32*1024 + 1));
   ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size));
   ASSERT_EQ(32*1024U + 1, stack_size);
-#if __BIONIC__
+#if defined(__BIONIC__)
   // Bionic rounds up, which is what POSIX allows.
   ASSERT_EQ(GetActualStackSize(attributes), (32 + 4)*1024U);
-#else
+#else // __BIONIC__
   // glibc rounds down, in violation of POSIX. They document this in their BUGS section.
   ASSERT_EQ(GetActualStackSize(attributes), 32*1024U);
-#endif
+#endif // __BIONIC__
 }
 
 TEST(pthread, pthread_rwlock_smoke) {
   pthread_rwlock_t l;
   ASSERT_EQ(0, pthread_rwlock_init(&l, NULL));
 
+  // Single read lock
   ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
   ASSERT_EQ(0, pthread_rwlock_unlock(&l));
 
+  // Multiple read lock
+  ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
+
+  // Write lock
   ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
   ASSERT_EQ(0, pthread_rwlock_unlock(&l));
 
+  // Try writer lock
+  ASSERT_EQ(0, pthread_rwlock_trywrlock(&l));
+  ASSERT_EQ(EBUSY, pthread_rwlock_trywrlock(&l));
+  ASSERT_EQ(EBUSY, pthread_rwlock_tryrdlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
+
+  // Try reader lock
+  ASSERT_EQ(0, pthread_rwlock_tryrdlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_tryrdlock(&l));
+  ASSERT_EQ(EBUSY, pthread_rwlock_trywrlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
+
+  // Try writer lock after unlock
+  ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
+
+#ifdef __BIONIC__
+  // EDEADLK in "read after write"
+  ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
+  ASSERT_EQ(EDEADLK, pthread_rwlock_rdlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
+
+  // EDEADLK in "write after write"
+  ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
+  ASSERT_EQ(EDEADLK, pthread_rwlock_wrlock(&l));
+  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
+#endif
+
   ASSERT_EQ(0, pthread_rwlock_destroy(&l));
 }
 
-static int gOnceFnCallCount = 0;
+static int g_once_fn_call_count = 0;
 static void OnceFn() {
-  ++gOnceFnCallCount;
+  ++g_once_fn_call_count;
 }
 
 TEST(pthread, pthread_once_smoke) {
   pthread_once_t once_control = PTHREAD_ONCE_INIT;
   ASSERT_EQ(0, pthread_once(&once_control, OnceFn));
   ASSERT_EQ(0, pthread_once(&once_control, OnceFn));
-  ASSERT_EQ(1, gOnceFnCallCount);
+  ASSERT_EQ(1, g_once_fn_call_count);
 }
 
-static int gAtForkPrepareCalls = 0;
-static void AtForkPrepare1() { gAtForkPrepareCalls = (gAtForkPrepareCalls << 4) | 1; }
-static void AtForkPrepare2() { gAtForkPrepareCalls = (gAtForkPrepareCalls << 4) | 2; }
-static int gAtForkParentCalls = 0;
-static void AtForkParent1() { gAtForkParentCalls = (gAtForkParentCalls << 4) | 1; }
-static void AtForkParent2() { gAtForkParentCalls = (gAtForkParentCalls << 4) | 2; }
-static int gAtForkChildCalls = 0;
-static void AtForkChild1() { gAtForkChildCalls = (gAtForkChildCalls << 4) | 1; }
-static void AtForkChild2() { gAtForkChildCalls = (gAtForkChildCalls << 4) | 2; }
+static std::string pthread_once_1934122_result = "";
+
+static void Routine2() {
+  pthread_once_1934122_result += "2";
+}
+
+static void Routine1() {
+  pthread_once_t once_control_2 = PTHREAD_ONCE_INIT;
+  pthread_once_1934122_result += "1";
+  pthread_once(&once_control_2, &Routine2);
+}
+
+TEST(pthread, pthread_once_1934122) {
+  // Very old versions of Android couldn't call pthread_once from a
+  // pthread_once init routine. http://b/1934122.
+  pthread_once_t once_control_1 = PTHREAD_ONCE_INIT;
+  ASSERT_EQ(0, pthread_once(&once_control_1, &Routine1));
+  ASSERT_EQ("12", pthread_once_1934122_result);
+}
+
+static int g_atfork_prepare_calls = 0;
+static void AtForkPrepare1() { g_atfork_prepare_calls = (g_atfork_prepare_calls << 4) | 1; }
+static void AtForkPrepare2() { g_atfork_prepare_calls = (g_atfork_prepare_calls << 4) | 2; }
+static int g_atfork_parent_calls = 0;
+static void AtForkParent1() { g_atfork_parent_calls = (g_atfork_parent_calls << 4) | 1; }
+static void AtForkParent2() { g_atfork_parent_calls = (g_atfork_parent_calls << 4) | 2; }
+static int g_atfork_child_calls = 0;
+static void AtForkChild1() { g_atfork_child_calls = (g_atfork_child_calls << 4) | 1; }
+static void AtForkChild2() { g_atfork_child_calls = (g_atfork_child_calls << 4) | 2; }
 
 TEST(pthread, pthread_atfork) {
   ASSERT_EQ(0, pthread_atfork(AtForkPrepare1, AtForkParent1, AtForkChild1));
@@ -564,13 +723,13 @@
 
   // Child and parent calls are made in the order they were registered.
   if (pid == 0) {
-    ASSERT_EQ(0x12, gAtForkChildCalls);
+    ASSERT_EQ(0x12, g_atfork_child_calls);
     _exit(0);
   }
-  ASSERT_EQ(0x12, gAtForkParentCalls);
+  ASSERT_EQ(0x12, g_atfork_parent_calls);
 
   // Prepare calls are made in the reverse order.
-  ASSERT_EQ(0x21, gAtForkPrepareCalls);
+  ASSERT_EQ(0x21, g_atfork_prepare_calls);
 }
 
 TEST(pthread, pthread_attr_getscope) {
@@ -581,3 +740,170 @@
   ASSERT_EQ(0, pthread_attr_getscope(&attr, &scope));
   ASSERT_EQ(PTHREAD_SCOPE_SYSTEM, scope);
 }
+
+TEST(pthread, pthread_condattr_init) {
+  pthread_condattr_t attr;
+  pthread_condattr_init(&attr);
+
+  clockid_t clock;
+  ASSERT_EQ(0, pthread_condattr_getclock(&attr, &clock));
+  ASSERT_EQ(CLOCK_REALTIME, clock);
+
+  int pshared;
+  ASSERT_EQ(0, pthread_condattr_getpshared(&attr, &pshared));
+  ASSERT_EQ(PTHREAD_PROCESS_PRIVATE, pshared);
+}
+
+TEST(pthread, pthread_condattr_setclock) {
+  pthread_condattr_t attr;
+  pthread_condattr_init(&attr);
+
+  ASSERT_EQ(0, pthread_condattr_setclock(&attr, CLOCK_REALTIME));
+  clockid_t clock;
+  ASSERT_EQ(0, pthread_condattr_getclock(&attr, &clock));
+  ASSERT_EQ(CLOCK_REALTIME, clock);
+
+  ASSERT_EQ(0, pthread_condattr_setclock(&attr, CLOCK_MONOTONIC));
+  ASSERT_EQ(0, pthread_condattr_getclock(&attr, &clock));
+  ASSERT_EQ(CLOCK_MONOTONIC, clock);
+
+  ASSERT_EQ(EINVAL, pthread_condattr_setclock(&attr, CLOCK_PROCESS_CPUTIME_ID));
+}
+
+TEST(pthread, pthread_cond_broadcast__preserves_condattr_flags) {
+#if defined(__BIONIC__) // This tests a bionic implementation detail.
+  pthread_condattr_t attr;
+  pthread_condattr_init(&attr);
+
+  ASSERT_EQ(0, pthread_condattr_setclock(&attr, CLOCK_MONOTONIC));
+  ASSERT_EQ(0, pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED));
+
+  pthread_cond_t cond_var;
+  ASSERT_EQ(0, pthread_cond_init(&cond_var, &attr));
+
+  ASSERT_EQ(0, pthread_cond_signal(&cond_var));
+  ASSERT_EQ(0, pthread_cond_broadcast(&cond_var));
+
+  attr = static_cast<pthread_condattr_t>(cond_var.value);
+  clockid_t clock;
+  ASSERT_EQ(0, pthread_condattr_getclock(&attr, &clock));
+  ASSERT_EQ(CLOCK_MONOTONIC, clock);
+  int pshared;
+  ASSERT_EQ(0, pthread_condattr_getpshared(&attr, &pshared));
+  ASSERT_EQ(PTHREAD_PROCESS_SHARED, pshared);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
+}
+
+TEST(pthread, pthread_mutex_timedlock) {
+  pthread_mutex_t m;
+  ASSERT_EQ(0, pthread_mutex_init(&m, NULL));
+
+  // If the mutex is already locked, pthread_mutex_timedlock should time out.
+  ASSERT_EQ(0, pthread_mutex_lock(&m));
+
+  timespec ts;
+  ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &ts));
+  ts.tv_nsec += 1;
+  ASSERT_EQ(ETIMEDOUT, pthread_mutex_timedlock(&m, &ts));
+
+  // If the mutex is unlocked, pthread_mutex_timedlock should succeed.
+  ASSERT_EQ(0, pthread_mutex_unlock(&m));
+
+  ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &ts));
+  ts.tv_nsec += 1;
+  ASSERT_EQ(0, pthread_mutex_timedlock(&m, &ts));
+
+  ASSERT_EQ(0, pthread_mutex_unlock(&m));
+  ASSERT_EQ(0, pthread_mutex_destroy(&m));
+}
+
+TEST(pthread, pthread_attr_getstack__main_thread) {
+  // This test is only meaningful for the main thread, so make sure we're running on it!
+  ASSERT_EQ(getpid(), syscall(__NR_gettid));
+
+  // Get the main thread's attributes.
+  pthread_attr_t attributes;
+  ASSERT_EQ(0, pthread_getattr_np(pthread_self(), &attributes));
+
+  // Check that we correctly report that the main thread has no guard page.
+  size_t guard_size;
+  ASSERT_EQ(0, pthread_attr_getguardsize(&attributes, &guard_size));
+  ASSERT_EQ(0U, guard_size); // The main thread has no guard page.
+
+  // Get the stack base and the stack size (both ways).
+  void* stack_base;
+  size_t stack_size;
+  ASSERT_EQ(0, pthread_attr_getstack(&attributes, &stack_base, &stack_size));
+  size_t stack_size2;
+  ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size2));
+
+  // The two methods of asking for the stack size should agree.
+  EXPECT_EQ(stack_size, stack_size2);
+
+  // What does /proc/self/maps' [stack] line say?
+  void* maps_stack_hi = NULL;
+  FILE* fp = fopen("/proc/self/maps", "r");
+  ASSERT_TRUE(fp != NULL);
+  char line[BUFSIZ];
+  while (fgets(line, sizeof(line), fp) != NULL) {
+    uintptr_t lo, hi;
+    char name[10];
+    sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %*4s %*x %*x:%*x %*d %10s", &lo, &hi, name);
+    if (strcmp(name, "[stack]") == 0) {
+      maps_stack_hi = reinterpret_cast<void*>(hi);
+      break;
+    }
+  }
+  fclose(fp);
+
+  // The stack size should correspond to RLIMIT_STACK.
+  rlimit rl;
+  ASSERT_EQ(0, getrlimit(RLIMIT_STACK, &rl));
+  uint64_t original_rlim_cur = rl.rlim_cur;
+#if defined(__BIONIC__)
+  if (rl.rlim_cur == RLIM_INFINITY) {
+    rl.rlim_cur = 8 * 1024 * 1024; // Bionic reports unlimited stacks as 8MiB.
+  }
+#endif
+  EXPECT_EQ(rl.rlim_cur, stack_size);
+
+  auto guard = create_scope_guard([&rl, original_rlim_cur]() {
+    rl.rlim_cur = original_rlim_cur;
+    ASSERT_EQ(0, setrlimit(RLIMIT_STACK, &rl));
+  });
+
+  // The high address of the /proc/self/maps [stack] region should equal stack_base + stack_size.
+  // Remember that the stack grows down (and is mapped in on demand), so the low address of the
+  // region isn't very interesting.
+  EXPECT_EQ(maps_stack_hi, reinterpret_cast<uint8_t*>(stack_base) + stack_size);
+
+  //
+  // What if RLIMIT_STACK is smaller than the stack's current extent?
+  //
+  rl.rlim_cur = rl.rlim_max = 1024; // 1KiB. We know the stack must be at least a page already.
+  rl.rlim_max = RLIM_INFINITY;
+  ASSERT_EQ(0, setrlimit(RLIMIT_STACK, &rl));
+
+  ASSERT_EQ(0, pthread_getattr_np(pthread_self(), &attributes));
+  ASSERT_EQ(0, pthread_attr_getstack(&attributes, &stack_base, &stack_size));
+  ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size2));
+
+  EXPECT_EQ(stack_size, stack_size2);
+  ASSERT_EQ(1024U, stack_size);
+
+  //
+  // What if RLIMIT_STACK isn't a whole number of pages?
+  //
+  rl.rlim_cur = rl.rlim_max = 6666; // Not a whole number of pages.
+  rl.rlim_max = RLIM_INFINITY;
+  ASSERT_EQ(0, setrlimit(RLIMIT_STACK, &rl));
+
+  ASSERT_EQ(0, pthread_getattr_np(pthread_self(), &attributes));
+  ASSERT_EQ(0, pthread_attr_getstack(&attributes, &stack_base, &stack_size));
+  ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size2));
+
+  EXPECT_EQ(stack_size, stack_size2);
+  ASSERT_EQ(6666U, stack_size);
+}
diff --git a/tests/regex_test.cpp b/tests/regex_test.cpp
index 659d1db..d026221 100644
--- a/tests/regex_test.cpp
+++ b/tests/regex_test.cpp
@@ -28,7 +28,7 @@
 
   char buf[80];
   regerror(REG_NOMATCH, &re, buf, sizeof(buf));
-#if __BIONIC__
+#if defined(__BIONIC__)
   ASSERT_STREQ("regexec() failed to match", buf);
 #else
   ASSERT_STREQ("No match", buf);
diff --git a/tests/sched_test.cpp b/tests/sched_test.cpp
index 49f1642..caf4c65 100644
--- a/tests/sched_test.cpp
+++ b/tests/sched_test.cpp
@@ -21,7 +21,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#ifdef __BIONIC__
+#if defined(__BIONIC__)
 static int child_fn(void* i_ptr) {
   *reinterpret_cast<int*>(i_ptr) = 42;
   return 123;
@@ -50,3 +50,215 @@
   GTEST_LOG_(INFO) << "This test does nothing.\n";
 }
 #endif
+
+TEST(sched, clone_errno) {
+  // Check that our hand-written clone assembler sets errno correctly on failure.
+  uintptr_t fake_child_stack[16];
+  errno = 0;
+  ASSERT_EQ(-1, clone(NULL, &fake_child_stack[16], CLONE_THREAD, NULL));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(sched, cpu_set) {
+  cpu_set_t set;
+
+  CPU_ZERO(&set);
+  CPU_SET(0, &set);
+  CPU_SET(17, &set);
+  for (int i = 0; i < CPU_SETSIZE; i++) {
+    ASSERT_EQ(i == 0 || i == 17, CPU_ISSET(i, &set));
+  }
+
+  // We should fail silently if we try to set/test outside the range.
+  CPU_SET(CPU_SETSIZE, &set);
+  ASSERT_FALSE(CPU_ISSET(CPU_SETSIZE, &set));
+}
+
+TEST(sched, cpu_count) {
+  cpu_set_t set;
+
+  CPU_ZERO(&set);
+  ASSERT_EQ(0, CPU_COUNT(&set));
+  CPU_SET(2, &set);
+  CPU_SET(10, &set);
+  ASSERT_EQ(2, CPU_COUNT(&set));
+  CPU_CLR(10, &set);
+  ASSERT_EQ(1, CPU_COUNT(&set));
+}
+
+TEST(sched, cpu_zero) {
+  cpu_set_t set;
+
+  CPU_ZERO(&set);
+  ASSERT_EQ(0, CPU_COUNT(&set));
+  for (int i = 0; i < CPU_SETSIZE; i++) {
+    ASSERT_FALSE(CPU_ISSET(i, &set));
+  }
+}
+
+TEST(sched, cpu_clr) {
+  cpu_set_t set;
+
+  CPU_ZERO(&set);
+  CPU_SET(0, &set);
+  CPU_SET(1, &set);
+  for (int i = 0; i < CPU_SETSIZE; i++) {
+    ASSERT_EQ(i == 0 || i == 1, CPU_ISSET(i, &set));
+  }
+  CPU_CLR(1, &set);
+  for (int i = 0; i < CPU_SETSIZE; i++) {
+    ASSERT_EQ(i == 0, CPU_ISSET(i, &set));
+  }
+
+  // We should fail silently if we try to clear/test outside the range.
+  CPU_CLR(CPU_SETSIZE, &set);
+  ASSERT_FALSE(CPU_ISSET(CPU_SETSIZE, &set));
+}
+
+TEST(sched, cpu_equal) {
+  cpu_set_t set1;
+  cpu_set_t set2;
+
+  CPU_ZERO(&set1);
+  CPU_ZERO(&set2);
+  CPU_SET(1, &set1);
+  ASSERT_FALSE(CPU_EQUAL(&set1, &set2));
+  CPU_SET(1, &set2);
+  ASSERT_TRUE(CPU_EQUAL(&set1, &set2));
+}
+
+TEST(sched, cpu_op) {
+  cpu_set_t set1;
+  cpu_set_t set2;
+  cpu_set_t set3;
+
+  CPU_ZERO(&set1);
+  CPU_ZERO(&set2);
+  CPU_ZERO(&set3);
+  CPU_SET(0, &set1);
+  CPU_SET(0, &set2);
+  CPU_SET(1, &set2);
+
+  CPU_AND(&set3, &set1, &set2);
+  for (int i = 0; i < CPU_SETSIZE; i++) {
+    ASSERT_EQ(i == 0, CPU_ISSET(i, &set3));
+  }
+
+  CPU_XOR(&set3, &set1, &set2);
+  for (int i = 0; i < CPU_SETSIZE; i++) {
+    ASSERT_EQ(i == 1, CPU_ISSET(i, &set3));
+  }
+
+  CPU_OR(&set3, &set1, &set2);
+  for (int i = 0; i < CPU_SETSIZE; i++) {
+    ASSERT_EQ(i == 0 || i == 1, CPU_ISSET(i, &set3));
+  }
+}
+
+
+TEST(sched, cpu_alloc_small) {
+  cpu_set_t* set = CPU_ALLOC(17);
+  size_t size = CPU_ALLOC_SIZE(17);
+
+  CPU_ZERO_S(size, set);
+  ASSERT_EQ(0, CPU_COUNT_S(size, set));
+  CPU_SET_S(16, size, set);
+  ASSERT_TRUE(CPU_ISSET_S(16, size, set));
+
+  CPU_FREE(set);
+}
+
+TEST(sched, cpu_alloc_big) {
+  cpu_set_t* set = CPU_ALLOC(10 * CPU_SETSIZE);
+  size_t size = CPU_ALLOC_SIZE(10 * CPU_SETSIZE);
+
+  CPU_ZERO_S(size, set);
+  ASSERT_EQ(0, CPU_COUNT_S(size, set));
+  CPU_SET_S(CPU_SETSIZE, size, set);
+  ASSERT_TRUE(CPU_ISSET_S(CPU_SETSIZE, size, set));
+
+  CPU_FREE(set);
+}
+
+TEST(sched, cpu_s_macros) {
+  int set_size = 64;
+  size_t size = CPU_ALLOC_SIZE(set_size);
+  cpu_set_t* set = CPU_ALLOC(set_size);
+
+  CPU_ZERO_S(size, set);
+  for (int i = 0; i < set_size; i++) {
+    ASSERT_FALSE(CPU_ISSET_S(i, size, set));
+    CPU_SET_S(i, size, set);
+    ASSERT_TRUE(CPU_ISSET_S(i, size, set));
+    ASSERT_EQ(i + 1, CPU_COUNT_S(size, set));
+  }
+
+  for (int i = 0; i < set_size; i++) {
+    CPU_CLR_S(i, size, set);
+    ASSERT_FALSE(CPU_ISSET_S(i, size, set));
+    ASSERT_EQ(set_size - i - 1, CPU_COUNT_S(size, set));
+  }
+
+  CPU_FREE(set);
+}
+
+TEST(sched, cpu_op_s_macros) {
+  int set_size1 = 64;
+  int set_size2 = set_size1 * 2;
+  int set_size3 = set_size1 * 3;
+  size_t size1 = CPU_ALLOC_SIZE(set_size1);
+  size_t size2 = CPU_ALLOC_SIZE(set_size2);
+  size_t size3 = CPU_ALLOC_SIZE(set_size3);
+
+  cpu_set_t* set1 = CPU_ALLOC(set_size1);
+  cpu_set_t* set2 = CPU_ALLOC(set_size2);
+  cpu_set_t* set3 = CPU_ALLOC(set_size3);
+  CPU_ZERO_S(size1, set1);
+  CPU_ZERO_S(size2, set2);
+  CPU_ZERO_S(size3, set3);
+
+  CPU_SET_S(0, size1, set1);
+  CPU_SET_S(0, size2, set2);
+  CPU_SET_S(1, size3, set2);
+
+  CPU_AND_S(size1, set3, set1, set2);
+  for (int i = 0; i < set_size3; i++) {
+    ASSERT_EQ(i == 0, CPU_ISSET_S(i, size3, set3));
+  }
+
+  CPU_OR_S(size1, set3, set1, set2);
+  for (int i = 0; i < set_size3; i++) {
+    ASSERT_EQ(i == 0 || i == 1, CPU_ISSET_S(i, size3, set3));
+  }
+
+  CPU_XOR_S(size1, set3, set1, set2);
+  for (int i = 0; i < set_size3; i++) {
+    ASSERT_EQ(i == 1, CPU_ISSET_S(i, size3, set3));
+  }
+
+  CPU_FREE(set1);
+  CPU_FREE(set2);
+  CPU_FREE(set3);
+}
+
+TEST(sched, cpu_equal_s) {
+  int set_size1 = 64;
+  int set_size2 = set_size1 * 2;
+  size_t size1 = CPU_ALLOC_SIZE(set_size1);
+  size_t size2 = CPU_ALLOC_SIZE(set_size2);
+
+  cpu_set_t* set1 = CPU_ALLOC(set_size1);
+  cpu_set_t* set2 = CPU_ALLOC(set_size2);
+
+  CPU_ZERO_S(size1, set1);
+  CPU_ZERO_S(size2, set2);
+
+  CPU_SET_S(0, size1, set1);
+  ASSERT_TRUE(CPU_EQUAL_S(size1, set1, set1));
+  ASSERT_FALSE(CPU_EQUAL_S(size1, set1, set2));
+  CPU_SET_S(0, size2, set2);
+  ASSERT_TRUE(CPU_EQUAL_S(size1, set1, set2));
+
+  CPU_FREE(set1);
+  CPU_FREE(set2);
+}
diff --git a/tests/search_test.cpp b/tests/search_test.cpp
new file mode 100644
index 0000000..3900c89
--- /dev/null
+++ b/tests/search_test.cpp
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <search.h>
+
+static int int_cmp(const void* lhs, const void* rhs) {
+  return *reinterpret_cast<const int*>(rhs) - *reinterpret_cast<const int*>(lhs);
+}
+
+TEST(search, lfind_lsearch) {
+  int xs[10];
+  memset(xs, 0, sizeof(xs));
+  size_t x_size = 0;
+
+  int needle;
+
+  // lfind(3) can't find '2' in the empty table.
+  needle = 2;
+  ASSERT_EQ(nullptr, lfind(&needle, xs, &x_size, sizeof(xs[0]), int_cmp));
+  ASSERT_EQ(0U, x_size);
+
+  // lsearch(3) will add it.
+  ASSERT_EQ(&xs[0], lsearch(&needle, xs, &x_size, sizeof(xs[0]), int_cmp));
+  ASSERT_EQ(2, xs[0]);
+  ASSERT_EQ(1U, x_size);
+
+  // And then lfind(3) can find it.
+  ASSERT_EQ(&xs[0], lfind(&needle, xs, &x_size, sizeof(xs[0]), int_cmp));
+  ASSERT_EQ(1U, x_size);
+
+  // Inserting a duplicate does nothing (but returns the existing element).
+  ASSERT_EQ(&xs[0], lsearch(&needle, xs, &x_size, sizeof(xs[0]), int_cmp));
+  ASSERT_EQ(1U, x_size);
+}
+
+struct node {
+  node(const char* s) : s(strdup(s)) {}
+
+  char* s;
+};
+
+static int node_cmp(const void* lhs, const void* rhs) {
+  return strcmp(reinterpret_cast<const node*>(lhs)->s, reinterpret_cast<const node*>(rhs)->s);
+}
+
+static std::vector<std::string> g_nodes;
+
+static void node_walk(const void* p, VISIT order, int) {
+  const node* n = *reinterpret_cast<const node* const*>(p);
+  if (order == postorder || order == leaf)  {
+    g_nodes.push_back(n->s);
+  }
+}
+
+static size_t g_free_calls;
+
+static void node_free(void* p) {
+  node* n = reinterpret_cast<node*>(p);
+  free(n->s);
+  ++g_free_calls;
+}
+
+TEST(search, tfind_tsearch_twalk_tdestroy) {
+  void* root = nullptr;
+
+  node n1("z");
+  node n2("a");
+  node n3("m");
+
+  // tfind(3) can't find anything in the empty tree.
+  ASSERT_EQ(nullptr, tfind(&n1, &root, node_cmp));
+  ASSERT_EQ(nullptr, tfind(&n2, &root, node_cmp));
+  ASSERT_EQ(nullptr, tfind(&n3, &root, node_cmp));
+
+  // tsearch(3) inserts and returns a pointer to a new node.
+  void* i1 = tsearch(&n1, &root, node_cmp);
+  ASSERT_NE(nullptr, i1);
+
+  // ...which tfind(3) will then return.
+  ASSERT_EQ(i1, tfind(&n1, &root, node_cmp));
+  ASSERT_EQ(nullptr, tfind(&n2, &root, node_cmp));
+  ASSERT_EQ(nullptr, tfind(&n3, &root, node_cmp));
+
+  // Add the other nodes.
+  ASSERT_NE(nullptr, tsearch(&n2, &root, node_cmp));
+  ASSERT_NE(nullptr, tsearch(&n3, &root, node_cmp));
+
+  // Use twalk(3) to iterate over the nodes.
+  g_nodes.clear();
+  twalk(root, node_walk);
+  ASSERT_EQ(3U, g_nodes.size());
+  ASSERT_EQ("a", g_nodes[0]);
+  ASSERT_EQ("m", g_nodes[1]);
+  ASSERT_EQ("z", g_nodes[2]);
+
+  // tdestroy(3) removes nodes under a node, calling our callback to destroy each one.
+  g_free_calls = 0;
+  tdestroy(root, node_free);
+  ASSERT_EQ(3U, g_free_calls);
+}
+
+struct pod_node {
+  pod_node(int i) : i(i) {}
+  int i;
+};
+
+static int pod_node_cmp(const void* lhs, const void* rhs) {
+  return reinterpret_cast<const pod_node*>(rhs)->i - reinterpret_cast<const pod_node*>(lhs)->i;
+}
+
+TEST(search, tdelete) {
+  void* root = nullptr;
+
+  pod_node n1(123);
+  ASSERT_NE(nullptr, tsearch(&n1, &root, pod_node_cmp));
+
+  // tdelete(3) leaks n1.
+  pod_node not_there(456);
+  ASSERT_EQ(nullptr, tdelete(&not_there, &root, pod_node_cmp));
+  ASSERT_NE(nullptr, tdelete(&n1, &root, pod_node_cmp));
+}
+
+struct q_node {
+  q_node(int i) : i(i) {}
+
+  q_node* next;
+  q_node* prev;
+
+  int i;
+};
+
+TEST(search, insque_remque) {
+  q_node zero(0);
+  q_node one(1);
+  q_node two(2);
+
+  // Linear (not circular).
+
+  insque(&zero, NULL);
+  insque(&one, &zero);
+  insque(&two, &one);
+
+  int expected = 0;
+  for (q_node* q = &zero; q != NULL; q = q->next) {
+    ASSERT_EQ(expected, q->i);
+    ++expected;
+  }
+  ASSERT_EQ(3, expected);
+
+  for (q_node* q = &two; q != NULL; q = q->prev) {
+    --expected;
+    ASSERT_EQ(expected, q->i);
+  }
+  ASSERT_EQ(0, expected);
+
+  q_node* head = &zero;
+
+  remque(&one);
+  ASSERT_EQ(0, head->i);
+  ASSERT_EQ(2, head->next->i);
+  ASSERT_EQ(nullptr, head->next->next);
+
+  remque(&two);
+  ASSERT_EQ(0, head->i);
+  ASSERT_EQ(nullptr, head->next);
+
+  remque(&zero);
+
+  // Circular.
+
+  zero.next = &zero;
+  zero.prev = &zero;
+
+  insque(&one, &zero);
+  insque(&two, &one);
+
+  ASSERT_EQ(0, head->i);
+  ASSERT_EQ(1, head->next->i);
+  ASSERT_EQ(2, head->next->next->i);
+  ASSERT_EQ(0, head->next->next->next->i);
+  ASSERT_EQ(1, head->next->next->next->next->i);
+  ASSERT_EQ(2, head->next->next->next->next->next->i);
+
+  remque(&one);
+  ASSERT_EQ(0, head->i);
+  ASSERT_EQ(2, head->next->i);
+  ASSERT_EQ(0, head->next->next->i);
+  ASSERT_EQ(2, head->next->next->next->i);
+
+  remque(&two);
+  ASSERT_EQ(0, head->i);
+  ASSERT_EQ(0, head->next->i);
+
+  remque(&zero);
+}
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index a7e5b9a..89b8088 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -146,10 +146,10 @@
   ASSERT_EQ(SIGALRM, received_signal);
 }
 
-static int gSigSuspendTestHelperCallCount = 0;
+static int g_sigsuspend_test_helper_call_count = 0;
 
 static void SigSuspendTestHelper(int) {
-  ++gSigSuspendTestHelperCallCount;
+  ++g_sigsuspend_test_helper_call_count;
 }
 
 TEST(signal, sigsuspend_sigpending) {
@@ -172,7 +172,7 @@
 
   // Raise SIGALRM and check our signal handler wasn't called.
   raise(SIGALRM);
-  ASSERT_EQ(0, gSigSuspendTestHelperCallCount);
+  ASSERT_EQ(0, g_sigsuspend_test_helper_call_count);
 
   // We should now have a pending SIGALRM but nothing else.
   sigemptyset(&pending);
@@ -188,7 +188,7 @@
   ASSERT_EQ(-1, sigsuspend(&not_SIGALRM));
   ASSERT_EQ(EINTR, errno);
   // ...and check that we now receive our pending SIGALRM.
-  ASSERT_EQ(1, gSigSuspendTestHelperCallCount);
+  ASSERT_EQ(1, g_sigsuspend_test_helper_call_count);
 
   // Restore the original set.
   ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL));
@@ -238,3 +238,35 @@
   // Put everything back how it was.
   ASSERT_EQ(0, sigaction(SIGALRM, &original_sa, NULL));
 }
+
+TEST(signal, sys_signame) {
+#if defined(__BIONIC__)
+  ASSERT_TRUE(sys_signame[0] == NULL);
+  ASSERT_STREQ("HUP", sys_signame[SIGHUP]);
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
+
+TEST(signal, sys_siglist) {
+  ASSERT_TRUE(sys_siglist[0] == NULL);
+  ASSERT_STREQ("Hangup", sys_siglist[SIGHUP]);
+}
+
+TEST(signal, limits) {
+  // This comes from the kernel.
+  ASSERT_EQ(32, __SIGRTMIN);
+
+  // We reserve a non-zero number at the bottom for ourselves.
+  ASSERT_GT(SIGRTMIN, __SIGRTMIN);
+
+  // MIPS has more signals than everyone else.
+#if defined(__mips__)
+  ASSERT_EQ(128, __SIGRTMAX);
+#else
+  ASSERT_EQ(64, __SIGRTMAX);
+#endif
+
+  // We don't currently reserve any at the top.
+  ASSERT_EQ(SIGRTMAX, __SIGRTMAX);
+}
diff --git a/tests/sstream_test.cpp b/tests/sstream_test.cpp
new file mode 100644
index 0000000..d5f8695
--- /dev/null
+++ b/tests/sstream_test.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <stdint.h>
+#include <limits>
+#include <sstream>
+
+// TODO: move this test to libcxx.
+
+template <typename T>
+static void CheckOverflow(T expected, const char* value, bool should_overflow) {
+  std::stringstream ss(value);
+  T result = T(0);
+  ss >> result;
+  EXPECT_FALSE(ss.bad()) << value << ' ' << int64_t(result);
+  EXPECT_EQ(should_overflow, ss.fail()) << value << ' ' << int64_t(result);
+  if (!should_overflow) { // glibc writes garbage on overflow.
+    ASSERT_EQ(expected, result) << value;
+  }
+}
+
+TEST(sstream, __get_integer_overflow_8) {
+  // The usual byte/char confusion means that operator>> on 8-bit types is used
+  // for chars, so there's no possibility of overflow.
+}
+
+TEST(sstream, __get_integer_overflow_16) {
+  CheckOverflow<int16_t>(std::numeric_limits<int16_t>::min(), "-32768", false);
+  CheckOverflow<int16_t>(0, "-32769", true);
+  CheckOverflow<int16_t>(std::numeric_limits<int16_t>::max(), "32767", false);
+  CheckOverflow<int16_t>(0, "32768", true);
+
+  CheckOverflow<uint16_t>(std::numeric_limits<uint16_t>::max(), "65535", false);
+  CheckOverflow<uint16_t>(0, "65536", true);
+}
+
+TEST(sstream, __get_integer_overflow_32) {
+  CheckOverflow<int32_t>(std::numeric_limits<int32_t>::min(), "-2147483648", false);
+  CheckOverflow<int32_t>(0, "-2147483649", true);
+  CheckOverflow<int32_t>(std::numeric_limits<int32_t>::max(), "2147483647", false);
+  CheckOverflow<int32_t>(0, "2147483648", true);
+
+  CheckOverflow<uint32_t>(std::numeric_limits<uint32_t>::max(), "4294967295", false);
+  CheckOverflow<uint32_t>(0, "4294967296", true);
+}
+
+TEST(sstream, __get_integer_overflow_64) {
+  CheckOverflow<int64_t>(std::numeric_limits<int64_t>::min(), "-9223372036854775808", false);
+  CheckOverflow<int64_t>(0, "-9223372036854775809", true);
+  CheckOverflow<int64_t>(std::numeric_limits<int64_t>::max(), "9223372036854775807", false);
+  CheckOverflow<int64_t>(0, "9223372036854775808", true);
+
+  CheckOverflow<uint64_t>(std::numeric_limits<uint64_t>::max(), "18446744073709551615", false);
+  CheckOverflow<uint64_t>(0, "18446744073709551616", true);
+}
diff --git a/tests/stack_protector_test.cpp b/tests/stack_protector_test.cpp
index 2ba8a87..fea24d8 100644
--- a/tests/stack_protector_test.cpp
+++ b/tests/stack_protector_test.cpp
@@ -27,17 +27,13 @@
 #include <unistd.h>
 #include <set>
 
-#ifdef __GLIBC__
-
+#if defined(__GLIBC__)
 // glibc doesn't expose gettid(2).
 pid_t gettid() { return syscall(__NR_gettid); }
-
-#endif
-
-#ifdef __i386__
+#endif // __GLIBC__
 
 // For x86, bionic and glibc have per-thread stack guard values (all identical).
-
+#if defined(__i386__)
 static uint32_t GetGuardFromTls() {
   uint32_t guard;
   asm ("mov %%gs:0x14, %0": "=d" (guard));
@@ -71,8 +67,10 @@
   checker->Check();
   return NULL;
 }
+#endif // __i386__
 
 TEST(stack_protector, same_guard_per_thread) {
+#if defined(__i386__)
   stack_protector_checker checker;
   size_t thread_count = 10;
   for (size_t i = 0; i < thread_count; ++i) {
@@ -86,24 +84,19 @@
 
   // bionic and glibc use the same guard for every thread.
   ASSERT_EQ(1U, checker.guards.size());
+#else // __i386__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __i386__
 }
 
-#endif
-
-#if defined(__BIONIC__) || defined(__arm__) || defined(__mips__)
-
 // For ARM and MIPS, glibc has a global stack check guard value.
+#if defined(__BIONIC__) || defined(__arm__) || defined(__mips__)
+#define TEST_STACK_CHK_GUARD
 
 // Bionic has the global for x86 too, to support binaries that can run on
 // Android releases that didn't implement the TLS guard value.
-
 extern "C" uintptr_t __stack_chk_guard;
 
-TEST(stack_protector, global_guard) {
-  ASSERT_NE(0, gettid());
-  ASSERT_NE(0U, __stack_chk_guard);
-}
-
 /*
  * When this function returns, the stack canary will be inconsistent
  * with the previous value, which will generate a call to __stack_chk_fail(),
@@ -116,10 +109,22 @@
 static void do_modify_stack_chk_guard() {
   __stack_chk_guard = 0x12345678;
 }
+#endif
 
-TEST(stack_protector_DeathTest, modify_stack_protector) {
-  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
-  ASSERT_EXIT(do_modify_stack_chk_guard(), testing::KilledBySignal(SIGABRT), "");
+TEST(stack_protector, global_guard) {
+#if defined(TEST_STACK_CHK_GUARD)
+  ASSERT_NE(0, gettid());
+  ASSERT_NE(0U, __stack_chk_guard);
+#else // TEST_STACK_CHK_GUARD
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // TEST_STACK_CHK_GUARD
 }
 
-#endif
+TEST(stack_protector_DeathTest, modify_stack_protector) {
+#if defined(TEST_STACK_CHK_GUARD)
+  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+  ASSERT_EXIT(do_modify_stack_chk_guard(), testing::KilledBySignal(SIGABRT), "");
+#else // TEST_STACK_CHK_GUARD
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // TEST_STACK_CHK_GUARD
+}
diff --git a/tests/stack_unwinding_test.cpp b/tests/stack_unwinding_test.cpp
index 3b18daa..1024f28 100644
--- a/tests/stack_unwinding_test.cpp
+++ b/tests/stack_unwinding_test.cpp
@@ -20,8 +20,6 @@
 
 #include <gtest/gtest.h>
 
-#if defined(i386) // Only our x86 unwinding is good enough. Switch to libunwind?
-
 extern "C" {
   void do_test();
 }
@@ -29,8 +27,11 @@
 // We have to say "DeathTest" here so gtest knows to run this test (which exits)
 // in its own process.
 TEST(stack_unwinding_DeathTest, unwinding_through_signal_frame) {
+// Only our x86 unwinding is good enough. Switch to libunwind?
+#if defined(__BIONIC__) && defined(__i386__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(do_test(), ::testing::ExitedWithCode(42), "");
+#else // __i386__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __i386__
 }
-
-#endif
diff --git a/tests/statvfs_test.cpp b/tests/statvfs_test.cpp
deleted file mode 100644
index 1afb9c6..0000000
--- a/tests/statvfs_test.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gtest/gtest.h>
-
-#include <sys/statvfs.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include <string>
-
-TEST(statvfs, statvfs) {
-  struct statvfs sb;
-  memset(&sb, 0, sizeof(sb));
-
-  ASSERT_EQ(0, statvfs("/proc", &sb));
-
-  EXPECT_EQ(4096U, sb.f_bsize);
-  EXPECT_EQ(0U, sb.f_bfree);
-  EXPECT_EQ(0U, sb.f_ffree);
-  EXPECT_EQ(0U, sb.f_fsid);
-  EXPECT_EQ(255U, sb.f_namemax);
-}
-
-TEST(statvfs, fstatvfs) {
-  struct statvfs sb;
-  memset(&sb, 0, sizeof(sb));
-
-  int fd = open("/proc", O_RDONLY);
-  ASSERT_EQ(0, fstatvfs(fd, &sb));
-  close(fd);
-
-  EXPECT_EQ(4096U, sb.f_bsize);
-  EXPECT_EQ(0U, sb.f_bfree);
-  EXPECT_EQ(0U, sb.f_ffree);
-  EXPECT_EQ(0U, sb.f_fsid);
-  EXPECT_EQ(255U, sb.f_namemax);
-}
diff --git a/tests/stdatomic_test.cpp b/tests/stdatomic_test.cpp
new file mode 100644
index 0000000..b7fb19b
--- /dev/null
+++ b/tests/stdatomic_test.cpp
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdatomic.h>
+#include <gtest/gtest.h>
+#include <pthread.h>
+#include <stdint.h>
+
+TEST(stdatomic, LOCK_FREE) {
+  ASSERT_TRUE(ATOMIC_BOOL_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_CHAR16_T_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_CHAR32_T_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_CHAR_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_INT_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_LLONG_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_LONG_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_POINTER_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_SHORT_LOCK_FREE);
+  ASSERT_TRUE(ATOMIC_WCHAR_T_LOCK_FREE);
+}
+
+TEST(stdatomic, init) {
+  atomic_int v = ATOMIC_VAR_INIT(123);
+  ASSERT_EQ(123, atomic_load(&v));
+
+  atomic_init(&v, 456);
+  ASSERT_EQ(456, atomic_load(&v));
+
+  atomic_flag f = ATOMIC_FLAG_INIT;
+  ASSERT_FALSE(atomic_flag_test_and_set(&f));
+}
+
+TEST(stdatomic, atomic_thread_fence) {
+  atomic_thread_fence(memory_order_relaxed);
+  atomic_thread_fence(memory_order_consume);
+  atomic_thread_fence(memory_order_acquire);
+  atomic_thread_fence(memory_order_release);
+  atomic_thread_fence(memory_order_acq_rel);
+  atomic_thread_fence(memory_order_seq_cst);
+}
+
+TEST(stdatomic, atomic_signal_fence) {
+  atomic_signal_fence(memory_order_relaxed);
+  atomic_signal_fence(memory_order_consume);
+  atomic_signal_fence(memory_order_acquire);
+  atomic_signal_fence(memory_order_release);
+  atomic_signal_fence(memory_order_acq_rel);
+  atomic_signal_fence(memory_order_seq_cst);
+}
+
+TEST(stdatomic, atomic_is_lock_free) {
+  atomic_char small;
+  ASSERT_TRUE(atomic_is_lock_free(&small));
+#if defined(__clang__) || __GNUC_PREREQ(4, 7)
+  // Otherwise stdatomic.h doesn't handle this.
+  atomic_intmax_t big;
+  // atomic_intmax_t(size = 64) is not lock free on mips32.
+#if defined(__mips__) && !defined(__LP64__)
+  ASSERT_FALSE(atomic_is_lock_free(&big));
+#else
+  ASSERT_TRUE(atomic_is_lock_free(&big));
+#endif
+#endif
+}
+
+TEST(stdatomic, atomic_flag) {
+  atomic_flag f = ATOMIC_FLAG_INIT;
+  ASSERT_FALSE(atomic_flag_test_and_set(&f));
+  ASSERT_TRUE(atomic_flag_test_and_set(&f));
+
+  atomic_flag_clear(&f);
+
+  ASSERT_FALSE(atomic_flag_test_and_set_explicit(&f, memory_order_relaxed));
+  ASSERT_TRUE(atomic_flag_test_and_set_explicit(&f, memory_order_relaxed));
+
+  atomic_flag_clear_explicit(&f, memory_order_relaxed);
+  ASSERT_FALSE(atomic_flag_test_and_set_explicit(&f, memory_order_relaxed));
+}
+
+TEST(stdatomic, atomic_store) {
+  atomic_int i;
+  atomic_store(&i, 123);
+  ASSERT_EQ(123, atomic_load(&i));
+  atomic_store_explicit(&i, 123, memory_order_relaxed);
+  ASSERT_EQ(123, atomic_load_explicit(&i, memory_order_relaxed));
+}
+
+TEST(stdatomic, atomic_exchange) {
+  atomic_int i;
+  atomic_store(&i, 123);
+  ASSERT_EQ(123, atomic_exchange(&i, 456));
+  ASSERT_EQ(456, atomic_exchange_explicit(&i, 123, memory_order_relaxed));
+}
+
+TEST(stdatomic, atomic_compare_exchange) {
+  atomic_int i;
+  int expected;
+
+  atomic_store(&i, 123);
+  expected = 123;
+  ASSERT_TRUE(atomic_compare_exchange_strong(&i, &expected, 456));
+  ASSERT_FALSE(atomic_compare_exchange_strong(&i, &expected, 456));
+  ASSERT_EQ(456, expected);
+
+  atomic_store(&i, 123);
+  expected = 123;
+  ASSERT_TRUE(atomic_compare_exchange_strong_explicit(&i, &expected, 456, memory_order_relaxed, memory_order_relaxed));
+  ASSERT_FALSE(atomic_compare_exchange_strong_explicit(&i, &expected, 456, memory_order_relaxed, memory_order_relaxed));
+  ASSERT_EQ(456, expected);
+
+  atomic_store(&i, 123);
+  expected = 123;
+  ASSERT_TRUE(atomic_compare_exchange_weak(&i, &expected, 456));
+  ASSERT_FALSE(atomic_compare_exchange_weak(&i, &expected, 456));
+  ASSERT_EQ(456, expected);
+
+  atomic_store(&i, 123);
+  expected = 123;
+  ASSERT_TRUE(atomic_compare_exchange_weak_explicit(&i, &expected, 456, memory_order_relaxed, memory_order_relaxed));
+  ASSERT_FALSE(atomic_compare_exchange_weak_explicit(&i, &expected, 456, memory_order_relaxed, memory_order_relaxed));
+  ASSERT_EQ(456, expected);
+}
+
+TEST(stdatomic, atomic_fetch_add) {
+  atomic_int i = ATOMIC_VAR_INIT(123);
+  ASSERT_EQ(123, atomic_fetch_add(&i, 1));
+  ASSERT_EQ(124, atomic_fetch_add_explicit(&i, 1, memory_order_relaxed));
+  ASSERT_EQ(125, atomic_load(&i));
+}
+
+TEST(stdatomic, atomic_fetch_sub) {
+  atomic_int i = ATOMIC_VAR_INIT(123);
+  ASSERT_EQ(123, atomic_fetch_sub(&i, 1));
+  ASSERT_EQ(122, atomic_fetch_sub_explicit(&i, 1, memory_order_relaxed));
+  ASSERT_EQ(121, atomic_load(&i));
+}
+
+TEST(stdatomic, atomic_fetch_or) {
+  atomic_int i = ATOMIC_VAR_INIT(0x100);
+  ASSERT_EQ(0x100, atomic_fetch_or(&i, 0x020));
+  ASSERT_EQ(0x120, atomic_fetch_or_explicit(&i, 0x003, memory_order_relaxed));
+  ASSERT_EQ(0x123, atomic_load(&i));
+}
+
+TEST(stdatomic, atomic_fetch_xor) {
+  atomic_int i = ATOMIC_VAR_INIT(0x100);
+  ASSERT_EQ(0x100, atomic_fetch_xor(&i, 0x120));
+  ASSERT_EQ(0x020, atomic_fetch_xor_explicit(&i, 0x103, memory_order_relaxed));
+  ASSERT_EQ(0x123, atomic_load(&i));
+}
+
+TEST(stdatomic, atomic_fetch_and) {
+  atomic_int i = ATOMIC_VAR_INIT(0x123);
+  ASSERT_EQ(0x123, atomic_fetch_and(&i, 0x00f));
+  ASSERT_EQ(0x003, atomic_fetch_and_explicit(&i, 0x2, memory_order_relaxed));
+  ASSERT_EQ(0x002, atomic_load(&i));
+}
+
+// And a rudimentary test of acquire-release memory ordering:
+
+constexpr static uint_least32_t BIG = 10000000ul; // Assumed even below.
+
+struct three_atomics {
+  atomic_uint_least32_t x;
+  char a[123];  // Everything in different cache lines,
+                // increase chance of compiler getting alignment wrong.
+  atomic_uint_least32_t y;
+  char b[4013];
+  atomic_uint_least32_t z;
+};
+
+// Very simple acquire/release memory ordering sanity check.
+static void* writer(void* arg) {
+  three_atomics* a = reinterpret_cast<three_atomics*>(arg);
+  for (uint_least32_t i = 0; i <= BIG; i+=2) {
+    atomic_store_explicit(&a->x, i, memory_order_relaxed);
+    atomic_store_explicit(&a->z, i, memory_order_relaxed);
+    atomic_store_explicit(&a->y, i, memory_order_release);
+    atomic_store_explicit(&a->x, i+1, memory_order_relaxed);
+    atomic_store_explicit(&a->z, i+1, memory_order_relaxed);
+    atomic_store_explicit(&a->y, i+1, memory_order_release);
+  }
+  return 0;
+}
+
+static void* reader(void* arg) {
+  three_atomics* a = reinterpret_cast<three_atomics*>(arg);
+  uint_least32_t xval = 0, yval = 0, zval = 0;
+  size_t repeat = 0;
+  size_t repeat_limit = 1000;
+  while (yval != BIG + 1) {
+    yval = atomic_load_explicit(&a->y, memory_order_acquire);
+    zval = atomic_load_explicit(&a->z, memory_order_relaxed);
+    xval = atomic_load_explicit(&a->x, memory_order_relaxed);
+    // If we see a given value of y, the immediately preceding
+    // stores to z and x, or later ones, should also be visible.
+    if (zval < yval) {
+      // Cant just ASSERT, since we are in a non-void function.
+      ADD_FAILURE() << "acquire-release ordering violation: "
+                    << zval << " < " << yval << ", " << xval << "\n";
+      return 0; // Only report once.
+    }
+    if (xval < yval) {
+      // Cant just ASSERT, since we are in a non-void function.
+      ADD_FAILURE() << "acquire-release ordering violation: "
+                    << xval << " < " << yval << ", " << zval <<  "\n";
+      return 0; // Only report once.
+    }
+    if (repeat < repeat_limit) ++repeat;
+  }
+  // The following assertion is not technically guaranteed to hold.
+  // But if it fails to hold, this test was useless, and we have a
+  // serious scheduling issue that we should probably know about.
+  EXPECT_EQ(repeat, repeat_limit);
+  return 0;
+}
+
+TEST(stdatomic, ordering) {
+  // Run a memory ordering sanity test.
+  void* result;
+  three_atomics a;
+  atomic_init(&a.x, 0ul);
+  atomic_init(&a.y, 0ul);
+  atomic_init(&a.z, 0ul);
+  pthread_t t1,t2;
+  ASSERT_EQ(0, pthread_create(&t1, 0, reader, &a));
+  ASSERT_EQ(0, pthread_create(&t2, 0, writer, &a));
+  ASSERT_EQ(0, pthread_join(t1, &result));
+  EXPECT_EQ(0, result);
+  ASSERT_EQ(0, pthread_join(t2, &result));
+  EXPECT_EQ(0, result);
+  EXPECT_EQ(atomic_load_explicit(&a.x, memory_order_consume), BIG + 1);
+  EXPECT_EQ(atomic_load_explicit(&a.y, memory_order_seq_cst), BIG + 1);
+  EXPECT_EQ(atomic_load(&a.z), BIG + 1);
+}
diff --git a/tests/stdint_test.cpp b/tests/stdint_test.cpp
new file mode 100644
index 0000000..5dafee3
--- /dev/null
+++ b/tests/stdint_test.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <stdint.h>
+
+TEST(stdint_types, type_sizes) {
+  ASSERT_EQ(1U, sizeof(int_fast8_t));
+  ASSERT_EQ(8U, sizeof(int_fast64_t));
+  ASSERT_EQ(1U, sizeof(uint_fast8_t));
+  ASSERT_EQ(8U, sizeof(uint_fast64_t));
+#if defined(__LP64__)
+  ASSERT_EQ(8U, sizeof(int_fast16_t));
+  ASSERT_EQ(8U, sizeof(int_fast32_t));
+  ASSERT_EQ(8U, sizeof(uint_fast16_t));
+  ASSERT_EQ(8U, sizeof(uint_fast32_t));
+#else
+  ASSERT_EQ(4U, sizeof(int_fast16_t));
+  ASSERT_EQ(4U, sizeof(int_fast32_t));
+  ASSERT_EQ(4U, sizeof(uint_fast16_t));
+  ASSERT_EQ(4U, sizeof(uint_fast32_t));
+#endif
+}
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index bd3c548..8c8c235 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -17,11 +17,17 @@
 #include <gtest/gtest.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <limits.h>
+#include <math.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <wchar.h>
+#include <locale.h>
+
+#include "TemporaryFile.h"
 
 TEST(stdio, tmpfile_fileno_fprintf_rewind_fgets) {
   FILE* fp = tmpfile();
@@ -48,6 +54,24 @@
   fclose(fp);
 }
 
+TEST(stdio, dprintf) {
+  TemporaryFile tf;
+
+  int rc = dprintf(tf.fd, "hello\n");
+  ASSERT_EQ(rc, 6);
+
+  lseek(tf.fd, SEEK_SET, 0);
+  FILE* tfile = fdopen(tf.fd, "r");
+  ASSERT_TRUE(tfile != NULL);
+
+  char buf[7];
+  ASSERT_EQ(buf, fgets(buf, sizeof(buf), tfile));
+  ASSERT_STREQ("hello\n", buf);
+  // Make sure there isn't anything else in the file.
+  ASSERT_EQ(NULL, fgets(buf, sizeof(buf), tfile));
+  fclose(tfile);
+}
+
 TEST(stdio, getdelim) {
   FILE* fp = tmpfile();
   ASSERT_TRUE(fp != NULL);
@@ -100,14 +124,12 @@
   ASSERT_EQ(getdelim(&buffer, NULL, ' ', fp), -1);
   ASSERT_EQ(EINVAL, errno);
 
-  // The stream can't be closed.
-  fclose(fp);
+  // The underlying fd can't be closed.
+  ASSERT_EQ(0, close(fileno(fp)));
   errno = 0;
   ASSERT_EQ(getdelim(&buffer, &buffer_length, ' ', fp), -1);
-  // glibc sometimes doesn't set errno in this particular case.
-#if defined(__BIONIC__)
   ASSERT_EQ(EBADF, errno);
-#endif
+  fclose(fp);
 }
 
 TEST(stdio, getline) {
@@ -169,14 +191,12 @@
   ASSERT_EQ(getline(&buffer, NULL, fp), -1);
   ASSERT_EQ(EINVAL, errno);
 
-  // The stream can't be closed.
-  fclose(fp);
+  // The underlying fd can't be closed.
+  ASSERT_EQ(0, close(fileno(fp)));
   errno = 0;
   ASSERT_EQ(getline(&buffer, &buffer_length, fp), -1);
-  // glibc sometimes doesn't set errno in this particular case.
-#if defined(__BIONIC__)
   ASSERT_EQ(EBADF, errno);
-#endif
+  fclose(fp);
 }
 
 TEST(stdio, printf_ssize_t) {
@@ -191,17 +211,44 @@
   snprintf(buf, sizeof(buf), "%zd", v);
 }
 
-#if !defined(__GLIBC__)
-TEST(stdio, snprintf_n_format_specifier_not_implemented) {
-  char buf[32];
-  int i = 0;
-  // We deliberately don't implement %n, so it's treated like
-  // any other unrecognized format specifier.
-  EXPECT_EQ(5, snprintf(buf, sizeof(buf), "a %n b", &i));
-  EXPECT_EQ(0, i);
-  EXPECT_STREQ("a n b", buf);
+// https://code.google.com/p/android/issues/detail?id=64886
+TEST(stdio, snprintf_a) {
+  char buf[BUFSIZ];
+  EXPECT_EQ(23, snprintf(buf, sizeof(buf), "<%a>", 9990.235));
+  EXPECT_STREQ("<0x1.3831e147ae148p+13>", buf);
 }
+
+TEST(stdio, snprintf_lc) {
+  char buf[BUFSIZ];
+  wint_t wc = L'a';
+  EXPECT_EQ(3, snprintf(buf, sizeof(buf), "<%lc>", wc));
+  EXPECT_STREQ("<a>", buf);
+}
+
+TEST(stdio, snprintf_ls) {
+  char buf[BUFSIZ];
+  wchar_t* ws = NULL;
+  EXPECT_EQ(8, snprintf(buf, sizeof(buf), "<%ls>", ws));
+  EXPECT_STREQ("<(null)>", buf);
+
+  wchar_t chars[] = { L'h', L'i', 0 };
+  ws = chars;
+  EXPECT_EQ(4, snprintf(buf, sizeof(buf), "<%ls>", ws));
+  EXPECT_STREQ("<hi>", buf);
+}
+
+TEST(stdio, snprintf_n) {
+#if defined(__BIONIC__)
+  // http://b/14492135
+  char buf[32];
+  int i = 1234;
+  EXPECT_EQ(5, snprintf(buf, sizeof(buf), "a %n b", &i));
+  EXPECT_EQ(1234, i);
+  EXPECT_STREQ("a n b", buf);
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
 #endif
+}
 
 TEST(stdio, snprintf_smoke) {
   char buf[BUFSIZ];
@@ -283,9 +330,9 @@
   snprintf(buf, sizeof(buf), "a%d,%pz", 5, p);
 #if defined(__BIONIC__)
   EXPECT_STREQ("a5,0x0z", buf);
-#else
+#else // __BIONIC__
   EXPECT_STREQ("a5,(nil)z", buf);
-#endif
+#endif // __BIONIC__
 
   snprintf(buf, sizeof(buf), "a%lld,%d,%d,%dz", 0x1000000000LL, 6, 7, 8);
   EXPECT_STREQ("a68719476736,6,7,8z", buf);
@@ -295,6 +342,27 @@
 
   snprintf(buf, sizeof(buf), "a_%g_b", 3.14);
   EXPECT_STREQ("a_3.14_b", buf);
+
+  snprintf(buf, sizeof(buf), "%1$s %1$s", "print_me_twice");
+  EXPECT_STREQ("print_me_twice print_me_twice", buf);
+}
+
+TEST(stdio, snprintf_f_special) {
+  char buf[BUFSIZ];
+  snprintf(buf, sizeof(buf), "%f", nanf(""));
+  EXPECT_STRCASEEQ("NaN", buf);
+
+  snprintf(buf, sizeof(buf), "%f", HUGE_VALF);
+  EXPECT_STRCASEEQ("Inf", buf);
+}
+
+TEST(stdio, snprintf_g_special) {
+  char buf[BUFSIZ];
+  snprintf(buf, sizeof(buf), "%g", nan(""));
+  EXPECT_STRCASEEQ("NaN", buf);
+
+  snprintf(buf, sizeof(buf), "%g", HUGE_VAL);
+  EXPECT_STRCASEEQ("Inf", buf);
 }
 
 TEST(stdio, snprintf_d_INT_MAX) {
@@ -341,6 +409,70 @@
   EXPECT_STREQ("-9223372036854775808", buf);
 }
 
+TEST(stdio, snprintf_e) {
+  char buf[BUFSIZ];
+
+  snprintf(buf, sizeof(buf), "%e", 1.5);
+  EXPECT_STREQ("1.500000e+00", buf);
+
+  snprintf(buf, sizeof(buf), "%Le", 1.5l);
+  EXPECT_STREQ("1.500000e+00", buf);
+}
+
+TEST(stdio, snprintf_negative_zero_5084292) {
+  char buf[BUFSIZ];
+
+  snprintf(buf, sizeof(buf), "%f", -0.0);
+  EXPECT_STREQ("-0.000000", buf);
+}
+
+TEST(stdio, snprintf_utf8_15439554) {
+  locale_t cloc = newlocale(LC_ALL, "C.UTF-8", 0);
+  locale_t old_locale = uselocale(cloc);
+
+  // http://b/15439554
+  char buf[BUFSIZ];
+
+  // 1-byte character.
+  snprintf(buf, sizeof(buf), "%dx%d", 1, 2);
+  EXPECT_STREQ("1x2", buf);
+  // 2-byte character.
+  snprintf(buf, sizeof(buf), "%d\xc2\xa2%d", 1, 2);
+  EXPECT_STREQ("1¢2", buf);
+  // 3-byte character.
+  snprintf(buf, sizeof(buf), "%d\xe2\x82\xac%d", 1, 2);
+  EXPECT_STREQ("1€2", buf);
+  // 4-byte character.
+  snprintf(buf, sizeof(buf), "%d\xf0\xa4\xad\xa2%d", 1, 2);
+  EXPECT_STREQ("1𤭢2", buf);
+
+  uselocale(old_locale);
+  freelocale(cloc);
+}
+
+TEST(stdio, fprintf_failures_7229520) {
+  // http://b/7229520
+  FILE* fp;
+
+  // Unbuffered case where the fprintf(3) itself fails.
+  ASSERT_NE(nullptr, fp = tmpfile());
+  setbuf(fp, NULL);
+  ASSERT_EQ(4, fprintf(fp, "epic"));
+  ASSERT_EQ(0, close(fileno(fp)));
+  ASSERT_EQ(-1, fprintf(fp, "fail"));
+  ASSERT_EQ(-1, fclose(fp));
+
+  // Buffered case where we won't notice until the fclose(3).
+  // It's likely this is what was actually seen in http://b/7229520,
+  // and that expecting fprintf to fail is setting yourself up for
+  // disappointment. Remember to check fclose(3)'s return value, kids!
+  ASSERT_NE(nullptr, fp = tmpfile());
+  ASSERT_EQ(4, fprintf(fp, "epic"));
+  ASSERT_EQ(0, close(fileno(fp)));
+  ASSERT_EQ(4, fprintf(fp, "fail"));
+  ASSERT_EQ(-1, fclose(fp));
+}
+
 TEST(stdio, popen) {
   FILE* fp = popen("cat /proc/version", "r");
   ASSERT_TRUE(fp != NULL);
@@ -370,3 +502,178 @@
   ASSERT_EQ(EOF, putc('x', fp));
   fclose(fp);
 }
+
+TEST(stdio, sscanf) {
+  char s1[123];
+  int i1;
+  double d1;
+  char s2[123];
+  ASSERT_EQ(3, sscanf("  hello 123 1.23 ", "%s %i %lf %s", s1, &i1, &d1, s2));
+  ASSERT_STREQ("hello", s1);
+  ASSERT_EQ(123, i1);
+  ASSERT_DOUBLE_EQ(1.23, d1);
+}
+
+TEST(stdio, cantwrite_EBADF) {
+  // If we open a file read-only...
+  FILE* fp = fopen("/proc/version", "r");
+
+  // ...all attempts to write to that file should return failure.
+
+  // They should also set errno to EBADF. This isn't POSIX, but it's traditional.
+  // glibc gets the wide-character functions wrong.
+
+  errno = 0;
+  EXPECT_EQ(EOF, putc('x', fp));
+  EXPECT_EQ(EBADF, errno);
+
+  errno = 0;
+  EXPECT_EQ(EOF, fprintf(fp, "hello"));
+  EXPECT_EQ(EBADF, errno);
+
+  errno = 0;
+  EXPECT_EQ(EOF, fwprintf(fp, L"hello"));
+#if defined(__BIONIC__)
+  EXPECT_EQ(EBADF, errno);
+#endif
+
+  errno = 0;
+  EXPECT_EQ(0U, fwrite("hello", 1, 2, fp));
+  EXPECT_EQ(EBADF, errno);
+
+  errno = 0;
+  EXPECT_EQ(EOF, fputs("hello", fp));
+  EXPECT_EQ(EBADF, errno);
+
+  errno = 0;
+  EXPECT_EQ(WEOF, fputwc(L'x', fp));
+#if defined(__BIONIC__)
+  EXPECT_EQ(EBADF, errno);
+#endif
+}
+
+// Tests that we can only have a consistent and correct fpos_t when using
+// f*pos functions (i.e. fpos doesn't get inside a multi byte character).
+TEST(stdio, consistent_fpos_t) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  FILE* fp = tmpfile();
+  ASSERT_TRUE(fp != NULL);
+
+  wchar_t mb_one_bytes = L'h';
+  wchar_t mb_two_bytes = 0x00a2;
+  wchar_t mb_three_bytes = 0x20ac;
+  wchar_t mb_four_bytes = 0x24b62;
+
+  // Write to file.
+  ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fputwc(mb_one_bytes, fp)));
+  ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fputwc(mb_two_bytes, fp)));
+  ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fputwc(mb_three_bytes, fp)));
+  ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fputwc(mb_four_bytes, fp)));
+
+  rewind(fp);
+
+  // Record each character position.
+  fpos_t pos1;
+  fpos_t pos2;
+  fpos_t pos3;
+  fpos_t pos4;
+  fpos_t pos5;
+  EXPECT_EQ(0, fgetpos(fp, &pos1));
+  ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fgetwc(fp)));
+  EXPECT_EQ(0, fgetpos(fp, &pos2));
+  ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp)));
+  EXPECT_EQ(0, fgetpos(fp, &pos3));
+  ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fgetwc(fp)));
+  EXPECT_EQ(0, fgetpos(fp, &pos4));
+  ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fgetwc(fp)));
+  EXPECT_EQ(0, fgetpos(fp, &pos5));
+
+#if defined(__BIONIC__)
+  // Bionic's fpos_t is just an alias for off_t. This is inherited from OpenBSD
+  // upstream. Glibc differs by storing the mbstate_t inside its fpos_t. In
+  // Bionic (and upstream OpenBSD) the mbstate_t is stored inside the FILE
+  // structure.
+  ASSERT_EQ(0, static_cast<off_t>(pos1));
+  ASSERT_EQ(1, static_cast<off_t>(pos2));
+  ASSERT_EQ(3, static_cast<off_t>(pos3));
+  ASSERT_EQ(6, static_cast<off_t>(pos4));
+  ASSERT_EQ(10, static_cast<off_t>(pos5));
+#endif
+
+  // Exercise back and forth movements of the position.
+  ASSERT_EQ(0, fsetpos(fp, &pos2));
+  ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp)));
+  ASSERT_EQ(0, fsetpos(fp, &pos1));
+  ASSERT_EQ(mb_one_bytes, static_cast<wchar_t>(fgetwc(fp)));
+  ASSERT_EQ(0, fsetpos(fp, &pos4));
+  ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fgetwc(fp)));
+  ASSERT_EQ(0, fsetpos(fp, &pos3));
+  ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fgetwc(fp)));
+  ASSERT_EQ(0, fsetpos(fp, &pos5));
+  ASSERT_EQ(WEOF, fgetwc(fp));
+
+  fclose(fp);
+}
+
+// Exercise the interaction between fpos and seek.
+TEST(stdio, fpos_t_and_seek) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  // In glibc-2.16 fseek doesn't work properly in wide mode
+  // (https://sourceware.org/bugzilla/show_bug.cgi?id=14543). One workaround is
+  // to close and re-open the file. We do it in order to make the test pass
+  // with all glibcs.
+
+  TemporaryFile tf;
+  FILE* fp = fdopen(tf.fd, "w+");
+  ASSERT_TRUE(fp != NULL);
+
+  wchar_t mb_two_bytes = 0x00a2;
+  wchar_t mb_three_bytes = 0x20ac;
+  wchar_t mb_four_bytes = 0x24b62;
+
+  // Write to file.
+  ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fputwc(mb_two_bytes, fp)));
+  ASSERT_EQ(mb_three_bytes, static_cast<wchar_t>(fputwc(mb_three_bytes, fp)));
+  ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fputwc(mb_four_bytes, fp)));
+
+  fflush(fp);
+  fclose(fp);
+
+  fp = fopen(tf.filename, "r");
+  ASSERT_TRUE(fp != NULL);
+
+  // Store a valid position.
+  fpos_t mb_two_bytes_pos;
+  ASSERT_EQ(0, fgetpos(fp, &mb_two_bytes_pos));
+
+  // Move inside mb_four_bytes with fseek.
+  long offset_inside_mb = 6;
+  ASSERT_EQ(0, fseek(fp, offset_inside_mb, SEEK_SET));
+
+  // Store the "inside multi byte" position.
+  fpos_t pos_inside_mb;
+  ASSERT_EQ(0, fgetpos(fp, &pos_inside_mb));
+#if defined(__BIONIC__)
+  ASSERT_EQ(offset_inside_mb, static_cast<off_t>(pos_inside_mb));
+#endif
+
+  // Reading from within a byte should produce an error.
+  ASSERT_EQ(WEOF, fgetwc(fp));
+  ASSERT_EQ(EILSEQ, errno);
+
+  // Reverting to a valid position should work.
+  ASSERT_EQ(0, fsetpos(fp, &mb_two_bytes_pos));
+  ASSERT_EQ(mb_two_bytes, static_cast<wchar_t>(fgetwc(fp)));
+
+  // Moving withing a multi byte with fsetpos should work but reading should
+  // produce an error.
+  ASSERT_EQ(0, fsetpos(fp, &pos_inside_mb));
+  ASSERT_EQ(WEOF, fgetwc(fp));
+  ASSERT_EQ(EILSEQ, errno);
+
+  fclose(fp);
+}
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index fa59c41..553f018 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -15,6 +15,7 @@
  */
 
 #include <gtest/gtest.h>
+#include "TemporaryFile.h"
 
 #include <errno.h>
 #include <libgen.h>
@@ -22,6 +23,9 @@
 #include <pthread.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 TEST(stdlib, drand48) {
   srand48(0x01020304);
@@ -31,28 +35,28 @@
   EXPECT_DOUBLE_EQ(0.061637783047395089, drand48());
 }
 
-TEST(stdlib, lrand48_random_rand) {
+TEST(stdlib, lrand48) {
   srand48(0x01020304);
   EXPECT_EQ(1409163720, lrand48());
   EXPECT_EQ(397769746, lrand48());
   EXPECT_EQ(902267124, lrand48());
   EXPECT_EQ(132366131, lrand48());
+}
 
-#if __BIONIC__
-  // On bionic, random(3) is equivalent to lrand48...
+TEST(stdlib, random) {
   srandom(0x01020304);
-  EXPECT_EQ(1409163720, random());
-  EXPECT_EQ(397769746, random());
-  EXPECT_EQ(902267124, random());
-  EXPECT_EQ(132366131, random());
+  EXPECT_EQ(55436735, random());
+  EXPECT_EQ(1399865117, random());
+  EXPECT_EQ(2032643283, random());
+  EXPECT_EQ(571329216, random());
+}
 
-  // ...and rand(3) is the bottom 32 bits.
+TEST(stdlib, rand) {
   srand(0x01020304);
-  EXPECT_EQ(static_cast<int>(1409163720), rand());
-  EXPECT_EQ(static_cast<int>(397769746), rand());
-  EXPECT_EQ(static_cast<int>(902267124), rand());
-  EXPECT_EQ(static_cast<int>(132366131), rand());
-#endif
+  EXPECT_EQ(55436735, rand());
+  EXPECT_EQ(1399865117, rand());
+  EXPECT_EQ(2032643283, rand());
+  EXPECT_EQ(571329216, rand());
 }
 
 TEST(stdlib, mrand48) {
@@ -157,3 +161,203 @@
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   ASSERT_EXIT(TestBug57421_main(), ::testing::ExitedWithCode(0), "");
 }
+
+TEST(stdlib, mkstemp) {
+  TemporaryFile tf;
+  struct stat sb;
+  ASSERT_EQ(0, fstat(tf.fd, &sb));
+}
+
+TEST(stdlib, mkstemp64) {
+  GenericTemporaryFile<mkstemp64> tf;
+  struct stat64 sb;
+  ASSERT_EQ(0, fstat64(tf.fd, &sb));
+  ASSERT_EQ(O_LARGEFILE, fcntl(tf.fd, F_GETFL) & O_LARGEFILE);
+}
+
+TEST(stdlib, system) {
+  int status;
+
+  status = system("exit 0");
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(0, WEXITSTATUS(status));
+
+  status = system("exit 1");
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(1, WEXITSTATUS(status));
+}
+
+TEST(stdlib, atof) {
+  ASSERT_DOUBLE_EQ(1.23, atof("1.23"));
+}
+
+TEST(stdlib, strtod) {
+  ASSERT_DOUBLE_EQ(1.23, strtod("1.23", NULL));
+}
+
+TEST(stdlib, strtof) {
+  ASSERT_FLOAT_EQ(1.23, strtof("1.23", NULL));
+}
+
+TEST(stdlib, strtold) {
+  ASSERT_DOUBLE_EQ(1.23, strtold("1.23", NULL));
+}
+
+TEST(stdlib, quick_exit) {
+  pid_t pid = fork();
+  ASSERT_NE(-1, pid) << strerror(errno);
+
+  if (pid == 0) {
+    quick_exit(99);
+  }
+
+  int status;
+  ASSERT_EQ(pid, waitpid(pid, &status, 0));
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(99, WEXITSTATUS(status));
+}
+
+static int quick_exit_status = 0;
+
+static void quick_exit_1(void) {
+  ASSERT_EQ(quick_exit_status, 0);
+  quick_exit_status = 1;
+}
+
+static void quick_exit_2(void) {
+  ASSERT_EQ(quick_exit_status, 1);
+}
+
+static void not_run(void) {
+  FAIL();
+}
+
+TEST(stdlib, at_quick_exit) {
+  pid_t pid = fork();
+  ASSERT_NE(-1, pid) << strerror(errno);
+
+  if (pid == 0) {
+    ASSERT_EQ(at_quick_exit(quick_exit_2), 0);
+    ASSERT_EQ(at_quick_exit(quick_exit_1), 0);
+    atexit(not_run);
+    quick_exit(99);
+  }
+
+  int status;
+  ASSERT_EQ(pid, waitpid(pid, &status, 0));
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(99, WEXITSTATUS(status));
+}
+
+TEST(unistd, _Exit) {
+  int pid = fork();
+  ASSERT_NE(-1, pid) << strerror(errno);
+
+  if (pid == 0) {
+    _Exit(99);
+  }
+
+  int status;
+  ASSERT_EQ(pid, waitpid(pid, &status, 0));
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(99, WEXITSTATUS(status));
+}
+
+TEST(stdlib, pty_smoke) {
+  // getpt returns a pty with O_RDWR|O_NOCTTY.
+  int fd = getpt();
+  ASSERT_NE(-1, fd);
+
+  // grantpt is a no-op.
+  ASSERT_EQ(0, grantpt(fd));
+
+  // ptsname_r should start "/dev/pts/".
+  char name_r[128];
+  ASSERT_EQ(0, ptsname_r(fd, name_r, sizeof(name_r)));
+  name_r[9] = 0;
+  ASSERT_STREQ("/dev/pts/", name_r);
+
+  close(fd);
+}
+
+TEST(stdlib, posix_openpt) {
+  int fd = posix_openpt(O_RDWR|O_NOCTTY|O_CLOEXEC);
+  ASSERT_NE(-1, fd);
+  close(fd);
+}
+
+TEST(stdlib, ptsname_r_ENOTTY) {
+  errno = 0;
+  char buf[128];
+  ASSERT_EQ(ENOTTY, ptsname_r(STDOUT_FILENO, buf, sizeof(buf)));
+  ASSERT_EQ(ENOTTY, errno);
+}
+
+TEST(stdlib, ptsname_r_EINVAL) {
+  int fd = getpt();
+  ASSERT_NE(-1, fd);
+  errno = 0;
+  char* buf = NULL;
+  ASSERT_EQ(EINVAL, ptsname_r(fd, buf, 128));
+  ASSERT_EQ(EINVAL, errno);
+  close(fd);
+}
+
+TEST(stdlib, ptsname_r_ERANGE) {
+  int fd = getpt();
+  ASSERT_NE(-1, fd);
+  errno = 0;
+  char buf[1];
+  ASSERT_EQ(ERANGE, ptsname_r(fd, buf, sizeof(buf)));
+  ASSERT_EQ(ERANGE, errno);
+  close(fd);
+}
+
+TEST(stdlib, ttyname_r) {
+  int fd = getpt();
+  ASSERT_NE(-1, fd);
+
+  // ttyname_r returns "/dev/ptmx" for a pty.
+  char name_r[128];
+  ASSERT_EQ(0, ttyname_r(fd, name_r, sizeof(name_r)));
+  ASSERT_STREQ("/dev/ptmx", name_r);
+
+  close(fd);
+}
+
+TEST(stdlib, ttyname_r_ENOTTY) {
+  int fd = open("/dev/null", O_WRONLY);
+  errno = 0;
+  char buf[128];
+  ASSERT_EQ(ENOTTY, ttyname_r(fd, buf, sizeof(buf)));
+  ASSERT_EQ(ENOTTY, errno);
+  close(fd);
+}
+
+TEST(stdlib, ttyname_r_EINVAL) {
+  int fd = getpt();
+  ASSERT_NE(-1, fd);
+  errno = 0;
+  char* buf = NULL;
+  ASSERT_EQ(EINVAL, ttyname_r(fd, buf, 128));
+  ASSERT_EQ(EINVAL, errno);
+  close(fd);
+}
+
+TEST(stdlib, ttyname_r_ERANGE) {
+  int fd = getpt();
+  ASSERT_NE(-1, fd);
+  errno = 0;
+  char buf[1];
+  ASSERT_EQ(ERANGE, ttyname_r(fd, buf, sizeof(buf)));
+  ASSERT_EQ(ERANGE, errno);
+  close(fd);
+}
+
+TEST(stdlib, unlockpt_ENOTTY) {
+  int fd = open("/dev/null", O_WRONLY);
+  errno = 0;
+  ASSERT_EQ(-1, unlockpt(fd));
+  ASSERT_EQ(ENOTTY, errno);
+  close(fd);
+}
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 1a7e27d..73c94c6 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -17,6 +17,7 @@
 #include <gtest/gtest.h>
 
 #include <errno.h>
+#include <malloc.h>
 #include <math.h>
 #include <string.h>
 
@@ -46,14 +47,16 @@
   ASSERT_STREQ("Unknown error 1234", strerror(1234));
 }
 
-#if __BIONIC__ // glibc's strerror isn't thread safe, only its strsignal.
-
+#if defined(__BIONIC__)
 static void* ConcurrentStrErrorFn(void*) {
   bool equal = (strcmp("Unknown error 2002", strerror(2002)) == 0);
   return reinterpret_cast<void*>(equal);
 }
+#endif // __BIONIC__
 
+// glibc's strerror isn't thread safe, only its strsignal.
 TEST(string, strerror_concurrent) {
+#if defined(__BIONIC__)
   const char* strerror1001 = strerror(1001);
   ASSERT_STREQ("Unknown error 1001", strerror1001);
 
@@ -64,12 +67,13 @@
   ASSERT_TRUE(static_cast<bool>(result));
 
   ASSERT_STREQ("Unknown error 1001", strerror1001);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
-#endif
-
-#if __BIONIC__ // glibc's strerror_r doesn't even have the same signature as the POSIX one.
 TEST(string, strerror_r) {
+#if defined(__BIONIC__) // glibc's strerror_r doesn't even have the same signature as the POSIX one.
   char buf[256];
 
   // Valid.
@@ -87,19 +91,19 @@
   // Buffer too small.
   ASSERT_EQ(-1, strerror_r(0, buf, 2));
   ASSERT_EQ(ERANGE, errno);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
 TEST(string, strsignal) {
   // A regular signal.
   ASSERT_STREQ("Hangup", strsignal(1));
 
   // A real-time signal.
-#ifdef __GLIBC__ // glibc reserves real-time signals for internal use, and doesn't count those.
-  ASSERT_STREQ("Real-time signal 14", strsignal(48));
-#else
-  ASSERT_STREQ("Real-time signal 16", strsignal(48));
-#endif
+  ASSERT_STREQ("Real-time signal 14", strsignal(SIGRTMIN + 14));
+  // One of the signals the C library keeps to itself.
+  ASSERT_STREQ("Unknown signal 32", strsignal(__SIGRTMIN));
 
   // Errors.
   ASSERT_STREQ("Unknown signal -1", strsignal(-1)); // Too small.
@@ -140,9 +144,9 @@
     int max_alignment = 64;
 
     // TODO: fix the tests to not sometimes use twice their specified "MAX_LEN".
-    glob_ptr = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment));
-    glob_ptr1 = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment));
-    glob_ptr2 = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment));
+    glob_ptr = reinterpret_cast<Character*>(memalign(sysconf(_SC_PAGESIZE), 2 * sizeof(Character) * MAX_LEN + max_alignment));
+    glob_ptr1 = reinterpret_cast<Character*>(memalign(sysconf(_SC_PAGESIZE), 2 * sizeof(Character) * MAX_LEN + max_alignment));
+    glob_ptr2 = reinterpret_cast<Character*>(memalign(sysconf(_SC_PAGESIZE), 2 * sizeof(Character) * MAX_LEN + max_alignment));
 
     InitLenArray();
 
@@ -217,7 +221,7 @@
 TEST(string, strcpy2) {
   char buf[1];
   char* orig = strdup("");
-  strcpy(buf, orig);
+  ASSERT_EQ(buf, strcpy(buf, orig));
   ASSERT_EQ('\0', buf[0]);
   free(orig);
 }
@@ -227,13 +231,8 @@
   char buf[10];
   char* orig = strdup("12345");
   memset(buf, 'A', sizeof(buf));
-  strcpy(buf, orig);
-  ASSERT_EQ('1',  buf[0]);
-  ASSERT_EQ('2',  buf[1]);
-  ASSERT_EQ('3',  buf[2]);
-  ASSERT_EQ('4',  buf[3]);
-  ASSERT_EQ('5',  buf[4]);
-  ASSERT_EQ('\0', buf[5]);
+  ASSERT_EQ(buf, strcpy(buf, orig));
+  ASSERT_STREQ("12345", buf);
   ASSERT_EQ('A',  buf[6]);
   ASSERT_EQ('A',  buf[7]);
   ASSERT_EQ('A',  buf[8]);
@@ -246,17 +245,41 @@
   char buf[10];
   char* orig = strdup("123456789");
   memset(buf, 'A', sizeof(buf));
-  strcpy(buf, orig);
-  ASSERT_EQ('1',  buf[0]);
-  ASSERT_EQ('2',  buf[1]);
-  ASSERT_EQ('3',  buf[2]);
-  ASSERT_EQ('4',  buf[3]);
-  ASSERT_EQ('5',  buf[4]);
-  ASSERT_EQ('6',  buf[5]);
-  ASSERT_EQ('7',  buf[6]);
-  ASSERT_EQ('8',  buf[7]);
-  ASSERT_EQ('9',  buf[8]);
-  ASSERT_EQ('\0', buf[9]);
+  ASSERT_EQ(buf, strcpy(buf, orig));
+  ASSERT_STREQ("123456789", buf);
+  free(orig);
+}
+
+// one byte target with "\0" source
+TEST(string, stpcpy2) {
+  char buf[1];
+  char* orig = strdup("");
+  ASSERT_EQ(buf, stpcpy(buf, orig));
+  ASSERT_EQ('\0', buf[0]);
+  free(orig);
+}
+
+// multibyte target where we under fill target
+TEST(string, stpcpy3) {
+  char buf[10];
+  char* orig = strdup("12345");
+  memset(buf, 'A', sizeof(buf));
+  ASSERT_EQ(buf+strlen(orig), stpcpy(buf, orig));
+  ASSERT_STREQ("12345", buf);
+  ASSERT_EQ('A',  buf[6]);
+  ASSERT_EQ('A',  buf[7]);
+  ASSERT_EQ('A',  buf[8]);
+  ASSERT_EQ('A',  buf[9]);
+  free(orig);
+}
+
+// multibyte target where we fill target exactly
+TEST(string, stpcpy4) {
+  char buf[10];
+  char* orig = strdup("123456789");
+  memset(buf, 'A', sizeof(buf));
+  ASSERT_EQ(buf+strlen(orig), stpcpy(buf, orig));
+  ASSERT_STREQ("123456789", buf);
   free(orig);
 }
 
@@ -267,13 +290,7 @@
   buf[1] = '\0';
   char* res = strcat(buf, "01234");
   ASSERT_EQ(buf, res);
-  ASSERT_EQ('a',  buf[0]);
-  ASSERT_EQ('0',  buf[1]);
-  ASSERT_EQ('1',  buf[2]);
-  ASSERT_EQ('2',  buf[3]);
-  ASSERT_EQ('3',  buf[4]);
-  ASSERT_EQ('4',  buf[5]);
-  ASSERT_EQ('\0', buf[6]);
+  ASSERT_STREQ("a01234", buf);
   ASSERT_EQ('A',  buf[7]);
   ASSERT_EQ('A',  buf[8]);
   ASSERT_EQ('A',  buf[9]);
@@ -286,16 +303,7 @@
   buf[1] = '\0';
   char* res = strcat(buf, "01234567");
   ASSERT_EQ(buf, res);
-  ASSERT_EQ('a',  buf[0]);
-  ASSERT_EQ('0',  buf[1]);
-  ASSERT_EQ('1',  buf[2]);
-  ASSERT_EQ('2',  buf[3]);
-  ASSERT_EQ('3',  buf[4]);
-  ASSERT_EQ('4',  buf[5]);
-  ASSERT_EQ('5', buf[6]);
-  ASSERT_EQ('6',  buf[7]);
-  ASSERT_EQ('7',  buf[8]);
-  ASSERT_EQ('\0',  buf[9]);
+  ASSERT_STREQ("a01234567", buf);
 }
 
 TEST(string, strncat2) {
@@ -305,13 +313,7 @@
   buf[1] = '\0';
   char* res = strncat(buf, "01234", sizeof(buf) - strlen(buf) - 1);
   ASSERT_EQ(buf, res);
-  ASSERT_EQ('a',  buf[0]);
-  ASSERT_EQ('0',  buf[1]);
-  ASSERT_EQ('1',  buf[2]);
-  ASSERT_EQ('2',  buf[3]);
-  ASSERT_EQ('3',  buf[4]);
-  ASSERT_EQ('4',  buf[5]);
-  ASSERT_EQ('\0', buf[6]);
+  ASSERT_STREQ("a01234", buf);
   ASSERT_EQ('A',  buf[7]);
   ASSERT_EQ('A',  buf[8]);
   ASSERT_EQ('A',  buf[9]);
@@ -324,13 +326,7 @@
   buf[1] = '\0';
   char* res = strncat(buf, "0123456789", 5);
   ASSERT_EQ(buf, res);
-  ASSERT_EQ('a',  buf[0]);
-  ASSERT_EQ('0',  buf[1]);
-  ASSERT_EQ('1',  buf[2]);
-  ASSERT_EQ('2',  buf[3]);
-  ASSERT_EQ('3',  buf[4]);
-  ASSERT_EQ('4',  buf[5]);
-  ASSERT_EQ('\0', buf[6]);
+  ASSERT_STREQ("a01234", buf);
   ASSERT_EQ('A',  buf[7]);
   ASSERT_EQ('A',  buf[8]);
   ASSERT_EQ('A',  buf[9]);
@@ -343,16 +339,7 @@
   buf[1] = '\0';
   char* res = strncat(buf, "01234567", 8);
   ASSERT_EQ(buf, res);
-  ASSERT_EQ('a',  buf[0]);
-  ASSERT_EQ('0',  buf[1]);
-  ASSERT_EQ('1',  buf[2]);
-  ASSERT_EQ('2',  buf[3]);
-  ASSERT_EQ('3',  buf[4]);
-  ASSERT_EQ('4',  buf[5]);
-  ASSERT_EQ('5', buf[6]);
-  ASSERT_EQ('6',  buf[7]);
-  ASSERT_EQ('7',  buf[8]);
-  ASSERT_EQ('\0',  buf[9]);
+  ASSERT_STREQ("a01234567", buf);
 }
 
 TEST(string, strncat5) {
@@ -362,16 +349,7 @@
   buf[1] = '\0';
   char* res = strncat(buf, "01234567", 9);
   ASSERT_EQ(buf, res);
-  ASSERT_EQ('a',  buf[0]);
-  ASSERT_EQ('0',  buf[1]);
-  ASSERT_EQ('1',  buf[2]);
-  ASSERT_EQ('2',  buf[3]);
-  ASSERT_EQ('3',  buf[4]);
-  ASSERT_EQ('4',  buf[5]);
-  ASSERT_EQ('5', buf[6]);
-  ASSERT_EQ('6',  buf[7]);
-  ASSERT_EQ('7',  buf[8]);
-  ASSERT_EQ('\0',  buf[9]);
+  ASSERT_STREQ("a01234567", buf);
 }
 
 TEST(string, strchr_with_0) {
@@ -381,6 +359,24 @@
   EXPECT_TRUE(strchr(buf, '\0') == (buf + strlen(s)));
 }
 
+TEST(string, strchr_multiple) {
+  char str[128];
+  memset(str, 'a', sizeof(str) - 1);
+  str[sizeof(str)-1] = '\0';
+
+  // Verify that strchr finds the first occurrence of 'a' in a string
+  // filled with 'a' characters. Iterate over the string putting
+  // non 'a' characters at the front of the string during each iteration
+  // and continue to verify that strchr can find the first occurrence
+  // properly. The idea is to cover all possible alignments of the location
+  // of the first occurrence of the 'a' character and which includes
+  // other 'a' characters close by.
+  for (size_t i = 0; i < sizeof(str) - 1; i++) {
+    EXPECT_EQ(&str[i], strchr(str, 'a'));
+    str[i] = 'b';
+  }
+}
+
 TEST(string, strchr) {
   int seek_char = random() & 255;
 
@@ -451,6 +447,32 @@
   }
 }
 
+TEST(string, stpcpy) {
+  StringTestState<char> state(SMALL);
+  for (size_t j = 0; j < POS_ITER; j++) {
+    state.NewIteration();
+
+    size_t pos = random() % state.MAX_LEN;
+
+    memset(state.ptr1, '\2', pos);
+    state.ptr1[pos] = '\0';
+    state.ptr1[state.MAX_LEN - 1] = '\0';
+
+    memcpy(state.ptr, state.ptr1, state.MAX_LEN);
+
+    memset(state.ptr2, '\1', state.MAX_LEN);
+    state.ptr2[state.MAX_LEN - 1] = '\0';
+
+    memset(state.ptr + state.MAX_LEN, '\1', state.MAX_LEN);
+    memcpy(state.ptr + state.MAX_LEN, state.ptr1, pos + 1);
+    state.ptr[2 * state.MAX_LEN - 1] = '\0';
+
+    ASSERT_TRUE(stpcpy(state.ptr2, state.ptr1) == state.ptr2 + strlen(state.ptr1));
+    ASSERT_FALSE((memcmp(state.ptr1, state.ptr, state.MAX_LEN)) != 0 ||
+                 (memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN) != 0));
+  }
+}
+
 TEST(string, strcpy) {
   StringTestState<char> state(SMALL);
   for (size_t j = 0; j < POS_ITER; j++) {
@@ -477,9 +499,8 @@
   }
 }
 
-
-#if __BIONIC__
 TEST(string, strlcat) {
+#if defined(__BIONIC__)
   StringTestState<char> state(SMALL);
   for (size_t i = 0; i < state.n; i++) {
     for (size_t j = 0; j < POS_ITER; j++) {
@@ -504,11 +525,13 @@
       ASSERT_TRUE(memcmp(state.ptr, state.ptr2, state.MAX_LEN + state.len[i]) == 0);
     }
   }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
-#if __BIONIC__
 TEST(string, strlcpy) {
+#if defined(__BIONIC__)
   StringTestState<char> state(SMALL);
   for (size_t j = 0; j < POS_ITER; j++) {
     state.NewIteration();
@@ -539,8 +562,10 @@
     ASSERT_FALSE((memcmp(state.ptr1, state.ptr, state.MAX_LEN) != 0) ||
                  (memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN) != 0));
   }
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-#endif
 
 TEST(string, strncat) {
   StringTestState<char> state(SMALL);
@@ -605,30 +630,81 @@
   }
 }
 
+TEST(string, stpncpy) {
+  StringTestState<char> state(SMALL);
+  for (size_t j = 0; j < ITER; j++) {
+    state.NewIteration();
+
+    // Choose a random value to fill the string, except \0 (string terminator),
+    // or \1 (guarantees it's different from anything in ptr2).
+    memset(state.ptr1, (random() % 254) + 2, state.MAX_LEN);
+    // Choose a random size for our src buffer.
+    size_t ptr1_len = random() % state.MAX_LEN;
+    state.ptr1[ptr1_len] = '\0';
+    // Copy ptr1 into ptr, used to verify that ptr1 does not get modified.
+    memcpy(state.ptr, state.ptr1, state.MAX_LEN);
+    // Init ptr2 to a set value.
+    memset(state.ptr2, '\1', state.MAX_LEN);
+
+    // Choose a random amount of data to copy.
+    size_t copy_len = random() % state.MAX_LEN;
+
+    // Set the second half of ptr to the expected pattern in ptr2.
+    memset(state.ptr + state.MAX_LEN, '\1', state.MAX_LEN);
+    memcpy(state.ptr + state.MAX_LEN, state.ptr1, copy_len);
+    size_t expected_end;
+    if (copy_len > ptr1_len) {
+      memset(state.ptr + state.MAX_LEN + ptr1_len, '\0', copy_len - ptr1_len);
+      expected_end = ptr1_len;
+    } else {
+      expected_end = copy_len;
+    }
+
+    ASSERT_EQ(state.ptr2 + expected_end, stpncpy(state.ptr2, state.ptr1, copy_len));
+
+    // Verify ptr1 was not modified.
+    ASSERT_EQ(0, memcmp(state.ptr1, state.ptr, state.MAX_LEN));
+    // Verify ptr2 contains the expected data.
+    ASSERT_EQ(0, memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN));
+  }
+}
+
 TEST(string, strncpy) {
   StringTestState<char> state(SMALL);
   for (size_t j = 0; j < ITER; j++) {
     state.NewIteration();
 
-    memset(state.ptr1, random() & 255, state.MAX_LEN);
-    state.ptr1[random () % state.MAX_LEN] = '\0';
+    // Choose a random value to fill the string, except \0 (string terminator),
+    // or \1 (guarantees it's different from anything in ptr2).
+    memset(state.ptr1, (random() % 254) + 2, state.MAX_LEN);
+    // Choose a random size for our src buffer.
+    size_t ptr1_len = random() % state.MAX_LEN;
+    state.ptr1[ptr1_len] = '\0';
+    // Copy ptr1 into ptr, used to verify that ptr1 does not get modified.
     memcpy(state.ptr, state.ptr1, state.MAX_LEN);
-
+    // Init ptr2 to a set value.
     memset(state.ptr2, '\1', state.MAX_LEN);
 
-    size_t pos;
-    if (memchr(state.ptr1, 0, state.MAX_LEN)) {
-      pos = strlen(state.ptr1);
+    // Choose a random amount of data to copy.
+    size_t copy_len = random() % state.MAX_LEN;
+
+    // Set the second half of ptr to the expected pattern in ptr2.
+    memset(state.ptr + state.MAX_LEN, '\1', state.MAX_LEN);
+    memcpy(state.ptr + state.MAX_LEN, state.ptr1, copy_len);
+    size_t expected_end;
+    if (copy_len > ptr1_len) {
+      memset(state.ptr + state.MAX_LEN + ptr1_len, '\0', copy_len - ptr1_len);
+      expected_end = ptr1_len;
     } else {
-      pos = state.MAX_LEN - 1;
+      expected_end = copy_len;
     }
 
-    memset(state.ptr + state.MAX_LEN, '\0', state.MAX_LEN);
-    memcpy(state.ptr + state.MAX_LEN, state.ptr1, pos + 1);
+    ASSERT_EQ(state.ptr2 + expected_end, stpncpy(state.ptr2, state.ptr1, copy_len));
 
-    ASSERT_TRUE(strncpy(state.ptr2, state.ptr1, state.MAX_LEN) == state.ptr2);
-    ASSERT_FALSE(memcmp(state.ptr1, state.ptr, state.MAX_LEN) != 0 ||
-                 memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN) != 0);
+    // Verify ptr1 was not modified.
+    ASSERT_EQ(0, memcmp(state.ptr1, state.ptr, state.MAX_LEN));
+    // Verify ptr2 contains the expected data.
+    ASSERT_EQ(0, memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN));
   }
 }
 
@@ -687,6 +763,14 @@
   }
 }
 
+TEST(string, memchr_zero) {
+  uint8_t* buffer;
+  ASSERT_EQ(0, posix_memalign(reinterpret_cast<void**>(&buffer), 64, 64));
+  memset(buffer, 10, 64);
+  ASSERT_TRUE(NULL == memchr(buffer, 5, 0));
+  ASSERT_TRUE(NULL == memchr(buffer, 10, 0));
+}
+
 TEST(string, memrchr) {
   int seek_char = random() & 255;
   StringTestState<char> state(SMALL);
@@ -732,35 +816,6 @@
   }
 }
 
-#if defined(__BIONIC__)
-extern "C" int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n);
-
-TEST(string, __memcmp16) {
-  StringTestState<unsigned short> state(SMALL);
-
-  for (size_t i = 0; i < state.n; i++) {
-    for (size_t j = 0; j < POS_ITER; j++) {
-      state.NewIteration();
-
-      unsigned short mask = 0xffff;
-      unsigned short c1 = rand() & mask;
-      unsigned short c2 = rand() & mask;
-
-      std::fill(state.ptr1, state.ptr1 + state.MAX_LEN, c1);
-      std::fill(state.ptr2, state.ptr2 + state.MAX_LEN, c1);
-
-      int pos = (state.len[i] == 0) ? 0 : (random() % state.len[i]);
-      state.ptr2[pos] = c2;
-
-      int expected = (static_cast<unsigned short>(c1) - static_cast<unsigned short>(c2));
-      int actual = __memcmp16(state.ptr1, state.ptr2, (size_t) state.MAX_LEN);
-
-      ASSERT_EQ(expected, actual);
-    }
-  }
-}
-#endif
-
 TEST(string, wmemcmp) {
   StringTestState<wchar_t> state(SMALL);
 
@@ -850,6 +905,85 @@
   }
 }
 
+TEST(string, memmove_cache_size) {
+  size_t len = 600000;
+  int max_alignment = 31;
+  int alignments[] = {0, 5, 11, 29, 30};
+  char* ptr = reinterpret_cast<char*>(malloc(sizeof(char) * len));
+  char* ptr1 = reinterpret_cast<char*>(malloc(2 * sizeof(char) * len));
+  char* glob_ptr2 = reinterpret_cast<char*>(malloc(2 * sizeof(char) * len + max_alignment));
+  size_t pos = 64;
+
+  ASSERT_TRUE(ptr != NULL);
+  ASSERT_TRUE(ptr1 != NULL);
+  ASSERT_TRUE(glob_ptr2 != NULL);
+
+  for (int i = 0; i < 5; i++) {
+    char* ptr2 = glob_ptr2 + alignments[i];
+    memset(ptr1, random() & 255, 2 * len);
+    memset(ptr1, random() & 255, len);
+    memcpy(ptr2, ptr1, 2 * len);
+    memcpy(ptr, ptr1, len);
+    memcpy(ptr1 + pos, ptr, len);
+
+    ASSERT_TRUE(memmove(ptr2 + pos, ptr, len) == ptr2 + pos);
+    ASSERT_EQ(0, memcmp(ptr2, ptr1, 2 * len));
+  }
+  free(ptr);
+  free(ptr1);
+  free(glob_ptr2);
+}
+
+static void verify_memmove(char* src_copy, char* dst, char* src, size_t size) {
+  memset(dst, 0, size);
+  memcpy(src, src_copy, size);
+  ASSERT_EQ(dst, memmove(dst, src, size));
+  ASSERT_EQ(0, memcmp(dst, src_copy, size));
+}
+
+#define MEMMOVE_DATA_SIZE (1024*1024*3)
+
+TEST(string, memmove_check) {
+  char* buffer = reinterpret_cast<char*>(malloc(MEMMOVE_DATA_SIZE));
+  ASSERT_TRUE(buffer != NULL);
+
+  char* src_data = reinterpret_cast<char*>(malloc(MEMMOVE_DATA_SIZE));
+  ASSERT_TRUE(src_data != NULL);
+  // Initialize to a known pattern to copy into src for each test and
+  // to compare dst against.
+  for (size_t i = 0; i < MEMMOVE_DATA_SIZE; i++) {
+    src_data[i] = (i + 1) % 255;
+  }
+
+  // Check all different dst offsets between 0 and 127 inclusive.
+  char* src = buffer;
+  for (size_t i = 0; i < 127; i++) {
+    char* dst = buffer + 256 + i;
+    // Small copy.
+    verify_memmove(src_data, dst, src, 1024);
+
+    // Medium copy.
+    verify_memmove(src_data, dst, src, 64 * 1024);
+
+    // Medium copy.
+    verify_memmove(src_data, dst, src, 1024 * 1024 + 128 * 1024);
+  }
+
+  // Check all leftover size offsets between 1 and 127 inclusive.
+  char* dst = buffer + 256;
+  src = buffer;
+  for (size_t size = 1; size < 127; size++) {
+    // Small copy.
+    verify_memmove(src_data, dst, src, 1024);
+
+    // Medium copy.
+    verify_memmove(src_data, dst, src, 64 * 1024);
+
+    // Large copy.
+    verify_memmove(src_data, dst, src, 1024 * 1024 + 128 * 1024);
+  }
+}
+
 TEST(string, bcopy) {
   StringTestState<char> state(LARGE);
   for (size_t i = 0; i < state.n; i++) {
@@ -905,6 +1039,22 @@
   RunSrcDstBufferOverreadTest(DoMemcpyTest);
 }
 
+static void DoMemmoveTest(uint8_t* src, uint8_t* dst, size_t len) {
+  memset(src, (len % 255) + 1, len);
+  memset(dst, 0, len);
+
+  ASSERT_EQ(dst, memmove(dst, src, len));
+  ASSERT_TRUE(memcmp(src, dst, len) == 0);
+}
+
+TEST(string, memmove_align) {
+  RunSrcDstBufferAlignTest(LARGE, DoMemmoveTest);
+}
+
+TEST(string, memmove_overread) {
+  RunSrcDstBufferOverreadTest(DoMemmoveTest);
+}
+
 static void DoMemsetTest(uint8_t* buf, size_t len) {
   for (size_t i = 0; i < len; i++) {
     buf[i] = 0;
@@ -955,6 +1105,25 @@
   RunSrcDstBufferOverreadTest(DoStrcpyTest);
 }
 
+static void DoStpcpyTest(uint8_t* src, uint8_t* dst, size_t len) {
+  if (len >= 1) {
+    memset(src, (32 + (len % 96)), len - 1);
+    src[len-1] = '\0';
+    memset(dst, 0, len);
+    ASSERT_EQ(dst+len-1, reinterpret_cast<uint8_t*>(stpcpy(reinterpret_cast<char*>(dst),
+                                                           reinterpret_cast<char*>(src))));
+    ASSERT_TRUE(memcmp(src, dst, len) == 0);
+  }
+}
+
+TEST(string, stpcpy_align) {
+  RunSrcDstBufferAlignTest(LARGE, DoStpcpyTest);
+}
+
+TEST(string, stpcpy_overread) {
+  RunSrcDstBufferOverreadTest(DoStpcpyTest);
+}
+
 // Use our own incrementer to cut down on the total number of calls.
 static size_t LargeSetIncrement(size_t len) {
   if (len >= 4096) {
@@ -1092,3 +1261,29 @@
 TEST(string, memcmp_overread) {
   RunCmpBufferOverreadTest(DoMemcmpTest, DoMemcmpFailTest);
 }
+
+static void DoStrchrTest(uint8_t* buf, size_t len) {
+  if (len >= 1) {
+    char value = 32 + (len % 96);
+    char search_value = 33 + (len % 96);
+    memset(buf, value, len - 1);
+    buf[len-1] = '\0';
+    ASSERT_EQ(NULL, strchr(reinterpret_cast<char*>(buf), search_value));
+    ASSERT_EQ(reinterpret_cast<char*>(&buf[len-1]), strchr(reinterpret_cast<char*>(buf), '\0'));
+    if (len >= 2) {
+      buf[0] = search_value;
+      ASSERT_EQ(reinterpret_cast<char*>(&buf[0]), strchr(reinterpret_cast<char*>(buf), search_value));
+      buf[0] = value;
+      buf[len-2] = search_value;
+      ASSERT_EQ(reinterpret_cast<char*>(&buf[len-2]), strchr(reinterpret_cast<char*>(buf), search_value));
+    }
+  }
+}
+
+TEST(string, strchr_align) {
+  RunSingleBufferAlignTest(MEDIUM, DoStrchrTest);
+}
+
+TEST(string, strchr_overread) {
+  RunSingleBufferOverreadTest(DoStrchrTest);
+}
diff --git a/tests/stubs_test.cpp b/tests/stubs_test.cpp
index 2e1acc1..9b0c231 100644
--- a/tests/stubs_test.cpp
+++ b/tests/stubs_test.cpp
@@ -23,8 +23,7 @@
 #include <limits.h>
 #include <unistd.h>
 
-#if __BIONIC__
-
+#if defined(__BIONIC__)
 #define CHECK_GETPWNAM_FOR(username, uid, uid_type) \
     SCOPED_TRACE(username); \
     ASSERT_NO_FATAL_FAILURE(check_getpwnam(username, uid, uid_type));
@@ -42,6 +41,10 @@
   EXPECT_STREQ(username, pwd->pw_name);
   EXPECT_EQ(uid, pwd->pw_uid);
   EXPECT_EQ(uid, pwd->pw_gid);
+  ASSERT_EQ(NULL, pwd->pw_passwd);
+#ifdef __LP64__
+  ASSERT_EQ(NULL, pwd->pw_gecos);
+#endif
 
   if (uid_type == TYPE_SYSTEM) {
     EXPECT_STREQ("/", pwd->pw_dir);
@@ -51,6 +54,10 @@
 
   EXPECT_STREQ("/system/bin/sh", pwd->pw_shell);
 }
+#else
+#define CHECK_GETPWNAM_FOR(username, uid, uid_type) \
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
 
 TEST(getpwnam, system_id_root) {
   CHECK_GETPWNAM_FOR("root", 0, TYPE_SYSTEM);
@@ -104,5 +111,3 @@
 TEST(getpwnam, app_id_u1_i0) {
   CHECK_GETPWNAM_FOR("u1_i0", 199000, TYPE_APP);
 }
-
-#endif /* __BIONIC__ */
diff --git a/tests/sys_epoll_test.cpp b/tests/sys_epoll_test.cpp
index e4e047b..6e7a807 100644
--- a/tests/sys_epoll_test.cpp
+++ b/tests/sys_epoll_test.cpp
@@ -17,7 +17,10 @@
 #include <gtest/gtest.h>
 
 #include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
 #include <sys/epoll.h>
+#include <unistd.h>
 
 TEST(sys_epoll, smoke) {
   int epoll_fd = epoll_create(1);
@@ -36,3 +39,30 @@
   sigaddset(&ss, SIGPIPE);
   ASSERT_EQ(0, epoll_pwait(epoll_fd, events, 1, 1, &ss));
 }
+
+TEST(sys_epoll, epoll_event_data) {
+  int epoll_fd = epoll_create(1);
+  ASSERT_NE(-1, epoll_fd) << strerror(errno);
+
+  int fds[2];
+  ASSERT_NE(-1, pipe(fds));
+
+  const uint64_t expected = 0x123456789abcdef0;
+
+  // Get ready to poll on read end of pipe.
+  epoll_event ev;
+  ev.events = EPOLLIN;
+  ev.data.u64 = expected;
+  ASSERT_NE(-1, epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fds[0], &ev));
+
+  // Ensure there's something in the pipe.
+  ASSERT_EQ(1, write(fds[1], "\n", 1));
+
+  // Poll.
+  epoll_event events[1];
+  ASSERT_EQ(1, epoll_wait(epoll_fd, events, 1, 1));
+  ASSERT_EQ(expected, events[0].data.u64);
+
+  close(fds[0]);
+  close(fds[1]);
+}
diff --git a/tests/sys_mman_test.cpp b/tests/sys_mman_test.cpp
index 57067d7..75ccfa3 100644
--- a/tests/sys_mman_test.cpp
+++ b/tests/sys_mman_test.cpp
@@ -17,14 +17,158 @@
 #include <gtest/gtest.h>
 
 #include <sys/mman.h>
+#include <sys/types.h>
 #include <unistd.h>
 
-TEST(sys_mman, mmap_negative) {
-  off_t off = -sysconf(_SC_PAGESIZE); // Aligned but negative.
-  ASSERT_EQ(MAP_FAILED, mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, off));
+#include "TemporaryFile.h"
+
+TEST(sys_mman, mmap_std) {
+  void* map = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+  ASSERT_NE(MAP_FAILED, map);
+  ASSERT_EQ(0, munmap(map, 4096));
 }
 
-TEST(sys_mman, mmap64_negative) {
-  off64_t off64 = -sysconf(_SC_PAGESIZE); // Aligned but negative.
-  ASSERT_EQ(MAP_FAILED, mmap64(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, off64));
+TEST(sys_mman, mmap64_std) {
+  void* map = mmap64(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+  ASSERT_NE(MAP_FAILED, map);
+  ASSERT_EQ(0, munmap(map, 4096));
+}
+
+TEST(sys_mman, mmap_file_bad_offset) {
+  TemporaryFile tf;
+
+  void* map = mmap(NULL, 100, PROT_READ, MAP_SHARED, tf.fd, 1);
+  ASSERT_EQ(MAP_FAILED, map);
+}
+
+TEST(sys_mman, mmap64_file_bad_offset) {
+  TemporaryFile tf;
+
+  void* map = mmap64(NULL, 100, PROT_READ, MAP_SHARED, tf.fd, 1);
+  ASSERT_EQ(MAP_FAILED, map);
+}
+
+#define STR_SSIZE(str) static_cast<ssize_t>(sizeof(str))
+
+#define STRING_MSG  "012345678\nabcdefgh\n"
+#define INITIAL_MSG "000000000\n00000000\n"
+
+TEST(sys_mman, mmap_file_read) {
+  TemporaryFile tf;
+
+  ASSERT_EQ(STR_SSIZE(STRING_MSG), write(tf.fd, STRING_MSG, sizeof(STRING_MSG)));
+
+  void* map = mmap(NULL, sizeof(STRING_MSG), PROT_READ, MAP_SHARED, tf.fd, 0);
+  ASSERT_NE(MAP_FAILED, map);
+
+  char* data = reinterpret_cast<char*>(map);
+  ASSERT_STREQ(STRING_MSG, data);
+
+  ASSERT_EQ(0, munmap(map, sizeof(STRING_MSG)));
+}
+
+TEST(sys_mman, mmap_file_write) {
+  TemporaryFile tf;
+
+  ASSERT_EQ(STR_SSIZE(INITIAL_MSG), write(tf.fd, INITIAL_MSG, sizeof(INITIAL_MSG)));
+  lseek(tf.fd, 0, SEEK_SET);
+
+  void* map = mmap(NULL, sizeof(STRING_MSG), PROT_WRITE, MAP_SHARED, tf.fd, 0);
+  ASSERT_NE(MAP_FAILED, map);
+  close(tf.fd);
+
+  memcpy(map, STRING_MSG, sizeof(STRING_MSG));
+
+  ASSERT_EQ(0, munmap(map, sizeof(STRING_MSG)));
+
+  tf.reopen();
+  char buf[sizeof(STRING_MSG)];
+  memset(buf, 0, sizeof(STRING_MSG));
+  ASSERT_EQ(STR_SSIZE(STRING_MSG), read(tf.fd, buf, sizeof(STRING_MSG)));
+
+  ASSERT_STREQ(STRING_MSG, buf);
+}
+
+#define PAGE0_MSG "00PAGE00"
+#define PAGE1_MSG "111PAGE111"
+#define PAGE2_MSG "2222PAGE2222"
+#define END_MSG "E"
+
+TEST(sys_mman, mmap_file_read_at_offset) {
+  TemporaryFile tf;
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+
+  // Create the file with three pages worth of data.
+  ASSERT_EQ(STR_SSIZE(PAGE0_MSG), write(tf.fd, PAGE0_MSG, sizeof(PAGE0_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, pagesize, SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(PAGE1_MSG), write(tf.fd, PAGE1_MSG, sizeof(PAGE1_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, 2 * pagesize, SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(PAGE2_MSG), write(tf.fd, PAGE2_MSG, sizeof(PAGE2_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, 3 * pagesize - sizeof(END_MSG), SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(END_MSG), write(tf.fd, END_MSG, sizeof(END_MSG)));
+
+  ASSERT_NE(-1, lseek(tf.fd, 0, SEEK_SET));
+
+  void* map = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, tf.fd, pagesize);
+  ASSERT_NE(MAP_FAILED, map);
+
+  char* data = reinterpret_cast<char*>(map);
+  ASSERT_STREQ(PAGE1_MSG, data);
+
+  ASSERT_EQ(0, munmap(map, pagesize));
+
+  map = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, tf.fd, 2 * pagesize);
+  ASSERT_NE(MAP_FAILED, map);
+
+  data = reinterpret_cast<char*>(map);
+  ASSERT_STREQ(PAGE2_MSG, data);
+  ASSERT_STREQ(END_MSG, data+pagesize-sizeof(END_MSG));
+
+  ASSERT_EQ(0, munmap(map, pagesize));
+}
+
+#define NEWPAGE1_MSG "1NEW1PAGE1"
+#define NEWPAGE2_MSG "22NEW22PAGE22"
+
+TEST(sys_mman, mmap_file_write_at_offset) {
+  TemporaryFile tf;
+  size_t pagesize = sysconf(_SC_PAGESIZE);
+
+  // Create the file with three pages worth of data.
+  ASSERT_EQ(STR_SSIZE(PAGE0_MSG), write(tf.fd, PAGE0_MSG, sizeof(PAGE0_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, pagesize, SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(PAGE1_MSG), write(tf.fd, PAGE1_MSG, sizeof(PAGE1_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, 2 * pagesize, SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(PAGE2_MSG), write(tf.fd, PAGE2_MSG, sizeof(PAGE2_MSG)));
+  ASSERT_NE(-1, lseek(tf.fd, 3 * pagesize - sizeof(END_MSG), SEEK_SET));
+  ASSERT_EQ(STR_SSIZE(END_MSG), write(tf.fd, END_MSG, sizeof(END_MSG)));
+
+  ASSERT_NE(-1, lseek(tf.fd, 0, SEEK_SET));
+
+  void* map = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, pagesize);
+  ASSERT_NE(MAP_FAILED, map);
+  close(tf.fd);
+
+  memcpy(map, NEWPAGE1_MSG, sizeof(NEWPAGE1_MSG));
+  ASSERT_EQ(0, munmap(map, pagesize));
+
+  tf.reopen();
+  map = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, 2 * pagesize);
+  ASSERT_NE(MAP_FAILED, map);
+  close(tf.fd);
+
+  memcpy(map, NEWPAGE2_MSG, sizeof(NEWPAGE2_MSG));
+  ASSERT_EQ(0, munmap(map, pagesize));
+
+  tf.reopen();
+  char buf[pagesize];
+  ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
+  ASSERT_STREQ(PAGE0_MSG, buf);
+  ASSERT_NE(-1, lseek(tf.fd, pagesize, SEEK_SET));
+  ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
+  ASSERT_STREQ(NEWPAGE1_MSG, buf);
+  ASSERT_NE(-1, lseek(tf.fd, 2 * pagesize, SEEK_SET));
+  ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
+  ASSERT_STREQ(NEWPAGE2_MSG, buf);
+  ASSERT_STREQ(END_MSG, buf+pagesize-sizeof(END_MSG));
 }
diff --git a/tests/sys_resource_test.cpp b/tests/sys_resource_test.cpp
index bd974cb..d6d99a0 100644
--- a/tests/sys_resource_test.cpp
+++ b/tests/sys_resource_test.cpp
@@ -18,7 +18,7 @@
 
 #include <sys/resource.h>
 
-#if __GLIBC__
+#if defined(__GLIBC__)
 /* The host glibc we're currently building with doesn't have prlimit64 yet. */
 static int prlimit64(pid_t, int resource, const struct rlimit64* new_limit, struct rlimit64* old_limit) {
   if (new_limit != NULL) {
@@ -30,7 +30,7 @@
 #endif
 
 TEST(sys_resource, smoke) {
-#if __LP64__ || __GLIBC__
+#if defined(__LP64__) || defined(__GLIBC__)
   ASSERT_EQ(sizeof(rlimit), sizeof(rlimit64));
   ASSERT_EQ(8U, sizeof(rlim_t));
 #else
diff --git a/tests/sys_select_test.cpp b/tests/sys_select_test.cpp
index 57afc9b..c1732ee 100644
--- a/tests/sys_select_test.cpp
+++ b/tests/sys_select_test.cpp
@@ -17,8 +17,11 @@
 #include <gtest/gtest.h>
 
 #include <errno.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <sys/select.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 TEST(sys_select, fd_set_smoke) {
   fd_set fds;
@@ -42,6 +45,32 @@
   EXPECT_FALSE(FD_ISSET(1, &fds));
 }
 
+#define DELAY_MSG "1234"
+
+static void DelayedWrite(int* pid, int* fd) {
+  int fds[2];
+  ASSERT_EQ(0, pipe(fds));
+
+  if ((*pid = fork()) == 0) {
+    close(fds[0]);
+    usleep(5000);
+    EXPECT_EQ(5, write(fds[1], DELAY_MSG, sizeof(DELAY_MSG)));
+    close(fds[1]);
+    exit(0);
+  }
+  ASSERT_LT(0, *pid);
+  close(fds[1]);
+
+  *fd = fds[0];
+}
+
+static void DelayedWriteCleanup(int pid, int fd) {
+  char buf[sizeof(DELAY_MSG)];
+  ASSERT_EQ(static_cast<ssize_t>(sizeof(DELAY_MSG)), read(fd, buf, sizeof(DELAY_MSG)));
+  ASSERT_STREQ(DELAY_MSG, buf);
+  ASSERT_EQ(pid, waitpid(pid, NULL, 0));
+}
+
 TEST(sys_select, select_smoke) {
   fd_set r;
   FD_ZERO(&r);
@@ -71,8 +100,17 @@
 
   // Valid timeout...
   tv.tv_sec = 1;
-  ASSERT_EQ(2, select(max, &r, &w, &e, &tv));
-  ASSERT_NE(0, tv.tv_usec); // ...which got updated.
+  int pid, fd;
+  DelayedWrite(&pid, &fd);
+
+  FD_ZERO(&r);
+  FD_SET(fd, &r);
+  ASSERT_EQ(1, select(fd+1, &r, NULL, NULL, &tv));
+  // Both tv_sec and tv_nsec should have been updated.
+  ASSERT_EQ(0, tv.tv_sec);
+  ASSERT_NE(0, tv.tv_usec);
+
+  DelayedWriteCleanup(pid, fd);
 }
 
 TEST(sys_select, pselect_smoke) {
@@ -108,6 +146,15 @@
 
   // Valid timeout...
   tv.tv_sec = 1;
-  ASSERT_EQ(2, pselect(max, &r, &w, &e, &tv, &ss));
-  ASSERT_EQ(0, tv.tv_nsec); // ...which did _not_ get updated.
+  int pid, fd;
+  DelayedWrite(&pid, &fd);
+
+  FD_ZERO(&r);
+  FD_SET(fd, &r);
+  ASSERT_EQ(1, pselect(fd+1, &r, NULL, NULL, &tv, NULL));
+  // Neither tv_sec nor tv_nsec should have been updated.
+  ASSERT_EQ(1, tv.tv_sec);
+  ASSERT_EQ(0, tv.tv_nsec);
+
+  DelayedWriteCleanup(pid, fd);
 }
diff --git a/tests/sys_sendfile_test.cpp b/tests/sys_sendfile_test.cpp
index bf23d3d..3d6b5cc 100644
--- a/tests/sys_sendfile_test.cpp
+++ b/tests/sys_sendfile_test.cpp
@@ -42,7 +42,6 @@
   ASSERT_STREQ("ll", buf);
 }
 
-#if __BIONIC__
 TEST(sys_sendfile, sendfile64) {
   TemporaryFile src_file;
   ASSERT_EQ(5, TEMP_FAILURE_RETRY(write(src_file.fd, "hello", 5)));
@@ -61,4 +60,3 @@
   ASSERT_EQ(2, TEMP_FAILURE_RETRY(read(dst_file.fd, &buf, 2)));
   ASSERT_STREQ("ll", buf);
 }
-#endif
diff --git a/tests/sys_socket_test.cpp b/tests/sys_socket_test.cpp
new file mode 100644
index 0000000..0bde024
--- /dev/null
+++ b/tests/sys_socket_test.cpp
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <fcntl.h>
+
+#if defined(__BIONIC__)
+  #define ACCEPT4_SUPPORTED 1
+  #define RECVMMSG_SUPPORTED 1
+  #define SENDMMSG_SUPPORTED 1
+#elif defined(__GLIBC_PREREQ)
+  #if __GLIBC_PREREQ(2, 9)
+    #define ACCEPT4_SUPPORTED 1
+  #endif
+  #if __GLIBC_PREREQ(2, 12)
+    #define RECVMMSG_SUPPORTED 1
+  #endif
+  #if __GLIBC_PREREQ(2, 14)
+    #define SENDMMSG_SUPPORTED 1
+  #endif
+#endif
+
+#if defined(ACCEPT4_SUPPORTED) || defined(RECVMMSG_SUPPORTED) || defined(SENDMMSG_SUPPORTED)
+
+#define SOCK_PATH "test"
+
+static void* ConnectFn(void* data) {
+  bool (*callback_fn)(int) = reinterpret_cast<bool (*)(int)>(data);
+  void* return_value = NULL;
+
+  int fd = socket(PF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
+  if (fd < 0) {
+    GTEST_LOG_(ERROR) << "socket call failed: " << strerror(errno);
+    return reinterpret_cast<void*>(-1);
+  }
+
+  struct sockaddr_un addr;
+  memset(&addr, 0, sizeof(addr));
+  addr.sun_family = AF_UNIX;
+  addr.sun_path[0] = '\0';
+  strcpy(addr.sun_path + 1, SOCK_PATH);
+
+  if (connect(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) < 0) {
+    GTEST_LOG_(ERROR) << "connect call failed: " << strerror(errno);
+    return_value = reinterpret_cast<void*>(-1);
+  }
+  else if (callback_fn != NULL && !callback_fn(fd)) {
+    return_value = reinterpret_cast<void*>(-1);
+  }
+
+  close(fd);
+
+  return return_value;
+}
+
+static void RunTest(void (*test_fn)(struct sockaddr_un*, int),
+                    bool (*callback_fn)(int fd)) {
+  int fd = socket(PF_UNIX, SOCK_SEQPACKET, 0);
+  ASSERT_NE(fd, -1) << strerror(errno);
+
+  struct sockaddr_un addr;
+  memset(&addr, 0, sizeof(addr));
+  addr.sun_family = AF_UNIX;
+  addr.sun_path[0] = '\0';
+  strcpy(addr.sun_path + 1, SOCK_PATH);
+
+  ASSERT_NE(-1, bind(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr))) << strerror(errno);
+
+  ASSERT_NE(-1, listen(fd, 1)) << strerror(errno);
+
+  pthread_t thread;
+  ASSERT_EQ(0, pthread_create(&thread, NULL, ConnectFn, reinterpret_cast<void*>(callback_fn)));
+
+  fd_set read_set;
+  FD_ZERO(&read_set);
+  FD_SET(fd, &read_set);
+  timeval tv;
+  tv.tv_sec = 5;
+  tv.tv_usec = 0;
+  ASSERT_LT(0, select(fd+1, &read_set, NULL, NULL, &tv));
+
+  test_fn(&addr, fd);
+
+  void* ret_val;
+  ASSERT_EQ(0, pthread_join(thread, &ret_val));
+  ASSERT_EQ(NULL, ret_val);
+
+  close(fd);
+}
+#endif
+
+TEST(sys_socket, accept4_error) {
+#if defined(ACCEPT4_SUPPORTED)
+  ASSERT_EQ(-1, accept4(-1, NULL, NULL, 0));
+  ASSERT_EQ(EBADF, errno);
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
+
+#if defined(ACCEPT4_SUPPORTED)
+static void TestAccept4(struct sockaddr_un* addr, int fd) {
+  socklen_t len = sizeof(*addr);
+  int fd_acc = accept4(fd, reinterpret_cast<struct sockaddr*>(addr), &len, SOCK_CLOEXEC);
+  ASSERT_NE(fd_acc, -1) << strerror(errno);
+
+  // Check that the flag was set properly.
+  ASSERT_EQ(FD_CLOEXEC, fcntl(fd_acc, F_GETFD) & FD_CLOEXEC);
+
+  close(fd_acc);
+}
+#endif
+
+TEST(sys_socket, accept4_smoke) {
+#if defined(ACCEPT4_SUPPORTED)
+  RunTest(TestAccept4, NULL);
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
+
+#if defined(RECVMMSG_SUPPORTED)
+const char* g_RecvMsgs[] = {
+  "RECVMMSG_ONE",
+  "RECVMMSG_TWO",
+  "RECVMMSG_THREE",
+};
+#define NUM_RECV_MSGS (sizeof(g_RecvMsgs)/sizeof(const char*))
+
+static bool SendMultiple(int fd) {
+  for (size_t i = 0; i < NUM_RECV_MSGS; i++) {
+    if (send(fd, g_RecvMsgs[i], strlen(g_RecvMsgs[i]) + 1, 0) < 0) {
+      GTEST_LOG_(ERROR) << "send call failed: " << strerror(errno);
+      return false;
+    }
+  }
+
+  return true;
+}
+
+static void TestRecvMMsg(struct sockaddr_un *addr, int fd) {
+  socklen_t len = sizeof(*addr);
+  int fd_acc = accept(fd, reinterpret_cast<struct sockaddr*>(addr), &len);
+  ASSERT_NE(fd_acc, -1) << strerror(errno);
+
+  struct mmsghdr msgs[NUM_RECV_MSGS];
+  memset(msgs, 0, sizeof(struct mmsghdr)*NUM_RECV_MSGS);
+
+  struct iovec io[NUM_RECV_MSGS];
+  char bufs[NUM_RECV_MSGS][100];
+  for (size_t i = 0; i < NUM_RECV_MSGS; i++) {
+    io[i].iov_base = reinterpret_cast<void*>(bufs[i]);
+    io[i].iov_len = strlen(g_RecvMsgs[i]) + 1;
+
+    msgs[i].msg_hdr.msg_iov = &io[i];
+    msgs[i].msg_hdr.msg_iovlen = 1;
+    msgs[i].msg_len = sizeof(struct msghdr);
+  }
+
+  struct timespec ts;
+  memset(&ts, 0, sizeof(ts));
+  ts.tv_sec = 5;
+  ts.tv_nsec = 0;
+  ASSERT_EQ(NUM_RECV_MSGS,
+            static_cast<size_t>(recvmmsg(fd_acc, msgs, NUM_RECV_MSGS, 0, &ts)))
+           << strerror(errno);
+  for (size_t i = 0; i < NUM_RECV_MSGS; i++) {
+    ASSERT_STREQ(g_RecvMsgs[i], bufs[i]);
+  }
+
+  close(fd_acc);
+}
+#endif
+
+TEST(sys_socket, recvmmsg_smoke) {
+#if defined(RECVMMSG_SUPPORTED)
+  RunTest(TestRecvMMsg, SendMultiple);
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
+
+TEST(sys_socket, recvmmsg_error) {
+#if defined(RECVMMSG_SUPPORTED)
+  ASSERT_EQ(-1, recvmmsg(-1, NULL, 0, 0, NULL));
+  ASSERT_EQ(EBADF, errno);
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
+
+#if defined(SENDMMSG_SUPPORTED)
+const char* g_SendMsgs[] = {
+  "MSG_ONE",
+  "MSG_TWO",
+  "MSG_THREE"
+};
+#define NUM_SEND_MSGS (sizeof(g_SendMsgs)/sizeof(const char*))
+
+static bool SendMMsg(int fd) {
+  struct mmsghdr msgs[NUM_SEND_MSGS];
+  memset(msgs, 0, sizeof(struct mmsghdr)*NUM_SEND_MSGS);
+  struct iovec io[NUM_SEND_MSGS];
+  for (size_t i = 0; i < NUM_SEND_MSGS; i++) {
+    io[i].iov_base = reinterpret_cast<void*>(const_cast<char*>(g_SendMsgs[i]));
+    io[i].iov_len = strlen(g_SendMsgs[i]) + 1;
+    msgs[i].msg_hdr.msg_iov = &io[i];
+    msgs[i].msg_hdr.msg_iovlen = 1;
+    msgs[i].msg_len = sizeof(struct msghdr);
+  }
+
+  if (sendmmsg(fd, msgs, NUM_SEND_MSGS, 0) < 0) {
+    GTEST_LOG_(ERROR) << "sendmmsg call failed: " << strerror(errno);
+    return false;
+  }
+  return true;
+}
+
+static void TestSendMMsg(struct sockaddr_un *addr, int fd) {
+  socklen_t len = sizeof(*addr);
+  int fd_acc = accept(fd, reinterpret_cast<struct sockaddr*>(addr), &len);
+  ASSERT_NE(fd_acc, -1) << strerror(errno);
+
+  fd_set read_set;
+  FD_ZERO(&read_set);
+  FD_SET(fd_acc, &read_set);
+
+  for (size_t i = 0; i < NUM_SEND_MSGS; i++) {
+    timeval tv;
+    tv.tv_sec = 5;
+    tv.tv_usec = 0;
+    ASSERT_LT(0, select(fd_acc+1, &read_set, NULL, NULL, &tv));
+    char buffer[100];
+    ASSERT_EQ(strlen(g_SendMsgs[i]) + 1,
+              static_cast<size_t>(recv(fd_acc, buffer, sizeof(buffer), 0)));
+    ASSERT_STREQ(g_SendMsgs[i], buffer);
+  }
+
+  close(fd_acc);
+}
+#endif
+
+TEST(sys_socket, sendmmsg_smoke) {
+#if defined(SENDMMSG_SUPPORTED)
+  RunTest(TestSendMMsg, SendMMsg);
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
+
+TEST(sys_socket, sendmmsg_error) {
+#if defined(SENDMMSG_SUPPORTED)
+  ASSERT_EQ(-1, sendmmsg(-1, NULL, 0, 0));
+  ASSERT_EQ(EBADF, errno);
+#else
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
+}
diff --git a/tests/sys_stat_test.cpp b/tests/sys_stat_test.cpp
index 176d462..64049ab 100644
--- a/tests/sys_stat_test.cpp
+++ b/tests/sys_stat_test.cpp
@@ -17,6 +17,7 @@
 #include <gtest/gtest.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 
@@ -55,16 +56,29 @@
 }
 
 TEST(sys_stat, mkfifo) {
-  // Racy but probably sufficient way to get a suitable filename.
-  std::string path;
-  {
-    TemporaryFile tf;
-    path = tf.filename;
-  }
+  if (getuid() == 0) {
+    // Racy but probably sufficient way to get a suitable filename.
+    std::string path;
+    {
+      TemporaryFile tf;
+      path = tf.filename;
+    }
 
-  ASSERT_EQ(0, mkfifo(path.c_str(), 0666));
-  struct stat sb;
-  ASSERT_EQ(0, stat(path.c_str(), &sb));
-  ASSERT_TRUE(S_ISFIFO(sb.st_mode));
-  unlink(path.c_str());
+    ASSERT_EQ(0, mkfifo(path.c_str(), 0666));
+    struct stat sb;
+    ASSERT_EQ(0, stat(path.c_str(), &sb));
+    ASSERT_TRUE(S_ISFIFO(sb.st_mode));
+    unlink(path.c_str());
+  } else {
+    GTEST_LOG_(INFO) << "This test only performs a test when run as root.";
+  }
+}
+
+TEST(sys_stat, stat64_lstat64_fstat64) {
+  struct stat64 sb;
+  ASSERT_EQ(0, stat64("/proc/version", &sb));
+  ASSERT_EQ(0, lstat64("/proc/version", &sb));
+  int fd = open("/proc/version", O_RDONLY);
+  ASSERT_EQ(0, fstat64(fd, &sb));
+  close(fd);
 }
diff --git a/tests/sys_statvfs_test.cpp b/tests/sys_statvfs_test.cpp
new file mode 100644
index 0000000..6b19e13
--- /dev/null
+++ b/tests/sys_statvfs_test.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <sys/statvfs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <string>
+
+template <typename StatVfsT> void Check(StatVfsT& sb) {
+  EXPECT_EQ(4096U, sb.f_bsize);
+  EXPECT_EQ(0U, sb.f_bfree);
+  EXPECT_EQ(0U, sb.f_ffree);
+  EXPECT_EQ(0U, sb.f_fsid);
+  EXPECT_EQ(255U, sb.f_namemax);
+}
+
+TEST(sys_statvfs, statvfs) {
+  struct statvfs sb;
+  ASSERT_EQ(0, statvfs("/proc", &sb));
+  Check(sb);
+}
+
+TEST(sys_statvfs, statvfs64) {
+  struct statvfs64 sb;
+  ASSERT_EQ(0, statvfs64("/proc", &sb));
+  Check(sb);
+}
+
+TEST(sys_statvfs, fstatvfs) {
+  struct statvfs sb;
+  int fd = open("/proc", O_RDONLY);
+  ASSERT_EQ(0, fstatvfs(fd, &sb));
+  close(fd);
+  Check(sb);
+}
+TEST(sys_statvfs, fstatvfs64) {
+  struct statvfs64 sb;
+  int fd = open("/proc", O_RDONLY);
+  ASSERT_EQ(0, fstatvfs64(fd, &sb));
+  close(fd);
+  Check(sb);
+}
diff --git a/tests/sys_time_test.cpp b/tests/sys_time_test.cpp
index 730992f..bb142bc 100644
--- a/tests/sys_time_test.cpp
+++ b/tests/sys_time_test.cpp
@@ -17,6 +17,7 @@
 #include <gtest/gtest.h>
 
 #include <errno.h>
+#include <sys/syscall.h>
 #include <sys/time.h>
 
 #include "TemporaryFile.h"
@@ -46,3 +47,23 @@
   TemporaryFile tf;
   ASSERT_EQ(0, utimes(tf.filename, NULL));
 }
+
+TEST(sys_time, gettimeofday) {
+  // Try to ensure that our vdso gettimeofday is working.
+  timeval tv1;
+  ASSERT_EQ(0, gettimeofday(&tv1, NULL));
+  timeval tv2;
+  ASSERT_EQ(0, syscall(__NR_gettimeofday, &tv2, NULL));
+
+  // What's the difference between the two?
+  tv2.tv_sec -= tv1.tv_sec;
+  tv2.tv_usec -= tv1.tv_usec;
+  if (tv2.tv_usec < 0) {
+    --tv2.tv_sec;
+    tv2.tv_usec += 1000000;
+  }
+
+  // Should be less than (a very generous, to try to avoid flakiness) 1000us.
+  ASSERT_EQ(0, tv2.tv_sec);
+  ASSERT_LT(tv2.tv_usec, 1000);
+}
diff --git a/tests/sys_vfs_test.cpp b/tests/sys_vfs_test.cpp
new file mode 100644
index 0000000..4b05660
--- /dev/null
+++ b/tests/sys_vfs_test.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <sys/vfs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <string>
+
+template <typename StatFsT> void Check(StatFsT& sb) {
+  EXPECT_EQ(4096, static_cast<int>(sb.f_bsize));
+  EXPECT_EQ(0U, sb.f_bfree);
+  EXPECT_EQ(0U, sb.f_ffree);
+  EXPECT_EQ(0, sb.f_fsid.__val[0]);
+  EXPECT_EQ(0, sb.f_fsid.__val[1]);
+  EXPECT_EQ(255, static_cast<int>(sb.f_namelen));
+}
+
+TEST(sys_vfs, statfs) {
+  struct statfs sb;
+  ASSERT_EQ(0, statfs("/proc", &sb));
+  Check(sb);
+}
+
+TEST(sys_vfs, statfs64) {
+  struct statfs64 sb;
+  ASSERT_EQ(0, statfs64("/proc", &sb));
+  Check(sb);
+}
+
+TEST(sys_vfs, fstatfs) {
+  struct statfs sb;
+  int fd = open("/proc", O_RDONLY);
+  ASSERT_EQ(0, fstatfs(fd, &sb));
+  close(fd);
+  Check(sb);
+}
+TEST(sys_vfs, fstatfs64) {
+  struct statfs64 sb;
+  int fd = open("/proc", O_RDONLY);
+  ASSERT_EQ(0, fstatfs64(fd, &sb));
+  close(fd);
+  Check(sb);
+}
diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp
index 5367972..bfd5854 100644
--- a/tests/system_properties_test.cpp
+++ b/tests/system_properties_test.cpp
@@ -20,7 +20,7 @@
 #include <unistd.h>
 #include <string>
 
-#if __BIONIC__
+#if defined(__BIONIC__)
 
 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
 #include <sys/_system_properties.h>
@@ -69,7 +69,54 @@
     void *old_pa;
 };
 
+static void foreach_test_callback(const prop_info *pi, void* cookie) {
+    size_t *count = static_cast<size_t *>(cookie);
+
+    ASSERT_NE((prop_info *)NULL, pi);
+    (*count)++;
+}
+
+static void hierarchical_test_callback(const prop_info *pi, void *cookie) {
+    bool (*ok)[8][8] = static_cast<bool (*)[8][8]>(cookie);
+
+    char name[PROP_NAME_MAX];
+    char value[PROP_VALUE_MAX];
+
+    __system_property_read(pi, name, value);
+
+    int name_i, name_j, name_k;
+    int value_i, value_j, value_k;
+    ASSERT_EQ(3, sscanf(name, "property_%d.%d.%d", &name_i, &name_j, &name_k));
+    ASSERT_EQ(3, sscanf(value, "value_%d.%d.%d", &value_i, &value_j, &value_k));
+    ASSERT_EQ(name_i, value_i);
+    ASSERT_GE(name_i, 0);
+    ASSERT_LT(name_i, 8);
+    ASSERT_EQ(name_j, value_j);
+    ASSERT_GE(name_j, 0);
+    ASSERT_LT(name_j, 8);
+    ASSERT_EQ(name_k, value_k);
+    ASSERT_GE(name_k, 0);
+    ASSERT_LT(name_k, 8);
+
+    ok[name_i][name_j][name_k] = true;
+}
+
+static void *PropertyWaitHelperFn(void *arg) {
+    int *flag = (int *)arg;
+    prop_info *pi;
+    pi = (prop_info *)__system_property_find("property");
+    usleep(100000);
+
+    *flag = 1;
+    __system_property_update(pi, "value3", 6);
+
+    return NULL;
+}
+
+#endif // __BIONIC__
+
 TEST(properties, add) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
 
@@ -87,9 +134,13 @@
 
     ASSERT_EQ(6, __system_property_get("property_other", propvalue));
     ASSERT_STREQ(propvalue, "value3");
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(properties, update) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
 
@@ -120,9 +171,13 @@
 
     ASSERT_EQ(6, __system_property_get("property_other", propvalue));
     ASSERT_STREQ(propvalue, "value6");
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(properties, fill) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
     char prop_name[PROP_NAME_MAX];
@@ -161,16 +216,13 @@
         ASSERT_EQ(PROP_VALUE_MAX - 1, __system_property_get(prop_name, prop_value_ret));
         ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX));
     }
-}
-
-static void foreach_test_callback(const prop_info *pi, void* cookie) {
-    size_t *count = static_cast<size_t *>(cookie);
-
-    ASSERT_NE((prop_info *)NULL, pi);
-    (*count)++;
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(properties, foreach) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
     size_t count = 0;
@@ -181,9 +233,13 @@
 
     ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count));
     ASSERT_EQ(3U, count);
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(properties, find_nth) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
 
@@ -201,34 +257,13 @@
     ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(100));
     ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(200));
     ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(247));
-}
-
-static void hierarchical_test_callback(const prop_info *pi, void *cookie) {
-    bool (*ok)[8][8] = static_cast<bool (*)[8][8]>(cookie);
-
-    char name[PROP_NAME_MAX];
-    char value[PROP_VALUE_MAX];
-
-    __system_property_read(pi, name, value);
-
-    int name_i, name_j, name_k;
-    int value_i, value_j, value_k;
-    ASSERT_EQ(3, sscanf(name, "property_%d.%d.%d", &name_i, &name_j, &name_k));
-    ASSERT_EQ(3, sscanf(value, "value_%d.%d.%d", &value_i, &value_j, &value_k));
-    ASSERT_EQ(name_i, value_i);
-    ASSERT_GE(name_i, 0);
-    ASSERT_LT(name_i, 8);
-    ASSERT_EQ(name_j, value_j);
-    ASSERT_GE(name_j, 0);
-    ASSERT_LT(name_j, 8);
-    ASSERT_EQ(name_k, value_k);
-    ASSERT_GE(name_k, 0);
-    ASSERT_LT(name_k, 8);
-
-    ok[name_i][name_j][name_k] = true;
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(properties, fill_hierarchical) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
     char prop_name[PROP_NAME_MAX];
@@ -279,9 +314,13 @@
             }
         }
     }
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(properties, errors) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
     char prop_value[PROP_NAME_MAX];
@@ -296,9 +335,13 @@
     ASSERT_EQ(-1, __system_property_add("name", PROP_NAME_MAX, "value", 5));
     ASSERT_EQ(-1, __system_property_add("name", 4, "value", PROP_VALUE_MAX));
     ASSERT_EQ(-1, __system_property_update(NULL, "value", PROP_VALUE_MAX));
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(properties, serial) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
     const prop_info *pi;
@@ -309,22 +352,13 @@
     serial = __system_property_serial(pi);
     ASSERT_EQ(0, __system_property_update((prop_info *)pi, "value2", 6));
     ASSERT_NE(serial, __system_property_serial(pi));
-}
-
-static void *PropertyWaitHelperFn(void *arg)
-{
-    int *flag = (int *)arg;
-    prop_info *pi;
-    pi = (prop_info *)__system_property_find("property");
-    usleep(100000);
-
-    *flag = 1;
-    __system_property_update(pi, "value3", 6);
-
-    return NULL;
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 TEST(properties, wait) {
+#if defined(__BIONIC__)
     LocalPropertyTestState pa;
     ASSERT_TRUE(pa.valid);
     unsigned int serial;
@@ -346,6 +380,9 @@
 
     void* result;
     ASSERT_EQ(0, pthread_join(t, &result));
+#else // __BIONIC__
+    GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
 
 class KilledByFault {
@@ -362,6 +399,7 @@
 }
 
 TEST(properties_DeathTest, read_only) {
+#if defined(__BIONIC__)
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
 
   // This test only makes sense if we're talking to the real system property service.
@@ -371,6 +409,7 @@
   }
 
   ASSERT_EXIT(__system_property_add("property", 8, "value", 5), KilledByFault(), "");
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
 }
-
-#endif
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index fb5a4a7..241c4a0 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -14,34 +14,18 @@
  * limitations under the License.
  */
 
-#include <sys/cdefs.h>
-#include <features.h>
-#include <gtest/gtest.h>
-
 #include <time.h>
 
-#ifdef __BIONIC__ // mktime_tz is a bionic extension.
-#include <libc/private/bionic_time.h>
-TEST(time, mktime_tz) {
-  struct tm epoch;
-  memset(&epoch, 0, sizeof(tm));
-  epoch.tm_year = 1970 - 1900;
-  epoch.tm_mon = 1;
-  epoch.tm_mday = 1;
+#include <errno.h>
+#include <features.h>
+#include <gtest/gtest.h>
+#include <pthread.h>
+#include <signal.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
-  // Alphabetically first. Coincidentally equivalent to UTC.
-  ASSERT_EQ(2678400, mktime_tz(&epoch, "Africa/Abidjan"));
-
-  // Alphabetically last. Coincidentally equivalent to UTC.
-  ASSERT_EQ(2678400, mktime_tz(&epoch, "Zulu"));
-
-  // Somewhere in the middle, not UTC.
-  ASSERT_EQ(2707200, mktime_tz(&epoch, "America/Los_Angeles"));
-
-  // Missing. Falls back to UTC.
-  ASSERT_EQ(2678400, mktime_tz(&epoch, "PST"));
-}
-#endif
+#include "ScopedSignalHandler.h"
 
 TEST(time, gmtime) {
   time_t t = 0;
@@ -55,7 +39,37 @@
   ASSERT_EQ(1970, broken_down->tm_year + 1900);
 }
 
-#if __BIONIC__
+static void* gmtime_no_stack_overflow_14313703_fn(void*) {
+  const char* original_tz = getenv("TZ");
+  // Ensure we'll actually have to enter tzload by using a time zone that doesn't exist.
+  setenv("TZ", "gmtime_stack_overflow_14313703", 1);
+  tzset();
+  if (original_tz != NULL) {
+    setenv("TZ", original_tz, 1);
+  }
+  tzset();
+  return NULL;
+}
+
+TEST(time, gmtime_no_stack_overflow_14313703) {
+  // Is it safe to call tzload on a thread with a small stack?
+  // http://b/14313703
+  // https://code.google.com/p/android/issues/detail?id=61130
+  pthread_attr_t attributes;
+  ASSERT_EQ(0, pthread_attr_init(&attributes));
+#if defined(__BIONIC__)
+  ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, PTHREAD_STACK_MIN));
+#else
+  // PTHREAD_STACK_MIN not currently in the host GCC sysroot.
+  ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, 4 * getpagesize()));
+#endif
+
+  pthread_t t;
+  ASSERT_EQ(0, pthread_create(&t, &attributes, gmtime_no_stack_overflow_14313703_fn, NULL));
+  void* result;
+  ASSERT_EQ(0, pthread_join(t, &result));
+}
+
 TEST(time, mktime_10310929) {
   struct tm t;
   memset(&t, 0, sizeof(tm));
@@ -66,7 +80,6 @@
 #if !defined(__LP64__)
   // 32-bit bionic stupidly had a signed 32-bit time_t.
   ASSERT_EQ(-1, mktime(&t));
-  ASSERT_EQ(-1, mktime_tz(&t, "UTC"));
 #else
   // Everyone else should be using a signed 64-bit time_t.
   ASSERT_GE(sizeof(time_t) * 8, 64U);
@@ -74,12 +87,319 @@
   setenv("TZ", "America/Los_Angeles", 1);
   tzset();
   ASSERT_EQ(static_cast<time_t>(4108348800U), mktime(&t));
-  ASSERT_EQ(static_cast<time_t>(4108320000U), mktime_tz(&t, "UTC"));
 
   setenv("TZ", "UTC", 1);
   tzset();
   ASSERT_EQ(static_cast<time_t>(4108320000U), mktime(&t));
-  ASSERT_EQ(static_cast<time_t>(4108348800U), mktime_tz(&t, "America/Los_Angeles"));
 #endif
 }
+
+TEST(time, strftime) {
+  setenv("TZ", "UTC", 1);
+
+  struct tm t;
+  memset(&t, 0, sizeof(tm));
+  t.tm_year = 200;
+  t.tm_mon = 2;
+  t.tm_mday = 10;
+
+  char buf[64];
+
+  // Seconds since the epoch.
+#if defined(__BIONIC__) || defined(__LP64__) // Not 32-bit glibc.
+  EXPECT_EQ(10U, strftime(buf, sizeof(buf), "%s", &t));
+  EXPECT_STREQ("4108320000", buf);
 #endif
+
+  // Date and time as text.
+  EXPECT_EQ(24U, strftime(buf, sizeof(buf), "%c", &t));
+  EXPECT_STREQ("Sun Mar 10 00:00:00 2100", buf);
+}
+
+TEST(time, strptime) {
+  setenv("TZ", "UTC", 1);
+
+  struct tm t;
+  char buf[64];
+
+  memset(&t, 0, sizeof(t));
+  strptime("11:14", "%R", &t);
+  strftime(buf, sizeof(buf), "%H:%M", &t);
+  EXPECT_STREQ("11:14", buf);
+
+  memset(&t, 0, sizeof(t));
+  strptime("09:41:53", "%T", &t);
+  strftime(buf, sizeof(buf), "%H:%M:%S", &t);
+  EXPECT_STREQ("09:41:53", buf);
+}
+
+void SetTime(timer_t t, time_t value_s, time_t value_ns, time_t interval_s, time_t interval_ns) {
+  itimerspec ts;
+  ts.it_value.tv_sec = value_s;
+  ts.it_value.tv_nsec = value_ns;
+  ts.it_interval.tv_sec = interval_s;
+  ts.it_interval.tv_nsec = interval_ns;
+  ASSERT_EQ(0, timer_settime(t, TIMER_ABSTIME, &ts, NULL));
+}
+
+static void NoOpNotifyFunction(sigval_t) {
+}
+
+TEST(time, timer_create) {
+  sigevent_t se;
+  memset(&se, 0, sizeof(se));
+  se.sigev_notify = SIGEV_THREAD;
+  se.sigev_notify_function = NoOpNotifyFunction;
+  timer_t timer_id;
+  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, &se, &timer_id));
+
+  int pid = fork();
+  ASSERT_NE(-1, pid) << strerror(errno);
+
+  if (pid == 0) {
+    // Timers are not inherited by the child.
+    ASSERT_EQ(-1, timer_delete(timer_id));
+    ASSERT_EQ(EINVAL, errno);
+    _exit(0);
+  }
+
+  int status;
+  ASSERT_EQ(pid, waitpid(pid, &status, 0));
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(0, WEXITSTATUS(status));
+
+  ASSERT_EQ(0, timer_delete(timer_id));
+}
+
+static int timer_create_SIGEV_SIGNAL_signal_handler_invocation_count = 0;
+static void timer_create_SIGEV_SIGNAL_signal_handler(int signal_number) {
+  ++timer_create_SIGEV_SIGNAL_signal_handler_invocation_count;
+  ASSERT_EQ(SIGUSR1, signal_number);
+}
+
+TEST(time, timer_create_SIGEV_SIGNAL) {
+  sigevent_t se;
+  memset(&se, 0, sizeof(se));
+  se.sigev_notify = SIGEV_SIGNAL;
+  se.sigev_signo = SIGUSR1;
+
+  timer_t timer_id;
+  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, &se, &timer_id));
+
+  ScopedSignalHandler ssh(SIGUSR1, timer_create_SIGEV_SIGNAL_signal_handler);
+
+  ASSERT_EQ(0, timer_create_SIGEV_SIGNAL_signal_handler_invocation_count);
+
+  itimerspec ts;
+  ts.it_value.tv_sec =  0;
+  ts.it_value.tv_nsec = 1;
+  ts.it_interval.tv_sec = 0;
+  ts.it_interval.tv_nsec = 0;
+  ASSERT_EQ(0, timer_settime(timer_id, TIMER_ABSTIME, &ts, NULL));
+
+  usleep(500000);
+  ASSERT_EQ(1, timer_create_SIGEV_SIGNAL_signal_handler_invocation_count);
+}
+
+struct Counter {
+  volatile int value;
+  timer_t timer_id;
+  sigevent_t se;
+
+  Counter(void (*fn)(sigval_t)) : value(0) {
+    memset(&se, 0, sizeof(se));
+    se.sigev_notify = SIGEV_THREAD;
+    se.sigev_notify_function = fn;
+    se.sigev_value.sival_ptr = this;
+  }
+
+  void Create() {
+    ASSERT_EQ(0, timer_create(CLOCK_REALTIME, &se, &timer_id));
+  }
+
+  ~Counter() {
+    if (timer_delete(timer_id) != 0) {
+      abort();
+    }
+  }
+
+  static void CountNotifyFunction(sigval_t value) {
+    Counter* cd = reinterpret_cast<Counter*>(value.sival_ptr);
+    ++cd->value;
+  }
+
+  static void CountAndDisarmNotifyFunction(sigval_t value) {
+    Counter* cd = reinterpret_cast<Counter*>(value.sival_ptr);
+    ++cd->value;
+
+    // Setting the initial expiration time to 0 disarms the timer.
+    SetTime(cd->timer_id, 0, 0, 1, 0);
+  }
+};
+
+TEST(time, timer_settime_0) {
+  Counter counter(Counter::CountAndDisarmNotifyFunction);
+  counter.Create();
+
+  ASSERT_EQ(0, counter.value);
+
+  SetTime(counter.timer_id, 0, 1, 1, 0);
+  usleep(500000);
+
+  // The count should just be 1 because we disarmed the timer the first time it fired.
+  ASSERT_EQ(1, counter.value);
+}
+
+TEST(time, timer_settime_repeats) {
+  Counter counter(Counter::CountNotifyFunction);
+  counter.Create();
+
+  ASSERT_EQ(0, counter.value);
+
+  SetTime(counter.timer_id, 0, 1, 0, 10);
+  usleep(500000);
+
+  // The count should just be > 1 because we let the timer repeat.
+  ASSERT_GT(counter.value, 1);
+}
+
+static int timer_create_NULL_signal_handler_invocation_count = 0;
+static void timer_create_NULL_signal_handler(int signal_number) {
+  ++timer_create_NULL_signal_handler_invocation_count;
+  ASSERT_EQ(SIGALRM, signal_number);
+}
+
+TEST(time, timer_create_NULL) {
+  // A NULL sigevent* is equivalent to asking for SIGEV_SIGNAL for SIGALRM.
+  timer_t timer_id;
+  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, NULL, &timer_id));
+
+  ScopedSignalHandler ssh(SIGALRM, timer_create_NULL_signal_handler);
+
+  ASSERT_EQ(0, timer_create_NULL_signal_handler_invocation_count);
+
+  SetTime(timer_id, 0, 1, 0, 0);
+  usleep(500000);
+
+  ASSERT_EQ(1, timer_create_NULL_signal_handler_invocation_count);
+}
+
+TEST(time, timer_create_EINVAL) {
+  clockid_t invalid_clock = 16;
+
+  // A SIGEV_SIGNAL timer is easy; the kernel does all that.
+  timer_t timer_id;
+  ASSERT_EQ(-1, timer_create(invalid_clock, NULL, &timer_id));
+  ASSERT_EQ(EINVAL, errno);
+
+  // A SIGEV_THREAD timer is more interesting because we have stuff to clean up.
+  sigevent_t se;
+  memset(&se, 0, sizeof(se));
+  se.sigev_notify = SIGEV_THREAD;
+  se.sigev_notify_function = NoOpNotifyFunction;
+  ASSERT_EQ(-1, timer_create(invalid_clock, &se, &timer_id));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(time, timer_delete_multiple) {
+  timer_t timer_id;
+  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, NULL, &timer_id));
+  ASSERT_EQ(0, timer_delete(timer_id));
+  ASSERT_EQ(-1, timer_delete(timer_id));
+  ASSERT_EQ(EINVAL, errno);
+
+  sigevent_t se;
+  memset(&se, 0, sizeof(se));
+  se.sigev_notify = SIGEV_THREAD;
+  se.sigev_notify_function = NoOpNotifyFunction;
+  ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, &se, &timer_id));
+  ASSERT_EQ(0, timer_delete(timer_id));
+  ASSERT_EQ(-1, timer_delete(timer_id));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(time, timer_create_multiple) {
+  Counter counter1(Counter::CountNotifyFunction);
+  counter1.Create();
+  Counter counter2(Counter::CountNotifyFunction);
+  counter2.Create();
+  Counter counter3(Counter::CountNotifyFunction);
+  counter3.Create();
+
+  ASSERT_EQ(0, counter1.value);
+  ASSERT_EQ(0, counter2.value);
+  ASSERT_EQ(0, counter3.value);
+
+  SetTime(counter2.timer_id, 0, 1, 0, 0);
+  usleep(500000);
+
+  EXPECT_EQ(0, counter1.value);
+  EXPECT_EQ(1, counter2.value);
+  EXPECT_EQ(0, counter3.value);
+}
+
+struct TimerDeleteData {
+  timer_t timer_id;
+  pthread_t thread_id;
+  volatile bool complete;
+};
+
+static void TimerDeleteCallback(sigval_t value) {
+  TimerDeleteData* tdd = reinterpret_cast<TimerDeleteData*>(value.sival_ptr);
+
+  tdd->thread_id = pthread_self();
+  timer_delete(tdd->timer_id);
+  tdd->complete = true;
+}
+
+TEST(time, timer_delete_from_timer_thread) {
+  TimerDeleteData tdd;
+  sigevent_t se;
+
+  memset(&se, 0, sizeof(se));
+  se.sigev_notify = SIGEV_THREAD;
+  se.sigev_notify_function = TimerDeleteCallback;
+  se.sigev_value.sival_ptr = &tdd;
+
+  tdd.complete = false;
+  ASSERT_EQ(0, timer_create(CLOCK_REALTIME, &se, &tdd.timer_id));
+
+  itimerspec ts;
+  ts.it_value.tv_sec = 0;
+  ts.it_value.tv_nsec = 100;
+  ts.it_interval.tv_sec = 0;
+  ts.it_interval.tv_nsec = 0;
+  ASSERT_EQ(0, timer_settime(tdd.timer_id, TIMER_ABSTIME, &ts, NULL));
+
+  time_t cur_time = time(NULL);
+  while (!tdd.complete && (time(NULL) - cur_time) < 5);
+  ASSERT_TRUE(tdd.complete);
+
+#if defined(__BIONIC__)
+  // Since bionic timers are implemented by creating a thread to handle the
+  // callback, verify that the thread actually completes.
+  cur_time = time(NULL);
+  while (pthread_detach(tdd.thread_id) != ESRCH && (time(NULL) - cur_time) < 5);
+  ASSERT_EQ(ESRCH, pthread_detach(tdd.thread_id));
+#endif
+}
+
+TEST(time, clock_gettime) {
+  // Try to ensure that our vdso clock_gettime is working.
+  timespec ts1;
+  ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts1));
+  timespec ts2;
+  ASSERT_EQ(0, syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &ts2));
+
+  // What's the difference between the two?
+  ts2.tv_sec -= ts1.tv_sec;
+  ts2.tv_nsec -= ts1.tv_nsec;
+  if (ts2.tv_nsec < 0) {
+    --ts2.tv_sec;
+    ts2.tv_nsec += 1000000000;
+  }
+
+  // Should be less than (a very generous, to try to avoid flakiness) 1000000ns.
+  ASSERT_EQ(0, ts2.tv_sec);
+  ASSERT_LT(ts2.tv_nsec, 1000000);
+}
diff --git a/tests/uchar_test.cpp b/tests/uchar_test.cpp
new file mode 100644
index 0000000..eca3c5e
--- /dev/null
+++ b/tests/uchar_test.cpp
@@ -0,0 +1,412 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <sys/cdefs.h>
+#if defined(__BIONIC__)
+#define HAVE_UCHAR 1
+#elif defined(__GLIBC__)
+#include <features.h>
+#define HAVE_UCHAR __GLIBC_PREREQ(2, 16)
+#endif
+
+#include <gtest/gtest.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdint.h>
+
+#if HAVE_UCHAR
+#include <uchar.h>
+#endif
+
+TEST(uchar, sizeof_uchar_t) {
+#if HAVE_UCHAR
+  EXPECT_EQ(2U, sizeof(char16_t));
+  EXPECT_EQ(4U, sizeof(char32_t));
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, start_state) {
+#if HAVE_UCHAR
+  char out[MB_LEN_MAX];
+  mbstate_t ps;
+
+  // Any non-initial state is invalid when calling c32rtomb.
+  memset(&ps, 0, sizeof(ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(NULL, "\xc2", 1, &ps));
+  EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(out, 0x00a2, &ps));
+  EXPECT_EQ(EILSEQ, errno);
+
+  // If the first argument to c32rtomb is NULL or the second is L'\0' the shift
+  // state should be reset.
+  memset(&ps, 0, sizeof(ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(NULL, "\xc2", 1, &ps));
+  EXPECT_EQ(1U, c32rtomb(NULL, 0x00a2, &ps));
+  EXPECT_TRUE(mbsinit(&ps));
+
+  memset(&ps, 0, sizeof(ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(NULL, "\xf0\xa4", 1, &ps));
+  EXPECT_EQ(1U, c32rtomb(out, L'\0', &ps));
+  EXPECT_TRUE(mbsinit(&ps));
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, c16rtomb_null_out) {
+#if HAVE_UCHAR
+  EXPECT_EQ(1U, c16rtomb(NULL, L'\0', NULL));
+  EXPECT_EQ(1U, c16rtomb(NULL, L'h', NULL));
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, c16rtomb_null_char) {
+#if HAVE_UCHAR
+  char bytes[MB_LEN_MAX];
+  EXPECT_EQ(1U, c16rtomb(bytes, L'\0', NULL));
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, c16rtomb) {
+#if HAVE_UCHAR
+  char bytes[MB_LEN_MAX];
+
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(1U, c16rtomb(bytes, L'h', NULL));
+  EXPECT_EQ('h', bytes[0]);
+
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  // 1-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(1U, c16rtomb(bytes, L'h', NULL));
+  EXPECT_EQ('h', bytes[0]);
+  // 2-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(2U, c16rtomb(bytes, 0x00a2, NULL));
+  EXPECT_EQ('\xc2', bytes[0]);
+  EXPECT_EQ('\xa2', bytes[1]);
+  // 3-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(3U, c16rtomb(bytes, 0x20ac, NULL));
+  EXPECT_EQ('\xe2', bytes[0]);
+  EXPECT_EQ('\x82', bytes[1]);
+  EXPECT_EQ('\xac', bytes[2]);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, c16rtomb_surrogate) {
+#if HAVE_UCHAR
+  char bytes[MB_LEN_MAX];
+
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, NULL));
+  EXPECT_EQ(4U, c16rtomb(bytes, 0xdfcd, NULL));
+  EXPECT_EQ('\xf4', bytes[0]);
+  EXPECT_EQ('\x8a', bytes[1]);
+  EXPECT_EQ('\xaf', bytes[2]);
+  EXPECT_EQ('\x8d', bytes[3]);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, c16rtomb_invalid) {
+#if HAVE_UCHAR
+  char bytes[MB_LEN_MAX];
+
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdfcd, NULL));
+
+  EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, NULL));
+  EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdbea, NULL));
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, mbrtoc16_null) {
+#if HAVE_UCHAR
+  ASSERT_EQ(0U, mbrtoc16(NULL, NULL, 0, NULL));
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, mbrtoc16_zero_len) {
+#if HAVE_UCHAR
+  char16_t out;
+
+  out = L'x';
+  ASSERT_EQ(0U, mbrtoc16(&out, "hello", 0, NULL));
+  ASSERT_EQ(L'x', out);
+
+  ASSERT_EQ(0U, mbrtoc16(&out, "hello", 0, NULL));
+  ASSERT_EQ(0U, mbrtoc16(&out, "", 0, NULL));
+  ASSERT_EQ(1U, mbrtoc16(&out, "hello", 1, NULL));
+  ASSERT_EQ(L'h', out);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, mbrtoc16) {
+#if HAVE_UCHAR
+  char16_t out;
+
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  // 1-byte UTF-8.
+  ASSERT_EQ(1U, mbrtoc16(&out, "abcdef", 6, NULL));
+  ASSERT_EQ(L'a', out);
+  // 2-byte UTF-8.
+  ASSERT_EQ(2U, mbrtoc16(&out, "\xc2\xa2" "cdef", 6, NULL));
+  ASSERT_EQ(static_cast<char16_t>(0x00a2), out);
+  // 3-byte UTF-8.
+  ASSERT_EQ(3U, mbrtoc16(&out, "\xe2\x82\xac" "def", 6, NULL));
+  ASSERT_EQ(static_cast<char16_t>(0x20ac), out);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, mbrtoc16_surrogate) {
+#if HAVE_UCHAR
+  char16_t out;
+
+  ASSERT_EQ(static_cast<size_t>(-3),
+            mbrtoc16(&out, "\xf4\x8a\xaf\x8d", 6, NULL));
+  ASSERT_EQ(static_cast<char16_t>(0xdbea), out);
+  ASSERT_EQ(4U, mbrtoc16(&out, "\xf4\x8a\xaf\x8d" "ef", 6, NULL));
+  ASSERT_EQ(static_cast<char16_t>(0xdfcd), out);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, mbrtoc16_reserved_range) {
+#if HAVE_UCHAR
+  char16_t out;
+  ASSERT_EQ(static_cast<size_t>(-1),
+            mbrtoc16(&out, "\xf0\x80\xbf\xbf", 6, NULL));
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, mbrtoc16_beyond_range) {
+#if HAVE_UCHAR
+  char16_t out;
+  ASSERT_EQ(static_cast<size_t>(-1),
+            mbrtoc16(&out, "\xf5\x80\x80\x80", 6, NULL));
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+#if HAVE_UCHAR
+void test_mbrtoc16_incomplete(mbstate_t* ps) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  char16_t out;
+  // 2-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xc2", 1, ps));
+  ASSERT_EQ(1U, mbrtoc16(&out, "\xa2" "cdef", 5, ps));
+  ASSERT_EQ(static_cast<char16_t>(0x00a2), out);
+  ASSERT_TRUE(mbsinit(ps));
+  // 3-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xe2", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\x82", 1, ps));
+  ASSERT_EQ(1U, mbrtoc16(&out, "\xac" "def", 4, ps));
+  ASSERT_EQ(static_cast<char16_t>(0x20ac), out);
+  ASSERT_TRUE(mbsinit(ps));
+  // 4-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xf4", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\x8a\xaf", 2, ps));
+  ASSERT_EQ(static_cast<size_t>(-3), mbrtoc16(&out, "\x8d" "ef", 3, ps));
+  ASSERT_EQ(static_cast<char16_t>(0xdbea), out);
+  ASSERT_EQ(1U, mbrtoc16(&out, "\x80" "ef", 3, ps));
+  ASSERT_EQ(static_cast<char16_t>(0xdfcd), out);
+  ASSERT_TRUE(mbsinit(ps));
+
+  // Invalid 2-byte
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xc2", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtoc16(&out, "\x20" "cdef", 5, ps));
+  ASSERT_EQ(EILSEQ, errno);
+}
+#endif
+
+TEST(uchar, mbrtoc16_incomplete) {
+#if HAVE_UCHAR
+  mbstate_t ps;
+  memset(&ps, 0, sizeof(ps));
+
+  test_mbrtoc16_incomplete(&ps);
+  test_mbrtoc16_incomplete(NULL);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, c32rtomb) {
+#if HAVE_UCHAR
+  EXPECT_EQ(1U, c32rtomb(NULL, L'\0', NULL));
+  EXPECT_EQ(1U, c32rtomb(NULL, L'h', NULL));
+
+  char bytes[MB_LEN_MAX];
+
+  EXPECT_EQ(1U, c32rtomb(bytes, L'\0', NULL));
+
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(1U, c32rtomb(bytes, L'h', NULL));
+  EXPECT_EQ('h', bytes[0]);
+
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  // 1-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(1U, c32rtomb(bytes, L'h', NULL));
+  EXPECT_EQ('h', bytes[0]);
+  // 2-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(2U, c32rtomb(bytes, 0x00a2, NULL));
+  EXPECT_EQ('\xc2', bytes[0]);
+  EXPECT_EQ('\xa2', bytes[1]);
+  // 3-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(3U, c32rtomb(bytes, 0x20ac, NULL));
+  EXPECT_EQ('\xe2', bytes[0]);
+  EXPECT_EQ('\x82', bytes[1]);
+  EXPECT_EQ('\xac', bytes[2]);
+  // 4-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(4U, c32rtomb(bytes, 0x24b62, NULL));
+  EXPECT_EQ('\xf0', bytes[0]);
+  EXPECT_EQ('\xa4', bytes[1]);
+  EXPECT_EQ('\xad', bytes[2]);
+  EXPECT_EQ('\xa2', bytes[3]);
+  // Invalid code point.
+  EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(bytes, 0xffffffff, NULL));
+  EXPECT_EQ(EILSEQ, errno);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+TEST(uchar, mbrtoc32) {
+#if HAVE_UCHAR
+  char32_t out[8];
+
+  out[0] = L'x';
+  ASSERT_EQ(0U, mbrtoc32(out, "hello", 0, NULL));
+  ASSERT_EQ(static_cast<char32_t>(L'x'), out[0]);
+
+  ASSERT_EQ(0U, mbrtoc32(out, "hello", 0, NULL));
+  ASSERT_EQ(0U, mbrtoc32(out, "", 0, NULL));
+  ASSERT_EQ(1U, mbrtoc32(out, "hello", 1, NULL));
+  ASSERT_EQ(static_cast<char32_t>(L'h'), out[0]);
+
+  ASSERT_EQ(0U, mbrtoc32(NULL, "hello", 0, NULL));
+  ASSERT_EQ(0U, mbrtoc32(NULL, "", 0, NULL));
+  ASSERT_EQ(1U, mbrtoc32(NULL, "hello", 1, NULL));
+
+  ASSERT_EQ(0U, mbrtoc32(NULL, NULL, 0, NULL));
+
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  // 1-byte UTF-8.
+  ASSERT_EQ(1U, mbrtoc32(out, "abcdef", 6, NULL));
+  ASSERT_EQ(static_cast<char32_t>(L'a'), out[0]);
+  // 2-byte UTF-8.
+  ASSERT_EQ(2U, mbrtoc32(out, "\xc2\xa2" "cdef", 6, NULL));
+  ASSERT_EQ(static_cast<char32_t>(0x00a2), out[0]);
+  // 3-byte UTF-8.
+  ASSERT_EQ(3U, mbrtoc32(out, "\xe2\x82\xac" "def", 6, NULL));
+  ASSERT_EQ(static_cast<char32_t>(0x20ac), out[0]);
+  // 4-byte UTF-8.
+  ASSERT_EQ(4U, mbrtoc32(out, "\xf0\xa4\xad\xa2" "ef", 6, NULL));
+  ASSERT_EQ(static_cast<char32_t>(0x24b62), out[0]);
+#if defined(__BIONIC__) // glibc allows this.
+  // Illegal 5-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, NULL));
+  ASSERT_EQ(EILSEQ, errno);
+#endif
+  // Illegal over-long sequence.
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf0\x82\x82\xac" "ef", 6, NULL));
+  ASSERT_EQ(EILSEQ, errno);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
+#if HAVE_UCHAR
+void test_mbrtoc32_incomplete(mbstate_t* ps) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  char32_t out;
+  // 2-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xc2", 1, ps));
+  ASSERT_EQ(1U, mbrtoc32(&out, "\xa2" "cdef", 5, ps));
+  ASSERT_EQ(static_cast<char32_t>(0x00a2), out);
+  ASSERT_TRUE(mbsinit(ps));
+  // 3-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xe2", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\x82", 1, ps));
+  ASSERT_EQ(1U, mbrtoc32(&out, "\xac" "def", 4, ps));
+  ASSERT_EQ(static_cast<char32_t>(0x20ac), out);
+  ASSERT_TRUE(mbsinit(ps));
+  // 4-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xf0", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xa4\xad", 2, ps));
+  ASSERT_EQ(1U, mbrtoc32(&out, "\xa2" "ef", 3, ps));
+  ASSERT_EQ(static_cast<char32_t>(0x24b62), out);
+  ASSERT_TRUE(mbsinit(ps));
+
+  // Invalid 2-byte
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xc2", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(&out, "\x20" "cdef", 5, ps));
+  ASSERT_EQ(EILSEQ, errno);
+}
+#endif
+
+TEST(uchar, mbrtoc32_incomplete) {
+#if HAVE_UCHAR
+  mbstate_t ps;
+  memset(&ps, 0, sizeof(ps));
+
+  test_mbrtoc32_incomplete(&ps);
+  test_mbrtoc32_incomplete(NULL);
+#else
+  GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
+#endif
+}
+
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 2308ad9..8195ea8 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -18,21 +18,123 @@
 #include "ScopedSignalHandler.h"
 #include "TemporaryFile.h"
 
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
 #include <stdint.h>
 #include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 TEST(unistd, sysconf_SC_MONOTONIC_CLOCK) {
   ASSERT_GT(sysconf(_SC_MONOTONIC_CLOCK), 0);
 }
 
-TEST(unistd, sbrk) {
-  void* initial_break = sbrk(0);
+static void* get_brk() {
+  return sbrk(0);
+}
 
-  void* new_break = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(initial_break) + 2000);
+static void* page_align(uintptr_t addr) {
+  uintptr_t mask = sysconf(_SC_PAGE_SIZE) - 1;
+  return reinterpret_cast<void*>((addr + mask) & ~mask);
+}
+
+TEST(unistd, brk) {
+  void* initial_break = get_brk();
+
+  // The kernel aligns the break to a page.
+  void* new_break = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(initial_break) + 1);
   ASSERT_EQ(0, brk(new_break));
+  ASSERT_GE(get_brk(), new_break);
 
-  void* final_break = sbrk(0);
-  ASSERT_EQ(final_break, new_break);
+  new_break = page_align(reinterpret_cast<uintptr_t>(initial_break) + sysconf(_SC_PAGE_SIZE));
+  ASSERT_EQ(0, brk(new_break));
+  ASSERT_EQ(get_brk(), new_break);
+}
+
+TEST(unistd, brk_ENOMEM) {
+  ASSERT_EQ(-1, brk(reinterpret_cast<void*>(-1)));
+  ASSERT_EQ(ENOMEM, errno);
+}
+
+#if defined(__GLIBC__)
+#define SBRK_MIN INTPTR_MIN
+#define SBRK_MAX INTPTR_MAX
+#else
+#define SBRK_MIN PTRDIFF_MIN
+#define SBRK_MAX PTRDIFF_MAX
+#endif
+
+TEST(unistd, sbrk_ENOMEM) {
+#if defined(__BIONIC__) && !defined(__LP64__)
+  // There is no way to guarantee that all overflow conditions can be tested
+  // without manipulating the underlying values of the current break.
+  extern void* __bionic_brk;
+
+  class ScopedBrk {
+  public:
+    ScopedBrk() : saved_brk_(__bionic_brk) {}
+    virtual ~ScopedBrk() { __bionic_brk = saved_brk_; }
+
+  private:
+    void* saved_brk_;
+  };
+
+  ScopedBrk scope_brk;
+
+  // Set the current break to a point that will cause an overflow.
+  __bionic_brk = reinterpret_cast<void*>(static_cast<uintptr_t>(PTRDIFF_MAX) + 2);
+
+  // Can't increase by so much that we'd overflow.
+  ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(PTRDIFF_MAX));
+  ASSERT_EQ(ENOMEM, errno);
+
+  // Set the current break to a point that will cause an overflow.
+  __bionic_brk = reinterpret_cast<void*>(static_cast<uintptr_t>(PTRDIFF_MAX));
+
+  ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(PTRDIFF_MIN));
+  ASSERT_EQ(ENOMEM, errno);
+
+  __bionic_brk = reinterpret_cast<void*>(static_cast<uintptr_t>(PTRDIFF_MAX) - 1);
+
+  ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(PTRDIFF_MIN + 1));
+  ASSERT_EQ(ENOMEM, errno);
+#else
+  class ScopedBrk {
+  public:
+    ScopedBrk() : saved_brk_(get_brk()) {}
+    virtual ~ScopedBrk() { brk(saved_brk_); }
+
+  private:
+    void* saved_brk_;
+  };
+
+  ScopedBrk scope_brk;
+
+  uintptr_t cur_brk = reinterpret_cast<uintptr_t>(get_brk());
+  if (cur_brk < static_cast<uintptr_t>(-(SBRK_MIN+1))) {
+    // Do the overflow test for a max negative increment.
+    ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(SBRK_MIN));
+#if defined(__BIONIC__)
+    // GLIBC does not set errno in overflow case.
+    ASSERT_EQ(ENOMEM, errno);
+#endif
+  }
+
+  uintptr_t overflow_brk = static_cast<uintptr_t>(SBRK_MAX) + 2;
+  if (cur_brk < overflow_brk) {
+    // Try and move the value to PTRDIFF_MAX + 2.
+    cur_brk = reinterpret_cast<uintptr_t>(sbrk(overflow_brk));
+  }
+  if (cur_brk >= overflow_brk) {
+    ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(SBRK_MAX));
+#if defined(__BIONIC__)
+    // GLIBC does not set errno in overflow case.
+    ASSERT_EQ(ENOMEM, errno);
+#endif
+  }
+#endif
 }
 
 TEST(unistd, truncate) {
@@ -75,16 +177,288 @@
   ASSERT_EQ(123, sb.st_size);
 }
 
-static bool gPauseTestFlag = false;
+static bool g_pause_test_flag = false;
 static void PauseTestSignalHandler(int) {
-  gPauseTestFlag = true;
+  g_pause_test_flag = true;
 }
 
 TEST(unistd, pause) {
   ScopedSignalHandler handler(SIGALRM, PauseTestSignalHandler);
 
   alarm(1);
-  ASSERT_FALSE(gPauseTestFlag);
+  ASSERT_FALSE(g_pause_test_flag);
   ASSERT_EQ(-1, pause());
-  ASSERT_TRUE(gPauseTestFlag);
+  ASSERT_TRUE(g_pause_test_flag);
+}
+
+TEST(unistd, read) {
+  int fd = open("/proc/version", O_RDONLY);
+  ASSERT_TRUE(fd != -1);
+
+  char buf[5];
+  ASSERT_EQ(5, read(fd, buf, 5));
+  ASSERT_EQ(buf[0], 'L');
+  ASSERT_EQ(buf[1], 'i');
+  ASSERT_EQ(buf[2], 'n');
+  ASSERT_EQ(buf[3], 'u');
+  ASSERT_EQ(buf[4], 'x');
+  close(fd);
+}
+
+TEST(unistd, read_EBADF) {
+  // read returns ssize_t which is 64-bits on LP64, so it's worth explicitly checking that
+  // our syscall stubs correctly return a 64-bit -1.
+  char buf[1];
+  ASSERT_EQ(-1, read(-1, buf, sizeof(buf)));
+  ASSERT_EQ(EBADF, errno);
+}
+
+TEST(unistd, syscall_long) {
+  // Check that syscall(3) correctly returns long results.
+  // https://code.google.com/p/android/issues/detail?id=73952
+  // We assume that the break is > 4GiB, but this is potentially flaky.
+  uintptr_t p = reinterpret_cast<uintptr_t>(sbrk(0));
+  ASSERT_EQ(p, static_cast<uintptr_t>(syscall(__NR_brk, 0)));
+}
+
+TEST(unistd, alarm) {
+  ASSERT_EQ(0U, alarm(0));
+}
+
+TEST(unistd, _exit) {
+  int pid = fork();
+  ASSERT_NE(-1, pid) << strerror(errno);
+
+  if (pid == 0) {
+    _exit(99);
+  }
+
+  int status;
+  ASSERT_EQ(pid, waitpid(pid, &status, 0));
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(99, WEXITSTATUS(status));
+}
+
+TEST(unistd, getenv_unsetenv) {
+  ASSERT_EQ(0, setenv("test-variable", "hello", 1));
+  ASSERT_STREQ("hello", getenv("test-variable"));
+  ASSERT_EQ(0, unsetenv("test-variable"));
+  ASSERT_TRUE(getenv("test-variable") == NULL);
+}
+
+TEST(unistd, unsetenv_EINVAL) {
+  EXPECT_EQ(-1, unsetenv(NULL));
+  EXPECT_EQ(EINVAL, errno);
+  EXPECT_EQ(-1, unsetenv(""));
+  EXPECT_EQ(EINVAL, errno);
+  EXPECT_EQ(-1, unsetenv("a=b"));
+  EXPECT_EQ(EINVAL, errno);
+}
+
+TEST(unistd, setenv_EINVAL) {
+  EXPECT_EQ(-1, setenv(NULL, "value", 0));
+  EXPECT_EQ(EINVAL, errno);
+  EXPECT_EQ(-1, setenv(NULL, "value", 1));
+  EXPECT_EQ(EINVAL, errno);
+  EXPECT_EQ(-1, setenv("", "value", 0));
+  EXPECT_EQ(EINVAL, errno);
+  EXPECT_EQ(-1, setenv("", "value", 1));
+  EXPECT_EQ(EINVAL, errno);
+  EXPECT_EQ(-1, setenv("a=b", "value", 0));
+  EXPECT_EQ(EINVAL, errno);
+  EXPECT_EQ(-1, setenv("a=b", "value", 1));
+  EXPECT_EQ(EINVAL, errno);
+}
+
+TEST(unistd, setenv) {
+  ASSERT_EQ(0, unsetenv("test-variable"));
+
+  char a[] = "a";
+  char b[] = "b";
+  char c[] = "c";
+
+  // New value.
+  EXPECT_EQ(0, setenv("test-variable", a, 0));
+  EXPECT_STREQ(a, getenv("test-variable"));
+
+  // Existing value, no overwrite.
+  EXPECT_EQ(0, setenv("test-variable", b, 0));
+  EXPECT_STREQ(a, getenv("test-variable"));
+
+  // Existing value, overwrite.
+  EXPECT_EQ(0, setenv("test-variable", c, 1));
+  EXPECT_STREQ(c, getenv("test-variable"));
+  // But the arrays backing the values are unchanged.
+  EXPECT_EQ('a', a[0]);
+  EXPECT_EQ('b', b[0]);
+  EXPECT_EQ('c', c[0]);
+
+  ASSERT_EQ(0, unsetenv("test-variable"));
+}
+
+TEST(unistd, putenv) {
+  ASSERT_EQ(0, unsetenv("a"));
+
+  char* s1 = strdup("a=b");
+  ASSERT_EQ(0, putenv(s1));
+
+  ASSERT_STREQ("b", getenv("a"));
+  s1[2] = 'c';
+  ASSERT_STREQ("c", getenv("a"));
+
+  char* s2 = strdup("a=b");
+  ASSERT_EQ(0, putenv(s2));
+
+  ASSERT_STREQ("b", getenv("a"));
+  ASSERT_EQ('c', s1[2]);
+
+  ASSERT_EQ(0, unsetenv("a"));
+  free(s1);
+  free(s2);
+}
+
+TEST(unistd, clearenv) {
+  extern char** environ;
+
+  // Guarantee that environ is not initially empty...
+  ASSERT_EQ(0, setenv("test-variable", "a", 1));
+
+  // Stash a copy.
+  std::vector<char*> old_environ;
+  for (size_t i = 0; environ[i] != NULL; ++i) {
+    old_environ.push_back(strdup(environ[i]));
+  }
+
+  ASSERT_EQ(0, clearenv());
+
+  EXPECT_TRUE(environ == NULL || environ[0] == NULL);
+  EXPECT_EQ(NULL, getenv("test-variable"));
+  EXPECT_EQ(0, setenv("test-variable", "post-clear", 1));
+  EXPECT_STREQ("post-clear", getenv("test-variable"));
+
+  // Put the old environment back.
+  for (size_t i = 0; i < old_environ.size(); ++i) {
+    EXPECT_EQ(0, putenv(old_environ[i]));
+  }
+
+  // Check it wasn't overwritten.
+  EXPECT_STREQ("a", getenv("test-variable"));
+
+  EXPECT_EQ(0, unsetenv("test-variable"));
+}
+
+static void TestFsyncFunction(int (*fn)(int)) {
+  int fd;
+
+  // Can't sync an invalid fd.
+  errno = 0;
+  EXPECT_EQ(-1, fn(-1));
+  EXPECT_EQ(EBADF, errno);
+
+  // It doesn't matter whether you've opened a file for write or not.
+  TemporaryFile tf;
+  ASSERT_NE(-1, tf.fd);
+
+  EXPECT_EQ(0, fn(tf.fd));
+
+  ASSERT_NE(-1, fd = open(tf.filename, O_RDONLY));
+  EXPECT_EQ(0, fn(fd));
+  close(fd);
+
+  ASSERT_NE(-1, fd = open(tf.filename, O_RDWR));
+  EXPECT_EQ(0, fn(fd));
+  close(fd);
+
+  // The fd can even be a directory.
+  ASSERT_NE(-1, fd = open("/", O_RDONLY));
+  EXPECT_EQ(0, fn(fd));
+  close(fd);
+
+  // But some file systems may choose to be fussy...
+  errno = 0;
+  ASSERT_NE(-1, fd = open("/proc/version", O_RDONLY));
+  EXPECT_EQ(-1, fn(fd));
+  EXPECT_EQ(EINVAL, errno);
+  close(fd);
+}
+
+TEST(unistd, fdatasync) {
+  TestFsyncFunction(fdatasync);
+}
+
+TEST(unistd, fsync) {
+  TestFsyncFunction(fsync);
+}
+
+static void AssertGetPidCorrect() {
+  // The loop is just to make manual testing/debugging with strace easier.
+  pid_t getpid_syscall_result = syscall(__NR_getpid);
+  for (size_t i = 0; i < 128; ++i) {
+    ASSERT_EQ(getpid_syscall_result, getpid());
+  }
+}
+
+TEST(unistd, getpid_caching_and_fork) {
+  pid_t parent_pid = getpid();
+  ASSERT_EQ(syscall(__NR_getpid), parent_pid);
+
+  pid_t fork_result = fork();
+  ASSERT_NE(fork_result, -1);
+  if (fork_result == 0) {
+    // We're the child.
+    AssertGetPidCorrect();
+    ASSERT_EQ(parent_pid, getppid());
+    _exit(123);
+  } else {
+    // We're the parent.
+    ASSERT_EQ(parent_pid, getpid());
+
+    int status;
+    ASSERT_EQ(fork_result, waitpid(fork_result, &status, 0));
+    ASSERT_TRUE(WIFEXITED(status));
+    ASSERT_EQ(123, WEXITSTATUS(status));
+  }
+}
+
+static int GetPidCachingCloneStartRoutine(void*) {
+  AssertGetPidCorrect();
+  return 123;
+}
+
+TEST(unistd, getpid_caching_and_clone) {
+  pid_t parent_pid = getpid();
+  ASSERT_EQ(syscall(__NR_getpid), parent_pid);
+
+  void* child_stack[1024];
+  int clone_result = clone(GetPidCachingCloneStartRoutine, &child_stack[1024], CLONE_NEWNS | SIGCHLD, NULL);
+  if (clone_result == -1 && errno == EPERM && getuid() != 0) {
+    GTEST_LOG_(INFO) << "This test only works if you have permission to CLONE_NEWNS; try running as root.\n";
+    return;
+  }
+  ASSERT_NE(clone_result, -1);
+
+  ASSERT_EQ(parent_pid, getpid());
+
+  int status;
+  ASSERT_EQ(clone_result, waitpid(clone_result, &status, 0));
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(123, WEXITSTATUS(status));
+}
+
+static void* GetPidCachingPthreadStartRoutine(void*) {
+  AssertGetPidCorrect();
+  return NULL;
+}
+
+TEST(unistd, getpid_caching_and_pthread_create) {
+  pid_t parent_pid = getpid();
+
+  pthread_t t;
+  ASSERT_EQ(0, pthread_create(&t, NULL, GetPidCachingPthreadStartRoutine, NULL));
+
+  ASSERT_EQ(parent_pid, getpid());
+
+  void* result;
+  ASSERT_EQ(0, pthread_join(t, &result));
+  ASSERT_EQ(NULL, result);
 }
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
new file mode 100644
index 0000000..d02c4bf
--- /dev/null
+++ b/tests/wchar_test.cpp
@@ -0,0 +1,491 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdint.h>
+#include <wchar.h>
+
+TEST(wchar, sizeof_wchar_t) {
+  EXPECT_EQ(4U, sizeof(wchar_t));
+  EXPECT_EQ(4U, sizeof(wint_t));
+}
+
+TEST(wchar, mbrlen) {
+  char bytes[] = { 'h', 'e', 'l', 'l', 'o', '\0' };
+  EXPECT_EQ(0U, mbrlen(&bytes[0], 0, NULL));
+  EXPECT_EQ(1U, mbrlen(&bytes[0], 1, NULL));
+
+  EXPECT_EQ(1U, mbrlen(&bytes[4], 1, NULL));
+  EXPECT_EQ(0U, mbrlen(&bytes[5], 1, NULL));
+}
+
+TEST(wchar, wctomb_wcrtomb) {
+  // wctomb and wcrtomb behave differently when s == NULL.
+  EXPECT_EQ(0, wctomb(NULL, L'h'));
+  EXPECT_EQ(0, wctomb(NULL, L'\0'));
+  EXPECT_EQ(1U, wcrtomb(NULL, L'\0', NULL));
+  EXPECT_EQ(1U, wcrtomb(NULL, L'h', NULL));
+
+  char bytes[MB_LEN_MAX];
+
+  // wctomb and wcrtomb behave similarly for the null wide character.
+  EXPECT_EQ(1, wctomb(bytes, L'\0'));
+  EXPECT_EQ(1U, wcrtomb(bytes, L'\0', NULL));
+
+  // ...and for regular characters.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(1, wctomb(bytes, L'h'));
+  EXPECT_EQ('h', bytes[0]);
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(1U, wcrtomb(bytes, L'h', NULL));
+  EXPECT_EQ('h', bytes[0]);
+
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  // 1-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(1U, wcrtomb(bytes, L'h', NULL));
+  EXPECT_EQ('h', bytes[0]);
+  // 2-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(2U, wcrtomb(bytes, 0x00a2, NULL));
+  EXPECT_EQ('\xc2', bytes[0]);
+  EXPECT_EQ('\xa2', bytes[1]);
+  // 3-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(3U, wcrtomb(bytes, 0x20ac, NULL));
+  EXPECT_EQ('\xe2', bytes[0]);
+  EXPECT_EQ('\x82', bytes[1]);
+  EXPECT_EQ('\xac', bytes[2]);
+  // 4-byte UTF-8.
+  memset(bytes, 0, sizeof(bytes));
+  EXPECT_EQ(4U, wcrtomb(bytes, 0x24b62, NULL));
+  EXPECT_EQ('\xf0', bytes[0]);
+  EXPECT_EQ('\xa4', bytes[1]);
+  EXPECT_EQ('\xad', bytes[2]);
+  EXPECT_EQ('\xa2', bytes[3]);
+  // Invalid code point.
+  EXPECT_EQ(static_cast<size_t>(-1), wcrtomb(bytes, 0xffffffff, NULL));
+  EXPECT_EQ(EILSEQ, errno);
+}
+
+TEST(wchar, wcrtomb_start_state) {
+  char out[MB_LEN_MAX];
+  mbstate_t ps;
+
+  // Any non-initial state is invalid when calling wcrtomb.
+  memset(&ps, 0, sizeof(ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(NULL, "\xc2", 1, &ps));
+  EXPECT_EQ(static_cast<size_t>(-1), wcrtomb(out, 0x00a2, &ps));
+  EXPECT_EQ(EILSEQ, errno);
+
+  // If the first argument to wcrtomb is NULL or the second is L'\0' the shift
+  // state should be reset.
+  memset(&ps, 0, sizeof(ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(NULL, "\xc2", 1, &ps));
+  EXPECT_EQ(1U, wcrtomb(NULL, 0x00a2, &ps));
+  EXPECT_TRUE(mbsinit(&ps));
+
+  memset(&ps, 0, sizeof(ps));
+  EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(NULL, "\xf0\xa4", 1, &ps));
+  EXPECT_EQ(1U, wcrtomb(out, L'\0', &ps));
+  EXPECT_TRUE(mbsinit(&ps));
+}
+
+TEST(wchar, wcstombs_wcrtombs) {
+  const wchar_t chars[] = { L'h', L'e', L'l', L'l', L'o', 0 };
+  const wchar_t bad_chars[] = { L'h', L'i', static_cast<wchar_t>(0xffffffff), 0 };
+  const wchar_t* src;
+  char bytes[BUFSIZ];
+
+  // Given a NULL destination, these functions count valid characters.
+  EXPECT_EQ(5U, wcstombs(NULL, chars, 0));
+  EXPECT_EQ(5U, wcstombs(NULL, chars, 4));
+  EXPECT_EQ(5U, wcstombs(NULL, chars, 256));
+  src = chars;
+  EXPECT_EQ(5U, wcsrtombs(NULL, &src, 0, NULL));
+  EXPECT_EQ(&chars[0], src);
+  src = chars;
+  EXPECT_EQ(5U, wcsrtombs(NULL, &src, 4, NULL));
+  EXPECT_EQ(&chars[0], src);
+  src = chars;
+  EXPECT_EQ(5U, wcsrtombs(NULL, &src, 256, NULL));
+  EXPECT_EQ(&chars[0], src);
+
+  // An unrepresentable char just returns an error from wcstombs...
+  errno = 0;
+  EXPECT_EQ(static_cast<size_t>(-1), wcstombs(NULL, bad_chars, 0));
+  EXPECT_EQ(EILSEQ, errno);
+  errno = 0;
+  EXPECT_EQ(static_cast<size_t>(-1), wcstombs(NULL, bad_chars, 256));
+  EXPECT_EQ(EILSEQ, errno);
+
+  // And wcsrtombs doesn't tell us where it got stuck because we didn't ask it
+  // to actually convert anything...
+  errno = 0;
+  src = bad_chars;
+  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(NULL, &src, 0, NULL));
+  EXPECT_EQ(&bad_chars[0], src);
+  EXPECT_EQ(EILSEQ, errno);
+  errno = 0;
+  src = bad_chars;
+  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(NULL, &src, 256, NULL));
+  EXPECT_EQ(&bad_chars[0], src);
+  EXPECT_EQ(EILSEQ, errno);
+
+  // Okay, now let's test actually converting something...
+  memset(bytes, 'x', sizeof(bytes));
+  EXPECT_EQ(0U, wcstombs(bytes, chars, 0));
+  memset(bytes, 'x', sizeof(bytes));
+  EXPECT_EQ(4U, wcstombs(bytes, chars, 4));
+  bytes[5] = 0;
+  EXPECT_STREQ("hellx", bytes);
+  memset(bytes, 'x', sizeof(bytes));
+  EXPECT_EQ(5U, wcstombs(bytes, chars, 256));
+  EXPECT_STREQ("hello", bytes);
+  memset(bytes, 'x', sizeof(bytes));
+  EXPECT_EQ(5U, wcstombs(bytes, chars, 6));
+  EXPECT_STREQ("hello", bytes);
+  errno = 0;
+  memset(bytes, 'x', sizeof(bytes));
+  EXPECT_EQ(static_cast<size_t>(-1), wcstombs(bytes, bad_chars, 256));
+  EXPECT_EQ(EILSEQ, errno);
+  bytes[3] = 0;
+  EXPECT_STREQ("hix", bytes);
+
+  // wcsrtombs is a bit more informative...
+  memset(bytes, 'x', sizeof(bytes));
+  src = chars;
+  EXPECT_EQ(0U, wcsrtombs(bytes, &src, 0, NULL));
+  EXPECT_EQ(&chars[0], src); // No input consumed.
+  EXPECT_EQ(EILSEQ, errno);
+
+  memset(bytes, 'x', sizeof(bytes));
+  src = chars;
+  EXPECT_EQ(4U, wcsrtombs(bytes, &src, 4, NULL));
+  EXPECT_EQ(&chars[4], src); // Some input consumed.
+  EXPECT_EQ(EILSEQ, errno);
+  bytes[5] = 0;
+  EXPECT_STREQ("hellx", bytes);
+
+  memset(bytes, 'x', sizeof(bytes));
+  src = chars;
+  EXPECT_EQ(5U, wcsrtombs(bytes, &src, 256, NULL));
+  EXPECT_EQ(NULL, src); // All input consumed!
+  EXPECT_EQ(EILSEQ, errno);
+  EXPECT_STREQ("hello", bytes);
+
+  memset(bytes, 'x', sizeof(bytes));
+  src = chars;
+  EXPECT_EQ(5U, wcsrtombs(bytes, &src, 6, NULL));
+  EXPECT_EQ(NULL, src); // All input consumed.
+  EXPECT_EQ(EILSEQ, errno);
+  EXPECT_STREQ("hello", bytes);
+
+  memset(bytes, 'x', sizeof(bytes));
+  src = bad_chars;
+  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(bytes, &src, 256, NULL));
+  EXPECT_EQ(&bad_chars[2], src);
+  EXPECT_EQ(EILSEQ, errno);
+  bytes[3] = 0;
+  EXPECT_STREQ("hix", bytes);
+
+  // Any non-initial state is invalid when calling wcsrtombs.
+  mbstate_t ps;
+  src = chars;
+  memset(&ps, 0, sizeof(ps));
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(NULL, "\xc2", 1, &ps));
+  EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(NULL, &src, 0, &ps));
+  EXPECT_EQ(EILSEQ, errno);
+}
+
+TEST(wchar, limits) {
+  ASSERT_LT(WCHAR_MIN, WCHAR_MAX);
+}
+
+TEST(wchar, wcsstr) {
+  const wchar_t* haystack = L"matches hello world, not the second hello world";
+  const wchar_t* empty_needle = L"";
+  const wchar_t* good_needle = L"ll";
+  const wchar_t* bad_needle = L"wort";
+
+  ASSERT_EQ(haystack, wcsstr(haystack, empty_needle));
+  ASSERT_EQ(&haystack[10], wcsstr(haystack, good_needle));
+  ASSERT_EQ(NULL, wcsstr(haystack, bad_needle));
+}
+
+TEST(wchar, mbtowc) {
+  wchar_t out[8];
+
+  out[0] = 'x';
+  ASSERT_EQ(0, mbtowc(out, "hello", 0));
+  ASSERT_EQ('x', out[0]);
+
+  ASSERT_EQ(0, mbtowc(out, "hello", 0));
+  ASSERT_EQ(0, mbtowc(out, "", 0));
+  ASSERT_EQ(1, mbtowc(out, "hello", 1));
+  ASSERT_EQ(L'h', out[0]);
+
+  ASSERT_EQ(0, mbtowc(NULL, "hello", 0));
+  ASSERT_EQ(0, mbtowc(NULL, "", 0));
+  ASSERT_EQ(1, mbtowc(NULL, "hello", 1));
+
+  ASSERT_EQ(0, mbtowc(NULL, NULL, 0));
+}
+
+TEST(wchar, mbrtowc) {
+  wchar_t out[8];
+
+  out[0] = 'x';
+  ASSERT_EQ(0U, mbrtowc(out, "hello", 0, NULL));
+  ASSERT_EQ('x', out[0]);
+
+  ASSERT_EQ(0U, mbrtowc(out, "hello", 0, NULL));
+  ASSERT_EQ(0U, mbrtowc(out, "", 0, NULL));
+  ASSERT_EQ(1U, mbrtowc(out, "hello", 1, NULL));
+  ASSERT_EQ(L'h', out[0]);
+
+  ASSERT_EQ(0U, mbrtowc(NULL, "hello", 0, NULL));
+  ASSERT_EQ(0U, mbrtowc(NULL, "", 0, NULL));
+  ASSERT_EQ(1U, mbrtowc(NULL, "hello", 1, NULL));
+
+  ASSERT_EQ(0U, mbrtowc(NULL, NULL, 0, NULL));
+
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  // 1-byte UTF-8.
+  ASSERT_EQ(1U, mbrtowc(out, "abcdef", 6, NULL));
+  ASSERT_EQ(L'a', out[0]);
+  // 2-byte UTF-8.
+  ASSERT_EQ(2U, mbrtowc(out, "\xc2\xa2" "cdef", 6, NULL));
+  ASSERT_EQ(static_cast<wchar_t>(0x00a2), out[0]);
+  // 3-byte UTF-8.
+  ASSERT_EQ(3U, mbrtowc(out, "\xe2\x82\xac" "def", 6, NULL));
+  ASSERT_EQ(static_cast<wchar_t>(0x20ac), out[0]);
+  // 4-byte UTF-8.
+  ASSERT_EQ(4U, mbrtowc(out, "\xf0\xa4\xad\xa2" "ef", 6, NULL));
+  ASSERT_EQ(static_cast<wchar_t>(0x24b62), out[0]);
+#if defined(__BIONIC__) // glibc allows this.
+  // Illegal 5-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, NULL));
+  ASSERT_EQ(EILSEQ, errno);
+#endif
+  // Illegal over-long sequence.
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(out, "\xf0\x82\x82\xac" "ef", 6, NULL));
+  ASSERT_EQ(EILSEQ, errno);
+}
+
+void test_mbrtowc_incomplete(mbstate_t* ps) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  wchar_t out;
+  // 2-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\xc2", 1, ps));
+  ASSERT_EQ(1U, mbrtowc(&out, "\xa2" "cdef", 5, ps));
+  ASSERT_EQ(static_cast<wchar_t>(0x00a2), out);
+  ASSERT_TRUE(mbsinit(ps));
+  // 3-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\xe2", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\x82", 1, ps));
+  ASSERT_EQ(1U, mbrtowc(&out, "\xac" "def", 4, ps));
+  ASSERT_EQ(static_cast<wchar_t>(0x20ac), out);
+  ASSERT_TRUE(mbsinit(ps));
+  // 4-byte UTF-8.
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\xf0", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\xa4\xad", 2, ps));
+  ASSERT_EQ(1U, mbrtowc(&out, "\xa2" "ef", 3, ps));
+  ASSERT_EQ(static_cast<wchar_t>(0x24b62), out);
+  ASSERT_TRUE(mbsinit(ps));
+
+  // Invalid 2-byte
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\xc2", 1, ps));
+  ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(&out, "\x20" "cdef", 5, ps));
+  ASSERT_EQ(EILSEQ, errno);
+}
+
+TEST(wchar, mbrtowc_incomplete) {
+  mbstate_t ps;
+  memset(&ps, 0, sizeof(ps));
+
+  test_mbrtowc_incomplete(&ps);
+  test_mbrtowc_incomplete(NULL);
+}
+
+void test_mbsrtowcs(mbstate_t* ps) {
+  wchar_t out[4];
+
+  const char* valid = "A" "\xc2\xa2" "\xe2\x82\xac" "\xf0\xa4\xad\xa2" "ef";
+  ASSERT_EQ(4U, mbsrtowcs(out, &valid, 4, ps));
+  ASSERT_EQ(L'A', out[0]);
+  ASSERT_EQ(static_cast<wchar_t>(0x00a2), out[1]);
+  ASSERT_EQ(static_cast<wchar_t>(0x20ac), out[2]);
+  ASSERT_EQ(static_cast<wchar_t>(0x24b62), out[3]);
+  // Check that valid has advanced to the next unread character.
+  ASSERT_EQ('e', *valid);
+
+  wmemset(out, L'x', sizeof(out) / sizeof(wchar_t));
+  ASSERT_EQ(2U, mbsrtowcs(out, &valid, 4, ps));
+  ASSERT_EQ(L'e', out[0]);
+  ASSERT_EQ(L'f', out[1]);
+  ASSERT_EQ(L'\0', out[2]);
+  // Check that we didn't clobber the rest of out.
+  ASSERT_EQ(L'x', out[3]);
+  // Check that valid has advanced to the end of the string.
+  ASSERT_EQ(nullptr, valid);
+
+  const char* invalid = "A" "\xc2\x20" "ef";
+  ASSERT_EQ(static_cast<size_t>(-1), mbsrtowcs(out, &invalid, 4, ps));
+  EXPECT_EQ(EILSEQ, errno);
+  ASSERT_EQ('\xc2', *invalid);
+
+  const char* incomplete = "A" "\xc2";
+  ASSERT_EQ(static_cast<size_t>(-1), mbsrtowcs(out, &incomplete, 2, ps));
+  EXPECT_EQ(EILSEQ, errno);
+  ASSERT_EQ('\xc2', *incomplete);
+}
+
+TEST(wchar, mbsrtowcs) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  mbstate_t ps;
+  memset(&ps, 0, sizeof(ps));
+  test_mbsrtowcs(&ps);
+  test_mbsrtowcs(NULL);
+
+  // Invalid multi byte continuation.
+  const char* invalid = "\x20";
+  wchar_t out;
+  ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(&out, "\xc2", 1, &ps));
+  ASSERT_EQ(static_cast<size_t>(-1), mbsrtowcs(&out, &invalid, 1, &ps));
+  EXPECT_EQ(EILSEQ, errno);
+  ASSERT_EQ('\x20', *invalid);
+}
+
+TEST(wchar, wcstod) {
+  ASSERT_DOUBLE_EQ(1.23, wcstod(L"1.23", NULL));
+}
+
+TEST(wchar, wcstof) {
+  ASSERT_FLOAT_EQ(1.23f, wcstof(L"1.23", NULL));
+}
+
+TEST(wchar, wcstol) {
+  ASSERT_EQ(123L, wcstol(L"123", NULL, 0));
+}
+
+TEST(wchar, wcstoll) {
+  ASSERT_EQ(123LL, wcstol(L"123", NULL, 0));
+}
+
+TEST(wchar, wcstold) {
+  ASSERT_DOUBLE_EQ(1.23L, wcstold(L"1.23", NULL));
+}
+
+TEST(wchar, wcstoul) {
+  ASSERT_EQ(123UL, wcstoul(L"123", NULL, 0));
+}
+
+TEST(wchar, wcstoull) {
+  ASSERT_EQ(123ULL, wcstoul(L"123", NULL, 0));
+}
+
+TEST(wchar, mbsnrtowcs) {
+  wchar_t dst[128];
+  const char* s = "hello, world!";
+  const char* src;
+
+  memset(dst, 0, sizeof(dst));
+  src = s;
+  ASSERT_EQ(0U, mbsnrtowcs(dst, &src, 0, 0, NULL));
+
+  memset(dst, 0, sizeof(dst));
+  src = s;
+  ASSERT_EQ(2U, mbsnrtowcs(dst, &src, 2, 123, NULL)); // glibc chokes on SIZE_MAX here.
+  ASSERT_EQ(L'h', dst[0]);
+  ASSERT_EQ(L'e', dst[1]);
+  ASSERT_EQ(&s[2], src);
+
+  memset(dst, 0, sizeof(dst));
+  src = s;
+  ASSERT_EQ(3U, mbsnrtowcs(dst, &src, SIZE_MAX, 3, NULL));
+  ASSERT_EQ(L'h', dst[0]);
+  ASSERT_EQ(L'e', dst[1]);
+  ASSERT_EQ(L'l', dst[2]);
+  ASSERT_EQ(&s[3], src);
+}
+
+TEST(wchar, wcsftime) {
+  setenv("TZ", "UTC", 1);
+
+  struct tm t;
+  memset(&t, 0, sizeof(tm));
+  t.tm_year = 200;
+  t.tm_mon = 2;
+  t.tm_mday = 10;
+
+  wchar_t buf[64];
+
+  EXPECT_EQ(24U, wcsftime(buf, sizeof(buf), L"%c", &t));
+  EXPECT_STREQ(L"Sun Mar 10 00:00:00 2100", buf);
+}
+
+TEST(wchar, wmemmove) {
+  const wchar_t const_wstr[] = L"This is a test of something or other.....";
+  wchar_t* wstr = new wchar_t[sizeof(const_wstr)];
+
+  wmemmove(wstr, const_wstr, sizeof(const_wstr)/sizeof(wchar_t));
+  EXPECT_STREQ(const_wstr, wstr);
+
+  wmemmove(wstr+5, wstr, sizeof(const_wstr)/sizeof(wchar_t) - 6);
+  EXPECT_STREQ(L"This This is a test of something or other", wstr);
+}
+
+TEST(wchar, mbrtowc_15439554) {
+  // http://b/15439554
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
+  uselocale(LC_GLOBAL_LOCALE);
+
+  ASSERT_GE(static_cast<size_t>(MB_LEN_MAX), MB_CUR_MAX);
+  ASSERT_GE(MB_CUR_MAX, 4U);
+
+  wchar_t wc;
+  size_t n;
+
+  // 1-byte character.
+  n = mbrtowc(&wc, "x", MB_CUR_MAX, NULL);
+  EXPECT_EQ(1U, n);
+  EXPECT_EQ(L'x', wc);
+  // 2-byte character.
+  n = mbrtowc(&wc, "\xc2\xa2", MB_CUR_MAX, NULL);
+  EXPECT_EQ(2U, n);
+  EXPECT_EQ(L'¢', wc);
+  // 3-byte character.
+  n = mbrtowc(&wc, "\xe2\x82\xac", MB_CUR_MAX, NULL);
+  EXPECT_EQ(3U, n);
+  EXPECT_EQ(L'€', wc);
+  // 4-byte character.
+  n = mbrtowc(&wc, "\xf0\xa4\xad\xa2", MB_CUR_MAX, NULL);
+  EXPECT_EQ(4U, n);
+  EXPECT_EQ(L'𤭢', wc);
+}